Commit 34109c04 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

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

Capture the vcpu pointer in a local varaible and replace '&vmx->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
vmx_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 034d8e2c
...@@ -6682,17 +6682,17 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu) ...@@ -6682,17 +6682,17 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
nested_vmx_free_vcpu(vcpu); nested_vmx_free_vcpu(vcpu);
free_loaded_vmcs(vmx->loaded_vmcs); free_loaded_vmcs(vmx->loaded_vmcs);
kvm_vcpu_uninit(vcpu); kvm_vcpu_uninit(vcpu);
kmem_cache_free(x86_fpu_cache, vmx->vcpu.arch.user_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.user_fpu);
kmem_cache_free(x86_fpu_cache, vmx->vcpu.arch.guest_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.guest_fpu);
kmem_cache_free(kvm_vcpu_cache, vmx); kmem_cache_free(kvm_vcpu_cache, vmx);
} }
static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
{ {
int err; struct kvm_vcpu *vcpu;
struct vcpu_vmx *vmx; struct vcpu_vmx *vmx;
unsigned long *msr_bitmap; unsigned long *msr_bitmap;
int i, cpu; int i, cpu, err;
BUILD_BUG_ON_MSG(offsetof(struct vcpu_vmx, vcpu) != 0, BUILD_BUG_ON_MSG(offsetof(struct vcpu_vmx, vcpu) != 0,
"struct kvm_vcpu must be at offset 0 for arch usercopy region"); "struct kvm_vcpu must be at offset 0 for arch usercopy region");
...@@ -6701,23 +6701,25 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -6701,23 +6701,25 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
if (!vmx) if (!vmx)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
vmx->vcpu.arch.user_fpu = kmem_cache_zalloc(x86_fpu_cache, vcpu = &vmx->vcpu;
GFP_KERNEL_ACCOUNT);
if (!vmx->vcpu.arch.user_fpu) { vcpu->arch.user_fpu = kmem_cache_zalloc(x86_fpu_cache,
GFP_KERNEL_ACCOUNT);
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_vcpu; goto free_partial_vcpu;
} }
vmx->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 (!vmx->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(&vmx->vcpu, kvm, id); err = kvm_vcpu_init(vcpu, kvm, id);
if (err) if (err)
goto free_vcpu; goto free_vcpu;
...@@ -6789,12 +6791,12 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -6789,12 +6791,12 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
vmx->loaded_vmcs = &vmx->vmcs01; vmx->loaded_vmcs = &vmx->vmcs01;
cpu = get_cpu(); cpu = get_cpu();
vmx_vcpu_load(&vmx->vcpu, cpu); vmx_vcpu_load(vcpu, cpu);
vmx->vcpu.cpu = cpu; vcpu->cpu = cpu;
init_vmcs(vmx); init_vmcs(vmx);
vmx_vcpu_put(&vmx->vcpu); vmx_vcpu_put(vcpu);
put_cpu(); put_cpu();
if (cpu_need_virtualize_apic_accesses(&vmx->vcpu)) { if (cpu_need_virtualize_apic_accesses(vcpu)) {
err = alloc_apic_access_page(kvm); err = alloc_apic_access_page(kvm);
if (err) if (err)
goto free_vmcs; goto free_vmcs;
...@@ -6809,7 +6811,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -6809,7 +6811,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
if (nested) if (nested)
nested_vmx_setup_ctls_msrs(&vmx->nested.msrs, nested_vmx_setup_ctls_msrs(&vmx->nested.msrs,
vmx_capability.ept, vmx_capability.ept,
kvm_vcpu_apicv_active(&vmx->vcpu)); kvm_vcpu_apicv_active(vcpu));
else else
memset(&vmx->nested.msrs, 0, sizeof(vmx->nested.msrs)); memset(&vmx->nested.msrs, 0, sizeof(vmx->nested.msrs));
...@@ -6827,19 +6829,19 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -6827,19 +6829,19 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
vmx->ept_pointer = INVALID_PAGE; vmx->ept_pointer = INVALID_PAGE;
return &vmx->vcpu; return vcpu;
free_vmcs: free_vmcs:
free_loaded_vmcs(vmx->loaded_vmcs); free_loaded_vmcs(vmx->loaded_vmcs);
free_pml: free_pml:
vmx_destroy_pml_buffer(vmx); vmx_destroy_pml_buffer(vmx);
uninit_vcpu: uninit_vcpu:
kvm_vcpu_uninit(&vmx->vcpu); kvm_vcpu_uninit(vcpu);
free_vpid(vmx->vpid); free_vpid(vmx->vpid);
free_vcpu: free_vcpu:
kmem_cache_free(x86_fpu_cache, vmx->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, vmx->vcpu.arch.user_fpu); kmem_cache_free(x86_fpu_cache, vcpu->arch.user_fpu);
free_partial_vcpu: free_partial_vcpu:
kmem_cache_free(kvm_vcpu_cache, vmx); kmem_cache_free(kvm_vcpu_cache, vmx);
return ERR_PTR(err); return ERR_PTR(err);
......
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