drm/amdgpu: fix the error handling of amdgpu_vm_init_entities()
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix the error handling of amdgpu_vm_init_entities()
When initializing the immediate entity fails, amdgpu_vm_init_entities() destroys that entity which was never set up, and when initializing the delayed entity fails, it returns without destroying the immediate one.
On navi48, with the allocation of the immediate entity's scheduler list failing through failslab while opening the render node:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:do_raw_spin_lock+0x7b/0x280 _raw_spin_lock+0x3c/0x50 drm_sched_rq_remove_entity+0x90/0x2a0 [gpu_sched] drm_sched_entity_kill+0x86/0x5a0 [gpu_sched] drm_sched_entity_fini+0x23/0x270 [gpu_sched] drm_sched_entity_destroy+0x24/0x30 [gpu_sched] amdgpu_vm_init_entities+0xc7/0x100 [amdgpu] amdgpu_vm_init+0x5d1/0x1480 [amdgpu] amdgpu_driver_open_kms+0x2b1/0xd10 [amdgpu]
Only destroy the immediate entity once it exists and the delayed one failed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -3
@@ -533,12 +533,16 @@ static int amdgpu_vm_init_entities(struct amdgpu_device *adev, r =drm_sched_entity_init (&vm->immediate,DRM_SCHED_PRIORITY_NORMAL , adev->vm_manager.vm_pte_scheds, adev->vm_manager.vm_pte_num_scheds,NULL ); +if (r) +return r; + + r =drm_sched_entity_init (&vm->delayed,DRM_SCHED_PRIORITY_NORMAL , + adev->vm_manager.vm_pte_scheds, + adev->vm_manager.vm_pte_num_scheds,NULL );if (r) goto error; -return drm_sched_entity_init (&vm->delayed,DRM_SCHED_PRIORITY_NORMAL , - adev->vm_manager.vm_pte_scheds, - adev->vm_manager.vm_pte_num_scheds,NULL ); +return 0 ; error:drm_sched_entity_destroy (&vm->immediate);
Signature · 1 line
2.50.1
Quoted 19 lines · Jesse Zhang
When initializing the immediate entity fails,
amdgpu_vm_init_entities()destroys that entity which was never set up, and when initializing the delayed entity fails, it returns without destroying the immediate one.On navi48, with the allocation of the immediate entity's scheduler list failing through failslab while opening the render node:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:do_raw_spin_lock+0x7b/0x280 _raw_spin_lock+0x3c/0x50 drm_sched_rq_remove_entity+0x90/0x2a0 [gpu_sched] drm_sched_entity_kill+0x86/0x5a0 [gpu_sched] drm_sched_entity_fini+0x23/0x270 [gpu_sched] drm_sched_entity_destroy+0x24/0x30 [gpu_sched] amdgpu_vm_init_entities+0xc7/0x100 [amdgpu] amdgpu_vm_init+0x5d1/0x1480 [amdgpu] amdgpu_driver_open_kms+0x2b1/0xd10 [amdgpu]
Quoted 5 lines
Only destroy the immediate entity once it exists and the delayed one failed.
Fixes 55bf196f60df ("drm/amdgpu: reset VM when an error is detected")Signed-off-by Jesse Zhang <[email protected]>
Quoted 28 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-3@@ -533,12 +533,16 @@ static int amdgpu_vm_init_entities(struct amdgpu_device *adev, r =drm_sched_entity_init (&vm->immediate,DRM_SCHED_PRIORITY_NORMAL , adev->vm_manager.vm_pte_scheds, adev->vm_manager.vm_pte_num_scheds,NULL ); +if (r) +return r; + + r =drm_sched_entity_init (&vm->delayed,DRM_SCHED_PRIORITY_NORMAL , + adev->vm_manager.vm_pte_scheds, + adev->vm_manager.vm_pte_num_scheds,NULL );if (r) goto error; -return drm_sched_entity_init (&vm->delayed,DRM_SCHED_PRIORITY_NORMAL , - adev->vm_manager.vm_pte_scheds, - adev->vm_manager.vm_pte_num_scheds,NULL ); +return 0 ; error:drm_sched_entity_destroy (&vm->immediate);