]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0010-nvme-don-t-reject-probe-due-to-duplicate-IDs-for-sin.patch
rebase patches on top of Ubuntu-6.2.0-32.32
[pve-kernel.git] / patches / kernel / 0010-nvme-don-t-reject-probe-due-to-duplicate-IDs-for-sin.patch
CommitLineData
069e83e4
TL
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Christoph Hellwig <hch@lst.de>
3Date: Thu, 13 Jul 2023 15:30:42 +0200
4Subject: [PATCH] nvme: don't reject probe due to duplicate IDs for
5 single-ported PCIe devices
6
7While duplicate IDs are still very harmful, including the potential to easily
8see changing devices in /dev/disk/by-id, it turn out they are extremely
9common for cheap end user NVMe devices.
10
11Relax our check for them for so that it doesn't reject the probe on
12single-ported PCIe devices, but prints a big warning instead. In doubt
13we'd still like to see quirk entries to disable the potential for
14changing supposed stable device identifier links, but this will at least
15allow users how have two (or more) of these devices to use them without
16having to manually add a new PCI ID entry with the quirk through sysfs or
17by patching the kernel.
18
19Fixes: 2079f41ec6ff ("nvme: check that EUI/GUID/UUID are globally unique")
20Cc: stable@vger.kernel.org # 6.0+
21Co-developed-by: Sagi Grimberg <sagi@grimberg.me>
22Signed-off-by: Christoph Hellwig <hch@lst.de>
23Signed-off-by: Keith Busch <kbusch@kernel.org>
24Signed-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
29diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
30index 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);