Skip to content

Commit c925b0e

Browse files
dcpleungkartben
authored andcommitted
xtensa: mmu: fix incorrect caching attrs on double mapping
Inside map_memory() with double mapping enabled, we should not be mapping the memory with the incoming attributes as-is since the incoming address may be on un-cached region but with caching attribute. So we need to sanitize the attributes according to the incoming address. Signed-off-by: Daniel Leung <[email protected]>
1 parent 4b5ceb9 commit c925b0e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

arch/xtensa/core/ptables.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,25 @@ static void map_memory_range(const uint32_t start, const uint32_t end,
250250
static void map_memory(const uint32_t start, const uint32_t end,
251251
const uint32_t attrs)
252252
{
253-
map_memory_range(start, end, attrs);
254-
255253
#ifdef CONFIG_XTENSA_MMU_DOUBLE_MAP
254+
uint32_t uc_attrs = attrs & ~XTENSA_MMU_PTE_ATTR_CACHED_MASK;
255+
uint32_t c_attrs = attrs | XTENSA_MMU_CACHED_WB;
256+
256257
if (sys_cache_is_ptr_uncached((void *)start)) {
258+
map_memory_range(start, end, uc_attrs);
259+
257260
map_memory_range(POINTER_TO_UINT(sys_cache_cached_ptr_get((void *)start)),
258-
POINTER_TO_UINT(sys_cache_cached_ptr_get((void *)end)),
259-
attrs | XTENSA_MMU_CACHED_WB);
261+
POINTER_TO_UINT(sys_cache_cached_ptr_get((void *)end)), c_attrs);
260262
} else if (sys_cache_is_ptr_cached((void *)start)) {
263+
map_memory_range(start, end, c_attrs);
264+
261265
map_memory_range(POINTER_TO_UINT(sys_cache_uncached_ptr_get((void *)start)),
262-
POINTER_TO_UINT(sys_cache_uncached_ptr_get((void *)end)), attrs);
263-
}
266+
POINTER_TO_UINT(sys_cache_uncached_ptr_get((void *)end)), uc_attrs);
267+
} else
264268
#endif
269+
{
270+
map_memory_range(start, end, attrs);
271+
}
265272
}
266273

267274
static void xtensa_init_page_tables(void)

0 commit comments

Comments
 (0)