Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vfio/pci: print vfio-device syspath to fdinfo

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>
Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Tested-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Link: https://lore.kernel.org/r/20250804-show-fdinfo-v4-1-96b14c5691b3@fb.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Alex Mastro and committed by
Alex Williamson
1e736f14 1b237f19

+34
+14
Documentation/filesystems/proc.rst
··· 2166 2166 where 'size' is the size of the DMA buffer in bytes. 'count' is the file count of 2167 2167 the DMA buffer file. 'exp_name' is the name of the DMA buffer exporter. 2168 2168 2169 + VFIO Device files 2170 + ~~~~~~~~~~~~~~~~ 2171 + 2172 + :: 2173 + 2174 + pos: 0 2175 + flags: 02000002 2176 + mnt_id: 17 2177 + ino: 5122 2178 + vfio-device-syspath: /sys/devices/pci0000:e0/0000:e0:01.1/0000:e1:00.0/0000:e2:05.0/0000:e8:00.0 2179 + 2180 + where 'vfio-device-syspath' is the sysfs path corresponding to the VFIO device 2181 + file. 2182 + 2169 2183 3.9 /proc/<pid>/map_files - Information about memory mapped files 2170 2184 --------------------------------------------------------------------- 2171 2185 This directory contains symbolic links which represent memory mapped files
+20
drivers/vfio/vfio_main.c
··· 28 28 #include <linux/pseudo_fs.h> 29 29 #include <linux/rwsem.h> 30 30 #include <linux/sched.h> 31 + #include <linux/seq_file.h> 31 32 #include <linux/slab.h> 32 33 #include <linux/stat.h> 33 34 #include <linux/string.h> ··· 1356 1355 return device->ops->mmap(device, vma); 1357 1356 } 1358 1357 1358 + #ifdef CONFIG_PROC_FS 1359 + static void vfio_device_show_fdinfo(struct seq_file *m, struct file *filep) 1360 + { 1361 + char *path; 1362 + struct vfio_device_file *df = filep->private_data; 1363 + struct vfio_device *device = df->device; 1364 + 1365 + path = kobject_get_path(&device->dev->kobj, GFP_KERNEL); 1366 + if (!path) 1367 + return; 1368 + 1369 + seq_printf(m, "vfio-device-syspath: /sys%s\n", path); 1370 + kfree(path); 1371 + } 1372 + #endif 1373 + 1359 1374 const struct file_operations vfio_device_fops = { 1360 1375 .owner = THIS_MODULE, 1361 1376 .open = vfio_device_fops_cdev_open, ··· 1381 1364 .unlocked_ioctl = vfio_device_fops_unl_ioctl, 1382 1365 .compat_ioctl = compat_ptr_ioctl, 1383 1366 .mmap = vfio_device_fops_mmap, 1367 + #ifdef CONFIG_PROC_FS 1368 + .show_fdinfo = vfio_device_show_fdinfo, 1369 + #endif 1384 1370 }; 1385 1371 1386 1372 static struct vfio_device *vfio_device_from_file(struct file *file)