Skip to content

Commit 16fb9a4

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: nVMX: do early preparation of vmcs02 before check_vmentry_postreqs()
In anticipation of using vmcs02 to do early consistency checks, move the early preparation of vmcs02 prior to checking the postreqs. The downside of this approach is that we'll unnecessary load vmcs02 in the case that check_vmentry_postreqs() fails, but that is essentially our slow path anyways (not actually slow, but it's the path we don't really care about optimizing). Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Reviewed-by: Jim Mattson <jmattson@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 9d6105b commit 16fb9a4

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

arch/x86/kvm/vmx.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12701,11 +12701,6 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
1270112701
if (likely(!evaluate_pending_interrupts) && kvm_vcpu_apicv_active(vcpu))
1270212702
evaluate_pending_interrupts |= vmx_has_apicv_interrupt(vcpu);
1270312703

12704-
if (from_vmentry && check_vmentry_postreqs(vcpu, vmcs12, &exit_qual))
12705-
goto vmentry_fail_vmexit;
12706-
12707-
enter_guest_mode(vcpu);
12708-
1270912704
if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
1271012705
vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
1271112706
if (kvm_mpx_supported() &&
@@ -12714,17 +12709,23 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
1271412709

1271512710
vmx_switch_vmcs(vcpu, &vmx->nested.vmcs02);
1271612711

12712+
prepare_vmcs02_early(vmx, vmcs12);
12713+
12714+
if (from_vmentry) {
12715+
nested_get_vmcs12_pages(vcpu);
12716+
12717+
if (check_vmentry_postreqs(vcpu, vmcs12, &exit_qual))
12718+
goto vmentry_fail_vmexit;
12719+
}
12720+
12721+
enter_guest_mode(vcpu);
1271712722
if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING)
1271812723
vcpu->arch.tsc_offset += vmcs12->tsc_offset;
1271912724

12720-
prepare_vmcs02_early(vmx, vmcs12);
12721-
1272212725
if (prepare_vmcs02(vcpu, vmcs12, &exit_qual))
1272312726
goto vmentry_fail_vmexit_guest_mode;
1272412727

1272512728
if (from_vmentry) {
12726-
nested_get_vmcs12_pages(vcpu);
12727-
1272812729
exit_reason = EXIT_REASON_MSR_LOAD_FAIL;
1272912730
exit_qual = nested_vmx_load_msr(vcpu,
1273012731
vmcs12->vm_entry_msr_load_addr,
@@ -12776,12 +12777,13 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
1277612777
if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING)
1277712778
vcpu->arch.tsc_offset -= vmcs12->tsc_offset;
1277812779
leave_guest_mode(vcpu);
12780+
12781+
vmentry_fail_vmexit:
1277912782
vmx_switch_vmcs(vcpu, &vmx->vmcs01);
1278012783

1278112784
if (!from_vmentry)
1278212785
return 1;
1278312786

12784-
vmentry_fail_vmexit:
1278512787
load_vmcs12_host_state(vcpu, vmcs12);
1278612788
vmcs12->vm_exit_reason = exit_reason | VMX_EXIT_REASONS_FAILED_VMENTRY;
1278712789
vmcs12->exit_qualification = exit_qual;

0 commit comments

Comments
 (0)