KVM: x86/pmu: Zero out pmu->all_valid_pmc_idx each time it's refreshed
authorLike Xu <likexu@tencent.com>
Tue, 4 Apr 2023 07:17:59 +0000 (15:17 +0800)
committerSean Christopherson <seanjc@google.com>
Wed, 5 Apr 2023 23:33:10 +0000 (16:33 -0700)
The kvm_pmu_refresh() may be called repeatedly (e.g. configure guest
CPUID repeatedly or update MSR_IA32_PERF_CAPABILITIES) and each
call will use the last pmu->all_valid_pmc_idx value, with the residual
bits introducing additional overhead later in the vPMU emulation.

Fixes: b35e5548b411 ("KVM: x86/vPMU: Add lazy mechanism to release perf_event per vPMC")
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Like Xu <likexu@tencent.com>
Link: https://lore.kernel.org/r/20230404071759.75376-1-likexu@tencent.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/pmu.c

index 612e6c70ce2e7212e327589b8e76913114377af7..29492c2a0c8261b124a899dedc75fff539142975 100644 (file)
@@ -589,6 +589,7 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
  */
 void kvm_pmu_refresh(struct kvm_vcpu *vcpu)
 {
+       bitmap_zero(vcpu_to_pmu(vcpu)->all_valid_pmc_idx, X86_PMC_IDX_MAX);
        static_call(kvm_x86_pmu_refresh)(vcpu);
 }