Skip to contentSkip to conversation

NFS client patches for v5.1 (complete)

PATCH In review Chuck Lever 2 participants 37 messages Feb 11, 2019 – Apr 8, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover NFS client patches for v5.1 (complete)

Hi Anna-

Here's the complete series of my patches that are ready for the v5.1 merge window. All of them have been previously posted for review. There are four main sets:

- the first three are RPC-over-RDMA-related fixes
- the next seven are observability improvements
- the next eight overhaul the RPC auth layer to use xdr_stream
- the last five reduce the size of RPC receive buffers

---

Chuck Lever (23):
xprtrdma: Fix sparse warnings
xprtrdma: Check inline size before providing a Write chunk
xprtrdma: Reduce the doorbell rate (Receive)
SUNRPC: Display symbolic flag names in RPC trace events
SUNRPC: Add xdr_stream::rqst field
SUNRPC: Add XDR overflow trace event
SUNRPC: Add trace event that reports reply page vector alignment
NFS: Remove print_overflow_msg()
NFS: Add trace events to report non-zero NFS status codes
SUNRPC: Remove some dprintk() call sites from auth functions
SUNRPC: Remove rpc_xprt::tsh_size
SUNRPC: Add build option to disable support for insecure enctypes
SUNRPC: Use struct xdr_stream when constructing RPC Call header
SUNRPC: Clean up rpc_verify_header()
SUNRPC: Use struct xdr_stream when decoding RPC Reply header
SUNRPC: Introduce trace points in rpc_auth_gss.ko
SUNRPC: Remove xdr_buf_trim()
SUNRPC: Add SPDX IDs to some net/sunrpc/auth_gss/ files
SUNRPC: Introduce rpc_prepare_reply_pages()
NFS: Account for XDR pad of buf->pages
SUNRPC: Make AUTH_SYS and AUTH_NULL set au_verfsize
SUNRPC: Add rpc_auth::au_ralign field
SUNRPC: Use au_rslack when computing reply buffer size

 fs/lockd/clnt4xdr.c                        |   14 -
 fs/lockd/clntxdr.c                         |   14 -
 fs/nfs/callback_xdr.c                      |   64 +--
 fs/nfs/flexfilelayout/flexfilelayout.c     |    2 
 fs/nfs/nfs2xdr.c                           |  124 ++----
 fs/nfs/nfs3xdr.c                           |  209 +++--------
 fs/nfs/nfs42xdr.c                          |   21 -
 fs/nfs/nfs4trace.h                         |   25 +
 fs/nfs/nfs4xdr.c                           |  529 ++++++++-------------------
 fs/nfs/nfstrace.c                          |    1 
 fs/nfs/nfstrace.h                          |   85 ++++
 fs/nfsd/nfs4callback.c                     |   13 -
 include/linux/sunrpc/auth.h                |   44 +-
 include/linux/sunrpc/clnt.h                |    3 
 include/linux/sunrpc/gss_krb5_enctypes.h   |   42 ++
 include/linux/sunrpc/xdr.h                 |   23 +
 include/linux/sunrpc/xprt.h                |    7 
 include/trace/events/rpcgss.h              |  361 ++++++++++++++++++
 include/trace/events/rpcrdma.h             |   12 +
 include/trace/events/sunrpc.h              |  361 ++++++++++++++++++
 net/sunrpc/Kconfig                         |   16 +
 net/sunrpc/auth.c                          |  136 ++++---
 net/sunrpc/auth_gss/Makefile               |    2 
 net/sunrpc/auth_gss/auth_gss.c             |  551 ++++++++++++++--------------
 net/sunrpc/auth_gss/gss_krb5_mech.c        |   29 -
 net/sunrpc/auth_gss/gss_krb5_wrap.c        |    8 
 net/sunrpc/auth_gss/gss_mech_switch.c      |   27 -
 net/sunrpc/auth_gss/gss_rpc_upcall.c       |   15 -
 net/sunrpc/auth_gss/gss_rpc_upcall.h       |   16 -
 net/sunrpc/auth_gss/gss_rpc_xdr.c          |   15 -
 net/sunrpc/auth_gss/gss_rpc_xdr.h          |   17 -
 net/sunrpc/auth_gss/svcauth_gss.c          |    3 
 net/sunrpc/auth_gss/trace.c                |   11 +
 net/sunrpc/auth_null.c                     |   56 ++-
 net/sunrpc/auth_unix.c                     |  120 ++++--
 net/sunrpc/clnt.c                          |  390 ++++++++++----------
 net/sunrpc/svc.c                           |   19 -
 net/sunrpc/xdr.c                           |  121 +++---
 net/sunrpc/xprt.c                          |   10 -
 net/sunrpc/xprtrdma/backchannel.c          |    2 
 net/sunrpc/xprtrdma/frwr_ops.c             |    4 
 net/sunrpc/xprtrdma/rpc_rdma.c             |   22 +
 net/sunrpc/xprtrdma/svc_rdma_backchannel.c |    1 
 net/sunrpc/xprtrdma/transport.c            |    1 
 net/sunrpc/xprtrdma/verbs.c                |    2 
 net/sunrpc/xprtrdma/xprt_rdma.h            |   12 +
 net/sunrpc/xprtsock.c                      |   91 +++--
 47 files changed, 2071 insertions(+), 1580 deletions(-)
 create mode 100644 include/trace/events/rpcgss.h
 create mode 100644 net/sunrpc/auth_gss/trace.c

--
Chuck Lever

#1 lore raw

PATCH 1/23 xprtrdma: Fix sparse warnings

linux/net/sunrpc/xprtrdma/rpc_rdma.c:375:63: warning: incorrect type in argument 5 (different base types)
linux/net/sunrpc/xprtrdma/rpc_rdma.c:375:63: expected unsigned int [usertype] xid
linux/net/sunrpc/xprtrdma/rpc_rdma.c:375:63: got restricted __be32 [usertype] rq_xid
linux/net/sunrpc/xprtrdma/rpc_rdma.c:432:62: warning: incorrect type in argument 5 (different base types)
linux/net/sunrpc/xprtrdma/rpc_rdma.c:432:62: expected unsigned int [usertype] xid
linux/net/sunrpc/xprtrdma/rpc_rdma.c:432:62: got restricted __be32 [usertype] rq_xid
linux/net/sunrpc/xprtrdma/rpc_rdma.c:489:62: warning: incorrect type in argument 5 (different base types)
linux/net/sunrpc/xprtrdma/rpc_rdma.c:489:62: expected unsigned int [usertype] xid
linux/net/sunrpc/xprtrdma/rpc_rdma.c:489:62: got restricted __be32 [usertype] rq_xid

Fixes 0a93fbcb16e6 ("xprtrdma: Plant XID in on-the-wire RDMA ... ")
---
 net/sunrpc/xprtrdma/frwr_ops.c  |    4 ++--
 net/sunrpc/xprtrdma/xprt_rdma.h |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
net/sunrpc/xprtrdma/frwr_ops.c +2 -2
index 6a56105..52cb6c1 100644
@@ -391,7 +391,7 @@ size_t frwr_maxpages(struct rpcrdma_xprt *r_xprt)
  */
 struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
 				struct rpcrdma_mr_seg *seg,
-				int nsegs, bool writing, u32 xid,
+				int nsegs, bool writing, __be32 xid,
 				struct rpcrdma_mr **out)
 {
 	struct rpcrdma_ia *ia = &r_xprt->rx_ia;
@@ -446,7 +446,7 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
 		goto out_mapmr_err;
 
 	ibmr->iova &= 0x00000000ffffffff;
-	ibmr->iova |= ((u64)cpu_to_be32(xid)) << 32;
+	ibmr->iova |= ((u64)be32_to_cpu(xid)) << 32;
 	key = (u8)(ibmr->rkey & 0x000000FF);
 	ib_update_fast_reg_key(ibmr, ++key);
 
net/sunrpc/xprtrdma/xprt_rdma.h +1 -1
index 5a18472..33db208 100644
@@ -577,7 +577,7 @@ int frwr_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep,
 size_t frwr_maxpages(struct rpcrdma_xprt *r_xprt);
 struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
 				struct rpcrdma_mr_seg *seg,
-				int nsegs, bool writing, u32 xid,
+				int nsegs, bool writing, __be32 xid,
 				struct rpcrdma_mr **mr);
 int frwr_send(struct rpcrdma_ia *ia, struct rpcrdma_req *req);
 void frwr_reminv(struct rpcrdma_rep *rep, struct list_head *mrs);
#2 lore raw

PATCH 2/23 xprtrdma: Check inline size before providing a Write chunk

In reply to Chuck Lever

In very rare cases, an NFS READ operation might predict that the non-payload part of the RPC Call is large. For instance, an NFSv4 COMPOUND with a large GETATTR result, in combination with a large Kerberos credential, could push the non-payload part to be several kilobytes.

If the non-payload part is larger than the connection's inline threshold, the client is required to provision a Reply chunk. The current Linux client does not check for this case. There are two obvious ways to handle it:

a. Provision a Write chunk for the payload and a Reply chunk for
the non-payload part

b. Provision a Reply chunk for the whole RPC Reply

Some testing at a recent NFS bake-a-thon showed that servers can mostly handle a. but there are some corner cases that do not work yet. b. already works (it has to, to handle krb5i/p), but could be somewhat less efficient. However, I expect this scenario to be very rare -- no-one has reported a problem yet.

So I'm going to implement b. Sometime later I will provide some patches to help make b. a little more efficient by more carefully choosing the Reply chunk's segment sizes to ensure the payload is optimally aligned.

---
 net/sunrpc/xprtrdma/rpc_rdma.c |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/rpc_rdma.c +17 -1
index d18614e..7774aee 100644
@@ -164,6 +164,21 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
 	return rqst->rq_rcv_buf.buflen <= ia->ri_max_inline_read;
 }
 
+/* The client is required to provide a Reply chunk if the maximum
+ * size of the non-payload part of the RPC Reply is larger than
+ * the inline threshold.
+ */
+static bool
+rpcrdma_nonpayload_inline(const struct rpcrdma_xprt *r_xprt,
+			  const struct rpc_rqst *rqst)
+{
+	const struct xdr_buf *buf = &rqst->rq_rcv_buf;
+	const struct rpcrdma_ia *ia = &r_xprt->rx_ia;
+
+	return buf->head[0].iov_len + buf->tail[0].iov_len <
+		ia->ri_max_inline_read;
+}
+
 /* Split @vec on page boundaries into SGEs. FMR registers pages, not
  * a byte range. Other modes coalesce these SGEs into a single MR
  * when they can.
@@ -762,7 +777,8 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
 	 */
 	if (rpcrdma_results_inline(r_xprt, rqst))
 		wtype = rpcrdma_noch;
-	else if (ddp_allowed && rqst->rq_rcv_buf.flags & XDRBUF_READ)
+	else if ((ddp_allowed && rqst->rq_rcv_buf.flags & XDRBUF_READ) &&
+		 rpcrdma_nonpayload_inline(r_xprt, rqst))
 		wtype = rpcrdma_writech;
 	else
 		wtype = rpcrdma_replych;
#3 lore raw

PATCH 3/23 xprtrdma: Reduce the doorbell rate (Receive)

In reply to Chuck Lever

Post RECV WRs in batches to reduce the hardware doorbell rate per transport. This helps the RPC-over-RDMA client scale better in number of transports.

---
 net/sunrpc/xprtrdma/verbs.c     |    2 ++
 net/sunrpc/xprtrdma/xprt_rdma.h |   10 ++++++++++
 2 files changed, 12 insertions(+)
net/sunrpc/xprtrdma/verbs.c +2 -0
index 4994e75..b4e997d 100644
@@ -1480,6 +1480,8 @@ struct rpcrdma_regbuf *
 	if (ep->rep_receive_count > needed)
 		goto out;
 	needed -= ep->rep_receive_count;
+	if (!temp)
+		needed += RPCRDMA_MAX_RECV_BATCH;
 
 	count = 0;
 	wr = NULL;
net/sunrpc/xprtrdma/xprt_rdma.h +10 -0
index 33db208..10f6593 100644
@@ -205,6 +205,16 @@ struct rpcrdma_rep {
 	struct ib_recv_wr	rr_recv_wr;
 };
 
+/* To reduce the rate at which a transport invokes ib_post_recv
+ * (and thus the hardware doorbell rate), xprtrdma posts Receive
+ * WRs in batches.
+ *
+ * Setting this to zero disables Receive post batching.
+ */
+enum {
+	RPCRDMA_MAX_RECV_BATCH = 7,
+};
+
 /* struct rpcrdma_sendctx - DMA mapped SGEs to unmap after Send completes
  */
 struct rpcrdma_req;
#4 lore raw

PATCH 4/23 SUNRPC: Display symbolic flag names in RPC trace events

In reply to Chuck Lever

Human-readable flags make it easier to observe RPC scheduling decisions and other operational details.

---
 include/trace/events/sunrpc.h |   56 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 50 insertions(+), 6 deletions(-)
include/trace/events/sunrpc.h +50 -6
index 0d5d0d9..f88b0f5 100644
@@ -77,6 +77,50 @@
 		)
 );
 
+TRACE_DEFINE_ENUM(RPC_TASK_ASYNC);
+TRACE_DEFINE_ENUM(RPC_TASK_SWAPPER);
+TRACE_DEFINE_ENUM(RPC_CALL_MAJORSEEN);
+TRACE_DEFINE_ENUM(RPC_TASK_ROOTCREDS);
+TRACE_DEFINE_ENUM(RPC_TASK_DYNAMIC);
+TRACE_DEFINE_ENUM(RPC_TASK_KILLED);
+TRACE_DEFINE_ENUM(RPC_TASK_SOFT);
+TRACE_DEFINE_ENUM(RPC_TASK_SOFTCONN);
+TRACE_DEFINE_ENUM(RPC_TASK_SENT);
+TRACE_DEFINE_ENUM(RPC_TASK_TIMEOUT);
+TRACE_DEFINE_ENUM(RPC_TASK_NOCONNECT);
+TRACE_DEFINE_ENUM(RPC_TASK_NO_RETRANS_TIMEOUT);
+
+#define rpc_show_task_flags(flags)					\
+	__print_flags(flags, "|",					\
+		{ RPC_TASK_ASYNC, "ASYNC" },				\
+		{ RPC_TASK_SWAPPER, "SWAPPER" },			\
+		{ RPC_CALL_MAJORSEEN, "MAJORSEEN" },			\
+		{ RPC_TASK_ROOTCREDS, "ROOTCREDS" },			\
+		{ RPC_TASK_DYNAMIC, "DYNAMIC" },			\
+		{ RPC_TASK_KILLED, "KILLED" },				\
+		{ RPC_TASK_SOFT, "SOFT" },				\
+		{ RPC_TASK_SOFTCONN, "SOFTCONN" },			\
+		{ RPC_TASK_SENT, "SENT" },				\
+		{ RPC_TASK_TIMEOUT, "TIMEOUT" },			\
+		{ RPC_TASK_NOCONNECT, "NOCONNECT" },			\
+		{ RPC_TASK_NO_RETRANS_TIMEOUT, "NORTO" })
+
+TRACE_DEFINE_ENUM(RPC_TASK_RUNNING);
+TRACE_DEFINE_ENUM(RPC_TASK_QUEUED);
+TRACE_DEFINE_ENUM(RPC_TASK_ACTIVE);
+TRACE_DEFINE_ENUM(RPC_TASK_NEED_XMIT);
+TRACE_DEFINE_ENUM(RPC_TASK_NEED_RECV);
+TRACE_DEFINE_ENUM(RPC_TASK_MSG_PIN_WAIT);
+
+#define rpc_show_runstate(flags)					\
+	__print_flags(flags, "|",					\
+		{ (1UL << RPC_TASK_RUNNING), "RUNNING" },		\
+		{ (1UL << RPC_TASK_QUEUED), "QUEUED" },			\
+		{ (1UL << RPC_TASK_ACTIVE), "ACTIVE" },			\
+		{ (1UL << RPC_TASK_NEED_XMIT), "NEED_XMIT" },		\
+		{ (1UL << RPC_TASK_NEED_RECV), "NEED_RECV" },		\
+		{ (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" })
+
 DECLARE_EVENT_CLASS(rpc_task_running,
 
 	TP_PROTO(const struct rpc_task *task, const void *action),
@@ -102,10 +146,10 @@
 		__entry->flags = task->tk_flags;
 		),
 
-	TP_printk("task:%u@%d flags=%4.4x state=%4.4lx status=%d action=%pf",
+	TP_printk("task:%u@%d flags=%s runstate=%s status=%d action=%pf",
 		__entry->task_id, __entry->client_id,
-		__entry->flags,
-		__entry->runstate,
+		rpc_show_task_flags(__entry->flags),
+		rpc_show_runstate(__entry->runstate),
 		__entry->status,
 		__entry->action
 		)
@@ -149,10 +193,10 @@
 		__assign_str(q_name, rpc_qname(q));
 		),
 
-	TP_printk("task:%u@%d flags=%4.4x state=%4.4lx status=%d timeout=%lu queue=%s",
+	TP_printk("task:%u@%d flags=%s runstate=%s status=%d timeout=%lu queue=%s",
 		__entry->task_id, __entry->client_id,
-		__entry->flags,
-		__entry->runstate,
+		rpc_show_task_flags(__entry->flags),
+		rpc_show_runstate(__entry->runstate),
 		__entry->status,
 		__entry->timeout,
 		__get_str(q_name)
#5 lore raw

PATCH 5/23 SUNRPC: Add xdr_stream::rqst field

In reply to Chuck Lever

Having access to the controlling rpc_rqst means a trace point in the XDR code can report:

- the XID
- the task ID and client ID
- the p_name of RPC being processed

Subsequent patches will introduce such trace points.

---
 fs/nfs/callback_xdr.c                  |    5 +++--
 fs/nfs/flexfilelayout/flexfilelayout.c |    2 +-
 include/linux/sunrpc/xdr.h             |    8 ++++++--
 net/sunrpc/auth.c                      |    4 ++--
 net/sunrpc/auth_gss/auth_gss.c         |    4 ++--
 net/sunrpc/xdr.c                       |   12 +++++++++---
 net/sunrpc/xprtrdma/backchannel.c      |    2 +-
 net/sunrpc/xprtrdma/rpc_rdma.c         |    4 ++--
 8 files changed, 26 insertions(+), 15 deletions(-)
fs/nfs/callback_xdr.c +3 -2
index a87a562..bc7c176 100644
@@ -943,10 +943,11 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp)
 	};
 	unsigned int nops = 0;
 
-	xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base);
+	xdr_init_decode(&xdr_in, &rqstp->rq_arg,
+			rqstp->rq_arg.head[0].iov_base, NULL);
 
 	p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
-	xdr_init_encode(&xdr_out, &rqstp->rq_res, p);
+	xdr_init_encode(&xdr_out, &rqstp->rq_res, p, NULL);
 
 	status = decode_compound_hdr_arg(&xdr_in, &hdr_arg);
 	if (status == htonl(NFS4ERR_RESOURCE))
fs/nfs/flexfilelayout/flexfilelayout.c +1 -1
index 63abe70..32701b6 100644
@@ -2036,7 +2036,7 @@ static void ff_layout_encode_iostats_array(struct xdr_stream *xdr,
 
 	dprintk("%s: Begin\n", __func__);
 
-	xdr_init_encode(&tmp_xdr, &tmp_buf, NULL);
+	xdr_init_encode(&tmp_xdr, &tmp_buf, NULL, NULL);
 
 	ff_layout_encode_ioerr(&tmp_xdr, args, ff_args);
 	ff_layout_encode_iostats_array(&tmp_xdr, args, ff_args);
include/linux/sunrpc/xdr.h +6 -2
index 2ec1280..787939d 100644
@@ -217,6 +217,8 @@ struct xdr_stream {
 	struct kvec scratch;	/* Scratch buffer */
 	struct page **page_ptr;	/* pointer to the current page */
 	unsigned int nwords;	/* Remaining decode buffer length */
+
+	struct rpc_rqst *rqst;	/* For debugging */
 };
 
 /*
@@ -227,7 +229,8 @@ typedef void	(*kxdreproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
 typedef int	(*kxdrdproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
 		void *obj);
 
-extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
+extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf,
+			    __be32 *p, struct rpc_rqst *rqst);
 extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
 extern void xdr_commit_encode(struct xdr_stream *xdr);
 extern void xdr_truncate_encode(struct xdr_stream *xdr, size_t len);
@@ -235,7 +238,8 @@ typedef int	(*kxdrdproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
 extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
 		unsigned int base, unsigned int len);
 extern unsigned int xdr_stream_pos(const struct xdr_stream *xdr);
-extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
+extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf,
+			    __be32 *p, struct rpc_rqst *rqst);
 extern void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
 		struct page **pages, unsigned int len);
 extern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen);
net/sunrpc/auth.c +2 -2
index f3023bb..8dfab61 100644
@@ -798,7 +798,7 @@ static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct xdr_stream xdr;
 
-	xdr_init_encode(&xdr, &rqstp->rq_snd_buf, data);
+	xdr_init_encode(&xdr, &rqstp->rq_snd_buf, data, rqstp);
 	encode(rqstp, &xdr, obj);
 }
 
@@ -823,7 +823,7 @@ static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct xdr_stream xdr;
 
-	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, data);
+	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, data, rqstp);
 	return decode(rqstp, &xdr, obj);
 }
 
net/sunrpc/auth_gss/auth_gss.c +2 -2
index 1531b02..a42672e 100644
@@ -1722,7 +1722,7 @@ static void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct xdr_stream xdr;
 
-	xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p);
+	xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p, rqstp);
 	encode(rqstp, &xdr, obj);
 }
 
@@ -1998,7 +1998,7 @@ static void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct xdr_stream xdr;
 
-	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
+	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p, rqstp);
 	return decode(rqstp, &xdr, obj);
 }
 
net/sunrpc/xdr.c +9 -3
index f302c6e..345f08b 100644
@@ -483,6 +483,7 @@ unsigned int xdr_stream_pos(const struct xdr_stream *xdr)
  * @xdr: pointer to xdr_stream struct
  * @buf: pointer to XDR buffer in which to encode data
  * @p: current pointer inside XDR buffer
+ * @rqst: pointer to controlling rpc_rqst, for debugging
  *
  * Note: at the moment the RPC client only passes the length of our
  *	 scratch buffer in the xdr_buf's header kvec. Previously this
@@ -491,7 +492,8 @@ unsigned int xdr_stream_pos(const struct xdr_stream *xdr)
  *	 of the buffer length, and takes care of adjusting the kvec
  *	 length for us.
  */
-void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p)
+void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
+		     struct rpc_rqst *rqst)
 {
 	struct kvec *iov = buf->head;
 	int scratch_len = buf->buflen - buf->page_len - buf->tail[0].iov_len;
@@ -513,6 +515,7 @@ void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p)
 		buf->len += len;
 		iov->iov_len += len;
 	}
