Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1417008 > unrolled thread

[PATCH] arm64: mm: only initialize swiotlb when necessary

Started byJisheng Zhang <jszhang@marvell.com>
First post2016-06-08 10:00 +0200
Last post2016-06-08 14:20 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] arm64: mm: only initialize swiotlb when necessary Jisheng Zhang <jszhang@marvell.com> - 2016-06-08 10:00 +0200
    Re: [PATCH] arm64: mm: only initialize swiotlb when necessary Jisheng Zhang <jszhang@marvell.com> - 2016-06-08 10:10 +0200
    Re: [PATCH] arm64: mm: only initialize swiotlb when necessary Catalin Marinas <catalin.marinas@arm.com> - 2016-06-08 14:10 +0200
      Re: [PATCH] arm64: mm: only initialize swiotlb when necessary Arnd Bergmann <arnd@arndb.de> - 2016-06-08 17:50 +0200
    Re: [PATCH] arm64: mm: only initialize swiotlb when necessary Catalin Marinas <catalin.marinas@arm.com> - 2016-06-08 14:20 +0200

#1417008 — [PATCH] arm64: mm: only initialize swiotlb when necessary

FromJisheng Zhang <jszhang@marvell.com>
Date2016-06-08 10:00 +0200
Subject[PATCH] arm64: mm: only initialize swiotlb when necessary
Message-ID<rHGz9-5Mb-35@gated-at.bofh.it>
we only initialize swiotlb when swiotlb_force is true or not all system
memory is DMA-able, this trivial optimization saves us 64MB when
swiotlb is not necessary.

Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
---
 arch/arm64/mm/dma-mapping.c | 15 ++++++++++++++-
 arch/arm64/mm/init.c        |  3 ++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index c566ec8..46a4157 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -19,6 +19,7 @@
 
 #include <linux/gfp.h>
 #include <linux/acpi.h>
+#include <linux/bootmem.h>
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/genalloc.h>
@@ -29,6 +30,8 @@
 
 #include <asm/cacheflush.h>
 
+static int swiotlb __read_mostly;
+
 static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot,
 				 bool coherent)
 {
@@ -341,6 +344,13 @@ static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt,
 	return ret;
 }
 
