aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorZachary Amsden <zamsden@redhat.com>2010-08-20 04:07:17 -0400
committerAvi Kivity <avi@redhat.com>2010-10-24 04:51:22 -0400
commit99e3e30aee1a326a98bf3a5f47b8622219c685f3 (patch)
tree1b67fc70af33988080784d32725f72b5ce7c07d1 /arch/x86/kvm/x86.c
parentf4e1b3c8bd2a044cd0ccf80595bfd088a49fe60b (diff)
KVM: x86: Move TSC offset writes to common code
Also, ensure that the storing of the offset and the reading of the TSC are never preempted by taking a spinlock. While the lock is overkill now, it is useful later in this patch series. Signed-off-by: Zachary Amsden <zamsden@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 8b0c51a1ada..886132b6ef1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -895,6 +895,22 @@ static void kvm_set_time_scale(uint32_t tsc_khz, struct pvclock_vcpu_time_info *
895 895
896static DEFINE_PER_CPU(unsigned long, cpu_tsc_khz); 896static DEFINE_PER_CPU(unsigned long, cpu_tsc_khz);
897 897
898void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data)
899{
900 struct kvm *kvm = vcpu->kvm;
901 u64 offset;
902 unsigned long flags;
903
904 spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags);
905 offset = data - native_read_tsc();
906 kvm_x86_ops->write_tsc_offset(vcpu, offset);
907 spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags);
908
909 /* Reset of TSC must disable overshoot protection below */
910 vcpu->arch.hv_clock.tsc_timestamp = 0;
911}
912EXPORT_SYMBOL_GPL(kvm_write_tsc);
913
898static void kvm_write_guest_time(struct kvm_vcpu *v) 914static void kvm_write_guest_time(struct kvm_vcpu *v)
899{ 915{
900 struct timespec ts; 916 struct timespec ts;
@@ -5495,6 +5511,8 @@ struct kvm *kvm_arch_create_vm(void)
5495 /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */ 5511 /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */
5496 set_bit(KVM_USERSPACE_IRQ_SOURCE_ID, &kvm->arch.irq_sources_bitmap); 5512 set_bit(KVM_USERSPACE_IRQ_SOURCE_ID, &kvm->arch.irq_sources_bitmap);
5497 5513
5514 spin_lock_init(&kvm->arch.tsc_write_lock);
5515
5498 return kvm; 5516 return kvm;
5499} 5517}
5500 5518