Skip to content

Commit 767a65e

Browse files
Hao Xuaxboe
authored andcommitted
io-wq: fix potential race of acct->nr_workers
Given max_worker is 1, and we currently have 1 running and it is exiting. There may be race like: io_wqe_enqueue worker1 no work there and timeout unlock(wqe->lock) ->insert work -->io_worker_exit lock(wqe->lock) ->if(!nr_workers) //it's still 1 unlock(wqe->lock) goto run_cancel lock(wqe->lock) nr_workers-- ->dec_running ->worker creation fails unlock(wqe->lock) We enqueued one work but there is no workers, causes hung. Signed-off-by: Hao Xu <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 7a842fb commit 767a65e

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

fs/io-wq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static void io_worker_ref_put(struct io_wq *wq)
176176
static void io_worker_exit(struct io_worker *worker)
177177
{
178178
struct io_wqe *wqe = worker->wqe;
179-
struct io_wqe_acct *acct = io_wqe_get_acct(worker);
180179

181180
if (refcount_dec_and_test(&worker->ref))
182181
complete(&worker->ref_done);
@@ -186,7 +185,6 @@ static void io_worker_exit(struct io_worker *worker)
186185
if (worker->flags & IO_WORKER_F_FREE)
187186
hlist_nulls_del_rcu(&worker->nulls_node);
188187
list_del_rcu(&worker->all_list);
189-
acct->nr_workers--;
190188
preempt_disable();
191189
io_wqe_dec_running(worker);
192190
worker->flags = 0;
@@ -569,6 +567,7 @@ static int io_wqe_worker(void *data)
569567
}
570568
/* timed out, exit unless we're the last worker */
571569
if (last_timeout && acct->nr_workers > 1) {
570+
acct->nr_workers--;
572571
raw_spin_unlock(&wqe->lock);
573572
__set_current_state(TASK_RUNNING);
574573
break;

0 commit comments

Comments
 (0)