tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c- Extension
.c- Size
- 4515 bytes
- Lines
- 189
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/stddef.hlinux/if_ether.hlinux/ipv6.hlinux/bpf.hlinux/tcp.hbpf/bpf_helpers.hbpf/bpf_endian.hbpf/bpf_tracing.h
Detected Declarations
struct sk_buffstruct args_subprog2struct args_subprog2function BPF_PROGfunction BPF_PROGfunction test_subprog2function BPF_PROGfunction new_get_skb_lenfunction new_get_skb_ifindexfunction new_get_constantfunction new_test_pkt_write_access_subprog
Annotated Snippet
struct sk_buff {
unsigned int len;
};
__u64 test_result = 0;
SEC("fexit/test_pkt_access")
int BPF_PROG(test_main, struct sk_buff *skb, int ret)
{
int len;
__builtin_preserve_access_index(({
len = skb->len;
}));
if (len != 74 || ret != 0)
return 0;
test_result = 1;
return 0;
}
__u64 test_result_subprog1 = 0;
SEC("fexit/test_pkt_access_subprog1")
int BPF_PROG(test_subprog1, struct sk_buff *skb, int ret)
{
int len;
__builtin_preserve_access_index(({
len = skb->len;
}));
if (len != 74 || ret != 148)
return 0;
test_result_subprog1 = 1;
return 0;
}
/* Though test_pkt_access_subprog2() is defined in C as:
* static __attribute__ ((noinline))
* int test_pkt_access_subprog2(int val, volatile struct __sk_buff *skb)
* {
* return skb->len * val;
* }
* llvm optimizations remove 'int val' argument and generate BPF assembly:
* r0 = *(u32 *)(r1 + 0)
* w0 <<= 1
* exit
* Before llvm23, in such case the verifier falls back to conservative and
* tracing program can access arguments and return value as u64
* instead of accurate types. With llvm23, the true signature
* int test_pkt_access_subprog2(volatile struct __sk_buff *skb)
* is available in btf.
*/
#if __clang_major__ >= 23
struct args_subprog2 {
__u64 args[1];
__u64 ret;
};
#else
struct args_subprog2 {
__u64 args[5];
__u64 ret;
};
#endif
__u64 test_result_subprog2 = 0;
SEC("fexit/test_pkt_access_subprog2")
int test_subprog2(struct args_subprog2 *ctx)
{
struct sk_buff *skb = (void *)ctx->args[0];
__u64 ret;
int len;
bpf_probe_read_kernel(&len, sizeof(len),
__builtin_preserve_access_index(&skb->len));
ret = ctx->ret;
/* bpf_prog_test_load() loads "test_pkt_access.bpf.o" with
* BPF_F_TEST_RND_HI32 which randomizes upper 32 bits after BPF_ALU32
* insns. Hence after 'w0 <<= 1' upper bits of $rax are random. That is
* expected and correct. Trim them.
*/
ret = (__u32) ret;
if (len != 74 || ret != 148)
return 0;
test_result_subprog2 = 1;
return 0;
}
__u64 test_result_subprog3 = 0;
SEC("fexit/test_pkt_access_subprog3")
int BPF_PROG(test_subprog3, int val, struct sk_buff *skb, int ret)
{
int len;
Annotation
- Immediate include surface: `linux/stddef.h`, `linux/if_ether.h`, `linux/ipv6.h`, `linux/bpf.h`, `linux/tcp.h`, `bpf/bpf_helpers.h`, `bpf/bpf_endian.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `struct sk_buff`, `struct args_subprog2`, `struct args_subprog2`, `function BPF_PROG`, `function BPF_PROG`, `function test_subprog2`, `function BPF_PROG`, `function new_get_skb_len`, `function new_get_skb_ifindex`, `function new_get_constant`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.