libbpf: Load btf_vmlinux only once per object.
authorKP Singh <kpsingh@google.com>
Fri, 17 Jan 2020 21:28:25 +0000 (22:28 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 17 Jan 2020 21:59:34 +0000 (13:59 -0800)
commita6ed02cac690b635dbb938690e795812ce1e14ca
treeba5d20de0b6fc00988964ae2ab917a90651a08a1
parentc701917e647c6aaee5e7bbb7a2c1ca99e8552c58
libbpf: Load btf_vmlinux only once per object.

As more programs (TRACING, STRUCT_OPS, and upcoming LSM) use vmlinux
BTF information, loading the BTF vmlinux information for every program
in an object is sub-optimal. The fix was originally proposed in:

   https://lore.kernel.org/bpf/CAEf4BzZodr3LKJuM7QwD38BiEH02Cc1UbtnGpVkCJ00Mf+V_Qg@mail.gmail.com/

The btf_vmlinux is populated in the object if any of the programs in
the object requires it just before the programs are loaded and freed
after the programs finish loading.

Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: KP Singh <kpsingh@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Brendan Jackman <jackmanb@chromium.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200117212825.11755-1-kpsingh@chromium.org
tools/lib/bpf/libbpf.c