Commit 6651ea5c authored by Xiaomeng Zhang's avatar Xiaomeng Zhang
Browse files

printk: Skip log flush in NMI context when logbuf_lock is held

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: 099f1c84 ("printk: introduce per-cpu safe_print seq buffer")
Signed-off-by: default avatarXiaomeng Zhang <zhangxiaomeng13@huawei.com>
parent f8234285
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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);