Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Fix configuration-dependent BTF function references

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>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20241213-bpf-cond-ids-v1-1-881849997219@weissschuh.net

authored by

Thomas Weißschuh and committed by
Andrii Nakryiko
00a5acdb 3d1af4bd

+12
+4
kernel/bpf/helpers.c
··· 3104 3104 BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL) 3105 3105 BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL) 3106 3106 BTF_ID_FLAGS(func, bpf_throw) 3107 + #ifdef CONFIG_BPF_EVENTS 3107 3108 BTF_ID_FLAGS(func, bpf_send_signal_task, KF_TRUSTED_ARGS) 3109 + #endif 3108 3110 BTF_KFUNCS_END(generic_btf_ids) 3109 3111 3110 3112 static const struct btf_kfunc_id_set generic_kfunc_set = { ··· 3152 3150 BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly) 3153 3151 BTF_ID_FLAGS(func, bpf_dynptr_size) 3154 3152 BTF_ID_FLAGS(func, bpf_dynptr_clone) 3153 + #ifdef CONFIG_NET 3155 3154 BTF_ID_FLAGS(func, bpf_modify_return_test_tp) 3155 + #endif 3156 3156 BTF_ID_FLAGS(func, bpf_wq_init) 3157 3157 BTF_ID_FLAGS(func, bpf_wq_set_callback_impl) 3158 3158 BTF_ID_FLAGS(func, bpf_wq_start)
+8
kernel/bpf/verifier.c
··· 5681 5681 5682 5682 /* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */ 5683 5683 BTF_SET_START(rcu_protected_types) 5684 + #ifdef CONFIG_NET 5684 5685 BTF_ID(struct, prog_test_ref_kfunc) 5686 + #endif 5685 5687 #ifdef CONFIG_CGROUPS 5686 5688 BTF_ID(struct, cgroup) 5687 5689 #endif ··· 5691 5689 BTF_ID(struct, bpf_cpumask) 5692 5690 #endif 5693 5691 BTF_ID(struct, task_struct) 5692 + #ifdef CONFIG_CRYPTO 5694 5693 BTF_ID(struct, bpf_crypto_ctx) 5694 + #endif 5695 5695 BTF_SET_END(rcu_protected_types) 5696 5696 5697 5697 static bool rcu_protected_object(const struct btf *btf, u32 btf_id) ··· 11726 11722 BTF_ID(func, bpf_rbtree_remove) 11727 11723 BTF_ID(func, bpf_rbtree_add_impl) 11728 11724 BTF_ID(func, bpf_rbtree_first) 11725 + #ifdef CONFIG_NET 11729 11726 BTF_ID(func, bpf_dynptr_from_skb) 11730 11727 BTF_ID(func, bpf_dynptr_from_xdp) 11728 + #endif 11731 11729 BTF_ID(func, bpf_dynptr_slice) 11732 11730 BTF_ID(func, bpf_dynptr_slice_rdwr) 11733 11731 BTF_ID(func, bpf_dynptr_clone) ··· 11757 11751 BTF_ID(func, bpf_rbtree_remove) 11758 11752 BTF_ID(func, bpf_rbtree_add_impl) 11759 11753 BTF_ID(func, bpf_rbtree_first) 11754 + #ifdef CONFIG_NET 11760 11755 BTF_ID(func, bpf_dynptr_from_skb) 11761 11756 BTF_ID(func, bpf_dynptr_from_xdp) 11757 + #endif 11762 11758 BTF_ID(func, bpf_dynptr_slice) 11763 11759 BTF_ID(func, bpf_dynptr_slice_rdwr) 11764 11760 BTF_ID(func, bpf_dynptr_clone)