From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wanpeng Li Subject: Re: [PATCH] KVM: VMX: Preserve host CR4.MCE value while in guest mode. Date: Fri, 17 Apr 2015 13:10:07 +0800 Message-ID: <20150417051007.GA3080@kernel> References: <1429210685-19510-1-git-send-email-serebrin@google.com> Reply-To: Wanpeng Li Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, stable@vger.kernel.org, luto@amacapital.net, pbonzini@redhat.com, jankiszka@siemens.com, Wanpeng Li To: Ben Serebrin Return-path: Received: from mga09.intel.com ([134.134.136.24]:60438 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750900AbbDQF2P (ORCPT ); Fri, 17 Apr 2015 01:28:15 -0400 Content-Disposition: inline In-Reply-To: <1429210685-19510-1-git-send-email-serebrin@google.com> Sender: kvm-owner@vger.kernel.org List-ID: Hi Ben, On Thu, Apr 16, 2015 at 11:58:05AM -0700, Ben Serebrin wrote: >The host's decision to enable machine check exceptions should remain >in force during non-root mode. KVM was writing 0 to cr4 on VCPU reset >and passed a slightly-modified 0 to the vmcs.guest_cr4 value. > >Tested: Built. >On earlier version, tested by injecting machine check >while a guest is spinning. > >Before the change, if guest CR4.MCE==0, then the machine check is >escalated to Catastrophic Error (CATERR) and the machine dies. Could you point out which section of SDM describes that the machine check is escalated to a CATERR if CR4.MCE==0? Regards, Wanpeng Li >If guest CR4.MCE==1, then the machine check causes VMEXIT and is >handled normally by host Linux. After the change, injecting a machine >check causes normal Linux machine check handling. > >Signed-off-by: Ben Serebrin >--- > arch/x86/kvm/vmx.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > >diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >index f5e8dce..f7b6168 100644 >--- a/arch/x86/kvm/vmx.c >+++ b/arch/x86/kvm/vmx.c >@@ -3622,8 +3622,16 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) > > static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > { >- unsigned long hw_cr4 = cr4 | (to_vmx(vcpu)->rmode.vm86_active ? >- KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON); >+ /* >+ * Pass through host's Machine Check Enable value to hw_cr4, which >+ * is in force while we are in guest mode. Do not let guests control >+ * this bit, even if host CR4.MCE == 0. >+ */ >+ unsigned long hw_cr4 = >+ (cr4_read_shadow() & X86_CR4_MCE) | >+ (cr4 & ~X86_CR4_MCE) | >+ (to_vmx(vcpu)->rmode.vm86_active ? >+ KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON); > > if (cr4 & X86_CR4_VMXE) { > /* >-- >2.2.0.rc0.207.ga3a616c > >-- >To unsubscribe from this list: send the line "unsubscribe kvm" in >the body of a message to majordomo@vger.kernel.org >More majordomo info at http://vger.kernel.org/majordomo-info.html