]> git.hungrycats.org Git - linux/commitdiff
LoongArch: Ensure FP/SIMD registers in the core dump file is up to date
authorHuacai Chen <chenhuacai@loongson.cn>
Sat, 26 Aug 2023 14:21:57 +0000 (22:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:48:44 +0000 (09:48 +0200)
[ Upstream commit 656f9aec07dba7c61d469727494a5d1b18d0bef4 ]

This is a port of commit 379eb01c21795edb4c ("riscv: Ensure the value
of FP registers in the core dump file is up to date").

The values of FP/SIMD registers in the core dump file come from the
thread.fpu. However, kernel saves the FP/SIMD registers only before
scheduling out the process. If no process switch happens during the
exception handling, kernel will not have a chance to save the latest
values of FP/SIMD registers. So it may cause their values in the core
dump file incorrect. To solve this problem, force fpr_get()/simd_get()
to save the FP/SIMD registers into the thread.fpu if the target task
equals the current task.

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/loongarch/include/asm/fpu.h
arch/loongarch/kernel/ptrace.c

index 192f8e35d9126bbb40b29bcd6fb18d20b5b22e40..b1dc4200ae6a4fd203184c4aededac5e6c38e01a 100644 (file)
@@ -117,16 +117,30 @@ static inline void restore_fp(struct task_struct *tsk)
                _restore_fp(&tsk->thread.fpu);
 }
 
-static inline union fpureg *get_fpu_regs(struct task_struct *tsk)
+static inline void save_fpu_regs(struct task_struct *tsk)
 {
+       unsigned int euen;
+
        if (tsk == current) {
                preempt_disable();
-               if (is_fpu_owner())
+
+               euen = csr_read32(LOONGARCH_CSR_EUEN);
+
+#ifdef CONFIG_CPU_HAS_LASX
+               if (euen & CSR_EUEN_LASXEN)
+                       _save_lasx(&current->thread.fpu);
+               else
+#endif
+#ifdef CONFIG_CPU_HAS_LSX
+               if (euen & CSR_EUEN_LSXEN)
+                       _save_lsx(&current->thread.fpu);
+               else
+#endif
+               if (euen & CSR_EUEN_FPEN)
                        _save_fp(&current->thread.fpu);
+
                preempt_enable();
        }
-
-       return tsk->thread.fpu.fpr;
 }
 
 #endif /* _ASM_FPU_H */
index 5fcffb45236764ee75fce64c2508003b5773bffc..286c0ca39eae0280e838bc96cc44571900f78e01 100644 (file)
@@ -147,6 +147,8 @@ static int fpr_get(struct task_struct *target,
 {
        int r;
 
+       save_fpu_regs(target);
+
        if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
                r = gfpr_get(target, &to);
        else