From: diasyzhangqing@gmail.com
To: tytso@mit.edu, adilger.kernel@dilger.ca
Cc: linux-ext4@vger.kernel.org, libaokun@linux.alibaba.com,
jack@suse.cz, ojaswin@linux.ibm.com, ritesh.list@gmail.com,
yi.zhang@huawei.com,
syzbot+d4ecb9a1e5b3dcf8baec@syzkaller.appspotmail.com,
linux-kernel@vger.kernel.org, Qing Zhang <diasyzhang@tencent.com>
Subject: [PATCH] ext4: make concurrent DEFAULT shutdown waits killable
Date: Tue, 10 Nov 2026 21:21:18 +0800 [thread overview]
Message-ID: <20261110132118.11265-1-diasyzhangqing@gmail.com> (raw)
In-Reply-To: <6af1e75f.3e87765f.91969.0010.GAE@google.com>
From: Qing Zhang <diasyzhang@tencent.com>
Concurrent DEFAULT shutdown callers can all pass the shutdown flag
check before the first caller finishes bdev_freeze(). They then wait
uninterruptibly on bd_fsfreeze_mutex and may perform redundant
freeze/thaw operations, triggering hung-task reports if the initial
freeze takes long enough.
Serialize DEFAULT shutdown attempts with a per-superblock mutex
acquired killably. Re-check the shutdown flag after acquiring it to
skip the freeze after a successful attempt, or retry if the previous
attempt failed.
Leave LOGFLUSH and NOLOGFLUSH unchanged. The ->shutdown callback uses
NOLOGFLUSH with s_umount held, so it must not acquire a mutex held
across a freeze. This does not shorten the initial freeze or prevent
hung-task reports for the active freezer and other freeze-blocked
tasks.
Fixes: 783d94854499 ("ext4: add EXT4_IOC_GOINGDOWN ioctl")
Reported-by: syzbot+d4ecb9a1e5b3dcf8baec@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d4ecb9a1e5b3dcf8baec
Signed-off-by: Qing Zhang <diasyzhang@tencent.com>
---
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
fs/ext4/ext4.h | 1 +
fs/ext4/ioctl.c | 14 +++++++++++++-
fs/ext4/super.c | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index f38fec3167fb..c4e44e3d58cc 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1647,6 +1647,7 @@ struct ext4_sb_info {
/* Journaling */
struct journal_s *s_journal;
unsigned long s_ext4_flags; /* Ext4 superblock flags */
+ struct mutex s_shutdown_lock; /* Serializes DEFAULT shutdown requests */
struct mutex s_orphan_lock; /* Protects on disk list changes */
struct list_head s_orphan; /* List of orphaned inodes in on disk
list */
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index e8e579498c99..3019b16320a0 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -818,16 +818,28 @@ int ext4_force_shutdown(struct super_block *sb, u32 flags)
if (ext4_forced_shutdown(sb))
return 0;
+ if (flags == EXT4_GOING_FLAGS_DEFAULT) {
+ if (mutex_lock_killable(&sbi->s_shutdown_lock))
+ return -EINTR;
+ if (ext4_forced_shutdown(sb)) {
+ mutex_unlock(&sbi->s_shutdown_lock);
+ return 0;
+ }
+ }
+
ext4_msg(sb, KERN_ALERT, "shut down requested (%d)", flags);
trace_ext4_shutdown(sb, flags);
switch (flags) {
case EXT4_GOING_FLAGS_DEFAULT:
ret = bdev_freeze(sb->s_bdev);
- if (ret)
+ if (ret) {
+ mutex_unlock(&sbi->s_shutdown_lock);
return ret;
+ }
set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
bdev_thaw(sb->s_bdev);
+ mutex_unlock(&sbi->s_shutdown_lock);
break;
case EXT4_GOING_FLAGS_LOGFLUSH:
/*
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 9cae52471dee..a1d4fc5c0a68 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5547,6 +5547,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
mutex_init(&sbi->s_orphan_lock);
+ mutex_init(&sbi->s_shutdown_lock);
spin_lock_init(&sbi->s_bdev_wb_lock);
--
2.43.7
next prev parent reply other threads:[~2026-11-10 13:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 15:31 [syzbot] [block?] [ext4?] INFO: task hung in bdev_freeze syzbot
2026-11-10 13:21 ` diasyzhangqing [this message]
2026-11-10 13:35 ` [PATCH] ext4: make concurrent DEFAULT shutdown waits killable Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110132118.11265-1-diasyzhangqing@gmail.com \
--to=diasyzhangqing@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=diasyzhang@tencent.com \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=syzbot+d4ecb9a1e5b3dcf8baec@syzkaller.appspotmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®