From: Ye Bin <yebin@huaweicloud.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Cc: jack@suse.cz, brauner@kernel.org
Subject: [PATCH] ext4: protect ext4_acquire_dquot against freezing
Date: Mon, 23 Nov 2026 19:46:02 +0800 [thread overview]
Message-ID: <20261123114602.66520-1-yebin@huaweicloud.com> (raw)
From: Ye Bin <yebin10@huawei.com>
A writable open of a regular file reaches the filesystem's ->open()
callback without holding any superblock write (freeze) protection, but
ext4_file_open() -> dquot_file_open() -> dquot_initialize() may need to
acquire a dquot and write the quota file. If the filesystem reaches
SB_FREEZE_COMPLETE in that window, ext4_journal_check_start() hits
WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
and the open then sleeps in jbd2 until the filesystem is thawed.
The background and the earlier discussion of this problem are described
in:
https://patchwork.kernel.org/project/linux-fsdevel/patch/20261112135245.3347102-1-yebin@huaweicloud.com/
The initial attempt added mnt_want_write() for every writable open of a
regular file in do_open(). Christian Brauner pointed out that this would
make a plain open(O_WRONLY|O_RDWR) on a frozen filesystem block even when
it never writes -- log files, editors and backup tools would hang rather
than fail on a later write, which is a drastic and unacceptable uapi
change. As Jan Kara noted, the write comes from the quota acquisition
path, so it should be fixed there instead of penalizing the whole VFS
layer. Jan also suggested using sb_start_intwrite() in the filesystem's
.acquire_dquot method, which neither deadlocks nor changes VFS semantics.
ocfs2 is already fine because ocfs2_start_trans() takes sb_start_intwrite()
itself, so only ext4 needs the fix.
Protect the quota acquisition path itself: take sb_start_intwrite()
around ext4_acquire_dquot() when no transaction is already running.
Running transactions are already protected against freezing and taking
sb_start_intwrite() inside one can deadlock.
Fixes: 907f4554e252 ("dquot: move dquot initialization responsibility into the filesystem")
Suggested-by: Jan Kara <jack@suse.cz>
Link: https://patchwork.kernel.org/project/linux-fsdevel/patch/20261112135245.3347102-1-yebin@huaweicloud.com/
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/ext4/super.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index d0415e5948e1..fc63219f5972 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7110,11 +7110,25 @@ static int ext4_acquire_dquot(struct dquot *dquot)
{
int ret, err;
handle_t *handle;
+ bool freeze_protected = false;
+
+ /*
+ * Trying to sb_start_intwrite() in a running transaction
+ * can result in a deadlock. Further, running transactions
+ * are already protected from freezing.
+ */
+ if (!ext4_journal_current_handle()) {
+ sb_start_intwrite(dquot->dq_sb);
+ freeze_protected = true;
+ }
handle = ext4_journal_start(dquot_to_inode(dquot), EXT4_HT_QUOTA,
EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
- if (IS_ERR(handle))
+ if (IS_ERR(handle)) {
+ if (freeze_protected)
+ sb_end_intwrite(dquot->dq_sb);
return PTR_ERR(handle);
+ }
ret = dquot_acquire(dquot);
if (ret < 0)
ext4_error_err(dquot->dq_sb, -ret,
@@ -7123,6 +7137,10 @@ static int ext4_acquire_dquot(struct dquot *dquot)
err = ext4_journal_stop(handle);
if (!ret)
ret = err;
+
+ if (freeze_protected)
+ sb_end_intwrite(dquot->dq_sb);
+
return ret;
}
--
2.34.1
next reply other threads:[~2026-11-23 11:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 11:46 Ye Bin [this message]
2026-11-23 12:02 ` [PATCH] ext4: protect ext4_acquire_dquot against freezing sashiko-bot
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=20261123114602.66520-1-yebin@huaweicloud.com \
--to=yebin@huaweicloud.com \
--cc=adilger.kernel@dilger.ca \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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