public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 12/19] svcrdma: Properly compute .len and .buflen for received RPC Calls
Date: Fri, 16 Jun 2017 11:21:58 -0400	[thread overview]
Message-ID: <20170616152158.14210.29858.stgit@klimt.1015granger.net> (raw)
In-Reply-To: <20170616151535.14210.34926.stgit-Hs+gFlyCn65vLzlybtyyYzGyq/o6K9yX@public.gmane.org>

When an RPC-over-RDMA request is received, the Receive buffer
contains a Transport Header possibly followed by an RPC message.

Even though rq_arg.head[0] (as passed to NFSD) does not contain the
Transport Header header, currently rq_arg.len includes the size of
the Transport Header.

That violates the intent of the xdr_buf API contract. .buflen should
include everything, but .len should be exactly the length of the RPC
message in the buffer.

The rq_arg fields are summed together at the end of
svc_rdma_recvfrom to obtain the correct return value. rq_arg.len
really ought to contain the correct number of bytes already, but it
currently doesn't due to the above misbehavior.

Let's instead ensure that .buflen includes the length of the
transport header, and that .len is always equal to head.iov_len +
.page_len + tail.iov_len .

Signed-off-by: Chuck Lever <chuck.lever-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
 net/sunrpc/xprtrdma/svc_rdma_recvfrom.c |   14 ++++----------
 net/sunrpc/xprtrdma/svc_rdma_rw.c       |    2 +-
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
index 5fbcb73..ad4bd62 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
@@ -143,7 +143,6 @@ static void rdma_build_arg_xdr(struct svc_rqst *rqstp,
 		put_page(rqstp->rq_pages[sge_no]);
 		rqstp->rq_pages[sge_no] = page;
 		bc -= min_t(u32, bc, ctxt->sge[sge_no].length);
-		rqstp->rq_arg.buflen += ctxt->sge[sge_no].length;
 		sge_no++;
 	}
 	rqstp->rq_respages = &rqstp->rq_pages[sge_no];
@@ -338,6 +337,7 @@ static int svc_rdma_xdr_decode_req(struct xdr_buf *rq_arg)
 	rq_arg->head[0].iov_base = p;
 	hdr_len = (unsigned long)p - (unsigned long)rdma_argp;
 	rq_arg->head[0].iov_len -= hdr_len;
+	rq_arg->len -= hdr_len;
 	dprintk("svcrdma: received %s request for XID 0x%08x, hdr_len=%u\n",
 		proc, be32_to_cpup(rdma_argp), hdr_len);
 	return hdr_len;
@@ -564,18 +564,12 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
 		goto out_readchunk;
 
 complete:
-	ret = rqstp->rq_arg.head[0].iov_len
-		+ rqstp->rq_arg.page_len
-		+ rqstp->rq_arg.tail[0].iov_len;
 	svc_rdma_put_context(ctxt, 0);
-	dprintk("svcrdma: ret=%d, rq_arg.len=%u, "
-		"rq_arg.head[0].iov_base=%p, rq_arg.head[0].iov_len=%zd\n",
-		ret, rqstp->rq_arg.len,
-		rqstp->rq_arg.head[0].iov_base,
-		rqstp->rq_arg.head[0].iov_len);
+	dprintk("svcrdma: recvfrom: xprt=%p, rqstp=%p, rq_arg.len=%u\n",
+		rdma_xprt, rqstp, rqstp->rq_arg.len);
 	rqstp->rq_prot = IPPROTO_MAX;
 	svc_xprt_copy_addrs(rqstp, xprt);
-	return ret;
+	return rqstp->rq_arg.len;
 
 out_readchunk:
 	ret = svc_rdma_recv_read_chunk(rdma_xprt, rqstp, ctxt, p);
