Skip to contentSkip to conversation

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

PATCH In review Guchun Chen 3 participants 4 messages May 9, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

Prevent further casting on chip MULLINS/KABINI/KAVERI when calling amdgpu_dpm_is_overdrive_supported, this can avoid UBSAN complain in init sequence.

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -2
index 86246f69dbe1..ccd3ea89eacf 100644
@@ -1467,8 +1467,14 @@ 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)
+		/*
+		 * SI asic and chip MULLINS/KABINI/KAVERI do not carry
+		 * od_enabled, as its pp_handle is casted from adev.
+		 */
+		if ((adev->family == AMDGPU_FAMILY_SI) ||
+		    (adev->asic_type == CHIP_MULLINS) ||
+		    (adev->asic_type == CHIP_KABINI) ||
+		    (adev->asic_type == CHIP_KAVERI))
 			return false;
 
 		hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

[AMD Official Use Only - General]

Quoted 45 lines

-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Tuesday, May 9, 2023 9:43 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] drm/amd/pm: avoid potential UBSAN issue on legacy asics

Prevent further casting on chip MULLINS/KABINI/KAVERI when calling amdgpu_dpm_is_overdrive_supported, this can avoid UBSAN complain in init sequence.

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -2
index 86246f69dbe1..ccd3ea89eacf 100644
@@ -1467,8 +1467,14 @@ 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)
+		/*
+		 * SI asic and chip MULLINS/KABINI/KAVERI do not carry
+		 * od_enabled, as its pp_handle is casted from adev.
+		 */
+		if ((adev->family == AMDGPU_FAMILY_SI) ||
+		    (adev->asic_type == CHIP_MULLINS) ||
+		    (adev->asic_type == CHIP_KABINI) ||
+		    (adev->asic_type == CHIP_KAVERI))
 			return false;
 

hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
--
2.25.1

#2 lore raw
In reply to Guchun Chen
Quoted 15 lines · Guchun Chen

Prevent further casting on chip MULLINS/KABINI/KAVERI when calling amdgpu_dpm_is_overdrive_supported, this can avoid UBSAN complain in init sequence.

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 86246f69dbe1..ccd3ea89eacf 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev) · line 1469

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1467,8 +1467,14 @@ int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
  	} else {
  		struct pp_hwmgr *hwmgr;
 

Instead of family check, what if you wrap it like -

is_legacy_dpm(adev)

	return (adev->powerplay.pp_handle == adev)

Could be useful for legacy dpm checks.

Thanks,
Lijo

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -2
-		/* SI asic does not carry od_enabled */
-		if (adev->family == AMDGPU_FAMILY_SI)
+		/*
+		 * SI asic and chip MULLINS/KABINI/KAVERI do not carry
+		 * od_enabled, as its pp_handle is casted from adev.
+		 */
+		if ((adev->family == AMDGPU_FAMILY_SI) ||
+		    (adev->asic_type == CHIP_MULLINS) ||
+		    (adev->asic_type == CHIP_KABINI) ||
+		    (adev->asic_type == CHIP_KAVERI))
  			return false;
 
  		hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
#3 lore raw
Quoted 36 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, May 9, 2023 11:47 AM
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

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 16 lines · Guchun Chen

Prevent further casting on chip MULLINS/KABINI/KAVERI when calling amdgpu_dpm_is_overdrive_supported, this can avoid UBSAN complain in init sequence.

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 86246f69dbe1..ccd3ea89eacf 100644
@@ -1467,8 +1467,14 @@ int

amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev) · line 1469

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  	} else {
  		struct pp_hwmgr *hwmgr;
 
Quoted 6 lines

Instead of family check, what if you wrap it like -

is_legacy_dpm(adev)

	return (adev->powerplay.pp_handle == adev)

Could be useful for legacy dpm checks.

Sounds good. Will address it in v2.

Regards,
Guchun

Quoted 16 lines

Thanks,
Lijo

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -2
-		/* SI asic does not carry od_enabled */
-		if (adev->family == AMDGPU_FAMILY_SI)
+		/*
+		 * SI asic and chip MULLINS/KABINI/KAVERI do not carry
+		 * od_enabled, as its pp_handle is casted from adev.
+		 */
+		if ((adev->family == AMDGPU_FAMILY_SI) ||
+		    (adev->asic_type == CHIP_MULLINS) ||
+		    (adev->asic_type == CHIP_KABINI) ||
+		    (adev->asic_type == CHIP_KAVERI))
  			return false;
 
  		hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;