From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Thomas Gleixner <tglx@kernel.org>,
Karl Mehltretter <kmehltretter@gmail.com>
Cc: peterz@infradead.org, 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,
Dominik Maier <dmnk@google.com>
Subject: Re: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity
Date: Mon, 30 Nov 2026 13:59:49 -0500 [thread overview]
Message-ID: <bd662cfb-4594-4868-9a7e-0393259b98e0@efficios.com> (raw)
In-Reply-To: <87ecc2qs9i.ffs@fw13>
On 2026-11-30 09:59, Thomas Gleixner wrote:
> That makes the whole thing even simpler. Updated patch below.
Thanks Thomas, and thanks Karl for the ptrace and vfork cases.
I applied this patch and your affinity patch [1] on tip sched/urgent
(006991aa8997), with the selftests of the series on top. I split the
affinity patch as you asked:
1) mm_init_cid() clears the allowed CPUs of the mm, and exec_mmap()
no longer calls it. A task that joins the mm adds its allowed
CPUs.
2) sched_mm_cid_fork() and sched_mm_cid_exit() take pi_lock around
mm_cid::lock. mm_update_cpus_allowed() gets the task instead of
the mm, and does nothing when the task is not active.
I left out the hunk on sched_mm_cid_cleanup_execve(), as your updated
patch no longer adds that function.
Your two patches replace the fixes 01 and 03 to 06 of the series, so I
would drop them. This includes patch 06 from Weiming Shi: an affinity
update now touches p->mm only while the task is an active user of it.
Could you credit Weiming in the affinity patch, with a Reported-by: or a
link to his patch [2]?
I ran the selftests with lockdep, on x86 guests with 2 to 64 CPUs. I
ran them with both parts of the split, and with the first part alone.
The results are the same. Here are the cases of Karl's list:
- execve_test case 1 (07/17) and case 3 (17/17) pass on all guests.
So does exec_affinity_test case 2 (12/17).
- execve_test case 2 (08/17) fails on 2 and 3 CPUs. Karl saw it on 2.
I agree that it tests a detail of my implementation. The case needs
per CPU mode to last down to one thread, which happens only with 2
or 3 possible CPUs. That thread then fails execve(). With your
patch, it no longer leaves the CID management of the mm. So on
CPU 1 it reads the CID of CPU 1, as it would without the execve().
That is a valid CID. I will drop this case.
All the other cases pass.
Two small things:
- In the affinity patch, the !CONFIG_SCHED_MM_CID stub of
mm_update_cpus_allowed() has no body: "{ }" is missing. I added it
in my split.
- In this patch, the new comment in the last user branch of
sched_mm_cid_exit() says that sched_mm_cid_after_execve() handles
a stale transit. That function has no such code in this version.
It does not need it: with the hooks in exec_mmap(), a task never
rejoins the old mm. So the last sentence of the comment can go.
I also checked your two patches with the Spin model I mentioned in the
cover letter. It runs up to 3 tasks on 2 or 3 CPUs, with up to 6
possible CPUs. No run found a violation of these:
- The CIDs stay unique and below the number of possible CPUs.
- mm_get_cid() never waits.
- No affinity change is lost.
- The affinity update never reads a freed mm.
Without your patches, the model finds the known bugs, the 0x80000000
CID among them.
The model found one new case with your affinity patch. It needs 4
possible CPUs or more. The mm starts in per CPU mode, and pcpu_thrs
was computed for the allowed CPUs of its threads. Then:
- A new child gets more allowed CPUs before sched_post_fork().
Another task can do this with sched_setaffinity() on the new pid.
With CLONE_INTO_CGROUP, cpuset_fork() does it with the CPUs of the
target cpuset.
- mm_update_cpus_allowed() skips the child, which is not active yet.
- sched_mm_cid_add_user() adds the child's CPUs to the mm. It drops
the return value of __mm_update_cpus_allowed(), so pcpu_thrs is not
recomputed.
pcpu_thrs keeps the value of the smaller mask. So the mm stays in per
CPU mode when its user count drops below the threshold of the new
mask. Only an affinity change which adds a CPU to the mm recomputes
pcpu_thrs later. For example, a process left with 2 threads allowed on
6 CPUs would use CIDs up to 5 instead of 0 and 1. The CIDs stay unique
and in bounds.
This change on top of your affinity patch passes in the model. The
selftests give the same results with it:
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11007,8 +11007,12 @@ static bool sched_mm_cid_add_user(struct task_struct *t, struct mm_struct *mm)
/*
* Update allowed CPUs to take any affinity change, which happened
* before sched_mm_cid_fork() acquired the locks, into account.
+ * Adjust the threshold to a wider set, as mm_update_cpus_allowed()
+ * does.
*/
- __mm_update_cpus_allowed(mm, &t->cpus_mask);
+ if (__mm_update_cpus_allowed(mm, &t->cpus_mask) &&
+ cid_on_cpu(mm->mm_cid.mode))
+ mm->mm_cid.pcpu_thrs = mm_cid_calc_pcpu_thrs(&mm->mm_cid);
t->mm_cid.active = 1;
hlist_add_head(&t->mm_cid.node, &mm->mm_cid.user_list);
How do you want to route your patches? You can take them yourself.
Or I can carry them in the next version of this series, if you give me
your Signed-off-by for them. The selftests would come on top.
Thanks,
Mathieu
[1] https://lore.kernel.org/all/87v75fqnsi.ffs@fw13/
[2] https://lore.kernel.org/all/20261110183809.3308868-1-bestswngs@gmail.com/
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
next prev parent reply other threads:[~2026-11-30 18:59 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:17 [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 01/17] sched/mmcid: Give a CID to a task that joins its mm while running Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 02/17] sched/mmcid: Give no concurrency ID to user workers Mathieu Desnoyers
2026-11-18 16:17 ` sashiko-bot
2026-11-18 20:39 ` Mathieu Desnoyers
2026-11-29 21:54 ` Thomas Gleixner
2026-11-30 16:23 ` Steven Rostedt
2026-11-30 18:57 ` Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 03/17] sched/mmcid: Reset stale state when the first user joins an mm Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 04/17] sched/mmcid: Let a running joiner take its CID after the fixups Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 05/17] sched/mmcid: Take the allowed CPUs of the first user when it joins Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 06/17] sched/mmcid: Synchronize MM teardown with affinity updates Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 07/17] selftests/rseq: Test the concurrency ID after a failed execve Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 08/17] selftests/rseq: Test the concurrency ID after the last user fails execve Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 09/17] selftests/rseq: Test the concurrency IDs across ownership mode switches Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 10/17] selftests/rseq: Test the upper bound of the concurrency IDs Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 11/17] selftests/rseq: Test affinity changes made by another process Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 12/17] selftests/rseq: Test an affinity change by another process during execve Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 13/17] selftests/rseq: Test concurrent thread creation and forced migration Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 14/17] selftests/rseq: Test the concurrency IDs after the affinity is widened Mathieu Desnoyers
2026-11-18 16:17 ` sashiko-bot
2026-11-18 20:39 ` Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 15/17] selftests/rseq: Test two race windows of the concurrency ID mode switches Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 16/17] selftests/rseq: Test affinity changes while a task replaces or drops its mm Mathieu Desnoyers
2026-11-18 16:17 ` sashiko-bot
2026-11-18 20:40 ` Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 17/17] selftests/rseq: Test the last user after an affinity change during execve Mathieu Desnoyers
2026-11-28 10:28 ` [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity Thomas Gleixner
2026-11-28 19:22 ` Karl Mehltretter
2026-11-28 22:40 ` Thomas Gleixner
2026-11-29 21:48 ` Thomas Gleixner
2026-11-29 22:24 ` Thomas Gleixner
2026-11-29 22:54 ` Karl Mehltretter
2026-11-30 14:59 ` Thomas Gleixner
2026-11-30 18:59 ` Mathieu Desnoyers [this message]
2026-11-30 20:36 ` Thomas Gleixner
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=bd662cfb-4594-4868-9a7e-0393259b98e0@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=dmnk@google.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