Skip to content

Commit 71581ee

Browse files
yyu-intel-comsuryasaimadhu
authored andcommitted
x86/fpu/xstate: Introduce XSAVES supervisor states
Enable XSAVES supervisor states by setting MSR_IA32_XSS bits according to CPUID enumeration results. Also revise comments at various places. Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Yu-cheng Yu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Reviewed-by: Tony Luck <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 524bb73 commit 71581ee

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,14 @@ void fpu__init_cpu_xstate(void)
228228
* states can be set here.
229229
*/
230230
xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask_user());
231+
232+
/*
233+
* MSR_IA32_XSS sets supervisor states managed by XSAVES.
234+
*/
235+
if (boot_cpu_has(X86_FEATURE_XSAVES))
236+
wrmsrl(MSR_IA32_XSS, xfeatures_mask_supervisor());
231237
}
232238

233-
/*
234-
* Note that in the future we will likely need a pair of
235-
* functions here: one for user xstates and the other for
236-
* system xstates. For now, they are the same.
237-
*/
238239
static bool xfeature_enabled(enum xfeature xfeature)
239240
{
240241
return xfeatures_mask_all & BIT_ULL(xfeature);
@@ -625,9 +626,6 @@ static void do_extra_xstate_size_checks(void)
625626
* the size of the *user* states. If we use it to size a buffer
626627
* that we use 'XSAVES' on, we could potentially overflow the
627628
* buffer because 'XSAVES' saves system states too.
628-
*
629-
* Note that we do not currently set any bits on IA32_XSS so
630-
* 'XCR0 | IA32_XSS == XCR0' for now.
631629
*/
632630
static unsigned int __init get_xsaves_size(void)
633631
{
@@ -750,7 +748,12 @@ void __init fpu__init_system_xstate(void)
750748
cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
751749
xfeatures_mask_all = eax + ((u64)edx << 32);
752750

753-
/* Place supervisor features in xfeatures_mask_all here */
751+
/*
752+
* Find supervisor xstates supported by the processor.
753+
*/
754+
cpuid_count(XSTATE_CPUID, 1, &eax, &ebx, &ecx, &edx);
755+
xfeatures_mask_all |= ecx + ((u64)edx << 32);
756+
754757
if ((xfeatures_mask_user() & XFEATURE_MASK_FPSSE) != XFEATURE_MASK_FPSSE) {
755758
/*
756759
* This indicates that something really unexpected happened
@@ -810,6 +813,13 @@ void fpu__resume_cpu(void)
810813
*/
811814
if (boot_cpu_has(X86_FEATURE_XSAVE))
812815
xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask_user());
816+
817+
/*
818+
* Restore IA32_XSS. The same CPUID bit enumerates support
819+
* of XSAVES and MSR_IA32_XSS.
820+
*/
821+
if (boot_cpu_has(X86_FEATURE_XSAVES))
822+
wrmsrl(MSR_IA32_XSS, xfeatures_mask_supervisor());
813823
}
814824

815825
/*

0 commit comments

Comments
 (0)