Skip to content

Commit 50b7b6f

Browse files
metze-sambaaxboe
authored andcommitted
x86/process: setup io_threads more like normal user space threads
As io_threads are fully set up USER threads it's clearer to separate the code path from the KTHREAD logic. The only remaining difference to user space threads is that io_threads never return to user space again. Instead they loop within the given worker function. The fact that they never return to user space means they don't have an user space thread stack. In order to indicate that to tools like gdb we reset the stack and instruction pointers to 0. This allows gdb attach to user space processes using io-uring, which like means that they have io_threads, without printing worrying message like this: warning: Selected architecture i386:x86-64 is not compatible with reported target architecture i386 warning: Architecture rejected target-supplied description The output will be something like this: (gdb) info threads Id Target Id Frame * 1 LWP 4863 "io_uring-cp-for" syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38 2 LWP 4864 "iou-mgr-4863" 0x0000000000000000 in ?? () 3 LWP 4865 "iou-wrk-4863" 0x0000000000000000 in ?? () (gdb) thread 3 [Switching to thread 3 (LWP 4865)] #0 0x0000000000000000 in ?? () (gdb) bt #0 0x0000000000000000 in ?? () Backtrace stopped: Cannot access memory at address 0x0 Fixes: 4727dc2 ("arch: setup PF_IO_WORKER threads like PF_KTHREAD") Link: https://lore.kernel.org/io-uring/[email protected]/T/#m1bbf5727e3d4e839603f6ec7ed79c7eebfba6267 Signed-off-by: Stefan Metzmacher <[email protected]> cc: Linus Torvalds <[email protected]> cc: Jens Axboe <[email protected]> cc: Andy Lutomirski <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Thomas Gleixner <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent a5e7da1 commit 50b7b6f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

arch/x86/kernel/process.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
156156
#endif
157157

158158
/* Kernel thread ? */
159-
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
159+
if (unlikely(p->flags & PF_KTHREAD)) {
160160
memset(childregs, 0, sizeof(struct pt_regs));
161161
kthread_frame_init(frame, sp, arg);
162162
return 0;
@@ -172,6 +172,23 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
172172
task_user_gs(p) = get_user_gs(current_pt_regs());
173173
#endif
174174

175+
if (unlikely(p->flags & PF_IO_WORKER)) {
176+
/*
177+
* An IO thread is a user space thread, but it doesn't
178+
* return to ret_after_fork().
179+
*
180+
* In order to indicate that to tools like gdb,
181+
* we reset the stack and instruction pointers.
182+
*
183+
* It does the same kernel frame setup to return to a kernel
184+
* function that a kernel thread does.
185+
*/
186+
childregs->sp = 0;
187+
childregs->ip = 0;
188+
kthread_frame_init(frame, sp, arg);
189+
return 0;
190+
}
191+
175192
/* Set a new TLS for the child thread? */
176193
if (clone_flags & CLONE_SETTLS)
177194
ret = set_new_tls(p, tls);

0 commit comments

Comments
 (0)