Commit 1279a6b1 authored by David Hildenbrand's avatar David Hildenbrand Committed by Radim Krčmář

KVM: nVMX: single function for switching between vmcs

Let's combine it in a single function vmx_switch_vmcs().
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: default avatarJim Mattson <jmattson@google.com>
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
parent f0b98c02
...@@ -9145,16 +9145,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) ...@@ -9145,16 +9145,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
vmx_complete_interrupts(vmx); vmx_complete_interrupts(vmx);
} }
static void vmx_load_vmcs01(struct kvm_vcpu *vcpu) static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
{ {
struct vcpu_vmx *vmx = to_vmx(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu);
int cpu; int cpu;
if (vmx->loaded_vmcs == &vmx->vmcs01) if (vmx->loaded_vmcs == vmcs)
return; return;
cpu = get_cpu(); cpu = get_cpu();
vmx->loaded_vmcs = &vmx->vmcs01; vmx->loaded_vmcs = vmcs;
vmx_vcpu_put(vcpu); vmx_vcpu_put(vcpu);
vmx_vcpu_load(vcpu, cpu); vmx_vcpu_load(vcpu, cpu);
vcpu->cpu = cpu; vcpu->cpu = cpu;
...@@ -9172,7 +9172,7 @@ static void vmx_free_vcpu_nested(struct kvm_vcpu *vcpu) ...@@ -9172,7 +9172,7 @@ static void vmx_free_vcpu_nested(struct kvm_vcpu *vcpu)
r = vcpu_load(vcpu); r = vcpu_load(vcpu);
BUG_ON(r); BUG_ON(r);
vmx_load_vmcs01(vcpu); vmx_switch_vmcs(vcpu, &vmx->vmcs01);
free_nested(vmx); free_nested(vmx);
vcpu_put(vcpu); vcpu_put(vcpu);
} }
...@@ -10424,7 +10424,6 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry) ...@@ -10424,7 +10424,6 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
struct vcpu_vmx *vmx = to_vmx(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu);
struct vmcs12 *vmcs12 = get_vmcs12(vcpu); struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
struct loaded_vmcs *vmcs02; struct loaded_vmcs *vmcs02;
int cpu;
u32 msr_entry_idx; u32 msr_entry_idx;
u32 exit_qual; u32 exit_qual;
...@@ -10437,18 +10436,12 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry) ...@@ -10437,18 +10436,12 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL); vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
cpu = get_cpu(); vmx_switch_vmcs(vcpu, vmcs02);
vmx->loaded_vmcs = vmcs02;
vmx_vcpu_put(vcpu);
vmx_vcpu_load(vcpu, cpu);
vcpu->cpu = cpu;
put_cpu();
vmx_segment_cache_clear(vmx); vmx_segment_cache_clear(vmx);
if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) { if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) {
leave_guest_mode(vcpu); leave_guest_mode(vcpu);
vmx_load_vmcs01(vcpu); vmx_switch_vmcs(vcpu, &vmx->vmcs01);
nested_vmx_entry_failure(vcpu, vmcs12, nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_INVALID_STATE, exit_qual); EXIT_REASON_INVALID_STATE, exit_qual);
return 1; return 1;
...@@ -10461,7 +10454,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry) ...@@ -10461,7 +10454,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
vmcs12->vm_entry_msr_load_count); vmcs12->vm_entry_msr_load_count);
if (msr_entry_idx) { if (msr_entry_idx) {
leave_guest_mode(vcpu); leave_guest_mode(vcpu);
vmx_load_vmcs01(vcpu); vmx_switch_vmcs(vcpu, &vmx->vmcs01);
nested_vmx_entry_failure(vcpu, vmcs12, nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx); EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
return 1; return 1;
...@@ -11029,7 +11022,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, ...@@ -11029,7 +11022,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
if (unlikely(vmx->fail)) if (unlikely(vmx->fail))
vm_inst_error = vmcs_read32(VM_INSTRUCTION_ERROR); vm_inst_error = vmcs_read32(VM_INSTRUCTION_ERROR);
vmx_load_vmcs01(vcpu); vmx_switch_vmcs(vcpu, &vmx->vmcs01);
if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT) if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
&& nested_exit_intr_ack_set(vcpu)) { && nested_exit_intr_ack_set(vcpu)) {
......
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