arch: arm64: Fix the cache coherence issue

Accessing mem before mmu or mpu init will cause a cache coherence issue.
To avoid such a problem, move the safe exception stack init function
after the mmu or mpu is initiated.

Also change the data section attribute from INNER_SHAREABLE to
OUTER_SHAREABLE. Otherwise there will be a cache coherence issue during
the memory regions switch. Because we are using background region to do
the regions switch, and the default background region is
OUTER_SHAREABLE, if we use INNER_SHAREABLE as the foreground region,
then we have to flush all cache regions to make sure the cached values
are right. However, flushing all regions is too heavy, so we set
OUTER_SHAREABLE to fix this issue.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
This commit is contained in:
Jaxson Han 2023-09-11 15:02:48 +08:00 committed by Carles Cufí
commit c57fa2c231
2 changed files with 4 additions and 3 deletions

View file

@ -141,12 +141,13 @@ void z_arm64_secondary_start(void)
/* Initialize tpidrro_el0 with our struct _cpu instance address */ /* Initialize tpidrro_el0 with our struct _cpu instance address */
write_tpidrro_el0((uintptr_t)&_kernel.cpus[cpu_num]); write_tpidrro_el0((uintptr_t)&_kernel.cpus[cpu_num]);
z_arm64_mm_init(false);
#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK #ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK
z_arm64_safe_exception_stack_init(); z_arm64_safe_exception_stack_init();
#endif #endif
z_arm64_mm_init(false);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
arm_gic_secondary_init(); arm_gic_secondary_init();

View file

@ -143,7 +143,7 @@
#define REGION_RAM_ATTR \ #define REGION_RAM_ATTR \
{ \ { \
/* AP, XN, SH */ \ /* AP, XN, SH */ \
.rbar = NOT_EXEC | P_RW_U_NA_Msk | INNER_SHAREABLE_Msk, \ .rbar = NOT_EXEC | P_RW_U_NA_Msk | OUTER_SHAREABLE_Msk, \
/* Cache-ability */ \ /* Cache-ability */ \
.mair_idx = MPU_MAIR_INDEX_SRAM, \ .mair_idx = MPU_MAIR_INDEX_SRAM, \
} }