Skip to content

Commit faeb2dc

Browse files
Alexei Starovoitovborkmann
authored andcommitted
bpf: Add kernel test functions for fentry testing
Add few kernel functions with various number of arguments, their types and sizes for BPF trampoline testing to cover different calling conventions. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20191114185720.1641606-9-ast@kernel.org
1 parent e41074d commit faeb2dc

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎net/bpf/test_run.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,40 @@ static int bpf_test_finish(const union bpf_attr *kattr,
105105
return err;
106106
}
107107

108+
/* Integer types of various sizes and pointer combinations cover variety of
109+
* architecture dependent calling conventions. 7+ can be supported in the
110+
* future.
111+
*/
112+
int noinline bpf_fentry_test1(int a)
113+
{
114+
return a + 1;
115+
}
116+
117+
int noinline bpf_fentry_test2(int a, u64 b)
118+
{
119+
return a + b;
120+
}
121+
122+
int noinline bpf_fentry_test3(char a, int b, u64 c)
123+
{
124+
return a + b + c;
125+
}
126+
127+
int noinline bpf_fentry_test4(void *a, char b, int c, u64 d)
128+
{
129+
return (long)a + b + c + d;
130+
}
131+
132+
int noinline bpf_fentry_test5(u64 a, void *b, short c, int d, u64 e)
133+
{
134+
return a + (long)b + c + d + e;
135+
}
136+
137+
int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
138+
{
139+
return a + (long)b + c + d + (long)e + f;
140+
}
141+
108142
static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
109143
u32 headroom, u32 tailroom)
110144
{
@@ -122,6 +156,13 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
122156
kfree(data);
123157
return ERR_PTR(-EFAULT);
124158
}
159+
if (bpf_fentry_test1(1) != 2 ||
160+
bpf_fentry_test2(2, 3) != 5 ||
161+
bpf_fentry_test3(4, 5, 6) != 15 ||
162+
bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
163+
bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
164+
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111)
165+
return ERR_PTR(-EFAULT);
125166
return data;
126167
}
127168

0 commit comments

Comments
 (0)