Re: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity

From: Karl Mehltretter

Date: Sun Nov 29 2026 - 17:54:18 EST


On Sun, Nov 29, 2026 at 10:48:39PM +0100, Thomas Gleixner wrote:
> + /*
> + * 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. Doing it here guarantees that the MM has only the
> + * current task left.
> + *

vfork() and CLONE_VM without CLONE_THREAD breaks that assumption:
de_thread() only terminates threads in the same thread group, not other
tasks sharing the MM.

When execve() fails in a CLONE_VM child before the MM switch,
sched_mm_cid_cleanup_execve() modifies the shared MM locklessly while
the parent's threads are still active. Allocation-failure injection on
x86 KVM hits:

WARNING: kernel/sched/core.c:11198 at sched_mm_cid_after_execve+0x309/0x3a0

Could both hooks move into exec_mmap() instead?

Leave the old MM after mm_exit_exec_release() and join the new one after
mmap_read_unlock(). The only failures in between are killable lock
waits, which require a pending SIGKILL, so the old MM never needs to be
rejoined. This removes new_mm and sched_mm_cid_cleanup_execve(), and
avoids holding the locks across irq_work_sync() and cancel_work_sync().

Thanks,
Karl
---
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -857,6 +857,7 @@ static int exec_mmap(struct linux_binprm *bprm)
old_mm = current->mm;
/* Clean up futexes and release the mm */
mm_exit_exec_release(tsk, old_mm);
+ sched_mm_cid_before_execve(tsk);

ret = down_write_killable(&tsk->signal->exec_update_lock);
if (ret)
@@ -909,6 +910,7 @@ static int exec_mmap(struct linux_binprm *bprm)
mmdrop_lazy_tlb(active_mm);
}
futex_exec_done(tsk);
+ sched_mm_cid_after_execve(tsk);
return 0;
}

@@ -1853,7 +1855,6 @@ static int bprm_execve(struct linux_binprm *bprm)
*/
check_unsafe_exec(bprm);
current->in_execve = 1;
- sched_mm_cid_before_execve(current);

sched_exec();

@@ -1866,7 +1867,6 @@ static int bprm_execve(struct linux_binprm *bprm)
if (retval < 0)
goto out;

- sched_mm_cid_after_execve(current);
rseq_execve(current);
/* execve succeeded */
current->in_execve = 0;
@@ -1885,7 +1885,6 @@ static int bprm_execve(struct linux_binprm *bprm)
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;