All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wesley Atwell" <atwellwea@gmail.com>
Cc: linux-ext4@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	tytso@mit.edu
Subject: Re: [PATCH] ext4: keep internal quota inode growth out of fast commits
Date: Tue, 01 Dec 2026 22:24:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-244341@kernel.org> (raw)
In-Reply-To: <20261201.da276679711b4a31aaa4af05bfcbc1be@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ext4: internal quota inode queued on s_fc_q when fallback
  clears ineligible flag
- [Medium] ext4: premature return in ext4_fc_commit() when fallback
  clears ineligible flag
- [Low] ext4: missing EXT4_FC_REASON_QUOTA_INODE in ext4_fc_stats
  tracepoint TP_printk
- [Low] ext4: duplicate ext4_fc_mark_ineligible() call on
  block-allocating quota writes
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] ext4: stale FC_Q_STAGING entries survive full commit in
  ext4_fc_cleanup() [1]
--

commit dcaa353a248a8dfde49d12865c6eaba385032da3
Author: Wesley Atwell <atwellwea@gmail.com>

ext4: keep internal quota inode growth out of fast commits

This commit marks the filesystem fast-commit ineligible when an internal
quota inode maps blocks or grows in size, and rechecks ineligibility in
ext4_fc_perform_commit() and ext4_fc_commit().

Link: https://lore.kernel.org/all/20261201013742.1562967-1-maxing.lan@bytedance.com/

> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index 9beb423b208f8..0c072cf800a4e 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
> @@ -1414,13 +1414,20 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid)
>  	 * doing logical-to-physical mapping.
>  	 */
>  	alloc_ctx = ext4_fc_lock(sb);
> +	/* A drained handle may have made this transaction ineligible. */
> +	if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) {
> +		ret = -EAGAIN;
> +		goto out_unlock_fc;
> +	}
>  	list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) {
>  		ext4_set_inode_state(&iter->vfs_inode,
>  				     EXT4_STATE_FC_COMMITTING);
>  	}

[Severity: High]
This problem wasn't introduced by this patch, but can ext4_fc_cleanup()
promote stale entries [1] from FC_Q_STAGING into FC_Q_MAIN when an
active handle in the committing transaction tracks updates after
JBD2_FULL_COMMIT_ONGOING is set?

CPU0 (transaction T)              CPU1 (kjournald2, transaction T)
ext4_unlink()
  ext4_journal_start()
                                  jbd2_journal_commit_transaction()
                                    j_flags |= JBD2_FULL_COMMIT_ONGOING
  ext4_fc_track_unlink()
    __track_dentry_update()
      list_add_tail(...,
        &s_fc_dentry_q[FC_Q_STAGING])
  ext4_journal_stop()
                                    jbd2_journal_wait_updates()
                                    ...
                                    ext4_fc_cleanup(journal, 1, T)
                                      /* drains FC_Q_MAIN only */
                                      list_splice_init(
                                        &s_fc_dentry_q[FC_Q_STAGING],
                                        &s_fc_dentry_q[FC_Q_MAIN])
                                        <-- stale T entry in FC_Q_MAIN

__track_dentry_update() and ext4_fc_track_template() queue updates onto
FC_Q_STAGING while JBD2_FULL_COMMIT_ONGOING is set.  Because
jbd2_journal_commit_transaction() sets that flag before calling
jbd2_journal_wait_updates(), in-flight handles in transaction T land on
FC_Q_STAGING.

At the end of full commit T, ext4_fc_cleanup() only drains FC_Q_MAIN and
splices FC_Q_STAGING into FC_Q_MAIN for transaction T+1.  A fast commit in
T+1 then logs those already-committed updates, so crash recovery replays
them after full commit T and corrupts directory state.

