Linux Device Mapper development
 help / color / mirror / Atom feed
* [RFC PATCH] fs: tolerate an unfrozen superblock in the block-layer thaw
@ 2026-11-27  0:39 Nikolai Dokutovich
  2026-11-27  0:50 ` Nikolai Dokutovich
  2026-11-27  0:56 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Nikolai Dokutovich @ 2026-11-27  0:39 UTC (permalink / raw)
  To: linux-fsdevel, linux-block, dm-devel
  Cc: Alexander Viro, Christian Brauner, Jens Axboe, Alasdair Kergon,
	Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Shuah Khan,
	linux-kselftest

The in-tree selftest tools/testing/selftests/filesystems/freeze fails in
shared_bdev.unmounted_sharer on v7.4-rc1 and v7.4-rc3.

DM suspend locks filesystems by default, so lock_fs() calls bdev_freeze(),
which freezes the superblock through fs_bdev_freeze() -> fs_super_freeze()
with FREEZE_HOLDER_USERSPACE.  A userspace FITHAW thaws that same credit.
On resume bdev_thaw() calls fs_bdev_thaw() -> fs_super_thaw(); the
superblock is already thawed, thaw_super() returns -EINVAL, and
fs_bdev_thaw() propagates the error when a single superblock uses the
device.  bdev_thaw() drops bd_fsfreeze_count only on success, so the count
stays elevated and every later mount that registers a superblock on the
device fails in super_dev_add() with -EBUSY.

The same condition is already tolerated when more than one superblock
uses the device.  Tolerate it for the single-superblock case too.

Add FREEZE_SKIP_UNFROZEN, set only by fs_super_thaw(), the holder thaw of
fs_bdev_thaw().  thaw_super_locked() returns success instead of -EINVAL
when the superblock is SB_UNFROZEN and the flag is set; a partially
frozen superblock, a superblock frozen by a different holder, and a
filesystem thaw error still fail, so the block-device reference is
released only when the holder thaw succeeds.

Filesystems with a custom ->thaw_super (gfs2) are not changed.

Block-layer freezes remain marked FREEZE_HOLDER_USERSPACE, so a userspace
FITHAW can still consume a device-manager freeze credit.  Marking them
FREEZE_HOLDER_KERNEL was considered but would change FITHAW behaviour
during a suspend.

Verified with the in-tree selftest: 5/6 before, 6/6 after.

Fixes: ea4e4cc26301 ("block: allow making a block device unfreezable")
Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>
---
 fs/super.c                     | 11 +++++++++--
 include/linux/fs/super_types.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index c5a0658f7aaf..5d850736c8d9 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1457,7 +1457,8 @@ static int fs_super_thaw(struct super_block *sb)
 	if (sb->s_op->thaw_super)
 		return sb->s_op->thaw_super(sb,
 				FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);
-	return thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);
+	return thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE |
+			       FREEZE_SKIP_UNFROZEN, NULL);
 }
 
 static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)
@@ -2025,7 +2026,8 @@ static int wait_for_partially_frozen(struct super_block *sb)
 }
 
 #define FREEZE_HOLDERS (FREEZE_HOLDER_KERNEL | FREEZE_HOLDER_USERSPACE)
-#define FREEZE_FLAGS (FREEZE_HOLDERS | FREEZE_MAY_NEST | FREEZE_EXCL)
+#define FREEZE_FLAGS (FREEZE_HOLDERS | FREEZE_MAY_NEST | FREEZE_EXCL | \
+		      FREEZE_SKIP_UNFROZEN)
 
 static inline int freeze_inc(struct super_block *sb, enum freeze_holder who)
 {
@@ -2296,6 +2298,11 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
 {
 	int error = -EINVAL;
 
+	if (sb->s_writers.frozen == SB_UNFROZEN) {
+		if (who & FREEZE_SKIP_UNFROZEN)
+			error = 0;
+		goto out_unlock;
+	}
 	if (sb->s_writers.frozen != SB_FREEZE_COMPLETE)
 		goto out_unlock;
 
diff --git a/include/linux/fs/super_types.h b/include/linux/fs/super_types.h
index 6ce105fe8359..434cdc338360 100644
--- a/include/linux/fs/super_types.h
+++ b/include/linux/fs/super_types.h
@@ -64,6 +64,7 @@ struct sb_writers {
  * @FREEZE_HOLDER_USERSPACE: userspace wants to freeze or thaw filesystem
  * @FREEZE_MAY_NEST: whether nesting freeze and thaw requests is allowed
  * @FREEZE_EXCL: a freeze that can only be undone by the owner
+ * @FREEZE_SKIP_UNFROZEN: tolerate thawing a superblock that is not frozen
  *
  * Indicate who the owner of the freeze or thaw request is and whether
  * the freeze needs to be exclusive or can nest.
@@ -78,6 +79,7 @@ enum freeze_holder {
 	FREEZE_HOLDER_USERSPACE	= (1U << 1),
 	FREEZE_MAY_NEST		= (1U << 2),
 	FREEZE_EXCL		= (1U << 3),
+	FREEZE_SKIP_UNFROZEN	= (1U << 4),
 };
 
 struct super_operations {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] fs: tolerate an unfrozen superblock in the block-layer thaw
  2026-11-27  0:39 [RFC PATCH] fs: tolerate an unfrozen superblock in the block-layer thaw Nikolai Dokutovich
@ 2026-11-27  0:50 ` Nikolai Dokutovich
  2026-11-27  0:56 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolai Dokutovich @ 2026-11-27  0:50 UTC (permalink / raw)
  To: linux-fsdevel, linux-block, dm-devel
  Cc: Alexander Viro, Christian Brauner, Jens Axboe, Alasdair Kergon,
	Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Shuah Khan,
	linux-kselftest

