2009-02-24 23:30:30 +08:00
|
|
|
/*
|
2018-07-24 11:51:22 +08:00
|
|
|
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
|
2009-02-24 23:30:30 +08:00
|
|
|
*
|
|
|
|
* 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 <linux/in.h>
|
|
|
|
#include <linux/if.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/inetdevice.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/delay.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-05-27 21:12:25 +08:00
|
|
|
#include <linux/module.h>
|
2018-07-24 11:51:22 +08:00
|
|
|
#include <net/addrconf.h>
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2016-06-14 00:44:26 +08:00
|
|
|
#include "rds_single_path.h"
|
2009-02-24 23:30:30 +08:00
|
|
|
#include "rds.h"
|
|
|
|
#include "ib.h"
|
2016-03-02 07:20:46 +08:00
|
|
|
#include "ib_mr.h"
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2017-02-28 14:45:40 +08:00
|
|
|
static unsigned int rds_ib_mr_1m_pool_size = RDS_MR_1M_POOL_SIZE;
|
|
|
|
static unsigned int rds_ib_mr_8k_pool_size = RDS_MR_8K_POOL_SIZE;
|
2009-07-17 21:13:22 +08:00
|
|
|
unsigned int rds_ib_retry_count = RDS_IB_DEFAULT_RETRY_COUNT;
|
2018-02-03 20:26:51 +08:00
|
|
|
static atomic_t rds_ib_unloading;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
module_param(rds_ib_mr_1m_pool_size, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_ib_mr_1m_pool_size, " Max number of 1M mr per HCA");
|
|
|
|
module_param(rds_ib_mr_8k_pool_size, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_ib_mr_8k_pool_size, " Max number of 8K mr per HCA");
|
2009-07-17 21:13:22 +08:00
|
|
|
module_param(rds_ib_retry_count, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_ib_retry_count, " Number of hw retries before reporting an error");
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2010-07-16 03:34:33 +08:00
|
|
|
/*
|
|
|
|
* we have a clumsy combination of RCU and a rwsem protecting this list
|
|
|
|
* because it is used both in the get_mr fast path and while blocking in
|
|
|
|
* the FMR flushing path.
|
|
|
|
*/
|
|
|
|
DECLARE_RWSEM(rds_ib_devices_lock);
|
2009-02-24 23:30:30 +08:00
|
|
|
struct list_head rds_ib_devices;
|
|
|
|
|
2009-04-01 16:20:19 +08:00
|
|
|
/* NOTE: if also grabbing ibdev lock, grab this first */
|
2009-02-24 23:30:30 +08:00
|
|
|
DEFINE_SPINLOCK(ib_nodev_conns_lock);
|
|
|
|
LIST_HEAD(ib_nodev_conns);
|
|
|
|
|
2010-10-19 16:08:33 +08:00
|
|
|
static void rds_ib_nodev_connect(void)
|
2010-05-25 04:16:57 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
|
|
|
|
spin_lock(&ib_nodev_conns_lock);
|
|
|
|
list_for_each_entry(ic, &ib_nodev_conns, ib_node)
|
|
|
|
rds_conn_connect_if_down(ic->conn);
|
|
|
|
spin_unlock(&ib_nodev_conns_lock);
|
|
|
|
}
|
|
|
|
|
2010-10-19 16:08:33 +08:00
|
|
|
static void rds_ib_dev_shutdown(struct rds_ib_device *rds_ibdev)
|
2010-05-25 04:16:57 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rds_ibdev->spinlock, flags);
|
|
|
|
list_for_each_entry(ic, &rds_ibdev->conn_list, ib_node)
|
net: rds: fix memory leak when unload rds_rdma
When KASAN is enabled, after several rds connections are
created, then "rmmod rds_rdma" is run. The following will
appear.
"
BUG rds_ib_incoming (Not tainted): Objects remaining
in rds_ib_incoming on __kmem_cache_shutdown()
Call Trace:
dump_stack+0x71/0xab
slab_err+0xad/0xd0
__kmem_cache_shutdown+0x17d/0x370
shutdown_cache+0x17/0x130
kmem_cache_destroy+0x1df/0x210
rds_ib_recv_exit+0x11/0x20 [rds_rdma]
rds_ib_exit+0x7a/0x90 [rds_rdma]
__x64_sys_delete_module+0x224/0x2c0
? __ia32_sys_delete_module+0x2c0/0x2c0
do_syscall_64+0x73/0x190
entry_SYSCALL_64_after_hwframe+0x44/0xa9
"
This is rds connection memory leak. The root cause is:
When "rmmod rds_rdma" is run, rds_ib_remove_one will call
rds_ib_dev_shutdown to drop the rds connections.
rds_ib_dev_shutdown will call rds_conn_drop to drop rds
connections as below.
"
rds_conn_path_drop(&conn->c_path[0], false);
"
In the above, destroy is set to false.
void rds_conn_path_drop(struct rds_conn_path *cp, bool destroy)
{
atomic_set(&cp->cp_state, RDS_CONN_ERROR);
rcu_read_lock();
if (!destroy && rds_destroy_pending(cp->cp_conn)) {
rcu_read_unlock();
return;
}
queue_work(rds_wq, &cp->cp_down_w);
rcu_read_unlock();
}
In the above function, destroy is set to false. rds_destroy_pending
is called. This does not move rds connections to ib_nodev_conns.
So destroy is set to true to move rds connections to ib_nodev_conns.
In rds_ib_unregister_client, flush_workqueue is called to make rds_wq
finsh shutdown rds connections. The function rds_ib_destroy_nodev_conns
is called to shutdown rds connections finally.
Then rds_ib_recv_exit is called to destroy slab.
void rds_ib_recv_exit(void)
{
kmem_cache_destroy(rds_ib_incoming_slab);
kmem_cache_destroy(rds_ib_frag_slab);
}
The above slab memory leak will not occur again.
>From tests,
256 rds connections
[root@ca-dev14 ~]# time rmmod rds_rdma
real 0m16.522s
user 0m0.000s
sys 0m8.152s
512 rds connections
[root@ca-dev14 ~]# time rmmod rds_rdma
real 0m32.054s
user 0m0.000s
sys 0m15.568s
To rmmod rds_rdma with 256 rds connections, about 16 seconds are needed.
And with 512 rds connections, about 32 seconds are needed.
>From ftrace, when one rds connection is destroyed,
"
19) | rds_conn_destroy [rds]() {
19) 7.782 us | rds_conn_path_drop [rds]();
15) | rds_shutdown_worker [rds]() {
15) | rds_conn_shutdown [rds]() {
15) 1.651 us | rds_send_path_reset [rds]();
15) 7.195 us | }
15) + 11.434 us | }
19) 2.285 us | rds_cong_remove_conn [rds]();
19) * 24062.76 us | }
"
So if many rds connections will be destroyed, this function
rds_ib_destroy_nodev_conns uses most of time.
Suggested-by: Håkon Bugge <haakon.bugge@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-03 20:48:19 +08:00
|
|
|
rds_conn_path_drop(&ic->conn->c_path[0], true);
|
2010-05-25 04:16:57 +08:00
|
|
|
spin_unlock_irqrestore(&rds_ibdev->spinlock, flags);
|
|
|
|
}
|
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
/*
|
|
|
|
* rds_ib_destroy_mr_pool() blocks on a few things and mrs drop references
|
|
|
|
* from interrupt context so we push freing off into a work struct in krdsd.
|
|
|
|
*/
|
|
|
|
static void rds_ib_dev_free(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct rds_ib_ipaddr *i_ipaddr, *i_next;
|
|
|
|
struct rds_ib_device *rds_ibdev = container_of(work,
|
|
|
|
struct rds_ib_device, free_work);
|
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
if (rds_ibdev->mr_8k_pool)
|
|
|
|
rds_ib_destroy_mr_pool(rds_ibdev->mr_8k_pool);
|
|
|
|
if (rds_ibdev->mr_1m_pool)
|
|
|
|
rds_ib_destroy_mr_pool(rds_ibdev->mr_1m_pool);
|
2010-05-19 06:48:51 +08:00
|
|
|
if (rds_ibdev->pd)
|
|
|
|
ib_dealloc_pd(rds_ibdev->pd);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(i_ipaddr, i_next, &rds_ibdev->ipaddr_list, list) {
|
|
|
|
list_del(&i_ipaddr->list);
|
|
|
|
kfree(i_ipaddr);
|
|
|
|
}
|
|
|
|
|
2017-02-23 20:47:01 +08:00
|
|
|
kfree(rds_ibdev->vector_load);
|
2016-07-05 07:16:36 +08:00
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
kfree(rds_ibdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_dev_put(struct rds_ib_device *rds_ibdev)
|
|
|
|
{
|
2017-07-04 20:53:15 +08:00
|
|
|
BUG_ON(refcount_read(&rds_ibdev->refcount) == 0);
|
|
|
|
if (refcount_dec_and_test(&rds_ibdev->refcount))
|
2010-05-19 06:48:51 +08:00
|
|
|
queue_work(rds_wq, &rds_ibdev->free_work);
|
|
|
|
}
|
|
|
|
|
2010-10-19 16:08:33 +08:00
|
|
|
static void rds_ib_add_one(struct ib_device *device)
|
2009-02-24 23:30:30 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
2017-10-05 03:10:43 +08:00
|
|
|
bool has_fr, has_fmr;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
/* Only handle IB (no iWARP) devices */
|
|
|
|
if (device->node_type != RDMA_NODE_IB_CA)
|
|
|
|
return;
|
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
rds_ibdev = kzalloc_node(sizeof(struct rds_ib_device), GFP_KERNEL,
|
|
|
|
ibdev_to_node(device));
|
2009-02-24 23:30:30 +08:00
|
|
|
if (!rds_ibdev)
|
2015-12-18 16:59:47 +08:00
|
|
|
return;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
spin_lock_init(&rds_ibdev->spinlock);
|
2017-07-04 20:53:15 +08:00
|
|
|
refcount_set(&rds_ibdev->refcount, 1);
|
2010-05-19 06:48:51 +08:00
|
|
|
INIT_WORK(&rds_ibdev->free_work, rds_ib_dev_free);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2015-12-18 16:59:47 +08:00
|
|
|
rds_ibdev->max_wrs = device->attrs.max_qp_wr;
|
2018-06-18 23:05:26 +08:00
|
|
|
rds_ibdev->max_sge = min(device->attrs.max_send_sge, RDS_IB_MAX_SGE);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2017-10-05 03:10:43 +08:00
|
|
|
has_fr = (device->attrs.device_cap_flags &
|
|
|
|
IB_DEVICE_MEM_MGT_EXTENSIONS);
|
2018-12-11 03:09:48 +08:00
|
|
|
has_fmr = (device->ops.alloc_fmr && device->ops.dealloc_fmr &&
|
|
|
|
device->ops.map_phys_fmr && device->ops.unmap_fmr);
|
2017-10-05 03:10:43 +08:00
|
|
|
rds_ibdev->use_fastreg = (has_fr && !has_fmr);
|
2016-03-02 07:20:52 +08:00
|
|
|
|
2015-12-18 16:59:47 +08:00
|
|
|
rds_ibdev->fmr_max_remaps = device->attrs.max_map_per_fmr?: 32;
|
2016-03-02 07:20:46 +08:00
|
|
|
rds_ibdev->max_1m_mrs = device->attrs.max_mr ?
|
2015-12-18 16:59:47 +08:00
|
|
|
min_t(unsigned int, (device->attrs.max_mr / 2),
|
2016-03-02 07:20:46 +08:00
|
|
|
rds_ib_mr_1m_pool_size) : rds_ib_mr_1m_pool_size;
|
2015-09-11 12:20:57 +08:00
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
rds_ibdev->max_8k_mrs = device->attrs.max_mr ?
|
2015-12-18 16:59:47 +08:00
|
|
|
min_t(unsigned int, ((device->attrs.max_mr / 2) * RDS_MR_8K_SCALE),
|
2016-03-02 07:20:46 +08:00
|
|
|
rds_ib_mr_8k_pool_size) : rds_ib_mr_8k_pool_size;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2015-12-18 16:59:47 +08:00
|
|
|
rds_ibdev->max_initiator_depth = device->attrs.max_qp_init_rd_atom;
|
|
|
|
rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom;
|
2010-01-13 02:50:48 +08:00
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
rds_ibdev->vector_load = kcalloc(device->num_comp_vectors,
|
|
|
|
sizeof(int),
|
2016-07-05 07:16:36 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!rds_ibdev->vector_load) {
|
|
|
|
pr_err("RDS/IB: %s failed to allocate vector memory\n",
|
|
|
|
__func__);
|
|
|
|
goto put_dev;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
rds_ibdev->dev = device;
|
2016-09-05 18:56:17 +08:00
|
|
|
rds_ibdev->pd = ib_alloc_pd(device, 0);
|
2010-05-19 06:48:51 +08:00
|
|
|
if (IS_ERR(rds_ibdev->pd)) {
|
|
|
|
rds_ibdev->pd = NULL;
|
|
|
|
goto put_dev;
|
|
|
|
}
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
rds_ibdev->mr_1m_pool =
|
|
|
|
rds_ib_create_mr_pool(rds_ibdev, RDS_IB_MR_1M_POOL);
|
|
|
|
if (IS_ERR(rds_ibdev->mr_1m_pool)) {
|
|
|
|
rds_ibdev->mr_1m_pool = NULL;
|
2010-05-19 06:48:51 +08:00
|
|
|
goto put_dev;
|
2009-02-24 23:30:30 +08:00
|
|
|
}
|
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
rds_ibdev->mr_8k_pool =
|
|
|
|
rds_ib_create_mr_pool(rds_ibdev, RDS_IB_MR_8K_POOL);
|
|
|
|
if (IS_ERR(rds_ibdev->mr_8k_pool)) {
|
|
|
|
rds_ibdev->mr_8k_pool = NULL;
|
|
|
|
goto put_dev;
|
|
|
|
}
|
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
rdsdebug("RDS/IB: max_mr = %d, max_wrs = %d, max_sge = %d, fmr_max_remaps = %d, max_1m_mrs = %d, max_8k_mrs = %d\n",
|
2015-12-18 16:59:47 +08:00
|
|
|
device->attrs.max_fmr, rds_ibdev->max_wrs, rds_ibdev->max_sge,
|
2016-03-02 07:20:46 +08:00
|
|
|
rds_ibdev->fmr_max_remaps, rds_ibdev->max_1m_mrs,
|
|
|
|
rds_ibdev->max_8k_mrs);
|
2015-09-11 12:20:57 +08:00
|
|
|
|
2016-03-02 07:20:52 +08:00
|
|
|
pr_info("RDS/IB: %s: %s supported and preferred\n",
|
|
|
|
device->name,
|
|
|
|
rds_ibdev->use_fastreg ? "FRMR" : "FMR");
|
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
INIT_LIST_HEAD(&rds_ibdev->ipaddr_list);
|
|
|
|
INIT_LIST_HEAD(&rds_ibdev->conn_list);
|
2010-07-16 03:34:33 +08:00
|
|
|
|
|
|
|
down_write(&rds_ib_devices_lock);
|
|
|
|
list_add_tail_rcu(&rds_ibdev->list, &rds_ib_devices);
|
|
|
|
up_write(&rds_ib_devices_lock);
|
2017-07-04 20:53:15 +08:00
|
|
|
refcount_inc(&rds_ibdev->refcount);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
ib_set_client_data(device, &rds_ib_client, rds_ibdev);
|
2017-07-04 20:53:15 +08:00
|
|
|
refcount_inc(&rds_ibdev->refcount);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2010-05-25 04:16:57 +08:00
|
|
|
rds_ib_nodev_connect();
|
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
put_dev:
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2009-02-24 23:30:30 +08:00
|
|
|
}
|
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
/*
|
|
|
|
* New connections use this to find the device to associate with the
|
|
|
|
* connection. It's not in the fast path so we're not concerned about the
|
|
|
|
* performance of the IB call. (As of this writing, it uses an interrupt
|
|
|
|
* blocking spinlock to serialize walking a per-device list of all registered
|
|
|
|
* clients.)
|
|
|
|
*
|
|
|
|
* RCU is used to handle incoming connections racing with device teardown.
|
|
|
|
* Rather than use a lock to serialize removal from the client_data and
|
|
|
|
* getting a new reference, we use an RCU grace period. The destruction
|
|
|
|
* path removes the device from client_data and then waits for all RCU
|
|
|
|
* readers to finish.
|
|
|
|
*
|
|
|
|
* A new connection can get NULL from this if its arriving on a
|
|
|
|
* device that is in the process of being removed.
|
|
|
|
*/
|
|
|
|
struct rds_ib_device *rds_ib_get_client_data(struct ib_device *device)
|
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
rds_ibdev = ib_get_client_data(device, &rds_ib_client);
|
|
|
|
if (rds_ibdev)
|
2017-07-04 20:53:15 +08:00
|
|
|
refcount_inc(&rds_ibdev->refcount);
|
2010-05-19 06:48:51 +08:00
|
|
|
rcu_read_unlock();
|
|
|
|
return rds_ibdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The IB stack is letting us know that a device is going away. This can
|
|
|
|
* happen if the underlying HCA driver is removed or if PCI hotplug is removing
|
|
|
|
* the pci function, for example.
|
|
|
|
*
|
|
|
|
* This can be called at any time and can be racing with any other RDS path.
|
|
|
|
*/
|
2015-07-30 22:50:14 +08:00
|
|
|
static void rds_ib_remove_one(struct ib_device *device, void *client_data)
|
2009-02-24 23:30:30 +08:00
|
|
|
{
|
2015-07-30 22:50:14 +08:00
|
|
|
struct rds_ib_device *rds_ibdev = client_data;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
if (!rds_ibdev)
|
|
|
|
return;
|
|
|
|
|
2010-05-25 04:16:57 +08:00
|
|
|
rds_ib_dev_shutdown(rds_ibdev);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2010-07-16 03:34:33 +08:00
|
|
|
/* stop connection attempts from getting a reference to this device. */
|
|
|
|
ib_set_client_data(device, &rds_ib_client, NULL);
|
|
|
|
|
|
|
|
down_write(&rds_ib_devices_lock);
|
|
|
|
list_del_rcu(&rds_ibdev->list);
|
|
|
|
up_write(&rds_ib_devices_lock);
|
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
/*
|
2010-07-16 03:34:33 +08:00
|
|
|
* This synchronize rcu is waiting for readers of both the ib
|
|
|
|
* client data and the devices list to finish before we drop
|
|
|
|
* both of those references.
|
2010-05-19 06:48:51 +08:00
|
|
|
*/
|
|
|
|
synchronize_rcu();
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2009-02-24 23:30:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ib_client rds_ib_client = {
|
|
|
|
.name = "rds_ib",
|
|
|
|
.add = rds_ib_add_one,
|
|
|
|
.remove = rds_ib_remove_one
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rds_ib_conn_info_visitor(struct rds_connection *conn,
|
|
|
|
void *buffer)
|
|
|
|
{
|
|
|
|
struct rds_info_rdma_connection *iinfo = buffer;
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
|
|
|
|
/* We will only ever look at IB transports */
|
|
|
|
if (conn->c_trans != &rds_ib_transport)
|
|
|
|
return 0;
|
2018-07-24 11:51:22 +08:00
|
|
|
if (conn->c_isv6)
|
|
|
|
return 0;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2018-07-24 11:51:21 +08:00
|
|
|
iinfo->src_addr = conn->c_laddr.s6_addr32[3];
|
|
|
|
iinfo->dst_addr = conn->c_faddr.s6_addr32[3];
|
2018-10-24 11:21:14 +08:00
|
|
|
iinfo->tos = conn->c_tos;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
memset(&iinfo->src_gid, 0, sizeof(iinfo->src_gid));
|
|
|
|
memset(&iinfo->dst_gid, 0, sizeof(iinfo->dst_gid));
|
|
|
|
if (rds_conn_state(conn) == RDS_CONN_UP) {
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
|
|
|
|
ic = conn->c_transport_data;
|
|
|
|
|
2018-01-18 16:11:18 +08:00
|
|
|
rdma_read_gids(ic->i_cm_id, (union ib_gid *)&iinfo->src_gid,
|
|
|
|
(union ib_gid *)&iinfo->dst_gid);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2010-05-19 06:48:51 +08:00
|
|
|
rds_ibdev = ic->rds_ibdev;
|
2009-02-24 23:30:30 +08:00
|
|
|
iinfo->max_send_wr = ic->i_send_ring.w_nr;
|
|
|
|
iinfo->max_recv_wr = ic->i_recv_ring.w_nr;
|
|
|
|
iinfo->max_send_sge = rds_ibdev->max_sge;
|
|
|
|
rds_ib_get_mr_info(rds_ibdev, iinfo);
|
2019-06-03 12:28:01 +08:00
|
|
|
iinfo->cache_allocs = atomic_read(&ic->i_cache_allocs);
|
2009-02-24 23:30:30 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:23 +08:00
|
|
|
/* IPv6 version of rds_ib_conn_info_visitor(). */
|
|
|
|
static int rds6_ib_conn_info_visitor(struct rds_connection *conn,
|
|
|
|
void *buffer)
|
|
|
|
{
|
|
|
|
struct rds6_info_rdma_connection *iinfo6 = buffer;
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
|
|
|
|
/* We will only ever look at IB transports */
|
|
|
|
if (conn->c_trans != &rds_ib_transport)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iinfo6->src_addr = conn->c_laddr;
|
|
|
|
iinfo6->dst_addr = conn->c_faddr;
|
|
|
|
|
|
|
|
memset(&iinfo6->src_gid, 0, sizeof(iinfo6->src_gid));
|
|
|
|
memset(&iinfo6->dst_gid, 0, sizeof(iinfo6->dst_gid));
|
|
|
|
|
|
|
|
if (rds_conn_state(conn) == RDS_CONN_UP) {
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
|
|
|
|
ic = conn->c_transport_data;
|
2018-08-25 15:19:05 +08:00
|
|
|
rdma_read_gids(ic->i_cm_id, (union ib_gid *)&iinfo6->src_gid,
|
|
|
|
(union ib_gid *)&iinfo6->dst_gid);
|
2018-07-24 11:51:23 +08:00
|
|
|
rds_ibdev = ic->rds_ibdev;
|
|
|
|
iinfo6->max_send_wr = ic->i_send_ring.w_nr;
|
|
|
|
iinfo6->max_recv_wr = ic->i_recv_ring.w_nr;
|
|
|
|
iinfo6->max_send_sge = rds_ibdev->max_sge;
|
|
|
|
rds6_ib_get_mr_info(rds_ibdev, iinfo6);
|
2019-06-03 12:28:01 +08:00
|
|
|
iinfo6->cache_allocs = atomic_read(&ic->i_cache_allocs);
|
2018-07-24 11:51:23 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2018-07-31 13:48:42 +08:00
|
|
|
#endif
|
2018-07-24 11:51:23 +08:00
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
static void rds_ib_ic_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens)
|
|
|
|
{
|
2018-03-12 05:07:49 +08:00
|
|
|
u64 buffer[(sizeof(struct rds_info_rdma_connection) + 7) / 8];
|
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
rds_for_each_conn_info(sock, len, iter, lens,
|
|
|
|
rds_ib_conn_info_visitor,
|
2018-03-12 05:07:49 +08:00
|
|
|
buffer,
|
2009-02-24 23:30:30 +08:00
|
|
|
sizeof(struct rds_info_rdma_connection));
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:23 +08:00
|
|
|
/* IPv6 version of rds_ib_ic_info(). */
|
|
|
|
static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens)
|
|
|
|
{
|
|
|
|
u64 buffer[(sizeof(struct rds6_info_rdma_connection) + 7) / 8];
|
|
|
|
|
|
|
|
rds_for_each_conn_info(sock, len, iter, lens,
|
|
|
|
rds6_ib_conn_info_visitor,
|
|
|
|
buffer,
|
|
|
|
sizeof(struct rds6_info_rdma_connection));
|
|
|
|
}
|
2018-07-31 13:48:42 +08:00
|
|
|
#endif
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Early RDS/IB was built to only bind to an address if there is an IPoIB
|
|
|
|
* device with that address set.
|
|
|
|
*
|
|
|
|
* If it were me, I'd advocate for something more flexible. Sending and
|
|
|
|
* receiving should be device-agnostic. Transports would try and maintain
|
|
|
|
* connections between peers who have messages queued. Userspace would be
|
|
|
|
* allowed to influence which paths have priority. We could call userspace
|
|
|
|
* asserting this policy "routing".
|
|
|
|
*/
|
2018-07-24 11:51:21 +08:00
|
|
|
static int rds_ib_laddr_check(struct net *net, const struct in6_addr *addr,
|
|
|
|
__u32 scope_id)
|
2009-02-24 23:30:30 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct rdma_cm_id *cm_id;
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:22 +08:00
|
|
|
struct sockaddr_in6 sin6;
|
2018-07-31 13:48:42 +08:00
|
|
|
#endif
|
2009-02-24 23:30:30 +08:00
|
|
|
struct sockaddr_in sin;
|
2018-07-24 11:51:22 +08:00
|
|
|
struct sockaddr *sa;
|
|
|
|
bool isv4;
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2018-07-24 11:51:22 +08:00
|
|
|
isv4 = ipv6_addr_v4mapped(addr);
|
2009-02-24 23:30:30 +08:00
|
|
|
/* Create a CMA ID and try to bind it. This catches both
|
|
|
|
* IB and iWARP capable NICs.
|
|
|
|
*/
|
2018-02-06 10:43:21 +08:00
|
|
|
cm_id = rdma_create_id(&init_net, rds_rdma_cm_event_handler,
|
|
|
|
NULL, RDMA_PS_TCP, IB_QPT_RC);
|
2009-04-09 22:09:46 +08:00
|
|
|
if (IS_ERR(cm_id))
|
|
|
|
return PTR_ERR(cm_id);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2018-07-24 11:51:22 +08:00
|
|
|
if (isv4) {
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_addr.s_addr = addr->s6_addr32[3];
|
|
|
|
sa = (struct sockaddr *)&sin;
|
|
|
|
} else {
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:22 +08:00
|
|
|
memset(&sin6, 0, sizeof(sin6));
|
|
|
|
sin6.sin6_family = AF_INET6;
|
|
|
|
sin6.sin6_addr = *addr;
|
|
|
|
sin6.sin6_scope_id = scope_id;
|
|
|
|
sa = (struct sockaddr *)&sin6;
|
|
|
|
|
|
|
|
/* XXX Do a special IPv6 link local address check here. The
|
|
|
|
* reason is that rdma_bind_addr() always succeeds with IPv6
|
|
|
|
* link local address regardless it is indeed configured in a
|
|
|
|
* system.
|
|
|
|
*/
|
|
|
|
if (ipv6_addr_type(addr) & IPV6_ADDR_LINKLOCAL) {
|
|
|
|
struct net_device *dev;
|
|
|
|
|
2018-07-31 13:48:42 +08:00
|
|
|
if (scope_id == 0) {
|
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-07-24 11:51:22 +08:00
|
|
|
|
|
|
|
/* Use init_net for now as RDS is not network
|
|
|
|
* name space aware.
|
|
|
|
*/
|
|
|
|
dev = dev_get_by_index(&init_net, scope_id);
|
2018-07-31 13:48:42 +08:00
|
|
|
if (!dev) {
|
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-07-24 11:51:22 +08:00
|
|
|
if (!ipv6_chk_addr(&init_net, addr, dev, 1)) {
|
|
|
|
dev_put(dev);
|
2018-07-31 13:48:42 +08:00
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
2018-07-24 11:51:22 +08:00
|
|
|
}
|
|
|
|
dev_put(dev);
|
|
|
|
}
|
2018-07-31 13:48:42 +08:00
|
|
|
#else
|
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
#endif
|
2018-07-24 11:51:22 +08:00
|
|
|
}
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
/* rdma_bind_addr will only succeed for IB & iWARP devices */
|
2018-07-24 11:51:22 +08:00
|
|
|
ret = rdma_bind_addr(cm_id, sa);
|
2009-02-24 23:30:30 +08:00
|
|
|
/* due to this, we will claim to support iWARP devices unless we
|
|
|
|
check node_type. */
|
2013-12-19 12:49:42 +08:00
|
|
|
if (ret || !cm_id->device ||
|
|
|
|
cm_id->device->node_type != RDMA_NODE_IB_CA)
|
2009-02-24 23:30:30 +08:00
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
|
2018-07-24 11:51:22 +08:00
|
|
|
rdsdebug("addr %pI6c%%%u ret %d node type %d\n",
|
|
|
|
addr, scope_id, ret,
|
2018-07-24 11:51:21 +08:00
|
|
|
cm_id->device ? cm_id->device->node_type : -1);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
2018-07-31 13:48:42 +08:00
|
|
|
out:
|
2009-02-24 23:30:30 +08:00
|
|
|
rdma_destroy_id(cm_id);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-06-26 05:59:49 +08:00
|
|
|
static void rds_ib_unregister_client(void)
|
|
|
|
{
|
|
|
|
ib_unregister_client(&rds_ib_client);
|
|
|
|
/* wait for rds_ib_dev_free() to complete */
|
|
|
|
flush_workqueue(rds_wq);
|
|
|
|
}
|
|
|
|
|
2018-02-03 20:26:51 +08:00
|
|
|
static void rds_ib_set_unloading(void)
|
|
|
|
{
|
|
|
|
atomic_set(&rds_ib_unloading, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool rds_ib_is_unloading(struct rds_connection *conn)
|
|
|
|
{
|
|
|
|
struct rds_conn_path *cp = &conn->c_path[0];
|
|
|
|
|
|
|
|
return (test_bit(RDS_DESTROY_PENDING, &cp->cp_flags) ||
|
|
|
|
atomic_read(&rds_ib_unloading) != 0);
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
void rds_ib_exit(void)
|
|
|
|
{
|
2018-02-03 20:26:51 +08:00
|
|
|
rds_ib_set_unloading();
|
|
|
|
synchronize_rcu();
|
2009-02-24 23:30:30 +08:00
|
|
|
rds_info_deregister_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:23 +08:00
|
|
|
rds_info_deregister_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
|
2018-07-31 13:48:42 +08:00
|
|
|
#endif
|
2010-06-26 05:59:49 +08:00
|
|
|
rds_ib_unregister_client();
|
2010-06-26 05:58:16 +08:00
|
|
|
rds_ib_destroy_nodev_conns();
|
2009-02-24 23:30:30 +08:00
|
|
|
rds_ib_sysctl_exit();
|
|
|
|
rds_ib_recv_exit();
|
|
|
|
rds_trans_unregister(&rds_ib_transport);
|
2016-03-02 07:20:46 +08:00
|
|
|
rds_ib_mr_exit();
|
2009-02-24 23:30:30 +08:00
|
|
|
}
|
|
|
|
|
2018-10-13 21:36:49 +08:00
|
|
|
static u8 rds_ib_get_tos_map(u8 tos)
|
|
|
|
{
|
|
|
|
/* 1:1 user to transport map for RDMA transport.
|
|
|
|
* In future, if custom map is desired, hook can export
|
|
|
|
* user configurable map.
|
|
|
|
*/
|
|
|
|
return tos;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
struct rds_transport rds_ib_transport = {
|
|
|
|
.laddr_check = rds_ib_laddr_check,
|
2016-07-01 07:11:10 +08:00
|
|
|
.xmit_path_complete = rds_ib_xmit_path_complete,
|
2009-02-24 23:30:30 +08:00
|
|
|
.xmit = rds_ib_xmit,
|
|
|
|
.xmit_rdma = rds_ib_xmit_rdma,
|
2010-01-13 06:33:38 +08:00
|
|
|
.xmit_atomic = rds_ib_xmit_atomic,
|
2016-07-01 07:11:15 +08:00
|
|
|
.recv_path = rds_ib_recv_path,
|
2009-02-24 23:30:30 +08:00
|
|
|
.conn_alloc = rds_ib_conn_alloc,
|
|
|
|
.conn_free = rds_ib_conn_free,
|
2016-07-01 07:11:16 +08:00
|
|
|
.conn_path_connect = rds_ib_conn_path_connect,
|
2016-07-01 07:11:10 +08:00
|
|
|
.conn_path_shutdown = rds_ib_conn_path_shutdown,
|
2009-02-24 23:30:30 +08:00
|
|
|
.inc_copy_to_user = rds_ib_inc_copy_to_user,
|
|
|
|
.inc_free = rds_ib_inc_free,
|
|
|
|
.cm_initiate_connect = rds_ib_cm_initiate_connect,
|
|
|
|
.cm_handle_connect = rds_ib_cm_handle_connect,
|
|
|
|
.cm_connect_complete = rds_ib_cm_connect_complete,
|
|
|
|
.stats_info_copy = rds_ib_stats_info_copy,
|
|
|
|
.exit = rds_ib_exit,
|
|
|
|
.get_mr = rds_ib_get_mr,
|
|
|
|
.sync_mr = rds_ib_sync_mr,
|
|
|
|
.free_mr = rds_ib_free_mr,
|
|
|
|
.flush_mrs = rds_ib_flush_mrs,
|
2018-10-13 21:36:49 +08:00
|
|
|
.get_tos_map = rds_ib_get_tos_map,
|
2009-02-24 23:30:30 +08:00
|
|
|
.t_owner = THIS_MODULE,
|
|
|
|
.t_name = "infiniband",
|
2018-02-03 20:26:51 +08:00
|
|
|
.t_unloading = rds_ib_is_unloading,
|
2009-08-21 20:28:34 +08:00
|
|
|
.t_type = RDS_TRANS_IB
|
2009-02-24 23:30:30 +08:00
|
|
|
};
|
|
|
|
|
2010-07-10 03:26:20 +08:00
|
|
|
int rds_ib_init(void)
|
2009-02-24 23:30:30 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&rds_ib_devices);
|
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
ret = rds_ib_mr_init();
|
2010-07-07 06:09:56 +08:00
|
|
|
if (ret)
|
2011-02-01 18:42:43 +08:00
|
|
|
goto out;
|
2010-07-07 06:09:56 +08:00
|
|
|
|
2015-08-26 03:02:01 +08:00
|
|
|
ret = ib_register_client(&rds_ib_client);
|
|
|
|
if (ret)
|
2016-03-02 07:20:46 +08:00
|
|
|
goto out_mr_exit;
|
2015-08-26 03:02:01 +08:00
|
|
|
|
2009-02-24 23:30:30 +08:00
|
|
|
ret = rds_ib_sysctl_init();
|
|
|
|
if (ret)
|
|
|
|
goto out_ibreg;
|
|
|
|
|
|
|
|
ret = rds_ib_recv_init();
|
|
|
|
if (ret)
|
|
|
|
goto out_sysctl;
|
|
|
|
|
2017-03-03 13:44:26 +08:00
|
|
|
rds_trans_register(&rds_ib_transport);
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:23 +08:00
|
|
|
rds_info_register_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
|
2018-07-31 13:48:42 +08:00
|
|
|
#endif
|
2009-02-24 23:30:30 +08:00
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out_sysctl:
|
|
|
|
rds_ib_sysctl_exit();
|
|
|
|
out_ibreg:
|
2010-06-26 05:59:49 +08:00
|
|
|
rds_ib_unregister_client();
|
2016-03-02 07:20:46 +08:00
|
|
|
out_mr_exit:
|
|
|
|
rds_ib_mr_exit();
|
2009-02-24 23:30:30 +08:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|