KVM: x86/pmu: Refactor PERF_GLOBAL_CTRL update helper for reuse by PEBS
authorLike Xu <likexu@tencent.com>
Thu, 22 Sep 2022 20:40:38 +0000 (13:40 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 28 Sep 2022 19:47:21 +0000 (12:47 -0700)
Extract the "global ctrl" specific bits out of global_ctrl_changed() so
that the helper only deals with reprogramming general purpose counters,
and rename the helper accordingly.  PEBS needs the same logic, i.e needs
to reprogram counters associated when PEBS_ENABLE bits are toggled, and
will use the helper in a future fix.

No functional change intended.

Signed-off-by: Like Xu <likexu@tencent.com>
Link: https://lore.kernel.org/r/20220831085328.45489-4-likexu@tencent.com
[sean: split to separate patch, write changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/pmu_intel.c

index 78dec4dc6e6fad67e565e982b90ceb02b98abf27..5592b1259e1bb1802d08d2a8213ebbeec1ac7a86 100644 (file)
@@ -68,15 +68,11 @@ static struct kvm_pmc *intel_pmc_idx_to_pmc(struct kvm_pmu *pmu, int pmc_idx)
        }
 }
 
-/* function is called when global control register has been updated. */
-static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data)
+static void reprogram_counters(struct kvm_pmu *pmu, u64 diff)
 {
        int bit;
-       u64 diff = pmu->global_ctrl ^ data;
        struct kvm_pmc *pmc;
 
-       pmu->global_ctrl = data;
-
        for_each_set_bit(bit, (unsigned long *)&diff, X86_PMC_IDX_MAX) {
                pmc = intel_pmc_idx_to_pmc(pmu, bit);
                if (pmc)
@@ -397,7 +393,7 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
        struct kvm_pmc *pmc;
        u32 msr = msr_info->index;
        u64 data = msr_info->data;
-       u64 reserved_bits;
+       u64 reserved_bits, diff;
 
        switch (msr) {
        case MSR_CORE_PERF_FIXED_CTR_CTRL:
@@ -418,7 +414,9 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                if (pmu->global_ctrl == data)
                        return 0;
                if (kvm_valid_perf_global_ctrl(pmu, data)) {
-                       global_ctrl_changed(pmu, data);
+                       diff = pmu->global_ctrl ^ data;
+                       pmu->global_ctrl = data;
+                       reprogram_counters(pmu, diff);
                        return 0;
                }
                break;