[PATCH v5 0/3] Introduce arch_do_panic

From: Mete Durlu

Date: Mon Aug 10 2026 - 07:38:42 EST


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/20260730-arch_do_panic-v3-0-d5401e683cdb@xxxxxxxxxxxxx/

Signed-off-by: Mete Durlu <meted@xxxxxxxxxxxxx>
---
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,
--
Mete Durlu <meted@xxxxxxxxxxxxx>