Skip to contentSkip to conversation

target-arm: Add CPU security extension enablement

PATCH Superseded Greg Bellows 2 participants 40 messages Dec 11, 2014 – Dec 15, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover target-arm: Add CPU security extension enablement

This patchset adds functionality for enabling the ARM CPU security extensions. At this time, the only machines supported are Versatile Express and the QEMU ARM virtual machines both with Cortex A9 & A15.

The patchset establishes the default security state along with adding overriding controls of the state. Booting with the "-kernel" QEMU command line option will start by default in non-secure state with EL3 support disabled. Booting with the "-bios" QEMU command line option will default to secure state with EL3 features enabled. An added "secure" machine property may be set to either 'on' or 'off' to override this default behavior. For example, the below command line syntax would enable security extensions...

aarch64-softmmu/qemu-system-aarch64
-machine type=vexpress-a15,secure=on -kernel ...

In order to add the machine specific 'secure' property, the vexpress machine object creation functionality needed to be updated. The existing QEMU machine mechanism was replaced with proper type, class, and instance usage.

v1 -> v2
- Added disablement of CPU EL3 on all machines that could potentially use an EL3 enabled CPU.
- Switched/Added default states for vexpress and virt machines
- Made the vexpress machine type abstract
- Removed static declaration of the machine property
- Renamed CPU "secure" property to "has_el3"
- Added arm_boot_info secure_boot field to communicate whether the secure state on a Linux boot needs to be updated. By default Vexpress defaults to secure and virt defaults to non-secure.

Fabian Aggeler (1):
target-arm: add cpu feature EL3 to CPUs with Security Extensions

Greg Bellows (14):
target-arm: Add vexpress class and machine types
target-arm: Add vexpress a9 & a15 machine objects
target-arm: Switch to common vexpress machine init
target-arm: Add vexpress machine secure property
target-arm: Change vexpress daughterboard init arg
target-arm: Add virt class and machine types
target-arm: Add virt machine secure property
target-arm: Add feature unset function
target-arm: Add ARMCPU secure property
target-arm: Add arm_boot_info secure_boot control
target-arm: Enable CPU has_el3 prop during VE init
target-arm: Set CPU has_el3 prop during virt init
target-arm: Breakout integratorcp and versatilepb cpu init
target-arm: Disable EL3 on unsupported machines

 hw/arm/boot.c         |  10 ++++
 hw/arm/exynos4210.c   |  11 ++++
 hw/arm/highbank.c     |  12 +++++
 hw/arm/integratorcp.c |  31 ++++++++++-
 hw/arm/realview.c     |  12 +++++
 hw/arm/versatilepb.c  |  32 ++++++++++-
 hw/arm/vexpress.c     | 145 ++++++++++++++++++++++++++++++++++++++++----------
 hw/arm/virt.c         |  82 +++++++++++++++++++++++++---
 hw/arm/xilinx_zynq.c  |  12 +++++
 include/hw/arm/arm.h  |   4 ++
 target-arm/cpu-qom.h  |   2 +
 target-arm/cpu.c      |  33 ++++++++++++
 12 files changed, 348 insertions(+), 38 deletions(-)

--
1.8.3.2

#1 lore raw

PATCH v2 1/15 target-arm: Add vexpress class and machine types

Adds base Vexpress class and machine objects and infrastructure. This is in preparation for switching to the full QEMU object model. The base vexpress infrastructure is intended to handle common vexpress details.

---

v1 -> v2
- Made the vexpress class abstract

---
 hw/arm/vexpress.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
hw/arm/vexpress.c +45 -0
index 7cbd13f..01046c2 100644
@@ -157,6 +157,23 @@ static hwaddr motherboard_aseries_map[] = {
 
 typedef struct VEDBoardInfo VEDBoardInfo;
 
+typedef struct {
+    MachineClass parent;
+    VEDBoardInfo *daughterboard;
+} VexpressMachineClass;
+
+typedef struct {
+    MachineState parent;
+} VexpressMachineState;
+
+#define TYPE_VEXPRESS_MACHINE   "vexpress"
+#define VEXPRESS_MACHINE(obj) \
+    OBJECT_CHECK(VexpressMachineState, (obj), TYPE_VEXPRESS_MACHINE)
+#define VEXPRESS_MACHINE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(VexpressMachineClass, obj, TYPE_VEXPRESS_MACHINE)
+#define VEXPRESS_MACHINE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(VexpressMachineClass, klass, TYPE_VEXPRESS_MACHINE)
+
 typedef void DBoardInitFn(const VEDBoardInfo *daughterboard,
                           ram_addr_t ram_size,
                           const char *cpu_model,
@@ -681,6 +698,13 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard,
     arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
 }
 
+static void vexpress_init(MachineState *machine)
+{
+    VexpressMachineClass *vmc = VEXPRESS_MACHINE_GET_CLASS(machine);
+
+    vexpress_common_init(vmc->daughterboard, machine);
+}
+
 static void vexpress_a9_init(MachineState *machine)
 {
     vexpress_common_init(&a9_daughterboard, machine);
@@ -691,6 +715,26 @@ static void vexpress_a15_init(MachineState *machine)
     vexpress_common_init(&a15_daughterboard, machine);
 }
 
+static void vexpress_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->name = TYPE_VEXPRESS_MACHINE;
+    mc->desc = "ARM Versatile Express";
+    mc->init = vexpress_init;
+    mc->block_default_type = IF_SCSI;
+    mc->max_cpus = 4;
+}
+
+static const TypeInfo vexpress_info = {
+    .name = TYPE_VEXPRESS_MACHINE,
+    .parent = TYPE_MACHINE,
+    .abstract = true,
+    .instance_size = sizeof(VexpressMachineState),
+    .class_size = sizeof(VexpressMachineClass),
+    .class_init = vexpress_class_init,
+};
+
 static QEMUMachine vexpress_a9_machine = {
     .name = "vexpress-a9",
     .desc = "ARM Versatile Express for Cortex-A9",
@@ -709,6 +753,7 @@ static QEMUMachine vexpress_a15_machine = {
 
 static void vexpress_machine_init(void)
 {
+    type_register_static(&vexpress_info);
     qemu_register_machine(&vexpress_a9_machine);
     qemu_register_machine(&vexpress_a15_machine);
 }
Signature · 1 line
1.8.3.2
Reviewed-by on v2 1/15
#2 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] target-arm: Add vexpress class and machine types

Quoted 5 lines · Greg Bellows

Adds base Vexpress class and machine objects and infrastructure. This is in preparation for switching to the full QEMU object model. The base vexpress infrastructure is intended to handle common vexpress details.

thanks
-- PMM

#3 lore raw

PATCH v2 2/15 target-arm: Add vexpress a9 & a15 machine objects

In reply to Greg Bellows

Add Vexpress machine objects for the the Cortex A9 & A15 variants. The older style QEMUMachine types were replaced with dedicated TypeInfo objects. The new objects include dedicated class init functions that currently ustilze dedicated machine init methods. The previous qemu_register_machine calls were replaced with the newer type_register_status calls.

---
 hw/arm/vexpress.c | 50 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 14 deletions(-)
hw/arm/vexpress.c +36 -14
index 01046c2..8f22696 100644
@@ -167,6 +167,8 @@ typedef struct {
 } VexpressMachineState;
 
 #define TYPE_VEXPRESS_MACHINE   "vexpress"
+#define TYPE_VEXPRESS_A9_MACHINE   "vexpress-a9"
+#define TYPE_VEXPRESS_A15_MACHINE   "vexpress-a15"
 #define VEXPRESS_MACHINE(obj) \
     OBJECT_CHECK(VexpressMachineState, (obj), TYPE_VEXPRESS_MACHINE)
 #define VEXPRESS_MACHINE_GET_CLASS(obj) \
@@ -726,6 +728,30 @@ static void vexpress_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = 4;
 }
 
+static void vexpress_a9_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc);
+
+    mc->name = TYPE_VEXPRESS_A9_MACHINE;
+    mc->desc = "ARM Versatile Express for Cortex-A9";
+    mc->init = vexpress_a9_init;
+
+    vmc->daughterboard = &a9_daughterboard;;
+}
+
+static void vexpress_a15_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc);
+
+    mc->name = TYPE_VEXPRESS_A15_MACHINE;
+    mc->desc = "ARM Versatile Express for Cortex-A15";
+    mc->init = vexpress_a15_init;
+
+    vmc->daughterboard = &a15_daughterboard;
+}
+
 static const TypeInfo vexpress_info = {
     .name = TYPE_VEXPRESS_MACHINE,
     .parent = TYPE_MACHINE,
@@ -735,27 +761,23 @@ static const TypeInfo vexpress_info = {
     .class_init = vexpress_class_init,
 };
 
-static QEMUMachine vexpress_a9_machine = {
-    .name = "vexpress-a9",
-    .desc = "ARM Versatile Express for Cortex-A9",
-    .init = vexpress_a9_init,
-    .block_default_type = IF_SCSI,
-    .max_cpus = 4,
+static const TypeInfo vexpress_a9_info = {
+    .name = TYPE_VEXPRESS_A9_MACHINE,
+    .parent = TYPE_VEXPRESS_MACHINE,
+    .class_init = vexpress_a9_class_init,
 };
 
-static QEMUMachine vexpress_a15_machine = {
-    .name = "vexpress-a15",
-    .desc = "ARM Versatile Express for Cortex-A15",
-    .init = vexpress_a15_init,
-    .block_default_type = IF_SCSI,
-    .max_cpus = 4,
+static const TypeInfo vexpress_a15_info = {
+    .name = TYPE_VEXPRESS_A15_MACHINE,
+    .parent = TYPE_VEXPRESS_MACHINE,
+    .class_init = vexpress_a15_class_init,
 };
 
 static void vexpress_machine_init(void)
 {
     type_register_static(&vexpress_info);
-    qemu_register_machine(&vexpress_a9_machine);
-    qemu_register_machine(&vexpress_a15_machine);
+    type_register_static(&vexpress_a9_info);
+    type_register_static(&vexpress_a15_info);
 }
 
 machine_init(vexpress_machine_init);
Signature · 1 line
1.8.3.2
Reviewed-by on v2 2/15
#4 lore raw

Re: [Qemu-devel] [PATCH v2 02/15] target-arm: Add vexpress a9 & a15 machine objects

Quoted 7 lines · Greg Bellows

Add Vexpress machine objects for the the Cortex A9 & A15 variants. The older style QEMUMachine types were replaced with dedicated TypeInfo objects. The new objects include dedicated class init functions that currently ustilze dedicated machine init methods. The previous qemu_register_machine calls were replaced with the newer type_register_status calls.

thanks
-- PMM

#5 lore raw

PATCH v2 3/15 target-arm: Switch to common vexpress machine init

In reply to Greg Bellows

Switched the Vexpress machine initialization to use the common function with the machine pointer to board info.

---
 hw/arm/vexpress.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)
hw/arm/vexpress.c +4 -22
index 8f22696..a03cb52 100644
@@ -532,9 +532,10 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
     return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
 }
 
-static void vexpress_common_init(VEDBoardInfo *daughterboard,
-                                 MachineState *machine)
+static void vexpress_common_init(MachineState *machine)
 {
+    VexpressMachineClass *vmc = VEXPRESS_MACHINE_GET_CLASS(machine);
+    VEDBoardInfo *daughterboard = vmc->daughterboard;;
     DeviceState *dev, *sysctl, *pl041;
     qemu_irq pic[64];
     uint32_t sys_id;
@@ -700,30 +701,13 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard,
     arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
 }
 
-static void vexpress_init(MachineState *machine)
-{
-    VexpressMachineClass *vmc = VEXPRESS_MACHINE_GET_CLASS(machine);
-
-    vexpress_common_init(vmc->daughterboard, machine);
-}
-
-static void vexpress_a9_init(MachineState *machine)
-{
-    vexpress_common_init(&a9_daughterboard, machine);
-}
-
-static void vexpress_a15_init(MachineState *machine)
-{
-    vexpress_common_init(&a15_daughterboard, machine);
-}
-
 static void vexpress_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
     mc->name = TYPE_VEXPRESS_MACHINE;
     mc->desc = "ARM Versatile Express";
-    mc->init = vexpress_init;
+    mc->init = vexpress_common_init;
     mc->block_default_type = IF_SCSI;
     mc->max_cpus = 4;
 }
