With CONFIG_HIGHMEM enabled, __dma_sync_page() unconditionally goes
through __dma_sync_page_highmem(), which disables interrupts and
kmaps the buffer one page at a time. This adds needless per-page
overhead to every streaming DMA sync on such kernels.

Use the per-page kmap path only when the buffer reaches into highmem
and do a single __dma_sync() on the linear mapping otherwise.

Signed-off-by: Marek Szyprowski <[email protected]>
---
 arch/powerpc/mm/dma-noncoherent.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/mm/dma-noncoherent.c 
b/arch/powerpc/mm/dma-noncoherent.c
index 30260b5d146d..3ce7dfc213d9 100644
--- a/arch/powerpc/mm/dma-noncoherent.c
+++ b/arch/powerpc/mm/dma-noncoherent.c
@@ -96,12 +96,16 @@ static void __dma_sync_page(phys_addr_t paddr, size_t size, 
int dir)
        struct page *page = pfn_to_page(paddr >> PAGE_SHIFT);
        unsigned offset = paddr & ~PAGE_MASK;
 
+       if (!size)
+               return;
+
 #ifdef CONFIG_HIGHMEM
-       __dma_sync_page_highmem(page, offset, size, dir);
-#else
-       unsigned long start = (unsigned long)page_address(page) + offset;
-       __dma_sync((void *)start, size, dir);
+       if (PageHighMem(pfn_to_page(PHYS_PFN(paddr + size - 1)))) {
+               __dma_sync_page_highmem(page, offset, size, dir);
+               return;
+       }
 #endif
+       __dma_sync(page_address(page) + offset, size, dir);
 }
 
 void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
-- 
2.43.0


Reply via email to