Skip to content

Commit e1fba49

Browse files
jsmattsonjrbonzini
authored andcommitted
kvm: vmx: Limit guest PMCs to those supported on the host
KVM can only virtualize as many PMCs as the host supports. Limit the number of generic counters and fixed counters to the number of corresponding counters supported on the host, rather than to INTEL_PMC_MAX_GENERIC and INTEL_PMC_MAX_FIXED, respectively. Note that INTEL_PMC_MAX_GENERIC is currently 32, which exceeds the 18 contiguous MSR indices reserved by Intel for event selectors. Since the existing code relies on a contiguous range of MSR indices for event selectors, it can't possibly work for more than 18 general purpose counters. Fixes: f5132b0 ("KVM: Expose a version 2 architectural PMU to a guests") Signed-off-by: Jim Mattson <[email protected]> Reviewed-by: Marc Orr <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 833b45d commit e1fba49

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
262262
static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
263263
{
264264
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
265+
struct x86_pmu_capability x86_pmu;
265266
struct kvm_cpuid_entry2 *entry;
266267
union cpuid10_eax eax;
267268
union cpuid10_edx edx;
@@ -283,8 +284,10 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
283284
if (!pmu->version)
284285
return;
285286

287+
perf_get_x86_pmu_capability(&x86_pmu);
288+
286289
pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters,
287-
INTEL_PMC_MAX_GENERIC);
290+
x86_pmu.num_counters_gp);
288291
pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1;
289292
pmu->available_event_types = ~entry->ebx &
290293
((1ull << eax.split.mask_length) - 1);
@@ -294,7 +297,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
294297
} else {
295298
pmu->nr_arch_fixed_counters =
296299
min_t(int, edx.split.num_counters_fixed,
297-
INTEL_PMC_MAX_FIXED);
300+
x86_pmu.num_counters_fixed);
298301
pmu->counter_bitmask[KVM_PMC_FIXED] =
299302
((u64)1 << edx.split.bit_width_fixed) - 1;
300303
}

0 commit comments

Comments
 (0)