From: "yebin (H)" <yebin10@huawei.com>
To: Jan Kara <jack@suse.cz>, <linux-ext4@vger.kernel.org>
Cc: <tytso@mit.edu>
Subject: Re: [PATCH v3 2/2] ext4: protect ext4_acquire_dquot against freezing
Date: Sat, 28 Nov 2026 11:49:03 +0800 [thread overview]
Message-ID: <6B0A4F2F.60203@huawei.com> (raw)
In-Reply-To: <sashiko-outbox-235531@kernel.org>
On 2026/11/26 20:50, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] ext4: s_umount vs SB_FREEZE_FS deadlock in ext4_acquire_dquot()
> via vfs_ustat()
> --
>
> commit 5d68ea2752fdd861a0ff07e25a26ec6f31917f7a
> Author: Ye Bin <yebin10@huawei.com>
>
> ext4: protect ext4_acquire_dquot against freezing
>
> This commit takes sb_start_intwrite() in ext4_acquire_dquot() when no
> transaction is running so that quota acquisition during file open does not
> start a transaction on a frozen filesystem.
>
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index 880f664d6c04b..af965cab32e7f 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -7168,11 +7168,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;
>> + }
>
> [Severity: High]
> Can this cause an ABBA deadlock between sb->s_umount and SB_FREEZE_FS when
> ustat(2) runs on a frozen filesystem?
>
> Commit "quota: Forbid Q_XGETQUOTA and Q_XGETNEXTQUOTA for frozen filesystem"
> blocks quotactl from reaching ext4_acquire_dquot() on a frozen superblock,
> but vfs_ustat() also acquires s_umount for reading via user_get_super()
> without checking whether the filesystem is frozen:
>
> fs/statfs.c:vfs_ustat() {
> struct super_block *s = user_get_super(dev, false);
> int err;
> if (!s)
> return -EINVAL;
>
> err = statfs_by_dentry(s->s_root, sbuf);
> drop_super(s);
> return err;
> }
>
> When project quota limits are enabled and the root directory inode has
> EXT4_INODE_PROJINHERIT set, ext4_statfs() calls ext4_statfs_project() ->
> dqget(). Because the root inode is a directory, its project dquot is not
> kept attached in i_dquot[PRJQUOTA], so if no other inode holds an active
> reference to that project dquot when the filesystem is frozen, dqget()
> invokes ext4_acquire_dquot() with no running transaction:
>
> CPU0 CPU1
> ---- ----
> freeze_super()
> /* freezes at SB_FREEZE_COMPLETE */
> vfs_ustat()
> user_get_super()
> down_read(&sb->s_umount)
> ...
> ext4_acquire_dquot()
> sb_start_intwrite(sb)
> thaw_super()
> super_lock_excl(sb)
> down_write(&sb->s_umount)
>
> *** DEADLOCK ***
>
> CPU0: vfs_ustat() -> statfs_by_dentry() -> ext4_statfs() ->
> ext4_statfs_project() -> dqget() -> ext4_acquire_dquot()
> CPU1: thaw_super() -> super_lock_excl()
>
> CPU0 blocks in sb_start_intwrite() waiting for SB_FREEZE_FS while holding
> s_umount for reading, and thaw_super() cannot unlock SB_FREEZE_FS until it
> acquires s_umount exclusively, leaving the filesystem permanently frozen.
>
This path indeed also has the ABBA deadlock issue.
(1) Could it be simply addressed by adding a check within the ext4 file system:
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b021cbeb5f3a..c1d6fec2481a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7132,8 +7132,16 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
buf->f_fsid = uuid_to_fsid(es->s_uuid);
#ifdef CONFIG_QUOTA
+ /*
+ * Instantiating a not-yet-cached project dquot takes freeze
+ * protection in ext4_acquire_dquot(). statfs can be called with
+ * s_umount held (ustat(2)), so doing that on a frozen filesystem
+ * would deadlock with thaw_super(). Skip the project limits while
+ * frozen instead; statfs must not write at that point anyway.
+ */
if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&
- sb_has_quota_limits_enabled(sb, PRJQUOTA))
+ sb_has_quota_limits_enabled(sb, PRJQUOTA) &&
+ READ_ONCE(sb->s_writers.frozen) == SB_UNFROZEN)
ext4_statfs_project(sb, EXT4_I(dentry->d_inode)->i_projid, buf);
#endif
return 0;
However, what's strange about this approach is that it cannot obtain PRJQUOTA
data when in a frozen state.If modifications are made to the VFS layer, it could
affect the behavior of other file systems. It seems unreasonable to just block
the query operation.In addition, this will also change the behavior of other
system calls of the ext4 file system.The process of calling ext4_statfs() does
not always hold the sb->s_umount lock. It seems difficult to wait for the file
system to unfreeze.
(2) Another solution is to obtain only cached data during the freezing process.
In other cases, data is obtained normally.
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b021cbeb5f3a..84d9942b7e2b 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7063,7 +7063,20 @@ static int ext4_statfs_project(struct super_block *sb,
u64 curblock;
qid = make_kqid_projid(projid);
- dquot = dqget(sb, qid);
+ /*
+ * A frozen filesystem must not be written to. Instantiating a dquot
+ * that is not cached yet would start a transaction, and statfs may run
+ * with s_umount held (ustat(2)), where taking freeze protection in
+ * ext4_acquire_dquot() would deadlock with thaw_super(). In that case
+ * only use an already cached dquot and skip the project limits if there
+ * is none.
+ */
+ if (READ_ONCE(sb->s_writers.frozen) != SB_UNFROZEN)
+ dquot = dqget_cached(sb, qid);
+ else
+ dquot = dqget(sb, qid);
+ if (!dquot)
+ return 0;
if (IS_ERR(dquot))
return PTR_ERR(dquot);
spin_lock(&dquot->dq_dqb_lock);
(3) The ustat system call transfers the dentry of the root. Can the root's quota
be resident in each path, and the root be specially processed in ext4_statfs().
Hello Jan, do you have any good suggestions or better solutions for fixing this issue?
According to the check, syncfs can be triggered when the file system is frozen.In this
case, the following two processes may cause deadlocks.
ext4_sync_fs()->dquot_writeback_dquots()->flush_delayed_work("a_release_work) // hold sb->s_umount lock
quota_release_workfn()->ext4_release_dquot()->sb_start_intwrite() // wait unfreeze
ext4_evict_inode()->if (inode->i_nlink) goto no_delete;->ext4_clear_inode()->dquot_drop(inode)
...->dqput()->queue_delayed_work(quota_unbound_wq, "a_release_work, 1);
In ext4_sync_fs(), it is more reasonable to call dquot_writeback_dquots() only when
(sb->s_writers.frozen!= SB_FREEZE_COMPLETE)?
next prev parent reply other threads:[~2026-11-28 3:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 12:36 [PATCH v3 0/2] ext4: protect quota acquisition against filesystem freezing Ye Bin
2026-11-26 12:36 ` [PATCH v3 1/2] quota: Forbid Q_XGETQUOTA and Q_XGETNEXTQUOTA for frozen filesystem Ye Bin
2026-11-26 12:36 ` [PATCH v3 2/2] ext4: protect ext4_acquire_dquot against freezing Ye Bin
2026-11-26 12:50 ` sashiko-bot
2026-11-28 3:49 ` yebin (H) [this message]
2026-11-26 12:50 ` [PATCH v3 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=6B0A4F2F.60203@huawei.com \
--to=yebin10@huawei.com \
--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