From: Arbab Haider <arbabhaider649@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
Jan Kara <jack@suse.cz>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Arbab Haider <arbabhaider649@gmail.com>
Subject: [PATCH] ext4: preserve EXT4_STATE_MAY_INLINE_DATA on failed inline data conversion
Date: Mon, 23 Nov 2026 11:54:49 +0500 [thread overview]
Message-ID: <20261123065448.60742-2-arbabhaider649@gmail.com> (raw)
Commit ef09ed5d37b8 ("ext4: fix bug_on in ext4_writepages") attempted to
prevent ext4_convert_inline_data() from racing with delayed-allocation
inline data conversion by calling filemap_flush() when
EXT4_STATE_MAY_INLINE_DATA is already cleared.
However, filemap_flush() is asynchronous (WB_SYNC_NONE) and can return 0
while folio 0 is locked by a concurrent buffered write and
ext4_has_inline_data(inode) is still true. ext4_convert_inline_data()
then falls through to ext4_convert_inline_data_nolock() with
EXT4_STATE_MAY_INLINE_DATA cleared. If ext4_map_blocks() fails (for
example due to -ENOSPC or a corrupted block bitmap), the out_restore
path calls ext4_restore_inline_data(), which unconditionally re-sets
EXT4_STATE_MAY_INLINE_DATA (both inside ext4_create_inline_data() and
directly).
When ext4_do_writepages() subsequently runs (e.g. via O_SYNC
ext4_sync_file()), it finds both ext4_has_inline_data(inode) and
EXT4_STATE_MAY_INLINE_DATA set and triggers:
kernel BUG at fs/ext4/inode.c:2949!
RIP: 0010:ext4_do_writepages+0x25c0/0x39a0
Call Trace:
ext4_writepages+0x285/0x500
do_writepages+0x205/0x520
filemap_writeback+0x1a6/0x250
file_write_and_wait_range+0x8c/0x150
ext4_sync_file+0x2cf/0x950
ext4_buffered_write_iter+0x428/0x5d0
ext4_file_write_iter+0x7cb/0x1450
Fix this in ext4_convert_inline_data_nolock() (called under xattr_sem,
which serializes against ext4_da_convert_inline_data_to_extent()) by
saving EXT4_STATE_MAY_INLINE_DATA before destroying inline data and
clearing it again after ext4_restore_inline_data() if it was not set
originally.
Tested locally in QEMU (x86_64, 4 CPUs, KASAN+UBSAN) using a concurrent
mmap + O_SYNC write reproducer on an inline_data ext4 image: hit
kernel BUG at fs/ext4/inode.c:2949 on mount #1 in <1s before the patch,
and completed 32 fresh mount/race iterations in 10s with zero BUG,
WARNING, or KASAN reports after the patch.
Fixes: ef09ed5d37b8 ("ext4: fix bug_on in ext4_writepages")
Cc: stable@vger.kernel.org
Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
---
fs/ext4/inline.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index ceee69a66..c4ef91cd3 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1105,6 +1105,8 @@ static int ext4_convert_inline_data_nolock(handle_t *handle,
struct buffer_head *data_bh = NULL;
struct ext4_map_blocks map;
int inline_size;
+ bool may_inline = ext4_test_inode_state(inode,
+ EXT4_STATE_MAY_INLINE_DATA);
inline_size = ext4_get_inline_size(inode);
buf = kmalloc(inline_size, GFP_NOFS);
@@ -1181,8 +1183,12 @@ static int ext4_convert_inline_data_nolock(handle_t *handle,
}
out_restore:
- if (error)
+ if (error) {
ext4_restore_inline_data(handle, inode, iloc, buf, inline_size);
+ if (!may_inline)
+ ext4_clear_inode_state(inode,
+ EXT4_STATE_MAY_INLINE_DATA);
+ }
out:
brelse(data_bh);
--
2.53.0
next reply other threads:[~2026-11-23 6:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 6:54 Arbab Haider [this message]
2026-11-23 7:10 ` [PATCH] ext4: preserve EXT4_STATE_MAY_INLINE_DATA on failed inline data conversion sashiko-bot
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=20261123065448.60742-2-arbabhaider649@gmail.com \
--to=arbabhaider649@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--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.