Skip to content

Commit 70c3f16

Browse files
ChangSeokBaesuryasaimadhu
authored andcommitted
x86/fpu/xstate: Prepare XSAVE feature table for gaps in state component numbers
The kernel checks at boot time which features are available by walking a XSAVE feature table which contains the CPUID feature bit numbers which need to be checked whether a feature is available on a CPU or not. So far the feature numbers have been linear, but AMX will create a gap which the current code cannot handle. Make the table entries explicitly indexed and adjust the loop code accordingly to prepare for that. No functional change. Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Len Brown <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 500afbf commit 70c3f16

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ static const char *xfeature_names[] =
5353
"unknown xstate feature" ,
5454
};
5555

56-
static short xsave_cpuid_features[] __initdata = {
57-
X86_FEATURE_FPU,
58-
X86_FEATURE_XMM,
59-
X86_FEATURE_AVX,
60-
X86_FEATURE_MPX,
61-
X86_FEATURE_MPX,
62-
X86_FEATURE_AVX512F,
63-
X86_FEATURE_AVX512F,
64-
X86_FEATURE_AVX512F,
65-
X86_FEATURE_INTEL_PT,
66-
X86_FEATURE_PKU,
67-
X86_FEATURE_ENQCMD,
56+
static unsigned short xsave_cpuid_features[] __initdata = {
57+
[XFEATURE_FP] = X86_FEATURE_FPU,
58+
[XFEATURE_SSE] = X86_FEATURE_XMM,
59+
[XFEATURE_YMM] = X86_FEATURE_AVX,
60+
[XFEATURE_BNDREGS] = X86_FEATURE_MPX,
61+
[XFEATURE_BNDCSR] = X86_FEATURE_MPX,
62+
[XFEATURE_OPMASK] = X86_FEATURE_AVX512F,
63+
[XFEATURE_ZMM_Hi256] = X86_FEATURE_AVX512F,
64+
[XFEATURE_Hi16_ZMM] = X86_FEATURE_AVX512F,
65+
[XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT,
66+
[XFEATURE_PKRU] = X86_FEATURE_PKU,
67+
[XFEATURE_PASID] = X86_FEATURE_ENQCMD,
6868
};
6969

7070
static unsigned int xstate_offsets[XFEATURE_MAX] __ro_after_init =
@@ -809,7 +809,10 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
809809
* Clear XSAVE features that are disabled in the normal CPUID.
810810
*/
811811
for (i = 0; i < ARRAY_SIZE(xsave_cpuid_features); i++) {
812-
if (!boot_cpu_has(xsave_cpuid_features[i]))
812+
unsigned short cid = xsave_cpuid_features[i];
813+
814+
/* Careful: X86_FEATURE_FPU is 0! */
815+
if ((i != XFEATURE_FP && !cid) || !boot_cpu_has(cid))
813816
fpu_kernel_cfg.max_features &= ~BIT_ULL(i);
814817
}
815818

0 commit comments

Comments
 (0)