mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Amit Machhiwal <amachhiw@linux.ibm.com>
To: Alex Mastro <amastro@fb.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Jonathan Corbet <corbet@lwn.net>, Jason Gunthorpe <jgg@ziepe.ca>,
	Keith Busch <kbusch@kernel.org>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-doc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
Date: Thu, 7 Aug 2025 15:04:29 +0530	[thread overview]
Message-ID: <20250807144938.e0abc7bb-a4-amachhiw@linux.ibm.com> (raw)
In-Reply-To: <20250804-show-fdinfo-v4-1-96b14c5691b3@fb.com>

Hello,

On 2025/08/04 12:44 PM, Alex Mastro wrote:
> Print the PCI device syspath to a vfio device's fdinfo. This enables tools
> to query which device is associated with a given vfio device fd.
> 
> This results in output like below:
> 
> $ cat /proc/"$SOME_PID"/fdinfo/"$VFIO_FD" | grep vfio
> vfio-device-syspath: /sys/devices/pci0000:e0/0000:e0:01.1/0000:e1:00.0/0000:e2:05.0/0000:e8:00.0
> 
> Signed-off-by: Alex Mastro <amastro@fb.com>

I tested this patch on a POWER9 bare metal system with a VFIO PCI device and
could see the VFIO device syspath in fdinfo.

 Without this patch:
 -------------------

    [root@localhost ~]# cat /proc/7059/fdinfo/188
    pos:    0
    flags:  02000002
    mnt_id: 17
    ino:    1113

 With this patch:
 ----------------
    [root@localhost ~]# cat /proc/7722/fdinfo/188
    pos:    0
    flags:  02000002
    mnt_id: 17
    ino:    2145
    vfio-device-syspath: /sys/devices/pci0031:00/0031:00:00.0/0031:01:00.0

..., and the code changes LGTM. Hence,

Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Tested-by: Amit Machhiwal <amachhiw@linux.ibm.com>

Thanks,
Amit

> ---
> Changes in v4:
> - Remove changes to vfio.h
> - Link to v3: https://lore.kernel.org/r/20250801-show-fdinfo-v3-1-165dfcab89b9@fb.com
> Changes in v3:
> - Remove changes to vfio_pci.c
> - Add section to Documentation/filesystems/proc.rst
> - Link to v2: https://lore.kernel.org/all/20250724-show-fdinfo-v2-1-2952115edc10@fb.com
> Changes in v2:
> - Instead of PCI bdf, print the fully-qualified syspath (prefixed by
>   /sys) to fdinfo.
> - Rename the field to "vfio-device-syspath". The term "syspath" was
>   chosen for consistency e.g. libudev's usage of the term.
> - Link to v1: https://lore.kernel.org/r/20250623-vfio-fdinfo-v1-1-c9cec65a2922@fb.com
> ---
>  Documentation/filesystems/proc.rst | 14 ++++++++++++++
>  drivers/vfio/vfio_main.c           | 20 ++++++++++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
> index 2a17865dfe39..fc5ed3117834 100644
> --- a/Documentation/filesystems/proc.rst
> +++ b/Documentation/filesystems/proc.rst
> @@ -2162,6 +2162,20 @@ DMA Buffer files
>  where 'size' is the size of the DMA buffer in bytes. 'count' is the file count of
>  the DMA buffer file. 'exp_name' is the name of the DMA buffer exporter.
>  
> +VFIO Device files
> +~~~~~~~~~~~~~~~~
> +
> +::
> +
> +	pos:    0
> +	flags:  02000002
> +	mnt_id: 17
> +	ino:    5122
> +	vfio-device-syspath: /sys/devices/pci0000:e0/0000:e0:01.1/0000:e1:00.0/0000:e2:05.0/0000:e8:00.0
> +
> +where 'vfio-device-syspath' is the sysfs path corresponding to the VFIO device
> +file.
> +
>  3.9	/proc/<pid>/map_files - Information about memory mapped files
>  ---------------------------------------------------------------------
>  This directory contains symbolic links which represent memory mapped files
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 1fd261efc582..37a39cee10ed 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -28,6 +28,7 @@
>  #include <linux/pseudo_fs.h>
>  #include <linux/rwsem.h>
>  #include <linux/sched.h>
> +#include <linux/seq_file.h>
>  #include <linux/slab.h>
>  #include <linux/stat.h>
>  #include <linux/string.h>
> @@ -1354,6 +1355,22 @@ static int vfio_device_fops_mmap(struct file *filep, struct vm_area_struct *vma)
>  	return device->ops->mmap(device, vma);
>  }
>  
> +#ifdef CONFIG_PROC_FS
> +static void vfio_device_show_fdinfo(struct seq_file *m, struct file *filep)
> +{
> +	char *path;
> +	struct vfio_device_file *df = filep->private_data;
> +	struct vfio_device *device = df->device;
> +
> +	path = kobject_get_path(&device->dev->kobj, GFP_KERNEL);
> +	if (!path)
> +		return;
> +
> +	seq_printf(m, "vfio-device-syspath: /sys%s\n", path);
> +	kfree(path);
> +}
> +#endif
> +
>  const struct file_operations vfio_device_fops = {
>  	.owner		= THIS_MODULE,
>  	.open		= vfio_device_fops_cdev_open,
> @@ -1363,6 +1380,9 @@ const struct file_operations vfio_device_fops = {
>  	.unlocked_ioctl	= vfio_device_fops_unl_ioctl,
>  	.compat_ioctl	= compat_ptr_ioctl,
>  	.mmap		= vfio_device_fops_mmap,
> +#ifdef CONFIG_PROC_FS
> +	.show_fdinfo	= vfio_device_show_fdinfo,
> +#endif
>  };
>  
>  static struct vfio_device *vfio_device_from_file(struct file *file)
> 
> ---
> base-commit: 4518e5a60c7fbf0cdff393c2681db39d77b4f87e
> change-id: 20250801-show-fdinfo-ef109ca738cf
> 
> Best regards,
> -- 
> Alex Mastro <amastro@fb.com>
> 

  reply	other threads:[~2025-08-07  9:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 19:44 Alex Mastro
2025-08-07  9:34 ` Amit Machhiwal [this message]
2025-08-07 16:50   ` Alex Mastro
2025-08-08 13:49   ` Cédric Le Goater
2025-08-08 15:45     ` Amit Machhiwal
2025-08-08 16:44       ` Cédric Le Goater
2025-08-08 17:21         ` Amit Machhiwal
2025-08-14  8:58   ` Amit Machhiwal
2025-08-27 18:54 ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250807144938.e0abc7bb-a4-amachhiw@linux.ibm.com \
    --to=amachhiw@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=amastro@fb.com \
    --cc=corbet@lwn.net \
    --cc=jgg@ziepe.ca \
    --cc=kbusch@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®