Linux filesystem development
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, 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,
	Dominik Maier <dmnk@google.com>
Subject: Re: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity
Date: Sat, 28 Nov 2026 11:28:05 +0100	[thread overview]
Message-ID: <87bj79s11m.ffs@fw13> (raw)
In-Reply-To: <cover.1794932121.git.mathieu.desnoyers@efficios.com>

On Tue, Nov 17 2026 at 11:17, Mathieu Desnoyers wrote:
> 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().

#1, #3 and #4 are all caused by the fact that the exec()'ing task
disables MM CID right at the beginning of exec(). But that can be
completely avoided because the only requirement to deactivate it is when
the task is about to switch to the new MM, i.e. after all other threads
are torn down.

So instead of adding duct tape and haywire in the MM CID core code we
really should fix the underlying problem. See untested patch below.

#6 is incomplete vs. exec() switching MMs because the new MM is visible
before MMCID has been initialized on it. I look into that seperately.

Thanks,

        tglx
---
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1171,6 +1171,21 @@ int begin_new_exec(struct linux_binprm *
 	 */
 	posixtimer_exec();
 
+	/*
+	 * Remove the task from the MM CID management which is associated to the
+	 * original MM. This is done here to avoid leaving and rejoining the MM
+	 * CID management _before_ all threads of the the process have been
+	 * terrminated.
+	 *
+	 * On success the task invokes sched_mm_cid_after_execve() in
+	 * bprm_execve().
+	 *
+	 * In case that the below fails, the task will not return to user space
+	 * because bprm->point_of_no_return is set so there is no point to bring
+	 * the task back into MM CID management.
+	 */
+	sched_mm_cid_before_execve(current);
+
 	/* see the comment in check_unsafe_exec() */
 	current->fs->in_exec = 0;
 
@@ -1853,7 +1868,6 @@ static int bprm_execve(struct linux_binp
 	 */
 	check_unsafe_exec(bprm);
 	current->in_execve = 1;
-	sched_mm_cid_before_execve(current);
 
 	sched_exec();
 
@@ -1866,7 +1880,14 @@ static int bprm_execve(struct linux_binp
 	if (retval < 0)
 		goto out;
 
+	/*
+	 * Reactivating MM CID is only required for the success case. The
+	 * exec()'ing task deactivates MM CID after bprm->point_of_no_return has
+	 * been set true, so any failure after that point will prevent the task
+	 * from going back to user space.
+	 */
 	sched_mm_cid_after_execve(current);
+
 	rseq_execve(current);
 	/* execve succeeded */
 	current->in_execve = 0;
@@ -1885,7 +1906,6 @@ static int bprm_execve(struct linux_binp
 	if (bprm->point_of_no_return && !fatal_signal_pending(current))
 		force_fatal_sig(SIGSEGV);
 
-	sched_mm_cid_after_execve(current);
 	rseq_force_update();
 	current->in_execve = 0;
 
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11166,7 +11166,7 @@ void sched_mm_cid_exit(struct task_struc
 	cancel_work_sync(&mm->mm_cid.work);
 }
 
-/* Deactivate MM CID allocation across execve() */
+/* Deactivate MM CID allocation across execve() switching MM */
 void sched_mm_cid_before_execve(struct task_struct *t)
 {
 	sched_mm_cid_exit(t);


      parent reply	other threads:[~2026-11-28 10:28 UTC|newest]

Thread overview: 19+ 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-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
2026-11-28 10:28 ` Thomas Gleixner [this message]

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=87bj79s11m.ffs@fw13 \
    --to=tglx@kernel.org \
    --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=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=mathieu.desnoyers@efficios.com \
    --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=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