xref: /linux/tools/testing/selftests/bpf/progs/verifier_gotol.c (revision 4f9786035f9e519db41375818e1d0b5f20da2f10)
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 #ifdef CAN_USE_GOTOL
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 SEC("socket")
33 __description("gotol, large_imm")
34 __success __failure_unpriv __retval(40000)
35 __naked void gotol_large_imm(void)
36 {
37 	asm volatile ("					\
38 	gotol 1f;					\
39 0:							\
40 	r0 = 0;						\
41 	.rept 40000;					\
42 	r0 += 1;					\
43 	.endr;						\
44 	exit;						\
45 1:	gotol 0b;					\
46 "	:
47 	:
48 	: __clobber_all);
49 }
50 
51 #else
52 
53 SEC("socket")
54 __description("cpuv4 is not supported by compiler or jit, use a dummy test")
55 __success
56 int dummy_test(void)
57 {
58 	return 0;
59 }
60 
61 #endif
62 
63 char _license[] SEC("license") = "GPL";
64