Commit f025c489 authored by Matan Barak's avatar Matan Barak Committed by Doug Ledford

IB/core: Don't pass the lock state to _rdma_remove_commit_uobject

The only scenario where this function was called while the lock is
already taken is in the context cleanup scenario. Thus, in order not
to pass the lock state to this function, we just call the remove logic
straight from the cleanup context function.

Fixes: 38321256 ('IB/core: Add support for idr types')
Signed-off-by: default avatarMatan Barak <matanb@mellanox.com>
Reviewed-by: default avatarSean Hefty <sean.hefty@intel.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 30004b86
...@@ -363,8 +363,7 @@ static void lockdep_check(struct ib_uobject *uobj, bool exclusive) ...@@ -363,8 +363,7 @@ static void lockdep_check(struct ib_uobject *uobj, bool exclusive)
} }
static int __must_check _rdma_remove_commit_uobject(struct ib_uobject *uobj, static int __must_check _rdma_remove_commit_uobject(struct ib_uobject *uobj,
enum rdma_remove_reason why, enum rdma_remove_reason why)
bool lock)
{ {
int ret; int ret;
struct ib_ucontext *ucontext = uobj->context; struct ib_ucontext *ucontext = uobj->context;
...@@ -375,11 +374,9 @@ static int __must_check _rdma_remove_commit_uobject(struct ib_uobject *uobj, ...@@ -375,11 +374,9 @@ static int __must_check _rdma_remove_commit_uobject(struct ib_uobject *uobj,
atomic_set(&uobj->usecnt, 0); atomic_set(&uobj->usecnt, 0);
uobj->type->type_class->lookup_put(uobj, true); uobj->type->type_class->lookup_put(uobj, true);
} else { } else {
if (lock) mutex_lock(&ucontext->uobjects_lock);
mutex_lock(&ucontext->uobjects_lock);
list_del(&uobj->list); list_del(&uobj->list);
if (lock) mutex_unlock(&ucontext->uobjects_lock);
mutex_unlock(&ucontext->uobjects_lock);
/* put the ref we took when we created the object */ /* put the ref we took when we created the object */
uverbs_uobject_put(uobj); uverbs_uobject_put(uobj);
} }
...@@ -401,7 +398,7 @@ int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj) ...@@ -401,7 +398,7 @@ int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj)
return 0; return 0;
} }
lockdep_check(uobj, true); lockdep_check(uobj, true);
ret = _rdma_remove_commit_uobject(uobj, RDMA_REMOVE_DESTROY, true); ret = _rdma_remove_commit_uobject(uobj, RDMA_REMOVE_DESTROY);
up_read(&ucontext->cleanup_rwsem); up_read(&ucontext->cleanup_rwsem);
return ret; return ret;
...@@ -534,8 +531,7 @@ static void _uverbs_close_fd(struct ib_uobject_file *uobj_file) ...@@ -534,8 +531,7 @@ static void _uverbs_close_fd(struct ib_uobject_file *uobj_file)
goto unlock; goto unlock;
ucontext = uobj_file->uobj.context; ucontext = uobj_file->uobj.context;
ret = _rdma_remove_commit_uobject(&uobj_file->uobj, RDMA_REMOVE_CLOSE, ret = _rdma_remove_commit_uobject(&uobj_file->uobj, RDMA_REMOVE_CLOSE);
true);
up_read(&ucontext->cleanup_rwsem); up_read(&ucontext->cleanup_rwsem);
if (ret) if (ret)
pr_warn("uverbs: unable to clean up uobject file in uverbs_close_fd.\n"); pr_warn("uverbs: unable to clean up uobject file in uverbs_close_fd.\n");
...@@ -583,7 +579,7 @@ void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed) ...@@ -583,7 +579,7 @@ void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed)
*/ */
mutex_lock(&ucontext->uobjects_lock); mutex_lock(&ucontext->uobjects_lock);
list_for_each_entry_safe(obj, next_obj, &ucontext->uobjects, list_for_each_entry_safe(obj, next_obj, &ucontext->uobjects,
list) list) {
if (obj->type->destroy_order == cur_order) { if (obj->type->destroy_order == cur_order) {
int ret; int ret;
...@@ -592,15 +588,19 @@ void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed) ...@@ -592,15 +588,19 @@ void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed)
* racing with a lookup_get. * racing with a lookup_get.
*/ */
WARN_ON(uverbs_try_lock_object(obj, true)); WARN_ON(uverbs_try_lock_object(obj, true));
ret = _rdma_remove_commit_uobject(obj, reason, ret = obj->type->type_class->remove_commit(obj,
false); reason);
list_del(&obj->list);
if (ret) if (ret)
pr_warn("ib_uverbs: failed to remove uobject id %d order %u\n", pr_warn("ib_uverbs: failed to remove uobject id %d order %u\n",
obj->id, cur_order); obj->id, cur_order);
/* put the ref we took when we created the object */
uverbs_uobject_put(obj);
} else { } else {
next_order = min(next_order, next_order = min(next_order,
obj->type->destroy_order); obj->type->destroy_order);
} }
}
mutex_unlock(&ucontext->uobjects_lock); mutex_unlock(&ucontext->uobjects_lock);
cur_order = next_order; cur_order = next_order;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment