[PATCH V2 4/5] panic: add 'panic_sys_info=' setup option for sysctl and kernel cmdline

Feng Tang posted 5 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH V2 4/5] panic: add 'panic_sys_info=' setup option for sysctl and kernel cmdline
Posted by Feng Tang 3 months, 3 weeks ago
Add 'panic_sys_info=' setup which expects string like "tasks,mem,lock,...".
It supports both runtime sysctl control and boot time kernel cmdline setup,
and could be seen as human readable string version of 'panic_print'.

The detail mapping is:
	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"

Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
---
 .../admin-guide/kernel-parameters.txt          | 13 +++++++++++++
 Documentation/admin-guide/sysctl/kernel.rst    | 18 ++++++++++++++++++
 kernel/panic.c                                 | 16 ++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index f1f2c0874da9..d714a0ebf909 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4541,6 +4541,19 @@
 			Use this option carefully, maybe worth to setup a
 			bigger log buffer with "log_buf_len" along with this.
 
+	panic_sys_info=
+			String of subsystem info to be dumped on panic.
+			It expects string of comma-separated words like
+			"tasks,mem,timer,...", which is a human readable string
+			version of 'panic_print':
+			tasks: print all tasks info
+			mem: print system memory info
+			timer: print timer info
+			lock: print locks info if CONFIG_LOCKDEP is on
+			ftrace: print ftrace buffer
+			all_bt: print all CPUs backtrace (if available in the arch)
+			blocked_tasks: print only tasks in uninterruptible (blocked) state
+
 	parkbd.port=	[HW] Parallel port number the keyboard adapter is
 			connected to, default is 0.
 			Format: <parport#>
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index dd49a89a62d3..2013afd98605 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -899,6 +899,24 @@ So for example to print tasks and memory info on panic, user can::
   echo 3 > /proc/sys/kernel/panic_print
 
 
+panic_sys_info
+==============
+
+String of subsystem info to be dumped on panic. It expects string of
+comma-separated words like "tasks,mem,timer,...", which is a human
+readable string version of 'panic_print':
+
+=============   ===================================================
+tasks           print all tasks info
+mem             print system memory info
+timer           print timer info
+lock            print locks info if CONFIG_LOCKDEP is on
+ftrace          print ftrace buffer
+all_bt          print all CPUs backtrace (if available in the arch)
+blocked_tasks   print only tasks in uninterruptible (blocked) state
+=============   ===================================================
+
+
 panic_on_rcu_stall
 ==================
 
diff --git a/kernel/panic.c b/kernel/panic.c
index 35c98aefa39f..ea238f7d4b54 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -125,6 +125,13 @@ static const struct ctl_table kern_panic_table[] = {
 		.mode           = 0644,
 		.proc_handler   = proc_douintvec,
 	},
+	{
+		.procname	= "panic_sys_info",
+		.data		= &panic_print,
+		.maxlen         = sizeof(panic_print),
+		.mode		= 0644,
+		.proc_handler	= sysctl_sys_info_handler,
+	},
 };
 
 static __init int kernel_panic_sysctls_init(void)
@@ -135,6 +142,15 @@ static __init int kernel_panic_sysctls_init(void)
 late_initcall(kernel_panic_sysctls_init);
 #endif
 
+/* The format is "panic_sys_info=task,mem,ftrace,..." */
+static int __init setup_panic_sys_info(char *buf)
+{
+	/* There is no risk of race in kernel boot phase */
+	panic_print = sys_info_parse_param(buf);
+	return 1;
+}
+__setup("panic_sys_info=", setup_panic_sys_info);
+
 static atomic_t warn_count = ATOMIC_INIT(0);
 
 #ifdef CONFIG_SYSFS
-- 
2.39.5 (Apple Git-154)
Re: [PATCH V2 4/5] panic: add 'panic_sys_info=' setup option for sysctl and kernel cmdline
Posted by Petr Mladek 3 months, 2 weeks ago
On Mon 2025-06-16 09:08:39, Feng Tang wrote:
> Add 'panic_sys_info=' setup which expects string like "tasks,mem,lock,...".

This patch actually adds also the sysctl interface. It should be
mentioned in the "Subject" and here.

That said, it might be better to add the sysctl interface in
the previous patch and add just the setup() here.

> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -4541,6 +4541,19 @@
>  			Use this option carefully, maybe worth to setup a
>  			bigger log buffer with "log_buf_len" along with this.
>  
> +	panic_sys_info=


> +			String of subsystem info to be dumped on panic.

I am not a native speaker but I have troubles to parse the above
sentence. See below.

> +			It expects string of comma-separated words like
> +			"tasks,mem,timer,...", which is a human readable string
> +			version of 'panic_print':
> +			tasks: print all tasks info
> +			mem: print system memory info
> +			timer: print timer info
> +			lock: print locks info if CONFIG_LOCKDEP is on
> +			ftrace: print ftrace buffer
> +			all_bt: print all CPUs backtrace (if available in the arch)
> +			blocked_tasks: print only tasks in uninterruptible (blocked) state

This blob is hard to parse. I suggest to replace it with something
like:

<proposal>
	panic_sys_info= A comma separated list of extra information to be dumped
			on panic.
			Format: val[,val...]
			Where @val can be any of the following:

			tasks:		print all tasks info
			mem:		print system memory info
			timers:		print timers info
			locks:		print locks info if CONFIG_LOCKDEP is on
			ftrace:		print ftrace buffer
			all_bt:		print all CPUs backtrace (if available in the arch)
			blocked_tasks:	print only tasks in uninterruptible (blocked) state

			This is a human readable alternative to the 'panic_print' option.
