Skip to content

Commit a82fe0b

Browse files
jsmattsonjrgregkh
authored andcommitted
KVM: x86/pmu: Use different raw event masks for AMD and Intel
[ Upstream commit 95b065b ] 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 <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 105b50d commit a82fe0b

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ struct kvm_pmu {
505505
u64 global_ctrl_mask;
506506
u64 global_ovf_ctrl_mask;
507507
u64 reserved_bits;
508+
u64 raw_event_mask;
508509
u8 version;
509510
struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
510511
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
@@ -178,6 +178,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
178178
struct kvm *kvm = pmc->vcpu->kvm;
179179
struct kvm_pmu_event_filter *filter;
180180
int i;
181+
struct kvm_pmu *pmu = vcpu_to_pmu(pmc->vcpu);
181182
bool allow_event = true;
182183

183184
if (eventsel & ARCH_PERFMON_EVENTSEL_PIN_CONTROL)
@@ -217,7 +218,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
217218
}
218219

219220
if (type == PERF_TYPE_RAW)
220-
config = eventsel & AMD64_RAW_EVENT_MASK;
221+
config = eventsel & pmu->raw_event_mask;
221222

222223
if (pmc->current_config == eventsel && pmc_resume_counter(pmc))
223224
return;

arch/x86/kvm/svm/pmu.c

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

284284
pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1;
285285
pmu->reserved_bits = 0xfffffff000280000ull;
286+
pmu->raw_event_mask = AMD64_RAW_EVENT_MASK;
286287
pmu->version = 1;
287288
/* not applicable to AMD; but clean them to prevent any fall out */
288289
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
@@ -478,6 +478,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
478478
pmu->counter_bitmask[KVM_PMC_FIXED] = 0;
479479
pmu->version = 0;
480480
pmu->reserved_bits = 0xffffffff00200000ull;
481+
pmu->raw_event_mask = X86_RAW_EVENT_MASK;
481482

482483
entry = kvm_find_cpuid_entry(vcpu, 0xa, 0);
483484
if (!entry)

0 commit comments

Comments
 (0)