]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/mpage: avoid negative shift for large blocksize
authorHannes Reinecke <hare@kernel.org>
Fri, 21 Feb 2025 22:38:18 +0000 (14:38 -0800)
committerChristian Brauner <brauner@kernel.org>
Mon, 24 Feb 2025 10:44:43 +0000 (11:44 +0100)
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@infradead.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Hannes Reinecke <hare@kernel.org>
Link: https://lore.kernel.org/r/20250221223823.1680616-4-mcgrof@kernel.org
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/mpage.c

index 82aecf37274379bf7cac087e88e471e8b5283feb..a3c82206977f6c2bb6d6fc0393f7306e2b541e97 100644 (file)
@@ -181,7 +181,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)
@@ -527,7 +527,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.