Skip to contentSkip to conversation

QOM CPUState patch queue 2013-04-15

GIT PULL In review Andreas Färber 2 participants 14 messages Apr 16, 2013 – Apr 18, 2013 KVM

lore
Share & tools
lore
#0 lore raw

Hello,

This is my current QOM CPU patch queue. Please pull.

It includes:
* -cpu ? fixes,
* preparations for x86 CPU static properties,
* preparations for x86 CPU hot-plug,
* preparations for x86 CPUID features array cleanup,
* do_interrupt cleanup for cris.

Regards,
Andreas

Cc Anthony Liguori <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Aurélien Jarno <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>

The following changes since commit 24a6e7f4d91e9ed5f8117ecb083431a23f8609a0:

virtio-balloon: fix dynamic properties. (2013-04-15 17:06:58 -0500)

are available in the git repository at:

git://github.com/afaerber/qemu-cpu.git qom-cpu

for you to fetch changes up to b21bfeead284cf212d88dfa25171fee122407bc2:

target-cris: Override do_interrupt for pre-v32 CPU cores (2013-04-16 02:45:11 +0200)

----------------------------------------------------------------
Andreas Färber (1):
target-cris: Override do_interrupt for pre-v32 CPU cores

Eduardo Habkost (1):
target-i386/cpu.c: Coding style fixes

Igor Mammedov (8):
qdev: Add qdev property for bool type
target-i386: Consolidate error propagation in x86_cpu_realizefn()
target-i386: Split APIC creation from initialization in x86_cpu_realizefn()
kvmvapic: Replace FROM_SYSBUS() with QOM type cast
ioapic: Replace FROM_SYSBUS() with QOM type cast
target-i386: Split out CPU creation and features parsing
cpu: Pass CPUState to *cpu_synchronize_post*()
qdev: Set device's parent before calling realize() down inheritance chain

Jan Kiszka (2):
target-i386: Fix including "host" in -cpu ? output
target-i386: Improve -cpu ? features output

 cpus.c                       |  4 +-
 hw/core/qdev-properties.c    | 33 ++++++++++++++++
 hw/core/qdev.c               |  8 ++--
 hw/i386/kvmvapic.c           |  7 +++-
 hw/intc/ioapic_common.c      |  2 +-
 include/hw/qdev-properties.h | 10 +++++
 include/sysemu/kvm.h         | 12 +++---
 kvm-all.c                    |  8 +---
 kvm-stub.c                   |  4 +-
 target-cris/cpu-qom.h        |  1 +
 target-cris/cpu.c            |  8 ++++
 target-cris/helper.c         | 14 ++++---
 target-i386/cpu.c            | 89 ++++++++++++++++++++++++++++++--------------
 target-i386/cpu.h            |  1 +
 14 files changed, 145 insertions(+), 56 deletions(-)
#1 lore raw

PATCH 1/12 target-i386: Fix including "host" in -cpu ? output

From: Jan Kiszka <[email protected]>

kvm_enabled() cannot be true at this point because accelerators are initialized much later during init. Also, hiding this makes it very hard to discover for users. Simply dump unconditionally if CONFIG_KVM is set.

Add explanation for "host" CPU type.

---
 target-i386/cpu.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
target-i386/cpu.c +6 -3
index 6dd993f..b8690d2 100644
@@ -1463,9 +1463,12 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
         snprintf(buf, sizeof(buf), "%s", def->name);
         (*cpu_fprintf)(f, "x86 %16s  %-48s\n", buf, def->model_id);
     }
