Skip to contentSkip to conversation

nfs: PCI P2PDMA for O_DIRECT over RDMA

RFC PATCH In review Pranjal Shrivastava 5 participants 25 messages Oct 6 – Nov 3

Subsystems (5)
Networking PCI NFS client NFS server +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover nfs: PCI P2PDMA for O_DIRECT over RDMA

Enable NFS O_DIRECT to and from PCI peer-to-peer DMA (P2PDMA) memory on RDMA mounts. This replaces the initial RFC [1] and builds on the Direct I/O modernization series [2].

P2PDMA memory can be an NVMe Controller Memory Buffer, or the BAR of a vfio-pci device exported as a ZONE_DEVICE-backed DMABUF, as proposed in [3]. Today, NFS O_DIRECT fails with -EREMOTEIO when the user buffer is such memory, since iov_iter_extract_pages() refuses P2PDMA pages unless the caller passes ITER_ALLOW_P2PDMA. Buffered I/O is not affected, as the CPU copies the data into the page cache.

P2PDMA memory may not be safe to access with the CPU. Thus, the series follows one rule: a P2PDMA payload moves only by DMA between the device memory and the NIC (or the local disk with LOCALIO). Any path that would touch the payload via CPU accesses refuses the I/O instead of copying it.

Design
======

O_DIRECT, user buffer in P2PDMA memory

      |
  nfs_direct_extract_pages()  ITER_ALLOW_P2PDMA on RDMA, !pNFS mounts
      |                       (other mounts: -EREMOTEIO, as today)
  nfs_generic_pgio()          is_pci_p2pdma_page() -> args.p2pdma
      |
      +-- LOCALIO: disk lacks BLK_FEAT_PCI_P2PDMA  -> regular RPC
      |            not one DIO-aligned segment     -> -EINVAL
      |
      +-- RPC: krb5i / krb5p                       -> -EREMOTEIO
               encoders set XDRBUF_P2PDMA
                 |
                 +-- xprtsock                      -> -EREMOTEIO
                 +-- xprtrdma: NIC can't do P2P    -> -EREMOTEIO
                               NIC can't reach it  -> -EREMOTEIO
                               otherwise: Read/Write chunks only

1. Per-RPC decision
ITER_ALLOW_P2PDMA at extraction is only a hint. NFS tags each READ and WRITE whose pages are P2PDMA memory with XDRBUF_P2PDMA, and the transport serving that RPC decides whether it can move them. With nconnect, reconnects and migration, the transport and its device can change between extraction and transmission, so a mount-time capability cannot be trusted. LOCALIO does not use the NIC at all.

2. Socket transports
TCP (including TLS), UDP and AF_LOCAL move data via CPU accesses, so they return -EREMOTEIO for a tagged RPC before touching the socket. xprt_transmit() now fails only the refused RPC and keeps draining the transmit queue.

3. RPC-over-RDMA
The inline paths copy the payload via CPU accesses or DMA-map it with calls that do not handle P2PDMA pages. Thus, xprtrdma always sends a P2PDMA WRITE payload in a Read chunk and receives a P2PDMA READ payload in a Write chunk, whatever its size. It returns -EREMOTEIO when:
- the NIC cannot DMA to PCI peer-to-peer memory (e.g. rxe, siw),
- the NIC cannot reach the P2PDMA memory (DMA mapping fails),
- the GSS service forbids direct data placement (krb5i, krb5p), or
- the rest of the READ reply does not fit inline.
If a server returns READ data inline despite the Write chunk, which RFC 8166 forbids, the RPC fails instead of copying into the pages. Small P2PDMA I/O therefore always pays for memory registration.

4. GSS
krb5i checksums and krb5p encrypts the payload via CPU accesses while the RPC is encoded, before the transport sees it. nfs_pgio_prepare() fails such READs and WRITEs with -EREMOTEIO before encoding.

5. LOCALIO
LOCALIO is used for P2PDMA pages only if the filesystem's block device supports P2PDMA. Otherwise, the I/O goes out as a regular RPC. I/O that is not a single DIO-aligned segment would fall back to buffered I/O, so it fails with -EINVAL instead.

6. READ_PLUS
READ_PLUS decoding moves data and zero-fills holes via CPU accesses, so it is never used for P2PDMA pages. RDMA mounts already disable it.

All refusals return -EREMOTEIO, the error iov_iter_extract_pages() returns today, except misaligned LOCALIO I/O, which returns -EINVAL. Refused I/O fails at once, even on hard mounts.

Call for review
===============
Feedback is appreciated on:

1. Layering: "RDMA transport, !pNFS" is only a hint, and each RPC re-checks its transport. Should the transport advertise P2PDMA capability up front instead? That would also allow LOCALIO on TCP mounts, which this series refuses.
2. nconnect: fail an RPC on a transport without P2PDMA, or pick a capable transport?
3. Migration / reconnect: the path can move to a NIC without P2PDMA, and I/O that worked starts failing with -EREMOTEIO. Acceptable?
4. Hard mounts: refused I/O fails at once instead of retrying. Acceptable?
5. LOCALIO: the check uses sb->s_bdev, which misses multi-device filesystems. Is there a better way to ask whether a file can do P2PDMA? Should misaligned I/O fall back to an RPC instead of failing with -EINVAL?
6. pNFS: excluded for now. Route P2PDMA I/O through the MDS, or let each layout driver opt in?

Known issue: the pNFS check happens at extraction. If a mount gains pNFS afterwards (e.g. after migration), a rescheduled WRITE could reach a layout driver. I plan to decide once per O_DIRECT call and force the MDS path when P2PDMA pages are allowed.

Thanks,
Praan

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

Changes since the initial RFC [1]:
- Split the Direct I/O modernization into its own series [2].
- Drop NFS_CAP_P2PDMA, the 64-bit caps expansion and the ->supports_p2pdma xprt op. Decide per RPC instead, as Chuck suggested.
- Refuse P2PDMA pages in the socket transports, and fail only the refused RPC.
- Move P2PDMA payloads only via chunks in xprtrdma, and return -EREMOTEIO when the NIC cannot reach the memory.
- Refuse krb5i and krb5p, and allow LOCALIO only as aligned direct I/O to a P2PDMA-capable disk.

Pranjal Shrivastava (8):
sunrpc: introduce XDRBUF_P2PDMA flag
sunrpc: fail only the RPC a transport refuses
xprtrdma: move P2PDMA payloads only via chunks
xprtrdma: return -EREMOTEIO on P2PDMA map failure
nfs: tag READ/WRITE RPCs carrying P2PDMA pages
nfs: refuse P2PDMA pages with krb5i and krb5p
nfs: allow LOCALIO for P2PDMA pages only as aligned direct I/O
nfs: allow P2PDMA pages for O_DIRECT on RDMA mounts

 fs/nfs/direct.c                | 10 ++++++++-
 fs/nfs/internal.h              |  8 +++++++
 fs/nfs/localio.c               | 40 ++++++++++++++++++++++++++++++++++
 fs/nfs/nfs2xdr.c               |  4 ++++
 fs/nfs/nfs3xdr.c               |  4 ++++
 fs/nfs/nfs4proc.c              |  3 +++
 fs/nfs/nfs4xdr.c               |  4 ++++
 fs/nfs/pagelist.c              | 13 +++++++++++
 include/linux/nfs_xdr.h        |  1 +
 include/linux/sunrpc/xdr.h     |  1 +
 include/linux/sunrpc/xprt.h    |  5 +++++
 net/sunrpc/xprt.c              |  9 ++++++++
 net/sunrpc/xprtrdma/frwr_ops.c | 15 ++++++++-----
 net/sunrpc/xprtrdma/rpc_rdma.c | 40 ++++++++++++++++++++++++++++++++--
 net/sunrpc/xprtsock.c          | 12 ++++++++++
 15 files changed, 161 insertions(+), 8 deletions(-)
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#1 lore raw

RFC PATCH 1/8 sunrpc: introduce XDRBUF_P2PDMA flag

The NFS client will soon pass PCI peer-to-peer DMA (P2PDMA) pages to the transport as READ or WRITE payload. Only a transport that can DMA directly to and from that memory may move it.

Introduce XDRBUF_P2PDMA and a helper, xprt_rqst_has_p2pdma(), to mark and detect requests whose pages are P2PDMA memory. The TCP (including TLS), UDP and AF_LOCAL transports return -EREMOTEIO for such a request before touching the socket. iov_iter_extract_pages() returns the same error today for P2PDMA pages the caller did not allow. Thus, users see no new error code.

---
 include/linux/sunrpc/xdr.h  |  1 +
 include/linux/sunrpc/xprt.h |  5 +++++
 net/sunrpc/xprtsock.c       | 12 ++++++++++++
 3 files changed, 18 insertions(+)
