diff mbox series

[v6,1/5] drm: add macro drm_file_err to print process info

Message ID 20250417091355.2240384-1-sunil.khatri@amd.com (mailing list archive)
State New
Headers show
Series [v6,1/5] drm: add macro drm_file_err to print process info | expand

Commit Message

Sunil Khatri April 17, 2025, 9:13 a.m. UTC
Add a drm helper macro which append the process information for
the drm_file over drm_err.

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

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Comments

Jani Nikula April 17, 2025, 9:35 a.m. UTC | #1
On Thu, 17 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote:
> Add a drm helper macro which append the process information for
> the drm_file over drm_err.
>
> 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

I guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Make
drm_file_err() a regular function and hide the implementation inside
drm_file.c. That's the cleanest approach IMO.

BR,
Jani.

>
> Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
> ---
>  include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
>
> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
> index 94d365b22505..856b38e996c7 100644
> --- a/include/drm/drm_file.h
> +++ b/include/drm/drm_file.h
> @@ -446,6 +446,43 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
>  	return file_priv->minor->type == DRM_MINOR_ACCEL;
>  }
>  
> +static inline struct task_struct *drm_task_lock(struct drm_file *file_priv)
> +{
> +	struct task_struct *task;
> +	struct pid *pid;
> +
> +	mutex_lock(&file_priv->client_name_lock);
> +	rcu_read_lock();
> +	pid = rcu_dereference(file_priv->pid);
> +	task = pid_task(pid, PIDTYPE_TGID);
> +	return task;
> +}
> +
> +static inline void drm_task_unlock(struct drm_file *file_priv)
> +{
> +	rcu_read_unlock();
> +	mutex_unlock(&file_priv->client_name_lock);
> +}
> +/**
> + * 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
> + */
> +#define drm_file_err(file_priv, fmt, ...)						\
> +	do {										\
> +		struct task_struct *task;						\
> +		struct drm_device *dev = file_priv->minor->dev;				\
> +											\
> +		task = drm_task_lock(file_priv);					\
> +		drm_err(dev, "comm: %s pid: %d client: %s " fmt,			\
> +			task ? task->comm : "", task ? task->pid : 0,			\
> +			file_priv->client_name ?: "Unset", ##__VA_ARGS__);		\
> +		drm_task_unlock(file_priv);						\
> +	} while (0)
> +
>  void drm_file_update_pid(struct drm_file *);
>  
>  struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
Christian König April 17, 2025, 9:57 a.m. UTC | #2
Am 17.04.25 um 11:35 schrieb Jani Nikula:
> On Thu, 17 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote:
>> Add a drm helper macro which append the process information for
>> the drm_file over drm_err.
>>
>> 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
> I guess I gave all kinds of comments, but in the end my conclusion was:
> why does *any* of this have to be static inline or macros? Make
> drm_file_err() a regular function and hide the implementation inside
> drm_file.c. That's the cleanest approach IMO.

That won't work. The macro is necessary to concatenate the format strings.

But the drm_task_lock() and drm_task_unlock() functions shouldn't be in the header. Those can be perfectly in drm_file.c or drm_print.c

And we should put drm_file_err into drm_print.h instead of drm_file.h as far as I can see.

Regards,
Christian.

>
> BR,
> Jani.
>
>> Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
>> ---
>>  include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++
>>  1 file changed, 37 insertions(+)
>>
>> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
>> index 94d365b22505..856b38e996c7 100644
>> --- a/include/drm/drm_file.h
>> +++ b/include/drm/drm_file.h
>> @@ -446,6 +446,43 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
>>  	return file_priv->minor->type == DRM_MINOR_ACCEL;
>>  }
>>  
>> +static inline struct task_struct *drm_task_lock(struct drm_file *file_priv)
>> +{
>> +	struct task_struct *task;
>> +	struct pid *pid;
>> +
>> +	mutex_lock(&file_priv->client_name_lock);
>> +	rcu_read_lock();
>> +	pid = rcu_dereference(file_priv->pid);
>> +	task = pid_task(pid, PIDTYPE_TGID);
>> +	return task;
>> +}
>> +
>> +static inline void drm_task_unlock(struct drm_file *file_priv)
>> +{
>> +	rcu_read_unlock();
>> +	mutex_unlock(&file_priv->client_name_lock);
>> +}
>> +/**
>> + * 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
>> + */
>> +#define drm_file_err(file_priv, fmt, ...)						\
>> +	do {										\
>> +		struct task_struct *task;						\
>> +		struct drm_device *dev = file_priv->minor->dev;				\
>> +											\
>> +		task = drm_task_lock(file_priv);					\
>> +		drm_err(dev, "comm: %s pid: %d client: %s " fmt,			\
>> +			task ? task->comm : "", task ? task->pid : 0,			\
>> +			file_priv->client_name ?: "Unset", ##__VA_ARGS__);		\
>> +		drm_task_unlock(file_priv);						\
>> +	} while (0)
>> +
>>  void drm_file_update_pid(struct drm_file *);
>>  
>>  struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
Jani Nikula April 17, 2025, 11:07 a.m. UTC | #3
On Thu, 17 Apr 2025, Christian König <christian.koenig@amd.com> wrote:
> Am 17.04.25 um 11:35 schrieb Jani Nikula:
>> On Thu, 17 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote:
>>> Add a drm helper macro which append the process information for
>>> the drm_file over drm_err.
>>>
>>> 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
>> I guess I gave all kinds of comments, but in the end my conclusion was:
>> why does *any* of this have to be static inline or macros? Make
>> drm_file_err() a regular function and hide the implementation inside
>> drm_file.c. That's the cleanest approach IMO.
>
> That won't work. The macro is necessary to concatenate the format strings.

I think you can handle them using struct va_format and %pV.

BR,
Jani.


>
> But the drm_task_lock() and drm_task_unlock() functions shouldn't be in the header. Those can be perfectly in drm_file.c or drm_print.c
>
> And we should put drm_file_err into drm_print.h instead of drm_file.h as far as I can see.
>
> Regards,
> Christian.
>
>>
>> BR,
>> Jani.
>>
>>> Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
>>> ---
>>>  include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++
>>>  1 file changed, 37 insertions(+)
>>>
>>> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
>>> index 94d365b22505..856b38e996c7 100644
>>> --- a/include/drm/drm_file.h
>>> +++ b/include/drm/drm_file.h
>>> @@ -446,6 +446,43 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
>>>  	return file_priv->minor->type == DRM_MINOR_ACCEL;
>>>  }
>>>  
>>> +static inline struct task_struct *drm_task_lock(struct drm_file *file_priv)
>>> +{
>>> +	struct task_struct *task;
>>> +	struct pid *pid;
>>> +
>>> +	mutex_lock(&file_priv->client_name_lock);
>>> +	rcu_read_lock();
>>> +	pid = rcu_dereference(file_priv->pid);
>>> +	task = pid_task(pid, PIDTYPE_TGID);
>>> +	return task;
>>> +}
>>> +
>>> +static inline void drm_task_unlock(struct drm_file *file_priv)
>>> +{
>>> +	rcu_read_unlock();
>>> +	mutex_unlock(&file_priv->client_name_lock);
>>> +}
>>> +/**
>>> + * 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
>>> + */
>>> +#define drm_file_err(file_priv, fmt, ...)						\
>>> +	do {										\
>>> +		struct task_struct *task;						\
>>> +		struct drm_device *dev = file_priv->minor->dev;				\
>>> +											\
>>> +		task = drm_task_lock(file_priv);					\
>>> +		drm_err(dev, "comm: %s pid: %d client: %s " fmt,			\
>>> +			task ? task->comm : "", task ? task->pid : 0,			\
>>> +			file_priv->client_name ?: "Unset", ##__VA_ARGS__);		\
>>> +		drm_task_unlock(file_priv);						\
>>> +	} while (0)
>>> +
>>>  void drm_file_update_pid(struct drm_file *);
>>>  
>>>  struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
>
Christian König April 17, 2025, 11:18 a.m. UTC | #4
Am 17.04.25 um 13:07 schrieb Jani Nikula:
> On Thu, 17 Apr 2025, Christian König <christian.koenig@amd.com> wrote:
>> Am 17.04.25 um 11:35 schrieb Jani Nikula:
>>> On Thu, 17 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote:
>>>> Add a drm helper macro which append the process information for
>>>> the drm_file over drm_err.
>>>>
>>>> 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
>>> I guess I gave all kinds of comments, but in the end my conclusion was:
>>> why does *any* of this have to be static inline or macros? Make
>>> drm_file_err() a regular function and hide the implementation inside
>>> drm_file.c. That's the cleanest approach IMO.
>> That won't work. The macro is necessary to concatenate the format strings.
> I think you can handle them using struct va_format and %pV.

Oh, really good point! I wasn't aware that this functionality exists.

Going to discuss that with Sunil internally.

Thanks,
Christian.

>
> BR,
> Jani.
>
>
>> But the drm_task_lock() and drm_task_unlock() functions shouldn't be in the header. Those can be perfectly in drm_file.c or drm_print.c
>>
>> And we should put drm_file_err into drm_print.h instead of drm_file.h as far as I can see.
>>
>> Regards,
>> Christian.
>>
>>> BR,
>>> Jani.
>>>
>>>> Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
>>>> ---
>>>>  include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++
>>>>  1 file changed, 37 insertions(+)
>>>>
>>>> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
>>>> index 94d365b22505..856b38e996c7 100644
>>>> --- a/include/drm/drm_file.h
>>>> +++ b/include/drm/drm_file.h
>>>> @@ -446,6 +446,43 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
>>>>  	return file_priv->minor->type == DRM_MINOR_ACCEL;
>>>>  }
>>>>  
>>>> +static inline struct task_struct *drm_task_lock(struct drm_file *file_priv)
>>>> +{
>>>> +	struct task_struct *task;
>>>> +	struct pid *pid;
>>>> +
>>>> +	mutex_lock(&file_priv->client_name_lock);
>>>> +	rcu_read_lock();
>>>> +	pid = rcu_dereference(file_priv->pid);
>>>> +	task = pid_task(pid, PIDTYPE_TGID);
>>>> +	return task;
>>>> +}
>>>> +
>>>> +static inline void drm_task_unlock(struct drm_file *file_priv)
>>>> +{
>>>> +	rcu_read_unlock();
>>>> +	mutex_unlock(&file_priv->client_name_lock);
>>>> +}
>>>> +/**
>>>> + * 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
>>>> + */
>>>> +#define drm_file_err(file_priv, fmt, ...)						\
>>>> +	do {										\
>>>> +		struct task_struct *task;						\
>>>> +		struct drm_device *dev = file_priv->minor->dev;				\
>>>> +											\
>>>> +		task = drm_task_lock(file_priv);					\
>>>> +		drm_err(dev, "comm: %s pid: %d client: %s " fmt,			\
>>>> +			task ? task->comm : "", task ? task->pid : 0,			\
>>>> +			file_priv->client_name ?: "Unset", ##__VA_ARGS__);		\
>>>> +		drm_task_unlock(file_priv);						\
>>>> +	} while (0)
>>>> +
>>>>  void drm_file_update_pid(struct drm_file *);
>>>>  
>>>>  struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
Jani Nikula April 17, 2025, 11:30 a.m. UTC | #5
On Thu, 17 Apr 2025, Christian König <christian.koenig@amd.com> wrote:
> Am 17.04.25 um 13:07 schrieb Jani Nikula:
>> On Thu, 17 Apr 2025, Christian König <christian.koenig@amd.com> wrote:
>>> Am 17.04.25 um 11:35 schrieb Jani Nikula:
>>>> On Thu, 17 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote:
>>>>> Add a drm helper macro which append the process information for
>>>>> the drm_file over drm_err.
>>>>>
>>>>> 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
>>>> I guess I gave all kinds of comments, but in the end my conclusion was:
>>>> why does *any* of this have to be static inline or macros? Make
>>>> drm_file_err() a regular function and hide the implementation inside
>>>> drm_file.c. That's the cleanest approach IMO.
>>> That won't work. The macro is necessary to concatenate the format strings.
>> I think you can handle them using struct va_format and %pV.
>
> Oh, really good point! I wasn't aware that this functionality exists.
>
> Going to discuss that with Sunil internally.

Please see the completely untested patch below for a starting point.

BR,
Jani.



From 55968ab339467c5b6e12ceb157ecbaf62eaa6082 Mon Sep 17 00:00:00 2001
From: Sunil Khatri <sunil.khatri@amd.com>
Date: Thu, 17 Apr 2025 14:43:51 +0530
Subject: [PATCH] drm: add macro drm_file_err to print process info
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Cc: Jani Nikula <jani.nikula@intel.com>

Add a drm helper macro which append the process information for
the drm_file over drm_err.

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

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/drm_file.c | 45 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  3 +++
 2 files changed, 48 insertions(+)

diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
index c299cd94d3f7..dea954f57890 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -1025,3 +1025,48 @@ struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags)
 	return file;
 }
 EXPORT_SYMBOL_FOR_TESTS_ONLY(mock_drm_getfile);
