* [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state
@ 2025-09-16 16:11 Marc Zyngier
2025-09-17 5:21 ` Oliver Upton
2025-09-17 16:42 ` Marc Zyngier
0 siblings, 2 replies; 4+ messages in thread
From: Marc Zyngier @ 2025-09-16 16:11 UTC (permalink / raw)
To: linux-arm-kernel, kvmarm
Cc: Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu
Nobody really cares about BE, but KVM currently only deals with
SCTLR_EL1 when evaluating or setting the endianness in PSCI,
meaning that we evaluate whatever the L2 state has been at some point.
Teach these primitives about SCTLR_EL2, and forget about BE...
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/kvm_emulate.h | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index fa8a08a1ccd5c..85f998dffea5d 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -511,21 +511,29 @@ static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu)
if (vcpu_mode_is_32bit(vcpu)) {
*vcpu_cpsr(vcpu) |= PSR_AA32_E_BIT;
} else {
- u64 sctlr = vcpu_read_sys_reg(vcpu, SCTLR_EL1);
+ enum vcpu_sysreg r;
+ u64 sctlr;
+
+ r = vcpu_has_nv(vcpu) ? SCTLR_EL2 : SCTLR_EL1;
+
+ sctlr = vcpu_read_sys_reg(vcpu, r);
sctlr |= SCTLR_ELx_EE;
- vcpu_write_sys_reg(vcpu, sctlr, SCTLR_EL1);
+ vcpu_write_sys_reg(vcpu, sctlr, r);
}
}
static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
{
+ enum vcpu_sysreg r;
+ u64 bit;
+
if (vcpu_mode_is_32bit(vcpu))
return !!(*vcpu_cpsr(vcpu) & PSR_AA32_E_BIT);
- if (vcpu_mode_priv(vcpu))
- return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_EE);
- else
- return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_EL1_E0E);
+ r = is_hyp_ctxt(vcpu) ? SCTLR_EL2 : SCTLR_EL1;
+ bit = vcpu_mode_priv(vcpu) ? SCTLR_ELx_EE : SCTLR_EL1_E0E;
+
+ return vcpu_read_sys_reg(vcpu, r) & bit;
}
static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state
2025-09-16 16:11 [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state Marc Zyngier
@ 2025-09-17 5:21 ` Oliver Upton
2025-09-17 8:21 ` Marc Zyngier
2025-09-17 16:42 ` Marc Zyngier
1 sibling, 1 reply; 4+ messages in thread
From: Oliver Upton @ 2025-09-17 5:21 UTC (permalink / raw)
To: Marc Zyngier
Cc: linux-arm-kernel, kvmarm, Joey Gouly, Suzuki K Poulose,
Zenghui Yu
On Tue, Sep 16, 2025 at 05:11:03PM +0100, Marc Zyngier wrote:
> Nobody really cares about BE, but KVM currently only deals with
> SCTLR_EL1 when evaluating or setting the endianness in PSCI,
> meaning that we evaluate whatever the L2 state has been at some point.
>
> Teach these primitives about SCTLR_EL2, and forget about BE...
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
You know, I was about to say "don't we need to sanitise this?" although
that seems to already be in place. Nice.
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Thanks,
Oliver
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state
2025-09-17 5:21 ` Oliver Upton
@ 2025-09-17 8:21 ` Marc Zyngier
0 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2025-09-17 8:21 UTC (permalink / raw)
To: Oliver Upton
Cc: linux-arm-kernel, kvmarm, Joey Gouly, Suzuki K Poulose,
Zenghui Yu
On Wed, 17 Sep 2025 06:21:09 +0100,
Oliver Upton <oliver.upton@linux.dev> wrote:
>
> On Tue, Sep 16, 2025 at 05:11:03PM +0100, Marc Zyngier wrote:
> > Nobody really cares about BE, but KVM currently only deals with
> > SCTLR_EL1 when evaluating or setting the endianness in PSCI,
> > meaning that we evaluate whatever the L2 state has been at some point.
> >
> > Teach these primitives about SCTLR_EL2, and forget about BE...
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
>
> You know, I was about to say "don't we need to sanitise this?" although
> that seems to already be in place. Nice.
Only for SCTLR_EL1.
SCTLR_EL2, annoyingly enough, isn't, owing to plenty of bits depending
on E2H. It's on my long list of things to address, but I'd like a
common mechanism that'd deal with horrors such as CNTHCTL_EL2...
> Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state
2025-09-16 16:11 [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state Marc Zyngier
2025-09-17 5:21 ` Oliver Upton
@ 2025-09-17 16:42 ` Marc Zyngier
1 sibling, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2025-09-17 16:42 UTC (permalink / raw)
To: linux-arm-kernel, kvmarm, Marc Zyngier
Cc: Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu
On Tue, 16 Sep 2025 17:11:03 +0100, Marc Zyngier wrote:
> Nobody really cares about BE, but KVM currently only deals with
> SCTLR_EL1 when evaluating or setting the endianness in PSCI,
> meaning that we evaluate whatever the L2 state has been at some point.
>
> Teach these primitives about SCTLR_EL2, and forget about BE...
>
>
> [...]
Applied to next, thanks!
[1/1] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state
commit: 6515c612e79949b17ef4b8c4180c07bbeaf01e4d
Cheers,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-17 16:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-16 16:11 [PATCH] KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state Marc Zyngier
2025-09-17 5:21 ` Oliver Upton
2025-09-17 8:21 ` Marc Zyngier
2025-09-17 16:42 ` Marc Zyngier
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).