Skip to contentSkip to conversation

target-arm: ARM64: Adding EL1 AARCH32 guest support

PATCH Superseded Greg Bellows 6 participants 26 messages Jan 19, 2015 – Jan 21, 2015

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover target-arm: ARM64: Adding EL1 AARCH32 guest support

Added support for running an AArch32 guest on a AArch64 KVM host. Support has only been added to the QEMU machvirt machine. The addition of CPU properties specifiable from the command line were added to allow disablement of AArch64 execution state hereby forcing EL1 to be AArch32. The new CPU command line propoerty is "-aarch64" that is specified as follows:

    aarch64-softmmu/qemu-system-aarch64 -M virt -cpu cortex-a57,-aarch64 ...

Support also added to support uncompressed images (Image) for aarch32.

Greg Bellows (5):
target-arm: Add ARM CPU feature parsing
target-arm: Add feature parsing to virt
target-arm: Add 32/64-bit register sync
target-arm: Add AArch32 guest support to KVM64
target-arm: Adjust kernel load address for Image

 hw/arm/boot.c           | 33 +++++++++++++++++-
 hw/arm/virt.c           | 21 ++++++++++--
 target-arm/cpu.c        | 45 ++++++++++++++++++++++++-
 target-arm/helper-a64.c |  5 +--
 target-arm/internals.h  | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/kvm64.c      | 21 +++++++++---
 target-arm/op_helper.c  |  6 ++--
 7 files changed, 204 insertions(+), 16 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/5 target-arm: Add ARM CPU feature parsing

Adds a CPU feature parsing function and assigns to the CPU class. The only feature added was "-aarch64" which disabled the AArch64 execution state on a 64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the ARM CPU by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +44 -1
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {
+            if (!strcmp(featurestr+1, "aarch64")) {
+                /* If AArch64 is disabled then we need to unset the feature */
+                unset_feature(&cpu->env, ARM_FEATURE_AARCH64);
+            } else {
+                /* Everyting else is unsupported */
+                error_setg(errp, "unsupported CPU property '%s'",
+                           &featurestr[1]);
+                return;
+            }
+        } else if (featurestr[0] == '+') {
+            /* No '+' properties supported yet */
+            error_setg(errp, "unsupported CPU property '%s'",
+                       &featurestr[1]);
+            return;
+        } else if (g_strstr_len(featurestr, -1, "=")) {
+            /* No '=' properties supported yet */
+            char *prop = strtok(featurestr, "=");
+            error_setg(errp, "unsupported CPU property '%s'", prop);
+            return;
+        } else {
+            /* Everything else is a bad format */
+            error_setg(errp, "CPU property string '%s' not in format "
+                             "(+feature|-feature|feature=xyz)", featurestr);
+            return;
+        }
+        featurestr = strtok(NULL, ",");
+    }
+}
+
 static void arm_cpu_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
@@ -1183,6 +1225,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
+    cc->parse_features = arm_cpu_parse_features;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
Signature · 1 line
1.8.3.2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 23 lines · Greg Bellows

Adds a CPU feature parsing function and assigns to the CPU class. The only feature added was "-aarch64" which disabled the AArch64 execution state on a 64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the ARM CPU by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +1 -0
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {

target-arm/cpu.c static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) · line 528

Quoted 10 lines
target-arm/cpu.c +4 -1
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);

Aren't we leaking here? strtok returns the next token (or NULL) so don't we loose the original ptr?

Also while using glib you might want to consider using glib's own tokenising functions (e.g. g_strsplit). This has the advantage of having helper functions like g_strfreev() which can clean-up everything in one go.

Quoted 33 lines
target-arm/cpu.c +27 -0
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {
+            if (!strcmp(featurestr+1, "aarch64")) {
+                /* If AArch64 is disabled then we need to unset the feature */
+                unset_feature(&cpu->env, ARM_FEATURE_AARCH64);
+            } else {
+                /* Everyting else is unsupported */
+                error_setg(errp, "unsupported CPU property '%s'",
+                           &featurestr[1]);
+                return;
+            }
+        } else if (featurestr[0] == '+') {
+            /* No '+' properties supported yet */
+            error_setg(errp, "unsupported CPU property '%s'",
+                       &featurestr[1]);
+            return;
+        } else if (g_strstr_len(featurestr, -1, "=")) {
+            /* No '=' properties supported yet */
+            char *prop = strtok(featurestr, "=");
+            error_setg(errp, "unsupported CPU property '%s'", prop);

target-arm/cpu.c static Property arm_cpu_properties[] = { · line 1206

Quoted 10 lines
target-arm/cpu.c +10 -0
+            return;
+        } else {
+            /* Everything else is a bad format */
+            error_setg(errp, "CPU property string '%s' not in format "
+                             "(+feature|-feature|feature=xyz)", featurestr);
+            return;
+        }
+        featurestr = strtok(NULL, ",");
+    }
+}

I only point to this for reference to a "gliby" approach to the parsing, relative beauty being in the eye of the beholder ;-)

https://github.com/stsquad/qemu/commit/86bc88f661141b93cbe5b107c4d5b4322b563241#diff-286aa0f2c1f0d862c4197781280a92efR116

It does make me think boilerplate but I wonder if this is a generic enough problem to be solved more generally in QEMU?

Quoted 12 lines
target-arm/cpu.c +2 -0
+
 static void arm_cpu_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
@@ -1183,6 +1225,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
+    cc->parse_features = arm_cpu_parse_features;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
Signature · 1 line
Alex Bennée
#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Thanks Alex comments inline....

Quoted 41 lines · Alex Bennée
Quoted 1 line · Greg Bellows

Adds a CPU feature parsing function and assigns to the CPU class. The

only

Quoted 1 line

feature added was "-aarch64" which disabled the AArch64 execution state

on a

Quoted 3 lines

64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the

ARM CPU

target-arm/cpu.c static ObjectClass *arm_cpu_class_by_name(const

Quoted 12 lines

by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +0 -0
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const

char *cpu_model)

Quoted 6 lines
target-arm/cpu.c +1 -0
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {

target-arm/cpu.c static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) · line 528

Quoted 10 lines
target-arm/cpu.c +4 -1
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);
Quoted 4 lines

Aren't we leaking here? strtok returns the next token (or NULL) so don't we loose the original ptr?

​As I understand it, strtok uses static pointers to track the location within an existing string rather than allocating storage that the user must free. This is apparently what makes the version I used non-reentrant.​ In which case, there should not be an leak due to its use.

Quoted 4 lines

Also while using glib you might want to consider using glib's own tokenising functions (e.g. g_strsplit). This has the advantage of having helper functions like g_strfreev() which can clean-up everything in one go.

​I certainly can use the glib version, but in this case I did not see the advantage. In fact, it actually may be less performant​ to use the glib version given it needs to allocate/free memory. I am fine either way if anyone feels strongly.

Quoted 47 lines
Quoted 8 lines
target-arm/cpu.c +1 -0
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,

target-arm/cpu.c static Property arm_cpu_properties[] = { · line 1180

Quoted 10 lines
target-arm/cpu.c +10 -0
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {
+            if (!strcmp(featurestr+1, "aarch64")) {
+                /* If AArch64 is disabled then we need to unset the

feature */

Quoted 11 lines
target-arm/cpu.c +11 -0
+                unset_feature(&cpu->env, ARM_FEATURE_AARCH64);
+            } else {
+                /* Everyting else is unsupported */
+                error_setg(errp, "unsupported CPU property '%s'",
+                           &featurestr[1]);
+                return;
+            }
+        } else if (featurestr[0] == '+') {
+            /* No '+' properties supported yet */
+            error_setg(errp, "unsupported CPU property '%s'",
+                       &featurestr[1]);

target-arm/cpu.c static Property arm_cpu_properties[] = {

Quoted 10 lines
target-arm/cpu.c +10 -0
+            return;
+        } else if (g_strstr_len(featurestr, -1, "=")) {
+            /* No '=' properties supported yet */
+            char *prop = strtok(featurestr, "=");
+            error_setg(errp, "unsupported CPU property '%s'", prop);
+            return;
+        } else {
+            /* Everything else is a bad format */
+            error_setg(errp, "CPU property string '%s' not in format "
+                             "(+feature|-feature|feature=xyz)",

featurestr);

target-arm/cpu.c static Property arm_cpu_properties[] = { · line 1206

Quoted 5 lines
target-arm/cpu.c +5 -0
+            return;
+        }
+        featurestr = strtok(NULL, ",");
+    }
+}
Quoted 9 lines

I only point to this for reference to a "gliby" approach to the parsing, relative beauty being in the eye of the beholder ;-)

https://github.com/stsquad/qemu/commit/86bc88f661141b93cbe5b107c4d5b4322b563241#diff-286aa0f2c1f0d862c4197781280a92efR116

It does make me think boilerplate but I wonder if this is a generic enough problem to be solved more generally in QEMU?

If we were to go with a boilerplate approach then it would make sense to follow the mechanism used for machine properties. However, this was how other arch were doing the CPU props, so we stuck to this approach. It does look very similar to the code you pointed at, but I think that the conditional piece looking for {+-=} would bt the only common piece once you add unique options and handling.

Quoted 18 lines

target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc,

Quoted 6 lines
target-arm/cpu.c +1 -0
+
 static void arm_cpu_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
@@ -1183,6 +1225,7 @@ static void arm_cpu_class_init(ObjectClass *oc,

void *data)

target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc, void *data) · line 1231

Quoted 7 lines
target-arm/cpu.c +1 -0
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
+    cc->parse_features = arm_cpu_parse_features;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else

--
Alex Bennée

#4 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 2 lines · Greg Bellows

Thanks Alex comments inline....

<snip>

Quoted 9 lines
Quoted 5 lines

Aren't we leaking here? strtok returns the next token (or NULL) so don't we loose the original ptr?

​As I understand it, strtok uses static pointers to track the location within an existing string rather than allocating storage that the user must free. This is apparently what makes the version I used non-reentrant.​ In which case, there should not be an leak due to its use.

Yeah - I realised this after re-reading the man page. Non-re-entrant isn't a particular problem these days but it still feels dirty....

Quoted 9 lines
Quoted 4 lines

Also while using glib you might want to consider using glib's own tokenising functions (e.g. g_strsplit). This has the advantage of having helper functions like g_strfreev() which can clean-up everything in one go.

​I certainly can use the glib version, but in this case I did not see the advantage. In fact, it actually may be less performant​ to use the glib version given it needs to allocate/free memory. I am fine either way if anyone feels strongly.

I suspect this discussion is trumped by moving to the feat_foo=on/off parsing style referenced elsewhere so we can use common code.

Signature · 1 line
Alex Bennée
#5 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

In reply to Greg Bellows
Quoted 48 lines · On Mon, 19 Jan 2015 16:30:17 -0600 Greg Bellows <[email protected]> wrote:

Adds a CPU feature parsing function and assigns to the CPU class. The only feature added was "-aarch64" which disabled the AArch64 execution state on a 64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the ARM CPU by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +14 -1
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {

...

Quoted 1 line

+ } else if (featurestr[0] == '+') {

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

Quoted 22 lines
target-arm/cpu.c +10 -0
+            /* Everything else is a bad format */
+            error_setg(errp, "CPU property string '%s' not in format "
+                             "(+feature|-feature|feature=xyz)", featurestr);
 
 
+            return;
+        }
+        featurestr = strtok(NULL, ",");
+    }
+}
+
 static void arm_cpu_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
@@ -1183,6 +1225,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
+    cc->parse_features = arm_cpu_parse_features;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
#6 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 56 lines · Igor Mammedov
Quoted 1 line · On Mon, 19 Jan 2015 16:30:17 -0600 Greg Bellows <[email protected]> wrote:

Adds a CPU feature parsing function and assigns to the CPU class. The

only

Quoted 1 line

feature added was "-aarch64" which disabled the AArch64 execution state

on a

Quoted 3 lines

64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the

ARM CPU

target-arm/cpu.c static ObjectClass *arm_cpu_class_by_name(const

Quoted 12 lines

by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +0 -0
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const

char *cpu_model)

Quoted 31 lines
target-arm/cpu.c +14 -1
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {

...

Quoted 6 lines
Quoted 1 line

+ } else if (featurestr[0] == '+') {

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

​Thanks Igor. I was under the impression that the +/- notation was still relevant. Perhaps it makes the most sense to convert to using object properties similar to how machine options are specified? ​What do you think Peter?

Quoted 26 lines

target-arm/cpu.c static Property arm_cpu_properties[] = {

Quoted 3 lines
target-arm/cpu.c +3 -0
+            /* Everything else is a bad format */
+            error_setg(errp, "CPU property string '%s' not in format "
+                             "(+feature|-feature|feature=xyz)",

featurestr);

target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc,

Quoted 10 lines
target-arm/cpu.c +6 -0
+            return;
+        }
+        featurestr = strtok(NULL, ",");
+    }
+}
+
 static void arm_cpu_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
@@ -1183,6 +1225,7 @@ static void arm_cpu_class_init(ObjectClass *oc,

void *data)

Quoted 7 lines
target-arm/cpu.c +1 -0
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
+    cc->parse_features = arm_cpu_parse_features;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
#7 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 64 lines · Greg Bellows
Quoted 56 lines · Igor Mammedov
Quoted 1 line · On Mon, 19 Jan 2015 16:30:17 -0600 Greg Bellows <[email protected]> wrote:

Adds a CPU feature parsing function and assigns to the CPU class. The

only

Quoted 1 line

feature added was "-aarch64" which disabled the AArch64 execution state

on a

Quoted 3 lines

64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the

ARM CPU

target-arm/cpu.c static ObjectClass *arm_cpu_class_by_name(const

Quoted 12 lines

by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +0 -0
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const

char *cpu_model)

