tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c- Extension
.c- Size
- 19917 bytes
- Lines
- 888
- 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/bpf_core_read.h../../../include/linux/filter.hbpf_misc.hstdbool.hbpf_kfuncs.h
Detected Declarations
function __log_levelfunction __xlatedfunction __xlatedfunction __log_levelfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction __xlatedfunction bad_write_in_subprog_auxfunction __xlatedfunction invalidate_one_subprogfunction invalidate_one_subprog_auxfunction subprogs_use_independent_offsetsfunction subprogs_use_independent_offsets_auxfunction __log_levelfunction __log_levelfunction __log_levelfunction dummy_loop_callbackfunction __log_levelfunction __log_levelfunction __log_levelfunction cumulative_stack_depth_subprogfunction kfunc_bpf_cast_to_kern_ctxfunction kfunc_bpf_rdonly_castfunction kfunc_root
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
#include "../../../include/linux/filter.h"
#include "bpf_misc.h"
#include <stdbool.h>
#include "bpf_kfuncs.h"
SEC("raw_tp")
__arch_x86_64
__log_level(4) __msg("stack depth 8")
__xlated("4: r5 = 5")
__xlated("5: r0 = ")
__xlated("6: r0 = &(void __percpu *)(r0)")
__xlated("7: r0 = *(u32 *)(r0 +0)")
__xlated("8: exit")
__success
__naked void simple(void)
{
asm volatile (
"r1 = 1;"
"r2 = 2;"
"r3 = 3;"
"r4 = 4;"
"r5 = 5;"
"*(u64 *)(r10 - 16) = r1;"
"*(u64 *)(r10 - 24) = r2;"
"*(u64 *)(r10 - 32) = r3;"
"*(u64 *)(r10 - 40) = r4;"
"*(u64 *)(r10 - 48) = r5;"
"call %[bpf_get_smp_processor_id];"
"r5 = *(u64 *)(r10 - 48);"
"r4 = *(u64 *)(r10 - 40);"
"r3 = *(u64 *)(r10 - 32);"
"r2 = *(u64 *)(r10 - 24);"
"r1 = *(u64 *)(r10 - 16);"
"exit;"
:
: __imm(bpf_get_smp_processor_id)
: __clobber_all);
}
/* The logic for detecting and verifying bpf_fastcall pattern is the same for
* any arch, however x86 differs from arm64 or riscv64 in a way
* bpf_get_smp_processor_id is rewritten:
* - on x86 it is done by verifier
* - on arm64 and riscv64 it is done by jit
*
* Which leads to different xlated patterns for different archs:
* - on x86 the call is expanded as 3 instructions
* - on arm64 and riscv64 the call remains as is
* (but spills/fills are still removed)
*
* It is really desirable to check instruction indexes in the xlated
* patterns, so add this canary test to check that function rewrite by
* jit is correctly processed by bpf_fastcall logic, keep the rest of the
* tests as x86.
*/
SEC("raw_tp")
__arch_arm64
__arch_riscv64
__xlated("0: r1 = 1")
__xlated("1: call bpf_get_smp_processor_id")
__xlated("2: exit")
__success
__naked void canary_arm64_riscv64(void)
{
asm volatile (
"r1 = 1;"
"*(u64 *)(r10 - 16) = r1;"
"call %[bpf_get_smp_processor_id];"
"r1 = *(u64 *)(r10 - 16);"
"exit;"
:
: __imm(bpf_get_smp_processor_id)
: __clobber_all);
}
SEC("raw_tp")
__arch_x86_64
__xlated("1: r0 = &(void __percpu *)(r0)")
__xlated("...")
__xlated("3: exit")
__success
__naked void canary_zero_spills(void)
{
asm volatile (
"call %[bpf_get_smp_processor_id];"
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `../../../include/linux/filter.h`, `bpf_misc.h`, `stdbool.h`, `bpf_kfuncs.h`.
- Detected declarations: `function __log_level`, `function __xlated`, `function __xlated`, `function __log_level`, `function __xlated`, `function __xlated`, `function __xlated`, `function __xlated`, `function __xlated`, `function __xlated`.
- 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.