CAP_BPF / CAP_SYS_ADMIN capabilities in container environments. Regular containers do not support running BPF tools by default.CONFIG_BPF=y (basic BPF support)CONFIG_BPF_SYSCALL=y (BPF system call)CONFIG_BPF_JIT=y (BPF JIT compilation)CONFIG_DEBUG_INFO_BTF=y (BTF support, required for CO-RE)CONFIG_BPF_LSM=y (LSM BPF support, required for security policy features)CONFIG_XDP_SOCKETS=y (XDP socket support, required for high-performance AF_XDP packet reception)dnf info bcc-tools bpftrace to check the specific versions of the BCC/bpftrace packages available on the current system.bpf-related modules are loaded (they are compiled into the kernel by default, so no additional modprobe is required).kernel-devel and kernel-headers packages that match the current kernel version.Function | Support Status | Mount Point | Typical Use |
XDP | Supported | NIC driver layer | High-performance packet processing and Anti-DDoS |
TC(Traffic Control) | Supported | Traffic control layer | Traffic classification and QoS |
cgroup sock | Supported | cgroup socket | Container network policies |
kprobe/kretprobe | Supported | Kernel function entry/exit | Kernel function tracing |
tracepoint | Supported | Kernel static tracepoint | System call tracing |
perf_event | Supported | Performance event | PMU event sampling |
uprobe/uretprobe | Supported | User function entry/exit | Application tracing |
LSM(BPF) | Supported (disabled by default; configure the lsm=tee,bpf boot parameter and restart. See step 7.) | Security hook point | Security Policies |
sock_ops | Supported | socket operations | TCP tuning |
sk_msg/sk_redirect | Supported | socket messages | Proxy redirection |
struct_ops | Supported | Struct operations | Custom TCP congestion control |
Limit | Value | Description |
Instruction quantity limit | 1 million entries (default, configurable) | Default value of the 6.6 kernel. It can be adjusted through kernel configuration. |
Stack size | 512 bytes | Use heap allocation to avoid this. |
Unprivileged user | Disabled by default | unprivileged_bpf_disabled values: 0 (allowed), 1 (disabled but can be changed back), 2 (disabled and cannot be changed back). The default value in TencentOS Server 4 is 0. |
Kernel version compatibility | CO-RE programs can work across kernel versions; non-CO-RE programs must match the kernel version. | Depends on BTF support. |
# Check basic kernel BPF configurationgrep CONFIG_BPF=y /boot/config-$(uname -r)# Expected output: CONFIG_BPF=ygrep CONFIG_BPF_SYSCALL=y /boot/config-$(uname -r)# Expected output: CONFIG_BPF_SYSCALL=ygrep CONFIG_BPF_JIT=y /boot/config-$(uname -r)# Expected output: CONFIG_BPF_JIT=ygrep CONFIG_XDP_SOCKETS=y /boot/config-$(uname -r)# Expected output: CONFIG_XDP_SOCKETS=y# Check BTF support (required for BPF CO-RE)grep CONFIG_DEBUG_INFO_BTF=y /boot/config-$(uname -r)# Expected output: CONFIG_DEBUG_INFO_BTF=y# Check LSM BPF support (see step 7 if security policy features are required)grep CONFIG_BPF_LSM=y /boot/config-$(uname -r)# Expected output: CONFIG_BPF_LSM=y# View BPF program limits (loading policy for unprivileged users)cat /proc/sys/kernel/unprivileged_bpf_disabled# Expected output: TencentOS Server 4 outputs 0 by default. Value meanings: 0=Allow unprivileged users to load BPF programs, 1=Prohibit and can be changed back, 2=Prohibit and cannot be changed back.
# If bpftool is not installed yet, run the following command to install it.dnf install bpftool# View all loaded BPF programs and their instruction countsbpftool prog show# Expected output: List all loaded programs, with each line containing:# <prog_id>: <type> name <name> tag <tag> gpl# loaded_at <time> uid 0# xlated <instruction count> insns limit 1000000 insns jited <JIT instruction count> bytes memlock <byte count># View detailed information of a specific program (JSON + verbose mode, replace <prog_id> with the actual ID)bpftool prog show id <prog_id> -j -d# Expected output: Program details in JSON format, including the xlated_insns field, which indicates the instruction count.
bpftool prog show, xlated <N> insns is the number of compiled instructions of the program, and limit 1000000 insns is the instruction quantity limit.# Install the BCC toolkit.dnf install bcc-tools# Expected output: Dependencies resolved and installed successfully with no errors.# Verify that the tool is installed.ls /usr/share/bcc/tools/ | head -10# Expected output: List tools such as opensnoop, execsnoop, biolatency, tcptop, and profile.# Example: Trace file opens./usr/share/bcc/tools/opensnoop -d 5# Expected output: Records of open() calls from all processes within 5 seconds, including the PID, COMM, FD, ERR, and PATH columns.
# Install bpftrace.dnf install bpftrace# Expected output: Dependencies resolved and installed successfully with no errors.# Confirm the version.bpftrace --version# Expected output: bpftrace v0.x.x or later.# List available tracepoints.bpftrace -l 'tracepoint:syscalls:sys_enter_*' | head -10# Expected output: List the sys_enter_* series of system call tracepoints.# Trace all openat() system calls, counted by process.bpftrace -e 'tracepoint:syscalls:sys_enter_openat { @[comm] = count(); }'# Expected output: A table of openat call counts aggregated by process name, with statistics printed after pressing Ctrl+C.# Function latency tracing (vfs_read latency histogram)bpftrace -e 'kprobe:vfs_read { @start[tid] = nsecs; } kretprobe:vfs_read /@start[tid]/ { @us = hist((nsecs - @start[tid]) / 1000); delete(@start[tid]); }'# Expected output: A histogram of vfs_read latency in microseconds, printed after pressing Ctrl+C.
# If bpftool is not installed yet, run the following command to install it.dnf install bpftool# Expected output: Installation succeeded with no errors.# View all loaded BPF programs.bpftool prog show# Expected output: List all loaded programs along with their types, names, and instruction counts.# View all BPF maps.bpftool map show# Expected output: List all BPF maps along with their types and sizes.# View BPF programs attached to the network interface (replace <NIC name> with the actual NIC name).bpftool net show dev <NIC name># Expected output: List the XDP/TC programs attached to the NIC. If no programs are attached, the output is empty.
# Install the libbpf development package.dnf install libbpf-devel# Expected output: Installation succeeded.# Verify that BTF information is available.ls /sys/kernel/btf/vmlinux# Expected output: /sys/kernel/btf/vmlinux (the existence of this file indicates that BTF is available)# Clone the libbpf-bootstrap template (requires network access to GitHub).git clone https://github.com/libbpf/libbpf-bootstrap# Expected output: Clone succeeded.
# Verify that the kernel supports BPF LSM.grep CONFIG_BPF_LSM=y /boot/config-$(uname -r)# Expected output: CONFIG_BPF_LSM=y# View the currently enabled LSM list.cat /sys/kernel/security/lsm# Expected output: lsm list (TencentOS Server 4 defaults to capability,yama,selinux,bpf, with bpf enabled by default)# If bpf is not in the list, add lsm=tee,bpf as a kernel boot parameter (a reboot is required for the change to take effect).# A restart will cause service interruption, so perform it within a maintenance window. Modifying the LSM list affects system security policy behavior, so verify the change in a test environment first.grubby --update-kernel=ALL --args="lsm=tee,bpf"# Expected output: No errors.# Restart to take effectreboot# Confirm after reboot.cat /sys/kernel/security/lsm# Expected output: An LSM list that includes bpf.
lsm=tee,bpf kernel boot parameter, and Secure Boot is not a hard requirement. If the system has other LSMs enabled (such as SELinux), BPF LSM can coexist with them.# CPU off-cpu analysis (5-second sampling)/usr/share/bcc/tools/offcputime 5# Expected output: A histogram of off-cpu time aggregated by kernel stack, used to identify blocking hotspots.# Memory allocation tracing/usr/share/bcc/tools/memleak# Expected output: Statistics of memory allocation and deallocation aggregated by call stack, where unreleased memory indicates a leak.# System call latency statistics/usr/share/bcc/tools/syscount# Expected output: A latency statistics table aggregated by system call.
Operation not permittedCAP_BPF / CAP_SYS_ADMIN capabilities.# Method 1: Run as the root usersudo <bpf command># Method 2: Add capabilities to the container runtimedocker run --cap-add CAP_BPF --cap-add CAP_SYS_ADMIN ...# Method 3: Confirm that loading by unprivileged users is disabled (normal state)cat /proc/sys/kernel/unprivileged_bpf_disabled# Expected output: 0, 1, or 2 (1 or 2 indicates that loading BPF programs by unprivileged users is prohibited)
kernel headers not foundkernel-devel package, and its version must match the current kernel.# View the current kernel versionuname -r# Expected output: for example, 6.6.0-xxx.el4.x86_64# Install the matching kernel-devel and kernel-headers packages.dnf install "kernel-devel-$(uname -r)" "kernel-headers-$(uname -r)"# Expected output: Installation succeeded.# Confirm that the header file path existsls /lib/modules/$(uname -r)/build# Expected output: The path exists and is a symbolic link pointing to the source code directory.
BTF not found or failed to load BTFCONFIG_DEBUG_INFO_BTF=y enabled, or the /sys/kernel/btf/vmlinux file does not exist.# Check the kernel BTF configurationgrep CONFIG_DEBUG_INFO_BTF=y /boot/config-$(uname -r)# Expected output: CONFIG_DEBUG_INFO_BTF=y# Verify that the BTF file exists.ls -l /sys/kernel/btf/vmlinux# Expected output: The file exists.# If BTF is not enabled on the kernel, replace it with a kernel version that has BTF enabled.# TencentOS Server 4 enables BTF by default. If BTF is missing, verify the kernel source.
program too large or Instruction Limit Exceeded# Use bpftool to view the actual instruction count of the program.bpftool prog show# Expected output: xlated <instruction count> insns limit 1000000 insns# If the instruction count approaches the limit, split the program into multiple smaller BPF programs.# Or optimize the program logic to reduce loops and branches.# Check whether any loops are not unrolled or any tail calls are not used.
sysctl kernel.bpf_stats?kernel.bpf_stats is the switch for BPF statistics collection. Its value can be 0 (disabled) or 1 (enabled). After it is enabled, you can view the runtime statistics of BPF programs.# View the current value of bpf_statssysctl kernel.bpf_stats# Expected output: kernel.bpf_stats = 0# Enable BPF statistics collection (0 to disable, 1 to enable)sysctl -w kernel.bpf_stats=1# Expected output: kernel.bpf_stats = 1
フィードバック