From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 2/2] x86/HVM: don't calculate XSTATE area sizes in software Date: Wed, 01 Jun 2016 09:06:32 -0600 Message-ID: <574F161802000078000F07FD@prv-mh.provo.novell.com> References: <574F13FB02000078000F07D9@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part605674E8.1__=" Return-path: 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 In-Reply-To: <574F13FB02000078000F07D9@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper , Wei Liu List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part605674E8.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 =20 switch ( input ) { - unsigned int sub_leaf, _eax, _ebx, _ecx, _edx; + unsigned int _ecx, _edx; =20 case 0x1: /* Fix up VLAPIC details. */ @@ -3440,42 +3440,24 @@ void hvm_cpuid(unsigned int input, unsig *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } - /* EBX value of main leaf 0 depends on enabled xsave features */ - if ( count =3D=3D 0 && v->arch.xcr0 )=20 - { - /* reset EBX to default value first */ - *ebx =3D XSTATE_AREA_MIN_SIZE;=20 - for ( sub_leaf =3D 2; sub_leaf < 63; sub_leaf++ ) - { - if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) ) - continue; - domain_cpuid(d, input, sub_leaf, &_eax, &_ebx, &_ecx,=20 - &_edx); - if ( (_eax + _ebx) > *ebx ) - *ebx =3D _eax + _ebx; - } - } - - if ( count =3D=3D 1 ) + switch ( count ) { + case 1: *eax &=3D hvm_featureset[FEATURESET_Da1]; - - if ( *eax & cpufeat_mask(X86_FEATURE_XSAVES) ) + if ( !(*eax & cpufeat_mask(X86_FEATURE_XSAVES)) ) { - uint64_t xfeatures =3D v->arch.xcr0 | v->arch.hvm_vcpu.msr= _xss; - - *ebx =3D XSTATE_AREA_MIN_SIZE; - if ( xfeatures & ~XSTATE_FP_SSE ) - for ( sub_leaf =3D 2; sub_leaf < 63; sub_leaf++ ) - if ( xfeatures & (1ULL << sub_leaf) ) - { - if ( test_bit(sub_leaf, &xstate_align) ) - *ebx =3D ROUNDUP(*ebx, 64); - *ebx +=3D xstate_sizes[sub_leaf]; - } - } - else *ebx =3D *ecx =3D *edx =3D 0; + break; + } + /* fall through */ + case 0: + /* + * Always read CPUID.0xD[ECX=3D0/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; =20 --=__Part605674E8.1__= Content-Type: text/plain; name="x86-HVM-xstate-CPUID-simplify.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HVM-xstate-CPUID-simplify.patch" x86/HVM: don't calculate XSTATE area sizes in software=0A=0AUse hardware = output instead, brining HVM behavior in line with PV one=0Ain this = regard.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/hvm/hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@@ -3362,7 = +3362,7 @@ void hvm_cpuid(unsigned int input, unsig=0A =0A switch ( = input )=0A {=0A- unsigned int sub_leaf, _eax, _ebx, _ecx, = _edx;=0A+ unsigned int _ecx, _edx;=0A =0A case 0x1:=0A = /* Fix up VLAPIC details. */=0A@@ -3440,42 +3440,24 @@ void hvm_cpuid(unsig= ned int input, unsig=0A *eax =3D *ebx =3D *ecx =3D *edx =3D = 0;=0A break;=0A }=0A- /* EBX value of main leaf = 0 depends on enabled xsave features */=0A- if ( count =3D=3D 0 && = v->arch.xcr0 ) =0A- {=0A- /* reset EBX to default value = first */=0A- *ebx =3D XSTATE_AREA_MIN_SIZE; =0A- for = ( sub_leaf =3D 2; sub_leaf < 63; sub_leaf++ )=0A- {=0A- = if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) )=0A- = continue;=0A- domain_cpuid(d, input, sub_leaf, &_eax, = &_ebx, &_ecx, =0A- &_edx);=0A- = if ( (_eax + _ebx) > *ebx )=0A- *ebx =3D _eax + = _ebx;=0A- }=0A- }=0A-=0A- if ( count =3D=3D 1 = )=0A+ switch ( count )=0A {=0A+ case 1:=0A = *eax &=3D hvm_featureset[FEATURESET_Da1];=0A-=0A- if ( *eax & = cpufeat_mask(X86_FEATURE_XSAVES) )=0A+ if ( !(*eax & cpufeat_mas= k(X86_FEATURE_XSAVES)) )=0A {=0A- uint64_t = xfeatures =3D v->arch.xcr0 | v->arch.hvm_vcpu.msr_xss;=0A-=0A- = *ebx =3D XSTATE_AREA_MIN_SIZE;=0A- if ( xfeatures & = ~XSTATE_FP_SSE )=0A- for ( sub_leaf =3D 2; sub_leaf < = 63; sub_leaf++ )=0A- if ( xfeatures & (1ULL << = sub_leaf) )=0A- {=0A- if = ( test_bit(sub_leaf, &xstate_align) )=0A- = *ebx =3D ROUNDUP(*ebx, 64);=0A- *ebx +=3D = xstate_sizes[sub_leaf];=0A- }=0A- }=0A- = else=0A *ebx =3D *ecx =3D *edx =3D 0;=0A+ = break;=0A+ }=0A+ /* fall through */=0A+ = case 0:=0A+ /*=0A+ * Always read CPUID.0xD[ECX=3D0= /1].EBX from hardware, rather than=0A+ * domain policy. It = varies with enabled xstate, and the correct=0A+ * xcr0/xss are = in context.=0A+ */=0A+ cpuid_count(input, count, = &dummy, ebx, &dummy, &dummy);=0A+ break;=0A }=0A = break;=0A =0A --=__Part605674E8.1__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --=__Part605674E8.1__=--