From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:09:46
A lot of architectures have essentially identical dma_map_ops
implementations to use swiotlb. This series adds new generic
swiotlb_alloc/free helpers that take the attrs argument exposed
in dma_map_ops, and which do an enhanced direct allocation
modelled after x86 and reused from the dma-direct code, and
then switches most architectures over to it. The only exceptions
are mips, which requires additional cache flushing which will
need a new abstraction, and x86 itself which will be handled in
a later series with other x86 dma mapping changes.
To support the generic code a few architectures that currently
use ZONE_DMA/GFP_DMA for <= 32-bit allocations are switched to
implement ZONE_DMA32 instead.
This series is based on the previously sent series to consolidate
the direct dma mapping implementation. A git tree with this
series as well as the prerequisites is available here:
git://git.infradead.org/users/hch/misc.git swiotlb
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:09:48
From: Christian K?nig <ckoenig.leichtzumerken@gmail.com>
TTM tries to allocate coherent memory in chunks of 2MB first to improve
TLB efficiency and falls back to allocating 4K pages if that fails.
Suppress the warning when the 2MB allocations fails since there is a
valid fall back path.
Signed-off-by: Christian K?nig <christian.koenig@amd.com>
Reported-by: Mike Galbraith <redacted>
Acked-by: Konrad Rzeszutek Wilk <redacted>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104082
CC: stable at vger.kernel.org
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
lib/swiotlb.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:09:52
We'll need that name for a generic implementation soon.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/arm64/mm/dma-mapping.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -89,7 +89,7 @@ static int ppc_swiotlb_bus_notify(struct notifier_block *nb,/* May need to bounce if the device can't address all of DRAM */if((dma_get_mask(dev)+1)<memblock_end_of_DRAM())-set_dma_ops(dev,&swiotlb_dma_ops);+set_dma_ops(dev,&powerpc_swiotlb_dma_ops);returnNOTIFY_DONE;}
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:06
Currently all architectures that want to use swiotlb have to implement
their own dma_map_ops instances. Provide a generic one based on the
x86 implementation which first calls into dma_direct to try a full blown
direct mapping implementation (including e.g. CMA) before falling back
allocating from the swiotlb buffer.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/swiotlb.h | 8 ++++++++
lib/swiotlb.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:11
Factor out a new swiotlb_free_buffer helper that checks if an address
is allocated from the swiotlb bounce buffer, and if yes frees it.
This allows to simplify the swiotlb_free implemenation that uses
dma_direct_free to free the non-bounce buffer allocations.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
lib/swiotlb.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:18
All these symbols are only used by arch dma_ops implementations or
xen-swiotlb. None of which can be modular.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
lib/swiotlb.c | 13 -------------
1 file changed, 13 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:25
These are identical to the ia64 ops, and would also support CMA
if enabled on ia64.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/ia64/Kconfig | 5 +++++
arch/ia64/hp/common/hwsw_iommu.c | 4 ++--
arch/ia64/hp/common/sba_iommu.c | 6 +++---
arch/ia64/kernel/pci-swiotlb.c | 38 +++-----------------------------------
4 files changed, 13 insertions(+), 40 deletions(-)
@@ -2096,7 +2096,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */arch_initcall(acpi_sba_ioc_init_acpi);-externconststructdma_map_opsia64_swiotlb_dma_ops;+externconststructdma_map_opsswiotlb_dma_ops;staticint__initsba_init(void)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:33
These are identical to the unicore32 ops, and would also support CMA
if enabled on unicore32.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/unicore32/include/asm/dma-mapping.h | 9 +-----
arch/unicore32/mm/Kconfig | 1 +
arch/unicore32/mm/Makefile | 2 --
arch/unicore32/mm/dma-swiotlb.c | 48 --------------------------------
4 files changed, 2 insertions(+), 58 deletions(-)
delete mode 100644 arch/unicore32/mm/dma-swiotlb.c
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:36
These are identical to the tile ops, and would also support CMA
if enabled on tile.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/tile/Kconfig | 1 +
arch/tile/kernel/pci-dma.c | 36 +++---------------------------------
2 files changed, 4 insertions(+), 33 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:43
nlm_swiotlb_dma_ops is unused code, so the whole swiotlb support is dead.
If it gets resurrected at some point it should use the generic
swiotlb_dma_ops instead.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/mips/include/asm/netlogic/common.h | 3 --
arch/mips/netlogic/Kconfig | 5 --
arch/mips/netlogic/common/Makefile | 1 -
arch/mips/netlogic/common/nlm-dma.c | 94 ---------------------------------
4 files changed, 103 deletions(-)
delete mode 100644 arch/mips/netlogic/common/nlm-dma.c
@@ -1,94 +0,0 @@-/*-* Copyright (C) 2003-2013 Broadcom Corporation-* All Rights Reserved- *- * This software is available to you under a choice of one of two- * licenses. You may choose to be licensed under the terms of the GNU- * General Public License (GPL) Version 2, available from the file- * COPYING in the main directory of this source tree, or the Broadcom- * license below:- *- * Redistribution and use in source and binary forms, with or without- * modification, are permitted provided that the following conditions- * are met:- *- * 1. Redistributions of source code must retain the above copyright- * notice, this list of conditions and the following disclaimer.- * 2. Redistributions in binary form must reproduce the above copyright- * notice, this list of conditions and the following disclaimer in- * the documentation and/or other materials provided with the- * distribution.- *- * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE- * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- */-#include <linux/dma-mapping.h>-#include <linux/scatterlist.h>-#include <linux/bootmem.h>-#include <linux/export.h>-#include <linux/swiotlb.h>-#include <linux/types.h>-#include <linux/init.h>-#include <linux/mm.h>--#include <asm/bootinfo.h>--static char *nlm_swiotlb;--static void *nlm_dma_alloc_coherent(struct device *dev, size_t size,- dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)-{-#ifdef CONFIG_ZONE_DMA32- if (dev->coherent_dma_mask <= DMA_BIT_MASK(32))- gfp |= __GFP_DMA32;-#endif-- /* Don't invoke OOM killer */- gfp |= __GFP_NORETRY;-- return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);-}--static void nlm_dma_free_coherent(struct device *dev, size_t size,- void *vaddr, dma_addr_t dma_handle, unsigned long attrs)-{- swiotlb_free_coherent(dev, size, vaddr, dma_handle);-}--const struct dma_map_ops nlm_swiotlb_dma_ops = {- .alloc = nlm_dma_alloc_coherent,- .free = nlm_dma_free_coherent,- .map_page = swiotlb_map_page,- .unmap_page = swiotlb_unmap_page,- .map_sg = swiotlb_map_sg_attrs,- .unmap_sg = swiotlb_unmap_sg_attrs,- .sync_single_for_cpu = swiotlb_sync_single_for_cpu,- .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,- .mapping_error = swiotlb_dma_mapping_error,- .dma_supported = swiotlb_dma_supported-};--void __init plat_swiotlb_setup(void)-{- size_t swiotlbsize;- unsigned long swiotlb_nslabs;-- swiotlbsize = 1 << 20; /* 1 MB for now */- swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;- swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);- swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;-- nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);- swiotlb_init_with_tbl(nlm_swiotlb, swiotlb_nslabs, 1);-}
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:50
arm64 uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/arm64/Kconfig | 2 +-
arch/arm64/mm/dma-mapping.c | 6 +++---
arch/arm64/mm/init.c | 16 ++++++++--------
3 files changed, 12 insertions(+), 12 deletions(-)
@@ -233,8 +233,8 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max){unsignedlongmax_zone_pfns[MAX_NR_ZONES]={0};-if(IS_ENABLED(CONFIG_ZONE_DMA))-max_zone_pfns[ZONE_DMA]=PFN_DOWN(max_zone_dma_phys());+if(IS_ENABLED(CONFIG_ZONE_DMA32))+max_zone_pfns[ZONE_DMA32]=PFN_DOWN(max_zone_dma_phys());max_zone_pfns[ZONE_NORMAL]=max;free_area_init_nodes(max_zone_pfns);
@@ -251,9 +251,9 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)memset(zone_size,0,sizeof(zone_size));/* 4GB maximum for 32-bit only capable devices */-#ifdef CONFIG_ZONE_DMA+#ifdef CONFIG_ZONE_DMA32max_dma=PFN_DOWN(arm64_dma_phys_limit);-zone_size[ZONE_DMA]=max_dma-min;+zone_size[ZONE_DMA32]=max_dma-min;#endifzone_size[ZONE_NORMAL]=max-max_dma;
@@ -266,10 +266,10 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)if(start>=max)continue;-#ifdef CONFIG_ZONE_DMA+#ifdef CONFIG_ZONE_DMA32if(start<max_dma){unsignedlongdma_end=min(end,max_dma);-zhole_size[ZONE_DMA]-=dma_end-start;+zhole_size[ZONE_DMA32]-=dma_end-start;}#endifif(end>max_dma){
@@ -467,7 +467,7 @@ void __init arm64_memblock_init(void)early_init_fdt_scan_reserved_mem();/* 4GB maximum for 32-bit only capable devices */-if(IS_ENABLED(CONFIG_ZONE_DMA))+if(IS_ENABLED(CONFIG_ZONE_DMA32))arm64_dma_phys_limit=max_zone_dma_phys();elsearm64_dma_phys_limit=PHYS_MASK+1;
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:10:54
The generic swiotlb_alloc and swiotlb_free routines already take care
of CMA allocations and adding GFP_DMA32 where needed, so use them
instead of the arm specific helpers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/arm64/Kconfig | 1 +
arch/arm64/mm/dma-mapping.c | 46 +++------------------------------------------
2 files changed, 4 insertions(+), 43 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:12:32
tile uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/tile/Kconfig | 2 +-
arch/tile/kernel/pci-dma.c | 4 ++--
arch/tile/kernel/setup.c | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)
@@ -814,11 +814,11 @@ static void __init zone_sizes_init(void)#endifif(start<dma_end){-zones_size[ZONE_DMA]=min(zones_size[ZONE_NORMAL],+zones_size[ZONE_DMA32]=min(zones_size[ZONE_NORMAL],dma_end-start);-zones_size[ZONE_NORMAL]-=zones_size[ZONE_DMA];+zones_size[ZONE_NORMAL]-=zones_size[ZONE_DMA32];}else{-zones_size[ZONE_DMA]=0;+zones_size[ZONE_DMA32]=0;}/* Take zone metadata from controller 0 if we're isolnode. */
@@ -830,7 +830,7 @@ static void __init zone_sizes_init(void)PFN_UP(node_percpu[i]));/* Track the type of memory on each node */-if(zones_size[ZONE_NORMAL]||zones_size[ZONE_DMA])+if(zones_size[ZONE_NORMAL]||zones_size[ZONE_DMA32])node_set_state(i,N_NORMAL_MEMORY);#ifdef CONFIG_HIGHMEMif(end!=start)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:12:34
The file is only compiled if CONFIG_INTEL_IOMMU is set to start with.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/ia64/kernel/pci-dma.c | 7 -------
1 file changed, 7 deletions(-)
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0#include<linux/dma-mapping.h>+#include<linux/swiotlb.h>#include<linux/export.h>/* Set this to 1 if there is a HW IOMMU in the system */
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:13:52
ia64 uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/ia64/Kconfig | 2 +-
arch/ia64/kernel/pci-swiotlb.c | 2 +-
arch/ia64/mm/contig.c | 4 ++--
arch/ia64/mm/discontig.c | 8 ++++----
4 files changed, 8 insertions(+), 8 deletions(-)
@@ -669,7 +669,7 @@ static __init int count_node_pages(unsigned long start, unsigned long len, int n{unsignedlongend=start+len;-#ifdef CONFIG_ZONE_DMA+#ifdef CONFIG_ZONE_DMA32if(start<=__pa(MAX_DMA_ADDRESS))mem_data[node].num_dma_physpages+=(min(end,__pa(MAX_DMA_ADDRESS))-start)>>PAGE_SHIFT;
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:14:11
Factor out a new swiotlb_alloc_buffer helper that allocates DMA coherent
memory from the swiotlb bounce buffer.
This allows to simplify the swiotlb_alloc implemenation that uses
dma_direct_alloc to try to allocate a reachable buffer first.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
lib/swiotlb.c | 122 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 65 insertions(+), 57 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:15:02
To properly reject too small DMA masks based on the addressability of the
bounce buffer.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
lib/swiotlb.c | 1 +
1 file changed, 1 insertion(+)
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 08:15:44
We'll need that name for a generic implementation soon.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/x86/kernel/pci-swiotlb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -2096,7 +2096,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */arch_initcall(acpi_sba_ioc_init_acpi);-externconststructdma_map_opsswiotlb_dma_ops;+externconststructdma_map_opsia64_swiotlb_dma_ops;staticint__initsba_init(void)
From: Christian König <ckoenig.leichtzumerken@gmail.com> Date: 2018-01-10 08:23:15
Acked-by: Christian K?nig <christian.koenig@amd.com> for the whole series.
Regards,
Christian.
Am 10.01.2018 um 09:09 schrieb Christoph Hellwig:
A lot of architectures have essentially identical dma_map_ops
implementations to use swiotlb. This series adds new generic
swiotlb_alloc/free helpers that take the attrs argument exposed
in dma_map_ops, and which do an enhanced direct allocation
modelled after x86 and reused from the dma-direct code, and
then switches most architectures over to it. The only exceptions
are mips, which requires additional cache flushing which will
need a new abstraction, and x86 itself which will be handled in
a later series with other x86 dma mapping changes.
To support the generic code a few architectures that currently
use ZONE_DMA/GFP_DMA for <= 32-bit allocations are switched to
implement ZONE_DMA32 instead.
This series is based on the previously sent series to consolidate
the direct dma mapping implementation. A git tree with this
series as well as the prerequisites is available here:
git://git.infradead.org/users/hch/misc.git swiotlb
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb
From: Robin Murphy <robin.murphy@arm.com> Date: 2018-01-10 12:22:27
On 10/01/18 08:09, Christoph Hellwig wrote:
quoted hunk
Factor out a new swiotlb_alloc_buffer helper that allocates DMA coherent
memory from the swiotlb bounce buffer.
This allows to simplify the swiotlb_alloc implemenation that uses
dma_direct_alloc to try to allocate a reachable buffer first.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
lib/swiotlb.c | 122 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 65 insertions(+), 57 deletions(-)
From: Robin Murphy <robin.murphy@arm.com> Date: 2018-01-10 12:58:34
On 10/01/18 08:09, Christoph Hellwig wrote:
arm64 uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
I do wonder if we could also "upgrade" GFP_DMA to GFP_DMA32 somehow when
!ZONE_DMA - there are almost certainly arm64 drivers out there using a
combination of GFP_DMA and streaming mappings which will no longer get
the guaranteed 32-bit addresses they expect after this. I'm not sure
quite how feasible that is, though :/
That said, I do agree that this is an appropriate change (the legacy of
GFP_DMA is obviously horrible), so, provided we get plenty of time to
find and fix the fallout when it lands:
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Robin.
@@ -233,8 +233,8 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max){unsignedlongmax_zone_pfns[MAX_NR_ZONES]={0};-if(IS_ENABLED(CONFIG_ZONE_DMA))-max_zone_pfns[ZONE_DMA]=PFN_DOWN(max_zone_dma_phys());+if(IS_ENABLED(CONFIG_ZONE_DMA32))+max_zone_pfns[ZONE_DMA32]=PFN_DOWN(max_zone_dma_phys());max_zone_pfns[ZONE_NORMAL]=max;free_area_init_nodes(max_zone_pfns);
@@ -251,9 +251,9 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)memset(zone_size,0,sizeof(zone_size));/* 4GB maximum for 32-bit only capable devices */-#ifdef CONFIG_ZONE_DMA+#ifdef CONFIG_ZONE_DMA32max_dma=PFN_DOWN(arm64_dma_phys_limit);-zone_size[ZONE_DMA]=max_dma-min;+zone_size[ZONE_DMA32]=max_dma-min;#endifzone_size[ZONE_NORMAL]=max-max_dma;
@@ -266,10 +266,10 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)if(start>=max)continue;-#ifdef CONFIG_ZONE_DMA+#ifdef CONFIG_ZONE_DMA32if(start<max_dma){unsignedlongdma_end=min(end,max_dma);-zhole_size[ZONE_DMA]-=dma_end-start;+zhole_size[ZONE_DMA32]-=dma_end-start;}#endifif(end>max_dma){
@@ -467,7 +467,7 @@ void __init arm64_memblock_init(void)early_init_fdt_scan_reserved_mem();/* 4GB maximum for 32-bit only capable devices */-if(IS_ENABLED(CONFIG_ZONE_DMA))+if(IS_ENABLED(CONFIG_ZONE_DMA32))arm64_dma_phys_limit=max_zone_dma_phys();elsearm64_dma_phys_limit=PHYS_MASK+1;
From: Robin Murphy <robin.murphy@arm.com> Date: 2018-01-10 13:16:23
On 10/01/18 08:09, Christoph Hellwig wrote:
The generic swiotlb_alloc and swiotlb_free routines already take care
of CMA allocations and adding GFP_DMA32 where needed, so use them
instead of the arm specific helpers.
It took a while to satisfy myself that the GFP_DMA(32) handling ends up
equivalent to the current behaviour, but I think it checks out. This
will certainly help with the long-overdue cleanup of this file that I've
had sat around half-finished for ages.
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 15:46:53
On Wed, Jan 10, 2018 at 12:22:18PM +0000, Robin Murphy wrote:
quoted
+ if (phys_addr == SWIOTLB_MAP_ERROR)
+ goto out_warn;
- /* Confirm address can be DMA'd by device */
- if (dev_addr + size - 1 > dma_mask) {
- printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n",
- (unsigned long long)dma_mask,
- (unsigned long long)dev_addr);
+ *dma_handle = swiotlb_phys_to_dma(dev, phys_addr);
nit: this should probably go after the dma_coherent_ok() check (as with the
original logic).
But the originall logic also needs the dma_addr_t for the
dma_coherent_ok check:
dev_addr = swiotlb_phys_to_dma(hwdev, paddr);
/* Confirm address can be DMA'd by device */
if (dev_addr + size - 1 > dma_mask) {
...
goto err_warn;
}
or do you mean assining to *dma_handle? The dma_handle is not
valid for a failure return, so I don't think this should matter.
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 15:55:21
On Wed, Jan 10, 2018 at 12:58:14PM +0000, Robin Murphy wrote:
On 10/01/18 08:09, Christoph Hellwig wrote:
quoted
arm64 uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
I do wonder if we could also "upgrade" GFP_DMA to GFP_DMA32 somehow when
!ZONE_DMA - there are almost certainly arm64 drivers out there using a
combination of GFP_DMA and streaming mappings which will no longer get the
guaranteed 32-bit addresses they expect after this. I'm not sure quite how
feasible that is, though :/
I can't find anything obvious in the tree. The alternative would be
to keep ZONE_DMA and set ARCH_ZONE_DMA_BITS.
That said, I do agree that this is an appropriate change (the legacy of
GFP_DMA is obviously horrible), so, provided we get plenty of time to find
and fix the fallout when it lands:
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
I was hoping to get this into 4.15. What would be proper time to
fix the fallout?
From: Christoph Hellwig <hch@lst.de> Date: 2018-01-10 15:55:50
On Wed, Jan 10, 2018 at 04:55:17PM +0100, Christoph Hellwig wrote:
On Wed, Jan 10, 2018 at 12:58:14PM +0000, Robin Murphy wrote:
quoted
On 10/01/18 08:09, Christoph Hellwig wrote:
quoted
arm64 uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
I do wonder if we could also "upgrade" GFP_DMA to GFP_DMA32 somehow when
!ZONE_DMA - there are almost certainly arm64 drivers out there using a
combination of GFP_DMA and streaming mappings which will no longer get the
guaranteed 32-bit addresses they expect after this. I'm not sure quite how
feasible that is, though :/
I can't find anything obvious in the tree. The alternative would be
to keep ZONE_DMA and set ARCH_ZONE_DMA_BITS.
quoted
That said, I do agree that this is an appropriate change (the legacy of
GFP_DMA is obviously horrible), so, provided we get plenty of time to find
and fix the fallout when it lands:
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
I was hoping to get this into 4.15. What would be proper time to
fix the fallout?
From: Robin Murphy <robin.murphy@arm.com> Date: 2018-01-10 17:02:36
On 10/01/18 15:46, Christoph Hellwig wrote:
On Wed, Jan 10, 2018 at 12:22:18PM +0000, Robin Murphy wrote:
quoted
quoted
+ if (phys_addr == SWIOTLB_MAP_ERROR)
+ goto out_warn;
- /* Confirm address can be DMA'd by device */
- if (dev_addr + size - 1 > dma_mask) {
- printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n",
- (unsigned long long)dma_mask,
- (unsigned long long)dev_addr);
+ *dma_handle = swiotlb_phys_to_dma(dev, phys_addr);
nit: this should probably go after the dma_coherent_ok() check (as with the
original logic).
But the originall logic also needs the dma_addr_t for the
dma_coherent_ok check:
dev_addr = swiotlb_phys_to_dma(hwdev, paddr);
/* Confirm address can be DMA'd by device */
if (dev_addr + size - 1 > dma_mask) {
...
goto err_warn;
}
or do you mean assining to *dma_handle? The dma_handle is not
valid for a failure return, so I don't think this should matter.
Yeah, only the assignment - as I said, it's just a stylistic nit; no big
deal either way.
From: Robin Murphy <robin.murphy@arm.com> Date: 2018-01-10 17:10:09
On 10/01/18 15:55, Christoph Hellwig wrote:
On Wed, Jan 10, 2018 at 04:55:17PM +0100, Christoph Hellwig wrote:
quoted
On Wed, Jan 10, 2018 at 12:58:14PM +0000, Robin Murphy wrote:
quoted
On 10/01/18 08:09, Christoph Hellwig wrote:
quoted
arm64 uses ZONE_DMA for allocations below 32-bits. These days we
name the zone for that ZONE_DMA32, which will allow to use the
dma-direct and generic swiotlb code as-is, so rename it.
I do wonder if we could also "upgrade" GFP_DMA to GFP_DMA32 somehow when
!ZONE_DMA - there are almost certainly arm64 drivers out there using a
combination of GFP_DMA and streaming mappings which will no longer get the
guaranteed 32-bit addresses they expect after this. I'm not sure quite how
feasible that is, though :/
I can't find anything obvious in the tree. The alternative would be
to keep ZONE_DMA and set ARCH_ZONE_DMA_BITS.
quoted
That said, I do agree that this is an appropriate change (the legacy of
GFP_DMA is obviously horrible), so, provided we get plenty of time to find
and fix the fallout when it lands:
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
I was hoping to get this into 4.15. What would be proper time to
fix the fallout?
Err, 4.16 of course.
Hee hee - cramming it into 4.15 is exactly what I wouldn't want to do,
even if Linus would accept it :)
Landing it this merge window for 4.16-rc1 sounds good if we can manage that.
Robin.
From: Robin Murphy <robin.murphy@arm.com> Date: 2018-01-10 17:23:15
On 10/01/18 15:35, Christoph Hellwig wrote:
On Wed, Jan 10, 2018 at 12:16:15PM +0000, Robin Murphy wrote:
quoted
On 10/01/18 08:09, Christoph Hellwig wrote:
quoted
To properly reject too small DMA masks based on the addressability of the
bounce buffer.
I reckon this is self-evident enough that it should simply be squashed into
the previous patch.
x86 didn't wire it up before, so I want a clear blaimpoint for this
change instead of mixing it up.
That almost makes sense, if x86 were using this generic swiotlb_dma_ops
already. AFAICS it's only ia64, unicore and tile who end up using it,
and they all had swiotlb_dma_supported hooked up to begin with. Am I
missing something?
If regressions are going to happen, they'll surely point at whichever
commit pulls the ops into the relevant arch code - there doesn't seem to
be a great deal of value in having a piecemeal history of said ops
*before* that point.
Robin.
@@ -2096,7 +2096,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */arch_initcall(acpi_sba_ioc_init_acpi);-externconststructdma_map_opsswiotlb_dma_ops;+externconststructdma_map_opsia64_swiotlb_dma_ops;staticint__initsba_init(void)
@@ -89,7 +89,7 @@ static int ppc_swiotlb_bus_notify(struct notifier_block *nb,/* May need to bounce if the device can't address all of DRAM */if((dma_get_mask(dev)+1)<memblock_end_of_DRAM())-set_dma_ops(dev,&swiotlb_dma_ops);+set_dma_ops(dev,&powerpc_swiotlb_dma_ops);returnNOTIFY_DONE;}
From: Christoph Hellwig <hch@infradead.org> Date: 2018-01-16 07:53:42
I've pulled this into the dma-mapping for-next tree, including the
missing free_pages noted. I'd be fine to rebase another day or two
for additional reviews or important fixes.