Quoted 31 lines
target-arm/cpu.c +14 -1
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {

...

Quoted 6 lines
Quoted 1 line

+ } else if (featurestr[0] == '+') {

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

Quoted 4 lines

​Thanks Igor. I was under the impression that the +/- notation was still relevant. Perhaps it makes the most sense to convert to using object properties similar to how machine options are specified? ​What do you think Peter?

This is what we have been working on, on x86. "+FOO" should be translated to setting QOM property "feat-FOO=on" (note that you shouldn't need to use "feat-FOO" for the proeprty names, as you don't need to support the legacy +-feature format).

Signature · 1 line
Eduardo
#8 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

In reply to Greg Bellows
Quoted 64 lines · On Tue, 20 Jan 2015 09:34:39 -0600 Greg Bellows <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov
Quoted 1 line · On Mon, 19 Jan 2015 16:30:17 -0600 Greg Bellows <[email protected]> wrote:

Adds a CPU feature parsing function and assigns to the CPU class. The

only

Quoted 1 line

feature added was "-aarch64" which disabled the AArch64 execution state

on a

Quoted 3 lines

64-bit ARM CPU.

Also adds stripping of features from CPU model string in acquiring the

ARM CPU

target-arm/cpu.c static ObjectClass *arm_cpu_class_by_name(const

Quoted 12 lines

by name.

---
 target-arm/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.c +0 -0
index 285947f..f327dd7 100644
@@ -514,13 +514,17 @@ static ObjectClass *arm_cpu_class_by_name(const

char *cpu_model)

Quoted 31 lines
target-arm/cpu.c +14 -1
 {
     ObjectClass *oc;
     char *typename;
+    char *cpuname;
 
     if (!cpu_model) {
         return NULL;
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname);
     oc = object_class_by_name(typename);
+    g_free(cpuname);
     g_free(typename);
     if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
         object_class_is_abstract(oc)) {
@@ -1163,6 +1167,44 @@ static Property arm_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static void arm_cpu_parse_features(CPUState *cs, char *features,
+                                   Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    char *featurestr;
+
+    featurestr = features ? strtok(features, ",") : NULL;
+    while (featurestr) {
+        if (featurestr[0] == '-') {

...

Quoted 6 lines
Quoted 1 line

+ } else if (featurestr[0] == '+') {

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

Quoted 4 lines

​Thanks Igor. I was under the impression that the +/- notation was still relevant. Perhaps it makes the most sense to convert to using object properties similar to how machine options are specified? ​What do you think Peter?

Yep make features as object properties and reuse generic property parsing. Since you do not have to support legacy format, you actually do not need to define arm_cpu_parse_features() callback because foo=val format can be parsed by generic property parsing infrastructure.

Quoted 28 lines
Quoted 28 lines

target-arm/cpu.c static Property arm_cpu_properties[] = {

Quoted 5 lines
target-arm/cpu.c +3 -0
+            /* Everything else is a bad format */
+            error_setg(errp, "CPU property string '%s' not in format "
+                             "(+feature|-feature|feature=xyz)",

featurestr);

target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc,

Quoted 10 lines
target-arm/cpu.c +6 -0
+            return;
+        }
+        featurestr = strtok(NULL, ",");
+    }
+}
+
 static void arm_cpu_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
@@ -1183,6 +1225,7 @@ static void arm_cpu_class_init(ObjectClass *oc,

void *data)

Quoted 7 lines
target-arm/cpu.c +1 -0
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
+    cc->parse_features = arm_cpu_parse_features;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
 #else
#9 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

In reply to Igor Mammedov
Quoted 3 lines · Igor Mammedov

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

I thought this was the standard format for CPU features. Do you have an example of a CPU feature being set using foo=val format?

-- PMM

#10 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 7 lines · On Tue, 20 Jan 2015 15:34:23 +0000 Peter Maydell <[email protected]>…
Quoted 3 lines · Igor Mammedov

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

I thought this was the standard format for CPU features. Do you have an example of a CPU feature being set using foo=val format?

Currently on x86 we can use either legacy +foo1,-foo2,foo3 and in addition to it we ca use canonized format for generic properties like, foo1=on,foo2=off,foo3=on

We try to move out of legacy format, so that it would be possible to reuse generic property parsing infrastructure like with any device object. That would allow to use -device/device_add for CPUs.

Quoted 3 lines

-- PMM

#11 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 10 lines · Igor Mammedov
Quoted 7 lines · On Tue, 20 Jan 2015 15:34:23 +0000 Peter Maydell <[email protected]>…
Quoted 3 lines · Igor Mammedov

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

I thought this was the standard format for CPU features. Do you have an example of a CPU feature being set using foo=val format?

Quoted 7 lines

Currently on x86 we can use either legacy +foo1,-foo2,foo3 and in addition to it we ca use canonized format for generic properties like, foo1=on,foo2=off,foo3=on

We try to move out of legacy format, so that it would be possible to reuse generic property parsing infrastructure like with any device object. That would allow to use -device/device_add for CPUs.

-device/-device_add for CPUs is pretty fraught in the general case because there's no obvious place to plug them and have them be wired up properly. You'd need to use -global for CPU properties, which is a nightmare...

Anyway, I'm not particularly attached to the exact command line syntax we've used here -- I was just looking for "we have a CPU property, and use the same syntax for specifying CPU feature enable/disable that other CPUs do"...

-- PMM

#12 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 15 lines · On Tue, 20 Jan 2015 16:08:09 +0000 Peter Maydell <[email protected]>…
Quoted 14 lines · Igor Mammedov
Quoted 7 lines · On Tue, 20 Jan 2015 15:34:23 +0000 Peter Maydell <[email protected]>…
Quoted 3 lines · Igor Mammedov

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

I thought this was the standard format for CPU features. Do you have an example of a CPU feature being set using foo=val format?

Currently on x86 we can use either legacy +foo1,-foo2,foo3 and in addition to it we ca use canonized format for generic properties like, foo1=on,foo2=off,foo3=on

Quoted 7 lines
Quoted 3 lines

We try to move out of legacy format, so that it would be possible to reuse generic property parsing infrastructure like with any device object. That would allow to use -device/device_add for CPUs.

-device/-device_add for CPUs is pretty fraught in the general case because there's no obvious place to plug them and have them be wired up properly.

That depends on CPU of-cause, but we are close to having device_add working with x86 CPUs.

Quoted 2 lines

You'd need to use -global for CPU
properties, which is a nightmare...

mine thoughts on it were that '-cpu type,feat...' would eventually do conversion of features to global properties transparently for user using target specific cc->parse_features() callback. Which Greg could actually do here. We would happy to reuse it with x86 CPUs.

Quoted 5 lines

Anyway, I'm not particularly attached to the exact command line syntax we've used here -- I was just looking for "we have a CPU property, and use the same syntax for specifying CPU feature enable/disable that other CPUs do"...

Then '-cpu arm_foo,featX=on/off' should do the job.

Quoted 2 lines

-- PMM

#13 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 36 lines · Igor Mammedov
Quoted 15 lines · On Tue, 20 Jan 2015 16:08:09 +0000 Peter Maydell <[email protected]>…
Quoted 14 lines · Igor Mammedov
Quoted 7 lines · On Tue, 20 Jan 2015 15:34:23 +0000 Peter Maydell <[email protected]>…
Quoted 3 lines · Igor Mammedov

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

I thought this was the standard format for CPU features. Do you have an example of a CPU feature being set using foo=val format?

Currently on x86 we can use either legacy +foo1,-foo2,foo3 and in addition to it we ca use canonized format for generic properties like, foo1=on,foo2=off,foo3=on

Quoted 7 lines
Quoted 3 lines

We try to move out of legacy format, so that it would be possible to reuse generic property parsing infrastructure like with any device object. That would allow to use -device/device_add for CPUs.

-device/-device_add for CPUs is pretty fraught in the general case because there's no obvious place to plug them and have them be wired up properly.

That depends on CPU of-cause, but we are close to having device_add working with x86 CPUs.

Quoted 2 lines

You'd need to use -global for CPU
properties, which is a nightmare...

mine thoughts on it were that '-cpu type,feat...' would eventually do conversion of features to global properties transparently for user using target specific cc->parse_features() callback. Which Greg could actually do here. We would happy to reuse it with x86 CPUs.

Quoted 1 line
Quoted 10 lines
Quoted 4 lines

Anyway, I'm not particularly attached to the exact command line syntax we've used here -- I was just looking for "we have a CPU property, and use the same syntax for specifying CPU feature enable/disable that other CPUs do"...

Then '-cpu arm_foo,featX=on/off' should do the job.

Quoted 2 lines

-- PMM

For now I went with the "-cpu arm_foo,aarch64=off" approach so as to not complicate it right now with adding full-blown CPU properties.

#14 lore raw

Re: [Qemu-devel] [PATCH 1/5] target-arm: Add ARM CPU feature parsing

Quoted 45 lines · On Tue, 20 Jan 2015 16:45:19 -0600 Greg Bellows <[email protected]> wrote:
Quoted 44 lines · Igor Mammedov
Quoted 15 lines · On Tue, 20 Jan 2015 16:08:09 +0000 Peter Maydell <[email protected]>…
Quoted 14 lines · Igor Mammedov
Quoted 7 lines · On Tue, 20 Jan 2015 15:34:23 +0000 Peter Maydell <[email protected]>…
Quoted 3 lines · Igor Mammedov

Please do not use legacy +-feature format and support only foo=val format. Other targets have it only for to being able support legacy setups which use +- format.

I thought this was the standard format for CPU features. Do you have an example of a CPU feature being set using foo=val format?

Currently on x86 we can use either legacy +foo1,-foo2,foo3 and in addition to it we ca use canonized format for generic properties like, foo1=on,foo2=off,foo3=on

Quoted 7 lines
Quoted 3 lines

We try to move out of legacy format, so that it would be possible to reuse generic property parsing infrastructure like with any device object. That would allow to use -device/device_add for CPUs.

-device/-device_add for CPUs is pretty fraught in the general case because there's no obvious place to plug them and have them be wired up properly.

That depends on CPU of-cause, but we are close to having device_add working with x86 CPUs.

Quoted 2 lines

You'd need to use -global for CPU
properties, which is a nightmare...

mine thoughts on it were that '-cpu type,feat...' would eventually do conversion of features to global properties transparently for user using target specific cc->parse_features() callback. Which Greg could actually do here. We would happy to reuse it with x86 CPUs.

Quoted 5 lines

Anyway, I'm not particularly attached to the exact command line syntax we've used here -- I was just looking for "we have a CPU property, and use the same syntax for specifying CPU feature enable/disable that other CPUs do"...

Then '-cpu arm_foo,featX=on/off' should do the job.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

-- PMM

For now I went with the "-cpu arm_foo,aarch64=off" approach so as to not complicate it right now with adding full-blown CPU properties.

I see that there is quite a mess with feature bits and properties on ARM target already, so I won't ask to rewrite all of it to. But since you need control only one feature than make it property and set related feature bit from property setter or like it's done for arm_cpu_has_el3_property.
Then in arm_cpu_parse_features() you can just do generic setting:

object_property_parse(OBJECT(cpu), val, featurename, &local_err);

for foo=on/off format and forget about touching it again, further down the road one would just need to add a property to mange needed feature bits.

#15 lore raw

PATCH 2/5 target-arm: Add feature parsing to virt

In reply to Greg Bellows

Added machvirt parsing of feature keywords added to the -cpu command line option. Parsing occurs during machine initialization.

---
 hw/arm/virt.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
hw/arm/virt.c +19 -2
index 2353440..cd192ae 100644
@@ -573,12 +573,19 @@ static void machvirt_init(MachineState *machine)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     const char *cpu_model = machine->cpu_model;
     VirtBoardInfo *vbi;
+    char *cpuname, *features;
 
     if (!cpu_model) {
         cpu_model = "cortex-a15";
     }
 
-    vbi = find_machine_info(cpu_model);
+    /* Separate the actual CPU model name from any appended features */
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    /* Keep track of the features for later parsing */
+    features = strtok(NULL, ",");
+
+    vbi = find_machine_info(cpuname);
 
     if (!vbi) {
         error_report("mach-virt: CPU %s not supported", cpu_model);
@@ -595,8 +602,10 @@ static void machvirt_init(MachineState *machine)
     create_fdt(vbi);
 
     for (n = 0; n < smp_cpus; n++) {
-        ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
+        ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpuname);
+        CPUClass *cc = CPU_CLASS(oc);
         Object *cpuobj;
+        Error *err = NULL;
 
         if (!oc) {
             fprintf(stderr, "Unable to find CPU definition\n");
@@ -604,6 +613,13 @@ static void machvirt_init(MachineState *machine)
         }
         cpuobj = object_new(object_class_get_name(oc));
 
+        /* Handle any CPU options specfied by the user */
+        cc->parse_features(CPU(cpuobj), features, &err);
+        if (err) {
+            error_report("%s", error_get_pretty(err));
+            exit(1);
+        }
+
         if (!vms->secure) {
             object_property_set_bool(cpuobj, false, "has_el3", NULL);
         }
@@ -623,6 +639,7 @@ static void machvirt_init(MachineState *machine)
 
         object_property_set_bool(cpuobj, true, "realized", NULL);
     }
+    g_free(cpuname);
     fdt_add_timer_nodes(vbi);
     fdt_add_cpu_nodes(vbi);
     fdt_add_psci_node(vbi);
Signature · 1 line
1.8.3.2
#16 lore raw

Re: [Qemu-devel] [PATCH 2/5] target-arm: Add feature parsing to virt

Quoted 18 lines · Greg Bellows

Added machvirt parsing of feature keywords added to the -cpu command line option. Parsing occurs during machine initialization.

---
 hw/arm/virt.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
hw/arm/virt.c +1 -0
index 2353440..cd192ae 100644
@@ -573,12 +573,19 @@ static void machvirt_init(MachineState *machine)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     const char *cpu_model = machine->cpu_model;
     VirtBoardInfo *vbi;
+    char *cpuname, *features;
 

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

Quoted 10 lines
hw/arm/virt.c +5 -1
     if (!cpu_model) {
         cpu_model = "cortex-a15";
     }
 
-    vbi = find_machine_info(cpu_model);
+    /* Separate the actual CPU model name from any appended features */
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    /* Keep track of the features for later parsing */
+    features = strtok(NULL, ",");

<snip>

OK having read the strtok man page a bit more closely the second time I'm happy this doesn't leak. My more-gliby request is a matter of personal taste.

Signature · 1 line
Alex Bennée
#17 lore raw

PATCH 3/5 target-arm: Add 32/64-bit register sync

In reply to Greg Bellows

Add AArch32 to AArch64 register sychronization functions. Replace manual register synchronization with new functions in aarch64_cpu_do_interrupt() and HELPER(exception_return)().

---
 target-arm/helper-a64.c |  5 +--
 target-arm/internals.h  | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/op_helper.c  |  6 ++--
 3 files changed, 92 insertions(+), 8 deletions(-)
target-arm/helper-a64.c +1 -4
index 81066ca..2b5a668 100644
@@ -448,7 +448,6 @@ void aarch64_cpu_do_interrupt(CPUState *cs)
     unsigned int new_el = arm_excp_target_el(cs, cs->exception_index);
     target_ulong addr = env->cp15.vbar_el[new_el];
     unsigned int new_mode = aarch64_pstate_mode(new_el, true);
-    int i;
 
     if (arm_current_el(env) < new_el) {
         if (env->aarch64) {
@@ -512,9 +511,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)
         }
         env->elr_el[new_el] = env->regs[15];
 
-        for (i = 0; i < 15; i++) {
-            env->xregs[i] = env->regs[i];
-        }
+        aarch64_sync_32_to_64(env);
 
         env->condexec_bits = 0;
     }
target-arm/internals.h +89 -0

95 lines not on this page · raw message

target-arm/op_helper.c +2 -4
index 2bed914..7713022 100644
@@ -465,7 +465,7 @@ void HELPER(exception_return)(CPUARMState *env)
     int cur_el = arm_current_el(env);
     unsigned int spsr_idx = aarch64_banked_spsr_index(cur_el);
     uint32_t spsr = env->banked_spsr[spsr_idx];
-    int new_el, i;
+    int new_el;
 
     aarch64_save_sp(env, cur_el);
 
@@ -491,9 +491,7 @@ void HELPER(exception_return)(CPUARMState *env)
         if (!arm_singlestep_active(env)) {
             env->uncached_cpsr &= ~PSTATE_SS;
         }
-        for (i = 0; i < 15; i++) {
-            env->regs[i] = env->xregs[i];
-        }
+        aarch64_sync_64_to_32(env);
 
         env->regs[15] = env->elr_el[1] & ~0x1;
     } else {
Signature · 1 line
1.8.3.2
#18 lore raw

PATCH 4/5 target-arm: Add AArch32 guest support to KVM64

In reply to Greg Bellows

Add 32-bit to/from 64-bit register synchronization on register gets and puts. Set EL1_32BIT feature flag passed to KVM

---
 target-arm/kvm64.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
target-arm/kvm64.c +17 -4
index ba16821..0061099 100644
@@ -81,8 +81,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
     int ret;
     ARMCPU *cpu = ARM_CPU(cs);
 
-    if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE ||
-        !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+    if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) {
         fprintf(stderr, "KVM is not supported for this guest CPU type\n");
         return -EINVAL;
     }
@@ -96,6 +95,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
         cpu->psci_version = 2;
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
+    if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT;
+    }
 
     /* Do KVM_ARM_VCPU_INIT ioctl */
     ret = kvm_arm_vcpu_init(cs);
@@ -133,6 +135,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
 
+    aarch64_sync_32_to_64(env);
     for (i = 0; i < 31; i++) {
         reg.id = AARCH64_CORE_REG(regs.regs[i]);
         reg.addr = (uintptr_t) &env->xregs[i];
@@ -162,7 +165,11 @@ int kvm_arch_put_registers(CPUState *cs, int level)
     }
 
     /* Note that KVM thinks pstate is 64 bit but we use a uint32_t */
-    val = pstate_read(env);
+    if (is_a64(env)) {
+        val = pstate_read(env);
+    } else {
+        val = cpsr_read(env);
+    }
     reg.id = AARCH64_CORE_REG(regs.pstate);
     reg.addr = (uintptr_t) &val;
     ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
@@ -218,6 +225,7 @@ int kvm_arch_get_registers(CPUState *cs)
             return ret;
         }
     }
