The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Karl Mehltretter <kmehltretter@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	 linux-kernel@vger.kernel.org,
	syzbot <syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com>,
	 Thomas Gleixner <tglx@kernel.org>, Radu Rendec <radu@rendec.net>,
	Ingo Molnar <mingo@redhat.com>,
	 Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	 Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>
Subject: Re: [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop()
Date: Fri, 4 Dec 2026 02:44:55 +0100	[thread overview]
Message-ID: <axIZyLafxYayeTnY@gmail.com> (raw)
In-Reply-To: <20261203130519.GC677025@noisy.programming.kicks-ass.net>

On Thu, Dec 03, 2026 at 02:05:19PM +0100, Peter Zijlstra wrote:
> On Thu, Dec 03, 2026 at 02:50:42AM +0100, Karl Mehltretter wrote:
> > I'm still wondering about migrate_disable().
> > 
> > Unlike try_to_wake_up(), the push stoppers call select_fallback_rq()
> > before taking rq->lock. If p is running on another CPU with migration
> > disabled at that point, is_cpu_allowed() only checks cpu_online().
> > 
> > Could p then re-enable migration and move back to rq before
> > rq_lock() in sched_non_preferred_cpu_push_stop()?
> 
> I am not quite seeing the race; everything is serialized by p->pi_lock,
> no?
> 
> Draw me a picture?
> 

Here's one from a TLA+ model of your sched/urgent branch. Very
unlikely in practice, but rc5 doesn't have it.

Four CPUs, !PREEMPT_RT. A is non-preferred, B is going offline, C and D
are in softirq balance passes that started while A was still preferred,
and A has queued active balance work on C.

   1. B: sched_cpu_deactivate(), synchronize_rcu() starts
   2. A: npc stopper preempts p, takes p->pi_lock
   3. D: balance pass pulls p from A
   4. D: p runs, migrate_disable()
   5. A: select_fallback_rq() returns B; p is migration-disabled,
         so is_cpu_allowed() only checks p->cpus_ptr and cpu_online(B)
   6. D: p does migrate_enable(), gets preempted
   7. C: balance pass pulls p from D
   8. B: grace period ends, sched_cpu_wait_empty(),
         stop_machine() queues multi_cpu_stop
   9. C: active balance moves p back to A
  10. A: rq_lock(); p is on A with migration enabled,
         move_queued_task(rq, &rf, p, B)
  11. B: sched_cpu_dying(): "Dying CPU not properly vacated!"

p->pi_lock doesn't cover the migrate_disable()/migrate_enable() fast
paths (4, 6), nor the load balancing (3, 7, 9). D can pull from A
because its pass computed env->cpus while A was still preferred. C's
queued work can't run before its pass returns.

The grace period waits for both passes, but not for A, which has already
reported a quiescent state for it.

The !is_migration_disabled(p) check Sebastian pointed out passes in
step 10, since p is no longer migration-disabled. rc5's __migrate_task()
would have refused B; commit 22bdf9cf90ec ("sched: Plug hole in
set_cpus_allowed_ptr()") drops that recheck.

For this you need:

 - A's stopper delayed between steps 2 and 10, past the end of the
   grace period;
 - C and D to stay in their passes until steps 3 and 7;
 - B's cpus_write_lock() to not wait for a grace period. It comes after
   the governor cleared A from cpu_preferred_mask, so the previous
   hotplug operation's rcu_sync grace period must still be running, not
   wait for the passes, and be followed directly by B's.

I also reproduced it in QEMU on sched/urgent, with debug hooks that
busy-wait at those points, pick the CPUs to pull from and force the
active balance. Apart from the waits, the migration, locking, RCU and
hotplug code is unchanged. All five runs hit the warning and left p
running on the offline B; my test task never blocks, so _cpu_down()
never returns.

Doing __select_fallback_rq() under rq_lock(), after the existing checks,
should fix it. I ran the same test three times with that change: p goes
to C and the offline completes each time.

Thanks,
Karl

  parent reply	other threads:[~2026-12-04  1:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 17:16 [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop() Sebastian Andrzej Siewior
2026-11-21 13:20 ` Karl Mehltretter
2026-11-21 14:39 ` Karl Mehltretter
2026-11-25 17:20 ` Peter Zijlstra
2026-11-25 19:37   ` Sebastian Andrzej Siewior
2026-11-26 10:40     ` Peter Zijlstra
2026-11-28 17:24       ` Karl Mehltretter
2026-12-02 14:26         ` Sebastian Andrzej Siewior
2026-12-02 14:42         ` Peter Zijlstra
2026-12-03  1:50           ` Karl Mehltretter
2026-12-03 13:05             ` Peter Zijlstra
2026-12-03 14:19               ` Sebastian Andrzej Siewior
2026-12-03 14:33                 ` Peter Zijlstra
2026-12-03 15:37                   ` Peter Zijlstra
2026-12-03 17:42                     ` Sebastian Andrzej Siewior
2026-12-04  1:44               ` Karl Mehltretter [this message]
2026-12-02 14:12       ` Sebastian Andrzej Siewior
2026-12-03 11:25 ` Zhen Wang
2026-12-03 12:05   ` Sebastian Andrzej Siewior

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=axIZyLafxYayeTnY@gmail.com \
    --to=kmehltretter@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=radu@rendec.net \
    --cc=rostedt@goodmis.org \
    --cc=syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /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