From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796348701; b=rwQ5YOtydl/eCxMr2P+RYSnKXP8/gpyQ6vDpdK2Qco1sDtZpbIWh1rHr6eD42FF1UlvA PRz3p2YQkQOGYlCNZI18Fnm5Qf7VIXZdY1pw7ce2kWxBnCLKTbdg/F9Uy9zNmvlBuNLb1 qxnFyHHwqMfHdszHhpPakRegHTHT5qUswAEzrQTD6kXrBfbcTfCAYrYxTtYoBjfXbBbOd WpFFyMS7xFHzSMVtFulv2IxwVkZr3y8mfO6AYfu5zLu6ILngAxuQyG9UK7gcdCbnDeLYf OdVqP3GOVjsyWinNIAJtJcNeolYQ7xdP5jN2D60OfOzOSkv00rzlaaNmsWCDGcV5+yg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796348701; 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=8R1vDacLRVbtZ8WXm0Ur/m+QJ/civ9AnGfwFHwzrCy8=; b=UQjQ8taA92VG/qeyOND4BC0mb/5QZlpXPO5wbyYIpXGGXS5R6lbdusIBY4wy4wNxkOnm 1ss7y3P5en8C7XYBOwLQBPKMzybie0EpSU2PYKVJ6JFvm2Sbj4surBPYK23b8u4pAC87W 2EblQUWz40N9MeBGNgTrt9QzWZuLwrkQos5JyXRRLvu1OVbdfo/nsDEkhknyQzeEm3z8q lk0CL3S5TKs+MQY9pH0QhcwWZnY/jFu5YHp+FzMS67E0IBMc/xgh06/hr1CV2v7Bv7VkY VZcflD6q9FtpfztF0pAeHV0HgBDSen57GwdFesyW0x6aNInvDngIhE6BZev8b36FlrQ== 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=vADIODTj; arc=none smtp.remote-ip=209.85.221.48 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 CEE2E606A322 for ; Fri, 4 Dec 2026 01:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CEE2E606A322 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=vADIODTj Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-4a42b34e930so341008f8f.2 for ; Thu, 03 Dec 2026 17:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796348699; x=1796953499; 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=8R1vDacLRVbtZ8WXm0Ur/m+QJ/civ9AnGfwFHwzrCy8=; b=vADIODTjdpyapfxuT8Y7IyDsewAQN2OYPVxDzkTH9FkVJ/6BDThqYFbY+MIAYknLUj PZoj2fS/KYZQiReCO+YvZVZ1VeqouM296SBTXzb6aK6gqVT3dTS4Qo30ysh9YUTo2XTB AM90YNTax9VjJ21qpwCqw2uS/e8+SZWj/GbhPWd/IwKGwuRnTZOctscb1MBRy6Xzs4vA w7+Zzl8DVr9VF8lPP0TZix9rwYZ7/iqWKQo+IhpC/MOvY+0+iwHR0JgtRb3f4iNNlrhb oqYptP8HM1xQM06mjfpf2HHEXv7b2Qvk4L489nj5DrP8iKfdKoqnYKCTRqJFvp+kUSEr ucwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796348699; x=1796953499; 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=8R1vDacLRVbtZ8WXm0Ur/m+QJ/civ9AnGfwFHwzrCy8=; b=MVScvOHKtT/UD84wXVhQFSYY6uHrYmBvcznaEgF/YNU0v89VeZJ/+3+jUtNx9hD4zc 1Tb/reQlNJM27g0+1oEUB3Txdj+2hRg4OGDApSej9frZA5NUQezfG9c7gdc4oSNhwRBN ljzD4w/eYWmzStg6Azkp0zRWBoEIr0ip4jbACX5RAMwuh5wlPFndJS8fc38q3RpEFiAD A1hBeBx30IBbKmtgY0g9DOu1kIi2Qv4+Mr1MboMVzatzBShp0Ay1QPq1VWyAKc2XotbU GlS6cMMHv9XxH/MhTv4QPN0KRnlvp4f00C91r5JuwVAbo38NNlBtMbRmqPkQ72Y+B4Dr o5zQ== X-Forwarded-Encrypted: i=1; AL+hErGe2/PT7tVuDPejRPP+IWpRW1R0KE3qclITW1zaL57/WcDbLQWBDmnOEh8D8UhvE7krVopFIVcISioXX/A=@vger.kernel.org X-Gm-Message-State: APuU4Z9egFELT1XfTYisMWkyGq1lBjxOzKYfFkKCoVWZjVa8qp7nX5pc Go8AWXdUVhXaMP+OZ816rFR4rtYhwAui7eOVBZiOE6chf7IZEUA70auI X-Gm-Gg: AZFdTZdWXUeviPhdY9MF8gpXD8YUlgPbbr4wrWeIKEeL8gUUBQxchN1/1moi0iLki7z 6a4eg0bzk6NJ2V+h8zsLcZEedKI7Vitdi7UcMYTunfYscBHV+vOpd7aHYFIHraiYjyhdHLJc2OW xH6So10elgxDAJvUIY8HqL2lqT6AjotNpw/AjrhJeImxk0o4K+9WyfzdDI4qxypRYWNFo0PuT/p rZ+YeyDkqP9HisCeSM4kVumwHcUzz/I2zpW1b7yFZiCVagFsayu8/GdIbtWJ6TGGvetoUCZFAQW UocxDNbOJ0DS15wu3FPpgSygKEKRzd5XxoF/+TLn+M66XXB1lRPcKPwZMQdqWYrvezAUlFtym6d Y4ieAmLams/MX7EDV9S64wJhGnv3paHGTNxQ+gUVdcsWSj9uzwOdmHHd3zUpIaRwn7oNSQtpiuA UdEjBz8n6zYX2XSAOUw5YPglC8UWPYIJLb9Esp1lawMD0pAphpSoBJZikj/q2rTdE9u93UhERTb 5SowOdAfrqJW9ClcI/RZIvH1bVuJjMNi+LhBMj7ERNf2oL/Wc9ppp+GGJySB4uS34tqIpIpCeeV HlLj0KPCVCY0AXNbxILn6N40DM4sAt8jQEsPmIYDSMPQNjZxDmR2fodLzyu7+vMl68z768HK6ZG V+m+jG5vnzYPgnVp0f81qmy8MXtIPyOu7owjUM4mBkGv1pspCMbJnc3V7KXQkGrDucyBVn7ceVu lRehhEpY/92W6OoTPP/qDd4SnNoeI+DTJzLRAn82SBO7nw1yyOMA== X-Received: by 2002:a05:600c:c4a2:b0:4a1:e672:5721 with SMTP id 5b1f17b1804b1-4bbeb894516mr7437365e9.13.1796348699007; Thu, 03 Dec 2026 17:44:59 -0800 (PST) Received: from unknown748F3CBA5068 (dynamic-2a02-3100-b31b-9101-e858-d3d5-3318-6613.310.pool.telefonica.de. [2a02:3100:b31b:9101:e858:d3d5:3318:6613]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17435e021sm2283889f8f.50.2026.12.03.17.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 17:44:57 -0800 (PST) Date: Fri, 4 Dec 2026 02:44:55 +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> 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: <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