Re: [RFC PATCH 3/7] vfio/pci: Support mmap() of a DMABUF
From: Jason Gunthorpe
Date: Fri Feb 27 2026 - 07:51:22 EST
On Fri, Feb 27, 2026 at 11:09:31AM +0100, Christian König wrote:
> When a DMA-buf just represents a linear piece of BAR which is
> map-able through the VFIO FD anyway then the right approach is to
> just re-direct the mapping to this VFIO FD.
I actually would like to go the other way and have VFIO always have a
DMABUF under the VMA's it mmaps because that will make it easy to
finish the type1 emulation which requires finding dmabufs for the
VMAs.
> It can be that you want additional checks (e.g. if the DMA-buf is
> revoked) in which case you would need to override the vma->vm_ops,
> but then just do the access checks and call the vfio_pci_mmap_ops to
> get the actually page fault handling done.
It isn't that simple, the vm_ops won't have a way to get back to the
dmabuf from the vma to find the per-fd revoke flag to check it.
> >+ unmap_mapping_range(priv->dmabuf->file->f_mapping,
> >+ 0, priv->size, 1);
>
> When you need to use unmap_mapping_range() then you usually share
> the address space object between the file descriptor exporting the
> DMA-buf and the DMA-buf fd itself.
Yeah, this becomes problematic. Right now there is a single address
space per vfio-device and the invalidation is global.
Possibly for this use case you can keep that and do a global unmap and
rely on fault to restore the mmaps that were not revoked.
Jason