@@ -153,9 +153,9 @@ static int uverbs_destroy_uobject(struct ib_uobject *uobj,
153
153
uobj -> context = NULL ;
154
154
155
155
/*
156
- * For DESTROY the usecnt is held write locked , the caller is expected
157
- * to put it unlock and put the object when done with it. Only DESTROY
158
- * can remove the IDR handle.
156
+ * For DESTROY the usecnt is not changed , the caller is expected to
157
+ * manage it via uobj_put_destroy(). Only DESTROY can remove the IDR
158
+ * handle.
159
159
*/
160
160
if (reason != RDMA_REMOVE_DESTROY )
161
161
atomic_set (& uobj -> usecnt , 0 );
@@ -187,7 +187,7 @@ static int uverbs_destroy_uobject(struct ib_uobject *uobj,
187
187
/*
188
188
* This calls uverbs_destroy_uobject() using the RDMA_REMOVE_DESTROY
189
189
* sequence. It should only be used from command callbacks. On success the
190
- * caller must pair this with rdma_lookup_put_uobject(LOOKUP_WRITE ). This
190
+ * caller must pair this with uobj_put_destroy( ). This
191
191
* version requires the caller to have already obtained an
192
192
* LOOKUP_DESTROY uobject kref.
193
193
*/
@@ -198,6 +198,13 @@ int uobj_destroy(struct ib_uobject *uobj, struct uverbs_attr_bundle *attrs)
198
198
199
199
down_read (& ufile -> hw_destroy_rwsem );
200
200
201
+ /*
202
+ * Once the uobject is destroyed by RDMA_REMOVE_DESTROY then it is left
203
+ * write locked as the callers put it back with UVERBS_LOOKUP_DESTROY.
204
+ * This is because any other concurrent thread can still see the object
205
+ * in the xarray due to RCU. Leaving it locked ensures nothing else will
206
+ * touch it.
207
+ */
201
208
ret = uverbs_try_lock_object (uobj , UVERBS_LOOKUP_WRITE );
202
209
if (ret )
203
210
goto out_unlock ;
@@ -216,7 +223,7 @@ int uobj_destroy(struct ib_uobject *uobj, struct uverbs_attr_bundle *attrs)
216
223
/*
217
224
* uobj_get_destroy destroys the HW object and returns a handle to the uobj
218
225
* with a NULL object pointer. The caller must pair this with
219
- * uverbs_put_destroy .
226
+ * uobj_put_destroy() .
220
227
*/
221
228
struct ib_uobject * __uobj_get_destroy (const struct uverbs_api_object * obj ,
222
229
u32 id , struct uverbs_attr_bundle * attrs )
@@ -250,8 +257,7 @@ int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id,
250
257
uobj = __uobj_get_destroy (obj , id , attrs );
251
258
if (IS_ERR (uobj ))
252
259
return PTR_ERR (uobj );
253
-
254
- rdma_lookup_put_uobject (uobj , UVERBS_LOOKUP_WRITE );
260
+ uobj_put_destroy (uobj );
255
261
return 0 ;
256
262
}
257
263
0 commit comments