+	xdr->rqst = rqst;
 }
 EXPORT_SYMBOL_GPL(xdr_init_encode);
 
@@ -819,8 +822,10 @@ static bool xdr_set_next_buffer(struct xdr_stream *xdr)
  * @xdr: pointer to xdr_stream struct
  * @buf: pointer to XDR buffer from which to decode data
  * @p: current pointer inside XDR buffer
+ * @rqst: pointer to controlling rpc_rqst, for debugging
  */
-void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p)
+void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
+		     struct rpc_rqst *rqst)
 {
 	xdr->buf = buf;
 	xdr->scratch.iov_base = NULL;
@@ -836,6 +841,7 @@ void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p)
 		xdr->nwords -= p - xdr->p;
 		xdr->p = p;
 	}
+	xdr->rqst = rqst;
 }
 EXPORT_SYMBOL_GPL(xdr_init_decode);
 
@@ -854,7 +860,7 @@ void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
 	buf->page_len =  len;
 	buf->buflen =  len;
 	buf->len = len;
-	xdr_init_decode(xdr, buf, NULL);
+	xdr_init_decode(xdr, buf, NULL, NULL);
 }
 EXPORT_SYMBOL_GPL(xdr_init_decode_pages);
 
net/sunrpc/xprtrdma/backchannel.c +1 -1
index 0de9b3e..98c1e43 100644
@@ -123,7 +123,7 @@ static int rpcrdma_bc_marshal_reply(struct rpc_rqst *rqst)
 
 	rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0);
 	xdr_init_encode(&req->rl_stream, &req->rl_hdrbuf,
-			req->rl_rdmabuf->rg_base);
+			req->rl_rdmabuf->rg_base, rqst);
 
 	p = xdr_reserve_space(&req->rl_stream, 28);
 	if (unlikely(!p))
net/sunrpc/xprtrdma/rpc_rdma.c +2 -2
index 7774aee..6c1fb27 100644
@@ -748,7 +748,7 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
 
 	rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0);
 	xdr_init_encode(xdr, &req->rl_hdrbuf,
-			req->rl_rdmabuf->rg_base);
+			req->rl_rdmabuf->rg_base, rqst);
 
 	/* Fixed header fields */
 	ret = -EMSGSIZE;
@@ -1329,7 +1329,7 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
 
 	/* Fixed transport header fields */
 	xdr_init_decode(&rep->rr_stream, &rep->rr_hdrbuf,
-			rep->rr_hdrbuf.head[0].iov_base);
+			rep->rr_hdrbuf.head[0].iov_base, NULL);
 	p = xdr_inline_decode(&rep->rr_stream, 4 * sizeof(*p));
 	if (unlikely(!p))
 		goto out_shortreply;
#6 lore raw

PATCH 6/23 SUNRPC: Add XDR overflow trace event

In reply to Chuck Lever

This can help field troubleshooting without needing the overhead of a full network capture (ie, tcpdump).

---
 include/trace/events/sunrpc.h |   67 +++++++++++++++++++++++++++++++++++++++++
 net/sunrpc/xdr.c              |   24 ++++++++++-----
 2 files changed, 84 insertions(+), 7 deletions(-)
include/trace/events/sunrpc.h +67 -0
index f88b0f5..fbc41b8 100644
@@ -254,6 +254,73 @@
 		__entry->backlog, __entry->rtt, __entry->execute)
 );
 
+TRACE_EVENT(rpc_xdr_overflow,
+	TP_PROTO(
+		const struct xdr_stream *xdr,
+		size_t requested
+	),
+
+	TP_ARGS(xdr, requested),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(int, version)
+		__field(size_t, requested)
+		__field(const void *, end)
+		__field(const void *, p)
+		__field(const void *, head_base)
+		__field(size_t, head_len)
+		__field(const void *, tail_base)
+		__field(size_t, tail_len)
+		__field(unsigned int, page_len)
+		__field(unsigned int, len)
+		__string(progname,
+			 xdr->rqst->rq_task->tk_client->cl_program->name)
+		__string(procedure,
+			 xdr->rqst->rq_task->tk_msg.rpc_proc->p_name)
+	),
+
+	TP_fast_assign(
+		if (xdr->rqst) {
+			const struct rpc_task *task = xdr->rqst->rq_task;
+
+			__entry->task_id = task->tk_pid;
+			__entry->client_id = task->tk_client->cl_clid;
+			__assign_str(progname,
+				     task->tk_client->cl_program->name)
+			__entry->version = task->tk_client->cl_vers;
+			__assign_str(procedure, task->tk_msg.rpc_proc->p_name)
+		} else {
+			__entry->task_id = 0;
+			__entry->client_id = 0;
+			__assign_str(progname, "unknown")
+			__entry->version = 0;
+			__assign_str(procedure, "unknown")
+		}
+		__entry->requested = requested;
+		__entry->end = xdr->end;
+		__entry->p = xdr->p;
+		__entry->head_base = xdr->buf->head[0].iov_base,
+		__entry->head_len = xdr->buf->head[0].iov_len,
+		__entry->page_len = xdr->buf->page_len,
+		__entry->tail_base = xdr->buf->tail[0].iov_base,
+		__entry->tail_len = xdr->buf->tail[0].iov_len,
+		__entry->len = xdr->buf->len;
+	),
+
+	TP_printk(
+		"task:%u@%u %sv%d %s requested=%zu p=%p end=%p xdr=[%p,%zu]/%u/[%p,%zu]/%u\n",
+		__entry->task_id, __entry->client_id,
+		__get_str(progname), __entry->version, __get_str(procedure),
+		__entry->requested, __entry->p, __entry->end,
+		__entry->head_base, __entry->head_len,
+		__entry->page_len,
+		__entry->tail_base, __entry->tail_len,
+		__entry->len
+	)
+);
+
 /*
  * First define the enums in the below macros to be exported to userspace
  * via TRACE_DEFINE_ENUM().
net/sunrpc/xdr.c +17 -7
index 345f08b..6d0b615 100644
@@ -16,6 +16,7 @@
 #include <linux/sunrpc/xdr.h>
 #include <linux/sunrpc/msg_prot.h>
 #include <linux/bvec.h>
+#include <trace/events/sunrpc.h>
 
 /*
  * XDR functions for basic NFS types
@@ -554,9 +555,9 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
 	int frag1bytes, frag2bytes;
 
 	if (nbytes > PAGE_SIZE)
-		return NULL; /* Bigger buffers require special handling */
+		goto out_overflow; /* Bigger buffers require special handling */
 	if (xdr->buf->len + nbytes > xdr->buf->buflen)
-		return NULL; /* Sorry, we're totally out of space */
+		goto out_overflow; /* Sorry, we're totally out of space */
 	frag1bytes = (xdr->end - xdr->p) << 2;
 	frag2bytes = nbytes - frag1bytes;
 	if (xdr->iov)
@@ -585,6 +586,9 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
 	xdr->buf->page_len += frag2bytes;
 	xdr->buf->len += nbytes;
 	return p;
+out_overflow:
+	trace_rpc_xdr_overflow(xdr, nbytes);
+	return NULL;
 }
 
 /**
@@ -902,20 +906,23 @@ static __be32 *xdr_copy_to_scratch(struct xdr_stream *xdr, size_t nbytes)
 	size_t cplen = (char *)xdr->end - (char *)xdr->p;
 
 	if (nbytes > xdr->scratch.iov_len)
-		return NULL;
+		goto out_overflow;
 	p = __xdr_inline_decode(xdr, cplen);
 	if (p == NULL)
 		return NULL;
 	memcpy(cpdest, p, cplen);
+	if (!xdr_set_next_buffer(xdr))
+		goto out_overflow;
 	cpdest += cplen;
 	nbytes -= cplen;
-	if (!xdr_set_next_buffer(xdr))
-		return NULL;
 	p = __xdr_inline_decode(xdr, nbytes);
 	if (p == NULL)
 		return NULL;
 	memcpy(cpdest, p, nbytes);
 	return xdr->scratch.iov_base;
+out_overflow:
+	trace_rpc_xdr_overflow(xdr, nbytes);
+	return NULL;
 }
 
 /**
@@ -932,14 +939,17 @@ __be32 * xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes)
 {
 	__be32 *p;
 
-	if (nbytes == 0)
+	if (unlikely(nbytes == 0))
 		return xdr->p;
 	if (xdr->p == xdr->end && !xdr_set_next_buffer(xdr))
-		return NULL;
+		goto out_overflow;
 	p = __xdr_inline_decode(xdr, nbytes);
 	if (p != NULL)
 		return p;
 	return xdr_copy_to_scratch(xdr, nbytes);
+out_overflow:
+	trace_rpc_xdr_overflow(xdr, nbytes);
+	return NULL;
 }
 EXPORT_SYMBOL_GPL(xdr_inline_decode);
 
#7 lore raw

PATCH 7/23 SUNRPC: Add trace event that reports reply page vector alignment

In reply to Chuck Lever

We don't want READ payloads that are partially in the head iovec and in the page buffer because this requires pull-up, which can be expensive.

The NFS/RPC client tries hard to predict the size of the head iovec so that the incoming READ data payload lands only in the page vector, but it doesn't always get it right. To help diagnose such problems, add a trace point in the logic that decodes READ-like operations that reports whether pull-up is being done.

---
 include/trace/events/sunrpc.h |   59 +++++++++++++++++++++++++++++++++++++++++
 net/sunrpc/xdr.c              |   33 +++++++++++++++++++----
 2 files changed, 86 insertions(+), 6 deletions(-)
include/trace/events/sunrpc.h +59 -0
index fbc41b8..6276508 100644
@@ -321,6 +321,65 @@
 	)
 );
 
+TRACE_EVENT(rpc_xdr_alignment,
+	TP_PROTO(
+		const struct xdr_stream *xdr,
+		size_t offset,
+		unsigned int copied
+	),
+
+	TP_ARGS(xdr, offset, copied),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(int, version)
+		__field(size_t, offset)
+		__field(unsigned int, copied)
+		__field(const void *, head_base)
+		__field(size_t, head_len)
+		__field(const void *, tail_base)
+		__field(size_t, tail_len)
+		__field(unsigned int, page_len)
+		__field(unsigned int, len)
+		__string(progname,
+			 xdr->rqst->rq_task->tk_client->cl_program->name)
+		__string(procedure,
+			 xdr->rqst->rq_task->tk_msg.rpc_proc->p_name)
+	),
+
+	TP_fast_assign(
+		const struct rpc_task *task = xdr->rqst->rq_task;
+
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+		__assign_str(progname,
+			     task->tk_client->cl_program->name)
+		__entry->version = task->tk_client->cl_vers;
+		__assign_str(procedure, task->tk_msg.rpc_proc->p_name)
+
+		__entry->offset = offset;
+		__entry->copied = copied;
+		__entry->head_base = xdr->buf->head[0].iov_base,
+		__entry->head_len = xdr->buf->head[0].iov_len,
+		__entry->page_len = xdr->buf->page_len,
+		__entry->tail_base = xdr->buf->tail[0].iov_base,
+		__entry->tail_len = xdr->buf->tail[0].iov_len,
+		__entry->len = xdr->buf->len;
+	),
+
+	TP_printk(
+		"task:%u@%u %sv%d %s offset=%zu copied=%u xdr=[%p,%zu]/%u/[%p,%zu]/%u\n",
+		__entry->task_id, __entry->client_id,
+		__get_str(progname), __entry->version, __get_str(procedure),
+		__entry->offset, __entry->copied,
+		__entry->head_base, __entry->head_len,
+		__entry->page_len,
+		__entry->tail_base, __entry->tail_len,
+		__entry->len
+	)
+);
+
 /*
  * First define the enums in the below macros to be exported to userspace
  * via TRACE_DEFINE_ENUM().
net/sunrpc/xdr.c +27 -6
index 6d0b615..5f0aa53 100644
@@ -347,13 +347,15 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
  * 'len' bytes. The extra data is not lost, but is instead
  * moved into the inlined pages and/or the tail.
  */
-static void
+static unsigned int
 xdr_shrink_bufhead(struct xdr_buf *buf, size_t len)
 {
 	struct kvec *head, *tail;
 	size_t copy, offs;
 	unsigned int pglen = buf->page_len;
+	unsigned int result;
 
+	result = 0;
 	tail = buf->tail;
 	head = buf->head;
 
@@ -367,6 +369,7 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 			copy = tail->iov_len - len;
 			memmove((char *)tail->iov_base + len,
 					tail->iov_base, copy);
+			result += copy;
 		}
 		/* Copy from the inlined pages into the tail */
 		copy = len;
@@ -377,11 +380,13 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 			copy = 0;
 		else if (copy > tail->iov_len - offs)
 			copy = tail->iov_len - offs;
-		if (copy != 0)
+		if (copy != 0) {
 			_copy_from_pages((char *)tail->iov_base + offs,
 					buf->pages,
 					buf->page_base + pglen + offs - len,
 					copy);
+			result += copy;
+		}
 		/* Do we also need to copy data from the head into the tail ? */
 		if (len > pglen) {
 			offs = copy = len - pglen;
@@ -391,6 +396,7 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 					(char *)head->iov_base +
 					head->iov_len - offs,
 					copy);
+			result += copy;
 		}
 	}
 	/* Now handle pages */
@@ -406,12 +412,15 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 		_copy_to_pages(buf->pages, buf->page_base,
 				(char *)head->iov_base + head->iov_len - len,
 				copy);
+		result += copy;
 	}
 	head->iov_len -= len;
 	buf->buflen -= len;
 	/* Have we truncated the message? */
 	if (buf->len > buf->buflen)
 		buf->len = buf->buflen;
+
+	return result;
 }
 
 /**
@@ -423,14 +432,16 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
  * 'len' bytes. The extra data is not lost, but is instead
  * moved into the tail.
  */
-static void
+static unsigned int
 xdr_shrink_pagelen(struct xdr_buf *buf, size_t len)
 {
 	struct kvec *tail;
 	size_t copy;
 	unsigned int pglen = buf->page_len;
 	unsigned int tailbuf_len;
+	unsigned int result;
 
+	result = 0;
 	tail = buf->tail;
 	BUG_ON (len > pglen);
 
@@ -448,18 +459,22 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 		if (tail->iov_len > len) {
 			char *p = (char *)tail->iov_base + len;
 			memmove(p, tail->iov_base, tail->iov_len - len);
+			result += tail->iov_len - len;
 		} else
 			copy = tail->iov_len;
 		/* Copy from the inlined pages into the tail */
 		_copy_from_pages((char *)tail->iov_base,
 				buf->pages, buf->page_base + pglen - len,
 				copy);
+		result += copy;
 	}
 	buf->page_len -= len;
 	buf->buflen -= len;
 	/* Have we truncated the message? */
 	if (buf->len > buf->buflen)
 		buf->len = buf->buflen;
+
+	return result;
 }
 
 void
@@ -959,13 +974,17 @@ static unsigned int xdr_align_pages(struct xdr_stream *xdr, unsigned int len)
 	struct kvec *iov;
 	unsigned int nwords = XDR_QUADLEN(len);
 	unsigned int cur = xdr_stream_pos(xdr);
+	unsigned int copied, offset;
 
 	if (xdr->nwords == 0)
 		return 0;
+
 	/* Realign pages to current pointer position */
-	iov  = buf->head;
+	iov = buf->head;
 	if (iov->iov_len > cur) {
-		xdr_shrink_bufhead(buf, iov->iov_len - cur);
+		offset = iov->iov_len - cur;
+		copied = xdr_shrink_bufhead(buf, offset);
+		trace_rpc_xdr_alignment(xdr, offset, copied);
 		xdr->nwords = XDR_QUADLEN(buf->len - cur);
 	}
 
@@ -977,7 +996,9 @@ static unsigned int xdr_align_pages(struct xdr_stream *xdr, unsigned int len)
 		len = buf->page_len;
 	else if (nwords < xdr->nwords) {
 		/* Truncate page data and move it into the tail */
-		xdr_shrink_pagelen(buf, buf->page_len - len);
+		offset = buf->page_len - len;
+		copied = xdr_shrink_pagelen(buf, offset);
+		trace_rpc_xdr_alignment(xdr, offset, copied);
 		xdr->nwords = XDR_QUADLEN(buf->len - cur);
 	}
 	return len;
