Skip to content

Commit 2bb8caf

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: vVMX: signal failure for nested VMEntry if emulation_required
Fail a nested VMEntry with EXIT_REASON_INVALID_STATE if L2 guest state is invalid, i.e. vmcs12 contained invalid guest state, and unrestricted guest is disabled in L0 (and by extension disabled in L1). WARN_ON_ONCE in handle_invalid_guest_state() if we're attempting to emulate L2, i.e. nested_run_pending is true, to aid debug in the (hopefully unlikely) scenario that we somehow skip the nested VMEntry consistency check, e.g. due to a L0 bug. Note: KVM relies on hardware to detect the scenario where unrestricted guest is enabled in L0 but disabled in L1 and vmcs12 contains invalid guest state, i.e. checking emulation_required in prepare_vmcs02 is required only to handle the case were unrestricted guest is disabled in L0 since L0 never actually attempts VMLAUNCH/VMRESUME with vmcs02. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent e1de91c commit 2bb8caf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

arch/x86/kvm/vmx.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6865,6 +6865,13 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
68656865
bool intr_window_requested;
68666866
unsigned count = 130;
68676867

6868+
/*
6869+
* We should never reach the point where we are emulating L2
6870+
* due to invalid guest state as that means we incorrectly
6871+
* allowed a nested VMEntry with an invalid vmcs12.
6872+
*/
6873+
WARN_ON_ONCE(vmx->emulation_required && vmx->nested.nested_run_pending);
6874+
68686875
cpu_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
68696876
intr_window_requested = cpu_exec_ctrl & CPU_BASED_VIRTUAL_INTR_PENDING;
68706877

@@ -10990,6 +10997,14 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
1099010997
vmx->nested.dirty_vmcs12 = false;
1099110998
}
1099210999

11000+
/*
11001+
* Guest state is invalid and unrestricted guest is disabled,
11002+
* which means L1 attempted VMEntry to L2 with invalid state.
11003+
* Fail the VMEntry.
11004+
*/
11005+
if (vmx->emulation_required)
11006+
return 1;
11007+
1099311008
/* Shadow page tables on either EPT or shadow page tables. */
1099411009
if (nested_vmx_load_cr3(vcpu, vmcs12->guest_cr3, nested_cpu_has_ept(vmcs12),
1099511010
entry_failure_code))

0 commit comments

Comments
 (0)