Snap for 13683512 from d6c84caf3e to 25Q4-release
Change-Id: I98a365588ac49570b4d8c09dd3c60749130d25af
This commit is contained in:
commit
ce70511e4b
6 changed files with 34 additions and 298709 deletions
18
Android.bp
18
Android.bp
|
|
@ -15,24 +15,6 @@ license {
|
|||
],
|
||||
}
|
||||
|
||||
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_library_headers {
|
||||
name: "android_bpf_defs",
|
||||
export_include_dirs: ["include/defs"],
|
||||
|
|
|
|||
3
include/vmlinux/OWNERS
Normal file
3
include/vmlinux/OWNERS
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
kaleshsingh@google.com
|
||||
nkapron@google.com
|
||||
tjmercier@google.com
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
These vmlinux.h files are manually generated using the following command:
|
||||
|
||||
bpftool btf dump file <path/to/vmlinux> format c > vmlinux.h
|
||||
|
||||
In the future, it would be good to create the infrastructure to periodically update this to a version with the latest tracking kernel.
|
||||
|
||||
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.
|
||||
31
include/vmlinux/README.md
Normal file
31
include/vmlinux/README.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
## Understanding `vmlinux.h` in BPF
|
||||
|
||||
The `vmlinux.h` header is crucial for building BPF (Berkeley Packet Filter) programs that inspect core kernel data structures.
|
||||
|
||||
|
||||
### What is `vmlinux.h`?
|
||||
|
||||
`vmlinux.h` is a C header file that contains the layout of internal kernel data structures. This allows a BPF program to access internal information from the kernel. BPF programs that inspect internel kernel data structures should utilize a feature called CO-RE (Compile Once - Run Everywhere). In essence, CO-RE allows BPF programs to work safely across different kernel versions without needing to be recompiled for each one.
|
||||
|
||||
NOTE: While a BPF program doesn't need a `vmlinux.h` file that perfectly matches the target kernel, it's important to regenerate it in some cases. For instance, if the program makes use of a new field added to a structure, you must create a new vmlinux.h to access that new field.
|
||||
|
||||
### How is `vmlinux.h` Generated?
|
||||
|
||||
A `vmlinux.h` file is created from a `vmlinux` file (the raw, uncompressed kernel image with BTF info) using the `bpftool` utility. The command for this is:
|
||||
|
||||
```sh
|
||||
bpftool btf dump file /path/to/vmlinux format c > vmlinux.h
|
||||
```
|
||||
|
||||
### Architecture Considerations on Android
|
||||
|
||||
A BPF program must be compiled with a vmlinux.h file that matches the architecture of the target kernel.
|
||||
|
||||
+ *`64-bit` Systems*: On `64-bit` Android systems (either `arm64` or `x86_64`), this is straightforward. The `64-bit` userspace (where the application runs) matches the `64-bit` kernel.
|
||||
+ *`32-bit` Systems*: This is more complex on devices with a `32-bit` Android userspace (arm or x86). At the time the BPF program is built, it's impossible to know if the device's kernel will be `32-bit` or `64-bit`. Because of this uncertainty, the system defaults to assuming a `32-bit` userspace running on a `64-bit` kernel. As a result, BPF programs that rely on libbpf will be disabled at runtime on systems that have a `32-bit` kernel.
|
||||
|
||||
### How to Generate vmlinux.h for New Kernels
|
||||
|
||||
When a new Android kernel version is released, a corresponding `vmlinux.h` can be generated by adding a new build rule to `system/bpf/include/vmlinux/Android.bp`.
|
||||
|
||||
You can do this by simply copying the existing rule for the latest kernel version and modifying it for the new one.
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue