KVM: x86/pmu: Use different raw event masks for AMD and Intel
authorJim Mattson <jmattson@google.com>
Tue, 8 Mar 2022 01:24:52 +0000 (17:24 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 2 Apr 2022 09:34:40 +0000 (05:34 -0400)
The third nybble of AMD's event select overlaps with Intel's IN_TX and
IN_TXCP bits. Therefore, we can't use AMD64_RAW_EVENT_MASK on Intel
platforms that support TSX.

Declare a raw_event_mask in the kvm_pmu structure, initialize it in
the vendor-specific pmu_refresh() functions, and use that mask for
PERF_TYPE_RAW configurations in reprogram_gp_counter().

Fixes: 710c47651431 ("KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW")
Signed-off-by: Jim Mattson <jmattson@google.com>
Message-Id: <20220308012452.3468611-1-jmattson@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/pmu.c
arch/x86/kvm/svm/pmu.c
arch/x86/kvm/vmx/pmu_intel.c

index 469c7702fad9d0f392addec5065ef22060847f03..47de0226d674e33e55f0dd5d04ac1295ea02956a 100644 (file)
@@ -511,6 +511,7 @@ struct kvm_pmu {
        u64 global_ctrl_mask;
        u64 global_ovf_ctrl_mask;
        u64 reserved_bits;
+       u64 raw_event_mask;
        u8 version;
        struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
        struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED];
index b1a02993782b376cfb5460ce786644115811b0ce..902b6d7002156b5a78a357a8404f71b415e81def 100644 (file)
@@ -185,6 +185,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
        u32 type = PERF_TYPE_RAW;
        struct kvm *kvm = pmc->vcpu->kvm;
        struct kvm_pmu_event_filter *filter;
+       struct kvm_pmu *pmu = vcpu_to_pmu(pmc->vcpu);
        bool allow_event = true;
 
        if (eventsel & ARCH_PERFMON_EVENTSEL_PIN_CONTROL)
@@ -221,7 +222,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
        }
 
        if (type == PERF_TYPE_RAW)
-               config = eventsel & AMD64_RAW_EVENT_MASK;
+               config = eventsel & pmu->raw_event_mask;
 
        if (pmc->current_config == eventsel && pmc_resume_counter(pmc))
                return;
index d4de5240933527b23604ed7703d14798a3bab065..e4163f75c11b08fc6801fecaf179e8e73263ad5d 100644 (file)
@@ -284,6 +284,7 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu)
 
        pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1;
        pmu->reserved_bits = 0xfffffff000280000ull;
+       pmu->raw_event_mask = AMD64_RAW_EVENT_MASK;
        pmu->version = 1;
        /* not applicable to AMD; but clean them to prevent any fall out */
        pmu->counter_bitmask[KVM_PMC_FIXED] = 0;
index 4e5b1eeeb77c3af0e5b0c6a715cdcf3bd0b31ed3..da71160a50d6cc77a4e2fa0454b60a3adfc07f9e 100644 (file)
@@ -485,6 +485,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
        pmu->counter_bitmask[KVM_PMC_FIXED] = 0;
        pmu->version = 0;
        pmu->reserved_bits = 0xffffffff00200000ull;
+       pmu->raw_event_mask = X86_RAW_EVENT_MASK;
 
        entry = kvm_find_cpuid_entry(vcpu, 0xa, 0);
        if (!entry || !vcpu->kvm->arch.enable_pmu)