Skip to contentSkip to conversation

drm: add drm_file_err function to add process info

PATCH Superseded Sunil Khatri 3 participants 13 messages Apr 17, 2025

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/5 drm: add drm_file_err function to add process info

Add a drm helper function which append the process information for the drm_file over drm_err formated output.

v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)

v6: remove __maybe_unused and make function inline (Jani Nikula)
remove drm_print.h

v7: Use va_format and %pV to concatenate fmt and vargs (Jani Nikula)

---
 drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  3 +++
 2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_file.c +34 -0
index c299cd94d3f7..7e64d84d4e2d 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
 }
 EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_file_err - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @fmt: prinf() like format string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+	va_list args;
+	struct va_format vaf;
+
+	va_start(args, fmt);
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+
+	drm_err(dev, "comm: %s pid: %d client: %s %pV", task ? task->comm : "",
+		task ? task->pid : 0, file_priv->client_name ?: "Unset", &vaf);
+
+	va_end(args);
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_file_err);
+
 /**
  * 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 +3 -0
index 94d365b22505..5c3b2aa3e69d 100644
@@ -446,6 +446,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
 	return file_priv->minor->type == DRM_MINOR_ACCEL;
 }
 
+__printf(2, 3)
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...);
+
 void drm_file_update_pid(struct drm_file *);
 
 struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 2/5 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 0701f33e6740..fe5d1c8afb9b 100644
@@ -78,6 +78,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
Reviewed-by on v6 2/5
#2 lore raw

Re: [PATCH V6 2/5] drm/amdgpu: add drm_file reference in userq_mgr

Quoted 30 lines · Sunil Khatri

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 +0 -0
index 0701f33e6740..fe5d1c8afb9b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h struct amdgpu_userq_mgr { · line 84

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1 -0
@@ -78,6 +78,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 {

With the promise you will later move the initialisation into amdgpu_userq_mgr_init():

Regards,

Tvrtko

#3 lore raw

PATCH v6 3/5 drm/amdgpu: use drm_file_err in fence timeouts

In reply to Sunil Khatri

use drm_file_err instead of DRM_ERROR which adds process and pid information in the userqueue error logging.

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 | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13 -8
index cd9dc0018ee6..613a3a63301b 100644
@@ -43,8 +43,9 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
 	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=%llu:%llu\n",
-				  f->context, f->seqno);
+			drm_file_err(uq_mgr->file,
+				     "Timed out waiting for fence: context=%llu seqno:%llu\n",
+				     f->context, f->seqno);
 			return;
 		}
 	}
@@ -456,7 +457,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	}
 
 	if (ret)
-		DRM_ERROR("Failed to map all the queues\n");
+		drm_file_err(uq_mgr->file, "Failed to map all the queues\n");
+
 	return ret;
 }
 
@@ -614,7 +616,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 	}
 
 	if (ret)
-		DRM_ERROR("Couldn't unmap all the queues\n");
+		drm_file_err(uq_mgr->file, "Couldn't unmap all the queues\n");
+
 	return ret;
 }
 
@@ -631,8 +634,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=%llu:%llu\n",
-				  f->context, f->seqno);
+			drm_file_err(uq_mgr->file,
+				     "Timed out waiting for fence: context=%llu seqno:%llu\n",
+				     f->context, f->seqno);
+
 			return -ETIMEDOUT;
 		}
 	}
@@ -651,13 +656,13 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_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");
+		drm_file_err(uq_mgr->file, "Not suspending userqueue, timeout waiting\n");
 		return;
 	}
 
 	ret = amdgpu_userqueue_suspend_all(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Failed to evict userqueue\n");
+		drm_file_err(uq_mgr->file, "Failed to evict userqueue\n");
 		return;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by on v6 3/5
#4 lore raw

Re: [PATCH V6 3/5] drm/amdgpu: use drm_file_err in fence timeouts

Quoted 9 lines · Sunil Khatri

use drm_file_err instead of DRM_ERROR which adds process and pid information in the userqueue error logging.

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

If you have some oomph left after this many revisions in a short time it would be good to update the examples to latest format.

Quoted 10 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 ++++++++++++-------
  1 file changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -0
index cd9dc0018ee6..613a3a63301b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr, · line 48

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +3 -2
@@ -43,8 +43,9 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
  	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=%llu:%llu\n",
-				  f->context, f->seqno);
+			drm_file_err(uq_mgr->file,
+				     "Timed out waiting for fence: context=%llu seqno:%llu\n",
+				     f->context, f->seqno);

I would just go "...fence=%llu:%llu" for consistency with tracepoints but up to you.

Quoted 37 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +8 -4
  			return;
  		}
  	}
@@ -456,7 +457,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
  	}
 
  	if (ret)
-		DRM_ERROR("Failed to map all the queues\n");
+		drm_file_err(uq_mgr->file, "Failed to map all the queues\n");
+
  	return ret;
  }
 
@@ -614,7 +616,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
  	}
 
  	if (ret)
-		DRM_ERROR("Couldn't unmap all the queues\n");
+		drm_file_err(uq_mgr->file, "Couldn't unmap all the queues\n");
+
  	return ret;
  }
 
@@ -631,8 +634,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=%llu:%llu\n",
-				  f->context, f->seqno);
+			drm_file_err(uq_mgr->file,
+				     "Timed out waiting for fence: context=%llu seqno:%llu\n",
+				     f->context, f->seqno);
+
  			return -ETIMEDOUT;
  		}
  	}

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr, · line 659

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
@@ -651,13 +656,13 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_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");
+		drm_file_err(uq_mgr->file, "Not suspending userqueue, timeout waiting\n");

...work?

Anyway, we can tidy it later.

With or without fence=%llu:%llu:

Regards,

Tvrtko

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
  		return;
  	}
 
  	ret = amdgpu_userqueue_suspend_all(uq_mgr);
  	if (ret) {
-		DRM_ERROR("Failed to evict userqueue\n");
+		drm_file_err(uq_mgr->file, "Failed to evict userqueue\n");
  		return;
  	}
 
#5 lore raw

Re: [PATCH V6 3/5] drm/amdgpu: use drm_file_err in fence timeouts

Quoted 6 lines · Tvrtko Ursulin
Quoted 4 lines · Sunil Khatri

use drm_file_err instead of DRM_ERROR which adds process and pid information in the userqueue error logging.

Quoted 7 lines
Quoted 5 lines

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

If you have some oomph left after this many revisions in a short time it would be good to update the examples to latest format.

Will push the changes in new patch set

regards

Sunil

Quoted 88 lines
Quoted 10 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 ++++++++++++-------

  1 file changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -0
index cd9dc0018ee6..613a3a63301b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr · line 50

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +3 -2
@@ -43,8 +43,9 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr 
 *uq_mgr,
       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=%llu:%llu\n",
-                  f->context, f->seqno);
+            drm_file_err(uq_mgr->file,
+                     "Timed out waiting for fence: context=%llu 
 seqno:%llu\n",
+                     f->context, f->seqno);

I would just go "...fence=%llu:%llu" for consistency with tracepoints but up to you.

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -0
               return;

          }
      }

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -1
@@ -456,7 +457,8 @@ amdgpu_userqueue_resume_all(struct 
 amdgpu_userq_mgr *uq_mgr)
       }
         if (ret)
-        DRM_ERROR("Failed to map all the queues\n");
+        drm_file_err(uq_mgr->file, "Failed to map all the queues\n");
+
       return ret;
   }
   @@ -614,7 +616,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)

      }
        if (ret)
-        DRM_ERROR("Couldn't unmap all the queues\n");
+        drm_file_err(uq_mgr->file, "Couldn't unmap all the queues\n");
+
      return ret;
  }
  @@ -631,8 +634,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=%llu:%llu\n",
-                  f->context, f->seqno);
+            drm_file_err(uq_mgr->file,
+                     "Timed out waiting for fence: context=%llu seqno:%llu\n",
+                     f->context, f->seqno);
+
              return -ETIMEDOUT;
          }
      }

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_suspend(struct · line 662

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
@@ -651,13 +656,13 @@ amdgpu_userqueue_suspend(struct 
 amdgpu_userq_mgr *uq_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");
+        drm_file_err(uq_mgr->file, "Not suspending userqueue, 
 timeout waiting\n");

...work?

Anyway, we can tidy it later.

With or without fence=%llu:%llu:

Regards,

Tvrtko

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
           return;
       }
         ret = amdgpu_userqueue_suspend_all(uq_mgr);
       if (ret) {
-        DRM_ERROR("Failed to evict userqueue\n");
+        drm_file_err(uq_mgr->file, "Failed to evict userqueue\n");
           return;

      }

#6 lore raw

PATCH v6 4/5 drm/amdgpu: change DRM_ERROR to drm_file_err in amdgpu_userqueue.c

In reply to Sunil Khatri

change the DRM_ERROR to drm_file_err to add process name and pid to the logging.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 52 +++++++++++--------
 1 file changed, 29 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +29 -23
index 613a3a63301b..4ef49179bbaf 100644
@@ -125,25 +125,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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "Failed to map BO for userqueue (%d)", r);
 		goto unresv;
 	}
 
@@ -179,7 +179,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_file_err(uq_mgr->file, "Can't find GEM object for doorbell\n");
 		return -EINVAL;
 	}
 
@@ -189,13 +189,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_file_err(uq_mgr->file,
+			"[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_file_err(uq_mgr->file,
+			"[Usermode queues] Failed to pin doorbell object\n");
 		goto unpin_bo;
 	}
 
@@ -217,7 +219,8 @@ 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_file_err(uq_mgr->file,
+			     "[Usermode queues] IP %d not support\n", db_info->queue_type);
 		r = -EINVAL;
 		goto unpin_bo;
 	}
@@ -285,7 +288,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_file_err(uq_mgr->file,
+			     "Usermode queue doesn't support IP type %u\n", args->in.ip_type);
 		return -EINVAL;
 	}
 
@@ -307,14 +311,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_file_err(uq_mgr->file,
+			"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_file_err(uq_mgr->file, "Failed to allocate memory for queue\n");
 		r = -ENOMEM;
 		goto unlock;
 	}
@@ -330,7 +336,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_file_err(uq_mgr->file, "Failed to get doorbell for queue\n");
 		kfree(queue);
 		goto unlock;
 	}
@@ -339,13 +345,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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "Failed to create Queue\n");
 		amdgpu_userq_fence_driver_free(queue);
 		kfree(queue);
 		goto unlock;
@@ -354,7 +360,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_file_err(uq_mgr->file, "Failed to allocate a queue id\n");
 		amdgpu_userq_fence_driver_free(queue);
 		uq_funcs->mqd_destroy(uq_mgr, queue);
 		kfree(queue);
@@ -374,7 +380,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 		r = uq_funcs->map(uq_mgr, queue);
 		if (r) {
 			mutex_unlock(&adev->userq_mutex);
-			DRM_ERROR("Failed to map Queue\n");
+			drm_file_err(uq_mgr->file, "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);
@@ -405,7 +411,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_file_err(filp, "Failed to create usermode queue\n");
 		break;
 
 	case AMDGPU_USERQ_OP_FREE:
@@ -423,7 +429,7 @@ 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_file_err(filp, "Failed to destroy usermode queue\n");
 		break;
 
 	default:
@@ -496,7 +502,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_file_err(uq_mgr->file, "Failed to lock PD\n");
 			goto unlock_all;
 		}
 
@@ -536,7 +542,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_file_err(uq_mgr->file, "Failed to validate BO\n");
 			goto unlock_all;
 		}
 
@@ -567,7 +573,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_file_err(uq_mgr->file, "Failed to replace eviction fence\n");
 
 unlock_all:
 	drm_exec_fini(&exec);
@@ -586,13 +592,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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "Failed to resume all queues\n");
 		goto unlock;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by on v6 4/5
#7 lore raw

Re: [PATCH V6 4/5] drm/amdgpu: change DRM_ERROR to drm_file_err in amdgpu_userqueue.c

Quoted 52 lines · Sunil Khatri

change the DRM_ERROR to drm_file_err to add process name and pid to the logging.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 52 +++++++++++--------
  1 file changed, 29 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -5
index 613a3a63301b..4ef49179bbaf 100644
@@ -125,25 +125,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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "Failed to map BO for userqueue (%d)", r);
  		goto unresv;
  	}
 
@@ -179,7 +179,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_file_err(uq_mgr->file, "Can't find GEM object for doorbell\n");
  		return -EINVAL;
  	}
 

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 193

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -1
@@ -189,13 +189,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_file_err(uq_mgr->file,
+			"[Usermode queues] Failed to pin doorbell object\n");

Cehck indentation?

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 200

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -1
  		goto unref_bo;
  	}
 
  	r = amdgpu_bo_reserve(db_obj->obj, true);
  	if (r) {
-		DRM_ERROR("[Usermode queues] Failed to pin doorbell object\n");
+		drm_file_err(uq_mgr->file,
+			"[Usermode queues] Failed to pin doorbell object\n");

Ditto.

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, · line 223

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -1
  		goto unpin_bo;
  	}
 
@@ -217,7 +219,8 @@ 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_file_err(uq_mgr->file,
+			     "[Usermode queues] IP %d not support\n", db_info->queue_type);

Not supportED or doesn't support? I don't know which one, but something, as followup, should be done.

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) · line 292

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -1
  		r = -EINVAL;
  		goto unpin_bo;
  	}
@@ -285,7 +288,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_file_err(uq_mgr->file,
+			     "Usermode queue doesn't support IP type %u\n", args->in.ip_type);

Also as follow up someone should IMO remove all drm_err from user triggerable ioctl failure paths.

Quoted 116 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15 -13
  		return -EINVAL;
  	}
 
@@ -307,14 +311,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_file_err(uq_mgr->file,
+			"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_file_err(uq_mgr->file, "Failed to allocate memory for queue\n");
  		r = -ENOMEM;
  		goto unlock;
  	}
@@ -330,7 +336,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_file_err(uq_mgr->file, "Failed to get doorbell for queue\n");
  		kfree(queue);
  		goto unlock;
  	}
@@ -339,13 +345,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_file_err(uq_mgr->file, "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_file_err(uq_mgr->file, "Failed to create Queue\n");
  		amdgpu_userq_fence_driver_free(queue);
  		kfree(queue);
  		goto unlock;
@@ -354,7 +360,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_file_err(uq_mgr->file, "Failed to allocate a queue id\n");
  		amdgpu_userq_fence_driver_free(queue);
  		uq_funcs->mqd_destroy(uq_mgr, queue);
  		kfree(queue);
@@ -374,7 +380,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  		r = uq_funcs->map(uq_mgr, queue);
  		if (r) {
  			mutex_unlock(&adev->userq_mutex);
-			DRM_ERROR("Failed to map Queue\n");
+			drm_file_err(uq_mgr->file, "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);
@@ -405,7 +411,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_file_err(filp, "Failed to create usermode queue\n");
  		break;
 
  	case AMDGPU_USERQ_OP_FREE:
@@ -423,7 +429,7 @@ 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_file_err(filp, "Failed to destroy usermode queue\n");
  		break;
 
  	default:
@@ -496,7 +502,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_file_err(uq_mgr->file, "Failed to lock PD\n");
  			goto unlock_all;
  		}
 
@@ -536,7 +542,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_file_err(uq_mgr->file, "Failed to validate BO\n");
  			goto unlock_all;
  		}
 
@@ -567,7 +573,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_file_err(uq_mgr->file, "Failed to replace eviction fence\n");
 
  unlock_all:
  	drm_exec_fini(&exec);
@@ -586,13 +592,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_file_err(uq_mgr->file, "Failed to validate BOs to restore\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c static void amdgpu_userqueue_resume_worker(struct work_struct *work) · line 604

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
  		goto unlock;
  	}
 
  	ret = amdgpu_userqueue_resume_all(uq_mgr);
  	if (ret) {
-		DRM_ERROR("Failed to resume all queues\n");
+		drm_file_err(uq_mgr->file, "Failed to resume all queues\n");
  		goto unlock;
  	}
 

With the indendation checked and fixed if needed:

Regards,

Tvrtko

#8 lore raw

PATCH v6 5/5 drm/amdgpu: change DRM_DBG_DRIVER to drm_dbg_driver

In reply to Sunil Khatri

update the functions in amdgpu_userqueues.c from DRM_DBG_DRIVER to drm_dbg_driver so multi gpu instance can be logged in.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -3
index 4ef49179bbaf..4729425c04a5 100644
@@ -227,7 +227,8 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 
 	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 +255,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(adev), "Invalid queue id to destroy\n");
 		mutex_unlock(&uq_mgr->userq_mutex);
 		return -EINVAL;
 	}
@@ -433,7 +434,8 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		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;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by on v6 5/5
#9 lore raw

Re: [PATCH V6 5/5] drm/amdgpu: change DRM_DBG_DRIVER to drm_dbg_driver

Quoted 33 lines · Sunil Khatri

update the functions in amdgpu_userqueues.c from DRM_DBG_DRIVER to drm_dbg_driver so multi gpu instance can be logged in.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +3 -2
index 4ef49179bbaf..4729425c04a5 100644
@@ -227,7 +227,8 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 
  	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 +255,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(adev), "Invalid queue id to destroy\n");
  		mutex_unlock(&uq_mgr->userq_mutex);
  		return -EINVAL;
  	}

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c int amdgpu_userq_ioctl(struct drm_device *dev, void *data, · line 441

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -1
@@ -433,7 +434,8 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
  		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;
  	}
 

Regards,

Tvrtko

Reviewed-by on v6 1/5
#10 lore raw
In reply to Sunil Khatri
Quoted 1 line · Sunil Khatri

Add a drm helper function which append the process information for

appends

Quoted 1 line

the drm_file over drm_err formated output.

formatted

Quoted 19 lines

v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)

v6: remove __maybe_unused and make function inline (Jani Nikula)
remove drm_print.h

v7: Use va_format and %pV to concatenate fmt and vargs (Jani Nikula)

---
  drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
  include/drm/drm_file.h     |  3 +++
  2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_file.c +0 -0
index c299cd94d3f7..7e64d84d4e2d 100644

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

Quoted 5 lines
drivers/gpu/drm/drm_file.c +2 -0
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
  }
  EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_file_err - Fill info string with process name and pid

Update to something like:

drm_file_err - Log error message associated with a drm_file client

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

Quoted 2 lines
drivers/gpu/drm/drm_file.c +2 -0
+ * @file_priv: context of interest for process name and pid
+ * @fmt: prinf() like format string

printf

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

Quoted 3 lines
drivers/gpu/drm/drm_file.c +3 -0
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv

Also stale but it may be okay to drop altogether since short description feels enough for a logging helper.

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

Quoted 8 lines
drivers/gpu/drm/drm_file.c +8 -0
+ */
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+	va_list args;
+	struct va_format vaf;

