From: carlos.bilbao@kernel.org
To: tglx@linutronix.de, seanjc@google.com, jan.glauber@gmail.com
Cc: bilbao@vt.edu, pmladek@suse.com, akpm@linux-foundation.org,
jani.nikula@intel.com, linux-kernel@vger.kernel.org,
gregkh@linuxfoundation.org, takakura@valinux.co.jp,
john.ogness@linutronix.de,
Carlos Bilbao <carlos.bilbao@kernel.org>
Subject: [PATCH v3 1/2] panic: Allow for dynamic custom behavior after panic
Date: Tue, 29 Apr 2025 10:06:37 -0500 [thread overview]
Message-ID: <20250429150638.1446781-2-carlos.bilbao@kernel.org> (raw)
In-Reply-To: <20250429150638.1446781-1-carlos.bilbao@kernel.org>
From: Carlos Bilbao <carlos.bilbao@kernel.org>
Introduce panic_set_handling() to allow overriding the default post-panic
behavior with a priority-based mechanism.
Signed-off-by: Carlos Bilbao (DigitalOcean) <carlos.bilbao@kernel.org>
Reviewed-by: Jan Glauber (DigitalOcean) <jan.glauber@gmail.com>
---
include/linux/panic.h | 2 ++
kernel/panic.c | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/linux/panic.h b/include/linux/panic.h
index 2494d51707ef..cf8d4a944407 100644
--- a/include/linux/panic.h
+++ b/include/linux/panic.h
@@ -98,4 +98,6 @@ extern void add_taint(unsigned flag, enum lockdep_ok);
extern int test_taint(unsigned flag);
extern unsigned long get_taint(void);
+void panic_set_handling(void (*fn)(void), int priority);
+
#endif /* _LINUX_PANIC_H */
diff --git a/kernel/panic.c b/kernel/panic.c
index a3889f38153d..559304546f2e 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -276,6 +276,25 @@ static void panic_other_cpus_shutdown(bool crash_kexec)
crash_smp_send_stop();
}
+/*
+ * If set, this function is called after a kernel panic is handled. It can
+ * be assigned using panic_set_handling(), which supports priority-based
+ * logic. For example, specific architectures may provide a default handler
+ * (priority 0) that halts the system to conserve CPU resources.
+ */
+static void (*panic_halt)(void);
+
+static int panic_halt_priority;
+
+void panic_set_handling(void (*fn)(void), int priority)
+{
+ if (panic_halt && priority <= panic_halt_priority)
+ return;
+
+ panic_halt_priority = priority;
+ panic_halt = fn;
+}
+
/**
* panic - halt the system
* @fmt: The text string to print
@@ -467,6 +486,9 @@ void panic(const char *fmt, ...)
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
nbcon_atomic_flush_unsafe();
+ if (panic_halt)
+ panic_halt();
+
local_irq_enable();
for (i = 0; ; i += PANIC_TIMER_STEP) {
touch_softlockup_watchdog();
--
2.47.1
next prev parent reply other threads:[~2025-04-29 16:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 15:06 [PATCH v3 0/2] Reduce CPU consumption " carlos.bilbao
2025-04-29 15:06 ` carlos.bilbao [this message]
2025-04-29 15:06 ` [PATCH v3 2/2] x86/panic: Add x86_panic_handler as default post-panic behavior carlos.bilbao
2025-04-29 20:39 ` [PATCH v3 0/2] Reduce CPU consumption after panic Andrew Morton
2025-04-29 20:17 ` Carlos Bilbao
2025-04-29 22:53 ` Andrew Morton
2025-04-29 21:39 ` Carlos Bilbao
2025-04-29 21:06 ` Peter Zijlstra
2025-04-29 20:32 ` Carlos Bilbao
2025-04-29 22:10 ` Peter Zijlstra
2025-04-29 20:52 ` Carlos Bilbao
2025-04-30 8:48 ` Peter Zijlstra
2025-04-30 15:59 ` Sean Christopherson
2025-04-30 18:54 ` Carlos Bilbao
2025-05-01 8:55 ` Peter Zijlstra
2025-05-07 19:49 ` Carlos Bilbao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250429150638.1446781-2-carlos.bilbao@kernel.org \
--to=carlos.bilbao@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bilbao@vt.edu \
--cc=gregkh@linuxfoundation.org \
--cc=jan.glauber@gmail.com \
--cc=jani.nikula@intel.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=seanjc@google.com \
--cc=takakura@valinux.co.jp \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®