Commit bbd51e88 authored by Jason Gunthorpe's avatar Jason Gunthorpe

IB/uverbs: Do not pass struct ib_device to the write based methods

This is a step to get rid of the global check for disassociation. In this
model, the ib_dev is not proven to be valid by the core code and cannot be
provided to the method. Instead, every method decides if it is able to
run after disassociation and obtains the ib_dev using one of three
different approaches:

- Call srcu_dereference on the udevice's ib_dev. As before, this means
  the method cannot be called after disassociation begins.
  (eg alloc ucontext)
- Retrieve the ib_dev from the ucontext, via ib_uverbs_get_ucontext()
- Retrieve the ib_dev from the uobject->object after checking
  under SRCU if disassociation has started (eg uobj_get)

Largely, the code is all ready for this, the main work is to provide a
ib_dev after calling uobj_alloc(). The few other places simply use
ib_uverbs_get_ucontext() to get the ib_dev.

This flexibility will let the next patches allow destroy to operate
after disassociation.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent cc2e14e6
...@@ -299,7 +299,6 @@ extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS); ...@@ -299,7 +299,6 @@ extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS);
#define IB_UVERBS_DECLARE_CMD(name) \ #define IB_UVERBS_DECLARE_CMD(name) \
ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \ ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
struct ib_device *ib_dev, \
const char __user *buf, int in_len, \ const char __user *buf, int in_len, \
int out_len) int out_len)
...@@ -341,7 +340,6 @@ IB_UVERBS_DECLARE_CMD(close_xrcd); ...@@ -341,7 +340,6 @@ IB_UVERBS_DECLARE_CMD(close_xrcd);
#define IB_UVERBS_DECLARE_EX_CMD(name) \ #define IB_UVERBS_DECLARE_EX_CMD(name) \
int ib_uverbs_ex_##name(struct ib_uverbs_file *file, \ int ib_uverbs_ex_##name(struct ib_uverbs_file *file, \
struct ib_device *ib_dev, \
struct ib_udata *ucore, \ struct ib_udata *ucore, \
struct ib_udata *uhw) struct ib_udata *uhw)
......
This diff is collapsed.
...@@ -75,7 +75,6 @@ static struct class *uverbs_class; ...@@ -75,7 +75,6 @@ static struct class *uverbs_class;
static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);
static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
struct ib_device *ib_dev,
const char __user *buf, int in_len, const char __user *buf, int in_len,
int out_len) = { int out_len) = {
[IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context, [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context,
...@@ -116,7 +115,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, ...@@ -116,7 +115,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
}; };
static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file, static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file,
struct ib_device *ib_dev,
struct ib_udata *ucore, struct ib_udata *ucore,
struct ib_udata *uhw) = { struct ib_udata *uhw) = {
[IB_USER_VERBS_EX_CMD_CREATE_FLOW] = ib_uverbs_ex_create_flow, [IB_USER_VERBS_EX_CMD_CREATE_FLOW] = ib_uverbs_ex_create_flow,
...@@ -774,7 +772,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -774,7 +772,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
buf += sizeof(hdr); buf += sizeof(hdr);
if (!extended) { if (!extended) {
ret = uverbs_cmd_table[command](file, ib_dev, buf, ret = uverbs_cmd_table[command](file, buf,
hdr.in_words * 4, hdr.in_words * 4,
hdr.out_words * 4); hdr.out_words * 4);
} else { } else {
...@@ -793,7 +791,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -793,7 +791,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
ex_hdr.provider_in_words * 8, ex_hdr.provider_in_words * 8,
ex_hdr.provider_out_words * 8); ex_hdr.provider_out_words * 8);
ret = uverbs_ex_cmd_table[command](file, ib_dev, &ucore, &uhw); ret = uverbs_ex_cmd_table[command](file, &ucore, &uhw);
ret = (ret) ? : count; ret = (ret) ? : count;
} }
......
...@@ -125,12 +125,18 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj) ...@@ -125,12 +125,18 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj)
} }
static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type, static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type,
struct ib_uverbs_file *ufile) struct ib_uverbs_file *ufile,
struct ib_device **ib_dev)
{ {
return rdma_alloc_begin_uobject(type, ufile); struct ib_uobject *uobj = rdma_alloc_begin_uobject(type, ufile);
if (!IS_ERR(uobj))
*ib_dev = uobj->context->device;
return uobj;
} }
#define uobj_alloc(_type, _ufile) __uobj_alloc(uobj_get_type(_type), _ufile) #define uobj_alloc(_type, _ufile, _ib_dev) \
__uobj_alloc(uobj_get_type(_type), _ufile, _ib_dev)
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment