All of lore.kernel.org
 help / color / mirror / Atom feed
From: hare@suse.de (Hannes Reinecke)
Subject: [PATCH 1/3] nvme: do not quiesce or unquiesce invalid namespaces
Date: Wed, 27 Mar 2019 09:09:27 +0100	[thread overview]
Message-ID: <20190327080929.27918-2-hare@suse.de> (raw)
In-Reply-To: <20190327080929.27918-1-hare@suse.de>

nvme_(start,stop)_queues() might race with namespace scanning.
As namespaces might be removed during scanning, but the removal
from the list is not atomic, those functions might trip
over namespaces which are partially deleted, causing really
interesting kernel crashes.
So validate the namespaces in nvme_(start,stop)_queues().

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 drivers/nvme/host/core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 470601980794..c583735383ca 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3857,8 +3857,11 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl)
 	struct nvme_ns *ns;
 
 	down_read(&ctrl->namespaces_rwsem);
-	list_for_each_entry(ns, &ctrl->namespaces, list)
+	list_for_each_entry(ns, &ctrl->namespaces, list) {
+		if (test_bit(NVME_NS_REMOVING, &ns->flags))
+			continue;
 		blk_mq_quiesce_queue(ns->queue);
+	}
 	up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_stop_queues);
@@ -3868,8 +3871,11 @@ void nvme_start_queues(struct nvme_ctrl *ctrl)
 	struct nvme_ns *ns;
 
 	down_read(&ctrl->namespaces_rwsem);
-	list_for_each_entry(ns, &ctrl->namespaces, list)
+	list_for_each_entry(ns, &ctrl->namespaces, list) {
+		if (test_bit(NVME_NS_REMOVING, &ns->flags))
+			continue;
 		blk_mq_unquiesce_queue(ns->queue);
+	}
 	up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_start_queues);
-- 
2.16.4

  reply	other threads:[~2019-03-27  8:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-27  8:09 [PATCH 0/3] nvme: fixup race with namespace removal Hannes Reinecke
2019-03-27  8:09 ` Hannes Reinecke [this message]
2019-03-27  8:09 ` [PATCH 2/3] nvme: shorten race window in nvme_ns_remove() Hannes Reinecke
2019-03-27 14:02   ` Christoph Hellwig
2019-03-27 14:41     ` Hannes Reinecke
2019-03-27 14:20   ` Keith Busch
2019-03-27 15:12     ` Hannes Reinecke
2019-03-27 18:50       ` James Smart
2019-03-28  9:27         ` Hannes Reinecke
2019-03-28 11:07           ` Ming Lei
2019-03-28 11:48             ` Hannes Reinecke
2019-03-28 12:11               ` Hannes Reinecke
2019-03-28 15:19                 ` Ming Lei
2019-03-28 15:56                   ` James Smart
2019-03-28 15:46                 ` James Smart
2019-03-28 15:57                   ` Hannes Reinecke
2019-03-28 17:50                     ` James Smart
2019-03-28 15:05           ` James Smart
2019-03-28 15:50             ` Hannes Reinecke
2019-03-29  0:40               ` Ming Lei
2019-03-27  8:09 ` [PATCH 3/3] nvme-multipath: test namespace state when selecting a new path Hannes Reinecke

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=20190327080929.27918-2-hare@suse.de \
    --to=hare@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.