Introduce arch_do_panic
Subsystems (2)
cover Introduce arch_do_panic
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.
Move s390 panic handling from the panic_notifier chain to arch_do_panic(). This corrects the execution order so that the panic_timeout is properly evaluated before architecture-specific actions. The previous notifier-based approach executed too early in the panic sequence.
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.
The cleanup reduces vpanic() complexity and establishes a pattern for other architectures needing custom panic behavior.
---
Mete Durlu (3):
panic: Introduce arch_do_panic
s390: Implement arch_do_panic
sparc: Implement arch_do_panic
arch/s390/include/asm/ipl.h | 1 + arch/s390/include/asm/setup.h | 3 +++ arch/s390/kernel/ipl.c | 15 +-------------- arch/sparc/include/asm/setup.h | 4 +++- arch/sparc/kernel/setup.c | 8 ++++++++ kernel/panic.c | 18 ++++++------------ 6 files changed, 22 insertions(+), 27 deletions(-)
---
base-commit: 48a5a7ab8d6ab7090564339e039c421f315de912
change-id: 20260724-arch_do_panic-a97f699aa332
Best regards,
Signature · 1 line
Mete Durlu <[email protected]>
PATCH 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.
--- kernel/panic.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/panic.c +6 -0
@@ -567,6 +567,11 @@ static void panic_other_cpus_shutdown(bool crash_kexec)crash_smp_send_stop (); } +#ifndef arch_do_panic +#define arch_do_panic arch_do_panic +static inline void arch_do_panic (void ) {} +#endif +/** * vpanic - halt the system * @fmt: The text string to print
@@ -756,6 +761,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 1/3] panic: Introduce arch_do_panic
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 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.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 2/3 s390: Implement arch_do_panic
In reply to Mete Durlus390 has a custom panic handler which carries out user specified actions during a panic scenario. This handler is invoked via the panic_notifier call chain and executed before panic_timeout value is evaluated in common code.
Use arch_do_panic() hook to invoke arch specific panic handling instead of using panic_notifier call chain. The execution order of panic handlers now allow for user specified panic_timeout value to be taken into account.
--- arch/s390/include/asm/ipl.h | 1 + arch/s390/include/asm/setup.h | 3 +++ arch/s390/kernel/ipl.c | 15 +-------------- kernel/panic.c | 3 --- 4 files changed, 5 insertions(+), 17 deletions(-)
arch/s390/include/asm/ipl.h +1 -0
@@ -166,5 +166,6 @@ enum diag308_rc {extern int diag308 (unsigned long subcode,void *addr);extern void store_status (void (*fn)(void *),void *data);extern void lgr_info_log (void ); +void s390_do_panic (void );#endif /* _ASM_S390_IPL_H */
arch/s390/include/asm/setup.h +3 -0
@@ -90,6 +90,9 @@ extern void (*_machine_restart)(char *command);extern void (*_machine_halt)(void );extern void (*_machine_power_off)(void ); +void arch_do_panic (void ); +#define arch_do_panic arch_do_panic +struct oldmem_data {unsigned long start;unsigned long size;
arch/s390/kernel/ipl.c +1 -14
@@ -2115,7 +2115,7 @@ static ssize_t on_panic_store(struct kobject *kobj, }static struct kobj_attribute on_panic_attr =__ATTR_RW (on_panic); -static void do_panic (void ) +void arch_do_panic (void ) {lgr_info_log (); on_panic_trigger.action->fn (&on_panic_trigger);
@@ -2331,18 +2331,6 @@ static int __init vmcmd_on_poff_setup(char *str) }__setup ("vmpoff=" , vmcmd_on_poff_setup); -static int on_panic_notify (struct notifier_block *self, -unsigned long event,void *data) -{ -do_panic (); -return NOTIFY_OK ; -} - -static struct notifier_block on_panic_nb = { - .notifier_call = on_panic_notify, - .priority =INT_MIN , -}; -void __init setup_ipl (void ) {BUILD_BUG_ON (sizeof (struct ipl_parameter_block ) !=PAGE_SIZE );
@@ -2375,7 +2363,6 @@ void __init setup_ipl(void)/* We have no info to copy */ break ; } -atomic_notifier_chain_register (&panic_notifier_list, &on_panic_nb); } void __no_stack_protector s390_reset_system(void)
kernel/panic.c +0 -3
@@ -755,9 +755,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 2/3] s390: Implement arch_do_panic
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] arch_do_panic() is bypassed when panic_timeout != 0 - [Low] Unused declaration of s390_do_panic() --
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] arch_do_panic() is bypassed when panic_timeout != 0
- [Low] Unused declaration of s390_do_panic()
--
--- Patch [2]: [PATCH 2/3] s390: Implement arch_do_panic --- commit 640e72aef0a165dacc87c9e5913aa8f9442aa6e9
Author: Mete Durlu <[email protected]>
s390: Implement arch_do_panic
This commit implements the arch_do_panic() hook for s390 to handle architecture-specific panic actions instead of relying on the panic_notifier chain. This change allows user-specified panic_timeout values to be evaluated in common code before executing the s390 specific actions.
arch/s390/include/asm/ipl.h enum diag308_rc { · line 169
Quoted 9 lines
arch/s390/include/asm/ipl.h +1
-0@@ -166,5 +166,6 @@ enum diag308_rc {extern int diag308 (unsigned long subcode,void *addr);extern void store_status (void (*fn)(void *),void *data);extern void lgr_info_log (void ); +void s390_do_panic (void );
[Severity: Low]
Is this declaration necessary?
It looks like s390_do_panic() is declared here but never implemented or used, as the actual implementation provided in arch/s390/kernel/ipl.c is named arch_do_panic().
[ ... ]
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 759
Quoted 13 lines
kernel/panic.c +0
-3@@ -755,9 +755,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);
[Severity: High]
Does this change unintentionally bypass the s390 panic actions when panic_timeout != 0?
Looking at vpanic() in kernel/panic.c, if a panic timeout is set, the system will restart before reaching arch_do_panic():
if (panic_timeout != 0) {
...
emergency_restart();
}
pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
arch_do_panic();Since emergency_restart() does not return, will the user-configured on_panic actions be lost in this scenario?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/3] s390: Implement arch_do_panic
Quoted 29 lines · On 7/27/26 11:10 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High]arch_do_panic()is bypassed whenpanic_timeout!= 0
- [Low] Unused declaration ofs390_do_panic()
----- Patch [2]: [PATCH 2/3] s390: Implement
arch_do_panic--- commit640e72aef0a165dacc87c9e5913aa8f9442aa6e9
Author: Mete Durlu <[email protected]>s390: Implement
arch_do_panicThis commit implements the
arch_do_panic()hook for s390 to handle architecture-specific panic actions instead of relying on thepanic_notifierchain. This change allows user-specifiedpanic_timeoutvalues to be evaluated in common code before executing the s390 specific actions.arch/s390/include/asm/ipl.h enum diag308_rc { · line 169
Quoted 9 lines
arch/s390/include/asm/ipl.h +1
-0@@ -166,5 +166,6 @@ enum diag308_rc {extern int diag308 (unsigned long subcode,void *addr);extern void store_status (void (*fn)(void *),void *data);extern void lgr_info_log (void ); +void s390_do_panic (void );[Severity: Low]
Is this declaration necessary?
Quoted 3 lines
It looks like
s390_do_panic()is declared here but never implemented or used, as the actual implementation provided inarch/s390/kernel/ipl.cis namedarch_do_panic().
This is leftover code. I'll remove it in the next version.
Quoted 31 lines
[ ... ]
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 759
Quoted 13 lines
kernel/panic.c +0
-3@@ -755,9 +755,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);[Severity: High]
Does this change unintentionally bypass the s390 panic actions whenpanic_timeout!= 0?Looking at
vpanic()inkernel/panic.c, if a panic timeout is set, the system will restart before reachingarch_do_panic():if (panic_timeout != 0) { ... emergency_restart(); } pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf); arch_do_panic();
Quoted 2 lines
Since
emergency_restart()does not return, will the user-configuredon_panicactions be lost in this scenario?
Yes, this is the intended behavior with this change. I'll document it in the commit message in next version.
PATCH 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.
--- arch/sparc/include/asm/setup.h | 4 +++- arch/sparc/kernel/setup.c | 8 ++++++++ kernel/panic.c | 9 --------- 3 files changed, 11 insertions(+), 10 deletions(-)
arch/sparc/include/asm/setup.h +3 -1
@@ -43,7 +43,6 @@ void __init device_scan(void);/* unaligned_32.c */ unsigned long safe_compute_effective_address (struct pt_regs *,unsigned int ); -#endif #ifdef CONFIG_SPARC64
@@ -67,4 +66,7 @@ void sun_do_break(void);extern int stop_a_enabled;extern int scons_pwroff; +void arch_do_panic (void ); +#define arch_do_panic arch_do_panic +#endif /* _SPARC_SETUP_H */
arch/sparc/kernel/setup.c +8 -0
@@ -36,6 +36,14 @@ static const struct ctl_table sparc_sysctl_table[] = {#endif }; +void arch_do_panic (void ) +{ +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" ); +}static int __init init_sparc_sysctls (void ) {
kernel/panic.c +0 -9
@@ -747,15 +747,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 3/3] sparc: Implement arch_do_panic
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The newly introduced SPARC implementation of `arch_do_panic()` is never called because the…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The newly introduced SPARC implementation of arch_do_panic() is never called because the overriding macro is not visible in kernel/panic.c, resulting in the empty fallback stub being used and the SPARC implementation becoming dead code.
- [Low] Redundant local extern declaration of stop_a_enabled.
--
--- Patch [3]: [PATCH 3/3] sparc: Implement arch_do_panic --- commit 0468bb7524180e5a2aa478f794a79dc389197120
Author: Mete Durlu <[email protected]>
sparc: Implement arch_do_panic
This patch implements a sparc-specific arch_do_panic function to handle the Stop-A hardware sequence. It removes the architecture-specific ifdef blocks from the generic panic code.
Quoted 4 lines
arch/sparc/include/asm/setup.h +0
-0
[ ... ]
Quoted 13 lines
arch/sparc/include/asm/setup.h +3
-0@@ -67,4 +66,7 @@ void sun_do_break(void);extern int stop_a_enabled;extern int scons_pwroff; +void arch_do_panic (void ); +#define arch_do_panic arch_do_panic +#endif /* _SPARC_SETUP_H */ arch/sparc/kernel/setup.c +0
-0
[ ... ]
arch/sparc/kernel/setup.c static const struct ctl_table sparc_sysctl_table[] = { · line 41
Quoted 7 lines
arch/sparc/kernel/setup.c +3
-0@@ -36,6 +36,14 @@ static const struct ctl_table sparc_sysctl_table[] = {#endif }; +void arch_do_panic (void ) +{ +extern int stop_a_enabled;
[Severity: Low]
This isn't a bug, but is this local extern declaration necessary? Since asm/setup.h is included at the top of this file, the global declaration of stop_a_enabled should already be visible.
Quoted 10 lines
arch/sparc/kernel/setup.c +5
-0+/* 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" ); +}kernel/panic.c +0
-0
[ ... ]
Quoted 6 lines
kernel/panic.c +0
-2@@ -747,15 +747,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 752
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 ();
[Severity: High]
Will this actually call the sparc-specific implementation?
Looking at kernel/panic.c, it does not appear to include asm/setup.h where the override macro for arch_do_panic is defined. Because the override macro isn't visible in this translation unit, won't vpanic end up executing the default empty inline fallback instead of the newly added sparc implementation, effectively dropping the sparc panic behavior?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3