Skip to content

Commit 7090426

Browse files
rosslagerwallaxboe
authored andcommitted
blk-mq: Fix stall due to recursive flush plug
We have seen rare IO stalls as follows: * blk_mq_plug_issue_direct() is entered with an mq_list containing two requests. * For the first request, it sets last == false and enters the driver's queue_rq callback. * The driver queue_rq callback indirectly calls schedule() which calls blk_flush_plug(). This may happen if the driver has the BLK_MQ_F_BLOCKING flag set and is allowed to sleep in ->queue_rq. * blk_flush_plug() handles the remaining request in the mq_list. mq_list is now empty. * The original call to queue_rq resumes (with last == false). * The loop in blk_mq_plug_issue_direct() terminates because there are no remaining requests in mq_list. The IO is now stalled because the last request submitted to the driver had last == false and there was no subsequent call to commit_rqs(). Fix this by returning early in blk_mq_flush_plug_list() if rq_count is 0 which it will be in the recursive case, rather than checking if the mq_list is empty. At the same time, adjust one of the callers to skip the mq_list empty check as it is not necessary. Fixes: dc5fc36 ("block: attempt direct issue of plug list") Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20230714101106.3635611-1-ross.lagerwall@citrix.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 9f87fc4 commit 7090426

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

block/blk-core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,7 @@ void __blk_flush_plug(struct blk_plug *plug, bool from_schedule)
11441144
{
11451145
if (!list_empty(&plug->cb_list))
11461146
flush_plug_callbacks(plug, from_schedule);
1147-
if (!rq_list_empty(plug->mq_list))
1148-
blk_mq_flush_plug_list(plug, from_schedule);
1147+
blk_mq_flush_plug_list(plug, from_schedule);
11491148
/*
11501149
* Unconditionally flush out cached requests, even if the unplug
11511150
* event came from schedule. Since we know hold references to the

block/blk-mq.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2754,7 +2754,14 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
27542754
{
27552755
struct request *rq;
27562756

2757-
if (rq_list_empty(plug->mq_list))
2757+
/*
2758+
* We may have been called recursively midway through handling
2759+
* plug->mq_list via a schedule() in the driver's queue_rq() callback.
2760+
* To avoid mq_list changing under our feet, clear rq_count early and
2761+
* bail out specifically if rq_count is 0 rather than checking
2762+
* whether the mq_list is empty.
2763+
*/
2764+
if (plug->rq_count == 0)
27582765
return;
27592766
plug->rq_count = 0;
27602767

0 commit comments

Comments
 (0)