Linux-NVME Archive mirror
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: hch@lst.de, kbusch@kernel.org, sagi@grimberg.me,
	gjoyce@linux.ibm.com, axboe@fb.com,
	Nilay Shroff <nilay@linux.ibm.com>
Subject: [PATCH] nvme: find numa distance only if controller has valid numa id
Date: Sat, 13 Apr 2024 14:34:36 +0530	[thread overview]
Message-ID: <20240413090614.678353-1-nilay@linux.ibm.com> (raw)

On numa aware system where native nvme multipath is configured and 
iopolicy is set to numa but the nvme controller numa node id is 
undefined or -1 (NUMA_NO_NODE) then avoid calculating node distance 
for finding optimal io path. In such case we may access numa distance
table with invalid index and that may potentially refer to incorrect
memory. So this patch ensures that if the nvme controller numa node
id is -1 then instead of calculating node distance for finding optimal
io path, we set the numa node distance of such controller to default 10
(LOCAL_DISTANCE).

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
 drivers/nvme/host/multipath.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 5397fb428b24..4c73a8038978 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -240,17 +240,19 @@ static bool nvme_path_is_disabled(struct nvme_ns *ns)
 
 static struct nvme_ns *__nvme_find_path(struct nvme_ns_head *head, int node)
 {
-	int found_distance = INT_MAX, fallback_distance = INT_MAX, distance;
+	int found_distance = INT_MAX, fallback_distance = INT_MAX;
 	struct nvme_ns *found = NULL, *fallback = NULL, *ns;
 
 	list_for_each_entry_rcu(ns, &head->list, siblings) {
+		int distance = LOCAL_DISTANCE;
+
 		if (nvme_path_is_disabled(ns))
 			continue;
 
-		if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_NUMA)
-			distance = node_distance(node, ns->ctrl->numa_node);
-		else
-			distance = LOCAL_DISTANCE;
+		if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_NUMA) {
+			if (ns->ctrl->numa_node != NUMA_NO_NODE)
+				distance = node_distance(node, ns->ctrl->numa_node);
+		}
 
 		switch (ns->ana_state) {
 		case NVME_ANA_OPTIMIZED:
-- 
2.44.0



             reply	other threads:[~2024-04-13  9:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-13  9:04 Nilay Shroff [this message]
2024-04-14  8:30 ` [PATCH] nvme: find numa distance only if controller has valid numa id Sagi Grimberg
2024-04-14 11:02   ` Nilay Shroff
2024-04-15  8:55     ` Sagi Grimberg
2024-04-15  9:30       ` Nilay Shroff
2024-04-15 10:04         ` Sagi Grimberg
2024-04-15 14:39         ` Hannes Reinecke
2024-04-15 16:56           ` Keith Busch
2024-04-16  8:06           ` Nilay Shroff
2024-04-15  7:25 ` Christoph Hellwig
2024-04-15  7:54   ` Nilay Shroff

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=20240413090614.678353-1-nilay@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=axboe@fb.com \
    --cc=gjoyce@linux.ibm.com \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).