tools/testing/selftests/bpf/progs/rbtree_search_kptr.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/rbtree_search_kptr.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/rbtree_search_kptr.c- Extension
.c- Size
- 6041 bytes
- Lines
- 291
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_helpers.hbpf_misc.hbpf_experimental.h
Detected Declarations
struct node_datastruct tree_nodestruct tree_node_reffunction lessfunction rbtree_search_kptrfunction less_rfunction rbtree_search_kptr_reffunction __msg
Annotated Snippet
struct node_data {
int data;
};
struct tree_node {
struct bpf_rb_node node;
u64 key;
struct node_data __kptr * node_data;
};
struct tree_node_ref {
struct bpf_refcount ref;
struct bpf_rb_node node;
u64 key;
struct node_data __kptr * node_data;
};
#define private(name) SEC(".data." #name) __hidden __aligned(8)
private(A) struct bpf_rb_root root __contains(tree_node, node);
private(A) struct bpf_spin_lock lock;
private(B) struct bpf_rb_root root_r __contains(tree_node_ref, node);
private(B) struct bpf_spin_lock lock_r;
static bool less(struct bpf_rb_node *a, const struct bpf_rb_node *b)
{
struct tree_node *node_a, *node_b;
node_a = container_of(a, struct tree_node, node);
node_b = container_of(b, struct tree_node, node);
return node_a->key < node_b->key;
}
SEC("syscall")
__retval(0)
long rbtree_search_kptr(void *ctx)
{
struct tree_node *tnode;
struct bpf_rb_node *rb_n;
struct node_data __kptr * node_data;
int lookup_key = NR_NODES / 2;
int lookup_data = NR_NODES / 2;
int i, data, ret = 0;
for (i = 0; i < NR_NODES && can_loop; i++) {
tnode = bpf_obj_new(typeof(*tnode));
if (!tnode)
return __LINE__;
node_data = bpf_obj_new(typeof(*node_data));
if (!node_data) {
bpf_obj_drop(tnode);
return __LINE__;
}
tnode->key = i;
node_data->data = i;
node_data = bpf_kptr_xchg(&tnode->node_data, node_data);
if (node_data)
bpf_obj_drop(node_data);
bpf_spin_lock(&lock);
bpf_rbtree_add(&root, &tnode->node, less);
bpf_spin_unlock(&lock);
}
bpf_spin_lock(&lock);
rb_n = bpf_rbtree_root(&root);
while (rb_n && can_loop) {
tnode = container_of(rb_n, struct tree_node, node);
node_data = bpf_kptr_xchg(&tnode->node_data, NULL);
if (!node_data) {
ret = __LINE__;
goto fail;
}
data = node_data->data;
node_data = bpf_kptr_xchg(&tnode->node_data, node_data);
if (node_data) {
bpf_spin_unlock(&lock);
bpf_obj_drop(node_data);
return __LINE__;
}
if (lookup_key == tnode->key) {
if (data == lookup_data)
break;
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `bpf_experimental.h`.
- Detected declarations: `struct node_data`, `struct tree_node`, `struct tree_node_ref`, `function less`, `function rbtree_search_kptr`, `function less_r`, `function rbtree_search_kptr_ref`, `function __msg`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.