<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Apple Color Emoji";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"\@宋体";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@等线";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:12.0pt;
        font-family:宋体;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:DengXian;
        color:windowtext;}
span.searchhighlight
        {mso-style-name:searchhighlight;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="ZH-CN" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<p style="font-family:Calibri;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<div class="WordSection1">
<p class="MsoNormal"><span class="searchhighlight"><span lang="EN-US" style="font-size:11.0pt;font-family:"Times New Roman",serif;color:#070706;background:#FFEE94">Reviewed-by</span></span><span lang="EN-US" style="font-size:11.0pt;font-family:"Times New Roman",serif;color:black">:
 Kenneth Feng <</span><span lang="EN-US" style="color:black"><a href="mailto:kenneth.feng@amd.com" title="mailto:kenneth.feng@amd.com"><span style="font-size:11.0pt;font-family:"Times New Roman",serif;color:#0078D4">kenneth.feng@amd.com</span></a></span><span lang="EN-US" style="font-size:11.0pt;font-family:"Times New Roman",serif;color:black">></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:DengXian"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:DengXian"><o:p> </o:p></span></p>
<div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">Best wishes<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Kenneth Feng <o:p></o:p></span></p>
</div>
</div>
</div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:DengXian"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:DengXian"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">发件人</span></b><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black"> Powell,
 Darren <Darren.Powell@amd.com><br>
</span><b><span style="color:black">日期</span></b><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">
</span><span style="color:black">星期四</span><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">, 2022</span><span style="color:black">年</span><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">6</span><span style="color:black">月</span><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">16</span><span style="color:black">日</span><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">
 05:00<br>
</span><b><span style="color:black">收件人</span></b><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black"> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
</span><b><span style="color:black">抄送</span></b><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black"> Lazar, Lijo <Lijo.Lazar@amd.com>, Wang, Yang(Kevin)
 <KevinYang.Wang@amd.com>, Feng, Kenneth <Kenneth.Feng@amd.com>, Quan, Evan <Evan.Quan@amd.com>, Ma, Le <Le.Ma@amd.com><br>
</span><b><span style="color:black">主题</span></b><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black"> Re: [PATCH v2 2/2] amdgpu/pm: Fix possible array
 out-of-bounds if SCLK levels != 2<o:p></o:p></span></p>
</div>
<p style="margin:5.0pt"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">[AMD Official Use Only - General]<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black">Ping
</span><span lang="EN-US" style="font-family:"Apple Color Emoji";color:black">🙂</span><span lang="EN-US" style="font-family:"Calibri",sans-serif;color:black"><o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US">
<hr size="0" width="100%" align="center">
</span></div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black"> Powell, Darren <Darren.Powell@amd.com><br>
<b>Sent:</b> Wednesday, May 11, 2022 1:44 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Lazar, Lijo <Lijo.Lazar@amd.com>; Wang, Yang(Kevin) <KevinYang.Wang@amd.com>; Feng, Kenneth <Kenneth.Feng@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Ma, Le <Le.Ma@amd.com>; Powell, Darren <Darren.Powell@amd.com><br>
<b>Subject:</b> [PATCH v2 2/2] amdgpu/pm: Fix possible array out-of-bounds if SCLK levels != 2</span><span lang="EN-US">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="font-size:11.0pt">[v2]<br>
simplified fix after Lijo's feedback<br>
 removed clocks.num_levels from calculation of loop count<br>
   removed unsafe accesses to shim table freq_values<br>
 retained corner case output only min,now if<br>
   clocks.num_levels == 1 && now > min<br>
<br>
 [v1]<br>
added a check to populate and use SCLK shim table freq_values only<br>
   if using dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL or<br>
                         AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM<br>
removed clocks.num_levels from calculation of shim table size<br>
removed unsafe accesses to shim table freq_values<br>
   output gfx_table values if using other dpm levels<br>
added check for freq_match when using freq_values for when now == min_clk<br>
<br>
== Test ==<br>
LOGFILE=aldebaran-sclk.test.log<br>
AMDGPU_PCI_ADDR=`lspci -nn | grep "VGA\|Display" | cut -d " " -f 1`<br>
AMDGPU_HWMON=`ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}'`<br>
HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON}<br>
<br>
lspci -nn | grep "VGA\|Display"  > $LOGFILE<br>
FILES="pp_od_clk_voltage<br>
pp_dpm_sclk"<br>
<br>
for f in $FILES<br>
do<br>
  echo === $f === >> $LOGFILE<br>
  cat $HWMON_DIR/device/$f >> $LOGFILE<br>
done<br>
cat $LOGFILE<br>
<br>
Signed-off-by: Darren Powell <darren.powell@amd.com><br>
---<br>
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 34 +++++++------------<br>
 1 file changed, 12 insertions(+), 22 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c<br>
index 6a4fca47ae53..3eb82bc88890 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c<br>
@@ -740,7 +740,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,<br>
         struct smu_13_0_dpm_table *single_dpm_table;<br>
         struct smu_dpm_context *smu_dpm = &smu->smu_dpm;<br>
         struct smu_13_0_dpm_context *dpm_context = NULL;<br>
-       uint32_t display_levels;<br>
+       int display_levels;<br>
         uint32_t freq_values[3] = {0};<br>
         uint32_t min_clk, max_clk;<br>
 <br>
@@ -772,7 +772,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,<br>
                         return ret;<br>
                 }<br>
 <br>
-               display_levels = clocks.num_levels;<br>
+               display_levels = (clocks.num_levels == 1) ? 1 : 2;<br>
 <br>
                 min_clk = pstate_table->gfxclk_pstate.curr.min;<br>
                 max_clk = pstate_table->gfxclk_pstate.curr.max;<br>
@@ -782,30 +782,20 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,<br>
 <br>
                 /* fine-grained dpm has only 2 levels */<br>
                 if (now > min_clk && now < max_clk) {<br>
-                       display_levels = clocks.num_levels + 1;<br>
+                       display_levels++;<br>
                         freq_values[2] = max_clk;<br>
                         freq_values[1] = now;<br>
                 }<br>
 <br>
-               /*<br>
-                * For DPM disabled case, there will be only one clock level.<br>
-                * And it's safe to assume that is always the current clock.<br>
-                */<br>
-               if (display_levels == clocks.num_levels) {<br>
-                       for (i = 0; i < clocks.num_levels; i++)<br>
-                               size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i,<br>
-                                       freq_values[i],<br>
-                                       (clocks.num_levels == 1) ?<br>
-                                               "*" :<br>
-                                               (aldebaran_freqs_in_same_level(<br>
-                                                        freq_values[i], now) ?<br>
-                                                        "*" :<br>
-                                                        ""));<br>
-               } else {<br>
-                       for (i = 0; i < display_levels; i++)<br>
-                               size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i,<br>
-                                               freq_values[i], i == 1 ? "*" : "");<br>
-               }<br>
+               for (i = 0; i < display_levels; i++)<br>
+                       size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i,<br>
+                               freq_values[i],<br>
+                               (display_levels == 1) ?<br>
+                                       "*" :<br>
+                                       (aldebaran_freqs_in_same_level(<br>
+                                                freq_values[i], now) ?<br>
+                                                "*" :<br>
+                                                ""));<br>
 <br>
                 break;<br>
 <br>
-- <br>
2.35.1<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>