From patchwork Fri Nov 29 13:17:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jinsong" X-Patchwork-Id: 295312 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 423942C00C1 for ; Sat, 30 Nov 2013 00:18:19 +1100 (EST) Received: from localhost ([::1]:47306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmNxW-0005hH-9X for incoming@patchwork.ozlabs.org; Fri, 29 Nov 2013 08:18:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmNxC-0005h7-IA for qemu-devel@nongnu.org; Fri, 29 Nov 2013 08:17:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmNx7-0005vt-CO for qemu-devel@nongnu.org; Fri, 29 Nov 2013 08:17:54 -0500 Received: from mga11.intel.com ([192.55.52.93]:1836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmNx7-0005vl-3u for qemu-devel@nongnu.org; Fri, 29 Nov 2013 08:17:49 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 29 Nov 2013 05:17:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,798,1378882800"; d="scan'208,223";a="442023061" Received: from fmsmsx105.amr.corp.intel.com ([10.19.9.36]) by fmsmga002.fm.intel.com with ESMTP; 29 Nov 2013 05:17:46 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX105.amr.corp.intel.com (10.19.9.36) with Microsoft SMTP Server (TLS) id 14.3.123.3; Fri, 29 Nov 2013 05:17:46 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.57]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.235]) with mapi id 14.03.0123.003; Fri, 29 Nov 2013 21:17:44 +0800 From: "Liu, Jinsong" To: Paolo Bonzini , Gleb Natapov , "qemu-devel@nongnu.org" , kvm Thread-Topic: [PATCH 2/2] target-i386: Intel MPX support Thread-Index: Ac7tBWN96Ga8TgDCQpCXkNGmHodM3A== Date: Fri, 29 Nov 2013 13:17:43 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: 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 Cc: "haoxudong.hao@gmail.com" Subject: [Qemu-devel] [PATCH 2/2] target-i386: Intel MPX support 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 aac033473bc88befe39a9add99820c0a7118ac90 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Nov 2013 00:24:35 +0800 Subject: [PATCH 2/2] target-i386: Intel MPX support Expose cpuid leaf (0xd, 3) and (0xd, 4) to guest. Fix ebx and re-calculate ecx of cpuid leaf (0xd, 0). Signed-off-by: Liu Jinsong --- target-i386/cpu.c | 34 ++++++++++++++++++++++++++-------- target-i386/cpu.h | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) -- 1.7.1 diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 544b57f..7d04f28 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -330,12 +330,12 @@ X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = { typedef struct ExtSaveArea { uint32_t feature, bits; - uint32_t offset, size; } ExtSaveArea; static const ExtSaveArea ext_save_areas[] = { - [2] = { .feature = FEAT_1_ECX, .bits = CPUID_EXT_AVX, - .offset = 0x240, .size = 0x100 }, + [2] = { .feature = FEAT_1_ECX, .bits = CPUID_EXT_AVX }, + [3] = { .feature = FEAT_7_0_EBX, .bits = CPUID_7_0_EBX_MPX }, + [4] = { .feature = FEAT_7_0_EBX, .bits = CPUID_7_0_EBX_MPX }, }; const char *get_register_name_32(unsigned int reg) @@ -2204,9 +2204,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, ((uint64_t)kvm_arch_get_supported_cpuid(s, 0xd, 0, R_EDX) << 32); if (count == 0) { - *ecx = 0x240; + *ebx = *ecx = 0x240; for (i = 2; i < ARRAY_SIZE(ext_save_areas); i++) { + uint32_t offset, size; const ExtSaveArea *esa = &ext_save_areas[i]; + if ((env->features[esa->feature] & esa->bits) == esa->bits && (kvm_mask & (1 << i)) != 0) { if (i < 32) { @@ -2214,19 +2216,35 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } else { *edx |= 1 << (i - 32); } - *ecx = MAX(*ecx, esa->offset + esa->size); + + size = kvm_arch_get_supported_cpuid(s, 0xd, i, R_EAX); + offset = kvm_arch_get_supported_cpuid(s, 0xd, i, R_EBX); + *ecx = MAX(*ecx, offset + size); + + /* + * EBX here just in order to + * 1. keep compatible with old qemu version, take AVX + * into account; + * 2. keep compatible with old kernel version. Currently + * KVM has bug when expose cpuid 0xd to guest (include + * static value when guest booting and dynamic value + * when guest enables XCR0 features. EBX here can + * co-work with old buggy and new updated KVM, keep + * same value independent to CPU and kernel version. + */ + if (i == 2) + *ebx = MAX(*ebx, offset + size); } } *eax |= kvm_mask & (XSTATE_FP | XSTATE_SSE); - *ebx = *ecx; } else if (count == 1) { *eax = kvm_arch_get_supported_cpuid(s, 0xd, 1, R_EAX); } else if (count < ARRAY_SIZE(ext_save_areas)) { const ExtSaveArea *esa = &ext_save_areas[count]; if ((env->features[esa->feature] & esa->bits) == esa->bits && (kvm_mask & (1 << count)) != 0) { - *eax = esa->size; - *ebx = esa->offset; + *eax = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EAX); + *ebx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EBX); } } break; diff --git a/target-i386/cpu.h b/target-i386/cpu.h index ea373e8..9a838d1 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -545,6 +545,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_7_0_EBX_ERMS (1 << 9) #define CPUID_7_0_EBX_INVPCID (1 << 10) #define CPUID_7_0_EBX_RTM (1 << 11) +#define CPUID_7_0_EBX_MPX (1 << 14) #define CPUID_7_0_EBX_RDSEED (1 << 18) #define CPUID_7_0_EBX_ADX (1 << 19) #define CPUID_7_0_EBX_SMAP (1 << 20)