Commit graph android_system_bpf/loader
Message SHA1
vendorBpfLoader: remove printing of map/prog ids
Really just spurious logging code.

If you're working on a device (as opposed to looking at bugreports)
you can get this information with for example 'bpftool':

$ adb shell bpftool map show pinned '/sys/fs/bpf/map_bpfRingbufProg_test_ringbuf'
77: ringbuf  name test_ringbuf  flags 0x0
        key 0B  value 0B  max_entries 4096  memlock 16696B

$ adb shell bpftool prog show pinned /sys/fs/bpf/vendor/prog_filterPowerSupplyEvents_skfilter_power_supply
82: socket_filter  name skfilter_power_  tag b8b4693584760391
        loaded_at 2025-07-16T08:44:56-0700  uid 0
        xlated 848B  jited 470B  memlock 4096B

Test: TreeHugger
Flag: EXEMPT cleanup
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie7baf7cf5df9c25ad2d159767584670361e8c6eb

Maciej Żenczykowski   commited 2025-07-16 08:47:49 -07:00
77f8e9e373
vendorBpfLoader: remove mapMatchesExpectations() check
This was primarily meant as a safety check for mainline,
it's not really needed in platform bpf loader.

Test: TreeHugger
Flag: EXEMPT cleanup
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I615f54f10baa75f641129507ecce9159ff31a740

Maciej Żenczykowski   commited 2025-07-16 08:39:23 -07:00
d9201c1612
vendorBpfLoader: change single line, end-of-line /* */ comments to //
Test: TreeHugger
Flag: EXEMPT cleanup
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibc2b32b3a07a1115489b373a97827625fa27ff10

Maciej Żenczykowski   commited 2025-07-16 08:35:43 -07:00
b902e1c254
vendorBpfLoader: kernel is guaranteed to be 5.4+
(even 5.10+)

Test: TreeHugger
Flag: EXEMPT cleanup
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4c9a2a222071095559b1605d4417f93eecf4667f

Maciej Żenczykowski   commited 2025-07-16 08:33:02 -07:00
174cddec91
vendorBpfLoader: move /sys/fs/bpf/vendor creation to rust
We continue to have:
  $ adbz shell ls -lZ /sys/fs/bpf /sys/fs/bpf/vendor
  /sys/fs/bpf:
  total 0
  ...
  drwxrwxrwt 2 root root     u:object_r:fs_bpf_vendor:s0          0 2025-07-16 00:09 vendor

  /sys/fs/bpf/vendor:
  total 0
  -r--r----- 1 root system u:object_r:fs_bpf_vendor:s0  0 2025-07-16 00:09 prog_filterPowerSupplyEvents_skfilter_power_supply

Test: TreeHugger
Flag: EXEMPT no-op
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I74d87a6f382e3b1bc10a8eb82915bc340568f2a8

Maciej Żenczykowski   commited 2025-07-16 00:09:47 -07:00
d29bd0b4ca
vendorBpfLoader: no need for locations array
Afterwards we still have:
  I BpfLoader: Platform BpfLoader loading critical for healthd ELF object /vendor/etc/bpf/filterPowerSupplyEvents.o with license Apache 2.0
  W BpfLoader: No maps section could be found in elf object
  D BpfLoader: prog /sys/fs/bpf/vendor/prog_filterPowerSupplyEvents_skfilter_power_supply id 82

  $ adbz shell ls -lZ /sys/fs/bpf /sys/fs/bpf/vendor
  /sys/fs/bpf:
  total 0
  ...
  drwxrwxrwt 2 root root     u:object_r:fs_bpf_vendor:s0          0 2025-07-15 23:53 vendor

  /sys/fs/bpf/vendor:
  total 0
  -r--r----- 1 root system u:object_r:fs_bpf_vendor:s0  0 2025-07-15 23:53 prog_filterPowerSupplyEvents_skfilter_power_supply

Test: TreeHugger
Flag: EXEMPT no-op
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I66a6fc3abf8f5c4c52f6a47476c251e97f1f6e14

Maciej Żenczykowski   commited 2025-07-15 23:57:34 -07:00
c30b4f8bee
vendorBpfLoader: no need for allowedProgTypes
(while at it remove fuse bpf support, which isn't needed for vendor)

Test: TreeHugger
Flag: EXEMPT no-op
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic7293b94644d933a908a252ab794ae64f88b5865

Maciej Żenczykowski   commited 2025-07-15 23:50:52 -07:00
0e2f1cc28b
simplify libbpf_android.h
Test: TreeHugger
Flag: EXEMPT trivial
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I39f73afef65b22b1d275742758aff7745991d9e7

Maciej Żenczykowski   commited 2025-07-15 23:40:18 -07:00
8b3ea0a274
Give all users access to CPU time in state bpf maps.
We want to read this from traced_probes, which is AID_NOBODY. And
SELinux does a far more thorough job of controlling access than Unix
permissions do.

Bug: 422976190

Test: ls -l, and checked WIP traced_probes implementation.
Change-Id: I51a6486c5d7bf85f922f79a89a7a7fbdb9bc79f2

Simon MacMullen   commited 2025-06-30 08:54:29 -07:00
5781bd4a22
Move CPU time in state bpf maps to their own dir,
This will allow us to use a genfscon SELinux rule to get finer grained access control.

Bug: 422976190

Test: Recorded a Perfetto trace with statsd atom  CPU_CYCLES_PER_UID_CLUSTER, tested manually with go/atomtester.
Change-Id: Ic16da605b9d7150d42176c428f0e1ecaf4a9472f

Simon MacMullen   commited 2025-06-26 16:31:52 +00:00
8546ea34c6
Merge "Use platform bpf_helpers.h and bpf_map_def.h for platform bpfloader" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-06-18 04:40:48 -07:00
16e017f20e
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
Use platform bpf_helpers.h and bpf_map_def.h for platform bpfloader
Platform BPF programs rely on platform bpf_helpers.h and bpf_map_def.h.
To ensure consistency and correctness, the loader must use these platform
headers instead of those from p/m/Connectivity.

Bug: 424341374
Test: TH
Change-Id: Id5f1bc8fdd29e54c28a3ec9e01f6a9292f6bb9e1

Motomu Utsumi   commited 2025-06-13 13:04:02 +09:00
1f5cd4b9a1
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