Re: [PATCH v4 10/10] drm/amdgpu: cleanup leftover queues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Am 24.04.23 um 19:38 schrieb Shashank Sharma:
This patch adds code to cleanup any leftover userqueues which
a user might have missed to destroy due to a crash or any other
programming error.

Cc: Alex Deucher <alexander.deucher@xxxxxxx>
Cc: Christian Koenig <christian.koenig@xxxxxxx>
Suggested-by: Bas Nieuwenhuizen <bas@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Bas Nieuwenhuizen <bas@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Shashank Sharma <shashank.sharma@xxxxxxx>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 31 +++++++++++++++----
  1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
index fbc9cb5c24ad..27201a0b1441 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -237,6 +237,18 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
  	return -EINVAL;
  }
+static void
+amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+	mutex_lock(&uq_mgr->userq_mutex);
+	if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy)
+		uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue);
+
+	amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
+	mutex_unlock(&uq_mgr->userq_mutex);
+	kfree(queue);
+}
+
  static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
  {
  	struct amdgpu_fpriv *fpriv = filp->driver_priv;
@@ -249,12 +261,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
  		return;
  	}
- mutex_lock(&uq_mgr->userq_mutex);
-	if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy)
-		uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue);
-	amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
-	mutex_unlock(&uq_mgr->userq_mutex);
-	kfree(queue);
+	amdgpu_userqueue_cleanup(uq_mgr, queue);
  }
int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
@@ -307,8 +314,20 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi
  	return 0;
  }
+static void amdgpu_userqueue_cleanup_residue(int queue_id, void *ptr, void *data)
+{
+	struct amdgpu_userq_mgr *uq_mgr = data;
+	struct amdgpu_usermode_queue *queue = ptr;
+
+	amdgpu_userqueue_cleanup(uq_mgr, queue);
+}
+
  void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
  {
+	idr_for_each(&userq_mgr->userq_idr,
+		     amdgpu_userqueue_cleanup_residue,
+		     userq_mgr);
+

Better use idr_for_each_entry() here.

Christian.
  	idr_destroy(&userq_mgr->userq_idr);
  	mutex_destroy(&userq_mgr->userq_mutex);
  }




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux