Skip to contentSkip to conversation

dma-direct: reject highmem pages from dma_alloc_from_contiguous

PATCH In review Christoph Hellwig 1 participant 2 messages Oct 14, 2018 – Oct 22, 2018 DMA mapping helpers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-direct: reject highmem pages from dma_alloc_from_contiguous

dma_alloc_from_contiguous can return highmem pages depending on the setup, which a plain non-remapping DMA allocator can't handle. Detect this case and try the normal page allocator instead.

---
 kernel/dma/direct.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
kernel/dma/direct.c +12 -0
index 87a6bc2a96c0..46fbaa49125b 100644
@@ -126,6 +126,18 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 	if (gfpflags_allow_blocking(gfp)) {
 		page = dma_alloc_from_contiguous(dev, count, page_order,
 						 gfp & __GFP_NOWARN);
+		if (page && PageHighMem(page)) {
+			/*
+			 * Depending on the cma= arguments and per-arch setup
+			 * dma_alloc_from_contiguous could return highmem
+			 * pages.  Without remapping there is no way to return
+			 * them here, so log an error and fail.
+			 */
+			dev_info(dev, "Ignoring highmem page from CMA.\n");
+			dma_release_from_contiguous(dev, page, count);
+			page = NULL;
+		}
+
 		if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) {
 			dma_release_from_contiguous(dev, page, count);
 			page = NULL;
Signature · 1 line
2.19.1
#1 lore raw

Any comments?

Quoted 39 lines · Christoph Hellwig

dma_alloc_from_contiguous can return highmem pages depending on the setup, which a plain non-remapping DMA allocator can't handle. Detect this case and try the normal page allocator instead.

---
 kernel/dma/direct.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
kernel/dma/direct.c +12 -0
index 87a6bc2a96c0..46fbaa49125b 100644
@@ -126,6 +126,18 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 	if (gfpflags_allow_blocking(gfp)) {
 		page = dma_alloc_from_contiguous(dev, count, page_order,
 						 gfp & __GFP_NOWARN);
+		if (page && PageHighMem(page)) {
+			/*
+			 * Depending on the cma= arguments and per-arch setup
+			 * dma_alloc_from_contiguous could return highmem
+			 * pages.  Without remapping there is no way to return
+			 * them here, so log an error and fail.
+			 */
+			dev_info(dev, "Ignoring highmem page from CMA.\n");
+			dma_release_from_contiguous(dev, page, count);
+			page = NULL;
+		}
+
 		if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) {
 			dma_release_from_contiguous(dev, page, count);
 			page = NULL;
Signature · 6 lines
2.19.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

---end quoted text---