Skip to content

Commit b1efd0f

Browse files
suryasaimadhuKAGA-KOKO
authored andcommitted
x86/cpu: Init AP exception handling from cpu_init_secondary()
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
1 parent d07f6ca commit b1efd0f

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ extern void load_direct_gdt(int);
663663
extern void load_fixmap_gdt(int);
664664
extern void load_percpu_segment(int);
665665
extern void cpu_init(void);
666+
extern void cpu_init_secondary(void);
666667
extern void cpu_init_exception_handling(void);
667668
extern void cr4_init(void);
668669

arch/x86/kernel/cpu/common.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,13 +1938,12 @@ void cpu_init_exception_handling(void)
19381938

19391939
/*
19401940
* cpu_init() initializes state that is per-CPU. Some data is already
1941-
* initialized (naturally) in the bootstrap process, such as the GDT
1942-
* and IDT. We reload them nevertheless, this function acts as a
1943-
* 'CPU state barrier', nothing should get across.
1941+
* initialized (naturally) in the bootstrap process, such as the GDT. We
1942+
* reload it nevertheless, this function acts as a 'CPU state barrier',
1943+
* nothing should get across.
19441944
*/
19451945
void cpu_init(void)
19461946
{
1947-
struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
19481947
struct task_struct *cur = current;
19491948
int cpu = raw_smp_processor_id();
19501949

@@ -1957,8 +1956,6 @@ void cpu_init(void)
19571956
early_cpu_to_node(cpu) != NUMA_NO_NODE)
19581957
set_numa_node(early_cpu_to_node(cpu));
19591958
#endif
1960-
setup_getcpu(cpu);
1961-
19621959
pr_debug("Initializing CPU#%d\n", cpu);
19631960

19641961
if (IS_ENABLED(CONFIG_X86_64) || cpu_feature_enabled(X86_FEATURE_VME) ||
@@ -1970,7 +1967,6 @@ void cpu_init(void)
19701967
* and set up the GDT descriptor:
19711968
*/
19721969
switch_to_new_gdt(cpu);
1973-
load_current_idt();
19741970

19751971
if (IS_ENABLED(CONFIG_X86_64)) {
19761972
loadsegment(fs, 0);
@@ -1990,12 +1986,6 @@ void cpu_init(void)
19901986
initialize_tlbstate_and_flush();
19911987
enter_lazy_tlb(&init_mm, cur);
19921988

1993-
/* Initialize the TSS. */
1994-
tss_setup_ist(tss);
1995-
tss_setup_io_bitmap(tss);
1996-
set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
1997-
1998-
load_TR_desc();
19991989
/*
20001990
* sp0 points to the entry trampoline stack regardless of what task
20011991
* is running.
@@ -2017,6 +2007,18 @@ void cpu_init(void)
20172007
load_fixmap_gdt(cpu);
20182008
}
20192009

2010+
#ifdef CONFIG_SMP
2011+
void cpu_init_secondary(void)
2012+
{
2013+
/*
2014+
* Relies on the BP having set-up the IDT tables, which are loaded
2015+
* on this CPU in cpu_init_exception_handling().
2016+
*/
2017+
cpu_init_exception_handling();
2018+
cpu_init();
2019+
}
2020+
#endif
2021+
20202022
/*
20212023
* The microcode loader calls this upon late microcode load to recheck features,
20222024
* only when microcode has been updated. Caller holds microcode_mutex and CPU

arch/x86/kernel/smpboot.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ static void notrace start_secondary(void *unused)
232232
load_cr3(swapper_pg_dir);
233233
__flush_tlb_all();
234234
#endif
235-
cpu_init_exception_handling();
236-
cpu_init();
235+
cpu_init_secondary();
237236
rcu_cpu_starting(raw_smp_processor_id());
238237
x86_cpuinit.early_percpu_clock_init();
239238
preempt_disable();

arch/x86/kernel/traps.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,9 +1162,7 @@ void __init trap_init(void)
11621162

11631163
idt_setup_traps();
11641164

1165-
/*
1166-
* Should be a barrier for any external CPU state:
1167-
*/
1165+
cpu_init_exception_handling();
11681166
cpu_init();
11691167

11701168
idt_setup_ist_traps();

0 commit comments

Comments
 (0)