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

bpf: Use BTF_ID to resolve bpf_ctx_convert struct

This way the ID is resolved during compile time,
and we can remove the runtime name search.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200711215329.41165-7-jolsa@kernel.org

authored by

Jiri Olsa and committed by
Alexei Starovoitov
49f4e672 138b9a05

+6 -8
+6 -8
kernel/bpf/btf.c
··· 18 18 #include <linux/sort.h> 19 19 #include <linux/bpf_verifier.h> 20 20 #include <linux/btf.h> 21 + #include <linux/btf_ids.h> 21 22 #include <linux/skmsg.h> 22 23 #include <linux/perf_event.h> 23 24 #include <net/sock.h> ··· 3622 3621 return kern_ctx_type->type; 3623 3622 } 3624 3623 3624 + BTF_ID_LIST(bpf_ctx_convert_btf_id) 3625 + BTF_ID(struct, bpf_ctx_convert) 3626 + 3625 3627 struct btf *btf_parse_vmlinux(void) 3626 3628 { 3627 3629 struct btf_verifier_env *env = NULL; 3628 3630 struct bpf_verifier_log *log; 3629 3631 struct btf *btf = NULL; 3630 - int err, btf_id; 3632 + int err; 3631 3633 3632 3634 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); 3633 3635 if (!env) ··· 3663 3659 if (err) 3664 3660 goto errout; 3665 3661 3666 - /* find struct bpf_ctx_convert for type checking later */ 3667 - btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT); 3668 - if (btf_id < 0) { 3669 - err = btf_id; 3670 - goto errout; 3671 - } 3672 3662 /* btf_parse_vmlinux() runs under bpf_verifier_lock */ 3673 - bpf_ctx_convert.t = btf_type_by_id(btf, btf_id); 3663 + bpf_ctx_convert.t = btf_type_by_id(btf, bpf_ctx_convert_btf_id[0]); 3674 3664 3675 3665 /* find bpf map structs for map_ptr access checking */ 3676 3666 err = btf_vmlinux_map_ids_init(btf, log);