#8 lore raw

PATCH 8/23 NFS: Remove print_overflow_msg()

In reply to Chuck Lever

This issue is now captured by a trace point in the RPC client.

---
 fs/lockd/clnt4xdr.c    |   14 -
 fs/lockd/clntxdr.c     |   14 -
 fs/nfs/callback_xdr.c  |   59 +++---
 fs/nfs/nfs2xdr.c       |   84 +++------
 fs/nfs/nfs3xdr.c       |  163 +++++------------
 fs/nfs/nfs42xdr.c      |   21 +-
 fs/nfs/nfs4xdr.c       |  451 +++++++++++++-----------------------------------
 fs/nfsd/nfs4callback.c |   13 -
 8 files changed, 219 insertions(+), 600 deletions(-)
fs/lockd/clnt4xdr.c +0 -14
index 214a2fa..7df6324 100644
@@ -75,17 +75,6 @@ static void nlm4_compute_offsets(const struct nlm_lock *lock,
 }
 
 /*
- * Handle decode buffer overflows out-of-line.
- */
-static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
-{
-	dprintk("lockd: %s prematurely hit the end of our receive buffer. "
-		"Remaining buffer length is %tu words.\n",
-		func, xdr->end - xdr->p);
-}
-
-
-/*
  * Encode/decode NLMv4 basic data types
  *
  * Basic NLMv4 data types are defined in Appendix II, section 6.1.4
@@ -176,7 +165,6 @@ static int decode_cookie(struct xdr_stream *xdr,
 	dprintk("NFS: returned cookie was too long: %u\n", length);
 	return -EIO;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
@@ -236,7 +224,6 @@ static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
 			__func__, be32_to_cpup(p));
 	return -EIO;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
@@ -309,7 +296,6 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
 out:
 	return error;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
fs/lockd/clntxdr.c +0 -14
index 747b9c8..4df62f6 100644
@@ -71,17 +71,6 @@ static void nlm_compute_offsets(const struct nlm_lock *lock,
 }
 
 /*
- * Handle decode buffer overflows out-of-line.
- */
-static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
-{
-	dprintk("lockd: %s prematurely hit the end of our receive buffer. "
-		"Remaining buffer length is %tu words.\n",
-		func, xdr->end - xdr->p);
-}
-
-
-/*
  * Encode/decode NLMv3 basic data types
  *
  * Basic NLMv3 data types are not defined in an IETF standards
@@ -173,7 +162,6 @@ static int decode_cookie(struct xdr_stream *xdr,
 	dprintk("NFS: returned cookie was too long: %u\n", length);
 	return -EIO;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
@@ -231,7 +219,6 @@ static int decode_nlm_stat(struct xdr_stream *xdr,
 		__func__, be32_to_cpup(p));
 	return -EIO;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
@@ -303,7 +290,6 @@ static int decode_nlm_holder(struct xdr_stream *xdr, struct nlm_res *result)
 out:
 	return error;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
fs/nfs/callback_xdr.c +25 -34

204 lines not on this page · raw message

fs/nfs/nfs2xdr.c +24 -60

196 lines not on this page · raw message

fs/nfs/nfs3xdr.c +47 -116

386 lines not on this page · raw message

fs/nfs/nfs42xdr.c +5 -16
index 69f72ed..22b3425 100644
@@ -394,7 +394,7 @@ static int decode_write_response(struct xdr_stream *xdr,
 
 	p = xdr_inline_decode(xdr, 4);
 	if (unlikely(!p))
-		goto out_overflow;
+		return -EIO;
 	count = be32_to_cpup(p);
 	if (count > 1)
 		return -EREMOTEIO;
@@ -402,18 +402,14 @@ static int decode_write_response(struct xdr_stream *xdr,
 		status = decode_opaque_fixed(xdr, &res->stateid,
 				NFS4_STATEID_SIZE);
 		if (unlikely(status))
-			goto out_overflow;
+			return -EIO;
 	}
 	p = xdr_inline_decode(xdr, 8 + 4);
 	if (unlikely(!p))
-		goto out_overflow;
+		return -EIO;
 	p = xdr_decode_hyper(p, &res->count);
 	res->verifier.committed = be32_to_cpup(p);
 	return decode_verifier(xdr, &res->verifier.verifier);
-
-out_overflow:
-	print_overflow_msg(__func__, xdr);
-	return -EIO;
 }
 
 static int decode_copy_requirements(struct xdr_stream *xdr,
@@ -422,14 +418,11 @@ static int decode_copy_requirements(struct xdr_stream *xdr,
 
 	p = xdr_inline_decode(xdr, 4 + 4);
 	if (unlikely(!p))
-		goto out_overflow;
+		return -EIO;
 
 	res->consecutive = be32_to_cpup(p++);
 	res->synchronous = be32_to_cpup(p++);
 	return 0;
-out_overflow:
-	print_overflow_msg(__func__, xdr);
-	return -EIO;
 }
 
 static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res)
@@ -474,15 +467,11 @@ static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
 
 	p = xdr_inline_decode(xdr, 4 + 8);
 	if (unlikely(!p))
-		goto out_overflow;
+		return -EIO;
 
 	res->sr_eof = be32_to_cpup(p++);
 	p = xdr_decode_hyper(p, &res->sr_offset);
 	return 0;
-
-out_overflow:
-	print_overflow_msg(__func__, xdr);
-	return -EIO;
 }
 
 static int decode_layoutstats(struct xdr_stream *xdr)
fs/nfs/nfs4xdr.c +118 -333

1,395 lines not on this page · raw message

fs/nfsd/nfs4callback.c +0 -13
index c74e453..a9d24d5 100644
@@ -60,16 +60,6 @@ struct nfs4_cb_compound_hdr {
 	int		status;
 };
 
-/*
- * Handle decode buffer overflows out-of-line.
- */
-static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
-{
-	dprintk("NFS: %s prematurely hit the end of our receive buffer. "
-		"Remaining buffer length is %tu words.\n",
-		func, xdr->end - xdr->p);
-}
-
 static __be32 *xdr_encode_empty_array(__be32 *p)
 {
 	*p++ = xdr_zero;
@@ -240,7 +230,6 @@ static int decode_cb_op_status(struct xdr_stream *xdr,
 	*status = nfs_cb_stat_to_errno(be32_to_cpup(p));
 	return 0;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 out_unexpected:
 	dprintk("NFSD: Callback server returned operation %d but "
@@ -309,7 +298,6 @@ static int decode_cb_compound4res(struct xdr_stream *xdr,
 	hdr->nops = be32_to_cpup(p);
 	return 0;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	return -EIO;
 }
 
@@ -437,7 +425,6 @@ static int decode_cb_sequence4resok(struct xdr_stream *xdr,
 	cb->cb_seq_status = status;
 	return status;
 out_overflow:
-	print_overflow_msg(__func__, xdr);
 	status = -EIO;
 	goto out;
 }
#9 lore raw

PATCH 9/23 NFS: Add trace events to report non-zero NFS status codes

In reply to Chuck Lever

These can help field troubleshooting without needing the overhead of a full network capture (ie, tcpdump).

---
 fs/nfs/nfs2xdr.c   |    7 ++++
 fs/nfs/nfs3xdr.c   |    7 ++++
 fs/nfs/nfs4trace.h |   25 +++++++++++++++
 fs/nfs/nfs4xdr.c   |   12 +++++--
 fs/nfs/nfstrace.c  |    1 +
 fs/nfs/nfstrace.h  |   85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 133 insertions(+), 4 deletions(-)
fs/nfs/nfs2xdr.c +7 -0
index 7661431..bac3a4e 100644
@@ -22,6 +22,7 @@
 #include <linux/nfs.h>
 #include <linux/nfs2.h>
 #include <linux/nfs_fs.h>
+#include "nfstrace.h"
 #include "internal.h"
 
 #define NFSDBG_FACILITY		NFSDBG_XDR
@@ -145,7 +146,13 @@ static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status)
 	p = xdr_inline_decode(xdr, 4);
 	if (unlikely(!p))
 		return -EIO;
+	if (unlikely(*p != cpu_to_be32(NFS_OK)))
+		goto out_status;
+	*status = 0;
+	return 0;
+out_status:
 	*status = be32_to_cpup(p);
+	trace_nfs_xdr_status((int)*status);
 	return 0;
 }
 
fs/nfs/nfs3xdr.c +7 -0
index e561980..4aa3ffe 100644
@@ -21,6 +21,7 @@
 #include <linux/nfs3.h>
 #include <linux/nfs_fs.h>
 #include <linux/nfsacl.h>
+#include "nfstrace.h"
 #include "internal.h"
 
 #define NFSDBG_FACILITY		NFSDBG_XDR
@@ -337,7 +338,13 @@ static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
 	p = xdr_inline_decode(xdr, 4);
 	if (unlikely(!p))
 		return -EIO;
+	if (unlikely(*p != cpu_to_be32(NFS3_OK)))
+		goto out_status;
+	*status = 0;
+	return 0;
+out_status:
 	*status = be32_to_cpup(p);
+	trace_nfs_xdr_status((int)*status);
 	return 0;
 }
 
fs/nfs/nfs4trace.h +25 -0
index b4557cf..cd1a5c0 100644
@@ -524,6 +524,31 @@
 		)
 );
 
+TRACE_EVENT(nfs4_xdr_status,
+		TP_PROTO(
+			u32 op,
+			int error
+		),
+
+		TP_ARGS(op, error),
+
+		TP_STRUCT__entry(
+			__field(u32, op)
+			__field(int, error)
+		),
+
+		TP_fast_assign(
+			__entry->op = op;
+			__entry->error = -error;
+		),
+
+		TP_printk(
+			"operation %d: nfs status %d (%s)",
+			__entry->op,
+			__entry->error, show_nfsv4_errors(__entry->error)
+		)
+);
+
 DECLARE_EVENT_CLASS(nfs4_open_event,
 		TP_PROTO(
 			const struct nfs_open_context *ctx,
fs/nfs/nfs4xdr.c +8 -4
index 24e6a45..38a4cbc 100644
@@ -54,6 +54,7 @@
 #include <linux/nfs_fs.h>
 
 #include "nfs4_fs.h"
+#include "nfs4trace.h"
 #include "internal.h"
 #include "nfs4idmap.h"
 #include "nfs4session.h"
@@ -3188,11 +3189,14 @@ static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
 	opnum = be32_to_cpup(p++);
 	if (unlikely(opnum != expected))
 		goto out_bad_operation;
+	if (unlikely(*p != cpu_to_be32(NFS_OK)))
+		goto out_status;
+	*nfs_retval = 0;
+	return true;
+out_status:
 	nfserr = be32_to_cpup(p);
-	if (nfserr == NFS_OK)
-		*nfs_retval = 0;
-	else
-		*nfs_retval = nfs4_stat_to_errno(nfserr);
+	trace_nfs4_xdr_status(opnum, nfserr);
+	*nfs_retval = nfs4_stat_to_errno(nfserr);
 	return true;
 out_bad_operation:
 	dprintk("nfs: Server returned operation"
fs/nfs/nfstrace.c +1 -0
index b60d5fb..a90b363 100644
@@ -11,3 +11,4 @@
 
 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_enter);
 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_exit);
+EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_xdr_status);
fs/nfs/nfstrace.h +85 -0

91 lines not on this page · raw message

#10 lore raw

PATCH 10/23 SUNRPC: Remove some dprintk() call sites from auth functions

In reply to Chuck Lever

Clean up: Reduce dprintk noise by removing dprintk() call sites from hot path that do not report exceptions. These are usually replaceable with function graph tracing.

---
 net/sunrpc/auth.c      |   29 -----------------------------
 net/sunrpc/auth_unix.c |    9 +--------
 2 files changed, 1 insertion(+), 37 deletions(-)
net/sunrpc/auth.c +0 -29
index 8dfab61..275e84e 100644
@@ -17,10 +17,6 @@
 #include <linux/sunrpc/gss_api.h>
 #include <linux/spinlock.h>
 
-#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
-# define RPCDBG_FACILITY	RPCDBG_AUTH
-#endif
-
 #define RPC_CREDCACHE_DEFAULT_HASHBITS	(4)
 struct rpc_cred_cache {
 	struct hlist_head	*hashtable;
@@ -267,8 +263,6 @@ static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)
 		}
 	}
 	rcu_read_unlock();
-
-	dprintk("RPC:       %s returns %d\n", __func__, result);
 	return result;
 }
 EXPORT_SYMBOL_GPL(rpcauth_list_flavors);
@@ -636,9 +630,6 @@ struct rpc_cred *
 	struct rpc_cred *ret;
 	const struct cred *cred = current_cred();
 
-	dprintk("RPC:       looking up %s cred\n",
-		auth->au_ops->au_name);
-
 	memset(&acred, 0, sizeof(acred));
 	acred.cred = cred;
 	ret = auth->au_ops->lookup_cred(auth, &acred, flags);
@@ -670,8 +661,6 @@ struct rpc_cred *
 	};
 	struct rpc_cred *ret;
 
-	dprintk("RPC: %5u looking up %s cred\n",
-		task->tk_pid, task->tk_client->cl_auth->au_ops->au_name);
 	ret = auth->au_ops->lookup_cred(auth, &acred, lookupflags);
 	put_cred(acred.cred);
 	return ret;
@@ -688,8 +677,6 @@ struct rpc_cred *
 
 	if (!acred.principal)
 		return NULL;
-	dprintk("RPC: %5u looking up %s machine cred\n",
-		task->tk_pid, task->tk_client->cl_auth->au_ops->au_name);
 	return auth->au_ops->lookup_cred(auth, &acred, lookupflags);
 }
 
@@ -698,8 +685,6 @@ struct rpc_cred *
 {
 	struct rpc_auth *auth = task->tk_client->cl_auth;
 
-	dprintk("RPC: %5u looking up %s cred\n",
-		task->tk_pid, auth->au_ops->au_name);
 	return rpcauth_lookupcred(auth, lookupflags);
 }
 
