Skip to content

Commit 156f1d4

Browse files
Flavio Ceolincarlescufi
authored andcommitted
xtensa: mmu: Flush cache when altering pages
When the target has a cache way size (cache size / cache wasy) bigger than the page size we have cache aliasing, since the number of bits required by the cache index is bigger than the number of bits in the page offset. To avoid this problem we flush the whole cache on context switch or when the current page table is changed. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 6c6894c commit 156f1d4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arch/xtensa/core/xtensa_mmu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ static inline uint32_t *alloc_l2_table(void)
231231
static ALWAYS_INLINE void switch_page_tables(uint32_t *ptables, bool dtlb_inv, bool cache_inv)
232232
{
233233
if (cache_inv) {
234-
sys_cache_data_invd_range((void *)ptables, XTENSA_L1_PAGE_TABLE_SIZE);
235-
sys_cache_data_invd_range((void *)l2_page_tables, sizeof(l2_page_tables));
234+
sys_cache_data_flush_and_invd_all();
236235
}
237236

238237
/* Invalidate data TLB to L1 page table */
@@ -669,6 +668,7 @@ void arch_mem_map(void *virt, uintptr_t phys, size_t size, uint32_t flags)
669668
z_xtensa_mmu_tlb_ipi();
670669
#endif
671670

671+
sys_cache_data_flush_and_invd_all();
672672
k_spin_unlock(&xtensa_mmu_lock, key);
673673
}
674674

@@ -805,6 +805,7 @@ void arch_mem_unmap(void *addr, size_t size)
805805
z_xtensa_mmu_tlb_ipi();
806806
#endif
807807

808+
sys_cache_data_flush_and_invd_all();
808809
k_spin_unlock(&xtensa_mmu_lock, key);
809810
}
810811

@@ -858,7 +859,7 @@ void z_xtensa_mmu_tlb_shootdown(void)
858859
* indicated by the current thread are different
859860
* than the current mapped page table.
860861
*/
861-
switch_page_tables((uint32_t *)thread_ptables, false, false);
862+
switch_page_tables((uint32_t *)thread_ptables, true, true);
862863
}
863864

864865
}
@@ -1039,6 +1040,7 @@ static inline int update_region(uint32_t *ptables, uintptr_t start,
10391040
}
10401041
#endif
10411042

1043+
sys_cache_data_flush_and_invd_all();
10421044
k_spin_unlock(&xtensa_mmu_lock, key);
10431045

10441046
return ret;

0 commit comments

Comments
 (0)