linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>, Keith Busch <kbusch@kernel.org>,
	linux-nvme@lists.infradead.org, Hannes Reinecke <hare@kernel.org>
Subject: [PATCH 3/3] nvme-multipath: stuck partition scan on inaccessible paths
Date: Wed, 11 Sep 2024 14:46:10 +0200	[thread overview]
Message-ID: <20240911124610.81615-4-hare@kernel.org> (raw)
In-Reply-To: <20240911124610.81615-1-hare@kernel.org>

When a path is switched to 'inaccessible' during partition scan
triggered via device_add_disk() and we only have one path the
system will be stuck as nvme_available_path() will always return
'true'. So I/O will never be completed and the system is stuck
in device_add_disk():

    [<0>] folio_wait_bit_common+0x12a/0x310
    [<0>] filemap_read_folio+0x97/0xd0
    [<0>] do_read_cache_folio+0x108/0x390
    [<0>] read_part_sector+0x31/0xa0
    [<0>] read_lba+0xc5/0x160
    [<0>] efi_partition+0xd9/0x8f0
    [<0>] bdev_disk_changed+0x23d/0x6d0
    [<0>] blkdev_get_whole+0x78/0xc0
    [<0>] bdev_open+0x2c6/0x3b0
    [<0>] bdev_file_open_by_dev+0xcb/0x120
    [<0>] disk_scan_partitions+0x5d/0x100
    [<0>] device_add_disk+0x402/0x420
    [<0>] nvme_mpath_set_live+0x4f/0x1f0 [nvme_core]
    [<0>] nvme_mpath_add_disk+0x107/0x120 [nvme_core]
    [<0>] nvme_alloc_ns+0xac6/0xe60 [nvme_core]
    [<0>] nvme_scan_ns+0x2dd/0x3e0 [nvme_core]
    [<0>] nvme_scan_work+0x1a3/0x490 [nvme_core]

This patch introduces a flag NVME_NSHEAD_FAIL_ON_LAST_PATH to
cause nvme_available_path() to always return NULL, and with
that I/O to be failed if the last path is unavailable. But
we also need to requeue all pending I/Os whenever we have
changed the ANA state as now even inaccessible ANA states
influence I/O behaviour.

Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
 drivers/nvme/host/multipath.c | 15 +++++++++++++++
 drivers/nvme/host/nvme.h      |  1 +
 2 files changed, 16 insertions(+)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index f72c5a6a2d8e..0373b4043eea 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -422,6 +422,10 @@ static bool nvme_available_path(struct nvme_ns_head *head)
 	struct nvme_ns *ns;
 
 	if (!test_bit(NVME_NSHEAD_DISK_LIVE, &head->flags))
+	    return NULL;
+
+	if (test_bit(NVME_NSHEAD_FAIL_ON_LAST_PATH, &head->flags) &&
+	    list_is_singular(&head->list))
 		return NULL;
 
 	list_for_each_entry_rcu(ns, &head->list, siblings) {
@@ -646,8 +650,15 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
 	 * head.
 	 */
 	if (!test_and_set_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
+		/*
+		 * Disable queueing to ensure I/O is not retried on unusable
+		 * paths, which would cause the system to be stuck during
+		 * partition scan.
+		 */
+		set_bit(NVME_NSHEAD_FAIL_ON_LAST_PATH, &head->flags);
 		rc = device_add_disk(&head->subsys->dev, head->disk,
 				     nvme_ns_attr_groups);
+		clear_bit(NVME_NSHEAD_FAIL_ON_LAST_PATH, &head->flags);
 		if (rc) {
 			clear_bit(NVME_NSHEAD_DISK_LIVE, &head->flags);
 			return;
@@ -737,6 +748,10 @@ static void nvme_update_ns_ana_state(struct nvme_ana_group_desc *desc,
 	if (nvme_state_is_live(ns->ana_state) &&
 	    nvme_ctrl_state(ns->ctrl) == NVME_CTRL_LIVE)
 		nvme_mpath_set_live(ns);
+	else {
+		synchronize_srcu(&ns->head->srcu);
+		kblockd_schedule_work(&ns->head->requeue_work);
+	}
 }
 
 static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 50515ad0f9d6..6aef38eba293 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -493,6 +493,7 @@ struct nvme_ns_head {
 	struct mutex		lock;
 	unsigned long		flags;
 #define NVME_NSHEAD_DISK_LIVE	0
+#define NVME_NSHEAD_FAIL_ON_LAST_PATH	1
 	struct nvme_ns __rcu	*current_path[];
 #endif
 };
-- 
2.35.3



  parent reply	other threads:[~2024-09-11 12:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 12:46 [PATCH 0/3] nvme: NSHEAD_DISK_LIVE fixes Hannes Reinecke
2024-09-11 12:46 ` [PATCH 1/3] nvme-multipath: fixup typo when clearing DISK_LIVE Hannes Reinecke
2024-09-12  9:37   ` Christoph Hellwig
2024-09-11 12:46 ` [PATCH 2/3] nvme-multipath: avoid hang on inaccessible namespaces Hannes Reinecke
2024-09-11 12:46 ` Hannes Reinecke [this message]
2024-09-11 15:20   ` [PATCH 3/3] nvme-multipath: stuck partition scan on inaccessible paths Sagi Grimberg
2024-09-11 16:10     ` Hannes Reinecke
2024-09-12 10:29       ` Sagi Grimberg
2024-09-12 14:30         ` 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=20240911124610.81615-4-hare@kernel.org \
    --to=hare@kernel.org \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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).