Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

buffer: fix various functions for block size > PAGE_SIZE

If i_blkbits is larger than PAGE_SHIFT, we shift by a negative number,
which is undefined. It is safe to shift the block left as a block device
must be smaller than MAX_LFS_FILESIZE, which is guaranteed to fit in
loff_t.

Link: https://lkml.kernel.org/r/20231109210608.2252323-6-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
4b04646c 80844194

+5 -5
+5 -5
fs/buffer.c
··· 199 199 int all_mapped = 1; 200 200 static DEFINE_RATELIMIT_STATE(last_warned, HZ, 1); 201 201 202 - index = block >> (PAGE_SHIFT - bd_inode->i_blkbits); 202 + index = ((loff_t)block << bd_inode->i_blkbits) / PAGE_SIZE; 203 203 folio = __filemap_get_folio(bd_mapping, index, FGP_ACCESSED, 0); 204 204 if (IS_ERR(folio)) 205 205 goto out; ··· 1693 1693 struct inode *bd_inode = bdev->bd_inode; 1694 1694 struct address_space *bd_mapping = bd_inode->i_mapping; 1695 1695 struct folio_batch fbatch; 1696 - pgoff_t index = block >> (PAGE_SHIFT - bd_inode->i_blkbits); 1696 + pgoff_t index = ((loff_t)block << bd_inode->i_blkbits) / PAGE_SIZE; 1697 1697 pgoff_t end; 1698 1698 int i, count; 1699 1699 struct buffer_head *bh; 1700 1700 struct buffer_head *head; 1701 1701 1702 - end = (block + len - 1) >> (PAGE_SHIFT - bd_inode->i_blkbits); 1702 + end = ((loff_t)(block + len - 1) << bd_inode->i_blkbits) / PAGE_SIZE; 1703 1703 folio_batch_init(&fbatch); 1704 1704 while (filemap_get_folios(bd_mapping, &index, end, &fbatch)) { 1705 1705 count = folio_batch_count(&fbatch); ··· 2660 2660 return 0; 2661 2661 2662 2662 length = blocksize - length; 2663 - iblock = (sector_t)index << (PAGE_SHIFT - inode->i_blkbits); 2664 - 2663 + iblock = ((loff_t)index * PAGE_SIZE) >> inode->i_blkbits; 2664 + 2665 2665 folio = filemap_grab_folio(mapping, index); 2666 2666 if (IS_ERR(folio)) 2667 2667 return PTR_ERR(folio);