diff --git a/net/sunrpc/xprtrdma/svc_rdma_rw.c b/net/sunrpc/xprtrdma/svc_rdma_rw.c
index d88a4b5..4cdea69 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_rw.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_rw.c
@@ -847,7 +847,7 @@ static int svc_rdma_build_pz_read_chunk(struct svc_rqst *rqstp,
 	head->arg.len += info->ri_chunklen;
 	head->arg.buflen += info->ri_chunklen;
 
-	if (head->arg.len <= head->sge[0].length) {
+	if (head->arg.buflen <= head->sge[0].length) {
 		/* Transport header and RPC message fit entirely
 		 * in page where head iovec resides.
 		 */

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-06-16 15:21 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-16 15:20 [PATCH v2 00/19] Server-side NFS/RDMA changes proposed for v4.13 Chuck Lever
     [not found] ` <20170616151535.14210.34926.stgit-Hs+gFlyCn65vLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2017-06-16 15:20   ` [PATCH v2 01/19] ib_core: Enable and expose force_mr module parameter Chuck Lever
2017-06-16 15:20   ` [PATCH v2 02/19] svcrdma: Squelch disconnection messages Chuck Lever
2017-06-16 15:20   ` [PATCH v2 03/19] svcrdma: Avoid Send Queue overflow Chuck Lever
2017-06-16 15:20   ` [PATCH v2 04/19] svcrdma: Remove svc_rdma_marshal.c Chuck Lever
2017-06-16 15:21   ` [PATCH v2 05/19] svcrdma: Improve Read chunk sanity checking Chuck Lever
2017-06-16 15:21   ` [PATCH v2 06/19] svcrdma: Improve Write " Chuck Lever
2017-06-16 15:21   ` [PATCH v2 07/19] svcrdma: Improve Reply " Chuck Lever
2017-06-16 15:21   ` [PATCH v2 08/19] svcrdma: Don't account for Receive queue "starvation" Chuck Lever
2017-06-16 15:21   ` [PATCH v2 09/19] sunrpc: Allocate one more page per svc_rqst Chuck Lever
2017-06-16 15:21   ` [PATCH v2 10/19] svcrdma: Add recvfrom helpers to svc_rdma_rw.c Chuck Lever
2017-06-16 15:21   ` [PATCH v2 11/19] svcrdma: Use generic RDMA R/W API in RPC Call path Chuck Lever
2017-06-16 15:21   ` Chuck Lever [this message]
2017-06-16 15:22   ` [PATCH v2 13/19] svcrdma: Remove unused Read completion handlers Chuck Lever
2017-06-16 15:22   ` [PATCH v2 14/19] svcrdma: Remove frmr cache Chuck Lever
2017-06-16 15:22   ` [PATCH v2 15/19] svcrdma: Clean-up svc_rdma_unmap_dma Chuck Lever
2017-06-16 15:22   ` [PATCH v2 16/19] svcrdma: Clean up after converting svc_rdma_recvfrom to rdma_rw API Chuck Lever
2017-06-16 15:22   ` [PATCH v2 17/19] svcrdma: use offset_in_page() macro Chuck Lever
2017-06-16 15:22   ` [PATCH v2 18/19] svcrdma: Remove svc_rdma_chunk_ctxt::cc_dir field Chuck Lever
2017-06-16 15:22   ` [PATCH v2 19/19] sunrpc: Disable splice for krb5i Chuck Lever
     [not found]     ` <20170616152254.14210.48071.stgit-Hs+gFlyCn65vLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2017-06-16 17:52       ` J. Bruce Fields
     [not found]         ` <20170616175253.GF12030-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2017-06-16 18:37           ` Chuck Lever
     [not found]             ` <D8C547C0-C361-43F4-8E5C-AF8A6C45C500-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-06-16 18:42               ` J. Bruce Fields
     [not found]                 ` <20170616184208.GH12030-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2017-06-16 18:44                   ` Chuck Lever
2017-06-17 10:01       ` Jeff Layton
     [not found]         ` <1497693712.4684.4.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-06-20 19:41           ` J. Bruce Fields
2017-06-17 15:07       ` Christoph Hellwig
     [not found]         ` <20170617150705.GA27917-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-06-17 17:23           ` Chuck Lever
     [not found]             ` <A573E1EB-48DB-4E4A-B710-34914B0CF016-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-06-18  7:34               ` Christoph Hellwig
     [not found]                 ` <20170618073438.GA15358-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-06-19 15:22                   ` Chuck Lever
     [not found]                     ` <14AD4311-5092-441C-8A3B-F7EC7E801358-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-06-19 15:30                       ` Christoph Hellwig
     [not found]                         ` <20170619153018.GA2667-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-06-22 17:13                           ` Jeff Layton
2017-06-20 19:24                   ` J. Bruce Fields
     [not found]                     ` <20170620192449.GB13008-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2017-06-20 19:28                       ` J. Bruce Fields

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=20170616152158.14210.29858.stgit@klimt.1015granger.net \
    --to=chuck.lever-qhclzuegtsvqt0dzr+alfa@public.gmane.org \
    --cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox