Commit da57db25 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/core: Remove ucontext_lock from the uverbs_destry_ufile_hw() path

This lock only serializes ucontext creation. Instead of checking the
ucontext_lock during destruction hold the existing hw_destroy_rwsem during
creation, which is the standard pattern for object creation.

The simplification of locking is needed for the next patch.

Link: https://lore.kernel.org/r/1578506740-22188-4-git-send-email-yishaih@mellanox.comSigned-off-by: default avatarYishai Hadas <yishaih@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent d680e88e
...@@ -845,9 +845,7 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile, ...@@ -845,9 +845,7 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile,
} }
/* /*
* Destroy the uncontext and every uobject associated with it. If called with * Destroy the uncontext and every uobject associated with it.
* reason != RDMA_REMOVE_CLOSE this will not return until the destruction has
* been completed and ufile->ucontext is NULL.
* *
* This is internally locked and can be called in parallel from multiple * This is internally locked and can be called in parallel from multiple
* contexts. * contexts.
...@@ -855,22 +853,6 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile, ...@@ -855,22 +853,6 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile,
void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile, void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
enum rdma_remove_reason reason) enum rdma_remove_reason reason)
{ {
if (reason == RDMA_REMOVE_CLOSE) {
/*
* During destruction we might trigger something that
* synchronously calls release on any file descriptor. For
* this reason all paths that come from file_operations
* release must use try_lock. They can progress knowing that
* there is an ongoing uverbs_destroy_ufile_hw that will clean
* up the driver resources.
*/
if (!mutex_trylock(&ufile->ucontext_lock))
return;
} else {
mutex_lock(&ufile->ucontext_lock);
}
down_write(&ufile->hw_destroy_rwsem); down_write(&ufile->hw_destroy_rwsem);
/* /*
...@@ -899,7 +881,6 @@ void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile, ...@@ -899,7 +881,6 @@ void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
done: done:
up_write(&ufile->hw_destroy_rwsem); up_write(&ufile->hw_destroy_rwsem);
mutex_unlock(&ufile->ucontext_lock);
} }
const struct uverbs_obj_type_class uverbs_fd_class = { const struct uverbs_obj_type_class uverbs_fd_class = {
......
...@@ -218,6 +218,8 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) ...@@ -218,6 +218,8 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
if (ret) if (ret)
return ret; return ret;
if (!down_read_trylock(&file->hw_destroy_rwsem))
return -EIO;
mutex_lock(&file->ucontext_lock); mutex_lock(&file->ucontext_lock);
ib_dev = srcu_dereference(file->device->ib_dev, ib_dev = srcu_dereference(file->device->ib_dev,
&file->device->disassociate_srcu); &file->device->disassociate_srcu);
...@@ -284,7 +286,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) ...@@ -284,7 +286,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
smp_store_release(&file->ucontext, ucontext); smp_store_release(&file->ucontext, ucontext);
mutex_unlock(&file->ucontext_lock); mutex_unlock(&file->ucontext_lock);
up_read(&file->hw_destroy_rwsem);
return 0; return 0;
err_uobj: err_uobj:
...@@ -298,6 +300,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) ...@@ -298,6 +300,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
err: err:
mutex_unlock(&file->ucontext_lock); mutex_unlock(&file->ucontext_lock);
up_read(&file->hw_destroy_rwsem);
return ret; return ret;
} }
......
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