linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq
@ 2018-05-24  9:51 Jianchao Wang
  2018-05-24  9:51 ` [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR Jianchao Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jianchao Wang @ 2018-05-24  9:51 UTC (permalink / raw)
  To: keith.busch, axboe, hch, sagi; +Cc: linux-nvme, linux-kernel

Currently nvmeq->cq_vector is set before alloc cq/sq. If the alloc
cq/sq command timeout, nvme_suspend_queue will invoke free_irq
for the nvmeq because the cq_vector is valid, this will cause warning
'Trying to free already-free IRQ xxx'. set nvmeq->cq_vector after
alloc cq/sq successes to fix this.

Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
---
 drivers/nvme/host/pci.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 17a0190..70b79f2 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1070,7 +1070,7 @@ static int adapter_delete_queue(struct nvme_dev *dev, u8 opcode, u16 id)
 }
 
 static int adapter_alloc_cq(struct nvme_dev *dev, u16 qid,
-						struct nvme_queue *nvmeq)
+						struct nvme_queue *nvmeq, int cq_vector)
 {
 	struct nvme_command c;
 	int flags = NVME_QUEUE_PHYS_CONTIG | NVME_CQ_IRQ_ENABLED;
@@ -1085,7 +1085,7 @@ static int adapter_alloc_cq(struct nvme_dev *dev, u16 qid,
 	c.create_cq.cqid = cpu_to_le16(qid);
 	c.create_cq.qsize = cpu_to_le16(nvmeq->q_depth - 1);
 	c.create_cq.cq_flags = cpu_to_le16(flags);
-	c.create_cq.irq_vector = cpu_to_le16(nvmeq->cq_vector);
+	c.create_cq.irq_vector = cpu_to_le16(cq_vector);
 
 	return nvme_submit_sync_cmd(dev->ctrl.admin_q, &c, NULL, 0);
 }
@@ -1459,6 +1459,7 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
 {
 	struct nvme_dev *dev = nvmeq->dev;
 	int result;
+	int cq_vector;
 
 	if (dev->cmb && use_cmb_sqes && (dev->cmbsz & NVME_CMBSZ_SQS)) {
 		unsigned offset = (qid - 1) * roundup(SQ_SIZE(nvmeq->q_depth),
@@ -1471,15 +1472,21 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
 	 * A queue's vector matches the queue identifier unless the controller
 	 * has only one vector available.
 	 */
-	nvmeq->cq_vector = dev->num_vecs == 1 ? 0 : qid;
-	result = adapter_alloc_cq(dev, qid, nvmeq);
+	cq_vector = dev->num_vecs == 1 ? 0 : qid;
+	result = adapter_alloc_cq(dev, qid, nvmeq, cq_vector);
 	if (result < 0)
-		goto release_vector;
+		goto out;
 
 	result = adapter_alloc_sq(dev, qid, nvmeq);
 	if (result < 0)
 		goto release_cq;
 
+	/*
+	 * set cq_vector after alloc cq/sq, otherwise, if alloc cq/sq command
+	 * timeout, nvme_suspend_queue will invoke free_irq for it and cause warning
+	 * 'Trying to free already-free IRQ xxx'
+	 */
+	nvmeq->cq_vector = cq_vector;
 	nvme_init_queue(nvmeq, qid);
 	result = queue_request_irq(nvmeq);
 	if (result < 0)
@@ -1487,13 +1494,13 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
 
 	return result;
 
- release_sq:
+release_sq:
+	nvmeq->cq_vector = -1;
 	dev->online_queues--;
 	adapter_delete_sq(dev, qid);
- release_cq:
+release_cq:
 	adapter_delete_cq(dev, qid);
- release_vector:
-	nvmeq->cq_vector = -1;
+out:
 	return result;
 }
 
-- 
2.7.4

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

* [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR
  2018-05-24  9:51 [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Jianchao Wang
@ 2018-05-24  9:51 ` Jianchao Wang
  2018-05-24 13:38   ` Keith Busch
  2018-05-24 13:36 ` [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Keith Busch
  2018-05-25  8:53 ` Christoph Hellwig
  2 siblings, 1 reply; 5+ messages in thread
From: Jianchao Wang @ 2018-05-24  9:51 UTC (permalink / raw)
  To: keith.busch, axboe, hch, sagi; +Cc: linux-nvme, linux-kernel

When allocate sq in nvme_create_queue return -EINTR, it means the
allocate sq command times out and is completed with NVME_REQ_CANCELLED.
At the moment, the controller has been disabled and admin request
queue has been quiesced. Don't send delete cq command, otherwise,
it will incur io hang.

Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
---
 drivers/nvme/host/pci.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 70b79f2..4ce1c89 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1478,7 +1478,15 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
 		goto out;
 
 	result = adapter_alloc_sq(dev, qid, nvmeq);
-	if (result < 0)
+	/*
+	 * If return -EINTR, it means the allocate sq command times out and is completed
+	 * with NVME_REQ_CANCELLED. At the time, the controller has been disabled
+	 * and admin request queue has been quiesced. So don't try to send delete cq
+	 * command any more.
+	 */
+	if (result == -EINTR)
+		goto out;
+	else if (result < 0)
 		goto release_cq;
 
 	/*
-- 
2.7.4

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

* Re: [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq
  2018-05-24  9:51 [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Jianchao Wang
  2018-05-24  9:51 ` [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR Jianchao Wang
@ 2018-05-24 13:36 ` Keith Busch
  2018-05-25  8:53 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2018-05-24 13:36 UTC (permalink / raw)
  To: Jianchao Wang; +Cc: keith.busch, axboe, hch, sagi, linux-kernel, linux-nvme

This looks fine.

Reviewed-by: Keith Busch <keith.busch@intel.com>

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

* Re: [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR
  2018-05-24  9:51 ` [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR Jianchao Wang
@ 2018-05-24 13:38   ` Keith Busch
  0 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2018-05-24 13:38 UTC (permalink / raw)
  To: Jianchao Wang; +Cc: keith.busch, axboe, hch, sagi, linux-kernel, linux-nvme

On Thu, May 24, 2018 at 05:51:34PM +0800, Jianchao Wang wrote:
>  	result = adapter_alloc_sq(dev, qid, nvmeq);
> -	if (result < 0)
> +	/*
> +	 * If return -EINTR, it means the allocate sq command times out and is completed
> +	 * with NVME_REQ_CANCELLED. At the time, the controller has been disabled
> +	 * and admin request queue has been quiesced. So don't try to send delete cq
> +	 * command any more.
> +	 */
> +	if (result == -EINTR)
> +		goto out;
> +	else if (result < 0)
>  		goto release_cq;

Since you're touching this part anyway, you'd really only want to goto
the release_cq if result is > 0.

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

* Re: [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq
  2018-05-24  9:51 [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Jianchao Wang
  2018-05-24  9:51 ` [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR Jianchao Wang
  2018-05-24 13:36 ` [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Keith Busch
@ 2018-05-25  8:53 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2018-05-25  8:53 UTC (permalink / raw)
  To: Jianchao Wang; +Cc: keith.busch, axboe, hch, sagi, linux-nvme, linux-kernel

Thanks,

applied to nvme-4.18.

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

end of thread, other threads:[~2018-05-25  8:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-24  9:51 [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Jianchao Wang
2018-05-24  9:51 ` [PATCH 2/2] nvme-pci: don't send delete cq command when allocate sq return -EINTR Jianchao Wang
2018-05-24 13:38   ` Keith Busch
2018-05-24 13:36 ` [PATCH 1/2] nvme-pci: set nvmeq->cq_vector after alloc cq/sq Keith Busch
2018-05-25  8:53 ` Christoph Hellwig

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).