From: Ye Bin <yebin@huaweicloud.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Cc: jack@suse.cz
Subject: [PATCH v2 2/2] ext4: protect ext4_acquire_dquot against freezing
Date: Wed, 25 Nov 2026 19:10:55 +0800 [thread overview]
Message-ID: <20261125111055.3672233-3-yebin@huaweicloud.com> (raw)
In-Reply-To: <20261125111055.3672233-1-yebin@huaweicloud.com>
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.
Taking freeze protection for every writable open in the VFS would make a
plain open(O_WRONLY) on a frozen filesystem block even when it never
writes, which is an unacceptable behaviour change. Instead 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.
This protection relies on the preceding quota change ("quota: Forbid
Q_XGETQUOTA and Q_XGETNEXTQUOTA for frozen filesystem"). Those commands
are treated as read-only and run with s_umount held for reading, but they
can still reach ext4_acquire_dquot(). Taking sb_start_intwrite() there
would deadlock against thaw_super(), which can only release the
SB_FREEZE_FS protection after taking s_umount exclusively. The preceding
change forbids those commands on a frozen filesystem, which makes the new
protection safe, so both patches have to be applied together.
Fixes: 907f4554e252 ("dquot: move dquot initialization responsibility into the filesystem")
Suggested-by: Jan Kara <jack@suse.cz>
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 prev parent reply other threads:[~2026-11-25 11:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 11:10 [PATCH v2 0/2] ext4: protect quota acquisition against filesystem freezing Ye Bin
2026-11-25 11:10 ` [PATCH v2 1/2] quota: Forbid Q_XGETQUOTA and Q_XGETNEXTQUOTA for frozen filesystem Ye Bin
2026-11-25 11:10 ` Ye Bin [this message]
2026-11-25 11:30 ` [PATCH v2 2/2] ext4: protect ext4_acquire_dquot against freezing sashiko-bot
2026-11-25 11:30 ` [PATCH v2 0/2] ext4: protect quota acquisition against filesystem 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=20261125111055.3672233-3-yebin@huaweicloud.com \
--to=yebin@huaweicloud.com \
--cc=adilger.kernel@dilger.ca \
--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