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: Sat, 5 Dec 2026 04:50:39 +0100	[thread overview]
Message-ID: <axOHKopYVUAaHlHk@gmail.com> (raw)
In-Reply-To: <20261204124434.GT2668804@noisy.programming.kicks-ass.net>

On Fri, Dec 04, 2026 at 01:44:34PM +0100, Peter Zijlstra wrote:
> Ooh, you created a TLA+ model for this? Valentin was looking to update
> his old one. Can you share?

Sure. It's in my repository for locking models:

https://github.com/kmehltretter82/linux-locking-formal

> > 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.
> 
> You mean something like so, right?

Not quite. When no CPU in p's mask is allowed, __select_fallback_rq()
takes the cpuset fallback, which needs task_rq(p) locked. Before the
task_rq() check, p may have left rq already:

CPU-A                           CPU-B           CPU-C

<p -> stopper>
  sched_non_preferred_cpu_push_stop()
                                                set_cpus_allowed_ptr(p, B)
                                                  // p -> B
                                sched_cpu_deactivate()
    lock(p->pi_lock)
    rq_lock()
    __select_fallback_rq()
      cpuset_cpus_allowed_fallback()
        __set_cpus_allowed_force()
          do_set_cpus_allowed()
            // p is on B, we hold A's rq lock
            WARN!!


Lockdep reports this in QEMU when hooks delay the stopper.

With p still on rq, the fallback updates the rq clock. The
update_rq_clock() after it then triggers WARN_DOUBLE_CLOCK.

The model of your diff:

https://github.com/kmehltretter82/linux-locking-formal/blob/0904b644a923/kernel/sched/hotplug-push/tla/Cfg9_NpcPush_SelectAfterRqLock_UnlockedRqEdit.cfg

Selecting inside the checks, between rq_clock_start_loop_update() and
rq_clock_stop_loop_update(), passes the model and both QEMU tests:

https://github.com/kmehltretter82/linux-locking-formal/blob/0904b644a923/kernel/sched/hotplug-push/tla/Cfg13_NpcPush_SelectInChecksSkipClockSafe.cfg

Cfg11 and Cfg14 in the same directory are the same two for
__balance_push_cpu_stop().

The diff I tested is below.

Thanks,
Karl

---
 kernel/sched/core.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 514c4b5..dbc930a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8452,12 +8452,14 @@ static int __balance_push_cpu_stop(void *arg)
 		 */
 		context_unsafe_alias(rq);
 
-		cpu = select_fallback_rq(rq->cpu, p);
-
 		rq_lock(rq, &rf);
 		update_rq_clock(rq);
-		if (task_rq(p) == rq && task_on_rq_queued(p))
+		if (task_rq(p) == rq && task_on_rq_queued(p)) {
+			rq_clock_start_loop_update(rq);
+			cpu = __select_fallback_rq(rq->cpu, p);
+			rq_clock_stop_loop_update(rq);
 			rq = move_queued_task(rq, &rf, p, cpu);
+		}
 		rq_unlock(rq, &rf);
 	}
 
@@ -11354,14 +11356,6 @@ static int sched_non_preferred_cpu_push_stop(void *arg)
 	}
 
 	scoped_guard (raw_spinlock_irq, &p->pi_lock) {
-		/*
-		 * select_fallback_rq() may acquire the rq lock in case of
-		 * fallback. So call it before grabbing rq lock. If the task
-		 * migrates to another CPU before the rq lock is acquired,
-		 * subsequent validation of task's current rq will help to
-		 * safely bail out.
-		 */
-		cpu = select_fallback_rq(rq->cpu, p);
 		context_unsafe_alias(rq);
 		rq_lock(rq, &rf);
 		rq->npc_push_work_pending = false;
@@ -11369,7 +11363,12 @@ static int sched_non_preferred_cpu_push_stop(void *arg)
 
 		if (task_rq(p) == rq && task_on_rq_queued(p) &&
 		    !is_migration_disabled(p)) {
-			struct rq *dest_rq = move_queued_task(rq, &rf, p, cpu);
+			struct rq *dest_rq;
+
+			rq_clock_start_loop_update(rq);
+			cpu = __select_fallback_rq(rq->cpu, p);
+			rq_clock_stop_loop_update(rq);
+			dest_rq = move_queued_task(rq, &rf, p, cpu);
 
 			if (rq != dest_rq)
 				schedstat_inc(p->stats.nr_migrations_cpu_non_preferred);


  reply	other threads:[~2026-12-05  3:51 UTC|newest]

Thread overview: 22+ 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 11:04                       ` Peter Zijlstra
2026-12-04  1:44               ` Karl Mehltretter
2026-12-04 12:44                 ` Peter Zijlstra
2026-12-05  3:50                   ` 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=axOHKopYVUAaHlHk@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