PCI/P2PDMA: Apply bus offset correctly in DMA address calculation
authorWang Lu <wanglu@dapustor.com>
Thu, 9 Sep 2021 03:25:28 +0000 (11:25 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 20 Sep 2021 19:46:02 +0000 (14:46 -0500)
The bus offset is bus address - physical address, so the calculation in
__pci_p2pdma_map_sg should be: bus address = physical address + bus offset.

Correct the dma_address computation in __pci_p2pdma_map_sg().

Link: https://lore.kernel.org/r/20210909032528.24517-1-wanglu@dapustor.com
Signed-off-by: Wang Lu <wanglu@dapustor.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
drivers/pci/p2pdma.c

index 50cdde3e9a8b2b34bc9d62def0218da7c7ae368d..327882638b301870053e3a3c0f7949c97dd15c2c 100644 (file)
@@ -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;
        }