All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-09 23:46 kernel test robot
  0 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2020-09-09 23:46 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 6797 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200908164758.3177341-10-hch@lst.de>
References: <20200908164758.3177341-10-hch@lst.de>
TO: Christoph Hellwig <hch@lst.de>

Hi Christoph,

I love your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on char-misc/char-misc-testing iommu/next linus/master v5.9-rc4 next-20200909]
[cannot apply to ia64/next tip/x86/core swiotlb/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
:::::: branch date: 20 hours ago
:::::: commit date: 20 hours ago
config: x86_64-randconfig-m001-20200909 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/xen/swiotlb-xen.c:315 xen_swiotlb_alloc_coherent() error: we previously assumed 'hwdev' could be null (see line 308)

# https://github.com/0day-ci/linux/commit/3e9f075c8a9790e7d58348f52270e7e57a721a31
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
git checkout 3e9f075c8a9790e7d58348f52270e7e57a721a31
vim +/hwdev +315 drivers/xen/swiotlb-xen.c

dceb1a6819ab2c Christoph Hellwig     2017-05-21  275  
dceb1a6819ab2c Christoph Hellwig     2017-05-21  276  static void *
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  277  xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
baa676fcf8d555 Andrzej Pietrasiewicz 2012-03-27  278  			   dma_addr_t *dma_handle, gfp_t flags,
00085f1efa387a Krzysztof Kozlowski   2016-08-03  279  			   unsigned long attrs)
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  280  {
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  281  	void *ret;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  282  	int order = get_order(size);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  283  	u64 dma_mask = DMA_BIT_MASK(32);
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  284  	phys_addr_t phys;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  285  	dma_addr_t dev_addr;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  286  
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  287  	/*
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  288  	* Ignore region specifiers - the kernel's ideas of
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  289  	* pseudo-phys memory layout has nothing to do with the
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  290  	* machine physical layout.  We can't allocate highmem
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  291  	* because we can't return a pointer to it.
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  292  	*/
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  293  	flags &= ~(__GFP_DMA | __GFP_HIGHMEM);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  294  
7250f422da0480 Joe Jin               2018-10-16  295  	/* Convert the size to actually allocated. */
7250f422da0480 Joe Jin               2018-10-16  296  	size = 1UL << (order + XEN_PAGE_SHIFT);
7250f422da0480 Joe Jin               2018-10-16  297  
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  298  	/* On ARM this function returns an ioremap'ped virtual address for
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  299  	 * which virt_to_phys doesn't return the corresponding physical
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  300  	 * address. In fact on ARM virt_to_phys only works for kernel direct
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  301  	 * mapped RAM memory. Also see comment below.
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  302  	 */
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  303  	ret = xen_alloc_coherent_pages(hwdev, size, dma_handle, flags, attrs);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  304  
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  305  	if (!ret)
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  306  		return ret;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  307  
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11 @308  	if (hwdev && hwdev->coherent_dma_mask)
038d07a283d623 Christoph Hellwig     2018-03-19  309  		dma_mask = hwdev->coherent_dma_mask;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  310  
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  311  	/* At this point dma_handle is the dma address, next we are
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  312  	 * going to set it to the machine address.
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  313  	 * Do not use virt_to_phys(ret) because on ARM it doesn't correspond
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  314  	 * to *dma_handle. */
91ffe4ad534ab2 Stefano Stabellini    2020-07-10 @315  	phys = dma_to_phys(hwdev, *dma_handle);
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  316  	dev_addr = xen_phys_to_dma(hwdev, phys);
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  317  	if (((dev_addr + size - 1 <= dma_mask)) &&
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  318  	    !range_straddles_page_boundary(phys, size))
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  319  		*dma_handle = dev_addr;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  320  	else {
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  321  		if (xen_create_contiguous_region(phys, order,
69908907b02efe Stefano Stabellini    2013-10-09  322  						 fls64(dma_mask), dma_handle) != 0) {
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  323  			xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  324  			return NULL;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  325  		}
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  326  		*dma_handle = phys_to_dma(hwdev, *dma_handle);
b877ac9815a8fe Juergen Gross         2019-06-14  327  		SetPageXenRemapped(virt_to_page(ret));
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  328  	}
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  329  	memset(ret, 0, size);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  330  	return ret;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  331  }
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  332  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 50057 bytes --]

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
  2020-09-10 13:26     ` Robin Murphy
  (?)
@ 2020-09-11  7:14       ` Christoph Hellwig
  -1 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-11  7:14 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Christoph Hellwig, Tony Luck, Fenghua Yu, Thomas Bogendoerfer,
	iommu, Tomasz Figa, Joerg Roedel, linux-doc, linux-kernel,
	linux-ia64, linux-mips

On Thu, Sep 10, 2020 at 02:26:03PM +0100, Robin Murphy wrote:
> On 2020-09-08 17:47, Christoph Hellwig wrote:
>> There is no harm in just always clearing the SME encryption bit, while
>> significantly simplifying the interface.
>
> After a 10-minute diversion into "but hang on, force_dma_unencrypted() is 
> meaningful on PPC and S390 too..." before realising that it all does just 
> come back to __sme_clr(), which is indeed a no-op for everyone other than 
> AMD, any simplification of this mess is indeed welcome :)
>
> Unless I've massively misunderstood how SME is supposed to work,

Exactly.  This weird encryption bit in AMD SME causes all kinds of harm,
and I'm glad no one picked it up.  I've also been wondering if we
should change the interface to explicit set/clear the bit, but I'll
leave that for another pass as fixing up the SME interfaces would turn
into a massive disgression.

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-11  7:14       ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-11  7:14 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Fenghua Yu, Tony Luck, linux-ia64, linux-doc, linux-kernel,
	iommu, Thomas Bogendoerfer, linux-mips, Christoph Hellwig

On Thu, Sep 10, 2020 at 02:26:03PM +0100, Robin Murphy wrote:
> On 2020-09-08 17:47, Christoph Hellwig wrote:
>> There is no harm in just always clearing the SME encryption bit, while
>> significantly simplifying the interface.
>
> After a 10-minute diversion into "but hang on, force_dma_unencrypted() is 
> meaningful on PPC and S390 too..." before realising that it all does just 
> come back to __sme_clr(), which is indeed a no-op for everyone other than 
> AMD, any simplification of this mess is indeed welcome :)
>
> Unless I've massively misunderstood how SME is supposed to work,

Exactly.  This weird encryption bit in AMD SME causes all kinds of harm,
and I'm glad no one picked it up.  I've also been wondering if we
should change the interface to explicit set/clear the bit, but I'll
leave that for another pass as fixing up the SME interfaces would turn
into a massive disgression.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-11  7:14       ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-11  7:14 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Christoph Hellwig, Tony Luck, Fenghua Yu, Thomas Bogendoerfer,
	iommu, Tomasz Figa, Joerg Roedel, linux-doc, linux-kernel,
	linux-ia64, linux-mips

On Thu, Sep 10, 2020 at 02:26:03PM +0100, Robin Murphy wrote:
> On 2020-09-08 17:47, Christoph Hellwig wrote:
>> There is no harm in just always clearing the SME encryption bit, while
>> significantly simplifying the interface.
>
> After a 10-minute diversion into "but hang on, force_dma_unencrypted() is 
> meaningful on PPC and S390 too..." before realising that it all does just 
> come back to __sme_clr(), which is indeed a no-op for everyone other than 
> AMD, any simplification of this mess is indeed welcome :)
>
> Unless I've massively misunderstood how SME is supposed to work,

Exactly.  This weird encryption bit in AMD SME causes all kinds of harm,
and I'm glad no one picked it up.  I've also been wondering if we
should change the interface to explicit set/clear the bit, but I'll
leave that for another pass as fixing up the SME interfaces would turn
into a massive disgression.

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
  2020-09-10  9:45     ` Dan Carpenter
  (?)
@ 2020-09-11  7:12     ` Christoph Hellwig
  -1 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-11  7:12 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 900 bytes --]

On Thu, Sep 10, 2020 at 12:45:39PM +0300, Dan Carpenter wrote:
> Hi Christoph,
> 
> url:    https://github.com/0day-ci/linux/commits/Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
> config: x86_64-randconfig-m001-20200909 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> smatch warnings:
> drivers/xen/swiotlb-xen.c:315 xen_swiotlb_alloc_coherent() error: we previously assumed 'hwdev' could be null (see line 308)

Yeah, we'll need to clean up all these device NULL checks as support for
NULL devices is long gone.  But I'd rather do that in a separate cleanups
pass.

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
  2020-09-08 16:47   ` Christoph Hellwig
  (?)
@ 2020-09-10 13:26     ` Robin Murphy
  -1 siblings, 0 replies; 13+ messages in thread
From: Robin Murphy @ 2020-09-10 13:26 UTC (permalink / raw)
  To: Christoph Hellwig, Tony Luck, Fenghua Yu, Thomas Bogendoerfer, iommu
  Cc: Tomasz Figa, Joerg Roedel, linux-doc, linux-kernel, linux-ia64,
	linux-mips

On 2020-09-08 17:47, Christoph Hellwig wrote:
> There is no harm in just always clearing the SME encryption bit, while
> significantly simplifying the interface.

After a 10-minute diversion into "but hang on, force_dma_unencrypted() 
is meaningful on PPC and S390 too..." before realising that it all does 
just come back to __sme_clr(), which is indeed a no-op for everyone 
other than AMD, any simplification of this mess is indeed welcome :)