You could tidy the declaration block a bit, usually ordering from longer to narrower lines for readability but up to you.

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

Quoted 13 lines
drivers/gpu/drm/drm_file.c +13 -0
+
+	va_start(args, fmt);
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+
+	drm_err(dev, "comm: %s pid: %d client: %s %pV", task ? task->comm : "",
+		task ? task->pid : 0, file_priv->client_name ?: "Unset", &vaf);
+

Hm is task->pid the tid or tgid? Could be the same thing due getting PIDTYPE_GID.. PID namespaces are always endlessly confusing to me since I don't work in that area often enough.

And I have some bikeshedding ideas for the format, like maybe consolidating with naming used in drm_clients_info() and adding some separator between the client data and the log message that follows. Like:

"Client %s[%d] (%s): %pV",
task ? task->comm : "<unknown>",
pid_nr(pid),
file_priv->client_name ?: "<unset>",
...

And even if I am a bit unsure about the "<unknown>", I think it doesn't harm to be consistent. It is fine as is though, so you decide if you want to change anything or not.

If you could please double check task->pid is indeed definitely TGID:

Regards,

Tvrtko

Quoted 23 lines
drivers/gpu/drm/drm_file.c +6 -0
+	va_end(args);
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_file_err);
+
  /**
   * 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 +3 -0
index 94d365b22505..5c3b2aa3e69d 100644
@@ -446,6 +446,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
  	return file_priv->minor->type == DRM_MINOR_ACCEL;
  }
 
+__printf(2, 3)
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...);
+
  void drm_file_update_pid(struct drm_file *);
 
  struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
#11 lore raw
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Sunil Khatri

Add a drm helper function which append the process information for

appends

Noted

Quoted 4 lines
Quoted 2 lines

the drm_file over drm_err formated output.

formatted

'Noted

Quoted 41 lines
Quoted 23 lines

v5: change to macro from function (Christian Koenig) add helper functions for lock/unlock (Christian Koenig)

v6: remove __maybe_unused and make function inline (Jani Nikula) remove drm_print.h

v7: Use va_format and %pV to concatenate fmt and vargs (Jani Nikula)

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

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

  +/**
+ * drm_file_err - Fill info string with process name and pid

Update to something like:

drm_file_err - Log error message associated with a drm_file client

Quoted 2 lines

+ * @file_priv: context of interest for process name and pid
+ * @fmt: prinf() like format string

printf

Quoted 3 lines

+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv

Also stale but it may be okay to drop altogether since short description feels enough for a logging helper.

Quoted 10 lines

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

Quoted 8 lines

+ */

drivers/gpu/drm/drm_file.c +7 -0
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...)
+{
+    struct task_struct *task;
+    struct pid *pid;
+    struct drm_device *dev = file_priv->minor->dev;
+    va_list args;
+    struct va_format vaf;

You could tidy the declaration block a bit, usually ordering from longer to narrower lines for readability but up to you.

Sure

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_file.c +8 -0
+
+    va_start(args, fmt);
+    vaf.fmt = fmt;
+    vaf.va = &args;
+
+    mutex_lock(&file_priv->client_name_lock);
+    rcu_read_lock();
+    pid = rcu_dereference(file_priv->pid);
Quoted 9 lines
Quoted 6 lines

+    task = pid_task(pid, PIDTYPE_TGID);
+
+    drm_err(dev, "comm: %s pid: %d client: %s %pV", task ? task->comm : "",
+        task ? task->pid : 0, file_priv->client_name ?: "Unset", &vaf); +

Hm is task->pid the tid or tgid? Could be the same thing due getting PIDTYPE_GID.. PID namespaces are always endlessly confusing to me since I don't work in that area often enough.

There are two parameters in task_struct one is pid and tgid and both are different if i am not wrong. In case of multi thread pid and tgid is different if its one thread i guess in that case pid and tgid are same but even i am not 100% sure.

Quoted 7 lines

And I have some bikeshedding ideas for the format, like maybe consolidating with naming used in drm_clients_info() and adding some separator between the client data and the log message that follows. Like:

"Client %s[%d] (%s): %pV",
task ? task->comm : "<unknown>",
pid_nr(pid),
file_priv->client_name ?: "<unset>",
...

Sure

Quoted 34 lines

And even if I am a bit unsure about the "<unknown>", I think it doesn't harm to be consistent. It is fine as is though, so you decide if you want to change anything or not.

If you could please double check task->pid is indeed definitely TGID:

Regards,

Tvrtko

Quoted 22 lines

+    va_end(args);
+    rcu_read_unlock();
+    mutex_unlock(&file_priv->client_name_lock);

drivers/gpu/drm/drm_file.c +3 -0
+}
+EXPORT_SYMBOL(drm_file_err);
+

  /**
   * 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 +2 -0
index 94d365b22505..5c3b2aa3e69d 100644
@@ -446,6 +446,9 @@ static inline bool drm_is_accel_client(const 
 struct drm_file *file_priv)
       return file_priv->minor->type == DRM_MINOR_ACCEL;
   }
   +__printf(2, 3)
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...);
+
   void drm_file_update_pid(struct drm_file *);
     struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
#12 lore raw
In reply to Sunil Khatri

For rest of the patches which are part of the amdgpu tree will push incorporating changes as shared by @Tvrtko Ursulin <[email protected]> once drm change is merged.

Thanks a lot all for the reviews.

Regards

Sunil Khatri

Quoted 76 lines · Sunil Khatri

Add a drm helper function which append the process information for the drm_file over drm_err formated output.

v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)

v6: remove __maybe_unused and make function inline (Jani Nikula)
remove drm_print.h

v7: Use va_format and %pV to concatenate fmt and vargs (Jani Nikula)

---
  drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
  include/drm/drm_file.h     |  3 +++
  2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_file.c +34 -0
index c299cd94d3f7..7e64d84d4e2d 100644
@@ -986,6 +986,40 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
  }
  EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_file_err - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @fmt: prinf() like format string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+	va_list args;
+	struct va_format vaf;
+
+	va_start(args, fmt);
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+
+	drm_err(dev, "comm: %s pid: %d client: %s %pV", task ? task->comm : "",
+		task ? task->pid : 0, file_priv->client_name ?: "Unset", &vaf);
+
+	va_end(args);
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+EXPORT_SYMBOL(drm_file_err);
+
  /**
   * 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 +3 -0
index 94d365b22505..5c3b2aa3e69d 100644
@@ -446,6 +446,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
  	return file_priv->minor->type == DRM_MINOR_ACCEL;
  }
 
+__printf(2, 3)
+void drm_file_err(struct drm_file *file_priv, const char *fmt, ...);
+
  void drm_file_update_pid(struct drm_file *);
 
  struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);