mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-22 17:01:14 +00:00
x86/fpu: Reset MXCSR to default in kernel_fpu_begin()
Previously, kernel floating point code would run with the MXCSR control register value last set by userland code by the thread that was active on the CPU core just before kernel call. This could affect calculation results if rounding mode was changed, or a crash if a FPU/SIMD exception was unmasked. Restore MXCSR to the kernel's default value. [ bp: Carve out from a bigger patch by Petteri, add feature check, add FNINIT call too (amluto). ] Signed-off-by: Petteri Aimonen <jpa@git.mail.kapsi.fi> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://bugzilla.kernel.org/show_bug.cgi?id=207979 Link: https://lkml.kernel.org/r/20200624114646.28953-2-bp@alien8.de
This commit is contained in:
parent
48778464bb
commit
7ad816762f
2 changed files with 11 additions and 0 deletions
|
@ -623,6 +623,11 @@ static inline void switch_fpu_finish(struct fpu *new_fpu)
|
||||||
* MXCSR and XCR definitions:
|
* MXCSR and XCR definitions:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static inline void ldmxcsr(u32 mxcsr)
|
||||||
|
{
|
||||||
|
asm volatile("ldmxcsr %0" :: "m" (mxcsr));
|
||||||
|
}
|
||||||
|
|
||||||
extern unsigned int mxcsr_feature_mask;
|
extern unsigned int mxcsr_feature_mask;
|
||||||
|
|
||||||
#define XCR_XFEATURE_ENABLED_MASK 0x00000000
|
#define XCR_XFEATURE_ENABLED_MASK 0x00000000
|
||||||
|
|
|
@ -101,6 +101,12 @@ void kernel_fpu_begin(void)
|
||||||
copy_fpregs_to_fpstate(¤t->thread.fpu);
|
copy_fpregs_to_fpstate(¤t->thread.fpu);
|
||||||
}
|
}
|
||||||
__cpu_invalidate_fpregs_state();
|
__cpu_invalidate_fpregs_state();
|
||||||
|
|
||||||
|
if (boot_cpu_has(X86_FEATURE_XMM))
|
||||||
|
ldmxcsr(MXCSR_DEFAULT);
|
||||||
|
|
||||||
|
if (boot_cpu_has(X86_FEATURE_FPU))
|
||||||
|
asm volatile ("fninit");
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(kernel_fpu_begin);
|
EXPORT_SYMBOL_GPL(kernel_fpu_begin);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue