Sched_ext development
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted
@ 2026-08-20  5:20 Tejun Heo
  2026-08-20  6:16 ` bot+bpf-ci
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tejun Heo @ 2026-08-20  5:20 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	John Fastabend, bpf, David Vernet, Andrea Righi, Changwoo Min,
	Emil Tsalapatis, sched-ext, linux-kernel

Walking an unannotated pointer field of a trusted struct yields a bare
PTR_TO_BTF_ID in non-sleepable programs, which kfuncs and helpers accept,
but PTR_UNTRUSTED in sleepable programs, which they reject. This gets in the
way of making ops.init_task() sleepable, which schedulers want for
allocations. For example, passing args->cgroup into bpf_cgrp_storage_get()
then fails verification and the only recourse is round-tripping through the
cgroup ID with bpf_cgroup_from_id().

The pointer fields in the sched_ext ops argument containers are all pinned
by the callers for the duration of the ops calls and are never NULL. Add
them to the verifier's trusted-fields whitelist so that they are PTR_TRUSTED
in both sleepable and non-sleepable programs.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/bpf/verifier.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5661,6 +5661,28 @@ BTF_TYPE_SAFE_TRUSTED(struct file) {
 	struct inode *f_inode;
 };
 
+/*
+ * The pointer fields in the sched_ext ops argument containers are pinned by the
+ * callers for the duration of the ops calls and are never NULL.
+ */
+BTF_TYPE_SAFE_TRUSTED(struct scx_init_task_args) {
+#ifdef CONFIG_EXT_GROUP_SCHED
+	struct cgroup *cgroup;
+#endif
+};
+
+BTF_TYPE_SAFE_TRUSTED(struct scx_cpu_release_args) {
+	struct task_struct *task;
+};
+
+BTF_TYPE_SAFE_TRUSTED(struct scx_sub_attach_args) {
+	struct sched_ext_ops *ops;
+};
+
+BTF_TYPE_SAFE_TRUSTED(struct scx_sub_detach_args) {
+	struct sched_ext_ops *ops;
+};
+
 BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct dentry) {
 	struct inode *d_inode;
 };
@@ -5705,6 +5727,10 @@ static bool type_is_trusted(struct bpf_v
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct bpf_iter__task));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct linux_binprm));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct file));
+	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_init_task_args));
+	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_cpu_release_args));
+	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_sub_attach_args));
+	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_sub_detach_args));
 
 	return btf_nested_type_is_trusted(&env->log, reg, field_name, btf_id, "__safe_trusted");
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted
  2026-08-20  5:20 [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted Tejun Heo
@ 2026-08-20  6:16 ` bot+bpf-ci
  2026-08-20  8:11   ` Tejun Heo
  2026-08-20 14:32 ` Kumar Kartikeya Dwivedi
  2026-08-20 17:50 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: bot+bpf-ci @ 2026-08-20  6:16 UTC (permalink / raw)
  To: tj, ast, daniel
  Cc: andrii, eddyz87, memxor, john.fastabend, bpf, void, arighi,
	changwoo, emil, sched-ext, linux-kernel, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, clm, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

>     bpf: sched_ext: Mark ops argument container pointer fields as trusted
>
>     Walking an unannotated pointer field of a trusted struct yields a bare
>     PTR_TO_BTF_ID in non-sleepable programs, which kfuncs and helpers accept,
>     but PTR_UNTRUSTED in sleepable programs, which they reject. This gets in the
>     way of making ops.init_task() sleepable, which schedulers want for
>     allocations. For example, passing args->cgroup into bpf_cgrp_storage_get()
>     then fails verification and the only recourse is round-tripping through the
>     cgroup ID with bpf_cgroup_from_id().
>
>     The pointer fields in the sched_ext ops argument containers are all pinned
>     by the callers for the duration of the ops calls and are never NULL. Add
>     them to the verifier's trusted-fields whitelist so that they are PTR_TRUSTED
>     in both sleepable and non-sleepable programs.
>
>     Signed-off-by: Tejun Heo <tj@kernel.org>

This looks like a bug fix for verification failures in sleepable programs.
Should this include:

  Fixes: 8195136669661 ("sched_ext: Add cgroup support")


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32336047878

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted
  2026-08-20  6:16 ` bot+bpf-ci
@ 2026-08-20  8:11   ` Tejun Heo
  0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2026-08-20  8:11 UTC (permalink / raw)
  To: bot+bpf-ci
  Cc: ast, daniel, andrii, eddyz87, memxor, john.fastabend, bpf, void,
	arighi, changwoo, emil, sched-ext, linux-kernel, martin.lau,
	yonghong.song, clm, ihor.solodrai

