x86/cpu: Init AP exception handling from cpu_init_secondary()
[ Upstream commit b1efd0ff4bd16e8bb8607ba566b03f2024a830bb ] 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() on secondary CPUs which can cause such #VC exceptions. Simplify the machinery by running that exception setup from a new function cpu_init_secondary() and explicitly call cpu_init_exception_handling() for the boot CPU before cpu_init(). The latter prepares for fixing and simplifying the exception/IST setup on the boot CPU. There should be no functional changes resulting from this patch. [ tglx: Reworked it so cpu_init_exception_handling() stays seperate ] Signed-off-by: Borislav Petkov <bp@suse.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Lai Jiangshan <laijs@linux.alibaba.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/87k0o6gtvu.ffs@nanos.tec.linutronix.de Stable-dep-of: c0dd9245aa9e ("x86/microcode: Check CPU capabilities after late microcode update correctly") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
0e7a569929
commit
2e3bd75f64
@@ -682,6 +682,7 @@ extern void load_direct_gdt(int);
|
|||||||
extern void load_fixmap_gdt(int);
|
extern void load_fixmap_gdt(int);
|
||||||
extern void load_percpu_segment(int);
|
extern void load_percpu_segment(int);
|
||||||
extern void cpu_init(void);
|
extern void cpu_init(void);
|
||||||
|
extern void cpu_init_secondary(void);
|
||||||
extern void cpu_init_exception_handling(void);
|
extern void cpu_init_exception_handling(void);
|
||||||
extern void cr4_init(void);
|
extern void cr4_init(void);
|
||||||
|
|
||||||
|
@@ -2048,13 +2048,12 @@ void cpu_init_exception_handling(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* cpu_init() initializes state that is per-CPU. Some data is already
|
* cpu_init() initializes state that is per-CPU. Some data is already
|
||||||
* initialized (naturally) in the bootstrap process, such as the GDT
|
* initialized (naturally) in the bootstrap process, such as the GDT. We
|
||||||
* and IDT. We reload them nevertheless, this function acts as a
|
* reload it nevertheless, this function acts as a 'CPU state barrier',
|
||||||
* 'CPU state barrier', nothing should get across.
|
* nothing should get across.
|
||||||
*/
|
*/
|
||||||
void cpu_init(void)
|
void cpu_init(void)
|
||||||
{
|
{
|
||||||
struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
|
|
||||||
struct task_struct *cur = current;
|
struct task_struct *cur = current;
|
||||||
int cpu = raw_smp_processor_id();
|
int cpu = raw_smp_processor_id();
|
||||||
|
|
||||||
@@ -2067,8 +2066,6 @@ void cpu_init(void)
|
|||||||
early_cpu_to_node(cpu) != NUMA_NO_NODE)
|
early_cpu_to_node(cpu) != NUMA_NO_NODE)
|
||||||
set_numa_node(early_cpu_to_node(cpu));
|
set_numa_node(early_cpu_to_node(cpu));
|
||||||
#endif
|
#endif
|
||||||
setup_getcpu(cpu);
|
|
||||||
|
|
||||||
pr_debug("Initializing CPU#%d\n", cpu);
|
pr_debug("Initializing CPU#%d\n", cpu);
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_X86_64) || cpu_feature_enabled(X86_FEATURE_VME) ||
|
if (IS_ENABLED(CONFIG_X86_64) || cpu_feature_enabled(X86_FEATURE_VME) ||
|
||||||
@@ -2080,7 +2077,6 @@ void cpu_init(void)
|
|||||||
* and set up the GDT descriptor:
|
* and set up the GDT descriptor:
|
||||||
*/
|
*/
|
||||||
switch_to_new_gdt(cpu);
|
switch_to_new_gdt(cpu);
|
||||||
load_current_idt();
|
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_X86_64)) {
|
if (IS_ENABLED(CONFIG_X86_64)) {
|
||||||
loadsegment(fs, 0);
|
loadsegment(fs, 0);
|
||||||
@@ -2100,12 +2096,6 @@ void cpu_init(void)
|
|||||||
initialize_tlbstate_and_flush();
|
initialize_tlbstate_and_flush();
|
||||||
enter_lazy_tlb(&init_mm, cur);
|
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
|
* sp0 points to the entry trampoline stack regardless of what task
|
||||||
* is running.
|
* is running.
|
||||||
@@ -2127,6 +2117,18 @@ void cpu_init(void)
|
|||||||
load_fixmap_gdt(cpu);
|
load_fixmap_gdt(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_SMP
|
||||||
|
void cpu_init_secondary(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Relies on the BP having set-up the IDT tables, which are loaded
|
||||||
|
* on this CPU in cpu_init_exception_handling().
|
||||||
|
*/
|
||||||
|
cpu_init_exception_handling();
|
||||||
|
cpu_init();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The microcode loader calls this upon late microcode load to recheck features,
|
* The microcode loader calls this upon late microcode load to recheck features,
|
||||||
* only when microcode has been updated. Caller holds microcode_mutex and CPU
|
* only when microcode has been updated. Caller holds microcode_mutex and CPU
|
||||||
|
@@ -227,8 +227,7 @@ static void notrace start_secondary(void *unused)
|
|||||||
load_cr3(swapper_pg_dir);
|
load_cr3(swapper_pg_dir);
|
||||||
__flush_tlb_all();
|
__flush_tlb_all();
|
||||||
#endif
|
#endif
|
||||||
cpu_init_exception_handling();
|
cpu_init_secondary();
|
||||||
cpu_init();
|
|
||||||
rcu_cpu_starting(raw_smp_processor_id());
|
rcu_cpu_starting(raw_smp_processor_id());
|
||||||
x86_cpuinit.early_percpu_clock_init();
|
x86_cpuinit.early_percpu_clock_init();
|
||||||
smp_callin();
|
smp_callin();
|
||||||
|
@@ -1185,9 +1185,7 @@ void __init trap_init(void)
|
|||||||
|
|
||||||
idt_setup_traps();
|
idt_setup_traps();
|
||||||
|
|
||||||
/*
|
cpu_init_exception_handling();
|
||||||
* Should be a barrier for any external CPU state:
|
|
||||||
*/
|
|
||||||
cpu_init();
|
cpu_init();
|
||||||
|
|
||||||
idt_setup_ist_traps();
|
idt_setup_ist_traps();
|
||||||
|
Reference in New Issue
Block a user