Lines Matching +full:guest +full:- +full:index +full:- +full:bits

1 /* SPDX-License-Identifier: GPL-2.0 */
9 #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu)
11 #define pmc_to_pmu(pmc) (&(pmc)->vcpu->arch.pmu)
16 /* retrieve the 4 bits for EN and PMI out of IA32_FIXED_CTR_CTRL */
58 * to/for the guest if the guest PMU supports at least "Architectural in kvm_pmu_has_perf_global_ctrl()
63 return pmu->version > 1; in kvm_pmu_has_perf_global_ctrl()
67 * KVM tracks all counters in 64-bit bitmaps, with general purpose counters
68 * mapped to bits 31:0 and fixed counters mapped to 63:32, e.g. fixed counter 0
69 * is tracked internally via index 32. On Intel, (AMD doesn't support fixed
71 * and similar MSRs, i.e. tracking fixed counters at base index 32 reduces the
76 * NOT safe for guest lookups, e.g. will do the wrong thing if passed a raw
78 * for RDPMC, not by adding 32 to the fixed counter index).
82 if (idx < pmu->nr_arch_gp_counters) in kvm_pmc_idx_to_pmc()
83 return &pmu->gp_counters[idx]; in kvm_pmc_idx_to_pmc()
85 idx -= KVM_FIXED_PMC_BASE_IDX; in kvm_pmc_idx_to_pmc()
86 if (idx >= 0 && idx < pmu->nr_arch_fixed_counters) in kvm_pmc_idx_to_pmc()
87 return &pmu->fixed_counters[idx]; in kvm_pmc_idx_to_pmc()
102 return pmu->counter_bitmask[pmc->type]; in pmc_bitmask()
109 counter = pmc->counter + pmc->emulated_counter; in pmc_read_counter()
111 if (pmc->perf_event && !pmc->is_paused) in pmc_read_counter()
112 counter += perf_event_read_value(pmc->perf_event, in pmc_read_counter()
122 return pmc->type == KVM_PMC_GP; in pmc_is_gp()
127 return pmc->type == KVM_PMC_FIXED; in pmc_is_fixed()
133 return !(pmu->global_ctrl_rsvd & data); in kvm_valid_perf_global_ctrl()
143 if (msr >= base && msr < base + pmu->nr_arch_gp_counters) { in get_gp_pmc()
144 u32 index = array_index_nospec(msr - base, in get_gp_pmc() local
145 pmu->nr_arch_gp_counters); in get_gp_pmc()
147 return &pmu->gp_counters[index]; in get_gp_pmc()
158 if (msr >= base && msr < base + pmu->nr_arch_fixed_counters) { in get_fixed_pmc()
159 u32 index = array_index_nospec(msr - base, in get_fixed_pmc() local
160 pmu->nr_arch_fixed_counters); in get_fixed_pmc()
162 return &pmu->fixed_counters[index]; in get_fixed_pmc()
173 return fixed_ctrl_field(pmu->fixed_ctr_ctrl, in pmc_speculative_in_use()
174 pmc->idx - KVM_FIXED_PMC_BASE_IDX) & in pmc_speculative_in_use()
177 return pmc->eventsel & ARCH_PERFMON_EVENTSEL_ENABLE; in pmc_speculative_in_use()
186 int min_nr_gp_ctrs = pmu_ops->MIN_NR_GP_COUNTERS; in kvm_init_pmu_capability()
192 * for hybrid PMUs until KVM gains a way to let userspace opt-in. in kvm_init_pmu_capability()
203 * there are a non-zero number of counters, but fewer than what in kvm_init_pmu_capability()
220 pmu_ops->MAX_NR_GP_COUNTERS); in kvm_init_pmu_capability()
232 set_bit(pmc->idx, pmc_to_pmu(pmc)->reprogram_pmi); in kvm_pmu_request_counter_reprogram()
233 kvm_make_request(KVM_REQ_PMU, pmc->vcpu); in kvm_pmu_request_counter_reprogram()
244 set_bit(bit, pmu->reprogram_pmi); in reprogram_counters()
249 * Check if a PMC is enabled by comparing it against global_ctrl bits.
260 return test_bit(pmc->idx, (unsigned long *)&pmu->global_ctrl); in pmc_is_globally_enabled()