AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/6] Fix some clean up in the userq create time
@ 2026-05-18 13:07 Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 1/6] drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail Sunil Khatri
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

*** 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(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 1/6] drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail
  2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
@ 2026-05-18 13:07 ` Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 2/6] drm/amdgpu/userq: Fix the mutex_init cleanup for fence_drv_lock Sunil Khatri
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

Unpin and unref the door bell obj if queue creation fails before
initialization is complete.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index f1873f632547..4a50f6536f8d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/6] drm/amdgpu/userq: Fix the mutex_init cleanup for fence_drv_lock
  2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 1/6] drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail Sunil Khatri
@ 2026-05-18 13:07 ` Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 3/6] drm/amdgpu: simplify return value in amdgpu_userq_get_doorbell_index Sunil Khatri
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

Mutex 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.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 4a50f6536f8d..d3971bf9112b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -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:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 3/6] drm/amdgpu: simplify return value in amdgpu_userq_get_doorbell_index
  2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 1/6] drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 2/6] drm/amdgpu/userq: Fix the mutex_init cleanup for fence_drv_lock Sunil Khatri
@ 2026-05-18 13:07 ` Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 4/6] drm/amdgpu/userq: dont override return value of xa_alloc Sunil Khatri
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

Function 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.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index d3971bf9112b..d42a4d97e8e4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index 49b33e2d6932..9c4d4220c353 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 4/6] drm/amdgpu/userq: dont override return value of xa_alloc
  2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
                   ` (2 preceding siblings ...)
  2026-05-18 13:07 ` [PATCH v1 3/6] drm/amdgpu: simplify return value in amdgpu_userq_get_doorbell_index Sunil Khatri
@ 2026-05-18 13:07 ` Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 5/6] drm/amdgpu/userq: clean up wptr_obj along with mqd_destroy Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 6/6] drm/amdgpu/userq: add amdgpu_bo_unpin when amdgpu_ttm_alloc_gart fails Sunil Khatri
  5 siblings, 0 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

xa_alloc on failure already return -ENOMEM, so there is
no need to override it again with r = -ENOMEM.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index d42a4d97e8e4..c07aad2c6a53 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -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;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 5/6] drm/amdgpu/userq: clean up wptr_obj along with mqd_destroy
  2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
                   ` (3 preceding siblings ...)
  2026-05-18 13:07 ` [PATCH v1 4/6] drm/amdgpu/userq: dont override return value of xa_alloc Sunil Khatri
@ 2026-05-18 13:07 ` Sunil Khatri
  2026-05-18 13:07 ` [PATCH v1 6/6] drm/amdgpu/userq: add amdgpu_bo_unpin when amdgpu_ttm_alloc_gart fails Sunil Khatri
  5 siblings, 0 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

During queue creation failure, when we clean up mqd via
mqd_destroy we arent doing the wptr_obj cleanup and hence
adding that clean up.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index c07aad2c6a53..68efed47f412 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -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:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 6/6] drm/amdgpu/userq: add amdgpu_bo_unpin when amdgpu_ttm_alloc_gart fails
  2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
                   ` (4 preceding siblings ...)
  2026-05-18 13:07 ` [PATCH v1 5/6] drm/amdgpu/userq: clean up wptr_obj along with mqd_destroy Sunil Khatri
@ 2026-05-18 13:07 ` Sunil Khatri
  5 siblings, 0 replies; 7+ messages in thread
From: Sunil Khatri @ 2026-05-18 13:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König; +Cc: amd-gfx, Sunil Khatri

Unping the wptr_obj->obj when amdgpu_ttm_alloc_gart fails.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 14db2124ff81..aa9dad4039bd 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -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:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-05-18 13:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 13:07 [PATCH v1 0/6] Fix some clean up in the userq create time Sunil Khatri
2026-05-18 13:07 ` [PATCH v1 1/6] drm/amdgpu/userq: Fix doorbell cleanup on queue creation fail Sunil Khatri
2026-05-18 13:07 ` [PATCH v1 2/6] drm/amdgpu/userq: Fix the mutex_init cleanup for fence_drv_lock Sunil Khatri
2026-05-18 13:07 ` [PATCH v1 3/6] drm/amdgpu: simplify return value in amdgpu_userq_get_doorbell_index Sunil Khatri
2026-05-18 13:07 ` [PATCH v1 4/6] drm/amdgpu/userq: dont override return value of xa_alloc Sunil Khatri
2026-05-18 13:07 ` [PATCH v1 5/6] drm/amdgpu/userq: clean up wptr_obj along with mqd_destroy Sunil Khatri
2026-05-18 13:07 ` [PATCH v1 6/6] drm/amdgpu/userq: add amdgpu_bo_unpin when amdgpu_ttm_alloc_gart fails Sunil Khatri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox