tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c- Extension
.c- Size
- 2895 bytes
- Lines
- 107
- 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.
Dependency Surface
linux/bpf.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
function subfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
int main(void);
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 1);
__uint(key_size, sizeof(__u32));
__array(values, void (void));
} jmp_table SEC(".maps") = {
.values = {
[0] = (void *) &main,
},
};
__noinline __auxiliary
static __naked int sub(void)
{
asm volatile (
"r2 = %[jmp_table] ll;"
"r3 = 0;"
"call 12;"
"exit;"
:
: __imm_addr(jmp_table)
: __clobber_all);
}
__success
__arch_x86_64
/* program entry for main(), regular function prologue */
__jited(" endbr64")
__jited(" nopl (%rax,%rax)")
__jited(" xorq %rax, %rax")
__jited(" pushq %rbp")
__jited(" movq %rsp, %rbp")
/* tail call prologue for program:
* - establish memory location for tail call counter at &rbp[-8];
* - spill tail_call_cnt_ptr at &rbp[-16];
* - expect tail call counter to be passed in rax;
* - for entry program rax is a raw counter, value < 33;
* - for tail called program rax is tail_call_cnt_ptr (value > 33).
*/
__jited(" endbr64")
__jited(" cmpq $0x21, %rax")
__jited(" ja L0")
__jited(" pushq %rax")
__jited(" movq %rsp, %rax")
__jited(" jmp L1")
__jited("L0: pushq %rax") /* rbp[-8] = rax */
__jited("L1: pushq %rax") /* rbp[-16] = rax */
/* on subprogram call restore rax to be tail_call_cnt_ptr from rbp[-16]
* (cause original rax might be clobbered by this point)
*/
__jited(" movq -0x10(%rbp), %rax")
__jited("...")
__jited(" callq 0x{{.*}}") /* call to sub() */
__jited(" xorl %eax, %eax")
__jited(" leave")
__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */
__jited("...")
/* subprogram entry for sub(), regular function prologue */
__jited(" endbr64")
__jited(" nopl (%rax,%rax)")
__jited(" nopl (%rax)")
__jited(" pushq %rbp")
__jited(" movq %rsp, %rbp")
/* tail call prologue for subprogram address of tail call counter
* stored at rbp[-16].
*/
__jited(" endbr64")
__jited(" pushq %rax") /* rbp[-8] = rax */
__jited(" pushq %rax") /* rbp[-16] = rax */
__jited(" movabsq ${{.*}}, %rsi") /* r2 = &jmp_table */
__jited(" xorl %edx, %edx") /* r3 = 0 */
/* bpf_tail_call implementation:
* - load tail_call_cnt_ptr from rbp[-16];
* - if *tail_call_cnt_ptr < 33, increment it and jump to target;
* - otherwise do nothing.
*/
__jited(" movq -0x10(%rbp), %rax")
__jited(" cmpq $0x21, (%rax)")
__jited(" jae L0")
__jited(" nopl (%rax,%rax)")
__jited(" addq $0x1, (%rax)") /* *tail_call_cnt_ptr += 1 */
__jited(" popq %rax")
__jited(" popq %rax")
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `function sub`, `function main`.
- 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.