drm/amdgpu: Fix NULL pointer dereference in APU threshold calculation
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix NULL pointer dereference in APU threshold calculation
The kernel OOPS occurs due to a NULL pointer dereference in amdttm_resource_manager_usage() when accessing the ttm_resource_manager lock, specifically on APU devices:
[ 911.954646] BUG: kernel NULL pointer dereference, address: 00000000000008f8 [ 911.962437] #PF: supervisor write access in kernel mode [ 912.007045] RIP: 0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] amdttm_resource_manager_usage+0x1f/0x40 [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 [amdgpu]
This happens because APU devices (adev->gmc.is_app_apu) don't initialize vram_mgr.manager (no dedicated VRAM), but the code still attempted to calculate memory migration thresholds using VRAM-specific logic.
Fix this by:
1. Merging APU check with the existing bandwidth control support check in amdgpu_cs_get_threshold_for_moves()
2. Returning 0 thresholds immediately for APU devices to skip VRAM-related logic
This prevents accessing uninitialized vram_mgr.manager on APUs and avoids the NULL pointer dereference in _raw_spin_lock().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -709,7 +709,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,*/ const s64 us_upper_bound =200000 ; -if (!adev->mm_stats.log2_max_MBps) { +if ((!adev->mm_stats.log2_max_MBps) || adev->gmc.is_app_apu) { *max_bytes =0 ; *max_vis_bytes =0 ;return ;
Signature · 1 line
2.49.0
Quoted 9 lines · Jesse.Zhang
The kernel OOPS occurs due to a NULL pointer dereference in
amdttm_resource_manager_usage()when accessing thettm_resource_managerlock, specifically on APU devices:[ 911.954646] BUG: kernel NULL pointer dereference, address: 00000000000008f8 [ 911.962437] #PF: supervisor write access in kernel mode [ 912.007045] RIP: 0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] amdttm_resource_manager_usage+0x1f/0x40 [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 [amdgpu]
I just noticed another NULL pointer reference back trace from amdttm_resource_manager_usage, when using rocm-smi on APU, maybe add NULL pointer or is_app_apu check inside amdttm_resource_manager_usage?
BUG: kernel NULL pointer dereference, address: 00000000000008f8 Call Trace: amdttm_resource_manager_usage+0x1f/0x40 [amdttm] amdgpu_mem_info_vram_used_show+0x1e/0x40 [amdgpu] dev_attr_show+0x1d/0x40 kernfs_seq_show+0x27/0x30 seq_read_iter+0x126/0x490 kernfs_fop_read_iter+0x150/0x1d0 new_sync_read+0x101/0x190 vfs_read+0x147/0x1a0 ksys_read+0x67/0xe0 __x64_sys_read+0x1a/0x20
Regards,
Philip
Quoted 30 lines
This happens because APU devices (
adev->gmc.is_app_apu) don't initialize vram_mgr.manager (no dedicated VRAM), but the code still attempted to calculate memory migration thresholds using VRAM-specific logic.Fix this by:
1. Merging APU check with the existing bandwidth control support check inamdgpu_cs_get_threshold_for_moves()
2. Returning 0 thresholds immediately for APU devices to skip VRAM-related logicThis prevents accessing uninitialized vram_mgr.manager on APUs and avoids the NULL pointer dereference in
_raw_spin_lock().Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -709,7 +709,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,*/ const s64 us_upper_bound =200000 ; -if (!adev->mm_stats.log2_max_MBps) { +if ((!adev->mm_stats.log2_max_MBps) || adev->gmc.is_app_apu) { *max_bytes =0 ; *max_vis_bytes =0 ;return ;
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 21 lines
-----Original Message-----
From: Yang, Philip <[email protected]>
Sent: Monday, October 13, 2025 7:55 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix NULL pointer dereference in APU threshold calculationQuoted 9 lines · Jesse.Zhang
The kernel OOPS occurs due to a NULL pointer dereference in
amdttm_resource_manager_usage()when accessing thettm_resource_managerlock, specifically on APU devices:[ 911.954646] BUG: kernel NULL pointer dereference, address: 00000000000008f8 [ 911.962437] #PF: supervisor write access in kernel mode [ 912.007045] RIP: 0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] amdttm_resource_manager_usage+0x1f/0x40 [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 [amdgpu]
Quoted 3 lines
I just noticed another NULL pointer reference back trace from
amdttm_resource_manager_usage, when using rocm-smi on APU, maybe add NULL pointer oris_app_apucheck insideamdttm_resource_manager_usage?
[Zhang, Jesse(Jie)] yes, we need it and will update the patch. Thanks Philip.
Quoted 51 lines
BUG: kernel NULL pointer dereference, address: 00000000000008f8 Call Trace: amdttm_resource_manager_usage+0x1f/0x40 [amdttm] amdgpu_mem_info_vram_used_show+0x1e/0x40 [amdgpu] dev_attr_show+0x1d/0x40 kernfs_seq_show+0x27/0x30 seq_read_iter+0x126/0x490 kernfs_fop_read_iter+0x150/0x1d0 new_sync_read+0x101/0x190 vfs_read+0x147/0x1a0 ksys_read+0x67/0xe0 __x64_sys_read+0x1a/0x20Regards,
Philip
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static void amdgpu_cs_get_threshold_for_moves(struct
Quoted 24 lines
This happens because APU devices (
adev->gmc.is_app_apu) don't initialize vram_mgr.manager (no dedicated VRAM), but the code still attempted to calculate memory migration thresholds using VRAM-specific logic.Fix this by:
1. Merging APU check with the existing bandwidth control support check inamdgpu_cs_get_threshold_for_moves()
2. Returning 0 thresholds immediately for APU devices to skip VRAM-related logicThis prevents accessing uninitialized vram_mgr.manager on APUs and avoids the NULL pointer dereference in
_raw_spin_lock().Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0@@ -709,7 +709,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct
amdgpu_device*adev,Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1*/ const s64 us_upper_bound =200000 ; -if (!adev->mm_stats.log2_max_MBps) { +if ((!adev->mm_stats.log2_max_MBps) || adev->gmc.is_app_apu) { *max_bytes =0 ; *max_vis_bytes =0 ;return ;