Skip to content

Commit db3e732

Browse files
ChangSeokBaesuryasaimadhu
authored andcommitted
x86/fpu: Add XFD handling for dynamic states
To handle the dynamic sizing of buffers on first use the XFD MSR has to be armed. Store the delta between the maximum available and the default feature bits in init_fpstate where it can be retrieved for task creation. If the delta is non zero then dynamic features are enabled. This needs also to enable the static key which guards the XFD updates. This is delayed to an initcall because the FPU setup runs before jump labels are initialized. Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2ae996e commit db3e732

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,12 @@ static void __init fpu__init_disable_system_xstate(unsigned int legacy_size)
835835
fpu_user_cfg.max_size = legacy_size;
836836
fpu_user_cfg.default_size = legacy_size;
837837

838+
/*
839+
* Prevent enabling the static branch which enables writes to the
840+
* XFD MSR.
841+
*/
842+
init_fpstate.xfd = 0;
843+
838844
fpstate_reset(&current->thread.fpu);
839845
}
840846

@@ -918,6 +924,14 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
918924
/* Store it for paranoia check at the end */
919925
xfeatures = fpu_kernel_cfg.max_features;
920926

927+
/*
928+
* Initialize the default XFD state in initfp_state and enable the
929+
* dynamic sizing mechanism if dynamic states are available. The
930+
* static key cannot be enabled here because this runs before
931+
* jump_label_init(). This is delayed to an initcall.
932+
*/
933+
init_fpstate.xfd = fpu_user_cfg.max_features & XFEATURE_MASK_USER_DYNAMIC;
934+
921935
/* Enable xstate instructions to be able to continue with initialization: */
922936
fpu__init_cpu_xstate();
923937
err = init_xstate_size();
@@ -1466,9 +1480,21 @@ void xfd_validate_state(struct fpstate *fpstate, u64 mask, bool rstor)
14661480
}
14671481
#endif /* CONFIG_X86_DEBUG_FPU */
14681482

1483+
static int __init xfd_update_static_branch(void)
1484+
{
1485+
/*
1486+
* If init_fpstate.xfd has bits set then dynamic features are
1487+
* available and the dynamic sizing must be enabled.
1488+
*/
1489+
if (init_fpstate.xfd)
1490+
static_branch_enable(&__fpu_state_size_dynamic);
1491+
return 0;
1492+
}
1493+
arch_initcall(xfd_update_static_branch)
1494+
14691495
void fpstate_free(struct fpu *fpu)
14701496
{
1471-
if (fpu->fpstate || fpu->fpstate != &fpu->__fpstate)
1497+
if (fpu->fpstate && fpu->fpstate != &fpu->__fpstate)
14721498
vfree(fpu->fpstate);
14731499
}
14741500

0 commit comments

Comments
 (0)