Re: [PATCH sched_ext/for-6.15 v3 3/5] sched_ext: Add scx_kfunc_ids_ops_context_sensitive for unified filtering of context-sensitive SCX kfuncs
From: Alexei Starovoitov
Date: Fri Feb 28 2025 - 18:06:57 EST
On Fri, Feb 28, 2025 at 1:31 PM Tejun Heo <tj@xxxxxxxxxx> wrote:
>
> Hello,
>
> On Thu, Feb 27, 2025 at 06:34:37PM -0800, Alexei Starovoitov wrote:
> > > Hmm... would that mean a non-sched_ext bpf prog would be able to call e.g.
> > > scx_bpf_dsq_insert()?
> >
> > Not as far as I can tell.
> > scx_kfunc_ids_unlocked[] doesn't include scx_bpf_dsq_insert.
> > It's part of scx_kfunc_ids_enqueue_dispatch[].
> >
> > So this bit in patch 3 enables it:
> > + if ((flags & SCX_OPS_KF_ENQUEUE) &&
> > + btf_id_set8_contains(&scx_kfunc_ids_enqueue_dispatch, kfunc_id))
> >
> > and in patch 2:
> > + [SCX_OP_IDX(enqueue)] = SCX_OPS_KF_ENQUEUE,
> >
> > So scx_bpf_dsq_insert() kfunc can only be called out
> > of enqueue() sched-ext hook.
> >
> > So the restriction is still the same. afaict.
>
> Hmm... maybe I'm missing something:
>
> static int scx_kfunc_ids_ops_context_sensitive_filter(const struct bpf_prog *prog, u32 kfunc_id)
> {
> u32 moff, flags;
>
> // allow non-context sensitive kfuncs
> if (!btf_id_set8_contains(&scx_kfunc_ids_ops_context_sensitive, kfunc_id))
> return 0;
>
> // allow unlocked to be called form all SYSCALL progs
> if (prog->type == BPF_PROG_TYPE_SYSCALL &&
> btf_id_set8_contains(&scx_kfunc_ids_unlocked, kfunc_id))
> return 0;
>
> // *** HERE, allow if the prog is not SCX ***
> if (prog->type == BPF_PROG_TYPE_STRUCT_OPS &&
> prog->aux->st_ops != &bpf_sched_ext_ops)
Ohh. You're right. My bad.
Here it probably needs
&& !!btf_id_set8_contains(&scx_kfunc_ids_ops_context_sensitive
since later scx_kfunc_set_ops_context_sensitive
is registered for all of struct-ops.