From: Baokun Li <libaokun1@huawei.com>
To: 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>, <jack@suse.cz>,
<wanghaichi0403@gmail.com>, <yi.zhang@huawei.com>,
<yukuai3@huawei.com>, <yangerkun@huawei.com>
Subject: Re: [PATCH v2 2/4] ext4: fix incorrect punch max_end
Date: Tue, 6 May 2025 15:39:27 +0800 [thread overview]
Message-ID: <a40b2f88-8590-485b-9542-3a7b120a1b17@huawei.com> (raw)
In-Reply-To: <20250506012009.3896990-2-yi.zhang@huaweicloud.com>
On 2025/5/6 9:20, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> For the extents based inodes, the maxbytes should be sb->s_maxbytes
> instead of sbi->s_bitmap_maxbytes. Additionally, for the calculation of
> max_end, the -sb->s_blocksize operation is necessary only for
> indirect-block based inodes. Correct the maxbytes and max_end value to
> correct the behavior of punch hole.
>
> Fixes: 2da376228a24 ("ext4: limit length to bitmap_maxbytes - blocksize in punch_hole")
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Looks good to me.
Reviewed-by: Baokun Li <libaokun1@huawei.com>
> ---
> fs/ext4/inode.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 4ec4a80b6879..5691966a19e1 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4006,7 +4006,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
> struct inode *inode = file_inode(file);
> struct super_block *sb = inode->i_sb;
> ext4_lblk_t start_lblk, end_lblk;
> - loff_t max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize;
> + loff_t max_end = sb->s_maxbytes;
> loff_t end = offset + length;
> handle_t *handle;
> unsigned int credits;
> @@ -4015,14 +4015,20 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
> trace_ext4_punch_hole(inode, offset, length, 0);
> WARN_ON_ONCE(!inode_is_locked(inode));
>
> + /*
> + * For indirect-block based inodes, make sure that the hole within
> + * one block before last range.
> + */
> + if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
> + max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize;
> +
> /* No need to punch hole beyond i_size */
> if (offset >= inode->i_size || offset >= max_end)
> return 0;
>
> /*
> * If the hole extends beyond i_size, set the hole to end after
> - * the page that contains i_size, and also make sure that the hole
> - * within one block before last range.
> + * the page that contains i_size.
> */
> if (end > inode->i_size)
> end = round_up(inode->i_size, PAGE_SIZE);
next prev parent reply other threads:[~2025-05-06 7:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 1:20 [PATCH v2 1/4] ext4: fix out of bounds punch offset Zhang Yi
2025-05-06 1:20 ` [PATCH v2 2/4] ext4: fix incorrect punch max_end Zhang Yi
2025-05-06 7:39 ` Baokun Li [this message]
2025-05-06 11:30 ` Jan Kara
2025-05-06 1:20 ` [PATCH v2 3/4] ext4: factor out ext4_get_maxbytes() Zhang Yi
2025-05-06 7:40 ` Baokun Li
2025-05-06 1:20 ` [PATCH v2 4/4] ext4: ensure i_size is smaller than maxbytes Zhang Yi
2025-05-06 7:42 ` Baokun Li
2025-05-06 7:37 ` [PATCH v2 1/4] ext4: fix out of bounds punch offset Baokun Li
2025-05-20 14:40 ` Theodore Ts'o
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=a40b2f88-8590-485b-9542-3a7b120a1b17@huawei.com \
--to=libaokun1@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=wanghaichi0403@gmail.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yi.zhang@huaweicloud.com \
--cc=yukuai3@huawei.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
all inboxes | Powered by JetHome®