linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Avoid that scsi-mq queue processing stalls
@ 2017-03-31 23:12 Bart Van Assche
  2017-03-31 23:12 ` [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Bart Van Assche @ 2017-03-31 23:12 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley, Bart Van Assche

Hello Jens,

The three patches in this patch series fix the queue lockup I reported
a few days ago on the linux-block mailing list. Please consider these
patches for kernel v4.11.

Thanks,

Bart.

Bart Van Assche (3):
  blk-mq: Introduce blk_mq_ops.restart_queues
  scsi: Add scsi_restart_queues()
  scsi: Ensure that scsi_run_queue() runs all hardware queues

 block/blk-mq-sched.c    | 11 +++--------
 block/blk-mq-sched.h    | 14 --------------
 drivers/scsi/scsi_lib.c | 20 +++++++++++++++++---
 include/linux/blk-mq.h  |  4 ++++
 include/linux/blkdev.h  |  1 -
 5 files changed, 24 insertions(+), 26 deletions(-)

-- 
2.12.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues
  2017-03-31 23:12 [PATCH 0/3] Avoid that scsi-mq queue processing stalls Bart Van Assche
@ 2017-03-31 23:12 ` Bart Van Assche
  2017-04-03  6:10   ` Hannes Reinecke
  2017-03-31 23:12 ` [PATCH 2/3] scsi: Add scsi_restart_queues() Bart Van Assche
  2017-03-31 23:12 ` [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues Bart Van Assche
  2 siblings, 1 reply; 8+ messages in thread
From: Bart Van Assche @ 2017-03-31 23:12 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Bart Van Assche, Christoph Hellwig, Hannes Reinecke

If a tag set is shared among multiple request queues, leave
it to the block driver to restart queues. Hence remove
QUEUE_FLAG_RESTART and introduce blk_mq_ops.restart_queues.
Remove blk_mq_sched_mark_restart_queue() because this
function has no callers.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 block/blk-mq-sched.c   | 11 +++--------
 block/blk-mq-sched.h   | 14 --------------
 include/linux/blk-mq.h |  4 ++++
 include/linux/blkdev.h |  1 -
 4 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index 09af8ff18719..ed9942ee0146 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -329,16 +329,11 @@ static void blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)
 void blk_mq_sched_restart_queues(struct blk_mq_hw_ctx *hctx)
 {
 	struct request_queue *q = hctx->queue;
-	unsigned int i;
 
-	if (test_bit(QUEUE_FLAG_RESTART, &q->queue_flags)) {
-		if (test_and_clear_bit(QUEUE_FLAG_RESTART, &q->queue_flags)) {
-			queue_for_each_hw_ctx(q, hctx, i)
-				blk_mq_sched_restart_hctx(hctx);
-		}
-	} else {
+	if (q->mq_ops->restart_queues)
+		q->mq_ops->restart_queues(q);
+	else
 		blk_mq_sched_restart_hctx(hctx);
-	}
 }
 
 /*
diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h
index a75b16b123f7..fe62b1eccf4c 100644
--- a/block/blk-mq-sched.h
+++ b/block/blk-mq-sched.h
@@ -131,20 +131,6 @@ static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
 		set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
 }
 
-/*
- * Mark a hardware queue and the request queue it belongs to as needing a
- * restart.
- */
-static inline void blk_mq_sched_mark_restart_queue(struct blk_mq_hw_ctx *hctx)
-{
-	struct request_queue *q = hctx->queue;
-
-	if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
-		set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
-	if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
-		set_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
-}
-
 static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
 {
 	return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index ea2e9dcd3aef..75160e9470cb 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -86,6 +86,7 @@ struct blk_mq_queue_data {
 };
 
 typedef int (queue_rq_fn)(struct blk_mq_hw_ctx *, const struct blk_mq_queue_data *);
+typedef void (restart_fn)(struct request_queue *q);
 typedef enum blk_eh_timer_return (timeout_fn)(struct request *, bool);
 typedef int (init_hctx_fn)(struct blk_mq_hw_ctx *, void *, unsigned int);
 typedef void (exit_hctx_fn)(struct blk_mq_hw_ctx *, unsigned int);
@@ -108,6 +109,9 @@ struct blk_mq_ops {
 	 */
 	queue_rq_fn		*queue_rq;
 
+	/* Called upon request completion to rerun all queues */
+	restart_fn		*restart_queues;
+
 	/*
 	 * Called on request timeout
 	 */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index a2dc6b390d48..a80543ec8be7 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -615,7 +615,6 @@ struct request_queue {
 #define QUEUE_FLAG_FLUSH_NQ    25	/* flush not queueuable */
 #define QUEUE_FLAG_DAX         26	/* device supports DAX */
 #define QUEUE_FLAG_STATS       27	/* track rq completion times */
-#define QUEUE_FLAG_RESTART     28	/* queue needs restart at completion */
 #define QUEUE_FLAG_POLL_STATS  29	/* collecting stats for hybrid polling */
 #define QUEUE_FLAG_REGISTERED  30	/* queue has been registered to a disk */
 
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] scsi: Add scsi_restart_queues()
  2017-03-31 23:12 [PATCH 0/3] Avoid that scsi-mq queue processing stalls Bart Van Assche
  2017-03-31 23:12 ` [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues Bart Van Assche
@ 2017-03-31 23:12 ` Bart Van Assche
  2017-04-03  6:10   ` Hannes Reinecke
  2017-03-31 23:12 ` [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues Bart Van Assche
  2 siblings, 1 reply; 8+ messages in thread
From: Bart Van Assche @ 2017-03-31 23:12 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Bart Van Assche, Christoph Hellwig, Hannes Reinecke

This patch avoids that if multiple SCSI devices are associated with
a SCSI host that a queue can get stuck if scsi_queue_rq() returns
"busy".

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/scsi_lib.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index c1519660824b..1d804e33971a 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -555,6 +555,21 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
 		scsi_run_queue(sdev->request_queue);
 }
 
+static void scsi_restart_queues(struct request_queue *q)
+{
+	struct scsi_device *sdev = q->queuedata;
+	struct Scsi_Host *shost = sdev->host;
+	unsigned long flags;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+	__shost_for_each_device(sdev, shost) {
+		q = sdev->request_queue;
+		if (q->mq_ops && !blk_queue_dying(q))
+			blk_mq_run_hw_queues(q, true);
+	}
+	spin_unlock_irqrestore(shost->host_lock, flags);
+}
+
 static void scsi_uninit_cmd(struct scsi_cmnd *cmd)
 {
 	if (!blk_rq_is_passthrough(cmd->request)) {
@@ -2156,6 +2171,7 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
 
 static const struct blk_mq_ops scsi_mq_ops = {
 	.queue_rq	= scsi_queue_rq,
+	.restart_queues	= scsi_restart_queues,
 	.complete	= scsi_softirq_done,
 	.timeout	= scsi_timeout,
 	.init_request	= scsi_init_request,
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues
  2017-03-31 23:12 [PATCH 0/3] Avoid that scsi-mq queue processing stalls Bart Van Assche
  2017-03-31 23:12 ` [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues Bart Van Assche
  2017-03-31 23:12 ` [PATCH 2/3] scsi: Add scsi_restart_queues() Bart Van Assche
@ 2017-03-31 23:12 ` Bart Van Assche
  2017-04-02  7:49   ` Sagi Grimberg
  2017-04-03  6:12   ` Hannes Reinecke
  2 siblings, 2 replies; 8+ messages in thread
From: Bart Van Assche @ 2017-03-31 23:12 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
	Sagi Grimberg

commit 52d7f1b5c2f3 ("blk-mq: Avoid that requeueing starts stopped
queues") removed the blk_mq_stop_hw_queue() call from scsi_queue_rq()
for the BLK_MQ_RQ_QUEUE_BUSY case. blk_mq_start_stopped_hw_queues()
only runs queues that had been stopped. Hence change the
blk_mq_start_stopped_hw_queues() call in scsi_run_queue() into
blk_mq_run_hw_queues(). Remove the blk_mq_start_stopped_hw_queues()
call from scsi_end_request() because __blk_mq_finish_request()
already runs all hardware queues if needed.

Fixes: commit 52d7f1b5c2f3 ("blk-mq: Avoid that requeueing starts stopped queues")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
---
 drivers/scsi/scsi_lib.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1d804e33971a..3323878423ac 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -496,7 +496,7 @@ static void scsi_run_queue(struct request_queue *q)
 		scsi_starved_list_run(sdev->host);
 
 	if (q->mq_ops)
-		blk_mq_start_stopped_hw_queues(q, false);
+		blk_mq_run_hw_queues(q, false);
 	else
 		blk_run_queue(q);
 }
@@ -681,8 +681,6 @@ static bool scsi_end_request(struct request *req, int error,
 		if (scsi_target(sdev)->single_lun ||
 		    !list_empty(&sdev->host->starved_list))
 			kblockd_schedule_work(&sdev->requeue_work);
-		else
-			blk_mq_start_stopped_hw_queues(q, true);
 	} else {
 		unsigned long flags;
 
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues
  2017-03-31 23:12 ` [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues Bart Van Assche
@ 2017-04-02  7:49   ` Sagi Grimberg
  2017-04-03  6:12   ` Hannes Reinecke
  1 sibling, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2017-04-02  7:49 UTC (permalink / raw)
  To: Bart Van Assche, Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Christoph Hellwig, Hannes Reinecke

Looks good,

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues
  2017-03-31 23:12 ` [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues Bart Van Assche
@ 2017-04-03  6:10   ` Hannes Reinecke
  0 siblings, 0 replies; 8+ messages in thread
From: Hannes Reinecke @ 2017-04-03  6:10 UTC (permalink / raw)
  To: Bart Van Assche, Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Christoph Hellwig, Hannes Reinecke

On 04/01/2017 01:12 AM, Bart Van Assche wrote:
> If a tag set is shared among multiple request queues, leave
> it to the block driver to restart queues. Hence remove
> QUEUE_FLAG_RESTART and introduce blk_mq_ops.restart_queues.
> Remove blk_mq_sched_mark_restart_queue() because this
> function has no callers.
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> ---
>  block/blk-mq-sched.c   | 11 +++--------
>  block/blk-mq-sched.h   | 14 --------------
>  include/linux/blk-mq.h |  4 ++++
>  include/linux/blkdev.h |  1 -
>  4 files changed, 7 insertions(+), 23 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N�rnberg)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] scsi: Add scsi_restart_queues()
  2017-03-31 23:12 ` [PATCH 2/3] scsi: Add scsi_restart_queues() Bart Van Assche
@ 2017-04-03  6:10   ` Hannes Reinecke
  0 siblings, 0 replies; 8+ messages in thread
From: Hannes Reinecke @ 2017-04-03  6:10 UTC (permalink / raw)
  To: Bart Van Assche, Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Christoph Hellwig, Hannes Reinecke

On 04/01/2017 01:12 AM, Bart Van Assche wrote:
> This patch avoids that if multiple SCSI devices are associated with
> a SCSI host that a queue can get stuck if scsi_queue_rq() returns
> "busy".
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/scsi/scsi_lib.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N�rnberg)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues
  2017-03-31 23:12 ` [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues Bart Van Assche
  2017-04-02  7:49   ` Sagi Grimberg
@ 2017-04-03  6:12   ` Hannes Reinecke
  1 sibling, 0 replies; 8+ messages in thread
From: Hannes Reinecke @ 2017-04-03  6:12 UTC (permalink / raw)
  To: Bart Van Assche, Jens Axboe
  Cc: linux-block, Martin K . Petersen, James Bottomley,
	Christoph Hellwig, Sagi Grimberg

On 04/01/2017 01:12 AM, Bart Van Assche wrote:
> commit 52d7f1b5c2f3 ("blk-mq: Avoid that requeueing starts stopped
> queues") removed the blk_mq_stop_hw_queue() call from scsi_queue_rq()
> for the BLK_MQ_RQ_QUEUE_BUSY case. blk_mq_start_stopped_hw_queues()
> only runs queues that had been stopped. Hence change the
> blk_mq_start_stopped_hw_queues() call in scsi_run_queue() into
> blk_mq_run_hw_queues(). Remove the blk_mq_start_stopped_hw_queues()
> call from scsi_end_request() because __blk_mq_finish_request()
> already runs all hardware queues if needed.
> 
> Fixes: commit 52d7f1b5c2f3 ("blk-mq: Avoid that requeueing starts stopped queues")
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Sagi Grimberg <sagi@grimberg.me>
> ---
>  drivers/scsi/scsi_lib.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N�rnberg)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-04-03  6:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 23:12 [PATCH 0/3] Avoid that scsi-mq queue processing stalls Bart Van Assche
2017-03-31 23:12 ` [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues Bart Van Assche
2017-04-03  6:10   ` Hannes Reinecke
2017-03-31 23:12 ` [PATCH 2/3] scsi: Add scsi_restart_queues() Bart Van Assche
2017-04-03  6:10   ` Hannes Reinecke
2017-03-31 23:12 ` [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues Bart Van Assche
2017-04-02  7:49   ` Sagi Grimberg
2017-04-03  6:12   ` Hannes Reinecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).