Skip to contentSkip to conversation

xlnx-zynqmp: Fix various issues with KVM runs

PATCH Superseded Edgar E. Iglesias 3 participants 16 messages May 19, 2016 – May 24, 2016 Arm/Zynq architecture

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover xlnx-zynqmp: Fix various issues with KVM runs

From: "Edgar E. Iglesias" <[email protected]>

(This is a resend of the same v1, I managed to typo my own work email address in CC in the first send-email :-))

This series fixes a bunch of issues with KVM runs using the ZynqMP machine.

When using KVM, we don't have support for TrustZone, the RPU subsystem with Cortex R5s and we also need to use the in-kernel GIC model.

This adds a set of properties to the ZynqMP allowing the creation of the KVM friendly machine.

I've opted to default the ZynqMP to the KVM friendly machine for consistensy between KVM and TCG and also because some of the options are currently of limited use (i.e the RPU) or were actually disabled to start with (e.g TrustZone sneaked in as we enabled EL3 on the A53s). I'm OK either way though, so if people think differently we can change the defaults.

Comments welcome!

Cheers,
Edgar

Edgar E. Iglesias (5):
xlnx-zynqmp: Add a secure prop to en/disable ARM Security Extensions
xlnx-zynqmp: Break out RPU setup into a separate function
xlnx-zynqmp: Make the RPU subsystem optional
xlnx-zynqmp: Delay realization of GIC until post CPU realization
xlnx-zynqmp: Use the in kernel GIC model for KVM runs

 hw/arm/xlnx-zynqmp.c         | 156 +++++++++++++++++++++++++++++--------------
 include/hw/arm/xlnx-zynqmp.h |   5 ++
 2 files changed, 110 insertions(+), 51 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/5 xlnx-zynqmp: Add a secure prop to en/disable ARM Security Extensions

From: "Edgar E. Iglesias" <[email protected]>

Add a secure prop to en/disable ARM Security Extensions. This is particulary useful for KVM runs.

Default to disabled to match the behavior of KVM.

---
 hw/arm/xlnx-zynqmp.c         | 3 +++
 include/hw/arm/xlnx-zynqmp.h | 3 +++
 2 files changed, 6 insertions(+)
hw/arm/xlnx-zynqmp.c +3 -0
index 4d504da..965a250 100644
@@ -238,6 +238,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
         }
         g_free(name);
 
+        object_property_set_bool(OBJECT(&s->apu_cpu[i]),
+                                 s->secure, "has_el3", NULL);
         object_property_set_int(OBJECT(&s->apu_cpu[i]), GIC_BASE_ADDR,
                                 "reset-cbar", &error_abort);
         object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "realized",
@@ -370,6 +372,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
 
 static Property xlnx_zynqmp_props[] = {
     DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
+    DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
     DEFINE_PROP_END_OF_LIST()
 };
 
include/hw/arm/xlnx-zynqmp.h +3 -0
index 2332596..38d4c8c 100644
@@ -84,6 +84,9 @@ typedef struct XlnxZynqMPState {
 
     char *boot_cpu;
     ARMCPU *boot_cpu_ptr;
+
+    /* Has the ARM Security extensions?  */
+    bool secure;
 }  XlnxZynqMPState;
 
 #define XLNX_ZYNQMP_H
Signature · 1 line
2.5.0
#2 lore raw

Re: [Qemu-arm] [PATCH v1 1/5] xlnx-zynqmp: Add a secure prop to en/disable ARM Security Extensions

Quoted 4 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Add a secure prop to en/disable ARM Security Extensions. This is particulary useful for KVM runs.

"particularly"

Quoted 1 line

Default to disabled to match the behavior of KVM.

This is a change in behaviour, though, right? Is that OK?

Quoted 32 lines
---
 hw/arm/xlnx-zynqmp.c         | 3 +++
 include/hw/arm/xlnx-zynqmp.h | 3 +++
 2 files changed, 6 insertions(+)
hw/arm/xlnx-zynqmp.c +3 -0
index 4d504da..965a250 100644
@@ -238,6 +238,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
         }
         g_free(name);
 
