[PATCH v7 18/19] RDMA/uverbs: Hand out the P2PDMA provider behind a dma-buf

From: Leon Romanovsky

Date: Sun Sep 20 2026 - 07:51:37 EST


From: Leon Romanovsky <leonro@xxxxxxxxxx>

An importer attached to a uverbs dma-buf cannot tell whether its
peer-to-peer traffic would reach the exported memory directly, because the
&struct p2pdma_provider describing it stays in ib_uverbs_dmabuf_file.

Implement @p2pdma_provider so dma_buf_p2pdma_map_type() can reach it, and
refuse once the buffer is revoked and the memory it described is gone.

Tested-by: Tushar Dave <tdave@xxxxxxxxxx>
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
drivers/infiniband/core/uverbs_std_types_dmabuf.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/infiniband/core/uverbs_std_types_dmabuf.c b/drivers/infiniband/core/uverbs_std_types_dmabuf.c
index 2411ebee69e2..5a6a1ee430a7 100644
--- a/drivers/infiniband/core/uverbs_std_types_dmabuf.c
+++ b/drivers/infiniband/core/uverbs_std_types_dmabuf.c
@@ -76,6 +76,17 @@ static void uverbs_dmabuf_release(struct dma_buf *dmabuf)
uverbs_uobject_release(&priv->uobj);
}

+static struct p2pdma_provider *
+uverbs_dmabuf_provider(struct dma_buf *dmabuf)
+{
+ struct ib_uverbs_dmabuf_file *priv = dmabuf->priv;
+
+ if (priv->revoked)
+ return NULL;
+
+ return priv->provider;
+}
+
static const struct dma_buf_ops uverbs_dmabuf_ops = {
.attach = uverbs_dmabuf_attach,
.map_dma_buf = uverbs_dmabuf_map,
@@ -83,6 +94,7 @@ static const struct dma_buf_ops uverbs_dmabuf_ops = {
.pin = uverbs_dmabuf_pin,
.unpin = uverbs_dmabuf_unpin,
.release = uverbs_dmabuf_release,
+ .p2pdma_provider = uverbs_dmabuf_provider,
};

static int UVERBS_HANDLER(UVERBS_METHOD_DMABUF_ALLOC)(

--
2.55.0