From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CEB581CEADF for ; Fri, 24 Jan 2025 19:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737745720; cv=none; b=doUFslUc+UChIpukCIoVVJi3x4UZqIidcdb9RsQIHfRz7A0lPYUJe+3Su+zaW9pCyBpTI3urfBFi0qFCPYMyX4nVz5PPWPhF9+WkoJalKfvzZ52X7Sr0QhIG/j+YHg0s5rQQ8kqLQQIkK5LBYJqtzrTNt4MbnGs4LmSNHOBvJ0w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737745720; c=relaxed/simple; bh=NOyFfDhHXMu2ZDovnKtXxuZbPHLsKgbc4/6f0OXqapY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tWlT3dQdJ3Nx2Q73jX4G2bWLxzjR/3odbvVRDeWlMF1+kMy/fe200O+WOhVFVwExxPgcX0T8MDrYaszwqLYiuoyJVVYrk+5hk6HWUj/sk300KmNkXmUvWzCGWHFg+sOt7cb4Vj4GbAW4qz95nG+P8PDbSoensmNhbxIQQO7iHis= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lISoYrEG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lISoYrEG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20DB2C4CED2; Fri, 24 Jan 2025 19:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737745720; bh=NOyFfDhHXMu2ZDovnKtXxuZbPHLsKgbc4/6f0OXqapY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lISoYrEGs3KzyS2EItl+xskBjsrh6uYskBU1qxlxWPJX2r+ijpI4LWaVNbJR2hROG 1zmQoey+h0Foj8v6flzG+zoWns9TGCXlntBCcmkGF0PE89DrAWUuY7TiNSqMcbRx9Q GaG7kS7wpyZVYta8QohJ92gaXOC0rr/7Zzza6dD9zRetvVYWc2VF8l7UTXGd5gN7u9 l+EzaDSp7mMPhHHj8FKrGpqdjrR8KOy+o5h7xRoapSyg3WZUR9H29kNud2Bzyl3euo TH3OsrBjaMP3rVCin4Y92Q+kj3/JoVW0FFXFfHggnTK2E51vTXO6+C/ocWRpQplaIw MDE9WPpYiag+g== Date: Fri, 24 Jan 2025 09:08:39 -1000 From: Tejun Heo To: Andrea Righi Cc: David Vernet , Changwoo Min , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched_ext: Fix lock imbalance in dispatch_to_local_dsq() Message-ID: References: <20250124072425.47795-1-arighi@nvidia.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: <20250124072425.47795-1-arighi@nvidia.com> Hello, Andrea. Thanks for debugging this. On Fri, Jan 24, 2025 at 08:24:25AM +0100, Andrea Righi wrote: ... > Fix this by correctly assuming that task is still in src_rq in this > specific scenario. But I find this a bit misleading. It's more that we didn't do anything and thus didn't switch the held lock and the assumption that the unlock path makes is wrong. ... > + } else { > + /* > + * Otherwise, if dequeue wins the race, we no longer have > + * exclusive ownership of the task and we must keep it in > + * its original @src_dsq. > + */ > + dst_rq = src_rq; Both the code and explanation are confusing to me. This is working around the incorrect assumption the following block is making - that we'd be locking $dsq_rq when control reach that point. Can you instead add new variable $locked_rq which tracks which rq is currently locked and then use that in the unlock path? It starts with $rq and set to $src_rq when switching to that and then set to $dst_rq in the migration block. Then, the unlock path can test @rq against $locked_rq. scx_dsq_move() uses a similar approach for reference. Thanks. -- tejun