Skip to contentSkip to conversation

efivarfs: add nostatfs mount option to skip QueryVariableInfo()

PATCH Superseded Prashant Singh 5 participants 13 messages Sep 28 – Oct 5

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 efivarfs: add nostatfs mount option to skip QueryVariableInfo()

QueryVariableInfo() is an EFI runtime service that, on some firmware, takes tens of milliseconds and runs with preemption disabled, stalling the CPU that services it. efivarfs_statfs() calls it (rate-limited since commit b2326338dc68 ("efivarfs: Rate limit statfs() handler")) to report the variable-store used/available capacity, so any statfs(2) -- e.g. every "df" -- can inject that stall into unrelated latency-sensitive workloads on the same CPU.

Add a negatable "nostatfs" mount option: with nostatfs, statfs(2) skips QueryVariableInfo() and reports zero used/available; with statfs it reports the capacity as before. It defaults to nostatfs on CONFIG_PREEMPT_RT so real-time kernels do not take the stall out of the box, but statfs can be passed there to force reporting back on -- e.g. for tools such as fwupd that need the efivars free space to update Secure Boot key databases.

The option can also be toggled on a live mount via remount, so reporting can be enabled only for the duration of a firmware update without unmounting the boot-time efivarfs mount:

mount -o remount,statfs /sys/firmware/efi/efivars # reporting on
mount -o remount,nostatfs /sys/firmware/efi/efivars # reporting off

Tested on an Intel Xeon E5-2628L v4, 6.12 kernel, via "strace -T -e trace=statfs df" on the efivarfs mount.

Cost of the firmware call (CONFIG_PREEMPT_RT not set, so reporting is enabled by default). Default mount calls QueryVariableInfo() and returns the real store capacity, ~66-129 ms per call:

statfs("/sys/firmware/efi/efivars", {f_type=EFIVARFS_MAGIC,

      f_bsize=1, f_blocks=90024, f_bfree=33387, f_bavail=28267, ...})
      = 0 <0.129124>

With -o nostatfs the firmware call is skipped, capacity reported as zero, ~11 us per call:

statfs("/sys/firmware/efi/efivars", {f_type=EFIVARFS_MAGIC,

      f_bsize=1, f_blocks=0, f_bfree=0, f_bavail=0, ...}) = 0 <0.000011>

PREEMPT_RT default and live remount toggle (CONFIG_PREEMPT_RT=y). The boot-time mount defaults to nostatfs (mount shows nostatfs); no firmware call, capacity zero:

statfs(... f_blocks=0, f_bfree=0, f_bavail=0, ...) = 0 <0.000018>

Enabling reporting in place with "mount -o remount,statfs" (mount now shows statfs) takes the ~70 ms firmware call and returns the real capacity, without unmounting:

statfs(... f_blocks=90024, f_bfree=30315, f_bavail=25195, ...)

      = 0 <0.070293>

Disabling it again with "mount -o remount,nostatfs" returns to the fast, zero-capacity path:

statfs(... f_blocks=0, f_bfree=0, f_bavail=0, ...) = 0 <0.000014>

An unrelated remount that does not respecify the option preserves it: a "mount -o remount,rw" after "remount,statfs" leaves the mount showing statfs.

---
Changes since v3:
- Drop the show_options "statfs" branch; the absence of "nostatfs" now indicates reporting is on (Ard Biesheuvel).
- Drop the uid/gid copies on the remount path; efivarfs_reconfigure() applies only nostatfs, so they were dead code (Ard Biesheuvel).

Changes since v2:
- Make the flag negatable (fsparam_flag_no): "statfs" forces reporting back on, "nostatfs" skips QueryVariableInfo(). Default stays nostatfs on PREEMPT_RT. This lets fwupd get the efivars free space it needs for Secure Boot key (KEK/DB/DBX) updates on an RT kernel by mounting with -o statfs (Luis Claudio R. Goncalves, Steve McIntyre).
- Support toggling the option on a live mount via remount, so reporting can be enabled just for a firmware update without unmounting efivarfs (Sebastian Andrzej Siewior). Options not respecified on remount are preserved.
- Add PREEMPT_RT + remount test data to the commit message.

Changes since v1:
- Replace the sysctl with a mount option named "nostatfs", per review (Ard Biesheuvel).

v1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/

 Documentation/filesystems/efivarfs.rst | 16 +++++++++++
 fs/efivarfs/internal.h                 |  1 +
 fs/efivarfs/super.c                    | 38 ++++++++++++++++++++++----
 3 files changed, 50 insertions(+), 5 deletions(-)
Documentation/filesystems/efivarfs.rst +16 -0
index f646c3f0980f..cd81ee84115b 100644
@@ -37,6 +37,22 @@ accidentally.
           |4_bytes_of_attributes + efivar_data|
           +-----------------------------------+
 
+Mount options
+=============
+
+statfs / nostatfs
+      Control whether ``statfs(2)`` reports the variable-store used/available
+      capacity. Obtaining it requires the ``QueryVariableInfo()`` EFI runtime
+      service, which on some firmware takes tens of milliseconds and runs with
+      preemption disabled, stalling the calling CPU. With ``nostatfs`` the call
+      is skipped and ``statfs(2)`` reports zero. The default is to report,
+      except on ``CONFIG_PREEMPT_RT`` where it defaults to ``nostatfs``; pass
+      ``statfs`` there to force reporting back on (e.g. for tools such as fwupd
+      that need the free space for firmware updates). The option can also be
+      flipped on a live mount with ``mount -o remount,statfs`` /
+      ``mount -o remount,nostatfs``, so reporting can be enabled only for the
+      duration of a firmware update without unmounting efivarfs.
+
 *See also:*
 
 - Documentation/admin-guide/acpi/ssdt-overlays.rst
