On Thu, 16 Apr 2026 06:17:47 -0700 Matt Evans mattev@meta.com wrote:
Convert the VFIO device fd fops->mmap to create a DMABUF representing the BAR mapping, and make the VMA fault handler look up PFNs from the corresponding DMABUF. This supports future code mmap()ing BAR DMABUFs, and iommufd work to support Type1 P2P.
First, vfio_pci_core_mmap() uses the new vfio_pci_core_mmap_prep_dmabuf() helper to export a DMABUF representing a single BAR range. Then, the vfio_pci_mmap_huge_fault() callback is updated to understand revoked buffers, and uses the new vfio_pci_dma_buf_find_pfn() helper to determine the PFN for a given fault address.
Now that the VFIO DMABUFs can be mmap()ed, vfio_pci_dma_buf_move() and vfio_pci_dma_buf_cleanup() need to zap PTEs on revocation and cleanup paths.
CONFIG_VFIO_PCI_CORE now unconditionally depends on CONFIG_DMA_SHARED_BUFFER. CONFIG_VFIO_PCI_DMABUF remains, to conditionally include support for VFIO_DEVICE_FEATURE_DMA_BUF, and depends on CONFIG_PCI_P2PDMA.
Signed-off-by: Matt Evans mattev@meta.com
drivers/vfio/pci/Kconfig | 3 +- drivers/vfio/pci/Makefile | 3 +- drivers/vfio/pci/vfio_pci_core.c | 86 ++++++++++++++++++------------ drivers/vfio/pci/vfio_pci_dmabuf.c | 14 +++++ drivers/vfio/pci/vfio_pci_priv.h | 11 +--- 5 files changed, 71 insertions(+), 46 deletions(-)
diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig index 296bf01e185e..2074f2a941e1 100644 --- a/drivers/vfio/pci/Kconfig +++ b/drivers/vfio/pci/Kconfig @@ -6,6 +6,7 @@ config VFIO_PCI_CORE tristate select VFIO_VIRQFD select IRQ_BYPASS_MANAGER
- select DMA_SHARED_BUFFER
config VFIO_PCI_INTX def_bool y if !S390 @@ -56,7 +57,7 @@ config VFIO_PCI_ZDEV_KVM To enable s390x KVM vfio-pci extensions, say Y. config VFIO_PCI_DMABUF
- def_bool y if VFIO_PCI_CORE && PCI_P2PDMA && DMA_SHARED_BUFFER
- def_bool y if PCI_P2PDMA
But here we introduce the call chain:
vfio_pci_core_mmap() -> vfio_pci_core_mmap_prep_dmabuf() -> pcim_p2pdma_provider()
Where pcim_p2pdma_provider() requires PCI_P2PDMA. So honestly, VFIO_PCI_CORE depends on PCI_P2PDMA. I think that's a pretty significant regression.
Exporting dma-bufs from vfio-pci is a feature, but mmap of MMIO BARs is a legacy requirement. That legacy requirement now depends on PCI_P2PDMA, which depends on 64BIT and ZONE_DEVICE.
It's possible that our 32-bit support is already broken and we can easily codify it in Kconfig. We should check. Otherwise it seems pretty harsh to drop it without notice, or make it fundamentally broken by exposing mmap support flags for regions where mmap is no longer available.
ZONE_DEVICE is harder, it seems like it's possible there could be minimal 64-bit custom kernel configs where vfio-pci currently works without ZONE_DEVICE.
We might be headed to this impasse already as dma-buf is required to have feature-complete compatibility with iommufd, but I had hoped we'd be able to manage that with full legacy functionality through the transition. Thanks,
Alex