Skip to content

Commit 4f81cba

Browse files
yyu-intel-comIngo Molnar
authored andcommitted
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 Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Borislav Petkov <bp@suse.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com> Cc: Ravi V. Shankar <ravi.v.shankar@intel.com> Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: yu-cheng yu <yu-cheng.yu@intel.com> Link: http://lkml.kernel.org/r/1452119094-7252-2-git-send-email-yu-cheng.yu@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b500f77 commit 4f81cba

File tree

1 file changed

+38
-71
lines changed

1 file changed

+38
-71
lines changed

arch/x86/kernel/fpu/init.c

Lines changed: 38 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
*/
44
#include <asm/fpu/internal.h>
55
#include <asm/tlbflush.h>
6+
#include <asm/setup.h>
7+
#include <asm/cmdline.h>
68

79
#include <linux/sched.h>
10+
#include <linux/init.h>
811

912
/*
1013
* 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)
270273
*/
271274
static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO;
272275

273-
static int __init eager_fpu_setup(char *s)
274-
{
275-
if (!strcmp(s, "on"))
276-
eagerfpu = ENABLE;
277-
else if (!strcmp(s, "off"))
278-
eagerfpu = DISABLE;
279-
else if (!strcmp(s, "auto"))
280-
eagerfpu = AUTO;
281-
return 1;
282-
}
283-
__setup("eagerfpu=", eager_fpu_setup);
284-
285276
/*
286277
* Pick the FPU context switching strategy:
287278
*/
@@ -315,12 +306,47 @@ static void __init fpu__init_system_ctx_switch(void)
315306
printk(KERN_INFO "x86/fpu: Using '%s' FPU context switches.\n", eagerfpu == ENABLE ? "eager" : "lazy");
316307
}
317308

309+
/*
310+
* We parse fpu parameters early because fpu__init_system() is executed
311+
* before parse_early_param().
312+
*/
313+
static void __init fpu__init_parse_early_param(void)
314+
{
315+
/*
316+
* No need to check "eagerfpu=auto" again, since it is the
317+
* initial default.
318+
*/
319+
if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
320+
eagerfpu = DISABLE;
321+
else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
322+
eagerfpu = ENABLE;
323+
324+
if (cmdline_find_option_bool(boot_command_line, "no387"))
325+
setup_clear_cpu_cap(X86_FEATURE_FPU);
326+
327+
if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
328+
setup_clear_cpu_cap(X86_FEATURE_FXSR);
329+
setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
330+
setup_clear_cpu_cap(X86_FEATURE_XMM);
331+
}
332+
333+
if (cmdline_find_option_bool(boot_command_line, "noxsave"))
334+
fpu__xstate_clear_all_cpu_caps();
335+
336+
if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
337+
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
338+
339+
if (cmdline_find_option_bool(boot_command_line, "noxsaves"))
340+
setup_clear_cpu_cap(X86_FEATURE_XSAVES);
341+
}
342+
318343
/*
319344
* Called on the boot CPU once per system bootup, to set up the initial
320345
* FPU state that is later cloned into all processes:
321346
*/
322347
void __init fpu__init_system(struct cpuinfo_x86 *c)
323348
{
349+
fpu__init_parse_early_param();
324350
fpu__init_system_early_generic(c);
325351

326352
/*
@@ -344,62 +370,3 @@ void __init fpu__init_system(struct cpuinfo_x86 *c)
344370

345371
fpu__init_system_ctx_switch();
346372
}
347-
348-
/*
349-
* Boot parameter to turn off FPU support and fall back to math-emu:
350-
*/
351-
static int __init no_387(char *s)
352-
{
353-
setup_clear_cpu_cap(X86_FEATURE_FPU);
354-
return 1;
355-
}
356-
__setup("no387", no_387);
357-
358-
/*
359-
* Disable all xstate CPU features:
360-
*/
361-
static int __init x86_noxsave_setup(char *s)
362-
{
363-
if (strlen(s))
364-
return 0;
365-
366-
fpu__xstate_clear_all_cpu_caps();
367-
368-
return 1;
369-
}
370-
__setup("noxsave", x86_noxsave_setup);
371-
372-
/*
373-
* Disable the XSAVEOPT instruction specifically:
374-
*/
375-
static int __init x86_noxsaveopt_setup(char *s)
376-
{
377-
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
378-
379-
return 1;
380-
}
381-
__setup("noxsaveopt", x86_noxsaveopt_setup);
382-
383-
/*
384-
* Disable the XSAVES instruction:
385-
*/
386-
static int __init x86_noxsaves_setup(char *s)
387-
{
388-
setup_clear_cpu_cap(X86_FEATURE_XSAVES);
389-
390-
return 1;
391-
}
392-
__setup("noxsaves", x86_noxsaves_setup);
393-
394-
/*
395-
* Disable FX save/restore and SSE support:
396-
*/
397-
static int __init x86_nofxsr_setup(char *s)
398-
{
399-
setup_clear_cpu_cap(X86_FEATURE_FXSR);
400-
setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
401-
setup_clear_cpu_cap(X86_FEATURE_XMM);
402-
403-
return 1;
404-
}
405-
__setup("nofxsr", x86_nofxsr_setup);

0 commit comments

Comments
 (0)