From patchwork Wed Nov 23 01:14:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9442481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8620B60237 for ; Wed, 23 Nov 2016 01:23:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79A111FFAE for ; Wed, 23 Nov 2016 01:23:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E92A206AF; Wed, 23 Nov 2016 01:23:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18A9E1FFAE for ; Wed, 23 Nov 2016 01:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756070AbcKWBXb (ORCPT ); Tue, 22 Nov 2016 20:23:31 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36439 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755919AbcKWBXa (ORCPT ); Tue, 22 Nov 2016 20:23:30 -0500 Received: by mail-pf0-f170.google.com with SMTP id 189so6806104pfz.3 for ; Tue, 22 Nov 2016 17:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=o65NgC4l33T3fNhqjGkXvVsQxIZOn9qRlEQRCLf/3jM=; b=FAEfh69QEEir3vaquDROhVCH2vTcZIdf/lL1gqO3OPyk06kyksbkg/71Uz4MtEoCtK fBdTmgaZIlieEhVyPmsJ18Qt3GMlq8wTB1BMOi0m2fO0oB4TmWGl4fH/qOnRhaU5VoMu dhqJA+FhRr6IGCup/Z4CsRZWhHBUvH0EfIc0WcP7iHCKMM3vpOxV28fSZcyLrl60qZW3 XT5b8ipTvrzCm3GsSCTUg6aJTWzU2jAsrUqBuytD8uy24k6yNf+Eeb/XYSkI+VCsTKkE LOIkm1tUhYktK50maCcueSN6fVA29DP7D/nK7Pv9QWFq/xcHRv303bPXxkNoLj3aMp3B w2pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o65NgC4l33T3fNhqjGkXvVsQxIZOn9qRlEQRCLf/3jM=; b=F7VHu4+r+X0tZezcOm1TGFkMNy3fbsQpAURhDWXgJQ/9wJbIn66hfFDPMBRYJeiVS+ hFZBmUOPYVXGmqGHPebPDvD5DO2T74UhlIZukQHBEaHqyaKejoNnYMLTqr0LBBisggB4 VYW3GOZ+mfD5r2PQ6M8pTzMjuqs1KWXpdZ8nGnK8fNN1x8c3ZM0FFicPxDy9v7bcGaX0 SG2JDSCSlbBArIrmbOz3VB8U2db+l8XXx150fU8ncTdxaaTOBjLPv45wBI0N4V62ED2A w2MKLHyFnbPk8MY1tuL92D8NtlCKQbJ+NrG21BM5pNR+aMl+TLnPFRNWM8YICfL3J4+B eLug== X-Gm-Message-State: AKaTC02v2Wt/1PoKXEQdXG6W540RMrJARmZ3pBSKF+vdpaos6XAKuzi8PBZ2rvakWkAMR/uY X-Received: by 10.84.208.227 with SMTP id c32mr1202274plj.144.1479863696909; Tue, 22 Nov 2016 17:14:56 -0800 (PST) Received: from dmatlack.sea.corp.google.com ([100.100.206.65]) by smtp.gmail.com with ESMTPSA id c8sm47849356pfe.15.2016.11.22.17.14.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Nov 2016 17:14:56 -0800 (PST) From: David Matlack To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jmattson@google.com, rkrcmar@redhat.com, pbonzini@redhat.com, David Matlack Subject: [PATCH 4/4] KVM: nVMX: load GUEST_EFER after GUEST_CR0 during emulated VM-entry Date: Tue, 22 Nov 2016 17:14:40 -0800 Message-Id: <1479863680-117511-5-git-send-email-dmatlack@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1479863680-117511-1-git-send-email-dmatlack@google.com> References: <1479863680-117511-1-git-send-email-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vmx_set_cr0() modifies GUEST_EFER and "IA-32e mode guest" in the current VMCS. Call vmx_set_efer() after vmx_set_cr0() so that emulated VM-entry is more faithful to VMCS12. This patch correctly causes VM-entry to fail when "IA-32e mode guest" is 1 and GUEST_CR0.PG is 0. Previously this configuration would succeed and "IA-32e mode guest" would silently be disabled by KVM. Signed-off-by: David Matlack --- arch/x86/kvm/vmx.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ac5d9c0..86235fc 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10418,15 +10418,6 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) nested_ept_init_mmu_context(vcpu); } - if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_EFER) - vcpu->arch.efer = vmcs12->guest_ia32_efer; - else if (vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) - vcpu->arch.efer |= (EFER_LMA | EFER_LME); - else - vcpu->arch.efer &= ~(EFER_LMA | EFER_LME); - /* Note: modifies VM_ENTRY/EXIT_CONTROLS and GUEST/HOST_IA32_EFER */ - vmx_set_efer(vcpu, vcpu->arch.efer); - /* * This sets GUEST_CR0 to vmcs12->guest_cr0, with possibly a modified * TS bit (for lazy fpu) and bits which we consider mandatory enabled. @@ -10441,6 +10432,15 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) vmx_set_cr4(vcpu, vmcs12->guest_cr4); vmcs_writel(CR4_READ_SHADOW, nested_read_cr4(vmcs12)); + if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_EFER) + vcpu->arch.efer = vmcs12->guest_ia32_efer; + else if (vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) + vcpu->arch.efer |= (EFER_LMA | EFER_LME); + else + vcpu->arch.efer &= ~(EFER_LMA | EFER_LME); + /* Note: modifies VM_ENTRY/EXIT_CONTROLS and GUEST/HOST_IA32_EFER */ + vmx_set_efer(vcpu, vcpu->arch.efer); + /* shadow page tables on either EPT or shadow page tables */ kvm_set_cr3(vcpu, vmcs12->guest_cr3); kvm_mmu_reset_context(vcpu);