History

Merge tag 'arm-swiotlb-5.3' of git://git.infradead.org/users/hch/dma-mapping

Pull arm swiotlb support from Christoph Hellwig: "This fixes a cascade of regressions that originally started with the addition of the ia64 port, but only got fatal once we removed most uses of block layer bounce buffering in Linux 4.18. The reason is that while the original i386/PAE code that was the first architecture that supported > 4GB of memory without an iommu decided to leave bounce buffering to the subsystems, which in those days just mean block and networking as no one else consumed arbitrary userspace memory. Later with ia64, x86_64 and other ports we assumed that either an iommu or something that fakes it up ("software IOTLB" in beautiful Intel speak) is present and that subsystems can rely on that for dealing with addressing limitations in devices. Except that the ARM LPAE scheme that added larger physical address to 32-bit ARM did not follow that scheme and thus only worked by chance and only for block and networking I/O directly to highmem. Long story, short fix - add swiotlb support to arm when build for LPAE platforms, which actuallys turns out to be pretty trivial with the modern dma-direct / swiotlb code to fix the Linux 4.18-ish regression" * tag 'arm-swiotlb-5.3' of git://git.infradead.org/users/hch/dma-mapping: arm: use swiotlb for bounce buffering on LPAE configs dma-mapping: check pfn validity in dma_common_{mmap,get_sgtable}

Linus Torvalds committed 7 years ago

Commit 234172f2 parents 35fca9f ad3c7b15 files · +85 −3Browse files

Unified · Split

5 files
  1. arch/arm/include/asm/dma-mapping.h +3 −1
  2. arch/arm/mm/Kconfig +5 −0
  3. arch/arm/mm/dma-mapping.c +61 −0
  4. arch/arm/mm/init.c +5 −0
  5. kernel/dma/mapping.c +11 −2
