@@ -160,9 +160,9 @@ static int uverbs_destroy_uobject(struct ib_uobject *uobj,
160
160
uobj -> context = NULL ;
161
161
162
162
/*
163
- * For DESTROY the usecnt is held write locked , the caller is expected
164
- * to put it unlock and put the object when done with it. Only DESTROY
165
- * can remove the IDR handle.
163
+ * For DESTROY the usecnt is not changed , the caller is expected to
164
+ * manage it via uobj_put_destroy(). Only DESTROY can remove the IDR
165
+ * handle.
166
166
*/
167
167
if (reason != RDMA_REMOVE_DESTROY )
168
168
atomic_set (& uobj -> usecnt , 0 );
@@ -194,7 +194,7 @@ static int uverbs_destroy_uobject(struct ib_uobject *uobj,
194
194
/*
195
195
* This calls uverbs_destroy_uobject() using the RDMA_REMOVE_DESTROY
196
196
* sequence. It should only be used from command callbacks. On success the
197
- * caller must pair this with rdma_lookup_put_uobject(LOOKUP_WRITE ). This
197
+ * caller must pair this with uobj_put_destroy( ). This
198
198
* version requires the caller to have already obtained an
199
199
* LOOKUP_DESTROY uobject kref.
200
200
*/
@@ -205,6 +205,13 @@ int uobj_destroy(struct ib_uobject *uobj, struct uverbs_attr_bundle *attrs)
205
205
206
206
down_read (& ufile -> hw_destroy_rwsem );
207
207
208
+ /*
209
+ * Once the uobject is destroyed by RDMA_REMOVE_DESTROY then it is left
210
+ * write locked as the callers put it back with UVERBS_LOOKUP_DESTROY.
211
+ * This is because any other concurrent thread can still see the object
212
+ * in the xarray due to RCU. Leaving it locked ensures nothing else will
213
+ * touch it.
214
+ */
208
215
ret = uverbs_try_lock_object (uobj , UVERBS_LOOKUP_WRITE );
209
216
if (ret )
210
217
goto out_unlock ;
@@ -223,7 +230,7 @@ int uobj_destroy(struct ib_uobject *uobj, struct uverbs_attr_bundle *attrs)
223
230
/*
224
231
* uobj_get_destroy destroys the HW object and returns a handle to the uobj
225
232
* with a NULL object pointer. The caller must pair this with
226
- * uverbs_put_destroy .
233
+ * uobj_put_destroy() .
227
234
*/
228
235
struct ib_uobject * __uobj_get_destroy (const struct uverbs_api_object * obj ,
229
236
u32 id , struct uverbs_attr_bundle * attrs )
@@ -257,8 +264,7 @@ int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id,
257
264
uobj = __uobj_get_destroy (obj , id , attrs );
258
265
if (IS_ERR (uobj ))
259
266
return PTR_ERR (uobj );
260
-
261
- rdma_lookup_put_uobject (uobj , UVERBS_LOOKUP_WRITE );
267
+ uobj_put_destroy (uobj );
262
268
return 0 ;
263
269
}
264
270
0 commit comments