Re: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity
From: Thomas Gleixner
Date: Mon Nov 30 2026 - 15:36:43 EST
On Mon, Nov 30 2026 at 13:59, Mathieu Desnoyers wrote:
> 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.
Correct. I missed that one.
> 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.
Indeed.
> 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.
Sure, pick them up and fold the fixes in. Just add a Suggested-by: tglx
tag. That's good enough.
Thanks,
tglx