* [PATCH v3] vfio/pci: print vfio-device syspath to fdinfo
@ 2025-08-01 20:50 Alex Mastro
2025-08-04 16:25 ` Alex Williamson
0 siblings, 1 reply; 3+ messages in thread
From: Alex Mastro @ 2025-08-01 20:50 UTC (permalink / raw)
To: Alex Williamson, Jonathan Corbet
Cc: Jason Gunthorpe, Keith Busch, linux-kernel, linux-fsdevel,
linux-doc, kvm, Alex Mastro
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>
---
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 ++++++++++++++++++++
include/linux/vfio.h | 2 ++
3 files changed, 36 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)
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 707b00772ce1..54076045a44f 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -16,6 +16,7 @@
#include <linux/cdev.h>
#include <uapi/linux/vfio.h>
#include <linux/iova_bitmap.h>
+#include <linux/seq_file.h>
struct kvm;
struct iommufd_ctx;
@@ -135,6 +136,7 @@ struct vfio_device_ops {
void (*dma_unmap)(struct vfio_device *vdev, u64 iova, u64 length);
int (*device_feature)(struct vfio_device *device, u32 flags,
void __user *arg, size_t argsz);
+ void (*show_fdinfo)(struct vfio_device *device, struct seq_file *m);
};
#if IS_ENABLED(CONFIG_IOMMUFD)
---
base-commit: 4518e5a60c7fbf0cdff393c2681db39d77b4f87e
change-id: 20250801-show-fdinfo-ef109ca738cf
Best regards,
--
Alex Mastro <amastro@fb.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] vfio/pci: print vfio-device syspath to fdinfo
2025-08-01 20:50 [PATCH v3] vfio/pci: print vfio-device syspath to fdinfo Alex Mastro
@ 2025-08-04 16:25 ` Alex Williamson
2025-08-04 19:09 ` Alex Mastro
0 siblings, 1 reply; 3+ messages in thread
From: Alex Williamson @ 2025-08-04 16:25 UTC (permalink / raw)
To: Alex Mastro
Cc: Jonathan Corbet, Jason Gunthorpe, Keith Busch, linux-kernel,
linux-fsdevel, linux-doc, kvm
On Fri, 1 Aug 2025 13:50:56 -0700
Alex Mastro <amastro@fb.com> 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>
> ---
> 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 ++++++++++++++++++++
> include/linux/vfio.h | 2 ++
> 3 files changed, 36 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)
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index 707b00772ce1..54076045a44f 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -16,6 +16,7 @@
> #include <linux/cdev.h>
> #include <uapi/linux/vfio.h>
> #include <linux/iova_bitmap.h>
> +#include <linux/seq_file.h>
>
> struct kvm;
> struct iommufd_ctx;
> @@ -135,6 +136,7 @@ struct vfio_device_ops {
> void (*dma_unmap)(struct vfio_device *vdev, u64 iova, u64 length);
> int (*device_feature)(struct vfio_device *device, u32 flags,
> void __user *arg, size_t argsz);
> + void (*show_fdinfo)(struct vfio_device *device, struct seq_file *m);
> };
Changes in this file look spurious, vfio_device_ops vs
vfio_device_fops? Nothing implements or consumes the vfio_device_ops
callback here. Thanks,
Alex
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] vfio/pci: print vfio-device syspath to fdinfo
2025-08-04 16:25 ` Alex Williamson
@ 2025-08-04 19:09 ` Alex Mastro
0 siblings, 0 replies; 3+ messages in thread
From: Alex Mastro @ 2025-08-04 19:09 UTC (permalink / raw)
To: Alex Williamson
Cc: Jonathan Corbet, Jason Gunthorpe, Keith Busch, linux-kernel,
linux-fsdevel, linux-doc, kvm
On Mon, Aug 04, 2025 at 10:25:59AM -0600, Alex Williamson wrote:
> Changes in this file look spurious, vfio_device_ops vs
> vfio_device_fops? Nothing implements or consumes the vfio_device_ops
> callback here.
Agh. Yes. I missed removing this. Fixing in v4.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-04 19:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01 20:50 [PATCH v3] vfio/pci: print vfio-device syspath to fdinfo Alex Mastro
2025-08-04 16:25 ` Alex Williamson
2025-08-04 19:09 ` Alex Mastro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).