Skip to content

Commit 0cda9bc

Browse files
isilencesmb49
authored andcommitted
io_uring/io-wq: limit retrying worker initialisation
BugLink: https://bugs.launchpad.net/bugs/2078428 commit 0453aad676ff99787124b9b3af4a5f59fbe808e2 upstream. If io-wq worker creation fails, we retry it by queueing up a task_work. tasK_work is needed because it should be done from the user process context. The problem is that retries are not limited, and if queueing a task_work is the reason for the failure, we might get into an infinite loop. It doesn't seem to happen now but it would with the following patch executing task_work in the freezer's loop. For now, arbitrarily limit the number of attempts to create a worker. Cc: [email protected] Fixes: 3146cba ("io-wq: make worker creation resilient against signals") Reported-by: Julian Orth <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/8280436925db88448c7c85c6656edee1a43029ea.1720634146.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Koichiro Den <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent 0af4fed commit 0cda9bc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

io_uring/io-wq.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "io-wq.h"
2020

2121
#define WORKER_IDLE_TIMEOUT (5 * HZ)
22+
#define WORKER_INIT_LIMIT 3
2223

2324
enum {
2425
IO_WORKER_F_UP = 1, /* up and active */
@@ -54,6 +55,7 @@ struct io_worker {
5455
unsigned long create_state;
5556
struct callback_head create_work;
5657
int create_index;
58+
int init_retries;
5759

5860
union {
5961
struct rcu_head rcu;
@@ -732,14 +734,16 @@ static bool io_wq_work_match_all(struct io_wq_work *work, void *data)
732734
return true;
733735
}
734736

735-
static inline bool io_should_retry_thread(long err)
737+
static inline bool io_should_retry_thread(struct io_worker *worker, long err)
736738
{
737739
/*
738740
* Prevent perpetual task_work retry, if the task (or its group) is
739741
* exiting.
740742
*/
741743
if (fatal_signal_pending(current))
742744
return false;
745+
if (worker->init_retries++ >= WORKER_INIT_LIMIT)
746+
return false;
743747

744748
switch (err) {
745749
case -EAGAIN:
@@ -766,7 +770,7 @@ static void create_worker_cont(struct callback_head *cb)
766770
io_init_new_worker(wqe, worker, tsk);
767771
io_worker_release(worker);
768772
return;
769-
} else if (!io_should_retry_thread(PTR_ERR(tsk))) {
773+
} else if (!io_should_retry_thread(worker, PTR_ERR(tsk))) {
770774
struct io_wqe_acct *acct = io_wqe_get_acct(worker);
771775

772776
atomic_dec(&acct->nr_running);
@@ -831,7 +835,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
831835
tsk = create_io_thread(io_wqe_worker, worker, wqe->node);
832836
if (!IS_ERR(tsk)) {
833837
io_init_new_worker(wqe, worker, tsk);
834-
} else if (!io_should_retry_thread(PTR_ERR(tsk))) {
838+
} else if (!io_should_retry_thread(worker, PTR_ERR(tsk))) {
835839
kfree(worker);
836840
goto fail;
837841
} else {

0 commit comments

Comments
 (0)