@@ -776,9 +761,6 @@ struct rpc_cred *
 {
 	struct rpc_cred	*cred = task->tk_rqstp->rq_cred;
 
-	dprintk("RPC: %5u marshaling %s cred %p\n",
-		task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
-
 	return cred->cr_ops->crmarshal(task, p);
 }
 
@@ -787,9 +769,6 @@ struct rpc_cred *
 {
 	struct rpc_cred	*cred = task->tk_rqstp->rq_cred;
 
-	dprintk("RPC: %5u validating %s cred %p\n",
-		task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
-
 	return cred->cr_ops->crvalidate(task, p);
 }
 
@@ -808,8 +787,6 @@ static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct rpc_cred *cred = task->tk_rqstp->rq_cred;
 
-	dprintk("RPC: %5u using %s cred %p to wrap rpc data\n",
-			task->tk_pid, cred->cr_ops->cr_name, cred);
 	if (cred->cr_ops->crwrap_req)
 		return cred->cr_ops->crwrap_req(task, encode, rqstp, data, obj);
 	/* By default, we encode the arguments normally. */
@@ -833,8 +810,6 @@ static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct rpc_cred *cred = task->tk_rqstp->rq_cred;
 
-	dprintk("RPC: %5u using %s cred %p to unwrap rpc data\n",
-			task->tk_pid, cred->cr_ops->cr_name, cred);
 	if (cred->cr_ops->crunwrap_resp)
 		return cred->cr_ops->crunwrap_resp(task, decode, rqstp,
 						   data, obj);
@@ -865,8 +840,6 @@ static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 			goto out;
 		cred = task->tk_rqstp->rq_cred;
 	}
-	dprintk("RPC: %5u refreshing %s cred %p\n",
-		task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
 
 	err = cred->cr_ops->crrefresh(task);
 out:
@@ -880,8 +853,6 @@ static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
 {
 	struct rpc_cred *cred = task->tk_rqstp->rq_cred;
 
-	dprintk("RPC: %5u invalidating %s cred %p\n",
-		task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
 	if (cred)
 		clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
 }
net/sunrpc/auth_unix.c +1 -8
index 387f6b3..fc8a591 100644
@@ -28,8 +28,6 @@
 static struct rpc_auth *
 unx_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
 {
-	dprintk("RPC:       creating UNIX authenticator for client %p\n",
-			clnt);
 	refcount_inc(&unix_auth.au_count);
 	return &unix_auth;
 }
@@ -37,7 +35,6 @@
 static void
 unx_destroy(struct rpc_auth *auth)
 {
-	dprintk("RPC:       destroying UNIX authenticator %p\n", auth);
 }
 
 /*
@@ -48,10 +45,6 @@
 {
 	struct rpc_cred *ret = mempool_alloc(unix_pool, GFP_NOFS);
 
-	dprintk("RPC:       allocating UNIX cred for uid %d gid %d\n",
-			from_kuid(&init_user_ns, acred->cred->fsuid),
-			from_kgid(&init_user_ns, acred->cred->fsgid));
-
 	rpcauth_init_cred(ret, acred, auth, &unix_credops);
 	ret->cr_flags = 1UL << RPCAUTH_CRED_UPTODATE;
 	return ret;
@@ -61,7 +54,7 @@
 unx_free_cred_callback(struct rcu_head *head)
 {
 	struct rpc_cred *rpc_cred = container_of(head, struct rpc_cred, cr_rcu);
-	dprintk("RPC:       unx_free_cred %p\n", rpc_cred);
+
 	put_cred(rpc_cred->cr_cred);
 	mempool_free(rpc_cred, unix_pool);
 }
#11 lore raw

PATCH 11/23 SUNRPC: Remove rpc_xprt::tsh_size

In reply to Chuck Lever

tsh_size was added to accommodate transports that send a pre-amble before each RPC message. However, this assumes the pre-amble is fixed in size, which isn't true for some transports. That makes tsh_size not very generic.

Also I'd like to make the estimation of RPC send and receive buffer sizes more precise. tsh_size doesn't currently appear to be accounted for at all by call_allocate.

Therefore let's just remove the tsh_size concept, and make the only transports that have a non-zero tsh_size employ a direct approach.

---
 include/linux/sunrpc/xprt.h                |    7 --
 net/sunrpc/auth_gss/auth_gss.c             |    3 -
 net/sunrpc/clnt.c                          |    1 
 net/sunrpc/svc.c                           |   19 +-----
 net/sunrpc/xprtrdma/svc_rdma_backchannel.c |    1 
 net/sunrpc/xprtrdma/transport.c            |    1 
 net/sunrpc/xprtsock.c                      |   91 ++++++++++++++++++----------
 7 files changed, 65 insertions(+), 58 deletions(-)
include/linux/sunrpc/xprt.h +0 -7
index ad7e910..3a39154 100644
@@ -196,8 +196,6 @@ struct rpc_xprt {
 
 	size_t			max_payload;	/* largest RPC payload size,
 						   in bytes */
-	unsigned int		tsh_size;	/* size of transport specific
-						   header */
 
 	struct rpc_wait_queue	binding;	/* requests waiting on rpcbind */
 	struct rpc_wait_queue	sending;	/* requests waiting to send */
@@ -362,11 +360,6 @@ struct rpc_xprt *	xprt_alloc(struct net *net, size_t size,
 				unsigned int max_req);
 void			xprt_free(struct rpc_xprt *);
 
-static inline __be32 *xprt_skip_transport_header(struct rpc_xprt *xprt, __be32 *p)
-{
-	return p + xprt->tsh_size;
-}
-
 static inline int
 xprt_enable_swap(struct rpc_xprt *xprt)
 {
net/sunrpc/auth_gss/auth_gss.c +1 -2
index a42672e..4b52e2b 100644
@@ -1563,8 +1563,7 @@ static void gss_pipe_free(struct gss_pipe *p)
 
 	/* We compute the checksum for the verifier over the xdr-encoded bytes
 	 * starting with the xid and ending at the end of the credential: */
-	iov.iov_base = xprt_skip_transport_header(req->rq_xprt,
-					req->rq_snd_buf.head[0].iov_base);
+	iov.iov_base = req->rq_snd_buf.head[0].iov_base;
 	iov.iov_len = (u8 *)p - (u8 *)iov.iov_base;
 	xdr_buf_from_iov(&iov, &verf_buf);
 
net/sunrpc/clnt.c +0 -1
index d7ec613..c4203f6 100644
@@ -2331,7 +2331,6 @@ void rpc_force_rebind(struct rpc_clnt *clnt)
 
 	/* FIXME: check buffer size? */
 
-	p = xprt_skip_transport_header(req->rq_xprt, p);
 	*p++ = req->rq_xid;		/* XID */
 	*p++ = htonl(RPC_CALL);		/* CALL */
 	*p++ = htonl(RPC_VERSION);	/* RPC version */
net/sunrpc/svc.c +4 -15
index e87ddb9..dbd1969 100644
@@ -1145,17 +1145,6 @@ static __printf(2,3) void svc_printk(struct svc_rqst *rqstp, const char *fmt, ..
 #endif
 
 /*
- * Setup response header for TCP, it has a 4B record length field.
- */
-static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp)
-{
-	struct kvec *resv = &rqstp->rq_res.head[0];
-
-	/* tcp needs a space for the record length... */
-	svc_putnl(resv, 0);
-}
-
-/*
  * Common routine for processing the RPC request.
  */
 static int
@@ -1182,10 +1171,6 @@ static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp)
 	set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
 	clear_bit(RQ_DROPME, &rqstp->rq_flags);
 
-	/* Setup reply header */
-	if (rqstp->rq_prot == IPPROTO_TCP)
-		svc_tcp_prep_reply_hdr(rqstp);
-
 	svc_putu32(resv, rqstp->rq_xid);
 
 	vers = svc_getnl(argv);
@@ -1443,6 +1428,10 @@ static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp)
 		goto out_drop;
 	}
 
+	/* Reserve space for the record marker */
+	if (rqstp->rq_prot == IPPROTO_TCP)
+		svc_putnl(resv, 0);
+
 	/* Returns 1 for send, 0 for drop */
 	if (likely(svc_process_common(rqstp, argv, resv)))
 		return svc_send(rqstp);
net/sunrpc/xprtrdma/svc_rdma_backchannel.c +0 -1
index b908f2c..907464c 100644
@@ -304,7 +304,6 @@ static int svc_rdma_bc_sendto(struct svcxprt_rdma *rdma,
 	xprt->idle_timeout = RPCRDMA_IDLE_DISC_TO;
 
 	xprt->prot = XPRT_TRANSPORT_BC_RDMA;
-	xprt->tsh_size = 0;
 	xprt->ops = &xprt_rdma_bc_procs;
 
 	memcpy(&xprt->addr, args->dstaddr, args->addrlen);
net/sunrpc/xprtrdma/transport.c +0 -1
index fbc171e..e7274dc 100644
@@ -332,7 +332,6 @@
 	xprt->idle_timeout = RPCRDMA_IDLE_DISC_TO;
 
 	xprt->resvport = 0;		/* privileged port not needed */
-	xprt->tsh_size = 0;		/* RPC-RDMA handles framing */
 	xprt->ops = &xprt_rdma_procs;
 
 	/*
net/sunrpc/xprtsock.c +60 -31

159 lines not on this page · raw message

#12 lore raw

PATCH 12/23 SUNRPC: Add build option to disable support for insecure enctypes

In reply to Chuck Lever

Enable distributions to enforce the rejection of ancient and insecure Kerberos enctypes in the kernel's RPCSEC_GSS implementation. These are the single-DES encryption types that were deprecated in 2012 by RFC 6649.

Enctypes that were deprecated more recently (by RFC 8429) remain fully supported for now because they are still likely to be widely used.

---
 include/linux/sunrpc/gss_krb5_enctypes.h |   42 +++++++++++++++++++++++++++++-
 net/sunrpc/Kconfig                       |   16 +++++++++++
 net/sunrpc/auth_gss/gss_krb5_mech.c      |    2 +
 3 files changed, 59 insertions(+), 1 deletion(-)
include/linux/sunrpc/gss_krb5_enctypes.h +41 -1
index ec6234e..981c89c 100644
@@ -1,4 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Dumb way to share this static piece of information with nfsd
+ * Define the string that exports the set of kernel-supported
+ * Kerberos enctypes. This list is sent via upcall to gssd, and
+ * is also exposed via the nfsd /proc API. The consumers generally
+ * treat this as an ordered list, where the first item in the list
+ * is the most preferred.
+ */
+
+#ifndef _LINUX_SUNRPC_GSS_KRB5_ENCTYPES_H
+#define _LINUX_SUNRPC_GSS_KRB5_ENCTYPES_H
+
+#ifdef CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES
+
+/*
+ * NB: This list includes encryption types that were deprecated
+ * by RFC 8429 (DES3_CBC_SHA1 and ARCFOUR_HMAC).
+ *
+ * ENCTYPE_AES256_CTS_HMAC_SHA1_96
+ * ENCTYPE_AES128_CTS_HMAC_SHA1_96
+ * ENCTYPE_DES3_CBC_SHA1
+ * ENCTYPE_ARCFOUR_HMAC
+ */
+#define KRB5_SUPPORTED_ENCTYPES "18,17,16,23"
+
+#else	/* CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES */
+
+/*
+ * NB: This list includes encryption types that were deprecated
+ * by RFC 8429 and RFC 6649.
+ *
+ * ENCTYPE_AES256_CTS_HMAC_SHA1_96
+ * ENCTYPE_AES128_CTS_HMAC_SHA1_96
+ * ENCTYPE_DES3_CBC_SHA1
+ * ENCTYPE_ARCFOUR_HMAC
+ * ENCTYPE_DES_CBC_MD5
+ * ENCTYPE_DES_CBC_CRC
+ * ENCTYPE_DES_CBC_MD4
  */
 #define KRB5_SUPPORTED_ENCTYPES "18,17,16,23,3,1,2"
+
+#endif	/* CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES */
+
+#endif	/* _LINUX_SUNRPC_GSS_KRB5_ENCTYPES_H */
net/sunrpc/Kconfig +16 -0
index ac09ca8..83f5617 100644
@@ -34,6 +34,22 @@ config RPCSEC_GSS_KRB5
 
 	  If unsure, say Y.
 
+config CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES
+	bool "Secure RPC: Disable insecure Kerberos encryption types"
+	depends on RPCSEC_GSS_KRB5
+	default n
+	help
+	  Choose Y here to disable the use of deprecated encryption types
+	  with the Kerberos version 5 GSS-API mechanism (RFC 1964). The
+	  deprecated encryption types include DES-CBC-MD5, DES-CBC-CRC,
+	  and DES-CBC-MD4. These types were deprecated by RFC 6649 because
+	  they were found to be insecure.
+
+	  N is the default because many sites have deployed KDCs and
+	  keytabs that contain only these deprecated encryption types.
+	  Choosing Y prevents the use of known-insecure encryption types
+	  but might result in compatibility problems.
+
 config SUNRPC_DEBUG
 	bool "RPC: Enable dprintk debugging"
 	depends on SUNRPC && SYSCTL
net/sunrpc/auth_gss/gss_krb5_mech.c +2 -0
index eab71fc..be31a58 100644
@@ -53,6 +53,7 @@
 static struct gss_api_mech gss_kerberos_mech;	/* forward declaration */
 
 static const struct gss_krb5_enctype supported_gss_krb5_enctypes[] = {
+#ifndef CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES
 	/*
 	 * DES (All DES enctypes are mapped to the same gss functionality)
 	 */
@@ -74,6 +75,7 @@
 	  .cksumlength = 8,
 	  .keyed_cksum = 0,
 	},
+#endif	/* CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES */
 	/*
 	 * RC4-HMAC
 	 */
#13 lore raw

PATCH 13/23 SUNRPC: Use struct xdr_stream when constructing RPC Call header

In reply to Chuck Lever

Modernize and harden the code path that constructs each RPC Call message.

---
 include/linux/sunrpc/auth.h    |   15 ++-
 include/linux/sunrpc/xdr.h     |    6 +
 include/trace/events/sunrpc.h  |   29 ++++++
 net/sunrpc/auth.c              |   56 ++++++++----
 net/sunrpc/auth_gss/auth_gss.c |  191 +++++++++++++++++++---------------------
 net/sunrpc/auth_null.c         |   23 +++--
 net/sunrpc/auth_unix.c         |   61 ++++++++-----
 net/sunrpc/clnt.c              |   66 +++++++-------
 8 files changed, 266 insertions(+), 181 deletions(-)
include/linux/sunrpc/auth.h +10 -5
index eed3cb1..96e237f 100644
@@ -131,11 +131,12 @@ struct rpc_credops {
 	void			(*crdestroy)(struct rpc_cred *);
 
 	int			(*crmatch)(struct auth_cred *, struct rpc_cred *, int);
-	__be32 *		(*crmarshal)(struct rpc_task *, __be32 *);
+	int			(*crmarshal)(struct rpc_task *task,
+					     struct xdr_stream *xdr);
 	int			(*crrefresh)(struct rpc_task *);
 	__be32 *		(*crvalidate)(struct rpc_task *, __be32 *);
-	int			(*crwrap_req)(struct rpc_task *, kxdreproc_t,
-						void *, __be32 *, void *);
+	int			(*crwrap_req)(struct rpc_task *task,
+					      struct xdr_stream *xdr);
 	int			(*crunwrap_resp)(struct rpc_task *, kxdrdproc_t,
 						void *, __be32 *, void *);
 	int			(*crkey_timeout)(struct rpc_cred *);
@@ -165,9 +166,13 @@ int			rpcauth_get_gssinfo(rpc_authflavor_t,
 void			rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
 struct rpc_cred *	rpcauth_lookupcred(struct rpc_auth *, int);
 void			put_rpccred(struct rpc_cred *);
-__be32 *		rpcauth_marshcred(struct rpc_task *, __be32 *);
+int			rpcauth_marshcred(struct rpc_task *task,
+					  struct xdr_stream *xdr);
 __be32 *		rpcauth_checkverf(struct rpc_task *, __be32 *);
-int			rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp, __be32 *data, void *obj);
+int			rpcauth_wrap_req_encode(struct rpc_task *task,
+						struct xdr_stream *xdr);
+int			rpcauth_wrap_req(struct rpc_task *task,
+					 struct xdr_stream *xdr);
 int			rpcauth_unwrap_resp(struct rpc_task *task, kxdrdproc_t decode, void *rqstp, __be32 *data, void *obj);
 bool			rpcauth_xmit_need_reencode(struct rpc_task *task);
 int			rpcauth_refreshcred(struct rpc_task *);
include/linux/sunrpc/xdr.h +6 -0
index 787939d..6df9ac1 100644
@@ -87,6 +87,12 @@ struct xdr_buf {
 #define	xdr_one		cpu_to_be32(1)
 #define	xdr_two		cpu_to_be32(2)
 
+#define	rpc_auth_null	cpu_to_be32(RPC_AUTH_NULL)
+#define	rpc_auth_unix	cpu_to_be32(RPC_AUTH_UNIX)
+#define	rpc_auth_gss	cpu_to_be32(RPC_AUTH_GSS)
+
+#define	rpc_call	cpu_to_be32(RPC_CALL)
+
 #define	rpc_success		cpu_to_be32(RPC_SUCCESS)
 #define	rpc_prog_unavail	cpu_to_be32(RPC_PROG_UNAVAIL)
 #define	rpc_prog_mismatch	cpu_to_be32(RPC_PROG_MISMATCH)
include/trace/events/sunrpc.h +29 -0
index 6276508..2b3f9d1 100644
@@ -213,6 +213,35 @@
 DEFINE_RPC_QUEUED_EVENT(sleep);
 DEFINE_RPC_QUEUED_EVENT(wakeup);
 
+DECLARE_EVENT_CLASS(rpc_failure,
+
+	TP_PROTO(const struct rpc_task *task),
+
+	TP_ARGS(task),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+	),
+
+	TP_fast_assign(
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+	),
+
+	TP_printk("task:%u@%u",
+		__entry->task_id, __entry->client_id)
+);
+
+#define DEFINE_RPC_FAILURE(name)					\
+	DEFINE_EVENT(rpc_failure, rpc_bad_##name,			\
+			TP_PROTO(					\
+				const struct rpc_task *task		\
+			),						\
+			TP_ARGS(task))
+
+DEFINE_RPC_FAILURE(callhdr);
+
 TRACE_EVENT(rpc_stats_latency,
 
 	TP_PROTO(
net/sunrpc/auth.c +38 -18

76 lines not on this page · raw message

net/sunrpc/auth_gss/auth_gss.c +93 -98

316 lines not on this page · raw message

net/sunrpc/auth_null.c +15 -8
index d0ceac5..797f8472 100644
@@ -59,15 +59,21 @@
 /*
  * Marshal credential.
  */
-static __be32 *
-nul_marshal(struct rpc_task *task, __be32 *p)
+static int
+nul_marshal(struct rpc_task *task, struct xdr_stream *xdr)
 {
-	*p++ = htonl(RPC_AUTH_NULL);
-	*p++ = 0;
-	*p++ = htonl(RPC_AUTH_NULL);
-	*p++ = 0;
-
-	return p;
+	__be32 *p;
+
+	p = xdr_reserve_space(xdr, 4 * sizeof(*p));
+	if (!p)
+		return -EMSGSIZE;
+	/* Credential */
+	*p++ = rpc_auth_null;
+	*p++ = xdr_zero;
+	/* Verifier */
+	*p++ = rpc_auth_null;
+	*p   = xdr_zero;
+	return 0;
 }
 
 /*
@@ -125,6 +131,7 @@ struct rpc_auth null_auth = {
 	.crdestroy	= nul_destroy_cred,
 	.crmatch	= nul_match,
 	.crmarshal	= nul_marshal,
+	.crwrap_req	= rpcauth_wrap_req_encode,
 	.crrefresh	= nul_refresh,
 	.crvalidate	= nul_validate,
 };
net/sunrpc/auth_unix.c +40 -21

83 lines not on this page · raw message

net/sunrpc/clnt.c +35 -31

107 lines not on this page · raw message

#14 lore raw

PATCH 14/23 SUNRPC: Clean up rpc_verify_header()

In reply to Chuck Lever

- Recover some instruction count because I'm about to introduce a few xdr_inline_decode call sites
- Replace dprintk() call sites with trace points
- Reduce the hot path so it fits in fewer cachelines

I've also renamed it rpc_decode_header() to match everything else in the RPC client.

---
 include/linux/sunrpc/xdr.h    |    7 +
 include/trace/events/sunrpc.h |   52 ++++++++++
 net/sunrpc/clnt.c             |  223 ++++++++++++++++++-----------------------
 3 files changed, 154 insertions(+), 128 deletions(-)
include/linux/sunrpc/xdr.h +6 -1
index 6df9ac1..c540419 100644
@@ -92,6 +92,9 @@ struct xdr_buf {
 #define	rpc_auth_gss	cpu_to_be32(RPC_AUTH_GSS)
 
 #define	rpc_call	cpu_to_be32(RPC_CALL)
+#define	rpc_reply	cpu_to_be32(RPC_REPLY)
+
+#define	rpc_msg_accepted	cpu_to_be32(RPC_MSG_ACCEPTED)
 
 #define	rpc_success		cpu_to_be32(RPC_SUCCESS)
 #define	rpc_prog_unavail	cpu_to_be32(RPC_PROG_UNAVAIL)
@@ -101,6 +104,9 @@ struct xdr_buf {
 #define	rpc_system_err		cpu_to_be32(RPC_SYSTEM_ERR)
 #define	rpc_drop_reply		cpu_to_be32(RPC_DROP_REPLY)
 
+#define	rpc_mismatch		cpu_to_be32(RPC_MISMATCH)
+#define	rpc_auth_error		cpu_to_be32(RPC_AUTH_ERROR)
+
 #define	rpc_auth_ok		cpu_to_be32(RPC_AUTH_OK)
 #define	rpc_autherr_badcred	cpu_to_be32(RPC_AUTH_BADCRED)
 #define	rpc_autherr_rejectedcred cpu_to_be32(RPC_AUTH_REJECTEDCRED)
@@ -109,7 +115,6 @@ struct xdr_buf {
 #define	rpc_autherr_tooweak	cpu_to_be32(RPC_AUTH_TOOWEAK)
 #define	rpcsec_gsserr_credproblem	cpu_to_be32(RPCSEC_GSS_CREDPROBLEM)
 #define	rpcsec_gsserr_ctxproblem	cpu_to_be32(RPCSEC_GSS_CTXPROBLEM)
-#define	rpc_autherr_oldseqnum	cpu_to_be32(101)
 
 /*
  * Miscellaneous XDR helper functions
include/trace/events/sunrpc.h +52 -0

58 lines not on this page · raw message

net/sunrpc/clnt.c +96 -127

281 lines not on this page · raw message

#15 lore raw

PATCH 15/23 SUNRPC: Use struct xdr_stream when decoding RPC Reply header

In reply to Chuck Lever

Modernize and harden the code path that parses an RPC Reply message.

---
 include/linux/sunrpc/auth.h    |   15 ++-
 include/linux/sunrpc/xdr.h     |    1 
 net/sunrpc/auth.c              |   63 ++++++++----
 net/sunrpc/auth_gss/auth_gss.c |  204 ++++++++++++++++++++++------------------
 net/sunrpc/auth_null.c         |   31 +++---
 net/sunrpc/auth_unix.c         |   42 +++++---
 net/sunrpc/clnt.c              |   88 +++++++++--------
 7 files changed, 243 insertions(+), 201 deletions(-)
include/linux/sunrpc/auth.h +10 -5
index 96e237f..c51e189 100644
@@ -134,11 +134,12 @@ struct rpc_credops {
 	int			(*crmarshal)(struct rpc_task *task,
 					     struct xdr_stream *xdr);
 	int			(*crrefresh)(struct rpc_task *);
-	__be32 *		(*crvalidate)(struct rpc_task *, __be32 *);
+	int			(*crvalidate)(struct rpc_task *task,
+					      struct xdr_stream *xdr);
 	int			(*crwrap_req)(struct rpc_task *task,
 					      struct xdr_stream *xdr);
-	int			(*crunwrap_resp)(struct rpc_task *, kxdrdproc_t,
-						void *, __be32 *, void *);
+	int			(*crunwrap_resp)(struct rpc_task *task,
+						 struct xdr_stream *xdr);
 	int			(*crkey_timeout)(struct rpc_cred *);
 	char *			(*crstringify_acceptor)(struct rpc_cred *);
 	bool			(*crneed_reencode)(struct rpc_task *);
@@ -168,12 +169,16 @@ int			rpcauth_get_gssinfo(rpc_authflavor_t,
 void			put_rpccred(struct rpc_cred *);
 int			rpcauth_marshcred(struct rpc_task *task,
 					  struct xdr_stream *xdr);
-__be32 *		rpcauth_checkverf(struct rpc_task *, __be32 *);
+int			rpcauth_checkverf(struct rpc_task *task,
+					  struct xdr_stream *xdr);
 int			rpcauth_wrap_req_encode(struct rpc_task *task,
 						struct xdr_stream *xdr);
 int			rpcauth_wrap_req(struct rpc_task *task,
 					 struct xdr_stream *xdr);
-int			rpcauth_unwrap_resp(struct rpc_task *task, kxdrdproc_t decode, void *rqstp, __be32 *data, void *obj);
+int			rpcauth_unwrap_resp_decode(struct rpc_task *task,
+						   struct xdr_stream *xdr);
+int			rpcauth_unwrap_resp(struct rpc_task *task,
+					    struct xdr_stream *xdr);
 bool			rpcauth_xmit_need_reencode(struct rpc_task *task);
 int			rpcauth_refreshcred(struct rpc_task *);
 void			rpcauth_invalcred(struct rpc_task *);
include/linux/sunrpc/xdr.h +1 -0
index c540419..65af6a2 100644
@@ -89,6 +89,7 @@ struct xdr_buf {
 
 #define	rpc_auth_null	cpu_to_be32(RPC_AUTH_NULL)
 #define	rpc_auth_unix	cpu_to_be32(RPC_AUTH_UNIX)
+#define	rpc_auth_short	cpu_to_be32(RPC_AUTH_SHORT)
 #define	rpc_auth_gss	cpu_to_be32(RPC_AUTH_GSS)
 
 #define	rpc_call	cpu_to_be32(RPC_CALL)
net/sunrpc/auth.c +41 -22

88 lines not on this page · raw message

net/sunrpc/auth_gss/auth_gss.c +110 -94

287 lines not on this page · raw message

net/sunrpc/auth_null.c +13 -18
index 797f8472..bf96975 100644
@@ -86,25 +86,19 @@
 	return 0;
 }
 
-static __be32 *
-nul_validate(struct rpc_task *task, __be32 *p)
+static int
+nul_validate(struct rpc_task *task, struct xdr_stream *xdr)
 {
-	rpc_authflavor_t	flavor;
-	u32			size;
-
-	flavor = ntohl(*p++);
-	if (flavor != RPC_AUTH_NULL) {
-		printk("RPC: bad verf flavor: %u\n", flavor);
-		return ERR_PTR(-EIO);
-	}
-
-	size = ntohl(*p++);
-	if (size != 0) {
-		printk("RPC: bad verf size: %u\n", size);
-		return ERR_PTR(-EIO);
-	}
-
-	return p;
+	__be32 *p;
+
+	p = xdr_inline_decode(xdr, 2 * sizeof(*p));
+	if (!p)
+		return -EIO;
+	if (*p++ != rpc_auth_null)
+		return -EIO;
+	if (*p != xdr_zero)
+		return -EIO;
+	return 0;
 }
 
 const struct rpc_authops authnull_ops = {
@@ -134,6 +128,7 @@ struct rpc_auth null_auth = {
 	.crwrap_req	= rpcauth_wrap_req_encode,
 	.crrefresh	= nul_refresh,
 	.crvalidate	= nul_validate,
+	.crunwrap_resp	= rpcauth_unwrap_resp_decode,
 };
 
 static
net/sunrpc/auth_unix.c +23 -19

56 lines not on this page · raw message

net/sunrpc/clnt.c +45 -43

173 lines not on this page · raw message

#16 lore raw

PATCH 16/23 SUNRPC: Introduce trace points in rpc_auth_gss.ko

In reply to Chuck Lever

Add infrastructure for trace points in the RPC_AUTH_GSS kernel module, and add a few sample trace points. These report exceptional or unexpected events, and observe the assignment of GSS sequence numbers.

---
 include/trace/events/rpcgss.h  |  361 ++++++++++++++++++++++++++++++++++++++++
 include/trace/events/rpcrdma.h |   12 +
 include/trace/events/sunrpc.h  |   61 +++++++
 net/sunrpc/auth_gss/Makefile   |    2 
 net/sunrpc/auth_gss/auth_gss.c |  165 +++++++++---------
 net/sunrpc/auth_gss/trace.c    |   11 +
 net/sunrpc/xprt.c              |   10 +
 7 files changed, 530 insertions(+), 92 deletions(-)
 create mode 100644 include/trace/events/rpcgss.h
 create mode 100644 net/sunrpc/auth_gss/trace.c
include/trace/events/rpcgss.h new file +361 -0
new file mode 100644
index 0000000..d1f7fe1
@@ -0,0 +1,361 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018 Oracle.  All rights reserved.
+ *
+ * Trace point definitions for the "rpcgss" subsystem.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM rpcgss
+
+#if !defined(_TRACE_RPCRDMA_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_RPCGSS_H
+
+#include <linux/tracepoint.h>
+
+/**
+ ** GSS-API related trace events
+ **/
+
+TRACE_DEFINE_ENUM(GSS_S_BAD_MECH);
+TRACE_DEFINE_ENUM(GSS_S_BAD_NAME);
+TRACE_DEFINE_ENUM(GSS_S_BAD_NAMETYPE);
+TRACE_DEFINE_ENUM(GSS_S_BAD_BINDINGS);
+TRACE_DEFINE_ENUM(GSS_S_BAD_STATUS);
+TRACE_DEFINE_ENUM(GSS_S_BAD_SIG);
+TRACE_DEFINE_ENUM(GSS_S_NO_CRED);
+TRACE_DEFINE_ENUM(GSS_S_NO_CONTEXT);
+TRACE_DEFINE_ENUM(GSS_S_DEFECTIVE_TOKEN);
+TRACE_DEFINE_ENUM(GSS_S_DEFECTIVE_CREDENTIAL);
+TRACE_DEFINE_ENUM(GSS_S_CREDENTIALS_EXPIRED);
+TRACE_DEFINE_ENUM(GSS_S_CONTEXT_EXPIRED);
+TRACE_DEFINE_ENUM(GSS_S_FAILURE);
+TRACE_DEFINE_ENUM(GSS_S_BAD_QOP);
+TRACE_DEFINE_ENUM(GSS_S_UNAUTHORIZED);
+TRACE_DEFINE_ENUM(GSS_S_UNAVAILABLE);
+TRACE_DEFINE_ENUM(GSS_S_DUPLICATE_ELEMENT);
+TRACE_DEFINE_ENUM(GSS_S_NAME_NOT_MN);
+TRACE_DEFINE_ENUM(GSS_S_CONTINUE_NEEDED);
+TRACE_DEFINE_ENUM(GSS_S_DUPLICATE_TOKEN);
+TRACE_DEFINE_ENUM(GSS_S_OLD_TOKEN);
+TRACE_DEFINE_ENUM(GSS_S_UNSEQ_TOKEN);
+TRACE_DEFINE_ENUM(GSS_S_GAP_TOKEN);
+
+#define show_gss_status(x)						\
+	__print_flags(x, "|",						\
+		{ GSS_S_BAD_MECH, "GSS_S_BAD_MECH" },			\
+		{ GSS_S_BAD_NAME, "GSS_S_BAD_NAME" },			\
+		{ GSS_S_BAD_NAMETYPE, "GSS_S_BAD_NAMETYPE" },		\
+		{ GSS_S_BAD_BINDINGS, "GSS_S_BAD_BINDINGS" },		\
+		{ GSS_S_BAD_STATUS, "GSS_S_BAD_STATUS" },		\
+		{ GSS_S_BAD_SIG, "GSS_S_BAD_SIG" },			\
+		{ GSS_S_NO_CRED, "GSS_S_NO_CRED" },			\
+		{ GSS_S_NO_CONTEXT, "GSS_S_NO_CONTEXT" },		\
+		{ GSS_S_DEFECTIVE_TOKEN, "GSS_S_DEFECTIVE_TOKEN" },	\
+		{ GSS_S_DEFECTIVE_CREDENTIAL, "GSS_S_DEFECTIVE_CREDENTIAL" }, \
+		{ GSS_S_CREDENTIALS_EXPIRED, "GSS_S_CREDENTIALS_EXPIRED" }, \
+		{ GSS_S_CONTEXT_EXPIRED, "GSS_S_CONTEXT_EXPIRED" },	\
+		{ GSS_S_FAILURE, "GSS_S_FAILURE" },			\
+		{ GSS_S_BAD_QOP, "GSS_S_BAD_QOP" },			\
+		{ GSS_S_UNAUTHORIZED, "GSS_S_UNAUTHORIZED" },		\
+		{ GSS_S_UNAVAILABLE, "GSS_S_UNAVAILABLE" },		\
+		{ GSS_S_DUPLICATE_ELEMENT, "GSS_S_DUPLICATE_ELEMENT" },	\
+		{ GSS_S_NAME_NOT_MN, "GSS_S_NAME_NOT_MN" },		\
+		{ GSS_S_CONTINUE_NEEDED, "GSS_S_CONTINUE_NEEDED" },	\
+		{ GSS_S_DUPLICATE_TOKEN, "GSS_S_DUPLICATE_TOKEN" },	\
+		{ GSS_S_OLD_TOKEN, "GSS_S_OLD_TOKEN" },			\
+		{ GSS_S_UNSEQ_TOKEN, "GSS_S_UNSEQ_TOKEN" },		\
+		{ GSS_S_GAP_TOKEN, "GSS_S_GAP_TOKEN" })
+
+
+DECLARE_EVENT_CLASS(rpcgss_gssapi_event,
+	TP_PROTO(
+		const struct rpc_task *task,
+		u32 maj_stat
+	),
+
+	TP_ARGS(task, maj_stat),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(u32, maj_stat)
+
+	),
+
+	TP_fast_assign(
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+		__entry->maj_stat = maj_stat;
+	),
+
+	TP_printk("task:%u@%u maj_stat=%s",
+		__entry->task_id, __entry->client_id,
+		__entry->maj_stat == 0 ?
+		"GSS_S_COMPLETE" : show_gss_status(__entry->maj_stat))
+);
+
+#define DEFINE_GSSAPI_EVENT(name)					\
+	DEFINE_EVENT(rpcgss_gssapi_event, rpcgss_##name,		\
+			TP_PROTO(					\
+				const struct rpc_task *task,		\
+				u32 maj_stat				\
+			),						\
+			TP_ARGS(task, maj_stat))
+
+TRACE_EVENT(rpcgss_import_ctx,
+	TP_PROTO(
+		int status
+	),
+
+	TP_ARGS(status),
+
+	TP_STRUCT__entry(
+		__field(int, status)
+	),
+
+	TP_fast_assign(
+		__entry->status = status;
+	),
+
+	TP_printk("status=%d", __entry->status)
+);
+
+DEFINE_GSSAPI_EVENT(get_mic);
+DEFINE_GSSAPI_EVENT(verify_mic);
+DEFINE_GSSAPI_EVENT(wrap);
+DEFINE_GSSAPI_EVENT(unwrap);
+
+
+/**
+ ** GSS auth unwrap failures
+ **/
+
+TRACE_EVENT(rpcgss_unwrap_failed,
+	TP_PROTO(
+		const struct rpc_task *task
+	),
+
+	TP_ARGS(task),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+	),
+
+	TP_fast_assign(
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+	),
+
+	TP_printk("task:%u@%u", __entry->task_id, __entry->client_id)
+);
+
+TRACE_EVENT(rpcgss_bad_seqno,
+	TP_PROTO(
+		const struct rpc_task *task,
+		u32 expected,
+		u32 received
+	),
+
+	TP_ARGS(task, expected, received),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(u32, expected)
+		__field(u32, received)
+	),
+
+	TP_fast_assign(
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+		__entry->expected = expected;
+		__entry->received = received;
+	),
+
+	TP_printk("task:%u@%u expected seqno %u, received seqno %u",
+		__entry->task_id, __entry->client_id,
+		__entry->expected, __entry->received)
+);
+
+TRACE_EVENT(rpcgss_seqno,
+	TP_PROTO(
+		const struct rpc_task *task
+	),
+
+	TP_ARGS(task),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(u32, xid)
+		__field(u32, seqno)
+	),
+
+	TP_fast_assign(
+		const struct rpc_rqst *rqst = task->tk_rqstp;
+
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+		__entry->xid = be32_to_cpu(rqst->rq_xid);
+		__entry->seqno = rqst->rq_seqno;
+	),
+
+	TP_printk("task:%u@%u xid=0x%08x seqno=%u",
+		__entry->task_id, __entry->client_id,
+		__entry->xid, __entry->seqno)
+);
+
+TRACE_EVENT(rpcgss_need_reencode,
+	TP_PROTO(
+		const struct rpc_task *task,
+		u32 seq_xmit,
+		bool ret
+	),
+
+	TP_ARGS(task, seq_xmit, ret),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(u32, xid)
+		__field(u32, seq_xmit)
+		__field(u32, seqno)
+		__field(bool, ret)
+	),
+
+	TP_fast_assign(
+		__entry->task_id = task->tk_pid;
+		__entry->client_id = task->tk_client->cl_clid;
+		__entry->xid = be32_to_cpu(task->tk_rqstp->rq_xid);
+		__entry->seq_xmit = seq_xmit;
+		__entry->seqno = task->tk_rqstp->rq_seqno;
+		__entry->ret = ret;
+	),
+
+	TP_printk("task:%u@%u xid=0x%08x rq_seqno=%u seq_xmit=%u reencode %sneeded",
+		__entry->task_id, __entry->client_id,
+		__entry->xid, __entry->seqno, __entry->seq_xmit,
+		__entry->ret ? "" : "un")
+);
+
+/**
+ ** gssd upcall related trace events
+ **/
+
+TRACE_EVENT(rpcgss_upcall_msg,
+	TP_PROTO(
+		const char *buf
+	),
+
+	TP_ARGS(buf),
+
+	TP_STRUCT__entry(
+		__string(msg, buf)
+	),
+
+	TP_fast_assign(
+		__assign_str(msg, buf)
+	),
+
+	TP_printk("msg='%s'", __get_str(msg))
+);
+
+TRACE_EVENT(rpcgss_upcall_result,
+	TP_PROTO(
+		u32 uid,
+		int result
+	),
+
+	TP_ARGS(uid, result),
+
+	TP_STRUCT__entry(
+		__field(u32, uid)
+		__field(int, result)
+
+	),
+
+	TP_fast_assign(
+		__entry->uid = uid;
+		__entry->result = result;
+	),
+
+	TP_printk("for uid %u, result=%d", __entry->uid, __entry->result)
+);
+
+TRACE_EVENT(rpcgss_context,
+	TP_PROTO(
+		unsigned long expiry,
+		unsigned long now,
+		unsigned int timeout,
+		unsigned int len,
+		const u8 *data
+	),
+
+	TP_ARGS(expiry, now, timeout, len, data),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, expiry)
+		__field(unsigned long, now)
+		__field(unsigned int, timeout)
+		__field(int, len)
+		__string(acceptor, data)
+	),
+
+	TP_fast_assign(
+		__entry->expiry = expiry;
+		__entry->now = now;
+		__entry->timeout = timeout;
+		__entry->len = len;
+		strncpy(__get_str(acceptor), data, len);
+	),
+
+	TP_printk("gc_expiry=%lu now=%lu timeout=%u acceptor=%.*s",
+		__entry->expiry, __entry->now, __entry->timeout,
+		__entry->len, __get_str(acceptor))
+);
+
+
+/**
+ ** Miscellaneous events
+ */
+
+TRACE_DEFINE_ENUM(RPC_AUTH_GSS_KRB5);
+TRACE_DEFINE_ENUM(RPC_AUTH_GSS_KRB5I);
+TRACE_DEFINE_ENUM(RPC_AUTH_GSS_KRB5P);
+
+#define show_pseudoflavor(x)						\
+	__print_symbolic(x,						\
+		{ RPC_AUTH_GSS_KRB5, "RPC_AUTH_GSS_KRB5" },		\
+		{ RPC_AUTH_GSS_KRB5I, "RPC_AUTH_GSS_KRB5I" },		\
+		{ RPC_AUTH_GSS_KRB5P, "RPC_AUTH_GSS_KRB5P" })
+
+
+TRACE_EVENT(rpcgss_createauth,
+	TP_PROTO(
+		unsigned int flavor,
+		int error
+	),
+
+	TP_ARGS(flavor, error),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, flavor)
+		__field(int, error)
+
+	),
+
+	TP_fast_assign(
+		__entry->flavor = flavor;
+		__entry->error = error;
+	),
+
+	TP_printk("flavor=%s error=%d",
+		show_pseudoflavor(__entry->flavor), __entry->error)
+);
+
+
+#endif	/* _TRACE_RPCGSS_H */
+
+#include <trace/define_trace.h>
include/trace/events/rpcrdma.h +10 -2
index 399b1ae..962975b 100644
@@ -521,12 +521,18 @@
 
 	TP_STRUCT__entry(
 		__field(const void *, req)
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
 		__field(int, num_sge)
 		__field(int, signaled)
 		__field(int, status)
 	),
 
 	TP_fast_assign(
+		const struct rpc_rqst *rqst = &req->rl_slot;
+
+		__entry->task_id = rqst->rq_task->tk_pid;
+		__entry->client_id = rqst->rq_task->tk_client->cl_clid;
 		__entry->req = req;
 		__entry->num_sge = req->rl_sendctx->sc_wr.num_sge;
 		__entry->signaled = req->rl_sendctx->sc_wr.send_flags &
@@ -534,9 +540,11 @@
 		__entry->status = status;
 	),
 
