[RFC PATCH 3/5] vfio/pci: Block mmap & dmabuf export for ZONE_DEVICE-registered BARs
From: Pranjal Shrivastava
Date: Wed Jun 10 2026 - 11:36:36 EST
Update vfio_pci_core_mmap() & vfio_pci_core_feature_dma_buf() to
enforce mutual exclusivity with ZONE_DEVICE P2P registration.
If a BAR has been registered for native P2P (via
VFIO_DEVICE_FEATURE_P2P_REGISTER), subsequent requests to mmap the BAR
or export it as a DMABUF are rejected with -EBUSY.
Signed-off-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
---
drivers/vfio/pci/vfio_pci_core.c | 7 +++++++
drivers/vfio/pci/vfio_pci_dmabuf.c | 6 ++++++
2 files changed, 13 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 1e922e3aaeb3..9cf494b765e7 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1828,6 +1828,13 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
if (!vdev->bar_mmap_supported[index])
return -EINVAL;
+ if (vdev->p2p_registered_bars & (1 << index)) {
+ pci_warn(vdev->pdev,
+ "BAR %d registered for P2P. Use sysfs to allocate\n",
+ index);
+ return -EBUSY;
+ }
+
phys_len = PAGE_ALIGN(pci_resource_len(pdev, index));
req_len = vma->vm_end - vma->vm_start;
pgoff = vma->vm_pgoff &
diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
index c16f460c01d6..6635a8681291 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -251,6 +251,12 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
IS_ERR(vfio_pci_core_get_iomap(vdev, get_dma_buf.region_index)))
return -ENODEV;
+ if (vdev->p2p_registered_bars & (1 << get_dma_buf.region_index)) {
+ pci_warn(vdev->pdev, "BAR %d registered for native P2P. Use sysfs for allocation.\n",
+ get_dma_buf.region_index);
+ return -EBUSY;
+ }
+
dma_ranges = memdup_array_user(&arg->dma_ranges, get_dma_buf.nr_ranges,
sizeof(*dma_ranges));
if (IS_ERR(dma_ranges))
--
2.54.0.1099.g489fc7bff1-goog