Skip to content

Commit 13afa29

Browse files
Like Xusean-jc
authored andcommitted
KVM: x86/pmu: Provide Intel PMU's pmc_is_enabled() as generic x86 code
Move the Intel PMU implementation of pmc_is_enabled() to common x86 code as pmc_is_globally_enabled(), and drop AMD's implementation. AMD PMU currently supports only v1, and thus not PERF_GLOBAL_CONTROL, thus the semantics for AMD are unchanged. And when support for AMD PMU v2 comes along, the common behavior will also Just Work. Signed-off-by: Like Xu <likexu@tencent.com> Co-developed-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20230603011058.1038821-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c85cdc1 commit 13afa29

5 files changed

Lines changed: 16 additions & 29 deletions

File tree

arch/x86/include/asm/kvm-x86-pmu-ops.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ BUILD_BUG_ON(1)
1313
* at the call sites.
1414
*/
1515
KVM_X86_PMU_OP(hw_event_available)
16-
KVM_X86_PMU_OP(pmc_is_enabled)
1716
KVM_X86_PMU_OP(pmc_idx_to_pmc)
1817
KVM_X86_PMU_OP(rdpmc_ecx_to_pmc)
1918
KVM_X86_PMU_OP(msr_idx_to_pmc)

arch/x86/kvm/pmu.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ void kvm_pmu_ops_update(const struct kvm_pmu_ops *pmu_ops)
9393
#undef __KVM_X86_PMU_OP
9494
}
9595

96-
static inline bool pmc_is_globally_enabled(struct kvm_pmc *pmc)
97-
{
98-
return static_call(kvm_x86_pmu_pmc_is_enabled)(pmc);
99-
}
100-
10196
static void kvm_pmi_trigger_fn(struct irq_work *irq_work)
10297
{
10398
struct kvm_pmu *pmu = container_of(irq_work, struct kvm_pmu, irq_work);

arch/x86/kvm/pmu.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
struct kvm_pmu_ops {
2222
bool (*hw_event_available)(struct kvm_pmc *pmc);
23-
bool (*pmc_is_enabled)(struct kvm_pmc *pmc);
2423
struct kvm_pmc *(*pmc_idx_to_pmc)(struct kvm_pmu *pmu, int pmc_idx);
2524
struct kvm_pmc *(*rdpmc_ecx_to_pmc)(struct kvm_vcpu *vcpu,
2625
unsigned int idx, u64 *mask);
@@ -227,6 +226,21 @@ static inline void reprogram_counters(struct kvm_pmu *pmu, u64 diff)
227226
kvm_make_request(KVM_REQ_PMU, pmu_to_vcpu(pmu));
228227
}
229228

229+
/*
230+
* Check if a PMC is enabled by comparing it against global_ctrl bits.
231+
*
232+
* If the vPMU doesn't have global_ctrl MSR, all vPMCs are enabled.
233+
*/
234+
static inline bool pmc_is_globally_enabled(struct kvm_pmc *pmc)
235+
{
236+
struct kvm_pmu *pmu = pmc_to_pmu(pmc);
237+
238+
if (!kvm_pmu_has_perf_global_ctrl(pmu))
239+
return true;
240+
241+
return test_bit(pmc->idx, (unsigned long *)&pmu->global_ctrl);
242+
}
243+
230244
void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu);
231245
void kvm_pmu_handle_event(struct kvm_vcpu *vcpu);
232246
int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);

arch/x86/kvm/svm/pmu.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ static bool amd_hw_event_available(struct kvm_pmc *pmc)
7878
return true;
7979
}
8080

81-
/* check if a PMC is enabled by comparing it against global_ctrl bits. Because
82-
* AMD CPU doesn't have global_ctrl MSR, all PMCs are enabled (return TRUE).
83-
*/
84-
static bool amd_pmc_is_enabled(struct kvm_pmc *pmc)
85-
{
86-
return true;
87-
}
88-
8981
static bool amd_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx)
9082
{
9183
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
@@ -220,7 +212,6 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu)
220212

221213
struct kvm_pmu_ops amd_pmu_ops __initdata = {
222214
.hw_event_available = amd_hw_event_available,
223-
.pmc_is_enabled = amd_pmc_is_enabled,
224215
.pmc_idx_to_pmc = amd_pmc_idx_to_pmc,
225216
.rdpmc_ecx_to_pmc = amd_rdpmc_ecx_to_pmc,
226217
.msr_idx_to_pmc = amd_msr_idx_to_pmc,

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,6 @@ static bool intel_hw_event_available(struct kvm_pmc *pmc)
9595
return true;
9696
}
9797

98-
/* check if a PMC is enabled by comparing it with globl_ctrl bits. */
99-
static bool intel_pmc_is_enabled(struct kvm_pmc *pmc)
100-
{
101-
struct kvm_pmu *pmu = pmc_to_pmu(pmc);
102-
103-
if (!kvm_pmu_has_perf_global_ctrl(pmu))
104-
return true;
105-
106-
return test_bit(pmc->idx, (unsigned long *)&pmu->global_ctrl);
107-
}
108-
10998
static bool intel_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx)
11099
{
111100
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
@@ -759,7 +748,7 @@ void intel_pmu_cross_mapped_check(struct kvm_pmu *pmu)
759748
pmc = intel_pmc_idx_to_pmc(pmu, bit);
760749

761750
if (!pmc || !pmc_speculative_in_use(pmc) ||
762-
!intel_pmc_is_enabled(pmc) || !pmc->perf_event)
751+
!pmc_is_globally_enabled(pmc) || !pmc->perf_event)
763752
continue;
764753

765754
/*
@@ -774,7 +763,6 @@ void intel_pmu_cross_mapped_check(struct kvm_pmu *pmu)
774763

775764
struct kvm_pmu_ops intel_pmu_ops __initdata = {
776765
.hw_event_available = intel_hw_event_available,
777-
.pmc_is_enabled = intel_pmc_is_enabled,
778766
.pmc_idx_to_pmc = intel_pmc_idx_to_pmc,
779767
.rdpmc_ecx_to_pmc = intel_rdpmc_ecx_to_pmc,
780768
.msr_idx_to_pmc = intel_msr_idx_to_pmc,

0 commit comments

Comments
 (0)