Never take root bo reservation locks with userq_mutex
Subsystems (2)
v3 cover Never take root bo reservation locks with userq_mutex
v1: Fixes the locks issue in all the places where userq_mutex is taken and then vm->root.bo reservation lock is next.
v2: Fix the minor comment on the patches.
v3: Add some more userq fixes found during testing
Sunil Khatri (6):
drm/amdgpu/userq: caller to take reserv lock for vas_list_cleanup drm/amdgpu/userq: hold root bo lock in caller of input_va_validate drm/amdgpu: add job->pasid in check as amdgpu_job could be NULL drm/amdgpu/userq: use pm_runtime_resume_and_get and fix err handling drm/amdgpu/userq: unmap is to be called before freeing doorbell/wptr
bo
drm/amdgpu/userq: unmap_helper dont return the queue state
.../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 86 ++++++++++--------- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 21 +++++ 3 files changed, 69 insertions(+), 40 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/6 drm/amdgpu/userq: caller to take reserv lock for vas_list_cleanup
In function amdgpu_userq_buffer_vas_list_cleanup, remove the reservation lock for vm and caller should make sure it's taken before locking userq_mutex.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 26 ++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +14 -12
@@ -312,25 +312,21 @@ static int amdgpu_userq_buffer_vas_list_cleanup(struct amdgpu_device *adev, {struct amdgpu_userq_va_cursor *va_cursor, *tmp;struct amdgpu_bo_va_mapping *mapping; -int r; - r =amdgpu_bo_reserve (queue->vm->root.bo, false); -if (r) -return r; +/* Caller must hold vm->root.bo reservation */ +dma_resv_assert_held (queue->vm->root.bo->tbo.base.resv);list_for_each_entry_safe (va_cursor, tmp, &queue->userq_va_list, list) { mapping =amdgpu_vm_bo_lookup_mapping (queue->vm, va_cursor->gpu_addr);if (!mapping) { - r = -EINVAL ; - goto err; +return -EINVAL ; }dev_dbg (adev->dev,"delete the userq:%p va:%llx\n" , queue, va_cursor->gpu_addr);amdgpu_userq_buffer_va_list_del (mapping, va_cursor); } -err: -amdgpu_bo_unreserve (queue->vm->root.bo); -return r; + +return 0 ; }static int amdgpu_userq_preempt_helper (struct amdgpu_usermode_queue *queue)
@@ -444,8 +440,6 @@ static void amdgpu_userq_cleanup(struct amdgpu_usermode_queue *queue)/* Wait for mode-1 reset to complete */ down_read (&adev->reset_domain->sem); -/* Drop the userq reference. */ -amdgpu_userq_buffer_vas_list_cleanup (adev, queue); uq_funcs->mqd_destroy (queue);/* Use interrupt-safe locking since IRQ handlers may access these XArrays */ xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index);
@@ -626,6 +620,9 @@ static int amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue) { struct amdgpu_device *adev = uq_mgr->adev; +struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (uq_mgr); +struct amdgpu_vm *vm = &fpriv->vm; +int r =0 ;cancel_delayed_work_sync (&uq_mgr->resume_work);
@@ -633,6 +630,10 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que/* Cancel any pending hang detection work and cleanup */ cancel_delayed_work_sync (&queue->hang_detect_work); +amdgpu_bo_reserve (vm->root.bo, true); +amdgpu_userq_buffer_vas_list_cleanup (adev, queue); +amdgpu_bo_unreserve (vm->root.bo); +mutex_lock (&uq_mgr->userq_mutex); queue->hang_detect_fence =NULL ;amdgpu_userq_wait_for_last_fence (queue);
@@ -664,7 +665,6 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que }amdgpu_userq_cleanup (queue);mutex_unlock (&uq_mgr->userq_mutex); -pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);return r;
@@ -856,7 +856,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) clean_fence_driver:amdgpu_userq_fence_driver_free (queue); clean_mapping: +amdgpu_bo_reserve (fpriv->vm.root.bo, true);amdgpu_userq_buffer_vas_list_cleanup (adev, queue); +amdgpu_bo_unreserve (fpriv->vm.root.bo);kfree (queue);return r; }
Signature · 1 line
2.34.1
Re: [PATCH v3 1/6] drm/amdgpu/userq: caller to take reserv lock for vas_list_cleanup
Quoted 5 lines · Sunil Khatri
In function
amdgpu_userq_buffer_vas_list_cleanup, remove the reservation lock for vm and caller should make sure it's taken before lockinguserq_mutex.Signed-off-by Sunil Khatri <[email protected]>
Quoted 87 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 26 ++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +14
-12@@ -312,25 +312,21 @@ static int amdgpu_userq_buffer_vas_list_cleanup(struct amdgpu_device *adev, {struct amdgpu_userq_va_cursor *va_cursor, *tmp;struct amdgpu_bo_va_mapping *mapping; -int r; - r =amdgpu_bo_reserve (queue->vm->root.bo, false); -if (r) -return r; +/* Caller must hold vm->root.bo reservation */ +dma_resv_assert_held (queue->vm->root.bo->tbo.base.resv);list_for_each_entry_safe (va_cursor, tmp, &queue->userq_va_list, list) { mapping =amdgpu_vm_bo_lookup_mapping (queue->vm, va_cursor->gpu_addr);if (!mapping) { - r = -EINVAL ; - goto err; +return -EINVAL ; }dev_dbg (adev->dev,"delete the userq:%p va:%llx\n" , queue, va_cursor->gpu_addr);amdgpu_userq_buffer_va_list_del (mapping, va_cursor); } -err: -amdgpu_bo_unreserve (queue->vm->root.bo); -return r; + +return 0 ; }static int amdgpu_userq_preempt_helper (struct amdgpu_usermode_queue *queue)@@ -444,8 +440,6 @@ static void amdgpu_userq_cleanup(struct amdgpu_usermode_queue *queue)/* Wait for mode-1 reset to complete */ down_read (&adev->reset_domain->sem); -/* Drop the userq reference. */ -amdgpu_userq_buffer_vas_list_cleanup (adev, queue); uq_funcs->mqd_destroy (queue);/* Use interrupt-safe locking since IRQ handlers may access these XArrays */ xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index);@@ -626,6 +620,9 @@ static int amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue) { struct amdgpu_device *adev = uq_mgr->adev; +struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (uq_mgr); +struct amdgpu_vm *vm = &fpriv->vm; +int r =0 ;cancel_delayed_work_sync (&uq_mgr->resume_work);@@ -633,6 +630,10 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que/* Cancel any pending hang detection work and cleanup */ cancel_delayed_work_sync (&queue->hang_detect_work); +amdgpu_bo_reserve (vm->root.bo, true); +amdgpu_userq_buffer_vas_list_cleanup (adev, queue); +amdgpu_bo_unreserve (vm->root.bo); +mutex_lock (&uq_mgr->userq_mutex); queue->hang_detect_fence =NULL ;amdgpu_userq_wait_for_last_fence (queue);@@ -664,7 +665,6 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que }amdgpu_userq_cleanup (queue);mutex_unlock (&uq_mgr->userq_mutex); -pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);return r;@@ -856,7 +856,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) clean_fence_driver:amdgpu_userq_fence_driver_free (queue); clean_mapping: +amdgpu_bo_reserve (fpriv->vm.root.bo, true);amdgpu_userq_buffer_vas_list_cleanup (adev, queue); +amdgpu_bo_unreserve (fpriv->vm.root.bo);kfree (queue);return r; }
PATCH v3 2/6 drm/amdgpu/userq: hold root bo lock in caller of input_va_validate
In reply to Sunil KhatriCaller should hold the reservation lock for root.bo in func amdgpu_userq_input_va_validate.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 17 +++++++++++------ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11 -6
@@ -239,13 +239,12 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,u64 size;int r =0 ; +/* Caller must hold vm->root.bo reservation */ +dma_resv_assert_held (queue->vm->root.bo->tbo.base.resv); + user_addr = (addr &AMDGPU_GMC_HOLE_MASK ) >>AMDGPU_GPU_PAGE_SHIFT ; size = expected_size >>AMDGPU_GPU_PAGE_SHIFT ; - r =amdgpu_bo_reserve (vm->root.bo, false); -if (r) -return r; - va_map =amdgpu_vm_bo_lookup_mapping (vm, user_addr);if (!va_map) { r = -EINVAL ;
@@ -255,13 +254,11 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,if (user_addr >= va_map->start && va_map->last - user_addr +1 >= size) {amdgpu_userq_buffer_va_list_add (queue, va_map, user_addr); -amdgpu_bo_unreserve (vm->root.bo);return 0 ; } r = -EINVAL ; out_err: -amdgpu_bo_unreserve (vm->root.bo);return r; }
@@ -769,13 +766,20 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) db_info.doorbell_offset = args->in.doorbell_offset; queue->userq_mgr = uq_mgr; +/* Validate the userq virtual address.*/ + r =amdgpu_bo_reserve (fpriv->vm.root.bo, false); +if (r) + goto free_queue; +if (amdgpu_userq_input_va_validate (adev, queue, args->in.queue_va, args->in.queue_size) ||amdgpu_userq_input_va_validate (adev, queue, args->in.rptr_va,AMDGPU_GPU_PAGE_SIZE ) ||amdgpu_userq_input_va_validate (adev, queue, args->in.wptr_va,AMDGPU_GPU_PAGE_SIZE )) { r = -EINVAL ; +amdgpu_bo_unreserve (fpriv->vm.root.bo); goto clean_mapping; } +amdgpu_bo_unreserve (fpriv->vm.root.bo);/* Convert relative doorbell offset into absolute doorbell index */ index =amdgpu_userq_get_doorbell_index (uq_mgr, &db_info, filp);
@@ -859,6 +863,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)amdgpu_bo_reserve (fpriv->vm.root.bo, true);amdgpu_userq_buffer_vas_list_cleanup (adev, queue);amdgpu_bo_unreserve (fpriv->vm.root.bo); +free_queue:kfree (queue);return r; }
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +21 -0
@@ -322,8 +322,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, goto free_mqd; } + r =amdgpu_bo_reserve (queue->vm->root.bo, false); +if (r) { +kfree (compute_mqd); + goto free_mqd; + } r =amdgpu_userq_input_va_validate (adev, queue, compute_mqd->eop_va,2048 ); +amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (compute_mqd); goto free_mqd;
@@ -365,14 +371,22 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, userq_props->tmz_queue = mqd_user->flags &AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE ; + r =amdgpu_bo_reserve (queue->vm->root.bo, false); +if (r) { +kfree (mqd_gfx_v11); + goto free_mqd; + } r =amdgpu_userq_input_va_validate (adev, queue, mqd_gfx_v11->shadow_va, shadow_info.shadow_size);if (r) { +amdgpu_bo_unreserve (queue->vm->root.bo);kfree (mqd_gfx_v11); goto free_mqd; } + r =amdgpu_userq_input_va_validate (adev, queue, mqd_gfx_v11->csa_va, shadow_info.csa_size); +amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (mqd_gfx_v11); goto free_mqd;
@@ -394,8 +408,15 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, r = -ENOMEM ; goto free_mqd; } + + r =amdgpu_bo_reserve (queue->vm->root.bo, false); +if (r) { +kfree (mqd_sdma_v11); + goto free_mqd; + } r =amdgpu_userq_input_va_validate (adev, queue, mqd_sdma_v11->csa_va,32 ); +amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (mqd_sdma_v11); goto free_mqd;
Signature · 1 line
2.34.1
Re: [PATCH v3 2/6] drm/amdgpu/userq: hold root bo lock in caller of input_va_validate
Quoted 4 lines · Sunil Khatri
Caller should hold the reservation lock for root.bo in func
amdgpu_userq_input_va_validate.Signed-off-by Sunil Khatri <[email protected]>
Quoted 127 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 17 +++++++++++------ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11
-6@@ -239,13 +239,12 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,u64 size;int r =0 ; +/* Caller must hold vm->root.bo reservation */ +dma_resv_assert_held (queue->vm->root.bo->tbo.base.resv); + user_addr = (addr &AMDGPU_GMC_HOLE_MASK ) >>AMDGPU_GPU_PAGE_SHIFT ; size = expected_size >>AMDGPU_GPU_PAGE_SHIFT ; - r =amdgpu_bo_reserve (vm->root.bo, false); -if (r) -return r; - va_map =amdgpu_vm_bo_lookup_mapping (vm, user_addr);if (!va_map) { r = -EINVAL ;@@ -255,13 +254,11 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,if (user_addr >= va_map->start && va_map->last - user_addr +1 >= size) {amdgpu_userq_buffer_va_list_add (queue, va_map, user_addr); -amdgpu_bo_unreserve (vm->root.bo);return 0 ; } r = -EINVAL ; out_err: -amdgpu_bo_unreserve (vm->root.bo);return r; }@@ -769,13 +766,20 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) db_info.doorbell_offset = args->in.doorbell_offset; queue->userq_mgr = uq_mgr; +/* Validate the userq virtual address.*/ + r =amdgpu_bo_reserve (fpriv->vm.root.bo, false); +if (r) + goto free_queue; +if (amdgpu_userq_input_va_validate (adev, queue, args->in.queue_va, args->in.queue_size) ||amdgpu_userq_input_va_validate (adev, queue, args->in.rptr_va,AMDGPU_GPU_PAGE_SIZE ) ||amdgpu_userq_input_va_validate (adev, queue, args->in.wptr_va,AMDGPU_GPU_PAGE_SIZE )) { r = -EINVAL ; +amdgpu_bo_unreserve (fpriv->vm.root.bo); goto clean_mapping; } +amdgpu_bo_unreserve (fpriv->vm.root.bo);/* Convert relative doorbell offset into absolute doorbell index */ index =amdgpu_userq_get_doorbell_index (uq_mgr, &db_info, filp);@@ -859,6 +863,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)amdgpu_bo_reserve (fpriv->vm.root.bo, true);amdgpu_userq_buffer_vas_list_cleanup (adev, queue);amdgpu_bo_unreserve (fpriv->vm.root.bo); +free_queue:kfree (queue);return r; }drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +21
-0@@ -322,8 +322,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, goto free_mqd; } + r =amdgpu_bo_reserve (queue->vm->root.bo, false); +if (r) { +kfree (compute_mqd); + goto free_mqd; + } r =amdgpu_userq_input_va_validate (adev, queue, compute_mqd->eop_va,2048 ); +amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (compute_mqd); goto free_mqd;@@ -365,14 +371,22 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, userq_props->tmz_queue = mqd_user->flags &AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE ; + r =amdgpu_bo_reserve (queue->vm->root.bo, false); +if (r) { +kfree (mqd_gfx_v11); + goto free_mqd; + } r =amdgpu_userq_input_va_validate (adev, queue, mqd_gfx_v11->shadow_va, shadow_info.shadow_size);if (r) { +amdgpu_bo_unreserve (queue->vm->root.bo);kfree (mqd_gfx_v11); goto free_mqd; } + r =amdgpu_userq_input_va_validate (adev, queue, mqd_gfx_v11->csa_va, shadow_info.csa_size); +amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (mqd_gfx_v11); goto free_mqd;@@ -394,8 +408,15 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, r = -ENOMEM ; goto free_mqd; } + + r =amdgpu_bo_reserve (queue->vm->root.bo, false); +if (r) { +kfree (mqd_sdma_v11); + goto free_mqd; + } r =amdgpu_userq_input_va_validate (adev, queue, mqd_sdma_v11->csa_va,32 ); +amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (mqd_sdma_v11); goto free_mqd;
PATCH v3 3/6 drm/amdgpu: add job->pasid in check as amdgpu_job could be NULL
In reply to Sunil KhatriIn below stack job->pasid is accessed while job is NULL. Access it within the check when job is non NULL.
Failure call stack.
[ 222.653622] BUG: kernel NULL pointer dereference, address: 000000000000014c [ 222.653625] #PF: supervisor read access in kernel mode [ 222.653628] #PF: error_code(0x0000) - not-present page [ 222.653630] PGD 0 P4D 0 [ 222.653635] Oops: Oops: 0000 [#1] SMP NOPTI [ 222.653639] CPU: 1 UID: 0 PID: 12 Comm: kworker/u96:0 Not tainted 6.19.0-amd-staging-drm-next #271 PREEMPT(voluntary) [ 222.653644] Hardware name: Gigabyte Technology Co., Ltd. X570 AORUS ELITE/X570 AORUS ELITE, BIOS F37c 05/12/2022 [ 222.653646] Workqueue: amdgpu-reset-dev amdgpu_userq_reset_work [amdgpu] [ 222.653961] RIP: 0010:amdgpu_coredump+0x8b/0x470 [amdgpu] [ 222.654158] Code: 48 83 c4 20 5b 41 5c 41 5d 41 5e 41 5f 5d 31 c0 31 c9 31 ff 31 d2 31 f6 45 31 c0 45 31 db e9 8c a9 1a e2 88 58 48 44 88 68 49 <41> 8b b7 4c 01 00 00 89 b0 80 00 00 00 4d 85 ff 48 89 45 d0 0f 84 [ 222.654161] RSP: 0018:ffffce68c0147c00 EFLAGS: 00010282 [ 222.654165] RAX: ffff8bc337407740 RBX: 0000000000000000 RCX: 0000000000000000 [ 222.654167] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 [ 222.654170] RBP: ffffce68c0147c48 R08: 0000000000000000 R09: 0000000000000000 [ 222.654172] R10: ffff8bc337407740 R11: ffffffffc10dda10 R12: ffff8bc2d2e00000 [ 222.654174] R13: 0000000000000001 R14: ffff8bc2d2e5b368 R15: 0000000000000000 [ 222.654176] FS: 0000000000000000(0000) GS:ffff8bc64a5fe000(0000) knlGS:0000000000000000 [ 222.654179] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 222.654182] CR2: 000000000000014c CR3: 0000000135eca000 CR4: 0000000000350ef0 [ 222.654184] Call Trace: [ 222.654187] <TASK> [ 222.654190] ? amdgpu_ip_block_resume+0x28/0x70 [amdgpu] [ 222.654376] ? srso_return_thunk+0x5/0x5f [ 222.654382] amdgpu_device_reinit_after_reset+0x184/0x320 [amdgpu] [ 222.654552] amdgpu_do_asic_reset+0x129/0x160 [amdgpu] [ 222.654720] amdgpu_device_asic_reset+0x92/0x710 [amdgpu] [ 222.654890] amdgpu_device_gpu_recover+0x2ae/0x3d0 [amdgpu] [ 222.655060] amdgpu_userq_reset_work+0x76/0xa0 [amdgpu] [ 222.655229] process_scheduled_works+0x1f0/0x450 [ 222.655235] worker_thread+0x27f/0x370
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +1 -1
@@ -511,7 +511,6 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->skip_vram_check = skip_vram_check; coredump->reset_vram_lost = vram_lost; - coredump->pasid = job->pasid;if (job && job->pasid) {struct amdgpu_task_info *ti;
@@ -521,6 +520,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->reset_task_info = *ti;amdgpu_vm_put_task_info (ti); } + coredump->pasid = job->pasid; coredump->num_ibs = job->num_ibs;for (i =0 ; i < job->num_ibs; ++i) { coredump->ibs[i].gpu_addr = job->ibs[i].gpu_addr;
Signature · 1 line
2.34.1
Re: [PATCH v3 3/6] drm/amdgpu: add job->pasid in check as amdgpu_job could be NULL
Quoted 35 lines · Sunil Khatri
In below stack
job->pasidis accessed while job is NULL. Access it within the check when job is non NULL.Failure call stack.
[ 222.653622] BUG: kernel NULL pointer dereference, address: 000000000000014c [ 222.653625] #PF: supervisor read access in kernel mode [ 222.653628] #PF: error_code(0x0000) - not-present page [ 222.653630] PGD 0 P4D 0 [ 222.653635] Oops: Oops: 0000 [#1] SMP NOPTI [ 222.653639] CPU: 1 UID: 0 PID: 12 Comm: kworker/u96:0 Not tainted 6.19.0-amd-staging-drm-next #271 PREEMPT(voluntary) [ 222.653644] Hardware name: Gigabyte Technology Co., Ltd. X570 AORUS ELITE/X570 AORUS ELITE, BIOS F37c 05/12/2022 [ 222.653646] Workqueue: amdgpu-reset-dev amdgpu_userq_reset_work [amdgpu] [ 222.653961] RIP: 0010:amdgpu_coredump+0x8b/0x470 [amdgpu] [ 222.654158] Code: 48 83 c4 20 5b 41 5c 41 5d 41 5e 41 5f 5d 31 c0 31 c9 31 ff 31 d2 31 f6 45 31 c0 45 31 db e9 8c a9 1a e2 88 58 48 44 88 68 49 <41> 8b b7 4c 01 00 00 89 b0 80 00 00 00 4d 85 ff 48 89 45 d0 0f 84 [ 222.654161] RSP: 0018:ffffce68c0147c00 EFLAGS: 00010282 [ 222.654165] RAX: ffff8bc337407740 RBX: 0000000000000000 RCX: 0000000000000000 [ 222.654167] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 [ 222.654170] RBP: ffffce68c0147c48 R08: 0000000000000000 R09: 0000000000000000 [ 222.654172] R10: ffff8bc337407740 R11: ffffffffc10dda10 R12: ffff8bc2d2e00000 [ 222.654174] R13: 0000000000000001 R14: ffff8bc2d2e5b368 R15: 0000000000000000 [ 222.654176] FS: 0000000000000000(0000) GS:ffff8bc64a5fe000(0000) knlGS:0000000000000000 [ 222.654179] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 222.654182] CR2: 000000000000014c CR3: 0000000135eca000 CR4: 0000000000350ef0 [ 222.654184] Call Trace: [ 222.654187] <TASK> [ 222.654190] ? amdgpu_ip_block_resume+0x28/0x70 [amdgpu] [ 222.654376] ? srso_return_thunk+0x5/0x5f [ 222.654382] amdgpu_device_reinit_after_reset+0x184/0x320 [amdgpu] [ 222.654552] amdgpu_do_asic_reset+0x129/0x160 [amdgpu] [ 222.654720] amdgpu_device_asic_reset+0x92/0x710 [amdgpu] [ 222.654890] amdgpu_device_gpu_recover+0x2ae/0x3d0 [amdgpu] [ 222.655060] amdgpu_userq_reset_work+0x76/0xa0 [amdgpu] [ 222.655229] process_scheduled_works+0x1f0/0x450 [ 222.655235] worker_thread+0x27f/0x370
Quoted 2 lines
Fixes f9839cc47e53d ("drm/amdgpu: store ib info for devcoredump")Signed-off-by Sunil Khatri <[email protected]>
Vitaly stumbled over the same issue, but his patch fixed a couple of more things.
I think we should push that one here first and then rebase Vitaly's patch on top of it.
Regards,
Christian.
Quoted 24 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +1
-1@@ -511,7 +511,6 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->skip_vram_check = skip_vram_check; coredump->reset_vram_lost = vram_lost; - coredump->pasid = job->pasid;if (job && job->pasid) {struct amdgpu_task_info *ti;@@ -521,6 +520,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->reset_task_info = *ti;amdgpu_vm_put_task_info (ti); } + coredump->pasid = job->pasid; coredump->num_ibs = job->num_ibs;for (i =0 ; i < job->num_ibs; ++i) { coredump->ibs[i].gpu_addr = job->ibs[i].gpu_addr;
PATCH v3 4/6 drm/amdgpu/userq: use pm_runtime_resume_and_get and fix err handling
In reply to Sunil KhatriUse pm_runtime_resume_and_get instead of pm_runtime_get_sync as it return error but put the reference in the function itself.
In goto statements we need to drop the pm reference too.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8 -5
@@ -734,10 +734,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (r)return r; - r =pm_runtime_get_sync (adev_to_drm (adev)->dev); + r =pm_runtime_resume_and_get (adev_to_drm (adev)->dev);if (r <0 ) { -drm_file_err (uq_mgr->file,"pm_runtime_get_sync() failed for userqueue create\n" ); -pm_runtime_put_autosuspend (adev_to_drm (adev)->dev); +drm_file_err (uq_mgr->file,"pm_runtime_resume_and_get() failed for userqueue create\n" );return r; }
@@ -745,13 +744,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (!uq_funcs) {drm_file_err (uq_mgr->file,"Usermode queue is not supported for this IP (%u)\n" , args->in.ip_type); -return -EINVAL ; + r = -EINVAL ; + goto err_pm_runtime; } queue =kzalloc (sizeof (struct amdgpu_usermode_queue ),GFP_KERNEL );if (!queue) {drm_file_err (uq_mgr->file,"Failed to allocate memory for queue\n" ); -return -ENOMEM ; + r = -ENOMEM ; + goto err_pm_runtime; }INIT_LIST_HEAD (&queue->userq_va_list);
@@ -865,6 +866,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)amdgpu_bo_unreserve (fpriv->vm.root.bo); free_queue:kfree (queue); +err_pm_runtime: +pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);return r; }
Signature · 1 line
2.34.1
Re: [PATCH v3 4/6] drm/amdgpu/userq: use pm_runtime_resume_and_get and fix err handling
Quoted 6 lines · Sunil Khatri
Use
pm_runtime_resume_and_getinstead ofpm_runtime_get_syncas it return error but put the reference in the function itself.In goto statements we need to drop the pm reference too.
Signed-off-by Sunil Khatri <[email protected]>
But Alex should probably take a look as well since I'm not very familiar with runtime PM functions.
Regards,
Christian.
Quoted 48 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8
-5@@ -734,10 +734,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (r)return r; - r =pm_runtime_get_sync (adev_to_drm (adev)->dev); + r =pm_runtime_resume_and_get (adev_to_drm (adev)->dev);if (r <0 ) { -drm_file_err (uq_mgr->file,"pm_runtime_get_sync() failed for userqueue create\n" ); -pm_runtime_put_autosuspend (adev_to_drm (adev)->dev); +drm_file_err (uq_mgr->file,"pm_runtime_resume_and_get() failed for userqueue create\n" );return r; }@@ -745,13 +744,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (!uq_funcs) {drm_file_err (uq_mgr->file,"Usermode queue is not supported for this IP (%u)\n" , args->in.ip_type); -return -EINVAL ; + r = -EINVAL ; + goto err_pm_runtime; } queue =kzalloc (sizeof (struct amdgpu_usermode_queue ),GFP_KERNEL );if (!queue) {drm_file_err (uq_mgr->file,"Failed to allocate memory for queue\n" ); -return -ENOMEM ; + r = -ENOMEM ; + goto err_pm_runtime; }INIT_LIST_HEAD (&queue->userq_va_list);@@ -865,6 +866,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)amdgpu_bo_unreserve (fpriv->vm.root.bo); free_queue:kfree (queue); +err_pm_runtime: +pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);return r; }
Re: [PATCH v3 4/6] drm/amdgpu/userq: use pm_runtime_resume_and_get and fix err handling
In reply to Sunil KhatriQuoted 7 lines · Sunil Khatri
Use
pm_runtime_resume_and_getinstead ofpm_runtime_get_syncas it return error but put the reference in the function itself.In goto statements we need to drop the pm reference too.
Signed-off-by Sunil Khatri <[email protected]>
Quoted 51 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8
-6@@ -734,10 +734,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (r)return r; - r =pm_runtime_get_sync (adev_to_drm (adev)->dev); + r =pm_runtime_resume_and_get (adev_to_drm (adev)->dev);if (r <0 ) { -drm_file_err (uq_mgr->file,"pm_runtime_get_sync() failed for userqueue create\n" ); -pm_runtime_put_autosuspend (adev_to_drm (adev)->dev); +drm_file_err (uq_mgr->file,"pm_runtime_resume_and_get() failed for userqueue create\n" );return r; }@@ -745,13 +744,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (!uq_funcs) {drm_file_err (uq_mgr->file,"Usermode queue is not supported for this IP (%u)\n" , args->in.ip_type); -return -EINVAL ; + r = -EINVAL ; + goto err_pm_runtime; } queue =kzalloc (sizeof (struct amdgpu_usermode_queue ),GFP_KERNEL );if (!queue) {drm_file_err (uq_mgr->file,"Failed to allocate memory for queue\n" ); -return -ENOMEM ; + r = -ENOMEM ; + goto err_pm_runtime; }INIT_LIST_HEAD (&queue->userq_va_list);@@ -865,6 +866,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)amdgpu_bo_unreserve (fpriv->vm.root.bo); free_queue:kfree (queue); +err_pm_runtime: +pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);return r; } --2.34.1
PATCH v3 5/6 drm/amdgpu/userq: unmap is to be called before freeing doorbell/wptr bo
In reply to Sunil KhatriUnmap the queue after freeing doorbell and wptr memory is completely wrong. Any operation on the queue needs the doorbell and wptr to be valid and hence fixing the ordering.
Also since we are using amdgpu_bo_reserve in non interruptrable mode so there is no need to check for its return values.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 28 +++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +13 -15
@@ -635,21 +635,6 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que queue->hang_detect_fence =NULL ;amdgpu_userq_wait_for_last_fence (queue); - r =amdgpu_bo_reserve (queue->db_obj.obj, true); -if (!r) { -amdgpu_bo_unpin (queue->db_obj.obj); -amdgpu_bo_unreserve (queue->db_obj.obj); - } -amdgpu_bo_unref (&queue->db_obj.obj); - - r =amdgpu_bo_reserve (queue->wptr_obj.obj, true); -if (!r) { -amdgpu_bo_unpin (queue->wptr_obj.obj); -amdgpu_bo_unreserve (queue->wptr_obj.obj); - } -amdgpu_bo_unref (&queue->wptr_obj.obj); - -atomic_dec (&uq_mgr->userq_count[queue->queue_type]);#if defined(CONFIG_DEBUG_FS )debugfs_remove_recursive (queue->debugfs_queue);#endif
@@ -660,6 +645,19 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_quedrm_warn (adev_to_drm (uq_mgr->adev),"trying to destroy a HW mapping userq\n" ); queue->state =AMDGPU_USERQ_STATE_HUNG ; } + +amdgpu_bo_reserve (queue->db_obj.obj, true); +amdgpu_bo_unpin (queue->db_obj.obj); +amdgpu_bo_unreserve (queue->db_obj.obj); +amdgpu_bo_unref (&queue->db_obj.obj); + +amdgpu_bo_reserve (queue->wptr_obj.obj, true); +amdgpu_bo_unpin (queue->wptr_obj.obj); +amdgpu_bo_unreserve (queue->wptr_obj.obj); +amdgpu_bo_unref (&queue->wptr_obj.obj); + +atomic_dec (&uq_mgr->userq_count[queue->queue_type]); +amdgpu_userq_cleanup (queue);mutex_unlock (&uq_mgr->userq_mutex);pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);
Signature · 1 line
2.34.1
Re: [PATCH v3 5/6] drm/amdgpu/userq: unmap is to be called before freeing doorbell/wptr bo
Quoted 8 lines · Sunil Khatri
Unmap the queue after freeing doorbell and wptr memory is completely wrong. Any operation on the queue needs the doorbell and wptr to be valid and hence fixing the ordering.
Also since we are using
amdgpu_bo_reservein non interruptrable mode so there is no need to check for its return values.Signed-off-by Sunil Khatri <[email protected]>
Quoted 50 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 28 +++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +13
-15@@ -635,21 +635,6 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que queue->hang_detect_fence =NULL ;amdgpu_userq_wait_for_last_fence (queue); - r =amdgpu_bo_reserve (queue->db_obj.obj, true); -if (!r) { -amdgpu_bo_unpin (queue->db_obj.obj); -amdgpu_bo_unreserve (queue->db_obj.obj); - } -amdgpu_bo_unref (&queue->db_obj.obj); - - r =amdgpu_bo_reserve (queue->wptr_obj.obj, true); -if (!r) { -amdgpu_bo_unpin (queue->wptr_obj.obj); -amdgpu_bo_unreserve (queue->wptr_obj.obj); - } -amdgpu_bo_unref (&queue->wptr_obj.obj); - -atomic_dec (&uq_mgr->userq_count[queue->queue_type]);#if defined(CONFIG_DEBUG_FS )debugfs_remove_recursive (queue->debugfs_queue);#endif @@ -660,6 +645,19 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_quedrm_warn (adev_to_drm (uq_mgr->adev),"trying to destroy a HW mapping userq\n" ); queue->state =AMDGPU_USERQ_STATE_HUNG ; } + +amdgpu_bo_reserve (queue->db_obj.obj, true); +amdgpu_bo_unpin (queue->db_obj.obj); +amdgpu_bo_unreserve (queue->db_obj.obj); +amdgpu_bo_unref (&queue->db_obj.obj); + +amdgpu_bo_reserve (queue->wptr_obj.obj, true); +amdgpu_bo_unpin (queue->wptr_obj.obj); +amdgpu_bo_unreserve (queue->wptr_obj.obj); +amdgpu_bo_unref (&queue->wptr_obj.obj); + +atomic_dec (&uq_mgr->userq_count[queue->queue_type]); +amdgpu_userq_cleanup (queue);mutex_unlock (&uq_mgr->userq_mutex);pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);
PATCH v3 6/6 drm/amdgpu/userq: unmap_helper dont return the queue state
In reply to Sunil KhatriWe check for return value of amdgpu_userq_unmap_helper and compare it against the queue->state which is logically wrong and we should just check for failure and do the needfull.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -1
@@ -641,7 +641,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queamdgpu_userq_detect_and_reset_queues (uq_mgr); r =amdgpu_userq_unmap_helper (queue);/*TODO: It requires a reset for userq hw unmap error*/ -if (unlikely (r !=AMDGPU_USERQ_STATE_UNMAPPED )) { +if (unlikely (r !=0 )) {drm_warn (adev_to_drm (uq_mgr->adev),"trying to destroy a HW mapping userq\n" ); queue->state =AMDGPU_USERQ_STATE_HUNG ; }
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH v3 6/6] drm/amdgpu/userq: unmap_helper dont return the queue state
Quoted 14 lines · Sunil Khatri
We check for return value of
amdgpu_userq_unmap_helperand compare it against thequeue->statewhich is logically wrong and we should just check for failure and do the needfull.Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que · line 644
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -641,7 +641,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queamdgpu_userq_detect_and_reset_queues (uq_mgr); r =amdgpu_userq_unmap_helper (queue);/*TODO: It requires a reset for userq hw unmap error*/ -if (unlikely (r !=AMDGPU_USERQ_STATE_UNMAPPED )) { +if (unlikely (r !=0 )) {
Usually either just if (r) or explicitly checking for if (r < 0).
And unlikely is only justified if it is a performance critical code path which that here clearly isn't.
Regards,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0drm_warn (adev_to_drm (uq_mgr->adev),"trying to destroy a HW mapping userq\n" ); queue->state =AMDGPU_USERQ_STATE_HUNG ; }
Re: [PATCH v3 6/6] drm/amdgpu/userq: unmap_helper dont return the queue state
Quoted 23 lines · Christian König
Quoted 14 lines · Sunil Khatri
We check for return value of
amdgpu_userq_unmap_helperand compare it against thequeue->statewhich is logically wrong and we should just check for failure and do the needfull.Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que · line 644
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -641,7 +641,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queamdgpu_userq_detect_and_reset_queues (uq_mgr); r =amdgpu_userq_unmap_helper (queue);/*TODO: It requires a reset for userq hw unmap error*/ -if (unlikely (r !=AMDGPU_USERQ_STATE_UNMAPPED )) { +if (unlikely (r !=0 )) {Usually either just if (r) or explicitly checking for if (r < 0).
Quoted 1 line
And unlikely is only justified if it is a performance critical code path which that here clearly isn't.
Sure will update that Christian
Regards
Sunil khatri
Quoted 7 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0drm_warn (adev_to_drm (uq_mgr->adev),"trying to destroy a HW mapping userq\n" ); queue->state =AMDGPU_USERQ_STATE_HUNG ; }