Commit graph android_system_bpf/libbpf_android/Loader.cpp
Message SHA1
Merge "use mapRetrieveRO() instead of bpf_obj_get()"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-07-01 20:01:30 +00:00
81329bd9e9
add missing logging for bpf_obj_pin operation
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ica8c15366c4db12fae1ac14c50fb46a5ab40acff

Maciej Żenczykowski   commited 2022-07-01 17:49:20 +00:00
d8259aa1e4
use mapRetrieveRO() instead of bpf_obj_get()
bpf_obj_get(path) is entirely equivalent to mapRetrieveRW(path)

See implementation in frameworks/libs/net common/native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h:

inline int bpfFdGet(const char* pathname, uint32_t flag) {
    return bpf(BPF_OBJ_GET, {
                                    .pathname = ptr_to_u64(pathname),
                                    .file_flags = flag,
                            });
}

inline int mapRetrieve(const char* pathname, uint32_t flag) { return bpfFdGet(pathname, flag); }
inline int mapRetrieveRW(const char* pathname) { return mapRetrieve(pathname, 0); }
inline int mapRetrieveRO(const char* pathname) { return mapRetrieve(pathname, BPF_F_RDONLY); }
inline int mapRetrieveWO(const char* pathname) { return mapRetrieve(pathname, BPF_F_WRONLY); }
inline int retrieveProgram(const char* pathname) { return bpfFdGet(pathname, BPF_F_RDONLY); }

However, this requires selinux file:write access which bpfloader
currently lacks, ie. we would need:

system/sepolicy private/bpfloader.te:
  -allow bpfloader bpffs_type:file { create read rename setattr };
  +allow bpfloader bpffs_type:file { create read rename setattr write };

Switching from mapRetrieveRW() to mapRetrieveRO() eliminates this problem.

BpfLoader itself does not need to write to the maps, while bpf program write
access is controlled by a different bit (it is independent of the r/w access
bits of the file descriptor itself).

Verified by re-opening the maps after pinning them.

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

Maciej Żenczykowski   commited 2022-07-01 15:56:21 +00:00
eb199dd748
bpfloader: add ability to disable btfloader
BTF support was added to bpfloader during Android T dev cycle.

As it causes bpfloader boot time process to shell out to a new
btfloader subprocess for every bpf.o file with BTF debugging
information compiled in, I'm worried this might have unforeseen
consequences - things like crashes or boot time bpfloader cpu
regressions.

However, BTF is exceedingly useful for debugging,
and it would be a huge pity if we were forced to disable it
and keep it disabled in mainline tethering module just to support
Android T devices for the next 5+ years.

It would also be a pity if the bpf.o files in prebuilt mainline
tethering apex in dev branches (like tm-dev) did not include
BTF debug information simply due to compatibility with older
kernels or OSes, since this would require rebuilding the module
everytime BTF information could be of use.

One of the things functioning BTF enables is 'cat /sys/fs/bpf/map_*'
as root on a userdebug build.  Among other things this can be
used to verify that in kernel bpf map state matches that dumped
by the mainline module's pretty dump code.

Even if there's issues wrt. BTF in Android T (or on older kernels),
we can always fix them in Android U or later (for example build
btfloader into bpfloader to avoid exec overhead, etc...).

Bug: 218408035
Bug: 230585250
Bug: 235559605
Test: TreeHugger, cuttlefish devices boots, and:
  adb root && adb shell cat /sys/fs/bpf/map_time_in_state_cpu_last_pid_map
  continues to show information which is available due to BTF debug provided
  in /system/etc/bpf/time_in_state.o file (due to "btf: true" in Android.bp)
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I553e90e0414453f8f3aaca8cf05d5decc8b911a2
(cherry picked from commit 37b3d06333)
Merged-In: I553e90e0414453f8f3aaca8cf05d5decc8b911a2

Maciej Żenczykowski   commited 2022-06-23 16:56:49 -07:00
bbab818687
const-ify mapMatchesExpectations arguments
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1364f7d0426c148e7daeb7df0bbfff7ea12c450e

Maciej Żenczykowski   commited 2022-06-23 13:20:45 +00:00
1a7fff3568
Revert "disable bpfloader selinux_context support"
This reverts commit 8e5e239dd0a7856e486a9e2d772ef3a9e38021eb.

No longer required now that selinux change has landed.

(while we're at it bump the bpfloader version to v0.19 just
 to make sure we can tell these apart in the future)

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

Maciej Żenczykowski   commited 2022-06-22 19:15:41 +00:00
687849e52e
disable bpfloader selinux_context support
(it requires bpfloader to be granted rename priv by selinux)

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

Maciej Żenczykowski   commited 2022-06-21 09:42:48 -07:00
a7a11bda00
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: verify that reused maps are the right type & shape
This is needed to make it safe to share maps across different .o's.

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