+        object_property_set_bool(OBJECT(&s->apu_cpu[i]),
+                                 s->secure, "has_el3", NULL);
         object_property_set_int(OBJECT(&s->apu_cpu[i]), GIC_BASE_ADDR,
                                 "reset-cbar", &error_abort);
         object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "realized",
@@ -370,6 +372,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
 
 static Property xlnx_zynqmp_props[] = {
     DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
+    DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
     DEFINE_PROP_END_OF_LIST()
 };
 
include/hw/arm/xlnx-zynqmp.h +0 -0
index 2332596..38d4c8c 100644

include/hw/arm/xlnx-zynqmp.h typedef struct XlnxZynqMPState { · line 90

Quoted 7 lines
include/hw/arm/xlnx-zynqmp.h +3 -0
@@ -84,6 +84,9 @@ typedef struct XlnxZynqMPState {
 
     char *boot_cpu;
     ARMCPU *boot_cpu_ptr;
+
+    /* Has the ARM Security extensions?  */
+    bool secure;
 }  XlnxZynqMPState;

thanks
-- PMM

#3 lore raw

Re: [Qemu-arm] [PATCH v1 1/5] xlnx-zynqmp: Add a secure prop to en/disable ARM Security Extensions

Quoted 11 lines · Peter Maydell
Quoted 4 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Add a secure prop to en/disable ARM Security Extensions. This is particulary useful for KVM runs.

"particularly"

Quoted 1 line

Default to disabled to match the behavior of KVM.

This is a change in behaviour, though, right? Is that OK?

IMO it's OK. But I don't have a very strong opinion. We didn't have EL3 in this machine to start with, it came in when we enabled it on the a53. We don't have a big user-base that really depends on either default I'd say.

Best regards,
Edgar

Quoted 43 lines
Quoted 33 lines
---
 hw/arm/xlnx-zynqmp.c         | 3 +++
 include/hw/arm/xlnx-zynqmp.h | 3 +++
 2 files changed, 6 insertions(+)
hw/arm/xlnx-zynqmp.c +3 -0
index 4d504da..965a250 100644
@@ -238,6 +238,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
         }
         g_free(name);
 
+        object_property_set_bool(OBJECT(&s->apu_cpu[i]),
+                                 s->secure, "has_el3", NULL);
         object_property_set_int(OBJECT(&s->apu_cpu[i]), GIC_BASE_ADDR,
                                 "reset-cbar", &error_abort);
         object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "realized",
@@ -370,6 +372,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
 
 static Property xlnx_zynqmp_props[] = {
     DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
+    DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
     DEFINE_PROP_END_OF_LIST()
 };
 
include/hw/arm/xlnx-zynqmp.h +0 -0
index 2332596..38d4c8c 100644

include/hw/arm/xlnx-zynqmp.h typedef struct XlnxZynqMPState { · line 90

Quoted 7 lines
include/hw/arm/xlnx-zynqmp.h +3 -0
@@ -84,6 +84,9 @@ typedef struct XlnxZynqMPState {
 
     char *boot_cpu;
     ARMCPU *boot_cpu_ptr;
+
+    /* Has the ARM Security extensions?  */
+    bool secure;
 }  XlnxZynqMPState;

thanks
-- PMM

#4 lore raw

Re: [Qemu-arm] [PATCH v1 1/5] xlnx-zynqmp: Add a secure prop to en/disable ARM Security Extensions

Quoted 9 lines · Edgar E. Iglesias
Quoted 8 lines · Peter Maydell
Quoted 4 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Add a secure prop to en/disable ARM Security Extensions. This is particulary useful for KVM runs.

"particularly"

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Default to disabled to match the behavior of KVM.

This is a change in behaviour, though, right? Is that OK?

IMO it's OK. But I don't have a very strong opinion. We didn't have EL3 in this machine to start with, it came in when we enabled it on the a53. We don't have a big user-base that really depends on either default I'd say.

I'll defer to your preference, but we should mention in the commit message that we changed the behaviour (and perhaps also that it was accidental that EL3 got enabled).

thanks
-- PMM

#5 lore raw

PATCH 2/5 xlnx-zynqmp: Break out RPU setup into a separate function

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Break out RPU setup into a separate function. This is in preparation for making the RPU optional.

No functional change.

---
 hw/arm/xlnx-zynqmp.c | 53 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 22 deletions(-)
hw/arm/xlnx-zynqmp.c +31 -22
index 965a250..250ecc4 100644
@@ -83,6 +83,36 @@ static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
 }
 
