Skip to contentSkip to conversation

hw/arm/cortex-a: Check for CPU types in machine_run_board_init()

PATCH Superseded Philippe Mathieu-Daudé 3 participants 20 messages Jan 23, 2024 – Jan 25, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover hw/arm/cortex-a: Check for CPU types in machine_run_board_init()

Since v1:
- Add missing QOM parent for CPU cores
- Dropped Aspeed changes (Cédric)

Following Gavin recent CPU type enforcement cleanups, restrict more single-CPU ARM machines (here Cortex-A SoC).

Based-on: <[email protected]> (arm-next)

Philippe Mathieu-Daudé (6):
hw/arm/exynos: Add missing QOM parent for CPU cores hw/arm/exynos: Check for CPU types in machine_run_board_init() hw/arm/highbank: Add missing QOM parent for CPU cores hw/arm/highbank: Check for CPU types in machine_run_board_init() hw/arm/vexpress: Check for CPU types in machine_run_board_init() hw/arm/zynq: Check for CPU types in machine_run_board_init()

 hw/arm/exynos4210.c     |  1 +
 hw/arm/exynos4_boards.c |  8 ++++++++
 hw/arm/highbank.c       | 11 +++++++++++
 hw/arm/vexpress.c       | 10 ++++++++++
 hw/arm/xilinx_zynq.c    |  5 +++++
 5 files changed, 35 insertions(+)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/6 hw/arm/exynos: Add missing QOM parent for CPU cores

QDev objects created with qdev_new() need to manually add their parent relationship with object_property_add_child().

---
 hw/arm/exynos4210.c | 1 +
 1 file changed, 1 insertion(+)
hw/arm/exynos4210.c +1 -0
index 6c428d8eeb..57c77b140c 100644
@@ -556,6 +556,7 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
     for (n = 0; n < EXYNOS4210_NCPUS; n++) {
         Object *cpuobj = object_new(ARM_CPU_TYPE_NAME("cortex-a9"));
 
+        object_property_add_child(OBJECT(s), "cpu[*]", cpuobj);
         /* By default A9 CPUs have EL3 enabled.  This board does not currently
          * support EL3 so the CPU EL3 property is disabled before realization.
          */
Signature · 1 line
2.41.0
#4 lore raw

PATCH v2 2/6 hw/arm/exynos: Check for CPU types in machine_run_board_init()

In reply to Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU type.

Instead of ignoring invalid CPU type requested by the user:

  $ qemu-system-arm -M nuri -cpu cortex-a7 -S -monitor stdio
  QEMU 8.2.50 monitor - type 'help' for more information
  (qemu) info qom-tree
  /machine (nuri-machine)
    /soc (exynos4210)
      /cpu[0] (cortex-a9-arm-cpu)
      ...

We now display an error:

  $ qemu-system-arm -M nuri -cpu cortex-a7
  qemu-system-arm: Invalid CPU model: cortex-a7
  The only valid type is: cortex-a9
---
 hw/arm/exynos4_boards.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/arm/exynos4_boards.c +8 -0
index b0e13eb4f0..01c7618a67 100644
@@ -34,6 +34,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/boards.h"
 #include "hw/irq.h"
+#include "target/arm/cpu-qom.h"
 
 #define SMDK_LAN9118_BASE_ADDR      0x05000000
 
@@ -150,12 +151,18 @@ static void smdkc210_init(MachineState *machine)
     arm_load_kernel(s->soc.cpu[0], machine, &exynos4_board_binfo);
 }
 
+static const char * const valid_cpu_types[] = {
+    ARM_CPU_TYPE_NAME("cortex-a9"),
+    NULL
+};
+
 static void nuri_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
     mc->desc = "Samsung NURI board (Exynos4210)";
     mc->init = nuri_init;
+    mc->valid_cpu_types = valid_cpu_types;
     mc->max_cpus = EXYNOS4210_NCPUS;
     mc->min_cpus = EXYNOS4210_NCPUS;
     mc->default_cpus = EXYNOS4210_NCPUS;
@@ -174,6 +181,7 @@ static void smdkc210_class_init(ObjectClass *oc, void *data)
 
     mc->desc = "Samsung SMDKC210 board (Exynos4210)";
     mc->init = smdkc210_init;
