Commit 3d9dfd06 authored by Shamir Rabinovitch's avatar Shamir Rabinovitch Committed by Jason Gunthorpe

IB/uverbs: Add ib_ucontext to uverbs_attr_bundle sent from ioctl and cmd flows

Add ib_ucontext to the uverbs_attr_bundle sent down the iocl and cmd flows
as soon as the flow has ib_uobject.

In addition, remove rdma_get_ucontext helper function that is only used by
ib_umem_get.
Signed-off-by: default avatarShamir Rabinovitch <shamir.rabinovitch@oracle.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 0dd9ce18
...@@ -438,6 +438,38 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj, ...@@ -438,6 +438,38 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
uverbs_uobject_put(uobj); uverbs_uobject_put(uobj);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
struct ib_uobject *_uobj_get_read(enum uverbs_default_objects type,
u32 object_id,
struct uverbs_attr_bundle *attrs)
{
struct ib_uobject *uobj;
uobj = rdma_lookup_get_uobject(uobj_get_type(attrs, type), attrs->ufile,
object_id, UVERBS_LOOKUP_READ);
if (IS_ERR(uobj))
return uobj;
attrs->context = uobj->context;
return uobj;
}
struct ib_uobject *_uobj_get_write(enum uverbs_default_objects type,
u32 object_id,
struct uverbs_attr_bundle *attrs)
{
struct ib_uobject *uobj;
uobj = rdma_lookup_get_uobject(uobj_get_type(attrs, type), attrs->ufile,
object_id, UVERBS_LOOKUP_WRITE);
if (IS_ERR(uobj))
return uobj;
attrs->context = uobj->context;
return uobj;
}
static struct ib_uobject * static struct ib_uobject *
alloc_begin_idr_uobject(const struct uverbs_api_object *obj, alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
......
...@@ -96,9 +96,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, ...@@ -96,9 +96,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr,
struct scatterlist *sg, *sg_list_start; struct scatterlist *sg, *sg_list_start;
unsigned int gup_flags = FOLL_WRITE; unsigned int gup_flags = FOLL_WRITE;
context = rdma_get_ucontext(udata); if (!udata)
if (IS_ERR(context)) return ERR_PTR(-EIO);
return ERR_CAST(context);
context = container_of(udata, struct uverbs_attr_bundle, driver_udata)
->context;
if (!context)
return ERR_PTR(-EIO);
if (dmasync) if (dmasync)
dma_attrs |= DMA_ATTR_WRITE_BARRIER; dma_attrs |= DMA_ATTR_WRITE_BARRIER;
......
...@@ -2634,7 +2634,7 @@ void flow_resources_add(struct ib_uflow_resources *uflow_res, ...@@ -2634,7 +2634,7 @@ void flow_resources_add(struct ib_uflow_resources *uflow_res,
} }
EXPORT_SYMBOL(flow_resources_add); EXPORT_SYMBOL(flow_resources_add);
static int kern_spec_to_ib_spec_action(const struct uverbs_attr_bundle *attrs, static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs,
struct ib_uverbs_flow_spec *kern_spec, struct ib_uverbs_flow_spec *kern_spec,
union ib_flow_spec *ib_spec, union ib_flow_spec *ib_spec,
struct ib_uflow_resources *uflow_res) struct ib_uflow_resources *uflow_res)
......
...@@ -213,6 +213,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle, ...@@ -213,6 +213,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
ret = PTR_ERR(attr->uobjects[i]); ret = PTR_ERR(attr->uobjects[i]);
break; break;
} }
pbundle->bundle.context = attr->uobjects[i]->context;
} }
attr->len = i; attr->len = i;
...@@ -330,6 +331,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle, ...@@ -330,6 +331,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
uattr->data_s64); uattr->data_s64);
if (IS_ERR(o_attr->uobject)) if (IS_ERR(o_attr->uobject))
return PTR_ERR(o_attr->uobject); return PTR_ERR(o_attr->uobject);
pbundle->bundle.context = o_attr->uobject->context;
__set_bit(attr_bkey, pbundle->uobj_finalize); __set_bit(attr_bkey, pbundle->uobj_finalize);
if (spec->u.obj.access == UVERBS_ACCESS_NEW) { if (spec->u.obj.access == UVERBS_ACCESS_NEW) {
...@@ -592,6 +594,7 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile, ...@@ -592,6 +594,7 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile,
pbundle->method_elm = method_elm; pbundle->method_elm = method_elm;
pbundle->method_key = attrs_iter.index; pbundle->method_key = attrs_iter.index;
pbundle->bundle.ufile = ufile; pbundle->bundle.ufile = ufile;
pbundle->bundle.context = NULL; /* only valid if bundle has uobject */
pbundle->radix = &uapi->radix; pbundle->radix = &uapi->radix;
pbundle->radix_slots = slot; pbundle->radix_slots = slot;
pbundle->radix_slots_len = radix_tree_chunk_size(&attrs_iter); pbundle->radix_slots_len = radix_tree_chunk_size(&attrs_iter);
......
...@@ -101,30 +101,6 @@ struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile) ...@@ -101,30 +101,6 @@ struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile)
} }
EXPORT_SYMBOL(ib_uverbs_get_ucontext_file); EXPORT_SYMBOL(ib_uverbs_get_ucontext_file);
/* rdma_get_ucontext - Return the ucontext from a udata
* @udata: The udata to get the context from
*
* This can only be called from within a uapi method that was passed ib_udata
* as a parameter. It returns the ucontext associated with the udata, or ERR_PTR
* if the udata is NULL or the ucontext has been disassociated.
*/
struct ib_ucontext *rdma_get_ucontext(struct ib_udata *udata)
{
if (!udata)
return ERR_PTR(-EIO);
/*
* FIXME: Really all cases that get here with a udata will have
* already called ib_uverbs_get_ucontext_file, or located a uobject
* that points to a ucontext. We could store that result in the udata
* so this function can't fail.
*/
return ib_uverbs_get_ucontext_file(
container_of(udata, struct uverbs_attr_bundle, driver_udata)
->ufile);
}
EXPORT_SYMBOL(rdma_get_ucontext);
int uverbs_dealloc_mw(struct ib_mw *mw) int uverbs_dealloc_mw(struct ib_mw *mw)
{ {
struct ib_pd *pd = mw->pd; struct ib_pd *pd = mw->pd;
...@@ -719,6 +695,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -719,6 +695,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
memset(bundle.attr_present, 0, sizeof(bundle.attr_present)); memset(bundle.attr_present, 0, sizeof(bundle.attr_present));
bundle.ufile = file; bundle.ufile = file;
bundle.context = NULL; /* only valid if bundle has uobject */
if (!method_elm->is_ex) { if (!method_elm->is_ex) {
size_t in_len = hdr.in_words * 4 - sizeof(hdr); size_t in_len = hdr.in_words * 4 - sizeof(hdr);
size_t out_len = hdr.out_words * 4; size_t out_len = hdr.out_words * 4;
......
...@@ -4247,8 +4247,6 @@ void rdma_roce_rescan_device(struct ib_device *ibdev); ...@@ -4247,8 +4247,6 @@ void rdma_roce_rescan_device(struct ib_device *ibdev);
struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile); struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
struct ib_ucontext *rdma_get_ucontext(struct ib_udata *udata);
int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs); int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num, struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num,
......
...@@ -652,6 +652,7 @@ struct uverbs_attr_bundle { ...@@ -652,6 +652,7 @@ struct uverbs_attr_bundle {
struct ib_udata driver_udata; struct ib_udata driver_udata;
struct ib_udata ucore; struct ib_udata ucore;
struct ib_uverbs_file *ufile; struct ib_uverbs_file *ufile;
struct ib_ucontext *context;
DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN); DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN);
struct uverbs_attr attrs[]; struct uverbs_attr attrs[];
}; };
......
...@@ -48,9 +48,12 @@ ...@@ -48,9 +48,12 @@
#define uobj_get_type(_attrs, _object) \ #define uobj_get_type(_attrs, _object) \
uapi_get_object((_attrs)->ufile->device->uapi, _object) uapi_get_object((_attrs)->ufile->device->uapi, _object)
struct ib_uobject *_uobj_get_read(enum uverbs_default_objects type,
u32 object_id,
struct uverbs_attr_bundle *attrs);
#define uobj_get_read(_type, _id, _attrs) \ #define uobj_get_read(_type, _id, _attrs) \
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ _uobj_get_read(_type, _uobj_check_id(_id), _attrs)
_uobj_check_id(_id), UVERBS_LOOKUP_READ)
#define ufd_get_read(_type, _fdnum, _attrs) \ #define ufd_get_read(_type, _fdnum, _attrs) \
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
...@@ -67,9 +70,12 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj) ...@@ -67,9 +70,12 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj)
((struct ib_##_object *)_uobj_get_obj_read( \ ((struct ib_##_object *)_uobj_get_obj_read( \
uobj_get_read(_type, _id, _attrs))) uobj_get_read(_type, _id, _attrs)))
struct ib_uobject *_uobj_get_write(enum uverbs_default_objects type,
u32 object_id,
struct uverbs_attr_bundle *attrs);
#define uobj_get_write(_type, _id, _attrs) \ #define uobj_get_write(_type, _id, _attrs) \
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ _uobj_get_write(_type, _uobj_check_id(_id), _attrs)
_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,
const struct uverbs_attr_bundle *attrs); const struct uverbs_attr_bundle *attrs);
...@@ -123,8 +129,10 @@ __uobj_alloc(const struct uverbs_api_object *obj, ...@@ -123,8 +129,10 @@ __uobj_alloc(const struct uverbs_api_object *obj,
{ {
struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, attrs->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;
attrs->context = uobj->context;
}
return uobj; return 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