All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing
@ 2019-04-18 15:59 sunpeng.li-5C7GfCeVMHo
       [not found] ` <1555603187-14645-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: sunpeng.li-5C7GfCeVMHo @ 2019-04-18 15:59 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Leo Li, Chengming Gui

From: Leo Li <sunpeng.li@amd.com>

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 <Jack.Gui@amd.com>
Signed-off-by: Leo Li <sunpeng.li@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 4b7a076..7993623 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -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);
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing
       [not found] ` <1555603187-14645-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-19 14:26   ` Alex Deucher
       [not found]     ` <CADnq5_OroPQFdyC9XxoKbfMJWz+z4hasgdLtJf59OOuhaaKpnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Deucher @ 2019-04-19 14:26 UTC (permalink / raw)
  To: Leo (Sunpeng) Li; +Cc: Chengming Gui, amd-gfx list

On Thu, Apr 18, 2019 at 12:01 PM <sunpeng.li@amd.com> wrote:
>
> From: Leo Li <sunpeng.li@amd.com>
>
> 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 <Jack.Gui@amd.com>
> Signed-off-by: Leo Li <sunpeng.li@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 4b7a076..7993623 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -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:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

>                 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
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing
       [not found]     ` <CADnq5_OroPQFdyC9XxoKbfMJWz+z4hasgdLtJf59OOuhaaKpnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-04-22  9:05       ` Huang, Ray
       [not found]         ` <MN2PR12MB33099C7B08EB132CB4CE2C45EC220-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Huang, Ray @ 2019-04-22  9:05 UTC (permalink / raw)
  To: Alex Deucher, Li, Sun peng (Leo); +Cc: Gui, Jack, amd-gfx list

> -----Original Message-----
> From: amd-gfx [mailto:amd-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Alex Deucher
> Sent: Friday, April 19, 2019 10:26 PM
> To: Li, Sun peng (Leo) <Sunpeng.Li@amd.com>
> Cc: Gui, Jack <Jack.Gui@amd.com>; amd-gfx list <amd-
> gfx@lists.freedesktop.org>
> Subject: Re: [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized
> before accessing
> 
> On Thu, Apr 18, 2019 at 12:01 PM <sunpeng.li@amd.com> wrote:
> >
> > From: Leo Li <sunpeng.li@amd.com>
> >
> > 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 <Jack.Gui@amd.com>
> > Signed-off-by: Leo Li <sunpeng.li@amd.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index 4b7a076..7993623 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -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:
> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

Yes. The same comment with me. Please use is_support_sw_smu() to check it.
With that fixed, please add Reviewed-by: Huang Rui <ray.huang@amd.com>

> 
> >                 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
> > amd-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing
       [not found]         ` <MN2PR12MB33099C7B08EB132CB4CE2C45EC220-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-04-22 13:27           ` Li, Sun peng (Leo)
  0 siblings, 0 replies; 4+ messages in thread
From: Li, Sun peng (Leo) @ 2019-04-22 13:27 UTC (permalink / raw)
  To: Huang, Ray, Alex Deucher; +Cc: Gui, Jack, amd-gfx list

>>> -       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:
>> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
> 
> Yes. The same comment with me. Please use is_support_sw_smu() to check it.
> With that fixed, please add Reviewed-by: Huang Rui <ray.huang@amd.com>
> 

Will modify and merge.

Thanks,
Leo

>>
>>>                  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
>>> amd-gfx@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-22 13:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18 15:59 [PATCH] drm/amdgpu: Check if smu.ppt_funcs is initialized before accessing sunpeng.li-5C7GfCeVMHo
     [not found] ` <1555603187-14645-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2019-04-19 14:26   ` Alex Deucher
     [not found]     ` <CADnq5_OroPQFdyC9XxoKbfMJWz+z4hasgdLtJf59OOuhaaKpnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-04-22  9:05       ` Huang, Ray
     [not found]         ` <MN2PR12MB33099C7B08EB132CB4CE2C45EC220-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-04-22 13:27           ` Li, Sun peng (Leo)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.