linux/tools
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
..
accounting
arch tools headers UAPI: Sync x86's asm/kvm.h with the kernel sources 2021-09-10 18:15:22 -03:00
bootconfig tools/bootconfig: Define memblock_free_ptr() to fix build error 2021-09-15 09:49:48 -07:00
bpf bpftool: Only probe trace_vprintk feature in 'full' mode 2021-09-17 14:02:05 -07:00
build perf cs-etm: Update OpenCSD decoder for ETE 2021-09-03 08:16:00 -03:00
cgroup
debugging
edid
firewire
firmware
gpio
hv
iio
include bpf: Clarify data_len param in bpf_snprintf and bpf_seq_printf comments 2021-09-17 14:02:06 -07:00
io_uring tools/io_uring/io_uring-cp: sync with liburing example 2021-08-13 08:58:11 -06:00
kvm/kvm_stat
laptop
leds
lib libbpf: Refactor internal sec_def handling to enable pluggability 2021-09-28 13:51:19 -07:00
memory-model tools/memory-model: Document data_race(READ_ONCE()) 2021-07-27 11:48:55 -07:00
objtool A single ELF format fix for a section flags mismatch bug that breaks 2021-06-28 11:35:55 -07:00
pci tools: PCI: Zero-initialize param 2021-08-05 11:01:30 +01:00
pcmcia
perf perf tools: Add an option to build without libbfd 2021-09-11 16:06:52 -03:00
power tools/power/x86/intel-speed-select: v1.10 release 2021-06-18 15:29:32 +02:00
rcu
scripts
spi
testing selftests/bpf: Normalize all the rest SEC() uses 2021-09-28 13:51:19 -07:00
thermal/tmon tools/thermal/tmon: Add cross compiling support 2021-08-14 15:33:19 +02:00
time
tracing
usb
virtio tools/virtio: fix build 2021-08-11 06:44:24 -04:00
vm tools/vm/page_owner_sort.c: check malloc() return 2021-06-29 10:53:47 -07:00
wmi
Makefile