+static void xlnx_zynqmp_setup_rpu(XlnxZynqMPState *s, const char *boot_cpu,
+                                  Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
+        char *name;
+
+        name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i]));
+        if (strcmp(name, boot_cpu)) {
+            /* Secondary CPUs start in PSCI powered-down state */
+            object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true,
+                                     "start-powered-off", &error_abort);
+        } else {
+            s->boot_cpu_ptr = &s->rpu_cpu[i];
+        }
+        g_free(name);
+
+        object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "reset-hivecs",
+                                 &error_abort);
+        object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "realized",
+                                 &err);
+        if (err) {
+            error_propagate(errp, err);
+            return;
+        }
+    }
+}
+
 static void xlnx_zynqmp_init(Object *obj)
 {
     XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
@@ -260,28 +290,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 1, irq);
     }
 
-    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
-        char *name;
-
-        name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i]));
-        if (strcmp(name, boot_cpu)) {
-            /* Secondary CPUs start in PSCI powered-down state */
-            object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true,
-                                     "start-powered-off", &error_abort);
-        } else {
-            s->boot_cpu_ptr = &s->rpu_cpu[i];
-        }
-        g_free(name);
-
-        object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "reset-hivecs",
-                                 &error_abort);
-        object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "realized",
-                                 &err);
-        if (err) {
-            error_propagate(errp, err);
-            return;
-        }
-    }
+    xlnx_zynqmp_setup_rpu(s, boot_cpu, errp);
 
     if (!s->boot_cpu_ptr) {
         error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu);
Signature · 1 line
2.5.0
#6 lore raw

Re: [Qemu-devel] [PATCH v1 2/5] xlnx-zynqmp: Break out RPU setup into a separate function

Quoted 36 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Break out RPU setup into a separate function. This is in preparation for making the RPU optional.

No functional change.

---
 hw/arm/xlnx-zynqmp.c | 53 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 22 deletions(-)
hw/arm/xlnx-zynqmp.c +16 -0
index 965a250..250ecc4 100644
@@ -83,6 +83,36 @@ static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
 }
 
+static void xlnx_zynqmp_setup_rpu(XlnxZynqMPState *s, const char *boot_cpu,
+                                  Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
+        char *name;
+
+        name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i]));
+        if (strcmp(name, boot_cpu)) {
+            /* Secondary CPUs start in PSCI powered-down state */
+            object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true,
+                                     "start-powered-off", &error_abort);
+        } else {
+            s->boot_cpu_ptr = &s->rpu_cpu[i];

hw/arm/xlnx-zynqmp.c static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) · line 111

Quoted 10 lines
hw/arm/xlnx-zynqmp.c +10 -0
+        }
+        g_free(name);
+
+        object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "reset-hivecs",
+                                 &error_abort);
+        object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "realized",
+                                 &err);
+        if (err) {
+            error_propagate(errp, err);
+            return;

This used to return from xlnz_zynqmp_init, but now it only returns from this setup function, and xlnx_zynqmp_init will blithely continue.

hw/arm/xlnx-zynqmp.c static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) · line 113

Quoted 3 lines
hw/arm/xlnx-zynqmp.c +3 -0
+        }
+    }
+}

thanks
-- PMM

#7 lore raw

PATCH 3/5 xlnx-zynqmp: Make the RPU subsystem optional

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

The way we currently model the RPU subsystem is of quite limited use. In addition to that, it causes problems for KVM and for GDB debugging.

Make the RPU optional by adding a has_rpu property and default to having it disabled.

---
 hw/arm/xlnx-zynqmp.c         | 50 +++++++++++++++++++++++++++++++++++++-------
 include/hw/arm/xlnx-zynqmp.h |  2 ++
 2 files changed, 44 insertions(+), 8 deletions(-)
