From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02D4FC10F0E for ; Mon, 15 Apr 2019 14:06:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3AF92087C for ; Mon, 15 Apr 2019 14:06:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sa7nrG2n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727605AbfDOOGB (ORCPT ); Mon, 15 Apr 2019 10:06:01 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51026 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727588AbfDOOGB (ORCPT ); Mon, 15 Apr 2019 10:06:01 -0400 Received: by mail-wm1-f66.google.com with SMTP id z11so20943378wmi.0; Mon, 15 Apr 2019 07:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=t1nPpstrlJM5kBs2fqSCtG3M2bij+WTmTrEa9fXX0WE=; b=sa7nrG2n2XdYRLO5bcWtTP0XQ/lCvo4C79lFXbdXSFCqqVsNcaYey1KISdEKzy6Tvd bporXZcI2YQkAlrWHS2w2q23pOVp4EXpIg7QSZP/oyATlNrOiiuI/X8S6vmTXvzcWO/R weF/G03rKwakeB78XfDZfeDvVXpqZKBmT67wEo9L9/8rewWpFKBLMcUYYNI/YJL74s9Q 1LFi+2QGIyc3WkjSuCO3CjnO0UEGEFtQehVK/rv2kGTzOXQOue/6vcjUi96uMShvuDWp nbodecL6cPu0Q57Ad33sTStodLzNp6p9jjQIbe5zudH8E4GYMuzcz2kA2XsxVBB+3Rk5 bWeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=t1nPpstrlJM5kBs2fqSCtG3M2bij+WTmTrEa9fXX0WE=; b=crAFI0KQkZsyCadi6iLbfHHlog5DgDuTZ6uixN59BS/a0PSjxy7kR948PJew4rj+52 j8cWAV3lLDtjvWX88cudYo044ty2515xNOKU2wp3j9gffBx7Dm6mLTFrI2N9pNOPNp/b FKSUBPqZEERBpgd6C5NN9+FULbIVW2bUwaXybEGlKYO5OCTT1WRAvhpTDgp6luT77biw yNwpqBiq/J1xxWSaYdanguVuobbtRC5BfetMKv2aRg/kS9GKCLbg/WY6/InMuhv7Fenc oNaZhQkJEF5kdxPeD0OpknoUxruFJe084vSPMcYP/aQ3Q5sfN7BpSvCrGs9G62/iR1er drCQ== X-Gm-Message-State: APjAAAXu4uIifE4A7mhHAbl39fT+askUT4mF2jkONQwouboEEllcCiAp U5zwiCVOmLz2kVdMMFm8y4uuMrlF X-Google-Smtp-Source: APXvYqz3DuIshr47RqymvoprLqcQpOaDYluoOEIPrMeRm+UD4ljTQlaCmwlyf/u68QsVS+DC05S+aw== X-Received: by 2002:a1c:b646:: with SMTP id g67mr23515676wmf.125.1555337158495; Mon, 15 Apr 2019 07:05:58 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id z84sm22034053wmg.24.2019.04.15.07.05.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 07:05:57 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson Subject: [PATCH] KVM: nVMX: always use early vmcs check when EPT is disabled Date: Mon, 15 Apr 2019 16:05:56 +0200 Message-Id: <1555337156-37142-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). --- arch/x86/include/uapi/asm/vmx.h | 1 + arch/x86/kvm/vmx/nested.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/uapi/asm/vmx.h b/arch/x86/include/uapi/asm/vmx.h index f0b0c90dd398..d213ec5c3766 100644 --- a/arch/x86/include/uapi/asm/vmx.h +++ b/arch/x86/include/uapi/asm/vmx.h @@ -146,6 +146,7 @@ #define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1 #define VMX_ABORT_LOAD_HOST_PDPTE_FAIL 2 +#define VMX_ABORT_VMCS_CORRUPTED 3 #define VMX_ABORT_LOAD_HOST_MSR_FAIL 4 #endif /* _UAPIVMX_H */ diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index a22af5a85540..6401eb7ef19c 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3796,8 +3796,18 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu) vmx_set_cr4(vcpu, vmcs_readl(CR4_READ_SHADOW)); nested_ept_uninit_mmu_context(vcpu); - vcpu->arch.cr3 = vmcs_readl(GUEST_CR3); - __set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail); + + /* + * This is only valid if EPT is in use, otherwise the vmcs01 GUEST_CR3 + * points to shadow pages! Fortunately we only get here after a WARN_ON + * if EPT is disabled, so a VMabort is perfectly fine. + */ + if (enable_ept) { + vcpu->arch.cr3 = vmcs_readl(GUEST_CR3); + __set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail); + } else { + nested_vmx_abort(vcpu, VMX_ABORT_VMCS_CORRUPTED); + } /* * 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 *)) { int i; + /* + * Without EPT it is not possible to restore L1's CR3 and PDPTR on + * VMfail, because they are not available in vmcs01. Just always + * use hardware checks. + */ + if (!enable_ept) + nested_early_check = 1; + if (!cpu_has_vmx_shadow_vmcs()) enable_shadow_vmcs = 0; if (enable_shadow_vmcs) { -- 1.8.3.1