The description of commit 2825a7f90753 ("nfsd4: allow encoding across page boundaries") states: > Also we can't handle a new operation starting close to the end of > a page. But does not detail why this is the case. Subtracting the scratch buffer's "shift" value from the remaining stream space seems to make reserving space close to the end of the buf->pages array reliable. This change is needed to make entry encoding with struct xdr_stream, introduced in a subsequent patch, work correctly when it approaches the end of the dirlist buffer. Fixes: 2825a7f90753 ("nfsd4: allow encoding across page boundaries") Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx> --- net/sunrpc/xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index 3964ff74ee51..043b67229792 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -978,7 +978,7 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr, * shifted this one back: */ xdr->p = (void *)p + frag2bytes; - space_left = xdr->buf->buflen - xdr->buf->len; + space_left = xdr->buf->buflen - xdr->buf->len - frag1bytes; xdr->end = (void *)p + min_t(int, space_left, PAGE_SIZE); xdr->buf->page_len += frag2bytes; xdr->buf->len += nbytes;