All of lore.kernel.org
 help / color / mirror / Atom feed
From: trondmy@kernel.org
To: linux-nfs@vger.kernel.org
Subject: [PATCH 2/3] NFS: Avoid copy of xdr padding in readlink, layoutget and getxattr
Date: Wed, 18 Nov 2020 17:19:38 -0500	[thread overview]
Message-ID: <20201118221939.20715-2-trondmy@kernel.org> (raw)
In-Reply-To: <20201118221939.20715-1-trondmy@kernel.org>

From: Trond Myklebust <trond.myklebust@hammerspace.com>

When doing a readlink, layoutget or getxattr call into an array of
pages, we don't care if the XDR padding ends up in the last page
when the data length is not 32-bit aligned.
Avoid an unnecessary copy by just leaving that padding in place.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/nfs2xdr.c  | 2 +-
 fs/nfs/nfs3xdr.c  | 2 +-
 fs/nfs/nfs42xdr.c | 2 +-
 fs/nfs/nfs4xdr.c  | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index f6676af37d5d..db9c265ad9e1 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -437,7 +437,7 @@ static int decode_path(struct xdr_stream *xdr)
 	length = be32_to_cpup(p);
 	if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN))
 		goto out_size;
-	recvd = xdr_read_pages(xdr, length);
+	recvd = xdr_read_pages(xdr, xdr_align_size(length));
 	if (unlikely(length > recvd))
 		goto out_cheating;
 	xdr_terminate_string(xdr->buf, length);
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index 69971f6c840d..d3e1726d538b 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -234,7 +234,7 @@ static int decode_nfspath3(struct xdr_stream *xdr)
 	count = be32_to_cpup(p);
 	if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
 		goto out_nametoolong;
-	recvd = xdr_read_pages(xdr, count);
+	recvd = xdr_read_pages(xdr, xdr_align_size(count));
 	if (unlikely(count > recvd))
 		goto out_cheating;
 	xdr_terminate_string(xdr->buf, count);
diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c
index 6e060a88f98c..e58bfe208ae8 100644
--- a/fs/nfs/nfs42xdr.c
+++ b/fs/nfs/nfs42xdr.c
@@ -495,7 +495,7 @@ static int decode_getxattr(struct xdr_stream *xdr,
 	res->xattr_len = len;
 
 	if (len > 0) {
-		rdlen = xdr_read_pages(xdr, len);
+		rdlen = xdr_read_pages(xdr, xdr_align_size(len));
 		if (rdlen < len)
 			return -EIO;
 	}
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index c8714381d511..755b556e85c3 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -5250,7 +5250,7 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
 		dprintk("nfs: server returned giant symlink!\n");
 		return -ENAMETOOLONG;
 	}
-	recvd = xdr_read_pages(xdr, len);
+	recvd = xdr_read_pages(xdr, xdr_align_size(len));
 	if (recvd < len) {
 		dprintk("NFS: server cheating in readlink reply: "
 				"count %u > recvd %u\n", len, recvd);
@@ -5925,7 +5925,7 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 		res->type,
 		res->layoutp->len);
 
-	recvd = xdr_read_pages(xdr, res->layoutp->len);
+	recvd = xdr_read_pages(xdr, xdr_align_size(res->layoutp->len));
 	if (res->layoutp->len > recvd) {
 		dprintk("NFS: server cheating in layoutget reply: "
 				"layout len %u > recvd %u\n",
-- 
2.28.0


  reply	other threads:[~2020-11-18 22:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 22:19 [PATCH 1/3] NFSv4: Fix the alignment of page data in the getdeviceinfo reply trondmy
2020-11-18 22:19 ` trondmy [this message]
2020-11-18 22:19   ` [PATCH 3/3] NFS: Avoid copy of xdr padding in read() trondmy
2020-11-19 14:17     ` Chuck Lever
2020-11-19 14:30       ` Trond Myklebust
2020-11-19 14:31         ` Chuck Lever
2020-11-19 14:34           ` Trond Myklebust
2020-11-19 22:58             ` Chuck Lever
2020-11-20  0:58               ` Trond Myklebust
2020-11-20 14:52                 ` Chuck Lever
2020-11-20 17:14                   ` Trond Myklebust
2020-11-20 17:51                     ` Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201118221939.20715-2-trondmy@kernel.org \
    --to=trondmy@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.