-    if (kvm_enabled()) {
-        (*cpu_fprintf)(f, "x86 %16s\n", "[host]");
-    }
+#ifdef CONFIG_KVM
+    (*cpu_fprintf)(f, "x86 %16s  %-48s\n", "host",
+                   "KVM processor with all supported host features "
+                   "(only available in KVM mode)");
+#endif
+
     (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
     listflags(buf, sizeof(buf), (uint32_t)~0, feature_name, 1);
     (*cpu_fprintf)(f, "  %s\n", buf);
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/12 target-i386: Improve -cpu ? features output

In reply to Andreas Färber

From: Jan Kiszka <[email protected]>

We were missing a bunch of feature lists. Fix this by simply dumping the meta list feature_word_info.

---
 target-i386/cpu.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
target-i386/cpu.c +6 -8
index b8690d2..0a4e5ae 100644
@@ -1470,14 +1470,12 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 #endif
 
     (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
-    listflags(buf, sizeof(buf), (uint32_t)~0, feature_name, 1);
-    (*cpu_fprintf)(f, "  %s\n", buf);
-    listflags(buf, sizeof(buf), (uint32_t)~0, ext_feature_name, 1);
-    (*cpu_fprintf)(f, "  %s\n", buf);
-    listflags(buf, sizeof(buf), (uint32_t)~0, ext2_feature_name, 1);
-    (*cpu_fprintf)(f, "  %s\n", buf);
-    listflags(buf, sizeof(buf), (uint32_t)~0, ext3_feature_name, 1);
-    (*cpu_fprintf)(f, "  %s\n", buf);
+    for (i = 0; i < ARRAY_SIZE(feature_word_info); i++) {
+        FeatureWordInfo *fw = &feature_word_info[i];
+
+        listflags(buf, sizeof(buf), (uint32_t)~0, fw->feat_names, 1);
+        (*cpu_fprintf)(f, "  %s\n", buf);
+    }
 }
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/12 qdev: Add qdev property for bool type

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

[AF: Use new qdev_prop_set_after_realize()]
---
 hw/core/qdev-properties.c    | 33 +++++++++++++++++++++++++++++++++
 include/hw/qdev-properties.h | 10 ++++++++++
 2 files changed, 43 insertions(+)
hw/core/qdev-properties.c +33 -0
index ddde18e..ca1739e 100644
@@ -120,6 +120,39 @@ PropertyInfo qdev_prop_bit = {
     .set   = set_bit,
 };
 
+/* --- bool --- */
+
+static void get_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+static void set_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_bool = {
+    .name  = "boolean",
+    .get   = get_bool,
+    .set   = set_bool,
+};
+
 /* --- 8bit integer --- */
 
 static void get_uint8(Object *obj, Visitor *v, void *opaque,
include/hw/qdev-properties.h +10 -0
index a379339..25dd1bb 100644
@@ -6,6 +6,7 @@
 /*** qdev-properties.c ***/
 
 extern PropertyInfo qdev_prop_bit;
+extern PropertyInfo qdev_prop_bool;
 extern PropertyInfo qdev_prop_uint8;
 extern PropertyInfo qdev_prop_uint16;
 extern PropertyInfo qdev_prop_uint32;
@@ -52,6 +53,15 @@ extern PropertyInfo qdev_prop_arraylen;
         .defval    = (bool)_defval,                              \
         }
 
+#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
+        .name      = (_name),                                    \
+        .info      = &(qdev_prop_bool),                          \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(bool, typeof_field(_state, _field)),    \
+        .qtype     = QTYPE_QBOOL,                                \
+        .defval    = (bool)_defval,                              \
+        }
+
 #define PROP_ARRAY_LEN_PREFIX "len-"
 
 /**
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/12 target-i386: Consolidate error propagation in x86_cpu_realizefn()

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

---
 target-i386/cpu.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
target-i386/cpu.c +10 -7
index 0a4e5ae..9d45f09 100644
@@ -2099,9 +2099,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     X86CPU *cpu = X86_CPU(dev);
     X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
     CPUX86State *env = &cpu->env;
-#ifndef CONFIG_USER_ONLY
     Error *local_err = NULL;
-#endif
 
     if (env->cpuid_7_0_ebx_features && env->cpuid_level < 7) {
         env->cpuid_level = 7;
@@ -2131,8 +2129,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     } else {
         if (check_cpuid && kvm_check_features_against_host(cpu)
             && enforce_cpuid) {
-            error_setg(errp, "Host's CPU doesn't support requested features");
-            return;
+            error_setg(&local_err,
+                       "Host's CPU doesn't support requested features");
+            goto out;
         }
 #ifdef CONFIG_KVM
         filter_features_for_kvm(cpu);
@@ -2145,8 +2144,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     if (cpu->env.cpuid_features & CPUID_APIC || smp_cpus > 1) {
         x86_cpu_apic_init(cpu, &local_err);
         if (local_err != NULL) {
-            error_propagate(errp, local_err);
-            return;
+            goto out;
         }
     }
 #endif
@@ -2155,7 +2153,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     qemu_init_vcpu(&cpu->env);
     cpu_reset(CPU(cpu));
 
-    xcc->parent_realize(dev, errp);
+    xcc->parent_realize(dev, &local_err);
+out:
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return;
+    }
 }
 
 /* Enables contiguous-apic-ID mode, for compatibility */
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 5/12 target-i386: Split APIC creation from initialization in x86_cpu_realizefn()

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

