~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/i387.h

Version: ~ [ linux-5.12-rc1 ] ~ [ linux-5.11.2 ] ~ [ linux-5.10.19 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.101 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.177 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.222 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.258 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.258 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 10 #ifndef _ASM_X86_I387_H
 11 #define _ASM_X86_I387_H
 12 
 13 #ifndef __ASSEMBLY__
 14 
 15 #include <linux/sched.h>
 16 #include <linux/hardirq.h>
 17 
 18 struct pt_regs;
 19 struct user_i387_struct;
 20 
 21 extern int init_fpu(struct task_struct *child);
 22 extern void fpu_finit(struct fpu *fpu);
 23 extern int dump_fpu(struct pt_regs *, struct user_i387_struct *);
 24 extern void math_state_restore(void);
 25 
 26 extern bool irq_fpu_usable(void);
 27 
 28 /*
 29  * Careful: __kernel_fpu_begin/end() must be called with preempt disabled
 30  * and they don't touch the preempt state on their own.
 31  * If you enable preemption after __kernel_fpu_begin(), preempt notifier
 32  * should call the __kernel_fpu_end() to prevent the kernel/user FPU
 33  * state from getting corrupted. KVM for example uses this model.
 34  *
 35  * All other cases use kernel_fpu_begin/end() which disable preemption
 36  * during kernel FPU usage.
 37  */
 38 extern void __kernel_fpu_begin(void);
 39 extern void __kernel_fpu_end(void);
 40 
 41 static inline void kernel_fpu_begin(void)
 42 {
 43         WARN_ON_ONCE(!irq_fpu_usable());
 44         preempt_disable();
 45         __kernel_fpu_begin();
 46 }
 47 
 48 static inline void kernel_fpu_end(void)
 49 {
 50         __kernel_fpu_end();
 51         preempt_enable();
 52 }
 53 
 54 /*
 55  * Some instructions like VIA's padlock instructions generate a spurious
 56  * DNA fault but don't modify SSE registers. And these instructions
 57  * get used from interrupt context as well. To prevent these kernel instructions
 58  * in interrupt context interacting wrongly with other user/kernel fpu usage, we
 59  * should use them only in the context of irq_ts_save/restore()
 60  */
 61 static inline int irq_ts_save(void)
 62 {
 63         /*
 64          * If in process context and not atomic, we can take a spurious DNA fault.
 65          * Otherwise, doing clts() in process context requires disabling preemption
 66          * or some heavy lifting like kernel_fpu_begin()
 67          */
 68         if (!in_atomic())
 69                 return 0;
 70 
 71         if (read_cr0() & X86_CR0_TS) {
 72                 clts();
 73                 return 1;
 74         }
 75 
 76         return 0;
 77 }
 78 
 79 static inline void irq_ts_restore(int TS_state)
 80 {
 81         if (TS_state)
 82                 stts();
 83 }
 84 
 85 /*
 86  * The question "does this thread have fpu access?"
 87  * is slightly racy, since preemption could come in
 88  * and revoke it immediately after the test.
 89  *
 90  * However, even in that very unlikely scenario,
 91  * we can just assume we have FPU access - typically
 92  * to save the FP state - we'll just take a #NM
 93  * fault and get the FPU access back.
 94  */
 95 static inline int user_has_fpu(void)
 96 {
 97         return current->thread.fpu.has_fpu;
 98 }
 99 
100 extern void unlazy_fpu(struct task_struct *tsk);
101 
102 #endif /* __ASSEMBLY__ */
103 
104 #endif /* _ASM_X86_I387_H */
105 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp