Skip to content

Commit d9dc7a3

Browse files
committed
IB/uverbs: Hold the uobj write lock after allocate
This clarifies the design intention that time between allocate and commit has the uobj exclusive to the caller. We already guarantee this by delaying publishing the uobj pointer via idr_insert, fd_install, list_add, etc. Additionally holding the usecnt lock during this period provides extra clarity and more protection against future mistakes. Fixes: 3832125 ("IB/core: Add support for idr types") Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4d39a95 commit d9dc7a3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/infiniband/core/rdma_core.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
141141
*/
142142
uobj->context = context;
143143
uobj->type = type;
144-
atomic_set(&uobj->usecnt, 0);
144+
/*
145+
* Allocated objects start out as write locked to deny any other
146+
* syscalls from accessing them until they are committed. See
147+
* rdma_alloc_commit_uobject
148+
*/
149+
atomic_set(&uobj->usecnt, -1);
145150
kref_init(&uobj->ref);
146151

147152
return uobj;
@@ -527,6 +532,10 @@ int rdma_alloc_commit_uobject(struct ib_uobject *uobj)
527532
return ret;
528533
}
529534

535+
/* matches atomic_set(-1) in alloc_uobj */
536+
lockdep_check(uobj, true);
537+
atomic_set(&uobj->usecnt, 0);
538+
530539
uobj->type->type_class->alloc_commit(uobj);
531540
up_read(&uobj->context->cleanup_rwsem);
532541

0 commit comments

Comments
 (0)