From: Glauber Costa <[email protected]> KVM access some state that is only present late in cpu initialization. This happens in kvm_vcpu_init(). APIC is an example of that.
So we have to make sure that kvm_vcpu_init is the last thing called in the initialization process. We also have to explicitly call qemu_kvm_load_apic(), since the first call will find the vcpu non initialized. Signed-off-by: Glauber Costa <[email protected]> Signed-off-by: Avi Kivity <[email protected]> diff --git a/hw/pc.c b/hw/pc.c index 74754a3..077187b 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -844,6 +844,11 @@ CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled) if (pci_enabled) { apic_init(env); } + + /* kvm needs this to run after the apic is initialized. Otherwise, + * it can access invalid state and crash. + */ + qemu_init_vcpu(env); return env; } diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index fcb594c..98aa530 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -527,6 +527,8 @@ int kvm_arch_qemu_init_env(CPUState *cenv) CPUState copy; uint32_t i, j, limit; + qemu_kvm_load_lapic(cenv); + copy = *cenv; #ifdef KVM_CPUID_SIGNATURE diff --git a/target-i386/helper.c b/target-i386/helper.c index 848d05b..6dc0111 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1699,7 +1699,5 @@ CPUX86State *cpu_x86_init(const char *cpu_model) kqemu_init(env); #endif - qemu_init_vcpu(env); - return env; } -- To unsubscribe from this list: send the line "unsubscribe kvm-commits" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
