treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 499
[linux-2.6-microblaze.git] / arch / x86 / kvm / pmu.c
index e397419..132d149 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Kernel-based Virtual Machine -- Performance Monitoring Unit support
  *
@@ -7,10 +8,6 @@
  *   Avi Kivity   <avi@redhat.com>
  *   Gleb Natapov <gleb@redhat.com>
  *   Wei Huang    <wei@redhat.com>
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- *
  */
 
 #include <linux/types.h>
@@ -283,7 +280,7 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
        bool fast_mode = idx & (1u << 31);
        struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
        struct kvm_pmc *pmc;
-       u64 ctr_val;
+       u64 mask = fast_mode ? ~0u : ~0ull;
 
        if (!pmu->version)
                return 1;
@@ -291,15 +288,11 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
        if (is_vmware_backdoor_pmc(idx))
                return kvm_pmu_rdpmc_vmware(vcpu, idx, data);
 
-       pmc = kvm_x86_ops->pmu_ops->msr_idx_to_pmc(vcpu, idx);
+       pmc = kvm_x86_ops->pmu_ops->msr_idx_to_pmc(vcpu, idx, &mask);
        if (!pmc)
                return 1;
 
-       ctr_val = pmc_read_counter(pmc);
-       if (fast_mode)
-               ctr_val = (u32)ctr_val;
-
-       *data = ctr_val;
+       *data = pmc_read_counter(pmc) & mask;
        return 0;
 }