Skip to content

Commit b86d080

Browse files
Yonghong SongKernel Patches Daemon
authored andcommitted
selftests/bpf: Add unit tests for new gotol insn
Add unit tests for gotol insn. Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
1 parent c7d75db commit b86d080

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "verifier_direct_stack_access_wraparound.skel.h"
2626
#include "verifier_div0.skel.h"
2727
#include "verifier_div_overflow.skel.h"
28+
#include "verifier_gotol.skel.h"
2829
#include "verifier_helper_access_var_len.skel.h"
2930
#include "verifier_helper_packet_access.skel.h"
3031
#include "verifier_helper_restricted.skel.h"
@@ -131,6 +132,7 @@ void test_verifier_direct_packet_access(void) { RUN(verifier_direct_packet_acces
131132
void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
132133
void test_verifier_div0(void) { RUN(verifier_div0); }
133134
void test_verifier_div_overflow(void) { RUN(verifier_div_overflow); }
135+
void test_verifier_gotol(void) { RUN(verifier_gotol); }
134136
void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_len); }
135137
void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
136138
void test_verifier_helper_restricted(void) { RUN(verifier_helper_restricted); }
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/bpf.h>
4+
#include <bpf/bpf_helpers.h>
5+
#include "bpf_misc.h"
6+
7+
#if defined(__TARGET_ARCH_x86) && __clang_major__ >= 18
8+
9+
SEC("socket")
10+
__description("gotol, small_imm")
11+
__success __success_unpriv __retval(1)
12+
__naked void gotol_small_imm(void)
13+
{
14+
asm volatile (" \
15+
call %[bpf_ktime_get_ns]; \
16+
if r0 == 0 goto l0_%=; \
17+
gotol l1_%=; \
18+
l2_%=: \
19+
gotol l3_%=; \
20+
l1_%=: \
21+
r0 = 1; \
22+
gotol l2_%=; \
23+
l0_%=: \
24+
r0 = 2; \
25+
l3_%=: \
26+
exit; \
27+
" :
28+
: __imm(bpf_ktime_get_ns)
29+
: __clobber_all);
30+
}
31+
32+
#else
33+
34+
SEC("socket")
35+
__description("cpuv4 is not supported by compiler or jit, use a dummy test")
36+
__success
37+
int dummy_test(void)
38+
{
39+
return 0;
40+
}
41+
42+
#endif
43+
44+
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)