On Fri, Jan 08, 2016 at 12:25:09PM +0530, Bharata B Rao wrote: > Prevent guests from booting with CPU topologies that have partially > filled CPU cores or can result in partially filled CPU cores after > CPU hotplug like > > -smp 15,sockets=1,cores=4,threads=4,maxcpus=16 or > -smp 15,sockets=1,cores=4,threads=4,maxcpus=17. > > This is enforced by introducing MachineClass::validate_smp_config() > that gets called from generic SMP parsing code. Machine type versions > that don't want to enforce this can override this method. > > TODO: Only sPAPR and PC changes are done in this patch, other archs > will be touched after there is agreement on this approach. > > Signed-off-by: Bharata B Rao <bhar...@linux.vnet.ibm.com> > --- > hw/core/machine.c | 20 ++++++++++++++++++++ > hw/i386/pc_piix.c | 7 +++++++ > hw/i386/pc_q35.c | 7 +++++++ > hw/ppc/spapr.c | 7 +++++++ > include/hw/boards.h | 1 + > vl.c | 4 ++++ > 6 files changed, 46 insertions(+) > > diff --git a/hw/core/machine.c b/hw/core/machine.c > index c46ddc7..b66c101 100644 > --- a/hw/core/machine.c > +++ b/hw/core/machine.c > @@ -336,6 +336,25 @@ static void machine_init_notify(Notifier *notifier, void > *data) > foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL); > } > > +static int validate_smp_config_generic(int smp_cpus, int max_cpus, > + int smp_threads)
Please make it use a Error** parameter to return error information, and let the caller decide what to do with the error message. One day the mc->validate_smp_config() call may be moved inside a function that returns error information using Error** and needs to propagate it to the caller. > +{ > + if (smp_cpus % smp_threads) { > + error_report("cpu topology: " > + "smp_cpus (%u) should be multiple of threads (%u) ", > + smp_cpus, smp_threads); > + return 1; > + } > + > + if (max_cpus % smp_threads) { > + error_report("cpu topology: " > + "max_cpus (%u) should be multiple of threads (%u) ", > + max_cpus, smp_threads); > + return 1; > + } > + return 0; > +} > + [...] > diff --git a/vl.c b/vl.c > index 5aaea77..4b36a49 100644 > --- a/vl.c > +++ b/vl.c > @@ -4132,6 +4132,10 @@ int main(int argc, char **argv, char **envp) > > smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); > > + if (machine_class->validate_smp_config(smp_cpus, max_cpus, smp_threads)) > { > + exit(1); > + } > + > machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP > */ > if (max_cpus > machine_class->max_cpus) { > error_report("Number of SMP CPUs requested (%d) exceeds max CPUs " > -- > 2.1.0 > -- Eduardo