[patch 1/4] QEMU/KVM: properly copy the in-kernel apicbase value

Marcelo Tosatti
2008-04-07T20:30:46Z

[-- Attachment #1: qemu-fix-apic --]
[-- Type: text/plain, Size: 2202 bytes --]

The MSR_IA32_APICBASE_ENABLE/MSR_IA32_APICBASE_BSP bits in s->apicbase
are not initialized if in-kernel APIC emulation is used, so save the
actual value passed by cpu_set_apic_base() caller.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: marcelo/git/kvm-userspace.io/qemu/hw/apic.c
===================================================================
--- marcelo.orig/git/kvm-userspace.io/qemu/hw/apic.c
+++ marcelo/git/kvm-userspace.io/qemu/hw/apic.c
@@ -248,8 +248,11 @@ void cpu_set_apic_base(CPUState *env, ui
#ifdef DEBUG_APIC
printf("cpu_set_apic_base: %016" PRIx64 "\n", val);
#endif
- s->apicbase = (val & 0xfffff000) |
- (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
+ if (kvm_enabled() && qemu_kvm_irqchip_in_kernel())
+ s->apicbase = val;
+ else
+ s->apicbase = (val & 0xfffff000) |
+ (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
/* if disabled, cannot be enabled again */
if (!(val & MSR_IA32_APICBASE_ENABLE)) {
s->apicbase &= ~MSR_IA32_APICBASE_ENABLE;
Index: marcelo/git/kvm-userspace.io/qemu/qemu-kvm-x86.c
===================================================================
--- marcelo.orig/git/kvm-userspace.io/qemu/qemu-kvm-x86.c
+++ marcelo/git/kvm-userspace.io/qemu/qemu-kvm-x86.c
@@ -248,13 +248,8 @@ void kvm_arch_load_regs(CPUState *env)
sregs.cr3 = env->cr[3];
sregs.cr4 = env->cr[4];

- if (kvm_irqchip_in_kernel(kvm_context)) {
- sregs.cr8 = kvm_get_cr8(kvm_context, env->cpu_index);
- sregs.apic_base = kvm_get_apic_base(kvm_context, env->cpu_index);
- } else {
- sregs.cr8 = cpu_get_apic_tpr(env);
- sregs.apic_base = cpu_get_apic_base(env);
- }
+ sregs.cr8 = cpu_get_apic_tpr(env);
+ sregs.apic_base = cpu_get_apic_base(env);

sregs.efer = env->efer;