Skip to content

Commit 70f06b2

Browse files
srabinovjgunthorpe
authored andcommitted
IB: ucontext should be set properly for all cmd & ioctl paths
the Attempt to use the below commit to initialize the ucontext for the uobject destroy path has shown that the below commit is incomplete. Parts were reverted and the ucontext set up in the uverbs_attr_bundle was moved to rdma_lookup_get_uobject which is called from the uobj_get_XXX macros and rdma_alloc_begin_uobject which is called when uobject is created. Fixes: 3d9dfd0 ("IB/uverbs: Add ib_ucontext to uverbs_attr_bundle sent from ioctl and cmd flows") Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent fae7a69 commit 70f06b2

6 files changed

Lines changed: 44 additions & 81 deletions

File tree

‎drivers/infiniband/core/rdma_core.c‎

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,13 @@ int uobj_destroy(struct ib_uobject *uobj)
224224
* uverbs_put_destroy.
225225
*/
226226
struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj,
227-
u32 id,
228-
const struct uverbs_attr_bundle *attrs)
227+
u32 id, struct uverbs_attr_bundle *attrs)
229228
{
230229
struct ib_uobject *uobj;
231230
int ret;
232231

233232
uobj = rdma_lookup_get_uobject(obj, attrs->ufile, id,
234-
UVERBS_LOOKUP_DESTROY);
233+
UVERBS_LOOKUP_DESTROY, attrs);
235234
if (IS_ERR(uobj))
236235
return uobj;
237236

@@ -249,7 +248,7 @@ struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj,
249248
* (negative errno on failure). For use by callers that do not need the uobj.
250249
*/
251250
int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id,
252-
const struct uverbs_attr_bundle *attrs)
251+
struct uverbs_attr_bundle *attrs)
253252
{
254253
struct ib_uobject *uobj;
255254

@@ -393,7 +392,8 @@ lookup_get_fd_uobject(const struct uverbs_api_object *obj,
393392

394393
struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
395394
struct ib_uverbs_file *ufile, s64 id,
396-
enum rdma_lookup_mode mode)
395+
enum rdma_lookup_mode mode,
396+
struct uverbs_attr_bundle *attrs)
397397
{
398398
struct ib_uobject *uobj;
399399
int ret;
@@ -431,45 +431,15 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
431431
ret = uverbs_try_lock_object(uobj, mode);
432432
if (ret)
433433
goto free;
434+
if (attrs)
435+
attrs->context = uobj->context;
434436

435437
return uobj;
436438
free:
437439
uobj->uapi_object->type_class->lookup_put(uobj, mode);
438440
uverbs_uobject_put(uobj);
439441
return ERR_PTR(ret);
440442
}
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-
}
473443

474444
static struct ib_uobject *
475445
alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
@@ -526,7 +496,8 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
526496
}
527497

528498
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
529-
struct ib_uverbs_file *ufile)
499+
struct ib_uverbs_file *ufile,
500+
struct uverbs_attr_bundle *attrs)
530501
{
531502
struct ib_uobject *ret;
532503

@@ -546,6 +517,8 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
546517
up_read(&ufile->hw_destroy_rwsem);
547518
return ret;
548519
}
520+
if (attrs)
521+
attrs->context = ret->context;
549522
return ret;
550523
}
551524

