[PATCH] drm/amdgpu/pm: fix the null pointer while the smu is disabled

2022-04-14 Thread Huang Rui
It needs to check if the pp_funcs is initialized while release the
context, otherwise it will trigger null pointer panic while the software
smu is not enabled.

[ 1109.404555] BUG: kernel NULL pointer dereference, address: 0078
[ 1109.404609] #PF: supervisor read access in kernel mode
[ 1109.404638] #PF: error_code(0x) - not-present page
[ 1109.404657] PGD 0 P4D 0
[ 1109.404672] Oops:  [#1] PREEMPT SMP NOPTI
[ 1109.404701] CPU: 7 PID: 9150 Comm: amdgpu_test Tainted: G   OEL
5.16.0-custom #1
[ 1109.404732] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS 
VirtualBox 12/01/2006
[ 1109.404765] RIP: 0010:amdgpu_dpm_force_performance_level+0x1d/0x170 [amdgpu]
[ 1109.405109] Code: 5d c3 44 8b a3 f0 80 00 00 eb e5 66 90 0f 1f 44 00 00 55 
48 89 e5 41 57 41 56 41 55 41 54 53 48 83 ec 08 4c 8b b7 f0 7d 00 00 <49> 83 7e 
78 00 0f 84 f2 00 00 00 80 bf 87 80 00 00 00 48 89 fb 0f
[ 1109.405176] RSP: 0018:af3083ad7c20 EFLAGS: 00010282
[ 1109.405203] RAX:  RBX: 9796b1c14600 RCX: 02862007
[ 1109.405229] RDX: 97968591c8c0 RSI: 0001 RDI: 9796a370
[ 1109.405260] RBP: af3083ad7c50 R08: 9897de00 R09: 979688d9db60
[ 1109.405286] R10:  R11: 979688d9db90 R12: 0001
[ 1109.405316] R13: 9796a370 R14:  R15: 9796a3708fc0
[ 1109.405345] FS:  7ff055cff180() GS:9796bfdc() 
knlGS:
[ 1109.405378] CS:  0010 DS:  ES:  CR0: 80050033
[ 1109.405400] CR2: 0078 CR3: 0a394000 CR4: 000506e0
[ 1109.405434] Call Trace:
[ 1109.405445]  
[ 1109.405456]  ? delete_object_full+0x1d/0x20
[ 1109.405480]  amdgpu_ctx_set_stable_pstate+0x7c/0xa0 [amdgpu]
[ 1109.405698]  amdgpu_ctx_fini.part.0+0xcb/0x100 [amdgpu]
[ 1109.405911]  amdgpu_ctx_do_release+0x71/0x80 [amdgpu]
[ 1109.406121]  amdgpu_ctx_ioctl+0x52d/0x550 [amdgpu]
[ 1109.406327]  ? _raw_spin_unlock+0x1a/0x30
[ 1109.406354]  ? drm_gem_handle_delete+0x81/0xb0 [drm]
[ 1109.406400]  ? amdgpu_ctx_get_entity+0x2c0/0x2c0 [amdgpu]
[ 1109.406609]  drm_ioctl_kernel+0xb6/0x140 [drm]

Signed-off-by: Huang Rui 
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c 
b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 1d63f1e8884c..428623e64e8f 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -717,7 +717,7 @@ int amdgpu_dpm_force_performance_level(struct amdgpu_device 
*adev,
AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
 
-   if (!pp_funcs->force_performance_level)
+   if (!pp_funcs || !pp_funcs->force_performance_level)
return 0;
 
if (adev->pm.dpm.thermal_active)
-- 
2.25.1



RE: [PATCH] drm/amdgpu/pm: fix the null pointer while the smu is disabled

2022-04-14 Thread Liu, Aaron
[AMD Official Use Only]

Reviewed-by: Aaron Liu 

> -Original Message-
> From: amd-gfx  On Behalf Of
> Huang Rui
> Sent: Friday, April 15, 2022 12:13 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander ; Huang, Tim
> ; Quan, Evan ; Huang, Ray
> ; Du, Xiaojian 
> Subject: [PATCH] drm/amdgpu/pm: fix the null pointer while the smu is
> disabled
> 
> It needs to check if the pp_funcs is initialized while release the context,
> otherwise it will trigger null pointer panic while the software smu is not
> enabled.
> 
> [ 1109.404555] BUG: kernel NULL pointer dereference, address:
> 0078 [ 1109.404609] #PF: supervisor read access in kernel mode
> [ 1109.404638] #PF: error_code(0x) - not-present page [ 1109.404657]
> PGD 0 P4D 0 [ 1109.404672] Oops:  [#1] PREEMPT SMP NOPTI
> [ 1109.404701] CPU: 7 PID: 9150 Comm: amdgpu_test Tainted: G   OEL
> 5.16.0-custom #1
> [ 1109.404732] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS
> VirtualBox 12/01/2006 [ 1109.404765] RIP:
> 0010:amdgpu_dpm_force_performance_level+0x1d/0x170 [amdgpu]
> [ 1109.405109] Code: 5d c3 44 8b a3 f0 80 00 00 eb e5 66 90 0f 1f 44 00 00 55 
> 48
> 89 e5 41 57 41 56 41 55 41 54 53 48 83 ec 08 4c 8b b7 f0 7d 00 00 <49> 83 7e 
> 78
> 00 0f 84 f2 00 00 00 80 bf 87 80 00 00 00 48 89 fb 0f [ 1109.405176] RSP:
> 0018:af3083ad7c20 EFLAGS: 00010282 [ 1109.405203] RAX:
>  RBX: 9796b1c14600 RCX: 02862007
> [ 1109.405229] RDX: 97968591c8c0 RSI: 0001 RDI:
> 9796a370 [ 1109.405260] RBP: af3083ad7c50 R08: 9897de00
> R09: 979688d9db60 [ 1109.405286] R10:  R11:
> 979688d9db90 R12: 0001 [ 1109.405316] R13:
> 9796a370 R14:  R15: 9796a3708fc0 [ 1109.405345]
> FS:  7ff055cff180() GS:9796bfdc()
> knlGS: [ 1109.405378] CS:  0010 DS:  ES:  CR0:
> 80050033 [ 1109.405400] CR2: 0078 CR3:
> 0a394000 CR4: 000506e0 [ 1109.405434] Call Trace:
> [ 1109.405445]  
> [ 1109.405456]  ? delete_object_full+0x1d/0x20 [ 1109.405480]
> amdgpu_ctx_set_stable_pstate+0x7c/0xa0 [amdgpu] [ 1109.405698]
> amdgpu_ctx_fini.part.0+0xcb/0x100 [amdgpu] [ 1109.405911]
> amdgpu_ctx_do_release+0x71/0x80 [amdgpu] [ 1109.406121]
> amdgpu_ctx_ioctl+0x52d/0x550 [amdgpu] [ 1109.406327]  ?
> _raw_spin_unlock+0x1a/0x30 [ 1109.406354]  ?
> drm_gem_handle_delete+0x81/0xb0 [drm] [ 1109.406400]  ?
> amdgpu_ctx_get_entity+0x2c0/0x2c0 [amdgpu] [ 1109.406609]
> drm_ioctl_kernel+0xb6/0x140 [drm]
> 
> Signed-off-by: Huang Rui 
> ---
>  drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
> b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
> index 1d63f1e8884c..428623e64e8f 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
> @@ -717,7 +717,7 @@ int amdgpu_dpm_force_performance_level(struct
> amdgpu_device *adev,
> 
>   AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
> 
>   AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
> 
> - if (!pp_funcs->force_performance_level)
> + if (!pp_funcs || !pp_funcs->force_performance_level)
>   return 0;
> 
>   if (adev->pm.dpm.thermal_active)
> --
> 2.25.1