diff mbox series

[1/2] ppc/pnv: Exit gracefully if CPU topology doesn't match the machine capacities

Message ID 157686070223.97184.882725559353545017.stgit@bahia.lan (mailing list archive)
State New, archived
Headers show
Series ppc/pnv: Improve command line experience with multi-chip | expand

Commit Message

Greg Kurz Dec. 20, 2019, 4:51 p.m. UTC
QEMU crashes when started with:

   -machine powernv,num-chips=2 -smp cores=2 -accel tcg,thread=multi

ERROR:
tcg/tcg.c:789:tcg_register_thread: assertion failed: (n < ms->smp.max_cpus)
Aborted (core dumped)

This happens because the powernv machine creates num-chips * smp.cores
CPUs, which might exceed the maximum number of CPUs of the CPU topology
as computed by smp_parse().

Check the CPU topology in pnv_set_num_chips().

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/pnv.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index f77e7ca84ede..f8cf2b6d760f 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -1706,7 +1706,8 @@  static void pnv_set_num_chips(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp)
 {
     PnvMachineState *pnv = PNV_MACHINE(obj);
-    uint32_t num_chips;
+    MachineState *ms = MACHINE(pnv);
+    uint32_t num_chips, num_cpus;
     Error *local_err = NULL;
 
     visit_type_uint32(v, name, &num_chips, &local_err);
@@ -1724,6 +1725,13 @@  static void pnv_set_num_chips(Object *obj, Visitor *v, const char *name,
         return;
     }
 
+    num_cpus = num_chips * ms->smp.cores * ms->smp.threads;
+    if (num_cpus > ms->smp.max_cpus) {
+        error_setg(errp, "%d chips don't fit in the CPU topology", num_chips);
+        error_append_hint(errp, "Try -smp sockets=%d.\n", num_chips);
+        return;
+    }
+
     pnv->num_chips = num_chips;
 }