netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yishai Hadas <yishaih@mellanox.com>
To: linux-rdma@vger.kernel.org, jgg@mellanox.com, dledford@redhat.com
Cc: saeedm@mellanox.com, yishaih@mellanox.com, maorg@mellanox.com,
	michaelgur@mellanox.com, netdev@vger.kernel.org
Subject: [PATCH rdma-next 03/10] RDMA/core: Remove ucontext_lock from the uverbs_destry_ufile_hw() path
Date: Wed,  8 Jan 2020 20:05:33 +0200	[thread overview]
Message-ID: <1578506740-22188-4-git-send-email-yishaih@mellanox.com> (raw)
In-Reply-To: <1578506740-22188-1-git-send-email-yishaih@mellanox.com>

From: Jason Gunthorpe <jgg@mellanox.com>

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.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
---
 drivers/infiniband/core/rdma_core.c  | 21 +--------------------
 drivers/infiniband/core/uverbs_cmd.c |  5 ++++-
 2 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index f839b93..58af6a7 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -863,9 +863,7 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile,
 }
 
 /*
- * Destroy the uncontext and every uobject associated with it. If called with
- * reason != RDMA_REMOVE_CLOSE this will not return until the destruction has
- * been completed and ufile->ucontext is NULL.
+ * Destroy the uncontext and every uobject associated with it.
  *
  * This is internally locked and can be called in parallel from multiple
  * contexts.
@@ -873,22 +871,6 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile,
 void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
 			     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);
 
 	/*
@@ -917,7 +899,6 @@ void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
 
 done:
 	up_write(&ufile->hw_destroy_rwsem);
-	mutex_unlock(&ufile->ucontext_lock);
 }
 
 const struct uverbs_obj_type_class uverbs_fd_class = {
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 29b1b5a..d71ffe4 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -218,6 +218,8 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
 	if (ret)
 		return ret;
 
+	if (!down_read_trylock(&file->hw_destroy_rwsem))
+		return -EIO;
 	mutex_lock(&file->ucontext_lock);
 	ib_dev = srcu_dereference(file->device->ib_dev,
 				  &file->device->disassociate_srcu);
@@ -284,7 +286,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
 	smp_store_release(&file->ucontext, ucontext);
 
 	mutex_unlock(&file->ucontext_lock);
-
+	up_read(&file->hw_destroy_rwsem);
 	return 0;
 
 err_uobj:
@@ -298,6 +300,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
 
 err:
 	mutex_unlock(&file->ucontext_lock);
+	up_read(&file->hw_destroy_rwsem);
 	return ret;
 }
 
-- 
1.8.3.1


  parent reply	other threads:[~2020-01-08 18:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-08 18:05 [PATCH rdma-next 00/10] Relaxed ordering memory regions Yishai Hadas
2020-01-08 18:05 ` [PATCH rdma-next 01/10] net/mlx5: Expose relaxed ordering bits Yishai Hadas
2020-01-08 18:05 ` [PATCH rdma-next 02/10] RDMA/core: Add UVERBS_METHOD_ASYNC_EVENT_ALLOC Yishai Hadas
2020-01-08 18:05 ` Yishai Hadas [this message]
2020-01-08 18:05 ` [PATCH rdma-next 04/10] RDMA/uverbs: Add ioctl command to get a device context Yishai Hadas
2020-01-08 18:05 ` [PATCH rdma-next 05/10] RDMA/uverbs: Verify MR access flags Yishai Hadas
2020-01-08 18:05 ` [PATCH rdma-next 06/10] RDMA/core: Add optional access flags range Yishai Hadas
2020-01-08 18:05 ` [PATCH rdma-next 07/10] RDMA/efa: Allow passing of optional access flags for MR registration Yishai Hadas
2020-01-21 16:37   ` Gal Pressman
2020-01-21 16:57     ` Yishai Hadas
2020-01-22  7:51       ` Gal Pressman
2020-01-08 18:05 ` [PATCH rdma-next 08/10] RDMA/uverbs: Add new relaxed ordering memory region access flag Yishai Hadas
2020-01-09  9:38   ` Sergei Shtylyov
2020-01-15 18:05   ` Jason Gunthorpe
2020-01-08 18:05 ` [PATCH rdma-next 09/10] RDMA/core: Add the core support field to METHOD_GET_CONTEXT Yishai Hadas
2020-01-08 18:05 ` [PATCH rdma-next 10/10] RDMA/mlx5: Set relaxed ordering when requested Yishai Hadas
2020-01-15 18:08 ` [PATCH rdma-next 00/10] Relaxed ordering memory regions Jason Gunthorpe
2020-01-16  9:20   ` Leon Romanovsky
2020-01-16 20:11     ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1578506740-22188-4-git-send-email-yishaih@mellanox.com \
    --to=yishaih@mellanox.com \
    --cc=dledford@redhat.com \
    --cc=jgg@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maorg@mellanox.com \
    --cc=michaelgur@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).