Skip to content

Commit 95b065b

Browse files
jsmattsonjrbonzini
authored andcommitted
KVM: x86/pmu: Use different raw event masks for AMD and Intel
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: 710c476 ("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>
1 parent df06dae commit 95b065b

4 files changed

Lines changed: 5 additions & 1 deletion

File tree

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ struct kvm_pmu {
511511
u64 global_ctrl_mask;
512512
u64 global_ovf_ctrl_mask;
513513
u64 reserved_bits;
514+
u64 raw_event_mask;
514515
u8 version;
515516
struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
516517
struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED];

arch/x86/kvm/pmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
185185
u32 type = PERF_TYPE_RAW;
186186
struct kvm *kvm = pmc->vcpu->kvm;
187187
struct kvm_pmu_event_filter *filter;
188+
struct kvm_pmu *pmu = vcpu_to_pmu(pmc->vcpu);
188189
bool allow_event = true;
189190

190191
if (eventsel & ARCH_PERFMON_EVENTSEL_PIN_CONTROL)
@@ -221,7 +222,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
221222
}
222223

223224
if (type == PERF_TYPE_RAW)
224-
config = eventsel & AMD64_RAW_EVENT_MASK;
225+
config = eventsel & pmu->raw_event_mask;
225226

226227
if (pmc->current_config == eventsel && pmc_resume_counter(pmc))
227228
return;

arch/x86/kvm/svm/pmu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu)
284284

285285
pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1;
286286
pmu->reserved_bits = 0xfffffff000280000ull;
287+
pmu->raw_event_mask = AMD64_RAW_EVENT_MASK;
287288
pmu->version = 1;
288289
/* not applicable to AMD; but clean them to prevent any fall out */
289290
pmu->counter_bitmask[KVM_PMC_FIXED] = 0;

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
485485
pmu->counter_bitmask[KVM_PMC_FIXED] = 0;
486486
pmu->version = 0;
487487
pmu->reserved_bits = 0xffffffff00200000ull;
488+
pmu->raw_event_mask = X86_RAW_EVENT_MASK;
488489

489490
entry = kvm_find_cpuid_entry(vcpu, 0xa, 0);
490491
if (!entry || !vcpu->kvm->arch.enable_pmu)

0 commit comments

Comments
 (0)