Chuck Lever | a2268cf | 2018-05-04 15:34:32 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
\"Talpey, Thomas\ | f58851e | 2007-09-10 13:50:12 -0400 | [diff] [blame] | 2 | /* |
Chuck Lever | 3a9568f | 2020-11-09 14:39:42 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, Oracle and/or its affiliates. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 4 | * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved. |
| 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the BSD-type |
| 10 | * license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * |
| 19 | * Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials provided |
| 22 | * with the distribution. |
| 23 | * |
| 24 | * Neither the name of the Network Appliance, Inc. nor the names of |
| 25 | * its contributors may be used to endorse or promote products |
| 26 | * derived from this software without specific prior written |
| 27 | * permission. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 40 | */ |
| 41 | |
| 42 | /* |
| 43 | * rpc_rdma.c |
| 44 | * |
| 45 | * This file contains the guts of the RPC RDMA protocol, and |
| 46 | * does marshaling/unmarshaling, etc. It is also where interfacing |
| 47 | * to the Linux RPC framework lives. |
\"Talpey, Thomas\ | f58851e | 2007-09-10 13:50:12 -0400 | [diff] [blame] | 48 | */ |
| 49 | |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 50 | #include <linux/highmem.h> |
| 51 | |
Chuck Lever | bd2abef | 2018-05-07 15:27:16 -0400 | [diff] [blame] | 52 | #include <linux/sunrpc/svc_rdma.h> |
| 53 | |
Chuck Lever | b6e717cb | 2018-05-07 15:27:05 -0400 | [diff] [blame] | 54 | #include "xprt_rdma.h" |
| 55 | #include <trace/events/rpcrdma.h> |
| 56 | |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 57 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 58 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 59 | #endif |
| 60 | |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 61 | /* Returns size of largest RPC-over-RDMA header in a Call message |
| 62 | * |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 63 | * The largest Call header contains a full-size Read list and a |
| 64 | * minimal Reply chunk. |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 65 | */ |
| 66 | static unsigned int rpcrdma_max_call_header_size(unsigned int maxsegs) |
| 67 | { |
| 68 | unsigned int size; |
| 69 | |
| 70 | /* Fixed header fields and list discriminators */ |
| 71 | size = RPCRDMA_HDRLEN_MIN; |
| 72 | |
| 73 | /* Maximum Read list size */ |
Colin Ian King | 9122884 | 2020-07-15 17:26:04 +0100 | [diff] [blame] | 74 | size += maxsegs * rpcrdma_readchunk_maxsz * sizeof(__be32); |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 75 | |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 76 | /* Minimal Read chunk size */ |
| 77 | size += sizeof(__be32); /* segment count */ |
Chuck Lever | 2232df5 | 2017-10-30 16:21:57 -0400 | [diff] [blame] | 78 | size += rpcrdma_segment_maxsz * sizeof(__be32); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 79 | size += sizeof(__be32); /* list discriminator */ |
| 80 | |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 81 | return size; |
| 82 | } |
| 83 | |
| 84 | /* Returns size of largest RPC-over-RDMA header in a Reply message |
| 85 | * |
| 86 | * There is only one Write list or one Reply chunk per Reply |
| 87 | * message. The larger list is the Write list. |
| 88 | */ |
| 89 | static unsigned int rpcrdma_max_reply_header_size(unsigned int maxsegs) |
| 90 | { |
| 91 | unsigned int size; |
| 92 | |
| 93 | /* Fixed header fields and list discriminators */ |
| 94 | size = RPCRDMA_HDRLEN_MIN; |
| 95 | |
| 96 | /* Maximum Write list size */ |
Colin Ian King | 9122884 | 2020-07-15 17:26:04 +0100 | [diff] [blame] | 97 | size += sizeof(__be32); /* segment count */ |
Chuck Lever | 2232df5 | 2017-10-30 16:21:57 -0400 | [diff] [blame] | 98 | size += maxsegs * rpcrdma_segment_maxsz * sizeof(__be32); |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 99 | size += sizeof(__be32); /* list discriminator */ |
| 100 | |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 101 | return size; |
| 102 | } |
| 103 | |
Chuck Lever | 94087e9 | 2019-04-24 09:40:20 -0400 | [diff] [blame] | 104 | /** |
| 105 | * rpcrdma_set_max_header_sizes - Initialize inline payload sizes |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 106 | * @ep: endpoint to initialize |
Chuck Lever | 94087e9 | 2019-04-24 09:40:20 -0400 | [diff] [blame] | 107 | * |
| 108 | * The max_inline fields contain the maximum size of an RPC message |
| 109 | * so the marshaling code doesn't have to repeat this calculation |
| 110 | * for every RPC. |
| 111 | */ |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 112 | void rpcrdma_set_max_header_sizes(struct rpcrdma_ep *ep) |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 113 | { |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 114 | unsigned int maxsegs = ep->re_max_rdma_segs; |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 115 | |
Chuck Lever | 93aa8e0 | 2020-02-21 17:00:54 -0500 | [diff] [blame] | 116 | ep->re_max_inline_send = |
| 117 | ep->re_inline_send - rpcrdma_max_call_header_size(maxsegs); |
| 118 | ep->re_max_inline_recv = |
| 119 | ep->re_inline_recv - rpcrdma_max_reply_header_size(maxsegs); |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 120 | } |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 121 | |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 122 | /* The client can send a request inline as long as the RPCRDMA header |
| 123 | * plus the RPC call fit under the transport's inline limit. If the |
| 124 | * combined call message size exceeds that limit, the client must use |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 125 | * a Read chunk for this operation. |
| 126 | * |
| 127 | * A Read chunk is also required if sending the RPC call inline would |
| 128 | * exceed this device's max_sge limit. |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 129 | */ |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 130 | static bool rpcrdma_args_inline(struct rpcrdma_xprt *r_xprt, |
| 131 | struct rpc_rqst *rqst) |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 132 | { |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 133 | struct xdr_buf *xdr = &rqst->rq_snd_buf; |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 134 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 135 | unsigned int count, remaining, offset; |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 136 | |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 137 | if (xdr->len > ep->re_max_inline_send) |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 138 | return false; |
| 139 | |
| 140 | if (xdr->page_len) { |
| 141 | remaining = xdr->page_len; |
Chuck Lever | d933cc3 | 2017-06-08 11:53:16 -0400 | [diff] [blame] | 142 | offset = offset_in_page(xdr->page_base); |
Chuck Lever | 1179e2c | 2018-01-31 12:34:05 -0500 | [diff] [blame] | 143 | count = RPCRDMA_MIN_SEND_SGES; |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 144 | while (remaining) { |
| 145 | remaining -= min_t(unsigned int, |
| 146 | PAGE_SIZE - offset, remaining); |
| 147 | offset = 0; |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 148 | if (++count > ep->re_attr.cap.max_send_sge) |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return true; |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* The client can't know how large the actual reply will be. Thus it |
| 157 | * plans for the largest possible reply for that particular ULP |
| 158 | * operation. If the maximum combined reply message size exceeds that |
| 159 | * limit, the client must provide a write list or a reply chunk for |
| 160 | * this request. |
| 161 | */ |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 162 | static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, |
| 163 | struct rpc_rqst *rqst) |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 164 | { |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 165 | return rqst->rq_rcv_buf.buflen <= r_xprt->rx_ep->re_max_inline_recv; |
Chuck Lever | 5457ced | 2015-08-03 13:03:49 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Chuck Lever | d4550bb | 2019-02-11 11:23:49 -0500 | [diff] [blame] | 168 | /* The client is required to provide a Reply chunk if the maximum |
| 169 | * size of the non-payload part of the RPC Reply is larger than |
| 170 | * the inline threshold. |
| 171 | */ |
| 172 | static bool |
| 173 | rpcrdma_nonpayload_inline(const struct rpcrdma_xprt *r_xprt, |
| 174 | const struct rpc_rqst *rqst) |
| 175 | { |
| 176 | const struct xdr_buf *buf = &rqst->rq_rcv_buf; |
Chuck Lever | d4550bb | 2019-02-11 11:23:49 -0500 | [diff] [blame] | 177 | |
Chuck Lever | 94087e9 | 2019-04-24 09:40:20 -0400 | [diff] [blame] | 178 | return (buf->head[0].iov_len + buf->tail[0].iov_len) < |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 179 | r_xprt->rx_ep->re_max_inline_recv; |
Chuck Lever | d4550bb | 2019-02-11 11:23:49 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Chuck Lever | 15261b9 | 2020-12-08 18:29:02 -0500 | [diff] [blame] | 182 | /* ACL likes to be lazy in allocating pages. For TCP, these |
| 183 | * pages can be allocated during receive processing. Not true |
| 184 | * for RDMA, which must always provision receive buffers |
| 185 | * up front. |
| 186 | */ |
| 187 | static noinline int |
| 188 | rpcrdma_alloc_sparse_pages(struct xdr_buf *buf) |
| 189 | { |
| 190 | struct page **ppages; |
| 191 | int len; |
| 192 | |
| 193 | len = buf->page_len; |
| 194 | ppages = buf->pages + (buf->page_base >> PAGE_SHIFT); |
| 195 | while (len > 0) { |
| 196 | if (!*ppages) |
| 197 | *ppages = alloc_page(GFP_NOWAIT | __GFP_NOWARN); |
| 198 | if (!*ppages) |
| 199 | return -ENOBUFS; |
| 200 | ppages++; |
| 201 | len -= PAGE_SIZE; |
| 202 | } |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Chuck Lever | 9929f4a | 2021-02-04 11:59:01 -0500 | [diff] [blame] | 207 | /* Convert @vec to a single SGL element. |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 208 | * |
| 209 | * Returns pointer to next available SGE, and bumps the total number |
| 210 | * of SGEs consumed. |
Chuck Lever | 821c791 | 2016-03-04 11:27:52 -0500 | [diff] [blame] | 211 | */ |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 212 | static struct rpcrdma_mr_seg * |
| 213 | rpcrdma_convert_kvec(struct kvec *vec, struct rpcrdma_mr_seg *seg, |
| 214 | unsigned int *n) |
Chuck Lever | 821c791 | 2016-03-04 11:27:52 -0500 | [diff] [blame] | 215 | { |
Chuck Lever | 54e6aec | 2021-02-04 11:59:07 -0500 | [diff] [blame] | 216 | seg->mr_page = virt_to_page(vec->iov_base); |
Chuck Lever | 67b1662 | 2021-02-04 11:59:13 -0500 | [diff] [blame] | 217 | seg->mr_offset = offset_in_page(vec->iov_base); |
Chuck Lever | 9929f4a | 2021-02-04 11:59:01 -0500 | [diff] [blame] | 218 | seg->mr_len = vec->iov_len; |
| 219 | ++seg; |
| 220 | ++(*n); |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 221 | return seg; |
Chuck Lever | 821c791 | 2016-03-04 11:27:52 -0500 | [diff] [blame] | 222 | } |
| 223 | |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 224 | /* Convert @xdrbuf into SGEs no larger than a page each. As they |
| 225 | * are registered, these SGEs are then coalesced into RDMA segments |
| 226 | * when the selected memreg mode supports it. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 227 | * |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 228 | * Returns positive number of SGEs consumed, or a negative errno. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 229 | */ |
| 230 | |
| 231 | static int |
Chuck Lever | b5f0afb | 2017-02-08 16:59:54 -0500 | [diff] [blame] | 232 | rpcrdma_convert_iovs(struct rpcrdma_xprt *r_xprt, struct xdr_buf *xdrbuf, |
| 233 | unsigned int pos, enum rpcrdma_chunktype type, |
| 234 | struct rpcrdma_mr_seg *seg) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 235 | { |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 236 | unsigned long page_base; |
| 237 | unsigned int len, n; |
Tom Tucker | bd7ea31 | 2011-02-09 19:45:28 +0000 | [diff] [blame] | 238 | struct page **ppages; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 239 | |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 240 | n = 0; |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 241 | if (pos == 0) |
| 242 | seg = rpcrdma_convert_kvec(&xdrbuf->head[0], seg, &n); |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 243 | |
Tom Tucker | bd7ea31 | 2011-02-09 19:45:28 +0000 | [diff] [blame] | 244 | len = xdrbuf->page_len; |
| 245 | ppages = xdrbuf->pages + (xdrbuf->page_base >> PAGE_SHIFT); |
Chuck Lever | d933cc3 | 2017-06-08 11:53:16 -0400 | [diff] [blame] | 246 | page_base = offset_in_page(xdrbuf->page_base); |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 247 | while (len) { |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 248 | seg->mr_page = *ppages; |
Chuck Lever | 67b1662 | 2021-02-04 11:59:13 -0500 | [diff] [blame] | 249 | seg->mr_offset = page_base; |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 250 | seg->mr_len = min_t(u32, PAGE_SIZE - page_base, len); |
| 251 | len -= seg->mr_len; |
| 252 | ++ppages; |
| 253 | ++seg; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 254 | ++n; |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 255 | page_base = 0; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Chuck Lever | 21037b8 | 2021-10-05 10:17:59 -0400 | [diff] [blame] | 258 | if (type == rpcrdma_readch || type == rpcrdma_writech) |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 259 | goto out; |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 260 | |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 261 | if (xdrbuf->tail[0].iov_len) |
Chuck Lever | 9929f4a | 2021-02-04 11:59:01 -0500 | [diff] [blame] | 262 | rpcrdma_convert_kvec(&xdrbuf->tail[0], seg, &n); |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 263 | |
Chuck Lever | 28d9d56 | 2017-08-14 15:38:22 -0400 | [diff] [blame] | 264 | out: |
| 265 | if (unlikely(n > RPCRDMA_MAX_SEGS)) |
| 266 | return -EIO; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 267 | return n; |
| 268 | } |
| 269 | |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 270 | static int |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 271 | encode_rdma_segment(struct xdr_stream *xdr, struct rpcrdma_mr *mr) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 272 | { |
| 273 | __be32 *p; |
| 274 | |
| 275 | p = xdr_reserve_space(xdr, 4 * sizeof(*p)); |
| 276 | if (unlikely(!p)) |
| 277 | return -EMSGSIZE; |
| 278 | |
Chuck Lever | 379c3bc | 2020-04-07 15:32:14 -0400 | [diff] [blame] | 279 | xdr_encode_rdma_segment(p, mr->mr_handle, mr->mr_length, mr->mr_offset); |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 284 | encode_read_segment(struct xdr_stream *xdr, struct rpcrdma_mr *mr, |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 285 | u32 position) |
| 286 | { |
| 287 | __be32 *p; |
| 288 | |
| 289 | p = xdr_reserve_space(xdr, 6 * sizeof(*p)); |
| 290 | if (unlikely(!p)) |
| 291 | return -EMSGSIZE; |
| 292 | |
| 293 | *p++ = xdr_one; /* Item present */ |
Chuck Lever | 379c3bc | 2020-04-07 15:32:14 -0400 | [diff] [blame] | 294 | xdr_encode_read_segment(p, position, mr->mr_handle, mr->mr_length, |
| 295 | mr->mr_offset); |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 296 | return 0; |
| 297 | } |
| 298 | |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 299 | static struct rpcrdma_mr_seg *rpcrdma_mr_prepare(struct rpcrdma_xprt *r_xprt, |
| 300 | struct rpcrdma_req *req, |
| 301 | struct rpcrdma_mr_seg *seg, |
| 302 | int nsegs, bool writing, |
| 303 | struct rpcrdma_mr **mr) |
| 304 | { |
Chuck Lever | 6dc6ec9 | 2019-08-19 18:47:10 -0400 | [diff] [blame] | 305 | *mr = rpcrdma_mr_pop(&req->rl_free_mrs); |
| 306 | if (!*mr) { |
| 307 | *mr = rpcrdma_mr_get(r_xprt); |
| 308 | if (!*mr) |
| 309 | goto out_getmr_err; |
Chuck Lever | 6dc6ec9 | 2019-08-19 18:47:10 -0400 | [diff] [blame] | 310 | (*mr)->mr_req = req; |
| 311 | } |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 312 | |
| 313 | rpcrdma_mr_push(*mr, &req->rl_registered); |
| 314 | return frwr_map(r_xprt, seg, nsegs, writing, req->rl_slot.rq_xid, *mr); |
| 315 | |
| 316 | out_getmr_err: |
Chuck Lever | 0307cde | 2020-11-09 14:39:58 -0500 | [diff] [blame] | 317 | trace_xprtrdma_nomrs_err(r_xprt, req); |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 318 | xprt_wait_for_buffer_space(&r_xprt->rx_xprt); |
Chuck Lever | 9d2da4f | 2019-10-09 13:07:48 -0400 | [diff] [blame] | 319 | rpcrdma_mrs_refresh(r_xprt); |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 320 | return ERR_PTR(-EAGAIN); |
| 321 | } |
| 322 | |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 323 | /* Register and XDR encode the Read list. Supports encoding a list of read |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 324 | * segments that belong to a single read chunk. |
| 325 | * |
| 326 | * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64): |
| 327 | * |
| 328 | * Read chunklist (a linked list): |
| 329 | * N elements, position P (same P for all chunks of same arg!): |
| 330 | * 1 - PHLOO - 1 - PHLOO - ... - 1 - PHLOO - 0 |
| 331 | * |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 332 | * Returns zero on success, or a negative errno if a failure occurred. |
| 333 | * @xdr is advanced to the next position in the stream. |
| 334 | * |
| 335 | * Only a single @pos value is currently supported. |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 336 | */ |
Chuck Lever | 1738de3 | 2019-08-19 18:51:03 -0400 | [diff] [blame] | 337 | static int rpcrdma_encode_read_list(struct rpcrdma_xprt *r_xprt, |
| 338 | struct rpcrdma_req *req, |
| 339 | struct rpc_rqst *rqst, |
| 340 | enum rpcrdma_chunktype rtype) |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 341 | { |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 342 | struct xdr_stream *xdr = &req->rl_stream; |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 343 | struct rpcrdma_mr_seg *seg; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 344 | struct rpcrdma_mr *mr; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 345 | unsigned int pos; |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 346 | int nsegs; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 347 | |
Chuck Lever | 614f3c9 | 2019-10-17 14:31:53 -0400 | [diff] [blame] | 348 | if (rtype == rpcrdma_noch_pullup || rtype == rpcrdma_noch_mapped) |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 349 | goto done; |
| 350 | |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 351 | pos = rqst->rq_snd_buf.head[0].iov_len; |
| 352 | if (rtype == rpcrdma_areadch) |
| 353 | pos = 0; |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 354 | seg = req->rl_segments; |
Chuck Lever | b5f0afb | 2017-02-08 16:59:54 -0500 | [diff] [blame] | 355 | nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_snd_buf, pos, |
| 356 | rtype, seg); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 357 | if (nsegs < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 358 | return nsegs; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 359 | |
| 360 | do { |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 361 | seg = rpcrdma_mr_prepare(r_xprt, req, seg, nsegs, false, &mr); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 362 | if (IS_ERR(seg)) |
Chuck Lever | ed3aa74 | 2018-05-04 15:35:52 -0400 | [diff] [blame] | 363 | return PTR_ERR(seg); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 364 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 365 | if (encode_read_segment(xdr, mr, pos) < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 366 | return -EMSGSIZE; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 367 | |
Chuck Lever | aba11831 | 2018-12-19 10:59:49 -0500 | [diff] [blame] | 368 | trace_xprtrdma_chunk_read(rqst->rq_task, pos, mr, nsegs); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 369 | r_xprt->rx_stats.read_chunk_count++; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 370 | nsegs -= mr->mr_nents; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 371 | } while (nsegs); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 372 | |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 373 | done: |
Chuck Lever | 48a124e | 2020-04-19 20:03:10 -0400 | [diff] [blame] | 374 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 375 | return -EMSGSIZE; |
| 376 | return 0; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 379 | /* Register and XDR encode the Write list. Supports encoding a list |
| 380 | * containing one array of plain segments that belong to a single |
| 381 | * write chunk. |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 382 | * |
| 383 | * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64): |
| 384 | * |
| 385 | * Write chunklist (a list of (one) counted array): |
| 386 | * N elements: |
| 387 | * 1 - N - HLOO - HLOO - ... - HLOO - 0 |
| 388 | * |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 389 | * Returns zero on success, or a negative errno if a failure occurred. |
| 390 | * @xdr is advanced to the next position in the stream. |
| 391 | * |
| 392 | * Only a single Write chunk is currently supported. |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 393 | */ |
Chuck Lever | 1738de3 | 2019-08-19 18:51:03 -0400 | [diff] [blame] | 394 | static int rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt, |
| 395 | struct rpcrdma_req *req, |
| 396 | struct rpc_rqst *rqst, |
| 397 | enum rpcrdma_chunktype wtype) |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 398 | { |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 399 | struct xdr_stream *xdr = &req->rl_stream; |
Chuck Lever | 21037b8 | 2021-10-05 10:17:59 -0400 | [diff] [blame] | 400 | struct rpcrdma_ep *ep = r_xprt->rx_ep; |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 401 | struct rpcrdma_mr_seg *seg; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 402 | struct rpcrdma_mr *mr; |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 403 | int nsegs, nchunks; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 404 | __be32 *segcount; |
| 405 | |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 406 | if (wtype != rpcrdma_writech) |
| 407 | goto done; |
| 408 | |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 409 | seg = req->rl_segments; |
Chuck Lever | b5f0afb | 2017-02-08 16:59:54 -0500 | [diff] [blame] | 410 | nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_rcv_buf, |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 411 | rqst->rq_rcv_buf.head[0].iov_len, |
Chuck Lever | b5f0afb | 2017-02-08 16:59:54 -0500 | [diff] [blame] | 412 | wtype, seg); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 413 | if (nsegs < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 414 | return nsegs; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 415 | |
Chuck Lever | 5c266df | 2020-03-02 15:02:20 -0500 | [diff] [blame] | 416 | if (xdr_stream_encode_item_present(xdr) < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 417 | return -EMSGSIZE; |
| 418 | segcount = xdr_reserve_space(xdr, sizeof(*segcount)); |
| 419 | if (unlikely(!segcount)) |
| 420 | return -EMSGSIZE; |
| 421 | /* Actual value encoded below */ |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 422 | |
| 423 | nchunks = 0; |
| 424 | do { |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 425 | seg = rpcrdma_mr_prepare(r_xprt, req, seg, nsegs, true, &mr); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 426 | if (IS_ERR(seg)) |
Chuck Lever | ed3aa74 | 2018-05-04 15:35:52 -0400 | [diff] [blame] | 427 | return PTR_ERR(seg); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 428 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 429 | if (encode_rdma_segment(xdr, mr) < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 430 | return -EMSGSIZE; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 431 | |
Chuck Lever | aba11831 | 2018-12-19 10:59:49 -0500 | [diff] [blame] | 432 | trace_xprtrdma_chunk_write(rqst->rq_task, mr, nsegs); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 433 | r_xprt->rx_stats.write_chunk_count++; |
Chuck Lever | aae2349 | 2018-01-03 15:38:09 -0500 | [diff] [blame] | 434 | r_xprt->rx_stats.total_rdma_request += mr->mr_length; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 435 | nchunks++; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 436 | nsegs -= mr->mr_nents; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 437 | } while (nsegs); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 438 | |
Chuck Lever | 21037b8 | 2021-10-05 10:17:59 -0400 | [diff] [blame] | 439 | if (xdr_pad_size(rqst->rq_rcv_buf.page_len)) { |
| 440 | if (encode_rdma_segment(xdr, ep->re_write_pad_mr) < 0) |
| 441 | return -EMSGSIZE; |
| 442 | |
| 443 | trace_xprtrdma_chunk_wp(rqst->rq_task, ep->re_write_pad_mr, |
| 444 | nsegs); |
| 445 | r_xprt->rx_stats.write_chunk_count++; |
| 446 | r_xprt->rx_stats.total_rdma_request += mr->mr_length; |
| 447 | nchunks++; |
| 448 | nsegs -= mr->mr_nents; |
| 449 | } |
| 450 | |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 451 | /* Update count of segments in this Write chunk */ |
| 452 | *segcount = cpu_to_be32(nchunks); |
| 453 | |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 454 | done: |
Chuck Lever | 48a124e | 2020-04-19 20:03:10 -0400 | [diff] [blame] | 455 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 456 | return -EMSGSIZE; |
| 457 | return 0; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 460 | /* Register and XDR encode the Reply chunk. Supports encoding an array |
| 461 | * of plain segments that belong to a single write (reply) chunk. |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 462 | * |
| 463 | * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64): |
| 464 | * |
| 465 | * Reply chunk (a counted array): |
| 466 | * N elements: |
| 467 | * 1 - N - HLOO - HLOO - ... - HLOO |
| 468 | * |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 469 | * Returns zero on success, or a negative errno if a failure occurred. |
| 470 | * @xdr is advanced to the next position in the stream. |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 471 | */ |
Chuck Lever | 1738de3 | 2019-08-19 18:51:03 -0400 | [diff] [blame] | 472 | static int rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt, |
| 473 | struct rpcrdma_req *req, |
| 474 | struct rpc_rqst *rqst, |
| 475 | enum rpcrdma_chunktype wtype) |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 476 | { |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 477 | struct xdr_stream *xdr = &req->rl_stream; |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 478 | struct rpcrdma_mr_seg *seg; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 479 | struct rpcrdma_mr *mr; |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 480 | int nsegs, nchunks; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 481 | __be32 *segcount; |
| 482 | |
Chuck Lever | 48a124e | 2020-04-19 20:03:10 -0400 | [diff] [blame] | 483 | if (wtype != rpcrdma_replych) { |
| 484 | if (xdr_stream_encode_item_absent(xdr) < 0) |
| 485 | return -EMSGSIZE; |
| 486 | return 0; |
| 487 | } |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 488 | |
Chuck Lever | 5ab8142 | 2016-06-29 13:54:25 -0400 | [diff] [blame] | 489 | seg = req->rl_segments; |
Chuck Lever | b5f0afb | 2017-02-08 16:59:54 -0500 | [diff] [blame] | 490 | nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_rcv_buf, 0, wtype, seg); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 491 | if (nsegs < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 492 | return nsegs; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 493 | |
Chuck Lever | 5c266df | 2020-03-02 15:02:20 -0500 | [diff] [blame] | 494 | if (xdr_stream_encode_item_present(xdr) < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 495 | return -EMSGSIZE; |
| 496 | segcount = xdr_reserve_space(xdr, sizeof(*segcount)); |
| 497 | if (unlikely(!segcount)) |
| 498 | return -EMSGSIZE; |
| 499 | /* Actual value encoded below */ |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 500 | |
| 501 | nchunks = 0; |
| 502 | do { |
Chuck Lever | 3b39f52 | 2019-08-19 18:45:37 -0400 | [diff] [blame] | 503 | seg = rpcrdma_mr_prepare(r_xprt, req, seg, nsegs, true, &mr); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 504 | if (IS_ERR(seg)) |
Chuck Lever | ed3aa74 | 2018-05-04 15:35:52 -0400 | [diff] [blame] | 505 | return PTR_ERR(seg); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 506 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 507 | if (encode_rdma_segment(xdr, mr) < 0) |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 508 | return -EMSGSIZE; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 509 | |
Chuck Lever | aba11831 | 2018-12-19 10:59:49 -0500 | [diff] [blame] | 510 | trace_xprtrdma_chunk_reply(rqst->rq_task, mr, nsegs); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 511 | r_xprt->rx_stats.reply_chunk_count++; |
Chuck Lever | aae2349 | 2018-01-03 15:38:09 -0500 | [diff] [blame] | 512 | r_xprt->rx_stats.total_rdma_request += mr->mr_length; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 513 | nchunks++; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 514 | nsegs -= mr->mr_nents; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 515 | } while (nsegs); |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 516 | |
| 517 | /* Update count of segments in the Reply chunk */ |
| 518 | *segcount = cpu_to_be32(nchunks); |
| 519 | |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 520 | return 0; |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 521 | } |
| 522 | |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 523 | static void rpcrdma_sendctx_done(struct kref *kref) |
| 524 | { |
| 525 | struct rpcrdma_req *req = |
| 526 | container_of(kref, struct rpcrdma_req, rl_kref); |
| 527 | struct rpcrdma_rep *rep = req->rl_reply; |
| 528 | |
| 529 | rpcrdma_complete_rqst(rep); |
| 530 | rep->rr_rxprt->rx_stats.reply_waits_for_send++; |
| 531 | } |
| 532 | |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 533 | /** |
Chuck Lever | dbcc53a | 2019-04-24 09:39:53 -0400 | [diff] [blame] | 534 | * rpcrdma_sendctx_unmap - DMA-unmap Send buffer |
Chuck Lever | ae72950 | 2017-10-20 10:48:12 -0400 | [diff] [blame] | 535 | * @sc: sendctx containing SGEs to unmap |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 536 | * |
| 537 | */ |
Chuck Lever | dbcc53a | 2019-04-24 09:39:53 -0400 | [diff] [blame] | 538 | void rpcrdma_sendctx_unmap(struct rpcrdma_sendctx *sc) |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 539 | { |
Chuck Lever | b5cde6a | 2019-10-17 14:31:27 -0400 | [diff] [blame] | 540 | struct rpcrdma_regbuf *rb = sc->sc_req->rl_sendbuf; |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 541 | struct ib_sge *sge; |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 542 | |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 543 | if (!sc->sc_unmap_count) |
| 544 | return; |
| 545 | |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 546 | /* The first two SGEs contain the transport header and |
| 547 | * the inline buffer. These are always left mapped so |
| 548 | * they can be cheaply re-used. |
| 549 | */ |
Chuck Lever | dbcc53a | 2019-04-24 09:39:53 -0400 | [diff] [blame] | 550 | for (sge = &sc->sc_sges[2]; sc->sc_unmap_count; |
| 551 | ++sge, --sc->sc_unmap_count) |
Chuck Lever | b5cde6a | 2019-10-17 14:31:27 -0400 | [diff] [blame] | 552 | ib_dma_unmap_page(rdmab_device(rb), sge->addr, sge->length, |
Chuck Lever | dbcc53a | 2019-04-24 09:39:53 -0400 | [diff] [blame] | 553 | DMA_TO_DEVICE); |
Chuck Lever | 01bb35c | 2017-10-20 10:48:36 -0400 | [diff] [blame] | 554 | |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 555 | kref_put(&sc->sc_req->rl_kref, rpcrdma_sendctx_done); |
Chuck Lever | 394b2c7 | 2017-10-20 10:47:47 -0400 | [diff] [blame] | 556 | } |
| 557 | |
Chuck Lever | a062a2a | 2017-10-20 10:48:03 -0400 | [diff] [blame] | 558 | /* Prepare an SGE for the RPC-over-RDMA transport header. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 559 | */ |
Chuck Lever | b78de1d | 2020-01-03 11:56:53 -0500 | [diff] [blame] | 560 | static void rpcrdma_prepare_hdr_sge(struct rpcrdma_xprt *r_xprt, |
Chuck Lever | d2832af | 2019-04-24 09:39:32 -0400 | [diff] [blame] | 561 | struct rpcrdma_req *req, u32 len) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 562 | { |
Chuck Lever | ae72950 | 2017-10-20 10:48:12 -0400 | [diff] [blame] | 563 | struct rpcrdma_sendctx *sc = req->rl_sendctx; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 564 | struct rpcrdma_regbuf *rb = req->rl_rdmabuf; |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 565 | struct ib_sge *sge = &sc->sc_sges[req->rl_wr.num_sge++]; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 566 | |
Chuck Lever | a062a2a | 2017-10-20 10:48:03 -0400 | [diff] [blame] | 567 | sge->addr = rdmab_addr(rb); |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 568 | sge->length = len; |
Chuck Lever | a062a2a | 2017-10-20 10:48:03 -0400 | [diff] [blame] | 569 | sge->lkey = rdmab_lkey(rb); |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 570 | |
Chuck Lever | d2832af | 2019-04-24 09:39:32 -0400 | [diff] [blame] | 571 | ib_dma_sync_single_for_device(rdmab_device(rb), sge->addr, sge->length, |
| 572 | DMA_TO_DEVICE); |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /* The head iovec is straightforward, as it is usually already |
| 576 | * DMA-mapped. Sync the content that has changed. |
| 577 | */ |
| 578 | static bool rpcrdma_prepare_head_iov(struct rpcrdma_xprt *r_xprt, |
| 579 | struct rpcrdma_req *req, unsigned int len) |
| 580 | { |
| 581 | struct rpcrdma_sendctx *sc = req->rl_sendctx; |
| 582 | struct ib_sge *sge = &sc->sc_sges[req->rl_wr.num_sge++]; |
| 583 | struct rpcrdma_regbuf *rb = req->rl_sendbuf; |
| 584 | |
| 585 | if (!rpcrdma_regbuf_dma_map(r_xprt, rb)) |
| 586 | return false; |
| 587 | |
| 588 | sge->addr = rdmab_addr(rb); |
| 589 | sge->length = len; |
| 590 | sge->lkey = rdmab_lkey(rb); |
| 591 | |
| 592 | ib_dma_sync_single_for_device(rdmab_device(rb), sge->addr, sge->length, |
| 593 | DMA_TO_DEVICE); |
| 594 | return true; |
| 595 | } |
| 596 | |
| 597 | /* If there is a page list present, DMA map and prepare an |
| 598 | * SGE for each page to be sent. |
| 599 | */ |
| 600 | static bool rpcrdma_prepare_pagelist(struct rpcrdma_req *req, |
| 601 | struct xdr_buf *xdr) |
| 602 | { |
| 603 | struct rpcrdma_sendctx *sc = req->rl_sendctx; |
| 604 | struct rpcrdma_regbuf *rb = req->rl_sendbuf; |
| 605 | unsigned int page_base, len, remaining; |
| 606 | struct page **ppages; |
| 607 | struct ib_sge *sge; |
| 608 | |
| 609 | ppages = xdr->pages + (xdr->page_base >> PAGE_SHIFT); |
| 610 | page_base = offset_in_page(xdr->page_base); |
| 611 | remaining = xdr->page_len; |
| 612 | while (remaining) { |
| 613 | sge = &sc->sc_sges[req->rl_wr.num_sge++]; |
| 614 | len = min_t(unsigned int, PAGE_SIZE - page_base, remaining); |
| 615 | sge->addr = ib_dma_map_page(rdmab_device(rb), *ppages, |
| 616 | page_base, len, DMA_TO_DEVICE); |
| 617 | if (ib_dma_mapping_error(rdmab_device(rb), sge->addr)) |
| 618 | goto out_mapping_err; |
| 619 | |
| 620 | sge->length = len; |
| 621 | sge->lkey = rdmab_lkey(rb); |
| 622 | |
| 623 | sc->sc_unmap_count++; |
| 624 | ppages++; |
| 625 | remaining -= len; |
| 626 | page_base = 0; |
| 627 | } |
| 628 | |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 629 | return true; |
Chuck Lever | 857f9ac | 2017-10-20 10:47:55 -0400 | [diff] [blame] | 630 | |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 631 | out_mapping_err: |
| 632 | trace_xprtrdma_dma_maperr(sge->addr); |
Chuck Lever | 857f9ac | 2017-10-20 10:47:55 -0400 | [diff] [blame] | 633 | return false; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 634 | } |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 635 | |
Chuck Lever | ae605ee | 2021-05-26 15:35:20 -0400 | [diff] [blame] | 636 | /* The tail iovec may include an XDR pad for the page list, |
| 637 | * as well as additional content, and may not reside in the |
| 638 | * same page as the head iovec. |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 639 | */ |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 640 | static bool rpcrdma_prepare_tail_iov(struct rpcrdma_req *req, |
Chuck Lever | d2832af | 2019-04-24 09:39:32 -0400 | [diff] [blame] | 641 | struct xdr_buf *xdr, |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 642 | unsigned int page_base, unsigned int len) |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 643 | { |
Chuck Lever | ae72950 | 2017-10-20 10:48:12 -0400 | [diff] [blame] | 644 | struct rpcrdma_sendctx *sc = req->rl_sendctx; |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 645 | struct ib_sge *sge = &sc->sc_sges[req->rl_wr.num_sge++]; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 646 | struct rpcrdma_regbuf *rb = req->rl_sendbuf; |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 647 | struct page *page = virt_to_page(xdr->tail[0].iov_base); |
Tom Talpey | b38ab40 | 2009-03-11 14:37:55 -0400 | [diff] [blame] | 648 | |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 649 | sge->addr = ib_dma_map_page(rdmab_device(rb), page, page_base, len, |
| 650 | DMA_TO_DEVICE); |
| 651 | if (ib_dma_mapping_error(rdmab_device(rb), sge->addr)) |
| 652 | goto out_mapping_err; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 653 | |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 654 | sge->length = len; |
| 655 | sge->lkey = rdmab_lkey(rb); |
| 656 | ++sc->sc_unmap_count; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 657 | return true; |
| 658 | |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 659 | out_mapping_err: |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 660 | trace_xprtrdma_dma_maperr(sge->addr); |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 661 | return false; |
| 662 | } |
| 663 | |
Chuck Lever | 614f3c9 | 2019-10-17 14:31:53 -0400 | [diff] [blame] | 664 | /* Copy the tail to the end of the head buffer. |
| 665 | */ |
| 666 | static void rpcrdma_pullup_tail_iov(struct rpcrdma_xprt *r_xprt, |
| 667 | struct rpcrdma_req *req, |
| 668 | struct xdr_buf *xdr) |
| 669 | { |
| 670 | unsigned char *dst; |
| 671 | |
| 672 | dst = (unsigned char *)xdr->head[0].iov_base; |
| 673 | dst += xdr->head[0].iov_len + xdr->page_len; |
| 674 | memmove(dst, xdr->tail[0].iov_base, xdr->tail[0].iov_len); |
| 675 | r_xprt->rx_stats.pullup_copy_count += xdr->tail[0].iov_len; |
| 676 | } |
| 677 | |
| 678 | /* Copy pagelist content into the head buffer. |
| 679 | */ |
| 680 | static void rpcrdma_pullup_pagelist(struct rpcrdma_xprt *r_xprt, |
| 681 | struct rpcrdma_req *req, |
| 682 | struct xdr_buf *xdr) |
| 683 | { |
| 684 | unsigned int len, page_base, remaining; |
| 685 | struct page **ppages; |
| 686 | unsigned char *src, *dst; |
| 687 | |
| 688 | dst = (unsigned char *)xdr->head[0].iov_base; |
| 689 | dst += xdr->head[0].iov_len; |
| 690 | ppages = xdr->pages + (xdr->page_base >> PAGE_SHIFT); |
| 691 | page_base = offset_in_page(xdr->page_base); |
| 692 | remaining = xdr->page_len; |
| 693 | while (remaining) { |
| 694 | src = page_address(*ppages); |
| 695 | src += page_base; |
| 696 | len = min_t(unsigned int, PAGE_SIZE - page_base, remaining); |
| 697 | memcpy(dst, src, len); |
| 698 | r_xprt->rx_stats.pullup_copy_count += len; |
| 699 | |
| 700 | ppages++; |
| 701 | dst += len; |
| 702 | remaining -= len; |
| 703 | page_base = 0; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /* Copy the contents of @xdr into @rl_sendbuf and DMA sync it. |
| 708 | * When the head, pagelist, and tail are small, a pull-up copy |
| 709 | * is considerably less costly than DMA mapping the components |
| 710 | * of @xdr. |
| 711 | * |
| 712 | * Assumptions: |
| 713 | * - the caller has already verified that the total length |
| 714 | * of the RPC Call body will fit into @rl_sendbuf. |
| 715 | */ |
| 716 | static bool rpcrdma_prepare_noch_pullup(struct rpcrdma_xprt *r_xprt, |
| 717 | struct rpcrdma_req *req, |
| 718 | struct xdr_buf *xdr) |
| 719 | { |
| 720 | if (unlikely(xdr->tail[0].iov_len)) |
| 721 | rpcrdma_pullup_tail_iov(r_xprt, req, xdr); |
| 722 | |
| 723 | if (unlikely(xdr->page_len)) |
| 724 | rpcrdma_pullup_pagelist(r_xprt, req, xdr); |
| 725 | |
| 726 | /* The whole RPC message resides in the head iovec now */ |
| 727 | return rpcrdma_prepare_head_iov(r_xprt, req, xdr->len); |
| 728 | } |
| 729 | |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 730 | static bool rpcrdma_prepare_noch_mapped(struct rpcrdma_xprt *r_xprt, |
| 731 | struct rpcrdma_req *req, |
| 732 | struct xdr_buf *xdr) |
| 733 | { |
| 734 | struct kvec *tail = &xdr->tail[0]; |
| 735 | |
| 736 | if (!rpcrdma_prepare_head_iov(r_xprt, req, xdr->head[0].iov_len)) |
| 737 | return false; |
| 738 | if (xdr->page_len) |
| 739 | if (!rpcrdma_prepare_pagelist(req, xdr)) |
| 740 | return false; |
| 741 | if (tail->iov_len) |
| 742 | if (!rpcrdma_prepare_tail_iov(req, xdr, |
| 743 | offset_in_page(tail->iov_base), |
| 744 | tail->iov_len)) |
| 745 | return false; |
| 746 | |
| 747 | if (req->rl_sendctx->sc_unmap_count) |
| 748 | kref_get(&req->rl_kref); |
| 749 | return true; |
| 750 | } |
| 751 | |
| 752 | static bool rpcrdma_prepare_readch(struct rpcrdma_xprt *r_xprt, |
| 753 | struct rpcrdma_req *req, |
| 754 | struct xdr_buf *xdr) |
| 755 | { |
| 756 | if (!rpcrdma_prepare_head_iov(r_xprt, req, xdr->head[0].iov_len)) |
| 757 | return false; |
| 758 | |
Chuck Lever | ae605ee | 2021-05-26 15:35:20 -0400 | [diff] [blame] | 759 | /* If there is a Read chunk, the page list is being handled |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 760 | * via explicit RDMA, and thus is skipped here. |
| 761 | */ |
| 762 | |
Chuck Lever | ae605ee | 2021-05-26 15:35:20 -0400 | [diff] [blame] | 763 | /* Do not include the tail if it is only an XDR pad */ |
| 764 | if (xdr->tail[0].iov_len > 3) { |
| 765 | unsigned int page_base, len; |
| 766 | |
| 767 | /* If the content in the page list is an odd length, |
| 768 | * xdr_write_pages() adds a pad at the beginning of |
| 769 | * the tail iovec. Force the tail's non-pad content to |
| 770 | * land at the next XDR position in the Send message. |
| 771 | */ |
| 772 | page_base = offset_in_page(xdr->tail[0].iov_base); |
| 773 | len = xdr->tail[0].iov_len; |
| 774 | page_base += len & 3; |
| 775 | len -= len & 3; |
| 776 | if (!rpcrdma_prepare_tail_iov(req, xdr, page_base, len)) |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 777 | return false; |
| 778 | kref_get(&req->rl_kref); |
| 779 | } |
| 780 | |
| 781 | return true; |
| 782 | } |
| 783 | |
Chuck Lever | 857f9ac | 2017-10-20 10:47:55 -0400 | [diff] [blame] | 784 | /** |
| 785 | * rpcrdma_prepare_send_sges - Construct SGEs for a Send WR |
| 786 | * @r_xprt: controlling transport |
| 787 | * @req: context of RPC Call being marshalled |
| 788 | * @hdrlen: size of transport header, in bytes |
| 789 | * @xdr: xdr_buf containing RPC Call |
| 790 | * @rtype: chunk type being encoded |
| 791 | * |
| 792 | * Returns 0 on success; otherwise a negative errno is returned. |
| 793 | */ |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 794 | inline int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt, |
| 795 | struct rpcrdma_req *req, u32 hdrlen, |
| 796 | struct xdr_buf *xdr, |
| 797 | enum rpcrdma_chunktype rtype) |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 798 | { |
Chuck Lever | 05eb06d | 2019-06-19 10:32:48 -0400 | [diff] [blame] | 799 | int ret; |
| 800 | |
| 801 | ret = -EAGAIN; |
Chuck Lever | dbcc53a | 2019-04-24 09:39:53 -0400 | [diff] [blame] | 802 | req->rl_sendctx = rpcrdma_sendctx_get_locked(r_xprt); |
Chuck Lever | ae72950 | 2017-10-20 10:48:12 -0400 | [diff] [blame] | 803 | if (!req->rl_sendctx) |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 804 | goto out_nosc; |
Chuck Lever | ae72950 | 2017-10-20 10:48:12 -0400 | [diff] [blame] | 805 | req->rl_sendctx->sc_unmap_count = 0; |
Chuck Lever | 01bb35c | 2017-10-20 10:48:36 -0400 | [diff] [blame] | 806 | req->rl_sendctx->sc_req = req; |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 807 | kref_init(&req->rl_kref); |
Chuck Lever | dc15c3d | 2019-10-17 14:31:35 -0400 | [diff] [blame] | 808 | req->rl_wr.wr_cqe = &req->rl_sendctx->sc_cqe; |
| 809 | req->rl_wr.sg_list = req->rl_sendctx->sc_sges; |
| 810 | req->rl_wr.num_sge = 0; |
| 811 | req->rl_wr.opcode = IB_WR_SEND; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 812 | |
Chuck Lever | b78de1d | 2020-01-03 11:56:53 -0500 | [diff] [blame] | 813 | rpcrdma_prepare_hdr_sge(r_xprt, req, hdrlen); |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 814 | |
Chuck Lever | b78de1d | 2020-01-03 11:56:53 -0500 | [diff] [blame] | 815 | ret = -EIO; |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 816 | switch (rtype) { |
Chuck Lever | 614f3c9 | 2019-10-17 14:31:53 -0400 | [diff] [blame] | 817 | case rpcrdma_noch_pullup: |
| 818 | if (!rpcrdma_prepare_noch_pullup(r_xprt, req, xdr)) |
| 819 | goto out_unmap; |
| 820 | break; |
| 821 | case rpcrdma_noch_mapped: |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 822 | if (!rpcrdma_prepare_noch_mapped(r_xprt, req, xdr)) |
| 823 | goto out_unmap; |
| 824 | break; |
| 825 | case rpcrdma_readch: |
| 826 | if (!rpcrdma_prepare_readch(r_xprt, req, xdr)) |
| 827 | goto out_unmap; |
| 828 | break; |
| 829 | case rpcrdma_areadch: |
| 830 | break; |
| 831 | default: |
| 832 | goto out_unmap; |
| 833 | } |
| 834 | |
Chuck Lever | 857f9ac | 2017-10-20 10:47:55 -0400 | [diff] [blame] | 835 | return 0; |
Chuck Lever | 05eb06d | 2019-06-19 10:32:48 -0400 | [diff] [blame] | 836 | |
Chuck Lever | d6764bb | 2019-10-17 14:31:44 -0400 | [diff] [blame] | 837 | out_unmap: |
| 838 | rpcrdma_sendctx_unmap(req->rl_sendctx); |
| 839 | out_nosc: |
Chuck Lever | 05eb06d | 2019-06-19 10:32:48 -0400 | [diff] [blame] | 840 | trace_xprtrdma_prepsend_failed(&req->rl_slot, ret); |
| 841 | return ret; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 842 | } |
| 843 | |
Chuck Lever | 09e6064 | 2017-08-10 12:47:12 -0400 | [diff] [blame] | 844 | /** |
| 845 | * rpcrdma_marshal_req - Marshal and send one RPC request |
| 846 | * @r_xprt: controlling transport |
| 847 | * @rqst: RPC request to be marshaled |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 848 | * |
Chuck Lever | 09e6064 | 2017-08-10 12:47:12 -0400 | [diff] [blame] | 849 | * For the RPC in "rqst", this function: |
| 850 | * - Chooses the transfer mode (eg., RDMA_MSG or RDMA_NOMSG) |
| 851 | * - Registers Read, Write, and Reply chunks |
| 852 | * - Constructs the transport header |
| 853 | * - Posts a Send WR to send the transport header and request |
| 854 | * |
| 855 | * Returns: |
| 856 | * %0 if the RPC was sent successfully, |
| 857 | * %-ENOTCONN if the connection was lost, |
Chuck Lever | 9e679d5 | 2018-02-28 15:30:44 -0500 | [diff] [blame] | 858 | * %-EAGAIN if the caller should call again with the same arguments, |
| 859 | * %-ENOBUFS if the caller should call again after a delay, |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 860 | * %-EMSGSIZE if the transport header is too small, |
Chuck Lever | 09e6064 | 2017-08-10 12:47:12 -0400 | [diff] [blame] | 861 | * %-EIO if a permanent problem occurred while marshaling. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 862 | */ |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 863 | int |
Chuck Lever | 09e6064 | 2017-08-10 12:47:12 -0400 | [diff] [blame] | 864 | rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 865 | { |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 866 | struct rpcrdma_req *req = rpcr_to_rdmar(rqst); |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 867 | struct xdr_stream *xdr = &req->rl_stream; |
Chuck Lever | e237794 | 2015-03-30 14:33:53 -0400 | [diff] [blame] | 868 | enum rpcrdma_chunktype rtype, wtype; |
Chuck Lever | 614f3c9 | 2019-10-17 14:31:53 -0400 | [diff] [blame] | 869 | struct xdr_buf *buf = &rqst->rq_snd_buf; |
Chuck Lever | 65b8017 | 2016-06-29 13:55:06 -0400 | [diff] [blame] | 870 | bool ddp_allowed; |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 871 | __be32 *p; |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 872 | int ret; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 873 | |
Chuck Lever | 15261b9 | 2020-12-08 18:29:02 -0500 | [diff] [blame] | 874 | if (unlikely(rqst->rq_rcv_buf.flags & XDRBUF_SPARSE_PAGES)) { |
| 875 | ret = rpcrdma_alloc_sparse_pages(&rqst->rq_rcv_buf); |
| 876 | if (ret) |
| 877 | return ret; |
| 878 | } |
| 879 | |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 880 | rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0); |
Chuck Lever | 8cec3db | 2019-04-24 09:39:16 -0400 | [diff] [blame] | 881 | xdr_init_encode(xdr, &req->rl_hdrbuf, rdmab_data(req->rl_rdmabuf), |
| 882 | rqst); |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 883 | |
| 884 | /* Fixed header fields */ |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 885 | ret = -EMSGSIZE; |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 886 | p = xdr_reserve_space(xdr, 4 * sizeof(*p)); |
| 887 | if (!p) |
| 888 | goto out_err; |
| 889 | *p++ = rqst->rq_xid; |
| 890 | *p++ = rpcrdma_version; |
Chuck Lever | 7581d90 | 2020-01-03 11:56:37 -0500 | [diff] [blame] | 891 | *p++ = r_xprt->rx_buf.rb_max_requests; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 892 | |
Chuck Lever | 65b8017 | 2016-06-29 13:55:06 -0400 | [diff] [blame] | 893 | /* When the ULP employs a GSS flavor that guarantees integrity |
| 894 | * or privacy, direct data placement of individual data items |
| 895 | * is not allowed. |
| 896 | */ |
Chuck Lever | 53bc19f | 2020-05-12 17:13:01 -0400 | [diff] [blame] | 897 | ddp_allowed = !test_bit(RPCAUTH_AUTH_DATATOUCH, |
| 898 | &rqst->rq_cred->cr_auth->au_flags); |
Chuck Lever | 65b8017 | 2016-06-29 13:55:06 -0400 | [diff] [blame] | 899 | |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 900 | /* |
| 901 | * Chunks needed for results? |
| 902 | * |
| 903 | * o If the expected result is under the inline threshold, all ops |
Chuck Lever | 33943b2 | 2015-08-03 13:04:08 -0400 | [diff] [blame] | 904 | * return as inline. |
Chuck Lever | cce6dee | 2016-05-02 14:41:14 -0400 | [diff] [blame] | 905 | * o Large read ops return data as write chunk(s), header as |
| 906 | * inline. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 907 | * o Large non-read ops return as a single reply chunk. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 908 | */ |
Chuck Lever | cce6dee | 2016-05-02 14:41:14 -0400 | [diff] [blame] | 909 | if (rpcrdma_results_inline(r_xprt, rqst)) |
Chuck Lever | 02eb57d8 | 2015-08-03 13:03:58 -0400 | [diff] [blame] | 910 | wtype = rpcrdma_noch; |
Chuck Lever | d4550bb | 2019-02-11 11:23:49 -0500 | [diff] [blame] | 911 | else if ((ddp_allowed && rqst->rq_rcv_buf.flags & XDRBUF_READ) && |
| 912 | rpcrdma_nonpayload_inline(r_xprt, rqst)) |
Chuck Lever | cce6dee | 2016-05-02 14:41:14 -0400 | [diff] [blame] | 913 | wtype = rpcrdma_writech; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 914 | else |
Chuck Lever | e237794 | 2015-03-30 14:33:53 -0400 | [diff] [blame] | 915 | wtype = rpcrdma_replych; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 916 | |
| 917 | /* |
| 918 | * Chunks needed for arguments? |
| 919 | * |
| 920 | * o If the total request is under the inline threshold, all ops |
| 921 | * are sent as inline. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 922 | * o Large write ops transmit data as read chunk(s), header as |
| 923 | * inline. |
Chuck Lever | 2fcc213 | 2015-08-03 13:04:26 -0400 | [diff] [blame] | 924 | * o Large non-write ops are sent with the entire message as a |
| 925 | * single read chunk (protocol 0-position special case). |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 926 | * |
Chuck Lever | 2fcc213 | 2015-08-03 13:04:26 -0400 | [diff] [blame] | 927 | * This assumes that the upper layer does not present a request |
| 928 | * that both has a data payload, and whose non-data arguments |
| 929 | * by themselves are larger than the inline threshold. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 930 | */ |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 931 | if (rpcrdma_args_inline(r_xprt, rqst)) { |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 932 | *p++ = rdma_msg; |
Chuck Lever | 614f3c9 | 2019-10-17 14:31:53 -0400 | [diff] [blame] | 933 | rtype = buf->len < rdmab_length(req->rl_sendbuf) ? |
| 934 | rpcrdma_noch_pullup : rpcrdma_noch_mapped; |
| 935 | } else if (ddp_allowed && buf->flags & XDRBUF_WRITE) { |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 936 | *p++ = rdma_msg; |
Chuck Lever | e237794 | 2015-03-30 14:33:53 -0400 | [diff] [blame] | 937 | rtype = rpcrdma_readch; |
Chuck Lever | 2fcc213 | 2015-08-03 13:04:26 -0400 | [diff] [blame] | 938 | } else { |
Chuck Lever | 860477d | 2015-08-03 13:04:45 -0400 | [diff] [blame] | 939 | r_xprt->rx_stats.nomsg_call_count++; |
Chuck Lever | 7a80f3f | 2017-08-10 12:47:28 -0400 | [diff] [blame] | 940 | *p++ = rdma_nomsg; |
Chuck Lever | 2fcc213 | 2015-08-03 13:04:26 -0400 | [diff] [blame] | 941 | rtype = rpcrdma_areadch; |
Chuck Lever | 2fcc213 | 2015-08-03 13:04:26 -0400 | [diff] [blame] | 942 | } |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 943 | |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 944 | /* This implementation supports the following combinations |
| 945 | * of chunk lists in one RPC-over-RDMA Call message: |
| 946 | * |
| 947 | * - Read list |
| 948 | * - Write list |
| 949 | * - Reply chunk |
| 950 | * - Read list + Reply chunk |
| 951 | * |
| 952 | * It might not yet support the following combinations: |
| 953 | * |
| 954 | * - Read list + Write list |
| 955 | * |
| 956 | * It does not support the following combinations: |
| 957 | * |
| 958 | * - Write list + Reply chunk |
| 959 | * - Read list + Write list + Reply chunk |
| 960 | * |
| 961 | * This implementation supports only a single chunk in each |
| 962 | * Read or Write list. Thus for example the client cannot |
| 963 | * send a Call message with a Position Zero Read chunk and a |
| 964 | * regular Read chunk at the same time. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 965 | */ |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 966 | ret = rpcrdma_encode_read_list(r_xprt, req, rqst, rtype); |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 967 | if (ret) |
Chuck Lever | 18c0fb3 | 2017-02-08 17:00:27 -0500 | [diff] [blame] | 968 | goto out_err; |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 969 | ret = rpcrdma_encode_write_list(r_xprt, req, rqst, wtype); |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 970 | if (ret) |
| 971 | goto out_err; |
Chuck Lever | 6a6c6de | 2019-06-19 10:33:31 -0400 | [diff] [blame] | 972 | ret = rpcrdma_encode_reply_chunk(r_xprt, req, rqst, wtype); |
Chuck Lever | 18c0fb3 | 2017-02-08 17:00:27 -0500 | [diff] [blame] | 973 | if (ret) |
Chuck Lever | 94f58c5 | 2016-05-02 14:41:30 -0400 | [diff] [blame] | 974 | goto out_err; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 975 | |
Chuck Lever | 1310051 | 2019-06-19 10:32:43 -0400 | [diff] [blame] | 976 | ret = rpcrdma_prepare_send_sges(r_xprt, req, req->rl_hdrbuf.len, |
Chuck Lever | 614f3c9 | 2019-10-17 14:31:53 -0400 | [diff] [blame] | 977 | buf, rtype); |
Chuck Lever | 857f9ac | 2017-10-20 10:47:55 -0400 | [diff] [blame] | 978 | if (ret) |
Chuck Lever | 18c0fb3 | 2017-02-08 17:00:27 -0500 | [diff] [blame] | 979 | goto out_err; |
Chuck Lever | 1310051 | 2019-06-19 10:32:43 -0400 | [diff] [blame] | 980 | |
| 981 | trace_xprtrdma_marshal(req, rtype, wtype); |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 982 | return 0; |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 983 | |
Chuck Lever | 18c0fb3 | 2017-02-08 17:00:27 -0500 | [diff] [blame] | 984 | out_err: |
Chuck Lever | 17e4c44 | 2019-04-24 09:39:48 -0400 | [diff] [blame] | 985 | trace_xprtrdma_marshal_failed(rqst, ret); |
Chuck Lever | 05eb06d | 2019-06-19 10:32:48 -0400 | [diff] [blame] | 986 | r_xprt->rx_stats.failed_marshal_count++; |
Chuck Lever | 40088f0 | 2019-06-19 10:33:04 -0400 | [diff] [blame] | 987 | frwr_reset(req); |
Chuck Lever | 39f4cd9 | 2017-08-10 12:47:36 -0400 | [diff] [blame] | 988 | return ret; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 989 | } |
| 990 | |
Chuck Lever | eea63ca | 2019-10-09 13:07:32 -0400 | [diff] [blame] | 991 | static void __rpcrdma_update_cwnd_locked(struct rpc_xprt *xprt, |
| 992 | struct rpcrdma_buffer *buf, |
| 993 | u32 grant) |
| 994 | { |
| 995 | buf->rb_credits = grant; |
| 996 | xprt->cwnd = grant << RPC_CWNDSHIFT; |
| 997 | } |
| 998 | |
| 999 | static void rpcrdma_update_cwnd(struct rpcrdma_xprt *r_xprt, u32 grant) |
| 1000 | { |
| 1001 | struct rpc_xprt *xprt = &r_xprt->rx_xprt; |
| 1002 | |
| 1003 | spin_lock(&xprt->transport_lock); |
| 1004 | __rpcrdma_update_cwnd_locked(xprt, &r_xprt->rx_buf, grant); |
| 1005 | spin_unlock(&xprt->transport_lock); |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * rpcrdma_reset_cwnd - Reset the xprt's congestion window |
| 1010 | * @r_xprt: controlling transport instance |
| 1011 | * |
| 1012 | * Prepare @r_xprt for the next connection by reinitializing |
| 1013 | * its credit grant to one (see RFC 8166, Section 3.3.3). |
| 1014 | */ |
| 1015 | void rpcrdma_reset_cwnd(struct rpcrdma_xprt *r_xprt) |
| 1016 | { |
| 1017 | struct rpc_xprt *xprt = &r_xprt->rx_xprt; |
| 1018 | |
| 1019 | spin_lock(&xprt->transport_lock); |
| 1020 | xprt->cong = 0; |
| 1021 | __rpcrdma_update_cwnd_locked(xprt, &r_xprt->rx_buf, 1); |
| 1022 | spin_unlock(&xprt->transport_lock); |
| 1023 | } |
| 1024 | |
Chuck Lever | cb0ae1f | 2016-06-29 13:54:41 -0400 | [diff] [blame] | 1025 | /** |
| 1026 | * rpcrdma_inline_fixup - Scatter inline received data into rqst's iovecs |
| 1027 | * @rqst: controlling RPC request |
| 1028 | * @srcp: points to RPC message payload in receive buffer |
| 1029 | * @copy_len: remaining length of receive buffer content |
| 1030 | * @pad: Write chunk pad bytes needed (zero for pure inline) |
| 1031 | * |
| 1032 | * The upper layer has set the maximum number of bytes it can |
| 1033 | * receive in each component of rq_rcv_buf. These values are set in |
| 1034 | * the head.iov_len, page_len, tail.iov_len, and buflen fields. |
Chuck Lever | cfabe2c | 2016-06-29 13:54:49 -0400 | [diff] [blame] | 1035 | * |
| 1036 | * Unlike the TCP equivalent (xdr_partial_copy_from_skb), in |
| 1037 | * many cases this function simply updates iov_base pointers in |
| 1038 | * rq_rcv_buf to point directly to the received reply data, to |
| 1039 | * avoid copying reply data. |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1040 | * |
| 1041 | * Returns the count of bytes which had to be memcopied. |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1042 | */ |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1043 | static unsigned long |
Tom Talpey | 9191ca3 | 2008-10-09 15:01:11 -0400 | [diff] [blame] | 1044 | rpcrdma_inline_fixup(struct rpc_rqst *rqst, char *srcp, int copy_len, int pad) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1045 | { |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1046 | unsigned long fixup_copy_count; |
| 1047 | int i, npages, curlen; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1048 | char *destp; |
Tom Tucker | bd7ea31 | 2011-02-09 19:45:28 +0000 | [diff] [blame] | 1049 | struct page **ppages; |
| 1050 | int page_base; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1051 | |
Chuck Lever | cb0ae1f | 2016-06-29 13:54:41 -0400 | [diff] [blame] | 1052 | /* The head iovec is redirected to the RPC reply message |
| 1053 | * in the receive buffer, to avoid a memcopy. |
| 1054 | */ |
| 1055 | rqst->rq_rcv_buf.head[0].iov_base = srcp; |
Chuck Lever | cfabe2c | 2016-06-29 13:54:49 -0400 | [diff] [blame] | 1056 | rqst->rq_private_buf.head[0].iov_base = srcp; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1057 | |
Chuck Lever | cb0ae1f | 2016-06-29 13:54:41 -0400 | [diff] [blame] | 1058 | /* The contents of the receive buffer that follow |
| 1059 | * head.iov_len bytes are copied into the page list. |
| 1060 | */ |
| 1061 | curlen = rqst->rq_rcv_buf.head[0].iov_len; |
| 1062 | if (curlen > copy_len) |
| 1063 | curlen = copy_len; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1064 | srcp += curlen; |
| 1065 | copy_len -= curlen; |
| 1066 | |
Chuck Lever | d933cc3 | 2017-06-08 11:53:16 -0400 | [diff] [blame] | 1067 | ppages = rqst->rq_rcv_buf.pages + |
| 1068 | (rqst->rq_rcv_buf.page_base >> PAGE_SHIFT); |
| 1069 | page_base = offset_in_page(rqst->rq_rcv_buf.page_base); |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1070 | fixup_copy_count = 0; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1071 | if (copy_len && rqst->rq_rcv_buf.page_len) { |
Chuck Lever | 80414ab | 2016-06-29 13:54:33 -0400 | [diff] [blame] | 1072 | int pagelist_len; |
| 1073 | |
| 1074 | pagelist_len = rqst->rq_rcv_buf.page_len; |
| 1075 | if (pagelist_len > copy_len) |
| 1076 | pagelist_len = copy_len; |
| 1077 | npages = PAGE_ALIGN(page_base + pagelist_len) >> PAGE_SHIFT; |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1078 | for (i = 0; i < npages; i++) { |
Tom Tucker | bd7ea31 | 2011-02-09 19:45:28 +0000 | [diff] [blame] | 1079 | curlen = PAGE_SIZE - page_base; |
Chuck Lever | 80414ab | 2016-06-29 13:54:33 -0400 | [diff] [blame] | 1080 | if (curlen > pagelist_len) |
| 1081 | curlen = pagelist_len; |
| 1082 | |
Cong Wang | b854178 | 2011-11-25 23:14:40 +0800 | [diff] [blame] | 1083 | destp = kmap_atomic(ppages[i]); |
Tom Tucker | bd7ea31 | 2011-02-09 19:45:28 +0000 | [diff] [blame] | 1084 | memcpy(destp + page_base, srcp, curlen); |
| 1085 | flush_dcache_page(ppages[i]); |
Cong Wang | b854178 | 2011-11-25 23:14:40 +0800 | [diff] [blame] | 1086 | kunmap_atomic(destp); |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1087 | srcp += curlen; |
| 1088 | copy_len -= curlen; |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1089 | fixup_copy_count += curlen; |
Chuck Lever | 80414ab | 2016-06-29 13:54:33 -0400 | [diff] [blame] | 1090 | pagelist_len -= curlen; |
| 1091 | if (!pagelist_len) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1092 | break; |
Tom Tucker | bd7ea31 | 2011-02-09 19:45:28 +0000 | [diff] [blame] | 1093 | page_base = 0; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1094 | } |
Chuck Lever | cb0ae1f | 2016-06-29 13:54:41 -0400 | [diff] [blame] | 1095 | |
| 1096 | /* Implicit padding for the last segment in a Write |
| 1097 | * chunk is inserted inline at the front of the tail |
| 1098 | * iovec. The upper layer ignores the content of |
| 1099 | * the pad. Simply ensure inline content in the tail |
| 1100 | * that follows the Write chunk is properly aligned. |
| 1101 | */ |
| 1102 | if (pad) |
| 1103 | srcp -= pad; |
Chuck Lever | 2b7bbc9 | 2014-03-12 12:51:30 -0400 | [diff] [blame] | 1104 | } |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1105 | |
Chuck Lever | cb0ae1f | 2016-06-29 13:54:41 -0400 | [diff] [blame] | 1106 | /* The tail iovec is redirected to the remaining data |
| 1107 | * in the receive buffer, to avoid a memcopy. |
| 1108 | */ |
Chuck Lever | cfabe2c | 2016-06-29 13:54:49 -0400 | [diff] [blame] | 1109 | if (copy_len || pad) { |
Chuck Lever | cb0ae1f | 2016-06-29 13:54:41 -0400 | [diff] [blame] | 1110 | rqst->rq_rcv_buf.tail[0].iov_base = srcp; |
Chuck Lever | cfabe2c | 2016-06-29 13:54:49 -0400 | [diff] [blame] | 1111 | rqst->rq_private_buf.tail[0].iov_base = srcp; |
| 1112 | } |
Tom Talpey | 9191ca3 | 2008-10-09 15:01:11 -0400 | [diff] [blame] | 1113 | |
Chuck Lever | d4957f0 | 2019-10-23 10:02:03 -0400 | [diff] [blame] | 1114 | if (fixup_copy_count) |
| 1115 | trace_xprtrdma_fixup(rqst, fixup_copy_count); |
Chuck Lever | 64695bde | 2016-06-29 13:54:58 -0400 | [diff] [blame] | 1116 | return fixup_copy_count; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1119 | /* By convention, backchannel calls arrive via rdma_msg type |
| 1120 | * messages, and never populate the chunk lists. This makes |
| 1121 | * the RPC/RDMA header small and fixed in size, so it is |
| 1122 | * straightforward to check the RPC header's direction field. |
| 1123 | */ |
| 1124 | static bool |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1125 | rpcrdma_is_bcall(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep) |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1126 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1127 | { |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1128 | struct xdr_stream *xdr = &rep->rr_stream; |
| 1129 | __be32 *p; |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1130 | |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1131 | if (rep->rr_proc != rdma_msg) |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1132 | return false; |
| 1133 | |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1134 | /* Peek at stream contents without advancing. */ |
| 1135 | p = xdr_inline_decode(xdr, 0); |
| 1136 | |
| 1137 | /* Chunk lists */ |
Chuck Lever | 07e9a63 | 2020-03-28 13:43:22 -0400 | [diff] [blame] | 1138 | if (xdr_item_is_present(p++)) |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1139 | return false; |
Chuck Lever | 07e9a63 | 2020-03-28 13:43:22 -0400 | [diff] [blame] | 1140 | if (xdr_item_is_present(p++)) |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1141 | return false; |
Chuck Lever | 07e9a63 | 2020-03-28 13:43:22 -0400 | [diff] [blame] | 1142 | if (xdr_item_is_present(p++)) |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1143 | return false; |
| 1144 | |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1145 | /* RPC header */ |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1146 | if (*p++ != rep->rr_xid) |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1147 | return false; |
| 1148 | if (*p != cpu_to_be32(RPC_CALL)) |
| 1149 | return false; |
| 1150 | |
| 1151 | /* Now that we are sure this is a backchannel call, |
| 1152 | * advance to the RPC header. |
| 1153 | */ |
| 1154 | p = xdr_inline_decode(xdr, 3 * sizeof(*p)); |
| 1155 | if (unlikely(!p)) |
Chuck Lever | 84dff5e | 2021-02-04 11:59:19 -0500 | [diff] [blame] | 1156 | return true; |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1157 | |
| 1158 | rpcrdma_bc_receive_call(r_xprt, rep); |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1159 | return true; |
| 1160 | } |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1161 | #else /* CONFIG_SUNRPC_BACKCHANNEL */ |
| 1162 | { |
| 1163 | return false; |
Chuck Lever | 63cae47 | 2015-10-24 17:28:08 -0400 | [diff] [blame] | 1164 | } |
| 1165 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
| 1166 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1167 | static int decode_rdma_segment(struct xdr_stream *xdr, u32 *length) |
| 1168 | { |
Chuck Lever | e11b7c9 | 2017-12-20 16:31:04 -0500 | [diff] [blame] | 1169 | u32 handle; |
| 1170 | u64 offset; |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1171 | __be32 *p; |
| 1172 | |
| 1173 | p = xdr_inline_decode(xdr, 4 * sizeof(*p)); |
| 1174 | if (unlikely(!p)) |
| 1175 | return -EIO; |
| 1176 | |
Chuck Lever | f60a086 | 2020-03-29 16:44:13 -0400 | [diff] [blame] | 1177 | xdr_decode_rdma_segment(p, &handle, length, &offset); |
Chuck Lever | e11b7c9 | 2017-12-20 16:31:04 -0500 | [diff] [blame] | 1178 | trace_xprtrdma_decode_seg(handle, *length, offset); |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int decode_write_chunk(struct xdr_stream *xdr, u32 *length) |
| 1183 | { |
| 1184 | u32 segcount, seglength; |
| 1185 | __be32 *p; |
| 1186 | |
| 1187 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 1188 | if (unlikely(!p)) |
| 1189 | return -EIO; |
| 1190 | |
| 1191 | *length = 0; |
| 1192 | segcount = be32_to_cpup(p); |
| 1193 | while (segcount--) { |
| 1194 | if (decode_rdma_segment(xdr, &seglength)) |
| 1195 | return -EIO; |
| 1196 | *length += seglength; |
| 1197 | } |
| 1198 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | /* In RPC-over-RDMA Version One replies, a Read list is never |
| 1203 | * expected. This decoder is a stub that returns an error if |
| 1204 | * a Read list is present. |
| 1205 | */ |
| 1206 | static int decode_read_list(struct xdr_stream *xdr) |
| 1207 | { |
| 1208 | __be32 *p; |
| 1209 | |
| 1210 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 1211 | if (unlikely(!p)) |
| 1212 | return -EIO; |
Chuck Lever | 07e9a63 | 2020-03-28 13:43:22 -0400 | [diff] [blame] | 1213 | if (unlikely(xdr_item_is_present(p))) |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1214 | return -EIO; |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | /* Supports only one Write chunk in the Write list |
| 1219 | */ |
| 1220 | static int decode_write_list(struct xdr_stream *xdr, u32 *length) |
| 1221 | { |
| 1222 | u32 chunklen; |
| 1223 | bool first; |
| 1224 | __be32 *p; |
| 1225 | |
| 1226 | *length = 0; |
| 1227 | first = true; |
| 1228 | do { |
| 1229 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 1230 | if (unlikely(!p)) |
| 1231 | return -EIO; |
Chuck Lever | 07e9a63 | 2020-03-28 13:43:22 -0400 | [diff] [blame] | 1232 | if (xdr_item_is_absent(p)) |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1233 | break; |
| 1234 | if (!first) |
| 1235 | return -EIO; |
| 1236 | |
| 1237 | if (decode_write_chunk(xdr, &chunklen)) |
| 1238 | return -EIO; |
| 1239 | *length += chunklen; |
| 1240 | first = false; |
| 1241 | } while (true); |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
| 1245 | static int decode_reply_chunk(struct xdr_stream *xdr, u32 *length) |
| 1246 | { |
| 1247 | __be32 *p; |
| 1248 | |
| 1249 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 1250 | if (unlikely(!p)) |
| 1251 | return -EIO; |
| 1252 | |
| 1253 | *length = 0; |
Chuck Lever | 07e9a63 | 2020-03-28 13:43:22 -0400 | [diff] [blame] | 1254 | if (xdr_item_is_present(p)) |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1255 | if (decode_write_chunk(xdr, length)) |
| 1256 | return -EIO; |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1260 | static int |
| 1261 | rpcrdma_decode_msg(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep, |
| 1262 | struct rpc_rqst *rqst) |
| 1263 | { |
| 1264 | struct xdr_stream *xdr = &rep->rr_stream; |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1265 | u32 writelist, replychunk, rpclen; |
| 1266 | char *base; |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1267 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1268 | /* Decode the chunk lists */ |
| 1269 | if (decode_read_list(xdr)) |
| 1270 | return -EIO; |
| 1271 | if (decode_write_list(xdr, &writelist)) |
| 1272 | return -EIO; |
| 1273 | if (decode_reply_chunk(xdr, &replychunk)) |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1274 | return -EIO; |
| 1275 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1276 | /* RDMA_MSG sanity checks */ |
| 1277 | if (unlikely(replychunk)) |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1278 | return -EIO; |
| 1279 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1280 | /* Build the RPC reply's Payload stream in rqst->rq_rcv_buf */ |
| 1281 | base = (char *)xdr_inline_decode(xdr, 0); |
| 1282 | rpclen = xdr_stream_remaining(xdr); |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1283 | r_xprt->rx_stats.fixup_copy_count += |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1284 | rpcrdma_inline_fixup(rqst, base, rpclen, writelist & 3); |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1285 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1286 | r_xprt->rx_stats.total_rdma_reply += writelist; |
| 1287 | return rpclen + xdr_align_size(writelist); |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | static noinline int |
| 1291 | rpcrdma_decode_nomsg(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep) |
| 1292 | { |
| 1293 | struct xdr_stream *xdr = &rep->rr_stream; |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1294 | u32 writelist, replychunk; |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1295 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1296 | /* Decode the chunk lists */ |
| 1297 | if (decode_read_list(xdr)) |
| 1298 | return -EIO; |
| 1299 | if (decode_write_list(xdr, &writelist)) |
| 1300 | return -EIO; |
| 1301 | if (decode_reply_chunk(xdr, &replychunk)) |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1302 | return -EIO; |
| 1303 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1304 | /* RDMA_NOMSG sanity checks */ |
| 1305 | if (unlikely(writelist)) |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1306 | return -EIO; |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1307 | if (unlikely(!replychunk)) |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1308 | return -EIO; |
| 1309 | |
Chuck Lever | 264b0cd | 2017-08-03 14:30:27 -0400 | [diff] [blame] | 1310 | /* Reply chunk buffer already is the reply vector */ |
| 1311 | r_xprt->rx_stats.total_rdma_reply += replychunk; |
| 1312 | return replychunk; |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static noinline int |
| 1316 | rpcrdma_decode_error(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep, |
| 1317 | struct rpc_rqst *rqst) |
| 1318 | { |
| 1319 | struct xdr_stream *xdr = &rep->rr_stream; |
| 1320 | __be32 *p; |
| 1321 | |
| 1322 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 1323 | if (unlikely(!p)) |
| 1324 | return -EIO; |
| 1325 | |
| 1326 | switch (*p) { |
| 1327 | case err_vers: |
| 1328 | p = xdr_inline_decode(xdr, 2 * sizeof(*p)); |
| 1329 | if (!p) |
| 1330 | break; |
Chuck Lever | 3821e23 | 2020-11-09 14:39:15 -0500 | [diff] [blame] | 1331 | trace_xprtrdma_err_vers(rqst, p, p + 1); |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1332 | break; |
| 1333 | case err_chunk: |
Chuck Lever | 3821e23 | 2020-11-09 14:39:15 -0500 | [diff] [blame] | 1334 | trace_xprtrdma_err_chunk(rqst); |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1335 | break; |
| 1336 | default: |
Chuck Lever | 3821e23 | 2020-11-09 14:39:15 -0500 | [diff] [blame] | 1337 | trace_xprtrdma_err_unrecognized(rqst, p); |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1338 | } |
| 1339 | |
Chuck Lever | 7b2182e | 2020-06-15 09:21:13 -0400 | [diff] [blame] | 1340 | return -EIO; |
Chuck Lever | 07ff2dd | 2017-08-03 14:30:19 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
Chuck Lever | 8a05343 | 2021-04-19 14:03:19 -0400 | [diff] [blame] | 1343 | /** |
| 1344 | * rpcrdma_unpin_rqst - Release rqst without completing it |
| 1345 | * @rep: RPC/RDMA Receive context |
| 1346 | * |
| 1347 | * This is done when a connection is lost so that a Reply |
| 1348 | * can be dropped and its matching Call can be subsequently |
| 1349 | * retransmitted on a new connection. |
| 1350 | */ |
| 1351 | void rpcrdma_unpin_rqst(struct rpcrdma_rep *rep) |
| 1352 | { |
| 1353 | struct rpc_xprt *xprt = &rep->rr_rxprt->rx_xprt; |
| 1354 | struct rpc_rqst *rqst = rep->rr_rqst; |
| 1355 | struct rpcrdma_req *req = rpcr_to_rdmar(rqst); |
| 1356 | |
| 1357 | req->rl_reply = NULL; |
| 1358 | rep->rr_rqst = NULL; |
| 1359 | |
| 1360 | spin_lock(&xprt->queue_lock); |
| 1361 | xprt_unpin_rqst(rqst); |
| 1362 | spin_unlock(&xprt->queue_lock); |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * rpcrdma_complete_rqst - Pass completed rqst back to RPC |
| 1367 | * @rep: RPC/RDMA Receive context |
| 1368 | * |
| 1369 | * Reconstruct the RPC reply and complete the transaction |
| 1370 | * while @rqst is still pinned to ensure the rep, rqst, and |
| 1371 | * rq_task pointers remain stable. |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1372 | */ |
| 1373 | void rpcrdma_complete_rqst(struct rpcrdma_rep *rep) |
| 1374 | { |
| 1375 | struct rpcrdma_xprt *r_xprt = rep->rr_rxprt; |
| 1376 | struct rpc_xprt *xprt = &r_xprt->rx_xprt; |
| 1377 | struct rpc_rqst *rqst = rep->rr_rqst; |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1378 | int status; |
| 1379 | |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1380 | switch (rep->rr_proc) { |
| 1381 | case rdma_msg: |
| 1382 | status = rpcrdma_decode_msg(r_xprt, rep, rqst); |
| 1383 | break; |
| 1384 | case rdma_nomsg: |
| 1385 | status = rpcrdma_decode_nomsg(r_xprt, rep); |
| 1386 | break; |
| 1387 | case rdma_error: |
| 1388 | status = rpcrdma_decode_error(r_xprt, rep, rqst); |
| 1389 | break; |
| 1390 | default: |
| 1391 | status = -EIO; |
| 1392 | } |
| 1393 | if (status < 0) |
| 1394 | goto out_badheader; |
| 1395 | |
| 1396 | out: |
Trond Myklebust | 75c8415 | 2018-08-31 10:21:00 -0400 | [diff] [blame] | 1397 | spin_lock(&xprt->queue_lock); |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1398 | xprt_complete_rqst(rqst->rq_task, status); |
| 1399 | xprt_unpin_rqst(rqst); |
Trond Myklebust | 75c8415 | 2018-08-31 10:21:00 -0400 | [diff] [blame] | 1400 | spin_unlock(&xprt->queue_lock); |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1401 | return; |
| 1402 | |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1403 | out_badheader: |
Chuck Lever | 3a9568f | 2020-11-09 14:39:42 -0500 | [diff] [blame] | 1404 | trace_xprtrdma_reply_hdr_err(rep); |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1405 | r_xprt->rx_stats.bad_reply_count++; |
Chuck Lever | 7b2182e | 2020-06-15 09:21:13 -0400 | [diff] [blame] | 1406 | rqst->rq_task->tk_status = status; |
| 1407 | status = 0; |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1408 | goto out; |
| 1409 | } |
| 1410 | |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 1411 | static void rpcrdma_reply_done(struct kref *kref) |
Chuck Lever | 0ba6f37 | 2017-10-20 10:48:28 -0400 | [diff] [blame] | 1412 | { |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 1413 | struct rpcrdma_req *req = |
| 1414 | container_of(kref, struct rpcrdma_req, rl_kref); |
Chuck Lever | 01bb35c | 2017-10-20 10:48:36 -0400 | [diff] [blame] | 1415 | |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 1416 | rpcrdma_complete_rqst(req->rl_reply); |
Chuck Lever | 0ba6f37 | 2017-10-20 10:48:28 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 1419 | /** |
| 1420 | * rpcrdma_reply_handler - Process received RPC/RDMA messages |
| 1421 | * @rep: Incoming rpcrdma_rep object to process |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 1422 | * |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1423 | * Errors must result in the RPC task either being awakened, or |
| 1424 | * allowed to timeout, to discover the errors at that time. |
| 1425 | */ |
Chuck Lever | d8f532d | 2017-10-16 15:01:30 -0400 | [diff] [blame] | 1426 | void rpcrdma_reply_handler(struct rpcrdma_rep *rep) |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1427 | { |
Chuck Lever | 431af64 | 2017-06-08 11:52:20 -0400 | [diff] [blame] | 1428 | struct rpcrdma_xprt *r_xprt = rep->rr_rxprt; |
Chuck Lever | 431af64 | 2017-06-08 11:52:20 -0400 | [diff] [blame] | 1429 | struct rpc_xprt *xprt = &r_xprt->rx_xprt; |
Chuck Lever | be798f9 | 2017-10-16 15:01:39 -0400 | [diff] [blame] | 1430 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1431 | struct rpcrdma_req *req; |
| 1432 | struct rpc_rqst *rqst; |
Chuck Lever | be798f9 | 2017-10-16 15:01:39 -0400 | [diff] [blame] | 1433 | u32 credits; |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1434 | __be32 *p; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1435 | |
Chuck Lever | f9e1afe | 2019-08-26 13:12:51 -0400 | [diff] [blame] | 1436 | /* Any data means we had a useful conversation, so |
| 1437 | * then we don't need to delay the next reconnect. |
| 1438 | */ |
| 1439 | if (xprt->reestablish_timeout) |
| 1440 | xprt->reestablish_timeout = 0; |
| 1441 | |
Chuck Lever | 7c8d9e7 | 2018-05-04 15:35:20 -0400 | [diff] [blame] | 1442 | /* Fixed transport header fields */ |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1443 | xdr_init_decode(&rep->rr_stream, &rep->rr_hdrbuf, |
Chuck Lever | 0ccc61b | 2019-02-11 11:24:05 -0500 | [diff] [blame] | 1444 | rep->rr_hdrbuf.head[0].iov_base, NULL); |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1445 | p = xdr_inline_decode(&rep->rr_stream, 4 * sizeof(*p)); |
Chuck Lever | 96f8778 | 2017-08-03 14:30:03 -0400 | [diff] [blame] | 1446 | if (unlikely(!p)) |
Chuck Lever | b0e178a | 2015-10-24 17:26:54 -0400 | [diff] [blame] | 1447 | goto out_shortreply; |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1448 | rep->rr_xid = *p++; |
| 1449 | rep->rr_vers = *p++; |
Chuck Lever | be798f9 | 2017-10-16 15:01:39 -0400 | [diff] [blame] | 1450 | credits = be32_to_cpu(*p++); |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1451 | rep->rr_proc = *p++; |
Chuck Lever | b0e178a | 2015-10-24 17:26:54 -0400 | [diff] [blame] | 1452 | |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1453 | if (rep->rr_vers != rpcrdma_version) |
Chuck Lever | 61433af | 2017-10-16 15:01:06 -0400 | [diff] [blame] | 1454 | goto out_badversion; |
| 1455 | |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1456 | if (rpcrdma_is_bcall(r_xprt, rep)) |
Chuck Lever | 41c8f70 | 2017-08-03 14:30:11 -0400 | [diff] [blame] | 1457 | return; |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1458 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 1459 | /* Match incoming rpcrdma_rep to an rpcrdma_req to |
| 1460 | * get context for handling any incoming chunks. |
| 1461 | */ |
Trond Myklebust | 75c8415 | 2018-08-31 10:21:00 -0400 | [diff] [blame] | 1462 | spin_lock(&xprt->queue_lock); |
Chuck Lever | 5381e0e | 2017-10-16 15:01:14 -0400 | [diff] [blame] | 1463 | rqst = xprt_lookup_rqst(xprt, rep->rr_xid); |
Chuck Lever | 9590d08 | 2017-08-23 17:05:58 -0400 | [diff] [blame] | 1464 | if (!rqst) |
| 1465 | goto out_norqst; |
| 1466 | xprt_pin_rqst(rqst); |
Trond Myklebust | 93bdcf9 | 2018-10-18 17:29:00 -0400 | [diff] [blame] | 1467 | spin_unlock(&xprt->queue_lock); |
Chuck Lever | be798f9 | 2017-10-16 15:01:39 -0400 | [diff] [blame] | 1468 | |
| 1469 | if (credits == 0) |
| 1470 | credits = 1; /* don't deadlock */ |
Chuck Lever | e28ce90 | 2020-02-21 17:01:05 -0500 | [diff] [blame] | 1471 | else if (credits > r_xprt->rx_ep->re_max_requests) |
| 1472 | credits = r_xprt->rx_ep->re_max_requests; |
Chuck Lever | 35d8b10 | 2021-04-19 14:02:41 -0400 | [diff] [blame] | 1473 | rpcrdma_post_recvs(r_xprt, credits + (buf->rb_bc_srv_max_requests << 1), |
| 1474 | false); |
Chuck Lever | eea63ca | 2019-10-09 13:07:32 -0400 | [diff] [blame] | 1475 | if (buf->rb_credits != credits) |
| 1476 | rpcrdma_update_cwnd(r_xprt, credits); |
Chuck Lever | be798f9 | 2017-10-16 15:01:39 -0400 | [diff] [blame] | 1477 | |
Chuck Lever | 9590d08 | 2017-08-23 17:05:58 -0400 | [diff] [blame] | 1478 | req = rpcr_to_rdmar(rqst); |
Chuck Lever | 03ffd92 | 2020-11-09 14:39:47 -0500 | [diff] [blame] | 1479 | if (unlikely(req->rl_reply)) |
Chuck Lever | c35ca60 | 2021-04-19 14:02:47 -0400 | [diff] [blame] | 1480 | rpcrdma_rep_put(buf, req->rl_reply); |
Chuck Lever | 4b196dc6 | 2017-06-08 11:51:56 -0400 | [diff] [blame] | 1481 | req->rl_reply = rep; |
Chuck Lever | e1352c9 | 2017-10-16 15:01:22 -0400 | [diff] [blame] | 1482 | rep->rr_rqst = rqst; |
Chuck Lever | 431af64 | 2017-06-08 11:52:20 -0400 | [diff] [blame] | 1483 | |
Chuck Lever | 03ffd92 | 2020-11-09 14:39:47 -0500 | [diff] [blame] | 1484 | trace_xprtrdma_reply(rqst->rq_task, rep, credits); |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 1485 | |
| 1486 | if (rep->rr_wc_flags & IB_WC_WITH_INVALIDATE) |
| 1487 | frwr_reminv(rep, &req->rl_registered); |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 1488 | if (!list_empty(&req->rl_registered)) |
Chuck Lever | d8099fe | 2019-06-19 10:33:10 -0400 | [diff] [blame] | 1489 | frwr_unmap_async(r_xprt, req); |
| 1490 | /* LocalInv completion will complete the RPC */ |
Chuck Lever | 0ab1152 | 2019-06-19 10:33:15 -0400 | [diff] [blame] | 1491 | else |
| 1492 | kref_put(&req->rl_kref, rpcrdma_reply_done); |
Chuck Lever | b0e178a | 2015-10-24 17:26:54 -0400 | [diff] [blame] | 1493 | return; |
| 1494 | |
Chuck Lever | 61433af | 2017-10-16 15:01:06 -0400 | [diff] [blame] | 1495 | out_badversion: |
Chuck Lever | 3a9568f | 2020-11-09 14:39:42 -0500 | [diff] [blame] | 1496 | trace_xprtrdma_reply_vers_err(rep); |
Chuck Lever | 6ceea36 | 2018-12-19 10:58:24 -0500 | [diff] [blame] | 1497 | goto out; |
Chuck Lever | 61433af | 2017-10-16 15:01:06 -0400 | [diff] [blame] | 1498 | |
Chuck Lever | 431af64 | 2017-06-08 11:52:20 -0400 | [diff] [blame] | 1499 | out_norqst: |
Trond Myklebust | 75c8415 | 2018-08-31 10:21:00 -0400 | [diff] [blame] | 1500 | spin_unlock(&xprt->queue_lock); |
Chuck Lever | 3a9568f | 2020-11-09 14:39:42 -0500 | [diff] [blame] | 1501 | trace_xprtrdma_reply_rqst_err(rep); |
Chuck Lever | 6ceea36 | 2018-12-19 10:58:24 -0500 | [diff] [blame] | 1502 | goto out; |
Chuck Lever | b0e178a | 2015-10-24 17:26:54 -0400 | [diff] [blame] | 1503 | |
Chuck Lever | 9590d08 | 2017-08-23 17:05:58 -0400 | [diff] [blame] | 1504 | out_shortreply: |
Chuck Lever | 3a9568f | 2020-11-09 14:39:42 -0500 | [diff] [blame] | 1505 | trace_xprtrdma_reply_short_err(rep); |
Chuck Lever | b0e178a | 2015-10-24 17:26:54 -0400 | [diff] [blame] | 1506 | |
Chuck Lever | 6ceea36 | 2018-12-19 10:58:24 -0500 | [diff] [blame] | 1507 | out: |
Chuck Lever | c35ca60 | 2021-04-19 14:02:47 -0400 | [diff] [blame] | 1508 | rpcrdma_rep_put(buf, rep); |
\"Talpey, Thomas\ | e960182 | 2007-09-10 13:50:42 -0400 | [diff] [blame] | 1509 | } |