From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=90.155.50.34 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796222570; b=5AZ8V4lWj3nBuG9bcbflfgc786RSBuhnT1R5xdljzGAoHSMwhMcbPYAhJOiRcffiiWrJ o0n1OGWkLMB8YMDlRwWxXXq4vcapd1dIGt6WnUJyTskSqqL21GUO3U6kaHhHAd26+QA94 SUOMaQHlrEVVWF0075CP73KfhSGPVeC7DZapcE70S1bCfZnetRFCtKFBNQW63hGj93AYk 9Kz/JXUZXB4rTgW4rZAFQTDSM2wSrCc9emvml282/ZKtafmolD1QtH4YnpKOepLWojRAU 6U+WLvyV3IRFN6aM9pEj/HtnKs4jBp1isO0LVjCdnwLjs3QRPE2uX3yARVw1WByMEwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796222570; 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=O+kmED8eHr1ryZhbleSVYahBw/tsOUEnNVQ0LkpT/O4=; b=SEsHhpjpjF2TvFm0yIpbLQ9Tz94Dxzx7Ch21PZlivHIfzv1Mn5F/ioNioLJJR3kEm+Ld JUGAG38e8gGbz1v6bIQ72na/Wc3nh4YIINH605rGT7QjL8Gv3FGM/qlGqkunNWxB9oMC7 3xwX3Mh2mF3EqRwVT9fAToDtm8NkRogHKK+1zVCoOkB7cyOJ2A6Nh1moNApcKgJKw5eej LYiLhAd665thqlG+EqpbEve/9w2PBkgoIlaSEe/VYzqgde5T8389N5HMP3BDydLXj+sYP 3fSECDwHshN5mOwjJKHf9QT4wcr/1PGEDSEFO5DBQ98W8WQTqnDVOyZVBRTLOMdxNgQ== 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=casper.20170209 header.b=ptq+hoAy; arc=none smtp.remote-ip=90.155.50.34 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 D7EBA606A31A for ; Wed, 2 Dec 2026 14:42:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D7EBA606A31A 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=casper.20170209 header.b=ptq+hoAy DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=O+kmED8eHr1ryZhbleSVYahBw/tsOUEnNVQ0LkpT/O4=; b=ptq+hoAymNC99zBPShzecb7RvZ 9oxAmh8z3S0iSax1X3DSwmjE0AcFqKooptrYll+JEb9VhzGakKJBbpMIVuEFjVv3TnqWICKdZpaTH U7+cqhCT+gp18Tv4azC3/kQuGdZZ0cnRjIBdXXkUpZuPBJduZNc17/lfZ8WsPigncYGe8ZeBH0wPl G6pULmkGUwrByaJdNNoVsf+As+Pp6P6SEIwiePLUyz3RZwRJpcmgso6XCUhbfoaN7NfllN+cDe0RZ GelIkV1lBXFH2YZ7rsqxkUzeKyZucrByJugpAI6+9xA3Dr84d5aJw5+KmW09B73pE5vUt9iCBU3qD 5ChOUCRA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYlXe-00000000Hl6-0GtV; Wed, 02 Dec 2026 14:42:42 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 085D330045A; Wed, 02 Dec 2026 15:42:41 +0100 (CET) Date: Wed, 2 Dec 2026 15:42:40 +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: <20261202144240.GG2668564@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> 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: <20261128172430.69629-1-kmehltretter@gmail.com> On Sat, Nov 28, 2026 at 06:24:30PM +0100, Karl Mehltretter wrote: > On Thu, 26 Nov 2026 11:40:49 +0100, Peter Zijlstra wrote: > > if (task_on_rq_queued(p)) { > > + int cpu = arg->dest_cpu; > > + > > update_rq_clock(rq); > > - rq = __migrate_task(rq, &rf, p, arg->dest_cpu); > > + if (!is_cpu_allowed(p, cpu)) > > + cpu = select_fallback_rq(rq->cpu, p); > > + > > + rq = move_queued_task(rq, &rf, p, cpu); > > This deadlocks. > > select_fallback_rq() can end up in set_cpus_allowed_force(), which takes > rq->lock again. > > That's similar issue as af13e5e437dc ("sched: Fix the do_set_cpus_allowed() > locking fix"). > > With your diff on tip/sched/core, IRQ/user affinity changes racing with CPU > hotplug hang on both RT and !RT (arm64 KVM): > > WARNING: possible recursive locking detected > migration/0/21 is trying to acquire lock: > ffff00003fd7e620 (&rq->__lock){-...}-{2:2}, at: ___task_rq_lock+0x68/0x140 > but task is already holding lock: > ffff00003fd7e620 (&rq->__lock){-...}-{2:2}, at: migration_cpu_stop+0xac/0x370 > ___task_rq_lock+0x68/0x140 > set_cpus_allowed_force+0x54/0x100 > select_fallback_rq+0xf4/0x180 > migration_cpu_stop+0x35c/0x370 > > Dropping rq->lock around select_fallback_rq() and rechecking > task_rq(p) == rq and task_on_rq_queued(p) before updating the clock > gets the test through on both RT and !RT. Durr. Dropping rq lock here makes my head hurt. Perhaps I'll try and make __select_fallback_rq() or somesuch. I'll have a poke. > > if (task_rq(p) == rq && task_on_rq_queued(p)) > > - rq = __migrate_task(rq, &rf, p, cpu); > > + rq = move_queued_task(rq, &rf, p, cpu); > [...] > > - struct rq *dest_rq = __migrate_task(rq, &rf, p, cpu); > > + struct rq *dest_rq = move_queued_task(rq, &rf, p, cpu); > > Don't you still need the is_cpu_allowed() check here? Both push stoppers > do select_fallback_rq() before taking rq->lock. All hold p->pi_lock, and hence IRQs and preemption are disabled, the affinity mask it locked and hotplug will wait for an RCU grace period due to deactivate_cpu or somesuch.