Skip to content

Commit 8475689

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Remove fr_state
Now that both the Send and Receive completions are handled in process context, it is safe to DMA unmap and return MRs to the free or recycle lists directly in the completion handlers. Doing this means rpcrdma_frwr no longer needs to track the state of each MR, meaning that a VALID or FLUSHED MR can no longer appear on an xprt's MR free list. Thus there is no longer a need to track the MR's registration state in rpcrdma_frwr. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 5809ea4 commit 8475689

4 files changed

Lines changed: 96 additions & 140 deletions

File tree

‎include/trace/events/rpcrdma.h‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,6 @@ DECLARE_EVENT_CLASS(xprtrdma_wrch_event,
181181
), \
182182
TP_ARGS(task, mr, nsegs))
183183

184-
TRACE_DEFINE_ENUM(FRWR_IS_INVALID);
185-
TRACE_DEFINE_ENUM(FRWR_IS_VALID);
186-
TRACE_DEFINE_ENUM(FRWR_FLUSHED_FR);
187-
TRACE_DEFINE_ENUM(FRWR_FLUSHED_LI);
188-
189-
#define xprtrdma_show_frwr_state(x) \
190-
__print_symbolic(x, \
191-
{ FRWR_IS_INVALID, "INVALID" }, \
192-
{ FRWR_IS_VALID, "VALID" }, \
193-
{ FRWR_FLUSHED_FR, "FLUSHED_FR" }, \
194-
{ FRWR_FLUSHED_LI, "FLUSHED_LI" })
195-
196184
DECLARE_EVENT_CLASS(xprtrdma_frwr_done,
197185
TP_PROTO(
198186
const struct ib_wc *wc,
@@ -203,22 +191,19 @@ DECLARE_EVENT_CLASS(xprtrdma_frwr_done,
203191

204192
TP_STRUCT__entry(
205193
__field(const void *, mr)
206-
__field(unsigned int, state)
207194
__field(unsigned int, status)
208195
__field(unsigned int, vendor_err)
209196
),
210197

211198
TP_fast_assign(
212199
__entry->mr = container_of(frwr, struct rpcrdma_mr, frwr);
213-
__entry->state = frwr->fr_state;
214200
__entry->status = wc->status;
215201
__entry->vendor_err = __entry->status ? wc->vendor_err : 0;
216202
),
217203

218204
TP_printk(
219-
"mr=%p state=%s: %s (%u/0x%x)",
220-
__entry->mr, xprtrdma_show_frwr_state(__entry->state),
221-
rdma_show_wc_status(__entry->status),
205+
"mr=%p: %s (%u/0x%x)",
206+
__entry->mr, rdma_show_wc_status(__entry->status),
222207
__entry->status, __entry->vendor_err
223208
)
224209
);

‎net/sunrpc/xprtrdma/frwr_ops.c‎

Lines changed: 92 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ int frwr_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mr *mr)
168168
goto out_list_err;
169169

170170
mr->frwr.fr_mr = frmr;
171-
mr->frwr.fr_state = FRWR_IS_INVALID;
172171
mr->mr_dir = DMA_NONE;
173172
INIT_LIST_HEAD(&mr->mr_list);
174173
INIT_WORK(&mr->mr_recycle, frwr_mr_recycle_worker);
@@ -297,65 +296,6 @@ size_t frwr_maxpages(struct rpcrdma_xprt *r_xprt)
297296
(ia->ri_max_segs - 2) * ia->ri_max_frwr_depth);
298297
}
299298