hw/arm/xlnx-zynqmp.c +42 -8
index 250ecc4..c180206 100644
@@ -83,6 +83,40 @@ static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
 }
 
+static bool xlnx_zynqmp_get_has_rpu(Object *obj, Error **errp)
+{
+    XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
+
+    return s->has_rpu;
+}
+
+static void xlnx_zynqmp_set_has_rpu(Object *obj, bool value, Error **errp)
+{
+    XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
+    int i;
+
+    if (s->has_rpu == value) {
+        /* Nothing to do.  */
+        return;
+    }
+
+    /* We don't support clearing the flag.  */
+    if (s->has_rpu) {
+        error_setg(errp, "has_rpu is already set to %u",
+                   s->has_rpu);
+        return;
+    }
+
+    /* Create the Cortex R5s.  */
+    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
+        object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
+                          "cortex-r5-" TYPE_ARM_CPU);
+        object_property_add_child(obj, "rpu-cpu[*]", OBJECT(&s->rpu_cpu[i]),
+                                  &error_abort);
+    }
+    s->has_rpu = value;
+}
+
 static void xlnx_zynqmp_setup_rpu(XlnxZynqMPState *s, const char *boot_cpu,
                                   Error **errp)
 {
@@ -118,6 +152,11 @@ static void xlnx_zynqmp_init(Object *obj)
     XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
     int i;
 
+    object_property_add_bool(obj, "has_rpu",
+                             xlnx_zynqmp_get_has_rpu,
+                             xlnx_zynqmp_set_has_rpu,
+                             &error_abort);
+
     for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
         object_initialize(&s->apu_cpu[i], sizeof(s->apu_cpu[i]),
                           "cortex-a53-" TYPE_ARM_CPU);
@@ -125,13 +164,6 @@ static void xlnx_zynqmp_init(Object *obj)
                                   &error_abort);
     }
 
-    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
-        object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
-                          "cortex-r5-" TYPE_ARM_CPU);
-        object_property_add_child(obj, "rpu-cpu[*]", OBJECT(&s->rpu_cpu[i]),
-                                  &error_abort);
-    }
-
     object_property_add_link(obj, "ddr-ram", TYPE_MEMORY_REGION,
                              (Object **)&s->ddr_ram,
                              qdev_prop_allow_set_link_before_realize,
@@ -290,7 +322,9 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 1, irq);
     }
 
-    xlnx_zynqmp_setup_rpu(s, boot_cpu, errp);
+    if (s->has_rpu) {
+        xlnx_zynqmp_setup_rpu(s, boot_cpu, errp);
+    }
 
     if (!s->boot_cpu_ptr) {
         error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu);
include/hw/arm/xlnx-zynqmp.h +2 -0
index 38d4c8c..68f6eb0 100644
@@ -87,6 +87,8 @@ typedef struct XlnxZynqMPState {
 
     /* Has the ARM Security extensions?  */
     bool secure;
+    /* Has the RPU subsystem?  */
+    bool has_rpu;
 }  XlnxZynqMPState;
 
 #define XLNX_ZYNQMP_H
Signature · 1 line
2.5.0
#8 lore raw

Re: [Qemu-arm] [PATCH v1 3/5] xlnx-zynqmp: Make the RPU subsystem optional

Quoted 44 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

The way we currently model the RPU subsystem is of quite limited use. In addition to that, it causes problems for KVM and for GDB debugging.

Make the RPU optional by adding a has_rpu property and default to having it disabled.

---
 hw/arm/xlnx-zynqmp.c         | 50 +++++++++++++++++++++++++++++++++++++-------
 include/hw/arm/xlnx-zynqmp.h |  2 ++
 2 files changed, 44 insertions(+), 8 deletions(-)
hw/arm/xlnx-zynqmp.c +21 -0
index 250ecc4..c180206 100644
@@ -83,6 +83,40 @@ static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
 }
 
