History

dma-mapping: remove CONFIG_DMA_REMAP

CONFIG_DMA_REMAP is used to build a few helpers around the core vmalloc code, and to use them in case there is a highmem page in dma-direct, and to make dma coherent allocations be able to use non-contiguous pages allocations for DMA allocations in the dma-iommu layer. Right now it needs to be explicitly selected by architectures, and is only done so by architectures that require remapping to deal with devices that are not DMA coherent. Make it unconditional for builds with CONFIG_MMU as it is very little extra code, but makes it much more likely that large DMA allocations succeed on x86. This fixes hot plugging a NVMe thunderbolt SSD for me, which tries to allocate a 1MB buffer that is otherwise hard to obtain due to memory fragmentation on a heavily used laptop.

Christoph Hellwig committed 4 years ago

Commit f5ff79f1 parent fba09096 files · +16 −29Browse files

Showing the changes to kernel (3 of 6 files). Show all

Unified · Split

3 files
  1. kernel/dma/Kconfig +1 −6
  2. kernel/dma/Makefile +1 −1
  3. kernel/dma/direct.c +7 −11
kernel/dma/Kconfig+1−6
@@ -110,15 +110,10 @@ config DMA_GLOBAL_POOL · 109 unmodified lines
110 select DMA_DECLARE_COHERENT110 select DMA_DECLARE_COHERENT
111 bool111 bool
112 112
113config DMA_REMAP
114 bool
115 depends on MMU
116 select DMA_NONCOHERENT_MMAP
117
118config DMA_DIRECT_REMAP113config DMA_DIRECT_REMAP
119 bool114 bool
120 select DMA_REMAP
121 select DMA_COHERENT_POOL115 select DMA_COHERENT_POOL
116 select DMA_NONCOHERENT_MMAP
122 117
123config DMA_CMA118config DMA_CMA
124 bool "DMA Contiguous Memory Allocator"119 bool "DMA Contiguous Memory Allocator"
kernel/dma/Makefile+1−1
@@ -8,5 +8,5 @@ obj-$(CONFIG_DMA_DECLARE_COHERENT) += coherent.o · 7 unmodified lines
8obj-$(CONFIG_DMA_API_DEBUG) += debug.o8obj-$(CONFIG_DMA_API_DEBUG) += debug.o
9obj-$(CONFIG_SWIOTLB) += swiotlb.o9obj-$(CONFIG_SWIOTLB) += swiotlb.o
10obj-$(CONFIG_DMA_COHERENT_POOL) += pool.o10obj-$(CONFIG_DMA_COHERENT_POOL) += pool.o
11obj-$(CONFIG_DMA_REMAP) += remap.o11obj-$(CONFIG_MMU) += remap.o
12obj-$(CONFIG_DMA_MAP_BENCHMARK) += map_benchmark.o12obj-$(CONFIG_DMA_MAP_BENCHMARK) += map_benchmark.o
kernel/dma/direct.c+7−11
@@ -265,17 +265,13 @@ void *dma_direct_alloc(struct device *dev, size_t size, · 264 unmodified lines
265 page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO);265 page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO);
266 if (!page)266 if (!page)
267 return NULL;267 return NULL;
268
269 /*
270 * dma_alloc_contiguous can return highmem pages depending on a
271 * combination the cma= arguments and per-arch setup. These need to be
272 * remapped to return a kernel virtual address.
273 */
268 if (PageHighMem(page)) {274 if (PageHighMem(page)) {
269 /*
270 * Depending on the cma= arguments and per-arch setup,
271 * dma_alloc_contiguous could return highmem pages.
272 * Without remapping there is no way to return them here, so
273 * log an error and fail.
274 */
275 if (!IS_ENABLED(CONFIG_DMA_REMAP)) {
276 dev_info(dev, "Rejecting highmem page from CMA.\n");
277 goto out_free_pages;
278 }
279 remap = true;275 remap = true;
280 set_uncached = false;276 set_uncached = false;
281 }277 }
@@ -349,7 +345,7 @@ void dma_direct_free(struct device *dev, size_t size, · 67 unmodified lines
349 dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size)))345 dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size)))
350 return;346 return;
351 347
352 if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) {348 if (is_vmalloc_addr(cpu_addr)) {
353 vunmap(cpu_addr);349 vunmap(cpu_addr);
354 } else {350 } else {
355 if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))351 if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))