@@ -735,7 +719,6 @@ static void vexpress_a9_class_init(ObjectClass *oc, void *data)
 
     mc->name = TYPE_VEXPRESS_A9_MACHINE;
     mc->desc = "ARM Versatile Express for Cortex-A9";
-    mc->init = vexpress_a9_init;
 
     vmc->daughterboard = &a9_daughterboard;;
 }
@@ -747,7 +730,6 @@ static void vexpress_a15_class_init(ObjectClass *oc, void *data)
 
     mc->name = TYPE_VEXPRESS_A15_MACHINE;
     mc->desc = "ARM Versatile Express for Cortex-A15";
-    mc->init = vexpress_a15_init;
 
     vmc->daughterboard = &a15_daughterboard;
 }
Signature · 1 line
1.8.3.2
#7 lore raw

PATCH v2 4/15 target-arm: Add vexpress machine secure property

In reply to Greg Bellows

Add "secure" Vexpress machine specific property to allow override of the default secure state configuration. By default, when using the QEMU -kernel command line argument, Vexpress machines boot into NS/SVC. When using the QEMU -bios command line argument, Vexpress machines boot into S/SVC.

The secure state can be changed from the default specifying the secure state as a machine property. For example, the below command line would enable secure state on a -linux boot:

    aarch64-softmmu/qemu-system-aarch64
        -machine type=vexpress-a15,secure=on
        -kernel ...

---

v1 -> v2
- Adapt the machine secure property to Marcel's new dynamic registration
- Change the default machine secure property to true (on).

---
 hw/arm/vexpress.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
hw/arm/vexpress.c +29 -0
index a03cb52..7b34f44 100644
@@ -164,6 +164,7 @@ typedef struct {
 
 typedef struct {
     MachineState parent;
+    bool secure;
 } VexpressMachineState;
 
 #define TYPE_VEXPRESS_MACHINE   "vexpress"
@@ -701,6 +702,33 @@ static void vexpress_common_init(MachineState *machine)
     arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
 }
 
+static bool vexpress_get_secure(Object *obj, Error **errp)
+{
+    VexpressMachineState *vms = VEXPRESS_MACHINE(obj);
+
+    return vms->secure;
+}
+
+static void vexpress_set_secure(Object *obj, bool value, Error **errp)
+{
+    VexpressMachineState *vms = VEXPRESS_MACHINE(obj);
+
+    vms->secure = value;
+}
+
+static void vexpress_instance_init(Object *obj)
+{
+    VexpressMachineState *vms = VEXPRESS_MACHINE(obj);
+
+    /* EL3 is enabled by default on vexpress */
+    vms->secure = true;
+    object_property_add_bool(obj, "secure", vexpress_get_secure,
+                             vexpress_set_secure, NULL);
+    object_property_set_description(obj, "secure",
+                             "Set on/off to enable/disable secure state",
+                             NULL);
+}
+
 static void vexpress_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -739,6 +767,7 @@ static const TypeInfo vexpress_info = {
     .parent = TYPE_MACHINE,
     .abstract = true,
     .instance_size = sizeof(VexpressMachineState),
+    .instance_init = vexpress_instance_init,
     .class_size = sizeof(VexpressMachineClass),
     .class_init = vexpress_class_init,
 };
Signature · 1 line
1.8.3.2
Reviewed-by on v2 4/15
#8 lore raw

Re: [Qemu-devel] [PATCH v2 04/15] target-arm: Add vexpress machine secure property

Quoted 5 lines · Greg Bellows

Add "secure" Vexpress machine specific property to allow override of the default secure state configuration. By default, when using the QEMU -kernel command line argument, Vexpress machines boot into NS/SVC. When using the QEMU -bios command line argument, Vexpress machines boot into S/SVC.

Quoted 7 lines

The secure state can be changed from the default specifying the secure state as a machine property. For example, the below command line would enable secure state on a -linux boot:

    aarch64-softmmu/qemu-system-aarch64
        -machine type=vexpress-a15,secure=on
        -kernel ...

This example's a bit odd because "on" is the default.

Quoted 1 line

thanks
-- PMM

#9 lore raw

Re: [Qemu-devel] [PATCH v2 04/15] target-arm: Add vexpress machine secure property

Quoted 11 lines · Peter Maydell
Quoted 3 lines · Greg Bellows

Add "secure" Vexpress machine specific property to allow override of the default secure state configuration. By default, when using the QEMU -kernel command line argument, Vexpress machines boot into NS/SVC. When

using

Quoted 4 lines

the QEMU -bios command line argument, Vexpress machines boot into S/SVC.

The secure state can be changed from the default specifying the secure state as a machine property. For example, the below command line would

Quoted 10 lines

enable

Quoted 5 lines

secure state on a -linux boot:

    aarch64-softmmu/qemu-system-aarch64
        -machine type=vexpress-a15,secure=on
        -kernel ...

This example's a bit odd because "on" is the default.

Whoops, yes it is. Changed to "off"

Quoted 7 lines
Quoted 1 line

thanks
-- PMM

#10 lore raw

PATCH v2 5/15 target-arm: Change vexpress daughterboard init arg

In reply to Greg Bellows

Change the Vexpress daughterboard initialization method to take a vexpress machine state pointer instead of the daughterboard struct pointer. The machine state now contains the daughterboard pointer.

---
 hw/arm/vexpress.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/arm/vexpress.c +5 -5
index 7b34f44..c82c32e 100644
@@ -177,7 +177,7 @@ typedef struct {
 #define VEXPRESS_MACHINE_CLASS(klass) \
     OBJECT_CLASS_CHECK(VexpressMachineClass, klass, TYPE_VEXPRESS_MACHINE)
 
-typedef void DBoardInitFn(const VEDBoardInfo *daughterboard,
+typedef void DBoardInitFn(const VexpressMachineState *machine,
                           ram_addr_t ram_size,
                           const char *cpu_model,
                           qemu_irq *pic);
@@ -252,7 +252,7 @@ static void init_cpus(const char *cpu_model, const char *privdev,
     }
 }
 
-static void a9_daughterboard_init(const VEDBoardInfo *daughterboard,
+static void a9_daughterboard_init(const VexpressMachineState *vms,
                                   ram_addr_t ram_size,
                                   const char *cpu_model,
                                   qemu_irq *pic)
@@ -342,7 +342,7 @@ static VEDBoardInfo a9_daughterboard = {
     .init = a9_daughterboard_init,
 };
 
-static void a15_daughterboard_init(const VEDBoardInfo *daughterboard,
+static void a15_daughterboard_init(const VexpressMachineState *vms,
                                    ram_addr_t ram_size,
                                    const char *cpu_model,
                                    qemu_irq *pic)
@@ -535,6 +535,7 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
 
 static void vexpress_common_init(MachineState *machine)
 {
+    VexpressMachineState *vms = VEXPRESS_MACHINE(machine);
     VexpressMachineClass *vmc = VEXPRESS_MACHINE_GET_CLASS(machine);
     VEDBoardInfo *daughterboard = vmc->daughterboard;;
     DeviceState *dev, *sysctl, *pl041;
@@ -551,8 +552,7 @@ static void vexpress_common_init(MachineState *machine)
     const hwaddr *map = daughterboard->motherboard_map;
     int i;
 
-    daughterboard->init(daughterboard, machine->ram_size, machine->cpu_model,
-                        pic);
+    daughterboard->init(vms, machine->ram_size, machine->cpu_model, pic);
 
     /*
      * If a bios file was provided, attempt to map it into memory
Signature · 1 line
1.8.3.2
Reviewed-by on v2 5/15
#11 lore raw

Re: [Qemu-devel] [PATCH v2 05/15] target-arm: Change vexpress daughterboard init arg

Quoted 5 lines · Greg Bellows

Change the Vexpress daughterboard initialization method to take a vexpress machine state pointer instead of the daughterboard struct pointer. The machine state now contains the daughterboard pointer.

thanks
-- PMM

#12 lore raw

PATCH v2 6/15 target-arm: Add virt class and machine types

In reply to Greg Bellows

Switch virt qemu machine support to use the newer object type, class, and instance model. Added virt TypeInfo with static registration along with virt specific class and machine structs. Also added virt class initialization method.

---
 hw/arm/virt.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)
hw/arm/virt.c +34 -6
index 314e55b..b6bb914 100644
@@ -86,6 +86,23 @@ typedef struct VirtBoardInfo {
     uint32_t clock_phandle;
 } VirtBoardInfo;
 
+typedef struct {
+    MachineClass parent;
+    VirtBoardInfo *daughterboard;
+} VirtMachineClass;
+
+typedef struct {
+    MachineState parent;
+} VirtMachineState;
+
+#define TYPE_VIRT_MACHINE   "virt"
+#define VIRT_MACHINE(obj) \
+    OBJECT_CHECK(VirtMachineState, (obj), TYPE_VIRT_MACHINE)
+#define VIRT_MACHINE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(VirtMachineClass, obj, TYPE_VIRT_MACHINE)
+#define VIRT_MACHINE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(VirtMachineClass, klass, TYPE_VIRT_MACHINE)
+
 /* Addresses and sizes of our components.
  * 0..128MB is space for a flash device so we can run bootrom code such as UEFI.
  * 128MB..256MB is used for miscellaneous device I/O.
@@ -615,16 +632,27 @@ static void machvirt_init(MachineState *machine)
     arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
 }
 
-static QEMUMachine machvirt_a15_machine = {
-    .name = "virt",
-    .desc = "ARM Virtual Machine",
-    .init = machvirt_init,
-    .max_cpus = 8,
+static void virt_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->name = TYPE_VIRT_MACHINE;
+    mc->desc = "ARM Virtual Machine",
+    mc->init = machvirt_init;
+    mc->max_cpus = 8;
+}
+
+static const TypeInfo machvirt_info = {
+    .name = TYPE_VIRT_MACHINE,
+    .parent = TYPE_MACHINE,
+    .instance_size = sizeof(VirtMachineState),
+    .class_size = sizeof(VirtMachineClass),
+    .class_init = virt_class_init,
 };
 
 static void machvirt_machine_init(void)
 {
-    qemu_register_machine(&machvirt_a15_machine);
+    type_register_static(&machvirt_info);
 }
 
 machine_init(machvirt_machine_init);
Signature · 1 line
1.8.3.2
Reviewed-by on v2 6/15
#13 lore raw

Re: [Qemu-devel] [PATCH v2 06/15] target-arm: Add virt class and machine types

Quoted 7 lines · Greg Bellows

Switch virt qemu machine support to use the newer object type, class, and instance model. Added virt TypeInfo with static registration along with virt specific class and machine structs. Also added virt class initialization method.

---

thanks
-- PMM

#14 lore raw

PATCH v2 7/15 target-arm: Add virt machine secure property

In reply to Greg Bellows

Add "secure" virt machine specific property to allow override of the default secure state configuration. By default, when using the QEMU -kernel command line argument, virt machines boot into NS/SVC. When using the QEMU -bios command line argument, virt machines boot into S/SVC.

The secure state can be changed from the default specifying the secure state as a machine property. For example, the below command line would enable secure state on a -linux boot:

    aarch64-softmmu/qemu-system-aarch64
        -machine type=virt,secure=on
        -kernel ...

---

v1 -> v2
- Adapt the machine secure property to Marcel's new dynamic registration
- Change the default machine secure property to true (on).

---
 hw/arm/virt.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
hw/arm/virt.c +29 -0
index b6bb914..3eacc43 100644
@@ -93,6 +93,7 @@ typedef struct {
 
 typedef struct {
     MachineState parent;
+    bool secure;
 } VirtMachineState;
 
 #define TYPE_VIRT_MACHINE   "virt"
@@ -632,6 +633,33 @@ static void machvirt_init(MachineState *machine)
     arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
 }
 
+static bool virt_get_secure(Object *obj, Error **errp)
+{
+    VirtMachineState *vms = VIRT_MACHINE(obj);
+
+    return vms->secure;
+}
+
+static void virt_set_secure(Object *obj, bool value, Error **errp)
+{
+    VirtMachineState *vms = VIRT_MACHINE(obj);
+
+    vms->secure = value;
+}
+
+static void virt_instance_init(Object *obj)
+{
+    VirtMachineState *vms = VIRT_MACHINE(obj);
+
+    /* EL3 is enabled by default on virt */
+    vms->secure = true;
+    object_property_add_bool(obj, "secure", virt_get_secure,
+                             virt_set_secure, NULL);
+    object_property_set_description(obj, "secure",
+                         "Set on/off to enable/disable secure state",
+                         NULL);
+}
+
 static void virt_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -646,6 +674,7 @@ static const TypeInfo machvirt_info = {
     .name = TYPE_VIRT_MACHINE,
     .parent = TYPE_MACHINE,
     .instance_size = sizeof(VirtMachineState),
+    .instance_init = virt_instance_init,
     .class_size = sizeof(VirtMachineClass),
     .class_init = virt_class_init,
 };
Signature · 1 line
1.8.3.2
Reviewed-by on v2 7/15
#15 lore raw

Re: [Qemu-devel] [PATCH v2 07/15] target-arm: Add virt machine secure property

Quoted 5 lines · Greg Bellows

Add "secure" virt machine specific property to allow override of the default secure state configuration. By default, when using the QEMU -kernel command line argument, virt machines boot into NS/SVC. When using the QEMU -bios command line argument, virt machines boot into S/SVC.

Quoted 7 lines

The secure state can be changed from the default specifying the secure state as a machine property. For example, the below command line would enable secure state on a -linux boot:

    aarch64-softmmu/qemu-system-aarch64
        -machine type=virt,secure=on
        -kernel ...

Example sets the property to its default value again.

Quoted 2 lines

thanks
-- PMM

#16 lore raw

Re: [Qemu-devel] [PATCH v2 07/15] target-arm: Add virt machine secure property

Quoted 13 lines · Peter Maydell
Quoted 3 lines · Greg Bellows

Add "secure" virt machine specific property to allow override of the default secure state configuration. By default, when using the QEMU -kernel command line argument, virt machines boot into NS/SVC. When

using

Quoted 6 lines

the QEMU -bios command line argument, virt machines boot into S/SVC.

The secure state can be changed from the default specifying the secure state as a machine property. For example, the below command line would enable secure state on a -linux boot:

Quoted 7 lines
Quoted 3 lines
    aarch64-softmmu/qemu-system-aarch64
        -machine type=virt,secure=on
        -kernel ...

Example sets the property to its default value again.

Fixed.

Quoted 8 lines
Quoted 2 lines

thanks
-- PMM

#17 lore raw

PATCH v2 8/15 target-arm: Add feature unset function

In reply to Greg Bellows

Add an unset_feature() function to compliment the set_feature() function. This will be used to disable functions after they have been enabled during initialization.

---
 target-arm/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
target-arm/cpu.c +5 -0
index d3db279..01afed2 100644
@@ -327,6 +327,11 @@ static inline void set_feature(CPUARMState *env, int feature)
     env->features |= 1ULL << feature;
 }
 
+static inline void unset_feature(CPUARMState *env, int feature)
+{
+    env->features &= ~(1ULL << feature);
+}
+
 static void arm_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
Signature · 1 line
1.8.3.2
#18 lore raw

PATCH v2 9/15 target-arm: Add ARMCPU secure property

In reply to Greg Bellows

Added a "has_el3" state property to the ARMCPU descriptor. This property indicates whether the ARMCPU has security extensions enabled (EL3) or not. By default it is disabled at this time.

---

v1 -> v2
- Added set of has_el3 to true when EL3 is enabled

---
 target-arm/cpu-qom.h |  2 ++
 target-arm/cpu.c     | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
target-arm/cpu-qom.h +2 -0
index dcfda7d..ed5a644 100644
@@ -100,6 +100,8 @@ typedef struct ARMCPU {
     bool start_powered_off;
     /* CPU currently in PSCI powered-off state */
     bool powered_off;
+    /* CPU has security extension */
+    bool has_el3;
 
     /* PSCI conduit used to invoke PSCI methods
      * 0 - disabled, 1 - smc, 2 - hvc
target-arm/cpu.c +24 -0
index 01afed2..758e8f8 100644
@@ -388,6 +388,9 @@ static Property arm_cpu_reset_hivecs_property =
 static Property arm_cpu_rvbar_property =
             DEFINE_PROP_UINT64("rvbar", ARMCPU, rvbar, 0);
 
+static Property arm_cpu_has_el3_property =
+            DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, false);
+
 static void arm_cpu_post_init(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -407,6 +410,15 @@ static void arm_cpu_post_init(Object *obj)
         qdev_property_add_static(DEVICE(obj), &arm_cpu_rvbar_property,
                                  &error_abort);
     }
+
+    if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
+        /* Add the has_el3 state CPU property only if EL3 is allowed.  This will
+         * prevent "has_el3" from existing on CPUs which cannot support EL3.
+         */
+        qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property,
+                                 &error_abort);
+        cpu->has_el3 = true;
+    }
 }
 
 static void arm_cpu_finalizefn(Object *obj)
@@ -476,6 +488,18 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
             cpu->reset_sctlr |= (1 << 13);
     }
 
+    if (!cpu->has_el3) {
+        /* If the hsa_el3 CPU property is disabled then we need to disable the
+         * feature.
+         */
+        unset_feature(env, ARM_FEATURE_EL3);
+
+        /* Disable the security extension feature bits in the processor feature
+         * register as well.  This is id_pfr1[7:4].
+         */
+        cpu->id_pfr1 &= ~0xf0;
+    }
+
     register_cp_regs_for_features(cpu);
     arm_cpu_register_gdb_regs_for_features(cpu);
 
Signature · 1 line
1.8.3.2
#19 lore raw

Re: [Qemu-devel] [PATCH v2 09/15] target-arm: Add ARMCPU secure property

Quoted 33 lines · Greg Bellows

Added a "has_el3" state property to the ARMCPU descriptor. This property indicates whether the ARMCPU has security extensions enabled (EL3) or not. By default it is disabled at this time.

---

v1 -> v2
- Added set of has_el3 to true when EL3 is enabled

---
 target-arm/cpu-qom.h |  2 ++
 target-arm/cpu.c     | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
