Commit 7f27179a authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: SVM: Use direct vcpu pointer during vCPU create/free

Capture the vcpu pointer in a local varaible and replace '&svm->vcpu'
references with a direct reference to the pointer in anticipation of
moving bits of the code to common x86 and passing the vcpu pointer into
svm_create_vcpu(), i.e. eliminate unnecessary noise from future patches.
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 34109c04
...@@ -2189,6 +2189,7 @@ static int avic_init_vcpu(struct vcpu_svm *svm) ...@@ -2189,6 +2189,7 @@ static int avic_init_vcpu(struct vcpu_svm *svm)
static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
{ {
struct kvm_vcpu *vcpu;
struct vcpu_svm *svm; struct vcpu_svm *svm;
struct page *page; struct page *page;
struct page *msrpm_pages; struct page *msrpm_pages;
...@@ -2204,24 +2205,25 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -2204,24 +2205,25 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
vcpu = &svm->vcpu;
svm->vcpu.arch.user_fpu = kmem_cache_zalloc(x86_fpu_cache, vcpu->arch.user_fpu = kmem_cache_zalloc(x86_fpu_cache,
GFP_KERNEL_ACCOUNT); GFP_KERNEL_ACCOUNT);
if (!svm->vcpu.arch.user_fpu) { if (!vcpu->arch.user_fpu) {
printk(KERN_ERR "kvm: failed to allocate kvm userspace's fpu\n"); printk(KERN_ERR "kvm: failed to allocate kvm userspace's fpu\n");
err = -ENOMEM; err = -ENOMEM;
goto free_partial_svm; goto free_partial_svm;
} }
svm->vcpu.arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache, vcpu->arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache,
GFP_KERNEL_ACCOUNT); GFP_KERNEL_ACCOUNT);
if (!svm->vcpu.arch.guest_fpu) { if (!vcpu->arch.guest_fpu) {
printk(KERN_ERR "kvm: failed to allocate vcpu's fpu\n"); printk(KERN_ERR "kvm: failed to allocate vcpu's fpu\n");
err = -ENOMEM; err = -ENOMEM;
goto free_user_fpu; goto free_user_fpu;
} }
err = kvm_vcpu_init(&svm->vcpu, kvm, id); err = kvm_vcpu_init(vcpu, kvm, id);
if (err) if (err)
goto free_svm; goto free_svm;
...@@ -2265,9 +2267,9 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -2265,9 +2267,9 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
svm->asid_generation = 0; svm->asid_generation = 0;
init_vmcb(svm); init_vmcb(svm);
svm_init_osvw(&svm->vcpu); svm_init_osvw(vcpu);
return &svm->vcpu; return vcpu;
free_page4: free_page4:
__free_page(hsave_page); __free_page(hsave_page);
...@@ -2278,11 +2280,11 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -2278,11 +2280,11 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
free_page1: free_page1:
__free_page(page); __free_page(page);
uninit: uninit:
kvm_vcpu_uninit(&svm->vcpu); kvm_vcpu_uninit(vcpu);
free_svm: free_svm:
kmem_cache_free(x86_fpu_cache, svm->vcpu.arch.guest_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.guest_fpu);
free_user_fpu: free_user_fpu:
kmem_cache_free(x86_fpu_cache, svm->vcpu.arch.user_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.user_fpu);
free_partial_svm: free_partial_svm:
kmem_cache_free(kvm_vcpu_cache, svm); kmem_cache_free(kvm_vcpu_cache, svm);
out: out:
...@@ -2313,8 +2315,8 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu) ...@@ -2313,8 +2315,8 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu)
__free_page(virt_to_page(svm->nested.hsave)); __free_page(virt_to_page(svm->nested.hsave));
__free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER); __free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER);
kvm_vcpu_uninit(vcpu); kvm_vcpu_uninit(vcpu);
kmem_cache_free(x86_fpu_cache, svm->vcpu.arch.user_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.user_fpu);
kmem_cache_free(x86_fpu_cache, svm->vcpu.arch.guest_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.guest_fpu);
kmem_cache_free(kvm_vcpu_cache, svm); kmem_cache_free(kvm_vcpu_cache, svm);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment