Skip to content

Commit 3d8500d

Browse files
vrazdan-oaigregkh
authored andcommitted
io_uring/io-wq: fix worker accounting when canceling creation callbacks
commit 297b5cc upstream. create_worker_cb() reserves an io-wq worker slot only after its task-work callback runs. If the callback is canceled before then, io_worker_cancel_cb() still decrements acct->nr_workers. When an existing worker retires with its creation callback pending, that worker has already decremented the same account's worker count. The resulting undercount permits worker creation beyond the account's configured limit. On an AST2600 OpenBMC system, an unchanged sensor daemon reached 4,291 threads with the original kernel. With an equivalent downstream fix, 25 passive samples under its normal workload showed 6-9 threads. Decrement nr_workers only when the canceled callback is not create_worker_cb(). Continuation callbacks still release their reserved slot, and both callback types retain the existing running-count, reference-count, and create-state cleanup. [ Backport: retain the existing worker->wqe->lock protecting worker accounting. ] Fixes: 1d5f5ea ("io-wq: remove worker to owner tw dependency") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.6-sol Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de> Link: https://patch.msgid.link/20260811-vrazdan-io-wq-b4-submit-v1-1-719ced16c921@openai.com Signed-off-by: Vishnu Razdan <vrazdan@openai.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5959cad commit 3d8500d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

io_uring/io-wq.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,12 @@ static void io_worker_cancel_cb(struct io_worker *worker)
201201
struct io_wq *wq = wqe->wq;
202202

203203
atomic_dec(&acct->nr_running);
204-
raw_spin_lock(&worker->wqe->lock);
205-
acct->nr_workers--;
206-
raw_spin_unlock(&worker->wqe->lock);
204+
/* create_worker_cb() has not reserved a worker slot yet. */
205+
if (worker->create_work.func != create_worker_cb) {
206+
raw_spin_lock(&worker->wqe->lock);
207+
acct->nr_workers--;
208+
raw_spin_unlock(&worker->wqe->lock);
209+
}
207210
io_worker_ref_put(wq);
208211
clear_bit_unlock(0, &worker->create_state);
209212
io_worker_release(worker);

0 commit comments

Comments
 (0)