+static bool xlnx_zynqmp_get_has_rpu(Object *obj, Error **errp)
+{
+    XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
+
+    return s->has_rpu;
+}
+
+static void xlnx_zynqmp_set_has_rpu(Object *obj, bool value, Error **errp)
+{
+    XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
+    int i;
+
+    if (s->has_rpu == value) {
+        /* Nothing to do.  */
+        return;
+    }
+
+    /* We don't support clearing the flag.  */
+    if (s->has_rpu) {
+        error_setg(errp, "has_rpu is already set to %u",
+                   s->has_rpu);

hw/arm/xlnx-zynqmp.c static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) · line 116

Quoted 10 lines
hw/arm/xlnx-zynqmp.c +10 -0
+        return;
+    }
+
+    /* Create the Cortex R5s.  */
+    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
+        object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
+                          "cortex-r5-" TYPE_ARM_CPU);
+        object_property_add_child(obj, "rpu-cpu[*]", OBJECT(&s->rpu_cpu[i]),
+                                  &error_abort);
+    }

Do we have to create them in the set function so we can set properties before realize, or could this be deferred to realize time?

thanks
-- PMM

#9 lore raw

Re: [Qemu-arm] [PATCH v1 3/5] xlnx-zynqmp: Make the RPU subsystem optional

Quoted 51 lines · Peter Maydell
Quoted 50 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

The way we currently model the RPU subsystem is of quite limited use. In addition to that, it causes problems for KVM and for GDB debugging.

Make the RPU optional by adding a has_rpu property and default to having it disabled.

---
 hw/arm/xlnx-zynqmp.c         | 50 +++++++++++++++++++++++++++++++++++++-------
 include/hw/arm/xlnx-zynqmp.h |  2 ++
 2 files changed, 44 insertions(+), 8 deletions(-)
hw/arm/xlnx-zynqmp.c +27 -0
index 250ecc4..c180206 100644
@@ -83,6 +83,40 @@ static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
 }
 
+static bool xlnx_zynqmp_get_has_rpu(Object *obj, Error **errp)
+{
+    XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
+
+    return s->has_rpu;
+}
+
+static void xlnx_zynqmp_set_has_rpu(Object *obj, bool value, Error **errp)
+{
+    XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
+    int i;
+
+    if (s->has_rpu == value) {
+        /* Nothing to do.  */
+        return;
+    }
+
+    /* We don't support clearing the flag.  */
+    if (s->has_rpu) {
+        error_setg(errp, "has_rpu is already set to %u",
+                   s->has_rpu);
+        return;
+    }
+
+    /* Create the Cortex R5s.  */
+    for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
+        object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
Quoted 8 lines

hw/arm/xlnx-zynqmp.c static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) · line 116

Quoted 4 lines
hw/arm/xlnx-zynqmp.c +4 -0
+                          "cortex-r5-" TYPE_ARM_CPU);
+        object_property_add_child(obj, "rpu-cpu[*]", OBJECT(&s->rpu_cpu[i]),
+                                  &error_abort);
+    }

Do we have to create them in the set function so we can set properties before realize, or could this be deferred to realize time?

Yes, I thought it was recommended to avoid object creation in realize. But creating the PRU in realize works too.

Cheers,
Edgar

#10 lore raw

Re: [Qemu-arm] [PATCH v1 3/5] xlnx-zynqmp: Make the RPU subsystem optional

Quoted 7 lines · Edgar E. Iglesias
Quoted 3 lines · Peter Maydell

Do we have to create them in the set function so we can set properties before realize, or could this be deferred to realize time?

Yes, I thought it was recommended to avoid object creation in realize. But creating the PRU in realize works too.

Well, it is recommended, but only in the sense of "prefer to do it in instance init" :-) I think we prefer not to have complicated behaviours happening on property-set because it's a bit unexpected (but sometimes it's necessary if later property-sets wouldn't work otherwise).

thanks
-- PMM

#11 lore raw

Re: [Qemu-arm] [PATCH v1 3/5] xlnx-zynqmp: Make the RPU subsystem optional

Quoted 6 lines · Peter Maydell
Quoted 5 lines · Edgar E. Iglesias
Quoted 3 lines · Peter Maydell

Do we have to create them in the set function so we can set properties before realize, or could this be deferred to realize time?

