Skip to contentSkip to conversation

drm: function to get process name and pid

PATCH In review Sunil Khatri 4 participants 8 messages Apr 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 drm: function to get process name and pid

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
 drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  1 +
 2 files changed, 35 insertions(+)
drivers/gpu/drm/drm_file.c +34 -0
index c299cd94d3f7..728a60975f5e 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
 }
 EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+
+	if (!proc_info) {
+		drm_WARN_ON_ONCE(dev, "Invalid user buffer\n");
+		return;
+	}
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "client_name:%s proc:%s pid:%d",
+			 file_priv->client_name ? file_priv->client_name : "Unset",
+			 task->comm, task->pid);
+
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_process_info);
+
 /**
  * mock_drm_getfile - Create a new struct file for the drm device
  * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index 94d365b22505..a972be73a615 100644
@@ -507,6 +507,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
 void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
 void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/4 drm/amdgpu: add drm_file reference in userq_mgr

drm_file will be used in usermode queues code to enable better process information in logging and hence add drm_file part of the userq_mgr struct.

update the drm_file pointer in userq_mgr for each
amdgpu_driver_open_kms.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -0
index 3d319687c1c9..3de3071d66ee 100644
@@ -1436,6 +1436,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
 	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
+	fpriv->userq_mgr.file = file_priv;
 	r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
 	if (r)
 		DRM_WARN("Can't setup usermode queues, use legacy workload submission only\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1 -0
index 381b9c6f0573..fe51a45f7ee4 100644
@@ -77,6 +77,7 @@ struct amdgpu_userq_mgr {
 	struct amdgpu_device		*adev;
 	struct delayed_work		resume_work;
 	struct list_head		list;
+	struct drm_file			*file;
 };
 
 struct amdgpu_db_info {
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 3/4 drm/amdgpu: update the error logging for more information

In reply to Sunil Khatri

add process and pid information in the userqueue error logging to make it more useful in resolving the error by logs.

Sample log:

[   42.444297] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=000000001c74d978 for comm:Xwayland pid:3427
[   42.444669] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:Xwayland pid:3427
[   42.824729] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=0000000074407d3e for comm:systemd-logind pid:1058
[   42.825082] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:systemd-logind pid:1058
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 47 +++++++++++++++----
 1 file changed, 39 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +39 -8
index 1867520ba258..eb96c12e02e7 100644
@@ -38,12 +38,17 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
 	struct amdgpu_device *adev = uq_mgr->adev;
 	const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
 	struct dma_fence *f = queue->last_fence;
+	struct drm_file *file;
+	char proc_log[50];
 	int ret;
 
 	if (f && !dma_fence_is_signaled(f)) {
 		ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
 		if (ret <= 0) {
-			DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+			file = uq_mgr->file;
+			drm_process_info(file, proc_log, sizeof(proc_log));
+			DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+				  f, proc_log);
 			return;
 		}
 	}
@@ -431,6 +436,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	const struct amdgpu_userq_funcs *userq_funcs;
 	struct amdgpu_usermode_queue *queue;
 	int queue_id;
+	struct drm_file *file;
+	char proc_log[50];
 	int ret = 0;
 
 	/* Resume all the queues for this process */
@@ -439,8 +446,13 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 		ret |= userq_funcs->map(uq_mgr, queue);
 	}
 
-	if (ret)
-		DRM_ERROR("Failed to map all the queues\n");
+	if (ret) {
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Failed to map all the queue for %s\n",
+			  proc_log);
+		}
+
 	return ret;
 }
 
@@ -589,6 +601,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 	const struct amdgpu_userq_funcs *userq_funcs;
 	struct amdgpu_usermode_queue *queue;
 	int queue_id;
+	struct drm_file *file;
+	char proc_log[50];
 	int ret = 0;
 
 	/* Try to unmap all the queues in this process ctx */
@@ -597,8 +611,13 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 		ret += userq_funcs->unmap(uq_mgr, queue);
 	}
 
-	if (ret)
-		DRM_ERROR("Couldn't unmap all the queues\n");
+	if (ret) {
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Couldn't unmap all the queues for %s\n",
+			  proc_log);
+		}
+
 	return ret;
 }
 