> +out_unlock_fc:
>  	ext4_fc_unlock(sb, alloc_ctx);
>  
> -	ret = ext4_fc_snapshot_inodes(journal, inodes, inodes_size,
> +	if (!ret)
> +		ret = ext4_fc_snapshot_inodes(journal, inodes, inodes_size,
>  				      &snap_inodes, &snap_ranges, &snap_err);
>  	jbd2_journal_unlock_updates(journal);
>  	locked_ns = ktime_to_ns(ktime_sub(ktime_get(), lock_start));
> @@ -1604,6 +1611,13 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
>  restart_fc:
>  	ret = jbd2_fc_begin_commit(journal, commit_tid);
>  	if (ret == -EALREADY) {
> +		/* An ongoing commit may not cover this ineligible transaction. */
> +		if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE) &&
> +		    !jbd2_transaction_committed(journal, commit_tid)) {
> +			ext4_fc_update_stats(sb, EXT4_FC_STATUS_INELIGIBLE, 0, 0,
> +					commit_tid);
> +			return jbd2_complete_transaction(journal, commit_tid);
> +		}

[Severity: Medium]
Can a waiter returning -EALREADY from jbd2_fc_begin_commit() miss
EXT4_MF_FC_INELIGIBLE and return 0 before the fallback full commit of
commit_tid finishes?

CPU0                          CPU1                          CPU2
/* fast commit on T,
 * s_fc_subtid == N,
 * past unlock_updates */
                              ext4_fc_mark_ineligible()
                              ext4_fc_commit(T)
                                subtid = N
                                jbd2_fc_begin_commit(T)
                                  /* sleeps on j_fc_wait */
atomic_inc(&s_fc_subtid)
jbd2_fc_end_commit()
  wake_up(&j_fc_wait)
                                                            ext4_fc_commit(T)
                                                              jbd2_fc_begin_commit(T)
                                                              jbd2_fc_end_commit_fallback()
                                                                ext4_fc_cleanup(0, T)
                                                                  clear EXT4_MF_FC_INELIGIBLE
                                                                wake_up(&j_fc_wait)
                                /* wakes, returns -EALREADY */
                                test EXT4_MF_FC_INELIGIBLE
                                  -> false
                                s_fc_subtid <= subtid
                                  -> false (N + 1 <= N)
                                return 0  <-- T not yet committed
                                                                jbd2_complete_transaction(T)

Inside jbd2_fc_end_commit_fallback() -> __jbd2_fc_end_commit(),
ext4_fc_cleanup(journal, 0, tid) clears EXT4_MF_FC_INELIGIBLE before
jbd2_complete_transaction(journal, tid) runs.  If CPU0's earlier fast
commit already incremented s_fc_subtid without covering CPU1's post-snapshot
ineligible update, CPU1 sees neither EXT4_MF_FC_INELIGIBLE nor
s_fc_subtid <= subtid and returns to ext4_sync_file() while commit_tid is
still uncommitted.

[ ... ]

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 07a62d8569d31..eec8cf33a4e73 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -929,6 +929,11 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
>  		internal_handle = true;
>  	}
>  
> +	/* Internal quota inode mappings cannot be replayed by fast commit. */
> +	if (ext4_is_quota_file(inode) &&
> +	    is_special_ino(inode->i_sb, inode->i_ino))
> +		ext4_fc_mark_ineligible(inode->i_sb,
> +					EXT4_FC_REASON_QUOTA_INODE, handle);
>  	ext4_fc_track_inode(handle, inode);

[Severity: Medium]
Can the internal quota inode still be queued onto s_fc_q[FC_Q_STAGING] if a
concurrent fast commit falls back before ext4_fc_track_inode() or
ext4_fc_track_range() runs?

CPU0 (transaction T)                  CPU1 (transaction T)
ext4_map_blocks(quota_inode)
  ext4_fc_mark_ineligible(..., T)
                                      ext4_fc_commit(T)
                                        /* sees EXT4_MF_FC_INELIGIBLE */
                                        jbd2_fc_end_commit_fallback()
                                          ext4_fc_cleanup(journal, 0, T)
                                            clear EXT4_MF_FC_INELIGIBLE
                                          j_flags |= JBD2_FULL_COMMIT_ONGOING
  ext4_fc_track_inode(quota_inode)
    /* ext4_fc_eligible() is true */
    list_add_tail(...,
      &s_fc_q[FC_Q_STAGING])
                                          jbd2_complete_transaction(T)
                                            ...
                                            ext4_fc_cleanup(journal, 1, T)
                                              list_splice_init(
                                                &s_fc_q[FC_Q_STAGING],
                                                &s_fc_q[FC_Q_MAIN])
                                              <-- quota_inode on FC_Q_MAIN

