linux-arm-kernel.lists.infradead.org archive mirror
 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 3/6] arm64: Allow sticky E2H when entering EL1
Date: Mon, 27 Jun 2022 16:14:09 +0100	[thread overview]
Message-ID: <20220627151412.1496361-4-maz@kernel.org> (raw)
In-Reply-To: <20220627151412.1496361-1-maz@kernel.org>

For CPUs that have the unfortunate mis-feature to be stuck in
VHE mode, we perform a funny dance where we completely shortcut
the normal boot process to enable VHE and run the kernel at EL2,
and only then start booting the kernel.

Not only this is pretty ugly, but it means that the EL2 finalisation
occurs before we have processed the sysreg override.

Instead, start executing the kernel as if it was an EL1 guest and
rely on the normal EL2 finalisation to go back to EL2.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kernel/head.S | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index d35287c22d30..c4be34133b9c 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -520,6 +520,8 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
 	msr	vbar_el2, x0
 	isb
 
+	mov_q	x1, INIT_SCTLR_EL1_MMU_OFF
+
 	/*
 	 * Fruity CPUs seem to have HCR_EL2.E2H set to RES1,
 	 * making it impossible to start in nVHE mode. Is that
@@ -531,34 +533,16 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
 	str	x0, [x1]
 	cbz	x0, 1f
 
-	/* Switching to VHE requires a sane SCTLR_EL1 as a start */
-	mov_q	x0, INIT_SCTLR_EL1_MMU_OFF
-	msr_s	SYS_SCTLR_EL12, x0
-
-	/*
-	 * Force an eret into a helper "function", and let it return
-	 * to our original caller... This makes sure that we have
-	 * initialised the basic PSTATE state.
-	 */
-	mov	x0, #INIT_PSTATE_EL2
-	msr	spsr_el1, x0
-	adr	x0, __cpu_stick_to_vhe
-	msr	elr_el1, x0
-	eret
+	/* Set a sane SCTLR_EL1, the VHE way */
+	msr_s	SYS_SCTLR_EL12, x1
+	b	2f
 
 1:
-	mov_q	x0, INIT_SCTLR_EL1_MMU_OFF
-	msr	sctlr_el1, x0
-
+	msr	sctlr_el1, x1
+2:
 	msr	elr_el2, lr
 	mov	w0, #BOOT_CPU_MODE_EL2
 	eret
-
-__cpu_stick_to_vhe:
-	mov	x0, #HVC_FINALISE_EL2
-	hvc	#0
-	mov	x0, #BOOT_CPU_MODE_EL2
-	ret
 SYM_FUNC_END(init_kernel_el)
 
 /*
-- 
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:17 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 ` [PATCH 2/6] arm64: Save state of HCR_EL2.E2H before switch to EL1 Marc Zyngier
2022-06-27 15:14 ` Marc Zyngier [this message]
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-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).