target-arm/cpu-qom.h +2 -0
index dcfda7d..ed5a644 100644
@@ -100,6 +100,8 @@ typedef struct ARMCPU {
     bool start_powered_off;
     /* CPU currently in PSCI powered-off state */
     bool powered_off;
+    /* CPU has security extension */
+    bool has_el3;
 
     /* PSCI conduit used to invoke PSCI methods
      * 0 - disabled, 1 - smc, 2 - hvc
target-arm/cpu.c +0 -0
index 01afed2..758e8f8 100644

target-arm/cpu.c static Property arm_cpu_reset_hivecs_property = · line 392

Quoted 5 lines
target-arm/cpu.c +2 -0
@@ -388,6 +388,9 @@ static Property arm_cpu_reset_hivecs_property =
 static Property arm_cpu_rvbar_property =
             DEFINE_PROP_UINT64("rvbar", ARMCPU, rvbar, 0);
 
+static Property arm_cpu_has_el3_property =
+            DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, false);

I think the default value here should be "true": we want CPUs to default to having all their features turned on unless the board specifically disables it.

(This won't affect behaviour til we get to patch 15 because before then ARM_FEATURE_EL3 isn't set and we never add the property here.)

Quoted 21 lines
target-arm/cpu.c +10 -0
+
 static void arm_cpu_post_init(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -407,6 +410,15 @@ static void arm_cpu_post_init(Object *obj)
         qdev_property_add_static(DEVICE(obj), &arm_cpu_rvbar_property,
                                  &error_abort);
     }
+
+    if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
+        /* Add the has_el3 state CPU property only if EL3 is allowed.  This will
+         * prevent "has_el3" from existing on CPUs which cannot support EL3.
+         */
+        qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property,
+                                 &error_abort);
+        cpu->has_el3 = true;
+    }
 }
 
 static void arm_cpu_finalizefn(Object *obj)

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 493

Quoted 6 lines
target-arm/cpu.c +3 -0
@@ -476,6 +488,18 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
             cpu->reset_sctlr |= (1 << 13);
     }
 
+    if (!cpu->has_el3) {
+        /* If the hsa_el3 CPU property is disabled then we need to disable the
+         * feature.

Typo: "has_el3".

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 504

Quoted 11 lines
target-arm/cpu.c +9 -0
+         */
+        unset_feature(env, ARM_FEATURE_EL3);
+
+        /* Disable the security extension feature bits in the processor feature
+         * register as well.  This is id_pfr1[7:4].
+         */
+        cpu->id_pfr1 &= ~0xf0;
+    }
+
     register_cp_regs_for_features(cpu);
     arm_cpu_register_gdb_regs_for_features(cpu);

thanks
-- PMM

#20 lore raw

Re: [Qemu-devel] [PATCH v2 09/15] target-arm: Add ARMCPU secure property

Quoted 47 lines · Peter Maydell
Quoted 2 lines · Greg Bellows

Added a "has_el3" state property to the ARMCPU descriptor. This property indicates whether the ARMCPU has security extensions enabled (EL3) or

not.

Quoted 31 lines

By default it is disabled at this time.

---

v1 -> v2
- Added set of has_el3 to true when EL3 is enabled

---
 target-arm/cpu-qom.h |  2 ++
 target-arm/cpu.c     | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
target-arm/cpu-qom.h +2 -0
index dcfda7d..ed5a644 100644
@@ -100,6 +100,8 @@ typedef struct ARMCPU {
     bool start_powered_off;
     /* CPU currently in PSCI powered-off state */
     bool powered_off;
+    /* CPU has security extension */
+    bool has_el3;
 
     /* PSCI conduit used to invoke PSCI methods
      * 0 - disabled, 1 - smc, 2 - hvc
target-arm/cpu.c +0 -0
index 01afed2..758e8f8 100644

target-arm/cpu.c static Property arm_cpu_reset_hivecs_property = · line 392

Quoted 5 lines
target-arm/cpu.c +2 -0
@@ -388,6 +388,9 @@ static Property arm_cpu_reset_hivecs_property =
 static Property arm_cpu_rvbar_property =
             DEFINE_PROP_UINT64("rvbar", ARMCPU, rvbar, 0);
 
+static Property arm_cpu_has_el3_property =
+            DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, false);

I think the default value here should be "true": we want CPUs to default to having all their features turned on unless the board specifically disables it.

Quoted 4 lines

(This won't affect behaviour til we get to patch 15 because before then ARM_FEATURE_EL3 isn't set and we never add the property here.)

I went with false in the initialization because it matches how features are initialized (disabled unless otherwise enabled). In the case of EL3, it is disabled on CPUs by default unless specifically enabled. This is also the case of the has_el3 property, disabled by default unless we see that the EL3 feature is enabled. As-is, the tunable is set to true once we discover that the EL3 feature is set and from there it is up to the board code to unset has_el3 and in turn the EL3 feature.

Quoted 28 lines

target-arm/cpu.c static void arm_cpu_post_init(Object *obj) · line 415

Quoted 12 lines
target-arm/cpu.c +4 -0
+
 static void arm_cpu_post_init(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -407,6 +410,15 @@ static void arm_cpu_post_init(Object *obj)
         qdev_property_add_static(DEVICE(obj), &arm_cpu_rvbar_property,
                                  &error_abort);
     }
+
+    if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
+        /* Add the has_el3 state CPU property only if EL3 is allowed.

This will

target-arm/cpu.c static void arm_cpu_post_init(Object *obj) · line 416

Quoted 1 line
target-arm/cpu.c +1 -0
+         * prevent "has_el3" from existing on CPUs which cannot support

EL3.

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev,

Quoted 9 lines
target-arm/cpu.c +5 -0
+         */
+        qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property,
+                                 &error_abort);
+        cpu->has_el3 = true;
+    }
 }
 
 static void arm_cpu_finalizefn(Object *obj)
@@ -476,6 +488,18 @@ static void arm_cpu_realizefn(DeviceState *dev,

Error **errp)

Quoted 3 lines
target-arm/cpu.c +0 -0
             cpu->reset_sctlr |= (1 << 13);
     }
 
Quoted 7 lines

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, · line 492

Quoted 2 lines
target-arm/cpu.c +2 -0
+    if (!cpu->has_el3) {
+        /* If the hsa_el3 CPU property is disabled then we need to

disable the

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 493

Quoted 1 line
target-arm/cpu.c +1 -0
+         * feature.

Typo: "has_el3".

Fixed.

Quoted 17 lines

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp)

Quoted 5 lines
target-arm/cpu.c +4 -0
+         */
+        unset_feature(env, ARM_FEATURE_EL3);
+
+        /* Disable the security extension feature bits in the processor

feature

target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 504

Quoted 7 lines
target-arm/cpu.c +5 -0
+         * register as well.  This is id_pfr1[7:4].
+         */
+        cpu->id_pfr1 &= ~0xf0;
+    }
+
     register_cp_regs_for_features(cpu);
     arm_cpu_register_gdb_regs_for_features(cpu);

thanks
-- PMM

#21 lore raw

Re: [Qemu-devel] [PATCH v2 09/15] target-arm: Add ARMCPU secure property

Quoted 19 lines · Greg Bellows
Quoted 6 lines · Peter Maydell

target-arm/cpu.c static Property arm_cpu_reset_hivecs_property = · line 392

Quoted 2 lines · Greg Bellows
target-arm/cpu.c +2 -0
+static Property arm_cpu_has_el3_property =
+            DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, false);
Quoted 7 lines

I think the default value here should be "true": we want CPUs to default to having all their features turned on unless the board specifically disables it.

(This won't affect behaviour til we get to patch 15 because before then ARM_FEATURE_EL3 isn't set and we never add the property here.)

Quoted 5 lines

I went with false in the initialization because it matches how features are initialized (disabled unless otherwise enabled). In the case of EL3, it is disabled on CPUs by default unless specifically enabled. This is also the case of the has_el3 property, disabled by default unless we see that the EL3 feature is enabled.

This is correct...

Quoted 2 lines

As-is, the tunable is set to true once we discover that the EL3 feature is set

...but this isn't. When you call qdev_property_add_static() it will call object_property_set_bool() to set the flag to the default value as specified in the Property struct, so we'll end up with has_el3 set to false by default on CPUs which can support EL3, which is not what we want.

In fact you're manually setting cpu->has_el3 = true in the arm_cpu_post_init(). You should just set the property struct's default value correctly in the first place...

thanks
-- PMM

#22 lore raw

Re: [Qemu-devel] [PATCH v2 09/15] target-arm: Add ARMCPU secure property

Quoted 43 lines · Peter Maydell
Quoted 14 lines · Greg Bellows
Quoted 10 lines · Peter Maydell

target-arm/cpu.c static Property arm_cpu_reset_hivecs_property = · line 392

Quoted 2 lines · Greg Bellows
target-arm/cpu.c +2 -0
+static Property arm_cpu_has_el3_property =
+            DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, false);

I think the default value here should be "true": we want CPUs to default to having all their features turned on unless the board specifically disables it.

Quoted 6 lines
Quoted 3 lines

(This won't affect behaviour til we get to patch 15 because before then ARM_FEATURE_EL3 isn't set and we never add the property here.)

I went with false in the initialization because it matches how features

are

Quoted 1 line

initialized (disabled unless otherwise enabled). In the case of EL3, it

is

Quoted 1 line

disabled on CPUs by default unless specifically enabled. This is also

the

Quoted 1 line

case of the has_el3 property, disabled by default unless we see that the

EL3

Quoted 1 line

feature is enabled.

This is correct...

Quoted 2 lines

As-is, the tunable is set to true once we discover that the EL3 feature is set

...but this isn't. When you call qdev_property_add_static() it will call object_property_set_bool() to set the flag to the default value as specified in the Property struct, so we'll end up with has_el3 set to false by default on CPUs which can support EL3, which is not what we want.

Quoted 5 lines

In fact you're manually setting cpu->has_el3 = true in the arm_cpu_post_init(). You should just set the property struct's default value correctly in the first place...

Ah... I see what you are saying. If I init it to true I can skip manual setting of it in the step that follows. I'll fix it in the next version.

Quoted 3 lines

thanks
-- PMM

#23 lore raw

PATCH v2 10/15 target-arm: Add arm_boot_info secure_boot control

In reply to Greg Bellows

