[RFC PATCH 1/4] sunrpc: add supports_p2pdma to rpc_xprt_ops

Pranjal Shrivastava
2026-04-01T19:45:11Z

Add a new transport op, supports_p2pdma, to allow upper layers (such as
NFS) to query whether the underlying RPC transport supports PCI
Peer-to-Peer DMA (P2PDMA).

Since the capability is hardware-dependent. For the RDMA transport,
implement this by querying the underlying InfiniBand device via
ib_dma_pci_p2p_dma_supported() to ensures that P2PDMA is only
attempted when both the transport and the HCA drivers support it.

Signed-off-by: Pranjal Shrivastava <praan@google.com>
---
include/linux/sunrpc/xprt.h | 1 +
net/sunrpc/xprtrdma/transport.c | 9 +++++++++
2 files changed, 10 insertions(+)

diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index f46d1fb8f71a..e451acd2e047 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -187,6 +187,7 @@ struct rpc_xprt_ops {
void (*bc_free_rqst)(struct rpc_rqst *rqst);
void (*bc_destroy)(struct rpc_xprt *xprt,
unsigned int max_reqs);
+ bool (*supports_p2pdma)(struct rpc_xprt *xprt);
};

/*
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 9a8ce5df83ca..1c1714189a29 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -717,6 +717,14 @@ xprt_rdma_disable_swap(struct rpc_xprt *xprt)
{
}

+static bool
+xprt_rdma_supports_p2pdma(struct rpc_xprt *xprt)
+{
+ struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
+
+ return ib_dma_pci_p2p_dma_supported(r_xprt->rx_ep->re_id->device);
+}
+
/*
* Plumbing for rpc transport switch and kernel module
*/
@@ -742,6 +750,7 @@ static const struct rpc_xprt_ops xprt_rdma_procs = {
.enable_swap = xprt_rdma_enable_swap,
.disable_swap = xprt_rdma_disable_swap,
.inject_disconnect = xprt_rdma_inject_disconnect,
+ .supports_p2pdma = xprt_rdma_supports_p2pdma,
#if defined(CONFIG_SUNRPC_BACKCHANNEL)
.bc_setup = xprt_rdma_bc_setup,
.bc_maxpayload = xprt_rdma_bc_maxpayload,
--
2.53.0.1185.g05d4b7b318-goog