frwr_ops.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * Copyright (c) 2015 Oracle. All rights reserved.
  3. * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
  4. */
  5. /* Lightweight memory registration using Fast Registration Work
  6. * Requests (FRWR). Also referred to sometimes as FRMR mode.
  7. *
  8. * FRWR features ordered asynchronous registration and deregistration
  9. * of arbitrarily sized memory regions. This is the fastest and safest
  10. * but most complex memory registration mode.
  11. */
  12. /* Normal operation
  13. *
  14. * A Memory Region is prepared for RDMA READ or WRITE using a FAST_REG
  15. * Work Request (frmr_op_map). When the RDMA operation is finished, this
  16. * Memory Region is invalidated using a LOCAL_INV Work Request
  17. * (frmr_op_unmap).
  18. *
  19. * Typically these Work Requests are not signaled, and neither are RDMA
  20. * SEND Work Requests (with the exception of signaling occasionally to
  21. * prevent provider work queue overflows). This greatly reduces HCA
  22. * interrupt workload.
  23. *
  24. * As an optimization, frwr_op_unmap marks MRs INVALID before the
  25. * LOCAL_INV WR is posted. If posting succeeds, the MR is placed on
  26. * rb_mws immediately so that no work (like managing a linked list
  27. * under a spinlock) is needed in the completion upcall.
  28. *
  29. * But this means that frwr_op_map() can occasionally encounter an MR
  30. * that is INVALID but the LOCAL_INV WR has not completed. Work Queue
  31. * ordering prevents a subsequent FAST_REG WR from executing against
  32. * that MR while it is still being invalidated.
  33. */
  34. /* Transport recovery
  35. *
  36. * ->op_map and the transport connect worker cannot run at the same
  37. * time, but ->op_unmap can fire while the transport connect worker
  38. * is running. Thus MR recovery is handled in ->op_map, to guarantee
  39. * that recovered MRs are owned by a sending RPC, and not one where
  40. * ->op_unmap could fire at the same time transport reconnect is
  41. * being done.
  42. *
  43. * When the underlying transport disconnects, MRs are left in one of
  44. * four states:
  45. *
  46. * INVALID: The MR was not in use before the QP entered ERROR state.
  47. *
  48. * VALID: The MR was registered before the QP entered ERROR state.
  49. *
  50. * FLUSHED_FR: The MR was being registered when the QP entered ERROR
  51. * state, and the pending WR was flushed.
  52. *
  53. * FLUSHED_LI: The MR was being invalidated when the QP entered ERROR
  54. * state, and the pending WR was flushed.
  55. *
  56. * When frwr_op_map encounters FLUSHED and VALID MRs, they are recovered
  57. * with ib_dereg_mr and then are re-initialized. Because MR recovery
  58. * allocates fresh resources, it is deferred to a workqueue, and the
  59. * recovered MRs are placed back on the rb_mws list when recovery is
  60. * complete. frwr_op_map allocates another MR for the current RPC while
  61. * the broken MR is reset.
  62. *
  63. * To ensure that frwr_op_map doesn't encounter an MR that is marked
  64. * INVALID but that is about to be flushed due to a previous transport
  65. * disconnect, the transport connect worker attempts to drain all
  66. * pending send queue WRs before the transport is reconnected.
  67. */
  68. #include <linux/sunrpc/rpc_rdma.h>
  69. #include "xprt_rdma.h"
  70. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  71. # define RPCDBG_FACILITY RPCDBG_TRANS
  72. #endif
  73. bool
  74. frwr_is_supported(struct rpcrdma_ia *ia)
  75. {
  76. struct ib_device_attr *attrs = &ia->ri_device->attrs;
  77. if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS))
  78. goto out_not_supported;
  79. if (attrs->max_fast_reg_page_list_len == 0)
  80. goto out_not_supported;
  81. return true;
  82. out_not_supported:
  83. pr_info("rpcrdma: 'frwr' mode is not supported by device %s\n",
  84. ia->ri_device->name);
  85. return false;
  86. }
  87. static int
  88. frwr_op_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mw *r)
  89. {
  90. unsigned int depth = ia->ri_max_frmr_depth;
  91. struct rpcrdma_frmr *f = &r->frmr;
  92. int rc;
  93. f->fr_mr = ib_alloc_mr(ia->ri_pd, IB_MR_TYPE_MEM_REG, depth);
  94. if (IS_ERR(f->fr_mr))
  95. goto out_mr_err;
  96. r->mw_sg = kcalloc(depth, sizeof(*r->mw_sg), GFP_KERNEL);
  97. if (!r->mw_sg)
  98. goto out_list_err;
  99. sg_init_table(r->mw_sg, depth);
  100. init_completion(&f->fr_linv_done);
  101. return 0;
  102. out_mr_err:
  103. rc = PTR_ERR(f->fr_mr);
  104. dprintk("RPC: %s: ib_alloc_mr status %i\n",
  105. __func__, rc);
  106. return rc;
  107. out_list_err:
  108. rc = -ENOMEM;
  109. dprintk("RPC: %s: sg allocation failure\n",
  110. __func__);
  111. ib_dereg_mr(f->fr_mr);
  112. return rc;
  113. }
  114. static void
  115. frwr_op_release_mr(struct rpcrdma_mw *r)
  116. {
  117. int rc;
  118. /* Ensure MW is not on any rl_registered list */
  119. if (!list_empty(&r->mw_list))
  120. list_del(&r->mw_list);
  121. rc = ib_dereg_mr(r->frmr.fr_mr);
  122. if (rc)
  123. pr_err("rpcrdma: final ib_dereg_mr for %p returned %i\n",
  124. r, rc);
  125. kfree(r->mw_sg);
  126. kfree(r);
  127. }
  128. static int
  129. __frwr_reset_mr(struct rpcrdma_ia *ia, struct rpcrdma_mw *r)
  130. {
  131. struct rpcrdma_frmr *f = &r->frmr;
  132. int rc;
  133. rc = ib_dereg_mr(f->fr_mr);
  134. if (rc) {
  135. pr_warn("rpcrdma: ib_dereg_mr status %d, frwr %p orphaned\n",
  136. rc, r);
  137. return rc;
  138. }
  139. f->fr_mr = ib_alloc_mr(ia->ri_pd, IB_MR_TYPE_MEM_REG,
  140. ia->ri_max_frmr_depth);
  141. if (IS_ERR(f->fr_mr)) {
  142. pr_warn("rpcrdma: ib_alloc_mr status %ld, frwr %p orphaned\n",
  143. PTR_ERR(f->fr_mr), r);
  144. return PTR_ERR(f->fr_mr);
  145. }
  146. dprintk("RPC: %s: recovered FRMR %p\n", __func__, f);
  147. f->fr_state = FRMR_IS_INVALID;
  148. return 0;
  149. }
  150. /* Reset of a single FRMR. Generate a fresh rkey by replacing the MR.
  151. *
  152. * There's no recovery if this fails. The FRMR is abandoned, but
  153. * remains in rb_all. It will be cleaned up when the transport is
  154. * destroyed.
  155. */
  156. static void
  157. frwr_op_recover_mr(struct rpcrdma_mw *mw)
  158. {
  159. enum rpcrdma_frmr_state state = mw->frmr.fr_state;
  160. struct rpcrdma_xprt *r_xprt = mw->mw_xprt;
  161. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  162. int rc;
  163. rc = __frwr_reset_mr(ia, mw);
  164. if (state != FRMR_FLUSHED_LI)
  165. ib_dma_unmap_sg(ia->ri_device,
  166. mw->mw_sg, mw->mw_nents, mw->mw_dir);
  167. if (rc)
  168. goto out_release;
  169. rpcrdma_put_mw(r_xprt, mw);
  170. r_xprt->rx_stats.mrs_recovered++;
  171. return;
  172. out_release:
  173. pr_err("rpcrdma: FRMR reset failed %d, %p release\n", rc, mw);
  174. r_xprt->rx_stats.mrs_orphaned++;
  175. spin_lock(&r_xprt->rx_buf.rb_mwlock);
  176. list_del(&mw->mw_all);
  177. spin_unlock(&r_xprt->rx_buf.rb_mwlock);
  178. frwr_op_release_mr(mw);
  179. }
  180. static int
  181. frwr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep,
  182. struct rpcrdma_create_data_internal *cdata)
  183. {
  184. int depth, delta;
  185. ia->ri_max_frmr_depth =
  186. min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS,
  187. ia->ri_device->attrs.max_fast_reg_page_list_len);
  188. dprintk("RPC: %s: device's max FR page list len = %u\n",
  189. __func__, ia->ri_max_frmr_depth);
  190. /* Add room for frmr register and invalidate WRs.
  191. * 1. FRMR reg WR for head
  192. * 2. FRMR invalidate WR for head
  193. * 3. N FRMR reg WRs for pagelist
  194. * 4. N FRMR invalidate WRs for pagelist
  195. * 5. FRMR reg WR for tail
  196. * 6. FRMR invalidate WR for tail
  197. * 7. The RDMA_SEND WR
  198. */
  199. depth = 7;
  200. /* Calculate N if the device max FRMR depth is smaller than
  201. * RPCRDMA_MAX_DATA_SEGS.
  202. */
  203. if (ia->ri_max_frmr_depth < RPCRDMA_MAX_DATA_SEGS) {
  204. delta = RPCRDMA_MAX_DATA_SEGS - ia->ri_max_frmr_depth;
  205. do {
  206. depth += 2; /* FRMR reg + invalidate */
  207. delta -= ia->ri_max_frmr_depth;
  208. } while (delta > 0);
  209. }
  210. ep->rep_attr.cap.max_send_wr *= depth;
  211. if (ep->rep_attr.cap.max_send_wr > ia->ri_device->attrs.max_qp_wr) {
  212. cdata->max_requests = ia->ri_device->attrs.max_qp_wr / depth;
  213. if (!cdata->max_requests)
  214. return -EINVAL;
  215. ep->rep_attr.cap.max_send_wr = cdata->max_requests *
  216. depth;
  217. }
  218. ia->ri_max_segs = max_t(unsigned int, 1, RPCRDMA_MAX_DATA_SEGS /
  219. ia->ri_max_frmr_depth);
  220. return 0;
  221. }
  222. /* FRWR mode conveys a list of pages per chunk segment. The
  223. * maximum length of that list is the FRWR page list depth.
  224. */
  225. static size_t
  226. frwr_op_maxpages(struct rpcrdma_xprt *r_xprt)
  227. {
  228. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  229. return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS,
  230. RPCRDMA_MAX_HDR_SEGS * ia->ri_max_frmr_depth);
  231. }
  232. static void
  233. __frwr_sendcompletion_flush(struct ib_wc *wc, const char *wr)
  234. {
  235. if (wc->status != IB_WC_WR_FLUSH_ERR)
  236. pr_err("rpcrdma: %s: %s (%u/0x%x)\n",
  237. wr, ib_wc_status_msg(wc->status),
  238. wc->status, wc->vendor_err);
  239. }
  240. /**
  241. * frwr_wc_fastreg - Invoked by RDMA provider for each polled FastReg WC
  242. * @cq: completion queue (ignored)
  243. * @wc: completed WR
  244. *
  245. */
  246. static void
  247. frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc)
  248. {
  249. struct rpcrdma_frmr *frmr;
  250. struct ib_cqe *cqe;
  251. /* WARNING: Only wr_cqe and status are reliable at this point */
  252. if (wc->status != IB_WC_SUCCESS) {
  253. cqe = wc->wr_cqe;
  254. frmr = container_of(cqe, struct rpcrdma_frmr, fr_cqe);
  255. frmr->fr_state = FRMR_FLUSHED_FR;
  256. __frwr_sendcompletion_flush(wc, "fastreg");
  257. }
  258. }
  259. /**
  260. * frwr_wc_localinv - Invoked by RDMA provider for each polled LocalInv WC
  261. * @cq: completion queue (ignored)
  262. * @wc: completed WR
  263. *
  264. */
  265. static void
  266. frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc)
  267. {
  268. struct rpcrdma_frmr *frmr;
  269. struct ib_cqe *cqe;
  270. /* WARNING: Only wr_cqe and status are reliable at this point */
  271. if (wc->status != IB_WC_SUCCESS) {
  272. cqe = wc->wr_cqe;
  273. frmr = container_of(cqe, struct rpcrdma_frmr, fr_cqe);
  274. frmr->fr_state = FRMR_FLUSHED_LI;
  275. __frwr_sendcompletion_flush(wc, "localinv");
  276. }
  277. }
  278. /**
  279. * frwr_wc_localinv - Invoked by RDMA provider for each polled LocalInv WC
  280. * @cq: completion queue (ignored)
  281. * @wc: completed WR
  282. *
  283. * Awaken anyone waiting for an MR to finish being fenced.
  284. */
  285. static void
  286. frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc)
  287. {
  288. struct rpcrdma_frmr *frmr;
  289. struct ib_cqe *cqe;
  290. /* WARNING: Only wr_cqe and status are reliable at this point */
  291. cqe = wc->wr_cqe;
  292. frmr = container_of(cqe, struct rpcrdma_frmr, fr_cqe);
  293. if (wc->status != IB_WC_SUCCESS) {
  294. frmr->fr_state = FRMR_FLUSHED_LI;
  295. __frwr_sendcompletion_flush(wc, "localinv");
  296. }
  297. complete(&frmr->fr_linv_done);
  298. }
  299. /* Post a REG_MR Work Request to register a memory region
  300. * for remote access via RDMA READ or RDMA WRITE.
  301. */
  302. static int
  303. frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
  304. int nsegs, bool writing, struct rpcrdma_mw **out)
  305. {
  306. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  307. struct rpcrdma_mw *mw;
  308. struct rpcrdma_frmr *frmr;
  309. struct ib_mr *mr;
  310. struct ib_reg_wr *reg_wr;
  311. struct ib_send_wr *bad_wr;
  312. int rc, i, n, dma_nents;
  313. u8 key;
  314. mw = NULL;
  315. do {
  316. if (mw)
  317. rpcrdma_defer_mr_recovery(mw);
  318. mw = rpcrdma_get_mw(r_xprt);
  319. if (!mw)
  320. return -ENOBUFS;
  321. } while (mw->frmr.fr_state != FRMR_IS_INVALID);
  322. frmr = &mw->frmr;
  323. frmr->fr_state = FRMR_IS_VALID;
  324. mr = frmr->fr_mr;
  325. reg_wr = &frmr->fr_regwr;
  326. if (nsegs > ia->ri_max_frmr_depth)
  327. nsegs = ia->ri_max_frmr_depth;
  328. for (i = 0; i < nsegs;) {
  329. if (seg->mr_page)
  330. sg_set_page(&mw->mw_sg[i],
  331. seg->mr_page,
  332. seg->mr_len,
  333. offset_in_page(seg->mr_offset));
  334. else
  335. sg_set_buf(&mw->mw_sg[i], seg->mr_offset,
  336. seg->mr_len);
  337. ++seg;
  338. ++i;
  339. /* Check for holes */
  340. if ((i < nsegs && offset_in_page(seg->mr_offset)) ||
  341. offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len))
  342. break;
  343. }
  344. mw->mw_nents = i;
  345. mw->mw_dir = rpcrdma_data_dir(writing);
  346. if (i == 0)
  347. goto out_dmamap_err;
  348. dma_nents = ib_dma_map_sg(ia->ri_device,
  349. mw->mw_sg, mw->mw_nents, mw->mw_dir);
  350. if (!dma_nents)
  351. goto out_dmamap_err;
  352. n = ib_map_mr_sg(mr, mw->mw_sg, mw->mw_nents, NULL, PAGE_SIZE);
  353. if (unlikely(n != mw->mw_nents))
  354. goto out_mapmr_err;
  355. dprintk("RPC: %s: Using frmr %p to map %u segments (%u bytes)\n",
  356. __func__, frmr, mw->mw_nents, mr->length);
  357. key = (u8)(mr->rkey & 0x000000FF);
  358. ib_update_fast_reg_key(mr, ++key);
  359. reg_wr->wr.next = NULL;
  360. reg_wr->wr.opcode = IB_WR_REG_MR;
  361. frmr->fr_cqe.done = frwr_wc_fastreg;
  362. reg_wr->wr.wr_cqe = &frmr->fr_cqe;
  363. reg_wr->wr.num_sge = 0;
  364. reg_wr->wr.send_flags = 0;
  365. reg_wr->mr = mr;
  366. reg_wr->key = mr->rkey;
  367. reg_wr->access = writing ?
  368. IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE :
  369. IB_ACCESS_REMOTE_READ;
  370. rpcrdma_set_signaled(&r_xprt->rx_ep, &reg_wr->wr);
  371. rc = ib_post_send(ia->ri_id->qp, &reg_wr->wr, &bad_wr);
  372. if (rc)
  373. goto out_senderr;
  374. mw->mw_handle = mr->rkey;
  375. mw->mw_length = mr->length;
  376. mw->mw_offset = mr->iova;
  377. *out = mw;
  378. return mw->mw_nents;
  379. out_dmamap_err:
  380. pr_err("rpcrdma: failed to dma map sg %p sg_nents %u\n",
  381. mw->mw_sg, mw->mw_nents);
  382. rpcrdma_defer_mr_recovery(mw);
  383. return -EIO;
  384. out_mapmr_err:
  385. pr_err("rpcrdma: failed to map mr %p (%u/%u)\n",
  386. frmr->fr_mr, n, mw->mw_nents);
  387. rpcrdma_defer_mr_recovery(mw);
  388. return -EIO;
  389. out_senderr:
  390. pr_err("rpcrdma: FRMR registration ib_post_send returned %i\n", rc);
  391. rpcrdma_defer_mr_recovery(mw);
  392. return -ENOTCONN;
  393. }
  394. static struct ib_send_wr *
  395. __frwr_prepare_linv_wr(struct rpcrdma_mw *mw)
  396. {
  397. struct rpcrdma_frmr *f = &mw->frmr;
  398. struct ib_send_wr *invalidate_wr;
  399. dprintk("RPC: %s: invalidating frmr %p\n", __func__, f);
  400. f->fr_state = FRMR_IS_INVALID;
  401. invalidate_wr = &f->fr_invwr;
  402. memset(invalidate_wr, 0, sizeof(*invalidate_wr));
  403. f->fr_cqe.done = frwr_wc_localinv;
  404. invalidate_wr->wr_cqe = &f->fr_cqe;
  405. invalidate_wr->opcode = IB_WR_LOCAL_INV;
  406. invalidate_wr->ex.invalidate_rkey = f->fr_mr->rkey;
  407. return invalidate_wr;
  408. }
  409. /* Invalidate all memory regions that were registered for "req".
  410. *
  411. * Sleeps until it is safe for the host CPU to access the
  412. * previously mapped memory regions.
  413. *
  414. * Caller ensures that req->rl_registered is not empty.
  415. */
  416. static void
  417. frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
  418. {
  419. struct ib_send_wr *invalidate_wrs, *pos, *prev, *bad_wr;
  420. struct rpcrdma_rep *rep = req->rl_reply;
  421. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  422. struct rpcrdma_mw *mw, *tmp;
  423. struct rpcrdma_frmr *f;
  424. int count, rc;
  425. dprintk("RPC: %s: req %p\n", __func__, req);
  426. /* ORDER: Invalidate all of the req's MRs first
  427. *
  428. * Chain the LOCAL_INV Work Requests and post them with
  429. * a single ib_post_send() call.
  430. */
  431. f = NULL;
  432. count = 0;
  433. invalidate_wrs = pos = prev = NULL;
  434. list_for_each_entry(mw, &req->rl_registered, mw_list) {
  435. if ((rep->rr_wc_flags & IB_WC_WITH_INVALIDATE) &&
  436. (mw->mw_handle == rep->rr_inv_rkey)) {
  437. mw->frmr.fr_state = FRMR_IS_INVALID;
  438. continue;
  439. }
  440. pos = __frwr_prepare_linv_wr(mw);
  441. count++;
  442. if (!invalidate_wrs)
  443. invalidate_wrs = pos;
  444. else
  445. prev->next = pos;
  446. prev = pos;
  447. f = &mw->frmr;
  448. }
  449. if (!f)
  450. goto unmap;
  451. /* Strong send queue ordering guarantees that when the
  452. * last WR in the chain completes, all WRs in the chain
  453. * are complete.
  454. */
  455. f->fr_invwr.send_flags = IB_SEND_SIGNALED;
  456. f->fr_cqe.done = frwr_wc_localinv_wake;
  457. reinit_completion(&f->fr_linv_done);
  458. /* Initialize CQ count, since there is always a signaled
  459. * WR being posted here. The new cqcount depends on how
  460. * many SQEs are about to be consumed.
  461. */
  462. rpcrdma_init_cqcount(&r_xprt->rx_ep, count);
  463. /* Transport disconnect drains the receive CQ before it
  464. * replaces the QP. The RPC reply handler won't call us
  465. * unless ri_id->qp is a valid pointer.
  466. */
  467. r_xprt->rx_stats.local_inv_needed++;
  468. rc = ib_post_send(ia->ri_id->qp, invalidate_wrs, &bad_wr);
  469. if (rc)
  470. goto reset_mrs;
  471. wait_for_completion(&f->fr_linv_done);
  472. /* ORDER: Now DMA unmap all of the req's MRs, and return
  473. * them to the free MW list.
  474. */
  475. unmap:
  476. list_for_each_entry_safe(mw, tmp, &req->rl_registered, mw_list) {
  477. dprintk("RPC: %s: unmapping frmr %p\n",
  478. __func__, &mw->frmr);
  479. list_del_init(&mw->mw_list);
  480. ib_dma_unmap_sg(ia->ri_device,
  481. mw->mw_sg, mw->mw_nents, mw->mw_dir);
  482. rpcrdma_put_mw(r_xprt, mw);
  483. }
  484. return;
  485. reset_mrs:
  486. pr_err("rpcrdma: FRMR invalidate ib_post_send returned %i\n", rc);
  487. rdma_disconnect(ia->ri_id);
  488. /* Find and reset the MRs in the LOCAL_INV WRs that did not
  489. * get posted. This is synchronous, and slow.
  490. */
  491. list_for_each_entry(mw, &req->rl_registered, mw_list) {
  492. f = &mw->frmr;
  493. if (mw->frmr.fr_mr->rkey == bad_wr->ex.invalidate_rkey) {
  494. __frwr_reset_mr(ia, mw);
  495. bad_wr = bad_wr->next;
  496. }
  497. }
  498. goto unmap;
  499. }
  500. /* Use a slow, safe mechanism to invalidate all memory regions
  501. * that were registered for "req".
  502. */
  503. static void
  504. frwr_op_unmap_safe(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
  505. bool sync)
  506. {
  507. struct rpcrdma_mw *mw;
  508. while (!list_empty(&req->rl_registered)) {
  509. mw = list_first_entry(&req->rl_registered,
  510. struct rpcrdma_mw, mw_list);
  511. list_del_init(&mw->mw_list);
  512. if (sync)
  513. frwr_op_recover_mr(mw);
  514. else
  515. rpcrdma_defer_mr_recovery(mw);
  516. }
  517. }
  518. const struct rpcrdma_memreg_ops rpcrdma_frwr_memreg_ops = {
  519. .ro_map = frwr_op_map,
  520. .ro_unmap_sync = frwr_op_unmap_sync,
  521. .ro_unmap_safe = frwr_op_unmap_safe,
  522. .ro_recover_mr = frwr_op_recover_mr,
  523. .ro_open = frwr_op_open,
  524. .ro_maxpages = frwr_op_maxpages,
  525. .ro_init_mr = frwr_op_init_mr,
  526. .ro_release_mr = frwr_op_release_mr,
  527. .ro_displayname = "frwr",
  528. .ro_send_w_inv_ok = RPCRDMA_CMP_F_SND_W_INV_OK,
  529. };