From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147688; b=L8oQzaMighXV7zyDIljeHssazrQqyHwoPWONACv0GK4F1FKUlvLz18mzkkiqsjyxBv2t EWEe5h7Dw8i23d8Cf04rvmG0MbbXhkNOFpzmrYn/6IgCmtsNvyxsomLyTLLZSzhpVTh3r eEWeptLZTMstDBOoE/xDoxt+bwTlbUjoMSoO0lu6s6j1QN/occzbuTIAl/RQ2CGdkPP6B +kupAQ481SXHQyVEX1p8uSyyzW/eW7fjAAdrf6NAOTvFcWA5RCBKmAVdKIjfT3IQgBTnG yGbxhtAC7OaREopqnS2nn5Say5RxdepDdVqFl9/MnD5Ittv83IY0Bysn0SjAGzUIkAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147688; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=s11ax+d4i56flDROtvYCQG1WO7N7Ri4YiBE72ccQPpI=; b=kEk/x/3cyJZ8soy7aXZkzTzu2DuJy3Ti1A1lNz7nFlVH1OhydWxgGlF6dm8XvgNyH7Rt iwGREOrw65KXbOxdNclftEvY8ShK03PDQ/L0CNx+uAomDHlTMz4OgxUwY4lxZ6C/yU9j/ nyjlea0AnafbF3rZxHTV7+h2/uJYGkP2ks+a/fvmVB3QYsaDtJIemHqaCPHgOMmLLt+2E CjVwaLxyHk8oMdRhbVc397tGSTftfpGxZxZ/83Xf3NfdzJZPOmau5ypKDY3g20rV19Ln0 KiUyPLQHkGAEpeJwmyqX9si5weHc8v0w1RWaYsgrk/NxS9gEwjvxPPjXIIcSakHqEHw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EsC3jYSx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22B51606A31A for ; Tue, 1 Dec 2026 17:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EsC3jYSx Received: by smtp.kernel.org (Postfix) with ESMTPSA id B06E01F00893; Tue, 1 Dec 2026 17:54:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796147687; bh=s11ax+d4i56flDROtvYCQG1WO7N7Ri4YiBE72ccQPpI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=EsC3jYSxdlkz62ag5XE5Kn2wt9Y+SiEqJMtAZQc594qRjWdWMr1hLhYaURkGnbDq+ uy9c5BGVKyJwR3Oyri7l+OzksPf3FnxJOzuvweoTSVKVBpb5Y0YGm+tC9KmlQFwUcr Oj7EcEdBvnB+LzKp5rQo+WiEOi95haNECFkO6ok7LyM+BA4Wjd2ad8Ni47oG5WBAXs JwGKGEnbTvtyIP9CxOXWg9eFgGfYnzoSvO38mcyXGAPLWvVrTl2d+SGr4ycNlwojhN UIKLrjje8QZxBesX8M8UuC6R4to9zCaTXaFd3tZcsBr21oI7ruCdEc4eJVvWICbd/h l3ph+gc9acKPw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 6.18.y] sched_ext: Fix this_rq() assumptions in dispatch kfuncs Reply-To: sashiko-reviews@lists.linux.dev To: "Kuba Piecuch" Cc: sched-ext@lists.linux.dev In-Reply-To: <20261201173537.1103264-1-jpiecuch@google.com> References: <20261201173537.1103264-1-jpiecuch@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 17:54:47 +0000 X-Mailing-List: sched-ext@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] sched_ext: deadlock in scx_dsq_move() due to missing scx_locked_rq() prereqs -- commit f1df95fec5f50329ce0dbe3284b81e578b28a649 Author: Tejun Heo sched_ext: Fix this_rq() assumptions in dispatch kfuncs This commit replaces this_rq() assumptions in finish_dispatch(), scx_dsq_move(), and scx_bpf_dsq_nr_queued() with the runqueue tracked by scx_locked_rq() so operations targeting an SMT sibling under core scheduling resolve SCX_DSQ_LOCAL and rq lock ownership against the dispatched rq. > diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c > index b3a6d60709403..8a378a50c3444 100644 > --- a/kernel/sched/ext.c > +++ b/kernel/sched/ext.c [ ... ] > @@ -5762,9 +5762,8 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_ke= rn *kit, > { > struct scx_sched *sch =3D scx_root; > struct scx_dispatch_q *src_dsq =3D kit->dsq, *dst_dsq; > - struct rq *this_rq, *src_rq, *locked_rq; > + struct rq *p_rq, *src_rq, *locked_rq; > bool dispatched =3D false; > - bool in_balance; > unsigned long flags; > =20 > /* > @@ -5780,19 +5779,23 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_= kern *kit, > return false; > =20 > /* > - * Can be called from either ops.dispatch() locking this_rq() or any > - * context where no rq lock is held. If latter, lock @p's task_rq which > - * we'll likely need anyway. > + * Can be called from either ops.dispatch() holding the dispatched rq's > + * lock or any context where no rq lock is held. If latter, lock @p's > + * task_rq which we'll likely need anyway. > */ > src_rq =3D task_rq(p); > =20 > local_irq_save(flags); > - this_rq =3D this_rq(); > - in_balance =3D this_rq->scx.flags & SCX_RQ_IN_BALANCE; > =20 > - if (in_balance) { > - if (this_rq !=3D src_rq) { > - raw_spin_rq_unlock(this_rq); > + /* > + * Under core scheduling, dispatch can run for a sibling rq, so the > + * locked rq is not necessarily this CPU's. > + */ > + locked_rq =3D scx_locked_rq(); > + > + if (locked_rq) { > + if (locked_rq !=3D src_rq) { > + raw_spin_rq_unlock(locked_rq); > raw_spin_rq_lock(src_rq); > } > } else { > @@ -5806,7 +5809,7 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_ke= rn *kit, > */ > scx_breather(src_rq); > =20 > - locked_rq =3D src_rq; > + p_rq =3D src_rq; > raw_spin_lock(&src_dsq->lock); > =20 > /* > @@ -5822,7 +5825,7 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_ke= rn *kit, > } > =20 > /* @p is still on $src_dsq and stable, determine the destination */ > - dst_dsq =3D find_dsq_for_dispatch(sch, this_rq, dsq_id, p); > + dst_dsq =3D find_dsq_for_dispatch(sch, locked_rq ?: this_rq(), dsq_id, = p); > =20 > /* > * Apply vtime and slice updates before moving so that the new time is > @@ -5835,16 +5838,16 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_= kern *kit, > p->scx.slice =3D kit->slice; > =20 > /* execute move */ > - locked_rq =3D move_task_between_dsqs(sch, p, enq_flags, src_dsq, dst_ds= q); > + p_rq =3D move_task_between_dsqs(sch, p, enq_flags, src_dsq, dst_dsq); > dispatched =3D true; > out: > - if (in_balance) { > - if (this_rq !=3D locked_rq) { > - raw_spin_rq_unlock(locked_rq); > - raw_spin_rq_lock(this_rq); > + if (locked_rq) { > + if (locked_rq !=3D p_rq) { > + raw_spin_rq_unlock(p_rq); > + raw_spin_rq_lock(locked_rq); > } > } else { > - raw_spin_rq_unlock_irqrestore(locked_rq, flags); > + raw_spin_rq_unlock_irqrestore(p_rq, flags); > } [Severity: High] Can a second scx_dsq_move() call inside ops.dispatch() see scx_locked_rq() =3D=3D NULL and deadlock on raw_spin_rq_lock(src_rq)? In 6.18.y, SCX_CALL_OP_RET() clears scx_locked_rq_state to NULL on exit instead of restoring the outer operation's locked rq: kernel/sched/ext.c:SCX_CALL_OP_RET() { if (rq) update_locked_rq(rq); ... if (rq) update_locked_rq(NULL); } When ops.dispatch() migrates a core-scheduled task to a remote local DSQ, activate_task() invokes ops.core_sched_before() via SCX_CALL_OP_RET(), wiping scx_locked_rq_state while ops.dispatch() still holds the dispatched rq lock: balance_one(rq) SCX_CALL_OP(..., dispatch, rq, ...) update_locked_rq(rq) ops.dispatch() scx_dsq_move() move_task_between_dsqs() move_remote_task_to_local_dsq() activate_task(dst_rq, p, 0) ... scx_prio_less() SCX_CALL_OP_2TASKS_RET(..., core_sched_before, ...) update_locked_rq(NULL) raw_spin_rq_lock(locked_rq) scx_dsq_move() locked_rq =3D scx_locked_rq() /* NULL */ raw_spin_rq_lock(src_rq) <-- deadlocks if src_rq shares rq lock If src_rq is on another core, scx_dsq_move() instead acquires src_rq on top of the held rq lock and then unlocks p_rq and enables IRQs at out: without restoring the dispatched rq lock. In addition, replacing switch_rq_lock() with raw_spin_rq_unlock() and raw_spin_rq_lock() skips updating scx_locked_rq_state across rq lock handoffs. Backporting prerequisite commits 7fb39e4eb4c3 ("sched_ext: Save and restore scx_locked_rq across SCX_CALL_OP") and 18d62044cda7 ("sched_ext: Preserve rq tracking across local DSQ dispatch") would preserve scx_locked_rq() across nested callbacks and rq lock switches. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201173537.1103= 264-1-jpiecuch@google.com?part=3D1