[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251020092727.GI3245006@noisy.programming.kicks-ass.net>
Date: Mon, 20 Oct 2025 11:27:27 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>,
Gabriele Monaco <gmonaco@...hat.com>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Michael Jeanson <mjeanson@...icios.com>,
Jens Axboe <axboe@...nel.dk>,
"Paul E. McKenney" <paulmck@...nel.org>,
"Gautham R. Shenoy" <gautham.shenoy@....com>,
Florian Weimer <fweimer@...hat.com>,
Tim Chen <tim.c.chen@...el.com>,
TCMalloc Team <tcmalloc-eng@...gle.com>
Subject: Re: [patch 16/19] sched/mmcid: Provide CID ownership mode fixup
functions
On Wed, Oct 15, 2025 at 07:29:54PM +0200, Thomas Gleixner wrote:
> +static bool mm_cid_fixup_task_to_cpu(struct task_struct *t, struct mm_struct *mm)
> +{
> + /* Remote access to mm::mm_cid::pcpu requires rq_lock */
> + guard(task_rq_lock)(t);
> + if (t->mm != mm)
> + return false;
I'm slightly confused about this one; I'm assuming it is a double check
of mm for the VM_CLONE case below, once before lock once after. Except,
none of the scheduler locks actually serialize t->mm ...
IIRC the only way to actually change ->mm is exec(), and that is under
task_lock().
> + if (cid_on_task(t->mm_cid.cid)) {
> + /* If running on the CPU, transfer the CID, otherwise drop it */
> + if (task_rq(t)->curr == t)
> + mm_cid_transfer_to_cpu(t, per_cpu_ptr(mm->mm_cid.pcpu, task_cpu(t)));
> + else
> + mm_unset_cid_on_task(t);
> + }
> + return true;
> +}
> +
> +static void __maybe_unused mm_cid_fixup_tasks_to_cpus(void)
> +{
> + struct mm_struct *mm = current->mm;
> + struct task_struct *p, *t;
> + unsigned int users;
> +
> + /*
> + * This can obviously race with a concurrent affinity change, which
> + * increases the number of allowed CPUs for this mm, but that does
> + * not affect the mode and only changes the CID constraints. A
> + * possible switch back to per task mode happens either in the
> + * deferred handler function or in the next fork()/exit().
> + *
> + * The caller has already transferred. The newly incoming task is
> + * already accounted for, but not yet visible.
> + */
> + users = mm->mm_cid.users - 2;
> + if (!users)
> + return;
> +
> + guard(rcu)();
> + for_other_threads(current, t) {
> + mm_cid_fixup_task_to_cpu(t, mm);
> + users--;
> + }
> +
> + if (!users)
> + return;
> +
> + /* Happens only for VM_CLONE processes. */
Right, sorry for reminding you about this :-)
> + for_each_process_thread(p, t) {
> + if (t == current || t->mm != mm)
> + continue;
> + if (mm_cid_fixup_task_to_cpu(t, mm)) {
> + if (--users == 0)
> + return;
> + }
> + }
> +}
Powered by blists - more mailing lists