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.
Unified · Split
| @@ -35,7 +35,6 @@ · 34 unmodified lines | |||
| 35 | #include <linux/memblock.h> | 35 | #include <linux/memblock.h> |
| 36 | #include <linux/syscalls.h> | 36 | #include <linux/syscalls.h> |
| 37 | #include <linux/crash_core.h> | 37 | #include <linux/crash_core.h> |
| 38 | #include <linux/kdb.h> | ||
| 39 | #include <linux/ratelimit.h> | 38 | #include <linux/ratelimit.h> |
| 40 | #include <linux/kmsg_dump.h> | 39 | #include <linux/kmsg_dump.h> |
| 41 | #include <linux/syslog.h> | 40 | #include <linux/syslog.h> |
| @@ -2047,18 +2046,7 @@ EXPORT_SYMBOL(vprintk); · 2005 unmodified lines | |||
| 2047 | 2046 | ||
| 2048 | int vprintk_default(const char *fmt, va_list args) | 2047 | int vprintk_default(const char *fmt, va_list args) |
| 2049 | { | 2048 | { |
| 2050 | int r; | 2049 | return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); |
| 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; | ||
| 2062 | } | 2050 | } |
| 2063 | EXPORT_SYMBOL_GPL(vprintk_default); | 2051 | EXPORT_SYMBOL_GPL(vprintk_default); |
| 2064 | 2052 | ||
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | #include <linux/preempt.h> | 6 | #include <linux/preempt.h> |
| 7 | #include <linux/spinlock.h> | 7 | #include <linux/spinlock.h> |
| 8 | #include <linux/debug_locks.h> | 8 | #include <linux/debug_locks.h> |
| 9 | #include <linux/kdb.h> | ||
| 9 | #include <linux/smp.h> | 10 | #include <linux/smp.h> |
| 10 | #include <linux/cpumask.h> | 11 | #include <linux/cpumask.h> |
| 11 | #include <linux/irq_work.h> | 12 | #include <linux/irq_work.h> |
| @@ -359,6 +360,12 @@ void __printk_safe_exit(void) · 347 unmodified lines | |||
| 359 | 360 | ||
| 360 | __printf(1, 0) int vprintk_func(const char *fmt, va_list args) | 361 | __printf(1, 0) int vprintk_func(const char *fmt, va_list args) |
| 361 | { | 362 | { |
| 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 | |||
| 362 | /* | 369 | /* |
| 363 | * Try to use the main logbuf even in NMI. But avoid calling console | 370 | * Try to use the main logbuf even in NMI. But avoid calling console |
| 364 | * drivers that might have their own locks. | 371 | * drivers that might have their own locks. |