fs/efivarfs/internal.h +1 -0
index f913b6824289..0cb053884b4b 100644
@@ -11,6 +11,7 @@
 struct efivarfs_mount_opts {
 	kuid_t uid;
 	kgid_t gid;
+	bool nostatfs;		/* skip QueryVariableInfo() in statfs() */
 };
 
 struct efivarfs_fs_info {
fs/efivarfs/super.c +33 -5
index 8d33f11db2a1..efeada6e314f 100644
@@ -74,6 +74,9 @@ static int efivarfs_show_options(struct seq_file *m, struct dentry *root)
 	if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
 		seq_printf(m, ",gid=%u",
 				from_kgid_munged(&init_user_ns, opts->gid));
+	/* Absence of nostatfs means statfs() reports real capacity. */
+	if (opts->nostatfs)
+		seq_puts(m, ",nostatfs");
 	return 0;
 }
 
@@ -82,13 +85,19 @@ static int efivarfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	const u32 attr = EFI_VARIABLE_NON_VOLATILE |
 			 EFI_VARIABLE_BOOTSERVICE_ACCESS |
 			 EFI_VARIABLE_RUNTIME_ACCESS;
+	struct efivarfs_fs_info *sfi = dentry->d_sb->s_fs_info;
 	u64 storage_space, remaining_space, max_variable_size;
 	u64 id = huge_encode_dev(dentry->d_sb->s_dev);
 	efi_status_t status;
 
-	/* Some UEFI firmware does not implement QueryVariableInfo() */
+	/*
+	 * Some UEFI firmware does not implement QueryVariableInfo(); the
+	 * nostatfs mount option also disables this (preempt-disabled,
+	 * potentially slow) call entirely, reporting zero used/available.
+	 */
 	storage_space = remaining_space = 0;
-	if (efi_rt_services_supported(EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO)) {
+	if (!READ_ONCE(sfi->mount_opts.nostatfs) &&
+	    efi_rt_services_supported(EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO)) {
 		static DEFINE_RATELIMIT_STATE(_rs, 2 * HZ, 5);
 		static u64 storage, remaining;
 		static DEFINE_SPINLOCK(lock);
@@ -323,12 +332,13 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
 }
 
 enum {
-	Opt_uid, Opt_gid,
+	Opt_uid, Opt_gid, Opt_statfs,
 };
 
 static const struct fs_parameter_spec efivarfs_parameters[] = {
 	fsparam_uid("uid", Opt_uid),
 	fsparam_gid("gid", Opt_gid),
+	fsparam_flag_no("statfs", Opt_statfs),
 	{},
 };
 
@@ -350,6 +360,9 @@ static int efivarfs_parse_param(struct fs_context *fc, struct fs_parameter *para
 	case Opt_gid:
 		opts->gid = result.gid;
 		break;
+	case Opt_statfs:
+		opts->nostatfs = result.negated;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -402,11 +415,17 @@ static int efivarfs_get_tree(struct fs_context *fc)
 
 static int efivarfs_reconfigure(struct fs_context *fc)
 {
+	struct efivarfs_fs_info *sfi = fc->root->d_sb->s_fs_info;
+	struct efivarfs_fs_info *new_sfi = fc->s_fs_info;
+
 	if (!efivar_supports_writes() && !(fc->sb_flags & SB_RDONLY)) {
 		pr_err("Firmware does not support SetVariableRT. Can not remount with rw\n");
 		return -EINVAL;
 	}
 
+	/* statfs() reads nostatfs without s_umount; mark the concurrent update. */
+	WRITE_ONCE(sfi->mount_opts.nostatfs, new_sfi->mount_opts.nostatfs);
+
 	return 0;
 }
 
@@ -524,8 +543,17 @@ static int efivarfs_init_fs_context(struct fs_context *fc)
 	if (!sfi)
 		return -ENOMEM;
 
-	sfi->mount_opts.uid = GLOBAL_ROOT_UID;
-	sfi->mount_opts.gid = GLOBAL_ROOT_GID;
+	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
+		/* nostatfs is writable via remount; keep it if not respecified. */
+		struct efivarfs_fs_info *old = fc->root->d_sb->s_fs_info;
+
+		sfi->mount_opts.nostatfs = READ_ONCE(old->mount_opts.nostatfs);
+	} else {
+		sfi->mount_opts.uid = GLOBAL_ROOT_UID;
+		sfi->mount_opts.gid = GLOBAL_ROOT_GID;
+		/* QueryVariableInfo() stalls the CPU; default nostatfs on PREEMPT_RT. */
+		sfi->mount_opts.nostatfs = IS_ENABLED(CONFIG_PREEMPT_RT);
+	}
 
 	fc->s_fs_info = sfi;
 	fc->ops = &efivarfs_context_ops;

base-commit: 9b87fdc9af2fbfcdb5c24a64139685ef80f6573f

Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] vfs: missing READ_ONCE() for opts->nostatfs in efivarfs_show_options() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] vfs: missing READ_ONCE() for opts->nostatfs in efivarfs_show_options() --

commit 8539129e21537b2431de520ca79339783ffada2d
Author: Prashant Singh <[email protected]>
Subject: efivarfs: add nostatfs mount option to skip QueryVariableInfo()

This commit adds a negatable "nostatfs" mount option to efivarfs. It skips the EFI QueryVariableInfo() call during statfs(2), which can take tens of milliseconds and run with preemption disabled. The option can also be toggled on a live mount via remount.

fs/efivarfs/super.c static int efivarfs_show_options(struct seq_file *m, struct dentry *root) · line 78

