History

printk/kdb: Redirect printk messages into kdb in any context

kdb has to get messages on consoles even when the system is stopped. It uses kdb_printf() internally and calls console drivers on its own. It uses a hack to reuse an existing code. It sets "kdb_trap_printk" global variable to redirect even the normal printk() into the kdb_printf() variant. The variable "kdb_trap_printk" is checked in printk_default() and it is ignored when printk is redirected to printk_safe in NMI context. Solve this by moving the check into printk_func(). It is obvious that it is not fully safe. But it does not make things worse. The console drivers are already called in this context by db_printf() direct calls.

Petr Mladek committed 6 years ago

Commit 2a9e5de1 parent ca1f5df2 files · +8 −13Browse files

Showing the changes to kernel (2 of 2 files). Show all

Unified · Split

2 files
  1. kernel/printk/printk.c +1 −13
  2. kernel/printk/printk_safe.c +7 −0
kernel/printk/printk.c+1−13
@@ -35,7 +35,6 @@ · 34 unmodified lines
3535 #include <linux/memblock.h>
3636 #include <linux/syscalls.h>
3737 #include <linux/crash_core.h>
38−#include <linux/kdb.h>
3938 #include <linux/ratelimit.h>
4039 #include <linux/kmsg_dump.h>
4140 #include <linux/syslog.h>
@@ -2047,18 +2046,7 @@ EXPORT_SYMBOL(vprintk); · 2005 unmodified lines
20472046
20482047 int vprintk_default(const char *fmt, va_list args)
20492048 {
2050− int r;
2051−
2052−#ifdef CONFIG_KGDB_KDB
2053− /* Allow to pass printk() to kdb but avoid a recursion. */
2054− if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) {
2055− r = vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
2056− return r;
2057− }
2058−#endif
2059− r = vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args);
2060−
2061− return r;
2049+ return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args);
20622050 }
20632051 EXPORT_SYMBOL_GPL(vprintk_default);
20642052
kernel/printk/printk_safe.c+7−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 #include <linux/preempt.h>
77 #include <linux/spinlock.h>
88 #include <linux/debug_locks.h>
9+#include <linux/kdb.h>
910 #include <linux/smp.h>
1011 #include <linux/cpumask.h>
1112 #include <linux/irq_work.h>
@@ -359,6 +360,12 @@ void __printk_safe_exit(void) · 347 unmodified lines
359360
360361 __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
361362 {
363+#ifdef CONFIG_KGDB_KDB
364+ /* Allow to pass printk() to kdb but avoid a recursion. */
365+ if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0))
366+ return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
367+#endif
368+
362369 /*
363370 * Try to use the main logbuf even in NMI. But avoid calling console
364371 * drivers that might have their own locks.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t