On Tue, 30 Jun 2026 15:42:25 -0700 Zhiping Zhang <[email protected]> wrote:
> Implement dma-buf get_pci_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_pci_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. Make PROBE follow the same hardware > gate so the feature only probes as supported when the device can really > consume it. > > Signed-off-by: Zhiping Zhang <[email protected]> > --- > drivers/vfio/pci/vfio_pci_core.c | 3 + > drivers/vfio/pci/vfio_pci_dmabuf.c | 99 +++++++++++++++++++++++++++++- > drivers/vfio/pci/vfio_pci_priv.h | 12 ++++ > include/uapi/linux/vfio.h | 43 +++++++++++++ > 4 files changed, 155 insertions(+), 2 deletions(-) > > diff --git a/drivers/vfio/pci/vfio_pci_core.c > b/drivers/vfio/pci/vfio_pci_core.c > index a28f1e99362c..c7d6902bc61b 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -1572,6 +1572,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 c16f460c01d6..8de72f9e7502 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,14 @@ struct vfio_pci_dma_buf { > u32 nr_ranges; > struct kref kref; > struct completion comp; > - u8 revoked : 1; > + > + /* Protected by dmabuf->resv. */ > + u16 tph_st_ext; > + u8 tph_st; > + bool revoked; > + u8 tph_st_valid:1; > + u8 tph_st_ext_valid:1; > + u8 tph_ph:2; Since it seems there will be a v11, note again the comment made here on v9: On Tue, 23 Jun 2026 22:24:54 -0700 Zhiping Zhang <[email protected]> wrote: > On Tue, Jun 23, 2026 at 11:17 AM Alex Williamson <[email protected]> wrote: > > > > Nit, it would be more accurate to say: > > > > /* > > * Updates protected by dmabuf->resv, @revoked additionally > > * protected by memory_lock. > > */ > > > > revoked also has an unprotected read, but it's previously existing and > > benign, and likely just needs a READ_ONCE() annotation. > > > > Agreed, I'll update the comment and add READ_ONCE() as well. The READ_ONCE was added, but the comment remains as in v9. The READ_ONCE rationale should be described in the commit log too. Thanks, Alex
