[PATCH 04/25] ext4: make ext4_punch_hole() support large block size

From: libaokun
Date: Fri Oct 24 2025 - 23:30:54 EST


From: Baokun Li <libaokun1@xxxxxxxxxx>

Since the block size may be greater than the page size, when a hole
extends beyond i_size, we need to align the hole's end upwards to the
larger of PAGE_SIZE and blocksize.

This is to prevent the issues seen in commit 2be4751b21ae ("ext4: fix
2nd xfstests 127 punch hole failure") from reappearing after BS > PS
is supported.

Signed-off-by: Baokun Li <libaokun1@xxxxxxxxxx>
Reviewed-by: Zhang Yi <yi.zhang@xxxxxxxxxx>
---
fs/ext4/inode.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 4c04af7e51c9..a63513a3db53 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4401,7 +4401,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
* the page that contains i_size.
*/
if (end > inode->i_size)
- end = round_up(inode->i_size, PAGE_SIZE);
+ end = round_up(inode->i_size,
+ umax(PAGE_SIZE, sb->s_blocksize));
if (end > max_end)
end = max_end;
length = end - offset;
--
2.46.1