Unless I've massively misunderstood how SME is supposed to work,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   arch/arm/include/asm/dma-direct.h      |  2 +-
>   arch/mips/bmips/dma.c                  |  2 +-
>   arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>   arch/mips/include/asm/dma-direct.h     |  2 +-
>   arch/mips/loongson2ef/fuloong-2e/dma.c |  2 +-
>   arch/mips/loongson2ef/lemote-2f/dma.c  |  2 +-
>   arch/mips/loongson64/dma.c             |  2 +-
>   arch/mips/pci/pci-ar2315.c             |  2 +-
>   arch/mips/pci/pci-xtalk-bridge.c       |  2 +-
>   arch/mips/sgi-ip32/ip32-dma.c          |  2 +-
>   arch/powerpc/include/asm/dma-direct.h  |  2 +-
>   include/linux/dma-direct.h             | 14 +++++---------
>   kernel/dma/direct.c                    |  6 +-----
>   13 files changed, 17 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
> index 7c3001a6a775bf..a8cee87a93e8ab 100644
> --- a/arch/arm/include/asm/dma-direct.h
> +++ b/arch/arm/include/asm/dma-direct.h
> @@ -8,7 +8,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
>   {
>   	unsigned int offset = dev_addr & ~PAGE_MASK;
>   	return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
> diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
> index df56bf4179e347..ba2a5d33dfd3fa 100644
> --- a/arch/mips/bmips/dma.c
> +++ b/arch/mips/bmips/dma.c
> @@ -52,7 +52,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
>   	return pa;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	struct bmips_dma_range *r;
>   
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
> index 14ea680d180e07..388b13ba2558c2 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -177,7 +177,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   #ifdef CONFIG_PCI
>   	if (dev && dev_is_pci(dev))
> diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
> index 14e352651ce946..8e178651c638c2 100644
> --- a/arch/mips/include/asm/dma-direct.h
> +++ b/arch/mips/include/asm/dma-direct.h
> @@ -3,6 +3,6 @@
>   #define _MIPS_DMA_DIRECT_H 1
>   
>   dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
>   
>   #endif /* _MIPS_DMA_DIRECT_H */
> diff --git a/arch/mips/loongson2ef/fuloong-2e/dma.c b/arch/mips/loongson2ef/fuloong-2e/dma.c
> index e122292bf6660a..83fadeb3fd7d56 100644
> --- a/arch/mips/loongson2ef/fuloong-2e/dma.c
> +++ b/arch/mips/loongson2ef/fuloong-2e/dma.c
> @@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr | 0x80000000;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr & 0x7fffffff;
>   }
> diff --git a/arch/mips/loongson2ef/lemote-2f/dma.c b/arch/mips/loongson2ef/lemote-2f/dma.c
> index abf0e39d7e4696..302b43a14eee74 100644
> --- a/arch/mips/loongson2ef/lemote-2f/dma.c
> +++ b/arch/mips/loongson2ef/lemote-2f/dma.c
> @@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr | 0x80000000;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	if (dma_addr > 0x8fffffff)
>   		return dma_addr;
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index dbfe6e82fddd1c..b3dc5d0bd2b113 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -13,7 +13,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
>   	 * Loongson-3's 48bit address space and embed it into 40bit */
> diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c
> index 490953f515282a..d88395684f487d 100644
> --- a/arch/mips/pci/pci-ar2315.c
> +++ b/arch/mips/pci/pci-ar2315.c
> @@ -175,7 +175,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr + ar2315_dev_offset(dev);
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr - ar2315_dev_offset(dev);
>   }
> diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
> index 9b3cc775c55e05..f1b37f32b55395 100644
> --- a/arch/mips/pci/pci-xtalk-bridge.c
> +++ b/arch/mips/pci/pci-xtalk-bridge.c
> @@ -33,7 +33,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return bc->baddr + paddr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr & ~(0xffUL << 56);
>   }
> diff --git a/arch/mips/sgi-ip32/ip32-dma.c b/arch/mips/sgi-ip32/ip32-dma.c
> index fa7b17cb53853e..160317294d97a9 100644
> --- a/arch/mips/sgi-ip32/ip32-dma.c
> +++ b/arch/mips/sgi-ip32/ip32-dma.c
> @@ -27,7 +27,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return dma_addr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
>   
> diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
> index abc154d784b078..95b09313d2a4cf 100644
> --- a/arch/powerpc/include/asm/dma-direct.h
> +++ b/arch/powerpc/include/asm/dma-direct.h
> @@ -7,7 +7,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr + dev->archdata.dma_offset;
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   	return daddr - dev->archdata.dma_offset;
>   }
> diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
> index 20eceb2e4f91f8..f00e262ab6b154 100644
> --- a/include/linux/dma-direct.h
> +++ b/include/linux/dma-direct.h
> @@ -24,11 +24,12 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
>   {
> -	phys_addr_t paddr = (phys_addr_t)dev_addr;
> +	phys_addr_t paddr = (phys_addr_t)dev_addr +
> +		((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
>   
> -	return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
> +	return __sme_clr(paddr);
>   }
>   #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
>   
> @@ -44,7 +45,7 @@ static inline bool force_dma_unencrypted(struct device *dev)
>   /*
>    * If memory encryption is supported, phys_to_dma will set the memory encryption
>    * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
> - * and __dma_to_phys versions should only be used on non-encrypted memory for
> + * version should only be used on non-encrypted memory for
>    * special occasions like DMA coherent buffers.
>    */
>   static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
> @@ -52,11 +53,6 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return __sme_set(__phys_to_dma(dev, paddr));
>   }
>   
> -static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
> -{
> -	return __sme_clr(__dma_to_phys(dev, daddr));
> -}
> -
>   static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
>   		bool is_ram)
>   {
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 57a6e7d7cf8f16..bfb479c8a370fa 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -48,11 +48,6 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
>   {
>   	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
>   
> -	if (force_dma_unencrypted(dev))
> -		*phys_limit = __dma_to_phys(dev, dma_limit);
> -	else
> -		*phys_limit = dma_to_phys(dev, dma_limit);
> -
>   	/*
>   	 * Optimistically try the zone that the physical address mask falls
>   	 * into first.  If that returns memory that isn't actually addressable
> @@ -61,6 +56,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
>   	 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
>   	 * zones.
>   	 */
> +	*phys_limit = dma_to_phys(dev, dma_limit);
>   	if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
>   		return GFP_DMA;
>   	if (*phys_limit <= DMA_BIT_MASK(32))
> 

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-10 13:26     ` Robin Murphy
  0 siblings, 0 replies; 13+ messages in thread
From: Robin Murphy @ 2020-09-10 13:26 UTC (permalink / raw)
  To: Christoph Hellwig, Tony Luck, Fenghua Yu, Thomas Bogendoerfer, iommu
  Cc: linux-ia64, linux-doc, linux-mips, linux-kernel

On 2020-09-08 17:47, Christoph Hellwig wrote:
> There is no harm in just always clearing the SME encryption bit, while
> significantly simplifying the interface.

After a 10-minute diversion into "but hang on, force_dma_unencrypted() 
is meaningful on PPC and S390 too..." before realising that it all does 
just come back to __sme_clr(), which is indeed a no-op for everyone 
other than AMD, any simplification of this mess is indeed welcome :)

Unless I've massively misunderstood how SME is supposed to work,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   arch/arm/include/asm/dma-direct.h      |  2 +-
>   arch/mips/bmips/dma.c                  |  2 +-
>   arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>   arch/mips/include/asm/dma-direct.h     |  2 +-
>   arch/mips/loongson2ef/fuloong-2e/dma.c |  2 +-
>   arch/mips/loongson2ef/lemote-2f/dma.c  |  2 +-
>   arch/mips/loongson64/dma.c             |  2 +-
>   arch/mips/pci/pci-ar2315.c             |  2 +-
>   arch/mips/pci/pci-xtalk-bridge.c       |  2 +-
>   arch/mips/sgi-ip32/ip32-dma.c          |  2 +-
>   arch/powerpc/include/asm/dma-direct.h  |  2 +-
>   include/linux/dma-direct.h             | 14 +++++---------
>   kernel/dma/direct.c                    |  6 +-----
>   13 files changed, 17 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
> index 7c3001a6a775bf..a8cee87a93e8ab 100644
> --- a/arch/arm/include/asm/dma-direct.h
> +++ b/arch/arm/include/asm/dma-direct.h
> @@ -8,7 +8,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
>   {
>   	unsigned int offset = dev_addr & ~PAGE_MASK;
>   	return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
> diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
> index df56bf4179e347..ba2a5d33dfd3fa 100644
> --- a/arch/mips/bmips/dma.c
> +++ b/arch/mips/bmips/dma.c
> @@ -52,7 +52,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
>   	return pa;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	struct bmips_dma_range *r;
>   
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
> index 14ea680d180e07..388b13ba2558c2 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -177,7 +177,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   #ifdef CONFIG_PCI
>   	if (dev && dev_is_pci(dev))
> diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
> index 14e352651ce946..8e178651c638c2 100644
> --- a/arch/mips/include/asm/dma-direct.h
> +++ b/arch/mips/include/asm/dma-direct.h
> @@ -3,6 +3,6 @@
>   #define _MIPS_DMA_DIRECT_H 1
>   
>   dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
>   
>   #endif /* _MIPS_DMA_DIRECT_H */
> diff --git a/arch/mips/loongson2ef/fuloong-2e/dma.c b/arch/mips/loongson2ef/fuloong-2e/dma.c
> index e122292bf6660a..83fadeb3fd7d56 100644
> --- a/arch/mips/loongson2ef/fuloong-2e/dma.c
> +++ b/arch/mips/loongson2ef/fuloong-2e/dma.c
> @@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr | 0x80000000;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr & 0x7fffffff;
>   }
> diff --git a/arch/mips/loongson2ef/lemote-2f/dma.c b/arch/mips/loongson2ef/lemote-2f/dma.c
> index abf0e39d7e4696..302b43a14eee74 100644
> --- a/arch/mips/loongson2ef/lemote-2f/dma.c
> +++ b/arch/mips/loongson2ef/lemote-2f/dma.c
> @@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr | 0x80000000;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	if (dma_addr > 0x8fffffff)
>   		return dma_addr;
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index dbfe6e82fddd1c..b3dc5d0bd2b113 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -13,7 +13,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
>   	 * Loongson-3's 48bit address space and embed it into 40bit */
> diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c
> index 490953f515282a..d88395684f487d 100644
> --- a/arch/mips/pci/pci-ar2315.c
> +++ b/arch/mips/pci/pci-ar2315.c
> @@ -175,7 +175,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr + ar2315_dev_offset(dev);
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr - ar2315_dev_offset(dev);
>   }
> diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
> index 9b3cc775c55e05..f1b37f32b55395 100644
> --- a/arch/mips/pci/pci-xtalk-bridge.c
> +++ b/arch/mips/pci/pci-xtalk-bridge.c
> @@ -33,7 +33,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return bc->baddr + paddr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr & ~(0xffUL << 56);
>   }
> diff --git a/arch/mips/sgi-ip32/ip32-dma.c b/arch/mips/sgi-ip32/ip32-dma.c
> index fa7b17cb53853e..160317294d97a9 100644
> --- a/arch/mips/sgi-ip32/ip32-dma.c
> +++ b/arch/mips/sgi-ip32/ip32-dma.c
> @@ -27,7 +27,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return dma_addr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
>   
> diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
> index abc154d784b078..95b09313d2a4cf 100644
> --- a/arch/powerpc/include/asm/dma-direct.h
> +++ b/arch/powerpc/include/asm/dma-direct.h
> @@ -7,7 +7,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr + dev->archdata.dma_offset;
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   	return daddr - dev->archdata.dma_offset;
>   }
> diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
> index 20eceb2e4f91f8..f00e262ab6b154 100644
> --- a/include/linux/dma-direct.h
> +++ b/include/linux/dma-direct.h
> @@ -24,11 +24,12 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
>   {
> -	phys_addr_t paddr = (phys_addr_t)dev_addr;
> +	phys_addr_t paddr = (phys_addr_t)dev_addr +
> +		((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
>   
> -	return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
> +	return __sme_clr(paddr);
>   }
>   #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
>   
> @@ -44,7 +45,7 @@ static inline bool force_dma_unencrypted(struct device *dev)
>   /*
>    * If memory encryption is supported, phys_to_dma will set the memory encryption
>    * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
> - * and __dma_to_phys versions should only be used on non-encrypted memory for
> + * version should only be used on non-encrypted memory for
>    * special occasions like DMA coherent buffers.
>    */
>   static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
> @@ -52,11 +53,6 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return __sme_set(__phys_to_dma(dev, paddr));
>   }
>   
> -static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
> -{
> -	return __sme_clr(__dma_to_phys(dev, daddr));
> -}
> -
>   static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
>   		bool is_ram)
>   {
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 57a6e7d7cf8f16..bfb479c8a370fa 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -48,11 +48,6 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
>   {
>   	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
>   
> -	if (force_dma_unencrypted(dev))
> -		*phys_limit = __dma_to_phys(dev, dma_limit);
> -	else
> -		*phys_limit = dma_to_phys(dev, dma_limit);
> -
>   	/*
>   	 * Optimistically try the zone that the physical address mask falls
>   	 * into first.  If that returns memory that isn't actually addressable
> @@ -61,6 +56,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
>   	 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
>   	 * zones.
>   	 */
> +	*phys_limit = dma_to_phys(dev, dma_limit);
>   	if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
>   		return GFP_DMA;
>   	if (*phys_limit <= DMA_BIT_MASK(32))
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-10 13:26     ` Robin Murphy
  0 siblings, 0 replies; 13+ messages in thread
From: Robin Murphy @ 2020-09-10 13:26 UTC (permalink / raw)
  To: Christoph Hellwig, Tony Luck, Fenghua Yu, Thomas Bogendoerfer, iommu
  Cc: Tomasz Figa, Joerg Roedel, linux-doc, linux-kernel, linux-ia64,
	linux-mips

On 2020-09-08 17:47, Christoph Hellwig wrote:
> There is no harm in just always clearing the SME encryption bit, while
> significantly simplifying the interface.

After a 10-minute diversion into "but hang on, force_dma_unencrypted() 
is meaningful on PPC and S390 too..." before realising that it all does 
just come back to __sme_clr(), which is indeed a no-op for everyone 
other than AMD, any simplification of this mess is indeed welcome :)

Unless I've massively misunderstood how SME is supposed to work,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   arch/arm/include/asm/dma-direct.h      |  2 +-
>   arch/mips/bmips/dma.c                  |  2 +-
>   arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>   arch/mips/include/asm/dma-direct.h     |  2 +-
>   arch/mips/loongson2ef/fuloong-2e/dma.c |  2 +-
>   arch/mips/loongson2ef/lemote-2f/dma.c  |  2 +-
>   arch/mips/loongson64/dma.c             |  2 +-
>   arch/mips/pci/pci-ar2315.c             |  2 +-
>   arch/mips/pci/pci-xtalk-bridge.c       |  2 +-
>   arch/mips/sgi-ip32/ip32-dma.c          |  2 +-
>   arch/powerpc/include/asm/dma-direct.h  |  2 +-
>   include/linux/dma-direct.h             | 14 +++++---------
>   kernel/dma/direct.c                    |  6 +-----
>   13 files changed, 17 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
> index 7c3001a6a775bf..a8cee87a93e8ab 100644
> --- a/arch/arm/include/asm/dma-direct.h
> +++ b/arch/arm/include/asm/dma-direct.h
> @@ -8,7 +8,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
>   {
>   	unsigned int offset = dev_addr & ~PAGE_MASK;
>   	return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
> diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
> index df56bf4179e347..ba2a5d33dfd3fa 100644
> --- a/arch/mips/bmips/dma.c
> +++ b/arch/mips/bmips/dma.c
> @@ -52,7 +52,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
>   	return pa;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	struct bmips_dma_range *r;
>   
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
> index 14ea680d180e07..388b13ba2558c2 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -177,7 +177,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   #ifdef CONFIG_PCI
>   	if (dev && dev_is_pci(dev))
> diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
> index 14e352651ce946..8e178651c638c2 100644
> --- a/arch/mips/include/asm/dma-direct.h
> +++ b/arch/mips/include/asm/dma-direct.h
> @@ -3,6 +3,6 @@
>   #define _MIPS_DMA_DIRECT_H 1
>   
>   dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
>   
>   #endif /* _MIPS_DMA_DIRECT_H */
> diff --git a/arch/mips/loongson2ef/fuloong-2e/dma.c b/arch/mips/loongson2ef/fuloong-2e/dma.c
> index e122292bf6660a..83fadeb3fd7d56 100644
> --- a/arch/mips/loongson2ef/fuloong-2e/dma.c
> +++ b/arch/mips/loongson2ef/fuloong-2e/dma.c
> @@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr | 0x80000000;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr & 0x7fffffff;
>   }
> diff --git a/arch/mips/loongson2ef/lemote-2f/dma.c b/arch/mips/loongson2ef/lemote-2f/dma.c
> index abf0e39d7e4696..302b43a14eee74 100644
> --- a/arch/mips/loongson2ef/lemote-2f/dma.c
> +++ b/arch/mips/loongson2ef/lemote-2f/dma.c
> @@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr | 0x80000000;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	if (dma_addr > 0x8fffffff)
>   		return dma_addr;
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index dbfe6e82fddd1c..b3dc5d0bd2b113 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -13,7 +13,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
>   	 * Loongson-3's 48bit address space and embed it into 40bit */
> diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c
> index 490953f515282a..d88395684f487d 100644
> --- a/arch/mips/pci/pci-ar2315.c
> +++ b/arch/mips/pci/pci-ar2315.c
> @@ -175,7 +175,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr + ar2315_dev_offset(dev);
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr - ar2315_dev_offset(dev);
>   }
> diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
> index 9b3cc775c55e05..f1b37f32b55395 100644
> --- a/arch/mips/pci/pci-xtalk-bridge.c
> +++ b/arch/mips/pci/pci-xtalk-bridge.c
> @@ -33,7 +33,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return bc->baddr + paddr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	return dma_addr & ~(0xffUL << 56);
>   }
> diff --git a/arch/mips/sgi-ip32/ip32-dma.c b/arch/mips/sgi-ip32/ip32-dma.c
> index fa7b17cb53853e..160317294d97a9 100644
> --- a/arch/mips/sgi-ip32/ip32-dma.c
> +++ b/arch/mips/sgi-ip32/ip32-dma.c
> @@ -27,7 +27,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return dma_addr;
>   }
>   
> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
> +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
>   {
>   	phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
>   
> diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
> index abc154d784b078..95b09313d2a4cf 100644
> --- a/arch/powerpc/include/asm/dma-direct.h
> +++ b/arch/powerpc/include/asm/dma-direct.h
> @@ -7,7 +7,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return paddr + dev->archdata.dma_offset;
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>   {
>   	return daddr - dev->archdata.dma_offset;
>   }
> diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
> index 20eceb2e4f91f8..f00e262ab6b154 100644
> --- a/include/linux/dma-direct.h
> +++ b/include/linux/dma-direct.h
> @@ -24,11 +24,12 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
>   }
>   
> -static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
> +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
>   {
> -	phys_addr_t paddr = (phys_addr_t)dev_addr;
> +	phys_addr_t paddr = (phys_addr_t)dev_addr +
> +		((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
>   
> -	return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
> +	return __sme_clr(paddr);
>   }
>   #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
>   
> @@ -44,7 +45,7 @@ static inline bool force_dma_unencrypted(struct device *dev)
>   /*
>    * If memory encryption is supported, phys_to_dma will set the memory encryption
>    * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
> - * and __dma_to_phys versions should only be used on non-encrypted memory for
> + * version should only be used on non-encrypted memory for
>    * special occasions like DMA coherent buffers.
>    */
>   static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
> @@ -52,11 +53,6 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
>   	return __sme_set(__phys_to_dma(dev, paddr));
>   }
>   
> -static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
> -{
> -	return __sme_clr(__dma_to_phys(dev, daddr));
> -}
> -
>   static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
>   		bool is_ram)
>   {
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 57a6e7d7cf8f16..bfb479c8a370fa 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -48,11 +48,6 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
>   {
>   	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
>   
> -	if (force_dma_unencrypted(dev))
> -		*phys_limit = __dma_to_phys(dev, dma_limit);
> -	else
> -		*phys_limit = dma_to_phys(dev, dma_limit);
> -
>   	/*
>   	 * Optimistically try the zone that the physical address mask falls
>   	 * into first.  If that returns memory that isn't actually addressable
> @@ -61,6 +56,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
>   	 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
>   	 * zones.
>   	 */
> +	*phys_limit = dma_to_phys(dev, dma_limit);
>   	if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
>   		return GFP_DMA;
>   	if (*phys_limit <= DMA_BIT_MASK(32))
> 

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
  2020-09-08 16:47   ` Christoph Hellwig
@ 2020-09-10  9:45     ` Dan Carpenter
  -1 siblings, 0 replies; 13+ messages in thread
From: Dan Carpenter @ 2020-09-10  9:45 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 6183 bytes --]

Hi Christoph,

url:    https://github.com/0day-ci/linux/commits/Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: x86_64-randconfig-m001-20200909 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/xen/swiotlb-xen.c:315 xen_swiotlb_alloc_coherent() error: we previously assumed 'hwdev' could be null (see line 308)

# https://github.com/0day-ci/linux/commit/3e9f075c8a9790e7d58348f52270e7e57a721a31
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
git checkout 3e9f075c8a9790e7d58348f52270e7e57a721a31
vim +/hwdev +315 drivers/xen/swiotlb-xen.c

dceb1a6819ab2c Christoph Hellwig     2017-05-21  276  static void *
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  277  xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
baa676fcf8d555 Andrzej Pietrasiewicz 2012-03-27  278  			   dma_addr_t *dma_handle, gfp_t flags,
00085f1efa387a Krzysztof Kozlowski   2016-08-03  279  			   unsigned long attrs)
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  280  {
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  281  	void *ret;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  282  	int order = get_order(size);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  283  	u64 dma_mask = DMA_BIT_MASK(32);
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  284  	phys_addr_t phys;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  285  	dma_addr_t dev_addr;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  286  
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  287  	/*
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  288  	* Ignore region specifiers - the kernel's ideas of
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  289  	* pseudo-phys memory layout has nothing to do with the
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  290  	* machine physical layout.  We can't allocate highmem
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  291  	* because we can't return a pointer to it.
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  292  	*/
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  293  	flags &= ~(__GFP_DMA | __GFP_HIGHMEM);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  294  
7250f422da0480 Joe Jin               2018-10-16  295  	/* Convert the size to actually allocated. */
7250f422da0480 Joe Jin               2018-10-16  296  	size = 1UL << (order + XEN_PAGE_SHIFT);
7250f422da0480 Joe Jin               2018-10-16  297  
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  298  	/* On ARM this function returns an ioremap'ped virtual address for
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  299  	 * which virt_to_phys doesn't return the corresponding physical
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  300  	 * address. In fact on ARM virt_to_phys only works for kernel direct
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  301  	 * mapped RAM memory. Also see comment below.
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  302  	 */
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  303  	ret = xen_alloc_coherent_pages(hwdev, size, dma_handle, flags, attrs);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  304  
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  305  	if (!ret)
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  306  		return ret;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  307  
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11 @308  	if (hwdev && hwdev->coherent_dma_mask)
                                                            ^^^^^
Check for NULL

038d07a283d623 Christoph Hellwig     2018-03-19  309  		dma_mask = hwdev->coherent_dma_mask;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  310  
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  311  	/* At this point dma_handle is the dma address, next we are
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  312  	 * going to set it to the machine address.
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  313  	 * Do not use virt_to_phys(ret) because on ARM it doesn't correspond
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  314  	 * to *dma_handle. */
91ffe4ad534ab2 Stefano Stabellini    2020-07-10 @315  	phys = dma_to_phys(hwdev, *dma_handle);
                                                                           ^^^^^
Unchecked dereference

91ffe4ad534ab2 Stefano Stabellini    2020-07-10  316  	dev_addr = xen_phys_to_dma(hwdev, phys);
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  317  	if (((dev_addr + size - 1 <= dma_mask)) &&
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  318  	    !range_straddles_page_boundary(phys, size))
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  319  		*dma_handle = dev_addr;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  320  	else {
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  321  		if (xen_create_contiguous_region(phys, order,
69908907b02efe Stefano Stabellini    2013-10-09  322  						 fls64(dma_mask), dma_handle) != 0) {
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  323  			xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  324  			return NULL;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  325  		}
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  326  		*dma_handle = phys_to_dma(hwdev, *dma_handle);
b877ac9815a8fe Juergen Gross         2019-06-14  327  		SetPageXenRemapped(virt_to_page(ret));
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  328  	}
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  329  	memset(ret, 0, size);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  330  	return ret;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  331  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 50057 bytes --]

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

* Re: [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-10  9:45     ` Dan Carpenter
  0 siblings, 0 replies; 13+ messages in thread
From: Dan Carpenter @ 2020-09-10  9:45 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6183 bytes --]

Hi Christoph,

url:    https://github.com/0day-ci/linux/commits/Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: x86_64-randconfig-m001-20200909 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/xen/swiotlb-xen.c:315 xen_swiotlb_alloc_coherent() error: we previously assumed 'hwdev' could be null (see line 308)

# https://github.com/0day-ci/linux/commit/3e9f075c8a9790e7d58348f52270e7e57a721a31
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christoph-Hellwig/MIPS-make-dma_sync_-_for_cpu-a-little-less-overzealous/20200909-120508
git checkout 3e9f075c8a9790e7d58348f52270e7e57a721a31
vim +/hwdev +315 drivers/xen/swiotlb-xen.c

dceb1a6819ab2c Christoph Hellwig     2017-05-21  276  static void *
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  277  xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
baa676fcf8d555 Andrzej Pietrasiewicz 2012-03-27  278  			   dma_addr_t *dma_handle, gfp_t flags,
00085f1efa387a Krzysztof Kozlowski   2016-08-03  279  			   unsigned long attrs)
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  280  {
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  281  	void *ret;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  282  	int order = get_order(size);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  283  	u64 dma_mask = DMA_BIT_MASK(32);
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  284  	phys_addr_t phys;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  285  	dma_addr_t dev_addr;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  286  
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  287  	/*
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  288  	* Ignore region specifiers - the kernel's ideas of
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  289  	* pseudo-phys memory layout has nothing to do with the
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  290  	* machine physical layout.  We can't allocate highmem
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  291  	* because we can't return a pointer to it.
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  292  	*/
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  293  	flags &= ~(__GFP_DMA | __GFP_HIGHMEM);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  294  
7250f422da0480 Joe Jin               2018-10-16  295  	/* Convert the size to actually allocated. */
7250f422da0480 Joe Jin               2018-10-16  296  	size = 1UL << (order + XEN_PAGE_SHIFT);
7250f422da0480 Joe Jin               2018-10-16  297  
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  298  	/* On ARM this function returns an ioremap'ped virtual address for
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  299  	 * which virt_to_phys doesn't return the corresponding physical
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  300  	 * address. In fact on ARM virt_to_phys only works for kernel direct
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  301  	 * mapped RAM memory. Also see comment below.
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  302  	 */
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  303  	ret = xen_alloc_coherent_pages(hwdev, size, dma_handle, flags, attrs);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  304  
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  305  	if (!ret)
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  306  		return ret;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  307  
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11 @308  	if (hwdev && hwdev->coherent_dma_mask)
                                                            ^^^^^
Check for NULL

038d07a283d623 Christoph Hellwig     2018-03-19  309  		dma_mask = hwdev->coherent_dma_mask;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  310  
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  311  	/* At this point dma_handle is the dma address, next we are
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  312  	 * going to set it to the machine address.
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  313  	 * Do not use virt_to_phys(ret) because on ARM it doesn't correspond
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  314  	 * to *dma_handle. */
91ffe4ad534ab2 Stefano Stabellini    2020-07-10 @315  	phys = dma_to_phys(hwdev, *dma_handle);
                                                                           ^^^^^
Unchecked dereference

91ffe4ad534ab2 Stefano Stabellini    2020-07-10  316  	dev_addr = xen_phys_to_dma(hwdev, phys);
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  317  	if (((dev_addr + size - 1 <= dma_mask)) &&
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  318  	    !range_straddles_page_boundary(phys, size))
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  319  		*dma_handle = dev_addr;
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  320  	else {
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  321  		if (xen_create_contiguous_region(phys, order,
69908907b02efe Stefano Stabellini    2013-10-09  322  						 fls64(dma_mask), dma_handle) != 0) {
1b65c4e5a9af1a Stefano Stabellini    2013-10-10  323  			xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  324  			return NULL;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  325  		}
91ffe4ad534ab2 Stefano Stabellini    2020-07-10  326  		*dma_handle = phys_to_dma(hwdev, *dma_handle);
b877ac9815a8fe Juergen Gross         2019-06-14  327  		SetPageXenRemapped(virt_to_page(ret));
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  328  	}
6810df88dcfc22 Konrad Rzeszutek Wilk 2011-08-25  329  	memset(ret, 0, size);
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  330  	return ret;
b097186fd29d5b Konrad Rzeszutek Wilk 2010-05-11  331  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 50057 bytes --]

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

* [PATCH 09/12] dma-direct: remove __dma_to_phys
  2020-09-08 16:47 dma-mapping cleanups Christoph Hellwig
  2020-09-08 16:47   ` Christoph Hellwig
@ 2020-09-08 16:47   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-08 16:47 UTC (permalink / raw)
  To: Tony Luck, Fenghua Yu, Thomas Bogendoerfer, iommu
  Cc: Tomasz Figa, Joerg Roedel, Robin Murphy, linux-doc, linux-kernel,
	linux-ia64, linux-mips

There is no harm in just always clearing the SME encryption bit, while
significantly simplifying the interface.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/include/asm/dma-direct.h      |  2 +-
 arch/mips/bmips/dma.c                  |  2 +-
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/include/asm/dma-direct.h     |  2 +-
 arch/mips/loongson2ef/fuloong-2e/dma.c |  2 +-
 arch/mips/loongson2ef/lemote-2f/dma.c  |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/pci/pci-ar2315.c             |  2 +-
 arch/mips/pci/pci-xtalk-bridge.c       |  2 +-
 arch/mips/sgi-ip32/ip32-dma.c          |  2 +-
 arch/powerpc/include/asm/dma-direct.h  |  2 +-
 include/linux/dma-direct.h             | 14 +++++---------
 kernel/dma/direct.c                    |  6 +-----
 13 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
index 7c3001a6a775bf..a8cee87a93e8ab 100644
--- a/arch/arm/include/asm/dma-direct.h
+++ b/arch/arm/include/asm/dma-direct.h
@@ -8,7 +8,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
 	unsigned int offset = dev_addr & ~PAGE_MASK;
 	return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
index df56bf4179e347..ba2a5d33dfd3fa 100644
--- a/arch/mips/bmips/dma.c
+++ b/arch/mips/bmips/dma.c
@@ -52,7 +52,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
 	return pa;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	struct bmips_dma_range *r;
 
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index 14ea680d180e07..388b13ba2558c2 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -177,7 +177,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 #ifdef CONFIG_PCI
 	if (dev && dev_is_pci(dev))
diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
index 14e352651ce946..8e178651c638c2 100644
--- a/arch/mips/include/asm/dma-direct.h
+++ b/arch/mips/include/asm/dma-direct.h
@@ -3,6 +3,6 @@
 #define _MIPS_DMA_DIRECT_H 1
 
 dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
 
 #endif /* _MIPS_DMA_DIRECT_H */
diff --git a/arch/mips/loongson2ef/fuloong-2e/dma.c b/arch/mips/loongson2ef/fuloong-2e/dma.c
index e122292bf6660a..83fadeb3fd7d56 100644
--- a/arch/mips/loongson2ef/fuloong-2e/dma.c
+++ b/arch/mips/loongson2ef/fuloong-2e/dma.c
@@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr | 0x80000000;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr & 0x7fffffff;
 }
