drm/amd/pm: avoid potential UBSAN issue on legacy asics
Subsystems (3)
PATCH 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
--- 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 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 (is_legacy_dpm (adev))return false; hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
Signature · 1 line
2.25.1
Quoted 16 lines · Guchun Chen
Prevent further dpm casting on legacy asics without
od_enabledinamdgpu_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
Suggested-by Evan Quan <[email protected]>Signed-off-by Guchun Chen <[email protected]> > ---drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0
-0
drivers/gpu/drm/amd/pm/amdgpu_dpm.c line 40
Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2
-0@@ -36,6 +36,8 @@#define amdgpu_dpm_enable_bapm (adev, e) \ ((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e))) +#define is_legacy_dpm (adev) ((adev)->powerplay.pp_handle == (adev)) +
For consistent naming, you may use amdgpu_dpm_is_legacy_dpm().
Regardless,
Thanks,
Lijo
Quoted 17 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5
-2int 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 (is_legacy_dpm (adev))return false; hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
Quoted 35 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, May 9, 2023 3:29 PM
To: Chen, Guchun <[email protected]>; amd- [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Quan, Evan <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid potential UBSAN issue on legacy asicsQuoted 20 lines · Guchun Chen
Prevent further dpm casting on legacy asics without
od_enabledinamdgpu_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
Suggested-by Evan Quan <[email protected]>Signed-off-by Guchun Chen <[email protected]> > ---drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0
-0@@ -36,6 +36,8 @@#define amdgpu_dpm_enable_bapm (adev, e) \
Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c line 40
Quoted 6 lines
((adev)->powerplay.pp_funcs->enable_bapm((adev)-
powerplay.pp_handle,
(e)))drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2
-0+#define is_legacy_dpm (adev) ((adev)->powerplay.pp_handle == (adev)) +For consistent naming, you may use
amdgpu_dpm_is_legacy_dpm().
Will update it before pushing. Thanks for your review.
Regards,
Guchun
Quoted 26 lines
Regardless,
Reviewed-by Lijo Lazar <[email protected]>Thanks,
LijoQuoted 3 lines
int amdgpu_dpm_get_sclk(struct amdgpu_device *adev, bool low) { const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;@@
Quoted 1 line
-1467,8 +1469,11 @@ int amdgpu_dpm_is_overdrive_supported(struct
amdgpu_device*adev)Quoted 13 lines
} else { struct pp_hwmgr *hwmgr;drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5
-2-/* 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 (is_legacy_dpm (adev))return false; hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;