Quoted 10 lines
fs/efivarfs/super.c +2 -0
index 8d33f11db2a1b..efeada6e314f4 100644
@@ -74,6 +74,9 @@ static int efivarfs_show_options(struct seq_file *m, struct dentry *root)
 	if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
 		seq_printf(m, ",gid=%u",
 				from_kgid_munged(&init_user_ns, opts->gid));
+	/* Absence of nostatfs means statfs() reports real capacity. */
+	if (opts->nostatfs)
       ^^^^

[Severity: Low]
Is a READ_ONCE() needed here?

This plain C read of opts->nostatfs in efivarfs_show_options() can race with the concurrent WRITE_ONCE() in efivarfs_reconfigure() during a remount.

A userspace process reading /proc/mounts calls efivarfs_show_options() holding only namespace_sem for read, while a concurrent mount -o remount calls efivarfs_reconfigure() holding only sb->s_umount for write. Because no common lock serializes these two paths, missing the READ_ONCE() here could lead to a KCSAN data race splat.

Quoted 3 lines
fs/efivarfs/super.c +1 -0
+		seq_puts(m, ",nostatfs");
 	return 0;
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Prashant Singh
Quoted 65 lines · Prashant Singh

QueryVariableInfo() is an EFI runtime service that, on some firmware, takes tens of milliseconds and runs with preemption disabled, stalling the CPU that services it. efivarfs_statfs() calls it (rate-limited since commit b2326338dc68 ("efivarfs: Rate limit statfs() handler")) to report the variable-store used/available capacity, so any statfs(2) -- e.g. every "df" -- can inject that stall into unrelated latency-sensitive workloads on the same CPU.

Add a negatable "nostatfs" mount option: with nostatfs, statfs(2) skips QueryVariableInfo() and reports zero used/available; with statfs it reports the capacity as before. It defaults to nostatfs on CONFIG_PREEMPT_RT so real-time kernels do not take the stall out of the box, but statfs can be passed there to force reporting back on -- e.g. for tools such as fwupd that need the efivars free space to update Secure Boot key databases.

The option can also be toggled on a live mount via remount, so reporting can be enabled only for the duration of a firmware update without unmounting the boot-time efivarfs mount:

mount -o remount,statfs /sys/firmware/efi/efivars # reporting on
mount -o remount,nostatfs /sys/firmware/efi/efivars # reporting off

Tested on an Intel Xeon E5-2628L v4, 6.12 kernel, via "strace -T -e trace=statfs df" on the efivarfs mount.

Cost of the firmware call (CONFIG_PREEMPT_RT not set, so reporting is enabled by default). Default mount calls QueryVariableInfo() and returns the real store capacity, ~66-129 ms per call:

statfs("/sys/firmware/efi/efivars", {f_type=EFIVARFS_MAGIC,

      f_bsize=1, f_blocks=90024, f_bfree=33387, f_bavail=28267, ...})
      = 0 <0.129124>

With -o nostatfs the firmware call is skipped, capacity reported as zero, ~11 us per call:

statfs("/sys/firmware/efi/efivars", {f_type=EFIVARFS_MAGIC,

      f_bsize=1, f_blocks=0, f_bfree=0, f_bavail=0, ...}) = 0 <0.000011>

PREEMPT_RT default and live remount toggle (CONFIG_PREEMPT_RT=y). The boot-time mount defaults to nostatfs (mount shows nostatfs); no firmware call, capacity zero:

statfs(... f_blocks=0, f_bfree=0, f_bavail=0, ...) = 0 <0.000018>

Enabling reporting in place with "mount -o remount,statfs" (mount now shows statfs) takes the ~70 ms firmware call and returns the real capacity, without unmounting:

statfs(... f_blocks=90024, f_bfree=30315, f_bavail=25195, ...)

      = 0 <0.070293>

Disabling it again with "mount -o remount,nostatfs" returns to the fast, zero-capacity path:

statfs(... f_blocks=0, f_bfree=0, f_bavail=0, ...) = 0 <0.000014>

An unrelated remount that does not respecify the option preserves it: a "mount -o remount,rw" after "remount,statfs" leaves the mount showing statfs.

Quoted 7 lines

---
Changes since v3:
- Drop the show_options "statfs" branch; the absence of "nostatfs" now indicates reporting is on (Ard Biesheuvel).
- Drop the uid/gid copies on the remount path; efivarfs_reconfigure() applies only nostatfs, so they were dead code (Ard Biesheuvel).

Please don't respond to questions by respinning the patch without having any discussion at all.

I asked you an honest question, and it seems Sashiko spotted an issue here too.

Is there a problem with how the current code deals with uid and gid on a remount?

#3 lore raw
In reply to Prashant Singh
Quoted 20 lines · Prashant Singh

QueryVariableInfo() is an EFI runtime service that, on some firmware, takes tens of milliseconds and runs with preemption disabled, stalling the CPU that services it. efivarfs_statfs() calls it (rate-limited since commit b2326338dc68 ("efivarfs: Rate limit statfs() handler")) to report the variable-store used/available capacity, so any statfs(2) -- e.g. every "df" -- can inject that stall into unrelated latency-sensitive workloads on the same CPU.

Add a negatable "nostatfs" mount option: with nostatfs, statfs(2) skips QueryVariableInfo() and reports zero used/available; with statfs it reports the capacity as before. It defaults to nostatfs on CONFIG_PREEMPT_RT so real-time kernels do not take the stall out of the box, but statfs can be passed there to force reporting back on -- e.g. for tools such as fwupd that need the efivars free space to update Secure Boot key databases.

