Skip to contentSkip to conversation

kgdb: Flush console before entering kgdb on panic

PATCH New Sasha Levin 1 participant 1 message Nov 12, 2023 Stable branch

lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

PATCH 1/1 kgdb: Flush console before entering kgdb on panic

From: Douglas Anderson <[email protected]>

[ Upstream commit dd712d3d45807db9fcae28a522deee85c1f2fde6 ]

When entering kdb/kgdb on a kernel panic, it was be observed that the console isn't flushed before the kdb prompt came up. Specifically, when using the buddy lockup detector on arm64 and running:
echo HARDLOCKUP > /sys/kernel/debug/provoke-crash/DIRECT

I could see:

  [   26.161099] lkdtm: Performing direct entry HARDLOCKUP
  [   32.499881] watchdog: Watchdog detected hard LOCKUP on cpu 6
  [   32.552865] Sending NMI from CPU 5 to CPUs 6:
  [   32.557359] NMI backtrace for cpu 6
  ... [backtrace for cpu 6] ...
  [   32.558353] NMI backtrace for cpu 5
  ... [backtrace for cpu 5] ...
  [   32.867471] Sending NMI from CPU 5 to CPUs 0-4,7:
  [   32.872321] NMI backtrace forP cpuANC: Hard LOCKUP

Entering kdb (current=..., pid 0) on processor 5 due to Keyboard Entry [5]kdb>

As you can see, backtraces for the other CPUs start printing and get interleaved with the kdb PANIC print.

Let's replicate the commands to flush the console in the kdb panic entry point to avoid this.

---
 kernel/debug/debug_core.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/debug/debug_core.c +3 -0
index f88611fadb195..1ab2e97034868 100644
@@ -945,6 +945,9 @@ void kgdb_panic(const char *msg)
 	if (panic_timeout)
 		return;
 
+	debug_locks_off();
+	console_flush_on_panic(CONSOLE_FLUSH_PENDING);
+
 	if (dbg_kdb_mode)
 		kdb_printf("PANIC: %s\n", msg);
 
Signature · 1 line
2.42.0