2006-12-01 08:53:41 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005-2006 Intel Corporation. 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/completion.h>
|
2007-11-14 16:29:50 +08:00
|
|
|
#include <linux/file.h>
|
2006-12-01 08:53:41 +08:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/poll.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2006-12-01 08:53:41 +08:00
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <linux/miscdevice.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>
|
2010-08-14 04:56:34 +08:00
|
|
|
#include <linux/sysctl.h>
|
2011-05-28 03:35:46 +08:00
|
|
|
#include <linux/module.h>
|
2015-10-22 20:20:11 +08:00
|
|
|
#include <linux/nsproxy.h>
|
2006-12-01 08:53:41 +08:00
|
|
|
|
2018-10-16 22:59:01 +08:00
|
|
|
#include <linux/nospec.h>
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
#include <rdma/rdma_user_cm.h>
|
|
|
|
#include <rdma/ib_marshall.h>
|
|
|
|
#include <rdma/rdma_cm.h>
|
2009-11-17 01:30:33 +08:00
|
|
|
#include <rdma/rdma_cm_ib.h>
|
2013-05-30 01:09:25 +08:00
|
|
|
#include <rdma/ib_addr.h>
|
2013-05-30 01:09:29 +08:00
|
|
|
#include <rdma/ib.h>
|
2019-06-14 08:38:19 +08:00
|
|
|
#include <rdma/rdma_netlink.h>
|
|
|
|
#include "core_priv.h"
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Sean Hefty");
|
|
|
|
MODULE_DESCRIPTION("RDMA Userspace Connection Manager Access");
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
|
2010-08-14 04:56:34 +08:00
|
|
|
static unsigned int max_backlog = 1024;
|
|
|
|
|
|
|
|
static struct ctl_table_header *ucma_ctl_table_hdr;
|
2013-10-23 06:29:50 +08:00
|
|
|
static struct ctl_table ucma_ctl_table[] = {
|
2010-08-14 04:56:34 +08:00
|
|
|
{
|
|
|
|
.procname = "max_backlog",
|
|
|
|
.data = &max_backlog,
|
|
|
|
.maxlen = sizeof max_backlog,
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
struct ucma_file {
|
|
|
|
struct mutex mut;
|
|
|
|
struct file *filp;
|
|
|
|
struct list_head ctx_list;
|
|
|
|
struct list_head event_list;
|
|
|
|
wait_queue_head_t poll_wait;
|
2015-08-13 23:32:07 +08:00
|
|
|
struct workqueue_struct *close_wq;
|
2006-12-01 08:53:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ucma_context {
|
2019-02-21 08:21:05 +08:00
|
|
|
u32 id;
|
2006-12-01 08:53:41 +08:00
|
|
|
struct completion comp;
|
|
|
|
atomic_t ref;
|
|
|
|
int events_reported;
|
|
|
|
int backlog;
|
|
|
|
|
|
|
|
struct ucma_file *file;
|
|
|
|
struct rdma_cm_id *cm_id;
|
|
|
|
u64 uid;
|
|
|
|
|
|
|
|
struct list_head list;
|
2007-02-16 09:00:18 +08:00
|
|
|
struct list_head mc_list;
|
2015-08-13 23:32:07 +08:00
|
|
|
/* mark that device is in process of destroying the internal HW
|
2019-02-21 08:21:05 +08:00
|
|
|
* resources, protected by the ctx_table lock
|
2015-08-13 23:32:07 +08:00
|
|
|
*/
|
|
|
|
int closing;
|
|
|
|
/* sync between removal event and id destroy, protected by file mut */
|
|
|
|
int destroying;
|
|
|
|
struct work_struct close_work;
|
2007-02-16 09:00:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ucma_multicast {
|
|
|
|
struct ucma_context *ctx;
|
2019-02-21 08:21:04 +08:00
|
|
|
u32 id;
|
2007-02-16 09:00:18 +08:00
|
|
|
int events_reported;
|
|
|
|
|
|
|
|
u64 uid;
|
2016-07-06 21:36:35 +08:00
|
|
|
u8 join_state;
|
2007-02-16 09:00:18 +08:00
|
|
|
struct list_head list;
|
2008-08-05 02:02:14 +08:00
|
|
|
struct sockaddr_storage addr;
|
2006-12-01 08:53:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ucma_event {
|
|
|
|
struct ucma_context *ctx;
|
2007-02-16 09:00:18 +08:00
|
|
|
struct ucma_multicast *mc;
|
2006-12-01 08:53:41 +08:00
|
|
|
struct list_head list;
|
|
|
|
struct rdma_cm_id *cm_id;
|
|
|
|
struct rdma_ucm_event_resp resp;
|
2015-08-13 23:32:07 +08:00
|
|
|
struct work_struct close_work;
|
2006-12-01 08:53:41 +08:00
|
|
|
};
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
static DEFINE_XARRAY_ALLOC(ctx_table);
|
2019-02-21 08:21:04 +08:00
|
|
|
static DEFINE_XARRAY_ALLOC(multicast_table);
|
2006-12-01 08:53:41 +08:00
|
|
|
|
2018-09-04 00:54:14 +08:00
|
|
|
static const struct file_operations ucma_fops;
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static inline struct ucma_context *_ucma_find_context(int id,
|
|
|
|
struct ucma_file *file)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
ctx = xa_load(&ctx_table, id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (!ctx)
|
|
|
|
ctx = ERR_PTR(-ENOENT);
|
2018-03-20 23:05:13 +08:00
|
|
|
else if (ctx->file != file || !ctx->cm_id)
|
2006-12-01 08:53:41 +08:00
|
|
|
ctx = ERR_PTR(-EINVAL);
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_lock(&ctx_table);
|
2006-12-01 08:53:41 +08:00
|
|
|
ctx = _ucma_find_context(id, file);
|
2015-08-13 23:32:07 +08:00
|
|
|
if (!IS_ERR(ctx)) {
|
|
|
|
if (ctx->closing)
|
|
|
|
ctx = ERR_PTR(-EIO);
|
|
|
|
else
|
|
|
|
atomic_inc(&ctx->ref);
|
|
|
|
}
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2006-12-01 08:53:41 +08:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_put_ctx(struct ucma_context *ctx)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&ctx->ref))
|
|
|
|
complete(&ctx->comp);
|
|
|
|
}
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
/*
|
|
|
|
* Same as ucm_get_ctx but requires that ->cm_id->device is valid, eg that the
|
|
|
|
* CM_ID is bound.
|
|
|
|
*/
|
|
|
|
static struct ucma_context *ucma_get_ctx_dev(struct ucma_file *file, int id)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx = ucma_get_ctx(file, id);
|
|
|
|
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return ctx;
|
|
|
|
if (!ctx->cm_id->device) {
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:32:07 +08:00
|
|
|
static void ucma_close_event_id(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ucma_event *uevent_close = container_of(work, struct ucma_event, close_work);
|
|
|
|
|
|
|
|
rdma_destroy_id(uevent_close->cm_id);
|
|
|
|
kfree(uevent_close);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_close_id(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx = container_of(work, struct ucma_context, close_work);
|
|
|
|
|
|
|
|
/* once all inflight tasks are finished, we close all underlying
|
|
|
|
* resources. The context is still alive till its explicit destryoing
|
|
|
|
* by its creator.
|
|
|
|
*/
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
wait_for_completion(&ctx->comp);
|
|
|
|
/* No new events will be generated after destroying the id. */
|
|
|
|
rdma_destroy_id(ctx->cm_id);
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
|
2015-08-13 23:32:07 +08:00
|
|
|
INIT_WORK(&ctx->close_work, ucma_close_id);
|
2006-12-01 08:53:41 +08:00
|
|
|
atomic_set(&ctx->ref, 1);
|
|
|
|
init_completion(&ctx->comp);
|
2007-02-16 09:00:18 +08:00
|
|
|
INIT_LIST_HEAD(&ctx->mc_list);
|
2006-12-01 08:53:41 +08:00
|
|
|
ctx->file = file;
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
if (xa_alloc(&ctx_table, &ctx->id, ctx, xa_limit_32b, GFP_KERNEL))
|
2006-12-01 08:53:41 +08:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
list_add_tail(&ctx->list, &file->ctx_list);
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
error:
|
|
|
|
kfree(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-16 09:00:18 +08:00
|
|
|
static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
|
|
|
|
{
|
|
|
|
struct ucma_multicast *mc;
|
|
|
|
|
|
|
|
mc = kzalloc(sizeof(*mc), GFP_KERNEL);
|
|
|
|
if (!mc)
|
|
|
|
return NULL;
|
|
|
|
|
2019-02-21 08:21:04 +08:00
|
|
|
mc->ctx = ctx;
|
|
|
|
if (xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b, GFP_KERNEL))
|
2007-02-16 09:00:18 +08:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
list_add_tail(&mc->list, &ctx->mc_list);
|
|
|
|
return mc;
|
|
|
|
|
|
|
|
error:
|
|
|
|
kfree(mc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst,
|
|
|
|
struct rdma_conn_param *src)
|
|
|
|
{
|
|
|
|
if (src->private_data_len)
|
|
|
|
memcpy(dst->private_data, src->private_data,
|
|
|
|
src->private_data_len);
|
|
|
|
dst->private_data_len = src->private_data_len;
|
|
|
|
dst->responder_resources =src->responder_resources;
|
|
|
|
dst->initiator_depth = src->initiator_depth;
|
|
|
|
dst->flow_control = src->flow_control;
|
|
|
|
dst->retry_count = src->retry_count;
|
|
|
|
dst->rnr_retry_count = src->rnr_retry_count;
|
|
|
|
dst->srq = src->srq;
|
|
|
|
dst->qp_num = src->qp_num;
|
|
|
|
}
|
|
|
|
|
2017-06-09 01:37:43 +08:00
|
|
|
static void ucma_copy_ud_event(struct ib_device *device,
|
|
|
|
struct rdma_ucm_ud_param *dst,
|
2006-12-01 08:53:41 +08:00
|
|
|
struct rdma_ud_param *src)
|
|
|
|
{
|
|
|
|
if (src->private_data_len)
|
|
|
|
memcpy(dst->private_data, src->private_data,
|
|
|
|
src->private_data_len);
|
|
|
|
dst->private_data_len = src->private_data_len;
|
2017-06-09 01:37:43 +08:00
|
|
|
ib_copy_ah_attr_to_user(device, &dst->ah_attr, &src->ah_attr);
|
2006-12-01 08:53:41 +08:00
|
|
|
dst->qp_num = src->qp_num;
|
|
|
|
dst->qkey = src->qkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_set_event_context(struct ucma_context *ctx,
|
|
|
|
struct rdma_cm_event *event,
|
|
|
|
struct ucma_event *uevent)
|
|
|
|
{
|
|
|
|
uevent->ctx = ctx;
|
2007-02-16 09:00:18 +08:00
|
|
|
switch (event->event) {
|
|
|
|
case RDMA_CM_EVENT_MULTICAST_JOIN:
|
|
|
|
case RDMA_CM_EVENT_MULTICAST_ERROR:
|
|
|
|
uevent->mc = (struct ucma_multicast *)
|
|
|
|
event->param.ud.private_data;
|
|
|
|
uevent->resp.uid = uevent->mc->uid;
|
|
|
|
uevent->resp.id = uevent->mc->id;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
uevent->resp.uid = ctx->uid;
|
|
|
|
uevent->resp.id = ctx->id;
|
|
|
|
break;
|
|
|
|
}
|
2006-12-01 08:53:41 +08:00
|
|
|
}
|
|
|
|
|
2015-08-13 23:32:07 +08:00
|
|
|
/* Called with file->mut locked for the relevant context. */
|
|
|
|
static void ucma_removal_event_handler(struct rdma_cm_id *cm_id)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx = cm_id->context;
|
|
|
|
struct ucma_event *con_req_eve;
|
|
|
|
int event_found = 0;
|
|
|
|
|
|
|
|
if (ctx->destroying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* only if context is pointing to cm_id that it owns it and can be
|
|
|
|
* queued to be closed, otherwise that cm_id is an inflight one that
|
|
|
|
* is part of that context event list pending to be detached and
|
|
|
|
* reattached to its new context as part of ucma_get_event,
|
|
|
|
* handled separately below.
|
|
|
|
*/
|
|
|
|
if (ctx->cm_id == cm_id) {
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_lock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
ctx->closing = 1;
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
queue_work(ctx->file->close_wq, &ctx->close_work);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(con_req_eve, &ctx->file->event_list, list) {
|
|
|
|
if (con_req_eve->cm_id == cm_id &&
|
|
|
|
con_req_eve->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST) {
|
|
|
|
list_del(&con_req_eve->list);
|
|
|
|
INIT_WORK(&con_req_eve->close_work, ucma_close_event_id);
|
|
|
|
queue_work(ctx->file->close_wq, &con_req_eve->close_work);
|
|
|
|
event_found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!event_found)
|
2016-03-02 03:20:29 +08:00
|
|
|
pr_err("ucma_removal_event_handler: warning: connect request event wasn't found\n");
|
2015-08-13 23:32:07 +08:00
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static int ucma_event_handler(struct rdma_cm_id *cm_id,
|
|
|
|
struct rdma_cm_event *event)
|
|
|
|
{
|
|
|
|
struct ucma_event *uevent;
|
|
|
|
struct ucma_context *ctx = cm_id->context;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
uevent = kzalloc(sizeof(*uevent), GFP_KERNEL);
|
|
|
|
if (!uevent)
|
|
|
|
return event->event == RDMA_CM_EVENT_CONNECT_REQUEST;
|
|
|
|
|
2012-08-04 07:59:41 +08:00
|
|
|
mutex_lock(&ctx->file->mut);
|
2006-12-01 08:53:41 +08:00
|
|
|
uevent->cm_id = cm_id;
|
|
|
|
ucma_set_event_context(ctx, event, uevent);
|
|
|
|
uevent->resp.event = event->event;
|
|
|
|
uevent->resp.status = event->status;
|
2011-06-15 07:31:53 +08:00
|
|
|
if (cm_id->qp_type == IB_QPT_UD)
|
2017-06-09 01:37:43 +08:00
|
|
|
ucma_copy_ud_event(cm_id->device, &uevent->resp.param.ud,
|
|
|
|
&event->param.ud);
|
2006-12-01 08:53:41 +08:00
|
|
|
else
|
|
|
|
ucma_copy_conn_event(&uevent->resp.param.conn,
|
|
|
|
&event->param.conn);
|
|
|
|
|
|
|
|
if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
|
|
|
|
if (!ctx->backlog) {
|
2007-03-07 03:58:32 +08:00
|
|
|
ret = -ENOMEM;
|
2006-12-15 03:22:19 +08:00
|
|
|
kfree(uevent);
|
2006-12-01 08:53:41 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ctx->backlog--;
|
2013-11-02 05:39:50 +08:00
|
|
|
} else if (!ctx->uid || ctx->cm_id != cm_id) {
|
2007-01-06 04:35:15 +08:00
|
|
|
/*
|
|
|
|
* We ignore events for new connections until userspace has set
|
|
|
|
* their context. This can only happen if an error occurs on a
|
|
|
|
* new connection before the user accepts it. This is okay,
|
2015-08-13 23:32:07 +08:00
|
|
|
* since the accept will just fail later. However, we do need
|
|
|
|
* to release the underlying HW resources in case of a device
|
|
|
|
* removal event.
|
2007-01-06 04:35:15 +08:00
|
|
|
*/
|
2015-08-13 23:32:07 +08:00
|
|
|
if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL)
|
|
|
|
ucma_removal_event_handler(cm_id);
|
|
|
|
|
2007-01-06 04:35:15 +08:00
|
|
|
kfree(uevent);
|
|
|
|
goto out;
|
2006-12-01 08:53:41 +08:00
|
|
|
}
|
2007-01-06 04:35:15 +08:00
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
list_add_tail(&uevent->list, &ctx->file->event_list);
|
|
|
|
wake_up_interruptible(&ctx->file->poll_wait);
|
2015-08-13 23:32:07 +08:00
|
|
|
if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL)
|
|
|
|
ucma_removal_event_handler(cm_id);
|
2006-12-01 08:53:41 +08:00
|
|
|
out:
|
|
|
|
mutex_unlock(&ctx->file->mut);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
struct rdma_ucm_get_event cmd;
|
|
|
|
struct ucma_event *uevent;
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-03-21 04:19:47 +08:00
|
|
|
/*
|
|
|
|
* Old 32 bit user space does not send the 4 byte padding in the
|
|
|
|
* reserved field. We don't care, allow it to keep working.
|
|
|
|
*/
|
|
|
|
if (out_len < sizeof(uevent->resp) - sizeof(uevent->resp.reserved))
|
2006-12-01 08:53:41 +08:00
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
mutex_lock(&file->mut);
|
|
|
|
while (list_empty(&file->event_list)) {
|
2007-04-06 01:49:51 +08:00
|
|
|
mutex_unlock(&file->mut);
|
2006-12-01 08:53:41 +08:00
|
|
|
|
2007-04-06 01:49:51 +08:00
|
|
|
if (file->filp->f_flags & O_NONBLOCK)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
if (wait_event_interruptible(file->poll_wait,
|
|
|
|
!list_empty(&file->event_list)))
|
|
|
|
return -ERESTARTSYS;
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
mutex_lock(&file->mut);
|
|
|
|
}
|
|
|
|
|
|
|
|
uevent = list_entry(file->event_list.next, struct ucma_event, list);
|
|
|
|
|
|
|
|
if (uevent->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST) {
|
|
|
|
ctx = ucma_alloc_ctx(file);
|
|
|
|
if (!ctx) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
uevent->ctx->backlog++;
|
|
|
|
ctx->cm_id = uevent->cm_id;
|
|
|
|
ctx->cm_id->context = ctx;
|
|
|
|
uevent->resp.id = ctx->id;
|
|
|
|
}
|
|
|
|
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2018-03-21 04:19:47 +08:00
|
|
|
&uevent->resp,
|
|
|
|
min_t(size_t, out_len, sizeof(uevent->resp)))) {
|
2006-12-01 08:53:41 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_del(&uevent->list);
|
|
|
|
uevent->ctx->events_reported++;
|
2007-02-16 09:00:18 +08:00
|
|
|
if (uevent->mc)
|
|
|
|
uevent->mc->events_reported++;
|
2006-12-01 08:53:41 +08:00
|
|
|
kfree(uevent);
|
|
|
|
done:
|
|
|
|
mutex_unlock(&file->mut);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-02 01:08:41 +08:00
|
|
|
static int ucma_get_qp_type(struct rdma_ucm_create_id *cmd, enum ib_qp_type *qp_type)
|
|
|
|
{
|
|
|
|
switch (cmd->ps) {
|
|
|
|
case RDMA_PS_TCP:
|
|
|
|
*qp_type = IB_QPT_RC;
|
|
|
|
return 0;
|
|
|
|
case RDMA_PS_UDP:
|
|
|
|
case RDMA_PS_IPOIB:
|
|
|
|
*qp_type = IB_QPT_UD;
|
|
|
|
return 0;
|
2011-06-15 07:31:53 +08:00
|
|
|
case RDMA_PS_IB:
|
|
|
|
*qp_type = cmd->qp_type;
|
|
|
|
return 0;
|
2010-04-02 01:08:41 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
2006-12-01 08:53:41 +08:00
|
|
|
{
|
|
|
|
struct rdma_ucm_create_id cmd;
|
|
|
|
struct rdma_ucm_create_id_resp resp;
|
|
|
|
struct ucma_context *ctx;
|
2018-03-20 23:05:13 +08:00
|
|
|
struct rdma_cm_id *cm_id;
|
2010-04-02 01:08:41 +08:00
|
|
|
enum ib_qp_type qp_type;
|
2006-12-01 08:53:41 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2010-04-02 01:08:41 +08:00
|
|
|
ret = ucma_get_qp_type(&cmd, &qp_type);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
mutex_lock(&file->mut);
|
|
|
|
ctx = ucma_alloc_ctx(file);
|
|
|
|
mutex_unlock(&file->mut);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ctx->uid = cmd.uid;
|
Merge candidates for 4.17 merge window
- Fix RDMA uapi headers to actually compile in userspace and be more
complete
- Three shared with netdev pull requests from Mellanox:
* 7 patches, mostly to net with 1 IB related one at the back). This
series addresses an IRQ performance issue (patch 1), cleanups related to
the fix for the IRQ performance problem (patches 2-6), and then extends
the fragmented completion queue support that already exists in the net
side of the driver to the ib side of the driver (patch 7).
* Mostly IB, with 5 patches to net that are needed to support the remaining
10 patches to the IB subsystem. This series extends the current
'representor' framework when the mlx5 driver is in switchdev mode from
being a netdev only construct to being a netdev/IB dev construct. The IB
dev is limited to raw Eth queue pairs only, but by having an IB dev of
this type attached to the representor for a switchdev port, it enables
DPDK to work on the switchdev device.
* All net related, but needed as infrastructure for the rdma driver
- Updates for the hns, i40iw, bnxt_re, cxgb3, cxgb4, hns drivers
- SRP performance updates
- IB uverbs write path cleanup patch series from Leon
- Add RDMA_CM support to ib_srpt. This is disabled by default. Users need to
set the port for ib_srpt to listen on in configfs in order for it to be
enabled (/sys/kernel/config/target/srpt/discovery_auth/rdma_cm_port)
- TSO and Scatter FCS support in mlx4
- Refactor of modify_qp routine to resolve problems seen while working on new
code that is forthcoming
- More refactoring and updates of RDMA CM for containers support from Parav
- mlx5 'fine grained packet pacing', 'ipsec offload' and 'device memory'
user API features
- Infrastructure updates for the new IOCTL interface, based on increased usage
- ABI compatibility bug fixes to fully support 32 bit userspace on 64 bit
kernel as was originally intended. See the commit messages for
extensive details
- Syzkaller bugs and code cleanups motivated by them
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAABCgAGBQJax5Z0AAoJEDht9xV+IJsacCwQAJBIgmLCvVp5fBu2kJcXMMVI
y3l2YNzAUJvDDKv1r5yTC9ugBXEkDtgzi/W/C2/5es2yUG/QeT/zzQ3YPrtsnN68
5FkiXQ35Tt7+PBHMr0cacGRmF4M3Td3MeW0X5aJaBKhqlNKwA+aF18pjGWBmpVYx
URYCwLb5BZBKVh4+1Leebsk4i0/7jSauAqE5M+9notuAUfBCoY1/Eve3DipEIBBp
EyrEnMDIdujYRsg4KHlxFKKJ1EFGItknLQbNL1+SEa0Oe0SnEl5Bd53Yxfz7ekNP
oOWQe5csTcs3Yr4Ob0TC+69CzI71zKbz6qPDILTwXmsPFZJ9ipJs4S8D6F7ra8tb
D5aT1EdRzh/vAORPC9T3DQ3VsHdvhwpUMG7knnKrVT9X/g7E+gSji1BqaQaTr/xs
i40GepHT7lM/TWEuee/6LRpqdhuOhud7vfaRFwn2JGRX9suqTcvwhkBkPUDGV5XX
5RkHcWOb/7KvmpG7S1gaRGK5kO208LgmAZi7REaJFoZB74FqSneMR6NHIH07ha41
Zou7rnxV68CT2bgu27m+72EsprgmBkVDeEzXgKxVI/+PZ1oadUFpgcZ3pRLOPWVx
rEqjHu65rlA/YPog4iXQaMfSwt/oRD3cVJS/n8EdJKXi4Qt2RDDGdyOmt74w4prM
QuLEdvJIFmwrND1KDoqn
=Ku8g
-----END PGP SIGNATURE-----
Merge tag 'for-linus-unmerged' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
Pull rdma updates from Jason Gunthorpe:
"Doug and I are at a conference next week so if another PR is sent I
expect it to only be bug fixes. Parav noted yesterday that there are
some fringe case behavior changes in his work that he would like to
fix, and I see that Intel has a number of rc looking patches for HFI1
they posted yesterday.
Parav is again the biggest contributor by patch count with his ongoing
work to enable container support in the RDMA stack, followed by Leon
doing syzkaller inspired cleanups, though most of the actual fixing
went to RC.
There is one uncomfortable series here fixing the user ABI to actually
work as intended in 32 bit mode. There are lots of notes in the commit
messages, but the basic summary is we don't think there is an actual
32 bit kernel user of drivers/infiniband for several good reasons.
However we are seeing people want to use a 32 bit user space with 64
bit kernel, which didn't completely work today. So in fixing it we
required a 32 bit rxe user to upgrade their userspace. rxe users are
still already quite rare and we think a 32 bit one is non-existing.
- Fix RDMA uapi headers to actually compile in userspace and be more
complete
- Three shared with netdev pull requests from Mellanox:
* 7 patches, mostly to net with 1 IB related one at the back).
This series addresses an IRQ performance issue (patch 1),
cleanups related to the fix for the IRQ performance problem
(patches 2-6), and then extends the fragmented completion queue
support that already exists in the net side of the driver to the
ib side of the driver (patch 7).
* Mostly IB, with 5 patches to net that are needed to support the
remaining 10 patches to the IB subsystem. This series extends
the current 'representor' framework when the mlx5 driver is in
switchdev mode from being a netdev only construct to being a
netdev/IB dev construct. The IB dev is limited to raw Eth queue
pairs only, but by having an IB dev of this type attached to the
representor for a switchdev port, it enables DPDK to work on the
switchdev device.
* All net related, but needed as infrastructure for the rdma
driver
- Updates for the hns, i40iw, bnxt_re, cxgb3, cxgb4, hns drivers
- SRP performance updates
- IB uverbs write path cleanup patch series from Leon
- Add RDMA_CM support to ib_srpt. This is disabled by default. Users
need to set the port for ib_srpt to listen on in configfs in order
for it to be enabled
(/sys/kernel/config/target/srpt/discovery_auth/rdma_cm_port)
- TSO and Scatter FCS support in mlx4
- Refactor of modify_qp routine to resolve problems seen while
working on new code that is forthcoming
- More refactoring and updates of RDMA CM for containers support from
Parav
- mlx5 'fine grained packet pacing', 'ipsec offload' and 'device
memory' user API features
- Infrastructure updates for the new IOCTL interface, based on
increased usage
- ABI compatibility bug fixes to fully support 32 bit userspace on 64
bit kernel as was originally intended. See the commit messages for
extensive details
- Syzkaller bugs and code cleanups motivated by them"
* tag 'for-linus-unmerged' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: (199 commits)
IB/rxe: Fix for oops in rxe_register_device on ppc64le arch
IB/mlx5: Device memory mr registration support
net/mlx5: Mkey creation command adjustments
IB/mlx5: Device memory support in mlx5_ib
net/mlx5: Query device memory capabilities
IB/uverbs: Add device memory registration ioctl support
IB/uverbs: Add alloc/free dm uverbs ioctl support
IB/uverbs: Add device memory capabilities reporting
IB/uverbs: Expose device memory capabilities to user
RDMA/qedr: Fix wmb usage in qedr
IB/rxe: Removed GID add/del dummy routines
RDMA/qedr: Zero stack memory before copying to user space
IB/mlx5: Add ability to hash by IPSEC_SPI when creating a TIR
IB/mlx5: Add information for querying IPsec capabilities
IB/mlx5: Add IPsec support for egress and ingress
{net,IB}/mlx5: Add ipsec helper
IB/mlx5: Add modify_flow_action_esp verb
IB/mlx5: Add implementation for create and destroy action_xfrm
IB/uverbs: Introduce ESP steering match filter
IB/uverbs: Add modify ESP flow_action
...
2018-04-07 08:35:43 +08:00
|
|
|
cm_id = __rdma_create_id(current->nsproxy->net_ns,
|
|
|
|
ucma_event_handler, ctx, cmd.ps, qp_type, NULL);
|
2018-03-20 23:05:13 +08:00
|
|
|
if (IS_ERR(cm_id)) {
|
|
|
|
ret = PTR_ERR(cm_id);
|
2006-12-01 08:53:41 +08:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.id = ctx->id;
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2006-12-01 08:53:41 +08:00
|
|
|
&resp, sizeof(resp))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err2;
|
|
|
|
}
|
2018-03-20 23:05:13 +08:00
|
|
|
|
|
|
|
ctx->cm_id = cm_id;
|
2006-12-01 08:53:41 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err2:
|
2018-03-20 23:05:13 +08:00
|
|
|
rdma_destroy_id(cm_id);
|
2006-12-01 08:53:41 +08:00
|
|
|
err1:
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_erase(&ctx_table, ctx->id);
|
2018-03-19 20:20:15 +08:00
|
|
|
mutex_lock(&file->mut);
|
|
|
|
list_del(&ctx->list);
|
|
|
|
mutex_unlock(&file->mut);
|
2006-12-01 08:53:41 +08:00
|
|
|
kfree(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-16 09:00:18 +08:00
|
|
|
static void ucma_cleanup_multicast(struct ucma_context *ctx)
|
|
|
|
{
|
|
|
|
struct ucma_multicast *mc, *tmp;
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
mutex_lock(&ctx->file->mut);
|
2007-02-16 09:00:18 +08:00
|
|
|
list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
|
|
|
|
list_del(&mc->list);
|
2019-02-21 08:21:04 +08:00
|
|
|
xa_erase(&multicast_table, mc->id);
|
2007-02-16 09:00:18 +08:00
|
|
|
kfree(mc);
|
|
|
|
}
|
2019-02-21 08:21:05 +08:00
|
|
|
mutex_unlock(&ctx->file->mut);
|
2007-02-16 09:00:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_cleanup_mc_events(struct ucma_multicast *mc)
|
|
|
|
{
|
|
|
|
struct ucma_event *uevent, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(uevent, tmp, &mc->ctx->file->event_list, list) {
|
|
|
|
if (uevent->mc != mc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(&uevent->list);
|
|
|
|
kfree(uevent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-02 08:01:19 +08:00
|
|
|
/*
|
2015-08-13 23:32:07 +08:00
|
|
|
* ucma_free_ctx is called after the underlying rdma CM-ID is destroyed. At
|
|
|
|
* this point, no new events will be reported from the hardware. However, we
|
|
|
|
* still need to cleanup the UCMA context for this ID. Specifically, there
|
|
|
|
* might be events that have not yet been consumed by the user space software.
|
|
|
|
* These might include pending connect requests which we have not completed
|
|
|
|
* processing. We cannot call rdma_destroy_id while holding the lock of the
|
|
|
|
* context (file->mut), as it might cause a deadlock. We therefore extract all
|
|
|
|
* relevant events from the context pending events list while holding the
|
|
|
|
* mutex. After that we release them as needed.
|
2012-03-02 08:01:19 +08:00
|
|
|
*/
|
2006-12-01 08:53:41 +08:00
|
|
|
static int ucma_free_ctx(struct ucma_context *ctx)
|
|
|
|
{
|
|
|
|
int events_reported;
|
2012-03-02 08:01:19 +08:00
|
|
|
struct ucma_event *uevent, *tmp;
|
|
|
|
LIST_HEAD(list);
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
|
2007-02-16 09:00:18 +08:00
|
|
|
ucma_cleanup_multicast(ctx);
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
/* Cleanup events not yet reported to the user. */
|
|
|
|
mutex_lock(&ctx->file->mut);
|
2012-03-02 08:01:19 +08:00
|
|
|
list_for_each_entry_safe(uevent, tmp, &ctx->file->event_list, list) {
|
|
|
|
if (uevent->ctx == ctx)
|
|
|
|
list_move_tail(&uevent->list, &list);
|
|
|
|
}
|
2006-12-01 08:53:41 +08:00
|
|
|
list_del(&ctx->list);
|
|
|
|
mutex_unlock(&ctx->file->mut);
|
|
|
|
|
2012-03-02 08:01:19 +08:00
|
|
|
list_for_each_entry_safe(uevent, tmp, &list, list) {
|
|
|
|
list_del(&uevent->list);
|
|
|
|
if (uevent->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST)
|
|
|
|
rdma_destroy_id(uevent->cm_id);
|
|
|
|
kfree(uevent);
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
events_reported = ctx->events_reported;
|
|
|
|
kfree(ctx);
|
|
|
|
return events_reported;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_destroy_id(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_destroy_id cmd;
|
|
|
|
struct rdma_ucm_destroy_id_resp resp;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_lock(&ctx_table);
|
2006-12-01 08:53:41 +08:00
|
|
|
ctx = _ucma_find_context(cmd.id, file);
|
|
|
|
if (!IS_ERR(ctx))
|
2019-02-21 08:21:05 +08:00
|
|
|
__xa_erase(&ctx_table, ctx->id);
|
|
|
|
xa_unlock(&ctx_table);
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2015-08-13 23:32:07 +08:00
|
|
|
mutex_lock(&ctx->file->mut);
|
|
|
|
ctx->destroying = 1;
|
|
|
|
mutex_unlock(&ctx->file->mut);
|
|
|
|
|
|
|
|
flush_workqueue(ctx->file->close_wq);
|
|
|
|
/* At this point it's guaranteed that there is no inflight
|
|
|
|
* closing task */
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_lock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
if (!ctx->closing) {
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
wait_for_completion(&ctx->comp);
|
|
|
|
rdma_destroy_id(ctx->cm_id);
|
|
|
|
} else {
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
}
|
2006-12-01 08:53:41 +08:00
|
|
|
|
2015-08-13 23:32:07 +08:00
|
|
|
resp.events_reported = ucma_free_ctx(ctx);
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2006-12-01 08:53:41 +08:00
|
|
|
&resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:30 +08:00
|
|
|
static ssize_t ucma_bind_ip(struct ucma_file *file, const char __user *inbuf,
|
2006-12-01 08:53:41 +08:00
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
2013-05-30 01:09:30 +08:00
|
|
|
struct rdma_ucm_bind_ip cmd;
|
2006-12-01 08:53:41 +08:00
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
if (!rdma_addr_size_in6(&cmd.addr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
ret = rdma_bind_addr(ctx->cm_id, (struct sockaddr *) &cmd.addr);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:31 +08:00
|
|
|
static ssize_t ucma_bind(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_bind cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
if (cmd.reserved || !cmd.addr_size ||
|
|
|
|
cmd.addr_size != rdma_addr_size_kss(&cmd.addr))
|
2013-05-30 01:09:31 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
ret = rdma_bind_addr(ctx->cm_id, (struct sockaddr *) &cmd.addr);
|
2013-05-30 01:09:31 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:30 +08:00
|
|
|
static ssize_t ucma_resolve_ip(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
2006-12-01 08:53:41 +08:00
|
|
|
{
|
2013-05-30 01:09:30 +08:00
|
|
|
struct rdma_ucm_resolve_ip cmd;
|
2006-12-01 08:53:41 +08:00
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-04-19 23:28:11 +08:00
|
|
|
if ((cmd.src_addr.sin6_family && !rdma_addr_size_in6(&cmd.src_addr)) ||
|
2018-03-29 02:27:22 +08:00
|
|
|
!rdma_addr_size_in6(&cmd.dst_addr))
|
2018-03-15 21:33:02 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
ret = rdma_resolve_addr(ctx->cm_id, (struct sockaddr *) &cmd.src_addr,
|
|
|
|
(struct sockaddr *) &cmd.dst_addr, cmd.timeout_ms);
|
2006-12-01 08:53:41 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:32 +08:00
|
|
|
static ssize_t ucma_resolve_addr(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_resolve_addr cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
if (cmd.reserved ||
|
|
|
|
(cmd.src_size && (cmd.src_size != rdma_addr_size_kss(&cmd.src_addr))) ||
|
|
|
|
!cmd.dst_size || (cmd.dst_size != rdma_addr_size_kss(&cmd.dst_addr)))
|
2013-05-30 01:09:32 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
ret = rdma_resolve_addr(ctx->cm_id, (struct sockaddr *) &cmd.src_addr,
|
|
|
|
(struct sockaddr *) &cmd.dst_addr, cmd.timeout_ms);
|
2013-05-30 01:09:32 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static ssize_t ucma_resolve_route(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_resolve_route cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd.id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
ret = rdma_resolve_route(ctx->cm_id, cmd.timeout_ms);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_copy_ib_route(struct rdma_ucm_query_route_resp *resp,
|
|
|
|
struct rdma_route *route)
|
|
|
|
{
|
|
|
|
struct rdma_dev_addr *dev_addr;
|
|
|
|
|
|
|
|
resp->num_paths = route->num_paths;
|
|
|
|
switch (route->num_paths) {
|
|
|
|
case 0:
|
|
|
|
dev_addr = &route->addr.dev_addr;
|
RDMA/cm: fix loopback address support
The RDMA CM is intended to support the use of a loopback address
when establishing a connection; however, the behavior of the CM
when loopback addresses are used is confusing and does not always
work, depending on whether loopback was specified by the server,
the client, or both.
The defined behavior of rdma_bind_addr is to associate an RDMA
device with an rdma_cm_id, as long as the user specified a non-
zero address. (ie they weren't just trying to reserve a port)
Currently, if the loopback address is passed to rdam_bind_addr,
no device is associated with the rdma_cm_id. Fix this.
If a loopback address is specified by the client as the destination
address for a connection, it will fail to establish a connection.
This is true even if the server is listing across all addresses or
on the loopback address itself. The issue is that the server tries
to translate the IP address carried in the REQ message to a local
net_device address, which fails. The translation is not needed in
this case, since the REQ carries the actual HW address that should
be used.
Finally, cleanup loopback support to be more transport neutral.
Replace separate calls to get/set the sgid and dgid from the
device address to a single call that behaves correctly depending
on the format of the device address. And support both IPv4 and
IPv6 address formats.
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
[ Fixed RDS build by s/ib_addr_get/rdma_addr_get/ - Roland ]
Signed-off-by: Roland Dreier <rolandd@cisco.com>
2009-11-20 05:26:06 +08:00
|
|
|
rdma_addr_get_dgid(dev_addr,
|
|
|
|
(union ib_gid *) &resp->ib_route[0].dgid);
|
|
|
|
rdma_addr_get_sgid(dev_addr,
|
|
|
|
(union ib_gid *) &resp->ib_route[0].sgid);
|
2006-12-01 08:53:41 +08:00
|
|
|
resp->ib_route[0].pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ib_copy_path_rec_to_user(&resp->ib_route[1],
|
|
|
|
&route->path_rec[1]);
|
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
ib_copy_path_rec_to_user(&resp->ib_route[0],
|
|
|
|
&route->path_rec[0]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 03:26:51 +08:00
|
|
|
static void ucma_copy_iboe_route(struct rdma_ucm_query_route_resp *resp,
|
|
|
|
struct rdma_route *route)
|
|
|
|
{
|
|
|
|
|
|
|
|
resp->num_paths = route->num_paths;
|
|
|
|
switch (route->num_paths) {
|
|
|
|
case 0:
|
2013-12-13 00:03:12 +08:00
|
|
|
rdma_ip2gid((struct sockaddr *)&route->addr.dst_addr,
|
|
|
|
(union ib_gid *)&resp->ib_route[0].dgid);
|
|
|
|
rdma_ip2gid((struct sockaddr *)&route->addr.src_addr,
|
|
|
|
(union ib_gid *)&resp->ib_route[0].sgid);
|
2010-10-14 03:26:51 +08:00
|
|
|
resp->ib_route[0].pkey = cpu_to_be16(0xffff);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ib_copy_path_rec_to_user(&resp->ib_route[1],
|
|
|
|
&route->path_rec[1]);
|
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
ib_copy_path_rec_to_user(&resp->ib_route[0],
|
|
|
|
&route->path_rec[0]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-21 11:40:46 +08:00
|
|
|
static void ucma_copy_iw_route(struct rdma_ucm_query_route_resp *resp,
|
|
|
|
struct rdma_route *route)
|
|
|
|
{
|
|
|
|
struct rdma_dev_addr *dev_addr;
|
|
|
|
|
|
|
|
dev_addr = &route->addr.dev_addr;
|
|
|
|
rdma_addr_get_dgid(dev_addr, (union ib_gid *) &resp->ib_route[0].dgid);
|
|
|
|
rdma_addr_get_sgid(dev_addr, (union ib_gid *) &resp->ib_route[0].sgid);
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static ssize_t ucma_query_route(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
2013-05-30 01:09:25 +08:00
|
|
|
struct rdma_ucm_query cmd;
|
2006-12-01 08:53:41 +08:00
|
|
|
struct rdma_ucm_query_route_resp resp;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
struct sockaddr *addr;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
memset(&resp, 0, sizeof resp);
|
2008-08-05 02:02:14 +08:00
|
|
|
addr = (struct sockaddr *) &ctx->cm_id->route.addr.src_addr;
|
2006-12-01 08:53:41 +08:00
|
|
|
memcpy(&resp.src_addr, addr, addr->sa_family == AF_INET ?
|
|
|
|
sizeof(struct sockaddr_in) :
|
|
|
|
sizeof(struct sockaddr_in6));
|
2008-08-05 02:02:14 +08:00
|
|
|
addr = (struct sockaddr *) &ctx->cm_id->route.addr.dst_addr;
|
2006-12-01 08:53:41 +08:00
|
|
|
memcpy(&resp.dst_addr, addr, addr->sa_family == AF_INET ?
|
|
|
|
sizeof(struct sockaddr_in) :
|
|
|
|
sizeof(struct sockaddr_in6));
|
|
|
|
if (!ctx->cm_id->device)
|
|
|
|
goto out;
|
|
|
|
|
2008-04-17 12:01:07 +08:00
|
|
|
resp.node_guid = (__force __u64) ctx->cm_id->device->node_guid;
|
2006-12-01 08:53:41 +08:00
|
|
|
resp.port_num = ctx->cm_id->port_num;
|
2015-05-05 20:50:28 +08:00
|
|
|
|
2015-05-05 20:50:36 +08:00
|
|
|
if (rdma_cap_ib_sa(ctx->cm_id->device, ctx->cm_id->port_num))
|
2015-05-05 20:50:28 +08:00
|
|
|
ucma_copy_ib_route(&resp, &ctx->cm_id->route);
|
2015-05-15 03:01:46 +08:00
|
|
|
else if (rdma_protocol_roce(ctx->cm_id->device, ctx->cm_id->port_num))
|
2015-05-05 20:50:28 +08:00
|
|
|
ucma_copy_iboe_route(&resp, &ctx->cm_id->route);
|
|
|
|
else if (rdma_protocol_iwarp(ctx->cm_id->device, ctx->cm_id->port_num))
|
2011-01-21 11:40:46 +08:00
|
|
|
ucma_copy_iw_route(&resp, &ctx->cm_id->route);
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
out:
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2006-12-01 08:53:41 +08:00
|
|
|
&resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:25 +08:00
|
|
|
static void ucma_query_device_addr(struct rdma_cm_id *cm_id,
|
|
|
|
struct rdma_ucm_query_addr_resp *resp)
|
|
|
|
{
|
|
|
|
if (!cm_id->device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
resp->node_guid = (__force __u64) cm_id->device->node_guid;
|
|
|
|
resp->port_num = cm_id->port_num;
|
|
|
|
resp->pkey = (__force __u16) cpu_to_be16(
|
|
|
|
ib_addr_get_pkey(&cm_id->route.addr.dev_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_query_addr(struct ucma_context *ctx,
|
|
|
|
void __user *response, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_query_addr_resp resp;
|
|
|
|
struct sockaddr *addr;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
memset(&resp, 0, sizeof resp);
|
|
|
|
|
|
|
|
addr = (struct sockaddr *) &ctx->cm_id->route.addr.src_addr;
|
|
|
|
resp.src_size = rdma_addr_size(addr);
|
|
|
|
memcpy(&resp.src_addr, addr, resp.src_size);
|
|
|
|
|
|
|
|
addr = (struct sockaddr *) &ctx->cm_id->route.addr.dst_addr;
|
|
|
|
resp.dst_size = rdma_addr_size(addr);
|
|
|
|
memcpy(&resp.dst_addr, addr, resp.dst_size);
|
|
|
|
|
|
|
|
ucma_query_device_addr(ctx->cm_id, &resp);
|
|
|
|
|
|
|
|
if (copy_to_user(response, &resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:27 +08:00
|
|
|
static ssize_t ucma_query_path(struct ucma_context *ctx,
|
|
|
|
void __user *response, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_query_path_resp *resp;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
if (out_len < sizeof(*resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
resp = kzalloc(out_len, GFP_KERNEL);
|
|
|
|
if (!resp)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
resp->num_paths = ctx->cm_id->route.num_paths;
|
|
|
|
for (i = 0, out_len -= sizeof(*resp);
|
|
|
|
i < resp->num_paths && out_len > sizeof(struct ib_path_rec_data);
|
|
|
|
i++, out_len -= sizeof(struct ib_path_rec_data)) {
|
2017-04-28 07:06:01 +08:00
|
|
|
struct sa_path_rec *rec = &ctx->cm_id->route.path_rec[i];
|
2013-05-30 01:09:27 +08:00
|
|
|
|
|
|
|
resp->path_data[i].flags = IB_PATH_GMP | IB_PATH_PRIMARY |
|
|
|
|
IB_PATH_BIDIRECTIONAL;
|
2018-01-08 23:04:48 +08:00
|
|
|
if (rec->rec_type == SA_PATH_REC_TYPE_OPA) {
|
2017-04-28 07:06:01 +08:00
|
|
|
struct sa_path_rec ib;
|
|
|
|
|
|
|
|
sa_convert_path_opa_to_ib(&ib, rec);
|
|
|
|
ib_sa_pack_path(&ib, &resp->path_data[i].path_rec);
|
2018-01-08 23:04:48 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
ib_sa_pack_path(rec, &resp->path_data[i].path_rec);
|
2017-04-28 07:06:01 +08:00
|
|
|
}
|
2013-05-30 01:09:27 +08:00
|
|
|
}
|
|
|
|
|
2019-06-04 23:42:22 +08:00
|
|
|
if (copy_to_user(response, resp, struct_size(resp, path_data, i)))
|
2013-05-30 01:09:27 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
kfree(resp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:29 +08:00
|
|
|
static ssize_t ucma_query_gid(struct ucma_context *ctx,
|
|
|
|
void __user *response, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_query_addr_resp resp;
|
|
|
|
struct sockaddr_ib *addr;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
memset(&resp, 0, sizeof resp);
|
|
|
|
|
|
|
|
ucma_query_device_addr(ctx->cm_id, &resp);
|
|
|
|
|
|
|
|
addr = (struct sockaddr_ib *) &resp.src_addr;
|
|
|
|
resp.src_size = sizeof(*addr);
|
|
|
|
if (ctx->cm_id->route.addr.src_addr.ss_family == AF_IB) {
|
|
|
|
memcpy(addr, &ctx->cm_id->route.addr.src_addr, resp.src_size);
|
|
|
|
} else {
|
|
|
|
addr->sib_family = AF_IB;
|
|
|
|
addr->sib_pkey = (__force __be16) resp.pkey;
|
2018-01-18 16:11:17 +08:00
|
|
|
rdma_read_gids(ctx->cm_id, (union ib_gid *)&addr->sib_addr,
|
|
|
|
NULL);
|
2013-05-30 01:09:29 +08:00
|
|
|
addr->sib_sid = rdma_get_service_id(ctx->cm_id, (struct sockaddr *)
|
|
|
|
&ctx->cm_id->route.addr.src_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = (struct sockaddr_ib *) &resp.dst_addr;
|
|
|
|
resp.dst_size = sizeof(*addr);
|
|
|
|
if (ctx->cm_id->route.addr.dst_addr.ss_family == AF_IB) {
|
|
|
|
memcpy(addr, &ctx->cm_id->route.addr.dst_addr, resp.dst_size);
|
|
|
|
} else {
|
|
|
|
addr->sib_family = AF_IB;
|
|
|
|
addr->sib_pkey = (__force __be16) resp.pkey;
|
2018-01-18 16:11:17 +08:00
|
|
|
rdma_read_gids(ctx->cm_id, NULL,
|
|
|
|
(union ib_gid *)&addr->sib_addr);
|
2013-05-30 01:09:29 +08:00
|
|
|
addr->sib_sid = rdma_get_service_id(ctx->cm_id, (struct sockaddr *)
|
|
|
|
&ctx->cm_id->route.addr.dst_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_user(response, &resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:25 +08:00
|
|
|
static ssize_t ucma_query(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_query cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
void __user *response;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-28 04:18:47 +08:00
|
|
|
response = u64_to_user_ptr(cmd.response);
|
2013-05-30 01:09:25 +08:00
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
switch (cmd.option) {
|
|
|
|
case RDMA_USER_CM_QUERY_ADDR:
|
|
|
|
ret = ucma_query_addr(ctx, response, out_len);
|
|
|
|
break;
|
2013-05-30 01:09:27 +08:00
|
|
|
case RDMA_USER_CM_QUERY_PATH:
|
|
|
|
ret = ucma_query_path(ctx, response, out_len);
|
|
|
|
break;
|
2013-05-30 01:09:29 +08:00
|
|
|
case RDMA_USER_CM_QUERY_GID:
|
|
|
|
ret = ucma_query_gid(ctx, response, out_len);
|
|
|
|
break;
|
2013-05-30 01:09:25 +08:00
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:23 +08:00
|
|
|
static void ucma_copy_conn_param(struct rdma_cm_id *id,
|
|
|
|
struct rdma_conn_param *dst,
|
2006-12-01 08:53:41 +08:00
|
|
|
struct rdma_ucm_conn_param *src)
|
|
|
|
{
|
|
|
|
dst->private_data = src->private_data;
|
|
|
|
dst->private_data_len = src->private_data_len;
|
|
|
|
dst->responder_resources =src->responder_resources;
|
|
|
|
dst->initiator_depth = src->initiator_depth;
|
|
|
|
dst->flow_control = src->flow_control;
|
|
|
|
dst->retry_count = src->retry_count;
|
|
|
|
dst->rnr_retry_count = src->rnr_retry_count;
|
|
|
|
dst->srq = src->srq;
|
|
|
|
dst->qp_num = src->qp_num;
|
2013-05-30 01:09:23 +08:00
|
|
|
dst->qkey = (id->route.addr.src_addr.ss_family == AF_IB) ? src->qkey : 0;
|
2006-12-01 08:53:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_connect(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_connect cmd;
|
|
|
|
struct rdma_conn_param conn_param;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (!cmd.conn_param.valid)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd.id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2013-05-30 01:09:23 +08:00
|
|
|
ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
|
2006-12-01 08:53:41 +08:00
|
|
|
ret = rdma_connect(ctx->cm_id, &conn_param);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_listen(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_listen cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2010-08-14 04:56:34 +08:00
|
|
|
ctx->backlog = cmd.backlog > 0 && cmd.backlog < max_backlog ?
|
|
|
|
cmd.backlog : max_backlog;
|
2006-12-01 08:53:41 +08:00
|
|
|
ret = rdma_listen(ctx->cm_id, ctx->backlog);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_accept(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_accept cmd;
|
|
|
|
struct rdma_conn_param conn_param;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd.id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
if (cmd.conn_param.valid) {
|
2013-05-30 01:09:23 +08:00
|
|
|
ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
|
2012-01-11 07:53:41 +08:00
|
|
|
mutex_lock(&file->mut);
|
2018-03-02 05:57:44 +08:00
|
|
|
ret = __rdma_accept(ctx->cm_id, &conn_param, NULL);
|
2012-01-11 07:53:41 +08:00
|
|
|
if (!ret)
|
|
|
|
ctx->uid = cmd.uid;
|
|
|
|
mutex_unlock(&file->mut);
|
2006-12-01 08:53:41 +08:00
|
|
|
} else
|
2018-03-02 05:57:44 +08:00
|
|
|
ret = __rdma_accept(ctx->cm_id, NULL, NULL);
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_reject(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_reject cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd.id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
ret = rdma_reject(ctx->cm_id, cmd.private_data, cmd.private_data_len);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_disconnect(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_disconnect cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd.id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
ret = rdma_disconnect(ctx->cm_id);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_init_qp_attr(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_init_qp_attr cmd;
|
|
|
|
struct ib_uverbs_qp_attr resp;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-08 00:49:16 +08:00
|
|
|
if (cmd.qp_state > IB_QPS_ERR)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd.id);
|
2006-12-01 08:53:41 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
resp.qp_attr_mask = 0;
|
|
|
|
memset(&qp_attr, 0, sizeof qp_attr);
|
|
|
|
qp_attr.qp_state = cmd.qp_state;
|
|
|
|
ret = rdma_init_qp_attr(ctx->cm_id, &qp_attr, &resp.qp_attr_mask);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2017-06-09 01:37:43 +08:00
|
|
|
ib_copy_qp_attr_to_user(ctx->cm_id->device, &resp, &qp_attr);
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2006-12-01 08:53:41 +08:00
|
|
|
&resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
out:
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 06:51:13 +08:00
|
|
|
static int ucma_set_option_id(struct ucma_context *ctx, int optname,
|
|
|
|
void *optval, size_t optlen)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case RDMA_OPTION_ID_TOS:
|
|
|
|
if (optlen != sizeof(u8)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rdma_set_service_type(ctx->cm_id, *((u8 *) optval));
|
|
|
|
break;
|
2011-05-10 13:06:10 +08:00
|
|
|
case RDMA_OPTION_ID_REUSEADDR:
|
|
|
|
if (optlen != sizeof(int)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = rdma_set_reuseaddr(ctx->cm_id, *((int *) optval) ? 1 : 0);
|
|
|
|
break;
|
2012-06-15 04:31:39 +08:00
|
|
|
case RDMA_OPTION_ID_AFONLY:
|
|
|
|
if (optlen != sizeof(int)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = rdma_set_afonly(ctx->cm_id, *((int *) optval) ? 1 : 0);
|
|
|
|
break;
|
2019-01-24 20:18:15 +08:00
|
|
|
case RDMA_OPTION_ID_ACK_TIMEOUT:
|
|
|
|
if (optlen != sizeof(u8)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = rdma_set_ack_timeout(ctx->cm_id, *((u8 *)optval));
|
|
|
|
break;
|
2007-08-09 06:51:13 +08:00
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-17 01:30:33 +08:00
|
|
|
static int ucma_set_ib_path(struct ucma_context *ctx,
|
|
|
|
struct ib_path_rec_data *path_data, size_t optlen)
|
|
|
|
{
|
2017-04-28 07:05:58 +08:00
|
|
|
struct sa_path_rec sa_path;
|
2009-11-17 01:30:33 +08:00
|
|
|
struct rdma_cm_event event;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (optlen % sizeof(*path_data))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (; optlen; optlen -= sizeof(*path_data), path_data++) {
|
|
|
|
if (path_data->flags == (IB_PATH_GMP | IB_PATH_PRIMARY |
|
|
|
|
IB_PATH_BIDIRECTIONAL))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!optlen)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-04-04 06:33:01 +08:00
|
|
|
if (!ctx->cm_id->device)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-02-05 19:53:48 +08:00
|
|
|
memset(&sa_path, 0, sizeof(sa_path));
|
|
|
|
|
2017-04-28 07:06:01 +08:00
|
|
|
sa_path.rec_type = SA_PATH_REC_TYPE_IB;
|
2009-11-17 01:30:33 +08:00
|
|
|
ib_sa_unpack_path(path_data->path_rec, &sa_path);
|
2017-04-28 07:06:01 +08:00
|
|
|
|
|
|
|
if (rdma_cap_opa_ah(ctx->cm_id->device, ctx->cm_id->port_num)) {
|
|
|
|
struct sa_path_rec opa;
|
|
|
|
|
|
|
|
sa_convert_path_ib_to_opa(&opa, &sa_path);
|
2018-01-08 23:04:45 +08:00
|
|
|
ret = rdma_set_ib_path(ctx->cm_id, &opa);
|
2017-04-28 07:06:01 +08:00
|
|
|
} else {
|
2018-01-08 23:04:45 +08:00
|
|
|
ret = rdma_set_ib_path(ctx->cm_id, &sa_path);
|
2017-04-28 07:06:01 +08:00
|
|
|
}
|
2009-11-17 01:30:33 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memset(&event, 0, sizeof event);
|
|
|
|
event.event = RDMA_CM_EVENT_ROUTE_RESOLVED;
|
|
|
|
return ucma_event_handler(ctx->cm_id, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ucma_set_option_ib(struct ucma_context *ctx, int optname,
|
|
|
|
void *optval, size_t optlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case RDMA_OPTION_IB_PATH:
|
|
|
|
ret = ucma_set_ib_path(ctx, optval, optlen);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 06:51:13 +08:00
|
|
|
static int ucma_set_option_level(struct ucma_context *ctx, int level,
|
|
|
|
int optname, void *optval, size_t optlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case RDMA_OPTION_ID:
|
|
|
|
ret = ucma_set_option_id(ctx, optname, optval, optlen);
|
|
|
|
break;
|
2009-11-17 01:30:33 +08:00
|
|
|
case RDMA_OPTION_IB:
|
|
|
|
ret = ucma_set_option_ib(ctx, optname, optval, optlen);
|
|
|
|
break;
|
2007-08-09 06:51:13 +08:00
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_set_option cmd;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
void *optval;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-04-10 22:26:23 +08:00
|
|
|
if (unlikely(cmd.optlen > KMALLOC_MAX_SIZE))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-08-09 06:51:13 +08:00
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2018-03-28 04:18:47 +08:00
|
|
|
optval = memdup_user(u64_to_user_ptr(cmd.optval),
|
2012-07-28 04:27:45 +08:00
|
|
|
cmd.optlen);
|
|
|
|
if (IS_ERR(optval)) {
|
|
|
|
ret = PTR_ERR(optval);
|
|
|
|
goto out;
|
2007-08-09 06:51:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
|
|
|
|
cmd.optlen);
|
|
|
|
kfree(optval);
|
2012-07-28 04:27:45 +08:00
|
|
|
|
|
|
|
out:
|
2007-08-09 06:51:13 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static ssize_t ucma_notify(struct ucma_file *file, const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_notify cmd;
|
|
|
|
struct ucma_context *ctx;
|
2018-03-25 16:39:05 +08:00
|
|
|
int ret = -EINVAL;
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
ctx = ucma_get_ctx(file, cmd.id);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
2018-03-25 16:39:05 +08:00
|
|
|
if (ctx->cm_id->device)
|
|
|
|
ret = rdma_notify(ctx->cm_id, (enum ib_event_type)cmd.event);
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:33 +08:00
|
|
|
static ssize_t ucma_process_join(struct ucma_file *file,
|
|
|
|
struct rdma_ucm_join_mcast *cmd, int out_len)
|
2007-02-16 09:00:18 +08:00
|
|
|
{
|
|
|
|
struct rdma_ucm_create_id_resp resp;
|
|
|
|
struct ucma_context *ctx;
|
|
|
|
struct ucma_multicast *mc;
|
2013-05-30 01:09:33 +08:00
|
|
|
struct sockaddr *addr;
|
2007-02-16 09:00:18 +08:00
|
|
|
int ret;
|
2016-07-06 21:36:35 +08:00
|
|
|
u8 join_state;
|
2007-02-16 09:00:18 +08:00
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
2013-05-30 01:09:33 +08:00
|
|
|
addr = (struct sockaddr *) &cmd->addr;
|
2018-03-14 00:37:27 +08:00
|
|
|
if (cmd->addr_size != rdma_addr_size(addr))
|
2016-07-06 21:36:35 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (cmd->join_flags == RDMA_MC_JOIN_FLAG_FULLMEMBER)
|
|
|
|
join_state = BIT(FULLMEMBER_JOIN);
|
|
|
|
else if (cmd->join_flags == RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER)
|
|
|
|
join_state = BIT(SENDONLY_FULLMEMBER_JOIN);
|
|
|
|
else
|
2013-05-30 01:09:33 +08:00
|
|
|
return -EINVAL;
|
2007-02-16 09:00:18 +08:00
|
|
|
|
2018-04-05 11:00:01 +08:00
|
|
|
ctx = ucma_get_ctx_dev(file, cmd->id);
|
2007-02-16 09:00:18 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
|
|
|
|
|
|
|
mutex_lock(&file->mut);
|
|
|
|
mc = ucma_alloc_multicast(ctx);
|
2008-10-11 03:00:19 +08:00
|
|
|
if (!mc) {
|
|
|
|
ret = -ENOMEM;
|
2007-02-16 09:00:18 +08:00
|
|
|
goto err1;
|
|
|
|
}
|
2016-07-06 21:36:35 +08:00
|
|
|
mc->join_state = join_state;
|
2013-05-30 01:09:33 +08:00
|
|
|
mc->uid = cmd->uid;
|
|
|
|
memcpy(&mc->addr, addr, cmd->addr_size);
|
2016-07-06 21:36:35 +08:00
|
|
|
ret = rdma_join_multicast(ctx->cm_id, (struct sockaddr *)&mc->addr,
|
|
|
|
join_state, mc);
|
2007-02-16 09:00:18 +08:00
|
|
|
if (ret)
|
|
|
|
goto err2;
|
|
|
|
|
|
|
|
resp.id = mc->id;
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd->response),
|
2007-02-16 09:00:18 +08:00
|
|
|
&resp, sizeof(resp))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err3;
|
|
|
|
}
|
|
|
|
|
2019-02-21 08:21:04 +08:00
|
|
|
xa_store(&multicast_table, mc->id, mc, 0);
|
2018-06-02 02:31:44 +08:00
|
|
|
|
2007-02-16 09:00:18 +08:00
|
|
|
mutex_unlock(&file->mut);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err3:
|
2008-08-05 02:02:14 +08:00
|
|
|
rdma_leave_multicast(ctx->cm_id, (struct sockaddr *) &mc->addr);
|
2007-02-16 09:00:18 +08:00
|
|
|
ucma_cleanup_mc_events(mc);
|
|
|
|
err2:
|
2019-02-21 08:21:04 +08:00
|
|
|
xa_erase(&multicast_table, mc->id);
|
2007-02-16 09:00:18 +08:00
|
|
|
list_del(&mc->list);
|
|
|
|
kfree(mc);
|
|
|
|
err1:
|
|
|
|
mutex_unlock(&file->mut);
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:09:33 +08:00
|
|
|
static ssize_t ucma_join_ip_multicast(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_join_ip_mcast cmd;
|
|
|
|
struct rdma_ucm_join_mcast join_cmd;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
join_cmd.response = cmd.response;
|
|
|
|
join_cmd.uid = cmd.uid;
|
|
|
|
join_cmd.id = cmd.id;
|
2018-03-29 02:27:22 +08:00
|
|
|
join_cmd.addr_size = rdma_addr_size_in6(&cmd.addr);
|
2018-03-14 00:37:27 +08:00
|
|
|
if (!join_cmd.addr_size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-07-06 21:36:35 +08:00
|
|
|
join_cmd.join_flags = RDMA_MC_JOIN_FLAG_FULLMEMBER;
|
2013-05-30 01:09:33 +08:00
|
|
|
memcpy(&join_cmd.addr, &cmd.addr, join_cmd.addr_size);
|
|
|
|
|
|
|
|
return ucma_process_join(file, &join_cmd, out_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_join_multicast(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_join_mcast cmd;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-29 02:27:22 +08:00
|
|
|
if (!rdma_addr_size_kss(&cmd.addr))
|
2018-03-14 00:37:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-05-30 01:09:33 +08:00
|
|
|
return ucma_process_join(file, &cmd, out_len);
|
|
|
|
}
|
|
|
|
|
2007-02-16 09:00:18 +08:00
|
|
|
static ssize_t ucma_leave_multicast(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_destroy_id cmd;
|
|
|
|
struct rdma_ucm_destroy_id_resp resp;
|
|
|
|
struct ucma_multicast *mc;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (out_len < sizeof(resp))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2019-02-21 08:21:04 +08:00
|
|
|
xa_lock(&multicast_table);
|
|
|
|
mc = xa_load(&multicast_table, cmd.id);
|
2007-02-16 09:00:18 +08:00
|
|
|
if (!mc)
|
|
|
|
mc = ERR_PTR(-ENOENT);
|
|
|
|
else if (mc->ctx->file != file)
|
|
|
|
mc = ERR_PTR(-EINVAL);
|
2015-08-05 07:13:32 +08:00
|
|
|
else if (!atomic_inc_not_zero(&mc->ctx->ref))
|
|
|
|
mc = ERR_PTR(-ENXIO);
|
|
|
|
else
|
2019-02-21 08:21:04 +08:00
|
|
|
__xa_erase(&multicast_table, mc->id);
|
|
|
|
xa_unlock(&multicast_table);
|
2007-02-16 09:00:18 +08:00
|
|
|
|
|
|
|
if (IS_ERR(mc)) {
|
|
|
|
ret = PTR_ERR(mc);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-08-05 02:02:14 +08:00
|
|
|
rdma_leave_multicast(mc->ctx->cm_id, (struct sockaddr *) &mc->addr);
|
2007-02-16 09:00:18 +08:00
|
|
|
mutex_lock(&mc->ctx->file->mut);
|
|
|
|
ucma_cleanup_mc_events(mc);
|
|
|
|
list_del(&mc->list);
|
|
|
|
mutex_unlock(&mc->ctx->file->mut);
|
|
|
|
|
|
|
|
ucma_put_ctx(mc->ctx);
|
|
|
|
resp.events_reported = mc->events_reported;
|
|
|
|
kfree(mc);
|
|
|
|
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2007-02-16 09:00:18 +08:00
|
|
|
&resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-11-14 16:29:50 +08:00
|
|
|
static void ucma_lock_files(struct ucma_file *file1, struct ucma_file *file2)
|
|
|
|
{
|
|
|
|
/* Acquire mutex's based on pointer comparison to prevent deadlock. */
|
|
|
|
if (file1 < file2) {
|
|
|
|
mutex_lock(&file1->mut);
|
2015-07-07 22:45:12 +08:00
|
|
|
mutex_lock_nested(&file2->mut, SINGLE_DEPTH_NESTING);
|
2007-11-14 16:29:50 +08:00
|
|
|
} else {
|
|
|
|
mutex_lock(&file2->mut);
|
2015-07-07 22:45:12 +08:00
|
|
|
mutex_lock_nested(&file1->mut, SINGLE_DEPTH_NESTING);
|
2007-11-14 16:29:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_unlock_files(struct ucma_file *file1, struct ucma_file *file2)
|
|
|
|
{
|
|
|
|
if (file1 < file2) {
|
|
|
|
mutex_unlock(&file2->mut);
|
|
|
|
mutex_unlock(&file1->mut);
|
|
|
|
} else {
|
|
|
|
mutex_unlock(&file1->mut);
|
|
|
|
mutex_unlock(&file2->mut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ucma_move_events(struct ucma_context *ctx, struct ucma_file *file)
|
|
|
|
{
|
|
|
|
struct ucma_event *uevent, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(uevent, tmp, &ctx->file->event_list, list)
|
|
|
|
if (uevent->ctx == ctx)
|
|
|
|
list_move_tail(&uevent->list, &file->event_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ucma_migrate_id(struct ucma_file *new_file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len)
|
|
|
|
{
|
|
|
|
struct rdma_ucm_migrate_id cmd;
|
|
|
|
struct rdma_ucm_migrate_resp resp;
|
|
|
|
struct ucma_context *ctx;
|
2012-08-29 00:52:22 +08:00
|
|
|
struct fd f;
|
2007-11-14 16:29:50 +08:00
|
|
|
struct ucma_file *cur_file;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* Get current fd to protect against it being closed */
|
2012-08-29 00:52:22 +08:00
|
|
|
f = fdget(cmd.fd);
|
|
|
|
if (!f.file)
|
2007-11-14 16:29:50 +08:00
|
|
|
return -ENOENT;
|
2018-09-04 00:54:14 +08:00
|
|
|
if (f.file->f_op != &ucma_fops) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto file_put;
|
|
|
|
}
|
2007-11-14 16:29:50 +08:00
|
|
|
|
|
|
|
/* Validate current fd and prevent destruction of id. */
|
2012-08-29 00:52:22 +08:00
|
|
|
ctx = ucma_get_ctx(f.file->private_data, cmd.id);
|
2007-11-14 16:29:50 +08:00
|
|
|
if (IS_ERR(ctx)) {
|
|
|
|
ret = PTR_ERR(ctx);
|
|
|
|
goto file_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_file = ctx->file;
|
|
|
|
if (cur_file == new_file) {
|
|
|
|
resp.events_reported = ctx->events_reported;
|
|
|
|
goto response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Migrate events between fd's, maintaining order, and avoiding new
|
|
|
|
* events being added before existing events.
|
|
|
|
*/
|
|
|
|
ucma_lock_files(cur_file, new_file);
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_lock(&ctx_table);
|
2007-11-14 16:29:50 +08:00
|
|
|
|
|
|
|
list_move_tail(&ctx->list, &new_file->ctx_list);
|
|
|
|
ucma_move_events(ctx, new_file);
|
|
|
|
ctx->file = new_file;
|
|
|
|
resp.events_reported = ctx->events_reported;
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2007-11-14 16:29:50 +08:00
|
|
|
ucma_unlock_files(cur_file, new_file);
|
|
|
|
|
|
|
|
response:
|
2018-03-28 04:18:47 +08:00
|
|
|
if (copy_to_user(u64_to_user_ptr(cmd.response),
|
2007-11-14 16:29:50 +08:00
|
|
|
&resp, sizeof(resp)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
file_put:
|
2012-08-29 00:52:22 +08:00
|
|
|
fdput(f);
|
2007-11-14 16:29:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
|
|
|
|
const char __user *inbuf,
|
|
|
|
int in_len, int out_len) = {
|
2013-05-30 01:09:30 +08:00
|
|
|
[RDMA_USER_CM_CMD_CREATE_ID] = ucma_create_id,
|
|
|
|
[RDMA_USER_CM_CMD_DESTROY_ID] = ucma_destroy_id,
|
|
|
|
[RDMA_USER_CM_CMD_BIND_IP] = ucma_bind_ip,
|
|
|
|
[RDMA_USER_CM_CMD_RESOLVE_IP] = ucma_resolve_ip,
|
|
|
|
[RDMA_USER_CM_CMD_RESOLVE_ROUTE] = ucma_resolve_route,
|
|
|
|
[RDMA_USER_CM_CMD_QUERY_ROUTE] = ucma_query_route,
|
|
|
|
[RDMA_USER_CM_CMD_CONNECT] = ucma_connect,
|
|
|
|
[RDMA_USER_CM_CMD_LISTEN] = ucma_listen,
|
|
|
|
[RDMA_USER_CM_CMD_ACCEPT] = ucma_accept,
|
|
|
|
[RDMA_USER_CM_CMD_REJECT] = ucma_reject,
|
|
|
|
[RDMA_USER_CM_CMD_DISCONNECT] = ucma_disconnect,
|
|
|
|
[RDMA_USER_CM_CMD_INIT_QP_ATTR] = ucma_init_qp_attr,
|
|
|
|
[RDMA_USER_CM_CMD_GET_EVENT] = ucma_get_event,
|
|
|
|
[RDMA_USER_CM_CMD_GET_OPTION] = NULL,
|
|
|
|
[RDMA_USER_CM_CMD_SET_OPTION] = ucma_set_option,
|
|
|
|
[RDMA_USER_CM_CMD_NOTIFY] = ucma_notify,
|
|
|
|
[RDMA_USER_CM_CMD_JOIN_IP_MCAST] = ucma_join_ip_multicast,
|
|
|
|
[RDMA_USER_CM_CMD_LEAVE_MCAST] = ucma_leave_multicast,
|
|
|
|
[RDMA_USER_CM_CMD_MIGRATE_ID] = ucma_migrate_id,
|
2013-05-30 01:09:31 +08:00
|
|
|
[RDMA_USER_CM_CMD_QUERY] = ucma_query,
|
2013-05-30 01:09:32 +08:00
|
|
|
[RDMA_USER_CM_CMD_BIND] = ucma_bind,
|
2013-05-30 01:09:33 +08:00
|
|
|
[RDMA_USER_CM_CMD_RESOLVE_ADDR] = ucma_resolve_addr,
|
|
|
|
[RDMA_USER_CM_CMD_JOIN_MCAST] = ucma_join_multicast
|
2006-12-01 08:53:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t ucma_write(struct file *filp, const char __user *buf,
|
|
|
|
size_t len, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct ucma_file *file = filp->private_data;
|
|
|
|
struct rdma_ucm_cmd_hdr hdr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
infiniband: remove WARN that is not kernel bug
On Mon, Nov 21, 2016 at 09:52:53AM -0700, Jason Gunthorpe wrote:
> On Mon, Nov 21, 2016 at 02:14:08PM +0200, Leon Romanovsky wrote:
> > >
> > > In ib_ucm_write function there is a wrong prefix:
> > >
> > > + pr_err_once("ucm_write: process %d (%s) tried to do something hinky\n",
> >
> > I did it intentionally to have the same errors for all flows.
>
> Lets actually use a good message too please?
>
> pr_err_once("ucm_write: process %d (%s) changed security contexts after opening FD, this is not allowed.\n",
>
> Jason
>From 70f95b2d35aea42e5b97e7d27ab2f4e8effcbe67 Mon Sep 17 00:00:00 2001
From: Leon Romanovsky <leonro@mellanox.com>
Date: Mon, 21 Nov 2016 13:30:59 +0200
Subject: [PATCH rdma-next V2] IB/{core, qib}: Remove WARN that is not kernel bug
WARNINGs mean kernel bugs, in this case, they are placed
to mark programming errors and/or malicious attempts.
BUG/WARNs that are not kernel bugs hinder automated testing efforts.
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-11-22 01:38:20 +08:00
|
|
|
if (!ib_safe_file_access(filp)) {
|
|
|
|
pr_err_once("ucma_write: process %d (%s) changed security contexts after opening file descriptor, this is not allowed.\n",
|
|
|
|
task_tgid_vnr(current), current->comm);
|
2016-04-11 09:13:13 +08:00
|
|
|
return -EACCES;
|
infiniband: remove WARN that is not kernel bug
On Mon, Nov 21, 2016 at 09:52:53AM -0700, Jason Gunthorpe wrote:
> On Mon, Nov 21, 2016 at 02:14:08PM +0200, Leon Romanovsky wrote:
> > >
> > > In ib_ucm_write function there is a wrong prefix:
> > >
> > > + pr_err_once("ucm_write: process %d (%s) tried to do something hinky\n",
> >
> > I did it intentionally to have the same errors for all flows.
>
> Lets actually use a good message too please?
>
> pr_err_once("ucm_write: process %d (%s) changed security contexts after opening FD, this is not allowed.\n",
>
> Jason
>From 70f95b2d35aea42e5b97e7d27ab2f4e8effcbe67 Mon Sep 17 00:00:00 2001
From: Leon Romanovsky <leonro@mellanox.com>
Date: Mon, 21 Nov 2016 13:30:59 +0200
Subject: [PATCH rdma-next V2] IB/{core, qib}: Remove WARN that is not kernel bug
WARNINGs mean kernel bugs, in this case, they are placed
to mark programming errors and/or malicious attempts.
BUG/WARNs that are not kernel bugs hinder automated testing efforts.
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-11-22 01:38:20 +08:00
|
|
|
}
|
2016-04-11 09:13:13 +08:00
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
if (len < sizeof(hdr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (copy_from_user(&hdr, buf, sizeof(hdr)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2011-10-07 00:33:05 +08:00
|
|
|
if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
|
2006-12-01 08:53:41 +08:00
|
|
|
return -EINVAL;
|
2018-10-16 22:59:01 +08:00
|
|
|
hdr.cmd = array_index_nospec(hdr.cmd, ARRAY_SIZE(ucma_cmd_table));
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
if (hdr.in + sizeof(hdr) > len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!ucma_cmd_table[hdr.cmd])
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
ret = ucma_cmd_table[hdr.cmd](file, buf + sizeof(hdr), hdr.in, hdr.out);
|
|
|
|
if (!ret)
|
|
|
|
ret = len;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-03 18:39:46 +08:00
|
|
|
static __poll_t ucma_poll(struct file *filp, struct poll_table_struct *wait)
|
2006-12-01 08:53:41 +08:00
|
|
|
{
|
|
|
|
struct ucma_file *file = filp->private_data;
|
2017-07-03 18:39:46 +08:00
|
|
|
__poll_t mask = 0;
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
poll_wait(filp, &file->poll_wait, wait);
|
|
|
|
|
|
|
|
if (!list_empty(&file->event_list))
|
2018-02-12 06:34:03 +08:00
|
|
|
mask = EPOLLIN | EPOLLRDNORM;
|
2006-12-01 08:53:41 +08:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2008-07-25 11:36:59 +08:00
|
|
|
/*
|
|
|
|
* ucma_open() does not need the BKL:
|
|
|
|
*
|
|
|
|
* - no global state is referred to;
|
|
|
|
* - there is no ioctl method to race against;
|
|
|
|
* - no further module initialization is required for open to work
|
|
|
|
* after the device is registered.
|
|
|
|
*/
|
2006-12-01 08:53:41 +08:00
|
|
|
static int ucma_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
struct ucma_file *file;
|
|
|
|
|
|
|
|
file = kmalloc(sizeof *file, GFP_KERNEL);
|
|
|
|
if (!file)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-08-16 01:59:10 +08:00
|
|
|
file->close_wq = alloc_ordered_workqueue("ucma_close_id",
|
|
|
|
WQ_MEM_RECLAIM);
|
2015-09-18 04:04:19 +08:00
|
|
|
if (!file->close_wq) {
|
|
|
|
kfree(file);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
INIT_LIST_HEAD(&file->event_list);
|
|
|
|
INIT_LIST_HEAD(&file->ctx_list);
|
|
|
|
init_waitqueue_head(&file->poll_wait);
|
|
|
|
mutex_init(&file->mut);
|
|
|
|
|
|
|
|
filp->private_data = file;
|
|
|
|
file->filp = filp;
|
2010-04-10 08:13:50 +08:00
|
|
|
|
2019-03-27 04:51:19 +08:00
|
|
|
return stream_open(inode, filp);
|
2006-12-01 08:53:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ucma_close(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
struct ucma_file *file = filp->private_data;
|
|
|
|
struct ucma_context *ctx, *tmp;
|
|
|
|
|
|
|
|
mutex_lock(&file->mut);
|
|
|
|
list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) {
|
2015-08-13 23:32:07 +08:00
|
|
|
ctx->destroying = 1;
|
2006-12-01 08:53:41 +08:00
|
|
|
mutex_unlock(&file->mut);
|
|
|
|
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_erase(&ctx_table, ctx->id);
|
2015-08-13 23:32:07 +08:00
|
|
|
flush_workqueue(file->close_wq);
|
|
|
|
/* At that step once ctx was marked as destroying and workqueue
|
|
|
|
* was flushed we are safe from any inflights handlers that
|
|
|
|
* might put other closing task.
|
|
|
|
*/
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_lock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
if (!ctx->closing) {
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2018-09-13 07:27:44 +08:00
|
|
|
ucma_put_ctx(ctx);
|
|
|
|
wait_for_completion(&ctx->comp);
|
2015-08-13 23:32:07 +08:00
|
|
|
/* rdma_destroy_id ensures that no event handlers are
|
|
|
|
* inflight for that id before releasing it.
|
|
|
|
*/
|
|
|
|
rdma_destroy_id(ctx->cm_id);
|
|
|
|
} else {
|
2019-02-21 08:21:05 +08:00
|
|
|
xa_unlock(&ctx_table);
|
2015-08-13 23:32:07 +08:00
|
|
|
}
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
ucma_free_ctx(ctx);
|
|
|
|
mutex_lock(&file->mut);
|
|
|
|
}
|
|
|
|
mutex_unlock(&file->mut);
|
2015-08-13 23:32:07 +08:00
|
|
|
destroy_workqueue(file->close_wq);
|
2006-12-01 08:53:41 +08:00
|
|
|
kfree(file);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:32 +08:00
|
|
|
static const struct file_operations ucma_fops = {
|
2006-12-01 08:53:41 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ucma_open,
|
|
|
|
.release = ucma_close,
|
|
|
|
.write = ucma_write,
|
|
|
|
.poll = ucma_poll,
|
2010-04-10 08:13:50 +08:00
|
|
|
.llseek = no_llseek,
|
2006-12-01 08:53:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice ucma_misc = {
|
2011-05-24 01:48:43 +08:00
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "rdma_cm",
|
|
|
|
.nodename = "infiniband/rdma_cm",
|
|
|
|
.mode = 0666,
|
|
|
|
.fops = &ucma_fops,
|
2006-12-01 08:53:41 +08:00
|
|
|
};
|
|
|
|
|
2019-06-14 08:38:19 +08:00
|
|
|
static int ucma_get_global_nl_info(struct ib_client_nl_info *res)
|
|
|
|
{
|
|
|
|
res->abi = RDMA_USER_CM_ABI_VERSION;
|
|
|
|
res->cdev = ucma_misc.this_device;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_client rdma_cma_client = {
|
|
|
|
.name = "rdma_cm",
|
|
|
|
.get_global_nl_info = ucma_get_global_nl_info,
|
|
|
|
};
|
|
|
|
MODULE_ALIAS_RDMA_CLIENT("rdma_cm");
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
static ssize_t show_abi_version(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", RDMA_USER_CM_ABI_VERSION);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
|
|
|
|
|
|
|
|
static int __init ucma_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = misc_register(&ucma_misc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = device_create_file(ucma_misc.this_device, &dev_attr_abi_version);
|
|
|
|
if (ret) {
|
2016-03-02 03:20:29 +08:00
|
|
|
pr_err("rdma_ucm: couldn't create abi_version attr\n");
|
2010-08-14 04:56:34 +08:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:44:49 +08:00
|
|
|
ucma_ctl_table_hdr = register_net_sysctl(&init_net, "net/rdma_ucm", ucma_ctl_table);
|
2010-08-14 04:56:34 +08:00
|
|
|
if (!ucma_ctl_table_hdr) {
|
2016-03-02 03:20:29 +08:00
|
|
|
pr_err("rdma_ucm: couldn't register sysctl paths\n");
|
2010-08-14 04:56:34 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err2;
|
2006-12-01 08:53:41 +08:00
|
|
|
}
|
2019-06-14 08:38:19 +08:00
|
|
|
|
|
|
|
ret = ib_register_client(&rdma_cma_client);
|
|
|
|
if (ret)
|
|
|
|
goto err3;
|
|
|
|
|
2006-12-01 08:53:41 +08:00
|
|
|
return 0;
|
2019-06-14 08:38:19 +08:00
|
|
|
err3:
|
|
|
|
unregister_net_sysctl_table(ucma_ctl_table_hdr);
|
2010-08-14 04:56:34 +08:00
|
|
|
err2:
|
|
|
|
device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
|
|
|
|
err1:
|
2006-12-01 08:53:41 +08:00
|
|
|
misc_deregister(&ucma_misc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ucma_cleanup(void)
|
|
|
|
{
|
2019-06-14 08:38:19 +08:00
|
|
|
ib_unregister_client(&rdma_cma_client);
|
2012-04-19 21:24:33 +08:00
|
|
|
unregister_net_sysctl_table(ucma_ctl_table_hdr);
|
2006-12-01 08:53:41 +08:00
|
|
|
device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
|
|
|
|
misc_deregister(&ucma_misc);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ucma_init);
|
|
|
|
module_exit(ucma_cleanup);
|