When APIC is hotplugged during CPU hotplug, device_set_realized() calls device_reset() on it. And if QEMU runs in KVM mode, following call chain will fail:

    apic_reset_common()
        -> kvm_apic_vapic_base_update()
            -> kvm_vcpu_ioctl(cpu->kvm_fd,...)

due to cpu->kvm_fd not being initialized yet.

cpu->kvm_fd is initialized during qemu_init_vcpu() but x86_cpu_apic_init() can't be moved after it because kvm_init_vcpu() -> kvm_arch_reset_vcpu() relies on APIC to determine if CPU is BSP for setting initial env->mp_state.

So split APIC device creation from its initialization and realize APIC after CPU is created, when it's safe to call APIC's reset method.

---
 target-i386/cpu.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
target-i386/cpu.c +21 -3
index 9d45f09..5d05803 100644
@@ -2050,9 +2050,8 @@ static void mce_init(X86CPU *cpu)
 }
 
 #ifndef CONFIG_USER_ONLY
-static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
+static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 {
-    static int apic_mapped;
     CPUX86State *env = &cpu->env;
     APICCommonState *apic;
     const char *apic_type = "apic";
@@ -2075,6 +2074,16 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
     /* TODO: convert to link<> */
     apic = APIC_COMMON(env->apic_state);
     apic->cpu = cpu;
+}
+
+static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
+{
+    CPUX86State *env = &cpu->env;
+    static int apic_mapped;
+
+    if (env->apic_state == NULL) {
+        return;
+    }
 
     if (qdev_init(env->apic_state)) {
         error_setg(errp, "APIC device '%s' could not be initialized",
@@ -2092,6 +2101,10 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
         apic_mapped = 1;
     }
 }
+#else
+static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
+{
+}
 #endif
 
 static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
@@ -2142,7 +2155,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
 
     if (cpu->env.cpuid_features & CPUID_APIC || smp_cpus > 1) {
-        x86_cpu_apic_init(cpu, &local_err);
+        x86_cpu_apic_create(cpu, &local_err);
         if (local_err != NULL) {
             goto out;
         }
@@ -2151,6 +2164,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 
     mce_init(cpu);
     qemu_init_vcpu(&cpu->env);
+
+    x86_cpu_apic_realize(cpu, &local_err);
+    if (local_err != NULL) {
+        goto out;
+    }
     cpu_reset(CPU(cpu));
 
     xcc->parent_realize(dev, &local_err);
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH 6/12 kvmvapic: Replace FROM_SYSBUS() with QOM type cast

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

... and define type name and type cast macro for kvmvapic according to accepted convention.

---
 hw/i386/kvmvapic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/i386/kvmvapic.c +5 -2
index ed9b448..3a10c07 100644
@@ -60,6 +60,9 @@ typedef struct VAPICROMState {
     bool rom_mapped_writable;
 } VAPICROMState;
 
+#define TYPE_VAPIC "kvmvapic"
+#define VAPIC(obj) OBJECT_CHECK(VAPICROMState, (obj), TYPE_VAPIC)
+
 #define TPR_INSTR_ABS_MODRM             0x1
 #define TPR_INSTR_MATCH_MODRM_REG       0x2
 
@@ -690,7 +693,7 @@ static const MemoryRegionOps vapic_ops = {
 
 static int vapic_init(SysBusDevice *dev)
 {
-    VAPICROMState *s = FROM_SYSBUS(VAPICROMState, dev);
+    VAPICROMState *s = VAPIC(dev);
 
     memory_region_init_io(&s->io, &vapic_ops, s, "kvmvapic", 2);
     sysbus_add_io(dev, VAPIC_IO_PORT, &s->io);
@@ -806,7 +809,7 @@ static void vapic_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo vapic_type = {
-    .name          = "kvmvapic",
+    .name          = TYPE_VAPIC,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(VAPICROMState),
     .class_init    = vapic_class_init,
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH 7/12 ioapic: Replace FROM_SYSBUS() with QOM type cast

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

---
 hw/intc/ioapic_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/ioapic_common.c +1 -1
index 42c7adc..5c5bb3c 100644
@@ -59,7 +59,7 @@ static int ioapic_dispatch_post_load(void *opaque, int version_id)
 
 static int ioapic_init_common(SysBusDevice *dev)
 {
-    IOAPICCommonState *s = FROM_SYSBUS(IOAPICCommonState, dev);
+    IOAPICCommonState *s = IOAPIC_COMMON(dev);
     IOAPICCommonClass *info;
     static int ioapic_no;
 
Signature · 1 line
1.8.1.4
#8 lore raw

PATCH 8/12 target-i386/cpu.c: Coding style fixes

In reply to Andreas Färber

From: Eduardo Habkost <[email protected]>

* Add braces to 'if' statements;
* Remove last TAB character from the source.

---
 target-i386/cpu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
target-i386/cpu.c +4 -3
index 5d05803..0a84000 100644
@@ -1869,12 +1869,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         if (env->cpuid_ext2_features & CPUID_EXT2_LM) {
             /* 64 bit processor */
 /* XXX: The physical address space is limited to 42 bits in exec.c. */
-            *eax = 0x00003028;	/* 48 bits virtual, 40 bits physical */
+            *eax = 0x00003028; /* 48 bits virtual, 40 bits physical */
         } else {
-            if (env->cpuid_features & CPUID_PSE36)
+            if (env->cpuid_features & CPUID_PSE36) {
                 *eax = 0x00000024; /* 36 bits physical */
-            else
+            } else {
                 *eax = 0x00000020; /* 32 bits physical */
+            }
         }
         *ebx = 0;
         *ecx = 0;
Signature · 1 line
1.8.1.4
#9 lore raw

PATCH 9/12 target-i386: Split out CPU creation and features parsing

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

Move CPU creation and features parsing into a separate cpu_x86_create() function, so that board would be able to set board-specific CPU properties before CPU is realized.

Keep cpu_x86_init() for compatibility with the code that uses cpu_init() and doesn't need to modify CPU properties.

---
 target-i386/cpu.c | 18 +++++++++++++++---
 target-i386/cpu.h |  1 +
 2 files changed, 16 insertions(+), 3 deletions(-)
target-i386/cpu.c +15 -3
index 0a84000..e2302d8 100644
@@ -1563,7 +1563,7 @@ static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
     object_property_set_str(OBJECT(cpu), def->model_id, "model-id", errp);
 }
 
-X86CPU *cpu_x86_init(const char *cpu_model)
+X86CPU *cpu_x86_create(const char *cpu_model, Error **errp)
 {
     X86CPU *cpu = NULL;
     CPUX86State *env;
@@ -1593,13 +1593,25 @@ X86CPU *cpu_x86_init(const char *cpu_model)
         goto out;
     }
 
-    object_property_set_bool(OBJECT(cpu), true, "realized", &error);
+out:
+    error_propagate(errp, error);
+    g_strfreev(model_pieces);
+    return cpu;
+}
+
+X86CPU *cpu_x86_init(const char *cpu_model)
+{
+    Error *error = NULL;
+    X86CPU *cpu;
+
+    cpu = cpu_x86_create(cpu_model, &error);
     if (error) {
         goto out;
     }
 
+    object_property_set_bool(OBJECT(cpu), true, "realized", &error);
+
 out:
-    g_strfreev(model_pieces);
     if (error) {
         fprintf(stderr, "%s\n", error_get_pretty(error));
         error_free(error);
target-i386/cpu.h +1 -0
index 2b4e319..cf1b05c 100644
@@ -896,6 +896,7 @@ typedef struct CPUX86State {
 #include "cpu-qom.h"
 
 X86CPU *cpu_x86_init(const char *cpu_model);
+X86CPU *cpu_x86_create(const char *cpu_model, Error **errp);
 int cpu_x86_exec(CPUX86State *s);
 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 void x86_cpudef_setup(void);
Signature · 1 line
1.8.1.4
#10 lore raw

PATCH 10/12 cpu: Pass CPUState to *cpu_synchronize_post*()

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

... so it could be called without requiring CPUArchState.

---
 cpus.c               |  4 ++--
 include/sysemu/kvm.h | 12 ++++++------
 kvm-all.c            |  8 ++------
 kvm-stub.c           |  4 ++--
 4 files changed, 12 insertions(+), 16 deletions(-)
cpus.c +2 -2
index 97e9ab4..c15ff6c 100644
@@ -419,7 +419,7 @@ void cpu_synchronize_all_post_reset(void)
     CPUArchState *cpu;
 
     for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
-        cpu_synchronize_post_reset(cpu);
+        cpu_synchronize_post_reset(ENV_GET_CPU(cpu));
     }
 }
 
@@ -428,7 +428,7 @@ void cpu_synchronize_all_post_init(void)
     CPUArchState *cpu;
 
     for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
-        cpu_synchronize_post_init(cpu);
+        cpu_synchronize_post_init(ENV_GET_CPU(cpu));
     }
 }
 
include/sysemu/kvm.h +6 -6
index f2d97b5..495e6f8 100644
@@ -250,8 +250,8 @@ int kvm_check_extension(KVMState *s, unsigned int extension);
 uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
                                       uint32_t index, int reg);
 void kvm_cpu_synchronize_state(CPUArchState *env);
-void kvm_cpu_synchronize_post_reset(CPUArchState *env);
-void kvm_cpu_synchronize_post_init(CPUArchState *env);
+void kvm_cpu_synchronize_post_reset(CPUState *cpu);
+void kvm_cpu_synchronize_post_init(CPUState *cpu);
 
 /* generic hooks - to be moved/refactored once there are more users */
 
@@ -262,17 +262,17 @@ static inline void cpu_synchronize_state(CPUArchState *env)
     }
 }
 
