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 595E218FC7B for ; Mon, 27 Jan 2025 22:41:32 +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=1738017692; cv=none; b=sJoG72roudrBlsjAjb8AcSDLANHMHqlpyj+3sqjTpX0WU/jM9HoCwjfG37rEZi5ZSXYuO8fd+bzmAgUkvJR2NCxTcourwJTMsYKW1KiYQH62nqcAMIkrF9GB3eIBmcuYVRykWN0JiXTZNJnByUw+8UI09kslWPWGrr0I7qFy9Pc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738017692; c=relaxed/simple; bh=lxTC2aoyX4rrL9oDC0DMPZjznSkuHSud83FmITAm61E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XBYGoe1RKn31LN10I55TkpfvPWG+G/l0kIZADCn8IEUynS4t46UE46qfi6ALgtIyzrNenLjXJVzw2owxW+KhOQ+twRlsnCyOvvOPaCth2agjh8HGNO1Szuw8gpbmsXdTCpK+PeFUifv5u8rAY2zVPRFc904xZiRBfWnTuqsb8Ro= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iEGgrH9v; 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="iEGgrH9v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEE36C4CED2; Mon, 27 Jan 2025 22:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738017691; bh=lxTC2aoyX4rrL9oDC0DMPZjznSkuHSud83FmITAm61E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iEGgrH9vylIshQN5oxtQqSK7T/K01SsZjtFngFpsndiQEt90k48x+zB/YJkUjlEcI EXrNt7yHmfCtfcCm9u/3tb8j3F9hKJiG3LqkQGiHUaC5Zp7aqOEWcdy9kSBcrAZEOn 18R+90PfJYpzhi8L0gxnsXulWOwLrDUFeNiMCbjHIziqC3xj7/VyepZtnsBgzu/2mu /7pBfctV+bUpGpmNP4zC3WL1BaCyQA4Uc+pMBrnS6qtkdXrjTa1/drsAF0376ThxPl 0ATzcm32tYH6wd6WlRW6BnHlU7LlRaq1hgEuvtxmbwrbErbdL2P8Q8BCZLaggIRfq/ jwS9biK8itirA== Date: Mon, 27 Jan 2025 12:41:30 -1000 From: Tejun Heo To: Andrea Righi Cc: David Vernet , Changwoo Min , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5] sched_ext: Fix lock imbalance in dispatch_to_local_dsq() Message-ID: References: <20250127220616.620097-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: <20250127220616.620097-1-arighi@nvidia.com> On Mon, Jan 27, 2025 at 11:06:16PM +0100, Andrea Righi wrote: > While performing the rq locking dance in dispatch_to_local_dsq(), we may > trigger the following lock imbalance condition, in particular when > multiple tasks are rapidly changing CPU affinity (i.e., running a > `stress-ng --race-sched 0`): > > [ 13.413579] ===================================== > [ 13.413660] WARNING: bad unlock balance detected! > [ 13.413729] 6.13.0-virtme #15 Not tainted > [ 13.413792] ------------------------------------- > [ 13.413859] kworker/1:1/80 is trying to release lock (&rq->__lock) at: > [ 13.413954] [] dispatch_to_local_dsq+0x108/0x1a0 > [ 13.414111] but there are no more locks to release! > [ 13.414176] > [ 13.414176] other info that might help us debug this: > [ 13.414258] 1 lock held by kworker/1:1/80: > [ 13.414318] #0: ffff8b66feb41698 (&rq->__lock){-.-.}-{2:2}, at: raw_spin_rq_lock_nested+0x20/0x90 > [ 13.414612] > [ 13.414612] stack backtrace: > [ 13.415255] CPU: 1 UID: 0 PID: 80 Comm: kworker/1:1 Not tainted 6.13.0-virtme #15 > [ 13.415505] Workqueue: 0x0 (events) > [ 13.415567] Sched_ext: dsp_local_on (enabled+all), task: runnable_at=-2ms > [ 13.415570] Call Trace: > [ 13.415700] > [ 13.415744] dump_stack_lvl+0x78/0xe0 > [ 13.415806] ? dispatch_to_local_dsq+0x108/0x1a0 > [ 13.415884] print_unlock_imbalance_bug+0x11b/0x130 > [ 13.415965] ? dispatch_to_local_dsq+0x108/0x1a0 > [ 13.416226] lock_release+0x231/0x2c0 > [ 13.416326] _raw_spin_unlock+0x1b/0x40 > [ 13.416422] dispatch_to_local_dsq+0x108/0x1a0 > [ 13.416554] flush_dispatch_buf+0x199/0x1d0 > [ 13.416652] balance_one+0x194/0x370 > [ 13.416751] balance_scx+0x61/0x1e0 > [ 13.416848] prev_balance+0x43/0xb0 > [ 13.416947] __pick_next_task+0x6b/0x1b0 > [ 13.417052] __schedule+0x20d/0x1740 > > This happens because dispatch_to_local_dsq() is racing with > dispatch_dequeue() and, when the latter wins, we incorrectly assume that > the task has been moved to dst_rq. > > Fix by properly tracking the currently locked rq. > > Fixes: 4d3ca89bdd31 ("sched_ext: Refactor consume_remote_task()") > Signed-off-by: Andrea Righi Applied to sched_ext/for-6.14-fixes. Thanks. -- tejun