diff mbox series

[bpf] bpf: fix configuration-dependent BTF function references

Message ID 20241213-bpf-cond-ids-v1-1-881849997219@weissschuh.net (mailing list archive)
State Superseded
Commit 00a5acdbf39816ad23b8db3255c366bbc77e69af
Delegated to: BPF
Headers show
Series [bpf] bpf: fix configuration-dependent BTF function references | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for aarch64-gcc / veristat-meta
bpf/vmtest-bpf-VM_Test-13 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-VM_Test-10 success Logs for aarch64-gcc / veristat-kernel
bpf/vmtest-bpf-VM_Test-12 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for s390x-gcc / veristat-kernel
bpf/vmtest-bpf-VM_Test-18 success Logs for s390x-gcc / veristat-meta
bpf/vmtest-bpf-VM_Test-20 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-21 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-VM_Test-30 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-36 success Logs for x86_64-llvm-17 / veristat-kernel
bpf/vmtest-bpf-VM_Test-37 success Logs for x86_64-llvm-17 / veristat-meta
bpf/vmtest-bpf-VM_Test-31 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-26 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for x86_64-gcc / veristat-kernel / x86_64-gcc veristat_kernel
bpf/vmtest-bpf-VM_Test-29 success Logs for x86_64-gcc / veristat-meta / x86_64-gcc veristat_meta
bpf/vmtest-bpf-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-34 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-35 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-38 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-39 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-VM_Test-44 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-45 success Logs for x86_64-llvm-18 / veristat-kernel
bpf/vmtest-bpf-VM_Test-46 success Logs for x86_64-llvm-18 / veristat-meta
bpf/vmtest-bpf-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-42 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-43 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc

Commit Message

Thomas Weißschuh Dec. 12, 2024, 11 p.m. UTC
These BTF functions are not available unconditionally,
only reference them when they are available.

Avoid the following build warnings:

  BTF     .tmp_vmlinux1.btf.o
btf_encoder__tag_kfunc: failed to find kfunc 'bpf_send_signal_task' in BTF
btf_encoder__tag_kfuncs: failed to tag kfunc 'bpf_send_signal_task'
  NM      .tmp_vmlinux1.syms
  KSYMS   .tmp_vmlinux1.kallsyms.S
  AS      .tmp_vmlinux1.kallsyms.o
  LD      .tmp_vmlinux2
  NM      .tmp_vmlinux2.syms
  KSYMS   .tmp_vmlinux2.kallsyms.S
  AS      .tmp_vmlinux2.kallsyms.o
  LD      vmlinux
  BTFIDS  vmlinux
WARN: resolve_btfids: unresolved symbol prog_test_ref_kfunc
WARN: resolve_btfids: unresolved symbol bpf_crypto_ctx
WARN: resolve_btfids: unresolved symbol bpf_send_signal_task
WARN: resolve_btfids: unresolved symbol bpf_modify_return_test_tp
WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_xdp
WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_skb

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 kernel/bpf/helpers.c  | 4 ++++
 kernel/bpf/verifier.c | 8 ++++++++
 2 files changed, 12 insertions(+)


---
base-commit: 5d287a7de3c95b78946e71d17d15ec9c87fffe7f
change-id: 20241212-bpf-cond-ids-9bfbc64dd77b

Best regards,

Comments

Andrii Nakryiko Dec. 12, 2024, 11:27 p.m. UTC | #1
On Thu, Dec 12, 2024 at 3:00 PM Thomas Weißschuh <linux@weissschuh.net> wrote:
>
> These BTF functions are not available unconditionally,
> only reference them when they are available.
>
> Avoid the following build warnings:
>
>   BTF     .tmp_vmlinux1.btf.o
> btf_encoder__tag_kfunc: failed to find kfunc 'bpf_send_signal_task' in BTF
> btf_encoder__tag_kfuncs: failed to tag kfunc 'bpf_send_signal_task'
>   NM      .tmp_vmlinux1.syms
>   KSYMS   .tmp_vmlinux1.kallsyms.S
>   AS      .tmp_vmlinux1.kallsyms.o
>   LD      .tmp_vmlinux2
>   NM      .tmp_vmlinux2.syms
>   KSYMS   .tmp_vmlinux2.kallsyms.S
>   AS      .tmp_vmlinux2.kallsyms.o
>   LD      vmlinux
>   BTFIDS  vmlinux
> WARN: resolve_btfids: unresolved symbol prog_test_ref_kfunc
> WARN: resolve_btfids: unresolved symbol bpf_crypto_ctx
> WARN: resolve_btfids: unresolved symbol bpf_send_signal_task
> WARN: resolve_btfids: unresolved symbol bpf_modify_return_test_tp
> WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_xdp
> WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_skb
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  kernel/bpf/helpers.c  | 4 ++++
>  kernel/bpf/verifier.c | 8 ++++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 751c150f9e1cd7f56e6a2b68a7ebb4ae89a30d2d..5edf5436a7804816b7dcf1bbef2624d71a985f20 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -3089,7 +3089,9 @@ BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
>  BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL)
>  BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL)
>  BTF_ID_FLAGS(func, bpf_throw)
> +#ifdef CONFIG_BPF_EVENTS
>  BTF_ID_FLAGS(func, bpf_send_signal_task, KF_TRUSTED_ARGS)
> +#endif
>  BTF_KFUNCS_END(generic_btf_ids)
>
>  static const struct btf_kfunc_id_set generic_kfunc_set = {
> @@ -3135,7 +3137,9 @@ BTF_ID_FLAGS(func, bpf_dynptr_is_null)
>  BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly)
>  BTF_ID_FLAGS(func, bpf_dynptr_size)
>  BTF_ID_FLAGS(func, bpf_dynptr_clone)
> +#ifdef CONFIG_NET
>  BTF_ID_FLAGS(func, bpf_modify_return_test_tp)
> +#endif

It makes little sense to have bpf_prog_test_run_tracing() and
bpf_modify_return_test_tp() depend on CONFIG_NET... It's just
historically where BPF_PROG_TEST_RUN functionality was implemented,
but it seems like we need to move bpf_prog_test_run_tracing() and
other tracing-related testing stuff into kernel/trace/bpf_trace.c or
somewhere under kernel/bpf/ (core.c? helpers.c?)

