Acked-by: Chengwen Feng <[email protected]>
On 7/16/2026 4:39 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.
>
> Hold memory_lock in the SET path while checking that the dma-buf still
> belongs to this vfio-pci device and while publishing the descriptor.
> Cleanup clears the dma-buf/vdev association under memory_lock; taking the
> same lock prevents publishing into a dma-buf that has already been
> detached from @vdev, and preserves the memory_lock -> dmabuf->resv order
> used by the move path.
>
> The attach path reads @revoked without holding memory_lock. Use
> READ_ONCE() for that lockless attach-path test and WRITE_ONCE() for the
> revoke/unrevoke writers 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.
> 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]>