@@ -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
5858void 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. */
136138static 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
156158static 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
187189struct 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 ;
211213free :
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,
0 commit comments