Currently the panic_print_sys_info() was called twice with different
parameters to handle console replay case, which is kind of confusing.
Add panic_console_replay() explicitly and rename 'PANIC_PRINT_ALL_PRINTK_MSG'
to 'PANIC_CONSOLE_REPLAY', to make the code straightforward. The
related kernel document is also updated.
Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
.../admin-guide/kernel-parameters.txt | 2 +-
Documentation/admin-guide/sysctl/kernel.rst | 2 +-
kernel/panic.c | 18 +++++++++---------
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index f1f2c0874da9..abb2ade021ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4533,7 +4533,7 @@
bit 2: print timer info
bit 3: print locks info if CONFIG_LOCKDEP is on
bit 4: print ftrace buffer
- bit 5: print all printk messages in buffer
+ bit 5: replay all messages on consoles at the end of panic
bit 6: print all CPUs backtrace (if available in the arch)
bit 7: print only tasks in uninterruptible (blocked) state
*Be aware* that this option may print a _lot_ of lines,
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index dd49a89a62d3..0d08b7a2db2d 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -889,7 +889,7 @@ bit 1 print system memory info
bit 2 print timer info
bit 3 print locks info if ``CONFIG_LOCKDEP`` is on
bit 4 print ftrace buffer
-bit 5 print all printk messages in buffer
+bit 5 replay all messages on consoles at the end of panic
bit 6 print all CPUs backtrace (if available in the arch)
bit 7 print only tasks in uninterruptible (blocked) state
===== ============================================
diff --git a/kernel/panic.c b/kernel/panic.c
index b0b9a8bf4560..9b6c5dc28a65 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(panic_timeout);
#define PANIC_PRINT_TIMER_INFO 0x00000004
#define PANIC_PRINT_LOCK_INFO 0x00000008
#define PANIC_PRINT_FTRACE_INFO 0x00000010
-#define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020
+#define PANIC_CONSOLE_REPLAY 0x00000020
#define PANIC_PRINT_ALL_CPU_BT 0x00000040
#define PANIC_PRINT_BLOCKED_TASKS 0x00000080
unsigned long panic_print;
@@ -238,14 +238,14 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
}
EXPORT_SYMBOL(nmi_panic);
-static void panic_print_sys_info(bool console_flush)
+static void panic_console_replay(void)
{
- if (console_flush) {
- if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
- console_flush_on_panic(CONSOLE_REPLAY_ALL);
- return;
- }
+ if (panic_print & PANIC_CONSOLE_REPLAY)
+ console_flush_on_panic(CONSOLE_REPLAY_ALL);
+}
+static void panic_print_sys_info(void)
+{
if (panic_print & PANIC_PRINT_TASK_INFO)
show_state();
@@ -410,7 +410,7 @@ void panic(const char *fmt, ...)
*/
atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
- panic_print_sys_info(false);
+ panic_print_sys_info();
kmsg_dump_desc(KMSG_DUMP_PANIC, buf);
@@ -439,7 +439,7 @@ void panic(const char *fmt, ...)
debug_locks_off();
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
- panic_print_sys_info(true);
+ panic_console_replay();
if (!panic_blink)
panic_blink = no_blink;
--
2.43.5
I just tested bit 5. It doesn't replay all console messages (i. e. everything printed to /dev/console ). Instead it merely replays kernel messages (i. e. printk/kmsg). So, please, rename PANIC_CONSOLE_REPLAY back to PANIC_PRINT_ALL_PRINTK_MSG or possibly to PANIC_KMSG_REPLAY. And update admin-guide/sysctl/kernel.rst -- Askar Safin
Hi Askar Safin, On Tue, Jul 15, 2025 at 12:09:40AM +0300, Askar Safin wrote: > I just tested bit 5. It doesn't replay all console messages (i. e. everything printed to /dev/console ). > Instead it merely replays kernel messages (i. e. printk/kmsg). > So, please, rename PANIC_CONSOLE_REPLAY back to PANIC_PRINT_ALL_PRINTK_MSG or possibly to PANIC_KMSG_REPLAY. > And update admin-guide/sysctl/kernel.rst Thanks for trying the patch! Petr could have better understanding on this, as he have been working on this for many years and maintained printk. I brought out the name for kernel space debugging, to replay all the printk message on the tty console I have. My understanding is, 'console' have kind of different meaning in kernel space than just /dev/console. In printk.c, you can see 'console' is used everywhere, which are mostly bound to kernel message.like console_try_replay_all(), console_flush_all(), console_flush_on_panic(), which are consistent with the new name suggested by Petr. Thanks, Feng > > -- > Askar Safin
---- On Tue, 15 Jul 2025 04:49:12 +0400 Feng Tang <feng.tang@linux.alibaba.com> wrote --- > Thanks for trying the patch! I didn't try it. :) I merely run normal mainline or distro kernel in qemu. > My understanding is, 'console' have kind of different meaning in kernel > space than just /dev/console. In printk.c, you can see 'console' is > used everywhere, which are mostly bound to kernel message.like > console_try_replay_all(), console_flush_all(), console_flush_on_panic(), > which are consistent with the new name suggested by Petr. Okay, I agree. But I still kindly ask you to revert changes to Documentation/admin-guide/kernel-parameters.txt . Previous documentation is better. admin-guide is written for admins, not for kernel developers. And they understand "console" as /dev/console . I run kernel with panic_print=32 in hope that this will flush console (i. e. /dev/console), because this is how I interpreted your patched documentation. And I got different effect. -- Askar Safin https://types.pl/@safinaskar
On Tue, Jul 15, 2025 at 05:18:10AM +0400, Askar Safin wrote: > ---- On Tue, 15 Jul 2025 04:49:12 +0400 Feng Tang <feng.tang@linux.alibaba.com> wrote --- > > Thanks for trying the patch! > I didn't try it. :) I merely run normal mainline or distro kernel in qemu. > > > My understanding is, 'console' have kind of different meaning in kernel > > space than just /dev/console. In printk.c, you can see 'console' is > > used everywhere, which are mostly bound to kernel message.like > > console_try_replay_all(), console_flush_all(), console_flush_on_panic(), > > which are consistent with the new name suggested by Petr. > Okay, I agree. > > But I still kindly ask you to revert changes to Documentation/admin-guide/kernel-parameters.txt . > Previous documentation is better. > admin-guide is written for admins, not for kernel developers. And they understand "console" as /dev/console . > > I run kernel with panic_print=32 in hope that this will flush console (i. e. /dev/console), because this is how I interpreted > your patched documentation. And I got different effect. I see. How about changing the patch to: - bit 5: print all printk messages in buffer + bit 5: replay all kernel messages on consoles at the end of panic Thanks, Feng > > -- > Askar Safin > https://types.pl/@safinaskar
---- On Tue, 15 Jul 2025 05:34:39 +0400 Feng Tang <feng.tang@linux.alibaba.com> wrote --- > I see. How about changing the patch to: > > - bit 5: print all printk messages in buffer > + bit 5: replay all kernel messages on consoles at the end of panic Yes, I agree! -- Askar Safin https://types.pl/@safinaskar
On Tue, Jul 15, 2025 at 06:48:47AM +0400, Askar Safin wrote: > > ---- On Tue, 15 Jul 2025 05:34:39 +0400 Feng Tang <feng.tang@linux.alibaba.com> wrote --- > > I see. How about changing the patch to: > > > > - bit 5: print all printk messages in buffer > > + bit 5: replay all kernel messages on consoles at the end of panic > > Yes, I agree! Hi Andrew, Could you help to squash below patch to 1/5 patch "panic: clean up code for console replay" in the nonmmu-unstable branch? Thanks! - Feng --- Documentation/admin-guide/kernel-parameters.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index f34de9978a91..a84d3f7f5bbf 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4533,7 +4533,7 @@ bit 2: print timer info bit 3: print locks info if CONFIG_LOCKDEP is on bit 4: print ftrace buffer - bit 5: replay all messages on consoles at the end of panic + bit 5: replay all kernel messages on consoles at the end of panic bit 6: print all CPUs backtrace (if available in the arch) bit 7: print only tasks in uninterruptible (blocked) state *Be aware* that this option may print a _lot_ of lines,
On Tue 2025-07-15 11:27:54, Feng Tang wrote: > On Tue, Jul 15, 2025 at 06:48:47AM +0400, Askar Safin wrote: > > > > ---- On Tue, 15 Jul 2025 05:34:39 +0400 Feng Tang <feng.tang@linux.alibaba.com> wrote --- > > > I see. How about changing the patch to: > > > > > > - bit 5: print all printk messages in buffer > > > + bit 5: replay all kernel messages on consoles at the end of panic > > > > Yes, I agree! > > Hi Andrew, > > Could you help to squash below patch to 1/5 patch "panic: clean up code > for console replay" in the nonmmu-unstable branch? Thanks! > > - Feng > > --- > Documentation/admin-guide/kernel-parameters.txt | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index f34de9978a91..a84d3f7f5bbf 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -4533,7 +4533,7 @@ > bit 2: print timer info > bit 3: print locks info if CONFIG_LOCKDEP is on > bit 4: print ftrace buffer > - bit 5: replay all messages on consoles at the end of panic > + bit 5: replay all kernel messages on consoles at the end of panic > bit 6: print all CPUs backtrace (if available in the arch) > bit 7: print only tasks in uninterruptible (blocked) state > *Be aware* that this option may print a _lot_ of lines, Yes, this looks better. It sees that this change is missing in the mainline. Fang, could you please send it as a followup fix, please? Best Regards, Petr
On Tue, Aug 12, 2025 at 01:59:32PM +0200, Petr Mladek wrote: > On Tue 2025-07-15 11:27:54, Feng Tang wrote: > > On Tue, Jul 15, 2025 at 06:48:47AM +0400, Askar Safin wrote: > > > > > > ---- On Tue, 15 Jul 2025 05:34:39 +0400 Feng Tang <feng.tang@linux.alibaba.com> wrote --- > > > > I see. How about changing the patch to: > > > > > > > > - bit 5: print all printk messages in buffer > > > > + bit 5: replay all kernel messages on consoles at the end of panic > > > > > > Yes, I agree! > > > > Hi Andrew, > > > > Could you help to squash below patch to 1/5 patch "panic: clean up code > > for console replay" in the nonmmu-unstable branch? Thanks! > > > > - Feng > > > > --- > > Documentation/admin-guide/kernel-parameters.txt | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > > index f34de9978a91..a84d3f7f5bbf 100644 > > --- a/Documentation/admin-guide/kernel-parameters.txt > > +++ b/Documentation/admin-guide/kernel-parameters.txt > > @@ -4533,7 +4533,7 @@ > > bit 2: print timer info > > bit 3: print locks info if CONFIG_LOCKDEP is on > > bit 4: print ftrace buffer > > - bit 5: replay all messages on consoles at the end of panic > > + bit 5: replay all kernel messages on consoles at the end of panic > > bit 6: print all CPUs backtrace (if available in the arch) > > bit 7: print only tasks in uninterruptible (blocked) state > > *Be aware* that this option may print a _lot_ of lines, > > Yes, this looks better. > > It sees that this change is missing in the mainline. > Fang, could you please send it as a followup fix, please? Sure. Will do. Thanks, Feng
© 2016 - 2025 Red Hat, Inc.