-static inline void cpu_synchronize_post_reset(CPUArchState *env)
+static inline void cpu_synchronize_post_reset(CPUState *cpu)
 {
     if (kvm_enabled()) {
-        kvm_cpu_synchronize_post_reset(env);
+        kvm_cpu_synchronize_post_reset(cpu);
     }
 }
 
-static inline void cpu_synchronize_post_init(CPUArchState *env)
+static inline void cpu_synchronize_post_init(CPUState *cpu)
 {
     if (kvm_enabled()) {
-        kvm_cpu_synchronize_post_init(env);
+        kvm_cpu_synchronize_post_init(cpu);
     }
 }
 
kvm-all.c +2 -6
index 9b433d3..fc4e17c 100644
@@ -1510,18 +1510,14 @@ void kvm_cpu_synchronize_state(CPUArchState *env)
     }
 }
 
-void kvm_cpu_synchronize_post_reset(CPUArchState *env)
+void kvm_cpu_synchronize_post_reset(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
-
     kvm_arch_put_registers(cpu, KVM_PUT_RESET_STATE);
     cpu->kvm_vcpu_dirty = false;
 }
 
-void kvm_cpu_synchronize_post_init(CPUArchState *env)
+void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
-
     kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE);
     cpu->kvm_vcpu_dirty = false;
 }
