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

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

File Facts

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

struct head_nested_inner {
	struct bpf_spin_lock lock;
	struct bpf_list_head head __contains(foo, node2);
};

struct head_nested {
	int dummy;
	struct head_nested_inner inner;
};

private(C) struct bpf_spin_lock glock_c;
private(C) struct bpf_list_head ghead_array[2] __contains(foo, node2);
private(C) struct bpf_list_head ghead_array_one[1] __contains(foo, node2);

private(D) struct head_nested ghead_nested;

static __always_inline
int list_push_pop(struct bpf_spin_lock *lock, struct bpf_list_head *head, bool leave_in_map)
{
	struct bpf_list_node *n;
	struct foo *f;

	f = bpf_obj_new(typeof(*f));
	if (!f)
		return 2;

	bpf_spin_lock(lock);
	n = bpf_list_pop_front(head);
	bpf_spin_unlock(lock);
	if (n) {
		bpf_obj_drop(container_of(n, struct foo, node2));
		bpf_obj_drop(f);
		return 3;
	}

	bpf_spin_lock(lock);
	n = bpf_list_pop_back(head);
	bpf_spin_unlock(lock);
	if (n) {
		bpf_obj_drop(container_of(n, struct foo, node2));
		bpf_obj_drop(f);
		return 4;
	}


	bpf_spin_lock(lock);
	f->data = 42;
	bpf_list_push_front(head, &f->node2);
	bpf_spin_unlock(lock);
	if (leave_in_map)
		return 0;
	bpf_spin_lock(lock);
	n = bpf_list_pop_back(head);
	bpf_spin_unlock(lock);
	if (!n)
		return 5;
	f = container_of(n, struct foo, node2);
	if (f->data != 42) {
		bpf_obj_drop(f);
		return 6;
	}

	bpf_spin_lock(lock);
	f->data = 13;
	bpf_list_push_front(head, &f->node2);
	bpf_spin_unlock(lock);
	bpf_spin_lock(lock);
	n = bpf_list_pop_front(head);
	bpf_spin_unlock(lock);
	if (!n)
		return 7;
	f = container_of(n, struct foo, node2);
	if (f->data != 13) {
		bpf_obj_drop(f);
		return 8;
	}
	bpf_obj_drop(f);

	bpf_spin_lock(lock);
	n = bpf_list_pop_front(head);
	bpf_spin_unlock(lock);
	if (n) {
		bpf_obj_drop(container_of(n, struct foo, node2));
		return 9;
	}

	bpf_spin_lock(lock);
	n = bpf_list_pop_back(head);
	bpf_spin_unlock(lock);
	if (n) {

Annotation

Implementation Notes