[PATCH v7 17/19] vfio/pci: Hand out the P2PDMA provider behind a dma-buf
From: Leon Romanovsky
Date: Sun Sep 20 2026 - 07:50:00 EST
From: Leon Romanovsky <leonro@xxxxxxxxxx>
An importer attached to a VFIO dma-buf cannot tell whether its peer-to-peer
traffic would reach the exported BAR directly, because the
&struct p2pdma_provider describing it stays in vfio_pci_dma_buf.
Implement @p2pdma_provider so dma_buf_p2pdma_map_type() can reach it.
Refuse once the buffer is revoked: vfio_pci_dma_buf_cleanup() revokes
before it drops the device registration that keeps the provider allocated,
so a revoked buffer has nothing left to describe.
Tested-by: Tushar Dave <tdave@xxxxxxxxxx>
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
drivers/vfio/pci/vfio_pci_dmabuf.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
index c16f460c01d6..fcf392cfc3c5 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -99,11 +99,23 @@ static void vfio_pci_dma_buf_release(struct dma_buf *dmabuf)
kfree(priv);
}
+static struct p2pdma_provider *
+vfio_pci_dma_buf_provider(struct dma_buf *dmabuf)
+{
+ struct vfio_pci_dma_buf *priv = dmabuf->priv;
+
+ if (priv->revoked)
+ return NULL;
+
+ return priv->provider;
+}
+
static const struct dma_buf_ops vfio_pci_dmabuf_ops = {
.attach = vfio_pci_dma_buf_attach,
.map_dma_buf = vfio_pci_dma_buf_map,
.unmap_dma_buf = vfio_pci_dma_buf_unmap,
.release = vfio_pci_dma_buf_release,
+ .p2pdma_provider = vfio_pci_dma_buf_provider,
};
/*
--
2.55.0