Introduce arch_do_panic
Subsystems (2)
v5 cover Introduce arch_do_panic
Changes in v5:
- Move s390 arch_do_panic() implementation to a more suitable file (Heiko Carstens)
Changes in v4:
- Remove s390 specific behavior changes and limit the series with cosmetic clean ups and introduction of arch_do_panic() (Heiko Carstens)
- Include linux/panic.h on files where arch_do_panic() is implemented (Sashiko)
- Remove extern "stop_a_enabled" definition from sparc's arch_do_panic() implementation as it is already visible by included asm/setup.h (Sashiko)
- Include "linux/printk.h" header on sparc/setup.c explicitly for pr_emerg() (Sashiko)
Changes in v3:
- Use __weak functions instead of symbol override via ifdef
- Patch 2: Better explain what is fixed (Bradley Morgan)
- Add statements about print order changes (Bradley Morgan)
- Patch 2: Add a pr_warn() to notify user about on_panic and panic_timeout relationship if they try to assign a trigger to on_panic action while panic_timeout is set to a value other than 0 (Bradley Morgan)
Changes in v2 - Address Sashiko findings;
- Patch 2: Remove unused leftover code
- Patch 2: Mention panic_timeout and shutdown_actions relationship for s390 in commit message
- Patch 3: Use bug.h instead of setup.h to pass around arch_do_panic implementation of sparc
A note before coverletter:
On earlier versions [1] I attempted to move s390s panic handler into arch_do_panic() but the interaction between panic handler and kernel's panic_timeout had become implicit and suboptimal. After reading Heiko's comments I have decided to tackle that in a separate series and keep this one limited to a smaller set of changes.
-------
Replace architecture-specific ifdef sections in vpanic() with a clean arch_do_panic() hook. Currently s390 and sparc embed their panic handlers directly in vpanic() using preprocessor conditionals, making the common code path harder to maintain.
Introduce arch_do_panic() as an architecture extension point called at the end of vpanic(). Architectures can use this hook to implement their specific panic handling without polluting the generic panic code.
Remove s390s ifdef block in vpanic() and move the corresponding code block to s390s own arch_do_panic() implementation in architecture specific code.
Move sparc panic handling from ifdef blocks to arch_do_panic(). Remove the preprocessor conditionals from vpanic() and place the Stop-A enablement code in architecture-specific files where it belongs. Stop-A enablement markers are now printed after "end Kernel panic" line. To me, there are no better alternatives other than setup.c to put sparc's arch_do_panic() implementation. The other files under arch/sparc/kernel are either divided to *_32.c and *_64.c variants, which mean code duplication, or unrelated.
The cleanup reduces vpanic() complexity and establishes a pattern for other architectures needing custom panic behavior.
No functional changes, only minor print order changes.
[1] https://lore.kernel.org/all/[email protected]/
---
Mete Durlu (3):
panic: Introduce arch_do_panic
s390: Implement arch_do_panic()
sparc: Implement arch_do_panic
arch/s390/kernel/traps.c | 7 +++++++ arch/sparc/kernel/setup.c | 9 +++++++++ include/linux/panic.h | 2 ++ kernel/panic.c | 15 +++------------ 4 files changed, 21 insertions(+), 12 deletions(-)
---
base-commit: 48a5a7ab8d6ab7090564339e039c421f315de912
change-id: 20260724-arch_do_panic-a97f699aa332
Best regards,
Signature · 1 line
Mete Durlu <[email protected]>
PATCH v5 1/3 panic: Introduce arch_do_panic
Introduce a hook for architectures to put their specific panic handlers. s390 and sparc already has ifdef preprocessor checks to execute architecture specific code. Pave the way for vpanic() cleanup.
--- include/linux/panic.h | 2 ++ kernel/panic.c | 3 +++ 2 files changed, 5 insertions(+)
include/linux/panic.h +2 -0
@@ -110,4 +110,6 @@ extern void add_taint(unsigned flag, enum lockdep_ok);extern int test_taint (unsigned flag);extern unsigned long get_taint (void ); +void arch_do_panic (void ); +#endif /* _LINUX_PANIC_H */
kernel/panic.c +3 -0
@@ -567,6 +567,8 @@ static void panic_other_cpus_shutdown(bool crash_kexec)crash_smp_send_stop (); } +void __weak arch_do_panic (void ) {} +/** * vpanic - halt the system * @fmt: The text string to print
@@ -756,6 +758,7 @@ void vpanic(const char *fmt, va_list args)#endif pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); +arch_do_panic ();/* Do not scroll important messages printed above */ suppress_printk =1 ;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 1/3] panic: Introduce arch_do_panic
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Introduce a hook for architectures to put their specific panic handlers. s390 and sparc already has ifdef preprocessor checks to execute architecture specific code. Pave the way for
vpanic()cleanup.Reviewed-by Bradley Morgan <[email protected]>Suggested-by Sven Schnelle <[email protected]>Signed-off-by Mete Durlu <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/3 s390: Implement arch_do_panic()
In reply to Mete DurluImplement s390 specific arch_do_panic() instead of using s390 specific ifdef sections in vpanic() code. disabled_wait() is now called after "end Kernel panic" marker.
No functional changes.
--- arch/s390/kernel/traps.c | 7 +++++++ kernel/panic.c | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-)
arch/s390/kernel/traps.c +7 -0
@@ -24,6 +24,7 @@#include <linux/entry-common.h> #include <linux/kmsan.h> #include <linux/bug.h> +#include <linux/panic.h> #include <asm/entry-percpu.h> #include <asm/asm-extable.h> #include <asm/irqflags.h>
@@ -31,6 +32,7 @@#include <asm/vtime.h> #include <asm/fpu.h> #include <asm/fault.h> +#include <asm/processor.h> #include "entry.h" static inline void __user *get_trap_ip (struct pt_regs *regs)
@@ -275,6 +277,11 @@ static void monitor_event_exception(struct pt_regs *regs) } } +void arch_do_panic (void ) +{ +disabled_wait (); +} +void kernel_stack_invalid (struct pt_regs *regs) {/*
kernel/panic.c +0 -3
@@ -752,9 +752,6 @@ void vpanic(const char *fmt, va_list args)pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" "twice on console to return to the boot prom\n"); } -#endif -#if defined(CONFIG_S390 ) -disabled_wait ();#endif pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 2/3] s390: Implement arch_do_panic()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly introduced `arch_do_panic()` hook is placed before the final console flushes, which…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly introduced arch_do_panic() hook is placed before the final console flushes, which causes the 'end Kernel panic' marker to remain unflushed in deferred printk contexts on s390. --
--- Patch [2]: [PATCH v5 2/3] s390: Implement arch_do_panic() --- commit b9b01d12abb499c817ce8c2a246d404e0331bf81
Author: Mete Durlu <[email protected]>
s390: Implement arch_do_panic()
This commit introduces a s390-specific arch_do_panic() implementation, removing an ifdef section from vpanic(). It moves the disabled_wait() call so it occurs after the "end Kernel panic" marker is printed.
Quoted 4 lines
arch/s390/kernel/traps.c +0
-0
[ ... ]
arch/s390/kernel/traps.c static void monitor_event_exception(struct pt_regs *regs) · line 284
Quoted 9 lines
arch/s390/kernel/traps.c +5
-0@@ -275,6 +277,11 @@ static void monitor_event_exception(struct pt_regs *regs) } } +void arch_do_panic (void ) +{ +disabled_wait (); +} +
[Severity: Medium]
Will this prevent the final console flushes from executing on s390?
Looking at vpanic() in kernel/panic.c, arch_do_panic() is called before the final console flushes:
pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
arch_do_panic();
/* Do not scroll important messages printed above */
suppress_printk = 1;
/*
* The final messages may not have been printed if in a context that
* defers printing (such as NMI) and irq_work is not available.
* Explicitly flush the kernel log buffer one last time.
*/
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
nbcon_atomic_flush_unsafe();Since disabled_wait() puts the CPU into an infinite wait state, it never returns to vpanic(). If the panic occurs in a context that defers printk (such as an NMI), does this mean the "end Kernel panic" marker will remain unflushed and not visible on the console?
Quoted 2 lines
arch/s390/kernel/traps.c +0
-0void kernel_stack_invalid (struct pt_regs *regs) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v5 2/3] s390: Implement arch_do_panic()
In reply to Mete DurluQuoted 5 lines · Mete Durlu
Implement s390 specific
arch_do_panic()instead of using s390 specific ifdef sections invpanic()code.disabled_wait()is now called after "end Kernel panic" marker.
No functional changes.
Can't see anything wrong, code wise
Quoted 27 lines
Signed-off-by Mete Durlu <[email protected]>---
arch/s390/kernel/traps.c| 7 +++++++kernel/panic.c| 3 ---2 files changed, 7 insertions(+), 3 deletions(-)arch/s390/kernel/traps.c +2
-0@@ -24,6 +24,7 @@#include <linux/entry-common.h> #include <linux/kmsan.h> #include <linux/bug.h> +#include <linux/panic.h> #include <asm/entry-percpu.h> #include <asm/asm-extable.h> #include <asm/irqflags.h> @@ -31,6 +32,7 @@#include <asm/vtime.h> #include <asm/fpu.h> #include <asm/fault.h> +#include <asm/processor.h> #include "entry.h" static inline void __user *get_trap_ip (struct pt_regs *regs)
arch/s390/kernel/traps.c static void monitor_event_exception(struct pt_regs *regs) · line 279
Quoted 3 lines
arch/s390/kernel/traps.c +0
-0@@ -275,6 +277,11 @@ static void monitor_event_exception(struct pt_regs *regs) } }
Comment? I mean, its a suggestion, but it's not strictly needed
Quoted 15 lines
arch/s390/kernel/traps.c +5
-0+void arch_do_panic (void ) +{ +disabled_wait (); +} +void kernel_stack_invalid (struct pt_regs *regs) {/* kernel/panic.c +0
-0
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 757
Quoted 9 lines
kernel/panic.c +0
-3@@ -752,9 +752,6 @@ void vpanic(const char *fmt, va_list args)pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" "twice on console to return to the boot prom\n"); } -#endif -#if defined(CONFIG_S390 ) -disabled_wait ();#endif pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf);
Thanks!
Re: [PATCH v5 2/3] s390: Implement arch_do_panic()
In reply to Mete DurluQuoted 10 lines · Mete Durlu
Implement s390 specific
arch_do_panic()instead of using s390 specific ifdef sections invpanic()code.disabled_wait()is now called after "end Kernel panic" marker.
No functional changes.Signed-off-by Mete Durlu <[email protected]>--- arch/s390/kernel/traps.c | 7 +++++++ kernel/panic.c | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-)
PATCH v5 3/3 sparc: Implement arch_do_panic
In reply to Mete DurluImplement sparc specific arch_do_panic() instead of using sparc specific ifdef sections in vpanic() code.
Reorder arch specific panic handling, sparc's Stop-A messages are now printed after "end Kernel panic" marker.
--- arch/sparc/kernel/setup.c | 9 +++++++++ kernel/panic.c | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-)
arch/sparc/kernel/setup.c +9 -0
@@ -2,6 +2,8 @@#include <asm/setup.h> #include <linux/sysctl.h> +#include <linux/panic.h> +#include <linux/printk.h> static const struct ctl_table sparc_sysctl_table[] = { {
@@ -36,6 +38,13 @@ static const struct ctl_table sparc_sysctl_table[] = {#endif }; +void arch_do_panic (void ) +{ +/* Make sure the user can actually press Stop-A (L1-A) */ + stop_a_enabled =1 ; +pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" +"twice on console to return to the boot prom\n" ); +}static int __init init_sparc_sysctls (void ) {
kernel/panic.c +0 -9
@@ -744,15 +744,6 @@ void vpanic(const char *fmt, va_list args) reboot_mode = panic_reboot_mode;emergency_restart (); } -#ifdef __sparc__ - { -extern int stop_a_enabled; -/* Make sure the user can actually press Stop-A (L1-A) */ - stop_a_enabled =1 ; -pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" -"twice on console to return to the boot prom\n" ); - } -#endif pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf);arch_do_panic ();
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 3/3] sparc: Implement arch_do_panic
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Implement sparc specific
arch_do_panic()instead of using sparc specific ifdef sections invpanic()code.
Reorder arch specific panic handling, sparc's Stop-A messages are now printed after "end Kernel panic" marker.Signed-off-by Mete Durlu <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v5 3/3] sparc: Implement arch_do_panic
In reply to Mete DurluQuoted 5 lines · Mete Durlu
Implement sparc specific
arch_do_panic()instead of using sparc specific ifdef sections invpanic()code.
Reorder arch specific panic handling, sparc's Stop-A messages are now printed after "end Kernel panic" marker.
thank you for clearing the ifdeffery..
Quoted 45 lines
Signed-off-by Mete Durlu <[email protected]>---
arch/sparc/kernel/setup.c| 9 +++++++++kernel/panic.c| 9 ---------2 files changed, 9 insertions(+), 9 deletions(-)arch/sparc/kernel/setup.c +9
-0@@ -2,6 +2,8 @@#include <asm/setup.h> #include <linux/sysctl.h> +#include <linux/panic.h> +#include <linux/printk.h> static const struct ctl_table sparc_sysctl_table[] = { {@@ -36,6 +38,13 @@ static const struct ctl_table sparc_sysctl_table[] = {#endif }; +void arch_do_panic (void ) +{ +/* Make sure the user can actually press Stop-A (L1-A) */ + stop_a_enabled =1 ; +pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" +"twice on console to return to the boot prom\n" ); +}static int __init init_sparc_sysctls (void ) {kernel/panic.c +0
-2@@ -744,15 +744,6 @@ void vpanic(const char *fmt, va_list args) reboot_mode = panic_reboot_mode;emergency_restart (); } -#ifdef __sparc__ - {
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 749
Quoted 10 lines
kernel/panic.c +0
-7-extern int stop_a_enabled; -/* Make sure the user can actually press Stop-A (L1-A) */ - stop_a_enabled =1 ; -pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" - "twice on console to return to the boot prom\n"); - } -#endif pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf);arch_do_panic ();
Thanks!