Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Brauner" <brauner@kernel.org>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH RFC v3 10/14] ext2: drop mmb_sync() from ext2_evict_inode()
Date: Mon, 09 Nov 2026 18:36:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-205427@kernel.org> (raw)
In-Reply-To: <20261109-work-inode-metadata_writeback-v3-10-91ac6c024018@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext2: unsynced metadata buffers in ext2_evict_inode() on
  mmb_sync() race
--

commit 87b835e8b247e4798e3fb46ec519ae23df154b20
Author: Christian Brauner <brauner@kernel.org>

ext2: drop mmb_sync() from ext2_evict_inode()

This commit removes the mmb_sync() call from ext2_evict_inode(), relying on
evict() to write out metadata buffers tracked via I_METADATA_WRITEBACK.

> diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
> index 9261b666d043a..4c38a3a8ea4d7 100644
> --- a/fs/ext2/inode.c
> +++ b/fs/ext2/inode.c
> @@ -91,8 +91,6 @@ void ext2_evict_inode(struct inode * inode)
>  		if (inode->i_blocks)
>  			ext2_truncate_blocks(inode, 0);
>  		ext2_xattr_delete_inode(inode);
> -	} else {
> -		mmb_sync(&EXT2_I(inode)->i_metadata_bhs);
>  	}
>  	mmb_invalidate(&EXT2_I(inode)->i_metadata_bhs);
>  	clear_inode(inode);

[Severity: Medium]
Can ext2_evict_inode() invalidate dirty metadata buffers on i_metadata_bhs
without writing them out if mmb_mark_buffer_dirty() races with mmb_sync()?

In __ext2_truncate_blocks(), ext2_free_branches() modifies
partial->bh->b_data and calls mark_inode_dirty(inode) before calling
mmb_mark_buffer_dirty().  If a concurrent writeback clears I_DIRTY and
I_METADATA_WRITEBACK in __writeback_single_inode() and enters mmb_sync(),
mmb_sync() temporarily sets bh->b_mmb to NULL in __remove_assoc_queue() and
restores bh->b_mmb = mmb if the buffer was dirtied again:

CPU0                                  CPU1
__ext2_truncate_blocks()
  ext2_free_branches()
    mark_inode_dirty(inode)
                                      __writeback_single_inode()
                                        inode_state_clear(...,
                                          I_METADATA_WRITEBACK)
                                        ext2_sync_inode_metadata()
                                          mmb_sync()
                                            spin_lock(&mmb->lock)
                                            __remove_assoc_queue()
                                              bh->b_mmb = NULL
  mmb_mark_buffer_dirty()
    mark_buffer_dirty(bh)
    if (!bh->b_mmb) // true
                                            if (buffer_dirty(bh)) {
                                              list_add(..., &mmb->list)
                                              bh->b_mmb = mmb
                                            }
                                            spin_unlock(&mmb->lock)
      spin_lock(&mmb->lock)
      if (cmpxchg(&bh->b_mmb,
                  NULL, mmb) != NULL) {
        spin_unlock(&mmb->lock)
        return;  <-- skips setting I_METADATA_WRITEBACK
      }

Because mmb_sync() only waits on in-flight I/O in its second loop without
submitting new I/O for the re-dirtied buffer, and mmb_mark_buffer_dirty()
returns early without setting I_METADATA_WRITEBACK, the dirty buffer remains
on i_metadata_bhs with I_METADATA_WRITEBACK clear on the inode.

With mmb_sync() removed from ext2_evict_inode(), evict() skips
sync_inode_metadata() and ext2_evict_inode() detaches the dirty buffer via
mmb_invalidate().  If the inode is later re-read from disk and fsync()ed
before background block device writeback flushes the buffer, fsync() will no
longer see the buffer on i_metadata_bhs and can return before the indirect
block is persisted to disk.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109-work-inode-metadata_writeback-v3-0-91ac6c024018@kernel.org?part=10

  reply	other threads:[~2026-11-09 18:36 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 16:51 [PATCH RFC v3 00/14] fs: reclaim inodes with I_METADATA_WRITEBACK Christian Brauner
2026-11-09 16:51 ` [PATCH RFC v3 01/14] ext2: add ext2_inode_block() helper Christian Brauner
2026-11-09 16:57   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 02/14] ext2: don't read the inode block in ext2_sync_inode_metadata() Christian Brauner
2026-11-09 17:02   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 03/14] ext4: use sb_find_get_block_nonatomic() in ext4_get_inode_loc_noio() Christian Brauner
2026-11-09 17:06   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 04/14] ext4: don't read the inode block in ext4_sync_inode_metadata() Christian Brauner
2026-11-09 17:11   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 05/14] minix: add minix_inode_block() helper Christian Brauner
2026-11-09 17:13   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 06/14] minix: don't read the inode block in minix_sync_inode_metadata() Christian Brauner
2026-11-09 17:16   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 07/14] udf: don't allocate the inode block in udf_sync_inode_metadata() Christian Brauner
2026-11-09 17:24   ` sashiko-bot
2026-11-09 16:51 ` [PATCH RFC v3 08/14] fs: set I_METADATA_WRITEBACK in mmb_mark_buffer_dirty() Christian Brauner
2026-11-09 17:50   ` sashiko-bot
2026-11-10 10:33   ` Jan Kara
2026-11-09 16:51 ` [PATCH RFC v3 09/14] fs: don't strand I_METADATA_WRITEBACK inodes outside the LRU Christian Brauner
2026-11-09 18:18   ` sashiko-bot
2026-11-10 10:28   ` Jan Kara
2026-11-09 16:51 ` [PATCH RFC v3 10/14] ext2: drop mmb_sync() from ext2_evict_inode() Christian Brauner
2026-11-09 18:36   ` sashiko-bot [this message]
2026-11-10 10:28   ` Jan Kara
2026-11-09 16:51 ` [PATCH RFC v3 11/14] ext4: drop mmb_sync() from ext4_evict_inode() Christian Brauner
2026-11-09 18:55   ` sashiko-bot
2026-11-10 10:28   ` Jan Kara
2026-11-09 16:51 ` [PATCH RFC v3 12/14] minix: drop mmb_sync() from minix_evict_inode() Christian Brauner
2026-11-09 18:58   ` sashiko-bot
2026-11-10 10:28   ` Jan Kara
2026-11-09 16:51 ` [PATCH RFC v3 13/14] udf: drop mmb_sync() from udf_evict_inode() Christian Brauner
2026-11-09 19:03   ` sashiko-bot
2026-11-10 10:29   ` Jan Kara
2026-11-09 16:51 ` [PATCH RFC v3 14/14] fat: drop mmb_sync() from fat_evict_inode() Christian Brauner
2026-11-09 19:08   ` sashiko-bot
2026-11-10 10:29   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-205427@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=brauner@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox