Skip to content

Commit 5695e51

Browse files
committed
Merge tag 'io_uring-worker.v3-2021-02-25' of git://git.kernel.dk/linux-block
Pull io_uring thread rewrite from Jens Axboe: "This converts the io-wq workers to be forked off the tasks in question instead of being kernel threads that assume various bits of the original task identity. This kills > 400 lines of code from io_uring/io-wq, and it's the worst part of the code. We've had several bugs in this area, and the worry is always that we could be missing some pieces for file types doing unusual things (recent /dev/tty example comes to mind, userfaultfd reads installing file descriptors is another fun one... - both of which need special handling, and I bet it's not the last weird oddity we'll find). With these identical workers, we can have full confidence that we're never missing anything. That, in itself, is a huge win. Outside of that, it's also more efficient since we're not wasting space and code on tracking state, or switching between different states. I'm sure we're going to find little things to patch up after this series, but testing has been pretty thorough, from the usual regression suite to production. Any issue that may crop up should be manageable. There's also a nice series of further reductions we can do on top of this, but I wanted to get the meat of it out sooner rather than later. The general worry here isn't that it's fundamentally broken. Most of the little issues we've found over the last week have been related to just changes in how thread startup/exit is done, since that's the main difference between using kthreads and these kinds of threads. In fact, if all goes according to plan, I want to get this into the 5.10 and 5.11 stable branches as well. That said, the changes outside of io_uring/io-wq are: - arch setup, simple one-liner to each arch copy_thread() implementation. - Removal of net and proc restrictions for io_uring, they are no longer needed or useful" * tag 'io_uring-worker.v3-2021-02-25' of git://git.kernel.dk/linux-block: (30 commits) io-wq: remove now unused IO_WQ_BIT_ERROR io_uring: fix SQPOLL thread handling over exec io-wq: improve manager/worker handling over exec io_uring: ensure SQPOLL startup is triggered before error shutdown io-wq: make buffered file write hashed work map per-ctx io-wq: fix race around io_worker grabbing io-wq: fix races around manager/worker creation and task exit io_uring: ensure io-wq context is always destroyed for tasks arch: ensure parisc/powerpc handle PF_IO_WORKER in copy_thread() io_uring: cleanup ->user usage io-wq: remove nr_process accounting io_uring: flag new native workers with IORING_FEAT_NATIVE_WORKERS net: remove cmsg restriction from io_uring based send/recvmsg calls Revert "proc: don't allow async path resolution of /proc/self components" Revert "proc: don't allow async path resolution of /proc/thread-self components" io_uring: move SQPOLL thread io-wq forked worker io-wq: make io_wq_fork_thread() available to other users io-wq: only remove worker from free_list, if it was there io_uring: remove io_identity io_uring: remove any grabbing of context ...
2 parents 5ceabb6 + d6ce7f6 commit 5695e51

38 files changed

Lines changed: 694 additions & 1114 deletions

File tree

arch/alpha/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
249249
childti->pcb.ksp = (unsigned long) childstack;
250250
childti->pcb.flags = 1; /* set FEN, clear everything else */
251251

252-
if (unlikely(p->flags & PF_KTHREAD)) {
252+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
253253
/* kernel thread */
254254
memset(childstack, 0,
255255
sizeof(struct switch_stack) + sizeof(struct pt_regs));

arch/arc/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
191191
childksp[0] = 0; /* fp */
192192
childksp[1] = (unsigned long)ret_from_fork; /* blink */
193193

194-
if (unlikely(p->flags & PF_KTHREAD)) {
194+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
195195
memset(c_regs, 0, sizeof(struct pt_regs));
196196

197197
c_callee->r13 = kthread_arg;

arch/arm/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
243243
thread->cpu_domain = get_domain();
244244
#endif
245245

246-
if (likely(!(p->flags & PF_KTHREAD))) {
246+
if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) {
247247
*childregs = *current_pt_regs();
248248
childregs->ARM_r0 = 0;
249249
if (stack_start)

arch/arm64/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
398398

399399
ptrauth_thread_init_kernel(p);
400400

401-
if (likely(!(p->flags & PF_KTHREAD))) {
401+
if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) {
402402
*childregs = *current_pt_regs();
403403
childregs->regs[0] = 0;
404404

arch/csky/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int copy_thread(unsigned long clone_flags,
4949
/* setup thread.sp for switch_to !!! */
5050
p->thread.sp = (unsigned long)childstack;
5151

52-
if (unlikely(p->flags & PF_KTHREAD)) {
52+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
5353
memset(childregs, 0, sizeof(struct pt_regs));
5454
childstack->r15 = (unsigned long) ret_from_kernel_thread;
5555
childstack->r10 = kthread_arg;

arch/h8300/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
112112

113113
childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
114114

115-
if (unlikely(p->flags & PF_KTHREAD)) {
115+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
116116
memset(childregs, 0, sizeof(struct pt_regs));
117117
childregs->retpc = (unsigned long) ret_from_kernel_thread;
118118
childregs->er4 = topstk; /* arg */

arch/hexagon/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
7373
sizeof(*ss));
7474
ss->lr = (unsigned long)ret_from_fork;
7575
p->thread.switch_sp = ss;
76-
if (unlikely(p->flags & PF_KTHREAD)) {
76+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
7777
memset(childregs, 0, sizeof(struct pt_regs));
7878
/* r24 <- fn, r25 <- arg */
7979
ss->r24 = usp;

arch/ia64/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ copy_thread(unsigned long clone_flags, unsigned long user_stack_base,
338338

339339
ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
340340

341-
if (unlikely(p->flags & PF_KTHREAD)) {
341+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
342342
if (unlikely(!user_stack_base)) {
343343
/* fork_idle() called us */
344344
return 0;

arch/m68k/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
157157
*/
158158
p->thread.fs = get_fs().seg;
159159

160-
if (unlikely(p->flags & PF_KTHREAD)) {
160+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
161161
/* kernel thread */
162162
memset(frame, 0, sizeof(struct fork_frame));
163163
frame->regs.sr = PS_S;

arch/microblaze/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
5959
struct pt_regs *childregs = task_pt_regs(p);
6060
struct thread_info *ti = task_thread_info(p);
6161

62-
if (unlikely(p->flags & PF_KTHREAD)) {
62+
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
6363
/* if we're creating a new kernel thread then just zeroing all
6464
* the registers. That's OK for a brand new thread.*/
6565
memset(childregs, 0, sizeof(struct pt_regs));

0 commit comments

Comments
 (0)