Merge branch 'work.regset' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-2.6-microblaze.git] / arch / x86 / include / asm / fpu / internal.h
index 0c85a08..0a460f2 100644 (file)
@@ -273,7 +273,7 @@ static inline void copy_fxregs_to_kernel(struct fpu *fpu)
  */
 static inline void copy_xregs_to_kernel_booting(struct xregs_state *xstate)
 {
-       u64 mask = -1;
+       u64 mask = xfeatures_mask_all;
        u32 lmask = mask;
        u32 hmask = mask >> 32;
        int err;
@@ -319,7 +319,7 @@ static inline void copy_kernel_to_xregs_booting(struct xregs_state *xstate)
  */
 static inline void copy_xregs_to_kernel(struct xregs_state *xstate)
 {
-       u64 mask = -1;
+       u64 mask = xfeatures_mask_all;
        u32 lmask = mask;
        u32 hmask = mask >> 32;
        int err;
@@ -355,6 +355,9 @@ static inline void copy_kernel_to_xregs(struct xregs_state *xstate, u64 mask)
  */
 static inline int copy_xregs_to_user(struct xregs_state __user *buf)
 {
+       u64 mask = xfeatures_mask_user();
+       u32 lmask = mask;
+       u32 hmask = mask >> 32;
        int err;
 
        /*
@@ -366,7 +369,7 @@ static inline int copy_xregs_to_user(struct xregs_state __user *buf)
                return -EFAULT;
 
        stac();
-       XSTATE_OP(XSAVE, buf, -1, -1, err);
+       XSTATE_OP(XSAVE, buf, lmask, hmask, err);
        clac();
 
        return err;
@@ -407,43 +410,7 @@ static inline int copy_kernel_to_xregs_err(struct xregs_state *xstate, u64 mask)
        return err;
 }
 
-/*
- * These must be called with preempt disabled. Returns
- * 'true' if the FPU state is still intact and we can
- * keep registers active.
- *
- * The legacy FNSAVE instruction cleared all FPU state
- * unconditionally, so registers are essentially destroyed.
- * Modern FPU state can be kept in registers, if there are
- * no pending FP exceptions.
- */
-static inline int copy_fpregs_to_fpstate(struct fpu *fpu)
-{
-       if (likely(use_xsave())) {
-               copy_xregs_to_kernel(&fpu->state.xsave);
-
-               /*
-                * AVX512 state is tracked here because its use is
-                * known to slow the max clock speed of the core.
-                */
-               if (fpu->state.xsave.header.xfeatures & XFEATURE_MASK_AVX512)
-                       fpu->avx512_timestamp = jiffies;
-               return 1;
-       }
-
-       if (likely(use_fxsr())) {
-               copy_fxregs_to_kernel(fpu);
-               return 1;
-       }
-
-       /*
-        * Legacy FPU register saving, FNSAVE always clears FPU registers,
-        * so we have to mark them inactive:
-        */
-       asm volatile("fnsave %[fp]; fwait" : [fp] "=m" (fpu->state.fsave));
-
-       return 0;
-}
+extern int copy_fpregs_to_fpstate(struct fpu *fpu);
 
 static inline void __copy_kernel_to_fpregs(union fpregs_state *fpstate, u64 mask)
 {
@@ -622,6 +589,11 @@ static inline void switch_fpu_finish(struct fpu *new_fpu)
  * MXCSR and XCR definitions:
  */
 
+static inline void ldmxcsr(u32 mxcsr)
+{
+       asm volatile("ldmxcsr %0" :: "m" (mxcsr));
+}
+
 extern unsigned int mxcsr_feature_mask;
 
 #define XCR_XFEATURE_ENABLED_MASK      0x00000000