Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 2 | /* |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 3 | * Copyright (c) 2015, 2017 Oracle. All rights reserved. |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 4 | * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved. |
| 5 | */ |
| 6 | |
| 7 | /* Lightweight memory registration using Fast Registration Work |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 8 | * Requests (FRWR). |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 9 | * |
Chuck Lever | 2fb2a4d | 2019-08-19 18:37:52 -0400 | [diff] [blame] | 10 | * FRWR features ordered asynchronous registration and invalidation |
| 11 | * of arbitrarily-sized memory regions. This is the fastest and safest |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 12 | * but most complex memory registration mode. |
| 13 | */ |
| 14 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 15 | /* Normal operation |
| 16 | * |
Chuck Lever | 2fb2a4d | 2019-08-19 18:37:52 -0400 | [diff] [blame] | 17 | * A Memory Region is prepared for RDMA Read or Write using a FAST_REG |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 18 | * Work Request (frwr_map). When the RDMA operation is finished, this |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 19 | * Memory Region is invalidated using a LOCAL_INV Work Request |
Chuck Lever | 2fb2a4d | 2019-08-19 18:37:52 -0400 | [diff] [blame] | 20 | * (frwr_unmap_async and frwr_unmap_sync). |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 21 | * |
Chuck Lever | 2fb2a4d | 2019-08-19 18:37:52 -0400 | [diff] [blame] | 22 | * Typically FAST_REG Work Requests are not signaled, and neither are |
| 23 | * RDMA Send Work Requests (with the exception of signaling occasionally |
| 24 | * to prevent provider work queue overflows). This greatly reduces HCA |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 25 | * interrupt workload. |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | /* Transport recovery |
| 29 | * |
Chuck Lever | 2fb2a4d | 2019-08-19 18:37:52 -0400 | [diff] [blame] | 30 | * frwr_map and frwr_unmap_* cannot run at the same time the transport |
| 31 | * connect worker is running. The connect worker holds the transport |
| 32 | * send lock, just as ->send_request does. This prevents frwr_map and |
| 33 | * the connect worker from running concurrently. When a connection is |
| 34 | * closed, the Receive completion queue is drained before the allowing |
| 35 | * the connect worker to get control. This prevents frwr_unmap and the |
| 36 | * connect worker from running concurrently. |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 37 | * |
Chuck Lever | 2fb2a4d | 2019-08-19 18:37:52 -0400 | [diff] [blame] | 38 | * When the underlying transport disconnects, MRs that are in flight |
Chuck Lever | 9d2da4f | 2019-10-09 13:07:48 -0400 | [diff] [blame] | 39 | * are flushed and are likely unusable. Thus all MRs are destroyed. |
| 40 | * New MRs are created on demand. |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 41 | */ |
| 42 | |
Chuck Lever | bd2abef | 2018-05-07 15:27:16 -0400 | [diff] [blame] | 43 | #include <linux/sunrpc/svc_rdma.h> |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 44 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 45 | #include "xprt_rdma.h" |
Chuck Lever | b6e717cb | 2018-05-07 15:27:05 -0400 | [diff] [blame] | 46 | #include <trace/events/rpcrdma.h> |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 47 | |
| 48 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 49 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 50 | #endif |
| 51 | |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 52 | static void frwr_mr_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr *mr) |
Chuck Lever | 61da886 | 2018-10-01 14:25:25 -0400 | [diff] [blame] | 53 | { |
Chuck Lever | 7a03aeb6 | 2020-11-09 14:40:19 -0500 | [diff] [blame] | 54 | if (mr->mr_device) { |
Chuck Lever | d379eaa | 2018-10-01 14:25:30 -0400 | [diff] [blame] | 55 | trace_xprtrdma_mr_unmap(mr); |
Chuck Lever | 7a03aeb6 | 2020-11-09 14:40:19 -0500 | [diff] [blame] | 56 | ib_dma_unmap_sg(mr->mr_device, mr->mr_sg, mr->mr_nents, |
| 57 | mr->mr_dir); |
| 58 | mr->mr_device = NULL; |
Chuck Lever | 61da886 | 2018-10-01 14:25:25 -0400 | [diff] [blame] | 59 | } |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 60 | } |
| 61 | |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 62 | /** |
| 63 | * frwr_mr_release - Destroy one MR |
| 64 | * @mr: MR allocated by frwr_mr_init |
| 65 | * |
| 66 | */ |
| 67 | void frwr_mr_release(struct rpcrdma_mr *mr) |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 68 | { |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 69 | int rc; |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 70 | |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 71 | frwr_mr_unmap(mr->mr_xprt, mr); |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 72 | |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 73 | rc = ib_dereg_mr(mr->frwr.fr_mr); |
| 74 | if (rc) |
| 75 | trace_xprtrdma_frwr_dereg(mr, rc); |
| 76 | kfree(mr->mr_sg); |
| 77 | kfree(mr); |
Chuck Lever | 61da886 | 2018-10-01 14:25:25 -0400 | [diff] [blame] | 78 | } |
| 79 | |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 80 | static void frwr_mr_put(struct rpcrdma_mr *mr) |
| 81 | { |
| 82 | frwr_mr_unmap(mr->mr_xprt, mr); |
| 83 | |
| 84 | /* The MR is returned to the req's MR free list instead |
| 85 | * of to the xprt's MR free list. No spinlock is needed. |
| 86 | */ |
| 87 | rpcrdma_mr_push(mr, &mr->mr_req->rl_free_mrs); |
| 88 | } |
| 89 | |
Chuck Lever | 40088f0 | 2019-06-19 10:33:04 -0400 | [diff] [blame] | 90 | /* frwr_reset - Place MRs back on the free list |
| 91 | * @req: request to reset |
| 92 | * |
| 93 | * Used after a failed marshal. For FRWR, this means the MRs |
| 94 | * don't have to be fully released and recreated. |
| 95 | * |
| 96 | * NB: This is safe only as long as none of @req's MRs are |
| 97 | * involved with an ongoing asynchronous FAST_REG or LOCAL_INV |
| 98 | * Work Request. |
| 99 | */ |
| 100 | void frwr_reset(struct rpcrdma_req *req) |
| 101 | { |
Chuck Lever | 265a38d | 2019-08-19 18:44:04 -0400 | [diff] [blame] | 102 | struct rpcrdma_mr *mr; |
Chuck Lever | 40088f0 | 2019-06-19 10:33:04 -0400 | [diff] [blame] | 103 | |
Chuck Lever | 265a38d | 2019-08-19 18:44:04 -0400 | [diff] [blame] | 104 | while ((mr = rpcrdma_mr_pop(&req->rl_registered))) |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 105 | frwr_mr_put(mr); |
Chuck Lever | 40088f0 | 2019-06-19 10:33:04 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 108 | /** |
Chuck Lever | 253a516 | 2020-02-21 17:00:17 -0500 | [diff] [blame] | 109 | * frwr_mr_init - Initialize one MR |
| 110 | * @r_xprt: controlling transport instance |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 111 | * @mr: generic MR to prepare for FRWR |
| 112 | * |
| 113 | * Returns zero if successful. Otherwise a negative errno |
| 114 | * is returned. |
| 115 | */ |
Chuck Lever | 253a516 | 2020-02-21 17:00:17 -0500 | [diff] [blame] | 116 | int frwr_mr_init(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr *mr) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 117 | { |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 118 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 119 | unsigned int depth = ep->re_max_fr_depth; |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 120 | struct scatterlist *sg; |
| 121 | struct ib_mr *frmr; |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 122 | int rc; |
| 123 | |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 124 | frmr = ib_alloc_mr(ep->re_pd, ep->re_mrtype, depth); |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 125 | if (IS_ERR(frmr)) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 126 | goto out_mr_err; |
| 127 | |
Julia Lawall | ed38c33 | 2020-09-20 13:26:20 +0200 | [diff] [blame] | 128 | sg = kmalloc_array(depth, sizeof(*sg), GFP_NOFS); |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 129 | if (!sg) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 130 | goto out_list_err; |
| 131 | |
Chuck Lever | 253a516 | 2020-02-21 17:00:17 -0500 | [diff] [blame] | 132 | mr->mr_xprt = r_xprt; |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 133 | mr->frwr.fr_mr = frmr; |
Chuck Lever | 7a03aeb6 | 2020-11-09 14:40:19 -0500 | [diff] [blame] | 134 | mr->mr_device = NULL; |
Chuck Lever | 054f155 | 2018-05-01 11:37:14 -0400 | [diff] [blame] | 135 | INIT_LIST_HEAD(&mr->mr_list); |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 136 | init_completion(&mr->frwr.fr_linv_done); |
| 137 | |
| 138 | sg_init_table(sg, depth); |
| 139 | mr->mr_sg = sg; |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 140 | return 0; |
| 141 | |
| 142 | out_mr_err: |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 143 | rc = PTR_ERR(frmr); |
Chuck Lever | 53b2c1c | 2018-12-19 11:00:06 -0500 | [diff] [blame] | 144 | trace_xprtrdma_frwr_alloc(mr, rc); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 145 | return rc; |
| 146 | |
| 147 | out_list_err: |
Chuck Lever | f85adb1 | 2018-12-19 11:00:48 -0500 | [diff] [blame] | 148 | ib_dereg_mr(frmr); |
| 149 | return -ENOMEM; |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 150 | } |
| 151 | |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 152 | /** |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 153 | * frwr_query_device - Prepare a transport for use with FRWR |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 154 | * @ep: endpoint to fill in |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 155 | * @device: RDMA device to query |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 156 | * |
| 157 | * On success, sets: |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 158 | * ep->re_attr |
| 159 | * ep->re_max_requests |
| 160 | * ep->re_max_rdma_segs |
| 161 | * ep->re_max_fr_depth |
| 162 | * ep->re_mrtype |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 163 | * |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 164 | * Return values: |
| 165 | * On success, returns zero. |
| 166 | * %-EINVAL - the device does not support FRWR memory registration |
| 167 | * %-ENOMEM - the device is not sufficiently capable for NFS/RDMA |
Chuck Lever | 914fcad | 2018-05-04 15:34:48 -0400 | [diff] [blame] | 168 | */ |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 169 | int frwr_query_device(struct rpcrdma_ep *ep, const struct ib_device *device) |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 170 | { |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 171 | const struct ib_device_attr *attrs = &device->attrs; |
Chuck Lever | 914fcad | 2018-05-04 15:34:48 -0400 | [diff] [blame] | 172 | int max_qp_wr, depth, delta; |
Chuck Lever | 2e87036 | 2020-01-03 11:56:27 -0500 | [diff] [blame] | 173 | unsigned int max_sge; |
| 174 | |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 175 | if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) || |
| 176 | attrs->max_fast_reg_page_list_len == 0) { |
| 177 | pr_err("rpcrdma: 'frwr' mode is not supported by device %s\n", |
| 178 | device->name); |
| 179 | return -EINVAL; |
| 180 | } |
| 181 | |
Chuck Lever | 2e87036 | 2020-01-03 11:56:27 -0500 | [diff] [blame] | 182 | max_sge = min_t(unsigned int, attrs->max_send_sge, |
| 183 | RPCRDMA_MAX_SEND_SGES); |
| 184 | if (max_sge < RPCRDMA_MIN_SEND_SGES) { |
| 185 | pr_err("rpcrdma: HCA provides only %u send SGEs\n", max_sge); |
| 186 | return -ENOMEM; |
| 187 | } |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 188 | ep->re_attr.cap.max_send_sge = max_sge; |
| 189 | ep->re_attr.cap.max_recv_sge = 1; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 190 | |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 191 | ep->re_mrtype = IB_MR_TYPE_MEM_REG; |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 192 | if (attrs->device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 193 | ep->re_mrtype = IB_MR_TYPE_SG_GAPS; |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 194 | |
Chuck Lever | a788684 | 2018-12-19 10:58:51 -0500 | [diff] [blame] | 195 | /* Quirk: Some devices advertise a large max_fast_reg_page_list_len |
| 196 | * capability, but perform optimally when the MRs are not larger |
| 197 | * than a page. |
| 198 | */ |
Chuck Lever | 18d065a | 2020-01-03 11:56:43 -0500 | [diff] [blame] | 199 | if (attrs->max_sge_rd > RPCRDMA_MAX_HDR_SEGS) |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 200 | ep->re_max_fr_depth = attrs->max_sge_rd; |
Chuck Lever | a788684 | 2018-12-19 10:58:51 -0500 | [diff] [blame] | 201 | else |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 202 | ep->re_max_fr_depth = attrs->max_fast_reg_page_list_len; |
| 203 | if (ep->re_max_fr_depth > RPCRDMA_MAX_DATA_SEGS) |
| 204 | ep->re_max_fr_depth = RPCRDMA_MAX_DATA_SEGS; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 205 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 206 | /* Add room for frwr register and invalidate WRs. |
| 207 | * 1. FRWR reg WR for head |
| 208 | * 2. FRWR invalidate WR for head |
| 209 | * 3. N FRWR reg WRs for pagelist |
| 210 | * 4. N FRWR invalidate WRs for pagelist |
| 211 | * 5. FRWR reg WR for tail |
| 212 | * 6. FRWR invalidate WR for tail |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 213 | * 7. The RDMA_SEND WR |
| 214 | */ |
| 215 | depth = 7; |
| 216 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 217 | /* Calculate N if the device max FRWR depth is smaller than |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 218 | * RPCRDMA_MAX_DATA_SEGS. |
| 219 | */ |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 220 | if (ep->re_max_fr_depth < RPCRDMA_MAX_DATA_SEGS) { |
| 221 | delta = RPCRDMA_MAX_DATA_SEGS - ep->re_max_fr_depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 222 | do { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 223 | depth += 2; /* FRWR reg + invalidate */ |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 224 | delta -= ep->re_max_fr_depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 225 | } while (delta > 0); |
| 226 | } |
| 227 | |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 228 | max_qp_wr = attrs->max_qp_wr; |
Chuck Lever | 914fcad | 2018-05-04 15:34:48 -0400 | [diff] [blame] | 229 | max_qp_wr -= RPCRDMA_BACKWARD_WRS; |
| 230 | max_qp_wr -= 1; |
| 231 | if (max_qp_wr < RPCRDMA_MIN_SLOT_TABLE) |
| 232 | return -ENOMEM; |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 233 | if (ep->re_max_requests > max_qp_wr) |
| 234 | ep->re_max_requests = max_qp_wr; |
| 235 | ep->re_attr.cap.max_send_wr = ep->re_max_requests * depth; |
| 236 | if (ep->re_attr.cap.max_send_wr > max_qp_wr) { |
| 237 | ep->re_max_requests = max_qp_wr / depth; |
| 238 | if (!ep->re_max_requests) |
Chuck Lever | 25868e6 | 2020-01-03 11:56:48 -0500 | [diff] [blame] | 239 | return -ENOMEM; |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 240 | ep->re_attr.cap.max_send_wr = ep->re_max_requests * depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 241 | } |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 242 | ep->re_attr.cap.max_send_wr += RPCRDMA_BACKWARD_WRS; |
| 243 | ep->re_attr.cap.max_send_wr += 1; /* for ib_drain_sq */ |
| 244 | ep->re_attr.cap.max_recv_wr = ep->re_max_requests; |
| 245 | ep->re_attr.cap.max_recv_wr += RPCRDMA_BACKWARD_WRS; |
Chuck Lever | 32e6b68 | 2021-04-19 14:02:03 -0400 | [diff] [blame] | 246 | ep->re_attr.cap.max_recv_wr += RPCRDMA_MAX_RECV_BATCH; |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 247 | ep->re_attr.cap.max_recv_wr += 1; /* for ib_drain_rq */ |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 248 | |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 249 | ep->re_max_rdma_segs = |
| 250 | DIV_ROUND_UP(RPCRDMA_MAX_DATA_SEGS, ep->re_max_fr_depth); |
Chuck Lever | 6946f82 | 2018-12-19 10:58:45 -0500 | [diff] [blame] | 251 | /* Reply chunks require segments for head and tail buffers */ |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 252 | ep->re_max_rdma_segs += 2; |
| 253 | if (ep->re_max_rdma_segs > RPCRDMA_MAX_HDR_SEGS) |
| 254 | ep->re_max_rdma_segs = RPCRDMA_MAX_HDR_SEGS; |
Chuck Lever | 18d065a | 2020-01-03 11:56:43 -0500 | [diff] [blame] | 255 | |
| 256 | /* Ensure the underlying device is capable of conveying the |
| 257 | * largest r/wsize NFS will ask for. This guarantees that |
| 258 | * failing over from one RDMA device to another will not |
| 259 | * break NFS I/O. |
| 260 | */ |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 261 | if ((ep->re_max_rdma_segs * ep->re_max_fr_depth) < RPCRDMA_MAX_SEGS) |
Chuck Lever | 18d065a | 2020-01-03 11:56:43 -0500 | [diff] [blame] | 262 | return -ENOMEM; |
| 263 | |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 267 | /** |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 268 | * frwr_map - Register a memory region |
| 269 | * @r_xprt: controlling transport |
| 270 | * @seg: memory region co-ordinates |
| 271 | * @nsegs: number of segments remaining |
| 272 | * @writing: true when RDMA Write will be used |
Chuck Lever | 0a93fbc | 2018-12-19 10:59:07 -0500 | [diff] [blame] | 273 | * @xid: XID of RPC using the registered memory |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 274 | * @mr: MR to fill in |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 275 | * |
| 276 | * Prepare a REG_MR Work Request to register a memory region |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 277 | * for remote access via RDMA READ or RDMA WRITE. |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 278 | * |
| 279 | * Returns the next segment or a negative errno pointer. |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 280 | * On success, @mr is filled in. |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 281 | */ |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 282 | struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt, |
| 283 | struct rpcrdma_mr_seg *seg, |
Chuck Lever | ec482cc | 2019-02-11 11:23:44 -0500 | [diff] [blame] | 284 | int nsegs, bool writing, __be32 xid, |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 285 | struct rpcrdma_mr *mr) |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 286 | { |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 287 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 288 | struct ib_reg_wr *reg_wr; |
Chuck Lever | ca1c671 | 2020-02-12 11:12:30 -0500 | [diff] [blame] | 289 | int i, n, dma_nents; |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 290 | struct ib_mr *ibmr; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 291 | u8 key; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 292 | |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 293 | if (nsegs > ep->re_max_fr_depth) |
| 294 | nsegs = ep->re_max_fr_depth; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 295 | for (i = 0; i < nsegs;) { |
Chuck Lever | 67b1662 | 2021-02-04 11:59:13 -0500 | [diff] [blame] | 296 | sg_set_page(&mr->mr_sg[i], seg->mr_page, |
| 297 | seg->mr_len, seg->mr_offset); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 298 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 299 | ++seg; |
| 300 | ++i; |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 301 | if (ep->re_mrtype == IB_MR_TYPE_SG_GAPS) |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 302 | continue; |
Chuck Lever | 67b1662 | 2021-02-04 11:59:13 -0500 | [diff] [blame] | 303 | if ((i < nsegs && seg->mr_offset) || |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 304 | offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len)) |
| 305 | break; |
| 306 | } |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 307 | mr->mr_dir = rpcrdma_data_dir(writing); |
Chuck Lever | ca1c671 | 2020-02-12 11:12:30 -0500 | [diff] [blame] | 308 | mr->mr_nents = i; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 309 | |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 310 | dma_nents = ib_dma_map_sg(ep->re_id->device, mr->mr_sg, mr->mr_nents, |
Chuck Lever | ca1c671 | 2020-02-12 11:12:30 -0500 | [diff] [blame] | 311 | mr->mr_dir); |
| 312 | if (!dma_nents) |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 313 | goto out_dmamap_err; |
Chuck Lever | 7a03aeb6 | 2020-11-09 14:40:19 -0500 | [diff] [blame] | 314 | mr->mr_device = ep->re_id->device; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 315 | |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 316 | ibmr = mr->frwr.fr_mr; |
Chuck Lever | ca1c671 | 2020-02-12 11:12:30 -0500 | [diff] [blame] | 317 | n = ib_map_mr_sg(ibmr, mr->mr_sg, dma_nents, NULL, PAGE_SIZE); |
| 318 | if (n != dma_nents) |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 319 | goto out_mapmr_err; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 320 | |
Chuck Lever | 0a93fbc | 2018-12-19 10:59:07 -0500 | [diff] [blame] | 321 | ibmr->iova &= 0x00000000ffffffff; |
Chuck Lever | ec482cc | 2019-02-11 11:23:44 -0500 | [diff] [blame] | 322 | ibmr->iova |= ((u64)be32_to_cpu(xid)) << 32; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 323 | key = (u8)(ibmr->rkey & 0x000000FF); |
| 324 | ib_update_fast_reg_key(ibmr, ++key); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 325 | |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 326 | reg_wr = &mr->frwr.fr_regwr; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 327 | reg_wr->mr = ibmr; |
| 328 | reg_wr->key = ibmr->rkey; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 329 | reg_wr->access = writing ? |
| 330 | IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE : |
| 331 | IB_ACCESS_REMOTE_READ; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 332 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 333 | mr->mr_handle = ibmr->rkey; |
| 334 | mr->mr_length = ibmr->length; |
| 335 | mr->mr_offset = ibmr->iova; |
Chuck Lever | ba217ec | 2018-12-19 10:59:55 -0500 | [diff] [blame] | 336 | trace_xprtrdma_mr_map(mr); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 337 | |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 338 | return seg; |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 339 | |
| 340 | out_dmamap_err: |
Chuck Lever | 53b2c1c | 2018-12-19 11:00:06 -0500 | [diff] [blame] | 341 | trace_xprtrdma_frwr_sgerr(mr, i); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 342 | return ERR_PTR(-EIO); |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 343 | |
| 344 | out_mapmr_err: |
Chuck Lever | 53b2c1c | 2018-12-19 11:00:06 -0500 | [diff] [blame] | 345 | trace_xprtrdma_frwr_maperr(mr, n); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 346 | return ERR_PTR(-EIO); |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 347 | } |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 348 | |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 349 | /** |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 350 | * frwr_wc_fastreg - Invoked by RDMA provider for a flushed FastReg WC |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 351 | * @cq: completion queue |
| 352 | * @wc: WCE for a completed FastReg WR |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 353 | * |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 354 | * Each flushed MR gets destroyed after the QP has drained. |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 355 | */ |
| 356 | static void frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc) |
| 357 | { |
| 358 | struct ib_cqe *cqe = wc->wr_cqe; |
| 359 | struct rpcrdma_frwr *frwr = |
| 360 | container_of(cqe, struct rpcrdma_frwr, fr_cqe); |
| 361 | |
| 362 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 363 | trace_xprtrdma_wc_fastreg(wc, &frwr->fr_cid); |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 364 | |
Chuck Lever | f423f75 | 2020-06-15 09:21:02 -0400 | [diff] [blame] | 365 | rpcrdma_flush_disconnect(cq->cq_context, wc); |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 368 | static void frwr_cid_init(struct rpcrdma_ep *ep, |
| 369 | struct rpcrdma_frwr *frwr) |
| 370 | { |
| 371 | struct rpc_rdma_cid *cid = &frwr->fr_cid; |
| 372 | |
| 373 | cid->ci_queue_id = ep->re_attr.send_cq->res.id; |
| 374 | cid->ci_completion_id = frwr->fr_mr->res.id; |
| 375 | } |
| 376 | |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 377 | /** |
Chuck Lever | 97d0de8 | 2020-02-21 17:00:23 -0500 | [diff] [blame] | 378 | * frwr_send - post Send WRs containing the RPC Call message |
| 379 | * @r_xprt: controlling transport instance |
| 380 | * @req: prepared RPC Call |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 381 | * |
Chuck Lever | e0f86bc | 2018-12-19 11:00:27 -0500 | [diff] [blame] | 382 | * For FRWR, chain any FastReg WRs to the Send WR. Only a |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 383 | * single ib_post_send call is needed to register memory |
| 384 | * and then post the Send WR. |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 385 | * |
Chuck Lever | 97d0de8 | 2020-02-21 17:00:23 -0500 | [diff] [blame] | 386 | * Returns the return code from ib_post_send. |
| 387 | * |
| 388 | * Caller must hold the transport send lock to ensure that the |
| 389 | * pointers to the transport's rdma_cm_id and QP are stable. |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 390 | */ |
Chuck Lever | 97d0de8 | 2020-02-21 17:00:23 -0500 | [diff] [blame] | 391 | int frwr_send(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 392 | { |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 393 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Bart Van Assche | ed288d7 | 2018-07-18 09:25:31 -0700 | [diff] [blame] | 394 | struct ib_send_wr *post_wr; |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 395 | struct rpcrdma_mr *mr; |
| 396 | |
Chuck Lever | dc15c3d | 2019-10-17 14:31:35 -0400 | [diff] [blame] | 397 | post_wr = &req->rl_wr; |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 398 | list_for_each_entry(mr, &req->rl_registered, mr_list) { |
| 399 | struct rpcrdma_frwr *frwr; |
| 400 | |
| 401 | frwr = &mr->frwr; |
| 402 | |
| 403 | frwr->fr_cqe.done = frwr_wc_fastreg; |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 404 | frwr_cid_init(ep, frwr); |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 405 | frwr->fr_regwr.wr.next = post_wr; |
| 406 | frwr->fr_regwr.wr.wr_cqe = &frwr->fr_cqe; |
| 407 | frwr->fr_regwr.wr.num_sge = 0; |
| 408 | frwr->fr_regwr.wr.opcode = IB_WR_REG_MR; |
| 409 | frwr->fr_regwr.wr.send_flags = 0; |
| 410 | |
| 411 | post_wr = &frwr->fr_regwr.wr; |
| 412 | } |
| 413 | |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 414 | return ib_post_send(ep->re_id->qp, post_wr, NULL); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 415 | } |
| 416 | |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 417 | /** |
| 418 | * frwr_reminv - handle a remotely invalidated mr on the @mrs list |
| 419 | * @rep: Received reply |
| 420 | * @mrs: list of MRs to check |
| 421 | * |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 422 | */ |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 423 | void frwr_reminv(struct rpcrdma_rep *rep, struct list_head *mrs) |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 424 | { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 425 | struct rpcrdma_mr *mr; |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 426 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 427 | list_for_each_entry(mr, mrs, mr_list) |
| 428 | if (mr->mr_handle == rep->rr_inv_rkey) { |
Chuck Lever | 054f155 | 2018-05-01 11:37:14 -0400 | [diff] [blame] | 429 | list_del_init(&mr->mr_list); |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 430 | frwr_mr_put(mr); |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 431 | break; /* only one invalidated MR per RPC */ |
| 432 | } |
| 433 | } |
| 434 | |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 435 | static void frwr_mr_done(struct ib_wc *wc, struct rpcrdma_mr *mr) |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 436 | { |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 437 | if (likely(wc->status == IB_WC_SUCCESS)) |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 438 | frwr_mr_put(mr); |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /** |
| 442 | * frwr_wc_localinv - Invoked by RDMA provider for a LOCAL_INV WC |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 443 | * @cq: completion queue |
| 444 | * @wc: WCE for a completed LocalInv WR |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 445 | * |
| 446 | */ |
| 447 | static void frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc) |
| 448 | { |
| 449 | struct ib_cqe *cqe = wc->wr_cqe; |
| 450 | struct rpcrdma_frwr *frwr = |
| 451 | container_of(cqe, struct rpcrdma_frwr, fr_cqe); |
| 452 | struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr); |
| 453 | |
| 454 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 455 | trace_xprtrdma_wc_li(wc, &frwr->fr_cid); |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 456 | frwr_mr_done(wc, mr); |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 457 | |
Chuck Lever | f423f75 | 2020-06-15 09:21:02 -0400 | [diff] [blame] | 458 | rpcrdma_flush_disconnect(cq->cq_context, wc); |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /** |
| 462 | * frwr_wc_localinv_wake - Invoked by RDMA provider for a LOCAL_INV WC |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 463 | * @cq: completion queue |
| 464 | * @wc: WCE for a completed LocalInv WR |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 465 | * |
| 466 | * Awaken anyone waiting for an MR to finish being fenced. |
| 467 | */ |
| 468 | static void frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc) |
| 469 | { |
| 470 | struct ib_cqe *cqe = wc->wr_cqe; |
| 471 | struct rpcrdma_frwr *frwr = |
| 472 | container_of(cqe, struct rpcrdma_frwr, fr_cqe); |
| 473 | struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr); |
| 474 | |
| 475 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 476 | trace_xprtrdma_wc_li_wake(wc, &frwr->fr_cid); |
Chuck Lever | ef2be59 | 2020-11-09 14:40:14 -0500 | [diff] [blame] | 477 | frwr_mr_done(wc, mr); |
Chuck Lever | 6dc6ec9 | 2019-08-19 18:47:10 -0400 | [diff] [blame] | 478 | complete(&frwr->fr_linv_done); |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 479 | |
Chuck Lever | f423f75 | 2020-06-15 09:21:02 -0400 | [diff] [blame] | 480 | rpcrdma_flush_disconnect(cq->cq_context, wc); |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Chuck Lever | 5f62412 | 2018-12-19 10:59:01 -0500 | [diff] [blame] | 483 | /** |
| 484 | * frwr_unmap_sync - invalidate memory regions that were registered for @req |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 485 | * @r_xprt: controlling transport instance |
| 486 | * @req: rpcrdma_req with a non-empty list of MRs to process |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 487 | * |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 488 | * Sleeps until it is safe for the host CPU to access the previously mapped |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 489 | * memory regions. This guarantees that registered MRs are properly fenced |
| 490 | * from the server before the RPC consumer accesses the data in them. It |
| 491 | * also ensures proper Send flow control: waking the next RPC waits until |
| 492 | * this RPC has relinquished all its Send Queue entries. |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 493 | */ |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 494 | void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 495 | { |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 496 | struct ib_send_wr *first, **prev, *last; |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 497 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 498 | const struct ib_send_wr *bad_wr; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 499 | struct rpcrdma_frwr *frwr; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 500 | struct rpcrdma_mr *mr; |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 501 | int rc; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 502 | |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 503 | /* ORDER: Invalidate all of the MRs first |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 504 | * |
| 505 | * Chain the LOCAL_INV Work Requests and post them with |
| 506 | * a single ib_post_send() call. |
| 507 | */ |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 508 | frwr = NULL; |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 509 | prev = &first; |
Chuck Lever | 265a38d | 2019-08-19 18:44:04 -0400 | [diff] [blame] | 510 | while ((mr = rpcrdma_mr_pop(&req->rl_registered))) { |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 511 | |
| 512 | trace_xprtrdma_mr_localinv(mr); |
| 513 | r_xprt->rx_stats.local_inv_needed++; |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 514 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 515 | frwr = &mr->frwr; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 516 | frwr->fr_cqe.done = frwr_wc_localinv; |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 517 | frwr_cid_init(ep, frwr); |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 518 | last = &frwr->fr_invwr; |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 519 | last->next = NULL; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 520 | last->wr_cqe = &frwr->fr_cqe; |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 521 | last->sg_list = NULL; |
| 522 | last->num_sge = 0; |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 523 | last->opcode = IB_WR_LOCAL_INV; |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 524 | last->send_flags = IB_SEND_SIGNALED; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 525 | last->ex.invalidate_rkey = mr->mr_handle; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 526 | |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 527 | *prev = last; |
| 528 | prev = &last->next; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 529 | } |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 530 | |
| 531 | /* Strong send queue ordering guarantees that when the |
| 532 | * last WR in the chain completes, all WRs in the chain |
| 533 | * are complete. |
| 534 | */ |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 535 | frwr->fr_cqe.done = frwr_wc_localinv_wake; |
| 536 | reinit_completion(&frwr->fr_linv_done); |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 537 | |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 538 | /* Transport disconnect drains the receive CQ before it |
| 539 | * replaces the QP. The RPC reply handler won't call us |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 540 | * unless re_id->qp is a valid pointer. |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 541 | */ |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 542 | bad_wr = NULL; |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 543 | rc = ib_post_send(ep->re_id->qp, first, &bad_wr); |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 544 | |
| 545 | /* The final LOCAL_INV WR in the chain is supposed to |
| 546 | * do the wake. If it was never posted, the wake will |
| 547 | * not happen, so don't wait in that case. |
| 548 | */ |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 549 | if (bad_wr != first) |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 550 | wait_for_completion(&frwr->fr_linv_done); |
Chuck Lever | 8475689 | 2019-06-19 10:32:59 -0400 | [diff] [blame] | 551 | if (!rc) |
| 552 | return; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 553 | |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 554 | /* On error, the MRs get destroyed once the QP has drained. */ |
Chuck Lever | 36a55ed | 2020-11-09 14:39:37 -0500 | [diff] [blame] | 555 | trace_xprtrdma_post_linv_err(req, rc); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 556 | } |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * frwr_wc_localinv_done - Invoked by RDMA provider for a signaled LOCAL_INV WC |
Chuck Lever | d6ccebf | 2020-02-21 17:00:49 -0500 | [diff] [blame] | 560 | * @cq: completion queue |
| 561 | * @wc: WCE for a completed LocalInv WR |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 562 | * |
| 563 | */ |
| 564 | static void frwr_wc_localinv_done(struct ib_cq *cq, struct ib_wc *wc) |
| 565 | { |
| 566 | struct ib_cqe *cqe = wc->wr_cqe; |
| 567 | struct rpcrdma_frwr *frwr = |
| 568 | container_of(cqe, struct rpcrdma_frwr, fr_cqe); |
| 569 | struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr); |
Chuck Lever | 44438ad | 2021-04-19 14:03:06 -0400 | [diff] [blame] | 570 | struct rpcrdma_rep *rep; |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 571 | |
| 572 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 573 | trace_xprtrdma_wc_li_done(wc, &frwr->fr_cid); |
Chuck Lever | 6dc6ec9 | 2019-08-19 18:47:10 -0400 | [diff] [blame] | 574 | |
Chuck Lever | 44438ad | 2021-04-19 14:03:06 -0400 | [diff] [blame] | 575 | /* Ensure that @rep is generated before the MR is released */ |
| 576 | rep = mr->mr_req->rl_reply; |
Chuck Lever | 6dc6ec9 | 2019-08-19 18:47:10 -0400 | [diff] [blame] | 577 | smp_rmb(); |
Chuck Lever | 44438ad | 2021-04-19 14:03:06 -0400 | [diff] [blame] | 578 | |
Chuck Lever | 8a05343 | 2021-04-19 14:03:19 -0400 | [diff] [blame^] | 579 | if (wc->status != IB_WC_SUCCESS) { |
| 580 | if (rep) |
| 581 | rpcrdma_unpin_rqst(rep); |
| 582 | rpcrdma_flush_disconnect(cq->cq_context, wc); |
| 583 | return; |
| 584 | } |
| 585 | frwr_mr_put(mr); |
Chuck Lever | 6dc6ec9 | 2019-08-19 18:47:10 -0400 | [diff] [blame] | 586 | rpcrdma_complete_rqst(rep); |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | /** |
| 590 | * frwr_unmap_async - invalidate memory regions that were registered for @req |
| 591 | * @r_xprt: controlling transport instance |
| 592 | * @req: rpcrdma_req with a non-empty list of MRs to process |
| 593 | * |
| 594 | * This guarantees that registered MRs are properly fenced from the |
| 595 | * server before the RPC consumer accesses the data in them. It also |
| 596 | * ensures proper Send flow control: waking the next RPC waits until |
| 597 | * this RPC has relinquished all its Send Queue entries. |
| 598 | */ |
| 599 | void frwr_unmap_async(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) |
| 600 | { |
| 601 | struct ib_send_wr *first, *last, **prev; |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 602 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 603 | struct rpcrdma_frwr *frwr; |
| 604 | struct rpcrdma_mr *mr; |
| 605 | int rc; |
| 606 | |
| 607 | /* Chain the LOCAL_INV Work Requests and post them with |
| 608 | * a single ib_post_send() call. |
| 609 | */ |
| 610 | frwr = NULL; |
| 611 | prev = &first; |
Chuck Lever | 265a38d | 2019-08-19 18:44:04 -0400 | [diff] [blame] | 612 | while ((mr = rpcrdma_mr_pop(&req->rl_registered))) { |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 613 | |
| 614 | trace_xprtrdma_mr_localinv(mr); |
| 615 | r_xprt->rx_stats.local_inv_needed++; |
| 616 | |
| 617 | frwr = &mr->frwr; |
| 618 | frwr->fr_cqe.done = frwr_wc_localinv; |
Chuck Lever | 5ecef9c | 2020-11-09 14:39:31 -0500 | [diff] [blame] | 619 | frwr_cid_init(ep, frwr); |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 620 | last = &frwr->fr_invwr; |
| 621 | last->next = NULL; |
| 622 | last->wr_cqe = &frwr->fr_cqe; |
| 623 | last->sg_list = NULL; |
| 624 | last->num_sge = 0; |
| 625 | last->opcode = IB_WR_LOCAL_INV; |
| 626 | last->send_flags = IB_SEND_SIGNALED; |
| 627 | last->ex.invalidate_rkey = mr->mr_handle; |
| 628 | |
| 629 | *prev = last; |
| 630 | prev = &last->next; |
| 631 | } |
| 632 | |
| 633 | /* Strong send queue ordering guarantees that when the |
| 634 | * last WR in the chain completes, all WRs in the chain |
| 635 | * are complete. The last completion will wake up the |
| 636 | * RPC waiter. |
| 637 | */ |
| 638 | frwr->fr_cqe.done = frwr_wc_localinv_done; |
| 639 | |
| 640 | /* Transport disconnect drains the receive CQ before it |
| 641 | * replaces the QP. The RPC reply handler won't call us |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 642 | * unless re_id->qp is a valid pointer. |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 643 | */ |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 644 | rc = ib_post_send(ep->re_id->qp, first, NULL); |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 645 | if (!rc) |
| 646 | return; |
| 647 | |
Chuck Lever | e4b52ca | 2021-04-19 14:03:12 -0400 | [diff] [blame] | 648 | /* On error, the MRs get destroyed once the QP has drained. */ |
Chuck Lever | 36a55ed | 2020-11-09 14:39:37 -0500 | [diff] [blame] | 649 | trace_xprtrdma_post_linv_err(req, rc); |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 650 | |
| 651 | /* The final LOCAL_INV WR in the chain is supposed to |
Chuck Lever | 8a05343 | 2021-04-19 14:03:19 -0400 | [diff] [blame^] | 652 | * do the wake. If it was never posted, the wake does |
| 653 | * not happen. Unpin the rqst in preparation for its |
| 654 | * retransmission. |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 655 | */ |
Chuck Lever | 8a05343 | 2021-04-19 14:03:19 -0400 | [diff] [blame^] | 656 | rpcrdma_unpin_rqst(req->rl_reply); |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 657 | } |