@@ -606,6 +625,8 @@ static int
 amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 {
 	struct amdgpu_usermode_queue *queue;
+	struct drm_file *file;
+	char proc_log[50];
 	int queue_id, ret;
 
 	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
@@ -615,7 +636,10 @@ amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 			continue;
 		ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
 		if (ret <= 0) {
-			DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+			file = uq_mgr->file;
+			drm_process_info(file, proc_log, sizeof(proc_log));
+			DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+				  f, proc_log);
 			return -ETIMEDOUT;
 		}
 	}
@@ -628,19 +652,26 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr,
 			 struct amdgpu_eviction_fence *ev_fence)
 {
 	int ret;
+	struct drm_file *file;
+	char proc_log[50];
 	struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(uq_mgr);
 	struct amdgpu_eviction_fence_mgr *evf_mgr = &fpriv->evf_mgr;
 
 	/* Wait for any pending userqueue fence work to finish */
 	ret = amdgpu_userqueue_wait_for_signal(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Not suspending userqueue, timeout waiting for work\n");
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Not suspending userqueue, timeout waiting for %s\n",
+			  proc_log);
 		return;
 	}
 
 	ret = amdgpu_userqueue_suspend_all(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Failed to evict userqueue\n");
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Failed to evict userqueue for %s\n", proc_log);
 		return;
 	}
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 4/4 drm/amdgpu: change DRM_ERROR to drm_err in amdgpu_userqueue.c

In reply to Sunil Khatri

change the DRM_ERROR to drm_err which gives the drm device information too which is useful in case of multiple GPU's.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 75 ++++++++++---------
 1 file changed, 41 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +41 -34
index eb96c12e02e7..a1046808ab4b 100644
@@ -47,7 +47,7 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
 		if (ret <= 0) {
 			file = uq_mgr->file;
 			drm_process_info(file, proc_log, sizeof(proc_log));
-			DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+			drm_err(adev_to_drm(adev), "Timed out waiting for fence f=%p for %s\n",
 				  f, proc_log);
 			return;
 		}
@@ -128,25 +128,25 @@ int amdgpu_userqueue_create_object(struct amdgpu_userq_mgr *uq_mgr,
 
 	r = amdgpu_bo_create(adev, &bp, &userq_obj->obj);
 	if (r) {
-		DRM_ERROR("Failed to allocate BO for userqueue (%d)", r);
+		drm_err(adev_to_drm(adev), "Failed to allocate BO for userqueue (%d)", r);
 		return r;
 	}
 
 	r = amdgpu_bo_reserve(userq_obj->obj, true);
 	if (r) {
-		DRM_ERROR("Failed to reserve BO to map (%d)", r);
+		drm_err(adev_to_drm(adev), "Failed to reserve BO to map (%d)", r);
 		goto free_obj;
 	}
 
 	r = amdgpu_ttm_alloc_gart(&(userq_obj->obj)->tbo);
 	if (r) {
-		DRM_ERROR("Failed to alloc GART for userqueue object (%d)", r);
+		drm_err(adev_to_drm(adev), "Failed to alloc GART for userqueue object (%d)", r);
 		goto unresv;
 	}
 
 	r = amdgpu_bo_kmap(userq_obj->obj, &userq_obj->cpu_ptr);
 	if (r) {
-		DRM_ERROR("Failed to map BO for userqueue (%d)", r);
+		drm_err(adev_to_drm(adev), "Failed to map BO for userqueue (%d)", r);
 		goto unresv;
 	}
 
@@ -182,7 +182,7 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 
 	gobj = drm_gem_object_lookup(filp, db_info->doorbell_handle);
 	if (gobj == NULL) {
-		DRM_ERROR("Can't find GEM object for doorbell\n");
+		drm_err(adev_to_drm(uq_mgr->adev), "Can't find GEM object for doorbell\n");
 		return -EINVAL;
 	}
 
@@ -192,13 +192,15 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 	/* Pin the BO before generating the index, unpin in queue destroy */
 	r = amdgpu_bo_pin(db_obj->obj, AMDGPU_GEM_DOMAIN_DOORBELL);
 	if (r) {
-		DRM_ERROR("[Usermode queues] Failed to pin doorbell object\n");
+		drm_err(adev_to_drm(uq_mgr->adev),
+			"[Usermode queues] Failed to pin doorbell object\n");
 		goto unref_bo;
 	}
 
 	r = amdgpu_bo_reserve(db_obj->obj, true);
 	if (r) {
-		DRM_ERROR("[Usermode queues] Failed to pin doorbell object\n");
+		drm_err(adev_to_drm(uq_mgr->adev),
+			"[Usermode queues] Failed to pin doorbell object\n");
 		goto unpin_bo;
 	}
 
@@ -220,14 +222,16 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 		break;
 
 	default:
-		DRM_ERROR("[Usermode queues] IP %d not support\n", db_info->queue_type);
+		drm_err(adev_to_drm(uq_mgr->adev),
+			"[Usermode queues] IP %d not support\n", db_info->queue_type);
 		r = -EINVAL;
 		goto unpin_bo;
 	}
 
 	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
 					     db_info->doorbell_offset, db_size);
