Skip to content

Commit 3b65a69

Browse files
committed
KVM: x86/pmu: Add a helper to enable bits in FIXED_CTR_CTRL
Add a helper, intel_pmu_enable_fixed_counter_bits(), to dedup code that enables fixed counter bits, i.e. when KVM clears bits in the reserved mask used to detect invalid MSR_CORE_PERF_FIXED_CTR_CTRL values. No functional change intended. Cc: Dapeng Mi <[email protected]> Reviewed-by: Dapeng Mi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 75430c4 commit 3b65a69

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@ static __always_inline u64 intel_get_fixed_pmc_eventsel(unsigned int index)
448448
return eventsel;
449449
}
450450

451+
static void intel_pmu_enable_fixed_counter_bits(struct kvm_pmu *pmu, u64 bits)
452+
{
453+
int i;
454+
455+
for (i = 0; i < pmu->nr_arch_fixed_counters; i++)
456+
pmu->fixed_ctr_ctrl_rsvd &= ~intel_fixed_bits_by_idx(i, bits);
457+
}
458+
451459
static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
452460
{
453461
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
@@ -457,7 +465,6 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
457465
union cpuid10_edx edx;
458466
u64 perf_capabilities;
459467
u64 counter_rsvd;
460-
int i;
461468

462469
memset(&lbr_desc->records, 0, sizeof(lbr_desc->records));
463470

@@ -501,12 +508,9 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
501508
((u64)1 << edx.split.bit_width_fixed) - 1;
502509
}
503510

504-
for (i = 0; i < pmu->nr_arch_fixed_counters; i++)
505-
pmu->fixed_ctr_ctrl_rsvd &=
506-
~intel_fixed_bits_by_idx(i,
507-
INTEL_FIXED_0_KERNEL |
508-
INTEL_FIXED_0_USER |
509-
INTEL_FIXED_0_ENABLE_PMI);
511+
intel_pmu_enable_fixed_counter_bits(pmu, INTEL_FIXED_0_KERNEL |
512+
INTEL_FIXED_0_USER |
513+
INTEL_FIXED_0_ENABLE_PMI);
510514

511515
counter_rsvd = ~(((1ull << pmu->nr_arch_gp_counters) - 1) |
512516
(((1ull << pmu->nr_arch_fixed_counters) - 1) << KVM_FIXED_PMC_BASE_IDX));
@@ -551,10 +555,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
551555
if (perf_capabilities & PERF_CAP_PEBS_BASELINE) {
552556
pmu->pebs_enable_rsvd = counter_rsvd;
553557
pmu->reserved_bits &= ~ICL_EVENTSEL_ADAPTIVE;
554-
for (i = 0; i < pmu->nr_arch_fixed_counters; i++)
555-
pmu->fixed_ctr_ctrl_rsvd &=
556-
~intel_fixed_bits_by_idx(i, ICL_FIXED_0_ADAPTIVE);
557558
pmu->pebs_data_cfg_rsvd = ~0xff00000full;
559+
intel_pmu_enable_fixed_counter_bits(pmu, ICL_FIXED_0_ADAPTIVE);
558560
} else {
559561
pmu->pebs_enable_rsvd =
560562
~((1ull << pmu->nr_arch_gp_counters) - 1);

0 commit comments

Comments
 (0)