From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795900787; b=b+um3rVQf5tPsoulF9y862nF/BO//Fx+CRO/vBmktL5ixHhAzru4AUBh68xCQi2XNHQ4 JY225LpU/PK4H3ut9UK9BDecibgTgj9bOcBS4L4TdYFfJQu11kI9Xx2kI714xQ1wMUkTq n/IwmnJyQ7cy4/qIyCyR/P0fObHb4PUhVw8T8gJB+1Lc2VMYeRud5qlG4ssozE1FKXi4k Ci2tKVdJAb6rXzrjCOHhFv/7qz5Q/69NZKNOHaadpTMRsTcu0Bf+kCQ7rdFZhxgijw/bp nVjC2pA8l0262lGjG7OjnrX63Mc29lDXaakKLkfkdDj7vxmYHbyh29q6yTEjtzKSJ2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795900787; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=HMZG+HOpOGlqy37Teoz1STvsI7pGPRhiDVLIhJxlbUc=; b=uumWedlcK2QawFrClm3kXKxTiUk5bIb0ApSVsjrnzrUDUUg7wTT+fSel6tPskVd1rnlJ wyU+4UAyisbGuxgJ88SuVgj0uN97lZZHmGC6DpDkXhSpgVqBF7e1ZKjcCmvMrqirZcH5k TN7JVr+YYZZ2ki9krkrWUDR2HDZNZSIlbsKi1tdIBB/7EYnw9//cq0Pp3fz4efCALG64V S1U5aktUeO0LBm/LoQTeam9R5scoW0AFsv4ICnF8y52FUThDOvoGkU3uwe6PZiCGbzspT Y8fQWUUV1e8qcZfp83+Slu90iR0pyunPSO6ipPz5BQPCNAomAbO4ZwPOGbmRETnR9yw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=H1rfTLTK; arc=none smtp.remote-ip=209.85.167.173 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02386606A6A1 for ; Sat, 28 Nov 2026 21:19:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 02386606A6A1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=H1rfTLTK Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-57309bd40b1so4715304b6e.3 for ; Sat, 28 Nov 2026 13:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795900786; x=1796505586; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=HMZG+HOpOGlqy37Teoz1STvsI7pGPRhiDVLIhJxlbUc=; b=H1rfTLTKPH2qImPtClaHaIgi4RUc+Ghq9BGfbzIfYiCPciNJe9lIdv1WlGEPX8/SOp RxvMAljSPN+609JAVzphlEjWG6tc3vmM9522se2tzvSAsV/93+OwRZvWDhGfrMrskWnR yj5wGLduv1IPanSBJ0XmVou2Sxd2GxQxBm0ZAN8mKDMocrU0O7hf7fm3js/SjAcFeAUs HPkSgM37w36ptDN/n6zDWvMDnRdf8xcB5kE5FWPl+/TBhH6KyIaAI284LFDySW24Fg/s ibP6/p7gGYjjKGWBS6oHS714DZ8u5T/EhZPkHhCg8qzIG/wCh+fGmfO2/DfreZmN1ae/ tYLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795900786; x=1796505586; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HMZG+HOpOGlqy37Teoz1STvsI7pGPRhiDVLIhJxlbUc=; b=Qht4Y/f9XKCnhAStl1MLO/3d62kdCFldwZAHTmBAA9RXgYxUf9PKIbG1Bb6YjOO5T/ ZewpaNySHGwZs3FA5ZSvUTDJuqJTgL81L1t2MbUASFxb5f46dTG/NpJbA94/xM7f26GS lCSmlpSArdqAefOOQfHk+X+VZNWUzJOmkHy1MzOFYccbCrB73in+E16N+NYHZhDoht1C SZMmet33tC6toCrhT3OCWOLmXnMNxnq4RrnvHZ/Ee/+Uq7iGHXQUUl0opGfXDS33ViPp r2PVAbMz7h3bAM86cGs5rSkQUYps7DI/vVu9SpLDHTKInIja2xVRyX6lTSosOtHhako4 z8VQ== X-Forwarded-Encrypted: i=1; AL+hErG+aUR38m/WMV7d70XZHK0Tk23zrl5qDpAEAx3xM3AbgBXAbVRIJmAcv0a+MWuE3UlK6jRyfs4H9IIJ68g=@vger.kernel.org X-Gm-Message-State: APuU4Z+GRQq/UIoRw6bm/0O805iE9G0yhC8r3SoxRxRreI1ljmCfLvob XuxGBEINi1yXfvaGbyXeA+FSGjd7xtKDSXtGyTvG+jOkDKYFcza/P5jU X-Gm-Gg: AZFdTZcb9RlrQPDb31p7AigtfOuTLhh+H39k5O0CkU1Oyd1hOaLkvqyvwpWa0JrEDBP 5V9WOxavaifxb/yN0kejqpeHJYumGJYGUiRqoH0lE+sJOeNklamdSEHSLpjkDGuVcJVpcBNDbqw pyfbl6AHwEFJnKbHnPJdk5jFMGXJYRBHV9kHrAbVDp5vIB3e+MVOSerlCHePhkGjbHgsp9DMFiG ywscW088cih9UMDK0WAPGfc66WQMi/9tdOlhQOJMvm5GUI0236gA5EEOms/y7IwCsthHuzqwil7 RaZyV4RZCJnSMa0TXMBURJI2wIuZWPO8QHPYA1VokHp0YuxoluY+gQ2HfdDQmhi5bc6KQ6scQV+ eqOJWM+RImB5l0DB2dtvG43cN7BJTeIJtkujHpLrV/kMS3EjMDJKisBjfM4C8Xfo6kTeTWwrvS0 FNRCJfMOxQroDNAIGTO/vvOgXE5mNqSw2OK2Fz83CNt0D39ABIY386JnvaoVZRV4jvuzbQUjkEn MM7tiBJ1bvdESSwMiVMjT0rHXeUO4bMShxedNprtK2rvW3ugzhxlaIHqcHO2ABsOxivIThU2Pum QhmdW8No5VpdEyHXktKwPrbYMAlNzwitzIEaM2Z2V3Zx5Ri9yhONWYURMZbgFubLOQpi6x8p39s TQtaQezYYdUqFIOEAhF1EvEvPJUl3UVdr7+t/l5nQypYunno= X-Received: by 2002:a05:6808:191a:b0:573:2541:17fe with SMTP id 5614622812f47-57a0ac2f810mr32920630b6e.25.1795900785738; Sat, 28 Nov 2026 13:19:45 -0800 (PST) Received: from Wes-PC.localdomain (108-212-132-20.lightspeed.irvnca.sbcglobal.net. [108.212.132.20]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485a164sm20219780b6e.10.2026.11.28.13.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 13:19:45 -0800 (PST) From: Wesley Atwell 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@vger.kernel.org, linux-ext4@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH] ext4: force a full commit when quota data is modified Date: Sat, 28 Nov 2026 14:19:25 -0700 Message-ID: X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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