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: handle large folios in __block_write_begin_int()

When __block_write_begin_int() was converted to support folios, we did not
expect large folios to be passed to it. With the current work to support
large block size storage devices, this will no longer be true so change
the checks on 'from' and 'to' to be related to the size of the folio
instead of PAGE_SIZE. Also remove an assumption that the block size is
smaller than PAGE_SIZE.

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

authored by

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

+7 -10
+7 -10
fs/buffer.c
··· 2075 2075 int __block_write_begin_int(struct folio *folio, loff_t pos, unsigned len, 2076 2076 get_block_t *get_block, const struct iomap *iomap) 2077 2077 { 2078 - unsigned from = pos & (PAGE_SIZE - 1); 2079 - unsigned to = from + len; 2078 + size_t from = offset_in_folio(folio, pos); 2079 + size_t to = from + len; 2080 2080 struct inode *inode = folio->mapping->host; 2081 - unsigned block_start, block_end; 2081 + size_t block_start, block_end; 2082 2082 sector_t block; 2083 2083 int err = 0; 2084 - unsigned blocksize, bbits; 2084 + size_t blocksize; 2085 2085 struct buffer_head *bh, *head, *wait[2], **wait_bh=wait; 2086 2086 2087 2087 BUG_ON(!folio_test_locked(folio)); 2088 - BUG_ON(from > PAGE_SIZE); 2089 - BUG_ON(to > PAGE_SIZE); 2088 + BUG_ON(to > folio_size(folio)); 2090 2089 BUG_ON(from > to); 2091 2090 2092 2091 head = folio_create_buffers(folio, inode, 0); 2093 2092 blocksize = head->b_size; 2094 - bbits = block_size_bits(blocksize); 2093 + block = div_u64(folio_pos(folio), blocksize); 2095 2094 2096 - block = (sector_t)folio->index << (PAGE_SHIFT - bbits); 2097 - 2098 - for(bh = head, block_start = 0; bh != head || !block_start; 2095 + for (bh = head, block_start = 0; bh != head || !block_start; 2099 2096 block++, block_start=block_end, bh = bh->b_this_page) { 2100 2097 block_end = block_start + blocksize; 2101 2098 if (block_end <= from || block_start >= to) {