Fix some clean up during userq create/destroy
Subsystems (2)
v3 cover Fix some clean up during userq create/destroy
v3: Add two more patches
Sunil Khatri (8):
drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail drm/amdgpu/userq: Fix the mutex_init cleanup for fence_drv_lock drm/amdgpu: simplify return value in amdgpu_userq_get_doorbell_index drm/amdgpu/userq: dont override return value of xa_alloc drm/amdgpu/userq: clean up wptr_obj along with mqd_destroy drm/amdgpu/userq: add amdgpu_bo_unpin when amdgpu_ttm_alloc_gart fails drm/amdgpu/userq: reserve root bo without interruption drm/amdgpu/userq: make sure queue is valid in the hang_detect_work
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 49 +++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 -- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 4 +- 3 files changed, 32 insertions(+), 24 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/8 drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail
Unpin and unref the door bell obj if queue creation fails before initialization is complete.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -1
@@ -782,7 +782,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) r =amdgpu_userq_fence_driver_alloc (adev, &queue->fence_drv);if (r) {drm_file_err (uq_mgr->file,"Failed to alloc fence driver\n" ); - goto clean_mapping; + goto clean_doorbell; } r = uq_funcs->mqd_create (queue, &args->in);
@@ -851,6 +851,11 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) uq_funcs->mqd_destroy (queue); clean_fence_driver:amdgpu_userq_fence_driver_free (queue); +clean_doorbell: +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); clean_mapping:amdgpu_bo_reserve (fpriv->vm.root.bo, true);amdgpu_userq_buffer_vas_list_cleanup (adev, queue);
Signature · 1 line
2.34.1
PATCH v3 2/8 drm/amdgpu/userq: Fix the mutex_init cleanup for fence_drv_lock
In reply to Sunil KhatriMutex fence_drv_lock is cleanup in amdgpu_userq_fence_driver_free but current cleanup is directly done later in the code which eventually tried to do mutex_destroy two times.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -3
@@ -777,14 +777,16 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) } queue->doorbell_index = index; -mutex_init (&queue->fence_drv_lock); -xa_init_flags (&queue->fence_drv_xa,XA_FLAGS_ALLOC ); + r =amdgpu_userq_fence_driver_alloc (adev, &queue->fence_drv);if (r) {drm_file_err (uq_mgr->file,"Failed to alloc fence driver\n" ); goto clean_doorbell; } +mutex_init (&queue->fence_drv_lock); +xa_init_flags (&queue->fence_drv_xa,XA_FLAGS_ALLOC ); + r = uq_funcs->mqd_create (queue, &args->in);if (r) {drm_file_err (uq_mgr->file,"Failed to create Queue\n" );
@@ -860,7 +862,6 @@ 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); -mutex_destroy (&queue->fence_drv_lock); free_queue:kfree (queue); err_pm_runtime:
Signature · 1 line
2.34.1
PATCH v3 3/8 drm/amdgpu: simplify return value in amdgpu_userq_get_doorbell_index
In reply to Sunil KhatriFunction amdgpu_userq_get_doorbell_index returns a uint64 type index as well as a int type failure values. So simplifying that here and using a int type return value and getting the index in input pointer of type uint64 type.
Also since it is used just once here so lets make it local to the file with static type.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 19 ++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 --- 2 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -9
@@ -536,12 +536,13 @@ void amdgpu_userq_destroy_object(struct amdgpu_userq_mgr *uq_mgr,amdgpu_bo_unref (&userq_obj->obj); } -uint64_t +static int amdgpu_userq_get_doorbell_index (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_db_info *db_info, -struct drm_file *filp) +struct drm_file *filp, +uint64_t *index) { -uint64_t index; +uint64_t doorbell_index;struct drm_gem_object *gobj;struct amdgpu_userq_obj *db_obj = db_info->db_obj;int r, db_size;
@@ -588,12 +589,13 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, goto unpin_bo; } - index =amdgpu_doorbell_index_on_bar (uq_mgr->adev, db_obj->obj, + doorbell_index =amdgpu_doorbell_index_on_bar (uq_mgr->adev, db_obj->obj, db_info->doorbell_offset, db_size);drm_dbg_driver (adev_to_drm (uq_mgr->adev), -"[Usermode queues] doorbell index=%lld\n" , index); +"[Usermode queues] doorbell index=%lld\n" , doorbell_index);amdgpu_bo_unreserve (db_obj->obj); -return index; + *index = doorbell_index; +return 0 ; unpin_bo:amdgpu_bo_unpin (db_obj->obj);
@@ -769,10 +771,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)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); -if (index == (uint64_t )-EINVAL ) { + r =amdgpu_userq_get_doorbell_index (uq_mgr, &db_info, filp, &index); +if (r) {drm_file_err (uq_mgr->file,"Failed to get doorbell for queue\n" ); - r = -EINVAL ; goto clean_mapping; }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0 -3
@@ -163,9 +163,6 @@ void amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr); -uint64_t amdgpu_userq_get_doorbell_index (struct amdgpu_userq_mgr *uq_mgr, -struct amdgpu_db_info *db_info, -struct drm_file *filp);u32 amdgpu_userq_get_supported_ip_mask (struct amdgpu_device *adev);bool amdgpu_userq_enabled (struct drm_device *dev);
Signature · 1 line
2.34.1
PATCH v3 4/8 drm/amdgpu/userq: dont override return value of xa_alloc
In reply to Sunil Khatrixa_alloc on failure already return -ENOMEM, so there is no need to override it again with r = -ENOMEM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -1
@@ -825,7 +825,6 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (r) {if (!skip_map_queue)amdgpu_userq_unmap_helper (queue); - r = -ENOMEM ; goto clean_reset_domain; }
Signature · 1 line
2.34.1
PATCH v3 5/8 drm/amdgpu/userq: clean up wptr_obj along with mqd_destroy
In reply to Sunil KhatriDuring queue creation failure, when we clean up mqd via mqd_destroy we arent doing the wptr_obj cleanup and hence adding that clean up.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -0
@@ -851,6 +851,10 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) clean_mqd:mutex_unlock (&uq_mgr->userq_mutex); uq_funcs->mqd_destroy (queue); +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); clean_fence_driver:amdgpu_userq_fence_driver_free (queue); clean_doorbell:
Signature · 1 line
2.34.1
PATCH v3 6/8 drm/amdgpu/userq: add amdgpu_bo_unpin when amdgpu_ttm_alloc_gart fails
In reply to Sunil KhatriUnping the wptr_obj->obj when amdgpu_ttm_alloc_gart fails.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -1
@@ -81,7 +81,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev, ret =amdgpu_ttm_alloc_gart (&wptr_obj->obj->tbo);if (ret) {DRM_ERROR ("Failed to bind bo to GART. ret %d\n" , ret); - goto fail_map; + goto fail_alloc_gart; } queue->wptr_obj.gpu_addr =amdgpu_bo_gpu_offset (wptr_obj->obj);
@@ -89,6 +89,8 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,drm_exec_fini (&exec);return 0 ; +fail_alloc_gart: +amdgpu_bo_unpin (wptr_obj->obj); fail_map:amdgpu_bo_unref (&wptr_obj->obj); fail_lock:
Signature · 1 line
2.34.1
PATCH v3 7/8 drm/amdgpu/userq: reserve root bo without interruption
In reply to Sunil KhatriFix the code to make it an uninterruptible reservation for root bo.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -5
@@ -620,11 +620,7 @@ 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); - r =amdgpu_bo_reserve (vm->root.bo, false); -if (r) { -drm_file_err (uq_mgr->file,"Failed to reserve root bo during userqueue destroy\n" ); -return r; - } +amdgpu_bo_reserve (vm->root.bo, true);amdgpu_userq_buffer_vas_list_cleanup (adev, queue);amdgpu_bo_unreserve (vm->root.bo);
Signature · 1 line
2.34.1
PATCH v3 8/8 drm/amdgpu/userq: make sure queue is valid in the hang_detect_work
In reply to Sunil KhatriThread 1: Running amdgpu_userq_destroy which eventually remove the queue from door bell and set userq_mgr = NULL.
Thread2: An interrupt might have scheduled the hang_detect_work which still need userq_mgr to be valid but could get an NULL ptrs.
To fix that make sure we cancel the hang_detect_work again before setting userq_mgr to NULL.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -1
@@ -427,7 +427,6 @@ static void amdgpu_userq_cleanup(struct amdgpu_usermode_queue *queue)xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index);amdgpu_userq_fence_driver_free (queue); queue->fence_drv =NULL ; - queue->userq_mgr =NULL ;list_del (&queue->userq_va_list);up_read (&adev->reset_domain->sem);
@@ -635,6 +634,10 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queamdgpu_userq_cleanup (queue);mutex_unlock (&uq_mgr->userq_mutex); +/* This is case an interrupt was fired and a hang detection work is pending */ +cancel_delayed_work_sync (&queue->hang_detect_work); + queue->userq_mgr =NULL ; +amdgpu_bo_reserve (queue->db_obj.obj, true);amdgpu_bo_unpin (queue->db_obj.obj);amdgpu_bo_unreserve (queue->db_obj.obj);
Signature · 1 line
2.34.1
Sent again since one of the patches got missing in the email. Regards
Sunil Khatri
Quoted 17 lines · Sunil Khatri
v3: Add two more patches
Sunil Khatri (8):
drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail drm/amdgpu/userq: Fix themutex_initcleanup forfence_drv_lockdrm/amdgpu: simplify return value inamdgpu_userq_get_doorbell_indexdrm/amdgpu/userq: dont override return value ofxa_allocdrm/amdgpu/userq: clean upwptr_objalong withmqd_destroydrm/amdgpu/userq: addamdgpu_bo_unpinwhenamdgpu_ttm_alloc_gartfails drm/amdgpu/userq: reserve root bo without interruption drm/amdgpu/userq: make sure queue is valid in thehang_detect_workdrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 49 +++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 -- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 4 +- 3 files changed, 32 insertions(+), 24 deletions(-)