* [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
@ 2025-08-04 19:44 Alex Mastro
2025-08-07 9:34 ` Amit Machhiwal
2025-08-27 18:54 ` Alex Williamson
0 siblings, 2 replies; 9+ messages in thread
From: Alex Mastro @ 2025-08-04 19:44 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 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>
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-04 19:44 [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo Alex Mastro
@ 2025-08-07 9:34 ` Amit Machhiwal
2025-08-07 16:50 ` Alex Mastro
` (2 more replies)
2025-08-27 18:54 ` Alex Williamson
1 sibling, 3 replies; 9+ messages in thread
From: Amit Machhiwal @ 2025-08-07 9:34 UTC (permalink / raw)
To: Alex Mastro
Cc: Alex Williamson, Jonathan Corbet, Jason Gunthorpe, Keith Busch,
linux-kernel, linux-fsdevel, linux-doc, kvm
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>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-07 9:34 ` Amit Machhiwal
@ 2025-08-07 16:50 ` Alex Mastro
2025-08-08 13:49 ` Cédric Le Goater
2025-08-14 8:58 ` Amit Machhiwal
2 siblings, 0 replies; 9+ messages in thread
From: Alex Mastro @ 2025-08-07 16:50 UTC (permalink / raw)
To: Amit Machhiwal
Cc: Alex Williamson, Jonathan Corbet, Jason Gunthorpe, Keith Busch,
linux-kernel, linux-fsdevel, linux-doc, kvm
On Thu, Aug 07, 2025 at 03:04:29PM +0530, Amit Machhiwal wrote:
> Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> Tested-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Hi Amit, thanks for taking the time to test and review!
Alex
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-07 9:34 ` Amit Machhiwal
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-14 8:58 ` Amit Machhiwal
2 siblings, 1 reply; 9+ messages in thread
From: Cédric Le Goater @ 2025-08-08 13:49 UTC (permalink / raw)
To: Alex Mastro, Alex Williamson, Jonathan Corbet, Jason Gunthorpe,
Keith Busch, linux-kernel, linux-fsdevel, linux-doc, kvm
Hello Amit,
On 8/7/25 11:34, Amit Machhiwal wrote:
> 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.
POWER9 running on OPAL FW : I am curious about the software stack.
I suppose this is the latest upstream kernel ?
Are you using an upstream QEMU to test too ?
and which device ?
Thanks,
C.
>
> 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>
>>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
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
0 siblings, 1 reply; 9+ messages in thread
From: Amit Machhiwal @ 2025-08-08 15:45 UTC (permalink / raw)
To: Cédric Le Goater
Cc: Alex Mastro, Alex Williamson, Jonathan Corbet, Jason Gunthorpe,
Keith Busch, linux-kernel, linux-fsdevel, linux-doc, kvm
Hi Cédric,
Please find my comments inline:
On 2025/08/08 03:49 PM, Cédric Le Goater wrote:
> Hello Amit,
>
> On 8/7/25 11:34, Amit Machhiwal wrote:
> > 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.
>
> POWER9 running on OPAL FW : I am curious about the software stack.
>
> I suppose this is the latest upstream kernel ?
Yes, I used the latest upstream kernel and applied this patch on top of commit
cca7a0aae895.
> Are you using an upstream QEMU to test too ?
No, I had used the Fedora 42 distro qemu. The version details are as below:
[root@localhost ~]# qemu-system-ppc64 --version
QEMU emulator version 9.2.4 (qemu-9.2.4-1.fc42)
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
I gave the upstream qemu (HEAD pointing to cd21ee5b27) a try and I see the same
behavior with that too.
[root@localhost ~]# ./qemu-system-ppc64 --version
QEMU emulator version 10.0.92 (v10.1.0-rc2-4-gcd21ee5b27-dirty)
Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers
[root@localhost ~]# cat /proc/52807/fdinfo/191
pos: 0
flags: 02000002
mnt_id: 17
ino: 1125
vfio-device-syspath: /sys/devices/pci0031:00/0031:00:00.0/0031:01:00.0
>
> and which device ?
I'm using a Broadcom NetXtreme network card (4-port) and passing through its
fn0.
[root@guest ~]# lspci
[...]
0001:00:01.0 Ethernet controller: Broadcom Inc. and subsidiaries NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
Please let me know if I may help you with any additional information.
Thanks,
Amit
>
> Thanks,
>
> C.
>
>
>
>
> >
> > 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>
> > >
> >
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-08 15:45 ` Amit Machhiwal
@ 2025-08-08 16:44 ` Cédric Le Goater
2025-08-08 17:21 ` Amit Machhiwal
0 siblings, 1 reply; 9+ messages in thread
From: Cédric Le Goater @ 2025-08-08 16:44 UTC (permalink / raw)
To: Alex Mastro, Alex Williamson, Jonathan Corbet, Jason Gunthorpe,
Keith Busch, linux-kernel, linux-fsdevel, linux-doc, kvm
On 8/8/25 17:45, Amit Machhiwal wrote:
> Hi Cédric,
>
> Please find my comments inline:
>
> On 2025/08/08 03:49 PM, Cédric Le Goater wrote:
>> Hello Amit,
>>
>> On 8/7/25 11:34, Amit Machhiwal wrote:
>>> 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.
>>
>> POWER9 running on OPAL FW : I am curious about the software stack.
>>
>> I suppose this is the latest upstream kernel ?
>
> Yes, I used the latest upstream kernel and applied this patch on top of commit
> cca7a0aae895.
>
>> Are you using an upstream QEMU to test too ?
>
> No, I had used the Fedora 42 distro qemu. The version details are as below:
>
> [root@localhost ~]# qemu-system-ppc64 --version
> QEMU emulator version 9.2.4 (qemu-9.2.4-1.fc42)
> Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
>
> I gave the upstream qemu (HEAD pointing to cd21ee5b27) a try and I see the same
> behavior with that too.
>
> [root@localhost ~]# ./qemu-system-ppc64 --version
> QEMU emulator version 10.0.92 (v10.1.0-rc2-4-gcd21ee5b27-dirty)
> Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers
>
> [root@localhost ~]# cat /proc/52807/fdinfo/191
> pos: 0
> flags: 02000002
> mnt_id: 17
> ino: 1125
> vfio-device-syspath: /sys/devices/pci0031:00/0031:00:00.0/0031:01:00.0
>
>>
>> and which device ?
>
> I'm using a Broadcom NetXtreme network card (4-port) and passing through its
> fn0.
>
> [root@guest ~]# lspci
> [...]
> 0001:00:01.0 Ethernet controller: Broadcom Inc. and subsidiaries NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
>
> Please let me know if I may help you with any additional information.
It is good to know that device pass-through still works with upstream on
OpenPower servers.
Have you tried VFs ?
Thanks Amit,
C.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-08 16:44 ` Cédric Le Goater
@ 2025-08-08 17:21 ` Amit Machhiwal
0 siblings, 0 replies; 9+ messages in thread
From: Amit Machhiwal @ 2025-08-08 17:21 UTC (permalink / raw)
To: Cédric Le Goater
Cc: Alex Mastro, Alex Williamson, Jonathan Corbet, Jason Gunthorpe,
Keith Busch, linux-kernel, linux-fsdevel, linux-doc, kvm
On 2025/08/08 06:44 PM, Cédric Le Goater wrote:
> On 8/8/25 17:45, Amit Machhiwal wrote:
> > Hi Cédric,
> >
> > Please find my comments inline:
> >
> > On 2025/08/08 03:49 PM, Cédric Le Goater wrote:
> > > Hello Amit,
> > >
> > > On 8/7/25 11:34, Amit Machhiwal wrote:
> > > > 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.
> > >
> > > POWER9 running on OPAL FW : I am curious about the software stack.
> > >
> > > I suppose this is the latest upstream kernel ?
> >
> > Yes, I used the latest upstream kernel and applied this patch on top of commit
> > cca7a0aae895.
> >
> > > Are you using an upstream QEMU to test too ?
> >
> > No, I had used the Fedora 42 distro qemu. The version details are as below:
> >
> > [root@localhost ~]# qemu-system-ppc64 --version
> > QEMU emulator version 9.2.4 (qemu-9.2.4-1.fc42)
> > Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
> >
> > I gave the upstream qemu (HEAD pointing to cd21ee5b27) a try and I see the same
> > behavior with that too.
> >
> > [root@localhost ~]# ./qemu-system-ppc64 --version
> > QEMU emulator version 10.0.92 (v10.1.0-rc2-4-gcd21ee5b27-dirty)
> > Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers
> >
> > [root@localhost ~]# cat /proc/52807/fdinfo/191
> > pos: 0
> > flags: 02000002
> > mnt_id: 17
> > ino: 1125
> > vfio-device-syspath: /sys/devices/pci0031:00/0031:00:00.0/0031:01:00.0
> >
> > >
> > > and which device ?
> >
> > I'm using a Broadcom NetXtreme network card (4-port) and passing through its
> > fn0.
> >
> > [root@guest ~]# lspci
> > [...]
> > 0001:00:01.0 Ethernet controller: Broadcom Inc. and subsidiaries NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
> >
> > Please let me know if I may help you with any additional information.
>
> It is good to know that device pass-through still works with upstream on
> OpenPower servers.
>
> Have you tried VFs ?
I didn't get a chance to try VFs yet, Cédric.
>
> Thanks Amit,
No problem. :)
Thanks,
Amit
>
> C.
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-07 9:34 ` Amit Machhiwal
2025-08-07 16:50 ` Alex Mastro
2025-08-08 13:49 ` Cédric Le Goater
@ 2025-08-14 8:58 ` Amit Machhiwal
2 siblings, 0 replies; 9+ messages in thread
From: Amit Machhiwal @ 2025-08-14 8:58 UTC (permalink / raw)
To: Alex Mastro, Alex Williamson, Jonathan Corbet, Jason Gunthorpe,
Keith Busch, linux-kernel, linux-fsdevel, linux-doc, kvm
On 2025/08/07 03:04 PM, Amit Machhiwal wrote:
> 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,
Additionally, I got a chance to test this patch on a pSeries POWER10 logical
partition (L1) running a KVM guest (L2) with a PCI device passthrough and I see
the expected results:
[root@guest ~]# lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 20
On-line CPU(s) list: 0-19
Model name: POWER10 (architected), altivec supported
Model: 2.0 (pvr 0080 0200)
[...]
[root@guest ~]# lspci
[...]
0001:00:01.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller PM9A1/PM9A3/980PRO
root@host:~ # cat /proc/2116/fdinfo/68
pos: 0
flags: 02000002
mnt_id: 17
ino: 160
vfio-device-syspath: /sys/devices/pci0182:70/0182:70:00.0
The L1 was booted with latest upstream kernel (HEAD: 53e760d89498) with the
patch applied and the L2 was booted on distro QEMU (version 10.0.2) and as well
as on latest upstream QEMU (HEAD: 5836af078321, version 10.0.93).
Thanks,
Amit
>
> 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>
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo
2025-08-04 19:44 [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo Alex Mastro
2025-08-07 9:34 ` Amit Machhiwal
@ 2025-08-27 18:54 ` Alex Williamson
1 sibling, 0 replies; 9+ messages in thread
From: Alex Williamson @ 2025-08-27 18:54 UTC (permalink / raw)
To: Alex Mastro
Cc: Jonathan Corbet, Jason Gunthorpe, Keith Busch, linux-kernel,
linux-fsdevel, linux-doc, kvm
On Mon, 4 Aug 2025 12:44:31 -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 v4:
> - Remove changes to vfio.h
> - Link to v3: https://lore.kernel.org/r/20250801-show-fdinfo-v3-1-165dfcab89b9@fb.com
Applied to vfio next branch for v6.18. Thanks,
Alex
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-08-27 18:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04 19:44 [PATCH v4] vfio/pci: print vfio-device syspath to fdinfo Alex Mastro
2025-08-07 9:34 ` Amit Machhiwal
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
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).