block: don't dereference request after flush insertion
authorJens Axboe <axboe@kernel.dk>
Sat, 16 Oct 2021 13:34:49 +0000 (07:34 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Oct 2021 12:17:18 +0000 (06:17 -0600)
We could have a race here, where the request gets freed before we call
into blk_mq_run_hw_queue(). If this happens, we cannot rely on the state
of the request.

Grab the hardware context before inserting the flush.

Fixes: 0f38d7664615 ("blk-mq: cleanup blk_mq_submit_bio")
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq.c

index 87dc2de..b7b8437 100644 (file)
@@ -2284,9 +2284,10 @@ blk_qc_t blk_mq_submit_bio(struct bio *bio)
        }
 
        if (unlikely(is_flush_fua)) {
+               struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
                /* Bypass scheduler for flush requests */
                blk_insert_flush(rq);
-               blk_mq_run_hw_queue(rq->mq_hctx, true);
+               blk_mq_run_hw_queue(hctx, true);
        } else if (plug && (q->nr_hw_queues == 1 ||
                   blk_mq_is_shared_tags(rq->mq_hctx->flags) ||
                   q->mq_ops->commit_rqs || !blk_queue_nonrot(q))) {