All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Ming Lei <ming.lei@redhat.com>, Omar Sandoval <osandov@fb.com>,
	Hannes Reinecke <hare@suse.de>,
	Johannes Thumshirn <jthumshirn@suse.de>
Subject: [PATCH 7/7] blk-mq: Fix another queue stall
Date: Thu, 30 Nov 2017 16:08:48 -0800	[thread overview]
Message-ID: <20171201000848.2656-8-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20171201000848.2656-1-bart.vanassche@wdc.com>

The following code at the end of blk_mq_dispatch_rq_list() detects
whether or not wake_up(&hctx->dispatch_wait) has been called
concurrently with pushing back requests onto the dispatch list:

    list_empty_careful(&hctx->dispatch_wait.entry)

Since blk_mq_dispatch_wake() is protected by another lock than the
dispatch list and since blk_mq_run_hw_queue() does not acquire any
lock if it notices that no requests are pending,
blk_mq_dispatch_wake() is not ordered against the code that pushes
back requests onto the dispatch list. Avoid that the dispatch_wait
empty check fails due to load/store reordering by serializing it
against the dispatch_wait queue wakeup. This patch fixes a queue
stall I ran into while testing a SCSI initiator driver with the
maximum target depth set to one.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Omar Sandoval <osandov@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
---
 block/blk-mq.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index b4225f606737..a11767a4d95c 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1074,6 +1074,20 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx **hctx,
 	return ret;
 }
 
+static bool blk_mq_dispatch_list_empty(struct blk_mq_hw_ctx *hctx)
+{
+	struct sbq_wait_state *ws = bt_wait_ptr(&hctx->tags->bitmap_tags, hctx);
+	struct wait_queue_head *wq_head = &ws->wait;
+	unsigned long flags;
+	bool result;
+
+	spin_lock_irqsave(&wq_head->lock, flags);
+	result = list_empty(&hctx->dispatch_wait.entry);
+	spin_unlock_irqrestore(&wq_head->lock, flags);
+
+	return result;
+}
+
 bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
 			     bool got_budget)
 {
@@ -1197,7 +1211,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
 		 */
 		if (restart ||
 		    !blk_mq_sched_needs_restart(hctx) ||
-		    (no_tag && list_empty_careful(&hctx->dispatch_wait.entry)))
+		    (no_tag && blk_mq_dispatch_list_empty(hctx)))
 			blk_mq_run_hw_queue(hctx, true);
 	}
 
-- 
2.15.0

  parent reply	other threads:[~2017-12-01  0:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01  0:08 [PATCH 0/7] blk-mq: Queue running fixes Bart Van Assche
2017-12-01  0:08 ` [PATCH 1/7] blk-mq: Fix spelling in a source code comment Bart Van Assche
2017-12-01  0:08 ` [PATCH 2/7] block: Document more locking requirements Bart Van Assche
2017-12-01  3:03   ` Jens Axboe
2017-12-01 17:05     ` Bart Van Assche
2017-12-01  0:08 ` [PATCH 3/7] blk-mq: Make blk_mq_mark_tag_wait() easier to read Bart Van Assche
2017-12-01  0:08 ` [PATCH 4/7] blk-mq: Avoid that request processing stalls when sharing tags Bart Van Assche
2017-12-01  2:58   ` Ming Lei
2017-12-01 19:52     ` Bart Van Assche
2017-12-02  0:36       ` Ming Lei
2017-12-02  0:48         ` Bart Van Assche
2017-12-02  1:00           ` Ming Lei
2017-12-02  1:05             ` Bart Van Assche
2017-12-02  1:14               ` Ming Lei
2017-12-02  1:20               ` Ming Lei
2017-12-01  0:08 ` [PATCH 5/7] blk-mq: Avoid that blk_mq_mark_tag_wait() triggers a queue stall Bart Van Assche
2017-12-01  3:51   ` Ming Lei
2017-12-01  0:08 ` [PATCH 6/7] blk-mq: Rerun hardware queues after having called .put_budget() Bart Van Assche
2017-12-01  3:23   ` Ming Lei
2017-12-01  0:08 ` Bart Van Assche [this message]
2017-12-01  3:00   ` [PATCH 7/7] blk-mq: Fix another queue stall Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171201000848.2656-8-bart.vanassche@wdc.com \
    --to=bart.vanassche@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jthumshirn@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=osandov@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.