| From foo@baz Mon Feb 5 10:12:24 PST 2018 |
| Subject: KVM: VMX: introduce alloc_loaded_vmcs |
| From: Paolo Bonzini pbonzini@redhat.com |
| Date: Thu Jan 11 12:16:15 2018 +0100 |
| |
| From: Paolo Bonzini pbonzini@redhat.com |
| |
| commit f21f165ef922c2146cc5bdc620f542953c41714b |
| |
| Group together the calls to alloc_vmcs and loaded_vmcs_init. Soon we'll also |
| allocate an MSR bitmap there. |
| |
| Cc: stable@vger.kernel.org # prereq for Spectre mitigation |
| Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| |
| --- |
| arch/x86/kvm/vmx.c | 36 ++++++++++++++++++++++-------------- |
| 1 file changed, 22 insertions(+), 14 deletions(-) |
| |
| --- a/arch/x86/kvm/vmx.c |
| +++ b/arch/x86/kvm/vmx.c |
| @@ -3814,11 +3814,6 @@ static struct vmcs *alloc_vmcs_cpu(int c |
| return vmcs; |
| } |
| |
| -static struct vmcs *alloc_vmcs(void) |
| -{ |
| - return alloc_vmcs_cpu(raw_smp_processor_id()); |
| -} |
| - |
| static void free_vmcs(struct vmcs *vmcs) |
| { |
| free_pages((unsigned long)vmcs, vmcs_config.order); |
| @@ -3837,6 +3832,22 @@ static void free_loaded_vmcs(struct load |
| WARN_ON(loaded_vmcs->shadow_vmcs != NULL); |
| } |
| |
| +static struct vmcs *alloc_vmcs(void) |
| +{ |
| + return alloc_vmcs_cpu(raw_smp_processor_id()); |
| +} |
| + |
| +static int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs) |
| +{ |
| + loaded_vmcs->vmcs = alloc_vmcs(); |
| + if (!loaded_vmcs->vmcs) |
| + return -ENOMEM; |
| + |
| + loaded_vmcs->shadow_vmcs = NULL; |
| + loaded_vmcs_init(loaded_vmcs); |
| + return 0; |
| +} |
| + |
| static void free_kvm_area(void) |
| { |
| int cpu; |
| @@ -7135,12 +7146,11 @@ static int enter_vmx_operation(struct kv |
| { |
| struct vcpu_vmx *vmx = to_vmx(vcpu); |
| struct vmcs *shadow_vmcs; |
| + int r; |
| |
| - vmx->nested.vmcs02.vmcs = alloc_vmcs(); |
| - vmx->nested.vmcs02.shadow_vmcs = NULL; |
| - if (!vmx->nested.vmcs02.vmcs) |
| + r = alloc_loaded_vmcs(&vmx->nested.vmcs02); |
| + if (r < 0) |
| goto out_vmcs02; |
| - loaded_vmcs_init(&vmx->nested.vmcs02); |
| |
| if (cpu_has_vmx_msr_bitmap()) { |
| vmx->nested.msr_bitmap = |
| @@ -9535,13 +9545,11 @@ static struct kvm_vcpu *vmx_create_vcpu( |
| if (!vmx->guest_msrs) |
| goto free_pml; |
| |
| - vmx->loaded_vmcs = &vmx->vmcs01; |
| - vmx->loaded_vmcs->vmcs = alloc_vmcs(); |
| - vmx->loaded_vmcs->shadow_vmcs = NULL; |
| - if (!vmx->loaded_vmcs->vmcs) |
| + err = alloc_loaded_vmcs(&vmx->vmcs01); |
| + if (err < 0) |
| goto free_msrs; |
| - loaded_vmcs_init(vmx->loaded_vmcs); |
| |
| + vmx->loaded_vmcs = &vmx->vmcs01; |
| cpu = get_cpu(); |
| vmx_vcpu_load(&vmx->vcpu, cpu); |
| vmx->vcpu.cpu = cpu; |