From patchwork Wed Nov 21 00:24:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 10691473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D99C13AD for ; Wed, 21 Nov 2018 00:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F4E52AED1 for ; Wed, 21 Nov 2018 00:25:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00F9E2AEE1; Wed, 21 Nov 2018 00:25:07 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 9AEA82AED1 for ; Wed, 21 Nov 2018 00:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbeKUK47 (ORCPT ); Wed, 21 Nov 2018 05:56:59 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:37478 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbeKUK47 (ORCPT ); Wed, 21 Nov 2018 05:56:59 -0500 Received: by mail-pl1-f202.google.com with SMTP id v11so4557274ply.4 for ; Tue, 20 Nov 2018 16:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=qAPf5v8pxN0vjLBlfstzHTJZu8p+5R9MtKCIVlyD41c=; b=RBsbCFzU52AhtU7qGsyhzJi9ER0LCXE8/mGmI0ul3PtEHopF9QEVsEqncFGcUz9xBj iYQbxvDa3pUTnUvbsruwvraYTUzJtDZKo5YsgLKw0TkLRcjvMp1F6ramrW4HVtXuL0BF qDjaOl/E5URzcc7fOhUICFK1nXR6H8iAj/0pa4J5zTzpkqVU40BxzIX7MIzTclvpapYO ZAQL3nRa/yPdqzkkpj0S+0tNcsccaYJgwxmEin4ZZ0Ij7vjh/UkMhYzz1GlD1d91u5wh 3B5l8lZxT+LpzB8uV0cxBCZ0OR2VOUHUUF86ywW9s7qe3Vi8CUchhyHx0yFgSO45eHbV PLRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=qAPf5v8pxN0vjLBlfstzHTJZu8p+5R9MtKCIVlyD41c=; b=gKS2J166z5f+RB4Uu23mZ8uMfGhpfMoB1OnlPmWujPFrMLKQoFekOwxlZdl8F3I7m0 Sh6IcCC1sc4mduBt4taGtDh2sgey5W8YVa3ydFkS21jhnHGPNjjjqOjtdoKY7IRGpPot rAgxGAHtKNV8C9wyK1WqtSsuIMA+MvEj4UCDAkEtxg0BKy5JAbPcpKsaog4KXdu+t1lx xl67nrsuUr5zEeJG0a2Xsi6DPIJtSZhNVcMssDXYwBXDAV0n0BNGltCANH4k+XEL4scD bpqBcChfFsKyZjwrB3jkW9yoE1icERE4ASmWbQ+vTNoIQr79/XyB9CzRatcmxOdoAWxA kfzA== X-Gm-Message-State: AA+aEWZ08NKpSa244VbKgi/SNGvjLOTScVbKLv1fncj60nSgxj5shke0 3Z/jlidlhEpz4ZgrbR7f6dcaujHzkrnbLfAQH/3ugA3ejYyuseW+5v6jNf6/GiUXErKzaH/5AzQ PwVsGOZl0lLDxx4t6DP/QaWkau2h1lH0ehxAKEMXxlSQx62309hYoRjY1JCTUHcw= X-Google-Smtp-Source: AFSGD/WAAbVDVMzRThjGaMdaBRiw6kByracN8dkQQh+iKlQOaZUV7yGhYoFcY+t6tIR4j//McprAArLI/VttoQ== X-Received: by 2002:a63:780d:: with SMTP id t13mr1877184pgc.39.1542759905081; Tue, 20 Nov 2018 16:25:05 -0800 (PST) Date: Tue, 20 Nov 2018 16:24:57 -0800 Message-Id: <20181121002458.239673-1-jmattson@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog Subject: [PATCH 1/2] kvm: nVMX: NMI-window exiting should wake L2 from HLT From: Jim Mattson To: kvm@vger.kernel.org Cc: Jim Mattson , Peter Shier Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to the SDM, "NMI-window exiting" VM-exits wake a logical processor from the same inactive states as would an NMI. Specifically, they wake a logical processor from the shutdown state and from the states entered using the HLT and MWAIT instructions. Fixes: 6dfacadd5858 ("KVM: nVMX: Add support for activity state HLT") Signed-off-by: Jim Mattson Reviewed-by: Peter Shier --- arch/x86/kvm/vmx.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ccc6a01eb4f4..5f5c79e72a49 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -13421,6 +13421,17 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, return 1; } +static bool nested_vmx_nmi_window_exit(struct kvm_vcpu *vcpu) +{ + struct vmcs12 *vmcs12 = get_vmcs12(vcpu); + + return (vmcs12->cpu_based_vm_exec_control & + CPU_BASED_VIRTUAL_NMI_PENDING) && + vmcs12->guest_activity_state != GUEST_ACTIVITY_WAIT_SIPI && + !(vmcs12->guest_interruptibility_info & + (GUEST_INTR_STATE_NMI | GUEST_INTR_STATE_MOV_SS)); +} + /* * nested_vmx_run() handles a nested entry, i.e., a VMLAUNCH or VMRESUME on L1 * for running an L2 nested guest. @@ -13512,11 +13523,13 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) nested_cache_shadow_vmcs12(vcpu, vmcs12); /* - * If we're entering a halted L2 vcpu and the L2 vcpu won't be woken - * by event injection, halt vcpu. + * If we're entering a halted L2 vcpu and the L2 vcpu won't be + * awakened by event injection or by an NMI-window VM-exit, + * halt the vcpu. */ if ((vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT) && - !(vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK)) { + !(vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK) && + !nested_vmx_nmi_window_exit(vcpu)) { vmx->nested.nested_run_pending = 0; return kvm_vcpu_halt(vcpu); }