Adds the secure_boot boolean field to the arm_boot_info descriptor. This fields is used to indicate whether Linux should boot into secure or non-secure state if the ARM EL3 feature is enabled. The default is to leave the CPU in an unaltered reset state. On EL3 enabled systems, the reset state is secure and can be overridden by setting the added field to false.

---
 hw/arm/boot.c        | 10 ++++++++++
 include/hw/arm/arm.h |  4 ++++
 2 files changed, 14 insertions(+)
hw/arm/boot.c +10 -0
index e6a3c5b..7ec33f3 100644
@@ -457,6 +457,16 @@ static void do_cpu_reset(void *opaque)
                 env->thumb = info->entry & 1;
             }
         } else {
+            /* If we are booting Linux then we need to check whether we are
+             * booting into secure or non-secure state and adjust the state
+             * accordingly.  Out of reset, ARM is defined to be in secure state
+             * (SCR.NS = 0), we change that here is non-secure boot has been
+             * requested.
+             */
+            if (arm_feature(env, ARM_FEATURE_EL3) && !info->secure_boot) {
+                env->cp15.scr_el3 |= SCR_NS;
+            }
+
             if (CPU(cpu) == first_cpu) {
                 if (env->aarch64) {
                     env->pc = info->loader_start;
include/hw/arm/arm.h +4 -0
index cefc9e6..6659562 100644
@@ -37,6 +37,10 @@ struct arm_boot_info {
     hwaddr gic_cpu_if_addr;
     int nb_cpus;
     int board_id;
+    /* ARM machines that support security extensions use this field to control
+     * whether Linux is booted as securei(true) or non-secure(false).
+     */
+    bool secure_boot;
     int (*atag_board)(const struct arm_boot_info *info, void *p);
     /* multicore boards that use the default secondary core boot functions
      * can ignore these two function calls. If the default functions won't
Signature · 1 line
1.8.3.2
#24 lore raw

Re: [Qemu-devel] [PATCH v2 10/15] target-arm: Add arm_boot_info secure_boot control

Quoted 17 lines · Greg Bellows

Adds the secure_boot boolean field to the arm_boot_info descriptor. This fields is used to indicate whether Linux should boot into secure or non-secure state if the ARM EL3 feature is enabled. The default is to leave the CPU in an unaltered reset state. On EL3 enabled systems, the reset state is secure and can be overridden by setting the added field to false.

---
 hw/arm/boot.c        | 10 ++++++++++
 include/hw/arm/arm.h |  4 ++++
 2 files changed, 14 insertions(+)
hw/arm/boot.c +0 -0
index e6a3c5b..7ec33f3 100644

hw/arm/boot.c static void do_cpu_reset(void *opaque) · line 463

Quoted 7 lines
hw/arm/boot.c +4 -0
@@ -457,6 +457,16 @@ static void do_cpu_reset(void *opaque)
                 env->thumb = info->entry & 1;
             }
         } else {
+            /* If we are booting Linux then we need to check whether we are
+             * booting into secure or non-secure state and adjust the state
+             * accordingly.  Out of reset, ARM is defined to be in secure state
+             * (SCR.NS = 0), we change that here is non-secure boot has been

typo: "if"

Quoted 14 lines
hw/arm/boot.c +6 -0
+             * requested.
+             */
+            if (arm_feature(env, ARM_FEATURE_EL3) && !info->secure_boot) {
+                env->cp15.scr_el3 |= SCR_NS;
+            }
+
             if (CPU(cpu) == first_cpu) {
                 if (env->aarch64) {
                     env->pc = info->loader_start;
include/hw/arm/arm.h +0 -0
index cefc9e6..6659562 100644

include/hw/arm/arm.h struct arm_boot_info { · line 40

Quoted 4 lines
include/hw/arm/arm.h +1 -0
@@ -37,6 +37,10 @@ struct arm_boot_info {
     hwaddr gic_cpu_if_addr;
     int nb_cpus;
     int board_id;
+    /* ARM machines that support security extensions use this field to control

Strictly, this should say "the Security Extensions".

include/hw/arm/arm.h struct arm_boot_info { · line 41

Quoted 1 line
include/hw/arm/arm.h +1 -0
+     * whether Linux is booted as securei(true) or non-secure(false).

Typo: "secure".

Quoted 7 lines
include/hw/arm/arm.h +2 -1
+     */
+    bool secure_boot;
     int (*atag_board)(const struct arm_boot_info *info, void *p);
     /* multicore boards that use the default secondary core boot functions
      * can ignore these two function calls. If the default functions won't
--

1.8.3.2

thanks
-- PMM

#25 lore raw

Re: [Qemu-devel] [PATCH v2 10/15] target-arm: Add arm_boot_info secure_boot control

Quoted 64 lines · Peter Maydell
Quoted 2 lines · Greg Bellows

Adds the secure_boot boolean field to the arm_boot_info descriptor. This fields is used to indicate whether Linux should boot into secure or

non-secure

Quoted 1 line

state if the ARM EL3 feature is enabled. The default is to leave the

CPU in an

Quoted 1 line

unaltered reset state. On EL3 enabled systems, the reset state is

secure and

Quoted 13 lines

can be overridden by setting the added field to false.

---
 hw/arm/boot.c        | 10 ++++++++++
 include/hw/arm/arm.h |  4 ++++
 2 files changed, 14 insertions(+)
hw/arm/boot.c +0 -0
index e6a3c5b..7ec33f3 100644

hw/arm/boot.c static void do_cpu_reset(void *opaque) · line 460

Quoted 4 lines
hw/arm/boot.c +1 -0
@@ -457,6 +457,16 @@ static void do_cpu_reset(void *opaque)
                 env->thumb = info->entry & 1;
             }
         } else {
+            /* If we are booting Linux then we need to check whether we

are

hw/arm/boot.c static void do_cpu_reset(void *opaque) · line 461

Quoted 1 line
hw/arm/boot.c +1 -0
+             * booting into secure or non-secure state and adjust the

state

hw/arm/boot.c static void do_cpu_reset(void *opaque) · line 462

Quoted 1 line
hw/arm/boot.c +1 -0
+             * accordingly.  Out of reset, ARM is defined to be in

secure state

hw/arm/boot.c static void do_cpu_reset(void *opaque) · line 463

Quoted 1 line
hw/arm/boot.c +1 -0
+             * (SCR.NS = 0), we change that here is non-secure boot has

been

typo: "if"

hw/arm/boot.c static void do_cpu_reset(void *opaque)

Quoted 3 lines
hw/arm/boot.c +3 -0
+             * requested.
+             */
+            if (arm_feature(env, ARM_FEATURE_EL3) &&

!info->secure_boot) {

Quoted 11 lines
hw/arm/boot.c +3 -0
+                env->cp15.scr_el3 |= SCR_NS;
+            }
+
             if (CPU(cpu) == first_cpu) {
                 if (env->aarch64) {
                     env->pc = info->loader_start;
include/hw/arm/arm.h +0 -0
index cefc9e6..6659562 100644

include/hw/arm/arm.h struct arm_boot_info { · line 40

Quoted 4 lines
include/hw/arm/arm.h +1 -0
@@ -37,6 +37,10 @@ struct arm_boot_info {
     hwaddr gic_cpu_if_addr;
     int nb_cpus;
     int board_id;
+    /* ARM machines that support security extensions use this field to

control

Strictly, this should say "the Security Extensions".

include/hw/arm/arm.h struct arm_boot_info { · line 41

Quoted 1 line
include/hw/arm/arm.h +1 -0
+     * whether Linux is booted as securei(true) or non-secure(false).

Typo: "secure".

Quoted 11 lines

include/hw/arm/arm.h struct arm_boot_info {

Quoted 4 lines
include/hw/arm/arm.h +2 -0
+     */
+    bool secure_boot;
     int (*atag_board)(const struct arm_boot_info *info, void *p);
     /* multicore boards that use the default secondary core boot

functions

include/hw/arm/arm.h struct arm_boot_info { · line 46

Quoted 1 line
include/hw/arm/arm.h +0 -0
      * can ignore these two function calls. If the default functions

won't

Quoted 2 lines

--
1.8.3.2

All typos fixed.

Quoted 3 lines

thanks
-- PMM

#26 lore raw

PATCH v2 11/15 target-arm: Enable CPU has_el3 prop during VE init

In reply to Greg Bellows

Adds setting of the CPU has_el3 property based on the vexpress machine secure state property during initialization. This enables/disables EL3 state during start-up. Changes include adding an additional secure state boolean during vexpress CPU initialization. Also enables the ARM secure boot by default.

---

v1 -> v2
- Changes CPU property name from "secure" to "has_el3"
- Change conditional to handle machine state default of secure. The check now checks if the machine secure property has been disabled which causes the CPU EL3 feautre to be disabled.
- Add setting of arm_boot_info.secure_boot to true

---
 hw/arm/vexpress.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
hw/arm/vexpress.c +14 -3
index c82c32e..d3fb2bd 100644
@@ -196,7 +196,7 @@ struct VEDBoardInfo {
 };
 
 static void init_cpus(const char *cpu_model, const char *privdev,
-                      hwaddr periphbase, qemu_irq *pic)
+                      hwaddr periphbase, qemu_irq *pic, bool secure)
 {
     ObjectClass *cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
     DeviceState *dev;
@@ -213,6 +213,15 @@ static void init_cpus(const char *cpu_model, const char *privdev,
         Object *cpuobj = object_new(object_class_get_name(cpu_oc));
         Error *err = NULL;
 
+        if (!secure) {
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("'secure' machine property not supported "
+                             "with %s cpu", cpu_model);
+                exit(1);
+            }
+        }
+
         if (object_property_find(cpuobj, "reset-cbar", NULL)) {
             object_property_set_int(cpuobj, periphbase,
                                     "reset-cbar", &error_abort);
@@ -288,7 +297,7 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,
     memory_region_add_subregion(sysmem, 0x60000000, ram);
 
     /* 0x1e000000 A9MPCore (SCU) private memory region */
-    init_cpus(cpu_model, "a9mpcore_priv", 0x1e000000, pic);
+    init_cpus(cpu_model, "a9mpcore_priv", 0x1e000000, pic, vms->secure);
 
     /* Daughterboard peripherals : 0x10020000 .. 0x20000000 */
 
@@ -374,7 +383,7 @@ static void a15_daughterboard_init(const VexpressMachineState *vms,
     memory_region_add_subregion(sysmem, 0x80000000, ram);
 
     /* 0x2c000000 A15MPCore private memory region (GIC) */
-    init_cpus(cpu_model, "a15mpcore_priv", 0x2c000000, pic);
+    init_cpus(cpu_model, "a15mpcore_priv", 0x2c000000, pic, vms->secure);
 
     /* A15 daughterboard peripherals: */
 
@@ -699,6 +708,8 @@ static void vexpress_common_init(MachineState *machine)
     daughterboard->bootinfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30;
     daughterboard->bootinfo.gic_cpu_if_addr = daughterboard->gic_cpu_if_addr;
     daughterboard->bootinfo.modify_dtb = vexpress_modify_dtb;
+    /* Indicate that when booting Linux we should be in secure state */
+    daughterboard->bootinfo.secure_boot = true;
     arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
 }
 
Signature · 1 line
1.8.3.2
#27 lore raw

Re: [Qemu-devel] [PATCH v2 11/15] target-arm: Enable CPU has_el3 prop during VE init

Quoted 34 lines · Greg Bellows

Adds setting of the CPU has_el3 property based on the vexpress machine secure state property during initialization. This enables/disables EL3 state during start-up. Changes include adding an additional secure state boolean during vexpress CPU initialization. Also enables the ARM secure boot by default.

---

v1 -> v2
- Changes CPU property name from "secure" to "has_el3"
- Change conditional to handle machine state default of secure. The check now checks if the machine secure property has been disabled which causes the CPU EL3 feautre to be disabled.
- Add setting of arm_boot_info.secure_boot to true

---
 hw/arm/vexpress.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
hw/arm/vexpress.c +1 -1
index c82c32e..d3fb2bd 100644
@@ -196,7 +196,7 @@ struct VEDBoardInfo {
 };
 
 static void init_cpus(const char *cpu_model, const char *privdev,
-                      hwaddr periphbase, qemu_irq *pic)
+                      hwaddr periphbase, qemu_irq *pic, bool secure)
 {
     ObjectClass *cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
     DeviceState *dev;

hw/arm/vexpress.c static void init_cpus(const char *cpu_model, const char *privdev, · line 222

Quoted 10 lines
hw/arm/vexpress.c +7 -0
@@ -213,6 +213,15 @@ static void init_cpus(const char *cpu_model, const char *privdev,
         Object *cpuobj = object_new(object_class_get_name(cpu_oc));
         Error *err = NULL;
 
+        if (!secure) {
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("'secure' machine property not supported "
+                             "with %s cpu", cpu_model);
+                exit(1);
+            }

This will break trying to use '-machine secure=off' with '-cpu host'. We should just silently continue if the has_el3 property doesn't exist on the CPU object.

Quoted 24 lines
hw/arm/vexpress.c +4 -2
+        }
+
         if (object_property_find(cpuobj, "reset-cbar", NULL)) {
             object_property_set_int(cpuobj, periphbase,
                                     "reset-cbar", &error_abort);
@@ -288,7 +297,7 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,
     memory_region_add_subregion(sysmem, 0x60000000, ram);
 
     /* 0x1e000000 A9MPCore (SCU) private memory region */
-    init_cpus(cpu_model, "a9mpcore_priv", 0x1e000000, pic);
+    init_cpus(cpu_model, "a9mpcore_priv", 0x1e000000, pic, vms->secure);
 
     /* Daughterboard peripherals : 0x10020000 .. 0x20000000 */
 
@@ -374,7 +383,7 @@ static void a15_daughterboard_init(const VexpressMachineState *vms,
     memory_region_add_subregion(sysmem, 0x80000000, ram);
 
     /* 0x2c000000 A15MPCore private memory region (GIC) */
-    init_cpus(cpu_model, "a15mpcore_priv", 0x2c000000, pic);
+    init_cpus(cpu_model, "a15mpcore_priv", 0x2c000000, pic, vms->secure);
 
     /* A15 daughterboard peripherals: */
 

hw/arm/vexpress.c static void vexpress_common_init(MachineState *machine) · line 714

Quoted 7 lines
hw/arm/vexpress.c +2 -0
@@ -699,6 +708,8 @@ static void vexpress_common_init(MachineState *machine)
     daughterboard->bootinfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30;
     daughterboard->bootinfo.gic_cpu_if_addr = daughterboard->gic_cpu_if_addr;
     daughterboard->bootinfo.modify_dtb = vexpress_modify_dtb;
+    /* Indicate that when booting Linux we should be in secure state */
+    daughterboard->bootinfo.secure_boot = true;
     arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
 }

thanks
-- PMM

#28 lore raw

Re: [Qemu-devel] [PATCH v2 11/15] target-arm: Enable CPU has_el3 prop during VE init

Quoted 52 lines · Peter Maydell
Quoted 4 lines · Greg Bellows

Adds setting of the CPU has_el3 property based on the vexpress machine secure state property during initialization. This enables/disables EL3 state during start-up. Changes include adding an additional secure state boolean during vexpress CPU initialization. Also enables the ARM secure

boot

Quoted 9 lines

by default.

---

v1 -> v2
- Changes CPU property name from "secure" to "has_el3"
- Change conditional to handle machine state default of secure. The

check now

Quoted 1 line

checks if the machine secure property has been disabled which causes

the CPU

hw/arm/vexpress.c static void init_cpus(const char *cpu_model, const

Quoted 20 lines

EL3 feautre to be disabled.
- Add setting of arm_boot_info.secure_boot to true

---
 hw/arm/vexpress.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
hw/arm/vexpress.c +1 -1
index c82c32e..d3fb2bd 100644
@@ -196,7 +196,7 @@ struct VEDBoardInfo {
 };
 
 static void init_cpus(const char *cpu_model, const char *privdev,
-                      hwaddr periphbase, qemu_irq *pic)
+                      hwaddr periphbase, qemu_irq *pic, bool secure)
 {
     ObjectClass *cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
     DeviceState *dev;
@@ -213,6 +213,15 @@ static void init_cpus(const char *cpu_model, const

char *privdev,

hw/arm/vexpress.c static void init_cpus(const char *cpu_model, const char *privdev, · line 222

Quoted 10 lines
hw/arm/vexpress.c +7 -0
         Object *cpuobj = object_new(object_class_get_name(cpu_oc));
         Error *err = NULL;
 
+        if (!secure) {
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("'secure' machine property not supported "
+                             "with %s cpu", cpu_model);
+                exit(1);
+            }
Quoted 4 lines

This will break trying to use '-machine secure=off' with '-cpu host'. We should just silently continue if the has_el3 property doesn't exist on the CPU object.

Fixed

Quoted 41 lines

hw/arm/vexpress.c static void a9_daughterboard_init(const

Quoted 7 lines
hw/arm/vexpress.c +2 -0
+        }
+
         if (object_property_find(cpuobj, "reset-cbar", NULL)) {
             object_property_set_int(cpuobj, periphbase,
                                     "reset-cbar", &error_abort);
@@ -288,7 +297,7 @@ static void a9_daughterboard_init(const

VexpressMachineState *vms,

hw/arm/vexpress.c static void a15_daughterboard_init(const

Quoted 9 lines
hw/arm/vexpress.c +1 -1
     memory_region_add_subregion(sysmem, 0x60000000, ram);
 
     /* 0x1e000000 A9MPCore (SCU) private memory region */
-    init_cpus(cpu_model, "a9mpcore_priv", 0x1e000000, pic);
+    init_cpus(cpu_model, "a9mpcore_priv", 0x1e000000, pic, vms->secure);
 
     /* Daughterboard peripherals : 0x10020000 .. 0x20000000 */
 
@@ -374,7 +383,7 @@ static void a15_daughterboard_init(const

VexpressMachineState *vms,

hw/arm/vexpress.c static void a15_daughterboard_init(const VexpressMachineState *vms,

Quoted 5 lines
hw/arm/vexpress.c +1 -1
     memory_region_add_subregion(sysmem, 0x80000000, ram);
 
     /* 0x2c000000 A15MPCore private memory region (GIC) */
-    init_cpus(cpu_model, "a15mpcore_priv", 0x2c000000, pic);
+    init_cpus(cpu_model, "a15mpcore_priv", 0x2c000000, pic,

vms->secure);

hw/arm/vexpress.c static void vexpress_common_init(MachineState

Quoted 4 lines
hw/arm/vexpress.c +0 -0
     /* A15 daughterboard peripherals: */
 
@@ -699,6 +708,8 @@ static void vexpress_common_init(MachineState

*machine)

hw/arm/vexpress.c static void vexpress_common_init(MachineState · line 709

Quoted 2 lines
hw/arm/vexpress.c +0 -0
     daughterboard->bootinfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30;
     daughterboard->bootinfo.gic_cpu_if_addr =

daughterboard->gic_cpu_if_addr;

hw/arm/vexpress.c static void vexpress_common_init(MachineState *machine) · line 714

Quoted 5 lines
hw/arm/vexpress.c +2 -0
     daughterboard->bootinfo.modify_dtb = vexpress_modify_dtb;
+    /* Indicate that when booting Linux we should be in secure state */
+    daughterboard->bootinfo.secure_boot = true;
     arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
 }

thanks
-- PMM

#29 lore raw

PATCH v2 12/15 target-arm: Set CPU has_el3 prop during virt init

In reply to Greg Bellows

Adds setting of the CPU has_el3 property based on the virt machine secure state property during initialization. This enables/disables EL3 state during start-up. Changes include adding an additional secure state boolean during virt CPU initialization. Also disables the ARM secure boot by default.

---

v1 -> v2
- Changes CPU property name from "secure" to "has_el3"
- Change conditional to handle machine state default of secure. The check now checks if the machine secure property has been disabled which causes the CPU EL3 feature to be disabled.
- Add setting of arm_boot_info.secure_boot to false

---
 hw/arm/virt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/arm/virt.c +13 -0
index 3eacc43..19d6174 100644
@@ -547,6 +547,7 @@ static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size)
 
 static void machvirt_init(MachineState *machine)
 {
+    VirtMachineState *vms = VIRT_MACHINE(machine);
     qemu_irq pic[NUM_IRQS];
     MemoryRegion *sysmem = get_system_memory();
     int n;
@@ -584,6 +585,16 @@ static void machvirt_init(MachineState *machine)
         }
         cpuobj = object_new(object_class_get_name(oc));
 
+        if (!vms->secure) {
+            Error *err = NULL;
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("'secure' machine property not supported "
+                             "with %s cpu", cpu_model);
+                exit(1);
+            }
+        }
+
         object_property_set_int(cpuobj, QEMU_PSCI_CONDUIT_HVC, "psci-conduit",
                                 NULL);
 
@@ -630,6 +641,8 @@ static void machvirt_init(MachineState *machine)
     vbi->bootinfo.board_id = -1;
     vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base;
     vbi->bootinfo.get_dtb = machvirt_dtb;
+    /* Indicate that when booting Linux we should be in non-secure state */
+    vbi->bootinfo.secure_boot = false;
     arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
 }
 
Signature · 1 line
1.8.3.2
#30 lore raw

Re: [Qemu-devel] [PATCH v2 12/15] target-arm: Set CPU has_el3 prop during virt init

Quoted 35 lines · Greg Bellows

Adds setting of the CPU has_el3 property based on the virt machine secure state property during initialization. This enables/disables EL3 state during start-up. Changes include adding an additional secure state boolean during virt CPU initialization. Also disables the ARM secure boot by default.

---

v1 -> v2
- Changes CPU property name from "secure" to "has_el3"
- Change conditional to handle machine state default of secure. The check now checks if the machine secure property has been disabled which causes the CPU EL3 feature to be disabled.
- Add setting of arm_boot_info.secure_boot to false

---
 hw/arm/virt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/arm/virt.c +1 -0
index 3eacc43..19d6174 100644
@@ -547,6 +547,7 @@ static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size)
 
 static void machvirt_init(MachineState *machine)
 {
+    VirtMachineState *vms = VIRT_MACHINE(machine);
     qemu_irq pic[NUM_IRQS];
     MemoryRegion *sysmem = get_system_memory();
     int n;
@@ -584,6 +585,16 @@ static void machvirt_init(MachineState *machine)
         }
         cpuobj = object_new(object_class_get_name(oc));

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 596

Quoted 10 lines
hw/arm/virt.c +9 -0
 
+        if (!vms->secure) {
+            Error *err = NULL;
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("'secure' machine property not supported "
+                             "with %s cpu", cpu_model);
+                exit(1);
+            }
+        }

As with vexpress, we should silently continue if the CPU object doesn't have has_el3.

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 645

Quoted 10 lines
hw/arm/virt.c +3 -0
+
         object_property_set_int(cpuobj, QEMU_PSCI_CONDUIT_HVC, "psci-conduit",
                                 NULL);
 
@@ -630,6 +641,8 @@ static void machvirt_init(MachineState *machine)
     vbi->bootinfo.board_id = -1;
     vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base;
     vbi->bootinfo.get_dtb = machvirt_dtb;
+    /* Indicate that when booting Linux we should be in non-secure state */
+    vbi->bootinfo.secure_boot = false;

You don't need to set this, false is the default.

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 647

Quoted 2 lines
hw/arm/virt.c +0 -0
     arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
 }

thanks
-- PMM

#31 lore raw

Re: [Qemu-devel] [PATCH v2 12/15] target-arm: Set CPU has_el3 prop during virt init

Quoted 43 lines · Peter Maydell
Quoted 4 lines · Greg Bellows

Adds setting of the CPU has_el3 property based on the virt machine secure state property during initialization. This enables/disables EL3 state during start-up. Changes include adding an additional secure state boolean during virt CPU initialization. Also disables the ARM secure

boot

Quoted 9 lines

by default.

---

v1 -> v2
- Changes CPU property name from "secure" to "has_el3"
- Change conditional to handle machine state default of secure. The

check

Quoted 1 line

now checks if the machine secure property has been disabled which

causes the

hw/arm/virt.c static void *machvirt_dtb(const struct arm_boot_info

Quoted 11 lines

CPU EL3 feature to be disabled.
- Add setting of arm_boot_info.secure_boot to false

---
 hw/arm/virt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/arm/virt.c +0 -0
index 3eacc43..19d6174 100644
@@ -547,6 +547,7 @@ static void *machvirt_dtb(const struct arm_boot_info

*binfo, int *fdt_size)

Quoted 11 lines
hw/arm/virt.c +1 -0
 static void machvirt_init(MachineState *machine)
 {
+    VirtMachineState *vms = VIRT_MACHINE(machine);
     qemu_irq pic[NUM_IRQS];
     MemoryRegion *sysmem = get_system_memory();
     int n;
@@ -584,6 +585,16 @@ static void machvirt_init(MachineState *machine)
         }
         cpuobj = object_new(object_class_get_name(oc));
 
Quoted 14 lines

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 596

Quoted 9 lines
hw/arm/virt.c +9 -0
+        if (!vms->secure) {
+            Error *err = NULL;
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("'secure' machine property not supported "
+                             "with %s cpu", cpu_model);
+                exit(1);
+            }
+        }

As with vexpress, we should silently continue if the CPU object doesn't have has_el3.

Fixed.

Quoted 11 lines

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 598

Quoted 2 lines
hw/arm/virt.c +1 -0
+
         object_property_set_int(cpuobj, QEMU_PSCI_CONDUIT_HVC,

"psci-conduit",

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 644

Quoted 7 lines
hw/arm/virt.c +1 -0
                                 NULL);
 
@@ -630,6 +641,8 @@ static void machvirt_init(MachineState *machine)
     vbi->bootinfo.board_id = -1;
     vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base;
     vbi->bootinfo.get_dtb = machvirt_dtb;
+    /* Indicate that when booting Linux we should be in non-secure

state */

Quoted 5 lines

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 645

Quoted 1 line
hw/arm/virt.c +1 -0
+    vbi->bootinfo.secure_boot = false;

You don't need to set this, false is the default.

Removed.

Quoted 6 lines

hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 647

Quoted 2 lines
hw/arm/virt.c +0 -0
     arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
 }

thanks
-- PMM

#32 lore raw

PATCH v2 13/15 target-arm: Breakout integratorcp and versatilepb cpu init

In reply to Greg Bellows

This commit changes the integratorcp and versatilepb CPU initialization from using the generic ARM cpu_arm_init function to doing it inline. This is necessary in order to allow CPU configuration changes to occur between CPU instance initialization and realization. Specifically, this change is in preparation for disabling CPU EL3 support.

---
 hw/arm/integratorcp.c | 19 +++++++++++++++++--
 hw/arm/versatilepb.c  | 20 ++++++++++++++++++--
 2 files changed, 35 insertions(+), 4 deletions(-)
hw/arm/integratorcp.c +17 -2
index 266ec18..f196189 100644
@@ -15,6 +15,7 @@
 #include "net/net.h"
 #include "exec/address-spaces.h"
 #include "sysemu/sysemu.h"
+#include "qemu/error-report.h"
 
 #define TYPE_INTEGRATOR_CM "integrator_core"
 #define INTEGRATOR_CM(obj) \
@@ -469,6 +470,8 @@ static void integratorcp_init(MachineState *machine)
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
+    ObjectClass *cpu_oc;
+    Object *cpuobj;
     ARMCPU *cpu;
     MemoryRegion *address_space_mem = get_system_memory();
     MemoryRegion *ram = g_new(MemoryRegion, 1);
@@ -476,16 +479,28 @@ static void integratorcp_init(MachineState *machine)
     qemu_irq pic[32];
     DeviceState *dev;
     int i;
+    Error *err = NULL;
 
     if (!cpu_model) {
         cpu_model = "arm926";
     }
-    cpu = cpu_arm_init(cpu_model);
-    if (!cpu) {
+
+    cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
+    if (!cpu_oc) {
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
 
+    cpuobj = object_new(object_class_get_name(cpu_oc));
+
+    object_property_set_bool(cpuobj, true, "realized", &err);
+    if (err) {
+        error_report("%s", error_get_pretty(err));
+        exit(1);
+    }
+
+    cpu = ARM_CPU(cpuobj);
+
     memory_region_init_ram(ram, NULL, "integrator.ram", ram_size, &error_abort);
     vmstate_register_ram_global(ram);
     /* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash.  */
hw/arm/versatilepb.c +18 -2
index e6ef0a2..b74dc15 100644
@@ -18,6 +18,7 @@
 #include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 #include "hw/block/flash.h"
+#include "qemu/error-report.h"
 
 #define VERSATILE_FLASH_ADDR 0x34000000
 #define VERSATILE_FLASH_SIZE (64 * 1024 * 1024)
@@ -175,6 +176,8 @@ static struct arm_boot_info versatile_binfo;
 
 static void versatile_init(MachineState *machine, int board_id)
 {
+    ObjectClass *cpu_oc;
+    Object *cpuobj;
     ARMCPU *cpu;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram = g_new(MemoryRegion, 1);
@@ -189,15 +192,28 @@ static void versatile_init(MachineState *machine, int board_id)
     int n;
     int done_smc = 0;
     DriveInfo *dinfo;
+    Error *err = NULL;
 
     if (!machine->cpu_model) {
         machine->cpu_model = "arm926";
     }
-    cpu = cpu_arm_init(machine->cpu_model);
-    if (!cpu) {
+
+    cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, machine->cpu_model);
+    if (!cpu_oc) {
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+
+    cpuobj = object_new(object_class_get_name(cpu_oc));
+
+    object_property_set_bool(cpuobj, true, "realized", &err);
+    if (err) {
+        error_report("%s", error_get_pretty(err));
+        exit(1);
+    }
+
+    cpu = ARM_CPU(cpuobj);
+
     memory_region_init_ram(ram, NULL, "versatile.ram", machine->ram_size,
                            &error_abort);
     vmstate_register_ram_global(ram);
Signature · 1 line
1.8.3.2
Reviewed-by on v2 13/15
#33 lore raw

Re: [Qemu-devel] [PATCH v2 13/15] target-arm: Breakout integratorcp and versatilepb cpu init

Quoted 11 lines · Greg Bellows

This commit changes the integratorcp and versatilepb CPU initialization from using the generic ARM cpu_arm_init function to doing it inline. This is necessary in order to allow CPU configuration changes to occur between CPU instance initialization and realization. Specifically, this change is in preparation for disabling CPU EL3 support.

---
 hw/arm/integratorcp.c | 19 +++++++++++++++++--
 hw/arm/versatilepb.c  | 20 ++++++++++++++++++--
 2 files changed, 35 insertions(+), 4 deletions(-)

thanks
-- PMM

#34 lore raw

PATCH v2 14/15 target-arm: Disable EL3 on unsupported machines

In reply to Greg Bellows

Disables the CPU ARM_FEATURE_EL3 featuere on machine models that can be configured to use Cortex-A9, Cortex-A15, and ARM1176 but don't officially support EL3. This preserves backwards compatibility.

---
 hw/arm/exynos4210.c   | 11 +++++++++++
 hw/arm/highbank.c     | 12 ++++++++++++
 hw/arm/integratorcp.c | 12 ++++++++++++
 hw/arm/realview.c     | 12 ++++++++++++
 hw/arm/versatilepb.c  | 12 ++++++++++++
 hw/arm/xilinx_zynq.c  | 12 ++++++++++++
 6 files changed, 71 insertions(+)
hw/arm/exynos4210.c +11 -0
index 582794c..97dafca 100644
@@ -152,6 +152,17 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
         Object *cpuobj = object_new(object_class_get_name(cpu_oc));
         Error *err = NULL;
 
+        /* By default A9 CPUs have EL3 enabled.  This board does not currently
+         * support EL3 so the CPU EL3 property is disabled before realization.
+         */
+        if (object_property_find(cpuobj, "has_el3", NULL)) {
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("%s", error_get_pretty(err));
+                exit(1);
+            }
+        }
+
         s->cpu[n] = ARM_CPU(cpuobj);
         object_property_set_int(cpuobj, EXYNOS4210_SMP_PRIVATE_BASE_ADDR,
                                 "reset-cbar", &error_abort);
hw/arm/highbank.c +12 -0
index 30f744a..f67570a 100644
@@ -241,6 +241,18 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)
         cpuobj = object_new(object_class_get_name(oc));
         cpu = ARM_CPU(cpuobj);
 
+        /* By default A9 and A15 CPUs have EL3 enabled.  This board does not
+         * currently support EL3 so the CPU EL3 property is disabled before
+         * realization.
+         */
+        if (object_property_find(cpuobj, "has_el3", NULL)) {
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("%s", error_get_pretty(err));
+                exit(1);
+            }
+        }
+
         if (object_property_find(cpuobj, "reset-cbar", NULL)) {
             object_property_set_int(cpuobj, MPCORE_PERIPHBASE,
                                     "reset-cbar", &error_abort);
hw/arm/integratorcp.c +12 -0
index f196189..8c48b68 100644
@@ -493,6 +493,18 @@ static void integratorcp_init(MachineState *machine)
 
     cpuobj = object_new(object_class_get_name(cpu_oc));
 
+    /* By default ARM1176 CPUs have EL3 enabled.  This board does not
+     * currently support EL3 so the CPU EL3 property is disabled before
+     * realization.
+     */
+    if (object_property_find(cpuobj, "has_el3", NULL)) {
+        object_property_set_bool(cpuobj, false, "has_el3", &err);
+        if (err) {
+            error_report("%s", error_get_pretty(err));
+            exit(1);
+        }
+    }
+
     object_property_set_bool(cpuobj, true, "realized", &err);
     if (err) {
         error_report("%s", error_get_pretty(err));
hw/arm/realview.c +12 -0
index d41ec97..66e51ef 100644
@@ -101,6 +101,18 @@ static void realview_init(MachineState *machine,
         Object *cpuobj = object_new(object_class_get_name(cpu_oc));
         Error *err = NULL;
 
+        /* By default A9,A15 and ARM1176 CPUs have EL3 enabled.  This board
+         * does not currently support EL3 so the CPU EL3 property is disabled
+         * before realization.
+         */
+        if (object_property_find(cpuobj, "has_el3", NULL)) {
+            object_property_set_bool(cpuobj, false, "has_el3", &err);
+            if (err) {
+                error_report("%s", error_get_pretty(err));
+                exit(1);
+            }
+        }
+
         if (is_pb && is_mpcore) {
             object_property_set_int(cpuobj, periphbase, "reset-cbar", &err);
             if (err) {
hw/arm/versatilepb.c +12 -0
index b74dc15..6c4c2e7 100644
@@ -206,6 +206,18 @@ static void versatile_init(MachineState *machine, int board_id)
 
     cpuobj = object_new(object_class_get_name(cpu_oc));
 
+    /* By default ARM1176 CPUs have EL3 enabled.  This board does not
+     * currently support EL3 so the CPU EL3 property is disabled before
+     * realization.
+     */
+    if (object_property_find(cpuobj, "has_el3", NULL)) {
+        object_property_set_bool(cpuobj, false, "has_el3", &err);
+        if (err) {
+            error_report("%s", error_get_pretty(err));
+            exit(1);
+        }
+    }
+
     object_property_set_bool(cpuobj, true, "realized", &err);
     if (err) {
         error_report("%s", error_get_pretty(err));
hw/arm/xilinx_zynq.c +12 -0
index b590392..06e6e24 100644
@@ -126,6 +126,18 @@ static void zynq_init(MachineState *machine)
 
     cpu = ARM_CPU(object_new(object_class_get_name(cpu_oc)));
 
+    /* By default A9 CPUs have EL3 enabled.  This board does not
+     * currently support EL3 so the CPU EL3 property is disabled before
+     * realization.
+     */
+    if (object_property_find(OBJECT(cpu), "has_el3", NULL)) {
+        object_property_set_bool(OBJECT(cpu), false, "has_el3", &err);
+        if (err) {
+            error_report("%s", error_get_pretty(err));
+            exit(1);
+        }
+    }
+
     object_property_set_int(OBJECT(cpu), ZYNQ_BOARD_MIDR, "midr", &err);
     if (err) {
         error_report("%s", error_get_pretty(err));
Signature · 1 line
1.8.3.2
Reviewed-by on v2 14/15
#35 lore raw

Re: [Qemu-devel] [PATCH v2 14/15] target-arm: Disable EL3 on unsupported machines

Quoted 5 lines · Greg Bellows

Disables the CPU ARM_FEATURE_EL3 featuere on machine models that can be configured to use Cortex-A9, Cortex-A15, and ARM1176 but don't officially support EL3. This preserves backwards compatibility.

Quoted 8 lines
---
 hw/arm/exynos4210.c   | 11 +++++++++++
 hw/arm/highbank.c     | 12 ++++++++++++
 hw/arm/integratorcp.c | 12 ++++++++++++
 hw/arm/realview.c     | 12 ++++++++++++
 hw/arm/versatilepb.c  | 12 ++++++++++++
 hw/arm/xilinx_zynq.c  | 12 ++++++++++++
 6 files changed, 71 insertions(+)

thanks
-- PMM

#36 lore raw

Re: [Qemu-devel] [PATCH v2 14/15] target-arm: Disable EL3 on unsupported machines

Should the has_el3 property errors on these machines also be silent (will break -cpu host).

Greg

Quoted 22 lines · Peter Maydell
Quoted 5 lines · Greg Bellows

Disables the CPU ARM_FEATURE_EL3 featuere on machine models that can be configured to use Cortex-A9, Cortex-A15, and ARM1176 but don't officially support EL3. This preserves backwards compatibility.

Quoted 8 lines
---
 hw/arm/exynos4210.c   | 11 +++++++++++
 hw/arm/highbank.c     | 12 ++++++++++++
 hw/arm/integratorcp.c | 12 ++++++++++++
 hw/arm/realview.c     | 12 ++++++++++++
 hw/arm/versatilepb.c  | 12 ++++++++++++
 hw/arm/xilinx_zynq.c  | 12 ++++++++++++
 6 files changed, 71 insertions(+)

thanks
-- PMM

#37 lore raw

Re: [Qemu-devel] [PATCH v2 14/15] target-arm: Disable EL3 on unsupported machines

Quoted 2 lines · Greg Bellows

Should the has_el3 property errors on these machines also be silent (will break -cpu host).

All the ones in this patch use the

    if (object_property_find(OBJECT(cpu), "has_el3", NULL)) {
        object_property_set_bool(OBJECT(cpu), false, "has_el3", &err);
        ...
    }

pattern, which is fine, because -cpu host (and other non-EL3 CPUs like cortex-a57) will not have the property and we'll silently continue as we should. It's only the vexpress and virt boards where you made it fail on the property not existing.

-- PMM

#38 lore raw

PATCH v2 15/15 target-arm: add cpu feature EL3 to CPUs with Security Extensions

In reply to Greg Bellows

From: Fabian Aggeler <[email protected]>

Set ARM_FEATURE_EL3 feature for CPUs that implement Security Extensions.

---
 target-arm/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target-arm/cpu.c +4 -0
index 758e8f8..cb89ee2 100644
@@ -669,6 +669,7 @@ static void arm1176_initfn(Object *obj)
     set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
     set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
     set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
+    set_feature(&cpu->env, ARM_FEATURE_EL3);
     cpu->midr = 0x410fb767;
     cpu->reset_fpsid = 0x410120b5;
     cpu->mvfr0 = 0x11111111;
@@ -757,6 +758,7 @@ static void cortex_a8_initfn(Object *obj)
     set_feature(&cpu->env, ARM_FEATURE_NEON);
     set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
     set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
+    set_feature(&cpu->env, ARM_FEATURE_EL3);
     cpu->midr = 0x410fc080;
     cpu->reset_fpsid = 0x410330c0;
     cpu->mvfr0 = 0x11110222;
@@ -824,6 +826,7 @@ static void cortex_a9_initfn(Object *obj)
     set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
     set_feature(&cpu->env, ARM_FEATURE_NEON);
     set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
+    set_feature(&cpu->env, ARM_FEATURE_EL3);
     /* Note that A9 supports the MP extensions even for
      * A9UP and single-core A9MP (which are both different
      * and valid configurations; we don't model A9UP).
@@ -891,6 +894,7 @@ static void cortex_a15_initfn(Object *obj)
     set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
     set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
     set_feature(&cpu->env, ARM_FEATURE_LPAE);
+    set_feature(&cpu->env, ARM_FEATURE_EL3);
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
     cpu->midr = 0x412fc0f1;
     cpu->reset_fpsid = 0x410430f0;
Signature · 1 line
1.8.3.2