Skip to content

Commit 3d9dfd0

Browse files
srabinovjgunthorpe
authored andcommitted
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: Shamir Rabinovitch <shamir.rabinovitch@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 0dd9ce1 commit 3d9dfd0

8 files changed

Lines changed: 58 additions & 35 deletions

File tree

‎drivers/infiniband/core/rdma_core.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,38 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
438438
uverbs_uobject_put(uobj);
439439
return ERR_PTR(ret);
440440
}
441+
struct ib_uobject *_uobj_get_read(enum uverbs_default_objects type,
442+
u32 object_id,
443+
struct uverbs_attr_bundle *attrs)
444+
{
445+
struct ib_uobject *uobj;
446+
447+
uobj = rdma_lookup_get_uobject(uobj_get_type(attrs, type), attrs->ufile,
448+
object_id, UVERBS_LOOKUP_READ);
449+
if (IS_ERR(uobj))
450+
return uobj;
451+
452+
attrs->context = uobj->context;
453+
454+
return uobj;
455+
}
456+
457+
struct ib_uobject *_uobj_get_write(enum uverbs_default_objects type,
458+
u32 object_id,
459+
struct uverbs_attr_bundle *attrs)
460+
{
461+
struct ib_uobject *uobj;
462+
463+
uobj = rdma_lookup_get_uobject(uobj_get_type(attrs, type), attrs->ufile,
464+
object_id, UVERBS_LOOKUP_WRITE);
465+
466+
if (IS_ERR(uobj))
467+
return uobj;
468+
469+
attrs->context = uobj->context;
470+
471+
return uobj;
472+
}
441473

442474
static struct ib_uobject *
443475
alloc_begin_idr_uobject(const struct uverbs_api_object *obj,

‎drivers/infiniband/core/umem.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr,
9696
struct scatterlist *sg, *sg_list_start;
9797
unsigned int gup_flags = FOLL_WRITE;
9898

99-
context = rdma_get_ucontext(udata);
100-
if (IS_ERR(context))
101-
return ERR_CAST(context);
99+
if (!udata)
100+
return ERR_PTR(-EIO);
101+
102+
context = container_of(udata, struct uverbs_attr_bundle, driver_udata)
103+
->context;
104+
if (!context)
105+
return ERR_PTR(-EIO);
102106

103107
if (dmasync)
104108
dma_attrs |= DMA_ATTR_WRITE_BARRIER;

‎drivers/infiniband/core/uverbs_cmd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ void flow_resources_add(struct ib_uflow_resources *uflow_res,
26342634
}
26352635
EXPORT_SYMBOL(flow_resources_add);
26362636

2637-
static int kern_spec_to_ib_spec_action(const struct uverbs_attr_bundle *attrs,
2637+
static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs,
26382638
struct ib_uverbs_flow_spec *kern_spec,
26392639
union ib_flow_spec *ib_spec,
26402640
struct ib_uflow_resources *uflow_res)

‎drivers/infiniband/core/uverbs_ioctl.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
213213
ret = PTR_ERR(attr->uobjects[i]);
214214
break;
215215
}
216+
pbundle->bundle.context = attr->uobjects[i]->context;
216217
}
217218

218219
attr->len = i;
@@ -330,6 +331,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
330331
uattr->data_s64);
331332
if (IS_ERR(o_attr->uobject))
332333
return PTR_ERR(o_attr->uobject);
334+
pbundle->bundle.context = o_attr->uobject->context;
333335
__set_bit(attr_bkey, pbundle->uobj_finalize);
334336

335337
if (spec->u.obj.access == UVERBS_ACCESS_NEW) {
@@ -592,6 +594,7 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile,
592594
pbundle->method_elm = method_elm;
593595
pbundle->method_key = attrs_iter.index;
594596
pbundle->bundle.ufile = ufile;
597+
pbundle->bundle.context = NULL; /* only valid if bundle has uobject */
595598
pbundle->radix = &uapi->radix;
596599
pbundle->radix_slots = slot;
597600
pbundle->radix_slots_len = radix_tree_chunk_size(&attrs_iter);

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,6 @@ struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile)
101101
}
102102
EXPORT_SYMBOL(ib_uverbs_get_ucontext_file);
103103

