From: sashiko-bot@kernel.org
To: "Changwoo Min" <changwoo@igalia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v3 3/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup
Date: Sun, 06 Dec 2026 06:00:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-252200@kernel.org> (raw)
In-Reply-To: <20261206053728.2026272-4-changwoo@igalia.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched_ext: scx_bpf_task_set_priv() missing from
scx_kfunc_ids_no_sub_caps
- [Low] sched_ext: scx_bpf_task_priv() takes non-const task_struct
pointer
- [Low] sched_ext: 64-bit p->scx.bpf_priv accesses can tear on 32-bit
x86 SMP
--
commit d733d17a1b2f82be9f9d84dff228752ded0286a8
Author: Changwoo Min <changwoo@igalia.com>
sched_ext: Add p->scx.bpf_priv for O(1) task context lookup
This commit adds an opaque u64 field p->scx.bpf_priv, a kfunc
scx_bpf_task_set_priv() to update it while the calling scheduler owns the
task, and a compat.bpf.h helper scx_bpf_task_priv() to read it locklessly.
> diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h
> index f3564581c317c..a1793ab5f0c32 100644
> --- a/include/linux/sched/ext.h
> +++ b/include/linux/sched/ext.h
> @@ -277,6 +277,17 @@ struct sched_ext_entity {
> */
> atomic64_t slice_oob;
>
> + /*
> + * Opaque value owned by the task's scheduler, typically an arena
> + * pointer to its per-task context. The kernel never dereferences it.
> + * Set with scx_bpf_task_set_priv() while @p is on the scheduler,
> + * from after ops.init_task() until ops.exit_task(), and cleared
> + * after ops.exit_task(). Any BPF program can read it, so a tracing
> + * program can reach the context of the current task with a single
> + * load.
> + */
> + u64 bpf_priv;
> +
[Severity: Low]
Can 64-bit accesses to p->scx.bpf_priv tear on 32-bit x86 SMP?
Both scx_bpf_task_set_priv() and __scx_disable_and_exit_task() update
p->scx.bpf_priv with WRITE_ONCE(), which splits a 64-bit store into two
32-bit stores on CONFIG_X86_32. On the reader side, do_jit() in
arch/x86/net/bpf_jit_comp32.c compiles the 64-bit BPF_LDX load from
scx_bpf_task_priv() into two 32-bit mov loads.
CPU0 (writer) CPU1 (lockless BPF reader)
__scx_disable_and_exit_task()
WRITE_ONCE(p->scx.bpf_priv, 0)
store low 32 bits = 0
scx_bpf_task_priv()
load low 32 bits (0)
load high 32 bits (old tag) <-- torn read
store high 32 bits = 0
On CONFIG_X86_32 SMP, bpf_jit_supports_kfunc_call() is enabled and a
callback-less root scheduler can attach without trampoline support, allowing
a BPF_PROG_TYPE_SYSCALL program to write via scx_bpf_task_set_priv() while
another CPU reads concurrently. A torn load can pair a matching scheduler ID
tag with a zeroed or stale payload, breaking the documented tagged-ID
lockless read contract.
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 343d82f328efc..4f575a19df761 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
[ ... ]
> @@ -12347,6 +12435,7 @@ static const struct btf_kfunc_id_set scx_kfunc_set_any = {
> BTF_KFUNCS_START(scx_kfunc_ids_no_tracing)
> BTF_ID_FLAGS(func, scx_bpf_cpuperf_set, KF_IMPLICIT_ARGS)
> BTF_ID_FLAGS(func, scx_bpf_cidperf_set, KF_IMPLICIT_ARGS)
> +BTF_ID_FLAGS(func, scx_bpf_task_set_priv, KF_IMPLICIT_ARGS | KF_RCU)
> BTF_ID_FLAGS(func, scx_bpf_sub_grant, KF_IMPLICIT_ARGS)
> BTF_ID_FLAGS(func, scx_bpf_sub_revoke, KF_IMPLICIT_ARGS)
> BTF_ID_FLAGS(func, scx_bpf_destroy_dsq, KF_IMPLICIT_ARGS)
[Severity: Medium]
Should scx_bpf_task_set_priv also be added to scx_kfunc_ids_no_sub_caps?
Because scx_bpf_task_set_priv is in scx_kfunc_ids_any and absent from
scx_kfunc_ids_no_sub_caps, scx_kfunc_context_filter() allows
ops.sub_caps_updated() to call it. caps_updated_deliver() invokes
ops.sub_caps_updated() synchronously with locked_rq = NULL under
guard(irqsave)(), inheriting whatever scx_locked_rq() and kf_tasks[] state
the parent scheduler holds.
Calling scx_bpf_task_set_priv() there therefore depends on the parent's
locking context, either silently returning false when the parent holds an rq
lock or taking task_rq_lock() inside caps_updated_deliver() when called
unlocked. Adding it to scx_kfunc_ids_no_sub_caps would match how
scx_bpf_cidperf_set() is restricted.
> diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
> index 4d2298bd7ac55..e8cb5f35eed08 100644
> --- a/tools/sched_ext/include/scx/compat.bpf.h
> +++ b/tools/sched_ext/include/scx/compat.bpf.h
[ ... ]
> +/* p->scx.bpf_priv, or 0 on kernels without it */
> +static __always_inline u64 scx_bpf_task_priv(struct task_struct *p)
> +{
> + struct sched_ext_entity___bpf_priv *scx = (void *)&p->scx;
> +
> + if (bpf_core_field_exists(scx->bpf_priv))
> + return READ_ONCE(scx->bpf_priv);
> + return 0;
> +}
[Severity: Low]
Should scx_bpf_task_priv() take a const struct task_struct *p?
It only performs a read-only load of p->scx.bpf_priv, while its companion
scx_task_sched_id() immediately below and the other task inspection helpers
in common.bpf.h all accept const struct task_struct *p. Taking a non-const
pointer prevents callers with a const task pointer from using it without a
cast.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206053728.2026272-1-changwoo@igalia.com?part=3
next prev parent reply other threads:[~2026-12-06 6:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 5:37 [PATCH v3 0/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-06 5:37 ` [PATCH v3 1/6] sched_ext: Add scx_bpf_sched_id() and scx_task_sched_id() Changwoo Min
2026-12-06 6:03 ` sashiko-bot
2026-12-06 5:37 ` [PATCH v3 2/6] selftests/sched_ext: Test " Changwoo Min
2026-12-06 5:37 ` [PATCH v3 3/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-06 6:00 ` sashiko-bot [this message]
2026-12-06 5:37 ` [PATCH v3 4/6] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Changwoo Min
2026-12-06 5:56 ` sashiko-bot
2026-12-06 5:37 ` [PATCH v3 5/6] selftests/sched_ext: Test p->scx.bpf_priv across class changes Changwoo Min
2026-12-06 5:59 ` sashiko-bot
2026-12-06 5:37 ` [PATCH v3 6/6] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Changwoo Min
2026-12-06 6:06 ` sashiko-bot
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-252200@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.