Skip to contentSkip to conversation

nvme-pci: Set the prp2 correctly when using more than 4k page

PATCH Superseded Kevin Hao 3 participants 7 messages Oct 17, 2019 – Oct 18, 2019 NVMe

lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

PATCH 1/1 nvme-pci: Set the prp2 correctly when using more than 4k page

In the current code, the nvme is using a fixed 4k PRP entry size, but if the kernel use a page size which is more than 4k, we should consider the situation that the bv_offset may be larger than the dev->ctrl.page_size. Otherwise we may miss setting the prp2 and then cause the command can't be executed correctly.

Fixes dff824b2aadb ("nvme-pci: optimize mapping of small single segment requests")
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index bb88681f4dc3..fa647608c907 100644
@@ -773,7 +773,8 @@ static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev,
 		struct bio_vec *bv)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
-	unsigned int first_prp_len = dev->ctrl.page_size - bv->bv_offset;
+	unsigned int offset = bv->bv_offset % dev->ctrl.page_size;
+	unsigned int first_prp_len = dev->ctrl.page_size - offset;
 
 	iod->first_dma = dma_map_bvec(dev->dev, bv, rq_dma_dir(req), 0);
 	if (dma_mapping_error(dev->dev, iod->first_dma))
Signature · 7 lines
2.14.4


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
maintainer
#2 lore raw

drivers/nvme/host/pci.c static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev, · line 776

Quoted 1 line · Kevin Hao
drivers/nvme/host/pci.c +1 -0
+	unsigned int offset = bv->bv_offset % dev->ctrl.page_size;

Can we do this without the modulo in the io path? The page_size is a power of 2, so this should work:

	unsigned int offset = bv->bv_offset & (dev->ctrl.page_size - 1);

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author
#3 lore raw
Quoted 7 lines · Keith Busch

drivers/nvme/host/pci.c static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev, · line 776

Quoted 1 line · Kevin Hao
drivers/nvme/host/pci.c +1 -0
+	unsigned int offset = bv->bv_offset % dev->ctrl.page_size;

Can we do this without the modulo in the io path? The page_size is a power of 2, so this should work:

	unsigned int offset = bv->bv_offset & (dev->ctrl.page_size - 1);

Sure. V2 is coming soon.

Thanks,
Kevin

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author
#4 lore raw

PATCH v2 1/1 nvme-pci: Set the prp2 correctly when using more than 4k page

In the current code, the nvme is using a fixed 4k PRP entry size, but if the kernel use a page size which is more than 4k, we should consider the situation that the bv_offset may be larger than the dev->ctrl.page_size. Otherwise we may miss setting the prp2 and then cause the command can't be executed correctly.

Fixes dff824b2aadb ("nvme-pci: optimize mapping of small single segment requests")

---
v2: Avoid using modulo as suggested by Keith Busch.

 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index bb88681f4dc3..c7ba2b16a93b 100644
@@ -773,7 +773,8 @@ static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev,
 		struct bio_vec *bv)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
-	unsigned int first_prp_len = dev->ctrl.page_size - bv->bv_offset;
+	unsigned int offset = bv->bv_offset & (dev->ctrl.page_size - 1);
+	unsigned int first_prp_len = dev->ctrl.page_size - offset;
 
 	iod->first_dma = dma_map_bvec(dev->dev, bv, rq_dma_dir(req), 0);
 	if (dma_mapping_error(dev->dev, iod->first_dma))
Signature · 7 lines
2.14.4


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme