aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorYanan Wang <wangyanan55@huawei.com>2021-09-29 10:58:15 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2021-10-01 19:04:31 +0200
commit8bdfec393a2ac67df9cecc0983d130db4a6bba58 (patch)
tree037eda9c70b3439890b2386bf4e743415321e009 /hw
parente7f944bb94a375e8ee7469ffa535ea6e11ce59e1 (diff)
downloadqemu-8bdfec393a2ac67df9cecc0983d130db4a6bba58.zip
qemu-8bdfec393a2ac67df9cecc0983d130db4a6bba58.tar.gz
qemu-8bdfec393a2ac67df9cecc0983d130db4a6bba58.tar.bz2
machine: Put all sanity-check in the generic SMP parser
Put both sanity-check of the input SMP configuration and sanity-check of the output SMP configuration uniformly in the generic parser. Then machine_set_smp() will become cleaner, also all the invalid scenarios can be tested only by calling the parser. Signed-off-by: Yanan Wang <wangyanan55@huawei.com> Reviewed-by: Andrew Jones <drjones@redhat.com> Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20210929025816.21076-16-wangyanan55@huawei.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/core/machine.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c
index d49ebc2..3920a2f 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -799,6 +799,20 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp)
unsigned maxcpus = config->has_maxcpus ? config->maxcpus : 0;
/*
+ * Specified CPU topology parameters must be greater than zero,
+ * 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)) {
+ warn_report("Deprecated CPU topology (considered invalid): "
+ "CPU topology parameters must be greater than zero");
+ }
+
+ /*
* If not supported by the machine, a topology parameter must be
* omitted or specified equal to 1.
*/
@@ -873,6 +887,22 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp)
topo_msg, maxcpus, cpus);
return;
}
+
+ if (ms->smp.cpus < mc->min_cpus) {
+ error_setg(errp, "Invalid SMP CPUs %d. The min CPUs "
+ "supported by machine '%s' is %d",
+ ms->smp.cpus,
+ mc->name, mc->min_cpus);
+ return;
+ }
+
+ if (ms->smp.max_cpus > mc->max_cpus) {
+ error_setg(errp, "Invalid SMP CPUs %d. The max CPUs "
+ "supported by machine '%s' is %d",
+ ms->smp.max_cpus,
+ mc->name, mc->max_cpus);
+ return;
+ }
}
static void machine_get_smp(Object *obj, Visitor *v, const char *name,
@@ -895,46 +925,14 @@ static void machine_get_smp(Object *obj, Visitor *v, const char *name,
static void machine_set_smp(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- MachineClass *mc = MACHINE_GET_CLASS(obj);
MachineState *ms = MACHINE(obj);
g_autoptr(SMPConfiguration) config = NULL;
- ERRP_GUARD();
if (!visit_type_SMPConfiguration(v, name, &config, errp)) {
return;
}
- /*
- * Specified CPU topology parameters must be greater than zero,
- * 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)) {
- warn_report("Deprecated CPU topology (considered invalid): "
- "CPU topology parameters must be greater than zero");
- }
-
smp_parse(ms, config, errp);
- if (*errp) {
- return;
- }
-
- /* sanity-check smp_cpus and max_cpus against mc */
- if (ms->smp.cpus < mc->min_cpus) {
- error_setg(errp, "Invalid SMP CPUs %d. The min CPUs "
- "supported by machine '%s' is %d",
- ms->smp.cpus,
- mc->name, mc->min_cpus);
- } else if (ms->smp.max_cpus > mc->max_cpus) {
- error_setg(errp, "Invalid SMP CPUs %d. The max CPUs "
- "supported by machine '%s' is %d",
- ms->smp.max_cpus,
- mc->name, mc->max_cpus);
- }
}
static void machine_class_init(ObjectClass *oc, void *data)