All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Will Deacon <will@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	broonie@kernel.org, danielmentz@google.com, saravanak@google.com,
	kernel-team@android.com
Subject: [PATCH 2/6] arm64: Save state of HCR_EL2.E2H before switch to EL1
Date: Mon, 27 Jun 2022 16:14:08 +0100	[thread overview]
Message-ID: <20220627151412.1496361-3-maz@kernel.org> (raw)
In-Reply-To: <20220627151412.1496361-1-maz@kernel.org>

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@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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-06-27 15:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 15:14 [PATCH 0/6] arm64: Disabling SVE/SME from the command-line Marc Zyngier
2022-06-27 15:14 ` [PATCH 1/6] arm64: Rename the VHE switch to "finalise_el2" Marc Zyngier
2022-06-27 15:14 ` Marc Zyngier [this message]
2022-06-27 15:14 ` [PATCH 3/6] arm64: Allow sticky E2H when entering EL1 Marc Zyngier
2022-06-27 15:14 ` [PATCH 4/6] arm64: Factor out checking of a feature against the override into a macro Marc Zyngier
2022-06-28 11:28   ` Mark Brown
2022-06-29 15:46     ` Marc Zyngier
2022-06-29 16:00       ` Mark Brown
2022-06-27 15:14 ` [PATCH 5/6] arm64: Add the arm64.nosme command line option Marc Zyngier
2022-06-27 17:04   ` Mark Brown
2022-06-27 18:08     ` Marc Zyngier
2022-06-27 18:20       ` Mark Brown
2022-06-27 15:14 ` [PATCH 6/6] arm64: Add the arm64.nosve " Marc Zyngier
2022-06-27 17:08   ` Mark Brown
2022-06-27 15:18 ` [PATCH 0/6] arm64: Disabling SVE/SME from the command-line Mark Brown
2022-06-27 15:30   ` Marc Zyngier
2022-06-27 16:49     ` Mark Brown

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=20220627151412.1496361-3-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=ardb@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=danielmentz@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=saravanak@google.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.