From patchwork Tue Oct 4 17:48:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 9362187 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 2D9D8608A7 for ; Tue, 4 Oct 2016 17:52:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 223A028B6B for ; Tue, 4 Oct 2016 17:52:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1658A28BBB; Tue, 4 Oct 2016 17:52:27 +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=ham 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 2A36828BB4 for ; Tue, 4 Oct 2016 17:52:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752072AbcJDRtF (ORCPT ); Tue, 4 Oct 2016 13:49:05 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:36816 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751969AbcJDRtE (ORCPT ); Tue, 4 Oct 2016 13:49:04 -0400 Received: by mail-pa0-f47.google.com with SMTP id qn7so74730419pac.3 for ; Tue, 04 Oct 2016 10:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=UZZytj2Vj4ZuZMBRZVR+fXxjadcydCJDoP75Zv47RfY=; b=ZvZCPaOuGmW+Rl60wq9X7Ux8yqixMKCE3OzDibHnXC+RQyQVubpl4+44McpEI2p/Ri TZ2hEBpYoRfjTz9L//m76CR0O7sqFoJ5po3R19WuY14VQ3OYrnbOSx0REqrei96MxOyc 3N0gGCHOD2v+N+jfZ2njflWueAUtA5g8XAXgK2DP78RyZvBhPWgyLA2hyNrJXPMlwxLx kEr3IaxmzHSTvq4GapeMF4cVFAslmT4FbQ01p+MLK0eKLRP2qkf2RNb78zOH+wzBJ/NU SDmI3XG5m+sqDqr++bCao+qvJSgULkFeaMdNWR0gVUdg9PWA8Mc54SmawGOcI6Ife+np AJog== 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; bh=UZZytj2Vj4ZuZMBRZVR+fXxjadcydCJDoP75Zv47RfY=; b=mf0S8kSQZU8vNkrpnO+xnU+QHz/7DZyfLgJgJXZcQvAgUmatHrkpGSJWYl8Tp6krkm VLVPdZ/+ibqqPKvv31iKOHgLfs3NXPrw0lBVBPfxqG043okpRr8TLZc61elazTdpV3MI qfseLetMKY7W9fQgM6kOfFviISof6WfT/2ojFC3lzWgenxiaUrpB0m7MZNadqTFdlbPq JJRXnYKRnhBf/hnN66VPDd3hB+LZe+c2GmXjNiAEhf2ommXM1zYGk2+u+HYL+7zzl/1O 547aH505kV3sWXkoAM+LWakG3oMi/xWjnRcYiqJl9Pd0C3rUu6F3f/S56SB9VlOtg2Ft XfCg== X-Gm-Message-State: AA6/9RnbHKDsDA8J7oEooN3NQ+KcBC4jkV1a14RuyDcI4YcX6xXgkMUWybMkKRZtrjQ4NyuK X-Received: by 10.66.144.5 with SMTP id si5mr6765156pab.158.1475603343096; Tue, 04 Oct 2016 10:49:03 -0700 (PDT) Received: from jmattson.sea.corp.google.com ([100.100.206.154]) by smtp.gmail.com with ESMTPSA id x190sm56809313pfx.21.2016.10.04.10.49.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Oct 2016 10:49:02 -0700 (PDT) From: Jim Mattson To: kvm@vger.kernel.org Cc: Jim Mattson Subject: [PATCH] kvm: nVMX: Update MSR load counts on a VMCS switch Date: Tue, 4 Oct 2016 10:48:38 -0700 Message-Id: <1475603318-559-1-git-send-email-jmattson@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When L0 establishes (or removes) an MSR entry in the VM-entry or VM-exit MSR load lists, the change should affect the dormant VMCS as well as the current VMCS. Moreover, the vmcs02 MSR-load addresses should be initialized. Signed-off-by: Jim Mattson --- arch/x86/kvm/vmx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 5cede40..bb60515 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -9928,6 +9928,15 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) vmx_set_constant_host_state(vmx); /* + * Set the MSR load/store lists to match L0's settings. + */ + vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0); + vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr); + vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host)); + vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr); + vmcs_write64(VM_ENTRY_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.guest)); + + /* * HOST_RSP is normally set correctly in vmx_vcpu_run() just before * entry, but only if the current (host) sp changed from the value * we wrote last (vmx->host_rsp). This cache is no longer relevant @@ -10754,6 +10763,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, load_vmcs12_host_state(vcpu, vmcs12); /* Update any VMCS fields that might have changed while L2 ran */ + vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr); + vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr); vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset); if (vmx->hv_deadline_tsc == -1) vmcs_clear_bits(PIN_BASED_VM_EXEC_CONTROL,