machine: Disallow specifying topology parameters as zero
v2 cover machine: Disallow specifying topology parameters as zero
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However; the commit 1e63fe685804d
(machine: pass QAPI struct to mc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.
This patch originly comes form [1], and it was suggested that this patch fixing the doc should be sent for 6.1 to avoid a deprecation process in the future.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
v1->v2:
- move the check to machine_set_smp
- update qemu-option.hx
- v1: https://lore.kernel.org/qemu-devel/[email protected]/
Yanan Wang (1):
machine: Disallow specifying topology parameters as zero
hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)
Signature · 1 line
2.19.1
PATCH v2 1/1 machine: Disallow specifying topology parameters as zero
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit 1e63fe685804d
(machine: pass QAPI struct to mc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.
--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)
hw/core/machine.c +14 -0
@@ -829,6 +829,20 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,return ; } +/* +* The topology parameters must be specified equal to or great than one +* or just omitted, explicit configuration like "cpus=0" is not allowed. +*/ +if ((config->has_cpus && config->cpus ==0 ) || + (config->has_sockets && config->sockets ==0 ) || + (config->has_dies && config->dies ==0 ) || + (config->has_cores && config->cores ==0 ) || + (config->has_threads && config->threads ==0 ) || + (config->has_maxcpus && config->maxcpus ==0 )) { +error_setg (errp,"parameters must be equal to or greater than one if provided" ); + goto out_free; + } + mc->smp_parse (ms, config, errp);if (errp) { goto out_free;
qapi/machine.json +3 -3
@@ -1288,8 +1288,8 @@ ## # @SMPConfiguration: # -# Schema for CPU topology configuration. "0" or a missing value lets -# QEMU figure out a suitable value based on the ones that are provided. +# Schema for CPU topology configuration. A missing value lets QEMU +# figure out a suitable value based on the ones that are provided. # # @cpus: number of virtual CPUs in the virtual machine #
@@ -1297,7 +1297,7 @@ # # @dies: number of dies per socket in the CPU topology # -# @cores: number of cores per thread in the CPU topology +# @cores: number of cores per die in the CPU topology # # @threads: number of threads per core in the CPU topology #
qemu-options.hx +7 -5
@@ -223,11 +223,13 @@ SRST of computing the CPU maximum count. Either the initial CPU count, or at least one of the topology parameters - must be specified. Values for any omitted parameters will be computed - from those which are given. Historically preference was given to the - coarsest topology parameters when computing missing values (ie sockets - preferred over cores, which were preferred over threads), however, this - behaviour is considered liable to change. + must be specified. The specified parameters must be equal to or great + than one, explicit configuration like "cpus=0" is not allowed. Values + for any omitted parameters will be computed from those which are given. + Historically preference was given to the coarsest topology parameters + when computing missing values (ie sockets preferred over cores, which + were preferred over threads), however, this behaviour is considered + liable to change. ERST DEF("numa", HAS_ARG, QEMU_OPTION_numa,
Signature · 1 line
2.19.1
Quoted 29 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)hw/core/machine.c +1
-0@@ -829,6 +829,20 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,return ; } +/*
hw/core/machine.c static void machine_set_smp(Object *obj, Visitor *v, const char *name, · line 842
Quoted 10 lines
hw/core/machine.c +10
-0+* The topology parameters must be specified equal to or great than one +* or just omitted, explicit configuration like "cpus=0" is not allowed. +*/ +if ((config->has_cpus && config->cpus ==0 ) || + (config->has_sockets && config->sockets ==0 ) || + (config->has_dies && config->dies ==0 ) || + (config->has_cores && config->cores ==0 ) || + (config->has_threads && config->threads ==0 ) || + (config->has_maxcpus && config->maxcpus ==0 )) { +error_setg (errp,"parameters must be equal to or greater than one if provided" );
I'd suggest a slight tweak since when seen it lacks context:
$ ./qemu-system-x86_64 -smp 4,cores=0,sockets=2 qemu-system-x86_64: parameters must be equal to or greater than one if provided
error_setg(errp, "CPU topology parameters must be equal to or greater than one if provided");
Quoted 5 lines
qemu-options.hx +0
-0
qemu-options.hx SRST · line 226
Quoted 9 lines
qemu-options.hx +1
-5@@ -223,11 +223,13 @@ SRST of computing the CPU maximum count. Either the initial CPU count, or at least one of the topology parameters - must be specified. Values for any omitted parameters will be computed - from those which are given. Historically preference was given to the - coarsest topology parameters when computing missing values (ie sockets - preferred over cores, which were preferred over threads), however, this - behaviour is considered liable to change. + must be specified. The specified parameters must be equal to or great
s/great/greater/
qemu-options.hx SRST · line 233
Quoted 7 lines
qemu-options.hx +6
-0+ than one, explicit configuration like "cpus=0" is not allowed. Values + for any omitted parameters will be computed from those which are given. + Historically preference was given to the coarsest topology parameters + when computing missing values (ie sockets preferred over cores, which + were preferred over threads), however, this behaviour is considered + liable to change. ERST
If you make the text changes, then feel free to add this when posting v2:
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 43 lines · Daniel P. Berrangé
Quoted 29 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)hw/core/machine.c +1
-0@@ -829,6 +829,20 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,return ; } +/* hw/core/machine.c static void machine_set_smp(Object *obj, Visitor *v, const char *name, · line 842
Quoted 10 lines
hw/core/machine.c +10
-0+* The topology parameters must be specified equal to or great than one +* or just omitted, explicit configuration like "cpus=0" is not allowed. +*/ +if ((config->has_cpus && config->cpus ==0 ) || + (config->has_sockets && config->sockets ==0 ) || + (config->has_dies && config->dies ==0 ) || + (config->has_cores && config->cores ==0 ) || + (config->has_threads && config->threads ==0 ) || + (config->has_maxcpus && config->maxcpus ==0 )) { +error_setg (errp,"parameters must be equal to or greater than one if provided" );I'd suggest a slight tweak since when seen it lacks context:
Quoted 5 lines
$ ./qemu-system-x86_64 -smp 4,cores=0,sockets=2 qemu-system-x86_64: parameters must be equal to or greater than one if providederror_setg(errp, "CPU topology parameters must be equal to or greater than one if provided");
Let's scratch "if provided".
I'd replace "must be equal to or greater than one" by "must be positive", or maybe "must be greater than zero".
Quoted 7 lines
Quoted 7 lines
qemu-options.hx +0
-0@@ -223,11 +223,13 @@ SRST of computing the CPU maximum count.
Quoted 11 lines
qemu-options.hx SRST · line 226
Quoted 7 lines
qemu-options.hx +1
-5Either the initial CPU count, or at least one of the topology parameters - must be specified. Values for any omitted parameters will be computed - from those which are given. Historically preference was given to the - coarsest topology parameters when computing missing values (ie sockets - preferred over cores, which were preferred over threads), however, this - behaviour is considered liable to change. + must be specified. The specified parameters must be equal to or greats/great/greater/
Quoted 1 line
qemu-options.hx +1
-0+ than one, explicit configuration like "cpus=0" is not allowed. Values
"positive" again.
Quoted 17 lines
qemu-options.hx SRST · line 233
Quoted 6 lines
qemu-options.hx +5
-0+ for any omitted parameters will be computed from those which are given. + Historically preference was given to the coarsest topology parameters + when computing missing values (ie sockets preferred over cores, which + were preferred over threads), however, this behaviour is considered + liable to change. ERSTIf you make the text changes, then feel free to add this when posting v2:
Reviewed-by Daniel P. Berrangé <[email protected]>Tested-by Daniel P. Berrangé <[email protected]>Regards,
Daniel
Quoted 48 lines · Markus Armbruster
Quoted 46 lines · Daniel P. Berrangé
Quoted 29 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)hw/core/machine.c +1
-0@@ -829,6 +829,20 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,return ; } +/* hw/core/machine.c static void machine_set_smp(Object *obj, Visitor *v, const char *name, · line 842
Quoted 10 lines
hw/core/machine.c +10
-0+* The topology parameters must be specified equal to or great than one +* or just omitted, explicit configuration like "cpus=0" is not allowed. +*/ +if ((config->has_cpus && config->cpus ==0 ) || + (config->has_sockets && config->sockets ==0 ) || + (config->has_dies && config->dies ==0 ) || + (config->has_cores && config->cores ==0 ) || + (config->has_threads && config->threads ==0 ) || + (config->has_maxcpus && config->maxcpus ==0 )) { +error_setg (errp,"parameters must be equal to or greater than one if provided" );I'd suggest a slight tweak since when seen it lacks context:
$ ./qemu-system-x86_64 -smp 4,cores=0,sockets=2 qemu-system-x86_64: parameters must be equal to or greater than one if provided
Quoted 5 lines
Quoted 1 line
error_setg(errp, "CPU topology parameters must be equal to or greater than one if provided");Let's scratch "if provided".
I'd replace "must be equal to or greater than one" by "must be positive", or maybe "must be greater than zero".
How about we use "must be greater than zero" ?
After a grep search of these two sentences in QEMU, they both show up in several places. "must be positive" always reports an invalid value that is "< 0". While the check in this patch actually reject an invalid zero value.
Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
qemu-options.hx +0
-0qemu-options.hx SRST · line 226
Quoted 9 lines
qemu-options.hx +1
-5@@ -223,11 +223,13 @@ SRST of computing the CPU maximum count. Either the initial CPU count, or at least one of the topology parameters - must be specified. Values for any omitted parameters will be computed - from those which are given. Historically preference was given to the - coarsest topology parameters when computing missing values (ie sockets - preferred over cores, which were preferred over threads), however, this - behaviour is considered liable to change. + must be specified. The specified parameters must be equal to or greats/great/greater/
Quoted 2 lines
Quoted 1 line
qemu-options.hx SRST · line 227
Quoted 1 line
qemu-options.hx +1
-0+ than one, explicit configuration like "cpus=0" is not allowed. Values"positive" again.
Thanks,
Yanan
Quoted 17 lines
Quoted 9 lines
qemu-options.hx SRST · line 233
Quoted 6 lines
qemu-options.hx +5
-0+ for any omitted parameters will be computed from those which are given. + Historically preference was given to the coarsest topology parameters + when computing missing values (ie sockets preferred over cores, which + were preferred over threads), however, this behaviour is considered + liable to change. ERSTIf you make the text changes, then feel free to add this when posting v2:
Quoted 7 lines
Reviewed-by Daniel P. Berrangé <[email protected]>Tested-by Daniel P. Berrangé <[email protected]>Regards,
Daniel.
Quoted 24 lines · wangyanan (Y)
Quoted 23 lines · Markus Armbruster
Quoted 12 lines · Daniel P. Berrangé
hw/core/machine.c static void machine_set_smp(Object *obj, Visitor *v, const char *name, · line 842
Quoted 11 lines · Yanan Wang
hw/core/machine.c +11
-0+/* +* The topology parameters must be specified equal to or great than one +* or just omitted, explicit configuration like "cpus=0" is not allowed. +*/ +if ((config->has_cpus && config->cpus ==0 ) || + (config->has_sockets && config->sockets ==0 ) || + (config->has_dies && config->dies ==0 ) || + (config->has_cores && config->cores ==0 ) || + (config->has_threads && config->threads ==0 ) || + (config->has_maxcpus && config->maxcpus ==0 )) { +error_setg (errp,"parameters must be equal to or greater than one if provided" );Quoted 7 lines
I'd suggest a slight tweak since when seen it lacks context:
$ ./qemu-system-x86_64 -smp 4,cores=0,sockets=2 qemu-system-x86_64: parameters must be equal to or greater than one if providederror_setg(errp, "CPU topology parameters must be equal to or greater than one if provided");Let's scratch "if provided".
Quoted 7 lines
Quoted 2 lines
I'd replace "must be equal to or greater than one" by "must be positive", or maybe "must be greater than zero".
How about we use "must be greater than zero" ?
After a grep search of these two sentences in QEMU, they both show up in several places. "must be positive" always reports an invalid value that is "< 0". While the check in this patch actually reject an invalid zero value.
Of the two, I'd prefer "greater than zero".
Quoted 12 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.
Quoted 7 lines
Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)
With Daniel's suggested changes for v3
Quoted 12 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.
Quoted 7 lines
Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)
Hi Yanan,
This looks somewhat similar to this very old patch of mine:
https://mail.gnu.org/archive/html/qemu-devel/2020-10/msg03039.html
I'm putting a reference here because I believe the test can be salvaged and slightly adapted for this patch of yours.
Let me know if I can help anyhow.
Thanks,
- Cleber.
Hi Cleber,
Quoted 23 lines · Cleber Rosa
Quoted 12 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.Quoted 7 lines
Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)Hi Yanan,
Quoted 9 lines
This looks somewhat similar to this very old patch of mine:
https://mail.gnu.org/archive/html/qemu-devel/2020-10/msg03039.htmlI'm putting a reference here because I believe the test can be salvaged and slightly adapted for this patch of yours.
Let me know if I can help anyhow.
Thanks for this.
I was introducing an unit test for the smp parsing in [1], in which all possible valid and invalid smp configs were covered, and actually the "parameter=0" stuff was also covered. You can have a look, and suggestions are welcome. I'm not sure we need two different tests for the same part. :)
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Thanks,
Yanan
.
Quoted 33 lines · wangyanan (Y)
Hi Cleber,
Quoted 30 lines · Cleber Rosa
Quoted 12 lines · Yanan Wang
In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=0" are meaningless, so disallow them.
However, the commit
1e63fe685804d
(machine: pass QAPI struct tomc->smp_parse) has documented that '0' has the same semantics as omitting a parameter in the qapi comment for SMPConfiguration. So this patch fixes the doc and also adds the corresponding sanity check in the smp parsers.Quoted 7 lines
Suggested-by Andrew Jones <[email protected]>Signed-off-by Yanan Wang <[email protected]>--- hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 6 +++--- qemu-options.hx | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-)Hi Yanan,
This looks somewhat similar to this very old patch of mine:
https://mail.gnu.org/archive/html/qemu-devel/2020-10/msg03039.htmlI'm putting a reference here because I believe the test can be salvaged and slightly adapted for this patch of yours.
Quoted 9 lines
Quoted 2 lines
Let me know if I can help anyhow.
Thanks for this.
I was introducing an unit test for the smp parsing in [1], in which all possible valid and invalid smp configs were covered, and actually the "parameter=0" stuff was also covered. You can have a look, and suggestions are welcome. I'm not sure we need two different tests for the same part. :)
Right, I only saw the other series later. Nice work there!
- Cleber.