From: sashiko-bot@kernel.org
To: "Arbab Haider" <arbabhaider649@gmail.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v3] ext4: fix inline data conversion races when !EXT4_STATE_MAY_INLINE_DATA
Date: Mon, 23 Nov 2026 17:53:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-229785@kernel.org> (raw)
In-Reply-To: <20261123172856.100887-2-arbabhaider649@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ext4: race with flag clearing and rollback in
ext4_convert_inline_data()
--
commit d8d6562907c89295338f0cf9b804847e8da0f4c9
Author: Arbab Haider <arbabhaider649@gmail.com>
ext4: fix inline data conversion races when !EXT4_STATE_MAY_INLINE_DATA
This commit updates ext4_convert_inline_data() and
ext4_inline_data_truncate() to handle inodes whose inline data has already
entered delayed-allocation conversion (!EXT4_STATE_MAY_INLINE_DATA).
> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
> index ceee69a66482b..a740549611252 100644
> --- a/fs/ext4/inline.c
> +++ b/fs/ext4/inline.c
[ ... ]
> @@ -1977,6 +2001,7 @@ int ext4_convert_inline_data(struct inode *inode)
> handle_t *handle;
> struct ext4_iloc iloc;
>
> +retry:
> if (!ext4_has_inline_data(inode)) {
> ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
> return 0;
> @@ -1984,14 +2009,18 @@ int ext4_convert_inline_data(struct inode *inode)
> /*
> * Inode has inline data but EXT4_STATE_MAY_INLINE_DATA is
> * cleared. This means we are in the middle of moving of
> - * inline data to delay allocated block. Just force writeout
> - * here to finish conversion.
> + * inline data to delay allocated block. Force synchronous
> + * writeout here to finish conversion.
> */
> - error = filemap_flush(inode->i_mapping);
> + error = filemap_write_and_wait(inode->i_mapping);
> if (error)
> return error;
> if (!ext4_has_inline_data(inode))
> return 0;
> + error = ext4_emergency_state(inode->i_sb);
> + if (error)
> + return error;
> + return -EIO;
> }
[Severity: High]
Can a concurrent ext4_convert_inline_data_nolock() rollback via
ext4_restore_inline_data() still trigger the BUG_ON() in
ext4_do_writepages() or cause ext4_convert_inline_data() to return a
spurious -EIO or premature 0?
When ext4_convert_inline_data_nolock() runs (for example from
ext4_page_mkwrite(), which does not hold i_rwsem),
ext4_destroy_inline_data_nolock() clears EXT4_INODE_INLINE_DATA and
EXT4_STATE_MAY_INLINE_DATA and drops i_data_sem before calling
ext4_map_blocks(). If ext4_map_blocks() fails (e.g. -ENOSPC),
ext4_restore_inline_data() restores EXT4_INODE_INLINE_DATA and
EXT4_STATE_MAY_INLINE_DATA:
CPU0 CPU1
ext4_page_mkwrite()
ext4_convert_inline_data()
down_write(&xattr_sem)
ext4_convert_inline_data_nolock()
ext4_destroy_inline_data_nolock()
clear EXT4_INODE_INLINE_DATA
clear EXT4_STATE_MAY_INLINE_DATA
up_write(&i_data_sem)
ext4_map_blocks() -> fails
ext4_da_write_begin()
test EXT4_STATE_MAY_INLINE_DATA -> 0
ext4_da_get_block_prep()
dirty folio 0
ext4_restore_inline_data()
ext4_create_inline_data()
set EXT4_INODE_INLINE_DATA
set EXT4_STATE_MAY_INLINE_DATA
ext4_do_writepages()
BUG_ON(ext4_test_inode_state(inode,
EXT4_STATE_MAY_INLINE_DATA))
In addition, because ext4_convert_inline_data() checks
ext4_has_inline_data(inode) and EXT4_STATE_MAY_INLINE_DATA before taking
xattr_sem, a second caller arriving while EXT4_INODE_INLINE_DATA is cleared
returns 0 before data_bh is initialized or inline data is restored. If it
arrives in the window inside ext4_restore_inline_data() after
ext4_create_inline_data() sets EXT4_INODE_INLINE_DATA but before
EXT4_STATE_MAY_INLINE_DATA is re-set, filemap_write_and_wait() finds no
dirty pages and ext4_convert_inline_data() returns a spurious -EIO.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123172856.100887-2-arbabhaider649@gmail.com?part=1
prev parent reply other threads:[~2026-11-23 17:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:28 [PATCH v3] ext4: fix inline data conversion races when !EXT4_STATE_MAY_INLINE_DATA Arbab Haider
2026-11-23 17:53 ` sashiko-bot [this message]
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-229785@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arbabhaider649@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.