>  BTF_ID_FLAGS(func, bpf_wq_init)
>  BTF_ID_FLAGS(func, bpf_wq_set_callback_impl)
>  BTF_ID_FLAGS(func, bpf_wq_start)
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 5e541339b2f6d1870561033fd55cca7144db14bc..77bbf58418fee7533bce539c8e005d2342ee1a48 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -5526,7 +5526,9 @@ static bool in_rcu_cs(struct bpf_verifier_env *env)
>
>  /* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */
>  BTF_SET_START(rcu_protected_types)
> +#ifdef CONFIG_NET
>  BTF_ID(struct, prog_test_ref_kfunc)
> +#endif
>  #ifdef CONFIG_CGROUPS
>  BTF_ID(struct, cgroup)
>  #endif
> @@ -5534,7 +5536,9 @@ BTF_ID(struct, cgroup)
>  BTF_ID(struct, bpf_cpumask)
>  #endif
>  BTF_ID(struct, task_struct)
> +#ifdef CONFIG_CRYPTO
>  BTF_ID(struct, bpf_crypto_ctx)
> +#endif
>  BTF_SET_END(rcu_protected_types)
>
>  static bool rcu_protected_object(const struct btf *btf, u32 btf_id)
> @@ -11529,8 +11533,10 @@ BTF_ID(func, bpf_rdonly_cast)
>  BTF_ID(func, bpf_rbtree_remove)
>  BTF_ID(func, bpf_rbtree_add_impl)
>  BTF_ID(func, bpf_rbtree_first)
> +#ifdef CONFIG_NET
>  BTF_ID(func, bpf_dynptr_from_skb)
>  BTF_ID(func, bpf_dynptr_from_xdp)
> +#endif
>  BTF_ID(func, bpf_dynptr_slice)
>  BTF_ID(func, bpf_dynptr_slice_rdwr)
>  BTF_ID(func, bpf_dynptr_clone)
> @@ -11558,8 +11564,10 @@ BTF_ID(func, bpf_rcu_read_unlock)
>  BTF_ID(func, bpf_rbtree_remove)
>  BTF_ID(func, bpf_rbtree_add_impl)
>  BTF_ID(func, bpf_rbtree_first)
> +#ifdef CONFIG_NET
>  BTF_ID(func, bpf_dynptr_from_skb)
>  BTF_ID(func, bpf_dynptr_from_xdp)
> +#endif
>  BTF_ID(func, bpf_dynptr_slice)
>  BTF_ID(func, bpf_dynptr_slice_rdwr)
>  BTF_ID(func, bpf_dynptr_clone)
>
> ---
> base-commit: 5d287a7de3c95b78946e71d17d15ec9c87fffe7f
> change-id: 20241212-bpf-cond-ids-9bfbc64dd77b
>
> Best regards,
> --
> Thomas Weißschuh <linux@weissschuh.net>
>
Thomas Weißschuh Dec. 12, 2024, 11:37 p.m. UTC | #2
On 2024-12-12 15:27:12-0800, Andrii Nakryiko wrote:
> On Thu, Dec 12, 2024 at 3:00 PM Thomas Weißschuh <linux@weissschuh.net> wrote:
> >
> > These BTF functions are not available unconditionally,
> > only reference them when they are available.
> >
> > Avoid the following build warnings:
> >
> >   BTF     .tmp_vmlinux1.btf.o
> > btf_encoder__tag_kfunc: failed to find kfunc 'bpf_send_signal_task' in BTF
> > btf_encoder__tag_kfuncs: failed to tag kfunc 'bpf_send_signal_task'
> >   NM      .tmp_vmlinux1.syms
> >   KSYMS   .tmp_vmlinux1.kallsyms.S
> >   AS      .tmp_vmlinux1.kallsyms.o
> >   LD      .tmp_vmlinux2
> >   NM      .tmp_vmlinux2.syms
> >   KSYMS   .tmp_vmlinux2.kallsyms.S
> >   AS      .tmp_vmlinux2.kallsyms.o
> >   LD      vmlinux
> >   BTFIDS  vmlinux
> > WARN: resolve_btfids: unresolved symbol prog_test_ref_kfunc
> > WARN: resolve_btfids: unresolved symbol bpf_crypto_ctx
> > WARN: resolve_btfids: unresolved symbol bpf_send_signal_task
> > WARN: resolve_btfids: unresolved symbol bpf_modify_return_test_tp
> > WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_xdp
> > WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_skb
> >
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> >  kernel/bpf/helpers.c  | 4 ++++
> >  kernel/bpf/verifier.c | 8 ++++++++
> >  2 files changed, 12 insertions(+)
> >
> > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> > index 751c150f9e1cd7f56e6a2b68a7ebb4ae89a30d2d..5edf5436a7804816b7dcf1bbef2624d71a985f20 100644
> > --- a/kernel/bpf/helpers.c
> > +++ b/kernel/bpf/helpers.c
> > @@ -3089,7 +3089,9 @@ BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
> >  BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL)
> >  BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL)
> >  BTF_ID_FLAGS(func, bpf_throw)
> > +#ifdef CONFIG_BPF_EVENTS
> >  BTF_ID_FLAGS(func, bpf_send_signal_task, KF_TRUSTED_ARGS)
> > +#endif
> >  BTF_KFUNCS_END(generic_btf_ids)
> >
> >  static const struct btf_kfunc_id_set generic_kfunc_set = {
> > @@ -3135,7 +3137,9 @@ BTF_ID_FLAGS(func, bpf_dynptr_is_null)
> >  BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly)
> >  BTF_ID_FLAGS(func, bpf_dynptr_size)
> >  BTF_ID_FLAGS(func, bpf_dynptr_clone)
> > +#ifdef CONFIG_NET
> >  BTF_ID_FLAGS(func, bpf_modify_return_test_tp)
> > +#endif
> 
> It makes little sense to have bpf_prog_test_run_tracing() and
> bpf_modify_return_test_tp() depend on CONFIG_NET... It's just
> historically where BPF_PROG_TEST_RUN functionality was implemented,
> but it seems like we need to move bpf_prog_test_run_tracing() and
> other tracing-related testing stuff into kernel/trace/bpf_trace.c or
> somewhere under kernel/bpf/ (core.c? helpers.c?)

I agree. But today these are the config values which are in effect.
When the functions get moved, the config values can be adapted.
With my commit "kbuild/btf: Propagate CONFIG_WERROR to resolve_btfids"
in bpf-next the warnings can actually become errors.
So I'd propose to apply this fix to avoid issues in the near future and
then do a proper move without any urgency.

> >  BTF_ID_FLAGS(func, bpf_wq_init)
> >  BTF_ID_FLAGS(func, bpf_wq_set_callback_impl)
> >  BTF_ID_FLAGS(func, bpf_wq_start)
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 5e541339b2f6d1870561033fd55cca7144db14bc..77bbf58418fee7533bce539c8e005d2342ee1a48 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -5526,7 +5526,9 @@ static bool in_rcu_cs(struct bpf_verifier_env *env)
> >
> >  /* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */
> >  BTF_SET_START(rcu_protected_types)
> > +#ifdef CONFIG_NET
> >  BTF_ID(struct, prog_test_ref_kfunc)
> > +#endif
> >  #ifdef CONFIG_CGROUPS
> >  BTF_ID(struct, cgroup)
> >  #endif
> > @@ -5534,7 +5536,9 @@ BTF_ID(struct, cgroup)
> >  BTF_ID(struct, bpf_cpumask)
> >  #endif
> >  BTF_ID(struct, task_struct)
> > +#ifdef CONFIG_CRYPTO
> >  BTF_ID(struct, bpf_crypto_ctx)
> > +#endif
> >  BTF_SET_END(rcu_protected_types)
> >
> >  static bool rcu_protected_object(const struct btf *btf, u32 btf_id)
> > @@ -11529,8 +11533,10 @@ BTF_ID(func, bpf_rdonly_cast)
> >  BTF_ID(func, bpf_rbtree_remove)
> >  BTF_ID(func, bpf_rbtree_add_impl)
> >  BTF_ID(func, bpf_rbtree_first)
> > +#ifdef CONFIG_NET
> >  BTF_ID(func, bpf_dynptr_from_skb)
> >  BTF_ID(func, bpf_dynptr_from_xdp)
> > +#endif
> >  BTF_ID(func, bpf_dynptr_slice)
> >  BTF_ID(func, bpf_dynptr_slice_rdwr)
> >  BTF_ID(func, bpf_dynptr_clone)
> > @@ -11558,8 +11564,10 @@ BTF_ID(func, bpf_rcu_read_unlock)
> >  BTF_ID(func, bpf_rbtree_remove)
> >  BTF_ID(func, bpf_rbtree_add_impl)
> >  BTF_ID(func, bpf_rbtree_first)
> > +#ifdef CONFIG_NET
> >  BTF_ID(func, bpf_dynptr_from_skb)
> >  BTF_ID(func, bpf_dynptr_from_xdp)
> > +#endif
> >  BTF_ID(func, bpf_dynptr_slice)
> >  BTF_ID(func, bpf_dynptr_slice_rdwr)
> >  BTF_ID(func, bpf_dynptr_clone)
> >
> > ---
> > base-commit: 5d287a7de3c95b78946e71d17d15ec9c87fffe7f
> > change-id: 20241212-bpf-cond-ids-9bfbc64dd77b
> >
> > Best regards,
> > --
> > Thomas Weißschuh <linux@weissschuh.net>
> >
Andrii Nakryiko Dec. 13, 2024, 10:37 p.m. UTC | #3
On Thu, Dec 12, 2024 at 3:37 PM Thomas Weißschuh <linux@weissschuh.net> wrote:
>
> On 2024-12-12 15:27:12-0800, Andrii Nakryiko wrote:
> > On Thu, Dec 12, 2024 at 3:00 PM Thomas Weißschuh <linux@weissschuh.net> wrote:
> > >
> > > These BTF functions are not available unconditionally,
> > > only reference them when they are available.
> > >
> > > Avoid the following build warnings:
> > >
> > >   BTF     .tmp_vmlinux1.btf.o
> > > btf_encoder__tag_kfunc: failed to find kfunc 'bpf_send_signal_task' in BTF
> > > btf_encoder__tag_kfuncs: failed to tag kfunc 'bpf_send_signal_task'
> > >   NM      .tmp_vmlinux1.syms
> > >   KSYMS   .tmp_vmlinux1.kallsyms.S
> > >   AS      .tmp_vmlinux1.kallsyms.o
> > >   LD      .tmp_vmlinux2
> > >   NM      .tmp_vmlinux2.syms
> > >   KSYMS   .tmp_vmlinux2.kallsyms.S
> > >   AS      .tmp_vmlinux2.kallsyms.o
> > >   LD      vmlinux
> > >   BTFIDS  vmlinux
> > > WARN: resolve_btfids: unresolved symbol prog_test_ref_kfunc
> > > WARN: resolve_btfids: unresolved symbol bpf_crypto_ctx
> > > WARN: resolve_btfids: unresolved symbol bpf_send_signal_task
> > > WARN: resolve_btfids: unresolved symbol bpf_modify_return_test_tp
> > > WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_xdp
> > > WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_skb
> > >
> > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > ---
> > >  kernel/bpf/helpers.c  | 4 ++++
> > >  kernel/bpf/verifier.c | 8 ++++++++
> > >  2 files changed, 12 insertions(+)
> > >
> > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> > > index 751c150f9e1cd7f56e6a2b68a7ebb4ae89a30d2d..5edf5436a7804816b7dcf1bbef2624d71a985f20 100644
> > > --- a/kernel/bpf/helpers.c
> > > +++ b/kernel/bpf/helpers.c
> > > @@ -3089,7 +3089,9 @@ BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
> > >  BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL)
> > >  BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL)
> > >  BTF_ID_FLAGS(func, bpf_throw)
> > > +#ifdef CONFIG_BPF_EVENTS
> > >  BTF_ID_FLAGS(func, bpf_send_signal_task, KF_TRUSTED_ARGS)
> > > +#endif
> > >  BTF_KFUNCS_END(generic_btf_ids)
> > >
> > >  static const struct btf_kfunc_id_set generic_kfunc_set = {
> > > @@ -3135,7 +3137,9 @@ BTF_ID_FLAGS(func, bpf_dynptr_is_null)
> > >  BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly)
> > >  BTF_ID_FLAGS(func, bpf_dynptr_size)
> > >  BTF_ID_FLAGS(func, bpf_dynptr_clone)
> > > +#ifdef CONFIG_NET
> > >  BTF_ID_FLAGS(func, bpf_modify_return_test_tp)
> > > +#endif
> >
> > It makes little sense to have bpf_prog_test_run_tracing() and
> > bpf_modify_return_test_tp() depend on CONFIG_NET... It's just
> > historically where BPF_PROG_TEST_RUN functionality was implemented,
> > but it seems like we need to move bpf_prog_test_run_tracing() and
> > other tracing-related testing stuff into kernel/trace/bpf_trace.c or
> > somewhere under kernel/bpf/ (core.c? helpers.c?)
>
> I agree. But today these are the config values which are in effect.
> When the functions get moved, the config values can be adapted.
> With my commit "kbuild/btf: Propagate CONFIG_WERROR to resolve_btfids"
> in bpf-next the warnings can actually become errors.
> So I'd propose to apply this fix to avoid issues in the near future and
> then do a proper move without any urgency.
>