-	TP_printk("req=%p, %d SGEs%s, status=%d",
+	TP_printk("task:%u@%u req=%p (%d SGE%s) %sstatus=%d",
+		__entry->task_id, __entry->client_id,
 		__entry->req, __entry->num_sge,
-		(__entry->signaled ? ", signaled" : ""),
+		(__entry->num_sge == 1 ? "" : "s"),
+		(__entry->signaled ? "signaled " : ""),
 		__entry->status
 	)
 );
include/trace/events/sunrpc.h +60 -1

69 lines not on this page · raw message

net/sunrpc/auth_gss/Makefile +1 -1
index c374268..4a29f4c 100644
@@ -7,7 +7,7 @@ obj-$(CONFIG_SUNRPC_GSS) += auth_rpcgss.o
 
 auth_rpcgss-y := auth_gss.o gss_generic_token.o \
 	gss_mech_switch.o svcauth_gss.o \
-	gss_rpc_upcall.o gss_rpc_xdr.o
+	gss_rpc_upcall.o gss_rpc_xdr.o trace.o
 
 obj-$(CONFIG_RPCSEC_GSS_KRB5) += rpcsec_gss_krb5.o
 
net/sunrpc/auth_gss/auth_gss.c +81 -84

483 lines not on this page · raw message

net/sunrpc/auth_gss/trace.c new file +11 -0
new file mode 100644
index 0000000..5576f1e
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, 2019 Oracle. All rights reserved.
+ */
+
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/sched.h>
+#include <linux/sunrpc/gss_err.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/rpcgss.h>
net/sunrpc/xprt.c +6 -4
index f1ec211..bc7489f 100644
@@ -1165,6 +1165,7 @@ void xprt_request_wait_receive(struct rpc_task *task)
 				/* Note: req is added _before_ pos */
 				list_add_tail(&req->rq_xmit, &pos->rq_xmit);
 				INIT_LIST_HEAD(&req->rq_xmit2);
