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: add a BIO_MAX_SIZE constant and use it

Currently the only constant for the maximum bio size is BIO_MAX_SECTORS,
which is in units of 512-byte sectors, but a lot of user need a byte
limit.

Add a BIO_MAX_SIZE constant, redefine BIO_MAX_SECTORS in terms of it, and
switch all bio-related uses of UINT_MAX for the maximum size to use the
symbolic names instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
fa0bdd45 7c746eb7

+15 -15
+5 -5
block/bio.c
··· 924 924 { 925 925 if (bio->bi_vcnt >= bio->bi_max_vecs) 926 926 return true; 927 - if (bio->bi_iter.bi_size > UINT_MAX - len) 927 + if (bio->bi_iter.bi_size > BIO_MAX_SIZE - len) 928 928 return true; 929 929 return false; 930 930 } ··· 1030 1030 { 1031 1031 if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED))) 1032 1032 return 0; 1033 - if (bio->bi_iter.bi_size > UINT_MAX - len) 1033 + if (bio->bi_iter.bi_size > BIO_MAX_SIZE - len) 1034 1034 return 0; 1035 1035 1036 1036 if (bio->bi_vcnt > 0) { ··· 1057 1057 { 1058 1058 unsigned long nr = off / PAGE_SIZE; 1059 1059 1060 - WARN_ON_ONCE(len > UINT_MAX); 1060 + WARN_ON_ONCE(len > BIO_MAX_SIZE); 1061 1061 __bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE); 1062 1062 } 1063 1063 EXPORT_SYMBOL_GPL(bio_add_folio_nofail); ··· 1081 1081 { 1082 1082 unsigned long nr = off / PAGE_SIZE; 1083 1083 1084 - if (len > UINT_MAX) 1084 + if (len > BIO_MAX_SIZE) 1085 1085 return false; 1086 1086 return bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE) > 0; 1087 1087 } ··· 1238 1238 extraction_flags |= ITER_ALLOW_P2PDMA; 1239 1239 1240 1240 size = iov_iter_extract_pages(iter, &pages, 1241 - UINT_MAX - bio->bi_iter.bi_size, 1241 + BIO_MAX_SIZE - bio->bi_iter.bi_size, 1242 1242 nr_pages, extraction_flags, &offset); 1243 1243 if (unlikely(size <= 0)) 1244 1244 return size ? size : -EFAULT;
+4 -5
block/blk-lib.c
··· 32 32 * Align the bio size to the discard granularity to make splitting the bio 33 33 * at discard granularity boundaries easier in the driver if needed. 34 34 */ 35 - return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT; 35 + return round_down(BIO_MAX_SIZE, discard_granularity) >> SECTOR_SHIFT; 36 36 } 37 37 38 38 struct bio *blk_alloc_discard_bio(struct block_device *bdev, ··· 107 107 { 108 108 sector_t bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; 109 109 110 - return min(bdev_write_zeroes_sectors(bdev), 111 - (UINT_MAX >> SECTOR_SHIFT) & ~bs_mask); 110 + return min(bdev_write_zeroes_sectors(bdev), BIO_MAX_SECTORS & ~bs_mask); 112 111 } 113 112 114 113 /* ··· 336 337 int ret = 0; 337 338 338 339 /* make sure that "len << SECTOR_SHIFT" doesn't overflow */ 339 - if (max_sectors > UINT_MAX >> SECTOR_SHIFT) 340 - max_sectors = UINT_MAX >> SECTOR_SHIFT; 340 + if (max_sectors > BIO_MAX_SECTORS) 341 + max_sectors = BIO_MAX_SECTORS; 341 342 max_sectors &= ~bs_mask; 342 343 343 344 if (max_sectors == 0)
+4 -4
block/blk-merge.c
··· 95 95 } 96 96 97 97 /* 98 - * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size 99 - * is defined as 'unsigned int', meantime it has to be aligned to with the 98 + * The maximum size that a bio can fit has to be aligned down to the 100 99 * logical block size, which is the minimum accepted unit by hardware. 101 100 */ 102 101 static unsigned int bio_allowed_max_sectors(const struct queue_limits *lim) 103 102 { 104 - return round_down(UINT_MAX, lim->logical_block_size) >> SECTOR_SHIFT; 103 + return round_down(BIO_MAX_SIZE, lim->logical_block_size) >> 104 + SECTOR_SHIFT; 105 105 } 106 106 107 107 /* ··· 502 502 503 503 rq_for_each_bvec(bv, rq, iter) 504 504 bvec_split_segs(&rq->q->limits, &bv, &nr_phys_segs, &bytes, 505 - UINT_MAX, UINT_MAX); 505 + UINT_MAX, BIO_MAX_SIZE); 506 506 return nr_phys_segs; 507 507 } 508 508
+2 -1
include/linux/blk_types.h
··· 281 281 }; 282 282 283 283 #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs) 284 - #define BIO_MAX_SECTORS (UINT_MAX >> SECTOR_SHIFT) 284 + #define BIO_MAX_SIZE UINT_MAX /* max value of bi_iter.bi_size */ 285 + #define BIO_MAX_SECTORS (BIO_MAX_SIZE >> SECTOR_SHIFT) 285 286 286 287 static inline struct bio_vec *bio_inline_vecs(struct bio *bio) 287 288 {