Commit graph

2,478 commits

Message SHA1
bpf: vmlinux: Update Readme
Convert readme to markdown; refactor existing descriptions;
add instructions on how to add vmlinux.h for new kernels.

Bug: 421990777
Test: N/A
Change-Id: Idc61221e729d034c5fedb458bd18db02fade713a
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-06-20 11:47:41 -07:00
9462a3d7aa
Merge "bpfloader: refactor C++ loader to just one function" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-17 05:56:59 -07:00
32075d5ef9
bpfloader: refactor C++ loader to just one function
no need for the complexity, as it is only for vendor now

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

Maciej Żenczykowski   commited 2025-06-17 04:18:41 -07:00
d689e6e01a
make platform bpfloader require bpftool cli
Test: TreeHugger
Flag: EXEMPT adds as yet unused cli tool
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib6c2be3c40338743f3482010d7500fef8964adc6

Maciej Żenczykowski   commited 2025-06-17 03:55:14 -07:00
7d62694b8f
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
Merge changes from topic "bpf_header_files1" into main
* changes:
  Remove unused bpfRingbufProg.o
  Add copy of bpf header files for platform use

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-13 04:32:44 -07:00
821600428c
Remove unused bpfRingbufProg.o
Test: TH
Bug: 410982483
Change-Id: Ib2fdedc63d5503aca38757f020fbe0466bbaca83

Motomu Utsumi   commited 2025-06-13 12:14:20 +09:00
e0fd4cdc6c
Add 6.1 vmlinux.h genrules
Generate vmlinux.h from the kernel prebuilt vmlinux

Bug: 421990777
Test: Manual; build bpf prog with "vmlinux_h_6_1" header
Change-Id: Ib1b7a24c470610ea6d1ee6c84f1c656e7139340b
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-06-12 09:33:39 -07:00
2e61afb442
Add copy of bpf header files for platform use
$ cp packages/modules/Connectivity/bpf/headers/include/bpf_helpers.h system/bpf/include/bpf/
$ cp packages/modules/Connectivity/bpf/headers/include/bpf_map_def.h system/bpf/include/bpf/

Bug: 424341374
Test: TH
Change-Id: I81eb6485956a1674c1c23b8ff91599862446061e

Motomu Utsumi   commited 2025-06-12 16:58:12 +09:00
64550b51c5
Add 6.6 vmlinux.h genrules
Generate vmlinux.h from the kernel prebuilt vmlinux

Bug: 421990777
Test: Manual; build bpf prog with "vmlinux_h_6_6" header
Change-Id: I6b172b1dd13dfc9750a9075616c596916d1473a9
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-06-11 15:45:46 -07:00
7a037f8346
Add 6.12 vmlinux.h genrules
Generate vmlinux.h from the kernel prebuilt vmlinux

Bug: 421990777
Test: Manual; build bpf prog with "vmlinux_h_6_12" header
Change-Id: I5647a3c2d7d1695aa42fd9636dd7f7abd4a1dc44
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-06-11 15:41:44 -07:00
655664e3cd
Merge "Load bpfRingbufProg by rust bpfloader" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-06-02 00:33:05 -07:00
a2c132b118
Merge "Fix the group of gpu_mem_total_map" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-06-02 00:32:15 -07:00
0a3358f0ea
Merge "Skip loading bpfMemEventsTest on user build" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-06-02 00:31:45 -07:00
6d7d61e364
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
Merge "bpf: Fix double inclusions" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-29 15:10:18 -07:00
c8789bf207
bpf: Fix double inclusions
Don't include <linux/bpf.h> if using vmlinux; as this causes
double inclusions.

Bug: 419635765
Test: manual; build and load a CO-RE BPF program
Change-Id: I4419778ea71b65ce46ac5e0e6358c33d7f78b82e
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-05-29 13:33:01 -07:00
0227ca2982
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 "KVER_5_8 -> KVER_5_10 for program that depends on ringbuf" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-05-26 00:17:01 -07:00
413aa0645f
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
Merge "Remove platform C++ bpfloader test" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-05-23 04:34:44 -07:00
3532e597aa
TEST_MAPPING: remove libbpf_load_test
(the test is being removed as it tests the obsolete C++
 platform bpf loader)

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

Maciej Żenczykowski   commited 2025-05-23 03:00:08 -07:00
87674a8141
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
KVER_5_8 -> KVER_5_10 for program that depends on ringbuf
ringbuf_test depends on the ring buffer that is loaded on 5.10+ kernel.

Test: TH
Bug: 410982483
Change-Id: If9d6a7f4483655cd5931bf64acfe34239f72cbe1

Motomu Utsumi   commited 2025-05-22 17:19:55 +09:00
92460e1c89
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