hw/nvme: make model & firmware version cnofigurable
cover hw/nvme: make model & firmware version cnofigurable
These are both currently set to QEMU specific hardcoded defaults, and in common with other block devices, should allow user overrides.
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Daniel P. Berrangé (4):
include/block: define constants for NVME string fields hw/nvme: report error for oversized 'serial' parameter hw/nvme: add user controlled 'model' property hw/nvme: add user controlled 'firmware-version' property
docs/system/devices/nvme.rst | 10 ++++++++++ hw/nvme/ctrl.c | 31 ++++++++++++++++++++++++++++--- hw/nvme/nvme.h | 2 ++ include/block/nvme.h | 10 +++++++--- 4 files changed, 47 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0
PATCH 2/4 hw/nvme: report error for oversized 'serial' parameter
The 'serial' accepted by the NVME device is at most 20 characters long. An over-sized user supplied value should be reported rather than silently truncated.
--- hw/nvme/ctrl.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/nvme/ctrl.c +5 -0
@@ -8600,6 +8600,11 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp)error_setg (errp,"serial property not set" );return false; } +if (strlen (params->serial) >NVME_ID_CTRL_SN_MAX_LEN ) { +error_setg (errp,"'serial' parameter '%s' can be at most '%d' characters" , + params->serial,NVME_ID_CTRL_SN_MAX_LEN ); +return false; + }if (params->mqes <1 ) {error_setg (errp,"mqes property cannot be less than 1" );
Signature · 1 line
2.53.0
PATCH 1/4 include/block: define constants for NVME string fields
In reply to Daniel P. BerrangéThe version, model and serial fields accept fixed length strings. Add constants to enable user supplied strings to be validated.
--- include/block/nvme.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
include/block/nvme.h +7 -3
@@ -1134,12 +1134,16 @@ enum NvmeIdCns { NVME_ID_CNS_CS_IND_NS_ALLOCATED = 0x1f, }; +#define NVME_ID_CTRL_SN_MAX_LEN 20 +#define NVME_ID_CTRL_MN_MAX_LEN 40 +#define NVME_ID_CTRL_FR_MAX_LEN 8 + typedef struct QEMU_PACKED NvmeIdCtrl {uint16_t vid;uint16_t ssvid; -uint8_t sn[20 ]; -uint8_t mn[40 ]; -uint8_t fr[8 ]; +uint8_t sn[NVME_ID_CTRL_SN_MAX_LEN ]; +uint8_t mn[NVME_ID_CTRL_MN_MAX_LEN ]; +uint8_t fr[NVME_ID_CTRL_FR_MAX_LEN ];uint8_t rab;uint8_t ieee[3 ];uint8_t cmic;
Signature · 1 line
2.53.0
PATCH 4/4 hw/nvme: add user controlled 'firmware-version' property
In reply to Daniel P. BerrangéThis enables overriding the built in default QEMU project version string with a user specified string. The value can be at most 8 characters in length.
--- docs/system/devices/nvme.rst | 5 +++++ hw/nvme/ctrl.c | 14 ++++++++++++-- hw/nvme/nvme.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-)
docs/system/devices/nvme.rst +5 -0
@@ -65,6 +65,11 @@ parameters. to more closely impersonate a particular device type. The model name can be a maximum of 40 characters in length. +``firmware-version`` (default: current QEMU version number) + Override the default reported firmware version, which can be used when + needing to more closely impersonate a particular device type. The version + can be a maximum of 8 characters in length. + Additional Namespaces ---------------------
hw/nvme/ctrl.c +12 -2
@@ -44,7 +44,8 @@* atomic.awun<N[optional]>, \ * atomic.awupf<N[optional]>, \ * subsys=<subsys_id>, \ -* model=<model-str> +* model=<model-str>, \ +* firmware-version=<version-str> * -device nvme-ns,drive=<drive_id>,bus=<bus_name>,nsid=<nsid>,\ * zoned=<true|false[optional]>, \ * subsys=<subsys_id>,shared=<true|false[optional]>, \
@@ -8614,6 +8615,13 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp)return false; } +if (params->firmware_version && +strlen (params->firmware_version) >NVME_ID_CTRL_FR_MAX_LEN ) { +error_setg (errp,"'firmware-version' parameter '%s' can be at most '%d' characters" , + params->firmware_version,NVME_ID_CTRL_FR_MAX_LEN ); +return false; + } +if (params->mqes <1 ) {error_setg (errp,"mqes property cannot be less than 1" );return false;
@@ -9109,7 +9117,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn), n->params.model ? n->params.model :"QEMU NVMe Ctrl" ,' ' ); -strpadcpy ((char *)id->fr,sizeof (id->fr),QEMU_VERSION ,' ' ); +strpadcpy ((char *)id->fr,sizeof (id->fr), + n->params.firmware_version ? n->params.firmware_version :QEMU_VERSION ,' ' );strpadcpy ((char *)id->sn,sizeof (id->sn), n->params.serial,' ' ); id->cntlid =cpu_to_le16 (n->cntlid);
@@ -9389,6 +9398,7 @@ static const Property nvme_props[] = { NvmeSubsystem *),DEFINE_PROP_STRING ("serial" , NvmeCtrl, params.serial),DEFINE_PROP_STRING ("model" , NvmeCtrl, params.model), +DEFINE_PROP_STRING ("firmware-version" , NvmeCtrl, params.firmware_version),DEFINE_PROP_UINT32 ("cmb_size_mb" , NvmeCtrl, params.cmb_size_mb,0 ),DEFINE_PROP_UINT32 ("num_queues" , NvmeCtrl, params.num_queues,0 ), DEFINE_PROP_UINT32("max_ioqpairs", NvmeCtrl, params.max_ioqpairs, 64),
hw/nvme/nvme.h +1 -0
@@ -543,6 +543,7 @@ typedef struct NvmeCQueue { typedef struct NvmeParams { char *serial; char *model; + char *firmware_version; uint32_t num_queues; /* deprecated since 5.1 */ uint32_t max_ioqpairs; uint16_t msix_qsize;
Signature · 1 line
2.53.0
PATCH 3/4 hw/nvme: add user controlled 'model' property
In reply to Daniel P. BerrangéThis enables overriding the built in default "QEMU NVMe Ctrl" string with a user specified string. The value can be at most 40 characters in length.
--- docs/system/devices/nvme.rst | 5 +++++ hw/nvme/ctrl.c | 14 ++++++++++++-- hw/nvme/nvme.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-)
docs/system/devices/nvme.rst +5 -0
@@ -60,6 +60,11 @@ parameters. the SMART / Health information extended log become available in the controller. We emulate version 5 of this log page. +``model`` (default: ``QEMU NVMe Ctrl``) + Override the default reported model, which can be used when needing + to more closely impersonate a particular device type. The model name + can be a maximum of 40 characters in length. + Additional Namespaces ---------------------
hw/nvme/ctrl.c +12 -2
@@ -43,7 +43,8 @@* atomic.dn=<on|off[optional]>, \ * atomic.awun<N[optional]>, \ * atomic.awupf<N[optional]>, \ -* subsys=<subsys_id> +* subsys=<subsys_id>, \ +* model=<model-str> * -device nvme-ns,drive=<drive_id>,bus=<bus_name>,nsid=<nsid>,\ * zoned=<true|false[optional]>, \ * subsys=<subsys_id>,shared=<true|false[optional]>, \
@@ -8606,6 +8607,13 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp)return false; } +if (params->model && +strlen (params->model) >NVME_ID_CTRL_MN_MAX_LEN ) { +error_setg (errp,"'model' parameter '%s' can be at most '%d' characters" , + params->model,NVME_ID_CTRL_MN_MAX_LEN ); +return false; + } +if (params->mqes <1 ) {error_setg (errp,"mqes property cannot be less than 1" );return false;
@@ -9099,7 +9107,8 @@ 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->mn,sizeof (id->mn), + n->params.model ? n->params.model :"QEMU NVMe Ctrl" ,' ' );strpadcpy ((char *)id->fr,sizeof (id->fr),QEMU_VERSION ,' ' );strpadcpy ((char *)id->sn,sizeof (id->sn), n->params.serial,' ' );
@@ -9379,6 +9388,7 @@ static const Property nvme_props[] = {DEFINE_PROP_LINK ("subsys" , NvmeCtrl, subsys,TYPE_NVME_SUBSYS , NvmeSubsystem *),DEFINE_PROP_STRING ("serial" , NvmeCtrl, params.serial), +DEFINE_PROP_STRING ("model" , NvmeCtrl, params.model),DEFINE_PROP_UINT32 ("cmb_size_mb" , NvmeCtrl, params.cmb_size_mb,0 ),DEFINE_PROP_UINT32 ("num_queues" , NvmeCtrl, params.num_queues,0 ), DEFINE_PROP_UINT32("max_ioqpairs", NvmeCtrl, params.max_ioqpairs, 64),
hw/nvme/nvme.h +1 -0
@@ -542,6 +542,7 @@ typedef struct NvmeCQueue { typedef struct NvmeParams { char *serial; + char *model; uint32_t num_queues; /* deprecated since 5.1 */ uint32_t max_ioqpairs; uint16_t msix_qsize;
Signature · 1 line
2.53.0
Quoted 2 lines · Daniel P. Berrangé
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Generally fine with that, but worried about user regressions from unknowingly relying on the truncation behavior. Could these overflow conditions just emit a truncation warn_report instead of failing to start?
Quoted 8 lines · Keith Busch
Quoted 2 lines · Daniel P. Berrangé
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Generally fine with that, but worried about user regressions from unknowingly relying on the truncation behavior. Could these overflow conditions just emit a truncation
warn_reportinstead of failing to start?
There is always that possibility that someone is unknowingly having their data truncated, however, we have generally taken the view that it is fair game to introduce error checking for invalid input in these kind of cases. As prior art, we introduced error checking to the SCSI serial to remove truncation:
commit 75997e182b695f2e3f0a2d649734952af5caf3ee
Author: Kevin Wolf <[email protected]>
Date: Tue Jun 4 18:17:55 2024 +0200
scsi-disk: Don't silently truncate serial number
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Quoted 13 lines · Daniel P. Berrangé
These are both currently set to QEMU specific hardcoded defaults, and in common with other block devices, should allow user overrides.
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Daniel P. Berrangé (4):
include/block: define constants for NVME string fields hw/nvme: report error for oversized 'serial' parameter hw/nvme: add user controlled 'model' property hw/nvme: add user controlled 'firmware-version' property
Ping on this, I'd really like to see it merged.
Klaus Jensen
AppliedQuoted 12 lines · Daniel P. Berrangé
These are both currently set to QEMU specific hardcoded defaults, and in common with other block devices, should allow user overrides.
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Daniel P. Berrangé (4):
include/block: define constants for NVME string fields hw/nvme: report error for oversized 'serial' parameter hw/nvme: add user controlled 'model' property hw/nvme: add user controlled 'firmware-version' property
Quoted 10 lines
docs/system/devices/nvme.rst | 10 ++++++++++ hw/nvme/ctrl.c | 31 ++++++++++++++++++++++++++++--- hw/nvme/nvme.h | 2 ++ include/block/nvme.h | 10 +++++++--- 4 files changed, 47 insertions(+), 6 deletions(-)Signature · 1 line
2.53.0
Given the reference to prior art on introducing error checking in these cases, this LGTM.
Applied to nvme.for-11.1. Thanks!
Quoted 24 lines · Klaus Jensen
Quoted 12 lines · Daniel P. Berrangé
These are both currently set to QEMU specific hardcoded defaults, and in common with other block devices, should allow user overrides.
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Daniel P. Berrangé (4):
include/block: define constants for NVME string fields hw/nvme: report error for oversized 'serial' parameter hw/nvme: add user controlled 'model' property hw/nvme: add user controlled 'firmware-version' propertyQuoted 10 lines
docs/system/devices/nvme.rst | 10 ++++++++++ hw/nvme/ctrl.c | 31 ++++++++++++++++++++++++++++--- hw/nvme/nvme.h | 2 ++ include/block/nvme.h | 10 +++++++--- 4 files changed, 47 insertions(+), 6 deletions(-)--
2.53.0
Quoted 5 lines
Given the reference to prior art on introducing error checking in these cases, this LGTM.
Applied to nvme.for-11.1. Thanks!
I don't see it in master. What's the schedule for upstreaming it?
Quoted 26 lines · Avi Kivity
Quoted 24 lines · Klaus Jensen
Quoted 22 lines · Daniel P. Berrangé
These are both currently set to QEMU specific hardcoded defaults, and in common with other block devices, should allow user overrides.
The pre-existing serial field should also be length checked to detect & report invalid user input instead of silently truncating.
Daniel P. Berrangé (4):
include/block: define constants for NVME string fields hw/nvme: report error for oversized 'serial' parameter hw/nvme: add user controlled 'model' property hw/nvme: add user controlled 'firmware-version' propertydocs/system/devices/nvme.rst | 10 ++++++++++ hw/nvme/ctrl.c | 31 ++++++++++++++++++++++++++++--- hw/nvme/nvme.h | 2 ++ include/block/nvme.h | 10 +++++++--- 4 files changed, 47 insertions(+), 6 deletions(-)--
2.53.0
Quoted 8 lines
Quoted 5 lines
Given the reference to prior art on introducing error checking in these cases, this LGTM.
Applied to nvme.for-11.1. Thanks!
I don't see it in master. What's the schedule for upstreaming it?
I see it's upstream. Thanks, silent maintainers! Looking forward to 11.1.