x86: Reset lapic after boot
PATCH v2 1/1 x86: Reset lapic after boot
Do not assume that the local APIC is in a xAPIC mode after reset. Instead reset it first, since it might be in x2APIC mode, from which a transition in xAPIC is invalid.
To use reset_apic(), change it to use xapic_write(), in order to make safe to use while apic_ops might change concurrently by x2apic_enable().
--- lib/x86/apic.c | 2 +- x86/cstart64.S | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
lib/x86/apic.c +1 -1
@@ -164,7 +164,7 @@ void reset_apic(void) {disable_apic ();wrmsr (MSR_IA32_APICBASE ,rdmsr (MSR_IA32_APICBASE ) |APIC_EN ); -apic_write (APIC_SPIV ,0x1ff ); +xapic_write (APIC_SPIV ,0x1ff ); }u32 ioapic_read_reg (unsigned reg)
x86/cstart64.S +2 -0
@@ -228,6 +228,7 @@ save_id: retq ap_start64: + call reset_apic call load_tss call enable_apic call save_id
@@ -240,6 +241,7 @@ ap_start64: jmp 1b start64: + call reset_apic call load_tss call mask_pic_interrupts call enable_apic
Signature · 1 line
2.17.1
Quoted 3 lines · Nadav Amit
Do not assume that the local APIC is in a xAPIC mode after reset. Instead reset it first, since it might be in x2APIC mode, from which a transition in xAPIC is invalid.
s/transition in/transition to/
Quoted 3 lines
To use
reset_apic(), change it to usexapic_write(), in order to make safe to use whileapic_opsmight change concurrently byx2apic_enable().
s/x2apic_enable/enable_x2apic/
Quoted 34 lines
Cc Krish Sadhukhan <[email protected]>Signed-off-by Nadav Amit <[email protected]>--- lib/x86/apic.c | 2 +- x86/cstart64.S | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)lib/x86/apic.c +1
-1@@ -164,7 +164,7 @@ void reset_apic(void) {disable_apic ();wrmsr (MSR_IA32_APICBASE ,rdmsr (MSR_IA32_APICBASE ) |APIC_EN ); -apic_write (APIC_SPIV ,0x1ff ); +xapic_write (APIC_SPIV ,0x1ff ); }u32 ioapic_read_reg (unsigned reg)x86/cstart64.S +1
-0@@ -228,6 +228,7 @@ save_id: retq ap_start64: + call reset_apic call load_tss call enable_apic call save_id
x86/cstart64.S ap_start64: · line 247
Quoted 7 lines
x86/cstart64.S +1
-0@@ -240,6 +241,7 @@ ap_start64: jmp 1b start64: + call reset_apic call load_tss call mask_pic_interrupts call enable_apic
Except the above minor things,
Paolo Bonzini
maintainerQuoted 10 lines · Nadav Amit
Do not assume that the local APIC is in a xAPIC mode after reset. Instead reset it first, since it might be in x2APIC mode, from which a transition in xAPIC is invalid.
To use
reset_apic(), change it to usexapic_write(), in order to make safe to use whileapic_opsmight change concurrently byx2apic_enable().Cc Krish Sadhukhan <[email protected]>Signed-off-by Nadav Amit <[email protected]>---
Also needs the 32-bit version:
x86/cstart.S +2 -0
@@ -143,6 +143,7 @@ ap_start32: lock/xaddl %esp, smp_stacktop setup_percpu_area call prepare_32 + call reset_apic call save_id call load_tss call enable_apic
@@ -155,6 +156,7 @@ ap_start32: jmp 1b start32: + call reset_apic call save_id call load_tss call mask_pic_interrupts
Paolo