From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 53E5739934B for ; Wed, 20 May 2026 09:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779270252; cv=none; b=UvrwYI2ICCGxuzKJ9x3GnfhG/TeM78XbV4LoZPWf+4dLLel20JpJQ5dubjmrf6QVQOr8fBocSlTjdU106cSjrnOf+Tg/WxI76LOk8qxN3erANRuMg7gZlFkpyAEf2OjqNSQNEjukzFS2lqq6qhDPCM569m8SljG9GzV4kGuUGvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779270252; c=relaxed/simple; bh=iqL9e3RW3p8VYG+9sYsde4zch8UeDGNnQxMCQBcsqCc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ERtNpP32iDFsMlM2jIazAahaWCjmz07uTsTLbH4dmy0/4iQT3vRlpnN6Kew7XLPfPRteszqDFYNUix9ut1U6e5prLkcNlJLDBb1zZaxHfSY7SG//rSkl10+UsS8mBx00Jr9PgTB5MLk4T0EdFq8lP9xRyXAmx0uRkNVDMKRDzP0= 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=A0nmz3ph; arc=none smtp.client-ip=90.155.92.199 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="A0nmz3ph" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=FeTNYdf8MvhIaoI4OV3S7sL2Fv4ontNnY7Zi40kwUwU=; b=A0nmz3phtGkZD8GPngtd6GgWjb RtW4TutgtA/iwO5qePIdOGahjipyIa2mGXPUrdymus35YrfCfJO09GR5CrfEirpw69LUZATsgY5eD wtwqrtRcvjujCx9oeP1dGrzRkaLHU+rcuIfwsagcp2BNvXOW0HzWJTB0HwzDQKHIN16LtnhiR2eeD 274SIy6l4jTGjS8dPwkqiAMLsLvm1/ZxDvZySoGczkwGMguq9XKB2CBbauNUD+25zO47ycby9IOVH B4GFl111ki12ucC6WR/H9mrvTm4eH7rMUHQOm3ddvmVgOb9DEd8giZOzc5WMP+D6Mf63UoeHyKjWm /NLYiv6Q==; Received: from 2001-1c00-8d85-4b00-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:4b00:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPdSw-0000000GOen-0egX; Wed, 20 May 2026 09:43:51 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 16C353001D0; Wed, 20 May 2026 11:43:49 +0200 (CEST) Date: Wed, 20 May 2026 11:43:49 +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: <20260520094349.GC3067227@noisy.programming.kicks-ass.net> References: <20260512025635.2840817-1-jstultz@google.com> <20260512025635.2840817-2-jstultz@google.com> <20260519103238.GA2934902@noisy.programming.kicks-ass.net> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, May 19, 2026 at 07:45:21PM -0700, John Stultz wrote: > On Tue, May 19, 2026 at 3:32 AM Peter Zijlstra wrote: > > 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. > > Sounds good to me! Let me know when you have a branch posted that I > should use as a base for any further iterations on the rest of the > proxy chagnes I submitted. I have some random bits in queue:sched/proxy, this is more a work-in-progress branch and will be rebased. It doesn't (yet) include the full series you posted simply because I didn't get around to looking at the remaining few patches yet. Aside from doing that blocked_donor review, I was also side-tracked by looking at doing some further cleanups wrt is_blocked.