Commit graph android_system_bpf/libbpf_android/BpfLoadTest.cpp
Message SHA1
Rename bpf_load_tp_prog.o and bpf_load_tp_prog_btf.o
Underscore character may cause bpf prog/map naming collision. For
example, x.o with map y_z and x_y.o with map z both result in x_y_z
prog/map name, which should be prevented during compile-time.

aosp/2147825 will prohibit underscore character in bpf source name
(source name derives the obj name). Existing bpf modules with underscore
characters in source name need to be updated accordingly.

Bug: 236706995
Test: atest libbpf_load_test
Change-Id: I037ccfedc4d2e48688ee47f575c73998ce1c2c4b

Ken Chen   commited 2022-07-10 18:31:18 +08:00
8693c789d3
bpfloader: support 'shared' maps and per-map/program selinux context
allow bpf .o files to specify desired selinux context

Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9d7449e477c371053a34191a2a9a935ba927d4b3

Maciej Żenczykowski   commited 2022-06-21 02:23:09 -07:00
4181713963
bpfloader: also load from /vendor/etc/bpf/
Allow vendors to use bpf programs, but limit to tracepoints
for now (other types of programs, for instance skfilter, aren't
safe to expose, because the kernel gives us limited ways to
control which resources can have BPF programs attached, and
some shared resources only support a single BPF program at an
attach point).

Bug: 140330870
Bug: 162057235
Test: install bpf program to /vendor/etc/bpf/ and use it.
Test: atest libbpf_load_test
Change-Id: I6c876fe52739c38db73689ffd784167e7d35d58a

Steven Moreland   commited 2022-02-09 00:59:37 +00:00
0f10f3fd9f
libbpf_load_test: use "data" instead of "required" for test progs
atest appears not to know how to push dependencies listed with the
"required" property, but it will push "data" modules to the same
folder as the test itself. Update Android.bp to use data instead, and
change BpfLoadTest.cpp to reflect the new location of the test
programs.

Test: atest libbpf_load_test
Bug: 203823368
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: Iabec3662e2c03f4ab19e5cdce859e4238767519d

Connor O'Brien   commited 2022-01-28 12:26:16 -08:00
509131481d
bpfloader: don't depend on symtab ordering to find function name
readCodeSections implicitly assumes that a function's name will be the
first symbol in its section to appear in the symbol table, but this is
not guaranteed. In particular, when compiling with -g the section name
can appear before it, resulting in a failure to find the bpf_prog_def
information for that section's program.

Add a check for the STT_FUNC symbol type to narrow our search to the
function name symbol we actually want.

Also, add a test to check that a program with a minimum kernel version
of infinity will not be loaded, to verify that bpfloader successfully
finds bpf_prog_def information.

Test: boot & confirm progs all have correct owners & permissions
Test: build time_in_state.c with -g and confirm owner & permissions
set correctly
Test: libbpf_load_test now passes iff this fix is applied
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I31db0c50d3adeed86ee5810b1a0fb972f56fdb47

Connor O'Brien   commited 2022-01-24 21:32:09 -08:00
0ea4c6b242
Test loading both with & without BTF
Add path to a test program with BTF info included to test bpfloader
handles both situations correctly

Test: libbpf_load_test
Bug: 203823368
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: Ibe63cdc2ee59199b687d4006efadb201d4a17f3c

Connor O'Brien   commited 2022-01-24 20:10:56 -08:00
0056fdce27
bpfloader: load map BTF via btfloader
btfloader uses upstream libbpf & libelf to parse the BTF sections of a
bpf .o file, load BTF information into the kernel, and identify the
BTF type ids corresponding to each map's keys and values.

Extend bpfloader to run btfloader on any .o file with a .BTF
section. We pass btfloader socket and pipe fds, which it will use to
send back a BTF fd and the key & value type ids, respectively.

To ensure a btfloader bug can't block bpfloader indefinitely, wait for
btfloader to run with a short timeout and use nonblocking socket &
pipe for communication.

