Commit 8313c10f authored by Jason Gunthorpe's avatar Jason Gunthorpe

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: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
parent 1b09577b
...@@ -224,12 +224,14 @@ int uobj_destroy(struct ib_uobject *uobj) ...@@ -224,12 +224,14 @@ int uobj_destroy(struct ib_uobject *uobj)
* uverbs_put_destroy. * uverbs_put_destroy.
*/ */
struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj, 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; struct ib_uobject *uobj;
int ret; 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)) if (IS_ERR(uobj))
return uobj; return uobj;
...@@ -248,11 +250,12 @@ struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj, ...@@ -248,11 +250,12 @@ struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj,
* the uobj. * the uobj.
*/ */
int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id, 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; struct ib_uobject *uobj;
uobj = __uobj_get_destroy(obj, id, ufile); uobj = __uobj_get_destroy(obj, id, attrs);
if (IS_ERR(uobj)) if (IS_ERR(uobj))
return PTR_ERR(uobj); return PTR_ERR(uobj);
...@@ -267,7 +270,7 @@ static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile, ...@@ -267,7 +270,7 @@ static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile,
struct ib_uobject *uobj; struct ib_uobject *uobj;
struct ib_ucontext *ucontext; struct ib_ucontext *ucontext;
ucontext = ib_uverbs_get_ucontext(ufile); ucontext = ib_uverbs_get_ucontext_file(ufile);
if (IS_ERR(ucontext)) if (IS_ERR(ucontext))
return ERR_CAST(ucontext); return ERR_CAST(ucontext);
......
...@@ -137,10 +137,10 @@ struct uverbs_api_ioctl_method { ...@@ -137,10 +137,10 @@ struct uverbs_api_ioctl_method {
}; };
struct uverbs_api_write_method { struct uverbs_api_write_method {
ssize_t (*handler)(struct ib_uverbs_file *file, const char __user *buf, ssize_t (*handler)(struct uverbs_attr_bundle *attrs,
int in_len, int out_len); const char __user *buf, int in_len, int out_len);
int (*handler_ex)(struct ib_uverbs_file *file, struct ib_udata *ucore, int (*handler_ex)(struct uverbs_attr_bundle *attrs,
struct ib_udata *uhw); struct ib_udata *ucore, struct ib_udata *uhw);
u8 disabled:1; u8 disabled:1;
u8 is_ex:1; u8 is_ex:1;
}; };
......
This diff is collapsed.
...@@ -81,7 +81,7 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data); ...@@ -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 called with the ufile->device->disassociate_srcu held, and the lock
* must be held until use of the ucontext is finished. * 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 * 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) ...@@ -99,7 +99,7 @@ struct ib_ucontext *ib_uverbs_get_ucontext(struct ib_uverbs_file *ufile)
return ucontext; return ucontext;
} }
EXPORT_SYMBOL(ib_uverbs_get_ucontext); EXPORT_SYMBOL(ib_uverbs_get_ucontext_file);
int uverbs_dealloc_mw(struct ib_mw *mw) 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, ...@@ -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 uverbs_api *uapi = file->device->uapi;
struct ib_uverbs_ex_cmd_hdr ex_hdr; struct ib_uverbs_ex_cmd_hdr ex_hdr;
struct ib_uverbs_cmd_hdr hdr; struct ib_uverbs_cmd_hdr hdr;
struct uverbs_attr_bundle bundle;
int srcu_key; int srcu_key;
ssize_t ret; ssize_t ret;
...@@ -666,8 +667,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -666,8 +667,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
buf += sizeof(hdr); buf += sizeof(hdr);
bundle.ufile = file;
if (!method_elm->is_ex) { 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); hdr.out_words * 4);
} else { } else {
struct ib_udata ucore; struct ib_udata ucore;
...@@ -685,7 +687,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -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_in_words * 8,
ex_hdr.provider_out_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; ret = (ret) ? : count;
} }
...@@ -701,7 +703,7 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -701,7 +703,7 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
int srcu_key; int srcu_key;
srcu_key = srcu_read_lock(&file->device->disassociate_srcu); 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)) { if (IS_ERR(ucontext)) {
ret = PTR_ERR(ucontext); ret = PTR_ERR(ucontext);
goto out; goto out;
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
#include "rdma_core.h" #include "rdma_core.h"
#include "uverbs.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, const char __user *buf, int in_len,
int out_len) int out_len)
{ {
return -EOPNOTSUPP; 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) struct ib_udata *ucore, struct ib_udata *uhw)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -42,7 +42,7 @@ struct devx_umem_reg_cmd { ...@@ -42,7 +42,7 @@ struct devx_umem_reg_cmd {
static struct mlx5_ib_ucontext *devx_ufile2uctx(struct ib_uverbs_file *file) 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) int mlx5_ib_devx_create(struct mlx5_ib_dev *dev)
......
...@@ -4207,7 +4207,7 @@ ib_get_vector_affinity(struct ib_device *device, int comp_vector) ...@@ -4207,7 +4207,7 @@ ib_get_vector_affinity(struct ib_device *device, int comp_vector)
*/ */
void rdma_roce_rescan_device(struct ib_device *ibdev); 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, int uverbs_destroy_def_handler(struct ib_uverbs_file *file,
struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
......
...@@ -368,10 +368,10 @@ struct uapi_definition { ...@@ -368,10 +368,10 @@ struct uapi_definition {
union { union {
bool (*func_is_supported)(struct ib_device *device); 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, const char __user *buf, int in_len,
int out_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 *ucore,
struct ib_udata *uhw); struct ib_udata *uhw);
const struct uapi_definition *chain; const struct uapi_definition *chain;
...@@ -806,6 +806,12 @@ static inline int _uverbs_copy_from_or_zero(void *to, ...@@ -806,6 +806,12 @@ static inline int _uverbs_copy_from_or_zero(void *to,
#define uverbs_copy_from_or_zero(to, attrs_bundle, idx) \ #define uverbs_copy_from_or_zero(to, attrs_bundle, idx) \
_uverbs_copy_from_or_zero(to, attrs_bundle, idx, sizeof(*to)) _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) #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
int uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle, int uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle,
size_t idx, u64 allowed_bits); size_t idx, u64 allowed_bits);
......
...@@ -45,15 +45,15 @@ ...@@ -45,15 +45,15 @@
*/ */
#define _uobj_check_id(_id) ((_id) * typecheck(u32, _id)) #define _uobj_check_id(_id) ((_id) * typecheck(u32, _id))
#define uobj_get_type(_ufile, _object) \ #define uobj_get_type(_attrs, _object) \
uapi_get_object((_ufile)->device->uapi, _object) uapi_get_object((_attrs)->ufile->device->uapi, _object)
#define uobj_get_read(_type, _id, _ufile) \ #define uobj_get_read(_type, _id, _attrs) \
rdma_lookup_get_uobject(uobj_get_type(_ufile, _type), _ufile, \ rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
_uobj_check_id(_id), UVERBS_LOOKUP_READ) _uobj_check_id(_id), UVERBS_LOOKUP_READ)
#define ufd_get_read(_type, _fdnum, _ufile) \ #define ufd_get_read(_type, _fdnum, _attrs) \
rdma_lookup_get_uobject(uobj_get_type(_ufile, _type), _ufile, \ rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
(_fdnum)*typecheck(s32, _fdnum), \ (_fdnum)*typecheck(s32, _fdnum), \
UVERBS_LOOKUP_READ) UVERBS_LOOKUP_READ)
...@@ -63,26 +63,28 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj) ...@@ -63,26 +63,28 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj)
return NULL; return NULL;
return uobj->object; 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( \ ((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) \ #define uobj_get_write(_type, _id, _attrs) \
rdma_lookup_get_uobject(uobj_get_type(_ufile, _type), _ufile, \ rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
_uobj_check_id(_id), UVERBS_LOOKUP_WRITE) _uobj_check_id(_id), UVERBS_LOOKUP_WRITE)
int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id, 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,
#define uobj_perform_destroy(_type, _id, _ufile, _success_res) \ int success_res);
__uobj_perform_destroy(uobj_get_type(_ufile, _type), \ #define uobj_perform_destroy(_type, _id, _attrs, _success_res) \
_uobj_check_id(_id), _ufile, _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, 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) \ #define uobj_get_destroy(_type, _id, _attrs) \
__uobj_get_destroy(uobj_get_type(_ufile, _type), _uobj_check_id(_id), \ __uobj_get_destroy(uobj_get_type(_attrs, _type), _uobj_check_id(_id), \
_ufile) _attrs)
static inline void uobj_put_destroy(struct ib_uobject *uobj) static inline void uobj_put_destroy(struct ib_uobject *uobj)
{ {
...@@ -118,18 +120,18 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj) ...@@ -118,18 +120,18 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj)
} }
static inline struct ib_uobject * static inline struct ib_uobject *
__uobj_alloc(const struct uverbs_api_object *obj, struct ib_uverbs_file *ufile, __uobj_alloc(const struct uverbs_api_object *obj,
struct ib_device **ib_dev) 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)) if (!IS_ERR(uobj))
*ib_dev = uobj->context->device; *ib_dev = uobj->context->device;
return uobj; return uobj;
} }
#define uobj_alloc(_type, _ufile, _ib_dev) \ #define uobj_alloc(_type, _attrs, _ib_dev) \
__uobj_alloc(uobj_get_type(_ufile, _type), _ufile, _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, static inline void uverbs_flow_action_fill_action(struct ib_flow_action *action,
struct ib_uobject *uobj, struct ib_uobject *uobj,
......
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