Skip to content

Commit 6b07699

Browse files
author
Russell King
committed
ARM: DMA: ensure that old section mappings are flushed from the TLB
When setting up the CMA region, we must ensure that the old section mappings are flushed from the TLB before replacing them with page tables, otherwise we can suffer from mismatched aliases if the CPU speculatively prefetches from these mappings at an inopportune time. A mismatched alias can occur when the TLB contains a section mapping, but a subsequent prefetch causes it to load a page table mapping, resulting in the possibility of the TLB containing two matching mappings for the same virtual address region. Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent cda390b commit 6b07699

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/arm/mm/dma-mapping.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,21 @@ void __init dma_contiguous_remap(void)
461461
map.type = MT_MEMORY_DMA_READY;
462462

463463
/*
464-
* Clear previous low-memory mapping
464+
* Clear previous low-memory mapping to ensure that the
465+
* TLB does not see any conflicting entries, then flush
466+
* the TLB of the old entries before creating new mappings.
467+
*
468+
* This ensures that any speculatively loaded TLB entries
469+
* (even though they may be rare) can not cause any problems,
470+
* and ensures that this code is architecturally compliant.
465471
*/
466472
for (addr = __phys_to_virt(start); addr < __phys_to_virt(end);
467473
addr += PMD_SIZE)
468474
pmd_clear(pmd_off_k(addr));
469475

476+
flush_tlb_kernel_range(__phys_to_virt(start),
477+
__phys_to_virt(end));
478+
470479
iotable_init(&map, 1);
471480
}
472481
}

0 commit comments

Comments
 (0)