Blob Blame History Raw
From: Daniel Wagner <dwagner@suse.de>
Date: Wed, 8 Dec 2021 09:51:41 +0100
Subject: nvme-multipath: Skip not ready namespaces when revalidating paths
Patch-mainline: Never, upstream refactored the bug away
References: bsc#1191793 bsc#1192507 bsc#1192969

Revalidating paths can happen at any time which races with creating
and initializing new namespaces (nvme_alloc_ns()). This can lead to
the situation that the new namespace has been added to the sibling
list (nvme_init_ns_head()) but the ns->disk pointer has not been
assigned while we start iterating over the sibling list in
nvme_mpath_revalidate_paths().

The initial idea check if list_empty(&ns->list) is not possible
because when the namespace object is destroyed, the ns->disk is reset
to NULL bevore it will be removed from the controler namespace list.

Thus just check if the ns->disk pointer is valid when iterating over
the sibling list.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 drivers/nvme/host/multipath.c |    2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -192,6 +192,8 @@ void nvme_mpath_revalidate_paths(struct
 
 	srcu_idx = srcu_read_lock(&head->srcu);
 	list_for_each_entry_rcu(ns, &head->list, siblings) {
+		if (!ns->disk)
+			continue;
 		if (capacity != get_capacity(ns->disk))
 			clear_bit(NVME_NS_READY, &ns->flags);
 	}