Skip to contentSkip to conversation

Create kernel thread possibly with USEDFPU flag in mips

PATCH New wangyangbo 1 participant 2 messages Sep 13, 2021 MIPS

lore
Share & tools
lore

wangyangbo

author
#0 lore raw

cover Create kernel thread possibly with USEDFPU flag in mips

Hi,
I want to use new syscall io_uring in mips,

Problem:
Running ./liburing/examples/io_uring-cp of liburing in mips kernel,

[  132.538431] do_cpu invoked from kernel context![#1]:
[  132.597936] CPU: 2 PID: 4154 Comm: iou-wrk-4153 Not tainted 5.14.0-rc1+ #5
[  132.680373] Hardware name: THTF CQTL630 Series/THTF-LS3A4000-7A1000-1W-VB1-ML4A, BIOS V2.0.3 05/08/2020
[  133.560951] Hi    : 0000000000000002
[  133.603728] Lo    : 000000000c49ba60
[  133.646499] epc   : ffffffff80217670 _save_fp+0x10/0xa0
[  133.709104] ra    : ffffffff80cb9c44 __schedule+0x574/0xad8
[  133.775875] Status: 5400cce2 KX SX UX KERNEL EXL
[  133.832222] Cause : 1000002c (ExcCode 0b)
[  133.880215] PrId  : 0014c004 (ICT Loongson-3)
[  135.382659] Call Trace:
[  135.411868] [<ffffffff80217670>] _save_fp+0x10/0xa0
[  135.470296] [<ffffffff80cb9c44>] __schedule+0x574/0xad8
[  135.532893] [<ffffffff80cba22c>] schedule+0x84/0x138
[  135.592361] [<ffffffff80cbf714>] schedule_timeout+0x1bc/0x3c0
[  135.661219] [<ffffffff80510588>] io_wqe_worker+0x110/0x350
[  135.726947] [<ffffffff80205a6c>] ret_from_kernel_thread+0x14/0x1c
[  135.799981]
[  135.817718] Code: 000c6940  05a10011  00000000 <f4810a00> f4830a20  f4850a40  f4870a60  f4890a80  f48b0aa0

Reason:
io-wq, fork worker threads from original user task(commit 3bfe6106693b6b4ba175ad1f929c4660b8f59ca8).
This causes copy_thread with TIF_USEDFPU flag in mips, meaning save_fp in switch_to, triggering do_cpu trap, however cpid 1(fpu) don't allow kernel to use.

Fix:
clear FPU flag in kernel IO_WORKER thread_copy branch.

wangyangbo (1):
MIPS: Fix fpu trap invoked by io-worker

 arch/mips/kernel/process.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/1 MIPS: Fix fpu trap invoked by io-worker

From: wangyangbo <[email protected]>

Create worker thread from original user task in mips, possibly copying FPU flag from user task, introducing save_fp when switch_to, triggering do_cpu trap. So clear USEDFPU flag for IO_WORKER in copy_thread.

---
 arch/mips/kernel/process.c | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/kernel/process.c +3 -0
index 95aa86fa6077..0095006d48c7 100644
@@ -135,6 +135,9 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 		status |= ST0_EXL;
 #endif
 		childregs->cp0_status = status;
+
+		if (p->flags & PF_IO_WORKER)
+			clear_tsk_thread_flag(p, TIF_USEDFPU);
 		return 0;
 	}
 
Signature · 1 line
2.20.1