Commit 625627e3 authored by Wei Wang's avatar Wei Wang Committed by Yunying Sun
Browse files

KVM: x86: use the KVM side max supported fixed counter

mainline inclusion
from mainline-v5.18-rc1
commit 0144ba0c
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I8WXIM
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0144ba0c5bd3176647bb4d49a697d231610c78b7



-------------------------------------

KVM vPMU doesn't support to emulate all the fixed counters that the
host PMU driver has supported, e.g. the fixed counter 3 used by
Topdown metrics hasn't been supported by KVM so far.

Rename MAX_FIXED_COUNTERS to KVM_PMC_MAX_FIXED to have a more
straightforward naming convention as INTEL_PMC_MAX_FIXED used by the
host PMU driver, and fix vPMU to use the KVM side KVM_PMC_MAX_FIXED
for the virtual fixed counter emulation, instead of the host side
INTEL_PMC_MAX_FIXED.

Intel-SIG: commit 0144ba0c KVM: x86: use the KVM side max supported fixed counter
Backport PEBS format 5 support to kernel v5.10.

Signed-off-by: default avatarWei Wang <wei.w.wang@intel.com>
Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/1643750603-100733-2-git-send-email-kan.liang@linux.intel.com


Signed-off-by: default avatarYunying Sun <yunying.sun@intel.com>
parent 36f313d3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -446,6 +446,7 @@ struct kvm_pmc {
	bool is_paused;
};

#define KVM_PMC_MAX_FIXED	3
struct kvm_pmu {
	unsigned nr_arch_gp_counters;
	unsigned nr_arch_fixed_counters;
@@ -462,7 +463,7 @@ struct kvm_pmu {
	u64 raw_event_mask;
	u8 version;
	struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
	struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED];
	struct kvm_pmc fixed_counters[KVM_PMC_MAX_FIXED];
	struct irq_work irq_work;
	DECLARE_BITMAP(reprogram_pmi, X86_PMC_IDX_MAX);
	DECLARE_BITMAP(all_valid_pmc_idx, X86_PMC_IDX_MAX);
+2 −1
Original line number Diff line number Diff line
@@ -793,7 +793,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
		eax.split.bit_width = cap.bit_width_gp;
		eax.split.mask_length = cap.events_mask_len;

		edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
		edx.split.num_counters_fixed =
			min(cap.num_counters_fixed, KVM_PMC_MAX_FIXED);
		edx.split.bit_width_fixed = cap.bit_width_fixed;
		if (cap.version)
			edx.split.anythread_deprecated = 1;
+0 −2
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
#define VMWARE_BACKDOOR_PMC_REAL_TIME		0x10001
#define VMWARE_BACKDOOR_PMC_APPARENT_TIME	0x10002

#define MAX_FIXED_COUNTERS	3

struct kvm_event_hw_type_mapping {
	u8 eventsel;
	u8 unit_mask;
+2 −2
Original line number Diff line number Diff line
@@ -562,7 +562,7 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu)
		pmu->gp_counters[i].current_config = 0;
	}

	for (i = 0; i < INTEL_PMC_MAX_FIXED; i++) {
	for (i = 0; i < KVM_PMC_MAX_FIXED; i++) {
		pmu->fixed_counters[i].type = KVM_PMC_FIXED;
		pmu->fixed_counters[i].vcpu = vcpu;
		pmu->fixed_counters[i].idx = i + INTEL_PMC_IDX_FIXED;
@@ -588,7 +588,7 @@ static void intel_pmu_reset(struct kvm_vcpu *vcpu)
		pmc->counter = pmc->eventsel = 0;
	}

	for (i = 0; i < INTEL_PMC_MAX_FIXED; i++) {
	for (i = 0; i < KVM_PMC_MAX_FIXED; i++) {
		pmc = &pmu->fixed_counters[i];

		pmc_stop_counter(pmc);
+1 −1
Original line number Diff line number Diff line
@@ -6165,7 +6165,7 @@ static void kvm_init_msr_list(void)
	u32 dummy[2];
	unsigned i;

	BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,
	BUILD_BUG_ON_MSG(KVM_PMC_MAX_FIXED != 3,
			 "Please update the fixed PMCs in msrs_to_saved_all[]");

	perf_get_x86_pmu_capability(&x86_pmu);