From patchwork Sun Aug 18 18:23:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jinsong" X-Patchwork-Id: 268048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 154832C0155 for ; Mon, 19 Aug 2013 04:24:49 +1000 (EST) Received: from localhost ([::1]:39661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VB7eh-0007S4-10 for incoming@patchwork.ozlabs.org; Sun, 18 Aug 2013 14:24:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VB7eL-0007QA-RD for qemu-devel@nongnu.org; Sun, 18 Aug 2013 14:24:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VB7eH-00010Z-5K for qemu-devel@nongnu.org; Sun, 18 Aug 2013 14:24:25 -0400 Received: from mga11.intel.com ([192.55.52.93]:38682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VB7eG-00010Q-Qe for qemu-devel@nongnu.org; Sun, 18 Aug 2013 14:24:21 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 18 Aug 2013 11:24:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.89,908,1367996400"; d="scan'208,223";a="388135070" Received: from fmsmsx107.amr.corp.intel.com ([10.19.9.54]) by fmsmga002.fm.intel.com with ESMTP; 18 Aug 2013 11:24:07 -0700 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by FMSMSX107.amr.corp.intel.com (10.19.9.54) with Microsoft SMTP Server (TLS) id 14.3.123.3; Sun, 18 Aug 2013 11:24:06 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.123.3; Sun, 18 Aug 2013 11:24:06 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.99]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.227]) with mapi id 14.03.0123.003; Mon, 19 Aug 2013 02:23:58 +0800 From: "Liu, Jinsong" To: Gleb Natapov , Marcelo Tosatti , "qemu-devel@nongnu.org" , kvm Thread-Topic: [PATCH] qemu-kvm bugfix for IA32_FEATURE_CONTROL Thread-Index: Ac6cQBm0QHDz+EMsSVSuT6SEnPl11w== Date: Sun, 18 Aug 2013 18:23:57 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH] qemu-kvm bugfix for IA32_FEATURE_CONTROL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From 1273f8b2e5464ec987facf9942fd3ccc0b69087e Mon Sep 17 00:00:00 2001 From: Liu Jinsong Date: Mon, 19 Aug 2013 09:33:30 +0800 Subject: [PATCH] qemu-kvm bugfix for IA32_FEATURE_CONTROL This patch is to fix the bug https://bugs.launchpad.net/qemu-kvm/+bug/1207623 IA32_FEATURE_CONTROL is pointless if not expose VMX or SMX bits to cpuid.1.ecx of vcpu. Current qemu-kvm will error return when kvm_put_msrs or kvm_get_msrs. Signed-off-by: Liu Jinsong --- target-i386/kvm.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 84ac00a..7facbfe 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -65,6 +65,7 @@ static bool has_msr_star; static bool has_msr_hsave_pa; static bool has_msr_tsc_adjust; static bool has_msr_tsc_deadline; +static bool has_msr_feature_control; static bool has_msr_async_pf_en; static bool has_msr_pv_eoi_en; static bool has_msr_misc_enable; @@ -644,6 +645,11 @@ int kvm_arch_init_vcpu(CPUState *cs) qemu_add_vm_change_state_handler(cpu_update_state, env); + c = cpuid_find_entry(&cpuid_data.cpuid, 1, 0); + if (c) + has_msr_feature_control = !!(c->ecx & CPUID_EXT_VMX) | + !!(c->ecx & CPUID_EXT_SMX); + cpuid_data.cpuid.padding = 0; r = kvm_vcpu_ioctl(cs, KVM_SET_CPUID2, &cpuid_data); if (r) { @@ -1121,7 +1127,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level) if (hyperv_vapic_recommended()) { kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0); } - kvm_msr_entry_set(&msrs[n++], MSR_IA32_FEATURE_CONTROL, env->msr_ia32_feature_control); + if (has_msr_feature_control) { + kvm_msr_entry_set(&msrs[n++], MSR_IA32_FEATURE_CONTROL, + env->msr_ia32_feature_control); + } } if (env->mcg_cap) { int i; @@ -1346,7 +1355,9 @@ static int kvm_get_msrs(X86CPU *cpu) if (has_msr_misc_enable) { msrs[n++].index = MSR_IA32_MISC_ENABLE; } - msrs[n++].index = MSR_IA32_FEATURE_CONTROL; + if (has_msr_feature_control) { + msrs[n++].index = MSR_IA32_FEATURE_CONTROL; + } if (!env->tsc_valid) { msrs[n++].index = MSR_IA32_TSC; @@ -1447,6 +1458,7 @@ static int kvm_get_msrs(X86CPU *cpu) break; case MSR_IA32_FEATURE_CONTROL: env->msr_ia32_feature_control = msrs[i].data; + break; default: if (msrs[i].index >= MSR_MC0_CTL && msrs[i].index < MSR_MC0_CTL + (env->mcg_cap & 0xff) * 4) {