The option can also be toggled on a live mount via remount, so reporting can be enabled only for the duration of a firmware update without unmounting the boot-time efivarfs mount:

Quoted 5 lines

mount -o remount,statfs /sys/firmware/efi/efivars # reporting on
mount -o remount,nostatfs /sys/firmware/efi/efivars # reporting off

Tested on an Intel Xeon E5-2628L v4, 6.12 kernel, via "strace -T -e trace=statfs df" on the efivarfs mount.

This until the end looks extremely verbose. Even if that statfs takes ages, that important part is that it does so with disables preemption. There has been also the introduction of the efi_runtime workqueue which can be pinned to a single CPU. I guess this doesn't work for you or the EFI firmware takes all other CPUs down until the all completes.

Quoted 36 lines

Cost of the firmware call (CONFIG_PREEMPT_RT not set, so reporting is enabled by default). Default mount calls QueryVariableInfo() and returns the real store capacity, ~66-129 ms per call:

statfs("/sys/firmware/efi/efivars", {f_type=EFIVARFS_MAGIC,

      f_bsize=1, f_blocks=90024, f_bfree=33387, f_bavail=28267, ...})
      = 0 <0.129124>

With -o nostatfs the firmware call is skipped, capacity reported as zero, ~11 us per call:

statfs("/sys/firmware/efi/efivars", {f_type=EFIVARFS_MAGIC,

      f_bsize=1, f_blocks=0, f_bfree=0, f_bavail=0, ...}) = 0 <0.000011>

PREEMPT_RT default and live remount toggle (CONFIG_PREEMPT_RT=y). The boot-time mount defaults to nostatfs (mount shows nostatfs); no firmware call, capacity zero:

statfs(... f_blocks=0, f_bfree=0, f_bavail=0, ...) = 0 <0.000018>

Enabling reporting in place with "mount -o remount,statfs" (mount now shows statfs) takes the ~70 ms firmware call and returns the real capacity, without unmounting:

statfs(... f_blocks=90024, f_bfree=30315, f_bavail=25195, ...)

      = 0 <0.070293>

Disabling it again with "mount -o remount,nostatfs" returns to the fast, zero-capacity path:

statfs(... f_blocks=0, f_bfree=0, f_bavail=0, ...) = 0 <0.000014>

An unrelated remount that does not respecify the option preserves it: a "mount -o remount,rw" after "remount,statfs" leaves the mount showing statfs.

…

Quoted 47 lines

---
Changes since v3:
- Drop the show_options "statfs" branch; the absence of "nostatfs" now indicates reporting is on (Ard Biesheuvel).
- Drop the uid/gid copies on the remount path; efivarfs_reconfigure() applies only nostatfs, so they were dead code (Ard Biesheuvel).

Changes since v2:
- Make the flag negatable (fsparam_flag_no): "statfs" forces reporting back on, "nostatfs" skips QueryVariableInfo(). Default stays nostatfs on PREEMPT_RT. This lets fwupd get the efivars free space it needs for Secure Boot key (KEK/DB/DBX) updates on an RT kernel by mounting with -o statfs (Luis Claudio R. Goncalves, Steve McIntyre).
- Support toggling the option on a live mount via remount, so reporting can be enabled just for a firmware update without unmounting efivarfs (Sebastian Andrzej Siewior). Options not respecified on remount are preserved.
- Add PREEMPT_RT + remount test data to the commit message.

Changes since v1:
- Replace the sysctl with a mount option named "nostatfs", per review (Ard Biesheuvel).

v1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/

 Documentation/filesystems/efivarfs.rst | 16 +++++++++++
 fs/efivarfs/internal.h                 |  1 +
 fs/efivarfs/super.c                    | 38 ++++++++++++++++++++++----
 3 files changed, 50 insertions(+), 5 deletions(-)
Documentation/filesystems/efivarfs.rst +5 -0
index f646c3f0980f..cd81ee84115b 100644
@@ -37,6 +37,22 @@ accidentally.
           |4_bytes_of_attributes + efivar_data|
           +-----------------------------------+
 
+Mount options
+=============
+
+statfs / nostatfs
+      Control whether ``statfs(2)`` reports the variable-store used/available

Documentation/filesystems/efivarfs.rst accidentally. · line 54

Quoted 10 lines
Documentation/filesystems/efivarfs.rst +10 -0
+      capacity. Obtaining it requires the ``QueryVariableInfo()`` EFI runtime
+      service, which on some firmware takes tens of milliseconds and runs with
+      preemption disabled, stalling the calling CPU. With ``nostatfs`` the call
+      is skipped and ``statfs(2)`` reports zero. The default is to report,
+      except on ``CONFIG_PREEMPT_RT`` where it defaults to ``nostatfs``; pass
+      ``statfs`` there to force reporting back on (e.g. for tools such as fwupd
+      that need the free space for firmware updates). The option can also be
+      flipped on a live mount with ``mount -o remount,statfs`` /
+      ``mount -o remount,nostatfs``, so reporting can be enabled only for the
+      duration of a firmware update without unmounting efivarfs.

could this be, I don't know something smaller not including the commandline where I would expect that people know how to use it.

=================== =========================================================
(no)statfs Control whether ``statfs(2)`` reports the variable-store
used/ available. Disabling it skips the EFI runtime service call, which might block the CPU for a few milliseconds, reporting 0 for used and capacity. Enabled by default on PREEMPT_RT.
=================== =========================================================

It might make sense to add this knob to Documentation/core-api/real-time/hardware.rst. I am not sure yet but slowly we are getting more knobs that I have expected.

fs/efivarfs/internal.h line 14

Quoted 13 lines
Documentation/filesystems/efivarfs.rst +1 -0
+
 *See also:*
 
 - Documentation/admin-guide/acpi/ssdt-overlays.rst
