From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796442676; b=Hg+GYo9rutXTo9pHltxxdKminyNM6kHDs9gFLp0obq5ml0a0D9UG2QM7Rblwh7gxVUSd /ncqiaWhMBldstvQ8qs37c284mPH2XmLxQaCwHNq5EDcGSaxBu3Ng8X80jkzY9EauoyeW 5mddyVMgZ09iGBIqz5+sFcTfrE7TvXsnvhArCfEFi25H/YAXmAjqTEWoitsudZciBzlG6 CNfgfg52k+XNT1PcAGA3NaahtbjhUKTTmE82mCGZcrpjQUQKIRG8m2vtrFWsEBeztpibi b3LB6F0k/3hc4ZQ1uywtoE2zrLxIVpaIeTwgrLhtVRt8yBTW1KCJOcjPaAS32ByYPbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796442676; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=r0FhIlEfM6TcI5fZa29Rd7pXN3JbEXkKiDTt1/QoRCU=; b=q368kJ/ToLxmTJd7w9zRbk8YfcctSnPGEcU8r1BhzGnUNF+zUU6KsF4dbCBW4HeBcnfX Qt6rBqOXYOxhh9KU0UXudXoIs+ApKhrf2Z+sLLZptWI6nQv0vrh8GqTku/idfPsj27KNk UkHN8tvK2a3vR6Bs8boaHiXeNq322X2t9BtULy3mVglk/9HXZUUbyzR4gs8GzVQyEhjpx w1KdALI/U/tqgHa1k995ERJ0rtqO5mMnw4kvsoX9TFIG3aP+mhiR0lZAY16WF9B0cbG+l 9xZx1kSlfEvcY523FU8DhMCXZsnpSM1/E6pFKcNg1UcJD1VarDWsqVgonQ0olgIriUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xWlcnWC1; arc=none smtp.remote-ip=209.85.221.50 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C54F606A322 for ; Sat, 5 Dec 2026 03:51:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1C54F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xWlcnWC1 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-4c3f0acc1easo1073067f8f.0 for ; Fri, 04 Dec 2026 19:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796442674; x=1797047474; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=r0FhIlEfM6TcI5fZa29Rd7pXN3JbEXkKiDTt1/QoRCU=; b=xWlcnWC1DZHrCbCRurwLC4LsBNGGL+GMXIZTfQPT/Q69n80zgb1stYvqWbBZgw9dLB iIXl6ysviOxsODt2cBJUzivHmrZCg2DSlJwlDQ9T2JjkLqRRmHiALFLHsLein5ZsG03s s9tUnNUjm17TKVnTKRkrSQ2hZNTm46yyPlZG0U4GYvccOcXC/TCEzVJF8DRQo+RkN+jZ +NhjqvEtNnD6y8OrXdaBBs2Dj/p9YYebxQNCelIkyJRowAHSuduN8oyL/dqiyXwBaYGF FDQyNzOxkgnt7Ao5xtsANolElequ9FTwZF0myAhI4bAh4tZ5yxotreEfGV7EUoQM61EN 58Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796442674; x=1797047474; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=r0FhIlEfM6TcI5fZa29Rd7pXN3JbEXkKiDTt1/QoRCU=; b=hFBadZMePqrjDXQZYJc9eXsQYv7X+9IIyr9v8W6zV10LtW32IVmUXOVkni/VA+R9a6 NSEmNAVlmVqmd/06lx/+tfhYpsOXjHn1cvrwZ8RAzjVDrCAuRORjyvhAorhXNxQv20nK mxeMA/gPF9u01oc2wn4BaSMfVtnGNbVJ3EpYNiEfizy97G199pWf4xXEyBZqabpdcBfr YgYG7Jacs2B23sIKBz9Z/tg/AuzRCI7w1x4chmSecIUOhsQzKmHNVI1Tdz+qeOiG7b+1 gElp7j8NNEsK9ZlSJAxxD6ntTSAFKFhIckXcAX51yCISoujMS+oDxbOGAaNOxKZ2T7yG BR2Q== X-Forwarded-Encrypted: i=1; AL+hErE0soNwWKGhQVDRfBNl7PfCapkjZZNPop16mtnJhPhYWyHgbWEWJXppRI5dQqNt8tQnqO3AI001fEYn3cs=@vger.kernel.org X-Gm-Message-State: AB4q+uHXMuDSh1Ze3h4ZnHSFELMGr6fuyWTvRbbK345io1lFTJTifxnv rqGxuUZD3liFio7shrnL5qaOdncRTielnizgvPuPYQpzubUTcoabTqfU X-Gm-Gg: AZFdTZc4i19O22Qulu303fGjHdP38j8FpXauSlVaedRHS8a1/1Tz/kT7iszKmnJ4IQ+ WaVsQRr3ERLmaGENibArH1QqoU/cXKGPwZDz1+00XTs05DiZpkpMg8rBde1cjkN0DvDSzbuT2tG 55TFZyjHcDlHHv8BrpekCSAxJW5SU6MN14ylHxDZjiOYcH2P0AS3L8Kcla7/OGn5auiOWZNhohg hkcgC9kMDRdmr7AYFT1F+FNG+bjvHcUsk0RUGZWOixK/znqJguSjBuVMhqFBAnnjf5IY6GH9VVB NmRUweXahO0ElJlkvd0VgZZymgN1OK0PVRLEmzsOK3OKbi/MwcXdHY19hdHWrO5a1iLzWZzcfpK E4NHgy75cVuQ77R6kPBPmNj8Hm7zfFXuznZI1zSghdblgpEd85bhubbneoPbXbJaVD5C8PYQpK4 IBUhbWzSZ38bknUqUW1B0fBp1CzfjxVxcOwustQXYdcb1fLjHPy7klSWWijJuNS00evd/Vn7tpl bNJnbOFbYcoyErwZRCn5mv9qiULcqX7CAQ+pFkkR3GmVqdlWYCxzPk4h69eQIgiRYNumnm8tONO uuDbvR+9Q82eOvFyrmPcIUDs1aRMcfz/tWp8+l0OEe3uUKWeXdXNbeF7apAVVFv9K17aYTuxYva ukP9NCDNXN8rgKzZfT2MoWzUmM4kOCo22sPtWSCSM4gapU1cqC48XSejS4dhjsyp7mz7H/BzyNg weqMbmVkt5Gw== X-Received: by 2002:a05:6000:4518:b0:4ce:d427:e223 with SMTP id ffacd0b85a97d-4cf44614ea1mr11807607f8f.2.1796442674183; Fri, 04 Dec 2026 19:51:14 -0800 (PST) Received: from MacBook-Pro-von-Karl (dynamic-077-007-221-063.77.7.pool.telefonica.de. [77.7.221.63]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172e41d6asm8670697f8f.25.2026.12.04.19.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 19:51:12 -0800 (PST) Date: Sat, 5 Dec 2026 04:50:39 +0100 From: Karl Mehltretter To: Peter Zijlstra 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: 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> <20261204124434.GT2668804@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: <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

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);