</proposal>

> +
>  	parkbd.port=	[HW] Parallel port number the keyboard adapter is
>  			connected to, default is 0.
>  			Format: <parport#>
> diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
> index dd49a89a62d3..2013afd98605 100644
> --- a/Documentation/admin-guide/sysctl/kernel.rst
> +++ b/Documentation/admin-guide/sysctl/kernel.rst
> @@ -899,6 +899,24 @@ So for example to print tasks and memory info on panic, user can::
>    echo 3 > /proc/sys/kernel/panic_print
>  
>  
> +panic_sys_info
> +==============
> +
> +String of subsystem info to be dumped on panic. It expects string of

Same here.

> +comma-separated words like "tasks,mem,timer,...", which is a human
> +readable string version of 'panic_print':

I would replace it with:

<proposal>
A comma separated list of extra information to be dumped on panic,
for example, "tasks,mem,timers,...".  It is a human readable alternative
to 'panic_print'. Possible values are:
</proposal>

> +
> +=============   ===================================================
> +tasks           print all tasks info
> +mem             print system memory info
> +timer           print timer info
> +lock            print locks info if CONFIG_LOCKDEP is on
> +ftrace          print ftrace buffer
> +all_bt          print all CPUs backtrace (if available in the arch)
> +blocked_tasks   print only tasks in uninterruptible (blocked) state
> +=============   ===================================================
> +
> +
>  panic_on_rcu_stall
>  ==================

The rest looks good.

Best Regards,
Petr
Re: [PATCH V2 4/5] panic: add 'panic_sys_info=' setup option for sysctl and kernel cmdline
Posted by Feng Tang 3 months, 2 weeks ago
On Mon, Jun 23, 2025 at 05:04:46PM +0200, Petr Mladek wrote:
> On Mon 2025-06-16 09:08:39, Feng Tang wrote:
> > Add 'panic_sys_info=' setup which expects string like "tasks,mem,lock,...".
> 
> This patch actually adds also the sysctl interface. It should be
> mentioned in the "Subject" and here.
 
I mentioned 'sysctl' in the subjec line, but maybe it's not obvious :)

> That said, it might be better to add the sysctl interface in
> the previous patch and add just the setup() here.

OK.

> 
> > --- a/Documentation/admin-guide/kernel-parameters.txt
> > +++ b/Documentation/admin-guide/kernel-parameters.txt
> > @@ -4541,6 +4541,19 @@
> >  			Use this option carefully, maybe worth to setup a
> >  			bigger log buffer with "log_buf_len" along with this.
> >  
> > +	panic_sys_info=
> 
> 
> > +			String of subsystem info to be dumped on panic.
> 
> I am not a native speaker but I have troubles to parse the above
> sentence. See below.
> > +			It expects string of comma-separated words like
> > +			"tasks,mem,timer,...", which is a human readable string
> > +			version of 'panic_print':
> > +			tasks: print all tasks info
> > +			mem: print system memory info
> > +			timer: print timer info
> > +			lock: print locks info if CONFIG_LOCKDEP is on
> > +			ftrace: print ftrace buffer
> > +			all_bt: print all CPUs backtrace (if available in the arch)
> > +			blocked_tasks: print only tasks in uninterruptible (blocked) state
> 
> This blob is hard to parse. I suggest to replace it with something
> like:
> 
> <proposal>
> 	panic_sys_info= A comma separated list of extra information to be dumped
> 			on panic.
> 			Format: val[,val...]
> 			Where @val can be any of the following:
> 
> 			tasks:		print all tasks info
> 			mem:		print system memory info
> 			timers:		print timers info
> 			locks:		print locks info if CONFIG_LOCKDEP is on
> 			ftrace:		print ftrace buffer
> 			all_bt:		print all CPUs backtrace (if available in the arch)
> 			blocked_tasks:	print only tasks in uninterruptible (blocked) state
> 
> 			This is a human readable alternative to the 'panic_print' option.
> </proposal>

Thanks! It's much better.

> > +
> >  	parkbd.port=	[HW] Parallel port number the keyboard adapter is
> >  			connected to, default is 0.
> >  			Format: <parport#>
> > diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
> > index dd49a89a62d3..2013afd98605 100644
> > --- a/Documentation/admin-guide/sysctl/kernel.rst
> > +++ b/Documentation/admin-guide/sysctl/kernel.rst
> > @@ -899,6 +899,24 @@ So for example to print tasks and memory info on panic, user can::
> >    echo 3 > /proc/sys/kernel/panic_print
> >  
> >  
> > +panic_sys_info
> > +==============
> > +
> > +String of subsystem info to be dumped on panic. It expects string of
> 
> Same here.
> 
> > +comma-separated words like "tasks,mem,timer,...", which is a human
> > +readable string version of 'panic_print':
> 
> I would replace it with:
> 
> <proposal>
> A comma separated list of extra information to be dumped on panic,
> for example, "tasks,mem,timers,...".  It is a human readable alternative
> to 'panic_print'. Possible values are:
> </proposal>

Will change.

> > +
> > +=============   ===================================================
> > +tasks           print all tasks info
> > +mem             print system memory info
> > +timer           print timer info
> > +lock            print locks info if CONFIG_LOCKDEP is on
> > +ftrace          print ftrace buffer
> > +all_bt          print all CPUs backtrace (if available in the arch)
> > +blocked_tasks   print only tasks in uninterruptible (blocked) state
> > +=============   ===================================================
> > +
> > +
> >  panic_on_rcu_stall
> >  ==================
> 
> The rest looks good.
 
Thanks!

- Feng

> Best Regards,
> Petr