More NFS/RDMA client patches for v4.15
Subsystems (4)
cover More NFS/RDMA client patches for v4.15
Hi Anna-
Here's my third set of NFS/RDMA client patches for v4.15. There is one small set remaining after this one, which I can send once this one is accepted.
This set implements strong Send Queue accounting, replacing the current system which has been in place since the beginning with a more reliable system that completely prevents the exposure of RPC buffer contents after RPC completion (for example, when a Send retransmit is necessary).
Please consider this set for v4.15.
---
Chuck Lever (9):
xprtrdma: Clean up SGE accounting in rpcrdma_prepare_msg_sges()
xprtrdma: Fix error handling in rpcrdma_prepare_msg_sges()
xprtrdma: Change return value of rpcrdma_prepare_send_sges()
xprtrdma: "Unoptimize" rpcrdma_prepare_hdr_sge()
xprtrdma: Add data structure to manage RDMA Send arguments
xprtrdma: Add a field of bit flags to struct rpcrdma_req
xprtrdma: Refactor rpcrdma_deferred_completion
xprtrdma: RPC completion should wait for Send completion
xprtrdma: Remove atomic send completion counting
net/sunrpc/xprtrdma/backchannel.c | 6 + net/sunrpc/xprtrdma/frwr_ops.c | 8 - net/sunrpc/xprtrdma/rpc_rdma.c | 178 ++++++++++++++++++++++----------- net/sunrpc/xprtrdma/transport.c | 15 +-- net/sunrpc/xprtrdma/verbs.c | 201 +++++++++++++++++++++++++++++++++++-- net/sunrpc/xprtrdma/xprt_rdma.h | 79 +++++++++------ 6 files changed, 367 insertions(+), 120 deletions(-)
--
Chuck Lever
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/9 xprtrdma: Clean up SGE accounting in rpcrdma_prepare_msg_sges()
Clean up. rpcrdma_prepare_hdr_sge() sets num_sge to one, then rpcrdma_prepare_msg_sges() sets num_sge again to the count of SGEs it added, plus one for the header SGE just mapped in rpcrdma_prepare_hdr_sge(). This is confusing, and nails in an assumption about when these functions are called.
Instead, maintain a running count that both functions can update with just the number of SGEs they have added to the SGE array.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/xprtrdma/rpc_rdma.c +1 -1
@@ -637,7 +637,7 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, } out: - req->rl_send_wr.num_sge = sge_no +1 ; + req->rl_send_wr.num_sge += sge_no;return true; out_mapping_overflow:
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/9 xprtrdma: Fix error handling in rpcrdma_prepare_msg_sges()
In reply to Chuck LeverWhen this function fails, it needs to undo the DMA mappings it's done so far. Otherwise these are leaked.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +24 -14
@@ -511,6 +511,28 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,return 0 ; } +/** +* rpcrdma_unmap_sges - DMA-unmap Send buffers +* @ia: interface adapter (device) +* @req: req with possibly some SGEs to be DMA unmapped +* +*/ +void +rpcrdma_unmap_sges (struct rpcrdma_ia *ia,struct rpcrdma_req *req) +{ +struct ib_sge *sge; +unsigned int count; + +/* The first two SGEs contain the transport header and +* the inline buffer. These are always left mapped so +* they can be cheaply re-used. +*/ + sge = &req->rl_send_sge[2 ]; +for (count = req->rl_mapped_sges; count--; sge++) +ib_dma_unmap_page (ia->ri_device, + sge->addr, sge->length,DMA_TO_DEVICE ); +} +/* Prepare the RPC-over-RDMA header SGE. */ static bool
@@ -641,10 +663,12 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,return true; out_mapping_overflow: +rpcrdma_unmap_sges (ia, req);pr_err ("rpcrdma: too many Send SGEs (%u)\n" , sge_no);return false; out_mapping_err: +rpcrdma_unmap_sges (ia, req);pr_err ("rpcrdma: Send mapping error\n" );return false; }
@@ -671,20 +695,6 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,return false; } -void -rpcrdma_unmap_sges (struct rpcrdma_ia *ia,struct rpcrdma_req *req) -{ -struct ib_device *device = ia->ri_device; -struct ib_sge *sge; -int count; - - sge = &req->rl_send_sge[2 ]; -for (count = req->rl_mapped_sges; count--; sge++) -ib_dma_unmap_page (device, sge->addr, sge->length, -DMA_TO_DEVICE ); - req->rl_mapped_sges =0 ; -} -/** * rpcrdma_marshal_req - Marshal and send one RPC request * @r_xprt: controlling transport
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/9 xprtrdma: Change return value of rpcrdma_prepare_send_sges()
In reply to Chuck LeverClean up: Make rpcrdma_prepare_send_sges() return a negative errno instead of a bool. Soon callers will want distinct treatments of different types of failures.
--- net/sunrpc/xprtrdma/backchannel.c | 4 +-- net/sunrpc/xprtrdma/rpc_rdma.c | 52 +++++++++++++++++++++++-------------- net/sunrpc/xprtrdma/xprt_rdma.h | 6 +++- 3 files changed, 38 insertions(+), 24 deletions(-)
net/sunrpc/xprtrdma/backchannel.c +2 -2
@@ -222,8 +222,8 @@ int rpcrdma_bc_marshal_reply(struct rpc_rqst *rqst) *p++ = xdr_zero; *p = xdr_zero; -if (!rpcrdma_prepare_send_sges (&r_xprt->rx_ia, req,RPCRDMA_HDRLEN_MIN , - &rqst->rq_snd_buf, rpcrdma_noch)) +if (rpcrdma_prepare_send_sges (r_xprt, req,RPCRDMA_HDRLEN_MIN , + &rqst->rq_snd_buf, rpcrdma_noch))return -EIO ;return 0 ; }
net/sunrpc/xprtrdma/rpc_rdma.c +32 -20
96 lines not on this page · raw message
net/sunrpc/xprtrdma/xprt_rdma.h +4 -2
@@ -613,8 +613,10 @@ enum rpcrdma_chunktype { rpcrdma_replych }; -bool rpcrdma_prepare_send_sges (struct rpcrdma_ia *,struct rpcrdma_req *, -u32 ,struct xdr_buf *,enum rpcrdma_chunktype ); +int rpcrdma_prepare_send_sges (struct rpcrdma_xprt *r_xprt, +struct rpcrdma_req *req,u32 hdrlen, +struct xdr_buf *xdr, +enum rpcrdma_chunktype rtype);void rpcrdma_unmap_sges (struct rpcrdma_ia *,struct rpcrdma_req *);int rpcrdma_marshal_req (struct rpcrdma_xprt *r_xprt,struct rpc_rqst *rqst);void rpcrdma_set_max_header_sizes (struct rpcrdma_xprt *);
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/9 xprtrdma: "Unoptimize" rpcrdma_prepare_hdr_sge()
In reply to Chuck LeverCommit 655fec6987be ("xprtrdma: Use gathered Send for large inline messages") assumed that, since the zeroeth element of the Send SGE array always pointed to req->rl_rdmabuf, it needed to be initialized just once. This was a valid assumption because the Send SGE array and rl_rdmabuf both live in the same rpcrdma_req.
In a subsequent patch, the Send SGE array will be separated from the rpcrdma_req, so the zeroeth element of the SGE array needs to be initialized every time.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +5 -7
@@ -533,7 +533,7 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, sge->addr, sge->length, DMA_TO_DEVICE); } -/* Prepare the RPC-over-RDMA header SGE. +/* Prepare an SGE for the RPC-over-RDMA transport header. */ static bool rpcrdma_prepare_hdr_sge(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
@@ -542,13 +542,11 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,struct rpcrdma_regbuf *rb = req->rl_rdmabuf;struct ib_sge *sge = &req->rl_send_sge[0 ]; -if (unlikely (!rpcrdma_regbuf_is_mapped (rb))) { -if (!__rpcrdma_dma_map_regbuf (ia, rb)) - goto out_regbuf; - sge->addr =rdmab_addr (rb); - sge->lkey =rdmab_lkey (rb); - } +if (!rpcrdma_dma_map_regbuf (ia, rb)) + goto out_regbuf; + sge->addr =rdmab_addr (rb); sge->length = len; + sge->lkey =rdmab_lkey (rb);ib_dma_sync_single_for_device (rdmab_device (rb), sge->addr, sge->length,DMA_TO_DEVICE );
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/9 xprtrdma: Add data structure to manage RDMA Send arguments
In reply to Chuck LeverProblem statement:
Recently Sagi Grimberg <[email protected]> observed that kernel RDMA- enabled storage initiators don't handle delayed Send completion
correctly. If Send completion is delayed beyond the end of a ULP
transaction, the ULP may release resources that are still being used
by the HCA to complete a long-running Send operation.
This is a common design trait amongst our initiators. Most Send operations are faster than the ULP transaction they are part of. Waiting for a completion for these is typically unnecessary.
Infrequently, a network partition or some other problem crops up where an ordering problem can occur. In NFS parlance, the RPC Reply arrives and completes the RPC, but the HCA is still retrying the Send WR that conveyed the RPC Call. In this case, the HCA can try to use memory that has been invalidated or DMA unmapped, and the connection is lost. If that memory has been re-used for something else (possibly not related to NFS), and the Send retransmission exposes that data on the wire.
Thus we cannot assume that it is safe to release Send-related resources just because a ULP reply has arrived.
After some analysis, we have determined that the completion housekeeping will not be difficult for xprtrdma:
- Inline Send buffers are registered via the local DMA key, and are already left DMA mapped for the lifetime of a transport connection, thus no additional handling is necessary for those
- Gathered Sends involving page cache pages _will_ need to DMA unmap those pages after the Send completes. But like inline send buffers, they are registered via the local DMA key, and thus will not need to be invalidated
In addition, RPC completion will need to wait for Send completion in the latter case. However, nearly always, the Send that conveys the RPC Call will have completed long before the RPC Reply arrives, and thus no additional latency will be accrued.
Design notes:
In this patch, the rpcrdma_sendctx object is introduced, and a lock-free circular queue is added to manage a set of them per transport.
The RPC client's send path already prevents sending more than one RPC Call at the same time. This allows us to treat the consumer side of the queue (rpcrdma_sendctx_get_locked) as if there is a single consumer thread.
The producer side of the queue (rpcrdma_sendctx_put_locked) is invoked only from the Send completion handler, which is a single thread of execution (soft IRQ).
The only care that needs to be taken is with the tail index, which is shared between the producer and consumer. Only the producer updates the tail index. The consumer compares the head with the tail to ensure that the a sendctx that is in use is never handed out again (or, expressed more conventionally, the queue is empty).
When the sendctx queue empties completely, there are enough Sends outstanding that posting more Send operations can result in a Send Queue overflow. In this case, the ULP is told to wait and try again. This introduces strong Send Queue accounting to xprtrdma.
As a final touch, Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> suggested a mechanism that does not require signaling every Send.
We signal once every N Sends, and perform SGE unmapping of N Send
operations during that one completion.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 40 +++++--- net/sunrpc/xprtrdma/transport.c | 6 + net/sunrpc/xprtrdma/verbs.c | 195 +++++++++++++++++++++++++++++++++++++-- net/sunrpc/xprtrdma/xprt_rdma.h | 38 +++++++- 4 files changed, 247 insertions(+), 32 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +24 -16
@@ -512,23 +512,26 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, }/** -* rpcrdma_unmap_sges - DMA-unmap Send buffers -* @ia: interface adapter (device) -* @req: req with possibly some SGEs to be DMA unmapped +* rpcrdma_unmap_sendctx - DMA-unmap Send buffers +* @sc: sendctx containing SGEs to unmap * */ void -rpcrdma_unmap_sges (struct rpcrdma_ia *ia,struct rpcrdma_req *req) +rpcrdma_unmap_sendctx (struct rpcrdma_sendctx *sc) { +struct rpcrdma_ia *ia = &sc->sc_xprt->rx_ia;struct ib_sge *sge;unsigned int count; +dprintk ("RPC: %s: unmapping %u sges for sc=%p\n" , + __func__, sc->sc_unmap_count, sc); +/* The first two SGEs contain the transport header and * the inline buffer. These are always left mapped so * they can be cheaply re-used. */ - sge = &req->rl_send_sge[2 ]; -for (count = req->rl_mapped_sges; count--; sge++) + sge = &sc->sc_sges[2 ]; +for (count = sc->sc_unmap_count; count; ++sge, --count)ib_dma_unmap_page (ia->ri_device, sge->addr, sge->length,DMA_TO_DEVICE ); }
@@ -539,8 +542,9 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, rpcrdma_prepare_hdr_sge(struct rpcrdma_ia *ia, struct rpcrdma_req *req, u32 len) { + struct rpcrdma_sendctx *sc = req->rl_sendctx;struct rpcrdma_regbuf *rb = req->rl_rdmabuf; -struct ib_sge *sge = &req->rl_send_sge[0 ]; +struct ib_sge *sge = sc->sc_sges;if (!rpcrdma_dma_map_regbuf (ia, rb)) goto out_regbuf;
@@ -550,7 +554,7 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,ib_dma_sync_single_for_device (rdmab_device (rb), sge->addr, sge->length,DMA_TO_DEVICE ); - req->rl_send_wr.num_sge++; + sc->sc_wr.num_sge++;return true; out_regbuf:
@@ -565,10 +569,11 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req, struct xdr_buf *xdr, enum rpcrdma_chunktype rtype) { + struct rpcrdma_sendctx *sc = req->rl_sendctx;unsigned int sge_no, page_base, len, remaining;struct rpcrdma_regbuf *rb = req->rl_sendbuf;struct ib_device *device = ia->ri_device; -struct ib_sge *sge = req->rl_send_sge; +struct ib_sge *sge = sc->sc_sges;u32 lkey = ia->ri_pd->local_dma_lkey;struct page *page, **ppages;
@@ -631,7 +636,7 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, sge[sge_no].length = len; sge[sge_no].lkey = lkey; - req->rl_mapped_sges++; + sc->sc_unmap_count++; ppages++; remaining -= len; page_base =0 ;
@@ -657,11 +662,11 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, goto out_mapping_err; sge[sge_no].length = len; sge[sge_no].lkey = lkey; - req->rl_mapped_sges++; + sc->sc_unmap_count++; } out: - req->rl_send_wr.num_sge += sge_no; + sc->sc_wr.num_sge += sge_no;return true; out_regbuf:
@@ -669,12 +674,12 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,return false; out_mapping_overflow: -rpcrdma_unmap_sges (ia, req); +rpcrdma_unmap_sendctx (sc);pr_err ("rpcrdma: too many Send SGEs (%u)\n" , sge_no);return false; out_mapping_err: -rpcrdma_unmap_sges (ia, req); +rpcrdma_unmap_sendctx (sc);pr_err ("rpcrdma: Send mapping error\n" );return false; }
@@ -694,8 +699,11 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req, u32 hdrlen, struct xdr_buf *xdr, enum rpcrdma_chunktype rtype) { - req->rl_send_wr.num_sge = 0; - req->rl_mapped_sges =0 ; + req->rl_sendctx = rpcrdma_sendctx_get_locked(&r_xprt->rx_buf); +if (!req->rl_sendctx) +return -ENOBUFS ; + req->rl_sendctx->sc_wr.num_sge =0 ; + req->rl_sendctx->sc_unmap_count =0 ;if (!rpcrdma_prepare_hdr_sge (&r_xprt->rx_ia, req, hdrlen))return -EIO ;
net/sunrpc/xprtrdma/transport.c +3 -3
@@ -687,7 +687,6 @@if (!list_empty (&req->rl_registered)) ia->ri_ops->ro_unmap_sync (r_xprt, &req->rl_registered); -rpcrdma_unmap_sges (ia, req);rpcrdma_buffer_put (req); }
@@ -793,11 +792,12 @@ void xprt_rdma_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) r_xprt->rx_stats.failed_marshal_count, r_xprt->rx_stats.bad_reply_count, r_xprt->rx_stats.nomsg_call_count); -seq_printf (seq,"%lu %lu %lu %lu\n" , +seq_printf (seq,"%lu %lu %lu %lu %lu\n" , r_xprt->rx_stats.mrs_recovered, r_xprt->rx_stats.mrs_orphaned, r_xprt->rx_stats.mrs_allocated, - r_xprt->rx_stats.local_inv_needed); + r_xprt->rx_stats.local_inv_needed, + r_xprt->rx_stats.empty_sendctx_q); } static int
net/sunrpc/xprtrdma/verbs.c +187 -8
262 lines not on this page · raw message
net/sunrpc/xprtrdma/xprt_rdma.h +33 -5
@@ -93,6 +93,8 @@ enum {*/ struct rpcrdma_ep { +unsigned int rep_send_count; +unsigned int rep_send_batch;atomic_t rep_cqcount;int rep_cqinit;int rep_connected;
@@ -232,6 +234,27 @@ struct rpcrdma_rep {struct ib_recv_wr rr_recv_wr; }; +/* struct rpcrdma_sendctx - DMA mapped SGEs to unmap after Send completes +*/ +struct rpcrdma_xprt ; +struct rpcrdma_sendctx { +struct ib_send_wr sc_wr; +struct ib_cqe sc_cqe; +struct rpcrdma_xprt *sc_xprt; +unsigned int sc_unmap_count; +struct ib_sge sc_sges[]; +}; + +/* Limit the number of SGEs that can be unmapped during one +* Send completion. This caps the amount of work a single +* completion can do before returning to the provider. +* +* Setting this to zero disables Send completion batching. +*/ +enum { +RPCRDMA_MAX_SEND_BATCH =7 , +}; +/* * struct rpcrdma_mw - external memory region metadata *
@@ -343,19 +366,16 @@ enum {struct rpcrdma_buffer ;struct rpcrdma_req {struct list_head rl_list; -unsigned int rl_mapped_sges;unsigned int rl_connect_cookie;struct rpcrdma_buffer *rl_buffer;struct rpcrdma_rep *rl_reply;struct xdr_stream rl_stream;struct xdr_buf rl_hdrbuf; -struct ib_send_wr rl_send_wr; -struct ib_sge rl_send_sge[RPCRDMA_MAX_SEND_SGES ]; +struct rpcrdma_sendctx *rl_sendctx;struct rpcrdma_regbuf *rl_rdmabuf;/* xprt header */ struct rpcrdma_regbuf *rl_sendbuf;/* rq_snd_buf */ struct rpcrdma_regbuf *rl_recvbuf;/* rq_rcv_buf */ -struct ib_cqe rl_cqe;struct list_head rl_all;bool rl_backchannel;
@@ -402,6 +422,11 @@ struct rpcrdma_buffer {struct list_head rb_mws;struct list_head rb_all; +unsigned long rb_sc_head; +unsigned long rb_sc_tail; +unsigned long rb_sc_last; +struct rpcrdma_sendctx **rb_sc_ctxs; +spinlock_t rb_lock;/* protect buf lists */ int rb_send_count, rb_recv_count;struct list_head rb_send_bufs;
@@ -456,6 +481,7 @@ struct rpcrdma_stats {unsigned long mrs_recovered;unsigned long mrs_orphaned;unsigned long mrs_allocated; +unsigned long empty_sendctx_q;/* accessed when receiving a reply */ unsigned long long total_rdma_reply;
@@ -557,6 +583,8 @@ int rpcrdma_ep_post(struct rpcrdma_ia *, struct rpcrdma_ep *,void rpcrdma_destroy_req (struct rpcrdma_req *);int rpcrdma_buffer_create (struct rpcrdma_xprt *);void rpcrdma_buffer_destroy (struct rpcrdma_buffer *); +struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked (struct rpcrdma_buffer *buf); +void rpcrdma_sendctx_put_locked (struct rpcrdma_sendctx *sc);struct rpcrdma_mw *rpcrdma_get_mw (struct rpcrdma_xprt *);void rpcrdma_put_mw (struct rpcrdma_xprt *,struct rpcrdma_mw *);
@@ -617,7 +645,7 @@ int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req, u32 hdrlen, struct xdr_buf *xdr, enum rpcrdma_chunktype rtype); -void rpcrdma_unmap_sges (struct rpcrdma_ia *,struct rpcrdma_req *); +void rpcrdma_unmap_sendctx (struct rpcrdma_sendctx *sc);int rpcrdma_marshal_req (struct rpcrdma_xprt *r_xprt,struct rpc_rqst *rqst);void rpcrdma_set_max_header_sizes (struct rpcrdma_xprt *);void rpcrdma_complete_rqst (struct rpcrdma_rep *rep);
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 6/9 xprtrdma: Add a field of bit flags to struct rpcrdma_req
In reply to Chuck LeverWe have one boolean flag in rpcrdma_req today. I'd like to add more flags, so convert that boolean to a bit flag.
--- net/sunrpc/xprtrdma/backchannel.c | 2 +- net/sunrpc/xprtrdma/transport.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 1 - net/sunrpc/xprtrdma/xprt_rdma.h | 7 ++++++- 4 files changed, 8 insertions(+), 4 deletions(-)
net/sunrpc/xprtrdma/backchannel.c +1 -1
@@ -42,7 +42,7 @@ static int rpcrdma_bc_setup_rqst(struct rpcrdma_xprt *r_xprt, req =rpcrdma_create_req (r_xprt);if (IS_ERR (req))return PTR_ERR (req); - req->rl_backchannel = true; +__set_bit (RPCRDMA_REQ_F_BACKCHANNEL , &req->rl_flags); rb =rpcrdma_alloc_regbuf (RPCRDMA_HDRBUF_SIZE ,DMA_TO_DEVICE ,GFP_KERNEL );
net/sunrpc/xprtrdma/transport.c +1 -1
@@ -680,7 +680,7 @@struct rpcrdma_req *req =rpcr_to_rdmar (rqst);struct rpcrdma_ia *ia = &r_xprt->rx_ia; -if (req->rl_backchannel) +if (test_bit (RPCRDMA_REQ_F_BACKCHANNEL , &req->rl_flags))return ;dprintk ("RPC: %s: called on 0x%p\n" , __func__, req->rl_reply);
net/sunrpc/xprtrdma/verbs.c +0 -1
@@ -1167,7 +1167,6 @@ struct rpcrdma_rep * rc =PTR_ERR (req); goto out; } - req->rl_backchannel = false;list_add (&req->rl_list, &buf->rb_send_bufs); }
net/sunrpc/xprtrdma/xprt_rdma.h +6 -1
@@ -377,12 +377,17 @@ struct rpcrdma_req {struct rpcrdma_regbuf *rl_recvbuf;/* rq_rcv_buf */ struct list_head rl_all; -bool rl_backchannel; +unsigned long rl_flags;struct list_head rl_registered;/* registered segments */ struct rpcrdma_mr_seg rl_segments[RPCRDMA_MAX_SEGS ]; }; +/* rl_flags */ +enum { +RPCRDMA_REQ_F_BACKCHANNEL =0 , +}; +static inline void rpcrdma_set_xprtdata (struct rpc_rqst *rqst,struct rpcrdma_req *req) {
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 7/9 xprtrdma: Refactor rpcrdma_deferred_completion
In reply to Chuck LeverInvoke a common routine for releasing hardware resources (for example, invalidating MRs). This needs to be done whether an RPC Reply has arrived or the RPC was terminated early.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 26 ++++++++++++++++---------- net/sunrpc/xprtrdma/transport.c | 6 +++--- net/sunrpc/xprtrdma/xprt_rdma.h | 3 +++ 3 files changed, 22 insertions(+), 13 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +16 -10
@@ -1293,6 +1293,20 @@ void rpcrdma_complete_rqst(struct rpcrdma_rep *rep) goto out; } +void rpcrdma_release_rqst (struct rpcrdma_xprt *r_xprt,struct rpcrdma_req *req) +{ +/* Invalidate and unmap the data payloads before waking +* the waiting application. This guarantees the memory +* regions are properly fenced from the server before the +* application accesses the data. It also ensures proper +* send flow control: waking the next RPC waits until this +* RPC has relinquished all its Send Queue entries. +*/ +if (!list_empty (&req->rl_registered)) + r_xprt->rx_ia.ri_ops->ro_unmap_sync (r_xprt, + &req->rl_registered); +} +/* Reply handling runs in the poll worker thread. Anything that * might wait is deferred to a separate workqueue. */
@@ -1301,18 +1315,9 @@ void rpcrdma_deferred_completion(struct work_struct *work)struct rpcrdma_rep *rep = container_of(work, struct rpcrdma_rep, rr_work);struct rpcrdma_req *req =rpcr_to_rdmar (rep->rr_rqst); -struct rpcrdma_xprt *r_xprt = rep->rr_rxprt; -/* Invalidate and unmap the data payloads before waking -* the waiting application. This guarantees the memory -* regions are properly fenced from the server before the -* application accesses the data. It also ensures proper -* send flow control: waking the next RPC waits until this -* RPC has relinquished all its Send Queue entries. -*/ rpcrdma_mark_remote_invalidation (&req->rl_registered, rep); - r_xprt->rx_ia.ri_ops->ro_unmap_sync (r_xprt, &req->rl_registered); - +rpcrdma_release_rqst (rep->rr_rxprt, req);rpcrdma_complete_rqst (rep); }
@@ -1374,6 +1379,7 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep) req =rpcr_to_rdmar (rqst); req->rl_reply = rep; rep->rr_rqst = rqst; +clear_bit (RPCRDMA_REQ_F_PENDING , &req->rl_flags);dprintk ("RPC: %s: reply %p completes request %p (xid 0x%08x)\n" , __func__, rep, req,be32_to_cpu (rep->rr_xid));
net/sunrpc/xprtrdma/transport.c +3 -3
@@ -678,15 +678,14 @@struct rpc_rqst *rqst = task->tk_rqstp;struct rpcrdma_xprt *r_xprt =rpcx_to_rdmax (rqst->rq_xprt);struct rpcrdma_req *req =rpcr_to_rdmar (rqst); -struct rpcrdma_ia *ia = &r_xprt->rx_ia;if (test_bit (RPCRDMA_REQ_F_BACKCHANNEL , &req->rl_flags))return ;dprintk ("RPC: %s: called on 0x%p\n" , __func__, req->rl_reply); -if (!list_empty (&req->rl_registered)) - ia->ri_ops->ro_unmap_sync (r_xprt, &req->rl_registered); +if (test_bit (RPCRDMA_REQ_F_PENDING , &req->rl_flags)) +rpcrdma_release_rqst (r_xprt, req);rpcrdma_buffer_put (req); }
@@ -745,6 +744,7 @@ goto drop_connection; req->rl_connect_cookie = xprt->connect_cookie; +set_bit (RPCRDMA_REQ_F_PENDING , &req->rl_flags);if (rpcrdma_ep_post (&r_xprt->rx_ia, &r_xprt->rx_ep, req)) goto drop_connection;
net/sunrpc/xprtrdma/xprt_rdma.h +3 -0
@@ -386,6 +386,7 @@ struct rpcrdma_req {/* rl_flags */ enum {RPCRDMA_REQ_F_BACKCHANNEL =0 , +RPCRDMA_REQ_F_PENDING , }; static inline void
@@ -655,6 +656,8 @@ int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,void rpcrdma_set_max_header_sizes (struct rpcrdma_xprt *);void rpcrdma_complete_rqst (struct rpcrdma_rep *rep);void rpcrdma_reply_handler (struct rpcrdma_rep *rep); +void rpcrdma_release_rqst (struct rpcrdma_xprt *r_xprt, +struct rpcrdma_req *req);void rpcrdma_deferred_completion (struct work_struct *work);static inline void rpcrdma_set_xdrlen (struct xdr_buf *xdr,size_t len)
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 8/9 xprtrdma: RPC completion should wait for Send completion
In reply to Chuck LeverWhen an RPC Call includes a file data payload, that payload can come from pages in the page cache, or a user buffer (for direct I/O).
If the payload can fit inline, xprtrdma includes it in the Send using a scatter-gather technique. xprtrdma mustn't allow the RPC consumer to re-use the memory where that payload resides before the Send completes. Otherwise, the new contents of that memory would be exposed by an HCA retransmit of the Send operation.
So, block RPC completion on Send completion, but only in the case where a separate file data payload is part of the Send. This prevents the reuse of that memory while it is still part of a Send operation without an undue cost to other cases.
Waiting is avoided in the common case because typically the Send will have completed long before the RPC Reply arrives.
These days, an RPC timeout will trigger a disconnect, which tears down the QP. The disconnect flushes all waiting Sends. This bounds the amount of time the reply handler has to wait for a Send completion.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 26 +++++++++++++++++++++++++- net/sunrpc/xprtrdma/transport.c | 5 +++-- net/sunrpc/xprtrdma/verbs.c | 3 ++- net/sunrpc/xprtrdma/xprt_rdma.h | 4 ++++ 4 files changed, 34 insertions(+), 4 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +25 -1
@@ -534,6 +534,11 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,for (count = sc->sc_unmap_count; count; ++sge, --count)ib_dma_unmap_page (ia->ri_device, sge->addr, sge->length,DMA_TO_DEVICE ); + +if (test_and_clear_bit (RPCRDMA_REQ_F_TX_RESOURCES , &sc->sc_req->rl_flags)) { +smp_mb__after_atomic (); +wake_up_bit (&sc->sc_req->rl_flags,RPCRDMA_REQ_F_TX_RESOURCES ); + } }/* Prepare an SGE for the RPC-over-RDMA transport header.
@@ -667,6 +672,8 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, out: sc->sc_wr.num_sge += sge_no; +if (sc->sc_unmap_count) +__set_bit (RPCRDMA_REQ_F_TX_RESOURCES , &req->rl_flags);return true; out_regbuf:
@@ -704,6 +711,8 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,return -ENOBUFS ; req->rl_sendctx->sc_wr.num_sge =0 ; req->rl_sendctx->sc_unmap_count =0 ; + req->rl_sendctx->sc_req = req; +__clear_bit (RPCRDMA_REQ_F_TX_RESOURCES , &req->rl_flags);if (!rpcrdma_prepare_hdr_sge (&r_xprt->rx_ia, req, hdrlen))return -EIO ;
@@ -1305,6 +1314,20 @@ void rpcrdma_release_rqst(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)if (!list_empty (&req->rl_registered)) r_xprt->rx_ia.ri_ops->ro_unmap_sync (r_xprt, &req->rl_registered); + +/* Ensure that any DMA mapped pages associated with +* the Send of the RPC Call have been unmapped before +* allowing the RPC to complete. This protects argument +* memory not controlled by the RPC client from being +* re-used before we're done with it. +*/ +if (test_bit (RPCRDMA_REQ_F_TX_RESOURCES , &req->rl_flags)) { + r_xprt->rx_stats.reply_waits_for_send++; +out_of_line_wait_on_bit (&req->rl_flags, +RPCRDMA_REQ_F_TX_RESOURCES , + bit_wait, +TASK_UNINTERRUPTIBLE ); + } }/* Reply handling runs in the poll worker thread. Anything that
@@ -1384,7 +1407,8 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)dprintk ("RPC: %s: reply %p completes request %p (xid 0x%08x)\n" , __func__, rep, req,be32_to_cpu (rep->rr_xid)); -if (list_empty (&req->rl_registered)) +if (list_empty (&req->rl_registered) && + !test_bit (RPCRDMA_REQ_F_TX_RESOURCES , &req->rl_flags))rpcrdma_complete_rqst (rep);else queue_work (rpcrdma_receive_wq, &rep->rr_work);
net/sunrpc/xprtrdma/transport.c +3 -2
@@ -792,12 +792,13 @@ void xprt_rdma_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) r_xprt->rx_stats.failed_marshal_count, r_xprt->rx_stats.bad_reply_count, r_xprt->rx_stats.nomsg_call_count); -seq_printf (seq,"%lu %lu %lu %lu %lu\n" , +seq_printf (seq,"%lu %lu %lu %lu %lu %lu\n" , r_xprt->rx_stats.mrs_recovered, r_xprt->rx_stats.mrs_orphaned, r_xprt->rx_stats.mrs_allocated, r_xprt->rx_stats.local_inv_needed, - r_xprt->rx_stats.empty_sendctx_q); + r_xprt->rx_stats.empty_sendctx_q, + r_xprt->rx_stats.reply_waits_for_send); } static int
net/sunrpc/xprtrdma/verbs.c +2 -1
@@ -1526,7 +1526,8 @@ struct rpcrdma_regbuf *dprintk ("RPC: %s: posting %d s/g entries\n" , __func__, send_wr->num_sge); -if (!ep->rep_send_count) { +if (!ep->rep_send_count || +test_bit (RPCRDMA_REQ_F_TX_RESOURCES , &req->rl_flags)) { send_wr->send_flags |=IB_SEND_SIGNALED ; ep->rep_send_count = ep->rep_send_batch; }else {
net/sunrpc/xprtrdma/xprt_rdma.h +4 -0
@@ -236,11 +236,13 @@ struct rpcrdma_rep {/* struct rpcrdma_sendctx - DMA mapped SGEs to unmap after Send completes */ +struct rpcrdma_req ;struct rpcrdma_xprt ;struct rpcrdma_sendctx {struct ib_send_wr sc_wr;struct ib_cqe sc_cqe;struct rpcrdma_xprt *sc_xprt; +struct rpcrdma_req *sc_req;unsigned int sc_unmap_count;struct ib_sge sc_sges[]; };
@@ -387,6 +389,7 @@ struct rpcrdma_req {enum {RPCRDMA_REQ_F_BACKCHANNEL =0 ,RPCRDMA_REQ_F_PENDING , +RPCRDMA_REQ_F_TX_RESOURCES , }; static inline void
@@ -492,6 +495,7 @@ struct rpcrdma_stats {/* accessed when receiving a reply */ unsigned long long total_rdma_reply;unsigned long long fixup_copy_count; +unsigned long reply_waits_for_send;unsigned long local_inv_needed;unsigned long nomsg_call_count;unsigned long bcall_count;
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 9/9 xprtrdma: Remove atomic send completion counting
In reply to Chuck LeverThe sendctx circular queue now guarantees that xprtrdma cannot overflow the Send Queue, so remove the remaining bits of the original Send WQE counting mechanism.
--- net/sunrpc/xprtrdma/frwr_ops.c | 8 -------- net/sunrpc/xprtrdma/verbs.c | 4 ---- net/sunrpc/xprtrdma/xprt_rdma.h | 21 --------------------- 3 files changed, 33 deletions(-)
net/sunrpc/xprtrdma/frwr_ops.c +0 -8
@@ -419,7 +419,6 @@ IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE :IB_ACCESS_REMOTE_READ ; -rpcrdma_set_signaled (&r_xprt->rx_ep, ®_wr->wr); rc =ib_post_send (ia->ri_id->qp, ®_wr->wr, &bad_wr);if (rc) goto out_senderr;
@@ -507,12 +506,6 @@ f->fr_cqe.done = frwr_wc_localinv_wake;reinit_completion (&f->fr_linv_done); -/* Initialize CQ count, since there is always a signaled -* WR being posted here. The new cqcount depends on how -* many SQEs are about to be consumed. -*/ -rpcrdma_init_cqcount (&r_xprt->rx_ep, count); -/* Transport disconnect drains the receive CQ before it * replaces the QP. The RPC reply handler won't call us * unless ri_id->qp is a valid pointer.
@@ -545,7 +538,6 @@/* Find and reset the MRs in the LOCAL_INV WRs that did not * get posted. */ -rpcrdma_init_cqcount (&r_xprt->rx_ep, -count);while (bad_wr) { f = container_of(bad_wr, struct rpcrdma_frmr, fr_invwr);
net/sunrpc/xprtrdma/verbs.c +0 -4
@@ -553,10 +553,6 @@ ep->rep_send_batch = min_t(unsigned int, RPCRDMA_MAX_SEND_BATCH, cdata->max_requests >>2 ); ep->rep_send_count = ep->rep_send_batch; - ep->rep_cqinit = ep->rep_attr.cap.max_send_wr/2 -1 ; -if (ep->rep_cqinit <=2 ) - ep->rep_cqinit =0 ;/* always signal? */ -rpcrdma_init_cqcount (ep,0 );init_waitqueue_head (&ep->rep_connect_wait);INIT_DELAYED_WORK (&ep->rep_connect_worker, rpcrdma_connect_worker);
net/sunrpc/xprtrdma/xprt_rdma.h +0 -21
@@ -95,8 +95,6 @@ enum {struct rpcrdma_ep {unsigned int rep_send_count;unsigned int rep_send_batch; -atomic_t rep_cqcount; -int rep_cqinit;int rep_connected;struct ib_qp_init_attr rep_attr;wait_queue_head_t rep_connect_wait;
@@ -106,25 +104,6 @@ struct rpcrdma_ep {struct delayed_work rep_connect_worker; }; -static inline void -rpcrdma_init_cqcount (struct rpcrdma_ep *ep,int count) -{ -atomic_set (&ep->rep_cqcount, ep->rep_cqinit - count); -} - -/* To update send queue accounting, provider must take a -* send completion every now and then. -*/ -static inline void -rpcrdma_set_signaled (struct rpcrdma_ep *ep,struct ib_send_wr *send_wr) -{ - send_wr->send_flags =0 ; -if (unlikely (atomic_sub_return (1 , &ep->rep_cqcount) <=0 )) { -rpcrdma_init_cqcount (ep,0 ); - send_wr->send_flags =IB_SEND_SIGNALED ; - } -} -/* Pre-allocate extra Work Requests for handling backward receives * and sends. This is a fixed value because the Work Queues are * allocated when the forward channel is set up.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html