[PATCH 2/6] arm64: Save state of HCR_EL2.E2H before switch to EL1
Marc Zyngier
maz at kernel.org
Mon Jun 27 08:14:08 PDT 2022
As we're about to switch the way E2H-stuck CPUs boot, save
the boot CPU E2H state into a global variable that can then be
checked by the iderg override code.
This allows us to replace the is_kernel_in_hyp_mode() check
with a simple comparison with this variable, even when running
at EL1. Note that the variable's validity is pretty short
(it cannot be trusted once a secondary has booted).
Use with caution.
Signed-off-by: Marc Zyngier <maz at kernel.org>
---
arch/arm64/kernel/head.S | 11 +++++++++++
arch/arm64/kernel/idreg-override.c | 10 +++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index f8550a939a6e..d35287c22d30 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -527,6 +527,8 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
*/
mrs x0, hcr_el2
and x0, x0, #HCR_E2H
+ adr_l x1, __e2h_state
+ str x0, [x1]
cbz x0, 1f
/* Switching to VHE requires a sane SCTLR_EL1 as a start */
@@ -599,6 +601,15 @@ SYM_DATA_END(__boot_cpu_mode)
SYM_DATA_START(__early_cpu_boot_status)
.quad 0
SYM_DATA_END(__early_cpu_boot_status)
+/*
+ * The value of the boot CPU's HCR_EL2.E2H state before dropping to
+ * EL1, so that the idreg override code can work out whether it can
+ * run in nVHE mode. Note that this is meaningless once a secondary
+ * CPU has booted, as it will have been overwritten.
+ */
+SYM_DATA_START(__e2h_state)
+ .quad 0
+SYM_DATA_END(__e2h_state)
.popsection
diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c
index 8a2ceb591686..6abff337b23b 100644
--- a/arch/arm64/kernel/idreg-override.c
+++ b/arch/arm64/kernel/idreg-override.c
@@ -31,13 +31,13 @@ struct ftr_set_desc {
static bool __init mmfr1_vh_filter(u64 val)
{
+ extern u64 __e2h_state;
/*
- * If we ever reach this point while running VHE, we're
- * guaranteed to be on one of these funky, VHE-stuck CPUs. If
- * the user was trying to force nVHE on us, proceed with
- * attitude adjustment.
+ * If the boot CPU has HCR_EL2.E2H set, we're guaranteed to be
+ * on one of these funky, VHE-stuck CPUs. If the user was
+ * trying to force nVHE on us, proceed with attitude adjustment.
*/
- return !(is_kernel_in_hyp_mode() && val == 0);
+ return !(__e2h_state != 0 && val == 0);
}
static const struct ftr_set_desc mmfr1 __initconst = {
--
2.34.1
More information about the linux-arm-kernel
mailing list