Now the infrastructure is in place let's trigger the
SYSREG prop update in the KVM code. This is done in both
kvm_arch_init_vcpu() and kvm_arm_reset_vcpu() after the final
vcpu has been initialized with the proper kvm init settings and
before kvmstate is synced back to the cpreg list.

Signed-off-by: Eric Auger <[email protected]>

---

v9 -> v10
- use ValueRange
---
 target/arm/cpu64.c |  9 +++++----
 target/arm/kvm.c   | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 26baee102c..ff178bcaf5 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -883,10 +883,11 @@ static void set_sysreg_prop(Object *obj, Visitor *v,
         return;
     }
 
-    if (field->arch_vals) {
-        /* this field has some enum values */
-        for (int i = 0; i < field->arch_vals_count; i++) {
-            if (value == field->arch_vals[i]) {
+    if (field->arch_value_ranges) {
+        for (uint32_t i = 0; i < field->arch_value_ranges_count; i++) {
+            const ARM64SysRegArchValueRange *r = &field->arch_value_ranges[i];
+
+            if (value >= r->lo && value <= r->hi) {
                 goto valid;
             }
         }
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index c6c9ea03a5..0c7e80aea8 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -1247,7 +1247,7 @@ bool kvm_arm_cpu_post_load(ARMCPU *cpu)
     return true;
 }
 
-static int G_GNUC_UNUSED
+static int
 kvm_arm_override_idreg_field(int fd, ARM64SysRegField *field,
                              uint64_t newfv, Error **errp)
 {
@@ -1291,6 +1291,17 @@ kvm_arm_override_idreg_field(int fd, ARM64SysRegField 
*field,
     return 0;
 }
 
+static int kvm_arm_apply_one_sysreg_prop(ARMCPU *cpu, ARM64SysRegField *field,
+                                         uint64_t newfv, Error **errp)
+{
+    return kvm_arm_override_idreg_field(CPU(cpu)->kvm_fd, field, newfv, errp);
+}
+
+static int kvm_arm_apply_sysreg_props(ARMCPU *cpu, Error **errp)
+{
+    return arm_cpu_apply_sysreg_props(cpu, kvm_arm_apply_one_sysreg_prop, 
errp);
+}
+
 void kvm_arm_reset_vcpu(ARMCPU *cpu)
 {
     int ret;
@@ -1304,6 +1315,8 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu)
         abort();
     }
 
+    kvm_arm_apply_sysreg_props(cpu, &error_abort);
+
     if (!write_kvmstate_to_list(cpu)) {
         fprintf(stderr, "write_kvmstate_to_list failed\n");
         abort();
@@ -2250,6 +2263,11 @@ int kvm_arch_init_vcpu(CPUState *cs, Error **errp)
     }
     SET_IDREG(&cpu->isar, MPIDR, mpidr);
 
+    ret = kvm_arm_apply_sysreg_props(cpu, errp);
+    if (ret) {
+        return ret;
+    }
+
     cpu->mp_affinity = GET_IDREG(&cpu->isar, MPIDR) & ARM64_AFFINITY_MASK;
 
     return kvm_arm_init_cpreg_list(cpu, errp);
-- 
2.53.0


Reply via email to