Please disregard this patch.  The same issue is already fixed by the
"super: fixes for freezing, reconfiguration and error reporting" series
([PATCH 09/15] fs: don't keep a device frozen when its freeze is already
gone), which I missed when preparing this.  Sorry for the noise.

Thanks,
Nikolai Dokutovich

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] fs: tolerate an unfrozen superblock in the block-layer thaw
  2026-11-27  0:39 [RFC PATCH] fs: tolerate an unfrozen superblock in the block-layer thaw Nikolai Dokutovich
  2026-11-27  0:50 ` Nikolai Dokutovich
@ 2026-11-27  0:56 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-27  0:56 UTC (permalink / raw)
  To: Nikolai Dokutovich, dm-devel
  Cc: Alexander Viro, Christian Brauner, Jens Axboe, Alasdair Kergon,
	Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Shuah Khan

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] fs: thaw_super_locked() fails when FITHAW consumed credit
  under kernel freeze
- [Low] fs: inaccurate Fixes trailer ea4e4cc26301 and super_dev_add()
  description
--

commit eb13bf6902950f18bf92590801b7adf9ead4c94a
Author: Nikolai Dokutovich <ndokutovich@gmail.com>

> fs: tolerate an unfrozen superblock in the block-layer thaw
>
> The in-tree selftest tools/testing/selftests/filesystems/freeze fails in
> shared_bdev.unmounted_sharer on v7.4-rc1 and v7.4-rc3.
>
> DM suspend locks filesystems by default, so lock_fs() calls bdev_freeze(),
> which freezes the superblock through fs_bdev_freeze() -> fs_super_freeze()
> with FREEZE_HOLDER_USERSPACE.  A userspace FITHAW thaws that same credit.
> On resume bdev_thaw() calls fs_bdev_thaw() -> fs_super_thaw(); the
> superblock is already thawed, thaw_super() returns -EINVAL, and
> fs_bdev_thaw() propagates the error when a single superblock uses the
> device.  bdev_thaw() drops bd_fsfreeze_count only on success, so the count
> stays elevated and every later mount that registers a superblock on the
> device fails in super_dev_add() with -EBUSY.
>
> The same condition is already tolerated when more than one superblock
> uses the device.  Tolerate it for the single-superblock case too.
>
> Add FREEZE_SKIP_UNFROZEN, set only by fs_super_thaw(), the holder thaw of
> fs_bdev_thaw().  thaw_super_locked() returns success instead of -EINVAL
> when the superblock is SB_UNFROZEN and the flag is set; a partially
> frozen superblock, a superblock frozen by a different holder, and a
> filesystem thaw error still fail, so the block-device reference is
> released only when the holder thaw succeeds.
>
> Filesystems with a custom ->thaw_super (gfs2) are not changed.
>
> Block-layer freezes remain marked FREEZE_HOLDER_USERSPACE, so a userspace
> FITHAW can still consume a device-manager freeze credit.  Marking them
> FREEZE_HOLDER_KERNEL was considered but would change FITHAW behaviour
> during a suspend.
>
> Verified with the in-tree selftest: 5/6 before, 6/6 after.
>
> Fixes: ea4e4cc26301 ("block: allow making a block device unfreezable")
> Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>

[Severity: Low]
Is the Fixes tag accurate?  Before ea4e4cc26301 ("block: allow making a
block device unfreezable"), bdev_thaw() decremented bd_fsfreeze_count
before calling ->thaw() and incremented it back when ->thaw() returned an
error, so bd_fsfreeze_count was already left elevated on failure.  The
device-table thaw walk and multi-superblock error tolerance came from
cdb5146f8d5f ("fs: look up superblocks via the device table in
fs_holder_ops") and 7a7ef107b449 ("fs: tolerate per-superblock freeze
errors on shared devices").

Also, super_dev_add() returns void; the bd_fsfreeze_count > 0 check that
returns -EBUSY on later mounts is in fs_bdev_register() and
setup_bdev_super().

> diff --git a/fs/super.c b/fs/super.c
> index c5a0658f7aaf3..5d850736c8d9b 100644
> --- a/fs/super.c
> +++ b/fs/super.c

[ ... ]

> @@ -2296,6 +2298,11 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
>  {
>  	int error = -EINVAL;
>  
> +	if (sb->s_writers.frozen == SB_UNFROZEN) {
> +		if (who & FREEZE_SKIP_UNFROZEN)
> +			error = 0;
> +		goto out_unlock;
> +	}
>  	if (sb->s_writers.frozen != SB_FREEZE_COMPLETE)
>  		goto out_unlock;
>  

[Severity: Medium]
Can thaw_super_locked() still return -EINVAL and leak
bdev->bd_fsfreeze_count when FITHAW consumed the userspace credit while a
FREEZE_HOLDER_KERNEL freeze is active?

If both bdev_freeze() (FREEZE_HOLDER_USERSPACE) and a kernel freeze
(FREEZE_HOLDER_KERNEL) hold the superblock frozen, a userspace FITHAW
decrements sb->s_writers.freeze_ucount to 0 while freeze_kcount keeps
sb->s_writers.frozen at SB_FREEZE_COMPLETE.  When bdev_thaw() later calls
fs_super_thaw(), sb->s_writers.frozen is not SB_UNFROZEN, so
thaw_super_locked() proceeds to may_unfreeze():

fs/super.c:may_unfreeze() {
	...
	if (who & FREEZE_HOLDER_USERSPACE)
		return sb->s_writers.freeze_ucount > 0;
	...
}

Because freeze_ucount is already 0, may_unfreeze() returns false and
thaw_super_locked() fails with -EINVAL, leaving bdev->bd_fsfreeze_count
elevated and causing subsequent mounts on the device to fail with -EBUSY
even after the kernel freeze is thawed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127003902.48-1-ndokutovich@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27  0:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  0:39 [RFC PATCH] fs: tolerate an unfrozen superblock in the block-layer thaw Nikolai Dokutovich
2026-11-27  0:50 ` Nikolai Dokutovich
2026-11-27  0:56 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox