From ad3abcd277f4897318381e761af437f236b0b59a Mon Sep 17 00:00:00 2001 From: hujun5 Date: Sun, 27 Apr 2025 11:48:13 +0800 Subject: [PATCH] arm64: g_mpu_region need support SMP Convert g_mpu_region from single-CPU global variable to per-CPU array indexed by this_cpu(). Change declaration from "unsigned int g_mpu_region" to "unsigned int g_mpu_region[CONFIG_SMP_NCPUS]". Update all accesses in mpu_allocregion(), mpu_freeregion(), and mpu_modify_region() to use g_mpu_region[this_cpu()] for proper per-CPU MPU region tracking in multi-core configurations. Signed-off-by: hujun5 --- arch/arm64/src/common/arm64_mpu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/src/common/arm64_mpu.c b/arch/arm64/src/common/arm64_mpu.c index 098c9a2b15d..41f3c081a64 100644 --- a/arch/arm64/src/common/arm64_mpu.c +++ b/arch/arm64/src/common/arm64_mpu.c @@ -73,7 +73,7 @@ * regions. */ -static unsigned int g_mpu_region; +static unsigned int g_mpu_region[CONFIG_SMP_NCPUS]; /**************************************************************************** * Private Functions @@ -153,12 +153,12 @@ static void mpu_init(void) unsigned int mpu_allocregion(void) { unsigned int num_regions = get_num_regions(); - unsigned int i = ffs(~g_mpu_region) - 1; + unsigned int i = ffs(~g_mpu_region[this_cpu()]) - 1; /* There are not enough regions to apply */ DEBUGASSERT(i < num_regions); - g_mpu_region |= 1 << i; + g_mpu_region[this_cpu()] |= 1 << i; return i; } @@ -191,7 +191,7 @@ void mpu_freeregion(unsigned int region) write_sysreg(0, prbar_el1); write_sysreg(0, prlar_el1); - g_mpu_region &= ~(1 << region); + g_mpu_region[this_cpu()] &= ~(1 << region); UP_MB(); } @@ -275,7 +275,7 @@ void mpu_modify_region(unsigned int region, /* Check that the region is valid */ - DEBUGASSERT(g_mpu_region & (1 << region)); + DEBUGASSERT(g_mpu_region[this_cpu()] & (1 << region)); rbar |= table->attr.rbar & (MPU_RBAR_XN_MSK | MPU_RBAR_AP_MSK | MPU_RBAR_SH_MSK);