Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/dma: Use DMA-direct (CONFIG_DMA_DIRECT_OPS=y)

The generic DMA-direct (CONFIG_DMA_DIRECT_OPS=y) implementation is now
functionally equivalent to the x86 nommu dma_map implementation, so
switch over to using it.

That includes switching from using x86_dma_supported in various IOMMU
drivers to use dma_direct_supported instead, which provides the same
functionality.

Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jon Mason <jdmason@kudzu.us>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Muli Ben-Yehuda <mulix@mulix.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: iommu@lists.linux-foundation.org
Link: http://lkml.kernel.org/r/20180319103826.12853-4-hch@lst.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Christoph Hellwig and committed by
Ingo Molnar
fec777c3 038d07a2

+17 -90
+1
arch/x86/Kconfig
··· 83 83 select CLOCKSOURCE_VALIDATE_LAST_CYCLE 84 84 select CLOCKSOURCE_WATCHDOG 85 85 select DCACHE_WORD_ACCESS 86 + select DMA_DIRECT_OPS 86 87 select EDAC_ATOMIC_SCRUB 87 88 select EDAC_SUPPORT 88 89 select GENERIC_CLOCKEVENTS
-8
arch/x86/include/asm/dma-mapping.h
··· 36 36 bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp); 37 37 #define arch_dma_alloc_attrs arch_dma_alloc_attrs 38 38 39 - extern void *dma_generic_alloc_coherent(struct device *dev, size_t size, 40 - dma_addr_t *dma_addr, gfp_t flag, 41 - unsigned long attrs); 42 - 43 - extern void dma_generic_free_coherent(struct device *dev, size_t size, 44 - void *vaddr, dma_addr_t dma_addr, 45 - unsigned long attrs); 46 - 47 39 static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp) 48 40 { 49 41 if (dev->coherent_dma_mask <= DMA_BIT_MASK(24))
-3
arch/x86/include/asm/iommu.h
··· 2 2 #ifndef _ASM_X86_IOMMU_H 3 3 #define _ASM_X86_IOMMU_H 4 4 5 - extern const struct dma_map_ops nommu_dma_ops; 6 5 extern int force_iommu, no_iommu; 7 6 extern int iommu_detected; 8 7 extern int iommu_pass_through; 9 - 10 - int x86_dma_supported(struct device *dev, u64 mask); 11 8 12 9 /* 10 seconds */ 13 10 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
+1 -1
arch/x86/kernel/Makefile
··· 57 57 obj-$(CONFIG_SYSFS) += ksysfs.o 58 58 obj-y += bootflag.o e820.o 59 59 obj-y += pci-dma.o quirks.o topology.o kdebugfs.o 60 - obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o 60 + obj-y += alternative.o i8253.o hw_breakpoint.o 61 61 obj-y += tsc.o tsc_msr.o io_delay.o rtc.o 62 62 obj-y += pci-iommu_table.o 63 63 obj-y += resource.o
+3 -4
arch/x86/kernel/amd_gart_64.c
··· 501 501 } 502 502 __free_pages(page, get_order(size)); 503 503 } else 504 - return dma_generic_alloc_coherent(dev, size, dma_addr, flag, 505 - attrs); 504 + return dma_direct_alloc(dev, size, dma_addr, flag, attrs); 506 505 507 506 return NULL; 508 507 } ··· 512 513 dma_addr_t dma_addr, unsigned long attrs) 513 514 { 514 515 gart_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, 0); 515 - dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs); 516 + dma_direct_free(dev, size, vaddr, dma_addr, attrs); 516 517 } 517 518 518 519 static int gart_mapping_error(struct device *dev, dma_addr_t dma_addr) ··· 704 705 .alloc = gart_alloc_coherent, 705 706 .free = gart_free_coherent, 706 707 .mapping_error = gart_mapping_error, 707 - .dma_supported = x86_dma_supported, 708 + .dma_supported = dma_direct_supported, 708 709 }; 709 710 710 711 static void gart_iommu_shutdown(void)
+2 -1
arch/x86/kernel/pci-calgary_64.c
··· 33 33 #include <linux/string.h> 34 34 #include <linux/crash_dump.h> 35 35 #include <linux/dma-mapping.h> 36 + #include <linux/dma-direct.h> 36 37 #include <linux/bitmap.h> 37 38 #include <linux/pci_ids.h> 38 39 #include <linux/pci.h> ··· 494 493 .map_page = calgary_map_page, 495 494 .unmap_page = calgary_unmap_page, 496 495 .mapping_error = calgary_mapping_error, 497 - .dma_supported = x86_dma_supported, 496 + .dma_supported = dma_direct_supported, 498 497 }; 499 498 500 499 static inline void __iomem * busno_to_bbar(unsigned char num)
+1 -65
arch/x86/kernel/pci-dma.c
··· 18 18 19 19 static int forbid_dac __read_mostly; 20 20 21 - const struct dma_map_ops *dma_ops = &nommu_dma_ops; 21 + const struct dma_map_ops *dma_ops = &dma_direct_ops; 22 22 EXPORT_SYMBOL(dma_ops); 23 23 24 24 static int iommu_sac_force __read_mostly; ··· 75 75 break; 76 76 } 77 77 } 78 - } 79 - void *dma_generic_alloc_coherent(struct device *dev, size_t size, 80 - dma_addr_t *dma_addr, gfp_t flag, 81 - unsigned long attrs) 82 - { 83 - struct page *page; 84 - unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; 85 - dma_addr_t addr; 86 - 87 - again: 88 - page = NULL; 89 - /* CMA can be used only in the context which permits sleeping */ 90 - if (gfpflags_allow_blocking(flag)) { 91 - page = dma_alloc_from_contiguous(dev, count, get_order(size), 92 - flag); 93 - if (page) { 94 - addr = phys_to_dma(dev, page_to_phys(page)); 95 - if (addr + size > dev->coherent_dma_mask) { 96 - dma_release_from_contiguous(dev, page, count); 97 - page = NULL; 98 - } 99 - } 100 - } 101 - /* fallback */ 102 - if (!page) 103 - page = alloc_pages_node(dev_to_node(dev), flag, get_order(size)); 104 - if (!page) 105 - return NULL; 106 - 107 - addr = phys_to_dma(dev, page_to_phys(page)); 108 - if (addr + size > dev->coherent_dma_mask) { 109 - __free_pages(page, get_order(size)); 110 - 111 - if (dev->coherent_dma_mask < DMA_BIT_MASK(32) && 112 - !(flag & GFP_DMA)) { 113 - flag = (flag & ~GFP_DMA32) | GFP_DMA; 114 - goto again; 115 - } 116 - 117 - return NULL; 118 - } 119 - memset(page_address(page), 0, size); 120 - *dma_addr = addr; 121 - return page_address(page); 122 - } 123 - 124 - void dma_generic_free_coherent(struct device *dev, size_t size, void *vaddr, 125 - dma_addr_t dma_addr, unsigned long attrs) 126 - { 127 - unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; 128 - struct page *page = virt_to_page(vaddr); 129 - 130 - if (!dma_release_from_contiguous(dev, page, count)) 131 - free_pages((unsigned long)vaddr, get_order(size)); 132 78 } 133 79 134 80 bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp) ··· 188 242 return 1; 189 243 } 190 244 EXPORT_SYMBOL(arch_dma_supported); 191 - 192 - int x86_dma_supported(struct device *dev, u64 mask) 193 - { 194 - /* Copied from i386. Doesn't make much sense, because it will 195 - only work for pci_alloc_coherent. 196 - The caller just has to use GFP_DMA in this case. */ 197 - if (mask < DMA_BIT_MASK(24)) 198 - return 0; 199 - return 1; 200 - } 201 245 202 246 static int __init pci_iommu_init(void) 203 247 {
+2 -3
arch/x86/kernel/pci-swiotlb.c
··· 30 30 */ 31 31 flags |= __GFP_NOWARN; 32 32 33 - vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags, 34 - attrs); 33 + vaddr = dma_direct_alloc(hwdev, size, dma_handle, flags, attrs); 35 34 if (vaddr) 36 35 return vaddr; 37 36 ··· 44 45 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr))) 45 46 swiotlb_free_coherent(dev, size, vaddr, dma_addr); 46 47 else 47 - dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs); 48 + dma_direct_free(dev, size, vaddr, dma_addr, attrs); 48 49 } 49 50 50 51 static const struct dma_map_ops x86_swiotlb_dma_ops = {
+1 -1
arch/x86/pci/sta2x11-fixup.c
··· 193 193 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, 194 194 .sync_sg_for_device = swiotlb_sync_sg_for_device, 195 195 .mapping_error = swiotlb_dma_mapping_error, 196 - .dma_supported = x86_dma_supported, 196 + .dma_supported = dma_direct_supported, 197 197 }; 198 198 199 199 /* At setup time, we use our own ops if the device is a ConneXt one */
+4 -3
drivers/iommu/amd_iommu.c
··· 28 28 #include <linux/debugfs.h> 29 29 #include <linux/scatterlist.h> 30 30 #include <linux/dma-mapping.h> 31 + #include <linux/dma-direct.h> 31 32 #include <linux/iommu-helper.h> 32 33 #include <linux/iommu.h> 33 34 #include <linux/delay.h> ··· 2194 2193 dev_name(dev)); 2195 2194 2196 2195 iommu_ignore_device(dev); 2197 - dev->dma_ops = &nommu_dma_ops; 2196 + dev->dma_ops = &dma_direct_ops; 2198 2197 goto out; 2199 2198 } 2200 2199 init_iommu_group(dev); ··· 2681 2680 */ 2682 2681 static int amd_iommu_dma_supported(struct device *dev, u64 mask) 2683 2682 { 2684 - if (!x86_dma_supported(dev, mask)) 2683 + if (!dma_direct_supported(dev, mask)) 2685 2684 return 0; 2686 2685 return check_device(dev); 2687 2686 } ··· 2795 2794 * continue to be SWIOTLB. 2796 2795 */ 2797 2796 if (!swiotlb) 2798 - dma_ops = &nommu_dma_ops; 2797 + dma_ops = &dma_direct_ops; 2799 2798 2800 2799 if (amd_iommu_unmap_flush) 2801 2800 pr_info("AMD-Vi: IO/TLB flush on unmap enabled\n");
+2 -1
drivers/iommu/intel-iommu.c
··· 45 45 #include <linux/pci-ats.h> 46 46 #include <linux/memblock.h> 47 47 #include <linux/dma-contiguous.h> 48 + #include <linux/dma-direct.h> 48 49 #include <linux/crash_dump.h> 49 50 #include <asm/irq_remapping.h> 50 51 #include <asm/cacheflush.h> ··· 3872 3871 .unmap_page = intel_unmap_page, 3873 3872 .mapping_error = intel_mapping_error, 3874 3873 #ifdef CONFIG_X86 3875 - .dma_supported = x86_dma_supported, 3874 + .dma_supported = dma_direct_supported, 3876 3875 #endif 3877 3876 }; 3878 3877