Skip to content

Commit a58a173

Browse files
committed
MIPS: kernel: Clear FPU states when setting up kernel threads
io_uring sets up the io worker kernel thread via a syscall out of an user space prrocess. This process might have used FPU and since copy_thread() didn't clear FPU states for kernel threads a BUG() is triggered for using FPU inside kernel. Move code around to always clear FPU state for user and kernel threads. Cc: stable@vger.kernel.org Reported-by: Aurelien Jarno <aurel32@debian.org> Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1055021 Suggested-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent c7206e7 commit a58a173

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

arch/mips/kernel/process.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
121121
/* Put the stack after the struct pt_regs. */
122122
childksp = (unsigned long) childregs;
123123
p->thread.cp0_status = (read_c0_status() & ~(ST0_CU2|ST0_CU1)) | ST0_KERNEL_CUMASK;
124+
125+
/*
126+
* New tasks lose permission to use the fpu. This accelerates context
127+
* switching for most programs since they don't use the fpu.
128+
*/
129+
clear_tsk_thread_flag(p, TIF_USEDFPU);
130+
clear_tsk_thread_flag(p, TIF_USEDMSA);
131+
clear_tsk_thread_flag(p, TIF_MSA_CTX_LIVE);
132+
133+
#ifdef CONFIG_MIPS_MT_FPAFF
134+
clear_tsk_thread_flag(p, TIF_FPUBOUND);
135+
#endif /* CONFIG_MIPS_MT_FPAFF */
136+
124137
if (unlikely(args->fn)) {
125138
/* kernel thread */
126139
unsigned long status = p->thread.cp0_status;
@@ -149,20 +162,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
149162
p->thread.reg29 = (unsigned long) childregs;
150163
p->thread.reg31 = (unsigned long) ret_from_fork;
151164

152-
/*
153-
* New tasks lose permission to use the fpu. This accelerates context
154-
* switching for most programs since they don't use the fpu.
155-
*/
156165
childregs->cp0_status &= ~(ST0_CU2|ST0_CU1);
157166

158-
clear_tsk_thread_flag(p, TIF_USEDFPU);
159-
clear_tsk_thread_flag(p, TIF_USEDMSA);
160-
clear_tsk_thread_flag(p, TIF_MSA_CTX_LIVE);
161-
162-
#ifdef CONFIG_MIPS_MT_FPAFF
163-
clear_tsk_thread_flag(p, TIF_FPUBOUND);
164-
#endif /* CONFIG_MIPS_MT_FPAFF */
165-
166167
#ifdef CONFIG_MIPS_FP_SUPPORT
167168
atomic_set(&p->thread.bd_emu_frame, BD_EMUFRAME_NONE);
168169
#endif

0 commit comments

Comments
 (0)