diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2018-11-25 20:51:13 +0200 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-11-26 16:48:07 -0700 |
commit | 8313c10fa8be032fccc1e757bccc21207f533127 (patch) | |
tree | 83df5841953b27023aa65ab8a6b5ed790dba5765 | |
parent | 1b09577bef3ac135ed02115943c9ab53f2129555 (diff) | |
download | linux-8313c10fa8be032fccc1e757bccc21207f533127.tar.bz2 |
RDMA/uverbs: Replace ib_uverbs_file with uverbs_attr_bundle for write
Now that we can add meta-data to the description of write() methods we
need to pass the uverbs_attr_bundle into all write based handlers so
future patches can use it as a container for any new data transferred out
of the core.
This is the first step to bringing the write() and ioctl() methods to a
common interface signature.
This is a simple search/replace, and we push the attr down into the uobj
and other APIs to keep changes minimal.
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
-rw-r--r-- | drivers/infiniband/core/rdma_core.c | 13 | ||||
-rw-r--r-- | drivers/infiniband/core/rdma_core.h | 8 | ||||
-rw-r--r-- | drivers/infiniband/core/uverbs_cmd.c | 301 | ||||
-rw-r--r-- | drivers/infiniband/core/uverbs_main.c | 12 | ||||
-rw-r--r-- | drivers/infiniband/core/uverbs_uapi.c | 4 | ||||
-rw-r--r-- | drivers/infiniband/hw/mlx5/devx.c | 2 | ||||
-rw-r--r-- | include/rdma/ib_verbs.h | 2 | ||||
-rw-r--r-- | include/rdma/uverbs_ioctl.h | 10 | ||||
-rw-r--r-- | include/rdma/uverbs_std_types.h | 48 |
9 files changed, 208 insertions, 192 deletions
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c index 752a55c6bdce..cf671a643d4c 100644 --- a/drivers/infiniband/core/rdma_core.c +++ b/drivers/infiniband/core/rdma_core.c @@ -224,12 +224,14 @@ out_unlock: * uverbs_put_destroy. */ struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj, - u32 id, struct ib_uverbs_file *ufile) + u32 id, + const struct uverbs_attr_bundle *attrs) { struct ib_uobject *uobj; int ret; - uobj = rdma_lookup_get_uobject(obj, ufile, id, UVERBS_LOOKUP_DESTROY); + uobj = rdma_lookup_get_uobject(obj, attrs->ufile, id, + UVERBS_LOOKUP_DESTROY); if (IS_ERR(uobj)) return uobj; @@ -248,11 +250,12 @@ struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj, * the uobj. */ int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id, - struct ib_uverbs_file *ufile, int success_res) + const struct uverbs_attr_bundle *attrs, + int success_res) { struct ib_uobject *uobj; - uobj = __uobj_get_destroy(obj, id, ufile); + uobj = __uobj_get_destroy(obj, id, attrs); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -267,7 +270,7 @@ static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile, struct ib_uobject *uobj; struct ib_ucontext *ucontext; - ucontext = ib_uverbs_get_ucontext(ufile); + ucontext = ib_uverbs_get_ucontext_file(ufile); if (IS_ERR(ucontext)) return ERR_CAST(ucontext); diff --git a/drivers/infiniband/core/rdma_core.h b/drivers/infiniband/core/rdma_core.h index f9039cfb28b4..edd299174d95 100644 --- a/drivers/infiniband/core/rdma_core.h +++ b/drivers/infiniband/core/rdma_core.h @@ -137,10 +137,10 @@ struct uverbs_api_ioctl_method { }; struct uverbs_api_write_method { - ssize_t (*handler)(struct ib_uverbs_file *file, const char __user *buf, - int in_len, int out_len); - int (*handler_ex)(struct ib_uverbs_file *file, struct ib_udata *ucore, - struct ib_udata *uhw); + ssize_t (*handler)(struct uverbs_attr_bundle *attrs, + const char __user *buf, int in_len, int out_len); + int (*handler_ex)(struct uverbs_attr_bundle *attrs, + struct ib_udata *ucore, struct ib_udata *uhw); u8 disabled:1; u8 is_ex:1; }; diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index e2fcaf398a4d..a49926a63ce0 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -48,10 +48,10 @@ #include "core_priv.h" static struct ib_uverbs_completion_event_file * -_ib_uverbs_lookup_comp_file(s32 fd, struct ib_uverbs_file *ufile) +_ib_uverbs_lookup_comp_file(s32 fd, const struct uverbs_attr_bundle *attrs) { struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL, - fd, ufile); + fd, attrs); if (IS_ERR(uobj)) return (void *)uobj; @@ -65,10 +65,11 @@ _ib_uverbs_lookup_comp_file(s32 fd, struct ib_uverbs_file *ufile) #define ib_uverbs_lookup_comp_file(_fd, _ufile) \ _ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile) -static ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_get_context(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { + struct ib_uverbs_file *file = attrs->ufile; struct ib_uverbs_get_context cmd; struct ib_uverbs_get_context_resp resp; struct ib_udata udata; @@ -224,7 +225,7 @@ static void copy_query_dev_fields(struct ib_ucontext *ucontext, resp->phys_port_cnt = ib_dev->phys_port_cnt; } -static ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_query_device(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -232,7 +233,7 @@ static ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file, struct ib_uverbs_query_device_resp resp; struct ib_ucontext *ucontext; - ucontext = ib_uverbs_get_ucontext(file); + ucontext = ib_uverbs_get_ucontext(attrs); if (IS_ERR(ucontext)) return PTR_ERR(ucontext); @@ -272,7 +273,7 @@ static u32 make_port_cap_flags(const struct ib_port_attr *attr) return res; } -static ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_query_port(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -283,7 +284,7 @@ static ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file, struct ib_ucontext *ucontext; struct ib_device *ib_dev; - ucontext = ib_uverbs_get_ucontext(file); + ucontext = ib_uverbs_get_ucontext(attrs); if (IS_ERR(ucontext)) return PTR_ERR(ucontext); ib_dev = ucontext->device; @@ -337,7 +338,7 @@ static ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file, return in_len; } -static ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_alloc_pd(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -360,7 +361,7 @@ static ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - uobj = uobj_alloc(UVERBS_OBJECT_PD, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_PD, attrs, &ib_dev); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -396,7 +397,7 @@ err: return ret; } -static ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_dealloc_pd(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -405,7 +406,7 @@ static ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, file, + return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, attrs, in_len); } @@ -494,10 +495,11 @@ static void xrcd_table_delete(struct ib_uverbs_device *dev, } } -static ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { + struct ib_uverbs_device *ibudev = attrs->ufile->device; struct ib_uverbs_open_xrcd cmd; struct ib_uverbs_open_xrcd_resp resp; struct ib_udata udata; @@ -520,7 +522,7 @@ static ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - mutex_lock(&file->device->xrcd_tree_mutex); + mutex_lock(&ibudev->xrcd_tree_mutex); if (cmd.fd != -1) { /* search for file descriptor */ @@ -531,7 +533,7 @@ static ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, } inode = file_inode(f.file); - xrcd = find_xrcd(file->device, inode); + xrcd = find_xrcd(ibudev, inode); if (!xrcd && !(cmd.oflags & O_CREAT)) { /* no file descriptor. Need CREATE flag */ ret = -EAGAIN; @@ -544,7 +546,7 @@ static ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, } } - obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, file, + obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, attrs, &ib_dev); if (IS_ERR(obj)) { ret = PTR_ERR(obj); @@ -574,7 +576,7 @@ static ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, if (inode) { if (new_xrcd) { /* create new inode/xrcd table entry */ - ret = xrcd_table_insert(file->device, inode, xrcd); + ret = xrcd_table_insert(ibudev, inode, xrcd); if (ret) goto err_dealloc_xrcd; } @@ -589,14 +591,14 @@ static ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, if (f.file) fdput(f); - mutex_unlock(&file->device->xrcd_tree_mutex); + mutex_unlock(&ibudev->xrcd_tree_mutex); return uobj_alloc_commit(&obj->uobject, in_len); err_copy: if (inode) { if (new_xrcd) - xrcd_table_delete(file->device, inode); + xrcd_table_delete(ibudev, inode); atomic_dec(&xrcd->usecnt); } @@ -610,12 +612,12 @@ err_tree_mutex_unlock: if (f.file) fdput(f); - mutex_unlock(&file->device->xrcd_tree_mutex); + mutex_unlock(&ibudev->xrcd_tree_mutex); return ret; } -static ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -624,7 +626,7 @@ static ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, file, + return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs, in_len); } @@ -653,7 +655,7 @@ int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, return ret; } -static ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { struct ib_uverbs_reg_mr cmd; @@ -683,11 +685,11 @@ static ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, if (ret) return ret; - uobj = uobj_alloc(UVERBS_OBJECT_MR, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev); if (IS_ERR(uobj)) return PTR_ERR(uobj); - pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, file); + pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); if (!pd) { ret = -EINVAL; goto err_free; @@ -744,7 +746,7 @@ err_free: return ret; } -static ssize_t ib_uverbs_rereg_mr(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -776,7 +778,7 @@ static ssize_t ib_uverbs_rereg_mr(struct ib_uverbs_file *file, (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))) return -EINVAL; - uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, file); + uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -795,7 +797,7 @@ static ssize_t ib_uverbs_rereg_mr(struct ib_uverbs_file *file, if (cmd.flags & IB_MR_REREG_PD) { pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, - file); + attrs); if (!pd) { ret = -EINVAL; goto put_uobjs; @@ -835,7 +837,7 @@ put_uobjs: return ret; } -static ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -844,11 +846,11 @@ static ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, file, + return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs, in_len); } -static ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -867,11 +869,11 @@ static ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof(cmd))) return -EFAULT; - uobj = uobj_alloc(UVERBS_OBJECT_MW, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev); if (IS_ERR(uobj)) return PTR_ERR(uobj); - pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, file); + pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); if (!pd) { ret = -EINVAL; goto err_free; @@ -916,7 +918,7 @@ err_free: return ret; } -static ssize_t ib_uverbs_dealloc_mw(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -925,11 +927,11 @@ static ssize_t ib_uverbs_dealloc_mw(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof(cmd))) return -EFAULT; - return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, file, + return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs, in_len); } -static ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -945,7 +947,7 @@ static ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -963,12 +965,12 @@ static ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file, return uobj_alloc_commit(uobj, in_len); } -static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, +static struct ib_ucq_object *create_cq(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw, struct ib_uverbs_ex_create_cq *cmd, size_t cmd_sz, - int (*cb)(struct ib_uverbs_file *file, + int (*cb)(struct uverbs_attr_bundle *attrs, struct ib_ucq_object *obj, struct ib_uverbs_ex_create_cq_resp *resp, struct ib_udata *udata, @@ -983,16 +985,16 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, struct ib_cq_init_attr attr = {}; struct ib_device *ib_dev; - if (cmd->comp_vector >= file->device->num_comp_vectors) + if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors) return ERR_PTR(-EINVAL); - obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, file, + obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs, &ib_dev); if (IS_ERR(obj)) return obj; if (cmd->comp_channel >= 0) { - ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, file); + ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs); if (IS_ERR(ev_file)) { ret = PTR_ERR(ev_file); goto err; @@ -1035,7 +1037,7 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, cq->res.type = RDMA_RESTRACK_CQ; rdma_restrack_add(&cq->res); - ret = cb(file, obj, &resp, ucore, context); + ret = cb(attrs, obj, &resp, ucore, context); if (ret) goto err_cb; @@ -1049,7 +1051,7 @@ err_cb: err_file: if (ev_file) - ib_uverbs_release_ucq(file, ev_file, obj); + ib_uverbs_release_ucq(attrs->ufile, ev_file, obj); err: uobj_alloc_abort(&obj->uobject); @@ -1057,7 +1059,7 @@ err: return ERR_PTR(ret); } -static int ib_uverbs_create_cq_cb(struct ib_uverbs_file *file, +static int ib_uverbs_create_cq_cb(struct uverbs_attr_bundle *attrs, struct ib_ucq_object *obj, struct ib_uverbs_ex_create_cq_resp *resp, struct ib_udata *ucore, void *context) @@ -1068,7 +1070,7 @@ static int ib_uverbs_create_cq_cb(struct ib_uverbs_file *file, return 0; } -static ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1099,7 +1101,7 @@ static ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, cmd_ex.comp_vector = cmd.comp_vector; cmd_ex.comp_channel = cmd.comp_channel; - obj = create_cq(file, &ucore, &uhw, &cmd_ex, + obj = create_cq(attrs, &ucore, &uhw, &cmd_ex, offsetof(typeof(cmd_ex), comp_channel) + sizeof(cmd.comp_channel), ib_uverbs_create_cq_cb, NULL); @@ -1110,7 +1112,7 @@ static ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, return in_len; } -static int ib_uverbs_ex_create_cq_cb(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_cq_cb(struct uverbs_attr_bundle *attrs, struct ib_ucq_object *obj, struct ib_uverbs_ex_create_cq_resp *resp, struct ib_udata *ucore, void *context) @@ -1121,7 +1123,7 @@ static int ib_uverbs_ex_create_cq_cb(struct ib_uverbs_file *file, return 0; } -static int ib_uverbs_ex_create_cq(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_create_cq_resp resp; @@ -1146,14 +1148,14 @@ static int ib_uverbs_ex_create_cq(struct ib_uverbs_file *file, sizeof(resp.response_length))) return -ENOSPC; - obj = create_cq(file, ucore, uhw, &cmd, + obj = create_cq(attrs, ucore, uhw, &cmd, min(ucore->inlen, sizeof(cmd)), ib_uverbs_ex_create_cq_cb, NULL); return PTR_ERR_OR_ZERO(obj); } -static ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1171,7 +1173,7 @@ static ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, file); + cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); if (!cq) return -EINVAL; @@ -1220,7 +1222,7 @@ static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest, return 0; } -static ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1235,7 +1237,7 @@ static ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, file); + cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); if (!cq) return -EINVAL; @@ -1271,7 +1273,7 @@ out_put: return ret; } -static ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1281,7 +1283,7 @@ static ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, file); + cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); if (!cq) return -EINVAL; @@ -1293,7 +1295,7 @@ static ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, return in_len; } -static ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1305,7 +1307,7 @@ static ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, file); + uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -1322,12 +1324,12 @@ static ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, return in_len; } -static int create_qp(struct ib_uverbs_file *file, +static int create_qp(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw, struct ib_uverbs_ex_create_qp *cmd, size_t cmd_sz, - int (*cb)(struct ib_uverbs_file *file, + int (*cb)(struct uverbs_attr_bundle *attrs, struct ib_uverbs_ex_create_qp_resp *resp, struct ib_udata *udata), void *context) @@ -1351,7 +1353,7 @@ static int create_qp(struct ib_uverbs_file *file, if (cmd->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW)) return -EPERM; - obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, file, + obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs, &ib_dev); if (IS_ERR(obj)) return PTR_ERR(obj); @@ -1364,7 +1366,7 @@ static int create_qp(struct ib_uverbs_file *file, (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE)) { ind_tbl = uobj_get_obj_read(rwq_ind_table, UVERBS_OBJECT_RWQ_IND_TBL, - cmd->rwq_ind_tbl_handle, file); + cmd->rwq_ind_tbl_handle, attrs); if (!ind_tbl) { ret = -EINVAL; goto err_put; @@ -1390,7 +1392,7 @@ static int create_qp(struct ib_uverbs_file *file, if (cmd->qp_type == IB_QPT_XRC_TGT) { xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle, - file); + attrs); if (IS_ERR(xrcd_uobj)) { ret = -EINVAL; @@ -1410,7 +1412,7 @@ static int create_qp(struct ib_uverbs_file *file, } else { if (cmd->is_srq) { srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, - cmd->srq_handle, file); + cmd->srq_handle, attrs); if (!srq || srq->srq_type == IB_SRQT_XRC) { ret = -EINVAL; goto err_put; @@ -1421,7 +1423,7 @@ static int create_qp(struct ib_uverbs_file *file, if (cmd->recv_cq_handle != cmd->send_cq_handle) { rcq = uobj_get_obj_read( cq, UVERBS_OBJECT_CQ, - cmd->recv_cq_handle, file); + cmd->recv_cq_handle, attrs); if (!rcq) { ret = -EINVAL; goto err_put; @@ -1432,11 +1434,11 @@ static int create_qp(struct ib_uverbs_file *file, if (has_sq) scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, - cmd->send_cq_handle, file); + cmd->send_cq_handle, attrs); if (!ind_tbl) rcq = rcq ?: scq; pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, - file); + attrs); if (!pd || (!scq && has_sq)) { ret = -EINVAL; goto err_put; @@ -1446,7 +1448,7 @@ static int create_qp(struct ib_uverbs_file *file, } attr.event_handler = ib_uverbs_qp_event_handler; - attr.qp_context = file; + attr.qp_context = attrs->ufile; attr.send_cq = scq; attr.recv_cq = rcq; attr.srq = srq; @@ -1554,7 +1556,7 @@ static int create_qp(struct ib_uverbs_file *file, resp.response_length = offsetof(typeof(resp), response_length) + sizeof(resp.response_length); - ret = cb(file, &resp, ucore); + ret = cb(attrs, &resp, ucore); if (ret) goto err_cb; @@ -1598,7 +1600,7 @@ err_put: return ret; } -static int ib_uverbs_create_qp_cb(struct ib_uverbs_file *file, +static int ib_uverbs_create_qp_cb(struct uverbs_attr_bundle *attrs, struct ib_uverbs_ex_create_qp_resp *resp, struct ib_udata *ucore) { @@ -1608,7 +1610,7 @@ static int ib_uverbs_create_qp_cb(struct ib_uverbs_file *file, return 0; } -static ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1647,7 +1649,7 @@ static ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, cmd_ex.qp_type = cmd.qp_type; cmd_ex.is_srq = cmd.is_srq; - err = create_qp(file, &ucore, &uhw, &cmd_ex, + err = create_qp(attrs, &ucore, &uhw, &cmd_ex, offsetof(typeof(cmd_ex), is_srq) + sizeof(cmd.is_srq), ib_uverbs_create_qp_cb, NULL); @@ -1658,7 +1660,7 @@ static ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, return in_len; } -static int ib_uverbs_ex_create_qp_cb(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_qp_cb(struct uverbs_attr_bundle *attrs, struct ib_uverbs_ex_create_qp_resp *resp, struct ib_udata *ucore) { @@ -1668,7 +1670,7 @@ static int ib_uverbs_ex_create_qp_cb(struct ib_uverbs_file *file, return 0; } -static int ib_uverbs_ex_create_qp(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_create_qp_resp resp; @@ -1693,7 +1695,7 @@ static int ib_uverbs_ex_create_qp(struct ib_uverbs_file *file, sizeof(resp.response_length))) return -ENOSPC; - err = create_qp(file, ucore, uhw, &cmd, + err = create_qp(attrs, ucore, uhw, &cmd, min(ucore->inlen, sizeof(cmd)), ib_uverbs_ex_create_qp_cb, NULL); @@ -1703,7 +1705,7 @@ static int ib_uverbs_ex_create_qp(struct ib_uverbs_file *file, return 0; } -static ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1729,12 +1731,12 @@ static ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, file, + obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs, &ib_dev); if (IS_ERR(obj)) return PTR_ERR(obj); - xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, file); + xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs); if (IS_ERR(xrcd_uobj)) { ret = -EINVAL; goto err_put; @@ -1747,7 +1749,7 @@ static ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file, } attr.event_handler = ib_uverbs_qp_event_handler; - attr.qp_context = file; + attr.qp_context = attrs->ufile; attr.qp_num = cmd.qpn; attr.qp_type = cmd.qp_type; @@ -1811,7 +1813,7 @@ static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr, uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr); } -static ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -1832,7 +1834,7 @@ static ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file, goto out; } - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (!qp) { ret = -EINVAL; goto out; @@ -1926,7 +1928,7 @@ static void copy_ah_attr_from_uverbs(struct ib_device *dev, rdma_ah_set_make_grd(rdma_attr, false); } -static int modify_qp(struct ib_uverbs_file *file, +static int modify_qp(struct uverbs_attr_bundle *attrs, struct ib_uverbs_ex_modify_qp *cmd, struct ib_udata *udata) { struct ib_qp_attr *attr; @@ -1937,7 +1939,8 @@ static int modify_qp(struct ib_uverbs_file *file, if (!attr) return -ENOMEM; - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle, + attrs); if (!qp) { ret = -EINVAL; goto out; @@ -2084,7 +2087,7 @@ out: return ret; } -static ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2103,14 +2106,14 @@ static ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, in_len - sizeof(cmd.base) - sizeof(struct ib_uverbs_cmd_hdr), out_len); - ret = modify_qp(file, &cmd, &udata); + ret = modify_qp(attrs, &cmd, &udata); if (ret) return ret; return in_len; } -static int ib_uverbs_ex_modify_qp(struct ib_uverbs_file *file, +static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_modify_qp cmd = {}; @@ -2139,12 +2142,12 @@ static int ib_uverbs_ex_modify_qp(struct ib_uverbs_file *file, return -EOPNOTSUPP; } - ret = modify_qp(file, &cmd, uhw); + ret = modify_qp(attrs, &cmd, uhw); return ret; } -static ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2156,7 +2159,7 @@ static ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, file); + uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -2182,7 +2185,7 @@ static void *alloc_wr(size_t wr_size, __u32 num_sge) num_sge * sizeof (struct ib_sge), GFP_KERNEL); } -static ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_post_send(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2211,7 +2214,7 @@ static ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, if (!user_wr) return -ENOMEM; - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (!qp) goto out; @@ -2248,7 +2251,7 @@ static ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, } ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH, - user_wr->wr.ud.ah, file); + user_wr->wr.ud.ah, attrs); if (!ud->ah) { kfree(ud); ret = -EINVAL; @@ -2462,7 +2465,7 @@ err: return ERR_PTR(ret); } -static ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2482,7 +2485,7 @@ static ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, if (IS_ERR(wr)) return PTR_ERR(wr); - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (!qp) goto out; @@ -2511,7 +2514,7 @@ out: return ret ? ret : in_len; } -static ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2531,7 +2534,7 @@ static ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, if (IS_ERR(wr)) return PTR_ERR(wr); - srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, file); + srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); if (!srq) goto out; @@ -2560,7 +2563,7 @@ out: return ret ? ret : in_len; } -static ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2585,7 +2588,7 @@ static ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - uobj = uobj_alloc(UVERBS_OBJECT_AH, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -2594,7 +2597,7 @@ static ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, goto err; } - pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, file); + pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); if (!pd) { ret = -EINVAL; goto err; @@ -2649,7 +2652,7 @@ err: return ret; } -static ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2658,11 +2661,11 @@ static ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, file, + return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs, in_len); } -static ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2675,7 +2678,7 @@ static ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (!qp) return -EINVAL; @@ -2711,7 +2714,7 @@ out_put: return ret ? ret : in_len; } -static ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -2725,7 +2728,7 @@ static ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (!qp) return -EINVAL; @@ -2830,7 +2833,7 @@ void flow_resources_add(struct ib_uflow_resources *uflow_res, } EXPORT_SYMBOL(flow_resources_add); -static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile, +static int kern_spec_to_ib_spec_action(const struct uverbs_attr_bundle *attrs, struct ib_uverbs_flow_spec *kern_spec, union ib_flow_spec *ib_spec, struct ib_uflow_resources *uflow_res) @@ -2859,7 +2862,7 @@ static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile, ib_spec->action.act = uobj_get_obj_read(flow_action, UVERBS_OBJECT_FLOW_ACTION, kern_spec->action.handle, - ufile); + attrs); if (!ib_spec->action.act) return -EINVAL; ib_spec->action.size = @@ -2877,7 +2880,7 @@ static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile, uobj_get_obj_read(counters, UVERBS_OBJECT_COUNTERS, kern_spec->flow_count.handle, - ufile); + attrs); if (!ib_spec->flow_count.counters) return -EINVAL; ib_spec->flow_count.size = @@ -3058,7 +3061,7 @@ static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec, kern_filter_sz, ib_spec); } -static int kern_spec_to_ib_spec(struct ib_uverbs_file *ufile, +static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs, struct ib_uverbs_flow_spec *kern_spec, union ib_flow_spec *ib_spec, struct ib_uflow_resources *uflow_res) @@ -3067,13 +3070,13 @@ static int kern_spec_to_ib_spec(struct ib_uverbs_file *ufile, return -EINVAL; if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG) - return kern_spec_to_ib_spec_action(ufile, kern_spec, ib_spec, + return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec, uflow_res); else return kern_spec_to_ib_spec_filter(kern_spec, ib_spec); } -static int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_create_wq cmd = {}; @@ -3109,18 +3112,18 @@ static int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file, if (cmd.comp_mask) return -EOPNOTSUPP; - obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, file, + obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs, &ib_dev); if (IS_ERR(obj)) return PTR_ERR(obj); - pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, file); + pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); if (!pd) { err = -EINVAL; goto err_uobj; } - cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, file); + cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); if (!cq) { err = -EINVAL; goto err_put_pd; @@ -3129,7 +3132,7 @@ static int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file, wq_init_attr.cq = cq; wq_init_attr.max_sge = cmd.max_sge; wq_init_attr.max_wr = cmd.max_wr; - wq_init_attr.wq_context = file; + wq_init_attr.wq_context = attrs->ufile; wq_init_attr.wq_type = cmd.wq_type; wq_init_attr.event_handler = ib_uverbs_wq_event_handler; if (ucore->inlen >= (offsetof(typeof(cmd), create_flags) + @@ -3184,7 +3187,7 @@ err_uobj: return err; } -static int ib_uverbs_ex_destroy_wq(struct ib_uverbs_file *file, +static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_destroy_wq cmd = {}; @@ -3217,7 +3220,7 @@ static int ib_uverbs_ex_destroy_wq(struct ib_uverbs_file *file, return -EOPNOTSUPP; resp.response_length = required_resp_len; - uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, file); + uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -3229,7 +3232,7 @@ static int ib_uverbs_ex_destroy_wq(struct ib_uverbs_file *file, return ib_copy_to_udata(ucore, &resp, resp.response_length); } -static int ib_uverbs_ex_modify_wq(struct ib_uverbs_file *file, +static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_modify_wq cmd = {}; @@ -3257,7 +3260,7 @@ static int ib_uverbs_ex_modify_wq(struct ib_uverbs_file *file, if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS)) return -EINVAL; - wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, file); + wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs); if (!wq) return -EINVAL; @@ -3272,7 +3275,7 @@ static int ib_uverbs_ex_modify_wq(struct ib_uverbs_file *file, return ret; } -static int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { @@ -3347,7 +3350,7 @@ static int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file, for (num_read_wqs = 0; num_read_wqs < num_wq_handles; num_read_wqs++) { wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, - wqs_handles[num_read_wqs], file); + wqs_handles[num_read_wqs], attrs); if (!wq) { err = -EINVAL; goto put_wqs; @@ -3356,7 +3359,7 @@ static int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file, wqs[num_read_wqs] = wq; } - uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev); if (IS_ERR(uobj)) { err = PTR_ERR(uobj); goto put_wqs; @@ -3411,7 +3414,7 @@ err_free: return err; } -static int ib_uverbs_ex_destroy_rwq_ind_table(struct ib_uverbs_file *file, +static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { @@ -3437,10 +3440,10 @@ static int ib_uverbs_ex_destroy_rwq_ind_table(struct ib_uverbs_file *file, return -EOPNOTSUPP; return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL, - cmd.ind_tbl_handle, file, 0); + cmd.ind_tbl_handle, attrs, 0); } -static int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, +static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { @@ -3512,13 +3515,13 @@ static int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, kern_flow_attr = &cmd.flow_attr; } - uobj = uobj_alloc(UVERBS_OBJECT_FLOW, file, &ib_dev); + uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev); if (IS_ERR(uobj)) { err = PTR_ERR(uobj); goto err_free_attr; } - qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, file); + qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); if (!qp) { err = -EINVAL; goto err_uobj; @@ -3555,7 +3558,7 @@ static int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, cmd.flow_attr.size >= kern_spec->size; i++) { err = kern_spec_to_ib_spec( - file, (struct ib_uverbs_flow_spec *)kern_spec, + attrs, (struct ib_uverbs_flow_spec *)kern_spec, ib_spec, uflow_res); if (err) goto err_free; @@ -3613,7 +3616,7 @@ err_free_attr: return err; } -static int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file, +static int ib_uverbs_ex_destroy_flow(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { @@ -3630,11 +3633,11 @@ static int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file, if (cmd.comp_mask) return -EINVAL; - return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, file, + return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, attrs, 0); } -static int __uverbs_create_xsrq(struct ib_uverbs_file *file, +static int __uverbs_create_xsrq(struct uverbs_attr_bundle *attrs, struct ib_uverbs_create_xsrq *cmd, struct ib_udata *udata) { @@ -3647,7 +3650,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, int ret; struct ib_device *ib_dev; - obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, file, + obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs, &ib_dev); if (IS_ERR(obj)) return PTR_ERR(obj); @@ -3657,7 +3660,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, if (cmd->srq_type == IB_SRQT_XRC) { xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->xrcd_handle, - file); + attrs); if (IS_ERR(xrcd_uobj)) { ret = -EINVAL; goto err; @@ -3675,21 +3678,21 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, if (ib_srq_has_cq(cmd->srq_type)) { attr.ext.cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, - cmd->cq_handle, file); + cmd->cq_handle, attrs); if (!attr.ext.cq) { ret = -EINVAL; goto err_put_xrcd; } } - pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, file); + pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, attrs); if (!pd) { ret = -EINVAL; goto err_put_cq; } attr.event_handler = ib_uverbs_srq_event_handler; - attr.srq_context = file; + attr.srq_context = attrs->ufile; attr.srq_type = cmd->srq_type; attr.attr.max_wr = cmd->max_wr; attr.attr.max_sge = cmd->max_sge; @@ -3770,7 +3773,7 @@ err: return ret; } -static ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -3800,14 +3803,14 @@ static ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - ret = __uverbs_create_xsrq(file, &xcmd, &udata); + ret = __uverbs_create_xsrq(attrs, &xcmd, &udata); if (ret) return ret; return in_len; } -static ssize_t ib_uverbs_create_xsrq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -3827,14 +3830,14 @@ static ssize_t ib_uverbs_create_xsrq(struct ib_uverbs_file *file, in_len - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr), out_len - sizeof(resp)); - ret = __uverbs_create_xsrq(file, &cmd, &udata); + ret = __uverbs_create_xsrq(attrs, &cmd, &udata); if (ret) return ret; return in_len; } -static ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -3850,7 +3853,7 @@ static ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, ib_uverbs_init_udata(&udata, buf + sizeof cmd, NULL, in_len - sizeof cmd, out_len); - srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, file); + srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); if (!srq) return -EINVAL; @@ -3864,7 +3867,7 @@ static ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, return ret ? ret : in_len; } -static ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -3880,7 +3883,7 @@ static ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, file); + srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); if (!srq) return -EINVAL; @@ -3903,7 +3906,7 @@ static ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file, return in_len; } -static ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { @@ -3915,7 +3918,7 @@ static ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, file); + uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); if (IS_ERR(uobj)) return PTR_ERR(uobj); @@ -3931,7 +3934,7 @@ static ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, return in_len; } -static int ib_uverbs_ex_query_device(struct ib_uverbs_file *file, +static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { @@ -3942,7 +3945,7 @@ static int ib_uverbs_ex_query_device(struct ib_uverbs_file *file, struct ib_device *ib_dev; int err; - ucontext = ib_uverbs_get_ucontext(file); + ucontext = ib_uverbs_get_ucontext(attrs); if (IS_ERR(ucontext)) return PTR_ERR(ucontext); ib_dev = ucontext->device; @@ -4055,7 +4058,7 @@ end: return err; } -static int ib_uverbs_ex_modify_cq(struct ib_uverbs_file *file, +static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { struct ib_uverbs_ex_modify_cq cmd = {}; @@ -4084,7 +4087,7 @@ static int ib_uverbs_ex_modify_cq(struct ib_uverbs_file *file, if (cmd.attr_mask > IB_CQ_MODERATE) return -EOPNOTSUPP; - cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, file); + cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); if (!cq) return -EINVAL; diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 6a1284c8a07d..c5d245133b51 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -81,7 +81,7 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data); * Must be called with the ufile->device->disassociate_srcu held, and the lock * must be held until use of the ucontext is finished. */ -struct ib_ucontext *ib_uverbs_get_ucontext(struct ib_uverbs_file *ufile) +struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile) { /* * We do not hold the hw_destroy_rwsem lock for this flow, instead @@ -99,7 +99,7 @@ struct ib_ucontext *ib_uverbs_get_ucontext(struct ib_uverbs_file *ufile) return ucontext; } -EXPORT_SYMBOL(ib_uverbs_get_ucontext); +EXPORT_SYMBOL(ib_uverbs_get_ucontext_file); int uverbs_dealloc_mw(struct ib_mw *mw) { @@ -632,6 +632,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, struct uverbs_api *uapi = file->device->uapi; struct ib_uverbs_ex_cmd_hdr ex_hdr; struct ib_uverbs_cmd_hdr hdr; + struct uverbs_attr_bundle bundle; int srcu_key; ssize_t ret; @@ -666,8 +667,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, buf += sizeof(hdr); + bundle.ufile = file; if (!method_elm->is_ex) { - ret = method_elm->handler(file, buf, hdr.in_words * 4, + ret = method_elm->handler(&bundle, buf, hdr.in_words * 4, hdr.out_words * 4); } else { struct ib_udata ucore; @@ -685,7 +687,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ex_hdr.provider_in_words * 8, ex_hdr.provider_out_words * 8); - ret = method_elm->handler_ex(file, &ucore, &uhw); + ret = method_elm->handler_ex(&bundle, &ucore, &uhw); ret = (ret) ? : count; } @@ -701,7 +703,7 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) int srcu_key; srcu_key = srcu_read_lock(&file->device->disassociate_srcu); - ucontext = ib_uverbs_get_ucontext(file); + ucontext = ib_uverbs_get_ucontext_file(file); if (IS_ERR(ucontext)) { ret = PTR_ERR(ucontext); goto out; diff --git a/drivers/infiniband/core/uverbs_uapi.c b/drivers/infiniband/core/uverbs_uapi.c index a92adbe2b034..ad72d726efa9 100644 --- a/drivers/infiniband/core/uverbs_uapi.c +++ b/drivers/infiniband/core/uverbs_uapi.c @@ -8,14 +8,14 @@ #include "rdma_core.h" #include "uverbs.h" -static ssize_t ib_uverbs_notsupp(struct ib_uverbs_file *file, +static ssize_t ib_uverbs_notsupp(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len) { return -EOPNOTSUPP; } -static int ib_uverbs_ex_notsupp(struct ib_uverbs_file *file, +static int ib_uverbs_ex_notsupp(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw) { return -EOPNOTSUPP; diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c index ee8db8d9e919..8ccb655db1ec 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -42,7 +42,7 @@ struct devx_umem_reg_cmd { static struct mlx5_ib_ucontext *devx_ufile2uctx(struct ib_uverbs_file *file) { - return to_mucontext(ib_uverbs_get_ucontext(file)); + return to_mucontext(ib_uverbs_get_ucontext_file(file)); } int mlx5_ib_devx_create(struct mlx5_ib_dev *dev) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index ee8a6008e222..0b7269870571 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -4207,7 +4207,7 @@ ib_get_vector_affinity(struct ib_device *device, int comp_vector) */ void rdma_roce_rescan_device(struct ib_device *ibdev); -struct ib_ucontext *ib_uverbs_get_ucontext(struct ib_uverbs_file *ufile); +struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile); int uverbs_destroy_def_handler(struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs); diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index 963dd6b70cde..f744691cd9ae 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -368,10 +368,10 @@ struct uapi_definition { union { bool (*func_is_supported)(struct ib_device *device); - ssize_t (*func_write)(struct ib_uverbs_file *file, + ssize_t (*func_write)(struct uverbs_attr_bundle *attrs, const char __user *buf, int in_len, int out_len); - int (*func_write_ex)(struct ib_uverbs_file *file, + int (*func_write_ex)(struct uverbs_attr_bundle *attrs, struct ib_udata *ucore, struct ib_udata *uhw); const struct uapi_definition *chain; @@ -806,6 +806,12 @@ static inline int _uverbs_copy_from_or_zero(void *to, #define uverbs_copy_from_or_zero(to, attrs_bundle, idx) \ _uverbs_copy_from_or_zero(to, attrs_bundle, idx, sizeof(*to)) +static inline struct ib_ucontext * +ib_uverbs_get_ucontext(const struct uverbs_attr_bundle *attrs) +{ + return ib_uverbs_get_ucontext_file(attrs->ufile); +} + #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) int uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle, size_t idx, u64 allowed_bits); diff --git a/include/rdma/uverbs_std_types.h b/include/rdma/uverbs_std_types.h index e3154f8d3cda..a6358c36bba0 100644 --- a/include/rdma/uverbs_std_types.h +++ b/include/rdma/uverbs_std_types.h @@ -45,15 +45,15 @@ */ #define _uobj_check_id(_id) ((_id) * typecheck(u32, _id)) -#define uobj_get_type(_ufile, _object) \ - uapi_get_object((_ufile)->device->uapi, _object) +#define uobj_get_type(_attrs, _object) \ + uapi_get_object((_attrs)->ufile->device->uapi, _object) -#define uobj_get_read(_type, _id, _ufile) \ - rdma_lookup_get_uobject(uobj_get_type(_ufile, _type), _ufile, \ +#define uobj_get_read(_type, _id, _attrs) \ + rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ _uobj_check_id(_id), UVERBS_LOOKUP_READ) -#define ufd_get_read(_type, _fdnum, _ufile) \ - rdma_lookup_get_uobject(uobj_get_type(_ufile, _type), _ufile, \ +#define ufd_get_read(_type, _fdnum, _attrs) \ + rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ (_fdnum)*typecheck(s32, _fdnum), \ UVERBS_LOOKUP_READ) @@ -63,26 +63,28 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj) return NULL; return uobj->object; } -#define uobj_get_obj_read(_object, _type, _id, _ufile) \ +#define uobj_get_obj_read(_object, _type, _id, _attrs) \ ((struct ib_##_object *)_uobj_get_obj_read( \ - uobj_get_read(_type, _id, _ufile))) + uobj_get_read(_type, _id, _attrs))) -#define uobj_get_write(_type, _id, _ufile) \ - rdma_lookup_get_uobject(uobj_get_type(_ufile, _type), _ufile, \ +#define uobj_get_write(_type, _id, _attrs) \ + rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ _uobj_check_id(_id), UVERBS_LOOKUP_WRITE) int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id, - struct ib_uverbs_file *ufile, int success_res); -#define uobj_perform_destroy(_type, _id, _ufile, _success_res) \ - __uobj_perform_destroy(uobj_get_type(_ufile, _type), \ - _uobj_check_id(_id), _ufile, _success_res) + const struct uverbs_attr_bundle *attrs, + int success_res); +#define uobj_perform_destroy(_type, _id, _attrs, _success_res) \ + __uobj_perform_destroy(uobj_get_type(_attrs, _type), \ + _uobj_check_id(_id), _attrs, _success_res) struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj, - u32 id, struct ib_uverbs_file *ufile); + u32 id, + const struct uverbs_attr_bundle *attrs); -#define uobj_get_destroy(_type, _id, _ufile) \ - __uobj_get_destroy(uobj_get_type(_ufile, _type), _uobj_check_id(_id), \ - _ufile) +#define uobj_get_destroy(_type, _id, _attrs) \ + __uobj_get_destroy(uobj_get_type(_attrs, _type), _uobj_check_id(_id), \ + _attrs) static inline void uobj_put_destroy(struct ib_uobject *uobj) { @@ -118,18 +120,18 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj) } static inline struct ib_uobject * -__uobj_alloc(const struct uverbs_api_object *obj, struct ib_uverbs_file *ufile, - struct ib_device **ib_dev) +__uobj_alloc(const struct uverbs_api_object *obj, + struct uverbs_attr_bundle *attrs, struct ib_device **ib_dev) { - struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, ufile); + struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, attrs->ufile); if (!IS_ERR(uobj)) *ib_dev = uobj->context->device; return uobj; } -#define uobj_alloc(_type, _ufile, _ib_dev) \ - __uobj_alloc(uobj_get_type(_ufile, _type), _ufile, _ib_dev) +#define uobj_alloc(_type, _attrs, _ib_dev) \ + __uobj_alloc(uobj_get_type(_attrs, _type), _attrs, _ib_dev) static inline void uverbs_flow_action_fill_action(struct ib_flow_action *action, struct ib_uobject *uobj, |