fs/efivarfs/internal.h +1 -0
index f913b6824289..0cb053884b4b 100644
@@ -11,6 +11,7 @@
 struct efivarfs_mount_opts {
 	kuid_t uid;
 	kgid_t gid;
+	bool nostatfs;		/* skip QueryVariableInfo() in statfs() */

Here and below you add a comment to every change you make. What about focusing on the important parts, that deserve an explanation why a change has been made. For instance why nostatfs has the READ_ONCE/ WRITE_ONCE accessors and sometimes it does not.

fs/efivarfs/internal.h line 16

Quoted 2 lines
fs/efivarfs/internal.h +0 -0
 };
 

Sebastian

maintainer
#4 lore raw

Hi Sebastian,

Thanks for taking a look.

Quoted 24 lines · Sebastian Andrzej Siewior
Quoted 23 lines · Prashant Singh

QueryVariableInfo() is an EFI runtime service that, on some firmware, takes tens of milliseconds and runs with preemption disabled, stalling the CPU that services it. efivarfs_statfs() calls it (rate-limited since commit b2326338dc68 ("efivarfs: Rate limit statfs() handler")) to report the variable-store used/available capacity, so any statfs(2) -- e.g. every "df" -- can inject that stall into unrelated latency-sensitive workloads on the same CPU.

Add a negatable "nostatfs" mount option: with nostatfs, statfs(2) skips QueryVariableInfo() and reports zero used/available; with statfs it reports the capacity as before. It defaults to nostatfs on CONFIG_PREEMPT_RT so real-time kernels do not take the stall out of the box, but statfs can be passed there to force reporting back on -- e.g. for tools such as fwupd that need the efivars free space to update Secure Boot key databases.

The option can also be toggled on a live mount via remount, so reporting can be enabled only for the duration of a firmware update without unmounting the boot-time efivarfs mount:

mount -o remount,statfs /sys/firmware/efi/efivars # reporting on
mount -o remount,nostatfs /sys/firmware/efi/efivars # reporting off

Quoted 9 lines
Quoted 2 lines

Tested on an Intel Xeon E5-2628L v4, 6.12 kernel, via "strace -T -e trace=statfs df" on the efivarfs mount.

This until the end looks extremely verbose. Even if that statfs takes ages, that important part is that it does so with disables preemption. There has been also the introduction of the efi_runtime workqueue which can be pinned to a single CPU. I guess this doesn't work for you or the EFI firmware takes all other CPUs down until the all completes.

Yeah the most severe issue is that entering SMM requires a rendez-vous of all the cores, and so whether preemption is enabled or not is actually kind of irrelevant, given that all the other cores just disappear.

...

Quoted 27 lines
Quoted 13 lines
Documentation/filesystems/efivarfs.rst +5 -0
index f646c3f0980f..cd81ee84115b 100644
@@ -37,6 +37,22 @@ accidentally.
           |4_bytes_of_attributes + efivar_data|
           +-----------------------------------+
 
+Mount options
+=============
+
+statfs / nostatfs
+      Control whether ``statfs(2)`` reports the variable-store used/available

Documentation/filesystems/efivarfs.rst accidentally. · line 54

Quoted 10 lines
Documentation/filesystems/efivarfs.rst +10 -0
+      capacity. Obtaining it requires the ``QueryVariableInfo()`` EFI runtime
+      service, which on some firmware takes tens of milliseconds and runs with
+      preemption disabled, stalling the calling CPU. With ``nostatfs`` the call
+      is skipped and ``statfs(2)`` reports zero. The default is to report,
+      except on ``CONFIG_PREEMPT_RT`` where it defaults to ``nostatfs``; pass
+      ``statfs`` there to force reporting back on (e.g. for tools such as fwupd
+      that need the free space for firmware updates). The option can also be
+      flipped on a live mount with ``mount -o remount,statfs`` /
+      ``mount -o remount,nostatfs``, so reporting can be enabled only for the
+      duration of a firmware update without unmounting efivarfs.

could this be, I don't know something smaller not including the commandline where I would expect that people know how to use it.

Quoted 10 lines

===================
=========================================================
(no)statfs Control whether ``statfs(2)`` reports the variable-store
used/ available. Disabling it skips the EFI runtime service call, which might block the CPU for a few milliseconds, reporting 0 for used and capacity. Enabled by default on PREEMPT_RT.
===================
=========================================================

+1

Quoted 8 lines

It might make sense to add this knob to Documentation/core-api/real-time/hardware.rst.
I am not sure yet but slowly we are getting more knobs that I have expected.

Quoted 3 lines
Documentation/filesystems/efivarfs.rst +1 -0
+
 *See also:*
 
Quoted 15 lines

fs/efivarfs/internal.h line 14

Quoted 10 lines
Documentation/filesystems/efivarfs.rst +0 -0
 - Documentation/admin-guide/acpi/ssdt-overlays.rst
fs/efivarfs/internal.h +1 -0
index f913b6824289..0cb053884b4b 100644
@@ -11,6 +11,7 @@
 struct efivarfs_mount_opts {
 	kuid_t uid;
 	kgid_t gid;
+	bool nostatfs;		/* skip QueryVariableInfo() in statfs() */

Here and below you add a comment to every change you make. What about focusing on the important parts, that deserve an explanation why a change has been made. For instance why nostatfs has the READ_ONCE/ WRITE_ONCE accessors and sometimes it does not.

AIUI the READ_ONCE/WRITE_ONCE were added because Sashiko warned about potential KCSAN splats? It would be nice to mention that.

In any case, KCSAN is runtime instrumentation, and efi_reboot_required() is only called after all other CPUs have been brought down. So if anything, this should just wrap the read on the reboot path in a data_race() so that we don't trigger any instrumentation inadvertently on the way down.

#5 lore raw
Quoted 1 line · Ard Biesheuvel

Hi Sebastian,

Hi Ard,

Quoted 1 line

Thanks for taking a look.

doing my best…

Quoted 13 lines
Quoted 12 lines

fs/efivarfs/internal.h line 14

Quoted 7 lines
fs/efivarfs/internal.h +1 -0
@@ -11,6 +11,7 @@
 struct efivarfs_mount_opts {
 	kuid_t uid;
 	kgid_t gid;
+	bool nostatfs;		/* skip QueryVariableInfo() in statfs() */

Here and below you add a comment to every change you make. What about focusing on the important parts, that deserve an explanation why a change has been made. For instance why nostatfs has the READ_ONCE/ WRITE_ONCE accessors and sometimes it does not.

Quoted 2 lines

AIUI the READ_ONCE/WRITE_ONCE were added because Sashiko warned about potential KCSAN splats? It would be nice to mention that.

:)

Quoted 4 lines

In any case, KCSAN is runtime instrumentation, and efi_reboot_required() is only called after all other CPUs have been brought down. So if anything, this should just wrap the read on the reboot path in a data_race() so that we don't trigger any instrumentation inadvertently on the way down.

Right. So if anything, there could be a data_race() in one place instead inconsistent READ/ WRITE once as we have it now.

Sebastian

#6 lore raw

Thanks Ard and Sebastian for the comments.

Quoted 2 lines

Please don't respond to questions by respinning the patch without having any discussion at all.

Noted, and apologies for sending v4 without first finalizing the v3 discussion.

Quoted 4 lines

I asked you an honest question, and it seems Sashiko spotted an issue here too.
Is there a problem with how the current code deals with uid and gid on a remount?

No, I checked and did not find a problem. I mentioned this in my response to your query on v3:
https://lore.kernel.org/all/[email protected]/

Quoted 1 line

This until the end looks extremely verbose.

I can drop the strace data from the commit message if that reads cleaner; I had included it to highlight the issue.

Quoted 11 lines

could this be, I don't know something smaller not including the commandline where I would expect that people know how to use it.

=================== =========================================================
(no)statfs Control whether ``statfs(2)`` reports the variable-store
used/ available. Disabling it skips the EFI runtime service call, which might block the CPU for a few milliseconds, reporting 0 for used and capacity. Enabled by default on PREEMPT_RT.
=================== =========================================================

Quoted 1 line

It might make sense to add this knob to Documentation/core-api/real-time/hardware.rst.

Thanks, I will use this wording and move it to
Documentation/core-api/real-time/hardware.rst.

Quoted 4 lines

Here and below you add a comment to every change you make. What about focusing on the important parts, that deserve an explanation why a change has been made. For instance why nostatfs has the READ_ONCE/ WRITE_ONCE accessors and sometimes it does not.

Apologies, that was a miss on my part, and I saw that sashiko-bot flagged it too. I wanted to gather any additional comments before addressing it.

Quoted 4 lines

Yeah the most severe issue is that entering SMM requires a rendez-vous of all the cores, and so whether preemption is enabled or not is actually kind of irrelevant, given that all the other cores just disappear.

Yes, I observed the same behavior. I was not sure whether this is x86-specific, so I refrained from mentioning it in the commit log.

Quoted 2 lines

Right. So if anything, there could be a data_race() in one place instead inconsistent READ/ WRITE once as we have it now.

I would use data_race() on the write for nostatfs. Please let me know if the below looks OK:

    /* nostatfs is read locklessly by statfs()/show_options(); the racy update is benign. */
    data_race(sfi->mount_opts.nostatfs = new_sfi->mount_opts.nostatfs);

Thanks,
Prashant

maintainer
#7 lore raw
Quoted 8 lines · Prashant Singh

Thanks Ard and Sebastian for the comments.

Quoted 2 lines

Please don't respond to questions by respinning the patch without having any discussion at all.

Noted, and apologies for sending v4 without first finalizing the v3 discussion.

Quoted 9 lines
Quoted 4 lines

I asked you an honest question, and it seems Sashiko spotted an issue here too.
Is there a problem with how the current code deals with uid and gid on a remount?

No, I checked and did not find a problem. I mentioned this in my response to your query on v3:
https://lore.kernel.org/all/[email protected]/

Apologies, I missed that.

Quoted 5 lines
Quoted 1 line

This until the end looks extremely verbose.

I can drop the strace data from the commit message if that reads cleaner; I had included it to highlight the issue.

Yeah you can trim it a bit but git commit log space is cheap and only people that care about the patch will read it anyway.

As for the docs and code comment changes themselves, please make those a bit more to the point. People can go and find the commit that introduced/updated them to know more about the background.

Quoted 7 lines
Quoted 7 lines

could this be, I don't know something smaller not including the commandline where I would expect that people know how to use it.

=================== =========================================================
(no)statfs Control whether ``statfs(2)`` reports the variable-store
used/ available. Disabling it skips the EFI runtime service call, which might block the CPU for a few milliseconds,

might block all CPUs for a few milliseconds.

Quoted 1 line
Quoted 1 line

reporting 0 for used and capacity. Enabled by default on

Instead, report 0/0 for used/available.

Quoted 17 lines
Quoted 4 lines

PREEMPT_RT.
=================== =========================================================

It might make sense to add this knob to Documentation/core-api/real-time/hardware.rst.

Thanks, I will use this wording and move it to
Documentation/core-api/real-time/hardware.rst.

Quoted 4 lines

Here and below you add a comment to every change you make. What about focusing on the important parts, that deserve an explanation why a change has been made. For instance why nostatfs has the READ_ONCE/ WRITE_ONCE accessors and sometimes it does not.

Apologies, that was a miss on my part, and I saw that sashiko-bot flagged it too. I wanted to gather any additional comments before addressing it.

Quoted 8 lines
Quoted 4 lines

Yeah the most severe issue is that entering SMM requires a rendez-vous of all the cores, and so whether preemption is enabled or not is actually kind of irrelevant, given that all the other cores just disappear.

Yes, I observed the same behavior. I was not sure whether this is x86-specific, so I refrained from mentioning it in the commit log.

It is x86 specific but that is the main reason we need any of this.

Quoted 10 lines
Quoted 2 lines

Right. So if anything, there could be a data_race() in one place instead inconsistent READ/ WRITE once as we have it now.

I would use data_race() on the write for nostatfs. Please let me know if the below looks OK:

    /* nostatfs is read locklessly by statfs()/show_options(); the racy 
update is benign. */
    data_race(sfi->mount_opts.nostatfs = new_sfi->mount_opts.nostatfs);

AFAICT, that would potentially leave KCSAN instrumentation on the reboot path, which might trigger and interfere with the reboot. So instead, I'd like to put this in efi_reboot_required if we can. If it is needed in more places to address an actual KCSAN splat, I don't mind. If it is just to make Sashiko happy, then we shouldn't bother.

#8 lore raw
In reply to Prashant Singh
Quoted 11 lines · Prashant Singh
Quoted 11 lines

could this be, I don't know something smaller not including the commandline where I would expect that people know how to use it.

=================== =========================================================
(no)statfs Control whether ``statfs(2)`` reports the variable-store
used/ available. Disabling it skips the EFI runtime service call, which might block the CPU for a few milliseconds, reporting 0 for used and capacity. Enabled by default on PREEMPT_RT.
=================== =========================================================

Quoted 4 lines
Quoted 1 line

It might make sense to add this knob to Documentation/core-api/real-time/hardware.rst.

Thanks, I will use this wording and move it to
Documentation/core-api/real-time/hardware.rst.

Please keep this description _here_ where you have it. Once this is merged, you could send another patch, extending the documentation with the statfs option (I think the workqueue change is in).

You still have the problem that someone reading the variable leads to the same program but this requires a privileged user. And if I am not mistaken, someone sent patches to have efi-runtime runtime disabled/ enabled.

Quoted 2 lines

Thanks,
Prashant

Sebastian

#9 lore raw

Thanks Ard and Sebastian for the comments.

Quoted 2 lines

Yeah you can trim it a bit but git commit log space is cheap and only people that care about the patch will read it anyway.

Will do.

Quoted 3 lines

As for the docs and code comment changes themselves, please make those a bit more to the point. People can go and find the commit that introduced/updated them to know more about the background.

Will do.

Quoted 8 lines
Quoted 2 lines

used/ available. Disabling it skips the EFI runtime service call, which might block the CPU for a few milliseconds,

might block all CPUs for a few milliseconds.

Quoted 1 line

reporting 0 for used and capacity. Enabled by default on

Instead, report 0/0 for used/available.

Will take care of this.

Quoted 5 lines

AFAICT, that would potentially leave KCSAN instrumentation on the reboot path, which might trigger and interfere with the reboot. So instead, I'd like to put this in efi_reboot_required if we can. If it is needed in more places to address an actual KCSAN splat, I don't mind. If it is just to make Sashiko happy, then we shouldn't bother.

Could you please clarify what you mean by efi_reboot_required here? nostatfs is only read in efivarfs_statfs(), efivarfs_show_options() and efivarfs_init_fs_context(), none of which run on the reboot path, so I'm not sure how it would apply.

On the annotation itself: an internal review flagged a potential KCSAN data race rather than an observed splat -- statfs() can run concurrently with a remount updating the flag, so it is a genuine (benign) concurrent access. I ran concurrent statfs/remount loops on separate CPUs under KCSAN and didn't trigger a report in a bounded run, which could be expected given KCSAN samples accesses, so it doesn't disprove the race. Since KCSAN only needs one side of the pair marked, data_race() on the write covers both readers and the reads stay plain. I'm happy to drop it entirely if you'd prefer to keep the benign race unannotated.

Quoted 3 lines

Please keep this description _here_ where you have it. Once this is merged, you could send another patch, extending the documentation with the statfs option (I think the workqueue change is in).

Sure -- I'll keep it in Documentation/filesystems/efivarfs.rst for now and send a follow-up extending Documentation/core-api/real-time/hardware.rst once this is merged.

Quoted 4 lines

You still have the problem that someone reading the variable leads to the same problem but this requires a privileged user. And if I am not mistaken, someone sent patches to have efi-runtime runtime disabled/ enabled.

Agreed -- the variable-read path is the same, but needs a privileged user unlike the unprivileged statfs()/df trigger.

Thanks,
Prashant

maintainer
#10 lore raw
Quoted 2 lines · Prashant Singh

Thanks Ard and Sebastian for the comments.

...

Quoted 11 lines
Quoted 5 lines

AFAICT, that would potentially leave KCSAN instrumentation on the reboot path, which might trigger and interfere with the reboot. So instead, I'd like to put this in efi_reboot_required if we can. If it is needed in more places to address an actual KCSAN splat, I don't mind. If it is just to make Sashiko happy, then we shouldn't bother.

Could you please clarify what you mean by efi_reboot_required here? nostatfs is only read in efivarfs_statfs(), efivarfs_show_options() and efivarfs_init_fs_context(), none of which run on the reboot path, so I'm not sure how it would apply.

Apologies, I managed to completely confuse myself here. Forget what I said here, please :-)

