xref: /linux/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h (revision f5ad4101009e7f5f5984ffea6923d4fcd470932a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2020 Facebook */
3 #ifndef _BPF_TESTMOD_H
4 #define _BPF_TESTMOD_H
5 
6 #include <linux/types.h>
7 
8 struct task_struct;
9 struct cgroup;
10 
11 struct bpf_testmod_test_read_ctx {
12 	char *buf;
13 	loff_t off;
14 	size_t len;
15 };
16 
17 struct bpf_testmod_test_write_ctx {
18 	char *buf;
19 	loff_t off;
20 	size_t len;
21 };
22 
23 struct bpf_testmod_test_writable_ctx {
24 	bool early_ret;
25 	int val;
26 };
27 
28 /* BPF iter that returns *value* *n* times in a row */
29 struct bpf_iter_testmod_seq {
30 	s64 value;
31 	int cnt;
32 };
33 
34 struct bpf_testmod_ops {
35 	int (*test_1)(void);
36 	void (*test_2)(int a, int b);
37 	/* Used to test nullable arguments. */
38 	int (*test_maybe_null)(int dummy, struct task_struct *task);
39 	int (*unsupported_ops)(void);
40 	/* Used to test ref_acquired arguments. */
41 	int (*test_refcounted)(int dummy, struct task_struct *task);
42 	/* Used to test checking of __ref arguments when it not the first argument. */
43 	int (*test_refcounted_multi)(int dummy, struct task_struct *task,
44 				     struct task_struct *task2);
45 	/* Used to test returning referenced kptr. */
46 	struct task_struct *(*test_return_ref_kptr)(int dummy, struct task_struct *task,
47 						    struct cgroup *cgrp);
48 
49 	/* The following fields are used to test shadow copies. */
50 	char onebyte;
51 	struct {
52 		int a;
53 		int b;
54 	} unsupported;
55 	int data;
56 
57 	/* The following pointers are used to test the maps having multiple
58 	 * pages of trampolines.
59 	 */
60 	int (*tramp_1)(int value);
61 	int (*tramp_2)(int value);
62 	int (*tramp_3)(int value);
63 	int (*tramp_4)(int value);
64 	int (*tramp_5)(int value);
65 	int (*tramp_6)(int value);
66 	int (*tramp_7)(int value);
67 	int (*tramp_8)(int value);
68 	int (*tramp_9)(int value);
69 	int (*tramp_10)(int value);
70 	int (*tramp_11)(int value);
71 	int (*tramp_12)(int value);
72 	int (*tramp_13)(int value);
73 	int (*tramp_14)(int value);
74 	int (*tramp_15)(int value);
75 	int (*tramp_16)(int value);
76 	int (*tramp_17)(int value);
77 	int (*tramp_18)(int value);
78 	int (*tramp_19)(int value);
79 	int (*tramp_20)(int value);
80 	int (*tramp_21)(int value);
81 	int (*tramp_22)(int value);
82 	int (*tramp_23)(int value);
83 	int (*tramp_24)(int value);
84 	int (*tramp_25)(int value);
85 	int (*tramp_26)(int value);
86 	int (*tramp_27)(int value);
87 	int (*tramp_28)(int value);
88 	int (*tramp_29)(int value);
89 	int (*tramp_30)(int value);
90 	int (*tramp_31)(int value);
91 	int (*tramp_32)(int value);
92 	int (*tramp_33)(int value);
93 	int (*tramp_34)(int value);
94 	int (*tramp_35)(int value);
95 	int (*tramp_36)(int value);
96 	int (*tramp_37)(int value);
97 	int (*tramp_38)(int value);
98 	int (*tramp_39)(int value);
99 	int (*tramp_40)(int value);
100 };
101 
102 struct bpf_testmod_ops2 {
103 	int (*test_1)(void);
104 };
105 
106 struct bpf_testmod_ops3 {
107 	int (*test_1)(void);
108 	int (*test_2)(void);
109 };
110 
111 struct st_ops_args {
112 	u64 a;
113 };
114 
115 struct bpf_testmod_st_ops {
116 	int (*test_prologue)(struct st_ops_args *args);
117 	int (*test_epilogue)(struct st_ops_args *args);
118 	int (*test_pro_epilogue)(struct st_ops_args *args);
119 	struct module *owner;
120 };
121 
122 struct bpf_testmod_multi_st_ops {
123 	int (*test_1)(struct st_ops_args *args);
124 	struct hlist_node node;
125 	int id;
126 };
127 
128 #endif /* _BPF_TESTMOD_H */
129