Skip to content

Commit e96d8b8

Browse files
committed
KVM: arm64: Only apply PMCR_EL0.P to the guest range of counters
An important distinction from other registers affected by HPMN is that PMCR_EL0 only affects the guest range of counters, regardless of the EL from which it is accessed. Ensure that PMCR_EL0.P is always applied to 'guest' counters by manually computing the mask rather than deriving it from the current context. Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent d3ba35b commit e96d8b8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/arm64/kvm/pmu-emul.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,14 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
617617
kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
618618

619619
if (val & ARMV8_PMU_PMCR_P) {
620-
unsigned long mask = kvm_pmu_accessible_counter_mask(vcpu);
621-
mask &= ~BIT(ARMV8_PMU_CYCLE_IDX);
620+
/*
621+
* Unlike other PMU sysregs, the controls in PMCR_EL0 always apply
622+
* to the 'guest' range of counters and never the 'hyp' range.
623+
*/
624+
unsigned long mask = kvm_pmu_implemented_counter_mask(vcpu) &
625+
~kvm_pmu_hyp_counter_mask(vcpu) &
626+
~BIT(ARMV8_PMU_CYCLE_IDX);
627+
622628
for_each_set_bit(i, &mask, 32)
623629
kvm_pmu_set_pmc_value(kvm_vcpu_idx_to_pmc(vcpu, i), 0, true);
624630
}

0 commit comments

Comments
 (0)