Skip to content

Commit c616cbe

Browse files
committed
blk-mq: punt failed direct issue to dispatch list
After the direct dispatch corruption fix, we permanently disallow direct dispatch of non read/write requests. This works fine off the normal IO path, as they will be retried like any other failed direct dispatch request. But for the blk_insert_cloned_request() that only DM uses to bypass the bottom level scheduler, we always first attempt direct dispatch. For some types of requests, that's now a permanent failure, and no amount of retrying will make that succeed. This results in a livelock. Instead of making special cases for what we can direct issue, and now having to deal with DM solving the livelock while still retaining a BUSY condition feedback loop, always just add a request that has been through ->queue_rq() to the hardware queue dispatch list. These are safe to use as no merging can take place there. Additionally, if requests do have prepped data from drivers, we aren't dependent on them not sharing space in the request structure to safely add them to the IO scheduler lists. This basically reverts ffe81d4 and is based on a patch from Ming, but with the list insert case covered as well. Fixes: ffe81d4 ("blk-mq: fix corruption with direct issue") Cc: stable@vger.kernel.org Suggested-by: Ming Lei <ming.lei@redhat.com> Reported-by: Bart Van Assche <bvanassche@acm.org> Tested-by: Ming Lei <ming.lei@redhat.com> Acked-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ba7aeae commit c616cbe

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

block/blk-mq.c

+5-28
Original file line numberDiff line numberDiff line change
@@ -1715,15 +1715,6 @@ static blk_status_t __blk_mq_issue_directly(struct blk_mq_hw_ctx *hctx,
17151715
break;
17161716
case BLK_STS_RESOURCE:
17171717
case BLK_STS_DEV_RESOURCE:
1718-
/*
1719-
* If direct dispatch fails, we cannot allow any merging on
1720-
* this IO. Drivers (like SCSI) may have set up permanent state
1721-
* for this request, like SG tables and mappings, and if we
1722-
* merge to it later on then we'll still only do IO to the
1723-
* original part.
1724-
*/
1725-
rq->cmd_flags |= REQ_NOMERGE;
1726-
17271718
blk_mq_update_dispatch_busy(hctx, true);
17281719
__blk_mq_requeue_request(rq);
17291720
break;
@@ -1736,18 +1727,6 @@ static blk_status_t __blk_mq_issue_directly(struct blk_mq_hw_ctx *hctx,
17361727
return ret;
17371728
}
17381729

1739-
/*
1740-
* Don't allow direct dispatch of anything but regular reads/writes,
1741-
* as some of the other commands can potentially share request space
1742-
* with data we need for the IO scheduler. If we attempt a direct dispatch
1743-
* on those and fail, we can't safely add it to the scheduler afterwards
1744-
* without potentially overwriting data that the driver has already written.
1745-
*/
1746-
static bool blk_rq_can_direct_dispatch(struct request *rq)
1747-
{
1748-
return req_op(rq) == REQ_OP_READ || req_op(rq) == REQ_OP_WRITE;
1749-
}
1750-
17511730
static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
17521731
struct request *rq,
17531732
blk_qc_t *cookie,
@@ -1769,7 +1748,7 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
17691748
goto insert;
17701749
}
17711750

1772-
if (!blk_rq_can_direct_dispatch(rq) || (q->elevator && !bypass_insert))
1751+
if (q->elevator && !bypass_insert)
17731752
goto insert;
17741753

17751754
if (!blk_mq_get_dispatch_budget(hctx))
@@ -1785,7 +1764,7 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
17851764
if (bypass_insert)
17861765
return BLK_STS_RESOURCE;
17871766

1788-
blk_mq_sched_insert_request(rq, false, run_queue, false);
1767+
blk_mq_request_bypass_insert(rq, run_queue);
17891768
return BLK_STS_OK;
17901769
}
17911770

@@ -1801,7 +1780,7 @@ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
18011780

18021781
ret = __blk_mq_try_issue_directly(hctx, rq, cookie, false);
18031782
if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE)
1804-
blk_mq_sched_insert_request(rq, false, true, false);
1783+
blk_mq_request_bypass_insert(rq, true);
18051784
else if (ret != BLK_STS_OK)
18061785
blk_mq_end_request(rq, ret);
18071786

@@ -1831,15 +1810,13 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
18311810
struct request *rq = list_first_entry(list, struct request,
18321811
queuelist);
18331812

1834-
if (!blk_rq_can_direct_dispatch(rq))
1835-
break;
1836-
18371813
list_del_init(&rq->queuelist);
18381814
ret = blk_mq_request_issue_directly(rq);
18391815
if (ret != BLK_STS_OK) {
18401816
if (ret == BLK_STS_RESOURCE ||
18411817
ret == BLK_STS_DEV_RESOURCE) {
1842-
list_add(&rq->queuelist, list);
1818+
blk_mq_request_bypass_insert(rq,
1819+
list_empty(list));
18431820
break;
18441821
}
18451822
blk_mq_end_request(rq, ret);

0 commit comments

Comments
 (0)