drm/amd/pm: avoid potential UBSAN issue on legacy asics
Subsystems (3)
PATCH v3 1/1 drm/amd/pm: avoid potential UBSAN issue on legacy asics
Prevent further dpm casting on legacy asics without od_enabled in amdgpu_dpm_is_overdrive_supported. This can avoid UBSAN complain in init sequence.
v2: add a macro to check legacy dpm instead of checking asic family/type
v3: refine macro name for naming consistency
--- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -2
@@ -36,6 +36,8 @@#define amdgpu_dpm_enable_bapm (adev, e) \ ((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e))) +#define amdgpu_dpm_is_legacy_dpm (adev) ((adev)->powerplay.pp_handle == (adev)) +int amdgpu_dpm_get_sclk (struct amdgpu_device *adev,bool low) {const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
@@ -1467,8 +1469,11 @@ int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev) }else {struct pp_hwmgr *hwmgr; -/* SI asic does not carry od_enabled */ -if (adev->family ==AMDGPU_FAMILY_SI ) +/* +* dpm on some legacy asics don't carry od_enabled member +* as its pp_handle is casted directly from adev. +*/ +if (amdgpu_dpm_is_legacy_dpm (adev))return false; hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
Signature · 1 line
2.25.1
[Public]
Quoted 16 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Guchun Chen
Sent: Tuesday, May 9, 2023 4:02 AM
To: [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>
Cc: Chen, Guchun <[email protected]>
Subject: [PATCH v3] drm/amd/pm: avoid potential UBSAN issue on legacy asicsPrevent further dpm casting on legacy asics without
od_enabledinamdgpu_dpm_is_overdrive_supported. This can avoid UBSAN complain in init sequence.
Quoted 6 lines
v2: add a macro to check legacy dpm instead of checking asic family/type
v3: refine macro name for naming consistencySuggested-by Evan Quan <[email protected]>Signed-off-by Guchun Chen <[email protected]>Reviewed-by Lijo Lazar <[email protected]>
Quoted 37 lines
--- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1
-0@@ -36,6 +36,8 @@#define amdgpu_dpm_enable_bapm (adev, e) \ ((adev)->powerplay.pp_funcs->enable_bapm((adev)- >powerplay.pp_handle, (e))) +#define amdgpu_dpm_is_legacy_dpm (adev) ((adev)-Quoted 1 line
powerplay.pp_handle ==
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2
-0+(adev)) +int amdgpu_dpm_get_sclk (struct amdgpu_device *adev,bool low) { const struct amd_pm_funcs *pp_funcs = adev-Quoted 1 line
powerplay.pp_funcs; @@ -1467,8 +1469,11 @@ int
amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5
-3}else {struct pp_hwmgr *hwmgr; -/* SI asic does not carry od_enabled */ -if (adev->family ==AMDGPU_FAMILY_SI ) +/* +* dpm on some legacy asics don't carry od_enabled member +* as its pp_handle is casted directly from adev. +*/ +if (amdgpu_dpm_is_legacy_dpm (adev))return false; hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle; --2.25.1