From patchwork Thu Apr 16 16:41:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Serebrin X-Patchwork-Id: 6227111 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 298939F313 for ; Thu, 16 Apr 2015 16:41:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 559A6201BB for ; Thu, 16 Apr 2015 16:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 76D2D20154 for ; Thu, 16 Apr 2015 16:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751850AbbDPQlx (ORCPT ); Thu, 16 Apr 2015 12:41:53 -0400 Received: from mail-qg0-f50.google.com ([209.85.192.50]:32837 "EHLO mail-qg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751536AbbDPQlw (ORCPT ); Thu, 16 Apr 2015 12:41:52 -0400 Received: by qgdy78 with SMTP id y78so8587825qgd.0 for ; Thu, 16 Apr 2015 09:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=0F6nEJqqXaK7ZTVMcGH66NiMgkI9Q/EaYTnI6SBlPsg=; b=Ew/S7XfDzCiutknCYjWH1CSLPMARXNhdxYSeZ36RfudUboUQK6sN6bwu2MaQRjPOIs SMkogUpuYNLl3nCepQkkA85KCQdbtBgkRl1jerA1hOa+PBnZiZNTwOT66BcgRfU/BMSs QUukND0uTUgAAimv5kKxgqc4YC1wYxmJ42p58ctJgWzlnuuOh04pb65gxLGRBS6Zhz9D pRCp+OaHXvl9+bUPijUsILRdzPY2giwdRijfoWUtn9m7WMNYF+FoPn3pKiL4V/JziQmO a+BCVKNHWES0TrDKfRH6O6XZIbKf+Q5Em8AjTzhJp/ijzUYbsxL1BzJdWwGTyQj3/eIt iGLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=0F6nEJqqXaK7ZTVMcGH66NiMgkI9Q/EaYTnI6SBlPsg=; b=egcuUUlgEvzT50WzOU6RCjupl7vDYTjptlT2hS5vZk/U31Wet6TfWDOGn4UvGcS3Aw mC2t5keEKR7wyJeIvMkVgkQkyew0IcNSoVXg8Md/DIMK4dfHCfmeWSc2F46T2aeeFcAH Aztq7jALg4UZPuSuTXLY5W+JyTot2faRhI2Z0svOCWO6pxn93Z1oNyRKW9k6kronN5+D WZw4FJ4Lw5RrUl2+glsSwcp9wwNAUrt8nC1Q+XP7gctT6eE84XCcWrnslhr3TqUZla9j XKQJwWxk8VzCoY8y10Zp5HEAS9fhSZhVl/hQr3A96gwv/ZX3toFNebLu6GABJzGUAOvg BKKA== X-Gm-Message-State: ALoCoQlDckSXDvgTPN5PLP3RT036qoPxKmK78ZTsTR//qiLcU7od3av4r0fLNIj3OjM3LgYu9xYu MIME-Version: 1.0 X-Received: by 10.55.31.90 with SMTP id f87mr64160710qkf.38.1429202511217; Thu, 16 Apr 2015 09:41:51 -0700 (PDT) Received: by 10.229.120.201 with HTTP; Thu, 16 Apr 2015 09:41:51 -0700 (PDT) Date: Thu, 16 Apr 2015 09:41:51 -0700 Message-ID: Subject: [PATCH] vt-x: Preserve host CR4.MCE value while in guest mode. From: Benjamin Serebrin To: kvm@vger.kernel.org, stable@vger.kernel.org, luto@amacapital.net, pbonzini@redhat.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. 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(-) /* -- 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 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) {