Skip to content

Commit 958148a

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: check BLK_FEAT_POLL under q_usage_count
Otherwise feature reconfiguration can race with I/O submission. Also drop the bio_clear_polled in the error path, as the flag does not matter for instant error completions, it is a left over from when we allowed polled I/O to proceed unpolled in this case. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Nilay Shroff <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent aa427d7 commit 958148a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

block/blk-core.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,14 @@ static void __submit_bio(struct bio *bio)
629629
blk_mq_submit_bio(bio);
630630
} else if (likely(bio_queue_enter(bio) == 0)) {
631631
struct gendisk *disk = bio->bi_bdev->bd_disk;
632-
633-
disk->fops->submit_bio(bio);
632+
633+
if ((bio->bi_opf & REQ_POLLED) &&
634+
!(disk->queue->limits.features & BLK_FEAT_POLL)) {
635+
bio->bi_status = BLK_STS_NOTSUPP;
636+
bio_endio(bio);
637+
} else {
638+
disk->fops->submit_bio(bio);
639+
}
634640
blk_queue_exit(disk->queue);
635641
}
636642

@@ -805,12 +811,6 @@ void submit_bio_noacct(struct bio *bio)
805811
}
806812
}
807813

808-
if (!(q->limits.features & BLK_FEAT_POLL) &&
809-
(bio->bi_opf & REQ_POLLED)) {
810-
bio_clear_polled(bio);
811-
goto not_supported;
812-
}
813-
814814
switch (bio_op(bio)) {
815815
case REQ_OP_READ:
816816
break;
@@ -935,7 +935,7 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
935935
return 0;
936936

937937
q = bdev_get_queue(bdev);
938-
if (cookie == BLK_QC_T_NONE || !(q->limits.features & BLK_FEAT_POLL))
938+
if (cookie == BLK_QC_T_NONE)
939939
return 0;
940940

941941
blk_flush_plug(current->plug, false);
@@ -951,7 +951,9 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
951951
*/
952952
if (!percpu_ref_tryget(&q->q_usage_counter))
953953
return 0;
954-
if (queue_is_mq(q)) {
954+
if (!(q->limits.features & BLK_FEAT_POLL)) {
955+
ret = 0;
956+
} else if (queue_is_mq(q)) {
955957
ret = blk_mq_poll(q, cookie, iob, flags);
956958
} else {
957959
struct gendisk *disk = q->disk;

block/blk-mq.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,14 +3096,22 @@ void blk_mq_submit_bio(struct bio *bio)
30963096
}
30973097

30983098
/*
3099-
* Device reconfiguration may change logical block size, so alignment
3100-
* check has to be done with queue usage counter held
3099+
* Device reconfiguration may change logical block size or reduce the
3100+
* number of poll queues, so the checks for alignment and poll support
3101+
* have to be done with queue usage counter held.
31013102
*/
31023103
if (unlikely(bio_unaligned(bio, q))) {
31033104
bio_io_error(bio);
31043105
goto queue_exit;
31053106
}
31063107

3108+
if ((bio->bi_opf & REQ_POLLED) &&
3109+
!(q->limits.features & BLK_FEAT_POLL)) {
3110+
bio->bi_status = BLK_STS_NOTSUPP;
3111+
bio_endio(bio);
3112+
goto queue_exit;
3113+
}
3114+
31073115
bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
31083116
if (!bio)
31093117
goto queue_exit;

0 commit comments

Comments
 (0)