+				trace_xprt_enq_xmit(task, 1);
 				goto out;
 			}
 		} else if (RPC_IS_SWAPPER(task)) {
@@ -1176,6 +1177,7 @@ void xprt_request_wait_receive(struct rpc_task *task)
 				/* Note: req is added _before_ pos */
 				list_add_tail(&req->rq_xmit, &pos->rq_xmit);
 				INIT_LIST_HEAD(&req->rq_xmit2);
+				trace_xprt_enq_xmit(task, 2);
 				goto out;
 			}
 		} else if (!req->rq_seqno) {
@@ -1184,11 +1186,13 @@ void xprt_request_wait_receive(struct rpc_task *task)
 					continue;
 				list_add_tail(&req->rq_xmit2, &pos->rq_xmit2);
 				INIT_LIST_HEAD(&req->rq_xmit);
+				trace_xprt_enq_xmit(task, 3);
 				goto out;
 			}
 		}
 		list_add_tail(&req->rq_xmit, &xprt->xmit_queue);
 		INIT_LIST_HEAD(&req->rq_xmit2);
+		trace_xprt_enq_xmit(task, 4);
 out:
 		set_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate);
 		spin_unlock(&xprt->queue_lock);
@@ -1313,8 +1317,6 @@ void xprt_end_transmit(struct rpc_task *task)
 	int is_retrans = RPC_WAS_SENT(task);
 	int status;
 
-	dprintk("RPC: %5u xprt_transmit(%u)\n", task->tk_pid, req->rq_slen);
-
 	if (!req->rq_bytes_sent) {
 		if (xprt_request_data_received(task)) {
 			status = 0;
@@ -1336,9 +1338,9 @@ void xprt_end_transmit(struct rpc_task *task)
 
 	connect_cookie = xprt->connect_cookie;
 	status = xprt->ops->send_request(req);
-	trace_xprt_transmit(xprt, req->rq_xid, status);
 	if (status != 0) {
 		req->rq_ntrans--;
+		trace_xprt_transmit(req, status);
 		return status;
 	}
 
@@ -1347,7 +1349,6 @@ void xprt_end_transmit(struct rpc_task *task)
 
 	xprt_inject_disconnect(xprt);
 
-	dprintk("RPC: %5u xmit complete\n", task->tk_pid);
 	task->tk_flags |= RPC_TASK_SENT;
 	spin_lock_bh(&xprt->transport_lock);
 
@@ -1360,6 +1361,7 @@ void xprt_end_transmit(struct rpc_task *task)
 
 	req->rq_connect_cookie = connect_cookie;
 out_dequeue:
+	trace_xprt_transmit(req, status);
 	xprt_request_dequeue_transmit(task);
 	rpc_wake_up_queued_task_set_status(&xprt->sending, task, status);
 	return status;
#17 lore raw

PATCH 17/23 SUNRPC: Remove xdr_buf_trim()

In reply to Chuck Lever

The key action of xdr_buf_trim() is that it shortens buf->len, the length of the xdr_buf's content. The other actions -- shortening the head, pages, and tail components -- are actually not necessary. In particular, changing the size of those components can corrupt the RPC message contained in the buffer. This is an accident waiting to happen rather than a current bug, as far as we know.

---
 include/linux/sunrpc/xdr.h          |    1 -
 net/sunrpc/auth_gss/gss_krb5_wrap.c |    8 ++++---
 net/sunrpc/auth_gss/svcauth_gss.c   |    2 +-
 net/sunrpc/xdr.c                    |   41 -----------------------------------
 4 files changed, 6 insertions(+), 46 deletions(-)
include/linux/sunrpc/xdr.h +0 -1
index 65af6a2..9ee3970 100644
@@ -179,7 +179,6 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
 extern void xdr_shift_buf(struct xdr_buf *, size_t);
 extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
 extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
-extern void xdr_buf_trim(struct xdr_buf *, unsigned int);
 extern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, unsigned int);
 extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
 extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
net/sunrpc/auth_gss/gss_krb5_wrap.c +5 -3
index 5cdde6c..14a0aff 100644
@@ -570,14 +570,16 @@ static void rotate_left(u32 base, struct xdr_buf *buf, unsigned int shift)
 	 */
 	movelen = min_t(unsigned int, buf->head[0].iov_len, buf->len);
 	movelen -= offset + GSS_KRB5_TOK_HDR_LEN + headskip;
-	BUG_ON(offset + GSS_KRB5_TOK_HDR_LEN + headskip + movelen >
-							buf->head[0].iov_len);
+	if (offset + GSS_KRB5_TOK_HDR_LEN + headskip + movelen >
+	    buf->head[0].iov_len)
+		return GSS_S_FAILURE;
 	memmove(ptr, ptr + GSS_KRB5_TOK_HDR_LEN + headskip, movelen);
 	buf->head[0].iov_len -= GSS_KRB5_TOK_HDR_LEN + headskip;
 	buf->len -= GSS_KRB5_TOK_HDR_LEN + headskip;
 
 	/* Trim off the trailing "extra count" and checksum blob */
-	xdr_buf_trim(buf, ec + GSS_KRB5_TOK_HDR_LEN + tailskip);
+	buf->len -= ec + GSS_KRB5_TOK_HDR_LEN + tailskip;
+
 	return GSS_S_COMPLETE;
 }
 
net/sunrpc/auth_gss/svcauth_gss.c +1 -1
index 152790e..f1aabab 100644
@@ -896,7 +896,7 @@ u32 svcauth_gss_flavor(struct auth_domain *dom)
 	if (svc_getnl(&buf->head[0]) != seq)
 		goto out;
 	/* trim off the mic and padding at the end before returning */
-	xdr_buf_trim(buf, round_up_to_quad(mic.len) + 4);
+	buf->len -= 4 + round_up_to_quad(mic.len);
 	stat = 0;
 out:
 	kfree(mic.data);
net/sunrpc/xdr.c +0 -41

47 lines not on this page · raw message

#18 lore raw

PATCH 18/23 SUNRPC: Add SPDX IDs to some net/sunrpc/auth_gss/ files

In reply to Chuck Lever

Files under net/sunrpc/auth_gss/ do not yet have SPDX ID tags. This directory is somewhat complicated because most of these files have license boilerplate that is not strictly GPL 2.0.

In this patch I add ID tags where there is an obvious match. The less recognizable licenses are still under research.

For reference, SPDX IDs added in this patch correspond to the following license text:

GPL-2.0         https://spdx.org/licenses/GPL-2.0.html
GPL-2.0+        https://spdx.org/licenses/GPL-2.0+.html
BSD-3-Clause    https://spdx.org/licenses/BSD-3-Clause.html
Cc Simo Sorce <[email protected]>
Cc Kate Stewart <[email protected]>
---
 net/sunrpc/auth_gss/auth_gss.c        |   27 +--------------------------
 net/sunrpc/auth_gss/gss_krb5_mech.c   |   27 +--------------------------
 net/sunrpc/auth_gss/gss_mech_switch.c |   27 +--------------------------
 net/sunrpc/auth_gss/gss_rpc_upcall.c  |   15 +--------------
 net/sunrpc/auth_gss/gss_rpc_upcall.h  |   16 ++--------------
 net/sunrpc/auth_gss/gss_rpc_xdr.c     |   15 +--------------
 net/sunrpc/auth_gss/gss_rpc_xdr.h     |   17 +----------------
 net/sunrpc/auth_gss/svcauth_gss.c     |    1 +
 8 files changed, 9 insertions(+), 136 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +1 -26
index 3d1fbd6..fda454c 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-3-Clause
 /*
  * linux/net/sunrpc/auth_gss/auth_gss.c
  *
@@ -8,34 +9,8 @@
  *
  *  Dug Song       <[email protected]>
  *  Andy Adamson   <[email protected]>
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions
- *  are met:
- *
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *  3. Neither the name of the University nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
net/sunrpc/auth_gss/gss_krb5_mech.c +1 -26
index be31a58..56cc85c 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-3-Clause
 /*
  *  linux/net/sunrpc/gss_krb5_mech.c
  *
@@ -6,32 +7,6 @@
  *
  *  Andy Adamson <[email protected]>
  *  J. Bruce Fields <[email protected]>
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions
- *  are met:
- *
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *  3. Neither the name of the University nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
  */
 
 #include <crypto/hash.h>
net/sunrpc/auth_gss/gss_mech_switch.c +1 -26
index 379318d..8206009 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-3-Clause
 /*
  *  linux/net/sunrpc/gss_mech_switch.c
  *
@@ -5,32 +6,6 @@
  *  All rights reserved.
  *
  *  J. Bruce Fields   <[email protected]>
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions
- *  are met:
- *
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *  3. Neither the name of the University nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
  */
 
 #include <linux/types.h>
net/sunrpc/auth_gss/gss_rpc_upcall.c +1 -14
index 73dcda0..0349f45 100644
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  *  linux/net/sunrpc/gss_rpc_upcall.c
  *
  *  Copyright (C) 2012 Simo Sorce <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/types.h>
net/sunrpc/auth_gss/gss_rpc_upcall.h +2 -14
index 1e542ad..31e9634 100644
@@ -1,21 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  *  linux/net/sunrpc/gss_rpc_upcall.h
  *
  *  Copyright (C) 2012 Simo Sorce <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #ifndef _GSS_RPC_UPCALL_H
@@ -45,4 +32,5 @@ int gssp_accept_sec_context_upcall(struct net *net,
 void init_gssp_clnt(struct sunrpc_net *);
 int set_gssp_clnt(struct net *);
 void clear_gssp_clnt(struct sunrpc_net *);
+
 #endif /* _GSS_RPC_UPCALL_H */
net/sunrpc/auth_gss/gss_rpc_xdr.c +1 -14
index 006062a..2ff7b70 100644
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * GSS Proxy upcall module
  *
  *  Copyright (C) 2012 Simo Sorce <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/sunrpc/svcauth.h>
net/sunrpc/auth_gss/gss_rpc_xdr.h +1 -16
index 146c310..3f17411 100644
@@ -1,21 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * GSS Proxy upcall module
  *
  *  Copyright (C) 2012 Simo Sorce <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #ifndef _LINUX_GSS_RPC_XDR_H
@@ -262,6 +249,4 @@ int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
 #define GSSX_ARG_wrap_size_limit_sz 0
 #define GSSX_RES_wrap_size_limit_sz 0
 
-
-
 #endif /* _LINUX_GSS_RPC_XDR_H */
net/sunrpc/auth_gss/svcauth_gss.c +1 -0
index f1aabab..0c5d789 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Neil Brown <[email protected]>
  * J. Bruce Fields <[email protected]>
#19 lore raw

PATCH 19/23 SUNRPC: Introduce rpc_prepare_reply_pages()

In reply to Chuck Lever

prepare_reply_buffer() and its NFSv4 equivalents expose the details of the RPC header and the auth slack values to upper layer consumers, creating a layering violation, and duplicating code.

Remedy these issues by adding a new RPC client API that hides those details from upper layers in a common helper function.

---
 fs/nfs/nfs2xdr.c              |   27 +++++-----------------
 fs/nfs/nfs3xdr.c              |   29 ++++++-----------------
 fs/nfs/nfs4xdr.c              |   51 +++++++++++++++++------------------------
 include/linux/sunrpc/clnt.h   |    3 ++
 include/trace/events/sunrpc.h |   37 ++++++++++++++++++++++++++++++
 net/sunrpc/clnt.c             |   19 +++++++++++++++
 net/sunrpc/xdr.c              |    9 +++++++
 7 files changed, 102 insertions(+), 73 deletions(-)
fs/nfs/nfs2xdr.c +6 -21
index bac3a4e..1dcd0fe 100644
@@ -66,21 +66,6 @@
 static int nfs_stat_to_errno(enum nfs_stat);
 
 /*
- * While encoding arguments, set up the reply buffer in advance to
- * receive reply data directly into the page cache.
- */
-static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
-				 unsigned int base, unsigned int len,
-				 unsigned int bufsize)
-{
-	struct rpc_auth	*auth = req->rq_cred->cr_auth;
-	unsigned int replen;
-
-	replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
-	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
-}
-
-/*
  * Encode/decode NFSv2 basic data types
  *
  * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
@@ -593,8 +578,8 @@ static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req,
 	const struct nfs_readlinkargs *args = data;
 
 	encode_fhandle(xdr, args->fh);
-	prepare_reply_buffer(req, args->pages, args->pgbase,
-					args->pglen, NFS_readlinkres_sz);
+	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
+				args->pglen, NFS_readlinkres_sz);
 }
 
 /*
@@ -629,8 +614,8 @@ static void nfs2_xdr_enc_readargs(struct rpc_rqst *req,
 	const struct nfs_pgio_args *args = data;
 
 	encode_readargs(xdr, args);
-	prepare_reply_buffer(req, args->pages, args->pgbase,
-					args->count, NFS_readres_sz);
+	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
+				args->count, NFS_readres_sz);
 	req->rq_rcv_buf.flags |= XDRBUF_READ;
 }
 
@@ -787,8 +772,8 @@ static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req,
 	const struct nfs_readdirargs *args = data;
 
 	encode_readdirargs(xdr, args);
-	prepare_reply_buffer(req, args->pages, 0,
-					args->count, NFS_readdirres_sz);
+	rpc_prepare_reply_pages(req, args->pages, 0,
+				args->count, NFS_readdirres_sz);
 }
 
 /*
fs/nfs/nfs3xdr.c +7 -22
index 4aa3ffe..a54dcf4 100644
@@ -105,21 +105,6 @@
 };
 
 /*
- * While encoding arguments, set up the reply buffer in advance to
- * receive reply data directly into the page cache.
- */
-static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
-				 unsigned int base, unsigned int len,
-				 unsigned int bufsize)
-{
-	struct rpc_auth	*auth = req->rq_cred->cr_auth;
-	unsigned int replen;
-
-	replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
-	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
-}
-
-/*
  * Encode/decode NFSv3 basic data types
  *
  * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
@@ -910,8 +895,8 @@ static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
 	const struct nfs3_readlinkargs *args = data;
 
 	encode_nfs_fh3(xdr, args->fh);
-	prepare_reply_buffer(req, args->pages, args->pgbase,
-					args->pglen, NFS3_readlinkres_sz);
+	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
+				args->pglen, NFS3_readlinkres_sz);
 }
 
 /*
@@ -943,8 +928,8 @@ static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
 	unsigned int replen = args->replen ? args->replen : NFS3_readres_sz;
 
 	encode_read3args(xdr, args);
-	prepare_reply_buffer(req, args->pages, args->pgbase,
-					args->count, replen);
+	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
+				args->count, replen);
 	req->rq_rcv_buf.flags |= XDRBUF_READ;
 }
 
@@ -1236,7 +1221,7 @@ static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
 	const struct nfs3_readdirargs *args = data;
 
 	encode_readdir3args(xdr, args);
-	prepare_reply_buffer(req, args->pages, 0,
+	rpc_prepare_reply_pages(req, args->pages, 0,
 				args->count, NFS3_readdirres_sz);
 }
 
@@ -1278,7 +1263,7 @@ static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
 	const struct nfs3_readdirargs *args = data;
 
 	encode_readdirplus3args(xdr, args);
-	prepare_reply_buffer(req, args->pages, 0,
+	rpc_prepare_reply_pages(req, args->pages, 0,
 				args->count, NFS3_readdirres_sz);
 }
 
@@ -1323,7 +1308,7 @@ static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
 	encode_nfs_fh3(xdr, args->fh);
 	encode_uint32(xdr, args->mask);
 	if (args->mask & (NFS_ACL | NFS_DFACL)) {
-		prepare_reply_buffer(req, args->pages, 0,
+		rpc_prepare_reply_pages(req, args->pages, 0,
 					NFSACL_MAXPAGES << PAGE_SHIFT,
 					ACL3_getaclres_sz);
 		req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
fs/nfs/nfs4xdr.c +21 -30

115 lines not on this page · raw message

include/linux/sunrpc/clnt.h +3 -0
index 1c44171..98bc988 100644
@@ -169,6 +169,9 @@ int		rpcb_v4_register(struct net *net, const u32 program,
 				 const char *netid);
 void		rpcb_getport_async(struct rpc_task *);
 
+void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
+			     unsigned int base, unsigned int len,
+			     unsigned int hdrsize);
 void		rpc_call_start(struct rpc_task *);
 int		rpc_call_async(struct rpc_clnt *clnt,
 			       const struct rpc_message *msg, int flags,
include/trace/events/sunrpc.h +37 -0
index e58dda8..8451f30 100644
@@ -461,6 +461,43 @@
 	)
 );
 
+TRACE_EVENT(rpc_reply_pages,
+	TP_PROTO(
+		const struct rpc_rqst *req
+	),
+
+	TP_ARGS(req),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, task_id)
+		__field(unsigned int, client_id)
+		__field(const void *, head_base)
+		__field(size_t, head_len)
+		__field(const void *, tail_base)
+		__field(size_t, tail_len)
+		__field(unsigned int, page_len)
+	),
+
+	TP_fast_assign(
+		__entry->task_id = req->rq_task->tk_pid;
+		__entry->client_id = req->rq_task->tk_client->cl_clid;
+
+		__entry->head_base = req->rq_rcv_buf.head[0].iov_base;
+		__entry->head_len = req->rq_rcv_buf.head[0].iov_len;
+		__entry->page_len = req->rq_rcv_buf.page_len;
+		__entry->tail_base = req->rq_rcv_buf.tail[0].iov_base;
+		__entry->tail_len = req->rq_rcv_buf.tail[0].iov_len;
+	),
+
+	TP_printk(
+		"task:%u@%u xdr=[%p,%zu]/%u/[%p,%zu]\n",
+		__entry->task_id, __entry->client_id,
+		__entry->head_base, __entry->head_len,
+		__entry->page_len,
+		__entry->tail_base, __entry->tail_len
+	)
+);
+
 /*
  * First define the enums in the below macros to be exported to userspace
  * via TRACE_DEFINE_ENUM().
net/sunrpc/clnt.c +19 -0
index 803e931..f780605 100644
@@ -1164,6 +1164,25 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req)
 }
 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
 
+/**
+ * rpc_prepare_reply_pages - Prepare to receive a reply data payload into pages
+ * @req: RPC request to prepare
+ * @pages: vector of struct page pointers
+ * @base: offset in first page where receive should start, in bytes
+ * @len: expected size of the upper layer data payload, in bytes
+ * @hdrsize: expected size of upper layer reply header, in XDR words
+ *
+ */
+void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
+			     unsigned int base, unsigned int len,
+			     unsigned int hdrsize)
+{
+	hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+	xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
+	trace_rpc_reply_pages(req);
+}
+EXPORT_SYMBOL_GPL(rpc_prepare_reply_pages);
+
 void
 rpc_call_start(struct rpc_task *task)
 {
net/sunrpc/xdr.c +9 -0
index 4bce619..7cca515 100644
@@ -163,6 +163,15 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 	buf->bvec = NULL;
 }
 
+/**
+ * xdr_inline_pages - Prepare receive buffer for a large reply
+ * @xdr: xdr_buf into which reply will be placed
+ * @offset: expected offset where data payload will start, in bytes
+ * @pages: vector of struct page pointers
+ * @base: offset in first page where receive should start, in bytes
+ * @len: expected size of the upper layer data payload, in bytes
+ *
+ */
 void
 xdr_inline_pages(struct xdr_buf *xdr, unsigned int offset,
 		 struct page **pages, unsigned int base, unsigned int len)
#20 lore raw

PATCH 20/23 NFS: Account for XDR pad of buf->pages