On Thu, Aug 20, 2026 at 06:16:48AM +0000, bot+bpf-ci@kernel.org wrote:
> >     bpf: sched_ext: Mark ops argument container pointer fields as trusted
> >
> >     Walking an unannotated pointer field of a trusted struct yields a bare
> >     PTR_TO_BTF_ID in non-sleepable programs, which kfuncs and helpers accept,
> >     but PTR_UNTRUSTED in sleepable programs, which they reject. This gets in the
> >     way of making ops.init_task() sleepable, which schedulers want for
> >     allocations. For example, passing args->cgroup into bpf_cgrp_storage_get()
> >     then fails verification and the only recourse is round-tripping through the
> >     cgroup ID with bpf_cgroup_from_id().
> >
> >     The pointer fields in the sched_ext ops argument containers are all pinned
> >     by the callers for the duration of the ops calls and are never NULL. Add
> >     them to the verifier's trusted-fields whitelist so that they are PTR_TRUSTED
> >     in both sleepable and non-sleepable programs.
> >
> >     Signed-off-by: Tejun Heo <tj@kernel.org>
> 
> This looks like a bug fix for verification failures in sleepable programs.
> Should this include:
> 
>   Fixes: 8195136669661 ("sched_ext: Add cgroup support")

Nothing has been using it, so not strictly necessary but yeah I don't see
why not.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted
  2026-08-20  5:20 [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted Tejun Heo
  2026-08-20  6:16 ` bot+bpf-ci
@ 2026-08-20 14:32 ` Kumar Kartikeya Dwivedi
  2026-08-20 17:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-08-20 14:32 UTC (permalink / raw)
  To: Tejun Heo, Alexei Starovoitov, Daniel Borkmann
  Cc: Andrii Nakryiko, Eduard Zingerman, John Fastabend, bpf,
	David Vernet, Andrea Righi, Changwoo Min, Emil Tsalapatis,
	sched-ext, linux-kernel

On Thu Aug 20, 2026 at 7:20 AM CEST, Tejun Heo wrote:
> Walking an unannotated pointer field of a trusted struct yields a bare
> PTR_TO_BTF_ID in non-sleepable programs, which kfuncs and helpers accept,
> but PTR_UNTRUSTED in sleepable programs, which they reject. This gets in the
> way of making ops.init_task() sleepable, which schedulers want for
> allocations. For example, passing args->cgroup into bpf_cgrp_storage_get()
> then fails verification and the only recourse is round-tripping through the
> cgroup ID with bpf_cgroup_from_id().
>
> The pointer fields in the sched_ext ops argument containers are all pinned
> by the callers for the duration of the ops calls and are never NULL. Add
> them to the verifier's trusted-fields whitelist so that they are PTR_TRUSTED
> in both sleepable and non-sleepable programs.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

I (or others) will add Fixes tag when applying, no need to respin.

> [...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted
  2026-08-20  5:20 [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted Tejun Heo
  2026-08-20  6:16 ` bot+bpf-ci
  2026-08-20 14:32 ` Kumar Kartikeya Dwivedi
@ 2026-08-20 17:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-20 17:50 UTC (permalink / raw)
  To: Tejun Heo
  Cc: ast, daniel, andrii, eddyz87, memxor, john.fastabend, bpf, void,
	arighi, changwoo, emil, sched-ext, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Kumar Kartikeya Dwivedi <memxor@gmail.com>:

On Wed, 19 Aug 2026 19:20:21 -1000 you wrote:
> Walking an unannotated pointer field of a trusted struct yields a bare
> PTR_TO_BTF_ID in non-sleepable programs, which kfuncs and helpers accept,
> but PTR_UNTRUSTED in sleepable programs, which they reject. This gets in the
> way of making ops.init_task() sleepable, which schedulers want for
> allocations. For example, passing args->cgroup into bpf_cgrp_storage_get()
> then fails verification and the only recourse is round-tripping through the
> cgroup ID with bpf_cgroup_from_id().
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted
    https://git.kernel.org/bpf/bpf-next/c/aed1bf1a352a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-20 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20  5:20 [PATCH bpf-next] bpf: sched_ext: Mark ops argument container pointer fields as trusted Tejun Heo
2026-08-20  6:16 ` bot+bpf-ci
2026-08-20  8:11   ` Tejun Heo
2026-08-20 14:32 ` Kumar Kartikeya Dwivedi
2026-08-20 17:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox