Skip to content

Commit 41aac14

Browse files
Wei Huangbonzini
authored andcommitted
KVM: x86/vPMU: introduce kvm_pmu_msr_idx_to_pmc
This function will be part of the kvm_pmu_ops interface. Introduce it already. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e5af058 commit 41aac14

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

arch/x86/kvm/pmu.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,34 @@ int kvm_pmu_is_valid_msr_idx(struct kvm_vcpu *vcpu, unsigned idx)
348348
(fixed && idx >= pmu->nr_arch_fixed_counters);
349349
}
350350

351-
int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
351+
static struct kvm_pmc *kvm_pmu_msr_idx_to_pmc(struct kvm_vcpu *vcpu,
352+
unsigned idx)
352353
{
353354
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
354-
bool fast_mode = idx & (1u << 31);
355355
bool fixed = idx & (1u << 30);
356356
struct kvm_pmc *counters;
357-
u64 ctr_val;
358357

359358
idx &= ~(3u << 30);
360359
if (!fixed && idx >= pmu->nr_arch_gp_counters)
361-
return 1;
360+
return NULL;
362361
if (fixed && idx >= pmu->nr_arch_fixed_counters)
363-
return 1;
362+
return NULL;
364363
counters = fixed ? pmu->fixed_counters : pmu->gp_counters;
365364

366-
ctr_val = pmc_read_counter(&counters[idx]);
365+
return &counters[idx];
366+
}
367+
368+
int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
369+
{
370+
bool fast_mode = idx & (1u << 31);
371+
struct kvm_pmc *pmc;
372+
u64 ctr_val;
373+
374+
pmc = kvm_pmu_msr_idx_to_pmc(vcpu, idx);
375+
if (!pmc)
376+
return 1;
377+
378+
ctr_val = pmc_read_counter(pmc);
367379
if (fast_mode)
368380
ctr_val = (u32)ctr_val;
369381

0 commit comments

Comments
 (0)