未验证 提交 a647a846 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!1022 [sync] PR-978: io_uring: fix the problem of running

Merge Pull Request from: @openeuler-sync-bot 
 

Origin pull request: 
https://gitee.com/openeuler/kernel/pulls/978 
 
PR sync from:  Li Lingfeng <lilingfeng3@huawei.com>
 https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/thread/DP5GHDF7ULWL52W5DGYZWS6HBE5WJ52E/ 
patch1: arch: setup PF_IO_WORKER threads like PF_KTHREAD
  pre patch of patch4
patch2: arch: ensure parisc/powerpc handle PF_IO_WORKER in copy_thread()
  fix patch of patch1
patch3: kernel: don't call do_exit() for PF_IO_WORKER threads
  fix the segfault
patch4: x86/process: setup io_threads more like normal user space
threads
  allow io worker to exit

Jens Axboe (3):
  arch: setup PF_IO_WORKER threads like PF_KTHREAD
  arch: ensure parisc/powerpc handle PF_IO_WORKER in copy_thread()
  kernel: don't call do_exit() for PF_IO_WORKER threads

Stefan Metzmacher (1):
  x86/process: setup io_threads more like normal user space threads


-- 
2.31.1
 
 
Link:https://gitee.com/openeuler/kernel/pulls/1022 

