All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changwoo Min" <changwoo@igalia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v2 3/8] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id()
Date: Thu, 03 Dec 2026 05:14:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-247179@kernel.org> (raw)
In-Reply-To: <20261203045618.982539-4-changwoo@igalia.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched_ext: scx_bpf_task_sched_id() ignores task when
  CONFIG_EXT_SUB_SCHED=n
- [Low] sched_ext: scx_bpf_task_sched_id() omits const on task_struct
  pointer
--

commit d4e2b84786b2aa7b0554a97e35d420c7934a3861
Author: Changwoo Min <changwoo@igalia.com>

sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id()

This commit adds the scx_bpf_sched_id() and scx_bpf_task_sched_id() kfuncs
and their compat wrappers to let BPF programs query a scheduler's instance
id and the id of the scheduler owning a given task.

> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 7e5f58f1d8447..2ebc67916757a 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -11940,6 +11940,39 @@ __bpf_kfunc s32 scx_bpf_task_cpu(const struct task_struct *p)
>  	return task_cpu(p);
>  }
>  
[ ... ]
> +/**
> + * scx_bpf_task_sched_id - Id of the scheduler that owns a task
> + * @p: task of interest
> + *
> + * Return the instance id of the scheduler @p is on, see scx_bpf_sched_id(), 0
> + * if @p is not on any. Without the rq lock of @p, @p may move to another
> + * scheduler right after.
> + */
> +__bpf_kfunc u64 scx_bpf_task_sched_id(struct task_struct *p)

[Severity: Low]
Should the task_struct pointer parameter here (and in the ksym declaration
and wrapper in tools/sched_ext/include/scx/compat.bpf.h) be const?

scx_bpf_task_sched_id() only passes p to scx_task_sched_rcu(), and its
adjacent read-only task kfuncs (scx_bpf_task_running(), scx_bpf_task_cpu(),
scx_bpf_task_cid()) all take const struct task_struct *p.  Omitting const
forces BPF callers with a const pointer to cast it away.

> +{
> +	struct scx_sched *sch;
> +
> +	guard(rcu)();
> +	sch = scx_task_sched_rcu(p);
> +	return sch ? sch->id : 0;
> +}

[Severity: Medium]
Does scx_bpf_task_sched_id() return 0 for unowned tasks when
CONFIG_EXT_SUB_SCHED is disabled?

When CONFIG_CGROUPS=n, CONFIG_EXT_SUB_SCHED is disabled and
scx_task_sched_rcu(p) in kernel/sched/ext/internal.h ignores p and returns
rcu_dereference_all(scx_root) directly.  That makes scx_bpf_task_sched_id()
return scx_root->id for tasks not on any scheduler, such as idle tasks.

In scx_root_disable(), scx_root also stays non-NULL after
WRITE_ONCE(sch->dead, true) until RCU_INIT_POINTER(scx_root, NULL), so
scx_bpf_task_sched_id() keeps returning the dead scheduler's id even after
scx_bpf_sched_id() returns 0.

As a result, BPF callers checking scx_bpf_task_sched_id(p) will misclassify
unowned tasks.  Checking scx_get_task_state(p) and !READ_ONCE(sch->dead) on
the !CONFIG_EXT_SUB_SCHED path would preserve the documented contract.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203045618.982539-1-changwoo@igalia.com?part=3

  reply	other threads:[~2026-12-03  5:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  4:56 [PATCH v2 0/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-03  4:56 ` [PATCH v2 1/8] sched_ext: Reset task fields after ops.exit_task() Changwoo Min
2026-12-04  6:10   ` Andrea Righi
2026-12-04 17:04   ` Tejun Heo
2026-12-03  4:56 ` [PATCH v2 2/8] sched_ext: Mark a task enabled before ops.enable() Changwoo Min
2026-12-04  6:10   ` Andrea Righi
2026-12-04 17:02   ` Tejun Heo
2026-12-03  4:56 ` [PATCH v2 3/8] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id() Changwoo Min
2026-12-03  5:14   ` sashiko-bot [this message]
2026-12-04  6:44   ` Andrea Righi
2026-12-04 17:17   ` Tejun Heo
2026-12-03  4:56 ` [PATCH v2 4/8] selftests/sched_ext: Test " Changwoo Min
2026-12-03  5:14   ` sashiko-bot
2026-12-03  4:56 ` [PATCH v2 5/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-03  5:20   ` sashiko-bot
2026-12-04 17:09   ` Tejun Heo
2026-12-03  4:56 ` [PATCH v2 6/8] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Changwoo Min
2026-12-03  5:19   ` sashiko-bot
2026-12-03  4:56 ` [PATCH v2 7/8] selftests/sched_ext: Test p->scx.bpf_priv across class changes Changwoo Min
2026-12-03  5:26   ` sashiko-bot
2026-12-03  4:56 ` [PATCH v2 8/8] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Changwoo Min
2026-12-03  5:32   ` sashiko-bot
2026-12-04 17:19 ` [PATCH v2 0/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup 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=sashiko-outbox-247179@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=changwoo@igalia.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.