Finally, add a check to BpfLoadTest to verify that map BTF is loaded
as expected.

Test: build & boot; existing programs load successfully
Test: libbpf_load_test
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I7bac83a08c2dc452bdb9030f1e74781116c1dd5c

Connor O'Brien   commited 2022-01-24 21:24:26 +00:00
35425e5a88
Make BpfLoadTest parameterized to support multiple test programs
This will enable testing both with & without BTF enabled once
necessary build changes are merged.

Test: libbpf_load_test passes
Bug: 203823368
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: Ifd89b6c0701791c216807e913d9a4803d9a4dd20

Connor O'Brien   commited 2022-01-21 18:24:21 -08:00
00fa9635f8
[NETD-BPF#14] Move BPF map definition and utils to frameworks/libs/net/
Move BPF map definition and utilities to a common place that easy to be
referenced from both mainline module and platform code.

Bug: 202086915
Test: m; flash; boot
Test: cd system/netd/ && atest
Test: cd packages/modules/Connectivity && atest
Test: m gpuservice_unittest libtimeinstate_test bpf_module_test
      CtsAppOpsTestCases libbpf_load_test VtsBootconfigTest
      vts_test_binary_bpf_module bpf_benchmark libbpf_load_test
      libbpf_android_test
Change-Id: Ib15cf78c2da97bff835fb406c866676eec77c013

Ken Chen   authored and   Maciej Żenczykowski   commited 2021-12-04 03:42:55 +00:00
b1d4888ec2
SKIP_IF_BPF_NOT_SUPPORTED is a no-op
Android S requires devices to support eBPF.

Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I62fb97f79103515f5a2fd531cfa36356d21a4a6f

Maciej Żenczykowski   commited 2021-01-12 02:08:55 +00:00
5756f0c937
Warn loudly and do not set bpf.progs_loaded property on critical bpf load failure.
Reasoning: critical load failures for netd bpf programs will just result
in unpredictable behaviour later on.  For example netd/systemserver
crash loops.

Test: builds
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iefa01e60cd0a9a223e96411726a199bfb4857a5a

Maciej Żenczykowski   commited 2020-06-15 08:01:50 +00:00
89515d979a
More missing calls to Result::ok() in libbpf_android tests
Test: m checkbuild
Change-Id: Idb70b975e3c3bcbaa78cb493ec8f66b9b625ef74

Bernie Innocenti   commited 2020-02-10 07:28:13 +09:00
43d2538871
BpfLoadTest.cpp - construct BpfMap from path not fd
switch over to the newer pinned path using constructor

Test: build, atest
  mMapFd no longer shows up in this file
Bug: 129773125
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie70149ffd5a541c80b35804ffd38df07f28b509b

Maciej Żenczykowski   commited 2020-01-30 08:59:44 +00:00
cd5c3023ce
libbpf_android: remove libnetdutils dep
Remove libnetdutils dependency because bpf is being used for things other
than networking these days, and we don't want to make libnetdutils
vendor-available in the future. libbase provides an alternative type now.

Bug: 140330870
Test: atest libbpf_android_test netd_integration_test netd_unit_test
    libnetdbpf_test bpf_module_test
Change-Id: I72ae8cd7f58a49bfc7dcb914a332a4c4bad5dea5

Steven Moreland   commited 2020-01-21 10:47:33 -08:00
e7cd2a72d0
libbpf_load_test: fix map location
This test had bitrot.

Bug: N/A
Test: `atest libbpf_load_test`
Change-Id: I3480286e225d8dfbd0badd7bbb7cb77ff29ab0ea

Steven Moreland   commited 2020-01-14 11:37:49 -08:00
cdeb9203af
Add tests for BPF loader
Bug: 112334572
Change-Id: I4457ee9ea3044c5c9ecb6ebfd5ad4f5a2c11dce5
Signed-off-by: Joel Fernandes <joelaf@google.com>

Joel Fernandes   commited 2019-02-04 15:28:52 -05:00
4845288a6e