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 AD8433F822A for ; Wed, 19 Aug 2026 07:58:50 +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=1787126334; cv=none; b=a4aUMcrNjQMeFlkFU9bJ1+7qNQ33kC7gs2VHThJTDXZbZ+gOo7A3s8k7pFyPp5RJR6XeN3q7kgp36TElU0QWjqgViUZlAW3aGImx9K4PCTfKzb/WqOw1yO2eCgUdaapoN7CWQuqC5rX1hDX9w+3K7GBykZa4I3L296tJL7n0Yx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787126334; c=relaxed/simple; bh=1INv/LuuBudiEHJRqomAGXmKQYCAqlfY6HbcsSKy44s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=riIJB/ULypLGTSMJQcTzpZqu6zzqArZIl0YAHI4SCcljYoY+e2WIvqmZxH342ajhaQlzq5F8A3UnKfa7a8offoz1XmvZyeKIhqQWbBWXF31GD3y8tjbRUq204AO0KL0SerqU5qTWUx7b2x1QpP4nSxUH1/9lJHWzTDpYo7hWCgQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=h8m+Mkuv; 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=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.b="h8m+Mkuv" 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=fc3DUG96eGKHlIADuJzGT1Zvqks8JiDMpxf6ucC30Gs=; b=h8m+Mkuvbj+/S/tCOPpg0H45Bh mhumO7LqWHxAl3QqjGMRnaYCwXZoh76SgbQL4FHdSKcVxyu9p9lc4bT0c1fl875XYeaDpOimeqHh2 UQJhjvT5zqb53Tnofvr0pFYkrfcoRQyEdojS/ZeRtzcBnQWyBUiZYup2nj3h8qcRmRWt5p6SMNmn5 y8yFNiwUIxm6Yv2+qqLHRsrY/smCo/6JmMFIsQCXqqS70mmi6akfUBFueTZliwUcVu1T/wMN6hg67 y9aQ2p4o7aktFU3YjkXyVUvLOSMdg4HBfTDmL81pWKltiBWXbDxTctGa43zEDM1P8uHMN7UrX5Y2a I0TdqfJw==; 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 1wwbBv-0000000DKL2-0Wxg; Wed, 19 Aug 2026 07:58:31 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8705830030F; Wed, 19 Aug 2026 09:58:30 +0200 (CEST) Date: Wed, 19 Aug 2026 09:58:30 +0200 From: Peter Zijlstra To: Aaron Lu Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, tj@kernel.org, williams@redhat.com, jkacur@redhat.com Subject: Re: [PATCH 0/2] sched: Remove sched_class::balance() Message-ID: <20260819075830.GF1246887@noisy.programming.kicks-ass.net> References: <20260624121327.190063948@infradead.org> <20260702114919.GA186418@bytedance.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: <20260702114919.GA186418@bytedance.com> On Thu, Jul 02, 2026 at 07:49:19PM +0800, Aaron Lu wrote: > Assume cpuX and cpuY are siblings, it appears the following happened: > > cpuX cpuY > > pick_next_task() > goto restart_multi > > rqX->core_pick = pick_task(rqX) > > pick_task(rqY) > pick_task_fair(rqY) > sched_balance_newidle(rqY) > raw_spin_rq_unlock(rqY) // drops core lock > > pick_next_task() > goto restart_multi > rqY->core_pick = pick_task(rqY) > rqX->core_pick = pick_task(rqX) > > if (rqX->curr == rqX->core_pick) > rqX->core_pick = NULL > > UNLOCK rq_lockp(rqY) > > raw_spin_rq_lock(rqY) > > rqY->core_pick = pick_task(rqY) > > p = rqX->core_pick // NULL > cookie_equals(p, cookie) // NULL deref Well, damn :/ That's a nice race. So while we did a lock-break, it does not trigger RETRY_TASK and continues. The 'easy' fix is taking a local copy of core_task_seq when we increase it for the pick, and double checking that is still valid at the end and then restarting if not. Except that is susceptible to live-locks. It doesn't have forward progress guarantees. For that we need to limit the amount of lock-breaks/newidle invocations. Bah, let me go poke at this for a bit.