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