From patchwork Thu Apr 16 18:15:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Serebrin X-Patchwork-Id: 6227461 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C071FBF4A6 for ; Thu, 16 Apr 2015 18:15:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E369E2035C for ; Thu, 16 Apr 2015 18:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 000F720353 for ; Thu, 16 Apr 2015 18:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755084AbbDPSPj (ORCPT ); Thu, 16 Apr 2015 14:15:39 -0400 Received: from mail-ie0-f182.google.com ([209.85.223.182]:35517 "EHLO mail-ie0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755046AbbDPSPi (ORCPT ); Thu, 16 Apr 2015 14:15:38 -0400 Received: by iejt8 with SMTP id t8so57917433iej.2 for ; Thu, 16 Apr 2015 11:15:37 -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:in-reply-to:references; bh=wFVLQ0+91Ze2kgH+T9E2JcetvTl/LSAIFemKqYT89E4=; b=lPgJOri96w+X6uyx+qI8QdLAamCnUqgQkrikOOwkVThhC6JR7rr+d7L32jYm7Vo/nv ZJgGFErrN583tpH2+cVVQzVHz8c2zBOWTqNWh7LACijrh9ioJ1PvABGvU2S8EyqT2D9t JTNy0TgAGx2yBorRnJiRm9hrTqQ+LFf4Gi7Qcy6/2dVq/oSBYu4L8Q0p/mOQn3FoP1fO Raf6nOLMP7J/h04nze1+2nccb35qtPKM2z0xbGWfnIxmdpYbPAUG7xvp4DbjliCtv1qa QS9PVe5vQqPIPplVby+sghjoRTL/W0ROeC3g73oraLJE0zvs4zi5CTYiH9cZLnGfqwrb jPyw== 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:in-reply-to :references; bh=wFVLQ0+91Ze2kgH+T9E2JcetvTl/LSAIFemKqYT89E4=; b=bSllCr7v0vRyf/E4YOORmFCy4gLnU2s0qrDo8uOBaOiridi+PJXylq2BH9wRmsL36c /6J6nZP3Pz8nkB4sdvg1LgIHixQ6MSbRDVUncBJTKZ0LH21Y2+kjySGnczpIL+U9ApUI 6/bo4pXuOoC9AwKMzrfiHBSnysqazHZI5IIs0OuWArCXKyWod6tGGZqCJ+DMy1ZtffBI nOiYbtO1eTVtsGEYPTIiQW2+GFJZOLBSCZmWZe3q/y+eMsZmtXyxN6rYGRS80pH/CY2M gY9kvq2FBrkdJGq0c1PWVXcvBSVoL1PEMCwdwcMgE5xywMvTrakwNvf7p2PvjPpWYQLf uIqQ== X-Gm-Message-State: ALoCoQl2XftCONTbeBYE/I6cXSE6yGUmyj7DhuXAfk+TVf4J9J6AgwNUWUiBQ7tDDXRAg9Fv7uQY X-Received: by 10.50.138.68 with SMTP id qo4mr7344284igb.33.1429208137328; Thu, 16 Apr 2015 11:15:37 -0700 (PDT) Received: from serebrin.mtv.corp.google.com ([172.18.64.225]) by mx.google.com with ESMTPSA id cy11sm11795003igc.14.2015.04.16.11.15.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Apr 2015 11:15:36 -0700 (PDT) From: Ben Serebrin To: kvm@vger.kernel.org, stable@vger.kernel.org, luto@amacapital.net, pbonzini@redhat.com, jan.kiszka@siemens.com Cc: serebrin@google.com Subject: [PATCH] vt-x: Preserve host CR4.MCE value while in guest mode. Date: Thu, 16 Apr 2015 11:15:06 -0700 Message-Id: <1429208106-11759-1-git-send-email-serebrin@google.com> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <552FEAAD.6000600@siemens.com> References: <552FEAAD.6000600@siemens.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(-) 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) { /*