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
110110 select DMA_DECLARE_COHERENT
111111 bool
112112
113−config DMA_REMAP
114− bool
115− depends on MMU
116− select DMA_NONCOHERENT_MMAP
117−
118113 config DMA_DIRECT_REMAP
119114 bool
120− select DMA_REMAP
121115 select DMA_COHERENT_POOL
116+ select DMA_NONCOHERENT_MMAP
122117
123118 config DMA_CMA
124119 bool "DMA Contiguous Memory Allocator"
kernel/dma/Makefile+1−1
@@ -8,5 +8,5 @@ obj-$(CONFIG_DMA_DECLARE_COHERENT) += coherent.o · 7 unmodified lines
88 obj-$(CONFIG_DMA_API_DEBUG) += debug.o
99 obj-$(CONFIG_SWIOTLB) += swiotlb.o
1010 obj-$(CONFIG_DMA_COHERENT_POOL) += pool.o
11−obj-$(CONFIG_DMA_REMAP) += remap.o
11+obj-$(CONFIG_MMU) += remap.o
1212 obj-$(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
265265 page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO);
266266 if (!page)
267267 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+ */
268274 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− }
279275 remap = true;
280276 set_uncached = false;
281277 }
@@ -349,7 +345,7 @@ void dma_direct_free(struct device *dev, size_t size, · 67 unmodified lines
349345 dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size)))
350346 return;
351347
352− if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) {
348+ if (is_vmalloc_addr(cpu_addr)) {
353349 vunmap(cpu_addr);
354350 } else {
355351 if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))