0001
0002 #ifndef __X86_KERNEL_FPU_CONTEXT_H
0003 #define __X86_KERNEL_FPU_CONTEXT_H
0004
0005 #include <asm/fpu/xstate.h>
0006 #include <asm/trace/fpu.h>
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 static inline void __cpu_invalidate_fpregs_state(void)
0028 {
0029 __this_cpu_write(fpu_fpregs_owner_ctx, NULL);
0030 }
0031
0032 static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
0033 {
0034 fpu->last_cpu = -1;
0035 }
0036
0037 static inline int fpregs_state_valid(struct fpu *fpu, unsigned int cpu)
0038 {
0039 return fpu == this_cpu_read(fpu_fpregs_owner_ctx) && cpu == fpu->last_cpu;
0040 }
0041
0042 static inline void fpregs_deactivate(struct fpu *fpu)
0043 {
0044 __this_cpu_write(fpu_fpregs_owner_ctx, NULL);
0045 trace_x86_fpu_regs_deactivated(fpu);
0046 }
0047
0048 static inline void fpregs_activate(struct fpu *fpu)
0049 {
0050 __this_cpu_write(fpu_fpregs_owner_ctx, fpu);
0051 trace_x86_fpu_regs_activated(fpu);
0052 }
0053
0054
0055 static inline void fpregs_restore_userregs(void)
0056 {
0057 struct fpu *fpu = ¤t->thread.fpu;
0058 int cpu = smp_processor_id();
0059
0060 if (WARN_ON_ONCE(current->flags & PF_KTHREAD))
0061 return;
0062
0063 if (!fpregs_state_valid(fpu, cpu)) {
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 restore_fpregs_from_fpstate(fpu->fpstate, XFEATURE_MASK_FPSTATE);
0076
0077 fpregs_activate(fpu);
0078 fpu->last_cpu = cpu;
0079 }
0080 clear_thread_flag(TIF_NEED_FPU_LOAD);
0081 }
0082
0083 #endif