Re: [PATCH] dma-direct: Skip cache prep for HighMem coherent allocations

From: Robin Murphy
Date: Thu Jan 08 2026 - 10:30:46 EST


On 2026-01-02 3:51 pm, Aneesh Kumar K.V (Arm) wrote:
dma_direct_alloc() calls arch_dma_prep_coherent() to clean any dirty
cache lines from the kernel linear alias before creating a coherent
remapping.

HighMem pages have no kernel alias mapping, so there are no alias cache
lines to clean. Skip arch_dma_prep_coherent() for HighMem allocations.

This is assuming that caches are always cleaned when unmapping highmem, and no still-mapped highmem pages are dirty - how is that guaranteed? The fact that they're not in the linear map doesn't mean they don't necessarily have kernel aliases in either vmalloc pagetables or caches.

Thanks,
Robin.

Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
---
kernel/dma/direct.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 50c3fe2a1d55..ffa267020a1e 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -272,7 +272,8 @@ void *dma_direct_alloc(struct device *dev, size_t size,
prot = pgprot_decrypted(prot);
/* remove any dirty cache lines on the kernel alias */
- arch_dma_prep_coherent(page, size);
+ if (!PageHighMem(page))
+ arch_dma_prep_coherent(page, size);
/* create a coherent mapping */
ret = dma_common_contiguous_remap(page, size, prot,