public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] nvme: fix hang in path of removing disk
@ 2017-05-22 15:05 Ming Lei
  2017-05-22 15:05 ` [PATCH v3 1/3] nvme: use blk_mq_start_hw_queues() in nvme_kill_queues() Ming Lei
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ming Lei @ 2017-05-22 15:05 UTC (permalink / raw)
  To: Jens Axboe, Keith Busch, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, Zhang Yi, linux-block, Johannes Thumshirn, Ming Lei

The first two patches fixes hang during removing disk.

The 3rd patch removes blk_mq_abort_requeue_list() since
no one uses it any more.

V3:
	- adjust comments about 'Forcibly start all queues'
	as suggested by Christoph

V2:
	- figure out one big issue is that we should start
	queues unconditionally when killing queues
	- fix requeue races in another way


Ming Lei (3):
  nvme: use blk_mq_start_hw_queues() in nvme_kill_queues()
  nvme: avoid to use blk_mq_abort_requeue_list()
  blk-mq: remove blk_mq_abort_requeue_list()

 block/blk-mq.c           | 19 -------------------
 drivers/nvme/host/core.c | 13 ++++++++++---
 include/linux/blk-mq.h   |  1 -
 3 files changed, 10 insertions(+), 23 deletions(-)

-- 
2.9.4

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

* [PATCH v3 1/3] nvme: use blk_mq_start_hw_queues() in nvme_kill_queues()
  2017-05-22 15:05 [PATCH v3 0/3] nvme: fix hang in path of removing disk Ming Lei
@ 2017-05-22 15:05 ` Ming Lei
  2017-05-22 15:05 ` [PATCH v3 2/3] nvme: avoid to use blk_mq_abort_requeue_list() Ming Lei
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2017-05-22 15:05 UTC (permalink / raw)
  To: Jens Axboe, Keith Busch, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, Zhang Yi, linux-block, Johannes Thumshirn, Ming Lei,
	stable

Inside nvme_kill_queues(), we have to start hw queues for
draining requests in sw queues, .dispatch list and requeue list,
so use blk_mq_start_hw_queues() instead of blk_mq_start_stopped_hw_queues()
which only run queues if queues are stopped, but the queues may have
been started already, for example nvme_start_queues() is called in reset work
function.

blk_mq_start_hw_queues() run hw queues in current context, instead
of running asynchronously like before. Given nvme_kill_queues() is
run from either remove context or reset worker context, both are fine
to run hw queue directly. And the mutex of namespaces_mutex isn't a
problem too becasue nvme_start_freeze() runs hw queue in this way
already.

Cc: stable@vger.kernel.org
Reported-by: Zhang Yi <yizhan@redhat.com>
Reviewed-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/nvme/host/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index d5e0906262ea..40d5e4a9e8d7 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2437,7 +2437,13 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)
 		revalidate_disk(ns->disk);
 		blk_set_queue_dying(ns->queue);
 		blk_mq_abort_requeue_list(ns->queue);
-		blk_mq_start_stopped_hw_queues(ns->queue, true);
+
+		/*
+		 * Forcibly start all queues to avoid having stuck requests.
+		 * Note that we must ensure the queues are not stopped
+		 * when the final removal happens.
+		 */
+		blk_mq_start_hw_queues(ns->queue);
 	}
 	mutex_unlock(&ctrl->namespaces_mutex);
 }
-- 
2.9.4

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

* [PATCH v3 2/3] nvme: avoid to use blk_mq_abort_requeue_list()
  2017-05-22 15:05 [PATCH v3 0/3] nvme: fix hang in path of removing disk Ming Lei
  2017-05-22 15:05 ` [PATCH v3 1/3] nvme: use blk_mq_start_hw_queues() in nvme_kill_queues() Ming Lei
