Fix some clean up in the userq create time
Subsystems (2)
cover Fix some clean up in the userq create time
*** BLURB HERE ***
Sunil Khatri (6):
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
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 38 ++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 -- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 ++ 3 files changed, 26 insertions(+), 17 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/6 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 2/6 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 3/6 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 4/6 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 5/6 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 6/6 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 | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
@@ -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