Skip to contentSkip to conversation

x86/xstate: Don't special case feature collection

PATCH In review Andrew Cooper 2 participants 3 messages Feb 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/xstate: Don't special case feature collection

The logic in xstate_init() is a rementent of the pre-featuremask days. Collect the xstate features in generic_identify(), like all other feature leaves, after which identify_cpu() will apply the known_feature[] mask derived from the automatically generated CPUID information.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/cpu/common.c |  4 ++++
 xen/arch/x86/xstate.c     | 13 -------------
 2 files changed, 4 insertions(+), 13 deletions(-)
xen/arch/x86/cpu/common.c +4 -0
index de6c5c9..8090131 100644
@@ -414,6 +414,10 @@ static void generic_identify(struct cpuinfo_x86 *c)
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_FSGSBASE)],
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_PKU)],
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_AVX512_4VNNIW)]);
+	if ( c->cpuid_level >= 0xd )
+		cpuid_count(0xd, 1,
+			    &c->x86_capability[cpufeat_word(X86_FEATURE_XSAVEOPT)],
+			    &tmp, &tmp, &tmp);
 }
 
 /*
xen/arch/x86/xstate.c +0 -13
index 15edd5d..858d1a6 100644
@@ -628,19 +628,6 @@ void xstate_init(struct cpuinfo_x86 *c)
         BUG_ON(xsave_cntxt_size != _xstate_ctxt_size(feature_mask));
     }
 
-    /* Check extended XSAVE features. */
-    cpuid_count(XSTATE_CPUID, 1, &eax, &ebx, &ecx, &edx);
-
-    /* Mask out features not currently understood by Xen. */
-    eax &= (cpufeat_mask(X86_FEATURE_XSAVEOPT) |
-            cpufeat_mask(X86_FEATURE_XSAVEC) |
-            cpufeat_mask(X86_FEATURE_XGETBV1) |
-            cpufeat_mask(X86_FEATURE_XSAVES));
-
-    c->x86_capability[cpufeat_word(X86_FEATURE_XSAVEOPT)] = eax;
-
-    BUG_ON(eax != boot_cpu_data.x86_capability[cpufeat_word(X86_FEATURE_XSAVEOPT)]);
-
     if ( setup_xstate_features(bsp) && bsp )
         BUG();
 }
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw

xen/arch/x86/cpu/common.c static void generic_identify(struct cpuinfo_x86 *c) · line 420

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 25.02.19 at 16:03, <[email protected]> wrote:
xen/arch/x86/cpu/common.c +4 -0
@@ -414,6 +414,10 @@ static void generic_identify(struct cpuinfo_x86 *c)
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_FSGSBASE)],
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_PKU)],
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_AVX512_4VNNIW)]);
+	if ( c->cpuid_level >= 0xd )
+		cpuid_count(0xd, 1,
+			    &c->x86_capability[cpufeat_word(X86_FEATURE_XSAVEOPT)],
+			    &tmp, &tmp, &tmp);

I think this file is still trying to be Linux style, with a couple of violations. I do notice that the immediately preceding if() is the same style as the one you add, but I think it would be more consistent to omit the blanks immediately inside the parentheses here. Either way,

I take it that you're intentionally using 0xd in favor of XSTATE_CPUID?

As an aside I wonder why we have cpuid_count_ebx(), but not e.g. cpuid_count_eax() as would have been useful here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 16 lines · Jan Beulich

xen/arch/x86/cpu/common.c static void generic_identify(struct cpuinfo_x86 *c) · line 420

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 25.02.19 at 16:03, <[email protected]> wrote:
xen/arch/x86/cpu/common.c +4 -0
@@ -414,6 +414,10 @@ static void generic_identify(struct cpuinfo_x86 *c)
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_FSGSBASE)],
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_PKU)],
 			    &c->x86_capability[cpufeat_word(X86_FEATURE_AVX512_4VNNIW)]);
+	if ( c->cpuid_level >= 0xd )
+		cpuid_count(0xd, 1,
+			    &c->x86_capability[cpufeat_word(X86_FEATURE_XSAVEOPT)],
+			    &tmp, &tmp, &tmp);

I think this file is still trying to be Linux style, with a couple of violations. I do notice that the immediately preceding if() is the same style as the one you add, but I think it would be more consistent to omit the blanks immediately inside the parentheses here.

/sigh - will fix.

Quoted 5 lines

Either way,

I take it that you're intentionally using 0xd in favor of XSTATE_CPUID?

XSTATE_CPUID is a bit of an oddity.  CPUID leaves are much more commonly referred to in their numeric form, both in the documentation and in technical discussion.  A specific bonus of using 0xd here is that you can trivially confirm that it is checked against the correct cpuid_level.

Quoted 2 lines

As an aside I wonder why we have cpuid_count_ebx(), but not e.g. cpuid_count_eax() as would have been useful here.

Pass.  I don't find those helpers terribly helpful, because they almost always lead (over time) to redundant invocations of CPUID.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel