]>
Commit | Line | Data |
---|---|---|
069e83e4 TL |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Christoph Hellwig <hch@lst.de> | |
3 | Date: Thu, 13 Jul 2023 15:30:42 +0200 | |
4 | Subject: [PATCH] nvme: don't reject probe due to duplicate IDs for | |
5 | single-ported PCIe devices | |
6 | ||
7 | While duplicate IDs are still very harmful, including the potential to easily | |
8 | see changing devices in /dev/disk/by-id, it turn out they are extremely | |
9 | common for cheap end user NVMe devices. | |
10 | ||
11 | Relax our check for them for so that it doesn't reject the probe on | |
12 | single-ported PCIe devices, but prints a big warning instead. In doubt | |
13 | we'd still like to see quirk entries to disable the potential for | |
14 | changing supposed stable device identifier links, but this will at least | |
15 | allow users how have two (or more) of these devices to use them without | |
16 | having to manually add a new PCI ID entry with the quirk through sysfs or | |
17 | by patching the kernel. | |
18 | ||
19 | Fixes: 2079f41ec6ff ("nvme: check that EUI/GUID/UUID are globally unique") | |
20 | Cc: stable@vger.kernel.org # 6.0+ | |
21 | Co-developed-by: Sagi Grimberg <sagi@grimberg.me> | |
22 | Signed-off-by: Christoph Hellwig <hch@lst.de> | |
23 | Signed-off-by: Keith Busch <kbusch@kernel.org> | |
24 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> | |
25 | --- | |
26 | drivers/nvme/host/core.c | 36 +++++++++++++++++++++++++++++++++--- | |
27 | 1 file changed, 33 insertions(+), 3 deletions(-) | |
28 | ||
29 | diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c | |
30 | index d567762545b0..f350df252d27 100644 | |
31 | --- a/drivers/nvme/host/core.c | |
32 | +++ b/drivers/nvme/host/core.c | |
33 | @@ -4162,10 +4162,40 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) | |
34 | ||
35 | ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); | |
36 | if (ret) { | |
37 | - dev_err(ctrl->device, | |
38 | - "globally duplicate IDs for nsid %d\n", info->nsid); | |
39 | + /* | |
40 | + * We've found two different namespaces on two different | |
41 | + * subsystems that report the same ID. This is pretty nasty | |
42 | + * for anything that actually requires unique device | |
43 | + * identification. In the kernel we need this for multipathing, | |
44 | + * and in user space the /dev/disk/by-id/ links rely on it. | |
45 | + * | |
46 | + * If the device also claims to be multi-path capable back off | |
47 | + * here now and refuse the probe the second device as this is a | |
48 | + * recipe for data corruption. If not this is probably a | |
49 | + * cheap consumer device if on the PCIe bus, so let the user | |
50 | + * proceed and use the shiny toy, but warn that with changing | |
51 | + * probing order (which due to our async probing could just be | |
52 | + * device taking longer to startup) the other device could show | |
53 | + * up at any time. | |
54 | + */ | |
55 | nvme_print_device_info(ctrl); | |
56 | - return ret; | |
57 | + if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ | |
58 | + ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && | |
59 | + info->is_shared)) { | |
60 | + dev_err(ctrl->device, | |
61 | + "ignoring nsid %d because of duplicate IDs\n", | |
62 | + info->nsid); | |
63 | + return ret; | |
64 | + } | |
65 | + | |
66 | + dev_err(ctrl->device, | |
67 | + "clearing duplicate IDs for nsid %d\n", info->nsid); | |
68 | + dev_err(ctrl->device, | |
69 | + "use of /dev/disk/by-id/ may cause data corruption\n"); | |
70 | + memset(&info->ids.nguid, 0, sizeof(info->ids.nguid)); | |
71 | + memset(&info->ids.uuid, 0, sizeof(info->ids.uuid)); | |
72 | + memset(&info->ids.eui64, 0, sizeof(info->ids.eui64)); | |
73 | + ctrl->quirks |= NVME_QUIRK_BOGUS_NID; | |
74 | } | |
75 | ||
76 | mutex_lock(&ctrl->subsys->lock); |