linux-stable/tools/lib/bpf
Andrii Nakryiko 12d9466d8b libbpf: Refactor internal sec_def handling to enable pluggability
Refactor internals of libbpf to allow adding custom SEC() handling logic
easily from outside of libbpf. To that effect, each SEC()-handling
registration sets mandatory program type/expected attach type for
a given prefix and can provide three callbacks called at different
points of BPF program lifetime:

  - init callback for right after bpf_program is initialized and
  prog_type/expected_attach_type is set. This happens during
  bpf_object__open() step, close to the very end of constructing
  bpf_object, so all the libbpf APIs for querying and updating
  bpf_program properties should be available;

  - pre-load callback is called right before BPF_PROG_LOAD command is
  called in the kernel. This callbacks has ability to set both
  bpf_program properties, as well as program load attributes, overriding
  and augmenting the standard libbpf handling of them;

  - optional auto-attach callback, which makes a given SEC() handler
  support auto-attachment of a BPF program through bpf_program__attach()
  API and/or BPF skeletons <skel>__attach() method.

Each callbacks gets a `long cookie` parameter passed in, which is
specified during SEC() handling. This can be used by callbacks to lookup
whatever additional information is necessary.

This is not yet completely ready to be exposed to the outside world,
mainly due to non-public nature of struct bpf_prog_load_params. Instead
of making it part of public API, we'll wait until the planned low-level
libbpf API improvements for BPF_PROG_LOAD and other typical bpf()
syscall APIs, at which point we'll have a public, probably OPTS-based,
way to fully specify BPF program load parameters, which will be used as
an interface for custom pre-load callbacks.

But this change itself is already a good first step to unify the BPF
program hanling logic even within the libbpf itself. As one example, all
the extra per-program type handling (sleepable bit, attach_btf_id
resolution, unsetting optional expected attach type) is now more obvious
and is gathered in one place.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/bpf/20210928161946.2512801-6-andrii@kernel.org
2021-09-28 13:51:19 -07:00
..
.gitignore libbpf: Make libbpf_version.h non-auto-generated 2021-09-13 15:36:47 -07:00
bpf.c libbpf: Add bpf_cookie support to bpf_link_create() API 2021-08-17 00:45:08 +02:00
bpf.h libbpf: Add bpf_cookie support to bpf_link_create() API 2021-08-17 00:45:08 +02:00
bpf_core_read.h selftests/bpf: Fix BPF_CORE_READ_BITFIELD() macro 2021-04-26 18:37:13 -07:00
bpf_endian.h libbpf: Make bpf_endian co-exist with vmlinux.h 2020-07-01 09:06:12 +02:00
bpf_gen_internal.h libbpf: Cleanup temp FDs when intermediate sys_bpf fails. 2021-05-19 00:40:44 +02:00
bpf_helpers.h libbpf: Use static const fmt string in __bpf_printk 2021-09-17 14:02:05 -07:00
bpf_prog_linfo.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
bpf_tracing.h libbpf: Fail compilation if target arch is missing 2021-06-16 20:15:30 -07:00
btf.c libbpf: Add support for BTF_KIND_TAG 2021-09-14 18:45:52 -07:00
btf.h libbpf: Add sphinx code documentation comments 2021-09-15 13:16:02 -07:00
btf_dump.c libbpf: Add support for BTF_KIND_TAG 2021-09-14 18:45:52 -07:00
Build libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
gen_loader.c libbpf: Cleanup temp FDs when intermediate sys_bpf fails. 2021-05-19 00:40:44 +02:00
hashmap.c libbpf: Centralize poisoning and poison reallocarray() 2020-08-18 18:38:25 -07:00
hashmap.h libbpf, hashmap: Fix undefined behavior in hash_bits 2020-11-02 23:33:51 +01:00
libbpf.c libbpf: Refactor internal sec_def handling to enable pluggability 2021-09-28 13:51:19 -07:00
libbpf.h libbpf: Refactor and simplify legacy kprobe code 2021-09-21 19:40:09 -07:00
libbpf.map libbpf: Add support for BTF_KIND_TAG 2021-09-14 18:45:52 -07:00
libbpf.pc.template libbpf: Add zlib as a dependency in pkg-config template 2019-12-16 14:55:29 -08:00
libbpf_common.h libbpf: Schedule open_opts.attach_prog_fd deprecation since v0.7 2021-09-17 09:05:41 -07:00
libbpf_errno.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
libbpf_internal.h libbpf: Add support for BTF_KIND_TAG 2021-09-14 18:45:52 -07:00
libbpf_legacy.h libbpf: Streamline error reporting for low-level APIs 2021-05-25 17:32:35 -07:00
libbpf_probes.c libbpf: Fix probe for BPF_PROG_TYPE_CGROUP_SOCKOPT 2021-08-07 01:38:52 +02:00
libbpf_version.h libbpf: Make libbpf_version.h non-auto-generated 2021-09-13 15:36:47 -07:00
linker.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
Makefile libbpf: Make libbpf_version.h non-auto-generated 2021-09-13 15:36:47 -07:00
netlink.c libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
nlattr.c libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
nlattr.h libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
relo_core.c libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
relo_core.h libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
ringbuf.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
skel_internal.h bpf: Add cmd alias BPF_PROG_RUN 2021-05-19 15:35:12 +02:00
str_error.c libbpf: Poison kernel-only integer types 2020-01-10 10:38:00 -08:00
str_error.h libbpf: relicense libbpf as LGPL-2.1 OR BSD-2-Clause 2018-10-08 10:09:48 +02:00
strset.c libbpf: Extract internal set-of-strings datastructure APIs 2021-03-18 16:14:22 -07:00
strset.h libbpf: Extract internal set-of-strings datastructure APIs 2021-03-18 16:14:22 -07:00
xsk.c libbpf: Fix build with latest gcc/binutils with LTO 2021-09-07 19:32:04 -07:00
xsk.h libbpf: xsk: Move barriers from libbpf_util.h to xsk.h 2021-03-10 13:45:16 -08:00