]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: Make sure BH_New bit is cleared in ->write_end handler
authorJan Kara <jack@suse.cz>
Wed, 9 Jul 2025 08:48:32 +0000 (10:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:13:55 +0000 (12:13 +0200)
[ Upstream commit 91b8ca8b26729b729dda8a4eddb9aceaea706f37 ]

Currently we clear BH_New bit in case of error and also in the standard
ext4_write_end() handler (in block_commit_write()). However
ext4_journalled_write_end() misses this clearing and thus we are leaving
stale BH_New bits behind. Generally ext4_block_write_begin() clears
these bits before any harm can be done but in case blocksize < pagesize
and we hit some error when processing a page with these stale bits,
we'll try to zero buffers with these stale BH_New bits and jbd2 will
complain (as buffers were not prepared for writing in this transaction).
Fix the problem by clearing BH_New bits in ext4_journalled_write_end()
and WARN if ext4_block_write_begin() sees stale BH_New bits.

Reported-by: Baolin Liu <liubaolin12138@163.com>
Reported-by: Zhi Long <longzhi@sangfor.com.cn>
Fixes: 3910b513fcdf ("ext4: persist the new uptodate buffers in ext4_journalled_zero_new_buffers")
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20250709084831.23876-2-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/inline.c
fs/ext4/inode.c

index 05b148d6fc711442fd0b1b8e48ebd89470e21534..e02a3141637a0b1a869944c1c590b47fb16a1a81 100644 (file)
@@ -606,6 +606,7 @@ retry:
        } else
                ret = ext4_block_write_begin(handle, folio, from, to,
                                             ext4_get_block);
+       clear_buffer_new(folio_buffers(folio));
 
        if (!ret && ext4_should_journal_data(inode)) {
                ret = ext4_walk_page_buffers(handle, inode,
@@ -867,6 +868,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
                return ret;
        }
 
+       clear_buffer_new(folio_buffers(folio));
        folio_mark_dirty(folio);
        folio_mark_uptodate(folio);
        ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
index eb092133c6b882f2939a1980f4e8ad80ad4ebd1a..232131804bb810f92f65be71836af5484157e1d7 100644 (file)
@@ -1056,7 +1056,7 @@ int ext4_block_write_begin(handle_t *handle, struct folio *folio,
                        }
                        continue;
                }
-               if (buffer_new(bh))
+               if (WARN_ON_ONCE(buffer_new(bh)))
                        clear_buffer_new(bh);
                if (!buffer_mapped(bh)) {
                        WARN_ON(bh->b_size != blocksize);
@@ -1272,6 +1272,7 @@ static int write_end_fn(handle_t *handle, struct inode *inode,
        ret = ext4_dirty_journalled_data(handle, bh);
        clear_buffer_meta(bh);
        clear_buffer_prio(bh);
+       clear_buffer_new(bh);
        return ret;
 }