[PATCH] io_uring/io-wq: don't change the io-wq CPU mask on CPU hotplug

From: Hang Zhengyang

Date: Sat Dec 05 2026 - 05:49:39 EST


The io-wq CPU hotplug callbacks set a CPU in wq->cpu_mask when it comes
online and clear it when it goes offline, if the io-wq has a worker at
that time. Since commit 0659e44ce739 ("io_uring/io-wq: apply the current
cpuset to new workers"), that mask is the affinity registered with
IORING_REGISTER_IOWQ_AFF, or all possible CPUs. So CPU hotplug changes
the affinity:

- A CPU that comes online is added to the registered mask. With CPUs
0-1 registered, after CPU 3 goes offline and online, a new worker has
Cpus_allowed_list 0-1,3. Suspend to RAM does this to every non-boot
CPU.

- A CPU that goes offline while the io-wq has a worker, and comes back
when it has none, is left out of the mask, registered or not.

The callbacks date from when io-wq had one mask per NUMA node, started
from cpumask_of_node(). The mask now starts from cpu_possible_mask and
needs no update on hotplug. Remove the callbacks.

Fixes: 0e03496d1967 ("io-wq: use private CPU mask")
Cc: stable@xxxxxxxxxxxxxxx # 6.6.x: 0659e44ce739: io_uring/io-wq: apply the current cpuset to new workers
Cc: stable@xxxxxxxxxxxxxxx # v6.4+
Signed-off-by: Hang Zhengyang <hang.zhengyang1010@xxxxxxxxx>
---
On 6.6.y, this needs 0659e44ce739 first, which is in 6.6.164-rc1.
6.12.120, 6.18.66 and 7.3.7 have it. 5.15 and 6.1 still have one mask
per node and need a different fix.

Tested on io_uring-7.4 in a 4-CPU KVM guest: both cases above happen
without the patch and not with it, and the liburing tests show no new
failures. The suspend case is from reading the code.

I used Claude Code to find the issue, write the patch and run the
tests. I reviewed the patch.

io_uring/io-wq.c | 68 ------------------------------------------------
1 file changed, 68 deletions(-)

diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
index 9609ae50dbd7..044b20be2bab 100644
--- a/io_uring/io-wq.c
+++ b/io_uring/io-wq.c
@@ -13,7 +13,6 @@
#include <linux/percpu.h>
#include <linux/slab.h>
#include <linux/rculist_nulls.h>
-#include <linux/cpu.h>
#include <linux/cpuset.h>
#include <linux/task_work.h>
#include <linux/audit.h>
@@ -125,8 +124,6 @@ struct io_wq {
atomic_t worker_refs;
struct completion worker_done;

- struct hlist_node cpuhp_node;
-
struct task_struct *task;

struct io_wq_acct acct[IO_WQ_ACCT_NR];
@@ -138,8 +135,6 @@ struct io_wq {
cpumask_var_t cpu_mask;
};

-static enum cpuhp_state io_wq_online;
-
struct io_cb_cancel_data {
work_cancel_fn *fn;
void *data;
@@ -1426,12 +1421,6 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
wq->task = get_task_struct(data->task);
atomic_set(&wq->worker_refs, 1);
init_completion(&wq->worker_done);
- ret = cpuhp_state_add_instance_nocalls(io_wq_online, &wq->cpuhp_node);
- if (ret) {
- put_task_struct(wq->task);
- goto err;
- }
-
return wq;
err:
io_wq_put_hash(data->hash);
@@ -1549,7 +1538,6 @@ static void io_wq_destroy(struct io_wq *wq)
.cancel_all = true,
};

- cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
io_wq_cancel_pending_work(wq, &match);
free_cpumask_var(wq->cpu_mask);
io_wq_put_hash(wq->hash);
@@ -1564,49 +1552,6 @@ void io_wq_put_and_exit(struct io_wq *wq)
io_wq_destroy(wq);
}

-struct online_data {
- unsigned int cpu;
- bool online;
-};
-
-static bool io_wq_worker_affinity(struct io_worker *worker, void *data)
-{
- struct online_data *od = data;
-
- if (od->online)
- cpumask_set_cpu(od->cpu, worker->wq->cpu_mask);
- else
- cpumask_clear_cpu(od->cpu, worker->wq->cpu_mask);
- return false;
-}
-
-static int __io_wq_cpu_online(struct io_wq *wq, unsigned int cpu, bool online)
-{
- struct online_data od = {
- .cpu = cpu,
- .online = online
- };
-
- rcu_read_lock();
- io_wq_for_each_worker(wq, io_wq_worker_affinity, &od);
- rcu_read_unlock();
- return 0;
-}
-
-static int io_wq_cpu_online(unsigned int cpu, struct hlist_node *node)
-{
- struct io_wq *wq = hlist_entry_safe(node, struct io_wq, cpuhp_node);
-
- return __io_wq_cpu_online(wq, cpu, true);
-}
-
-static int io_wq_cpu_offline(unsigned int cpu, struct hlist_node *node)
-{
- struct io_wq *wq = hlist_entry_safe(node, struct io_wq, cpuhp_node);
-
- return __io_wq_cpu_online(wq, cpu, false);
-}
-
int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask)
{
cpumask_var_t allowed_mask;
@@ -1673,16 +1618,3 @@ int io_wq_max_workers(struct io_wq *wq, int *new_count)

return 0;
}
-
-static __init int io_wq_init(void)
-{
- int ret;
-
- ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "io-wq/online",
- io_wq_cpu_online, io_wq_cpu_offline);
- if (ret < 0)
- return ret;
- io_wq_online = ret;
- return 0;
-}
-subsys_initcall(io_wq_init);

base-commit: 7e3dc305a86e40ce1f9cd926ecd06d339468f5cb
--
2.53.0