Skip to content

Commit 959e953

Browse files
Marc Zyngiergregkh
authored andcommitted
arm64: KVM: pmu: Reset PMSELR_EL0.SEL to a sane value before entering the guest
commit 21cbe3c upstream. The ARMv8 architecture allows the cycle counter to be configured by setting PMSELR_EL0.SEL==0x1f and then accessing PMXEVTYPER_EL0, hence accessing PMCCFILTR_EL0. But it disallows the use of PMSELR_EL0.SEL==0x1f to access the cycle counter itself through PMXEVCNTR_EL0. Linux itself doesn't violate this rule, but we may end up with PMSELR_EL0.SEL being set to 0x1f when we enter a guest. If that guest accesses PMXEVCNTR_EL0, the access may UNDEF at EL1, despite the guest not having done anything wrong. In order to avoid this unfortunate course of events (haha!), let's sanitize PMSELR_EL0 on guest entry. This ensures that the guest won't explode unexpectedly. Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 111e0cc commit 959e953

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎arch/arm64/kvm/hyp/switch.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,13 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
8585
write_sysreg(val, hcr_el2);
8686
/* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */
8787
write_sysreg(1 << 15, hstr_el2);
88-
/* Make sure we trap PMU access from EL0 to EL2 */
88+
/*
89+
* Make sure we trap PMU access from EL0 to EL2. Also sanitize
90+
* PMSELR_EL0 to make sure it never contains the cycle
91+
* counter, which could make a PMXEVCNTR_EL0 access UNDEF at
92+
* EL1 instead of being trapped to EL2.
93+
*/
94+
write_sysreg(0, pmselr_el0);
8995
write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0);
9096
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
9197
__activate_traps_arch()();

0 commit comments

Comments
 (0)