From: Cheng Jian cj.chengjian@huawei.com
hulk inclusion category: bugfix bugzilla: 34546, https://gitee.com/openeuler/kernel/issues/I4JKT1 CVE: NA
----------------------------------------
Any architecture that involves an NMI should be treated with caution. For example, the X86 architecture and ARM64 enabled PSEUDO NMI.
Signed-off-by: Cheng Jian cj.chengjian@huawei.com Reviewed-by: Xie XiuQi xiexiuqi@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- include/linux/printk.h | 4 ++++ kernel/panic.c | 2 +- kernel/printk/printk.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h index de1457e3af3f..e6a8ee6db68e 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -209,8 +209,12 @@ void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack(void) __cold; extern void printk_safe_flush(void); extern void printk_safe_flush_on_panic(void); +#if defined(CONFIG_X86) || defined(CONFIG_ARM64_PSEUDO_NMI) extern void zap_locks(void); #else +static inline void zap_locks(void) { } +#endif +#else static inline __printf(1, 0) int vprintk(const char *s, va_list args) { diff --git a/kernel/panic.c b/kernel/panic.c index 3d75855db4e6..d991c3b1b559 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -265,6 +265,7 @@ void panic(const char *fmt, ...) crash_smp_send_stop(); }
+#if defined(CONFIG_X86) || defined(CONFIG_ARM64_PSEUDO_NMI) /* * ZAP console related locks when nmi broadcast. If a crash is occurring, * make sure we can't deadlock. And make sure that we print immediately. @@ -288,7 +289,6 @@ void panic(const char *fmt, ...) * have a chance to see the messages. Others prefer to always * reach emergency_restart() and reboot the machine. */ -#ifdef CONFIG_X86 zap_locks(); #endif
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 69a1be81dd98..729e4ce2decb 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1742,6 +1742,7 @@ static DEFINE_RAW_SPINLOCK(console_owner_lock); static struct task_struct *console_owner; static bool console_waiter;
+#if defined(CONFIG_X86) || defined(CONFIG_ARM64_PSEUDO_NMI) void zap_locks(void) { if (raw_spin_is_locked(&logbuf_lock)) { @@ -1758,6 +1759,7 @@ void zap_locks(void)
sema_init(&console_sem, 1); } +#endif
/** * console_lock_spinning_enable - mark beginning of code where another