[Vivid,1/1] nvme: Fix PRP list calculation for non-4k system page size

Message ID d0e3fbe6a2ae3442c9c25f0486c9cde5fe009ba6.1428686212.git.leann.ogasawara@canonical.com
State New
Headers show

Commit Message

Leann Ogasawara April 10, 2015, 5:28 p.m.
From: Murali Iyer <mniyer@us.ibm.com>

BugLink: http://bugs.launchpad.net/bugs/1442186

PRP list calculation is supposed to be based on device's page size.
Systems with page size larger than device's page size cause corruption
to the name space as well as system memory with out this fix.
Systems like x86 might not experience this issue because it uses
PAGE_SIZE of 4K where as powerpc uses PAGE_SIZE of 64k while NVMe device's
page size varies depending upon the vendor.

Signed-off-by: Murali Iyer <mniyer@us.ibm.com>
Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
Acked-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
(cherry picked from commit f137e0f15101c0a0ff8a5d956042e50247f1fef9 in
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next)
Signed-off-by: Leann Ogasawara <leann.ogasawara@canonical.com>
---
 drivers/block/nvme-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tim Gardner April 10, 2015, 5:37 p.m. | #1

Kamal Mostafa April 10, 2015, 5:38 p.m. | #2

Brad Figg April 10, 2015, 5:39 p.m. | #3
On Fri, Apr 10, 2015 at 10:28:15AM -0700, leann.ogasawara@canonical.com wrote:
> From: Murali Iyer <mniyer@us.ibm.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1442186
> 
> PRP list calculation is supposed to be based on device's page size.
> Systems with page size larger than device's page size cause corruption
> to the name space as well as system memory with out this fix.
> Systems like x86 might not experience this issue because it uses
> PAGE_SIZE of 4K where as powerpc uses PAGE_SIZE of 64k while NVMe device's
> page size varies depending upon the vendor.
> 
> Signed-off-by: Murali Iyer <mniyer@us.ibm.com>
> Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
> Acked-by: Keith Busch <keith.busch@intel.com>
> Signed-off-by: Jens Axboe <axboe@fb.com>
> (cherry picked from commit f137e0f15101c0a0ff8a5d956042e50247f1fef9 in
> git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next)
> Signed-off-by: Leann Ogasawara <leann.ogasawara@canonical.com>
> ---
>  drivers/block/nvme-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
> index d826bf3..3251e93 100644
> --- a/drivers/block/nvme-core.c
> +++ b/drivers/block/nvme-core.c
> @@ -467,12 +467,12 @@ int nvme_setup_prps(struct nvme_dev *dev, struct nvme_iod *iod, int total_len,
>  	struct scatterlist *sg = iod->sg;
>  	int dma_len = sg_dma_len(sg);
>  	u64 dma_addr = sg_dma_address(sg);
> -	int offset = offset_in_page(dma_addr);
> +	u32 page_size = dev->page_size;
> +	int offset = dma_addr & (page_size - 1);
>  	__le64 *prp_list;
>  	__le64 **list = iod_list(iod);
>  	dma_addr_t prp_dma;
>  	int nprps, i;
> -	u32 page_size = dev->page_size;
>  
>  	length -= (page_size - offset);
>  	if (length <= 0)
> -- 
> 2.1.4
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
Chris J Arges April 10, 2015, 5:44 p.m. | #4
On 04/10/2015 12:28 PM, leann.ogasawara@canonical.com wrote:
> From: Murali Iyer <mniyer@us.ibm.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1442186
> 
> PRP list calculation is supposed to be based on device's page size.
> Systems with page size larger than device's page size cause corruption
> to the name space as well as system memory with out this fix.
> Systems like x86 might not experience this issue because it uses
> PAGE_SIZE of 4K where as powerpc uses PAGE_SIZE of 64k while NVMe device's
> page size varies depending upon the vendor.
> 
> Signed-off-by: Murali Iyer <mniyer@us.ibm.com>
> Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
> Acked-by: Keith Busch <keith.busch@intel.com>
> Signed-off-by: Jens Axboe <axboe@fb.com>
> (cherry picked from commit f137e0f15101c0a0ff8a5d956042e50247f1fef9 in
> git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next)
> Signed-off-by: Leann Ogasawara <leann.ogasawara@canonical.com>
> ---
>  drivers/block/nvme-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
> index d826bf3..3251e93 100644
> --- a/drivers/block/nvme-core.c
> +++ b/drivers/block/nvme-core.c
> @@ -467,12 +467,12 @@ int nvme_setup_prps(struct nvme_dev *dev, struct nvme_iod *iod, int total_len,
>  	struct scatterlist *sg = iod->sg;
>  	int dma_len = sg_dma_len(sg);
>  	u64 dma_addr = sg_dma_address(sg);
> -	int offset = offset_in_page(dma_addr);
> +	u32 page_size = dev->page_size;
> +	int offset = dma_addr & (page_size - 1);
>  	__le64 *prp_list;
>  	__le64 **list = iod_list(iod);
>  	dma_addr_t prp_dma;
>  	int nprps, i;
> -	u32 page_size = dev->page_size;
>  
>  	length -= (page_size - offset);
>  	if (length <= 0)
>

Patch

diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index d826bf3..3251e93 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -467,12 +467,12 @@  int nvme_setup_prps(struct nvme_dev *dev, struct nvme_iod *iod, int total_len,
 	struct scatterlist *sg = iod->sg;
 	int dma_len = sg_dma_len(sg);
 	u64 dma_addr = sg_dma_address(sg);
-	int offset = offset_in_page(dma_addr);
+	u32 page_size = dev->page_size;
+	int offset = dma_addr & (page_size - 1);
 	__le64 *prp_list;
 	__le64 **list = iod_list(iod);
 	dma_addr_t prp_dma;
 	int nprps, i;
-	u32 page_size = dev->page_size;
 
 	length -= (page_size - offset);
 	if (length <= 0)