Skip to contentSkip to conversation

drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing

PATCH In review [email protected] 3 participants 4 messages Apr 18, 2019 – Apr 22, 2019 3 messages not in the archive

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

PATCH 1/1 drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing

From: Leo Li <[email protected]>

smu.ppt_funcs is only initialized for specific SMU versions.

On a Hawaii ASIC, attempting to access the udev attribute ATTRS{power_dpm_state} will cause a null pointer deref in amdgpu_get_dpm_state() because of this.

Fix by checking that ppt_funcs is initialized first.

CC Chengming Gui <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
index 4b7a076..7993623 100644
@@ -144,7 +144,7 @@ static ssize_t amdgpu_get_dpm_state(struct device *dev,
 	struct amdgpu_device *adev = ddev->dev_private;
 	enum amd_pm_state_type pm;
 
-	if (adev->smu.ppt_funcs->get_current_power_state)
+	if (adev->smu.ppt_funcs && adev->smu.ppt_funcs->get_current_power_state)
 		pm = amdgpu_smu_get_current_power_state(adev);
 	else if (adev->powerplay.pp_funcs->get_current_power_state)
 		pm = amdgpu_dpm_get_current_power_state(adev);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1555603187-14645-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#2 lore raw
Quoted 22 lines · On Thu, Apr 18, 2019 at 12:01 PM <[email protected]> wrote:

From: Leo Li <[email protected]>

smu.ppt_funcs is only initialized for specific SMU versions.

On a Hawaii ASIC, attempting to access the udev attribute ATTRS{power_dpm_state} will cause a null pointer deref in amdgpu_get_dpm_state() because of this.

Fix by checking that ppt_funcs is initialized first.

CC Chengming Gui <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
index 4b7a076..7993623 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_dpm_state(struct device *dev, · line 147

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
@@ -144,7 +144,7 @@ static ssize_t amdgpu_get_dpm_state(struct device *dev,
        struct amdgpu_device *adev = ddev->dev_private;
        enum amd_pm_state_type pm;
 
-       if (adev->smu.ppt_funcs->get_current_power_state)
+       if (adev->smu.ppt_funcs && adev->smu.ppt_funcs->get_current_power_state)

For consistency, I think we probably want something like:
if (is_support_sw_smu(adev) && adev->smu.ppt_funcs->get_current_power_state)

Either way:

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -1
                pm = amdgpu_smu_get_current_power_state(adev);
        else if (adev->powerplay.pp_funcs->get_current_power_state)
                pm = amdgpu_dpm_get_current_power_state(adev);
--

2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_OroPQFdyC9XxoKbfMJWz+z4hasgdLtJf59OOuhaaKpnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 42 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Alex Deucher
Sent: Friday, April 19, 2019 10:26 PM
To: Li, Sun peng (Leo) <[email protected]>
Cc: Gui, Jack <[email protected]>; amd-gfx list <amd- [email protected]>
Subject: Re: [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing

Quoted 11 lines · On Thu, Apr 18, 2019 at 12:01 PM <[email protected]> wrote:

From: Leo Li <[email protected]>

smu.ppt_funcs is only initialized for specific SMU versions.

On a Hawaii ASIC, attempting to access the udev attribute ATTRS{power_dpm_state} will cause a null pointer deref in amdgpu_get_dpm_state() because of this.

Fix by checking that ppt_funcs is initialized first.

Review

Quoted 7 lines
CC Chengming Gui <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_dpm_state(struct device

Quoted 4 lines

index 4b7a076..7993623 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
@@ -144,7 +144,7 @@ static ssize_t amdgpu_get_dpm_state(struct device

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_dpm_state(struct device *dev,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
        struct amdgpu_device *adev = ddev->dev_private;
        enum amd_pm_state_type pm;
 
-       if (adev->smu.ppt_funcs->get_current_power_state)
+       if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 get_current_power_state)
Quoted 6 lines

For consistency, I think we probably want something like:
if (is_support_sw_smu(adev) && adev->smu.ppt_funcs-

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_dpm_state(struct device · line 149

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
 get_current_power_state)

Either way:

Yes. The same comment with me. Please use is_support_sw_smu() to check it. With that fixed, please add Reviewed-by: Huang Rui <[email protected]>

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
                pm = amdgpu_smu_get_current_power_state(adev);
        else if (adev->powerplay.pp_funcs->get_current_power_state)
                pm = amdgpu_dpm_get_current_power_state(adev);

--
2.7.4

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MN2PR12MB33099C7B08EB132CB4CE2C45EC220-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
(quoted diff) +1 -1
-       if (adev->smu.ppt_funcs->get_current_power_state)
+       if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-

get_current_power_state)

For consistency, I think we probably want something like:
if (is_support_sw_smu(adev) && adev->smu.ppt_funcs-

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

get_current_power_state)

Either way:

Yes. The same comment with me. Please use is_support_sw_smu() to check it. With that fixed, please add Reviewed-by: Huang Rui <[email protected]>

Will modify and merge.

Thanks,
Leo

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
                 pm = amdgpu_smu_get_current_power_state(adev);
         else if (adev->powerplay.pp_funcs->get_current_power_state)
                 pm = amdgpu_dpm_get_current_power_state(adev);

--
2.7.4

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx