Skip to contentSkip to conversation

drm/amd/pm: parse pp_handle under appropriate conditions

PATCH Superseded Guchun Chen 3 participants 5 messages May 5, 2023 – May 6, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/pm: parse pp_handle under appropriate conditions

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

Fixes ebfc253335af("drm/amd/pm: do not expose the smu_context structure used internally in power")
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -7
index f0068df2d073..ae45abeab5b5 100644
@@ -1455,13 +1455,15 @@ int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
 
 int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
 {
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	struct smu_context *smu = adev->powerplay.pp_handle;
-
-	if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-	    (is_support_sw_smu(adev) && smu->is_apu) ||
-		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
-		return true;
+	if (is_support_sw_smu(adev)) {
+		struct smu_context *smu = adev->powerplay.pp_handle;
+		if (smu->od_enabled || smu->is_apu)
+			return true;
+	} else {
+		struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+		if (hwmgr->od_enabled)
+			return true;
+	}
 
 	return false;
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Guchun Chen

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

Fixes ebfc253335af("drm/amd/pm: do not expose the smu_context structure used internally in power")
---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
index f0068df2d073..ae45abeab5b5 100644
@@ -1455,13 +1455,15 @@ int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
 
  int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
  {
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev, · line 1461

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -6
-	struct smu_context *smu = adev->powerplay.pp_handle;
-
-	if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-	    (is_support_sw_smu(adev) && smu->is_apu) ||
-		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
-		return true;
+	if (is_support_sw_smu(adev)) {
+		struct smu_context *smu = adev->powerplay.pp_handle;
+		if (smu->od_enabled || smu->is_apu)
+	

Minor change - return (smu->od_enabled || smu->is_apu); and similar below for the other check also.

Anyway,

Thanks,
Lijo

		return true;
Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	} else {
+		struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+		if (hwmgr->od_enabled)
+			return true;
+	}
 
  	return false;
  }
#2 lore raw
Quoted 37 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, May 5, 2023 5:00 PM
To: Chen, Guchun <[email protected]>; amd- [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Quan, Evan <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: parse pp_handle under appropriate conditions

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

Quoted 18 lines · Guchun Chen

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

Fixes ebfc253335af("drm/amd/pm: do not expose the smu_context

structure used internally in power")

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index f0068df2d073..ae45abeab5b5 100644
@@ -1455,13 +1455,15 @@ int

amdgpu_dpm_get_smu_prv_buf_details(struct

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
 amdgpu_device *adev,
 
Quoted 16 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -7
  int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
  {
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	struct smu_context *smu = adev->powerplay.pp_handle;
-
-	if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-	    (is_support_sw_smu(adev) && smu->is_apu) ||
-		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
-		return true;
+	if (is_support_sw_smu(adev)) {
+		struct smu_context *smu = adev->powerplay.pp_handle;
+		if (smu->od_enabled || smu->is_apu)
+

Minor change - return (smu->od_enabled || smu->is_apu); and similar below for the other check also.

Make sense, will update in v2 with your RB.

Regards,
Guchun

Quoted 16 lines

Anyway,

Thanks,
Lijo

		return true;
Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	} else {
+		struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+		if (hwmgr->od_enabled)
+			return true;
+	}
 
  	return false;
  }
#3 lore raw
In reply to Guchun Chen

[AMD Official Use Only - General]

+Mario

I believe the comment below from Mario points the right direction to suppress the "UBSAN: invalid-load..." warnings.
https://gitlab.freedesktop.org/drm/amd/-/issues/2541#note_1898035
However, it might be not right to simply drop the line below since the adev->powerplay.pp_handle pointer is still needed for those APIs like amdgpu_dpm_read_sensor().
- adev->powerplay.pp_handle = adev;

BR
Evan

Quoted 55 lines

-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Friday, May 5, 2023 4:24 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Chen, Guchun <[email protected]>
Subject: [PATCH] drm/amd/pm: parse pp_handle under appropriate conditions

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

Fixes ebfc253335af("drm/amd/pm: do not expose the smu_context

structure used internally in power")

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -7
index f0068df2d073..ae45abeab5b5 100644
@@ -1455,13 +1455,15 @@ int
 amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
 
 int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
 {
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	struct smu_context *smu = adev->powerplay.pp_handle;
-
-	if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-	    (is_support_sw_smu(adev) && smu->is_apu) ||
-		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
-		return true;
+	if (is_support_sw_smu(adev)) {
+		struct smu_context *smu = adev->powerplay.pp_handle;
+		if (smu->od_enabled || smu->is_apu)
+			return true;
+	} else {
+		struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+		if (hwmgr->od_enabled)
+			return true;
+	}
 
 	return false;

}
--
2.25.1

#4 lore raw

[AMD Official Use Only - General]

Quoted 16 lines

-----Original Message-----
From: Quan, Evan <[email protected]>
Sent: Saturday, May 6, 2023 9:51 AM
To: Chen, Guchun <[email protected]>; amd- [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Limonciello, Mario <[email protected]>
Subject: RE: [PATCH] drm/amd/pm: parse pp_handle under appropriate conditions

[AMD Official Use Only - General]

+Mario

Quoted 7 lines

I believe the comment below from Mario points the right direction to suppress the "UBSAN: invalid-load..." warnings.
https://gitlab.freedesktop.org/drm/amd/-/issues/2541#note_1898035
However, it might be not right to simply drop the line below since the adev-

Quoted 1 line

powerplay.pp_handle pointer is still needed for those APIs like

amdgpu_dpm_read_sensor().
- adev->powerplay.pp_handle = adev;

Thanks Mario and Evan. I think the new patch set v3 should fix that problem. I will ask reporter to have a try as well.

Regards,
Guchun

Quoted 57 lines

BR
Evan

Quoted 5 lines

-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Friday, May 5, 2023 4:24 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking

<[email protected]>;

Quoted 49 lines

Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Chen, Guchun <[email protected]>
Subject: [PATCH] drm/amd/pm: parse pp_handle under appropriate conditions

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

Fixes ebfc253335af("drm/amd/pm: do not expose the smu_context

structure used internally in power")

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -8
index f0068df2d073..ae45abeab5b5 100644
@@ -1455,13 +1455,15 @@ int
 amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
 
 int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)  {
-   struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-   struct smu_context *smu = adev->powerplay.pp_handle;
-
-   if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-       (is_support_sw_smu(adev) && smu->is_apu) ||
-           (!is_support_sw_smu(adev) && hwmgr->od_enabled))
-           return true;
+   if (is_support_sw_smu(adev)) {
+           struct smu_context *smu = adev->powerplay.pp_handle;
+           if (smu->od_enabled || smu->is_apu)
+                   return true;
+   } else {
+           struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+           if (hwmgr->od_enabled)
+                   return true;
+   }
 
    return false;
 }
--

2.25.1