Skip to contentSkip to conversation

hw/arm/virt: max-cpus init/check fixup

PATCH In review Andrew Jones 6 participants 10 messages Oct 18, 2015 – Oct 26, 2015

lore
Share & tools
lore
#0 lore raw

v2 cover hw/arm/virt: max-cpus init/check fixup

Changes from v1
. drop the RFC patch "arm_gic_common.h: add gicv2 aliases for defines" [Peter] . add a patch to cleanup vl.c's max-cpu error message a little [Drew] . cleanup mach-virt's new error message [Peter]
. make the error message exactly like vl's cleaned up message [Drew] . add a comment to virt_class_init explaining that we'll further restrict
max_cpus later [Peter]

---

Sorry to be so late getting this simple v2 out. I was trying to get a new feature (qmp-dump-guest-memory support for arm) posted before the 2.5 soft freeze (but missed that anyway...)

Andrew Jones (2):
vl: trivial: minor tweaks to a max-cpu error msg hw/arm/virt: don't use a15memmap directly

 hw/arm/virt.c | 25 +++++++++++++++++++++----
 vl.c          |  4 ++--
 2 files changed, 23 insertions(+), 6 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/2 vl: trivial: minor tweaks to a max-cpu error msg

---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 7c806a2428399..9a64b75ebbd24 100644
@@ -4080,8 +4080,8 @@ int main(int argc, char **argv, char **envp)
 
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
     if (max_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", max_cpus,
+        fprintf(stderr, "Number of SMP CPUs requested (%d) exceeds max CPUs "
+                "supported by machine '%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }
Signature · 1 line
2.4.3
Reviewed-by Acked-by on v2 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: trivial: minor tweaks to a max-cpu error msg

Quoted 1 line · Andrew Jones

If this can go through my tree, please let me know.

Quoted 22 lines
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 7c806a2428399..9a64b75ebbd24 100644
@@ -4080,8 +4080,8 @@ int main(int argc, char **argv, char **envp)
 
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
     if (max_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", max_cpus,
+        fprintf(stderr, "Number of SMP CPUs requested (%d) exceeds max CPUs "
+                "supported by machine '%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }
Signature · 1 line
2.4.3
Signature · 1 line
Eduardo
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: trivial: minor tweaks to a max-cpu error msg

Quoted 7 lines · Eduardo Habkost
Quoted 1 line · Andrew Jones

If this can go through my tree, please let me know.

Sure, why not.

Paolo

Quoted 23 lines
Quoted 22 lines
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 7c806a2428399..9a64b75ebbd24 100644
@@ -4080,8 +4080,8 @@ int main(int argc, char **argv, char **envp)
 
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
     if (max_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", max_cpus,
+        fprintf(stderr, "Number of SMP CPUs requested (%d) exceeds max CPUs "
+                "supported by machine '%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }
Signature · 1 line
2.4.3
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: trivial: minor tweaks to a max-cpu error msg

In reply to Andrew Jones
Quoted 10 lines · Andrew Jones
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +0 -0
index 7c806a2428399..9a64b75ebbd24 100644

vl.c int main(int argc, char **argv, char **envp) · line 4087

Quoted 10 lines
vl.c +2 -2
@@ -4080,8 +4080,8 @@ int main(int argc, char **argv, char **envp)
 
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
     if (max_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", max_cpus,
+        fprintf(stderr, "Number of SMP CPUs requested (%d) exceeds max CPUs "
+                "supported by machine '%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }

While you're touching this, error_report(), please.

#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: trivial: minor tweaks to a max-cpu error msg

Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Andrew Jones
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +0 -0
index 7c806a2428399..9a64b75ebbd24 100644
@@ -4080,8 +4080,8 @@ int main(int argc, char **argv, char **envp)
 
Quoted 12 lines

vl.c int main(int argc, char **argv, char **envp) · line 4087

Quoted 9 lines
vl.c +2 -2
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
     if (max_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", max_cpus,
+        fprintf(stderr, "Number of SMP CPUs requested (%d) exceeds max CPUs "
+                "supported by machine '%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }

While you're touching this, error_report(), please.

Good call. Eduardo, I'll send you a v2 now.

drew

#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: trivial: minor tweaks to a max-cpu error msg

Quoted 27 lines · Andrew Jones
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Andrew Jones
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +0 -0
index 7c806a2428399..9a64b75ebbd24 100644
@@ -4080,8 +4080,8 @@ int main(int argc, char **argv, char **envp)
 
Quoted 12 lines

vl.c int main(int argc, char **argv, char **envp) · line 4087

Quoted 9 lines
vl.c +2 -2
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
     if (max_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", max_cpus,
+        fprintf(stderr, "Number of SMP CPUs requested (%d) exceeds max CPUs "
+                "supported by machine '%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }

While you're touching this, error_report(), please.

Quoted 1 line

Good call. Eduardo, I'll send you a v2 now.

v1 was already merged, as it was an improvement anyway. A separate patch to use error_report() will be welcome, though.

Signature · 1 line
Eduardo
#7 lore raw

PATCH v2 2/2 hw/arm/virt: don't use a15memmap directly

In reply to Andrew Jones

We should always go through VirtBoardInfo when we need the memmap. To avoid using a15memmap directly, in this case, we need to defer the max-cpus check from class init time to instance init time. In class init we now use MAX_CPUMASK_BITS for max_cpus initialization, which is the maximum QEMU supports, and also, incidentally, the maximum KVM/gicv3 currently supports. Also, a nice side-effect of delaying the max-cpus check is that we now get more appropriate error messages for gicv2 machines that try to configure more than 123 cpus. Before this patch it would complain that the requested number of cpus was greater than 123, but for gicv2 configs, it should complain that the number is greater than 8.

---
 hw/arm/virt.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
hw/arm/virt.c +21 -4
index 4e7160ce96997..8ec346f8fda3e 100644
@@ -923,7 +923,7 @@ static void machvirt_init(MachineState *machine)
     qemu_irq pic[NUM_IRQS];
     MemoryRegion *sysmem = get_system_memory();
     int gic_version = vms->gic_version;
-    int n;
+    int n, max_cpus;
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     const char *cpu_model = machine->cpu_model;
     VirtBoardInfo *vbi;
@@ -957,6 +957,22 @@ static void machvirt_init(MachineState *machine)
         exit(1);
     }
 
+    /* The maximum number of CPUs depends on the GIC version, or on how
+     * many redistributors we can fit into the memory map.
+     */
+    if (gic_version == 3) {
+        max_cpus = vbi->memmap[VIRT_GIC_REDIST].size / 0x20000;
+    } else {
+        max_cpus = GIC_NCPU;
+    }
+
+    if (smp_cpus > max_cpus) {
+        error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
+                     "supported by machine 'mach-virt' (%d)",
+                     smp_cpus, max_cpus);
+        exit(1);
+    }
+
     vbi->smp_cpus = smp_cpus;
 
     if (machine->ram_size > vbi->memmap[VIRT_MEM].size) {
@@ -1155,10 +1171,11 @@ static void virt_class_init(ObjectClass *oc, void *data)
 
     mc->desc = "ARM Virtual Machine",
     mc->init = machvirt_init;
-    /* Our maximum number of CPUs depends on how many redistributors
-     * we can fit into memory map
+    /* Start max_cpus at the maximum QEMU supports. We'll further restrict
+     * it later in machvirt_init, where we have more information about the
+     * configuration of the particular instance.
      */
-    mc->max_cpus = a15memmap[VIRT_GIC_REDIST].size / 0x20000;
+    mc->max_cpus = MAX_CPUMASK_BITS;
     mc->has_dynamic_sysbus = true;
     mc->block_default_type = IF_VIRTIO;
     mc->no_cdrom = 1;
Signature · 1 line
2.4.3
#8 lore raw
In reply to Andrew Jones
Quoted 8 lines · Andrew Jones

Changes from v1
. drop the RFC patch "arm_gic_common.h: add gicv2 aliases for defines" [Peter] . add a patch to cleanup vl.c's max-cpu error message a little [Drew] . cleanup mach-virt's new error message [Peter]
. make the error message exactly like vl's cleaned up message [Drew] . add a comment to virt_class_init explaining that we'll further restrict
max_cpus later [Peter]

Quoted 5 lines

---

Sorry to be so late getting this simple v2 out. I was trying to get a new feature (qmp-dump-guest-memory support for arm) posted before the 2.5 soft freeze (but missed that anyway...)

(off-topic)

When you do that, please consider extending the
"scripts/dump-guest-memory.py" script as well.

(This is not even a "nice to have" request -- the script already doesn't support all the target arches on which the QMP command is available (it only supports x86_64), so nothing is lost if you don't extend the script. My only goal is to put the thought in your mind; you decide :))

Thanks!
Laszlo

Quoted 9 lines

Andrew Jones (2):
vl: trivial: minor tweaks to a max-cpu error msg hw/arm/virt: don't use a15memmap directly

 hw/arm/virt.c | 25 +++++++++++++++++++++----
 vl.c          |  4 ++--
 2 files changed, 23 insertions(+), 6 deletions(-)
#9 lore raw
In reply to Andrew Jones
Quoted 10 lines · Andrew Jones

Changes from v1
. drop the RFC patch "arm_gic_common.h: add gicv2 aliases for defines" [Peter] . add a patch to cleanup vl.c's max-cpu error message a little [Drew] . cleanup mach-virt's new error message [Peter]
. make the error message exactly like vl's cleaned up message [Drew] . add a comment to virt_class_init explaining that we'll further restrict
max_cpus later [Peter]

---

Quoted 7 lines

Sorry to be so late getting this simple v2 out. I was trying to get a new feature (qmp-dump-guest-memory support for arm) posted before the 2.5 soft freeze (but missed that anyway...)

Andrew Jones (2):
vl: trivial: minor tweaks to a max-cpu error msg hw/arm/virt: don't use a15memmap directly

Thanks; applied patch 2/2 to target-arm.next, since Eduardo said he would take 1/2 through his tree.

-- PMM