]> www.infradead.org Git - users/jedix/linux-maple.git/commit
selftests/bpf: Add tests for bpf_rbtree_{root,left,right}
authorMartin KaFai Lau <martin.lau@kernel.org>
Tue, 6 May 2025 01:58:52 +0000 (18:58 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 6 May 2025 17:21:05 +0000 (10:21 -0700)
commit47ada65c5cf91b9cb51abf5bd32513ebd7720941
treeeeca2e8eb780553ba4829cd81bab3c02f2a1e4c3
parent2ddef1783c43ba81a05dec0a5781ebbc61a3c089
selftests/bpf: Add tests for bpf_rbtree_{root,left,right}

This patch has a much simplified rbtree usage from the
kernel sch_fq qdisc. It has a "struct node_data" which can be
added to two different rbtrees which are ordered by different keys.

The test first populates both rbtrees. Then search for a lookup_key
from the "groot0" rbtree. Once the lookup_key is found, that node
refcount is taken. The node is then removed from another "groot1"
rbtree.

While searching the lookup_key, the test will also try to remove
all rbnodes in the path leading to the lookup_key.

The test_{root,left,right}_spinlock_true tests ensure that the
return value of the bpf_rbtree functions is a non_own_ref node pointer.
This is done by forcing an verifier error by calling a helper
bpf_jiffies64() while holding the spinlock. The tests then
check for the verifier message
"call bpf_rbtree...R0=rcu_ptr_or_null_node..."

The other test_{root,left,right}_spinlock_false tests ensure that
they must be called with spinlock held.

Suggested-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> # Check non_own_ref marking
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20250506015857.817950-6-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/rbtree.c
tools/testing/selftests/bpf/progs/rbtree_search.c [new file with mode: 0644]