+    mc->valid_cpu_types = valid_cpu_types;
     mc->max_cpus = EXYNOS4210_NCPUS;
     mc->min_cpus = EXYNOS4210_NCPUS;
     mc->default_cpus = EXYNOS4210_NCPUS;
Signature · 1 line
2.41.0
Reviewed-by on v2 2/6
#5 lore raw

Re: [PATCH v2 2/6] hw/arm/exynos: Check for CPU types in machine_run_board_init()

Quoted 15 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU type.

Instead of ignoring invalid CPU type requested by the user:

   $ qemu-system-arm -M nuri -cpu cortex-a7 -S -monitor stdio
   QEMU 8.2.50 monitor - type 'help' for more information
   (qemu) info qom-tree
   /machine (nuri-machine)
     /soc (exynos4210)
       /cpu[0] (cortex-a9-arm-cpu)
       ...

We now display an error:

Quoted 8 lines
   $ qemu-system-arm -M nuri -cpu cortex-a7
   qemu-system-arm: Invalid CPU model: cortex-a7
   The only valid type is: cortex-a9
---
  hw/arm/exynos4_boards.c | 8 ++++++++
  1 file changed, 8 insertions(+)

r~

Reviewed-by on v2 2/6
#6 lore raw

Re: [PATCH v2 2/6] hw/arm/exynos: Check for CPU types in machine_run_board_init()

In reply to Philippe Mathieu-Daudé
Quoted 15 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU type.

Instead of ignoring invalid CPU type requested by the user:

   $ qemu-system-arm -M nuri -cpu cortex-a7 -S -monitor stdio
   QEMU 8.2.50 monitor - type 'help' for more information
   (qemu) info qom-tree
   /machine (nuri-machine)
     /soc (exynos4210)
       /cpu[0] (cortex-a9-arm-cpu)
       ...

We now display an error:

Quoted 9 lines
   $ qemu-system-arm -M nuri -cpu cortex-a7
   qemu-system-arm: Invalid CPU model: cortex-a7
   The only valid type is: cortex-a9
---
  hw/arm/exynos4_boards.c | 8 ++++++++
  1 file changed, 8 insertions(+)
#7 lore raw

PATCH v2 3/6 hw/arm/highbank: Add missing QOM parent for CPU cores

In reply to Philippe Mathieu-Daudé

QDev objects created with qdev_new() need to manually add their parent relationship with object_property_add_child().

---
 hw/arm/highbank.c | 1 +
 1 file changed, 1 insertion(+)
hw/arm/highbank.c +1 -0
index e6e27d69af..b8d702c82c 100644
@@ -209,6 +209,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)
         cpuobj = object_new(machine->cpu_type);
         cpu = ARM_CPU(cpuobj);
 
+        object_property_add_child(OBJECT(machine), "cpu[*]", cpuobj);
         object_property_set_int(cpuobj, "psci-conduit", QEMU_PSCI_CONDUIT_SMC,
                                 &error_abort);
 
Signature · 1 line
2.41.0
#10 lore raw

PATCH v2 4/6 hw/arm/highbank: Check for CPU types in machine_run_board_init()

In reply to Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU types.

Instead of ignoring invalid CPU type requested by the user:

  $ qemu-system-arm -M midway -cpu cortex-a7 -S -monitor stdio
  QEMU 8.2.50 monitor - type 'help' for more information
  (qemu) info qom-tree
  /machine (midway-machine)
    /cpu[0] (cortex-a15-arm-cpu)
    ...

we now display an error:

  $ qemu-system-arm -M midway -cpu cortex-a7
  qemu-system-arm: Invalid CPU model: cortex-a7
  The only valid type is: cortex-a15
---
 hw/arm/highbank.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/arm/highbank.c +10 -0
index b8d702c82c..0367050697 100644
@@ -345,10 +345,15 @@ static void midway_init(MachineState *machine)
 
 static void highbank_class_init(ObjectClass *oc, void *data)
 {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a9"),
+        NULL
+    };
     MachineClass *mc = MACHINE_CLASS(oc);
 
     mc->desc = "Calxeda Highbank (ECX-1000)";
     mc->init = highbank_init;