-	DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);
+	drm_dbg_driver(adev_to_drm(uq_mgr->adev),
+		       "[Usermode queues] doorbell index=%lld\n", index);
 	amdgpu_bo_unreserve(db_obj->obj);
 	return index;
 
@@ -254,7 +258,7 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
 
 	queue = amdgpu_userqueue_find(uq_mgr, queue_id);
 	if (!queue) {
-		DRM_DEBUG_DRIVER("Invalid queue id to destroy\n");
+		drm_dbg_driver(adev_to_drm(uq_mgr->adev), "Invalid queue id to destroy\n");
 		mutex_unlock(&uq_mgr->userq_mutex);
 		return -EINVAL;
 	}
@@ -287,7 +291,8 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	if (args->in.ip_type != AMDGPU_HW_IP_GFX &&
 	    args->in.ip_type != AMDGPU_HW_IP_DMA &&
 	    args->in.ip_type != AMDGPU_HW_IP_COMPUTE) {
-		DRM_ERROR("Usermode queue doesn't support IP type %u\n", args->in.ip_type);
+		drm_err(adev_to_drm(adev),
+			"Usermode queue doesn't support IP type %u\n", args->in.ip_type);
 		return -EINVAL;
 	}
 
@@ -309,14 +314,16 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 
 	uq_funcs = adev->userq_funcs[args->in.ip_type];
 	if (!uq_funcs) {
-		DRM_ERROR("Usermode queue is not supported for this IP (%u)\n", args->in.ip_type);
+		drm_err(adev_to_drm(adev),
+			"Usermode queue is not supported for this IP (%u)\n",
+			args->in.ip_type);
 		r = -EINVAL;
 		goto unlock;
 	}
 
 	queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL);
 	if (!queue) {
-		DRM_ERROR("Failed to allocate memory for queue\n");
+		drm_err(adev_to_drm(adev), "Failed to allocate memory for queue\n");
 		r = -ENOMEM;
 		goto unlock;
 	}
@@ -332,7 +339,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	/* Convert relative doorbell offset into absolute doorbell index */
 	index = amdgpu_userqueue_get_doorbell_index(uq_mgr, &db_info, filp);
 	if (index == (uint64_t)-EINVAL) {
-		DRM_ERROR("Failed to get doorbell for queue\n");
+		drm_err(adev_to_drm(adev), "Failed to get doorbell for queue\n");
 		kfree(queue);
 		goto unlock;
 	}
