summaryrefslogtreecommitdiff
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorWei Huang <wehuang@redhat.com>2015-06-19 16:16:59 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2015-06-23 14:12:11 +0200
commit41aac14a8dee66a720894e5979c2372c0d5afd34 (patch)
treea62e5a91c7c14dfa1af95d8f7c733ae7c34c5b80 /arch/x86/kvm
parente5af058aacd55e578b3c57b1582b90c4290b77f9 (diff)
downloadlwn-41aac14a8dee66a720894e5979c2372c0d5afd34.tar.gz
lwn-41aac14a8dee66a720894e5979c2372c0d5afd34.zip
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 <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/pmu.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index f38ad84be87e..bd5dbd9ce0e3 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -348,22 +348,34 @@ int kvm_pmu_is_valid_msr_idx(struct kvm_vcpu *vcpu, unsigned idx)
(fixed && idx >= pmu->nr_arch_fixed_counters);
}
-int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
+static struct kvm_pmc *kvm_pmu_msr_idx_to_pmc(struct kvm_vcpu *vcpu,
+ unsigned idx)
{
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
- bool fast_mode = idx & (1u << 31);
bool fixed = idx & (1u << 30);
struct kvm_pmc *counters;
- u64 ctr_val;
idx &= ~(3u << 30);
if (!fixed && idx >= pmu->nr_arch_gp_counters)
- return 1;
+ return NULL;
if (fixed && idx >= pmu->nr_arch_fixed_counters)
- return 1;
+ return NULL;
counters = fixed ? pmu->fixed_counters : pmu->gp_counters;
- ctr_val = pmc_read_counter(&counters[idx]);
+ return &counters[idx];
+}
+
+int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
+{
+ bool fast_mode = idx & (1u << 31);
+ struct kvm_pmc *pmc;
+ u64 ctr_val;
+
+ pmc = kvm_pmu_msr_idx_to_pmc(vcpu, idx);
+ if (!pmc)
+ return 1;
+
+ ctr_val = pmc_read_counter(pmc);
if (fast_mode)
ctr_val = (u32)ctr_val;