Skip to content

Commit cc9c884

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: call submit_bio_checks under q_usage_counter
Ensure all bios check the current values of the queue under freeze protection, i.e. to make sure the zero capacity set by del_gendisk is actually seen before dispatching to the driver. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Yi Zhang <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent baa0ab2 commit cc9c884

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

block/blk-core.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,18 @@ static blk_qc_t __submit_bio(struct bio *bio)
899899
struct gendisk *disk = bio->bi_bdev->bd_disk;
900900
blk_qc_t ret = BLK_QC_T_NONE;
901901

902-
if (blk_crypto_bio_prep(&bio)) {
903-
if (!disk->fops->submit_bio)
904-
return blk_mq_submit_bio(bio);
902+
if (unlikely(bio_queue_enter(bio) != 0))
903+
return BLK_QC_T_NONE;
904+
905+
if (!submit_bio_checks(bio) || !blk_crypto_bio_prep(&bio))
906+
goto queue_exit;
907+
if (disk->fops->submit_bio) {
905908
ret = disk->fops->submit_bio(bio);
909+
goto queue_exit;
906910
}
911+
return blk_mq_submit_bio(bio);
912+
913+
queue_exit:
907914
blk_queue_exit(disk->queue);
908915
return ret;
909916
}
@@ -941,9 +948,6 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio)
941948
struct request_queue *q = bio->bi_bdev->bd_disk->queue;
942949
struct bio_list lower, same;
943950

944-
if (unlikely(bio_queue_enter(bio) != 0))
945-
continue;
946-
947951
/*
948952
* Create a fresh bio_list for all subordinate requests.
949953
*/
@@ -979,23 +983,12 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio)
979983
static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)
980984
{
981985
struct bio_list bio_list[2] = { };
982-
blk_qc_t ret = BLK_QC_T_NONE;
986+
blk_qc_t ret;
983987

984988
current->bio_list = bio_list;
985989

986990
do {
987-
struct gendisk *disk = bio->bi_bdev->bd_disk;
988-
989-
if (unlikely(bio_queue_enter(bio) != 0))
990-
continue;
991-
992-
if (!blk_crypto_bio_prep(&bio)) {
993-
blk_queue_exit(disk->queue);
994-
ret = BLK_QC_T_NONE;
995-
continue;
996-
}
997-
998-
ret = blk_mq_submit_bio(bio);
991+
ret = __submit_bio(bio);
999992
} while ((bio = bio_list_pop(&bio_list[0])));
1000993

1001994
current->bio_list = NULL;
@@ -1013,9 +1006,6 @@ static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)
10131006
*/
10141007
blk_qc_t submit_bio_noacct(struct bio *bio)
10151008
{
1016-
if (!submit_bio_checks(bio))
1017-
return BLK_QC_T_NONE;
1018-
10191009
/*
10201010
* We only want one ->submit_bio to be active at a time, else stack
10211011
* usage with stacked devices could be a problem. Use current->bio_list

0 commit comments

Comments
 (0)