From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795902332; b=YdgjGbAEXCaDqJoTn0DMjIuNd0MYin7FGg4anbN9A9wFCbPRBT7BE9OnoZYfG34G5Kzr cq+UQMNV1ISAjnhCYaZQ1zQuWnXfXYOR0sO3nmXhENkDfzB5FaslMcVOzgaIzeNtlbtJr 3k877dKcZh2ReW4WoYbY1SUcpy2D3KAvTTqM5vT3t9B2f0M6ClVjjoXWxaeAwkPkL2KDu TDGZ1PmXXvcyhRwHOSxZTZtwS0L14a9k9JBIjOcDa62NEBHJr/k0LD6zaHybvKwkk4q3l ftTzNPnRNbh9puOXdWeGAu3pLMnxfXIzRohNlNw/5LUKGaPwk1PidBhhjDdJMf0rKqg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795902332; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=MKjMEkp3bzJxBfSW2lzDrLJqu5+u4VeX/3GQx/tZvho=; b=HYt93orZQAn5sRsvU1Yu5gxTX8nKPYMTqnjO9advgXlkVfiZ9n0UsbIUeGa7uUfOMGoF b2gsrXfttYcOcEA1pR8YRnXL1gFhq8ubTsPArG5h4Svx175ETcTPe368sBZauyxog5RFz /8A0vsNdKZLb97kn1iKbuS2+MdiJ3h2mYKr3EutO5JQTCcnXLoyBvsjQEtYLU5xsY56Ev M08RvOZVoZ6jywPkd3MSU3cfNZ0nta5toty6GZCssGLXM20d5GyyAj2RNEbHsFVls+K4g FMNvMa9JOKe1NlTaXy2CrFCdRUziKK+qC5boBiYgZ0W1k4WVqR1cBOp31G9zJIg3nEQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jNN2osAZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEDBE606A31C; Sat, 28 Nov 2026 21:45:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jNN2osAZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F02B1F000C1; Sat, 28 Nov 2026 21:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795902331; bh=MKjMEkp3bzJxBfSW2lzDrLJqu5+u4VeX/3GQx/tZvho=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jNN2osAZD7ofhOvJNf14E3bGYoWJbr9+zk7mdXNLKYUljGx65VZdKZz4V+Sk1Uo3H HRXx+H+JOYK9b6uzAgl57hTToNP6br9Q11kfmkgl0fU8OleUr2H11ScMCEh+SimaGF PaIyc3GrMFjr6jjYwKBOybIOm/SScp61rtHJXPSfLcTObR8dHVDZNDxduKMdYyhCRX ZgnVwNAmPZQThvj1afK14bEdXWjNFo0xoXnw89NkFzlP3Q1obdItXHk30aV3Zcjrj4 jRR2kuyQRGjxoGNgYWJ+FvNzvcJ4a7z1jrWaVnktzo5WStuaLMufhsCKDSA+IA/nP9 qSzDFHTO7aGLQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ext4: force a full commit when quota data is modified Reply-To: sashiko-reviews@lists.linux.dev To: "Wesley Atwell" Cc: linux-ext4@vger.kernel.org, linux-trace-kernel@vger.kernel.org, tytso@mit.edu In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 28 Nov 2026 21:45:31 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 comm= it_tid) > struct super_block *sb =3D journal->j_private; > struct ext4_sb_info *sbi =3D EXT4_SB(sb); > int nblks =3D 0, ret, bsize =3D journal->j_blocksize; > - int subtid =3D atomic_read(&sbi->s_fc_subtid); > + int subtid, alloc_ctx; > int status =3D EXT4_FC_STATUS_OK, fc_bufs_before =3D 0; > ktime_t start_time, commit_time; > int old_ioprio, journal_ioprio; > + bool ineligible_on_entry; > =20 > 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 commi= t_tid) > start_time =3D ktime_get(); > old_ioprio =3D get_current_ioprio(); > =20 > + /* Keep ineligibility observed before waiting for another fast commit. = */ > + alloc_ctx =3D ext4_fc_lock(sb); > + ineligible_on_entry =3D ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE); > + subtid =3D 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 =3D jbd2_fc_begin_commit(journal, commit_tid); > if (ret =3D=3D -EALREADY) { > @@ -1608,6 +1626,13 @@ int ext4_fc_commit(journal_t *journal, tid_t commi= t_tid) > if (atomic_read(&sbi->s_fc_subtid) <=3D 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 =3D 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= =3D 0 subtid =3D S jbd2_fc_begin_commi= t(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) =3D=3D 0 /* sees FC_INELIGIBLE */ jbd2_fc_end_commit_fallback() ext4_fc_cleanup(0, T) clear(FC_INELIGIBLE) wake_up(j_fc_wait) /* wakes with -EALR= EADY */ s_fc_subtid > S ineligible_on_entry= =3D=3D 0 test(FC_INELIGIBLE)= =3D=3D 0 return 0; <-- T un= committed 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 =3D true (from T) and subtid =3D 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 <=3D 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 =3D=3D true, and calls jbd2_complete_transaction(journa= l, 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 =3D 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); > =20 > #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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/kernel-7f509bcdfe16= 388c-v1.atwellwea@gmail.com?part=3D1