selftests/bpf: Add bpf_cookie selftests for high-level APIs
authorAndrii Nakryiko <andrii@kernel.org>
Sun, 15 Aug 2021 07:06:07 +0000 (00:06 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 16 Aug 2021 22:45:08 +0000 (00:45 +0200)
commit0a80cf67f34cab7c18d74c28bb59e131670dc268
tree53373765c64d1f3510f9914543f29a5608529411
parenta549aaa67395eea89c2b9d2bea01ab0455b18408
selftests/bpf: Add bpf_cookie selftests for high-level APIs

Add selftest with few subtests testing proper bpf_cookie usage.

Kprobe and uprobe subtests are pretty straightforward and just validate that
the same BPF program attached with different bpf_cookie will be triggered with
those different bpf_cookie values.

Tracepoint subtest is a bit more interesting, as it is the only
perf_event-based BPF hook that shares bpf_prog_array between multiple
perf_events internally. This means that the same BPF program can't be attached
to the same tracepoint multiple times. So we have 3 identical copies. This
arrangement allows to test bpf_prog_array_copy()'s handling of bpf_prog_array
list manipulation logic when programs are attached and detached.  The test
validates that bpf_cookie isn't mixed up and isn't lost during such list
manipulations.

Perf_event subtest validates that two BPF links can be created against the
same perf_event (but not at the same time, only one BPF program can be
attached to perf_event itself), and that for each we can specify different
bpf_cookie value.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210815070609.987780-15-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_bpf_cookie.c [new file with mode: 0644]