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=1796379314; b=nPcfcGte2H9y9mGHs3OAD8eOAWdX2irhmO0S/xd49XWIsbftv2Jc3C/0colyE7Wek8pt MMzgzJpN2sFoN/7Kppnfbbf34Yb5MpJHZATte2su3C16dBIOgy/FCp/vBg97W4/5+3MCN siHH+y0JiAh/hGJviLAqhqwHfgBWsDu6ERp8SJidT3QkJ6iE/VobQYze6kdY8g8mgu2k3 KwpR+K/1I64hy72D4zCX+amvWavOqUiR2mYDJdnOUIBPN9XPHv0u8rPoVVCVykiyBCztF xRXlYITFgWNc0tOQeWLihcLcCBL9cWDrV1gTgXSwkdpclZGPMqgSlKRNlo+7UTSUSzQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379314; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=u153i0hIzHijNGwoEXu7V9iqbZr3Ey2x+pOIl/ci2g8=; b=u9wGnwAihbL84uzyd62SN+uBDd+hdkREseU1CY+PP2GjtYcB72DzgAwaLy0dbtJc3Eiy /Ete2tzF+ywwgYhIOeCQ+FKWmaNUDYM3uPqYsHyPIE0Gga/Rn5Ut295B5fVzOTu+K75KD if83xKmngE7Q13GrtTx1DzhHqBOUtql76rLFhAtgWfl1s7PCnrNfGpo6GFQDqLG/t3mp2 cgf9OXN/PNiRbJy0DaMVgbB9/tqMmoK+6zkoe1sjTX/x6sso0gLKcP3FaieNMcm+VV86O 897Am2qAAUDMZGtPaJVERn2OWKJHv6LZ018GmIqBmXIn/A71EFz3+CKHlWVablTsgiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CvLaU43M; 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 29D8D606A32D; Fri, 4 Dec 2026 10:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CvLaU43M Received: by smtp.kernel.org (Postfix) with ESMTPSA id 975361F000C2; Fri, 4 Dec 2026 10:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379314; bh=u153i0hIzHijNGwoEXu7V9iqbZr3Ey2x+pOIl/ci2g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CvLaU43MwPFvnuzPSzPzBepNa2FxL/a5BzmuU3WiRr/taamaYcCD5MGFPZDvOswSj 1WINrWo2xDvAKye0jbtRYvJOXhbQoFLrhEoUdXxkH9j4ymUcRKhyzk0R7lo94aFqYy jgsAfbLodhiH0kmYi4gkh7yePcpyOT5VXSrA146Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rahad Bhuiya , Tejun Heo , Cheng-Yang Chou , Sasha Levin Subject: [PATCH 7.3 013/742] sched_ext: Reset task fields on exit of an SCX_TASK_READY task Date: Fri, 4 Dec 2026 18:57:57 +0900 Message-ID: <20261204100635.391664290@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rahad Bhuiya commit 564405c424f49d70b13debe7fe5b550234ad6b84 upstream. Tasks in SCX_TASK_READY are attached to a scheduler but outside the ext class, such as RT/DL tasks, or non-SCHED_EXT tasks under a partial switch. The scheduler's BPF code can still update their dsq_vtime and slice (for instance, via ops.cgroup_move() as done by scx_flatcg). Because __scx_disable_and_exit_task() currently breaks out of the state switch for SCX_TASK_READY without calling scx_reset_task_fields(), these fields are not cleared when the task leaves the scheduler. If the task is subsequently moved to another cgroup/sub-scheduler and later switches to SCHED_NORMAL, the new scheduler's ops.enable() sees stale dsq_vtime from the previous scheduler's clock. Call scx_reset_task_fields() in the SCX_TASK_READY case of __scx_disable_and_exit_task() to ensure SCX-managed fields are properly reset when leaving the scheduler. Fixes: 5771e79e461e ("sched_ext: Reset dsq_vtime and slice when a task leaves SCX") Signed-off-by: Rahad Bhuiya Signed-off-by: Tejun Heo [ chengyang: 7.3 lacks scx_reset_task_fields(), so factor it out of scx_disable_task() ] Signed-off-by: Cheng-Yang Chou Signed-off-by: Sasha Levin --- kernel/sched/ext/ext.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index cc8d09924fa13..1049a0914d600 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -4159,6 +4159,27 @@ void scx_enable_task(struct scx_sched *sch, struct task_struct *p) scx_set_task_state(p, SCX_TASK_ENABLED); } +/* + * Reset the SCX-managed fields when @p leaves the BPF scheduler's control. + */ +static void scx_reset_task_fields(struct rq *rq, struct task_struct *p) +{ + lockdep_assert_rq_held(rq); + + p->scx.dsq_vtime = 0; + scx_task_slice_ended(rq, p); + scx_set_task_slice(p, 0); + p->scx.reenq_cnt = 0; + + /* + * If @p is runnable but not running, its wait started at runnable_at, + * which ops_dequeue() didn't reset. Leaving the scheduler ends the + * wait. Reset runnable_at the next time @p is enqueued on SCX, so that + * the watchdog doesn't count the time @p spends elsewhere. + */ + p->scx.flags |= SCX_TASK_RESET_RUNNABLE_AT; +} + static void scx_disable_task(struct scx_sched *sch, struct task_struct *p) { struct rq *rq = task_rq(p); @@ -4172,22 +4193,8 @@ static void scx_disable_task(struct scx_sched *sch, struct task_struct *p) SCX_CALL_OP_TASK(sch, disable, rq, p); scx_set_task_state(p, SCX_TASK_READY); - /* - * Reset the SCX-managed fields when @p leaves the BPF scheduler's - * control, after ops.disable() has observed their final values. - */ - p->scx.dsq_vtime = 0; - scx_task_slice_ended(rq, p); - scx_set_task_slice(p, 0); - p->scx.reenq_cnt = 0; - - /* - * If @p is runnable but not running, its wait started at runnable_at, - * which ops_dequeue() didn't reset. Leaving @sch ends the wait. Reset - * runnable_at the next time @p is enqueued on SCX, so that the watchdog - * doesn't count the time @p spends elsewhere. - */ - p->scx.flags |= SCX_TASK_RESET_RUNNABLE_AT; + /* after ops.disable() has observed the final values */ + scx_reset_task_fields(rq, p); /* * Verify the task is not in BPF scheduler's custody. If flag @@ -4213,6 +4220,7 @@ void __scx_disable_and_exit_task(struct scx_sched *sch, struct task_struct *p) args.cancelled = true; break; case SCX_TASK_READY: + scx_reset_task_fields(task_rq(p), p); break; case SCX_TASK_ENABLED: scx_disable_task(sch, p); -- 2.53.0