104-
/* rdma_get_ucontext - Return the ucontext from a udata
105-
* @udata: The udata to get the context from
106-
*
107-
* This can only be called from within a uapi method that was passed ib_udata
108-
* as a parameter. It returns the ucontext associated with the udata, or ERR_PTR
109-
* if the udata is NULL or the ucontext has been disassociated.
110-
*/
111-
struct ib_ucontext *rdma_get_ucontext(struct ib_udata *udata)
112-
{
113-
if (!udata)
114-
return ERR_PTR(-EIO);
115-
116-
/*
117-
* FIXME: Really all cases that get here with a udata will have
118-
* already called ib_uverbs_get_ucontext_file, or located a uobject
119-
* that points to a ucontext. We could store that result in the udata
120-
* so this function can't fail.
121-
*/
122-
return ib_uverbs_get_ucontext_file(
123-
container_of(udata, struct uverbs_attr_bundle, driver_udata)
124-
->ufile);
125-
}
126-
EXPORT_SYMBOL(rdma_get_ucontext);
127-
128104
int uverbs_dealloc_mw(struct ib_mw *mw)
129105
{
130106
struct ib_pd *pd = mw->pd;
@@ -719,6 +695,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
719695

720696
memset(bundle.attr_present, 0, sizeof(bundle.attr_present));
721697
bundle.ufile = file;
698+
bundle.context = NULL; /* only valid if bundle has uobject */
722699
if (!method_elm->is_ex) {
723700
size_t in_len = hdr.in_words * 4 - sizeof(hdr);
724701
size_t out_len = hdr.out_words * 4;

‎include/rdma/ib_verbs.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,8 +4247,6 @@ void rdma_roce_rescan_device(struct ib_device *ibdev);
42474247

42484248
struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
42494249

4250-
struct ib_ucontext *rdma_get_ucontext(struct ib_udata *udata);
4251-
42524250
int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
42534251

42544252
struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num,

‎include/rdma/uverbs_ioctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ struct uverbs_attr_bundle {
652652
struct ib_udata driver_udata;
653653
struct ib_udata ucore;
654654
struct ib_uverbs_file *ufile;
655+
struct ib_ucontext *context;
655656
DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN);
656657
struct uverbs_attr attrs[];
657658
};

‎include/rdma/uverbs_std_types.h‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@
4848
#define uobj_get_type(_attrs, _object) \
4949
uapi_get_object((_attrs)->ufile->device->uapi, _object)
5050

51+
struct ib_uobject *_uobj_get_read(enum uverbs_default_objects type,
52+
u32 object_id,
53+
struct uverbs_attr_bundle *attrs);
54+
5155
#define uobj_get_read(_type, _id, _attrs) \
52-
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
53-
_uobj_check_id(_id), UVERBS_LOOKUP_READ)
56+
_uobj_get_read(_type, _uobj_check_id(_id), _attrs)
5457

5558
#define ufd_get_read(_type, _fdnum, _attrs) \
5659
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)
6770
((struct ib_##_object *)_uobj_get_obj_read( \
6871
uobj_get_read(_type, _id, _attrs)))
6972

73+
struct ib_uobject *_uobj_get_write(enum uverbs_default_objects type,
74+
u32 object_id,
75+
struct uverbs_attr_bundle *attrs);
76+
7077
#define uobj_get_write(_type, _id, _attrs) \
71-
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
72-
_uobj_check_id(_id), UVERBS_LOOKUP_WRITE)
78+
_uobj_get_write(_type, _uobj_check_id(_id), _attrs)
7379

7480
int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id,
7581
const struct uverbs_attr_bundle *attrs);
@@ -123,8 +129,10 @@ __uobj_alloc(const struct uverbs_api_object *obj,
123129
{
124130
struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, attrs->ufile);
125131

126-
if (!IS_ERR(uobj))
132+
if (!IS_ERR(uobj)) {
127133
*ib_dev = uobj->context->device;
134+
attrs->context = uobj->context;
135+
}
128136
return uobj;
129137
}
130138

0 commit comments

Comments
 (0)