quirk broken namespace identifiers v2
Christoph Hellwig
maintainerHi all,
this series adds a quirk to ignore namespace identifiers on controllers where they are completely broken and then quirks two controllers for it.
Changes since v1:
- validate namespace descriptor sizes even if ignoring them
- also handle another MAXIO controller with the same problem
- fix up a few commit messages
Christoph Hellwig
maintainerPATCH 1/3 nvme: add a quirk to disable namespace identifiers
Add a quirk to disable using and exporting namespace identifiers for controllers where they are broken beyond repair.
The most directly visible problem with non-unique namespace identifiers is that they break the /dev/disk/by-id/ links, with the link for a supposedly unique identifier now pointing to one of multiple possible namespaces that share the same ID, and a somewhat random selection of which one actually shows up.
--- drivers/nvme/host/core.c | 24 ++++++++++++++++++------ drivers/nvme/host/nvme.h | 5 +++++ 2 files changed, 23 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +18 -6
@@ -1288,6 +1288,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, warn_str, cur->nidl);return -1 ; } +if (ctrl->quirks &NVME_QUIRK_BOGUS_NID ) +return NVME_NIDT_EUI64_LEN ;memcpy (ids->eui64, data +sizeof (*cur),NVME_NIDT_EUI64_LEN );return NVME_NIDT_EUI64_LEN ;case NVME_NIDT_NGUID :
@@ -1296,6 +1298,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, warn_str, cur->nidl);return -1 ; } +if (ctrl->quirks &NVME_QUIRK_BOGUS_NID ) +return NVME_NIDT_NGUID_LEN ;memcpy (ids->nguid, data +sizeof (*cur),NVME_NIDT_NGUID_LEN );return NVME_NIDT_NGUID_LEN ;case NVME_NIDT_UUID :
@@ -1304,6 +1308,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, warn_str, cur->nidl);return -1 ; } +if (ctrl->quirks &NVME_QUIRK_BOGUS_NID ) +return NVME_NIDT_UUID_LEN ;uuid_copy (&ids->uuid, data +sizeof (*cur));return NVME_NIDT_UUID_LEN ;case NVME_NIDT_CSI :
@@ -1400,12 +1406,18 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,if ((*id)->ncap ==0 )/* namespace not allocated or attached */ goto out_free_id; -if (ctrl->vs >=NVME_VS (1 ,1 ,0 ) && - !memchr_inv (ids->eui64,0 ,sizeof (ids->eui64))) -memcpy (ids->eui64, (*id)->eui64,sizeof (ids->eui64)); -if (ctrl->vs >=NVME_VS (1 ,2 ,0 ) && - !memchr_inv (ids->nguid,0 ,sizeof (ids->nguid))) -memcpy (ids->nguid, (*id)->nguid,sizeof (ids->nguid)); + +if (ctrl->quirks &NVME_QUIRK_BOGUS_NID ) { +dev_info (ctrl->device, +"Ignoring bogus Namespace Identifiers\n" ); + }else { +if (ctrl->vs >=NVME_VS (1 ,1 ,0 ) && + !memchr_inv (ids->eui64,0 ,sizeof (ids->eui64))) +memcpy (ids->eui64, (*id)->eui64,sizeof (ids->eui64)); +if (ctrl->vs >=NVME_VS (1 ,2 ,0 ) && + !memchr_inv (ids->nguid,0 ,sizeof (ids->nguid))) +memcpy (ids->nguid, (*id)->nguid,sizeof (ids->nguid)); + }return 0 ;
drivers/nvme/host/nvme.h +5 -0
@@ -144,6 +144,11 @@ enum nvme_quirks {* encoding the generation sequence number. */ NVME_QUIRK_SKIP_CID_GEN = (1 <<17 ), + +/* +* Reports garbage in the namespace identifiers (eui64, nguid, uuid). +*/ + NVME_QUIRK_BOGUS_NID = (1 << 18), };/*
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 2/3 nvme-pci: disable namespace identifiers for the MAXIO MAP1002/1202
In reply to Christoph HellwigThe MAXIO MAP1002/1202 controllers reports completely bogus Namespace identifiers that even change after suspend cycles. Disable using the Identifiers entirely.
--- drivers/nvme/host/pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvme/host/pci.c +4 -0
@@ -3447,6 +3447,10 @@ static const struct pci_device_id nvme_id_table[] = { .driver_data = NVME_QUIRK_NO_DEEPEST_PS, }, { PCI_DEVICE(0x2646, 0x2263), /* KINGSTON A2000 NVMe SSD */ .driver_data = NVME_QUIRK_NO_DEEPEST_PS, }, + { PCI_DEVICE(0x1e4B, 0x1002), /* MAXIO MAP1002 */ + .driver_data = NVME_QUIRK_BOGUS_NID, }, + { PCI_DEVICE(0x1e4B, 0x1202), /* MAXIO MAP1202 */ + .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(PCI_VENDOR_ID_AMAZON, 0x0061), .driver_data = NVME_QUIRK_DMA_ADDRESS_BITS_48, }, { PCI_DEVICE(PCI_VENDOR_ID_AMAZON, 0x0065),
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 3/3 nvme-pci: disable namespace identifiers for Qemu controllers
In reply to Christoph HellwigQemu unconditionally reports a UUID, which depending on the qemu version is either all-null (which is incorrect but harmless) or contains a single bit set for all controllers. In addition it can also optionally report a eui64 which needs to be manually set. Disable namespace identifiers for Qemu controlles entirely even if in some cases they could be set correctly through manual intervention.
--- drivers/nvme/host/pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/host/pci.c +2 -0
@@ -3410,6 +3410,8 @@ static const struct pci_device_id nvme_id_table[] = { { PCI_VDEVICE(INTEL, 0x5845), /* Qemu emulated controller */ .driver_data =NVME_QUIRK_IDENTIFY_CNS | NVME_QUIRK_DISABLE_WRITE_ZEROES, }, + { PCI_VDEVICE(REDHAT, 0x0010), /* Qemu emulated controller */ + .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x126f, 0x2263), /* Silicon Motion unidentified */ .driver_data = NVME_QUIRK_NO_NS_DESC_LIST, }, { PCI_DEVICE(0x1bb1, 0x0100), /* Seagate Nytro Flash Storage */
Signature · 1 line
2.30.2
Re: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 1 line · Christoph Hellwig
Qemu unconditionally reports a UUID, which depending on the qemu version
Since it appears that both older and current QEMU versions are not implementing this properly, perhaps you should also consider adding the pci vendor and device id used by older QEMU versions?
QEMU nvme pci vendor and device id was changed in commit:
https://github.com/qemu/qemu/commit/6eb7a071292a2f11065127ac152fa24248806021
Which was first included in QEMU v5.2.0.
Kind regards,
Niklas
Quoted 30 lines
is either all-null (which is incorrect but harmless) or contains a single bit set for all controllers. In addition it can also optionally report a eui64 which needs to be manually set. Disable namespace identifiers for Qemu controlles entirely even if in some cases they could be set correctly through manual intervention.
Reported-by Luis Chamberlain <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Sagi Grimberg <[email protected]>--- drivers/nvme/host/pci.c | 2 ++ 1 file changed, 2 insertions(+)drivers/nvme/host/pci.c +2
-0@@ -3410,6 +3410,8 @@ static const struct pci_device_id nvme_id_table[] = { { PCI_VDEVICE(INTEL, 0x5845), /* Qemu emulated controller */ .driver_data =NVME_QUIRK_IDENTIFY_CNS | NVME_QUIRK_DISABLE_WRITE_ZEROES, }, + { PCI_VDEVICE(REDHAT, 0x0010), /* Qemu emulated controller */ + .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x126f, 0x2263), /* Silicon Motion unidentified */ .driver_data = NVME_QUIRK_NO_NS_DESC_LIST, }, { PCI_DEVICE(0x1bb1, 0x0100), /* Seagate Nytro Flash Storage */Signature · 1 line
2.30.2
Re: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 12 lines · Niklas Cassel
Quoted 1 line · Christoph Hellwig
Qemu unconditionally reports a UUID, which depending on the qemu version
Since it appears that both older and current QEMU versions are not implementing this properly, perhaps you should also consider adding the pci vendor and device id used by older QEMU versions?
QEMU nvme pci vendor and device id was changed in commit:
https://github.com/qemu/qemu/commit/6eb7a071292a2f11065127ac152fa24248806021Which was first included in QEMU v5.2.0.
That is a good point Niklas. +1 for that. The driver already knows about that ID.
Christoph Hellwig
maintainerRe: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 8 lines · Klaus Jensen
Quoted 7 lines · Niklas Cassel
Quoted 1 line · Christoph Hellwig
Qemu unconditionally reports a UUID, which depending on the qemu version
Since it appears that both older and current QEMU versions are not implementing this properly, perhaps you should also consider adding the pci vendor and device id used by older QEMU versions?
Quoted 8 lines
Quoted 5 lines
QEMU nvme pci vendor and device id was changed in commit:
https://github.com/qemu/qemu/commit/6eb7a071292a2f11065127ac152fa24248806021Which was first included in QEMU v5.2.0.
That is a good point Niklas. +1 for that. The driver already knows about that ID.
5.2.0 is also the first qemu that supports the namespace descriptor list, that's why I didn't include it.
Re: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Klaus Jensen
Quoted 10 lines · Niklas Cassel
Quoted 1 line · Christoph Hellwig
Qemu unconditionally reports a UUID, which depending on the qemu version
Since it appears that both older and current QEMU versions are not implementing this properly, perhaps you should also consider adding the pci vendor and device id used by older QEMU versions?
QEMU nvme pci vendor and device id was changed in commit:
https://github.com/qemu/qemu/commit/6eb7a071292a2f11065127ac152fa24248806021
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Which was first included in QEMU v5.2.0.
That is a good point Niklas. +1 for that. The driver already knows about that ID.
5.2.0 is also the first qemu that supports the namespace descriptor list, that's why I didn't include it.
However, backwards compatibility in QEMU mandates that a compatibility parameter is added when a device changes identity like this (i.e. PCI vendor id).
This means that the 'use-intel-id' compatibility parameter may cause a 5.2 nvme device to present itself with the Intel PCI vendor/device id, either because the user explicitly set it, or because the machine is launched using a pre-5.2 machine type (i.e. -machine pc-q35-5.1), which you would normally do if you want launch an existing VM on a new version of QEMU.
Christoph Hellwig
maintainerRe: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 6 lines · Klaus Jensen
This means that the 'use-intel-id' compatibility parameter may cause a 5.2 nvme device to present itself with the Intel PCI vendor/device id, either because the user explicitly set it, or because the machine is launched using a pre-5.2 machine type (i.e.
-machine pc-q35-5.1), which you would normally do if you want launch an existing VM on a new version of QEMU.
But if it presents an old machine it also shouldn't support a new identify call, right?
Re: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Klaus Jensen
This means that the 'use-intel-id' compatibility parameter may cause a 5.2 nvme device to present itself with the Intel PCI vendor/device id, either because the user explicitly set it, or because the machine is launched using a pre-5.2 machine type (i.e.
-machine pc-q35-5.1), which you would normally do if you want launch an existing VM on a new version of QEMU.But if it presents an old machine it also shouldn't support a new identify call, right?
You are absolutely right in the case of live-migration, but hw/nvme is marked unmigratable, so we do not worry about that.
We probably screwed up with the compatibility parameter here, since it really only guarantees the id and some headaches for you as driver maintainer. I'm sorry about that - I'll keep this in mind for the future.
Regardless, the fact remains that it is possible to have a device with a buggy uuid namespace descriptor using the Intel identifier, so we should add the quirk for that as well.
Keith Busch
maintainerRe: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
Quoted 16 lines · Klaus Jensen
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Klaus Jensen
This means that the 'use-intel-id' compatibility parameter may cause a 5.2 nvme device to present itself with the Intel PCI vendor/device id, either because the user explicitly set it, or because the machine is launched using a pre-5.2 machine type (i.e.
-machine pc-q35-5.1), which you would normally do if you want launch an existing VM on a new version of QEMU.But if it presents an old machine it also shouldn't support a new identify call, right?
You are absolutely right in the case of live-migration, but hw/nvme is marked unmigratable, so we do not worry about that.
Quoted 8 lines
We probably screwed up with the compatibility parameter here, since it really only guarantees the id and some headaches for you as driver maintainer. I'm sorry about that - I'll keep this in mind for the future.
Regardless, the fact remains that it is possible to have a device with a buggy uuid namespace descriptor using the Intel identifier, so we should add the quirk for that as well.
Reporting that identifier really should be deprecated and removed if at all possible. There was a miscommunication regarding if that PCI device ID was actually reserved for this purpose (it wasn't). Intel at some point will use that DID for some device that isn't NVMe, then we're really going to be in difficult spot.
Christoph Hellwig
maintainerRe: [PATCH 3/3] nvme-pci: disable namespace identifiers for Qemu controllers
In reply to Klaus JensenQuoted 11 lines · Klaus Jensen
You are absolutely right in the case of live-migration, but hw/nvme is marked unmigratable, so we do not worry about that.
We probably screwed up with the compatibility parameter here, since it really only guarantees the id and some headaches for you as driver maintainer. I'm sorry about that - I'll keep this in mind for the future.
Regardless, the fact remains that it is possible to have a device with a buggy uuid namespace descriptor using the Intel identifier, so we should add the quirk for that as well.
I've added the quirk to the old ID for now.
Quoted 9 lines · Christoph Hellwig
Hi all,
this series adds a quirk to ignore namespace identifiers on controllers where they are completely broken and then quirks two controllers for it.
Changes since v1:
- validate namespace descriptor sizes even if ignoring them
- also handle another MAXIO controller with the same problem
- fix up a few commit messages
Looks good.