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.

block: support adding less than len in bio_add_hw_page

bio_add_hw_page currently always fails or succeeds. This is fine for
the existing callers that always add PAGE_SIZE worth given that the
max_segment_size and max_sectors must always allow at least a page
worth of data. But when we want to add it for bigger amounts of data
this means it can also fail when adding the data to a bio, and creating
a fallback for that becomes really annoying in the callers.

Make use of the existing API design that allows to return a smaller
length than the one passed in and add up to max_segment_size worth
of data from a larger input. All the existing callers are fine with
this - not because they handle this return correctly, but because they
never pass more than a page in.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/20231204173419.782378-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
6ef02df1 3f034c37

+4 -1
+4 -1
block/bio.c
··· 966 966 struct page *page, unsigned int len, unsigned int offset, 967 967 unsigned int max_sectors, bool *same_page) 968 968 { 969 + unsigned int max_size = max_sectors << SECTOR_SHIFT; 970 + 969 971 if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED))) 970 972 return 0; 971 973 972 - if (((bio->bi_iter.bi_size + len) >> SECTOR_SHIFT) > max_sectors) 974 + len = min3(len, max_size, queue_max_segment_size(q)); 975 + if (len > max_size - bio->bi_iter.bi_size) 973 976 return 0; 974 977 975 978 if (bio->bi_vcnt > 0) {