arch/arm/include/asm/dma-mapping.h+3−1
@@ -18,7 +18,9 @@ extern const struct dma_map_ops arm_coherent_dma_ops; · 17 unmodified lines
18 18
19static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)19static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
20{20{
21 return IS_ENABLED(CONFIG_MMU) ? &arm_dma_ops : NULL;21 if (IS_ENABLED(CONFIG_MMU) && !IS_ENABLED(CONFIG_ARM_LPAE))
22 return &arm_dma_ops;
23 return NULL;
22}24}
23 25
24#ifdef __arch_page_to_dma26#ifdef __arch_page_to_dma
arch/arm/mm/Kconfig+5−0
@@ -663,6 +663,11 @@ config ARM_LPAE · 662 unmodified lines
663 depends on MMU && CPU_32v7 && !CPU_32v6 && !CPU_32v5 && \663 depends on MMU && CPU_32v7 && !CPU_32v6 && !CPU_32v5 && \
664 !CPU_32v4 && !CPU_32v3664 !CPU_32v4 && !CPU_32v3
665 select PHYS_ADDR_T_64BIT665 select PHYS_ADDR_T_64BIT
666 select SWIOTLB
667 select ARCH_HAS_DMA_COHERENT_TO_PFN
668 select ARCH_HAS_DMA_MMAP_PGPROT
669 select ARCH_HAS_SYNC_DMA_FOR_DEVICE
670 select ARCH_HAS_SYNC_DMA_FOR_CPU
666 help671 help
667 Say Y if you have an ARMv7 processor supporting the LPAE page672 Say Y if you have an ARMv7 processor supporting the LPAE page
668 table format and you would like to access memory beyond the673 table format and you would like to access memory beyond the
arch/arm/mm/dma-mapping.c+61−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
15#include <linux/init.h>15#include <linux/init.h>
16#include <linux/device.h>16#include <linux/device.h>
17#include <linux/dma-mapping.h>17#include <linux/dma-mapping.h>
18#include <linux/dma-noncoherent.h>
18#include <linux/dma-contiguous.h>19#include <linux/dma-contiguous.h>
19#include <linux/highmem.h>20#include <linux/highmem.h>
20#include <linux/memblock.h>21#include <linux/memblock.h>
@@ -1125,6 +1126,19 @@ int arm_dma_supported(struct device *dev, u64 mask) · 1104 unmodified lines
1125 1126
1126static const struct dma_map_ops *arm_get_dma_map_ops(bool coherent)1127static const struct dma_map_ops *arm_get_dma_map_ops(bool coherent)
1127{1128{
1129 /*
1130 * When CONFIG_ARM_LPAE is set, physical address can extend above
1131 * 32-bits, which then can't be addressed by devices that only support
1132 * 32-bit DMA.
1133 * Use the generic dma-direct / swiotlb ops code in that case, as that
1134 * handles bounce buffering for us.
1135 *
1136 * Note: this checks CONFIG_ARM_LPAE instead of CONFIG_SWIOTLB as the
1137 * latter is also selected by the Xen code, but that code for now relies
1138 * on non-NULL dev_dma_ops. To be cleaned up later.
1139 */
1140 if (IS_ENABLED(CONFIG_ARM_LPAE))
1141 return NULL;
1128 return coherent ? &arm_coherent_dma_ops : &arm_dma_ops;1142 return coherent ? &arm_coherent_dma_ops : &arm_dma_ops;
1129}1143}
1130 1144
@@ -2329,6 +2343,9 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, · 1198 unmodified lines
2329 const struct dma_map_ops *dma_ops;2343 const struct dma_map_ops *dma_ops;
2330 2344
2331 dev->archdata.dma_coherent = coherent;2345 dev->archdata.dma_coherent = coherent;
2346#ifdef CONFIG_SWIOTLB
2347 dev->dma_coherent = coherent;
2348#endif
2332 2349
2333 /*2350 /*
2334 * Don't override the dma_ops if they have already been set. Ideally2351 * Don't override the dma_ops if they have already been set. Ideally
@@ -2363,3 +2380,47 @@ void arch_teardown_dma_ops(struct device *dev) · 28 unmodified lines
2363 /* Let arch_setup_dma_ops() start again from scratch upon re-probe */2380 /* Let arch_setup_dma_ops() start again from scratch upon re-probe */
2364 set_dma_ops(dev, NULL);2381 set_dma_ops(dev, NULL);
2365}2382}
2383
2384#ifdef CONFIG_SWIOTLB
2385void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
2386 size_t size, enum dma_data_direction dir)
2387{
2388 __dma_page_cpu_to_dev(phys_to_page(paddr), paddr & (PAGE_SIZE - 1),
2389 size, dir);
2390}
2391
2392void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
2393 size_t size, enum dma_data_direction dir)
2394{
2395 __dma_page_dev_to_cpu(phys_to_page(paddr), paddr & (PAGE_SIZE - 1),
2396 size, dir);
2397}
2398
2399long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
2400 dma_addr_t dma_addr)
2401{
2402 return dma_to_pfn(dev, dma_addr);
2403}
2404
2405pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
2406 unsigned long attrs)
2407{
2408 if (!dev_is_dma_coherent(dev))
2409 return __get_dma_pgprot(attrs, prot);
2410 return prot;
2411}
2412
2413void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
2414 gfp_t gfp, unsigned long attrs)
2415{
2416 return __dma_alloc(dev, size, dma_handle, gfp,
2417 __get_dma_pgprot(attrs, PAGE_KERNEL), false,
2418 attrs, __builtin_return_address(0));
2419}
2420
2421void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
2422 dma_addr_t dma_handle, unsigned long attrs)
2423{
2424 __arm_dma_free(dev, size, cpu_addr, dma_handle, attrs, false);
2425}
2426#endif /* CONFIG_SWIOTLB */
arch/arm/mm/init.c+5−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
21#include <linux/dma-contiguous.h>21#include <linux/dma-contiguous.h>
22#include <linux/sizes.h>22#include <linux/sizes.h>
23#include <linux/stop_machine.h>23#include <linux/stop_machine.h>
24#include <linux/swiotlb.h>
24 25
25#include <asm/cp15.h>26#include <asm/cp15.h>
26#include <asm/mach-types.h>27#include <asm/mach-types.h>
@@ -463,6 +464,10 @@ static void __init free_highpages(void) · 436 unmodified lines
463 */464 */
464void __init mem_init(void)465void __init mem_init(void)
465{466{
467#ifdef CONFIG_ARM_LPAE
468 swiotlb_init(1);
469#endif
470
466 set_max_mapnr(pfn_to_page(max_pfn) - mem_map);471 set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
467 472
468 /* this will put all unused low memory onto the freelists */473 /* this will put all unused low memory onto the freelists */
kernel/dma/mapping.c+11−2
@@ -116,11 +116,16 @@ int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, · 115 unmodified lines
116 int ret;116 int ret;
117 117
118 if (!dev_is_dma_coherent(dev)) {118 if (!dev_is_dma_coherent(dev)) {
119 unsigned long pfn;
120
119 if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_COHERENT_TO_PFN))121 if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_COHERENT_TO_PFN))
120 return -ENXIO;122 return -ENXIO;
121 123
122 page = pfn_to_page(arch_dma_coherent_to_pfn(dev, cpu_addr,124 /* If the PFN is not valid, we do not have a struct page */
123 dma_addr));125 pfn = arch_dma_coherent_to_pfn(dev, cpu_addr, dma_addr);
126 if (!pfn_valid(pfn))
127 return -ENXIO;
128 page = pfn_to_page(pfn);
124 } else {129 } else {
125 page = virt_to_page(cpu_addr);130 page = virt_to_page(cpu_addr);
126 }131 }
@@ -170,7 +175,11 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, · 43 unmodified lines
170 if (!dev_is_dma_coherent(dev)) {175 if (!dev_is_dma_coherent(dev)) {
171 if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_COHERENT_TO_PFN))176 if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_COHERENT_TO_PFN))
172 return -ENXIO;177 return -ENXIO;
178
179 /* If the PFN is not valid, we do not have a struct page */
173 pfn = arch_dma_coherent_to_pfn(dev, cpu_addr, dma_addr);180 pfn = arch_dma_coherent_to_pfn(dev, cpu_addr, dma_addr);
181 if (!pfn_valid(pfn))
182 return -ENXIO;
174 } else {183 } else {
175 pfn = page_to_pfn(virt_to_page(cpu_addr));184 pfn = page_to_pfn(virt_to_page(cpu_addr));
176 }185 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t