Skip to content

Commit 1c2bf8a

Browse files
Like Xusean-jc
authored andcommitted
KVM: x86/pmu: Constrain the num of guest counters with kvm_pmu_cap
Cap the number of general purpose counters enumerated on AMD to what KVM actually supports, i.e. don't allow userspace to coerce KVM into thinking there are more counters than actually exist, e.g. by enumerating X86_FEATURE_PERFCTR_CORE in guest CPUID when its not supported. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Like Xu <likexu@tencent.com> [sean: massage changelog] Link: https://lore.kernel.org/r/20230603011058.1038821-10-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent d338d87 commit 1c2bf8a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

arch/x86/kvm/svm/pmu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu)
170170
else
171171
pmu->nr_arch_gp_counters = AMD64_NUM_COUNTERS;
172172

173+
pmu->nr_arch_gp_counters = min_t(unsigned int, pmu->nr_arch_gp_counters,
174+
kvm_pmu_cap.num_counters_gp);
175+
173176
pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1;
174177
pmu->reserved_bits = 0xfffffff000280000ull;
175178
pmu->raw_event_mask = AMD64_RAW_EVENT_MASK;

0 commit comments

Comments
 (0)