Skip to contentSkip to conversation

x86: Reset lapic after boot

PATCH In review Nadav Amit 3 participants 3 messages Jun 27, 2019 – Jul 2, 2019 KVM

lore
Share & tools
lore

Nadav Amit

author
#0 lore raw

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().

Cc Krish Sadhukhan <[email protected]>
---
 lib/x86/apic.c | 2 +-
 x86/cstart64.S | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
lib/x86/apic.c +1 -1
index 1514730..b3e39ae 100644
@@ -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
index 9791282..1889c6b 100644
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
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 use xapic_write(), in order to make safe to use while apic_ops might change concurrently by x2apic_enable().

s/x2apic_enable/enable_x2apic/

Quoted 34 lines
Cc Krish Sadhukhan <[email protected]>
---
  lib/x86/apic.c | 2 +-
  x86/cstart64.S | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)
lib/x86/apic.c +1 -1
index 1514730..b3e39ae 100644
@@ -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
index 9791282..1889c6b 100644
@@ -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,

maintainer
#2 lore raw
In reply to Nadav Amit
Quoted 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 use xapic_write(), in order to make safe to use while apic_ops might change concurrently by x2apic_enable().

Cc Krish Sadhukhan <[email protected]>

---

Also needs the 32-bit version:

x86/cstart.S +2 -0
index 2fa4c30..575101b 100644
@@ -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