Skip to content

Commit 292e8f1

Browse files
author
Marc Zyngier
committed
KVM: arm64: PMU: Simplify PMCR_EL0 reset handling
Resetting PMCR_EL0 is a pretty involved process that includes poisoning some of the writable bits, just because we can. It makes it hard to reason about about what gets configured, and just resetting things to 0 seems like a much saner option. Reduce reset_pmcr() to just preserving PMCR_EL0.N from the host, and setting PMCR_EL0.LC if we don't support AArch32. Signed-off-by: Marc Zyngier <[email protected]>
1 parent 8681573 commit 292e8f1

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -639,24 +639,18 @@ static void reset_pmselr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
639639

640640
static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
641641
{
642-
u64 pmcr, val;
642+
u64 pmcr;
643643

644644
/* No PMU available, PMCR_EL0 may UNDEF... */
645645
if (!kvm_arm_support_pmu_v3())
646646
return;
647647

648-
pmcr = read_sysreg(pmcr_el0);
649-
/*
650-
* Writable bits of PMCR_EL0 (ARMV8_PMU_PMCR_MASK) are reset to UNKNOWN
651-
* except PMCR.E resetting to zero.
652-
*/
653-
val = ((pmcr & ~ARMV8_PMU_PMCR_MASK)
654-
| (ARMV8_PMU_PMCR_MASK & 0xdecafbad)) & (~ARMV8_PMU_PMCR_E);
648+
/* Only preserve PMCR_EL0.N, and reset the rest to 0 */
649+
pmcr = read_sysreg(pmcr_el0) & ARMV8_PMU_PMCR_N_MASK;
655650
if (!kvm_supports_32bit_el0())
656-
val |= ARMV8_PMU_PMCR_LC;
657-
if (!kvm_pmu_is_3p5(vcpu))
658-
val &= ~ARMV8_PMU_PMCR_LP;
659-
__vcpu_sys_reg(vcpu, r->reg) = val;
651+
pmcr |= ARMV8_PMU_PMCR_LC;
652+
653+
__vcpu_sys_reg(vcpu, r->reg) = pmcr;
660654
}
661655

662656
static bool check_pmu_access_disabled(struct kvm_vcpu *vcpu, u64 flags)

0 commit comments

Comments
 (0)