From 84ac636dfe0f11541ae276df9726cea1391d5189 Mon Sep 17 00:00:00 2001 From: Xiaomeng Zhang Date: Fri, 21 Feb 2025 01:29:36 +0000 Subject: [PATCH 1/2] x86: reboot: Initialize the printk locks to avoid deadlock Offering: HULK hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IB5G5N -------------------------------- The reboot process needs to acquire the lock for log printing, but the CPU holding the lock cannot release it while in NMI context, preventing the system from completing the reboot process normally. The primary function of nmi_shootdown_cpus() is to send NMI to all other CPUs. By adding zap_locks(), it reinitializes logbuf_lock and console_owner_lock, clears the owner and waiters of console_owner_lock, and reinitializes console_sem. This ensures that even if logbuf_lock is held, other CPUs calling printk in NMI context won't deadlock due to inability to acquire the lock. Fixes: c4ac4263a019 ("crashdump: x86: add NMI handler to capture other CPUs") Signed-off-by: Xiaomeng Zhang --- arch/x86/kernel/reboot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 970296f4403b..c5470431a1b6 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -924,6 +924,7 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback) mdelay(1); msecs--; } + zap_locks(); /* * Leave the nmi callback set, shootdown is a one-time thing. Clearing -- Gitee From 4c240be07f7581e21da69b7f40566e6e4c9743d0 Mon Sep 17 00:00:00 2001 From: Xiaomeng Zhang Date: Fri, 21 Feb 2025 01:29:37 +0000 Subject: [PATCH 2/2] printk: Skip log flush in NMI context when logbuf_lock is held Offering: HULK hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IB963V -------------------------------- In nmi_trigger_cpumask_backtrace(), printk_safe_flush() is called after sending NMI to flush the logs. When logbuf_lock is already held and the current CPU is in printk-safe context (e.g., NMI context), attempting to acquire the lock again can lead to deadlock. Modify the function to return early when detecting logbuf_lock is held and current CPU is in printk-safe context. This prevents deadlock scenarios where CPU0 holds the lock while other CPUs try to acquire it in NMI context. Fixes: 099f1c84c005 ("printk: introduce per-cpu safe_print seq buffer") Signed-off-by: Xiaomeng Zhang --- kernel/printk/printk_safe.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c index b774685ccf80..4ee5e1b4cea0 100644 --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -246,6 +246,10 @@ void printk_safe_flush(void) { int cpu; + if (raw_spin_is_locked(&logbuf_lock) && + (this_cpu_read(printk_context) & PRINTK_SAFE_CONTEXT_MASK)) + return; + for_each_possible_cpu(cpu) { #ifdef CONFIG_PRINTK_NMI __printk_safe_flush(&per_cpu(nmi_print_seq, cpu).work); -- Gitee