From nobody Wed Oct 8 02:02:20 2025 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 8EAC5189F3B for ; Thu, 3 Jul 2025 02:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508619; cv=none; b=ukxwOStGaOpG6w/WNnZvRfGfCKKf//5P51MlJFvcgrNQdEiF287kKaLYscC+SkBrFHFS+JuEedJm3QG3nYnls5zyhjIEE8ZWMPDHYeV0i0AjI8YfM30DEnXnBJoot0vSQFjEdwxfxnRAASuzxywPSIc9rGREwg+kX5xqVT3wzak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508619; c=relaxed/simple; bh=I3KXST0xTf08Th70DnKWCRs5vARFt6elXYjog4TvP48=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HKjSouRGKWsovdaiQOVtzrApnbdFjETrKsF0tmMH8K/txFVv0iKm1AXd7BZy5xGpeMqKmRFvsi0yyBagR3ZmXqyRIbY9B+SG4IStfILCg4Y1bq0SA3zvGiYHwnUH411eY2w1duVVlx63t5QnCtuASI124t+GesUIwN5jgyAAIfg= 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=w92tkT8X; arc=none smtp.client-ip=115.124.30.113 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="w92tkT8X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751508607; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=WOLKp4Okgfsgx4gkUFe1bvBEcgsr4BZ1qlxKndLNm9U=; b=w92tkT8XimeedKmTre+g/T7lolxCNQ71kD22PK8J6r1UoUkajDcB7rmI+XoKmH/oq6PvxZud2yCoEh5S8qunFjg2B8IG80Jdal94LmAIOd0vUAB8yNUcHaDWqWhG9Rbe89f5RcXgYy8XqbGZecNl9p/XRcKGJbzxhDB+A3zv3zo= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WgqZ3d7_1751508606 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Jul 2025 10:10:06 +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 v3 1/5] panic: clean up code for console replay Date: Thu, 3 Jul 2025 10:10:00 +0800 Message-Id: <20250703021004.42328-2-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250703021004.42328-1-feng.tang@linux.alibaba.com> References: <20250703021004.42328-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 and rename 'PANIC_PRINT_ALL_PRINTK_MS= G' to 'PANIC_CONSOLE_REPLAY', to make the code straightforward. The related kernel document is also updated. Suggested-by: Petr Mladek Signed-off-by: Feng Tang Reviewed-by: Petr Mladek --- .../admin-guide/kernel-parameters.txt | 2 +- Documentation/admin-guide/sysctl/kernel.rst | 2 +- kernel/panic.c | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index f1f2c0874da9..abb2ade021ee 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4533,7 +4533,7 @@ bit 2: print timer info bit 3: print locks info if CONFIG_LOCKDEP is on bit 4: print ftrace buffer - bit 5: print all printk messages in buffer + bit 5: replay all messages on consoles at the end of panic bit 6: print all CPUs backtrace (if available in the arch) bit 7: print only tasks in uninterruptible (blocked) state *Be aware* that this option may print a _lot_ of lines, diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index dd49a89a62d3..0d08b7a2db2d 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -889,7 +889,7 @@ bit 1 print system memory info bit 2 print timer info bit 3 print locks info if ``CONFIG_LOCKDEP`` is on bit 4 print ftrace buffer -bit 5 print all printk messages in buffer +bit 5 replay all messages on consoles at the end of panic bit 6 print all CPUs backtrace (if available in the arch) bit 7 print only tasks in uninterruptible (blocked) state =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 diff --git a/kernel/panic.c b/kernel/panic.c index b0b9a8bf4560..9b6c5dc28a65 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(panic_timeout); #define PANIC_PRINT_TIMER_INFO 0x00000004 #define PANIC_PRINT_LOCK_INFO 0x00000008 #define PANIC_PRINT_FTRACE_INFO 0x00000010 -#define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020 +#define PANIC_CONSOLE_REPLAY 0x00000020 #define PANIC_PRINT_ALL_CPU_BT 0x00000040 #define PANIC_PRINT_BLOCKED_TASKS 0x00000080 unsigned long panic_print; @@ -238,14 +238,14 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); =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_CONSOLE_REPLAY) + 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.43.5 From nobody Wed Oct 8 02:02:20 2025 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (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 3D6981AA1DA for ; Thu, 3 Jul 2025 02:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508619; cv=none; b=BFrv2FTbPnvyjvKH6wGN/DyoeHAqSdHqvcYo6ua07d8A0Eii1YkjtjtOB5M91J0mBoSy2UyX8r+wj64WOnfj5cUe7l/MaI9C4Mga7zm079DLHEmZAFFM42v6soHsLTm2biGMlZp6P1dE9BgeXz6T91XwxXoR4FQwdK9hPRok+Po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508619; c=relaxed/simple; bh=i+ziQx0pFG5A9c4/LCh4XtC+9feRIAyIrN3K8zaQ9aI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Iwe8Z1dJic7lVhkihNbdFD5Nn7TTusAHmm+MrmTpPPWoLN3gOEBVpGgnzCKEmoW6Y935ZLxdwd62Zn3Gn/OXIU/6dgwYodQfm2ibE63t7sb53RTBKvizhAZUDOp8Lv99Rt87O754v4sZoF3mQT81R/t3edaa3rRzkzydIChXyH0= 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=oLbdpj7+; arc=none smtp.client-ip=115.124.30.98 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="oLbdpj7+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751508607; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=LpcRBrGxYBHD+m9doP1TXKIrI6hUfSgRBLsw1Ps2UbY=; b=oLbdpj7+ObOoxZMBBs/PrXjsBAlhZah6vOrd8++qb2UsjM72C/N43FMzthSdySPr/3Zl9pD0usVWKKnEhRHy2u6x0fm0+FxMPVUB83C9H9u0Q3KSQhE0j8ELP5a+xMsRiN6oL7FRs7k3+Sk6hSKsYF4sD8Rk6chIp53Jm6KugIM= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WgqQirJ_1751508606 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Jul 2025 10:10:07 +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 v3 2/5] panic: generalize panic_print's function to show sys info Date: Thu, 3 Jul 2025 10:10:01 +0800 Message-Id: <20250703021004.42328-3-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250703021004.42328-1-feng.tang@linux.alibaba.com> References: <20250703021004.42328-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. Actually this function could also be used to help debugging other cases like task-hung, soft/hard lockup, etc. where user may need the snapshot of system info at that time. Extract system info dump function related code from panic.c to separate file sys_info.[ch], for wider usage by other kernel parts for debugging. Also modify the macro names about singulars/plurals. Suggested-by: Petr Mladek Signed-off-by: Feng Tang Reviewed-by: Petr Mladek --- include/linux/sys_info.h | 20 ++++++++++++++++++++ kernel/panic.c | 36 ++++-------------------------------- lib/Makefile | 2 +- lib/sys_info.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 include/linux/sys_info.h create mode 100644 lib/sys_info.c diff --git a/include/linux/sys_info.h b/include/linux/sys_info.h new file mode 100644 index 000000000000..53b7e27dbf2a --- /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_INFO_PANIC_CONSOLE_REPLAY is for panic case only, as it needs speci= al + * handling which only fits panic case. + */ +#define SYS_INFO_TASKS 0x00000001 +#define SYS_INFO_MEM 0x00000002 +#define SYS_INFO_TIMERS 0x00000004 +#define SYS_INFO_LOCKS 0x00000008 +#define SYS_INFO_FTRACE 0x00000010 +#define SYS_INFO_PANIC_CONSOLE_REPLAY 0x00000020 +#define SYS_INFO_ALL_CPU_BT 0x00000040 +#define SYS_INFO_BLOCKED_TASKS 0x00000080 + +void sys_info(unsigned long si_mask); + +#endif /* _LINUX_SYS_INFO_H */ diff --git a/kernel/panic.c b/kernel/panic.c index 9b6c5dc28a65..cbb0681177b3 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include =20 @@ -69,14 +70,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_CONSOLE_REPLAY 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 +233,10 @@ EXPORT_SYMBOL(nmi_panic); =20 static void panic_console_replay(void) { - if (panic_print & PANIC_CONSOLE_REPLAY) + if (panic_print & SYS_INFO_PANIC_CONSOLE_REPLAY) 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 +257,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_INFO_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 +382,7 @@ void panic(const char *fmt, ...) */ atomic_notifier_call_chain(&panic_notifier_list, 0, buf); =20 - panic_print_sys_info(); + sys_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..53031e5cb98e --- /dev/null +++ b/lib/sys_info.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + +#include + +void sys_info(unsigned long si_mask) +{ + if (si_mask & SYS_INFO_TASKS) + show_state(); + + if (si_mask & SYS_INFO_MEM) + show_mem(); + + if (si_mask & SYS_INFO_TIMERS) + sysrq_timer_list_show(); + + if (si_mask & SYS_INFO_LOCKS) + debug_show_all_locks(); + + if (si_mask & SYS_INFO_FTRACE) + ftrace_dump(DUMP_ALL); + + if (si_mask & SYS_INFO_ALL_CPU_BT) + trigger_all_cpu_backtrace(); + + if (si_mask & SYS_INFO_BLOCKED_TASKS) + show_state_filter(TASK_UNINTERRUPTIBLE); +} --=20 2.43.5 From nobody Wed Oct 8 02:02:20 2025 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 2332F19D09C for ; Thu, 3 Jul 2025 02:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508618; cv=none; b=gIN7GrFhQWLgIX0w+jTzadbmx39jO3plp2PB2oE8MwjDNaicao8FHFGCf8RDCSLNtw3LVtkEoegKkdjP0GlQOylX8n9tXHG/eV5Vwk+YH2s34UuiwcrHK9ESGfzBntT9Y27s7MjjELIgKBm6miGtKSFNFEm15FG6hnsyy3LhZwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508618; c=relaxed/simple; bh=AGyT1RGyUGIEDOqh41DYk3aIyMYjDi2PZShTjHoY6NE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UKn0Ls21PGLstDD65xou5R9tlBAjVwV8+dAdUroi2LA/RQYv49idVf9x/xQDIIJD/9cgrCTaZY5dtzoTuAzQH0VpkqjA0lJunONF6G5yjLr6KxKyhHLjex6SEHPi2YPkOQicl/9ELGfA9A7zxMR6W+n6PvIHBgsQMo/ok+Hm0HM= 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=xM6NQciA; arc=none smtp.client-ip=115.124.30.132 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="xM6NQciA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751508608; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=8jmzkVzSVkX+vDy5tamYP6AxVr7STdICWiyCDu8ltf8=; b=xM6NQciA0Jvl9zqGWkrsSHzQNwjSb4IkMjcSYcR+hotj5MZ2pYgyaZA1mSFBtWykOgdHPWf3yLi5M2XOq50mDbJKbXrZjREy970RYXNmS/YyIDewYiE3TsmotpXnha2Vaw8pXUzxbaS/5mbWRhhukHWAUkC+qyijk0gnn3IXoVc= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WgqUuD7_1751508607 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Jul 2025 10:10:07 +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 3/5] panic: add 'panic_sys_info' sysctl to take human readable string parameter Date: Thu, 3 Jul 2025 10:10:02 +0800 Message-Id: <20250703021004.42328-4-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250703021004.42328-1-feng.tang@linux.alibaba.com> References: <20250703021004.42328-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 for 'panic_print' is hard to remember and decode. Add 'panic_sys_info=3D'sysctl to take human readable string like "tasks,mem,timers,locks,ftrace,..." and translate it into bitmap. The detailed mapping is: SYS_INFO_TASKS "tasks" SYS_INFO_MEM "mem" SYS_INFO_TIMERS "timers" SYS_INFO_LOCKS "locks" SYS_INFO_FTRACE "ftrace" SYS_INFO_ALL_CPU_BT "all_bt" SYS_INFO_BLOCKED_TASKS "blocked_tasks" Suggested-by: Petr Mladek Signed-off-by: Feng Tang --- Documentation/admin-guide/sysctl/kernel.rst | 18 +++++ include/linux/sys_info.h | 8 ++ kernel/panic.c | 7 ++ lib/sys_info.c | 90 +++++++++++++++++++++ 4 files changed, 123 insertions(+) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 0d08b7a2db2d..cccb06d1a6bf 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 + +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: + +=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 timers 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/include/linux/sys_info.h b/include/linux/sys_info.h index 53b7e27dbf2a..89d77dc4f2ed 100644 --- a/include/linux/sys_info.h +++ b/include/linux/sys_info.h @@ -2,6 +2,8 @@ #ifndef _LINUX_SYS_INFO_H #define _LINUX_SYS_INFO_H =20 +#include + /* * SYS_INFO_PANIC_CONSOLE_REPLAY is for panic case only, as it needs speci= al * handling which only fits panic case. @@ -16,5 +18,11 @@ #define SYS_INFO_BLOCKED_TASKS 0x00000080 =20 void sys_info(unsigned long si_mask); +unsigned long sys_info_parse_param(char *str); =20 +#ifdef CONFIG_SYSCTL +int sysctl_sys_info_handler(const struct ctl_table *ro_table, int write, + void *buffer, size_t *lenp, + loff_t *ppos); +#endif #endif /* _LINUX_SYS_INFO_H */ diff --git a/kernel/panic.c b/kernel/panic.c index cbb0681177b3..d7aa427dc23c 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -126,6 +126,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) diff --git a/lib/sys_info.c b/lib/sys_info.c index 53031e5cb98e..46d6f4f1ad2a 100644 --- a/lib/sys_info.c +++ b/lib/sys_info.c @@ -3,10 +3,100 @@ #include #include #include +#include #include =20 #include =20 +struct sys_info_name { + unsigned long bit; + const char *name; +}; + +/* + * When 'si_names' gets updated, please make sure the 'sys_info_avail' + * below is updated accordingly. + */ +static const struct sys_info_name si_names[] =3D { + { SYS_INFO_TASKS, "tasks" }, + { SYS_INFO_MEM, "mem" }, + { SYS_INFO_TIMERS, "timers" }, + { SYS_INFO_LOCKS, "locks" }, + { SYS_INFO_FTRACE, "ftrace" }, + { SYS_INFO_ALL_CPU_BT, "all_bt" }, + { SYS_INFO_BLOCKED_TASKS, "blocked_tasks" }, +}; + +/* Expecting string like "xxx_sys_info=3Dtasks,mem,timers,locks,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 + +static const char sys_info_avail[] =3D "tasks,mem,timers,locks,ftrace,all_= bt,blocked_tasks"; + +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; + + si_bits_global =3D ro_table->data; + + if (write) { + unsigned long si_bits; + int ret; + + 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 */ + char *delim =3D ""; + int i, len =3D 0; + + for (i =3D 0; i < ARRAY_SIZE(si_names); i++) { + if (*si_bits_global & si_names[i].bit) { + len +=3D scnprintf(names + len, sizeof(names) - len, + "%s%s", delim, si_names[i].name); + delim =3D ","; + } + } + + table =3D *ro_table; + table.data =3D names; + table.maxlen =3D sizeof(names); + return proc_dostring(&table, write, buffer, lenp, ppos); + } +} +#endif + void sys_info(unsigned long si_mask) { if (si_mask & SYS_INFO_TASKS) --=20 2.43.5 From nobody Wed Oct 8 02:02:20 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 63C261ADC65 for ; Thu, 3 Jul 2025 02:10:16 +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=1751508619; cv=none; b=NUcBURV5vPrz1ESqhOB9MH38kBW7Z0cZ7g3SbUDc03yFvqTKbnv13eO12hlW4/+EgTIYaVdd6GDzI21Hsq/C0DIDowi1GZxcYC6zTzP6rq1qFZN9TlOY7s0XruPZNBB+SCbJjXO6fyfwcpYq5lJSvXhvt5chwyCAhElUq2OFdiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508619; c=relaxed/simple; bh=tPii+pXoG0cERdcXuiTmHVS/vIx3hqlR1qO4qZI8Cgg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SRiqHTK1XmsfGIqSBW6Z7EDA3afbK+GMALs1DIid1gwF3X7rB5elkha+ekLtBONcWvSFbrvladUFK7T1g2y9sL9fdR6+LA5ynEVRzmymICPcFYNdWxpb/7CxmLmj+X6eQqeJFJL+Yc1oSB+e8Ur1PCen21xC8pDzGoCnAqj0+68= 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=tCDtNckC; 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="tCDtNckC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751508609; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=3wjCxcOLhf2OFMej0SFymeFA2froSrrQkmUHMvBDaRQ=; b=tCDtNckCQEk4IMUh/dIHev/GxWmslYQRoSbASRNBtddQ2ID+tM7vwQ4mpMEg6I2vbCZTT++rXnw2EE8kkznEAlJ3oPueEdTwk0KalXfqMfK+IKJwN00ROVvf6UDZMNVssakEXG2bDYjzQp7v0KRNzzYjBS8TlP5a/oW2UA3Lhww= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WgqZ3e._1751508608 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Jul 2025 10:10:08 +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 v3 4/5] panic: add 'panic_sys_info=' setup option for kernel cmdline Date: Thu, 3 Jul 2025 10:10:03 +0800 Message-Id: <20250703021004.42328-5-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250703021004.42328-1-feng.tang@linux.alibaba.com> References: <20250703021004.42328-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_sys_info=3D' sysctl interface is already added for runtime setting. Add counterpart kernel cmdline option for boottime setting. Suggested-by: Petr Mladek Signed-off-by: Feng Tang Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- Documentation/admin-guide/kernel-parameters.txt | 15 +++++++++++++++ kernel/panic.c | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index abb2ade021ee..39ddef7c5857 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4541,6 +4541,21 @@ Use this option carefully, maybe worth to setup a bigger log buffer with "log_buf_len" along with this. =20 + panic_sys_info=3D 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 avail= able in the arch) + blocked_tasks: print only tasks in uninterruptibl= e (blocked) state + + This is a human readable alternative to the 'panic= _print' option. + parkbd.port=3D [HW] Parallel port number the keyboard adapter is connected to, default is 0. Format: diff --git a/kernel/panic.c b/kernel/panic.c index d7aa427dc23c..d9d4fcd5e318 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -143,6 +143,15 @@ static __init int kernel_panic_sysctls_init(void) late_initcall(kernel_panic_sysctls_init); #endif =20 +/* The format is "panic_sys_info=3Dtasks,mem,locks,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.43.5 From nobody Wed Oct 8 02:02:20 2025 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 F00571AF0C1 for ; Thu, 3 Jul 2025 02:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508620; cv=none; b=MpMJ+eLJnflP+tR9r1kHaIIuX/sS5XTMXNvLxw+A6FsFlGu1gigqvo+Zty7i5p2MN/aUSmB9A8rZ31fIRWeKN7gIuI2XARUt1y52TpFI5TEb1oxaSeDWB7r3gFk2lmo6kaCePpFhgM2A73mlS8IiZIOsDdNtHP8CA4iKPiwD5hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751508620; c=relaxed/simple; bh=PrbpDPIGwbVnLN+XYaYPxiEMUbBiLtTOwlu9YoQVYDc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ig3ReYNo3d0DCXPRsiU8bTBxXqx8yoaWyYm+FMlSd4wlRSQE3HN5V5AM6oRqswEDZj+JEmrt6taqfSl8DJBW+/xRQHTQosXtRLxY0t9iMOOeZN20eIpLUFQIDw9yhfqJmAwMvTHw0ku6zFFOmVYm+FAwQqzG6sV7i6QH6cy8l+0= 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=QEZcP9KC; arc=none smtp.client-ip=115.124.30.113 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="QEZcP9KC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751508610; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=sCxjicG5r3fkQxnVPRBp7xHrgO61Yw1xC3KdXRbaghg=; b=QEZcP9KCuneqETxHwWmpXTUd2so8WPsozc6pp/BuVdoW6VKIDlsrUrPuptwQWPGvh1xSWGYWHTXLzLh7kL5F0N4FhfXjsx+kLUg8zkryFAbN63GeY4mGndjCkWBr/UsTxggFz4pFZ3i7bDE/59CrjEfTHu0vtn1Y951si8ZPEPc= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WgqQisY_1751508608 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Jul 2025 10:10:09 +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 v3 5/5] panic: add note that panic_print sysctl interface is deprecated Date: Thu, 3 Jul 2025 10:10:04 +0800 Message-Id: <20250703021004.42328-6-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250703021004.42328-1-feng.tang@linux.alibaba.com> References: <20250703021004.42328-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 a dedicated core parameter 'panic_console_replay' for controlling console replay, and add note that 'panic_print' sysctl interface will be obsoleted by 'panic_sys_info' and 'panic_console_replay'. When it happens, the SYS_INFO_PANIC_CONSOLE_REPLAY can be removed as well. Suggested-by: Petr Mladek Signed-off-by: Feng Tang --- .../admin-guide/kernel-parameters.txt | 4 ++++ kernel/panic.c | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 39ddef7c5857..f34de9978a91 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4556,6 +4556,10 @@ =20 This is a human readable alternative to the 'panic= _print' option. =20 + panic_console_replay + When panic happens, replay all kernel messages on + consoles at the end of panic. + parkbd.port=3D [HW] Parallel port number the keyboard adapter is connected to, default is 0. Format: diff --git a/kernel/panic.c b/kernel/panic.c index d9d4fcd5e318..bb16f254cd02 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -64,6 +64,7 @@ int panic_on_warn __read_mostly; unsigned long panic_on_taint; bool panic_on_taint_nousertaint =3D false; static unsigned int warn_limit __read_mostly; +static bool panic_console_replay; =20 bool panic_triggering_all_cpu_backtrace; =20 @@ -77,6 +78,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) +{ + pr_info_once("Kernel: 'panic_print' sysctl interface will be obsoleted by= both 'panic_sys_info' and 'panic_console_replay'\n"); + return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); +} + static const struct ctl_table kern_panic_table[] =3D { #ifdef CONFIG_SMP { @@ -108,7 +116,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", @@ -247,12 +255,6 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); =20 -static void panic_console_replay(void) -{ - if (panic_print & SYS_INFO_PANIC_CONSOLE_REPLAY) - console_flush_on_panic(CONSOLE_REPLAY_ALL); -} - void check_panic_on_warn(const char *origin) { unsigned int limit; @@ -427,7 +429,9 @@ void panic(const char *fmt, ...) debug_locks_off(); console_flush_on_panic(CONSOLE_FLUSH_PENDING); =20 - panic_console_replay(); + if ((panic_print & SYS_INFO_PANIC_CONSOLE_REPLAY) || + panic_console_replay) + console_flush_on_panic(CONSOLE_REPLAY_ALL); =20 if (!panic_blink) panic_blink =3D no_blink; @@ -869,6 +873,7 @@ core_param(panic_print, panic_print, ulong, 0644); core_param(pause_on_oops, pause_on_oops, int, 0644); core_param(panic_on_warn, panic_on_warn, int, 0644); core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0= 644); +core_param(panic_console_replay, panic_console_replay, bool, 0644); =20 static int __init oops_setup(char *s) { --=20 2.43.5