From e0e7d6eb3ac43186a6561e64c2adf79e0291405c Mon Sep 17 00:00:00 2001 From: Sanghoon Lee Date: Thu, 14 Jun 2018 14:36:02 +0900 Subject: [PATCH] [COMMON] arm64: fpsimd: Restore FPSIMD state for user thread 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 --- arch/arm64/kernel/fpsimd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 805b9c746e55..705ccb03008b 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -279,6 +279,16 @@ void fpsimd_put(void) BUG_ON(atomic_dec_return( ¤t->thread.fpsimd_kernel_state.depth) < 0); + + preempt_disable(); + if (current->mm && test_thread_flag(TIF_FOREIGN_FPSTATE) + && atomic_read(¤t->thread.fpsimd_kernel_state.depth) == 0) { + fpsimd_load_state(¤t->thread.fpsimd_state); + this_cpu_write(fpsimd_last_state, ¤t->thread.fpsimd_state); + current->thread.fpsimd_state.cpu = smp_processor_id(); + clear_thread_flag(TIF_FOREIGN_FPSTATE); + } + preempt_enable(); } #ifdef CONFIG_KERNEL_MODE_NEON -- 2.20.1