Skip to content

Commit 76d1025

Browse files
Kan LiangIngo Molnar
authored andcommitted
x86/fpu/xstate: Fix an xstate size check warning with architectural LBRs
An xstate size check warning is triggered on machines which support Architectural LBRs. XSAVE consistency problem, dumping leaves WARNING: CPU: 0 PID: 0 at arch/x86/kernel/fpu/xstate.c:649 fpu__init_system_xstate+0x4d4/0xd0e Modules linked in: CPU: 0 PID: 0 Comm: swapper Not tainted intel-arch_lbr+ RIP: 0010:fpu__init_system_xstate+0x4d4/0xd0e The xstate size check routine, init_xstate_size(), compares the size retrieved from the hardware with the size of task->fpu, which is calculated by the software. The size from the hardware is the total size of the enabled xstates in XCR0 | IA32_XSS. Architectural LBR state is a dynamic supervisor feature, which sets the corresponding bit in the IA32_XSS at boot time. The size from the hardware includes the size of the Architectural LBR state. However, a dynamic supervisor feature doesn't allocate a buffer in the task->fpu. The size of task->fpu doesn't include the size of the Architectural LBR state. The mismatch will trigger the warning. Three options as below were considered to fix the issue: - Correct the size from the hardware by subtracting the size of the dynamic supervisor features. The purpose of the check is to compare the size CPU told with the size of the XSAVE buffer, which is calculated by the software. If the software mucks with the number from hardware, it removes the value of the check. This option is not a good option. - Prevent the hardware from counting the size of the dynamic supervisor feature by temporarily removing the corresponding bits in IA32_XSS. Two extra MSR writes are required to flip the IA32_XSS. The option is not pretty, but it is workable. The check is only called once at early boot time. The synchronization or context-switching doesn't need to be worried. This option is implemented here. - Remove the check entirely, because the check hasn't found any real problems. The option may be an alternative as option 2. This option is not implemented here. Add a new function, get_xsaves_size_no_dynamic(), which retrieves the total size without the dynamic supervisor features from the hardware. The size will be used to compare with the size of task->fpu. Fixes: f0dccc9 ("x86/fpu/xstate: Support dynamic supervisor feature for LBR") Reported-by: Chang S. Bae <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 52416ff commit 76d1025

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ static void check_xstate_against_struct(int nr)
611611
* This essentially double-checks what the cpu told us about
612612
* how large the XSAVE buffer needs to be. We are recalculating
613613
* it to be safe.
614+
*
615+
* Dynamic XSAVE features allocate their own buffers and are not
616+
* covered by these checks. Only the size of the buffer for task->fpu
617+
* is checked here.
614618
*/
615619
static void do_extra_xstate_size_checks(void)
616620
{
@@ -673,6 +677,33 @@ static unsigned int __init get_xsaves_size(void)
673677
return ebx;
674678
}
675679

680+
/*
681+
* Get the total size of the enabled xstates without the dynamic supervisor
682+
* features.
683+
*/
684+
static unsigned int __init get_xsaves_size_no_dynamic(void)
685+
{
686+
u64 mask = xfeatures_mask_dynamic();
687+
unsigned int size;
688+
689+
if (!mask)
690+
return get_xsaves_size();
691+
692+
/* Disable dynamic features. */
693+
wrmsrl(MSR_IA32_XSS, xfeatures_mask_supervisor());
694+
695+
/*
696+
* Ask the hardware what size is required of the buffer.
697+
* This is the size required for the task->fpu buffer.
698+
*/
699+
size = get_xsaves_size();
700+
701+
/* Re-enable dynamic features so XSAVES will work on them again. */
702+
wrmsrl(MSR_IA32_XSS, xfeatures_mask_supervisor() | mask);
703+
704+
return size;
705+
}
706+
676707
static unsigned int __init get_xsave_size(void)
677708
{
678709
unsigned int eax, ebx, ecx, edx;
@@ -710,7 +741,7 @@ static int __init init_xstate_size(void)
710741
xsave_size = get_xsave_size();
711742

712743
if (boot_cpu_has(X86_FEATURE_XSAVES))
713-
possible_xstate_size = get_xsaves_size();
744+
possible_xstate_size = get_xsaves_size_no_dynamic();
714745
else
715746
possible_xstate_size = xsave_size;
716747

0 commit comments

Comments
 (0)