From: Marc Zyngier <maz@kernel.org>
To: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
Hector Martin <marcan@marcan.st>, Arnd Bergmann <arnd@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
kernel-team@android.com
Subject: Re: [PATCH 2/2] arm64: Cope with CPUs stuck in VHE mode
Date: Fri, 26 Mar 2021 11:20:18 +0000 [thread overview]
Message-ID: <87sg4if9fx.wl-maz@kernel.org> (raw)
In-Reply-To: <20210325193318.GD16123@willie-the-truck>
On Thu, 25 Mar 2021 19:33:19 +0000,
Will Deacon <will@kernel.org> wrote:
>
> On Thu, Mar 25, 2021 at 12:47:21PM +0000, Marc Zyngier wrote:
> > It seems that the CPUs part of the SoC known as Apple M1 have the
> > terrible habit of being stuck with HCR_EL2.E2H==1, in violation
> > of the architecture.
> >
> > Try and work around this deplorable state of affairs by detecting
> > the stuck bit early and short-circuit the nVHE dance. Additional
> > filtering code ensures that attempts at switching to nVHE from
> > the command-line are also ignored.
> >
> > It is still unknown whether there are many more such nuggets
> > to be found...
> >
> > Reported-by: Hector Martin <marcan@marcan.st>
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > arch/arm64/kernel/head.S | 33 +++++++++++++++++++++++++++---
> > arch/arm64/kernel/hyp-stub.S | 15 ++++++++++----
> > arch/arm64/kernel/idreg-override.c | 13 +++++++++++-
> > 3 files changed, 53 insertions(+), 8 deletions(-)
> >
> > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> > index 840bda1869e9..db2de5b8f3d9 100644
> > --- a/arch/arm64/kernel/head.S
> > +++ b/arch/arm64/kernel/head.S
> > @@ -477,14 +477,13 @@ EXPORT_SYMBOL(kimage_vaddr)
> > * booted in EL1 or EL2 respectively.
> > */
> > SYM_FUNC_START(init_kernel_el)
> > - mov_q x0, INIT_SCTLR_EL1_MMU_OFF
> > - msr sctlr_el1, x0
> > -
> > mrs x0, CurrentEL
> > cmp x0, #CurrentEL_EL2
> > b.eq init_el2
> >
> > SYM_INNER_LABEL(init_el1, SYM_L_LOCAL)
> > + mov_q x0, INIT_SCTLR_EL1_MMU_OFF
> > + msr sctlr_el1, x0
> > isb
> > mov_q x0, INIT_PSTATE_EL1
> > msr spsr_el1, x0
> > @@ -504,6 +503,34 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
> > msr vbar_el2, x0
> > isb
> >
> > + /*
> > + * Fruity CPUs seem to have HCR_EL2.E2H set to RES1,
> > + * making it impossible to start in nVHE mode. Is that
> > + * compliant with the architecture? Absolutely not!
> > + */
> > + mrs x0, hcr_el2
> > + and x0, x0, #HCR_E2H
> > + 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_l x0, stick_to_vhe
> > + msr elr_el1, x0
> > + eret
>
> What does this do if CONFIG_VHE=n on one of these CPUs?
Interesting question. With this patch, it will actually boot, and
behave just fine as long as you don't run a guest (the percpu offset
being stored in TPIDR_EL1 will then be corrupted, though you may not
even get there because of the sysreg renaming being unexpectedly
active).
I guess I could either make this code conditional on CONFIG_ARM64_VHE
and let the machine crash early without a word, or have some later
checks once the machine started booting. In the later case, displaying
anything useful is going to be a challenge though (the odds of someone
having a serial console on this box are close to nil). Pick your poison.
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
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-26 11:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 12:47 [PATCH 0/2] arm64: Dealing with VHE-only CPUs Marc Zyngier
2021-03-25 12:47 ` [PATCH 1/2] arm64: cpufeature: Allow early filtering of feature override Marc Zyngier
2021-03-25 19:27 ` Will Deacon
2021-03-26 10:56 ` Marc Zyngier
2021-03-29 10:21 ` Will Deacon
2021-03-25 12:47 ` [PATCH 2/2] arm64: Cope with CPUs stuck in VHE mode Marc Zyngier
2021-03-25 19:33 ` Will Deacon
2021-03-26 11:20 ` Marc Zyngier [this message]
2021-03-29 10:22 ` Will Deacon
2021-03-30 17:00 ` 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=87sg4if9fx.wl-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 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).