Skip to content

Commit 49f4e67

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
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
1 parent 138b9a0 commit 49f4e67

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎kernel/bpf/btf.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/sort.h>
1919
#include <linux/bpf_verifier.h>
2020
#include <linux/btf.h>
21+
#include <linux/btf_ids.h>
2122
#include <linux/skmsg.h>
2223
#include <linux/perf_event.h>
2324
#include <net/sock.h>
@@ -3621,12 +3622,15 @@ static int btf_translate_to_vmlinux(struct bpf_verifier_log *log,
36213622
return kern_ctx_type->type;
36223623
}
36233624

3625+
BTF_ID_LIST(bpf_ctx_convert_btf_id)
3626+
BTF_ID(struct, bpf_ctx_convert)
3627+
36243628
struct btf *btf_parse_vmlinux(void)
36253629
{
36263630
struct btf_verifier_env *env = NULL;
36273631
struct bpf_verifier_log *log;
36283632
struct btf *btf = NULL;
3629-
int err, btf_id;
3633+
int err;
36303634

36313635
env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN);
36323636
if (!env)
@@ -3659,14 +3663,8 @@ struct btf *btf_parse_vmlinux(void)
36593663
if (err)
36603664
goto errout;
36613665

3662-
/* find struct bpf_ctx_convert for type checking later */
3663-
btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT);
3664-
if (btf_id < 0) {
3665-
err = btf_id;
3666-
goto errout;
3667-
}
36683666
/* btf_parse_vmlinux() runs under bpf_verifier_lock */
3669-
bpf_ctx_convert.t = btf_type_by_id(btf, btf_id);
3667+
bpf_ctx_convert.t = btf_type_by_id(btf, bpf_ctx_convert_btf_id[0]);
36703668

36713669
/* find bpf map structs for map_ptr access checking */
36723670
err = btf_vmlinux_map_ids_init(btf, log);

0 commit comments

Comments
 (0)