generalize panic_print's dump function to be used by other kernel parts
Subsystems (3)
cover generalize panic_print's dump function to be used by other kernel parts
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has panic_print_sys_info() for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Please help to review, thanks!
- Feng
Changelog:
Since RFC:
* Don't print all cpu backtrace if 'sysctl_hung_task_all_cpu_backtracemay' is 'false' (Lance Yang)
* Change the name of 2 new kernel control knob to have 'mask' inside, and add kernel document and code comments for them (Lance Yang)
* Make the sys_show_info() support printk msg replay and all CPU backtrace.
Feng Tang (3):
kernel/panic: generalize panic_print's function to show sys info kernel/hung_task: add option to dump system info when hung task
detected
kernel/watchdog: add option to dump system info when system is locked
up
.../admin-guide/kernel-parameters.txt | 10 ++++ include/linux/panic.h | 11 +++++ kernel/hung_task.c | 42 ++++++++++++----- kernel/panic.c | 47 ++++++++++--------- kernel/watchdog.c | 20 ++++++++ 5 files changed, 95 insertions(+), 35 deletions(-)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH 1/3 kernel/panic: generalize panic_print's function to show sys info
panic_print was introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.
Extract sys_show_info() function out to be used by other kernel parts for debugging.
--- include/linux/panic.h | 11 ++++++++++ kernel/panic.c | 47 +++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 22 deletions(-)
include/linux/panic.h +11 -0
@@ -16,6 +16,17 @@ extern void oops_enter(void);extern void oops_exit (void );extern bool oops_may_print (void ); +#define SYS_PRINT_TASK_INFO 0x00000001 +#define SYS_PRINT_MEM_INFO 0x00000002 +#define SYS_PRINT_TIMER_INFO 0x00000004 +#define SYS_PRINT_LOCK_INFO 0x00000008 +#define SYS_PRINT_FTRACE_INFO 0x00000010 +#define SYS_PRINT_ALL_PRINTK_MSG 0x00000020 +#define SYS_PRINT_ALL_CPU_BT 0x00000040 +#define SYS_PRINT_BLOCKED_TASKS 0x00000080 + +extern void sys_show_info (unsigned long info_mask); +extern bool panic_triggering_all_cpu_backtrace;extern int panic_timeout;extern unsigned long panic_print;
kernel/panic.c +25 -22
79 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)
Petr Mladek
reviewerRe: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
Quoted 12 lines · Feng Tang
panic_printwas introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.Extract
sys_show_info()function out to be used by other kernel parts for debugging.
include/linux/panic.h extern void oops_enter(void); · line 24
Quoted 9 lines
include/linux/panic.h +6
-0@@ -16,6 +16,17 @@ extern void oops_enter(void);extern void oops_exit (void );extern bool oops_may_print (void ); +#define SYS_PRINT_TASK_INFO 0x00000001 +#define SYS_PRINT_MEM_INFO 0x00000002 +#define SYS_PRINT_TIMER_INFO 0x00000004 +#define SYS_PRINT_LOCK_INFO 0x00000008 +#define SYS_PRINT_FTRACE_INFO 0x00000010 +#define SYS_PRINT_ALL_PRINTK_MSG 0x00000020
Please, remove this option from the generic interface. It is controversial. In the current form, it makes sense to replay the log only in panic() after all the other actions:
console_verbose(); bust_spinlocks(1); panic_other_cpus_shutdown(_crash_kexec_post_notifiers); printk_legacy_allow_panic_sync(); console_unblank(); debug_locks_off(); console_flush_on_panic(CONSOLE_FLUSH_PENDING);
All these operations have some (side-)effect which increases the chance to actually see the messages on the console.
I think that it was primary meant for graphics consoles. But there it would need to be used together with printk_delay (/proc/sys/kernel/printk_delay, sysctl printk_delay).
Note that it creates a hairy code. It is the only reason why we need to call panic_print_sys_info() twice with "false" and "true" parameter.
That said, I could imagine a generic use, for example, after forcing ignore_loglevel or so. Otherwise, I do not see any advantage in flushing the same messages again, for example, on serial or network consoles where they are likely already stored. We could add this later when there is a real-life demand.
include/linux/panic.h extern void oops_enter(void); · line 26
Quoted 2 lines
include/linux/panic.h +2
-0+#define SYS_PRINT_ALL_CPU_BT 0x00000040 +#define SYS_PRINT_BLOCKED_TASKS 0x00000080
The generic approach might deserve a separate source file, for example:
include/linux/sys_info.h
lib/sys_info.c
Also I always considered the bitmask as a horrible user interface. It might be used internally. But it would be better to allow a human readable parameter, for example:
panic_sys_info=task,mem,timer,lock,ftrace,bt,all_bt,blocked_tasks
The console reply might be handled by a separate:
panic_console_reply=1
And it would obsolete the existing "panic_print" which is an ugly name and interface from my POV.
Quoted 33 lines
include/linux/panic.h +2
-0+extern void sys_show_info (unsigned long info_mask); +extern bool panic_triggering_all_cpu_backtrace;extern int panic_timeout;extern unsigned long panic_print;kernel/panic.c +4
-11@@ -208,33 +200,44 @@ void nmi_panic(struct pt_regs *regs, const char *msg) }EXPORT_SYMBOL (nmi_panic); -static void panic_print_sys_info (bool console_flush) +void sys_show_info (unsigned long info_mask) { -if (console_flush) { -if (panic_print &PANIC_PRINT_ALL_PRINTK_MSG ) -console_flush_on_panic (CONSOLE_REPLAY_ALL ); -return ; - } - -if (panic_print &PANIC_PRINT_TASK_INFO ) +if (info_mask &SYS_PRINT_TASK_INFO )show_state (); -if (panic_print &PANIC_PRINT_MEM_INFO ) +if (info_mask &SYS_PRINT_MEM_INFO )show_mem (); -if (panic_print &PANIC_PRINT_TIMER_INFO ) +if (info_mask &SYS_PRINT_TIMER_INFO )sysrq_timer_list_show (); -if (panic_print &PANIC_PRINT_LOCK_INFO )
kernel/panic.c void nmi_panic(struct pt_regs *regs, const char *msg) · line 221
Quoted 10 lines
kernel/panic.c +4
-2+if (info_mask &SYS_PRINT_LOCK_INFO )debug_show_all_locks (); -if (panic_print &PANIC_PRINT_FTRACE_INFO ) +if (info_mask &SYS_PRINT_FTRACE_INFO )ftrace_dump (DUMP_ALL ); -if (panic_print &PANIC_PRINT_BLOCKED_TASKS ) +if (panic_print &SYS_PRINT_ALL_PRINTK_MSG ) +console_flush_on_panic (CONSOLE_REPLAY_ALL );
I do not see any advantage in replaying the log at this stage. It might make sense to replay the messages printed before the critical situation. But it makes sense only when they might be filtered/blocked before and can be seen now (unblanked consoles, forced ignore_loglevel, or so).
I would keep this in the bitmap for backward compactibility. But I would ignore it my the generic print_sys_info().
And I would replace panic_print_sys_info(true) call with:
static void panic_console_replay(void)
{
if (panic_print & SYS_PRINT_ALL_PRINTK_MSG)
console_flush_on_panic(CONSOLE_REPLAY_ALL);
}kernel/panic.c void nmi_panic(struct pt_regs *regs, const char *msg) · line 228
Quoted 6 lines
kernel/panic.c +4
-0+if (info_mask &SYS_PRINT_ALL_CPU_BT ) +trigger_all_cpu_backtrace (); + +if (info_mask &SYS_PRINT_BLOCKED_TASKS )show_state_filter (TASK_UNINTERRUPTIBLE ); }
Best Regards,
Petr
Re: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
Hi Petr,
Thanks for the review!
Quoted 27 lines · Petr Mladek
Quoted 12 lines · Feng Tang
panic_printwas introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.Extract
sys_show_info()function out to be used by other kernel parts for debugging.include/linux/panic.h extern void oops_enter(void); · line 24
Quoted 9 lines
include/linux/panic.h +6
-0@@ -16,6 +16,17 @@ extern void oops_enter(void);extern void oops_exit (void );extern bool oops_may_print (void ); +#define SYS_PRINT_TASK_INFO 0x00000001 +#define SYS_PRINT_MEM_INFO 0x00000002 +#define SYS_PRINT_TIMER_INFO 0x00000004 +#define SYS_PRINT_LOCK_INFO 0x00000008 +#define SYS_PRINT_FTRACE_INFO 0x00000010 +#define SYS_PRINT_ALL_PRINTK_MSG 0x00000020Please, remove this option from the generic interface. It is controversial. In the current form, it makes sense to replay the log only in
panic()after all the other actions:
Quoted 7 lines
console_verbose(); bust_spinlocks(1); panic_other_cpus_shutdown(_crash_kexec_post_notifiers); printk_legacy_allow_panic_sync(); console_unblank(); debug_locks_off(); console_flush_on_panic(CONSOLE_FLUSH_PENDING);
OK, will do.
In my RFC version, I did reserved it for panic use only :) and added the support to general case in v1 after some hesitation.
https://lore.kernel.org/lkml/[email protected]/
Quoted 11 lines
All these operations have some (side-)effect which increases the chance to actually see the messages on the console.
I think that it was primary meant for graphics consoles. But there it would need to be used together with
printk_delay(/proc/sys/kernel/printk_delay, sysctlprintk_delay).Note that it creates a hairy code. It is the only reason why we need to call
panic_print_sys_info()twice with "false" and "true" parameter.
Yes.
Quoted 6 lines
That said, I could imagine a generic use, for example, after forcing
ignore_loglevelor so. Otherwise, I do not see any advantage in flushing the same messages again, for example, on serial or network consoles where they are likely already stored. We could add this later when there is a real-life demand.
You are right, one main usage is for some product which has only graphics console and no serial one. And we also used for serial console sometimes, when the console have a lot of user space message mixed with kernel ones, and we'd like to see the full clean kernel messages.
Quoted 9 lines
include/linux/panic.h extern void oops_enter(void); · line 26
Quoted 3 lines
include/linux/panic.h +2
-0+#define SYS_PRINT_ALL_CPU_BT 0x00000040 +#define SYS_PRINT_BLOCKED_TASKS 0x00000080The generic approach might deserve a separate source file, for example:
include/linux/sys_info.h
lib/sys_info.c
Thanks for the suggestion! I'm really not good at naming.
As panic.c is always built-in, I'll put sys_info.c as obj-y.
Quoted 5 lines
Also I always considered the bitmask as a horrible user interface. It might be used internally. But it would be better to allow a human readable parameter, for example:
panic_sys_info=task,mem,timer,lock,ftrace,bt,all_bt,blocked_tasks
Yes, it's convenient for developers, as a cmdline parameter being parsed at boot time.
But I think bitmask may be easier for runtime changing as a core parameter under /proc/ or /sys/, or from sysctl interface. There are also some other modules use debug bitmask controlling printking info for different sub-components.
And we have similar control knobs for hung, lockup etc.
Or should I change the name from 'xxx_print_mask' to 'xxx_sysinfo_flag' in patch 2/3 ?
Quoted 7 lines
The console reply might be handled by a separate:
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.
Agree it's ugly :). But besides a kernel parameter, 'panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.
Quoted 50 lines
Quoted 33 lines
include/linux/panic.h +2
-0+extern void sys_show_info (unsigned long info_mask); +extern bool panic_triggering_all_cpu_backtrace;extern int panic_timeout;extern unsigned long panic_print;kernel/panic.c +4
-11@@ -208,33 +200,44 @@ void nmi_panic(struct pt_regs *regs, const char *msg) }EXPORT_SYMBOL (nmi_panic); -static void panic_print_sys_info (bool console_flush) +void sys_show_info (unsigned long info_mask) { -if (console_flush) { -if (panic_print &PANIC_PRINT_ALL_PRINTK_MSG ) -console_flush_on_panic (CONSOLE_REPLAY_ALL ); -return ; - } - -if (panic_print &PANIC_PRINT_TASK_INFO ) +if (info_mask &SYS_PRINT_TASK_INFO )show_state (); -if (panic_print &PANIC_PRINT_MEM_INFO ) +if (info_mask &SYS_PRINT_MEM_INFO )show_mem (); -if (panic_print &PANIC_PRINT_TIMER_INFO ) +if (info_mask &SYS_PRINT_TIMER_INFO )sysrq_timer_list_show (); -if (panic_print &PANIC_PRINT_LOCK_INFO )kernel/panic.c void nmi_panic(struct pt_regs *regs, const char *msg) · line 221
Quoted 10 lines
kernel/panic.c +4
-2+if (info_mask &SYS_PRINT_LOCK_INFO )debug_show_all_locks (); -if (panic_print &PANIC_PRINT_FTRACE_INFO ) +if (info_mask &SYS_PRINT_FTRACE_INFO )ftrace_dump (DUMP_ALL ); -if (panic_print &PANIC_PRINT_BLOCKED_TASKS ) +if (panic_print &SYS_PRINT_ALL_PRINTK_MSG ) +console_flush_on_panic (CONSOLE_REPLAY_ALL );I do not see any advantage in replaying the log at this stage. It might make sense to replay the messages printed before the critical situation. But it makes sense only when they might be filtered/blocked before and can be seen now (unblanked consoles, forced
ignore_loglevel, or so).
Quoted 2 lines
I would keep this in the bitmap for backward compactibility. But I would ignore it my the generic
print_sys_info().
OK.
Quoted 7 lines
And I would replace
panic_print_sys_info(true)call with:static void
panic_console_replay(void){ if (panic_print & SYS_PRINT_ALL_PRINTK_MSG) console_flush_on_panic(CONSOLE_REPLAY_ALL); }
Nice cleanup! Will do. I'll fold this change with this patch.
Thanks,
Feng
Quoted 10 lines
kernel/panic.c void nmi_panic(struct pt_regs *regs, const char *msg) · line 228
Quoted 7 lines
kernel/panic.c +4
-0+if (info_mask &SYS_PRINT_ALL_CPU_BT ) +trigger_all_cpu_backtrace (); + +if (info_mask &SYS_PRINT_BLOCKED_TASKS )show_state_filter (TASK_UNINTERRUPTIBLE ); }Best Regards,
Petr
Petr Mladek
reviewerRe: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
Quoted 15 lines · Feng Tang
Hi Petr,
Thanks for the review!
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Feng Tang
panic_printwas introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.The generic approach might deserve a separate source file, for example:
Quoted 6 lines
Quoted 2 lines
include/linux/sys_info.h
lib/sys_info.cThanks for the suggestion! I'm really not good at naming.
As
panic.cis always built-in, I'll putsys_info.cas obj-y.
Makes sense.
Quoted 6 lines
Quoted 5 lines
Also I always considered the bitmask as a horrible user interface. It might be used internally. But it would be better to allow a human readable parameter, for example:
panic_sys_info=task,mem,timer,lock,ftrace,bt,all_bt,blocked_tasks
Quoted 7 lines
Yes, it's convenient for developers, as a cmdline parameter being parsed at boot time.
But I think bitmask may be easier for runtime changing as a core parameter under
/proc/or/sys/, or from sysctl interface. There are also some other modules use debug bitmask controlling printking info for different sub-components.
Good to know. Could you please give me a pointer to some other modules using the bitmask? I believe that they exist but I can't find any. I wonder how common it is...
Anyway, I personally find words/names easier to use. For example, I like the following interfaces:
#> cat /sys/power/pm_test
[none] core processors platform devices freezer
#> cat /sys/kernel/debug/tracing/available_tracers blk function_graph wakeup_dl wakeup_rt wakeup function nop
#> cat /proc/sys/kernel/seccomp/actions_avail kill_process kill_thread trap errno user_notif trace log allow
# cat /proc/sys/kernel/seccomp/actions_logged kill_process kill_thread trap errno user_notif trace log
Quoted 8 lines
And we have similar control knobs for hung, lockup etc.
Or should I change the name from '
xxx_print_mask' to 'xxx_sysinfo_flag' in patch 2/3 ?Quoted 3 lines
The console reply might be handled by a separate:
Quoted 7 lines
Quoted 4 lines
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.Agree it's ugly :). But besides a kernel parameter, '
panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.
A solution would be to keep it and create "panic_sys_info=" with the human readable parameters in parallel. They would store the request in the same bitmap.
We could print a message that "panic_print" has been obsoleted by "panic_sys_info" when people use it.
Both parameters would override the current bitmap. So the later used parameter or procfs/sysfs write would win.
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
The sysfs, aka include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the /sys/... jungle ;-)
I would slightly prefer "sysctl" because these parameters are easier to find.
Best Regards,
Petr
Lance Yang
maintainerRe: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
Quoted 49 lines · Petr Mladek
Quoted 15 lines · Feng Tang
Hi Petr,
Thanks for the review!
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Feng Tang
panic_printwas introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.The generic approach might deserve a separate source file, for example:
Quoted 6 lines
Quoted 2 lines
include/linux/sys_info.h
lib/sys_info.cThanks for the suggestion! I'm really not good at naming.
As
panic.cis always built-in, I'll putsys_info.cas obj-y.Makes sense.
Quoted 6 lines
Quoted 5 lines
Also I always considered the bitmask as a horrible user interface. It might be used internally. But it would be better to allow a human readable parameter, for example:
panic_sys_info=task,mem,timer,lock,ftrace,bt,all_bt,blocked_tasks
Quoted 7 lines
Yes, it's convenient for developers, as a cmdline parameter being parsed at boot time.
But I think bitmask may be easier for runtime changing as a core parameter under
/proc/or/sys/, or from sysctl interface. There are also some other modules use debug bitmask controlling printking info for different sub-components.Good to know. Could you please give me a pointer to some other modules using the bitmask? I believe that they exist but I can't find any. I wonder how common it is...
Anyway, I personally find words/names easier to use. For example, I like the following interfaces:
#> cat
/sys/power/pm_test
[none] core processors platform devices freezer
Quoted 7 lines
#> cat
/sys/kernel/debug/tracing/available_tracersblkfunction_graphwakeup_dlwakeup_rtwakeup function nop#> cat
/proc/sys/kernel/seccomp/actions_availkill_processkill_threadtrap errnouser_notiftrace log allow# cat /proc/sys/kernel/seccomp/actions_logged kill_process kill_thread trap errno user_notif trace log
Clean and straightforward! I prefer this too ;p
Quoted 14 lines
Quoted 14 lines
And we have similar control knobs for hung, lockup etc.
Or should I change the name from '
xxx_print_mask' to 'xxx_sysinfo_flag' in patch 2/3 ?Quoted 7 lines
The console reply might be handled by a separate:
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.
Quoted 6 lines
Quoted 2 lines
Agree it's ugly :). But besides a kernel parameter, '
panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.A solution would be to keep it and create "panic_sys_info=" with the human readable parameters in parallel. They would store the request in the same bitmap.
Nice! Seems like a well-balanced solution ;)
Quoted 3 lines
We could print a message that "
panic_print" has been obsoleted by "panic_sys_info" when people use it.
Indeed, we should add a deprecation warning. Perhaps the message could say:
"'panic_print=' is deprecated and will be removed. Use 'panic_sys_info=' instead."
e.g. pr_warn_ratelimited("block device autoloading is deprecated and will be removed.\n") in blkdev_get_no_open().
Quoted 3 lines
Both parameters would override the current bitmap. So the later used parameter or procfs/sysfs write would win.
Makes sense to me. BTW, this override behavior needs to be documented in kernel-doc.
Quoted 9 lines
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
Quoted 5 lines
The sysfs, aka
include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the/sys/... jungle ;-)I would slightly prefer "sysctl" because these parameters are easier to find.
+1 for sysctl.
Thanks,
Lance
Quoted 3 lines
Best Regards,
Petr
Re: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
In reply to Petr MladekQuoted 34 lines · Petr Mladek
Quoted 15 lines · Feng Tang
Hi Petr,
Thanks for the review!
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Feng Tang
panic_printwas introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.The generic approach might deserve a separate source file, for example:
Quoted 6 lines
Quoted 2 lines
include/linux/sys_info.h
lib/sys_info.cThanks for the suggestion! I'm really not good at naming.
As
panic.cis always built-in, I'll putsys_info.cas obj-y.Makes sense.
Quoted 9 lines
Quoted 5 lines
Also I always considered the bitmask as a horrible user interface. It might be used internally. But it would be better to allow a human readable parameter, for example:
panic_sys_info=task,mem,timer,lock,ftrace,bt,all_bt,blocked_tasks
Yes, it's convenient for developers, as a cmdline parameter being parsed at boot time.
Quoted 8 lines
Quoted 4 lines
But I think bitmask may be easier for runtime changing as a core parameter under
/proc/or/sys/, or from sysctl interface. There are also some other modules use debug bitmask controlling printking info for different sub-components.Good to know. Could you please give me a pointer to some other modules using the bitmask? I believe that they exist but I can't find any. I wonder how common it is...
Definitely not common :) I only know one: ACPI, which has 2 debug knobs, 'debug_layer' is a bigmap to control which sub-component's msg to be dumped, and 'debug_level'.
Quoted 1 line
Anyway, I personally find words/names easier to use.
True. For me, I have some notes sticked on my monitor: one about characters for /proc/sysrq-trigger, one for panic_print, one for struct page's flag :)
Quoted 6 lines
For example,
I like the following interfaces:#> cat
/sys/power/pm_test
[none] core processors platform devices freezer
Quoted 7 lines
#> cat
/sys/kernel/debug/tracing/available_tracersblkfunction_graphwakeup_dlwakeup_rtwakeup function nop#> cat
/proc/sys/kernel/seccomp/actions_availkill_processkill_threadtrap errnouser_notiftrace log allow# cat /proc/sys/kernel/seccomp/actions_logged kill_process kill_thread trap errno user_notif trace log
Thanks for the info, will check them.
Quoted 20 lines
Quoted 8 lines
And we have similar control knobs for hung, lockup etc.
Or should I change the name from '
xxx_print_mask' to 'xxx_sysinfo_flag' in patch 2/3 ?Quoted 3 lines
The console reply might be handled by a separate:
Quoted 7 lines
Quoted 4 lines
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.Agree it's ugly :). But besides a kernel parameter, '
panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.A solution would be to keep it and create "panic_sys_info=" with the human readable parameters in parallel. They would store the request in the same bitmap.
Quoted 5 lines
We could print a message that "
panic_print" has been obsoleted by "panic_sys_info" when people use it.Both parameters would override the current bitmap. So the later used parameter or procfs/sysfs write would win.
Reasonalbe.
Quoted 8 lines
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
Quoted 5 lines
The sysfs, aka
include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the/sys/... jungle ;-)I would slightly prefer "sysctl" because these parameters are easier to find.
I will think about the string parsing in sys_info.c, and in the backend, a bitmap is still needed to save the parsing result, and as the parameter for sys_show_info().
Also if we go 'sysctl' way, in the future, some exising interface like 'sysctl_hung_task_all_cpu_backtrace' could be deprecated and integrated into the 'hung_task_sys_info'?
Thanks,
Feng
Quoted 2 lines
Best Regards,
Petr
Lance Yang
maintainerRe: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
Quoted 111 lines · Feng Tang
Quoted 34 lines · Petr Mladek
Quoted 15 lines · Feng Tang
Hi Petr,
Thanks for the review!
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Feng Tang
panic_printwas introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.The generic approach might deserve a separate source file, for example:
Quoted 6 lines
Quoted 2 lines
include/linux/sys_info.h
lib/sys_info.cThanks for the suggestion! I'm really not good at naming.
As
panic.cis always built-in, I'll putsys_info.cas obj-y.Makes sense.
Quoted 9 lines
Quoted 5 lines
Also I always considered the bitmask as a horrible user interface. It might be used internally. But it would be better to allow a human readable parameter, for example:
panic_sys_info=task,mem,timer,lock,ftrace,bt,all_bt,blocked_tasks
Yes, it's convenient for developers, as a cmdline parameter being parsed at boot time.
Quoted 8 lines
Quoted 4 lines
But I think bitmask may be easier for runtime changing as a core parameter under
/proc/or/sys/, or from sysctl interface. There are also some other modules use debug bitmask controlling printking info for different sub-components.Good to know. Could you please give me a pointer to some other modules using the bitmask? I believe that they exist but I can't find any. I wonder how common it is...
Definitely not common :) I only know one: ACPI, which has 2 debug knobs, '
debug_layer' is a bigmap to control which sub-component's msg to be dumped, and 'debug_level'.Quoted 1 line
Anyway, I personally find words/names easier to use.
True. For me, I have some notes sticked on my monitor: one about characters for
/proc/sysrq-trigger, one forpanic_print, one for struct page's flag :)Quoted 6 lines
For example,
I like the following interfaces:#> cat
/sys/power/pm_test
[none] core processors platform devices freezerQuoted 7 lines
#> cat
/sys/kernel/debug/tracing/available_tracersblkfunction_graphwakeup_dlwakeup_rtwakeup function nop#> cat
/proc/sys/kernel/seccomp/actions_availkill_processkill_threadtrap errnouser_notiftrace log allow# cat /proc/sys/kernel/seccomp/actions_logged kill_process kill_thread trap errno user_notif trace logThanks for the info, will check them.
Quoted 20 lines
Quoted 8 lines
And we have similar control knobs for hung, lockup etc.
Or should I change the name from '
xxx_print_mask' to 'xxx_sysinfo_flag' in patch 2/3 ?Quoted 3 lines
The console reply might be handled by a separate:
Quoted 7 lines
Quoted 4 lines
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.Agree it's ugly :). But besides a kernel parameter, '
panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.A solution would be to keep it and create "panic_sys_info=" with the human readable parameters in parallel. They would store the request in the same bitmap.
Quoted 5 lines
We could print a message that "
panic_print" has been obsoleted by "panic_sys_info" when people use it.Both parameters would override the current bitmap. So the later used parameter or procfs/sysfs write would win.
Reasonalbe.
Quoted 8 lines
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
Quoted 5 lines
The sysfs, aka
include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the/sys/... jungle ;-)I would slightly prefer "sysctl" because these parameters are easier to find.
Quoted 7 lines
I will think about the string parsing in
sys_info.c, and in the backend, a bitmap is still needed to save the parsing result, and as the parameter forsys_show_info().Also if we go 'sysctl' way, in the future, some exising interface like '
sysctl_hung_task_all_cpu_backtrace' could be deprecated and integrated into the 'hung_task_sys_info'?
Works for me. Let's go with 'sysctl' approach, and 'hung_task_all_cpu_backtrace' could be deprecated, though it won't be removed anytime soon. IMHO, 'hung_task_sys_info' is more organized and easier to expand - plus these parameters are much easier to find as Petr said ;)
Thanks,
Lance
Quoted 6 lines
Thanks,
FengQuoted 2 lines
Best Regards,
Petr
Re: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
In reply to Feng TangQuoted 1 line · Feng Tang
On Thu, May 15, 2025 at 12:32:04PM +0200, Petr Mladek wrote:
[...]
Quoted 33 lines
Quoted 14 lines
Quoted 9 lines
Quoted 6 lines
The console reply might be handled by a separate:
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.Agree it's ugly :). But besides a kernel parameter, '
panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.A solution would be to keep it and create "panic_sys_info=" with the human readable parameters in parallel. They would store the request in the same bitmap.
Quoted 5 lines
We could print a message that "
panic_print" has been obsoleted by "panic_sys_info" when people use it.Both parameters would override the current bitmap. So the later used parameter or procfs/sysfs write would win.
Reasonalbe.
Quoted 11 lines
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
The sysfs, aka
include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the/sys/... jungle ;-)
Quoted 6 lines
Quoted 2 lines
I would slightly prefer "sysctl" because these parameters are easier to find.
I will think about the string parsing in
sys_info.c, and in the backend, a bitmap is still needed to save the parsing result, and as the parameter forsys_show_info().
Hi Petr
I tried further this way, and with below patch on top of current 1/3 patch, the 'panic_sys_info' sysctl interface basically works, as parsing user-input, and save it in 'panic_print' bitmap.
It has one problem that it doesn't support the string parsing as a the kernel command line parameter (auto-derived from sysctl interface), I'm not sure if we should add a __setup() or early_param() for it, or it's fine?
Thanks,
Feng
---
include/linux/sys_info.h +4 -0
@@ -17,4 +17,8 @@extern void sys_show_info (unsigned long info_mask); +struct ctl_table ; +extern int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write, +void *buffer,size_t *lenp, +loff_t *ppos);#endif /* _LINUX_SYS_INFO_H */
kernel/panic.c +7 -0
@@ -88,6 +88,13 @@ static const struct ctl_table kern_panic_table[] = { .extra2 = SYSCTL_ONE, },#endif + { + .procname = "panic_sys_info", + .data = &panic_print, + .maxlen = sizeof(panic_print), + .mode = 0644, + .proc_handler = sysctl_sys_info_handler, + }, { .procname = "warn_limit", .data = &warn_limit,
lib/sys_info.c +115 -0
121 lines not on this page · raw message
Petr Mladek
reviewerRe: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
Quoted 43 lines · Feng Tang
Quoted 1 line · Feng Tang
On Thu, May 15, 2025 at 12:32:04PM +0200, Petr Mladek wrote:
[...]
Quoted 33 lines
Quoted 14 lines
Quoted 9 lines
Quoted 6 lines
The console reply might be handled by a separate:
panic_console_reply=1
And it would obsolete the existing "
panic_print" which is an ugly name and interface from my POV.Agree it's ugly :). But besides a kernel parameter, '
panic_print' is also a sysctl interface, I'm afraid renaming it might break user ABI.A solution would be to keep it and create "panic_sys_info=" with the human readable parameters in parallel. They would store the request in the same bitmap.
Quoted 5 lines
We could print a message that "
panic_print" has been obsoleted by "panic_sys_info" when people use it.Both parameters would override the current bitmap. So the later used parameter or procfs/sysfs write would win.
Reasonalbe.
Quoted 11 lines
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
The sysfs, aka
include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the/sys/... jungle ;-)Quoted 6 lines
Quoted 2 lines
I would slightly prefer "sysctl" because these parameters are easier to find.
I will think about the string parsing in
sys_info.c, and in the backend, a bitmap is still needed to save the parsing result, and as the parameter forsys_show_info().
Quoted 5 lines
Hi Petr
I tried further this way, and with below patch on top of current 1/3 patch, the '
panic_sys_info' sysctl interface basically works, as parsing user-input, and save it in 'panic_print' bitmap.
It does not apply. It seems that it depends on another change which crated lib/sys_info.c...
Quoted 4 lines
It has one problem that it doesn't support the string parsing as a the kernel command line parameter (auto-derived from sysctl interface), I'm not sure if we should add a
__setup()orearly_param()for it, or it's fine?
Ah, I was not aware of this. We need to make it working from the command line, definitely. I would go with __setup() for now. We could always switch it to early_param() when anyone requires it.
See some more comments, below.
Quoted 37 lines
---
include/linux/sys_info.h +4
-0@@ -17,4 +17,8 @@extern void sys_show_info (unsigned long info_mask); +struct ctl_table ; +extern int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write, +void *buffer,size_t *lenp, +loff_t *ppos);#endif /* _LINUX_SYS_INFO_H */ kernel/panic.c +7
-0@@ -88,6 +88,13 @@ static const struct ctl_table kern_panic_table[] = { .extra2 = SYSCTL_ONE, },#endif + { + .procname = "panic_sys_info", + .data = &panic_print, + .maxlen = sizeof(panic_print), + .mode = 0644, + .proc_handler = sysctl_sys_info_handler, + }, { .procname = "warn_limit", .data = &warn_limit,lib/sys_info.c +0
-0
lib/sys_info.c line 12
Quoted 9 lines
lib/sys_info.c +6
-0@@ -4,6 +4,121 @@#include <linux/console.h> #include <linux/nmi.h> +struct sys_info_name { +unsigned long bit; +const char *name; +}; + +static const char sys_info_avail[] =" tasks mem timer lock ftrace all_bt blocked_tasks " ;
It is a bit confusing to have it space-separated when the parameter is comma-separated. Also I am not sure why there is the leading and trailing space.
I would expect:
static const char sys_info_avail[] = "tasks,mem,timer,lock,ftrace,all_bt,blocked_tasks";
lib/sys_info.c line 22
Quoted 9 lines
lib/sys_info.c +9
-0+static const struct sys_info_name si_names[] = { + {SYS_SHOW_TASK_INFO ,"tasks" }, + {SYS_SHOW_MEM_INFO ,"mem" }, + {SYS_SHOW_TIMER_INFO ,"timer" }, + {SYS_SHOW_LOCK_INFO ,"lock" }, + {SYS_SHOW_FTRACE_INFO ,"ftrace" }, + {SYS_SHOW_ALL_CPU_BT ,"all_bt" }, + {SYS_SHOW_BLOCKED_TASKS ,"blocked_tasks" }, +};
I guess that this is just an RFC. Anyway, I would expect that SYS_SHOW_* values would be defined in sys_info.h.
Quoted 23 lines
lib/sys_info.c +23
-0+ +/* Expecting string like "xxx_sys_info=tasks,mem,timer,lock" */ +static int write_handler (const struct ctl_table *ro_table,void *buffer, +size_t *lenp,loff_t *ppos) +{ +char names[sizeof (sys_info_avail)]; +char *buf, *name; +struct ctl_table table; +unsigned long *si_flag; +int i, len, ret; + + si_flag = ro_table->data; + +/* Clear it first */ + *si_flag =0 ; + + table = *ro_table; + table.data = names; + table.maxlen =sizeof (names); + ret =proc_dostring (&table,1 , buffer, lenp, ppos); +if (ret) +return ret; +
lib/sys_info.c line 56
Quoted 10 lines
lib/sys_info.c +10
-0+ buf = names; +while ((name =strsep (&buf,"," )) && *name) { +for (i =0 ; i <ARRAY_SIZE (si_names); i++) { +if (!strcmp (name, si_names[i].name)) + *si_flag |= si_names[i].bit; + } + } + +return 0 ; +}
The above function is defined but not used. The same code is copy&pasted in the if (write) section below.
I think that we would need a helper function which could be used in both sysctl_sys_info_handler() and in the __setup() callback.
Something like:
static unsigned long sys_info_parse_flags(char *str)
{
unsigned long si_bits = 0;
char *s, *name;
int i;
s = str;
while ((name = strsep(&s, ",")) && *name) {
for (i = 0; i < ARRAY_SIZE(si_names); i++) {
if (!strcmp(name, si_names[i].name)) {
*si_bits |= si_names[i].bit;
break;
}
}
}
return si_bits;
}lib/sys_info.c line 65
Quoted 9 lines
lib/sys_info.c +9
-0+ +int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write, +void *buffer,size_t *lenp, +loff_t *ppos) +{ +char names[sizeof (sys_info_avail) +1 ]; +char *buf, *name; +struct ctl_table table; +unsigned long *si_flag;
Nit: I would call this "si_bits_global" to make it more clear that
this is pointer to the global bitmask.
lib/sys_info.c line 72
Quoted 7 lines
lib/sys_info.c +7
-0+int i, ret, len; + + si_flag = ro_table->data; + +if (write) { +/* Clear it first */ + *si_flag =0 ;
There is no synchronization against readers. IMHO, it is not worth it. But we should at least update the global value only once.
We should define a local variable, e.g.
unsigned long si_bits;
and do the following:
lib/sys_info.c line 43
Quoted 4 lines
lib/sys_info.c +4
-0+ table = *ro_table; + table.data = names; + table.maxlen =sizeof (names); + ret =proc_dostring (&table,1 , buffer, lenp, ppos);
I would pass the "write" parameter here instead of the hard-coded "1". Do we know that it should be exactly '1'?
lib/sys_info.c line 76
Quoted 2 lines
lib/sys_info.c +2
-0+if (ret) +return ret;
si_bits = sys_info_parse_param(flags); /* * The access to the global value is not synchronized. * Update it at once at least. */ WRITE_ONCE(*si_bits_global, si_bits);
Quoted 4 lines
lib/sys_info.c +4
-0+/* Expecting string like "xxx_sys_info=tasks,mem,timer,lock" */ + buf = names; +while ((name =strsep (&buf,"," )) && *name) { +for (i =0 ; i <ARRAY_SIZE (si_names); i++) {
lib/sys_info.c line 94
Quoted 10 lines
lib/sys_info.c +10
-0+if (!strcmp (name, si_names[i].name)) + *si_flag |= si_names[i].bit; + } + } + +return 0 ; + }else { +bool first = true; + +memset (names,0 ,sizeof (names));
I guess that you took this from read_actions_logged().
It looks too paranoid to me. I do not see it anywhere else. IMHO, if the proc_dostring() does not stop at the trailing '\0' then most interfaces would leak data.
Quoted 8 lines
lib/sys_info.c +8
-0+ buf = names; +for (i =0 ; i <ARRAY_SIZE (si_names); i++) { +if (*si_flag & si_names[i].bit) { + +if (first) { + first = false; + }else { + *buf =',' ;
lib/sys_info.c line 113
Quoted 10 lines
lib/sys_info.c +10
-0+ buf++; + } + + len =strlen (si_names[i].name); +strncpy (buf, si_names[i].name, len); + buf += len; + } + + } + *buf ='\0' ;
IMHO, always adding this trailing '\0' should be enough.
lib/sys_info.c line 118
Quoted 4 lines
lib/sys_info.c +4
-0+ table = *ro_table; + table.data = names; + table.maxlen =sizeof (names); +return proc_dostring (&table,0 , buffer, lenp, ppos);
I would pass the "write" parameter here instead of the hard coded 0. But it is a matter of taste.
lib/sys_info.c line 124
Quoted 6 lines
lib/sys_info.c +3
-0+ } +} +void sys_show_info (unsigned long info_flag) {if (info_flag &SYS_SHOW_TASK_INFO )
Best Regards,
Petr
PS: I am sorry for the late reply. Too many things have accumulated over the few last weeks.
Re: [PATCH v1 1/3] kernel/panic: generalize panic_print's function to show sys info
On Tue, Jun 10, 2025 at 05:44:34PM +0200, Petr Mladek wrote:
[...]
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 8 lines
Note:
One question is whether to use sysctl or module parameters.
An advantage of sysctl is the "systcl" userspace tool. Some people might like it. But the API is very old and a bit cumbersome for implementing.
Quoted 5 lines
The sysfs, aka
include/linux/moduleparam.h, API looks cleaner to me. But the parameters are hidden in the/sys/... jungle ;-)I would slightly prefer "sysctl" because these parameters are easier to find.
I will think about the string parsing in
sys_info.c, and in the backend, a bitmap is still needed to save the parsing result, and as the parameter forsys_show_info().
Quoted 8 lines
Quoted 5 lines
Hi Petr
I tried further this way, and with below patch on top of current 1/3 patch, the '
panic_sys_info' sysctl interface basically works, as parsing user-input, and save it in 'panic_print' bitmap.It does not apply. It seems that it depends on another change which crated
lib/sys_info.c...
My bad. It could be another my local change which follows your suggestion of using a panic_console_replay() cleanup.
Quoted 8 lines
Quoted 4 lines
It has one problem that it doesn't support the string parsing as a the kernel command line parameter (auto-derived from sysctl interface), I'm not sure if we should add a
__setup()orearly_param()for it, or it's fine?Ah, I was not aware of this. We need to make it working from the command line, definitely. I would go with
__setup()for now. We could always switch it toearly_param()when anyone requires it.
OK.
Quoted 42 lines
See some more comments, below.
Quoted 40 lines
---
include/linux/sys_info.h +4
-0@@ -17,4 +17,8 @@extern void sys_show_info (unsigned long info_mask); +struct ctl_table ; +extern int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write, +void *buffer,size_t *lenp, +loff_t *ppos);#endif /* _LINUX_SYS_INFO_H */ kernel/panic.c +7
-0@@ -88,6 +88,13 @@ static const struct ctl_table kern_panic_table[] = { .extra2 = SYSCTL_ONE, },#endif + { + .procname = "panic_sys_info", + .data = &panic_print, + .maxlen = sizeof(panic_print), + .mode = 0644, + .proc_handler = sysctl_sys_info_handler, + }, { .procname = "warn_limit", .data = &warn_limit,lib/sys_info.c +0
-0@@ -4,6 +4,121 @@#include <linux/console.h> #include <linux/nmi.h>
Quoted 9 lines
lib/sys_info.c line 12
Quoted 6 lines
lib/sys_info.c +6
-0+struct sys_info_name { +unsigned long bit; +const char *name; +}; + +static const char sys_info_avail[] =" tasks mem timer lock ftrace all_bt blocked_tasks " ;It is a bit confusing to have it space-separated when the parameter is comma-separated.
Aha, right.
Quoted 2 lines
Also I am not sure why there is the leading and
trailing space.
I tried to give more space to avoid 'char names[strlen()+1]'
Quoted 3 lines
I would expect:
static const char sys_info_avail[] = "tasks,mem,timer,lock,ftrace,all_bt,blocked_tasks";
OK.
Quoted 4 lines
Quoted 4 lines
lib/sys_info.c +4
-0+static const struct sys_info_name si_names[] = { + {SYS_SHOW_TASK_INFO ,"tasks" }, + {SYS_SHOW_MEM_INFO ,"mem" }, + {SYS_SHOW_TIMER_INFO ,"timer" },
Quoted 8 lines
lib/sys_info.c line 22
Quoted 5 lines
lib/sys_info.c +5
-0+ { SYS_SHOW_LOCK_INFO, "lock" }, + { SYS_SHOW_FTRACE_INFO, "ftrace" }, + { SYS_SHOW_ALL_CPU_BT, "all_bt" }, + { SYS_SHOW_BLOCKED_TASKS, "blocked_tasks" }, +};I guess that this is just an RFC. Anyway, I would expect that SYS_SHOW_* values would be defined in
sys_info.h.
Yes, in 0001 patch, they are defined in sys_info.h
Quoted 28 lines
Quoted 28 lines
lib/sys_info.c +28
-0+ +/* Expecting string like "xxx_sys_info=tasks,mem,timer,lock" */ +static int write_handler (const struct ctl_table *ro_table,void *buffer, +size_t *lenp,loff_t *ppos) +{ +char names[sizeof (sys_info_avail)]; +char *buf, *name; +struct ctl_table table; +unsigned long *si_flag; +int i, len, ret; + + si_flag = ro_table->data; + +/* Clear it first */ + *si_flag =0 ; + + table = *ro_table; + table.data = names; + table.maxlen =sizeof (names); + ret =proc_dostring (&table,1 , buffer, lenp, ppos); +if (ret) +return ret; + + buf = names; +while ((name =strsep (&buf,"," )) && *name) { +for (i =0 ; i <ARRAY_SIZE (si_names); i++) { +if (!strcmp (name, si_names[i].name)) + *si_flag |= si_names[i].bit;
Quoted 8 lines
lib/sys_info.c line 56
Quoted 5 lines
lib/sys_info.c +5
-0+ } + } + +return 0 ; +}The above function is defined but not used. The same code is copy&pasted in the if (write) section below.
I forgot to remove it in code clean :)
Quoted 6 lines
I think that we would need a helper function which could be used in both
sysctl_sys_info_handler()and in the__setup()callback.Something like:
static unsigned long
sys_info_parse_flags(char *str)
Quoted 11 lines
{
unsigned long si_bits = 0;
char *s, *name;
int i;
s = str;
while ((name = strsep(&s, ",")) && *name) {
for (i = 0; i < ARRAY_SIZE(si_names); i++) {
if (!strcmp(name, si_names[i].name)) {
*si_bits |= si_names[i].bit;
break;Good catch! thanks
Quoted 6 lines
} } } return si_bits; }
Will do.
Quoted 4 lines
Quoted 4 lines
lib/sys_info.c +4
-0+ +int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write, +void *buffer,size_t *lenp, +loff_t *ppos)
Quoted 8 lines
lib/sys_info.c line 65
Quoted 5 lines
lib/sys_info.c +5
-0+{ +char names[sizeof (sys_info_avail) +1 ]; +char *buf, *name; +struct ctl_table table; +unsigned long *si_flag;Nit: I would call this "
si_bits_global" to make it more clear that
this is pointer to the global bitmask.
Makes sense.
Quoted 12 lines
lib/sys_info.c line 72
Quoted 8 lines
lib/sys_info.c +7
-0+int i, ret, len; + + si_flag = ro_table->data; + +if (write) { +/* Clear it first */ + *si_flag =0 ;There is no synchronization against readers. IMHO, it is not worth it. But we should at least update the global value only once.
Quoted 5 lines
We should define a local variable, e.g.
unsigned long si_bits;and do the following:
Will do.
Quoted 8 lines
lib/sys_info.c line 43
Quoted 4 lines
lib/sys_info.c +4
-0+ table = *ro_table; + table.data = names; + table.maxlen =sizeof (names); + ret =proc_dostring (&table,1 , buffer, lenp, ppos);I would pass the "write" parameter here instead of the hard-coded "1". Do we know that it should be exactly '1'?
Quoted 9 lines
lib/sys_info.c line 76
Quoted 2 lines
lib/sys_info.c +2
-0+if (ret) +return ret;si_bits = sys_info_parse_param(flags); /* * The access to the global value is not synchronized. * Update it at once at least. */ WRITE_ONCE(*si_bits_global, si_bits);
Thanks for the suggestion.
Quoted 8 lines
Quoted 8 lines
lib/sys_info.c +8
-0+/* Expecting string like "xxx_sys_info=tasks,mem,timer,lock" */ + buf = names; +while ((name =strsep (&buf,"," )) && *name) { +for (i =0 ; i <ARRAY_SIZE (si_names); i++) { +if (!strcmp (name, si_names[i].name)) + *si_flag |= si_names[i].bit; + } + }
Quoted 8 lines
lib/sys_info.c line 94
Quoted 6 lines
lib/sys_info.c +6
-0+ +return 0 ; + }else { +bool first = true; + +memset (names,0 ,sizeof (names));I guess that you took this from
read_actions_logged().
Yes, I referred the seccomp.c in many places.
Quoted 16 lines
It looks too paranoid to me. I do not see it anywhere else. IMHO, if the
proc_dostring()does not stop at the trailing '\0' then most interfaces would leak data.Quoted 12 lines
lib/sys_info.c +12
-0+ buf = names; +for (i =0 ; i <ARRAY_SIZE (si_names); i++) { +if (*si_flag & si_names[i].bit) { + +if (first) { + first = false; + }else { + *buf =',' ; + buf++; + } + + len =strlen (si_names[i].name);
Quoted 8 lines
lib/sys_info.c line 113
Quoted 6 lines
lib/sys_info.c +6
-0+strncpy (buf, si_names[i].name, len); + buf += len; + } + + } + *buf ='\0' ;IMHO, always adding this trailing '\0' should be enough.
OK.
Quoted 8 lines
lib/sys_info.c line 118
Quoted 5 lines
lib/sys_info.c +4
-0+ table = *ro_table; + table.data = names; + table.maxlen =sizeof (names); +return proc_dostring (&table,0 , buffer, lenp, ppos);I would pass the "write" parameter here instead of the hard coded 0. But it is a matter of taste.
I think it's obviously better :). will change.
Quoted 11 lines
lib/sys_info.c line 124
Quoted 7 lines
lib/sys_info.c +3
-0+ } +} +void sys_show_info (unsigned long info_flag) {if (info_flag &SYS_SHOW_TASK_INFO )Best Regards,
Petr
Quoted 2 lines
PS: I am sorry for the late reply. Too many things have accumulated over the few last weeks.
No problem! I really appreciate your review and suggestions, like your help on reviewing my early 'panic_print' patches years ago.
Thanks,
Feng
PATCH 2/3 kernel/hung_task: add option to dump system info when hung task detected
In reply to Feng TangKernel panic code utilizes sys_show_info() to dump needed system
information to help debugging. Similarly, add this debug option for task hung case, and 'hungtask_print_mask' is the control knob and a bitmask to control what information should be printed out:
bit 0: print all tasks info
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 6: print all CPUs backtrace (if available in the arch) bit 7: print only tasks in uninterruptible (blocked) state
Also simplify the code about dumping locks and triggering backtrace for all CPUs by leveraging sys_show_info().
--- .../admin-guide/kernel-parameters.txt | 5 +++ kernel/hung_task.c | 42 +++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -4488,6 +4488,11 @@ Use this option carefully, maybe worth to setup a bigger log buffer with "log_buf_len" along with this. + hungtask_print_mask= + Bitmask for printing system info when hung task is detected. + Details of bits definition is the same as panic_print's + definition above. + parkbd.port= [HW] Parallel port number the keyboard adapter is connected to, default is 0. Format: <parport#>
kernel/hung_task.c +29 -13
83 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH 3/3 kernel/watchdog: add option to dump system info when system is locked up
In reply to Feng TangKernel panic code utilizes sys_show_info() to dump needed system
information to help debugging. Similarly, add this debug option for software/hardware lockup cases, and 'lockup_print_mask' is the control knob and a bitmask to control what information should be printed out:
bit 0: print all tasks info
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 6: print all CPUs backtrace (if available in the arch) bit 7: print only tasks in uninterruptible (blocked) state
--- .../admin-guide/kernel-parameters.txt | 11 +++++++--- kernel/watchdog.c | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +8 -3
@@ -4489,9 +4489,14 @@ bigger log buffer with "log_buf_len" along with this. hungtask_print_mask= - Bitmask for printing system info when hung task is detected. - Details of bits definition is the same as panic_print's - definition above. + Bitmask for printing system info when hung task is + detected. Details of bits definition is the same as + panic_print's definition above. + + lockup_print_mask= + Bitmask for printing system info when software/hardware + system lockup is detected. Details of bits definition + is the same as panic_print's definition above. parkbd.port= [HW] Parallel port number the keyboard adapter is connected to, default is 0.
kernel/watchdog.c +20 -0
@@ -52,6 +52,23 @@ static int __read_mostly watchdog_hardlockup_available;struct cpumask watchdog_cpumask__read_mostly ;unsigned long *watchdog_cpumask_bits =cpumask_bits (&watchdog_cpumask); +/* +* A bitmask to control what kinds of system info to be printed when a +* software/hardware lockup is detected, it could be task, memory, lock +* etc. And the bit definition (from panic.h) is: +* +* #define SYS_PRINT_TASK_INFO 0x00000001 +* #define SYS_PRINT_MEM_INFO 0x00000002 +* #define SYS_PRINT_TIMER_INFO 0x00000004 +* #define SYS_PRINT_LOCK_INFO 0x00000008 +* #define SYS_PRINT_FTRACE_INFO 0x00000010 +* #define SYS_PRINT_ALL_PRINTK_MSG 0x00000020 +* #define SYS_PRINT_ALL_CPU_BT 0x00000040 +* #define SYS_PRINT_BLOCKED_TASKS 0x00000080 +*/ +unsigned long lockup_print_mask; +core_param (lockup_print_mask, lockup_print_mask, ulong,0644 ); +#ifdef CONFIG_HARDLOCKUP_DETECTOR # ifdef CONFIG_SMP
@@ -212,6 +229,7 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs)clear_bit_unlock (0 , &hard_lockup_nmi_warn); } +sys_show_info (lockup_print_mask);if (hardlockup_panic)nmi_panic (regs,"Hard LOCKUP" );
@@ -774,6 +792,8 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) }add_taint (TAINT_SOFTLOCKUP ,LOCKDEP_STILL_OK ); + +sys_show_info (lockup_print_mask);if (softlockup_panic)panic ("softlockup: hung tasks" ); }
Signature · 1 line
2.39.5 (Apple Git-154)
Andrew Morton
maintainerQuoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.
Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
As for this patchset - sounds good to me. For now I'll await input from reviewers.
Hi Andrew,
Thanks for the review!
Quoted 17 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Quoted 7 lines
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
Quoted 2 lines
As for this patchset - sounds good to me. For now I'll await input from reviewers.
Thank you!
- Feng
Lance Yang
maintainerQuoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.
Something like:
If SYS_PRINT_ALL_CPU_BT (global knob) is on, it enables hung_task_all_cpu_backtrace for hung-task situation automatically. But users can still disable it via hung_task_all_cpu_backtrace.
Anyway, the global knob (when set) controls all feature-level knobs, but they can override it if explicitly set ;)
Thanks,
Lance
Quoted 7 lines
Quoted 3 lines
As for this patchset - sounds good to me. For now I'll await input from reviewers.
Thank you!
- Feng
Quoted 48 lines · Lance Yang
Quoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.Something like:
Quoted 7 lines
If
SYS_PRINT_ALL_CPU_BT(global knob) is on, it enableshung_task_all_cpu_backtrace
for hung-task situation automatically. But users can still disable it viahung_task_all_cpu_backtrace.Anyway, the global knob (when set) controls all feature-level knobs, but they can override it if explicitly set ;)
Yes, it makes sense for parts which already has its own user space control knob.
What I proposed is a todo mostly for other parts than panic/hungtask in this patchset, as these parts have some special handling required, like panic need to handle printk-replay for kexec case.
Thanks,
Feng
Petr Mladek
reviewerQuoted 46 lines · Lance Yang
Quoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.
Quoted 6 lines
Something like:
If
SYS_PRINT_ALL_CPU_BT(global knob) is on, it enableshung_task_all_cpu_backtrace
for hung-task situation automatically. But users can still disable it viahung_task_all_cpu_backtrace.
I am all for unifying the options for printing debug information in various emergency situations. I am just not sure whether we really want to do the same in all situations.
Some lockup detectors tries to be more clever, for example:
+ RCU stall detector prints backtraces only from CPUs which are involved in the stall, see print_other_cpu_stall().
+ Workqueues watchdog shows backtraces from tasks which are preventing forward progress, see show_cpu_pool_hog().
And stalls are about scheduling (disabled preemption, disabled IRQ, deadlocks, too long uninterruptible sleep). OOM is about memory usage. Oops is about an invalid memory access. WARNs() are completely random stuff.
Also I am afraid of printing too much information when the system is supposed to continue running. It would make sense to print it in nbcon_cpu_emergency_enter()/exit() context which disables preemption. And it might cause softlockups on its own.
Finally, I wonder whether ftrace_dump() might cause a livelock when ftrace is adding new messages in parallel.
The situation is much easier during panic() because the system is going to die() anyway, non-panic CPUs are stopped, ...
That said, I could understand that people might want to see as much information as possible when the console is fast and the range of possible problems is big.
Anyway, I have added few more people into Cc who are interested into the various watchdogs.
And there is parallel initiative which tries to unify the loglevel or somehow make the filtering easier, see
https://lore.kernel.org/r/[email protected]
Best Regards,
Petr
Quoted 71 lines · Petr Mladek
Quoted 46 lines · Lance Yang
Quoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.Quoted 6 lines
Something like:
If
SYS_PRINT_ALL_CPU_BT(global knob) is on, it enableshung_task_all_cpu_backtrace
for hung-task situation automatically. But users can still disable it viahung_task_all_cpu_backtrace.I am all for unifying the options for printing debug information in various emergency situations. I am just not sure whether we really want to do the same in all situations.
Some lockup detectors tries to be more clever, for example:
+ RCU stall detector prints backtraces only from CPUs which are involved in the stall, see
print_other_cpu_stall().+ Workqueues watchdog shows backtraces from tasks which are preventing forward progress, see
show_cpu_pool_hog().And stalls are about scheduling (disabled preemption, disabled IRQ, deadlocks, too long uninterruptible sleep). OOM is about memory usage. Oops is about an invalid memory access.
WARNs()are completely random stuff.
Quoted 4 lines
Also I am afraid of printing too much information when the system is supposed to continue running. It would make sense to print it in nbcon_cpu_emergency_enter()/exit() context which disables preemption. And it might cause softlockups on its own.
And we did do some of the cleverness that Petr points out because of problems caused by flooding the console log. We first ran into this sort of thing on embedded systems with slow serial consoles (where 115K baud is now way slow), but it also shows up in other environments, for example, those committing large numbers of console logs to stable storage, multiplexing large numbers of logs across networks that sometimes get congested, and so on.
So I second the call for individual knobs, either in addition to or instead of the global knob.
Quoted 2 lines
Finally, I wonder whether
ftrace_dump()might cause a livelock when ftrace is adding new messages in parallel.
It definitely can cause problems, and me learning this the hard way is why rcutorture calls tracing_off() before calling ftrace_dump().
Quoted 6 lines
The situation is much easier during
panic()because the system is going todie()anyway, non-panic CPUs are stopped, ...That said, I could understand that people might want to see as much information as possible when the console is fast and the range of possible problems is big.
No argument here.
Thanx, Paul
Quoted 9 lines
Anyway, I have added few more people into Cc who are interested into the various watchdogs.
And there is parallel initiative which tries to unify the loglevel or somehow make the filtering easier, see
https://lore.kernel.org/r/[email protected]Best Regards,
Petr
Quoted 85 lines · Paul E. McKenney
Quoted 71 lines · Petr Mladek
Quoted 46 lines · Lance Yang
Quoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.Quoted 6 lines
Something like:
If
SYS_PRINT_ALL_CPU_BT(global knob) is on, it enableshung_task_all_cpu_backtrace
for hung-task situation automatically. But users can still disable it viahung_task_all_cpu_backtrace.I am all for unifying the options for printing debug information in various emergency situations. I am just not sure whether we really want to do the same in all situations.
Some lockup detectors tries to be more clever, for example:
+ RCU stall detector prints backtraces only from CPUs which are involved in the stall, see
print_other_cpu_stall().+ Workqueues watchdog shows backtraces from tasks which are preventing forward progress, see
show_cpu_pool_hog().And stalls are about scheduling (disabled preemption, disabled IRQ, deadlocks, too long uninterruptible sleep). OOM is about memory usage. Oops is about an invalid memory access.
WARNs()are completely random stuff.Quoted 4 lines
Also I am afraid of printing too much information when the system is supposed to continue running. It would make sense to print it in nbcon_cpu_emergency_enter()/exit() context which disables preemption. And it might cause softlockups on its own.
And we did do some of the cleverness that Petr points out because of problems caused by flooding the console log. We first ran into this sort of thing on embedded systems with slow serial consoles (where 115K baud is now way slow), but it also shows up in other environments, for example, those committing large numbers of console logs to stable storage, multiplexing large numbers of logs across networks that sometimes get congested, and so on.
Quoted 2 lines
So I second the call for individual knobs, either in addition to or instead of the global knob.
Thanks for the detail elaboration! RCU stall case is also a main target in the stability issues I have worked on, besides panic/taskhung/lockup. I noticed it has its own mature handling, and dare not to touch it in this patchset :)
Thanks,
Feng
Quoted 27 lines
Quoted 3 lines
Finally, I wonder whether
ftrace_dump()might cause a livelock when ftrace is adding new messages in parallel.It definitely can cause problems, and me learning this the hard way is why rcutorture calls
tracing_off()before callingftrace_dump().Quoted 6 lines
The situation is much easier during
panic()because the system is going todie()anyway, non-panic CPUs are stopped, ...That said, I could understand that people might want to see as much information as possible when the console is fast and the range of possible problems is big.
No argument here.
Thanx, Paul
Quoted 9 lines
Anyway, I have added few more people into Cc who are interested into the various watchdogs.
And there is parallel initiative which tries to unify the loglevel or somehow make the filtering easier, see
https://lore.kernel.org/r/[email protected]Best Regards,
Petr
Quoted 86 lines · Feng Tang
Quoted 85 lines · Paul E. McKenney
Quoted 71 lines · Petr Mladek
Quoted 46 lines · Lance Yang
Quoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.Quoted 6 lines
Something like:
If
SYS_PRINT_ALL_CPU_BT(global knob) is on, it enableshung_task_all_cpu_backtrace
for hung-task situation automatically. But users can still disable it viahung_task_all_cpu_backtrace.I am all for unifying the options for printing debug information in various emergency situations. I am just not sure whether we really want to do the same in all situations.
Some lockup detectors tries to be more clever, for example:
+ RCU stall detector prints backtraces only from CPUs which are involved in the stall, see
print_other_cpu_stall().+ Workqueues watchdog shows backtraces from tasks which are preventing forward progress, see
show_cpu_pool_hog().And stalls are about scheduling (disabled preemption, disabled IRQ, deadlocks, too long uninterruptible sleep). OOM is about memory usage. Oops is about an invalid memory access.
WARNs()are completely random stuff.Quoted 4 lines
Also I am afraid of printing too much information when the system is supposed to continue running. It would make sense to print it in nbcon_cpu_emergency_enter()/exit() context which disables preemption. And it might cause softlockups on its own.
And we did do some of the cleverness that Petr points out because of problems caused by flooding the console log. We first ran into this sort of thing on embedded systems with slow serial consoles (where 115K baud is now way slow), but it also shows up in other environments, for example, those committing large numbers of console logs to stable storage, multiplexing large numbers of logs across networks that sometimes get congested, and so on.
Quoted 7 lines
Quoted 2 lines
So I second the call for individual knobs, either in addition to or instead of the global knob.
Thanks for the detail elaboration! RCU stall case is also a main target in the stability issues I have worked on, besides panic/taskhung/lockup. I noticed it has its own mature handling, and dare not to touch it in this patchset :)
Uhhh...
Please do dare to touch it, as that is the only way that it can possibly improve. Just please also be very careful *how* you touch it. ;-)
Thanx, Paul
Quoted 30 lines
Thanks,
FengQuoted 27 lines
Quoted 3 lines
Finally, I wonder whether
ftrace_dump()might cause a livelock when ftrace is adding new messages in parallel.It definitely can cause problems, and me learning this the hard way is why rcutorture calls
tracing_off()before callingftrace_dump().Quoted 6 lines
The situation is much easier during
panic()because the system is going todie()anyway, non-panic CPUs are stopped, ...That said, I could understand that people might want to see as much information as possible when the console is fast and the range of possible problems is big.
No argument here.
Thanx, Paul
Quoted 9 lines
Anyway, I have added few more people into Cc who are interested into the various watchdogs.
And there is parallel initiative which tries to unify the loglevel or somehow make the filtering easier, see
https://lore.kernel.org/r/[email protected]Best Regards,
Petr
Quoted 49 lines · Petr Mladek
Quoted 48 lines · Lance Yang
Quoted 29 lines · Feng Tang
Hi Andrew,
Thanks for the review!
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Sun, 11 May 2025 16:52:51 +0800 Feng Tang <[email protected]>…
When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.
panic case already has
panic_print_sys_info()for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.Quoted 5 lines
So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.
Locally these have been used in our bug chasing for stablility issues and was helpful.
Truth. Our responses to panics, oopses, WARNs, BUGs, OOMs etc seem quite poorly organized. Some effort to clean up (and document!) all of this sounds good.
My vote is to permit the display of every scrap of information we can think of in all situations. And then to permit users to select which of that information is to be displayed under each situation.
Completely agreed. The tricky part is making a global knob that works for all situations without breaking userspace, but it's a better system-wide approach ;)
Quoted 4 lines
Good point! Maybe one future todo is to add a gloabl system info dump function with ONE global knob for selecting different kinds of information, which could be embedded into some cases you mentioned above.
IMHO, for features with their own knobs, we need:
a) The global knob (if enabled) turns on all related feature-level knobs,
b) while still allowing users to manually override individual knobs.Something like:
Quoted 8 lines
Quoted 4 lines
If
SYS_PRINT_ALL_CPU_BT(global knob) is on, it enableshung_task_all_cpu_backtrace
for hung-task situation automatically. But users can still disable it viahung_task_all_cpu_backtrace.I am all for unifying the options for printing debug information in various emergency situations. I am just not sure whether we really want to do the same in all situations.
Yes, valid concern.
Quoted 5 lines
Some lockup detectors tries to be more clever, for example:
+ RCU stall detector prints backtraces only from CPUs which are involved in the stall, see
print_other_cpu_stall().
Quoted 7 lines
+ Workqueues watchdog shows backtraces from tasks which are preventing forward progress, see
show_cpu_pool_hog().And stalls are about scheduling (disabled preemption, disabled IRQ, deadlocks, too long uninterruptible sleep). OOM is about memory usage. Oops is about an invalid memory access.
WARNs()are completely random stuff.
Agreed. I noticed RCU has special handling and I skipped "RCU stall" case in this patchset on purpose :)
Quoted 4 lines
Also I am afraid of printing too much information when the system is supposed to continue running. It would make sense to print it in nbcon_cpu_emergency_enter()/exit() context which disables preemption. And it might cause softlockups on its own.
Yes. And for the global knob, my thought is it's 0 (disabled) by default, which equals doing nothing. And its user should be experienced developers who knows precisely what information they need, and set it runtime or by kernel command line.
For 'panic_print' which we used frequently in bug chasing, we still let it be 0 even in our debug version kernel, and only enable it in debugging.
As for the patch set, I tried to not change existing behavior, and just added option for user to get more info when needed.
Quoted 2 lines
Finally, I wonder whether
ftrace_dump()might cause a livelock when ftrace is adding new messages in parallel.
IIUC, ftrace_dump_one() will turn off the tracing during dump, and should be safe.
Quoted 2 lines
The situation is much easier during
panic()because the system is going todie()anyway, non-panic CPUs are stopped, ...
Yes.
Quoted 3 lines
That said, I could understand that people might want to see as much information as possible when the console is fast and the range of possible problems is big.
I agree with you that more is not always better, it should be based on real needs, case by case.
Quoted 6 lines
Anyway, I have added few more people into Cc who are interested into the various watchdogs.
And there is parallel initiative which tries to unify the loglevel or somehow make the filtering easier, see
https://lore.kernel.org/r/[email protected]
Thanks for involving more people and sharing the link.
Thanks,
Feng
Quoted 2 lines
Best Regards,
Petr