@ 2017-05-22 15:05 ` Ming Lei
  2017-05-22 15:05 ` [PATCH v3 3/3] blk-mq: remove blk_mq_abort_requeue_list() Ming Lei
  2017-05-22 18:48 ` [PATCH v3 0/3] nvme: fix hang in path of removing disk Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2017-05-22 15:05 UTC (permalink / raw)
  To: Jens Axboe, Keith Busch, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, Zhang Yi, linux-block, Johannes Thumshirn, Ming Lei,
	stable

NVMe may add request into requeue list simply and not kick off the
requeue if hw queues are stopped. Then blk_mq_abort_requeue_list()
is called in both nvme_kill_queues() and nvme_ns_remove() for
dealing with this issue.

Unfortunately blk_mq_abort_requeue_list() is absolutely a
race maker, for example, one request may be requeued during
the aborting. So this patch just calls blk_mq_kick_requeue_list() in
nvme_kill_queues() to handle this issue like what nvme_start_queues()
does. Now all requests in requeue list when queues are stopped will be
handled by blk_mq_kick_requeue_list() when queues are restarted, either
in nvme_start_queues() or in nvme_kill_queues().

Cc: stable@vger.kernel.org
Reported-by: Zhang Yi <yizhan@redhat.com>
Reviewed-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/nvme/host/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 40d5e4a9e8d7..04e115834702 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2098,7 +2098,6 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 		if (ns->ndev)
 			nvme_nvm_unregister_sysfs(ns);
 		del_gendisk(ns->disk);
-		blk_mq_abort_requeue_list(ns->queue);
 		blk_cleanup_queue(ns->queue);
 	}
 
@@ -2436,7 +2435,6 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)
 			continue;
 		revalidate_disk(ns->disk);
 		blk_set_queue_dying(ns->queue);
-		blk_mq_abort_requeue_list(ns->queue);
 
 		/*
 		 * Forcibly start all queues to avoid having stuck requests.
@@ -2444,6 +2442,9 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)
 		 * when the final removal happens.
 		 */
 		blk_mq_start_hw_queues(ns->queue);
+
+		/* draining requests in requeue list */
+		blk_mq_kick_requeue_list(ns->queue);
 	}
 	mutex_unlock(&ctrl->namespaces_mutex);
 }
-- 
2.9.4

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

* [PATCH v3 3/3] blk-mq: remove blk_mq_abort_requeue_list()
  2017-05-22 15:05 [PATCH v3 0/3] nvme: fix hang in path of removing disk Ming Lei
  2017-05-22 15:05 ` [PATCH v3 1/3] nvme: use blk_mq_start_hw_queues() in nvme_kill_queues() Ming Lei
  2017-05-22 15:05 ` [PATCH v3 2/3] nvme: avoid to use blk_mq_abort_requeue_list() Ming Lei
@ 2017-05-22 15:05 ` Ming Lei
  2017-05-22 18:48 ` [PATCH v3 0/3] nvme: fix hang in path of removing disk Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2017-05-22 15:05 UTC (permalink / raw)
  To: Jens Axboe, Keith Busch, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, Zhang Yi, linux-block, Johannes Thumshirn, Ming Lei

No one uses it any more, so remove it.

Reviewed-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq.c         | 19 -------------------
 include/linux/blk-mq.h |  1 -
 2 files changed, 20 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index a69ad122ed66..f2224ffd225d 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -628,25 +628,6 @@ void blk_mq_delay_kick_requeue_list(struct request_queue *q,
 }
 EXPORT_SYMBOL(blk_mq_delay_kick_requeue_list);
 
-void blk_mq_abort_requeue_list(struct request_queue *q)
-{
-	unsigned long flags;
-	LIST_HEAD(rq_list);
-
-	spin_lock_irqsave(&q->requeue_lock, flags);
-	list_splice_init(&q->requeue_list, &rq_list);
-	spin_unlock_irqrestore(&q->requeue_lock, flags);
-
-	while (!list_empty(&rq_list)) {
-		struct request *rq;
-
-		rq = list_first_entry(&rq_list, struct request, queuelist);
-		list_del_init(&rq->queuelist);
-		blk_mq_end_request(rq, -EIO);
-	}
-}
-EXPORT_SYMBOL(blk_mq_abort_requeue_list);
-
 struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag)
 {
 	if (tag < tags->nr_tags) {
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index c47aa248c640..fcd641032f8d 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -238,7 +238,6 @@ void blk_mq_add_to_requeue_list(struct request *rq, bool at_head,
 				bool kick_requeue_list);
 void blk_mq_kick_requeue_list(struct request_queue *q);
 void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs);
-void blk_mq_abort_requeue_list(struct request_queue *q);
 void blk_mq_complete_request(struct request *rq);
 
 bool blk_mq_queue_stopped(struct request_queue *q);
-- 
2.9.4

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

* Re: [PATCH v3 0/3] nvme: fix hang in path of removing disk
  2017-05-22 15:05 [PATCH v3 0/3] nvme: fix hang in path of removing disk Ming Lei
                   ` (2 preceding siblings ...)
  2017-05-22 15:05 ` [PATCH v3 3/3] blk-mq: remove blk_mq_abort_requeue_list() Ming Lei
@ 2017-05-22 18:48 ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2017-05-22 18:48 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, Keith Busch, Christoph Hellwig, Sagi Grimberg,
	linux-nvme, Zhang Yi, linux-block, Johannes Thumshirn

Thanks Ming,

I'll add the three patches to the nvme-4.12 queue, assuming Jens
is okay with us queueing up the block path to remove
blk_mq_abort_requeue_list.

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

end of thread, other threads:[~2017-05-22 18:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-22 15:05 [PATCH v3 0/3] nvme: fix hang in path of removing disk Ming Lei
2017-05-22 15:05 ` [PATCH v3 1/3] nvme: use blk_mq_start_hw_queues() in nvme_kill_queues() Ming Lei
2017-05-22 15:05 ` [PATCH v3 2/3] nvme: avoid to use blk_mq_abort_requeue_list() Ming Lei
2017-05-22 15:05 ` [PATCH v3 3/3] blk-mq: remove blk_mq_abort_requeue_list() Ming Lei
2017-05-22 18:48 ` [PATCH v3 0/3] nvme: fix hang in path of removing disk Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox