From nobody Tue Dec 2 02:05:52 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E4F42309BE; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; cv=none; b=rdIpFoGrBpZSnfne2RGtqaE/7x+9fq5TTcpfe5Od/CiWr4EY1r6h1pLPksSn4wg32QYoukDYxwql1D/9/uh+bohFiSx7krnn6flIDeDGVK8BKqnMys1vEKfKCnWQ9V8M2lFT3uYpar7LYwtBrVbbS+mJ4D3wcPbUfyq7C5XL2hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; c=relaxed/simple; bh=5W3Z0XNee6raDH58/A7nkZPv+mwSM+TuZmYuKDXaQzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u6fHOJFG7yIfA/kzHLE1+QyKxfucQ7Aiq13VMpHESUJ5I6KWNG24zuNRhfBQTEiRN8Z09uCz6PYgtb33X5bx8SYtfx9odasQGn1bOI3KYvgseWV470aunEql1tYGUOk+/XTC1IQjQN8cGS+m767Yhj4sfxbFhofxVfJfmeS6Jiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV283y4kzYQvHP; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id CA9A61A07BD; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S21; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 17/24] ext4: support large block size in ext4_block_write_begin() Date: Fri, 21 Nov 2025 17:06:47 +0800 Message-Id: <20251121090654.631996-18-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S21 X-Coremail-Antispam: 1UD129KBjvJXoWxJryDZFyxGrykZF4rXrWxXrb_yoW8XF4Dpr y5K3s7GrsF9rWj93W7WFn3Xr1xKa4DWF4UCFW3Zry5XFy8trnagr1kt3s5XF4jqayxZFyk XF1FyryxW3W7ArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFwADs9 Content-Type: text/plain; charset="utf-8" From: Baokun Li Use the EXT4_PG_TO_LBLK() macro to convert folio indexes to blocks to avoid negative left shifts after supporting blocksize greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 65a9c04bc691..9259d08d4a59 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1168,8 +1168,7 @@ int ext4_block_write_begin(handle_t *handle, struct f= olio *folio, unsigned block_start, block_end; sector_t block; int err =3D 0; - unsigned blocksize =3D inode->i_sb->s_blocksize; - unsigned bbits; + unsigned int blocksize =3D i_blocksize(inode); struct buffer_head *bh, *head, *wait[2]; int nr_wait =3D 0; int i; @@ -1178,12 +1177,12 @@ int ext4_block_write_begin(handle_t *handle, struct= folio *folio, BUG_ON(!folio_test_locked(folio)); BUG_ON(to > folio_size(folio)); BUG_ON(from > to); + WARN_ON_ONCE(blocksize > folio_size(folio)); =20 head =3D folio_buffers(folio); if (!head) head =3D create_empty_buffers(folio, blocksize, 0); - bbits =3D ilog2(blocksize); - block =3D (sector_t)folio->index << (PAGE_SHIFT - bbits); + block =3D EXT4_PG_TO_LBLK(inode, folio->index); =20 for (bh =3D head, block_start =3D 0; bh !=3D head || !block_start; block++, block_start =3D block_end, bh =3D bh->b_this_page) { --=20 2.46.1