Quoted 8 lines
Quoted 2 lines

Yes, I thought it was recommended to avoid object creation in realize. But creating the PRU in realize works too.

Well, it is recommended, but only in the sense of "prefer to do it in instance init" :-) I think we prefer not to have complicated behaviours happening on property-set because it's a bit unexpected (but sometimes it's necessary if later property-sets wouldn't work otherwise).

Allright, I'm happy to change it. It definitely simplifies the code.

Cheers,
Edgar

#12 lore raw

PATCH 4/5 xlnx-zynqmp: Delay realization of GIC until post CPU realization

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Delay the realization of the GIC until after CPUs are realized. This is needed for KVM as the in-kernel GIC model will fail if it is realized with no available CPUs.

---
 hw/arm/xlnx-zynqmp.c | 56 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 25 deletions(-)
hw/arm/xlnx-zynqmp.c +31 -25
index c180206..0648028 100644
@@ -258,33 +258,9 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
     qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32);
     qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
     qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", XLNX_ZYNQMP_NUM_APU_CPUS);
-    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
-    assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS);
-    for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) {
-        SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic);
-        const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i];
-        MemoryRegion *mr = sysbus_mmio_get_region(gic, r->region_index);
-        uint32_t addr = r->address;
-        int j;
-
-        sysbus_mmio_map(gic, r->region_index, addr);
-
-        for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) {
-            MemoryRegion *alias = &s->gic_mr[i][j];
-
-            addr += XLNX_ZYNQMP_GIC_REGION_SIZE;
-            memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr,
-                                     0, XLNX_ZYNQMP_GIC_REGION_SIZE);
-            memory_region_add_subregion(system_memory, addr, alias);
-        }
-    }
 
+    /* Realize APUs before realizing the GIC. KVM requires this.  */
     for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
-        qemu_irq irq;
         char *name;
 
         object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC,
@@ -310,6 +286,36 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
             error_propagate(errp, err);
             return;
         }
+    }
+
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS);
+    for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) {
+        SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic);
+        const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i];
+        MemoryRegion *mr = sysbus_mmio_get_region(gic, r->region_index);
+        uint32_t addr = r->address;
+        int j;
+
+        sysbus_mmio_map(gic, r->region_index, addr);
+
+        for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) {
+            MemoryRegion *alias = &s->gic_mr[i][j];
+
+            addr += XLNX_ZYNQMP_GIC_REGION_SIZE;
+            memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr,
+                                     0, XLNX_ZYNQMP_GIC_REGION_SIZE);
+            memory_region_add_subregion(system_memory, addr, alias);
+        }
+    }
+
+    for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
+        qemu_irq irq;
 
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
                            qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
Signature · 1 line
2.5.0
Reviewed-by on v1 4/5
#13 lore raw

Re: [Qemu-arm] [PATCH v1 4/5] xlnx-zynqmp: Delay realization of GIC until post CPU realization

Quoted 7 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Delay the realization of the GIC until after CPUs are realized. This is needed for KVM as the in-kernel GIC model will fail if it is realized with no available CPUs.

thanks
-- PMM

#14 lore raw

PATCH 5/5 xlnx-zynqmp: Use the in kernel GIC model for KVM runs

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Use the in kernel GIC model when running with KVM enabled.

---
 hw/arm/xlnx-zynqmp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/xlnx-zynqmp.c +3 -1
index 0648028..c3878da 100644
@@ -22,6 +22,8 @@
 #include "hw/arm/xlnx-zynqmp.h"
 #include "hw/intc/arm_gic_common.h"
 #include "exec/address-spaces.h"
+#include "sysemu/kvm.h"
+#include "kvm_arm.h"
 
 #define GIC_NUM_SPI_INTR 160
 
@@ -169,7 +171,7 @@ static void xlnx_zynqmp_init(Object *obj)
                              qdev_prop_allow_set_link_before_realize,
                              OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
 
-    object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC);
+    object_initialize(&s->gic, sizeof(s->gic), gic_class_name());
     qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
 
     for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
Signature · 1 line
2.5.0