License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-09 17:06:16 +00:00
|
|
|
/*
|
2018-05-07 19:27:21 +00:00
|
|
|
* Copyright (c) 2016-2018 Oracle. All rights reserved.
|
2017-04-09 17:06:16 +00:00
|
|
|
*
|
|
|
|
* Use the core R/W API to move RPC-over-RDMA Read and Write chunks.
|
|
|
|
*/
|
|
|
|
|
2018-05-07 19:27:11 +00:00
|
|
|
#include <rdma/rw.h>
|
|
|
|
|
2020-03-29 20:44:13 +00:00
|
|
|
#include <linux/sunrpc/xdr.h>
|
2017-04-09 17:06:16 +00:00
|
|
|
#include <linux/sunrpc/rpc_rdma.h>
|
|
|
|
#include <linux/sunrpc/svc_rdma.h>
|
|
|
|
|
2018-05-07 19:27:11 +00:00
|
|
|
#include "xprt_rdma.h"
|
|
|
|
#include <trace/events/rpcrdma.h>
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2017-06-23 21:18:24 +00:00
|
|
|
static void svc_rdma_write_done(struct ib_cq *cq, struct ib_wc *wc);
|
|
|
|
static void svc_rdma_wc_read_done(struct ib_cq *cq, struct ib_wc *wc);
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
/* Each R/W context contains state for one chain of RDMA Read or
|
|
|
|
* Write Work Requests.
|
|
|
|
*
|
|
|
|
* Each WR chain handles a single contiguous server-side buffer,
|
|
|
|
* because scatterlist entries after the first have to start on
|
|
|
|
* page alignment. xdr_buf iovecs cannot guarantee alignment.
|
|
|
|
*
|
|
|
|
* Each WR chain handles only one R_key. Each RPC-over-RDMA segment
|
|
|
|
* from a client may contain a unique R_key, so each WR chain moves
|
|
|
|
* up to one segment at a time.
|
|
|
|
*
|
|
|
|
* The scatterlist makes this data structure over 4KB in size. To
|
|
|
|
* make it less likely to fail, and to handle the allocation for
|
|
|
|
* smaller I/O requests without disabling bottom-halves, these
|
|
|
|
* contexts are created on demand, but cached and reused until the
|
|
|
|
* controlling svcxprt_rdma is destroyed.
|
|
|
|
*/
|
|
|
|
struct svc_rdma_rw_ctxt {
|
2021-02-08 20:33:16 +00:00
|
|
|
struct llist_node rw_node;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct list_head rw_list;
|
|
|
|
struct rdma_rw_ctx rw_ctx;
|
2020-03-20 18:02:49 +00:00
|
|
|
unsigned int rw_nents;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct sg_table rw_sg_table;
|
2020-02-17 20:05:00 +00:00
|
|
|
struct scatterlist rw_first_sgl[];
|
2017-04-09 17:06:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct svc_rdma_rw_ctxt *
|
|
|
|
svc_rdma_next_ctxt(struct list_head *list)
|
|
|
|
{
|
|
|
|
return list_first_entry_or_null(list, struct svc_rdma_rw_ctxt,
|
|
|
|
rw_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct svc_rdma_rw_ctxt *
|
|
|
|
svc_rdma_get_rw_ctxt(struct svcxprt_rdma *rdma, unsigned int sges)
|
|
|
|
{
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt;
|
2021-02-08 20:33:16 +00:00
|
|
|
struct llist_node *node;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
spin_lock(&rdma->sc_rw_ctxt_lock);
|
2021-02-08 20:33:16 +00:00
|
|
|
node = llist_del_first(&rdma->sc_rw_ctxts);
|
|
|
|
spin_unlock(&rdma->sc_rw_ctxt_lock);
|
|
|
|
if (node) {
|
|
|
|
ctxt = llist_entry(node, struct svc_rdma_rw_ctxt, rw_node);
|
2017-04-09 17:06:16 +00:00
|
|
|
} else {
|
2019-01-15 21:11:40 +00:00
|
|
|
ctxt = kmalloc(struct_size(ctxt, rw_first_sgl, SG_CHUNK_SIZE),
|
2017-04-09 17:06:16 +00:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ctxt)
|
2020-03-20 18:23:13 +00:00
|
|
|
goto out_noctx;
|
2021-02-08 20:33:16 +00:00
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
INIT_LIST_HEAD(&ctxt->rw_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->rw_sg_table.sgl = ctxt->rw_first_sgl;
|
|
|
|
if (sg_alloc_table_chained(&ctxt->rw_sg_table, sges,
|
2019-04-28 07:39:30 +00:00
|
|
|
ctxt->rw_sg_table.sgl,
|
2020-03-20 18:23:13 +00:00
|
|
|
SG_CHUNK_SIZE))
|
|
|
|
goto out_free;
|
2017-04-09 17:06:16 +00:00
|
|
|
return ctxt;
|
2020-03-20 18:23:13 +00:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(ctxt);
|
|
|
|
out_noctx:
|
|
|
|
trace_svcrdma_no_rwctx_err(rdma, sges);
|
|
|
|
return NULL;
|
2017-04-09 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 20:33:16 +00:00
|
|
|
static void __svc_rdma_put_rw_ctxt(struct svcxprt_rdma *rdma,
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt,
|
|
|
|
struct llist_head *list)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
2019-04-28 07:39:30 +00:00
|
|
|
sg_free_table_chained(&ctxt->rw_sg_table, SG_CHUNK_SIZE);
|
2021-02-08 20:33:16 +00:00
|
|
|
llist_add(&ctxt->rw_node, list);
|
|
|
|
}
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2021-02-08 20:33:16 +00:00
|
|
|
static void svc_rdma_put_rw_ctxt(struct svcxprt_rdma *rdma,
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt)
|
|
|
|
{
|
|
|
|
__svc_rdma_put_rw_ctxt(rdma, ctxt, &rdma->sc_rw_ctxts);
|
2017-04-09 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_destroy_rw_ctxts - Free accumulated R/W contexts
|
|
|
|
* @rdma: transport about to be destroyed
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma)
|
|
|
|
{
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt;
|
2021-02-08 20:33:16 +00:00
|
|
|
struct llist_node *node;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2021-02-08 20:33:16 +00:00
|
|
|
while ((node = llist_del_first(&rdma->sc_rw_ctxts)) != NULL) {
|
|
|
|
ctxt = llist_entry(node, struct svc_rdma_rw_ctxt, rw_node);
|
2017-04-09 17:06:16 +00:00
|
|
|
kfree(ctxt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:02:49 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_rw_ctx_init - Prepare a R/W context for I/O
|
|
|
|
* @rdma: controlling transport instance
|
|
|
|
* @ctxt: R/W context to prepare
|
|
|
|
* @offset: RDMA offset
|
|
|
|
* @handle: RDMA tag/handle
|
|
|
|
* @direction: I/O direction
|
|
|
|
*
|
|
|
|
* Returns on success, the number of WQEs that will be needed
|
|
|
|
* on the workqueue, or a negative errno.
|
|
|
|
*/
|
|
|
|
static int svc_rdma_rw_ctx_init(struct svcxprt_rdma *rdma,
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt,
|
|
|
|
u64 offset, u32 handle,
|
|
|
|
enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rdma_rw_ctx_init(&ctxt->rw_ctx, rdma->sc_qp, rdma->sc_port_num,
|
|
|
|
ctxt->rw_sg_table.sgl, ctxt->rw_nents,
|
|
|
|
0, offset, handle, direction);
|
|
|
|
if (unlikely(ret < 0)) {
|
|
|
|
svc_rdma_put_rw_ctxt(rdma, ctxt);
|
|
|
|
trace_svcrdma_dma_map_rw_err(rdma, ctxt->rw_nents, ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
/* A chunk context tracks all I/O for moving one Read or Write
|
2020-08-23 01:07:38 +00:00
|
|
|
* chunk. This is a set of rdma_rw's that handle data movement
|
2017-04-09 17:06:16 +00:00
|
|
|
* for all segments of one chunk.
|
|
|
|
*
|
|
|
|
* These are small, acquired with a single allocator call, and
|
|
|
|
* no more than one is needed per chunk. They are allocated on
|
|
|
|
* demand, and not cached.
|
|
|
|
*/
|
|
|
|
struct svc_rdma_chunk_ctxt {
|
2020-04-29 21:25:36 +00:00
|
|
|
struct rpc_rdma_cid cc_cid;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct ib_cqe cc_cqe;
|
|
|
|
struct svcxprt_rdma *cc_rdma;
|
|
|
|
struct list_head cc_rwctxts;
|
|
|
|
int cc_sqecount;
|
2020-12-22 18:22:20 +00:00
|
|
|
enum ib_wc_status cc_status;
|
|
|
|
struct completion cc_done;
|
2017-04-09 17:06:16 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 21:25:36 +00:00
|
|
|
static void svc_rdma_cc_cid_init(struct svcxprt_rdma *rdma,
|
|
|
|
struct rpc_rdma_cid *cid)
|
|
|
|
{
|
|
|
|
cid->ci_queue_id = rdma->sc_sq_cq->res.id;
|
|
|
|
cid->ci_completion_id = atomic_inc_return(&rdma->sc_completion_ids);
|
|
|
|
}
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
static void svc_rdma_cc_init(struct svcxprt_rdma *rdma,
|
2017-06-23 21:19:29 +00:00
|
|
|
struct svc_rdma_chunk_ctxt *cc)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
2020-04-29 21:25:36 +00:00
|
|
|
svc_rdma_cc_cid_init(rdma, &cc->cc_cid);
|
2017-04-09 17:06:16 +00:00
|
|
|
cc->cc_rdma = rdma;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&cc->cc_rwctxts);
|
|
|
|
cc->cc_sqecount = 0;
|
|
|
|
}
|
|
|
|
|
2021-02-08 20:33:16 +00:00
|
|
|
/*
|
|
|
|
* The consumed rw_ctx's are cleaned and placed on a local llist so
|
|
|
|
* that only one atomic llist operation is needed to put them all
|
|
|
|
* back on the free list.
|
|
|
|
*/
|
2017-06-23 21:19:29 +00:00
|
|
|
static void svc_rdma_cc_release(struct svc_rdma_chunk_ctxt *cc,
|
|
|
|
enum dma_data_direction dir)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
|
|
|
struct svcxprt_rdma *rdma = cc->cc_rdma;
|
2021-02-08 20:33:16 +00:00
|
|
|
struct llist_node *first, *last;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct svc_rdma_rw_ctxt *ctxt;
|
2021-02-08 20:33:16 +00:00
|
|
|
LLIST_HEAD(free);
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2021-02-08 20:33:16 +00:00
|
|
|
first = last = NULL;
|
2017-04-09 17:06:16 +00:00
|
|
|
while ((ctxt = svc_rdma_next_ctxt(&cc->cc_rwctxts)) != NULL) {
|
|
|
|
list_del(&ctxt->rw_list);
|
|
|
|
|
|
|
|
rdma_rw_ctx_destroy(&ctxt->rw_ctx, rdma->sc_qp,
|
|
|
|
rdma->sc_port_num, ctxt->rw_sg_table.sgl,
|
2017-06-23 21:19:29 +00:00
|
|
|
ctxt->rw_nents, dir);
|
2021-02-08 20:33:16 +00:00
|
|
|
__svc_rdma_put_rw_ctxt(rdma, ctxt, &free);
|
|
|
|
|
|
|
|
ctxt->rw_node.next = first;
|
|
|
|
first = &ctxt->rw_node;
|
|
|
|
if (!last)
|
|
|
|
last = first;
|
2017-04-09 17:06:16 +00:00
|
|
|
}
|
2021-02-08 20:33:16 +00:00
|
|
|
if (first)
|
|
|
|
llist_add_batch(first, last, &rdma->sc_rw_ctxts);
|
2017-04-09 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* State for sending a Write or Reply chunk.
|
|
|
|
* - Tracks progress of writing one chunk over all its segments
|
|
|
|
* - Stores arguments for the SGL constructor functions
|
|
|
|
*/
|
|
|
|
struct svc_rdma_write_info {
|
2020-06-17 15:07:00 +00:00
|
|
|
const struct svc_rdma_chunk *wi_chunk;
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
/* write state of this chunk */
|
|
|
|
unsigned int wi_seg_off;
|
|
|
|
unsigned int wi_seg_no;
|
|
|
|
|
|
|
|
/* SGL constructor arguments */
|
2020-03-13 14:42:10 +00:00
|
|
|
const struct xdr_buf *wi_xdr;
|
2017-04-09 17:06:16 +00:00
|
|
|
unsigned char *wi_base;
|
|
|
|
unsigned int wi_next_off;
|
|
|
|
|
|
|
|
struct svc_rdma_chunk_ctxt wi_cc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct svc_rdma_write_info *
|
2020-06-17 15:07:00 +00:00
|
|
|
svc_rdma_write_info_alloc(struct svcxprt_rdma *rdma,
|
|
|
|
const struct svc_rdma_chunk *chunk)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
|
|
|
struct svc_rdma_write_info *info;
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (!info)
|
|
|
|
return info;
|
|
|
|
|
2020-06-17 15:07:00 +00:00
|
|
|
info->wi_chunk = chunk;
|
2017-04-09 17:06:16 +00:00
|
|
|
info->wi_seg_off = 0;
|
|
|
|
info->wi_seg_no = 0;
|
2017-06-23 21:19:29 +00:00
|
|
|
svc_rdma_cc_init(rdma, &info->wi_cc);
|
2017-06-23 21:18:24 +00:00
|
|
|
info->wi_cc.cc_cqe.done = svc_rdma_write_done;
|
2017-04-09 17:06:16 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void svc_rdma_write_info_free(struct svc_rdma_write_info *info)
|
|
|
|
{
|
2017-06-23 21:19:29 +00:00
|
|
|
svc_rdma_cc_release(&info->wi_cc, DMA_TO_DEVICE);
|
2017-04-09 17:06:16 +00:00
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_write_done - Write chunk completion
|
|
|
|
* @cq: controlling Completion Queue
|
|
|
|
* @wc: Work Completion
|
|
|
|
*
|
|
|
|
* Pages under I/O are freed by a subsequent Send completion.
|
|
|
|
*/
|
|
|
|
static void svc_rdma_write_done(struct ib_cq *cq, struct ib_wc *wc)
|
|
|
|
{
|
|
|
|
struct ib_cqe *cqe = wc->wr_cqe;
|
|
|
|
struct svc_rdma_chunk_ctxt *cc =
|
|
|
|
container_of(cqe, struct svc_rdma_chunk_ctxt, cc_cqe);
|
|
|
|
struct svcxprt_rdma *rdma = cc->cc_rdma;
|
|
|
|
struct svc_rdma_write_info *info =
|
|
|
|
container_of(cc, struct svc_rdma_write_info, wi_cc);
|
|
|
|
|
2020-04-29 21:25:36 +00:00
|
|
|
trace_svcrdma_wc_write(wc, &cc->cc_cid);
|
2018-05-07 19:27:16 +00:00
|
|
|
|
2021-07-07 18:57:28 +00:00
|
|
|
svc_rdma_wake_send_waiters(rdma, cc->cc_sqecount);
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2019-02-06 17:00:57 +00:00
|
|
|
if (unlikely(wc->status != IB_WC_SUCCESS))
|
2021-02-20 23:53:40 +00:00
|
|
|
svc_xprt_deferred_close(&rdma->sc_xprt);
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
svc_rdma_write_info_free(info);
|
|
|
|
}
|
|
|
|
|
2017-06-23 21:18:24 +00:00
|
|
|
/* State for pulling a Read chunk.
|
|
|
|
*/
|
|
|
|
struct svc_rdma_read_info {
|
2020-09-17 17:04:17 +00:00
|
|
|
struct svc_rqst *ri_rqst;
|
2018-05-07 19:27:21 +00:00
|
|
|
struct svc_rdma_recv_ctxt *ri_readctxt;
|
2017-06-23 21:18:24 +00:00
|
|
|
unsigned int ri_pageno;
|
|
|
|
unsigned int ri_pageoff;
|
2020-07-17 19:05:51 +00:00
|
|
|
unsigned int ri_totalbytes;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
|
|
|
struct svc_rdma_chunk_ctxt ri_cc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct svc_rdma_read_info *
|
|
|
|
svc_rdma_read_info_alloc(struct svcxprt_rdma *rdma)
|
|
|
|
{
|
|
|
|
struct svc_rdma_read_info *info;
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (!info)
|
|
|
|
return info;
|
|
|
|
|
2017-06-23 21:19:29 +00:00
|
|
|
svc_rdma_cc_init(rdma, &info->ri_cc);
|
2017-06-23 21:18:24 +00:00
|
|
|
info->ri_cc.cc_cqe.done = svc_rdma_wc_read_done;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void svc_rdma_read_info_free(struct svc_rdma_read_info *info)
|
|
|
|
{
|
2017-06-23 21:19:29 +00:00
|
|
|
svc_rdma_cc_release(&info->ri_cc, DMA_FROM_DEVICE);
|
2017-06-23 21:18:24 +00:00
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_wc_read_done - Handle completion of an RDMA Read ctx
|
|
|
|
* @cq: controlling Completion Queue
|
|
|
|
* @wc: Work Completion
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void svc_rdma_wc_read_done(struct ib_cq *cq, struct ib_wc *wc)
|
|
|
|
{
|
|
|
|
struct ib_cqe *cqe = wc->wr_cqe;
|
|
|
|
struct svc_rdma_chunk_ctxt *cc =
|
|
|
|
container_of(cqe, struct svc_rdma_chunk_ctxt, cc_cqe);
|
|
|
|
struct svcxprt_rdma *rdma = cc->cc_rdma;
|
|
|
|
|
2020-04-29 21:25:36 +00:00
|
|
|
trace_svcrdma_wc_read(wc, &cc->cc_cid);
|
2018-05-07 19:27:16 +00:00
|
|
|
|
2021-07-07 18:57:28 +00:00
|
|
|
svc_rdma_wake_send_waiters(rdma, cc->cc_sqecount);
|
2020-12-22 18:22:20 +00:00
|
|
|
cc->cc_status = wc->status;
|
|
|
|
complete(&cc->cc_done);
|
|
|
|
return;
|
2017-06-23 21:18:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
/* This function sleeps when the transport's Send Queue is congested.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - If ib_post_send() succeeds, only one completion is expected,
|
|
|
|
* even if one or more WRs are flushed. This is true when posting
|
|
|
|
* an rdma_rw_ctx or when posting a single signaled WR.
|
|
|
|
*/
|
|
|
|
static int svc_rdma_post_chunk_ctxt(struct svc_rdma_chunk_ctxt *cc)
|
|
|
|
{
|
|
|
|
struct svcxprt_rdma *rdma = cc->cc_rdma;
|
2018-07-18 16:25:32 +00:00
|
|
|
struct ib_send_wr *first_wr;
|
|
|
|
const struct ib_send_wr *bad_wr;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct list_head *tmp;
|
|
|
|
struct ib_cqe *cqe;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-23 21:17:24 +00:00
|
|
|
if (cc->cc_sqecount > rdma->sc_sq_depth)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
first_wr = NULL;
|
|
|
|
cqe = &cc->cc_cqe;
|
|
|
|
list_for_each(tmp, &cc->cc_rwctxts) {
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt;
|
|
|
|
|
|
|
|
ctxt = list_entry(tmp, struct svc_rdma_rw_ctxt, rw_list);
|
|
|
|
first_wr = rdma_rw_ctx_wrs(&ctxt->rw_ctx, rdma->sc_qp,
|
|
|
|
rdma->sc_port_num, cqe, first_wr);
|
|
|
|
cqe = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (atomic_sub_return(cc->cc_sqecount,
|
|
|
|
&rdma->sc_sq_avail) > 0) {
|
2018-07-26 17:36:50 +00:00
|
|
|
ret = ib_post_send(rdma->sc_qp, first_wr, &bad_wr);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-29 20:55:17 +00:00
|
|
|
percpu_counter_inc(&svcrdma_stat_sq_starve);
|
2018-05-07 19:27:16 +00:00
|
|
|
trace_svcrdma_sq_full(rdma);
|
2017-04-09 17:06:16 +00:00
|
|
|
atomic_add(cc->cc_sqecount, &rdma->sc_sq_avail);
|
|
|
|
wait_event(rdma->sc_send_wait,
|
|
|
|
atomic_read(&rdma->sc_sq_avail) > cc->cc_sqecount);
|
2018-05-07 19:27:16 +00:00
|
|
|
trace_svcrdma_sq_retry(rdma);
|
2017-04-09 17:06:16 +00:00
|
|
|
} while (1);
|
|
|
|
|
2020-03-30 18:27:37 +00:00
|
|
|
trace_svcrdma_sq_post_err(rdma, ret);
|
2021-02-20 23:53:40 +00:00
|
|
|
svc_xprt_deferred_close(&rdma->sc_xprt);
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
/* If even one was posted, there will be a completion. */
|
|
|
|
if (bad_wr != first_wr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
atomic_add(cc->cc_sqecount, &rdma->sc_sq_avail);
|
|
|
|
wake_up(&rdma->sc_send_wait);
|
|
|
|
return -ENOTCONN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build and DMA-map an SGL that covers one kvec in an xdr_buf
|
|
|
|
*/
|
|
|
|
static void svc_rdma_vec_to_sg(struct svc_rdma_write_info *info,
|
|
|
|
unsigned int len,
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg = ctxt->rw_sg_table.sgl;
|
|
|
|
|
|
|
|
sg_set_buf(&sg[0], info->wi_base, len);
|
|
|
|
info->wi_base += len;
|
|
|
|
|
|
|
|
ctxt->rw_nents = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build and DMA-map an SGL that covers part of an xdr_buf's pagelist.
|
|
|
|
*/
|
|
|
|
static void svc_rdma_pagelist_to_sg(struct svc_rdma_write_info *info,
|
|
|
|
unsigned int remaining,
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt)
|
|
|
|
{
|
|
|
|
unsigned int sge_no, sge_bytes, page_off, page_no;
|
2020-03-13 14:42:10 +00:00
|
|
|
const struct xdr_buf *xdr = info->wi_xdr;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct scatterlist *sg;
|
|
|
|
struct page **page;
|
|
|
|
|
2017-06-23 21:19:21 +00:00
|
|
|
page_off = info->wi_next_off + xdr->page_base;
|
|
|
|
page_no = page_off >> PAGE_SHIFT;
|
|
|
|
page_off = offset_in_page(page_off);
|
2017-04-09 17:06:16 +00:00
|
|
|
page = xdr->pages + page_no;
|
|
|
|
info->wi_next_off += remaining;
|
|
|
|
sg = ctxt->rw_sg_table.sgl;
|
|
|
|
sge_no = 0;
|
|
|
|
do {
|
|
|
|
sge_bytes = min_t(unsigned int, remaining,
|
|
|
|
PAGE_SIZE - page_off);
|
|
|
|
sg_set_page(sg, *page, sge_bytes, page_off);
|
|
|
|
|
|
|
|
remaining -= sge_bytes;
|
|
|
|
sg = sg_next(sg);
|
|
|
|
page_off = 0;
|
|
|
|
sge_no++;
|
|
|
|
page++;
|
|
|
|
} while (remaining);
|
|
|
|
|
|
|
|
ctxt->rw_nents = sge_no;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct RDMA Write WRs to send a portion of an xdr_buf containing
|
|
|
|
* an RPC Reply.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
svc_rdma_build_writes(struct svc_rdma_write_info *info,
|
|
|
|
void (*constructor)(struct svc_rdma_write_info *info,
|
|
|
|
unsigned int len,
|
|
|
|
struct svc_rdma_rw_ctxt *ctxt),
|
|
|
|
unsigned int remaining)
|
|
|
|
{
|
|
|
|
struct svc_rdma_chunk_ctxt *cc = &info->wi_cc;
|
|
|
|
struct svcxprt_rdma *rdma = cc->cc_rdma;
|
2020-06-17 15:07:00 +00:00
|
|
|
const struct svc_rdma_segment *seg;
|
2017-04-09 17:06:16 +00:00
|
|
|
struct svc_rdma_rw_ctxt *ctxt;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
unsigned int write_len;
|
2020-03-29 20:44:13 +00:00
|
|
|
u64 offset;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2020-06-17 15:07:00 +00:00
|
|
|
seg = &info->wi_chunk->ch_segments[info->wi_seg_no];
|
|
|
|
if (!seg)
|
2017-04-09 17:06:16 +00:00
|
|
|
goto out_overflow;
|
|
|
|
|
2020-06-17 15:07:00 +00:00
|
|
|
write_len = min(remaining, seg->rs_length - info->wi_seg_off);
|
2020-11-12 19:47:14 +00:00
|
|
|
if (!write_len)
|
|
|
|
goto out_overflow;
|
2017-04-09 17:06:16 +00:00
|
|
|
ctxt = svc_rdma_get_rw_ctxt(rdma,
|
|
|
|
(write_len >> PAGE_SHIFT) + 2);
|
|
|
|
if (!ctxt)
|
2020-03-20 18:23:13 +00:00
|
|
|
return -ENOMEM;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
constructor(info, write_len, ctxt);
|
2020-06-17 15:07:00 +00:00
|
|
|
offset = seg->rs_offset + info->wi_seg_off;
|
|
|
|
ret = svc_rdma_rw_ctx_init(rdma, ctxt, offset, seg->rs_handle,
|
2020-03-20 18:02:49 +00:00
|
|
|
DMA_TO_DEVICE);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (ret < 0)
|
2020-03-20 18:02:49 +00:00
|
|
|
return -EIO;
|
2020-12-29 21:09:36 +00:00
|
|
|
percpu_counter_inc(&svcrdma_stat_write);
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
list_add(&ctxt->rw_list, &cc->cc_rwctxts);
|
|
|
|
cc->cc_sqecount += ret;
|
2020-06-17 15:07:00 +00:00
|
|
|
if (write_len == seg->rs_length - info->wi_seg_off) {
|
2017-04-09 17:06:16 +00:00
|
|
|
info->wi_seg_no++;
|
|
|
|
info->wi_seg_off = 0;
|
|
|
|
} else {
|
|
|
|
info->wi_seg_off += write_len;
|
|
|
|
}
|
|
|
|
remaining -= write_len;
|
|
|
|
} while (remaining);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_overflow:
|
2020-03-20 18:36:44 +00:00
|
|
|
trace_svcrdma_small_wrch_err(rdma, remaining, info->wi_seg_no,
|
2020-06-17 15:07:00 +00:00
|
|
|
info->wi_chunk->ch_segcount);
|
2017-04-09 17:06:16 +00:00
|
|
|
return -E2BIG;
|
|
|
|
}
|
|
|
|
|
2020-03-13 14:42:10 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_iov_write - Construct RDMA Writes from an iov
|
|
|
|
* @info: pointer to write arguments
|
|
|
|
* @iov: kvec to write
|
|
|
|
*
|
|
|
|
* Returns:
|
2021-05-31 06:36:40 +00:00
|
|
|
* On success, returns zero
|
2020-03-13 14:42:10 +00:00
|
|
|
* %-E2BIG if the client-provided Write chunk is too small
|
|
|
|
* %-ENOMEM if a resource has been exhausted
|
|
|
|
* %-EIO if an rdma-rw error occurred
|
2017-04-09 17:06:16 +00:00
|
|
|
*/
|
2020-03-13 14:42:10 +00:00
|
|
|
static int svc_rdma_iov_write(struct svc_rdma_write_info *info,
|
|
|
|
const struct kvec *iov)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
2020-03-13 14:42:10 +00:00
|
|
|
info->wi_base = iov->iov_base;
|
2017-04-09 17:06:16 +00:00
|
|
|
return svc_rdma_build_writes(info, svc_rdma_vec_to_sg,
|
2020-03-13 14:42:10 +00:00
|
|
|
iov->iov_len);
|
2017-04-09 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 14:42:10 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_pages_write - Construct RDMA Writes from pages
|
|
|
|
* @info: pointer to write arguments
|
|
|
|
* @xdr: xdr_buf with pages to write
|
|
|
|
* @offset: offset into the content of @xdr
|
|
|
|
* @length: number of bytes to write
|
|
|
|
*
|
|
|
|
* Returns:
|
2021-05-31 06:36:40 +00:00
|
|
|
* On success, returns zero
|
2020-03-13 14:42:10 +00:00
|
|
|
* %-E2BIG if the client-provided Write chunk is too small
|
|
|
|
* %-ENOMEM if a resource has been exhausted
|
|
|
|
* %-EIO if an rdma-rw error occurred
|
2017-04-09 17:06:16 +00:00
|
|
|
*/
|
2020-03-13 14:42:10 +00:00
|
|
|
static int svc_rdma_pages_write(struct svc_rdma_write_info *info,
|
|
|
|
const struct xdr_buf *xdr,
|
|
|
|
unsigned int offset,
|
|
|
|
unsigned long length)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
|
|
|
info->wi_xdr = xdr;
|
2020-03-02 19:45:53 +00:00
|
|
|
info->wi_next_off = offset - xdr->head[0].iov_len;
|
2017-04-09 17:06:16 +00:00
|
|
|
return svc_rdma_build_writes(info, svc_rdma_pagelist_to_sg,
|
2020-03-02 19:45:53 +00:00
|
|
|
length);
|
2017-04-09 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 14:42:10 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_xb_write - Construct RDMA Writes to write an xdr_buf
|
|
|
|
* @xdr: xdr_buf to write
|
2020-03-09 17:29:28 +00:00
|
|
|
* @data: pointer to write arguments
|
2020-03-13 14:42:10 +00:00
|
|
|
*
|
|
|
|
* Returns:
|
2021-05-31 06:36:40 +00:00
|
|
|
* On success, returns zero
|
2020-03-13 14:42:10 +00:00
|
|
|
* %-E2BIG if the client-provided Write chunk is too small
|
|
|
|
* %-ENOMEM if a resource has been exhausted
|
|
|
|
* %-EIO if an rdma-rw error occurred
|
|
|
|
*/
|
2020-03-09 17:29:28 +00:00
|
|
|
static int svc_rdma_xb_write(const struct xdr_buf *xdr, void *data)
|
2020-03-13 14:42:10 +00:00
|
|
|
{
|
2020-03-09 17:29:28 +00:00
|
|
|
struct svc_rdma_write_info *info = data;
|
2020-03-13 14:42:10 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (xdr->head[0].iov_len) {
|
|
|
|
ret = svc_rdma_iov_write(info, &xdr->head[0]);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xdr->page_len) {
|
|
|
|
ret = svc_rdma_pages_write(info, xdr, xdr->head[0].iov_len,
|
|
|
|
xdr->page_len);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xdr->tail[0].iov_len) {
|
|
|
|
ret = svc_rdma_iov_write(info, &xdr->tail[0]);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xdr->len;
|
|
|
|
}
|
|
|
|
|
2017-04-09 17:06:16 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_send_write_chunk - Write all segments in a Write chunk
|
|
|
|
* @rdma: controlling RDMA transport
|
2020-06-17 15:07:00 +00:00
|
|
|
* @chunk: Write chunk provided by the client
|
2017-04-09 17:06:16 +00:00
|
|
|
* @xdr: xdr_buf containing the data payload
|
|
|
|
*
|
|
|
|
* Returns a non-negative number of bytes the chunk consumed, or
|
|
|
|
* %-E2BIG if the payload was larger than the Write chunk,
|
2017-06-23 21:17:24 +00:00
|
|
|
* %-EINVAL if client provided too many segments,
|
2017-04-09 17:06:16 +00:00
|
|
|
* %-ENOMEM if rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN if posting failed (connection is lost),
|
|
|
|
* %-EIO if rdma_rw initialization failed (DMA mapping, etc).
|
|
|
|
*/
|
2020-06-17 15:07:00 +00:00
|
|
|
int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma,
|
|
|
|
const struct svc_rdma_chunk *chunk,
|
2020-03-13 14:42:10 +00:00
|
|
|
const struct xdr_buf *xdr)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
|
|
|
struct svc_rdma_write_info *info;
|
2020-06-11 17:28:28 +00:00
|
|
|
struct svc_rdma_chunk_ctxt *cc;
|
2017-04-09 17:06:16 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-06-17 15:07:00 +00:00
|
|
|
info = svc_rdma_write_info_alloc(rdma, chunk);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
2020-06-11 17:28:28 +00:00
|
|
|
cc = &info->wi_cc;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2020-03-13 14:42:10 +00:00
|
|
|
ret = svc_rdma_xb_write(xdr, info);
|
|
|
|
if (ret != xdr->len)
|
2017-04-09 17:06:16 +00:00
|
|
|
goto out_err;
|
|
|
|
|
2020-06-11 17:28:28 +00:00
|
|
|
trace_svcrdma_post_write_chunk(&cc->cc_cid, cc->cc_sqecount);
|
|
|
|
ret = svc_rdma_post_chunk_ctxt(cc);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out_err;
|
2020-03-13 14:42:10 +00:00
|
|
|
return xdr->len;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
out_err:
|
|
|
|
svc_rdma_write_info_free(info);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_send_reply_chunk - Write all segments in the Reply chunk
|
|
|
|
* @rdma: controlling RDMA transport
|
2020-03-02 20:02:19 +00:00
|
|
|
* @rctxt: Write and Reply chunks from client
|
2017-04-09 17:06:16 +00:00
|
|
|
* @xdr: xdr_buf containing an RPC Reply
|
|
|
|
*
|
|
|
|
* Returns a non-negative number of bytes the chunk consumed, or
|
|
|
|
* %-E2BIG if the payload was larger than the Reply chunk,
|
2017-06-23 21:17:24 +00:00
|
|
|
* %-EINVAL if client provided too many segments,
|
2017-04-09 17:06:16 +00:00
|
|
|
* %-ENOMEM if rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN if posting failed (connection is lost),
|
|
|
|
* %-EIO if rdma_rw initialization failed (DMA mapping, etc).
|
|
|
|
*/
|
2020-03-02 20:02:19 +00:00
|
|
|
int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,
|
|
|
|
const struct svc_rdma_recv_ctxt *rctxt,
|
2020-03-09 17:29:28 +00:00
|
|
|
const struct xdr_buf *xdr)
|
2017-04-09 17:06:16 +00:00
|
|
|
{
|
|
|
|
struct svc_rdma_write_info *info;
|
2020-06-11 17:28:28 +00:00
|
|
|
struct svc_rdma_chunk_ctxt *cc;
|
2020-06-17 15:07:00 +00:00
|
|
|
struct svc_rdma_chunk *chunk;
|
2020-03-09 17:29:28 +00:00
|
|
|
int ret;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2020-06-17 15:07:00 +00:00
|
|
|
if (pcl_is_empty(&rctxt->rc_reply_pcl))
|
2020-03-13 14:42:10 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-06-17 15:07:00 +00:00
|
|
|
chunk = pcl_first_chunk(&rctxt->rc_reply_pcl);
|
|
|
|
info = svc_rdma_write_info_alloc(rdma, chunk);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
2020-06-11 17:28:28 +00:00
|
|
|
cc = &info->wi_cc;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
2020-03-09 17:29:28 +00:00
|
|
|
ret = pcl_process_nonpayloads(&rctxt->rc_write_pcl, xdr,
|
|
|
|
svc_rdma_xb_write, info);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out_err;
|
|
|
|
|
2020-06-11 17:28:28 +00:00
|
|
|
trace_svcrdma_post_reply_chunk(&cc->cc_cid, cc->cc_sqecount);
|
|
|
|
ret = svc_rdma_post_chunk_ctxt(cc);
|
2017-04-09 17:06:16 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out_err;
|
2018-05-07 19:27:11 +00:00
|
|
|
|
2020-03-09 17:29:28 +00:00
|
|
|
return xdr->len;
|
2017-04-09 17:06:16 +00:00
|
|
|
|
|
|
|
out_err:
|
|
|
|
svc_rdma_write_info_free(info);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-06-23 21:18:24 +00:00
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_build_read_segment - Build RDMA Read WQEs to pull one RDMA segment
|
|
|
|
* @info: context for ongoing I/O
|
|
|
|
* @segment: co-ordinates of remote memory to be read
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* %0: the Read WR chain was constructed successfully
|
|
|
|
* %-EINVAL: there were not enough rq_pages to finish
|
|
|
|
* %-ENOMEM: allocating a local resources failed
|
|
|
|
* %-EIO: a DMA mapping error occurred
|
|
|
|
*/
|
2017-06-23 21:18:24 +00:00
|
|
|
static int svc_rdma_build_read_segment(struct svc_rdma_read_info *info,
|
2020-09-17 17:04:17 +00:00
|
|
|
const struct svc_rdma_segment *segment)
|
2017-06-23 21:18:24 +00:00
|
|
|
{
|
2018-05-07 19:27:21 +00:00
|
|
|
struct svc_rdma_recv_ctxt *head = info->ri_readctxt;
|
2017-06-23 21:18:24 +00:00
|
|
|
struct svc_rdma_chunk_ctxt *cc = &info->ri_cc;
|
2020-09-17 17:04:17 +00:00
|
|
|
struct svc_rqst *rqstp = info->ri_rqst;
|
|
|
|
unsigned int sge_no, seg_len, len;
|
2020-12-22 18:22:20 +00:00
|
|
|
struct svc_rdma_rw_ctxt *ctxt;
|
2017-06-23 21:18:24 +00:00
|
|
|
struct scatterlist *sg;
|
|
|
|
int ret;
|
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
len = segment->rs_length;
|
2017-06-23 21:18:24 +00:00
|
|
|
sge_no = PAGE_ALIGN(info->ri_pageoff + len) >> PAGE_SHIFT;
|
|
|
|
ctxt = svc_rdma_get_rw_ctxt(cc->cc_rdma, sge_no);
|
|
|
|
if (!ctxt)
|
2020-03-20 18:23:13 +00:00
|
|
|
return -ENOMEM;
|
2017-06-23 21:18:24 +00:00
|
|
|
ctxt->rw_nents = sge_no;
|
|
|
|
|
|
|
|
sg = ctxt->rw_sg_table.sgl;
|
|
|
|
for (sge_no = 0; sge_no < ctxt->rw_nents; sge_no++) {
|
|
|
|
seg_len = min_t(unsigned int, len,
|
|
|
|
PAGE_SIZE - info->ri_pageoff);
|
|
|
|
|
|
|
|
if (!info->ri_pageoff)
|
2018-05-07 19:27:21 +00:00
|
|
|
head->rc_page_count++;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
|
|
|
sg_set_page(sg, rqstp->rq_pages[info->ri_pageno],
|
|
|
|
seg_len, info->ri_pageoff);
|
|
|
|
sg = sg_next(sg);
|
|
|
|
|
|
|
|
info->ri_pageoff += seg_len;
|
|
|
|
if (info->ri_pageoff == PAGE_SIZE) {
|
|
|
|
info->ri_pageno++;
|
|
|
|
info->ri_pageoff = 0;
|
|
|
|
}
|
|
|
|
len -= seg_len;
|
|
|
|
|
|
|
|
/* Safety check */
|
|
|
|
if (len &&
|
|
|
|
&rqstp->rq_pages[info->ri_pageno + 1] > rqstp->rq_page_end)
|
|
|
|
goto out_overrun;
|
|
|
|
}
|
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
ret = svc_rdma_rw_ctx_init(cc->cc_rdma, ctxt, segment->rs_offset,
|
|
|
|
segment->rs_handle, DMA_FROM_DEVICE);
|
2017-06-23 21:18:24 +00:00
|
|
|
if (ret < 0)
|
2020-03-20 18:02:49 +00:00
|
|
|
return -EIO;
|
2020-12-29 21:09:36 +00:00
|
|
|
percpu_counter_inc(&svcrdma_stat_read);
|
2017-06-23 21:18:24 +00:00
|
|
|
|
|
|
|
list_add(&ctxt->rw_list, &cc->cc_rwctxts);
|
|
|
|
cc->cc_sqecount += ret;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_overrun:
|
2020-03-20 18:33:05 +00:00
|
|
|
trace_svcrdma_page_overrun_err(cc->cc_rdma, rqstp, info->ri_pageno);
|
2017-06-23 21:18:24 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_build_read_chunk - Build RDMA Read WQEs to pull one RDMA chunk
|
|
|
|
* @info: context for ongoing I/O
|
|
|
|
* @chunk: Read chunk to pull
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: the Read WR chain was constructed successfully
|
|
|
|
* %-EINVAL: there were not enough resources to finish
|
|
|
|
* %-ENOMEM: allocating a local resources failed
|
|
|
|
* %-EIO: a DMA mapping error occurred
|
2017-08-01 16:00:14 +00:00
|
|
|
*/
|
2020-09-17 17:04:17 +00:00
|
|
|
static int svc_rdma_build_read_chunk(struct svc_rdma_read_info *info,
|
|
|
|
const struct svc_rdma_chunk *chunk)
|
2017-06-23 21:18:24 +00:00
|
|
|
{
|
2020-09-17 17:04:17 +00:00
|
|
|
const struct svc_rdma_segment *segment;
|
2017-06-23 21:18:24 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-08-01 16:00:14 +00:00
|
|
|
ret = -EINVAL;
|
2020-09-17 17:04:17 +00:00
|
|
|
pcl_for_each_segment(segment, chunk) {
|
|
|
|
ret = svc_rdma_build_read_segment(info, segment);
|
2017-06-23 21:18:24 +00:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
2020-09-17 17:04:17 +00:00
|
|
|
info->ri_totalbytes += segment->rs_length;
|
2017-06-23 21:18:24 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
/**
|
2020-08-05 18:59:05 +00:00
|
|
|
* svc_rdma_copy_inline_range - Copy part of the inline content into pages
|
|
|
|
* @info: context for RDMA Reads
|
|
|
|
* @offset: offset into the Receive buffer of region to copy
|
|
|
|
* @remaining: length of region to copy
|
|
|
|
*
|
|
|
|
* Take a page at a time from rqstp->rq_pages and copy the inline
|
|
|
|
* content from the Receive buffer into that page. Update
|
|
|
|
* info->ri_pageno and info->ri_pageoff so that the next RDMA Read
|
|
|
|
* result will land contiguously with the copied content.
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: Inline content was successfully copied
|
|
|
|
* %-EINVAL: offset or length was incorrect
|
|
|
|
*/
|
|
|
|
static int svc_rdma_copy_inline_range(struct svc_rdma_read_info *info,
|
|
|
|
unsigned int offset,
|
|
|
|
unsigned int remaining)
|
|
|
|
{
|
|
|
|
struct svc_rdma_recv_ctxt *head = info->ri_readctxt;
|
|
|
|
unsigned char *dst, *src = head->rc_recv_buf;
|
|
|
|
struct svc_rqst *rqstp = info->ri_rqst;
|
|
|
|
unsigned int page_no, numpages;
|
|
|
|
|
|
|
|
numpages = PAGE_ALIGN(info->ri_pageoff + remaining) >> PAGE_SHIFT;
|
|
|
|
for (page_no = 0; page_no < numpages; page_no++) {
|
|
|
|
unsigned int page_len;
|
|
|
|
|
|
|
|
page_len = min_t(unsigned int, remaining,
|
|
|
|
PAGE_SIZE - info->ri_pageoff);
|
|
|
|
|
|
|
|
if (!info->ri_pageoff)
|
|
|
|
head->rc_page_count++;
|
|
|
|
|
2020-12-22 18:22:20 +00:00
|
|
|
dst = page_address(rqstp->rq_pages[info->ri_pageno]);
|
2020-08-05 18:59:05 +00:00
|
|
|
memcpy(dst + info->ri_pageno, src + offset, page_len);
|
|
|
|
|
|
|
|
info->ri_totalbytes += page_len;
|
|
|
|
info->ri_pageoff += page_len;
|
|
|
|
if (info->ri_pageoff == PAGE_SIZE) {
|
|
|
|
info->ri_pageno++;
|
|
|
|
info->ri_pageoff = 0;
|
|
|
|
}
|
|
|
|
remaining -= page_len;
|
|
|
|
offset += page_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_read_multiple_chunks - Construct RDMA Reads to pull data item Read chunks
|
|
|
|
* @info: context for RDMA Reads
|
|
|
|
*
|
2020-12-22 18:22:20 +00:00
|
|
|
* The chunk data lands in rqstp->rq_arg as a series of contiguous pages,
|
2020-08-05 18:59:05 +00:00
|
|
|
* like an incoming TCP call.
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: RDMA Read WQEs were successfully built
|
|
|
|
* %-EINVAL: client provided too many chunks or segments,
|
|
|
|
* %-ENOMEM: rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN: posting failed (connection is lost),
|
|
|
|
* %-EIO: rdma_rw initialization failed (DMA mapping, etc).
|
|
|
|
*/
|
|
|
|
static noinline int svc_rdma_read_multiple_chunks(struct svc_rdma_read_info *info)
|
|
|
|
{
|
|
|
|
struct svc_rdma_recv_ctxt *head = info->ri_readctxt;
|
|
|
|
const struct svc_rdma_pcl *pcl = &head->rc_read_pcl;
|
2020-12-22 18:22:20 +00:00
|
|
|
struct xdr_buf *buf = &info->ri_rqst->rq_arg;
|
2020-08-05 18:59:05 +00:00
|
|
|
struct svc_rdma_chunk *chunk, *next;
|
|
|
|
unsigned int start, length;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
chunk = pcl_first_chunk(pcl);
|
|
|
|
length = chunk->ch_position;
|
|
|
|
ret = svc_rdma_copy_inline_range(info, start, length);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pcl_for_each_chunk(chunk, pcl) {
|
|
|
|
ret = svc_rdma_build_read_chunk(info, chunk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
next = pcl_next_chunk(pcl, chunk);
|
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
|
|
|
|
start += length;
|
|
|
|
length = next->ch_position - info->ri_totalbytes;
|
|
|
|
ret = svc_rdma_copy_inline_range(info, start, length);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
start += length;
|
|
|
|
length = head->rc_byte_len - start;
|
|
|
|
ret = svc_rdma_copy_inline_range(info, start, length);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
buf->len += info->ri_totalbytes;
|
|
|
|
buf->buflen += info->ri_totalbytes;
|
|
|
|
|
2020-12-22 18:22:20 +00:00
|
|
|
buf->head[0].iov_base = page_address(info->ri_rqst->rq_pages[0]);
|
2020-08-05 18:59:05 +00:00
|
|
|
buf->head[0].iov_len = min_t(size_t, PAGE_SIZE, info->ri_totalbytes);
|
2020-12-22 18:22:20 +00:00
|
|
|
buf->pages = &info->ri_rqst->rq_pages[1];
|
2020-08-05 18:59:05 +00:00
|
|
|
buf->page_len = info->ri_totalbytes - buf->head[0].iov_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_read_data_item - Construct RDMA Reads to pull data item Read chunks
|
2020-09-17 17:04:17 +00:00
|
|
|
* @info: context for RDMA Reads
|
|
|
|
*
|
2020-12-22 18:22:20 +00:00
|
|
|
* The chunk data lands in the page list of rqstp->rq_arg.pages.
|
2017-06-23 21:18:24 +00:00
|
|
|
*
|
2020-12-22 18:22:20 +00:00
|
|
|
* Currently NFSD does not look at the rqstp->rq_arg.tail[0] kvec.
|
2017-06-23 21:18:24 +00:00
|
|
|
* Therefore, XDR round-up of the Read chunk and trailing
|
|
|
|
* inline content must both be added at the end of the pagelist.
|
2020-09-17 17:04:17 +00:00
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: RDMA Read WQEs were successfully built
|
|
|
|
* %-EINVAL: client provided too many chunks or segments,
|
|
|
|
* %-ENOMEM: rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN: posting failed (connection is lost),
|
|
|
|
* %-EIO: rdma_rw initialization failed (DMA mapping, etc).
|
2017-06-23 21:18:24 +00:00
|
|
|
*/
|
2020-08-05 18:59:05 +00:00
|
|
|
static int svc_rdma_read_data_item(struct svc_rdma_read_info *info)
|
2017-06-23 21:18:24 +00:00
|
|
|
{
|
2018-05-07 19:27:21 +00:00
|
|
|
struct svc_rdma_recv_ctxt *head = info->ri_readctxt;
|
2020-12-22 18:22:20 +00:00
|
|
|
struct xdr_buf *buf = &info->ri_rqst->rq_arg;
|
2020-09-17 17:04:17 +00:00
|
|
|
struct svc_rdma_chunk *chunk;
|
2020-07-17 19:05:51 +00:00
|
|
|
unsigned int length;
|
2017-06-23 21:18:24 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
chunk = pcl_first_chunk(&head->rc_read_pcl);
|
|
|
|
ret = svc_rdma_build_read_chunk(info, chunk);
|
2017-06-23 21:18:24 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2017-08-18 15:12:35 +00:00
|
|
|
/* Split the Receive buffer between the head and tail
|
|
|
|
* buffers at Read chunk's position. XDR roundup of the
|
|
|
|
* chunk is not included in either the pagelist or in
|
|
|
|
* the tail.
|
2017-06-23 21:18:24 +00:00
|
|
|
*/
|
2020-09-17 17:04:17 +00:00
|
|
|
buf->tail[0].iov_base = buf->head[0].iov_base + chunk->ch_position;
|
|
|
|
buf->tail[0].iov_len = buf->head[0].iov_len - chunk->ch_position;
|
|
|
|
buf->head[0].iov_len = chunk->ch_position;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
svcrdma: Fix Read chunk round-up
A single NFSv4 WRITE compound can often have three operations:
PUTFH, WRITE, then GETATTR.
When the WRITE payload is sent in a Read chunk, the client places
the GETATTR in the inline part of the RPC/RDMA message, just after
the WRITE operation (sans payload). The position value in the Read
chunk enables the receiver to insert the Read chunk at the correct
place in the received XDR stream; that is between the WRITE and
GETATTR.
According to RFC 8166, an NFS/RDMA client does not have to add XDR
round-up to the Read chunk that carries the WRITE payload. The
receiver adds XDR round-up padding if it is absent and the
receiver's XDR decoder requires it to be present.
Commit 193bcb7b3719 ("svcrdma: Populate tail iovec when receiving")
attempted to add support for receiving such a compound so that just
the WRITE payload appears in rq_arg's page list, and the trailing
GETATTR is placed in rq_arg's tail iovec. (TCP just strings the
whole compound into the head iovec and page list, without regard
to the alignment of the WRITE payload).
The server transport logic also had to accommodate the optional XDR
round-up of the Read chunk, which it did simply by lengthening the
tail iovec when round-up was needed. This approach is adequate for
the NFSv2 and NFSv3 WRITE decoders.
Unfortunately it is not sufficient for nfsd4_decode_write. When the
Read chunk length is a couple of bytes less than PAGE_SIZE, the
computation at the end of nfsd4_decode_write allows argp->pagelen to
go negative, which breaks the logic in read_buf that looks for the
tail iovec.
The result is that a WRITE operation whose payload length is just
less than a multiple of a page succeeds, but the subsequent GETATTR
in the same compound fails with NFS4ERR_OP_ILLEGAL because the XDR
decoder can't find it. Clients ignore the error, but they must
update their attribute cache via a separate round trip.
As nfsd4_decode_write appears to expect the payload itself to always
have appropriate XDR round-up, have svc_rdma_build_normal_read_chunk
add the Read chunk XDR round-up to the page_len rather than
lengthening the tail iovec.
Reported-by: Olga Kornievskaia <kolga@netapp.com>
Fixes: 193bcb7b3719 ("svcrdma: Populate tail iovec when receiving")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: Olga Kornievskaia <kolga@netapp.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2018-02-02 19:28:59 +00:00
|
|
|
/* Read chunk may need XDR roundup (see RFC 8166, s. 3.4.5.2).
|
2017-08-18 15:12:35 +00:00
|
|
|
*
|
svcrdma: Fix Read chunk round-up
A single NFSv4 WRITE compound can often have three operations:
PUTFH, WRITE, then GETATTR.
When the WRITE payload is sent in a Read chunk, the client places
the GETATTR in the inline part of the RPC/RDMA message, just after
the WRITE operation (sans payload). The position value in the Read
chunk enables the receiver to insert the Read chunk at the correct
place in the received XDR stream; that is between the WRITE and
GETATTR.
According to RFC 8166, an NFS/RDMA client does not have to add XDR
round-up to the Read chunk that carries the WRITE payload. The
receiver adds XDR round-up padding if it is absent and the
receiver's XDR decoder requires it to be present.
Commit 193bcb7b3719 ("svcrdma: Populate tail iovec when receiving")
attempted to add support for receiving such a compound so that just
the WRITE payload appears in rq_arg's page list, and the trailing
GETATTR is placed in rq_arg's tail iovec. (TCP just strings the
whole compound into the head iovec and page list, without regard
to the alignment of the WRITE payload).
The server transport logic also had to accommodate the optional XDR
round-up of the Read chunk, which it did simply by lengthening the
tail iovec when round-up was needed. This approach is adequate for
the NFSv2 and NFSv3 WRITE decoders.
Unfortunately it is not sufficient for nfsd4_decode_write. When the
Read chunk length is a couple of bytes less than PAGE_SIZE, the
computation at the end of nfsd4_decode_write allows argp->pagelen to
go negative, which breaks the logic in read_buf that looks for the
tail iovec.
The result is that a WRITE operation whose payload length is just
less than a multiple of a page succeeds, but the subsequent GETATTR
in the same compound fails with NFS4ERR_OP_ILLEGAL because the XDR
decoder can't find it. Clients ignore the error, but they must
update their attribute cache via a separate round trip.
As nfsd4_decode_write appears to expect the payload itself to always
have appropriate XDR round-up, have svc_rdma_build_normal_read_chunk
add the Read chunk XDR round-up to the page_len rather than
lengthening the tail iovec.
Reported-by: Olga Kornievskaia <kolga@netapp.com>
Fixes: 193bcb7b3719 ("svcrdma: Populate tail iovec when receiving")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: Olga Kornievskaia <kolga@netapp.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2018-02-02 19:28:59 +00:00
|
|
|
* If the client already rounded up the chunk length, the
|
|
|
|
* length does not change. Otherwise, the length of the page
|
|
|
|
* list is increased to include XDR round-up.
|
|
|
|
*
|
|
|
|
* Currently these chunks always start at page offset 0,
|
|
|
|
* thus the rounded-up length never crosses a page boundary.
|
2017-08-18 15:12:35 +00:00
|
|
|
*/
|
2020-12-22 18:22:20 +00:00
|
|
|
buf->pages = &info->ri_rqst->rq_pages[0];
|
|
|
|
length = xdr_align_size(chunk->ch_length);
|
2020-07-17 19:05:51 +00:00
|
|
|
buf->page_len = length;
|
|
|
|
buf->len += length;
|
|
|
|
buf->buflen += length;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-08-05 18:59:05 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_read_chunk_range - Build RDMA Read WQEs for portion of a chunk
|
|
|
|
* @info: context for RDMA Reads
|
|
|
|
* @chunk: parsed Call chunk to pull
|
|
|
|
* @offset: offset of region to pull
|
|
|
|
* @length: length of region to pull
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: RDMA Read WQEs were successfully built
|
|
|
|
* %-EINVAL: there were not enough resources to finish
|
|
|
|
* %-ENOMEM: rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN: posting failed (connection is lost),
|
|
|
|
* %-EIO: rdma_rw initialization failed (DMA mapping, etc).
|
|
|
|
*/
|
|
|
|
static int svc_rdma_read_chunk_range(struct svc_rdma_read_info *info,
|
|
|
|
const struct svc_rdma_chunk *chunk,
|
|
|
|
unsigned int offset, unsigned int length)
|
|
|
|
{
|
|
|
|
const struct svc_rdma_segment *segment;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
pcl_for_each_segment(segment, chunk) {
|
|
|
|
struct svc_rdma_segment dummy;
|
|
|
|
|
|
|
|
if (offset > segment->rs_length) {
|
|
|
|
offset -= segment->rs_length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dummy.rs_handle = segment->rs_handle;
|
|
|
|
dummy.rs_length = min_t(u32, length, segment->rs_length) - offset;
|
|
|
|
dummy.rs_offset = segment->rs_offset + offset;
|
|
|
|
|
|
|
|
ret = svc_rdma_build_read_segment(info, &dummy);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
info->ri_totalbytes += dummy.rs_length;
|
|
|
|
length -= dummy.rs_length;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* svc_rdma_read_call_chunk - Build RDMA Read WQEs to pull a Long Message
|
|
|
|
* @info: context for RDMA Reads
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: RDMA Read WQEs were successfully built
|
|
|
|
* %-EINVAL: there were not enough resources to finish
|
|
|
|
* %-ENOMEM: rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN: posting failed (connection is lost),
|
|
|
|
* %-EIO: rdma_rw initialization failed (DMA mapping, etc).
|
|
|
|
*/
|
|
|
|
static int svc_rdma_read_call_chunk(struct svc_rdma_read_info *info)
|
|
|
|
{
|
|
|
|
struct svc_rdma_recv_ctxt *head = info->ri_readctxt;
|
|
|
|
const struct svc_rdma_chunk *call_chunk =
|
|
|
|
pcl_first_chunk(&head->rc_call_pcl);
|
|
|
|
const struct svc_rdma_pcl *pcl = &head->rc_read_pcl;
|
|
|
|
struct svc_rdma_chunk *chunk, *next;
|
|
|
|
unsigned int start, length;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (pcl_is_empty(pcl))
|
|
|
|
return svc_rdma_build_read_chunk(info, call_chunk);
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
chunk = pcl_first_chunk(pcl);
|
|
|
|
length = chunk->ch_position;
|
|
|
|
ret = svc_rdma_read_chunk_range(info, call_chunk, start, length);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pcl_for_each_chunk(chunk, pcl) {
|
|
|
|
ret = svc_rdma_build_read_chunk(info, chunk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
next = pcl_next_chunk(pcl, chunk);
|
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
|
|
|
|
start += length;
|
|
|
|
length = next->ch_position - info->ri_totalbytes;
|
|
|
|
ret = svc_rdma_read_chunk_range(info, call_chunk,
|
|
|
|
start, length);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
start += length;
|
|
|
|
length = call_chunk->ch_length - start;
|
|
|
|
return svc_rdma_read_chunk_range(info, call_chunk, start, length);
|
|
|
|
}
|
|
|
|
|
2020-09-17 17:04:17 +00:00
|
|
|
/**
|
|
|
|
* svc_rdma_read_special - Build RDMA Read WQEs to pull a Long Message
|
|
|
|
* @info: context for RDMA Reads
|
|
|
|
*
|
|
|
|
* The start of the data lands in the first page just after the
|
2020-12-22 18:22:20 +00:00
|
|
|
* Transport header, and the rest lands in rqstp->rq_arg.pages.
|
2017-06-23 21:18:24 +00:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2020-09-17 17:04:17 +00:00
|
|
|
* - A PZRC is never sent in an RDMA_MSG message, though it's
|
|
|
|
* allowed by spec.
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %0: RDMA Read WQEs were successfully built
|
|
|
|
* %-EINVAL: client provided too many chunks or segments,
|
|
|
|
* %-ENOMEM: rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN: posting failed (connection is lost),
|
|
|
|
* %-EIO: rdma_rw initialization failed (DMA mapping, etc).
|
2017-06-23 21:18:24 +00:00
|
|
|
*/
|
2020-08-05 18:59:05 +00:00
|
|
|
static noinline int svc_rdma_read_special(struct svc_rdma_read_info *info)
|
2017-06-23 21:18:24 +00:00
|
|
|
{
|
2020-12-22 18:22:20 +00:00
|
|
|
struct xdr_buf *buf = &info->ri_rqst->rq_arg;
|
2017-06-23 21:18:24 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-08-05 18:59:05 +00:00
|
|
|
ret = svc_rdma_read_call_chunk(info);
|
2017-06-23 21:18:24 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2020-07-17 19:05:51 +00:00
|
|
|
buf->len += info->ri_totalbytes;
|
|
|
|
buf->buflen += info->ri_totalbytes;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
2020-12-22 18:22:20 +00:00
|
|
|
buf->head[0].iov_base = page_address(info->ri_rqst->rq_pages[0]);
|
2020-07-17 19:05:51 +00:00
|
|
|
buf->head[0].iov_len = min_t(size_t, PAGE_SIZE, info->ri_totalbytes);
|
2020-12-22 18:22:20 +00:00
|
|
|
buf->pages = &info->ri_rqst->rq_pages[1];
|
2020-07-17 19:05:51 +00:00
|
|
|
buf->page_len = info->ri_totalbytes - buf->head[0].iov_len;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-17 17:04:17 +00:00
|
|
|
* svc_rdma_process_read_list - Pull list of Read chunks from the client
|
2017-06-23 21:18:24 +00:00
|
|
|
* @rdma: controlling RDMA transport
|
|
|
|
* @rqstp: set of pages to use as Read sink buffers
|
|
|
|
* @head: pages under I/O collect here
|
|
|
|
*
|
2020-09-17 17:04:17 +00:00
|
|
|
* The RPC/RDMA protocol assumes that the upper layer's XDR decoders
|
|
|
|
* pull each Read chunk as they decode an incoming RPC message.
|
2017-06-23 21:18:24 +00:00
|
|
|
*
|
2020-09-17 17:04:17 +00:00
|
|
|
* On Linux, however, the server needs to have a fully-constructed RPC
|
|
|
|
* message in rqstp->rq_arg when there is a positive return code from
|
|
|
|
* ->xpo_recvfrom. So the Read list is safety-checked immediately when
|
|
|
|
* it is received, then here the whole Read list is pulled all at once.
|
|
|
|
* The ingress RPC message is fully reconstructed once all associated
|
|
|
|
* RDMA Reads have completed.
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* %1: all needed RDMA Reads were posted successfully,
|
|
|
|
* %-EINVAL: client provided too many chunks or segments,
|
|
|
|
* %-ENOMEM: rdma_rw context pool was exhausted,
|
|
|
|
* %-ENOTCONN: posting failed (connection is lost),
|
|
|
|
* %-EIO: rdma_rw initialization failed (DMA mapping, etc).
|
2017-06-23 21:18:24 +00:00
|
|
|
*/
|
2020-09-17 17:04:17 +00:00
|
|
|
int svc_rdma_process_read_list(struct svcxprt_rdma *rdma,
|
|
|
|
struct svc_rqst *rqstp,
|
|
|
|
struct svc_rdma_recv_ctxt *head)
|
2017-06-23 21:18:24 +00:00
|
|
|
{
|
|
|
|
struct svc_rdma_read_info *info;
|
2020-06-11 17:28:28 +00:00
|
|
|
struct svc_rdma_chunk_ctxt *cc;
|
2017-06-23 21:18:24 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
info = svc_rdma_read_info_alloc(rdma);
|
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
2020-06-11 17:28:28 +00:00
|
|
|
cc = &info->ri_cc;
|
2020-09-17 17:04:17 +00:00
|
|
|
info->ri_rqst = rqstp;
|
2017-06-23 21:18:24 +00:00
|
|
|
info->ri_readctxt = head;
|
2018-05-07 19:27:43 +00:00
|
|
|
info->ri_pageno = 0;
|
|
|
|
info->ri_pageoff = 0;
|
2020-07-17 19:05:51 +00:00
|
|
|
info->ri_totalbytes = 0;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
2020-08-05 18:59:05 +00:00
|
|
|
if (pcl_is_empty(&head->rc_call_pcl)) {
|
|
|
|
if (head->rc_read_pcl.cl_count == 1)
|
|
|
|
ret = svc_rdma_read_data_item(info);
|
|
|
|
else
|
|
|
|
ret = svc_rdma_read_multiple_chunks(info);
|
|
|
|
} else
|
2020-09-17 17:04:17 +00:00
|
|
|
ret = svc_rdma_read_special(info);
|
2017-06-23 21:18:24 +00:00
|
|
|
if (ret < 0)
|
2018-07-27 15:18:59 +00:00
|
|
|
goto out_err;
|
2017-06-23 21:18:24 +00:00
|
|
|
|
2020-06-11 17:28:28 +00:00
|
|
|
trace_svcrdma_post_read_chunk(&cc->cc_cid, cc->cc_sqecount);
|
2020-12-22 18:22:20 +00:00
|
|
|
init_completion(&cc->cc_done);
|
2020-06-11 17:28:28 +00:00
|
|
|
ret = svc_rdma_post_chunk_ctxt(cc);
|
2017-06-23 21:18:24 +00:00
|
|
|
if (ret < 0)
|
2018-07-27 15:18:59 +00:00
|
|
|
goto out_err;
|
2020-12-22 18:22:20 +00:00
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
wait_for_completion(&cc->cc_done);
|
|
|
|
if (cc->cc_status != IB_WC_SUCCESS)
|
|
|
|
ret = -EIO;
|
|
|
|
|
|
|
|
/* rq_respages starts after the last arg page */
|
|
|
|
rqstp->rq_respages = &rqstp->rq_pages[head->rc_page_count];
|
|
|
|
rqstp->rq_next_page = rqstp->rq_respages + 1;
|
|
|
|
|
|
|
|
/* Ensure svc_rdma_recv_ctxt_put() does not try to release pages */
|
|
|
|
head->rc_page_count = 0;
|
2018-07-27 15:18:59 +00:00
|
|
|
|
|
|
|
out_err:
|
|
|
|
svc_rdma_read_info_free(info);
|
2017-06-23 21:18:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|