From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH 2/2] x86/HVM: don't calculate XSTATE area sizes in software
Date: Wed, 01 Jun 2016 09:06:32 -0600 [thread overview]
Message-ID: <574F161802000078000F07FD@prv-mh.provo.novell.com> (raw)
In-Reply-To: <574F13FB02000078000F07D9@prv-mh.provo.novell.com>
[-- Attachment #1: Type: text/plain, Size: 2606 bytes --]
Use hardware output instead, brining HVM behavior in line with PV one
in this regard.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- 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;
[-- Attachment #2: x86-HVM-xstate-CPUID-simplify.patch --]
[-- Type: text/plain, Size: 2658 bytes --]
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 <jbeulich@suse.com>
--- 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;
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-06-01 15:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-01 14:57 [PATCH 0/2] x86: xstate CPUID guest output adjustments Jan Beulich
2016-06-01 15:05 ` [PATCH 1/2] x86: flush high xstate CPUID sub-leaves to zero Jan Beulich
2016-06-01 15:30 ` Andrew Cooper
2016-06-01 15:45 ` Wei Liu
2016-06-01 15:06 ` Jan Beulich [this message]
2016-06-01 15:35 ` [PATCH 2/2] x86/HVM: don't calculate XSTATE area sizes in software Andrew Cooper
2016-06-01 15:47 ` Wei Liu
2016-06-01 15:50 ` Jan Beulich
2016-06-01 15:57 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=574F161802000078000F07FD@prv-mh.provo.novell.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).