Skip to contentSkip to conversation

nvme: Fix PRP list pointer arithmetic for chained transfers

PATCH In review Prashant Kamble 2 participants 3 messages May 18 – May 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: Fix PRP list pointer arithmetic for chained transfers

The PRP setup code advances prp_pool using u64 pointer arithmetic:

        prp_pool += page_size;

This increments the pointer by page_size * sizeof(u64) bytes instead of page_size bytes, resulting in invalid PRP list addresses when multiple PRP list pages are required.

The issue becomes visible for large transfers, typically above 2 MiB when MDTS > 9.

Fix it by using byte-wise pointer arithmetic when advancing to the next PRP list page.

---
 drivers/nvme/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/nvme.c +1 -1
index 2b14437f69c..3ce98de1a5c 100644
@@ -94,7 +94,7 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2,
 			*(prp_pool + i) = cpu_to_le64((ulong)prp_pool +
 					page_size);
 			i = 0;
-			prp_pool += page_size;
+			prp_pool = (u64 *)((uintptr_t)prp_pool + page_size);
 		}
 		*(prp_pool + i++) = cpu_to_le64(dma_addr);
 		dma_addr += page_size;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Prashant Kamble

The PRP setup code advances prp_pool using u64 pointer arithmetic:

         prp_pool += page_size;

This increments the pointer by page_size * sizeof(u64) bytes instead of page_size bytes, resulting in invalid PRP list addresses when multiple PRP list pages are required.

The issue becomes visible for large transfers, typically above 2 MiB when MDTS > 9.

Fix it by using byte-wise pointer arithmetic when advancing to the next PRP list page.

---
  drivers/nvme/nvme.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/nvme.c +0 -0
index 2b14437f69c..3ce98de1a5c 100644

drivers/nvme/nvme.c static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2, · line 100

Quoted 8 lines
drivers/nvme/nvme.c +1 -1
@@ -94,7 +94,7 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2,
  			*(prp_pool + i) = cpu_to_le64((ulong)prp_pool +
  					page_size);
  			i = 0;
-			prp_pool += page_size;
+			prp_pool = (u64 *)((uintptr_t)prp_pool + page_size);
  		}
  		*(prp_pool + i++) = cpu_to_le64(dma_addr);
  		dma_addr += page_size;

Thanks,
Neil

#2 lore raw
In reply to Prashant Kamble

Hi,

Quoted 11 lines · Prashant Kamble

The PRP setup code advances prp_pool using u64 pointer arithmetic:

        prp_pool += page_size;

This increments the pointer by page_size * sizeof(u64) bytes instead of page_size bytes, resulting in invalid PRP list addresses when multiple PRP list pages are required.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-ufs (u-boot-nvme-fixes)

[1/1] nvme: Fix PRP list pointer arithmetic for chained transfers

      https://source.denx.de/u-boot/custodians/u-boot-ufs/-/commit/4f510505988928e129e109811587c4a00d28ec56
Signature · 1 line
Neil