Skip to contentSkip to conversation

KVM: x86/pmu: Zero out pmu->all_valid_pmc_idx each time it's refreshed

PATCH Applied Like Xu 2 participants 2 messages Apr 4, 2023 – Apr 6, 2023

Subsystems (3)
lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 KVM: x86/pmu: Zero out pmu->all_valid_pmc_idx each time it's refreshed

From: Like Xu <[email protected]>

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")
---
 arch/x86/kvm/pmu.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kvm/pmu.c +1 -0
index 612e6c70ce2e..29492c2a0c82 100644
@@ -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);
 }
 
Signature · 1 line
2.40.0
maintainer Applied
#1 lore raw
Quoted 6 lines · Like Xu

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.

Applied to kvm-x86 pmu, thanks!

[1/1] KVM: x86/pmu: Zero out pmu->all_valid_pmc_idx each time it's refreshed

      https://github.com/kvm-x86/linux/commit/7e768ce8278b

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes