Skip to content

Commit 73270c1

Browse files
xinli-intelKAGA-KOKO
authored andcommitted
x86/fred: Move FRED RSP initialization into a separate function
To enable FRED earlier, move the RSP initialization out of cpu_init_fred_exceptions() into cpu_init_fred_rsps(). This is required as the FRED RSP initialization depends on the availability of the CPU entry areas which are set up late in trap_init(), No functional change intended. Marked with Fixes as it's a depedency for the real fix. Fixes: 14619d9 ("x86/fred: FRED entry/exit and dispatch code") Signed-off-by: Xin Li (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 989b5cf commit 73270c1

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

arch/x86/include/asm/fred.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ static __always_inline void fred_entry_from_kvm(unsigned int type, unsigned int
8484
}
8585

8686
void cpu_init_fred_exceptions(void);
87+
void cpu_init_fred_rsps(void);
8788
void fred_complete_exception_setup(void);
8889

8990
#else /* CONFIG_X86_FRED */
9091
static __always_inline unsigned long fred_event_data(struct pt_regs *regs) { return 0; }
9192
static inline void cpu_init_fred_exceptions(void) { }
93+
static inline void cpu_init_fred_rsps(void) { }
9294
static inline void fred_complete_exception_setup(void) { }
9395
static __always_inline void fred_entry_from_kvm(unsigned int type, unsigned int vector) { }
9496
#endif /* CONFIG_X86_FRED */

arch/x86/kernel/cpu/common.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,10 +2195,12 @@ void cpu_init_exception_handling(void)
21952195
/* GHCB needs to be setup to handle #VC. */
21962196
setup_ghcb();
21972197

2198-
if (cpu_feature_enabled(X86_FEATURE_FRED))
2198+
if (cpu_feature_enabled(X86_FEATURE_FRED)) {
21992199
cpu_init_fred_exceptions();
2200-
else
2200+
cpu_init_fred_rsps();
2201+
} else {
22012202
load_current_idt();
2203+
}
22022204
}
22032205

22042206
/*

arch/x86/kernel/fred.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ void cpu_init_fred_exceptions(void)
3232
FRED_CONFIG_INT_STKLVL(0) |
3333
FRED_CONFIG_ENTRYPOINT(asm_fred_entrypoint_user));
3434

35+
wrmsrl(MSR_IA32_FRED_STKLVLS, 0);
36+
wrmsrl(MSR_IA32_FRED_RSP0, 0);
37+
wrmsrl(MSR_IA32_FRED_RSP1, 0);
38+
wrmsrl(MSR_IA32_FRED_RSP2, 0);
39+
wrmsrl(MSR_IA32_FRED_RSP3, 0);
40+
41+
/* Enable FRED */
42+
cr4_set_bits(X86_CR4_FRED);
43+
/* Any further IDT use is a bug */
44+
idt_invalidate();
45+
46+
/* Use int $0x80 for 32-bit system calls in FRED mode */
47+
setup_clear_cpu_cap(X86_FEATURE_SYSENTER32);
48+
setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
49+
}
50+
51+
/* Must be called after setup_cpu_entry_areas() */
52+
void cpu_init_fred_rsps(void)
53+
{
3554
/*
3655
* The purpose of separate stacks for NMI, #DB and #MC *in the kernel*
3756
* (remember that user space faults are always taken on stack level 0)
@@ -47,13 +66,4 @@ void cpu_init_fred_exceptions(void)
4766
wrmsrl(MSR_IA32_FRED_RSP1, __this_cpu_ist_top_va(DB));
4867
wrmsrl(MSR_IA32_FRED_RSP2, __this_cpu_ist_top_va(NMI));
4968
wrmsrl(MSR_IA32_FRED_RSP3, __this_cpu_ist_top_va(DF));
50-
51-
/* Enable FRED */
52-
cr4_set_bits(X86_CR4_FRED);
53-
/* Any further IDT use is a bug */
54-
idt_invalidate();
55-
56-
/* Use int $0x80 for 32-bit system calls in FRED mode */
57-
setup_clear_cpu_cap(X86_FEATURE_SYSENTER32);
58-
setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
5969
}

0 commit comments

Comments
 (0)