Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 1 | /* |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 2 | * x86 FPU boot time init code: |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 3 | */ |
Ingo Molnar | 78f7f1e | 2015-04-24 02:54:44 +0200 | [diff] [blame] | 4 | #include <asm/fpu/internal.h> |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 5 | #include <asm/tlbflush.h> |
| 6 | |
Ingo Molnar | 5aaeb5c | 2015-07-17 12:28:12 +0200 | [diff] [blame] | 7 | #include <linux/sched.h> |
| 8 | |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 9 | /* |
| 10 | * Initialize the TS bit in CR0 according to the style of context-switches |
| 11 | * we are using: |
| 12 | */ |
Ingo Molnar | 41e7841 | 2015-04-26 15:32:40 +0200 | [diff] [blame] | 13 | static void fpu__init_cpu_ctx_switch(void) |
| 14 | { |
Borislav Petkov | 362f924 | 2015-12-07 10:39:41 +0100 | [diff] [blame] | 15 | if (!boot_cpu_has(X86_FEATURE_EAGER_FPU)) |
Ingo Molnar | 41e7841 | 2015-04-26 15:32:40 +0200 | [diff] [blame] | 16 | stts(); |
| 17 | else |
| 18 | clts(); |
| 19 | } |
| 20 | |
| 21 | /* |
| 22 | * Initialize the registers found in all CPUs, CR0 and CR4: |
| 23 | */ |
| 24 | static void fpu__init_cpu_generic(void) |
| 25 | { |
| 26 | unsigned long cr0; |
| 27 | unsigned long cr4_mask = 0; |
| 28 | |
| 29 | if (cpu_has_fxsr) |
| 30 | cr4_mask |= X86_CR4_OSFXSR; |
| 31 | if (cpu_has_xmm) |
| 32 | cr4_mask |= X86_CR4_OSXMMEXCPT; |
| 33 | if (cr4_mask) |
| 34 | cr4_set_bits(cr4_mask); |
| 35 | |
| 36 | cr0 = read_cr0(); |
| 37 | cr0 &= ~(X86_CR0_TS|X86_CR0_EM); /* clear TS and EM */ |
| 38 | if (!cpu_has_fpu) |
| 39 | cr0 |= X86_CR0_EM; |
| 40 | write_cr0(cr0); |
Ingo Molnar | b1276c4 | 2015-04-29 10:58:03 +0200 | [diff] [blame] | 41 | |
| 42 | /* Flush out any pending x87 state: */ |
Ingo Molnar | 5fc9603 | 2015-08-22 09:52:06 +0200 | [diff] [blame] | 43 | #ifdef CONFIG_MATH_EMULATION |
| 44 | if (!cpu_has_fpu) |
| 45 | fpstate_init_soft(¤t->thread.fpu.state.soft); |
| 46 | else |
| 47 | #endif |
| 48 | asm volatile ("fninit"); |
Ingo Molnar | 41e7841 | 2015-04-26 15:32:40 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /* |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 52 | * Enable all supported FPU features. Called when a CPU is brought online: |
Ingo Molnar | 41e7841 | 2015-04-26 15:32:40 +0200 | [diff] [blame] | 53 | */ |
| 54 | void fpu__init_cpu(void) |
| 55 | { |
| 56 | fpu__init_cpu_generic(); |
| 57 | fpu__init_cpu_xstate(); |
| 58 | fpu__init_cpu_ctx_switch(); |
| 59 | } |
| 60 | |
Ingo Molnar | 4d16409 | 2015-04-22 13:44:25 +0200 | [diff] [blame] | 61 | /* |
Ingo Molnar | dd86388 | 2015-04-26 15:07:18 +0200 | [diff] [blame] | 62 | * The earliest FPU detection code. |
| 63 | * |
| 64 | * Set the X86_FEATURE_FPU CPU-capability bit based on |
| 65 | * trying to execute an actual sequence of FPU instructions: |
Ingo Molnar | 2e2f3da | 2015-04-26 14:40:54 +0200 | [diff] [blame] | 66 | */ |
| 67 | static void fpu__init_system_early_generic(struct cpuinfo_x86 *c) |
| 68 | { |
| 69 | unsigned long cr0; |
| 70 | u16 fsw, fcw; |
| 71 | |
| 72 | fsw = fcw = 0xffff; |
| 73 | |
| 74 | cr0 = read_cr0(); |
| 75 | cr0 &= ~(X86_CR0_TS | X86_CR0_EM); |
| 76 | write_cr0(cr0); |
| 77 | |
| 78 | asm volatile("fninit ; fnstsw %0 ; fnstcw %1" |
| 79 | : "+m" (fsw), "+m" (fcw)); |
| 80 | |
| 81 | if (fsw == 0 && (fcw & 0x103f) == 0x003f) |
| 82 | set_cpu_cap(c, X86_FEATURE_FPU); |
| 83 | else |
| 84 | clear_cpu_cap(c, X86_FEATURE_FPU); |
Ingo Molnar | e83ab9a | 2015-04-26 14:43:44 +0200 | [diff] [blame] | 85 | |
| 86 | #ifndef CONFIG_MATH_EMULATION |
| 87 | if (!cpu_has_fpu) { |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 88 | pr_emerg("x86/fpu: Giving up, no FPU found and no math emulation present\n"); |
Ingo Molnar | e83ab9a | 2015-04-26 14:43:44 +0200 | [diff] [blame] | 89 | for (;;) |
| 90 | asm volatile("hlt"); |
| 91 | } |
| 92 | #endif |
Ingo Molnar | 2e2f3da | 2015-04-26 14:40:54 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /* |
Ingo Molnar | 4d16409 | 2015-04-22 13:44:25 +0200 | [diff] [blame] | 96 | * Boot time FPU feature detection code: |
| 97 | */ |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 98 | unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu; |
Ingo Molnar | 91a8c2a | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 99 | |
Ingo Molnar | 3223187 | 2015-05-04 09:52:42 +0200 | [diff] [blame] | 100 | static void __init fpu__init_system_mxcsr(void) |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 101 | { |
Ingo Molnar | 91a8c2a | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 102 | unsigned int mask = 0; |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 103 | |
| 104 | if (cpu_has_fxsr) { |
Ingo Molnar | b96fecb | 2015-07-04 09:58:19 +0200 | [diff] [blame] | 105 | /* Static because GCC does not get 16-byte stack alignment right: */ |
| 106 | static struct fxregs_state fxregs __initdata; |
Ingo Molnar | 91a8c2a | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 107 | |
Ingo Molnar | b96fecb | 2015-07-04 09:58:19 +0200 | [diff] [blame] | 108 | asm volatile("fxsave %0" : "+m" (fxregs)); |
Ingo Molnar | 91a8c2a | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 109 | |
Ingo Molnar | b96fecb | 2015-07-04 09:58:19 +0200 | [diff] [blame] | 110 | mask = fxregs.mxcsr_mask; |
Ingo Molnar | 91a8c2a | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 111 | |
| 112 | /* |
| 113 | * If zero then use the default features mask, |
| 114 | * which has all features set, except the |
| 115 | * denormals-are-zero feature bit: |
| 116 | */ |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 117 | if (mask == 0) |
| 118 | mask = 0x0000ffbf; |
| 119 | } |
| 120 | mxcsr_feature_mask &= mask; |
| 121 | } |
| 122 | |
Ingo Molnar | 7218e8b | 2015-04-26 14:35:54 +0200 | [diff] [blame] | 123 | /* |
| 124 | * Once per bootup FPU initialization sequences that will run on most x86 CPUs: |
| 125 | */ |
Ingo Molnar | 3223187 | 2015-05-04 09:52:42 +0200 | [diff] [blame] | 126 | static void __init fpu__init_system_generic(void) |
Ingo Molnar | 7218e8b | 2015-04-26 14:35:54 +0200 | [diff] [blame] | 127 | { |
| 128 | /* |
| 129 | * Set up the legacy init FPU context. (xstate init might overwrite this |
| 130 | * with a more modern format, if the CPU supports it.) |
| 131 | */ |
Ingo Molnar | 6f57502 | 2015-04-30 11:07:06 +0200 | [diff] [blame] | 132 | fpstate_init_fxstate(&init_fpstate.fxsave); |
Ingo Molnar | 7218e8b | 2015-04-26 14:35:54 +0200 | [diff] [blame] | 133 | |
| 134 | fpu__init_system_mxcsr(); |
| 135 | } |
| 136 | |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 137 | /* |
| 138 | * Size of the FPU context state. All tasks in the system use the |
| 139 | * same context size, regardless of what portion they use. |
| 140 | * This is inherent to the XSAVE architecture which puts all state |
| 141 | * components into a single, continuous memory block: |
| 142 | */ |
Ingo Molnar | 41e7841 | 2015-04-26 15:32:40 +0200 | [diff] [blame] | 143 | unsigned int xstate_size; |
| 144 | EXPORT_SYMBOL_GPL(xstate_size); |
| 145 | |
Jiri Olsa | 25ec02f | 2015-12-21 15:25:30 +0100 | [diff] [blame] | 146 | /* Get alignment of the TYPE. */ |
| 147 | #define TYPE_ALIGN(TYPE) offsetof(struct { char x; TYPE test; }, test) |
| 148 | |
| 149 | /* |
| 150 | * Enforce that 'MEMBER' is the last field of 'TYPE'. |
| 151 | * |
| 152 | * Align the computed size with alignment of the TYPE, |
| 153 | * because that's how C aligns structs. |
| 154 | */ |
Ingo Molnar | 5aaeb5c | 2015-07-17 12:28:12 +0200 | [diff] [blame] | 155 | #define CHECK_MEMBER_AT_END_OF(TYPE, MEMBER) \ |
Jiri Olsa | 25ec02f | 2015-12-21 15:25:30 +0100 | [diff] [blame] | 156 | BUILD_BUG_ON(sizeof(TYPE) != ALIGN(offsetofend(TYPE, MEMBER), \ |
| 157 | TYPE_ALIGN(TYPE))) |
Dave Hansen | 0c8c0f0 | 2015-07-17 12:28:11 +0200 | [diff] [blame] | 158 | |
| 159 | /* |
Ingo Molnar | 5aaeb5c | 2015-07-17 12:28:12 +0200 | [diff] [blame] | 160 | * We append the 'struct fpu' to the task_struct: |
Dave Hansen | 0c8c0f0 | 2015-07-17 12:28:11 +0200 | [diff] [blame] | 161 | */ |
Ingo Molnar | 5aaeb5c | 2015-07-17 12:28:12 +0200 | [diff] [blame] | 162 | static void __init fpu__init_task_struct_size(void) |
Dave Hansen | 0c8c0f0 | 2015-07-17 12:28:11 +0200 | [diff] [blame] | 163 | { |
| 164 | int task_size = sizeof(struct task_struct); |
| 165 | |
| 166 | /* |
| 167 | * Subtract off the static size of the register state. |
| 168 | * It potentially has a bunch of padding. |
| 169 | */ |
| 170 | task_size -= sizeof(((struct task_struct *)0)->thread.fpu.state); |
| 171 | |
| 172 | /* |
| 173 | * Add back the dynamically-calculated register state |
| 174 | * size. |
| 175 | */ |
| 176 | task_size += xstate_size; |
| 177 | |
| 178 | /* |
| 179 | * We dynamically size 'struct fpu', so we require that |
| 180 | * it be at the end of 'thread_struct' and that |
| 181 | * 'thread_struct' be at the end of 'task_struct'. If |
| 182 | * you hit a compile error here, check the structure to |
| 183 | * see if something got added to the end. |
| 184 | */ |
| 185 | CHECK_MEMBER_AT_END_OF(struct fpu, state); |
| 186 | CHECK_MEMBER_AT_END_OF(struct thread_struct, fpu); |
| 187 | CHECK_MEMBER_AT_END_OF(struct task_struct, thread); |
| 188 | |
Ingo Molnar | 5aaeb5c | 2015-07-17 12:28:12 +0200 | [diff] [blame] | 189 | arch_task_struct_size = task_size; |
Dave Hansen | 0c8c0f0 | 2015-07-17 12:28:11 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Ingo Molnar | 41e7841 | 2015-04-26 15:32:40 +0200 | [diff] [blame] | 192 | /* |
| 193 | * Set up the xstate_size based on the legacy FPU context size. |
| 194 | * |
| 195 | * We set this up first, and later it will be overwritten by |
| 196 | * fpu__init_system_xstate() if the CPU knows about xstates. |
| 197 | */ |
Ingo Molnar | 3223187 | 2015-05-04 09:52:42 +0200 | [diff] [blame] | 198 | static void __init fpu__init_system_xstate_size_legacy(void) |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 199 | { |
Rasmus Villemoes | e49a449 | 2015-11-13 15:18:31 +0100 | [diff] [blame] | 200 | static int on_boot_cpu __initdata = 1; |
Ingo Molnar | e97131a | 2015-05-05 11:34:49 +0200 | [diff] [blame] | 201 | |
| 202 | WARN_ON_FPU(!on_boot_cpu); |
| 203 | on_boot_cpu = 0; |
| 204 | |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 205 | /* |
| 206 | * Note that xstate_size might be overwriten later during |
Ingo Molnar | c42103b | 2015-04-25 06:52:53 +0200 | [diff] [blame] | 207 | * fpu__init_system_xstate(). |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 208 | */ |
| 209 | |
| 210 | if (!cpu_has_fpu) { |
| 211 | /* |
| 212 | * Disable xsave as we do not support it if i387 |
| 213 | * emulation is enabled. |
| 214 | */ |
| 215 | setup_clear_cpu_cap(X86_FEATURE_XSAVE); |
| 216 | setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); |
Ingo Molnar | c47ada3 | 2015-04-30 17:15:32 +0200 | [diff] [blame] | 217 | xstate_size = sizeof(struct swregs_state); |
Ingo Molnar | 6a13320 | 2015-04-25 04:29:26 +0200 | [diff] [blame] | 218 | } else { |
| 219 | if (cpu_has_fxsr) |
Ingo Molnar | c47ada3 | 2015-04-30 17:15:32 +0200 | [diff] [blame] | 220 | xstate_size = sizeof(struct fxregs_state); |
Ingo Molnar | 6a13320 | 2015-04-25 04:29:26 +0200 | [diff] [blame] | 221 | else |
Ingo Molnar | c47ada3 | 2015-04-30 17:15:32 +0200 | [diff] [blame] | 222 | xstate_size = sizeof(struct fregs_state); |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 223 | } |
Ingo Molnar | 6f56a8d | 2015-05-20 11:59:45 +0200 | [diff] [blame] | 224 | /* |
| 225 | * Quirk: we don't yet handle the XSAVES* instructions |
| 226 | * correctly, as we don't correctly convert between |
| 227 | * standard and compacted format when interfacing |
| 228 | * with user-space - so disable it for now. |
| 229 | * |
| 230 | * The difference is small: with recent CPUs the |
| 231 | * compacted format is only marginally smaller than |
| 232 | * the standard FPU state format. |
| 233 | * |
| 234 | * ( This is easy to backport while we are fixing |
| 235 | * XSAVES* support. ) |
| 236 | */ |
| 237 | setup_clear_cpu_cap(X86_FEATURE_XSAVES); |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 240 | /* |
| 241 | * FPU context switching strategies: |
| 242 | * |
| 243 | * Against popular belief, we don't do lazy FPU saves, due to the |
| 244 | * task migration complications it brings on SMP - we only do |
| 245 | * lazy FPU restores. |
| 246 | * |
| 247 | * 'lazy' is the traditional strategy, which is based on setting |
| 248 | * CR0::TS to 1 during context-switch (instead of doing a full |
| 249 | * restore of the FPU state), which causes the first FPU instruction |
| 250 | * after the context switch (whenever it is executed) to fault - at |
| 251 | * which point we lazily restore the FPU state into FPU registers. |
| 252 | * |
| 253 | * Tasks are of course under no obligation to execute FPU instructions, |
| 254 | * so it can easily happen that another context-switch occurs without |
| 255 | * a single FPU instruction being executed. If we eventually switch |
| 256 | * back to the original task (that still owns the FPU) then we have |
| 257 | * not only saved the restores along the way, but we also have the |
| 258 | * FPU ready to be used for the original task. |
| 259 | * |
| 260 | * 'eager' switching is used on modern CPUs, there we switch the FPU |
| 261 | * state during every context switch, regardless of whether the task |
| 262 | * has used FPU instructions in that time slice or not. This is done |
| 263 | * because modern FPU context saving instructions are able to optimize |
| 264 | * state saving and restoration in hardware: they can detect both |
| 265 | * unused and untouched FPU state and optimize accordingly. |
| 266 | * |
| 267 | * [ Note that even in 'lazy' mode we might optimize context switches |
| 268 | * to use 'eager' restores, if we detect that a task is using the FPU |
| 269 | * frequently. See the fpu->counter logic in fpu/internal.h for that. ] |
| 270 | */ |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 271 | static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO; |
| 272 | |
| 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 | |
| 285 | /* |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 286 | * Pick the FPU context switching strategy: |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 287 | */ |
Ingo Molnar | 3223187 | 2015-05-04 09:52:42 +0200 | [diff] [blame] | 288 | static void __init fpu__init_system_ctx_switch(void) |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 289 | { |
Rasmus Villemoes | e49a449 | 2015-11-13 15:18:31 +0100 | [diff] [blame] | 290 | static bool on_boot_cpu __initdata = 1; |
Ingo Molnar | e97131a | 2015-05-05 11:34:49 +0200 | [diff] [blame] | 291 | |
| 292 | WARN_ON_FPU(!on_boot_cpu); |
| 293 | on_boot_cpu = 0; |
| 294 | |
| 295 | WARN_ON_FPU(current->thread.fpu.fpstate_active); |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 296 | current_thread_info()->status = 0; |
| 297 | |
| 298 | /* Auto enable eagerfpu for xsaveopt */ |
Borislav Petkov | 362f924 | 2015-12-07 10:39:41 +0100 | [diff] [blame] | 299 | if (boot_cpu_has(X86_FEATURE_XSAVEOPT) && eagerfpu != DISABLE) |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 300 | eagerfpu = ENABLE; |
| 301 | |
Dave Hansen | d91cab7 | 2015-09-02 16:31:26 -0700 | [diff] [blame] | 302 | if (xfeatures_mask & XFEATURE_MASK_EAGER) { |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 303 | if (eagerfpu == DISABLE) { |
| 304 | pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n", |
Dave Hansen | d91cab7 | 2015-09-02 16:31:26 -0700 | [diff] [blame] | 305 | xfeatures_mask & XFEATURE_MASK_EAGER); |
| 306 | xfeatures_mask &= ~XFEATURE_MASK_EAGER; |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 307 | } else { |
| 308 | eagerfpu = ENABLE; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (eagerfpu == ENABLE) |
| 313 | setup_force_cpu_cap(X86_FEATURE_EAGER_FPU); |
| 314 | |
Ingo Molnar | 3223187 | 2015-05-04 09:52:42 +0200 | [diff] [blame] | 315 | printk(KERN_INFO "x86/fpu: Using '%s' FPU context switches.\n", eagerfpu == ENABLE ? "eager" : "lazy"); |
Ingo Molnar | 6f5d265 | 2015-04-25 20:11:05 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Ingo Molnar | e35f6f1 | 2015-04-25 04:34:48 +0200 | [diff] [blame] | 318 | /* |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 319 | * Called on the boot CPU once per system bootup, to set up the initial |
| 320 | * FPU state that is later cloned into all processes: |
Ingo Molnar | e35f6f1 | 2015-04-25 04:34:48 +0200 | [diff] [blame] | 321 | */ |
Ingo Molnar | 3223187 | 2015-05-04 09:52:42 +0200 | [diff] [blame] | 322 | void __init fpu__init_system(struct cpuinfo_x86 *c) |
Ingo Molnar | e35f6f1 | 2015-04-25 04:34:48 +0200 | [diff] [blame] | 323 | { |
Ingo Molnar | dd86388 | 2015-04-26 15:07:18 +0200 | [diff] [blame] | 324 | fpu__init_system_early_generic(c); |
| 325 | |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 326 | /* |
| 327 | * The FPU has to be operational for some of the |
| 328 | * later FPU init activities: |
| 329 | */ |
Ingo Molnar | e35f6f1 | 2015-04-25 04:34:48 +0200 | [diff] [blame] | 330 | fpu__init_cpu(); |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 331 | |
Ingo Molnar | 2507e1c | 2015-04-25 08:35:53 +0200 | [diff] [blame] | 332 | /* |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 333 | * But don't leave CR0::TS set yet, as some of the FPU setup |
| 334 | * methods depend on being able to execute FPU instructions |
| 335 | * that will fault on a set TS, such as the FXSAVE in |
| 336 | * fpu__init_system_mxcsr(). |
Ingo Molnar | 530b37e | 2015-04-25 08:27:44 +0200 | [diff] [blame] | 337 | */ |
| 338 | clts(); |
| 339 | |
Ingo Molnar | 7218e8b | 2015-04-26 14:35:54 +0200 | [diff] [blame] | 340 | fpu__init_system_generic(); |
Ingo Molnar | 7638b74 | 2015-04-26 15:23:37 +0200 | [diff] [blame] | 341 | fpu__init_system_xstate_size_legacy(); |
Ingo Molnar | c42103b | 2015-04-25 06:52:53 +0200 | [diff] [blame] | 342 | fpu__init_system_xstate(); |
Ingo Molnar | 5aaeb5c | 2015-07-17 12:28:12 +0200 | [diff] [blame] | 343 | fpu__init_task_struct_size(); |
Ingo Molnar | 997578b | 2015-04-26 10:35:57 +0200 | [diff] [blame] | 344 | |
Ingo Molnar | 011545b | 2015-04-26 08:28:31 +0200 | [diff] [blame] | 345 | fpu__init_system_ctx_switch(); |
Ingo Molnar | 0c86753 | 2015-04-22 10:53:34 +0200 | [diff] [blame] | 346 | } |
Ingo Molnar | 146ed59 | 2015-04-22 11:36:14 +0200 | [diff] [blame] | 347 | |
Ingo Molnar | ae02679 | 2015-04-26 15:36:46 +0200 | [diff] [blame] | 348 | /* |
| 349 | * Boot parameter to turn off FPU support and fall back to math-emu: |
| 350 | */ |
Ingo Molnar | 146ed59 | 2015-04-22 11:36:14 +0200 | [diff] [blame] | 351 | static int __init no_387(char *s) |
| 352 | { |
| 353 | setup_clear_cpu_cap(X86_FEATURE_FPU); |
| 354 | return 1; |
| 355 | } |
Ingo Molnar | 146ed59 | 2015-04-22 11:36:14 +0200 | [diff] [blame] | 356 | __setup("no387", no_387); |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 357 | |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 358 | /* |
| 359 | * Disable all xstate CPU features: |
| 360 | */ |
| 361 | static int __init x86_noxsave_setup(char *s) |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 362 | { |
| 363 | if (strlen(s)) |
| 364 | return 0; |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 365 | |
Dave Hansen | 0a26537 | 2015-09-02 16:31:24 -0700 | [diff] [blame] | 366 | fpu__xstate_clear_all_cpu_caps(); |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 367 | |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 368 | return 1; |
| 369 | } |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 370 | __setup("noxsave", x86_noxsave_setup); |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 371 | |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 372 | /* |
| 373 | * Disable the XSAVEOPT instruction specifically: |
| 374 | */ |
| 375 | static int __init x86_noxsaveopt_setup(char *s) |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 376 | { |
| 377 | setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 378 | |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 379 | return 1; |
| 380 | } |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 381 | __setup("noxsaveopt", x86_noxsaveopt_setup); |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 382 | |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 383 | /* |
| 384 | * Disable the XSAVES instruction: |
| 385 | */ |
| 386 | static int __init x86_noxsaves_setup(char *s) |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 387 | { |
| 388 | setup_clear_cpu_cap(X86_FEATURE_XSAVES); |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 389 | |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 390 | return 1; |
| 391 | } |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 392 | __setup("noxsaves", x86_noxsaves_setup); |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 393 | |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 394 | /* |
| 395 | * Disable FX save/restore and SSE support: |
| 396 | */ |
| 397 | static int __init x86_nofxsr_setup(char *s) |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 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); |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 402 | |
Ingo Molnar | 7cf82d3 | 2015-05-20 11:35:02 +0200 | [diff] [blame] | 403 | return 1; |
| 404 | } |
Ingo Molnar | 5856afe | 2015-05-20 11:39:35 +0200 | [diff] [blame] | 405 | __setup("nofxsr", x86_nofxsr_setup); |