[PATCH v7 11/20] KVM: arm64: Enforce PMU event filter at vcpu_load()
Colton Lewis
coltonlewis at google.com
Thu Jun 18 16:30:10 PDT 2026
Hi Yifan, thanks for the review.
wuyifan <wuyifan50 at huawei.com> writes:
> Hi Colton,
> On 5/5/2026 5:18 AM, Colton Lewis wrote:
>> + for_each_set_bit(i, &guest_counters, ARMPMU_MAX_HWEVENTS) {
>> + if (i == ARMV8_PMU_CYCLE_IDX) {
>> + val = __vcpu_sys_reg(vcpu, PMCCFILTR_EL0);
>> + evsel = ARMV8_PMUV3_PERFCTR_CPU_CYCLES;
>> + } else {
>> + val = __vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i);
>> + evsel = val & kvm_pmu_event_mask(vcpu->kvm);
>> + }
>> +
>> + guest_include_el2 = (val & ARMV8_PMU_INCLUDE_EL2);
>> + val &= ~evtyper_clr;
>> +
>> + if (unlikely(is_hyp_ctxt(vcpu)) && guest_include_el2)
>> + val &= ~ARMV8_PMU_EXCLUDE_EL1;
>> +
>> + if (vcpu->kvm->arch.pmu_filter &&
>> + !test_bit(evsel, vcpu->kvm->arch.pmu_filter))
>> + val |= evtyper_set;
>> +
>> + if (i == ARMV8_PMU_CYCLE_IDX) {
>> + write_sysreg(val, pmccntr_el0);
> This should be pmccfiltr_el0.
> Writing the filter bits to pmccntr_el0 would corrupt the cycle count
> value.
Yes it should. I found that and thought I corrected it before I sent out
the series. Thanks for catching it.
>> + } else {
>> + write_sysreg(i, pmselr_el0);
>> + write_sysreg(val, pmxevtyper_el0);
>> + }
>> + }
>> +}
> Thanks,
> Yifan
More information about the linux-arm-kernel
mailing list