hw/arm: Check for CPU types in machine_run_board_init()
v3 cover hw/arm: Check for CPU types in machine_run_board_init()
Series fully reviewed.
Since v2:
- Rebased
- Remove default_cpu_type (Richard)
- Added R-b tags
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.
Supersedes: <[email protected]>
Philippe Mathieu-Daudé (9):
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/msf2: Simplify setting MachineClass::valid_cpu_types[] hw/arm/musca: Simplify setting MachineClass::valid_cpu_types[] hw/arm/npcm7xx_boards: Simplify setting
MachineClass::valid_cpu_types[]
hw/arm/vexpress: Check for CPU types in machine_run_board_init() hw/arm/zynq: Check for CPU types in machine_run_board_init()
include/hw/arm/msf2-soc.h | 3 --- hw/arm/exynos4210.c | 1 + hw/arm/exynos4_boards.c | 8 ++++++++ hw/arm/highbank.c | 11 +++++++++++ hw/arm/msf2-soc.c | 3 +-- hw/arm/msf2-som.c | 4 ---- hw/arm/musca.c | 1 - hw/arm/npcm7xx_boards.c | 1 - hw/arm/vexpress.c | 12 ++++++++++-- hw/arm/xilinx_zynq.c | 6 +++++- 10 files changed, 36 insertions(+), 14 deletions(-)
Signature · 1 line
2.41.0
PATCH v3 1/9 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
@@ -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
PATCH v3 2/9 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
@@ -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
PATCH v3 3/9 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
@@ -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
PATCH v3 4/9 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
@@ -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
PATCH v3 5/9 hw/arm/msf2: Simplify setting MachineClass::valid_cpu_types[]
In reply to Philippe Mathieu-DaudéThe M2Sxxx SoC family can only be used with Cortex-M3. Propagating the CPU type from the board level is pointless.
Hard-code the CPU type at the SoC level.
Remove the now ignored MachineClass::default_cpu_type field.
Use the common code introduced in commit c9cf636d48 ("machine: Add a valid_cpu_types property") to check for valid CPU type at the board level.
--- include/hw/arm/msf2-soc.h | 3 --- hw/arm/msf2-soc.c | 3 +-- hw/arm/msf2-som.c | 4 ---- 3 files changed, 1 insertion(+), 9 deletions(-)
include/hw/arm/msf2-soc.h +0 -3
@@ -47,13 +47,10 @@ OBJECT_DECLARE_SIMPLE_TYPE(MSF2State, MSF2_SOC)#define MSF2_NUM_TIMERS 2struct MSF2State { -/*< private >*/ SysBusDevice parent_obj; -/*< public >*/ ARMv7MState armv7m; -char *cpu_type;char *part_name;uint64_t envm_size;uint64_t esram_size;
hw/arm/msf2-soc.c +1 -2
@@ -134,7 +134,7 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) armv7m =DEVICE (&s->armv7m);qdev_prop_set_uint32 (armv7m,"num-irq" ,81 ); -qdev_prop_set_string (armv7m,"cpu-type" , s->cpu_type); +qdev_prop_set_string (armv7m,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m3" ));qdev_prop_set_bit (armv7m,"enable-bitband" , true);qdev_connect_clock_in (armv7m,"cpuclk" , s->m3clk);qdev_connect_clock_in (armv7m,"refclk" , s->refclk);
@@ -231,7 +231,6 @@ static Property m2sxxx_soc_properties[] = {* part name specifies the type of SmartFusion2 device variant(this * property is for information purpose only. */ -DEFINE_PROP_STRING ("cpu-type" , MSF2State, cpu_type),DEFINE_PROP_STRING ("part-name" , MSF2State, part_name),DEFINE_PROP_UINT64 ("eNVM-size" , MSF2State, envm_size,MSF2_ENVM_MAX_SIZE ), DEFINE_PROP_UINT64("eSRAM-size", MSF2State, esram_size,
hw/arm/msf2-som.c +0 -4
@@ -47,7 +47,6 @@ static void emcraft_sf2_s2s010_init(MachineState *machine)DeviceState *dev;DeviceState *spi_flash;MSF2State *soc; -MachineClass *mc =MACHINE_GET_CLASS (machine);DriveInfo *dinfo =drive_get (IF_MTD ,0 ,0 );qemu_irq cs_line;BusState *spi_bus;
@@ -62,8 +61,6 @@ static void emcraft_sf2_s2s010_init(MachineState *machine) dev =qdev_new (TYPE_MSF2_SOC );object_property_add_child (OBJECT (machine),"soc" ,OBJECT (dev));qdev_prop_set_string (dev,"part-name" ,"M2S010" ); -qdev_prop_set_string (dev,"cpu-type" , mc->default_cpu_type); -qdev_prop_set_uint64 (dev,"eNVM-size" ,M2S010_ENVM_SIZE );qdev_prop_set_uint64 (dev,"eSRAM-size" ,M2S010_ESRAM_SIZE );
@@ -108,7 +105,6 @@ static void emcraft_sf2_machine_init(MachineClass *mc) mc->desc ="SmartFusion2 SOM kit from Emcraft (M2S010)" ; mc->init = emcraft_sf2_s2s010_init; - mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m3" ); mc->valid_cpu_types = valid_cpu_types; }
Signature · 1 line
2.41.0
PATCH v3 6/9 hw/arm/musca: Simplify setting MachineClass::valid_cpu_types[]
In reply to Philippe Mathieu-DaudéMusca boards use the embedded subsystems (SSE) tied to a specific Cortex core. Our models only use the Cortex-M33.
Use the common code introduced in commit c9cf636d48 ("machine: Add a valid_cpu_types property") to check for valid CPU type at the board level.
Remove the now unused MachineClass::default_cpu_type field.
--- hw/arm/musca.c | 1 - 1 file changed, 1 deletion(-)
hw/arm/musca.c +0 -1
@@ -605,7 +605,6 @@ static void musca_class_init(ObjectClass *oc, void *data) mc->default_cpus =2 ; mc->min_cpus = mc->default_cpus; mc->max_cpus = mc->default_cpus; - mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m33" ); mc->valid_cpu_types = valid_cpu_types; mc->init = musca_init; }
Signature · 1 line
2.41.0
PATCH v3 7/9 hw/arm/npcm7xx_boards: Simplify setting MachineClass::valid_cpu_types[]
In reply to Philippe Mathieu-DaudéThe npcm7xx Soc is created with a Cortex-A9 core, see in hw/arm/npcm7xx.c:
static void npcm7xx_init(Object *obj)
{
NPCM7xxState *s = NPCM7XX(obj); for (int i = 0; i < NPCM7XX_MAX_NUM_CPUS; i++) {
object_initialize_child(obj, "cpu[*]", &s->cpu[i],
ARM_CPU_TYPE_NAME("cortex-a9"));
}The MachineClass::default_cpu_type field is ignored: delete it.
Use the common code introduced in commit c9cf636d48 ("machine: Add a valid_cpu_types property") to check for valid CPU type at the board level.
--- hw/arm/npcm7xx_boards.c | 1 - 1 file changed, 1 deletion(-)
hw/arm/npcm7xx_boards.c +0 -1
@@ -465,7 +465,6 @@ static void npcm7xx_machine_class_init(ObjectClass *oc, void *data) mc->no_cdrom =1 ; mc->no_parallel =1 ; mc->default_ram_id ="ram" ; - mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a9" ); mc->valid_cpu_types = valid_cpu_types; }
Signature · 1 line
2.41.0
PATCH v3 8/9 hw/arm/vexpress: Check for CPU types in machine_run_board_init()
In reply to Philippe Mathieu-DaudéLeverage the common code introduced in commit c9cf636d48 ("machine:
Add a valid_cpu_types property") to check for the single valid CPU type. Remove the now unused MachineClass::default_cpu_type field.
--- hw/arm/vexpress.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
hw/arm/vexpress.c +10 -2
@@ -783,22 +783,30 @@ 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
PATCH v3 9/9 hw/arm/zynq: Check for CPU types in machine_run_board_init()
In reply to Philippe Mathieu-DaudéLeverage the common code introduced in commit c9cf636d48 ("machine:
Add a valid_cpu_types property") to check for the single valid CPU type. Remove the now unused MachineClass::default_cpu_type field.
--- hw/arm/xilinx_zynq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/arm/xilinx_zynq.c +5 -1
@@ -355,13 +355,17 @@ 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; mc->max_cpus =1 ; 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
Peter Maydell
AppliedQuoted 8 lines · Philippe Mathieu-Daudé
Series fully reviewed.
Since v2:
- Rebased
- Removedefault_cpu_type(Richard)
- Added R-b tags
Quoted 9 lines
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.
Supersedes: <[email protected]>
Applied to target-arm.next, thanks.
-- PMM