+    aarch64_sync_64_to_32(env);
 
     reg.id = AARCH64_CORE_REG(regs.sp);
     reg.addr = (uintptr_t) &env->sp_el[0];
@@ -239,7 +247,12 @@ int kvm_arch_get_registers(CPUState *cs)
     if (ret) {
         return ret;
     }
-    pstate_write(env, val);
+    if (is_a64(env)) {
+        pstate_write(env, val);
+    } else {
+        env->uncached_cpsr = val & CPSR_M;
+        cpsr_write(env, val, 0xffffffff);
+    }
 
     /* KVM puts SP_EL0 in regs.sp and SP_EL1 in regs.sp_el1. On the
      * QEMU side we keep the current SP in xregs[31] as well.
Signature · 1 line
1.8.3.2
#19 lore raw

Re: [Qemu-devel] [PATCH 4/5] target-arm: Add AArch32 guest support to KVM64

Quoted 41 lines · Greg Bellows

Add 32-bit to/from 64-bit register synchronization on register gets and puts. Set EL1_32BIT feature flag passed to KVM

---
 target-arm/kvm64.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
target-arm/kvm64.c +5 -2
index ba16821..0061099 100644
@@ -81,8 +81,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
     int ret;
     ARMCPU *cpu = ARM_CPU(cs);
 
-    if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE ||
-        !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+    if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) {
         fprintf(stderr, "KVM is not supported for this guest CPU type\n");
         return -EINVAL;
     }
@@ -96,6 +95,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
         cpu->psci_version = 2;
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
+    if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT;
+    }
 
     /* Do KVM_ARM_VCPU_INIT ioctl */
     ret = kvm_arm_vcpu_init(cs);
