Subject: Re: [PATCH v1 1/2] vfio: add callback to get tph info for dma-buf

From: Leon Romanovsky <[email-masked]>
Date: Mon, 27 Apr 2026 16:37:46 +0300

On Wed, Apr 22, 2026 at 09:23:27AM -0600, Alex Williamson wrote:
> On Mon, 20 Apr 2026 11:39:15 -0700
> Zhiping Zhang <[email-masked]> wrote:
> 
> > Add a dma-buf callback that returns raw TPH metadata from the exporter
> > so peer devices can reuse the steering tag and processing hint
> > associated with a VFIO-exported buffer.
> > 
> > Keep the existing VFIO_DEVICE_FEATURE_DMA_BUF uAPI layout intact by
> > using a flag plus one extra trailing entries[] object for the optional
> > TPH metadata. Rename the uAPI field dma_ranges to entries. The
> > nr_ranges field remains the DMA range count; when VFIO_DMABUF_FLAG_TPH
> > is set the kernel reads one extra entry beyond nr_ranges for the TPH
> > metadata.
> > 
> > Add an st_width parameter to get_tph() so the exporter can reject
> > steering tags that exceed the consumer's supported width (8 vs 16 bit).
> > When no TPH metadata was supplied, make get_tph() return -EOPNOTSUPP.
> > 
> > Signed-off-by: Zhiping Zhang <[email-masked]>
> > ---
> >  drivers/vfio/pci/vfio_pci_dmabuf.c | 62 +++++++++++++++++++++++-------
> >  include/linux/dma-buf.h            | 17 ++++++++
> >  include/uapi/linux/vfio.h          | 28 ++++++++++++--
> >  3 files changed, 89 insertions(+), 18 deletions(-)

<...>

> > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> > index bb7b89330d35..a0bd24623c52 100644
> > --- a/include/uapi/linux/vfio.h
> > +++ b/include/uapi/linux/vfio.h
> > @@ -1490,16 +1490,36 @@ struct vfio_device_feature_bus_master {
> >   * open_flags are the typical flags passed to open(2), eg O_RDWR, O_CLOEXEC,
> >   * etc. offset/length specify a slice of the region to create the dmabuf from.
> >   * nr_ranges is the total number of (P2P DMA) ranges that comprise the dmabuf.
> > + * When VFIO_DMABUF_FLAG_TPH is set, entries[] contains one extra trailing
> > + * object after the nr_ranges DMA ranges carrying the TPH steering tag and
> > + * processing hint.
> 
> I really don't think we want to design an API where entries is
> implicitly one-off from what's actually there.  This feeds back into
> the below removal of the __counted by attribute, which is a red flag
> that this is the wrong approach.

I believe removing `__counted` is a mistake. In my proposal, the intent  
was to adjust the meaning of the storage object based on the flag bit.  
The size of the array should still be represented correctly.

Thanks