drm/amd/pm: avoid large variable on kernel stack
Subsystems (3)
PATCH 1/1 drm/amd/pm: avoid large variable on kernel stack
From: Arnd Bergmann <[email protected]>
The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang:
drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than]
Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier.
--- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +16 -5
@@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,static int smu_v13_0_7_get_power_profile_mode (struct smu_context *smu,char *buf) { -DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT ]; +DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external;uint32_t i, j, size =0 ;int16_t workload_type =0 ;int result =0 ;
@@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *bufif (!buf)return -EINVAL ; + activity_monitor_external =kcalloc (sizeof (activity_monitor_external), +PP_SMC_POWER_PROFILE_COUNT , +GFP_KERNEL ); +if (!activity_monitor_external) +return -ENOMEM ; + size +=sysfs_emit_at (buf, size," " );for (i =0 ; i <=PP_SMC_POWER_PROFILE_WINDOW3D ; i++) size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],
@@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf workload_type =smu_cmn_to_asic_specific_index (smu,CMN2ASIC_MAPPING_WORKLOAD , i); -if (workload_type <0 ) -return -EINVAL ; +if (workload_type <0 ) { + result = -EINVAL ; + goto out; + } result =smu_cmn_update_table (smu,SMU_TABLE_ACTIVITY_MONITOR_COEFF , workload_type, (void *)(&activity_monitor_external[i]), false);if (result) {dev_err (smu->adev->dev,"[%s] Failed to get activity monitor!" , __func__); -return result; + goto out; } }
@@ -1495,7 +1503,10 @@ do { \PRINT_DPM_MONITOR (Fclk_BoosterFreq);#undef PRINT_DPM_MONITOR -return size; + result = size; +out: +kfree (activity_monitor_external); +return result; }static int smu_v13_0_7_set_power_profile_mode (struct smu_context *smu,long *input,uint32_t size)
Signature · 1 line
2.35.1
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 80 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang:
drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than]Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier.
Fixes 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7")Signed-off-by Arnd Bergmann <[email protected]>--- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +16
-6@@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,static int smu_v13_0_7_get_power_profile_mode (struct smu_context *smu,char *buf) { -DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT ]; +DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external;uint32_t i, j, size =0 ;int16_t workload_type =0 ;int result =0 ;@@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *bufif (!buf)return -EINVAL ; + activity_monitor_external =kcalloc (sizeof (activity_monitor_external), +PP_SMC_POWER_PROFILE_COUNT , +GFP_KERNEL ); +if (!activity_monitor_external) +return -ENOMEM ; + size +=sysfs_emit_at (buf, size," " );for (i =0 ; i <=PP_SMC_POWER_PROFILE_WINDOW3D ; i++) size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],@@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf workload_type =smu_cmn_to_asic_specific_index (smu,CMN2ASIC_MAPPING_WORKLOAD , i); -if (workload_type <0 ) -return -EINVAL ; +if (workload_type <0 ) { + result = -EINVAL ; + goto out; + } result =smu_cmn_update_table (smu,SMU_TABLE_ACTIVITY_MONITOR_COEFF , workload_type, (void *)(&activity_monitor_external[i]), false);if (result) {dev_err (smu->adev->dev,"[%s] Failed to get activity monitor!" , __func__); -return result; + goto out; } }@@ -1495,7 +1503,10 @@ do { \PRINT_DPM_MONITOR (Fclk_BoosterFreq);#undef PRINT_DPM_MONITOR -return size; + result = size; +out: +kfree (activity_monitor_external); +return result; }static int smu_v13_0_7_set_power_profile_mode (struct smu_context *smu,long *input,uint32_t size) --2.35.1
Le 15/12/2022 à 17:36, Arnd Bergmann a écrit :
Quoted 31 lines
From: Arnd Bergmann <[email protected]>
The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang:
drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than]Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier.
Fixes 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7")Signed-off-by Arnd Bergmann <[email protected]>--- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1@@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,static int smu_v13_0_7_get_power_profile_mode (struct smu_context *smu,char *buf) { -DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT ]; +DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external;uint32_t i, j, size =0 ;int16_t workload_type =0 ;int result =0 ;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf · line 1450
Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-0@@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *bufif (!buf)return -EINVAL ; + activity_monitor_external = kcalloc(sizeof(activity_monitor_external),
Hi,
Before, 'activity_monitor_external' was not initialized. Maybe kcalloc() is enough?
sizeof(*activity_monitor_external)?
~~~~
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf · line 1457
Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +5
-0+PP_SMC_POWER_PROFILE_COUNT , + GFP_KERNEL); +if (!activity_monitor_external) +return -ENOMEM ; + size +=sysfs_emit_at (buf, size," " );for (i =0 ; i <=PP_SMC_POWER_PROFILE_WINDOW3D ; i++)
Unrelated, but wouldn't it be more straightforward with "< PP_SMC_POWER_PROFILE_COUNT"?
Quoted 34 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +9
-4size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],@@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf workload_type =smu_cmn_to_asic_specific_index (smu,CMN2ASIC_MAPPING_WORKLOAD , i); -if (workload_type <0 ) -return -EINVAL ; +if (workload_type <0 ) { + result = -EINVAL ; + goto out; + } result =smu_cmn_update_table (smu,SMU_TABLE_ACTIVITY_MONITOR_COEFF , workload_type, (void *)(&activity_monitor_external[i]), false);if (result) {dev_err (smu->adev->dev,"[%s] Failed to get activity monitor!" , __func__); -return result; + goto out; } }@@ -1495,7 +1503,10 @@ do { \PRINT_DPM_MONITOR (Fclk_BoosterFreq);#undef PRINT_DPM_MONITOR -return size; + result = size; +out: +kfree (activity_monitor_external); +return result; }static int smu_v13_0_7_set_power_profile_mode (struct smu_context *smu,long *input,uint32_t size)
Le 15/12/2022 à 20:46, Christophe JAILLET a écrit :
Quoted 41 lines
Le 15/12/2022 à 17:36, Arnd Bergmann a écrit :
Quoted 32 lines
From: Arnd Bergmann <[email protected]>
The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang:
drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than]Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier.
Fixes 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7")Signed-off-by Arnd Bergmann <[email protected]>---
.../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++-----1 file changed, 16 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1@@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(structsmu_context *smu, static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf) { - DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT ]; + DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; uint32_t i, j, size = 0; int16_t workload_type = 0;int result = 0;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0
-0@@ -1447,6 +1447,12 @@ static intQuoted 5 lines
smu_v13_0_7_get_power_profile_mode(struct
smu_context*smu, char *buf if (!buf)
return-EINVAL;
+activity_monitor_external= kcalloc(sizeof(activity_monitor_external),Hi,
Quoted 2 lines
Before, '
activity_monitor_external' was not initialized. Maybekcalloc()is enough?
Read kmalloc_array()
Quoted 48 lines
sizeof(*activity_monitor_external)?
~~~~Quoted 7 lines
+
PP_SMC_POWER_PROFILE_COUNT,
+GFP_KERNEL);
+ if (!activity_monitor_external)
+ return-ENOMEM;
+
size +=sysfs_emit_at(buf, size, " "); for (i = 0; i <=PP_SMC_POWER_PROFILE_WINDOW3D; i++)Unrelated, but wouldn't it be more straightforward with "<
PP_SMC_POWER_PROFILE_COUNT"?Quoted 32 lines
size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0
-0@@ -1459,15 +1465,17 @@ static intsmu_v13_0_7_get_power_profile_mode(struct
smu_context*smu, char *bufworkload_type= smu_cmn_to_asic_specific_index(smu,CMN2ASIC_MAPPING_WORKLOAD,
i);
- if (workload_type< 0)
- return-EINVAL;
+ if (workload_type< 0) {
+ result =-EINVAL;
+ goto out;
+ }
result = smu_cmn_update_table(smu,SMU_TABLE_ACTIVITY_MONITOR_COEFF,workload_type, (void *)(&activity_monitor_external[i]), false); if (result) {
dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__); - return result;
+ goto out;
}
}drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4
-1@@ -1495,7 +1503,10 @@ do { \ PRINT_DPM_MONITOR(Fclk_BoosterFreq); #undef PRINT_DPM_MONITOR - return size; + result = size; +out: + kfree(activity_monitor_external); + return result; } static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)
Quoted 40 lines · Christophe JAILLET
Quoted 31 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang:
drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than]Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier.
Fixes 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7")Signed-off-by Arnd Bergmann <[email protected]>--- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1@@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,static int smu_v13_0_7_get_power_profile_mode (struct smu_context *smu,char *buf) { -DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT ]; +DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external;uint32_t i, j, size =0 ;int16_t workload_type =0 ;int result =0 ;drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf · line 1450
Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-0@@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *bufif (!buf)return -EINVAL ; + activity_monitor_external = kcalloc(sizeof(activity_monitor_external),Hi,
Quoted 5 lines
Before, '
activity_monitor_external' was not initialized. Maybekcalloc()is enough?
sizeof(*activity_monitor_external)?~~~~
I've fixed this up when applying.
Alex
Quoted 47 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf · line 1457
Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +5
-0+PP_SMC_POWER_PROFILE_COUNT , + GFP_KERNEL); +if (!activity_monitor_external) +return -ENOMEM ; + size +=sysfs_emit_at (buf, size," " );for (i =0 ; i <=PP_SMC_POWER_PROFILE_WINDOW3D ; i++)Unrelated, but wouldn't it be more straightforward with "<
PP_SMC_POWER_PROFILE_COUNT"?Quoted 34 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +9
-4size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],@@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf workload_type =smu_cmn_to_asic_specific_index (smu,CMN2ASIC_MAPPING_WORKLOAD , i); -if (workload_type <0 ) -return -EINVAL ; +if (workload_type <0 ) { + result = -EINVAL ; + goto out; + } result =smu_cmn_update_table (smu,SMU_TABLE_ACTIVITY_MONITOR_COEFF , workload_type, (void *)(&activity_monitor_external[i]), false);if (result) {dev_err (smu->adev->dev,"[%s] Failed to get activity monitor!" , __func__); -return result; + goto out; } }@@ -1495,7 +1503,10 @@ do { \PRINT_DPM_MONITOR (Fclk_BoosterFreq);#undef PRINT_DPM_MONITOR -return size; + result = size; +out: +kfree (activity_monitor_external); +return result; }static int smu_v13_0_7_set_power_profile_mode (struct smu_context *smu,long *input,uint32_t size)