kvm-stub.c +2 -2
index f6137d3..723a813 100644
@@ -41,11 +41,11 @@ void kvm_cpu_synchronize_state(CPUArchState *env)
 {
 }
 
-void kvm_cpu_synchronize_post_reset(CPUArchState *env)
+void kvm_cpu_synchronize_post_reset(CPUState *cpu)
 {
 }
 
-void kvm_cpu_synchronize_post_init(CPUArchState *env)
+void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
 }
 
Signature · 1 line
1.8.1.4
Acked-by on v1 10/12
#11 lore raw

Re: [PATCH 10/12] cpu: Pass CPUState to *cpu_synchronize_post*()

Quoted 7 lines · Andreas Färber

From: Igor Mammedov <[email protected]>

... so it could be called without requiring CPUArchState.

Quoted 111 lines
---
 cpus.c               |  4 ++--
 include/sysemu/kvm.h | 12 ++++++------
 kvm-all.c            |  8 ++------
 kvm-stub.c           |  4 ++--
 4 files changed, 12 insertions(+), 16 deletions(-)
cpus.c +2 -2
index 97e9ab4..c15ff6c 100644
@@ -419,7 +419,7 @@ void cpu_synchronize_all_post_reset(void)
     CPUArchState *cpu;
 
     for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
-        cpu_synchronize_post_reset(cpu);
+        cpu_synchronize_post_reset(ENV_GET_CPU(cpu));
     }
 }
 
@@ -428,7 +428,7 @@ void cpu_synchronize_all_post_init(void)
     CPUArchState *cpu;
 
     for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
-        cpu_synchronize_post_init(cpu);
+        cpu_synchronize_post_init(ENV_GET_CPU(cpu));
     }
 }
 
include/sysemu/kvm.h +6 -6
index f2d97b5..495e6f8 100644
@@ -250,8 +250,8 @@ int kvm_check_extension(KVMState *s, unsigned int extension);
 uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
                                       uint32_t index, int reg);
 void kvm_cpu_synchronize_state(CPUArchState *env);
-void kvm_cpu_synchronize_post_reset(CPUArchState *env);
-void kvm_cpu_synchronize_post_init(CPUArchState *env);
+void kvm_cpu_synchronize_post_reset(CPUState *cpu);
+void kvm_cpu_synchronize_post_init(CPUState *cpu);
 
 /* generic hooks - to be moved/refactored once there are more users */
 
@@ -262,17 +262,17 @@ static inline void cpu_synchronize_state(CPUArchState *env)
     }
 }
 
-static inline void cpu_synchronize_post_reset(CPUArchState *env)
+static inline void cpu_synchronize_post_reset(CPUState *cpu)
 {
     if (kvm_enabled()) {
-        kvm_cpu_synchronize_post_reset(env);
+        kvm_cpu_synchronize_post_reset(cpu);
     }
 }
 
-static inline void cpu_synchronize_post_init(CPUArchState *env)
+static inline void cpu_synchronize_post_init(CPUState *cpu)
 {
     if (kvm_enabled()) {
-        kvm_cpu_synchronize_post_init(env);
+        kvm_cpu_synchronize_post_init(cpu);
     }
 }
 
kvm-all.c +2 -6
index 9b433d3..fc4e17c 100644
@@ -1510,18 +1510,14 @@ void kvm_cpu_synchronize_state(CPUArchState *env)
     }
 }
 
-void kvm_cpu_synchronize_post_reset(CPUArchState *env)
+void kvm_cpu_synchronize_post_reset(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
-
     kvm_arch_put_registers(cpu, KVM_PUT_RESET_STATE);
     cpu->kvm_vcpu_dirty = false;
 }
 
-void kvm_cpu_synchronize_post_init(CPUArchState *env)
+void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
-    CPUState *cpu = ENV_GET_CPU(env);
-
     kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE);
     cpu->kvm_vcpu_dirty = false;
 }
kvm-stub.c +2 -2
index f6137d3..723a813 100644
@@ -41,11 +41,11 @@ void kvm_cpu_synchronize_state(CPUArchState *env)
 {
 }
 
-void kvm_cpu_synchronize_post_reset(CPUArchState *env)
+void kvm_cpu_synchronize_post_reset(CPUState *cpu)
 {
 }
 
-void kvm_cpu_synchronize_post_init(CPUArchState *env)
+void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
 }
 
Signature · 1 line
1.8.1.4

--
Gleb.

#12 lore raw

PATCH 11/12 qdev: Set device's parent before calling realize() down inheritance chain

In reply to Andreas Färber

From: Igor Mammedov <[email protected]>

Currently device_set_realized() sets parent only after device was realized, but qdev_device_add() sets it before device is realized.
Make behavior consistent and alter device_set_realized() to behave like qdev_device_add().

It will allow to set link<> properties in realize() method in classes inherited from DEVICE.

---
 hw/core/qdev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/core/qdev.c +4 -4
