From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795900787; b=SDaNOAh0B4bT6bEiVYx8MSpUzIdZ6ySAOLzYfWhjDXjRf7wCiteq/C4WmqDhzlnuhadZ zx/bp0RYwvdhUT72nzQINFpi1YzXz4KznTi03qTiF7EV/FoaB2oho8owOm6N+WQyumKHI STKHNImih89SMS15nzvUtfM05dTjpkVB2edKWoPUihFjb2C+f7YdgizdSFQxAi5Hfzf+R btSZ/oy4cgV/Dehm2N5JBFvHHxte6nr+uJyX0SGU07llOs/uuok67gf9/uEfYc5axFaW+ 6WRAgTgUQ6jX9vY0qibyFhXioqk6nrgCMQc8eRGaKER3QdXmqaqTrLGEZiUBnaGrzzA== 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=c4JsHSvHIR7hwZMhqwrB9IpjwVyxEK+rNcuGBo4sy9MSY655Jk5PAXYYPE6YPFWvqwaf 7r085ovdom4WBBRbaVcc8NuiLaLUVNm3vlkB7ZMAnebAGVmB278+Aq483Nm/Wu0IVE5C+ 5k+5egfjrJFG/+N36zSzLZlU3FcbeOYejngW/QDrwIxktRTo1yxuMlmRSKi7gl1eACmv7 OoLBgWKgaRW8lytitLWNXb0tKp2ls2T37q1X9WRoS4Ziz+DgpBuQPDv35Xefogzq0rGYt Ld81hxjZtpVotNxQeMfv4VniFH1VpTyVAHxz/SsFsYCpudXvF0UTHsLdVTNcLSi6aqA== 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.160.53 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 D1F92606A333 for ; Sat, 28 Nov 2026 21:19:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1F92606A333 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-oa1-f53.google.com with SMTP id 586e51a60fabf-43bf9548df4so8634336fac.0 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=gDl5X5XAfUHj6kjz5nQxt58jGdD+Ei8ANtfNpSccegLtm+5xG9j6Szjc6cPvRJzqLC LYkSRJttXYg/xWcP5JYgwoHRbcly8W33lBXUEo0NsXDmZbTdq5INxMnwjqaoef84Rpmx 4sLnBgHOD38kl75ozOOT1DzEITtAUr9w2dP5lRNoR4MMyOKQpKG2OQyRbtB2RFj8ZxEs 7Y3D2EYw4HIFl0a+08HJw/ZISsyoY+hI29HQXdi13LbGnvy55jzFfHwTJhAyl8vlB9Hv Oh0WQVAOPPjWe3ZL8e94cJfFCt5XP1vNLtXmZbH2bKQoBUc02lXETnLfTOdHHI6t7qUm TnEg== X-Forwarded-Encrypted: i=1; AL+hErGqEO6ltIaqJpiz1St+KW2J4Pl0UOCqdSSvvDUjdWudXsr/p7L93yjY2JOh5/h6nhDChIW3GU/MYkTP@vger.kernel.org X-Gm-Message-State: APuU4Z+WMzDVHD7nq14FtQMt55EB1EuweXzl9mquGmutPhGhBUh3lrfj dTOgLgB3DceDqFS7/Vwz9qFnvw2CoZ6lofO+nPRzI0KRU2pQRtAP1FQ8 X-Gm-Gg: AZFdTZfJppUl1WP1O4qonffxG1DoR5nhRRGu7pbPNwDnaA4NjEJkdQvdKb7OC/bsvk8 kSCe3TAYy7sPSoNjKl72Y6iKDtj2ErELrMOyfpvPvAGGFIRBgN0NX261nxFb2wqjcsmlcufyz/f tX2p9T/1E4n2nJh+2wRIRd7HuD1fJqh2GTgCDu5jiFzYuIaq5YuyMKwbjFcNMPO50c2kEqf6Gai iAiEtZftZVWNGoIwV8/aI3mwu4rd91nrKI6gLp0iEKaHXcZ3+/YF1IeJwXCunKf9JL6Kq+JbhPi jrzTWbdu7ASUINHkpZneeupcW2BK+2zWeRlrsWrGXzGtiGb0Z/tMZQ4GHvhbI+UWmVIwZPOBrA+ NvgU0StFJ/mTNg7s3kbaZGharX7wRfqQi9hXOrWNE/K5nJTjXqezcbyut7Tij5NBpohgZ9mQIb+ 8sMvc+nNPBtCi6Msarx6NM2XoHALVDsQSJ4qg3w+VRLA9dA2LEYlTwTK5kEpU1ZsM4l8e+3O46u +JQUGjCLTBGEErbbXlkh7A9rgsuGVFQZoq0RJWEzkbe7UmG4WNOednpnQYvpVoYQq4cuuLLV2gq hqw2vQHiLc9sAqH4UVuFjZRb3Hpuoei0DteYk30VOPM2vlyZ3SgPycMVjuzqYgiPvne3ksXni/P 5Awp0bU9R6tkbayQulNwjIrjmY1XdqfDLREWFVdWtPIZNz3E= 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-ext4@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