Skip to content

Commit 2b27924

Browse files
committed
KVM: nVMX: always use early vmcs check when EPT is disabled
The remaining failures of vmx.flat when EPT is disabled are caused by incorrectly reflecting VMfails to the L1 hypervisor. What happens is that nested_vmx_restore_host_state corrupts the guest CR3, reloading it with the host's shadow CR3 instead, because it blindly loads GUEST_CR3 from the vmcs01. For simplicity let's just always use hardware VMCS checks when EPT is disabled. This way, nested_vmx_restore_host_state is not reached at all (or at least shouldn't be reached). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6909081 commit 2b27924

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎arch/x86/include/uapi/asm/vmx.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146

147147
#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1
148148
#define VMX_ABORT_LOAD_HOST_PDPTE_FAIL 2
149+
#define VMX_ABORT_VMCS_CORRUPTED 3
149150
#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4
150151

151152
#endif /* _UAPIVMX_H */

‎arch/x86/kvm/vmx/nested.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,8 +3796,18 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu)
37963796
vmx_set_cr4(vcpu, vmcs_readl(CR4_READ_SHADOW));
37973797

37983798
nested_ept_uninit_mmu_context(vcpu);
3799-
vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
3800-
__set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail);
3799+
3800+
/*
3801+
* This is only valid if EPT is in use, otherwise the vmcs01 GUEST_CR3
3802+
* points to shadow pages! Fortunately we only get here after a WARN_ON
3803+
* if EPT is disabled, so a VMabort is perfectly fine.
3804+
*/
3805+
if (enable_ept) {
3806+
vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
3807+
__set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail);
3808+
} else {
3809+
nested_vmx_abort(vcpu, VMX_ABORT_VMCS_CORRUPTED);
3810+
}
38013811

38023812
/*
38033813
* Use ept_save_pdptrs(vcpu) to load the MMU's cached PDPTRs
@@ -5745,6 +5755,14 @@ __init int nested_vmx_hardware_setup(int (*exit_handlers[])(struct kvm_vcpu *))
57455755
{
57465756
int i;
57475757

5758+
/*
5759+
* Without EPT it is not possible to restore L1's CR3 and PDPTR on
5760+
* VMfail, because they are not available in vmcs01. Just always
5761+
* use hardware checks.
5762+
*/
5763+
if (!enable_ept)
5764+
nested_early_check = 1;
5765+
57485766
if (!cpu_has_vmx_shadow_vmcs())
57495767
enable_shadow_vmcs = 0;
57505768
if (enable_shadow_vmcs) {

0 commit comments

Comments
 (0)