Commit graph android_system_bpf/include
Message SHA1
bpf: vmlinux: Add OWNERS
Bug: 421990777
Test: N/A
Change-Id: I89a4c1d2b908f997c92eaa210f2006420e7a30cf
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-06-20 14:40:47 -07:00
d2852e8687
bpf: vmlinux: Remove android15_6.6 headers
These are now generated by the build system when needed.

Bug: 421990777
Test: m
Change-Id: I961ba203989325e58428a7b3068326fc89debaa8
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Kalesh Singh   commited 2025-06-20 12:04:31 -07:00
a6156a9122
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 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
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
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
Add LLVM eBPF builtins methods to android_bpf_defs.h
Bug: 410982483
Test: m filterPowerSupplyEvents.o filterPowerSupplyEvents.bpf
Change-Id: I52eb9623fd73ebd5620482ba3bdf5f303ebf2958

Motomu Utsumi   commited 2025-05-14 12:41:56 +09:00
886a957f4c
Add libbpf_prog bpfRingbufProg.bpf target
This is a preparation for migrating to the Rust platform bpfloader.

Bug: 410982483
Test: m bpfRingbufProg.bpf bpfRingbufProg.o
Change-Id: I094635be14e56aac53384ac517538c2587367c44

Motomu Utsumi   commited 2025-05-12 16:58:02 +09:00
fbadb82001
Define CRITICAL as no-op for libbpf_prog
Test: m bpfRingbufProg.bpf
Change-Id: I874cadca706f7ae9964ad7d2981884320cc20d68

Motomu Utsumi   commited 2025-05-12 16:55:06 +09:00
26d2b1c73f
Fix __always_inline macro conflict and add linux/bpf.h include
The bpf_helpers.h in libbpf defines the `__always_inline` macro
using the `inline` keyword (`inline __attribute__((always_inline))`).
`cdefs.h` defines `__always_inline` using only the attribute
(`__attribute__((__always_inline__))`).

This leads to "duplicate 'inline' declaration" errors depending on the order
in which these headers are included.

To prevent such conflicts, this CL explicitly redefines
`__always_inline` using `__attribute__((__always_inline__))` immediately
after including <bpf/bpf_helpers.h>.

This CL also adds an include of <linux/bpf.h> for BPF map types
(e.g. BPF_MAP_TYPE_RINGBUF).

Bug: 410982483
Test: m bpfMemEvents.bpf bpfMemEventsTest.bpf
Change-Id: Ib55805c09a7946b537f55512f9d88141b561e0ab

Motomu Utsumi   commited 2025-05-12 15:23:02 +09:00
4ed7d8f093
Add DEFINE_BPF_RINGBUF to android_bpf_defs.h
Test: m bpfMemEvents.bpf bpfMemEventsTest.bpf
Bug: 410982483
Change-Id: I30eacdc39a4307b446bc51dfbd69fe0d3f48713b

Motomu Utsumi   commited 2025-05-12 12:36:30 +09:00
728276f83c
Add DEFINE_BPF_PROG_KVER to android_bpf_defs.h
Bug: 410982483
Test: m bpfMemEvents.bpf bpfMemEventsTest.bpf
Change-Id: I97b7cbe5d033dbe4b15a52b1487e9ace3d12ee7d

Motomu Utsumi   commited 2025-05-12 12:10:18 +09:00
867009fdab
BPF: Create android_bpf_defs
Create a new header lib to assist with the transition between bpf and
libbpf.

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

Neill Kapron   commited 2024-11-22 19:12:30 +00:00
644d336d2c
BPF: Add vmlinux.h
Generated from aosp_kernel-common-android15_6.6 build 12345991
Tagged as android15-6.6-2024-08-r7

These vmlinux.h files are used for bpf programs leveraging CO-RE to
access internal kernel data structures. They do not need to track the
target kernel perfectly, but if fields are added to an internal kernel
data structure, they must be regenerated before these fields are used.

Similarly, the BPF programs which use vmlinux.h should be compiled
against a vmlinux.h file which is generated from the vmlinux of the same
architecture. On Android, this is not a problem for arm64 or x86_64
architectures, as the 64bit system userspace matches the 64bit kernel.

However, for 32 bit Android userspace, either arm or x86, we currently
have no way to determine at build time if the kernel we will be running
on will be 32bit or 64bit. For this reason, we default to 32bit
userspace running on 64bit kernel, and therefore loading libbpf programs
will be disabled at runtime for systems with 32bit kernels.

In the future, it would be good to create the infrastructure to
periodically update this to a version with the latest tracking kernel.

vmlinux.h files are manually generated using the following command:

bpftool btf dump file <path/to/vmlinux> format c > vmlinux.h

The vmlinux artifact can be downloaded through this process:

Navigate to
https://source.android.com/docs/core/architecture/kernel/gki-android15-6_6-release-builds#launch-releases

and identify the link to the latest release kernel artifacts, in this
case android15-6.6-2024-08-r7 is linked to
https://ci.android.com/builds/submitted/12345991/kernel_aarch64/latest

Appending '/vmlinux' to the end will take you directly to the artifact
download for aarch64.

Change the 'kernel_aarch64' path to 'kernel_x86_64' to download the
x86_64 vmlinux file.

The final download paths for the vmlinux files used in this change are:
https://ci.android.com/builds/submitted/12345991/kernel_aarch64/latest/vmlinux
https://ci.android.com/builds/submitted/12345991/kernel_x86_64/latest/vmlinux

Internally, this can be done with:
/google/data/ro/projects/android/fetch_artifact --bid 12345991 --target kernel_aarch64 'vmlinux'
/google/data/ro/projects/android/fetch_artifact --bid 12345991 --target kernel_x86_64 'vmlinux'

Using bpftool v7.3.0 with libbpf v1.3 with llvm, skeletons enabled:

cd system/bpf/imclude/vmlinux/arm64/
<cp aarch64 vmlinux file here>
bpftool btf dump file vmlinux format c > vmlinux.h
rm vmlinux

cd ../x86_64
<cp x86_64 vmlinux file here>
bpftool btf dump file vmlinux format c > vmlinux.h
rm vmlinux

For future automation use, the following command may be useful in
identifying the latest kernel release tag:

git -c  'versionsort.suffix=-' ls-remote --tags --refs \
https://android.googlesource.com/kernel/common/ android15-6.6-202\* \
| tail --lines=1

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

Neill Kapron   commited 2024-09-17 22:13:54 +00:00
432d150808