1 {
2 	"jit: lsh, rsh, arsh by 1",
3 	.insns = {
4 	BPF_MOV64_IMM(BPF_REG_0, 1),
5 	BPF_MOV64_IMM(BPF_REG_1, 0xff),
6 	BPF_ALU64_IMM(BPF_LSH, BPF_REG_1, 1),
7 	BPF_ALU32_IMM(BPF_LSH, BPF_REG_1, 1),
8 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x3fc, 1),
9 	BPF_EXIT_INSN(),
10 	BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 1),
11 	BPF_ALU32_IMM(BPF_RSH, BPF_REG_1, 1),
12 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0xff, 1),
13 	BPF_EXIT_INSN(),
14 	BPF_ALU64_IMM(BPF_ARSH, BPF_REG_1, 1),
15 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x7f, 1),
16 	BPF_EXIT_INSN(),
17 	BPF_MOV64_IMM(BPF_REG_0, 2),
18 	BPF_EXIT_INSN(),
19 	},
20 	.result = ACCEPT,
21 	.retval = 2,
22 },
23 {
24 	"jit: lsh, rsh, arsh by reg",
25 	.insns = {
26 	BPF_MOV64_IMM(BPF_REG_0, 1),
27 	BPF_MOV64_IMM(BPF_REG_4, 1),
28 	BPF_MOV64_IMM(BPF_REG_1, 0xff),
29 	BPF_ALU64_REG(BPF_LSH, BPF_REG_1, BPF_REG_0),
30 	BPF_ALU32_REG(BPF_LSH, BPF_REG_1, BPF_REG_4),
31 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x3fc, 1),
32 	BPF_EXIT_INSN(),
33 	BPF_ALU64_REG(BPF_RSH, BPF_REG_1, BPF_REG_4),
34 	BPF_MOV64_REG(BPF_REG_4, BPF_REG_1),
35 	BPF_ALU32_REG(BPF_RSH, BPF_REG_4, BPF_REG_0),
36 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 0xff, 1),
37 	BPF_EXIT_INSN(),
38 	BPF_ALU64_REG(BPF_ARSH, BPF_REG_4, BPF_REG_4),
39 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 0, 1),
40 	BPF_EXIT_INSN(),
41 	BPF_MOV64_IMM(BPF_REG_0, 2),
42 	BPF_EXIT_INSN(),
43 	},
44 	.result = ACCEPT,
45 	.retval = 2,
46 },
47 {
48 	"jit: mov32 for ldimm64, 1",
49 	.insns = {
50 	BPF_MOV64_IMM(BPF_REG_0, 2),
51 	BPF_LD_IMM64(BPF_REG_1, 0xfeffffffffffffffULL),
52 	BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 32),
53 	BPF_LD_IMM64(BPF_REG_2, 0xfeffffffULL),
54 	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
55 	BPF_MOV64_IMM(BPF_REG_0, 1),
56 	BPF_EXIT_INSN(),
57 	},
58 	.result = ACCEPT,
59 	.retval = 2,
60 },
61 {
62 	"jit: mov32 for ldimm64, 2",
63 	.insns = {
64 	BPF_MOV64_IMM(BPF_REG_0, 1),
65 	BPF_LD_IMM64(BPF_REG_1, 0x1ffffffffULL),
66 	BPF_LD_IMM64(BPF_REG_2, 0xffffffffULL),
67 	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
68 	BPF_MOV64_IMM(BPF_REG_0, 2),
69 	BPF_EXIT_INSN(),
70 	},
71 	.result = ACCEPT,
72 	.retval = 2,
73 },
74 {
75 	"jit: various mul tests",
76 	.insns = {
77 	BPF_LD_IMM64(BPF_REG_2, 0xeeff0d413122ULL),
78 	BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
79 	BPF_LD_IMM64(BPF_REG_1, 0xefefefULL),
80 	BPF_ALU64_REG(BPF_MUL, BPF_REG_0, BPF_REG_1),
81 	BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
82 	BPF_MOV64_IMM(BPF_REG_0, 1),
83 	BPF_EXIT_INSN(),
84 	BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
85 	BPF_ALU64_REG(BPF_MUL, BPF_REG_3, BPF_REG_1),
86 	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
87 	BPF_MOV64_IMM(BPF_REG_0, 1),
88 	BPF_EXIT_INSN(),
89 	BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
90 	BPF_ALU64_IMM(BPF_MUL, BPF_REG_3, 0xefefef),
91 	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
92 	BPF_MOV64_IMM(BPF_REG_0, 1),
93 	BPF_EXIT_INSN(),
94 	BPF_MOV32_REG(BPF_REG_2, BPF_REG_2),
95 	BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
96 	BPF_ALU32_REG(BPF_MUL, BPF_REG_0, BPF_REG_1),
97 	BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
98 	BPF_MOV64_IMM(BPF_REG_0, 1),
99 	BPF_EXIT_INSN(),
100 	BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
101 	BPF_ALU32_REG(BPF_MUL, BPF_REG_3, BPF_REG_1),
102 	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
103 	BPF_MOV64_IMM(BPF_REG_0, 1),
104 	BPF_EXIT_INSN(),
105 	BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
106 	BPF_ALU32_IMM(BPF_MUL, BPF_REG_3, 0xefefef),
107 	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
108 	BPF_MOV64_IMM(BPF_REG_0, 1),
109 	BPF_EXIT_INSN(),
110 	BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
111 	BPF_LD_IMM64(BPF_REG_2, 0x2ad4d4aaULL),
112 	BPF_ALU32_IMM(BPF_MUL, BPF_REG_0, 0x2b),
113 	BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
114 	BPF_MOV64_IMM(BPF_REG_0, 1),
115 	BPF_EXIT_INSN(),
116 	BPF_LD_IMM64(BPF_REG_0, 0x952a7bbcULL),
117 	BPF_LD_IMM64(BPF_REG_1, 0xfefefeULL),
118 	BPF_LD_IMM64(BPF_REG_5, 0xeeff0d413122ULL),
119 	BPF_ALU32_REG(BPF_MUL, BPF_REG_5, BPF_REG_1),
120 	BPF_JMP_REG(BPF_JEQ, BPF_REG_5, BPF_REG_0, 2),
121 	BPF_MOV64_IMM(BPF_REG_0, 1),
122 	BPF_EXIT_INSN(),
123 	BPF_MOV64_IMM(BPF_REG_0, 2),
124 	BPF_EXIT_INSN(),
125 	},
126 	.result = ACCEPT,
127 	.retval = 2,
128 },
129 {
130 	"jit: various div tests",
131 	.insns = {
132 	BPF_LD_IMM64(BPF_REG_2, 0xefeffeULL),
133 	BPF_LD_IMM64(BPF_REG_0, 0xeeff0d413122ULL),
134 	BPF_LD_IMM64(BPF_REG_1, 0xfefeeeULL),
135 	BPF_ALU64_REG(BPF_DIV, BPF_REG_0, BPF_REG_1),
136 	BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
137 	BPF_MOV64_IMM(BPF_REG_0, 1),
138 	BPF_EXIT_INSN(),
139 	BPF_LD_IMM64(BPF_REG_3, 0xeeff0d413122ULL),
140 	BPF_ALU64_IMM(BPF_DIV, BPF_REG_3, 0xfefeeeULL),
141 	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
142 	BPF_MOV64_IMM(BPF_REG_0, 1),
143 	BPF_EXIT_INSN(),
144 	BPF_LD_IMM64(BPF_REG_2, 0xaa93ULL),
145 	BPF_ALU64_IMM(BPF_MOD, BPF_REG_1, 0xbeefULL),
146 	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 2),
147 	BPF_MOV64_IMM(BPF_REG_0, 1),
148 	BPF_EXIT_INSN(),
149 	BPF_LD_IMM64(BPF_REG_1, 0xfefeeeULL),
150 	BPF_LD_IMM64(BPF_REG_3, 0xbeefULL),
151 	BPF_ALU64_REG(BPF_MOD, BPF_REG_1, BPF_REG_3),
152 	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 2),
153 	BPF_MOV64_IMM(BPF_REG_0, 1),
154 	BPF_EXIT_INSN(),
155 	BPF_LD_IMM64(BPF_REG_2, 0x5ee1dULL),
156 	BPF_LD_IMM64(BPF_REG_1, 0xfefeeeULL),
157 	BPF_LD_IMM64(BPF_REG_3, 0x2bULL),
158 	BPF_ALU32_REG(BPF_DIV, BPF_REG_1, BPF_REG_3),
159 	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 2),
160 	BPF_MOV64_IMM(BPF_REG_0, 1),
161 	BPF_EXIT_INSN(),
162 	BPF_ALU32_REG(BPF_DIV, BPF_REG_1, BPF_REG_1),
163 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 2),
164 	BPF_MOV64_IMM(BPF_REG_0, 1),
165 	BPF_EXIT_INSN(),
166 	BPF_ALU64_REG(BPF_MOD, BPF_REG_2, BPF_REG_2),
167 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_2, 0, 2),
168 	BPF_MOV64_IMM(BPF_REG_0, 1),
169 	BPF_EXIT_INSN(),
170 	BPF_MOV64_IMM(BPF_REG_0, 2),
171 	BPF_EXIT_INSN(),
172 	},
173 	.result = ACCEPT,
174 	.retval = 2,
175 },
176 {
177 	"jit: jsgt, jslt",
178 	.insns = {
179 	BPF_LD_IMM64(BPF_REG_1, 0x80000000ULL),
180 	BPF_LD_IMM64(BPF_REG_2, 0x0ULL),
181 	BPF_JMP_REG(BPF_JSGT, BPF_REG_1, BPF_REG_2, 2),
182 	BPF_MOV64_IMM(BPF_REG_0, 1),
183 	BPF_EXIT_INSN(),
184 
185 	BPF_JMP_REG(BPF_JSLT, BPF_REG_2, BPF_REG_1, 2),
186 	BPF_MOV64_IMM(BPF_REG_0, 1),
187 	BPF_EXIT_INSN(),
188 
189 	BPF_MOV64_IMM(BPF_REG_0, 2),
190 	BPF_EXIT_INSN(),
191 	},
192 	.result = ACCEPT,
193 	.retval = 2,
194 },
195 {
196 	"jit: torturous jumps, imm8 nop jmp and pure jump padding",
197 	.insns = { },
198 	.fill_helper = bpf_fill_torturous_jumps,
199 	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
200 	.result = ACCEPT,
201 	.retval = 1,
202 },
203 {
204 	"jit: torturous jumps, imm32 nop jmp and jmp_cond padding",
205 	.insns = { },
206 	.fill_helper = bpf_fill_torturous_jumps,
207 	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
208 	.result = ACCEPT,
209 	.retval = 2,
210 },
211 {
212 	"jit: torturous jumps in subprog",
213 	.insns = { },
214 	.fill_helper = bpf_fill_torturous_jumps,
215 	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
216 	.result = ACCEPT,
217 	.retval = 3,
218 },
219