public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] nvme: check duplicate unique identifiers in order
@ 2025-05-09 15:16 Bryan Gurney
  2025-05-09 15:33 ` Keith Busch
  0 siblings, 1 reply; 11+ messages in thread
From: Bryan Gurney @ 2025-05-09 15:16 UTC (permalink / raw)
  To: bgurney, linux-nvme, kbusch, hch, sagi, axboe; +Cc: jmeneghi, mlombard

The identifier check in nvme_subsys_check_duplicate_ids returns an error
if any of the identifiers match; however, this causes problems with
PCI-Express NVMe devices that may otherwise have unique identifiers of
higher precedent (for example, unique NGUIDs, but common EUI64s).

Check for duplicate IDs in order of precedence in the NVMe standard:
UUID, then NGUID, then EUI64, in a way that ensures the highest
priority identifer that exists for the namespace will be checked for
uniquness.  If a lower-priority identifier exists and is non-unique, the
higher priority identifier will be unique, and should be used as the
identifier for the namespace.

Suggested-by: John Meneghini <jmeneghi@redhat.com>

Reviewed-by: John Meneghini <jmeneghi@redhat.com>
Signed-off-by: Bryan Gurney <bgurney@redhat.com>
---
 drivers/nvme/host/core.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index eb6ea8acb3cc..49ca29c64ca9 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3577,15 +3577,29 @@ static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys,
 
 	lockdep_assert_held(&subsys->lock);
 
-	list_for_each_entry(h, &subsys->nsheads, entry) {
-		if (has_uuid && uuid_equal(&ids->uuid, &h->ids.uuid))
-			return -EINVAL;
-		if (has_nguid &&
-		    memcmp(&ids->nguid, &h->ids.nguid, sizeof(ids->nguid)) == 0)
-			return -EINVAL;
-		if (has_eui64 &&
-		    memcmp(&ids->eui64, &h->ids.eui64, sizeof(ids->eui64)) == 0)
-			return -EINVAL;
+	if (has_uuid) {
+		list_for_each_entry(h, &subsys->nsheads, entry)
+			if (uuid_equal(&ids->uuid, &h->ids.uuid))
+				return -EINVAL;
+		return 0;
+	}
+
+	if (has_nguid) {
+		list_for_each_entry(h, &subsys->nsheads, entry)
+			if (memcmp(&ids->nguid,
+				   &h->ids.nguid,
+				   sizeof(ids->nguid)) == 0)
+				return -EINVAL;
+		return 0;
+	}
+
+	if (has_eui64) {
+		list_for_each_entry(h, &subsys->nsheads, entry)
+			if (memcmp(&ids->eui64,
+				   &h->ids.eui64,
+				   sizeof(ids->eui64)) == 0)
+				return -EINVAL;
+		return 0;
 	}
 
 	return 0;
-- 
2.49.0



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

end of thread, other threads:[~2025-09-16 19:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-09 15:16 [PATCH 1/2] nvme: check duplicate unique identifiers in order Bryan Gurney
2025-05-09 15:33 ` Keith Busch
2025-05-12 15:18   ` John Meneghini
2025-05-12 16:12     ` Keith Busch
2025-06-24 15:16       ` Keith Busch
2025-07-15 19:01         ` John Meneghini
2025-07-15 19:29           ` Keith Busch
2025-07-22  7:00             ` Hannes Reinecke
2025-07-22 11:58               ` Martin K. Petersen
2025-09-12 20:32                 ` John Meneghini
2025-09-16 19:04                   ` Martin K. Petersen

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