Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Zhang Yi <yizhang089@gmail.com>
To: Jan Kara <jack@suse.cz>, Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, libaokun@linux.alibaba.com,
	ojaswin@linux.ibm.com, ritesh.list@gmail.com,
	yi.zhang@huawei.com, chengzhihao1@huawei.com,
	yangerkun@huawei.com, yukuai@fnnas.com
Subject: Re: [PATCH v3 2/9] ext4: skip tail block zeroing for inline data files
Date: Mon, 13 Jul 2026 14:37:17 +0800	[thread overview]
Message-ID: <efe86dda-96c2-47a4-b9b8-a30584633196@gmail.com> (raw)
In-Reply-To: <j5jbhizj5ldw3h5tnplfs23zblhqa7di5occ4zbmd6dsqq5hwl@uznnurl5zljt>



On 7/9/2026 9:25 PM, Jan Kara wrote:
> On Wed 08-07-26 14:20:42, Zhang Yi wrote:
>> From: Zhang Yi <yi.zhang@huawei.com>
>>
>> ext4_block_zero_eof() is called from ext4_write_checks() on every
>> append write beyond EOF. For inline data files, ext4_get_block()
>> returns -ERANGE when ext4_load_tail_bh() looks up the tail block.
>> However, this error is currently ignored because the return value
>> of ext4_get_block() in ext4_load_tail_bh() is discarded.
>>
>> Before we fix ext4_load_tail_bh() to properly propagate the error,
>> skip the zeroing for inline data inodes to avoid unnecessary
>> failures or confusion.
>>
>> Fixes: 3f60efd65412d ("ext4: zero post-EOF partial block before appending write")
>> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> 
> Hum, but this check is racy (inline data can be removed from
> ext4_page_mkwrite() after this check) so we could in theory miss some
> zeroing we should do. I didn't put too deep thought to whether it really
> can do some harm or not but it would at least deserve a comment.
> 
> 								Honza

You're right, the race does exist. Thank you for pointing this out. Let
me analyze the scenario precisely.

ext4_block_zero_eof() is invoked during a file-extending operation (when
buffered write with start_pos > old_size) to zero out the contents of
the old post-EOF block. This zeroing is intended to prevent stale page-
cache or on-disk data from being exposed.

Now consider a race between a file-extending operation and a concurrent
mmap write. In the mmap path, ext4_page_mkwrite() first converts inline
data via ext4_convert_inline_data_nolock(). During that conversion, the
entire block is zeroed with memset() before the inline data is copied
in. As a result, by the time the conversion completes, any stale post-
EOF data that ext4_block_zero_eof() would normally guard against has
already been cleared.

The only remaining concern is a scenario where an mmap write touches the
old post-EOF block after the conversion but before the file is expanded.
However, that would constitute undefined behavior regardless of whether
inline data is involved.

So from a practical standpoint, I do not see a real issue here. I will
add a comment in the next revision to clarify this reasoning.

Thanks,
Yi.

> 
>> ---
>>   fs/ext4/inode.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
>> index 7b2face041ef..a3f7c71b701d 100644
>> --- a/fs/ext4/inode.c
>> +++ b/fs/ext4/inode.c
>> @@ -4218,6 +4218,9 @@ int ext4_block_zero_eof(struct inode *inode, loff_t from, loff_t end)
>>   	offset = from & (blocksize - 1);
>>   	if (!offset || from >= end)
>>   		return 0;
>> +	/* Inline data has no tail block to zero. */
>> +	if (ext4_has_inline_data(inode))
>> +		return 0;
>>   	/* If we are processing an encrypted inode during orphan list handling */
>>   	if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode))
>>   		return 0;
>> -- 
>> 2.52.0
>>


  reply	other threads:[~2026-07-13  6:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  6:20 [PATCH v3 0/9] ext4: fix unaligned edge handling in FALLOC_FL_WRITE_ZEROES Zhang Yi
2026-07-08  6:20 ` [PATCH v3 1/9] ext4: use FGP_WRITEBEGIN for tail block zeroing Zhang Yi
2026-07-09 13:19   ` Jan Kara
2026-07-08  6:20 ` [PATCH v3 2/9] ext4: skip tail block zeroing for inline data files Zhang Yi
2026-07-09 13:25   ` Jan Kara
2026-07-13  6:37     ` Zhang Yi [this message]
2026-07-08  6:20 ` [PATCH v3 3/9] ext4: check return value of ext4_get_block() in ext4_load_tail_bh() Zhang Yi
2026-07-09 13:26   ` Jan Kara
2026-07-08  6:20 ` [PATCH v3 4/9] ext4: move partial block zeroing earlier in ext4_zero_range() Zhang Yi
2026-07-08  6:20 ` [PATCH v3 5/9] ext4: clarify return semantics of ext4_load_tail_bh() Zhang Yi
2026-07-09 13:26   ` Jan Kara
2026-07-08  6:20 ` [PATCH v3 6/9] ext4: track partial-zero outcome per edge in ext4_zero_partial_blocks() Zhang Yi
2026-07-08  6:20 ` [PATCH v3 7/9] ext4: zero out whole block for clean edges in WRITE_ZEROES Zhang Yi
2026-07-09 13:27   ` Jan Kara
2026-07-08  6:20 ` [PATCH v3 8/9] ext4: write back partial-zeroed " Zhang Yi
2026-07-08  6:20 ` [PATCH v3 9/9] ext4: protect WRITE_ZEROES written extents with orphan list Zhang Yi
2026-07-09 13:28   ` 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=efe86dda-96c2-47a4-b9b8-a30584633196@gmail.com \
    --to=yizhang089@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=chengzhihao1@huawei.com \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yi.zhang@huaweicloud.com \
    --cc=yukuai@fnnas.com \
    /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