Re: [PATCH 8/9] sched: Fix migrate_disable() vs set_cpus_allowed_ptr()

From: Peter Zijlstra
Date: Fri Sep 25 2020 - 04:44:08 EST


On Thu, Sep 24, 2020 at 08:59:33PM +0100, Valentin Schneider wrote:

> > + if (task_running(rq, p) || p->state == TASK_WAKING) {
> > +
> > + task_rq_unlock(rq, p, rf);
> > + stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
> > +
>
> Shouldn't we check for is_migrate_disabled(p) before doing any of that?
> migration_cpu_stop() does check for it, is there something that prevents us
> from acting on it earlier than that?

Since migrate_disable() / ->migration_disabled is only touched from the
current task, you can only reliably read it from the same CPU.

Hence I only look at it when the stop task has pinned the task, because
at that point I know it's stable.

Doing it earlier gives races, races give me head-aches. This is a slow
path, I don't care about performance.