[kvm-unit-tests PATCH v6 04/14] arm64: efi: initialise SCTLR_ELx fully
Joey Gouly
joey.gouly at arm.com
Fri Jan 23 08:50:43 PST 2026
Don't rely on the value of SCTLR_ELx when booting via EFI.
Signed-off-by: Joey Gouly <joey.gouly at arm.com>
Acked-by: Marc Zyngier <maz at kernel.org>
---
lib/arm/asm/setup.h | 6 ++++++
lib/arm/setup.c | 2 ++
lib/arm64/processor.c | 14 ++++++++++++++
3 files changed, 22 insertions(+)
diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
index 9f8ef82e..4e60d552 100644
--- a/lib/arm/asm/setup.h
+++ b/lib/arm/asm/setup.h
@@ -28,6 +28,12 @@ void setup(const void *fdt, phys_addr_t freemem_start);
#include <efi.h>
+#ifdef __aarch64__
+void setup_efi_sctlr(void);
+#else
+static inline void setup_efi_sctlr(void) {}
+#endif
+
efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo);
#endif
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 67b5db07..49f5e0f6 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -349,6 +349,8 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
{
efi_status_t status;
+ setup_efi_sctlr();
+
exceptions_init();
memregions_init(arm_mem_regions, NR_MEM_REGIONS);
diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
index eb93fd7c..f9fea519 100644
--- a/lib/arm64/processor.c
+++ b/lib/arm64/processor.c
@@ -8,6 +8,7 @@
#include <libcflat.h>
#include <asm/ptrace.h>
#include <asm/processor.h>
+#include <asm/setup.h>
#include <asm/thread_info.h>
static const char *vector_names[] = {
@@ -271,3 +272,16 @@ bool __mmu_enabled(void)
{
return read_sysreg(sctlr_el1) & SCTLR_EL1_M;
}
+
+#ifdef CONFIG_EFI
+
+void setup_efi_sctlr(void)
+{
+ /*
+ * EFI exits boot services with SCTLR_ELx.M=1, so keep
+ * the MMU enabled.
+ */
+ write_sysreg(INIT_SCTLR_EL1_MMU_OFF | SCTLR_EL1_M, sctlr_el1);
+}
+
+#endif
--
2.25.1
More information about the linux-arm-kernel
mailing list