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

Tvrtko Ursulin tvrtko.ursulin at igalia.com
Tue Apr 15 11:40:58 UTC 2025


On 15/04/2025 12:25, Sunil Khatri wrote:
> 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.
> 
> Signed-off-by: Sunil Khatri <sunil.khatri at amd.com>
> ---
>   drivers/gpu/drm/drm_file.c | 34 ++++++++++++++++++++++++++++++++++
>   include/drm/drm_file.h     |  1 +
>   2 files changed, 35 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> index c299cd94d3f7..728a60975f5e 100644
> --- a/drivers/gpu/drm/drm_file.c
> +++ b/drivers/gpu/drm/drm_file.c
> @@ -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;
> +	}

I think this should be:

if (drm_WARN_ON_ONCE(dev, !proc_info))
	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);

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

> +
> +	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)
> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
> index 94d365b22505..a972be73a615 100644
> --- a/include/drm/drm_file.h
> +++ b/include/drm/drm_file.h
> @@ -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);
>   



More information about the dri-devel mailing list