index bab4ed7..4eb0134 100644
@@ -684,10 +684,6 @@ static void device_set_realized(Object *obj, bool value, Error **err)
     Error *local_err = NULL;
 
     if (value && !dev->realized) {
-        if (dc->realize) {
-            dc->realize(dev, &local_err);
-        }
-
         if (!obj->parent && local_err == NULL) {
             static int unattached_count;
             gchar *name = g_strdup_printf("device[%d]", unattached_count++);
@@ -698,6 +694,10 @@ static void device_set_realized(Object *obj, bool value, Error **err)
             g_free(name);
         }
 
+        if (dc->realize) {
+            dc->realize(dev, &local_err);
+        }
+
         if (qdev_get_vmsd(dev) && local_err == NULL) {
             vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
                                            dev->instance_id_alias,
Signature · 1 line
1.8.1.4
#13 lore raw

PATCH 12/12 target-cris: Override do_interrupt for pre-v32 CPU cores

In reply to Andreas Färber

Instead of forwarding from cris_cpu_do_interrupt() to do_interruptv10(), override CPUClass::do_interrupt with crisv10_cpu_do_interrupt() in the newly introduced class_init functions.

---
 target-cris/cpu-qom.h |  1 +
 target-cris/cpu.c     |  8 ++++++++
 target-cris/helper.c  | 14 ++++++++------
 3 files changed, 17 insertions(+), 6 deletions(-)
target-cris/cpu-qom.h +1 -0
index deea1d8..03829bd 100644
@@ -74,5 +74,6 @@ static inline CRISCPU *cris_env_get_cpu(CPUCRISState *env)
 #define ENV_OFFSET offsetof(CRISCPU, env)
 
 void cris_cpu_do_interrupt(CPUState *cpu);
+void crisv10_cpu_do_interrupt(CPUState *cpu);
 
 #endif
target-cris/cpu.c +8 -0
index 95cbf39..67181e5 100644
@@ -169,30 +169,38 @@ static void cris_cpu_initfn(Object *obj)
 
 static void crisv8_cpu_class_init(ObjectClass *oc, void *data)
 {
+    CPUClass *cc = CPU_CLASS(oc);
     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
 
     ccc->vr = 8;
+    cc->do_interrupt = crisv10_cpu_do_interrupt;
 }
 
 static void crisv9_cpu_class_init(ObjectClass *oc, void *data)
 {
+    CPUClass *cc = CPU_CLASS(oc);
     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
 
     ccc->vr = 9;
+    cc->do_interrupt = crisv10_cpu_do_interrupt;
 }
 
 static void crisv10_cpu_class_init(ObjectClass *oc, void *data)
 {
+    CPUClass *cc = CPU_CLASS(oc);
     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
 
     ccc->vr = 10;
+    cc->do_interrupt = crisv10_cpu_do_interrupt;
 }
 
 static void crisv11_cpu_class_init(ObjectClass *oc, void *data)
 {
+    CPUClass *cc = CPU_CLASS(oc);
     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
 
     ccc->vr = 11;
+    cc->do_interrupt = crisv10_cpu_do_interrupt;
 }
 
 static void crisv32_cpu_class_init(ObjectClass *oc, void *data)
target-cris/helper.c +8 -6
index e1ef7bc..466cc2f 100644
@@ -45,6 +45,11 @@ void cris_cpu_do_interrupt(CPUState *cs)
     env->pregs[PR_ERP] = env->pc;
 }
 
+void crisv10_cpu_do_interrupt(CPUState *cs)
+{
+    cris_cpu_do_interrupt(cs);
+}
+
 int cpu_cris_handle_mmu_fault(CPUCRISState * env, target_ulong address, int rw,
                               int mmu_idx)
 {
@@ -109,9 +114,10 @@ int cpu_cris_handle_mmu_fault(CPUCRISState *env, target_ulong address, int rw,
     return r;
 }
 
-static void do_interruptv10(CPUCRISState *env)
+void crisv10_cpu_do_interrupt(CPUState *cs)
 {
-    D(CPUState *cs = CPU(cris_env_get_cpu(env)));
+    CRISCPU *cpu = CRIS_CPU(cs);
+    CPUCRISState *env = &cpu->env;
     int ex_vec = -1;
 
     D_LOG("exception index=%d interrupt_req=%d\n",
@@ -171,10 +177,6 @@ void cris_cpu_do_interrupt(CPUState *cs)
     CPUCRISState *env = &cpu->env;
     int ex_vec = -1;
 
-    if (env->pregs[PR_VR] < 32) {
-        return do_interruptv10(env);
-    }
-
     D_LOG("exception index=%d interrupt_req=%d\n",
           env->exception_index,
           cs->interrupt_request);
Signature · 1 line
1.8.1.4