hw/nvme: fix namespace identifiers
v2 cover hw/nvme: fix namespace identifiers
From: Klaus Jensen <[email protected]>
The namespace identifiers reported by the controller is kind of a mess. See [1,2].
This series should fix this for both the -device nvme,drive=... and -device nvme-ns,... cases.
[1]: https://lore.kernel.org/linux-nvme/[email protected]/
[2]: https://lore.kernel.org/linux-nvme/[email protected]/
Changes since v1:
- Revert auto-generation of eui64 (Christoph)
User should set it explicitly.
Klaus Jensen (5):
hw/nvme: enforce common serial per subsystem
hw/nvme: do not auto-generate eui64
hw/nvme: do not auto-generate uuid
hw/nvme: do not report null uuid
hw/nvme: bump firmware revision
docs/about/deprecated.rst | 7 +++++++ hw/core/machine.c | 4 +++- hw/nvme/ctrl.c | 19 ++++++++----------- hw/nvme/ns.c | 4 ++-- hw/nvme/nvme.h | 1 + hw/nvme/subsys.c | 7 +++++++ 6 files changed, 28 insertions(+), 14 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/5 hw/nvme: enforce common serial per subsystem
From: Klaus Jensen <[email protected]>
The Identify Controller Serial Number (SN) is the serial number for the NVM subsystem and must be the same across all controller in the NVM subsystem.
Enforce this.
--- hw/nvme/nvme.h | 1 + hw/nvme/subsys.c | 7 +++++++ 2 files changed, 8 insertions(+)
hw/nvme/nvme.h +1 -0
@@ -48,6 +48,7 @@ typedef struct NvmeSubsystem {DeviceState parent_obj;NvmeBus bus;uint8_t subnqn[256 ]; +char *serial;NvmeCtrl *ctrls[NVME_MAX_CONTROLLERS ];NvmeNamespace *namespaces[NVME_MAX_NAMESPACES +1 ];
hw/nvme/subsys.c +7 -0
@@ -27,6 +27,13 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)return -1 ; } +if (!subsys->serial) { + subsys->serial =g_strdup (n->params.serial); + }else if (strcmp (subsys->serial, n->params.serial)) { +error_setg (errp,"invalid controller serial" ); +return -1 ; + } + subsys->ctrls[cntlid] = n;for (nsid =1 ; nsid <ARRAY_SIZE (subsys->namespaces); nsid++) {
Signature · 1 line
2.35.1
PATCH v2 2/5 hw/nvme: do not auto-generate eui64
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
We cannot provide auto-generated unique or persistent namespace identifiers (EUI64, NGUID, UUID) easily. Since 6.1, namespaces have been assigned a generated EUI64 of the form "52:54:00:<namespace counter>". This is will be unique within a QEMU instance, but not globally.
Revert that this is assigned automatically and immediately deprecate the compatibility parameter. Users can opt-in to this with the eui64-default=on device parameter or set it explicitly with eui64=UINT64.
--- docs/about/deprecated.rst | 7 +++++++ hw/core/machine.c | 4 +++- hw/nvme/ns.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)
docs/about/deprecated.rst +7 -0
@@ -356,6 +356,13 @@ contains native support for this feature and thus use of the option ROM approach is obsolete. The native SeaBIOS support can be activated by using ``-machine graphics=off``. +``-device nvme-ns,eui64-default=on|off`` (since 7.1) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In QEMU versions 6.1, 6.2 and 7.0, the ``nvme-ns`` generates an EUI-64 +identifer that is not globally unique. If an EUI-64 identifer is required, the +user must set it explicitly using the ``nvme-ns`` device parameter ``eui64``. + Block device options ''''''''''''''''''''
hw/core/machine.c +3 -1
@@ -37,7 +37,9 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-pci.h" -GlobalProperty hw_compat_7_0[] = {}; +GlobalProperty hw_compat_7_0[] = { + {"nvme-ns" ,"eui64-default" ,"on" }, +};const size_t hw_compat_7_0_len =G_N_ELEMENTS (hw_compat_7_0);GlobalProperty hw_compat_6_2[] = {
hw/nvme/ns.c +1 -1
@@ -641,7 +641,7 @@ static Property nvme_ns_props[] = {DEFINE_PROP_SIZE ("zoned.zrwas" , NvmeNamespace, params.zrwas,0 ),DEFINE_PROP_SIZE ("zoned.zrwafg" , NvmeNamespace, params.zrwafg,-1 ),DEFINE_PROP_BOOL ("eui64-default" , NvmeNamespace, params.eui64_default, - true), + false), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.35.1
Re: [PATCH v2 2/5] hw/nvme: do not auto-generate eui64
Quoted 11 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
We cannot provide auto-generated unique or persistent namespace identifiers (EUI64, NGUID, UUID) easily. Since 6.1, namespaces have been assigned a generated EUI64 of the form "52:54:00:<namespace counter>". This is will be unique within a QEMU instance, but not globally.
Revert that this is assigned automatically and immediately deprecate the compatibility parameter. Users can opt-in to this with the
eui64-default=ondevice parameter or set it explicitly witheui64=UINT64.
Looks good:
PATCH v2 3/5 hw/nvme: do not auto-generate uuid
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Do not default to generate an UUID for namespaces if it is not explicitly specified.
This is a technically a breaking change in behavior. However, since the UUID changes on every VM launch, it is not spec compliant and is of little use since the UUID cannot be used reliably anyway and the behavior prior to this patch must be considered buggy.
--- hw/nvme/ns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/ns.c +1 -1
@@ -614,7 +614,7 @@ static Property nvme_ns_props[] = {DEFINE_PROP_BOOL ("detached" , NvmeNamespace, params.detached, false),DEFINE_PROP_BOOL ("shared" , NvmeNamespace, params.shared, true),DEFINE_PROP_UINT32 ("nsid" , NvmeNamespace, params.nsid,0 ), -DEFINE_PROP_UUID ("uuid" , NvmeNamespace, params.uuid), +DEFINE_PROP_UUID_NODEFAULT ("uuid" , NvmeNamespace, params.uuid),DEFINE_PROP_UINT64 ("eui64" , NvmeNamespace, params.eui64,0 ),DEFINE_PROP_UINT16 ("ms" , NvmeNamespace, params.ms,0 ), DEFINE_PROP_UINT8("mset", NvmeNamespace, params.mset, 0),
Signature · 1 line
2.35.1
Re: [PATCH v2 3/5] hw/nvme: do not auto-generate uuid
Quoted 5 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Do not default to generate an UUID for namespaces if it is not explicitly specified.
Quoted 7 lines
This is a technically a breaking change in behavior. However, since the UUID changes on every VM launch, it is not spec compliant and is of little use since the UUID cannot be used reliably anyway and the behavior prior to this patch must be considered buggy.
Reviewed-by Keith Busch <[email protected]>Signed-off-by Klaus Jensen <[email protected]>
Looks good:
PATCH v2 4/5 hw/nvme: do not report null uuid
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Do not report the "null uuid" (all zeros) in the namespace identification descriptors.
--- hw/nvme/ctrl.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
hw/nvme/ctrl.c +7 -10
@@ -4955,16 +4955,13 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req)return NVME_INVALID_FIELD |NVME_DNR ; } -/* -* If the EUI-64 field is 0 and the NGUID field is 0, the namespace must -* provide a valid Namespace UUID in the Namespace Identification Descriptor -* data structure. QEMU does not yet support setting NGUID. -*/ - uuid.hdr.nidt =NVME_NIDT_UUID ; - uuid.hdr.nidl =NVME_NIDL_UUID ; -memcpy (uuid.v, ns->params.uuid.data,NVME_NIDL_UUID ); -memcpy (pos, &uuid,sizeof (uuid)); - pos +=sizeof (uuid); +if (!qemu_uuid_is_null (&ns->params.uuid)) { + uuid.hdr.nidt =NVME_NIDT_UUID ; + uuid.hdr.nidl =NVME_NIDL_UUID ; +memcpy (uuid.v, ns->params.uuid.data,NVME_NIDL_UUID ); +memcpy (pos, &uuid,sizeof (uuid)); + pos +=sizeof (uuid); + }if (ns->params.eui64) { eui64.hdr.nidt =NVME_NIDT_EUI64 ;
Signature · 1 line
2.35.1
PATCH v2 5/5 hw/nvme: bump firmware revision
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The Linux kernel quirks the QEMU NVMe controller pretty heavily because of the namespace identifier mess. Since this is now fixed, bump the firmware revision number to allow the quirk to be disabled for this revision.
As of now, bump the firmware revision number to be equal to the QEMU release version number.
--- hw/nvme/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/ctrl.c +1 -1
@@ -6713,7 +6713,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn),"QEMU NVMe Ctrl" ,' ' ); -strpadcpy ((char *)id->fr,sizeof (id->fr),"1.0" ,' ' ); +strpadcpy ((char *)id->fr,sizeof (id->fr),QEMU_VERSION ,' ' );strpadcpy ((char *)id->sn,sizeof (id->sn), n->params.serial,' ' ); id->cntlid =cpu_to_le16 (n->cntlid);
Signature · 1 line
2.35.1
Quoted 22 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
The namespace identifiers reported by the controller is kind of a mess. See [1,2].
This series should fix this for both the
-device nvme,drive=...and-device nvme-ns,...cases.[1]: https://lore.kernel.org/linux-nvme/[email protected]/
[2]: https://lore.kernel.org/linux-nvme/[email protected]/Changes since v1:
- Revert auto-generation of eui64 (Christoph)
User should set it explicitly.Klaus Jensen (5):
hw/nvme: enforce common serial per subsystem
hw/nvme: do not auto-generate eui64
hw/nvme: do not auto-generate uuid
hw/nvme: do not report null uuid
hw/nvme: bump firmware revision
Quoted 11 lines
docs/about/deprecated.rst | 7 +++++++ hw/core/machine.c | 4 +++- hw/nvme/ctrl.c | 19 ++++++++----------- hw/nvme/ns.c | 4 ++-- hw/nvme/nvme.h | 1 + hw/nvme/subsys.c | 7 +++++++ 6 files changed, 28 insertions(+), 14 deletions(-)Signature · 1 line
2.35.1
Thanks for the reviews! Applied to nvme-next.