* [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again
2026-11-24 17:28 [PATCH v2 0/5] efi: Fix pstore runtime en/disable Ard Biesheuvel
@ 2026-11-24 17:28 ` Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock() Ard Biesheuvel
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
To: linux-efi
Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
Uwe Kleine-König, stable
From: Ard Biesheuvel <ardb@kernel.org>
Commit a28655c330ab ("efi: pstore: Allow dynamic initialization based on
module parameter") wired up a kernel_param_ops::set callback for
pstore_disable that invokes efivars_pstore_init() directly.
Because parse_args() runs before module initialization (and before
mm_core_init() during early boot when built-in), calling
efivars_pstore_init() from the parameter setter is fundamentally broken:
- Loading efi-pstore as a module with pstore_disable=N initializes and
registers efi_pstore_info during parse_args(), and then runs
efivars_pstore_init() a second time from do_init_module(), leaking
the first buffer, failing pstore_register() with -EBUSY, and zeroing
efi_pstore_info.buf/bufsize while leaving efi_pstore_info registered
with pstore.
- If load_module() fails after parse_args() (e.g., due to a subsequent
unknown parameter), the module is freed without calling module_exit,
leaving pstore with a dangling backend pointer.
- Passing pstore_disable=N before record_size=<N> initializes the
buffer using the default record_size before record_size is parsed.
Module parameters are meant for boot/load-time configuration rather than
runtime driver state control via sysfs. Revert the dynamic parameter
callback changes and tighten the sysfs permissions of pstore_disable from
0644 to 0444 (matching record_size) so it is no longer misleadingly
writable at runtime.
Fixes: a28655c330ab ("efi: pstore: Allow dynamic initialization based on module parameter")
Cc: stable@vger.kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/efi-pstore.c | 39 +++-----------------
1 file changed, 6 insertions(+), 33 deletions(-)
diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c
index a5db3534f0a6..19a7e4fe5b52 100644
--- a/drivers/firmware/efi/efi-pstore.c
+++ b/drivers/firmware/efi/efi-pstore.c
@@ -19,37 +19,10 @@ MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/defau
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
EFI_VARIABLE_RUNTIME_ACCESS)
-static bool pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
+static bool efivars_pstore_disable =
+ IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
-static int efivars_pstore_init(void);
-static void efivars_pstore_exit(void);
-
-static int efi_pstore_disable_set(const char *val, const struct kernel_param *kp)
-{
- int err;
- bool old_pstore_disable = pstore_disable;
-
- err = param_set_bool(val, kp);
- if (err)
- return err;
-
- if (old_pstore_disable != pstore_disable) {
- if (pstore_disable)
- efivars_pstore_exit();
- else
- efivars_pstore_init();
- }
-
- return 0;
-}
-
-static const struct kernel_param_ops pstore_disable_ops = {
- .set = efi_pstore_disable_set,
- .get = param_get_bool,
-};
-
-module_param_cb(pstore_disable, &pstore_disable_ops, &pstore_disable, 0644);
-__MODULE_PARM_TYPE(pstore_disable, "bool");
+module_param_named(pstore_disable, efivars_pstore_disable, bool, 0444);
static int efi_pstore_open(struct pstore_info *psi)
{
@@ -255,12 +228,12 @@ static struct pstore_info efi_pstore_info = {
.erase = efi_pstore_erase,
};
-static int efivars_pstore_init(void)
+static __init int efivars_pstore_init(void)
{
if (!efivar_supports_writes())
return 0;
- if (pstore_disable)
+ if (efivars_pstore_disable)
return 0;
/*
@@ -287,7 +260,7 @@ static int efivars_pstore_init(void)
return 0;
}
-static void efivars_pstore_exit(void)
+static __exit void efivars_pstore_exit(void)
{
if (!efi_pstore_info.bufsize)
return;
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock()
2026-11-24 17:28 [PATCH v2 0/5] efi: Fix pstore runtime en/disable Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel
@ 2026-11-24 17:28 ` Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 3/5] efi: Statically initialize efivar_ops_nh Ard Biesheuvel
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
To: linux-efi
Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
Uwe Kleine-König, stable
From: Ard Biesheuvel <ardb@kernel.org>
efivar_lock() and efivar_trylock() check __efivars->ops after taking
efivars_lock, but __efivars itself is NULL whenever no efivars
implementation is registered.
That happens at runtime, not only before efivars is set up. For example,
tee_stmm_efi_probe() unregisters the generic efivars ops before
registering its own, and qcom_uefisecapp_remove() and gsmi_exit()
unregister efivars outright. A concurrent or subsequent efivarfs
access, or a write from a pstore backend that is still registered, then
dereferences a NULL pointer instead of failing with -ENODEV.
Check __efivars itself as well as __efivars->ops.
Fixes: 472831d4c4b2 ("efi: vars: Add thin wrapper around EFI get/set variable interface")
Cc: stable@vger.kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/vars.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index 3700e9869767..f9c28fbdb26d 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -143,7 +143,7 @@ int efivar_lock(void)
{
if (down_interruptible(&efivars_lock))
return -EINTR;
- if (!__efivars->ops) {
+ if (!__efivars || !__efivars->ops) {
up(&efivars_lock);
return -ENODEV;
}
@@ -159,7 +159,7 @@ int efivar_trylock(void)
{
if (down_trylock(&efivars_lock))
return -EBUSY;
- if (!__efivars->ops) {
+ if (!__efivars || !__efivars->ops) {
up(&efivars_lock);
return -ENODEV;
}
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 3/5] efi: Statically initialize efivar_ops_nh
2026-11-24 17:28 [PATCH v2 0/5] efi: Fix pstore runtime en/disable Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock() Ard Biesheuvel
@ 2026-11-24 17:28 ` Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 4/5] efi: Tie 'efivars' pdev lifecycle to generic efivars Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 5/5] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel
4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
To: linux-efi
Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
Uwe Kleine-König
From: Ard Biesheuvel <ardb@kernel.org>
efisubsys_init() initializes the efivar_ops_nh notifier head at runtime,
but only after generic_ops_register() has already called
efivars_register(), which invokes blocking_notifier_call_chain() on it.
This is currently harmless: the head is zero-initialized, and
blocking_notifier_call_chain() returns early on an empty chain before
touching the rwsem. Still, it is fragile, and there is no reason to set
up the notifier head at runtime at all.
Use BLOCKING_NOTIFIER_HEAD() so it is valid from the start, and drop the
runtime initialization.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/efi.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 40b423f85e06..98f6365c1a8c 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -184,7 +184,7 @@ static const struct attribute_group efi_subsys_attr_group = {
.is_visible_const = efi_attr_is_visible,
};
-struct blocking_notifier_head efivar_ops_nh;
+BLOCKING_NOTIFIER_HEAD(efivar_ops_nh);
EXPORT_SYMBOL_GPL(efivar_ops_nh);
static struct efivars generic_efivars;
@@ -485,8 +485,6 @@ static int __init efisubsys_init(void)
platform_device_register_simple("efivars", 0, NULL, 0);
}
- BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh);
-
error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
if (error) {
pr_err("efi: Sysfs attribute export failed with error %d.\n",
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 4/5] efi: Tie 'efivars' pdev lifecycle to generic efivars
2026-11-24 17:28 [PATCH v2 0/5] efi: Fix pstore runtime en/disable Ard Biesheuvel
` (2 preceding siblings ...)
2026-11-24 17:28 ` [PATCH v2 3/5] efi: Statically initialize efivar_ops_nh Ard Biesheuvel
@ 2026-11-24 17:28 ` Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 5/5] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel
4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
To: linux-efi
Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
Uwe Kleine-König
From: Ard Biesheuvel <ardb@kernel.org>
Currently, efisubsys_init() registers the "efivars" platform device,
which efi-pstore matches via MODULE_ALIAS("platform:efivars"), whenever
EFI_BOOT is set and GetVariable/GetNextVariableName are marked supported
in efi.runtime_supported_mask. The device is never unregistered.
That makes the device's existence unrelated to what efi-pstore actually
needs:
- it is registered even when generic_ops_supported() returns false
(leaving no efivars implementation registered) or when SetVariable()
is unsupported;
- it remains registered after tee_stmm_efi_probe() replaces the generic
ops with the OP-TEE StandaloneMM implementation, which does not
support non-blocking SetVariable() calls from the pstore dump path.
Other efivars implementations (Coreboot GSMI, Qualcomm UEFI Secure App)
should not be exposed to efi-pstore at all. qcuefi_set_variable() takes
a mutex and allocates memory, and efivar_set_variable_locked() falls
back to it from pstore_dump(), which runs with a raw spinlock held and
interrupts disabled. On GSMI systems, efi-pstore would also compete with
ramoops for pstore's single backend slot.
Instead, register the "efivars" platform device from
generic_ops_register() once efivars_register() has succeeded with
SetVariable() support, and unregister it from generic_ops_unregister()
before efivars_unregister(). Consumers are then always detached while
the ops they use are still in place.
Serialize both paths with a new generic_ops_lock. They can also be
reached at runtime via efivars_generic_ops_[un]register() from
tee_stmm_efi. The device is registered and unregistered outside
efivars_lock, so a consumer can take efivars_lock from its probe or
remove path.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/efi.c | 52 +++++++++++++++++++-
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 98f6365c1a8c..a9508595740b 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -31,6 +31,7 @@
#include <linux/acpi.h>
#include <linux/ucs2_string.h>
#include <linux/memblock.h>
+#include <linux/mutex.h>
#include <linux/security.h>
#include <linux/notifier.h>
@@ -190,6 +191,21 @@ EXPORT_SYMBOL_GPL(efivar_ops_nh);
static struct efivars generic_efivars;
static struct efivar_operations generic_ops;
+/*
+ * Serializes generic_ops_register() and generic_ops_unregister(), which may
+ * also be called at runtime via efivars_generic_ops_[un]register(), and
+ * protects efivars_pdev.
+ */
+static DEFINE_MUTEX(generic_ops_lock);
+
+/*
+ * The "efivars" platform device that efi-pstore binds to. It only exists
+ * while the generic, EFI runtime services based efivars ops are registered
+ * and support SetVariable(), as other efivars implementations may not
+ * provide a SetVariable() that is safe to call from the pstore dump path.
+ */
+static struct platform_device *efivars_pdev;
+
static bool generic_ops_supported(void)
{
unsigned long name_size;
@@ -210,6 +226,11 @@ static bool generic_ops_supported(void)
static int generic_ops_register(void)
{
+ struct platform_device *pdev;
+ int ret;
+
+ guard(mutex)(&generic_ops_lock);
+
if (!generic_ops_supported())
return 0;
@@ -222,14 +243,42 @@ static int generic_ops_register(void)
generic_ops.set_variable = efi.set_variable;
generic_ops.set_variable_nonblocking = efi.set_variable_nonblocking;
}
- return efivars_register(&generic_efivars, &generic_ops);
+
+ ret = efivars_register(&generic_efivars, &generic_ops);
+ if (ret || !generic_ops.set_variable)
+ return ret;
+
+ /*
+ * Register the platform device only after efivars_register() has
+ * returned, so that a consumer probing synchronously from
+ * platform_device_register_simple() can take efivars_lock.
+ */
+ pdev = platform_device_register_simple("efivars", 0, NULL, 0);
+ if (IS_ERR(pdev))
+ pr_warn("efi: failed to register efivars platform device: %pe\n",
+ pdev);
+ else
+ efivars_pdev = pdev;
+
+ return 0;
}
static void generic_ops_unregister(void)
{
+ guard(mutex)(&generic_ops_lock);
+
if (!generic_ops.get_variable)
return;
+ /*
+ * Unregister the platform device first, so that consumers are
+ * detached while the efivars ops they rely on are still registered.
+ */
+ if (efivars_pdev) {
+ platform_device_unregister(efivars_pdev);
+ efivars_pdev = NULL;
+ }
+
efivars_unregister(&generic_efivars);
}
@@ -482,7 +531,6 @@ 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);
}
error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 5/5] efi: pstore: Convert into a platform driver for 'efivars'
2026-11-24 17:28 [PATCH v2 0/5] efi: Fix pstore runtime en/disable Ard Biesheuvel
` (3 preceding siblings ...)
2026-11-24 17:28 ` [PATCH v2 4/5] efi: Tie 'efivars' pdev lifecycle to generic efivars Ard Biesheuvel
@ 2026-11-24 17:28 ` Ard Biesheuvel
4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
To: linux-efi
Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
Uwe Kleine-König
From: Ard Biesheuvel <ardb@kernel.org>
efi-pstore already carries MODULE_ALIAS("platform:efivars") to match the
"efivars" platform device, but never registered an actual platform_driver
for it. As a result, it stays registered with pstore even after the
"efivars" device goes away, e.g., when tee_stmm_efi replaces the generic
efivars ops.
Convert efi-pstore into a proper platform_driver, so that its pstore
backend lifetime follows that of the "efivars" device. The EFI core
registers that device only while the generic, EFI runtime services based
efivars ops are in use and support SetVariable().
efi_pstore_info is a singleton, so only bind to the device named
"efivars" that carries struct efivars_pdev_data. This rejects devices
whose driver_override has been set to "efi-pstore" via sysfs: binding to
one of those would race with the "efivars" device under a different
device_lock and clobber efi_pstore_info.buf while it is registered.
When pstore_disable is set (via CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE=y
or efi_pstore.pstore_disable=Y), refuse the probes that the driver core
performs automatically during platform_driver_register() and during
registration of the "efivars" device, while keeping the driver
registered. Each window is tracked by a flag: a module-local one for
driver registration, and efivars_pdev_data::registering, which the EFI
core sets while registering the device. With PROBE_FORCE_SYNCHRONOUS,
the automatic probes complete within these windows. This lets userspace
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
An explicit bind that races with either registration window is refused.
A manual binding does not carry over if the "efivars" device is
re-registered, e.g., when tee_stmm_efi is unbound and the generic ops are
restored; the new device is again subject to pstore_disable.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/efi-pstore.c | 87 +++++++++++++++++---
drivers/firmware/efi/efi.c | 25 ++++--
include/linux/efi.h | 11 +++
3 files changed, 107 insertions(+), 16 deletions(-)
diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c
index 19a7e4fe5b52..93c5e18f33b5 100644
--- a/drivers/firmware/efi/efi-pstore.c
+++ b/drivers/firmware/efi/efi-pstore.c
@@ -2,8 +2,10 @@
#include <linux/efi.h>
#include <linux/module.h>
+#include <linux/platform_device.h>
#include <linux/pstore.h>
#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/ucs2_string.h>
MODULE_IMPORT_NS("EFIVAR");
@@ -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 efi_pstore_driver_registering;
module_param_named(pstore_disable, efivars_pstore_disable, bool, 0444);
@@ -228,13 +231,42 @@ 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)
{
+ const struct efivars_pdev_data *pdata = dev_get_platdata(&pdev->dev);
+ int ret;
+
+ /*
+ * efi_pstore_info is a singleton, so only bind to the "efivars" device
+ * registered by the EFI core, of which at most one exists at any given
+ * time, and whose probe and remove are serialized by its device_lock.
+ * This also rejects other devices whose driver_override was set to
+ * "efi-pstore" via sysfs, which platform_match() honours before
+ * consulting the id table.
+ */
+ if (!pdata || strcmp(pdev->name, EFIVARS_PDEV_NAME))
+ return -ENODEV;
+
if (!efivar_supports_writes())
- return 0;
+ return -ENODEV;
- if (efivars_pstore_disable)
- return 0;
+ /*
+ * If efi-pstore is disabled, only permit binding it explicitly via
+ * sysfs, by refusing the probes that the driver core performs
+ * automatically when the driver or the "efivars" device is
+ * registered. As the driver uses PROBE_FORCE_SYNCHRONOUS, such probes
+ * always complete before platform_driver_register() or
+ * platform_device_register_data() return, and therefore before the
+ * respective flag is cleared again. (This also means that an explicit
+ * bind that races with either registration is refused.)
+ *
+ * The flags may be cleared concurrently by another CPU, without
+ * holding this device's device_lock, hence the READ_ONCE()s.
+ */
+ if (efivars_pstore_disable &&
+ (READ_ONCE(efi_pstore_driver_registering) ||
+ READ_ONCE(pdata->registering)))
+ return -ENODEV;
/*
* Notice that 1024 is the minimum here to prevent issues with
@@ -251,29 +283,62 @@ 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 0;
+ return ret;
}
-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[] = {
+ { .name = EFIVARS_PDEV_NAME, },
+ { }
+};
+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",
+ .probe_type = PROBE_FORCE_SYNCHRONOUS,
+ },
+};
+
+static __init int efivars_pstore_init(void)
+{
+ int ret;
+
+ /*
+ * efi_pstore_driver becomes visible on the platform bus and in sysfs
+ * before platform_driver_register() returns, so a concurrent probe on
+ * another CPU may read the flag while it is being cleared.
+ */
+ WRITE_ONCE(efi_pstore_driver_registering, true);
+ ret = platform_driver_register(&efi_pstore_driver);
+ WRITE_ONCE(efi_pstore_driver_registering, false);
+ return ret;
+}
+
+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 a9508595740b..5b47e3073256 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -226,6 +226,8 @@ static bool generic_ops_supported(void)
static int generic_ops_register(void)
{
+ struct efivars_pdev_data pdata = { .registering = true };
+ struct efivars_pdev_data *pdev_data;
struct platform_device *pdev;
int ret;
@@ -251,14 +253,27 @@ static int generic_ops_register(void)
/*
* Register the platform device only after efivars_register() has
* returned, so that a consumer probing synchronously from
- * platform_device_register_simple() can take efivars_lock.
+ * platform_device_register_data() can take efivars_lock.
*/
- pdev = platform_device_register_simple("efivars", 0, NULL, 0);
- if (IS_ERR(pdev))
+ pdev = platform_device_register_data(NULL, EFIVARS_PDEV_NAME, 0,
+ &pdata, sizeof(pdata));
+ if (IS_ERR(pdev)) {
pr_warn("efi: failed to register efivars platform device: %pe\n",
pdev);
- else
- efivars_pdev = pdev;
+ return 0;
+ }
+
+ /*
+ * Any probe performed automatically by the driver core as part of
+ * registering the device has completed by now (for drivers that
+ * probe synchronously). Clear the flag so that consumers can tell
+ * such probes apart from later ones, e.g., explicit binds via sysfs.
+ * The device is already visible in sysfs, so a concurrent probe on
+ * another CPU may read the flag without serialization.
+ */
+ pdev_data = dev_get_platdata(&pdev->dev);
+ WRITE_ONCE(pdev_data->registering, false);
+ efivars_pdev = pdev;
return 0;
}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index cc1df1577d5f..c58ff1c1e206 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1069,6 +1069,17 @@ struct efivars {
const struct efivar_operations *ops;
};
+/*
+ * The "efivars" platform device is registered while the generic, EFI runtime
+ * services based efivars ops are registered and support SetVariable().
+ */
+#define EFIVARS_PDEV_NAME "efivars"
+
+struct efivars_pdev_data {
+ /* true only while platform_device_register_data() is in progress */
+ bool registering;
+};
+
#ifdef CONFIG_X86
u64 __attribute_const__ efivar_reserved_space(void);
#else
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread