Skip to content

Commit 7b4f36c

Browse files
committed
block: ensure we hold a queue reference when using queue limits
q_usage_counter is the only thing preventing us from the limits changing under us in __bio_split_to_limits, but blk_mq_submit_bio doesn't hold it while calling into it. Move the splitting inside the region where we know we've got a queue reference. Ideally this could still remain a shared section of code, but let's keep the fix simple and defer any refactoring here to later. Reported-by: Christoph Hellwig <hch@lst.de> Fixes: 900e080 ("block: move queue enter logic into blk_mq_submit_bio()") Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 309ce67 commit 7b4f36c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

block/blk-mq.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,12 +2964,6 @@ void blk_mq_submit_bio(struct bio *bio)
29642964
blk_status_t ret;
29652965

29662966
bio = blk_queue_bounce(bio, q);
2967-
if (bio_may_exceed_limits(bio, &q->limits)) {
2968-
bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
2969-
if (!bio)
2970-
return;
2971-
}
2972-
29732967
bio_set_ioprio(bio);
29742968

29752969
if (plug) {
@@ -2978,6 +2972,11 @@ void blk_mq_submit_bio(struct bio *bio)
29782972
rq = NULL;
29792973
}
29802974
if (rq) {
2975+
if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
2976+
bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
2977+
if (!bio)
2978+
return;
2979+
}
29812980
if (!bio_integrity_prep(bio))
29822981
return;
29832982
if (blk_mq_attempt_bio_merge(q, bio, nr_segs))
@@ -2988,6 +2987,11 @@ void blk_mq_submit_bio(struct bio *bio)
29882987
} else {
29892988
if (unlikely(bio_queue_enter(bio)))
29902989
return;
2990+
if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
2991+
bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
2992+
if (!bio)
2993+
goto fail;
2994+
}
29912995
if (!bio_integrity_prep(bio))
29922996
goto fail;
29932997
}

0 commit comments

Comments
 (0)