Message ID | 20200625221304.2817194-7-jolsa@kernel.org |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | bpf: Add d_path helper | expand |
On Thu, Jun 25, 2020 at 4:47 PM Jiri Olsa <jolsa@kernel.org> wrote: > > 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> > --- This is a good improvement, but I was thinking about actually simplifying btf_get_prog_ctx_type() logic itself (it also does all this BTF ID resolution). But this is a nice first step, so: Acked-by: Andrii Nakryiko <andriin@fb.com> [...]
On 6/25/20 3:12 PM, Jiri Olsa wrote: > 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> > --- > kernel/bpf/btf.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index 4da6b0770ff9..701a2cb5dfb2 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -18,6 +18,7 @@ > #include <linux/sort.h> > #include <linux/bpf_verifier.h> > #include <linux/btf.h> > +#include <linux/btf_ids.h> > #include <linux/skmsg.h> > #include <linux/perf_event.h> > #include <net/sock.h> > @@ -3621,6 +3622,9 @@ static int btf_translate_to_vmlinux(struct bpf_verifier_log *log, > return kern_ctx_type->type; > } > > +BTF_ID_LIST(bpf_ctx_convert_btf_id) > +BTF_ID(struct, bpf_ctx_convert) > + > struct btf *btf_parse_vmlinux(void) > { > struct btf_verifier_env *env = NULL; > @@ -3659,10 +3663,10 @@ struct btf *btf_parse_vmlinux(void) > if (err) > goto errout; > > - /* find struct bpf_ctx_convert for type checking later */ > - btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT); > - if (btf_id < 0) { > - err = btf_id; > + /* struct bpf_ctx_convert for type checking later */ > + btf_id = bpf_ctx_convert_btf_id[0]; > + if (btf_id <= 0) { Just want to double check. Is it possible btf_id < 0 since previous patch did not check < 0? > + err = -EINVAL; > goto errout; > } > /* btf_parse_vmlinux() runs under bpf_verifier_lock */ >
On Fri, Jun 26, 2020 at 02:44:39PM -0700, Yonghong Song wrote: > > > On 6/25/20 3:12 PM, Jiri Olsa wrote: > > 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> > > --- > > kernel/bpf/btf.c | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > > index 4da6b0770ff9..701a2cb5dfb2 100644 > > --- a/kernel/bpf/btf.c > > +++ b/kernel/bpf/btf.c > > @@ -18,6 +18,7 @@ > > #include <linux/sort.h> > > #include <linux/bpf_verifier.h> > > #include <linux/btf.h> > > +#include <linux/btf_ids.h> > > #include <linux/skmsg.h> > > #include <linux/perf_event.h> > > #include <net/sock.h> > > @@ -3621,6 +3622,9 @@ static int btf_translate_to_vmlinux(struct bpf_verifier_log *log, > > return kern_ctx_type->type; > > } > > +BTF_ID_LIST(bpf_ctx_convert_btf_id) > > +BTF_ID(struct, bpf_ctx_convert) > > + > > struct btf *btf_parse_vmlinux(void) > > { > > struct btf_verifier_env *env = NULL; > > @@ -3659,10 +3663,10 @@ struct btf *btf_parse_vmlinux(void) > > if (err) > > goto errout; > > - /* find struct bpf_ctx_convert for type checking later */ > > - btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT); > > - if (btf_id < 0) { > > - err = btf_id; > > + /* struct bpf_ctx_convert for type checking later */ > > + btf_id = bpf_ctx_convert_btf_id[0]; > > + if (btf_id <= 0) { > > Just want to double check. Is it possible btf_id < 0 since previous patch > did not check < 0? right.. resolve_btfids would fail during linking, so this is not necessary thanks, jirka
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 4da6b0770ff9..701a2cb5dfb2 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -18,6 +18,7 @@ #include <linux/sort.h> #include <linux/bpf_verifier.h> #include <linux/btf.h> +#include <linux/btf_ids.h> #include <linux/skmsg.h> #include <linux/perf_event.h> #include <net/sock.h> @@ -3621,6 +3622,9 @@ static int btf_translate_to_vmlinux(struct bpf_verifier_log *log, return kern_ctx_type->type; } +BTF_ID_LIST(bpf_ctx_convert_btf_id) +BTF_ID(struct, bpf_ctx_convert) + struct btf *btf_parse_vmlinux(void) { struct btf_verifier_env *env = NULL; @@ -3659,10 +3663,10 @@ struct btf *btf_parse_vmlinux(void) if (err) goto errout; - /* find struct bpf_ctx_convert for type checking later */ - btf_id = btf_find_by_name_kind(btf, "bpf_ctx_convert", BTF_KIND_STRUCT); - if (btf_id < 0) { - err = btf_id; + /* struct bpf_ctx_convert for type checking later */ + btf_id = bpf_ctx_convert_btf_id[0]; + if (btf_id <= 0) { + err = -EINVAL; goto errout; } /* btf_parse_vmlinux() runs under bpf_verifier_lock */
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> --- kernel/bpf/btf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)