[PATCH] efi: efibc: Optionally report panic as a reboot reason
Dave Young
hidave at 163.com
Wed Nov 11 18:57:05 PST 2026
Cc kexec list
On 11/8/26 8:34 AM, Guilherme G. Piccoli wrote:
> The small efibc driver can be used to determine the cause of a reboot,
> in addition to controlling bootloader behavior. Currently, this driver
> reports "shutdown" or "reboot" as possible reasons for a system restart.
>
> Add support for panic reporting, gated by a module parameter. If users
> set the parameter, a panic notifier is registered and tries to save
> "panic" as the reboot reason, if the kernel is configured to reboot on
> panic. Note that it is a best-effort approach, relying on the nonblocking
> version of the EFI variable setter.
>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli at igalia.com>
> ---
>
>
> Hi folks, this is a 2nd attempt to make the kernel notify UEFI about
> a panic. The first proposal was a new (small) driver, sent here:
> https://lore.kernel.org/r/20220729194532.228403-1-gpiccoli@igalia.com/
>
> The idea is to have a simple mechanism, independent of efi-pstore (since
> users could be using other pstore backends, or do not wish to collect
> logs for privacy), to let UEFI know a panic happened. Using efibc seems
> to be a reasonable and simple approach.
>
> The option is gated by a parameter; this could be removed in case it's
> considered unnecessary. I think a parameter is less invasive than just
> changing the default.
>
> Feedback / reviews are greatly appreciated.
> Thanks in advance,
>
> Guilherme
>
>
> drivers/firmware/efi/efibc.c | 46 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/efi/efibc.c b/drivers/firmware/efi/efibc.c
> index 345a10aa7086..b4014500513f 100644
> --- a/drivers/firmware/efi/efibc.c
> +++ b/drivers/firmware/efi/efibc.c
> @@ -11,9 +11,14 @@
> #include <linux/reboot.h>
> #include <linux/slab.h>
> #include <linux/ucs2_string.h>
> +#include <linux/panic_notifier.h>
>
> #define MAX_DATA_LEN 512
>
> +static bool report_panic;
> +module_param(report_panic, bool, 0444);
> +MODULE_PARM_DESC(report_panic, "Report kernel panic as a reboot reason too (default N)");
> +
> static int efibc_set_variable(efi_char16_t *name, efi_char16_t *value,
> unsigned long len)
> {
> @@ -65,6 +70,30 @@ static struct notifier_block efibc_reboot_notifier = {
> .notifier_call = efibc_reboot_notifier_call,
> };
>
> +static int efibc_panic_notifier_call(struct notifier_block *notifier,
> + unsigned long event, void *data)
> +{
> + efi_char16_t *reason = L"panic";
> +
> + /* Skip if we aren't rebooting on panic. */
> + if (!panic_timeout)
> + return NOTIFY_DONE;
> +
> + efi.set_variable_nonblocking(L"LoaderEntryRebootReason",
> + &LINUX_EFI_LOADER_ENTRY_GUID,
> + EFI_VARIABLE_NON_VOLATILE
> + | EFI_VARIABLE_BOOTSERVICE_ACCESS
> + | EFI_VARIABLE_RUNTIME_ACCESS,
> + ucs2_strlen(reason) * sizeof(efi_char16_t),
> + reason);
> + return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block efibc_panic_nb = {
> + .notifier_call = efibc_panic_notifier_call,
> + .priority = INT_MIN,
> +};
> +
> static int __init efibc_init(void)
> {
> int ret;
> @@ -73,16 +102,29 @@ static int __init efibc_init(void)
> return -ENODEV;
>
> ret = register_reboot_notifier(&efibc_reboot_notifier);
> - if (ret)
> + if (ret) {
> pr_err("unable to register reboot notifier\n");
> + return ret;
> + }
>
> - return ret;
> + if (report_panic && efi.set_variable_nonblocking) {
> + ret = atomic_notifier_chain_register(&panic_notifier_list,
> + &efibc_panic_nb);
> + if (ret)
> + pr_err("unable to register panic notifier\n");
> + }
> +
> + return 0;
> }
> module_init(efibc_init);
>
> static void __exit efibc_exit(void)
> {
> unregister_reboot_notifier(&efibc_reboot_notifier);
> +
> + if (report_panic && efi.set_variable_nonblocking)
> + atomic_notifier_chain_unregister(&panic_notifier_list,
> + &efibc_panic_nb);
> }
> module_exit(efibc_exit);
>
More information about the kexec
mailing list