xref: /linux/tools/testing/selftests/bpf/progs/struct_ops_private_stack.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
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 "../bpf_testmod/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_2(void) __ksym;
17 
18 int val_i, val_j;
19 
20 __noinline static int subprog2(int *a, int *b)
21 {
22 	return val_i + a[10] + b[20];
23 }
24 
25 __noinline static int subprog1(int *a)
26 {
27 	/* stack size 200 bytes */
28 	int b[50] = {};
29 
30 	b[20] = 2;
31 	return subprog2(a, b);
32 }
33 
34 
35 SEC("struct_ops")
36 int BPF_PROG(test_1)
37 {
38 	/* stack size 400 bytes */
39 	int a[100] = {};
40 
41 	a[10] = 1;
42 	val_i = subprog1(a);
43 	bpf_testmod_ops3_call_test_2();
44 	return 0;
45 }
46 
47 SEC("struct_ops")
48 int BPF_PROG(test_2)
49 {
50 	/* stack size 200 bytes */
51 	int a[50] = {};
52 
53 	a[10] = 3;
54 	val_j = subprog1(a);
55 	return 0;
56 }
57 
58 SEC(".struct_ops")
59 struct bpf_testmod_ops3 testmod_1 = {
60 	.test_1 = (void *)test_1,
61 	.test_2 = (void *)test_2,
62 };
63