Quoted 10 lines

On the annotation itself: an internal review flagged a potential KCSAN data race rather than an observed splat -- statfs() can run concurrently with a remount updating the flag, so it is a genuine (benign) concurrent access. I ran concurrent statfs/remount loops on separate CPUs under KCSAN and didn't trigger a report in a bounded run, which could be expected given KCSAN samples accesses, so it doesn't disprove the race. Since KCSAN only needs one side of the pair marked, data_race() on the write covers both readers and the reads stay plain. I'm happy to drop it entirely if you'd prefer to keep the benign race unannotated.

No, let's keep it as you suggest.

Quoted 8 lines
Quoted 3 lines

Please keep this description _here_ where you have it. Once this is merged, you could send another patch, extending the documentation with the statfs option (I think the workqueue change is in).

Sure -- I'll keep it in Documentation/filesystems/efivarfs.rst for now and send a follow-up extending Documentation/core-api/real-time/hardware.rst once this is merged.

Quoted 8 lines
Quoted 4 lines

You still have the problem that someone reading the variable leads to the same problem but this requires a privileged user. And if I am not mistaken, someone sent patches to have efi-runtime runtime disabled/ enabled.

Agreed -- the variable-read path is the same, but needs a privileged user unlike the unprivileged statfs()/df trigger.

