From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: tglx@kernel.org, peterz@infradead.org
Cc: linux-kernel@vger.kernel.org,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
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
Subject: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity
Date: Tue, 17 Nov 2026 11:17:00 -0500 [thread overview]
Message-ID: <cover.1794932121.git.mathieu.desnoyers@efficios.com> (raw)
Hi Thomas, Peter,
This series fixes six problems of the rseq concurrency IDs (mm_cid),
and adds selftests for them. I looked for cases the existing tests do
not reach:
- a thread count that goes up and down;
- exit, fork and a failed execve();
- affinity changes made by another process.
The fixes come first, and all six are marked for stable:
1 Give a CID to a task that joins its mm while running. A failed
execve() then no longer returns to user space with an mm_cid of
0x80000000.
2 Give no CID to io_uring and vhost workers, so that they do not
take IDs from the threads of the process.
3 Reset the stale per CPU state of an mm when its first user joins.
A machine with two or three CPUs no longer locks up after a failed
execve().
4 Keep a running joiner inactive until the fixups are done, so that
it cannot loop in mm_get_cid() while it holds mm_cid.mutex.
5 Add the allowed CPUs of the first user to the mm when it joins.
An affinity change by another task during execve() is then not
lost.
6 Fix the use after free of the old mm in set_cpus_allowed_common().
The tests, all in tools/testing/selftests/rseq. Tests 7, 8, 12 and 17
fail without the fix they check:
7 mm_cid_execve_test: the mm_cid after a failed execve(). For patch
1.
8 The last user fails execve() on another CPU. For patch 3, on
guests with 2 and 3 CPUs.
9 mm_cid_transition_test: threads count per mm_cid while the thread
count crosses the mode thresholds.
10 mm_cid_bound_test: the largest mm_cid stays below the possible
CPUs. It prints how far the IDs go above the max_cids target.
11 A transition case: affinity changes made by another process.
12 mm_cid_exec_affinity_test. For patch 5, on guests with 4 to 64
CPUs.
13 Transition cases: threads created by several threads at once, and
threads migrated by another process.
14 A bound case: the IDs after the affinity is widened. It prints
when they are not compact.
15 mm_cid_window_test: two directed cases for mode switch windows.
For patch 4, see the last point below.
16 mm_cid_teardown_test, for patch 6.
17 A second case for patch 3, see the first point below.
Points I would like your opinion on:
- Patch 3. Thomas, this is your cleanup from the thread "[PATCH]
sched/mmcid: Bound the CID allocation busy wait", which you preferred
to my fix. I wrote its subject and changelog. Change them as you see
fit. Without your Signed-off-by, the patch carries my name, with an
Originally-by: tag for you. If you send your Signed-off-by, I will
make you its author. Three remarks on the code:
- From patch 5 on, the cleanup runs in sched_mm_cid_add_first_user(),
under t->pi_lock and mm_cid.lock. Its loop over the possible CPUs
then runs with interrupts off. It could move out of the raw locks:
mm_cid.mutex is held and the mm has no user.
- The cleanup copies the allowed CPUs of the task when the mode is
not 0. Patch 5 adds them at every first join. One of the two is
enough.
- The stale state is not limited to two or three possible CPUs.
mm_cid_calc_pcpu_thrs() also returns 1 when the mm counts one
allowed CPU. Test 17 gets a CID leaked that way on guests with 4, 8
and 64 CPUs. It needs an affinity change that the mm missed during
an execve(). So it fails only without both patch 3 and patch 5. I
reproduced the lockup itself with two and three possible CPUs only.
I did not show that this lockup is the splat of that thread.
- Patch 5 has Fixes: b0c3d51b54f8. Part of its window is older and
dates from commit 7e019dcc470f ("sched: Improve cache locality of
RSEQ concurrency IDs for intermittent workloads").
- Test 15 passes on a kernel without the two fixes it targets: its
windows are a few instructions wide. It fails there only when the
kernel makes the chosen thread sleep in the window. I did that with a
local debug prctl(), which is not in this series. The test marks the
places with "Delay injection" comments. Would you want such delay
points upstream, for instance as fault injection?
Testing
=======
All tests pass in x86-64 QEMU guests with lockdep, with 2 to 64 CPUs.
Also:
- Without patch 4 and without delay injection, the sequence of test 15
hangs a guest with 2 CPUs when a SCHED_FIFO task preempts the joiner.
- Patch 2 has no test.
- I did not reproduce the use after free that patch 6 fixes. Its exec
case needs CONFIG_FUTEX=n. Test 16 passes on a KASAN guest with
CONFIG_FUTEX=n and the fix, with no report.
- Tests 11, 13 and 16 are stress tests. They found no bug.
A Spin model of the mode switches found the problem of patch 4. It is
not part of the series.
How this was developed
======================
An LLM coding assistant reviewed the mm_cid code under my direction. It
wrote all the patches, their messages and the tests, which I reviewed.
There are two exceptions. The code of patch 3 is Thomas's. Patch 6 is
Weiming Shi's, carried as he posted it. Test 16 follows the shape of his
reproducer, and takes no code from it.
A reproducer that stops failing shows that the symptom goes away. It
does not show that the fix is the one you would have written, so I ask
for a careful reading.
Based on tip sched/urgent, 006991aa8997.
Links:
- Weiming Shi, "[PATCH v3] sched/mmcid: Synchronize MM teardown with
affinity updates":
https://lore.kernel.org/all/20261110183809.3308868-1-bestswngs@gmail.com/
- "[PATCH] sched/mmcid: Bound the CID allocation busy wait":
https://lore.kernel.org/all/87mrs8bhp4.ffs@fw13/
- My reply in that thread, with my variant of patch 3 and the
reproducer:
https://lore.kernel.org/all/bd4c03e6-7ea6-4a21-9a3e-74ea9d36fe17@efficios.com/
- Thomas's answer, which prefers the cleanup:
https://lore.kernel.org/all/87eccossye.ffs@fw13/
Mathieu Desnoyers (16):
sched/mmcid: Give a CID to a task that joins its mm while running
sched/mmcid: Give no concurrency ID to user workers
sched/mmcid: Reset stale state when the first user joins an mm
sched/mmcid: Let a running joiner take its CID after the fixups
sched/mmcid: Take the allowed CPUs of the first user when it joins
selftests/rseq: Test the concurrency ID after a failed execve
selftests/rseq: Test the concurrency ID after the last user fails
execve
selftests/rseq: Test the concurrency IDs across ownership mode
switches
selftests/rseq: Test the upper bound of the concurrency IDs
selftests/rseq: Test affinity changes made by another process
selftests/rseq: Test an affinity change by another process during
execve
selftests/rseq: Test concurrent thread creation and forced migration
selftests/rseq: Test the concurrency IDs after the affinity is widened
selftests/rseq: Test two race windows of the concurrency ID mode
switches
selftests/rseq: Test affinity changes while a task replaces or drops
its mm
selftests/rseq: Test the last user after an affinity change during
execve
Weiming Shi (1):
sched/mmcid: Synchronize MM teardown with affinity updates
fs/exec.c | 1 +
include/linux/sched.h | 2 +
kernel/exit.c | 1 +
kernel/kthread.c | 1 +
kernel/sched/core.c | 151 +++-
tools/testing/selftests/rseq/.gitignore | 5 +
tools/testing/selftests/rseq/Makefile | 5 +-
.../selftests/rseq/mm_cid_bound_test.c | 441 +++++++++++
.../rseq/mm_cid_exec_affinity_test.c | 283 ++++++++
.../selftests/rseq/mm_cid_execve_test.c | 685 ++++++++++++++++++
.../selftests/rseq/mm_cid_teardown_test.c | 396 ++++++++++
.../selftests/rseq/mm_cid_transition_test.c | 511 +++++++++++++
.../selftests/rseq/mm_cid_window_test.c | 485 +++++++++++++
13 files changed, 2942 insertions(+), 25 deletions(-)
create mode 100644 tools/testing/selftests/rseq/mm_cid_bound_test.c
create mode 100644 tools/testing/selftests/rseq/mm_cid_exec_affinity_test.c
create mode 100644 tools/testing/selftests/rseq/mm_cid_execve_test.c
create mode 100644 tools/testing/selftests/rseq/mm_cid_teardown_test.c
create mode 100644 tools/testing/selftests/rseq/mm_cid_transition_test.c
create mode 100644 tools/testing/selftests/rseq/mm_cid_window_test.c
base-commit: 006991aa89974378ee579416dba87adc22cd60fd
--
2.47.3
next reply other threads:[~2026-11-17 16:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:17 Mathieu Desnoyers [this message]
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-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-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-17 16:17 ` [PATCH 17/17] selftests/rseq: Test the last user after an affinity change during execve 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=cover.1794932121.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=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®