Skip to content

Commit 30004b8

Browse files
matanb10dledford
authored andcommitted
IB/core: Rename write flag to exclusive in rdma_core
We rename the "write" flags to "exclusive", as it's used for both WRITE and DESTROY actions. Fixes: 3832125 ('IB/core: Add support for idr types') Signed-off-by: Matan Barak <matanb@mellanox.com> Reviewed-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent b58fc80 commit 30004b8

2 files changed

Lines changed: 48 additions & 45 deletions

File tree

‎drivers/infiniband/core/rdma_core.c‎

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void uverbs_uobject_get(struct ib_uobject *uobject)
4444
kref_get(&uobject->ref);
4545
}
4646

47-
static void uverbs_uobject_put_ref(struct kref *ref)
47+
static void uverbs_uobject_free(struct kref *ref)
4848
{
4949
struct ib_uobject *uobj =
5050
container_of(ref, struct ib_uobject, ref);
@@ -57,21 +57,23 @@ static void uverbs_uobject_put_ref(struct kref *ref)
5757

5858
void uverbs_uobject_put(struct ib_uobject *uobject)
5959
{
60-
kref_put(&uobject->ref, uverbs_uobject_put_ref);
60+
kref_put(&uobject->ref, uverbs_uobject_free);
6161
}
6262

63-
static int uverbs_try_lock_object(struct ib_uobject *uobj, bool write)
63+
static int uverbs_try_lock_object(struct ib_uobject *uobj, bool exclusive)
6464
{
6565
/*
66-
* When a read is required, we use a positive counter. Each read
67-
* request checks that the value != -1 and increment it. Write
68-
* requires an exclusive access, thus we check that the counter is
69-
* zero (nobody claimed this object) and we set it to -1.
70-
* Releasing a read lock is done by simply decreasing the counter.
71-
* As for writes, since only a single write is permitted, setting
72-
* it to zero is enough for releasing it.
66+
* When a shared access is required, we use a positive counter. Each
67+
* shared access request checks that the value != -1 and increment it.
68+
* Exclusive access is required for operations like write or destroy.
69+
* In exclusive access mode, we check that the counter is zero (nobody
70+
* claimed this object) and we set it to -1. Releasing a shared access
71+
* lock is done simply by decreasing the counter. As for exclusive
72+
* access locks, since only a single one of them is is allowed
73+
* concurrently, setting the counter to zero is enough for releasing
74+
* this lock.
7375
*/
74-
if (!write)
76+
if (!exclusive)
7577
return __atomic_add_unless(&uobj->usecnt, 1, -1) == -1 ?
7678
-EBUSY : 0;
7779

@@ -135,7 +137,7 @@ static void uverbs_idr_remove_uobj(struct ib_uobject *uobj)
135137
/* Returns the ib_uobject or an error. The caller should check for IS_ERR. */
136138
static struct ib_uobject *lookup_get_idr_uobject(const struct uverbs_obj_type *type,
137139
struct ib_ucontext *ucontext,
138-
int id, bool write)
140+
int id, bool exclusive)
139141
{
140142
struct ib_uobject *uobj;
141143

@@ -155,14 +157,14 @@ static struct ib_uobject *lookup_get_idr_uobject(const struct uverbs_obj_type *t
155157

156158
static struct ib_uobject *lookup_get_fd_uobject(const struct uverbs_obj_type *type,
157159
struct ib_ucontext *ucontext,
158-
int id, bool write)
160+
int id, bool exclusive)
159161
{
160162
struct file *f;
161163
struct ib_uobject *uobject;
162164
const struct uverbs_obj_fd_type *fd_type =
163165
container_of(type, struct uverbs_obj_fd_type, type);
164166

165-
if (write)
167+
if (exclusive)
166168
return ERR_PTR(-EOPNOTSUPP);
167169

168170
f = fget(id);
@@ -186,12 +188,12 @@ static struct ib_uobject *lookup_get_fd_uobject(const struct uverbs_obj_type *ty
186188

187189
struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
188190
struct ib_ucontext *ucontext,
189-
int id, bool write)
191+
int id, bool exclusive)
190192
{
191193
struct ib_uobject *uobj;
192194
int ret;
193195

194-
uobj = type->type_class->lookup_get(type, ucontext, id, write);
196+
uobj = type->type_class->lookup_get(type, ucontext, id, exclusive);
195197
if (IS_ERR(uobj))
196198
return uobj;
197199

@@ -200,7 +202,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
200202
goto free;
201203
}
202204

203-
ret = uverbs_try_lock_object(uobj, write);
205+
ret = uverbs_try_lock_object(uobj, exclusive);
204206
if (ret) {
205207
WARN(ucontext->cleanup_reason,
206208
"ib_uverbs: Trying to lookup_get while cleanup context\n");
@@ -209,7 +211,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
209211

210212
return uobj;
211213
free:
212-
uobj->type->type_class->lookup_put(uobj, write);
214+
uobj->type->type_class->lookup_put(uobj, exclusive);
213215
uverbs_uobject_put(uobj);
214216
return ERR_PTR(ret);
215217
}
@@ -350,10 +352,10 @@ static int __must_check remove_commit_fd_uobject(struct ib_uobject *uobj,
350352
return ret;
351353
}
352354

353-
static void lockdep_check(struct ib_uobject *uobj, bool write)
355+
static void lockdep_check(struct ib_uobject *uobj, bool exclusive)
354356
{
355357
#ifdef CONFIG_LOCKDEP
356-
if (write)
358+
if (exclusive)
357359
WARN_ON(atomic_read(&uobj->usecnt) > 0);
358360
else
359361
WARN_ON(atomic_read(&uobj->usecnt) == -1);
@@ -465,29 +467,29 @@ void rdma_alloc_abort_uobject(struct ib_uobject *uobj)
465467
uobj->type->type_class->alloc_abort(uobj);
466468
}
467469

468-
static void lookup_put_idr_uobject(struct ib_uobject *uobj, bool write)
470+
static void lookup_put_idr_uobject(struct ib_uobject *uobj, bool exclusive)
469471
{
470472
}
471473

472-
static void lookup_put_fd_uobject(struct ib_uobject *uobj, bool write)
474+
static void lookup_put_fd_uobject(struct ib_uobject *uobj, bool exclusive)
473475
{
474476
struct file *filp = uobj->object;
475477

476-
WARN_ON(write);
478+
WARN_ON(exclusive);
477479
/* This indirectly calls uverbs_close_fd and free the object */
478480
fput(filp);
479481
}
480482

481-
void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool write)
483+
void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive)
482484
{
483-
lockdep_check(uobj, write);
484-
uobj->type->type_class->lookup_put(uobj, write);
485+
lockdep_check(uobj, exclusive);
486+
uobj->type->type_class->lookup_put(uobj, exclusive);
485487
/*
486488
* In order to unlock an object, either decrease its usecnt for
487-
* read access or zero it in case of write access. See
489+
* read access or zero it in case of exclusive access. See
488490
* uverbs_try_lock_object for locking schema information.
489491
*/
490-
if (!write)
492+
if (!exclusive)
491493
atomic_dec(&uobj->usecnt);
492494
else
493495
atomic_set(&uobj->usecnt, 0);
@@ -512,7 +514,7 @@ const struct uverbs_obj_type_class uverbs_idr_class = {
512514
* When the other thread continue - without the RCU, it would
513515
* access freed memory. However, the rcu_read_lock delays the free
514516
* until the rcu_read_lock of the READ operation quits. Since the
515-
* write lock of the object is still taken by the DESTROY flow, the
517+
* exclusive lock of the object is still taken by the DESTROY flow, the
516518
* READ operation will get -EBUSY and it'll just bail out.
517519
*/
518520
.needs_kfree_rcu = true,

‎include/rdma/uverbs_types.h‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ struct uverbs_obj_type_class {
5454
* destroyed.
5555
* [lookup]: Starts with lookup_get which fetches and locks the
5656
* object. After the handler finished using the object, it
57-
* needs to call lookup_put to unlock it. The write flag
58-
* indicates if the object is locked for exclusive access.
59-
* [remove]: Starts with lookup_get with write flag set. This locks
60-
* the object for exclusive access. If the handler code
61-
* completed successfully, remove_commit is called and
62-
* the ib_uobject is removed from the context's uobjects
63-
* repository and put. The object itself is destroyed as
64-
* well. Once remove succeeds new krefs to the object
65-
* cannot be acquired by other threads or userspace and
66-
* the hardware driver is removed from the object.
67-
* Other krefs on the object may still exist.
57+
* needs to call lookup_put to unlock it. The exclusive
58+
* flag indicates if the object is locked for exclusive
59+
* access.
60+
* [remove]: Starts with lookup_get with exclusive flag set. This
61+
* locks the object for exclusive access. If the handler
62+
* code completed successfully, remove_commit is called
63+
* and the ib_uobject is removed from the context's
64+
* uobjects repository and put. The object itself is
65+
* destroyed as well. Once remove succeeds new krefs to
66+
* the object cannot be acquired by other threads or
67+
* userspace and the hardware driver is removed from the
68+
* object. Other krefs on the object may still exist.
6869
* If the handler code failed, lookup_put should be
6970
* called. This callback is used when the context
7071
* is destroyed as well (process termination,
@@ -77,10 +78,10 @@ struct uverbs_obj_type_class {
7778

7879
struct ib_uobject *(*lookup_get)(const struct uverbs_obj_type *type,
7980
struct ib_ucontext *ucontext, int id,
80-
bool write);
81-
void (*lookup_put)(struct ib_uobject *uobj, bool write);
81+
bool exclusive);
82+
void (*lookup_put)(struct ib_uobject *uobj, bool exclusive);
8283
/*
83-
* Must be called with the write lock held. If successful uobj is
84+
* Must be called with the exclusive lock held. If successful uobj is
8485
* invalid on return. On failure uobject is left completely
8586
* unchanged
8687
*/
@@ -121,8 +122,8 @@ struct uverbs_obj_idr_type {
121122

122123
struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
123124
struct ib_ucontext *ucontext,
124-
int id, bool write);
125-
void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool write);
125+
int id, bool exclusive);
126+
void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive);
126127
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_obj_type *type,
127128
struct ib_ucontext *ucontext);
128129
void rdma_alloc_abort_uobject(struct ib_uobject *uobj);

0 commit comments

Comments
 (0)