All of lore.kernel.org
 help / color / mirror / Atom feed
* [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset
@ 2018-07-12 21:27 Scott Bauer
  2018-07-12 22:14 ` Derrick, Jonathan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Scott Bauer @ 2018-07-12 21:27 UTC (permalink / raw)
  To: stable; +Cc: Scott Bauer, Jon Derrick, Keith Busch

Commit 815c6704bf9f1c59f3a6be380a4032b9c57b12f1 upstream.

The controller memory buffer is remapped into a kernel address on each
reset, but the driver was setting the submission queue base address
only on the very first queue creation. The remapped address is likely to
change after a reset, so accessing the old address will hit a kernel bug.

This patch fixes that by setting the queue's CMB base address each time
the queue is created.

Fixes: f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset path")
Reported-by: Christian Black <christian.d.black@intel.com>
Cc: Jon Derrick <jonathan.derrick@intel.com>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Scott Bauer <scott.bauer@intel.com>
---
 drivers/nvme/host/pci.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 3d4724e38aa9..4cac4755abef 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1233,17 +1233,15 @@ static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues,
 static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq,
 				int qid, int depth)
 {
-	if (qid && dev->cmb && use_cmb_sqes && NVME_CMB_SQS(dev->cmbsz)) {
-		unsigned offset = (qid - 1) * roundup(SQ_SIZE(depth),
-						      dev->ctrl.page_size);
-		nvmeq->sq_dma_addr = dev->cmb_bus_addr + offset;
-		nvmeq->sq_cmds_io = dev->cmb + offset;
-	} else {
-		nvmeq->sq_cmds = dma_alloc_coherent(dev->dev, SQ_SIZE(depth),
-					&nvmeq->sq_dma_addr, GFP_KERNEL);
-		if (!nvmeq->sq_cmds)
-			return -ENOMEM;
-	}
+
+	/* CMB SQEs will be mapped before creation */
+	if (qid && dev->cmb && use_cmb_sqes && NVME_CMB_SQS(dev->cmbsz))
+		return 0;
+
+	nvmeq->sq_cmds = dma_alloc_coherent(dev->dev, SQ_SIZE(depth),
+					    &nvmeq->sq_dma_addr, GFP_KERNEL);
+	if (!nvmeq->sq_cmds)
+		return -ENOMEM;
 
 	return 0;
 }
@@ -1320,6 +1318,13 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
 	struct nvme_dev *dev = nvmeq->dev;
 	int result;
 
+	if (qid && dev->cmb && use_cmb_sqes && NVME_CMB_SQS(dev->cmbsz)) {
+		unsigned offset = (qid - 1) * roundup(SQ_SIZE(nvmeq->q_depth),
+						      dev->ctrl.page_size);
+		nvmeq->sq_dma_addr = dev->cmb_bus_addr + offset;
+		nvmeq->sq_cmds_io = dev->cmb + offset;
+	}
+
 	nvmeq->cq_vector = qid - 1;
 	result = adapter_alloc_cq(dev, qid, nvmeq);
 	if (result < 0)
-- 
2.17.1

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

* Re: [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset
  2018-07-12 21:27 [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset Scott Bauer
@ 2018-07-12 22:14 ` Derrick, Jonathan
  2018-07-13 12:01 ` Greg KH
  2018-07-15 10:21 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Derrick, Jonathan @ 2018-07-12 22:14 UTC (permalink / raw)
  To: Bauer, Scott, stable; +Cc: Busch, Keith

[-- Attachment #1: Type: text/plain, Size: 2853 bytes --]

Thank you, Scott

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

On Thu, 2018-07-12 at 15:27 -0600, Scott Bauer wrote:
> Commit 815c6704bf9f1c59f3a6be380a4032b9c57b12f1 upstream.
> 
> The controller memory buffer is remapped into a kernel address on
> each
> reset, but the driver was setting the submission queue base address
> only on the very first queue creation. The remapped address is likely
> to
> change after a reset, so accessing the old address will hit a kernel
> bug.
> 
> This patch fixes that by setting the queue's CMB base address each
> time
> the queue is created.
> 
> Fixes: f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset
> path")
> Reported-by: Christian Black <christian.d.black@intel.com>
> Cc: Jon Derrick <jonathan.derrick@intel.com>
> Signed-off-by: Keith Busch <keith.busch@intel.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Scott Bauer <scott.bauer@intel.com>
> ---
>  drivers/nvme/host/pci.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 3d4724e38aa9..4cac4755abef 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -1233,17 +1233,15 @@ static int nvme_cmb_qdepth(struct nvme_dev
> *dev, int nr_io_queues,
>  static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct
> nvme_queue *nvmeq,
>  				int qid, int depth)
>  {
> -	if (qid && dev->cmb && use_cmb_sqes && NVME_CMB_SQS(dev-
> >cmbsz)) {
> -		unsigned offset = (qid - 1) *
> roundup(SQ_SIZE(depth),
> -						      dev-
> >ctrl.page_size);
> -		nvmeq->sq_dma_addr = dev->cmb_bus_addr + offset;
> -		nvmeq->sq_cmds_io = dev->cmb + offset;
> -	} else {
> -		nvmeq->sq_cmds = dma_alloc_coherent(dev->dev,
> SQ_SIZE(depth),
> -					&nvmeq->sq_dma_addr,
> GFP_KERNEL);
> -		if (!nvmeq->sq_cmds)
> -			return -ENOMEM;
> -	}
> +
> +	/* CMB SQEs will be mapped before creation */
> +	if (qid && dev->cmb && use_cmb_sqes && NVME_CMB_SQS(dev-
> >cmbsz))
> +		return 0;
> +
> +	nvmeq->sq_cmds = dma_alloc_coherent(dev->dev,
> SQ_SIZE(depth),
> +					    &nvmeq->sq_dma_addr,
> GFP_KERNEL);
> +	if (!nvmeq->sq_cmds)
> +		return -ENOMEM;
>  
>  	return 0;
>  }
> @@ -1320,6 +1318,13 @@ static int nvme_create_queue(struct nvme_queue
> *nvmeq, int qid)
>  	struct nvme_dev *dev = nvmeq->dev;
>  	int result;
>  
> +	if (qid && dev->cmb && use_cmb_sqes && NVME_CMB_SQS(dev-
> >cmbsz)) {
> +		unsigned offset = (qid - 1) * roundup(SQ_SIZE(nvmeq-
> >q_depth),
> +						      dev-
> >ctrl.page_size);
> +		nvmeq->sq_dma_addr = dev->cmb_bus_addr + offset;
> +		nvmeq->sq_cmds_io = dev->cmb + offset;
> +	}
> +
>  	nvmeq->cq_vector = qid - 1;
>  	result = adapter_alloc_cq(dev, qid, nvmeq);
>  	if (result < 0)

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

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

* Re: [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset
  2018-07-12 21:27 [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset Scott Bauer
  2018-07-12 22:14 ` Derrick, Jonathan
@ 2018-07-13 12:01 ` Greg KH
  2018-07-13 15:51   ` Keith Busch
  2018-07-15 10:21 ` Greg KH
  2 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2018-07-13 12:01 UTC (permalink / raw)
  To: Scott Bauer; +Cc: stable, Jon Derrick, Keith Busch

On Thu, Jul 12, 2018 at 03:27:17PM -0600, Scott Bauer wrote:
> Commit 815c6704bf9f1c59f3a6be380a4032b9c57b12f1 upstream.
> 
> The controller memory buffer is remapped into a kernel address on each
> reset, but the driver was setting the submission queue base address
> only on the very first queue creation. The remapped address is likely to
> change after a reset, so accessing the old address will hit a kernel bug.
> 
> This patch fixes that by setting the queue's CMB base address each time
> the queue is created.
> 
> Fixes: f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset path")
> Reported-by: Christian Black <christian.d.black@intel.com>
> Cc: Jon Derrick <jonathan.derrick@intel.com>
> Signed-off-by: Keith Busch <keith.busch@intel.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Scott Bauer <scott.bauer@intel.com>
> Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>
> ---
>  drivers/nvme/host/pci.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)

"backport" to where?  What kernel tree(s) do you want this applied to?

I need a hint please...

thanks,

greg k-h

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

* Re: [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset
  2018-07-13 12:01 ` Greg KH
@ 2018-07-13 15:51   ` Keith Busch
  0 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2018-07-13 15:51 UTC (permalink / raw)
  To: Greg KH; +Cc: Scott Bauer, stable, Jon Derrick

On Fri, Jul 13, 2018 at 02:01:04PM +0200, Greg KH wrote:
> On Thu, Jul 12, 2018 at 03:27:17PM -0600, Scott Bauer wrote:
> > Commit 815c6704bf9f1c59f3a6be380a4032b9c57b12f1 upstream.
> > 
> > The controller memory buffer is remapped into a kernel address on each
> > reset, but the driver was setting the submission queue base address
> > only on the very first queue creation. The remapped address is likely to
> > change after a reset, so accessing the old address will hit a kernel bug.
> > 
> > This patch fixes that by setting the queue's CMB base address each time
> > the queue is created.
> > 
> > Fixes: f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset path")
> > Reported-by: Christian Black <christian.d.black@intel.com>
> > Cc: Jon Derrick <jonathan.derrick@intel.com>
> > Signed-off-by: Keith Busch <keith.busch@intel.com>
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > Signed-off-by: Scott Bauer <scott.bauer@intel.com>
> > Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>
> > ---
> >  drivers/nvme/host/pci.c | 27 ++++++++++++++++-----------
> >  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> "backport" to where?  What kernel tree(s) do you want this applied to?
> 
> I need a hint please...

Sorry about that. 4.9 and 4.14 are the applicable targets.

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

* Re: [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset
  2018-07-12 21:27 [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset Scott Bauer
  2018-07-12 22:14 ` Derrick, Jonathan
  2018-07-13 12:01 ` Greg KH
@ 2018-07-15 10:21 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2018-07-15 10:21 UTC (permalink / raw)
  To: Scott Bauer; +Cc: stable, Jon Derrick, Keith Busch

On Thu, Jul 12, 2018 at 03:27:17PM -0600, Scott Bauer wrote:
> Commit 815c6704bf9f1c59f3a6be380a4032b9c57b12f1 upstream.
> 
> The controller memory buffer is remapped into a kernel address on each
> reset, but the driver was setting the submission queue base address
> only on the very first queue creation. The remapped address is likely to
> change after a reset, so accessing the old address will hit a kernel bug.
> 
> This patch fixes that by setting the queue's CMB base address each time
> the queue is created.
> 
> Fixes: f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset path")
> Reported-by: Christian Black <christian.d.black@intel.com>
> Cc: Jon Derrick <jonathan.derrick@intel.com>
> Signed-off-by: Keith Busch <keith.busch@intel.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Scott Bauer <scott.bauer@intel.com>
> Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>
> ---
>  drivers/nvme/host/pci.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)

Now queued up, thanks.

greg k-h

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

end of thread, other threads:[~2018-07-15 10:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12 21:27 [BACKPORT PATCH] nvme-pci: Remap CMB SQ entries on every controller reset Scott Bauer
2018-07-12 22:14 ` Derrick, Jonathan
2018-07-13 12:01 ` Greg KH
2018-07-13 15:51   ` Keith Busch
2018-07-15 10:21 ` Greg KH

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.