blob: cbb7ec0f7de2c224209c2f072336fb3f379fcbb9 [file] [log] [blame]
From cedefa5208be706ff64d572dfecbbb917a5fe2d8 Mon Sep 17 00:00:00 2001
From: Kevin Hao <>
Date: Fri, 18 Oct 2019 10:53:14 +0800
Subject: [PATCH] nvme-pci: Set the prp2 correctly when using more than 4k page
commit a4f40484e7f1dff56bb9f286cc59ffa36e0259eb upstream.
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")
Reviewed-by: Christoph Hellwig <>
Signed-off-by: Kevin Hao <>
Signed-off-by: Keith Busch <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 13ab059dc110..c9f5983a9f82 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -786,7 +786,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))