Re: [PATCH 5/9] vfio/pci: Provide a user-facing name for BAR mappings

From: Matt Evans

Date: Thu May 07 2026 - 13:18:18 EST


Sent too soon, :|

On 07/05/2026 17:56, Matt Evans wrote:
Hi Alex,

On 01/05/2026 23:44, Alex Williamson wrote:

On Thu, 16 Apr 2026 06:17:48 -0700
Matt Evans <mattev@xxxxxxxx> wrote:

Since converting BAR mmap()s to using DMABUFs, we lose the original
device path in /proc/<pid>/maps, lsof, etc.  Generate a debug-oriented
synthetic 'filename' based on the cdev, plus BDF, plus resource index.

This applies only to BAR mappings via the VFIO device fd, as
explicitly-exported DMABUFs are named by userspace via the
DMA_BUF_SET_NAME ioctl.

Signed-off-by: Matt Evans <mattev@xxxxxxxx>
---
  drivers/vfio/pci/vfio_pci_dmabuf.c | 27 +++++++++++++++++++++++++--
  1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/ vfio_pci_dmabuf.c
index a12432825e5e..04c7733fe712 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -4,6 +4,7 @@
  #include <linux/dma-buf-mapping.h>
  #include <linux/pci-p2pdma.h>
  #include <linux/dma-resv.h>
+#include <uapi/linux/dma-buf.h>
  #include "vfio_pci_priv.h"
@@ -467,6 +468,7 @@ int vfio_pci_core_mmap_prep_dmabuf(struct vfio_pci_core_device *vdev,
  {
      struct vfio_pci_dma_buf *priv;
      const unsigned int nr_ranges = 1;
+    char *bufname;
      int ret;
      priv = kzalloc_obj(*priv);
@@ -479,6 +481,20 @@ int vfio_pci_core_mmap_prep_dmabuf(struct vfio_pci_core_device *vdev,
          goto err_free_priv;
      }
+    bufname = kzalloc(DMA_BUF_NAME_LEN, GFP_KERNEL);
+    if (!bufname) {
+        ret = -ENOMEM;
+        goto err_free_phys;
+    }
+
+    /*
+     * Maximum size of the friendly debug name is
+     * vfio1234567890:ffff:ff:3f.7-9 = 30, which fits within
+     * DMA_BUF_NAME_LEN.
+     */
+    snprintf(bufname, DMA_BUF_NAME_LEN, "%s:%s/%x",
+         dev_name(&vdev->vdev.device), pci_name(vdev->pdev), res_index);

Comment suggests 9 is the max res_index that can be printed, but mmap
only directly supports standard BARs 0-5.  Comment also uses a '-'
while the code uses a '/'.  Thanks,

Right you are.  Fixed, but, since...
https://lore.kernel.org/kvm/52162da4-e1cc-4f90-a95a-218d6089cd71@xxxxxxxx/

...I'm keeping the resource index encoded in the vm_pgoffs and as that's
in /proc/<pid>/maps it doesn't need to be in the name. I.e., an example
mapping of BAR 2 looks like:

ffffa9330000-ffffad300000 rw-s 20000030000 00:0b 12 / dmabuf:vfio0:0000:00:03.0

BUT, the name's visible via paths other than just /proc/<pid>/maps, e.g.
/sys/kernel/debug/dma_buf/bufinfo or /proc/<pid>/map_files which don't have the vm_offs, and so back to plan A. Just made the comment consistent.

Matt