+    mc->valid_cpu_types = valid_cpu_types;
     mc->block_default_type = IF_IDE;
     mc->units_per_default_bus = 1;
     mc->max_cpus = 4;
@@ -364,10 +369,15 @@ static const TypeInfo highbank_type = {
 
 static void midway_class_init(ObjectClass *oc, void *data)
 {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a15"),
+        NULL
+    };
     MachineClass *mc = MACHINE_CLASS(oc);
 
     mc->desc = "Calxeda Midway (ECX-2000)";
     mc->init = midway_init;
+    mc->valid_cpu_types = valid_cpu_types;
     mc->block_default_type = IF_IDE;
     mc->units_per_default_bus = 1;
     mc->max_cpus = 4;
Signature · 1 line
2.41.0
Reviewed-by on v2 4/6
#11 lore raw

Re: [PATCH v2 4/6] hw/arm/highbank: Check for CPU types in machine_run_board_init()

Quoted 14 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU types.

Instead of ignoring invalid CPU type requested by the user:

   $ qemu-system-arm -M midway -cpu cortex-a7 -S -monitor stdio
   QEMU 8.2.50 monitor - type 'help' for more information
   (qemu) info qom-tree
   /machine (midway-machine)
     /cpu[0] (cortex-a15-arm-cpu)
     ...

we now display an error:

Quoted 8 lines
   $ qemu-system-arm -M midway -cpu cortex-a7
   qemu-system-arm: Invalid CPU model: cortex-a7
   The only valid type is: cortex-a15
---
  hw/arm/highbank.c | 10 ++++++++++
  1 file changed, 10 insertions(+)

r~

Reviewed-by on v2 4/6
#12 lore raw

Re: [PATCH v2 4/6] hw/arm/highbank: Check for CPU types in machine_run_board_init()

In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU types.

Instead of ignoring invalid CPU type requested by the user:

   $ qemu-system-arm -M midway -cpu cortex-a7 -S -monitor stdio
   QEMU 8.2.50 monitor - type 'help' for more information
   (qemu) info qom-tree
   /machine (midway-machine)
     /cpu[0] (cortex-a15-arm-cpu)
     ...

we now display an error:

Quoted 9 lines
   $ qemu-system-arm -M midway -cpu cortex-a7
   qemu-system-arm: Invalid CPU model: cortex-a7
   The only valid type is: cortex-a15
---
  hw/arm/highbank.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
#13 lore raw

PATCH v2 5/6 hw/arm/vexpress: Check for CPU types in machine_run_board_init()

In reply to Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU types.

---
 hw/arm/vexpress.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/arm/vexpress.c +10 -0
index f1b45245d5..a3561a1b56 100644
@@ -783,22 +783,32 @@ static void vexpress_class_init(ObjectClass *oc, void *data)
 
 static void vexpress_a9_class_init(ObjectClass *oc, void *data)
 {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a9"),
+        NULL
+    };
     MachineClass *mc = MACHINE_CLASS(oc);
     VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc);
 
     mc->desc = "ARM Versatile Express for Cortex-A9";
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+    mc->valid_cpu_types = valid_cpu_types;
 
     vmc->daughterboard = &a9_daughterboard;
 }
 
 static void vexpress_a15_class_init(ObjectClass *oc, void *data)
 {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a15"),
+        NULL
+    };
     MachineClass *mc = MACHINE_CLASS(oc);
     VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc);
 
     mc->desc = "ARM Versatile Express for Cortex-A15";
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
+    mc->valid_cpu_types = valid_cpu_types;
 
     vmc->daughterboard = &a15_daughterboard;
 
Signature · 1 line
2.41.0
Reviewed-by on v2 5/6
#14 lore raw

Re: [PATCH v2 5/6] hw/arm/vexpress: Check for CPU types in machine_run_board_init()

Quoted 16 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU types.

---
  hw/arm/vexpress.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