In reply to Chuck Lever

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---
 fs/nfs/nfs2xdr.c  |    6 +++---
 fs/nfs/nfs3xdr.c  |   10 +++++-----
 fs/nfs/nfs4xdr.c  |   15 ++++++++-------
 net/sunrpc/clnt.c |    6 +++++-
 net/sunrpc/xdr.c  |    2 ++
 5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz		(1+NFS_fattr_sz)
 #define NFS_diropres_sz		(1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz	(2)
-#define NFS_readres_sz		(1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz	(2+1)
+#define NFS_readres_sz		(1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz		(1)
-#define NFS_readdirres_sz	(1)
+#define NFS_readdirres_sz	(1+1)
 #define NFS_statfsres_sz	(1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz	(NFS3_setattrres_sz)
 #define NFS3_lookupres_sz	(1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz	(1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz	(1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz		(1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz	(1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz		(1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz	(1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz	(1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz	(1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz		(1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz	(1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz	(1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz	(1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz	(1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz	(1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz	(NFS3_fh_sz+1+ \
 				XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz	(1+NFS3_post_op_attr_sz+1+ \
-				XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+				XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz	(1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
 	result->op_status = status;
 	if (status != NFS3_OK)
 		goto out_status;
-	result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+	result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
 	error = decode_read3resok(xdr, result);
 out:
 	return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 				 nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz	(op_encode_hdr_maxsz + \
 				 encode_stateid_maxsz + 3)
-#define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz	(op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
 				 2 + encode_verifier_maxsz + 5 + \
 				nfs4_label_maxsz)
 #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
-				 decode_verifier_maxsz)
+				 decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
-#define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz	(op_encode_hdr_maxsz + \
 				 encode_stateid_maxsz + 4)
 #define decode_write_maxsz	(op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz	(encode_getattr_maxsz)
 #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
-				 nfs4_fattr_bitmap_maxsz + 1)
+				 nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
 				 encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz	(decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
 				(encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-				(0)
+				(1)
 #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 				1 /* opaque devaddr4 length */ + \
 				  /* devaddr4 payload is read into page */ \
 				1 /* notification bitmap length */ + \
-				1 /* notification bitmap, word 0 */)
+				1 /* notification bitmap, word 0 */ + \
+				1 /* possible XDR padding */)
 #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
 				encode_stateid_maxsz)
 #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
 				decode_stateid_maxsz + \
-				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
 				2 /* offset */ + \
 				2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
 			     unsigned int base, unsigned int len,
 			     unsigned int hdrsize)
 {
-	hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+	/* Subtract one to force an extra word of buffer space for the
+	 * payload's XDR pad to fall into the rcv_buf's tail iovec.
+	 */
+	hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
 	xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
 	trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +2 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
 	tail->iov_base = buf + offset;
 	tail->iov_len = buflen - offset;
+	if ((xdr->page_len & 3) == 0)
+		tail->iov_len -= sizeof(__be32);
 
 	xdr->buflen += len;
 }
#21 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Quoted 171 lines · Chuck Lever

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---
 fs/nfs/nfs2xdr.c  |    6 +++---
 fs/nfs/nfs3xdr.c  |   10 +++++-----
 fs/nfs/nfs4xdr.c  |   15 ++++++++-------
 net/sunrpc/clnt.c |    6 +++++-
 net/sunrpc/xdr.c  |    2 ++
 5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                                XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
        result->op_status = status;
        if (status != NFS3_OK)
                goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
        error = decode_read3resok(xdr, result);
 out:
        return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                                 nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                                 encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                                 2 + encode_verifier_maxsz + 5 + \
                                nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                                 encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                                 encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                                (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                                1 /* opaque devaddr4 length */ + \
                                  /* devaddr4 payload is read into page */ \
                                1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                                encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                                decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                                2 /* offset */ + \
                                2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                             unsigned int base, unsigned int len,
                             unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
        xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
        trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +2 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
        tail->iov_base = buf + offset;
        tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
        xdr->buflen += len;
 }
#22 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 8 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 164 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
       result->op_status = status;
       if (status != NFS3_OK)
               goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
       error = decode_read3resok(xdr, result);

out:

       return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                                nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                                2 + encode_verifier_maxsz + 5 + \
                               nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                               1 /* opaque devaddr4 length */ + \
                                 /* devaddr4 payload is read into page */ \
                               1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                               encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                               decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                               2 /* offset */ + \
                               2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                            unsigned int base, unsigned int len,
                            unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
       xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
       trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
       tail->iov_base = buf + offset;
       tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
       xdr->buflen += len;
 }

--
Chuck Lever

#23 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 5 lines · Chuck Lever
Quoted 5 lines · Olga Kornievskaia
Quoted 8 lines
Quoted 4 lines

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified. The question is:
can't we just revert it??

Quoted 179 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
       result->op_status = status;
       if (status != NFS3_OK)
               goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
       error = decode_read3resok(xdr, result);

out:

       return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                                nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                                2 + encode_verifier_maxsz + 5 + \
                               nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                               1 /* opaque devaddr4 length */ + \
                                 /* devaddr4 payload is read into page */ \
                               1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                               encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                               decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                               2 /* offset */ + \
                               2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                            unsigned int base, unsigned int len,
                            unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
       xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
       trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
       tail->iov_base = buf + offset;
       tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
       xdr->buflen += len;
 }

--
Chuck Lever

#24 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 15 lines · Olga Kornievskaia
Quoted 10 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Quoted 6 lines
Quoted 3 lines

Possibly the macro that defines the maximum size of the reply is incorrect.

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

Quoted 169 lines
Quoted 169 lines
Quoted 169 lines · Chuck Lever
Quoted 168 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                              XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
      result->op_status = status;
      if (status != NFS3_OK)
              goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
      error = decode_read3resok(xdr, result);

out:

      return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                               nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                               2 + encode_verifier_maxsz + 5 + \
                              nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                              (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                              1 /* opaque devaddr4 length */ + \
                                /* devaddr4 payload is read into page */ \
                              1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                              encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                              decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                              2 /* offset */ + \
                              2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                           unsigned int base, unsigned int len,
                           unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
      xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
      trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +2 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
      tail->iov_base = buf + offset;
      tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 3 lines
net/sunrpc/xdr.c +0 -0
      xdr->buflen += len;
 }

--
Chuck Lever

--
Chuck Lever

#25 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 16 lines · Chuck Lever
Quoted 16 lines · Olga Kornievskaia
Quoted 10 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Possibly the macro that defines the maximum size of the reply is incorrect.

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Quoted 183 lines
Quoted 171 lines
Quoted 171 lines
Quoted 171 lines · Chuck Lever
Quoted 168 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                              XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
      result->op_status = status;
      if (status != NFS3_OK)
              goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
      error = decode_read3resok(xdr, result);

out:

      return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                               nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                               2 + encode_verifier_maxsz + 5 + \
                              nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                              (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                              1 /* opaque devaddr4 length */ + \
                                /* devaddr4 payload is read into page */ \
                              1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                              encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                              decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                              2 /* offset */ + \
                              2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                           unsigned int base, unsigned int len,
                           unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
      xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
      trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +2 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
      tail->iov_base = buf + offset;
      tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 3 lines
net/sunrpc/xdr.c +0 -0
      xdr->buflen += len;
 }

--
Chuck Lever

--
Chuck Lever

#26 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 25 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

fs/nfs/nfs4xdr.c +0 -0
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,

#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
#define encode_getacl_maxsz (encode_getattr_maxsz)
#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
- nfs4_fattr_bitmap_maxsz + 1)
+ nfs4_fattr_bitmap_maxsz + 1 + 1)
#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
encode_stateid_maxsz + 3)
#define decode_setacl_maxsz (decode_setattr_maxsz)
#define encode_fs_locations_maxsz \
(encode_getattr_maxsz)
#define decode_fs_locations_maxsz \
- (0)
+ (1)
#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))

Quoted 176 lines
Quoted 176 lines
Quoted 175 lines
Quoted 175 lines
Quoted 164 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                             XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
     result->op_status = status;
     if (status != NFS3_OK)
             goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
     error = decode_read3resok(xdr, result);

out:

     return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                              nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                              encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                              2 + encode_verifier_maxsz + 5 + \
                             nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                              encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                              encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                             (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             1 /* opaque devaddr4 length */ + \
                               /* devaddr4 payload is read into page */ \
                             1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                             encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                             decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                             2 /* offset */ + \
                             2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                          unsigned int base, unsigned int len,
                          unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
     xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
     trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
     tail->iov_base = buf + offset;
     tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
     xdr->buflen += len;
 }

--
Chuck Lever

Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

#27 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 39 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

Quoted 207 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                                 encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                                (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                             XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
     result->op_status = status;
     if (status != NFS3_OK)
             goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
     error = decode_read3resok(xdr, result);

out:

     return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                              nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                              encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                              2 + encode_verifier_maxsz + 5 + \
                             nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                              encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                              encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                             (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             1 /* opaque devaddr4 length */ + \
                               /* devaddr4 payload is read into page */ \
                             1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                             encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                             decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                             2 /* offset */ + \
                             2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                          unsigned int base, unsigned int len,
                          unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
     xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
     trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
     tail->iov_base = buf + offset;
     tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
     xdr->buflen += len;
 }

--
Chuck Lever

Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

#28 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 50 lines · Olga Kornievskaia
Quoted 45 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Quoted 7 lines
Quoted 1 line

Try reverting just this hunk:

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

How do you know there isn't a latent bug in the getfacl decoder?

How are you reproducing this issue? I can try it here later today.

Quoted 198 lines
Quoted 198 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                            XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
    result->op_status = status;
    if (status != NFS3_OK)
            goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
    error = decode_read3resok(xdr, result);

out:

    return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                             2 + encode_verifier_maxsz + 5 + \
                            nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                            (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                            1 /* opaque devaddr4 length */ + \
                              /* devaddr4 payload is read into page */ \
                            1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                            encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                            decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                            2 /* offset */ + \
                            2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                         unsigned int base, unsigned int len,
                         unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
    xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
    trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
    tail->iov_base = buf + offset;
    tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
    xdr->buflen += len;
 }

--
Chuck Lever

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

#29 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 53 lines · Chuck Lever
Quoted 53 lines · Olga Kornievskaia
Quoted 46 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

Quoted 7 lines
Quoted 5 lines

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

How do you know there isn't a latent bug in the getfacl decoder?

I don't. All I know is that it passed tests before and now it doesn't.

Quoted 1 line

How are you reproducing this issue? I can try it here later today.

The issue was found running xfstest nfs/001. However, you don't need
that: (1) mount (2) nfs4_getfacl <file>

To understand a patch, does it fix a problem with READLINK or is the an optimization?

Quoted 211 lines
Quoted 200 lines
Quoted 200 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                            XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
    result->op_status = status;
    if (status != NFS3_OK)
            goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
    error = decode_read3resok(xdr, result);

out:

    return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                             2 + encode_verifier_maxsz + 5 + \
                            nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                            (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                            1 /* opaque devaddr4 length */ + \
                              /* devaddr4 payload is read into page */ \
                            1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                            encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                            decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                            2 /* offset */ + \
                            2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                         unsigned int base, unsigned int len,
                         unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
    xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
    trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
    tail->iov_base = buf + offset;
    tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
    xdr->buflen += len;
 }

--
Chuck Lever

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

#30 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 58 lines · Olga Kornievskaia
Quoted 56 lines · Chuck Lever
Quoted 56 lines · Olga Kornievskaia
Quoted 39 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

How do you know there isn't a latent bug in the getfacl decoder?

I don't. All I know is that it passed tests before and now it doesn't.

Also this bug will have to be in both getfacl and fs_location code. What they both share is xd_enter_page() code that now with new semantics makes the buffer point to the wrong place.

Quoted 219 lines
Quoted 1 line

How are you reproducing this issue? I can try it here later today.

The issue was found running xfstest nfs/001. However, you don't need
that: (1) mount (2) nfs4_getfacl <file>

To understand a patch, does it fix a problem with READLINK or is the an optimization?

Quoted 211 lines
Quoted 200 lines
Quoted 200 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                            XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
    result->op_status = status;
    if (status != NFS3_OK)
            goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
    error = decode_read3resok(xdr, result);

out:

    return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                             2 + encode_verifier_maxsz + 5 + \
                            nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                            (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                            1 /* opaque devaddr4 length */ + \
                              /* devaddr4 payload is read into page */ \
                            1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                            encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                            decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                            2 /* offset */ + \
                            2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                         unsigned int base, unsigned int len,
                         unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
    xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
    trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
    tail->iov_base = buf + offset;
    tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
    xdr->buflen += len;
 }

--
Chuck Lever

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

#31 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 63 lines · Olga Kornievskaia
Quoted 61 lines · Olga Kornievskaia
Quoted 59 lines · Chuck Lever
Quoted 58 lines · Olga Kornievskaia
Quoted 39 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

Quoted 15 lines
Quoted 3 lines
Quoted 1 line

How do you know there isn't a latent bug in the getfacl decoder?

I don't. All I know is that it passed tests before and now it doesn't.

Also this bug will have to be in both getfacl and fs_location code. What they both share is xd_enter_page() code that now with new semantics makes the buffer point to the wrong place.

Quoted 7 lines
Quoted 1 line

How are you reproducing this issue? I can try it here later today.

The issue was found running xfstest nfs/001. However, you don't need
that: (1) mount (2) nfs4_getfacl <file>

To understand a patch, does it fix a problem with READLINK or is the an optimization?

So this "fixes" it but this don't look really good.

fs/nfs/nfs4xdr.c +0 -0
index cfcabc3..f2a5553 100644

@@ -5280,6 +5280,7 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
goto out;
xdr_enter_page(xdr, xdr->buf->page_len);
+ xdr->p++;

/* Calculate the offset of the page data */
pg_offset = xdr->buf->head[0].iov_len;
@@ -6949,6 +6950,7 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
goto out;
if (res->migration) {
xdr_enter_page(xdr, PAGE_SIZE);
+ xdr->p++;
status = decode_getfattr_generic(xdr,
&res->fs_locations->fattr,
NULL, res->fs_locations,
@@ -6962,6 +6964,7 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
if (status)
goto out;
xdr_enter_page(xdr, PAGE_SIZE);
+ xdr->p++;
status = decode_getfattr_generic(xdr,
&res->fs_locations->fattr,
NULL, res->fs_locations,

Quoted 212 lines
Quoted 212 lines
Quoted 212 lines
Quoted 201 lines
Quoted 201 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                            XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
    result->op_status = status;
    if (status != NFS3_OK)
            goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
    error = decode_read3resok(xdr, result);

out:

    return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                             2 + encode_verifier_maxsz + 5 + \
                            nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                            (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                            1 /* opaque devaddr4 length */ + \
                              /* devaddr4 payload is read into page */ \
                            1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                            encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                            decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                            2 /* offset */ + \
                            2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                         unsigned int base, unsigned int len,
                         unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
    xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
    trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
    tail->iov_base = buf + offset;
    tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
    xdr->buflen += len;
 }

--
Chuck Lever

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

#32 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

Quoted 65 lines · Olga Kornievskaia
Quoted 63 lines · Olga Kornievskaia
Quoted 61 lines · Olga Kornievskaia
Quoted 59 lines · Chuck Lever
Quoted 58 lines · Olga Kornievskaia
Quoted 39 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

How do you know there isn't a latent bug in the getfacl decoder?

I don't. All I know is that it passed tests before and now it doesn't.

Also this bug will have to be in both getfacl and fs_location code. What they both share is xd_enter_page() code that now with new semantics makes the buffer point to the wrong place.

READLINK uses xdr_read_pages() function which sets the xdr->p and accounts for padding which xdr_enter_page() does not.

Quoted 254 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

How are you reproducing this issue? I can try it here later today.

The issue was found running xfstest nfs/001. However, you don't need
that: (1) mount (2) nfs4_getfacl <file>

To understand a patch, does it fix a problem with READLINK or is the an optimization?

So this "fixes" it but this don't look really good.

fs/nfs/nfs4xdr.c +3 -0
index cfcabc3..f2a5553 100644
@@ -5280,6 +5280,7 @@ static int decode_getacl(struct xdr_stream *xdr,
 struct rpc_rqst *req,
  goto out;
  xdr_enter_page(xdr, xdr->buf->page_len);
+ xdr->p++;
 
  /* Calculate the offset of the page data */
  pg_offset = xdr->buf->head[0].iov_len;
@@ -6949,6 +6950,7 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  goto out;
  if (res->migration) {
  xdr_enter_page(xdr, PAGE_SIZE);
+ xdr->p++;
  status = decode_getfattr_generic(xdr,
  &res->fs_locations->fattr,
  NULL, res->fs_locations,
@@ -6962,6 +6964,7 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  if (status)
  goto out;
  xdr_enter_page(xdr, PAGE_SIZE);
+ xdr->p++;
  status = decode_getfattr_generic(xdr,
  &res->fs_locations->fattr,
  NULL, res->fs_locations,
Quoted 214 lines
Quoted 214 lines
Quoted 214 lines
Quoted 203 lines
Quoted 203 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                                encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                               (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                            XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
    result->op_status = status;
    if (status != NFS3_OK)
            goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
    error = decode_read3resok(xdr, result);

out:

    return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                             nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                             2 + encode_verifier_maxsz + 5 + \
                            nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                             encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                            (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                            1 /* opaque devaddr4 length */ + \
                              /* devaddr4 payload is read into page */ \
                            1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                            encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                            decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                            2 /* offset */ + \
                            2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                         unsigned int base, unsigned int len,
                         unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
    xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
    trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
    tail->iov_base = buf + offset;
    tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
    xdr->buflen += len;
 }

--
Chuck Lever

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

#33 lore raw

Re: [PATCH v1 20/23] NFS: Account for XDR pad of buf->pages

In reply to Olga Kornievskaia
Quoted 108 lines · Olga Kornievskaia
Quoted 63 lines · Olga Kornievskaia
Quoted 61 lines · Olga Kornievskaia
Quoted 59 lines · Chuck Lever
Quoted 58 lines · Olga Kornievskaia
Quoted 39 lines · Chuck Lever
Quoted 26 lines · Olga Kornievskaia
Quoted 20 lines · Chuck Lever
Quoted 20 lines · Olga Kornievskaia
Quoted 13 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

Hi Chuck,

This patch break ACLs. After applying this patch nfs4_getfacl fails (it fails within xdr and returns ENOTSUPP). Any ideas why?

Possibly the macro that defines the maximum size of the reply is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This also breaks FS_LOCATION. I'm going to go on the limb here and say that it probably breaks whatever else it modified.

It modifies READ, READDIR, and READLINK. Are those broken?

I don't know how to test READLINK.. but I think READ/READDIR work OK otherwise folks would have noticed it (I gather ACL and FS_LOCATION testing doesn't happen frequently).

I guess I don't have any NFSv4 ACL or FS_LOCATIONS regressions tests in my automated unit tests.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The question is: can't we just revert it??

Why not "root cause" it first?

I'm trying :-/ I was just fishing to see how important the change was.

Try reverting just this hunk:

That doesn't help. It seems to be this piece that's causing issues hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1

With this there is an extra byte (in front) in the buffer when (ACL) operation is decoded.

Quoted 15 lines
Quoted 3 lines
Quoted 1 line

How do you know there isn't a latent bug in the getfacl decoder?

I don't. All I know is that it passed tests before and now it doesn't.

Also this bug will have to be in both getfacl and fs_location code. What they both share is xd_enter_page() code that now with new semantics makes the buffer point to the wrong place.

Quoted 7 lines
Quoted 1 line

How are you reproducing this issue? I can try it here later today.

The issue was found running xfstest nfs/001. However, you don't need
that: (1) mount (2) nfs4_getfacl <file>

To understand a patch, does it fix a problem with READLINK or is the an optimization?

So this "fixes" it but this don't look really good.

fs/nfs/nfs4xdr.c +2 -0
index cfcabc3..f2a5553 100644
@@ -5280,6 +5280,7 @@ static int decode_getacl(struct xdr_stream *xdr,
 struct rpc_rqst *req,
 goto out;
 xdr_enter_page(xdr, xdr->buf->page_len);
+ xdr->p++;
 
 /* Calculate the offset of the page data */
 pg_offset = xdr->buf->head[0].iov_len;
@@ -6949,6 +6950,7 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
 goto out;
 if (res->migration) {
 xdr_enter_page(xdr, PAGE_SIZE);
+ xdr->p++;
 status = decode_getfattr_generic(xdr,
 &res->fs_locations->fattr,
 NULL, res->fs_locations,

fs/nfs/nfs4xdr.c static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, · line 6970

Quoted 7 lines
fs/nfs/nfs4xdr.c +1 -0
@@ -6962,6 +6964,7 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
 if (status)
 goto out;
 xdr_enter_page(xdr, PAGE_SIZE);
+ xdr->p++;
 status = decode_getfattr_generic(xdr,
 &res->fs_locations->fattr,
 NULL, res->fs_locations,

Your workaround appears to advance xdr->p one quad into the first page in the xdr_buf. We really want that XDR data item to fall right at offset 0 of that page.

I'm looking into it.

Quoted 198 lines
Quoted 198 lines
Quoted 198 lines
Quoted 198 lines
Quoted 198 lines
Quoted 198 lines
fs/nfs/nfs4xdr.c +2 -2
index d0fa18d..6d9d5e2 100644
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz     (encode_getattr_maxsz)
 #define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
                               encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz     (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                              (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
Quoted 177 lines
Quoted 177 lines
Quoted 176 lines
Quoted 176 lines
Quoted 165 lines · Chuck Lever
Quoted 163 lines

Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word.

In each case where the data payload is to be received into pages:

- 1 word is added to the size of the receive buffer allocated by call_allocate

- rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec

- If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail

---

fs/nfs/nfs2xdr.c  |    6 +++---
fs/nfs/nfs3xdr.c  |   10 +++++-----
fs/nfs/nfs4xdr.c  |   15 ++++++++-------
net/sunrpc/clnt.c |    6 +++++-
net/sunrpc/xdr.c  |    2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
fs/nfs/nfs2xdr.c +3 -3
index 1dcd0fe..a7ed29d 100644
@@ -56,11 +56,11 @@
 
 #define NFS_attrstat_sz                (1+NFS_fattr_sz)
 #define NFS_diropres_sz                (1+NFS_fhandle_sz+NFS_fattr_sz)
-#define NFS_readlinkres_sz     (2)
-#define NFS_readres_sz         (1+NFS_fattr_sz+1)
+#define NFS_readlinkres_sz     (2+1)
+#define NFS_readres_sz         (1+NFS_fattr_sz+1+1)
 #define NFS_writeres_sz         (NFS_attrstat_sz)
 #define NFS_stat_sz            (1)
-#define NFS_readdirres_sz      (1)
+#define NFS_readdirres_sz      (1+1)
 #define NFS_statfsres_sz       (1+NFS_info_sz)
 
 static int nfs_stat_to_errno(enum nfs_stat);
fs/nfs/nfs3xdr.c +5 -5
index a54dcf4..110358f 100644
@@ -69,13 +69,13 @@
 #define NFS3_removeres_sz      (NFS3_setattrres_sz)
 #define NFS3_lookupres_sz      (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
 #define NFS3_accessres_sz      (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1)
-#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3)
+#define NFS3_readlinkres_sz    (1+NFS3_post_op_attr_sz+1+1)
+#define NFS3_readres_sz                (1+NFS3_post_op_attr_sz+3+1)
 #define NFS3_writeres_sz       (1+NFS3_wcc_data_sz+4)
 #define NFS3_createres_sz      (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
 #define NFS3_renameres_sz      (1+(2 * NFS3_wcc_data_sz))
 #define NFS3_linkres_sz                (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
-#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2)
+#define NFS3_readdirres_sz     (1+NFS3_post_op_attr_sz+2+1)
 #define NFS3_fsstatres_sz      (1+NFS3_post_op_attr_sz+13)
 #define NFS3_fsinfores_sz      (1+NFS3_post_op_attr_sz+12)
 #define NFS3_pathconfres_sz    (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
 #define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
                           XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
-                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
   result->op_status = status;
   if (status != NFS3_OK)
           goto out_status;
-       result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
+       result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
   error = decode_read3resok(xdr, result);

out:

   return error;
fs/nfs/nfs4xdr.c +8 -7
index d0fa18d..6d9d5e2 100644
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                            nfs4_fattr_bitmap_maxsz)
 #define encode_read_maxsz      (op_encode_hdr_maxsz + \
                            encode_stateid_maxsz + 3)
-#define decode_read_maxsz      (op_decode_hdr_maxsz + 2)
+#define decode_read_maxsz      (op_decode_hdr_maxsz + 2 + 1)
 #define encode_readdir_maxsz   (op_encode_hdr_maxsz + \
                            2 + encode_verifier_maxsz + 5 + \
                           nfs4_label_maxsz)
 #define decode_readdir_maxsz   (op_decode_hdr_maxsz + \
-                                decode_verifier_maxsz)
+                                decode_verifier_maxsz + 1)
 #define encode_readlink_maxsz  (op_encode_hdr_maxsz)
-#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1)
+#define decode_readlink_maxsz  (op_decode_hdr_maxsz + 1 + 1)
 #define encode_write_maxsz     (op_encode_hdr_maxsz + \
                            encode_stateid_maxsz + 4)
 #define decode_write_maxsz     (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 #define encode_getacl_maxsz    (encode_getattr_maxsz)
 #define decode_getacl_maxsz    (op_decode_hdr_maxsz + \
-                                nfs4_fattr_bitmap_maxsz + 1)
+                                nfs4_fattr_bitmap_maxsz + 1 + 1)
 #define encode_setacl_maxsz    (op_encode_hdr_maxsz + \
                            encode_stateid_maxsz + 3)
 #define decode_setacl_maxsz    (decode_setattr_maxsz)
 #define encode_fs_locations_maxsz \
                           (encode_getattr_maxsz)
 #define decode_fs_locations_maxsz \
-                               (0)
+                               (1)
 #define encode_secinfo_maxsz   (op_encode_hdr_maxsz + nfs4_name_maxsz)
 #define decode_secinfo_maxsz   (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 
@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                           1 /* opaque devaddr4 length */ + \
                             /* devaddr4 payload is read into page */ \
                           1 /* notification bitmap length */ + \
-                               1 /* notification bitmap, word 0 */)
+                               1 /* notification bitmap, word 0 */ + \
+                               1 /* possible XDR padding */)
 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
                           encode_stateid_maxsz)
 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
                           decode_stateid_maxsz + \
-                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
+                               XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
                           2 /* offset */ + \
                           2 /* length */ + \
net/sunrpc/clnt.c +5 -1
index f780605..4ea38b0 100644
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
                        unsigned int base, unsigned int len,
                        unsigned int hdrsize)
 {
-       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
+       /* Subtract one to force an extra word of buffer space for the
+        * payload's XDR pad to fall into the rcv_buf's tail iovec.
+        */
+       hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+
   xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
   trace_rpc_reply_pages(req);
 }
net/sunrpc/xdr.c +0 -0
index 7cca515..aa8177d 100644
@@ -189,6 +189,8 @@ __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
 
Quoted 8 lines

net/sunrpc/xdr.c __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) · line 196

