vl: exit if maxcpus is negative
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---Steps to Reproduce---
When passed a negative number to 'maxcpus' parameter, Qemu aborts
with a core dump.
Run the following command with maxcpus argument as negative number
ppc64-softmmu/qemu-system-ppc64 --nographic -vga none -machine
pseries,accel=kvm,kvm-type=HV -m size=200g -device virtio-blk-pci,
drive=rootdisk -drive file=/home/images/pegas-1.0-ppc64le.qcow2,
if=none,cache=none,id=rootdisk,format=qcow2 -monitor telnet
:127.0.0.1:1234,server,nowait -net nic,model=virtio -net
user -redir tcp:2000::22 -device nec-usb-xhci -smp 8,cores=1,
threads=1,maxcpus=-12
(process:12149): GLib-ERROR **: gmem.c:130: failed to allocate
18446744073709550568 bytes
Trace/breakpoint trap
Reported-by: R.Nageswara Sastry <rnsastry@linux.vnet.ibm.com>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Message-Id: <1504511031-26834-1-git-send-email-s1seetee@linux.vnet.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff --git a/vl.c b/vl.c
index ebea42e..d7c3492 100644
--- a/vl.c
+++ b/vl.c
@@ -161,7 +161,7 @@
int win2k_install_hack = 0;
int singlestep = 0;
int smp_cpus = 1;
-int max_cpus = 1;
+unsigned int max_cpus = 1;
int smp_cores = 1;
int smp_threads = 1;
int acpi_enabled = 1;
@@ -4331,8 +4331,8 @@
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 "
- "supported by machine '%s' (%d)", max_cpus,
+ error_report("Invalid SMP CPUs %d. The max CPUs "
+ "supported by machine '%s' is %d", max_cpus,
machine_class->name, machine_class->max_cpus);
exit(1);
}