@@ -133,6 +135,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
 
+    aarch64_sync_32_to_64(env);
     for (i = 0; i < 31; i++) {
         reg.id = AARCH64_CORE_REG(regs.regs[i]);
         reg.addr = (uintptr_t) &env->xregs[i];

target-arm/kvm64.c int kvm_arch_put_registers(CPUState *cs, int level) · line 172

Quoted 9 lines
target-arm/kvm64.c +5 -1
@@ -162,7 +165,11 @@ int kvm_arch_put_registers(CPUState *cs, int level)
     }
 
     /* Note that KVM thinks pstate is 64 bit but we use a uint32_t */
-    val = pstate_read(env);
+    if (is_a64(env)) {
+        val = pstate_read(env);
+    } else {
+        val = cpsr_read(env);
+    }

I know why we do this (especially given where my attempt ended up) but perhaps we could at list have a single state aware accessor so we don't end up duplicating this test all over the place?

Signature · 1 line
Alex Bennée
#20 lore raw

Re: [Qemu-devel] [PATCH 4/5] target-arm: Add AArch32 guest support to KVM64

Quoted 46 lines · Alex Bennée
Quoted 43 lines · Greg Bellows

Add 32-bit to/from 64-bit register synchronization on register gets and puts. Set EL1_32BIT feature flag passed to KVM

