Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 RFC] nvme: use nvme_set_queue_dying() during namespace rescanning
@ 2019-04-03 23:12 Hannes Reinecke
  2019-04-13  8:29 ` Ming Lei
  2019-04-24 16:30 ` Sagi Grimberg
  0 siblings, 2 replies; 7+ messages in thread
From: Hannes Reinecke @ 2019-04-03 23:12 UTC (permalink / raw)


From: Hannes Reinecke <hare@suse.com>

There is a race condition between namespace rescanning and controller
reset; during controller reset all namespaces are quiesed vie
nams_stop_ctrl(), and after reset all namespaces are unquiesced
again.
When namespace scanning was active by the time controller reset was
triggered the rescan code will call nvme_ns_remove(), which then will
cause a kernel crash in nvme_start_ctrl() as it'll trip over
uninitialized namespaces.

This patch calls nvme_set_queue_dying() during namespace rescan,
which will already unquiesce the queue. Hence we can skip all namespaces
with the 'DEAD' flag during unquiesce in nvme_start_ctrl() and eliminate
this issue.

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

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 23000a368e1f..21aa5c516d2a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3359,7 +3359,7 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	ns = nvme_find_get_ns(ctrl, nsid);
 	if (ns) {
 		if (ns->disk && revalidate_disk(ns->disk))
-			nvme_ns_remove(ns);
+			nvme_set_queue_dying(ns);
 		nvme_put_ns(ns);
 	} else
 		nvme_alloc_ns(ctrl, nsid);
@@ -3409,7 +3409,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
 			while (++prev < nsid) {
 				ns = nvme_find_get_ns(ctrl, prev);
 				if (ns) {
-					nvme_ns_remove(ns);
+					nvme_set_queue_dying(ns);
 					nvme_put_ns(ns);
 				}
 			}
@@ -3871,8 +3871,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_DEAD, &ns->flags))
+			continue;
 		blk_mq_quiesce_queue(ns->queue);
+	}
 	up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_stop_queues);
@@ -3882,8 +3885,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_DEAD, &ns->flags))
+			continue;
 		blk_mq_unquiesce_queue(ns->queue);
+	}
 	up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_start_queues);
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-04-25  7:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-03 23:12 [PATCHv2 RFC] nvme: use nvme_set_queue_dying() during namespace rescanning Hannes Reinecke
2019-04-13  8:29 ` Ming Lei
2019-04-13  9:13   ` Ming Lei
2019-04-17 11:32   ` Hannes Reinecke
2019-04-17 12:49     ` Ming Lei
2019-04-24 16:30 ` Sagi Grimberg
2019-04-25  7:10   ` Hannes Reinecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox