Re: [PATCH bpf-next v1 5/8] bpf: Re-define bpf_wq_set_callback as magic kfunc

Eduard Zingerman
2025-10-30T00:16:20Z

On Wed, 2025-10-29 at 12:01 -0700, Ihor Solodrai wrote:

[...]

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 67914464d503..3c9e963d879b 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[...]

> @@ -12916,9 +12919,10 @@ static bool is_bpf_throw_kfunc(struct bpf_insn *insn)
> insn->imm == special_kfunc_list[KF_bpf_throw];
> }
>
> -static bool is_bpf_wq_set_callback_impl_kfunc(u32 btf_id)
> +static bool is_bpf_wq_set_callback_kfunc(u32 btf_id)
> {
> - return btf_id == special_kfunc_list[KF_bpf_wq_set_callback_impl];
> + return btf_id == special_kfunc_list[KF_bpf_wq_set_callback_impl] ||
> + btf_id == special_kfunc_list[KF_bpf_wq_set_callback];

If insn->imm is patched in add_kfunc_call() there will be no need to
handle two cases here.

> }
>
> static bool is_callback_calling_kfunc(u32 btf_id)
> @@ -14035,7 +14039,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> meta.r0_rdonly = false;
> }
>
> - if (is_bpf_wq_set_callback_impl_kfunc(meta.func_id)) {
> + if (is_bpf_wq_set_callback_kfunc(meta.func_id)) {
> err = push_callback_call(env, insn, insn_idx, meta.subprogno,
> set_timer_callback_state);
> if (err) {
> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> index 2cd9165c7348..68a49b1f77ae 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h

Nit: The tests won't fail with the above changes, right?
If so, we usually ship changes to selftests in separate patches.

> @@ -580,11 +580,6 @@ extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym;
>
> extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
> extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
> -extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
> - int (callback_fn)(void *map, int *key, void *value),
> - unsigned int flags__k, void *aux__ign) __ksym;
> -#define bpf_wq_set_callback(timer, cb, flags) \
> - bpf_wq_set_callback_impl(timer, cb, flags, NULL)

...