Maciej Żenczykowski   commited 2022-06-18 00:33:31 -07:00
12bb520707
add support for 'netd_readonly'
For use by:
- maps netd should have read but not write access to
  (needed due to netd being root with DAC_OVERRIDE,
   and thus not obeying standard unix permissions)
- programs that netd should have access to but
  not netutils_wrappers (which due to being able to
  run iptables, needs access to xt_bpf programs)

Bug: 218408035
Test: booted on cuttlefish
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I72b106692a25077ff54252fd93db81f46b52125d

Maciej Żenczykowski   commited 2022-06-17 18:08:00 -07:00
32c0b8f46e
remove spurious newlines in ALOG lines
eliminates empty lines visible in cuttlefish kernel.log

Bug: 218408035
Test: booted on cuttlefish
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2d75f1702c02b72c298642beb62c5df1c2629367

Maciej Żenczykowski   commited 2022-06-17 18:07:00 -07:00
e626a95e2f
bpfloader: add support for perf_event program type
Based on
  https://android-review.googlesource.com/c/platform/system/bpf/+/2104448

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

Maciej Żenczykowski   commited 2022-05-24 13:14:56 +00:00
e092e0bbfe
ease debugging - print pinned bpf prog & map ids
combined with content of /proc/${pid}/fd/${fd}
and /proc/${pid}/fdinfo/${fd} this allows figuring
out which programs/maps a process continues to
have open

See:
  adbz logcat -d | egrep '(map|prog) .* id'
  adbz root
  adbz_bpf_progs_and_maps

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

Maciej Żenczykowski   commited 2022-05-20 17:20:36 -07:00
57412c2a27
bpfloader: add support for netd_shared and net_private subdirs
Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I613b84342fba7b425fb10af157fe0a6a731b71cb

Maciej Żenczykowski   commited 2022-05-12 08:47:55 +00:00
7acf938127
move net_shared bpf programs into net_shared subdirectory
(no selinux consequences to this in and of itself,
 though required for follow up selinux changes)

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

Maciej Żenczykowski   commited 2022-04-21 06:45:25 -07:00
2a36ce48b0
Add socket filter to allowed programs for vendor and remove tracepoint
This also fixes a permissions issue if a non-root user is set. The read
permissions should be set before the file is set as non-root to ensure
that the permissions can be set without error.

Bump the BPF loader version.

Bug: 203462310
Test: Ensure that vendor skfilter bpf programs can load
Change-Id: Ib6b9a64d8652ff464c9d4d734bb8ae351673b6ce

Stephane Lee   commited 2022-03-11 00:43:06 +00:00
16c9360b1f
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
Load Bpf Program With Expected Attach Type
Move to bcc_prog_load_xattr() so that expected attach
type can be passed in when loading program.

Change-Id: I72533dd8805fa75287e12e828ee12315c0f8cd2d

Tyler Wear   commited 2022-02-07 21:48:37 +00:00
4e2f4608c0
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
Merge "bpfloader: load map BTF via btfloader"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-01-25 02:31:59 +00:00
102f93a5da
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
Merge "Update Loader.cpp for updated bcc"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-01-24 20:00:38 +00:00
3009d44d2d
Allow bpfloader to handle 'net_shared' subdirectory
netd.c is moved from netd to tethering mainline module.

Bump BpfLoader to v0.9

Bug: 202086915
Test: cd system/netd; atest
Test: atest TrafficStatsTest NetworkUsageStatsTest
Change-Id: I0b8ba90bbbe4e16d979c4a40d6fdbbaac0d14d27

Ken Chen   authored and   Maciej Żenczykowski   commited 2022-01-19 04:18:53 +00:00
6d69784cdc
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
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
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
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
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
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
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
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
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
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
add support for xdp bpf program type
Tested via:
  packages/modules/Connectivity/Tethering/Tethering/bpf_progs/offload.c:

  +DEFINE_BPF_PROG_KVER("xdp/test", AID_ROOT, AID_ROOT,
  +                      xdp_test, KVER(5, 10, 0))
  +(struct xdp_md *ctx) {
  +    return XDP_PASS;
  +}

  vsoc_x86:/ # ip link show dev lo
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

  vsoc_x86:/ # ip link set dev lo xdp pinned /sys/fs/bpf/prog_offload_xdp_test

  vsoc_x86:/ # ip link show dev lo
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      prog/xdp id 3 tag 3b185187f1855c4c jited

  vsoc_x86:/ # ip link set dev lo xdp off

  vsoc_x86:/ # ip link show dev lo
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

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

Maciej Żenczykowski   commited 2021-01-07 14:51:20 -08:00
aa46222706
reduce error to warning - happens for valid progs-section-less programs
07-21 01:39:43.946 26835 26835 E LibBpfLoader: No progs section could be found in elf object
07-21 01:39:43.951 26835 26835 I bpfloader: Loaded object: /system/etc/bpf/clatd.o
07-21 01:39:43.955 26835 26835 I bpfloader: Loaded object: /system/etc/bpf/offload.o
07-21 01:39:43.958 26835 26835 I bpfloader: Loaded object: /system/etc/bpf/time_in_state.o
07-21 01:39:43.967 26835 26835 I bpfloader: Loaded object: /system/etc/bpf/netd.o

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

