extend the bio alignment check to bio based drivers
Subsystems (2)
Hi Jens,
this series extends the bio alignment check in the block layer to cover bio based drivers in addition to the blk-mq based path, and then drops the equivalent debug checks in brd.
Diffstat:
block/blk-core.c | 7 +++++-- block/blk-mq.c | 11 ----------- block/blk.h | 11 +++++++++++ drivers/block/brd.c | 4 ---- 4 files changed, 16 insertions(+), 17 deletions(-)
PATCH 1/2 block: also check bio alignment for bio based drivers
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.
--- block/blk-core.c | 7 +++++-- block/blk-mq.c | 11 ----------- block/blk.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-)
block/blk-core.c +5 -2
@@ -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); }
block/blk-mq.c +0 -11
@@ -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.
block/blk.h +11 -0
@@ -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 ();
Signature · 1 line
2.43.0
Re: [PATCH 1/2] block: also check bio alignment for bio based drivers
Quoted 3 lines · Christoph Hellwig
Extend the checks added in
0676c434a99b("block: check bio alignment inblk_mq_submit_bio") for blk-mq drivers to bio based drivers as all the same reasons apply for them as well.
Do we have bio based driver which may re-configure logical block size?
If yes, is it enough to do so? Cause queue usage counter is only held during bio submission, and it won't cover the whole bio lifetime.
Thanks,
Ming
Re: [PATCH 1/2] block: also check bio alignment for bio based drivers
Quoted 6 lines · Ming Lei
Quoted 3 lines · Christoph Hellwig
Extend the checks added in
0676c434a99b("block: check bio alignment inblk_mq_submit_bio") for blk-mq drivers to bio based drivers as all the same reasons apply for them as well.Do we have bio based driver which may re-configure logical block size?
nvme multipath can, and it looks drbd might be able to do so as well.
Quoted 2 lines
If yes, is it enough to do so? Cause queue usage counter is only held during bio submission, and it won't cover the whole bio lifetime.
Yes. But for me the prime intend here is not to prevent that, but to ensure we actually have the damn sanity check for all drivers instead of just a few and instead a gazillion more or less equivalent open coded versions.
That doesn't mean we shouldn't look into actually holding q_usage_count over the entire bio lifetime for bio based drivers, but that's a separate project.
Re: [PATCH 1/2] block: also check bio alignment for bio based drivers
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Ming Lei
Quoted 3 lines · Christoph Hellwig
Extend the checks added in
0676c434a99b("block: check bio alignment inblk_mq_submit_bio") for blk-mq drivers to bio based drivers as all the same reasons apply for them as well.Do we have bio based driver which may re-configure logical block size?
nvme multipath can, and it looks drbd might be able to do so as well.
nvme multipath should be fine since the check is done for the underlying nvme device.
drbd doesn't call freeze queue, so it shouldn't have done that.
Quoted 4 lines
Quoted 3 lines
If yes, is it enough to do so? Cause queue usage counter is only held during bio submission, and it won't cover the whole bio lifetime.
Quoted 8 lines
Yes. But for me the prime intend here is not to prevent that, but to ensure we actually have the damn sanity check for all drivers instead of just a few and instead a gazillion more or less equivalent open coded versions.
That doesn't mean we shouldn't look into actually holding
q_usage_countover the entire bio lifetime for bio based drivers, but that's a separate project.
What if logical block size is changed between bio submission and completion?
For blk-mq device, we need to drain any IO when re-configuring device, however it can't be supported generically for bio based driver.
Thanks,
Ming
Re: [PATCH 1/2] block: also check bio alignment for bio based drivers
Quoted 9 lines · Ming Lei
Quoted 3 lines
That doesn't mean we shouldn't look into actually holding
q_usage_countover the entire bio lifetime for bio based drivers, but that's a separate project.What if logical block size is changed between bio submission and completion?
For blk-mq device, we need to drain any IO when re-configuring device, however it can't be supported generically for bio based driver.
Many bio based drivers do the same, just reimplemented without block helpers (e.g. md/dm).
But as I said the point is that I really want the sanity check to always be there. I'd also like to eventually make freeze work for bio based drivers, but that is a separate issue.
Re: [PATCH 1/2] block: also check bio alignment for bio based drivers
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
Extend the checks added in
0676c434a99b("block: check bio alignment inblk_mq_submit_bio") for blk-mq drivers to bio based drivers as all the same reasons apply for them as well.
So do we now still need blkdev_dio_invalid() -> bdev_logical_block_size() pos checks for simple and async paths in fops?
They are not doing harm and messy to remove, I suppose (if strictly not required).
Quoted 69 lines
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-core.c | 7 +++++-- block/blk-mq.c | 11 ----------- block/blk.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-)block/blk-core.c +5
-2@@ -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); }block/blk-mq.c +0
-11@@ -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. block/blk.h +10
-0@@ -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 ();
Re: [PATCH 1/2] block: also check bio alignment for bio based drivers
Quoted 10 lines · John Garry
Quoted 3 lines · Christoph Hellwig
Extend the checks added in
0676c434a99b("block: check bio alignment inblk_mq_submit_bio") for blk-mq drivers to bio based drivers as all the same reasons apply for them as well.So do we now still need
blkdev_dio_invalid()->bdev_logical_block_size()pos checks for simple and async paths in fops?They are not doing harm and messy to remove, I suppose (if strictly not required).
Going all the way down into the block layer vs just doing the trivial check ahead of time does not sound like a winning proposition..
PATCH 2/2 brd: remove sector alignment checks
In reply to Christoph HellwigThe block layer now takes care of these.
--- drivers/block/brd.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/block/brd.c +0 -4
@@ -256,10 +256,6 @@ static void brd_submit_bio(struct bio *bio)unsigned int len = bvec.bv_len;int err; -/* Don't support un-aligned buffer */ -WARN_ON_ONCE ((bvec.bv_offset & (SECTOR_SIZE -1 )) || - (len & (SECTOR_SIZE -1 ))); - err =brd_do_bvec (brd, bvec.bv_page, len, bvec.bv_offset, bio->bi_opf, sector);if (err) {
Signature · 1 line
2.43.0