Skip to contentSkip to conversation

nvme-pci: DMA unmap the correct regions in nvme_free_sgls

PATCH Applied Nicolai Buchwitz 3 participants 3 messages Jul 14 – Jul 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-pci: DMA unmap the correct regions in nvme_free_sgls

From: Roger Pau Monne <[email protected]>

commit a54afbc8a2138f8c2490510cf26cde188d480c43 upstream.

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Fixes f0887e2a52d4 ("nvme-pci: create common sgl unmapping helper")

[nb: drop the attrs parameter added in 6.19 by commit 61d43b1731e0
("nvme-pci: migrate to dma_map_phys instead of map_page"), which is not in 6.18.y]

---
This hits 6.18 too: besides the known Xen PV issue, the missing fix leads to corrupted data on NVMe disks with SGL support on BCM2712 (Raspberry Pi 5).

Reported and diagnosed in https://github.com/raspberrypi/linux/issues/7496
Backported by Phil Elwell in https://github.com/raspberrypi/linux/pull/7500

 drivers/nvme/host/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +2 -2
index 5e36a5926fe0..8c66fd23a143 100644
@@ -761,8 +761,8 @@ static void nvme_unmap_data(struct request *req)
 
 	if (!blk_rq_dma_unmap(req, dma_dev, &iod->dma_state, iod->total_len)) {
 		if (nvme_pci_cmd_use_sgl(&iod->cmd))
-			nvme_free_sgls(req, iod->descriptors[0],
-				       &iod->cmd.common.dptr.sgl);
+			nvme_free_sgls(req, &iod->cmd.common.dptr.sgl,
+				       iod->descriptors[0]);
 		else
 			nvme_free_prps(req);
 	}
Signature · 1 line
2.53.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Nicolai Buchwitz

From: Roger Pau Monne <[email protected]>

commit a54afbc8a2138f8c2490510cf26cde188d480c43 upstream.

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Quoted 8 lines
Fixes f0887e2a52d4 ("nvme-pci: create common sgl unmapping helper")

[nb: drop the attrs parameter added in 6.19 by commit 61d43b1731e0
("nvme-pci: migrate to dma_map_phys instead of map_page"), which is not in 6.18.y]

Yes, definitely want this for LTS.

maintainer Applied
#2 lore raw
In reply to Nicolai Buchwitz
Quoted 5 lines · Nicolai Buchwitz

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Queued for 6.18, thanks.

Signature · 2 lines
Thanks,
Sasha