linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI/P2PDMA: fix the wrong dma address calculation when map sg
@ 2021-09-09  3:25 Wang Lu
  2021-09-09 16:51 ` Logan Gunthorpe
  2021-09-09 17:28 ` Bjorn Helgaas
  0 siblings, 2 replies; 3+ messages in thread
From: Wang Lu @ 2021-09-09  3:25 UTC (permalink / raw)
  To: bhelgaas; +Cc: linux-pci, linux-kernel, 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.

Signed-off-by: Wang Lu <wanglu@dapustor.com>
---
 drivers/pci/p2pdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index 50cdde3e9a8b..327882638b30 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -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;
 	}
 
-- 
2.17.1




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

* Re: [PATCH] PCI/P2PDMA: fix the wrong dma address calculation when map sg
  2021-09-09  3:25 [PATCH] PCI/P2PDMA: fix the wrong dma address calculation when map sg Wang Lu
@ 2021-09-09 16:51 ` Logan Gunthorpe
  2021-09-09 17:28 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Logan Gunthorpe @ 2021-09-09 16:51 UTC (permalink / raw)
  To: Wang Lu, bhelgaas; +Cc: linux-pci, linux-kernel




On 2021-09-08 9:25 p.m., Wang Lu wrote:
> The bus offset is bus address - physical address,
> so the calculation in __pci_p2pdma_map_sg should be:
> bus address = physical address + bus offset.
> 
> Signed-off-by: Wang Lu <wanglu@dapustor.com>

Thanks, yes I believe my math was wrong here.

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

Reviewed-by: Logan Gunthorpe <logang@deltatee.com>

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

* Re: [PATCH] PCI/P2PDMA: fix the wrong dma address calculation when map sg
  2021-09-09  3:25 [PATCH] PCI/P2PDMA: fix the wrong dma address calculation when map sg Wang Lu
  2021-09-09 16:51 ` Logan Gunthorpe
@ 2021-09-09 17:28 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2021-09-09 17:28 UTC (permalink / raw)
  To: Wang Lu; +Cc: bhelgaas, linux-pci, linux-kernel, Logan Gunthorpe

On Thu, Sep 09, 2021 at 11:25:28AM +0800, Wang Lu wrote:
> The bus offset is bus address - physical address,
> so the calculation in __pci_p2pdma_map_sg should be:
> bus address = physical address + bus offset.
> 
> Signed-off-by: Wang Lu <wanglu@dapustor.com>

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.

> ---
>  drivers/pci/p2pdma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
> index 50cdde3e9a8b..327882638b30 100644
> --- a/drivers/pci/p2pdma.c
> +++ b/drivers/pci/p2pdma.c
> @@ -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;
>  	}
>  
> -- 
> 2.17.1
> 
> 
> 

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

end of thread, other threads:[~2021-09-09 17:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  3:25 [PATCH] PCI/P2PDMA: fix the wrong dma address calculation when map sg Wang Lu
2021-09-09 16:51 ` Logan Gunthorpe
2021-09-09 17:28 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).