2019-05-19 20:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-04-22 16:53:34 +08:00
|
|
|
/*
|
2015-04-26 21:36:46 +08:00
|
|
|
* x86 FPU boot time init code:
|
2015-04-22 16:53:34 +08:00
|
|
|
*/
|
2015-04-24 08:54:44 +08:00
|
|
|
#include <asm/fpu/internal.h>
|
2015-04-22 16:53:34 +08:00
|
|
|
#include <asm/tlbflush.h>
|
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>
2016-01-07 06:24:51 +08:00
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/cmdline.h>
|
2015-04-22 16:53:34 +08:00
|
|
|
|
2015-07-17 18:28:12 +08:00
|
|
|
#include <linux/sched.h>
|
2017-02-09 01:51:36 +08:00
|
|
|
#include <linux/sched/task.h>
|
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>
2016-01-07 06:24:51 +08:00
|
|
|
#include <linux/init.h>
|
2015-07-17 18:28:12 +08:00
|
|
|
|
2015-04-26 21:32:40 +08:00
|
|
|
/*
|
|
|
|
* Initialize the registers found in all CPUs, CR0 and CR4:
|
|
|
|
*/
|
|
|
|
static void fpu__init_cpu_generic(void)
|
|
|
|
{
|
|
|
|
unsigned long cr0;
|
|
|
|
unsigned long cr4_mask = 0;
|
|
|
|
|
2016-04-05 04:25:01 +08:00
|
|
|
if (boot_cpu_has(X86_FEATURE_FXSR))
|
2015-04-26 21:32:40 +08:00
|
|
|
cr4_mask |= X86_CR4_OSFXSR;
|
2016-04-05 04:24:57 +08:00
|
|
|
if (boot_cpu_has(X86_FEATURE_XMM))
|
2015-04-26 21:32:40 +08:00
|
|
|
cr4_mask |= X86_CR4_OSXMMEXCPT;
|
|
|
|
if (cr4_mask)
|
|
|
|
cr4_set_bits(cr4_mask);
|
|
|
|
|
|
|
|
cr0 = read_cr0();
|
|
|
|
cr0 &= ~(X86_CR0_TS|X86_CR0_EM); /* clear TS and EM */
|
2016-04-05 04:24:58 +08:00
|
|
|
if (!boot_cpu_has(X86_FEATURE_FPU))
|
2015-04-26 21:32:40 +08:00
|
|
|
cr0 |= X86_CR0_EM;
|
|
|
|
write_cr0(cr0);
|
2015-04-29 16:58:03 +08:00
|
|
|
|
|
|
|
/* Flush out any pending x87 state: */
|
2015-08-22 15:52:06 +08:00
|
|
|
#ifdef CONFIG_MATH_EMULATION
|
2016-04-05 04:24:58 +08:00
|
|
|
if (!boot_cpu_has(X86_FEATURE_FPU))
|
2015-08-22 15:52:06 +08:00
|
|
|
fpstate_init_soft(¤t->thread.fpu.state.soft);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
asm volatile ("fninit");
|
2015-04-26 21:32:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-04-26 21:36:46 +08:00
|
|
|
* Enable all supported FPU features. Called when a CPU is brought online:
|
2015-04-26 21:32:40 +08:00
|
|
|
*/
|
|
|
|
void fpu__init_cpu(void)
|
|
|
|
{
|
|
|
|
fpu__init_cpu_generic();
|
|
|
|
fpu__init_cpu_xstate();
|
|
|
|
}
|
|
|
|
|
2017-01-19 03:15:41 +08:00
|
|
|
static bool fpu__probe_without_cpuid(void)
|
2015-04-26 20:40:54 +08:00
|
|
|
{
|
|
|
|
unsigned long cr0;
|
|
|
|
u16 fsw, fcw;
|
|
|
|
|
|
|
|
fsw = fcw = 0xffff;
|
|
|
|
|
|
|
|
cr0 = read_cr0();
|
|
|
|
cr0 &= ~(X86_CR0_TS | X86_CR0_EM);
|
|
|
|
write_cr0(cr0);
|
|
|
|
|
2017-01-19 03:15:41 +08:00
|
|
|
asm volatile("fninit ; fnstsw %0 ; fnstcw %1" : "+m" (fsw), "+m" (fcw));
|
|
|
|
|
|
|
|
pr_info("x86/fpu: Probing for FPU: FSW=0x%04hx FCW=0x%04hx\n", fsw, fcw);
|
2016-01-22 07:24:31 +08:00
|
|
|
|
2017-01-19 03:15:41 +08:00
|
|
|
return fsw == 0 && (fcw & 0x103f) == 0x003f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fpu__init_system_early_generic(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
if (!boot_cpu_has(X86_FEATURE_CPUID) &&
|
|
|
|
!test_bit(X86_FEATURE_FPU, (unsigned long *)cpu_caps_cleared)) {
|
|
|
|
if (fpu__probe_without_cpuid())
|
|
|
|
setup_force_cpu_cap(X86_FEATURE_FPU);
|
2016-01-22 07:24:31 +08:00
|
|
|
else
|
2017-01-19 03:15:41 +08:00
|
|
|
setup_clear_cpu_cap(X86_FEATURE_FPU);
|
2016-01-22 07:24:31 +08:00
|
|
|
}
|
2015-04-26 20:43:44 +08:00
|
|
|
|
|
|
|
#ifndef CONFIG_MATH_EMULATION
|
2017-01-19 03:15:42 +08:00
|
|
|
if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_FPU)) {
|
2015-04-26 21:36:46 +08:00
|
|
|
pr_emerg("x86/fpu: Giving up, no FPU found and no math emulation present\n");
|
2015-04-26 20:43:44 +08:00
|
|
|
for (;;)
|
|
|
|
asm volatile("hlt");
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-26 20:40:54 +08:00
|
|
|
}
|
|
|
|
|
2015-04-22 19:44:25 +08:00
|
|
|
/*
|
|
|
|
* Boot time FPU feature detection code:
|
|
|
|
*/
|
2015-04-22 16:53:34 +08:00
|
|
|
unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu;
|
2017-05-11 17:58:55 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mxcsr_feature_mask);
|
2015-04-24 16:49:11 +08:00
|
|
|
|
2015-05-04 15:52:42 +08:00
|
|
|
static void __init fpu__init_system_mxcsr(void)
|
2015-04-22 16:53:34 +08:00
|
|
|
{
|
2015-04-24 16:49:11 +08:00
|
|
|
unsigned int mask = 0;
|
2015-04-22 16:53:34 +08:00
|
|
|
|
2016-04-05 04:25:01 +08:00
|
|
|
if (boot_cpu_has(X86_FEATURE_FXSR)) {
|
2015-07-04 15:58:19 +08:00
|
|
|
/* Static because GCC does not get 16-byte stack alignment right: */
|
|
|
|
static struct fxregs_state fxregs __initdata;
|
2015-04-24 16:49:11 +08:00
|
|
|
|
2015-07-04 15:58:19 +08:00
|
|
|
asm volatile("fxsave %0" : "+m" (fxregs));
|
2015-04-24 16:49:11 +08:00
|
|
|
|
2015-07-04 15:58:19 +08:00
|
|
|
mask = fxregs.mxcsr_mask;
|
2015-04-24 16:49:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If zero then use the default features mask,
|
|
|
|
* which has all features set, except the
|
|
|
|
* denormals-are-zero feature bit:
|
|
|
|
*/
|
2015-04-22 16:53:34 +08:00
|
|
|
if (mask == 0)
|
|
|
|
mask = 0x0000ffbf;
|
|
|
|
}
|
|
|
|
mxcsr_feature_mask &= mask;
|
|
|
|
}
|
|
|
|
|
2015-04-26 20:35:54 +08:00
|
|
|
/*
|
|
|
|
* Once per bootup FPU initialization sequences that will run on most x86 CPUs:
|
|
|
|
*/
|
2015-05-04 15:52:42 +08:00
|
|
|
static void __init fpu__init_system_generic(void)
|
2015-04-26 20:35:54 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set up the legacy init FPU context. (xstate init might overwrite this
|
|
|
|
* with a more modern format, if the CPU supports it.)
|
|
|
|
*/
|
2016-03-11 19:32:06 +08:00
|
|
|
fpstate_init(&init_fpstate);
|
2015-04-26 20:35:54 +08:00
|
|
|
|
|
|
|
fpu__init_system_mxcsr();
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:36:46 +08:00
|
|
|
/*
|
|
|
|
* Size of the FPU context state. All tasks in the system use the
|
|
|
|
* same context size, regardless of what portion they use.
|
|
|
|
* This is inherent to the XSAVE architecture which puts all state
|
|
|
|
* components into a single, continuous memory block:
|
|
|
|
*/
|
2016-05-21 01:47:06 +08:00
|
|
|
unsigned int fpu_kernel_xstate_size;
|
|
|
|
EXPORT_SYMBOL_GPL(fpu_kernel_xstate_size);
|
2015-04-26 21:32:40 +08:00
|
|
|
|
2015-12-21 22:25:30 +08:00
|
|
|
/* Get alignment of the TYPE. */
|
|
|
|
#define TYPE_ALIGN(TYPE) offsetof(struct { char x; TYPE test; }, test)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enforce that 'MEMBER' is the last field of 'TYPE'.
|
|
|
|
*
|
|
|
|
* Align the computed size with alignment of the TYPE,
|
|
|
|
* because that's how C aligns structs.
|
|
|
|
*/
|
2015-07-17 18:28:12 +08:00
|
|
|
#define CHECK_MEMBER_AT_END_OF(TYPE, MEMBER) \
|
2015-12-21 22:25:30 +08:00
|
|
|
BUILD_BUG_ON(sizeof(TYPE) != ALIGN(offsetofend(TYPE, MEMBER), \
|
|
|
|
TYPE_ALIGN(TYPE)))
|
2015-07-17 18:28:11 +08:00
|
|
|
|
|
|
|
/*
|
2015-07-17 18:28:12 +08:00
|
|
|
* We append the 'struct fpu' to the task_struct:
|
2015-07-17 18:28:11 +08:00
|
|
|
*/
|
2015-07-17 18:28:12 +08:00
|
|
|
static void __init fpu__init_task_struct_size(void)
|
2015-07-17 18:28:11 +08:00
|
|
|
{
|
|
|
|
int task_size = sizeof(struct task_struct);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Subtract off the static size of the register state.
|
|
|
|
* It potentially has a bunch of padding.
|
|
|
|
*/
|
|
|
|
task_size -= sizeof(((struct task_struct *)0)->thread.fpu.state);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add back the dynamically-calculated register state
|
|
|
|
* size.
|
|
|
|
*/
|
2016-05-21 01:47:06 +08:00
|
|
|
task_size += fpu_kernel_xstate_size;
|
2015-07-17 18:28:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We dynamically size 'struct fpu', so we require that
|
|
|
|
* it be at the end of 'thread_struct' and that
|
|
|
|
* 'thread_struct' be at the end of 'task_struct'. If
|
|
|
|
* you hit a compile error here, check the structure to
|
|
|
|
* see if something got added to the end.
|
|
|
|
*/
|
|
|
|
CHECK_MEMBER_AT_END_OF(struct fpu, state);
|
|
|
|
CHECK_MEMBER_AT_END_OF(struct thread_struct, fpu);
|
|
|
|
CHECK_MEMBER_AT_END_OF(struct task_struct, thread);
|
|
|
|
|
2015-07-17 18:28:12 +08:00
|
|
|
arch_task_struct_size = task_size;
|
2015-07-17 18:28:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:32:40 +08:00
|
|
|
/*
|
2016-05-21 01:47:06 +08:00
|
|
|
* Set up the user and kernel xstate sizes based on the legacy FPU context size.
|
2015-04-26 21:32:40 +08:00
|
|
|
*
|
|
|
|
* We set this up first, and later it will be overwritten by
|
|
|
|
* fpu__init_system_xstate() if the CPU knows about xstates.
|
|
|
|
*/
|
2015-05-04 15:52:42 +08:00
|
|
|
static void __init fpu__init_system_xstate_size_legacy(void)
|
2015-04-22 16:53:34 +08:00
|
|
|
{
|
2015-11-13 22:18:31 +08:00
|
|
|
static int on_boot_cpu __initdata = 1;
|
2015-05-05 17:34:49 +08:00
|
|
|
|
|
|
|
WARN_ON_FPU(!on_boot_cpu);
|
|
|
|
on_boot_cpu = 0;
|
|
|
|
|
2015-04-22 16:53:34 +08:00
|
|
|
/*
|
2016-05-21 01:47:06 +08:00
|
|
|
* Note that xstate sizes might be overwritten later during
|
2015-04-25 12:52:53 +08:00
|
|
|
* fpu__init_system_xstate().
|
2015-04-22 16:53:34 +08:00
|
|
|
*/
|
|
|
|
|
2016-04-05 04:24:58 +08:00
|
|
|
if (!boot_cpu_has(X86_FEATURE_FPU)) {
|
2015-04-22 16:53:34 +08:00
|
|
|
/*
|
|
|
|
* Disable xsave as we do not support it if i387
|
|
|
|
* emulation is enabled.
|
|
|
|
*/
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVE);
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
|
2016-05-21 01:47:06 +08:00
|
|
|
fpu_kernel_xstate_size = sizeof(struct swregs_state);
|
2015-04-25 10:29:26 +08:00
|
|
|
} else {
|
2016-04-05 04:25:01 +08:00
|
|
|
if (boot_cpu_has(X86_FEATURE_FXSR))
|
2016-05-21 01:47:06 +08:00
|
|
|
fpu_kernel_xstate_size =
|
|
|
|
sizeof(struct fxregs_state);
|
2015-04-25 10:29:26 +08:00
|
|
|
else
|
2016-05-21 01:47:06 +08:00
|
|
|
fpu_kernel_xstate_size =
|
|
|
|
sizeof(struct fregs_state);
|
2015-04-22 16:53:34 +08:00
|
|
|
}
|
2016-05-21 01:47:05 +08:00
|
|
|
|
2016-05-21 01:47:06 +08:00
|
|
|
fpu_user_xstate_size = fpu_kernel_xstate_size;
|
2015-04-22 16:53:34 +08:00
|
|
|
}
|
|
|
|
|
2016-01-07 06:24:53 +08:00
|
|
|
/*
|
|
|
|
* Find supported xfeatures based on cpu features and command-line input.
|
|
|
|
* This must be called after fpu__init_parse_early_param() is called and
|
|
|
|
* xfeatures_mask is enumerated.
|
|
|
|
*/
|
|
|
|
u64 __init fpu__get_supported_xfeatures_mask(void)
|
|
|
|
{
|
2016-10-05 08:34:31 +08:00
|
|
|
return XCNTXT_MASK;
|
2016-01-07 06:24:53 +08:00
|
|
|
}
|
|
|
|
|
2016-10-05 08:34:31 +08:00
|
|
|
/* Legacy code to initialize eager fpu mode. */
|
2015-05-04 15:52:42 +08:00
|
|
|
static void __init fpu__init_system_ctx_switch(void)
|
2015-04-26 02:11:05 +08:00
|
|
|
{
|
2015-11-13 22:18:31 +08:00
|
|
|
static bool on_boot_cpu __initdata = 1;
|
2015-05-05 17:34:49 +08:00
|
|
|
|
|
|
|
WARN_ON_FPU(!on_boot_cpu);
|
|
|
|
on_boot_cpu = 0;
|
2015-04-26 02:11:05 +08:00
|
|
|
}
|
|
|
|
|
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>
2016-01-07 06:24:51 +08:00
|
|
|
/*
|
|
|
|
* We parse fpu parameters early because fpu__init_system() is executed
|
|
|
|
* before parse_early_param().
|
|
|
|
*/
|
|
|
|
static void __init fpu__init_parse_early_param(void)
|
|
|
|
{
|
2017-10-14 05:56:43 +08:00
|
|
|
char arg[32];
|
|
|
|
char *argptr = arg;
|
|
|
|
int bit;
|
|
|
|
|
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>
2016-01-07 06:24:51 +08:00
|
|
|
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);
|
2017-10-14 05:56:43 +08:00
|
|
|
|
|
|
|
if (cmdline_find_option(boot_command_line, "clearcpuid", arg,
|
|
|
|
sizeof(arg)) &&
|
|
|
|
get_option(&argptr, &bit) &&
|
|
|
|
bit >= 0 &&
|
|
|
|
bit < NCAPINTS * 32)
|
|
|
|
setup_clear_cpu_cap(bit);
|
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>
2016-01-07 06:24:51 +08:00
|
|
|
}
|
|
|
|
|
x86/fpu: Split fpu__cpu_init() into early-boot and cpu-boot parts
There are two kinds of FPU initialization sequences necessary to bring FPU
functionality up: once per system bootup activities, such as detection,
feature initialization, etc. of attributes that are shared by all CPUs
in the system - and per cpu initialization sequences run when a CPU is
brought online (either during bootup or during CPU hotplug onlining),
such as CR0/CR4 register setting, etc.
The FPU code is mixing these roles together, with no clear distinction.
Start sorting this out by splitting the main FPU detection routine
(fpu__cpu_init()) into two parts: fpu__init_system() for
one per system init activities, and fpu__init_cpu() for the
per CPU onlining init activities.
Note that xstate_init() is called from both variants for the time being,
because it has a dual nature as well. We'll fix that in upcoming patches.
Just do the split and call it as we used to before, don't introduce any
change in initialization behavior yet, beyond duplicate (and harmless)
fpu__init_cpu() and xstate_init() calls - which we'll fix in later
patches.
Reviewed-by: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
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: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-04-25 10:34:48 +08:00
|
|
|
/*
|
2015-04-26 21:36:46 +08:00
|
|
|
* Called on the boot CPU once per system bootup, to set up the initial
|
|
|
|
* FPU state that is later cloned into all processes:
|
x86/fpu: Split fpu__cpu_init() into early-boot and cpu-boot parts
There are two kinds of FPU initialization sequences necessary to bring FPU
functionality up: once per system bootup activities, such as detection,
feature initialization, etc. of attributes that are shared by all CPUs
in the system - and per cpu initialization sequences run when a CPU is
brought online (either during bootup or during CPU hotplug onlining),
such as CR0/CR4 register setting, etc.
The FPU code is mixing these roles together, with no clear distinction.
Start sorting this out by splitting the main FPU detection routine
(fpu__cpu_init()) into two parts: fpu__init_system() for
one per system init activities, and fpu__init_cpu() for the
per CPU onlining init activities.
Note that xstate_init() is called from both variants for the time being,
because it has a dual nature as well. We'll fix that in upcoming patches.
Just do the split and call it as we used to before, don't introduce any
change in initialization behavior yet, beyond duplicate (and harmless)
fpu__init_cpu() and xstate_init() calls - which we'll fix in later
patches.
Reviewed-by: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
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: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-04-25 10:34:48 +08:00
|
|
|
*/
|
2015-05-04 15:52:42 +08:00
|
|
|
void __init fpu__init_system(struct cpuinfo_x86 *c)
|
x86/fpu: Split fpu__cpu_init() into early-boot and cpu-boot parts
There are two kinds of FPU initialization sequences necessary to bring FPU
functionality up: once per system bootup activities, such as detection,
feature initialization, etc. of attributes that are shared by all CPUs
in the system - and per cpu initialization sequences run when a CPU is
brought online (either during bootup or during CPU hotplug onlining),
such as CR0/CR4 register setting, etc.
The FPU code is mixing these roles together, with no clear distinction.
Start sorting this out by splitting the main FPU detection routine
(fpu__cpu_init()) into two parts: fpu__init_system() for
one per system init activities, and fpu__init_cpu() for the
per CPU onlining init activities.
Note that xstate_init() is called from both variants for the time being,
because it has a dual nature as well. We'll fix that in upcoming patches.
Just do the split and call it as we used to before, don't introduce any
change in initialization behavior yet, beyond duplicate (and harmless)
fpu__init_cpu() and xstate_init() calls - which we'll fix in later
patches.
Reviewed-by: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
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: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-04-25 10:34:48 +08:00
|
|
|
{
|
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>
2016-01-07 06:24:51 +08:00
|
|
|
fpu__init_parse_early_param();
|
2015-04-26 21:07:18 +08:00
|
|
|
fpu__init_system_early_generic(c);
|
|
|
|
|
2015-04-26 21:36:46 +08:00
|
|
|
/*
|
|
|
|
* The FPU has to be operational for some of the
|
|
|
|
* later FPU init activities:
|
|
|
|
*/
|
x86/fpu: Split fpu__cpu_init() into early-boot and cpu-boot parts
There are two kinds of FPU initialization sequences necessary to bring FPU
functionality up: once per system bootup activities, such as detection,
feature initialization, etc. of attributes that are shared by all CPUs
in the system - and per cpu initialization sequences run when a CPU is
brought online (either during bootup or during CPU hotplug onlining),
such as CR0/CR4 register setting, etc.
The FPU code is mixing these roles together, with no clear distinction.
Start sorting this out by splitting the main FPU detection routine
(fpu__cpu_init()) into two parts: fpu__init_system() for
one per system init activities, and fpu__init_cpu() for the
per CPU onlining init activities.
Note that xstate_init() is called from both variants for the time being,
because it has a dual nature as well. We'll fix that in upcoming patches.
Just do the split and call it as we used to before, don't introduce any
change in initialization behavior yet, beyond duplicate (and harmless)
fpu__init_cpu() and xstate_init() calls - which we'll fix in later
patches.
Reviewed-by: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
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: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-04-25 10:34:48 +08:00
|
|
|
fpu__init_cpu();
|
2015-04-22 16:53:34 +08:00
|
|
|
|
2015-04-26 20:35:54 +08:00
|
|
|
fpu__init_system_generic();
|
2015-04-26 21:23:37 +08:00
|
|
|
fpu__init_system_xstate_size_legacy();
|
2015-04-25 12:52:53 +08:00
|
|
|
fpu__init_system_xstate();
|
2015-07-17 18:28:12 +08:00
|
|
|
fpu__init_task_struct_size();
|
2015-04-26 16:35:57 +08:00
|
|
|
|
2015-04-26 14:28:31 +08:00
|
|
|
fpu__init_system_ctx_switch();
|
2015-04-22 16:53:34 +08:00
|
|
|
}
|