diff mbox series

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

Message ID 20230404071759.75376-1-likexu@tencent.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86/pmu: Zero out pmu->all_valid_pmc_idx each time it's refreshed | expand

Commit Message

Like Xu April 4, 2023, 7:17 a.m. UTC
From: Like Xu <likexu@tencent.com>

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>
---
 arch/x86/kvm/pmu.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Sean Christopherson April 5, 2023, 11:59 p.m. UTC | #1
On Tue, 04 Apr 2023 15:17:59 +0800, Like Xu wrote:
> 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
diff mbox series

Patch

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 612e6c70ce2e..29492c2a0c82 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -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);
 }