Re: [PATCH 9/9] vfio/pci: Add mmap() attributes to DMABUF feature

Alex Williamson
2026-04-27T14:36:49Z

On Sun, 26 Apr 2026 13:52:15 +0300
Leon Romanovsky <leon@kernel.org> wrote:

> On Fri, Apr 24, 2026 at 03:31:53PM -0300, Jason Gunthorpe wrote:
> > On Thu, Apr 16, 2026 at 06:17:52AM -0700, Matt Evans wrote:
> > > A new field is reserved in vfio_device_feature_dma_buf.flags to
> > > request CPU-facing memory type attributes for mmap()s of the buffer.
> > > Add a flag VFIO_DEVICE_FEATURE_DMA_BUF_ATTR_WC, which results in WC
> > > PTEs for the DMABUF's BAR region.
> > >
> > > Signed-off-by: Matt Evans <mattev@meta.com>
> > > ---
> > > drivers/vfio/pci/vfio_pci_dmabuf.c | 15 +++++++++++++--
> > > drivers/vfio/pci/vfio_pci_priv.h | 1 +
> > > include/uapi/linux/vfio.h | 12 +++++++++---
> > > 3 files changed, 23 insertions(+), 5 deletions(-)
> >
> > Nice and simple
> >
> > Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> >
> > > @@ -1549,8 +1551,12 @@ struct vfio_region_dma_range {
> > > struct vfio_device_feature_dma_buf {
> > > __u32 region_index;
> > > __u32 open_flags;
> > > - __u32 flags;
> > > - __u32 nr_ranges;
> > > + __u32 flags;
> > > + /* Flags sub-field reserved for attribute enum */
> > > +#define VFIO_DEVICE_FEATURE_DMA_BUF_ATTR_MASK (0xfU << 28)
> > > +#define VFIO_DEVICE_FEATURE_DMA_BUF_ATTR_UC (0 << 28)
> > > +#define VFIO_DEVICE_FEATURE_DMA_BUF_ATTR_WC (1 << 28)
> > > + __u32 nr_ranges;
>
> Alex,
>
> The TPH proposal extends the flags field in a similar way, but I suggested
> a different approach to conserve bits. At the moment, we spend three bits
> on a single feature, which feels wasteful.
>
> What do you think?
> https://lore.kernel.org/all/20260409120415.GF86584@unreal/

I already proposed a very different interface for TPH that decouples
the dma-buf creation from setting the TPH values:

https://lore.kernel.org/all/20260423132016.4a25e074@shazbot.org/

This is overall less intrusive than the TPH change proposed, but it
could still make sense to align this as an operation on the dma-buf,
that can be probed as a separate feature. Thanks,

Alex