From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: tglx@kernel.org, peterz@infradead.org
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, mingo@redhat.com,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, paulmck@kernel.org, boqun@kernel.org,
shuah@kernel.org, kees@kernel.org, viro@zeniv.linux.org.uk,
brauner@kernel.org, jack@suse.cz, oleg@redhat.com,
bestswngs@gmail.com, xmei5@asu.edu, xujiakai24@mails.ucas.ac.cn,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kselftest@vger.kernel.org, kmehltretter@gmail.com
Subject: [PATCH v2 04/13] sched/mmcid: Give no concurrency ID to user workers
Date: Tue, 1 Dec 2026 19:27:52 -0500 [thread overview]
Message-ID: <a90ebc59893e6a994c5f93523e688e611960536a.1796169827.git.mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <cover.1796169827.git.mathieu.desnoyers@efficios.com>
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 <mathieu.desnoyers@efficios.com>
---
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
next prev parent reply other threads:[~2026-12-02 0:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 0:27 [PATCH v2 00/13] sched/mmcid: fixes for execve, mode switches and affinity Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 01/13] sched/mmcid: Move the execve() hooks into exec_mmap() Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 02/13] sched/mmcid: Add the allowed CPUs of each joining task to the mm Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 03/13] sched/mmcid: Serialize joins and exits with affinity changes by pi_lock Mathieu Desnoyers
2026-12-02 0:27 ` Mathieu Desnoyers [this message]
2026-12-02 0:27 ` [PATCH v2 05/13] selftests/rseq: Test the concurrency ID after a failed execve Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 06/13] selftests/rseq: Test the concurrency IDs across ownership mode switches Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 07/13] selftests/rseq: Test the upper bound of the concurrency IDs Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 08/13] selftests/rseq: Test an affinity change by another process during execve Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 09/13] selftests/rseq: Test the concurrency IDs after the affinity is widened Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 10/13] selftests/rseq: Test two race windows of the concurrency ID mode switches Mathieu Desnoyers
2026-12-02 0:27 ` [PATCH v2 11/13] selftests/rseq: Test the last user after an affinity change during execve Mathieu Desnoyers
2026-12-02 0:28 ` [PATCH v2 12/13] selftests/rseq: Test the concurrency IDs with an io_uring SQPOLL thread Mathieu Desnoyers
2026-12-02 0:28 ` [PATCH v2 13/13] selftests/rseq: Test the concurrency IDs after clone3() into a wider cpuset Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a90ebc59893e6a994c5f93523e688e611960536a.1796169827.git.mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=bestswngs@gmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jack@suse.cz \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kmehltretter@gmail.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
--cc=xmei5@asu.edu \
--cc=xujiakai24@mails.ucas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®