Skip to contentSkip to conversation

drm/amd/pm: avoid potential UBSAN issue on legacy asics

PATCH Superseded Guchun Chen 2 participants 3 messages May 9, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index 86246f69dbe1..4b28fd62ed7a 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Guchun Chen

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 +0 -0
index 86246f69dbe1..4b28fd62ed7a 100644

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 -2
  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;
#2 lore raw
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 asics

Quoted 20 lines · Guchun Chen

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 +0 -0
index 86246f69dbe1..4b28fd62ed7a 100644
@@ -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,

Thanks,
Lijo

Quoted 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;