Skip to contentSkip to conversation

PCI/P2PDMA: fix the wrong dma address calculation when map sg

PATCH In review Wang Lu 3 participants 3 messages Sep 9, 2021

Subsystems (2)
lore
Share & tools
lore

Wang Lu

author
#0 lore raw

PATCH 1/1 PCI/P2PDMA: fix the wrong dma address calculation when map sg

The bus offset is bus address - physical address, so the calculation in __pci_p2pdma_map_sg should be:
bus address = physical address + bus offset.

---
 drivers/pci/p2pdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/p2pdma.c +1 -1
index 50cdde3e9a8b..327882638b30 100644
@@ -874,7 +874,7 @@ static int __pci_p2pdma_map_sg(struct pci_p2pdma_pagemap *p2p_pgmap,
 	int i;
 
 	for_each_sg(sg, s, nents, i) {
-		s->dma_address = sg_phys(s) - p2p_pgmap->bus_offset;
+		s->dma_address = sg_phys(s) + p2p_pgmap->bus_offset;
 		sg_dma_len(s) = s->length;
 	}
 
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Wang Lu

The bus offset is bus address - physical address, so the calculation in __pci_p2pdma_map_sg should be:
bus address = physical address + bus offset.

Thanks, yes I believe my math was wrong here.

It was never tested on any machine that has a non-zero bus-offset.

#2 lore raw
In reply to Wang Lu
Quoted 5 lines · Wang Lu

The bus offset is bus address - physical address, so the calculation in __pci_p2pdma_map_sg should be:
bus address = physical address + bus offset.

Applied with Logan's reviewed-by to pci/p2pdma for v5.16, thanks!

I fixed the subject line and commit log for you to follow the usual conventions.

Quoted 22 lines
---
 drivers/pci/p2pdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/p2pdma.c +1 -1
index 50cdde3e9a8b..327882638b30 100644
@@ -874,7 +874,7 @@ static int __pci_p2pdma_map_sg(struct pci_p2pdma_pagemap *p2p_pgmap,
 	int i;
 
 	for_each_sg(sg, s, nents, i) {
-		s->dma_address = sg_phys(s) - p2p_pgmap->bus_offset;
+		s->dma_address = sg_phys(s) + p2p_pgmap->bus_offset;
 		sg_dma_len(s) = s->length;
 	}
 
Signature · 1 line
2.17.1