Sched_ext development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Qiurong Fang" <fangqiurong@kylinos.cn>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH] sched_ext: Close the pre-enable ops error claim window
Date: Thu, 10 Sep 2026 09:01:02 +0000	[thread overview]
Message-ID: <20260910090102.AEE431F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260910084533.2420199-1-fangqiurong@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Concurrent calls to scx_root_disable() on the same scheduler cause a double teardown due to fall-throughs on SCX_DISABLING and SCX_DISABLED.
--

commit dd97abeb536b6afa1a46d2a0b2de7e7eaddfef0a
Author: fangqiurong <fangqiurong@kylinos.cn>

sched_ext: Close the pre-enable ops error claim window

This commit addresses a race window where scx_alloc_and_add_sched()
publishes ops->priv before transitioning to SCX_ENABLING. It moves the state
transition before the allocation and adjusts the early exit logic in
scx_root_disable() to prevent a teardown shortcut from racing with the
enable workfn.

> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c

[ ... ]

> @@ -6395,8 +6395,9 @@ static void scx_root_disable(struct scx_sched *sch)
>  	case SCX_DISABLED:
>  		pr_warn("sched_ext: ops error detected without ops (%s)\n",
>  			sch->exit_info->msg);
> -		WARN_ON_ONCE(scx_set_enable_state(SCX_DISABLED) != SCX_DISABLING);
> -		goto done;
> +		if (scx_tryset_enable_state(SCX_DISABLED, SCX_DISABLING))
> +			goto done;
> +		break;

[Severity: High]
If two threads concurrently call scx_root_disable() (e.g., a SysRq disable
and a BPF error triggering scx_disable_workfn), both will serialize on
scx_enable_mutex.

For the thread that arrives second, if scx_set_enable_state() returns
SCX_DISABLED and scx_tryset_enable_state() fails, the newly added break
statement will cause it to fall through the switch block instead of going to
done.

Similarly, if scx_set_enable_state() returns SCX_DISABLING, the adjacent
case block logs a warning and also breaks out of the switch.

In both cases, does this allow the second thread to bypass the early exit,
acquire scx_enable_mutex, and execute the full teardown sequence again on an
already disabled scheduler?

Could this result in memory corruption from double frees (such as calling
rhashtable_free_and_destroy() on scx_tid_hash again) and duplicate calls to
the BPF program's exit callback?

>  	default:
>  		break;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910084533.2420199-1-fangqiurong@kylinos.cn?part=1

  reply	other threads:[~2026-09-10  9:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  8:45 [PATCH] sched_ext: Close the pre-enable ops error claim window Qiurong Fang
2026-09-10  9:01 ` sashiko-bot [this message]
2026-09-10 21:40 ` Tejun Heo
2026-09-11  2:42 ` [PATCH v2] " Qiurong Fang
2026-09-11 15:24   ` Tejun Heo
2026-09-12 13:15   ` [PATCH v3] " Qiurong Fang
2026-09-13 15:59     ` Tejun Heo

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=20260910090102.AEE431F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fangqiurong@kylinos.cn \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox