Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1313105 > unrolled thread

[PATH v2] NVMe: init nvme queue before enabling irq

Started byWenbo Wang <mail_weber_wang@163.com>
First post2016-01-20 11:50 +0100
Last post2016-01-20 18:20 +0100
Articles 6 — 6 participants

Back to article view | Back to linux.kernel


Contents

  [PATH v2] NVMe: init nvme queue before enabling irq Wenbo Wang <mail_weber_wang@163.com> - 2016-01-20 11:50 +0100
    Re: [PATH v2] NVMe: init nvme queue before enabling irq Sagi Grimberg <sagig@dev.mellanox.co.il> - 2016-01-20 13:40 +0100
    Re: [PATH v2] NVMe: init nvme queue before enabling irq Keith Busch <keith.busch@intel.com> - 2016-01-20 16:00 +0100
    Re: [PATH v2] NVMe: init nvme queue before enabling irq Johannes Thumshirn <jthumshirn@suse.de> - 2016-01-20 16:20 +0100
    Re: [PATH v2] NVMe: init nvme queue before enabling irq Greg KH <gregkh@linuxfoundation.org> - 2016-01-20 18:20 +0100
      Re: [PATH v2] NVMe: init nvme queue before enabling irq Jens Axboe <axboe@fb.com> - 2016-01-20 18:20 +0100

#1313105 — [PATH v2] NVMe: init nvme queue before enabling irq

FromWenbo Wang <mail_weber_wang@163.com>
Date2016-01-20 11:50 +0100
Subject[PATH v2] NVMe: init nvme queue before enabling irq
Message-ID<qSYuT-5ao-35@gated-at.bofh.it>
From: Wenbo Wang <wenbo.wang@memblaze.com>

During reset process, the nvme_dev->bar (ioremapped) may change,
so nvmeq->q_db shall be also updated by nvme_init_queue().

Currently nvmeq irq is enabled before queue init, so a spurious
interrupt triggered nvme_process_cq may access nvmeq->q_db just
before it is updated, this could cause kernel panic.

Signed-off-by: Wenbo Wang <wenbo.wang@memblaze.com>
Reviewed-by: Wenwei Tao <wenwei.tao@memblaze.com>
---
 drivers/nvme/host/pci.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index f5c0e26..3371c18 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1529,9 +1529,6 @@ static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
 	snprintf(nvmeq->irqname, sizeof(nvmeq->irqname), "nvme%dq%d",
 			dev->instance, qid);
 	spin_lock_init(&nvmeq->q_lock);
-	nvmeq->cq_head = 0;
-	nvmeq->cq_phase = 1;
-	nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
 	nvmeq->q_depth = depth;
 	nvmeq->qid = qid;
 	nvmeq->cq_vector = -1;
@@ -1590,11 +1587,17 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
 	if (result < 0)
 		goto release_cq;
 
+	/*
+	 * Init queue door bell ioremap address before enabling irq, if not,
+	 * a spurious interrupt triggered nvme_process_cq may access invalid
+	 * address
+	 */
+	nvme_init_queue(nvmeq, qid);
+
 	result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
 	if (result < 0)
 		goto release_sq;
 
-	nvme_init_queue(nvmeq, qid);
 	return result;
 
  release_sq:
@@ -1789,6 +1792,8 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
 	if (result)
 		goto free_nvmeq;
 
+	nvme_init_queue(nvmeq, 0);
+
 	nvmeq->cq_vector = 0;
 	result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
 	if (result) {
@@ -3164,7 +3169,6 @@ static void nvme_probe_work(struct work_struct *work)
 		goto disable;
 	}
 
-	nvme_init_queue(dev->queues[0], 0);
 	result = nvme_alloc_admin_tags(dev);
 	if (result)
 		goto disable;
-- 
1.8.3.1

[toc] | [next] | [standalone]


#1313193

FromSagi Grimberg <sagig@dev.mellanox.co.il>
Date2016-01-20 13:40 +0100
Message-ID<qT0dm-6mw-39@gated-at.bofh.it>
In reply to#1313105
> From: Wenbo Wang <wenbo.wang@memblaze.com>
>
> During reset process, the nvme_dev->bar (ioremapped) may change,
> so nvmeq->q_db shall be also updated by nvme_init_queue().
>
> Currently nvmeq irq is enabled before queue init, so a spurious
> interrupt triggered nvme_process_cq may access nvmeq->q_db just
> before it is updated, this could cause kernel panic.
>
> Signed-off-by: Wenbo Wang <wenbo.wang@memblaze.com>
> Reviewed-by: Wenwei Tao <wenwei.tao@memblaze.com>

You should add Cc: stable@vger.kernel.org here,
git-send-email will take care of the CC for you.

[toc] | [prev] | [next] | [standalone]


#1313271

FromKeith Busch <keith.busch@intel.com>
Date2016-01-20 16:00 +0100
Message-ID<qT2oP-7Xe-25@gated-at.bofh.it>
In reply to#1313105
On Wed, Jan 20, 2016 at 05:48:35AM -0500, Wenbo Wang wrote:
> From: Wenbo Wang <wenbo.wang@memblaze.com>
> 
> During reset process, the nvme_dev->bar (ioremapped) may change,
> so nvmeq->q_db shall be also updated by nvme_init_queue().
> 
> Currently nvmeq irq is enabled before queue init, so a spurious
> interrupt triggered nvme_process_cq may access nvmeq->q_db just
> before it is updated, this could cause kernel panic.
> 
> Signed-off-by: Wenbo Wang <wenbo.wang@memblaze.com>
> Reviewed-by: Wenwei Tao <wenwei.tao@memblaze.com>

Looks good, thanks for the fix.

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

[toc] | [prev] | [next] | [standalone]


#1313290

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2016-01-20 16:20 +0100
Message-ID<qT2Ib-8li-45@gated-at.bofh.it>
In reply to#1313105
On Wed, Jan 20, 2016 at 05:48:35AM -0500, Wenbo Wang wrote:
> From: Wenbo Wang <wenbo.wang@memblaze.com>
> 
> During reset process, the nvme_dev->bar (ioremapped) may change,
> so nvmeq->q_db shall be also updated by nvme_init_queue().
> 
> Currently nvmeq irq is enabled before queue init, so a spurious
> interrupt triggered nvme_process_cq may access nvmeq->q_db just
> before it is updated, this could cause kernel panic.
> 
> Signed-off-by: Wenbo Wang <wenbo.wang@memblaze.com>
> Reviewed-by: Wenwei Tao <wenwei.tao@memblaze.com>
> ---
>  drivers/nvme/host/pci.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index f5c0e26..3371c18 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -1529,9 +1529,6 @@ static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
>  	snprintf(nvmeq->irqname, sizeof(nvmeq->irqname), "nvme%dq%d",
>  			dev->instance, qid);
>  	spin_lock_init(&nvmeq->q_lock);
> -	nvmeq->cq_head = 0;
> -	nvmeq->cq_phase = 1;
> -	nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
>  	nvmeq->q_depth = depth;
>  	nvmeq->qid = qid;
>  	nvmeq->cq_vector = -1;
> @@ -1590,11 +1587,17 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
>  	if (result < 0)
>  		goto release_cq;
>  
> +	/*
> +	 * Init queue door bell ioremap address before enabling irq, if not,
> +	 * a spurious interrupt triggered nvme_process_cq may access invalid
> +	 * address
> +	 */
> +	nvme_init_queue(nvmeq, qid);
> +
>  	result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
>  	if (result < 0)
>  		goto release_sq;
>  
> -	nvme_init_queue(nvmeq, qid);
>  	return result;
>  
>   release_sq:
> @@ -1789,6 +1792,8 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
>  	if (result)
>  		goto free_nvmeq;
>  
> +	nvme_init_queue(nvmeq, 0);
> +
>  	nvmeq->cq_vector = 0;
>  	result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
>  	if (result) {
> @@ -3164,7 +3169,6 @@ static void nvme_probe_work(struct work_struct *work)
>  		goto disable;
>  	}
>  
> -	nvme_init_queue(dev->queues[0], 0);
>  	result = nvme_alloc_admin_tags(dev);
>  	if (result)
>  		goto disable;
> -- 
> 1.8.3.1
> 
> 
> 
> _______________________________________________
> Linux-nvme mailing list
> Linux-nvme@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-nvme



Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>

-- 
Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

[toc] | [prev] | [next] | [standalone]


#1313386

FromGreg KH <gregkh@linuxfoundation.org>
Date2016-01-20 18:20 +0100
Message-ID<qT4Ah-1fm-11@gated-at.bofh.it>
In reply to#1313105
On Wed, Jan 20, 2016 at 05:48:35AM -0500, Wenbo Wang wrote:
> From: Wenbo Wang <wenbo.wang@memblaze.com>
> 
> During reset process, the nvme_dev->bar (ioremapped) may change,
> so nvmeq->q_db shall be also updated by nvme_init_queue().
> 
> Currently nvmeq irq is enabled before queue init, so a spurious
> interrupt triggered nvme_process_cq may access nvmeq->q_db just
> before it is updated, this could cause kernel panic.
> 
> Signed-off-by: Wenbo Wang <wenbo.wang@memblaze.com>
> Reviewed-by: Wenwei Tao <wenwei.tao@memblaze.com>
> ---
>  drivers/nvme/host/pci.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>

[toc] | [prev] | [next] | [standalone]


#1313389

FromJens Axboe <axboe@fb.com>
Date2016-01-20 18:20 +0100
Message-ID<qT4Ai-1fm-25@gated-at.bofh.it>
In reply to#1313386
On 01/20/2016 10:12 AM, Greg KH wrote:
> On Wed, Jan 20, 2016 at 05:48:35AM -0500, Wenbo Wang wrote:
>> From: Wenbo Wang <wenbo.wang@memblaze.com>
>>
>> During reset process, the nvme_dev->bar (ioremapped) may change,
>> so nvmeq->q_db shall be also updated by nvme_init_queue().
>>
>> Currently nvmeq irq is enabled before queue init, so a spurious
>> interrupt triggered nvme_process_cq may access nvmeq->q_db just
>> before it is updated, this could cause kernel panic.
>>
>> Signed-off-by: Wenbo Wang <wenbo.wang@memblaze.com>
>> Reviewed-by: Wenwei Tao <wenwei.tao@memblaze.com>
>> ---
>>   drivers/nvme/host/pci.c | 14 +++++++++-----
>>   1 file changed, 9 insertions(+), 5 deletions(-)
>
> <formletter>
>
> This is not the correct way to submit patches for inclusion in the
> stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
> for how to do this properly.

I'll mark it stable when adding, just ignore it for now.

-- 
Jens Axboe

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web