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
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
2048int vprintk_default(const char *fmt, va_list args)2047int 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}
2063EXPORT_SYMBOL_GPL(vprintk_default);2051EXPORT_SYMBOL_GPL(vprintk_default);
2064 2052
kernel/printk/printk_safe.c+7−0
@@ -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 console370 * 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.

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