diff options
author | Sean Christopherson <sean.j.christopherson@intel.com> | 2019-12-18 13:54:55 -0800 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-01-24 09:18:57 +0100 |
commit | 987b2594ed5d128c95c5255a9c7755f7480bf407 (patch) | |
tree | bb6992fe500527e9003be59ce00af6e1153c21f1 /arch/x86/kvm/x86.c | |
parent | d813a8ba54f94fd6a0276230bdf53c97b36c2101 (diff) | |
download | lwn-987b2594ed5d128c95c5255a9c7755f7480bf407.tar.gz lwn-987b2594ed5d128c95c5255a9c7755f7480bf407.zip |
KVM: x86: Move kvm_vcpu_init() invocation to common code
Move the kvm_cpu_{un}init() calls to common x86 code as an intermediate
step to removing kvm_cpu_{un}init() altogether.
Note, VMX'x alloc_apic_access_page() and init_rmode_identity_map() are
per-VM allocations and are intentionally kept if vCPU creation fails.
They are freed by kvm_arch_destroy_vm().
No functional change intended.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 50110bca7d57..51292843afcb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9176,6 +9176,8 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) kvm_x86_ops->vcpu_free(vcpu); + kvm_vcpu_uninit(vcpu); + free_cpumask_var(vcpu->arch.wbinvd_dirty_mask); kmem_cache_free(x86_fpu_cache, vcpu->arch.user_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.guest_fpu); @@ -9197,12 +9199,20 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, if (!vcpu) return ERR_PTR(-ENOMEM); - r = kvm_x86_ops->vcpu_create(kvm, vcpu, id); - if (r) { - kmem_cache_free(kvm_vcpu_cache, vcpu); - return ERR_PTR(r); - } + r = kvm_vcpu_init(vcpu, kvm, id); + if (r) + goto free_vcpu; + + r = kvm_x86_ops->vcpu_create(vcpu); + if (r) + goto uninit_vcpu; return vcpu; + +uninit_vcpu: + kvm_vcpu_uninit(vcpu); +free_vcpu: + kmem_cache_free(kvm_vcpu_cache, vcpu); + return ERR_PTR(r); } int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |