2009-02-24 23:30:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-15 23:47:34 +08:00
|
|
|
#include <linux/export.h>
|
2018-02-16 02:49:35 +08:00
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/errqueue.h>
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
#include "rds.h"
|
|
|
|
|
|
|
|
static unsigned int rds_exthdr_size[__RDS_EXTHDR_MAX] = {
|
|
|
|
[RDS_EXTHDR_NONE] = 0,
|
|
|
|
[RDS_EXTHDR_VERSION] = sizeof(struct rds_ext_header_version),
|
|
|
|
[RDS_EXTHDR_RDMA] = sizeof(struct rds_ext_header_rdma),
|
|
|
|
[RDS_EXTHDR_RDMA_DEST] = sizeof(struct rds_ext_header_rdma_dest),
|
2016-07-14 18:51:03 +08:00
|
|
|
[RDS_EXTHDR_NPATHS] = sizeof(u16),
|
2016-11-17 05:29:49 +08:00
|
|
|
[RDS_EXTHDR_GEN_NUM] = sizeof(u32),
|
2009-02-24 23:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void rds_message_addref(struct rds_message *rm)
|
|
|
|
{
|
2017-07-04 20:53:18 +08:00
|
|
|
rdsdebug("addref rm %p ref %d\n", rm, refcount_read(&rm->m_refcount));
|
|
|
|
refcount_inc(&rm->m_refcount);
|
2009-02-24 23:30:26 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_message_addref);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2018-03-06 23:22:34 +08:00
|
|
|
static inline bool rds_zcookie_add(struct rds_msg_zcopy_info *info, u32 cookie)
|
2018-02-16 02:49:35 +08:00
|
|
|
{
|
2018-03-06 23:22:34 +08:00
|
|
|
struct rds_zcopy_cookies *ck = &info->zcookies;
|
2018-02-28 01:52:43 +08:00
|
|
|
int ncookies = ck->num;
|
2018-02-16 02:49:35 +08:00
|
|
|
|
2018-02-28 01:52:43 +08:00
|
|
|
if (ncookies == RDS_MAX_ZCOOKIES)
|
2018-02-16 02:49:35 +08:00
|
|
|
return false;
|
2018-02-28 01:52:43 +08:00
|
|
|
ck->cookies[ncookies] = cookie;
|
|
|
|
ck->num = ++ncookies;
|
2018-02-16 02:49:35 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-08 19:37:30 +08:00
|
|
|
static struct rds_msg_zcopy_info *rds_info_from_znotifier(struct rds_znotifier *znotif)
|
2018-03-06 23:22:34 +08:00
|
|
|
{
|
|
|
|
return container_of(znotif, struct rds_msg_zcopy_info, znotif);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_notify_msg_zcopy_purge(struct rds_msg_zcopy_queue *q)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
LIST_HEAD(copy);
|
|
|
|
struct rds_msg_zcopy_info *info, *tmp;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&q->lock, flags);
|
|
|
|
list_splice(&q->zcookie_head, ©);
|
|
|
|
INIT_LIST_HEAD(&q->zcookie_head);
|
|
|
|
spin_unlock_irqrestore(&q->lock, flags);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(info, tmp, ©, rs_zcookie_next) {
|
|
|
|
list_del(&info->rs_zcookie_next);
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:49:35 +08:00
|
|
|
static void rds_rm_zerocopy_callback(struct rds_sock *rs,
|
|
|
|
struct rds_znotifier *znotif)
|
|
|
|
{
|
2018-03-06 23:22:34 +08:00
|
|
|
struct rds_msg_zcopy_info *info;
|
|
|
|
struct rds_msg_zcopy_queue *q;
|
2018-02-16 02:49:35 +08:00
|
|
|
u32 cookie = znotif->z_cookie;
|
2018-02-28 01:52:43 +08:00
|
|
|
struct rds_zcopy_cookies *ck;
|
2018-03-06 23:22:34 +08:00
|
|
|
struct list_head *head;
|
|
|
|
unsigned long flags;
|
2018-02-16 02:49:35 +08:00
|
|
|
|
2018-03-06 23:22:34 +08:00
|
|
|
mm_unaccount_pinned_pages(&znotif->z_mmp);
|
2018-02-28 01:52:43 +08:00
|
|
|
q = &rs->rs_zcookie_queue;
|
2018-02-16 02:49:35 +08:00
|
|
|
spin_lock_irqsave(&q->lock, flags);
|
2018-03-06 23:22:34 +08:00
|
|
|
head = &q->zcookie_head;
|
|
|
|
if (!list_empty(head)) {
|
2024-06-12 13:13:20 +08:00
|
|
|
info = list_first_entry(head, struct rds_msg_zcopy_info,
|
|
|
|
rs_zcookie_next);
|
|
|
|
if (rds_zcookie_add(info, cookie)) {
|
2018-03-06 23:22:34 +08:00
|
|
|
spin_unlock_irqrestore(&q->lock, flags);
|
|
|
|
kfree(rds_info_from_znotifier(znotif));
|
|
|
|
/* caller invokes rds_wake_sk_sleep() */
|
|
|
|
return;
|
|
|
|
}
|
2018-02-16 02:49:35 +08:00
|
|
|
}
|
|
|
|
|
2018-03-06 23:22:34 +08:00
|
|
|
info = rds_info_from_znotifier(znotif);
|
|
|
|
ck = &info->zcookies;
|
2018-02-28 01:52:43 +08:00
|
|
|
memset(ck, 0, sizeof(*ck));
|
2018-03-06 23:22:34 +08:00
|
|
|
WARN_ON(!rds_zcookie_add(info, cookie));
|
2024-06-12 13:13:20 +08:00
|
|
|
list_add_tail(&info->rs_zcookie_next, &q->zcookie_head);
|
2018-02-16 02:49:35 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&q->lock, flags);
|
2018-02-28 01:52:43 +08:00
|
|
|
/* caller invokes rds_wake_sk_sleep() */
|
2018-02-16 02:49:35 +08:00
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:26 +08:00
|
|
|
/*
|
|
|
|
* This relies on dma_map_sg() not touching sg[].page during merging.
|
|
|
|
*/
|
|
|
|
static void rds_message_purge(struct rds_message *rm)
|
|
|
|
{
|
2018-02-16 02:49:33 +08:00
|
|
|
unsigned long i, flags;
|
2018-02-16 02:49:35 +08:00
|
|
|
bool zcopy = false;
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
if (unlikely(test_bit(RDS_MSG_PAGEVEC, &rm->m_flags)))
|
|
|
|
return;
|
|
|
|
|
2018-02-16 02:49:33 +08:00
|
|
|
spin_lock_irqsave(&rm->m_rs_lock, flags);
|
|
|
|
if (rm->m_rs) {
|
2018-02-16 02:49:35 +08:00
|
|
|
struct rds_sock *rs = rm->m_rs;
|
|
|
|
|
|
|
|
if (rm->data.op_mmp_znotifier) {
|
|
|
|
zcopy = true;
|
|
|
|
rds_rm_zerocopy_callback(rs, rm->data.op_mmp_znotifier);
|
2018-02-28 01:52:43 +08:00
|
|
|
rds_wake_sk_sleep(rs);
|
2018-02-16 02:49:35 +08:00
|
|
|
rm->data.op_mmp_znotifier = NULL;
|
|
|
|
}
|
|
|
|
sock_put(rds_rs_to_sk(rs));
|
2018-02-16 02:49:33 +08:00
|
|
|
rm->m_rs = NULL;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&rm->m_rs_lock, flags);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2018-02-16 02:49:35 +08:00
|
|
|
for (i = 0; i < rm->data.op_nents; i++) {
|
|
|
|
/* XXX will have to put_page for page refs */
|
|
|
|
if (!zcopy)
|
|
|
|
__free_page(sg_page(&rm->data.op_sg[i]));
|
|
|
|
else
|
|
|
|
put_page(sg_page(&rm->data.op_sg[i]));
|
|
|
|
}
|
|
|
|
rm->data.op_nents = 0;
|
|
|
|
|
2010-03-02 06:11:53 +08:00
|
|
|
if (rm->rdma.op_active)
|
|
|
|
rds_rdma_free_op(&rm->rdma);
|
|
|
|
if (rm->rdma.op_rdma_mr)
|
|
|
|
rds_mr_put(rm->rdma.op_rdma_mr);
|
2010-01-28 08:15:48 +08:00
|
|
|
|
|
|
|
if (rm->atomic.op_active)
|
|
|
|
rds_atomic_free_op(&rm->atomic);
|
|
|
|
if (rm->atomic.op_rdma_mr)
|
|
|
|
rds_mr_put(rm->atomic.op_rdma_mr);
|
2009-02-24 23:30:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rds_message_put(struct rds_message *rm)
|
|
|
|
{
|
2017-07-04 20:53:18 +08:00
|
|
|
rdsdebug("put rm %p ref %d\n", rm, refcount_read(&rm->m_refcount));
|
|
|
|
WARN(!refcount_read(&rm->m_refcount), "danger refcount zero on %p\n", rm);
|
|
|
|
if (refcount_dec_and_test(&rm->m_refcount)) {
|
2009-02-24 23:30:26 +08:00
|
|
|
BUG_ON(!list_empty(&rm->m_sock_item));
|
|
|
|
BUG_ON(!list_empty(&rm->m_conn_item));
|
|
|
|
rds_message_purge(rm);
|
|
|
|
|
|
|
|
kfree(rm);
|
|
|
|
}
|
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_message_put);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
void rds_message_populate_header(struct rds_header *hdr, __be16 sport,
|
|
|
|
__be16 dport, u64 seq)
|
|
|
|
{
|
|
|
|
hdr->h_flags = 0;
|
|
|
|
hdr->h_sport = sport;
|
|
|
|
hdr->h_dport = dport;
|
|
|
|
hdr->h_sequence = cpu_to_be64(seq);
|
|
|
|
hdr->h_exthdr[0] = RDS_EXTHDR_NONE;
|
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_message_populate_header);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2010-10-19 16:08:33 +08:00
|
|
|
int rds_message_add_extension(struct rds_header *hdr, unsigned int type,
|
|
|
|
const void *data, unsigned int len)
|
2009-02-24 23:30:26 +08:00
|
|
|
{
|
|
|
|
unsigned int ext_len = sizeof(u8) + len;
|
|
|
|
unsigned char *dst;
|
|
|
|
|
|
|
|
/* For now, refuse to add more than one extension header */
|
|
|
|
if (hdr->h_exthdr[0] != RDS_EXTHDR_NONE)
|
|
|
|
return 0;
|
|
|
|
|
2009-11-30 08:55:45 +08:00
|
|
|
if (type >= __RDS_EXTHDR_MAX || len != rds_exthdr_size[type])
|
2009-02-24 23:30:26 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ext_len >= RDS_HEADER_EXT_SPACE)
|
|
|
|
return 0;
|
|
|
|
dst = hdr->h_exthdr;
|
|
|
|
|
|
|
|
*dst++ = type;
|
|
|
|
memcpy(dst, data, len);
|
|
|
|
|
|
|
|
dst[len] = RDS_EXTHDR_NONE;
|
|
|
|
return 1;
|
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_message_add_extension);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a message has extension headers, retrieve them here.
|
|
|
|
* Call like this:
|
|
|
|
*
|
|
|
|
* unsigned int pos = 0;
|
|
|
|
*
|
|
|
|
* while (1) {
|
|
|
|
* buflen = sizeof(buffer);
|
|
|
|
* type = rds_message_next_extension(hdr, &pos, buffer, &buflen);
|
|
|
|
* if (type == RDS_EXTHDR_NONE)
|
|
|
|
* break;
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
int rds_message_next_extension(struct rds_header *hdr,
|
|
|
|
unsigned int *pos, void *buf, unsigned int *buflen)
|
|
|
|
{
|
|
|
|
unsigned int offset, ext_type, ext_len;
|
|
|
|
u8 *src = hdr->h_exthdr;
|
|
|
|
|
|
|
|
offset = *pos;
|
|
|
|
if (offset >= RDS_HEADER_EXT_SPACE)
|
|
|
|
goto none;
|
|
|
|
|
|
|
|
/* Get the extension type and length. For now, the
|
|
|
|
* length is implied by the extension type. */
|
|
|
|
ext_type = src[offset++];
|
|
|
|
|
|
|
|
if (ext_type == RDS_EXTHDR_NONE || ext_type >= __RDS_EXTHDR_MAX)
|
|
|
|
goto none;
|
|
|
|
ext_len = rds_exthdr_size[ext_type];
|
|
|
|
if (offset + ext_len > RDS_HEADER_EXT_SPACE)
|
|
|
|
goto none;
|
|
|
|
|
|
|
|
*pos = offset + ext_len;
|
|
|
|
if (ext_len < *buflen)
|
|
|
|
*buflen = ext_len;
|
|
|
|
memcpy(buf, src + offset, *buflen);
|
|
|
|
return ext_type;
|
|
|
|
|
|
|
|
none:
|
|
|
|
*pos = RDS_HEADER_EXT_SPACE;
|
|
|
|
*buflen = 0;
|
|
|
|
return RDS_EXTHDR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rds_message_add_rdma_dest_extension(struct rds_header *hdr, u32 r_key, u32 offset)
|
|
|
|
{
|
|
|
|
struct rds_ext_header_rdma_dest ext_hdr;
|
|
|
|
|
|
|
|
ext_hdr.h_rdma_rkey = cpu_to_be32(r_key);
|
|
|
|
ext_hdr.h_rdma_offset = cpu_to_be32(offset);
|
|
|
|
return rds_message_add_extension(hdr, RDS_EXTHDR_RDMA_DEST, &ext_hdr, sizeof(ext_hdr));
|
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_message_add_rdma_dest_extension);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2010-01-13 04:56:06 +08:00
|
|
|
/*
|
|
|
|
* Each rds_message is allocated with extra space for the scatterlist entries
|
|
|
|
* rds ops will need. This is to minimize memory allocation count. Then, each rds op
|
|
|
|
* can grab SGs when initializing its part of the rds_message.
|
|
|
|
*/
|
|
|
|
struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp)
|
2009-02-24 23:30:26 +08:00
|
|
|
{
|
|
|
|
struct rds_message *rm;
|
|
|
|
|
2013-03-04 00:18:11 +08:00
|
|
|
if (extra_len > KMALLOC_MAX_SIZE - sizeof(struct rds_message))
|
|
|
|
return NULL;
|
|
|
|
|
2010-01-13 04:56:06 +08:00
|
|
|
rm = kzalloc(sizeof(struct rds_message) + extra_len, gfp);
|
2009-02-24 23:30:26 +08:00
|
|
|
if (!rm)
|
|
|
|
goto out;
|
|
|
|
|
2010-01-13 04:56:06 +08:00
|
|
|
rm->m_used_sgs = 0;
|
|
|
|
rm->m_total_sgs = extra_len / sizeof(struct scatterlist);
|
|
|
|
|
2017-07-04 20:53:18 +08:00
|
|
|
refcount_set(&rm->m_refcount, 1);
|
2009-02-24 23:30:26 +08:00
|
|
|
INIT_LIST_HEAD(&rm->m_sock_item);
|
|
|
|
INIT_LIST_HEAD(&rm->m_conn_item);
|
|
|
|
spin_lock_init(&rm->m_rs_lock);
|
2010-04-22 04:09:28 +08:00
|
|
|
init_waitqueue_head(&rm->m_flush_wait);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
return rm;
|
|
|
|
}
|
|
|
|
|
2010-01-13 04:56:06 +08:00
|
|
|
/*
|
|
|
|
* RDS ops use this to grab SG entries from the rm's sg pool.
|
|
|
|
*/
|
2024-06-11 20:26:44 +08:00
|
|
|
struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents)
|
2010-01-13 04:56:06 +08:00
|
|
|
{
|
|
|
|
struct scatterlist *sg_first = (struct scatterlist *) &rm[1];
|
|
|
|
struct scatterlist *sg_ret;
|
|
|
|
|
2018-12-16 15:01:09 +08:00
|
|
|
if (nents <= 0) {
|
|
|
|
pr_warn("rds: alloc sgs failed! nents <= 0\n");
|
2024-06-11 20:26:44 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
2018-12-16 15:01:09 +08:00
|
|
|
}
|
2010-01-13 04:56:06 +08:00
|
|
|
|
2018-12-16 15:01:09 +08:00
|
|
|
if (rm->m_used_sgs + nents > rm->m_total_sgs) {
|
|
|
|
pr_warn("rds: alloc sgs failed! total %d used %d nents %d\n",
|
|
|
|
rm->m_total_sgs, rm->m_used_sgs, nents);
|
2024-06-11 20:26:44 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2018-12-16 15:01:09 +08:00
|
|
|
}
|
2010-10-28 23:40:59 +08:00
|
|
|
|
2010-01-13 04:56:06 +08:00
|
|
|
sg_ret = &sg_first[rm->m_used_sgs];
|
2010-01-13 06:17:31 +08:00
|
|
|
sg_init_table(sg_ret, nents);
|
2010-01-13 04:56:06 +08:00
|
|
|
rm->m_used_sgs += nents;
|
|
|
|
|
|
|
|
return sg_ret;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:26 +08:00
|
|
|
struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned int total_len)
|
|
|
|
{
|
|
|
|
struct rds_message *rm;
|
|
|
|
unsigned int i;
|
2019-01-07 09:59:59 +08:00
|
|
|
int num_sgs = DIV_ROUND_UP(total_len, PAGE_SIZE);
|
2010-01-13 06:13:15 +08:00
|
|
|
int extra_bytes = num_sgs * sizeof(struct scatterlist);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2010-03-30 07:46:46 +08:00
|
|
|
rm = rds_message_alloc(extra_bytes, GFP_NOWAIT);
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!rm)
|
2009-02-24 23:30:26 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
set_bit(RDS_MSG_PAGEVEC, &rm->m_flags);
|
|
|
|
rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len);
|
2019-01-07 09:59:59 +08:00
|
|
|
rm->data.op_nents = DIV_ROUND_UP(total_len, PAGE_SIZE);
|
2024-06-11 20:26:44 +08:00
|
|
|
rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs);
|
|
|
|
if (IS_ERR(rm->data.op_sg)) {
|
|
|
|
void *err = ERR_CAST(rm->data.op_sg);
|
2010-11-08 14:20:50 +08:00
|
|
|
rds_message_put(rm);
|
2024-06-11 20:26:44 +08:00
|
|
|
return err;
|
2010-11-08 14:20:50 +08:00
|
|
|
}
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2010-01-28 10:04:18 +08:00
|
|
|
for (i = 0; i < rm->data.op_nents; ++i) {
|
|
|
|
sg_set_page(&rm->data.op_sg[i],
|
2009-02-24 23:30:26 +08:00
|
|
|
virt_to_page(page_addrs[i]),
|
|
|
|
PAGE_SIZE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rm;
|
|
|
|
}
|
|
|
|
|
2018-03-08 18:56:14 +08:00
|
|
|
static int rds_message_zcopy_from_user(struct rds_message *rm, struct iov_iter *from)
|
2009-02-24 23:30:26 +08:00
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
2010-01-13 04:56:06 +08:00
|
|
|
int ret = 0;
|
2018-02-16 02:49:36 +08:00
|
|
|
int length = iov_iter_count(from);
|
2018-03-06 23:22:33 +08:00
|
|
|
int total_copied = 0;
|
2018-03-06 23:22:34 +08:00
|
|
|
struct rds_msg_zcopy_info *info;
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2014-11-20 22:31:08 +08:00
|
|
|
rm->m_inc.i_hdr.h_len = cpu_to_be32(iov_iter_count(from));
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now allocate and copy in the data payload.
|
|
|
|
*/
|
2010-01-28 10:04:18 +08:00
|
|
|
sg = rm->data.op_sg;
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2018-03-06 23:22:34 +08:00
|
|
|
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (!info)
|
2018-03-06 23:22:33 +08:00
|
|
|
return -ENOMEM;
|
2018-03-06 23:22:34 +08:00
|
|
|
INIT_LIST_HEAD(&info->rs_zcookie_next);
|
|
|
|
rm->data.op_mmp_znotifier = &info->znotif;
|
2018-03-06 23:22:33 +08:00
|
|
|
if (mm_account_pinned_pages(&rm->data.op_mmp_znotifier->z_mmp,
|
|
|
|
length)) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
while (iov_iter_count(from)) {
|
|
|
|
struct page *pages;
|
|
|
|
size_t start;
|
|
|
|
ssize_t copied;
|
|
|
|
|
|
|
|
copied = iov_iter_get_pages(from, &pages, PAGE_SIZE,
|
|
|
|
1, &start);
|
|
|
|
if (copied < 0) {
|
|
|
|
struct mmpin *mmp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < rm->data.op_nents; i++)
|
|
|
|
put_page(sg_page(&rm->data.op_sg[i]));
|
|
|
|
mmp = &rm->data.op_mmp_znotifier->z_mmp;
|
|
|
|
mm_unaccount_pinned_pages(mmp);
|
|
|
|
ret = -EFAULT;
|
2018-02-16 02:49:36 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2018-03-06 23:22:33 +08:00
|
|
|
total_copied += copied;
|
|
|
|
iov_iter_advance(from, copied);
|
|
|
|
length -= copied;
|
|
|
|
sg_set_page(sg, pages, copied, start);
|
|
|
|
rm->data.op_nents++;
|
|
|
|
sg++;
|
|
|
|
}
|
|
|
|
WARN_ON_ONCE(length != 0);
|
|
|
|
return ret;
|
2018-02-16 02:49:36 +08:00
|
|
|
err:
|
2018-03-06 23:22:34 +08:00
|
|
|
kfree(info);
|
2018-03-06 23:22:33 +08:00
|
|
|
rm->data.op_mmp_znotifier = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from,
|
|
|
|
bool zcopy)
|
|
|
|
{
|
|
|
|
unsigned long to_copy, nbytes;
|
|
|
|
unsigned long sg_off;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rm->m_inc.i_hdr.h_len = cpu_to_be32(iov_iter_count(from));
|
|
|
|
|
|
|
|
/* now allocate and copy in the data payload. */
|
|
|
|
sg = rm->data.op_sg;
|
|
|
|
sg_off = 0; /* Dear gcc, sg->page will be null from kzalloc. */
|
|
|
|
|
|
|
|
if (zcopy)
|
|
|
|
return rds_message_zcopy_from_user(rm, from);
|
2018-02-16 02:49:36 +08:00
|
|
|
|
2014-11-20 22:31:08 +08:00
|
|
|
while (iov_iter_count(from)) {
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!sg_page(sg)) {
|
2014-11-20 22:31:08 +08:00
|
|
|
ret = rds_page_remainder_alloc(sg, iov_iter_count(from),
|
2009-02-24 23:30:26 +08:00
|
|
|
GFP_HIGHUSER);
|
|
|
|
if (ret)
|
2014-11-20 22:31:08 +08:00
|
|
|
return ret;
|
2010-01-28 10:04:18 +08:00
|
|
|
rm->data.op_nents++;
|
2009-02-24 23:30:26 +08:00
|
|
|
sg_off = 0;
|
|
|
|
}
|
|
|
|
|
2014-11-20 22:31:08 +08:00
|
|
|
to_copy = min_t(unsigned long, iov_iter_count(from),
|
|
|
|
sg->length - sg_off);
|
2009-02-24 23:30:26 +08:00
|
|
|
|
2014-11-20 22:31:08 +08:00
|
|
|
rds_stats_add(s_copy_from_user, to_copy);
|
2015-02-06 06:41:43 +08:00
|
|
|
nbytes = copy_page_from_iter(sg_page(sg), sg->offset + sg_off,
|
|
|
|
to_copy, from);
|
|
|
|
if (nbytes != to_copy)
|
2014-11-20 22:31:08 +08:00
|
|
|
return -EFAULT;
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
sg_off += to_copy;
|
|
|
|
|
|
|
|
if (sg_off == sg->length)
|
|
|
|
sg++;
|
|
|
|
}
|
|
|
|
|
2010-01-13 04:56:06 +08:00
|
|
|
return ret;
|
2009-02-24 23:30:26 +08:00
|
|
|
}
|
|
|
|
|
2014-11-20 22:21:14 +08:00
|
|
|
int rds_message_inc_copy_to_user(struct rds_incoming *inc, struct iov_iter *to)
|
2009-02-24 23:30:26 +08:00
|
|
|
{
|
|
|
|
struct rds_message *rm;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned long to_copy;
|
|
|
|
unsigned long vec_off;
|
|
|
|
int copied;
|
|
|
|
int ret;
|
|
|
|
u32 len;
|
|
|
|
|
|
|
|
rm = container_of(inc, struct rds_message, m_inc);
|
|
|
|
len = be32_to_cpu(rm->m_inc.i_hdr.h_len);
|
|
|
|
|
2010-01-28 10:04:18 +08:00
|
|
|
sg = rm->data.op_sg;
|
2009-02-24 23:30:26 +08:00
|
|
|
vec_off = 0;
|
|
|
|
copied = 0;
|
|
|
|
|
2014-11-20 22:21:14 +08:00
|
|
|
while (iov_iter_count(to) && copied < len) {
|
2014-12-15 20:21:42 +08:00
|
|
|
to_copy = min_t(unsigned long, iov_iter_count(to),
|
|
|
|
sg->length - vec_off);
|
2009-02-24 23:30:26 +08:00
|
|
|
to_copy = min_t(unsigned long, to_copy, len - copied);
|
|
|
|
|
2014-11-20 22:21:14 +08:00
|
|
|
rds_stats_add(s_copy_to_user, to_copy);
|
|
|
|
ret = copy_page_to_iter(sg_page(sg), sg->offset + vec_off,
|
|
|
|
to_copy, to);
|
|
|
|
if (ret != to_copy)
|
|
|
|
return -EFAULT;
|
2009-02-24 23:30:26 +08:00
|
|
|
|
|
|
|
vec_off += to_copy;
|
|
|
|
copied += to_copy;
|
|
|
|
|
|
|
|
if (vec_off == sg->length) {
|
|
|
|
vec_off = 0;
|
|
|
|
sg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the message is still on the send queue, wait until the transport
|
|
|
|
* is done with it. This is particularly important for RDMA operations.
|
|
|
|
*/
|
|
|
|
void rds_message_wait(struct rds_message *rm)
|
|
|
|
{
|
2010-04-22 04:09:28 +08:00
|
|
|
wait_event_interruptible(rm->m_flush_wait,
|
2009-02-24 23:30:26 +08:00
|
|
|
!test_bit(RDS_MSG_MAPPED, &rm->m_flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_message_unmapped(struct rds_message *rm)
|
|
|
|
{
|
|
|
|
clear_bit(RDS_MSG_MAPPED, &rm->m_flags);
|
2010-04-22 04:09:28 +08:00
|
|
|
wake_up_interruptible(&rm->m_flush_wait);
|
2009-02-24 23:30:26 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_message_unmapped);
|