Skip to content

Commit 6515c61

Browse files
author
Marc Zyngier
committed
KVM: arm64: Fix kvm_vcpu_{set,is}_be() to deal with EL2 state
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... Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 597f41e commit 6515c61

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,21 +511,29 @@ static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu)
511511
if (vcpu_mode_is_32bit(vcpu)) {
512512
*vcpu_cpsr(vcpu) |= PSR_AA32_E_BIT;
513513
} else {
514-
u64 sctlr = vcpu_read_sys_reg(vcpu, SCTLR_EL1);
514+
enum vcpu_sysreg r;
515+
u64 sctlr;
516+
517+
r = vcpu_has_nv(vcpu) ? SCTLR_EL2 : SCTLR_EL1;
518+
519+
sctlr = vcpu_read_sys_reg(vcpu, r);
515520
sctlr |= SCTLR_ELx_EE;
516-
vcpu_write_sys_reg(vcpu, sctlr, SCTLR_EL1);
521+
vcpu_write_sys_reg(vcpu, sctlr, r);
517522
}
518523
}
519524

520525
static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
521526
{
527+
enum vcpu_sysreg r;
528+
u64 bit;
529+
522530
if (vcpu_mode_is_32bit(vcpu))
523531
return !!(*vcpu_cpsr(vcpu) & PSR_AA32_E_BIT);
524532

525-
if (vcpu_mode_priv(vcpu))
526-
return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_EE);
527-
else
528-
return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_EL1_E0E);
533+
r = is_hyp_ctxt(vcpu) ? SCTLR_EL2 : SCTLR_EL1;
534+
bit = vcpu_mode_priv(vcpu) ? SCTLR_ELx_EE : SCTLR_EL1_E0E;
535+
536+
return vcpu_read_sys_reg(vcpu, r) & bit;
529537
}
530538

531539
static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)