Skip to content

Commit ffa4901

Browse files
xinli-intelbp3tk0v
authored andcommitted
x86/fred: Add a machine check entry stub for FRED
Like #DB, when occurred on different ring level, i.e., from user or kernel context, #MCE needs to be handled on different stack: User #MCE on current task stack, while kernel #MCE on a dedicated stack. This is exactly how FRED event delivery invokes an exception handler: ring 3 event on level 0 stack, i.e., current task stack; ring 0 event on the the FRED machine check entry stub doesn't do stack switch. Signed-off-by: Xin Li <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Tested-by: Shan Kang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f8b8ee4 commit ffa4901

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

arch/x86/kernel/cpu/mce/core.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <linux/hardirq.h>
4747
#include <linux/kexec.h>
4848

49+
#include <asm/fred.h>
4950
#include <asm/intel-family.h>
5051
#include <asm/processor.h>
5152
#include <asm/traps.h>
@@ -2166,6 +2167,31 @@ DEFINE_IDTENTRY_MCE_USER(exc_machine_check)
21662167
exc_machine_check_user(regs);
21672168
local_db_restore(dr7);
21682169
}
2170+
2171+
#ifdef CONFIG_X86_FRED
2172+
/*
2173+
* When occurred on different ring level, i.e., from user or kernel
2174+
* context, #MCE needs to be handled on different stack: User #MCE
2175+
* on current task stack, while kernel #MCE on a dedicated stack.
2176+
*
2177+
* This is exactly how FRED event delivery invokes an exception
2178+
* handler: ring 3 event on level 0 stack, i.e., current task stack;
2179+
* ring 0 event on the #MCE dedicated stack specified in the
2180+
* IA32_FRED_STKLVLS MSR. So unlike IDT, the FRED machine check entry
2181+
* stub doesn't do stack switch.
2182+
*/
2183+
DEFINE_FREDENTRY_MCE(exc_machine_check)
2184+
{
2185+
unsigned long dr7;
2186+
2187+
dr7 = local_db_save();
2188+
if (user_mode(regs))
2189+
exc_machine_check_user(regs);
2190+
else
2191+
exc_machine_check_kernel(regs);
2192+
local_db_restore(dr7);
2193+
}
2194+
#endif
21692195
#else
21702196
/* 32bit unified entry point */
21712197
DEFINE_IDTENTRY_RAW(exc_machine_check)

0 commit comments

Comments
 (0)