[RFC PATCH] nvme-multipath: break endless loop in nvme_round_robin_path

Chris Leech cleech at redhat.com
Mon Mar 21 15:43:03 PDT 2022


This is a backstop for the odd loop construct in nvme_round_robin_path.
It counts how many times the head pointer has been passed, as that's the
only thing guarenteed to stay on the list.  Once is needed to start from
a different place and check the entire list, twice is excessive looping.
---
 drivers/nvme/host/multipath.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index ff775235534c..c2039746ca15 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -261,12 +261,13 @@ static struct nvme_ns *__nvme_find_path(struct nvme_ns_head *head, int node)
 }
 
 static struct nvme_ns *nvme_next_ns(struct nvme_ns_head *head,
-		struct nvme_ns *ns)
+		struct nvme_ns *ns, int *head_pass_count)
 {
 	ns = list_next_or_null_rcu(&head->list, &ns->siblings, struct nvme_ns,
 			siblings);
 	if (ns)
 		return ns;
+	*head_pass_count++;
 	return list_first_or_null_rcu(&head->list, struct nvme_ns, siblings);
 }
 
@@ -274,6 +275,7 @@ static struct nvme_ns *nvme_round_robin_path(struct nvme_ns_head *head,
 		int node, struct nvme_ns *old)
 {
 	struct nvme_ns *ns, *found = NULL;
+	int head_pass_count = 0;
 
 	if (list_is_singular(&head->list)) {
 		if (nvme_path_is_disabled(old))
@@ -281,9 +283,12 @@ static struct nvme_ns *nvme_round_robin_path(struct nvme_ns_head *head,
 		return old;
 	}
 
-	for (ns = nvme_next_ns(head, old);
+	for (ns = nvme_next_ns(head, old, &head_pass_count);
 	     ns && ns != old;
-	     ns = nvme_next_ns(head, ns)) {
+	     ns = nvme_next_ns(head, ns, &head_pass_count)) {
+		if (head_pass_count > 1)
+			break;
+
 		if (nvme_path_is_disabled(ns))
 			continue;
 
-- 
2.35.1




More information about the Linux-nvme mailing list