阅读一些附加到跟踪点的 ebpf 示例,我注意到每个结构都是从这样的填充开始构建的(来自samples/bpf/xdp_redirect_cpu_kern.c
)
/* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_cpumap_enqueue/format
* Code in: kernel/include/trace/events/xdp.h
*/
struct cpumap_enqueue_ctx {
u64 __pad; // First 8 bytes are not accessible by bpf code
int map_id; // offset:8; size:4; signed:1;
u32 act; // offset:12; size:4; signed:0;
int cpu; // offset:16; size:4; signed:1;
unsigned int drops; // offset:20; size:4; signed:0;
unsigned int processed; // offset:24; size:4; signed:0;
int to_cpu; // offset:28; size:4; signed:1;
};
我发现的只是这条评论,它说 bpf 代码无法访问前 8 个字节,但我不明白为什么。