From patchwork Wed Jun 1 15:06:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9147555 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 24BFF60761 for ; Wed, 1 Jun 2016 15:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1611F20410 for ; Wed, 1 Jun 2016 15:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AD5126B39; Wed, 1 Jun 2016 15:08:47 +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 878AF20410 for ; Wed, 1 Jun 2016 15:08:46 +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 1b87jD-0005zj-Ki; Wed, 01 Jun 2016 15:06:39 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b87jC-0005zU-70 for xen-devel@lists.xenproject.org; Wed, 01 Jun 2016 15:06:38 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id 3F/5A-10829-DF9FE475; Wed, 01 Jun 2016 15:06:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRWlGSWpSXmKPExsXS6fjDS/fPT79 wg3fnzSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozzD/cwFvzQq/g+ZxlrA+Nj2S5GTg4hgTyJ tjdfmUBsXgE7iWMtVxhBbAkBQ4l981exgdgsAqoSk7ceZgex2QTUJdqebWftYuTgEBEwkDh3N AkkzCwQKHHr/gywVmEBH4n7Xc+ZQUqEgEY+acsBCXMK2EtcubKDHSTMKyAo8XeHMESnncTL3h PMExh5ZiFkZiHJQNhaEg9/3WKBsLUlli18zQxSziwgLbH8HweE6SJxd68kqgoQ219i+4IWlgW MHKsY1YtTi8pSi3TN9ZKKMtMzSnITM3N0DQ1M9XJTi4sT01NzEpOK9ZLzczcxAsOUAQh2MB6b 7HyIUZKDSUmUN/ibX7gQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd62H0A5waLU9NSKtMwcYMTAp CU4eJREINK8xQWJucWZ6RCpU4yKUuK8nSAJAZBERmkeXBssSi8xykoJ8zICHSLEU5BalJtZgi r/ilGcg1FJmHcCyBSezLwSuOmvgBYzAS2Oz/ABWVySiJCSamDU+bd49gbWN9cKvn/xrI0+dbd W+UD/wrczJ35a1vKppcnycsHr1vPxM5QmtSdt21dd15huF+545EQrM3/6imMKLSpeOtpZdm2O W0S+ufLHmGyp31ny9ejsmoI9M9TismbtZ/PlyXi17lujj5uSqbTW7gaO3RVb7pw8sPzOL78t/ 488Y9r+4e5iJZbijERDLeai4kQAaXCW580CAAA= X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1464793594!6316852!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5828 invoked from network); 1 Jun 2016 15:06:36 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Jun 2016 15:06:36 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 01 Jun 2016 09:06:34 -0600 Message-Id: <574F161802000078000F07FD@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Wed, 01 Jun 2016 09:06:32 -0600 From: "Jan Beulich" To: "xen-devel" References: <574F13FB02000078000F07D9@prv-mh.provo.novell.com> In-Reply-To: <574F13FB02000078000F07D9@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper , Wei Liu Subject: [Xen-devel] [PATCH 2/2] x86/HVM: don't calculate XSTATE area sizes in software 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 Use hardware output instead, brining HVM behavior in line with PV one in this regard. Signed-off-by: Jan Beulich x86/HVM: don't calculate XSTATE area sizes in software Use hardware output instead, brining HVM behavior in line with PV one in this regard. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3362,7 +3362,7 @@ void hvm_cpuid(unsigned int input, unsig switch ( input ) { - unsigned int sub_leaf, _eax, _ebx, _ecx, _edx; + unsigned int _ecx, _edx; case 0x1: /* Fix up VLAPIC details. */ @@ -3440,42 +3440,24 @@ void hvm_cpuid(unsigned int input, unsig *eax = *ebx = *ecx = *edx = 0; break; } - /* EBX value of main leaf 0 depends on enabled xsave features */ - if ( count == 0 && v->arch.xcr0 ) - { - /* reset EBX to default value first */ - *ebx = XSTATE_AREA_MIN_SIZE; - for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ ) - { - if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) ) - continue; - domain_cpuid(d, input, sub_leaf, &_eax, &_ebx, &_ecx, - &_edx); - if ( (_eax + _ebx) > *ebx ) - *ebx = _eax + _ebx; - } - } - - if ( count == 1 ) + switch ( count ) { + case 1: *eax &= hvm_featureset[FEATURESET_Da1]; - - if ( *eax & cpufeat_mask(X86_FEATURE_XSAVES) ) + if ( !(*eax & cpufeat_mask(X86_FEATURE_XSAVES)) ) { - uint64_t xfeatures = v->arch.xcr0 | v->arch.hvm_vcpu.msr_xss; - - *ebx = XSTATE_AREA_MIN_SIZE; - if ( xfeatures & ~XSTATE_FP_SSE ) - for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ ) - if ( xfeatures & (1ULL << sub_leaf) ) - { - if ( test_bit(sub_leaf, &xstate_align) ) - *ebx = ROUNDUP(*ebx, 64); - *ebx += xstate_sizes[sub_leaf]; - } - } - else *ebx = *ecx = *edx = 0; + break; + } + /* fall through */ + case 0: + /* + * Always read CPUID.0xD[ECX=0/1].EBX from hardware, rather than + * domain policy. It varies with enabled xstate, and the correct + * xcr0/xss are in context. + */ + cpuid_count(input, count, &dummy, ebx, &dummy, &dummy); + break; } break; --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3362,7 +3362,7 @@ void hvm_cpuid(unsigned int input, unsig switch ( input ) { - unsigned int sub_leaf, _eax, _ebx, _ecx, _edx; + unsigned int _ecx, _edx; case 0x1: /* Fix up VLAPIC details. */ @@ -3440,42 +3440,24 @@ void hvm_cpuid(unsigned int input, unsig *eax = *ebx = *ecx = *edx = 0; break; } - /* EBX value of main leaf 0 depends on enabled xsave features */ - if ( count == 0 && v->arch.xcr0 ) - { - /* reset EBX to default value first */ - *ebx = XSTATE_AREA_MIN_SIZE; - for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ ) - { - if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) ) - continue; - domain_cpuid(d, input, sub_leaf, &_eax, &_ebx, &_ecx, - &_edx); - if ( (_eax + _ebx) > *ebx ) - *ebx = _eax + _ebx; - } - } - - if ( count == 1 ) + switch ( count ) { + case 1: *eax &= hvm_featureset[FEATURESET_Da1]; - - if ( *eax & cpufeat_mask(X86_FEATURE_XSAVES) ) + if ( !(*eax & cpufeat_mask(X86_FEATURE_XSAVES)) ) { - uint64_t xfeatures = v->arch.xcr0 | v->arch.hvm_vcpu.msr_xss; - - *ebx = XSTATE_AREA_MIN_SIZE; - if ( xfeatures & ~XSTATE_FP_SSE ) - for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ ) - if ( xfeatures & (1ULL << sub_leaf) ) - { - if ( test_bit(sub_leaf, &xstate_align) ) - *ebx = ROUNDUP(*ebx, 64); - *ebx += xstate_sizes[sub_leaf]; - } - } - else *ebx = *ecx = *edx = 0; + break; + } + /* fall through */ + case 0: + /* + * Always read CPUID.0xD[ECX=0/1].EBX from hardware, rather than + * domain policy. It varies with enabled xstate, and the correct + * xcr0/xss are in context. + */ + cpuid_count(input, count, &dummy, ebx, &dummy, &dummy); + break; } break;