From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=90.155.92.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388284; b=Ywo8z2TE8nzHt9x3gbFXqdpJQKLRurs1nSBJCZ8ptrkVM1dTsRi5dee2iFHkcn2rwdFV C3jjk3Kh+L2KVNArJFLmgXg5FfZ6vnonQDoNt3+iU/kQ2NBaijqDXeFrkoeW4l9Eb/pTy rGdqnAShX5tREvIr//L4rfci0wQvIrtKEvAXt3ellswrmJSuffHUe4F8nfuV1O96l5Ptq xEU2qDMgN+z6haEKwIF5UxFqrVraidvI6v/LirQFvOzLPK4LndmQSoV6bmr+sylr3laAu 0wADFlqY6ht/Bjd3jeEgDLbZOj3Fr/21sOOlrp31PPWHPKbN0+hLpmqUpbtjjyhKjFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388284; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=wx/LC2Thzi1bgqy2X64lGF+DfzJj5+fZEg3tE2CB/bs=; b=YSqf9TIJXmmNaXVTTz3eNGKGUH+p2thD/QM1HpT3354gDrebmesWDO8dT/6sTCK5wU47 bMsXb4sJ/UjCkHbeDFMR+lxqJ86/ac3OAj9KhHrmULQPukpddnSggbbUf7sNTPhGHLStk 3VJScPFMgN2Pd25JWPJ5St3oyEe/Cl9gTjgrJ6ocaOqiVFvDNhj2AH9GsWJgAnhk/JWj4 81a/wuv+xvOFVLkyfdFxvExyi6d3Q+VsLlb4Y/K13p7e0zwgPvYWRyOSkMgj0SsRw76/Q WO8USdla6e81uiT4dnXG5WqQLxDovFH53j60G4Jc22tkVsiCCJhpsXo9Nl7eDqlzJCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=JRx8e1aB; arc=none smtp.remote-ip=90.155.92.199 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26919606A322 for ; Fri, 4 Dec 2026 12:44:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 26919606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=JRx8e1aB DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=wx/LC2Thzi1bgqy2X64lGF+DfzJj5+fZEg3tE2CB/bs=; b=JRx8e1aBhjaztUYGvwfub3DLDq U3kkFv1IwM/XxuwrWE2kCV65/DH03cLOQCTw4YzhMAwTI2ODG99qBE8XBqwFhXPFsBGlDb2nZuobH TGH5IQ6qax5FxQ/kSJgalIV+ZRj2STHtqtOUXSxvFGeqD4wgcpiy1w8NBoUCycT0qNONRKpQqWQOt 81Reg1SBaLZ43atEmPAr/MxHMMSTbU3FvbO53iCB/ntD6YkcQVgoR3eaJx+YwfT2Fm63gG/27DkIX paP9rF3Yi1DwbTRiBkL/ghIe38lZGuUhBK2A5hY6F0T3QeLF3/i/X6elbOhD3x/P5PQGm/Spsy+JQ GSbaS9vQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZSeS-0000000EOXh-2Hoa; Fri, 04 Dec 2026 12:44:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 301E53006DD; Fri, 04 Dec 2026 13:44:34 +0100 (CET) Date: Fri, 4 Dec 2026 13:44:34 +0100 From: Peter Zijlstra To: Karl Mehltretter Cc: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, syzbot , Thomas Gleixner , Radu Rendec , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak Subject: Re: [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop() Message-ID: <20261204124434.GT2668804@noisy.programming.kicks-ass.net> References: <20261120171658.Cf9qIU-Y@linutronix.de> <20261125172018.GD2668564@noisy.programming.kicks-ass.net> <20261125193735.qrxCdHTx@linutronix.de> <20261126104049.GC49833@noisy.programming.kicks-ass.net> <20261128172430.69629-1-kmehltretter@gmail.com> <20261202144240.GG2668564@noisy.programming.kicks-ass.net> <20261203130519.GC677025@noisy.programming.kicks-ass.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Dec 04, 2026 at 02:44:55AM +0100, Karl Mehltretter wrote: > 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. Ooh, you created a TLA+ model for this? Valentin was looking to update his old one. Can you share? Christian is keeping a git tree: https://github.com/brauner/linux-formal with various validation bits in; we should get this there. > 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. *groan* quite so. Although I had to draw me a picture while working through this. CPU-A CPU-B CPU-C CPU-D

sched_cpu_deactivate() synchronize_rcu()

stopper> sched_non_preferred_cpu_push_stop() lock (p->pi_lock) sched_balance_rq(A) detach_tasks() attach_tasks() // p -> D <-> p> migrate_disable() cpu = select_fallback_rq(); // B migrate_enable(); <<- p> sched_balance_rq(D) detach_tasks() attach_tasks() // p -> C sched_cpu_wait_empty() stop_machine() active_balance() <-> stopper> __active_load_balance_cpu_stop() // p -> A rq_lock(); move_queue_task(rq, &rf, p, B); rq_unlock() sched_cpu_dying() WARN!! > 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. You mean something like so, right? --- kernel/sched/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 514c4b529024..22f61b76b70e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8452,9 +8452,8 @@ static int __balance_push_cpu_stop(void *arg) */ context_unsafe_alias(rq); - cpu = select_fallback_rq(rq->cpu, p); - rq_lock(rq, &rf); + cpu = __select_fallback_rq(rq->cpu, p); update_rq_clock(rq); if (task_rq(p) == rq && task_on_rq_queued(p)) rq = move_queued_task(rq, &rf, p, cpu); @@ -11361,9 +11360,9 @@ static int sched_non_preferred_cpu_push_stop(void *arg) * 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); + cpu = __select_fallback_rq(rq->cpu, p); rq->npc_push_work_pending = false; update_rq_clock(rq);