[PATCH -next v5 04/32] ext4: skip ordered I/O wait when zeroing beyond i_disksize block
Zhang Yi <[email protected]>
| Newsgroups | org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-ext4,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: Zhang Yi <[email protected]> ext4_block_zero_eof() zeros the tail of a partial block beyond EOF. After zeroing, it waits for ordered I/O completion to prevent stale data exposure from concurrent post-EOF mmap writes during folio writeback. However, if the zeroed range lies entirely beyond the block containing i_disksize, no stale data can be exposed because the zeroed region is beyond existing on-disk data. The zeroed pages will be written out before i_disksize is later extended past i_size, so the ordered I/O wait is unnecessary. Add a condition to skip it. Suggested-by: Ojaswin Mujoo <[email protected]> Signed-off-by: Zhang Yi <[email protected]> --- fs/ext4/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 76bf0e944ebe..7601fe3618b1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4241,9 +4241,16 @@ int ext4_block_zero_eof(struct inode *inode, loff_t from, loff_t end) * truncating up or performing an append write, because there might be * exposing stale on-disk data which may caused by concurrent post-EOF * mmap write during folio writeback. + * + * Ordered I/O is required only when zeroing the tail of a block that + * overlaps with i_disksize. If the zeroed range falls outside that + * block, the zeroed data lies beyond the existing on-disk data. It + * will be written out before i_disksize is later extended past + * i_size, so no stale data can be exposed. */ if (ext4_should_order_data(inode) && - did_zero && zero_written && !IS_DAX(inode)) { + did_zero && zero_written && !IS_DAX(inode) && + from < round_up(READ_ONCE(EXT4_I(inode)->i_disksize), blocksize)) { handle_t *handle; handle = ext4_journal_start(inode, EXT4_HT_MISC, 1); -- 2.52.0