@@ -341,13 +348,13 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	xa_init_flags(&queue->fence_drv_xa, XA_FLAGS_ALLOC);
 	r = amdgpu_userq_fence_driver_alloc(adev, queue);
 	if (r) {
-		DRM_ERROR("Failed to alloc fence driver\n");
+		drm_err(adev_to_drm(adev), "Failed to alloc fence driver\n");
 		goto unlock;
 	}
 
 	r = uq_funcs->mqd_create(uq_mgr, &args->in, queue);
 	if (r) {
-		DRM_ERROR("Failed to create Queue\n");
+		drm_err(adev_to_drm(adev), "Failed to create Queue\n");
 		amdgpu_userq_fence_driver_free(queue);
 		kfree(queue);
 		goto unlock;
@@ -355,7 +362,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 
 	qid = idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ_COUNT, GFP_KERNEL);
 	if (qid < 0) {
-		DRM_ERROR("Failed to allocate a queue id\n");
+		drm_err(adev_to_drm(adev), "Failed to allocate a queue id\n");
 		amdgpu_userq_fence_driver_free(queue);
 		uq_funcs->mqd_destroy(uq_mgr, queue);
 		kfree(queue);
@@ -365,7 +372,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 
 	r = uq_funcs->map(uq_mgr, queue);
 	if (r) {
-		DRM_ERROR("Failed to map Queue\n");
+		drm_err(adev_to_drm(adev), "Failed to map Queue\n");
 		idr_remove(&uq_mgr->userq_idr, qid);
 		amdgpu_userq_fence_driver_free(queue);
 		uq_funcs->mqd_destroy(uq_mgr, queue);
@@ -393,7 +400,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 			return -EINVAL;
 		r = amdgpu_userqueue_create(filp, args);
 		if (r)
-			DRM_ERROR("Failed to create usermode queue\n");
+			drm_err(dev, "Failed to create usermode queue\n");
 		break;
 
 	case AMDGPU_USERQ_OP_FREE:
@@ -411,11 +418,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 			return -EINVAL;
 		r = amdgpu_userqueue_destroy(filp, args->in.queue_id);
 		if (r)
-			DRM_ERROR("Failed to destroy usermode queue\n");
+			drm_err(dev, "Failed to destroy usermode queue\n");
 		break;
 
 	default:
-		DRM_DEBUG_DRIVER("Invalid user queue op specified: %d\n", args->in.op);
+		drm_dbg_driver(dev, "Invalid user queue op specified: %d\n", args->in.op);
 		return -EINVAL;
 	}
 
@@ -449,7 +456,7 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	if (ret) {
 		file = uq_mgr->file;
 		drm_process_info(file, proc_log, sizeof(proc_log));
-		DRM_ERROR("Failed to map all the queue for %s\n",
+		drm_err(adev_to_drm(uq_mgr->adev), "Failed to map all the queue for %s\n",
 			  proc_log);
 		}
 
@@ -490,7 +497,7 @@ amdgpu_userqueue_validate_bos(struct amdgpu_userq_mgr *uq_mgr)
 		ret = amdgpu_vm_lock_pd(vm, &exec, 2);
 		drm_exec_retry_on_contention(&exec);
 		if (unlikely(ret)) {
-			DRM_ERROR("Failed to lock PD\n");
+			drm_err(adev_to_drm(adev), "Failed to lock PD\n");
 			goto unlock_all;
 		}
 
@@ -530,7 +537,7 @@ amdgpu_userqueue_validate_bos(struct amdgpu_userq_mgr *uq_mgr)
 		bo = bo_va->base.bo;
 		ret = amdgpu_userqueue_validate_vm_bo(NULL, bo);
 		if (ret) {
-			DRM_ERROR("Failed to validate BO\n");
+			drm_err(adev_to_drm(adev), "Failed to validate BO\n");
 			goto unlock_all;
 		}
 
@@ -561,7 +568,7 @@ amdgpu_userqueue_validate_bos(struct amdgpu_userq_mgr *uq_mgr)
 
 	ret = amdgpu_eviction_fence_replace_fence(&fpriv->evf_mgr, &exec);
 	if (ret)
-		DRM_ERROR("Failed to replace eviction fence\n");
+		drm_err(adev_to_drm(adev), "Failed to replace eviction fence\n");
 
 unlock_all:
 	drm_exec_fini(&exec);
@@ -580,13 +587,13 @@ static void amdgpu_userqueue_resume_worker(struct work_struct *work)
 
 	ret = amdgpu_userqueue_validate_bos(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Failed to validate BOs to restore\n");
+		drm_err(adev_to_drm(uq_mgr->adev), "Failed to validate BOs to restore\n");
 		goto unlock;
 	}
 
 	ret = amdgpu_userqueue_resume_all(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Failed to resume all queues\n");
+		drm_err(adev_to_drm(uq_mgr->adev), "Failed to resume all queues\n");
 		goto unlock;
 	}
 
@@ -614,7 +621,7 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 	if (ret) {
 		file = uq_mgr->file;
 		drm_process_info(file, proc_log, sizeof(proc_log));
-		DRM_ERROR("Couldn't unmap all the queues for %s\n",
+		drm_err(adev_to_drm(adev), "Couldn't unmap all the queues for %s\n",
 			  proc_log);
 		}
 
@@ -638,8 +645,8 @@ amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 		if (ret <= 0) {
 			file = uq_mgr->file;
 			drm_process_info(file, proc_log, sizeof(proc_log));
-			DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
-				  f, proc_log);
+			drm_err(adev_to_drm(uq_mgr->adev),
+				"Timed out waiting for fence f=%p for %s\n", f, proc_log);
 			return -ETIMEDOUT;
 		}
 	}
@@ -662,8 +669,8 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr,
 	if (ret) {
 		file = uq_mgr->file;
 		drm_process_info(file, proc_log, sizeof(proc_log));
-		DRM_ERROR("Not suspending userqueue, timeout waiting for %s\n",
-			  proc_log);
+		drm_err(adev_to_drm(uq_mgr->adev),
+			"Not suspending userqueue, timeout waiting for %s\n", proc_log);
 		return;
 	}
 
@@ -671,7 +678,7 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr,
 	if (ret) {
 		file = uq_mgr->file;
 		drm_process_info(file, proc_log, sizeof(proc_log));
-		DRM_ERROR("Failed to evict userqueue for %s\n", proc_log);
+		drm_err(adev_to_drm(uq_mgr->adev), "Failed to evict userqueue for %s\n", proc_log);
 		return;
 	}
 
Signature · 1 line
2.34.1
#4 lore raw
In reply to Sunil Khatri
Quoted 27 lines · Sunil Khatri

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
  drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
  include/drm/drm_file.h     |  1 +
  2 files changed, 35 insertions(+)
drivers/gpu/drm/drm_file.c +9 -0
index c299cd94d3f7..728a60975f5e 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
  }
  EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 1007

Quoted 10 lines
drivers/gpu/drm/drm_file.c +10 -0
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+
+	if (!proc_info) {
+		drm_WARN_ON_ONCE(dev, "Invalid user buffer\n");
+		return;
+	}

I think this should be:

if (drm_WARN_ON_ONCE(dev, !proc_info))

	return;

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 1016

Quoted 9 lines
drivers/gpu/drm/drm_file.c +9 -0
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "client_name:%s proc:%s pid:%d",
+			 file_priv->client_name ? file_priv->client_name : "Unset",
+			 task->comm, task->pid);

Probably bad to return uninitialised string for the !task case.

Also, now that you added client name the case to move towards the helper which does not need a temporary buffer, like I was suggesting drm_file_err(drm_file *, const char *, ...), is IMO even stronger. Consider if nothing else DRM_CLIENT_NAME_MAX_LEN plus the length of other fields you will be adding (the series as is can truncate). And it would be a bit unsightly to require relatively huge stack buffers in the later patches when it can all be easily avoided.

Regards,

Tvrtko

Quoted 21 lines
drivers/gpu/drm/drm_file.c +6 -0
+
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_process_info);
+
  /**
   * mock_drm_getfile - Create a new struct file for the drm device
   * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index 94d365b22505..a972be73a615 100644
@@ -507,6 +507,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
  void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
  void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
  struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
 
maintainer
#5 lore raw

Am 15.04.25 um 13:40 schrieb Tvrtko Ursulin:

Quoted 54 lines · Sunil Khatri
Quoted 26 lines

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
  drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++ include/drm/drm_file.h     |  1 +

  2 files changed, 35 insertions(+)
drivers/gpu/drm/drm_file.c +0 -0
index c299cd94d3f7..728a60975f5e 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
   }
   EXPORT_SYMBOL(drm_show_fdinfo);

  +/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 1007

Quoted 10 lines
drivers/gpu/drm/drm_file.c +10 -0
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+    struct task_struct *task;
+    struct pid *pid;
+    struct drm_device *dev = file_priv->minor->dev;
+
+    if (!proc_info) {
+        drm_WARN_ON_ONCE(dev, "Invalid user buffer\n");
+        return;
+    }

I think this should be:

if (drm_WARN_ON_ONCE(dev, !proc_info))
    return;

Quoted 9 lines

+
+    mutex_lock(&file_priv->client_name_lock);
+    rcu_read_lock();
+    pid = rcu_dereference(file_priv->pid);
+    task = pid_task(pid, PIDTYPE_TGID);
+    if (task)
+        snprintf(proc_info, buff_size, "client_name:%s proc:%s pid:%d", +             file_priv->client_name ? file_priv->client_name : "Unset", +             task->comm, task->pid);

Quoted 3 lines

Probably bad to return uninitialised string for the !task case.

Also, now that you added client name the case to move towards the helper which does not need a temporary buffer, like I was suggesting drm_file_err(drm_file *, const char *, ...), is IMO even stronger. Consider if nothing else DRM_CLIENT_NAME_MAX_LEN plus the length of other fields you will be adding (the series as is can truncate). And it would be a bit unsightly to require relatively huge stack buffers in the later patches when it can all be easily avoided.

+1 for the drm_file_err() approach.

That is quite some nifty idea and could potentially be applied to quite some other cases as well.

Regards,
Christian.

Quoted 25 lines

Regards,

Tvrtko

Quoted 19 lines
drivers/gpu/drm/drm_file.c +6 -0
+
+    rcu_read_unlock();
+    mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_process_info);
+

  /**
   * mock_drm_getfile - Create a new struct file for the drm device
   * @minor: drm minor to wrap (e.g. #drm_device.primary)

include/drm/drm_file.h +1 -0
index 94d365b22505..a972be73a615 100644
@@ -507,6 +507,7 @@ void drm_print_memory_stats(struct drm_printer *p,
     void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
   void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
     struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);

#6 lore raw
In reply to Tvrtko Ursulin
Quoted 86 lines · Tvrtko Ursulin
Quoted 29 lines · Sunil Khatri

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
  drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++ include/drm/drm_file.h     |  1 +

  2 files changed, 35 insertions(+)
drivers/gpu/drm/drm_file.c +0 -0
index c299cd94d3f7..728a60975f5e 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct 
 file *f)
   }
   EXPORT_SYMBOL(drm_show_fdinfo);

  +/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 1007

Quoted 9 lines
drivers/gpu/drm/drm_file.c +9 -0
+{
+    struct task_struct *task;
+    struct pid *pid;
+    struct drm_device *dev = file_priv->minor->dev;
+
+    if (!proc_info) {
+        drm_WARN_ON_ONCE(dev, "Invalid user buffer\n");
+        return;
+    }

I think this should be:

if (drm_WARN_ON_ONCE(dev, !proc_info))
    return;

Quoted 9 lines

+
+    mutex_lock(&file_priv->client_name_lock);
+    rcu_read_lock();
+    pid = rcu_dereference(file_priv->pid);
+    task = pid_task(pid, PIDTYPE_TGID);
+    if (task)
+        snprintf(proc_info, buff_size, "client_name:%s proc:%s pid:%d", +             file_priv->client_name ? file_priv->client_name : "Unset", +             task->comm, task->pid);

Probably bad to return uninitialised string for the !task case.

Also, now that you added client name the case to move towards the helper which does not need a temporary buffer, like I was suggesting drm_file_err(drm_file *, const char *, ...), is IMO even stronger. Consider if nothing else DRM_CLIENT_NAME_MAX_LEN plus the length of other fields you will be adding (the series as is can truncate). And it would be a bit unsightly to require relatively huge stack buffers in the later patches when it can all be easily avoided.

Sure let me try adding a new drm_file_err which handles it without user input buffer. let me work on this and get back with a new patch set for this.

Regards,

Tvrtko

Quoted 19 lines
drivers/gpu/drm/drm_file.c +6 -0
+
+    rcu_read_unlock();
+    mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_process_info);
+

  /**
   * mock_drm_getfile - Create a new struct file for the drm device
   * @minor: drm minor to wrap (e.g. #drm_device.primary)

include/drm/drm_file.h +1 -0
index 94d365b22505..a972be73a615 100644
@@ -507,6 +507,7 @@ void drm_print_memory_stats(struct drm_printer *p,
     void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
   void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, 
 size_t buff_size);
     struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
maintainer
#7 lore raw
In reply to Sunil Khatri

Am 15.04.25 um 13:25 schrieb Sunil Khatri:

Quoted 36 lines

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
 drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  1 +
 2 files changed, 35 insertions(+)
drivers/gpu/drm/drm_file.c +18 -0
index c299cd94d3f7..728a60975f5e 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
 }
 EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+
+	if (!proc_info) {
+		drm_WARN_ON_ONCE(dev, "Invalid user buffer\n");
+		return;

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 1016

Quoted 10 lines
drivers/gpu/drm/drm_file.c +10 -0
+	}
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "client_name:%s proc:%s pid:%d",
+			 file_priv->client_name ? file_priv->client_name : "Unset",
+			 task->comm, task->pid);

Client name should probably come after the others. And you can reduce file_priv->client_name ? file_priv->client_name : "Unset" to just file_priv->client_name ?: "Unset".

Regards,
Christian.

Quoted 21 lines
drivers/gpu/drm/drm_file.c +6 -0
+
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_process_info);
+
 /**
  * mock_drm_getfile - Create a new struct file for the drm device
  * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index 94d365b22505..a972be73a615 100644
@@ -507,6 +507,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
 void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
 void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);