From: Sandipan Das <sandipan.das@xxxxxxx> Implement the AMD-specific callback for passthrough PMU that increments counters for cases such as instruction emulation. A PMI will also be injected if the increment results in an overflow. Signed-off-by: Sandipan Das <sandipan.das@xxxxxxx> Signed-off-by: Mingwei Zhang <mizhang@xxxxxxxxxx> --- arch/x86/kvm/svm/pmu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c index 9f3e910ee453..70465903ef1e 100644 --- a/arch/x86/kvm/svm/pmu.c +++ b/arch/x86/kvm/svm/pmu.c @@ -346,6 +346,17 @@ static void amd_restore_pmu_context(struct kvm_vcpu *vcpu) wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_CTL, pmu->global_ctrl); } +static bool amd_incr_counter(struct kvm_pmc *pmc) +{ + pmc->counter += 1; + pmc->counter &= pmc_bitmask(pmc); + + if (!pmc->counter) + return true; + + return false; +} + struct kvm_pmu_ops amd_pmu_ops __initdata = { .rdpmc_ecx_to_pmc = amd_rdpmc_ecx_to_pmc, .msr_idx_to_pmc = amd_msr_idx_to_pmc, @@ -359,6 +370,7 @@ struct kvm_pmu_ops amd_pmu_ops __initdata = { .passthrough_pmu_msrs = amd_passthrough_pmu_msrs, .save_pmu_context = amd_save_pmu_context, .restore_pmu_context = amd_restore_pmu_context, + .incr_counter = amd_incr_counter, .EVENTSEL_EVENT = AMD64_EVENTSEL_EVENT, .MAX_NR_GP_COUNTERS = KVM_AMD_PMC_MAX_GENERIC, .MIN_NR_GP_COUNTERS = AMD64_NUM_COUNTERS, -- 2.46.0.rc1.232.g9752f9e123-goog