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 v1 2/8] xprtrdma: Invalidate memory when a signal is caught
Date: Fri, 12 Feb 2016 16:06:10 -0500	[thread overview]
Message-ID: <20160212210610.5278.22489.stgit@manet.1015granger.net> (raw)
In-Reply-To: <20160212205107.5278.55938.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>

When a signal occurs during a synchronous RPC, the RPC scheduler
causes the RPC task to exit immediately.

However, the RPC transaction is still running on the server, which
may read arguments from the client or deliver a reply into client
memory that is still registered.

Ensure that xprt_release() invalidates the signaled RPC's chunks
and waits for the invalidation to complete in order to fence the
memory from the server before the client re-allocates it.

Note it should be safe to sleep in this case. An asynchronous
RPC is never awoken by a signal.

Signed-off-by: Chuck Lever <chuck.lever-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
 net/sunrpc/xprtrdma/transport.c |   41 ++++++++++++++++++++++++++++++++-------
 net/sunrpc/xprtrdma/xprt_rdma.h |    1 +
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index b1b009f..ceb7140 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -508,6 +508,7 @@ xprt_rdma_allocate(struct rpc_task *task, size_t size)
 out:
 	dprintk("RPC:       %s: size %zd, request 0x%p\n", __func__, size, req);
 	req->rl_connect_cookie = 0;	/* our reserved value */
+	req->rl_task = task;
 	return req->rl_sendbuf->rg_base;
 
 out_rdmabuf:
@@ -555,6 +556,37 @@ out_fail:
 	return NULL;
 }
 
+/* Invalidate registered memory still associated with this req.
+ *
+ * Normally, the RPC reply handler invalidates chunks.
+ *
+ * If we're here because a signal fired, this is an exiting
+ * synchronous RPC and the reply handler has not run, leaving
+ * the RPC's chunks registered. The server is still processing
+ * this RPC and can still read or update those chunks.
+ *
+ * Synchronously fence the chunks before this RPC terminates
+ * to ensure the server doesn't write into memory that has
+ * been reallocated.
+ */
+static void xprt_rdma_free_chunks(struct rpcrdma_xprt *r_xprt,
+				  struct rpcrdma_req *req)
+{
+	unsigned int i;
+
+	if (!RPC_IS_ASYNC(req->rl_task)) {
+		r_xprt->rx_ia.ri_ops->ro_unmap_sync(r_xprt, req);
+		return;
+	}
+
+	pr_warn("rpcrdma: freeing async RPC task with registered chunks\n");
+	for (i = 0; req->rl_nchunks;) {
+		--req->rl_nchunks;
+		i += r_xprt->rx_ia.ri_ops->ro_unmap(r_xprt,
+						    &req->rl_segments[i]);
+	}
+}
+
 /*
  * This function returns all RDMA resources to the pool.
  */
@@ -564,7 +596,6 @@ xprt_rdma_free(void *buffer)
 	struct rpcrdma_req *req;
 	struct rpcrdma_xprt *r_xprt;
 	struct rpcrdma_regbuf *rb;
-	int i;
 
 	if (buffer == NULL)
 		return;
@@ -578,12 +609,8 @@ xprt_rdma_free(void *buffer)
 
 	dprintk("RPC:       %s: called on 0x%p\n", __func__, req->rl_reply);
 
-	for (i = 0; req->rl_nchunks;) {
-		--req->rl_nchunks;
-		i += r_xprt->rx_ia.ri_ops->ro_unmap(r_xprt,
-						    &req->rl_segments[i]);
-	}
-
+	if (req->rl_nchunks)
+		xprt_rdma_free_chunks(r_xprt, req);
 	rpcrdma_buffer_put(req);
 }
 
diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h
index 38fe11b..bf98c67 100644
--- a/net/sunrpc/xprtrdma/xprt_rdma.h
+++ b/net/sunrpc/xprtrdma/xprt_rdma.h
@@ -280,6 +280,7 @@ struct rpcrdma_req {
 	struct rpcrdma_regbuf	*rl_rdmabuf;
 	struct rpcrdma_regbuf	*rl_sendbuf;
 	struct rpcrdma_mr_seg	rl_segments[RPCRDMA_MAX_SEGS];
+	struct rpc_task		*rl_task;
 
 	struct list_head	rl_all;
 	bool			rl_backchannel;

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" 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:[~2016-02-12 21:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12 21:05 [PATCH v1 0/8] NFS/RDMA client patches for v4.6 Chuck Lever
     [not found] ` <20160212205107.5278.55938.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-12 21:06   ` [PATCH v1 1/8] xprtrdma: Segment head and tail XDR buffers on page boundaries Chuck Lever
     [not found]     ` <20160212210602.5278.57457.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:27       ` Devesh Sharma
2016-02-12 21:06   ` Chuck Lever [this message]
     [not found]     ` <20160212210610.5278.22489.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:28       ` [PATCH v1 2/8] xprtrdma: Invalidate memory when a signal is caught Devesh Sharma
2016-02-12 21:06   ` [PATCH v1 3/8] rpcrdma: Add RPCRDMA_HDRLEN_ERR Chuck Lever
     [not found]     ` <20160212210618.5278.28591.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:28       ` Devesh Sharma
2016-02-12 21:06   ` [PATCH v1 4/8] xprtrdma: Properly handle RDMA_ERROR replies Chuck Lever
     [not found]     ` <20160212210627.5278.89517.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:28       ` Devesh Sharma
2016-02-17 21:19       ` Anna Schumaker
     [not found]         ` <56C4E3D6.1040605-ZwjVKphTwtPQT0dZR+AlfA@public.gmane.org>
2016-02-17 21:21           ` Chuck Lever
     [not found]             ` <16F01212-1045-449D-AD9E-C02F75ECE39A-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-02-17 21:24               ` Anna Schumaker
2016-02-12 21:06   ` [PATCH v1 5/8] xprtrdma: Serialize credit accounting again Chuck Lever
     [not found]     ` <20160212210635.5278.72709.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:29       ` Devesh Sharma
     [not found]         ` <CANjDDBgag4c2K0G+c-Mbxri+Bh2CZ6qkb49S-3myNva2J4bu_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-15 15:00           ` Chuck Lever
     [not found]             ` <DF2B8B89-F9CA-4DF9-96BF-6E455E0E1196-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-02-16  5:15               ` Devesh Sharma
2016-02-12 21:06   ` [PATCH v1 6/8] xprtrdma: Use new CQ API for RPC-over-RDMA client receive CQs Chuck Lever
     [not found]     ` <20160212210643.5278.97996.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:29       ` Devesh Sharma
2016-02-12 21:06   ` [PATCH v1 7/8] xprtrdma: Use an anonymous union in struct rpcrdma_mw Chuck Lever
     [not found]     ` <20160212210651.5278.31825.stgit-FYjufvaPoItvLzlybtyyYzGyq/o6K9yX@public.gmane.org>
2016-02-15 14:30       ` Devesh Sharma
2016-02-12 21:07   ` [PATCH v1 8/8] xprtrdma: Use new CQ API for RPC-over-RDMA client send CQs Chuck Lever
2016-02-15 14:31   ` [PATCH v1 0/8] NFS/RDMA client patches for v4.6 Devesh Sharma

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=20160212210610.5278.22489.stgit@manet.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