Re: [PATCH v2 22/50] convert efivarfs

Christian Brauner
2025-11-05T13:43:42Z

[-- Attachment #1: Type: text/plain, Size: 765 bytes --]

> > > And suspend/resume works just fine with freeze/thaw. See commit
> > > eacfbf74196f ("power: freeze filesystems during suspend/resume")
> > > which implements exactly that.
> > >
> > > The reason this didn't work for you is very likely:
> > >
> > > cat /sys/power/freeze_filesystems
> > > 0
> > >
> > > which you must set to 1.
> >
> > Actually, no, that's not correct. The efivarfs freeze/thaw logic must
> > run unconditionally regardless of this setting to fix the systemd bug,
> > so all the variable resyncing is done in the thaw call, which isn't
> > conditioned on the above (or at least it shouldn't be).
>
> It is conditioned on the above currently but we can certainly fix it
> easily to not be.

Something like the appended patch would do it.

[-- Attachment #2: 0001-power-always-freeze-efivarfs.patch --]
[-- Type: text/x-diff, Size: 4586 bytes --]

From 1f9dc293cebb10b18d9ec8e01b60c014664c98ab Mon Sep 17 00:00:00 2001
From: Christian Brauner <brauner@kernel.org>
Date: Wed, 5 Nov 2025 14:39:45 +0100
Subject: [PATCH] power: always freeze efivarfs

The efivarfs filesystems must always be frozen and thawed to resync
variable state. Make it so.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/efivarfs/super.c | 1 +
fs/super.c | 14 +++++++++++---
include/linux/fs.h | 3 ++-
kernel/power/hibernate.c | 9 +++------
kernel/power/suspend.c | 3 +--
5 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c
index 1f4d8ce56667..6f9cd18ce6f0 100644
--- a/fs/efivarfs/super.c
+++ b/fs/efivarfs/super.c
@@ -512,6 +512,7 @@ static int efivarfs_init_fs_context(struct fs_context *fc)
sfi->mount_opts.gid = GLOBAL_ROOT_GID;

fc->s_fs_info = sfi;
+ fc->s_iflags |= SB_I_FREEZE_POWER;
fc->ops = &efivarfs_context_ops;

return 0;
diff --git a/fs/super.c b/fs/super.c
index 5bab94fb7e03..017f0be22c61 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1183,11 +1183,19 @@ static inline bool get_active_super(struct super_block *sb)

static const char *filesystems_freeze_ptr = "filesystems_freeze";

-static void filesystems_freeze_callback(struct super_block *sb, void *unused)
+static void filesystems_freeze_callback(struct super_block *sb, void *bool_freeze_all)
{
+ bool freeze_all = *(bool *)bool_freeze_all;
+
if (!sb->s_op->freeze_fs && !sb->s_op->freeze_super)
return;

+ if (!freeze_all) {
+ if (!(sb->s_iflags & SB_I_FREEZE_POWER))
+ return;
+ pr_info("VFS: Freezing %s filesystems\n", sb->s_type->name);
+ }
+
if (!get_active_super(sb))
return;

@@ -1201,9 +1209,9 @@ static void filesystems_freeze_callback(struct super_block *sb, void *unused)
deactivate_super(sb);
}

-void filesystems_freeze(void)
+void filesystems_freeze(bool freeze_all)
{
- __iterate_supers(filesystems_freeze_callback, NULL,
+ __iterate_supers(filesystems_freeze_callback, &freeze_all,
SUPER_ITER_UNLOCKED | SUPER_ITER_REVERSE);
}

diff --git a/include/linux/fs.h b/include/linux/fs.h
index c895146c1444..bde4967fdb68 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1419,6 +1419,7 @@ extern int send_sigurg(struct file *file);
#define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */
#define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */
#define SB_I_ALLOW_HSM 0x00004000 /* Allow HSM events on this superblock */
+#define SB_I_FREEZE_POWER 0x00008000 /* Always freeze on suspend/hibernate */

/* Possible states of 'frozen' field */
enum {
@@ -3606,7 +3607,7 @@ extern void drop_super_exclusive(struct super_block *sb);
extern void iterate_supers(void (*f)(struct super_block *, void *), void *arg);
extern void iterate_supers_type(struct file_system_type *,
void (*)(struct super_block *, void *), void *);
-void filesystems_freeze(void);
+void filesystems_freeze(bool freeze_all);
void filesystems_thaw(void);

extern int dcache_dir_open(struct inode *, struct file *);
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 14e85ff23551..1f250ce036a0 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -825,8 +825,7 @@ int hibernate(void)
goto Restore;

ksys_sync_helper();
- if (filesystem_freeze_enabled)
- filesystems_freeze();
+ filesystems_freeze(filesystem_freeze_enabled);

error = freeze_processes();
if (error)
@@ -932,8 +931,7 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data)
if (error)
goto restore;

- if (filesystem_freeze_enabled)
- filesystems_freeze();
+ filesystems_freeze(filesystem_freeze_enabled);

error = freeze_processes();
if (error)
@@ -1083,8 +1081,7 @@ static int software_resume(void)
if (error)
goto Restore;

- if (filesystem_freeze_enabled)
- filesystems_freeze();
+ filesystems_freeze(filesystem_freeze_enabled);

pm_pr_dbg("Preparing processes for hibernation restore.\n");
error = freeze_processes();
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 4bb4686c1c08..c933a63a9718 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -375,8 +375,7 @@ static int suspend_prepare(suspend_state_t state)
if (error)
goto Restore;

- if (filesystem_freeze_enabled)
- filesystems_freeze();
+ filesystems_freeze(filesystem_freeze_enabled);
trace_suspend_resume(TPS("freeze_processes"), 0, true);
error = suspend_freeze_processes();
trace_suspend_resume(TPS("freeze_processes"), 0, false);
--
2.47.3