Skip to contentSkip to conversation

vfio: show the name of IOMMU driver in /proc/$pid/fdinfo

PATCH In review Masatake YAMATO 1 participant 2 messages Aug 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio: show the name of IOMMU driver in /proc/$pid/fdinfo

The ops of VFIO overlap:

  (include/uapi/linux/vfio.h)
  #define VFIO_DEVICE_GET_PCI_HOT_RESET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
  ...
  #define VFIO_MIG_GET_PRECOPY_INFO _IO(VFIO_TYPE, VFIO_BASE + 21)
  ...
  #define VFIO_IOMMU_DIRTY_PAGES             _IO(VFIO_TYPE, VFIO_BASE + 17)
  #define VFIO_IOMMU_SPAPR_TCE_GET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
  #define VFIO_EEH_PE_OP			_IO(VFIO_TYPE, VFIO_BASE + 21)
  #define VFIO_IOMMU_SPAPR_REGISTER_MEMORY	_IO(VFIO_TYPE, VFIO_BASE + 17)
  ...
  #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)

These overlapping makes strace decoding the ops and their arguments hard. See also https://lists.strace.io/pipermail/strace-devel/2021-May/010561.html

This change adds "vfio-iommu-driver" field to /proc/$pid/fdinfo/$fd where $fd opens /dev/vfio/vfio. The value of the field helps strace decode the ops arguments.

The prototype version of strace based on this change works fine:
- https://lists.strace.io/pipermail/strace-devel/2021-August/010660.html
- https://lists.strace.io/pipermail/strace-devel/2021-August/010660.html

---
 drivers/vfio/container.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/vfio/container.c +11 -0
index d53d08f16973..03677fda49de 100644
@@ -11,6 +11,7 @@
 #include <linux/iommu.h>
 #include <linux/miscdevice.h>
 #include <linux/vfio.h>
+#include <linux/seq_file.h>
 #include <uapi/linux/vfio.h>
 
 #include "vfio.h"
@@ -384,12 +385,22 @@ static int vfio_fops_release(struct inode *inode, struct file *filep)
 	return 0;
 }
 
+static void vfio_fops_show_fdinfo(struct seq_file *m, struct file *filep)
+{
+	struct vfio_container *container = filep->private_data;
+	struct vfio_iommu_driver *driver = container->iommu_driver;
+
+	if (driver && driver->ops->name)
+		seq_printf(m, "vfio-iommu-driver:\t%s\n", driver->ops->name);
+}
+
 static const struct file_operations vfio_fops = {
 	.owner		= THIS_MODULE,
 	.open		= vfio_fops_open,
 	.release	= vfio_fops_release,
 	.unlocked_ioctl	= vfio_fops_unl_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.show_fdinfo    = vfio_fops_show_fdinfo,
 };
 
 struct vfio_container *vfio_container_from_file(struct file *file)
Signature · 1 line
2.51.0
#1 lore raw

Please, ignore my last post.
I should send the original message to [email protected]. Sorry for making noise.

Masatake YAMATO

Quoted 69 lines

The ops of VFIO overlap:

  (include/uapi/linux/vfio.h)
  #define VFIO_DEVICE_GET_PCI_HOT_RESET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
  ...
  #define VFIO_MIG_GET_PRECOPY_INFO _IO(VFIO_TYPE, VFIO_BASE + 21)
  ...
  #define VFIO_IOMMU_DIRTY_PAGES             _IO(VFIO_TYPE, VFIO_BASE + 17)
  #define VFIO_IOMMU_SPAPR_TCE_GET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
  #define VFIO_EEH_PE_OP			_IO(VFIO_TYPE, VFIO_BASE + 21)
  #define VFIO_IOMMU_SPAPR_REGISTER_MEMORY	_IO(VFIO_TYPE, VFIO_BASE + 17)
  ...
  #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)

These overlapping makes strace decoding the ops and their arguments hard. See also https://lists.strace.io/pipermail/strace-devel/2021-May/010561.html

This change adds "vfio-iommu-driver" field to /proc/$pid/fdinfo/$fd where $fd opens /dev/vfio/vfio. The value of the field helps strace decode the ops arguments.

The prototype version of strace based on this change works fine:
- https://lists.strace.io/pipermail/strace-devel/2021-August/010660.html
- https://lists.strace.io/pipermail/strace-devel/2021-August/010660.html

---
 drivers/vfio/container.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/vfio/container.c +11 -0
index d53d08f16973..03677fda49de 100644
@@ -11,6 +11,7 @@
 #include <linux/iommu.h>
 #include <linux/miscdevice.h>
 #include <linux/vfio.h>
+#include <linux/seq_file.h>
 #include <uapi/linux/vfio.h>
 
 #include "vfio.h"
@@ -384,12 +385,22 @@ static int vfio_fops_release(struct inode *inode, struct file *filep)
 	return 0;
 }
 
+static void vfio_fops_show_fdinfo(struct seq_file *m, struct file *filep)
+{
+	struct vfio_container *container = filep->private_data;
+	struct vfio_iommu_driver *driver = container->iommu_driver;
+
+	if (driver && driver->ops->name)
+		seq_printf(m, "vfio-iommu-driver:\t%s\n", driver->ops->name);
+}
+
 static const struct file_operations vfio_fops = {
 	.owner		= THIS_MODULE,
 	.open		= vfio_fops_open,
 	.release	= vfio_fops_release,
 	.unlocked_ioctl	= vfio_fops_unl_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.show_fdinfo    = vfio_fops_show_fdinfo,
 };
 
 struct vfio_container *vfio_container_from_file(struct file *file)
Signature · 1 line
2.51.0