]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86/pmu: do not mask the value that is written to fixed PMUs
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 20 May 2019 15:34:30 +0000 (17:34 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 May 2019 19:27:14 +0000 (21:27 +0200)
According to the SDM, for MSR_IA32_PERFCTR0/1 "the lower-order 32 bits of
each MSR may be written with any value, and the high-order 8 bits are
sign-extended according to the value of bit 31", but the fixed counters
in real hardware are limited to the width of the fixed counters ("bits
beyond the width of the fixed-function counter are reserved and must be
written as zeros").  Fix KVM to do the same.

Reported-by: Nadav Amit <nadav.amit@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/pmu_intel.c

index b6f5157445fe80173a97f40b765cc48d54257af2..a99613a060dd8cee8790a3213cfc826c506fc784 100644 (file)
@@ -240,11 +240,14 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                }
                break;
        default:
-               if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) ||
-                   (pmc = get_fixed_pmc(pmu, msr))) {
-                       if (!msr_info->host_initiated)
-                               data = (s64)(s32)data;
-                       pmc->counter += data - pmc_read_counter(pmc);
+               if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0))) {
+                       if (msr_info->host_initiated)
+                               pmc->counter = data;
+                       else
+                               pmc->counter = (s32)data;
+                       return 0;
+               } else if ((pmc = get_fixed_pmc(pmu, msr))) {
+                       pmc->counter = data;
                        return 0;
                } else if ((pmc = get_gp_pmc(pmu, msr, MSR_P6_EVNTSEL0))) {
                        if (data == pmc->eventsel)