frwr_ops.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. * three states:
  45. *
  46. * INVALID: The MR was not in use before the QP entered ERROR state.
  47. * (Or, the LOCAL_INV WR has not completed or flushed yet).
  48. *
  49. * STALE: The MR was being registered or unregistered when the QP
  50. * entered ERROR state, and the pending WR was flushed.
  51. *
  52. * VALID: The MR was registered before the QP entered ERROR state.
  53. *
  54. * When frwr_op_map encounters STALE and VALID MRs, they are recovered
  55. * with ib_dereg_mr and then are re-initialized. Beause MR recovery
  56. * allocates fresh resources, it is deferred to a workqueue, and the
  57. * recovered MRs are placed back on the rb_mws list when recovery is
  58. * complete. frwr_op_map allocates another MR for the current RPC while
  59. * the broken MR is reset.
  60. *
  61. * To ensure that frwr_op_map doesn't encounter an MR that is marked
  62. * INVALID but that is about to be flushed due to a previous transport
  63. * disconnect, the transport connect worker attempts to drain all
  64. * pending send queue WRs before the transport is reconnected.
  65. */
  66. #include "xprt_rdma.h"
  67. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  68. # define RPCDBG_FACILITY RPCDBG_TRANS
  69. #endif
  70. static struct workqueue_struct *frwr_recovery_wq;
  71. #define FRWR_RECOVERY_WQ_FLAGS (WQ_UNBOUND | WQ_MEM_RECLAIM)
  72. int
  73. frwr_alloc_recovery_wq(void)
  74. {
  75. frwr_recovery_wq = alloc_workqueue("frwr_recovery",
  76. FRWR_RECOVERY_WQ_FLAGS, 0);
  77. return !frwr_recovery_wq ? -ENOMEM : 0;
  78. }
  79. void
  80. frwr_destroy_recovery_wq(void)
  81. {
  82. struct workqueue_struct *wq;
  83. if (!frwr_recovery_wq)
  84. return;
  85. wq = frwr_recovery_wq;
  86. frwr_recovery_wq = NULL;
  87. destroy_workqueue(wq);
  88. }
  89. /* Deferred reset of a single FRMR. Generate a fresh rkey by
  90. * replacing the MR.
  91. *
  92. * There's no recovery if this fails. The FRMR is abandoned, but
  93. * remains in rb_all. It will be cleaned up when the transport is
  94. * destroyed.
  95. */
  96. static void
  97. __frwr_recovery_worker(struct work_struct *work)
  98. {
  99. struct rpcrdma_mw *r = container_of(work, struct rpcrdma_mw,
  100. r.frmr.fr_work);
  101. struct rpcrdma_xprt *r_xprt = r->r.frmr.fr_xprt;
  102. unsigned int depth = r_xprt->rx_ia.ri_max_frmr_depth;
  103. struct ib_pd *pd = r_xprt->rx_ia.ri_pd;
  104. if (ib_dereg_mr(r->r.frmr.fr_mr))
  105. goto out_fail;
  106. r->r.frmr.fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth);
  107. if (IS_ERR(r->r.frmr.fr_mr))
  108. goto out_fail;
  109. dprintk("RPC: %s: recovered FRMR %p\n", __func__, r);
  110. r->r.frmr.fr_state = FRMR_IS_INVALID;
  111. rpcrdma_put_mw(r_xprt, r);
  112. return;
  113. out_fail:
  114. pr_warn("RPC: %s: FRMR %p unrecovered\n",
  115. __func__, r);
  116. }
  117. /* A broken MR was discovered in a context that can't sleep.
  118. * Defer recovery to the recovery worker.
  119. */
  120. static void
  121. __frwr_queue_recovery(struct rpcrdma_mw *r)
  122. {
  123. INIT_WORK(&r->r.frmr.fr_work, __frwr_recovery_worker);
  124. queue_work(frwr_recovery_wq, &r->r.frmr.fr_work);
  125. }
  126. static int
  127. __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device,
  128. unsigned int depth)
  129. {
  130. struct rpcrdma_frmr *f = &r->r.frmr;
  131. int rc;
  132. f->fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth);
  133. if (IS_ERR(f->fr_mr))
  134. goto out_mr_err;
  135. f->sg = kcalloc(depth, sizeof(*f->sg), GFP_KERNEL);
  136. if (!f->sg)
  137. goto out_list_err;
  138. sg_init_table(f->sg, depth);
  139. return 0;
  140. out_mr_err:
  141. rc = PTR_ERR(f->fr_mr);
  142. dprintk("RPC: %s: ib_alloc_mr status %i\n",
  143. __func__, rc);
  144. return rc;
  145. out_list_err:
  146. rc = -ENOMEM;
  147. dprintk("RPC: %s: sg allocation failure\n",
  148. __func__);
  149. ib_dereg_mr(f->fr_mr);
  150. return rc;
  151. }
  152. static void
  153. __frwr_release(struct rpcrdma_mw *r)
  154. {
  155. int rc;
  156. rc = ib_dereg_mr(r->r.frmr.fr_mr);
  157. if (rc)
  158. dprintk("RPC: %s: ib_dereg_mr status %i\n",
  159. __func__, rc);
  160. kfree(r->r.frmr.sg);
  161. }
  162. static int
  163. frwr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep,
  164. struct rpcrdma_create_data_internal *cdata)
  165. {
  166. int depth, delta;
  167. ia->ri_max_frmr_depth =
  168. min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS,
  169. ia->ri_device->attrs.max_fast_reg_page_list_len);
  170. dprintk("RPC: %s: device's max FR page list len = %u\n",
  171. __func__, ia->ri_max_frmr_depth);
  172. /* Add room for frmr register and invalidate WRs.
  173. * 1. FRMR reg WR for head
  174. * 2. FRMR invalidate WR for head
  175. * 3. N FRMR reg WRs for pagelist
  176. * 4. N FRMR invalidate WRs for pagelist
  177. * 5. FRMR reg WR for tail
  178. * 6. FRMR invalidate WR for tail
  179. * 7. The RDMA_SEND WR
  180. */
  181. depth = 7;
  182. /* Calculate N if the device max FRMR depth is smaller than
  183. * RPCRDMA_MAX_DATA_SEGS.
  184. */
  185. if (ia->ri_max_frmr_depth < RPCRDMA_MAX_DATA_SEGS) {
  186. delta = RPCRDMA_MAX_DATA_SEGS - ia->ri_max_frmr_depth;
  187. do {
  188. depth += 2; /* FRMR reg + invalidate */
  189. delta -= ia->ri_max_frmr_depth;
  190. } while (delta > 0);
  191. }
  192. ep->rep_attr.cap.max_send_wr *= depth;
  193. if (ep->rep_attr.cap.max_send_wr > ia->ri_device->attrs.max_qp_wr) {
  194. cdata->max_requests = ia->ri_device->attrs.max_qp_wr / depth;
  195. if (!cdata->max_requests)
  196. return -EINVAL;
  197. ep->rep_attr.cap.max_send_wr = cdata->max_requests *
  198. depth;
  199. }
  200. return 0;
  201. }
  202. /* FRWR mode conveys a list of pages per chunk segment. The
  203. * maximum length of that list is the FRWR page list depth.
  204. */
  205. static size_t
  206. frwr_op_maxpages(struct rpcrdma_xprt *r_xprt)
  207. {
  208. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  209. return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS,
  210. rpcrdma_max_segments(r_xprt) * ia->ri_max_frmr_depth);
  211. }
  212. /* If FAST_REG or LOCAL_INV failed, indicate the frmr needs
  213. * to be reset.
  214. *
  215. * WARNING: Only wr_id and status are reliable at this point
  216. */
  217. static void
  218. __frwr_sendcompletion_flush(struct ib_wc *wc, struct rpcrdma_mw *r)
  219. {
  220. if (likely(wc->status == IB_WC_SUCCESS))
  221. return;
  222. /* WARNING: Only wr_id and status are reliable at this point */
  223. r = (struct rpcrdma_mw *)(unsigned long)wc->wr_id;
  224. if (wc->status == IB_WC_WR_FLUSH_ERR)
  225. dprintk("RPC: %s: frmr %p flushed\n", __func__, r);
  226. else
  227. pr_warn("RPC: %s: frmr %p error, status %s (%d)\n",
  228. __func__, r, ib_wc_status_msg(wc->status), wc->status);
  229. r->r.frmr.fr_state = FRMR_IS_STALE;
  230. }
  231. static void
  232. frwr_sendcompletion(struct ib_wc *wc)
  233. {
  234. struct rpcrdma_mw *r = (struct rpcrdma_mw *)(unsigned long)wc->wr_id;
  235. struct rpcrdma_frmr *f = &r->r.frmr;
  236. if (unlikely(wc->status != IB_WC_SUCCESS))
  237. __frwr_sendcompletion_flush(wc, r);
  238. if (f->fr_waiter)
  239. complete(&f->fr_linv_done);
  240. }
  241. static int
  242. frwr_op_init(struct rpcrdma_xprt *r_xprt)
  243. {
  244. struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
  245. struct ib_device *device = r_xprt->rx_ia.ri_device;
  246. unsigned int depth = r_xprt->rx_ia.ri_max_frmr_depth;
  247. struct ib_pd *pd = r_xprt->rx_ia.ri_pd;
  248. int i;
  249. spin_lock_init(&buf->rb_mwlock);
  250. INIT_LIST_HEAD(&buf->rb_mws);
  251. INIT_LIST_HEAD(&buf->rb_all);
  252. i = max_t(int, RPCRDMA_MAX_DATA_SEGS / depth, 1);
  253. i += 2; /* head + tail */
  254. i *= buf->rb_max_requests; /* one set for each RPC slot */
  255. dprintk("RPC: %s: initalizing %d FRMRs\n", __func__, i);
  256. while (i--) {
  257. struct rpcrdma_mw *r;
  258. int rc;
  259. r = kzalloc(sizeof(*r), GFP_KERNEL);
  260. if (!r)
  261. return -ENOMEM;
  262. rc = __frwr_init(r, pd, device, depth);
  263. if (rc) {
  264. kfree(r);
  265. return rc;
  266. }
  267. list_add(&r->mw_list, &buf->rb_mws);
  268. list_add(&r->mw_all, &buf->rb_all);
  269. r->mw_sendcompletion = frwr_sendcompletion;
  270. r->r.frmr.fr_xprt = r_xprt;
  271. }
  272. return 0;
  273. }
  274. /* Post a FAST_REG Work Request to register a memory region
  275. * for remote access via RDMA READ or RDMA WRITE.
  276. */
  277. static int
  278. frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
  279. int nsegs, bool writing)
  280. {
  281. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  282. struct ib_device *device = ia->ri_device;
  283. enum dma_data_direction direction = rpcrdma_data_dir(writing);
  284. struct rpcrdma_mr_seg *seg1 = seg;
  285. struct rpcrdma_mw *mw;
  286. struct rpcrdma_frmr *frmr;
  287. struct ib_mr *mr;
  288. struct ib_reg_wr *reg_wr;
  289. struct ib_send_wr *bad_wr;
  290. int rc, i, n, dma_nents;
  291. u8 key;
  292. mw = seg1->rl_mw;
  293. seg1->rl_mw = NULL;
  294. do {
  295. if (mw)
  296. __frwr_queue_recovery(mw);
  297. mw = rpcrdma_get_mw(r_xprt);
  298. if (!mw)
  299. return -ENOMEM;
  300. } while (mw->r.frmr.fr_state != FRMR_IS_INVALID);
  301. frmr = &mw->r.frmr;
  302. frmr->fr_state = FRMR_IS_VALID;
  303. frmr->fr_waiter = false;
  304. mr = frmr->fr_mr;
  305. reg_wr = &frmr->fr_regwr;
  306. if (nsegs > ia->ri_max_frmr_depth)
  307. nsegs = ia->ri_max_frmr_depth;
  308. for (i = 0; i < nsegs;) {
  309. if (seg->mr_page)
  310. sg_set_page(&frmr->sg[i],
  311. seg->mr_page,
  312. seg->mr_len,
  313. offset_in_page(seg->mr_offset));
  314. else
  315. sg_set_buf(&frmr->sg[i], seg->mr_offset,
  316. seg->mr_len);
  317. ++seg;
  318. ++i;
  319. /* Check for holes */
  320. if ((i < nsegs && offset_in_page(seg->mr_offset)) ||
  321. offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len))
  322. break;
  323. }
  324. frmr->sg_nents = i;
  325. dma_nents = ib_dma_map_sg(device, frmr->sg, frmr->sg_nents, direction);
  326. if (!dma_nents) {
  327. pr_err("RPC: %s: failed to dma map sg %p sg_nents %u\n",
  328. __func__, frmr->sg, frmr->sg_nents);
  329. return -ENOMEM;
  330. }
  331. n = ib_map_mr_sg(mr, frmr->sg, frmr->sg_nents, PAGE_SIZE);
  332. if (unlikely(n != frmr->sg_nents)) {
  333. pr_err("RPC: %s: failed to map mr %p (%u/%u)\n",
  334. __func__, frmr->fr_mr, n, frmr->sg_nents);
  335. rc = n < 0 ? n : -EINVAL;
  336. goto out_senderr;
  337. }
  338. dprintk("RPC: %s: Using frmr %p to map %u segments (%u bytes)\n",
  339. __func__, mw, frmr->sg_nents, mr->length);
  340. key = (u8)(mr->rkey & 0x000000FF);
  341. ib_update_fast_reg_key(mr, ++key);
  342. reg_wr->wr.next = NULL;
  343. reg_wr->wr.opcode = IB_WR_REG_MR;
  344. reg_wr->wr.wr_id = (uintptr_t)mw;
  345. reg_wr->wr.num_sge = 0;
  346. reg_wr->wr.send_flags = 0;
  347. reg_wr->mr = mr;
  348. reg_wr->key = mr->rkey;
  349. reg_wr->access = writing ?
  350. IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE :
  351. IB_ACCESS_REMOTE_READ;
  352. DECR_CQCOUNT(&r_xprt->rx_ep);
  353. rc = ib_post_send(ia->ri_id->qp, &reg_wr->wr, &bad_wr);
  354. if (rc)
  355. goto out_senderr;
  356. seg1->mr_dir = direction;
  357. seg1->rl_mw = mw;
  358. seg1->mr_rkey = mr->rkey;
  359. seg1->mr_base = mr->iova;
  360. seg1->mr_nsegs = frmr->sg_nents;
  361. seg1->mr_len = mr->length;
  362. return frmr->sg_nents;
  363. out_senderr:
  364. dprintk("RPC: %s: ib_post_send status %i\n", __func__, rc);
  365. ib_dma_unmap_sg(device, frmr->sg, dma_nents, direction);
  366. __frwr_queue_recovery(mw);
  367. return rc;
  368. }
  369. static struct ib_send_wr *
  370. __frwr_prepare_linv_wr(struct rpcrdma_mr_seg *seg)
  371. {
  372. struct rpcrdma_mw *mw = seg->rl_mw;
  373. struct rpcrdma_frmr *f = &mw->r.frmr;
  374. struct ib_send_wr *invalidate_wr;
  375. f->fr_waiter = false;
  376. f->fr_state = FRMR_IS_INVALID;
  377. invalidate_wr = &f->fr_invwr;
  378. memset(invalidate_wr, 0, sizeof(*invalidate_wr));
  379. invalidate_wr->wr_id = (unsigned long)(void *)mw;
  380. invalidate_wr->opcode = IB_WR_LOCAL_INV;
  381. invalidate_wr->ex.invalidate_rkey = f->fr_mr->rkey;
  382. return invalidate_wr;
  383. }
  384. static void
  385. __frwr_dma_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
  386. int rc)
  387. {
  388. struct ib_device *device = r_xprt->rx_ia.ri_device;
  389. struct rpcrdma_mw *mw = seg->rl_mw;
  390. struct rpcrdma_frmr *f = &mw->r.frmr;
  391. seg->rl_mw = NULL;
  392. ib_dma_unmap_sg(device, f->sg, f->sg_nents, seg->mr_dir);
  393. if (!rc)
  394. rpcrdma_put_mw(r_xprt, mw);
  395. else
  396. __frwr_queue_recovery(mw);
  397. }
  398. /* Invalidate all memory regions that were registered for "req".
  399. *
  400. * Sleeps until it is safe for the host CPU to access the
  401. * previously mapped memory regions.
  402. */
  403. static void
  404. frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
  405. {
  406. struct ib_send_wr *invalidate_wrs, *pos, *prev, *bad_wr;
  407. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  408. struct rpcrdma_mr_seg *seg;
  409. unsigned int i, nchunks;
  410. struct rpcrdma_frmr *f;
  411. int rc;
  412. dprintk("RPC: %s: req %p\n", __func__, req);
  413. /* ORDER: Invalidate all of the req's MRs first
  414. *
  415. * Chain the LOCAL_INV Work Requests and post them with
  416. * a single ib_post_send() call.
  417. */
  418. invalidate_wrs = pos = prev = NULL;
  419. seg = NULL;
  420. for (i = 0, nchunks = req->rl_nchunks; nchunks; nchunks--) {
  421. seg = &req->rl_segments[i];
  422. pos = __frwr_prepare_linv_wr(seg);
  423. if (!invalidate_wrs)
  424. invalidate_wrs = pos;
  425. else
  426. prev->next = pos;
  427. prev = pos;
  428. i += seg->mr_nsegs;
  429. }
  430. f = &seg->rl_mw->r.frmr;
  431. /* Strong send queue ordering guarantees that when the
  432. * last WR in the chain completes, all WRs in the chain
  433. * are complete.
  434. */
  435. f->fr_invwr.send_flags = IB_SEND_SIGNALED;
  436. f->fr_waiter = true;
  437. init_completion(&f->fr_linv_done);
  438. INIT_CQCOUNT(&r_xprt->rx_ep);
  439. /* Transport disconnect drains the receive CQ before it
  440. * replaces the QP. The RPC reply handler won't call us
  441. * unless ri_id->qp is a valid pointer.
  442. */
  443. rc = ib_post_send(ia->ri_id->qp, invalidate_wrs, &bad_wr);
  444. if (rc)
  445. pr_warn("%s: ib_post_send failed %i\n", __func__, rc);
  446. wait_for_completion(&f->fr_linv_done);
  447. /* ORDER: Now DMA unmap all of the req's MRs, and return
  448. * them to the free MW list.
  449. */
  450. for (i = 0, nchunks = req->rl_nchunks; nchunks; nchunks--) {
  451. seg = &req->rl_segments[i];
  452. __frwr_dma_unmap(r_xprt, seg, rc);
  453. i += seg->mr_nsegs;
  454. seg->mr_nsegs = 0;
  455. }
  456. req->rl_nchunks = 0;
  457. }
  458. /* Post a LOCAL_INV Work Request to prevent further remote access
  459. * via RDMA READ or RDMA WRITE.
  460. */
  461. static int
  462. frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
  463. {
  464. struct rpcrdma_mr_seg *seg1 = seg;
  465. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  466. struct rpcrdma_mw *mw = seg1->rl_mw;
  467. struct rpcrdma_frmr *frmr = &mw->r.frmr;
  468. struct ib_send_wr *invalidate_wr, *bad_wr;
  469. int rc, nsegs = seg->mr_nsegs;
  470. dprintk("RPC: %s: FRMR %p\n", __func__, mw);
  471. seg1->rl_mw = NULL;
  472. frmr->fr_state = FRMR_IS_INVALID;
  473. invalidate_wr = &mw->r.frmr.fr_invwr;
  474. memset(invalidate_wr, 0, sizeof(*invalidate_wr));
  475. invalidate_wr->wr_id = (uintptr_t)mw;
  476. invalidate_wr->opcode = IB_WR_LOCAL_INV;
  477. invalidate_wr->ex.invalidate_rkey = frmr->fr_mr->rkey;
  478. DECR_CQCOUNT(&r_xprt->rx_ep);
  479. ib_dma_unmap_sg(ia->ri_device, frmr->sg, frmr->sg_nents, seg1->mr_dir);
  480. read_lock(&ia->ri_qplock);
  481. rc = ib_post_send(ia->ri_id->qp, invalidate_wr, &bad_wr);
  482. read_unlock(&ia->ri_qplock);
  483. if (rc)
  484. goto out_err;
  485. rpcrdma_put_mw(r_xprt, mw);
  486. return nsegs;
  487. out_err:
  488. dprintk("RPC: %s: ib_post_send status %i\n", __func__, rc);
  489. __frwr_queue_recovery(mw);
  490. return nsegs;
  491. }
  492. static void
  493. frwr_op_destroy(struct rpcrdma_buffer *buf)
  494. {
  495. struct rpcrdma_mw *r;
  496. /* Ensure stale MWs for "buf" are no longer in flight */
  497. flush_workqueue(frwr_recovery_wq);
  498. while (!list_empty(&buf->rb_all)) {
  499. r = list_entry(buf->rb_all.next, struct rpcrdma_mw, mw_all);
  500. list_del(&r->mw_all);
  501. __frwr_release(r);
  502. kfree(r);
  503. }
  504. }
  505. const struct rpcrdma_memreg_ops rpcrdma_frwr_memreg_ops = {
  506. .ro_map = frwr_op_map,
  507. .ro_unmap_sync = frwr_op_unmap_sync,
  508. .ro_unmap = frwr_op_unmap,
  509. .ro_open = frwr_op_open,
  510. .ro_maxpages = frwr_op_maxpages,
  511. .ro_init = frwr_op_init,
  512. .ro_destroy = frwr_op_destroy,
  513. .ro_displayname = "frwr",
  514. };