The Alibaba Cloud Linux Kernel (ANCK) is a Linux kernel optimized by Alibaba Cloud. This topic describes how to use the eBPF features of ANCK.
Background information
The extended Berkeley Packet Filter (eBPF) is widely used in areas such as networking, tracing, and diagnostics due to its secure and programmable features. The features that eBPF supports are closely related to the kernel version. Some users or community components might use the kernel version number to determine whether a target kernel has specific eBPF capabilities. However, this practice is not recommended for ANCK. This is because ANCK enhances the standard kernel from the upstream community. For example, version 5.10.134-17 is based on the stable community kernel 5.10.134, but new features are continuously added to it. Therefore, ANCK includes the following:
All eBPF features from the upstream community 5.10 kernel.
New features introduced by the upstream community in later versions, such as 5.11 and higher, and in the
6.xseries kernels. Examples include newbpf progtypes andhelperfunctions.Important security patches (CVEs) and bug fixes.
Performance optimizations and enhancements.
Use eBPF features correctly
Check the eBPF features supported by the ANCK kernel
(Recommended) Check the official documentation
You can check the eBPF features for different versions in the ANCK ReleaseNotes.
Bpftool detection
(Optional) Run the following command to install the
bpftooltool.sudo yum install bpftoolRun the following commands to check the runtime environment.
Run the following command to view the exact kernel version.
uname -rRun the following command to probe for eBPF feature support.
sudo bpftool feature probeRun the following command to view the kernel's BPF Type Format (BTF) information.
bpftool btf dump file /sys/kernel/btf/vmlinux
Manual testing
To confirm the availability of a specific feature, write a minimal unit test program. Then, test whether the program can pass the kernel
verifierand run successfully after it is loaded.
Write standardized code
Use compatibility-focused constructs such as
BPF_CORE_READ.Refer to examples from the libbpf standard library and the upstream kernel's test programs.
Long-term maintenance
Continuously follow the ANCK ReleaseNotes.
Establish a test environment and mechanism. Run your test case suite when a new kernel is released.
Use eBPF CO-RE (Compile Once – Run Everywhere) and BTF symbol detection to improve compatibility.
Potential problems
Scenario 1: A program that loaded correctly suddenly fails to load
Symptoms
The program fails to load and returns an error message similar to the following:
libbpf: prog 'xxx': BPF program load failed: xxx
libbpf: prog 'xxx': -- BEGIN PROG LOAD LOG --
[verifier output ...]
-- END PROG LOAD LOG --Cause
The verifier in a new version of ANCK has stricter security requirements for BPF programs.
The code uses an operation with security risks.
The upstream community adjusted the behavior of certain operations, marking them as no longer safe or valid.
For example, the upstream community patch bpf: Allow delete from sockmap/sockhash only if update is allowed narrows the scope of
bpf_map_delete_elem(). Because some scenarios are now considered unsafe, an eBPF program that could previously call thishelperfunction might be rejected by the new kernel.
Solution
Test your program on the latest upstream Linux kernel.
If the upstream kernel also reports an error, check and modify your program code.
If the upstream kernel runs correctly, contact us to report the issue.
Scenario 2: Confusion about feature support
Symptoms
Other Linux distributions with a 5.10 kernel do not support certain features, but ANCK 5.10 supports them.
Cause
Support for the 5.10 kernel varies among different communities and distributions. They typically support the eBPF features from the upstream 5.10 kernel and earlier versions. Support for features from version 5.11 and later must be evaluated on a case-by-case basis.
References
For more information about the relationship between eBPF features and upstream kernel version numbers, see BPF Features by Linux Kernel Version.