From: Mark Rutland <mark.rutland@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: Leo Yan <leo.yan@arm.com>,
linux-arm-kernel@lists.infradead.org, ahmed.genidi@arm.com,
ben.horgan@arm.com, catalin.marinas@arm.com,
kvmarm@lists.linux.dev, oliver.upton@linux.dev, will@kernel.org
Subject: Re: [PATCH 1/2] KVM: arm64: Initialize HCR_EL2.E2H early
Date: Fri, 28 Feb 2025 11:13:39 +0000 [thread overview]
Message-ID: <Z8GaY09Ly2-qVRM1@J2N7QTR9R3> (raw)
In-Reply-To: <86v7supdzd.wl-maz@kernel.org>
On Fri, Feb 28, 2025 at 10:20:38AM +0000, Marc Zyngier wrote:
> On Fri, 28 Feb 2025 09:52:50 +0000,
> Mark Rutland <mark.rutland@arm.com> wrote:
> >
> > On Fri, Feb 28, 2025 at 09:43:20AM +0000, Marc Zyngier wrote:
> > > On Fri, 28 Feb 2025 09:29:55 +0000,
> > > Leo Yan <leo.yan@arm.com> wrote:
> > > >
> > > > Hi Mark,
> > > >
> > > > On Thu, Feb 27, 2025 at 06:05:25PM +0000, Mark Rutland wrote:
> > > >
> > > > [...]
> > > >
> > > > > +.macro init_el2_hcr val
> > > > > + mov_q x0, \val
> > > > > +
> > > > > + /*
> > > > > + * Compliant CPUs advertise their VHE-onlyness with
> > > > > + * ID_AA64MMFR4_EL1.E2H0 < 0. On such CPUs HCR_EL2.E2H is RES1, but it
> > > > > + * can reset into an UNKNOWN state and might not read as 1 until it has
> > > > > + * been initialized explicitly.
> > > >
> > > > For ID_AA64MMFR4_EL1.E2H0 < 0 case, the code actually clears the
> > > > HCR_EL2.E2H bit.
> > > >
> > > > Hence, the comment should be corrected as: "... it can reset into an
> > > > UNKNOWN state and might not read as 0 until it has been initialized
> > > > explicitly".
> > >
> > > The comment is just fine. It is the code that is wrong, as it avoids
> > > setting E2H when E2H0 < 0 while we want the exact opposite behaviour.
> > >
> > > As a result, 'b.lt' really should be a 'b.ge'. Or the original code
> > > kept as is.
> >
> > Ugh, yes. I got confused and got the condition backwards.
> >
> > Either works. Using 'b.ge' is closer to my intention -- I found the
> > 'tbz' of the sign bit somewhat surprising and that needed a longer line
> > after the lable name changed.
> >
> > Would you like me to respin, or would you be hapy to fix up when
> > applying?
>
> I can fix it on the fly, but it needs retesting, as I don't understand
> how things could work in this state.
This happened to work by virtue of coincidence :/
Critically, I have not tested this on a CPU where HCR_EL2.E2H is
writeable but one polarity has no effect, as I don't have such a CPU to
hand. IIUC you tested that with hVHE under NV per commit:
b3320142f3db9b3f ("arm64: Fix early handling of FEAT_E2H0 not being implemented")
... but I don't currently have a good setup to test that configuration.
In other cases, this largely falls out in the wash, e.g.
* On a CPU without E2H, where the HCR_EL2.E2H bit is implemented as
RAZ/WI, the bit always reads as 0. Trying to set the bit has no
effect. Later reads see 0.
Hence this case happens to work.
* On a CPU with E2H and without FEAT_E2H0, where the HCR_EL2.E2H bit is
implemented as RAO/WI, the bit always reads as 1. Trying to clear the
bit has no effect. Later reads see 1.
Hence this case happens to work.
* On a CPU with E2H and with FEAT_E2H0, there the HCR_EL2.E2H bit is
implemented and has an effect, writing to the bit moves the CPU into
E2H mode.
The early boot code handles this the same as FEAT_E2H0 being absent,
and so that happens to work. I haven't dug into how HCR_EL2 gets
properly initialized later by KVM, but testing seems to indicate that
this works.
Mark.
next prev parent reply other threads:[~2025-02-28 12:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 18:05 [PATCH 0/2] KVM: arm64: PSCI relay fixes Mark Rutland
2025-02-27 18:05 ` [PATCH 1/2] KVM: arm64: Initialize HCR_EL2.E2H early Mark Rutland
2025-02-28 9:29 ` Leo Yan
2025-02-28 9:43 ` Marc Zyngier
2025-02-28 9:52 ` Mark Rutland
2025-02-28 10:20 ` Marc Zyngier
2025-02-28 11:13 ` Mark Rutland [this message]
2025-02-28 10:14 ` Leo Yan
2025-02-27 18:05 ` [PATCH 2/2] KVM: arm64: Initialize SCTLR_EL1 in __kvm_hyp_init_cpu() Mark Rutland
2025-02-28 9:56 ` Leo Yan
2025-03-02 8:41 ` [PATCH 0/2] KVM: arm64: PSCI relay fixes 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=Z8GaY09Ly2-qVRM1@J2N7QTR9R3 \
--to=mark.rutland@arm.com \
--cc=ahmed.genidi@arm.com \
--cc=ben.horgan@arm.com \
--cc=catalin.marinas@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--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