From 9cfac948964223e4bcbc2700c55b764b67a69a8e Mon Sep 17 00:00:00 2001 From: leoliu-oc Date: Fri, 28 Jun 2024 16:33:56 +0800 Subject: [PATCH] anolis: x86/mce: Add NMIs setup in machine_check func ANBZ: #9448 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. CPU x CPU x ---- ---- vprintk vprintk_default vprintk_emit console_trylock_spinning ...(&console_owner_lock) #MCE happened do_machine_check mce_panic panic console_flush_on_panic console_emit_next_record console_lock_spinning_enable ...(&console_owner_lock) To avoid these issues, add NMIs setup When Handling #MC Exceptions. Signed-off-by: leoliu-oc --- arch/x86/kernel/cpu/mce/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index c9c9ebbb3268..1efb2a807981 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -2122,11 +2122,17 @@ static __always_inline void exc_machine_check_kernel(struct pt_regs *regs) static __always_inline void exc_machine_check_user(struct pt_regs *regs) { + irqentry_state_t irq_state; + + irq_state = irqentry_nmi_enter(regs); + irqentry_enter_from_user_mode(regs); do_machine_check(regs); irqentry_exit_to_user_mode(regs); + + irqentry_nmi_exit(regs, irq_state); } #ifdef CONFIG_X86_64 -- Gitee