Skip to content

Commit ef98eb0

Browse files
anadavaxboe
authored andcommitted
io_uring: clear TIF_NOTIFY_SIGNAL when running task work
When using SQPOLL, the submission queue polling thread calls task_work_run() to run queued work. However, when work is added with TWA_SIGNAL - as done by io_uring itself - the TIF_NOTIFY_SIGNAL remains set afterwards and is never cleared. Consequently, when the submission queue polling thread checks whether signal_pending(), it may always find a pending signal, if task_work_add() was ever called before. The impact of this bug might be different on different kernel versions. It appears that on 5.14 it would only cause unnecessary calculation and prevent the polling thread from sleeping. On 5.13, where the bug was found, it stops the polling thread from finding newly submitted work. Instead of task_work_run(), use tracehook_notify_signal() that clears TIF_NOTIFY_SIGNAL. Test for TIF_NOTIFY_SIGNAL in addition to current->task_works to avoid a race in which task_works is cleared but the TIF_NOTIFY_SIGNAL is set. Fixes: 685fe7f ("io-wq: eliminate the need for a manager thread") Cc: Jens Axboe <[email protected]> Cc: Pavel Begunkov <[email protected]> Signed-off-by: Nadav Amit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 2169827 commit ef98eb0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/io_uring.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include <linux/task_work.h>
7979
#include <linux/pagemap.h>
8080
#include <linux/io_uring.h>
81+
#include <linux/tracehook.h>
8182

8283
#define CREATE_TRACE_POINTS
8384
#include <trace/events/io_uring.h>
@@ -2222,9 +2223,9 @@ static inline unsigned int io_put_rw_kbuf(struct io_kiocb *req)
22222223

22232224
static inline bool io_run_task_work(void)
22242225
{
2225-
if (current->task_works) {
2226+
if (test_thread_flag(TIF_NOTIFY_SIGNAL) || current->task_works) {
22262227
__set_current_state(TASK_RUNNING);
2227-
task_work_run();
2228+
tracehook_notify_signal();
22282229
return true;
22292230
}
22302231

0 commit comments

Comments
 (0)