tools/testing/selftests/bpf/prog_tests/linked_list.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/linked_list.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/linked_list.c
Extension
.c
Size
26901 bytes
Lines
815
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
#include <bpf/btf.h>
#include <test_btf.h>
#include <linux/btf.h>
#include <test_progs.h>
#include <network_helpers.h>

#include "linked_list.skel.h"
#include "linked_list_fail.skel.h"
#include "linked_list_peek.skel.h"

static char log_buf[1024 * 1024];

static struct {
	const char *prog_name;
	const char *err_msg;
} linked_list_fail_tests[] = {
#define TEST(test, off) \
	{ #test "_missing_lock_push_front", \
	  "bpf_spin_lock at off=" #off " must be held for bpf_list_head" }, \
	{ #test "_missing_lock_push_back", \
	  "bpf_spin_lock at off=" #off " must be held for bpf_list_head" }, \
	{ #test "_missing_lock_pop_front", \
	  "bpf_spin_lock at off=" #off " must be held for bpf_list_head" }, \
	{ #test "_missing_lock_pop_back", \
	  "bpf_spin_lock at off=" #off " must be held for bpf_list_head" },
	TEST(kptr, 40)
	TEST(global, 16)
	TEST(map, 0)
	TEST(inner_map, 0)
#undef TEST
#define TEST(test, op) \
	{ #test "_kptr_incorrect_lock_" #op, \
	  "held lock and object are not in the same allocation\n" \
	  "bpf_spin_lock at off=40 must be held for bpf_list_head" }, \
	{ #test "_global_incorrect_lock_" #op, \
	  "held lock and object are not in the same allocation\n" \
	  "bpf_spin_lock at off=16 must be held for bpf_list_head" }, \
	{ #test "_map_incorrect_lock_" #op, \
	  "held lock and object are not in the same allocation\n" \
	  "bpf_spin_lock at off=0 must be held for bpf_list_head" }, \
	{ #test "_inner_map_incorrect_lock_" #op, \
	  "held lock and object are not in the same allocation\n" \
	  "bpf_spin_lock at off=0 must be held for bpf_list_head" },
	TEST(kptr, push_front)
	TEST(kptr, push_back)
	TEST(kptr, pop_front)
	TEST(kptr, pop_back)
	TEST(global, push_front)
	TEST(global, push_back)
	TEST(global, pop_front)
	TEST(global, pop_back)
	TEST(map, push_front)
	TEST(map, push_back)
	TEST(map, pop_front)
	TEST(map, pop_back)
	TEST(inner_map, push_front)
	TEST(inner_map, push_back)
	TEST(inner_map, pop_front)
	TEST(inner_map, pop_back)
#undef TEST
	{ "map_compat_kprobe", "tracing progs cannot use bpf_{list_head,rb_root} yet" },
	{ "map_compat_kretprobe", "tracing progs cannot use bpf_{list_head,rb_root} yet" },
	{ "map_compat_tp", "tracing progs cannot use bpf_{list_head,rb_root} yet" },
	{ "map_compat_perf", "tracing progs cannot use bpf_{list_head,rb_root} yet" },
	{ "map_compat_raw_tp", "tracing progs cannot use bpf_{list_head,rb_root} yet" },
	{ "map_compat_raw_tp_w", "tracing progs cannot use bpf_{list_head,rb_root} yet" },
	{ "obj_type_id_oor", "local type ID argument must be in range [0, U32_MAX]" },
	{ "obj_new_no_composite", "bpf_obj_new/bpf_percpu_obj_new type ID argument must be of a struct" },
	{ "obj_new_no_struct", "bpf_obj_new/bpf_percpu_obj_new type ID argument must be of a struct" },
	{ "obj_drop_non_zero_off", "R1 must have zero offset when passed to release func" },
	{ "new_null_ret", "R0 invalid mem access 'ptr_or_null_'" },
	{ "obj_new_acq", "Unreleased reference id=" },
	{ "use_after_drop", "invalid mem access 'scalar'" },
	{ "ptr_walk_scalar", "type=rdonly_untrusted_mem expected=percpu_ptr_" },
	{ "direct_read_lock", "direct access to bpf_spin_lock is disallowed" },
	{ "direct_write_lock", "direct access to bpf_spin_lock is disallowed" },
	{ "direct_read_head", "direct access to bpf_list_head is disallowed" },
	{ "direct_write_head", "direct access to bpf_list_head is disallowed" },
	{ "direct_read_node", "direct access to bpf_list_node is disallowed" },
	{ "direct_write_node", "direct access to bpf_list_node is disallowed" },
	{ "use_after_unlock_push_front", "invalid mem access 'scalar'" },
	{ "use_after_unlock_push_back", "invalid mem access 'scalar'" },
	{ "double_push_front", "R2 expected pointer to allocated object" },
	{ "double_push_back", "R2 expected pointer to allocated object" },
	{ "no_node_value_type", "bpf_list_node not found at offset=0" },
	{ "incorrect_value_type",
	  "operation on bpf_list_head expects arg#1 bpf_list_node at offset=48 in struct foo, "
	  "but arg is at offset=0 in struct bar" },
	{ "incorrect_node_var_off", "variable ptr_ access var_off=(0x0; 0x1ffffffff) disallowed" },

Annotation

Implementation Notes