From patchwork Mon Jul 3 15:23:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9823631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B83BE60353 for ; Mon, 3 Jul 2017 15:24:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7CF922B27 for ; Mon, 3 Jul 2017 15:24:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C16626E98; Mon, 3 Jul 2017 15:24:19 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 EDCA727FA6 for ; Mon, 3 Jul 2017 15:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754492AbdGCPYP (ORCPT ); Mon, 3 Jul 2017 11:24:15 -0400 Received: from mga05.intel.com ([192.55.52.43]:38021 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbdGCPYO (ORCPT ); Mon, 3 Jul 2017 11:24:14 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP; 03 Jul 2017 08:24:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,303,1496127600"; d="scan'208";a="106600062" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by orsmga002.jf.intel.com with ESMTP; 03 Jul 2017 08:24:11 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Paolo Bonzini , Marcelo Tosatti , Richard Henderson , Eduardo Habkost , Haozhong Zhang Subject: [PATCH] i386/kvm: mask MSR_IA32_BNDCFGS if MPX is not enabled in guest cpuid Date: Mon, 3 Jul 2017 23:23:38 +0800 Message-Id: <20170703152338.20024-1-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Otherwise, QEMU on a host with MPX support will try to set guest MSR_IA32_BNDCFGS although guest MPX is not enabled, and result in abort. For example, qemu-system-x86_64 -enable-kvm -cpu qemu64,-mpx ... aborts with messages: qemu-system-x86_64: error: failed to set MSR 0xd90 to 0x0 qemu-system-x86_64: /root/qemu.git/target/i386/kvm.c:1832: kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed Signed-off-by: Haozhong Zhang --- target/i386/kvm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index ee36502789..7b3a310a31 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -943,6 +943,11 @@ int kvm_arch_init_vcpu(CPUState *cs) has_msr_mcg_ext_ctl = has_msr_feature_control = true; } + if (has_msr_bndcfgs) { + c = cpuid_find_entry(&cpuid_data.cpuid, 7, 0); + has_msr_bndcfgs = c && (c->ebx & CPUID_7_0_EBX_MPX); + } + if (!env->user_tsc_khz) { if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) && invtsc_mig_blocker == NULL) {