Commit graph android_system_bpf/loader
Message SHA1
bpf: remove /system/etc/bpf from the loader
These directories are not populated on real devices
and are not part of the test suite.
This change removes them from the BPF loader.

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

Maciej Żenczykowski   commited 2025-06-16 01:28:45 -07:00
c041c4825b
Load bpfRingbufProg by rust bpfloader
No behavior change is expected.

Before this CL
"""
$ adb shell ls /etc/bpf/bpfRingbufProg.o
/etc/bpf/bpfRingbufProg.o
$ adb shell ls -lZ /sys/fs/bpf/*bpfRingbufProg*
-rw-rw---- 1 root root u:object_r:fs_bpf:s0  0 2025-05-28 12:40 /sys/fs/bpf/map_bpfRingbufProg_test_ringbuf
-r--r----- 1 root root u:object_r:fs_bpf:s0  0 2025-05-28 12:40 /sys/fs/bpf/prog_bpfRingbufProg_skfilter_ringbuf_test
"""

After this CL
"""
$ adb shell ls /etc/bpf/bpfRingbufProg.bpf
/etc/bpf/bpfRingbufProg.bpf
$ adb shell ls -lZ /sys/fs/bpf/*bpfRingbufProg*
-rw-rw---- 1 root root u:object_r:fs_bpf:s0  0 2025-05-28 15:12 /sys/fs/bpf/map_bpfRingbufProg_test_ringbuf
-r--r----- 1 root root u:object_r:fs_bpf:s0  0 2025-05-28 15:12 /sys/fs/bpf/prog_bpfRingbufProg_skfilter_ringbuf_test
"""

Test: Loaded successfully on kernel 5.10, 5.15, 6.1, 6.12
Test: Load is skipped on user build
Bug: 410982483
Change-Id: I17563ea55a34d216c0d3ccd100a19ca52aa4d7ac

