Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
9SEC("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_%=; \
18l2_%=: \
19 gotol l3_%=; \
20l1_%=: \
21 r0 = 1; \
22 gotol l2_%=; \
23l0_%=: \
24 r0 = 2; \
25l3_%=: \
26 exit; \
27" :
28 : __imm(bpf_ktime_get_ns)
29 : __clobber_all);
30}
31
32SEC("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; \
390: \
40 r0 = 0; \
41 .rept 40000; \
42 r0 += 1; \
43 .endr; \
44 exit; \
451: gotol 0b; \
46" :
47 :
48 : __clobber_all);
49}
50
51#else
52
53SEC("socket")
54__description("cpuv4 is not supported by compiler or jit, use a dummy test")
55__success
56int dummy_test(void)
57{
58 return 0;
59}
60
61#endif
62
63char _license[] SEC("license") = "GPL";