[PATCH 07/14] x86/entry, mce: Disallow #DB during #MC

From: Peter Zijlstra
Date: Fri May 29 2020 - 17:37:14 EST


#MC is fragile as heck, don't tempt fate.

Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/mce/core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -1936,22 +1936,34 @@ static __always_inline void exc_machine_
/* MCE hit kernel mode */
DEFINE_IDTENTRY_MCE(exc_machine_check)
{
+ unsigned long dr7;
+
+ dr7 = local_db_save();
exc_machine_check_kernel(regs);
+ local_db_restore(dr7);
}

/* The user mode variant. */
DEFINE_IDTENTRY_MCE_USER(exc_machine_check)
{
+ unsigned long dr7;
+
+ dr7 = local_db_save();
exc_machine_check_user(regs);
+ local_db_restore(dr7);
}
#else
/* 32bit unified entry point */
DEFINE_IDTENTRY_MCE(exc_machine_check)
{
+ unsigned long dr7;
+
+ dr7 = local_db_save();
if (user_mode(regs))
exc_machine_check_user(regs);
else
exc_machine_check_kernel(regs);
+ local_db_restore(dr7);
}
#endif