@@ -967,26 +940,25 @@ const struct uverbs_obj_type_class uverbs_fd_class = {
967940
EXPORT_SYMBOL(uverbs_fd_class);
968941

969942
struct ib_uobject *
970-
uverbs_get_uobject_from_file(u16 object_id,
971-
struct ib_uverbs_file *ufile,
972-
enum uverbs_obj_access access, s64 id)
943+
uverbs_get_uobject_from_file(u16 object_id, enum uverbs_obj_access access,
944+
s64 id, struct uverbs_attr_bundle *attrs)
973945
{
974946
const struct uverbs_api_object *obj =
975-
uapi_get_object(ufile->device->uapi, object_id);
947+
uapi_get_object(attrs->ufile->device->uapi, object_id);
976948

977949
switch (access) {
978950
case UVERBS_ACCESS_READ:
979-
return rdma_lookup_get_uobject(obj, ufile, id,
980-
UVERBS_LOOKUP_READ);
951+
return rdma_lookup_get_uobject(obj, attrs->ufile, id,
952+
UVERBS_LOOKUP_READ, attrs);
981953
case UVERBS_ACCESS_DESTROY:
982954
/* Actual destruction is done inside uverbs_handle_method */
983-
return rdma_lookup_get_uobject(obj, ufile, id,
984-
UVERBS_LOOKUP_DESTROY);
955+
return rdma_lookup_get_uobject(obj, attrs->ufile, id,
956+
UVERBS_LOOKUP_DESTROY, attrs);
985957
case UVERBS_ACCESS_WRITE:
986-
return rdma_lookup_get_uobject(obj, ufile, id,
987-
UVERBS_LOOKUP_WRITE);
958+
return rdma_lookup_get_uobject(obj, attrs->ufile, id,
959+
UVERBS_LOOKUP_WRITE, attrs);
988960
case UVERBS_ACCESS_NEW:
989-
return rdma_alloc_begin_uobject(obj, ufile);
961+
return rdma_alloc_begin_uobject(obj, attrs->ufile, attrs);
990962
default:
991963
WARN_ON(true);
992964
return ERR_PTR(-EOPNOTSUPP);

‎drivers/infiniband/core/rdma_core.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ void uverbs_close_fd(struct file *f);
8383
* uverbs_finalize_objects are called.
8484
*/
8585
struct ib_uobject *
86-
uverbs_get_uobject_from_file(u16 object_id,
87-
struct ib_uverbs_file *ufile,
88-
enum uverbs_obj_access access, s64 id);
86+
uverbs_get_uobject_from_file(u16 object_id, enum uverbs_obj_access access,
87+
s64 id, struct uverbs_attr_bundle *attrs);
8988

9089
/*
9190
* Note that certain finalize stages could return a status:

‎drivers/infiniband/core/uverbs_cmd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int uverbs_request_finish(struct uverbs_req_iter *iter)
175175
}
176176

177177
static struct ib_uverbs_completion_event_file *
178-
_ib_uverbs_lookup_comp_file(s32 fd, const struct uverbs_attr_bundle *attrs)
178+
_ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs)
179179
{
180180
struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL,
181181
fd, attrs);

‎drivers/infiniband/core/uverbs_ioctl.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,12 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
207207

208208
for (i = 0; i != array_len; i++) {
209209
attr->uobjects[i] = uverbs_get_uobject_from_file(
210-
spec->u2.objs_arr.obj_type, pbundle->bundle.ufile,
211-
spec->u2.objs_arr.access, idr_vals[i]);
210+
spec->u2.objs_arr.obj_type, spec->u2.objs_arr.access,
211+
idr_vals[i], &pbundle->bundle);
212212
if (IS_ERR(attr->uobjects[i])) {
213213
ret = PTR_ERR(attr->uobjects[i]);
214214
break;
215215
}
216-
pbundle->bundle.context = attr->uobjects[i]->context;
217216
}
218217

219218
attr->len = i;
@@ -325,13 +324,10 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
325324
* IDR implementation today rejects negative IDs
326325
*/
327326
o_attr->uobject = uverbs_get_uobject_from_file(
328-
spec->u.obj.obj_type,
329-
pbundle->bundle.ufile,
330-
spec->u.obj.access,
331-
uattr->data_s64);
327+
spec->u.obj.obj_type, spec->u.obj.access,
328+
uattr->data_s64, &pbundle->bundle);
332329
if (IS_ERR(o_attr->uobject))
333330
return PTR_ERR(o_attr->uobject);
334-
pbundle->bundle.context = o_attr->uobject->context;
335331
__set_bit(attr_bkey, pbundle->uobj_finalize);
336332

337333
if (spec->u.obj.access == UVERBS_ACCESS_NEW) {

‎include/rdma/uverbs_std_types.h‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,15 @@
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-
5551
#define uobj_get_read(_type, _id, _attrs) \
56-
_uobj_get_read(_type, _uobj_check_id(_id), _attrs)
52+
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
53+
_uobj_check_id(_id), UVERBS_LOOKUP_READ, \
54+
_attrs)
5755

5856
#define ufd_get_read(_type, _fdnum, _attrs) \
5957
rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \
6058
(_fdnum)*typecheck(s32, _fdnum), \
61-
UVERBS_LOOKUP_READ)
59+
UVERBS_LOOKUP_READ, _attrs)
6260

6361
static inline void *_uobj_get_obj_read(struct ib_uobject *uobj)
6462
{
@@ -70,22 +68,19 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj)
7068
((struct ib_##_object *)_uobj_get_obj_read( \
7169
uobj_get_read(_type, _id, _attrs)))
7270

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

8076
int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id,
81-
const struct uverbs_attr_bundle *attrs);
77+
struct uverbs_attr_bundle *attrs);
8278
#define uobj_perform_destroy(_type, _id, _attrs) \
8379
__uobj_perform_destroy(uobj_get_type(_attrs, _type), \
8480
_uobj_check_id(_id), _attrs)
8581

8682
struct ib_uobject *__uobj_get_destroy(const struct uverbs_api_object *obj,
87-
u32 id,
88-
const struct uverbs_attr_bundle *attrs);
83+
u32 id, struct uverbs_attr_bundle *attrs);
8984

9085
#define uobj_get_destroy(_type, _id, _attrs) \
9186
__uobj_get_destroy(uobj_get_type(_attrs, _type), _uobj_check_id(_id), \
@@ -127,12 +122,11 @@ static inline struct ib_uobject *
127122
__uobj_alloc(const struct uverbs_api_object *obj,
128123
struct uverbs_attr_bundle *attrs, struct ib_device **ib_dev)
129124
{
130-
struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, attrs->ufile);
125+
struct ib_uobject *uobj =
126+
rdma_alloc_begin_uobject(obj, attrs->ufile, attrs);
131127

132-
if (!IS_ERR(uobj)) {
128+
if (!IS_ERR(uobj))
133129
*ib_dev = uobj->context->device;
134-
attrs->context = uobj->context;
135-
}
136130
return uobj;
137131
}
138132

‎include/rdma/uverbs_types.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ struct uverbs_obj_idr_type {
131131

132132
struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
133133
struct ib_uverbs_file *ufile, s64 id,
134-
enum rdma_lookup_mode mode);
134+
enum rdma_lookup_mode mode,
135+
struct uverbs_attr_bundle *attrs);
135136
void rdma_lookup_put_uobject(struct ib_uobject *uobj,
136137
enum rdma_lookup_mode mode);
137138
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
138-
struct ib_uverbs_file *ufile);
139+
struct ib_uverbs_file *ufile,
140+
struct uverbs_attr_bundle *attrs);
139141
void rdma_alloc_abort_uobject(struct ib_uobject *uobj);
140142
int __must_check rdma_alloc_commit_uobject(struct ib_uobject *uobj);
141143

0 commit comments

Comments
 (0)