dma-direct: reject highmem pages from dma_alloc_from_contiguous
authorChristoph Hellwig <hch@lst.de>
Sat, 22 Sep 2018 18:47:26 +0000 (20:47 +0200)
committerChristoph Hellwig <hch@lst.de>
Sat, 1 Dec 2018 16:56:08 +0000 (17:56 +0100)
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 fail the allocation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
kernel/dma/direct.c

index 680287779b0ad2932187e9b1d400c7f9650b9652..c49849bcced6a37265b1af1ec80650bd258bbdf0 100644 (file)
@@ -162,6 +162,18 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
        if (!page)
                return NULL;
 
+       if (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, "Rejecting highmem page from CMA.\n");
+               __dma_direct_free_pages(dev, size, page);
+               return NULL;
+       }
+
        ret = page_address(page);
        if (force_dma_unencrypted()) {
                set_memory_decrypted((unsigned long)ret, 1 << get_order(size));