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>
diff --git a/Android.bp b/Android.bp
index 9a17183..dca9aba 100644
--- a/Android.bp
+++ b/Android.bp
@@ -15,6 +15,24 @@
],
}
+cc_library_headers {
+ name: "vmlinux15_6.6",
+ arch: {
+ arm: {
+ export_include_dirs: ["include/vmlinux/android15_6.6/arm64"],
+ },
+ arm64: {
+ export_include_dirs: ["include/vmlinux/android15_6.6/arm64"],
+ },
+ x86: {
+ export_include_dirs: ["include/vmlinux/android15_6.6/x86_64"],
+ },
+ x86_64: {
+ export_include_dirs: ["include/vmlinux/android15_6.6/x86_64"],
+ },
+ },
+}
+
cc_defaults {
name: "bpf_cc_defaults",
cflags: [