blk-mq: fix two misuses on RQF_USE_SCHED
authorMing Lei <ming.lei@redhat.com>
Sat, 24 Jun 2023 13:01:05 +0000 (21:01 +0800)
committerJens Axboe <axboe@kernel.dk>
Sun, 25 Jun 2023 14:01:05 +0000 (08:01 -0600)
Request allocated from sched tags can't be issued via ->queue_rqs()
directly, since driver tag isn't allocated yet. This is the 1st misuse
of RQF_USE_SCHED for figuring out plug->has_elevator.

Request allocated from sched tags can't be ended by
blk_mq_end_request_batch() too, fix the 2nd RQF_USE_SCHED misuse
in blk_mq_add_to_batch().

Without this patch, NVMe uring cmd passthrough IO workload can run into
hang easily with real io scheduler.

Fixes: dd6216bb16e8 ("blk-mq: make sure elevator callbacks aren't called for passthrough request")
Reported-by: Guangwu Zhang <guazhang@redhat.com>
Closes: https://lore.kernel.org/linux-block/CAGS2=YrBjpLPOKa-gzcKuuOG60AGth5794PNCDwatdnnscB9ug@mail.gmail.com/
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20230624130105.1443879-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq.c
include/linux/blk-mq.h

index 720b5061ffe880496d7a0264904459ec920291b2..32e50bc0cbb0cc6887f386ab5db147030e7d2020 100644 (file)
@@ -1280,7 +1280,11 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
 
        if (!plug->multiple_queues && last && last->q != rq->q)
                plug->multiple_queues = true;
-       if (!plug->has_elevator && (rq->rq_flags & RQF_USE_SCHED))
+       /*
+        * Any request allocated from sched tags can't be issued to
+        * ->queue_rqs() directly
+        */
+       if (!plug->has_elevator && (rq->rq_flags & RQF_SCHED_TAGS))
                plug->has_elevator = true;
        rq->rq_next = NULL;
        rq_list_add(&plug->mq_list, rq);
index f401067ac03a19dfa12bd6e97075a72d7f91b757..aaed687a454c38e83a386e5ac20595e7a351ec0b 100644 (file)
@@ -852,7 +852,11 @@ static inline bool blk_mq_add_to_batch(struct request *req,
                                       struct io_comp_batch *iob, int ioerror,
                                       void (*complete)(struct io_comp_batch *))
 {
-       if (!iob || (req->rq_flags & RQF_USE_SCHED) || ioerror ||
+       /*
+        * blk_mq_end_request_batch() can't end request allocated from
+        * sched tags
+        */
+       if (!iob || (req->rq_flags & RQF_SCHED_TAGS) || ioerror ||
                        (req->end_io && !blk_rq_is_passthrough(req)))
                return false;