sched/mmcid: fixes for execve, mode switches and affinity
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest17 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/17 | sched/mmcid: Give a CID to a task that joins its mm while runningkernel/ | +35 | 0 replies | |
| 2/17 | sched/mmcid: Give no concurrency ID to user workerskernel/ | +5 | 0 replies | |
| 3/17 | sched/mmcid: Reset stale state when the first user joins an mmkernel/ | +32 | 0 replies | |
| 4/17 | sched/mmcid: Let a running joiner take its CID after the fixupskernel/ | +13 | 0 replies | |
| 5/17 | sched/mmcid: Take the allowed CPUs of the first user when it joinskernel/ | +45 | 0 replies | |
| 6/17 | sched/mmcid: Synchronize MM teardown with affinity updatesfs/ include/ kernel/ +2 more | +14 | 0 replies | |
| 7/17 | selftests/rseq: Test the concurrency ID after a failed execvetools/ tools/ tools/ | +279 | 0 replies | |
| 8/17 | selftests/rseq: Test the concurrency ID after the last user fails execvetools/ | +208 | 0 replies | |
| 9/17 | selftests/rseq: Test the concurrency IDs across ownership mode switchestools/ tools/ tools/ | +377 | 0 replies | |
| 10/17 | selftests/rseq: Test the upper bound of the concurrency IDstools/ tools/ tools/ | +358 | 0 replies | |
| 11/17 | selftests/rseq: Test affinity changes made by another processtools/ | +68 | 0 replies | |
| 12/17 | selftests/rseq: Test an affinity change by another process during execvetools/ tools/ tools/ | +285 | 0 replies | |
| 13/17 | selftests/rseq: Test concurrent thread creation and forced migrationtools/ | +121 | 0 replies | |
| 14/17 | selftests/rseq: Test the concurrency IDs after the affinity is widenedtools/ | +87 | 0 replies | |
| 15/17 | selftests/rseq: Test two race windows of the concurrency ID mode switchestools/ tools/ tools/ | +488 | 0 replies | |
| 16/17 | selftests/rseq: Test affinity changes while a task replaces or drops its mmtools/ tools/ | +397 | 0 replies | |
| 17/17 | selftests/rseq: Test the last user after an affinity change during execvetools/ | +232 | 0 replies |
Reviews trailers per patch
None of the 17 patches has a Reviewed-by or Acked-by.
| Patch | Thomas Gleixner |
|---|---|
| 1/17 | |
| 2/17 | |
| 3/17 | Originally-by |
| 4/17 | |
| 5/17 | |
| 6/17 | |
| 7/17 | |
| 8/17 | |
| 9/17 | |
| 10/17 | |
| 11/17 | |
| 12/17 | |
| 13/17 | |
| 14/17 | |
| 15/17 | |
| 16/17 | |
| 17/17 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity
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/[email protected]/
- "[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/[email protected]/
- 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
Signature · 1 line
2.47.3