Fair enough.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

> > >  BTF_ID_FLAGS(func, bpf_wq_init)
> > >  BTF_ID_FLAGS(func, bpf_wq_set_callback_impl)
> > >  BTF_ID_FLAGS(func, bpf_wq_start)
> > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > > index 5e541339b2f6d1870561033fd55cca7144db14bc..77bbf58418fee7533bce539c8e005d2342ee1a48 100644
> > > --- a/kernel/bpf/verifier.c
> > > +++ b/kernel/bpf/verifier.c
> > > @@ -5526,7 +5526,9 @@ static bool in_rcu_cs(struct bpf_verifier_env *env)
> > >
> > >  /* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */
> > >  BTF_SET_START(rcu_protected_types)
> > > +#ifdef CONFIG_NET
> > >  BTF_ID(struct, prog_test_ref_kfunc)
> > > +#endif
> > >  #ifdef CONFIG_CGROUPS
> > >  BTF_ID(struct, cgroup)
> > >  #endif
> > > @@ -5534,7 +5536,9 @@ BTF_ID(struct, cgroup)
> > >  BTF_ID(struct, bpf_cpumask)
> > >  #endif
> > >  BTF_ID(struct, task_struct)
> > > +#ifdef CONFIG_CRYPTO
> > >  BTF_ID(struct, bpf_crypto_ctx)
> > > +#endif
> > >  BTF_SET_END(rcu_protected_types)
> > >
> > >  static bool rcu_protected_object(const struct btf *btf, u32 btf_id)
> > > @@ -11529,8 +11533,10 @@ BTF_ID(func, bpf_rdonly_cast)
> > >  BTF_ID(func, bpf_rbtree_remove)
> > >  BTF_ID(func, bpf_rbtree_add_impl)
> > >  BTF_ID(func, bpf_rbtree_first)
> > > +#ifdef CONFIG_NET
> > >  BTF_ID(func, bpf_dynptr_from_skb)
> > >  BTF_ID(func, bpf_dynptr_from_xdp)
> > > +#endif
> > >  BTF_ID(func, bpf_dynptr_slice)
> > >  BTF_ID(func, bpf_dynptr_slice_rdwr)
> > >  BTF_ID(func, bpf_dynptr_clone)
> > > @@ -11558,8 +11564,10 @@ BTF_ID(func, bpf_rcu_read_unlock)
> > >  BTF_ID(func, bpf_rbtree_remove)
> > >  BTF_ID(func, bpf_rbtree_add_impl)
> > >  BTF_ID(func, bpf_rbtree_first)
> > > +#ifdef CONFIG_NET
> > >  BTF_ID(func, bpf_dynptr_from_skb)
> > >  BTF_ID(func, bpf_dynptr_from_xdp)
> > > +#endif
> > >  BTF_ID(func, bpf_dynptr_slice)
> > >  BTF_ID(func, bpf_dynptr_slice_rdwr)
> > >  BTF_ID(func, bpf_dynptr_clone)
> > >
> > > ---
> > > base-commit: 5d287a7de3c95b78946e71d17d15ec9c87fffe7f
> > > change-id: 20241212-bpf-cond-ids-9bfbc64dd77b
> > >
> > > Best regards,
> > > --
> > > Thomas Weißschuh <linux@weissschuh.net>
> > >
patchwork-bot+netdevbpf@kernel.org Dec. 13, 2024, 11:10 p.m. UTC | #4
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Fri, 13 Dec 2024 00:00:30 +0100 you wrote:
> These BTF functions are not available unconditionally,
> only reference them when they are available.
> 
> Avoid the following build warnings:
> 
>   BTF     .tmp_vmlinux1.btf.o
> btf_encoder__tag_kfunc: failed to find kfunc 'bpf_send_signal_task' in BTF
> btf_encoder__tag_kfuncs: failed to tag kfunc 'bpf_send_signal_task'
>   NM      .tmp_vmlinux1.syms
>   KSYMS   .tmp_vmlinux1.kallsyms.S
>   AS      .tmp_vmlinux1.kallsyms.o
>   LD      .tmp_vmlinux2
>   NM      .tmp_vmlinux2.syms
>   KSYMS   .tmp_vmlinux2.kallsyms.S
>   AS      .tmp_vmlinux2.kallsyms.o
>   LD      vmlinux
>   BTFIDS  vmlinux
> WARN: resolve_btfids: unresolved symbol prog_test_ref_kfunc
> WARN: resolve_btfids: unresolved symbol bpf_crypto_ctx
> WARN: resolve_btfids: unresolved symbol bpf_send_signal_task
> WARN: resolve_btfids: unresolved symbol bpf_modify_return_test_tp
> WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_xdp
> WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_skb
> 
> [...]

