path: root/kernel/printk/printk_safe.c
diff options
authorLinus Torvalds <>2020-06-12 12:13:36 -0700
committerLinus Torvalds <>2020-06-12 12:13:36 -0700
commit5c2fb57af0f42550eb718a3b0b445c81ec923895 (patch)
treebf0493dc247f07554a66302b653f6a7f7bdc0da4 /kernel/printk/printk_safe.c
parent923ea1631e942f8af179ca418e0cc1915025e4c2 (diff)
parent2a9e5ded9543436620a7fbc9329ddcc32bf97bc7 (diff)
Merge tag 'printk-for-5.8-kdb-nmi' of git://
Pull printk fix from Petr Mladek: "One more printk change for 5.8: make sure that messages printed from KDB context are redirected to KDB console handlers. It did not work when KDB interrupted NMI or printk_safe contexts. Arm people started hitting this problem more often recently. I forgot to add the fix into the previous pull request by mistake" * tag 'printk-for-5.8-kdb-nmi' of git:// printk/kdb: Redirect printk messages into kdb in any context
Diffstat (limited to 'kernel/printk/printk_safe.c')
1 files changed, 7 insertions, 0 deletions
diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c
index 4242403316bb..50aeae770434 100644
--- a/kernel/printk/printk_safe.c
+++ b/kernel/printk/printk_safe.c
@@ -6,6 +6,7 @@
#include <linux/preempt.h>
#include <linux/spinlock.h>
#include <linux/debug_locks.h>
+#include <linux/kdb.h>
#include <linux/smp.h>
#include <linux/cpumask.h>
#include <linux/irq_work.h>
@@ -360,6 +361,12 @@ void __printk_safe_exit(void)
__printf(1, 0) int vprintk_func(const char *fmt, va_list args)
+ /* Allow to pass printk() to kdb but avoid a recursion. */
+ if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0))
+ return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
* Try to use the main logbuf even in NMI. But avoid calling console
* drivers that might have their own locks.