On 11/4/21 5:41 AM, Jens Axboe wrote: >> This is broken, we really ant the submit checks under freeze >> protection to make sure the parameters can't be changed underneath >> us. > > Which parameters are you worried about in submit_bio_checks()? I don't > immediately see anything that would make me worry about it. To player it safer, I would suggest we fold in something like the below. That keeps the submit_checks() under the queue enter. diff --git a/block/blk-core.c b/block/blk-core.c index 2b12a427ffa6..18aab7f8469a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -746,7 +746,7 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_OK; } -static noinline_for_stack bool submit_bio_checks(struct bio *bio) +noinline_for_stack bool submit_bio_checks(struct bio *bio) { struct block_device *bdev = bio->bi_bdev; struct request_queue *q = bdev_get_queue(bdev); @@ -868,14 +868,13 @@ static void __submit_bio(struct bio *bio) { struct gendisk *disk = bio->bi_bdev->bd_disk; - if (!submit_bio_checks(bio) || !blk_crypto_bio_prep(&bio)) - return; if (!disk->fops->submit_bio) { blk_mq_submit_bio(bio); } else { if (unlikely(bio_queue_enter(bio) != 0)) return; - disk->fops->submit_bio(bio); + if (submit_bio_checks(bio) && blk_crypto_bio_prep(&bio)) + disk->fops->submit_bio(bio); blk_queue_exit(disk->queue); } } diff --git a/block/blk-mq.c b/block/blk-mq.c index e92c36f2326a..2dab9bdcc51a 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2526,6 +2526,9 @@ void blk_mq_submit_bio(struct bio *bio) unsigned int nr_segs = 1; blk_status_t ret; + if (unlikely(!blk_crypto_bio_prep(&bio))) + return; + blk_queue_bounce(q, &bio); if (blk_may_split(q, bio)) __blk_queue_split(q, &bio, &nr_segs); @@ -2551,6 +2554,8 @@ void blk_mq_submit_bio(struct bio *bio) if (unlikely(!blk_mq_queue_enter(q, bio))) return; + if (unlikely(!submit_bio_checks(bio))) + goto put_exit; rq_qos_throttle(q, bio); diff --git a/block/blk.h b/block/blk.h index f7371d3b1522..79c98ced59c8 100644 --- a/block/blk.h +++ b/block/blk.h @@ -56,6 +56,7 @@ void blk_freeze_queue(struct request_queue *q); void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic); void blk_queue_start_drain(struct request_queue *q); int bio_queue_enter(struct bio *bio); +bool submit_bio_checks(struct bio *bio); static inline bool blk_try_enter_queue(struct request_queue *q, bool pm) { -- Jens Axboe