---
 target-arm/kvm64.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
target-arm/kvm64.c +5 -2
index ba16821..0061099 100644
@@ -81,8 +81,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
     int ret;
     ARMCPU *cpu = ARM_CPU(cs);
 
-    if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE ||
-        !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+    if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) {
         fprintf(stderr, "KVM is not supported for this guest CPU type\n");
         return -EINVAL;
     }
@@ -96,6 +95,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
         cpu->psci_version = 2;
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
+    if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT;
+    }
 
     /* Do KVM_ARM_VCPU_INIT ioctl */
     ret = kvm_arm_vcpu_init(cs);
@@ -133,6 +135,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
 
+    aarch64_sync_32_to_64(env);
     for (i = 0; i < 31; i++) {
         reg.id = AARCH64_CORE_REG(regs.regs[i]);
         reg.addr = (uintptr_t) &env->xregs[i];
@@ -162,7 +165,11 @@ int kvm_arch_put_registers(CPUState *cs, int level)
     }
 
Quoted 11 lines

target-arm/kvm64.c int kvm_arch_put_registers(CPUState *cs, int level) · line 172

Quoted 7 lines
target-arm/kvm64.c +5 -1
     /* Note that KVM thinks pstate is 64 bit but we use a uint32_t */
-    val = pstate_read(env);
+    if (is_a64(env)) {
+        val = pstate_read(env);
+    } else {
+        val = cpsr_read(env);
+    }

I know why we do this (especially given where my attempt ended up) but perhaps we could at list have a single state aware accessor so we don't end up duplicating this test all over the place?

I'd happily add an accessor function, but I only found 1 other location that does this conditional so I'm not sure it is warranted.

Quoted 3 lines

--
Alex Bennée

#21 lore raw

Re: [Qemu-devel] [PATCH 4/5] target-arm: Add AArch32 guest support to KVM64

Quoted 8 lines · Greg Bellows
Quoted 7 lines · Alex Bennée
Quoted 4 lines · Greg Bellows

Add 32-bit to/from 64-bit register synchronization on register gets and puts. Set EL1_32BIT feature flag passed to KVM

<snip>

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
     }

     /* Note that KVM thinks pstate is 64 bit but we use a uint32_t */
