printk/kdb: Redirect printk messages into kdb in any context
authorPetr Mladek <pmladek@suse.com>
Wed, 20 May 2020 10:22:33 +0000 (12:22 +0200)
committerPetr Mladek <pmladek@suse.com>
Thu, 11 Jun 2020 06:48:44 +0000 (08:48 +0200)
commit2a9e5ded9543436620a7fbc9329ddcc32bf97bc7
tree22e7a2221b58aed5c48d2230aa5c0c7fd0a97474
parentca1f5df23f28228c46aa45d934abad38c6b6ff2e
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.

Reported-by: Sumit Garg <sumit.garg@linaro.org>
Tested-by: Sumit Garg <sumit.garg@linaro.org>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20200520102233.GC3464@linux-b0ei
kernel/printk/printk.c
kernel/printk/printk_safe.c