]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.8/panic-flush-kernel-log-buffer-at-the-end.patch
Linux 6.6.27
[thirdparty/kernel/stable-queue.git] / queue-6.8 / panic-flush-kernel-log-buffer-at-the-end.patch
1 From 99e72425ba799e59856786bc8b6c64600c0753c1 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 7 Feb 2024 14:47:02 +0106
4 Subject: panic: Flush kernel log buffer at the end
5
6 From: John Ogness <john.ogness@linutronix.de>
7
8 [ Upstream commit d988d9a9b9d180bfd5c1d353b3b176cb90d6861b ]
9
10 If the kernel crashes in a context where printk() calls always
11 defer printing (such as in NMI or inside a printk_safe section)
12 then the final panic messages will be deferred to irq_work. But
13 if irq_work is not available, the messages will not get printed
14 unless explicitly flushed. The result is that the final
15 "end Kernel panic" banner does not get printed.
16
17 Add one final flush after the last printk() call to make sure
18 the final panic messages make it out as well.
19
20 Signed-off-by: John Ogness <john.ogness@linutronix.de>
21 Reviewed-by: Petr Mladek <pmladek@suse.com>
22 Link: https://lore.kernel.org/r/20240207134103.1357162-14-john.ogness@linutronix.de
23 Signed-off-by: Petr Mladek <pmladek@suse.com>
24 Signed-off-by: Sasha Levin <sashal@kernel.org>
25 ---
26 kernel/panic.c | 8 ++++++++
27 1 file changed, 8 insertions(+)
28
29 diff --git a/kernel/panic.c b/kernel/panic.c
30 index 2807639aab51d..f22d8f33ea147 100644
31 --- a/kernel/panic.c
32 +++ b/kernel/panic.c
33 @@ -446,6 +446,14 @@ void panic(const char *fmt, ...)
34
35 /* Do not scroll important messages printed above */
36 suppress_printk = 1;
37 +
38 + /*
39 + * The final messages may not have been printed if in a context that
40 + * defers printing (such as NMI) and irq_work is not available.
41 + * Explicitly flush the kernel log buffer one last time.
42 + */
43 + console_flush_on_panic(CONSOLE_FLUSH_PENDING);
44 +
45 local_irq_enable();
46 for (i = 0; ; i += PANIC_TIMER_STEP) {
47 touch_softlockup_watchdog();
48 --
49 2.43.0
50