From 14e5d8a995510a8dc0394b062bf1d662a9802172 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Tue, 13 May 2025 15:12:59 +0800 Subject: [PATCH] arm64: fix mpu_freeregion The limit register contains the enable/disable bit for the MPU region, so it must be written first before writing the base register to ensure proper region disable operation. Signed-off-by: hujun5 --- arch/arm64/src/common/arm64_mpu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/src/common/arm64_mpu.c b/arch/arm64/src/common/arm64_mpu.c index 41f3c081a64..e9cd12e44f9 100644 --- a/arch/arm64/src/common/arm64_mpu.c +++ b/arch/arm64/src/common/arm64_mpu.c @@ -187,10 +187,14 @@ void mpu_freeregion(unsigned int region) write_sysreg(region, prselr_el1); UP_DSB(); - /* Set the region base, limit and attribute */ + /* Set the region base, limit and attribute + * Have to set limit register first as the enable/disable bit of the + * region is in the limit register. + */ - write_sysreg(0, prbar_el1); write_sysreg(0, prlar_el1); + write_sysreg(0, prbar_el1); + g_mpu_region[this_cpu()] &= ~(1 << region); UP_MB(); }