Extend the checks added in 0676c434a99b ("block: check bio alignment in blk_mq_submit_bio") for blk-mq drivers to bio based drivers as all the same reasons apply for them as well. Signed-off-by: Christoph Hellwig <hch@xxxxxx> --- block/blk-core.c | 7 +++++-- block/blk-mq.c | 11 ----------- block/blk.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 71b7622c523a30..ffb55d8843a121 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -615,8 +615,11 @@ static void __submit_bio(struct bio *bio) blk_mq_submit_bio(bio); } else if (likely(bio_queue_enter(bio) == 0)) { struct gendisk *disk = bio->bi_bdev->bd_disk; - - disk->fops->submit_bio(bio); + + if (unlikely(bio_unaligned(bio, disk->queue))) + bio_io_error(bio); + else + disk->fops->submit_bio(bio); blk_queue_exit(disk->queue); } diff --git a/block/blk-mq.c b/block/blk-mq.c index e3c3c0c21b5536..94a102abb88055 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2909,17 +2909,6 @@ static void blk_mq_use_cached_rq(struct request *rq, struct blk_plug *plug, INIT_LIST_HEAD(&rq->queuelist); } -static bool bio_unaligned(const struct bio *bio, struct request_queue *q) -{ - unsigned int bs_mask = queue_logical_block_size(q) - 1; - - /* .bi_sector of any zero sized bio need to be initialized */ - if ((bio->bi_iter.bi_size & bs_mask) || - ((bio->bi_iter.bi_sector << SECTOR_SHIFT) & bs_mask)) - return true; - return false; -} - /** * blk_mq_submit_bio - Create and send a request to block device. * @bio: Bio pointer. diff --git a/block/blk.h b/block/blk.h index 8e8936e97307c6..d099ef1df5f64a 100644 --- a/block/blk.h +++ b/block/blk.h @@ -40,6 +40,17 @@ int __bio_queue_enter(struct request_queue *q, struct bio *bio); void submit_bio_noacct_nocheck(struct bio *bio); void bio_await_chain(struct bio *bio); +static inline bool bio_unaligned(const struct bio *bio, struct request_queue *q) +{ + unsigned int bs_mask = queue_logical_block_size(q) - 1; + + /* .bi_sector of any zero sized bio need to be initialized */ + if ((bio->bi_iter.bi_size & bs_mask) || + ((bio->bi_iter.bi_sector << SECTOR_SHIFT) & bs_mask)) + return true; + return false; +} + static inline bool blk_try_enter_queue(struct request_queue *q, bool pm) { rcu_read_lock(); -- 2.43.0