From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E88C215A85A for ; Tue, 19 May 2026 10:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779186774; cv=none; b=JBnrwb1umQByHUFyygtgyJnT8qi6GNWAjiG+Og7dCzgeEiw0s7KsHHoNGy5P2e83KrdPFoDzs40gWEc0uPJSuR0zRcYm06XFrChljpA3dGUHrC0FkivI/LgNK02TieOL2YlEgPusI7CoHgesaZ02xrlM+NqQRj4xN3uCnkKmTFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779186774; c=relaxed/simple; bh=fAcZYTpjJIrpGhC0NObosx0gL3D8njgXuVg7FHb4emM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WXKpCV+7qYBXzUfxfn2TXrY+McJCoMetnc0LejFaUp/DIx2ajeUrt2e04YfUrv917E5r0AQeDrVycZjKP9sfBWKIqWzu1P3HGs2ubFbOZI8Gnq3YqQRYIL6nAy0oEe1+ucaA91bRTtTkPTMEH/GtiCisufcZN9fmkX21ZFg766s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=uJ9wA4yh; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="uJ9wA4yh" 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=eRrRlwu8mGUczYRJj86nwaCWkZtCxKAE7Pd3ZIy/WTw=; b=uJ9wA4yhSOMFdRmKDWnwuqqDjX wuC+LvcuxaUdGo0T2KiKIF0SMrAik2ZVrH5urLN7ddy27ttJQWZKcqGMTJs9bp5jcZI2Fr5hBkNNC 26zlyZCTuQZSRkExS2pXYyoMpCsJBhIt1m5uj09FNR5Ml460WHYj76zWv/wcsCElHz9mvbaSb9exG aMtlZ9f/uavQtviL1MWoby1HTeCSqu0lSD11Z88w6K+zW/RU9c95UYeWZS8ewC4EfDpZvPF/cCLvy 1KehW8WYmMT+cK1V7h5UCDwh2NCcJh2E6QuQziCj/drrxH4E7zQiek75c4sBExopC+DE22A4jY/QZ Yww/o2/Q==; 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.99.1 #2 (Red Hat Linux)) id 1wPHke-00000005nZh-2Qbb; Tue, 19 May 2026 10:32:40 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 0A53A300182; Tue, 19 May 2026 12:32:39 +0200 (CEST) Date: Tue, 19 May 2026 12:32:38 +0200 From: Peter Zijlstra To: John Stultz Cc: LKML , Joel Fernandes , Qais Yousef , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , Daniel Lezcano , Suleiman Souhlal , kuyo chang , hupu , kernel-team@android.com Subject: Re: [PATCH v29 1/9] sched: Rework pick_next_task() and prev_balance() to avoid stale prev references Message-ID: <20260519103238.GA2934902@noisy.programming.kicks-ass.net> References: <20260512025635.2840817-1-jstultz@google.com> <20260512025635.2840817-2-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260512025635.2840817-2-jstultz@google.com> On Tue, May 12, 2026 at 02:56:11AM +0000, John Stultz wrote: > Historically, the prev value from __schedule() was the rq->curr. > This prev value is passed down through numerous functions, and > used in the class scheduler implementations. The fact that > prev was on_cpu until the end of __schedule(), meant it was > stable across the rq lock drops that the class->pick_next_task() > and ->balance() implementations often do. > > However, with proxy-exec, the prev passed to functions called > by __schedule() is rq->donor, which may not be the same as > rq->curr and may not be on_cpu, this makes the prev value > potentially unstable across rq lock drops. > > A recently found issue with proxy-exec, is when we begin doing > return migration from try_to_wake_up(), its possible we may be > waking up the rq->donor. When we do this, we proxy_resched_idle() > to put_prev_set_next() setting the rq->donor to rq->idle, allowing > the rq->donor to be return migrated and allowed to run. > > This however runs into trouble, as on another cpu we might be in > the middle of calling __schedule(). Conceptually the rq lock is > held for the majority of the time, but in calling pick_next_task() > its possible the class->pick_next_task() handler or the > ->balance() call may briefly drop the rq lock. This opens a > window for try_to_wake_up() to wake and return migrate the > rq->donor before the class logic reacquires the rq lock. > > Unfortunately pick_next_task() and prev_balance() pass in a prev > argument, to which we pass rq->donor. However this prev value can > now become stale and incorrect across a rq lock drop. > > So, to correct this, rework the pick_next_task() and > prev_balance() calls so that they do not take a "prev" argument. > > Also rework the class ->pick_next_task() and ->balance() > implementations to drop the prev argument, and in the cases > where it was used, and have the class functions reference > rq->donor directly, and not save the value across rq lock drops > so that we don't end up with a stale references. > > Signed-off-by: John Stultz Right, so I think I'll take patches 1,2,3,8,9 from the flat series and munge this on top. That gets rid of all that pick_next_task() nonsense and simplifies things a little.