All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: stable@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>,
	Kuba Piecuch <jpiecuch@google.com>,
	fangqiurong <fangqiurong@kylinos.cn>,
	Rahad Bhuiya <rahadbhuiya2021@gmail.com>,
	sched-ext@lists.linux.dev
Subject: [PATCH 7.1.y 7/8] sched_ext: Reset dsq_vtime and slice when a task leaves SCX
Date: Sat, 28 Nov 2026 11:23:50 +0100	[thread overview]
Message-ID: <20261128102535.655465-8-arighi@nvidia.com> (raw)
In-Reply-To: <20261128102535.655465-1-arighi@nvidia.com>

commit 5771e79e461e72140b752496b69275b9e6bd1a75 upstream.

When a task leaves the BPF scheduler's control, p->scx.dsq_vtime and
p->scx.slice keep whatever values they last held. The slice value is
core-managed and is refilled on the next enqueue, but dsq_vtime is owned
by the BPF scheduler and is never cleared by the core, so a task that
leaves SCX and later returns carries a stale dsq_vtime across the
round-trip.

The stale values are also visible to other SCX schedulers that inspect
the scx fields of non-SCX tasks.

Fix this by resetting both dsq_vtime and slice in scx_disable_task(),
after ops.disable(), so the BPF scheduler can still observe the task's
final values and non-SCX tasks do not retain stale SCX state.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
[arighi: Apply to kernel/sched/ext.c before the source split.]
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index ca9ed9c1da66a..b2bb60ff78d39 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -3692,6 +3692,13 @@ 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;
+	p->scx.slice = 0;
+
 	/*
 	 * Verify the task is not in BPF scheduler's custody. If flag
 	 * transitions are consistent, the flag should always be clear
-- 
2.56.1


  parent reply	other threads:[~2026-11-28 10:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 10:23 [PATCH 7.1.y 0/8] sched_ext: Backport dispatch and task-state fixes Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 1/8] sched_ext: Check remote rq eligibility under task's rq lock Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 2/8] sched_ext: Don't run ops.dequeue() with a DSQ lock held Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 3/8] sched_ext: Call ops.dequeue() when a task arrives on a remote local DSQ Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 4/8] sched_ext: Wait for SCX_OPSS_DISPATCHING before reenqueueing a task Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 5/8] sched_ext: Wait for SCX_OPSS_DISPATCHING before moving tasks off DSQs Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 6/8] sched_ext: Generate qseq from a per-task counter Andrea Righi
2026-11-28 10:23 ` Andrea Righi [this message]
2026-11-28 10:23 ` [PATCH 7.1.y 8/8] sched_ext: Reset task fields on exit of an SCX_TASK_READY task Andrea Righi
2026-11-29 12:21 ` [PATCH 7.1.y 0/8] sched_ext: Backport dispatch and task-state fixes Greg Kroah-Hartman
2026-11-29 13:54   ` Andrea Righi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128102535.655465-8-arighi@nvidia.com \
    --to=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=fangqiurong@kylinos.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=jpiecuch@google.com \
    --cc=rahadbhuiya2021@gmail.com \
    --cc=sashal@kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.