[PATCH 02/17] sched/mmcid: Give no concurrency ID to user workers
From: Mathieu Desnoyers
Date: Tue Nov 17 2026 - 11:17:33 EST
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 only
run kernel code: copy_process() gives them a kernel function that ends
in do_exit(). They never return to user space and have no rseq area.
sched_mm_cid_fork() still makes them users of the CIDs of the mm, like
every task with an mm. A worker takes a CID whenever it runs. It also
counts as a user for max_cids and for the switch to per CPU mode.
Nothing reports the CID of a worker. But it is one CID fewer for the
threads of the process, which then get larger ones. The added users can
also switch the mm to per CPU mode. A process with io_uring workers
would then read mm_cid values at or above its number of threads. This
was found by reading the code, and has no test.
Fix this by not making a user worker a user of the CIDs. Kernel threads
are already left out, as they have no mm.
Fixes: af7f588d8f73 ("sched: Introduce per-memory-map concurrency ID")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
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 f2a981d418eb..7e213e88ac28 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11000,7 +11000,11 @@ static void sched_mm_cid_fork(struct task_struct *t)
struct mm_struct *mm = t->mm;
bool percpu = false, flip = false;
- 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