From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795900787; b=CP/Jfwgh0aCwRGMetLAXrkDhW1qgbUMCAhgGwuiJR3LDPL+z4q7szu6b4alSE0y6yw6L 6JPVyAxZx75MYMYAXSCmdktowPseEm9vRNXno4mTvfYXtihcw92voXuhDCKj/0jGXu1sS tt65yMbu3R4HRYrUh1ptmXs47N02ASV2sxDGFRT+PD/jciv5Q3Gyyb5ThsEn0iaOeFSYP 34zPuIS1W4FVaGHH3kpe9otPhKrk5zazhC3LXA2UCwphTJeedPr38zAlg9FJuTpqzTJte MJCPYwGKWM43w+Tl9ShRIL9t6gyX/oPrxsviVyDVZ1X20azaXZM4BoZRnRL9+74uugA== 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=svAyNQJXFs66S2aZX+hNMEP0iUWUWvvqvu6av8OJzNoPrP4IlC5qbZYX44VgpMDDS512 6MGJP6OeQwfhWcnplJnylPimuo8sjXKK7gnliwBMKgOUIjbycjL5mtNAeNdTHZYO7GBBR V4cs8087FtBDu7v8x08T20pSHcTxOcEmd2/nCEqHgkThnOlUFdNCIvn02Cdd1/+WVxrBH E4Z8QL4hY2XYFjDpJ1XHy7sOEjb9LOEnO2aEiauqD1wgxBTjrZm+iVQdxWxfvnua+62+G RJL1btNwb1pcYfjFJFAUAxXccUXsKqzxEhoyiCiY5VOlvUAV+kooS6QL5z6600Rixjg== 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.182 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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 D3ACD606A6A0 for ; Sat, 28 Nov 2026 21:19:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D3ACD606A6A0 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-f182.google.com with SMTP id 5614622812f47-53ec92375d2so5634573b6e.1 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=mcII1ioQCUGtvrLtkDPwJdLyhjbAUGA/22nfUs8c84VjfWgJGjoWSeIDIrqFapCoyz zmtUM02p+pBBDaxkyKXfZdpsFc/uktWbzxVBSbL1A0KKzRJkoHITR4PoHRXY10gpkIDW qSolYLDG808LB0GHUdEq/+XFyCARMtA+75ybjxN7fpGqiNG7XLY6tQxyAklyRkKElE9t 8J6ipufaeylyqdGQgsf93bdCcsIPFuZBkfGzhm/sABhfkf/F/inwkXV1tcZy/1GKKw8u FFiKpAAjoZBCjPBoDFKGtPklPxaUyZS5epyXL1xM1N7YCmsu13j1JIJfdaXvtteW1Hd4 QMSw== X-Forwarded-Encrypted: i=1; AL+hErEaUsZs8CczkJx/7QWiN0KluJCnSbLVHL1AU6sDAL86ZuKMwPcnNGPBiHpBHEz4MV0S2Ll9zSRS1Sda5vPN+rl1Vl8=@vger.kernel.org X-Gm-Message-State: APuU4Z83sFqyxjl3Q1ZYwlu0Ab5lh2qFOLgVxrO5vnO7oa1CPSya7IAF t16/pQNjaAXAzTB+30BglN2bfMRcvcL6HzRAjFPeeYZHmt4IGZao0NcP X-Gm-Gg: AZFdTZerlqpICJSXEvGkYZEkYckThhOS7GK5RAS7PT1r9Qjlq/cMEY3XESoAdfLsOUp 3iHAfK1ErBfbXh0S2ZKWtM9S9hLeh/DANPIEWjVJgjgo4uqWzqB3cQ5u4rHwCOMwG+A6cLYRuMG b+aYW0EmLIsYJ0qHS6jc+p/RwzuqzKCfneuFwcXykiEl8AsqlAtRoK1ZumIrbwsyuOw4zc4vAZF nE0nvIdIHyZ9VutvZ5Tkq0qfgPwnFhEugUhFK+pFg91uDxkQwTZfeN9hWwnvffaDJKTWN7s2o40 jV8s7pjbKjOufl98iw8CWRm7XqmD3iBubkWgw7m9n2DDQmZxxceAVQ8ESF7zf7jUVLKhLJ24Qf8 1MhAxEJtFhzByjVmPrKuppC9RwuZdUbVf5TccBUmSF0iryEPH3UemBfqQ3uXYGNPoKfdZ6ZEfcY RDsXrsYO4uou/JHDjaU51LYVXdjx8lfq3vzER4ENE1GVLssvdWSyVNDL68QCxNP0m8Xao/oPScg hcWFQdx7sDvku1O1EYi/zlMG+v2uSXkeZc+jb76l31Li3PZi27vhku6CE9G8YkPNQQRtXuHm2Fu +OBEkKPqUdkdwDGw8U8vB9XOgp3hPSgxS88rIykkPOyCO+l8YeuJkYSJE9Dv3/5ohEtzwyU/yv4 TLQwQPwJ6mwzvrQRKoHKR4ryFRp96geXpzzqpeAxlThN93iI= 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-trace-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