Skip to content

Commit 6ef1c82

Browse files
committed
IB/uverbs: Replace ib_ucontext with ib_uverbs_file in core function calls
The correct handle to refer to the idr/etc is ib_uverbs_file, revise all the core APIs to use this instead. The user API are left as wrappers that automatically convert a ucontext to a ufile for now. Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
1 parent 6a5e9c8 commit 6ef1c82

6 files changed

Lines changed: 62 additions & 68 deletions

File tree

‎drivers/infiniband/core/rdma_core.c‎

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int __uobj_perform_destroy(const struct uverbs_obj_type *type, int id,
139139
struct ib_uobject *uobj;
140140
int ret;
141141

142-
uobj = rdma_lookup_get_uobject(type, ufile->ucontext, id, true);
142+
uobj = rdma_lookup_get_uobject(type, ufile, id, true);
143143
if (IS_ERR(uobj))
144144
return PTR_ERR(uobj);
145145

@@ -150,7 +150,7 @@ int __uobj_perform_destroy(const struct uverbs_obj_type *type, int id,
150150
return success_res;
151151
}
152152

153-
static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
153+
static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile,
154154
const struct uverbs_obj_type *type)
155155
{
156156
struct ib_uobject *uobj = kzalloc(type->obj_size, GFP_KERNEL);
@@ -161,8 +161,8 @@ static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
161161
* user_handle should be filled by the handler,
162162
* The object is added to the list in the commit stage.
163163
*/
164-
uobj->ufile = context->ufile;
165-
uobj->context = context;
164+
uobj->ufile = ufile;
165+
uobj->context = ufile->ucontext;
166166
uobj->type = type;
167167
/*
168168
* Allocated objects start out as write locked to deny any other
@@ -210,15 +210,15 @@ static void uverbs_idr_remove_uobj(struct ib_uobject *uobj)
210210
}
211211

212212
/* Returns the ib_uobject or an error. The caller should check for IS_ERR. */
213-
static struct ib_uobject *lookup_get_idr_uobject(const struct uverbs_obj_type *type,
214-
struct ib_ucontext *ucontext,
215-
int id, bool exclusive)
213+
static struct ib_uobject *
214+
lookup_get_idr_uobject(const struct uverbs_obj_type *type,
215+
struct ib_uverbs_file *ufile, int id, bool exclusive)
216216
{
217217
struct ib_uobject *uobj;
218218

219219
rcu_read_lock();
220220
/* object won't be released as we're protected in rcu */
221-
uobj = idr_find(&ucontext->ufile->idr, id);
221+
uobj = idr_find(&ufile->idr, id);
222222
if (!uobj) {
223223
uobj = ERR_PTR(-ENOENT);
224224
goto free;
@@ -239,7 +239,7 @@ static struct ib_uobject *lookup_get_idr_uobject(const struct uverbs_obj_type *t
239239
}
240240

241241
static struct ib_uobject *lookup_get_fd_uobject(const struct uverbs_obj_type *type,
242-
struct ib_ucontext *ucontext,
242+
struct ib_uverbs_file *ufile,
243243
int id, bool exclusive)
244244
{
245245
struct file *f;
@@ -270,13 +270,13 @@ static struct ib_uobject *lookup_get_fd_uobject(const struct uverbs_obj_type *ty
270270
}
271271

272272
struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
273-
struct ib_ucontext *ucontext,
274-
int id, bool exclusive)
273+
struct ib_uverbs_file *ufile, int id,
274+
bool exclusive)
275275
{
276276
struct ib_uobject *uobj;
277277
int ret;
278278

279-
uobj = type->type_class->lookup_get(type, ucontext, id, exclusive);
279+
uobj = type->type_class->lookup_get(type, ufile, id, exclusive);
280280
if (IS_ERR(uobj))
281281
return uobj;
282282

@@ -300,20 +300,20 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
300300
}
301301

302302
static struct ib_uobject *alloc_begin_idr_uobject(const struct uverbs_obj_type *type,
303-
struct ib_ucontext *ucontext)
303+
struct ib_uverbs_file *ufile)
304304
{
305305
int ret;
306306
struct ib_uobject *uobj;
307307

308-
uobj = alloc_uobj(ucontext, type);
308+
uobj = alloc_uobj(ufile, type);
309309
if (IS_ERR(uobj))
310310
return uobj;
311311

312312
ret = idr_add_uobj(uobj);
313313
if (ret)
314314
goto uobj_put;
315315

316-
ret = ib_rdmacg_try_charge(&uobj->cg_obj, ucontext->device,
316+
ret = ib_rdmacg_try_charge(&uobj->cg_obj, ufile->ucontext->device,
317317
RDMACG_RESOURCE_HCA_OBJECT);
318318
if (ret)
319319
goto idr_remove;
@@ -328,7 +328,7 @@ static struct ib_uobject *alloc_begin_idr_uobject(const struct uverbs_obj_type *
328328
}
329329

330330
static struct ib_uobject *alloc_begin_fd_uobject(const struct uverbs_obj_type *type,
331-
struct ib_ucontext *ucontext)
331+
struct ib_uverbs_file *ufile)
332332
{
333333
const struct uverbs_obj_fd_type *fd_type =
334334
container_of(type, struct uverbs_obj_fd_type, type);
@@ -341,7 +341,7 @@ static struct ib_uobject *alloc_begin_fd_uobject(const struct uverbs_obj_type *t
341341
if (new_fd < 0)
342342
return ERR_PTR(new_fd);
343343

344-
uobj = alloc_uobj(ucontext, type);
344+
uobj = alloc_uobj(ufile, type);
345345
if (IS_ERR(uobj)) {
346346
put_unused_fd(new_fd);
347347
return uobj;
@@ -360,17 +360,17 @@ static struct ib_uobject *alloc_begin_fd_uobject(const struct uverbs_obj_type *t
360360

361361
uobj_file->uobj.id = new_fd;
362362
uobj_file->uobj.object = filp;
363-
uobj_file->ufile = ucontext->ufile;
363+
uobj_file->ufile = ufile;
364364
INIT_LIST_HEAD(&uobj->list);
365365
kref_get(&uobj_file->ufile->ref);
366366

367367
return uobj;
368368
}
369369

370370
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_obj_type *type,
371-
struct ib_ucontext *ucontext)
371+
struct ib_uverbs_file *ufile)
372372
{
373-
return type->type_class->alloc_begin(type, ucontext);
373+
return type->type_class->alloc_begin(type, ufile);
374374
}
375375

376376
static int __must_check remove_commit_idr_uobject(struct ib_uobject *uobj,
@@ -669,10 +669,9 @@ void uverbs_close_fd(struct file *f)
669669
kref_put(uverbs_file_ref, ib_uverbs_release_file);
670670
}
671671

672-
static int __uverbs_cleanup_ucontext(struct ib_ucontext *ucontext,
673-
enum rdma_remove_reason reason)
672+
static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile,
673+
enum rdma_remove_reason reason)
674674
{
675-
struct ib_uverbs_file *ufile = ucontext->ufile;
676675
struct ib_uobject *obj, *next_obj;
677676
int ret = -EINVAL;
678677
int err = 0;
@@ -716,12 +715,11 @@ static int __uverbs_cleanup_ucontext(struct ib_ucontext *ucontext,
716715
return ret;
717716
}
718717

719-
void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed)
718+
void uverbs_cleanup_ufile(struct ib_uverbs_file *ufile, bool device_removed)
720719
{
721720
enum rdma_remove_reason reason = device_removed ?
722721
RDMA_REMOVE_DRIVER_REMOVE :
723722
RDMA_REMOVE_CLOSE;
724-
struct ib_uverbs_file *ufile = ucontext->ufile;
725723

726724
/*
727725
* Waits for all remove_commit and alloc_commit to finish. Logically, We
@@ -731,7 +729,7 @@ void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed)
731729
down_write(&ufile->cleanup_rwsem);
732730
ufile->ucontext->cleanup_retryable = true;
733731
while (!list_empty(&ufile->uobjects))
734-
if (__uverbs_cleanup_ucontext(ucontext, reason)) {
732+
if (__uverbs_cleanup_ufile(ufile, reason)) {
735733
/*
736734
* No entry was cleaned-up successfully during this
737735
* iteration
@@ -741,7 +739,7 @@ void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed)
741739

742740
ufile->ucontext->cleanup_retryable = false;
743741
if (!list_empty(&ufile->uobjects))
744-
__uverbs_cleanup_ucontext(ucontext, reason);
742+
__uverbs_cleanup_ufile(ufile, reason);
745743

746744
up_write(&ufile->cleanup_rwsem);
747745
}
@@ -757,19 +755,19 @@ const struct uverbs_obj_type_class uverbs_fd_class = {
757755
};
758756
EXPORT_SYMBOL(uverbs_fd_class);
759757

760-
struct ib_uobject *uverbs_get_uobject_from_context(const struct uverbs_obj_type *type_attrs,
761-
struct ib_ucontext *ucontext,
762-
enum uverbs_obj_access access,
763-
int id)
758+
struct ib_uobject *
759+
uverbs_get_uobject_from_file(const struct uverbs_obj_type *type_attrs,
760+
struct ib_uverbs_file *ufile,
761+
enum uverbs_obj_access access, int id)
764762
{
765763
switch (access) {
766764
case UVERBS_ACCESS_READ:
767-
return rdma_lookup_get_uobject(type_attrs, ucontext, id, false);
765+
return rdma_lookup_get_uobject(type_attrs, ufile, id, false);
768766
case UVERBS_ACCESS_DESTROY:
769767
case UVERBS_ACCESS_WRITE:
770-
return rdma_lookup_get_uobject(type_attrs, ucontext, id, true);
768+
return rdma_lookup_get_uobject(type_attrs, ufile, id, true);
771769
case UVERBS_ACCESS_NEW:
772-
return rdma_alloc_begin_uobject(type_attrs, ucontext);
770+
return rdma_alloc_begin_uobject(type_attrs, ufile);
773771
default:
774772
WARN_ON(true);
775773
return ERR_PTR(-EOPNOTSUPP);

‎drivers/infiniband/core/rdma_core.h‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,8 @@ const struct uverbs_object_spec *uverbs_get_object(struct ib_uverbs_file *ufile,
4848
uint16_t object);
4949
const struct uverbs_method_spec *uverbs_get_method(const struct uverbs_object_spec *object,
5050
uint16_t method);
51-
/*
52-
* These functions initialize the context and cleanups its uobjects.
53-
* The context has a list of objects which is protected by a mutex
54-
* on the context. initialize_ucontext should be called when we create
55-
* a context.
56-
* cleanup_ucontext removes all uobjects from the context and puts them.
57-
*/
58-
void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed);
51+
52+
void uverbs_cleanup_ufile(struct ib_uverbs_file *ufile, bool device_removed);
5953

6054
/*
6155
* uverbs_uobject_get is called in order to increase the reference count on
@@ -81,18 +75,19 @@ void uverbs_uobject_put(struct ib_uobject *uobject);
8175
void uverbs_close_fd(struct file *f);
8276

8377
/*
84-
* Get an ib_uobject that corresponds to the given id from ucontext, assuming
78+
* Get an ib_uobject that corresponds to the given id from ufile, assuming
8579
* the object is from the given type. Lock it to the required access when
8680
* applicable.
8781
* This function could create (access == NEW), destroy (access == DESTROY)
8882
* or unlock (access == READ || access == WRITE) objects if required.
8983
* The action will be finalized only when uverbs_finalize_object or
9084
* uverbs_finalize_objects are called.
9185
*/
92-
struct ib_uobject *uverbs_get_uobject_from_context(const struct uverbs_obj_type *type_attrs,
93-
struct ib_ucontext *ucontext,
94-
enum uverbs_obj_access access,
95-
int id);
86+
struct ib_uobject *
87+
uverbs_get_uobject_from_file(const struct uverbs_obj_type *type_attrs,
88+
struct ib_uverbs_file *ufile,
89+
enum uverbs_obj_access access, int id);
90+
9691
/*
9792
* Note that certain finalize stages could return a status:
9893
* (a) alloc_commit could return a failure if the object is committed at the

‎drivers/infiniband/core/uverbs_ioctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ static int uverbs_process_attr(struct ib_uverbs_file *ufile,
152152
if (!object)
153153
return -EINVAL;
154154

155-
o_attr->uobject = uverbs_get_uobject_from_context(
155+
o_attr->uobject = uverbs_get_uobject_from_file(
156156
object->type_attrs,
157-
ufile->ucontext,
157+
ufile,
158158
spec->u.obj.access,
159159
(int)uattr->data);
160160

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,13 @@ void ib_uverbs_detach_umcast(struct ib_qp *qp,
227227
}
228228
}
229229

230-
static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
231-
struct ib_ucontext *context,
232-
bool device_removed)
230+
static int ib_uverbs_cleanup_ufile(struct ib_uverbs_file *file,
231+
bool device_removed)
233232
{
233+
struct ib_ucontext *context = file->ucontext;
234+
234235
context->closing = 1;
235-
uverbs_cleanup_ucontext(context, device_removed);
236+
uverbs_cleanup_ufile(file, device_removed);
236237
put_pid(context->tgid);
237238

238239
ib_rdmacg_uncharge(&context->cg_obj, context->device,
@@ -918,7 +919,7 @@ static int ib_uverbs_close(struct inode *inode, struct file *filp)
918919

919920
mutex_lock(&file->cleanup_mutex);
920921
if (file->ucontext) {
921-
ib_uverbs_cleanup_ucontext(file, file->ucontext, false);
922+
ib_uverbs_cleanup_ufile(file, false);
922923
file->ucontext = NULL;
923924
}
924925
mutex_unlock(&file->cleanup_mutex);
@@ -1176,7 +1177,7 @@ static void ib_uverbs_free_hw_resources(struct ib_uverbs_device *uverbs_dev,
11761177
mutex_unlock(&file->cleanup_mutex);
11771178

11781179
/* At this point ib_uverbs_close cannot be running
1179-
* ib_uverbs_cleanup_ucontext
1180+
* ib_uverbs_cleanup_ufile
11801181
*/
11811182
if (ucontext) {
11821183
/* We must release the mutex before going ahead and
@@ -1188,7 +1189,7 @@ static void ib_uverbs_free_hw_resources(struct ib_uverbs_device *uverbs_dev,
11881189
ib_uverbs_event_handler(&file->event_handler, &event);
11891190
ib_uverbs_disassociate_ucontext(ucontext);
11901191
mutex_lock(&file->cleanup_mutex);
1191-
ib_uverbs_cleanup_ucontext(file, ucontext, true);
1192+
ib_uverbs_cleanup_ufile(file, true);
11921193
mutex_unlock(&file->cleanup_mutex);
11931194
}
11941195

‎include/rdma/uverbs_std_types.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,28 @@ static inline const struct uverbs_object_tree_def *uverbs_default_get_objects(vo
4848

4949
static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type,
5050
bool write,
51-
struct ib_ucontext *ucontext,
51+
struct ib_uverbs_file *ufile,
5252
int id)
5353
{
54-
return rdma_lookup_get_uobject(type, ucontext, id, write);
54+
return rdma_lookup_get_uobject(type, ufile, id, write);
5555
}
5656

5757
#define uobj_get_type(_object) UVERBS_OBJECT(_object).type_attrs
5858

59-
#define uobj_get_read(_type, _id, _ucontext) \
60-
__uobj_get(uobj_get_type(_type), false, _ucontext, _id)
59+
#define uobj_get_read(_type, _id, _ucontext) \
60+
__uobj_get(uobj_get_type(_type), false, (_ucontext)->ufile, _id)
6161

6262
#define uobj_get_obj_read(_object, _type, _id, _ucontext) \
6363
({ \
6464
struct ib_uobject *__uobj = \
6565
__uobj_get(uobj_get_type(_type), \
66-
false, _ucontext, _id); \
66+
false, (_ucontext)->ufile, _id); \
6767
\
6868
(struct ib_##_object *)(IS_ERR(__uobj) ? NULL : __uobj->object);\
6969
})
7070

71-
#define uobj_get_write(_type, _id, _ucontext) \
72-
__uobj_get(uobj_get_type(_type), true, _ucontext, _id)
71+
#define uobj_get_write(_type, _id, _ucontext) \
72+
__uobj_get(uobj_get_type(_type), true, (_ucontext)->ufile, _id)
7373

7474
int __uobj_perform_destroy(const struct uverbs_obj_type *type, int id,
7575
struct ib_uverbs_file *ufile, int success_res);
@@ -107,7 +107,7 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj)
107107
static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type,
108108
struct ib_ucontext *ucontext)
109109
{
110-
return rdma_alloc_begin_uobject(type, ucontext);
110+
return rdma_alloc_begin_uobject(type, ucontext->ufile);
111111
}
112112

113113
#define uobj_alloc(_type, ucontext) \

‎include/rdma/uverbs_types.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ struct uverbs_obj_type_class {
7272
* reset flow).
7373
*/
7474
struct ib_uobject *(*alloc_begin)(const struct uverbs_obj_type *type,
75-
struct ib_ucontext *ucontext);
75+
struct ib_uverbs_file *ufile);
7676
void (*alloc_commit)(struct ib_uobject *uobj);
7777
void (*alloc_abort)(struct ib_uobject *uobj);
7878

7979
struct ib_uobject *(*lookup_get)(const struct uverbs_obj_type *type,
80-
struct ib_ucontext *ucontext, int id,
80+
struct ib_uverbs_file *ufile, int id,
8181
bool exclusive);
8282
void (*lookup_put)(struct ib_uobject *uobj, bool exclusive);
8383
/*
@@ -120,11 +120,11 @@ struct uverbs_obj_idr_type {
120120
};
121121

122122
struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
123-
struct ib_ucontext *ucontext,
123+
struct ib_uverbs_file *ufile,
124124
int id, bool exclusive);
125125
void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive);
126126
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_obj_type *type,
127-
struct ib_ucontext *ucontext);
127+
struct ib_uverbs_file *ufile);
128128
void rdma_alloc_abort_uobject(struct ib_uobject *uobj);
129129
int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj);
130130
int rdma_alloc_commit_uobject(struct ib_uobject *uobj);

0 commit comments

Comments
 (0)