* [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page
@ 2019-10-17 7:34 Kevin Hao
2019-10-17 14:55 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Kevin Hao @ 2019-10-17 7:34 UTC (permalink / raw)
To: linux-nvme; +Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
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")
Cc: stable@vger.kernel.org
Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
drivers/nvme/host/pci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index bb88681f4dc3..fa647608c907 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -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))
--
2.14.4
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page
2019-10-17 7:34 [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page Kevin Hao
@ 2019-10-17 14:55 ` Christoph Hellwig
2019-10-17 17:38 ` Keith Busch
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2019-10-17 14:55 UTC (permalink / raw)
To: Kevin Hao
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, linux-nvme, Sagi Grimberg
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page
2019-10-17 14:55 ` Christoph Hellwig
@ 2019-10-17 17:38 ` Keith Busch
2019-10-18 0:59 ` Kevin Hao
0 siblings, 1 reply; 7+ messages in thread
From: Keith Busch @ 2019-10-17 17:38 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Jens Axboe, Kevin Hao, Sagi Grimberg, linux-nvme
On 10/17/19, 1:40 AM, "Kevin Hao" <haokexin@gmail.com> wrote:
> + 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
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page
2019-10-17 17:38 ` Keith Busch
@ 2019-10-18 0:59 ` Kevin Hao
2019-10-18 2:53 ` [PATCH v2] " Kevin Hao
0 siblings, 1 reply; 7+ messages in thread
From: Kevin Hao @ 2019-10-18 0:59 UTC (permalink / raw)
To: Keith Busch; +Cc: Jens Axboe, Christoph Hellwig, linux-nvme, Sagi Grimberg
[-- Attachment #1.1: Type: text/plain, Size: 426 bytes --]
On Thu, Oct 17, 2019 at 11:38:07AM -0600, Keith Busch wrote:
> On 10/17/19, 1:40 AM, "Kevin Hao" <haokexin@gmail.com> wrote:
> > + 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
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 158 bytes --]
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] nvme-pci: Set the prp2 correctly when using more than 4k page
2019-10-18 0:59 ` Kevin Hao
@ 2019-10-18 2:53 ` Kevin Hao
2019-10-18 6:48 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Kevin Hao @ 2019-10-18 2:53 UTC (permalink / raw)
To: linux-nvme; +Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
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")
Cc: stable@vger.kernel.org
Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
v2: Avoid using modulo as suggested by Keith Busch.
drivers/nvme/host/pci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index bb88681f4dc3..c7ba2b16a93b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -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))
--
2.14.4
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] nvme-pci: Set the prp2 correctly when using more than 4k page
2019-10-18 2:53 ` [PATCH v2] " Kevin Hao
@ 2019-10-18 6:48 ` Christoph Hellwig
2019-10-18 14:10 ` Keith Busch
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2019-10-18 6:48 UTC (permalink / raw)
To: Kevin Hao
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, linux-nvme, Sagi Grimberg
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] nvme-pci: Set the prp2 correctly when using more than 4k page
2019-10-18 6:48 ` Christoph Hellwig
@ 2019-10-18 14:10 ` Keith Busch
0 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2019-10-18 14:10 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Keith Busch, Jens Axboe, Kevin Hao, Sagi Grimberg, linux-nvme
Applied to nvme-5.4, thanks.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-10-18 14:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17 7:34 [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page Kevin Hao
2019-10-17 14:55 ` Christoph Hellwig
2019-10-17 17:38 ` Keith Busch
2019-10-18 0:59 ` Kevin Hao
2019-10-18 2:53 ` [PATCH v2] " Kevin Hao
2019-10-18 6:48 ` Christoph Hellwig
2019-10-18 14:10 ` Keith Busch
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.