+
+static struct task_struct *drm_task_lock(struct drm_file *file_priv)
+{
+	struct task_struct *task;
+	struct pid *pid;
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+
+	return task;
+}
+
+static void drm_task_unlock(struct drm_file *file_priv)
+{
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+/**
+ * drm_file_err - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @format: printf() 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 *format, ...)
+{
+	struct drm_device *dev = file_priv->minor->dev;
+	struct task_struct *task;
+	struct va_format vaf;
+	va_list args;
+
+	va_start(args, format);
+	vaf.fmt = format;
+	vaf.va = &args;
+
+	task = drm_task_lock(file_priv);
+	drm_err(dev, "comm: %s pid: %d client: %s %pV",
+		task ? task->comm : "", task ? task->pid : 0,
+		file_priv->client_name ?: "Unset", &vaf);
+	drm_task_unlock(file_priv);
+}
+EXPORT_SYMBOL(drm_file_err);
diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 94d365b22505..ceb08a67f0b7 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -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 *format, ...);
+
 void drm_file_update_pid(struct drm_file *);
 
 struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
Sunil Khatri April 17, 2025, 11:38 a.m. UTC | #6
[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Jani Nikula <jani.nikula@linux.intel.com>
Sent: Thursday, April 17, 2025 5:00 PM
To: Koenig, Christian <Christian.Koenig@amd.com>; Khatri, Sunil <Sunil.Khatri@amd.com>; dri-devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Tvrtko Ursulin <tvrtko.ursulin@igalia.com>; Pelloux-Prayer, Pierre-Eric <Pierre-eric.Pelloux-prayer@amd.com>
Subject: Re: [PATCH v6 1/5] drm: add macro drm_file_err to print process info

On Thu, 17 Apr 2025, Christian König <christian.koenig@amd.com> wrote:
> Am 17.04.25 um 13:07 schrieb Jani Nikula:
>> On Thu, 17 Apr 2025, Christian König <christian.koenig@amd.com> wrote:
>>> Am 17.04.25 um 11:35 schrieb Jani Nikula:
>>>> On Thu, 17 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote:
>>>>> Add a drm helper macro which append the process information for
>>>>> the drm_file over drm_err.
>>>>>
>>>>> 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
>>>> I guess I gave all kinds of comments, but in the end my conclusion was:
>>>> why does *any* of this have to be static inline or macros? Make
>>>> drm_file_err() a regular function and hide the implementation
>>>> inside drm_file.c. That's the cleanest approach IMO.
>>> That won't work. The macro is necessary to concatenate the format strings.
>> I think you can handle them using struct va_format and %pV.
>
> Oh, really good point! I wasn't aware that this functionality exists.
>
> Going to discuss that with Sunil internally.

Please see the completely untested patch below for a starting point.

BR,
Jani.



From 55968ab339467c5b6e12ceb157ecbaf62eaa6082 Mon Sep 17 00:00:00 2001
From: Sunil Khatri <sunil.khatri@amd.com>
Date: Thu, 17 Apr 2025 14:43:51 +0530
Subject: [PATCH] drm: add macro drm_file_err to print process info
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Cc: Jani Nikula <jani.nikula@intel.com>

Add a drm helper macro which append the process information for the drm_file over drm_err.

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

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/drm_file.c | 45 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  3 +++
 2 files changed, 48 insertions(+)

diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index c299cd94d3f7..dea954f57890 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -1025,3 +1025,48 @@ struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags)
        return file;
 }
 EXPORT_SYMBOL_FOR_TESTS_ONLY(mock_drm_getfile);
+
+static struct task_struct *drm_task_lock(struct drm_file *file_priv) {
+       struct task_struct *task;
+       struct pid *pid;
+
+       mutex_lock(&file_priv->client_name_lock);
+       rcu_read_lock();
+       pid = rcu_dereference(file_priv->pid);
+       task = pid_task(pid, PIDTYPE_TGID);
+
+       return task;
+}
+
+static void drm_task_unlock(struct drm_file *file_priv) {
+       rcu_read_unlock();
+       mutex_unlock(&file_priv->client_name_lock);
+}
+/**
+ * drm_file_err - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @format: printf() 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 *format, ...) {
+       struct drm_device *dev = file_priv->minor->dev;
+       struct task_struct *task;
+       struct va_format vaf;
+       va_list args;
+
+       va_start(args, format);
+       vaf.fmt = format;
+       vaf.va = &args;
+
+       task = drm_task_lock(file_priv);
+       drm_err(dev, "comm: %s pid: %d client: %s %pV",
+               task ? task->comm : "", task ? task->pid : 0,
+               file_priv->client_name ?: "Unset", &vaf);
+       drm_task_unlock(file_priv);
+}
+EXPORT_SYMBOL(drm_file_err);

I made this change only and validating it. Thanks a lot for suggesting it. Would be great if it works as intended and as we need it.

Regards
Sunil Khatri

diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 94d365b22505..ceb08a67f0b7 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -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 *format, ...);
+
 void drm_file_update_pid(struct drm_file *);

 struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
--
2.39.5




--
Jani Nikula, Intel
diff mbox series

Patch

diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 94d365b22505..856b38e996c7 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -446,6 +446,43 @@  static inline bool drm_is_accel_client(const struct drm_file *file_priv)
 	return file_priv->minor->type == DRM_MINOR_ACCEL;
 }
 
+static inline struct task_struct *drm_task_lock(struct drm_file *file_priv)
+{
+	struct task_struct *task;
+	struct pid *pid;
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	return task;
+}
+
+static inline void drm_task_unlock(struct drm_file *file_priv)
+{
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+/**
+ * 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
+ */
+#define drm_file_err(file_priv, fmt, ...)						\
+	do {										\
+		struct task_struct *task;						\
+		struct drm_device *dev = file_priv->minor->dev;				\
+											\
+		task = drm_task_lock(file_priv);					\
+		drm_err(dev, "comm: %s pid: %d client: %s " fmt,			\
+			task ? task->comm : "", task ? task->pid : 0,			\
+			file_priv->client_name ?: "Unset", ##__VA_ARGS__);		\
+		drm_task_unlock(file_priv);						\
+	} while (0)
+
 void drm_file_update_pid(struct drm_file *);
 
 struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);