<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Acked-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> SHANMUGAM, SRINIVASAN <SRINIVASAN.SHANMUGAM@amd.com><br>
<b>Sent:</b> Friday, June 9, 2023 4:45 AM<br>
<b>To:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Gui, Jack <Jack.Gui@amd.com><br>
<b>Cc:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; SHANMUGAM, SRINIVASAN <SRINIVASAN.SHANMUGAM@amd.com><br>
<b>Subject:</b> [PATCH v2] drm/amdgpu: Fix memcpy() in sienna_cichlid_append_powerplay_table function.</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Fixes the following gcc with W=1:<br>
<br>
In file included from ./include/linux/string.h:253,<br>
                 from ./include/linux/bitmap.h:11,<br>
                 from ./include/linux/cpumask.h:12,<br>
                 from ./arch/x86/include/asm/cpumask.h:5,<br>
                 from ./arch/x86/include/asm/msr.h:11,<br>
                 from ./arch/x86/include/asm/processor.h:22,<br>
                 from ./arch/x86/include/asm/cpufeature.h:5,<br>
                 from ./arch/x86/include/asm/thread_info.h:53,<br>
                 from ./include/linux/thread_info.h:60,<br>
                 from ./arch/x86/include/asm/preempt.h:7,<br>
                 from ./include/linux/preempt.h:78,<br>
                 from ./include/linux/spinlock.h:56,<br>
                 from ./include/linux/mmzone.h:8,<br>
                 from ./include/linux/gfp.h:7,<br>
                 from ./include/linux/firmware.h:7,<br>
                 from drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:26:<br>
In function ‘fortify_memcpy_chk’,<br>
    inlined from ‘sienna_cichlid_append_powerplay_table’ at drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:444:2,<br>
    inlined from ‘sienna_cichlid_setup_pptable’ at drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:506:8,<br>
    inlined from ‘sienna_cichlid_setup_pptable’ at drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:494:12:<br>
./include/linux/fortify-string.h:413:4: warning: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning]<br>
  413 |    __read_overflow2_field(q_size_field, size);<br>
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
<br>
the compiler complains about the size calculation in the memcpy() -<br>
"sizeof(*smc_dpm_table) - sizeof(smc_dpm_table->table_header)" is much<br>
larger than what fits into table_member.<br>
<br>
'Fixes: 7077b19a38240 ("drm/amd/pm: use macro to get pptable members")'<br>
Suggested-by: Evan Quan <Evan.Quan@amd.com><br>
Cc: Evan Quan <Evan.Quan@amd.com><br>
Cc: Chengming Gui <Jack.Gui@amd.com><br>
Cc: Christian König <christian.koenig@amd.com><br>
Cc: Alex Deucher <alexander.deucher@amd.com><br>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com><br>
---<br>
<br>
v2: <br>
 - turned to the way used for nv1x (Evan)<br>
<br>
 .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c    | 18 ++++++++++++++----<br>
 1 file changed, 14 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c<br>
index 85d53597eb07..f7ed3e655e39 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c<br>
@@ -431,7 +431,13 @@ static int sienna_cichlid_append_powerplay_table(struct smu_context *smu)<br>
 {<br>
         struct atom_smc_dpm_info_v4_9 *smc_dpm_table;<br>
         int index, ret;<br>
-       I2cControllerConfig_t *table_member;<br>
+       PPTable_beige_goby_t *ppt_beige_goby;<br>
+       PPTable_t *ppt;<br>
+<br>
+       if (smu->adev->ip_versions[MP1_HWIP][0] == IP_VERSION(11, 0, 13))<br>
+               ppt_beige_goby = smu->smu_table.driver_pptable;<br>
+       else<br>
+               ppt = smu->smu_table.driver_pptable;<br>
 <br>
         index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,<br>
                                             smc_dpm_info);<br>
@@ -440,9 +446,13 @@ static int sienna_cichlid_append_powerplay_table(struct smu_context *smu)<br>
                                       (uint8_t **)&smc_dpm_table);<br>
         if (ret)<br>
                 return ret;<br>
-       GET_PPTABLE_MEMBER(I2cControllers, &table_member);<br>
-       memcpy(table_member, smc_dpm_table->I2cControllers,<br>
-                       sizeof(*smc_dpm_table) - sizeof(smc_dpm_table->table_header));<br>
+<br>
+       if (smu->adev->ip_versions[MP1_HWIP][0] == IP_VERSION(11, 0, 13))<br>
+               smu_memcpy_trailing(ppt_beige_goby, I2cControllers, BoardReserved,<br>
+                                   smc_dpm_table, I2cControllers);<br>
+       else<br>
+               smu_memcpy_trailing(ppt, I2cControllers, BoardReserved,<br>
+                                   smc_dpm_table, I2cControllers);<br>
 <br>
         return 0;<br>
 }<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>