xref: /linux/tools/testing/selftests/bpf/prog_tests/local_kptr_ownership.c (revision 5fc5768c7ca92895ccd1de94dc521e5a55ae7896)
1*0288ed67SKumar Kartikeya Dwivedi // SPDX-License-Identifier: GPL-2.0
2*0288ed67SKumar Kartikeya Dwivedi /* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
3*0288ed67SKumar Kartikeya Dwivedi 
4*0288ed67SKumar Kartikeya Dwivedi #include <bpf/btf.h>
5*0288ed67SKumar Kartikeya Dwivedi #include <linux/btf.h>
6*0288ed67SKumar Kartikeya Dwivedi #include <test_progs.h>
7*0288ed67SKumar Kartikeya Dwivedi 
8*0288ed67SKumar Kartikeya Dwivedi #define SPIN_LOCK 2
9*0288ed67SKumar Kartikeya Dwivedi #define LIST_HEAD 3
10*0288ed67SKumar Kartikeya Dwivedi #define LIST_NODE 4
11*0288ed67SKumar Kartikeya Dwivedi /* Keep in sync with BTF_MAX_OWNERSHIP_DEPTH. */
12*0288ed67SKumar Kartikeya Dwivedi #define MAX_OWNERSHIP_DEPTH 8
13*0288ed67SKumar Kartikeya Dwivedi 
init_btf(void)14*0288ed67SKumar Kartikeya Dwivedi static struct btf *init_btf(void)
15*0288ed67SKumar Kartikeya Dwivedi {
16*0288ed67SKumar Kartikeya Dwivedi 	struct btf *btf;
17*0288ed67SKumar Kartikeya Dwivedi 	int id;
18*0288ed67SKumar Kartikeya Dwivedi 
19*0288ed67SKumar Kartikeya Dwivedi 	btf = btf__new_empty();
20*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(btf, "btf__new_empty"))
21*0288ed67SKumar Kartikeya Dwivedi 		return NULL;
22*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
23*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 1, "btf__add_int"))
24*0288ed67SKumar Kartikeya Dwivedi 		goto err_out;
25*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "bpf_spin_lock", 4);
26*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, SPIN_LOCK, "btf__add_struct bpf_spin_lock"))
27*0288ed67SKumar Kartikeya Dwivedi 		goto err_out;
28*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "bpf_list_head", 16);
29*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, LIST_HEAD, "btf__add_struct bpf_list_head"))
30*0288ed67SKumar Kartikeya Dwivedi 		goto err_out;
31*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "bpf_list_node", 24);
32*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, LIST_NODE, "btf__add_struct bpf_list_node"))
33*0288ed67SKumar Kartikeya Dwivedi 		goto err_out;
34*0288ed67SKumar Kartikeya Dwivedi 	return btf;
35*0288ed67SKumar Kartikeya Dwivedi 
36*0288ed67SKumar Kartikeya Dwivedi err_out:
37*0288ed67SKumar Kartikeya Dwivedi 	btf__free(btf);
38*0288ed67SKumar Kartikeya Dwivedi 	return NULL;
39*0288ed67SKumar Kartikeya Dwivedi }
40*0288ed67SKumar Kartikeya Dwivedi 
add_local_kptr(struct btf * btf,int pointee_id,const char * tag)41*0288ed67SKumar Kartikeya Dwivedi static int add_local_kptr(struct btf *btf, int pointee_id, const char *tag)
42*0288ed67SKumar Kartikeya Dwivedi {
43*0288ed67SKumar Kartikeya Dwivedi 	int id;
44*0288ed67SKumar Kartikeya Dwivedi 
45*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_type_tag(btf, tag, pointee_id);
46*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_GT(id, 0, "btf__add_type_tag"))
47*0288ed67SKumar Kartikeya Dwivedi 		return id;
48*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_ptr(btf, id);
49*0288ed67SKumar Kartikeya Dwivedi 	ASSERT_GT(id, 0, "btf__add_ptr");
50*0288ed67SKumar Kartikeya Dwivedi 	return id;
51*0288ed67SKumar Kartikeya Dwivedi }
52*0288ed67SKumar Kartikeya Dwivedi 
test_self_cycle(const char * tag,int expected_err)53*0288ed67SKumar Kartikeya Dwivedi static void test_self_cycle(const char *tag, int expected_err)
54*0288ed67SKumar Kartikeya Dwivedi {
55*0288ed67SKumar Kartikeya Dwivedi 	struct btf *btf;
56*0288ed67SKumar Kartikeya Dwivedi 	int id, err;
57*0288ed67SKumar Kartikeya Dwivedi 
58*0288ed67SKumar Kartikeya Dwivedi 	btf = init_btf();
59*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(btf, "init_btf"))
60*0288ed67SKumar Kartikeya Dwivedi 		return;
61*0288ed67SKumar Kartikeya Dwivedi 	id = add_local_kptr(btf, 7, tag);
62*0288ed67SKumar Kartikeya Dwivedi 	if (id <= 0)
63*0288ed67SKumar Kartikeya Dwivedi 		goto out;
64*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "self_cycle", 8);
65*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 7, "btf__add_struct self_cycle"))
66*0288ed67SKumar Kartikeya Dwivedi 		goto out;
67*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "next", 6, 0, 0);
68*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field self_cycle::next"))
69*0288ed67SKumar Kartikeya Dwivedi 		goto out;
70*0288ed67SKumar Kartikeya Dwivedi 
71*0288ed67SKumar Kartikeya Dwivedi 	err = btf__load_into_kernel(btf);
72*0288ed67SKumar Kartikeya Dwivedi 	ASSERT_EQ(err, expected_err, "check btf");
73*0288ed67SKumar Kartikeya Dwivedi out:
74*0288ed67SKumar Kartikeya Dwivedi 	btf__free(btf);
75*0288ed67SKumar Kartikeya Dwivedi }
76*0288ed67SKumar Kartikeya Dwivedi 
test_aba_cycle(void)77*0288ed67SKumar Kartikeya Dwivedi static void test_aba_cycle(void)
78*0288ed67SKumar Kartikeya Dwivedi {
79*0288ed67SKumar Kartikeya Dwivedi 	struct btf *btf;
80*0288ed67SKumar Kartikeya Dwivedi 	int id, err;
81*0288ed67SKumar Kartikeya Dwivedi 
82*0288ed67SKumar Kartikeya Dwivedi 	btf = init_btf();
83*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(btf, "init_btf"))
84*0288ed67SKumar Kartikeya Dwivedi 		return;
85*0288ed67SKumar Kartikeya Dwivedi 	id = add_local_kptr(btf, 10, "kptr");
86*0288ed67SKumar Kartikeya Dwivedi 	if (id <= 0)
87*0288ed67SKumar Kartikeya Dwivedi 		goto out;
88*0288ed67SKumar Kartikeya Dwivedi 	id = add_local_kptr(btf, 9, "kptr");
89*0288ed67SKumar Kartikeya Dwivedi 	if (id <= 0)
90*0288ed67SKumar Kartikeya Dwivedi 		goto out;
91*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "cycle_a", 8);
92*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 9, "btf__add_struct cycle_a"))
93*0288ed67SKumar Kartikeya Dwivedi 		goto out;
94*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "b", 6, 0, 0);
95*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field cycle_a::b"))
96*0288ed67SKumar Kartikeya Dwivedi 		goto out;
97*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "cycle_b", 8);
98*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 10, "btf__add_struct cycle_b"))
99*0288ed67SKumar Kartikeya Dwivedi 		goto out;
100*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "a", 8, 0, 0);
101*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field cycle_b::a"))
102*0288ed67SKumar Kartikeya Dwivedi 		goto out;
103*0288ed67SKumar Kartikeya Dwivedi 
104*0288ed67SKumar Kartikeya Dwivedi 	err = btf__load_into_kernel(btf);
105*0288ed67SKumar Kartikeya Dwivedi 	ASSERT_EQ(err, -ELOOP, "check btf");
106*0288ed67SKumar Kartikeya Dwivedi out:
107*0288ed67SKumar Kartikeya Dwivedi 	btf__free(btf);
108*0288ed67SKumar Kartikeya Dwivedi }
109*0288ed67SKumar Kartikeya Dwivedi 
test_mixed_cycle(void)110*0288ed67SKumar Kartikeya Dwivedi static void test_mixed_cycle(void)
111*0288ed67SKumar Kartikeya Dwivedi {
112*0288ed67SKumar Kartikeya Dwivedi 	struct btf *btf;
113*0288ed67SKumar Kartikeya Dwivedi 	int id, err;
114*0288ed67SKumar Kartikeya Dwivedi 
115*0288ed67SKumar Kartikeya Dwivedi 	btf = init_btf();
116*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(btf, "init_btf"))
117*0288ed67SKumar Kartikeya Dwivedi 		return;
118*0288ed67SKumar Kartikeya Dwivedi 	id = add_local_kptr(btf, 7, "kptr");
119*0288ed67SKumar Kartikeya Dwivedi 	if (id <= 0)
120*0288ed67SKumar Kartikeya Dwivedi 		goto out;
121*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "mixed_owner", 20);
122*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 7, "btf__add_struct mixed_owner"))
123*0288ed67SKumar Kartikeya Dwivedi 		goto out;
124*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "root", LIST_HEAD, 0, 0);
125*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field mixed_owner::root"))
126*0288ed67SKumar Kartikeya Dwivedi 		goto out;
127*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "lock", SPIN_LOCK, 128, 0);
128*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field mixed_owner::lock"))
129*0288ed67SKumar Kartikeya Dwivedi 		goto out;
130*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_decl_tag(btf, "contains:mixed_node:node", 7, 0);
131*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 8, "btf__add_decl_tag mixed_owner"))
132*0288ed67SKumar Kartikeya Dwivedi 		goto out;
133*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "mixed_node", 32);
134*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, 9, "btf__add_struct mixed_node"))
135*0288ed67SKumar Kartikeya Dwivedi 		goto out;
136*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "node", LIST_NODE, 0, 0);
137*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field mixed_node::node"))
138*0288ed67SKumar Kartikeya Dwivedi 		goto out;
139*0288ed67SKumar Kartikeya Dwivedi 	err = btf__add_field(btf, "owner", 6, 192, 0);
140*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(err, "btf__add_field mixed_node::owner"))
141*0288ed67SKumar Kartikeya Dwivedi 		goto out;
142*0288ed67SKumar Kartikeya Dwivedi 
143*0288ed67SKumar Kartikeya Dwivedi 	err = btf__load_into_kernel(btf);
144*0288ed67SKumar Kartikeya Dwivedi 	ASSERT_EQ(err, -ELOOP, "check btf");
145*0288ed67SKumar Kartikeya Dwivedi out:
146*0288ed67SKumar Kartikeya Dwivedi 	btf__free(btf);
147*0288ed67SKumar Kartikeya Dwivedi }
148*0288ed67SKumar Kartikeya Dwivedi 
test_acyclic_depth(int depth,bool child_first,bool shared_suffix,int expected_err)149*0288ed67SKumar Kartikeya Dwivedi static void test_acyclic_depth(int depth, bool child_first, bool shared_suffix, int expected_err)
150*0288ed67SKumar Kartikeya Dwivedi {
151*0288ed67SKumar Kartikeya Dwivedi 	int ptr_id[MAX_OWNERSHIP_DEPTH + 1];
152*0288ed67SKumar Kartikeya Dwivedi 	int first_struct_id;
153*0288ed67SKumar Kartikeya Dwivedi 	struct btf *btf;
154*0288ed67SKumar Kartikeya Dwivedi 	int id, err, i, n, pointee_id;
155*0288ed67SKumar Kartikeya Dwivedi 
156*0288ed67SKumar Kartikeya Dwivedi 	btf = init_btf();
157*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(btf, "init_btf"))
158*0288ed67SKumar Kartikeya Dwivedi 		return;
159*0288ed67SKumar Kartikeya Dwivedi 	first_struct_id = 5 + 2 * depth;
160*0288ed67SKumar Kartikeya Dwivedi 	for (i = 0; i < depth; i++) {
161*0288ed67SKumar Kartikeya Dwivedi 		if (i == depth - 1)
162*0288ed67SKumar Kartikeya Dwivedi 			pointee_id = first_struct_id + depth;
163*0288ed67SKumar Kartikeya Dwivedi 		else
164*0288ed67SKumar Kartikeya Dwivedi 			pointee_id = first_struct_id + (child_first ? depth - 2 - i : i + 1);
165*0288ed67SKumar Kartikeya Dwivedi 		ptr_id[i] = add_local_kptr(btf, pointee_id, "kptr");
166*0288ed67SKumar Kartikeya Dwivedi 		if (ptr_id[i] <= 0)
167*0288ed67SKumar Kartikeya Dwivedi 			goto out;
168*0288ed67SKumar Kartikeya Dwivedi 	}
169*0288ed67SKumar Kartikeya Dwivedi 	for (n = 0; n < depth; n++) {
170*0288ed67SKumar Kartikeya Dwivedi 		char name[32];
171*0288ed67SKumar Kartikeya Dwivedi 		int offset = 0;
172*0288ed67SKumar Kartikeya Dwivedi 
173*0288ed67SKumar Kartikeya Dwivedi 		i = child_first ? depth - 1 - n : n;
174*0288ed67SKumar Kartikeya Dwivedi 		snprintf(name, sizeof(name), "owner_%d", i);
175*0288ed67SKumar Kartikeya Dwivedi 		id = btf__add_struct(btf, name, shared_suffix && !i ? 16 : 8);
176*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_EQ(id, first_struct_id + n, "btf__add_struct owner"))
177*0288ed67SKumar Kartikeya Dwivedi 			goto out;
178*0288ed67SKumar Kartikeya Dwivedi 		if (shared_suffix && !i) {
179*0288ed67SKumar Kartikeya Dwivedi 			/*
180*0288ed67SKumar Kartikeya Dwivedi 			 * Visit the shared suffix through the shorter path before
181*0288ed67SKumar Kartikeya Dwivedi 			 * reaching it again with less remaining depth.
182*0288ed67SKumar Kartikeya Dwivedi 			 */
183*0288ed67SKumar Kartikeya Dwivedi 			err = btf__add_field(btf, "suffix", ptr_id[1], 0, 0);
184*0288ed67SKumar Kartikeya Dwivedi 			if (!ASSERT_OK(err, "btf__add_field owner::suffix"))
185*0288ed67SKumar Kartikeya Dwivedi 				goto out;
186*0288ed67SKumar Kartikeya Dwivedi 			offset = 64;
187*0288ed67SKumar Kartikeya Dwivedi 		}
188*0288ed67SKumar Kartikeya Dwivedi 		err = btf__add_field(btf, "next", ptr_id[i], offset, 0);
189*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_OK(err, "btf__add_field owner::next"))
190*0288ed67SKumar Kartikeya Dwivedi 			goto out;
191*0288ed67SKumar Kartikeya Dwivedi 	}
192*0288ed67SKumar Kartikeya Dwivedi 	id = btf__add_struct(btf, "plain_leaf", 4);
193*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_EQ(id, first_struct_id + depth, "btf__add_struct plain_leaf"))
194*0288ed67SKumar Kartikeya Dwivedi 		goto out;
195*0288ed67SKumar Kartikeya Dwivedi 
196*0288ed67SKumar Kartikeya Dwivedi 	err = btf__load_into_kernel(btf);
197*0288ed67SKumar Kartikeya Dwivedi 	ASSERT_EQ(err, expected_err, "check btf");
198*0288ed67SKumar Kartikeya Dwivedi out:
199*0288ed67SKumar Kartikeya Dwivedi 	btf__free(btf);
200*0288ed67SKumar Kartikeya Dwivedi }
201*0288ed67SKumar Kartikeya Dwivedi 
test_graph_depth(bool rbtree,int depth,int expected_err)202*0288ed67SKumar Kartikeya Dwivedi static void test_graph_depth(bool rbtree, int depth, int expected_err)
203*0288ed67SKumar Kartikeya Dwivedi {
204*0288ed67SKumar Kartikeya Dwivedi 	int root_type = LIST_HEAD, node_type = LIST_NODE, node_size = 24;
205*0288ed67SKumar Kartikeya Dwivedi 	int id, err, i, lock_off, root_off, size;
206*0288ed67SKumar Kartikeya Dwivedi 	struct btf *btf;
207*0288ed67SKumar Kartikeya Dwivedi 
208*0288ed67SKumar Kartikeya Dwivedi 	btf = init_btf();
209*0288ed67SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(btf, "init_btf"))
210*0288ed67SKumar Kartikeya Dwivedi 		return;
211*0288ed67SKumar Kartikeya Dwivedi 	if (rbtree) {
212*0288ed67SKumar Kartikeya Dwivedi 		root_type = btf__add_struct(btf, "bpf_rb_root", 16);
213*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_GT(root_type, 0, "btf__add_struct bpf_rb_root"))
214*0288ed67SKumar Kartikeya Dwivedi 			goto out;
215*0288ed67SKumar Kartikeya Dwivedi 		node_type = btf__add_struct(btf, "bpf_rb_node", 32);
216*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_GT(node_type, 0, "btf__add_struct bpf_rb_node"))
217*0288ed67SKumar Kartikeya Dwivedi 			goto out;
218*0288ed67SKumar Kartikeya Dwivedi 		node_size = 32;
219*0288ed67SKumar Kartikeya Dwivedi 	}
220*0288ed67SKumar Kartikeya Dwivedi 
221*0288ed67SKumar Kartikeya Dwivedi 	for (i = 0; i < depth; i++) {
222*0288ed67SKumar Kartikeya Dwivedi 		char name[32], tag[64];
223*0288ed67SKumar Kartikeya Dwivedi 
224*0288ed67SKumar Kartikeya Dwivedi 		lock_off = i ? node_size : 0;
225*0288ed67SKumar Kartikeya Dwivedi 		root_off = lock_off + 8;
226*0288ed67SKumar Kartikeya Dwivedi 		size = i == depth - 1 ? node_size : root_off + 16;
227*0288ed67SKumar Kartikeya Dwivedi 		snprintf(name, sizeof(name), "graph_owner_%d", i);
228*0288ed67SKumar Kartikeya Dwivedi 		id = btf__add_struct(btf, name, size);
229*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_GT(id, 0, "btf__add_struct graph_owner"))
230*0288ed67SKumar Kartikeya Dwivedi 			goto out;
231*0288ed67SKumar Kartikeya Dwivedi 		if (i) {
232*0288ed67SKumar Kartikeya Dwivedi 			err = btf__add_field(btf, "node", node_type, 0, 0);
233*0288ed67SKumar Kartikeya Dwivedi 			if (!ASSERT_OK(err, "btf__add_field graph_owner::node"))
234*0288ed67SKumar Kartikeya Dwivedi 				goto out;
235*0288ed67SKumar Kartikeya Dwivedi 		}
236*0288ed67SKumar Kartikeya Dwivedi 		if (i == depth - 1)
237*0288ed67SKumar Kartikeya Dwivedi 			continue;
238*0288ed67SKumar Kartikeya Dwivedi 		err = btf__add_field(btf, "lock", SPIN_LOCK, lock_off * 8, 0);
239*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_OK(err, "btf__add_field graph_owner::lock"))
240*0288ed67SKumar Kartikeya Dwivedi 			goto out;
241*0288ed67SKumar Kartikeya Dwivedi 		err = btf__add_field(btf, "root", root_type, root_off * 8, 0);
242*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_OK(err, "btf__add_field graph_owner::root"))
243*0288ed67SKumar Kartikeya Dwivedi 			goto out;
244*0288ed67SKumar Kartikeya Dwivedi 		snprintf(tag, sizeof(tag), "contains:graph_owner_%d:node", i + 1);
245*0288ed67SKumar Kartikeya Dwivedi 		err = btf__add_decl_tag(btf, tag, id, i ? 2 : 1);
246*0288ed67SKumar Kartikeya Dwivedi 		if (!ASSERT_GT(err, 0, "btf__add_decl_tag graph_owner"))
247*0288ed67SKumar Kartikeya Dwivedi 			goto out;
248*0288ed67SKumar Kartikeya Dwivedi 	}
249*0288ed67SKumar Kartikeya Dwivedi 
250*0288ed67SKumar Kartikeya Dwivedi 	err = btf__load_into_kernel(btf);
251*0288ed67SKumar Kartikeya Dwivedi 	ASSERT_EQ(err, expected_err, "check btf");
252*0288ed67SKumar Kartikeya Dwivedi out:
253*0288ed67SKumar Kartikeya Dwivedi 	btf__free(btf);
254*0288ed67SKumar Kartikeya Dwivedi }
255*0288ed67SKumar Kartikeya Dwivedi 
test_local_kptr_ownership(void)256*0288ed67SKumar Kartikeya Dwivedi void test_local_kptr_ownership(void)
257*0288ed67SKumar Kartikeya Dwivedi {
258*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("self_cycle"))
259*0288ed67SKumar Kartikeya Dwivedi 		test_self_cycle("kptr", -ELOOP);
260*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("untrusted_self_cycle"))
261*0288ed67SKumar Kartikeya Dwivedi 		test_self_cycle("kptr_untrusted", 0);
262*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("percpu_self_cycle"))
263*0288ed67SKumar Kartikeya Dwivedi 		test_self_cycle("percpu_kptr", -ELOOP);
264*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("ABA_cycle"))
265*0288ed67SKumar Kartikeya Dwivedi 		test_aba_cycle();
266*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("mixed_graph_root_cycle"))
267*0288ed67SKumar Kartikeya Dwivedi 		test_mixed_cycle();
268*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("max_acyclic"))
269*0288ed67SKumar Kartikeya Dwivedi 		test_acyclic_depth(MAX_OWNERSHIP_DEPTH, false, false, 0);
270*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("too_deep_acyclic"))
271*0288ed67SKumar Kartikeya Dwivedi 		test_acyclic_depth(MAX_OWNERSHIP_DEPTH + 1, false, false, -ELOOP);
272*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("max_acyclic_child_first"))
273*0288ed67SKumar Kartikeya Dwivedi 		test_acyclic_depth(MAX_OWNERSHIP_DEPTH, true, false, 0);
274*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("too_deep_acyclic_child_first"))
275*0288ed67SKumar Kartikeya Dwivedi 		test_acyclic_depth(MAX_OWNERSHIP_DEPTH + 1, true, false, -ELOOP);
276*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("max_acyclic_shared_suffix"))
277*0288ed67SKumar Kartikeya Dwivedi 		test_acyclic_depth(MAX_OWNERSHIP_DEPTH, false, true, 0);
278*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("too_deep_acyclic_shared_suffix"))
279*0288ed67SKumar Kartikeya Dwivedi 		test_acyclic_depth(MAX_OWNERSHIP_DEPTH + 1, false, true, -ELOOP);
280*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("list_three_types"))
281*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(false, 3, 0);
282*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("list_four_types"))
283*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(false, 4, 0);
284*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("list_max_depth"))
285*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(false, MAX_OWNERSHIP_DEPTH, 0);
286*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("list_too_deep"))
287*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(false, MAX_OWNERSHIP_DEPTH + 1, -ELOOP);
288*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("rbtree_three_types"))
289*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(true, 3, 0);
290*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("rbtree_four_types"))
291*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(true, 4, 0);
292*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("rbtree_max_depth"))
293*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(true, MAX_OWNERSHIP_DEPTH, 0);
294*0288ed67SKumar Kartikeya Dwivedi 	if (test__start_subtest("rbtree_too_deep"))
295*0288ed67SKumar Kartikeya Dwivedi 		test_graph_depth(true, MAX_OWNERSHIP_DEPTH + 1, -ELOOP);
296*0288ed67SKumar Kartikeya Dwivedi }
297