From patchwork Wed Jun 29 11:45:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luwei Kang X-Patchwork-Id: 9204993 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 EDB4F607D8 for ; Wed, 29 Jun 2016 11:47:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8AB328653 for ; Wed, 29 Jun 2016 11:47:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD4F128655; Wed, 29 Jun 2016 11:47:49 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 02A6928653 for ; Wed, 29 Jun 2016 11:47:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bIDw4-0006Ha-JR; Wed, 29 Jun 2016 11:45:40 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bIDw3-0006HR-EZ for xen-devel@lists.xen.org; Wed, 29 Jun 2016 11:45:39 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id FF/C8-07320-2E4B3775; Wed, 29 Jun 2016 11:45:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKKsWRWlGSWpSXmKPExsVywNwkVvfRluJ wg693eSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owNd88wFqxzqWh/voG5gfG3YRcjJ4eQQIXE 1YkPGUFsCQFeiSPLZrBC2CESPzrbWboYuYBqGhglzl7rZ4JwdjNKPHn2HMrZySjxb94pVghnD aPEpJsb2EH62QS0JJ7sfs4GYosImEtsXbKFEaSIWWAbo0Rj+zYgh4NDWMBM4vOtfJianR8/sU PYRhJfd/5hAbFZBFQl1k28DBbnFQiWuPN/ITPE3S4S9+dMBLubU8BV4tCFHrAaRgExie+n1jC B2MwC4hK3nsxngvhHQGLJnvPMELaoxMvH/6D+lJeYf/kb2J8SAkuZJS7OeQJVpCjxd30rI8Qg HYkFuz+xQdjaEssWvmaGOEhQ4uTMJywQBylKPJw5h30Co8wsJLtnIWmfhaR9FpL2BYwsqxjVi 1OLylKLdM30kooy0zNKchMzc3QNDUz1clOLixPTU3MSk4r1kvNzNzECo5sBCHYwTm1wPsQoyc GkJMqrn1ccLsSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCd/dmoJxgUWp6akVaZg4wzcCkJTh4lER 4P20CSvMWFyTmFmemQ6ROMSpKifNOBukTAElklObBtcFS2yVGWSlhXkagQ4R4ClKLcjNLUOVf MYpzMCoJ8zIBE6UQT2ZeCdz0V0CLmYAWM5eCLS5JREhJNTAumBjF5CcVHSPlXNispl7YufP8R pt7bgFNDSw3lx3KMdJVfb/+cMQKt+LTdoYP9h1qP2B5Xv7+pOzdZd1vm2a/0L8cdvbm0QC27m t/H4VOU1aeUpFy3/Ld9EVHpFmKy2fGbVRWLLu2b7bJDEXHCUXau0N7VQ5KVtt/1bSZt3dW0vb KqC/rxLOUWIozEg21mIuKEwF6zVUsaAMAAA== X-Env-Sender: luwei.kang@intel.com X-Msg-Ref: server-3.tower-206.messagelabs.com!1467200736!43927484!1 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40730 invoked from network); 29 Jun 2016 11:45:37 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-3.tower-206.messagelabs.com with SMTP; 29 Jun 2016 11:45:37 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 29 Jun 2016 04:45:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,546,1459839600"; d="scan'208,223";a="1007422223" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 29 Jun 2016 04:45:36 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 29 Jun 2016 04:45:35 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 29 Jun 2016 04:45:35 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.8]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.116]) with mapi id 14.03.0248.002; Wed, 29 Jun 2016 19:45:33 +0800 From: "Kang, Luwei" To: "xen-devel@lists.xen.org" Thread-Topic: [V3] x86/cpuid: AVX-512 Feature Detection Thread-Index: AQHR0flG4xUAff+qzEaB9rfa9iy9EKAAUI2A Date: Wed, 29 Jun 2016 11:45:32 +0000 Message-ID: <82D7661F83C1A047AF7DC287873BF1E136ADF46B@SHSMSX101.ccr.corp.intel.com> References: <1467199664-13676-1-git-send-email-luwei.kang@intel.com> In-Reply-To: <1467199664-13676-1-git-send-email-luwei.kang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_PUBLIC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjYyNzMwM2EtZDVmZi00MDVhLWE3MTQtYjQ1NGUyZTFjYzI5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX1BVQkxJQyJ9XX1dfSwiU3ViamVjdExhYmVscyI6W10sIlRNQ1ZlcnNpb24iOiIxNS45LjYuNiIsIlRydXN0ZWRMYWJlbEhhc2giOiJESlZpajBpQ24zaFRIekV1UjdCVGQzOUxaXC9QS1kweEpKXC9YYmFXb1BEUU09In0= x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Cc: "andrew.cooper3@citrix.com" , "Peng, Chao P" , "Wang, Yong Y" , "jbeulich@suse.com" Subject: Re: [Xen-devel] [V3] x86/cpuid: AVX-512 Feature Detection X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From table 2-2 I can see that AVX512F = AVX512F & AVX512VL AVX512CD = AVX512F & AVX512VL & AVX512CD AVX512DQ = AVX512F & AVX512VL & AVX512DQ AVX512BW = AVX512F & AVX512VL & AVX512BW AVX512IFMA = AVX512F & AVX512VL & AVX512IFMA AVX512VBMI = AVX512F & AVX512VL & AVX512VBMI From this depends list some AVX512 feature also depends on AVX512VL. So the depends may like this: AVX2: [AVX512F], AVX512F: [AVX512DQ, AVX512IFMA, AVX512CD, AVX512BW, AVX512VBMI], AVX512VL:[AVX512F, AVX512DQ, AVX512IFMA, AVX512CD, AVX512BW, AVX512VBMI] But I have test on current hardware, this machine support AVX512F, AVX512PF, AVX512ER and AVX512CD, do not support AVX512VL. I think there may have some conflict between spec and hardware. The depends about AVX512VL should not add, or the AVX512 feature will not work. So I think below depends is ok. AVX2: [AVX512F], AVX512F: [AVX512DQ, AVX512IFMA, AVX512PF, AVX512ER, AVX512CD, AVX512BW, AVX512VL, AVX512VBMI], Thanks, Luwei Kang -----Original Message----- From: Kang, Luwei Sent: Wednesday, June 29, 2016 7:28 PM To: xen-devel@lists.xen.org Cc: jbeulich@suse.com; andrew.cooper3@citrix.com; Wang, Yong Y ; Peng, Chao P ; Kang, Luwei Subject: [V3] x86/cpuid: AVX-512 Feature Detection AVX-512 is an extention of AVX2. Its spec can be found at: https://software.intel.com/sites/default/files/managed/b4/3a/319433-024.pdf This patch detects AVX-512 features by CPUID. Signed-off-by: Luwei Kang --- [V3] 1.adjust dependencies between features. [V2] 1.one per bit, change from > + xstate_size = max(xstate_size, > + xstate_offsets[_XSTATE_HI_ZMM] + > + xstate_sizes[_XSTATE_HI_ZMM]); to xstate_size = max(xstate_size, xstate_offsets[_XSTATE_OPMASK] + xstate_sizes[_XSTATE_OPMASK]); xstate_size = max(xstate_size, xstate_offsets[_XSTATE_ZMM] + xstate_sizes[_XSTATE_ZMM]); xstate_size = max(xstate_size, xstate_offsets[_XSTATE_HI_ZMM] + xstate_sizes[_XSTATE_HI_ZMM]); 2.change form domain_cpuid(currd, 0x07, 0, &tmp, &_ebx, &tmp, &tmp); to domain_cpuid(currd, 7, 0, &tmp, &_ebx, &tmp, &tmp); 3.add dependencies between features in xen/tools/gen-cpuid.py 4.split the cpuid call just like the way the hvm_cpuid() side works. xen/arch/x86/hvm/hvm.c | 14 ++++++++++++++ xen/arch/x86/traps.c | 22 +++++++++++++++++++++- xen/include/public/arch-x86/cpufeatureset.h | 9 +++++++++ xen/tools/gen-cpuid.py | 11 +++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index c89ab6e..7696b1e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3474,6 +3474,20 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, xstate_sizes[_XSTATE_BNDCSR]); } + if ( _ebx & cpufeat_mask(X86_FEATURE_AVX512F) ) + { + xfeature_mask |= XSTATE_OPMASK | XSTATE_ZMM | XSTATE_HI_ZMM; + xstate_size = max(xstate_size, + xstate_offsets[_XSTATE_OPMASK] + + xstate_sizes[_XSTATE_OPMASK]); + xstate_size = max(xstate_size, + xstate_offsets[_XSTATE_ZMM] + + xstate_sizes[_XSTATE_ZMM]); + xstate_size = max(xstate_size, + xstate_offsets[_XSTATE_HI_ZMM] + + xstate_sizes[_XSTATE_HI_ZMM]); + } + if ( _ecx & cpufeat_mask(X86_FEATURE_PKU) ) { xfeature_mask |= XSTATE_PKRU; diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 767d0b0..8fb697b 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -975,7 +975,7 @@ void pv_cpuid(struct cpu_user_regs *regs) switch ( leaf ) { - uint32_t tmp, _ecx; + uint32_t tmp, _ecx, _ebx; case 0x00000001: c &= pv_featureset[FEATURESET_1c]; @@ -1157,6 +1157,26 @@ void pv_cpuid(struct cpu_user_regs *regs) xstate_sizes[_XSTATE_YMM]); } + if ( !is_control_domain(currd) && !is_hardware_domain(currd) ) + domain_cpuid(currd, 7, 0, &tmp, &_ebx, &tmp, &tmp); + else + cpuid_count(7, 0, &tmp, &_ebx, &tmp, &tmp); + _ebx &= pv_featureset[FEATURESET_7b0]; + + if ( _ebx & cpufeat_mask(X86_FEATURE_AVX512F) ) + { + xfeature_mask |= XSTATE_OPMASK | XSTATE_ZMM | XSTATE_HI_ZMM; + xstate_size = max(xstate_size, + xstate_offsets[_XSTATE_OPMASK] + + xstate_sizes[_XSTATE_OPMASK]); + xstate_size = max(xstate_size, + xstate_offsets[_XSTATE_ZMM] + + xstate_sizes[_XSTATE_ZMM]); + xstate_size = max(xstate_size, + xstate_offsets[_XSTATE_HI_ZMM] + + xstate_sizes[_XSTATE_HI_ZMM]); + } + a = (uint32_t)xfeature_mask; d = (uint32_t)(xfeature_mask >> 32); c = xstate_size; diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h index 39acf8c..9320c9e 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -206,15 +206,24 @@ XEN_CPUFEATURE(PQM, 5*32+12) /* Platform QoS Monitoring */ XEN_CPUFEATURE(NO_FPU_SEL, 5*32+13) /*! FPU CS/DS stored as zero */ XEN_CPUFEATURE(MPX, 5*32+14) /*S Memory Protection Extensions */ XEN_CPUFEATURE(PQE, 5*32+15) /* Platform QoS Enforcement */ +XEN_CPUFEATURE(AVX512F, 5*32+16) /*A AVX-512 Foundation Instructions */ +XEN_CPUFEATURE(AVX512DQ, 5*32+17) /*A AVX-512 Doubleword & Quadword Instrs */ XEN_CPUFEATURE(RDSEED, 5*32+18) /*A RDSEED instruction */ XEN_CPUFEATURE(ADX, 5*32+19) /*A ADCX, ADOX instructions */ XEN_CPUFEATURE(SMAP, 5*32+20) /*S Supervisor Mode Access Prevention */ +XEN_CPUFEATURE(AVX512IFMA, 5*32+21) /*A AVX-512 Integer Fused Multiply Add */ XEN_CPUFEATURE(CLFLUSHOPT, 5*32+23) /*A CLFLUSHOPT instruction */ XEN_CPUFEATURE(CLWB, 5*32+24) /*A CLWB instruction */ +XEN_CPUFEATURE(AVX512PF, 5*32+26) /*A AVX-512 Prefetch Instructions */ +XEN_CPUFEATURE(AVX512ER, 5*32+27) /*A AVX-512 Exponent & Reciprocal Instrs */ +XEN_CPUFEATURE(AVX512CD, 5*32+28) /*A AVX-512 Conflict Detection Instrs */ XEN_CPUFEATURE(SHA, 5*32+29) /*A SHA1 & SHA256 instructions */ +XEN_CPUFEATURE(AVX512BW, 5*32+30) /*A AVX-512 Byte and Word Instructions */ +XEN_CPUFEATURE(AVX512VL, 5*32+31) /*A AVX-512 Vector Length Extensions */ /* Intel-defined CPU features, CPUID level 0x00000007:0.ecx, word 6 */ XEN_CPUFEATURE(PREFETCHWT1, 6*32+ 0) /*A PREFETCHWT1 instruction */ +XEN_CPUFEATURE(AVX512VBMI, 6*32+ 1) /*A AVX-512 Vector Byte Manipulation Instrs */ XEN_CPUFEATURE(PKU, 6*32+ 3) /*H Protection Keys for Userspace */ XEN_CPUFEATURE(OSPKE, 6*32+ 4) /*! OS Protection Keys Enable */ diff --git a/xen/tools/gen-cpuid.py b/xen/tools/gen-cpuid.py index 7c45eca..cf7bb67 100755 --- a/xen/tools/gen-cpuid.py +++ b/xen/tools/gen-cpuid.py @@ -243,6 +243,17 @@ def crunch_numbers(state): # AMD K6-2+ and K6-III processors shipped with 3DNow+, beyond the # standard 3DNow in the earlier K6 processors. _3DNOW: [_3DNOWEXT], + + # AVX2 is an extension to AVX, providing mainly new integer instructions. + # In principle, AVX512 only depends on YMM register state, but many AVX2 + # instructions are extended by AVX512F to 512-bit forms. + AVX2: [AVX512F], + + # AVX512F is taken to mean hardware support for EVEX encoded instructions, + # 512bit registers, and the instructions themselves. All further AVX512 features + # are built on top of AVX512F + AVX512F: [AVX512DQ, AVX512IFMA, AVX512PF, AVX512ER, AVX512CD, + AVX512BW, AVX512VL, AVX512VBMI], } deep_features = tuple(sorted(deps.keys()))