KVM: x86: add kvm_arch_vcpu_postcreate callback, move TSC initialization
authorMarcelo Tosatti <mtosatti@redhat.com>
Wed, 28 Nov 2012 01:29:02 +0000 (23:29 -0200)
committerMarcelo Tosatti <mtosatti@redhat.com>
Wed, 28 Nov 2012 01:29:14 +0000 (23:29 -0200)
TSC initialization will soon make use of online_vcpus.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/ia64/kvm/kvm-ia64.c
arch/powerpc/kvm/powerpc.c
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
include/linux/kvm_host.h
virt/kvm/kvm_main.c

index c71acd7f9a13d1a878a513558f099b04421ebe4b..83b54530916e72e1102cf09b20196d3eb9b6d3e6 100644 (file)
@@ -1330,6 +1330,11 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
        return 0;
 }
 
+int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
+{
+       return 0;
+}
+
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
        return -EINVAL;
index deb0d596d815fca2457c415d774144702869f60e..f9ab12aea829de64a61b7e066769121dd8b57f36 100644 (file)
@@ -439,6 +439,11 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
        return vcpu;
 }
 
+int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
+{
+       return 0;
+}
+
 void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
 {
        /* Make sure we're not using the vcpu anymore */
index 38883f0bf27e0e8ec9c864133bc5bd6939770888..731ddeee32e416b24d27c7674e12328e65cfae49 100644 (file)
@@ -355,6 +355,11 @@ static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu)
        atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
 }
 
+int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
+{
+       return 0;
+}
+
 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 {
        atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH |
index 94f5ceba7e1e266d7677d128ef8c16a734de0698..161a5fa66d8234291f6abdccf36b71e69def4992 100644 (file)
@@ -1251,7 +1251,6 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
        svm->vmcb_pa = page_to_pfn(page) << PAGE_SHIFT;
        svm->asid_generation = 0;
        init_vmcb(svm);
-       kvm_write_tsc(&svm->vcpu, 0);
 
        err = fx_init(&svm->vcpu);
        if (err)
index 896efd4842e73edc71f3b48847bc9525a378c95a..bb18923bf632b074e647678faff83dc7e6358d18 100644 (file)
@@ -3896,8 +3896,6 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
        vmcs_writel(CR0_GUEST_HOST_MASK, ~0UL);
        set_cr4_guest_host_mask(vmx);
 
-       kvm_write_tsc(&vmx->vcpu, 0);
-
        return 0;
 }
 
index a7b97a49d8ad8fce106b271e835c0e54d064063e..f3c069efc72a1f732ef599880d923236297ef111 100644 (file)
@@ -6320,6 +6320,19 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
        return r;
 }
 
+int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
+{
+       int r;
+
+       r = vcpu_load(vcpu);
+       if (r)
+               return r;
+       kvm_write_tsc(vcpu, 0);
+       vcpu_put(vcpu);
+
+       return r;
+}
+
 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 {
        int r;
index c94c9985dee06174891ce6965b2679491230f6c0..8e5c7b6516559e919140b15317b9578aa95f1c2f 100644 (file)
@@ -596,6 +596,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
+int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu);
 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
 
 int kvm_arch_hardware_enable(void *garbage);
index be3e7bb73b1083edd2c3e8f207587456b309cbff..e6cfd4344d28fdf927b689983d45439224558d1a 100644 (file)
@@ -1853,6 +1853,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
        atomic_inc(&kvm->online_vcpus);
 
        mutex_unlock(&kvm->lock);
+       kvm_arch_vcpu_postcreate(vcpu);
        return r;
 
 unlock_vcpu_destroy: