2015-04-22 15:53:34 +07:00
|
|
|
/*
|
2015-04-26 20:36:46 +07:00
|
|
|
* x86 FPU boot time init code:
|
2015-04-22 15:53:34 +07:00
|
|
|
*/
|
2015-04-24 07:54:44 +07:00
|
|
|
#include <asm/fpu/internal.h>
|
2015-04-22 15:53:34 +07:00
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
2015-07-17 17:28:12 +07:00
|
|
|
#include <linux/sched.h>
|
|
|
|
|
2015-04-26 20:36:46 +07:00
|
|
|
/*
|
|
|
|
* Initialize the TS bit in CR0 according to the style of context-switches
|
|
|
|
* we are using:
|
|
|
|
*/
|
2015-04-26 20:32:40 +07:00
|
|
|
static void fpu__init_cpu_ctx_switch(void)
|
|
|
|
{
|
|
|
|
if (!cpu_has_eager_fpu)
|
|
|
|
stts();
|
|
|
|
else
|
|
|
|
clts();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
if (cpu_has_fxsr)
|
|
|
|
cr4_mask |= X86_CR4_OSFXSR;
|
|
|
|
if (cpu_has_xmm)
|
|
|
|
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 */
|
|
|
|
if (!cpu_has_fpu)
|
|
|
|
cr0 |= X86_CR0_EM;
|
|
|
|
write_cr0(cr0);
|
2015-04-29 15:58:03 +07:00
|
|
|
|
|
|
|
/* Flush out any pending x87 state: */
|
2015-08-22 14:52:06 +07:00
|
|
|
#ifdef CONFIG_MATH_EMULATION
|
|
|
|
if (!cpu_has_fpu)
|
|
|
|
fpstate_init_soft(¤t->thread.fpu.state.soft);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
asm volatile ("fninit");
|
2015-04-26 20:32:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-04-26 20:36:46 +07:00
|
|
|
* Enable all supported FPU features. Called when a CPU is brought online:
|
2015-04-26 20:32:40 +07:00
|
|
|
*/
|
|
|
|
void fpu__init_cpu(void)
|
|
|
|
{
|
|
|
|
fpu__init_cpu_generic();
|
|
|
|
fpu__init_cpu_xstate();
|
|
|
|
fpu__init_cpu_ctx_switch();
|
|
|
|
}
|
|
|
|
|
2015-04-26 19:40:54 +07:00
|
|
|
/*
|
2015-04-26 20:07:18 +07:00
|
|
|
* The earliest FPU detection code.
|
|
|
|
*
|
|
|
|
* Set the X86_FEATURE_FPU CPU-capability bit based on
|
|
|
|
* trying to execute an actual sequence of FPU instructions:
|
2015-04-26 19:40:54 +07:00
|
|
|
*/
|
|
|
|
static void fpu__init_system_early_generic(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
unsigned long cr0;
|
|
|
|
u16 fsw, fcw;
|
|
|
|
|
|
|
|
fsw = fcw = 0xffff;
|
|
|
|
|
|
|
|
cr0 = read_cr0();
|
|
|
|
cr0 &= ~(X86_CR0_TS | X86_CR0_EM);
|
|
|
|
write_cr0(cr0);
|
|
|
|
|
|
|
|
asm volatile("fninit ; fnstsw %0 ; fnstcw %1"
|
|
|
|
: "+m" (fsw), "+m" (fcw));
|
|
|
|
|
|
|
|
if (fsw == 0 && (fcw & 0x103f) == 0x003f)
|
|
|
|
set_cpu_cap(c, X86_FEATURE_FPU);
|
|
|
|
else
|
|
|
|
clear_cpu_cap(c, X86_FEATURE_FPU);
|
2015-04-26 19:43:44 +07:00
|
|
|
|
|
|
|
#ifndef CONFIG_MATH_EMULATION
|
|
|
|
if (!cpu_has_fpu) {
|
2015-04-26 20:36:46 +07:00
|
|
|
pr_emerg("x86/fpu: Giving up, no FPU found and no math emulation present\n");
|
2015-04-26 19:43:44 +07:00
|
|
|
for (;;)
|
|
|
|
asm volatile("hlt");
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-26 19:40:54 +07:00
|
|
|
}
|
|
|
|
|
2015-04-22 18:44:25 +07:00
|
|
|
/*
|
|
|
|
* Boot time FPU feature detection code:
|
|
|
|
*/
|
2015-04-22 15:53:34 +07:00
|
|
|
unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu;
|
2015-04-24 15:49:11 +07:00
|
|
|
|
2015-05-04 14:52:42 +07:00
|
|
|
static void __init fpu__init_system_mxcsr(void)
|
2015-04-22 15:53:34 +07:00
|
|
|
{
|
2015-04-24 15:49:11 +07:00
|
|
|
unsigned int mask = 0;
|
2015-04-22 15:53:34 +07:00
|
|
|
|
|
|
|
if (cpu_has_fxsr) {
|
2015-07-04 14:58:19 +07:00
|
|
|
/* Static because GCC does not get 16-byte stack alignment right: */
|
|
|
|
static struct fxregs_state fxregs __initdata;
|
2015-04-24 15:49:11 +07:00
|
|
|
|
2015-07-04 14:58:19 +07:00
|
|
|
asm volatile("fxsave %0" : "+m" (fxregs));
|
2015-04-24 15:49:11 +07:00
|
|
|
|
2015-07-04 14:58:19 +07:00
|
|
|
mask = fxregs.mxcsr_mask;
|
2015-04-24 15:49:11 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If zero then use the default features mask,
|
|
|
|
* which has all features set, except the
|
|
|
|
* denormals-are-zero feature bit:
|
|
|
|
*/
|
2015-04-22 15:53:34 +07:00
|
|
|
if (mask == 0)
|
|
|
|
mask = 0x0000ffbf;
|
|
|
|
}
|
|
|
|
mxcsr_feature_mask &= mask;
|
|
|
|
}
|
|
|
|
|
2015-04-26 19:35:54 +07:00
|
|
|
/*
|
|
|
|
* Once per bootup FPU initialization sequences that will run on most x86 CPUs:
|
|
|
|
*/
|
2015-05-04 14:52:42 +07:00
|
|
|
static void __init fpu__init_system_generic(void)
|
2015-04-26 19:35:54 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set up the legacy init FPU context. (xstate init might overwrite this
|
|
|
|
* with a more modern format, if the CPU supports it.)
|
|
|
|
*/
|
2015-04-30 16:07:06 +07:00
|
|
|
fpstate_init_fxstate(&init_fpstate.fxsave);
|
2015-04-26 19:35:54 +07:00
|
|
|
|
|
|
|
fpu__init_system_mxcsr();
|
|
|
|
}
|
|
|
|
|
2015-04-26 20:36:46 +07: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:
|
|
|
|
*/
|
2015-04-26 20:32:40 +07:00
|
|
|
unsigned int xstate_size;
|
|
|
|
EXPORT_SYMBOL_GPL(xstate_size);
|
|
|
|
|
2015-07-17 17:28:12 +07:00
|
|
|
/* Enforce that 'MEMBER' is the last field of 'TYPE': */
|
|
|
|
#define CHECK_MEMBER_AT_END_OF(TYPE, MEMBER) \
|
|
|
|
BUILD_BUG_ON(sizeof(TYPE) != offsetofend(TYPE, MEMBER))
|
2015-07-17 17:28:11 +07:00
|
|
|
|
|
|
|
/*
|
2015-07-17 17:28:12 +07:00
|
|
|
* We append the 'struct fpu' to the task_struct:
|
2015-07-17 17:28:11 +07:00
|
|
|
*/
|
2015-07-17 17:28:12 +07:00
|
|
|
static void __init fpu__init_task_struct_size(void)
|
2015-07-17 17:28:11 +07: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.
|
|
|
|
*/
|
|
|
|
task_size += xstate_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 17:28:12 +07:00
|
|
|
arch_task_struct_size = task_size;
|
2015-07-17 17:28:11 +07:00
|
|
|
}
|
|
|
|
|
2015-04-26 20:32:40 +07:00
|
|
|
/*
|
|
|
|
* Set up the xstate_size based on the legacy FPU context size.
|
|
|
|
*
|
|
|
|
* 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 14:52:42 +07:00
|
|
|
static void __init fpu__init_system_xstate_size_legacy(void)
|
2015-04-22 15:53:34 +07:00
|
|
|
{
|
2015-05-05 16:34:49 +07:00
|
|
|
static int on_boot_cpu = 1;
|
|
|
|
|
|
|
|
WARN_ON_FPU(!on_boot_cpu);
|
|
|
|
on_boot_cpu = 0;
|
|
|
|
|
2015-04-22 15:53:34 +07:00
|
|
|
/*
|
|
|
|
* Note that xstate_size might be overwriten later during
|
2015-04-25 11:52:53 +07:00
|
|
|
* fpu__init_system_xstate().
|
2015-04-22 15:53:34 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!cpu_has_fpu) {
|
|
|
|
/*
|
|
|
|
* 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);
|
2015-04-30 22:15:32 +07:00
|
|
|
xstate_size = sizeof(struct swregs_state);
|
2015-04-25 09:29:26 +07:00
|
|
|
} else {
|
|
|
|
if (cpu_has_fxsr)
|
2015-04-30 22:15:32 +07:00
|
|
|
xstate_size = sizeof(struct fxregs_state);
|
2015-04-25 09:29:26 +07:00
|
|
|
else
|
2015-04-30 22:15:32 +07:00
|
|
|
xstate_size = sizeof(struct fregs_state);
|
2015-04-22 15:53:34 +07:00
|
|
|
}
|
2015-05-20 16:59:45 +07:00
|
|
|
/*
|
|
|
|
* Quirk: we don't yet handle the XSAVES* instructions
|
|
|
|
* correctly, as we don't correctly convert between
|
|
|
|
* standard and compacted format when interfacing
|
|
|
|
* with user-space - so disable it for now.
|
|
|
|
*
|
|
|
|
* The difference is small: with recent CPUs the
|
|
|
|
* compacted format is only marginally smaller than
|
|
|
|
* the standard FPU state format.
|
|
|
|
*
|
|
|
|
* ( This is easy to backport while we are fixing
|
|
|
|
* XSAVES* support. )
|
|
|
|
*/
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVES);
|
2015-04-22 15:53:34 +07:00
|
|
|
}
|
|
|
|
|
2015-04-26 20:36:46 +07:00
|
|
|
/*
|
|
|
|
* FPU context switching strategies:
|
|
|
|
*
|
|
|
|
* Against popular belief, we don't do lazy FPU saves, due to the
|
|
|
|
* task migration complications it brings on SMP - we only do
|
|
|
|
* lazy FPU restores.
|
|
|
|
*
|
|
|
|
* 'lazy' is the traditional strategy, which is based on setting
|
|
|
|
* CR0::TS to 1 during context-switch (instead of doing a full
|
|
|
|
* restore of the FPU state), which causes the first FPU instruction
|
|
|
|
* after the context switch (whenever it is executed) to fault - at
|
|
|
|
* which point we lazily restore the FPU state into FPU registers.
|
|
|
|
*
|
|
|
|
* Tasks are of course under no obligation to execute FPU instructions,
|
|
|
|
* so it can easily happen that another context-switch occurs without
|
|
|
|
* a single FPU instruction being executed. If we eventually switch
|
|
|
|
* back to the original task (that still owns the FPU) then we have
|
|
|
|
* not only saved the restores along the way, but we also have the
|
|
|
|
* FPU ready to be used for the original task.
|
|
|
|
*
|
|
|
|
* 'eager' switching is used on modern CPUs, there we switch the FPU
|
|
|
|
* state during every context switch, regardless of whether the task
|
|
|
|
* has used FPU instructions in that time slice or not. This is done
|
|
|
|
* because modern FPU context saving instructions are able to optimize
|
|
|
|
* state saving and restoration in hardware: they can detect both
|
|
|
|
* unused and untouched FPU state and optimize accordingly.
|
|
|
|
*
|
|
|
|
* [ Note that even in 'lazy' mode we might optimize context switches
|
|
|
|
* to use 'eager' restores, if we detect that a task is using the FPU
|
|
|
|
* frequently. See the fpu->counter logic in fpu/internal.h for that. ]
|
|
|
|
*/
|
2015-04-26 01:11:05 +07:00
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
2015-04-26 20:36:46 +07:00
|
|
|
* Pick the FPU context switching strategy:
|
2015-04-26 01:11:05 +07:00
|
|
|
*/
|
2015-05-04 14:52:42 +07:00
|
|
|
static void __init fpu__init_system_ctx_switch(void)
|
2015-04-26 01:11:05 +07:00
|
|
|
{
|
2015-05-05 16:34:49 +07:00
|
|
|
static bool on_boot_cpu = 1;
|
|
|
|
|
|
|
|
WARN_ON_FPU(!on_boot_cpu);
|
|
|
|
on_boot_cpu = 0;
|
|
|
|
|
|
|
|
WARN_ON_FPU(current->thread.fpu.fpstate_active);
|
2015-04-26 01:11:05 +07:00
|
|
|
current_thread_info()->status = 0;
|
|
|
|
|
|
|
|
/* Auto enable eagerfpu for xsaveopt */
|
|
|
|
if (cpu_has_xsaveopt && eagerfpu != DISABLE)
|
|
|
|
eagerfpu = ENABLE;
|
|
|
|
|
2015-09-03 06:31:26 +07:00
|
|
|
if (xfeatures_mask & XFEATURE_MASK_EAGER) {
|
2015-04-26 01:11:05 +07:00
|
|
|
if (eagerfpu == DISABLE) {
|
|
|
|
pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n",
|
2015-09-03 06:31:26 +07:00
|
|
|
xfeatures_mask & XFEATURE_MASK_EAGER);
|
|
|
|
xfeatures_mask &= ~XFEATURE_MASK_EAGER;
|
2015-04-26 01:11:05 +07:00
|
|
|
} else {
|
|
|
|
eagerfpu = ENABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eagerfpu == ENABLE)
|
|
|
|
setup_force_cpu_cap(X86_FEATURE_EAGER_FPU);
|
|
|
|
|
2015-05-04 14:52:42 +07:00
|
|
|
printk(KERN_INFO "x86/fpu: Using '%s' FPU context switches.\n", eagerfpu == ENABLE ? "eager" : "lazy");
|
2015-04-26 01:11:05 +07: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 09:34:48 +07:00
|
|
|
/*
|
2015-04-26 20:36:46 +07: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 09:34:48 +07:00
|
|
|
*/
|
2015-05-04 14:52:42 +07: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 09:34:48 +07:00
|
|
|
{
|
2015-04-26 20:07:18 +07:00
|
|
|
fpu__init_system_early_generic(c);
|
|
|
|
|
2015-04-26 20:36:46 +07: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 09:34:48 +07:00
|
|
|
fpu__init_cpu();
|
2015-04-22 15:53:34 +07:00
|
|
|
|
2015-04-25 13:27:44 +07:00
|
|
|
/*
|
2015-04-26 20:36:46 +07:00
|
|
|
* But don't leave CR0::TS set yet, as some of the FPU setup
|
|
|
|
* methods depend on being able to execute FPU instructions
|
|
|
|
* that will fault on a set TS, such as the FXSAVE in
|
|
|
|
* fpu__init_system_mxcsr().
|
2015-04-25 13:27:44 +07:00
|
|
|
*/
|
|
|
|
clts();
|
|
|
|
|
2015-04-26 19:35:54 +07:00
|
|
|
fpu__init_system_generic();
|
2015-04-26 20:23:37 +07:00
|
|
|
fpu__init_system_xstate_size_legacy();
|
2015-04-25 11:52:53 +07:00
|
|
|
fpu__init_system_xstate();
|
2015-07-17 17:28:12 +07:00
|
|
|
fpu__init_task_struct_size();
|
2015-04-26 15:35:57 +07:00
|
|
|
|
2015-04-26 13:28:31 +07:00
|
|
|
fpu__init_system_ctx_switch();
|
2015-04-22 15:53:34 +07:00
|
|
|
}
|
2015-04-22 16:36:14 +07:00
|
|
|
|
2015-04-26 20:36:46 +07:00
|
|
|
/*
|
|
|
|
* Boot parameter to turn off FPU support and fall back to math-emu:
|
|
|
|
*/
|
2015-04-22 16:36:14 +07:00
|
|
|
static int __init no_387(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_FPU);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("no387", no_387);
|
2015-05-20 16:35:02 +07:00
|
|
|
|
2015-05-20 16:39:35 +07:00
|
|
|
/*
|
|
|
|
* Disable all xstate CPU features:
|
|
|
|
*/
|
|
|
|
static int __init x86_noxsave_setup(char *s)
|
2015-05-20 16:35:02 +07:00
|
|
|
{
|
|
|
|
if (strlen(s))
|
|
|
|
return 0;
|
2015-05-20 16:39:35 +07:00
|
|
|
|
2015-09-03 06:31:24 +07:00
|
|
|
fpu__xstate_clear_all_cpu_caps();
|
2015-05-20 16:39:35 +07:00
|
|
|
|
2015-05-20 16:35:02 +07:00
|
|
|
return 1;
|
|
|
|
}
|
2015-05-20 16:39:35 +07:00
|
|
|
__setup("noxsave", x86_noxsave_setup);
|
2015-05-20 16:35:02 +07:00
|
|
|
|
2015-05-20 16:39:35 +07:00
|
|
|
/*
|
|
|
|
* Disable the XSAVEOPT instruction specifically:
|
|
|
|
*/
|
|
|
|
static int __init x86_noxsaveopt_setup(char *s)
|
2015-05-20 16:35:02 +07:00
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
|
2015-05-20 16:39:35 +07:00
|
|
|
|
2015-05-20 16:35:02 +07:00
|
|
|
return 1;
|
|
|
|
}
|
2015-05-20 16:39:35 +07:00
|
|
|
__setup("noxsaveopt", x86_noxsaveopt_setup);
|
2015-05-20 16:35:02 +07:00
|
|
|
|
2015-05-20 16:39:35 +07:00
|
|
|
/*
|
|
|
|
* Disable the XSAVES instruction:
|
|
|
|
*/
|
|
|
|
static int __init x86_noxsaves_setup(char *s)
|
2015-05-20 16:35:02 +07:00
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVES);
|
2015-05-20 16:39:35 +07:00
|
|
|
|
2015-05-20 16:35:02 +07:00
|
|
|
return 1;
|
|
|
|
}
|
2015-05-20 16:39:35 +07:00
|
|
|
__setup("noxsaves", x86_noxsaves_setup);
|
2015-05-20 16:35:02 +07:00
|
|
|
|
2015-05-20 16:39:35 +07:00
|
|
|
/*
|
|
|
|
* Disable FX save/restore and SSE support:
|
|
|
|
*/
|
|
|
|
static int __init x86_nofxsr_setup(char *s)
|
2015-05-20 16:35:02 +07:00
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_FXSR);
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XMM);
|
2015-05-20 16:39:35 +07:00
|
|
|
|
2015-05-20 16:35:02 +07:00
|
|
|
return 1;
|
|
|
|
}
|
2015-05-20 16:39:35 +07:00
|
|
|
__setup("nofxsr", x86_nofxsr_setup);
|