FAILED: patch "[PATCH] super: fix emergency thaw deadlock on frozen block devices" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 749d7aa0377aae32af8c0a4ad43371e7bf830ab5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072927-mom-flyover-909f@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 749d7aa0377aae32af8c0a4ad43371e7bf830ab5 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Thu, 23 Jul 2026 11:37:05 +0200
Subject: [PATCH] super: fix emergency thaw deadlock on frozen block devices
do_thaw_all_callback() calls bdev_thaw() while holding sb->s_umount exclusively. If the block device was frozen via bdev_freeze() dropping the last block layer freeze reference calls fs_bdev_thaw() which reacquires s_umount:
do_thaw_all_callback(sb)
super_lock_excl(sb) # holds sb->s_umount
bdev_thaw(sb->s_bdev)
mutex_lock(&bdev->bd_fsfreeze_mutex)
# bd_fsfreeze_count drops 1 -> 0
bd_holder_ops->thaw == fs_bdev_thaw
get_bdev_super(bdev)
bdev_super_lock(bdev, true)
super_lock(sb, true)
down_write(&sb->s_umount) # same task: deadlockThe emergency thaw worker deadlocks against itself holding both s_umount and bd_fsfreeze_mutex. That fscks any subsequent unmount, freeze, or thaw of that filesystem and block device.
[ 81.878470] sysrq: Show Blocked State [ 81.880140] task:kworker/0:1 state:D stack:0 pid:11 tgid:11 ppid:2 task_flags:0x4208060 flags:0x00080000 [ 81.884876] Workqueue: events do_thaw_all [ 81.886656] Call Trace: [ 81.887759] <TASK> [ 81.888763] __schedule+0x579/0x1420 [ 81.890372] schedule+0x3a/0x100 [ 81.891794] schedule_preempt_disabled+0x15/0x30 [ 81.893848] rwsem_down_write_slowpath+0x1ea/0x900 [ 81.895191] ? __pfx_do_thaw_all_callback+0x10/0x10 [ 81.896528] down_write+0xbd/0xc0 [ 81.897505] super_lock+0x91/0x180 [ 81.898457] ? __mutex_lock+0xa99/0x1140 [ 81.900748] ? __mutex_unlock_slowpath+0x1f/0x400 [ 81.902069] bdev_super_lock+0x5b/0x150 [ 81.903132] get_bdev_super+0x10/0x60 [ 81.904042] fs_bdev_thaw+0x23/0xf0 [ 81.904755] bdev_thaw+0x82/0x100 [ 81.905484] do_thaw_all_callback+0x2c/0x50 [ 81.906298] __iterate_supers+0x5d/0x130 [ 81.907067] do_thaw_all+0x20/0x40 [ 81.907739] process_one_work+0x206/0x5e0 [ 81.908545] worker_thread+0x1e2/0x3c0 [ 81.909339] ? __pfx_worker_thread+0x10/0x10 [ 81.910171] kthread+0xf4/0x130 [ 81.910799] ? __pfx_kthread+0x10/0x10 [ 81.911528] ret_from_fork+0x2e2/0x3b0 [ 81.912259] ? __pfx_kthread+0x10/0x10 [ 81.913010] ret_from_fork_asm+0x1a/0x30 [ 81.913806] </TASK>
bdev_super_lock() even documents the violated requirement with lockdep_assert_not_held(&sb->s_umount).
Acquiring bd_fsfreeze_mutex under s_umount also inverts the bd_fsfreeze_mutex vs. s_umount ordering established by bdev_{freeze,thaw}() and can thus ABBA against a concurrent block-layer freeze even when the recursive path isn't hit.
Fix this by not holding s_umount around the bdev_thaw() loop at all. Pin the superblock with an active reference instead as filesystems_freeze_callback() does. The active reference keeps the superblock from being shut down and so ->s_bdev stays valid without holding s_umount. The block-layer-held freeze is dropped by fs_bdev_thaw() with FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE exactly as a regular unfreeze would and thaw_super_locked() handles filesystem-level freezes as before.
The emergency thaw path has deadlocked like this in one form or another for a long long time but the current exclusively-held shape dates back to commit [1] where thaw_bdev() already ended in thaw_super() with s_umount held by do_thaw_all_callback().
fs/super.c +16 -13
@@ -1082,16 +1082,30 @@ void emergency_remount(void) } } +static inline bool get_active_super (struct super_block *sb) +{ +bool active = false; + +if (super_lock_excl (sb)) { + active =atomic_inc_not_zero (&sb->s_active); +super_unlock_excl (sb); + } +return active; +} +static void do_thaw_all_callback (struct super_block *sb,void *unused) { -if (!super_lock_excl (sb)) +if (!get_active_super (sb))return ; +/* fs_bdev_thaw() acquires s_umount so it must not be held here */ if (IS_ENABLED (CONFIG_BLOCK ))while (sb->s_bdev && !bdev_thaw (sb->s_bdev))pr_warn ("Emergency Thaw on %pg\n" , sb->s_bdev); -thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ,NULL ); +if (super_lock_excl (sb)) +thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ,NULL ); +deactivate_super (sb); }static void do_thaw_all (struct work_struct *work)
@@ -1117,17 +1131,6 @@ void emergency_thaw_all(void) } } -static inline bool get_active_super (struct super_block *sb) -{ -bool active = false; - -if (super_lock_excl (sb)) { - active =atomic_inc_not_zero (&sb->s_active); -super_unlock_excl (sb); - } -return active; -} -static const char *filesystems_freeze_ptr ="filesystems_freeze" ;static void filesystems_freeze_callback (struct super_block *sb,void *freeze_all_ptr)
Sasha Levin
maintainerPATCH 1/6 super: remove pointless s_root checks
From: Christian Brauner <[email protected]>
[ Upstream commit af7551cf13cf7fb1d4f939db4f1f24c00550ed57 ]
The locking guarantees that the superblock is alive and sb->s_root is still set. Remove the pointless check.
Stable-dep-of: 749d7aa0377a ("super: fix emergency thaw deadlock on frozen block devices")
--- fs/super.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
fs/super.c +6 -13
@@ -930,8 +930,7 @@ void iterate_supers(void (*f)(struct super_block *, void *), void *arg) locked =super_lock_shared (sb);if (locked) { -if (sb->s_root) -f (sb, arg); +f (sb, arg);super_unlock_shared (sb); }
@@ -967,11 +966,8 @@ void iterate_supers_type(struct file_system_type *type,spin_unlock (&sb_lock); locked =super_lock_shared (sb); -if (locked) { -if (sb->s_root) -f (sb, arg); -super_unlock_shared (sb); - } +if (locked) +f (sb, arg);spin_lock (&sb_lock);if (p)
@@ -991,18 +987,15 @@ struct super_block *user_get_super(dev_t dev, bool excl)spin_lock (&sb_lock);list_for_each_entry (sb, &super_blocks, s_list) { -if (sb->s_dev == dev) { +if (sb->s_dev == dev) {bool locked; sb->s_count++;spin_unlock (&sb_lock);/* still alive? */ locked =super_lock (sb, excl); -if (locked) { -if (sb->s_root) -return sb; -super_unlock (sb, excl); - } +if (locked) +return sb;/* caller will drop */ /* nope, got unmounted */ spin_lock (&sb_lock);__put_super (sb);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/6 super: skip dying superblocks early
From: Christian Brauner <[email protected]>
[ Upstream commit 6920e3388ba4c66b0468d43bb7a373f5fff15d35 ]
Make all iterators uniform by performing an early check whether the superblock is dying.
Stable-dep-of: 749d7aa0377a ("super: fix emergency thaw deadlock on frozen block devices")
--- fs/super.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/super.c +6 -0
@@ -925,6 +925,9 @@ void iterate_supers(void (*f)(struct super_block *, void *), void *arg)list_for_each_entry (sb, &super_blocks, s_list) {bool locked; +if (super_flags (sb,SB_DYING )) +continue ; + sb->s_count++;spin_unlock (&sb_lock);
@@ -962,6 +965,9 @@ void iterate_supers_type(struct file_system_type *type,hlist_for_each_entry (sb, &type->fs_supers, s_instances) {bool locked; +if (super_flags (sb,SB_DYING )) +continue ; + sb->s_count++;spin_unlock (&sb_lock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/6 super: use a common iterator (Part 1)
In reply to Sasha LevinFrom: Christian Brauner <[email protected]>
[ Upstream commit 2992476528aeecbaee17ba0a6396a817481205a3 ]
Use a common iterator for all callbacks.
Stable-dep-of: 749d7aa0377a ("super: fix emergency thaw deadlock on frozen block devices")
--- fs/super.c | 67 +++++++++------------------------------------- include/linux/fs.h | 6 ++++- 2 files changed, 18 insertions(+), 55 deletions(-)
fs/super.c +13 -54
@@ -887,37 +887,7 @@ void drop_super_exclusive(struct super_block *sb) }EXPORT_SYMBOL (drop_super_exclusive); -static void __iterate_supers (void (*f)(struct super_block *)) -{ -struct super_block *sb, *p =NULL ; - -spin_lock (&sb_lock); -list_for_each_entry (sb, &super_blocks, s_list) { -if (super_flags (sb,SB_DYING )) -continue ; - sb->s_count++; -spin_unlock (&sb_lock); - -f (sb); - -spin_lock (&sb_lock); -if (p) -__put_super (p); - p = sb; - } -if (p) -__put_super (p); -spin_unlock (&sb_lock); -} -/** -* iterate_supers - call function for all active superblocks -* @f: function to call -* @arg: argument to pass to it -* -* Scans the superblock list and calls given function, passing it -* locked superblock and given argument. -*/ -void iterate_supers (void (*f)(struct super_block *,void *),void *arg) +void __iterate_supers (void (*f)(struct super_block *,void *),void *arg,bool excl) {struct super_block *sb, *p =NULL ;
@@ -927,14 +897,13 @@ void iterate_supers(void (*f)(struct super_block *, void *), void *arg)if (super_flags (sb,SB_DYING ))continue ; - sb->s_count++;spin_unlock (&sb_lock); - locked =super_lock_shared (sb); + locked =super_lock (sb, excl);if (locked) {f (sb, arg); -super_unlock_shared (sb); +super_unlock (sb, excl); }spin_lock (&sb_lock);
@@ -1110,11 +1079,9 @@ int reconfigure_super(struct fs_context *fc)return retval; } -static void do_emergency_remount_callback (struct super_block *sb) +static void do_emergency_remount_callback (struct super_block *sb,void *unused) { -bool locked =super_lock_excl (sb); - -if (locked && sb->s_root && sb->s_bdev && !sb_rdonly (sb)) { +if (sb->s_bdev && !sb_rdonly (sb)) {struct fs_context *fc; fc = fs_context_for_reconfigure(sb->s_root,
@@ -1125,13 +1092,11 @@ static void do_emergency_remount_callback(struct super_block *sb)put_fs_context (fc); } } -if (locked) -super_unlock_excl (sb); }static void do_emergency_remount (struct work_struct *work) { -__iterate_supers (do_emergency_remount_callback); +__iterate_supers (do_emergency_remount_callback,NULL , true);kfree (work);printk ("Emergency Remount complete\n" ); }
@@ -1147,24 +1112,18 @@ void emergency_remount(void) } } -static void do_thaw_all_callback (struct super_block *sb) +static void do_thaw_all_callback (struct super_block *sb,void *unused) { -bool locked =super_lock_excl (sb); - -if (locked && sb->s_root) { -if (IS_ENABLED (CONFIG_BLOCK )) -while (sb->s_bdev && !bdev_thaw (sb->s_bdev)) -pr_warn ("Emergency Thaw on %pg\n" , sb->s_bdev); -thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ); -return ; - } -if (locked) -super_unlock_excl (sb); +if (IS_ENABLED (CONFIG_BLOCK )) +while (sb->s_bdev && !bdev_thaw (sb->s_bdev)) +pr_warn ("Emergency Thaw on %pg\n" , sb->s_bdev); +thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ); +return ; }static void do_thaw_all (struct work_struct *work) { -__iterate_supers (do_thaw_all_callback); +__iterate_supers (do_thaw_all_callback,NULL , true);kfree (work);printk (KERN_WARNING "Emergency Thaw complete\n" ); }
include/linux/fs.h +5 -1
@@ -3398,7 +3398,11 @@ extern void put_filesystem(struct file_system_type *fs);extern struct file_system_type *get_fs_type (const char *name);extern void drop_super (struct super_block *sb);extern void drop_super_exclusive (struct super_block *sb); -extern void iterate_supers (void (*)(struct super_block *,void *),void *); +void __iterate_supers (void (*f)(struct super_block *,void *),void *arg,bool excl); +static inline void iterate_supers (void (*f)(struct super_block *,void *),void *arg) +{ +__iterate_supers (f, arg, false); +}extern void iterate_supers_type (struct file_system_type *,void (*)(struct super_block *,void *),void *);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/6 super: use common iterator (Part 2)
In reply to Sasha LevinFrom: Christian Brauner <[email protected]>
[ Upstream commit b47e42d10e8c20525febccbd6e0dc8528861aea4 ]
Use a common iterator for all callbacks. We could go for something even more elaborate (advance step-by-step similar to iov_iter) but I really don't think this is warranted.
Stable-dep-of: 749d7aa0377a ("super: fix emergency thaw deadlock on frozen block devices")
--- fs/super.c | 48 +++++++++++++++++++++++++++++++++++++--------- include/linux/fs.h | 6 +----- 2 files changed, 40 insertions(+), 14 deletions(-)
fs/super.c +39 -9
@@ -887,21 +887,46 @@ void drop_super_exclusive(struct super_block *sb) }EXPORT_SYMBOL (drop_super_exclusive); -void __iterate_supers (void (*f)(struct super_block *,void *),void *arg,bool excl) +enum super_iter_flags_t { +SUPER_ITER_EXCL = (1U <<0 ), +SUPER_ITER_UNLOCKED = (1U <<1 ), +SUPER_ITER_REVERSE = (1U <<2 ), +}; + +static inline struct super_block *first_super (enum super_iter_flags_t flags) +{ +if (flags &SUPER_ITER_REVERSE ) + return list_last_entry(&super_blocks, struct super_block, s_list); + return list_first_entry(&super_blocks, struct super_block, s_list); +} + +static inline struct super_block *next_super (struct super_block *sb, +enum super_iter_flags_t flags) +{ +if (flags &SUPER_ITER_REVERSE ) +return list_prev_entry (sb, s_list); +return list_next_entry (sb, s_list); +} + +static void __iterate_supers (void (*f)(struct super_block *,void *),void *arg, +enum super_iter_flags_t flags) {struct super_block *sb, *p =NULL ; +bool excl = flags &SUPER_ITER_EXCL ; -spin_lock (&sb_lock); -list_for_each_entry (sb, &super_blocks, s_list) { -bool locked; +guard (spinlock)(&sb_lock); +for (sb =first_super (flags); + !list_entry_is_head (sb, &super_blocks, s_list); + sb =next_super (sb, flags)) {if (super_flags (sb,SB_DYING ))continue ; sb->s_count++;spin_unlock (&sb_lock); - locked =super_lock (sb, excl); -if (locked) { +if (flags &SUPER_ITER_UNLOCKED ) { +f (sb, arg); + }else if (super_lock (sb, excl)) {f (sb, arg);super_unlock (sb, excl); }
@@ -913,7 +938,11 @@ void __iterate_supers(void (*f)(struct super_block *, void *), void *arg, bool e }if (p)__put_super (p); -spin_unlock (&sb_lock); +} + +void iterate_supers (void (*f)(struct super_block *,void *),void *arg) +{ +__iterate_supers (f, arg,0 ); }/**
@@ -1096,7 +1125,8 @@ static void do_emergency_remount_callback(struct super_block *sb, void *unused)static void do_emergency_remount (struct work_struct *work) { -__iterate_supers (do_emergency_remount_callback,NULL , true); +__iterate_supers (do_emergency_remount_callback,NULL , +SUPER_ITER_EXCL |SUPER_ITER_REVERSE );kfree (work);printk ("Emergency Remount complete\n" ); }
@@ -1123,7 +1153,7 @@ static void do_thaw_all_callback(struct super_block *sb, void *unused)static void do_thaw_all (struct work_struct *work) { -__iterate_supers (do_thaw_all_callback,NULL , true); +__iterate_supers (do_thaw_all_callback,NULL ,SUPER_ITER_EXCL );kfree (work);printk (KERN_WARNING "Emergency Thaw complete\n" ); }
include/linux/fs.h +1 -5
@@ -3398,11 +3398,7 @@ extern void put_filesystem(struct file_system_type *fs);extern struct file_system_type *get_fs_type (const char *name);extern void drop_super (struct super_block *sb);extern void drop_super_exclusive (struct super_block *sb); -void __iterate_supers (void (*f)(struct super_block *,void *),void *arg,bool excl); -static inline void iterate_supers (void (*f)(struct super_block *,void *),void *arg) -{ -__iterate_supers (f, arg, false); -} +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 *);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/6 fs/super: fix emergency thaw double-unlock of s_umount
In reply to Sasha LevinFrom: Chen Changcheng <[email protected]>
[ Upstream commit 503d67fbaec6fdeaba391cb497675071db9d16ea ]
do_thaw_all() iterates over all superblocks via __iterate_supers() with SUPER_ITER_EXCL, which acquires s_umount exclusively before calling the callback and releases it afterwards. However, the callback do_thaw_all_callback() calls thaw_super_locked() which unconditionally releases s_umount on every code path. This results in a second unlock attempt in __iterate_supers() that corrupts the rwsem state, triggering a DEBUG_RWSEMS warning:
[ 182.601148] sysrq: Emergency Thaw of all frozen filesystems [ 182.601865] ------------[ cut here ]------------ [ 182.602375] DEBUG_RWSEMS_WARN_ON((rwsem_owner(sem) != current) && !rwsem_test_oflags(sem, RWSEM_NONSPINNABLE)): count = 0x0, magic = 0xffff99b1011e5870, owner = 0x0, curr 0xffff99b101b06c80, list not empty [ 182.603817] WARNING: kernel/locking/rwsem.c:1412 at up_write+0xa3/0x170, CPU#2: kworker/2:1/53 [ 182.604578] Modules linked in: [ 182.604864] CPU: 2 UID: 0 PID: 53 Comm: kworker/2:1 Not tainted 7.2.0-rc4-00001-gbd3bd93ea98a-dirty #4 PREEMPT(lazy) [ 182.605711] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1kylin1 04/01/2014 [ 182.606417] Workqueue: events do_thaw_all [ 182.606750] RIP: 0010:up_write+0xaf/0x170 [ 182.607076] Code: 19 3a 92 48 0f 44 c2 48 8b 55 08 48 8b 55 00 4c 8b 45 08 48 8b 55 00 48 8d 3d ad 91 e0 01 48 8b 4d 20 50 48 c7 c6 f0 8c 26 92 <67> 48 0f b9 3a e8 d7 93 4e 00 58 eb 81 48 83 7f 18 00 48 c7 c2 8d [ 182.608563] RSP: 0018:ffffb670001d7e08 EFLAGS: 00010246 [ 182.609007] RAX: ffffffff92349e8d RBX: 0000000000000000 RCX: ffff99b1011e5870 [ 182.609595] RDX: 0000000000000000 RSI: ffffffff92268cf0 RDI: ffffffff92914d10 [ 182.610283] RBP: ffff99b1011e5870 R08: 0000000000000000 R09: ffff99b101b06c80 [ 182.610847] R10: ffff99b10139a808 R11: fefefefefefefeff R12: 0000000000000000 [ 182.611414] R13: ffffffff90cf74d0 R14: 0000000000000000 R15: ffff99b1011e5800 [ 182.612009] FS: 0000000000000000(0000) GS:ffff99b1eaaee000(0000) knlGS:0000000000000000 [ 182.612670] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 182.613146] CR2: 00000000005c631c CR3: 00000000013ee000 CR4: 00000000000006f0 [ 182.613722] Call Trace: [ 182.613946] <TASK> [ 182.614130] __iterate_supers+0x128/0x150 [ 182.614463] do_thaw_all+0x1b/0x30 [ 182.614759] process_scheduled_works+0xbb/0x3f0 [ 182.615150] ? __pfx_worker_thread+0x10/0x10 [ 182.615499] worker_thread+0x129/0x270 [ 182.615816] ? __pfx_worker_thread+0x10/0x10 [ 182.616201] kthread+0xe2/0x120 [ 182.616469] ? __pfx_kthread+0x10/0x10 [ 182.616792] ret_from_fork+0x15b/0x240 [ 182.617115] ? __pfx_kthread+0x10/0x10 [ 182.617426] ret_from_fork_asm+0x1a/0x30 [ 182.617761] </TASK> [ 182.617968] ---[ end trace 0000000000000000 ]--- [ 182.618412] Emergency Thaw complete
Fix this by switching to SUPER_ITER_UNLOCKED and acquiring s_umount in the callback via super_lock_excl() before calling thaw_super_locked(). This matches the locking pattern expected by thaw_super_locked() and eliminates the double unlock.
While at it, remove the dead 'return;' at the end of do_thaw_all_callback().
Stable-dep-of: 749d7aa0377a ("super: fix emergency thaw deadlock on frozen block devices")
--- fs/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/super.c +5 -2
@@ -1144,16 +1144,19 @@ void emergency_remount(void)static void do_thaw_all_callback (struct super_block *sb,void *unused) { +if (!super_lock_excl (sb)) +return ; +if (IS_ENABLED (CONFIG_BLOCK ))while (sb->s_bdev && !bdev_thaw (sb->s_bdev))pr_warn ("Emergency Thaw on %pg\n" , sb->s_bdev); +thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ); -return ; }static void do_thaw_all (struct work_struct *work) { -__iterate_supers (do_thaw_all_callback,NULL ,SUPER_ITER_EXCL ); +__iterate_supers (do_thaw_all_callback,NULL ,SUPER_ITER_UNLOCKED );kfree (work);printk (KERN_WARNING "Emergency Thaw complete\n" ); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 6/6 super: fix emergency thaw deadlock on frozen block devices
In reply to Sasha LevinFrom: Christian Brauner <[email protected]>
[ Upstream commit 749d7aa0377aae32af8c0a4ad43371e7bf830ab5 ]
do_thaw_all_callback() calls bdev_thaw() while holding sb->s_umount exclusively. If the block device was frozen via bdev_freeze() dropping the last block layer freeze reference calls fs_bdev_thaw() which reacquires s_umount:
do_thaw_all_callback(sb)
super_lock_excl(sb) # holds sb->s_umount
bdev_thaw(sb->s_bdev)
mutex_lock(&bdev->bd_fsfreeze_mutex)
# bd_fsfreeze_count drops 1 -> 0
bd_holder_ops->thaw == fs_bdev_thaw
get_bdev_super(bdev)
bdev_super_lock(bdev, true)
super_lock(sb, true)
down_write(&sb->s_umount) # same task: deadlockThe emergency thaw worker deadlocks against itself holding both s_umount and bd_fsfreeze_mutex. That fscks any subsequent unmount, freeze, or thaw of that filesystem and block device.
[ 81.878470] sysrq: Show Blocked State [ 81.880140] task:kworker/0:1 state:D stack:0 pid:11 tgid:11 ppid:2 task_flags:0x4208060 flags:0x00080000 [ 81.884876] Workqueue: events do_thaw_all [ 81.886656] Call Trace: [ 81.887759] <TASK> [ 81.888763] __schedule+0x579/0x1420 [ 81.890372] schedule+0x3a/0x100 [ 81.891794] schedule_preempt_disabled+0x15/0x30 [ 81.893848] rwsem_down_write_slowpath+0x1ea/0x900 [ 81.895191] ? __pfx_do_thaw_all_callback+0x10/0x10 [ 81.896528] down_write+0xbd/0xc0 [ 81.897505] super_lock+0x91/0x180 [ 81.898457] ? __mutex_lock+0xa99/0x1140 [ 81.900748] ? __mutex_unlock_slowpath+0x1f/0x400 [ 81.902069] bdev_super_lock+0x5b/0x150 [ 81.903132] get_bdev_super+0x10/0x60 [ 81.904042] fs_bdev_thaw+0x23/0xf0 [ 81.904755] bdev_thaw+0x82/0x100 [ 81.905484] do_thaw_all_callback+0x2c/0x50 [ 81.906298] __iterate_supers+0x5d/0x130 [ 81.907067] do_thaw_all+0x20/0x40 [ 81.907739] process_one_work+0x206/0x5e0 [ 81.908545] worker_thread+0x1e2/0x3c0 [ 81.909339] ? __pfx_worker_thread+0x10/0x10 [ 81.910171] kthread+0xf4/0x130 [ 81.910799] ? __pfx_kthread+0x10/0x10 [ 81.911528] ret_from_fork+0x2e2/0x3b0 [ 81.912259] ? __pfx_kthread+0x10/0x10 [ 81.913010] ret_from_fork_asm+0x1a/0x30 [ 81.913806] </TASK>
bdev_super_lock() even documents the violated requirement with lockdep_assert_not_held(&sb->s_umount).
Acquiring bd_fsfreeze_mutex under s_umount also inverts the bd_fsfreeze_mutex vs. s_umount ordering established by bdev_{freeze,thaw}() and can thus ABBA against a concurrent block-layer freeze even when the recursive path isn't hit.
Fix this by not holding s_umount around the bdev_thaw() loop at all. Pin the superblock with an active reference instead as filesystems_freeze_callback() does. The active reference keeps the superblock from being shut down and so ->s_bdev stays valid without holding s_umount. The block-layer-held freeze is dropped by fs_bdev_thaw() with FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE exactly as a regular unfreeze would and thaw_super_locked() handles filesystem-level freezes as before.
The emergency thaw path has deadlocked like this in one form or another for a long long time but the current exclusively-held shape dates back to commit [1] where thaw_bdev() already ended in thaw_super() with s_umount held by do_thaw_all_callback().
--- fs/super.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fs/super.c +16 -2
@@ -1142,16 +1142,30 @@ void emergency_remount(void) } } +static inline bool get_active_super (struct super_block *sb) +{ +bool active = false; + +if (super_lock_excl (sb)) { + active =atomic_inc_not_zero (&sb->s_active); +super_unlock_excl (sb); + } +return active; +} +static void do_thaw_all_callback (struct super_block *sb,void *unused) { -if (!super_lock_excl (sb)) +if (!get_active_super (sb))return ; +/* fs_bdev_thaw() acquires s_umount so it must not be held here */ if (IS_ENABLED (CONFIG_BLOCK ))while (sb->s_bdev && !bdev_thaw (sb->s_bdev))pr_warn ("Emergency Thaw on %pg\n" , sb->s_bdev); -thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ); +if (super_lock_excl (sb)) +thaw_super_locked (sb,FREEZE_HOLDER_USERSPACE ); +deactivate_super (sb); }static void do_thaw_all (struct work_struct *work)
Signature · 1 line
2.53.0