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

Zhiping Zhang
2026-04-24T05:41:41Z

On Thu, Apr 23, 2026 at 3:46 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> >
> On Thu, Apr 23, 2026 at 01:20:16PM -0600, Alex Williamson wrote:
>
> > My suggestion would be that we leave VFIO_DEVICE_FEATURE_DMA_BUF
> > unchanged and add a VFIO_DEVICE_FEATURE_DMA_BUF_TPH ioctl which takes
> > the fd from VFIO_DEVICE_FEATURE_DMA_BUF, along with a steering tag and
> > processing hint. It would fdget() the dmabuf fd, validate it's a
> > dmabuf via f_ops, validate it's a vfio exported dmabuf via dmabuf->ops,
> > find the matching vfio_pci_dma_buf via priv under memory_lock, and
> > stuff the provided TPH values into the object. It would be left to the
> > user to sequence setting the TPH values on the dmabuf before the dmabuf
> > is consumed by the importer.
> >
> > Is that a more reasonable uAPI? Thanks,
>
> Off hand I think it can work, with the proviso that if userspace uses
> the dmabuf before setting the tph the importer may ignore it. I don't
> think that is a problem in practice.
>
> Jason

Thanks Alex and Jason!

I agree that the separate feature sounds like a cleaner design and could avoid
the uAPI complications. For v2 I'll:
- Leave VFIO_DEVICE_FEATURE_DMA_BUF unchanged,
- Add VFIO_DEVICE_FEATURE_DMA_BUF_TPH as a SET-only feature that
takes the dmabuf fd, steering tag, and processing hint,
- Keep the dma_buf_ops.get_tph callback as-is.
and then the userspace sequence would become:
1. fd = VFIO_DEVICE_FEATURE_DMA_BUF (create dmabuf, unchanged)
2. VFIO_DEVICE_FEATURE_DMA_BUF_TPH (set TPH on fd)
3. pass fd to importer

Zhiping