From: keith.busch@intel.com (Keith Busch)
Subject: [PATCH-4.5-v3 2/5] NVMe: Fix namespace removal deadlock
Date: Wed, 17 Feb 2016 11:36:52 -0700 [thread overview]
Message-ID: <1455734215-20396-3-git-send-email-keith.busch@intel.com> (raw)
In-Reply-To: <1455734215-20396-1-git-send-email-keith.busch@intel.com>
This patch makes nvme namespace removal lockless. It is up to the caller
to ensure no active namespace scanning is occuring.
The lockless removal allows the driver to cleanup a namespace
request_queue if the controller fails during removal. Previously this
could deadlock trying to acquire the namespace mutex in order to handle
such events.
Signed-off-by: Keith Busch <keith.busch at intel.com>
---
drivers/nvme/host/core.c | 15 +++++++++------
drivers/nvme/host/nvme.h | 4 ++++
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 3cd921e..1b7387d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -48,6 +48,10 @@ static void nvme_free_ns(struct kref *kref)
{
struct nvme_ns *ns = container_of(kref, struct nvme_ns, kref);
+ mutex_lock(&ns->ctrl->namespaces_mutex);
+ list_del_init(&ns->list);
+ mutex_unlock(&ns->ctrl->namespaces_mutex);
+
if (ns->type == NVME_NS_LIGHTNVM)
nvme_nvm_unregister(ns->queue, ns->disk->disk_name);
@@ -1179,11 +1183,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
static void nvme_ns_remove(struct nvme_ns *ns)
{
- bool kill = nvme_io_incapable(ns->ctrl) &&
- !blk_queue_dying(ns->queue);
+ bool kill;
- lockdep_assert_held(&ns->ctrl->namespaces_mutex);
+ if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
+ return;
+ kill = nvme_io_incapable(ns->ctrl) &&
+ !blk_queue_dying(ns->queue);
if (kill) {
blk_set_queue_dying(ns->queue);
@@ -1206,7 +1212,6 @@ static void nvme_ns_remove(struct nvme_ns *ns)
blk_mq_abort_requeue_list(ns->queue);
blk_cleanup_queue(ns->queue);
}
- list_del_init(&ns->list);
nvme_put_ns(ns);
}
@@ -1300,10 +1305,8 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl)
{
struct nvme_ns *ns, *next;
- mutex_lock(&ctrl->namespaces_mutex);
list_for_each_entry_safe(ns, next, &ctrl->namespaces, list)
nvme_ns_remove(ns);
- mutex_unlock(&ctrl->namespaces_mutex);
}
static DEFINE_IDA(nvme_instance_ida);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 9664d07..db413a7 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -112,6 +112,10 @@ struct nvme_ns {
bool ext;
u8 pi_type;
int type;
+ unsigned long flags;
+
+#define NVME_NS_REMOVING 0
+
u64 mode_select_num_blocks;
u32 mode_select_block_len;
};
--
2.6.2.307.g37023ba
next prev parent reply other threads:[~2016-02-17 18:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 18:36 [PATCH-4.5-v3 0/5] NVMe hot plug stuff Keith Busch
2016-02-17 18:36 ` [PATCH-4.5-v3 1/5] NVMe: Add controller removing state Keith Busch
2016-02-18 4:09 ` Christoph Hellwig
2016-02-18 9:37 ` Johannes Thumshirn
2016-02-17 18:36 ` Keith Busch [this message]
2016-02-18 2:00 ` [PATCH-4.5-v3 2/5] NVMe: Fix namespace removal deadlock Wenbo Wang
2016-02-18 4:09 ` Christoph Hellwig
2016-02-18 16:26 ` Keith Busch
2016-02-18 9:39 ` Johannes Thumshirn
2016-02-21 16:17 ` Christoph Hellwig
2016-02-17 18:36 ` [PATCH-4.5-v3 3/5] NVMe: Simplify device reset failure Keith Busch
2016-02-17 18:36 ` [PATCH-4.5-v3 4/5] NVMe: Move error handling to failed reset handler Keith Busch
2016-02-18 4:11 ` Christoph Hellwig
2016-02-18 19:38 ` Keith Busch
2016-02-18 9:42 ` Johannes Thumshirn
2016-02-17 18:36 ` [PATCH-4.5-v3 5/5] NVMe: Don't unmap controller registers on reset Keith Busch
2016-02-18 9:45 ` Johannes Thumshirn
2016-02-21 16:15 ` Christoph Hellwig
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=1455734215-20396-3-git-send-email-keith.busch@intel.com \
--to=keith.busch@intel.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).