tools/testing/selftests/bpf/progs/verifier_store_release.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_store_release.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/verifier_store_release.c
Extension
.c
Size
7956 bytes
Lines
302
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Google LLC. */

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "../../../include/linux/filter.h"
#include "bpf_misc.h"

#ifdef CAN_USE_LOAD_ACQ_STORE_REL

SEC("socket")
__description("store-release, 8-bit")
__success __success_unpriv __retval(0)
__naked void store_release_8(void)
{
	asm volatile (
	"r0 = 0;"
	"w1 = 0x12;"
	".8byte %[store_release_insn];" // store_release((u8 *)(r10 - 1), w1);
	"w2 = *(u8 *)(r10 - 1);"
	"if r2 == r1 goto 1f;"
	"r0 = 1;"
"1:"
	"exit;"
	:
	: __imm_insn(store_release_insn,
		     BPF_ATOMIC_OP(BPF_B, BPF_STORE_REL, BPF_REG_10, BPF_REG_1, -1))
	: __clobber_all);
}

SEC("socket")
__description("store-release, 16-bit")
__success __success_unpriv __retval(0)
__naked void store_release_16(void)
{
	asm volatile (
	"r0 = 0;"
	"w1 = 0x1234;"
	".8byte %[store_release_insn];" // store_release((u16 *)(r10 - 2), w1);
	"w2 = *(u16 *)(r10 - 2);"
	"if r2 == r1 goto 1f;"
	"r0 = 1;"
"1:"
	"exit;"
	:
	: __imm_insn(store_release_insn,
		     BPF_ATOMIC_OP(BPF_H, BPF_STORE_REL, BPF_REG_10, BPF_REG_1, -2))
	: __clobber_all);
}

SEC("socket")
__description("store-release, 32-bit")
__success __success_unpriv __retval(0)
__naked void store_release_32(void)
{
	asm volatile (
	"r0 = 0;"
	"w1 = 0x12345678;"
	".8byte %[store_release_insn];" // store_release((u32 *)(r10 - 4), w1);
	"w2 = *(u32 *)(r10 - 4);"
	"if r2 == r1 goto 1f;"
	"r0 = 1;"
"1:"
	"exit;"
	:
	: __imm_insn(store_release_insn,
		     BPF_ATOMIC_OP(BPF_W, BPF_STORE_REL, BPF_REG_10, BPF_REG_1, -4))
	: __clobber_all);
}

SEC("socket")
__description("store-release, 64-bit")
__success __success_unpriv __retval(0)
__naked void store_release_64(void)
{
	asm volatile (
	"r0 = 0;"
	"r1 = 0x1234567890abcdef ll;"
	".8byte %[store_release_insn];" // store_release((u64 *)(r10 - 8), r1);
	"r2 = *(u64 *)(r10 - 8);"
	"if r2 == r1 goto 1f;"
	"r0 = 1;"
"1:"
	"exit;"
	:
	: __imm_insn(store_release_insn,
		     BPF_ATOMIC_OP(BPF_DW, BPF_STORE_REL, BPF_REG_10, BPF_REG_1, -8))
	: __clobber_all);
}

Annotation

Implementation Notes