This patch adds a NULL check to fix this crash reported during the freeing of root PT entry: [ 06:55] BUG: unable to handle page fault for address: ffffc9002d637aa0 [ +0.007689] #PF: supervisor write access in kernel mode [ +0.005833] #PF: error_code(0x0002) - not-present page [ +0.005732] PGD 100000067 P4D 100000067 PUD 1001ec067 PMD 4882af067 PTE 0 [ +0.007579] Oops: 0002 [#1] PREEMPT SMP NOPTI [ +0.004861] CPU: 52 PID: 8146 Comm: kworker/52:2 Tainted: G OE 5.18.2-mi300-build-140423-ubuntu-22.04+ #24 [ +0.012135] Hardware name: AMD Corporation Sh54p/Sh54p, BIOS WPP4311S 03/11/2024 [ +0.008254] Workqueue: events delayed_fput [ +0.004573] RIP: 0010:amdgpu_vm_pt_free+0x66/0xe0 [amdgpu] [ +0.006270] Code: 01 74 6e 48 c7 45 e8 00 00 00 00 31 f6 48 83 c7 58 e8 0e ea 3b ff 48 8b 03 48 8d 78 38 e8 f2 9b 90 c0 48 8b 43 20 48 8b 53 18 <48> 89 42 08 48 89 10 48 b8 00 01 00 00 00 00 ad de 48 89 43 18 48 [ +0.020954] RSP: 0018:ffffc9002e117c08 EFLAGS: 00010246 [ +0.005830] RAX: ffff8884867bda20 RBX: ffff8884867bd9a8 RCX: 0000000000000000 [ +0.007961] RDX: ffffc9002d637a98 RSI: ffff888482845458 RDI: ffffffffc155916e [ +0.007958] RBP: ffffc9002e117c20 R08: 0000000000000000 R09: 0000000000000001 [ +0.007961] R10: ffff888482843000 R11: 0000000141eed000 R12: ffff8884867bd9a8 [ +0.007959] R13: ffff888471d68098 R14: ffff888471d68098 R15: 00000000c1dab300 [ +0.007960] FS: 0000000000000000(0000) GS:ffff88e1cf700000(0000) knlGS:0000000000000000 [ +0.009027] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ +0.006409] CR2: ffffc9002d637aa0 CR3: 0000000006410006 CR4: 0000000000770ee0 [ +0.007961] PKRU: 55555554 [ +0.003016] Call Trace: [ +0.002726] <TASK> [ +0.002340] amdgpu_vm_pt_free_root+0x60/0xa0 [amdgpu] [ +0.005843] amdgpu_vm_fini+0x2cb/0x5d0 [amdgpu] [ +0.005248] ? amdgpu_ctx_mgr_entity_fini+0x53/0x1c0 [amdgpu] [ +0.006520] amdgpu_driver_postclose_kms+0x191/0x2d0 [amdgpu] [ +0.006520] drm_file_free.part.0+0x1e5/0x260 [drm] Cc: Christian König <Christian.Koenig@xxxxxxx> Cc: Alex Deucher <alexander.deucher@xxxxxxx> Cc: Felix Kuehling <felix.kuehling@xxxxxxx> Cc: Rajneesh Bhardwaj <rajneesh.bhardwaj@xxxxxxx> Signed-off-by: Shashank Sharma <shashank.sharma@xxxxxxx> --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c index d904fc96ba0f..a0a5b955a4b4 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c @@ -688,8 +688,10 @@ void amdgpu_vm_pt_free_root(struct amdgpu_device *adev, struct amdgpu_vm *vm) struct amdgpu_vm_pt_cursor cursor; struct amdgpu_vm_bo_base *entry; - for_each_amdgpu_vm_pt_dfs_safe(adev, vm, NULL, cursor, entry) - amdgpu_vm_pt_free(entry); + for_each_amdgpu_vm_pt_dfs_safe(adev, vm, NULL, cursor, entry) { + if (entry) + amdgpu_vm_pt_free(entry); + } } /** -- 2.43.2