From de7c581708a749f037f8a620ed04b0d03e1ac75f Mon Sep 17 00:00:00 2001 From: Chuck Lever Date: Tue, 8 Sep 2026 09:42:25 -0400 Subject: [PATCH] SUNRPC: Carry a generated-codec context pointer in struct xdr_stream A generated XDR codec function receives only an xdr_stream, yet some codecs need state that the stream does not carry. Passing that state as an additional argument changes the signature of every function on the path from the program entry point down to the one that consumes it, and for generated code it makes each function's argument list depend on an analysis of the entire specification. Add xdrgen_ctx to struct xdr_stream, a pointer that the layer initializing the stream sets aside for generated codecs to find, following the precedent of seq_file->private and netlink_callback->data. Every xdr_stream initializer clears it, so a codec never reads a residual value left in a stream that was allocated on the stack or taken from a transport's free pool. Acked-by: Jeff Layton Reviewed-by: NeilBrown Link: https://patch.msgid.link/20260908134234.512312-2-cel@kernel.org Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 1 + include/linux/sunrpc/svc.h | 1 + include/linux/sunrpc/xdr.h | 1 + net/sunrpc/xdr.c | 3 +++ 4 files changed, 6 insertions(+) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 00ddaac499c6..6ea6cb0632f8 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4609,6 +4609,7 @@ static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, xdr->p = p; xdr->end = (void *)p + bytes; buf->buflen = bytes; + xdr->xdrgen_ctx = NULL; } __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index 5fa9417e034d..b80161b849ce 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -567,6 +567,7 @@ static inline void svcxdr_init_encode(struct svc_rqst *rqstp) xdr->page_ptr = buf->pages - 1; buf->buflen = PAGE_SIZE * (rqstp->rq_page_end - buf->pages); xdr->rqst = NULL; + xdr->xdrgen_ctx = NULL; } /** diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index b102b4f21e6b..2b33fc64be17 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -244,6 +244,7 @@ struct xdr_stream { unsigned int nwords; /* Remaining decode buffer length */ struct rpc_rqst *rqst; /* For debugging */ + void *xdrgen_ctx; /* Context for generated codecs */ }; /* diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index c42fd338c607..7353109fdbae 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -1161,6 +1161,7 @@ void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p, iov->iov_len += len; } xdr->rqst = rqst; + xdr->xdrgen_ctx = NULL; } EXPORT_SYMBOL_GPL(xdr_init_encode); @@ -1180,6 +1181,7 @@ void xdr_init_encode_pages(struct xdr_stream *xdr, struct xdr_buf *buf) xdr->p = page_address(*xdr->page_ptr); xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE); xdr->rqst = NULL; + xdr->xdrgen_ctx = NULL; } EXPORT_SYMBOL_GPL(xdr_init_encode_pages); @@ -1618,6 +1620,7 @@ void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p, xdr->p = p; } xdr->rqst = rqst; + xdr->xdrgen_ctx = NULL; } EXPORT_SYMBOL_GPL(xdr_init_decode);