xref: /linux/tools/testing/selftests/bpf/progs/struct_ops_private_stack.c (revision d0d106a2bd21499901299160744e5fe9f4c83ddb)
1becfe32bSYonghong Song // SPDX-License-Identifier: GPL-2.0
2becfe32bSYonghong Song 
3becfe32bSYonghong Song #include <vmlinux.h>
4becfe32bSYonghong Song #include <bpf/bpf_helpers.h>
5becfe32bSYonghong Song #include <bpf/bpf_tracing.h>
6*d6212d82SToke Høiland-Jørgensen #include "../test_kmods/bpf_testmod.h"
7becfe32bSYonghong Song 
8becfe32bSYonghong Song char _license[] SEC("license") = "GPL";
9becfe32bSYonghong Song 
10becfe32bSYonghong Song #if defined(__TARGET_ARCH_x86)
11becfe32bSYonghong Song bool skip __attribute((__section__(".data"))) = false;
12becfe32bSYonghong Song #else
13becfe32bSYonghong Song bool skip = true;
14becfe32bSYonghong Song #endif
15becfe32bSYonghong Song 
16becfe32bSYonghong Song void bpf_testmod_ops3_call_test_2(void) __ksym;
17becfe32bSYonghong Song 
18becfe32bSYonghong Song int val_i, val_j;
19becfe32bSYonghong Song 
subprog2(int * a,int * b)20becfe32bSYonghong Song __noinline static int subprog2(int *a, int *b)
21becfe32bSYonghong Song {
22becfe32bSYonghong Song 	return val_i + a[10] + b[20];
23becfe32bSYonghong Song }
24becfe32bSYonghong Song 
subprog1(int * a)25becfe32bSYonghong Song __noinline static int subprog1(int *a)
26becfe32bSYonghong Song {
27becfe32bSYonghong Song 	/* stack size 200 bytes */
28becfe32bSYonghong Song 	int b[50] = {};
29becfe32bSYonghong Song 
30becfe32bSYonghong Song 	b[20] = 2;
31becfe32bSYonghong Song 	return subprog2(a, b);
32becfe32bSYonghong Song }
33becfe32bSYonghong Song 
34becfe32bSYonghong Song 
35becfe32bSYonghong Song SEC("struct_ops")
BPF_PROG(test_1)36becfe32bSYonghong Song int BPF_PROG(test_1)
37becfe32bSYonghong Song {
38becfe32bSYonghong Song 	/* stack size 400 bytes */
39becfe32bSYonghong Song 	int a[100] = {};
40becfe32bSYonghong Song 
41becfe32bSYonghong Song 	a[10] = 1;
42becfe32bSYonghong Song 	val_i = subprog1(a);
43becfe32bSYonghong Song 	bpf_testmod_ops3_call_test_2();
44becfe32bSYonghong Song 	return 0;
45becfe32bSYonghong Song }
46becfe32bSYonghong Song 
47becfe32bSYonghong Song SEC("struct_ops")
BPF_PROG(test_2)48becfe32bSYonghong Song int BPF_PROG(test_2)
49becfe32bSYonghong Song {
50becfe32bSYonghong Song 	/* stack size 200 bytes */
51becfe32bSYonghong Song 	int a[50] = {};
52becfe32bSYonghong Song 
53becfe32bSYonghong Song 	a[10] = 3;
54becfe32bSYonghong Song 	val_j = subprog1(a);
55becfe32bSYonghong Song 	return 0;
56becfe32bSYonghong Song }
57becfe32bSYonghong Song 
58becfe32bSYonghong Song SEC(".struct_ops")
59becfe32bSYonghong Song struct bpf_testmod_ops3 testmod_1 = {
60becfe32bSYonghong Song 	.test_1 = (void *)test_1,
61becfe32bSYonghong Song 	.test_2 = (void *)test_2,
62becfe32bSYonghong Song };
63