From b7d24be2e757f5132fa207f6412ff36e1c46188c Mon Sep 17 00:00:00 2001 From: LeoLiu-oc Date: Mon, 4 Nov 2024 16:39:26 +0800 Subject: [PATCH] x86/mce: Add NMIs setup in machine_check func \#MC is a NMI-like exception. But do not do any setup that NMIs need. This will lead to console_owner_lock issue and HPET dead loop issue. For example, The HPET dead loop issue: CPU x CPU x ---- ---- read_hpet() arch_spin_trylock(&hpet.lock) [CPU x got the hpet.lock] #MCE happened do_machine_check() mce_panic() panic() kmsg_dump() pstore_dump() pstore_record_init() ktime_get_real_fast_ns() read_hpet() [dead loops] This may lead to read_hpet dead loops. The console_owner_lock issue is similar. To avoid these issues, add NMIs setup When Handling #MC Exceptions. Signed-off-by: LeoLiu-oc --- arch/x86/kernel/cpu/mce/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 3c85464ff177..4d48be16bce3 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -2012,7 +2012,9 @@ void (*machine_check_vector)(struct pt_regs *, long error_code) = dotraplinkage void do_mce(struct pt_regs *regs, long error_code) { + nmi_enter(); machine_check_vector(regs, error_code); + nmi_exit(); } /*