Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <maz@kernel.org>
Link: https://lore.kernel.org/r/20241217175611.3658290-1-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>

+8 -2
+8 -2
arch/arm64/kvm/pmu-emul.c
··· 617 617 kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0); 618 618 619 619 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 + 622 628 for_each_set_bit(i, &mask, 32) 623 629 kvm_pmu_set_pmc_value(kvm_vcpu_idx_to_pmc(vcpu, i), 0, true); 624 630 }