Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9979938ybi; Wed, 24 Jul 2019 13:27:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/vIxfVbYfYwXGs+V1G8YvlDoP6sC2YT/BE3OMdWsj5K4oAOGUvAn4qKyGjAzsuHzH4Rr6 X-Received: by 2002:a63:714a:: with SMTP id b10mr49825426pgn.25.1564000046557; Wed, 24 Jul 2019 13:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000046; cv=none; d=google.com; s=arc-20160816; b=fcstT0mmg5SM93kn8kCHGm8Nf+uxlK28jMjft6A3ALZYGZ6+wEQsZXgJ4yilCi/VUJ i9ly/N8EoaRNJzqG6WLt8W4XXfBel1pOVATXACqrDBPWWBSe/1dL9MUM4SlH/PvLwRV3 QJZm3xIOW1QEw5x8NYizCoAaBqVOLep4JeRiPgS6AiAxqhW3uP6H5bXW/8zGF6uV+4HK dszeVBd5Wjw2h8/f2YOJ3C/DtIuWclgqaZIP5qcqvkCNf1zFgbN9tSPidKw+Y3TwIohF KB5Y88ih6WeQXpM/3dh7gfdOXNPCzDyRdaOJOuJHjUP5KjZrQDOaxHqYVNra+KQxq+lG U8lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xL+kAgzD77QP5JabDKSjU3ovVfbxGCL8lui78Wa3Dog=; b=0+dOS9/pJExy7L0BT61xfQA+CAxWnaPzm0bZELxiTebGhRhPjRfTrRE+812OmI3Jaj mu3JQVNNO3bO0RjiRVGX0J/aozGbo6ygxhg8HP91onPQtkonXrqzunboCMvbzFL0+lpA Ys3JElvSArBlbCjBCZDSExTHNHH+8pov1J81av/zjOaII2+H33UUXChB3SdlmyphTImL KlNKZ0rBmumwg4zbyhW/y9zrHbjCI8Slmh7cmlqCO2kJGkWdkvL9MsdwjlDM/GeKKsNC RzqCdr4yhcKIrp32NW44Wy5hL8zwJg03SgboDC4mdi6gCEvNZlBk3FIbDCR/7EaVbFeK 9k/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RxFZy59V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si15850235pfo.108.2019.07.24.13.27.11; Wed, 24 Jul 2019 13:27:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RxFZy59V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389796AbfGXTix (ORCPT + 99 others); Wed, 24 Jul 2019 15:38:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:39608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389360AbfGXTis (ORCPT ); Wed, 24 Jul 2019 15:38:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6CCE0217D4; Wed, 24 Jul 2019 19:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997127; bh=RDfTuyx8Im7cNKgat8flDA5CdC/i7ij3ck4IM5BLh9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RxFZy59VCHO3fi2vBVJb5kqUpfC3f/5wU16yo9wtnGK90dTdGKG/kNwJYBBJ6/fRZ v/oNG5ZOZ4bYVDkrNhu9MKWkz035RFVJOYA6tDMyXia3m9Ty7LFJWKRdL4ogYUtNTw PeekeqmVwPJzqyN0QT9a9G0mzuaUJJgCfTQl+GYk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Jim Mattson , Paolo Bonzini Subject: [PATCH 5.2 329/413] KVM: VMX: Fix handling of #MC that occurs during VM-Entry Date: Wed, 24 Jul 2019 21:20:20 +0200 Message-Id: <20190724191759.391565357@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit beb8d93b3e423043e079ef3dda19dad7b28467a8 upstream. A previous fix to prevent KVM from consuming stale VMCS state after a failed VM-Entry inadvertantly blocked KVM's handling of machine checks that occur during VM-Entry. Per Intel's SDM, a #MC during VM-Entry is handled in one of three ways, depending on when the #MC is recognoized. As it pertains to this bug fix, the third case explicitly states EXIT_REASON_MCE_DURING_VMENTRY is handled like any other VM-Exit during VM-Entry, i.e. sets bit 31 to indicate the VM-Entry failed. If a machine-check event occurs during a VM entry, one of the following occurs: - The machine-check event is handled as if it occurred before the VM entry: ... - The machine-check event is handled after VM entry completes: ... - A VM-entry failure occurs as described in Section 26.7. The basic exit reason is 41, for "VM-entry failure due to machine-check event". Explicitly handle EXIT_REASON_MCE_DURING_VMENTRY as a one-off case in vmx_vcpu_run() instead of binning it into vmx_complete_atomic_exit(). Doing so allows vmx_vcpu_run() to handle VMX_EXIT_REASONS_FAILED_VMENTRY in a sane fashion and also simplifies vmx_complete_atomic_exit() since VMCS.VM_EXIT_INTR_INFO is guaranteed to be fresh. Fixes: b060ca3b2e9e7 ("kvm: vmx: Handle VMLAUNCH/VMRESUME failure properly") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Reviewed-by: Jim Mattson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/vmx.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6110,28 +6110,21 @@ static void vmx_apicv_post_state_restore static void vmx_complete_atomic_exit(struct vcpu_vmx *vmx) { - u32 exit_intr_info = 0; - u16 basic_exit_reason = (u16)vmx->exit_reason; - - if (!(basic_exit_reason == EXIT_REASON_MCE_DURING_VMENTRY - || basic_exit_reason == EXIT_REASON_EXCEPTION_NMI)) + if (vmx->exit_reason != EXIT_REASON_EXCEPTION_NMI) return; - if (!(vmx->exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY)) - exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO); - vmx->exit_intr_info = exit_intr_info; + vmx->exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO); /* if exit due to PF check for async PF */ - if (is_page_fault(exit_intr_info)) + if (is_page_fault(vmx->exit_intr_info)) vmx->vcpu.arch.apf.host_apf_reason = kvm_read_and_reset_pf_reason(); /* Handle machine checks before interrupts are enabled */ - if (basic_exit_reason == EXIT_REASON_MCE_DURING_VMENTRY || - is_machine_check(exit_intr_info)) + if (is_machine_check(vmx->exit_intr_info)) kvm_machine_check(); /* We need to handle NMIs before interrupts are enabled */ - if (is_nmi(exit_intr_info)) { + if (is_nmi(vmx->exit_intr_info)) { kvm_before_interrupt(&vmx->vcpu); asm("int $2"); kvm_after_interrupt(&vmx->vcpu); @@ -6534,6 +6527,9 @@ static void vmx_vcpu_run(struct kvm_vcpu vmx->idt_vectoring_info = 0; vmx->exit_reason = vmx->fail ? 0xdead : vmcs_read32(VM_EXIT_REASON); + if ((u16)vmx->exit_reason == EXIT_REASON_MCE_DURING_VMENTRY) + kvm_machine_check(); + if (vmx->fail || (vmx->exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY)) return;