Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1994 Linus Torvalds |
| 3 | * |
| 4 | * Pentium III FXSR, SSE support |
| 5 | * General FPU state handling cleanups |
| 6 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
| 7 | * x86-64 work by Andi Kleen 2002 |
| 8 | */ |
| 9 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 10 | #ifndef _ASM_X86_I387_H |
| 11 | #define _ASM_X86_I387_H |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 12 | |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/kernel_stat.h> |
| 15 | #include <linux/regset.h> |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 16 | #include <linux/hardirq.h> |
H. Peter Anvin | 92c37fa | 2008-02-04 16:47:58 +0100 | [diff] [blame] | 17 | #include <asm/asm.h> |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 18 | #include <asm/processor.h> |
| 19 | #include <asm/sigcontext.h> |
| 20 | #include <asm/user.h> |
| 21 | #include <asm/uaccess.h> |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 22 | #include <asm/xsave.h> |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 23 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 24 | extern unsigned int sig_xstate_size; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 25 | extern void fpu_init(void); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 26 | extern void mxcsr_feature_mask_init(void); |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 27 | extern int init_fpu(struct task_struct *child); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 28 | extern asmlinkage void math_state_restore(void); |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 29 | extern void init_thread_xstate(void); |
Jaswinder Singh | 3645493 | 2008-07-21 22:31:57 +0530 | [diff] [blame] | 30 | extern int dump_fpu(struct pt_regs *, struct user_i387_struct *); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 31 | |
| 32 | extern user_regset_active_fn fpregs_active, xfpregs_active; |
| 33 | extern user_regset_get_fn fpregs_get, xfpregs_get, fpregs_soft_get; |
| 34 | extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set; |
| 35 | |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 36 | extern struct _fpx_sw_bytes fx_sw_reserved; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 37 | #ifdef CONFIG_IA32_EMULATION |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 38 | extern unsigned int sig_xstate_ia32_size; |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 39 | extern struct _fpx_sw_bytes fx_sw_reserved_ia32; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 40 | struct _fpstate_ia32; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 41 | struct _xstate_ia32; |
| 42 | extern int save_i387_xstate_ia32(void __user *buf); |
| 43 | extern int restore_i387_xstate_ia32(void __user *buf); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 44 | #endif |
| 45 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 46 | #define X87_FSW_ES (1 << 7) /* Exception Summary */ |
| 47 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 48 | #ifdef CONFIG_X86_64 |
| 49 | |
| 50 | /* Ignore delayed exceptions from user space */ |
| 51 | static inline void tolerant_fwait(void) |
| 52 | { |
| 53 | asm volatile("1: fwait\n" |
| 54 | "2:\n" |
Joe Perches | affe663 | 2008-03-23 01:02:18 -0700 | [diff] [blame] | 55 | _ASM_EXTABLE(1b, 2b)); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 58 | static inline int fxrstor_checking(struct i387_fxsave_struct *fx) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 59 | { |
| 60 | int err; |
| 61 | |
| 62 | asm volatile("1: rex64/fxrstor (%[fx])\n\t" |
| 63 | "2:\n" |
| 64 | ".section .fixup,\"ax\"\n" |
| 65 | "3: movl $-1,%[err]\n" |
| 66 | " jmp 2b\n" |
| 67 | ".previous\n" |
Joe Perches | affe663 | 2008-03-23 01:02:18 -0700 | [diff] [blame] | 68 | _ASM_EXTABLE(1b, 3b) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 69 | : [err] "=r" (err) |
Jiri Slaby | 4ecf458 | 2009-04-08 13:32:00 +0200 | [diff] [blame] | 70 | #if 0 /* See comment in fxsave() below. */ |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 71 | : [fx] "r" (fx), "m" (*fx), "0" (0)); |
| 72 | #else |
| 73 | : [fx] "cdaSDb" (fx), "m" (*fx), "0" (0)); |
| 74 | #endif |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 75 | return err; |
| 76 | } |
| 77 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 78 | /* AMD CPUs don't save/restore FDP/FIP/FOP unless an exception |
| 79 | is pending. Clear the x87 state here by setting it to fixed |
| 80 | values. The kernel data segment can be sometimes 0 and sometimes |
| 81 | new user value. Both should be ok. |
| 82 | Use the PDA as safe address because it should be already in L1. */ |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 83 | static inline void clear_fpu_state(struct task_struct *tsk) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 84 | { |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 85 | struct xsave_struct *xstate = &tsk->thread.xstate->xsave; |
| 86 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; |
| 87 | |
| 88 | /* |
| 89 | * xsave header may indicate the init state of the FP. |
| 90 | */ |
| 91 | if ((task_thread_info(tsk)->status & TS_XSAVE) && |
| 92 | !(xstate->xsave_hdr.xstate_bv & XSTATE_FP)) |
| 93 | return; |
| 94 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 95 | if (unlikely(fx->swd & X87_FSW_ES)) |
Joe Perches | affe663 | 2008-03-23 01:02:18 -0700 | [diff] [blame] | 96 | asm volatile("fnclex"); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 97 | alternative_input(ASM_NOP8 ASM_NOP2, |
Joe Perches | affe663 | 2008-03-23 01:02:18 -0700 | [diff] [blame] | 98 | " emms\n" /* clear stack tags */ |
| 99 | " fildl %%gs:0", /* load to clear state */ |
| 100 | X86_FEATURE_FXSAVE_LEAK); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 103 | static inline int fxsave_user(struct i387_fxsave_struct __user *fx) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 104 | { |
| 105 | int err; |
| 106 | |
| 107 | asm volatile("1: rex64/fxsave (%[fx])\n\t" |
| 108 | "2:\n" |
| 109 | ".section .fixup,\"ax\"\n" |
| 110 | "3: movl $-1,%[err]\n" |
| 111 | " jmp 2b\n" |
| 112 | ".previous\n" |
Joe Perches | affe663 | 2008-03-23 01:02:18 -0700 | [diff] [blame] | 113 | _ASM_EXTABLE(1b, 3b) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 114 | : [err] "=r" (err), "=m" (*fx) |
Jiri Slaby | 4ecf458 | 2009-04-08 13:32:00 +0200 | [diff] [blame] | 115 | #if 0 /* See comment in fxsave() below. */ |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 116 | : [fx] "r" (fx), "0" (0)); |
| 117 | #else |
| 118 | : [fx] "cdaSDb" (fx), "0" (0)); |
| 119 | #endif |
Joe Perches | affe663 | 2008-03-23 01:02:18 -0700 | [diff] [blame] | 120 | if (unlikely(err) && |
| 121 | __clear_user(fx, sizeof(struct i387_fxsave_struct))) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 122 | err = -EFAULT; |
| 123 | /* No need to clear here because the caller clears USED_MATH */ |
| 124 | return err; |
| 125 | } |
| 126 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 127 | static inline void fxsave(struct task_struct *tsk) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 128 | { |
| 129 | /* Using "rex64; fxsave %0" is broken because, if the memory operand |
| 130 | uses any extended registers for addressing, a second REX prefix |
| 131 | will be generated (to the assembler, rex64 followed by semicolon |
| 132 | is a separate instruction), and hence the 64-bitness is lost. */ |
| 133 | #if 0 |
| 134 | /* Using "fxsaveq %0" would be the ideal choice, but is only supported |
| 135 | starting with gas 2.16. */ |
| 136 | __asm__ __volatile__("fxsaveq %0" |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 137 | : "=m" (tsk->thread.xstate->fxsave)); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 138 | #elif 0 |
| 139 | /* Using, as a workaround, the properly prefixed form below isn't |
| 140 | accepted by any binutils version so far released, complaining that |
| 141 | the same type of prefix is used twice if an extended register is |
| 142 | needed for addressing (fix submitted to mainline 2005-11-21). */ |
| 143 | __asm__ __volatile__("rex64/fxsave %0" |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 144 | : "=m" (tsk->thread.xstate->fxsave)); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 145 | #else |
| 146 | /* This, however, we can work around by forcing the compiler to select |
| 147 | an addressing mode that doesn't require extended registers. */ |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 148 | __asm__ __volatile__("rex64/fxsave (%1)" |
| 149 | : "=m" (tsk->thread.xstate->fxsave) |
| 150 | : "cdaSDb" (&tsk->thread.xstate->fxsave)); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 151 | #endif |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static inline void __save_init_fpu(struct task_struct *tsk) |
| 155 | { |
| 156 | if (task_thread_info(tsk)->status & TS_XSAVE) |
| 157 | xsave(tsk); |
| 158 | else |
| 159 | fxsave(tsk); |
| 160 | |
| 161 | clear_fpu_state(tsk); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 162 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
| 163 | } |
| 164 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 165 | #else /* CONFIG_X86_32 */ |
| 166 | |
Daniel Glöckner | ab9e185 | 2009-03-04 19:42:27 +0100 | [diff] [blame] | 167 | #ifdef CONFIG_MATH_EMULATION |
| 168 | extern void finit_task(struct task_struct *tsk); |
| 169 | #else |
| 170 | static inline void finit_task(struct task_struct *tsk) |
| 171 | { |
| 172 | } |
| 173 | #endif |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 174 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 175 | static inline void tolerant_fwait(void) |
| 176 | { |
| 177 | asm volatile("fnclex ; fwait"); |
| 178 | } |
| 179 | |
Jiri Slaby | 34ba476 | 2009-04-08 13:31:59 +0200 | [diff] [blame] | 180 | /* perform fxrstor iff the processor has extended states, otherwise frstor */ |
| 181 | static inline int fxrstor_checking(struct i387_fxsave_struct *fx) |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 182 | { |
| 183 | /* |
| 184 | * The "nop" is needed to make the instructions the same |
| 185 | * length. |
| 186 | */ |
| 187 | alternative_input( |
| 188 | "nop ; frstor %1", |
| 189 | "fxrstor %1", |
| 190 | X86_FEATURE_FXSR, |
Jiri Slaby | 34ba476 | 2009-04-08 13:31:59 +0200 | [diff] [blame] | 191 | "m" (*fx)); |
| 192 | |
Jiri Slaby | fcb2ac5 | 2009-04-08 13:31:58 +0200 | [diff] [blame] | 193 | return 0; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* We need a safe address that is cheap to find and that is already |
| 197 | in L1 during context switch. The best choices are unfortunately |
| 198 | different for UP and SMP */ |
| 199 | #ifdef CONFIG_SMP |
| 200 | #define safe_address (__per_cpu_offset[0]) |
| 201 | #else |
| 202 | #define safe_address (kstat_cpu(0).cpustat.user) |
| 203 | #endif |
| 204 | |
| 205 | /* |
| 206 | * These must be called with preempt disabled |
| 207 | */ |
| 208 | static inline void __save_init_fpu(struct task_struct *tsk) |
| 209 | { |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 210 | if (task_thread_info(tsk)->status & TS_XSAVE) { |
| 211 | struct xsave_struct *xstate = &tsk->thread.xstate->xsave; |
| 212 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; |
| 213 | |
| 214 | xsave(tsk); |
| 215 | |
| 216 | /* |
| 217 | * xsave header may indicate the init state of the FP. |
| 218 | */ |
| 219 | if (!(xstate->xsave_hdr.xstate_bv & XSTATE_FP)) |
| 220 | goto end; |
| 221 | |
| 222 | if (unlikely(fx->swd & X87_FSW_ES)) |
| 223 | asm volatile("fnclex"); |
| 224 | |
| 225 | /* |
| 226 | * we can do a simple return here or be paranoid :) |
| 227 | */ |
| 228 | goto clear_state; |
| 229 | } |
| 230 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 231 | /* Use more nops than strictly needed in case the compiler |
| 232 | varies code */ |
| 233 | alternative_input( |
| 234 | "fnsave %[fx] ;fwait;" GENERIC_NOP8 GENERIC_NOP4, |
| 235 | "fxsave %[fx]\n" |
| 236 | "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:", |
| 237 | X86_FEATURE_FXSR, |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 238 | [fx] "m" (tsk->thread.xstate->fxsave), |
| 239 | [fsw] "m" (tsk->thread.xstate->fxsave.swd) : "memory"); |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 240 | clear_state: |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 241 | /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception |
| 242 | is pending. Clear the x87 state here by setting it to fixed |
| 243 | values. safe_address is a random variable that should be in L1 */ |
| 244 | alternative_input( |
| 245 | GENERIC_NOP8 GENERIC_NOP2, |
| 246 | "emms\n\t" /* clear stack tags */ |
| 247 | "fildl %[addr]", /* set F?P to defined value */ |
| 248 | X86_FEATURE_FXSAVE_LEAK, |
| 249 | [addr] "m" (safe_address)); |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 250 | end: |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 251 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
| 252 | } |
| 253 | |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 254 | #endif /* CONFIG_X86_64 */ |
| 255 | |
Jiri Slaby | 34ba476 | 2009-04-08 13:31:59 +0200 | [diff] [blame] | 256 | static inline int restore_fpu_checking(struct task_struct *tsk) |
| 257 | { |
| 258 | if (task_thread_info(tsk)->status & TS_XSAVE) |
| 259 | return xrstor_checking(&tsk->thread.xstate->xsave); |
| 260 | else |
| 261 | return fxrstor_checking(&tsk->thread.xstate->fxsave); |
| 262 | } |
| 263 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 264 | /* |
| 265 | * Signal frame handlers... |
| 266 | */ |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 267 | extern int save_i387_xstate(void __user *buf); |
| 268 | extern int restore_i387_xstate(void __user *buf); |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 269 | |
| 270 | static inline void __unlazy_fpu(struct task_struct *tsk) |
| 271 | { |
| 272 | if (task_thread_info(tsk)->status & TS_USEDFPU) { |
| 273 | __save_init_fpu(tsk); |
| 274 | stts(); |
| 275 | } else |
| 276 | tsk->fpu_counter = 0; |
| 277 | } |
| 278 | |
| 279 | static inline void __clear_fpu(struct task_struct *tsk) |
| 280 | { |
| 281 | if (task_thread_info(tsk)->status & TS_USEDFPU) { |
| 282 | tolerant_fwait(); |
| 283 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
| 284 | stts(); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | static inline void kernel_fpu_begin(void) |
| 289 | { |
| 290 | struct thread_info *me = current_thread_info(); |
| 291 | preempt_disable(); |
| 292 | if (me->status & TS_USEDFPU) |
| 293 | __save_init_fpu(me->task); |
| 294 | else |
| 295 | clts(); |
| 296 | } |
| 297 | |
| 298 | static inline void kernel_fpu_end(void) |
| 299 | { |
| 300 | stts(); |
| 301 | preempt_enable(); |
| 302 | } |
| 303 | |
Huang Ying | ae4b688 | 2009-08-31 13:11:54 +0800 | [diff] [blame^] | 304 | static inline bool irq_fpu_usable(void) |
| 305 | { |
| 306 | struct pt_regs *regs; |
| 307 | |
| 308 | return !in_interrupt() || !(regs = get_irq_regs()) || \ |
| 309 | user_mode(regs) || (read_cr0() & X86_CR0_TS); |
| 310 | } |
| 311 | |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 312 | /* |
| 313 | * Some instructions like VIA's padlock instructions generate a spurious |
| 314 | * DNA fault but don't modify SSE registers. And these instructions |
Chuck Ebbert | 0b8c3d5 | 2009-06-09 10:40:50 -0400 | [diff] [blame] | 315 | * get used from interrupt context as well. To prevent these kernel instructions |
| 316 | * in interrupt context interacting wrongly with other user/kernel fpu usage, we |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 317 | * should use them only in the context of irq_ts_save/restore() |
| 318 | */ |
| 319 | static inline int irq_ts_save(void) |
| 320 | { |
| 321 | /* |
Chuck Ebbert | 0b8c3d5 | 2009-06-09 10:40:50 -0400 | [diff] [blame] | 322 | * If in process context and not atomic, we can take a spurious DNA fault. |
| 323 | * Otherwise, doing clts() in process context requires disabling preemption |
| 324 | * or some heavy lifting like kernel_fpu_begin() |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 325 | */ |
Chuck Ebbert | 0b8c3d5 | 2009-06-09 10:40:50 -0400 | [diff] [blame] | 326 | if (!in_atomic()) |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 327 | return 0; |
| 328 | |
| 329 | if (read_cr0() & X86_CR0_TS) { |
| 330 | clts(); |
| 331 | return 1; |
| 332 | } |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static inline void irq_ts_restore(int TS_state) |
| 338 | { |
| 339 | if (TS_state) |
| 340 | stts(); |
| 341 | } |
| 342 | |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 343 | #ifdef CONFIG_X86_64 |
| 344 | |
| 345 | static inline void save_init_fpu(struct task_struct *tsk) |
| 346 | { |
| 347 | __save_init_fpu(tsk); |
| 348 | stts(); |
| 349 | } |
| 350 | |
| 351 | #define unlazy_fpu __unlazy_fpu |
| 352 | #define clear_fpu __clear_fpu |
| 353 | |
| 354 | #else /* CONFIG_X86_32 */ |
| 355 | |
| 356 | /* |
| 357 | * These disable preemption on their own and are safe |
| 358 | */ |
| 359 | static inline void save_init_fpu(struct task_struct *tsk) |
| 360 | { |
| 361 | preempt_disable(); |
| 362 | __save_init_fpu(tsk); |
| 363 | stts(); |
| 364 | preempt_enable(); |
| 365 | } |
| 366 | |
| 367 | static inline void unlazy_fpu(struct task_struct *tsk) |
| 368 | { |
| 369 | preempt_disable(); |
| 370 | __unlazy_fpu(tsk); |
| 371 | preempt_enable(); |
| 372 | } |
| 373 | |
| 374 | static inline void clear_fpu(struct task_struct *tsk) |
| 375 | { |
| 376 | preempt_disable(); |
| 377 | __clear_fpu(tsk); |
| 378 | preempt_enable(); |
| 379 | } |
| 380 | |
| 381 | #endif /* CONFIG_X86_64 */ |
| 382 | |
| 383 | /* |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 384 | * i387 state interaction |
| 385 | */ |
| 386 | static inline unsigned short get_fpu_cwd(struct task_struct *tsk) |
| 387 | { |
| 388 | if (cpu_has_fxsr) { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 389 | return tsk->thread.xstate->fxsave.cwd; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 390 | } else { |
Suresh Siddha | 1679f27 | 2008-04-16 10:27:53 +0200 | [diff] [blame] | 391 | return (unsigned short)tsk->thread.xstate->fsave.cwd; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
| 395 | static inline unsigned short get_fpu_swd(struct task_struct *tsk) |
| 396 | { |
| 397 | if (cpu_has_fxsr) { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 398 | return tsk->thread.xstate->fxsave.swd; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 399 | } else { |
Suresh Siddha | 1679f27 | 2008-04-16 10:27:53 +0200 | [diff] [blame] | 400 | return (unsigned short)tsk->thread.xstate->fsave.swd; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | static inline unsigned short get_fpu_mxcsr(struct task_struct *tsk) |
| 405 | { |
| 406 | if (cpu_has_xmm) { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 407 | return tsk->thread.xstate->fxsave.mxcsr; |
Roland McGrath | 1eeaed7 | 2008-01-30 13:31:51 +0100 | [diff] [blame] | 408 | } else { |
| 409 | return MXCSR_DEFAULT; |
| 410 | } |
| 411 | } |
| 412 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 413 | #endif /* _ASM_X86_I387_H */ |