Commit 057aec0d authored by Yishai Hadas's avatar Yishai Hadas Committed by Doug Ledford

IB/uverbs: Explicitly pass ib_dev to uverbs commands

Done in preparation for deploying RCU for the device removal
flow. Allows isolating the RCU handling to the uverb_main layer and
keeping the uverbs_cmd code as is.
Signed-off-by: default avatarYishai Hadas <yishaih@mellanox.com>
Signed-off-by: default avatarShachar Raindel <raindel@mellanox.com>
Reviewed-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 35d4a0b6
...@@ -178,6 +178,7 @@ extern struct idr ib_uverbs_rule_idr; ...@@ -178,6 +178,7 @@ extern struct idr ib_uverbs_rule_idr;
void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj); void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj);
struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
struct ib_device *ib_dev,
int is_async); int is_async);
void ib_uverbs_free_async_event_file(struct ib_uverbs_file *uverbs_file); void ib_uverbs_free_async_event_file(struct ib_uverbs_file *uverbs_file);
struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd); struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd);
...@@ -214,6 +215,7 @@ struct ib_uverbs_flow_spec { ...@@ -214,6 +215,7 @@ struct ib_uverbs_flow_spec {
#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)
...@@ -255,6 +257,7 @@ IB_UVERBS_DECLARE_CMD(close_xrcd); ...@@ -255,6 +257,7 @@ 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.
...@@ -79,6 +79,7 @@ static DEFINE_SPINLOCK(map_lock); ...@@ -79,6 +79,7 @@ static DEFINE_SPINLOCK(map_lock);
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,
...@@ -119,6 +120,7 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, ...@@ -119,6 +120,7 @@ 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,
...@@ -557,6 +559,7 @@ void ib_uverbs_free_async_event_file(struct ib_uverbs_file *file) ...@@ -557,6 +559,7 @@ void ib_uverbs_free_async_event_file(struct ib_uverbs_file *file)
} }
struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
struct ib_device *ib_dev,
int is_async) int is_async)
{ {
struct ib_uverbs_event_file *ev_file; struct ib_uverbs_event_file *ev_file;
...@@ -586,7 +589,7 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, ...@@ -586,7 +589,7 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
uverbs_file->async_file = ev_file; uverbs_file->async_file = ev_file;
kref_get(&uverbs_file->async_file->ref); kref_get(&uverbs_file->async_file->ref);
INIT_IB_EVENT_HANDLER(&uverbs_file->event_handler, INIT_IB_EVENT_HANDLER(&uverbs_file->event_handler,
uverbs_file->device->ib_dev, ib_dev,
ib_uverbs_event_handler); ib_uverbs_event_handler);
ret = ib_register_event_handler(&uverbs_file->event_handler); ret = ib_register_event_handler(&uverbs_file->event_handler);
if (ret) if (ret)
...@@ -643,9 +646,13 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -643,9 +646,13 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
size_t count, loff_t *pos) size_t count, loff_t *pos)
{ {
struct ib_uverbs_file *file = filp->private_data; struct ib_uverbs_file *file = filp->private_data;
struct ib_device *ib_dev = file->device->ib_dev;
struct ib_uverbs_cmd_hdr hdr; struct ib_uverbs_cmd_hdr hdr;
__u32 flags; __u32 flags;
if (!ib_dev)
return -ENODEV;
if (count < sizeof hdr) if (count < sizeof hdr)
return -EINVAL; return -EINVAL;
...@@ -672,13 +679,13 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -672,13 +679,13 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
command != IB_USER_VERBS_CMD_GET_CONTEXT) command != IB_USER_VERBS_CMD_GET_CONTEXT)
return -EINVAL; return -EINVAL;
if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << command))) if (!(ib_dev->uverbs_cmd_mask & (1ull << command)))
return -ENOSYS; return -ENOSYS;
if (hdr.in_words * 4 != count) if (hdr.in_words * 4 != count)
return -EINVAL; return -EINVAL;
return uverbs_cmd_table[command](file, return uverbs_cmd_table[command](file, ib_dev,
buf + sizeof(hdr), buf + sizeof(hdr),
hdr.in_words * 4, hdr.in_words * 4,
hdr.out_words * 4); hdr.out_words * 4);
...@@ -705,7 +712,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -705,7 +712,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
if (!file->ucontext) if (!file->ucontext)
return -EINVAL; return -EINVAL;
if (!(file->device->ib_dev->uverbs_ex_cmd_mask & (1ull << command))) if (!(ib_dev->uverbs_ex_cmd_mask & (1ull << command)))
return -ENOSYS; return -ENOSYS;
if (count < (sizeof(hdr) + sizeof(ex_hdr))) if (count < (sizeof(hdr) + sizeof(ex_hdr)))
...@@ -746,6 +753,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -746,6 +753,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
ex_hdr.provider_out_words * 8); ex_hdr.provider_out_words * 8);
err = uverbs_ex_cmd_table[command](file, err = uverbs_ex_cmd_table[command](file,
ib_dev,
&ucore, &ucore,
&uhw); &uhw);
...@@ -761,11 +769,12 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -761,11 +769,12 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
{ {
struct ib_uverbs_file *file = filp->private_data; struct ib_uverbs_file *file = filp->private_data;
struct ib_device *ib_dev = file->device->ib_dev;
if (!file->ucontext) if (!ib_dev || !file->ucontext)
return -ENODEV; return -ENODEV;
else else
return file->device->ib_dev->mmap(file->ucontext, vma); return ib_dev->mmap(file->ucontext, vma);
} }
/* /*
......
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