Here is the summary with links:
  - [bpf] bpf: fix configuration-dependent BTF function references
    https://git.kernel.org/bpf/bpf-next/c/00a5acdbf398

You are awesome, thank you!
Alexei Starovoitov Dec. 18, 2024, 9:18 p.m. UTC | #5
On Fri, Dec 13, 2024 at 3:10 PM <patchwork-bot+netdevbpf@kernel.org> wrote:
>
> Hello:
>
> This patch was applied to bpf/bpf-next.git (master)
> by Andrii Nakryiko <andrii@kernel.org>:
>
> On Fri, 13 Dec 2024 00:00:30 +0100 you wrote:
> > These BTF functions are not available unconditionally,
> > only reference them when they are available.
> >
> > Avoid the following build warnings:
> >
> >   BTF     .tmp_vmlinux1.btf.o
> > btf_encoder__tag_kfunc: failed to find kfunc 'bpf_send_signal_task' in BTF
> > btf_encoder__tag_kfuncs: failed to tag kfunc 'bpf_send_signal_task'
> >   NM      .tmp_vmlinux1.syms
> >   KSYMS   .tmp_vmlinux1.kallsyms.S
> >   AS      .tmp_vmlinux1.kallsyms.o
> >   LD      .tmp_vmlinux2
> >   NM      .tmp_vmlinux2.syms
> >   KSYMS   .tmp_vmlinux2.kallsyms.S
> >   AS      .tmp_vmlinux2.kallsyms.o
> >   LD      vmlinux
> >   BTFIDS  vmlinux
> > WARN: resolve_btfids: unresolved symbol prog_test_ref_kfunc
> > WARN: resolve_btfids: unresolved symbol bpf_crypto_ctx
> > WARN: resolve_btfids: unresolved symbol bpf_send_signal_task
> > WARN: resolve_btfids: unresolved symbol bpf_modify_return_test_tp
> > WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_xdp
> > WARN: resolve_btfids: unresolved symbol bpf_dynptr_from_skb
> >
> > [...]
>
> Here is the summary with links:
>   - [bpf] bpf: fix configuration-dependent BTF function references
>     https://git.kernel.org/bpf/bpf-next/c/00a5acdbf398

