From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>, Kees Cook <kees@kernel.org>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>
Subject: [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars'
Date: Fri, 20 Nov 2026 14:18:30 +0100 [thread overview]
Message-ID: <20261120131827.480055-6-ardb+git@google.com> (raw)
In-Reply-To: <20261120131827.480055-4-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
efi-pstore already carries MODULE_ALIAS("platform:efivars") to match the
"efivars" platform device registered by efisubsys_init(), but never
registered an actual platform_driver for it.
Convert efi-pstore into a proper platform_driver, and only register the
"efivars" platform device when EFI_RT_SUPPORTED_SET_VARIABLE is
advertised so udev does not auto-load efi-pstore on platforms with
read-only runtime variable services.
When pstore_disable is set (via CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE=y
or efi_pstore.pstore_disable=Y), skip the initial automatic probe while
keeping the platform driver registered. This allows userspace to enable
or disable efi-pstore at runtime without rebooting via the standard
driver model sysfs interface:
echo efivars.0 > /sys/bus/platform/drivers/efi-pstore/bind
echo efivars.0 > /sys/bus/platform/drivers/efi-pstore/unbind
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/efi-pstore.c | 51 ++++++++++++++++----
drivers/firmware/efi/efi.c | 3 +-
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c
index 19a7e4fe5b52..44571fa1dd88 100644
--- a/drivers/firmware/efi/efi-pstore.c
+++ b/drivers/firmware/efi/efi-pstore.c
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0+
#include <linux/efi.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
+#include <linux/platform_device.h>
#include <linux/pstore.h>
#include <linux/slab.h>
#include <linux/ucs2_string.h>
@@ -21,6 +23,7 @@ MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/defau
static bool efivars_pstore_disable =
IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
+static bool efivars_pstore_autoprobe_disable;
module_param_named(pstore_disable, efivars_pstore_disable, bool, 0444);
@@ -228,13 +231,17 @@ static struct pstore_info efi_pstore_info = {
.erase = efi_pstore_erase,
};
-static __init int efivars_pstore_init(void)
+static int efi_pstore_probe(struct platform_device *pdev)
{
+ int ret;
+
if (!efivar_supports_writes())
- return 0;
+ return -ENODEV;
- if (efivars_pstore_disable)
- return 0;
+ if (efivars_pstore_autoprobe_disable) {
+ efivars_pstore_autoprobe_disable = false;
+ return -ENODEV;
+ }
/*
* Notice that 1024 is the minimum here to prevent issues with
@@ -251,29 +258,53 @@ static __init int efivars_pstore_init(void)
efi_pstore_info.bufsize = record_size;
- if (pstore_register(&efi_pstore_info)) {
+ ret = pstore_register(&efi_pstore_info);
+ if (ret) {
kfree(efi_pstore_info.buf);
efi_pstore_info.buf = NULL;
efi_pstore_info.bufsize = 0;
+ return ret;
}
return 0;
}
-static __exit void efivars_pstore_exit(void)
+static void efi_pstore_remove(struct platform_device *pdev)
{
- if (!efi_pstore_info.bufsize)
- return;
-
pstore_unregister(&efi_pstore_info);
kfree(efi_pstore_info.buf);
efi_pstore_info.buf = NULL;
efi_pstore_info.bufsize = 0;
}
+static const struct platform_device_id efi_pstore_ids[] = {
+ { "efivars", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, efi_pstore_ids);
+
+static struct platform_driver efi_pstore_driver = {
+ .probe = efi_pstore_probe,
+ .remove = efi_pstore_remove,
+ .id_table = efi_pstore_ids,
+ .driver = {
+ .name = "efi-pstore",
+ },
+};
+
+static __init int efivars_pstore_init(void)
+{
+ efivars_pstore_autoprobe_disable = efivars_pstore_disable;
+ return platform_driver_register(&efi_pstore_driver);
+}
+
+static __exit void efivars_pstore_exit(void)
+{
+ platform_driver_unregister(&efi_pstore_driver);
+}
+
module_init(efivars_pstore_init);
module_exit(efivars_pstore_exit);
MODULE_DESCRIPTION("EFI variable backend for pstore");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:efivars");
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 9bc22de0d67e..e98436a9bb9b 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -483,7 +483,8 @@ static int __init efisubsys_init(void)
error = efivar_ssdt_load();
if (error)
pr_err("efi: failed to load SSDT, error %d.\n", error);
- platform_device_register_simple("efivars", 0, NULL, 0);
+ if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE))
+ platform_device_register_simple("efivars", 0, NULL, 0);
}
BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh);
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-20 13:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 13:18 [PATCH 0/2] efi: Fix pstore runtime en/disable Ard Biesheuvel
2026-11-20 13:18 ` [PATCH 1/2] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel
2026-11-20 13:18 ` Ard Biesheuvel [this message]
2026-11-20 13:39 ` [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' sashiko-bot
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=20261120131827.480055-6-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=gpiccoli@igalia.com \
--cc=kees@kernel.org \
--cc=linux-efi@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.