From: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
To: <xen-devel@lists.xenproject.org>
Cc: Ayan Kumar Halder <ayan.kumar.halder@amd.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>
Subject: [PATCH v4 5/6] xen/arm: mpu: Enable MPU
Date: Mon, 28 Oct 2024 12:45:46 +0000 [thread overview]
Message-ID: <20241028124547.1371867-6-ayan.kumar.halder@amd.com> (raw)
In-Reply-To: <20241028124547.1371867-1-ayan.kumar.halder@amd.com>
After the regions have been created, now we enable the MPU. For this we disable
the background region so that the new memory map created for the regions take
effect. Also, we treat all RW regions as non executable and the data cache is
enabled.
As enable_mpu() is invoked from enable_boot_cpu_mm(), one needs to save and
restore the lr.
Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
---
Changes from :-
v2 - 1. Extracted from the previous patch into a new one.
2. Disabled background region.
v3 - 1. Removed dsb before setting SCTLR_EL2. The reason being
From ARM DDI 0487K.a D23-7349:
"Direct writes to these registers (includes SCTLR_EL2) are not allowed to affect
any instructions appearing in program order before the direct write."
So, we don't need a synchronization barrier before writing to SCTLR_EL2.
Further, we do have synchronization barriers after writing the MPU region
registers (which happens before we read SCTLR_EL2). So, SCTLR_EL2 is written
after the MPU registers are synchronized. And, thus adding a 'isb' to flush the
instruction pipeline ensures that the subsequent instructions are fetched after
the MPU has been enabled.
2. Saved and restored lr in enable_boot_cpu_mm().
xen/arch/arm/arm64/mpu/head.S | 30 ++++++++++++++++++--
xen/arch/arm/include/asm/arm64/mpu/sysregs.h | 3 ++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S
index 9377ae778c..0edadb009c 100644
--- a/xen/arch/arm/arm64/mpu/head.S
+++ b/xen/arch/arm/arm64/mpu/head.S
@@ -68,6 +68,29 @@ FUNC_LOCAL(fail_insufficient_regions)
b 1b
END(fail_insufficient_regions)
+/*
+ * Enable EL2 MPU and data cache
+ * If the Background region is enabled, then the MPU uses the default memory
+ * map as the Background region for generating the memory
+ * attributes when MPU is disabled.
+ * Since the default memory map of the Armv8-R AArch64 architecture is
+ * IMPLEMENTATION DEFINED, we intend to turn off the Background region here.
+ *
+ * Clobbers x0
+ *
+ */
+FUNC_LOCAL(enable_mpu)
+ mrs x0, SCTLR_EL2
+ bic x0, x0, #SCTLR_ELx_BR /* Disable Background region */
+ orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MPU */
+ orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */
+ orr x0, x0, #SCTLR_Axx_ELx_WXN /* Enable WXN */
+ msr SCTLR_EL2, x0
+ isb
+
+ ret
+END(enable_mpu)
+
/*
* Maps the various sections of Xen (described in xen.lds.S) as different MPU
* regions.
@@ -75,10 +98,11 @@ END(fail_insufficient_regions)
* Inputs:
* lr : Address to return to.
*
- * Clobbers x0 - x5
+ * Clobbers x0 - x6
*
*/
FUNC(enable_boot_cpu_mm)
+ mov x6, lr
/* Get the number of regions specified in MPUIR_EL2 */
mrs x5, MPUIR_EL2
@@ -110,8 +134,10 @@ FUNC(enable_boot_cpu_mm)
ldr x2, =__bss_end
prepare_xen_region x0, x1, x2, x3, x4, x5
- ret
+ bl enable_mpu
+ mov lr, x6
+ ret
END(enable_boot_cpu_mm)
/*
diff --git a/xen/arch/arm/include/asm/arm64/mpu/sysregs.h b/xen/arch/arm/include/asm/arm64/mpu/sysregs.h
index b0c31a58ec..3769d23c80 100644
--- a/xen/arch/arm/include/asm/arm64/mpu/sysregs.h
+++ b/xen/arch/arm/include/asm/arm64/mpu/sysregs.h
@@ -15,6 +15,9 @@
/* MPU Protection Region Selection Register encode */
#define PRSELR_EL2 S3_4_C6_C2_1
+/* Backgroud region enable/disable */
+#define SCTLR_ELx_BR BIT(17, UL)
+
#endif /* __ASM_ARM_ARM64_MPU_SYSREGS_H */
/*
--
2.25.1
next prev parent reply other threads:[~2024-10-28 12:46 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 12:45 [PATCH v4 0/6] Enable early bootup of AArch64 MPU systems Ayan Kumar Halder
2024-10-28 12:45 ` [PATCH v4 1/6] xen/arm: Skip initializing the BSS section when it is empty Ayan Kumar Halder
2024-10-28 14:45 ` Luca Fancellu
2024-11-01 13:55 ` Julien Grall
2024-10-28 12:45 ` [PATCH v4 2/6] xen/arm: mpu: Introduce choice between MMU and MPU Ayan Kumar Halder
2024-10-29 9:53 ` Andrew Cooper
2024-10-29 16:49 ` oleksii.kurochko
2024-10-28 12:45 ` [PATCH v4 3/6] xen/arm: mpu: Define Xen start address for MPU systems Ayan Kumar Halder
2024-10-28 14:53 ` Luca Fancellu
2024-11-01 13:57 ` Julien Grall
2024-10-28 12:45 ` [PATCH v4 4/6] xen/arm: mpu: Create boot-time MPU protection regions Ayan Kumar Halder
2024-10-28 15:14 ` Luca Fancellu
2024-10-28 15:37 ` Luca Fancellu
2024-10-29 16:20 ` Ayan Kumar Halder
2024-10-29 16:25 ` Luca Fancellu
2024-10-30 9:16 ` Luca Fancellu
2024-10-30 9:52 ` Julien Grall
2024-10-30 10:08 ` Luca Fancellu
2024-10-30 10:32 ` Julien Grall
2024-10-30 10:51 ` Luca Fancellu
2024-10-31 16:16 ` Ayan Kumar Halder
2024-11-01 14:11 ` Julien Grall
2024-11-01 17:08 ` Ayan Kumar Halder
2024-11-01 17:11 ` Ayan Kumar Halder
2024-10-28 12:45 ` Ayan Kumar Halder [this message]
2024-10-28 15:39 ` [PATCH v4 5/6] xen/arm: mpu: Enable MPU Luca Fancellu
2024-11-01 14:19 ` Julien Grall
2024-10-28 12:45 ` [PATCH v4 6/6] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm Ayan Kumar Halder
2024-10-28 12:55 ` Jan Beulich
2024-10-28 14:39 ` Ayan Kumar Halder
2024-10-28 15:01 ` Jan Beulich
2024-10-28 17:38 ` Ayan Kumar Halder
2024-10-29 8:08 ` Jan Beulich
2024-10-29 9:30 ` Luca Fancellu
2024-10-29 9:41 ` Jan Beulich
2024-10-29 9:58 ` Luca Fancellu
2024-11-01 14:22 ` [PATCH v4 0/6] Enable early bootup of AArch64 MPU systems Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241028124547.1371867-6-ayan.kumar.halder@amd.com \
--to=ayan.kumar.halder@amd.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.