x86/smpboot: Load TSS and getcpu GDT entry before loading IDT
authorJoerg Roedel <jroedel@suse.de>
Mon, 7 Sep 2020 13:16:08 +0000 (15:16 +0200)
committerBorislav Petkov <bp@suse.de>
Wed, 9 Sep 2020 09:33:20 +0000 (11:33 +0200)
The IDT on 64-bit contains vectors which use paranoid_entry() and/or IST
stacks. To make these vectors work, the TSS and the getcpu GDT entry need
to be set up before the IDT is loaded.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200907131613.12703-68-joro@8bytes.org
arch/x86/include/asm/processor.h
arch/x86/kernel/cpu/common.c
arch/x86/kernel/smpboot.c

index 97143d87994c24e21c6474121ad95255ec3d77c1..615dd440bed8706ee5adc595e129153396d302c7 100644 (file)
@@ -696,6 +696,7 @@ extern void load_direct_gdt(int);
 extern void load_fixmap_gdt(int);
 extern void load_percpu_segment(int);
 extern void cpu_init(void);
+extern void cpu_init_exception_handling(void);
 extern void cr4_init(void);
 
 static inline unsigned long get_debugctlmsr(void)
index 81fba4d4a242abdb13ed68d34e58cd9c0c6a4d05..beffea22e2af7d8671cc581c733c375ae25f5582 100644 (file)
@@ -1862,6 +1862,29 @@ static inline void tss_setup_io_bitmap(struct tss_struct *tss)
 #endif
 }
 
+/*
+ * Setup everything needed to handle exceptions from the IDT, including the IST
+ * exceptions which use paranoid_entry().
+ */
+void cpu_init_exception_handling(void)
+{
+       struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
+       int cpu = raw_smp_processor_id();
+
+       /* paranoid_entry() gets the CPU number from the GDT */
+       setup_getcpu(cpu);
+
+       /* IST vectors need TSS to be set up. */
+       tss_setup_ist(tss);
+       tss_setup_io_bitmap(tss);
+       set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
+
+       load_TR_desc();
+
+       /* Finally load the IDT */
+       load_current_idt();
+}
+
 /*
  * cpu_init() initializes state that is per-CPU. Some data is already
  * initialized (naturally) in the bootstrap process, such as the GDT
index f5ef689dd62ad743e18a9159206eb8ce15a13803..de776b2e60467b0f7d8bcbfbe0912cb6213d6554 100644 (file)
@@ -227,7 +227,7 @@ static void notrace start_secondary(void *unused)
        load_cr3(swapper_pg_dir);
        __flush_tlb_all();
 #endif
-       load_current_idt();
+       cpu_init_exception_handling();
        cpu_init();
        x86_cpuinit.early_percpu_clock_init();
        preempt_disable();