hw/arm/vexpress.c +0 -0
index f1b45245d5..a3561a1b56 100644
@@ -783,22 +783,32 @@ static void vexpress_class_init(ObjectClass *oc, void *data)
 
  static void vexpress_a9_class_init(ObjectClass *oc, void *data)
  {

hw/arm/vexpress.c static void vexpress_class_init(ObjectClass *oc, void *data) · line 795

Quoted 10 lines
hw/arm/vexpress.c +5 -0
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a9"),
+        NULL
+    };
      MachineClass *mc = MACHINE_CLASS(oc);
      VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc);
 
      mc->desc = "ARM Versatile Express for Cortex-A9";
      mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+    mc->valid_cpu_types = valid_cpu_types;

Repetition of the cpu type here. Do you still need default_cpu_type?
I didn't see it in the highbank patch, but it might have been outside the patch context.

If it is needed, perhaps "default_cpu_type = valid_cpu_types[0]".

Otherwise,

r~

#15 lore raw

Re: [PATCH v2 5/6] hw/arm/vexpress: Check for CPU types in machine_run_board_init()

Quoted 30 lines · Richard Henderson
Quoted 15 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU types.

---
  hw/arm/vexpress.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
hw/arm/vexpress.c +0 -0
index f1b45245d5..a3561a1b56 100644
@@ -783,22 +783,32 @@ static void vexpress_class_init(ObjectClass *oc, 
 void *data)
   static void vexpress_a9_class_init(ObjectClass *oc, void *data)

hw/arm/vexpress.c static void vexpress_class_init(ObjectClass *oc, · line 794

Quoted 10 lines
hw/arm/vexpress.c +5 -0
   {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a9"),
+        NULL
+    };
       MachineClass *mc = MACHINE_CLASS(oc);
       VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc);
       mc->desc = "ARM Versatile Express for Cortex-A9";
       mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+    mc->valid_cpu_types = valid_cpu_types;

Repetition of the cpu type here.  Do you still need default_cpu_type?
I didn't see it in the highbank patch, but it might have been outside the patch context.

Quoted 1 line

If it is needed, perhaps "default_cpu_type = valid_cpu_types[0]".

The plan is to eventually get there applying
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 2 lines

Otherwise,

Thanks!

#17 lore raw

PATCH v2 6/6 hw/arm/zynq: Check for CPU types in machine_run_board_init()

In reply to Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU type.

---
 hw/arm/xilinx_zynq.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/arm/xilinx_zynq.c +5 -0
index 66d0de139f..6ec65d4780 100644
@@ -355,6 +355,10 @@ static void zynq_init(MachineState *machine)
 
 static void zynq_machine_class_init(ObjectClass *oc, void *data)
 {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a9"),
+        NULL
+    };
     MachineClass *mc = MACHINE_CLASS(oc);
     mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
     mc->init = zynq_init;
@@ -362,6 +366,7 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
     mc->no_sdcard = 1;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+    mc->valid_cpu_types = valid_cpu_types;
     mc->default_ram_id = "zynq.ext_ram";
 }
 
Signature · 1 line
2.41.0
Reviewed-by on v2 6/6
#18 lore raw

Re: [PATCH v2 6/6] hw/arm/zynq: Check for CPU types in machine_run_board_init()

Quoted 24 lines · Philippe Mathieu-Daudé

Restrict MachineClass::valid_cpu_types[] to the single valid CPU type.

---
  hw/arm/xilinx_zynq.c | 5 +++++
  1 file changed, 5 insertions(+)
hw/arm/xilinx_zynq.c +4 -0
index 66d0de139f..6ec65d4780 100644
@@ -355,6 +355,10 @@ static void zynq_init(MachineState *machine)
 
  static void zynq_machine_class_init(ObjectClass *oc, void *data)
  {
+    static const char * const valid_cpu_types[] = {
+        ARM_CPU_TYPE_NAME("cortex-a9"),
+        NULL
+    };
      MachineClass *mc = MACHINE_CLASS(oc);
      mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
      mc->init = zynq_init;

hw/arm/xilinx_zynq.c static void zynq_machine_class_init(ObjectClass *oc, void *data) · line 369

Quoted 4 lines
hw/arm/xilinx_zynq.c +1 -0
@@ -362,6 +366,7 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
      mc->no_sdcard = 1;
      mc->ignore_memory_transaction_failures = true;
      mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+    mc->valid_cpu_types = valid_cpu_types;

Same comment re default_cpu_type. Otherwise,

r~