Pull io_uring fixes from Jens Axboe: "One fix in here, for a regression in 5.7 where a task is waiting in the kernel for a condition, but that condition won't become true until task_work is run. And the task_work can't be run exactly because the task is waiting in the kernel, so we'll never make any progress. One example of that is registering an eventfd and queueing io_uring work, and then the task goes and waits in eventfd read with the expectation that it'll get woken (and read an event) when the io_uring request completes. The io_uring request is finished through task_work, which won't get run while the task is looping in eventfd read" * tag 'io_uring-5.8-2020-07-01' of git://git.kernel.dk/linux-block: io_uring: use signal based task_work running task_work: teach task_work_add() to do signal_wake_up()
Showing the changes to kernel (2 of 5 files). Show all
Unified · Split
| @@ -2529,9 +2529,6 @@ bool get_signal(struct ksignal *ksig) · 2528 unmodified lines | ||
| 2529 | 2529 | struct signal_struct *signal = current->signal; |
| 2530 | 2530 | int signr; |
| 2531 | 2531 | |
| 2532 | − if (unlikely(current->task_works)) | |
| 2533 | − task_work_run(); | |
| 2534 | − | |
| 2535 | 2532 | if (unlikely(uprobe_deny_signal())) |
| 2536 | 2533 | return false; |
| 2537 | 2534 | |
| @@ -2544,6 +2541,13 @@ bool get_signal(struct ksignal *ksig) · 6 unmodified lines | ||
| 2544 | 2541 | |
| 2545 | 2542 | relock: |
| 2546 | 2543 | spin_lock_irq(&sighand->siglock); |
| 2544 | + current->jobctl &= ~JOBCTL_TASK_WORK; | |
| 2545 | + if (unlikely(current->task_works)) { | |
| 2546 | + spin_unlock_irq(&sighand->siglock); | |
| 2547 | + task_work_run(); | |
| 2548 | + goto relock; | |
| 2549 | + } | |
| 2550 | + | |
| 2547 | 2551 | /* |
| 2548 | 2552 | * Every stopped thread goes here after wakeup. Check to see if |
| 2549 | 2553 | * we should notify the parent, prepare_signal(SIGCONT) encodes |
| @@ -25,9 +25,10 @@ static struct callback_head work_exited; /* all we need is ->next == NULL */ · 24 unmodified lines | ||
| 25 | 25 | * 0 if succeeds or -ESRCH. |
| 26 | 26 | */ |
| 27 | 27 | int |
| 28 | −task_work_add(struct task_struct *task, struct callback_head *work, bool notify) | |
| 28 | +task_work_add(struct task_struct *task, struct callback_head *work, int notify) | |
| 29 | 29 | { |
| 30 | 30 | struct callback_head *head; |
| 31 | + unsigned long flags; | |
| 31 | 32 | |
| 32 | 33 | do { |
| 33 | 34 | head = READ_ONCE(task->task_works); |
| @@ -36,8 +37,19 @@ task_work_add(struct task_struct *task, struct callback_head *work, bool notify) · 2 unmodified lines | ||
| 36 | 37 | work->next = head; |
| 37 | 38 | } while (cmpxchg(&task->task_works, head, work) != head); |
| 38 | 39 | |
| 39 | − if (notify) | |
| 40 | + switch (notify) { | |
| 41 | + case TWA_RESUME: | |
| 40 | 42 | set_notify_resume(task); |
| 43 | + break; | |
| 44 | + case TWA_SIGNAL: | |
| 45 | + if (lock_task_sighand(task, &flags)) { | |
| 46 | + task->jobctl |= JOBCTL_TASK_WORK; | |
| 47 | + signal_wake_up(task, 0); | |
| 48 | + unlock_task_sighand(task, &flags); | |
| 49 | + } | |
| 50 | + break; | |
| 51 | + } | |
| 52 | + | |
| 41 | 53 | return 0; |
| 42 | 54 | } |
| 43 | 55 | |