146a010ddSJoerg Roedel // SPDX-License-Identifier: GPL-2.0-only 246a010ddSJoerg Roedel /* 346a010ddSJoerg Roedel * KVM PMU support for AMD 446a010ddSJoerg Roedel * 546a010ddSJoerg Roedel * Copyright 2015, Red Hat, Inc. and/or its affiliates. 646a010ddSJoerg Roedel * 746a010ddSJoerg Roedel * Author: 846a010ddSJoerg Roedel * Wei Huang <wei@redhat.com> 946a010ddSJoerg Roedel * 1046a010ddSJoerg Roedel * Implementation is based on pmu_intel.c file 1146a010ddSJoerg Roedel */ 1246a010ddSJoerg Roedel #include <linux/types.h> 1346a010ddSJoerg Roedel #include <linux/kvm_host.h> 1446a010ddSJoerg Roedel #include <linux/perf_event.h> 1546a010ddSJoerg Roedel #include "x86.h" 1646a010ddSJoerg Roedel #include "cpuid.h" 1746a010ddSJoerg Roedel #include "lapic.h" 1846a010ddSJoerg Roedel #include "pmu.h" 19b1d66dadSLike Xu #include "svm.h" 2046a010ddSJoerg Roedel 2146a010ddSJoerg Roedel enum pmu_type { 2246a010ddSJoerg Roedel PMU_TYPE_COUNTER = 0, 2346a010ddSJoerg Roedel PMU_TYPE_EVNTSEL, 2446a010ddSJoerg Roedel }; 2546a010ddSJoerg Roedel 2646a010ddSJoerg Roedel enum index { 2746a010ddSJoerg Roedel INDEX_ZERO = 0, 2846a010ddSJoerg Roedel INDEX_ONE, 2946a010ddSJoerg Roedel INDEX_TWO, 3046a010ddSJoerg Roedel INDEX_THREE, 3146a010ddSJoerg Roedel INDEX_FOUR, 3246a010ddSJoerg Roedel INDEX_FIVE, 3346a010ddSJoerg Roedel INDEX_ERROR, 3446a010ddSJoerg Roedel }; 3546a010ddSJoerg Roedel 3646a010ddSJoerg Roedel /* duplicated from amd_perfmon_event_map, K7 and above should work. */ 3746a010ddSJoerg Roedel static struct kvm_event_hw_type_mapping amd_event_mapping[] = { 3846a010ddSJoerg Roedel [0] = { 0x76, 0x00, PERF_COUNT_HW_CPU_CYCLES }, 3946a010ddSJoerg Roedel [1] = { 0xc0, 0x00, PERF_COUNT_HW_INSTRUCTIONS }, 4046a010ddSJoerg Roedel [2] = { 0x7d, 0x07, PERF_COUNT_HW_CACHE_REFERENCES }, 4146a010ddSJoerg Roedel [3] = { 0x7e, 0x07, PERF_COUNT_HW_CACHE_MISSES }, 4246a010ddSJoerg Roedel [4] = { 0xc2, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS }, 4346a010ddSJoerg Roedel [5] = { 0xc3, 0x00, PERF_COUNT_HW_BRANCH_MISSES }, 4446a010ddSJoerg Roedel [6] = { 0xd0, 0x00, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND }, 4546a010ddSJoerg Roedel [7] = { 0xd1, 0x00, PERF_COUNT_HW_STALLED_CYCLES_BACKEND }, 4646a010ddSJoerg Roedel }; 4746a010ddSJoerg Roedel 485eb84932SKyle Huey /* duplicated from amd_f17h_perfmon_event_map. */ 495eb84932SKyle Huey static struct kvm_event_hw_type_mapping amd_f17h_event_mapping[] = { 505eb84932SKyle Huey [0] = { 0x76, 0x00, PERF_COUNT_HW_CPU_CYCLES }, 515eb84932SKyle Huey [1] = { 0xc0, 0x00, PERF_COUNT_HW_INSTRUCTIONS }, 525eb84932SKyle Huey [2] = { 0x60, 0xff, PERF_COUNT_HW_CACHE_REFERENCES }, 535eb84932SKyle Huey [3] = { 0x64, 0x09, PERF_COUNT_HW_CACHE_MISSES }, 545eb84932SKyle Huey [4] = { 0xc2, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS }, 555eb84932SKyle Huey [5] = { 0xc3, 0x00, PERF_COUNT_HW_BRANCH_MISSES }, 565eb84932SKyle Huey [6] = { 0x87, 0x02, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND }, 575eb84932SKyle Huey [7] = { 0x87, 0x01, PERF_COUNT_HW_STALLED_CYCLES_BACKEND }, 585eb84932SKyle Huey }; 595eb84932SKyle Huey 605eb84932SKyle Huey /* amd_pmc_perf_hw_id depends on these being the same size */ 615eb84932SKyle Huey static_assert(ARRAY_SIZE(amd_event_mapping) == 625eb84932SKyle Huey ARRAY_SIZE(amd_f17h_event_mapping)); 635eb84932SKyle Huey 6446a010ddSJoerg Roedel static unsigned int get_msr_base(struct kvm_pmu *pmu, enum pmu_type type) 6546a010ddSJoerg Roedel { 6646a010ddSJoerg Roedel struct kvm_vcpu *vcpu = pmu_to_vcpu(pmu); 6746a010ddSJoerg Roedel 6846a010ddSJoerg Roedel if (guest_cpuid_has(vcpu, X86_FEATURE_PERFCTR_CORE)) { 6946a010ddSJoerg Roedel if (type == PMU_TYPE_COUNTER) 7046a010ddSJoerg Roedel return MSR_F15H_PERF_CTR; 7146a010ddSJoerg Roedel else 7246a010ddSJoerg Roedel return MSR_F15H_PERF_CTL; 7346a010ddSJoerg Roedel } else { 7446a010ddSJoerg Roedel if (type == PMU_TYPE_COUNTER) 7546a010ddSJoerg Roedel return MSR_K7_PERFCTR0; 7646a010ddSJoerg Roedel else 7746a010ddSJoerg Roedel return MSR_K7_EVNTSEL0; 7846a010ddSJoerg Roedel } 7946a010ddSJoerg Roedel } 8046a010ddSJoerg Roedel 8146a010ddSJoerg Roedel static enum index msr_to_index(u32 msr) 8246a010ddSJoerg Roedel { 8346a010ddSJoerg Roedel switch (msr) { 8446a010ddSJoerg Roedel case MSR_F15H_PERF_CTL0: 8546a010ddSJoerg Roedel case MSR_F15H_PERF_CTR0: 8646a010ddSJoerg Roedel case MSR_K7_EVNTSEL0: 8746a010ddSJoerg Roedel case MSR_K7_PERFCTR0: 8846a010ddSJoerg Roedel return INDEX_ZERO; 8946a010ddSJoerg Roedel case MSR_F15H_PERF_CTL1: 9046a010ddSJoerg Roedel case MSR_F15H_PERF_CTR1: 9146a010ddSJoerg Roedel case MSR_K7_EVNTSEL1: 9246a010ddSJoerg Roedel case MSR_K7_PERFCTR1: 9346a010ddSJoerg Roedel return INDEX_ONE; 9446a010ddSJoerg Roedel case MSR_F15H_PERF_CTL2: 9546a010ddSJoerg Roedel case MSR_F15H_PERF_CTR2: 9646a010ddSJoerg Roedel case MSR_K7_EVNTSEL2: 9746a010ddSJoerg Roedel case MSR_K7_PERFCTR2: 9846a010ddSJoerg Roedel return INDEX_TWO; 9946a010ddSJoerg Roedel case MSR_F15H_PERF_CTL3: 10046a010ddSJoerg Roedel case MSR_F15H_PERF_CTR3: 10146a010ddSJoerg Roedel case MSR_K7_EVNTSEL3: 10246a010ddSJoerg Roedel case MSR_K7_PERFCTR3: 10346a010ddSJoerg Roedel return INDEX_THREE; 10446a010ddSJoerg Roedel case MSR_F15H_PERF_CTL4: 10546a010ddSJoerg Roedel case MSR_F15H_PERF_CTR4: 10646a010ddSJoerg Roedel return INDEX_FOUR; 10746a010ddSJoerg Roedel case MSR_F15H_PERF_CTL5: 10846a010ddSJoerg Roedel case MSR_F15H_PERF_CTR5: 10946a010ddSJoerg Roedel return INDEX_FIVE; 11046a010ddSJoerg Roedel default: 11146a010ddSJoerg Roedel return INDEX_ERROR; 11246a010ddSJoerg Roedel } 11346a010ddSJoerg Roedel } 11446a010ddSJoerg Roedel 11546a010ddSJoerg Roedel static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr, 11646a010ddSJoerg Roedel enum pmu_type type) 11746a010ddSJoerg Roedel { 1181973caddSVitaly Kuznetsov struct kvm_vcpu *vcpu = pmu_to_vcpu(pmu); 1191973caddSVitaly Kuznetsov 120ba7bb663SDavid Dunn if (!vcpu->kvm->arch.enable_pmu) 121b1d66dadSLike Xu return NULL; 122b1d66dadSLike Xu 12346a010ddSJoerg Roedel switch (msr) { 12446a010ddSJoerg Roedel case MSR_F15H_PERF_CTL0: 12546a010ddSJoerg Roedel case MSR_F15H_PERF_CTL1: 12646a010ddSJoerg Roedel case MSR_F15H_PERF_CTL2: 12746a010ddSJoerg Roedel case MSR_F15H_PERF_CTL3: 12846a010ddSJoerg Roedel case MSR_F15H_PERF_CTL4: 12946a010ddSJoerg Roedel case MSR_F15H_PERF_CTL5: 1301973caddSVitaly Kuznetsov if (!guest_cpuid_has(vcpu, X86_FEATURE_PERFCTR_CORE)) 1311973caddSVitaly Kuznetsov return NULL; 1321973caddSVitaly Kuznetsov fallthrough; 13346a010ddSJoerg Roedel case MSR_K7_EVNTSEL0 ... MSR_K7_EVNTSEL3: 13446a010ddSJoerg Roedel if (type != PMU_TYPE_EVNTSEL) 13546a010ddSJoerg Roedel return NULL; 13646a010ddSJoerg Roedel break; 13746a010ddSJoerg Roedel case MSR_F15H_PERF_CTR0: 13846a010ddSJoerg Roedel case MSR_F15H_PERF_CTR1: 13946a010ddSJoerg Roedel case MSR_F15H_PERF_CTR2: 14046a010ddSJoerg Roedel case MSR_F15H_PERF_CTR3: 14146a010ddSJoerg Roedel case MSR_F15H_PERF_CTR4: 14246a010ddSJoerg Roedel case MSR_F15H_PERF_CTR5: 1431973caddSVitaly Kuznetsov if (!guest_cpuid_has(vcpu, X86_FEATURE_PERFCTR_CORE)) 1441973caddSVitaly Kuznetsov return NULL; 1451973caddSVitaly Kuznetsov fallthrough; 14646a010ddSJoerg Roedel case MSR_K7_PERFCTR0 ... MSR_K7_PERFCTR3: 14746a010ddSJoerg Roedel if (type != PMU_TYPE_COUNTER) 14846a010ddSJoerg Roedel return NULL; 14946a010ddSJoerg Roedel break; 15046a010ddSJoerg Roedel default: 15146a010ddSJoerg Roedel return NULL; 15246a010ddSJoerg Roedel } 15346a010ddSJoerg Roedel 15446a010ddSJoerg Roedel return &pmu->gp_counters[msr_to_index(msr)]; 15546a010ddSJoerg Roedel } 15646a010ddSJoerg Roedel 1577c174f30SLike Xu static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc) 15846a010ddSJoerg Roedel { 1595eb84932SKyle Huey struct kvm_event_hw_type_mapping *event_mapping; 1607c174f30SLike Xu u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT; 1617c174f30SLike Xu u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8; 16246a010ddSJoerg Roedel int i; 16346a010ddSJoerg Roedel 1646ed1298eSLike Xu /* return PERF_COUNT_HW_MAX as AMD doesn't have fixed events */ 1656ed1298eSLike Xu if (WARN_ON(pmc_is_fixed(pmc))) 1666ed1298eSLike Xu return PERF_COUNT_HW_MAX; 1676ed1298eSLike Xu 1685eb84932SKyle Huey if (guest_cpuid_family(pmc->vcpu) >= 0x17) 1695eb84932SKyle Huey event_mapping = amd_f17h_event_mapping; 1705eb84932SKyle Huey else 1715eb84932SKyle Huey event_mapping = amd_event_mapping; 1725eb84932SKyle Huey 17346a010ddSJoerg Roedel for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++) 1745eb84932SKyle Huey if (event_mapping[i].eventsel == event_select 1755eb84932SKyle Huey && event_mapping[i].unit_mask == unit_mask) 17646a010ddSJoerg Roedel break; 17746a010ddSJoerg Roedel 17846a010ddSJoerg Roedel if (i == ARRAY_SIZE(amd_event_mapping)) 17946a010ddSJoerg Roedel return PERF_COUNT_HW_MAX; 18046a010ddSJoerg Roedel 1815eb84932SKyle Huey return event_mapping[i].event_type; 18246a010ddSJoerg Roedel } 18346a010ddSJoerg Roedel 18446a010ddSJoerg Roedel /* check if a PMC is enabled by comparing it against global_ctrl bits. Because 18546a010ddSJoerg Roedel * AMD CPU doesn't have global_ctrl MSR, all PMCs are enabled (return TRUE). 18646a010ddSJoerg Roedel */ 18746a010ddSJoerg Roedel static bool amd_pmc_is_enabled(struct kvm_pmc *pmc) 18846a010ddSJoerg Roedel { 18946a010ddSJoerg Roedel return true; 19046a010ddSJoerg Roedel } 19146a010ddSJoerg Roedel 19246a010ddSJoerg Roedel static struct kvm_pmc *amd_pmc_idx_to_pmc(struct kvm_pmu *pmu, int pmc_idx) 19346a010ddSJoerg Roedel { 19446a010ddSJoerg Roedel unsigned int base = get_msr_base(pmu, PMU_TYPE_COUNTER); 19546a010ddSJoerg Roedel struct kvm_vcpu *vcpu = pmu_to_vcpu(pmu); 19646a010ddSJoerg Roedel 19746a010ddSJoerg Roedel if (guest_cpuid_has(vcpu, X86_FEATURE_PERFCTR_CORE)) { 19846a010ddSJoerg Roedel /* 19946a010ddSJoerg Roedel * The idx is contiguous. The MSRs are not. The counter MSRs 20046a010ddSJoerg Roedel * are interleaved with the event select MSRs. 20146a010ddSJoerg Roedel */ 20246a010ddSJoerg Roedel pmc_idx *= 2; 20346a010ddSJoerg Roedel } 20446a010ddSJoerg Roedel 20546a010ddSJoerg Roedel return get_gp_pmc_amd(pmu, base + pmc_idx, PMU_TYPE_COUNTER); 20646a010ddSJoerg Roedel } 20746a010ddSJoerg Roedel 208e6cd31f1SJim Mattson static bool amd_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 20946a010ddSJoerg Roedel { 21046a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 21146a010ddSJoerg Roedel 21246a010ddSJoerg Roedel idx &= ~(3u << 30); 21346a010ddSJoerg Roedel 214e6cd31f1SJim Mattson return idx < pmu->nr_arch_gp_counters; 21546a010ddSJoerg Roedel } 21646a010ddSJoerg Roedel 21746a010ddSJoerg Roedel /* idx is the ECX register of RDPMC instruction */ 21846a010ddSJoerg Roedel static struct kvm_pmc *amd_rdpmc_ecx_to_pmc(struct kvm_vcpu *vcpu, 21946a010ddSJoerg Roedel unsigned int idx, u64 *mask) 22046a010ddSJoerg Roedel { 22146a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 22246a010ddSJoerg Roedel struct kvm_pmc *counters; 22346a010ddSJoerg Roedel 22446a010ddSJoerg Roedel idx &= ~(3u << 30); 22546a010ddSJoerg Roedel if (idx >= pmu->nr_arch_gp_counters) 22646a010ddSJoerg Roedel return NULL; 22746a010ddSJoerg Roedel counters = pmu->gp_counters; 22846a010ddSJoerg Roedel 22946a010ddSJoerg Roedel return &counters[idx]; 23046a010ddSJoerg Roedel } 23146a010ddSJoerg Roedel 232d1c88a40SPaolo Bonzini static bool amd_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr, bool host_initiated) 23346a010ddSJoerg Roedel { 23446a010ddSJoerg Roedel /* All MSRs refer to exactly one PMC, so msr_idx_to_pmc is enough. */ 23546a010ddSJoerg Roedel return false; 23646a010ddSJoerg Roedel } 23746a010ddSJoerg Roedel 23846a010ddSJoerg Roedel static struct kvm_pmc *amd_msr_idx_to_pmc(struct kvm_vcpu *vcpu, u32 msr) 23946a010ddSJoerg Roedel { 24046a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 24146a010ddSJoerg Roedel struct kvm_pmc *pmc; 24246a010ddSJoerg Roedel 24346a010ddSJoerg Roedel pmc = get_gp_pmc_amd(pmu, msr, PMU_TYPE_COUNTER); 24446a010ddSJoerg Roedel pmc = pmc ? pmc : get_gp_pmc_amd(pmu, msr, PMU_TYPE_EVNTSEL); 24546a010ddSJoerg Roedel 24646a010ddSJoerg Roedel return pmc; 24746a010ddSJoerg Roedel } 24846a010ddSJoerg Roedel 249cbd71758SWei Wang static int amd_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) 25046a010ddSJoerg Roedel { 25146a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 25246a010ddSJoerg Roedel struct kvm_pmc *pmc; 253cbd71758SWei Wang u32 msr = msr_info->index; 25446a010ddSJoerg Roedel 25546a010ddSJoerg Roedel /* MSR_PERFCTRn */ 25646a010ddSJoerg Roedel pmc = get_gp_pmc_amd(pmu, msr, PMU_TYPE_COUNTER); 25746a010ddSJoerg Roedel if (pmc) { 258cbd71758SWei Wang msr_info->data = pmc_read_counter(pmc); 25946a010ddSJoerg Roedel return 0; 26046a010ddSJoerg Roedel } 26146a010ddSJoerg Roedel /* MSR_EVNTSELn */ 26246a010ddSJoerg Roedel pmc = get_gp_pmc_amd(pmu, msr, PMU_TYPE_EVNTSEL); 26346a010ddSJoerg Roedel if (pmc) { 264cbd71758SWei Wang msr_info->data = pmc->eventsel; 26546a010ddSJoerg Roedel return 0; 26646a010ddSJoerg Roedel } 26746a010ddSJoerg Roedel 26846a010ddSJoerg Roedel return 1; 26946a010ddSJoerg Roedel } 27046a010ddSJoerg Roedel 27146a010ddSJoerg Roedel static int amd_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) 27246a010ddSJoerg Roedel { 27346a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 27446a010ddSJoerg Roedel struct kvm_pmc *pmc; 27546a010ddSJoerg Roedel u32 msr = msr_info->index; 27646a010ddSJoerg Roedel u64 data = msr_info->data; 27746a010ddSJoerg Roedel 27846a010ddSJoerg Roedel /* MSR_PERFCTRn */ 27946a010ddSJoerg Roedel pmc = get_gp_pmc_amd(pmu, msr, PMU_TYPE_COUNTER); 28046a010ddSJoerg Roedel if (pmc) { 28146a010ddSJoerg Roedel pmc->counter += data - pmc_read_counter(pmc); 28275189d1dSLike Xu pmc_update_sample_period(pmc); 28346a010ddSJoerg Roedel return 0; 28446a010ddSJoerg Roedel } 28546a010ddSJoerg Roedel /* MSR_EVNTSELn */ 28646a010ddSJoerg Roedel pmc = get_gp_pmc_amd(pmu, msr, PMU_TYPE_EVNTSEL); 28746a010ddSJoerg Roedel if (pmc) { 2889b026073SJim Mattson data &= ~pmu->reserved_bits; 289fb121aafSLike Xu if (data != pmc->eventsel) { 290fb121aafSLike Xu pmc->eventsel = data; 291*e99fae6eSPaolo Bonzini reprogram_counter(pmc); 292fb121aafSLike Xu } 29346a010ddSJoerg Roedel return 0; 29446a010ddSJoerg Roedel } 29546a010ddSJoerg Roedel 29646a010ddSJoerg Roedel return 1; 29746a010ddSJoerg Roedel } 29846a010ddSJoerg Roedel 29946a010ddSJoerg Roedel static void amd_pmu_refresh(struct kvm_vcpu *vcpu) 30046a010ddSJoerg Roedel { 30146a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 30246a010ddSJoerg Roedel 30346a010ddSJoerg Roedel if (guest_cpuid_has(vcpu, X86_FEATURE_PERFCTR_CORE)) 30446a010ddSJoerg Roedel pmu->nr_arch_gp_counters = AMD64_NUM_COUNTERS_CORE; 30546a010ddSJoerg Roedel else 30646a010ddSJoerg Roedel pmu->nr_arch_gp_counters = AMD64_NUM_COUNTERS; 30746a010ddSJoerg Roedel 30846a010ddSJoerg Roedel pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1; 309cb1d220dSLike Xu pmu->reserved_bits = 0xfffffff000280000ull; 31095b065bfSJim Mattson pmu->raw_event_mask = AMD64_RAW_EVENT_MASK; 31146a010ddSJoerg Roedel pmu->version = 1; 31246a010ddSJoerg Roedel /* not applicable to AMD; but clean them to prevent any fall out */ 31346a010ddSJoerg Roedel pmu->counter_bitmask[KVM_PMC_FIXED] = 0; 31446a010ddSJoerg Roedel pmu->nr_arch_fixed_counters = 0; 31546a010ddSJoerg Roedel pmu->global_status = 0; 31646a010ddSJoerg Roedel bitmap_set(pmu->all_valid_pmc_idx, 0, pmu->nr_arch_gp_counters); 31746a010ddSJoerg Roedel } 31846a010ddSJoerg Roedel 31946a010ddSJoerg Roedel static void amd_pmu_init(struct kvm_vcpu *vcpu) 32046a010ddSJoerg Roedel { 32146a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 32246a010ddSJoerg Roedel int i; 32346a010ddSJoerg Roedel 32446a010ddSJoerg Roedel BUILD_BUG_ON(AMD64_NUM_COUNTERS_CORE > INTEL_PMC_MAX_GENERIC); 32546a010ddSJoerg Roedel 32646a010ddSJoerg Roedel for (i = 0; i < AMD64_NUM_COUNTERS_CORE ; i++) { 32746a010ddSJoerg Roedel pmu->gp_counters[i].type = KVM_PMC_GP; 32846a010ddSJoerg Roedel pmu->gp_counters[i].vcpu = vcpu; 32946a010ddSJoerg Roedel pmu->gp_counters[i].idx = i; 33046a010ddSJoerg Roedel pmu->gp_counters[i].current_config = 0; 33146a010ddSJoerg Roedel } 33246a010ddSJoerg Roedel } 33346a010ddSJoerg Roedel 33446a010ddSJoerg Roedel static void amd_pmu_reset(struct kvm_vcpu *vcpu) 33546a010ddSJoerg Roedel { 33646a010ddSJoerg Roedel struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 33746a010ddSJoerg Roedel int i; 33846a010ddSJoerg Roedel 33946a010ddSJoerg Roedel for (i = 0; i < AMD64_NUM_COUNTERS_CORE; i++) { 34046a010ddSJoerg Roedel struct kvm_pmc *pmc = &pmu->gp_counters[i]; 34146a010ddSJoerg Roedel 34246a010ddSJoerg Roedel pmc_stop_counter(pmc); 34346a010ddSJoerg Roedel pmc->counter = pmc->eventsel = 0; 34446a010ddSJoerg Roedel } 34546a010ddSJoerg Roedel } 34646a010ddSJoerg Roedel 34734886e79SLike Xu struct kvm_pmu_ops amd_pmu_ops __initdata = { 3487c174f30SLike Xu .pmc_perf_hw_id = amd_pmc_perf_hw_id, 34946a010ddSJoerg Roedel .pmc_is_enabled = amd_pmc_is_enabled, 35046a010ddSJoerg Roedel .pmc_idx_to_pmc = amd_pmc_idx_to_pmc, 35146a010ddSJoerg Roedel .rdpmc_ecx_to_pmc = amd_rdpmc_ecx_to_pmc, 35246a010ddSJoerg Roedel .msr_idx_to_pmc = amd_msr_idx_to_pmc, 35346a010ddSJoerg Roedel .is_valid_rdpmc_ecx = amd_is_valid_rdpmc_ecx, 35446a010ddSJoerg Roedel .is_valid_msr = amd_is_valid_msr, 35546a010ddSJoerg Roedel .get_msr = amd_pmu_get_msr, 35646a010ddSJoerg Roedel .set_msr = amd_pmu_set_msr, 35746a010ddSJoerg Roedel .refresh = amd_pmu_refresh, 35846a010ddSJoerg Roedel .init = amd_pmu_init, 35946a010ddSJoerg Roedel .reset = amd_pmu_reset, 36046a010ddSJoerg Roedel }; 361