The workers of io_uring and vhost are PF_USER_WORKER tasks. They are threads of the process they work for, created with CLONE_VM. They run a kernel function until they exit. They never return to user space and have no rseq area, so nothing reads their CID. But sched_mm_cid_fork() makes them users of the CIDs, like every task with an mm. The kernel aims to keep the CIDs below the smaller of two counts: the users, and the CPUs they may run on. User space can then keep compact per-CPU data indexed by CID. A worker adds to both counts. In per task mode, it also keeps a CID which the threads of the process cannot use. An io_uring SQPOLL thread without a fixed CPU sets its affinity to all online CPUs when it starts. set_cpus_allowed_ptr() does not limit this to the cpuset of the process. The allowed CPUs of the mm only grow, so they stay wide after the worker exits. The CIDs then spread over more values than the process has CPUs. They stay below the number of possible CPUs, so nothing breaks. In testing, a process in a cpuset of two CPUs created an io_uring with an SQPOLL thread. Its three threads then read mm_cid values up to 3. The Sashiko AI review found this case. Skip user workers in sched_mm_cid_fork(). Their mm_cid.active then stays 0, so mm_update_cpus_allowed() ignores their affinity changes. Kernel threads are already skipped, as they have no mm. With this change, the three threads read mm_cid values of at most 1. Signed-off-by: Mathieu Desnoyers --- kernel/sched/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 575813b1ae97..cee702c981e5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11091,7 +11091,11 @@ static void sched_mm_cid_fork(struct task_struct *t) struct mm_struct *mm = t->mm; bool percpu; - if (!mm) + /* + * A user worker (io_uring, vhost) never returns to user space and + * has no rseq area. It needs no CID. + */ + if (!mm || (t->flags & PF_USER_WORKER)) return; WARN_ON_ONCE(t->mm_cid.cid != MM_CID_UNSET); -- 2.47.3