Return-Path: Received: from mail-it0-f67.google.com ([209.85.214.67]:47011 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754670AbdLOB6F (ORCPT ); Thu, 14 Dec 2017 20:58:05 -0500 Subject: [PATCH v1 16/16] xprtrdma: Introduce rpcrdma_mw_unmap_and_put From: Chuck Lever To: anna.schumaker@netapp.com Cc: linux-rdma@vger.kernel.org, linux-nfs@vger.kernel.org Date: Thu, 14 Dec 2017 20:58:04 -0500 Message-ID: <20171215015803.13776.23123.stgit@manet.1015granger.net> In-Reply-To: <20171215015403.13776.46706.stgit@manet.1015granger.net> References: <20171215015403.13776.46706.stgit@manet.1015granger.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sender: linux-nfs-owner@vger.kernel.org List-ID: Clean up: Code review suggested that a common bit of code can be placed into a helper function, and this gives us fewer places to stick an "I DMA unmapped something" trace point. Signed-off-by: Chuck Lever --- net/sunrpc/xprtrdma/fmr_ops.c | 19 ++++++++----------- net/sunrpc/xprtrdma/frwr_ops.c | 10 ++-------- net/sunrpc/xprtrdma/verbs.c | 26 ++++++++++++++++++++++---- net/sunrpc/xprtrdma/xprt_rdma.h | 1 + 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/net/sunrpc/xprtrdma/fmr_ops.c b/net/sunrpc/xprtrdma/fmr_ops.c index 8bd0399..7f2f2b7 100644 --- a/net/sunrpc/xprtrdma/fmr_ops.c +++ b/net/sunrpc/xprtrdma/fmr_ops.c @@ -135,14 +135,12 @@ enum { /* ORDER: invalidate first */ rc = __fmr_unmap(mr); - - /* ORDER: then DMA unmap */ - ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, - mr->mr_sg, mr->mr_nents, mr->mr_dir); if (rc) goto out_release; - rpcrdma_mr_put(mr); + /* ORDER: then DMA unmap */ + rpcrdma_mr_unmap_and_put(mr); + r_xprt->rx_stats.mrs_recovered++; return; @@ -150,6 +148,9 @@ enum { pr_err("rpcrdma: FMR reset failed (%d), %p released\n", rc, mr); r_xprt->rx_stats.mrs_orphaned++; + ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, + mr->mr_sg, mr->mr_nents, mr->mr_dir); + spin_lock(&r_xprt->rx_buf.rb_mrlock); list_del(&mr->mr_all); spin_unlock(&r_xprt->rx_buf.rb_mrlock); @@ -245,9 +246,7 @@ enum { pr_err("rpcrdma: ib_map_phys_fmr %u@0x%llx+%i (%d) status %i\n", len, (unsigned long long)dma_pages[0], pageoff, mr->mr_nents, rc); - ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, - mr->mr_sg, mr->mr_nents, mr->mr_dir); - rpcrdma_mr_put(mr); + rpcrdma_mr_unmap_and_put(mr); return ERR_PTR(-EIO); } @@ -289,9 +288,7 @@ enum { dprintk("RPC: %s: DMA unmapping fmr %p\n", __func__, &mr->fmr); list_del(&mr->fmr.fm_mr->list); - ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, - mr->mr_sg, mr->mr_nents, mr->mr_dir); - rpcrdma_mr_put(mr); + rpcrdma_mr_unmap_and_put(mr); } return; diff --git a/net/sunrpc/xprtrdma/frwr_ops.c b/net/sunrpc/xprtrdma/frwr_ops.c index 8ba4b33..35e3a54 100644 --- a/net/sunrpc/xprtrdma/frwr_ops.c +++ b/net/sunrpc/xprtrdma/frwr_ops.c @@ -459,13 +459,9 @@ list_for_each_entry(mr, mrs, mr_list) if (mr->mr_handle == rep->rr_inv_rkey) { - struct rpcrdma_xprt *r_xprt = mr->mr_xprt; - list_del(&mr->mr_list); mr->frwr.fr_state = FRWR_IS_INVALID; - ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, - mr->mr_sg, mr->mr_nents, mr->mr_dir); - rpcrdma_mr_put(mr); + rpcrdma_mr_unmap_and_put(mr); break; /* only one invalidated MR per RPC */ } } @@ -545,9 +541,7 @@ mr = rpcrdma_mr_pop(mrs); dprintk("RPC: %s: DMA unmapping frwr %p\n", __func__, &mr->frwr); - ib_dma_unmap_sg(ia->ri_device, - mr->mr_sg, mr->mr_nents, mr->mr_dir); - rpcrdma_mr_put(mr); + rpcrdma_mr_unmap_and_put(mr); } return; diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 2582729..9cc8abc 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -1321,6 +1321,14 @@ struct rpcrdma_mr * return NULL; } +static void +__rpcrdma_mr_put(struct rpcrdma_buffer *buf, struct rpcrdma_mr *mr) +{ + spin_lock(&buf->rb_mrlock); + rpcrdma_mr_push(mr, &buf->rb_mrs); + spin_unlock(&buf->rb_mrlock); +} + /** * rpcrdma_mr_put - Release an rpcrdma_mr object * @mr: object to release @@ -1329,12 +1337,22 @@ struct rpcrdma_mr * void rpcrdma_mr_put(struct rpcrdma_mr *mr) { + __rpcrdma_mr_put(&mr->mr_xprt->rx_buf, mr); +} + +/** + * rpcrdma_mr_unmap_and_put - DMA unmap an MR and release it + * @mr: object to release + * + */ +void +rpcrdma_mr_unmap_and_put(struct rpcrdma_mr *mr) +{ struct rpcrdma_xprt *r_xprt = mr->mr_xprt; - struct rpcrdma_buffer *buf = &r_xprt->rx_buf; - spin_lock(&buf->rb_mrlock); - rpcrdma_mr_push(mr, &buf->rb_mrs); - spin_unlock(&buf->rb_mrlock); + ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, + mr->mr_sg, mr->mr_nents, mr->mr_dir); + __rpcrdma_mr_put(&r_xprt->rx_buf, mr); } static struct rpcrdma_rep * diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h index 530ace6..28ae1fb 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -576,6 +576,7 @@ int rpcrdma_ep_post(struct rpcrdma_ia *, struct rpcrdma_ep *, struct rpcrdma_mr *rpcrdma_mr_get(struct rpcrdma_xprt *r_xprt); void rpcrdma_mr_put(struct rpcrdma_mr *mr); +void rpcrdma_mr_unmap_and_put(struct rpcrdma_mr *mr); void rpcrdma_mr_defer_recovery(struct rpcrdma_mr *mr); struct rpcrdma_req *rpcrdma_buffer_get(struct rpcrdma_buffer *);