300-
/**
301-
* frwr_wc_fastreg - Invoked by RDMA provider for a flushed FastReg WC
302-
* @cq: completion queue (ignored)
303-
* @wc: completed WR
304-
*
305-
*/
306-
static void
307-
frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc)
308-
{
309-
struct ib_cqe *cqe = wc->wr_cqe;
310-
struct rpcrdma_frwr *frwr =
311-
container_of(cqe, struct rpcrdma_frwr, fr_cqe);
312-
313-
/* WARNING: Only wr_cqe and status are reliable at this point */
314-
if (wc->status != IB_WC_SUCCESS)
315-
frwr->fr_state = FRWR_FLUSHED_FR;
316-
trace_xprtrdma_wc_fastreg(wc, frwr);
317-
}
318-
319-
/**
320-
* frwr_wc_localinv - Invoked by RDMA provider for a flushed LocalInv WC
321-
* @cq: completion queue (ignored)
322-
* @wc: completed WR
323-
*
324-
*/
325-
static void
326-
frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc)
327-
{
328-
struct ib_cqe *cqe = wc->wr_cqe;
329-
struct rpcrdma_frwr *frwr = container_of(cqe, struct rpcrdma_frwr,
330-
fr_cqe);
331-
332-
/* WARNING: Only wr_cqe and status are reliable at this point */
333-
if (wc->status != IB_WC_SUCCESS)
334-
frwr->fr_state = FRWR_FLUSHED_LI;
335-
trace_xprtrdma_wc_li(wc, frwr);
336-
}
337-
338-
/**
339-
* frwr_wc_localinv_wake - Invoked by RDMA provider for a signaled LocalInv WC
340-
* @cq: completion queue (ignored)
341-
* @wc: completed WR
342-
*
343-
* Awaken anyone waiting for an MR to finish being fenced.
344-
*/
345-
static void
346-
frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc)
347-
{
348-
struct ib_cqe *cqe = wc->wr_cqe;
349-
struct rpcrdma_frwr *frwr = container_of(cqe, struct rpcrdma_frwr,
350-
fr_cqe);
351-
352-
/* WARNING: Only wr_cqe and status are reliable at this point */
353-
if (wc->status != IB_WC_SUCCESS)
354-
frwr->fr_state = FRWR_FLUSHED_LI;
355-
trace_xprtrdma_wc_li_wake(wc, frwr);
356-
complete(&frwr->fr_linv_done);
357-
}
358-
359299
/**
360300
* frwr_map - Register a memory region
361301
* @r_xprt: controlling transport
@@ -378,23 +318,15 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
378318
{
379319
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
380320
bool holes_ok = ia->ri_mrtype == IB_MR_TYPE_SG_GAPS;
381-
struct rpcrdma_frwr *frwr;
382321
struct rpcrdma_mr *mr;
383322
struct ib_mr *ibmr;
384323
struct ib_reg_wr *reg_wr;
385324
int i, n;
386325
u8 key;
387326

388-
mr = NULL;
389-
do {
390-
if (mr)
391-
rpcrdma_mr_recycle(mr);
392-
mr = rpcrdma_mr_get(r_xprt);
393-
if (!mr)
394-
goto out_getmr_err;
395-
} while (mr->frwr.fr_state != FRWR_IS_INVALID);
396-
frwr = &mr->frwr;
397-
frwr->fr_state = FRWR_IS_VALID;
327+
mr = rpcrdma_mr_get(r_xprt);
328+
if (!mr)
329+
goto out_getmr_err;
398330

399331
if (nsegs > ia->ri_max_frwr_depth)
400332
nsegs = ia->ri_max_frwr_depth;
@@ -423,7 +355,7 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
423355
if (!mr->mr_nents)
424356
goto out_dmamap_err;
425357

426-
ibmr = frwr->fr_mr;
358+
ibmr = mr->frwr.fr_mr;
427359
n = ib_map_mr_sg(ibmr, mr->mr_sg, mr->mr_nents, NULL, PAGE_SIZE);
428360
if (unlikely(n != mr->mr_nents))
429361
goto out_mapmr_err;
@@ -433,7 +365,7 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
433365
key = (u8)(ibmr->rkey & 0x000000FF);
434366
ib_update_fast_reg_key(ibmr, ++key);
435367

436-
reg_wr = &frwr->fr_regwr;
368+
reg_wr = &mr->frwr.fr_regwr;
437369
reg_wr->mr = ibmr;
438370
reg_wr->key = ibmr->rkey;
439371
reg_wr->access = writing ?
@@ -464,6 +396,23 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
464396
return ERR_PTR(-EIO);
465397
}
466398

399+
/**
400+
* frwr_wc_fastreg - Invoked by RDMA provider for a flushed FastReg WC
401+
* @cq: completion queue (ignored)
402+
* @wc: completed WR
403+
*
404+
*/
405+
static void frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc)
406+
{
407+
struct ib_cqe *cqe = wc->wr_cqe;
408+
struct rpcrdma_frwr *frwr =
409+
container_of(cqe, struct rpcrdma_frwr, fr_cqe);
410+
411+
/* WARNING: Only wr_cqe and status are reliable at this point */
412+
trace_xprtrdma_wc_fastreg(wc, frwr);
413+
/* The MR will get recycled when the associated req is retransmitted */
414+
}
415+
467416
/**
468417
* frwr_send - post Send WR containing the RPC Call message
469418
* @ia: interface adapter
@@ -516,95 +465,126 @@ void frwr_reminv(struct rpcrdma_rep *rep, struct list_head *mrs)
516465
if (mr->mr_handle == rep->rr_inv_rkey) {
517466
list_del_init(&mr->mr_list);
518467
trace_xprtrdma_mr_remoteinv(mr);
519-
mr->frwr.fr_state = FRWR_IS_INVALID;
520468
rpcrdma_mr_unmap_and_put(mr);
521469
break; /* only one invalidated MR per RPC */
522470
}
523471
}
524472

