[PATCH printk v1 09/10] kdb: if available, only use atomic consoles for output mirroring

John Ogness
2021-08-03T13:13:36Z

Currently kdb uses the @oops_in_progress hack to mirror kdb output
to all active consoles from NMI context. Ignoring locks is unsafe.

Now that an NMI-safe atomic interface is available for consoles,
use only that interface to mirror kdb output if such a console is
available.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/debug/kdb/kdb_io.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 6735ac36b718..871b89d6294b 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -544,6 +544,7 @@ static int kdb_search_string(char *searched, char *searchfor)

static void kdb_msg_write(const char *msg, int msg_len)
{
+ bool atomic_console_available;
struct console *c;
const char *cp;
int len;
@@ -559,11 +560,26 @@ static void kdb_msg_write(const char *msg, int msg_len)
cp++;
}

+ atomic_console_available = have_atomic_console();
+
for_each_console(c) {
if (!(c->flags & CON_ENABLED))
continue;
if (c == dbg_io_ops->cons)
continue;
+
+ /*
+ * If any atomic consoles are available, only atomic
+ * consoles are used.
+ */
+ if (atomic_console_available) {
+ if (c->write_atomic) {
+ c->write_atomic(c, msg, msg_len);
+ touch_nmi_watchdog();
+ }
+ continue;
+ }
+
/*
* Set oops_in_progress to encourage the console drivers to
* disregard their internal spin locks: in the current calling
--
2.20.1