Motomu Utsumi   commited 2025-05-30 16:15:21 +09:00
87f696e2c3
Fix the group of gpu_mem_total_map
Test: adb shell ls -lZ /sys/fs/bpf/*gpuMem_*
Bug: 410982483
Change-Id: I4576d219c5a22164c3b7d57a27f58bde272802cf

Motomu Utsumi   commited 2025-05-28 16:19:27 +09:00
bebda53162
Skip loading bpfMemEventsTest on user build
bpfMemEventsTest is installed only on debuggable devices.

Test: TH
Bug: 410982483
Change-Id: Ibf21f0cd639881058580d473dd0aae80bf3c480d

Motomu Utsumi   commited 2025-05-28 15:48:21 +09:00
9f53399e6c
Merge changes I471532a8,Ic1301be9,I076aed22,I156024bf,I2d2f4d09, ... into main
* changes:
  Allow rust bpfloader to load filterPowerSupplyEvents.bpf
  Allow rust bpfloader to load bpfRingbufProg.bpf
  Allow rust bpfloader to load bpfMemEventsTest.bpf
  Allow rust bpfloader to load bpfMemEvents.bpf
  Allow rust bpfloader to load gpuWork.bpf
  Allow rust bpfloader to load gpuMem.bpf

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-26 06:22:24 -07:00
7714bcfe30
Merge "Allow bpfloader to skip loading bpf object on user build" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-26 01:53:21 -07:00
5be3ce428e
Merge "Fix C++23 build: add missing #include." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-25 19:41:11 -07:00
87ff39a16b
Allow rust bpfloader to load filterPowerSupplyEvents.bpf
Test: TH
Bug: 410982483
Change-Id: I471532a80ea872191f1ae880d3c5de2937d289ba

Motomu Utsumi   commited 2025-05-26 10:13:24 +09:00
f89e35a924
Allow rust bpfloader to load bpfRingbufProg.bpf
Test: TH
Bug: 410982483
Change-Id: Ic1301be9a49935f4845d09d70d6b80d215dce5fa

Motomu Utsumi   commited 2025-05-26 10:13:21 +09:00
256af2c856
Allow rust bpfloader to load bpfMemEventsTest.bpf
Test: TH
Bug: 410982483
Change-Id: I076aed2206e47c9432628d4383edf9e64159ee67

Motomu Utsumi   commited 2025-05-23 11:46:25 +09:00
f088c4a66e
Allow rust bpfloader to load bpfMemEvents.bpf
Test: TH
Bug: 410982483
Change-Id: I156024bf130c1a808d657b9b501b64d2ae0d607b

Motomu Utsumi   commited 2025-05-23 11:46:25 +09:00
d8506e9151
Allow rust bpfloader to load gpuWork.bpf
Test: TH
Bug: 410982483
Change-Id: I2d2f4d0995eb8533751c91465afcdc71619375cd

Motomu Utsumi   commited 2025-05-23 11:46:25 +09:00
3023601201
Allow rust bpfloader to load gpuMem.bpf
Test: TH
Bug: 410982483
Change-Id: Ie801f58d8cb338bb99af2010c8a693c13c16579d

Motomu Utsumi   commited 2025-05-23 11:46:25 +09:00
8b9682001f
Allow bpfloader to skip loading bpf object on user build
Test: TH
Bug: 410982483
Change-Id: Ic13708deccefa330ce0c584fb6b0d0151fb872ed

Motomu Utsumi   commited 2025-05-23 11:45:51 +09:00
a1f21dd717
Remove platform C++ bpfloader test
C/C++ platform bpf loader is being replaced by rust version.

This test never had much value, and additional relies on
a sepolicy violation being allowed by su.

The bpf ring buf test is far better.

Test: TreeHugger
Flag: EXEMPT test code removal
Signed-off-by: Maciej Żenczykowski maze@google.com>
Change-Id: I448cc543aa9a0c161515ae2189020bf98db7bca3

Maciej Żenczykowski   commited 2025-05-22 14:10:18 -07:00
d93083a979
Fix C++23 build: add missing #include.
Change-Id: I21ab3f589ba1c9c0df4570264c9a25bc8c2ee427

Elliott Hughes   commited 2025-05-22 15:42:22 -04:00
7d08e8803d
Fix kernel version check for program loading
Before this CL, the kernel version check occurred after all programs
were loaded by `open_file.load()`.

This CL moves the check before `open_file.load()`. It calls
`prog.set_autoload(false)` for programs incompatible with the current
kernel, preventing their auto-load by libbpf.

Test: Verify the program is not loaded if the kver is out of range
Bug: 410982483
Change-Id: Ifacd9dd8696a7bb4fd186ad1faf01fba9f021c6d

Motomu Utsumi   commited 2025-05-21 15:29:27 +09:00
315feea5fc
Fix kernel version check for map loading
Before this CL, the kernel version check occurred after all maps
were loaded by `open_file.load()`.

This CL moves the check before `open_file.load()`. It calls
`map.set_autocreate(false)` for maps incompatible with the current
kernel, preventing their auto-creation by libbpf.

Test: Verify the map is not loaded if the kver is out of range
Bug: 410982483
Change-Id: I7a102dd2ef4b24f87c6efa5a105848fddc08d501

Motomu Utsumi   commited 2025-05-21 15:10:28 +09:00
91e5b0ba66
Load fuseMedia.bpf
Bug: 410982483
Test: adb shell ls /etc/bpf/
Test: adb shell ls /sys/fs/bpf/
Test: adb logcat | grep -i bpf
Change-Id: I609707e0c3767bf7098b3f96e9c8aeb0fe3afe5e

Motomu Utsumi   commited 2025-05-20 15:25:00 +09:00
7f3f0f1c78
Skip pinning .rodata array map
libbpf creates an array map for the .rodata section to allow BPF
programs to access its data. However, the loader does not need
to pin this map as userspace processes do not require access to it.

This does not break existing code as the legacy bpfloader did not
create a map for .rodata.

Bug: 410982483
Test: TH
Change-Id: I036c93849731c25e8d1b6a2c1778ffc60935bbe2

Motomu Utsumi   commited 2025-05-20 15:18:17 +09:00
294bb70ec9
Skip loading unexisting bpf object while BPF loader migration
This makes bpfloader.rs simpler while BPF loader migration.

Bug: 410982483
Test: TH
Change-Id: I32fbbaed3efed45b5297634dbcfc7c80132cabc8

Motomu Utsumi   commited 2025-05-20 14:57:13 +09:00
a6a915dd12
Explicitly set bpf fuse program type for fuse/ programs
This is a no-op for existing timeInState.bpf

Bug: 410982483
Test: TH
Change-Id: Iaedc96c673241ffb2d040db17c5119a23543c923

Motomu Utsumi   commited 2025-05-19 13:37:50 +09:00
1b036d6475
Explicitly set SocketFilter type for skfilter/ programs
This is a no-op for existing timeInState.bpf

Bug: 410982483
Test: TH
Change-Id: Ie73a9f99b591ae730c91988ab67e36d2a13729ce

Motomu Utsumi   commited 2025-05-19 13:21:58 +09:00
519bf2e7fd
Use GID_SYSTEM alias to improve readability.
Bug: 410982483
Test: TH
Change-Id: I5618ab07fc6721a667157f9e4d61854394a8e1bb

Motomu Utsumi   commited 2025-05-19 10:43:03 +09:00
16be5d0aab
Change argument order for MapDesc::new and ProgDesc::new
This improves readability.

Bug: 410982483
Test: TH
Change-Id: Ia2ae417f28a92866cd971db7b7b2229d49aa4b63

Motomu Utsumi   commited 2025-05-19 10:07:14 +09:00
9e359a4d54
Support specifying owner and group for each map and prog
Currently, the owner and group apply to each BPF object file.
However, each map and program can specify a different owner and group,
even if they are in the same BPF object file.

This is a no-op for existing timeInState.bpf

Bug: 410982483
Test: TH
Change-Id: I0fa2731385645e598b4d3bb7d27200dbb6d3a8ec

Motomu Utsumi   commited 2025-05-16 15:07:13 +09:00
c1e1ad596f
Add test for parsing kernel release string
Test: atest bpfloader_tests
Bug: 410982483
Change-Id: I09ace37a2624b08e96a91374a59e7d8df3bcce90

Motomu Utsumi   commited 2025-05-16 15:07:13 +09:00
5076bd332d
Add kernel version check for prog and map
This is a no-op because maps and progs of timeInState are always loaded.
They have min_kver: KVER_NONE and max_kver: KVER_INF.

Bug: 410982483
Test: atest bpfloader_tests with next CL
Change-Id: I5db1909126fb3ca43939f39653f8a2334f130e94

Motomu Utsumi   commited 2025-05-16 15:07:08 +09:00
bc4f085435
Add min_kver and max_kver fields to MapDesc and ProgDesc
This is a no-op.

Bug: 410982483
Test: TH
Change-Id: Ia09667b95c2d534b4b204fea4656e7db3e27e6c6

Motomu Utsumi   commited 2025-05-16 10:13:28 +09:00
9d6cb3567b
Create /sys/fs/bpf dir to pin bpf maps and progs
This is a no-op because maps and progs of timeInState are pinned under
/sys/fs/bpf/ and this directory already exists.

Bug: 410982483
Test: timeInState.bpf loaded successfully
Change-Id: Ied42ebcbde5c8727f19c31b8dc9930dac2ef5f79

Motomu Utsumi   commited 2025-05-16 10:13:23 +09:00
84b3a97525
Add dir and prefix fields to BpfFileDesc
The "dir" field specifies the directory where the BPF file is located.
The "prefix" field specifies the subdirectory under
/sys/fs/bpf/ where maps and programs are pinned.
These fields are required for memevents and vendor bpf.

This CL is a no-op for the existing timeInState.bpf loading

Bug: 410982483
Test: timeInState.bpf loaded successfully
Change-Id: Ic509b19490b9561173f84ace10d68c7725f8055b

Motomu Utsumi   commited 2025-05-14 12:59:22 +09:00
4f1cdd4f91
Enable libbpf log in bpf loader
Bug: 410982483
Test: TH
Change-Id: I20b08db4e1b33c7654feb209cf0fd0ff4a0d96a6

Motomu Utsumi   commited 2025-04-23 16:57:59 +09:00
f349602777
Remove support for the RELEASE_BPF_ENABLE_LIBBPF flag
This flag has already been released, so the code path
for its disabled state can now be removed.

Test: TH
Bug: 359646531
Bug: 410982483
Change-Id: Ia211fe240e6687e00470a9fb9350a2a7ae089580

Motomu Utsumi   commited 2025-04-23 13:24:26 +09:00
e6c62af6f3
Add -Wshadow to bpf_cc_defaults
Test: m
Change-Id: I08899d0c1bbdb05c3a2ef7df4b0debe748c25d94

Motomu Utsumi   commited 2025-03-21 16:27:05 +09:00
c52a98dde5
platform BpfLoader: drop support for uprobestats
this has moved to mainline via apex

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

Maciej Żenczykowski   commited 2025-03-10 18:24:05 -07:00
c799e7610f
BpfLoader-rs: Load libbpf programs
Loader for libbpf based programs. It successfully
loads timeInState.bpf and pins its maps and programs to bpffs.

Bug: 359646531
Test: atest libtimeinstate_test
Change-Id: I9eaba3a15ea3af2eff2cb819bff8925e781e3c2a
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-11-22 20:40:43 +00:00
d036b6f113
bpfloader-rs: implement rust native logging
Add a logger to enable rust native logging to kmsg on errors (and
therefore also to the serial port). Because bpfloader runs early in the
init process, errors could cause the boot to fail and therefore we
require the messages to go to the serial port to debug.

Bug: 359646531
Test: manual/TH
Change-Id: If3c5963fd17dea101769b844b970c7e2d6dd93c9
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-11-06 16:20:13 +00:00
cbb87b6c97
BpfLoader: remove unnecessary logging functionality
With the addition of aosp/3294153, we no longer need the c logging
functionality exposed to rust, so remove them

Bug: 359646531
Test: Manual
Change-Id: Ia6f61263f3315fe7dd3533556d9a5fdd2726a2b3
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-10-04 21:10:13 +00:00
ba0666388b
BpfLoadTest: change some EXPECT's to ASSERT's
This should hopefully cause test failures to be clean test failures instead of hitting abort() and bringing down the entire test framework.

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

Maciej Żenczykowski   commited 2024-09-17 00:04:20 +00:00
f381ae9268
BPF: rename bpf_defaults to bpf_cc_defaults
With the addition of defaults to the bpf soong module (see aosp/3249485
), the name `bpf_defaults` will be used to define defaults for bpf
program compilation. While there are separate soong namespaces for
module types and module names, rename the existing bpf_defaults
cc_defaults to bpf_cc_defaults for clarity.

While we're at it, add -Wextra, and cleanup unnecessary cflags in
clauses which use bpf_cc_defaults.

Test: TH
Change-Id: Ia6e69a7ae447490ddc7bc3e08f2d07753bae0eac
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-09-13 18:01:02 +00:00
19a5ec2f66
Merge "Adding memevents subdirectory for bpf" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-09-05 05:40:29 +00:00
ea44c94fbf
Adding memevents subdirectory for bpf
Create new memevents subdirectory to contain bpf related files for
libmemevents. Memevents-bpf are used to listen to kernel tracepoints
(BPF_PROG_TYPE_TRACEPOINT), and skfilter bpf progrs to inject mock data
for testing purposes (BPF_PROG_TYPE_SOCKET_FILTER).

Test: Verified memevents-bpf files are loaded in new subdir
Bug: 330396528
Change-Id: I57f7738f6a9eb18293cf9c51e0d1da2b2c1ebfe4
Signed-off-by: Carlos Galo <carlosgalo@google.com>

Carlos Galo   commited 2024-09-04 22:10:24 +00:00
0621b1e0a1
Merge "BPF: Implement build time feature flag for libbpf" into main
Neill Kapron   authored and   Gerrit Code Review   commited 2024-08-23 20:04:27 +00:00
e9d3f9c0ff
BPF: Implement build time feature flag for libbpf
For trunk stable development, we use a build time feature flag for the
libbpf functionality to be added to bpfloader. For now, simply stub it
out.

This approach will allow merging and testing of libbpf functionality
without changing the binaries produced with the feature disabled going
forward.

Bug: 359646531
Test: manual/treehugger
Change-Id: I230e81b5f23b49a17f3731e0c40e184cde1c49c1
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-08-23 16:43:51 +00:00
01249cb13d
BpfLoader: adjust for change to bpf_map_def.h location
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iebd599d12f502c3cb8e030d53aae5e95c19e21ef

Maciej Żenczykowski   commited 2024-08-21 13:21:16 -07:00
1b44455113
BpfLoader: split bpffs subdir creation out
Needs to be before program loading, this should eventually allow loading programs in parallel.

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

Maciej Żenczykowski   commited 2024-08-13 20:04:18 +00:00
7ff8310ea2
bpf: remove no longer used expected attach type
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I513d9b22bf57a19d1b33cd37bf3a6f3ae06d969f

Maciej Żenczykowski   commited 2024-08-12 17:41:26 +00:00
119ad75c4b
BPF: Create rust bpfloader
In preparation for adding libbpf support via libbpf-rs, replace the
existing cpp bpfloader with a rust application calling into the
libbpf_android bindings to the legacy code.

Test: treehugger
Change-Id: I79eff1fece3372727c700308ff9a35029d0e34d3
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-08-08 00:08:58 +00:00
dd93f853bc
BPF: add rust bindgen for libbpf_android
Add bindgen rules to create rust bindings for libbpf_android. This will
be used to provide the legacy bpf support in the new rust bpfloader.

Test: treehugger
Change-Id: I22f7b38d6ccb25d4d1f61d9f6e672ab6f6abe42e
Signed-off-by: Neill Kapron <nkapron@google.com>

Neill Kapron   commited 2024-08-08 00:05:39 +00:00
e3fc91e755
BpfLoader: split legacy bpfloader into 3 phases, simplify arguments
Should make integration with BpfLoader written in rust easier.

While at it add simple wrappers around ALOG{V,D,I,W,E}(),
which may come in handy as bpfloader runs early enough that
logging must be to the kernel dmesg ringbuffer instead...

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

Maciej Żenczykowski   authored and   Neill Kapron   commited 2024-08-07 21:20:02 +00:00
dd4bd2d655