From 923a7e7cfa3babad7d8bb19a69a2b4a7b090e649 Mon Sep 17 00:00:00 2001 From: leoliu-oc Date: Thu, 25 Dec 2025 18:36:02 +0800 Subject: [PATCH] anolis: x86/mce: Improve conditional NMI context handling for MCE ANBZ: #28531 Machine check (#MC) exceptions require proper NMI context management to prevent issues like console_owner_lock contention and HPET deadlocks. This patch enhances the NMI handling by introducing a more robust mechanism that properly tracks and manages NMI state. The implementation includes: 1. A per-CPU variable to track NMI state, ensuring accurate context management 2. Conditional NMI context setup that only activates when not already in an NMI context 3. Proper state cleanup to maintain consistent NMI state boundaries These improvements prevent potential nested NMI operations and ensure that critical sections like panic and kmsg_dump can execute safely without deadlocks when machine check exceptions occur. Signed-off-by: LeoLiu-oc --- arch/x86/kernel/cpu/mce/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index a99107a98416..2b8daa2fe64b 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -2052,10 +2052,14 @@ 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; + irqentry_enter_from_user_mode(regs); + irq_state = irqentry_nmi_enter(regs); instrumentation_begin(); machine_check_vector(regs); instrumentation_end(); + irqentry_nmi_exit(regs, irq_state); irqentry_exit_to_user_mode(regs); } -- Gitee