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: 9823637 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 5E54360353 for ; Mon, 3 Jul 2017 15:28:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46C1928572 for ; Mon, 3 Jul 2017 15:28:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AF46285B8; Mon, 3 Jul 2017 15:28:07 +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=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C327F28572 for ; Mon, 3 Jul 2017 15:28:06 +0000 (UTC) Received: from localhost ([::1]:35863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS3Gf-0003eO-Ku for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Jul 2017 11:28:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS3D0-0000sE-Iu for qemu-devel@nongnu.org; Mon, 03 Jul 2017 11:24:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dS3Cy-0007ZP-0K for qemu-devel@nongnu.org; Mon, 03 Jul 2017 11:24:18 -0400 Received: from mga04.intel.com ([192.55.52.120]:26935) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dS3Cx-0007YR-OH for qemu-devel@nongnu.org; Mon, 03 Jul 2017 11:24:15 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 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 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 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [PATCH] i386/kvm: mask MSR_IA32_BNDCFGS if MPX is not enabled in guest cpuid X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Eduardo Habkost , kvm@vger.kernel.org, Marcelo Tosatti , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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) {