target-arm/kvm64.c +5 -1
-    val = pstate_read(env);
+    if (is_a64(env)) {
+        val = pstate_read(env);
+    } else {
+        val = cpsr_read(env);
+    }
Quoted 6 lines
Quoted 3 lines

I know why we do this (especially given where my attempt ended up) but perhaps we could at list have a single state aware accessor so we don't end up duplicating this test all over the place?

I'd happily add an accessor function, but I only found 1 other location that does this conditional so I'm not sure it is warranted.

The migration/serialisation code? Today one other, tomorrow just one more?

Signature · 1 line
Alex Bennée
#22 lore raw

Re: [Qemu-devel] [PATCH 4/5] target-arm: Add AArch32 guest support to KVM64

Quoted 4 lines · Alex Bennée
Quoted 1 line · Greg Bellows

On Tue, Jan 20, 2015 at 10:57 AM, Alex Bennée <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I know why we do this (especially given where my attempt ended up) but perhaps we could at list have a single state aware accessor so we don't end up duplicating this test all over the place?

I'd happily add an accessor function, but I only found 1 other location that does this conditional so I'm not sure it is warranted.

The migration/serialisation code? Today one other, tomorrow just one more?

Meh. I suggested to Greg that just inlining this at point of use was the simplest approach. Maybe one day we'll clean this stuff up but yet another accessor function doesn't seem too great either.

-- PMM

#23 lore raw

PATCH 5/5 target-arm: Adjust kernel load address for Image

In reply to Greg Bellows

Adjust the kernel load offset by 0x8000 if not a zImage.

---
 hw/arm/boot.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
hw/arm/boot.c +32 -1
index 52ebd8b..b581cea 100644
@@ -537,6 +537,32 @@ static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
     fw_cfg_add_bytes(fw_cfg, data_key, data, size);
 }
 
+static int check_load_zimage(const char *filename)
+{
+    int fd;
+    uint8_t buf[40];
+    uint32_t *p = (uint32_t *) &buf[36];
+
+    fd = open(filename, O_RDONLY | O_BINARY);
+    if (fd < 0) {
+        perror(filename);
+        return -1;
+    }
+
+    memset(buf, 0, sizeof(buf));
+    if (read(fd, buf, sizeof(buf)) != sizeof(buf)) {
+        close(fd);
+        return -1;
+    }
+
+    /* Check for zImage magic number */
+    if (*p == 0x016F2818) {
+        return 1;
+    }
+
+   return 0;
+}
+
 void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
 {
     CPUState *cs;
@@ -613,7 +639,12 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
         primary_loader = bootloader;
         kernel_load_offset = KERNEL_LOAD_ADDR;
         elf_machine = EM_ARM;
-    }
+
+        if (!check_load_zimage(info->kernel_filename)) {
+            /* Assuming we are loading Image hence aligning it to 0x8000 */
+            kernel_load_offset -= 0x8000;
+        }
+   }
 
     info->dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
 
Signature · 1 line
1.8.3.2
#24 lore raw
In reply to Greg Bellows
Quoted 7 lines · Greg Bellows

Added support for running an AArch32 guest on a AArch64 KVM host. Support has only been added to the QEMU machvirt machine. The addition of CPU properties specifiable from the command line were added to allow disablement of AArch64 execution state hereby forcing EL1 to be AArch32. The new CPU command line propoerty is "-aarch64" that is specified as follows:

    aarch64-softmmu/qemu-system-aarch64 -M virt -cpu cortex-a57,-aarch64 ...

Hi!

It seems a little confusing for me to specify '-aarch64' when forcing AArch32 execution state. Why don't just specify 'aarch32' in command line instead of '-aarch64' construction?

BTW, /propoerty/property/

Best regards,
Serge

Quoted 19 lines

Support also added to support uncompressed images (Image) for aarch32.

Greg Bellows (5):
target-arm: Add ARM CPU feature parsing
target-arm: Add feature parsing to virt
target-arm: Add 32/64-bit register sync
target-arm: Add AArch32 guest support to KVM64
target-arm: Adjust kernel load address for Image

 hw/arm/boot.c           | 33 +++++++++++++++++-
 hw/arm/virt.c           | 21 ++++++++++--
 target-arm/cpu.c        | 45 ++++++++++++++++++++++++-
 target-arm/helper-a64.c |  5 +--
 target-arm/internals.h  | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/kvm64.c      | 21 +++++++++---
 target-arm/op_helper.c  |  6 ++--
 7 files changed, 204 insertions(+), 16 deletions(-)
#25 lore raw
Quoted 5 lines · Sergey Fedorov
    aarch64-softmmu/qemu-system-aarch64 -M virt -cpu cortex-a57,-aarch64 ...

It seems a little confusing for me to specify '-aarch64' when forcing AArch32 execution state. Why don't just specify 'aarch32' in command line instead of '-aarch64' construction?

This is one of the things we discussed during design of this patchset, and I agree the command line semantics are a bit odd. Essentially, they make sense from the PoV of the CPU object, because they're saying "I want a 32-bit only CPU", ie "I do not want the 64 bit feature this CPU defaults to". Specifying '+aarch32' wouldn't do anything, because the default Cortex-A57 already has 32-bit support. But from the PoV of the user, it's a bit odd. The other possible approach to this would be to have a machine model parameter for "force 32 bit boot", and have this turn off the CPU 64 bit feature.

Other proposals welcome; I don't like the UI we end up exposing to the user here, it's just what falls out of the natural way to model things at the CPU QOM property level.

-- PMM