Skip to content

Commit c8607e4

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: nVMX: don't fail nested VM entry on invalid guest state if !from_vmentry
It is possible that when non root mode is entered via special entry (!from_vmentry), that is from SMM or from loading the nested state, the L2 state could be invalid in regard to non unrestricted guest mode, but later it can become valid. (for example when RSM emulation restores segment registers from SMRAM) Thus delay the check to VM entry, where we will check this and fail. Signed-off-by: Maxim Levitsky <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c42dec1 commit c8607e4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2583,8 +2583,13 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
25832583
* Guest state is invalid and unrestricted guest is disabled,
25842584
* which means L1 attempted VMEntry to L2 with invalid state.
25852585
* Fail the VMEntry.
2586+
*
2587+
* However when force loading the guest state (SMM exit or
2588+
* loading nested state after migration, it is possible to
2589+
* have invalid guest state now, which will be later fixed by
2590+
* restoring L2 register state
25862591
*/
2587-
if (CC(!vmx_guest_state_valid(vcpu))) {
2592+
if (CC(from_vmentry && !vmx_guest_state_valid(vcpu))) {
25882593
*entry_failure_code = ENTRY_FAIL_DEFAULT;
25892594
return -EINVAL;
25902595
}

arch/x86/kvm/vmx/vmx.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6628,7 +6628,10 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
66286628
* consistency check VM-Exit due to invalid guest state and bail.
66296629
*/
66306630
if (unlikely(vmx->emulation_required)) {
6631-
vmx->fail = 0;
6631+
6632+
/* We don't emulate invalid state of a nested guest */
6633+
vmx->fail = is_guest_mode(vcpu);
6634+
66326635
vmx->exit_reason.full = EXIT_REASON_INVALID_STATE;
66336636
vmx->exit_reason.failed_vmentry = 1;
66346637
kvm_register_mark_available(vcpu, VCPU_EXREG_EXIT_INFO_1);

0 commit comments

Comments
 (0)