[PATCH v2] KVM: x86/pmu: Don't pre-set the pmu->global_ctrl when refreshing

Like Xu posted 1 patch 3 years, 12 months ago
arch/x86/kvm/vmx/pmu_intel.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[PATCH v2] KVM: x86/pmu: Don't pre-set the pmu->global_ctrl when refreshing
Posted by Like Xu 3 years, 12 months ago
From: Like Xu <likexu@tencent.com>

Assigning a value to pmu->global_ctrl just to set the value of
pmu->global_ctrl_mask in a more readable way leaves a side effect of
not conforming to the specification. The value is reset to zero on
Power up and Reset but keeps unchanged on INIT, like an ordinary MSR.

Signed-off-by: Like Xu <likexu@tencent.com>
---
v1 -> v2 Changelog:
- Explicitly add parentheses around;

 arch/x86/kvm/vmx/pmu_intel.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
index b82b6709d7a8..7829ec457b28 100644
--- a/arch/x86/kvm/vmx/pmu_intel.c
+++ b/arch/x86/kvm/vmx/pmu_intel.c
@@ -522,9 +522,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
 		setup_fixed_pmc_eventsel(pmu);
 	}
 
-	pmu->global_ctrl = ((1ull << pmu->nr_arch_gp_counters) - 1) |
-		(((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED);
-	pmu->global_ctrl_mask = ~pmu->global_ctrl;
+	pmu->global_ctrl_mask = ~(((1ull << pmu->nr_arch_gp_counters) - 1) |
+		(((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED));
 	pmu->global_ovf_ctrl_mask = pmu->global_ctrl_mask
 			& ~(MSR_CORE_PERF_GLOBAL_OVF_CTRL_OVF_BUF |
 			    MSR_CORE_PERF_GLOBAL_OVF_CTRL_COND_CHGD);
-- 
2.36.1
Re: [PATCH v2] KVM: x86/pmu: Don't pre-set the pmu->global_ctrl when refreshing
Posted by Paolo Bonzini 3 years, 11 months ago
Queued, thanks.

Paolo