Both ext4_map_blocks() and ext4_quota_write() (via ext4_mark_inode_dirty())
still call ext4_fc_track_inode() on the internal quota inode after marking
the filesystem ineligible, relying on EXT4_MF_FC_INELIGIBLE to make
ext4_fc_eligible() return false.  However, jbd2_fc_end_commit_fallback()
runs ext4_fc_cleanup(journal, 0, tid) before jbd2_complete_transaction()
waits for open handles on tid to drain, and ext4_fc_cleanup() clears
EXT4_MF_FC_INELIGIBLE even when full == 0.  Once spliced onto FC_Q_MAIN,
the special quota inode is written out by the next fast commit and causes
mount recovery to fail in ext4_fc_replay_inode().

Should ext4_fc_track_inode() and ext4_fc_track_range() ignore special quota
inodes directly (or should ext4_fc_cleanup() only clear
EXT4_MF_FC_INELIGIBLE when full is set)?

> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 880f664d6c04b..76d617e023d2c 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -7539,6 +7539,10 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
>  			(unsigned long long)off, (unsigned long long)len);
>  		return -EIO;
>  	}
> +	/* Size can grow even when the quota inode's last block is mapped. */
> +	if (inode->i_size < off + len && ext4_is_quota_file(inode) &&
> +	    is_special_ino(sb, inode->i_ino))
> +		ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_QUOTA_INODE, handle);
>  
>  	do {
>  		bh = ext4_bread(handle, inode, blk,

[Severity: Low]
When a write to an internal quota file grows i_size and allocates a new
block via ext4_bread(..., EXT4_GET_BLOCKS_CREATE), doesn't this call
ext4_fc_mark_ineligible() twice for the same write—once here and again in
ext4_map_blocks()—taking s_fc_lock twice and double-counting
fc_ineligible_reason_count[EXT4_FC_REASON_QUOTA_INODE]?

> diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
> index 92048da9dae43..f73288d0d6ffe 100644
> --- a/include/trace/events/ext4.h
> +++ b/include/trace/events/ext4.h

[ ... ]

> @@ -141,7 +142,8 @@ TRACE_SNAP_ERR
>  		{ EXT4_FC_REASON_ENCRYPTED_FILENAME,	"ENCRYPTED_FILENAME"}, \
>  		{ EXT4_FC_REASON_MIGRATE,		"MIGRATE"},	\
>  		{ EXT4_FC_REASON_VERITY,		"VERITY"},	\
> -		{ EXT4_FC_REASON_MOVE_EXT,		"MOVE_EXT"})
> +		{ EXT4_FC_REASON_MOVE_EXT,		"MOVE_EXT"},	\
> +		{ EXT4_FC_REASON_QUOTA_INODE, "QUOTA_INODE"})

[Severity: Low]
show_fc_reason() is only used by FC_REASON_NAME_STAT() in
TRACE_EVENT(ext4_fc_stats).  Should TP_printk in TRACE_EVENT(ext4_fc_stats)
also be updated to print FC_REASON_NAME_STAT(EXT4_FC_REASON_QUOTA_INODE)?

[1] https://sashiko.dev/#/bug/linux-1abe6f8d-3af8-47e4-9040-53c37377486a

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201.da276679711b4a31aaa4af05bfcbc1be@gmail.com?part=1

      reply	other threads:[~2026-12-01 22:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 22:06 [PATCH] ext4: keep internal quota inode growth out of fast commits Wesley Atwell
2026-12-01 22:24 ` sashiko-bot [this message]

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=sashiko-outbox-244341@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atwellwea@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.