From 67bc6af94ab39e69e01220fc9c07f99754076d68 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Tue, 10 Dec 2019 11:41:25 -0800 Subject: [PATCH] dma-mapping-fast: Remap contiguous pages only when needed When a CPU mapping is determined for the contiguous pages allocated with DMA_ATTR_FORCE_CONTIGUOUS, the pages are remapped into the vmalloc space, independent of the device's coherency settings. In cases where the device accessing the memory is I/O coherent this is unnecessary, as the kernel logical mappings can be used for coherent CPU accesses. Thus, only remap the contiguous pages when the CPU needs an uncached mapping to access the memory--when the device is non I/O coherent--or when the pages are in high memory. Change-Id: I6179adbfbda5cb639c1da87c72424ddbee9821f1 Signed-off-by: Isaac J. Manjarres --- drivers/iommu/dma-mapping-fast.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/dma-mapping-fast.c b/drivers/iommu/dma-mapping-fast.c index 290ccc4b4032..b3d0f0aeed25 100644 --- a/drivers/iommu/dma-mapping-fast.c +++ b/drivers/iommu/dma-mapping-fast.c @@ -630,13 +630,18 @@ static void *__fast_smmu_alloc_contiguous(struct device *dev, size_t size, size, prot)) goto release_iova; - coherent_addr = dma_common_contiguous_remap(page, size, remap_prot, + if (!is_coherent || PageHighMem(page)) { + coherent_addr = dma_common_contiguous_remap(page, size, + remap_prot, __fast_smmu_alloc_contiguous); - if (!coherent_addr) - goto release_mapping; + if (!coherent_addr) + goto release_mapping; - if (!is_coherent) - __dma_flush_area(page_to_virt(page), size); + if (!is_coherent) + __dma_flush_area(page_to_virt(page), size); + } else { + coherent_addr = page_address(page); + } *handle = iova; return coherent_addr;