x86/fpu: FPU init code bugfixes
cover x86/fpu: FPU init code bugfixes
The function fpu__init_system() is executed before parse_early_param(). This causes wrong fpu configuration. In addition, there are three related issues:
1. XGETBV1 is enabled when noxsave is given
2. MPX is enabled when eagerfpu=off is given
3. AVX is enabled when eagerfpu=off is given
Issues 1 and 3 are existing bugs. Issue 2 is a fallout from the command-line parsing move.
The following four patches fix these issues.
yu-cheng yu (4):
x86/fpu: Fix early fpu command-line parsing.
x86/fpu: Disable XGETBV1 when no XSAVE.
x86/fpu: Disable MPX when eagerfpu is off.
x86/fpu: Disable AVX when eagerfpu is off.
arch/x86/include/asm/fpu/internal.h | 1 + arch/x86/include/asm/fpu/xstate.h | 11 +-- arch/x86/kernel/fpu/init.c | 161 +++++++++++++++++++----------------- arch/x86/kernel/fpu/xstate.c | 4 +- 4 files changed, 92 insertions(+), 85 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/4 x86/fpu: Fix early fpu command-line parsing
The function fpu__init_system() is executed before parse_early_param(). This causes wrong fpu configuration. This patch fixes this issue by parsing boot_command_line in the beginning of fpu__init_system().
With all four patches in this series, each parameter disables features as the following:
eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx
no387: fpu
nofxsr: fxsr, fxsropt, xmm
noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512, mpx, xgetbv1
noxsaveopt: xsaveopt
noxsaves: xsaves
--- arch/x86/kernel/fpu/init.c | 109 ++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 71 deletions(-)
arch/x86/kernel/fpu/init.c +38 -71
@@ -3,8 +3,11 @@*/ #include <asm/fpu/internal.h> #include <asm/tlbflush.h> +#include <asm/setup.h> +#include <asm/cmdline.h> #include <linux/sched.h> +#include <linux/init.h> /* * Initialize the TS bit in CR0 according to the style of context-switches
@@ -261,18 +264,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)*/ static enum {AUTO ,ENABLE ,DISABLE } eagerfpu =AUTO ; -static int __init eager_fpu_setup (char *s) -{ -if (!strcmp (s,"on" )) - eagerfpu =ENABLE ; -else if (!strcmp (s,"off" )) - eagerfpu =DISABLE ; -else if (!strcmp (s,"auto" )) - eagerfpu =AUTO ; -return 1 ; -} -__setup ("eagerfpu=" , eager_fpu_setup); -/* * Pick the FPU context switching strategy: */
@@ -307,11 +298,46 @@ static void __init fpu__init_system_ctx_switch(void) }/* +* We parse fpu parameters early because fpu__init_system() is executed +* before parse_early_param(). +*/ +static void __init fpu__init_parse_early_param (void ) +{ +/* +* No need to check "eagerfpu=auto" again, since it is the +* initial default. +*/ +if (cmdline_find_option_bool (boot_command_line,"eagerfpu=off" )) + eagerfpu =DISABLE ; +else if (cmdline_find_option_bool (boot_command_line,"eagerfpu=on" )) + eagerfpu =ENABLE ; + +if (cmdline_find_option_bool (boot_command_line,"no387" )) +setup_clear_cpu_cap (X86_FEATURE_FPU ); + +if (cmdline_find_option_bool (boot_command_line,"nofxsr" )) { +setup_clear_cpu_cap (X86_FEATURE_FXSR ); +setup_clear_cpu_cap (X86_FEATURE_FXSR_OPT ); +setup_clear_cpu_cap (X86_FEATURE_XMM ); + } + +if (cmdline_find_option_bool (boot_command_line,"noxsave" )) +fpu__xstate_clear_all_cpu_caps (); + +if (cmdline_find_option_bool (boot_command_line,"noxsaveopt" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); + +if (cmdline_find_option_bool (boot_command_line,"noxsaves" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVES ); +} + +/* * Called on the boot CPU once per system bootup, to set up the initial * FPU state that is later cloned into all processes: */ void __init fpu__init_system (struct cpuinfo_x86 *c) { +fpu__init_parse_early_param ();fpu__init_system_early_generic (c);/*
@@ -335,62 +361,3 @@ void __init fpu__init_system(struct cpuinfo_x86 *c)fpu__init_system_ctx_switch (); } - -/* -* Boot parameter to turn off FPU support and fall back to math-emu: -*/ -static int __init no_387 (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_FPU ); -return 1 ; -} -__setup ("no387" , no_387); - -/* -* Disable all xstate CPU features: -*/ -static int __init x86_noxsave_setup (char *s) -{ -if (strlen (s)) -return 0 ; - -fpu__xstate_clear_all_cpu_caps (); - -return 1 ; -} -__setup ("noxsave" , x86_noxsave_setup); - -/* -* Disable the XSAVEOPT instruction specifically: -*/ -static int __init x86_noxsaveopt_setup (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); - -return 1 ; -} -__setup ("noxsaveopt" , x86_noxsaveopt_setup); - -/* -* Disable the XSAVES instruction: -*/ -static int __init x86_noxsaves_setup (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_XSAVES ); - -return 1 ; -} -__setup ("noxsaves" , x86_noxsaves_setup); - -/* -* Disable FX save/restore and SSE support: -*/ -static int __init x86_nofxsr_setup (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_FXSR ); -setup_clear_cpu_cap (X86_FEATURE_FXSR_OPT ); -setup_clear_cpu_cap (X86_FEATURE_XMM ); - -return 1 ; -} -__setup ("nofxsr" , x86_nofxsr_setup);
Signature · 1 line
1.9.1
tip-bot for yu-cheng yu
merge bot[tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
x86/fpu: Fix early FPU command-line parsing
Commit-ID: 4f81cbafcce2c603db7865e9d0e461f7947d77d4 Gitweb: http://git.kernel.org/tip/4f81cbafcce2c603db7865e9d0e461f7947d77d4 Author: yu-cheng yu <[email protected]> AuthorDate: Wed, 6 Jan 2016 14:24:51 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 Jan 2016 11:51:20 +0100
x86/fpu: Fix early FPU command-line parsing
The function fpu__init_system() is executed before parse_early_param(). This causes wrong FPU configuration. This patch fixes this issue by parsing boot_command_line in the beginning of fpu__init_system().
With all four patches in this series, each parameter disables features as the following:
eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx
no387: fpu
nofxsr: fxsr, fxsropt, xmm
noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512, mpx, xgetbv1 noxsaveopt: xsaveopt
noxsaves: xsaves
--- arch/x86/kernel/fpu/init.c | 109 ++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 71 deletions(-)
arch/x86/kernel/fpu/init.c +38 -71
@@ -3,8 +3,11 @@*/ #include <asm/fpu/internal.h> #include <asm/tlbflush.h> +#include <asm/setup.h> +#include <asm/cmdline.h> #include <linux/sched.h> +#include <linux/init.h> /* * Initialize the TS bit in CR0 according to the style of context-switches
@@ -270,18 +273,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)*/ static enum {AUTO ,ENABLE ,DISABLE } eagerfpu =AUTO ; -static int __init eager_fpu_setup (char *s) -{ -if (!strcmp (s,"on" )) - eagerfpu =ENABLE ; -else if (!strcmp (s,"off" )) - eagerfpu =DISABLE ; -else if (!strcmp (s,"auto" )) - eagerfpu =AUTO ; -return 1 ; -} -__setup ("eagerfpu=" , eager_fpu_setup); -/* * Pick the FPU context switching strategy: */
@@ -316,11 +307,46 @@ static void __init fpu__init_system_ctx_switch(void) }/* +* We parse fpu parameters early because fpu__init_system() is executed +* before parse_early_param(). +*/ +static void __init fpu__init_parse_early_param (void ) +{ +/* +* No need to check "eagerfpu=auto" again, since it is the +* initial default. +*/ +if (cmdline_find_option_bool (boot_command_line,"eagerfpu=off" )) + eagerfpu =DISABLE ; +else if (cmdline_find_option_bool (boot_command_line,"eagerfpu=on" )) + eagerfpu =ENABLE ; + +if (cmdline_find_option_bool (boot_command_line,"no387" )) +setup_clear_cpu_cap (X86_FEATURE_FPU ); + +if (cmdline_find_option_bool (boot_command_line,"nofxsr" )) { +setup_clear_cpu_cap (X86_FEATURE_FXSR ); +setup_clear_cpu_cap (X86_FEATURE_FXSR_OPT ); +setup_clear_cpu_cap (X86_FEATURE_XMM ); + } + +if (cmdline_find_option_bool (boot_command_line,"noxsave" )) +fpu__xstate_clear_all_cpu_caps (); + +if (cmdline_find_option_bool (boot_command_line,"noxsaveopt" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); + +if (cmdline_find_option_bool (boot_command_line,"noxsaves" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVES ); +} + +/* * Called on the boot CPU once per system bootup, to set up the initial * FPU state that is later cloned into all processes: */ void __init fpu__init_system (struct cpuinfo_x86 *c) { +fpu__init_parse_early_param ();fpu__init_system_early_generic (c);/*
@@ -344,62 +370,3 @@ void __init fpu__init_system(struct cpuinfo_x86 *c)fpu__init_system_ctx_switch (); } - -/* -* Boot parameter to turn off FPU support and fall back to math-emu: -*/ -static int __init no_387 (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_FPU ); -return 1 ; -} -__setup ("no387" , no_387); - -/* -* Disable all xstate CPU features: -*/ -static int __init x86_noxsave_setup (char *s) -{ -if (strlen (s)) -return 0 ; - -fpu__xstate_clear_all_cpu_caps (); - -return 1 ; -} -__setup ("noxsave" , x86_noxsave_setup); - -/* -* Disable the XSAVEOPT instruction specifically: -*/ -static int __init x86_noxsaveopt_setup (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); - -return 1 ; -} -__setup ("noxsaveopt" , x86_noxsaveopt_setup); - -/* -* Disable the XSAVES instruction: -*/ -static int __init x86_noxsaves_setup (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_XSAVES ); - -return 1 ; -} -__setup ("noxsaves" , x86_noxsaves_setup); - -/* -* Disable FX save/restore and SSE support: -*/ -static int __init x86_nofxsr_setup (char *s) -{ -setup_clear_cpu_cap (X86_FEATURE_FXSR ); -setup_clear_cpu_cap (X86_FEATURE_FXSR_OPT ); -setup_clear_cpu_cap (X86_FEATURE_XMM ); - -return 1 ; -} -__setup ("nofxsr" , x86_nofxsr_setup);
Borislav Petkov
maintainerRe: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
Quoted 44 lines · tip-bot for yu-cheng yu
Commit-ID: 4f81cbafcce2c603db7865e9d0e461f7947d77d4 Gitweb: http://git.kernel.org/tip/4f81cbafcce2c603db7865e9d0e461f7947d77d4 Author: yu-cheng yu <[email protected]> AuthorDate: Wed, 6 Jan 2016 14:24:51 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 Jan 2016 11:51:20 +0100x86/fpu: Fix early FPU command-line parsing
The function
fpu__init_system()is executed beforeparse_early_param(). This causes wrong FPU configuration. This patch fixes this issue by parsingboot_command_linein the beginning offpu__init_system().With all four patches in this series, each parameter disables features as the following:
eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx
no387: fpu
nofxsr: fxsr, fxsropt, xmm
noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512, mpx, xgetbv1 noxsaveopt: xsaveopt
noxsaves: xsavesSigned-off-by Yu-cheng Yu <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Borislav Petkov <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Cc Fenghua Yu <[email protected]>Cc H. Peter Anvin <[email protected]>Cc Linus Torvalds <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Quentin Casasnovas <[email protected]>Cc Ravi V. Shankar <[email protected]>Cc Sai Praneeth Prakhya <[email protected]>Cc Thomas Gleixner <[email protected]>Cc yu-cheng yu <[email protected]>Signed-off-by Ingo Molnar <[email protected]>--- arch/x86/kernel/fpu/init.c | 109 ++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 71 deletions(-)
...
Quoted 21 lines
+ * We parse fpu parameters early because
fpu__init_system()is executed
+ * beforeparse_early_param().
+ */arch/x86/kernel/fpu/init.c +18
-0+static void __init fpu__init_parse_early_param (void ) +{ +/* +* No need to check "eagerfpu=auto" again, since it is the +* initial default. +*/ +if (cmdline_find_option_bool (boot_command_line,"eagerfpu=off" )) + eagerfpu =DISABLE ; +else if (cmdline_find_option_bool (boot_command_line,"eagerfpu=on" )) + eagerfpu =ENABLE ; + +if (cmdline_find_option_bool (boot_command_line,"no387" )) +setup_clear_cpu_cap (X86_FEATURE_FPU ); + +if (cmdline_find_option_bool (boot_command_line,"nofxsr" )) { +setup_clear_cpu_cap (X86_FEATURE_FXSR ); +setup_clear_cpu_cap (X86_FEATURE_FXSR_OPT ); +setup_clear_cpu_cap (X86_FEATURE_XMM );
arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void) · line 340
Quoted 10 lines
arch/x86/kernel/fpu/init.c +10
-0+ } + +if (cmdline_find_option_bool (boot_command_line,"noxsave" )) +fpu__xstate_clear_all_cpu_caps (); + +if (cmdline_find_option_bool (boot_command_line,"noxsaveopt" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); + +if (cmdline_find_option_bool (boot_command_line,"noxsaves" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVES );
This could certainly be improved: we're iterating over the *whole* command line each time for each option unconditionally instead of iterating word by word and comparing it with all strings.
We'd need something like cmdline_for_each_word() or so, though...
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Re: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
Quoted 33 lines · Borislav Petkov
Quoted 18 lines
arch/x86/kernel/fpu/init.c +18
-0+static void __init fpu__init_parse_early_param (void ) +{ +/* +* No need to check "eagerfpu=auto" again, since it is the +* initial default. +*/ +if (cmdline_find_option_bool (boot_command_line,"eagerfpu=off" )) + eagerfpu =DISABLE ; +else if (cmdline_find_option_bool (boot_command_line,"eagerfpu=on" )) + eagerfpu =ENABLE ; + +if (cmdline_find_option_bool (boot_command_line,"no387" )) +setup_clear_cpu_cap (X86_FEATURE_FPU ); + +if (cmdline_find_option_bool (boot_command_line,"nofxsr" )) { +setup_clear_cpu_cap (X86_FEATURE_FXSR ); +setup_clear_cpu_cap (X86_FEATURE_FXSR_OPT ); +setup_clear_cpu_cap (X86_FEATURE_XMM );arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void) · line 340
Quoted 10 lines
arch/x86/kernel/fpu/init.c +10
-0+ } + +if (cmdline_find_option_bool (boot_command_line,"noxsave" )) +fpu__xstate_clear_all_cpu_caps (); + +if (cmdline_find_option_bool (boot_command_line,"noxsaveopt" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); + +if (cmdline_find_option_bool (boot_command_line,"noxsaves" )) +setup_clear_cpu_cap (X86_FEATURE_XSAVES );This could certainly be improved: we're iterating over the *whole* command line each time for each option unconditionally instead of iterating word by word and comparing it with all strings.
Quoted 2 lines
We'd need something like
cmdline_for_each_word()or so, though...
That is a good point. I will work on it.
Thanks,
Yu-cheng
Dave Hansen
maintainerRe: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
Quoted 8 lines · Yu-cheng Yu
Quoted 7 lines
Quoted 7 lines
This could certainly be improved: we're iterating over the *whole* command line each time for each option unconditionally instead of iterating word by word and comparing it with all strings.
We'd need something like
cmdline_for_each_word()or so, though...That is a good point. I will work on it.
I really don't think we need to do this. It's code that runs *ONCE* at boot time. Let's not work on optimizing it unless we have some acute need.
Borislav Petkov
maintainerRe: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
Quoted 3 lines · Dave Hansen
I really don't think we need to do this. It's code that runs *ONCE* at boot time. Let's not work on optimizing it unless we have some acute need.
It was just a "it would be better if" suggestion, no one said anyone should work on it. And sorry but if we can elegantly optimize something, I think we should always do it.
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.PATCH 2/4 x86/fpu: Disable XGETBV1 when no XSAVE
In reply to yu-cheng yuWhen "noxsave" is given as a command-line input, the kernel should disable XGETBV1. This issue currently does not cause any actual problems. XGETBV1 is only useful if we have something using the 'init optimization' (i.e. xsaveopt, xsaves). We already clear both of those in fpu__xstate_clear_all_cpu_caps(). But this is good for completeness.
--- arch/x86/kernel/fpu/xstate.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/fpu/xstate.c +1 -0
@@ -52,6 +52,7 @@ void fpu__xstate_clear_all_cpu_caps(void)setup_clear_cpu_cap (X86_FEATURE_AVX512ER );setup_clear_cpu_cap (X86_FEATURE_AVX512CD );setup_clear_cpu_cap (X86_FEATURE_MPX ); +setup_clear_cpu_cap (X86_FEATURE_XGETBV1 ); }/*
Signature · 1 line
1.9.1
tip-bot for yu-cheng yu
merge bot[tip:x86/asm] x86/fpu: Disable XGETBV1 when no XSAVE
x86/fpu: Disable XGETBV1 when no XSAVE
Commit-ID: eb7c5f872e697b0aebd846cf3a3328d71e9decb2 Gitweb: http://git.kernel.org/tip/eb7c5f872e697b0aebd846cf3a3328d71e9decb2 Author: yu-cheng yu <[email protected]> AuthorDate: Wed, 6 Jan 2016 14:24:52 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 Jan 2016 11:51:21 +0100
x86/fpu: Disable XGETBV1 when no XSAVE
When "noxsave" is given as a command-line input, the kernel should disable XGETBV1. This issue currently does not cause any actual problems. XGETBV1 is only useful if we have something using the 'init optimization' (i.e. xsaveopt, xsaves). We already clear both of those in fpu__xstate_clear_all_cpu_caps(). But this is good for completeness.
--- arch/x86/kernel/fpu/xstate.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/fpu/xstate.c +1 -0
@@ -52,6 +52,7 @@ void fpu__xstate_clear_all_cpu_caps(void)setup_clear_cpu_cap (X86_FEATURE_AVX512ER );setup_clear_cpu_cap (X86_FEATURE_AVX512CD );setup_clear_cpu_cap (X86_FEATURE_MPX ); +setup_clear_cpu_cap (X86_FEATURE_XGETBV1 ); }/*
PATCH 3/4 x86/fpu: Disable MPX when eagerfpu is off
In reply to yu-cheng yuThis issue is a fallout from the command-line parsing move.
When "eagerfpu=off" is given as a command-line input, the kernel should disable MPX support. The decision for turning off MPX was made in fpu__init_system_ctx_switch(), which is after the selection of the XSAVE format. This patch fixes it by getting that decision done earlier in fpu__init_system_xstate().
--- arch/x86/include/asm/fpu/internal.h | 1 + arch/x86/kernel/fpu/init.c | 56 +++++++++++++++++++++++++++++-------- arch/x86/kernel/fpu/xstate.c | 3 +- 3 files changed, 46 insertions(+), 14 deletions(-)
arch/x86/include/asm/fpu/internal.h +1 -0
@@ -42,6 +42,7 @@ extern void fpu__init_cpu_xstate(void);extern void fpu__init_system (struct cpuinfo_x86 *c);extern void fpu__init_check_bugs (void );extern void fpu__resume_cpu (void ); +extern u64 fpu__get_supported_xfeatures_mask (void );/* * Debugging facility:
arch/x86/kernel/fpu/init.c +44 -12
80 lines not on this page · raw message
arch/x86/kernel/fpu/xstate.c +1 -2
@@ -633,8 +633,7 @@ void __init fpu__init_system_xstate(void)BUG (); } -/* Support only the state known to the OS: */ - xfeatures_mask = xfeatures_mask &XCNTXT_MASK ; + xfeatures_mask &=fpu__get_supported_xfeatures_mask ();/* Enable xstate instructions to be able to continue with initialization: */ fpu__init_cpu_xstate ();
Signature · 1 line
1.9.1
tip-bot for yu-cheng yu
merge bot[tip:x86/asm] x86/fpu: Disable MPX when eagerfpu is off
x86/fpu: Disable MPX when eagerfpu is off
Commit-ID: a5fe93a549c54838063d2952dd9643b0b18aa67f Gitweb: http://git.kernel.org/tip/a5fe93a549c54838063d2952dd9643b0b18aa67f Author: yu-cheng yu <[email protected]> AuthorDate: Wed, 6 Jan 2016 14:24:53 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 Jan 2016 11:51:21 +0100
x86/fpu: Disable MPX when eagerfpu is off
This issue is a fallout from the command-line parsing move.
When "eagerfpu=off" is given as a command-line input, the kernel should disable MPX support. The decision for turning off MPX was made in fpu__init_system_ctx_switch(), which is after the selection of the XSAVE format. This patch fixes it by getting that decision done earlier in fpu__init_system_xstate().
--- arch/x86/include/asm/fpu/internal.h | 1 + arch/x86/kernel/fpu/init.c | 56 +++++++++++++++++++++++++++++-------- arch/x86/kernel/fpu/xstate.c | 3 +- 3 files changed, 46 insertions(+), 14 deletions(-)
arch/x86/include/asm/fpu/internal.h +1 -0
@@ -42,6 +42,7 @@ extern void fpu__init_cpu_xstate(void);extern void fpu__init_system (struct cpuinfo_x86 *c);extern void fpu__init_check_bugs (void );extern void fpu__resume_cpu (void ); +extern u64 fpu__get_supported_xfeatures_mask (void );/* * Debugging facility:
arch/x86/kernel/fpu/init.c +44 -12
80 lines not on this page · raw message
arch/x86/kernel/fpu/xstate.c +1 -2
@@ -633,8 +633,7 @@ void __init fpu__init_system_xstate(void)BUG (); } -/* Support only the state known to the OS: */ - xfeatures_mask = xfeatures_mask &XCNTXT_MASK ; + xfeatures_mask &=fpu__get_supported_xfeatures_mask ();/* Enable xstate instructions to be able to continue with initialization: */ fpu__init_cpu_xstate ();
PATCH 4/4 x86/fpu: Disable AVX when eagerfpu is off
In reply to yu-cheng yuWhen "eagerfpu=off" is given as a command-line input, the kernel should disable AVX support.
The Task Switched bit used for lazy context switching does not support AVX. If AVX is enabled without eagerfpu context switching, one task's AVX state could become corrupted or leak to other tasks. This is a bug and has bad security implications.
This only affects systems that have AVX/AVX2/AVX512 and this issue will be found only when one actually uses AVX/AVX2/AVX512 _AND_ does eagerfpu=off.
Referece: Intel Software Developer's Manual Vol. 3A
Sec. 2.5 Control Registers:
TS Task Switched bit (bit 3 of CR0) -- Allows the saving of the x87 FPU/ MMX/SSE/SSE2/SSE3/SSSE3/SSE4 context on a task switch to be delayed until an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction is actually executed by the new task.
Sec. 13.4.1 Using the TS Flag to Control the Saving of the X87 FPU and SSE State
When the TS flag is set, the processor monitors the instruction stream for x87 FPU, MMX, SSE instructions. When the processor detects one of these instructions, it raises a device-not-available exeception (#NM) prior to executing the instruction.
--- arch/x86/include/asm/fpu/xstate.h | 11 ++++++----- arch/x86/kernel/fpu/init.c | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
arch/x86/include/asm/fpu/xstate.h +6 -5
@@ -20,15 +20,16 @@/* Supported features which support lazy state saving */ #define XFEATURE_MASK_LAZY (XFEATURE_MASK_FP | \ - XFEATURE_MASK_SSE | \ + XFEATURE_MASK_SSE) + +/* Supported features which require eager state saving */ +#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | \ + XFEATURE_MASK_BNDCSR | \ XFEATURE_MASK_YMM | \ - XFEATURE_MASK_OPMASK | \ + XFEATURE_MASK_OPMASK | \ XFEATURE_MASK_ZMM_Hi256 | \ XFEATURE_MASK_Hi16_ZMM) -/* Supported features which require eager state saving */ -#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR) -/* All currently supported features */ #define XCNTXT_MASK (XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER)
arch/x86/kernel/fpu/init.c +6 -0
@@ -291,6 +291,12 @@ u64 __init fpu__get_supported_xfeatures_mask(void)static void __init fpu__clear_eager_fpu_features (void ) {setup_clear_cpu_cap (X86_FEATURE_MPX ); +setup_clear_cpu_cap (X86_FEATURE_AVX ); +setup_clear_cpu_cap (X86_FEATURE_AVX2 ); +setup_clear_cpu_cap (X86_FEATURE_AVX512F ); +setup_clear_cpu_cap (X86_FEATURE_AVX512PF ); +setup_clear_cpu_cap (X86_FEATURE_AVX512ER ); +setup_clear_cpu_cap (X86_FEATURE_AVX512CD ); }/*
Signature · 1 line
1.9.1
tip-bot for yu-cheng yu
merge bot[tip:x86/asm] x86/fpu: Disable AVX when eagerfpu is off
x86/fpu: Disable AVX when eagerfpu is off
Commit-ID: 394db20ca240741a08d472173db13d6f6a6e5a28 Gitweb: http://git.kernel.org/tip/394db20ca240741a08d472173db13d6f6a6e5a28 Author: yu-cheng yu <[email protected]> AuthorDate: Wed, 6 Jan 2016 14:24:54 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 Jan 2016 11:51:21 +0100
x86/fpu: Disable AVX when eagerfpu is off
When "eagerfpu=off" is given as a command-line input, the kernel should disable AVX support.
The Task Switched bit used for lazy context switching does not support AVX. If AVX is enabled without eagerfpu context switching, one task's AVX state could become corrupted or leak to other tasks. This is a bug and has bad security implications.
This only affects systems that have AVX/AVX2/AVX512 and this issue will be found only when one actually uses AVX/AVX2/AVX512 _AND_ does eagerfpu=off.
Reference: Intel Software Developer's Manual Vol. 3A
Sec. 2.5 Control Registers:
TS Task Switched bit (bit 3 of CR0) -- Allows the saving of the x87 FPU/ MMX/SSE/SSE2/SSE3/SSSE3/SSE4 context on a task switch to be delayed until an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction is actually executed by the new task.
Sec. 13.4.1 Using the TS Flag to Control the Saving of the X87 FPU and SSE State
When the TS flag is set, the processor monitors the instruction stream for x87 FPU, MMX, SSE instructions. When the processor detects one of these instructions, it raises a device-not-available exeception (#NM) prior to executing the instruction.
--- arch/x86/include/asm/fpu/xstate.h | 11 ++++++----- arch/x86/kernel/fpu/init.c | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
arch/x86/include/asm/fpu/xstate.h +6 -5
@@ -20,15 +20,16 @@/* Supported features which support lazy state saving */ #define XFEATURE_MASK_LAZY (XFEATURE_MASK_FP | \ - XFEATURE_MASK_SSE | \ + XFEATURE_MASK_SSE) + +/* Supported features which require eager state saving */ +#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | \ + XFEATURE_MASK_BNDCSR | \ XFEATURE_MASK_YMM | \ - XFEATURE_MASK_OPMASK | \ + XFEATURE_MASK_OPMASK | \ XFEATURE_MASK_ZMM_Hi256 | \ XFEATURE_MASK_Hi16_ZMM) -/* Supported features which require eager state saving */ -#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR) -/* All currently supported features */ #define XCNTXT_MASK (XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER)
arch/x86/kernel/fpu/init.c +6 -0
@@ -300,6 +300,12 @@ u64 __init fpu__get_supported_xfeatures_mask(void)static void __init fpu__clear_eager_fpu_features (void ) {setup_clear_cpu_cap (X86_FEATURE_MPX ); +setup_clear_cpu_cap (X86_FEATURE_AVX ); +setup_clear_cpu_cap (X86_FEATURE_AVX2 ); +setup_clear_cpu_cap (X86_FEATURE_AVX512F ); +setup_clear_cpu_cap (X86_FEATURE_AVX512PF ); +setup_clear_cpu_cap (X86_FEATURE_AVX512ER ); +setup_clear_cpu_cap (X86_FEATURE_AVX512CD ); }/*