@@ -891,6 +891,15 @@ static void kvm_kernel_lapic_load_from_user(APICState *s)
#endif
+void qemu_kvm_load_lapic(CPUState *env)
+{
+#ifdef KVM_CAP_IRQCHIP
+ if (kvm_enabled() && kvm_vcpu_inited(env) && qemu_kvm_irqchip_in_kernel()) {
+ kvm_kernel_lapic_load_from_user(env->apic_state);
+ }
+#endif
+}
+
static void apic_save(QEMUFile *f, void *opaque)
{
APICState *s = opaque;
@@ -965,11 +974,7 @@ static int apic_load(QEMUFile *f, void *opaque, int version_id)
if (version_id >= 2)
qemu_get_timer(f, s->timer);
-#ifdef KVM_CAP_IRQCHIP
- if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
- kvm_kernel_lapic_load_from_user(s);
- }
-#endif
+ qemu_kvm_load_lapic(s->cpu_env);
return 0;
}
@@ -991,11 +996,7 @@ static void apic_reset(void *opaque)
*/
s->lvt[APIC_LVT_LINT0] = 0x700;
}
-#ifdef KVM_CAP_IRQCHIP
- if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
- kvm_kernel_lapic_load_from_user(s);
- }
-#endif
+ qemu_kvm_load_lapic(s->cpu_env);
}
static CPUReadMemoryFunc *apic_mem_read[3] = {
@@ -462,6 +462,11 @@ void kvm_init_vcpu(CPUState *env)
qemu_cond_wait(&qemu_vcpu_cond);
}
+int kvm_vcpu_inited(CPUState *env)
+{
+ return env->kvm_cpu_state.created;
+}
+
int kvm_init_ap(void)
{
#ifdef TARGET_I386
@@ -16,6 +16,7 @@ int kvm_main_loop(void);
int kvm_qemu_init(void);
int kvm_qemu_create_context(void);
int kvm_init_ap(void);
+int kvm_vcpu_inited(CPUState *env);
void kvm_qemu_destroy(void);
void kvm_load_registers(CPUState *env);
void kvm_save_registers(CPUState *env);
@@ -31,6 +32,9 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap);
int kvm_qemu_init_env(CPUState *env);
int kvm_qemu_check_extension(int ext);
void kvm_apic_init(CPUState *env);
+/* called from vcpu initialization */
+void qemu_kvm_load_lapic(CPUState *env);
+
int kvm_set_irq(int irq, int level, int *status);
int kvm_physical_memory_set_dirty_tracking(int enable);
In a later patch, we will reorder the execution of vcpu initialization. After that, the first call to KVM_SET_LAPIC ioctl will not find an existant vcpu. So we introduce a function that tell us that the vcpu is already initialized, and is it safe to call the ioctl. This patch is included first rather than after, so nothing breaks, and we can keep the tree bisectable. Signed-off-by: Glauber Costa <glommer@redhat.com> --- hw/apic.c | 21 +++++++++++---------- qemu-kvm.c | 5 +++++ qemu-kvm.h | 4 ++++ 3 files changed, 20 insertions(+), 10 deletions(-)