Skip to content

Commit 13cbc0c

Browse files
amlutoKAGA-KOKO
authored andcommitted
x86/entry/32: Fix #MC and #DB wiring on x86_32
DEFINE_IDTENTRY_MCE and DEFINE_IDTENTRY_DEBUG were wired up as non-RAW on x86_32, but the code expected them to be RAW. Get rid of all the macro indirection for them on 32-bit and just use DECLARE_IDTENTRY_RAW and DEFINE_IDTENTRY_RAW directly. Also add a warning to make sure that we only hit the _kernel paths in kernel mode. Reported-by: Naresh Kamboju <[email protected]> Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/9e90a7ee8e72fd757db6d92e1e5ff16339c1ecf9.1593795633.git.luto@kernel.org
1 parent f41f082 commit 13cbc0c

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

arch/x86/include/asm/idtentry.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,6 @@ static __always_inline void __##func(struct pt_regs *regs)
353353

354354
#else /* CONFIG_X86_64 */
355355

356-
/* Maps to a regular IDTENTRY on 32bit for now */
357-
# define DECLARE_IDTENTRY_IST DECLARE_IDTENTRY
358-
# define DEFINE_IDTENTRY_IST DEFINE_IDTENTRY
359-
360356
/**
361357
* DECLARE_IDTENTRY_DF - Declare functions for double fault 32bit variant
362358
* @vector: Vector number (ignored for C)
@@ -387,16 +383,18 @@ __visible noinstr void func(struct pt_regs *regs, \
387383
#endif /* !CONFIG_X86_64 */
388384

389385
/* C-Code mapping */
386+
#define DECLARE_IDTENTRY_NMI DECLARE_IDTENTRY_RAW
387+
#define DEFINE_IDTENTRY_NMI DEFINE_IDTENTRY_RAW
388+
389+
#ifdef CONFIG_X86_64
390390
#define DECLARE_IDTENTRY_MCE DECLARE_IDTENTRY_IST
391391
#define DEFINE_IDTENTRY_MCE DEFINE_IDTENTRY_IST
392392
#define DEFINE_IDTENTRY_MCE_USER DEFINE_IDTENTRY_NOIST
393393

394-
#define DECLARE_IDTENTRY_NMI DECLARE_IDTENTRY_RAW
395-
#define DEFINE_IDTENTRY_NMI DEFINE_IDTENTRY_RAW
396-
397394
#define DECLARE_IDTENTRY_DEBUG DECLARE_IDTENTRY_IST
398395
#define DEFINE_IDTENTRY_DEBUG DEFINE_IDTENTRY_IST
399396
#define DEFINE_IDTENTRY_DEBUG_USER DEFINE_IDTENTRY_NOIST
397+
#endif
400398

401399
#else /* !__ASSEMBLY__ */
402400

@@ -443,9 +441,6 @@ __visible noinstr void func(struct pt_regs *regs, \
443441
# define DECLARE_IDTENTRY_MCE(vector, func) \
444442
DECLARE_IDTENTRY(vector, func)
445443

446-
# define DECLARE_IDTENTRY_DEBUG(vector, func) \
447-
DECLARE_IDTENTRY(vector, func)
448-
449444
/* No ASM emitted for DF as this goes through a C shim */
450445
# define DECLARE_IDTENTRY_DF(vector, func)
451446

@@ -549,7 +544,11 @@ DECLARE_IDTENTRY_RAW(X86_TRAP_BP, exc_int3);
549544
DECLARE_IDTENTRY_RAW_ERRORCODE(X86_TRAP_PF, exc_page_fault);
550545

551546
#ifdef CONFIG_X86_MCE
547+
#ifdef CONFIG_X86_64
552548
DECLARE_IDTENTRY_MCE(X86_TRAP_MC, exc_machine_check);
549+
#else
550+
DECLARE_IDTENTRY_RAW(X86_TRAP_MC, exc_machine_check);
551+
#endif
553552
#endif
554553

555554
/* NMI */
@@ -559,7 +558,11 @@ DECLARE_IDTENTRY_RAW(X86_TRAP_NMI, xenpv_exc_nmi);
559558
#endif
560559

561560
/* #DB */
561+
#ifdef CONFIG_X86_64
562562
DECLARE_IDTENTRY_DEBUG(X86_TRAP_DB, exc_debug);
563+
#else
564+
DECLARE_IDTENTRY_RAW(X86_TRAP_DB, exc_debug);
565+
#endif
563566
#ifdef CONFIG_XEN_PV
564567
DECLARE_IDTENTRY_RAW(X86_TRAP_DB, xenpv_exc_debug);
565568
#endif

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,8 @@ void (*machine_check_vector)(struct pt_regs *) = unexpected_machine_check;
19011901

19021902
static __always_inline void exc_machine_check_kernel(struct pt_regs *regs)
19031903
{
1904+
WARN_ON_ONCE(user_mode(regs));
1905+
19041906
/*
19051907
* Only required when from kernel mode. See
19061908
* mce_check_crashing_cpu() for details.
@@ -1954,7 +1956,7 @@ DEFINE_IDTENTRY_MCE_USER(exc_machine_check)
19541956
}
19551957
#else
19561958
/* 32bit unified entry point */
1957-
DEFINE_IDTENTRY_MCE(exc_machine_check)
1959+
DEFINE_IDTENTRY_RAW(exc_machine_check)
19581960
{
19591961
unsigned long dr7;
19601962

arch/x86/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ DEFINE_IDTENTRY_DEBUG_USER(exc_debug)
925925
}
926926
#else
927927
/* 32 bit does not have separate entry points. */
928-
DEFINE_IDTENTRY_DEBUG(exc_debug)
928+
DEFINE_IDTENTRY_RAW(exc_debug)
929929
{
930930
unsigned long dr6, dr7;
931931

0 commit comments

Comments
 (0)