rpc_rdma.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. /*
  2. * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the BSD-type
  8. * license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * Redistributions in binary form must reproduce the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer in the documentation and/or other materials provided
  20. * with the distribution.
  21. *
  22. * Neither the name of the Network Appliance, Inc. nor the names of
  23. * its contributors may be used to endorse or promote products
  24. * derived from this software without specific prior written
  25. * permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. /*
  40. * rpc_rdma.c
  41. *
  42. * This file contains the guts of the RPC RDMA protocol, and
  43. * does marshaling/unmarshaling, etc. It is also where interfacing
  44. * to the Linux RPC framework lives.
  45. */
  46. #include "xprt_rdma.h"
  47. #include <linux/highmem.h>
  48. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  49. # define RPCDBG_FACILITY RPCDBG_TRANS
  50. #endif
  51. static const char transfertypes[][12] = {
  52. "inline", /* no chunks */
  53. "read list", /* some argument via rdma read */
  54. "*read list", /* entire request via rdma read */
  55. "write list", /* some result via rdma write */
  56. "reply chunk" /* entire reply via rdma write */
  57. };
  58. /* Returns size of largest RPC-over-RDMA header in a Call message
  59. *
  60. * The largest Call header contains a full-size Read list and a
  61. * minimal Reply chunk.
  62. */
  63. static unsigned int rpcrdma_max_call_header_size(unsigned int maxsegs)
  64. {
  65. unsigned int size;
  66. /* Fixed header fields and list discriminators */
  67. size = RPCRDMA_HDRLEN_MIN;
  68. /* Maximum Read list size */
  69. maxsegs += 2; /* segment for head and tail buffers */
  70. size = maxsegs * sizeof(struct rpcrdma_read_chunk);
  71. /* Minimal Read chunk size */
  72. size += sizeof(__be32); /* segment count */
  73. size += sizeof(struct rpcrdma_segment);
  74. size += sizeof(__be32); /* list discriminator */
  75. dprintk("RPC: %s: max call header size = %u\n",
  76. __func__, size);
  77. return size;
  78. }
  79. /* Returns size of largest RPC-over-RDMA header in a Reply message
  80. *
  81. * There is only one Write list or one Reply chunk per Reply
  82. * message. The larger list is the Write list.
  83. */
  84. static unsigned int rpcrdma_max_reply_header_size(unsigned int maxsegs)
  85. {
  86. unsigned int size;
  87. /* Fixed header fields and list discriminators */
  88. size = RPCRDMA_HDRLEN_MIN;
  89. /* Maximum Write list size */
  90. maxsegs += 2; /* segment for head and tail buffers */
  91. size = sizeof(__be32); /* segment count */
  92. size += maxsegs * sizeof(struct rpcrdma_segment);
  93. size += sizeof(__be32); /* list discriminator */
  94. dprintk("RPC: %s: max reply header size = %u\n",
  95. __func__, size);
  96. return size;
  97. }
  98. void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *r_xprt)
  99. {
  100. struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
  101. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  102. unsigned int maxsegs = ia->ri_max_segs;
  103. ia->ri_max_inline_write = cdata->inline_wsize -
  104. rpcrdma_max_call_header_size(maxsegs);
  105. ia->ri_max_inline_read = cdata->inline_rsize -
  106. rpcrdma_max_reply_header_size(maxsegs);
  107. }
  108. /* The client can send a request inline as long as the RPCRDMA header
  109. * plus the RPC call fit under the transport's inline limit. If the
  110. * combined call message size exceeds that limit, the client must use
  111. * the read chunk list for this operation.
  112. */
  113. static bool rpcrdma_args_inline(struct rpcrdma_xprt *r_xprt,
  114. struct rpc_rqst *rqst)
  115. {
  116. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  117. return rqst->rq_snd_buf.len <= ia->ri_max_inline_write;
  118. }
  119. /* The client can't know how large the actual reply will be. Thus it
  120. * plans for the largest possible reply for that particular ULP
  121. * operation. If the maximum combined reply message size exceeds that
  122. * limit, the client must provide a write list or a reply chunk for
  123. * this request.
  124. */
  125. static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
  126. struct rpc_rqst *rqst)
  127. {
  128. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  129. return rqst->rq_rcv_buf.buflen <= ia->ri_max_inline_read;
  130. }
  131. /* Split "vec" on page boundaries into segments. FMR registers pages,
  132. * not a byte range. Other modes coalesce these segments into a single
  133. * MR when they can.
  134. */
  135. static int
  136. rpcrdma_convert_kvec(struct kvec *vec, struct rpcrdma_mr_seg *seg, int n)
  137. {
  138. size_t page_offset;
  139. u32 remaining;
  140. char *base;
  141. base = vec->iov_base;
  142. page_offset = offset_in_page(base);
  143. remaining = vec->iov_len;
  144. while (remaining && n < RPCRDMA_MAX_SEGS) {
  145. seg[n].mr_page = NULL;
  146. seg[n].mr_offset = base;
  147. seg[n].mr_len = min_t(u32, PAGE_SIZE - page_offset, remaining);
  148. remaining -= seg[n].mr_len;
  149. base += seg[n].mr_len;
  150. ++n;
  151. page_offset = 0;
  152. }
  153. return n;
  154. }
  155. /*
  156. * Chunk assembly from upper layer xdr_buf.
  157. *
  158. * Prepare the passed-in xdr_buf into representation as RPC/RDMA chunk
  159. * elements. Segments are then coalesced when registered, if possible
  160. * within the selected memreg mode.
  161. *
  162. * Returns positive number of segments converted, or a negative errno.
  163. */
  164. static int
  165. rpcrdma_convert_iovs(struct xdr_buf *xdrbuf, unsigned int pos,
  166. enum rpcrdma_chunktype type, struct rpcrdma_mr_seg *seg,
  167. bool reminv_expected)
  168. {
  169. int len, n, p, page_base;
  170. struct page **ppages;
  171. n = 0;
  172. if (pos == 0) {
  173. n = rpcrdma_convert_kvec(&xdrbuf->head[0], seg, n);
  174. if (n == RPCRDMA_MAX_SEGS)
  175. goto out_overflow;
  176. }
  177. len = xdrbuf->page_len;
  178. ppages = xdrbuf->pages + (xdrbuf->page_base >> PAGE_SHIFT);
  179. page_base = xdrbuf->page_base & ~PAGE_MASK;
  180. p = 0;
  181. while (len && n < RPCRDMA_MAX_SEGS) {
  182. if (!ppages[p]) {
  183. /* alloc the pagelist for receiving buffer */
  184. ppages[p] = alloc_page(GFP_ATOMIC);
  185. if (!ppages[p])
  186. return -EAGAIN;
  187. }
  188. seg[n].mr_page = ppages[p];
  189. seg[n].mr_offset = (void *)(unsigned long) page_base;
  190. seg[n].mr_len = min_t(u32, PAGE_SIZE - page_base, len);
  191. if (seg[n].mr_len > PAGE_SIZE)
  192. goto out_overflow;
  193. len -= seg[n].mr_len;
  194. ++n;
  195. ++p;
  196. page_base = 0; /* page offset only applies to first page */
  197. }
  198. /* Message overflows the seg array */
  199. if (len && n == RPCRDMA_MAX_SEGS)
  200. goto out_overflow;
  201. /* When encoding the read list, the tail is always sent inline */
  202. if (type == rpcrdma_readch)
  203. return n;
  204. /* When encoding the Write list, some servers need to see an extra
  205. * segment for odd-length Write chunks. The upper layer provides
  206. * space in the tail iovec for this purpose.
  207. */
  208. if (type == rpcrdma_writech && reminv_expected)
  209. return n;
  210. if (xdrbuf->tail[0].iov_len) {
  211. /* the rpcrdma protocol allows us to omit any trailing
  212. * xdr pad bytes, saving the server an RDMA operation. */
  213. if (xdrbuf->tail[0].iov_len < 4 && xprt_rdma_pad_optimize)
  214. return n;
  215. n = rpcrdma_convert_kvec(&xdrbuf->tail[0], seg, n);
  216. if (n == RPCRDMA_MAX_SEGS)
  217. goto out_overflow;
  218. }
  219. return n;
  220. out_overflow:
  221. pr_err("rpcrdma: segment array overflow\n");
  222. return -EIO;
  223. }
  224. static inline __be32 *
  225. xdr_encode_rdma_segment(__be32 *iptr, struct rpcrdma_mw *mw)
  226. {
  227. *iptr++ = cpu_to_be32(mw->mw_handle);
  228. *iptr++ = cpu_to_be32(mw->mw_length);
  229. return xdr_encode_hyper(iptr, mw->mw_offset);
  230. }
  231. /* XDR-encode the Read list. Supports encoding a list of read
  232. * segments that belong to a single read chunk.
  233. *
  234. * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
  235. *
  236. * Read chunklist (a linked list):
  237. * N elements, position P (same P for all chunks of same arg!):
  238. * 1 - PHLOO - 1 - PHLOO - ... - 1 - PHLOO - 0
  239. *
  240. * Returns a pointer to the XDR word in the RDMA header following
  241. * the end of the Read list, or an error pointer.
  242. */
  243. static __be32 *
  244. rpcrdma_encode_read_list(struct rpcrdma_xprt *r_xprt,
  245. struct rpcrdma_req *req, struct rpc_rqst *rqst,
  246. __be32 *iptr, enum rpcrdma_chunktype rtype)
  247. {
  248. struct rpcrdma_mr_seg *seg;
  249. struct rpcrdma_mw *mw;
  250. unsigned int pos;
  251. int n, nsegs;
  252. if (rtype == rpcrdma_noch) {
  253. *iptr++ = xdr_zero; /* item not present */
  254. return iptr;
  255. }
  256. pos = rqst->rq_snd_buf.head[0].iov_len;
  257. if (rtype == rpcrdma_areadch)
  258. pos = 0;
  259. seg = req->rl_segments;
  260. nsegs = rpcrdma_convert_iovs(&rqst->rq_snd_buf, pos, rtype, seg, false);
  261. if (nsegs < 0)
  262. return ERR_PTR(nsegs);
  263. do {
  264. n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs,
  265. false, &mw);
  266. if (n < 0)
  267. return ERR_PTR(n);
  268. list_add(&mw->mw_list, &req->rl_registered);
  269. *iptr++ = xdr_one; /* item present */
  270. /* All read segments in this chunk
  271. * have the same "position".
  272. */
  273. *iptr++ = cpu_to_be32(pos);
  274. iptr = xdr_encode_rdma_segment(iptr, mw);
  275. dprintk("RPC: %5u %s: pos %u %u@0x%016llx:0x%08x (%s)\n",
  276. rqst->rq_task->tk_pid, __func__, pos,
  277. mw->mw_length, (unsigned long long)mw->mw_offset,
  278. mw->mw_handle, n < nsegs ? "more" : "last");
  279. r_xprt->rx_stats.read_chunk_count++;
  280. seg += n;
  281. nsegs -= n;
  282. } while (nsegs);
  283. /* Finish Read list */
  284. *iptr++ = xdr_zero; /* Next item not present */
  285. return iptr;
  286. }
  287. /* XDR-encode the Write list. Supports encoding a list containing
  288. * one array of plain segments that belong to a single write chunk.
  289. *
  290. * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
  291. *
  292. * Write chunklist (a list of (one) counted array):
  293. * N elements:
  294. * 1 - N - HLOO - HLOO - ... - HLOO - 0
  295. *
  296. * Returns a pointer to the XDR word in the RDMA header following
  297. * the end of the Write list, or an error pointer.
  298. */
  299. static __be32 *
  300. rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
  301. struct rpc_rqst *rqst, __be32 *iptr,
  302. enum rpcrdma_chunktype wtype)
  303. {
  304. struct rpcrdma_mr_seg *seg;
  305. struct rpcrdma_mw *mw;
  306. int n, nsegs, nchunks;
  307. __be32 *segcount;
  308. if (wtype != rpcrdma_writech) {
  309. *iptr++ = xdr_zero; /* no Write list present */
  310. return iptr;
  311. }
  312. seg = req->rl_segments;
  313. nsegs = rpcrdma_convert_iovs(&rqst->rq_rcv_buf,
  314. rqst->rq_rcv_buf.head[0].iov_len,
  315. wtype, seg,
  316. r_xprt->rx_ia.ri_reminv_expected);
  317. if (nsegs < 0)
  318. return ERR_PTR(nsegs);
  319. *iptr++ = xdr_one; /* Write list present */
  320. segcount = iptr++; /* save location of segment count */
  321. nchunks = 0;
  322. do {
  323. n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs,
  324. true, &mw);
  325. if (n < 0)
  326. return ERR_PTR(n);
  327. list_add(&mw->mw_list, &req->rl_registered);
  328. iptr = xdr_encode_rdma_segment(iptr, mw);
  329. dprintk("RPC: %5u %s: %u@0x016%llx:0x%08x (%s)\n",
  330. rqst->rq_task->tk_pid, __func__,
  331. mw->mw_length, (unsigned long long)mw->mw_offset,
  332. mw->mw_handle, n < nsegs ? "more" : "last");
  333. r_xprt->rx_stats.write_chunk_count++;
  334. r_xprt->rx_stats.total_rdma_request += seg->mr_len;
  335. nchunks++;
  336. seg += n;
  337. nsegs -= n;
  338. } while (nsegs);
  339. /* Update count of segments in this Write chunk */
  340. *segcount = cpu_to_be32(nchunks);
  341. /* Finish Write list */
  342. *iptr++ = xdr_zero; /* Next item not present */
  343. return iptr;
  344. }
  345. /* XDR-encode the Reply chunk. Supports encoding an array of plain
  346. * segments that belong to a single write (reply) chunk.
  347. *
  348. * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
  349. *
  350. * Reply chunk (a counted array):
  351. * N elements:
  352. * 1 - N - HLOO - HLOO - ... - HLOO
  353. *
  354. * Returns a pointer to the XDR word in the RDMA header following
  355. * the end of the Reply chunk, or an error pointer.
  356. */
  357. static __be32 *
  358. rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt,
  359. struct rpcrdma_req *req, struct rpc_rqst *rqst,
  360. __be32 *iptr, enum rpcrdma_chunktype wtype)
  361. {
  362. struct rpcrdma_mr_seg *seg;
  363. struct rpcrdma_mw *mw;
  364. int n, nsegs, nchunks;
  365. __be32 *segcount;
  366. if (wtype != rpcrdma_replych) {
  367. *iptr++ = xdr_zero; /* no Reply chunk present */
  368. return iptr;
  369. }
  370. seg = req->rl_segments;
  371. nsegs = rpcrdma_convert_iovs(&rqst->rq_rcv_buf, 0, wtype, seg,
  372. r_xprt->rx_ia.ri_reminv_expected);
  373. if (nsegs < 0)
  374. return ERR_PTR(nsegs);
  375. *iptr++ = xdr_one; /* Reply chunk present */
  376. segcount = iptr++; /* save location of segment count */
  377. nchunks = 0;
  378. do {
  379. n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs,
  380. true, &mw);
  381. if (n < 0)
  382. return ERR_PTR(n);
  383. list_add(&mw->mw_list, &req->rl_registered);
  384. iptr = xdr_encode_rdma_segment(iptr, mw);
  385. dprintk("RPC: %5u %s: %u@0x%016llx:0x%08x (%s)\n",
  386. rqst->rq_task->tk_pid, __func__,
  387. mw->mw_length, (unsigned long long)mw->mw_offset,
  388. mw->mw_handle, n < nsegs ? "more" : "last");
  389. r_xprt->rx_stats.reply_chunk_count++;
  390. r_xprt->rx_stats.total_rdma_request += seg->mr_len;
  391. nchunks++;
  392. seg += n;
  393. nsegs -= n;
  394. } while (nsegs);
  395. /* Update count of segments in the Reply chunk */
  396. *segcount = cpu_to_be32(nchunks);
  397. return iptr;
  398. }
  399. /* Prepare the RPC-over-RDMA header SGE.
  400. */
  401. static bool
  402. rpcrdma_prepare_hdr_sge(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
  403. u32 len)
  404. {
  405. struct rpcrdma_regbuf *rb = req->rl_rdmabuf;
  406. struct ib_sge *sge = &req->rl_send_sge[0];
  407. if (unlikely(!rpcrdma_regbuf_is_mapped(rb))) {
  408. if (!__rpcrdma_dma_map_regbuf(ia, rb))
  409. return false;
  410. sge->addr = rdmab_addr(rb);
  411. sge->lkey = rdmab_lkey(rb);
  412. }
  413. sge->length = len;
  414. ib_dma_sync_single_for_device(ia->ri_device, sge->addr,
  415. sge->length, DMA_TO_DEVICE);
  416. req->rl_send_wr.num_sge++;
  417. return true;
  418. }
  419. /* Prepare the Send SGEs. The head and tail iovec, and each entry
  420. * in the page list, gets its own SGE.
  421. */
  422. static bool
  423. rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
  424. struct xdr_buf *xdr, enum rpcrdma_chunktype rtype)
  425. {
  426. unsigned int sge_no, page_base, len, remaining;
  427. struct rpcrdma_regbuf *rb = req->rl_sendbuf;
  428. struct ib_device *device = ia->ri_device;
  429. struct ib_sge *sge = req->rl_send_sge;
  430. u32 lkey = ia->ri_pd->local_dma_lkey;
  431. struct page *page, **ppages;
  432. /* The head iovec is straightforward, as it is already
  433. * DMA-mapped. Sync the content that has changed.
  434. */
  435. if (!rpcrdma_dma_map_regbuf(ia, rb))
  436. return false;
  437. sge_no = 1;
  438. sge[sge_no].addr = rdmab_addr(rb);
  439. sge[sge_no].length = xdr->head[0].iov_len;
  440. sge[sge_no].lkey = rdmab_lkey(rb);
  441. ib_dma_sync_single_for_device(device, sge[sge_no].addr,
  442. sge[sge_no].length, DMA_TO_DEVICE);
  443. /* If there is a Read chunk, the page list is being handled
  444. * via explicit RDMA, and thus is skipped here. However, the
  445. * tail iovec may include an XDR pad for the page list, as
  446. * well as additional content, and may not reside in the
  447. * same page as the head iovec.
  448. */
  449. if (rtype == rpcrdma_readch) {
  450. len = xdr->tail[0].iov_len;
  451. /* Do not include the tail if it is only an XDR pad */
  452. if (len < 4)
  453. goto out;
  454. page = virt_to_page(xdr->tail[0].iov_base);
  455. page_base = (unsigned long)xdr->tail[0].iov_base & ~PAGE_MASK;
  456. /* If the content in the page list is an odd length,
  457. * xdr_write_pages() has added a pad at the beginning
  458. * of the tail iovec. Force the tail's non-pad content
  459. * to land at the next XDR position in the Send message.
  460. */
  461. page_base += len & 3;
  462. len -= len & 3;
  463. goto map_tail;
  464. }
  465. /* If there is a page list present, temporarily DMA map
  466. * and prepare an SGE for each page to be sent.
  467. */
  468. if (xdr->page_len) {
  469. ppages = xdr->pages + (xdr->page_base >> PAGE_SHIFT);
  470. page_base = xdr->page_base & ~PAGE_MASK;
  471. remaining = xdr->page_len;
  472. while (remaining) {
  473. sge_no++;
  474. if (sge_no > RPCRDMA_MAX_SEND_SGES - 2)
  475. goto out_mapping_overflow;
  476. len = min_t(u32, PAGE_SIZE - page_base, remaining);
  477. sge[sge_no].addr = ib_dma_map_page(device, *ppages,
  478. page_base, len,
  479. DMA_TO_DEVICE);
  480. if (ib_dma_mapping_error(device, sge[sge_no].addr))
  481. goto out_mapping_err;
  482. sge[sge_no].length = len;
  483. sge[sge_no].lkey = lkey;
  484. req->rl_mapped_sges++;
  485. ppages++;
  486. remaining -= len;
  487. page_base = 0;
  488. }
  489. }
  490. /* The tail iovec is not always constructed in the same
  491. * page where the head iovec resides (see, for example,
  492. * gss_wrap_req_priv). To neatly accommodate that case,
  493. * DMA map it separately.
  494. */
  495. if (xdr->tail[0].iov_len) {
  496. page = virt_to_page(xdr->tail[0].iov_base);
  497. page_base = (unsigned long)xdr->tail[0].iov_base & ~PAGE_MASK;
  498. len = xdr->tail[0].iov_len;
  499. map_tail:
  500. sge_no++;
  501. sge[sge_no].addr = ib_dma_map_page(device, page,
  502. page_base, len,
  503. DMA_TO_DEVICE);
  504. if (ib_dma_mapping_error(device, sge[sge_no].addr))
  505. goto out_mapping_err;
  506. sge[sge_no].length = len;
  507. sge[sge_no].lkey = lkey;
  508. req->rl_mapped_sges++;
  509. }
  510. out:
  511. req->rl_send_wr.num_sge = sge_no + 1;
  512. return true;
  513. out_mapping_overflow:
  514. pr_err("rpcrdma: too many Send SGEs (%u)\n", sge_no);
  515. return false;
  516. out_mapping_err:
  517. pr_err("rpcrdma: Send mapping error\n");
  518. return false;
  519. }
  520. bool
  521. rpcrdma_prepare_send_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
  522. u32 hdrlen, struct xdr_buf *xdr,
  523. enum rpcrdma_chunktype rtype)
  524. {
  525. req->rl_send_wr.num_sge = 0;
  526. req->rl_mapped_sges = 0;
  527. if (!rpcrdma_prepare_hdr_sge(ia, req, hdrlen))
  528. goto out_map;
  529. if (rtype != rpcrdma_areadch)
  530. if (!rpcrdma_prepare_msg_sges(ia, req, xdr, rtype))
  531. goto out_map;
  532. return true;
  533. out_map:
  534. pr_err("rpcrdma: failed to DMA map a Send buffer\n");
  535. return false;
  536. }
  537. void
  538. rpcrdma_unmap_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req)
  539. {
  540. struct ib_device *device = ia->ri_device;
  541. struct ib_sge *sge;
  542. int count;
  543. sge = &req->rl_send_sge[2];
  544. for (count = req->rl_mapped_sges; count--; sge++)
  545. ib_dma_unmap_page(device, sge->addr, sge->length,
  546. DMA_TO_DEVICE);
  547. req->rl_mapped_sges = 0;
  548. }
  549. /*
  550. * Marshal a request: the primary job of this routine is to choose
  551. * the transfer modes. See comments below.
  552. *
  553. * Returns zero on success, otherwise a negative errno.
  554. */
  555. int
  556. rpcrdma_marshal_req(struct rpc_rqst *rqst)
  557. {
  558. struct rpc_xprt *xprt = rqst->rq_xprt;
  559. struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
  560. struct rpcrdma_req *req = rpcr_to_rdmar(rqst);
  561. enum rpcrdma_chunktype rtype, wtype;
  562. struct rpcrdma_msg *headerp;
  563. bool ddp_allowed;
  564. ssize_t hdrlen;
  565. size_t rpclen;
  566. __be32 *iptr;
  567. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  568. if (test_bit(RPC_BC_PA_IN_USE, &rqst->rq_bc_pa_state))
  569. return rpcrdma_bc_marshal_reply(rqst);
  570. #endif
  571. headerp = rdmab_to_msg(req->rl_rdmabuf);
  572. /* don't byte-swap XID, it's already done in request */
  573. headerp->rm_xid = rqst->rq_xid;
  574. headerp->rm_vers = rpcrdma_version;
  575. headerp->rm_credit = cpu_to_be32(r_xprt->rx_buf.rb_max_requests);
  576. headerp->rm_type = rdma_msg;
  577. /* When the ULP employs a GSS flavor that guarantees integrity
  578. * or privacy, direct data placement of individual data items
  579. * is not allowed.
  580. */
  581. ddp_allowed = !(rqst->rq_cred->cr_auth->au_flags &
  582. RPCAUTH_AUTH_DATATOUCH);
  583. /*
  584. * Chunks needed for results?
  585. *
  586. * o If the expected result is under the inline threshold, all ops
  587. * return as inline.
  588. * o Large read ops return data as write chunk(s), header as
  589. * inline.
  590. * o Large non-read ops return as a single reply chunk.
  591. */
  592. if (rpcrdma_results_inline(r_xprt, rqst))
  593. wtype = rpcrdma_noch;
  594. else if (ddp_allowed && rqst->rq_rcv_buf.flags & XDRBUF_READ)
  595. wtype = rpcrdma_writech;
  596. else
  597. wtype = rpcrdma_replych;
  598. /*
  599. * Chunks needed for arguments?
  600. *
  601. * o If the total request is under the inline threshold, all ops
  602. * are sent as inline.
  603. * o Large write ops transmit data as read chunk(s), header as
  604. * inline.
  605. * o Large non-write ops are sent with the entire message as a
  606. * single read chunk (protocol 0-position special case).
  607. *
  608. * This assumes that the upper layer does not present a request
  609. * that both has a data payload, and whose non-data arguments
  610. * by themselves are larger than the inline threshold.
  611. */
  612. if (rpcrdma_args_inline(r_xprt, rqst)) {
  613. rtype = rpcrdma_noch;
  614. rpclen = rqst->rq_snd_buf.len;
  615. } else if (ddp_allowed && rqst->rq_snd_buf.flags & XDRBUF_WRITE) {
  616. rtype = rpcrdma_readch;
  617. rpclen = rqst->rq_snd_buf.head[0].iov_len +
  618. rqst->rq_snd_buf.tail[0].iov_len;
  619. } else {
  620. r_xprt->rx_stats.nomsg_call_count++;
  621. headerp->rm_type = htonl(RDMA_NOMSG);
  622. rtype = rpcrdma_areadch;
  623. rpclen = 0;
  624. }
  625. /* This implementation supports the following combinations
  626. * of chunk lists in one RPC-over-RDMA Call message:
  627. *
  628. * - Read list
  629. * - Write list
  630. * - Reply chunk
  631. * - Read list + Reply chunk
  632. *
  633. * It might not yet support the following combinations:
  634. *
  635. * - Read list + Write list
  636. *
  637. * It does not support the following combinations:
  638. *
  639. * - Write list + Reply chunk
  640. * - Read list + Write list + Reply chunk
  641. *
  642. * This implementation supports only a single chunk in each
  643. * Read or Write list. Thus for example the client cannot
  644. * send a Call message with a Position Zero Read chunk and a
  645. * regular Read chunk at the same time.
  646. */
  647. iptr = headerp->rm_body.rm_chunks;
  648. iptr = rpcrdma_encode_read_list(r_xprt, req, rqst, iptr, rtype);
  649. if (IS_ERR(iptr))
  650. goto out_unmap;
  651. iptr = rpcrdma_encode_write_list(r_xprt, req, rqst, iptr, wtype);
  652. if (IS_ERR(iptr))
  653. goto out_unmap;
  654. iptr = rpcrdma_encode_reply_chunk(r_xprt, req, rqst, iptr, wtype);
  655. if (IS_ERR(iptr))
  656. goto out_unmap;
  657. hdrlen = (unsigned char *)iptr - (unsigned char *)headerp;
  658. dprintk("RPC: %5u %s: %s/%s: hdrlen %zd rpclen %zd\n",
  659. rqst->rq_task->tk_pid, __func__,
  660. transfertypes[rtype], transfertypes[wtype],
  661. hdrlen, rpclen);
  662. if (!rpcrdma_prepare_send_sges(&r_xprt->rx_ia, req, hdrlen,
  663. &rqst->rq_snd_buf, rtype)) {
  664. iptr = ERR_PTR(-EIO);
  665. goto out_unmap;
  666. }
  667. return 0;
  668. out_unmap:
  669. r_xprt->rx_ia.ri_ops->ro_unmap_safe(r_xprt, req, false);
  670. return PTR_ERR(iptr);
  671. }
  672. /*
  673. * Chase down a received write or reply chunklist to get length
  674. * RDMA'd by server. See map at rpcrdma_create_chunks()! :-)
  675. */
  676. static int
  677. rpcrdma_count_chunks(struct rpcrdma_rep *rep, int wrchunk, __be32 **iptrp)
  678. {
  679. unsigned int i, total_len;
  680. struct rpcrdma_write_chunk *cur_wchunk;
  681. char *base = (char *)rdmab_to_msg(rep->rr_rdmabuf);
  682. i = be32_to_cpu(**iptrp);
  683. cur_wchunk = (struct rpcrdma_write_chunk *) (*iptrp + 1);
  684. total_len = 0;
  685. while (i--) {
  686. struct rpcrdma_segment *seg = &cur_wchunk->wc_target;
  687. ifdebug(FACILITY) {
  688. u64 off;
  689. xdr_decode_hyper((__be32 *)&seg->rs_offset, &off);
  690. dprintk("RPC: %s: chunk %d@0x%016llx:0x%08x\n",
  691. __func__,
  692. be32_to_cpu(seg->rs_length),
  693. (unsigned long long)off,
  694. be32_to_cpu(seg->rs_handle));
  695. }
  696. total_len += be32_to_cpu(seg->rs_length);
  697. ++cur_wchunk;
  698. }
  699. /* check and adjust for properly terminated write chunk */
  700. if (wrchunk) {
  701. __be32 *w = (__be32 *) cur_wchunk;
  702. if (*w++ != xdr_zero)
  703. return -1;
  704. cur_wchunk = (struct rpcrdma_write_chunk *) w;
  705. }
  706. if ((char *)cur_wchunk > base + rep->rr_len)
  707. return -1;
  708. *iptrp = (__be32 *) cur_wchunk;
  709. return total_len;
  710. }
  711. /**
  712. * rpcrdma_inline_fixup - Scatter inline received data into rqst's iovecs
  713. * @rqst: controlling RPC request
  714. * @srcp: points to RPC message payload in receive buffer
  715. * @copy_len: remaining length of receive buffer content
  716. * @pad: Write chunk pad bytes needed (zero for pure inline)
  717. *
  718. * The upper layer has set the maximum number of bytes it can
  719. * receive in each component of rq_rcv_buf. These values are set in
  720. * the head.iov_len, page_len, tail.iov_len, and buflen fields.
  721. *
  722. * Unlike the TCP equivalent (xdr_partial_copy_from_skb), in
  723. * many cases this function simply updates iov_base pointers in
  724. * rq_rcv_buf to point directly to the received reply data, to
  725. * avoid copying reply data.
  726. *
  727. * Returns the count of bytes which had to be memcopied.
  728. */
  729. static unsigned long
  730. rpcrdma_inline_fixup(struct rpc_rqst *rqst, char *srcp, int copy_len, int pad)
  731. {
  732. unsigned long fixup_copy_count;
  733. int i, npages, curlen;
  734. char *destp;
  735. struct page **ppages;
  736. int page_base;
  737. /* The head iovec is redirected to the RPC reply message
  738. * in the receive buffer, to avoid a memcopy.
  739. */
  740. rqst->rq_rcv_buf.head[0].iov_base = srcp;
  741. rqst->rq_private_buf.head[0].iov_base = srcp;
  742. /* The contents of the receive buffer that follow
  743. * head.iov_len bytes are copied into the page list.
  744. */
  745. curlen = rqst->rq_rcv_buf.head[0].iov_len;
  746. if (curlen > copy_len)
  747. curlen = copy_len;
  748. dprintk("RPC: %s: srcp 0x%p len %d hdrlen %d\n",
  749. __func__, srcp, copy_len, curlen);
  750. srcp += curlen;
  751. copy_len -= curlen;
  752. page_base = rqst->rq_rcv_buf.page_base;
  753. ppages = rqst->rq_rcv_buf.pages + (page_base >> PAGE_SHIFT);
  754. page_base &= ~PAGE_MASK;
  755. fixup_copy_count = 0;
  756. if (copy_len && rqst->rq_rcv_buf.page_len) {
  757. int pagelist_len;
  758. pagelist_len = rqst->rq_rcv_buf.page_len;
  759. if (pagelist_len > copy_len)
  760. pagelist_len = copy_len;
  761. npages = PAGE_ALIGN(page_base + pagelist_len) >> PAGE_SHIFT;
  762. for (i = 0; i < npages; i++) {
  763. curlen = PAGE_SIZE - page_base;
  764. if (curlen > pagelist_len)
  765. curlen = pagelist_len;
  766. dprintk("RPC: %s: page %d"
  767. " srcp 0x%p len %d curlen %d\n",
  768. __func__, i, srcp, copy_len, curlen);
  769. destp = kmap_atomic(ppages[i]);
  770. memcpy(destp + page_base, srcp, curlen);
  771. flush_dcache_page(ppages[i]);
  772. kunmap_atomic(destp);
  773. srcp += curlen;
  774. copy_len -= curlen;
  775. fixup_copy_count += curlen;
  776. pagelist_len -= curlen;
  777. if (!pagelist_len)
  778. break;
  779. page_base = 0;
  780. }
  781. /* Implicit padding for the last segment in a Write
  782. * chunk is inserted inline at the front of the tail
  783. * iovec. The upper layer ignores the content of
  784. * the pad. Simply ensure inline content in the tail
  785. * that follows the Write chunk is properly aligned.
  786. */
  787. if (pad)
  788. srcp -= pad;
  789. }
  790. /* The tail iovec is redirected to the remaining data
  791. * in the receive buffer, to avoid a memcopy.
  792. */
  793. if (copy_len || pad) {
  794. rqst->rq_rcv_buf.tail[0].iov_base = srcp;
  795. rqst->rq_private_buf.tail[0].iov_base = srcp;
  796. }
  797. return fixup_copy_count;
  798. }
  799. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  800. /* By convention, backchannel calls arrive via rdma_msg type
  801. * messages, and never populate the chunk lists. This makes
  802. * the RPC/RDMA header small and fixed in size, so it is
  803. * straightforward to check the RPC header's direction field.
  804. */
  805. static bool
  806. rpcrdma_is_bcall(struct rpcrdma_msg *headerp)
  807. {
  808. __be32 *p = (__be32 *)headerp;
  809. if (headerp->rm_type != rdma_msg)
  810. return false;
  811. if (headerp->rm_body.rm_chunks[0] != xdr_zero)
  812. return false;
  813. if (headerp->rm_body.rm_chunks[1] != xdr_zero)
  814. return false;
  815. if (headerp->rm_body.rm_chunks[2] != xdr_zero)
  816. return false;
  817. /* sanity */
  818. if (p[7] != headerp->rm_xid)
  819. return false;
  820. /* call direction */
  821. if (p[8] != cpu_to_be32(RPC_CALL))
  822. return false;
  823. return true;
  824. }
  825. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  826. /* Process received RPC/RDMA messages.
  827. *
  828. * Errors must result in the RPC task either being awakened, or
  829. * allowed to timeout, to discover the errors at that time.
  830. */
  831. void
  832. rpcrdma_reply_handler(struct work_struct *work)
  833. {
  834. struct rpcrdma_rep *rep =
  835. container_of(work, struct rpcrdma_rep, rr_work);
  836. struct rpcrdma_msg *headerp;
  837. struct rpcrdma_req *req;
  838. struct rpc_rqst *rqst;
  839. struct rpcrdma_xprt *r_xprt = rep->rr_rxprt;
  840. struct rpc_xprt *xprt = &r_xprt->rx_xprt;
  841. __be32 *iptr;
  842. int rdmalen, status, rmerr;
  843. unsigned long cwnd;
  844. dprintk("RPC: %s: incoming rep %p\n", __func__, rep);
  845. if (rep->rr_len == RPCRDMA_BAD_LEN)
  846. goto out_badstatus;
  847. if (rep->rr_len < RPCRDMA_HDRLEN_ERR)
  848. goto out_shortreply;
  849. headerp = rdmab_to_msg(rep->rr_rdmabuf);
  850. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  851. if (rpcrdma_is_bcall(headerp))
  852. goto out_bcall;
  853. #endif
  854. /* Match incoming rpcrdma_rep to an rpcrdma_req to
  855. * get context for handling any incoming chunks.
  856. */
  857. spin_lock_bh(&xprt->transport_lock);
  858. rqst = xprt_lookup_rqst(xprt, headerp->rm_xid);
  859. if (!rqst)
  860. goto out_nomatch;
  861. req = rpcr_to_rdmar(rqst);
  862. if (req->rl_reply)
  863. goto out_duplicate;
  864. /* Sanity checking has passed. We are now committed
  865. * to complete this transaction.
  866. */
  867. list_del_init(&rqst->rq_list);
  868. spin_unlock_bh(&xprt->transport_lock);
  869. dprintk("RPC: %s: reply %p completes request %p (xid 0x%08x)\n",
  870. __func__, rep, req, be32_to_cpu(headerp->rm_xid));
  871. /* from here on, the reply is no longer an orphan */
  872. req->rl_reply = rep;
  873. xprt->reestablish_timeout = 0;
  874. if (headerp->rm_vers != rpcrdma_version)
  875. goto out_badversion;
  876. /* check for expected message types */
  877. /* The order of some of these tests is important. */
  878. switch (headerp->rm_type) {
  879. case rdma_msg:
  880. /* never expect read chunks */
  881. /* never expect reply chunks (two ways to check) */
  882. /* never expect write chunks without having offered RDMA */
  883. if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
  884. (headerp->rm_body.rm_chunks[1] == xdr_zero &&
  885. headerp->rm_body.rm_chunks[2] != xdr_zero) ||
  886. (headerp->rm_body.rm_chunks[1] != xdr_zero &&
  887. list_empty(&req->rl_registered)))
  888. goto badheader;
  889. if (headerp->rm_body.rm_chunks[1] != xdr_zero) {
  890. /* count any expected write chunks in read reply */
  891. /* start at write chunk array count */
  892. iptr = &headerp->rm_body.rm_chunks[2];
  893. rdmalen = rpcrdma_count_chunks(rep, 1, &iptr);
  894. /* check for validity, and no reply chunk after */
  895. if (rdmalen < 0 || *iptr++ != xdr_zero)
  896. goto badheader;
  897. rep->rr_len -=
  898. ((unsigned char *)iptr - (unsigned char *)headerp);
  899. status = rep->rr_len + rdmalen;
  900. r_xprt->rx_stats.total_rdma_reply += rdmalen;
  901. /* special case - last chunk may omit padding */
  902. if (rdmalen &= 3) {
  903. rdmalen = 4 - rdmalen;
  904. status += rdmalen;
  905. }
  906. } else {
  907. /* else ordinary inline */
  908. rdmalen = 0;
  909. iptr = (__be32 *)((unsigned char *)headerp +
  910. RPCRDMA_HDRLEN_MIN);
  911. rep->rr_len -= RPCRDMA_HDRLEN_MIN;
  912. status = rep->rr_len;
  913. }
  914. r_xprt->rx_stats.fixup_copy_count +=
  915. rpcrdma_inline_fixup(rqst, (char *)iptr, rep->rr_len,
  916. rdmalen);
  917. break;
  918. case rdma_nomsg:
  919. /* never expect read or write chunks, always reply chunks */
  920. if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
  921. headerp->rm_body.rm_chunks[1] != xdr_zero ||
  922. headerp->rm_body.rm_chunks[2] != xdr_one ||
  923. list_empty(&req->rl_registered))
  924. goto badheader;
  925. iptr = (__be32 *)((unsigned char *)headerp +
  926. RPCRDMA_HDRLEN_MIN);
  927. rdmalen = rpcrdma_count_chunks(rep, 0, &iptr);
  928. if (rdmalen < 0)
  929. goto badheader;
  930. r_xprt->rx_stats.total_rdma_reply += rdmalen;
  931. /* Reply chunk buffer already is the reply vector - no fixup. */
  932. status = rdmalen;
  933. break;
  934. case rdma_error:
  935. goto out_rdmaerr;
  936. badheader:
  937. default:
  938. dprintk("RPC: %5u %s: invalid rpcrdma reply (type %u)\n",
  939. rqst->rq_task->tk_pid, __func__,
  940. be32_to_cpu(headerp->rm_type));
  941. status = -EIO;
  942. r_xprt->rx_stats.bad_reply_count++;
  943. break;
  944. }
  945. out:
  946. /* Invalidate and flush the data payloads before waking the
  947. * waiting application. This guarantees the memory region is
  948. * properly fenced from the server before the application
  949. * accesses the data. It also ensures proper send flow
  950. * control: waking the next RPC waits until this RPC has
  951. * relinquished all its Send Queue entries.
  952. */
  953. if (!list_empty(&req->rl_registered))
  954. r_xprt->rx_ia.ri_ops->ro_unmap_sync(r_xprt, req);
  955. spin_lock_bh(&xprt->transport_lock);
  956. cwnd = xprt->cwnd;
  957. xprt->cwnd = atomic_read(&r_xprt->rx_buf.rb_credits) << RPC_CWNDSHIFT;
  958. if (xprt->cwnd > cwnd)
  959. xprt_release_rqst_cong(rqst->rq_task);
  960. xprt_complete_rqst(rqst->rq_task, status);
  961. spin_unlock_bh(&xprt->transport_lock);
  962. dprintk("RPC: %s: xprt_complete_rqst(0x%p, 0x%p, %d)\n",
  963. __func__, xprt, rqst, status);
  964. return;
  965. out_badstatus:
  966. rpcrdma_recv_buffer_put(rep);
  967. if (r_xprt->rx_ep.rep_connected == 1) {
  968. r_xprt->rx_ep.rep_connected = -EIO;
  969. rpcrdma_conn_func(&r_xprt->rx_ep);
  970. }
  971. return;
  972. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  973. out_bcall:
  974. rpcrdma_bc_receive_call(r_xprt, rep);
  975. return;
  976. #endif
  977. /* If the incoming reply terminated a pending RPC, the next
  978. * RPC call will post a replacement receive buffer as it is
  979. * being marshaled.
  980. */
  981. out_badversion:
  982. dprintk("RPC: %s: invalid version %d\n",
  983. __func__, be32_to_cpu(headerp->rm_vers));
  984. status = -EIO;
  985. r_xprt->rx_stats.bad_reply_count++;
  986. goto out;
  987. out_rdmaerr:
  988. rmerr = be32_to_cpu(headerp->rm_body.rm_error.rm_err);
  989. switch (rmerr) {
  990. case ERR_VERS:
  991. pr_err("%s: server reports header version error (%u-%u)\n",
  992. __func__,
  993. be32_to_cpu(headerp->rm_body.rm_error.rm_vers_low),
  994. be32_to_cpu(headerp->rm_body.rm_error.rm_vers_high));
  995. break;
  996. case ERR_CHUNK:
  997. pr_err("%s: server reports header decoding error\n",
  998. __func__);
  999. break;
  1000. default:
  1001. pr_err("%s: server reports unknown error %d\n",
  1002. __func__, rmerr);
  1003. }
  1004. status = -EREMOTEIO;
  1005. r_xprt->rx_stats.bad_reply_count++;
  1006. goto out;
  1007. /* If no pending RPC transaction was matched, post a replacement
  1008. * receive buffer before returning.
  1009. */
  1010. out_shortreply:
  1011. dprintk("RPC: %s: short/invalid reply\n", __func__);
  1012. goto repost;
  1013. out_nomatch:
  1014. spin_unlock_bh(&xprt->transport_lock);
  1015. dprintk("RPC: %s: no match for incoming xid 0x%08x len %d\n",
  1016. __func__, be32_to_cpu(headerp->rm_xid),
  1017. rep->rr_len);
  1018. goto repost;
  1019. out_duplicate:
  1020. spin_unlock_bh(&xprt->transport_lock);
  1021. dprintk("RPC: %s: "
  1022. "duplicate reply %p to RPC request %p: xid 0x%08x\n",
  1023. __func__, rep, req, be32_to_cpu(headerp->rm_xid));
  1024. repost:
  1025. r_xprt->rx_stats.bad_reply_count++;
  1026. if (rpcrdma_ep_post_recv(&r_xprt->rx_ia, rep))
  1027. rpcrdma_recv_buffer_put(rep);
  1028. }