[COMMON] arm64: fpsimd: Restore FPSIMD state for user thread
authorSanghoon Lee <shoon114.lee@samsung.com>
Thu, 14 Jun 2018 05:36:02 +0000 (14:36 +0900)
committerEunyoung Lee <ey470.lee@samsung.com>
Tue, 19 Jun 2018 08:57:13 +0000 (17:57 +0900)
When user thread calls system call to kernel and kernel has overwritten the FPSIMD registers,
these registers should be restored for user when kernel completes its job.

Change-Id: Ieca1f7baa8a1b245d172bfc750517c70b999ccfa
Signed-off-by: Sanghoon Lee <shoon114.lee@samsung.com>
arch/arm64/kernel/fpsimd.c

index 805b9c746e55184fa6f9dc09fa1fad40019685b4..705ccb03008b0c78d8bdf6c88be262ff17ac25db 100644 (file)
@@ -279,6 +279,16 @@ void fpsimd_put(void)
 
        BUG_ON(atomic_dec_return(
                &current->thread.fpsimd_kernel_state.depth) < 0);
+
+       preempt_disable();
+       if (current->mm && test_thread_flag(TIF_FOREIGN_FPSTATE)
+               && atomic_read(&current->thread.fpsimd_kernel_state.depth) == 0) {
+               fpsimd_load_state(&current->thread.fpsimd_state);
+               this_cpu_write(fpsimd_last_state, &current->thread.fpsimd_state);
+               current->thread.fpsimd_state.cpu = smp_processor_id();
+               clear_thread_flag(TIF_FOREIGN_FPSTATE);
+       }
+       preempt_enable();
 }
 
 #ifdef CONFIG_KERNEL_MODE_NEON