diff --git a/arch/mips/loongson2ef/lemote-2f/dma.c b/arch/mips/loongson2ef/lemote-2f/dma.c
index abf0e39d7e4696..302b43a14eee74 100644
--- a/arch/mips/loongson2ef/lemote-2f/dma.c
+++ b/arch/mips/loongson2ef/lemote-2f/dma.c
@@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr | 0x80000000;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	if (dma_addr > 0x8fffffff)
 		return dma_addr;
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index dbfe6e82fddd1c..b3dc5d0bd2b113 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -13,7 +13,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
 	 * Loongson-3's 48bit address space and embed it into 40bit */
diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c
index 490953f515282a..d88395684f487d 100644
--- a/arch/mips/pci/pci-ar2315.c
+++ b/arch/mips/pci/pci-ar2315.c
@@ -175,7 +175,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr + ar2315_dev_offset(dev);
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr - ar2315_dev_offset(dev);
 }
diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
index 9b3cc775c55e05..f1b37f32b55395 100644
--- a/arch/mips/pci/pci-xtalk-bridge.c
+++ b/arch/mips/pci/pci-xtalk-bridge.c
@@ -33,7 +33,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return bc->baddr + paddr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr & ~(0xffUL << 56);
 }
diff --git a/arch/mips/sgi-ip32/ip32-dma.c b/arch/mips/sgi-ip32/ip32-dma.c
index fa7b17cb53853e..160317294d97a9 100644
--- a/arch/mips/sgi-ip32/ip32-dma.c
+++ b/arch/mips/sgi-ip32/ip32-dma.c
@@ -27,7 +27,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return dma_addr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
 
diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
index abc154d784b078..95b09313d2a4cf 100644
--- a/arch/powerpc/include/asm/dma-direct.h
+++ b/arch/powerpc/include/asm/dma-direct.h
@@ -7,7 +7,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr + dev->archdata.dma_offset;
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 	return daddr - dev->archdata.dma_offset;
 }
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index 20eceb2e4f91f8..f00e262ab6b154 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -24,11 +24,12 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
-	phys_addr_t paddr = (phys_addr_t)dev_addr;
+	phys_addr_t paddr = (phys_addr_t)dev_addr +
+		((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 
-	return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
+	return __sme_clr(paddr);
 }
 #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
 
@@ -44,7 +45,7 @@ static inline bool force_dma_unencrypted(struct device *dev)
 /*
  * If memory encryption is supported, phys_to_dma will set the memory encryption
  * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
- * and __dma_to_phys versions should only be used on non-encrypted memory for
+ * version should only be used on non-encrypted memory for
  * special occasions like DMA coherent buffers.
  */
 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
@@ -52,11 +53,6 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return __sme_set(__phys_to_dma(dev, paddr));
 }
 
-static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
-{
-	return __sme_clr(__dma_to_phys(dev, daddr));
-}
-
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
 		bool is_ram)
 {
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 57a6e7d7cf8f16..bfb479c8a370fa 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -48,11 +48,6 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 {
 	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
 
-	if (force_dma_unencrypted(dev))
-		*phys_limit = __dma_to_phys(dev, dma_limit);
-	else
-		*phys_limit = dma_to_phys(dev, dma_limit);
-
 	/*
 	 * Optimistically try the zone that the physical address mask falls
 	 * into first.  If that returns memory that isn't actually addressable
@@ -61,6 +56,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 	 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
 	 * zones.
 	 */
+	*phys_limit = dma_to_phys(dev, dma_limit);
 	if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
 		return GFP_DMA;
 	if (*phys_limit <= DMA_BIT_MASK(32))
-- 
2.28.0


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

* [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-08 16:47   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-08 16:47 UTC (permalink / raw)
  To: Tony Luck, Fenghua Yu, Thomas Bogendoerfer, iommu
  Cc: linux-ia64, linux-doc, linux-kernel, linux-mips, Robin Murphy

There is no harm in just always clearing the SME encryption bit, while
significantly simplifying the interface.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/include/asm/dma-direct.h      |  2 +-
 arch/mips/bmips/dma.c                  |  2 +-
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/include/asm/dma-direct.h     |  2 +-
 arch/mips/loongson2ef/fuloong-2e/dma.c |  2 +-
 arch/mips/loongson2ef/lemote-2f/dma.c  |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/pci/pci-ar2315.c             |  2 +-
 arch/mips/pci/pci-xtalk-bridge.c       |  2 +-
 arch/mips/sgi-ip32/ip32-dma.c          |  2 +-
 arch/powerpc/include/asm/dma-direct.h  |  2 +-
 include/linux/dma-direct.h             | 14 +++++---------
 kernel/dma/direct.c                    |  6 +-----
 13 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
index 7c3001a6a775bf..a8cee87a93e8ab 100644
--- a/arch/arm/include/asm/dma-direct.h
+++ b/arch/arm/include/asm/dma-direct.h
@@ -8,7 +8,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
 	unsigned int offset = dev_addr & ~PAGE_MASK;
 	return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
index df56bf4179e347..ba2a5d33dfd3fa 100644
--- a/arch/mips/bmips/dma.c
+++ b/arch/mips/bmips/dma.c
@@ -52,7 +52,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
 	return pa;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	struct bmips_dma_range *r;
 
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index 14ea680d180e07..388b13ba2558c2 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -177,7 +177,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 #ifdef CONFIG_PCI
 	if (dev && dev_is_pci(dev))
diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
index 14e352651ce946..8e178651c638c2 100644
--- a/arch/mips/include/asm/dma-direct.h
+++ b/arch/mips/include/asm/dma-direct.h
@@ -3,6 +3,6 @@
 #define _MIPS_DMA_DIRECT_H 1
 
 dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
 
 #endif /* _MIPS_DMA_DIRECT_H */
diff --git a/arch/mips/loongson2ef/fuloong-2e/dma.c b/arch/mips/loongson2ef/fuloong-2e/dma.c
index e122292bf6660a..83fadeb3fd7d56 100644
--- a/arch/mips/loongson2ef/fuloong-2e/dma.c
+++ b/arch/mips/loongson2ef/fuloong-2e/dma.c
@@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr | 0x80000000;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr & 0x7fffffff;
 }
diff --git a/arch/mips/loongson2ef/lemote-2f/dma.c b/arch/mips/loongson2ef/lemote-2f/dma.c
index abf0e39d7e4696..302b43a14eee74 100644
--- a/arch/mips/loongson2ef/lemote-2f/dma.c
+++ b/arch/mips/loongson2ef/lemote-2f/dma.c
@@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr | 0x80000000;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	if (dma_addr > 0x8fffffff)
 		return dma_addr;
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index dbfe6e82fddd1c..b3dc5d0bd2b113 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -13,7 +13,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
 	 * Loongson-3's 48bit address space and embed it into 40bit */
diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c
index 490953f515282a..d88395684f487d 100644
--- a/arch/mips/pci/pci-ar2315.c
+++ b/arch/mips/pci/pci-ar2315.c
@@ -175,7 +175,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr + ar2315_dev_offset(dev);
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr - ar2315_dev_offset(dev);
 }
diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
index 9b3cc775c55e05..f1b37f32b55395 100644
--- a/arch/mips/pci/pci-xtalk-bridge.c
+++ b/arch/mips/pci/pci-xtalk-bridge.c
@@ -33,7 +33,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return bc->baddr + paddr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr & ~(0xffUL << 56);
 }
