Skip to content

Commit ac522fc

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
nvme: don't reject probe due to duplicate IDs for single-ported PCIe devices
While duplicate IDs are still very harmful, including the potential to easily see changing devices in /dev/disk/by-id, it turn out they are extremely common for cheap end user NVMe devices. Relax our check for them for so that it doesn't reject the probe on single-ported PCIe devices, but prints a big warning instead. In doubt we'd still like to see quirk entries to disable the potential for changing supposed stable device identifier links, but this will at least allow users how have two (or more) of these devices to use them without having to manually add a new PCI ID entry with the quirk through sysfs or by patching the kernel. Fixes: 2079f41 ("nvme: check that EUI/GUID/UUID are globally unique") Cc: stable@vger.kernel.org # 6.0+ Co-developed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 71a5bb1 commit ac522fc

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

drivers/nvme/host/core.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,10 +3431,40 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
34313431

34323432
ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids);
34333433
if (ret) {
3434-
dev_err(ctrl->device,
3435-
"globally duplicate IDs for nsid %d\n", info->nsid);
3434+
/*
3435+
* We've found two different namespaces on two different
3436+
* subsystems that report the same ID. This is pretty nasty
3437+
* for anything that actually requires unique device
3438+
* identification. In the kernel we need this for multipathing,
3439+
* and in user space the /dev/disk/by-id/ links rely on it.
3440+
*
3441+
* If the device also claims to be multi-path capable back off
3442+
* here now and refuse the probe the second device as this is a
3443+
* recipe for data corruption. If not this is probably a
3444+
* cheap consumer device if on the PCIe bus, so let the user
3445+
* proceed and use the shiny toy, but warn that with changing
3446+
* probing order (which due to our async probing could just be
3447+
* device taking longer to startup) the other device could show
3448+
* up at any time.
3449+
*/
34363450
nvme_print_device_info(ctrl);
3437-
return ret;
3451+
if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */
3452+
((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) &&
3453+
info->is_shared)) {
3454+
dev_err(ctrl->device,
3455+
"ignoring nsid %d because of duplicate IDs\n",
3456+
info->nsid);
3457+
return ret;
3458+
}
3459+
3460+
dev_err(ctrl->device,
3461+
"clearing duplicate IDs for nsid %d\n", info->nsid);
3462+
dev_err(ctrl->device,
3463+
"use of /dev/disk/by-id/ may cause data corruption\n");
3464+
memset(&info->ids.nguid, 0, sizeof(info->ids.nguid));
3465+
memset(&info->ids.uuid, 0, sizeof(info->ids.uuid));
3466+
memset(&info->ids.eui64, 0, sizeof(info->ids.eui64));
3467+
ctrl->quirks |= NVME_QUIRK_BOGUS_NID;
34383468
}
34393469

34403470
mutex_lock(&ctrl->subsys->lock);

0 commit comments

Comments
 (0)