Maciej Żenczykowski   commited 2020-08-05 03:39:17 +00:00
21f34cb32c
waitForProgsLoaded() - reduce log spaminess
Logging every 5s isn't actually useful and it just gets the important stuff out
of log buffers.

Test: adb logcat -s 'bpfloader:D' 'BpfUtils:D' 'LibBpfLoader:D'
  ...
  06-17 01:02:34.205   433   433 E bpfloader: --- DO NOT EXPECT SYSTEM TO BOOT SUCCESSFULLY ---
  06-17 01:02:38.103   335   335 W LibBpfLoader: Waited 5s for bpf.progs_loaded, still waiting...
  06-17 01:02:48.104   335   335 W LibBpfLoader: Waited 10s for bpf.progs_loaded, still waiting...
  06-17 01:03:08.104   335   335 W LibBpfLoader: Waited 20s for bpf.progs_loaded, still waiting...
  06-17 01:04:12.226   335   335 W LibBpfLoader: Waited 60s for bpf.progs_loaded, still waiting...
  06-17 01:04:17.628  1324  1324 W LibBpfLoader: Waited 5s for bpf.progs_loaded, still waiting...
  06-17 01:04:27.629  1324  1324 W LibBpfLoader: Waited 10s for bpf.progs_loaded, still waiting...
  06-17 01:04:47.629  1324  1324 W LibBpfLoader: Waited 20s for bpf.progs_loaded, still waiting...
  06-17 01:05:50.163  1324  1324 W LibBpfLoader: Waited 60s for bpf.progs_loaded, still waiting...
  06-17 01:05:55.551  1741  1741 W LibBpfLoader: Waited 5s for bpf.progs_loaded, still waiting...

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

Maciej Żenczykowski   commited 2020-06-17 21:24:55 +00:00
2090e3449d
implement support for functions which may optionally fail to load
This is useful for critical functions with fallbacks, but
may even be useful for non-critical functions, where a function
in the middle of the file may fail to load, but you still want
other (later) functions to be attempted.

Critical applies to the entire .c file (or to be more correct to
the entire resulting .o).  Optional applies to a specific section
of that .o (ie. a specific individual function).

This new optional attribute is necessary to be able to declare
a .c/.o file critical even if *some* of the individual functions
might fail to load due to missing kernel patches.

(Note: we currently have no way to specify a map as optional)

Critical guarantees that all non-optional programs, and all maps,
have been created, pinned, chowned, and chmoded successfully
(or that they already existed).

For an example of use see:
  system/netd/bpf_progs/offload.c

(while at it also add retrieveProgram() and mapRetrieve{RW,RO,WO}()
 helpers to BpfUtils.h)

Test: builds, atest, see paired netd change for extra details
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I50b292c061b05fc8f4b4b8574f128345c45c78db

Maciej Żenczykowski   commited 2020-06-17 10:44:19 +00:00
aa295c8355
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
allow tagging a bpf .o as critical
This does not yet do anything with this information besides logging it.

Test: builds
  $ adb logcat -s -d LibBpfLoader:D | egrep Loading
  06-14 22:52:48.657   430   430 D LibBpfLoader: Loading critical for netd ELF object /system/etc/bpf/offload.o with license Apache 2.0
  06-14 22:52:48.682   430   430 D LibBpfLoader: Loading optional ELF object /system/etc/bpf/time_in_state.o with license GPL
  06-14 22:52:48.729   430   430 D LibBpfLoader: Loading critical for netd ELF object /system/etc/bpf/clatd.o with license Apache 2.0
  06-14 22:52:48.767   430   430 D LibBpfLoader: Loading critical for netd ELF object /system/etc/bpf/netd.o with license Apache 2.0
  06-14 22:53:26.052  2605  2605 D LibBpfLoader: Loading optional ELF object /data/local/tmp/32/kern.o with license Apache 2.0
  06-14 22:54:26.070  2605  2605 D LibBpfLoader: Loading optional ELF object /data/local/tmp/32/kern.o with license Apache 2.0
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie07549528800d6d7c5ff7f12b859702113d7194e

Maciej Żenczykowski   commited 2020-06-15 06:34:51 +00:00
4ba8c1c1ac
only set 'bpf.progs_loaded' property on eBPF capable devices...
... which also means waitForProgsLoaded() has to be a no-op on pre-bpf devices.

This is more consistent: it's weird to have bpf.progs_loaded set on a 4.4 device.

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

Maciej Żenczykowski   commited 2020-06-13 22:41:48 -07:00
567dc56b57