x86/cpu: Init exception handling from cpu_init()
Borislav Petkov
maintainerPATCH 1/1 x86/cpu: Init exception handling from cpu_init()
From: Borislav Petkov <[email protected]>
SEV-ES guests require properly setup task register with which the TSS descriptor in the GDT can be located so that the IST-type #VC exception handler which they need to function properly, can be executed.
This setup needs to happen before attempting to load microcode in ucode_cpu_init() which can cause such #VC exceptions.
Simplify the machinery by running that exception setup from cpu_init() directly.
There should be no functional changes resulting from this patch.
--- arch/x86/include/asm/processor.h | 1 - arch/x86/kernel/cpu/common.c | 14 +++----------- arch/x86/kernel/smpboot.c | 1 - 3 files changed, 3 insertions(+), 13 deletions(-)
arch/x86/include/asm/processor.h +0 -1
@@ -663,7 +663,6 @@ 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 )
arch/x86/kernel/cpu/common.c +3 -11
@@ -1917,7 +1917,7 @@ static inline void tss_setup_io_bitmap(struct tss_struct *tss)* Setup everything needed to handle exceptions from the IDT, including the IST * exceptions which use paranoid_entry(). */ -void cpu_init_exception_handling (void ) +static void init_exception_handling (void ) {struct tss_struct *tss =this_cpu_ptr (&cpu_tss_rw);int cpu =raw_smp_processor_id ();
@@ -1944,10 +1944,11 @@ void cpu_init_exception_handling(void)*/ void cpu_init (void ) { -struct tss_struct *tss =this_cpu_ptr (&cpu_tss_rw);struct task_struct *cur = current;int cpu =raw_smp_processor_id (); +init_exception_handling (); +wait_for_master_cpu (cpu);ucode_cpu_init (cpu);
@@ -1957,8 +1958,6 @@ void cpu_init(void) early_cpu_to_node(cpu) != NUMA_NO_NODE)set_numa_node (early_cpu_to_node (cpu));#endif -setup_getcpu (cpu); -pr_debug ("Initializing CPU#%d\n" , cpu); if (IS_ENABLED(CONFIG_X86_64) || cpu_feature_enabled(X86_FEATURE_VME) ||
@@ -1970,7 +1969,6 @@ void cpu_init(void)* and set up the GDT descriptor: */ switch_to_new_gdt (cpu); -load_current_idt ();if (IS_ENABLED (CONFIG_X86_64 )) {loadsegment (fs,0 );
@@ -1990,12 +1988,6 @@ void cpu_init(void)initialize_tlbstate_and_flush ();enter_lazy_tlb (&init_mm, cur); -/* Initialize the TSS. */ -tss_setup_ist (tss); -tss_setup_io_bitmap (tss); -set_tss_desc (cpu, &get_cpu_entry_area (cpu)->tss.x86_tss); - -load_TR_desc ();/* * sp0 points to the entry trampoline stack regardless of what task * is running.
arch/x86/kernel/smpboot.c +0 -1
@@ -232,7 +232,6 @@ static void notrace start_secondary(void *unused)load_cr3 (swapper_pg_dir);__flush_tlb_all ();#endif -cpu_init_exception_handling ();cpu_init ();rcu_cpu_starting (raw_smp_processor_id ()); x86_cpuinit.early_percpu_clock_init ();
Signature · 1 line
2.29.2
Quoted 12 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
SEV-ES guests require properly setup task register with which the TSS descriptor in the GDT can be located so that the IST-type #VC exception handler which they need to function properly, can be executed.
This setup needs to happen before attempting to load microcode in
ucode_cpu_init()which can cause such #VC exceptions.Simplify the machinery by running that exception setup from
cpu_init()directly.
Quoted 8 lines
There should be no functional changes resulting from this patch.
Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/include/asm/processor.h | 1 - arch/x86/kernel/cpu/common.c | 14 +++----------- arch/x86/kernel/smpboot.c | 1 - 3 files changed, 3 insertions(+), 13 deletions(-)