[PATCH] printk: Allow direct printing for PREEMPT_RT during panic

From: takakura
Date: Wed Oct 09 2024 - 23:55:35 EST


From: Ryo Takakura <takakura@xxxxxxxxxxxxx>

If PREEMPT_RT was enabled, printing for legacy consoles are deferred
by default, including after printk_legacy_allow_panic_sync() during
panic which allows direct printing afterwards in case of !PREEMPT_RT.
As a result, printing of messages during panic for PREEMPT_RT
is handled by the console_flush_on_panic() called at the end.

In case if kexec was loaded, console_flush_on_panic() will not be
called and starts booting into the second kernel without printing
the messages.

Allow direct printing for PREEMPT_RT during panic so that messages
before kexec gets printed.

Signed-off-by: Ryo Takakura <takakura@xxxxxxxxxxxxx>
---

I was not sure if the behavior of deferred printing for PREEMPT_RT
during panic was expected or not. I think printing messages would be
useful even if kexec was loaded in case if it fails.

Thanks!

---
kernel/printk/printk_safe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c
index 2b35a9d3919d..67a0510a8e12 100644
--- a/kernel/printk/printk_safe.c
+++ b/kernel/printk/printk_safe.c
@@ -44,7 +44,7 @@ bool is_printk_legacy_deferred(void)
* The per-CPU variable @printk_context can be read safely in any
* context. CPU migration is always disabled when set.
*/
- return (force_legacy_kthread() ||
+ return ((!this_cpu_in_panic() && force_legacy_kthread()) ||
this_cpu_read(printk_context) ||
in_nmi());
}
--
2.34.1