include/linux/sunrpc/xdr.h +1 -0
index b102b4f21e6b..79526f47be2d 100644
@@ -65,6 +65,7 @@ struct xdr_buf {
 #define XDRBUF_READ		0x01		/* target of file read */
 #define XDRBUF_WRITE		0x02		/* source of file write */
 #define XDRBUF_SPARSE_PAGES	0x04		/* Page array is sparse */
+#define XDRBUF_P2PDMA		0x08		/* Pages are P2PDMA memory */
 
 	unsigned int	buflen,		/* Total length of storage buffer */
 			len;		/* Length of XDR encoded message */
include/linux/sunrpc/xprt.h +5 -0
index a82045804d34..08ab04fa4509 100644
@@ -134,6 +134,11 @@ static inline int xprt_rqst_add_seqno(struct rpc_rqst *req, u32 seqno)
 	return 0;
 }
 
+static inline bool xprt_rqst_has_p2pdma(const struct rpc_rqst *req)
+{
+	return (req->rq_snd_buf.flags | req->rq_rcv_buf.flags) & XDRBUF_P2PDMA;
+}
+
 /* RPC transport layer security policies */
 enum xprtsec_policies {
 	RPC_XPRTSEC_NONE = 0,
net/sunrpc/xprtsock.c +12 -0
index f5a5136327ba..9fa6d7ec207e 100644
@@ -962,6 +962,10 @@ static int xs_local_send_request(struct rpc_rqst *req)
 	unsigned int sent;
 	int status;
 
+	/* Sockets move data via CPU accesses, so refuse P2PDMA pages */
+	if (xprt_rqst_has_p2pdma(req))
+		return -EREMOTEIO;
+
 	/* Close the stream if the previous transmission was incomplete */
 	if (xs_send_request_was_aborted(transport, req)) {
 		xprt_force_disconnect(xprt);
@@ -1031,6 +1035,10 @@ static int xs_udp_send_request(struct rpc_rqst *req)
 	unsigned int sent;
 	int status;
 
+	/* Sockets move data via CPU accesses, so refuse P2PDMA pages */
+	if (xprt_rqst_has_p2pdma(req))
+		return -EREMOTEIO;
+
 	xs_pktdump("packet data:",
 				req->rq_svec->iov_base,
 				req->rq_svec->iov_len);
@@ -1118,6 +1126,10 @@ static int xs_tcp_send_request(struct rpc_rqst *req)
 	unsigned int sent;
 	int status;
 
+	/* Sockets move data via CPU accesses, so refuse P2PDMA pages */
+	if (xprt_rqst_has_p2pdma(req))
+		return -EREMOTEIO;
+
 	/* Close the stream if the previous transmission was incomplete */
 	if (xs_send_request_was_aborted(transport, req)) {
 		if (transport->sock != NULL)
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#2 lore raw

Re: [RFC PATCH v1 1/8] sunrpc: introduce XDRBUF_P2PDMA flag

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

The NFS client will soon pass PCI peer-to-peer DMA (P2PDMA) pages to the transport as READ or WRITE payload. Only a transport that can DMA directly to and from that memory may move it.

Quoted 8 lines

Introduce XDRBUF_P2PDMA and a helper, xprt_rqst_has_p2pdma(), to mark and detect requests whose pages are P2PDMA memory. The TCP (including TLS), UDP and AF_LOCAL transports return -EREMOTEIO for such a request before touching the socket. iov_iter_extract_pages() returns the same error today for P2PDMA pages the caller did not allow. Thus, users see no new error code.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

RFC PATCH 2/8 sunrpc: fail only the RPC a transport refuses

In reply to Pranjal Shrivastava

A transport returns -EREMOTEIO from ->send_request() for a request whose P2PDMA pages it cannot move. Retrying doesn't help, but today the error stops xprt_transmit(), finds whichever task is draining the transmit queue, and leaves the refused request queued.

Dequeue the request, on -EREMOTEIO, cancel only its own task with rpc_task_try_cancel(), and keep draining. Setting tk_status instead would not work, a dequeued task looks transmitted and would wait for a reply that never comes.

---
 net/sunrpc/xprt.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/sunrpc/xprt.c +9 -0
index 48a3618cbb29..084d5a508357 100644
@@ -1579,6 +1579,15 @@ xprt_request_transmit(struct rpc_rqst *req, struct rpc_task *snd_task)
 	if (status != 0) {
 		req->rq_ntrans--;
 		trace_xprt_transmit(req, status);
+		if (status == -EREMOTEIO) {
+			/*
+			 * This transport will never send req. Fail only
+			 * its task, and let the caller keep draining.
+			 */
+			xprt_request_dequeue_transmit(task);
+			rpc_task_try_cancel(task, status);
+			return 0;
+		}
 		return status;
 	}
 
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#4 lore raw

Re: [RFC PATCH v1 2/8] sunrpc: fail only the RPC a transport refuses

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

A transport returns -EREMOTEIO from ->send_request() for a request whose P2PDMA pages it cannot move. Retrying doesn't help, but today the error stops xprt_transmit(), finds whichever task is draining the transmit queue, and leaves the refused request queued.

Dequeue the request, on -EREMOTEIO, cancel only its own task with rpc_task_try_cancel(), and keep draining. Setting tk_status instead would not work, a dequeued task looks transmitted and would wait for a reply that never comes.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

RFC PATCH 3/8 xprtrdma: move P2PDMA payloads only via chunks

In reply to Pranjal Shrivastava

Only chunks move a P2PDMA payload by DMA directly between the NIC and the device memory. The inline paths copy the payload via CPU accesses or DMA-map it with calls that do not handle P2PDMA pages.

Always send a P2PDMA WRITE payload in a Read chunk, and receive a P2PDMA READ payload in a Write chunk, whatever its size. Return -EREMOTEIO when that is not possible: the NIC cannot DMA to PCI peer-to-peer memory (e.g. rxe, siw), the GSS service forbids direct data placement (krb5i, krb5p), or the rest of the READ reply does not fit inline.

If a server returns READ data inline anyway, fail the RPC with -EREMOTEIO instead of copying the data into the P2PDMA pages.

---
 net/sunrpc/xprtrdma/rpc_rdma.c | 40 ++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +38 -2
index 1285f04cdac1..065ab9a7edc9 100644
@@ -175,6 +175,22 @@ rpcrdma_nonpayload_inline(const struct rpcrdma_xprt *r_xprt,
 		r_xprt->rx_ep->re_max_inline_recv;
 }
 
+/* A P2PDMA payload moves only by DMA between the NIC and device
+ * memory, in its own Read or Write chunk. That requires a NIC that
+ * can DMA to PCI peer-to-peer memory and, for a READ, a Reply whose
+ * non-payload part fits inline.
+ */
+static bool
+rpcrdma_p2pdma_allowed(const struct rpcrdma_xprt *r_xprt,
+		       const struct rpc_rqst *rqst)
+{
+	if (!ib_dma_pci_p2p_dma_supported(r_xprt->rx_ep->re_id->device))
+		return false;
+	if (rqst->rq_rcv_buf.flags & XDRBUF_P2PDMA)
+		return rpcrdma_nonpayload_inline(r_xprt, rqst);
+	return true;
+}
+
 /* ACL likes to be lazy in allocating pages. For TCP, these
  * pages can be allocated during receive processing. Not true
  * for RDMA, which must always provision receive buffers
@@ -815,6 +831,7 @@ inline int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,
  *	%-EAGAIN if the caller should call again with the same arguments,
  *	%-ENOBUFS if the caller should call again after a delay,
  *	%-EMSGSIZE if the transport header is too small,
+ *	%-EREMOTEIO if the device cannot move the request's P2PDMA pages,
  *	%-EIO if a permanent problem occurred while marshaling.
  */
 int
@@ -854,16 +871,25 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
 	ddp_allowed = !test_bit(RPCAUTH_AUTH_DATATOUCH,
 				&rqst->rq_cred->cr_auth->au_flags);
 
+	if (xprt_rqst_has_p2pdma(rqst) &&
+	    (!ddp_allowed || !rpcrdma_p2pdma_allowed(r_xprt, rqst))) {
+		ret = -EREMOTEIO;
+		goto out_err;
+	}
+
 	/*
 	 * Chunks needed for results?
 	 *
+	 * o A P2PDMA read payload always returns in a write chunk.
 	 * o If the expected result is under the inline threshold, all ops
 	 *   return as inline.
 	 * o Large read ops return data as write chunk(s), header as
 	 *   inline.
 	 * o Large non-read ops return as a single reply chunk.
 	 */
-	if (rpcrdma_results_inline(r_xprt, rqst))
+	if (rqst->rq_rcv_buf.flags & XDRBUF_P2PDMA)
+		wtype = rpcrdma_writech;
+	else if (rpcrdma_results_inline(r_xprt, rqst))
 		wtype = rpcrdma_noch;
 	else if ((ddp_allowed && rqst->rq_rcv_buf.flags & XDRBUF_READ) &&
 		 rpcrdma_nonpayload_inline(r_xprt, rqst))
@@ -874,6 +900,7 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
 	/*
 	 * Chunks needed for arguments?
 	 *
+	 * o A P2PDMA write payload is always sent as a read chunk.
 	 * o If the total request is under the inline threshold, all ops
 	 *   are sent as inline.
 	 * o Large write ops transmit data as read chunk(s), header as
@@ -885,7 +912,10 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
 	 * that both has a data payload, and whose non-data arguments
 	 * by themselves are larger than the inline threshold.
 	 */
-	if (rpcrdma_args_inline(r_xprt, rqst)) {
+	if (buf->flags & XDRBUF_P2PDMA) {
+		*p++ = rdma_msg;
+		rtype = rpcrdma_readch;
+	} else if (rpcrdma_args_inline(r_xprt, rqst)) {
 		*p++ = rdma_msg;
 		rtype = buf->len < rdmab_length(req->rl_sendbuf) ?
 			rpcrdma_noch_pullup : rpcrdma_noch_mapped;
@@ -1244,6 +1274,12 @@ rpcrdma_decode_msg(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep,
 	/* Build the RPC reply's Payload stream in rqst->rq_rcv_buf */
 	base = (char *)xdr_inline_decode(xdr, 0);
 	rpclen = xdr_stream_remaining(xdr);
+
+	/* Never copy inline reply data into P2PDMA pages */
+	if (unlikely(rqst->rq_rcv_buf.flags & XDRBUF_P2PDMA &&
+		     rpclen > rqst->rq_rcv_buf.head[0].iov_len))
+		return -EREMOTEIO;
+
 	r_xprt->rx_stats.fixup_copy_count +=
 		rpcrdma_inline_fixup(rqst, base, rpclen, writelist & 3);
 
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#6 lore raw

Re: [RFC PATCH v1 3/8] xprtrdma: move P2PDMA payloads only via chunks

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

Only chunks move a P2PDMA payload by DMA directly between the NIC and the device memory. The inline paths copy the payload via CPU accesses or DMA-map it with calls that do not handle P2PDMA pages.

Always send a P2PDMA WRITE payload in a Read chunk, and receive a P2PDMA READ payload in a Write chunk, whatever its size. Return -EREMOTEIO when that is not possible: the NIC cannot DMA to PCI peer-to-peer memory (e.g. rxe, siw), the GSS service forbids direct data placement (krb5i, krb5p), or the rest of the READ reply does not fit inline.

Quoted 4 lines

If a server returns READ data inline anyway, fail the RPC with -EREMOTEIO instead of copying the data into the P2PDMA pages.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

RFC PATCH 4/8 xprtrdma: return -EREMOTEIO on P2PDMA map failure

In reply to Pranjal Shrivastava

ib_dma_map_sg() returns 0 on any failure, so frwr_map() cannot tell why a mapping failed and reports -EIO. Use ib_dma_map_sgtable_attrs() instead, which returns the reason. Pass up -EREMOTEIO, which means the device cannot reach the P2PDMA memory, so the RPC fails with the same error as other P2PDMA refusals. Every other mapping failure still returns -EIO.

---
 net/sunrpc/xprtrdma/frwr_ops.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/frwr_ops.c +10 -5
index e83cef19e656..a55d5e11c0e2 100644
@@ -293,7 +293,8 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	bool sg_gaps = ep->re_mrtype == IB_MR_TYPE_SG_GAPS;
 	unsigned int max_depth = ep->re_max_fr_depth;
 	struct ib_reg_wr *reg_wr;
-	int i, n, dma_nents;
+	struct sg_table sgt;
+	int i, n, dma_nents, ret;
 	struct ib_mr *ibmr;
 	u8 key;
 
@@ -381,10 +382,13 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	mr->mr_dir = rpcrdma_data_dir(writing);
 	mr->mr_nents = i;
 
-	dma_nents = ib_dma_map_sg(ep->re_id->device, mr->mr_sg, mr->mr_nents,
-				  mr->mr_dir);
-	if (!dma_nents)
+	/* Unlike ib_dma_map_sg(), this reports why a mapping failed */
+	sgt.sgl = mr->mr_sg;
+	sgt.orig_nents = mr->mr_nents;
+	ret = ib_dma_map_sgtable_attrs(ep->re_id->device, &sgt, mr->mr_dir, 0);
+	if (ret || !sgt.nents)
 		goto out_dmamap_err;
+	dma_nents = sgt.nents;
 	mr->mr_device = ep->re_id->device;
 
 	ibmr = mr->mr_ibmr;
@@ -413,7 +417,8 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 
 out_dmamap_err:
 	trace_xprtrdma_frwr_sgerr(mr, i);
-	return -EIO;
+	/* Return -EREMOTEIO if the device cannot reach the P2PDMA memory */
+	return ret == -EREMOTEIO ? ret : -EIO;
 
 out_mapmr_err:
 	trace_xprtrdma_frwr_maperr(mr, n);
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#8 lore raw

Re: [RFC PATCH v1 4/8] xprtrdma: return -EREMOTEIO on P2PDMA map failure

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

ib_dma_map_sg() returns 0 on any failure, so frwr_map() cannot tell why a mapping failed and reports -EIO. Use ib_dma_map_sgtable_attrs() instead, which returns the reason. Pass up -EREMOTEIO, which means the device cannot reach the P2PDMA memory, so the RPC fails with the same error as other P2PDMA refusals. Every other mapping failure still returns -EIO.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

Re: [RFC PATCH v1 4/8] xprtrdma: return -EREMOTEIO on P2PDMA map failure

In reply to Pranjal Shrivastava
Quoted 27 lines · Pranjal Shrivastava

ib_dma_map_sg() returns 0 on any failure, so frwr_map() cannot tell why a mapping failed and reports -EIO. Use ib_dma_map_sgtable_attrs() instead, which returns the reason. Pass up -EREMOTEIO, which means the device cannot reach the P2PDMA memory, so the RPC fails with the same error as other P2PDMA refusals. Every other mapping failure still returns -EIO.

---
 net/sunrpc/xprtrdma/frwr_ops.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/frwr_ops.c +2 -1
index e83cef19e656..a55d5e11c0e2 100644
@@ -293,7 +293,8 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	bool sg_gaps = ep->re_mrtype == IB_MR_TYPE_SG_GAPS;
 	unsigned int max_depth = ep->re_max_fr_depth;
 	struct ib_reg_wr *reg_wr;
-	int i, n, dma_nents;
+	struct sg_table sgt;
+	int i, n, dma_nents, ret;
 	struct ib_mr *ibmr;
 	u8 key;
 

net/sunrpc/xprtrdma/frwr_ops.c int frwr_map(struct rpcrdma_xprt *r_xprt, · line 388

Quoted 10 lines
net/sunrpc/xprtrdma/frwr_ops.c +4 -3
@@ -381,10 +382,13 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	mr->mr_dir = rpcrdma_data_dir(writing);
 	mr->mr_nents = i;
 
-	dma_nents = ib_dma_map_sg(ep->re_id->device, mr->mr_sg, mr->mr_nents,
-				  mr->mr_dir);
-	if (!dma_nents)
+	/* Unlike ib_dma_map_sg(), this reports why a mapping failed */
+	sgt.sgl = mr->mr_sg;
+	sgt.orig_nents = mr->mr_nents;
+	ret = ib_dma_map_sgtable_attrs(ep->re_id->device, &sgt, mr->mr_dir, 0);

Please avoid using this function. We are gradually moving away from SG tables in the RDMA code.

In general, it is never good thing to built API around try-and-fail approach. It will require from us to be aware of "specific" usage for the return value from one subsystem by another.

Thanks

#10 lore raw

Re: [RFC PATCH v1 4/8] xprtrdma: return -EREMOTEIO on P2PDMA map failure

Quoted 42 lines · Leon Romanovsky
Quoted 27 lines · Pranjal Shrivastava

ib_dma_map_sg() returns 0 on any failure, so frwr_map() cannot tell why a mapping failed and reports -EIO. Use ib_dma_map_sgtable_attrs() instead, which returns the reason. Pass up -EREMOTEIO, which means the device cannot reach the P2PDMA memory, so the RPC fails with the same error as other P2PDMA refusals. Every other mapping failure still returns -EIO.

---
 net/sunrpc/xprtrdma/frwr_ops.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/frwr_ops.c +2 -1
index e83cef19e656..a55d5e11c0e2 100644
@@ -293,7 +293,8 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	bool sg_gaps = ep->re_mrtype == IB_MR_TYPE_SG_GAPS;
 	unsigned int max_depth = ep->re_max_fr_depth;
 	struct ib_reg_wr *reg_wr;
-	int i, n, dma_nents;
+	struct sg_table sgt;
+	int i, n, dma_nents, ret;
 	struct ib_mr *ibmr;
 	u8 key;
 

net/sunrpc/xprtrdma/frwr_ops.c int frwr_map(struct rpcrdma_xprt *r_xprt, · line 388

Quoted 10 lines
net/sunrpc/xprtrdma/frwr_ops.c +4 -3
@@ -381,10 +382,13 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	mr->mr_dir = rpcrdma_data_dir(writing);
 	mr->mr_nents = i;
 
-	dma_nents = ib_dma_map_sg(ep->re_id->device, mr->mr_sg, mr->mr_nents,
-				  mr->mr_dir);
-	if (!dma_nents)
+	/* Unlike ib_dma_map_sg(), this reports why a mapping failed */
+	sgt.sgl = mr->mr_sg;
+	sgt.orig_nents = mr->mr_nents;
+	ret = ib_dma_map_sgtable_attrs(ep->re_id->device, &sgt, mr->mr_dir, 0);

Please avoid using this function. We are gradually moving away from SG tables in the RDMA code.

Quoted 4 lines

In general, it is never good thing to built API around try-and-fail approach. It will require from us to be aware of "specific" usage for the return value from one subsystem by another.

Fair, I'll drop ib_dma_map_sgtable_attrs(), keep ib_dma_map_sg() as it is today, and check reachability explicitly before mapping instead.

rpcrdma_p2pdma_allowed() already asks ib_dma_pci_p2p_dma_supported() whether the device can do P2PDMA at all. It would also run pci_p2pdma_state() against the device's dma_device for the payload pages, and refuse the RPC with -EREMOTEIO on PCI_P2PDMA_MAP_NOT_SUPPORTED. A mapping failure then stays a plain -EIO, and nothing depends on the DMA layer's return value.

xprtrdma can be built as a module, though, and pci_p2pdma_state() is an inline wrapper around __pci_p2pdma_update_state(), which isn't exported. I see two ways to handle that: export __pci_p2pdma_update_state() as is, or add a small exported helper in p2pdma.c that returns the map type for a page and a device, e.g. pci_p2pdma_page_map_type(). Which would you prefer?

Thanks,
Praan

#11 lore raw

Re: [RFC PATCH v1 4/8] xprtrdma: return -EREMOTEIO on P2PDMA map failure

Quoted 58 lines · Pranjal Shrivastava
Quoted 42 lines · Leon Romanovsky
Quoted 27 lines · Pranjal Shrivastava

ib_dma_map_sg() returns 0 on any failure, so frwr_map() cannot tell why a mapping failed and reports -EIO. Use ib_dma_map_sgtable_attrs() instead, which returns the reason. Pass up -EREMOTEIO, which means the device cannot reach the P2PDMA memory, so the RPC fails with the same error as other P2PDMA refusals. Every other mapping failure still returns -EIO.

---
 net/sunrpc/xprtrdma/frwr_ops.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/frwr_ops.c +2 -1
index e83cef19e656..a55d5e11c0e2 100644
@@ -293,7 +293,8 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	bool sg_gaps = ep->re_mrtype == IB_MR_TYPE_SG_GAPS;
 	unsigned int max_depth = ep->re_max_fr_depth;
 	struct ib_reg_wr *reg_wr;
-	int i, n, dma_nents;
+	struct sg_table sgt;
+	int i, n, dma_nents, ret;
 	struct ib_mr *ibmr;
 	u8 key;
 

net/sunrpc/xprtrdma/frwr_ops.c int frwr_map(struct rpcrdma_xprt *r_xprt, · line 388

Quoted 10 lines
net/sunrpc/xprtrdma/frwr_ops.c +4 -3
@@ -381,10 +382,13 @@ int frwr_map(struct rpcrdma_xprt *r_xprt,
 	mr->mr_dir = rpcrdma_data_dir(writing);
 	mr->mr_nents = i;
 
-	dma_nents = ib_dma_map_sg(ep->re_id->device, mr->mr_sg, mr->mr_nents,
-				  mr->mr_dir);
-	if (!dma_nents)
+	/* Unlike ib_dma_map_sg(), this reports why a mapping failed */
+	sgt.sgl = mr->mr_sg;
+	sgt.orig_nents = mr->mr_nents;
+	ret = ib_dma_map_sgtable_attrs(ep->re_id->device, &sgt, mr->mr_dir, 0);

Please avoid using this function. We are gradually moving away from SG tables in the RDMA code.

Quoted 4 lines

In general, it is never good thing to built API around try-and-fail approach. It will require from us to be aware of "specific" usage for the return value from one subsystem by another.

Fair, I'll drop ib_dma_map_sgtable_attrs(), keep ib_dma_map_sg() as it is today, and check reachability explicitly before mapping instead.

rpcrdma_p2pdma_allowed() already asks ib_dma_pci_p2p_dma_supported() whether the device can do P2PDMA at all. It would also run pci_p2pdma_state() against the device's dma_device for the payload pages, and refuse the RPC with -EREMOTEIO on PCI_P2PDMA_MAP_NOT_SUPPORTED. A mapping failure then stays a plain -EIO, and nothing depends on the DMA layer's return value.

Quoted 6 lines

xprtrdma can be built as a module, though, and pci_p2pdma_state() is an inline wrapper around __pci_p2pdma_update_state(), which isn't exported. I see two ways to handle that: export __pci_p2pdma_update_state() as is, or add a small exported helper in p2pdma.c that returns the map type for a page and a device, e.g. pci_p2pdma_page_map_type(). Which would you prefer?

This isn't my decision to make, but my understanding is that these functions should not be exported. They are intended for use by subsystem core code, which should export the processed results to its local callers.

Thanks

Quoted 4 lines

Thanks,
Praan

#12 lore raw

RFC PATCH 5/8 nfs: tag READ/WRITE RPCs carrying P2PDMA pages

In reply to Pranjal Shrivastava

A transport must know when an RPC's payload pages are P2PDMA memory, so it can move them by DMA or refuse the RPC.

Check each page as nfs_generic_pgio() builds the page array, and record the result in nfs_pgio_args. The READ and WRITE encoders of every NFS version then set XDRBUF_P2PDMA on the buffer holding the payload.

Additionally, avoid using READ_PLUS when the pages are P2PDMA memory.

---
 fs/nfs/nfs2xdr.c        | 4 ++++
 fs/nfs/nfs3xdr.c        | 4 ++++
 fs/nfs/nfs4proc.c       | 3 +++
 fs/nfs/nfs4xdr.c        | 4 ++++
 fs/nfs/pagelist.c       | 2 ++
 include/linux/nfs_xdr.h | 1 +
 6 files changed, 18 insertions(+)
fs/nfs/nfs2xdr.c +4 -0
index 9eff09158518..5a8f2eccd068 100644
@@ -628,6 +628,8 @@ static void nfs2_xdr_enc_readargs(struct rpc_rqst *req,
 	rpc_prepare_reply_pages(req, args->pages, args->pgbase, args->count,
 				NFS_readres_sz - NFS_pagepad_sz);
 	req->rq_rcv_buf.flags |= XDRBUF_READ;
+	if (args->p2pdma)
+		req->rq_rcv_buf.flags |= XDRBUF_P2PDMA;
 }
 
 /*
@@ -668,6 +670,8 @@ static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req,
 
 	encode_writeargs(xdr, args);
 	xdr->buf->flags |= XDRBUF_WRITE;
+	if (args->p2pdma)
+		xdr->buf->flags |= XDRBUF_P2PDMA;
 }
 
 /*
fs/nfs/nfs3xdr.c +4 -0
index e745e78faab0..e39c58883a2a 100644
@@ -946,6 +946,8 @@ static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
 				args->count, replen);
 	req->rq_rcv_buf.flags |= XDRBUF_READ;
+	if (args->p2pdma)
+		req->rq_rcv_buf.flags |= XDRBUF_P2PDMA;
 }
 
 /*
@@ -988,6 +990,8 @@ static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
 
 	encode_write3args(xdr, args);
 	xdr->buf->flags |= XDRBUF_WRITE;
+	if (args->p2pdma)
+		xdr->buf->flags |= XDRBUF_P2PDMA;
 }
 
 /*
fs/nfs/nfs4proc.c +3 -0
index beb659744760..443079f5adc9 100644
@@ -5721,6 +5721,9 @@ static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
 static bool nfs42_read_plus_support(struct nfs_pgio_header *hdr,
 				    struct rpc_message *msg)
 {
+	/* P2PDMA payloads move only by DMA */
+	if (hdr->args.p2pdma)
+		return false;
 	/* Note: We don't use READ_PLUS with pNFS yet */
 	if (nfs_server_capable(hdr->inode, NFS_CAP_READ_PLUS) && !hdr->ds_clp) {
 		msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS];
fs/nfs/nfs4xdr.c +4 -0
index 8b3d96b4a0f0..04765b56de28 100644
@@ -2621,6 +2621,8 @@ static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
 				args->count, hdr.replen - pagepad_maxsz);
 	req->rq_rcv_buf.flags |= XDRBUF_READ;
+	if (args->p2pdma)
+		req->rq_rcv_buf.flags |= XDRBUF_P2PDMA;
 	encode_nops(&hdr);
 }
 
@@ -2686,6 +2688,8 @@ static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
 	encode_putfh(xdr, args->fh, &hdr);
 	encode_write(xdr, args, &hdr);
 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
+	if (args->p2pdma)
+		req->rq_snd_buf.flags |= XDRBUF_P2PDMA;
 	if (args->bitmask)
 		encode_getfattr(xdr, args->bitmask, &hdr);
 	encode_nops(&hdr);
fs/nfs/pagelist.c +2 -0
index 71f0ce2bc4ea..3ec4e1e5fe1f 100644
@@ -970,6 +970,8 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
 				if (pageused > pagecount)
 					goto full;
 				*pages++ = last_page = page;
+				if (is_pci_p2pdma_page(page))
+					hdr->args.p2pdma = true;
 			}
 		}
 	}
include/linux/nfs_xdr.h +1 -0
index c0e29b4dfa62..85cdee107559 100644
@@ -685,6 +685,7 @@ struct nfs_pgio_args {
 	__u32			count;
 	unsigned int		pgbase;
 	struct page **		pages;
+	bool			p2pdma;		/* pages include P2PDMA memory */
 	union {
 		unsigned int		replen;			/* used by read */
 		struct {
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#13 lore raw

Re: [RFC PATCH v1 5/8] nfs: tag READ/WRITE RPCs carrying P2PDMA pages

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

A transport must know when an RPC's payload pages are P2PDMA memory, so it can move them by DMA or refuse the RPC.

Check each page as nfs_generic_pgio() builds the page array, and record the result in nfs_pgio_args. The READ and WRITE encoders of every NFS version then set XDRBUF_P2PDMA on the buffer holding the payload.

Additionally, avoid using READ_PLUS when the pages are P2PDMA memory.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#14 lore raw

Re: [RFC PATCH v1 5/8] nfs: tag READ/WRITE RPCs carrying P2PDMA pages

In reply to Pranjal Shrivastava
Quoted 19 lines · Pranjal Shrivastava

A transport must know when an RPC's payload pages are P2PDMA memory, so it can move them by DMA or refuse the RPC.

Check each page as nfs_generic_pgio() builds the page array, and record the result in nfs_pgio_args. The READ and WRITE encoders of every NFS version then set XDRBUF_P2PDMA on the buffer holding the payload.

Additionally, avoid using READ_PLUS when the pages are P2PDMA memory.

---
 fs/nfs/nfs2xdr.c        | 4 ++++
 fs/nfs/nfs3xdr.c        | 4 ++++
 fs/nfs/nfs4proc.c       | 3 +++
 fs/nfs/nfs4xdr.c        | 4 ++++
 fs/nfs/pagelist.c       | 2 ++
 include/linux/nfs_xdr.h | 1 +
 6 files changed, 18 insertions(+)

<...>

fs/nfs/pagelist.c int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, · line 974

Quoted 7 lines

+++ b/fs/nfs/pagelist.c

fs/nfs/pagelist.c +2 -0
@@ -970,6 +970,8 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
 				if (pageused > pagecount)
 					goto full;
 				*pages++ = last_page = page;
+				if (is_pci_p2pdma_page(page))
+					hdr->args.p2pdma = true;

Should we allow wider use of is_pci_p2pdma_page()? Does NFS require struct page?

Thanks

#15 lore raw

Re: [RFC PATCH v1 5/8] nfs: tag READ/WRITE RPCs carrying P2PDMA pages

Quoted 23 lines · Leon Romanovsky
Quoted 19 lines · Pranjal Shrivastava

A transport must know when an RPC's payload pages are P2PDMA memory, so it can move them by DMA or refuse the RPC.

Check each page as nfs_generic_pgio() builds the page array, and record the result in nfs_pgio_args. The READ and WRITE encoders of every NFS version then set XDRBUF_P2PDMA on the buffer holding the payload.

Additionally, avoid using READ_PLUS when the pages are P2PDMA memory.

---
 fs/nfs/nfs2xdr.c        | 4 ++++
 fs/nfs/nfs3xdr.c        | 4 ++++
 fs/nfs/nfs4proc.c       | 3 +++
 fs/nfs/nfs4xdr.c        | 4 ++++
 fs/nfs/pagelist.c       | 2 ++
 include/linux/nfs_xdr.h | 1 +
 6 files changed, 18 insertions(+)

<...>

Quoted 11 lines

fs/nfs/pagelist.c int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, · line 974

Quoted 7 lines

+++ b/fs/nfs/pagelist.c

fs/nfs/pagelist.c +2 -0
@@ -970,6 +970,8 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
 				if (pageused > pagecount)
 					goto full;
 				*pages++ = last_page = page;
+				if (is_pci_p2pdma_page(page))
+					hdr->args.p2pdma = true;

Should we allow wider use of is_pci_p2pdma_page()? Does NFS require struct page?

Hi Leon,

Yes. NFS O_DIRECT is page based today, and the Direct I/O series [1] just moved it from get_page() references to FOLL_PIN pins through iov_iter_extract_pages(), which is what DMA into user pages requires.

This series lets P2PDMA pages through the existing path, and is_pci_p2pdma_page() is how NFS tells which RPCs carry them, the same way the block layer does for bios.

I'm aware of Pavel's dma-buf I/O work [2], which Jens has queued for 7.4. The hook is a file operation, but the only implementation so far is the raw block device on NVMe, where the block driver owns the dma-buf mapping. It's also exposed through io_uring registered buffers, while this series serves plain O_DIRECT on user buffers.

Since NFS isn't block based & its I/O goes via SUNRPC to the transport, taking a dma-buf map instead of pages would mean reworking the NFS I/O path end to end, which is a large + separate effort that I'm happy to look into after this series.

Thanks,
Praan

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

#16 lore raw

RFC PATCH 6/8 nfs: refuse P2PDMA pages with krb5i and krb5p

In reply to Pranjal Shrivastava

krb5i checksums and krb5p encrypts the payload via CPU accesses while the RPC is encoded, before the transport can refuse it.

Fail such READs and WRITEs with -EREMOTEIO in nfs_pgio_prepare(), before encoding. Check the task's RPC client, which for a WRITE may be the krb5i client that SP4_MACH_CRED swaps in.

---
 fs/nfs/pagelist.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/nfs/pagelist.c +8 -0
index 3ec4e1e5fe1f..ec535ed3051d 100644
@@ -771,6 +771,14 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)
 {
 	struct nfs_pgio_header *hdr = calldata;
 	int err;
+
+	/* P2PDMA payloads move only by DMA */
+	if (hdr->args.p2pdma &&
+	    test_bit(RPCAUTH_AUTH_DATATOUCH,
+		     &task->tk_client->cl_auth->au_flags)) {
+		rpc_exit(task, -EREMOTEIO);
+		return;
+	}
 	err = NFS_PROTO(hdr->inode)->pgio_rpc_prepare(task, hdr);
 	if (err)
 		rpc_exit(task, err);
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#17 lore raw

Re: [RFC PATCH v1 6/8] nfs: refuse P2PDMA pages with krb5i and krb5p

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

krb5i checksums and krb5p encrypts the payload via CPU accesses while the RPC is encoded, before the transport can refuse it.

Fail such READs and WRITEs with -EREMOTEIO in nfs_pgio_prepare(), before encoding. Check the task's RPC client, which for a WRITE may be the krb5i client that SP4_MACH_CRED swaps in.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#18 lore raw

RFC PATCH 7/8 nfs: allow LOCALIO for P2PDMA pages only as aligned direct I/O

In reply to Pranjal Shrivastava

LOCALIO hands READs and WRITEs to the local filesystem, which can take P2PDMA pages only if its disk can DMA to them. Use LOCALIO for such I/O only if the filesystem's block device supports P2PDMA. Otherwise send a regular READ or WRITE RPC, as if LOCALIO were off.

When the I/O is not a single DIO-aligned segment, LOCALIO falls back to buffered I/O, which copies the payload through the page cache via CPU accesses. Fail such I/O with -EINVAL instead.

---
 fs/nfs/internal.h |  8 ++++++++
 fs/nfs/localio.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 fs/nfs/pagelist.c |  3 +++
 3 files changed, 51 insertions(+)
fs/nfs/internal.h +8 -0
index d6ea41a3f9b4..9338b5e0896a 100644
@@ -476,6 +476,7 @@ extern struct nfsd_file *nfs_local_open_fh(struct nfs_client *,
 					   struct nfs_fh *,
 					   struct nfs_file_localio *,
 					   const fmode_t);
+struct nfsd_file *nfs_local_p2pdma_check(struct nfsd_file *localio);
 extern int nfs_local_doio(struct nfs_client *,
 			  struct nfsd_file *,
 			  struct nfs_pgio_header *,
@@ -495,6 +496,13 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
 {
 	return NULL;
 }
+
+static inline struct nfsd_file *
+nfs_local_p2pdma_check(struct nfsd_file *localio)
+{
+	return NULL;
+}
+
 static inline int nfs_local_doio(struct nfs_client *clp,
 				 struct nfsd_file *localio,
 				 struct nfs_pgio_header *hdr,
fs/nfs/localio.c +40 -0
index f42b6112a613..6c8f2d393c35 100644
@@ -19,6 +19,7 @@
 #include <linux/nfs_common.h>
 #include <linux/nfslocalio.h>
 #include <linux/bvec.h>
+#include <linux/blkdev.h>
 
 #include <linux/nfs.h>
 #include <linux/nfs_fs.h>
@@ -290,6 +291,22 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
 }
 EXPORT_SYMBOL_GPL(nfs_local_open_fh);
 
+/*
+ * LOCALIO moves P2PDMA pages only by DMA to and from the local disk.
+ * If that disk cannot do P2PDMA, put @localio and return NULL so the
+ * I/O is sent as a regular RPC instead.
+ */
+struct nfsd_file *nfs_local_p2pdma_check(struct nfsd_file *localio)
+{
+	struct file *file = nfs_to->nfsd_file_file(localio);
+	struct block_device *bdev = file_inode(file)->i_sb->s_bdev;
+
+	if (bdev && blk_queue_pci_p2pdma(bdev_get_queue(bdev)))
+		return localio;
+	nfs_local_file_put(localio);
+	return NULL;
+}
+
 /*
  * Ensure all page cache allocations are done from GFP_NOFS context to
  * prevent direct reclaim recursion back into NFS via nfs_writepages.
@@ -511,6 +528,17 @@ nfs_local_iters_init(struct nfs_local_kiocb *iocb, int rw)
 	iov_iter_bvec(&iocb->iters[0], rw, iocb->bvec, v, len);
 }
 
+/*
+ * P2PDMA payloads move only by DMA, never through the page cache, so the
+ * whole I/O must be a single DIO-aligned segment.
+ */
+static bool nfs_local_p2pdma_misaligned(struct nfs_local_kiocb *iocb)
+{
+	return iocb->hdr->args.p2pdma &&
+	       (atomic_read(&iocb->n_iters) != 1 ||
+		!iocb->iter_is_dio_aligned[0]);
+}
+
 static void
 nfs_local_hdr_release(struct nfs_pgio_header *hdr,
 		const struct rpc_call_ops *call_ops)
@@ -732,6 +760,12 @@ static void nfs_local_do_read(struct nfs_local_kiocb *iocb,
 	nfs_local_pgio_init(hdr, call_ops);
 	hdr->res.eof = false;
 
+	if (nfs_local_p2pdma_misaligned(iocb)) {
+		nfs_local_pgio_done(iocb, -EINVAL);
+		nfs_local_pgio_release(iocb);
+		return;
+	}
+
 	INIT_WORK(&iocb->work, nfs_local_call_read);
 	if (nfs_local_defer_io())
 		queue_work(nfslocaliod_workqueue, &iocb->work);
@@ -953,6 +987,12 @@ static void nfs_local_do_write(struct nfs_local_kiocb *iocb,
 
 	nfs_set_local_verifier(hdr->inode, hdr->res.verf, hdr->args.stable);
 
+	if (nfs_local_p2pdma_misaligned(iocb)) {
+		nfs_local_pgio_done(iocb, -EINVAL);
+		nfs_local_pgio_release(iocb);
+		return;
+	}
+
 	INIT_WORK(&iocb->work, nfs_local_call_write);
 	if (nfs_local_defer_io())
 		queue_work(nfslocaliod_workqueue, &iocb->work);
fs/nfs/pagelist.c +3 -0
index ec535ed3051d..2d1d07c460fd 100644
@@ -1023,6 +1023,9 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 					  &hdr->args.context->nfl,
 					  hdr->args.context->mode);
 
+		if (localio && hdr->args.p2pdma)
+			localio = nfs_local_p2pdma_check(localio);
+
 		if (NFS_SERVER(hdr->inode)->nfs_client->cl_minorversion)
 			task_flags = RPC_TASK_MOVEABLE;
 		ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode),
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#19 lore raw

Re: [RFC PATCH v1 7/8] nfs: allow LOCALIO for P2PDMA pages only as aligned direct I/O

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mm: memory and refcount leak in nfs_local_doio() on initialization failure --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: memory and refcount leak in nfs_local_doio() on initialization failure --

commit 9173ddb2cde9be449dc0867c1db4182cfbf16690
Author: Pranjal Shrivastava <[email protected]>

nfs: allow LOCALIO for P2PDMA pages only as aligned direct I/O

LOCALIO hands READs and WRITEs to the local filesystem, which can take P2PDMA pages only if its disk can DMA to them. Use LOCALIO for such I/O only if the filesystem's block device supports P2PDMA. Otherwise send a regular READ or WRITE RPC, as if LOCALIO were off.

[ ... ]

Quoted 14 lines
fs/nfs/pagelist.c +3 -0
index ec535ed3051d4..2d1d07c460fd4 100644
@@ -1023,6 +1023,9 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 					  &hdr->args.context->nfl,
 					  hdr->args.context->mode);
 
+		if (localio && hdr->args.p2pdma)
+			localio = nfs_local_p2pdma_check(localio);
+
 		if (NFS_SERVER(hdr->inode)->nfs_client->cl_minorversion)
 			task_flags = RPC_TASK_MOVEABLE;
 		ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode),

fs/nfs/pagelist.c

Quoted 7 lines
fs/nfs/pagelist.c +0 -0
 					hdr,
 					hdr->cred,
 					NFS_PROTO(hdr->inode),
 					desc->pg_rpc_callops,
 					desc->pg_ioflags,
 					RPC_TASK_CRED_NOREF | task_flags,
 					localio);

[Severity: High]
Does this code leak the localio reference and the nfs_pgio_header on initialization failure?

The localio reference is created here and passed down. On error return from nfs_initiate_pgio() -> nfs_local_doio(), this caller does not drop the reference, nor does it have access to the requests bound to the leaked hdr.

If nfs_local_iocb_init() fails (e.g. -ENOMEM) or !hdr->args.count evaluates to true, nfs_local_doio() returns early:

fs/nfs/localio.c:nfs_local_doio() {
    ...
	if (!hdr->args.count)
		return 0;

	iocb = nfs_local_iocb_init(hdr, localio);
	if (IS_ERR(iocb))
		return PTR_ERR(iocb);
    ...
}

In these early return paths, it looks like the nfsd_file reference (localio) is leaked because nfs_local_file_put(localio) is not called.

Furthermore, call_ops->rpc_release(hdr) is never invoked. Because the requests (nfs_page structs) were already moved to hdr->pages in the caller (nfs_generic_pgio), the nfs_pgio_header and all attached pages seem to be permanently leaked, potentially resulting in hung processes waiting on page writeback/read and memory depletion.

By comparison, nfs_local_commit() correctly invokes nfs_local_release_commit_data() to clean up on its allocation failure.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#20 lore raw

RFC PATCH 8/8 nfs: allow P2PDMA pages for O_DIRECT on RDMA mounts

In reply to Pranjal Shrivastava

Pass ITER_ALLOW_P2PDMA when extracting O_DIRECT pages on mounts that use the RDMA transport and not pNFS. The RDMA transport moves such pages only by DMA, and fails the RPC with -EREMOTEIO if the device cannot reach them.

On other mounts, extracting P2PDMA pages still fails with -EREMOTEIO.

---
 fs/nfs/direct.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfs/direct.c +9 -1
index a3c6e8f4ea06..dbeb4f8274e3 100644
@@ -157,14 +157,22 @@ static ssize_t nfs_direct_extract_pages(struct nfs_direct_req *dreq,
 					size_t size, loff_t *pos,
 					struct list_head *list)
 {
+	struct nfs_server *server = NFS_SERVER(dreq->inode);
 	bool pinned = iov_iter_extract_will_pin(iter);
+	iov_iter_extraction_t flags = 0;
 	struct page **pagevec = NULL;
 	ssize_t result, bytes = 0;
 	int err = 0;
 	unsigned int npages, i;
 	size_t pgbase;
 
-	result = iov_iter_extract_pages(iter, &pagevec, size, ~0U, 0, &pgbase);
+	/* Allow P2PDMA pages only on RDMA mounts that do not use pNFS */
+	if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA &&
+	    !pnfs_enabled_sb(server))
+		flags = ITER_ALLOW_P2PDMA;
+
+	result = iov_iter_extract_pages(iter, &pagevec, size, ~0U, flags,
+					&pgbase);
 	if (result <= 0)
 		return result;
 
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#21 lore raw

Re: [RFC PATCH v1 8/8] nfs: allow P2PDMA pages for O_DIRECT on RDMA mounts

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] nfs: build failure when CONFIG_NFS_V4 is disabled due to missing pnfs_enabled_sb() stub --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] nfs: build failure when CONFIG_NFS_V4 is disabled due to missing pnfs_enabled_sb() stub --

commit e7be3531eda417e46246d357bf5c813741ed9450
Author: Pranjal Shrivastava <[email protected]>

nfs: allow P2PDMA pages for O_DIRECT on RDMA mounts

This commit passes ITER_ALLOW_P2PDMA when extracting O_DIRECT pages on mounts that use the RDMA transport and not pNFS. The RDMA transport moves such pages only by DMA, and fails the RPC with -EREMOTEIO if the device cannot reach them.

Quoted 5 lines
fs/nfs/direct.c +0 -0
index a3c6e8f4ea06a..dbeb4f8274e3a 100644
@@ -157,14 +157,22 @@ static ssize_t nfs_direct_extract_pages(struct nfs_direct_req *dreq,

[ ... ]

fs/nfs/direct.c static ssize_t nfs_direct_extract_pages(struct nfs_direct_req *dreq, · line 172

Quoted 8 lines
fs/nfs/direct.c +4 -1
 	unsigned int npages, i;
 	size_t pgbase;
 
-	result = iov_iter_extract_pages(iter, &pagevec, size, ~0U, 0, &pgbase);
+	/* Allow P2PDMA pages only on RDMA mounts that do not use pNFS */
+	if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA &&
+	    !pnfs_enabled_sb(server))
+		flags = ITER_ALLOW_P2PDMA;

[Severity: Low]
Will this cause a build failure when CONFIG_NFS_V4 is disabled?

The file fs/nfs/direct.c is compiled unconditionally for all NFS versions via CONFIG_NFS_FS. However, pnfs_enabled_sb() is defined in fs/nfs/pnfs.h exclusively inside an #if IS_ENABLED(CONFIG_NFS_V4) block:

fs/nfs/pnfs.h:pnfs_enabled_sb() {
	return nfss->pnfs_curr_ld != NULL;
}

Since there is no fallback provided in the #else block for configurations without NFSv4, it seems any kernel configuration with CONFIG_NFS_FS=y and CONFIG_NFS_V4=n might fail to build with an implicit function declaration.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#22 lore raw

Re: [RFC PATCH v1 8/8] nfs: allow P2PDMA pages for O_DIRECT on RDMA mounts

In reply to Pranjal Shrivastava
kernel test robot noticed the following build errors:

Hi Pranjal,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on next-20261006]
[cannot apply to linux-review/Pranjal-Shrivastava/nfs-make-nfs_page-pin-aware/20260814-143251 trondmy-nfs/linux-next v7.3-rc6 v7.3-rc5 v7.3-rc4 linus/master v7.3-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pranjal-Shrivastava/sunrpc-introduce-XDRBUF_P2PDMA-flag/20261006-233241
base:   next-20261006
patch link:    https://lore.kernel.org/r/20261006233248.705086-9-praan%40google.com
patch subject: [RFC PATCH v1 8/8] nfs: allow P2PDMA pages for O_DIRECT on RDMA mounts
config: nios2-defconfig (https://download.01.org/0day-ci/archive/20261010/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261010/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

fs/nfs/direct.c: In function 'nfs_direct_extract_pages':

>> fs/nfs/direct.c:171:14: error: implicit declaration of function 'pnfs_enabled_sb' [-Werror=implicit-function-declaration]

171 | !pnfs_enabled_sb(server))
| ^~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

vim +/pnfs_enabled_sb +171 fs/nfs/direct.c

154
155 static ssize_t nfs_direct_extract_pages(struct nfs_direct_req *dreq,
156 struct iov_iter *iter,
157 size_t size, loff_t *pos,
158 struct list_head *list)
159 {
160 struct nfs_server *server = NFS_SERVER(dreq->inode);
161 bool pinned = iov_iter_extract_will_pin(iter);
162 iov_iter_extraction_t flags = 0;
163 struct page **pagevec = NULL;
164 ssize_t result, bytes = 0;
165 int err = 0;
166 unsigned int npages, i;
167 size_t pgbase;
168
169 /* Allow P2PDMA pages only on RDMA mounts that do not use pNFS */
170 if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA &&

 > 171		    !pnfs_enabled_sb(server))

172 flags = ITER_ALLOW_P2PDMA;
173
174 result = iov_iter_extract_pages(iter, &pagevec, size, ~0U, flags,
175 &pgbase);
176 if (result <= 0)
177 return result;
178
179 npages = (result + pgbase + PAGE_SIZE - 1) >> PAGE_SHIFT;
180 for (i = 0; i < npages; i++) {
181 struct nfs_page *req;
182 unsigned int req_len = min_t(size_t, result - bytes, PAGE_SIZE - pgbase);
183
184 req = nfs_page_create_from_page(dreq->ctx, pagevec[i],
185 pinned, pgbase, *pos,
186 req_len);
187 if (IS_ERR(req)) {
188 err = PTR_ERR(req);
189 break;
190 }
191
192 list_add_tail(&req->wb_list, list);
193 pgbase = 0;
194 bytes += req_len;
195 *pos += req_len;
196 }
197
198 if (i < npages) {
199 iov_iter_revert(iter, result - bytes);
200 nfs_direct_release_pages(pagevec + i, npages - i, pinned);
201 }
202
203 kvfree(pagevec);
204 return bytes ? bytes : err;
205 }
206

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

maintainer
#23 lore raw
In reply to Pranjal Shrivastava
Quoted 3 lines · Pranjal Shrivastava

Enable NFS O_DIRECT to and from PCI peer-to-peer DMA (P2PDMA) memory on RDMA mounts. This replaces the initial RFC [1] and builds on the Direct I/O modernization series [2].

Hi Praan,

Good to see this moving.

Quoted 7 lines

6. pNFS: excluded for now. Route P2PDMA I/O through the MDS, or let each layout driver opt in?

Known issue: the pNFS check happens at extraction. If a mount gains pNFS afterwards (e.g. after migration), a rescheduled WRITE could reach a layout driver. I plan to decide once per O_DIRECT call and force the MDS path when P2PDMA pages are allowed.

I think we need to have a path to supporting DS I/O with P2PDMA.

The deployment sites that want P2PDMA O_DIRECT are the same sites running flexfiles, and flexfiles with a co-located DS is where LOCALIO actually offers quite a benefit. So for question 6 I'd say:
layout driver opt-in, flexfiles first, and the flexfiles LOCALIO path is part of that.

Although it is fine for a prototype, forcing the MDS path will always be the slow path. Can v1 be designed so the follow-on is additive? As posted it might not be. The P2PDMA refusals sit in the MDS-only pgio path and at page extraction, and the decision is made once and never revisited where the RPC is built.

- The krb5i/krb5p refusal is in nfs_pgio_prepare(). Flexfiles and filelayout install their own rpc_call_prepare, so a DS RPC never sees it and gets as far as call_encode, where gss_wrap() encrypts device memory in place before xprtrdma has a chance to refuse.

- ff_layout_read_pagelist() and ff_layout_write_pagelist() open an nfsd_file through ff_local_open_fh() without going through nfs_local_p2pdma_check().

If the auth refusal lives in the RPC client (any XDRBUF_P2PDMA buffer under an RPCAUTH_AUTH_DATATOUCH flavor) and the rest lives in the transport, then every RPC gets checked no matter who built it, and enabling flexfiles later is a small series on top instead of reworking already-merged code.

Quoted 4 lines

1. Layering: "RDMA transport, !pNFS" is only a hint, and each RPC re-checks its transport. Should the transport advertise P2PDMA capability up front instead? That would also allow LOCALIO on TCP mounts, which this series refuses.

Yes, please. LOCALIO never goes near the NIC, so a TCP mount has no reason to be refused. Advertise the capability and keep the per-RPC check as the backstop; that covers both cases.

Quoted 4 lines

5. LOCALIO: the check uses sb->s_bdev, which misses multi-device filesystems. Is there a better way to ask whether a file can do P2PDMA? Should misaligned I/O fall back to an RPC instead of failing with -EINVAL?

s_bdev turns out to be the smaller part of this. I went looking for ways LOCALIO could still CPU-touch the payload after the checks pass, and found these:

o ext4 and xfs both retry a direct write as buffered when the DIO path returns -ENOTBLK (fs/ext4/file.c, fs/xfs/xfs_file.c). nfs_local_p2pdma_misaligned() only guards the NFS-side split. Once the write reaches the local filesystem, that fallback copies the P2PDMA pages through the page cache and nothing reports it.

o The queue feature doesn't say anything about what the filesystem does with the data. btrfs checksums every data page on write and verifies on read unless nodatasum, so an aligned DIO on btrfs reads the pages with the CPU. Plain O_DIRECT on btrfs has the same exposure today, since bio_iov_iter_get_pages() gates on the same queue feature, so this isn't something the series introduced. But it does mean the cover's claim that every CPU-touching path refuses the I/O isn't true on btrfs.

o nfs_local_p2pdma_check() tests the queue feature but not whether the page's provider can reach the disk's DMA device. blk_dma_map_iter_start() rejects an unreachable provider with BLK_STS_INVAL. That shows up in nfs_local_read_done() as -EINVAL, gets logged as an alignment failure, and fails the I/O. There's no RPC retry at that point, so the comment's "sent as a regular RPC instead" doesn't hold here, and the same I/O would have worked over the NIC.

o sb->s_bdev, as you noted: wrong for XFS realtime, btrfs multi-device, and dm/md stacks, and wrong in both directions.

I don't see a clean fix for 1 or 2. The VFS does not have a "DIO or fail" knob, and a filesystem's data path isn't visible from the block queue. Perhaps for v1, drop LOCALIO for P2PDMA pages and bring it back under a filesystem allowlist when the flexfiles work needs it.

On alignment: yes, fall back to an RPC. Decide inside nfs_local_p2pdma_check() from offset, count and bdev_logical_block_size(), and return NULL when it doesn't line up. The RDMA path has no alignment requirement, so returning -EINVAL here makes LOCALIO strictly worse than not having it. That change also lets you delete the two duplicated error exits.

Nits:

8/8 doesn't build with CONFIG_NFS_V4=n. nfs_direct_extract_pages() calls pnfs_enabled_sb(), which is only defined inside the IS_ENABLED(CONFIG_NFS_V4) block in fs/nfs/pnfs.h, and the #else branch has no stub.

In rpcrdma_marshal_req(), a P2PDMA WRITE is forced to rpcrdma_readch without checking that head and tail fit the inline send threshold. The READ side checks rpcrdma_nonpayload_inline(); the WRITE side should too, or fall back to a Position Zero Read chunk, or return -EREMOTEIO. From code audit.

On a server returning READ data inline despite the Write chunk:
you're right that RFC 8166 section 4.3.2.2 requires the responder to use the offered chunk, so failing the RPC is correct. It does surface as a per-RPC "RPC call returned error 121" printk from call_status(), though. A tracepoint and a quiet error path would be better.

A short LOCALIO write restarts via nfs_local_pgio_restart() with offset and count advanced, and the residual can then fail the alignment check with -EINVAL after most of the bytes have landed.

The same three-line P2PDMA guard appears in xs_local, xs_udp and xs_tcp send_request. One check in xprt_request_transmit() keyed on a transport flag would cover the socket transports and anything that comes later.

Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
#24 lore raw
Quoted 8 lines · Chuck Lever
Quoted 3 lines · Pranjal Shrivastava

Enable NFS O_DIRECT to and from PCI peer-to-peer DMA (P2PDMA) memory on RDMA mounts. This replaces the initial RFC [1] and builds on the Direct I/O modernization series [2].

Hi Praan,

Good to see this moving.

Hi Chuck,

Thanks a lot for the detailed review!

Quoted 8 lines
Quoted 7 lines

6. pNFS: excluded for now. Route P2PDMA I/O through the MDS, or let each layout driver opt in?

Known issue: the pNFS check happens at extraction. If a mount gains pNFS afterwards (e.g. after migration), a rescheduled WRITE could reach a layout driver. I plan to decide once per O_DIRECT call and force the MDS path when P2PDMA pages are allowed.

Quoted 7 lines

I think we need to have a path to supporting DS I/O with P2PDMA.

The deployment sites that want P2PDMA O_DIRECT are the same sites running flexfiles, and flexfiles with a co-located DS is where LOCALIO actually offers quite a benefit. So for question 6 I'd say:
layout driver opt-in, flexfiles first, and the flexfiles LOCALIO path is part of that.

Makes sense. Layout driver opt-in it is, with flexfiles first.

Quoted 15 lines

Although it is fine for a prototype, forcing the MDS path will always be the slow path. Can v1 be designed so the follow-on is additive? As posted it might not be. The P2PDMA refusals sit in the MDS-only pgio path and at page extraction, and the decision is made once and never revisited where the RPC is built.

- The krb5i/krb5p refusal is in nfs_pgio_prepare(). Flexfiles and filelayout install their own rpc_call_prepare, so a DS RPC never sees it and gets as far as call_encode, where gss_wrap() encrypts device memory in place before xprtrdma has a chance to refuse.

- ff_layout_read_pagelist() and ff_layout_write_pagelist() open an nfsd_file through ff_local_open_fh() without going through nfs_local_p2pdma_check().

Quoted 5 lines

If the auth refusal lives in the RPC client (any XDRBUF_P2PDMA buffer under an RPCAUTH_AUTH_DATATOUCH flavor) and the rest lives in the transport, then every RPC gets checked no matter who built it, and enabling flexfiles later is a small series on top instead of reworking already-merged code.

Agreed, the checks shouldn't depend on who builds the RPC. For v2, I plan to:

- Move the krb5i/krb5p refusal into rpcauth_wrap_req_encode(), right after the encoder tags the buffer and before gss_wrap_req_integ() and gss_wrap_req_priv() touch the pages. Both of them currently turn an encoder failure into -EMSGSIZE / -EIO, so they'd pass the error up instead. The check in nfs_pgio_prepare() goes away.

- Make the LOCALIO decision in nfs_initiate_pgio(), which is where both the generic pgio path and flexfiles hand a header over to nfs_local_doio(). That covers ff_local_open_fh() as well.

- Add a layout driver flag for P2PDMA, with no driver setting it in this series, and decide once per O_DIRECT call. A layout driver that hasn't opted in gets the MDS path, which also closes the migration race. Flexfiles, including its LOCALIO path, would then be a small series on top.

Quoted 8 lines
Quoted 4 lines

1. Layering: "RDMA transport, !pNFS" is only a hint, and each RPC re-checks its transport. Should the transport advertise P2PDMA capability up front instead? That would also allow LOCALIO on TCP mounts, which this series refuses.

Yes, please. LOCALIO never goes near the NIC, so a TCP mount has no reason to be refused. Advertise the capability and keep the per-RPC check as the backstop; that covers both cases.

Ack. I'll add a transport capability that xprtrdma advertises. NFS uses it as the extraction hint, and xprt_request_transmit() refuses a tagged request on a transport without it, which also replaces the three xs_* guards you pointed out below. The per-RPC device check in xprtrdma stays as the backstop.

With LOCALIO out of v2 (below), a TCP mount still refuses P2PDMA pages for now, but the capability leaves room for LOCALIO to opt in later.

Quoted 8 lines
Quoted 4 lines

5. LOCALIO: the check uses sb->s_bdev, which misses multi-device filesystems. Is there a better way to ask whether a file can do P2PDMA? Should misaligned I/O fall back to an RPC instead of failing with -EINVAL?

s_bdev turns out to be the smaller part of this. I went looking for ways LOCALIO could still CPU-touch the payload after the checks pass, and found these:

[...]

Quoted 5 lines

I don't see a clean fix for 1 or 2. The VFS does not have a "DIO or fail" knob, and a filesystem's data path isn't visible from the block queue. Perhaps for v1, drop LOCALIO for P2PDMA pages and bring it back under a filesystem allowlist when the flexfiles work needs it.

Thanks for digging into this. I missed the -ENOTBLK fallback and the btrfs checksums, and you're right that the cover letter overclaims there.

Agreed, v2 won't use LOCALIO for P2PDMA pages; they go out as a regular RPC instead. FWIW, the XFS dma-buf direct I/O RFC [1] hits the same fallbacks and refuses them explicitly for dma-buf iterators, so that may turn out to be a cleaner way back for LOCALIO than an allowlist for P2PDMA pages.

Quoted 6 lines

On alignment: yes, fall back to an RPC. Decide inside nfs_local_p2pdma_check() from offset, count and bdev_logical_block_size(), and return NULL when it doesn't line up. The RDMA path has no alignment requirement, so returning -EINVAL here makes LOCALIO strictly worse than not having it. That change also lets you delete the two duplicated error exits.

Makes sense. I'll do that when LOCALIO comes back, along with the short write restart you pointed out below.

Quoted 6 lines

Nits:

8/8 doesn't build with CONFIG_NFS_V4=n. nfs_direct_extract_pages() calls pnfs_enabled_sb(), which is only defined inside the IS_ENABLED(CONFIG_NFS_V4) block in fs/nfs/pnfs.h, and the #else branch has no stub.

Oops, thanks. Will fix.

Quoted 5 lines

In rpcrdma_marshal_req(), a P2PDMA WRITE is forced to rpcrdma_readch without checking that head and tail fit the inline send threshold. The READ side checks rpcrdma_nonpayload_inline(); the WRITE side should too, or fall back to a Position Zero Read chunk, or return -EREMOTEIO. From code audit.

Agreed. I'll check head and tail against the inline send threshold and return -EREMOTEIO when they don't fit, same as the READ side. The non-payload part of an NFS WRITE is small, so a Position Zero Read chunk doesn't seem worth it for now.

Quoted 6 lines

On a server returning READ data inline despite the Write chunk:
you're right that RFC 8166 section 4.3.2.2 requires the responder to use the offered chunk, so failing the RPC is correct. It does surface as a per-RPC "RPC call returned error 121" printk from call_status(), though. A tracepoint and a quiet error path would be better.

Ack. I'll add a tracepoint in rpcrdma_decode_msg() and keep -EREMOTEIO quiet in call_status().

Quoted 3 lines

A short LOCALIO write restarts via nfs_local_pgio_restart() with offset and count advanced, and the residual can then fail the alignment check with -EINVAL after most of the bytes have landed.

Good catch. This goes away with LOCALIO in v2, and I'll keep it in mind for when it comes back.

Quoted 4 lines

The same three-line P2PDMA guard appears in xs_local, xs_udp and xs_tcp send_request. One check in xprt_request_transmit() keyed on a transport flag would cover the socket transports and anything that comes later.

Ack, that's covered by the capability above.

Thanks,
Praan

[1] https://lore.kernel.org/all/[email protected]/