On Fri, Jun 12, 2026 at 10:10 AM Alex Williamson <[email protected]> wrote: > > > > On Thu, 11 Jun 2026 09:11:19 -0700 > Zhiping Zhang <[email protected]> wrote: > > > Implement dma-buf get_tph for vfio-pci exported dma-bufs and add > > VFIO_DEVICE_FEATURE_DMA_BUF_TPH so userspace can publish TPH metadata > > for a VFIO-owned device. > > > > 8-bit ST and 16-bit Extended ST are distinct PCIe TPH namespaces; the > > uAPI carries both with explicit validity flags, and get_tph() returns > > the value matching the importer's requested namespace or -EOPNOTSUPP. > > > > Publish and read the TPH descriptor under dmabuf->resv, matching the > > locking used for other importer-visible dma-buf state. The SET ioctl > > takes dma_resv_lock_interruptible(), while the callback runs under > > DMA-buf's asserted resv lock. > > > > Reject requests the device cannot consume as a completer: > > pcie_tph_completer_type() must report at least > > PCI_EXP_DEVCAP2_TPH_COMP_TPH_ONLY, and Extended ST requires > > PCI_EXP_DEVCAP2_TPH_COMP_EXT_TPH. Validate fields before the completer > > check so userspace gets the narrowest errno. > > > > Signed-off-by: Zhiping Zhang <[email protected]> > > --- > > drivers/vfio/pci/vfio_pci_core.c | 3 + > > drivers/vfio/pci/vfio_pci_dmabuf.c | 94 +++++++++++++++++++++++++++++- > > drivers/vfio/pci/vfio_pci_priv.h | 12 ++++ > > include/uapi/linux/vfio.h | 37 ++++++++++++ > > 4 files changed, 145 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/vfio/pci/vfio_pci_core.c > > b/drivers/vfio/pci/vfio_pci_core.c > > index 050e7542952e..4fa36f2f7555 100644 > > --- a/drivers/vfio/pci/vfio_pci_core.c > > +++ b/drivers/vfio/pci/vfio_pci_core.c > > @@ -1569,6 +1569,9 @@ int vfio_pci_core_ioctl_feature(struct vfio_device > > *device, u32 flags, > > return vfio_pci_core_feature_token(vdev, flags, arg, argsz); > > case VFIO_DEVICE_FEATURE_DMA_BUF: > > return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz); > > + case VFIO_DEVICE_FEATURE_DMA_BUF_TPH: > > + return vfio_pci_core_feature_dma_buf_tph(vdev, flags, arg, > > + argsz); > > default: > > return -ENOTTY; > > } > > diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c > > b/drivers/vfio/pci/vfio_pci_dmabuf.c > > index 1a177ce7de54..0a0705c8dbea 100644 > > --- a/drivers/vfio/pci/vfio_pci_dmabuf.c > > +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c > > @@ -3,6 +3,7 @@ > > */ > > #include <linux/dma-buf-mapping.h> > > #include <linux/pci-p2pdma.h> > > +#include <linux/pci-tph.h> > > #include <linux/dma-resv.h> > > > > #include "vfio_pci_priv.h" > > @@ -19,7 +20,12 @@ struct vfio_pci_dma_buf { > > u32 nr_ranges; > > struct kref kref; > > struct completion comp; > > - u8 revoked : 1; > > + u8 tph_st_valid:1; > > + u8 tph_st_ext_valid:1; > > + u8 tph_ph:2; > > + u8 tph_st; > > + u16 tph_st_ext; > > + u8 revoked:1; > > If these bitfields are now all protected under dma_resv_lock they > should be grouped together with a comment to that effect, no need for > revoked to get kicked out to its own storage unit. In [1] I'm > proposing runtime modified flags each get their own storage unit, but > for more isolated cases, so long as we keep track and enforce serialized > updates, I'm ok with runtime bitfields. Thanks, > > Alex > > [1]https://lore.kernel.org/all/[email protected]/
Sure, will group them under one comment. Thanks, Zhiping
