]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - arch/x86/kernel/fpu/core.c
x86/fpu: Change fpu->fpregs_active users to fpu->fpstate_active
[mirror_ubuntu-bionic-kernel.git] / arch / x86 / kernel / fpu / core.c
index e1114f070c2dfdedf9911cd587afb7cca1769785..eab24462240252a6ab8797112c20dc2df6fd50bb 100644 (file)
@@ -100,7 +100,7 @@ void __kernel_fpu_begin(void)
 
        kernel_fpu_disable();
 
-       if (fpu->fpregs_active) {
+       if (fpu->fpstate_active) {
                /*
                 * Ignore return value -- we don't care if reg state
                 * is clobbered.
@@ -116,7 +116,7 @@ void __kernel_fpu_end(void)
 {
        struct fpu *fpu = &current->thread.fpu;
 
-       if (fpu->fpregs_active)
+       if (fpu->fpstate_active)
                copy_kernel_to_fpregs(&fpu->state);
 
        kernel_fpu_enable();
@@ -147,8 +147,10 @@ void fpu__save(struct fpu *fpu)
        WARN_ON_FPU(fpu != &current->thread.fpu);
 
        preempt_disable();
+       WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
+
        trace_x86_fpu_before_save(fpu);
-       if (fpu->fpregs_active) {
+       if (fpu->fpstate_active) {
                if (!copy_fpregs_to_fpstate(fpu)) {
                        copy_kernel_to_fpregs(&fpu->state);
                }
@@ -262,11 +264,12 @@ EXPORT_SYMBOL_GPL(fpu__activate_curr);
  */
 void fpu__activate_fpstate_read(struct fpu *fpu)
 {
+       WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
        /*
         * If fpregs are active (in the current CPU), then
         * copy them to the fpstate:
         */
-       if (fpu->fpregs_active) {
+       if (fpu->fpstate_active) {
                fpu__save(fpu);
        } else {
                if (!fpu->fpstate_active) {
@@ -362,12 +365,13 @@ void fpu__current_fpstate_write_end(void)
 {
        struct fpu *fpu = &current->thread.fpu;
 
+       WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
        /*
         * 'fpu' now has an updated copy of the state, but the
         * registers may still be out of date.  Update them with
         * an XRSTOR if they are active.
         */
-       if (fpregs_active())
+       if (fpu->fpstate_active)
                copy_kernel_to_fpregs(&fpu->state);
 
        /*
@@ -414,12 +418,19 @@ void fpu__drop(struct fpu *fpu)
 {
        preempt_disable();
 
-       if (fpu->fpregs_active) {
-               /* Ignore delayed exceptions from user space */
-               asm volatile("1: fwait\n"
-                            "2:\n"
-                            _ASM_EXTABLE(1b, 2b));
-               fpregs_deactivate(fpu);
+       if (fpu == &current->thread.fpu) {
+               WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
+
+               if (fpu->fpstate_active) {
+                       /* Ignore delayed exceptions from user space */
+                       asm volatile("1: fwait\n"
+                                    "2:\n"
+                                    _ASM_EXTABLE(1b, 2b));
+                       if (fpu->fpregs_active)
+                               fpregs_deactivate(fpu);
+               }
+       } else {
+               WARN_ON_FPU(fpu->fpregs_active);
        }
 
        fpu->fpstate_active = 0;
@@ -462,9 +473,11 @@ void fpu__clear(struct fpu *fpu)
         * Make sure fpstate is cleared and initialized.
         */
        if (static_cpu_has(X86_FEATURE_FPU)) {
+               preempt_disable();
                fpu__activate_curr(fpu);
                user_fpu_begin();
                copy_init_fpstate_to_fpregs();
+               preempt_enable();
        }
 }