Skip to content

Commit a2d0d62

Browse files
rdnaborkmann
authored andcommitted
bpf: Switch btf_parse_vmlinux to btf_find_by_name_kind
btf_parse_vmlinux() implements manual search for struct bpf_ctx_convert since at the time of implementing btf_find_by_name_kind() was not available. Later btf_find_by_name_kind() was introduced in 27ae799 ("bpf: Introduce BPF_PROG_TYPE_STRUCT_OPS"). It provides similar search functionality and can be leveraged in btf_parse_vmlinux(). Do it. Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andriin@fb.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/6e12d5c3e8a3d552925913ef73a695dd1bb27800.1592600985.git.rdna@fb.com
1 parent bb8dc26 commit a2d0d62

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

‎kernel/bpf/btf.c‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ struct btf *btf_parse_vmlinux(void)
35913591
struct btf_verifier_env *env = NULL;
35923592
struct bpf_verifier_log *log;
35933593
struct btf *btf = NULL;
3594-
int err, i;
3594+
int err, btf_id;
35953595

35963596
env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN);
35973597
if (!env)
@@ -3625,24 +3625,13 @@ struct btf *btf_parse_vmlinux(void)
36253625
goto errout;
36263626

36273627
/* find struct bpf_ctx_convert for type checking later */
3628-
for (i = 1; i <= btf->nr_types; i++) {
3629-
const struct btf_type *t;
3630-
const char *tname;
3631-
3632-
t = btf_type_by_id(btf, i);
3633-
if (!__btf_type_is_struct(t))
3634-
continue;
3635-
tname = __btf_name_by_offset(btf, t->name_off);
3636-
if (!strcmp(tname, "bpf_ctx_convert")) {
3637-
/* btf_parse_vmlinux() runs under bpf_verifier_lock */
3638-
bpf_ctx_convert.t = t;
3639-
break;
3640-
}
3641-
}
3642-
if (i > btf->nr_types) {
3643-
err = -ENOENT;
3628+
btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT);
3629+
if (btf_id < 0) {
3630+
err = btf_id;
36443631
goto errout;
36453632
}
3633+
/* btf_parse_vmlinux() runs under bpf_verifier_lock */
3634+
bpf_ctx_convert.t = btf_type_by_id(btf, btf_id);
36463635

36473636
bpf_struct_ops_init(btf, log);
36483637

0 commit comments

Comments
 (0)