Quoted 8 lines
net/sunrpc/xdr.c +2 -0
   tail->iov_base = buf + offset;
   tail->iov_len = buflen - offset;
+       if ((xdr->page_len & 3) == 0)
+               tail->iov_len -= sizeof(__be32);
 
   xdr->buflen += len;
 }

--
Chuck Lever

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

#34 lore raw

PATCH 21/23 SUNRPC: Make AUTH_SYS and AUTH_NULL set au_verfsize

In reply to Chuck Lever

au_verfsize will be needed for a non-flavor-specific computation in a subsequent patch.

---
 include/linux/sunrpc/auth.h    |    3 +--
 net/sunrpc/auth_gss/auth_gss.c |    1 +
 net/sunrpc/auth_null.c         |    1 +
 net/sunrpc/auth_unix.c         |    5 ++++-
 4 files changed, 7 insertions(+), 3 deletions(-)
include/linux/sunrpc/auth.h +1 -2
index c51e189..359dfdd 100644
@@ -77,8 +77,7 @@ struct rpc_auth {
 				/* guess at number of u32's auth adds before
 				 * reply data; normally the verifier size: */
 	unsigned int		au_rslack;
-				/* for gss, used to calculate au_rslack: */
-	unsigned int		au_verfsize;
+	unsigned int		au_verfsize;	/* size of reply verifier */
 
 	unsigned int		au_flags;	/* various flags */
 	const struct rpc_authops *au_ops;		/* operations */
net/sunrpc/auth_gss/auth_gss.c +1 -0
index fda454c..731e7a4 100644
@@ -1016,6 +1016,7 @@ static void gss_pipe_free(struct gss_pipe *p)
 	auth = &gss_auth->rpc_auth;
 	auth->au_cslack = GSS_CRED_SLACK >> 2;
 	auth->au_rslack = GSS_VERF_SLACK >> 2;
+	auth->au_verfsize = GSS_VERF_SLACK >> 2;
 	auth->au_flags = 0;
 	auth->au_ops = &authgss_ops;
 	auth->au_flavor = flavor;
net/sunrpc/auth_null.c +1 -0
index bf96975..9ae0824 100644
@@ -114,6 +114,7 @@
 struct rpc_auth null_auth = {
 	.au_cslack	= NUL_CALLSLACK,
 	.au_rslack	= NUL_REPLYSLACK,
+	.au_verfsize	= NUL_REPLYSLACK,
 	.au_ops		= &authnull_ops,
 	.au_flavor	= RPC_AUTH_NULL,
 	.au_count	= REFCOUNT_INIT(1),
net/sunrpc/auth_unix.c +4 -1
index 5ea84a9..a93c564 100644
@@ -163,6 +163,7 @@
 static int
 unx_validate(struct rpc_task *task, struct xdr_stream *xdr)
 {
+	struct rpc_auth *auth = task->tk_rqstp->rq_cred->cr_auth;
 	__be32 *p;
 	u32 size;
 
@@ -184,7 +185,8 @@
 	if (!p)
 		return -EIO;
 
-	task->tk_rqstp->rq_cred->cr_auth->au_rslack = (size >> 2) + 2;
+	auth->au_verfsize = XDR_QUADLEN(size) + 2;
+	auth->au_rslack = XDR_QUADLEN(size) + 2;
 	return 0;
 }
 
@@ -212,6 +214,7 @@ void rpc_destroy_authunix(void)
 struct rpc_auth		unix_auth = {
 	.au_cslack	= UNX_CALLSLACK,
 	.au_rslack	= NUL_REPLYSLACK,
+	.au_verfsize	= NUL_REPLYSLACK,
 	.au_ops		= &authunix_ops,
 	.au_flavor	= RPC_AUTH_UNIX,
 	.au_count	= REFCOUNT_INIT(1),
#35 lore raw

PATCH 22/23 SUNRPC: Add rpc_auth::au_ralign field

In reply to Chuck Lever

Currently rpc_inline_rcv_pages() uses au_rslack to estimate the size of the upper layer reply header. This is fine for auth flavors where au_verfsize == au_rslack.

However, some auth flavors have more going on. krb5i for example has two more words after the verifier, and another blob following the RPC message. The calculation involving au_rslack pushes the upper layer reply header too far into the rcv_buf.

au_rslack is still valuable: it's the amount of buffer space needed for the reply, and is used when allocating the reply buffer. We'll keep that.

But, add a new field that can be used to properly estimate the location of the upper layer header in each RPC reply, based on the auth flavor in use.

---
 include/linux/sunrpc/auth.h    |    9 ++++-----
 net/sunrpc/auth_gss/auth_gss.c |   18 +++++++++++++-----
 net/sunrpc/auth_null.c         |    1 +
 net/sunrpc/auth_unix.c         |    1 +
 net/sunrpc/clnt.c              |    2 +-
 5 files changed, 20 insertions(+), 11 deletions(-)
include/linux/sunrpc/auth.h +4 -5
index 359dfdd..5f9076f 100644
@@ -74,13 +74,12 @@ struct rpc_cred {
 struct rpc_authops;
 struct rpc_auth {
 	unsigned int		au_cslack;	/* call cred size estimate */
-				/* guess at number of u32's auth adds before
-				 * reply data; normally the verifier size: */
-	unsigned int		au_rslack;
+	unsigned int		au_rslack;	/* reply cred size estimate */
 	unsigned int		au_verfsize;	/* size of reply verifier */
+	unsigned int		au_ralign;	/* words before UL header */
 
-	unsigned int		au_flags;	/* various flags */
-	const struct rpc_authops *au_ops;		/* operations */
+	unsigned int		au_flags;
+	const struct rpc_authops *au_ops;
 	rpc_authflavor_t	au_flavor;	/* pseudoflavor (note may
 						 * differ from the flavor in
 						 * au_ops->au_flavor in gss
net/sunrpc/auth_gss/auth_gss.c +13 -5
index 731e7a4..c67e2ad 100644
@@ -1017,6 +1017,7 @@ static void gss_pipe_free(struct gss_pipe *p)
 	auth->au_cslack = GSS_CRED_SLACK >> 2;
 	auth->au_rslack = GSS_VERF_SLACK >> 2;
 	auth->au_verfsize = GSS_VERF_SLACK >> 2;
+	auth->au_ralign = GSS_VERF_SLACK >> 2;
 	auth->au_flags = 0;
 	auth->au_ops = &authgss_ops;
 	auth->au_flavor = flavor;
@@ -1891,7 +1892,10 @@ static int gss_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
 static int
 gss_unwrap_resp_auth(struct rpc_cred *cred)
 {
-	cred->cr_auth->au_rslack = cred->cr_auth->au_verfsize;
+	struct rpc_auth *auth = cred->cr_auth;
+
+	auth->au_rslack = auth->au_verfsize;
+	auth->au_ralign = auth->au_verfsize;
 	return 0;
 }
 
@@ -1902,6 +1906,7 @@ static int gss_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
 {
 	struct xdr_buf integ_buf, *rcv_buf = &rqstp->rq_rcv_buf;
 	u32 data_offset, mic_offset, integ_len, maj_stat;
+	struct rpc_auth *auth = cred->cr_auth;
 	struct xdr_netobj mic;
 	__be32 *p;
 
@@ -1928,8 +1933,8 @@ static int gss_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
 	if (maj_stat != GSS_S_COMPLETE)
 		goto bad_mic;
 
-	cred->cr_auth->au_rslack = cred->cr_auth->au_verfsize + 2 +
-				   1 + XDR_QUADLEN(mic.len);
+	auth->au_rslack = auth->au_verfsize + 2 + 1 + XDR_QUADLEN(mic.len);
+	auth->au_ralign = auth->au_verfsize + 2;
 	return 0;
 unwrap_failed:
 	trace_rpcgss_unwrap_failed(task);
@@ -1949,6 +1954,7 @@ static int gss_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
 {
 	struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf;
 	struct kvec *head = rqstp->rq_rcv_buf.head;
+	struct rpc_auth *auth = cred->cr_auth;
 	unsigned int savedlen = rcv_buf->len;
 	u32 offset, opaque_len, maj_stat;
 	__be32 *p;
@@ -1976,8 +1982,10 @@ static int gss_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
 	 */
 	xdr_init_decode(xdr, rcv_buf, p, rqstp);
 
-	cred->cr_auth->au_rslack = cred->cr_auth->au_verfsize + 2 +
-				   XDR_QUADLEN(savedlen - rcv_buf->len);
+	auth->au_rslack = auth->au_verfsize + 2 +
+			  XDR_QUADLEN(savedlen - rcv_buf->len);
+	auth->au_ralign = auth->au_verfsize + 2 +
+			  XDR_QUADLEN(savedlen - rcv_buf->len);
 	return 0;
 unwrap_failed:
 	trace_rpcgss_unwrap_failed(task);
net/sunrpc/auth_null.c +1 -0
index 9ae0824..41a633a 100644
@@ -115,6 +115,7 @@ struct rpc_auth null_auth = {
 	.au_cslack	= NUL_CALLSLACK,
 	.au_rslack	= NUL_REPLYSLACK,
 	.au_verfsize	= NUL_REPLYSLACK,
+	.au_ralign	= NUL_REPLYSLACK,
 	.au_ops		= &authnull_ops,
 	.au_flavor	= RPC_AUTH_NULL,
 	.au_count	= REFCOUNT_INIT(1),
net/sunrpc/auth_unix.c +1 -0
index a93c564..c048eb6 100644
@@ -187,6 +187,7 @@
 
 	auth->au_verfsize = XDR_QUADLEN(size) + 2;
 	auth->au_rslack = XDR_QUADLEN(size) + 2;
+	auth->au_ralign = XDR_QUADLEN(size) + 2;
 	return 0;
 }
 
net/sunrpc/clnt.c +1 -1
index 4ea38b0..99bfeb1 100644
@@ -1180,7 +1180,7 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
 	/* Subtract one to force an extra word of buffer space for the
 	 * payload's XDR pad to fall into the rcv_buf's tail iovec.
 	 */
-	hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
+	hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_ralign - 1;
 
 	xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
 	trace_rpc_reply_pages(req);
#36 lore raw

PATCH 23/23 SUNRPC: Use au_rslack when computing reply buffer size

In reply to Chuck Lever

au_rslack is significantly smaller than (au_cslack << 2). Using that value results in smaller receive buffers. In some cases this eliminates an extra segment in Reply chunks (RPC/RDMA).

---
 net/sunrpc/clnt.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/sunrpc/clnt.c +4 -3
index 99bfeb1..241e842 100644
@@ -1690,7 +1690,7 @@ void rpc_force_rebind(struct rpc_clnt *clnt)
 static void
 call_allocate(struct rpc_task *task)
 {
-	unsigned int slack = task->tk_rqstp->rq_cred->cr_auth->au_cslack;
+	const struct rpc_auth *auth = task->tk_rqstp->rq_cred->cr_auth;
 	struct rpc_rqst *req = task->tk_rqstp;
 	struct rpc_xprt *xprt = req->rq_xprt;
 	const struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
@@ -1715,9 +1715,10 @@ void rpc_force_rebind(struct rpc_clnt *clnt)
 	 * and reply headers, and convert both values
 	 * to byte sizes.
 	 */
-	req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen;
+	req->rq_callsize = RPC_CALLHDRSIZE + (auth->au_cslack << 1) +
+			   proc->p_arglen;
 	req->rq_callsize <<= 2;
-	req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen;
+	req->rq_rcvsize = RPC_REPHDRSIZE + auth->au_rslack + proc->p_replen;
 	req->rq_rcvsize <<= 2;
 
 	status = xprt->ops->buf_alloc(task);