From: Manali Shukla <manali.shukla@xxxxxxx> With the Passthrough PMU enabled, the PERF_CTLx MSRs (event selectors) are always intercepted and the event filter checking can be directly done inside amd_pmu_set_msr(). Add a check to allow writing to event selector for GP counters if and only if the event is allowed in filter. Signed-off-by: Manali Shukla <manali.shukla@xxxxxxx> --- arch/x86/kvm/svm/pmu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c index 9629a172aa1b..cb6d3bfdd588 100644 --- a/arch/x86/kvm/svm/pmu.c +++ b/arch/x86/kvm/svm/pmu.c @@ -166,6 +166,15 @@ static int amd_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (data != pmc->eventsel) { pmc->eventsel = data; if (is_passthrough_pmu_enabled(vcpu)) { + if (!check_pmu_event_filter(pmc)) { + /* + * When guest request an invalid event, + * stop the counter by clearing the + * event selector MSR. + */ + pmc->eventsel_hw = 0; + return 0; + } data &= ~AMD64_EVENTSEL_HOSTONLY; pmc->eventsel_hw = data | AMD64_EVENTSEL_GUESTONLY; } else { -- 2.45.0.rc1.225.g2a3ae87e7f-goog