Commit graph android_system_bpf/libbpf_android
Message SHA1
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
Update Loader.cpp for updated bcc
bpf_create_map and bpf_prog_load have been renamed, so update those
calls. bcc now depends on upstream libbpf and has deleted its
redundant implementations of bpf_obj_pin and bpf_obj_get, so add
upstream libbpf as a dependency.

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

Connor O'Brien   commited 2022-01-18 09:26:17 -08:00
52863b6ba6
[NETD-BPF#22] Move a few headers to frameworks/libs/net
BPF headers used by both platform and mainline modules should be in
frameworks/libs/net.

Bug: 202086915
Test: build and boot
Test: cd packages/modules/Connectivity/netd; atest
Change-Id: Id9ac888d5519b2a8663232610d36386cabfe4e94

Ken Chen   commited 2021-12-23 09:50:01 +08:00
d568947cd7
Rename bpf_map_utils to bpf_headers
Use a generic name so that it can contain more bpf related headers.

Bug: 202086915
Test: build
Change-Id: I36d93cbc77723464df84023752915e1e79e623df

Ken Chen   commited 2021-12-21 15:36:25 +08:00
fb045621be
Rename libbpf to libbpf_bcc
This is to prevent a name collision with "upstream"
libbpf (external/libbpf) which is built using the same name.

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

Connor O'Brien   commited 2021-12-16 13:16:05 -08:00
474eb0baa0
[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
[NETD-BPF#13] Delete libbpf_android_test from system/bpf
The test will be moved to frameworks/libs/net along with header files.

Bug: 202086915
Test: m
Merged-In: I1de9c1f443f8bf90ef341e4867866093e62f427d
Change-Id: I1de9c1f443f8bf90ef341e4867866093e62f427d

Ken Chen   commited 2021-12-04 02:30:36 +00:00
b81aef32e5
[NETD-BPF#10] Add WaitForProgsLoaded.h
Move waitForProgsLoaded() from libbpf_android.h to a single header file.
A transitional commit of separating headers, utilities from bfploader.

Bug: 202086915
Test: build; flash; cd system/netd; atest
Change-Id: Ief1bcd09e973f952c29859a7a8fba92c8626e32d

Ken Chen   commited 2021-12-03 08:16:24 +00:00
5b0fbc192e
Merge "[NETD_BPF#8] Move BpfUtils.cpp to BpfUtils.h"
Ken Chen   authored and   Gerrit Code Review   commited 2021-12-03 08:15:06 +00:00
edfca8b548
Support fuse prog types
When fuse-bpf lands in the kernel, support reading its bpf program type
from /sys/fs/fuse/bpf_prog_type_fuse and load such programs.

This is to allow development of fuse-bpf to continue, and is needed
until such time as fuse-bpf is upstreamed and this value is fixed.

Bug: 202785178
Test: Along with change to bpfprogs, prog_fuse_media_fuse_media appears
in /sys/fs/bpf

Change-Id: I83636f25b0a0c678b3ee48c6450d9c8dc157387b

Paul Lawrence   authored and   Maciej Żenczykowski   commited 2021-11-23 00:28:12 +00:00
9548f9fbed
[NETD_BPF#8] Move BpfUtils.cpp to BpfUtils.h
Functions in BpfUtils.cpp are trivial, they can be static inlined
in BpfUtils.h.

Bug: 202086915
Test: m; flash; boot; cd system/netd && atest
Test: m gpuservice_unittest libtimeinstate_test bpf_module_test
      CtsAppOpsTestCases libmeminfo_test VtsBootconfigTest
      vts_test_binary_bpf_module
Change-Id: Ie1ece23b6fc9a4db5fc95930209a10da1e528cb5

Ken Chen   commited 2021-11-21 10:59:39 +08:00
02c2536103
fix 'cgroupsockaddr' support
... it does prefix matching - and first match wins.

By appending / to the strings this no longer matters.

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

Maciej Żenczykowski   commited 2021-11-19 11:18:57 +00:00
2b203138cb
add mainline module support for targetting only newer bpfloader versions
This will allow shipping .o's targetting only T and not S devices.

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

Maciej Żenczykowski   commited 2021-11-18 05:47:24 +00:00
41661a10e3
rename SEC() to SECTION()
The only purpose of this is to break cut-and-paste of examples
that use SEC() causing people to think things through, look
at Android bpf program examples and use a better macro.

In particular programs with SEC("license") / SEC("maps") need to be
changed to use LICENSE("license") and the map helpers or the map
section is wrong and cannot be correctly parsed by the bpfloader.

Generated via:
  git grep 'SEC\(' | cut -d: -f1-2 | while read i; do mcedit $i; done
and manually editting found locations

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

Maciej Żenczykowski   commited 2021-11-18 05:45:21 +00:00
3adb1d5569
BpfUtils.h - switch to GTEST_SKIP in all 4 SKIP macros
Test: TreeHugger, atest libbpf_android_test netd_unit_test netd_integration_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3acb47a432378f257418f81b26516e18d6ff3780

Maciej Żenczykowski   commited 2021-11-11 11:54:02 -08:00
5460527c74
Add Bpf Prog Type for CGROUP_SOCK_ADDR
When loading a BPF program check for CGROUP_SOCK_ADDR
program type.

Bug: 179733303
Change-Id: I0464052065ec6f77a639a12a8dd343b7bf6f6ef8

Tyler Wear   commited 2021-10-26 16:54:35 -07:00
25c028576d
Increase the log size for larger bpf programs
Test: Build passes, bpf program loads without an out of space error
Bug: 203462310
Change-Id: I5f67021a530223467662f341cdfffc4816781078

Stephane Lee   authored and   Maciej Żenczykowski   commited 2021-10-22 19:07:05 -07:00
eb61b739ae
bpfloader: add schedact support
This also bumps the bpfloader version to 0.3 to signify support
for loading schedact (ie. tc scheduler action) programs.

Test: load netd.o
Change-Id: Ic3fdc80d3f6ea2b42a4f1d6829b1ff12dd4d52c0

Patrick Rohr   authored and   Maciej Żenczykowski   commited 2021-10-13 19:28:53 +00:00
b28bf2aa53
Cleanup unused dependency to libprocessgroup
Bug: http://b/197965342

Dependence on libprocessgroup was removed in aosp/947297

Test: presubmit
Change-Id: I802efee3500e25006b55e0f35cb8650fd1aa2033

Pirama Arumuga Nainar   commited 2021-08-31 19:59:20 +00:00
e8d6df1231
expose readSectionUint() for testing
Bug: 190519702
Test: atest bpf_module_test, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I772c918d162440de6cc492b2faeafe03340fca11

Maciej Żenczykowski   commited 2021-07-06 01:55:33 -07:00
7ed94efeda
bpf - struct bpf_map_def - add min/max kernel version.
This is also bpfloader v0.2.
Some newer map types (for example DEVMAP) are unusable
on older kernel versions.

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

Maciej Żenczykowski   commited 2021-07-05 18:02:16 -07:00
36c53ba91e
bpfloader - minor fixups asked for by reviewer
As requested by Bernie on previous commit.

Bug: 190519702
Test: atest, TreeHugger - existing bpf programs load
  examination of bpfloader logs
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4f5181f371d31dcf52768217ffd2b1b5b772103d

Maciej Żenczykowski   commited 2021-07-02 01:17:13 -07:00
a21256dcf1
bpf loader improvements for better long term compatibility with mainline
This is bpfLoader v0.1, previously we had no version number,
the version immediately preceding this commit we'll call v0.0.

Versions older than that are either pre-S and don't matter, since
loading mainline eBpf code was only added in S, or are from early
during the S development cycle (ie. pre-March 5th 2021 or earlier)
and simply no longer supported (no need to maintain compatibility).

Bug: 190519702
Test: atest, TreeHugger - existing bpf programs load
  examination of bpfloader logs
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I36fa5b917540be7ea3ecfddc5fe7834e9eb18d88

Maciej Żenczykowski   commited 2021-07-02 03:36:49 +00:00
9217eee3df
BpfUtils.h - add back SKIP_IF_BPF_NOT_SUPPORTED macro
Needs to be used by dns mainline module tests on R devices (Pixel 2).

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

Maciej Żenczykowski   commited 2021-03-11 19:52:30 -08:00
67fa2073ff
bpfloader: auto-demote DEVMAP/DEVMAP_HASH map types on too old kernels
Basically:
  <4.14: DEVMAP -> ARRAY
  <5.4: DEVMAP_HASH -> HASH

See added comments for explanation of why, but basically:
This allows our bpf program .o files to load maps on all kernel versions,
even if those map types are not supported by the kernel.
This avoids the need for code that conditionally creates maps based on
kernel version. Any program that actually attempts to use one of these
maps will fail to load, but programs are already loaded conditionally
based on kernel version so this is not a problem.

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

Maciej Żenczykowski   commited 2021-03-05 06:00:59 +00:00
cb358de067
make failure on map creation returns -errno
This slightly improves error logging.

(also fd == 0 is not an error condition)

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

Maciej Żenczykowski   commited 2021-03-02 07:46:32 +00:00
2c37213796
KVER macro - support 4.9.256+ kernel
Instead of doing 16/8/8 bits for major/minor/subver macro,
switch to 8/8/16 bits, since this gives plenty of space:
  - major versions are bumped every few years, so 256 last forever
  - minor versions are bumped every few months (~5-6 per year),
    so 256 lasts for decades, additionally Linus Torvalds doesn't
    like big numbers, and eventually bumps the major instead
  - sub versions are the problematic ones, because they're bumped
    on every LTS security release, however even at one release per day,
    16 bits lasts for 180 years

Note: before this change 4.9.256 was treated as equivalent to 4.10.0.

Luckily all our tests were only ever (by chance) against the LTS release
bases (ie. 4.9.0, 4.14.0, 4.19.0, 5.4.0) and thus we wouldn't have hit
an actually failure until 4.9.(5*256) === 4.14.0 which would have caused
the bpfloader to attempt to load bpf code requiring 4.14 on a 4.9 kernel,
and resulted in failure of device to successfully boot.

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

Maciej Żenczykowski   commited 2021-02-11 16:05:21 -08:00
30af4b5487
[LSC] Add LOCAL_LICENSE_KINDS to system/bpf
Added SPDX-license-identifier-Apache-2.0 to:
  Android.bp
  bpfloader/Android.bp
  libbpf_android/Android.bp
  progs/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: Ia881b61da1755797085916aab5325375c82ed76e

Bob Badour   commited 2021-02-05 01:28:19 -08:00
dcbf8ca070
BpfMap - fix a clang warning: misc-unconventional-assign-operator
//system/bpf/libbpf_android:libbpf_android_test clang-tidy BpfMapTest.cpp
system/bpf/libbpf_android/include/bpf/BpfMap.h:138:5: warning: operator=() should return 'BpfMap&' [misc-unconventional-assign-operator]
    void operator=(BpfMap<Key, Value>&& other) noexcept {
    ^

Test: builds without warnings
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0bb0d42f58bba58c7b9220f062453d827438e85a

Maciej Żenczykowski   commited 2021-01-23 18:30:07 +00:00
8ed7c0f9b9
move waitForProgsLoaded() to header file
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2f0035f2622ca2a8c10d29caff912f3f895f2607

Maciej Żenczykowski   commited 2021-01-21 17:39:33 -08:00
cdf85a3148
eliminate LoaderUtils.h
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I662714ee4faa6485d2ba7bbcbc8e34c76e37b091

Maciej Żenczykowski   commited 2021-01-21 17:39:29 -08:00
f7c0d993dd
header file cleanup
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I03920e51bab3cb704f156ea9c62a0a38fd65a3a9

Maciej Żenczykowski   commited 2021-01-21 14:24:25 -08:00
23c436f957
add SKIP_IF_XDP_NOT_SUPPORTED macro
Test: builds, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia954983565250faff547e81a53ec0df5fc26827e

Maciej Żenczykowski   commited 2021-01-20 16:24:02 -08:00
a36bed395f
remove isBpfSupported()
Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifb4b4ced25ac444fe913c6392c0c8d57b2d9c58e

Maciej Żenczykowski   commited 2021-01-19 23:48:01 -08:00
916d2395cc
remove BpfLevel and getBpfSupportLevel in favour of isAtLeastKernelVersion
Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I50dbed1843a8c2802e1b416281e193ae7d282a99

Maciej Żenczykowski   commited 2021-01-19 23:48:01 -08:00
dcb5228f2c
put tethering bpf maps & programs in /sys/fs/bpf/tethering/...
This makes it harder for system and mainline bpf programs to
conflict with each other, thus enabling easier mainline module
updates.

Test: builds and boots, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic1b69bb1ddc4a10bd4861dadbd6b97e2520c532d

Maciej Żenczykowski   commited 2021-01-20 05:17:14 +00:00
d8a4578f30
Merge changes Ic378d0e5,Ib3a8696a
* changes:
  remove unused enum value BpfLevel::NONE
  remove unused function BpfLevelToString()

Treehugger Robot   authored and   Gerrit Code Review   commited 2021-01-20 03:38:42 +00:00
da5d7ec6a7
Merge "remove unused macros SKIP_IF_BPF{,_NOT}_SUPPORTED"
Treehugger Robot   authored and   Gerrit Code Review   commited 2021-01-20 03:09:46 +00:00
71e977fb0d
bpf is always supported
Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifcc6ff2b2293b7585f20108ad849408ed9af4538

Maciej Żenczykowski   commited 2021-01-20 01:37:32 +00:00
d6cbd5622e
remove unused enum value BpfLevel::NONE
Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic378d0e5a579abf44985a3353a21885796c297bb

Maciej Żenczykowski   commited 2021-01-20 01:36:55 +00:00
2337d47db3
remove unused function BpfLevelToString()
Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib3a8696a9653e5fbb022c98c26cfff623fadb3b4

Maciej Żenczykowski   commited 2021-01-20 01:36:16 +00:00
5947162cc5
remove unused macros SKIP_IF_BPF{,_NOT}_SUPPORTED
Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic740b1102fcf735516123eee2c6a3d5caa0892f9

Maciej Żenczykowski   commited 2021-01-20 01:15:04 +00:00
b8e9af4b10
libbpf_android/Loader.cpp - fix a clang warning (clang-analyzer-deadcode.DeadStores)
//system/bpf/libbpf_android:libbpf_android clang-tidy Loader.cpp
system/bpf/libbpf_android/Loader.cpp:133:5: warning: Value stored to 'entries' is never read [clang-analyzer-deadcode.DeadStores]
    entries = shTable.size();
    ^
system/bpf/libbpf_android/Loader.cpp:133:5: note: Value stored to 'entries' is never read

Test: builds without warnings
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I548976b59d44a51e992c9520e730fc9dae82fce2

Maciej Żenczykowski   commited 2021-01-19 21:18:20 +00:00
d56ec05712
Merge "4.9 kernels must support eBPF (as of Android S)"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2021-01-14 07:36:56 +00:00
1fddcce3c9
Merge "Use the module bpf_syscall_wrappers for BPF system calls"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2021-01-14 07:36:50 +00:00
6fadbcf91a
4.9 kernels must support eBPF (as of Android S)
so there is no longer a need to look at any properties
or api levels.

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

Maciej Żenczykowski   commited 2021-01-14 03:27:47 +00:00
ef6689652c
Use the module bpf_syscall_wrappers for BPF system calls
Use the versioned header library of BPF system calls and remove the
stubs.

Test: atest BpfMapTest
Change-Id: Ib178b02b7cfebaae7681609ae7c40a49cda47eeb

Hungming Chen   commited 2021-01-13 14:34:41 +08:00
a46f217d73
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
Merge "Add an sdk_version annotation to libbpf_android_headers."
Treehugger Robot   authored and   Gerrit Code Review   commited 2021-01-08 05:29:47 +00:00
8e614c2ca2
Add an sdk_version annotation to libbpf_android_headers.
This will be used by the tethering module when running on S, so
it needs to have an sdk_version. Because this target does not
depend on anything, there is no need to change any other code.

Because this is only needed by the tethering module, which
shipped in R, pick the R SDK version, 30. That ensures we do not
need to support it on releases older than when it is needed.

Test: m
Bug: 173167302
Change-Id: I15c1e943d0c30aceebcb8288e78a5a8135ee7fd1

Lorenzo Colitti   commited 2021-01-08 13:18:10 +09:00
8cc4f91fca