On 7/3/2026 2:10 AM, Zhiping Zhang 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. > > The attach path reads @revoked without holding memory_lock. Annotate it > with READ_ONCE() to document this intentional lockless access: the read > is a benign early-out, and a racing revocation is re-checked under > dmabuf->resv in vfio_pci_dma_buf_map() before any mapping is handed out.
I believe this modification (@revoked) might be related to resetting the bit field segment and subsequently identifying a concurrency issue. It is recommended to submit this as an independent commit. > The annotation only needs to keep the access well-formed against the > memory_lock-protected writers. > > 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]> ... > > #include "vfio_pci_priv.h" > @@ -19,7 +20,17 @@ struct vfio_pci_dma_buf { > u32 nr_ranges; > struct kref kref; > struct completion comp; > - u8 revoked : 1; > + > + /* > + * Updates protected by dmabuf->resv, @revoked additionally > + * protected by memory_lock. > + */ > + u16 tph_st_ext; > + u8 tph_st; how about: u16 tph_xst; u16 tph_st; > + bool revoked; why not move revoked before or after tph fields if it don't take one bit field? > + u8 tph_st_valid:1; > + u8 tph_st_ext_valid:1; how about: u8 tph_xst_valid > + u8 tph_ph:2; > }; ... > +#define VFIO_DEVICE_FEATURE_DMA_BUF_TPH 13 > + > +#define VFIO_DMA_BUF_TPH_ST (1 << 0) > +#define VFIO_DMA_BUF_TPH_ST_EXT (1 << 1) > + > +struct vfio_device_feature_dma_buf_tph { > + __s32 dmabuf_fd; > + __u32 flags; > + __u16 steering_tag_ext; > + __u8 steering_tag; how about: __u16 xst; __u8 st; and it corresponding to VFIO_DMA_BUF_TPH_ST/ST_EXT Thanks > + __u8 ph; > +}; > + > /* -------- API for Type1 VFIO IOMMU -------- */ > > /**
