From patchwork Wed Jan 2 19:25:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10746645 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 1C04714E2 for ; Wed, 2 Jan 2019 19:25:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F148127F98 for ; Wed, 2 Jan 2019 19:25:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E21DD27FA9; Wed, 2 Jan 2019 19:25:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 8DD7A27F98 for ; Wed, 2 Jan 2019 19:25:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729289AbfABTZq (ORCPT ); Wed, 2 Jan 2019 14:25:46 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:36018 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728918AbfABTZq (ORCPT ); Wed, 2 Jan 2019 14:25:46 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x02JJHb1188604; Wed, 2 Jan 2019 19:25:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=43EbTJa4K/9IhY1ZpQFgoJtpgdcPdZR6ZTXdTrFlNmg=; b=Sl8hyy6vOVLRsHQihw6/Coi0oHwlW2fx5oLA+Y5+TkDN7dYgu4+H5NMQ8KcLUplbk7bF btJLhXy5cM3/8LLIe0r1momdrXEfzjneyANUKnZ9fSu35Ro9cYyF7Vu6tQTOaZpLBSW/ 0LZJRdewSXx99isiQoeaM+FM1soO0jwPtOgQA0rpzebhg9m4NBdEVmotrljVq84L4gMa /6TemOgtEYDGCAWX1+ocjzF1w/rXaKH+vHL6a7aRJKLGsaiD/RsqHOrGI5Tr7FCvKXkU YvRv7bOvW9Gu7pBUI22SUohfqAf1zAte0sfIK1OHHKNSuOTyiQ33LIhj2hGh9nekM7YY Og== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2pnxee3t30-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Jan 2019 19:25:42 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x02JPfmk018923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Jan 2019 19:25:41 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x02JPfJM022123; Wed, 2 Jan 2019 19:25:41 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Jan 2019 11:25:40 -0800 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, boris.ostrovsky@oracle.com, Liran Alon Subject: [PATCH] KVM: x86: Do not raise #GP on write to MSR_IA32_MCG_CTL which is not 0 or all 1s Date: Wed, 2 Jan 2019 21:25:22 +0200 Message-Id: <20190102192522.13158-1-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9124 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=793 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901020171 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Only 0 or all 1s can be written to IA32_MCG_CTL. SDM specifies other values as undefined and/or implementation specific. However, some guest kernels write different values. One such example is WinNT 4 SP6 which uses a value of 0xffffffff. Prefer to silently accept these writes to avoid an uncatched #GP in the guest. We will define our implementation specific behaviour as any value other than 0 to be treated as all 1s. Reviewed-by: Boris Ostrovsky Signed-off-by: Liran Alon --- arch/x86/kvm/x86.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 02c8e095a239..a06e4e892a9d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2287,9 +2287,21 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (!(mcg_cap & MCG_CTL_P) && (data || !msr_info->host_initiated)) return 1; - if (data != 0 && data != ~(u64)0) - return 1; - vcpu->arch.mcg_ctl = data; + /* + * Only 0 or all 1s can be written to IA32_MCG_CTL. + * SDM specifies other values as undefined and/or + * implementation specific. + * + * However, some guest kernels write different values. + * One such example is WinNT 4 SP6 which uses a value + * of 0xffffffff. + * + * Prefer to silently accept these writes to avoid an + * uncatched #GP in the guest. We will define our + * implementation specific behaviour as any value + * other than 0 to be treated as all 1s. + */ + vcpu->arch.mcg_ctl = data ? ~(u64)0 : 0; break; default: if (msr >= MSR_IA32_MC0_CTL &&