From: Marc Zyngier <maz@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Hector Martin <marcan@marcan.st>, Arnd Bergmann <arnd@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
kernel-team@android.com
Subject: [PATCH v2 3/3] arm64: Allow nVHE impaired CPUs to boot without CONFIG_ARM64_VHE
Date: Tue, 30 Mar 2021 18:39:47 +0100 [thread overview]
Message-ID: <20210330173947.999859-4-maz@kernel.org> (raw)
In-Reply-To: <20210330173947.999859-1-maz@kernel.org>
CPUs stuck in VHE mode need some additional care if the kernel
is compiled without CONFIG_ARM64_VHE.
Treat this case as another version of a mismatched boot, and
prevent KVM from being initialised. The machine will boot in
some bizarre state, using TPIDR_EL1 instead of TPIDR_EL2, but
otherwise be functional.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/virt.h | 18 +++++++++++++-----
arch/arm64/kvm/va_layout.c | 9 +++++++++
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h
index 7379f35ae2c6..69bc4e26aa26 100644
--- a/arch/arm64/include/asm/virt.h
+++ b/arch/arm64/include/asm/virt.h
@@ -72,6 +72,11 @@ void __hyp_reset_vectors(void);
DECLARE_STATIC_KEY_FALSE(kvm_protected_mode_initialized);
+static inline bool is_kernel_in_hyp_mode(void)
+{
+ return read_sysreg(CurrentEL) == CurrentEL_EL2;
+}
+
/* Reports the availability of HYP mode */
static inline bool is_hyp_mode_available(void)
{
@@ -83,6 +88,10 @@ static inline bool is_hyp_mode_available(void)
static_branch_likely(&kvm_protected_mode_initialized))
return true;
+ /* Catch braindead CPUs */
+ if (!IS_ENABLED(CONFIG_ARM64_VHE) && is_kernel_in_hyp_mode())
+ return false;
+
return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
__boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
}
@@ -98,12 +107,11 @@ static inline bool is_hyp_mode_mismatched(void)
static_branch_likely(&kvm_protected_mode_initialized))
return false;
- return __boot_cpu_mode[0] != __boot_cpu_mode[1];
-}
+ /* Catch braindead CPUs */
+ if (!IS_ENABLED(CONFIG_ARM64_VHE) && is_kernel_in_hyp_mode())
+ return true;
-static inline bool is_kernel_in_hyp_mode(void)
-{
- return read_sysreg(CurrentEL) == CurrentEL_EL2;
+ return __boot_cpu_mode[0] != __boot_cpu_mode[1];
}
static __always_inline bool has_vhe(void)
diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c
index 978301392d67..edb048654e00 100644
--- a/arch/arm64/kvm/va_layout.c
+++ b/arch/arm64/kvm/va_layout.c
@@ -156,6 +156,9 @@ void __init kvm_update_va_mask(struct alt_instr *alt,
{
int i;
+ if (!is_hyp_mode_available())
+ return;
+
BUG_ON(nr_inst != 5);
for (i = 0; i < nr_inst; i++) {
@@ -191,6 +194,9 @@ void kvm_patch_vector_branch(struct alt_instr *alt,
u64 addr;
u32 insn;
+ if (!is_hyp_mode_available())
+ return;
+
BUG_ON(nr_inst != 4);
if (!cpus_have_const_cap(ARM64_SPECTRE_V3A) || WARN_ON_ONCE(has_vhe()))
@@ -244,6 +250,9 @@ static void generate_mov_q(u64 val, __le32 *origptr, __le32 *updptr, int nr_inst
{
u32 insn, oinsn, rd;
+ if (!is_hyp_mode_available())
+ return;
+
BUG_ON(nr_inst != 4);
/* Compute target register */
--
2.29.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-03-30 17:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 17:39 [PATCH v2 0/3] arm64: Dealing with VHE-only CPUs Marc Zyngier
2021-03-30 17:39 ` [PATCH v2 1/3] arm64: cpufeature: Allow early filtering of feature override Marc Zyngier
2021-04-08 11:13 ` Hector Martin
2021-04-08 13:11 ` Marc Zyngier
2021-03-30 17:39 ` [PATCH v2 2/3] arm64: Cope with CPUs stuck in VHE mode Marc Zyngier
2021-04-07 21:16 ` Will Deacon
2021-03-30 17:39 ` Marc Zyngier [this message]
2021-04-07 21:18 ` [PATCH v2 3/3] arm64: Allow nVHE impaired CPUs to boot without CONFIG_ARM64_VHE Will Deacon
2021-04-08 10:31 ` Marc Zyngier
2021-04-08 10:58 ` Will Deacon
2021-04-08 13:05 ` Marc Zyngier
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=20210330173947.999859-4-maz@kernel.org \
--to=maz@kernel.org \
--cc=arnd@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kernel-team@android.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marcan@marcan.st \
--cc=mark.rutland@arm.com \
--cc=will@kernel.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.