target-i386: clear bsp bit when designating bsp

Since the BSP bit is writable on real hardware, during reset all the CPUs which
were not chosen to be the BSP should have their BSP bit cleared. This fix is
required for KVM to work correctly when it changes the BSP bit.

An additional fix is required for QEMU tcg to allow software to change the BSP
bit.

Backports commit 9cb11fd7539b5b787d8fb3834004804a58dd16ae from qemu
This commit is contained in:
Nadav Amit 2018-02-12 16:38:52 -05:00 committed by Lioncash
parent d723e590f2
commit 8debf8cc3c
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
3 changed files with 8 additions and 6 deletions

View file

@ -161,7 +161,7 @@ void apic_init_reset(struct uc_struct *uc, DeviceState *dev)
}
}
void apic_designate_bsp(struct uc_struct *uc, DeviceState *dev)
void apic_designate_bsp(struct uc_struct *uc, DeviceState *dev, bool bsp)
{
APICCommonState *s;
@ -170,7 +170,11 @@ void apic_designate_bsp(struct uc_struct *uc, DeviceState *dev)
}
s = APIC_COMMON(uc, dev);
s->apicbase |= MSR_IA32_APICBASE_BSP;
if (bsp) {
s->apicbase |= MSR_IA32_APICBASE_BSP;
} else {
s->apicbase &= ~MSR_IA32_APICBASE_BSP;
}
}
static void apic_reset_common(struct uc_struct *uc, DeviceState *dev)

View file

@ -15,7 +15,7 @@ void apic_sipi(DeviceState *s);
void apic_handle_tpr_access_report(DeviceState *d, target_ulong ip,
TPRAccess access);
void apic_poll_irq(DeviceState *d);
void apic_designate_bsp(struct uc_struct *uc, DeviceState *d);
void apic_designate_bsp(struct uc_struct *uc, DeviceState *d, bool bsp);
/* pc.c */
DeviceState *cpu_get_current_apic(struct uc_struct *uc);

View file

@ -2289,9 +2289,7 @@ static void x86_cpu_reset(CPUState *s)
#if !defined(CONFIG_USER_ONLY)
/* We hard-wire the BSP to the first CPU. */
if (s->cpu_index == 0) {
apic_designate_bsp(env->uc, cpu->apic_state);
}
apic_designate_bsp(env->uc, cpu->apic_state, s->cpu_index == 0);
s->halted = !cpu_is_bsp(cpu);
#endif