All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task()
Date: Wed, 15 Jul 2026 21:14:55 +0000	[thread overview]
Message-ID: <20260715211455.981AF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715205622.276220-6-arighi@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Lost wakeup / scheduler stall when a task is skipped during DSQ consumption.
- [High] List corruption and state machine violation due to enqueuing an actively executing task to the global DSQ.
--

--- Patch [5]: [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task() ---
commit b2d369cbc11d2586ba8175f09e54ae5417c87ff8
Author: Andrea Righi <arighi@nvidia.com>

sched_ext: Fix TOCTOU race in consume_remote_task()

This commit addresses a TOCTOU race when migrating a task during DSQ
consumption. It re-evaluates task_can_run_on_remote_rq() after locking the
source runqueue and falls back to enqueuing the task on the global DSQ if
the task is no longer eligible to migrate.

> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 04fc34a7ded65..8d8057b80d544 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c

[ ... ]

> @@ -2382,6 +2384,10 @@ static bool task_can_run_on_remote_rq(struct scx_sched *sch,
>  
>  	WARN_ON_ONCE(task_cpu(p) == cpu);
>  
> +	/* Don't migrate a task which is running on a CPU. */
> +	if (task_on_cpu(task_rq(p), p))
> +		return false;
> +

[Severity: High]
Could returning false here cause a lost wakeup or scheduler stall?

When a task is preempted and enqueued to a non-local DSQ, an idle CPU might
attempt to consume it from scx_consume_dispatch_q() before the previous CPU
completes finish_task_switch() (which clears p->on_cpu).

Since scx_consume_dispatch_q() evaluates task_can_run_on_remote_rq()
locklessly, it would return false, causing the consuming CPU to skip the
task and potentially go back to sleep. Once the previous CPU finally clears
p->on_cpu, is there a mechanism to generate a new kick, or will the task
remain stranded on the dispatch queue indefinitely?

>  	/*
>  	 * If @p has migration disabled, @p->cpus_ptr is updated to contain only
>  	 * the pinned CPU in migrate_disable_switch() while @p is being switched

[ ... ]

> @@ -2480,6 +2486,27 @@ static bool consume_remote_task(struct scx_sched *sch, struct rq *this_rq,
>  				struct scx_dispatch_q *dsq, struct rq *src_rq)
>  {
>  	if (unlink_dsq_and_switch_rq_lock(p, dsq, this_rq, src_rq)) {
> +		/*
> +		 * Eligibility may have changed while switching rq locks. This is a
> +		 * kernel-side race, not an invalid BPF placement request, so don't
> +		 * abort the scheduler on failure. Fall back to the global DSQ, where
> +		 * normal consumption filters can select an eligible CPU without
> +		 * forcing the task onto the source local DSQ.
> +		 */
> +		if (unlikely(!task_can_run_on_remote_rq(sch, p, this_rq, false))) {
> +			p->scx.dsq = NULL;
> +			p->scx.holding_cpu = -1;
> +			scx_dispatch_enqueue(sch, src_rq,
> +					     find_global_dsq(sch, task_cpu(p)), p,
> +					     enq_flags | SCX_ENQ_CLEAR_OPSS |
> +					     SCX_ENQ_GDSQ_FALLBACK);

[Severity: High]
Can this fallback path lead to list corruption if the task is actively
executing?

If a donor task in a DSQ becomes active (task_on_cpu() is true) during proxy
execution, the re-evaluation of task_can_run_on_remote_rq() correctly detects
it as executing and returns false.

However, this fallback path will then clear p->scx.dsq and unconditionally
enqueue the actively executing task to the global DSQ. When the task is later
preempted, put_prev_task_scx() will attempt to enqueue it again, which seems
like it would trigger the WARN_ON_ONCE(p->scx.dsq || !list_empty(...)) and
corrupt the DSQ list.

> +			if (sched_class_above(p->sched_class,
> +					      src_rq->donor->sched_class))
> +				resched_curr(src_rq);
> +			switch_rq_lock(src_rq, this_rq);
> +			return false;
> +		}
> +
>  		move_remote_task_to_local_dsq(sch, p, enq_flags, src_rq, this_rq);
>  		return true;
>  	} else {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260715205622.276220-1-arighi@nvidia.com?part=5

  reply	other threads:[~2026-07-15 21:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 20:54 [PATCHSET v6 sched_ext/for-7.3] sched: Make proxy execution compatible with sched_ext Andrea Righi
2026-07-15 20:54 ` [PATCH 01/11] sched: Make NOHZ CFS bandwidth checks follow proxy donor Andrea Righi
2026-07-15 20:54 ` [PATCH 02/11] sched: Add helper to block retained proxy donors Andrea Righi
2026-07-15 20:54 ` [PATCH 03/11] sched_ext: Block proxy donors across scheduler transitions Andrea Righi
2026-07-15 20:54 ` [PATCH 04/11] sched_ext: Fix ops.running/stopping() pairing for proxy-exec donors Andrea Righi
2026-07-15 20:54 ` [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task() Andrea Righi
2026-07-15 21:14   ` sashiko-bot [this message]
2026-07-15 20:54 ` [PATCH 06/11] sched_ext: Split curr|donor references properly Andrea Righi
2026-07-15 21:15   ` sashiko-bot
2026-07-15 20:54 ` [PATCH 07/11] sched_ext: Handle blocked donor migration with proxy execution Andrea Righi
2026-07-15 21:21   ` sashiko-bot
2026-07-15 20:54 ` [PATCH 08/11] sched_ext: Delegate proxy donor admission to BPF schedulers Andrea Righi
2026-07-15 20:54 ` [PATCH 09/11] sched_ext: Add selftest for blocked donor admission Andrea Righi
2026-07-15 20:54 ` [PATCH 10/11] sched_ext: scx_qmap: Add proxy execution support Andrea Righi
2026-07-15 21:35   ` sashiko-bot
2026-07-15 20:54 ` [PATCH 11/11] sched: Allow enabling proxy exec with sched_ext 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=20260715211455.981AF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sched-ext@lists.linux.dev \
    /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.