Indeed - this is only about anyone with read permissions on the mount point being able to trigger this. And looking at your results, the rate limit we added recently might be a bit too permissive as well.

#11 lore raw

Hi Prashant, Ard, Sebastian,

Regarding the concurrent update validation on efivarfs_reconfigure() and the KCSAN annotations discussed for the benign data race:

The implementation of data_race() directly wrapping the assignment of the nostatfs flag inside the reconfiguration path is clean and highly efficient for low-level standalone execution boundaries:

    data_race(sfi->mount_opts.nostatfs = new_sfi->mount_opts.nostatfs);

Since the reads inside efivarfs_statfs() and efivarfs_show_options() stay plain, this approach perfectly satisfies runtime instrumentation checks without adding dead memory barriers or locking overhead to unprivileged statfs(2)/df routines.

Furthermore, preventing the global CPU stall caused by the SMM rendezvous during QueryVariableInfo() on real-time environments (CONFIG_PREEMPT_RT) by defaulting to nostatfs is a major architectural improvement for deterministic scheduling.

For the final v5 patch spin, keeping the commit log focused on the preemption disabled context and dropping the verbose raw strace outputs as suggested makes the patch documentation extremely tight and industrial grade.

Acked-by: dev12124 (João Guilherme da Silva Freitas Lima) <[email protected]>

Em dom., 4 de out. de 2026 às 04:59, Ard Biesheuvel <[email protected]> escreveu:

Quoted 55 lines · Prashant Singh
Quoted 2 lines

Thanks Ard and Sebastian for the comments.

...

Quoted 11 lines
Quoted 5 lines

AFAICT, that would potentially leave KCSAN instrumentation on the reboot path, which might trigger and interfere with the reboot. So instead, I'd like to put this in efi_reboot_required if we can. If it is needed in more places to address an actual KCSAN splat, I don't mind. If it is just to make Sashiko happy, then we shouldn't bother.

Could you please clarify what you mean by efi_reboot_required here? nostatfs is only read in efivarfs_statfs(), efivarfs_show_options() and efivarfs_init_fs_context(), none of which run on the reboot path, so I'm not sure how it would apply.

Apologies, I managed to completely confuse myself here. Forget what I said here, please :-)

Quoted 10 lines

On the annotation itself: an internal review flagged a potential KCSAN data race rather than an observed splat -- statfs() can run concurrently with a remount updating the flag, so it is a genuine (benign) concurrent access. I ran concurrent statfs/remount loops on separate CPUs under KCSAN and didn't trigger a report in a bounded run, which could be expected given KCSAN samples accesses, so it doesn't disprove the race. Since KCSAN only needs one side of the pair marked, data_race() on the write covers both readers and the reads stay plain. I'm happy to drop it entirely if you'd prefer to keep the benign race unannotated.

No, let's keep it as you suggest.

Quoted 8 lines
Quoted 3 lines

Please keep this description _here_ where you have it. Once this is merged, you could send another patch, extending the documentation with the statfs option (I think the workqueue change is in).

Sure -- I'll keep it in Documentation/filesystems/efivarfs.rst for now and send a follow-up extending Documentation/core-api/real-time/hardware.rst once this is merged.

Quoted 8 lines
Quoted 4 lines

You still have the problem that someone reading the variable leads to the same problem but this requires a privileged user. And if I am not mistaken, someone sent patches to have efi-runtime runtime disabled/ enabled.

Agreed -- the variable-read path is the same, but needs a privileged user unlike the unprivileged statfs()/df trigger.

Indeed - this is only about anyone with read permissions on the mount point being able to trigger this. And looking at your results, the rate limit we added recently might be a bit too permissive as well.

#12 lore raw
Quoted 4 lines · MaeeFilho FL

For the final v5 patch spin, keeping the commit log focused on the preemption-disabled context and dropping the verbose raw strace outputs as suggested makes the patch documentation extremely tight and industrial grade.

Thanks, Joao. Done in v5: the commit log now keeps only the preemption-disabled rationale and the raw strace dumps are gone.

Quoted 1 line

No, let's keep it as you suggest.

Done -- kept as-is in v5.

v5 is posted here:
https://lore.kernel.org/all/[email protected]/

Thanks,
Prashant