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: check for valid bio while splitting

We're already iterating every segment, so check these for a valid IO
lengths at the same time. Individual segment lengths will not be checked
on passthrough commands. The read/write command segments must be sized
to the dma alignment.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Keith Busch and committed by
Jens Axboe
fec2e705 d7b1cdc9

+27 -7
+1 -1
block/blk-map.c
··· 443 443 int ret; 444 444 445 445 /* check that the data layout matches the hardware restrictions */ 446 - ret = bio_split_rw_at(bio, lim, &nr_segs, max_bytes); 446 + ret = bio_split_io_at(bio, lim, &nr_segs, max_bytes, 0); 447 447 if (ret) { 448 448 /* if we would have to split the bio, copy instead */ 449 449 if (ret > 0)
+17 -4
block/blk-merge.c
··· 279 279 } 280 280 281 281 /** 282 - * bio_split_rw_at - check if and where to split a read/write bio 282 + * bio_split_io_at - check if and where to split a bio 283 283 * @bio: [in] bio to be split 284 284 * @lim: [in] queue limits to split based on 285 285 * @segs: [out] number of segments in the bio with the first half of the sectors 286 286 * @max_bytes: [in] maximum number of bytes per bio 287 + * @len_align_mask: [in] length alignment mask for each vector 287 288 * 288 289 * Find out if @bio needs to be split to fit the queue limits in @lim and a 289 290 * maximum size of @max_bytes. Returns a negative error number if @bio can't be 290 291 * split, 0 if the bio doesn't have to be split, or a positive sector offset if 291 292 * @bio needs to be split. 292 293 */ 293 - int bio_split_rw_at(struct bio *bio, const struct queue_limits *lim, 294 - unsigned *segs, unsigned max_bytes) 294 + int bio_split_io_at(struct bio *bio, const struct queue_limits *lim, 295 + unsigned *segs, unsigned max_bytes, unsigned len_align_mask) 295 296 { 296 297 struct bio_vec bv, bvprv, *bvprvp = NULL; 297 298 struct bvec_iter iter; 298 299 unsigned nsegs = 0, bytes = 0; 299 300 300 301 bio_for_each_bvec(bv, bio, iter) { 302 + if (bv.bv_offset & lim->dma_alignment || 303 + bv.bv_len & len_align_mask) 304 + return -EINVAL; 305 + 301 306 /* 302 307 * If the queue doesn't support SG gaps and adding this 303 308 * offset would create a gap, disallow it. ··· 344 339 * Individual bvecs might not be logical block aligned. Round down the 345 340 * split size so that each bio is properly block size aligned, even if 346 341 * we do not use the full hardware limits. 342 + * 343 + * It is possible to submit a bio that can't be split into a valid io: 344 + * there may either be too many discontiguous vectors for the max 345 + * segments limit, or contain virtual boundary gaps without having a 346 + * valid block sized split. A zero byte result means one of those 347 + * conditions occured. 347 348 */ 348 349 bytes = ALIGN_DOWN(bytes, bio_split_alignment(bio, lim)); 350 + if (!bytes) 351 + return -EINVAL; 349 352 350 353 /* 351 354 * Bio splitting may cause subtle trouble such as hang when doing sync ··· 363 350 bio_clear_polled(bio); 364 351 return bytes >> SECTOR_SHIFT; 365 352 } 366 - EXPORT_SYMBOL_GPL(bio_split_rw_at); 353 + EXPORT_SYMBOL_GPL(bio_split_io_at); 367 354 368 355 struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, 369 356 unsigned *nr_segs)
+2 -2
include/linux/bio.h
··· 322 322 void bio_trim(struct bio *bio, sector_t offset, sector_t size); 323 323 extern struct bio *bio_split(struct bio *bio, int sectors, 324 324 gfp_t gfp, struct bio_set *bs); 325 - int bio_split_rw_at(struct bio *bio, const struct queue_limits *lim, 326 - unsigned *segs, unsigned max_bytes); 325 + int bio_split_io_at(struct bio *bio, const struct queue_limits *lim, 326 + unsigned *segs, unsigned max_bytes, unsigned len_align); 327 327 328 328 /** 329 329 * bio_next_split - get next @sectors from a bio, splitting if necessary
+7
include/linux/blkdev.h
··· 1870 1870 return queue_atomic_write_unit_max_bytes(bdev_get_queue(bdev)); 1871 1871 } 1872 1872 1873 + static inline int bio_split_rw_at(struct bio *bio, 1874 + const struct queue_limits *lim, 1875 + unsigned *segs, unsigned max_bytes) 1876 + { 1877 + return bio_split_io_at(bio, lim, segs, max_bytes, lim->dma_alignment); 1878 + } 1879 + 1873 1880 #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } 1874 1881 1875 1882 #endif /* _LINUX_BLKDEV_H */