nvme-pci: Remap CMB SQ entries on every controller reset
Subsystems (2)
PATCH 4/4 nvme-pci: Remap CMB SQ entries on every controller reset
In reply to a message not in the archiveThe 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.
Cherry-pick from upstream commit 815c6704bf9f ("nvme-pci: Remap CMB SQ entries on every controller reset")
--- drivers/nvme/host/pci.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/nvme/host/pci.c +17 -12
@@ -1174,18 +1174,16 @@ static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq, int sq_idx, int depth) { int qid = nvmeq->sq[sq_idx].id; -if (qid && dev->cmb && use_cmb_sqes && (dev->cmbsz &NVME_CMBSZ_SQS )) { -unsigned offset = (qid -1 ) *roundup (SQ_SIZE (depth), - dev->ctrl.page_size); - nvmeq->sq[sq_idx].sq_dma_addr = dev->cmb_bus_addr + offset; - nvmeq->sq[sq_idx].sq_cmds_io = dev->cmb + offset; - }else { - nvmeq->sq[sq_idx].sq_cmds =dma_alloc_coherent (dev->dev, -SQ_SIZE (depth), - &nvmeq->sq[sq_idx].sq_dma_addr,GFP_KERNEL ); -if (!nvmeq->sq[sq_idx].sq_cmds) -return -ENOMEM ; - } + +/* CMB SQEs will be mapped before creation */ +if (qid && dev->cmb && use_cmb_sqes && (dev->cmbsz &NVME_CMBSZ_SQS )) +return 0 ; + + nvmeq->sq[sq_idx].sq_cmds =dma_alloc_coherent (dev->dev,SQ_SIZE (depth), + &nvmeq->sq[sq_idx].sq_dma_addr, +GFP_KERNEL ); +if (!nvmeq->sq[sq_idx].sq_cmds) +return -ENOMEM ;return 0 ; }
@@ -1280,6 +1278,13 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)struct nvme_dev *dev = nvmeq->dev;int result, i; +if (dev->cmb && use_cmb_sqes && (dev->cmbsz &NVME_CMBSZ_SQS )) { +unsigned offset = (qid -1 ) *roundup (SQ_SIZE (nvmeq->q_depth), + dev->ctrl.page_size); + nvmeq->sq[0 ].sq_dma_addr = dev->cmb_bus_addr + offset; + nvmeq->sq[0 ].sq_cmds_io = dev->cmb + offset; + } + nvmeq->cq_vector = qid -1 ; result =adapter_alloc_cq (dev, nvmeq->cq_id, nvmeq);if (result <0 )
Signature · 1 line
2.11.0
Quoted 8 lines · On Mon, Aug 13, 2018 at 03:42:38PM +0800, [email protected] wrote:
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.
Quoted 7 lines
Cherry-pick from upstream commit
815c6704bf9f("nvme-pci: Remap CMB SQ entries on every controller reset")Fixes f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset path")Reported-by Christian Black <[email protected]>Cc Jon Derrick <[email protected]>Cc <[email protected]> # 4.9+
This one is already in 4.9-stable.
Quoted 10 lines · On Mon, Aug 13, 2018 at 03:42:38PM +0800, [email protected] wrote:
Quoted 8 lines
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.
Quoted 8 lines
Quoted 7 lines
Cherry-pick from upstream commit
815c6704bf9f("nvme-pci: Remap CMB SQ entries on every controller reset")Fixes f63572dff1421 ("nvme: unmap CMB and remove sysfs file in reset path")Reported-by Christian Black <[email protected]>Cc Jon Derrick <[email protected]>Cc <[email protected]> # 4.9+This one is already in 4.9-stable.
Sorry, Keith. I was intending to send to internal maillist, but sent to external one by accident. Please ignore it.
Cheers,
Gavin