Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Oracle. All rights reserved. |
| 3 | * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | /* Lightweight memory registration using Fast Memory Regions (FMR). |
| 7 | * Referred to sometimes as MTHCAFMR mode. |
| 8 | * |
| 9 | * FMR uses synchronous memory registration and deregistration. |
| 10 | * FMR registration is known to be fast, but FMR deregistration |
| 11 | * can take tens of usecs to complete. |
| 12 | */ |
| 13 | |
Chuck Lever | fc7fbb5 | 2015-05-26 11:52:16 -0400 | [diff] [blame] | 14 | /* Normal operation |
| 15 | * |
| 16 | * A Memory Region is prepared for RDMA READ or WRITE using the |
| 17 | * ib_map_phys_fmr verb (fmr_op_map). When the RDMA operation is |
| 18 | * finished, the Memory Region is unmapped using the ib_unmap_fmr |
| 19 | * verb (fmr_op_unmap). |
| 20 | */ |
| 21 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 22 | #include "xprt_rdma.h" |
| 23 | |
| 24 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 25 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 26 | #endif |
| 27 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 28 | /* Maximum scatter/gather per FMR */ |
| 29 | #define RPCRDMA_MAX_FMR_SGES (64) |
| 30 | |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 31 | /* Access mode of externally registered pages */ |
| 32 | enum { |
| 33 | RPCRDMA_FMR_ACCESS_FLAGS = IB_ACCESS_REMOTE_WRITE | |
| 34 | IB_ACCESS_REMOTE_READ, |
| 35 | }; |
| 36 | |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 37 | bool |
| 38 | fmr_is_supported(struct rpcrdma_ia *ia) |
| 39 | { |
| 40 | if (!ia->ri_device->alloc_fmr) { |
| 41 | pr_info("rpcrdma: 'fmr' mode is not supported by device %s\n", |
| 42 | ia->ri_device->name); |
| 43 | return false; |
| 44 | } |
| 45 | return true; |
| 46 | } |
| 47 | |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 48 | static int |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 49 | fmr_op_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mw *mw) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 50 | { |
| 51 | static struct ib_fmr_attr fmr_attr = { |
| 52 | .max_pages = RPCRDMA_MAX_FMR_SGES, |
| 53 | .max_maps = 1, |
| 54 | .page_shift = PAGE_SHIFT |
| 55 | }; |
| 56 | |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 57 | mw->fmr.fm_physaddrs = kcalloc(RPCRDMA_MAX_FMR_SGES, |
| 58 | sizeof(u64), GFP_KERNEL); |
| 59 | if (!mw->fmr.fm_physaddrs) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 60 | goto out_free; |
| 61 | |
| 62 | mw->mw_sg = kcalloc(RPCRDMA_MAX_FMR_SGES, |
| 63 | sizeof(*mw->mw_sg), GFP_KERNEL); |
| 64 | if (!mw->mw_sg) |
| 65 | goto out_free; |
| 66 | |
| 67 | sg_init_table(mw->mw_sg, RPCRDMA_MAX_FMR_SGES); |
| 68 | |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 69 | mw->fmr.fm_mr = ib_alloc_fmr(ia->ri_pd, RPCRDMA_FMR_ACCESS_FLAGS, |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 70 | &fmr_attr); |
| 71 | if (IS_ERR(mw->fmr.fm_mr)) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 72 | goto out_fmr_err; |
| 73 | |
| 74 | return 0; |
| 75 | |
| 76 | out_fmr_err: |
| 77 | dprintk("RPC: %s: ib_alloc_fmr returned %ld\n", __func__, |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 78 | PTR_ERR(mw->fmr.fm_mr)); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 79 | |
| 80 | out_free: |
| 81 | kfree(mw->mw_sg); |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 82 | kfree(mw->fmr.fm_physaddrs); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 83 | return -ENOMEM; |
| 84 | } |
| 85 | |
| 86 | static int |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 87 | __fmr_unmap(struct rpcrdma_mw *mw) |
| 88 | { |
| 89 | LIST_HEAD(l); |
Chuck Lever | 38f1932e | 2016-06-29 13:52:12 -0400 | [diff] [blame] | 90 | int rc; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 91 | |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 92 | list_add(&mw->fmr.fm_mr->list, &l); |
Chuck Lever | 38f1932e | 2016-06-29 13:52:12 -0400 | [diff] [blame] | 93 | rc = ib_unmap_fmr(&l); |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 94 | list_del_init(&mw->fmr.fm_mr->list); |
Chuck Lever | 38f1932e | 2016-06-29 13:52:12 -0400 | [diff] [blame] | 95 | return rc; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 98 | static void |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 99 | fmr_op_release_mr(struct rpcrdma_mw *r) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 100 | { |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 101 | LIST_HEAD(unmap_list); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 102 | int rc; |
| 103 | |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 104 | /* Ensure MW is not on any rl_registered list */ |
| 105 | if (!list_empty(&r->mw_list)) |
| 106 | list_del(&r->mw_list); |
| 107 | |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 108 | kfree(r->fmr.fm_physaddrs); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 109 | kfree(r->mw_sg); |
| 110 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 111 | /* In case this one was left mapped, try to unmap it |
| 112 | * to prevent dealloc_fmr from failing with EBUSY |
| 113 | */ |
| 114 | rc = __fmr_unmap(r); |
| 115 | if (rc) |
| 116 | pr_err("rpcrdma: final ib_unmap_fmr for %p failed %i\n", |
| 117 | r, rc); |
| 118 | |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 119 | rc = ib_dealloc_fmr(r->fmr.fm_mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 120 | if (rc) |
| 121 | pr_err("rpcrdma: final ib_dealloc_fmr for %p returned %i\n", |
| 122 | r, rc); |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 123 | |
| 124 | kfree(r); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 127 | /* Reset of a single FMR. |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 128 | */ |
| 129 | static void |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 130 | fmr_op_recover_mr(struct rpcrdma_mw *mw) |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 131 | { |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 132 | struct rpcrdma_xprt *r_xprt = mw->mw_xprt; |
| 133 | int rc; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 134 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 135 | /* ORDER: invalidate first */ |
| 136 | rc = __fmr_unmap(mw); |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 137 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 138 | /* ORDER: then DMA unmap */ |
| 139 | ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, |
| 140 | mw->mw_sg, mw->mw_nents, mw->mw_dir); |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 141 | if (rc) |
| 142 | goto out_release; |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 143 | |
| 144 | rpcrdma_put_mw(r_xprt, mw); |
| 145 | r_xprt->rx_stats.mrs_recovered++; |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 146 | return; |
| 147 | |
| 148 | out_release: |
| 149 | pr_err("rpcrdma: FMR reset failed (%d), %p released\n", rc, mw); |
| 150 | r_xprt->rx_stats.mrs_orphaned++; |
| 151 | |
| 152 | spin_lock(&r_xprt->rx_buf.rb_mwlock); |
| 153 | list_del(&mw->mw_all); |
| 154 | spin_unlock(&r_xprt->rx_buf.rb_mwlock); |
| 155 | |
| 156 | fmr_op_release_mr(mw); |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 159 | static int |
| 160 | fmr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, |
| 161 | struct rpcrdma_create_data_internal *cdata) |
| 162 | { |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 163 | ia->ri_max_segs = max_t(unsigned int, 1, RPCRDMA_MAX_DATA_SEGS / |
| 164 | RPCRDMA_MAX_FMR_SGES); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 168 | /* FMR mode conveys up to 64 pages of payload per chunk segment. |
| 169 | */ |
| 170 | static size_t |
| 171 | fmr_op_maxpages(struct rpcrdma_xprt *r_xprt) |
| 172 | { |
| 173 | return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
Chuck Lever | 9493174 | 2016-05-02 14:40:56 -0400 | [diff] [blame] | 174 | RPCRDMA_MAX_HDR_SEGS * RPCRDMA_MAX_FMR_SGES); |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 177 | /* Use the ib_map_phys_fmr() verb to register a memory region |
| 178 | * for remote access via RDMA READ or RDMA WRITE. |
| 179 | */ |
| 180 | static int |
| 181 | fmr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 182 | int nsegs, bool writing, struct rpcrdma_mw **out) |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 183 | { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 184 | struct rpcrdma_mr_seg *seg1 = seg; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 185 | int len, pageoff, i, rc; |
Chuck Lever | fc7fbb5 | 2015-05-26 11:52:16 -0400 | [diff] [blame] | 186 | struct rpcrdma_mw *mw; |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 187 | u64 *dma_pages; |
Chuck Lever | fc7fbb5 | 2015-05-26 11:52:16 -0400 | [diff] [blame] | 188 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 189 | mw = rpcrdma_get_mw(r_xprt); |
| 190 | if (!mw) |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 191 | return -ENOBUFS; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 192 | |
| 193 | pageoff = offset_in_page(seg1->mr_offset); |
| 194 | seg1->mr_offset -= pageoff; /* start of page */ |
| 195 | seg1->mr_len += pageoff; |
| 196 | len = -pageoff; |
| 197 | if (nsegs > RPCRDMA_MAX_FMR_SGES) |
| 198 | nsegs = RPCRDMA_MAX_FMR_SGES; |
| 199 | for (i = 0; i < nsegs;) { |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 200 | if (seg->mr_page) |
| 201 | sg_set_page(&mw->mw_sg[i], |
| 202 | seg->mr_page, |
| 203 | seg->mr_len, |
| 204 | offset_in_page(seg->mr_offset)); |
| 205 | else |
| 206 | sg_set_buf(&mw->mw_sg[i], seg->mr_offset, |
| 207 | seg->mr_len); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 208 | len += seg->mr_len; |
| 209 | ++seg; |
| 210 | ++i; |
| 211 | /* Check for holes */ |
| 212 | if ((i < nsegs && offset_in_page(seg->mr_offset)) || |
| 213 | offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len)) |
| 214 | break; |
| 215 | } |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 216 | mw->mw_nents = i; |
| 217 | mw->mw_dir = rpcrdma_data_dir(writing); |
Chuck Lever | a54d405 | 2016-06-29 13:53:52 -0400 | [diff] [blame] | 218 | if (i == 0) |
| 219 | goto out_dmamap_err; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 220 | |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 221 | if (!ib_dma_map_sg(r_xprt->rx_ia.ri_device, |
| 222 | mw->mw_sg, mw->mw_nents, mw->mw_dir)) |
| 223 | goto out_dmamap_err; |
| 224 | |
| 225 | for (i = 0, dma_pages = mw->fmr.fm_physaddrs; i < mw->mw_nents; i++) |
| 226 | dma_pages[i] = sg_dma_address(&mw->mw_sg[i]); |
| 227 | rc = ib_map_phys_fmr(mw->fmr.fm_mr, dma_pages, mw->mw_nents, |
| 228 | dma_pages[0]); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 229 | if (rc) |
| 230 | goto out_maperr; |
| 231 | |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 232 | mw->mw_handle = mw->fmr.fm_mr->rkey; |
| 233 | mw->mw_length = len; |
| 234 | mw->mw_offset = dma_pages[0] + pageoff; |
| 235 | |
| 236 | *out = mw; |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 237 | return mw->mw_nents; |
| 238 | |
| 239 | out_dmamap_err: |
| 240 | pr_err("rpcrdma: failed to dma map sg %p sg_nents %u\n", |
| 241 | mw->mw_sg, mw->mw_nents); |
Chuck Lever | 42fe28f | 2016-06-29 13:53:02 -0400 | [diff] [blame] | 242 | rpcrdma_defer_mr_recovery(mw); |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 243 | return -EIO; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 244 | |
| 245 | out_maperr: |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 246 | pr_err("rpcrdma: ib_map_phys_fmr %u@0x%llx+%i (%d) status %i\n", |
| 247 | len, (unsigned long long)dma_pages[0], |
| 248 | pageoff, mw->mw_nents, rc); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 249 | rpcrdma_defer_mr_recovery(mw); |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 250 | return -EIO; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 253 | /* Invalidate all memory regions that were registered for "req". |
| 254 | * |
| 255 | * Sleeps until it is safe for the host CPU to access the |
| 256 | * previously mapped memory regions. |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 257 | * |
| 258 | * Caller ensures that req->rl_registered is not empty. |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 259 | */ |
| 260 | static void |
| 261 | fmr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) |
| 262 | { |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 263 | struct rpcrdma_mw *mw, *tmp; |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 264 | LIST_HEAD(unmap_list); |
| 265 | int rc; |
| 266 | |
| 267 | dprintk("RPC: %s: req %p\n", __func__, req); |
| 268 | |
| 269 | /* ORDER: Invalidate all of the req's MRs first |
| 270 | * |
| 271 | * ib_unmap_fmr() is slow, so use a single call instead |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 272 | * of one call per mapped FMR. |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 273 | */ |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 274 | list_for_each_entry(mw, &req->rl_registered, mw_list) |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 275 | list_add_tail(&mw->fmr.fm_mr->list, &unmap_list); |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 276 | r_xprt->rx_stats.local_inv_needed++; |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 277 | rc = ib_unmap_fmr(&unmap_list); |
| 278 | if (rc) |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 279 | goto out_reset; |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 280 | |
| 281 | /* ORDER: Now DMA unmap all of the req's MRs, and return |
| 282 | * them to the free MW list. |
| 283 | */ |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 284 | list_for_each_entry_safe(mw, tmp, &req->rl_registered, mw_list) { |
| 285 | list_del_init(&mw->mw_list); |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 286 | list_del_init(&mw->fmr.fm_mr->list); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 287 | ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, |
| 288 | mw->mw_sg, mw->mw_nents, mw->mw_dir); |
| 289 | rpcrdma_put_mw(r_xprt, mw); |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 290 | } |
| 291 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 292 | return; |
| 293 | |
| 294 | out_reset: |
| 295 | pr_err("rpcrdma: ib_unmap_fmr failed (%i)\n", rc); |
| 296 | |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 297 | list_for_each_entry_safe(mw, tmp, &req->rl_registered, mw_list) { |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 298 | list_del_init(&mw->fmr.fm_mr->list); |
| 299 | fmr_op_recover_mr(mw); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 300 | } |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 301 | } |
| 302 | |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 303 | /* Use a slow, safe mechanism to invalidate all memory regions |
| 304 | * that were registered for "req". |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 305 | */ |
| 306 | static void |
| 307 | fmr_op_unmap_safe(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req, |
| 308 | bool sync) |
| 309 | { |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 310 | struct rpcrdma_mw *mw; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 311 | |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 312 | while (!list_empty(&req->rl_registered)) { |
Chuck Lever | 9a5c63e | 2017-02-08 17:00:43 -0500 | [diff] [blame] | 313 | mw = rpcrdma_pop_mw(&req->rl_registered); |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 314 | if (sync) |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 315 | fmr_op_recover_mr(mw); |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 316 | else |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 317 | rpcrdma_defer_mr_recovery(mw); |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 321 | const struct rpcrdma_memreg_ops rpcrdma_fmr_memreg_ops = { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 322 | .ro_map = fmr_op_map, |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 323 | .ro_unmap_sync = fmr_op_unmap_sync, |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 324 | .ro_unmap_safe = fmr_op_unmap_safe, |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 325 | .ro_recover_mr = fmr_op_recover_mr, |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 326 | .ro_open = fmr_op_open, |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 327 | .ro_maxpages = fmr_op_maxpages, |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 328 | .ro_init_mr = fmr_op_init_mr, |
| 329 | .ro_release_mr = fmr_op_release_mr, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 330 | .ro_displayname = "fmr", |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 331 | .ro_send_w_inv_ok = 0, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 332 | }; |