Skip to content

Commit aa570a7

Browse files
suomilewissean-jc
authored andcommitted
kvm: x86/pmu: Correct the mask used in a pmu event filter lookup
When checking if a pmu event the guest is attempting to program should be filtered, only consider the event select + unit mask in that decision. Use an architecture specific mask to mask out all other bits, including bits 35:32 on Intel. Those bits are not part of the event select and should not be considered in that decision. Fixes: 66bb8a0 ("KVM: x86: PMU Event Filter") Signed-off-by: Aaron Lewis <aaronlewis@google.com> Link: https://lore.kernel.org/r/20221220161236.555143-2-aaronlewis@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent de60733 commit aa570a7

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

arch/x86/kvm/pmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ static bool check_pmu_event_filter(struct kvm_pmc *pmc)
279279
goto out;
280280

281281
if (pmc_is_gp(pmc)) {
282-
key = pmc->eventsel & AMD64_RAW_EVENT_MASK_NB;
282+
key = pmc->eventsel & (kvm_pmu_ops.EVENTSEL_EVENT |
283+
ARCH_PERFMON_EVENTSEL_UMASK);
283284
if (bsearch(&key, filter->events, filter->nevents,
284285
sizeof(__u64), cmp_u64))
285286
allow_event = filter->action == KVM_PMU_EVENT_ALLOW;

arch/x86/kvm/pmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct kvm_pmu_ops {
4040
void (*reset)(struct kvm_vcpu *vcpu);
4141
void (*deliver_pmi)(struct kvm_vcpu *vcpu);
4242
void (*cleanup)(struct kvm_vcpu *vcpu);
43+
44+
const u64 EVENTSEL_EVENT;
4345
};
4446

4547
void kvm_pmu_ops_update(const struct kvm_pmu_ops *pmu_ops);

arch/x86/kvm/svm/pmu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,5 @@ struct kvm_pmu_ops amd_pmu_ops __initdata = {
231231
.refresh = amd_pmu_refresh,
232232
.init = amd_pmu_init,
233233
.reset = amd_pmu_reset,
234+
.EVENTSEL_EVENT = AMD64_EVENTSEL_EVENT,
234235
};

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,5 @@ struct kvm_pmu_ops intel_pmu_ops __initdata = {
811811
.reset = intel_pmu_reset,
812812
.deliver_pmi = intel_pmu_deliver_pmi,
813813
.cleanup = intel_pmu_cleanup,
814+
.EVENTSEL_EVENT = ARCH_PERFMON_EVENTSEL_EVENT,
814815
};

0 commit comments

Comments
 (0)