Thread (4 messages) 4 messages, 3 authors, 2025-08-25

Re: [PATCH] printk: Fix panic log flush to serial console during kdump in PREEMPT_RT kernels

From: Ryo Takakura <hidden>
Date: 2025-08-19 13:31:56
Also in: linux-rt-devel, lkml

Hi cuiguoqi!

I'm not an expert on the subject, but hope this helps.

On Thu,  7 Aug 2025 19:22:47 +0800, cuiguoqi wrote:
When a system running a real-time (PREEMPT_RT) kernel panics and triggers kdump,
the critical log messages (e.g., panic reason, stack traces) may fail to appear
on the serial console.

When kdump cannot be used properly, serial console logs are crucial,
whether for diagnosing kdump issues or troubleshooting the underlying problem.
The console not being flushed in the case of kexec should be expected
as described [0]. Its about prioritizing kexec over serial output.
quoted hunk ↗ jump to hunk
This issue arises due to synchronization or deferred flushing of the printk buffer
in real-time contexts, where preemptible console locks or delayed workqueues prevent
timely log output before kexec transitions to the crash kernel.

/**
 * kexec_image_info - For debugging output.
@@ -176,6 +177,9 @@ void machine_kexec(struct kimage *kimage)
	pr_info("Bye!\n");

+	if (IS_ENABLED(CONFIG_PREEMPT_RT) && in_kexec_crash)
+		console_flush_on_panic(CONSOLE_FLUSH_PENDING);
+
Calling console_flush_on_panic() while trying to kexec will
reduce its chance of success.
quoted hunk ↗ jump to hunk
diff --git a/kernel/panic.c b/kernel/panic.c
index 72fcbb5..e0ad0df 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -437,6 +437,8 @@ void vpanic(const char *fmt, va_list args)
	 */
	kgdb_panic(buf);

+	printk_legacy_allow_panic_sync();
+
	/*
	 * If we have crashed and we have a crash kernel loaded let it handle
	 * everything else.
@@ -450,8 +452,6 @@ void vpanic(const char *fmt, va_list args)
	panic_other_cpus_shutdown(_crash_kexec_post_notifiers);

-	printk_legacy_allow_panic_sync();
-
The ordering here should be kept where we don't want CPUs other than
the one panicked flushing legacy consoles.

Sincerely,
Ryo Takakura

[0] https://lore.kernel.org/lkml/847cagmjsx.fsf@jogness.linutronix.de/ (local)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help