From: Hannes Reinecke <hare@xxxxxxxxxx> [ Upstream commit 86c60efd7c0ede43bd677f2eee1d84200528df1e ] For large blocksizes the number of block bits is larger than PAGE_SHIFT, so calculate the sector number from the byte offset instead. This is required to enable large folios with buffer-heads. Reviewed-by: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx> Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx> Signed-off-by: Hannes Reinecke <hare@xxxxxxxxxx> Link: https://lore.kernel.org/r/20250221223823.1680616-4-mcgrof@xxxxxxxxxx Reviewed-by: Hannes Reinecke <hare@xxxxxxx> Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> --- fs/mpage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/mpage.c b/fs/mpage.c index 242e213ee0644..20d95847666b6 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -189,7 +189,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) if (folio_buffers(folio)) goto confused; - block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); + block_in_file = folio_pos(folio) >> blkbits; last_block = block_in_file + args->nr_pages * blocks_per_page; last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits; if (last_block > last_block_in_file) @@ -543,7 +543,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, * The page has no buffers: map it to disk */ BUG_ON(!folio_test_uptodate(folio)); - block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); + block_in_file = folio_pos(folio) >> blkbits; /* * Whole page beyond EOF? Skip allocating blocks to avoid leaking * space. -- 2.39.5