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 --- 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