From nobody Fri Oct 10 04:08:12 2025 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C577D17BA5 for ; Mon, 16 Jun 2025 01:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036127; cv=none; b=dFMR2Yq0rUxk/wovsCnIBRl+TTVseEfB4zeLV3RJ9mXCeWBVBbv2Qt+0hx3AI61029gj8LlrzaJUAu6hM43NJ+Cd4fENHaEehI/ZXPifFQxBY9mwgUNmjoh52evsjVff2UICk8eA9hXE2NULDg7fkCvAQVjt7wcyl4QC5dy91ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036127; c=relaxed/simple; bh=Kj9loMjOceAfTvJkSvXiARKvoR/e9L3Fz3btdN/YJA0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H7MlNdi3RwDxtqKYrrSQ6qrDmWhW+Gok0CQlQYavFzTMCpP9dXxCKNjf7O35Pkn8BsZh0QyI1Eadn5s/n8mZ5Ag0MnL4TXLjX0CULu985jum7HJUJ5HhUHnDvjyuCCX3OdluSY9Bj76n1AyTHAlVmUy9ftIa0wztUT9fzGQmSyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=HKchmyPo; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="HKchmyPo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750036122; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=b7nsMWZwXRG7VGmZov0snPfqziKqK7Nrc8RStA8klUc=; b=HKchmyPoWqmwweG8/xe2Oz+sE1RLXlc3bohSAR8xBvgyxh6iSegNAMlALekfVDLpX7CUSC9UqjVrK2HYlWiB2bBzALmjgz3TPoGOlIAqk3woT1gYmz98D2ELEY6b57vCMP4oNQqvJC+XaVk4qJrNwcH7HrhSfDDzexXF3JjUPeM= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0Wdr3n8N_1750036121 cluster:ay36) by smtp.aliyun-inc.com; Mon, 16 Jun 2025 09:08:41 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Steven Rostedt , Lance Yang , Jonathan Corbet , linux-kernel@vger.kernel.org Cc: paulmck@kernel.org, john.ogness@linutronix.de, Feng Tang Subject: [PATCH V2 1/5] panic: clean up code for console replay Date: Mon, 16 Jun 2025 09:08:36 +0800 Message-Id: <20250616010840.38258-2-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250616010840.38258-1-feng.tang@linux.alibaba.com> References: <20250616010840.38258-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the panic_print_sys_info() was called twice with different parameters to handle console replay case, which is kind of confusing. Add panic_console_replay() explicitly to make the code straightforward. Suggested-by: Petr Mladek Signed-off-by: Feng Tang Reviewed-by: Petr Mladek --- kernel/panic.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/panic.c b/kernel/panic.c index b0b9a8bf4560..af0d5206a624 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -238,14 +238,14 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); =20 -static void panic_print_sys_info(bool console_flush) +static void panic_console_replay(void) { - if (console_flush) { - if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) - console_flush_on_panic(CONSOLE_REPLAY_ALL); - return; - } + if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) + console_flush_on_panic(CONSOLE_REPLAY_ALL); +} =20 +static void panic_print_sys_info(void) +{ if (panic_print & PANIC_PRINT_TASK_INFO) show_state(); =20 @@ -410,7 +410,7 @@ void panic(const char *fmt, ...) */ atomic_notifier_call_chain(&panic_notifier_list, 0, buf); =20 - panic_print_sys_info(false); + panic_print_sys_info(); =20 kmsg_dump_desc(KMSG_DUMP_PANIC, buf); =20 @@ -439,7 +439,7 @@ void panic(const char *fmt, ...) debug_locks_off(); console_flush_on_panic(CONSOLE_FLUSH_PENDING); =20 - panic_print_sys_info(true); + panic_console_replay(); =20 if (!panic_blink) panic_blink =3D no_blink; --=20 2.39.5 (Apple Git-154) From nobody Fri Oct 10 04:08:12 2025 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44FEB18DB01 for ; Mon, 16 Jun 2025 01:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036133; cv=none; b=jfYvxqVZ6eKIvSlutRM/zxwvNzL8v5YSjam0alCkavQsCM9rmOyAhNN2+krlIcFPJtuFC/ra692iMoFIDyCH2bkdBKQlTAd6L0mgTN4gT29p6opeqCGJMHrrD6ndwY3bw3w/6SPRSvUnqp+/7kwY5n16zjI8NtCrsWqaQfCu00E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036133; c=relaxed/simple; bh=xPkpImzhx1jRra9PFkx7m1hA215DTG/U0AmmeWZrI5Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cFPKDoZW5MY6S/vHbgb/xQ1OBioKDrceUzAqNxC3GoMLUHD2CBhEoWgM6XdQ3lCQifBf+JYqYHylw1IuZO65Q72P/0nc6jE2NML+DwtqdJFINrfDwBIIRDXT+fXvV07IgtnIcCqVQpHsvhL/zJHWnt3INMw2Is1341Yhat4wd8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=PHSK/D5q; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="PHSK/D5q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750036122; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=l9D6CkJA8XX+bAui6HLlqouzyt9/aXPsK5IASOTxZyU=; b=PHSK/D5qrKX89yOmM7SKak0Alp7434ZsY2w56X6fdsAxt2zwDcb7uYtt+3o266e3mDgDb7gE6VIdH8FdXHxhkevMI3fdg0uTpvAFSaXqA9f7jP8vtKuHT3nCqaLas/MsLoT80bIZdRzwOMubA35uUAxQjD8sgaANCT8k4lGeAzY= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0Wdr3n8c_1750036121 cluster:ay36) by smtp.aliyun-inc.com; Mon, 16 Jun 2025 09:08:42 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Steven Rostedt , Lance Yang , Jonathan Corbet , linux-kernel@vger.kernel.org Cc: paulmck@kernel.org, john.ogness@linutronix.de, Feng Tang Subject: [PATCH V2 2/5] panic: generalize panic_print's function to show sys info Date: Mon, 16 Jun 2025 09:08:37 +0800 Message-Id: <20250616010840.38258-3-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250616010840.38258-1-feng.tang@linux.alibaba.com> References: <20250616010840.38258-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" '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 also help debugging cases like task-hung, soft/hard lockup, and other cases , where user may need the snapshot of system info at that time. Extract sys_show_info() function out of panic code to be used by other kernel parts for debugging. Suggested-by: Petr Mladek Signed-off-by: Feng Tang --- include/linux/kernel.h | 1 + include/linux/sys_info.h | 20 ++++++++++++++++++++ kernel/panic.c | 35 +++-------------------------------- lib/Makefile | 2 +- lib/sys_info.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 include/linux/sys_info.h create mode 100644 lib/sys_info.c diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 1cce1f6410a9..4788c0e4a8bd 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/sys_info.h b/include/linux/sys_info.h new file mode 100644 index 000000000000..79bf4a942e5f --- /dev/null +++ b/include/linux/sys_info.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_SYS_INFO_H +#define _LINUX_SYS_INFO_H + +/* + * SYS_SHOW_ALL_PRINTK_MSG is for panic case only, as it needs special + * handling which only fits panic case. + */ +#define SYS_SHOW_TASK_INFO 0x00000001 +#define SYS_SHOW_MEM_INFO 0x00000002 +#define SYS_SHOW_TIMER_INFO 0x00000004 +#define SYS_SHOW_LOCK_INFO 0x00000008 +#define SYS_SHOW_FTRACE_INFO 0x00000010 +#define SYS_SHOW_ALL_PRINTK_MSG 0x00000020 +#define SYS_SHOW_ALL_CPU_BT 0x00000040 +#define SYS_SHOW_BLOCKED_TASKS 0x00000080 + +extern void sys_show_info(unsigned long info_mask); + +#endif /* _LINUX_SYS_INFO_H */ diff --git a/kernel/panic.c b/kernel/panic.c index af0d5206a624..35c98aefa39f 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -69,14 +69,6 @@ bool panic_triggering_all_cpu_backtrace; int panic_timeout =3D CONFIG_PANIC_TIMEOUT; EXPORT_SYMBOL_GPL(panic_timeout); =20 -#define PANIC_PRINT_TASK_INFO 0x00000001 -#define PANIC_PRINT_MEM_INFO 0x00000002 -#define PANIC_PRINT_TIMER_INFO 0x00000004 -#define PANIC_PRINT_LOCK_INFO 0x00000008 -#define PANIC_PRINT_FTRACE_INFO 0x00000010 -#define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020 -#define PANIC_PRINT_ALL_CPU_BT 0x00000040 -#define PANIC_PRINT_BLOCKED_TASKS 0x00000080 unsigned long panic_print; =20 ATOMIC_NOTIFIER_HEAD(panic_notifier_list); @@ -240,31 +232,10 @@ EXPORT_SYMBOL(nmi_panic); =20 static void panic_console_replay(void) { - if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) + if (panic_print & SYS_SHOW_ALL_PRINTK_MSG) console_flush_on_panic(CONSOLE_REPLAY_ALL); } =20 -static void panic_print_sys_info(void) -{ - if (panic_print & PANIC_PRINT_TASK_INFO) - show_state(); - - if (panic_print & PANIC_PRINT_MEM_INFO) - show_mem(); - - if (panic_print & PANIC_PRINT_TIMER_INFO) - sysrq_timer_list_show(); - - if (panic_print & PANIC_PRINT_LOCK_INFO) - debug_show_all_locks(); - - if (panic_print & PANIC_PRINT_FTRACE_INFO) - ftrace_dump(DUMP_ALL); - - if (panic_print & PANIC_PRINT_BLOCKED_TASKS) - show_state_filter(TASK_UNINTERRUPTIBLE); -} - void check_panic_on_warn(const char *origin) { unsigned int limit; @@ -285,7 +256,7 @@ void check_panic_on_warn(const char *origin) */ static void panic_other_cpus_shutdown(bool crash_kexec) { - if (panic_print & PANIC_PRINT_ALL_CPU_BT) { + if (panic_print & SYS_SHOW_ALL_CPU_BT) { /* Temporary allow non-panic CPUs to write their backtraces. */ panic_triggering_all_cpu_backtrace =3D true; trigger_all_cpu_backtrace(); @@ -410,7 +381,7 @@ void panic(const char *fmt, ...) */ atomic_notifier_call_chain(&panic_notifier_list, 0, buf); =20 - panic_print_sys_info(); + sys_show_info(panic_print); =20 kmsg_dump_desc(KMSG_DUMP_PANIC, buf); =20 diff --git a/lib/Makefile b/lib/Makefile index c38582f187dd..88d6228089a8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -40,7 +40,7 @@ lib-y :=3D ctype.o string.o vsprintf.o cmdline.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ nmi_backtrace.o win_minmax.o memcat_p.o \ - buildid.o objpool.o iomem_copy.o + buildid.o objpool.o iomem_copy.o sys_info.o =20 lib-$(CONFIG_UNION_FIND) +=3D union_find.o lib-$(CONFIG_PRINTK) +=3D dump_stack.o diff --git a/lib/sys_info.c b/lib/sys_info.c new file mode 100644 index 000000000000..90a79b5164c9 --- /dev/null +++ b/lib/sys_info.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + +void sys_show_info(unsigned long info_flag) +{ + if (info_flag & SYS_SHOW_TASK_INFO) + show_state(); + + if (info_flag & SYS_SHOW_MEM_INFO) + show_mem(); + + if (info_flag & SYS_SHOW_TIMER_INFO) + sysrq_timer_list_show(); + + if (info_flag & SYS_SHOW_LOCK_INFO) + debug_show_all_locks(); + + if (info_flag & SYS_SHOW_FTRACE_INFO) + ftrace_dump(DUMP_ALL); + + if (info_flag & SYS_SHOW_ALL_CPU_BT) + trigger_all_cpu_backtrace(); + + if (info_flag & SYS_SHOW_BLOCKED_TASKS) + show_state_filter(TASK_UNINTERRUPTIBLE); +} --=20 2.39.5 (Apple Git-154) From nobody Fri Oct 10 04:08:12 2025 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0DDF23AD for ; Mon, 16 Jun 2025 01:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036133; cv=none; b=F/a/5pLn87uL8POB5IRv5FSDPgpohaejgTG1HLf07boOxwETX677nFERtKB1pBl9p5HFvWYDNE94uIGWBrrmo/2cSRd0xoreELVXRG2mq1kvQtF+1OVag39iagfpj0U/JZnJ6C+9tcwMM9fouzFiUU6++SKxJwYmNurAWIm0SDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036133; c=relaxed/simple; bh=abEiY5hBMI67CoNMXEMvgnnZK8G6qawPiVrmr/bLuG0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hOJlojOVMqh5Cznsb+wMY4ZZiTUnhlqVSLa9/hewIjYcMVBPE5G5hnY3rZkGr4UG0mRJ3Xfo4QQ4pW1QDNmonyLR3Od37ynRjVDh89421VrDzWZLuqWeR3o23v+ZgHeYy82gLAx7C2GywIQNXa3pyOcmDKKMWIgEpej8k/D2mG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=yL/oXijF; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="yL/oXijF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750036124; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=PLJj49F9PjWWVpiZxBe0LA+dLBqogOq9Z6+7w2bNWXk=; b=yL/oXijFpfOmhCbcDCAq8xYUSSrD81HZynudmaTSRMKtgSuK9kSuuaHNp8odsVvWwQUVBLJe9vDsooRH9PntuO9gTYZfvx2Wmoc0Ign236G1xFA3f765ANeh9oyusgk58dBFurGxDct1Ht/yrHnUbj/IS03TBHe4CRYb4hV47Ng= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WdqyMzW_1750036122 cluster:ay36) by smtp.aliyun-inc.com; Mon, 16 Jun 2025 09:08:42 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Steven Rostedt , Lance Yang , Jonathan Corbet , linux-kernel@vger.kernel.org Cc: paulmck@kernel.org, john.ogness@linutronix.de, Feng Tang Subject: [PATCH V2 3/5] sys_info: add help to translate sys_info string to bitmap Date: Mon, 16 Jun 2025 09:08:38 +0800 Message-Id: <20250616010840.38258-4-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250616010840.38258-1-feng.tang@linux.alibaba.com> References: <20250616010840.38258-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Bitmap definition is hard to remember and decode. Add sysctl interface to translate human readable string like "tasks,mem,timer,lock,ftrace,..." to bitmap. Suggested-by: Petr Mladek Signed-off-by: Feng Tang --- include/linux/sys_info.h | 7 +++ lib/sys_info.c | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/include/linux/sys_info.h b/include/linux/sys_info.h index 79bf4a942e5f..0b49863cd414 100644 --- a/include/linux/sys_info.h +++ b/include/linux/sys_info.h @@ -16,5 +16,12 @@ #define SYS_SHOW_BLOCKED_TASKS 0x00000080 =20 extern void sys_show_info(unsigned long info_mask); +extern unsigned long sys_info_parse_param(char *str); =20 +#ifdef CONFIG_SYSCTL +struct ctl_table; +extern int sysctl_sys_info_handler(const struct ctl_table *ro_table, int w= rite, + void *buffer, size_t *lenp, + loff_t *ppos); +#endif #endif /* _LINUX_SYS_INFO_H */ diff --git a/lib/sys_info.c b/lib/sys_info.c index 90a79b5164c9..9693542435ba 100644 --- a/lib/sys_info.c +++ b/lib/sys_info.c @@ -5,6 +5,103 @@ #include #include =20 +struct sys_info_name { + unsigned long bit; + const char *name; +}; + +static const char sys_info_avail[] =3D "tasks,mem,timer,lock,ftrace,all_bt= ,blocked_tasks"; + +static const struct sys_info_name si_names[] =3D { + { 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" }, +}; + +/* Expecting string like "xxx_sys_info=3Dtasks,mem,timer,lock,ftrace,..." = */ +unsigned long sys_info_parse_param(char *str) +{ + unsigned long si_bits =3D 0; + char *s, *name; + int i; + + s =3D str; + while ((name =3D strsep(&s, ",")) && *name) { + for (i =3D 0; i < ARRAY_SIZE(si_names); i++) { + if (!strcmp(name, si_names[i].name)) { + si_bits |=3D si_names[i].bit; + break; + } + } + } + + return si_bits; +} + +#ifdef CONFIG_SYSCTL +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]; + struct ctl_table table; + unsigned long *si_bits_global; + int i, ret, len; + + si_bits_global =3D ro_table->data; + + if (write) { + unsigned long si_bits; + + table =3D *ro_table; + table.data =3D names; + table.maxlen =3D sizeof(names); + ret =3D proc_dostring(&table, write, buffer, lenp, ppos); + if (ret) + return ret; + + si_bits =3D sys_info_parse_param(names); + /* + * The access to the global value is not synchronized. + */ + WRITE_ONCE(*si_bits_global, si_bits); + return 0; + } else { + /* for 'read' operation */ + bool first =3D true; + char *buf; + + buf =3D names; + for (i =3D 0; i < ARRAY_SIZE(si_names); i++) { + if (*si_bits_global & si_names[i].bit) { + + if (first) { + first =3D false; + } else { + *buf =3D ','; + buf++; + } + + len =3D strlen(si_names[i].name); + strncpy(buf, si_names[i].name, len); + buf +=3D len; + } + + } + *buf =3D '\0'; + + table =3D *ro_table; + table.data =3D names; + table.maxlen =3D sizeof(names); + return proc_dostring(&table, write, buffer, lenp, ppos); + } +} +#endif + void sys_show_info(unsigned long info_flag) { if (info_flag & SYS_SHOW_TASK_INFO) --=20 2.39.5 (Apple Git-154) From nobody Fri Oct 10 04:08:12 2025 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D83F417BA5 for ; Mon, 16 Jun 2025 01:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036134; cv=none; b=DNj2xiEvUbCEXlwFUPH+HsSqUiDqtAvXXIwXSC0tdmsbv/ei8jlEMTtREPA+xIrVI2+iJ2yoRT1LTJtianJqccz+vFTdH6PG93tfoJDZZ0CNXHkeorksMT3aRM+XanVUkQ4o8KZvHQddeIzYynaBQMSiFgRtvq8x2EJjysSKch8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036134; c=relaxed/simple; bh=aJiRQnuOhkLa7LiyyMk2v14H2mCJujdpRcITqvpIvqI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ecOYB7HAMSw8VTQMY5aguismw23JHAV1MMx/oavqcWO1Ri1wMe5s9KMCClVPAyvsw2HKzWRBhFf9Isng0nDIPb3q7SbkgzSY9IbHKMqJCUL2TtUfVOK3YoAW7JOWXs/vGBVa+NlT9vyWT0hiAItB8eFXFczvvYp4puc0kZqLWXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=gi7mAVBM; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="gi7mAVBM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750036124; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=M3lJK2qdxM3QqbG3JD1EivF32/aBG5sfk+PR7hs51W0=; b=gi7mAVBMq6CkoejO4q2D/p0iy/jiYBDXGYwYbJhJOERMCaE1xrIaqZ1TS549PiH1HyncC558tHjc8SYgBGUhRX3fE4I7sBvNXDvrzlfuLjUtt/hR0uJbgX0M96IyWJTkDA6t9wUpgsep8Lhu5JFB2/7a285I9L0i7CD2vM8MBOA= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0Wdr-a1H_1750036123 cluster:ay36) by smtp.aliyun-inc.com; Mon, 16 Jun 2025 09:08:43 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Steven Rostedt , Lance Yang , Jonathan Corbet , linux-kernel@vger.kernel.org Cc: paulmck@kernel.org, john.ogness@linutronix.de, Feng Tang Subject: [PATCH V2 4/5] panic: add 'panic_sys_info=' setup option for sysctl and kernel cmdline Date: Mon, 16 Jun 2025 09:08:39 +0800 Message-Id: <20250616010840.38258-5-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250616010840.38258-1-feng.tang@linux.alibaba.com> References: <20250616010840.38258-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add 'panic_sys_info=3D' 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 Signed-off-by: Feng Tang --- .../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/Documentatio= n/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. =20 + panic_sys_info=3D + 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=3D [HW] Parallel port number the keyboard adapter is connected to, default is 0. Format: diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-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 =20 =20 +panic_sys_info +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +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': + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +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 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + + panic_on_rcu_stall =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 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[] =3D { .mode =3D 0644, .proc_handler =3D proc_douintvec, }, + { + .procname =3D "panic_sys_info", + .data =3D &panic_print, + .maxlen =3D sizeof(panic_print), + .mode =3D 0644, + .proc_handler =3D sysctl_sys_info_handler, + }, }; =20 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 =20 +/* The format is "panic_sys_info=3Dtask,mem,ftrace,..." */ +static int __init setup_panic_sys_info(char *buf) +{ + /* There is no risk of race in kernel boot phase */ + panic_print =3D sys_info_parse_param(buf); + return 1; +} +__setup("panic_sys_info=3D", setup_panic_sys_info); + static atomic_t warn_count =3D ATOMIC_INIT(0); =20 #ifdef CONFIG_SYSFS --=20 2.39.5 (Apple Git-154) From nobody Fri Oct 10 04:08:12 2025 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1244D1A4E9D for ; Mon, 16 Jun 2025 01:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036136; cv=none; b=p1PTQZOpOyDzNHaGkpsrzaMc1kRB4iMD3muqUG6xo5jHv3ekwb6ub7uf3Vz3o0hFtmU61ZSXWjarwArLqMoh0YztFyJfcqSiIhuz18V0li1OT/udOeKoEVgQGDu4convSkBvjgHctj3RBV/9wSn3e4jut2IJQVXdmmEFljiBrCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750036136; c=relaxed/simple; bh=lTJPQgSUL+HA9iGN4smN0uaMAZJI9ZXb1POdzToXVqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YmY/btM71hNDlOspfhgNFfrmGWcKyr5h/XXmp8y2/wsVhQB0qFwSr1Ay6tMN8ISiakbMdCyG84dNuTdEhZ56DcOvhDHFwGqspSE42T8jH37OR4w2J2OQEW7jIFYxFYM/gxJ9BsNGLUv+SEdkHfuaIFSUOWMvT2hoDDGuFUnD8e0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=sMlr3T0+; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="sMlr3T0+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750036126; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=GW2zZxjWOUZ9IQnQWcV8PPRSVZvl4IdIaylUilpQWL4=; b=sMlr3T0+uTIgcHfBUSNmfqWx+eX3HeglpQ4Du91OVAVL773tkf1eWIMELOsIuMpkm/wqA5ZRzqgijAo/BdZAIcVPzdKLsenQXx5nWfe0O96J6VH9h/CbSjswdMwoLrBqT8A+O9noCeq7M2sC3wjCSXz1/FC7pA2JTLobCBSrCrA= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0Wdr-a1R_1750036123 cluster:ay36) by smtp.aliyun-inc.com; Mon, 16 Jun 2025 09:08:43 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Steven Rostedt , Lance Yang , Jonathan Corbet , linux-kernel@vger.kernel.org Cc: paulmck@kernel.org, john.ogness@linutronix.de, Feng Tang Subject: [PATCH V2 5/5] panic: add note that panic_print interface is deprecated Date: Mon, 16 Jun 2025 09:08:40 +0800 Message-Id: <20250616010840.38258-6-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250616010840.38258-1-feng.tang@linux.alibaba.com> References: <20250616010840.38258-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Long term wise, the 'panic_sys_info' should be the only controlling interface, which can be referred by other modules. Suggested-by: Petr Mladek Signed-off-by: Feng Tang --- kernel/panic.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/panic.c b/kernel/panic.c index ea238f7d4b54..e8a05fc6b733 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -76,6 +76,13 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list); EXPORT_SYMBOL(panic_notifier_list); =20 #ifdef CONFIG_SYSCTL +static int sysctl_panic_print_handler(const struct ctl_table *table, int w= rite, + void *buffer, size_t *lenp, loff_t *ppos) +{ + printk_once("panic: 'panic_print' sysctl interface will be obsoleted by '= panic_sys_info' interface.\n"); + return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); +} + static const struct ctl_table kern_panic_table[] =3D { #ifdef CONFIG_SMP { @@ -107,7 +114,7 @@ static const struct ctl_table kern_panic_table[] =3D { .data =3D &panic_print, .maxlen =3D sizeof(unsigned long), .mode =3D 0644, - .proc_handler =3D proc_doulongvec_minmax, + .proc_handler =3D sysctl_panic_print_handler, }, { .procname =3D "panic_on_warn", --=20 2.39.5 (Apple Git-154)