+static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
+{
+	if (swiotlb)
+		return swiotlb_dma_supported(hwdev, mask);
+	return 1;
+}
+
 static struct dma_map_ops swiotlb_dma_ops = {
 	.alloc = __dma_alloc,
 	.free = __dma_free,
@@ -354,7 +364,7 @@ static struct dma_map_ops swiotlb_dma_ops = {
 	.sync_single_for_device = __swiotlb_sync_single_for_device,
 	.sync_sg_for_cpu = __swiotlb_sync_sg_for_cpu,
 	.sync_sg_for_device = __swiotlb_sync_sg_for_device,
-	.dma_supported = swiotlb_dma_supported,
+	.dma_supported = __swiotlb_dma_supported,
 	.mapping_error = swiotlb_dma_mapping_error,
 };
 
@@ -513,6 +523,9 @@ EXPORT_SYMBOL(dummy_dma_ops);
 
 static int __init arm64_dma_init(void)
 {
+	if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
+		swiotlb = 1;
+
 	return atomic_pool_init();
 }
 arch_initcall(arm64_dma_init);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index d45f862..7d25b4d 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -403,7 +403,8 @@ static void __init free_unused_memmap(void)
  */
 void __init mem_init(void)
 {
-	swiotlb_init(1);
+	if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
+		swiotlb_init(1);
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
 
-- 
2.8.1

[toc] | [next] | [standalone]


#1417017

FromJisheng Zhang <jszhang@marvell.com>
Date2016-06-08 10:10 +0200
Message-ID<rHGIN-64G-25@gated-at.bofh.it>
In reply to#1417008
Dear all,

On Wed, 8 Jun 2016 15:53:46 +0800 Jisheng Zhang wrote:

> we only initialize swiotlb when swiotlb_force is true or not all system
> memory is DMA-able, this trivial optimization saves us 64MB when
> swiotlb is not necessary.

another solution is to call swiotlb_free() as ppc does. Either solution can
solve my problem. If maintainers prefer that solution, I can send a v2 patch.

Thanks,
Jisheng

> 
> Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
> ---
>  arch/arm64/mm/dma-mapping.c | 15 ++++++++++++++-
>  arch/arm64/mm/init.c        |  3 ++-
>  2 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
> index c566ec8..46a4157 100644
> --- a/arch/arm64/mm/dma-mapping.c
> +++ b/arch/arm64/mm/dma-mapping.c
> @@ -19,6 +19,7 @@
>  
>  #include <linux/gfp.h>
>  #include <linux/acpi.h>
> +#include <linux/bootmem.h>
>  #include <linux/export.h>
>  #include <linux/slab.h>
>  #include <linux/genalloc.h>
> @@ -29,6 +30,8 @@
>  
>  #include <asm/cacheflush.h>
>  
> +static int swiotlb __read_mostly;
> +
>  static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot,
>  				 bool coherent)
>  {
> @@ -341,6 +344,13 @@ static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt,
>  	return ret;
>  }
>  
> +static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
> +{
> +	if (swiotlb)
> +		return swiotlb_dma_supported(hwdev, mask);
> +	return 1;
> +}
> +
>  static struct dma_map_ops swiotlb_dma_ops = {
>  	.alloc = __dma_alloc,
>  	.free = __dma_free,
> @@ -354,7 +364,7 @@ static struct dma_map_ops swiotlb_dma_ops = {
>  	.sync_single_for_device = __swiotlb_sync_single_for_device,
>  	.sync_sg_for_cpu = __swiotlb_sync_sg_for_cpu,
>  	.sync_sg_for_device = __swiotlb_sync_sg_for_device,
> -	.dma_supported = swiotlb_dma_supported,
> +	.dma_supported = __swiotlb_dma_supported,
>  	.mapping_error = swiotlb_dma_mapping_error,
>  };
>  
> @@ -513,6 +523,9 @@ EXPORT_SYMBOL(dummy_dma_ops);
>  
>  static int __init arm64_dma_init(void)
>  {
> +	if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
> +		swiotlb = 1;
> +
>  	return atomic_pool_init();
>  }
>  arch_initcall(arm64_dma_init);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index d45f862..7d25b4d 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -403,7 +403,8 @@ static void __init free_unused_memmap(void)
>   */
>  void __init mem_init(void)
>  {
> -	swiotlb_init(1);
> +	if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
> +		swiotlb_init(1);
>  
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
>  

[toc] | [prev] | [next] | [standalone]


#1417333

FromCatalin Marinas <catalin.marinas@arm.com>
Date2016-06-08 14:10 +0200
Message-ID<rHKt3-8pd-3@gated-at.bofh.it>
In reply to#1417008
On Wed, Jun 08, 2016 at 03:53:46PM +0800, Jisheng Zhang wrote:
>  static int __init arm64_dma_init(void)
>  {
> +	if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
> +		swiotlb = 1;
> +
>  	return atomic_pool_init();
>  }

So any platform with RAM larger than 4GB would still initialise swiotlb.
I wouldn't say it's an issue, 64MB is not a significant loss on such
systems.

An alternative would be to defer the freeing until we are aware of all
possible dma masks for the populated devices (e.g. from DT), though I'm
not sure that's enough, drivers may try to change such masks when
probed.

-- 
Catalin

[toc] | [prev] | [next] | [standalone]


#1417602

FromArnd Bergmann <arnd@arndb.de>
Date2016-06-08 17:50 +0200
Message-ID<rHNTY-21z-23@gated-at.bofh.it>
In reply to#1417333
On Wednesday, June 8, 2016 1:08:29 PM CEST Catalin Marinas wrote:
> On Wed, Jun 08, 2016 at 03:53:46PM +0800, Jisheng Zhang wrote:
> >  static int __init arm64_dma_init(void)
> >  {
> > +     if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
> > +             swiotlb = 1;
> > +
> >       return atomic_pool_init();
> >  }
> 
> So any platform with RAM larger than 4GB would still initialise swiotlb.
> I wouldn't say it's an issue, 64MB is not a significant loss on such
> systems.
> 
> An alternative would be to defer the freeing until we are aware of all
> possible dma masks for the populated devices (e.g. from DT), though I'm
> not sure that's enough, drivers may try to change such masks when
> probed.

Right, this is a hard problem, because you can in theory have odd devices
that require a DMA mask lower than the limit of ZONE_DMA.

In the kernel sources, I find these:

# git grep DMA_BIT_MASK | grep -v 'DMA_BIT_MASK(\(3[2-9]\|[456][0-9]\))'
arch/arm/mach-ixp4xx/common.c:		dev->coherent_dma_mask = DMA_BIT_MASK(28); /* 64 MB */
drivers/base/isa.c:		isa_dev->dev.coherent_dma_mask = DMA_BIT_MASK(24);
drivers/media/pci/sta2x11/sta2x11_vip.c:	err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29));
drivers/media/pci/sta2x11/sta2x11_vip.c:	if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(26))) {
drivers/net/ethernet/broadcom/b44.c:		mapping + RX_PKT_BUF_SZ > DMA_BIT_MASK(30)) {
drivers/net/ethernet/broadcom/b44.c:		    mapping + RX_PKT_BUF_SZ > DMA_BIT_MASK(30)) {
drivers/net/ethernet/broadcom/b44.c:	if (dma_mapping_error(bp->sdev->dma_dev, mapping) || mapping + len > DMA_BIT_MASK(30)) {
drivers/net/ethernet/broadcom/b44.c:		if (dma_mapping_error(bp->sdev->dma_dev, mapping) || mapping + len > DMA_BIT_MASK(30)) {
drivers/net/ethernet/broadcom/b44.c:			rx_ring_dma + size > DMA_BIT_MASK(30)) {
drivers/net/ethernet/broadcom/b44.c:			tx_ring_dma + size > DMA_BIT_MASK(30)) {
drivers/net/ethernet/broadcom/b44.c:	if (dma_set_mask_and_coherent(sdev->dma_dev, DMA_BIT_MASK(30))) {
drivers/net/wan/wanxl.c:	if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(28)) ||
drivers/net/wan/wanxl.c:	    pci_set_dma_mask(pdev, DMA_BIT_MASK(28))) {
drivers/net/wireless/broadcom/b43/dma.c:	return DMA_BIT_MASK(30);
drivers/net/wireless/broadcom/b43/dma.c:	if (dmamask == DMA_BIT_MASK(30))
drivers/net/wireless/broadcom/b43/dma.c:			mask = DMA_BIT_MASK(30);
drivers/net/wireless/broadcom/b43legacy/dma.c:	return DMA_BIT_MASK(30);
drivers/net/wireless/broadcom/b43legacy/dma.c:	if (dmamask == DMA_BIT_MASK(30))
drivers/net/wireless/broadcom/b43legacy/dma.c:			mask = DMA_BIT_MASK(30);
drivers/parport/parport_pc.c:		ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(24));
drivers/pnp/card.c:	card->dev.coherent_dma_mask = DMA_BIT_MASK(24);
drivers/pnp/core.c:	dev->dma_mask = DMA_BIT_MASK(24);
drivers/scsi/aacraid/commsup.c:		if (((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(31)))) ||
drivers/scsi/aacraid/commsup.c:		  ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_BIT_MASK(31)))))
drivers/scsi/aacraid/linit.c:		dmamask = DMA_BIT_MASK(31);
drivers/usb/host/ehci-pci.c:						DMA_BIT_MASK(31)) < 0)
include/linux/blkdev.h:#define BLK_BOUNCE_ISA		(DMA_BIT_MASK(24))
sound/pci/ali5451/ali5451.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(31)) < 0 ||
sound/pci/als300.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 ||
sound/pci/als4000.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
sound/pci/azt3328.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
sound/pci/emu10k1/emu10k1x.c:	if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
sound/pci/es1938.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
sound/pci/es1968.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 ||
sound/pci/ice1712/ice1712.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 ||
sound/pci/maestro3.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 ||
sound/pci/sis7019.c:	rc = dma_set_mask(&pci->dev, DMA_BIT_MASK(30));
sound/pci/sonicvibes.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
sound/pci/trident/trident_main.c:	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(30)) < 0 ||
sound/pci/trident/trident_main.c:	    dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(30)) < 0) {
sound/soc/intel/common/sst-firmware.c:	err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(31));
sound/soc/intel/haswell/sst-haswell-dsp.c:	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(31));

	Arnd

[toc] | [prev] | [next] | [standalone]


#1417340

FromCatalin Marinas <catalin.marinas@arm.com>
Date2016-06-08 14:20 +0200
Message-ID<rHKCJ-8sB-1@gated-at.bofh.it>
In reply to#1417008
On Wed, Jun 08, 2016 at 03:53:46PM +0800, Jisheng Zhang wrote:
> --- a/arch/arm64/mm/dma-mapping.c
> +++ b/arch/arm64/mm/dma-mapping.c
> @@ -19,6 +19,7 @@
>  
>  #include <linux/gfp.h>
>  #include <linux/acpi.h>
> +#include <linux/bootmem.h>
>  #include <linux/export.h>
>  #include <linux/slab.h>
>  #include <linux/genalloc.h>

Why is this include needed?

-- 
Catalin

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web