From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 04/14] sched: Add prepare_switch() class callback
Date: Sat, 25 Jul 2026 16:25:23 +0000 [thread overview]
Message-ID: <20260725162523.85F1A1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260725160513.57477-5-arighi@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `prepare_switch()` callback is invoked on the incoming `next_class`, but the task may never actually transition to that class if `SCHED_FLAG_KEEP_PARAMS` is set, leaving the prepared state orphaned and leaking resources.
--
--- Patch [4]: [PATCH 04/14] sched: Add prepare_switch() class callback ---
commit f8056ba7bb47e84cdf2c8a5193c3485b3b2d44d0
Author: Andrea Righi <arighi@nvidia.com>
sched: Add prepare_switch() class callback
This commit introduces a prepare_switch() callback for scheduling classes.
It allows an incoming class to prepare a task while the state is still
live, before the normal dequeue and class transition take place.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 37c87783439f5..66e9ba50f5639 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
[ ... ]
> @@ -11221,7 +11221,9 @@ static inline void sched_mm_cid_fork(struct task_struct *t) { }
>
> static DEFINE_PER_CPU(struct sched_change_ctx, sched_change_ctx);
>
> -struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned int flags)
> +struct sched_change_ctx *
> +sched_change_begin(struct task_struct *p, const struct sched_class *next_class,
> + unsigned int flags)
> {
> struct sched_change_ctx *ctx = this_cpu_ptr(&sched_change_ctx);
> struct rq *rq = task_rq(p);
> @@ -11239,6 +11241,10 @@ struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned int
> flags |= DEQUEUE_NOCLOCK;
> }
>
> + if ((flags & DEQUEUE_CLASS) && next_class != p->sched_class &&
> + next_class->prepare_switch)
> + next_class->prepare_switch(rq, p);
> +
> if ((flags & DEQUEUE_CLASS) && p->sched_class->switching_from)
> p->sched_class->switching_from(rq, p);
>
[ ... ]
> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> index b215b0ead9a60..bc32ce76ff4fe 100644
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
[ ... ]
> @@ -678,7 +678,7 @@ int __sched_setscheduler(struct task_struct *p,
> if (prev_class != next_class)
> queue_flags |= DEQUEUE_CLASS;
>
> - scoped_guard (sched_change, p, queue_flags) {
> + scoped_guard (sched_change, p, next_class, queue_flags) {
>
> if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) {
> __setscheduler_params(p, attr);
[Severity: Medium]
Will this leak resources if a user calls sched_setattr() with a new policy and
sets attr.sched_flags = SCHED_FLAG_KEEP_PARAMS?
In __sched_setscheduler(), if SCHED_FLAG_KEEP_PARAMS is set, the class
assignment p->sched_class = next_class is explicitly skipped.
However, because queue_flags includes DEQUEUE_CLASS, the newly modified
sched_change_begin() unconditionally invokes next_class->prepare_switch(rq, p)
for the incoming class.
Because the task never actually transitions to next_class, does this leave
the prepared state dangling and resources leaked since there won't be a
matching cleanup or transition?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725160513.57477-1-arighi@nvidia.com?part=4
next prev parent reply other threads:[~2026-07-25 16:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 16:04 [PATCHSET v9 sched_ext/for-7.3] sched: Make proxy execution compatible with sched_ext Andrea Righi
2026-07-25 16:04 ` [PATCH 01/14] sched/core: Avoid false migration warning for proxy donors Andrea Righi
2026-07-25 16:04 ` [PATCH 02/14] sched: Make NOHZ CFS bandwidth checks follow proxy donor Andrea Righi
2026-07-25 16:26 ` sashiko-bot
2026-07-25 16:04 ` [PATCH 03/14] sched: Add helper to block retained proxy donors Andrea Righi
2026-07-25 16:04 ` [PATCH 04/14] sched: Add prepare_switch() class callback Andrea Righi
2026-07-25 16:25 ` sashiko-bot [this message]
2026-07-25 16:04 ` [PATCH 05/14] sched: Add sched_ext hooks for proxy execution Andrea Righi
2026-07-25 16:14 ` sashiko-bot
2026-07-25 16:04 ` [PATCH 06/14] sched_ext: Block proxy donors across scheduler transitions Andrea Righi
2026-07-25 16:04 ` [PATCH 07/14] sched_ext: Fix ops.running/stopping() pairing for proxy-exec donors Andrea Righi
2026-07-25 16:04 ` [PATCH 08/14] sched_ext: Generalize the reject DSQ reenqueue path Andrea Righi
2026-07-25 16:04 ` [PATCH 09/14] sched_ext: Handle proxy-exec races in remote DSQ transfers Andrea Righi
2026-07-25 16:04 ` [PATCH 10/14] sched_ext: Split curr|donor references properly Andrea Righi
2026-07-25 16:04 ` [PATCH 11/14] sched_ext: Delegate proxy donor admission to BPF schedulers Andrea Righi
2026-07-25 16:04 ` [PATCH 12/14] sched_ext: Add selftest for blocked donor admission Andrea Righi
2026-07-25 16:04 ` [PATCH 13/14] sched_ext: scx_qmap: Add proxy execution support Andrea Righi
2026-07-25 16:04 ` [PATCH 14/14] 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=20260725162523.85F1A1F00A3A@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox