From nobody Sun Feb 8 13:47:21 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (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 8A02F1FA8F7 for ; Wed, 8 Jan 2025 15:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736348912; cv=none; b=RIXaxugsjmJnJkm39yvMWyfwzzs1s4repSE3SRy/Ai06wbjA5B52ZXQN138qofCIyhcPSnAlTUashqMCcocUaKU2MF3XpRKOLhdH4rTLWo7nlSWMGxrwnEHZYlHZe0NaxtWK34WjjSoW+adRJXLehigNSfafOE4vCKM6Ju/+JkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736348912; c=relaxed/simple; bh=/jY4drHZJYKdLWsLubTAUiWt6vLEpyIvGuvCVulRsLM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FnaY9sAgpOMJIhrL+Sr9Pkizaz8mhzwRw6eTjHOpKLijrgXbsxfOZpbsRXBZ9udaZgWZV/LVPZE89kDgPw5gSJ08uTpEEE8VYCVB/qOF+HgCkYFMx3b7RPQmNuDW/wm6CEoWcRCA3nEFLCPPCcBKFAfZcHPdVQw4jB15X6xv4EU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=ljE6mxEG; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="ljE6mxEG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SAVTMeDsZ6ZbgUuFDAnzfgLe6Ovrq8z+s9lxwWwszwY=; b=ljE6mxEGlGIRd8AO1+MA7KrDkh jdIODxsF+GMlg80f3cYezNq2TcXhrVuTqOpbGnr0N0FtZJWWKfywU5CoooeeUG5x4/RuvXjYgKPWD y2h7FkFFjCP/CHN1P1PLdouyK7T2H8pcBjbvGsP102TtOBSlXl400bsFd85pBUT8tXcnAHE3kefcQ LEEzE8APh3IYu43U+Yt55FaQZKfIfNxZxfJx35azCVoyl1GVTMGc6+moE9kdAAeUih5OYXmFvKyXi E2wte+uIPxLkQB4/v4Xfv78v5AEbfkwOZIsaw4nrV7cng2ko5p4fcr7tREVnpImDdyaTZkLG3cGge T15+U9wg==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1tVXfL-00DAxB-DS; Wed, 08 Jan 2025 16:08:16 +0100 From: Changwoo Min To: tj@kernel.org, void@manifault.com, arighi@nvidia.com Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v3] sched_ext: Replace rq_lock() to raw_spin_rq_lock() in scx_ops_bypass() Date: Thu, 9 Jan 2025 00:08:06 +0900 Message-ID: <20250108150806.101555-1-changwoo@igalia.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" scx_ops_bypass() iterates all CPUs to re-enqueue all the scx tasks. For each CPU, it acquires a lock using rq_lock() regardless of whether a CPU is offline or the CPU is currently running a task in a higher scheduler class (e.g., deadline). The rq_lock() is supposed to be used for online CPUs, and the use of rq_lock() may trigger an unnecessary warning in rq_pin_lock(). Therefore, replace rq_lock() to raw_spin_rq_lock() in scx_ops_bypass(). Without this change, we observe the following warning: =3D=3D=3D=3D=3D START =3D=3D=3D=3D=3D [ 6.615205] rq->balance_callback && rq->balance_callback !=3D &balance_p= ush_callback [ 6.615208] WARNING: CPU: 2 PID: 0 at kernel/sched/sched.h:1730 __schedu= le+0x1130/0x1c90 =3D=3D=3D=3D=3D END =3D=3D=3D=3D=3D Fixes: 0e7ffff1b811 ("scx: Fix raciness in scx_ops_bypass()") Signed-off-by: Changwoo Min Acked-by: Andrea Righi --- ChangeLog v2 -> v3: - Trim long warning messages for readability. - Properly add the Fixes tag. ChangeLog v1 -> v2: - Add warning messages without this change. - Use resched_curr() instead of resched_cpu() to avoid redundant locking = (Andrea) kernel/sched/ext.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 8fe64c27004e..cb6eb49d16be 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -4803,10 +4803,9 @@ static void scx_ops_bypass(bool bypass) */ for_each_possible_cpu(cpu) { struct rq *rq =3D cpu_rq(cpu); - struct rq_flags rf; struct task_struct *p, *n; =20 - rq_lock(rq, &rf); + raw_spin_rq_lock(rq); =20 if (bypass) { WARN_ON_ONCE(rq->scx.flags & SCX_RQ_BYPASSING); @@ -4822,7 +4821,7 @@ static void scx_ops_bypass(bool bypass) * sees scx_rq_bypassing() before moving tasks to SCX. */ if (!scx_enabled()) { - rq_unlock(rq, &rf); + raw_spin_rq_unlock(rq); continue; } =20 @@ -4842,10 +4841,11 @@ static void scx_ops_bypass(bool bypass) sched_enq_and_set_task(&ctx); } =20 - rq_unlock(rq, &rf); - /* resched to restore ticks and idle state */ - resched_cpu(cpu); + if (cpu_online(cpu) || cpu =3D=3D smp_processor_id()) + resched_curr(rq); + + raw_spin_rq_unlock(rq); } =20 atomic_dec(&scx_ops_breather_depth); --=20 2.47.1