Just noticed that this is broken.
The #ifdef CONFIG_NET part in special_kfunc_list()
needs to match positions in enum special_kfunc_type.
BTF_ID_UNUSED must be used when !CONFIG_NET.

Pls send the fix.
diff mbox series

Patch

diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 751c150f9e1cd7f56e6a2b68a7ebb4ae89a30d2d..5edf5436a7804816b7dcf1bbef2624d71a985f20 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -3089,7 +3089,9 @@  BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_throw)
+#ifdef CONFIG_BPF_EVENTS
 BTF_ID_FLAGS(func, bpf_send_signal_task, KF_TRUSTED_ARGS)
+#endif
 BTF_KFUNCS_END(generic_btf_ids)
 
 static const struct btf_kfunc_id_set generic_kfunc_set = {
@@ -3135,7 +3137,9 @@  BTF_ID_FLAGS(func, bpf_dynptr_is_null)
 BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly)
 BTF_ID_FLAGS(func, bpf_dynptr_size)
 BTF_ID_FLAGS(func, bpf_dynptr_clone)
+#ifdef CONFIG_NET
 BTF_ID_FLAGS(func, bpf_modify_return_test_tp)
+#endif
 BTF_ID_FLAGS(func, bpf_wq_init)
 BTF_ID_FLAGS(func, bpf_wq_set_callback_impl)
 BTF_ID_FLAGS(func, bpf_wq_start)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5e541339b2f6d1870561033fd55cca7144db14bc..77bbf58418fee7533bce539c8e005d2342ee1a48 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5526,7 +5526,9 @@  static bool in_rcu_cs(struct bpf_verifier_env *env)
 
 /* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */
 BTF_SET_START(rcu_protected_types)
+#ifdef CONFIG_NET
 BTF_ID(struct, prog_test_ref_kfunc)
+#endif
 #ifdef CONFIG_CGROUPS
 BTF_ID(struct, cgroup)
 #endif
@@ -5534,7 +5536,9 @@  BTF_ID(struct, cgroup)
 BTF_ID(struct, bpf_cpumask)
 #endif
 BTF_ID(struct, task_struct)
+#ifdef CONFIG_CRYPTO
 BTF_ID(struct, bpf_crypto_ctx)
+#endif
 BTF_SET_END(rcu_protected_types)
 
 static bool rcu_protected_object(const struct btf *btf, u32 btf_id)
@@ -11529,8 +11533,10 @@  BTF_ID(func, bpf_rdonly_cast)
 BTF_ID(func, bpf_rbtree_remove)
 BTF_ID(func, bpf_rbtree_add_impl)
 BTF_ID(func, bpf_rbtree_first)
+#ifdef CONFIG_NET
 BTF_ID(func, bpf_dynptr_from_skb)
 BTF_ID(func, bpf_dynptr_from_xdp)
+#endif
 BTF_ID(func, bpf_dynptr_slice)
 BTF_ID(func, bpf_dynptr_slice_rdwr)
 BTF_ID(func, bpf_dynptr_clone)
@@ -11558,8 +11564,10 @@  BTF_ID(func, bpf_rcu_read_unlock)
 BTF_ID(func, bpf_rbtree_remove)
 BTF_ID(func, bpf_rbtree_add_impl)
 BTF_ID(func, bpf_rbtree_first)
+#ifdef CONFIG_NET
 BTF_ID(func, bpf_dynptr_from_skb)
 BTF_ID(func, bpf_dynptr_from_xdp)
+#endif
 BTF_ID(func, bpf_dynptr_slice)
 BTF_ID(func, bpf_dynptr_slice_rdwr)
 BTF_ID(func, bpf_dynptr_clone)