diff --git a/arch/mips/sgi-ip32/ip32-dma.c b/arch/mips/sgi-ip32/ip32-dma.c
index fa7b17cb53853e..160317294d97a9 100644
--- a/arch/mips/sgi-ip32/ip32-dma.c
+++ b/arch/mips/sgi-ip32/ip32-dma.c
@@ -27,7 +27,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return dma_addr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
 
diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
index abc154d784b078..95b09313d2a4cf 100644
--- a/arch/powerpc/include/asm/dma-direct.h
+++ b/arch/powerpc/include/asm/dma-direct.h
@@ -7,7 +7,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr + dev->archdata.dma_offset;
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 	return daddr - dev->archdata.dma_offset;
 }
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index 20eceb2e4f91f8..f00e262ab6b154 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -24,11 +24,12 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
-	phys_addr_t paddr = (phys_addr_t)dev_addr;
+	phys_addr_t paddr = (phys_addr_t)dev_addr +
+		((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 
-	return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
+	return __sme_clr(paddr);
 }
 #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
 
@@ -44,7 +45,7 @@ static inline bool force_dma_unencrypted(struct device *dev)
 /*
  * If memory encryption is supported, phys_to_dma will set the memory encryption
  * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
- * and __dma_to_phys versions should only be used on non-encrypted memory for
+ * version should only be used on non-encrypted memory for
  * special occasions like DMA coherent buffers.
  */
 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
@@ -52,11 +53,6 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return __sme_set(__phys_to_dma(dev, paddr));
 }
 
-static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
-{
-	return __sme_clr(__dma_to_phys(dev, daddr));
-}
-
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
 		bool is_ram)
 {
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 57a6e7d7cf8f16..bfb479c8a370fa 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -48,11 +48,6 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 {
 	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
 
-	if (force_dma_unencrypted(dev))
-		*phys_limit = __dma_to_phys(dev, dma_limit);
-	else
-		*phys_limit = dma_to_phys(dev, dma_limit);
-
 	/*
 	 * Optimistically try the zone that the physical address mask falls
 	 * into first.  If that returns memory that isn't actually addressable
@@ -61,6 +56,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 	 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
 	 * zones.
 	 */
+	*phys_limit = dma_to_phys(dev, dma_limit);
 	if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
 		return GFP_DMA;
 	if (*phys_limit <= DMA_BIT_MASK(32))
-- 
2.28.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 09/12] dma-direct: remove __dma_to_phys
@ 2020-09-08 16:47   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-09-08 16:47 UTC (permalink / raw)
  To: Tony Luck, Fenghua Yu, Thomas Bogendoerfer, iommu
  Cc: Tomasz Figa, Joerg Roedel, Robin Murphy, linux-doc, linux-kernel,
	linux-ia64, linux-mips

There is no harm in just always clearing the SME encryption bit, while
significantly simplifying the interface.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/include/asm/dma-direct.h      |  2 +-
 arch/mips/bmips/dma.c                  |  2 +-
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/include/asm/dma-direct.h     |  2 +-
 arch/mips/loongson2ef/fuloong-2e/dma.c |  2 +-
 arch/mips/loongson2ef/lemote-2f/dma.c  |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/pci/pci-ar2315.c             |  2 +-
 arch/mips/pci/pci-xtalk-bridge.c       |  2 +-
 arch/mips/sgi-ip32/ip32-dma.c          |  2 +-
 arch/powerpc/include/asm/dma-direct.h  |  2 +-
 include/linux/dma-direct.h             | 14 +++++---------
 kernel/dma/direct.c                    |  6 +-----
 13 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
index 7c3001a6a775bf..a8cee87a93e8ab 100644
--- a/arch/arm/include/asm/dma-direct.h
+++ b/arch/arm/include/asm/dma-direct.h
@@ -8,7 +8,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
 	unsigned int offset = dev_addr & ~PAGE_MASK;
 	return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
index df56bf4179e347..ba2a5d33dfd3fa 100644
--- a/arch/mips/bmips/dma.c
+++ b/arch/mips/bmips/dma.c
@@ -52,7 +52,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
 	return pa;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	struct bmips_dma_range *r;
 
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index 14ea680d180e07..388b13ba2558c2 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -177,7 +177,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 #ifdef CONFIG_PCI
 	if (dev && dev_is_pci(dev))
diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
index 14e352651ce946..8e178651c638c2 100644
--- a/arch/mips/include/asm/dma-direct.h
+++ b/arch/mips/include/asm/dma-direct.h
@@ -3,6 +3,6 @@
 #define _MIPS_DMA_DIRECT_H 1
 
 dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
 
 #endif /* _MIPS_DMA_DIRECT_H */
diff --git a/arch/mips/loongson2ef/fuloong-2e/dma.c b/arch/mips/loongson2ef/fuloong-2e/dma.c
index e122292bf6660a..83fadeb3fd7d56 100644
--- a/arch/mips/loongson2ef/fuloong-2e/dma.c
+++ b/arch/mips/loongson2ef/fuloong-2e/dma.c
@@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr | 0x80000000;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr & 0x7fffffff;
 }
diff --git a/arch/mips/loongson2ef/lemote-2f/dma.c b/arch/mips/loongson2ef/lemote-2f/dma.c
index abf0e39d7e4696..302b43a14eee74 100644
--- a/arch/mips/loongson2ef/lemote-2f/dma.c
+++ b/arch/mips/loongson2ef/lemote-2f/dma.c
@@ -6,7 +6,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr | 0x80000000;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	if (dma_addr > 0x8fffffff)
 		return dma_addr;
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index dbfe6e82fddd1c..b3dc5d0bd2b113 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -13,7 +13,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
 	 * Loongson-3's 48bit address space and embed it into 40bit */
diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c
index 490953f515282a..d88395684f487d 100644
--- a/arch/mips/pci/pci-ar2315.c
+++ b/arch/mips/pci/pci-ar2315.c
@@ -175,7 +175,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr + ar2315_dev_offset(dev);
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr - ar2315_dev_offset(dev);
 }
diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
index 9b3cc775c55e05..f1b37f32b55395 100644
--- a/arch/mips/pci/pci-xtalk-bridge.c
+++ b/arch/mips/pci/pci-xtalk-bridge.c
@@ -33,7 +33,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return bc->baddr + paddr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	return dma_addr & ~(0xffUL << 56);
 }
diff --git a/arch/mips/sgi-ip32/ip32-dma.c b/arch/mips/sgi-ip32/ip32-dma.c
index fa7b17cb53853e..160317294d97a9 100644
--- a/arch/mips/sgi-ip32/ip32-dma.c
+++ b/arch/mips/sgi-ip32/ip32-dma.c
@@ -27,7 +27,7 @@ dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return dma_addr;
 }
 
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dma_addr)
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
 {
 	phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
 
diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
index abc154d784b078..95b09313d2a4cf 100644
--- a/arch/powerpc/include/asm/dma-direct.h
+++ b/arch/powerpc/include/asm/dma-direct.h
@@ -7,7 +7,7 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return paddr + dev->archdata.dma_offset;
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
 	return daddr - dev->archdata.dma_offset;
 }
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index 20eceb2e4f91f8..f00e262ab6b154 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -24,11 +24,12 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 }
 
-static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
-	phys_addr_t paddr = (phys_addr_t)dev_addr;
+	phys_addr_t paddr = (phys_addr_t)dev_addr +
+		((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 
-	return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
+	return __sme_clr(paddr);
 }
 #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
 
@@ -44,7 +45,7 @@ static inline bool force_dma_unencrypted(struct device *dev)
 /*
  * If memory encryption is supported, phys_to_dma will set the memory encryption
  * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
- * and __dma_to_phys versions should only be used on non-encrypted memory for
+ * version should only be used on non-encrypted memory for
  * special occasions like DMA coherent buffers.
  */
 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
@@ -52,11 +53,6 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 	return __sme_set(__phys_to_dma(dev, paddr));
 }
 
-static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
-{
-	return __sme_clr(__dma_to_phys(dev, daddr));
-}
-
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
 		bool is_ram)
 {
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 57a6e7d7cf8f16..bfb479c8a370fa 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -48,11 +48,6 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 {
 	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
 
-	if (force_dma_unencrypted(dev))
-		*phys_limit = __dma_to_phys(dev, dma_limit);
-	else
-		*phys_limit = dma_to_phys(dev, dma_limit);
-
 	/*
 	 * Optimistically try the zone that the physical address mask falls
 	 * into first.  If that returns memory that isn't actually addressable
@@ -61,6 +56,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 	 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
 	 * zones.
 	 */
+	*phys_limit = dma_to_phys(dev, dma_limit);
 	if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
 		return GFP_DMA;
 	if (*phys_limit <= DMA_BIT_MASK(32))
-- 
2.28.0

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

end of thread, other threads:[~2020-09-11  7:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09 23:46 [PATCH 09/12] dma-direct: remove __dma_to_phys kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2020-09-08 16:47 dma-mapping cleanups Christoph Hellwig
2020-09-08 16:47 ` [PATCH 09/12] dma-direct: remove __dma_to_phys Christoph Hellwig
2020-09-08 16:47   ` Christoph Hellwig
2020-09-08 16:47   ` Christoph Hellwig
2020-09-10  9:45   ` Dan Carpenter
2020-09-10  9:45     ` Dan Carpenter
2020-09-11  7:12     ` Christoph Hellwig
2020-09-10 13:26   ` Robin Murphy
2020-09-10 13:26     ` Robin Murphy
2020-09-10 13:26     ` Robin Murphy
2020-09-11  7:14     ` Christoph Hellwig
2020-09-11  7:14       ` Christoph Hellwig
2020-09-11  7:14       ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.