Reviewed-by: Zucheng Zheng <zhengzucheng@huawei.com> 
Signed-off-by: Jialin Zhang <zhangjialin11@huawei.com> 
...@@ -249,7 +249,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, ...@@ -249,7 +249,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
childti->pcb.ksp = (unsigned long) childstack; childti->pcb.ksp = (unsigned long) childstack;
childti->pcb.flags = 1; /* set FEN, clear everything else */ childti->pcb.flags = 1; /* set FEN, clear everything else */
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* kernel thread */ /* kernel thread */
memset(childstack, 0, memset(childstack, 0,
sizeof(struct switch_stack) + sizeof(struct pt_regs)); sizeof(struct switch_stack) + sizeof(struct pt_regs));
......
...@@ -191,7 +191,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, ...@@ -191,7 +191,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
childksp[0] = 0; /* fp */ childksp[0] = 0; /* fp */
childksp[1] = (unsigned long)ret_from_fork; /* blink */ childksp[1] = (unsigned long)ret_from_fork; /* blink */
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(c_regs, 0, sizeof(struct pt_regs)); memset(c_regs, 0, sizeof(struct pt_regs));
c_callee->r13 = kthread_arg; c_callee->r13 = kthread_arg;
......
...@@ -243,7 +243,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, ...@@ -243,7 +243,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
thread->cpu_domain = get_domain(); thread->cpu_domain = get_domain();
#endif #endif
if (likely(!(p->flags & PF_KTHREAD))) { if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) {
*childregs = *current_pt_regs(); *childregs = *current_pt_regs();
childregs->ARM_r0 = 0; childregs->ARM_r0 = 0;
if (stack_start) if (stack_start)
......
...@@ -405,7 +405,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, ...@@ -405,7 +405,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
ptrauth_thread_init_kernel(p); ptrauth_thread_init_kernel(p);
if (likely(!(p->flags & PF_KTHREAD))) { if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) {
*childregs = *current_pt_regs(); *childregs = *current_pt_regs();
childregs->regs[0] = 0; childregs->regs[0] = 0;
......
...@@ -49,7 +49,7 @@ int copy_thread(unsigned long clone_flags, ...@@ -49,7 +49,7 @@ int copy_thread(unsigned long clone_flags,
/* setup thread.sp for switch_to !!! */ /* setup thread.sp for switch_to !!! */
p->thread.sp = (unsigned long)childstack; p->thread.sp = (unsigned long)childstack;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
childstack->r15 = (unsigned long) ret_from_kernel_thread; childstack->r15 = (unsigned long) ret_from_kernel_thread;
childstack->r10 = kthread_arg; childstack->r10 = kthread_arg;
......
...@@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, ...@@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1; childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
childregs->retpc = (unsigned long) ret_from_kernel_thread; childregs->retpc = (unsigned long) ret_from_kernel_thread;
childregs->er4 = topstk; /* arg */ childregs->er4 = topstk; /* arg */
......
...@@ -73,7 +73,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -73,7 +73,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
sizeof(*ss)); sizeof(*ss));
ss->lr = (unsigned long)ret_from_fork; ss->lr = (unsigned long)ret_from_fork;
p->thread.switch_sp = ss; p->thread.switch_sp = ss;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
/* r24 <- fn, r25 <- arg */ /* r24 <- fn, r25 <- arg */
ss->r24 = usp; ss->r24 = usp;
......
...@@ -337,7 +337,7 @@ copy_thread(unsigned long clone_flags, unsigned long user_stack_base, ...@@ -337,7 +337,7 @@ copy_thread(unsigned long clone_flags, unsigned long user_stack_base,
ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */ ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
if (unlikely(!user_stack_base)) { if (unlikely(!user_stack_base)) {
/* fork_idle() called us */ /* fork_idle() called us */
return 0; return 0;
......
...@@ -157,7 +157,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -157,7 +157,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
*/ */
p->thread.fs = get_fs().seg; p->thread.fs = get_fs().seg;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* kernel thread */ /* kernel thread */
memset(frame, 0, sizeof(struct fork_frame)); memset(frame, 0, sizeof(struct fork_frame));
frame->regs.sr = PS_S; frame->regs.sr = PS_S;
......
...@@ -59,7 +59,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -59,7 +59,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
struct pt_regs *childregs = task_pt_regs(p); struct pt_regs *childregs = task_pt_regs(p);
struct thread_info *ti = task_thread_info(p); struct thread_info *ti = task_thread_info(p);
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* if we're creating a new kernel thread then just zeroing all /* if we're creating a new kernel thread then just zeroing all
* the registers. That's OK for a brand new thread.*/ * the registers. That's OK for a brand new thread.*/
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
......
...@@ -135,7 +135,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, ...@@ -135,7 +135,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
/* Put the stack after the struct pt_regs. */ /* Put the stack after the struct pt_regs. */
childksp = (unsigned long) childregs; childksp = (unsigned long) childregs;
p->thread.cp0_status = (read_c0_status() & ~(ST0_CU2|ST0_CU1)) | ST0_KERNEL_CUMASK; p->thread.cp0_status = (read_c0_status() & ~(ST0_CU2|ST0_CU1)) | ST0_KERNEL_CUMASK;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* kernel thread */ /* kernel thread */
unsigned long status = p->thread.cp0_status; unsigned long status = p->thread.cp0_status;
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
......
...@@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, ...@@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context));
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
/* kernel thread fn */ /* kernel thread fn */
p->thread.cpu_context.r6 = stack_start; p->thread.cpu_context.r6 = stack_start;
......
...@@ -109,7 +109,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -109,7 +109,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
struct switch_stack *childstack = struct switch_stack *childstack =
((struct switch_stack *)childregs) - 1; ((struct switch_stack *)childregs) - 1;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(childstack, 0, memset(childstack, 0,
sizeof(struct switch_stack) + sizeof(struct pt_regs)); sizeof(struct switch_stack) + sizeof(struct pt_regs));
......
...@@ -167,7 +167,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -167,7 +167,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
sp -= sizeof(struct pt_regs); sp -= sizeof(struct pt_regs);
kregs = (struct pt_regs *)sp; kregs = (struct pt_regs *)sp;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(kregs, 0, sizeof(struct pt_regs)); memset(kregs, 0, sizeof(struct pt_regs));
kregs->gpr[20] = usp; /* fn, kernel thread */ kregs->gpr[20] = usp; /* fn, kernel thread */
kregs->gpr[22] = arg; kregs->gpr[22] = arg;
......
...@@ -200,7 +200,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp, ...@@ -200,7 +200,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
extern void * const ret_from_kernel_thread; extern void * const ret_from_kernel_thread;
extern void * const child_return; extern void * const child_return;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* kernel thread */ /* kernel thread */
memset(cregs, 0, sizeof(struct pt_regs)); memset(cregs, 0, sizeof(struct pt_regs));
if (!usp) /* idle thread */ if (!usp) /* idle thread */
......
...@@ -1684,7 +1684,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, ...@@ -1684,7 +1684,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
/* Copy registers */ /* Copy registers */
sp -= sizeof(struct pt_regs); sp -= sizeof(struct pt_regs);
childregs = (struct pt_regs *) sp; childregs = (struct pt_regs *) sp;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* kernel thread */ /* kernel thread */
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
childregs->gpr[1] = sp + sizeof(struct pt_regs); childregs->gpr[1] = sp + sizeof(struct pt_regs);
......
...@@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
struct pt_regs *childregs = task_pt_regs(p); struct pt_regs *childregs = task_pt_regs(p);
/* p->thread holds context to be restored by __switch_to() */ /* p->thread holds context to be restored by __switch_to() */
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* Kernel thread */ /* Kernel thread */
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
childregs->gp = gp_in_global; childregs->gp = gp_in_global;
......
...@@ -127,7 +127,7 @@ int copy_thread(unsigned long clone_flags, unsigned long new_stackp, ...@@ -127,7 +127,7 @@ int copy_thread(unsigned long clone_flags, unsigned long new_stackp,
frame->sf.gprs[9] = (unsigned long) frame; frame->sf.gprs[9] = (unsigned long) frame;
/* Store access registers to kernel stack of new process. */ /* Store access registers to kernel stack of new process. */
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
/* kernel thread */ /* kernel thread */
memset(&frame->childregs, 0, sizeof(struct pt_regs)); memset(&frame->childregs, 0, sizeof(struct pt_regs));
frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT | frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT |
......
...@@ -114,7 +114,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, ...@@ -114,7 +114,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
childregs = task_pt_regs(p); childregs = task_pt_regs(p);
p->thread.sp = (unsigned long) childregs; p->thread.sp = (unsigned long) childregs;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(childregs, 0, sizeof(struct pt_regs)); memset(childregs, 0, sizeof(struct pt_regs));
p->thread.pc = (unsigned long) ret_from_kernel_thread; p->thread.pc = (unsigned long) ret_from_kernel_thread;
childregs->regs[4] = arg; childregs->regs[4] = arg;
......
...@@ -309,7 +309,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, ...@@ -309,7 +309,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
ti->ksp = (unsigned long) new_stack; ti->ksp = (unsigned long) new_stack;
p->thread.kregs = childregs; p->thread.kregs = childregs;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
extern int nwindows; extern int nwindows;
unsigned long psr; unsigned long psr;
memset(new_stack, 0, STACKFRAME_SZ + TRACEREG_SZ); memset(new_stack, 0, STACKFRAME_SZ + TRACEREG_SZ);
......
...@@ -599,7 +599,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, ...@@ -599,7 +599,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
sizeof(struct sparc_stackf)); sizeof(struct sparc_stackf));
t->fpsaved[0] = 0; t->fpsaved[0] = 0;
if (unlikely(p->flags & PF_KTHREAD)) { if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
memset(child_trap_frame, 0, child_stack_sz); memset(child_trap_frame, 0, child_stack_sz);
__thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] = __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] =
(current_pt_regs()->tstate + 1) & TSTATE_CWP; (current_pt_regs()->tstate + 1) & TSTATE_CWP;
......
...@@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, ...@@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
unsigned long arg, struct task_struct * p, unsigned long tls) unsigned long arg, struct task_struct * p, unsigned long tls)
{ {
void (*handler)(void); void (*handler)(void);
int kthread = current->flags & PF_KTHREAD; int kthread = current->flags & (PF_KTHREAD | PF_IO_WORKER);
int ret = 0; int ret = 0;
p->thread = (struct thread_struct) INIT_THREAD; p->thread = (struct thread_struct) INIT_THREAD;
......
...@@ -200,6 +200,23 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, ...@@ -200,6 +200,23 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
task_user_gs(p) = get_user_gs(current_pt_regs()); task_user_gs(p) = get_user_gs(current_pt_regs());
#endif #endif
if (unlikely(p->flags & PF_IO_WORKER)) {
/*
* An IO thread is a user space thread, but it doesn't
* return to ret_after_fork().
*
* In order to indicate that to tools like gdb,
* we reset the stack and instruction pointers.
*
* It does the same kernel frame setup to return to a kernel
* function that a kernel thread does.
*/
childregs->sp = 0;
childregs->ip = 0;
kthread_frame_init(frame, sp, arg);
return 0;
}
/* Set a new TLS for the child thread? */ /* Set a new TLS for the child thread? */
if (clone_flags & CLONE_SETTLS) if (clone_flags & CLONE_SETTLS)
ret = set_new_tls(p, tls); ret = set_new_tls(p, tls);
......
...@@ -217,7 +217,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn, ...@@ -217,7 +217,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
p->thread.sp = (unsigned long)childregs; p->thread.sp = (unsigned long)childregs;
if (!(p->flags & PF_KTHREAD)) { if (!(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
struct pt_regs *regs = current_pt_regs(); struct pt_regs *regs = current_pt_regs();
unsigned long usp = usp_thread_fn ? unsigned long usp = usp_thread_fn ?
usp_thread_fn : regs->areg[1]; usp_thread_fn : regs->areg[1];
......
...@@ -2760,6 +2760,14 @@ bool get_signal(struct ksignal *ksig) ...@@ -2760,6 +2760,14 @@ bool get_signal(struct ksignal *ksig)
do_coredump(&ksig->info); do_coredump(&ksig->info);
} }
/*
* PF_IO_WORKER threads will catch and exit on fatal signals
* themselves. They have cleanup that must be performed, so
* we cannot call do_exit() on their behalf.
*/
if (current->flags & PF_IO_WORKER)
goto out;
/* /*
* Death signals, no core dump. * Death signals, no core dump.
*/ */
...@@ -2767,7 +2775,7 @@ bool get_signal(struct ksignal *ksig) ...@@ -2767,7 +2775,7 @@ bool get_signal(struct ksignal *ksig)
/* NOTREACHED */ /* NOTREACHED */
} }
spin_unlock_irq(&sighand->siglock); spin_unlock_irq(&sighand->siglock);
out:
ksig->sig = signr; ksig->sig = signr;
return ksig->sig > 0; return ksig->sig > 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册