Commit a2d0d62f authored by Andrey Ignatov's avatar Andrey Ignatov Committed by Daniel Borkmann

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 27ae7997 ("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: default avatarAndrey Ignatov <rdna@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/6e12d5c3e8a3d552925913ef73a695dd1bb27800.1592600985.git.rdna@fb.com
parent bb8dc269
...@@ -3591,7 +3591,7 @@ struct btf *btf_parse_vmlinux(void) ...@@ -3591,7 +3591,7 @@ struct btf *btf_parse_vmlinux(void)
struct btf_verifier_env *env = NULL; struct btf_verifier_env *env = NULL;
struct bpf_verifier_log *log; struct bpf_verifier_log *log;
struct btf *btf = NULL; struct btf *btf = NULL;
int err, i; int err, btf_id;
env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN);
if (!env) if (!env)
...@@ -3625,24 +3625,13 @@ struct btf *btf_parse_vmlinux(void) ...@@ -3625,24 +3625,13 @@ struct btf *btf_parse_vmlinux(void)
goto errout; goto errout;
/* find struct bpf_ctx_convert for type checking later */ /* find struct bpf_ctx_convert for type checking later */
for (i = 1; i <= btf->nr_types; i++) { btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT);
const struct btf_type *t; if (btf_id < 0) {
const char *tname; err = btf_id;
t = btf_type_by_id(btf, i);
if (!__btf_type_is_struct(t))
continue;
tname = __btf_name_by_offset(btf, t->name_off);
if (!strcmp(tname, "bpf_ctx_convert")) {
/* btf_parse_vmlinux() runs under bpf_verifier_lock */
bpf_ctx_convert.t = t;
break;
}
}
if (i > btf->nr_types) {
err = -ENOENT;
goto errout; goto errout;
} }
/* btf_parse_vmlinux() runs under bpf_verifier_lock */
bpf_ctx_convert.t = btf_type_by_id(btf, btf_id);
bpf_struct_ops_init(btf, log); bpf_struct_ops_init(btf, log);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment