All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] nvme: Fix PRP list calculation for non-4k system page size
@ 2015-03-24 22:26 Brian King
  2015-03-24 22:43 ` Keith Busch
  0 siblings, 1 reply; 5+ messages in thread
From: Brian King @ 2015-03-24 22:26 UTC (permalink / raw)



From: Murali Iyer <mniyer@us.ibm.com>

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 at us.ibm.com>
Signed-off-by: Brian King <brking at linux.vnet.ibm.com>
---

 drivers/block/nvme-core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN drivers/block/nvme-core.c~nvme_power drivers/block/nvme-core.c
--- linux-nvme/drivers/block/nvme-core.c~nvme_power	2015-03-24 17:12:09.912743224 -0500
+++ linux-nvme-bjking1/drivers/block/nvme-core.c	2015-03-24 17:16:13.414970447 -0500
@@ -503,12 +503,12 @@ int nvme_setup_prps(struct nvme_dev *dev
 	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;
 	__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)
_

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/1] nvme: Fix PRP list calculation for non-4k system page size
  2015-03-24 22:26 [PATCH 1/1] nvme: Fix PRP list calculation for non-4k system page size Brian King
@ 2015-03-24 22:43 ` Keith Busch
  2015-03-26 16:07   ` [PATCH v2 " Brian King
  0 siblings, 1 reply; 5+ messages in thread
From: Keith Busch @ 2015-03-24 22:43 UTC (permalink / raw)


On Tue, 24 Mar 2015, Brian King wrote:
> 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.

Darn, I thought we had this working. I must have just gotten lucky when
testing on an 8k page. Thanks for the fix.

> -	int offset = offset_in_page(dma_addr);
> +	u32 page_size = dev->page_size;
> +	int offset = dma_addr % page_size;

Trying to micro-optimize the io path to have fewer divisions. This should
work out the same if changed to:

 	int offset = dma_addr & (page_size - 1);

The page_size is always a power of two, but I don't think the compiler
knows that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] nvme: Fix PRP list calculation for non-4k system page size
  2015-03-24 22:43 ` Keith Busch
@ 2015-03-26 16:07   ` Brian King
  2015-03-26 16:19     ` Keith Busch
  0 siblings, 1 reply; 5+ messages in thread
From: Brian King @ 2015-03-26 16:07 UTC (permalink / raw)


From: Murali Iyer <mniyer@us.ibm.com>

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 at us.ibm.com>
Signed-off-by: Brian King <brking at linux.vnet.ibm.com>
---

 drivers/block/nvme-core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN drivers/block/nvme-core.c~nvme_power drivers/block/nvme-core.c
--- linux-nvme/drivers/block/nvme-core.c~nvme_power	2015-03-24 17:12:09.912743224 -0500
+++ linux-nvme-bjking1/drivers/block/nvme-core.c	2015-03-25 09:25:43.580260410 -0500
@@ -503,12 +503,12 @@ int nvme_setup_prps(struct nvme_dev *dev
 	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)
_

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] nvme: Fix PRP list calculation for non-4k system page size
  2015-03-26 16:07   ` [PATCH v2 " Brian King
@ 2015-03-26 16:19     ` Keith Busch
  2015-03-31 16:40       ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Keith Busch @ 2015-03-26 16:19 UTC (permalink / raw)


On Thu, 26 Mar 2015, Brian King wrote:
> From: Murali Iyer <mniyer at us.ibm.com>
>
> 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.

Thanks!

Acked-by: Keith Busch <keith.busch at intel.com>

> Signed-off-by: Murali Iyer <mniyer at us.ibm.com>
> Signed-off-by: Brian King <brking at linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] nvme: Fix PRP list calculation for non-4k system page size
  2015-03-26 16:19     ` Keith Busch
@ 2015-03-31 16:40       ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2015-03-31 16:40 UTC (permalink / raw)


On 03/26/2015 10:19 AM, Keith Busch wrote:
> On Thu, 26 Mar 2015, Brian King wrote:
>> From: Murali Iyer <mniyer at us.ibm.com>
>>
>> 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.
>
> Thanks!
>
> Acked-by: Keith Busch <keith.busch at intel.com>

Added for 4.1.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-31 16:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-24 22:26 [PATCH 1/1] nvme: Fix PRP list calculation for non-4k system page size Brian King
2015-03-24 22:43 ` Keith Busch
2015-03-26 16:07   ` [PATCH v2 " Brian King
2015-03-26 16:19     ` Keith Busch
2015-03-31 16:40       ` Jens Axboe

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.