KVM: Add generic RDPMC support
authorAvi Kivity <avi@redhat.com>
Thu, 10 Nov 2011 12:57:23 +0000 (14:57 +0200)
committerAvi Kivity <avi@redhat.com>
Tue, 27 Dec 2011 09:24:35 +0000 (11:24 +0200)
Add a helper function that emulates the RDPMC instruction operation.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/x86.c

index fb60ffdb4e4332b0c5a0abe194e6368f1f64e904..52d6640a5ca1eec731418d408fc6e03c161ce3fe 100644 (file)
@@ -760,6 +760,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
 
 unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu);
 void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
+bool kvm_rdpmc(struct kvm_vcpu *vcpu);
 
 void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr);
 void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
index 08ae951ecc5ca9ce2f027fe73841097fa52a0a5a..27d18b7617f37d78b6e17507447f8d9337c8c620 100644 (file)
@@ -760,6 +760,21 @@ int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val)
 }
 EXPORT_SYMBOL_GPL(kvm_get_dr);
 
+bool kvm_rdpmc(struct kvm_vcpu *vcpu)
+{
+       u32 ecx = kvm_register_read(vcpu, VCPU_REGS_RCX);
+       u64 data;
+       int err;
+
+       err = kvm_pmu_read_pmc(vcpu, ecx, &data);
+       if (err)
+               return err;
+       kvm_register_write(vcpu, VCPU_REGS_RAX, (u32)data);
+       kvm_register_write(vcpu, VCPU_REGS_RDX, data >> 32);
+       return err;
+}
+EXPORT_SYMBOL_GPL(kvm_rdpmc);
+
 /*
  * List of msr numbers which we expose to userspace through KVM_GET_MSRS
  * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.