473+
static void __frwr_release_mr(struct ib_wc *wc, struct rpcrdma_mr *mr)
474+
{
475+
if (wc->status != IB_WC_SUCCESS)
476+
rpcrdma_mr_recycle(mr);
477+
else
478+
rpcrdma_mr_unmap_and_put(mr);
479+
}
480+
525481
/**
526-
* frwr_unmap_sync - invalidate memory regions that were registered for @req
527-
* @r_xprt: controlling transport
528-
* @mrs: list of MRs to process
482+
* frwr_wc_localinv - Invoked by RDMA provider for a LOCAL_INV WC
483+
* @cq: completion queue (ignored)
484+
* @wc: completed WR
529485
*
530-
* Sleeps until it is safe for the host CPU to access the
531-
* previously mapped memory regions.
486+
*/
487+
static void frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc)
488+
{
489+
struct ib_cqe *cqe = wc->wr_cqe;
490+
struct rpcrdma_frwr *frwr =
491+
container_of(cqe, struct rpcrdma_frwr, fr_cqe);
492+
struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr);
493+
494+
/* WARNING: Only wr_cqe and status are reliable at this point */
495+
trace_xprtrdma_wc_li(wc, frwr);
496+
__frwr_release_mr(wc, mr);
497+
}
498+
499+
/**
500+
* frwr_wc_localinv_wake - Invoked by RDMA provider for a LOCAL_INV WC
501+
* @cq: completion queue (ignored)
502+
* @wc: completed WR
532503
*
533-
* Caller ensures that @mrs is not empty before the call. This
534-
* function empties the list.
504+
* Awaken anyone waiting for an MR to finish being fenced.
535505
*/
536-
void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt, struct list_head *mrs)
506+
static void frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc)
507+
{
508+
struct ib_cqe *cqe = wc->wr_cqe;
509+
struct rpcrdma_frwr *frwr =
510+
container_of(cqe, struct rpcrdma_frwr, fr_cqe);
511+
struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr);
512+
513+
/* WARNING: Only wr_cqe and status are reliable at this point */
514+
trace_xprtrdma_wc_li_wake(wc, frwr);
515+
complete(&frwr->fr_linv_done);
516+
__frwr_release_mr(wc, mr);
517+
}
518+
519+
/**
520+
* frwr_unmap_sync - invalidate memory regions that were registered for @req
521+
* @r_xprt: controlling transport instance
522+
* @req: rpcrdma_req with a non-empty list of MRs to process
523+
*
524+
* Sleeps until it is safe for the host CPU to access the previously mapped
525+
* memory regions.
526+
*/
527+
void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
537528
{
538529
struct ib_send_wr *first, **prev, *last;
539530
const struct ib_send_wr *bad_wr;
540-
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
541531
struct rpcrdma_frwr *frwr;
542532
struct rpcrdma_mr *mr;
543-
int count, rc;
533+
int rc;
544534

545535
/* ORDER: Invalidate all of the MRs first
546536
*
547537
* Chain the LOCAL_INV Work Requests and post them with
548538
* a single ib_post_send() call.
549539
*/
550540
frwr = NULL;
551-
count = 0;
552541
prev = &first;
553-
list_for_each_entry(mr, mrs, mr_list) {
554-
mr->frwr.fr_state = FRWR_IS_INVALID;
542+
while (!list_empty(&req->rl_registered)) {
543+
mr = rpcrdma_mr_pop(&req->rl_registered);
555544

556-
frwr = &mr->frwr;
557545
trace_xprtrdma_mr_localinv(mr);
546+
r_xprt->rx_stats.local_inv_needed++;
558547

548+
frwr = &mr->frwr;
559549
frwr->fr_cqe.done = frwr_wc_localinv;
560550
last = &frwr->fr_invwr;
561-
memset(last, 0, sizeof(*last));
551+
last->next = NULL;
562552
last->wr_cqe = &frwr->fr_cqe;
553+
last->sg_list = NULL;
554+
last->num_sge = 0;
563555
last->opcode = IB_WR_LOCAL_INV;
556+
last->send_flags = IB_SEND_SIGNALED;
564557
last->ex.invalidate_rkey = mr->mr_handle;
565-
count++;
566558

567559
*prev = last;
568560
prev = &last->next;
569561
}
570-
if (!frwr)
571-
goto unmap;
572562

573563
/* Strong send queue ordering guarantees that when the
574564
* last WR in the chain completes, all WRs in the chain
575565
* are complete.
576566
*/
577-
last->send_flags = IB_SEND_SIGNALED;
578567
frwr->fr_cqe.done = frwr_wc_localinv_wake;
579568
reinit_completion(&frwr->fr_linv_done);
580569

581570
/* Transport disconnect drains the receive CQ before it
582571
* replaces the QP. The RPC reply handler won't call us
583572
* unless ri_id->qp is a valid pointer.
584573
*/
585-
r_xprt->rx_stats.local_inv_needed++;
586574
bad_wr = NULL;
587-
rc = ib_post_send(ia->ri_id->qp, first, &bad_wr);
588-
if (bad_wr != first)
589-
wait_for_completion(&frwr->fr_linv_done);
590-
if (rc)
591-
goto out_release;
575+
rc = ib_post_send(r_xprt->rx_ia.ri_id->qp, first, &bad_wr);
576+
trace_xprtrdma_post_send(req, rc);
592577

593-
/* ORDER: Now DMA unmap all of the MRs, and return
594-
* them to the free MR list.
578+
/* The final LOCAL_INV WR in the chain is supposed to
579+
* do the wake. If it was never posted, the wake will
580+
* not happen, so don't wait in that case.
595581
*/
596-
unmap:
597-
while (!list_empty(mrs)) {
598-
mr = rpcrdma_mr_pop(mrs);
599-
rpcrdma_mr_unmap_and_put(mr);
600-
}
601-
return;
602-
603-
out_release:
604-
pr_err("rpcrdma: FRWR invalidate ib_post_send returned %i\n", rc);
582+
if (bad_wr != first)
583+
wait_for_completion(&frwr->fr_linv_done);
584+
if (!rc)
585+
return;
605586

606-
/* Unmap and release the MRs in the LOCAL_INV WRs that did not
607-
* get posted.
587+
/* Recycle MRs in the LOCAL_INV chain that did not get posted.
608588
*/
609589
while (bad_wr) {
610590
frwr = container_of(bad_wr, struct rpcrdma_frwr,

‎net/sunrpc/xprtrdma/rpc_rdma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ void rpcrdma_release_rqst(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
12771277
* RPC has relinquished all its Send Queue entries.
12781278
*/
12791279
if (!list_empty(&req->rl_registered))
1280-
frwr_unmap_sync(r_xprt, &req->rl_registered);
1280+
frwr_unmap_sync(r_xprt, req);
12811281

12821282
/* Ensure that any DMA mapped pages associated with
12831283
* the Send of the RPC Call have been unmapped before

‎net/sunrpc/xprtrdma/xprt_rdma.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,9 @@ struct rpcrdma_sendctx {
240240
* An external memory region is any buffer or page that is registered
241241
* on the fly (ie, not pre-registered).
242242
*/
243-
enum rpcrdma_frwr_state {
244-
FRWR_IS_INVALID, /* ready to be used */
245-
FRWR_IS_VALID, /* in use */
246-
FRWR_FLUSHED_FR, /* flushed FASTREG WR */
247-
FRWR_FLUSHED_LI, /* flushed LOCALINV WR */
248-
};
249-
250243
struct rpcrdma_frwr {
251244
struct ib_mr *fr_mr;
252245
struct ib_cqe fr_cqe;
253-
enum rpcrdma_frwr_state fr_state;
254246
struct completion fr_linv_done;
255247
union {
256248
struct ib_reg_wr fr_regwr;
@@ -567,8 +559,7 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
567559
struct rpcrdma_mr **mr);
568560
int frwr_send(struct rpcrdma_ia *ia, struct rpcrdma_req *req);
569561
void frwr_reminv(struct rpcrdma_rep *rep, struct list_head *mrs);
570-
void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt,
571-
struct list_head *mrs);
562+
void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req);
572563

573564
/*
574565
* RPC/RDMA protocol calls - xprtrdma/rpc_rdma.c

0 commit comments

Comments
 (0)