* [PATCH] ext4: force a full commit when quota data is modified
@ 2026-11-28 21:19 Wesley Atwell
2026-11-28 21:45 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Wesley Atwell @ 2026-11-28 21:19 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Ojaswin Mujoo, Zhang Yi,
Jan Kara, Ritesh Harjani (IBM), Steven Rostedt,
Harshad Shirwadkar, Baokun Li, Mathieu Desnoyers,
Masami Hiramatsu
Cc: Wesley Atwell, linux-kernel, linux-ext4, linux-trace-kernel
Fast commits record regular inode and extent changes, but not the
contents of ext4's internal quota file. With journalled user quotas
and fast commits, an fsynced file can survive a crash while its quota
charge does not. Recovery can then let the user exceed a hard limit.
On the unmodified ext4 dev tree, a QEMU guest wrote and fsynced an 8 MiB
file as UID 1000 under a 16 MiB hard limit. After an abrupt stop,
recovery kept the file and its hash but reported zero quota usage; the
user then wrote another 10 MiB successfully. Full-commit controls kept
the charge and stopped that write at the limit.
Mark the current transaction fast-commit-ineligible when
ext4_quota_write() modifies a quota buffer. The first eligibility check
alone is insufficient: an active handle can write quota after that
check but before jbd2_journal_lock_updates() drains handles. Recheck
under the update barrier before writing the fast-commit log. Another
quota-changing handle can join after the barrier and share the running
transaction. If its fsync waits behind a fast commit, an advanced
fast-commit sub-TID does not make its quota update durable. Snapshot
ineligibility before reading the sub-TID and wait for a full JBD2 commit
when that fsync receives -EALREADY and its TID is still uncommitted.
Name the new QUOTA reason in the ext4 trace output as well.
With the fix, the crash/recovery workload retained 8,392,704 quota
bytes and two inodes, and the 10 MiB follow-up stopped with EDQUOT.
Test-only timing pauses also exercised normal UID 1000 fallocate and
fsync operations before and after the update barrier. The changed
kernel preserved a 12 MiB file with 12,587,008 charged bytes in the first
case; in the second, fsync waited for the full commit and recovery kept
the extended file and matching quota charge. The pauses only scheduled
those operations; they did not create quota writes. Quota-changing
transactions pay the full-commit cost. No latency benchmark was run.
OpenAI Codex identified the quota durability gap, drafted the fix and
changelog, and prepared the QEMU crash recovery and concurrency tests.
The changed kernel retained the quota charge after recovery, returned
EDQUOT on the over-limit write, and preserved quota accounting in both
controlled overlaps.
Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
Cc: stable@vger.kernel.org
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
fs/ext4/fast_commit.c | 28 +++++++++++++++++++++++++++-
fs/ext4/fast_commit.h | 1 +
fs/ext4/super.c | 2 ++
include/trace/events/ext4.h | 4 +++-
4 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 9beb423b208f..5e7c9b4b0c2b 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1414,6 +1414,16 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid)
* doing logical-to-physical mapping.
*/
alloc_ctx = ext4_fc_lock(sb);
+ /*
+ * An active handle may have marked this transaction ineligible
+ * since the first check in ext4_fc_commit(). Recheck after draining
+ * those handles and before writing a fast commit.
+ */
+ if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) {
+ ext4_fc_unlock(sb, alloc_ctx);
+ ret = -EAGAIN;
+ goto out_unlock_updates;
+ }
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);
@@ -1422,6 +1432,7 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid)
ret = ext4_fc_snapshot_inodes(journal, inodes, inodes_size,
&snap_inodes, &snap_ranges, &snap_err);
+out_unlock_updates:
jbd2_journal_unlock_updates(journal);
locked_ns = ktime_to_ns(ktime_sub(ktime_get(), lock_start));
atomic64_add(locked_ns, &snap_stats->lock_updates_ns_total);
@@ -1588,10 +1599,11 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
struct super_block *sb = journal->j_private;
struct ext4_sb_info *sbi = EXT4_SB(sb);
int nblks = 0, ret, bsize = journal->j_blocksize;
- int subtid = atomic_read(&sbi->s_fc_subtid);
+ int subtid, alloc_ctx;
int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0;
ktime_t start_time, commit_time;
int old_ioprio, journal_ioprio;
+ bool ineligible_on_entry;
if (!test_opt2(sb, JOURNAL_FAST_COMMIT))
return jbd2_complete_transaction(journal, commit_tid);
@@ -1601,6 +1613,12 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
start_time = ktime_get();
old_ioprio = get_current_ioprio();
+ /* Keep ineligibility observed before waiting for another fast commit. */
+ alloc_ctx = ext4_fc_lock(sb);
+ ineligible_on_entry = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
+ subtid = atomic_read(&sbi->s_fc_subtid);
+ ext4_fc_unlock(sb, alloc_ctx);
+
restart_fc:
ret = jbd2_fc_begin_commit(journal, commit_tid);
if (ret == -EALREADY) {
@@ -1608,6 +1626,13 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
if (atomic_read(&sbi->s_fc_subtid) <= subtid &&
tid_gt(commit_tid, journal->j_commit_sequence))
goto restart_fc;
+ if (tid_gt(commit_tid, journal->j_commit_sequence) &&
+ (ineligible_on_entry ||
+ ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE))) {
+ ext4_fc_update_stats(sb, EXT4_FC_STATUS_INELIGIBLE,
+ 0, 0, commit_tid);
+ return jbd2_complete_transaction(journal, commit_tid);
+ }
ext4_fc_update_stats(sb, EXT4_FC_STATUS_SKIPPED, 0, 0,
commit_tid);
return 0;
@@ -2726,6 +2751,7 @@ static const char * const fc_ineligible_reasons[] = {
[EXT4_FC_REASON_MIGRATE] = "Inode format migration",
[EXT4_FC_REASON_VERITY] = "fs-verity enable",
[EXT4_FC_REASON_MOVE_EXT] = "Move extents",
+ [EXT4_FC_REASON_QUOTA] = "Quota data modified",
};
int ext4_fc_info_show(struct seq_file *seq, void *v)
diff --git a/fs/ext4/fast_commit.h b/fs/ext4/fast_commit.h
index 2f77a37fb101..1a3294fad6c6 100644
--- a/fs/ext4/fast_commit.h
+++ b/fs/ext4/fast_commit.h
@@ -100,6 +100,7 @@ enum {
EXT4_FC_REASON_MIGRATE,
EXT4_FC_REASON_VERITY,
EXT4_FC_REASON_MOVE_EXT,
+ EXT4_FC_REASON_QUOTA,
EXT4_FC_REASON_MAX
};
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 880f664d6c04..8f3c1de720be 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7560,6 +7560,8 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
memcpy(bh->b_data+offset, data, len);
flush_dcache_folio(bh->b_folio);
unlock_buffer(bh);
+ /* Fast commit does not track quota file updates. */
+ ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_QUOTA, handle);
err = ext4_handle_dirty_metadata(handle, NULL, bh);
brelse(bh);
out:
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 92048da9dae4..56edde70dbac 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -105,6 +105,7 @@ TRACE_DEFINE_ENUM(EXT4_FC_REASON_ENCRYPTED_FILENAME);
TRACE_DEFINE_ENUM(EXT4_FC_REASON_MIGRATE);
TRACE_DEFINE_ENUM(EXT4_FC_REASON_VERITY);
TRACE_DEFINE_ENUM(EXT4_FC_REASON_MOVE_EXT);
+TRACE_DEFINE_ENUM(EXT4_FC_REASON_QUOTA);
TRACE_DEFINE_ENUM(EXT4_FC_REASON_MAX);
#undef EM
@@ -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, "QUOTA"})
TRACE_DEFINE_ENUM(CR_POWER2_ALIGNED);
TRACE_DEFINE_ENUM(CR_GOAL_LEN_FAST);
base-commit: aceadbccd428fb8e6593b27a3091d961f80225d1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ext4: force a full commit when quota data is modified
2026-11-28 21:19 [PATCH] ext4: force a full commit when quota data is modified Wesley Atwell
@ 2026-11-28 21:45 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-28 21:45 UTC (permalink / raw)
To: Wesley Atwell; +Cc: linux-ext4, linux-trace-kernel, tytso
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ext4: premature clearing of EXT4_MF_FC_INELIGIBLE in
ext4_fc_cleanup()
- [Medium] ext4: late ext4_fc_mark_ineligible() in ext4_quota_write()
tracks quota inode
- [Medium] ext4: stale ineligible_on_entry in ext4_fc_commit() forces
full commit
- [Low] ext4: missing EXT4_FC_REASON_QUOTA in ext4_fc_stats tracepoint
TP_printk()
- [Low] ext4: unnecessary s_fc_lock acquisition on entry to
ext4_fc_commit()
--
commit 27f3c8498a2c6f9057fcdc7d749d8315055f56a8
Author: Wesley Atwell <atwellwea@gmail.com>
ext4: force a full commit when quota data is modified
This commit marks the active transaction ineligible for fast commit when
ext4_quota_write() modifies a quota block, and updates ext4_fc_commit()
and ext4_fc_perform_commit() to fall back to a full commit when quota
updates race with an ongoing fast commit.
> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index 9beb423b208f8..5e7c9b4b0c2b1 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
[ ... ]
> @@ -1588,10 +1599,11 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
> struct super_block *sb = journal->j_private;
> struct ext4_sb_info *sbi = EXT4_SB(sb);
> int nblks = 0, ret, bsize = journal->j_blocksize;
> - int subtid = atomic_read(&sbi->s_fc_subtid);
> + int subtid, alloc_ctx;
> int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0;
> ktime_t start_time, commit_time;
> int old_ioprio, journal_ioprio;
> + bool ineligible_on_entry;
>
> if (!test_opt2(sb, JOURNAL_FAST_COMMIT))
> return jbd2_complete_transaction(journal, commit_tid);
> @@ -1601,6 +1613,12 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
> start_time = ktime_get();
> old_ioprio = get_current_ioprio();
>
> + /* Keep ineligibility observed before waiting for another fast commit. */
> + alloc_ctx = ext4_fc_lock(sb);
> + ineligible_on_entry = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
> + subtid = atomic_read(&sbi->s_fc_subtid);
> + ext4_fc_unlock(sb, alloc_ctx);
[Severity: Low]
Is taking sbi->s_fc_lock on entry to ext4_fc_commit() needed here?
EXT4_MF_FC_INELIGIBLE is an atomic bit in sbi->s_mount_flags, and
s_fc_subtid is incremented outside sbi->s_fc_lock via atomic_inc(), so
ext4_fc_lock() does not serialize the two reads against s_fc_subtid
updates. Acquiring sbi->s_fc_lock unconditionally before
jbd2_fc_begin_commit() also blocks callers whose commit_tid is already
committed behind any thread holding sbi->s_fc_lock during fast-commit log
writing in ext4_fc_perform_commit().
> +
> restart_fc:
> ret = jbd2_fc_begin_commit(journal, commit_tid);
> if (ret == -EALREADY) {
> @@ -1608,6 +1626,13 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
> if (atomic_read(&sbi->s_fc_subtid) <= subtid &&
> tid_gt(commit_tid, journal->j_commit_sequence))
> goto restart_fc;
> + if (tid_gt(commit_tid, journal->j_commit_sequence) &&
> + (ineligible_on_entry ||
> + ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE))) {
> + ext4_fc_update_stats(sb, EXT4_FC_STATUS_INELIGIBLE,
> + 0, 0, commit_tid);
> + return jbd2_complete_transaction(journal, commit_tid);
> + }
[Severity: High]
Can a waiting fsync() caller still miss EXT4_MF_FC_INELIGIBLE and return
0 before commit_tid is committed?
When a fast commit falls back to a full commit,
jbd2_fc_end_commit_fallback() runs __jbd2_fc_end_commit(journal, tid,
true), which invokes ext4_fc_cleanup(journal, 0, tid) and wakes j_fc_wait
before calling jbd2_complete_transaction(journal, tid). In
ext4_fc_cleanup(), clearing EXT4_MF_FC_INELIGIBLE is not gated on full:
fs/ext4/fast_commit.c:ext4_fc_cleanup() {
...
if (tid_geq(tid, sbi->s_fc_ineligible_tid)) {
sbi->s_fc_ineligible_tid = 0;
ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
}
...
}
If a third thread falls back to a full commit after an earlier fast
commit has already incremented s_fc_subtid, a waiter on j_fc_wait can see
both ineligible_on_entry and EXT4_MF_FC_INELIGIBLE as false:
CPU0 CPU1 CPU2
ext4_fc_commit(T)
jbd2_fc_begin_commit(T)
...
unlock_updates()
ext4_fc_commit(T)
ineligible_on_entry = 0
subtid = S
jbd2_fc_begin_commit(T)
/* sleeps on j_fc_wait */
ext4_quota_write()
ext4_fc_mark_ineligible()
ext4_fc_commit(T)
/* sleeps on j_fc_wait */
atomic_inc(s_fc_subtid)
jbd2_fc_end_commit()
wake_up(j_fc_wait)
jbd2_fc_begin_commit(T) == 0
/* sees FC_INELIGIBLE */
jbd2_fc_end_commit_fallback()
ext4_fc_cleanup(0, T)
clear(FC_INELIGIBLE)
wake_up(j_fc_wait)
/* wakes with -EALREADY */
s_fc_subtid > S
ineligible_on_entry == 0
test(FC_INELIGIBLE) == 0
return 0; <-- T uncommitted
jbd2_complete_transaction(T)
CPU2 then returns from fsync() with EXT4_FC_STATUS_SKIPPED before the
full commit of transaction T completes. Only clearing
EXT4_MF_FC_INELIGIBLE in ext4_fc_cleanup() when full is true avoids
dropping the flag before transaction T has committed.
[Severity: Medium]
Can a stale ineligible_on_entry from a previous committing transaction
force a redundant full commit on a newly fast-committed transaction?
While an ineligible transaction T is undergoing a full commit,
JBD2_FULL_COMMIT_ONGOING and EXT4_MF_FC_INELIGIBLE remain set until the
end of jbd2_journal_commit_transaction(), whereas updates for transaction
T + 1 can start once T leaves T_LOCKED. If two threads call
ext4_fc_commit(journal, T + 1) while T is still committing, both capture
ineligible_on_entry = true (from T) and subtid = S, then sleep in
jbd2_fc_begin_commit() on j_fc_wait.
When T finishes its full commit, ext4_fc_cleanup(journal, 1, T) clears
EXT4_MF_FC_INELIGIBLE and wakes both threads. Both see s_fc_subtid <= S
and jump to restart_fc without refreshing ineligible_on_entry. The first
thread wins jbd2_fc_begin_commit(journal, T + 1), sees
EXT4_MF_FC_INELIGIBLE is now clear, fast-commits T + 1, and increments
s_fc_subtid to S + 1. The second thread then wakes from
jbd2_fc_begin_commit() with -EALREADY, sees s_fc_subtid > S and
ineligible_on_entry == true, and calls jbd2_complete_transaction(journal,
T + 1) on a transaction that was just fast-committed.
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 880f664d6c04b..8f3c1de720be3 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -7560,6 +7560,8 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
> memcpy(bh->b_data+offset, data, len);
> flush_dcache_folio(bh->b_folio);
> unlock_buffer(bh);
> + /* Fast commit does not track quota file updates. */
> + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_QUOTA, handle);
> err = ext4_handle_dirty_metadata(handle, NULL, bh);
> brelse(bh);
> out:
[Severity: Medium]
Should ext4_fc_mark_ineligible() be called before ext4_bread() in
ext4_quota_write()?
Earlier in ext4_quota_write(), ext4_bread(handle, inode, blk,
EXT4_GET_BLOCKS_CREATE | EXT4_GET_BLOCKS_METADATA_NOFAIL) can allocate a
new block for the quota inode while the transaction is still eligible.
Inside ext4_map_blocks(), ext4_fc_track_inode(handle, inode) runs before
ext4_map_create_blocks() and queues the quota inode onto sbi->s_fc_q. If
ext4_bread() or ext4_journal_get_write_access() then returns an error,
ext4_quota_write() returns before reaching ext4_fc_mark_ineligible(),
leaving the transaction fast-commit eligible with the special quota inode
queued on sbi->s_fc_q. A later fast commit will write an
EXT4_FC_TAG_INODE tag for that quota inode, which fails recovery replay in
ext4_fc_replay_inode() because ext4_iget(sb, ino, EXT4_IGET_NORMAL)
rejects special quota inodes with -EFSCORRUPTED.
> diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
> index 92048da9dae43..56edde70dbac1 100644
> --- a/include/trace/events/ext4.h
> +++ b/include/trace/events/ext4.h
> @@ -105,6 +105,7 @@ TRACE_DEFINE_ENUM(EXT4_FC_REASON_ENCRYPTED_FILENAME);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_MIGRATE);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_VERITY);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_MOVE_EXT);
> +TRACE_DEFINE_ENUM(EXT4_FC_REASON_QUOTA);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_MAX);
>
> #undef EM
> @@ -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, "QUOTA"})
[Severity: Low]
show_fc_reason() is only used by FC_REASON_NAME_STAT() in
TRACE_EVENT(ext4_fc_stats), whose TP_printk() format string and argument
list stop at EXT4_FC_REASON_ENCRYPTED_FILENAME and were not updated to
include FC_REASON_NAME_STAT(EXT4_FC_REASON_QUOTA). As a result, the
EXT4_FC_REASON_QUOTA entry in show_fc_reason() is unused and never
appears in the ext4_fc_stats trace output.
--
Sashiko AI review · https://sashiko.dev/#/patchset/kernel-7f509bcdfe16388c-v1.atwellwea@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-28 21:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 21:19 [PATCH] ext4: force a full commit when quota data is modified Wesley Atwell
2026-11-28 21:45 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox