[PATCH v2] nvme: check duplicate unique identifiers in order
John Meneghini
jmeneghi at redhat.com
Wed Oct 1 00:00:36 PDT 2025
The identifier check in nvme_subsys_check_duplicate_ids currently
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, a NGUIDs but common
EUI64).
Rather than enforcing a policy that requires all identifiers reported by
the nvme device to be unique we return success if we find at least one
unique identifier. We zero out any non-unque identifier we find before
returning, thus preventing non-unque identifiers from being reported in
sysfs.
This allows nvme device that return multiple non-unque identifiers to
work as long as one or more unique identifier is reported by the device.
Signed-off-by: John Meneghini <jmeneghi at redhat.com>
Reviewed-by: Maurizio Lombardi <mlombard at redhat.com>
---
drivers/nvme/host/core.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index edfe7a267a4b..8e7d1ca349e6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3797,18 +3797,35 @@ 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)) {
+ memset(&ids->uuid, 0, sizeof(ids->uuid));
+ has_uuid = false;
+ }
}
- return 0;
+ if (has_nguid) {
+ list_for_each_entry(h, &subsys->nsheads, entry)
+ if (memcmp(&ids->nguid,
+ &h->ids.nguid,
+ sizeof(ids->nguid)) == 0) {
+ memset(ids->nguid, 0, sizeof(ids->nguid));
+ has_nguid = false;
+ }
+ }
+
+ if (has_eui64) {
+ list_for_each_entry(h, &subsys->nsheads, entry)
+ if (memcmp(&ids->eui64,
+ &h->ids.eui64,
+ sizeof(ids->eui64)) == 0) {
+ memset(ids->eui64, 0, sizeof(ids->eui64));
+ has_eui64 = false;
+ }
+ }
+
+ return (has_uuid || has_nguid || has_eui64) ? 0 : -EINVAL;
}
static void nvme_cdev_rel(struct device *dev)
--
2.51.0
More information about the Linux-nvme
mailing list