blob: 855f64093ca798bde3dbd74a3de7de023b11b837 [file] [log] [blame]
Thomas Gleixner5b497af2019-05-29 07:18:09 -07001// SPDX-License-Identifier: GPL-2.0-only
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002/*
3 * Testsuite for BPF interpreter and BPF JIT compiler
4 *
5 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/filter.h>
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -070013#include <linux/bpf.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070014#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16#include <linux/if_vlan.h>
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020017#include <linux/random.h>
Nicolas Schichanbac142a2015-08-04 15:19:08 +020018#include <linux/highmem.h>
Eric Dumazetd40bc962018-02-26 10:52:46 -080019#include <linux/sched.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070020
Daniel Borkmann10f18e02014-05-23 18:44:00 +020021/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070022#define MAX_SUBTESTS 3
Eric Dumazet9960d762018-02-28 08:39:20 -080023#define MAX_TESTRUNS 1000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070024#define MAX_DATA 128
25#define MAX_INSNS 512
26#define MAX_K 0xffffFFFF
27
Daniel Borkmann10f18e02014-05-23 18:44:00 +020028/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070029#define SKB_TYPE 3
30#define SKB_MARK 0x1234aaaa
31#define SKB_HASH 0x1234aaab
32#define SKB_QUEUE_MAP 123
33#define SKB_VLAN_TCI 0xffff
Michał Mirosław0c4b2d32018-11-10 19:58:36 +010034#define SKB_VLAN_PRESENT 1
Alexei Starovoitov64a89462014-05-08 14:10:52 -070035#define SKB_DEV_IFINDEX 577
36#define SKB_DEV_TYPE 588
37
Daniel Borkmann10f18e02014-05-23 18:44:00 +020038/* Redefine REGs to make tests less verbose */
39#define R0 BPF_REG_0
40#define R1 BPF_REG_1
41#define R2 BPF_REG_2
42#define R3 BPF_REG_3
43#define R4 BPF_REG_4
44#define R5 BPF_REG_5
45#define R6 BPF_REG_6
46#define R7 BPF_REG_7
47#define R8 BPF_REG_8
48#define R9 BPF_REG_9
49#define R10 BPF_REG_10
50
51/* Flags that can be passed to test cases */
52#define FLAG_NO_DATA BIT(0)
53#define FLAG_EXPECTED_FAIL BIT(1)
Nicolas Schichanbac142a2015-08-04 15:19:08 +020054#define FLAG_SKB_FRAG BIT(2)
Daniel Borkmann10f18e02014-05-23 18:44:00 +020055
56enum {
57 CLASSIC = BIT(6), /* Old BPF instructions only. */
58 INTERNAL = BIT(7), /* Extended instruction set. */
59};
60
61#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070062
63struct bpf_test {
64 const char *descr;
65 union {
66 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070067 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020068 struct {
69 void *insns;
70 unsigned int len;
71 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070072 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020073 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070074 __u8 data[MAX_DATA];
75 struct {
76 int data_size;
77 __u32 result;
78 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020079 int (*fill_helper)(struct bpf_test *self);
Yonghong Song09584b42018-02-02 22:37:15 -080080 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
Nicolas Schichanbac142a2015-08-04 15:19:08 +020081 __u8 frag_data[MAX_DATA];
Alexei Starovoitov105c0362017-05-30 13:31:32 -070082 int stack_depth; /* for eBPF only, since tests don't call verifier */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070083};
84
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020085/* Large test cases need separate allocation and fill handler. */
86
87static int bpf_fill_maxinsns1(struct bpf_test *self)
88{
89 unsigned int len = BPF_MAXINSNS;
90 struct sock_filter *insn;
91 __u32 k = ~0;
92 int i;
93
94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
95 if (!insn)
96 return -ENOMEM;
97
98 for (i = 0; i < len; i++, k--)
99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
100
101 self->u.ptr.insns = insn;
102 self->u.ptr.len = len;
103
104 return 0;
105}
106
107static int bpf_fill_maxinsns2(struct bpf_test *self)
108{
109 unsigned int len = BPF_MAXINSNS;
110 struct sock_filter *insn;
111 int i;
112
113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
114 if (!insn)
115 return -ENOMEM;
116
117 for (i = 0; i < len; i++)
118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
119
120 self->u.ptr.insns = insn;
121 self->u.ptr.len = len;
122
123 return 0;
124}
125
126static int bpf_fill_maxinsns3(struct bpf_test *self)
127{
128 unsigned int len = BPF_MAXINSNS;
129 struct sock_filter *insn;
130 struct rnd_state rnd;
131 int i;
132
133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
134 if (!insn)
135 return -ENOMEM;
136
137 prandom_seed_state(&rnd, 3141592653589793238ULL);
138
139 for (i = 0; i < len - 1; i++) {
140 __u32 k = prandom_u32_state(&rnd);
141
142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
143 }
144
145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
146
147 self->u.ptr.insns = insn;
148 self->u.ptr.len = len;
149
150 return 0;
151}
152
153static int bpf_fill_maxinsns4(struct bpf_test *self)
154{
155 unsigned int len = BPF_MAXINSNS + 1;
156 struct sock_filter *insn;
157 int i;
158
159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
160 if (!insn)
161 return -ENOMEM;
162
163 for (i = 0; i < len; i++)
164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
165
166 self->u.ptr.insns = insn;
167 self->u.ptr.len = len;
168
169 return 0;
170}
171
172static int bpf_fill_maxinsns5(struct bpf_test *self)
173{
174 unsigned int len = BPF_MAXINSNS;
175 struct sock_filter *insn;
176 int i;
177
178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
179 if (!insn)
180 return -ENOMEM;
181
182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
183
184 for (i = 1; i < len - 1; i++)
185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
186
187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
188
189 self->u.ptr.insns = insn;
190 self->u.ptr.len = len;
191
192 return 0;
193}
194
195static int bpf_fill_maxinsns6(struct bpf_test *self)
196{
197 unsigned int len = BPF_MAXINSNS;
198 struct sock_filter *insn;
199 int i;
200
201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
202 if (!insn)
203 return -ENOMEM;
204
205 for (i = 0; i < len - 1; i++)
206 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
207 SKF_AD_VLAN_TAG_PRESENT);
208
209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
210
211 self->u.ptr.insns = insn;
212 self->u.ptr.len = len;
213
214 return 0;
215}
216
217static int bpf_fill_maxinsns7(struct bpf_test *self)
218{
219 unsigned int len = BPF_MAXINSNS;
220 struct sock_filter *insn;
221 int i;
222
223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
224 if (!insn)
225 return -ENOMEM;
226
227 for (i = 0; i < len - 4; i++)
228 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
229 SKF_AD_CPU);
230
231 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
232 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
233 SKF_AD_CPU);
234 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
235 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
236
237 self->u.ptr.insns = insn;
238 self->u.ptr.len = len;
239
240 return 0;
241}
242
243static int bpf_fill_maxinsns8(struct bpf_test *self)
244{
245 unsigned int len = BPF_MAXINSNS;
246 struct sock_filter *insn;
247 int i, jmp_off = len - 3;
248
249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
250 if (!insn)
251 return -ENOMEM;
252
253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
254
255 for (i = 1; i < len - 1; i++)
256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
257
258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
259
260 self->u.ptr.insns = insn;
261 self->u.ptr.len = len;
262
263 return 0;
264}
265
Daniel Borkmann3b529602015-05-23 01:10:07 +0200266static int bpf_fill_maxinsns9(struct bpf_test *self)
267{
268 unsigned int len = BPF_MAXINSNS;
269 struct bpf_insn *insn;
270 int i;
271
272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
273 if (!insn)
274 return -ENOMEM;
275
276 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
277 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
278 insn[2] = BPF_EXIT_INSN();
279
280 for (i = 3; i < len - 2; i++)
281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
282
283 insn[len - 2] = BPF_EXIT_INSN();
284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
285
286 self->u.ptr.insns = insn;
287 self->u.ptr.len = len;
288
289 return 0;
290}
291
292static int bpf_fill_maxinsns10(struct bpf_test *self)
293{
294 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
295 struct bpf_insn *insn;
296 int i;
297
298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
299 if (!insn)
300 return -ENOMEM;
301
302 for (i = 0; i < hlen / 2; i++)
303 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
304 for (i = hlen - 1; i > hlen / 2; i--)
305 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
306
307 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
308 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
309 insn[hlen + 1] = BPF_EXIT_INSN();
310
311 self->u.ptr.insns = insn;
312 self->u.ptr.len = len;
313
314 return 0;
315}
316
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200317static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
318 unsigned int plen)
319{
320 struct sock_filter *insn;
321 unsigned int rlen;
322 int i, j;
323
324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
325 if (!insn)
326 return -ENOMEM;
327
328 rlen = (len % plen) - 1;
329
330 for (i = 0; i + plen < len; i += plen)
331 for (j = 0; j < plen; j++)
332 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
333 plen - 1 - j, 0, 0);
334 for (j = 0; j < rlen; j++)
335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
336 0, 0);
337
338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
339
340 self->u.ptr.insns = insn;
341 self->u.ptr.len = len;
342
343 return 0;
344}
345
346static int bpf_fill_maxinsns11(struct bpf_test *self)
347{
Gary Lin16a660e2021-01-19 18:25:00 +0800348 /* Hits 70 passes on x86_64 and triggers NOPs padding. */
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
350}
351
Daniel Borkmannbe088152018-06-02 23:06:32 +0200352static int bpf_fill_maxinsns12(struct bpf_test *self)
353{
354 unsigned int len = BPF_MAXINSNS;
355 struct sock_filter *insn;
356 int i = 0;
357
358 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
359 if (!insn)
360 return -ENOMEM;
361
362 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
363
364 for (i = 1; i < len - 1; i++)
365 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
366
367 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
368
369 self->u.ptr.insns = insn;
370 self->u.ptr.len = len;
371
372 return 0;
373}
374
375static int bpf_fill_maxinsns13(struct bpf_test *self)
376{
377 unsigned int len = BPF_MAXINSNS;
378 struct sock_filter *insn;
379 int i = 0;
380
381 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
382 if (!insn)
383 return -ENOMEM;
384
385 for (i = 0; i < len - 3; i++)
386 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
387
388 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
389 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
390 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
391
392 self->u.ptr.insns = insn;
393 self->u.ptr.len = len;
394
395 return 0;
396}
397
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200398static int bpf_fill_ja(struct bpf_test *self)
399{
400 /* Hits exactly 11 passes on x86_64 JIT. */
401 return __bpf_fill_ja(self, 12, 9);
402}
403
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700404static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
405{
406 unsigned int len = BPF_MAXINSNS;
407 struct sock_filter *insn;
408 int i;
409
410 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
411 if (!insn)
412 return -ENOMEM;
413
414 for (i = 0; i < len - 1; i += 2) {
415 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
416 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
417 SKF_AD_OFF + SKF_AD_CPU);
418 }
419
420 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
421
422 self->u.ptr.insns = insn;
423 self->u.ptr.len = len;
424
425 return 0;
426}
427
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200428static int __bpf_fill_stxdw(struct bpf_test *self, int size)
429{
430 unsigned int len = BPF_MAXINSNS;
431 struct bpf_insn *insn;
432 int i;
433
434 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
435 if (!insn)
436 return -ENOMEM;
437
438 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
439 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
440
441 for (i = 2; i < len - 2; i++)
442 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
443
444 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
445 insn[len - 1] = BPF_EXIT_INSN();
446
447 self->u.ptr.insns = insn;
448 self->u.ptr.len = len;
Alexei Starovoitov105c0362017-05-30 13:31:32 -0700449 self->stack_depth = 40;
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200450
451 return 0;
452}
453
454static int bpf_fill_stxw(struct bpf_test *self)
455{
456 return __bpf_fill_stxdw(self, BPF_W);
457}
458
459static int bpf_fill_stxdw(struct bpf_test *self)
460{
461 return __bpf_fill_stxdw(self, BPF_DW);
462}
463
Johan Almbladh66e5eb82021-08-09 11:18:25 +0200464static int bpf_fill_long_jmp(struct bpf_test *self)
465{
466 unsigned int len = BPF_MAXINSNS;
467 struct bpf_insn *insn;
468 int i;
469
470 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
471 if (!insn)
472 return -ENOMEM;
473
474 insn[0] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
475 insn[1] = BPF_JMP_IMM(BPF_JEQ, R0, 1, len - 2 - 1);
476
477 /*
478 * Fill with a complex 64-bit operation that expands to a lot of
479 * instructions on 32-bit JITs. The large jump offset can then
480 * overflow the conditional branch field size, triggering a branch
481 * conversion mechanism in some JITs.
482 *
483 * Note: BPF_MAXINSNS of ALU64 MUL is enough to trigger such branch
484 * conversion on the 32-bit MIPS JIT. For other JITs, the instruction
485 * count and/or operation may need to be modified to trigger the
486 * branch conversion.
487 */
488 for (i = 2; i < len - 1; i++)
489 insn[i] = BPF_ALU64_IMM(BPF_MUL, R0, (i << 16) + i);
490
491 insn[len - 1] = BPF_EXIT_INSN();
492
493 self->u.ptr.insns = insn;
494 self->u.ptr.len = len;
495
496 return 0;
497}
498
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700499static struct bpf_test tests[] = {
500 {
501 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700502 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700503 BPF_STMT(BPF_LD | BPF_IMM, 1),
504 BPF_STMT(BPF_MISC | BPF_TAX, 0),
505 BPF_STMT(BPF_LD | BPF_IMM, 2),
506 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
507 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
508 BPF_STMT(BPF_MISC | BPF_TAX, 0),
509 BPF_STMT(BPF_LD | BPF_LEN, 0),
510 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
511 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
512 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
513 BPF_STMT(BPF_RET | BPF_A, 0)
514 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200515 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700516 { 10, 20, 30, 40, 50 },
517 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
518 },
519 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700520 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700521 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700522 BPF_STMT(BPF_LDX | BPF_LEN, 0),
523 BPF_STMT(BPF_MISC | BPF_TXA, 0),
524 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
525 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
526 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200527 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700528 { 10, 20, 30, 40, 50 },
529 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
530 },
531 {
532 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700533 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700534 BPF_STMT(BPF_LD | BPF_IMM, 1),
535 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
536 BPF_STMT(BPF_LDX | BPF_IMM, 3),
537 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
538 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
539 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
540 BPF_STMT(BPF_RET | BPF_A, 0)
541 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200542 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700543 { },
544 { { 0, 0xfffffffd } }
545 },
546 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300547 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700548 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700549 BPF_STMT(BPF_LD | BPF_IMM, 8),
550 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
551 BPF_STMT(BPF_MISC | BPF_TAX, 0),
552 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
553 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
554 BPF_STMT(BPF_MISC | BPF_TAX, 0),
555 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
556 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300557 BPF_STMT(BPF_MISC | BPF_TAX, 0),
558 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
559 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
560 BPF_STMT(BPF_MISC | BPF_TAX, 0),
561 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
562 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700563 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
564 BPF_STMT(BPF_RET | BPF_A, 0)
565 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200566 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700567 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300568 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700569 },
570 {
571 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700572 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700573 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
574 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
575 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
576 BPF_STMT(BPF_MISC | BPF_TAX, 0),
577 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
578 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
579 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
580 BPF_STMT(BPF_RET | BPF_A, 0)
581 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200582 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700583 { },
584 { { 0, 0x800000ff }, { 1, 0x800000ff } },
585 },
586 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700587 "LD_IMM_0",
588 .u.insns = {
589 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
591 BPF_STMT(BPF_RET | BPF_K, 0),
592 BPF_STMT(BPF_RET | BPF_K, 1),
593 },
594 CLASSIC,
595 { },
596 { { 1, 1 } },
597 },
598 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700599 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700600 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
603 BPF_STMT(BPF_RET | BPF_K, 1)
604 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200605 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700606 { },
607 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
608 },
609 {
610 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700611 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700612 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
613 BPF_STMT(BPF_RET | BPF_K, 1)
614 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200615 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700616 { },
617 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
618 },
619 {
620 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700621 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700622 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
623 BPF_STMT(BPF_MISC | BPF_TAX, 0),
624 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
625 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
626 BPF_STMT(BPF_RET | BPF_A, 0)
627 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200628 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700629 { 1, 2, 3 },
630 { { 1, 0 }, { 2, 3 } },
631 },
632 {
633 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700634 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700635 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
636 BPF_STMT(BPF_LDX | BPF_LEN, 0),
637 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
638 BPF_STMT(BPF_MISC | BPF_TAX, 0),
639 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
640 BPF_STMT(BPF_RET | BPF_A, 0)
641 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200642 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700643 { 1, 2, 3, 0xff },
644 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
645 },
646 {
647 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700648 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700649 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
650 BPF_STMT(BPF_MISC | BPF_TAX, 0),
651 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
652 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
653 BPF_STMT(BPF_RET | BPF_A, 0)
654 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200655 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700656 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
657 { { 15, 0 }, { 16, 3 } },
658 },
659 {
660 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700661 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700662 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
663 BPF_STMT(BPF_LDX | BPF_LEN, 0),
664 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
665 BPF_STMT(BPF_MISC | BPF_TAX, 0),
666 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
667 BPF_STMT(BPF_RET | BPF_A, 0)
668 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200669 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700670 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
671 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
672 },
673 {
674 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700675 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700676 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
677 SKF_AD_OFF + SKF_AD_PKTTYPE),
678 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
679 BPF_STMT(BPF_RET | BPF_K, 1),
680 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
681 SKF_AD_OFF + SKF_AD_PKTTYPE),
682 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
683 BPF_STMT(BPF_RET | BPF_K, 1),
684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_PKTTYPE),
686 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
687 BPF_STMT(BPF_RET | BPF_K, 1),
688 BPF_STMT(BPF_RET | BPF_A, 0)
689 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200690 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700691 { },
692 { { 1, 3 }, { 10, 3 } },
693 },
694 {
695 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700696 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700697 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
698 SKF_AD_OFF + SKF_AD_MARK),
699 BPF_STMT(BPF_RET | BPF_A, 0)
700 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200701 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700702 { },
703 { { 1, SKB_MARK}, { 10, SKB_MARK} },
704 },
705 {
706 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700707 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700708 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
709 SKF_AD_OFF + SKF_AD_RXHASH),
710 BPF_STMT(BPF_RET | BPF_A, 0)
711 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200712 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700713 { },
714 { { 1, SKB_HASH}, { 10, SKB_HASH} },
715 },
716 {
717 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700718 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700719 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
720 SKF_AD_OFF + SKF_AD_QUEUE),
721 BPF_STMT(BPF_RET | BPF_A, 0)
722 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200723 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700724 { },
725 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
726 },
727 {
728 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700729 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700730 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
731 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
732 BPF_STMT(BPF_RET | BPF_K, 0),
733 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
734 SKF_AD_OFF + SKF_AD_PROTOCOL),
735 BPF_STMT(BPF_MISC | BPF_TAX, 0),
736 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
737 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
738 BPF_STMT(BPF_RET | BPF_K, 0),
739 BPF_STMT(BPF_MISC | BPF_TXA, 0),
740 BPF_STMT(BPF_RET | BPF_A, 0)
741 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200742 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700743 { 10, 20, 30 },
744 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
745 },
746 {
747 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700748 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700749 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
750 SKF_AD_OFF + SKF_AD_VLAN_TAG),
751 BPF_STMT(BPF_RET | BPF_A, 0)
752 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200753 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700754 { },
755 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100756 { 1, SKB_VLAN_TCI },
757 { 10, SKB_VLAN_TCI }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700758 },
759 },
760 {
761 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700762 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700763 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
764 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
765 BPF_STMT(BPF_RET | BPF_A, 0)
766 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200767 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700768 { },
769 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100770 { 1, SKB_VLAN_PRESENT },
771 { 10, SKB_VLAN_PRESENT }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700772 },
773 },
774 {
775 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700776 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700777 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
778 SKF_AD_OFF + SKF_AD_IFINDEX),
779 BPF_STMT(BPF_RET | BPF_A, 0)
780 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200781 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700782 { },
783 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
784 },
785 {
786 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700787 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700788 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
789 SKF_AD_OFF + SKF_AD_HATYPE),
790 BPF_STMT(BPF_RET | BPF_A, 0)
791 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200792 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700793 { },
794 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
795 },
796 {
797 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700798 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700799 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
800 SKF_AD_OFF + SKF_AD_CPU),
801 BPF_STMT(BPF_MISC | BPF_TAX, 0),
802 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
803 SKF_AD_OFF + SKF_AD_CPU),
804 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
805 BPF_STMT(BPF_RET | BPF_A, 0)
806 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200807 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700808 { },
809 { { 1, 0 }, { 10, 0 } },
810 },
811 {
812 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700813 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700814 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700815 BPF_STMT(BPF_MISC | BPF_TXA, 0),
816 BPF_STMT(BPF_LDX | BPF_IMM, 3),
817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_NLATTR),
819 BPF_STMT(BPF_RET | BPF_A, 0)
820 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200821 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700822#ifdef __BIG_ENDIAN
823 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
824#else
825 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
826#endif
827 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700828 },
829 {
830 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700831 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700832 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700833 BPF_STMT(BPF_LDX | BPF_IMM, 3),
834 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
835 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700836 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700839 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700840 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
841 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700842 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700843 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
844 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700845 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700846 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
847 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700848 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700849 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
850 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700851 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700852 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
853 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700854 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700855 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
856 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
857 BPF_STMT(BPF_RET | BPF_A, 0)
858 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200859 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700860#ifdef __BIG_ENDIAN
861 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
862#else
863 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
864#endif
865 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700866 },
867 {
868 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700869 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700870 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
871 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
872 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
873 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
874 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
875 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
876 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
877 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
878 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
879 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
880 BPF_STMT(BPF_RET | BPF_A, 0)
881 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200882 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700883 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
884 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
885 * id 9737, seq 1, length 64
886 */
887 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
889 0x08, 0x00,
890 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
891 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
892 { { 30, 0 }, { 100, 42 } },
893 },
894 {
895 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700896 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700897 BPF_STMT(BPF_LD | BPF_IMM, 10),
898 BPF_STMT(BPF_LDX | BPF_IMM, 300),
899 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
900 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
901 BPF_STMT(BPF_RET | BPF_A, 0)
902 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200903 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700904 { },
Nathan Chancellor09845432019-08-18 21:34:20 -0700905 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700906 },
907 {
908 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700909 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700910 BPF_STMT(BPF_LDX | BPF_LEN, 0),
911 BPF_STMT(BPF_LD | BPF_IMM, 2),
912 BPF_STMT(BPF_ALU | BPF_RSH, 1),
913 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
914 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
915 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
916 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
917 BPF_STMT(BPF_STX, 15), /* M3 = len */
918 BPF_STMT(BPF_LDX | BPF_MEM, 1),
919 BPF_STMT(BPF_LD | BPF_MEM, 2),
920 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
921 BPF_STMT(BPF_LDX | BPF_MEM, 15),
922 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
923 BPF_STMT(BPF_RET | BPF_A, 0)
924 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200925 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700926 { },
927 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
928 },
929 {
930 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700931 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700932 BPF_STMT(BPF_LDX | BPF_LEN, 0),
933 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
934 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
935 BPF_STMT(BPF_RET | BPF_K, 1),
936 BPF_STMT(BPF_RET | BPF_K, MAX_K)
937 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200938 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700939 { 3, 3, 3, 3, 3 },
940 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
941 },
942 {
943 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700944 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700945 BPF_STMT(BPF_LDX | BPF_LEN, 0),
946 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
947 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
948 BPF_STMT(BPF_RET | BPF_K, 1),
949 BPF_STMT(BPF_RET | BPF_K, MAX_K)
950 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200951 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700952 { 4, 4, 4, 3, 3 },
953 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
954 },
955 {
Daniel Borkmann92b31a92017-08-10 01:39:55 +0200956 "JGE (jt 0), test 1",
957 .u.insns = {
958 BPF_STMT(BPF_LDX | BPF_LEN, 0),
959 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
960 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
961 BPF_STMT(BPF_RET | BPF_K, 1),
962 BPF_STMT(BPF_RET | BPF_K, MAX_K)
963 },
964 CLASSIC,
965 { 4, 4, 4, 3, 3 },
966 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
967 },
968 {
969 "JGE (jt 0), test 2",
970 .u.insns = {
971 BPF_STMT(BPF_LDX | BPF_LEN, 0),
972 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
973 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
974 BPF_STMT(BPF_RET | BPF_K, 1),
975 BPF_STMT(BPF_RET | BPF_K, MAX_K)
976 },
977 CLASSIC,
978 { 4, 4, 5, 3, 3 },
979 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
980 },
981 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700982 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700983 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700984 BPF_STMT(BPF_LDX | BPF_LEN, 0),
985 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
986 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
987 BPF_STMT(BPF_RET | BPF_K, 10),
988 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
989 BPF_STMT(BPF_RET | BPF_K, 20),
990 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
991 BPF_STMT(BPF_RET | BPF_K, 30),
992 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
993 BPF_STMT(BPF_RET | BPF_K, 40),
994 BPF_STMT(BPF_RET | BPF_K, MAX_K)
995 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200996 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700997 { 1, 2, 3, 4, 5 },
998 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
999 },
1000 {
1001 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -07001002 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001003 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1004 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
1005 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1006 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1007 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1008 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1009 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
1010 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1011 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
1012 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
1013 BPF_STMT(BPF_RET | BPF_K, 10),
1014 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
1015 BPF_STMT(BPF_RET | BPF_K, 20),
1016 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1017 BPF_STMT(BPF_RET | BPF_K, 30),
1018 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1019 BPF_STMT(BPF_RET | BPF_K, 30),
1020 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1021 BPF_STMT(BPF_RET | BPF_K, 30),
1022 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1023 BPF_STMT(BPF_RET | BPF_K, 30),
1024 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1025 BPF_STMT(BPF_RET | BPF_K, 30),
1026 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1027 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001028 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001029 { 0, 0xAA, 0x55, 1 },
1030 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
1031 },
1032 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001033 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -07001034 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +02001035 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1036 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1037 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1038 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1039 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1040 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1041 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1042 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1043 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1044 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1045 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1046 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1047 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1048 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1049 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1050 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1051 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1052 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1053 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1054 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1055 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1056 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1057 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1058 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001059 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001060 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001061 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1062 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1063 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1064 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1065 */
1066 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1067 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1068 0x08, 0x00,
1069 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1070 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1071 0x0a, 0x01, 0x01, 0x95, /* ip src */
1072 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1073 0xc2, 0x24,
1074 0x00, 0x16 /* dst port */ },
1075 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1076 },
1077 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001078 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001079 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001080 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1081 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1082 * (len > 115 or len < 30000000000)' -d
1083 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001084 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1085 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1086 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1087 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1088 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1089 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1090 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1091 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1092 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1093 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1094 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1095 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1096 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1097 BPF_STMT(BPF_ST, 1),
1098 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1099 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1100 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1101 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1102 BPF_STMT(BPF_LD | BPF_MEM, 1),
1103 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1104 BPF_STMT(BPF_ST, 5),
1105 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1106 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1107 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1108 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1109 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1110 BPF_STMT(BPF_LD | BPF_MEM, 5),
1111 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1112 BPF_STMT(BPF_LD | BPF_LEN, 0),
1113 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1114 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1115 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1116 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001117 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001118 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001119 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1120 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1121 0x08, 0x00,
1122 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1123 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1124 0x0a, 0x01, 0x01, 0x95, /* ip src */
1125 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1126 0xc2, 0x24,
1127 0x00, 0x16 /* dst port */ },
1128 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1129 },
1130 {
1131 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001132 .u.insns = {
Zhen Lei53b0fe32021-07-07 18:07:28 -07001133 /* check that uninitialized X and A contain zeros */
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001134 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1135 BPF_STMT(BPF_RET | BPF_A, 0)
1136 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001137 CLASSIC,
1138 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001139 { {1, 0}, {2, 0} },
1140 },
1141 {
1142 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001143 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001144 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1145 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1146 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1147 BPF_ALU64_REG(BPF_SUB, R1, R2),
1148 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1149 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1150 BPF_ALU64_REG(BPF_MOV, R0, R1),
1151 BPF_EXIT_INSN(),
1152 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001153 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001154 { },
1155 { { 0, 0xfffffffd } }
1156 },
1157 {
1158 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001159 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001160 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1161 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1162 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1163 BPF_ALU64_REG(BPF_MUL, R1, R2),
1164 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1165 BPF_EXIT_INSN(),
1166 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1167 BPF_EXIT_INSN(),
1168 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001169 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001170 { },
1171 { { 0, 1 } }
1172 },
1173 {
1174 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001175 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001176 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1177 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1178 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1179 BPF_ALU64_REG(BPF_MUL, R1, R2),
1180 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1181 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1182 BPF_EXIT_INSN(),
1183 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1184 BPF_EXIT_INSN(),
1185 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001186 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001187 { },
1188 { { 0, 1 } }
1189 },
1190 {
1191 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001192 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001193 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1194 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1195 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1196 BPF_ALU32_REG(BPF_MUL, R1, R2),
1197 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1198 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1199 BPF_EXIT_INSN(),
1200 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1201 BPF_EXIT_INSN(),
1202 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001203 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001204 { },
1205 { { 0, 1 } }
1206 },
1207 {
1208 /* Have to test all register combinations, since
1209 * JITing of different registers will produce
1210 * different asm code.
1211 */
1212 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001213 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001214 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1215 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1216 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1217 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1218 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1219 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1220 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1221 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1222 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1223 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1224 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1225 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1226 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1227 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1228 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1229 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1230 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1231 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1232 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1233 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1234 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1235 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1236 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1237 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1238 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1239 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1240 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1241 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1242 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1243 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1244 BPF_ALU64_REG(BPF_ADD, R0, R0),
1245 BPF_ALU64_REG(BPF_ADD, R0, R1),
1246 BPF_ALU64_REG(BPF_ADD, R0, R2),
1247 BPF_ALU64_REG(BPF_ADD, R0, R3),
1248 BPF_ALU64_REG(BPF_ADD, R0, R4),
1249 BPF_ALU64_REG(BPF_ADD, R0, R5),
1250 BPF_ALU64_REG(BPF_ADD, R0, R6),
1251 BPF_ALU64_REG(BPF_ADD, R0, R7),
1252 BPF_ALU64_REG(BPF_ADD, R0, R8),
1253 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1254 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1255 BPF_EXIT_INSN(),
1256 BPF_ALU64_REG(BPF_ADD, R1, R0),
1257 BPF_ALU64_REG(BPF_ADD, R1, R1),
1258 BPF_ALU64_REG(BPF_ADD, R1, R2),
1259 BPF_ALU64_REG(BPF_ADD, R1, R3),
1260 BPF_ALU64_REG(BPF_ADD, R1, R4),
1261 BPF_ALU64_REG(BPF_ADD, R1, R5),
1262 BPF_ALU64_REG(BPF_ADD, R1, R6),
1263 BPF_ALU64_REG(BPF_ADD, R1, R7),
1264 BPF_ALU64_REG(BPF_ADD, R1, R8),
1265 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1266 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1267 BPF_EXIT_INSN(),
1268 BPF_ALU64_REG(BPF_ADD, R2, R0),
1269 BPF_ALU64_REG(BPF_ADD, R2, R1),
1270 BPF_ALU64_REG(BPF_ADD, R2, R2),
1271 BPF_ALU64_REG(BPF_ADD, R2, R3),
1272 BPF_ALU64_REG(BPF_ADD, R2, R4),
1273 BPF_ALU64_REG(BPF_ADD, R2, R5),
1274 BPF_ALU64_REG(BPF_ADD, R2, R6),
1275 BPF_ALU64_REG(BPF_ADD, R2, R7),
1276 BPF_ALU64_REG(BPF_ADD, R2, R8),
1277 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1278 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1279 BPF_EXIT_INSN(),
1280 BPF_ALU64_REG(BPF_ADD, R3, R0),
1281 BPF_ALU64_REG(BPF_ADD, R3, R1),
1282 BPF_ALU64_REG(BPF_ADD, R3, R2),
1283 BPF_ALU64_REG(BPF_ADD, R3, R3),
1284 BPF_ALU64_REG(BPF_ADD, R3, R4),
1285 BPF_ALU64_REG(BPF_ADD, R3, R5),
1286 BPF_ALU64_REG(BPF_ADD, R3, R6),
1287 BPF_ALU64_REG(BPF_ADD, R3, R7),
1288 BPF_ALU64_REG(BPF_ADD, R3, R8),
1289 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1290 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1291 BPF_EXIT_INSN(),
1292 BPF_ALU64_REG(BPF_ADD, R4, R0),
1293 BPF_ALU64_REG(BPF_ADD, R4, R1),
1294 BPF_ALU64_REG(BPF_ADD, R4, R2),
1295 BPF_ALU64_REG(BPF_ADD, R4, R3),
1296 BPF_ALU64_REG(BPF_ADD, R4, R4),
1297 BPF_ALU64_REG(BPF_ADD, R4, R5),
1298 BPF_ALU64_REG(BPF_ADD, R4, R6),
1299 BPF_ALU64_REG(BPF_ADD, R4, R7),
1300 BPF_ALU64_REG(BPF_ADD, R4, R8),
1301 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1302 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1303 BPF_EXIT_INSN(),
1304 BPF_ALU64_REG(BPF_ADD, R5, R0),
1305 BPF_ALU64_REG(BPF_ADD, R5, R1),
1306 BPF_ALU64_REG(BPF_ADD, R5, R2),
1307 BPF_ALU64_REG(BPF_ADD, R5, R3),
1308 BPF_ALU64_REG(BPF_ADD, R5, R4),
1309 BPF_ALU64_REG(BPF_ADD, R5, R5),
1310 BPF_ALU64_REG(BPF_ADD, R5, R6),
1311 BPF_ALU64_REG(BPF_ADD, R5, R7),
1312 BPF_ALU64_REG(BPF_ADD, R5, R8),
1313 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1314 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1315 BPF_EXIT_INSN(),
1316 BPF_ALU64_REG(BPF_ADD, R6, R0),
1317 BPF_ALU64_REG(BPF_ADD, R6, R1),
1318 BPF_ALU64_REG(BPF_ADD, R6, R2),
1319 BPF_ALU64_REG(BPF_ADD, R6, R3),
1320 BPF_ALU64_REG(BPF_ADD, R6, R4),
1321 BPF_ALU64_REG(BPF_ADD, R6, R5),
1322 BPF_ALU64_REG(BPF_ADD, R6, R6),
1323 BPF_ALU64_REG(BPF_ADD, R6, R7),
1324 BPF_ALU64_REG(BPF_ADD, R6, R8),
1325 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1326 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1327 BPF_EXIT_INSN(),
1328 BPF_ALU64_REG(BPF_ADD, R7, R0),
1329 BPF_ALU64_REG(BPF_ADD, R7, R1),
1330 BPF_ALU64_REG(BPF_ADD, R7, R2),
1331 BPF_ALU64_REG(BPF_ADD, R7, R3),
1332 BPF_ALU64_REG(BPF_ADD, R7, R4),
1333 BPF_ALU64_REG(BPF_ADD, R7, R5),
1334 BPF_ALU64_REG(BPF_ADD, R7, R6),
1335 BPF_ALU64_REG(BPF_ADD, R7, R7),
1336 BPF_ALU64_REG(BPF_ADD, R7, R8),
1337 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1338 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1339 BPF_EXIT_INSN(),
1340 BPF_ALU64_REG(BPF_ADD, R8, R0),
1341 BPF_ALU64_REG(BPF_ADD, R8, R1),
1342 BPF_ALU64_REG(BPF_ADD, R8, R2),
1343 BPF_ALU64_REG(BPF_ADD, R8, R3),
1344 BPF_ALU64_REG(BPF_ADD, R8, R4),
1345 BPF_ALU64_REG(BPF_ADD, R8, R5),
1346 BPF_ALU64_REG(BPF_ADD, R8, R6),
1347 BPF_ALU64_REG(BPF_ADD, R8, R7),
1348 BPF_ALU64_REG(BPF_ADD, R8, R8),
1349 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1350 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1351 BPF_EXIT_INSN(),
1352 BPF_ALU64_REG(BPF_ADD, R9, R0),
1353 BPF_ALU64_REG(BPF_ADD, R9, R1),
1354 BPF_ALU64_REG(BPF_ADD, R9, R2),
1355 BPF_ALU64_REG(BPF_ADD, R9, R3),
1356 BPF_ALU64_REG(BPF_ADD, R9, R4),
1357 BPF_ALU64_REG(BPF_ADD, R9, R5),
1358 BPF_ALU64_REG(BPF_ADD, R9, R6),
1359 BPF_ALU64_REG(BPF_ADD, R9, R7),
1360 BPF_ALU64_REG(BPF_ADD, R9, R8),
1361 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1362 BPF_ALU64_REG(BPF_MOV, R0, R9),
1363 BPF_EXIT_INSN(),
1364 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001365 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001366 { },
1367 { { 0, 2957380 } }
1368 },
1369 {
1370 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001371 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001372 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1373 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1374 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1375 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1376 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1377 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1378 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1379 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1380 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1381 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1382 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1383 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1384 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1385 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1386 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1387 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1388 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1389 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1390 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1391 BPF_ALU32_REG(BPF_ADD, R0, R1),
1392 BPF_ALU32_REG(BPF_ADD, R0, R2),
1393 BPF_ALU32_REG(BPF_ADD, R0, R3),
1394 BPF_ALU32_REG(BPF_ADD, R0, R4),
1395 BPF_ALU32_REG(BPF_ADD, R0, R5),
1396 BPF_ALU32_REG(BPF_ADD, R0, R6),
1397 BPF_ALU32_REG(BPF_ADD, R0, R7),
1398 BPF_ALU32_REG(BPF_ADD, R0, R8),
1399 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1400 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1401 BPF_EXIT_INSN(),
1402 BPF_ALU32_REG(BPF_ADD, R1, R0),
1403 BPF_ALU32_REG(BPF_ADD, R1, R1),
1404 BPF_ALU32_REG(BPF_ADD, R1, R2),
1405 BPF_ALU32_REG(BPF_ADD, R1, R3),
1406 BPF_ALU32_REG(BPF_ADD, R1, R4),
1407 BPF_ALU32_REG(BPF_ADD, R1, R5),
1408 BPF_ALU32_REG(BPF_ADD, R1, R6),
1409 BPF_ALU32_REG(BPF_ADD, R1, R7),
1410 BPF_ALU32_REG(BPF_ADD, R1, R8),
1411 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1412 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1413 BPF_EXIT_INSN(),
1414 BPF_ALU32_REG(BPF_ADD, R2, R0),
1415 BPF_ALU32_REG(BPF_ADD, R2, R1),
1416 BPF_ALU32_REG(BPF_ADD, R2, R2),
1417 BPF_ALU32_REG(BPF_ADD, R2, R3),
1418 BPF_ALU32_REG(BPF_ADD, R2, R4),
1419 BPF_ALU32_REG(BPF_ADD, R2, R5),
1420 BPF_ALU32_REG(BPF_ADD, R2, R6),
1421 BPF_ALU32_REG(BPF_ADD, R2, R7),
1422 BPF_ALU32_REG(BPF_ADD, R2, R8),
1423 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1424 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1425 BPF_EXIT_INSN(),
1426 BPF_ALU32_REG(BPF_ADD, R3, R0),
1427 BPF_ALU32_REG(BPF_ADD, R3, R1),
1428 BPF_ALU32_REG(BPF_ADD, R3, R2),
1429 BPF_ALU32_REG(BPF_ADD, R3, R3),
1430 BPF_ALU32_REG(BPF_ADD, R3, R4),
1431 BPF_ALU32_REG(BPF_ADD, R3, R5),
1432 BPF_ALU32_REG(BPF_ADD, R3, R6),
1433 BPF_ALU32_REG(BPF_ADD, R3, R7),
1434 BPF_ALU32_REG(BPF_ADD, R3, R8),
1435 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1436 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1437 BPF_EXIT_INSN(),
1438 BPF_ALU32_REG(BPF_ADD, R4, R0),
1439 BPF_ALU32_REG(BPF_ADD, R4, R1),
1440 BPF_ALU32_REG(BPF_ADD, R4, R2),
1441 BPF_ALU32_REG(BPF_ADD, R4, R3),
1442 BPF_ALU32_REG(BPF_ADD, R4, R4),
1443 BPF_ALU32_REG(BPF_ADD, R4, R5),
1444 BPF_ALU32_REG(BPF_ADD, R4, R6),
1445 BPF_ALU32_REG(BPF_ADD, R4, R7),
1446 BPF_ALU32_REG(BPF_ADD, R4, R8),
1447 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1448 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1449 BPF_EXIT_INSN(),
1450 BPF_ALU32_REG(BPF_ADD, R5, R0),
1451 BPF_ALU32_REG(BPF_ADD, R5, R1),
1452 BPF_ALU32_REG(BPF_ADD, R5, R2),
1453 BPF_ALU32_REG(BPF_ADD, R5, R3),
1454 BPF_ALU32_REG(BPF_ADD, R5, R4),
1455 BPF_ALU32_REG(BPF_ADD, R5, R5),
1456 BPF_ALU32_REG(BPF_ADD, R5, R6),
1457 BPF_ALU32_REG(BPF_ADD, R5, R7),
1458 BPF_ALU32_REG(BPF_ADD, R5, R8),
1459 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1460 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1461 BPF_EXIT_INSN(),
1462 BPF_ALU32_REG(BPF_ADD, R6, R0),
1463 BPF_ALU32_REG(BPF_ADD, R6, R1),
1464 BPF_ALU32_REG(BPF_ADD, R6, R2),
1465 BPF_ALU32_REG(BPF_ADD, R6, R3),
1466 BPF_ALU32_REG(BPF_ADD, R6, R4),
1467 BPF_ALU32_REG(BPF_ADD, R6, R5),
1468 BPF_ALU32_REG(BPF_ADD, R6, R6),
1469 BPF_ALU32_REG(BPF_ADD, R6, R7),
1470 BPF_ALU32_REG(BPF_ADD, R6, R8),
1471 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1472 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1473 BPF_EXIT_INSN(),
1474 BPF_ALU32_REG(BPF_ADD, R7, R0),
1475 BPF_ALU32_REG(BPF_ADD, R7, R1),
1476 BPF_ALU32_REG(BPF_ADD, R7, R2),
1477 BPF_ALU32_REG(BPF_ADD, R7, R3),
1478 BPF_ALU32_REG(BPF_ADD, R7, R4),
1479 BPF_ALU32_REG(BPF_ADD, R7, R5),
1480 BPF_ALU32_REG(BPF_ADD, R7, R6),
1481 BPF_ALU32_REG(BPF_ADD, R7, R7),
1482 BPF_ALU32_REG(BPF_ADD, R7, R8),
1483 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1484 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1485 BPF_EXIT_INSN(),
1486 BPF_ALU32_REG(BPF_ADD, R8, R0),
1487 BPF_ALU32_REG(BPF_ADD, R8, R1),
1488 BPF_ALU32_REG(BPF_ADD, R8, R2),
1489 BPF_ALU32_REG(BPF_ADD, R8, R3),
1490 BPF_ALU32_REG(BPF_ADD, R8, R4),
1491 BPF_ALU32_REG(BPF_ADD, R8, R5),
1492 BPF_ALU32_REG(BPF_ADD, R8, R6),
1493 BPF_ALU32_REG(BPF_ADD, R8, R7),
1494 BPF_ALU32_REG(BPF_ADD, R8, R8),
1495 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1496 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1497 BPF_EXIT_INSN(),
1498 BPF_ALU32_REG(BPF_ADD, R9, R0),
1499 BPF_ALU32_REG(BPF_ADD, R9, R1),
1500 BPF_ALU32_REG(BPF_ADD, R9, R2),
1501 BPF_ALU32_REG(BPF_ADD, R9, R3),
1502 BPF_ALU32_REG(BPF_ADD, R9, R4),
1503 BPF_ALU32_REG(BPF_ADD, R9, R5),
1504 BPF_ALU32_REG(BPF_ADD, R9, R6),
1505 BPF_ALU32_REG(BPF_ADD, R9, R7),
1506 BPF_ALU32_REG(BPF_ADD, R9, R8),
1507 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1508 BPF_ALU32_REG(BPF_MOV, R0, R9),
1509 BPF_EXIT_INSN(),
1510 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001511 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001512 { },
1513 { { 0, 2957380 } }
1514 },
1515 { /* Mainly checking JIT here. */
1516 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001517 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001518 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1519 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1520 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1521 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1522 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1523 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1524 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1525 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1526 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1527 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1528 BPF_ALU64_REG(BPF_SUB, R0, R0),
1529 BPF_ALU64_REG(BPF_SUB, R0, R1),
1530 BPF_ALU64_REG(BPF_SUB, R0, R2),
1531 BPF_ALU64_REG(BPF_SUB, R0, R3),
1532 BPF_ALU64_REG(BPF_SUB, R0, R4),
1533 BPF_ALU64_REG(BPF_SUB, R0, R5),
1534 BPF_ALU64_REG(BPF_SUB, R0, R6),
1535 BPF_ALU64_REG(BPF_SUB, R0, R7),
1536 BPF_ALU64_REG(BPF_SUB, R0, R8),
1537 BPF_ALU64_REG(BPF_SUB, R0, R9),
1538 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1539 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1540 BPF_EXIT_INSN(),
1541 BPF_ALU64_REG(BPF_SUB, R1, R0),
1542 BPF_ALU64_REG(BPF_SUB, R1, R2),
1543 BPF_ALU64_REG(BPF_SUB, R1, R3),
1544 BPF_ALU64_REG(BPF_SUB, R1, R4),
1545 BPF_ALU64_REG(BPF_SUB, R1, R5),
1546 BPF_ALU64_REG(BPF_SUB, R1, R6),
1547 BPF_ALU64_REG(BPF_SUB, R1, R7),
1548 BPF_ALU64_REG(BPF_SUB, R1, R8),
1549 BPF_ALU64_REG(BPF_SUB, R1, R9),
1550 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1551 BPF_ALU64_REG(BPF_SUB, R2, R0),
1552 BPF_ALU64_REG(BPF_SUB, R2, R1),
1553 BPF_ALU64_REG(BPF_SUB, R2, R3),
1554 BPF_ALU64_REG(BPF_SUB, R2, R4),
1555 BPF_ALU64_REG(BPF_SUB, R2, R5),
1556 BPF_ALU64_REG(BPF_SUB, R2, R6),
1557 BPF_ALU64_REG(BPF_SUB, R2, R7),
1558 BPF_ALU64_REG(BPF_SUB, R2, R8),
1559 BPF_ALU64_REG(BPF_SUB, R2, R9),
1560 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1561 BPF_ALU64_REG(BPF_SUB, R3, R0),
1562 BPF_ALU64_REG(BPF_SUB, R3, R1),
1563 BPF_ALU64_REG(BPF_SUB, R3, R2),
1564 BPF_ALU64_REG(BPF_SUB, R3, R4),
1565 BPF_ALU64_REG(BPF_SUB, R3, R5),
1566 BPF_ALU64_REG(BPF_SUB, R3, R6),
1567 BPF_ALU64_REG(BPF_SUB, R3, R7),
1568 BPF_ALU64_REG(BPF_SUB, R3, R8),
1569 BPF_ALU64_REG(BPF_SUB, R3, R9),
1570 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1571 BPF_ALU64_REG(BPF_SUB, R4, R0),
1572 BPF_ALU64_REG(BPF_SUB, R4, R1),
1573 BPF_ALU64_REG(BPF_SUB, R4, R2),
1574 BPF_ALU64_REG(BPF_SUB, R4, R3),
1575 BPF_ALU64_REG(BPF_SUB, R4, R5),
1576 BPF_ALU64_REG(BPF_SUB, R4, R6),
1577 BPF_ALU64_REG(BPF_SUB, R4, R7),
1578 BPF_ALU64_REG(BPF_SUB, R4, R8),
1579 BPF_ALU64_REG(BPF_SUB, R4, R9),
1580 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1581 BPF_ALU64_REG(BPF_SUB, R5, R0),
1582 BPF_ALU64_REG(BPF_SUB, R5, R1),
1583 BPF_ALU64_REG(BPF_SUB, R5, R2),
1584 BPF_ALU64_REG(BPF_SUB, R5, R3),
1585 BPF_ALU64_REG(BPF_SUB, R5, R4),
1586 BPF_ALU64_REG(BPF_SUB, R5, R6),
1587 BPF_ALU64_REG(BPF_SUB, R5, R7),
1588 BPF_ALU64_REG(BPF_SUB, R5, R8),
1589 BPF_ALU64_REG(BPF_SUB, R5, R9),
1590 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1591 BPF_ALU64_REG(BPF_SUB, R6, R0),
1592 BPF_ALU64_REG(BPF_SUB, R6, R1),
1593 BPF_ALU64_REG(BPF_SUB, R6, R2),
1594 BPF_ALU64_REG(BPF_SUB, R6, R3),
1595 BPF_ALU64_REG(BPF_SUB, R6, R4),
1596 BPF_ALU64_REG(BPF_SUB, R6, R5),
1597 BPF_ALU64_REG(BPF_SUB, R6, R7),
1598 BPF_ALU64_REG(BPF_SUB, R6, R8),
1599 BPF_ALU64_REG(BPF_SUB, R6, R9),
1600 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1601 BPF_ALU64_REG(BPF_SUB, R7, R0),
1602 BPF_ALU64_REG(BPF_SUB, R7, R1),
1603 BPF_ALU64_REG(BPF_SUB, R7, R2),
1604 BPF_ALU64_REG(BPF_SUB, R7, R3),
1605 BPF_ALU64_REG(BPF_SUB, R7, R4),
1606 BPF_ALU64_REG(BPF_SUB, R7, R5),
1607 BPF_ALU64_REG(BPF_SUB, R7, R6),
1608 BPF_ALU64_REG(BPF_SUB, R7, R8),
1609 BPF_ALU64_REG(BPF_SUB, R7, R9),
1610 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1611 BPF_ALU64_REG(BPF_SUB, R8, R0),
1612 BPF_ALU64_REG(BPF_SUB, R8, R1),
1613 BPF_ALU64_REG(BPF_SUB, R8, R2),
1614 BPF_ALU64_REG(BPF_SUB, R8, R3),
1615 BPF_ALU64_REG(BPF_SUB, R8, R4),
1616 BPF_ALU64_REG(BPF_SUB, R8, R5),
1617 BPF_ALU64_REG(BPF_SUB, R8, R6),
1618 BPF_ALU64_REG(BPF_SUB, R8, R7),
1619 BPF_ALU64_REG(BPF_SUB, R8, R9),
1620 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1621 BPF_ALU64_REG(BPF_SUB, R9, R0),
1622 BPF_ALU64_REG(BPF_SUB, R9, R1),
1623 BPF_ALU64_REG(BPF_SUB, R9, R2),
1624 BPF_ALU64_REG(BPF_SUB, R9, R3),
1625 BPF_ALU64_REG(BPF_SUB, R9, R4),
1626 BPF_ALU64_REG(BPF_SUB, R9, R5),
1627 BPF_ALU64_REG(BPF_SUB, R9, R6),
1628 BPF_ALU64_REG(BPF_SUB, R9, R7),
1629 BPF_ALU64_REG(BPF_SUB, R9, R8),
1630 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1631 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1632 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1633 BPF_ALU64_REG(BPF_SUB, R0, R1),
1634 BPF_ALU64_REG(BPF_SUB, R0, R2),
1635 BPF_ALU64_REG(BPF_SUB, R0, R3),
1636 BPF_ALU64_REG(BPF_SUB, R0, R4),
1637 BPF_ALU64_REG(BPF_SUB, R0, R5),
1638 BPF_ALU64_REG(BPF_SUB, R0, R6),
1639 BPF_ALU64_REG(BPF_SUB, R0, R7),
1640 BPF_ALU64_REG(BPF_SUB, R0, R8),
1641 BPF_ALU64_REG(BPF_SUB, R0, R9),
1642 BPF_EXIT_INSN(),
1643 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001644 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001645 { },
1646 { { 0, 11 } }
1647 },
1648 { /* Mainly checking JIT here. */
1649 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001650 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001651 BPF_ALU64_REG(BPF_SUB, R0, R0),
1652 BPF_ALU64_REG(BPF_XOR, R1, R1),
1653 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1654 BPF_EXIT_INSN(),
1655 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1656 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1657 BPF_ALU64_REG(BPF_SUB, R1, R1),
1658 BPF_ALU64_REG(BPF_XOR, R2, R2),
1659 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1660 BPF_EXIT_INSN(),
1661 BPF_ALU64_REG(BPF_SUB, R2, R2),
1662 BPF_ALU64_REG(BPF_XOR, R3, R3),
1663 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1664 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1665 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_REG(BPF_SUB, R3, R3),
1668 BPF_ALU64_REG(BPF_XOR, R4, R4),
1669 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1670 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1671 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1672 BPF_EXIT_INSN(),
1673 BPF_ALU64_REG(BPF_SUB, R4, R4),
1674 BPF_ALU64_REG(BPF_XOR, R5, R5),
1675 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1676 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1677 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1678 BPF_EXIT_INSN(),
1679 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1680 BPF_ALU64_REG(BPF_SUB, R5, R5),
1681 BPF_ALU64_REG(BPF_XOR, R6, R6),
1682 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1683 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1684 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1685 BPF_EXIT_INSN(),
1686 BPF_ALU64_REG(BPF_SUB, R6, R6),
1687 BPF_ALU64_REG(BPF_XOR, R7, R7),
1688 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1689 BPF_EXIT_INSN(),
1690 BPF_ALU64_REG(BPF_SUB, R7, R7),
1691 BPF_ALU64_REG(BPF_XOR, R8, R8),
1692 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1693 BPF_EXIT_INSN(),
1694 BPF_ALU64_REG(BPF_SUB, R8, R8),
1695 BPF_ALU64_REG(BPF_XOR, R9, R9),
1696 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1697 BPF_EXIT_INSN(),
1698 BPF_ALU64_REG(BPF_SUB, R9, R9),
1699 BPF_ALU64_REG(BPF_XOR, R0, R0),
1700 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1701 BPF_EXIT_INSN(),
1702 BPF_ALU64_REG(BPF_SUB, R1, R1),
1703 BPF_ALU64_REG(BPF_XOR, R0, R0),
1704 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1705 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1706 BPF_EXIT_INSN(),
1707 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1708 BPF_EXIT_INSN(),
1709 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001710 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001711 { },
1712 { { 0, 1 } }
1713 },
1714 { /* Mainly checking JIT here. */
1715 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001716 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001717 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1718 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1719 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1720 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1721 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1722 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1723 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1724 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1725 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1726 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1727 BPF_ALU64_REG(BPF_MUL, R0, R0),
1728 BPF_ALU64_REG(BPF_MUL, R0, R1),
1729 BPF_ALU64_REG(BPF_MUL, R0, R2),
1730 BPF_ALU64_REG(BPF_MUL, R0, R3),
1731 BPF_ALU64_REG(BPF_MUL, R0, R4),
1732 BPF_ALU64_REG(BPF_MUL, R0, R5),
1733 BPF_ALU64_REG(BPF_MUL, R0, R6),
1734 BPF_ALU64_REG(BPF_MUL, R0, R7),
1735 BPF_ALU64_REG(BPF_MUL, R0, R8),
1736 BPF_ALU64_REG(BPF_MUL, R0, R9),
1737 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1738 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1739 BPF_EXIT_INSN(),
1740 BPF_ALU64_REG(BPF_MUL, R1, R0),
1741 BPF_ALU64_REG(BPF_MUL, R1, R2),
1742 BPF_ALU64_REG(BPF_MUL, R1, R3),
1743 BPF_ALU64_REG(BPF_MUL, R1, R4),
1744 BPF_ALU64_REG(BPF_MUL, R1, R5),
1745 BPF_ALU64_REG(BPF_MUL, R1, R6),
1746 BPF_ALU64_REG(BPF_MUL, R1, R7),
1747 BPF_ALU64_REG(BPF_MUL, R1, R8),
1748 BPF_ALU64_REG(BPF_MUL, R1, R9),
1749 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1750 BPF_ALU64_REG(BPF_MOV, R2, R1),
1751 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1752 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1753 BPF_EXIT_INSN(),
1754 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1755 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1756 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1757 BPF_EXIT_INSN(),
1758 BPF_ALU64_REG(BPF_MUL, R2, R0),
1759 BPF_ALU64_REG(BPF_MUL, R2, R1),
1760 BPF_ALU64_REG(BPF_MUL, R2, R3),
1761 BPF_ALU64_REG(BPF_MUL, R2, R4),
1762 BPF_ALU64_REG(BPF_MUL, R2, R5),
1763 BPF_ALU64_REG(BPF_MUL, R2, R6),
1764 BPF_ALU64_REG(BPF_MUL, R2, R7),
1765 BPF_ALU64_REG(BPF_MUL, R2, R8),
1766 BPF_ALU64_REG(BPF_MUL, R2, R9),
1767 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1768 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1769 BPF_ALU64_REG(BPF_MOV, R0, R2),
1770 BPF_EXIT_INSN(),
1771 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001772 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001773 { },
1774 { { 0, 0x35d97ef2 } }
1775 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001776 { /* Mainly checking JIT here. */
1777 "MOV REG64",
1778 .u.insns_int = {
1779 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1780 BPF_MOV64_REG(R1, R0),
1781 BPF_MOV64_REG(R2, R1),
1782 BPF_MOV64_REG(R3, R2),
1783 BPF_MOV64_REG(R4, R3),
1784 BPF_MOV64_REG(R5, R4),
1785 BPF_MOV64_REG(R6, R5),
1786 BPF_MOV64_REG(R7, R6),
1787 BPF_MOV64_REG(R8, R7),
1788 BPF_MOV64_REG(R9, R8),
1789 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1790 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1791 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1792 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1793 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1794 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1795 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1796 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1797 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1798 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1799 BPF_ALU64_REG(BPF_ADD, R0, R0),
1800 BPF_ALU64_REG(BPF_ADD, R0, R1),
1801 BPF_ALU64_REG(BPF_ADD, R0, R2),
1802 BPF_ALU64_REG(BPF_ADD, R0, R3),
1803 BPF_ALU64_REG(BPF_ADD, R0, R4),
1804 BPF_ALU64_REG(BPF_ADD, R0, R5),
1805 BPF_ALU64_REG(BPF_ADD, R0, R6),
1806 BPF_ALU64_REG(BPF_ADD, R0, R7),
1807 BPF_ALU64_REG(BPF_ADD, R0, R8),
1808 BPF_ALU64_REG(BPF_ADD, R0, R9),
1809 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1810 BPF_EXIT_INSN(),
1811 },
1812 INTERNAL,
1813 { },
1814 { { 0, 0xfefe } }
1815 },
1816 { /* Mainly checking JIT here. */
1817 "MOV REG32",
1818 .u.insns_int = {
1819 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1820 BPF_MOV64_REG(R1, R0),
1821 BPF_MOV64_REG(R2, R1),
1822 BPF_MOV64_REG(R3, R2),
1823 BPF_MOV64_REG(R4, R3),
1824 BPF_MOV64_REG(R5, R4),
1825 BPF_MOV64_REG(R6, R5),
1826 BPF_MOV64_REG(R7, R6),
1827 BPF_MOV64_REG(R8, R7),
1828 BPF_MOV64_REG(R9, R8),
1829 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1830 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1831 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1832 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1833 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1834 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1835 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1836 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1837 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1838 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1839 BPF_ALU64_REG(BPF_ADD, R0, R0),
1840 BPF_ALU64_REG(BPF_ADD, R0, R1),
1841 BPF_ALU64_REG(BPF_ADD, R0, R2),
1842 BPF_ALU64_REG(BPF_ADD, R0, R3),
1843 BPF_ALU64_REG(BPF_ADD, R0, R4),
1844 BPF_ALU64_REG(BPF_ADD, R0, R5),
1845 BPF_ALU64_REG(BPF_ADD, R0, R6),
1846 BPF_ALU64_REG(BPF_ADD, R0, R7),
1847 BPF_ALU64_REG(BPF_ADD, R0, R8),
1848 BPF_ALU64_REG(BPF_ADD, R0, R9),
1849 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1850 BPF_EXIT_INSN(),
1851 },
1852 INTERNAL,
1853 { },
1854 { { 0, 0xfefe } }
1855 },
1856 { /* Mainly checking JIT here. */
1857 "LD IMM64",
1858 .u.insns_int = {
1859 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1860 BPF_MOV64_REG(R1, R0),
1861 BPF_MOV64_REG(R2, R1),
1862 BPF_MOV64_REG(R3, R2),
1863 BPF_MOV64_REG(R4, R3),
1864 BPF_MOV64_REG(R5, R4),
1865 BPF_MOV64_REG(R6, R5),
1866 BPF_MOV64_REG(R7, R6),
1867 BPF_MOV64_REG(R8, R7),
1868 BPF_MOV64_REG(R9, R8),
1869 BPF_LD_IMM64(R0, 0x0LL),
1870 BPF_LD_IMM64(R1, 0x0LL),
1871 BPF_LD_IMM64(R2, 0x0LL),
1872 BPF_LD_IMM64(R3, 0x0LL),
1873 BPF_LD_IMM64(R4, 0x0LL),
1874 BPF_LD_IMM64(R5, 0x0LL),
1875 BPF_LD_IMM64(R6, 0x0LL),
1876 BPF_LD_IMM64(R7, 0x0LL),
1877 BPF_LD_IMM64(R8, 0x0LL),
1878 BPF_LD_IMM64(R9, 0x0LL),
1879 BPF_ALU64_REG(BPF_ADD, R0, R0),
1880 BPF_ALU64_REG(BPF_ADD, R0, R1),
1881 BPF_ALU64_REG(BPF_ADD, R0, R2),
1882 BPF_ALU64_REG(BPF_ADD, R0, R3),
1883 BPF_ALU64_REG(BPF_ADD, R0, R4),
1884 BPF_ALU64_REG(BPF_ADD, R0, R5),
1885 BPF_ALU64_REG(BPF_ADD, R0, R6),
1886 BPF_ALU64_REG(BPF_ADD, R0, R7),
1887 BPF_ALU64_REG(BPF_ADD, R0, R8),
1888 BPF_ALU64_REG(BPF_ADD, R0, R9),
1889 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1890 BPF_EXIT_INSN(),
1891 },
1892 INTERNAL,
1893 { },
1894 { { 0, 0xfefe } }
1895 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001896 {
1897 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001898 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001899 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1900 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1901 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1902 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1903 BPF_ALU64_REG(BPF_DIV, R0, R2),
1904 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1905 BPF_EXIT_INSN(),
1906 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1907 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1908 BPF_EXIT_INSN(),
1909 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1910 BPF_EXIT_INSN(),
1911 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001912 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001913 { },
1914 { { 0, -1 } }
1915 },
1916 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001917 "INT: shifts by register",
1918 .u.insns_int = {
1919 BPF_MOV64_IMM(R0, -1234),
1920 BPF_MOV64_IMM(R1, 1),
1921 BPF_ALU32_REG(BPF_RSH, R0, R1),
1922 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1923 BPF_EXIT_INSN(),
1924 BPF_MOV64_IMM(R2, 1),
1925 BPF_ALU64_REG(BPF_LSH, R0, R2),
1926 BPF_MOV32_IMM(R4, -1234),
1927 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1928 BPF_EXIT_INSN(),
1929 BPF_ALU64_IMM(BPF_AND, R4, 63),
1930 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1931 BPF_MOV64_IMM(R3, 47),
1932 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1933 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1934 BPF_EXIT_INSN(),
1935 BPF_MOV64_IMM(R2, 1),
1936 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1937 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1938 BPF_EXIT_INSN(),
1939 BPF_MOV64_IMM(R4, 4),
1940 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1941 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1942 BPF_EXIT_INSN(),
1943 BPF_MOV64_IMM(R4, 5),
1944 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1945 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1946 BPF_EXIT_INSN(),
1947 BPF_MOV64_IMM(R0, -1),
1948 BPF_EXIT_INSN(),
1949 },
1950 INTERNAL,
1951 { },
1952 { { 0, -1 } }
1953 },
1954 {
Johan Almbladh84024a42021-08-09 11:18:23 +02001955 /*
1956 * Register (non-)clobbering test, in the case where a 32-bit
1957 * JIT implements complex ALU64 operations via function calls.
1958 * If so, the function call must be invisible in the eBPF
1959 * registers. The JIT must then save and restore relevant
1960 * registers during the call. The following tests check that
1961 * the eBPF registers retain their values after such a call.
1962 */
1963 "INT: Register clobbering, R1 updated",
1964 .u.insns_int = {
1965 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1966 BPF_ALU32_IMM(BPF_MOV, R1, 123456789),
1967 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1968 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1969 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1970 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1971 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1972 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1973 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1974 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1975 BPF_ALU64_IMM(BPF_DIV, R1, 123456789),
1976 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
1977 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
1978 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
1979 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
1980 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
1981 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
1982 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
1983 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
1984 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
1985 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
1986 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1987 BPF_EXIT_INSN(),
1988 },
1989 INTERNAL,
1990 { },
1991 { { 0, 1 } }
1992 },
1993 {
1994 "INT: Register clobbering, R2 updated",
1995 .u.insns_int = {
1996 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1997 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1998 BPF_ALU32_IMM(BPF_MOV, R2, 2 * 123456789),
1999 BPF_ALU32_IMM(BPF_MOV, R3, 3),
2000 BPF_ALU32_IMM(BPF_MOV, R4, 4),
2001 BPF_ALU32_IMM(BPF_MOV, R5, 5),
2002 BPF_ALU32_IMM(BPF_MOV, R6, 6),
2003 BPF_ALU32_IMM(BPF_MOV, R7, 7),
2004 BPF_ALU32_IMM(BPF_MOV, R8, 8),
2005 BPF_ALU32_IMM(BPF_MOV, R9, 9),
2006 BPF_ALU64_IMM(BPF_DIV, R2, 123456789),
2007 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
2008 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
2009 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
2010 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
2011 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
2012 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
2013 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
2014 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
2015 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
2016 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
2017 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2018 BPF_EXIT_INSN(),
2019 },
2020 INTERNAL,
2021 { },
2022 { { 0, 1 } }
2023 },
2024 {
2025 /*
2026 * Test 32-bit JITs that implement complex ALU64 operations as
2027 * function calls R0 = f(R1, R2), and must re-arrange operands.
2028 */
2029#define NUMER 0xfedcba9876543210ULL
2030#define DENOM 0x0123456789abcdefULL
2031 "ALU64_DIV X: Operand register permutations",
2032 .u.insns_int = {
2033 /* R0 / R2 */
2034 BPF_LD_IMM64(R0, NUMER),
2035 BPF_LD_IMM64(R2, DENOM),
2036 BPF_ALU64_REG(BPF_DIV, R0, R2),
2037 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2038 BPF_EXIT_INSN(),
2039 /* R1 / R0 */
2040 BPF_LD_IMM64(R1, NUMER),
2041 BPF_LD_IMM64(R0, DENOM),
2042 BPF_ALU64_REG(BPF_DIV, R1, R0),
2043 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2044 BPF_EXIT_INSN(),
2045 /* R0 / R1 */
2046 BPF_LD_IMM64(R0, NUMER),
2047 BPF_LD_IMM64(R1, DENOM),
2048 BPF_ALU64_REG(BPF_DIV, R0, R1),
2049 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2050 BPF_EXIT_INSN(),
2051 /* R2 / R0 */
2052 BPF_LD_IMM64(R2, NUMER),
2053 BPF_LD_IMM64(R0, DENOM),
2054 BPF_ALU64_REG(BPF_DIV, R2, R0),
2055 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2056 BPF_EXIT_INSN(),
2057 /* R2 / R1 */
2058 BPF_LD_IMM64(R2, NUMER),
2059 BPF_LD_IMM64(R1, DENOM),
2060 BPF_ALU64_REG(BPF_DIV, R2, R1),
2061 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2062 BPF_EXIT_INSN(),
2063 /* R1 / R2 */
2064 BPF_LD_IMM64(R1, NUMER),
2065 BPF_LD_IMM64(R2, DENOM),
2066 BPF_ALU64_REG(BPF_DIV, R1, R2),
2067 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2068 BPF_EXIT_INSN(),
2069 /* R1 / R1 */
2070 BPF_LD_IMM64(R1, NUMER),
2071 BPF_ALU64_REG(BPF_DIV, R1, R1),
2072 BPF_JMP_IMM(BPF_JEQ, R1, 1, 1),
2073 BPF_EXIT_INSN(),
2074 /* R2 / R2 */
2075 BPF_LD_IMM64(R2, DENOM),
2076 BPF_ALU64_REG(BPF_DIV, R2, R2),
2077 BPF_JMP_IMM(BPF_JEQ, R2, 1, 1),
2078 BPF_EXIT_INSN(),
2079 /* R3 / R4 */
2080 BPF_LD_IMM64(R3, NUMER),
2081 BPF_LD_IMM64(R4, DENOM),
2082 BPF_ALU64_REG(BPF_DIV, R3, R4),
2083 BPF_JMP_IMM(BPF_JEQ, R3, NUMER / DENOM, 1),
2084 BPF_EXIT_INSN(),
2085 /* Successful return */
2086 BPF_LD_IMM64(R0, 1),
2087 BPF_EXIT_INSN(),
2088 },
2089 INTERNAL,
2090 { },
2091 { { 0, 1 } },
2092#undef NUMER
2093#undef DENOM
2094 },
Johan Almbladh53e33f92021-08-09 11:18:26 +02002095#ifdef CONFIG_32BIT
2096 {
2097 "INT: 32-bit context pointer word order and zero-extension",
2098 .u.insns_int = {
2099 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2100 BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3),
2101 BPF_ALU64_IMM(BPF_RSH, R1, 32),
2102 BPF_JMP32_IMM(BPF_JNE, R1, 0, 1),
2103 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2104 BPF_EXIT_INSN(),
2105 },
2106 INTERNAL,
2107 { },
2108 { { 0, 1 } }
2109 },
2110#endif
Johan Almbladh84024a42021-08-09 11:18:23 +02002111 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002112 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07002113 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002114 BPF_STMT(BPF_LD | BPF_IMM, 1),
2115 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002116 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002117 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002118 { },
2119 .fill_helper = NULL,
2120 .expected_errcode = -EINVAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002121 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002122 {
2123 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07002124 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002125 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
2126 BPF_STMT(BPF_RET | BPF_K, 0)
2127 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002128 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002129 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002130 { },
2131 .fill_helper = NULL,
2132 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002133 },
2134 {
2135 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07002136 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002137 /* seccomp insn, rejected in socket filter */
2138 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
2139 BPF_STMT(BPF_RET | BPF_K, 0)
2140 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002141 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002142 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002143 { },
2144 .fill_helper = NULL,
2145 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002146 },
2147 {
2148 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07002149 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002150 BPF_STMT(BPF_STX, 16),
2151 BPF_STMT(BPF_RET | BPF_K, 0)
2152 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002153 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002154 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002155 { },
2156 .fill_helper = NULL,
2157 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002158 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002159 {
2160 "JUMPS + HOLES",
2161 .u.insns = {
2162 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2163 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
2164 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2165 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2166 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2167 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2168 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2169 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2170 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2171 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2172 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2173 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2174 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2175 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2176 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2177 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
2178 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2179 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
2180 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2181 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2182 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2183 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2184 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2185 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2186 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2187 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2188 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2189 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2190 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2191 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2192 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2193 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2194 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2195 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2196 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2197 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2198 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2199 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2200 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2201 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2202 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2203 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2204 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2205 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2206 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2207 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2208 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2209 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2210 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2211 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2212 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2213 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2214 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2215 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2216 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2217 BPF_STMT(BPF_RET | BPF_A, 0),
2218 BPF_STMT(BPF_RET | BPF_A, 0),
2219 },
2220 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002221 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2222 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2223 0x08, 0x00,
2224 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2225 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2226 0xc0, 0xa8, 0x33, 0x01,
2227 0xc0, 0xa8, 0x33, 0x02,
2228 0xbb, 0xb6,
2229 0xa9, 0xfa,
2230 0x00, 0x14, 0x00, 0x00,
2231 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2232 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2233 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2234 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2235 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2236 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2237 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2238 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002239 { { 88, 0x001b } }
2240 },
2241 {
2242 "check: RET X",
2243 .u.insns = {
2244 BPF_STMT(BPF_RET | BPF_X, 0),
2245 },
2246 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2247 { },
2248 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002249 .fill_helper = NULL,
2250 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002251 },
2252 {
2253 "check: LDX + RET X",
2254 .u.insns = {
2255 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2256 BPF_STMT(BPF_RET | BPF_X, 0),
2257 },
2258 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2259 { },
2260 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002261 .fill_helper = NULL,
2262 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002263 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002264 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002265 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002266 .u.insns = {
2267 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2268 BPF_STMT(BPF_STX, 0),
2269 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2270 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2271 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2272 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2273 BPF_STMT(BPF_STX, 1),
2274 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2275 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2276 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2277 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2278 BPF_STMT(BPF_STX, 2),
2279 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2280 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2281 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2282 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2283 BPF_STMT(BPF_STX, 3),
2284 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2285 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2286 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2287 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2288 BPF_STMT(BPF_STX, 4),
2289 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2290 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2291 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2292 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2293 BPF_STMT(BPF_STX, 5),
2294 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2295 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2296 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2297 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2298 BPF_STMT(BPF_STX, 6),
2299 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2300 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2301 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2302 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2303 BPF_STMT(BPF_STX, 7),
2304 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2305 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2306 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2307 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2308 BPF_STMT(BPF_STX, 8),
2309 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2310 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2311 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2312 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2313 BPF_STMT(BPF_STX, 9),
2314 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2315 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2316 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2317 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2318 BPF_STMT(BPF_STX, 10),
2319 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2320 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2321 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2322 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2323 BPF_STMT(BPF_STX, 11),
2324 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2325 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2326 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2327 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2328 BPF_STMT(BPF_STX, 12),
2329 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2330 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2331 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2332 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2333 BPF_STMT(BPF_STX, 13),
2334 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2335 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2336 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2337 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2338 BPF_STMT(BPF_STX, 14),
2339 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2340 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2341 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2342 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2343 BPF_STMT(BPF_STX, 15),
2344 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2345 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2346 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2347 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2348 BPF_STMT(BPF_RET | BPF_A, 0),
2349 },
2350 CLASSIC | FLAG_NO_DATA,
2351 { },
2352 { { 0, 116 } },
2353 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002354 { /* Mainly checking JIT here. */
2355 "M[]: full STX + full LDX",
2356 .u.insns = {
2357 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2358 BPF_STMT(BPF_STX, 0),
2359 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2360 BPF_STMT(BPF_STX, 1),
2361 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2362 BPF_STMT(BPF_STX, 2),
2363 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2364 BPF_STMT(BPF_STX, 3),
2365 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2366 BPF_STMT(BPF_STX, 4),
2367 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2368 BPF_STMT(BPF_STX, 5),
2369 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2370 BPF_STMT(BPF_STX, 6),
2371 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2372 BPF_STMT(BPF_STX, 7),
2373 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2374 BPF_STMT(BPF_STX, 8),
2375 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2376 BPF_STMT(BPF_STX, 9),
2377 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2378 BPF_STMT(BPF_STX, 10),
2379 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2380 BPF_STMT(BPF_STX, 11),
2381 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2382 BPF_STMT(BPF_STX, 12),
2383 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2384 BPF_STMT(BPF_STX, 13),
2385 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2386 BPF_STMT(BPF_STX, 14),
2387 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2388 BPF_STMT(BPF_STX, 15),
2389 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2390 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2391 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2392 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2393 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2394 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2395 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2396 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2397 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2398 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2399 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2400 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2401 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2402 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2403 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2404 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2405 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2406 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2407 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2408 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2409 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2410 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2411 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2412 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2413 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2414 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2415 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2416 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2417 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2418 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2419 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2420 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2421 BPF_STMT(BPF_RET | BPF_A, 0),
2422 },
2423 CLASSIC | FLAG_NO_DATA,
2424 { },
2425 { { 0, 0x2a5a5e5 } },
2426 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002427 {
2428 "check: SKF_AD_MAX",
2429 .u.insns = {
2430 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2431 SKF_AD_OFF + SKF_AD_MAX),
2432 BPF_STMT(BPF_RET | BPF_A, 0),
2433 },
2434 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2435 { },
2436 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002437 .fill_helper = NULL,
2438 .expected_errcode = -EINVAL,
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002439 },
2440 { /* Passes checker but fails during runtime. */
2441 "LD [SKF_AD_OFF-1]",
2442 .u.insns = {
2443 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2444 SKF_AD_OFF - 1),
2445 BPF_STMT(BPF_RET | BPF_K, 1),
2446 },
2447 CLASSIC,
2448 { },
2449 { { 1, 0 } },
2450 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002451 {
2452 "load 64-bit immediate",
2453 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002454 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002455 BPF_MOV64_REG(R2, R1),
2456 BPF_MOV64_REG(R3, R2),
2457 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2458 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2459 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2460 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2461 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2462 BPF_EXIT_INSN(),
2463 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2464 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002465 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2466 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002467 BPF_EXIT_INSN(),
2468 },
2469 INTERNAL,
2470 { },
2471 { { 0, 1 } }
2472 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002473 /* BPF_ALU | BPF_MOV | BPF_X */
2474 {
2475 "ALU_MOV_X: dst = 2",
2476 .u.insns_int = {
2477 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2478 BPF_ALU32_REG(BPF_MOV, R0, R1),
2479 BPF_EXIT_INSN(),
2480 },
2481 INTERNAL,
2482 { },
2483 { { 0, 2 } },
2484 },
2485 {
2486 "ALU_MOV_X: dst = 4294967295",
2487 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002488 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002489 BPF_ALU32_REG(BPF_MOV, R0, R1),
2490 BPF_EXIT_INSN(),
2491 },
2492 INTERNAL,
2493 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002494 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002495 },
2496 {
2497 "ALU64_MOV_X: dst = 2",
2498 .u.insns_int = {
2499 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2500 BPF_ALU64_REG(BPF_MOV, R0, R1),
2501 BPF_EXIT_INSN(),
2502 },
2503 INTERNAL,
2504 { },
2505 { { 0, 2 } },
2506 },
2507 {
2508 "ALU64_MOV_X: dst = 4294967295",
2509 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002510 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002511 BPF_ALU64_REG(BPF_MOV, R0, R1),
2512 BPF_EXIT_INSN(),
2513 },
2514 INTERNAL,
2515 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002516 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002517 },
2518 /* BPF_ALU | BPF_MOV | BPF_K */
2519 {
2520 "ALU_MOV_K: dst = 2",
2521 .u.insns_int = {
2522 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2523 BPF_EXIT_INSN(),
2524 },
2525 INTERNAL,
2526 { },
2527 { { 0, 2 } },
2528 },
2529 {
2530 "ALU_MOV_K: dst = 4294967295",
2531 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002532 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002533 BPF_EXIT_INSN(),
2534 },
2535 INTERNAL,
2536 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002537 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002538 },
2539 {
2540 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2541 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002542 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2543 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002544 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2545 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2546 BPF_MOV32_IMM(R0, 2),
2547 BPF_EXIT_INSN(),
2548 BPF_MOV32_IMM(R0, 1),
2549 BPF_EXIT_INSN(),
2550 },
2551 INTERNAL,
2552 { },
2553 { { 0, 0x1 } },
2554 },
2555 {
Johan Almbladh565731a2021-08-09 11:18:17 +02002556 "ALU_MOV_K: small negative",
2557 .u.insns_int = {
2558 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2559 BPF_EXIT_INSN(),
2560 },
2561 INTERNAL,
2562 { },
2563 { { 0, -123 } }
2564 },
2565 {
2566 "ALU_MOV_K: small negative zero extension",
2567 .u.insns_int = {
2568 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2569 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2570 BPF_EXIT_INSN(),
2571 },
2572 INTERNAL,
2573 { },
2574 { { 0, 0 } }
2575 },
2576 {
2577 "ALU_MOV_K: large negative",
2578 .u.insns_int = {
2579 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2580 BPF_EXIT_INSN(),
2581 },
2582 INTERNAL,
2583 { },
2584 { { 0, -123456789 } }
2585 },
2586 {
2587 "ALU_MOV_K: large negative zero extension",
2588 .u.insns_int = {
2589 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2590 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2591 BPF_EXIT_INSN(),
2592 },
2593 INTERNAL,
2594 { },
2595 { { 0, 0 } }
2596 },
2597 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002598 "ALU64_MOV_K: dst = 2",
2599 .u.insns_int = {
2600 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2601 BPF_EXIT_INSN(),
2602 },
2603 INTERNAL,
2604 { },
2605 { { 0, 2 } },
2606 },
2607 {
2608 "ALU64_MOV_K: dst = 2147483647",
2609 .u.insns_int = {
2610 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2611 BPF_EXIT_INSN(),
2612 },
2613 INTERNAL,
2614 { },
2615 { { 0, 2147483647 } },
2616 },
2617 {
2618 "ALU64_OR_K: dst = 0x0",
2619 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002620 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002621 BPF_LD_IMM64(R3, 0x0),
2622 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2623 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2624 BPF_MOV32_IMM(R0, 2),
2625 BPF_EXIT_INSN(),
2626 BPF_MOV32_IMM(R0, 1),
2627 BPF_EXIT_INSN(),
2628 },
2629 INTERNAL,
2630 { },
2631 { { 0, 0x1 } },
2632 },
2633 {
2634 "ALU64_MOV_K: dst = -1",
2635 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002636 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2637 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002638 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2639 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2640 BPF_MOV32_IMM(R0, 2),
2641 BPF_EXIT_INSN(),
2642 BPF_MOV32_IMM(R0, 1),
2643 BPF_EXIT_INSN(),
2644 },
2645 INTERNAL,
2646 { },
2647 { { 0, 0x1 } },
2648 },
Johan Almbladh565731a2021-08-09 11:18:17 +02002649 {
2650 "ALU64_MOV_K: small negative",
2651 .u.insns_int = {
2652 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2653 BPF_EXIT_INSN(),
2654 },
2655 INTERNAL,
2656 { },
2657 { { 0, -123 } }
2658 },
2659 {
2660 "ALU64_MOV_K: small negative sign extension",
2661 .u.insns_int = {
2662 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2663 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2664 BPF_EXIT_INSN(),
2665 },
2666 INTERNAL,
2667 { },
2668 { { 0, 0xffffffff } }
2669 },
2670 {
2671 "ALU64_MOV_K: large negative",
2672 .u.insns_int = {
2673 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2674 BPF_EXIT_INSN(),
2675 },
2676 INTERNAL,
2677 { },
2678 { { 0, -123456789 } }
2679 },
2680 {
2681 "ALU64_MOV_K: large negative sign extension",
2682 .u.insns_int = {
2683 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2684 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2685 BPF_EXIT_INSN(),
2686 },
2687 INTERNAL,
2688 { },
2689 { { 0, 0xffffffff } }
2690 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002691 /* BPF_ALU | BPF_ADD | BPF_X */
2692 {
2693 "ALU_ADD_X: 1 + 2 = 3",
2694 .u.insns_int = {
2695 BPF_LD_IMM64(R0, 1),
2696 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2697 BPF_ALU32_REG(BPF_ADD, R0, R1),
2698 BPF_EXIT_INSN(),
2699 },
2700 INTERNAL,
2701 { },
2702 { { 0, 3 } },
2703 },
2704 {
2705 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2706 .u.insns_int = {
2707 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002708 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002709 BPF_ALU32_REG(BPF_ADD, R0, R1),
2710 BPF_EXIT_INSN(),
2711 },
2712 INTERNAL,
2713 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002714 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002715 },
2716 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302717 "ALU_ADD_X: 2 + 4294967294 = 0",
2718 .u.insns_int = {
2719 BPF_LD_IMM64(R0, 2),
2720 BPF_LD_IMM64(R1, 4294967294U),
2721 BPF_ALU32_REG(BPF_ADD, R0, R1),
2722 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2723 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2724 BPF_EXIT_INSN(),
2725 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2726 BPF_EXIT_INSN(),
2727 },
2728 INTERNAL,
2729 { },
2730 { { 0, 1 } },
2731 },
2732 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002733 "ALU64_ADD_X: 1 + 2 = 3",
2734 .u.insns_int = {
2735 BPF_LD_IMM64(R0, 1),
2736 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2737 BPF_ALU64_REG(BPF_ADD, R0, R1),
2738 BPF_EXIT_INSN(),
2739 },
2740 INTERNAL,
2741 { },
2742 { { 0, 3 } },
2743 },
2744 {
2745 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2746 .u.insns_int = {
2747 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002748 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002749 BPF_ALU64_REG(BPF_ADD, R0, R1),
2750 BPF_EXIT_INSN(),
2751 },
2752 INTERNAL,
2753 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002754 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002755 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302756 {
2757 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2758 .u.insns_int = {
2759 BPF_LD_IMM64(R0, 2),
2760 BPF_LD_IMM64(R1, 4294967294U),
2761 BPF_LD_IMM64(R2, 4294967296ULL),
2762 BPF_ALU64_REG(BPF_ADD, R0, R1),
2763 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2764 BPF_MOV32_IMM(R0, 0),
2765 BPF_EXIT_INSN(),
2766 BPF_MOV32_IMM(R0, 1),
2767 BPF_EXIT_INSN(),
2768 },
2769 INTERNAL,
2770 { },
2771 { { 0, 1 } },
2772 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002773 /* BPF_ALU | BPF_ADD | BPF_K */
2774 {
2775 "ALU_ADD_K: 1 + 2 = 3",
2776 .u.insns_int = {
2777 BPF_LD_IMM64(R0, 1),
2778 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2779 BPF_EXIT_INSN(),
2780 },
2781 INTERNAL,
2782 { },
2783 { { 0, 3 } },
2784 },
2785 {
2786 "ALU_ADD_K: 3 + 0 = 3",
2787 .u.insns_int = {
2788 BPF_LD_IMM64(R0, 3),
2789 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2790 BPF_EXIT_INSN(),
2791 },
2792 INTERNAL,
2793 { },
2794 { { 0, 3 } },
2795 },
2796 {
2797 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2798 .u.insns_int = {
2799 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002800 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002801 BPF_EXIT_INSN(),
2802 },
2803 INTERNAL,
2804 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002805 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002806 },
2807 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302808 "ALU_ADD_K: 4294967294 + 2 = 0",
2809 .u.insns_int = {
2810 BPF_LD_IMM64(R0, 4294967294U),
2811 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2812 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2813 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2814 BPF_EXIT_INSN(),
2815 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2816 BPF_EXIT_INSN(),
2817 },
2818 INTERNAL,
2819 { },
2820 { { 0, 1 } },
2821 },
2822 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002823 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2824 .u.insns_int = {
2825 BPF_LD_IMM64(R2, 0x0),
2826 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2827 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2828 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2829 BPF_MOV32_IMM(R0, 2),
2830 BPF_EXIT_INSN(),
2831 BPF_MOV32_IMM(R0, 1),
2832 BPF_EXIT_INSN(),
2833 },
2834 INTERNAL,
2835 { },
2836 { { 0, 0x1 } },
2837 },
2838 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302839 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2840 .u.insns_int = {
2841 BPF_LD_IMM64(R2, 0x0),
2842 BPF_LD_IMM64(R3, 0xffff),
2843 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2844 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2845 BPF_MOV32_IMM(R0, 2),
2846 BPF_EXIT_INSN(),
2847 BPF_MOV32_IMM(R0, 1),
2848 BPF_EXIT_INSN(),
2849 },
2850 INTERNAL,
2851 { },
2852 { { 0, 0x1 } },
2853 },
2854 {
2855 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2856 .u.insns_int = {
2857 BPF_LD_IMM64(R2, 0x0),
2858 BPF_LD_IMM64(R3, 0x7fffffff),
2859 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2860 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2861 BPF_MOV32_IMM(R0, 2),
2862 BPF_EXIT_INSN(),
2863 BPF_MOV32_IMM(R0, 1),
2864 BPF_EXIT_INSN(),
2865 },
2866 INTERNAL,
2867 { },
2868 { { 0, 0x1 } },
2869 },
2870 {
2871 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2872 .u.insns_int = {
2873 BPF_LD_IMM64(R2, 0x0),
2874 BPF_LD_IMM64(R3, 0x80000000),
2875 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2876 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2877 BPF_MOV32_IMM(R0, 2),
2878 BPF_EXIT_INSN(),
2879 BPF_MOV32_IMM(R0, 1),
2880 BPF_EXIT_INSN(),
2881 },
2882 INTERNAL,
2883 { },
2884 { { 0, 0x1 } },
2885 },
2886 {
2887 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2888 .u.insns_int = {
2889 BPF_LD_IMM64(R2, 0x0),
2890 BPF_LD_IMM64(R3, 0x80008000),
2891 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2892 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2893 BPF_MOV32_IMM(R0, 2),
2894 BPF_EXIT_INSN(),
2895 BPF_MOV32_IMM(R0, 1),
2896 BPF_EXIT_INSN(),
2897 },
2898 INTERNAL,
2899 { },
2900 { { 0, 0x1 } },
2901 },
2902 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002903 "ALU64_ADD_K: 1 + 2 = 3",
2904 .u.insns_int = {
2905 BPF_LD_IMM64(R0, 1),
2906 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2907 BPF_EXIT_INSN(),
2908 },
2909 INTERNAL,
2910 { },
2911 { { 0, 3 } },
2912 },
2913 {
2914 "ALU64_ADD_K: 3 + 0 = 3",
2915 .u.insns_int = {
2916 BPF_LD_IMM64(R0, 3),
2917 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2918 BPF_EXIT_INSN(),
2919 },
2920 INTERNAL,
2921 { },
2922 { { 0, 3 } },
2923 },
2924 {
2925 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2926 .u.insns_int = {
2927 BPF_LD_IMM64(R0, 1),
2928 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2929 BPF_EXIT_INSN(),
2930 },
2931 INTERNAL,
2932 { },
2933 { { 0, 2147483647 } },
2934 },
2935 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302936 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2937 .u.insns_int = {
2938 BPF_LD_IMM64(R0, 4294967294U),
2939 BPF_LD_IMM64(R1, 4294967296ULL),
2940 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2941 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2942 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2943 BPF_EXIT_INSN(),
2944 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2945 BPF_EXIT_INSN(),
2946 },
2947 INTERNAL,
2948 { },
2949 { { 0, 1 } },
2950 },
2951 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002952 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2953 .u.insns_int = {
2954 BPF_LD_IMM64(R0, 2147483646),
2955 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2956 BPF_EXIT_INSN(),
2957 },
2958 INTERNAL,
2959 { },
2960 { { 0, -1 } },
2961 },
2962 {
2963 "ALU64_ADD_K: 1 + 0 = 1",
2964 .u.insns_int = {
2965 BPF_LD_IMM64(R2, 0x1),
2966 BPF_LD_IMM64(R3, 0x1),
2967 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2968 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2969 BPF_MOV32_IMM(R0, 2),
2970 BPF_EXIT_INSN(),
2971 BPF_MOV32_IMM(R0, 1),
2972 BPF_EXIT_INSN(),
2973 },
2974 INTERNAL,
2975 { },
2976 { { 0, 0x1 } },
2977 },
2978 {
2979 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2980 .u.insns_int = {
2981 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002982 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002983 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2984 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2985 BPF_MOV32_IMM(R0, 2),
2986 BPF_EXIT_INSN(),
2987 BPF_MOV32_IMM(R0, 1),
2988 BPF_EXIT_INSN(),
2989 },
2990 INTERNAL,
2991 { },
2992 { { 0, 0x1 } },
2993 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302994 {
2995 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2996 .u.insns_int = {
2997 BPF_LD_IMM64(R2, 0x0),
2998 BPF_LD_IMM64(R3, 0xffff),
2999 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
3000 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3001 BPF_MOV32_IMM(R0, 2),
3002 BPF_EXIT_INSN(),
3003 BPF_MOV32_IMM(R0, 1),
3004 BPF_EXIT_INSN(),
3005 },
3006 INTERNAL,
3007 { },
3008 { { 0, 0x1 } },
3009 },
3010 {
3011 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
3012 .u.insns_int = {
3013 BPF_LD_IMM64(R2, 0x0),
3014 BPF_LD_IMM64(R3, 0x7fffffff),
3015 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
3016 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3017 BPF_MOV32_IMM(R0, 2),
3018 BPF_EXIT_INSN(),
3019 BPF_MOV32_IMM(R0, 1),
3020 BPF_EXIT_INSN(),
3021 },
3022 INTERNAL,
3023 { },
3024 { { 0, 0x1 } },
3025 },
3026 {
3027 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
3028 .u.insns_int = {
3029 BPF_LD_IMM64(R2, 0x0),
3030 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
3031 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
3032 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3033 BPF_MOV32_IMM(R0, 2),
3034 BPF_EXIT_INSN(),
3035 BPF_MOV32_IMM(R0, 1),
3036 BPF_EXIT_INSN(),
3037 },
3038 INTERNAL,
3039 { },
3040 { { 0, 0x1 } },
3041 },
3042 {
3043 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
3044 .u.insns_int = {
3045 BPF_LD_IMM64(R2, 0x0),
3046 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
3047 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
3048 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3049 BPF_MOV32_IMM(R0, 2),
3050 BPF_EXIT_INSN(),
3051 BPF_MOV32_IMM(R0, 1),
3052 BPF_EXIT_INSN(),
3053 },
3054 INTERNAL,
3055 { },
3056 { { 0, 0x1 } },
3057 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003058 /* BPF_ALU | BPF_SUB | BPF_X */
3059 {
3060 "ALU_SUB_X: 3 - 1 = 2",
3061 .u.insns_int = {
3062 BPF_LD_IMM64(R0, 3),
3063 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3064 BPF_ALU32_REG(BPF_SUB, R0, R1),
3065 BPF_EXIT_INSN(),
3066 },
3067 INTERNAL,
3068 { },
3069 { { 0, 2 } },
3070 },
3071 {
3072 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
3073 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003074 BPF_LD_IMM64(R0, 4294967295U),
3075 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003076 BPF_ALU32_REG(BPF_SUB, R0, R1),
3077 BPF_EXIT_INSN(),
3078 },
3079 INTERNAL,
3080 { },
3081 { { 0, 1 } },
3082 },
3083 {
3084 "ALU64_SUB_X: 3 - 1 = 2",
3085 .u.insns_int = {
3086 BPF_LD_IMM64(R0, 3),
3087 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3088 BPF_ALU64_REG(BPF_SUB, R0, R1),
3089 BPF_EXIT_INSN(),
3090 },
3091 INTERNAL,
3092 { },
3093 { { 0, 2 } },
3094 },
3095 {
3096 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
3097 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003098 BPF_LD_IMM64(R0, 4294967295U),
3099 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003100 BPF_ALU64_REG(BPF_SUB, R0, R1),
3101 BPF_EXIT_INSN(),
3102 },
3103 INTERNAL,
3104 { },
3105 { { 0, 1 } },
3106 },
3107 /* BPF_ALU | BPF_SUB | BPF_K */
3108 {
3109 "ALU_SUB_K: 3 - 1 = 2",
3110 .u.insns_int = {
3111 BPF_LD_IMM64(R0, 3),
3112 BPF_ALU32_IMM(BPF_SUB, R0, 1),
3113 BPF_EXIT_INSN(),
3114 },
3115 INTERNAL,
3116 { },
3117 { { 0, 2 } },
3118 },
3119 {
3120 "ALU_SUB_K: 3 - 0 = 3",
3121 .u.insns_int = {
3122 BPF_LD_IMM64(R0, 3),
3123 BPF_ALU32_IMM(BPF_SUB, R0, 0),
3124 BPF_EXIT_INSN(),
3125 },
3126 INTERNAL,
3127 { },
3128 { { 0, 3 } },
3129 },
3130 {
3131 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
3132 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003133 BPF_LD_IMM64(R0, 4294967295U),
3134 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003135 BPF_EXIT_INSN(),
3136 },
3137 INTERNAL,
3138 { },
3139 { { 0, 1 } },
3140 },
3141 {
3142 "ALU64_SUB_K: 3 - 1 = 2",
3143 .u.insns_int = {
3144 BPF_LD_IMM64(R0, 3),
3145 BPF_ALU64_IMM(BPF_SUB, R0, 1),
3146 BPF_EXIT_INSN(),
3147 },
3148 INTERNAL,
3149 { },
3150 { { 0, 2 } },
3151 },
3152 {
3153 "ALU64_SUB_K: 3 - 0 = 3",
3154 .u.insns_int = {
3155 BPF_LD_IMM64(R0, 3),
3156 BPF_ALU64_IMM(BPF_SUB, R0, 0),
3157 BPF_EXIT_INSN(),
3158 },
3159 INTERNAL,
3160 { },
3161 { { 0, 3 } },
3162 },
3163 {
3164 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3165 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003166 BPF_LD_IMM64(R0, 4294967294U),
3167 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003168 BPF_EXIT_INSN(),
3169 },
3170 INTERNAL,
3171 { },
3172 { { 0, -1 } },
3173 },
3174 {
3175 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3176 .u.insns_int = {
3177 BPF_LD_IMM64(R0, 2147483646),
3178 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
3179 BPF_EXIT_INSN(),
3180 },
3181 INTERNAL,
3182 { },
3183 { { 0, -1 } },
3184 },
3185 /* BPF_ALU | BPF_MUL | BPF_X */
3186 {
3187 "ALU_MUL_X: 2 * 3 = 6",
3188 .u.insns_int = {
3189 BPF_LD_IMM64(R0, 2),
3190 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3191 BPF_ALU32_REG(BPF_MUL, R0, R1),
3192 BPF_EXIT_INSN(),
3193 },
3194 INTERNAL,
3195 { },
3196 { { 0, 6 } },
3197 },
3198 {
3199 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3200 .u.insns_int = {
3201 BPF_LD_IMM64(R0, 2),
3202 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
3203 BPF_ALU32_REG(BPF_MUL, R0, R1),
3204 BPF_EXIT_INSN(),
3205 },
3206 INTERNAL,
3207 { },
3208 { { 0, 0xFFFFFFF0 } },
3209 },
3210 {
3211 "ALU_MUL_X: -1 * -1 = 1",
3212 .u.insns_int = {
3213 BPF_LD_IMM64(R0, -1),
3214 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3215 BPF_ALU32_REG(BPF_MUL, R0, R1),
3216 BPF_EXIT_INSN(),
3217 },
3218 INTERNAL,
3219 { },
3220 { { 0, 1 } },
3221 },
3222 {
3223 "ALU64_MUL_X: 2 * 3 = 6",
3224 .u.insns_int = {
3225 BPF_LD_IMM64(R0, 2),
3226 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3227 BPF_ALU64_REG(BPF_MUL, R0, R1),
3228 BPF_EXIT_INSN(),
3229 },
3230 INTERNAL,
3231 { },
3232 { { 0, 6 } },
3233 },
3234 {
3235 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3236 .u.insns_int = {
3237 BPF_LD_IMM64(R0, 1),
3238 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3239 BPF_ALU64_REG(BPF_MUL, R0, R1),
3240 BPF_EXIT_INSN(),
3241 },
3242 INTERNAL,
3243 { },
3244 { { 0, 2147483647 } },
3245 },
Johan Almbladhfaa57622021-08-09 11:18:22 +02003246 {
3247 "ALU64_MUL_X: 64x64 multiply, low word",
3248 .u.insns_int = {
3249 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3250 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3251 BPF_ALU64_REG(BPF_MUL, R0, R1),
3252 BPF_EXIT_INSN(),
3253 },
3254 INTERNAL,
3255 { },
3256 { { 0, 0xe5618cf0 } }
3257 },
3258 {
3259 "ALU64_MUL_X: 64x64 multiply, high word",
3260 .u.insns_int = {
3261 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3262 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3263 BPF_ALU64_REG(BPF_MUL, R0, R1),
3264 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3265 BPF_EXIT_INSN(),
3266 },
3267 INTERNAL,
3268 { },
3269 { { 0, 0x2236d88f } }
3270 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003271 /* BPF_ALU | BPF_MUL | BPF_K */
3272 {
3273 "ALU_MUL_K: 2 * 3 = 6",
3274 .u.insns_int = {
3275 BPF_LD_IMM64(R0, 2),
3276 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3277 BPF_EXIT_INSN(),
3278 },
3279 INTERNAL,
3280 { },
3281 { { 0, 6 } },
3282 },
3283 {
3284 "ALU_MUL_K: 3 * 1 = 3",
3285 .u.insns_int = {
3286 BPF_LD_IMM64(R0, 3),
3287 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3288 BPF_EXIT_INSN(),
3289 },
3290 INTERNAL,
3291 { },
3292 { { 0, 3 } },
3293 },
3294 {
3295 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3296 .u.insns_int = {
3297 BPF_LD_IMM64(R0, 2),
3298 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3299 BPF_EXIT_INSN(),
3300 },
3301 INTERNAL,
3302 { },
3303 { { 0, 0xFFFFFFF0 } },
3304 },
3305 {
3306 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3307 .u.insns_int = {
3308 BPF_LD_IMM64(R2, 0x1),
3309 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3310 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3311 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3312 BPF_MOV32_IMM(R0, 2),
3313 BPF_EXIT_INSN(),
3314 BPF_MOV32_IMM(R0, 1),
3315 BPF_EXIT_INSN(),
3316 },
3317 INTERNAL,
3318 { },
3319 { { 0, 0x1 } },
3320 },
3321 {
3322 "ALU64_MUL_K: 2 * 3 = 6",
3323 .u.insns_int = {
3324 BPF_LD_IMM64(R0, 2),
3325 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3326 BPF_EXIT_INSN(),
3327 },
3328 INTERNAL,
3329 { },
3330 { { 0, 6 } },
3331 },
3332 {
3333 "ALU64_MUL_K: 3 * 1 = 3",
3334 .u.insns_int = {
3335 BPF_LD_IMM64(R0, 3),
3336 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3337 BPF_EXIT_INSN(),
3338 },
3339 INTERNAL,
3340 { },
3341 { { 0, 3 } },
3342 },
3343 {
3344 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3345 .u.insns_int = {
3346 BPF_LD_IMM64(R0, 1),
3347 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3348 BPF_EXIT_INSN(),
3349 },
3350 INTERNAL,
3351 { },
3352 { { 0, 2147483647 } },
3353 },
3354 {
3355 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3356 .u.insns_int = {
3357 BPF_LD_IMM64(R0, 1),
3358 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3359 BPF_EXIT_INSN(),
3360 },
3361 INTERNAL,
3362 { },
3363 { { 0, -2147483647 } },
3364 },
3365 {
3366 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3367 .u.insns_int = {
3368 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003369 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003370 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3371 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3372 BPF_MOV32_IMM(R0, 2),
3373 BPF_EXIT_INSN(),
3374 BPF_MOV32_IMM(R0, 1),
3375 BPF_EXIT_INSN(),
3376 },
3377 INTERNAL,
3378 { },
3379 { { 0, 0x1 } },
3380 },
Johan Almbladhfaa57622021-08-09 11:18:22 +02003381 {
3382 "ALU64_MUL_K: 64x32 multiply, low word",
3383 .u.insns_int = {
3384 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3385 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3386 BPF_EXIT_INSN(),
3387 },
3388 INTERNAL,
3389 { },
3390 { { 0, 0xe242d208 } }
3391 },
3392 {
3393 "ALU64_MUL_K: 64x32 multiply, high word",
3394 .u.insns_int = {
3395 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3396 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3397 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3398 BPF_EXIT_INSN(),
3399 },
3400 INTERNAL,
3401 { },
3402 { { 0, 0xc28f5c28 } }
3403 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003404 /* BPF_ALU | BPF_DIV | BPF_X */
3405 {
3406 "ALU_DIV_X: 6 / 2 = 3",
3407 .u.insns_int = {
3408 BPF_LD_IMM64(R0, 6),
3409 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3410 BPF_ALU32_REG(BPF_DIV, R0, R1),
3411 BPF_EXIT_INSN(),
3412 },
3413 INTERNAL,
3414 { },
3415 { { 0, 3 } },
3416 },
3417 {
3418 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3419 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003420 BPF_LD_IMM64(R0, 4294967295U),
3421 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003422 BPF_ALU32_REG(BPF_DIV, R0, R1),
3423 BPF_EXIT_INSN(),
3424 },
3425 INTERNAL,
3426 { },
3427 { { 0, 1 } },
3428 },
3429 {
3430 "ALU64_DIV_X: 6 / 2 = 3",
3431 .u.insns_int = {
3432 BPF_LD_IMM64(R0, 6),
3433 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3434 BPF_ALU64_REG(BPF_DIV, R0, R1),
3435 BPF_EXIT_INSN(),
3436 },
3437 INTERNAL,
3438 { },
3439 { { 0, 3 } },
3440 },
3441 {
3442 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3443 .u.insns_int = {
3444 BPF_LD_IMM64(R0, 2147483647),
3445 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3446 BPF_ALU64_REG(BPF_DIV, R0, R1),
3447 BPF_EXIT_INSN(),
3448 },
3449 INTERNAL,
3450 { },
3451 { { 0, 1 } },
3452 },
3453 {
3454 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3455 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003456 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3457 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3458 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003459 BPF_ALU64_REG(BPF_DIV, R2, R4),
3460 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3461 BPF_MOV32_IMM(R0, 2),
3462 BPF_EXIT_INSN(),
3463 BPF_MOV32_IMM(R0, 1),
3464 BPF_EXIT_INSN(),
3465 },
3466 INTERNAL,
3467 { },
3468 { { 0, 0x1 } },
3469 },
3470 /* BPF_ALU | BPF_DIV | BPF_K */
3471 {
3472 "ALU_DIV_K: 6 / 2 = 3",
3473 .u.insns_int = {
3474 BPF_LD_IMM64(R0, 6),
3475 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3476 BPF_EXIT_INSN(),
3477 },
3478 INTERNAL,
3479 { },
3480 { { 0, 3 } },
3481 },
3482 {
3483 "ALU_DIV_K: 3 / 1 = 3",
3484 .u.insns_int = {
3485 BPF_LD_IMM64(R0, 3),
3486 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3487 BPF_EXIT_INSN(),
3488 },
3489 INTERNAL,
3490 { },
3491 { { 0, 3 } },
3492 },
3493 {
3494 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3495 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003496 BPF_LD_IMM64(R0, 4294967295U),
3497 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003498 BPF_EXIT_INSN(),
3499 },
3500 INTERNAL,
3501 { },
3502 { { 0, 1 } },
3503 },
3504 {
3505 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3506 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003507 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003508 BPF_LD_IMM64(R3, 0x1UL),
3509 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3510 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3511 BPF_MOV32_IMM(R0, 2),
3512 BPF_EXIT_INSN(),
3513 BPF_MOV32_IMM(R0, 1),
3514 BPF_EXIT_INSN(),
3515 },
3516 INTERNAL,
3517 { },
3518 { { 0, 0x1 } },
3519 },
3520 {
3521 "ALU64_DIV_K: 6 / 2 = 3",
3522 .u.insns_int = {
3523 BPF_LD_IMM64(R0, 6),
3524 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3525 BPF_EXIT_INSN(),
3526 },
3527 INTERNAL,
3528 { },
3529 { { 0, 3 } },
3530 },
3531 {
3532 "ALU64_DIV_K: 3 / 1 = 3",
3533 .u.insns_int = {
3534 BPF_LD_IMM64(R0, 3),
3535 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3536 BPF_EXIT_INSN(),
3537 },
3538 INTERNAL,
3539 { },
3540 { { 0, 3 } },
3541 },
3542 {
3543 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3544 .u.insns_int = {
3545 BPF_LD_IMM64(R0, 2147483647),
3546 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3547 BPF_EXIT_INSN(),
3548 },
3549 INTERNAL,
3550 { },
3551 { { 0, 1 } },
3552 },
3553 {
3554 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3555 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003556 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3557 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003558 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3559 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3560 BPF_MOV32_IMM(R0, 2),
3561 BPF_EXIT_INSN(),
3562 BPF_MOV32_IMM(R0, 1),
3563 BPF_EXIT_INSN(),
3564 },
3565 INTERNAL,
3566 { },
3567 { { 0, 0x1 } },
3568 },
3569 /* BPF_ALU | BPF_MOD | BPF_X */
3570 {
3571 "ALU_MOD_X: 3 % 2 = 1",
3572 .u.insns_int = {
3573 BPF_LD_IMM64(R0, 3),
3574 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3575 BPF_ALU32_REG(BPF_MOD, R0, R1),
3576 BPF_EXIT_INSN(),
3577 },
3578 INTERNAL,
3579 { },
3580 { { 0, 1 } },
3581 },
3582 {
3583 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3584 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003585 BPF_LD_IMM64(R0, 4294967295U),
3586 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003587 BPF_ALU32_REG(BPF_MOD, R0, R1),
3588 BPF_EXIT_INSN(),
3589 },
3590 INTERNAL,
3591 { },
3592 { { 0, 2 } },
3593 },
3594 {
3595 "ALU64_MOD_X: 3 % 2 = 1",
3596 .u.insns_int = {
3597 BPF_LD_IMM64(R0, 3),
3598 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3599 BPF_ALU64_REG(BPF_MOD, R0, R1),
3600 BPF_EXIT_INSN(),
3601 },
3602 INTERNAL,
3603 { },
3604 { { 0, 1 } },
3605 },
3606 {
3607 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3608 .u.insns_int = {
3609 BPF_LD_IMM64(R0, 2147483647),
3610 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3611 BPF_ALU64_REG(BPF_MOD, R0, R1),
3612 BPF_EXIT_INSN(),
3613 },
3614 INTERNAL,
3615 { },
3616 { { 0, 2 } },
3617 },
3618 /* BPF_ALU | BPF_MOD | BPF_K */
3619 {
3620 "ALU_MOD_K: 3 % 2 = 1",
3621 .u.insns_int = {
3622 BPF_LD_IMM64(R0, 3),
3623 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3624 BPF_EXIT_INSN(),
3625 },
3626 INTERNAL,
3627 { },
3628 { { 0, 1 } },
3629 },
3630 {
3631 "ALU_MOD_K: 3 % 1 = 0",
3632 .u.insns_int = {
3633 BPF_LD_IMM64(R0, 3),
3634 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3635 BPF_EXIT_INSN(),
3636 },
3637 INTERNAL,
3638 { },
3639 { { 0, 0 } },
3640 },
3641 {
3642 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3643 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003644 BPF_LD_IMM64(R0, 4294967295U),
3645 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003646 BPF_EXIT_INSN(),
3647 },
3648 INTERNAL,
3649 { },
3650 { { 0, 2 } },
3651 },
3652 {
3653 "ALU64_MOD_K: 3 % 2 = 1",
3654 .u.insns_int = {
3655 BPF_LD_IMM64(R0, 3),
3656 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3657 BPF_EXIT_INSN(),
3658 },
3659 INTERNAL,
3660 { },
3661 { { 0, 1 } },
3662 },
3663 {
3664 "ALU64_MOD_K: 3 % 1 = 0",
3665 .u.insns_int = {
3666 BPF_LD_IMM64(R0, 3),
3667 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3668 BPF_EXIT_INSN(),
3669 },
3670 INTERNAL,
3671 { },
3672 { { 0, 0 } },
3673 },
3674 {
3675 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3676 .u.insns_int = {
3677 BPF_LD_IMM64(R0, 2147483647),
3678 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3679 BPF_EXIT_INSN(),
3680 },
3681 INTERNAL,
3682 { },
3683 { { 0, 2 } },
3684 },
3685 /* BPF_ALU | BPF_AND | BPF_X */
3686 {
3687 "ALU_AND_X: 3 & 2 = 2",
3688 .u.insns_int = {
3689 BPF_LD_IMM64(R0, 3),
3690 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3691 BPF_ALU32_REG(BPF_AND, R0, R1),
3692 BPF_EXIT_INSN(),
3693 },
3694 INTERNAL,
3695 { },
3696 { { 0, 2 } },
3697 },
3698 {
3699 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3700 .u.insns_int = {
3701 BPF_LD_IMM64(R0, 0xffffffff),
3702 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3703 BPF_ALU32_REG(BPF_AND, R0, R1),
3704 BPF_EXIT_INSN(),
3705 },
3706 INTERNAL,
3707 { },
3708 { { 0, 0xffffffff } },
3709 },
3710 {
3711 "ALU64_AND_X: 3 & 2 = 2",
3712 .u.insns_int = {
3713 BPF_LD_IMM64(R0, 3),
3714 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3715 BPF_ALU64_REG(BPF_AND, R0, R1),
3716 BPF_EXIT_INSN(),
3717 },
3718 INTERNAL,
3719 { },
3720 { { 0, 2 } },
3721 },
3722 {
3723 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3724 .u.insns_int = {
3725 BPF_LD_IMM64(R0, 0xffffffff),
3726 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3727 BPF_ALU64_REG(BPF_AND, R0, R1),
3728 BPF_EXIT_INSN(),
3729 },
3730 INTERNAL,
3731 { },
3732 { { 0, 0xffffffff } },
3733 },
3734 /* BPF_ALU | BPF_AND | BPF_K */
3735 {
3736 "ALU_AND_K: 3 & 2 = 2",
3737 .u.insns_int = {
3738 BPF_LD_IMM64(R0, 3),
3739 BPF_ALU32_IMM(BPF_AND, R0, 2),
3740 BPF_EXIT_INSN(),
3741 },
3742 INTERNAL,
3743 { },
3744 { { 0, 2 } },
3745 },
3746 {
3747 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3748 .u.insns_int = {
3749 BPF_LD_IMM64(R0, 0xffffffff),
3750 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3751 BPF_EXIT_INSN(),
3752 },
3753 INTERNAL,
3754 { },
3755 { { 0, 0xffffffff } },
3756 },
3757 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003758 "ALU_AND_K: Small immediate",
3759 .u.insns_int = {
3760 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3761 BPF_ALU32_IMM(BPF_AND, R0, 15),
3762 BPF_EXIT_INSN(),
3763 },
3764 INTERNAL,
3765 { },
3766 { { 0, 4 } }
3767 },
3768 {
3769 "ALU_AND_K: Large immediate",
3770 .u.insns_int = {
3771 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
3772 BPF_ALU32_IMM(BPF_AND, R0, 0xafbfcfdf),
3773 BPF_EXIT_INSN(),
3774 },
3775 INTERNAL,
3776 { },
3777 { { 0, 0xa1b2c3d4 } }
3778 },
3779 {
3780 "ALU_AND_K: Zero extension",
3781 .u.insns_int = {
3782 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3783 BPF_LD_IMM64(R1, 0x0000000080a0c0e0LL),
3784 BPF_ALU32_IMM(BPF_AND, R0, 0xf0f0f0f0),
3785 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3786 BPF_MOV32_IMM(R0, 2),
3787 BPF_EXIT_INSN(),
3788 BPF_MOV32_IMM(R0, 1),
3789 BPF_EXIT_INSN(),
3790 },
3791 INTERNAL,
3792 { },
3793 { { 0, 1 } }
3794 },
3795 {
Michael Holzheucffc6422015-05-11 22:22:44 -07003796 "ALU64_AND_K: 3 & 2 = 2",
3797 .u.insns_int = {
3798 BPF_LD_IMM64(R0, 3),
3799 BPF_ALU64_IMM(BPF_AND, R0, 2),
3800 BPF_EXIT_INSN(),
3801 },
3802 INTERNAL,
3803 { },
3804 { { 0, 2 } },
3805 },
3806 {
3807 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3808 .u.insns_int = {
3809 BPF_LD_IMM64(R0, 0xffffffff),
3810 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3811 BPF_EXIT_INSN(),
3812 },
3813 INTERNAL,
3814 { },
3815 { { 0, 0xffffffff } },
3816 },
3817 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003818 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000000000000000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003819 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003820 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3821 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003822 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3823 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3824 BPF_MOV32_IMM(R0, 2),
3825 BPF_EXIT_INSN(),
3826 BPF_MOV32_IMM(R0, 1),
3827 BPF_EXIT_INSN(),
3828 },
3829 INTERNAL,
3830 { },
3831 { { 0, 0x1 } },
3832 },
3833 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003834 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffff0000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003835 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003836 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3837 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003838 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3839 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3840 BPF_MOV32_IMM(R0, 2),
3841 BPF_EXIT_INSN(),
3842 BPF_MOV32_IMM(R0, 1),
3843 BPF_EXIT_INSN(),
3844 },
3845 INTERNAL,
3846 { },
3847 { { 0, 0x1 } },
3848 },
3849 {
3850 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3851 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003852 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3853 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003854 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3855 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3856 BPF_MOV32_IMM(R0, 2),
3857 BPF_EXIT_INSN(),
3858 BPF_MOV32_IMM(R0, 1),
3859 BPF_EXIT_INSN(),
3860 },
3861 INTERNAL,
3862 { },
3863 { { 0, 0x1 } },
3864 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003865 {
3866 "ALU64_AND_K: Sign extension 1",
3867 .u.insns_int = {
3868 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3869 BPF_LD_IMM64(R1, 0x00000000090b0d0fLL),
3870 BPF_ALU64_IMM(BPF_AND, R0, 0x0f0f0f0f),
3871 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3872 BPF_MOV32_IMM(R0, 2),
3873 BPF_EXIT_INSN(),
3874 BPF_MOV32_IMM(R0, 1),
3875 BPF_EXIT_INSN(),
3876 },
3877 INTERNAL,
3878 { },
3879 { { 0, 1 } }
3880 },
3881 {
3882 "ALU64_AND_K: Sign extension 2",
3883 .u.insns_int = {
3884 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3885 BPF_LD_IMM64(R1, 0x0123456780a0c0e0LL),
3886 BPF_ALU64_IMM(BPF_AND, R0, 0xf0f0f0f0),
3887 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3888 BPF_MOV32_IMM(R0, 2),
3889 BPF_EXIT_INSN(),
3890 BPF_MOV32_IMM(R0, 1),
3891 BPF_EXIT_INSN(),
3892 },
3893 INTERNAL,
3894 { },
3895 { { 0, 1 } }
3896 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003897 /* BPF_ALU | BPF_OR | BPF_X */
3898 {
3899 "ALU_OR_X: 1 | 2 = 3",
3900 .u.insns_int = {
3901 BPF_LD_IMM64(R0, 1),
3902 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3903 BPF_ALU32_REG(BPF_OR, R0, R1),
3904 BPF_EXIT_INSN(),
3905 },
3906 INTERNAL,
3907 { },
3908 { { 0, 3 } },
3909 },
3910 {
3911 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3912 .u.insns_int = {
3913 BPF_LD_IMM64(R0, 0),
3914 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3915 BPF_ALU32_REG(BPF_OR, R0, R1),
3916 BPF_EXIT_INSN(),
3917 },
3918 INTERNAL,
3919 { },
3920 { { 0, 0xffffffff } },
3921 },
3922 {
3923 "ALU64_OR_X: 1 | 2 = 3",
3924 .u.insns_int = {
3925 BPF_LD_IMM64(R0, 1),
3926 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3927 BPF_ALU64_REG(BPF_OR, R0, R1),
3928 BPF_EXIT_INSN(),
3929 },
3930 INTERNAL,
3931 { },
3932 { { 0, 3 } },
3933 },
3934 {
3935 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3936 .u.insns_int = {
3937 BPF_LD_IMM64(R0, 0),
3938 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3939 BPF_ALU64_REG(BPF_OR, R0, R1),
3940 BPF_EXIT_INSN(),
3941 },
3942 INTERNAL,
3943 { },
3944 { { 0, 0xffffffff } },
3945 },
3946 /* BPF_ALU | BPF_OR | BPF_K */
3947 {
3948 "ALU_OR_K: 1 | 2 = 3",
3949 .u.insns_int = {
3950 BPF_LD_IMM64(R0, 1),
3951 BPF_ALU32_IMM(BPF_OR, R0, 2),
3952 BPF_EXIT_INSN(),
3953 },
3954 INTERNAL,
3955 { },
3956 { { 0, 3 } },
3957 },
3958 {
3959 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3960 .u.insns_int = {
3961 BPF_LD_IMM64(R0, 0),
3962 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3963 BPF_EXIT_INSN(),
3964 },
3965 INTERNAL,
3966 { },
3967 { { 0, 0xffffffff } },
3968 },
3969 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003970 "ALU_OR_K: Small immediate",
3971 .u.insns_int = {
3972 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3973 BPF_ALU32_IMM(BPF_OR, R0, 1),
3974 BPF_EXIT_INSN(),
3975 },
3976 INTERNAL,
3977 { },
3978 { { 0, 0x01020305 } }
3979 },
3980 {
3981 "ALU_OR_K: Large immediate",
3982 .u.insns_int = {
3983 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3984 BPF_ALU32_IMM(BPF_OR, R0, 0xa0b0c0d0),
3985 BPF_EXIT_INSN(),
3986 },
3987 INTERNAL,
3988 { },
3989 { { 0, 0xa1b2c3d4 } }
3990 },
3991 {
3992 "ALU_OR_K: Zero extension",
3993 .u.insns_int = {
3994 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3995 BPF_LD_IMM64(R1, 0x00000000f9fbfdffLL),
3996 BPF_ALU32_IMM(BPF_OR, R0, 0xf0f0f0f0),
3997 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3998 BPF_MOV32_IMM(R0, 2),
3999 BPF_EXIT_INSN(),
4000 BPF_MOV32_IMM(R0, 1),
4001 BPF_EXIT_INSN(),
4002 },
4003 INTERNAL,
4004 { },
4005 { { 0, 1 } }
4006 },
4007 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004008 "ALU64_OR_K: 1 | 2 = 3",
4009 .u.insns_int = {
4010 BPF_LD_IMM64(R0, 1),
4011 BPF_ALU64_IMM(BPF_OR, R0, 2),
4012 BPF_EXIT_INSN(),
4013 },
4014 INTERNAL,
4015 { },
4016 { { 0, 3 } },
4017 },
4018 {
4019 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
4020 .u.insns_int = {
4021 BPF_LD_IMM64(R0, 0),
4022 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
4023 BPF_EXIT_INSN(),
4024 },
4025 INTERNAL,
4026 { },
4027 { { 0, 0xffffffff } },
4028 },
4029 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02004030 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffffffff0000",
Michael Holzheucffc6422015-05-11 22:22:44 -07004031 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004032 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4033 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004034 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
4035 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4036 BPF_MOV32_IMM(R0, 2),
4037 BPF_EXIT_INSN(),
4038 BPF_MOV32_IMM(R0, 1),
4039 BPF_EXIT_INSN(),
4040 },
4041 INTERNAL,
4042 { },
4043 { { 0, 0x1 } },
4044 },
4045 {
4046 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
4047 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004048 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4049 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004050 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4051 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4052 BPF_MOV32_IMM(R0, 2),
4053 BPF_EXIT_INSN(),
4054 BPF_MOV32_IMM(R0, 1),
4055 BPF_EXIT_INSN(),
4056 },
4057 INTERNAL,
4058 { },
4059 { { 0, 0x1 } },
4060 },
4061 {
4062 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
4063 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004064 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4065 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004066 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4067 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4068 BPF_MOV32_IMM(R0, 2),
4069 BPF_EXIT_INSN(),
4070 BPF_MOV32_IMM(R0, 1),
4071 BPF_EXIT_INSN(),
4072 },
4073 INTERNAL,
4074 { },
4075 { { 0, 0x1 } },
4076 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004077 {
4078 "ALU64_OR_K: Sign extension 1",
4079 .u.insns_int = {
4080 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4081 BPF_LD_IMM64(R1, 0x012345678fafcfefLL),
4082 BPF_ALU64_IMM(BPF_OR, R0, 0x0f0f0f0f),
4083 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4084 BPF_MOV32_IMM(R0, 2),
4085 BPF_EXIT_INSN(),
4086 BPF_MOV32_IMM(R0, 1),
4087 BPF_EXIT_INSN(),
4088 },
4089 INTERNAL,
4090 { },
4091 { { 0, 1 } }
4092 },
4093 {
4094 "ALU64_OR_K: Sign extension 2",
4095 .u.insns_int = {
4096 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4097 BPF_LD_IMM64(R1, 0xfffffffff9fbfdffLL),
4098 BPF_ALU64_IMM(BPF_OR, R0, 0xf0f0f0f0),
4099 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4100 BPF_MOV32_IMM(R0, 2),
4101 BPF_EXIT_INSN(),
4102 BPF_MOV32_IMM(R0, 1),
4103 BPF_EXIT_INSN(),
4104 },
4105 INTERNAL,
4106 { },
4107 { { 0, 1 } }
4108 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004109 /* BPF_ALU | BPF_XOR | BPF_X */
4110 {
4111 "ALU_XOR_X: 5 ^ 6 = 3",
4112 .u.insns_int = {
4113 BPF_LD_IMM64(R0, 5),
4114 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4115 BPF_ALU32_REG(BPF_XOR, R0, R1),
4116 BPF_EXIT_INSN(),
4117 },
4118 INTERNAL,
4119 { },
4120 { { 0, 3 } },
4121 },
4122 {
4123 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
4124 .u.insns_int = {
4125 BPF_LD_IMM64(R0, 1),
4126 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4127 BPF_ALU32_REG(BPF_XOR, R0, R1),
4128 BPF_EXIT_INSN(),
4129 },
4130 INTERNAL,
4131 { },
4132 { { 0, 0xfffffffe } },
4133 },
4134 {
4135 "ALU64_XOR_X: 5 ^ 6 = 3",
4136 .u.insns_int = {
4137 BPF_LD_IMM64(R0, 5),
4138 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4139 BPF_ALU64_REG(BPF_XOR, R0, R1),
4140 BPF_EXIT_INSN(),
4141 },
4142 INTERNAL,
4143 { },
4144 { { 0, 3 } },
4145 },
4146 {
4147 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
4148 .u.insns_int = {
4149 BPF_LD_IMM64(R0, 1),
4150 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4151 BPF_ALU64_REG(BPF_XOR, R0, R1),
4152 BPF_EXIT_INSN(),
4153 },
4154 INTERNAL,
4155 { },
4156 { { 0, 0xfffffffe } },
4157 },
4158 /* BPF_ALU | BPF_XOR | BPF_K */
4159 {
4160 "ALU_XOR_K: 5 ^ 6 = 3",
4161 .u.insns_int = {
4162 BPF_LD_IMM64(R0, 5),
4163 BPF_ALU32_IMM(BPF_XOR, R0, 6),
4164 BPF_EXIT_INSN(),
4165 },
4166 INTERNAL,
4167 { },
4168 { { 0, 3 } },
4169 },
4170 {
4171 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
4172 .u.insns_int = {
4173 BPF_LD_IMM64(R0, 1),
4174 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
4175 BPF_EXIT_INSN(),
4176 },
4177 INTERNAL,
4178 { },
4179 { { 0, 0xfffffffe } },
4180 },
4181 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004182 "ALU_XOR_K: Small immediate",
4183 .u.insns_int = {
4184 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
4185 BPF_ALU32_IMM(BPF_XOR, R0, 15),
4186 BPF_EXIT_INSN(),
4187 },
4188 INTERNAL,
4189 { },
4190 { { 0, 0x0102030b } }
4191 },
4192 {
4193 "ALU_XOR_K: Large immediate",
4194 .u.insns_int = {
4195 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
4196 BPF_ALU32_IMM(BPF_XOR, R0, 0xafbfcfdf),
4197 BPF_EXIT_INSN(),
4198 },
4199 INTERNAL,
4200 { },
4201 { { 0, 0x5e4d3c2b } }
4202 },
4203 {
4204 "ALU_XOR_K: Zero extension",
4205 .u.insns_int = {
4206 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4207 BPF_LD_IMM64(R1, 0x00000000795b3d1fLL),
4208 BPF_ALU32_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4209 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4210 BPF_MOV32_IMM(R0, 2),
4211 BPF_EXIT_INSN(),
4212 BPF_MOV32_IMM(R0, 1),
4213 BPF_EXIT_INSN(),
4214 },
4215 INTERNAL,
4216 { },
4217 { { 0, 1 } }
4218 },
4219 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004220 "ALU64_XOR_K: 5 ^ 6 = 3",
4221 .u.insns_int = {
4222 BPF_LD_IMM64(R0, 5),
4223 BPF_ALU64_IMM(BPF_XOR, R0, 6),
4224 BPF_EXIT_INSN(),
4225 },
4226 INTERNAL,
4227 { },
4228 { { 0, 3 } },
4229 },
4230 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02004231 "ALU64_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
Michael Holzheucffc6422015-05-11 22:22:44 -07004232 .u.insns_int = {
4233 BPF_LD_IMM64(R0, 1),
4234 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
4235 BPF_EXIT_INSN(),
4236 },
4237 INTERNAL,
4238 { },
4239 { { 0, 0xfffffffe } },
4240 },
4241 {
4242 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
4243 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004244 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4245 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004246 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
4247 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4248 BPF_MOV32_IMM(R0, 2),
4249 BPF_EXIT_INSN(),
4250 BPF_MOV32_IMM(R0, 1),
4251 BPF_EXIT_INSN(),
4252 },
4253 INTERNAL,
4254 { },
4255 { { 0, 0x1 } },
4256 },
4257 {
4258 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
4259 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004260 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4261 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004262 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4263 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4264 BPF_MOV32_IMM(R0, 2),
4265 BPF_EXIT_INSN(),
4266 BPF_MOV32_IMM(R0, 1),
4267 BPF_EXIT_INSN(),
4268 },
4269 INTERNAL,
4270 { },
4271 { { 0, 0x1 } },
4272 },
4273 {
4274 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
4275 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004276 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4277 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004278 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4279 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4280 BPF_MOV32_IMM(R0, 2),
4281 BPF_EXIT_INSN(),
4282 BPF_MOV32_IMM(R0, 1),
4283 BPF_EXIT_INSN(),
4284 },
4285 INTERNAL,
4286 { },
4287 { { 0, 0x1 } },
4288 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004289 {
4290 "ALU64_XOR_K: Sign extension 1",
4291 .u.insns_int = {
4292 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4293 BPF_LD_IMM64(R1, 0x0123456786a4c2e0LL),
4294 BPF_ALU64_IMM(BPF_XOR, R0, 0x0f0f0f0f),
4295 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4296 BPF_MOV32_IMM(R0, 2),
4297 BPF_EXIT_INSN(),
4298 BPF_MOV32_IMM(R0, 1),
4299 BPF_EXIT_INSN(),
4300 },
4301 INTERNAL,
4302 { },
4303 { { 0, 1 } }
4304 },
4305 {
4306 "ALU64_XOR_K: Sign extension 2",
4307 .u.insns_int = {
4308 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4309 BPF_LD_IMM64(R1, 0xfedcba98795b3d1fLL),
4310 BPF_ALU64_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4311 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4312 BPF_MOV32_IMM(R0, 2),
4313 BPF_EXIT_INSN(),
4314 BPF_MOV32_IMM(R0, 1),
4315 BPF_EXIT_INSN(),
4316 },
4317 INTERNAL,
4318 { },
4319 { { 0, 1 } }
4320 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004321 /* BPF_ALU | BPF_LSH | BPF_X */
4322 {
4323 "ALU_LSH_X: 1 << 1 = 2",
4324 .u.insns_int = {
4325 BPF_LD_IMM64(R0, 1),
4326 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4327 BPF_ALU32_REG(BPF_LSH, R0, R1),
4328 BPF_EXIT_INSN(),
4329 },
4330 INTERNAL,
4331 { },
4332 { { 0, 2 } },
4333 },
4334 {
4335 "ALU_LSH_X: 1 << 31 = 0x80000000",
4336 .u.insns_int = {
4337 BPF_LD_IMM64(R0, 1),
4338 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4339 BPF_ALU32_REG(BPF_LSH, R0, R1),
4340 BPF_EXIT_INSN(),
4341 },
4342 INTERNAL,
4343 { },
4344 { { 0, 0x80000000 } },
4345 },
4346 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004347 "ALU_LSH_X: 0x12345678 << 12 = 0x45678000",
4348 .u.insns_int = {
4349 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4350 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4351 BPF_ALU32_REG(BPF_LSH, R0, R1),
4352 BPF_EXIT_INSN(),
4353 },
4354 INTERNAL,
4355 { },
4356 { { 0, 0x45678000 } }
4357 },
4358 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004359 "ALU64_LSH_X: 1 << 1 = 2",
4360 .u.insns_int = {
4361 BPF_LD_IMM64(R0, 1),
4362 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4363 BPF_ALU64_REG(BPF_LSH, R0, R1),
4364 BPF_EXIT_INSN(),
4365 },
4366 INTERNAL,
4367 { },
4368 { { 0, 2 } },
4369 },
4370 {
4371 "ALU64_LSH_X: 1 << 31 = 0x80000000",
4372 .u.insns_int = {
4373 BPF_LD_IMM64(R0, 1),
4374 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4375 BPF_ALU64_REG(BPF_LSH, R0, R1),
4376 BPF_EXIT_INSN(),
4377 },
4378 INTERNAL,
4379 { },
4380 { { 0, 0x80000000 } },
4381 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004382 {
4383 "ALU64_LSH_X: Shift < 32, low word",
4384 .u.insns_int = {
4385 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4386 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4387 BPF_ALU64_REG(BPF_LSH, R0, R1),
4388 BPF_EXIT_INSN(),
4389 },
4390 INTERNAL,
4391 { },
4392 { { 0, 0xbcdef000 } }
4393 },
4394 {
4395 "ALU64_LSH_X: Shift < 32, high word",
4396 .u.insns_int = {
4397 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4398 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4399 BPF_ALU64_REG(BPF_LSH, R0, R1),
4400 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4401 BPF_EXIT_INSN(),
4402 },
4403 INTERNAL,
4404 { },
4405 { { 0, 0x3456789a } }
4406 },
4407 {
4408 "ALU64_LSH_X: Shift > 32, low word",
4409 .u.insns_int = {
4410 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4411 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4412 BPF_ALU64_REG(BPF_LSH, R0, R1),
4413 BPF_EXIT_INSN(),
4414 },
4415 INTERNAL,
4416 { },
4417 { { 0, 0 } }
4418 },
4419 {
4420 "ALU64_LSH_X: Shift > 32, high word",
4421 .u.insns_int = {
4422 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4423 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4424 BPF_ALU64_REG(BPF_LSH, R0, R1),
4425 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4426 BPF_EXIT_INSN(),
4427 },
4428 INTERNAL,
4429 { },
4430 { { 0, 0x9abcdef0 } }
4431 },
4432 {
4433 "ALU64_LSH_X: Shift == 32, low word",
4434 .u.insns_int = {
4435 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4436 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4437 BPF_ALU64_REG(BPF_LSH, R0, R1),
4438 BPF_EXIT_INSN(),
4439 },
4440 INTERNAL,
4441 { },
4442 { { 0, 0 } }
4443 },
4444 {
4445 "ALU64_LSH_X: Shift == 32, high word",
4446 .u.insns_int = {
4447 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4448 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4449 BPF_ALU64_REG(BPF_LSH, R0, R1),
4450 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4451 BPF_EXIT_INSN(),
4452 },
4453 INTERNAL,
4454 { },
4455 { { 0, 0x89abcdef } }
4456 },
4457 {
4458 "ALU64_LSH_X: Zero shift, low word",
4459 .u.insns_int = {
4460 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4461 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4462 BPF_ALU64_REG(BPF_LSH, R0, R1),
4463 BPF_EXIT_INSN(),
4464 },
4465 INTERNAL,
4466 { },
4467 { { 0, 0x89abcdef } }
4468 },
4469 {
4470 "ALU64_LSH_X: Zero shift, high word",
4471 .u.insns_int = {
4472 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4473 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4474 BPF_ALU64_REG(BPF_LSH, R0, R1),
4475 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4476 BPF_EXIT_INSN(),
4477 },
4478 INTERNAL,
4479 { },
4480 { { 0, 0x01234567 } }
4481 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004482 /* BPF_ALU | BPF_LSH | BPF_K */
4483 {
4484 "ALU_LSH_K: 1 << 1 = 2",
4485 .u.insns_int = {
4486 BPF_LD_IMM64(R0, 1),
4487 BPF_ALU32_IMM(BPF_LSH, R0, 1),
4488 BPF_EXIT_INSN(),
4489 },
4490 INTERNAL,
4491 { },
4492 { { 0, 2 } },
4493 },
4494 {
4495 "ALU_LSH_K: 1 << 31 = 0x80000000",
4496 .u.insns_int = {
4497 BPF_LD_IMM64(R0, 1),
4498 BPF_ALU32_IMM(BPF_LSH, R0, 31),
4499 BPF_EXIT_INSN(),
4500 },
4501 INTERNAL,
4502 { },
4503 { { 0, 0x80000000 } },
4504 },
4505 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004506 "ALU_LSH_K: 0x12345678 << 12 = 0x45678000",
4507 .u.insns_int = {
4508 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4509 BPF_ALU32_IMM(BPF_LSH, R0, 12),
4510 BPF_EXIT_INSN(),
4511 },
4512 INTERNAL,
4513 { },
4514 { { 0, 0x45678000 } }
4515 },
4516 {
4517 "ALU_LSH_K: 0x12345678 << 0 = 0x12345678",
4518 .u.insns_int = {
4519 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4520 BPF_ALU32_IMM(BPF_LSH, R0, 0),
4521 BPF_EXIT_INSN(),
4522 },
4523 INTERNAL,
4524 { },
4525 { { 0, 0x12345678 } }
4526 },
4527 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004528 "ALU64_LSH_K: 1 << 1 = 2",
4529 .u.insns_int = {
4530 BPF_LD_IMM64(R0, 1),
4531 BPF_ALU64_IMM(BPF_LSH, R0, 1),
4532 BPF_EXIT_INSN(),
4533 },
4534 INTERNAL,
4535 { },
4536 { { 0, 2 } },
4537 },
4538 {
4539 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4540 .u.insns_int = {
4541 BPF_LD_IMM64(R0, 1),
4542 BPF_ALU64_IMM(BPF_LSH, R0, 31),
4543 BPF_EXIT_INSN(),
4544 },
4545 INTERNAL,
4546 { },
4547 { { 0, 0x80000000 } },
4548 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004549 {
4550 "ALU64_LSH_K: Shift < 32, low word",
4551 .u.insns_int = {
4552 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4553 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4554 BPF_EXIT_INSN(),
4555 },
4556 INTERNAL,
4557 { },
4558 { { 0, 0xbcdef000 } }
4559 },
4560 {
4561 "ALU64_LSH_K: Shift < 32, high word",
4562 .u.insns_int = {
4563 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4564 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4565 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4566 BPF_EXIT_INSN(),
4567 },
4568 INTERNAL,
4569 { },
4570 { { 0, 0x3456789a } }
4571 },
4572 {
4573 "ALU64_LSH_K: Shift > 32, low word",
4574 .u.insns_int = {
4575 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4576 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4577 BPF_EXIT_INSN(),
4578 },
4579 INTERNAL,
4580 { },
4581 { { 0, 0 } }
4582 },
4583 {
4584 "ALU64_LSH_K: Shift > 32, high word",
4585 .u.insns_int = {
4586 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4587 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4588 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4589 BPF_EXIT_INSN(),
4590 },
4591 INTERNAL,
4592 { },
4593 { { 0, 0x9abcdef0 } }
4594 },
4595 {
4596 "ALU64_LSH_K: Shift == 32, low word",
4597 .u.insns_int = {
4598 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4599 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4600 BPF_EXIT_INSN(),
4601 },
4602 INTERNAL,
4603 { },
4604 { { 0, 0 } }
4605 },
4606 {
4607 "ALU64_LSH_K: Shift == 32, high word",
4608 .u.insns_int = {
4609 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4610 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4611 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4612 BPF_EXIT_INSN(),
4613 },
4614 INTERNAL,
4615 { },
4616 { { 0, 0x89abcdef } }
4617 },
4618 {
4619 "ALU64_LSH_K: Zero shift",
4620 .u.insns_int = {
4621 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4622 BPF_ALU64_IMM(BPF_LSH, R0, 0),
4623 BPF_EXIT_INSN(),
4624 },
4625 INTERNAL,
4626 { },
4627 { { 0, 0x89abcdef } }
4628 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004629 /* BPF_ALU | BPF_RSH | BPF_X */
4630 {
4631 "ALU_RSH_X: 2 >> 1 = 1",
4632 .u.insns_int = {
4633 BPF_LD_IMM64(R0, 2),
4634 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4635 BPF_ALU32_REG(BPF_RSH, R0, R1),
4636 BPF_EXIT_INSN(),
4637 },
4638 INTERNAL,
4639 { },
4640 { { 0, 1 } },
4641 },
4642 {
4643 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4644 .u.insns_int = {
4645 BPF_LD_IMM64(R0, 0x80000000),
4646 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4647 BPF_ALU32_REG(BPF_RSH, R0, R1),
4648 BPF_EXIT_INSN(),
4649 },
4650 INTERNAL,
4651 { },
4652 { { 0, 1 } },
4653 },
4654 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004655 "ALU_RSH_X: 0x12345678 >> 20 = 0x123",
4656 .u.insns_int = {
4657 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4658 BPF_ALU32_IMM(BPF_MOV, R1, 20),
4659 BPF_ALU32_REG(BPF_RSH, R0, R1),
4660 BPF_EXIT_INSN(),
4661 },
4662 INTERNAL,
4663 { },
4664 { { 0, 0x123 } }
4665 },
4666 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004667 "ALU64_RSH_X: 2 >> 1 = 1",
4668 .u.insns_int = {
4669 BPF_LD_IMM64(R0, 2),
4670 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4671 BPF_ALU64_REG(BPF_RSH, R0, R1),
4672 BPF_EXIT_INSN(),
4673 },
4674 INTERNAL,
4675 { },
4676 { { 0, 1 } },
4677 },
4678 {
4679 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4680 .u.insns_int = {
4681 BPF_LD_IMM64(R0, 0x80000000),
4682 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4683 BPF_ALU64_REG(BPF_RSH, R0, R1),
4684 BPF_EXIT_INSN(),
4685 },
4686 INTERNAL,
4687 { },
4688 { { 0, 1 } },
4689 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004690 {
4691 "ALU64_RSH_X: Shift < 32, low word",
4692 .u.insns_int = {
4693 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4694 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4695 BPF_ALU64_REG(BPF_RSH, R0, R1),
4696 BPF_EXIT_INSN(),
4697 },
4698 INTERNAL,
4699 { },
4700 { { 0, 0x56789abc } }
4701 },
4702 {
4703 "ALU64_RSH_X: Shift < 32, high word",
4704 .u.insns_int = {
4705 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4706 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4707 BPF_ALU64_REG(BPF_RSH, R0, R1),
4708 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4709 BPF_EXIT_INSN(),
4710 },
4711 INTERNAL,
4712 { },
4713 { { 0, 0x00081234 } }
4714 },
4715 {
4716 "ALU64_RSH_X: Shift > 32, low word",
4717 .u.insns_int = {
4718 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4719 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4720 BPF_ALU64_REG(BPF_RSH, R0, R1),
4721 BPF_EXIT_INSN(),
4722 },
4723 INTERNAL,
4724 { },
4725 { { 0, 0x08123456 } }
4726 },
4727 {
4728 "ALU64_RSH_X: Shift > 32, high word",
4729 .u.insns_int = {
4730 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4731 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4732 BPF_ALU64_REG(BPF_RSH, R0, R1),
4733 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4734 BPF_EXIT_INSN(),
4735 },
4736 INTERNAL,
4737 { },
4738 { { 0, 0 } }
4739 },
4740 {
4741 "ALU64_RSH_X: Shift == 32, low word",
4742 .u.insns_int = {
4743 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4744 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4745 BPF_ALU64_REG(BPF_RSH, R0, R1),
4746 BPF_EXIT_INSN(),
4747 },
4748 INTERNAL,
4749 { },
4750 { { 0, 0x81234567 } }
4751 },
4752 {
4753 "ALU64_RSH_X: Shift == 32, high word",
4754 .u.insns_int = {
4755 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4756 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4757 BPF_ALU64_REG(BPF_RSH, R0, R1),
4758 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4759 BPF_EXIT_INSN(),
4760 },
4761 INTERNAL,
4762 { },
4763 { { 0, 0 } }
4764 },
4765 {
4766 "ALU64_RSH_X: Zero shift, low word",
4767 .u.insns_int = {
4768 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4769 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4770 BPF_ALU64_REG(BPF_RSH, R0, R1),
4771 BPF_EXIT_INSN(),
4772 },
4773 INTERNAL,
4774 { },
4775 { { 0, 0x89abcdef } }
4776 },
4777 {
4778 "ALU64_RSH_X: Zero shift, high word",
4779 .u.insns_int = {
4780 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4781 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4782 BPF_ALU64_REG(BPF_RSH, R0, R1),
4783 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4784 BPF_EXIT_INSN(),
4785 },
4786 INTERNAL,
4787 { },
4788 { { 0, 0x81234567 } }
4789 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004790 /* BPF_ALU | BPF_RSH | BPF_K */
4791 {
4792 "ALU_RSH_K: 2 >> 1 = 1",
4793 .u.insns_int = {
4794 BPF_LD_IMM64(R0, 2),
4795 BPF_ALU32_IMM(BPF_RSH, R0, 1),
4796 BPF_EXIT_INSN(),
4797 },
4798 INTERNAL,
4799 { },
4800 { { 0, 1 } },
4801 },
4802 {
4803 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4804 .u.insns_int = {
4805 BPF_LD_IMM64(R0, 0x80000000),
4806 BPF_ALU32_IMM(BPF_RSH, R0, 31),
4807 BPF_EXIT_INSN(),
4808 },
4809 INTERNAL,
4810 { },
4811 { { 0, 1 } },
4812 },
4813 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004814 "ALU_RSH_K: 0x12345678 >> 20 = 0x123",
4815 .u.insns_int = {
4816 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4817 BPF_ALU32_IMM(BPF_RSH, R0, 20),
4818 BPF_EXIT_INSN(),
4819 },
4820 INTERNAL,
4821 { },
4822 { { 0, 0x123 } }
4823 },
4824 {
4825 "ALU_RSH_K: 0x12345678 >> 0 = 0x12345678",
4826 .u.insns_int = {
4827 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4828 BPF_ALU32_IMM(BPF_RSH, R0, 0),
4829 BPF_EXIT_INSN(),
4830 },
4831 INTERNAL,
4832 { },
4833 { { 0, 0x12345678 } }
4834 },
4835 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004836 "ALU64_RSH_K: 2 >> 1 = 1",
4837 .u.insns_int = {
4838 BPF_LD_IMM64(R0, 2),
4839 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4840 BPF_EXIT_INSN(),
4841 },
4842 INTERNAL,
4843 { },
4844 { { 0, 1 } },
4845 },
4846 {
4847 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4848 .u.insns_int = {
4849 BPF_LD_IMM64(R0, 0x80000000),
4850 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4851 BPF_EXIT_INSN(),
4852 },
4853 INTERNAL,
4854 { },
4855 { { 0, 1 } },
4856 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004857 {
4858 "ALU64_RSH_K: Shift < 32, low word",
4859 .u.insns_int = {
4860 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4861 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4862 BPF_EXIT_INSN(),
4863 },
4864 INTERNAL,
4865 { },
4866 { { 0, 0x56789abc } }
4867 },
4868 {
4869 "ALU64_RSH_K: Shift < 32, high word",
4870 .u.insns_int = {
4871 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4872 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4873 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4874 BPF_EXIT_INSN(),
4875 },
4876 INTERNAL,
4877 { },
4878 { { 0, 0x00081234 } }
4879 },
4880 {
4881 "ALU64_RSH_K: Shift > 32, low word",
4882 .u.insns_int = {
4883 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4884 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4885 BPF_EXIT_INSN(),
4886 },
4887 INTERNAL,
4888 { },
4889 { { 0, 0x08123456 } }
4890 },
4891 {
4892 "ALU64_RSH_K: Shift > 32, high word",
4893 .u.insns_int = {
4894 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4895 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4896 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4897 BPF_EXIT_INSN(),
4898 },
4899 INTERNAL,
4900 { },
4901 { { 0, 0 } }
4902 },
4903 {
4904 "ALU64_RSH_K: Shift == 32, low word",
4905 .u.insns_int = {
4906 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4907 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4908 BPF_EXIT_INSN(),
4909 },
4910 INTERNAL,
4911 { },
4912 { { 0, 0x81234567 } }
4913 },
4914 {
4915 "ALU64_RSH_K: Shift == 32, high word",
4916 .u.insns_int = {
4917 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4918 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4919 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4920 BPF_EXIT_INSN(),
4921 },
4922 INTERNAL,
4923 { },
4924 { { 0, 0 } }
4925 },
4926 {
4927 "ALU64_RSH_K: Zero shift",
4928 .u.insns_int = {
4929 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4930 BPF_ALU64_IMM(BPF_RSH, R0, 0),
4931 BPF_EXIT_INSN(),
4932 },
4933 INTERNAL,
4934 { },
4935 { { 0, 0x89abcdef } }
4936 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004937 /* BPF_ALU | BPF_ARSH | BPF_X */
4938 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004939 "ALU32_ARSH_X: -1234 >> 7 = -10",
4940 .u.insns_int = {
4941 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
4942 BPF_ALU32_IMM(BPF_MOV, R1, 7),
4943 BPF_ALU32_REG(BPF_ARSH, R0, R1),
4944 BPF_EXIT_INSN(),
4945 },
4946 INTERNAL,
4947 { },
4948 { { 0, -10 } }
4949 },
4950 {
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004951 "ALU64_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
Michael Holzheucffc6422015-05-11 22:22:44 -07004952 .u.insns_int = {
4953 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4954 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4955 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4956 BPF_EXIT_INSN(),
4957 },
4958 INTERNAL,
4959 { },
4960 { { 0, 0xffff00ff } },
4961 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004962 {
4963 "ALU64_ARSH_X: Shift < 32, low word",
4964 .u.insns_int = {
4965 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4966 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4967 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4968 BPF_EXIT_INSN(),
4969 },
4970 INTERNAL,
4971 { },
4972 { { 0, 0x56789abc } }
4973 },
4974 {
4975 "ALU64_ARSH_X: Shift < 32, high word",
4976 .u.insns_int = {
4977 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4978 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4979 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4980 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4981 BPF_EXIT_INSN(),
4982 },
4983 INTERNAL,
4984 { },
4985 { { 0, 0xfff81234 } }
4986 },
4987 {
4988 "ALU64_ARSH_X: Shift > 32, low word",
4989 .u.insns_int = {
4990 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4991 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4992 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4993 BPF_EXIT_INSN(),
4994 },
4995 INTERNAL,
4996 { },
4997 { { 0, 0xf8123456 } }
4998 },
4999 {
5000 "ALU64_ARSH_X: Shift > 32, high word",
5001 .u.insns_int = {
5002 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5003 BPF_ALU32_IMM(BPF_MOV, R1, 36),
5004 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5005 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5006 BPF_EXIT_INSN(),
5007 },
5008 INTERNAL,
5009 { },
5010 { { 0, -1 } }
5011 },
5012 {
5013 "ALU64_ARSH_X: Shift == 32, low word",
5014 .u.insns_int = {
5015 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5016 BPF_ALU32_IMM(BPF_MOV, R1, 32),
5017 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5018 BPF_EXIT_INSN(),
5019 },
5020 INTERNAL,
5021 { },
5022 { { 0, 0x81234567 } }
5023 },
5024 {
5025 "ALU64_ARSH_X: Shift == 32, high word",
5026 .u.insns_int = {
5027 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5028 BPF_ALU32_IMM(BPF_MOV, R1, 32),
5029 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5030 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5031 BPF_EXIT_INSN(),
5032 },
5033 INTERNAL,
5034 { },
5035 { { 0, -1 } }
5036 },
5037 {
5038 "ALU64_ARSH_X: Zero shift, low word",
5039 .u.insns_int = {
5040 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5041 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5042 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5043 BPF_EXIT_INSN(),
5044 },
5045 INTERNAL,
5046 { },
5047 { { 0, 0x89abcdef } }
5048 },
5049 {
5050 "ALU64_ARSH_X: Zero shift, high word",
5051 .u.insns_int = {
5052 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5053 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5054 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5055 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5056 BPF_EXIT_INSN(),
5057 },
5058 INTERNAL,
5059 { },
5060 { { 0, 0x81234567 } }
5061 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005062 /* BPF_ALU | BPF_ARSH | BPF_K */
5063 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02005064 "ALU32_ARSH_K: -1234 >> 7 = -10",
5065 .u.insns_int = {
5066 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5067 BPF_ALU32_IMM(BPF_ARSH, R0, 7),
5068 BPF_EXIT_INSN(),
5069 },
5070 INTERNAL,
5071 { },
5072 { { 0, -10 } }
5073 },
5074 {
5075 "ALU32_ARSH_K: -1234 >> 0 = -1234",
5076 .u.insns_int = {
5077 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5078 BPF_ALU32_IMM(BPF_ARSH, R0, 0),
5079 BPF_EXIT_INSN(),
5080 },
5081 INTERNAL,
5082 { },
5083 { { 0, -1234 } }
5084 },
5085 {
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005086 "ALU64_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
Michael Holzheucffc6422015-05-11 22:22:44 -07005087 .u.insns_int = {
5088 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
5089 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
5090 BPF_EXIT_INSN(),
5091 },
5092 INTERNAL,
5093 { },
5094 { { 0, 0xffff00ff } },
5095 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005096 {
5097 "ALU64_ARSH_K: Shift < 32, low word",
5098 .u.insns_int = {
5099 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5100 BPF_ALU64_IMM(BPF_RSH, R0, 12),
5101 BPF_EXIT_INSN(),
5102 },
5103 INTERNAL,
5104 { },
5105 { { 0, 0x56789abc } }
5106 },
5107 {
5108 "ALU64_ARSH_K: Shift < 32, high word",
5109 .u.insns_int = {
5110 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5111 BPF_ALU64_IMM(BPF_ARSH, R0, 12),
5112 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5113 BPF_EXIT_INSN(),
5114 },
5115 INTERNAL,
5116 { },
5117 { { 0, 0xfff81234 } }
5118 },
5119 {
5120 "ALU64_ARSH_K: Shift > 32, low word",
5121 .u.insns_int = {
5122 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5123 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5124 BPF_EXIT_INSN(),
5125 },
5126 INTERNAL,
5127 { },
5128 { { 0, 0xf8123456 } }
5129 },
5130 {
5131 "ALU64_ARSH_K: Shift > 32, high word",
5132 .u.insns_int = {
5133 BPF_LD_IMM64(R0, 0xf123456789abcdefLL),
5134 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5135 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5136 BPF_EXIT_INSN(),
5137 },
5138 INTERNAL,
5139 { },
5140 { { 0, -1 } }
5141 },
5142 {
5143 "ALU64_ARSH_K: Shift == 32, low word",
5144 .u.insns_int = {
5145 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5146 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5147 BPF_EXIT_INSN(),
5148 },
5149 INTERNAL,
5150 { },
5151 { { 0, 0x81234567 } }
5152 },
5153 {
5154 "ALU64_ARSH_K: Shift == 32, high word",
5155 .u.insns_int = {
5156 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5157 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5158 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5159 BPF_EXIT_INSN(),
5160 },
5161 INTERNAL,
5162 { },
5163 { { 0, -1 } }
5164 },
5165 {
5166 "ALU64_ARSH_K: Zero shoft",
5167 .u.insns_int = {
5168 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5169 BPF_ALU64_IMM(BPF_ARSH, R0, 0),
5170 BPF_EXIT_INSN(),
5171 },
5172 INTERNAL,
5173 { },
5174 { { 0, 0x89abcdef } }
5175 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005176 /* BPF_ALU | BPF_NEG */
5177 {
5178 "ALU_NEG: -(3) = -3",
5179 .u.insns_int = {
5180 BPF_ALU32_IMM(BPF_MOV, R0, 3),
5181 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5182 BPF_EXIT_INSN(),
5183 },
5184 INTERNAL,
5185 { },
5186 { { 0, -3 } },
5187 },
5188 {
5189 "ALU_NEG: -(-3) = 3",
5190 .u.insns_int = {
5191 BPF_ALU32_IMM(BPF_MOV, R0, -3),
5192 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5193 BPF_EXIT_INSN(),
5194 },
5195 INTERNAL,
5196 { },
5197 { { 0, 3 } },
5198 },
5199 {
5200 "ALU64_NEG: -(3) = -3",
5201 .u.insns_int = {
5202 BPF_LD_IMM64(R0, 3),
5203 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5204 BPF_EXIT_INSN(),
5205 },
5206 INTERNAL,
5207 { },
5208 { { 0, -3 } },
5209 },
5210 {
5211 "ALU64_NEG: -(-3) = 3",
5212 .u.insns_int = {
5213 BPF_LD_IMM64(R0, -3),
5214 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5215 BPF_EXIT_INSN(),
5216 },
5217 INTERNAL,
5218 { },
5219 { { 0, 3 } },
5220 },
5221 /* BPF_ALU | BPF_END | BPF_FROM_BE */
5222 {
5223 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
5224 .u.insns_int = {
5225 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5226 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
5227 BPF_EXIT_INSN(),
5228 },
5229 INTERNAL,
5230 { },
5231 { { 0, cpu_to_be16(0xcdef) } },
5232 },
5233 {
5234 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
5235 .u.insns_int = {
5236 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5237 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07005238 BPF_ALU64_REG(BPF_MOV, R1, R0),
5239 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5240 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07005241 BPF_EXIT_INSN(),
5242 },
5243 INTERNAL,
5244 { },
5245 { { 0, cpu_to_be32(0x89abcdef) } },
5246 },
5247 {
5248 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
5249 .u.insns_int = {
5250 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5251 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
5252 BPF_EXIT_INSN(),
5253 },
5254 INTERNAL,
5255 { },
5256 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
5257 },
5258 /* BPF_ALU | BPF_END | BPF_FROM_LE */
5259 {
5260 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
5261 .u.insns_int = {
5262 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5263 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
5264 BPF_EXIT_INSN(),
5265 },
5266 INTERNAL,
5267 { },
5268 { { 0, cpu_to_le16(0xcdef) } },
5269 },
5270 {
5271 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
5272 .u.insns_int = {
5273 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5274 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07005275 BPF_ALU64_REG(BPF_MOV, R1, R0),
5276 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5277 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07005278 BPF_EXIT_INSN(),
5279 },
5280 INTERNAL,
5281 { },
5282 { { 0, cpu_to_le32(0x89abcdef) } },
5283 },
5284 {
5285 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
5286 .u.insns_int = {
5287 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5288 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
5289 BPF_EXIT_INSN(),
5290 },
5291 INTERNAL,
5292 { },
5293 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
5294 },
5295 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
5296 {
5297 "ST_MEM_B: Store/Load byte: max negative",
5298 .u.insns_int = {
5299 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5300 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
5301 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5302 BPF_EXIT_INSN(),
5303 },
5304 INTERNAL,
5305 { },
5306 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005307 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005308 },
5309 {
5310 "ST_MEM_B: Store/Load byte: max positive",
5311 .u.insns_int = {
5312 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5313 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
5314 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5315 BPF_EXIT_INSN(),
5316 },
5317 INTERNAL,
5318 { },
5319 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005320 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005321 },
5322 {
5323 "STX_MEM_B: Store/Load byte: max negative",
5324 .u.insns_int = {
5325 BPF_LD_IMM64(R0, 0),
5326 BPF_LD_IMM64(R1, 0xffLL),
5327 BPF_STX_MEM(BPF_B, R10, R1, -40),
5328 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5329 BPF_EXIT_INSN(),
5330 },
5331 INTERNAL,
5332 { },
5333 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005334 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005335 },
5336 {
5337 "ST_MEM_H: Store/Load half word: max negative",
5338 .u.insns_int = {
5339 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5340 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
5341 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5342 BPF_EXIT_INSN(),
5343 },
5344 INTERNAL,
5345 { },
5346 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005347 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005348 },
5349 {
5350 "ST_MEM_H: Store/Load half word: max positive",
5351 .u.insns_int = {
5352 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5353 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
5354 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5355 BPF_EXIT_INSN(),
5356 },
5357 INTERNAL,
5358 { },
5359 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005360 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005361 },
5362 {
5363 "STX_MEM_H: Store/Load half word: max negative",
5364 .u.insns_int = {
5365 BPF_LD_IMM64(R0, 0),
5366 BPF_LD_IMM64(R1, 0xffffLL),
5367 BPF_STX_MEM(BPF_H, R10, R1, -40),
5368 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5369 BPF_EXIT_INSN(),
5370 },
5371 INTERNAL,
5372 { },
5373 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005374 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005375 },
5376 {
5377 "ST_MEM_W: Store/Load word: max negative",
5378 .u.insns_int = {
5379 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5380 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
5381 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5382 BPF_EXIT_INSN(),
5383 },
5384 INTERNAL,
5385 { },
5386 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005387 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005388 },
5389 {
5390 "ST_MEM_W: Store/Load word: max positive",
5391 .u.insns_int = {
5392 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5393 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
5394 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5395 BPF_EXIT_INSN(),
5396 },
5397 INTERNAL,
5398 { },
5399 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005400 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005401 },
5402 {
5403 "STX_MEM_W: Store/Load word: max negative",
5404 .u.insns_int = {
5405 BPF_LD_IMM64(R0, 0),
5406 BPF_LD_IMM64(R1, 0xffffffffLL),
5407 BPF_STX_MEM(BPF_W, R10, R1, -40),
5408 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5409 BPF_EXIT_INSN(),
5410 },
5411 INTERNAL,
5412 { },
5413 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005414 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005415 },
5416 {
5417 "ST_MEM_DW: Store/Load double word: max negative",
5418 .u.insns_int = {
5419 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5420 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5421 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5422 BPF_EXIT_INSN(),
5423 },
5424 INTERNAL,
5425 { },
5426 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005427 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005428 },
5429 {
5430 "ST_MEM_DW: Store/Load double word: max negative 2",
5431 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07005432 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
5433 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07005434 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5435 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
5436 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5437 BPF_MOV32_IMM(R0, 2),
5438 BPF_EXIT_INSN(),
5439 BPF_MOV32_IMM(R0, 1),
5440 BPF_EXIT_INSN(),
5441 },
5442 INTERNAL,
5443 { },
5444 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005445 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005446 },
5447 {
5448 "ST_MEM_DW: Store/Load double word: max positive",
5449 .u.insns_int = {
5450 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5451 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
5452 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5453 BPF_EXIT_INSN(),
5454 },
5455 INTERNAL,
5456 { },
5457 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005458 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005459 },
5460 {
5461 "STX_MEM_DW: Store/Load double word: max negative",
5462 .u.insns_int = {
5463 BPF_LD_IMM64(R0, 0),
5464 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
Johan Almbladhae7f4702021-07-21 12:40:58 +02005465 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5466 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07005467 BPF_EXIT_INSN(),
5468 },
5469 INTERNAL,
5470 { },
5471 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005472 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005473 },
Johan Almbladhe5009b42021-08-09 11:18:24 +02005474 {
5475 "STX_MEM_DW: Store double word: first word in memory",
5476 .u.insns_int = {
5477 BPF_LD_IMM64(R0, 0),
5478 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5479 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5480 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5481 BPF_EXIT_INSN(),
5482 },
5483 INTERNAL,
5484 { },
5485#ifdef __BIG_ENDIAN
5486 { { 0, 0x01234567 } },
5487#else
5488 { { 0, 0x89abcdef } },
5489#endif
5490 .stack_depth = 40,
5491 },
5492 {
5493 "STX_MEM_DW: Store double word: second word in memory",
5494 .u.insns_int = {
5495 BPF_LD_IMM64(R0, 0),
5496 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5497 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5498 BPF_LDX_MEM(BPF_W, R0, R10, -36),
5499 BPF_EXIT_INSN(),
5500 },
5501 INTERNAL,
5502 { },
5503#ifdef __BIG_ENDIAN
5504 { { 0, 0x89abcdef } },
5505#else
5506 { { 0, 0x01234567 } },
5507#endif
5508 .stack_depth = 40,
5509 },
Brendan Jackman91c960b2021-01-14 18:17:44 +00005510 /* BPF_STX | BPF_ATOMIC | BPF_W/DW */
Michael Holzheucffc6422015-05-11 22:22:44 -07005511 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005512 "STX_XADD_W: X + 1 + 1 + 1 + ...",
5513 { },
5514 INTERNAL,
5515 { },
5516 { { 0, 4134 } },
5517 .fill_helper = bpf_fill_stxw,
5518 },
5519 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005520 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
5521 { },
5522 INTERNAL,
5523 { },
5524 { { 0, 4134 } },
5525 .fill_helper = bpf_fill_stxdw,
5526 },
Johan Almbladhe4517b32021-08-09 11:18:27 +02005527 /*
5528 * Exhaustive tests of atomic operation variants.
5529 * Individual tests are expanded from template macros for all
5530 * combinations of ALU operation, word size and fetching.
5531 */
5532#define BPF_ATOMIC_OP_TEST1(width, op, logic, old, update, result) \
5533{ \
5534 "BPF_ATOMIC | " #width ", " #op ": Test: " \
5535 #old " " #logic " " #update " = " #result, \
5536 .u.insns_int = { \
5537 BPF_ALU32_IMM(BPF_MOV, R5, update), \
5538 BPF_ST_MEM(width, R10, -40, old), \
5539 BPF_ATOMIC_OP(width, op, R10, R5, -40), \
5540 BPF_LDX_MEM(width, R0, R10, -40), \
5541 BPF_EXIT_INSN(), \
5542 }, \
5543 INTERNAL, \
5544 { }, \
5545 { { 0, result } }, \
5546 .stack_depth = 40, \
5547}
5548#define BPF_ATOMIC_OP_TEST2(width, op, logic, old, update, result) \
5549{ \
5550 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r10: " \
5551 #old " " #logic " " #update " = " #result, \
5552 .u.insns_int = { \
5553 BPF_ALU64_REG(BPF_MOV, R1, R10), \
5554 BPF_ALU32_IMM(BPF_MOV, R0, update), \
5555 BPF_ST_MEM(BPF_W, R10, -40, old), \
5556 BPF_ATOMIC_OP(width, op, R10, R0, -40), \
5557 BPF_ALU64_REG(BPF_MOV, R0, R10), \
5558 BPF_ALU64_REG(BPF_SUB, R0, R1), \
5559 BPF_EXIT_INSN(), \
5560 }, \
5561 INTERNAL, \
5562 { }, \
5563 { { 0, 0 } }, \
5564 .stack_depth = 40, \
5565}
5566#define BPF_ATOMIC_OP_TEST3(width, op, logic, old, update, result) \
5567{ \
5568 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r0: " \
5569 #old " " #logic " " #update " = " #result, \
5570 .u.insns_int = { \
5571 BPF_ALU64_REG(BPF_MOV, R0, R10), \
5572 BPF_ALU32_IMM(BPF_MOV, R1, update), \
5573 BPF_ST_MEM(width, R10, -40, old), \
5574 BPF_ATOMIC_OP(width, op, R10, R1, -40), \
5575 BPF_ALU64_REG(BPF_SUB, R0, R10), \
5576 BPF_EXIT_INSN(), \
5577 }, \
5578 INTERNAL, \
5579 { }, \
5580 { { 0, 0 } }, \
5581 .stack_depth = 40, \
5582}
5583#define BPF_ATOMIC_OP_TEST4(width, op, logic, old, update, result) \
5584{ \
5585 "BPF_ATOMIC | " #width ", " #op ": Test fetch: " \
5586 #old " " #logic " " #update " = " #result, \
5587 .u.insns_int = { \
5588 BPF_ALU32_IMM(BPF_MOV, R3, update), \
5589 BPF_ST_MEM(width, R10, -40, old), \
5590 BPF_ATOMIC_OP(width, op, R10, R3, -40), \
5591 BPF_ALU64_REG(BPF_MOV, R0, R3), \
5592 BPF_EXIT_INSN(), \
5593 }, \
5594 INTERNAL, \
5595 { }, \
5596 { { 0, (op) & BPF_FETCH ? old : update } }, \
5597 .stack_depth = 40, \
5598}
5599 /* BPF_ATOMIC | BPF_W: BPF_ADD */
5600 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5601 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5602 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5603 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5604 /* BPF_ATOMIC | BPF_W: BPF_ADD | BPF_FETCH */
5605 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5606 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5607 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5608 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5609 /* BPF_ATOMIC | BPF_DW: BPF_ADD */
5610 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5611 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5612 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5613 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5614 /* BPF_ATOMIC | BPF_DW: BPF_ADD | BPF_FETCH */
5615 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5616 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5617 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5618 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5619 /* BPF_ATOMIC | BPF_W: BPF_AND */
5620 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5621 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5622 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5623 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5624 /* BPF_ATOMIC | BPF_W: BPF_AND | BPF_FETCH */
5625 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5626 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5627 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5628 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5629 /* BPF_ATOMIC | BPF_DW: BPF_AND */
5630 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5631 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5632 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5633 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5634 /* BPF_ATOMIC | BPF_DW: BPF_AND | BPF_FETCH */
5635 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5636 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5637 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5638 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5639 /* BPF_ATOMIC | BPF_W: BPF_OR */
5640 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5641 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5642 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5643 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5644 /* BPF_ATOMIC | BPF_W: BPF_OR | BPF_FETCH */
5645 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5646 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5647 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5648 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5649 /* BPF_ATOMIC | BPF_DW: BPF_OR */
5650 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5651 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5652 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5653 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5654 /* BPF_ATOMIC | BPF_DW: BPF_OR | BPF_FETCH */
5655 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5656 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5657 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5658 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5659 /* BPF_ATOMIC | BPF_W: BPF_XOR */
5660 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5661 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5662 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5663 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5664 /* BPF_ATOMIC | BPF_W: BPF_XOR | BPF_FETCH */
5665 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5666 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5667 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5668 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5669 /* BPF_ATOMIC | BPF_DW: BPF_XOR */
5670 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5671 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5672 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5673 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5674 /* BPF_ATOMIC | BPF_DW: BPF_XOR | BPF_FETCH */
5675 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5676 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5677 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5678 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5679 /* BPF_ATOMIC | BPF_W: BPF_XCHG */
5680 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5681 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5682 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5683 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5684 /* BPF_ATOMIC | BPF_DW: BPF_XCHG */
5685 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5686 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5687 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5688 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5689#undef BPF_ATOMIC_OP_TEST1
5690#undef BPF_ATOMIC_OP_TEST2
5691#undef BPF_ATOMIC_OP_TEST3
5692#undef BPF_ATOMIC_OP_TEST4
Johan Almbladhb55dfa82021-08-09 11:18:16 +02005693 /* BPF_JMP32 | BPF_JEQ | BPF_K */
5694 {
5695 "JMP32_JEQ_K: Small immediate",
5696 .u.insns_int = {
5697 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5698 BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
5699 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5700 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5701 BPF_EXIT_INSN(),
5702 },
5703 INTERNAL,
5704 { },
5705 { { 0, 123 } }
5706 },
5707 {
5708 "JMP32_JEQ_K: Large immediate",
5709 .u.insns_int = {
5710 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5711 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1),
5712 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1),
5713 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5714 BPF_EXIT_INSN(),
5715 },
5716 INTERNAL,
5717 { },
5718 { { 0, 12345678 } }
5719 },
5720 {
5721 "JMP32_JEQ_K: negative immediate",
5722 .u.insns_int = {
5723 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5724 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5725 BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1),
5726 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5727 BPF_EXIT_INSN(),
5728 },
5729 INTERNAL,
5730 { },
5731 { { 0, -123 } }
5732 },
5733 /* BPF_JMP32 | BPF_JEQ | BPF_X */
5734 {
5735 "JMP32_JEQ_X",
5736 .u.insns_int = {
5737 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5738 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5739 BPF_JMP32_REG(BPF_JEQ, R0, R1, 2),
5740 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5741 BPF_JMP32_REG(BPF_JEQ, R0, R1, 1),
5742 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5743 BPF_EXIT_INSN(),
5744 },
5745 INTERNAL,
5746 { },
5747 { { 0, 1234 } }
5748 },
5749 /* BPF_JMP32 | BPF_JNE | BPF_K */
5750 {
5751 "JMP32_JNE_K: Small immediate",
5752 .u.insns_int = {
5753 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5754 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5755 BPF_JMP32_IMM(BPF_JNE, R0, 321, 1),
5756 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5757 BPF_EXIT_INSN(),
5758 },
5759 INTERNAL,
5760 { },
5761 { { 0, 123 } }
5762 },
5763 {
5764 "JMP32_JNE_K: Large immediate",
5765 .u.insns_int = {
5766 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5767 BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1),
5768 BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1),
5769 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5770 BPF_EXIT_INSN(),
5771 },
5772 INTERNAL,
5773 { },
5774 { { 0, 12345678 } }
5775 },
5776 {
5777 "JMP32_JNE_K: negative immediate",
5778 .u.insns_int = {
5779 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5780 BPF_JMP32_IMM(BPF_JNE, R0, -123, 1),
5781 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5782 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5783 BPF_EXIT_INSN(),
5784 },
5785 INTERNAL,
5786 { },
5787 { { 0, -123 } }
5788 },
5789 /* BPF_JMP32 | BPF_JNE | BPF_X */
5790 {
5791 "JMP32_JNE_X",
5792 .u.insns_int = {
5793 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5794 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5795 BPF_JMP32_REG(BPF_JNE, R0, R1, 2),
5796 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5797 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
5798 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5799 BPF_EXIT_INSN(),
5800 },
5801 INTERNAL,
5802 { },
5803 { { 0, 1234 } }
5804 },
5805 /* BPF_JMP32 | BPF_JSET | BPF_K */
5806 {
5807 "JMP32_JSET_K: Small immediate",
5808 .u.insns_int = {
5809 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5810 BPF_JMP32_IMM(BPF_JSET, R0, 2, 1),
5811 BPF_JMP32_IMM(BPF_JSET, R0, 3, 1),
5812 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5813 BPF_EXIT_INSN(),
5814 },
5815 INTERNAL,
5816 { },
5817 { { 0, 1 } }
5818 },
5819 {
5820 "JMP32_JSET_K: Large immediate",
5821 .u.insns_int = {
5822 BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000),
5823 BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1),
5824 BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1),
5825 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5826 BPF_EXIT_INSN(),
5827 },
5828 INTERNAL,
5829 { },
5830 { { 0, 0x40000000 } }
5831 },
5832 {
5833 "JMP32_JSET_K: negative immediate",
5834 .u.insns_int = {
5835 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5836 BPF_JMP32_IMM(BPF_JSET, R0, -1, 1),
5837 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5838 BPF_EXIT_INSN(),
5839 },
5840 INTERNAL,
5841 { },
5842 { { 0, -123 } }
5843 },
5844 /* BPF_JMP32 | BPF_JSET | BPF_X */
5845 {
5846 "JMP32_JSET_X",
5847 .u.insns_int = {
5848 BPF_ALU32_IMM(BPF_MOV, R0, 8),
5849 BPF_ALU32_IMM(BPF_MOV, R1, 7),
5850 BPF_JMP32_REG(BPF_JSET, R0, R1, 2),
5851 BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2),
5852 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
5853 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5854 BPF_EXIT_INSN(),
5855 },
5856 INTERNAL,
5857 { },
5858 { { 0, 8 } }
5859 },
5860 /* BPF_JMP32 | BPF_JGT | BPF_K */
5861 {
5862 "JMP32_JGT_K: Small immediate",
5863 .u.insns_int = {
5864 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5865 BPF_JMP32_IMM(BPF_JGT, R0, 123, 1),
5866 BPF_JMP32_IMM(BPF_JGT, R0, 122, 1),
5867 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5868 BPF_EXIT_INSN(),
5869 },
5870 INTERNAL,
5871 { },
5872 { { 0, 123 } }
5873 },
5874 {
5875 "JMP32_JGT_K: Large immediate",
5876 .u.insns_int = {
5877 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5878 BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1),
5879 BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1),
5880 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5881 BPF_EXIT_INSN(),
5882 },
5883 INTERNAL,
5884 { },
5885 { { 0, 0xfffffffe } }
5886 },
5887 /* BPF_JMP32 | BPF_JGT | BPF_X */
5888 {
5889 "JMP32_JGT_X",
5890 .u.insns_int = {
5891 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5892 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
5893 BPF_JMP32_REG(BPF_JGT, R0, R1, 2),
5894 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
5895 BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
5896 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5897 BPF_EXIT_INSN(),
5898 },
5899 INTERNAL,
5900 { },
5901 { { 0, 0xfffffffe } }
5902 },
5903 /* BPF_JMP32 | BPF_JGE | BPF_K */
5904 {
5905 "JMP32_JGE_K: Small immediate",
5906 .u.insns_int = {
5907 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5908 BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
5909 BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
5910 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5911 BPF_EXIT_INSN(),
5912 },
5913 INTERNAL,
5914 { },
5915 { { 0, 123 } }
5916 },
5917 {
5918 "JMP32_JGE_K: Large immediate",
5919 .u.insns_int = {
5920 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5921 BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
5922 BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
5923 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5924 BPF_EXIT_INSN(),
5925 },
5926 INTERNAL,
5927 { },
5928 { { 0, 0xfffffffe } }
5929 },
5930 /* BPF_JMP32 | BPF_JGE | BPF_X */
5931 {
5932 "JMP32_JGE_X",
5933 .u.insns_int = {
5934 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5935 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
5936 BPF_JMP32_REG(BPF_JGE, R0, R1, 2),
5937 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
5938 BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
5939 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5940 BPF_EXIT_INSN(),
5941 },
5942 INTERNAL,
5943 { },
5944 { { 0, 0xfffffffe } }
5945 },
5946 /* BPF_JMP32 | BPF_JLT | BPF_K */
5947 {
5948 "JMP32_JLT_K: Small immediate",
5949 .u.insns_int = {
5950 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5951 BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
5952 BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
5953 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5954 BPF_EXIT_INSN(),
5955 },
5956 INTERNAL,
5957 { },
5958 { { 0, 123 } }
5959 },
5960 {
5961 "JMP32_JLT_K: Large immediate",
5962 .u.insns_int = {
5963 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5964 BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
5965 BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
5966 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5967 BPF_EXIT_INSN(),
5968 },
5969 INTERNAL,
5970 { },
5971 { { 0, 0xfffffffe } }
5972 },
5973 /* BPF_JMP32 | BPF_JLT | BPF_X */
5974 {
5975 "JMP32_JLT_X",
5976 .u.insns_int = {
5977 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5978 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
5979 BPF_JMP32_REG(BPF_JLT, R0, R1, 2),
5980 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
5981 BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
5982 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5983 BPF_EXIT_INSN(),
5984 },
5985 INTERNAL,
5986 { },
5987 { { 0, 0xfffffffe } }
5988 },
5989 /* BPF_JMP32 | BPF_JLE | BPF_K */
5990 {
5991 "JMP32_JLE_K: Small immediate",
5992 .u.insns_int = {
5993 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5994 BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
5995 BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
5996 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5997 BPF_EXIT_INSN(),
5998 },
5999 INTERNAL,
6000 { },
6001 { { 0, 123 } }
6002 },
6003 {
6004 "JMP32_JLE_K: Large immediate",
6005 .u.insns_int = {
6006 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6007 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
6008 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
6009 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6010 BPF_EXIT_INSN(),
6011 },
6012 INTERNAL,
6013 { },
6014 { { 0, 0xfffffffe } }
6015 },
6016 /* BPF_JMP32 | BPF_JLE | BPF_X */
6017 {
6018 "JMP32_JLE_X",
6019 .u.insns_int = {
6020 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6021 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6022 BPF_JMP32_REG(BPF_JLE, R0, R1, 2),
6023 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
6024 BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
6025 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6026 BPF_EXIT_INSN(),
6027 },
6028 INTERNAL,
6029 { },
6030 { { 0, 0xfffffffe } }
6031 },
6032 /* BPF_JMP32 | BPF_JSGT | BPF_K */
6033 {
6034 "JMP32_JSGT_K: Small immediate",
6035 .u.insns_int = {
6036 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6037 BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
6038 BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
6039 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6040 BPF_EXIT_INSN(),
6041 },
6042 INTERNAL,
6043 { },
6044 { { 0, -123 } }
6045 },
6046 {
6047 "JMP32_JSGT_K: Large immediate",
6048 .u.insns_int = {
6049 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6050 BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
6051 BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
6052 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6053 BPF_EXIT_INSN(),
6054 },
6055 INTERNAL,
6056 { },
6057 { { 0, -12345678 } }
6058 },
6059 /* BPF_JMP32 | BPF_JSGT | BPF_X */
6060 {
6061 "JMP32_JSGT_X",
6062 .u.insns_int = {
6063 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6064 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6065 BPF_JMP32_REG(BPF_JSGT, R0, R1, 2),
6066 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6067 BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
6068 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6069 BPF_EXIT_INSN(),
6070 },
6071 INTERNAL,
6072 { },
6073 { { 0, -12345678 } }
6074 },
6075 /* BPF_JMP32 | BPF_JSGE | BPF_K */
6076 {
6077 "JMP32_JSGE_K: Small immediate",
6078 .u.insns_int = {
6079 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6080 BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
6081 BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
6082 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6083 BPF_EXIT_INSN(),
6084 },
6085 INTERNAL,
6086 { },
6087 { { 0, -123 } }
6088 },
6089 {
6090 "JMP32_JSGE_K: Large immediate",
6091 .u.insns_int = {
6092 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6093 BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
6094 BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
6095 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6096 BPF_EXIT_INSN(),
6097 },
6098 INTERNAL,
6099 { },
6100 { { 0, -12345678 } }
6101 },
6102 /* BPF_JMP32 | BPF_JSGE | BPF_X */
6103 {
6104 "JMP32_JSGE_X",
6105 .u.insns_int = {
6106 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6107 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6108 BPF_JMP32_REG(BPF_JSGE, R0, R1, 2),
6109 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6110 BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
6111 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6112 BPF_EXIT_INSN(),
6113 },
6114 INTERNAL,
6115 { },
6116 { { 0, -12345678 } }
6117 },
6118 /* BPF_JMP32 | BPF_JSLT | BPF_K */
6119 {
6120 "JMP32_JSLT_K: Small immediate",
6121 .u.insns_int = {
6122 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6123 BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
6124 BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
6125 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6126 BPF_EXIT_INSN(),
6127 },
6128 INTERNAL,
6129 { },
6130 { { 0, -123 } }
6131 },
6132 {
6133 "JMP32_JSLT_K: Large immediate",
6134 .u.insns_int = {
6135 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6136 BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
6137 BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
6138 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6139 BPF_EXIT_INSN(),
6140 },
6141 INTERNAL,
6142 { },
6143 { { 0, -12345678 } }
6144 },
6145 /* BPF_JMP32 | BPF_JSLT | BPF_X */
6146 {
6147 "JMP32_JSLT_X",
6148 .u.insns_int = {
6149 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6150 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6151 BPF_JMP32_REG(BPF_JSLT, R0, R1, 2),
6152 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6153 BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
6154 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6155 BPF_EXIT_INSN(),
6156 },
6157 INTERNAL,
6158 { },
6159 { { 0, -12345678 } }
6160 },
6161 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6162 {
6163 "JMP32_JSLE_K: Small immediate",
6164 .u.insns_int = {
6165 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6166 BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
6167 BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
6168 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6169 BPF_EXIT_INSN(),
6170 },
6171 INTERNAL,
6172 { },
6173 { { 0, -123 } }
6174 },
6175 {
6176 "JMP32_JSLE_K: Large immediate",
6177 .u.insns_int = {
6178 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6179 BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
6180 BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
6181 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6182 BPF_EXIT_INSN(),
6183 },
6184 INTERNAL,
6185 { },
6186 { { 0, -12345678 } }
6187 },
6188 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6189 {
6190 "JMP32_JSLE_X",
6191 .u.insns_int = {
6192 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6193 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6194 BPF_JMP32_REG(BPF_JSLE, R0, R1, 2),
6195 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6196 BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
6197 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6198 BPF_EXIT_INSN(),
6199 },
6200 INTERNAL,
6201 { },
6202 { { 0, -12345678 } }
6203 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006204 /* BPF_JMP | BPF_EXIT */
6205 {
6206 "JMP_EXIT",
6207 .u.insns_int = {
6208 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
6209 BPF_EXIT_INSN(),
6210 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
6211 },
6212 INTERNAL,
6213 { },
6214 { { 0, 0x4711 } },
6215 },
6216 /* BPF_JMP | BPF_JA */
6217 {
6218 "JMP_JA: Unconditional jump: if (true) return 1",
6219 .u.insns_int = {
6220 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6221 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
6222 BPF_EXIT_INSN(),
6223 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6224 BPF_EXIT_INSN(),
6225 },
6226 INTERNAL,
6227 { },
6228 { { 0, 1 } },
6229 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006230 /* BPF_JMP | BPF_JSLT | BPF_K */
6231 {
6232 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
6233 .u.insns_int = {
6234 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6235 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6236 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6237 BPF_EXIT_INSN(),
6238 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6239 BPF_EXIT_INSN(),
6240 },
6241 INTERNAL,
6242 { },
6243 { { 0, 1 } },
6244 },
6245 {
6246 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
6247 .u.insns_int = {
6248 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6249 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6250 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6251 BPF_EXIT_INSN(),
6252 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6253 BPF_EXIT_INSN(),
6254 },
6255 INTERNAL,
6256 { },
6257 { { 0, 1 } },
6258 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006259 /* BPF_JMP | BPF_JSGT | BPF_K */
6260 {
6261 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
6262 .u.insns_int = {
6263 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6264 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6265 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
6266 BPF_EXIT_INSN(),
6267 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6268 BPF_EXIT_INSN(),
6269 },
6270 INTERNAL,
6271 { },
6272 { { 0, 1 } },
6273 },
6274 {
6275 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
6276 .u.insns_int = {
6277 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6278 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6279 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
6280 BPF_EXIT_INSN(),
6281 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6282 BPF_EXIT_INSN(),
6283 },
6284 INTERNAL,
6285 { },
6286 { { 0, 1 } },
6287 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006288 /* BPF_JMP | BPF_JSLE | BPF_K */
6289 {
6290 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
6291 .u.insns_int = {
6292 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6293 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6294 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6295 BPF_EXIT_INSN(),
6296 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6297 BPF_EXIT_INSN(),
6298 },
6299 INTERNAL,
6300 { },
6301 { { 0, 1 } },
6302 },
6303 {
6304 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
6305 .u.insns_int = {
6306 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6307 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6308 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6309 BPF_EXIT_INSN(),
6310 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6311 BPF_EXIT_INSN(),
6312 },
6313 INTERNAL,
6314 { },
6315 { { 0, 1 } },
6316 },
6317 {
6318 "JMP_JSLE_K: Signed jump: value walk 1",
6319 .u.insns_int = {
6320 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6321 BPF_LD_IMM64(R1, 3),
6322 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
6323 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6324 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6325 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6326 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6327 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6328 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6329 BPF_EXIT_INSN(), /* bad exit */
6330 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6331 BPF_EXIT_INSN(),
6332 },
6333 INTERNAL,
6334 { },
6335 { { 0, 1 } },
6336 },
6337 {
6338 "JMP_JSLE_K: Signed jump: value walk 2",
6339 .u.insns_int = {
6340 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6341 BPF_LD_IMM64(R1, 3),
6342 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6343 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6344 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6345 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6346 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6347 BPF_EXIT_INSN(), /* bad exit */
6348 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6349 BPF_EXIT_INSN(),
6350 },
6351 INTERNAL,
6352 { },
6353 { { 0, 1 } },
6354 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006355 /* BPF_JMP | BPF_JSGE | BPF_K */
6356 {
6357 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
6358 .u.insns_int = {
6359 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6360 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6361 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
6362 BPF_EXIT_INSN(),
6363 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6364 BPF_EXIT_INSN(),
6365 },
6366 INTERNAL,
6367 { },
6368 { { 0, 1 } },
6369 },
6370 {
6371 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
6372 .u.insns_int = {
6373 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6374 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6375 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
6376 BPF_EXIT_INSN(),
6377 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6378 BPF_EXIT_INSN(),
6379 },
6380 INTERNAL,
6381 { },
6382 { { 0, 1 } },
6383 },
David Daney791caeb2017-05-24 16:35:49 -07006384 {
6385 "JMP_JSGE_K: Signed jump: value walk 1",
6386 .u.insns_int = {
6387 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6388 BPF_LD_IMM64(R1, -3),
6389 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
6390 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6391 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6392 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6393 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6394 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6395 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6396 BPF_EXIT_INSN(), /* bad exit */
6397 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6398 BPF_EXIT_INSN(),
6399 },
6400 INTERNAL,
6401 { },
6402 { { 0, 1 } },
6403 },
6404 {
6405 "JMP_JSGE_K: Signed jump: value walk 2",
6406 .u.insns_int = {
6407 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6408 BPF_LD_IMM64(R1, -3),
6409 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6410 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6411 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6412 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6413 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6414 BPF_EXIT_INSN(), /* bad exit */
6415 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6416 BPF_EXIT_INSN(),
6417 },
6418 INTERNAL,
6419 { },
6420 { { 0, 1 } },
6421 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006422 /* BPF_JMP | BPF_JGT | BPF_K */
6423 {
6424 "JMP_JGT_K: if (3 > 2) return 1",
6425 .u.insns_int = {
6426 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6427 BPF_LD_IMM64(R1, 3),
6428 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
6429 BPF_EXIT_INSN(),
6430 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6431 BPF_EXIT_INSN(),
6432 },
6433 INTERNAL,
6434 { },
6435 { { 0, 1 } },
6436 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05306437 {
6438 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
6439 .u.insns_int = {
6440 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6441 BPF_LD_IMM64(R1, -1),
6442 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
6443 BPF_EXIT_INSN(),
6444 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6445 BPF_EXIT_INSN(),
6446 },
6447 INTERNAL,
6448 { },
6449 { { 0, 1 } },
6450 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006451 /* BPF_JMP | BPF_JLT | BPF_K */
6452 {
6453 "JMP_JLT_K: if (2 < 3) return 1",
6454 .u.insns_int = {
6455 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6456 BPF_LD_IMM64(R1, 2),
6457 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
6458 BPF_EXIT_INSN(),
6459 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6460 BPF_EXIT_INSN(),
6461 },
6462 INTERNAL,
6463 { },
6464 { { 0, 1 } },
6465 },
6466 {
6467 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
6468 .u.insns_int = {
6469 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6470 BPF_LD_IMM64(R1, 1),
6471 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
6472 BPF_EXIT_INSN(),
6473 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6474 BPF_EXIT_INSN(),
6475 },
6476 INTERNAL,
6477 { },
6478 { { 0, 1 } },
6479 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006480 /* BPF_JMP | BPF_JGE | BPF_K */
6481 {
6482 "JMP_JGE_K: if (3 >= 2) return 1",
6483 .u.insns_int = {
6484 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6485 BPF_LD_IMM64(R1, 3),
6486 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
6487 BPF_EXIT_INSN(),
6488 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6489 BPF_EXIT_INSN(),
6490 },
6491 INTERNAL,
6492 { },
6493 { { 0, 1 } },
6494 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006495 /* BPF_JMP | BPF_JLE | BPF_K */
6496 {
6497 "JMP_JLE_K: if (2 <= 3) return 1",
6498 .u.insns_int = {
6499 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6500 BPF_LD_IMM64(R1, 2),
6501 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6502 BPF_EXIT_INSN(),
6503 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6504 BPF_EXIT_INSN(),
6505 },
6506 INTERNAL,
6507 { },
6508 { { 0, 1 } },
6509 },
Michael Holzheufe593842015-05-22 08:36:40 -07006510 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
6511 {
6512 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
6513 .u.insns_int = {
6514 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6515 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6516 BPF_EXIT_INSN(),
6517 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6518 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
6519 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
6520 BPF_EXIT_INSN(),
6521 },
6522 INTERNAL,
6523 { },
6524 { { 0, 1 } },
6525 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006526 {
6527 "JMP_JGE_K: if (3 >= 3) return 1",
6528 .u.insns_int = {
6529 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6530 BPF_LD_IMM64(R1, 3),
6531 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
6532 BPF_EXIT_INSN(),
6533 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6534 BPF_EXIT_INSN(),
6535 },
6536 INTERNAL,
6537 { },
6538 { { 0, 1 } },
6539 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006540 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
6541 {
6542 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
6543 .u.insns_int = {
6544 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6545 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6546 BPF_EXIT_INSN(),
6547 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6548 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
6549 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
6550 BPF_EXIT_INSN(),
6551 },
6552 INTERNAL,
6553 { },
6554 { { 0, 1 } },
6555 },
6556 {
6557 "JMP_JLE_K: if (3 <= 3) return 1",
6558 .u.insns_int = {
6559 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6560 BPF_LD_IMM64(R1, 3),
6561 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6562 BPF_EXIT_INSN(),
6563 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6564 BPF_EXIT_INSN(),
6565 },
6566 INTERNAL,
6567 { },
6568 { { 0, 1 } },
6569 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006570 /* BPF_JMP | BPF_JNE | BPF_K */
6571 {
6572 "JMP_JNE_K: if (3 != 2) return 1",
6573 .u.insns_int = {
6574 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6575 BPF_LD_IMM64(R1, 3),
6576 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
6577 BPF_EXIT_INSN(),
6578 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6579 BPF_EXIT_INSN(),
6580 },
6581 INTERNAL,
6582 { },
6583 { { 0, 1 } },
6584 },
6585 /* BPF_JMP | BPF_JEQ | BPF_K */
6586 {
6587 "JMP_JEQ_K: if (3 == 3) return 1",
6588 .u.insns_int = {
6589 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6590 BPF_LD_IMM64(R1, 3),
6591 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
6592 BPF_EXIT_INSN(),
6593 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6594 BPF_EXIT_INSN(),
6595 },
6596 INTERNAL,
6597 { },
6598 { { 0, 1 } },
6599 },
6600 /* BPF_JMP | BPF_JSET | BPF_K */
6601 {
6602 "JMP_JSET_K: if (0x3 & 0x2) return 1",
6603 .u.insns_int = {
6604 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6605 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306606 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006607 BPF_EXIT_INSN(),
6608 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6609 BPF_EXIT_INSN(),
6610 },
6611 INTERNAL,
6612 { },
6613 { { 0, 1 } },
6614 },
6615 {
6616 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
6617 .u.insns_int = {
6618 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6619 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306620 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006621 BPF_EXIT_INSN(),
6622 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6623 BPF_EXIT_INSN(),
6624 },
6625 INTERNAL,
6626 { },
6627 { { 0, 1 } },
6628 },
6629 /* BPF_JMP | BPF_JSGT | BPF_X */
6630 {
6631 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
6632 .u.insns_int = {
6633 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6634 BPF_LD_IMM64(R1, -1),
6635 BPF_LD_IMM64(R2, -2),
6636 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6637 BPF_EXIT_INSN(),
6638 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6639 BPF_EXIT_INSN(),
6640 },
6641 INTERNAL,
6642 { },
6643 { { 0, 1 } },
6644 },
6645 {
6646 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
6647 .u.insns_int = {
6648 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6649 BPF_LD_IMM64(R1, -1),
6650 BPF_LD_IMM64(R2, -1),
6651 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6652 BPF_EXIT_INSN(),
6653 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6654 BPF_EXIT_INSN(),
6655 },
6656 INTERNAL,
6657 { },
6658 { { 0, 1 } },
6659 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006660 /* BPF_JMP | BPF_JSLT | BPF_X */
6661 {
6662 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
6663 .u.insns_int = {
6664 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6665 BPF_LD_IMM64(R1, -1),
6666 BPF_LD_IMM64(R2, -2),
6667 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
6668 BPF_EXIT_INSN(),
6669 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6670 BPF_EXIT_INSN(),
6671 },
6672 INTERNAL,
6673 { },
6674 { { 0, 1 } },
6675 },
6676 {
6677 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
6678 .u.insns_int = {
6679 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6680 BPF_LD_IMM64(R1, -1),
6681 BPF_LD_IMM64(R2, -1),
6682 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
6683 BPF_EXIT_INSN(),
6684 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6685 BPF_EXIT_INSN(),
6686 },
6687 INTERNAL,
6688 { },
6689 { { 0, 1 } },
6690 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006691 /* BPF_JMP | BPF_JSGE | BPF_X */
6692 {
6693 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
6694 .u.insns_int = {
6695 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6696 BPF_LD_IMM64(R1, -1),
6697 BPF_LD_IMM64(R2, -2),
6698 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6699 BPF_EXIT_INSN(),
6700 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6701 BPF_EXIT_INSN(),
6702 },
6703 INTERNAL,
6704 { },
6705 { { 0, 1 } },
6706 },
6707 {
6708 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
6709 .u.insns_int = {
6710 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6711 BPF_LD_IMM64(R1, -1),
6712 BPF_LD_IMM64(R2, -1),
6713 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6714 BPF_EXIT_INSN(),
6715 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6716 BPF_EXIT_INSN(),
6717 },
6718 INTERNAL,
6719 { },
6720 { { 0, 1 } },
6721 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006722 /* BPF_JMP | BPF_JSLE | BPF_X */
6723 {
6724 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
6725 .u.insns_int = {
6726 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6727 BPF_LD_IMM64(R1, -1),
6728 BPF_LD_IMM64(R2, -2),
6729 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
6730 BPF_EXIT_INSN(),
6731 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6732 BPF_EXIT_INSN(),
6733 },
6734 INTERNAL,
6735 { },
6736 { { 0, 1 } },
6737 },
6738 {
6739 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
6740 .u.insns_int = {
6741 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6742 BPF_LD_IMM64(R1, -1),
6743 BPF_LD_IMM64(R2, -1),
6744 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
6745 BPF_EXIT_INSN(),
6746 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6747 BPF_EXIT_INSN(),
6748 },
6749 INTERNAL,
6750 { },
6751 { { 0, 1 } },
6752 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006753 /* BPF_JMP | BPF_JGT | BPF_X */
6754 {
6755 "JMP_JGT_X: if (3 > 2) return 1",
6756 .u.insns_int = {
6757 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6758 BPF_LD_IMM64(R1, 3),
6759 BPF_LD_IMM64(R2, 2),
6760 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6761 BPF_EXIT_INSN(),
6762 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6763 BPF_EXIT_INSN(),
6764 },
6765 INTERNAL,
6766 { },
6767 { { 0, 1 } },
6768 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05306769 {
6770 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
6771 .u.insns_int = {
6772 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6773 BPF_LD_IMM64(R1, -1),
6774 BPF_LD_IMM64(R2, 1),
6775 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6776 BPF_EXIT_INSN(),
6777 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6778 BPF_EXIT_INSN(),
6779 },
6780 INTERNAL,
6781 { },
6782 { { 0, 1 } },
6783 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006784 /* BPF_JMP | BPF_JLT | BPF_X */
6785 {
6786 "JMP_JLT_X: if (2 < 3) return 1",
6787 .u.insns_int = {
6788 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6789 BPF_LD_IMM64(R1, 3),
6790 BPF_LD_IMM64(R2, 2),
6791 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6792 BPF_EXIT_INSN(),
6793 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6794 BPF_EXIT_INSN(),
6795 },
6796 INTERNAL,
6797 { },
6798 { { 0, 1 } },
6799 },
6800 {
6801 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
6802 .u.insns_int = {
6803 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6804 BPF_LD_IMM64(R1, -1),
6805 BPF_LD_IMM64(R2, 1),
6806 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6807 BPF_EXIT_INSN(),
6808 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6809 BPF_EXIT_INSN(),
6810 },
6811 INTERNAL,
6812 { },
6813 { { 0, 1 } },
6814 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006815 /* BPF_JMP | BPF_JGE | BPF_X */
6816 {
6817 "JMP_JGE_X: if (3 >= 2) return 1",
6818 .u.insns_int = {
6819 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6820 BPF_LD_IMM64(R1, 3),
6821 BPF_LD_IMM64(R2, 2),
6822 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
6823 BPF_EXIT_INSN(),
6824 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6825 BPF_EXIT_INSN(),
6826 },
6827 INTERNAL,
6828 { },
6829 { { 0, 1 } },
6830 },
6831 {
6832 "JMP_JGE_X: if (3 >= 3) return 1",
6833 .u.insns_int = {
6834 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6835 BPF_LD_IMM64(R1, 3),
6836 BPF_LD_IMM64(R2, 3),
6837 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
6838 BPF_EXIT_INSN(),
6839 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6840 BPF_EXIT_INSN(),
6841 },
6842 INTERNAL,
6843 { },
6844 { { 0, 1 } },
6845 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006846 /* BPF_JMP | BPF_JLE | BPF_X */
6847 {
6848 "JMP_JLE_X: if (2 <= 3) return 1",
6849 .u.insns_int = {
6850 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6851 BPF_LD_IMM64(R1, 3),
6852 BPF_LD_IMM64(R2, 2),
6853 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
6854 BPF_EXIT_INSN(),
6855 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6856 BPF_EXIT_INSN(),
6857 },
6858 INTERNAL,
6859 { },
6860 { { 0, 1 } },
6861 },
6862 {
6863 "JMP_JLE_X: if (3 <= 3) return 1",
6864 .u.insns_int = {
6865 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6866 BPF_LD_IMM64(R1, 3),
6867 BPF_LD_IMM64(R2, 3),
6868 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
6869 BPF_EXIT_INSN(),
6870 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6871 BPF_EXIT_INSN(),
6872 },
6873 INTERNAL,
6874 { },
6875 { { 0, 1 } },
6876 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006877 {
6878 /* Mainly testing JIT + imm64 here. */
6879 "JMP_JGE_X: ldimm64 test 1",
6880 .u.insns_int = {
6881 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6882 BPF_LD_IMM64(R1, 3),
6883 BPF_LD_IMM64(R2, 2),
6884 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02006885 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6886 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006887 BPF_EXIT_INSN(),
6888 },
6889 INTERNAL,
6890 { },
6891 { { 0, 0xeeeeeeeeU } },
6892 },
6893 {
6894 "JMP_JGE_X: ldimm64 test 2",
6895 .u.insns_int = {
6896 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6897 BPF_LD_IMM64(R1, 3),
6898 BPF_LD_IMM64(R2, 2),
6899 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02006900 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006901 BPF_EXIT_INSN(),
6902 },
6903 INTERNAL,
6904 { },
6905 { { 0, 0xffffffffU } },
6906 },
6907 {
6908 "JMP_JGE_X: ldimm64 test 3",
6909 .u.insns_int = {
6910 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6911 BPF_LD_IMM64(R1, 3),
6912 BPF_LD_IMM64(R2, 2),
6913 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02006914 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6915 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006916 BPF_EXIT_INSN(),
6917 },
6918 INTERNAL,
6919 { },
6920 { { 0, 1 } },
6921 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006922 {
6923 "JMP_JLE_X: ldimm64 test 1",
6924 .u.insns_int = {
6925 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6926 BPF_LD_IMM64(R1, 3),
6927 BPF_LD_IMM64(R2, 2),
6928 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
6929 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6930 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
6931 BPF_EXIT_INSN(),
6932 },
6933 INTERNAL,
6934 { },
6935 { { 0, 0xeeeeeeeeU } },
6936 },
6937 {
6938 "JMP_JLE_X: ldimm64 test 2",
6939 .u.insns_int = {
6940 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6941 BPF_LD_IMM64(R1, 3),
6942 BPF_LD_IMM64(R2, 2),
6943 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
6944 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6945 BPF_EXIT_INSN(),
6946 },
6947 INTERNAL,
6948 { },
6949 { { 0, 0xffffffffU } },
6950 },
6951 {
6952 "JMP_JLE_X: ldimm64 test 3",
6953 .u.insns_int = {
6954 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6955 BPF_LD_IMM64(R1, 3),
6956 BPF_LD_IMM64(R2, 2),
6957 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
6958 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6959 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
6960 BPF_EXIT_INSN(),
6961 },
6962 INTERNAL,
6963 { },
6964 { { 0, 1 } },
6965 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006966 /* BPF_JMP | BPF_JNE | BPF_X */
6967 {
6968 "JMP_JNE_X: if (3 != 2) return 1",
6969 .u.insns_int = {
6970 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6971 BPF_LD_IMM64(R1, 3),
6972 BPF_LD_IMM64(R2, 2),
6973 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
6974 BPF_EXIT_INSN(),
6975 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6976 BPF_EXIT_INSN(),
6977 },
6978 INTERNAL,
6979 { },
6980 { { 0, 1 } },
6981 },
6982 /* BPF_JMP | BPF_JEQ | BPF_X */
6983 {
6984 "JMP_JEQ_X: if (3 == 3) return 1",
6985 .u.insns_int = {
6986 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6987 BPF_LD_IMM64(R1, 3),
6988 BPF_LD_IMM64(R2, 3),
6989 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
6990 BPF_EXIT_INSN(),
6991 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6992 BPF_EXIT_INSN(),
6993 },
6994 INTERNAL,
6995 { },
6996 { { 0, 1 } },
6997 },
6998 /* BPF_JMP | BPF_JSET | BPF_X */
6999 {
7000 "JMP_JSET_X: if (0x3 & 0x2) return 1",
7001 .u.insns_int = {
7002 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7003 BPF_LD_IMM64(R1, 3),
7004 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05307005 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07007006 BPF_EXIT_INSN(),
7007 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7008 BPF_EXIT_INSN(),
7009 },
7010 INTERNAL,
7011 { },
7012 { { 0, 1 } },
7013 },
7014 {
7015 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
7016 .u.insns_int = {
7017 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7018 BPF_LD_IMM64(R1, 3),
7019 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05307020 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07007021 BPF_EXIT_INSN(),
7022 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7023 BPF_EXIT_INSN(),
7024 },
7025 INTERNAL,
7026 { },
7027 { { 0, 1 } },
7028 },
Johan Almbladh66e5eb82021-08-09 11:18:25 +02007029 { /* Mainly checking JIT here. */
7030 "BPF_MAXINSNS: Very long conditional jump",
7031 { },
7032 INTERNAL | FLAG_NO_DATA,
7033 { },
7034 { { 0, 1 } },
7035 .fill_helper = bpf_fill_long_jmp,
7036 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02007037 {
7038 "JMP_JA: Jump, gap, jump, ...",
7039 { },
7040 CLASSIC | FLAG_NO_DATA,
7041 { },
7042 { { 0, 0xababcbac } },
7043 .fill_helper = bpf_fill_ja,
7044 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007045 { /* Mainly checking JIT here. */
7046 "BPF_MAXINSNS: Maximum possible literals",
7047 { },
7048 CLASSIC | FLAG_NO_DATA,
7049 { },
7050 { { 0, 0xffffffff } },
7051 .fill_helper = bpf_fill_maxinsns1,
7052 },
7053 { /* Mainly checking JIT here. */
7054 "BPF_MAXINSNS: Single literal",
7055 { },
7056 CLASSIC | FLAG_NO_DATA,
7057 { },
7058 { { 0, 0xfefefefe } },
7059 .fill_helper = bpf_fill_maxinsns2,
7060 },
7061 { /* Mainly checking JIT here. */
7062 "BPF_MAXINSNS: Run/add until end",
7063 { },
7064 CLASSIC | FLAG_NO_DATA,
7065 { },
7066 { { 0, 0x947bf368 } },
7067 .fill_helper = bpf_fill_maxinsns3,
7068 },
7069 {
7070 "BPF_MAXINSNS: Too many instructions",
7071 { },
7072 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
7073 { },
7074 { },
7075 .fill_helper = bpf_fill_maxinsns4,
Yonghong Song09584b42018-02-02 22:37:15 -08007076 .expected_errcode = -EINVAL,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007077 },
7078 { /* Mainly checking JIT here. */
7079 "BPF_MAXINSNS: Very long jump",
7080 { },
7081 CLASSIC | FLAG_NO_DATA,
7082 { },
7083 { { 0, 0xabababab } },
7084 .fill_helper = bpf_fill_maxinsns5,
7085 },
7086 { /* Mainly checking JIT here. */
7087 "BPF_MAXINSNS: Ctx heavy transformations",
7088 { },
7089 CLASSIC,
7090 { },
7091 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01007092 { 1, SKB_VLAN_PRESENT },
7093 { 10, SKB_VLAN_PRESENT }
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007094 },
7095 .fill_helper = bpf_fill_maxinsns6,
7096 },
7097 { /* Mainly checking JIT here. */
7098 "BPF_MAXINSNS: Call heavy transformations",
7099 { },
7100 CLASSIC | FLAG_NO_DATA,
7101 { },
7102 { { 1, 0 }, { 10, 0 } },
7103 .fill_helper = bpf_fill_maxinsns7,
7104 },
7105 { /* Mainly checking JIT here. */
7106 "BPF_MAXINSNS: Jump heavy test",
7107 { },
7108 CLASSIC | FLAG_NO_DATA,
7109 { },
7110 { { 0, 0xffffffff } },
7111 .fill_helper = bpf_fill_maxinsns8,
7112 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02007113 { /* Mainly checking JIT here. */
7114 "BPF_MAXINSNS: Very long jump backwards",
7115 { },
7116 INTERNAL | FLAG_NO_DATA,
7117 { },
7118 { { 0, 0xcbababab } },
7119 .fill_helper = bpf_fill_maxinsns9,
7120 },
7121 { /* Mainly checking JIT here. */
7122 "BPF_MAXINSNS: Edge hopping nuthouse",
7123 { },
7124 INTERNAL | FLAG_NO_DATA,
7125 { },
7126 { { 0, 0xabababac } },
7127 .fill_helper = bpf_fill_maxinsns10,
7128 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02007129 {
7130 "BPF_MAXINSNS: Jump, gap, jump, ...",
7131 { },
7132 CLASSIC | FLAG_NO_DATA,
7133 { },
7134 { { 0, 0xababcbac } },
7135 .fill_helper = bpf_fill_maxinsns11,
7136 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007137 {
Daniel Borkmannbe088152018-06-02 23:06:32 +02007138 "BPF_MAXINSNS: jump over MSH",
7139 { },
7140 CLASSIC | FLAG_EXPECTED_FAIL,
7141 { 0xfa, 0xfb, 0xfc, 0xfd, },
7142 { { 4, 0xabababab } },
7143 .fill_helper = bpf_fill_maxinsns12,
7144 .expected_errcode = -EINVAL,
7145 },
7146 {
7147 "BPF_MAXINSNS: exec all MSH",
7148 { },
7149 CLASSIC,
7150 { 0xfa, 0xfb, 0xfc, 0xfd, },
7151 { { 4, 0xababab83 } },
7152 .fill_helper = bpf_fill_maxinsns13,
7153 },
7154 {
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007155 "BPF_MAXINSNS: ld_abs+get_processor_id",
7156 { },
7157 CLASSIC,
7158 { },
7159 { { 1, 0xbee } },
7160 .fill_helper = bpf_fill_ld_abs_get_processor_id,
7161 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02007162 /*
7163 * LD_IND / LD_ABS on fragmented SKBs
7164 */
7165 {
7166 "LD_IND byte frag",
7167 .u.insns = {
7168 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7169 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
7170 BPF_STMT(BPF_RET | BPF_A, 0x0),
7171 },
7172 CLASSIC | FLAG_SKB_FRAG,
7173 { },
7174 { {0x40, 0x42} },
7175 .frag_data = {
7176 0x42, 0x00, 0x00, 0x00,
7177 0x43, 0x44, 0x00, 0x00,
7178 0x21, 0x07, 0x19, 0x83,
7179 },
7180 },
7181 {
7182 "LD_IND halfword frag",
7183 .u.insns = {
7184 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7185 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
7186 BPF_STMT(BPF_RET | BPF_A, 0x0),
7187 },
7188 CLASSIC | FLAG_SKB_FRAG,
7189 { },
7190 { {0x40, 0x4344} },
7191 .frag_data = {
7192 0x42, 0x00, 0x00, 0x00,
7193 0x43, 0x44, 0x00, 0x00,
7194 0x21, 0x07, 0x19, 0x83,
7195 },
7196 },
7197 {
7198 "LD_IND word frag",
7199 .u.insns = {
7200 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7201 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
7202 BPF_STMT(BPF_RET | BPF_A, 0x0),
7203 },
7204 CLASSIC | FLAG_SKB_FRAG,
7205 { },
7206 { {0x40, 0x21071983} },
7207 .frag_data = {
7208 0x42, 0x00, 0x00, 0x00,
7209 0x43, 0x44, 0x00, 0x00,
7210 0x21, 0x07, 0x19, 0x83,
7211 },
7212 },
7213 {
7214 "LD_IND halfword mixed head/frag",
7215 .u.insns = {
7216 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7217 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7218 BPF_STMT(BPF_RET | BPF_A, 0x0),
7219 },
7220 CLASSIC | FLAG_SKB_FRAG,
7221 { [0x3e] = 0x25, [0x3f] = 0x05, },
7222 { {0x40, 0x0519} },
7223 .frag_data = { 0x19, 0x82 },
7224 },
7225 {
7226 "LD_IND word mixed head/frag",
7227 .u.insns = {
7228 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7229 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7230 BPF_STMT(BPF_RET | BPF_A, 0x0),
7231 },
7232 CLASSIC | FLAG_SKB_FRAG,
7233 { [0x3e] = 0x25, [0x3f] = 0x05, },
7234 { {0x40, 0x25051982} },
7235 .frag_data = { 0x19, 0x82 },
7236 },
7237 {
7238 "LD_ABS byte frag",
7239 .u.insns = {
7240 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
7241 BPF_STMT(BPF_RET | BPF_A, 0x0),
7242 },
7243 CLASSIC | FLAG_SKB_FRAG,
7244 { },
7245 { {0x40, 0x42} },
7246 .frag_data = {
7247 0x42, 0x00, 0x00, 0x00,
7248 0x43, 0x44, 0x00, 0x00,
7249 0x21, 0x07, 0x19, 0x83,
7250 },
7251 },
7252 {
7253 "LD_ABS halfword frag",
7254 .u.insns = {
7255 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
7256 BPF_STMT(BPF_RET | BPF_A, 0x0),
7257 },
7258 CLASSIC | FLAG_SKB_FRAG,
7259 { },
7260 { {0x40, 0x4344} },
7261 .frag_data = {
7262 0x42, 0x00, 0x00, 0x00,
7263 0x43, 0x44, 0x00, 0x00,
7264 0x21, 0x07, 0x19, 0x83,
7265 },
7266 },
7267 {
7268 "LD_ABS word frag",
7269 .u.insns = {
7270 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
7271 BPF_STMT(BPF_RET | BPF_A, 0x0),
7272 },
7273 CLASSIC | FLAG_SKB_FRAG,
7274 { },
7275 { {0x40, 0x21071983} },
7276 .frag_data = {
7277 0x42, 0x00, 0x00, 0x00,
7278 0x43, 0x44, 0x00, 0x00,
7279 0x21, 0x07, 0x19, 0x83,
7280 },
7281 },
7282 {
7283 "LD_ABS halfword mixed head/frag",
7284 .u.insns = {
7285 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7286 BPF_STMT(BPF_RET | BPF_A, 0x0),
7287 },
7288 CLASSIC | FLAG_SKB_FRAG,
7289 { [0x3e] = 0x25, [0x3f] = 0x05, },
7290 { {0x40, 0x0519} },
7291 .frag_data = { 0x19, 0x82 },
7292 },
7293 {
7294 "LD_ABS word mixed head/frag",
7295 .u.insns = {
7296 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
7297 BPF_STMT(BPF_RET | BPF_A, 0x0),
7298 },
7299 CLASSIC | FLAG_SKB_FRAG,
7300 { [0x3e] = 0x25, [0x3f] = 0x05, },
7301 { {0x40, 0x25051982} },
7302 .frag_data = { 0x19, 0x82 },
7303 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007304 /*
7305 * LD_IND / LD_ABS on non fragmented SKBs
7306 */
7307 {
7308 /*
7309 * this tests that the JIT/interpreter correctly resets X
7310 * before using it in an LD_IND instruction.
7311 */
7312 "LD_IND byte default X",
7313 .u.insns = {
7314 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7315 BPF_STMT(BPF_RET | BPF_A, 0x0),
7316 },
7317 CLASSIC,
7318 { [0x1] = 0x42 },
7319 { {0x40, 0x42 } },
7320 },
7321 {
7322 "LD_IND byte positive offset",
7323 .u.insns = {
7324 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7325 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7326 BPF_STMT(BPF_RET | BPF_A, 0x0),
7327 },
7328 CLASSIC,
7329 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7330 { {0x40, 0x82 } },
7331 },
7332 {
7333 "LD_IND byte negative offset",
7334 .u.insns = {
7335 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7336 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
7337 BPF_STMT(BPF_RET | BPF_A, 0x0),
7338 },
7339 CLASSIC,
7340 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7341 { {0x40, 0x05 } },
7342 },
7343 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007344 "LD_IND byte positive offset, all ff",
7345 .u.insns = {
7346 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7347 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7348 BPF_STMT(BPF_RET | BPF_A, 0x0),
7349 },
7350 CLASSIC,
7351 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7352 { {0x40, 0xff } },
7353 },
7354 {
7355 "LD_IND byte positive offset, out of bounds",
7356 .u.insns = {
7357 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7358 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7359 BPF_STMT(BPF_RET | BPF_A, 0x0),
7360 },
7361 CLASSIC,
7362 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7363 { {0x3f, 0 }, },
7364 },
7365 {
7366 "LD_IND byte negative offset, out of bounds",
7367 .u.insns = {
7368 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7369 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
7370 BPF_STMT(BPF_RET | BPF_A, 0x0),
7371 },
7372 CLASSIC,
7373 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7374 { {0x3f, 0 } },
7375 },
7376 {
7377 "LD_IND byte negative offset, multiple calls",
7378 .u.insns = {
7379 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7380 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
7381 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
7382 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
7383 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
7384 BPF_STMT(BPF_RET | BPF_A, 0x0),
7385 },
7386 CLASSIC,
7387 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7388 { {0x40, 0x82 }, },
7389 },
7390 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007391 "LD_IND halfword positive offset",
7392 .u.insns = {
7393 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7394 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
7395 BPF_STMT(BPF_RET | BPF_A, 0x0),
7396 },
7397 CLASSIC,
7398 {
7399 [0x1c] = 0xaa, [0x1d] = 0x55,
7400 [0x1e] = 0xbb, [0x1f] = 0x66,
7401 [0x20] = 0xcc, [0x21] = 0x77,
7402 [0x22] = 0xdd, [0x23] = 0x88,
7403 },
7404 { {0x40, 0xdd88 } },
7405 },
7406 {
7407 "LD_IND halfword negative offset",
7408 .u.insns = {
7409 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7410 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
7411 BPF_STMT(BPF_RET | BPF_A, 0x0),
7412 },
7413 CLASSIC,
7414 {
7415 [0x1c] = 0xaa, [0x1d] = 0x55,
7416 [0x1e] = 0xbb, [0x1f] = 0x66,
7417 [0x20] = 0xcc, [0x21] = 0x77,
7418 [0x22] = 0xdd, [0x23] = 0x88,
7419 },
7420 { {0x40, 0xbb66 } },
7421 },
7422 {
7423 "LD_IND halfword unaligned",
7424 .u.insns = {
7425 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7426 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7427 BPF_STMT(BPF_RET | BPF_A, 0x0),
7428 },
7429 CLASSIC,
7430 {
7431 [0x1c] = 0xaa, [0x1d] = 0x55,
7432 [0x1e] = 0xbb, [0x1f] = 0x66,
7433 [0x20] = 0xcc, [0x21] = 0x77,
7434 [0x22] = 0xdd, [0x23] = 0x88,
7435 },
7436 { {0x40, 0x66cc } },
7437 },
7438 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007439 "LD_IND halfword positive offset, all ff",
7440 .u.insns = {
7441 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
7442 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7443 BPF_STMT(BPF_RET | BPF_A, 0x0),
7444 },
7445 CLASSIC,
7446 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7447 { {0x40, 0xffff } },
7448 },
7449 {
7450 "LD_IND halfword positive offset, out of bounds",
7451 .u.insns = {
7452 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7453 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7454 BPF_STMT(BPF_RET | BPF_A, 0x0),
7455 },
7456 CLASSIC,
7457 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7458 { {0x3f, 0 }, },
7459 },
7460 {
7461 "LD_IND halfword negative offset, out of bounds",
7462 .u.insns = {
7463 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7464 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
7465 BPF_STMT(BPF_RET | BPF_A, 0x0),
7466 },
7467 CLASSIC,
7468 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7469 { {0x3f, 0 } },
7470 },
7471 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007472 "LD_IND word positive offset",
7473 .u.insns = {
7474 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7475 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
7476 BPF_STMT(BPF_RET | BPF_A, 0x0),
7477 },
7478 CLASSIC,
7479 {
7480 [0x1c] = 0xaa, [0x1d] = 0x55,
7481 [0x1e] = 0xbb, [0x1f] = 0x66,
7482 [0x20] = 0xcc, [0x21] = 0x77,
7483 [0x22] = 0xdd, [0x23] = 0x88,
7484 [0x24] = 0xee, [0x25] = 0x99,
7485 [0x26] = 0xff, [0x27] = 0xaa,
7486 },
7487 { {0x40, 0xee99ffaa } },
7488 },
7489 {
7490 "LD_IND word negative offset",
7491 .u.insns = {
7492 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7493 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
7494 BPF_STMT(BPF_RET | BPF_A, 0x0),
7495 },
7496 CLASSIC,
7497 {
7498 [0x1c] = 0xaa, [0x1d] = 0x55,
7499 [0x1e] = 0xbb, [0x1f] = 0x66,
7500 [0x20] = 0xcc, [0x21] = 0x77,
7501 [0x22] = 0xdd, [0x23] = 0x88,
7502 [0x24] = 0xee, [0x25] = 0x99,
7503 [0x26] = 0xff, [0x27] = 0xaa,
7504 },
7505 { {0x40, 0xaa55bb66 } },
7506 },
7507 {
7508 "LD_IND word unaligned (addr & 3 == 2)",
7509 .u.insns = {
7510 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7511 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7512 BPF_STMT(BPF_RET | BPF_A, 0x0),
7513 },
7514 CLASSIC,
7515 {
7516 [0x1c] = 0xaa, [0x1d] = 0x55,
7517 [0x1e] = 0xbb, [0x1f] = 0x66,
7518 [0x20] = 0xcc, [0x21] = 0x77,
7519 [0x22] = 0xdd, [0x23] = 0x88,
7520 [0x24] = 0xee, [0x25] = 0x99,
7521 [0x26] = 0xff, [0x27] = 0xaa,
7522 },
7523 { {0x40, 0xbb66cc77 } },
7524 },
7525 {
7526 "LD_IND word unaligned (addr & 3 == 1)",
7527 .u.insns = {
7528 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7529 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
7530 BPF_STMT(BPF_RET | BPF_A, 0x0),
7531 },
7532 CLASSIC,
7533 {
7534 [0x1c] = 0xaa, [0x1d] = 0x55,
7535 [0x1e] = 0xbb, [0x1f] = 0x66,
7536 [0x20] = 0xcc, [0x21] = 0x77,
7537 [0x22] = 0xdd, [0x23] = 0x88,
7538 [0x24] = 0xee, [0x25] = 0x99,
7539 [0x26] = 0xff, [0x27] = 0xaa,
7540 },
7541 { {0x40, 0x55bb66cc } },
7542 },
7543 {
7544 "LD_IND word unaligned (addr & 3 == 3)",
7545 .u.insns = {
7546 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7547 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
7548 BPF_STMT(BPF_RET | BPF_A, 0x0),
7549 },
7550 CLASSIC,
7551 {
7552 [0x1c] = 0xaa, [0x1d] = 0x55,
7553 [0x1e] = 0xbb, [0x1f] = 0x66,
7554 [0x20] = 0xcc, [0x21] = 0x77,
7555 [0x22] = 0xdd, [0x23] = 0x88,
7556 [0x24] = 0xee, [0x25] = 0x99,
7557 [0x26] = 0xff, [0x27] = 0xaa,
7558 },
7559 { {0x40, 0x66cc77dd } },
7560 },
7561 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007562 "LD_IND word positive offset, all ff",
7563 .u.insns = {
7564 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7565 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7566 BPF_STMT(BPF_RET | BPF_A, 0x0),
7567 },
7568 CLASSIC,
7569 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7570 { {0x40, 0xffffffff } },
7571 },
7572 {
7573 "LD_IND word positive offset, out of bounds",
7574 .u.insns = {
7575 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7576 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7577 BPF_STMT(BPF_RET | BPF_A, 0x0),
7578 },
7579 CLASSIC,
7580 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7581 { {0x3f, 0 }, },
7582 },
7583 {
7584 "LD_IND word negative offset, out of bounds",
7585 .u.insns = {
7586 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7587 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
7588 BPF_STMT(BPF_RET | BPF_A, 0x0),
7589 },
7590 CLASSIC,
7591 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7592 { {0x3f, 0 } },
7593 },
7594 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007595 "LD_ABS byte",
7596 .u.insns = {
7597 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
7598 BPF_STMT(BPF_RET | BPF_A, 0x0),
7599 },
7600 CLASSIC,
7601 {
7602 [0x1c] = 0xaa, [0x1d] = 0x55,
7603 [0x1e] = 0xbb, [0x1f] = 0x66,
7604 [0x20] = 0xcc, [0x21] = 0x77,
7605 [0x22] = 0xdd, [0x23] = 0x88,
7606 [0x24] = 0xee, [0x25] = 0x99,
7607 [0x26] = 0xff, [0x27] = 0xaa,
7608 },
7609 { {0x40, 0xcc } },
7610 },
7611 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007612 "LD_ABS byte positive offset, all ff",
7613 .u.insns = {
7614 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7615 BPF_STMT(BPF_RET | BPF_A, 0x0),
7616 },
7617 CLASSIC,
7618 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7619 { {0x40, 0xff } },
7620 },
7621 {
7622 "LD_ABS byte positive offset, out of bounds",
7623 .u.insns = {
7624 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7625 BPF_STMT(BPF_RET | BPF_A, 0x0),
7626 },
7627 CLASSIC,
7628 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7629 { {0x3f, 0 }, },
7630 },
7631 {
7632 "LD_ABS byte negative offset, out of bounds load",
7633 .u.insns = {
7634 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
7635 BPF_STMT(BPF_RET | BPF_A, 0x0),
7636 },
7637 CLASSIC | FLAG_EXPECTED_FAIL,
7638 .expected_errcode = -EINVAL,
7639 },
7640 {
7641 "LD_ABS byte negative offset, in bounds",
7642 .u.insns = {
7643 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7644 BPF_STMT(BPF_RET | BPF_A, 0x0),
7645 },
7646 CLASSIC,
7647 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7648 { {0x40, 0x82 }, },
7649 },
7650 {
7651 "LD_ABS byte negative offset, out of bounds",
7652 .u.insns = {
7653 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7654 BPF_STMT(BPF_RET | BPF_A, 0x0),
7655 },
7656 CLASSIC,
7657 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7658 { {0x3f, 0 }, },
7659 },
7660 {
7661 "LD_ABS byte negative offset, multiple calls",
7662 .u.insns = {
7663 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
7664 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
7665 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
7666 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7667 BPF_STMT(BPF_RET | BPF_A, 0x0),
7668 },
7669 CLASSIC,
7670 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7671 { {0x40, 0x82 }, },
7672 },
7673 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007674 "LD_ABS halfword",
7675 .u.insns = {
7676 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
7677 BPF_STMT(BPF_RET | BPF_A, 0x0),
7678 },
7679 CLASSIC,
7680 {
7681 [0x1c] = 0xaa, [0x1d] = 0x55,
7682 [0x1e] = 0xbb, [0x1f] = 0x66,
7683 [0x20] = 0xcc, [0x21] = 0x77,
7684 [0x22] = 0xdd, [0x23] = 0x88,
7685 [0x24] = 0xee, [0x25] = 0x99,
7686 [0x26] = 0xff, [0x27] = 0xaa,
7687 },
7688 { {0x40, 0xdd88 } },
7689 },
7690 {
7691 "LD_ABS halfword unaligned",
7692 .u.insns = {
7693 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
7694 BPF_STMT(BPF_RET | BPF_A, 0x0),
7695 },
7696 CLASSIC,
7697 {
7698 [0x1c] = 0xaa, [0x1d] = 0x55,
7699 [0x1e] = 0xbb, [0x1f] = 0x66,
7700 [0x20] = 0xcc, [0x21] = 0x77,
7701 [0x22] = 0xdd, [0x23] = 0x88,
7702 [0x24] = 0xee, [0x25] = 0x99,
7703 [0x26] = 0xff, [0x27] = 0xaa,
7704 },
7705 { {0x40, 0x99ff } },
7706 },
7707 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007708 "LD_ABS halfword positive offset, all ff",
7709 .u.insns = {
7710 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
7711 BPF_STMT(BPF_RET | BPF_A, 0x0),
7712 },
7713 CLASSIC,
7714 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7715 { {0x40, 0xffff } },
7716 },
7717 {
7718 "LD_ABS halfword positive offset, out of bounds",
7719 .u.insns = {
7720 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7721 BPF_STMT(BPF_RET | BPF_A, 0x0),
7722 },
7723 CLASSIC,
7724 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7725 { {0x3f, 0 }, },
7726 },
7727 {
7728 "LD_ABS halfword negative offset, out of bounds load",
7729 .u.insns = {
7730 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
7731 BPF_STMT(BPF_RET | BPF_A, 0x0),
7732 },
7733 CLASSIC | FLAG_EXPECTED_FAIL,
7734 .expected_errcode = -EINVAL,
7735 },
7736 {
7737 "LD_ABS halfword negative offset, in bounds",
7738 .u.insns = {
7739 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7740 BPF_STMT(BPF_RET | BPF_A, 0x0),
7741 },
7742 CLASSIC,
7743 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7744 { {0x40, 0x1982 }, },
7745 },
7746 {
7747 "LD_ABS halfword negative offset, out of bounds",
7748 .u.insns = {
7749 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7750 BPF_STMT(BPF_RET | BPF_A, 0x0),
7751 },
7752 CLASSIC,
7753 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7754 { {0x3f, 0 }, },
7755 },
7756 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007757 "LD_ABS word",
7758 .u.insns = {
7759 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
7760 BPF_STMT(BPF_RET | BPF_A, 0x0),
7761 },
7762 CLASSIC,
7763 {
7764 [0x1c] = 0xaa, [0x1d] = 0x55,
7765 [0x1e] = 0xbb, [0x1f] = 0x66,
7766 [0x20] = 0xcc, [0x21] = 0x77,
7767 [0x22] = 0xdd, [0x23] = 0x88,
7768 [0x24] = 0xee, [0x25] = 0x99,
7769 [0x26] = 0xff, [0x27] = 0xaa,
7770 },
7771 { {0x40, 0xaa55bb66 } },
7772 },
7773 {
7774 "LD_ABS word unaligned (addr & 3 == 2)",
7775 .u.insns = {
7776 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
7777 BPF_STMT(BPF_RET | BPF_A, 0x0),
7778 },
7779 CLASSIC,
7780 {
7781 [0x1c] = 0xaa, [0x1d] = 0x55,
7782 [0x1e] = 0xbb, [0x1f] = 0x66,
7783 [0x20] = 0xcc, [0x21] = 0x77,
7784 [0x22] = 0xdd, [0x23] = 0x88,
7785 [0x24] = 0xee, [0x25] = 0x99,
7786 [0x26] = 0xff, [0x27] = 0xaa,
7787 },
7788 { {0x40, 0xdd88ee99 } },
7789 },
7790 {
7791 "LD_ABS word unaligned (addr & 3 == 1)",
7792 .u.insns = {
7793 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
7794 BPF_STMT(BPF_RET | BPF_A, 0x0),
7795 },
7796 CLASSIC,
7797 {
7798 [0x1c] = 0xaa, [0x1d] = 0x55,
7799 [0x1e] = 0xbb, [0x1f] = 0x66,
7800 [0x20] = 0xcc, [0x21] = 0x77,
7801 [0x22] = 0xdd, [0x23] = 0x88,
7802 [0x24] = 0xee, [0x25] = 0x99,
7803 [0x26] = 0xff, [0x27] = 0xaa,
7804 },
7805 { {0x40, 0x77dd88ee } },
7806 },
7807 {
7808 "LD_ABS word unaligned (addr & 3 == 3)",
7809 .u.insns = {
7810 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
7811 BPF_STMT(BPF_RET | BPF_A, 0x0),
7812 },
7813 CLASSIC,
7814 {
7815 [0x1c] = 0xaa, [0x1d] = 0x55,
7816 [0x1e] = 0xbb, [0x1f] = 0x66,
7817 [0x20] = 0xcc, [0x21] = 0x77,
7818 [0x22] = 0xdd, [0x23] = 0x88,
7819 [0x24] = 0xee, [0x25] = 0x99,
7820 [0x26] = 0xff, [0x27] = 0xaa,
7821 },
7822 { {0x40, 0x88ee99ff } },
7823 },
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007824 {
7825 "LD_ABS word positive offset, all ff",
7826 .u.insns = {
7827 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
7828 BPF_STMT(BPF_RET | BPF_A, 0x0),
7829 },
7830 CLASSIC,
7831 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7832 { {0x40, 0xffffffff } },
7833 },
7834 {
7835 "LD_ABS word positive offset, out of bounds",
7836 .u.insns = {
7837 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
7838 BPF_STMT(BPF_RET | BPF_A, 0x0),
7839 },
7840 CLASSIC,
7841 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7842 { {0x3f, 0 }, },
7843 },
7844 {
7845 "LD_ABS word negative offset, out of bounds load",
7846 .u.insns = {
7847 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
7848 BPF_STMT(BPF_RET | BPF_A, 0x0),
7849 },
7850 CLASSIC | FLAG_EXPECTED_FAIL,
7851 .expected_errcode = -EINVAL,
7852 },
7853 {
7854 "LD_ABS word negative offset, in bounds",
7855 .u.insns = {
7856 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
7857 BPF_STMT(BPF_RET | BPF_A, 0x0),
7858 },
7859 CLASSIC,
7860 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7861 { {0x40, 0x25051982 }, },
7862 },
7863 {
7864 "LD_ABS word negative offset, out of bounds",
7865 .u.insns = {
7866 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
7867 BPF_STMT(BPF_RET | BPF_A, 0x0),
7868 },
7869 CLASSIC,
7870 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7871 { {0x3f, 0 }, },
7872 },
7873 {
7874 "LDX_MSH standalone, preserved A",
7875 .u.insns = {
7876 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7877 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
7878 BPF_STMT(BPF_RET | BPF_A, 0x0),
7879 },
7880 CLASSIC,
7881 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7882 { {0x40, 0xffeebbaa }, },
7883 },
7884 {
7885 "LDX_MSH standalone, preserved A 2",
7886 .u.insns = {
7887 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
7888 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
7889 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
7890 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
7891 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
7892 BPF_STMT(BPF_RET | BPF_A, 0x0),
7893 },
7894 CLASSIC,
7895 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7896 { {0x40, 0x175e9d63 }, },
7897 },
7898 {
7899 "LDX_MSH standalone, test result 1",
7900 .u.insns = {
7901 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7902 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
7903 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7904 BPF_STMT(BPF_RET | BPF_A, 0x0),
7905 },
7906 CLASSIC,
7907 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7908 { {0x40, 0x14 }, },
7909 },
7910 {
7911 "LDX_MSH standalone, test result 2",
7912 .u.insns = {
7913 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7914 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
7915 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7916 BPF_STMT(BPF_RET | BPF_A, 0x0),
7917 },
7918 CLASSIC,
7919 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7920 { {0x40, 0x24 }, },
7921 },
7922 {
7923 "LDX_MSH standalone, negative offset",
7924 .u.insns = {
7925 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7926 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
7927 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7928 BPF_STMT(BPF_RET | BPF_A, 0x0),
7929 },
7930 CLASSIC,
7931 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7932 { {0x40, 0 }, },
7933 },
7934 {
7935 "LDX_MSH standalone, negative offset 2",
7936 .u.insns = {
7937 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7938 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
7939 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7940 BPF_STMT(BPF_RET | BPF_A, 0x0),
7941 },
7942 CLASSIC,
7943 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7944 { {0x40, 0x24 }, },
7945 },
7946 {
7947 "LDX_MSH standalone, out of bounds",
7948 .u.insns = {
7949 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7950 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
7951 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7952 BPF_STMT(BPF_RET | BPF_A, 0x0),
7953 },
7954 CLASSIC,
7955 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7956 { {0x40, 0 }, },
7957 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02007958 /*
7959 * verify that the interpreter or JIT correctly sets A and X
7960 * to 0.
7961 */
7962 {
7963 "ADD default X",
7964 .u.insns = {
7965 /*
7966 * A = 0x42
7967 * A = A + X
7968 * ret A
7969 */
7970 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
7971 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
7972 BPF_STMT(BPF_RET | BPF_A, 0x0),
7973 },
7974 CLASSIC | FLAG_NO_DATA,
7975 {},
7976 { {0x1, 0x42 } },
7977 },
7978 {
7979 "ADD default A",
7980 .u.insns = {
7981 /*
7982 * A = A + 0x42
7983 * ret A
7984 */
7985 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
7986 BPF_STMT(BPF_RET | BPF_A, 0x0),
7987 },
7988 CLASSIC | FLAG_NO_DATA,
7989 {},
7990 { {0x1, 0x42 } },
7991 },
7992 {
7993 "SUB default X",
7994 .u.insns = {
7995 /*
7996 * A = 0x66
7997 * A = A - X
7998 * ret A
7999 */
8000 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
8001 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
8002 BPF_STMT(BPF_RET | BPF_A, 0x0),
8003 },
8004 CLASSIC | FLAG_NO_DATA,
8005 {},
8006 { {0x1, 0x66 } },
8007 },
8008 {
8009 "SUB default A",
8010 .u.insns = {
8011 /*
8012 * A = A - -0x66
8013 * ret A
8014 */
8015 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
8016 BPF_STMT(BPF_RET | BPF_A, 0x0),
8017 },
8018 CLASSIC | FLAG_NO_DATA,
8019 {},
8020 { {0x1, 0x66 } },
8021 },
8022 {
8023 "MUL default X",
8024 .u.insns = {
8025 /*
8026 * A = 0x42
8027 * A = A * X
8028 * ret A
8029 */
8030 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8031 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
8032 BPF_STMT(BPF_RET | BPF_A, 0x0),
8033 },
8034 CLASSIC | FLAG_NO_DATA,
8035 {},
8036 { {0x1, 0x0 } },
8037 },
8038 {
8039 "MUL default A",
8040 .u.insns = {
8041 /*
8042 * A = A * 0x66
8043 * ret A
8044 */
8045 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
8046 BPF_STMT(BPF_RET | BPF_A, 0x0),
8047 },
8048 CLASSIC | FLAG_NO_DATA,
8049 {},
8050 { {0x1, 0x0 } },
8051 },
8052 {
8053 "DIV default X",
8054 .u.insns = {
8055 /*
8056 * A = 0x42
8057 * A = A / X ; this halt the filter execution if X is 0
8058 * ret 0x42
8059 */
8060 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8061 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
8062 BPF_STMT(BPF_RET | BPF_K, 0x42),
8063 },
8064 CLASSIC | FLAG_NO_DATA,
8065 {},
8066 { {0x1, 0x0 } },
8067 },
8068 {
8069 "DIV default A",
8070 .u.insns = {
8071 /*
8072 * A = A / 1
8073 * ret A
8074 */
8075 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
8076 BPF_STMT(BPF_RET | BPF_A, 0x0),
8077 },
8078 CLASSIC | FLAG_NO_DATA,
8079 {},
8080 { {0x1, 0x0 } },
8081 },
8082 {
Yang Shid4e4bc12015-11-04 11:36:37 -08008083 "MOD default X",
8084 .u.insns = {
8085 /*
8086 * A = 0x42
8087 * A = A mod X ; this halt the filter execution if X is 0
8088 * ret 0x42
8089 */
8090 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8091 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
8092 BPF_STMT(BPF_RET | BPF_K, 0x42),
8093 },
8094 CLASSIC | FLAG_NO_DATA,
8095 {},
8096 { {0x1, 0x0 } },
8097 },
8098 {
8099 "MOD default A",
8100 .u.insns = {
8101 /*
8102 * A = A mod 1
8103 * ret A
8104 */
8105 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
8106 BPF_STMT(BPF_RET | BPF_A, 0x0),
8107 },
8108 CLASSIC | FLAG_NO_DATA,
8109 {},
8110 { {0x1, 0x0 } },
8111 },
8112 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02008113 "JMP EQ default A",
8114 .u.insns = {
8115 /*
8116 * cmp A, 0x0, 0, 1
8117 * ret 0x42
8118 * ret 0x66
8119 */
8120 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
8121 BPF_STMT(BPF_RET | BPF_K, 0x42),
8122 BPF_STMT(BPF_RET | BPF_K, 0x66),
8123 },
8124 CLASSIC | FLAG_NO_DATA,
8125 {},
8126 { {0x1, 0x42 } },
8127 },
8128 {
8129 "JMP EQ default X",
8130 .u.insns = {
8131 /*
8132 * A = 0x0
8133 * cmp A, X, 0, 1
8134 * ret 0x42
8135 * ret 0x66
8136 */
8137 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
8138 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
8139 BPF_STMT(BPF_RET | BPF_K, 0x42),
8140 BPF_STMT(BPF_RET | BPF_K, 0x66),
8141 },
8142 CLASSIC | FLAG_NO_DATA,
8143 {},
8144 { {0x1, 0x42 } },
8145 },
Daniel Borkmannfcd1c912018-01-20 01:24:31 +01008146 /* Checking interpreter vs JIT wrt signed extended imms. */
8147 {
8148 "JNE signed compare, test 1",
8149 .u.insns_int = {
8150 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8151 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8152 BPF_MOV64_REG(R2, R1),
8153 BPF_ALU64_REG(BPF_AND, R2, R3),
8154 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8155 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
8156 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8157 BPF_EXIT_INSN(),
8158 },
8159 INTERNAL,
8160 { },
8161 { { 0, 1 } },
8162 },
8163 {
8164 "JNE signed compare, test 2",
8165 .u.insns_int = {
8166 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8167 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8168 BPF_MOV64_REG(R2, R1),
8169 BPF_ALU64_REG(BPF_AND, R2, R3),
8170 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8171 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
8172 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8173 BPF_EXIT_INSN(),
8174 },
8175 INTERNAL,
8176 { },
8177 { { 0, 1 } },
8178 },
8179 {
8180 "JNE signed compare, test 3",
8181 .u.insns_int = {
8182 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8183 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8184 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
8185 BPF_MOV64_REG(R2, R1),
8186 BPF_ALU64_REG(BPF_AND, R2, R3),
8187 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8188 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
8189 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8190 BPF_EXIT_INSN(),
8191 },
8192 INTERNAL,
8193 { },
8194 { { 0, 2 } },
8195 },
8196 {
8197 "JNE signed compare, test 4",
8198 .u.insns_int = {
8199 BPF_LD_IMM64(R1, -17104896),
8200 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8201 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
8202 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8203 BPF_EXIT_INSN(),
8204 },
8205 INTERNAL,
8206 { },
8207 { { 0, 2 } },
8208 },
8209 {
8210 "JNE signed compare, test 5",
8211 .u.insns_int = {
8212 BPF_LD_IMM64(R1, 0xfefb0000),
8213 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8214 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
8215 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8216 BPF_EXIT_INSN(),
8217 },
8218 INTERNAL,
8219 { },
8220 { { 0, 1 } },
8221 },
8222 {
8223 "JNE signed compare, test 6",
8224 .u.insns_int = {
8225 BPF_LD_IMM64(R1, 0x7efb0000),
8226 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8227 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
8228 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8229 BPF_EXIT_INSN(),
8230 },
8231 INTERNAL,
8232 { },
8233 { { 0, 2 } },
8234 },
8235 {
8236 "JNE signed compare, test 7",
8237 .u.insns = {
8238 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
8239 BPF_STMT(BPF_MISC | BPF_TAX, 0),
8240 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
8241 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
8242 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
8243 BPF_STMT(BPF_RET | BPF_K, 1),
8244 BPF_STMT(BPF_RET | BPF_K, 2),
8245 },
8246 CLASSIC | FLAG_NO_DATA,
8247 {},
8248 { { 0, 2 } },
8249 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008250};
8251
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008252static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008253
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008254static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008255{
8256 struct sk_buff *skb;
8257
8258 if (size >= MAX_DATA)
8259 return NULL;
8260
8261 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
8262 if (!skb)
8263 return NULL;
8264
yuan linyude77b962017-06-18 22:48:17 +08008265 __skb_put_data(skb, buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008266
8267 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008268 skb_reset_mac_header(skb);
8269 skb->protocol = htons(ETH_P_IP);
8270 skb->pkt_type = SKB_TYPE;
8271 skb->mark = SKB_MARK;
8272 skb->hash = SKB_HASH;
8273 skb->queue_mapping = SKB_QUEUE_MAP;
8274 skb->vlan_tci = SKB_VLAN_TCI;
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01008275 skb->vlan_present = SKB_VLAN_PRESENT;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01008276 skb->vlan_proto = htons(ETH_P_IP);
Song Liu100811932018-09-27 09:34:41 -07008277 dev_net_set(&dev, &init_net);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008278 skb->dev = &dev;
8279 skb->dev->ifindex = SKB_DEV_IFINDEX;
8280 skb->dev->type = SKB_DEV_TYPE;
8281 skb_set_network_header(skb, min(size, ETH_HLEN));
8282
8283 return skb;
8284}
8285
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008286static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008287{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02008288 struct sk_buff *skb;
8289 struct page *page;
8290
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008291 if (test->aux & FLAG_NO_DATA)
8292 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008293
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008294 /* Test case expects an skb, so populate one. Various
8295 * subtests generate skbs of different sizes based on
8296 * the same data.
8297 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02008298 skb = populate_skb(test->data, test->test[sub].data_size);
8299 if (!skb)
8300 return NULL;
8301
8302 if (test->aux & FLAG_SKB_FRAG) {
8303 /*
8304 * when the test requires a fragmented skb, add a
8305 * single fragment to the skb, filled with
8306 * test->frag_data.
8307 */
8308 void *ptr;
8309
8310 page = alloc_page(GFP_KERNEL);
8311
8312 if (!page)
8313 goto err_kfree_skb;
8314
8315 ptr = kmap(page);
8316 if (!ptr)
8317 goto err_free_page;
8318 memcpy(ptr, test->frag_data, MAX_DATA);
8319 kunmap(page);
8320 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
8321 }
8322
8323 return skb;
8324
8325err_free_page:
8326 __free_page(page);
8327err_kfree_skb:
8328 kfree_skb(skb);
8329 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008330}
8331
8332static void release_test_data(const struct bpf_test *test, void *data)
8333{
8334 if (test->aux & FLAG_NO_DATA)
8335 return;
8336
8337 kfree_skb(data);
8338}
8339
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008340static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008341{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008342 struct sock_filter *fp;
8343 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008344
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008345 if (tests[which].fill_helper)
8346 return tests[which].u.ptr.len;
8347
8348 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07008349 for (len = MAX_INSNS - 1; len > 0; --len)
8350 if (fp[len].code != 0 || fp[len].k != 0)
8351 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008352
Chema Gonzaleze9d94502014-05-30 10:15:12 -07008353 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008354}
8355
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008356static void *filter_pointer(int which)
8357{
8358 if (tests[which].fill_helper)
8359 return tests[which].u.ptr.insns;
8360 else
8361 return tests[which].u.insns;
8362}
8363
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008364static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008365{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008366 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008367 unsigned int flen = filter_length(which);
8368 void *fptr = filter_pointer(which);
8369 struct sock_fprog_kern fprog;
8370 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008371
8372 switch (test_type) {
8373 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008374 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008375 fprog.len = flen;
8376
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008377 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008378 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
Yonghong Song09584b42018-02-02 22:37:15 -08008379 if (*err == tests[which].expected_errcode) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008380 pr_cont("PASS\n");
8381 /* Verifier rejected filter as expected. */
8382 *err = 0;
8383 return NULL;
8384 } else {
8385 pr_cont("UNEXPECTED_PASS\n");
8386 /* Verifier didn't reject the test that's
8387 * bad enough, just return!
8388 */
8389 *err = -EINVAL;
8390 return NULL;
8391 }
8392 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008393 if (*err) {
Alexei Starovoitov290af862018-01-09 10:04:29 -08008394 pr_cont("FAIL to prog_create err=%d len=%d\n",
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008395 *err, fprog.len);
8396 return NULL;
8397 }
8398 break;
8399
8400 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02008401 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008402 if (fp == NULL) {
8403 pr_cont("UNEXPECTED_FAIL no memory left\n");
8404 *err = -ENOMEM;
8405 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008406 }
8407
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008408 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02008409 /* Type doesn't really matter here as long as it's not unspec. */
8410 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008411 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07008412 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008413
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02008414 /* We cannot error here as we don't need type compatibility
8415 * checks.
8416 */
8417 fp = bpf_prog_select_runtime(fp, err);
Alexei Starovoitov290af862018-01-09 10:04:29 -08008418 if (*err) {
8419 pr_cont("FAIL to select_runtime err=%d\n", *err);
8420 return NULL;
8421 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008422 break;
8423 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008424
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008425 *err = 0;
8426 return fp;
8427}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008428
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008429static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008430{
8431 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008432
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008433 switch (test_type) {
8434 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008435 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008436 break;
8437 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008438 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008439 break;
8440 }
8441}
8442
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008443static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008444 int runs, u64 *duration)
8445{
8446 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07008447 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008448
David Miller6eac7792020-02-24 15:01:44 +01008449 migrate_disable();
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008450 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008451
8452 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008453 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008454
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008455 finish = ktime_get_ns();
David Miller6eac7792020-02-24 15:01:44 +01008456 migrate_enable();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008457
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008458 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008459 do_div(*duration, runs);
8460
8461 return ret;
8462}
8463
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008464static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008465{
8466 int err_cnt = 0, i, runs = MAX_TESTRUNS;
8467
8468 for (i = 0; i < MAX_SUBTESTS; i++) {
8469 void *data;
8470 u64 duration;
8471 u32 ret;
8472
Johan Almbladh2b7e9f22021-07-21 12:38:22 +02008473 /*
8474 * NOTE: Several sub-tests may be present, in which case
8475 * a zero {data_size, result} tuple indicates the end of
8476 * the sub-test array. The first test is always run,
8477 * even if both data_size and result happen to be zero.
8478 */
8479 if (i > 0 &&
8480 test->test[i].data_size == 0 &&
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008481 test->test[i].result == 0)
8482 break;
8483
8484 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02008485 if (!data && !(test->aux & FLAG_NO_DATA)) {
8486 pr_cont("data generation failed ");
8487 err_cnt++;
8488 break;
8489 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008490 ret = __run_one(fp, data, runs, &duration);
8491 release_test_data(test, data);
8492
8493 if (ret == test->test[i].result) {
8494 pr_cont("%lld ", duration);
8495 } else {
8496 pr_cont("ret %d != %d ", ret,
8497 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008498 err_cnt++;
8499 }
8500 }
8501
8502 return err_cnt;
8503}
8504
Nicolas Schichand2648d42015-08-04 15:19:10 +02008505static char test_name[64];
8506module_param_string(test_name, test_name, sizeof(test_name), 0);
8507
8508static int test_id = -1;
8509module_param(test_id, int, 0);
8510
8511static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
8512module_param_array(test_range, int, NULL, 0);
8513
8514static __init int find_test_index(const char *test_name)
8515{
8516 int i;
8517
8518 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8519 if (!strcmp(tests[i].descr, test_name))
8520 return i;
8521 }
8522 return -1;
8523}
8524
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008525static __init int prepare_bpf_tests(void)
8526{
8527 int i;
8528
Nicolas Schichand2648d42015-08-04 15:19:10 +02008529 if (test_id >= 0) {
8530 /*
8531 * if a test_id was specified, use test_range to
8532 * cover only that test.
8533 */
8534 if (test_id >= ARRAY_SIZE(tests)) {
8535 pr_err("test_bpf: invalid test_id specified.\n");
8536 return -EINVAL;
8537 }
8538
8539 test_range[0] = test_id;
8540 test_range[1] = test_id;
8541 } else if (*test_name) {
8542 /*
8543 * if a test_name was specified, find it and setup
8544 * test_range to cover only that test.
8545 */
8546 int idx = find_test_index(test_name);
8547
8548 if (idx < 0) {
8549 pr_err("test_bpf: no test named '%s' found.\n",
8550 test_name);
8551 return -EINVAL;
8552 }
8553 test_range[0] = idx;
8554 test_range[1] = idx;
8555 } else {
8556 /*
8557 * check that the supplied test_range is valid.
8558 */
8559 if (test_range[0] >= ARRAY_SIZE(tests) ||
8560 test_range[1] >= ARRAY_SIZE(tests) ||
8561 test_range[0] < 0 || test_range[1] < 0) {
8562 pr_err("test_bpf: test_range is out of bound.\n");
8563 return -EINVAL;
8564 }
8565
8566 if (test_range[1] < test_range[0]) {
8567 pr_err("test_bpf: test_range is ending before it starts.\n");
8568 return -EINVAL;
8569 }
8570 }
8571
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008572 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8573 if (tests[i].fill_helper &&
8574 tests[i].fill_helper(&tests[i]) < 0)
8575 return -ENOMEM;
8576 }
8577
8578 return 0;
8579}
8580
8581static __init void destroy_bpf_tests(void)
8582{
8583 int i;
8584
8585 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8586 if (tests[i].fill_helper)
8587 kfree(tests[i].u.ptr.insns);
8588 }
8589}
8590
Nicolas Schichand2648d42015-08-04 15:19:10 +02008591static bool exclude_test(int test_id)
8592{
8593 return test_id < test_range[0] || test_id > test_range[1];
8594}
8595
Yonghong Song76db8082018-03-21 16:31:04 -07008596static __init struct sk_buff *build_test_skb(void)
8597{
8598 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
8599 struct sk_buff *skb[2];
8600 struct page *page[2];
8601 int i, data_size = 8;
8602
8603 for (i = 0; i < 2; i++) {
8604 page[i] = alloc_page(GFP_KERNEL);
8605 if (!page[i]) {
8606 if (i == 0)
8607 goto err_page0;
8608 else
8609 goto err_page1;
8610 }
8611
8612 /* this will set skb[i]->head_frag */
8613 skb[i] = dev_alloc_skb(headroom + data_size);
8614 if (!skb[i]) {
8615 if (i == 0)
8616 goto err_skb0;
8617 else
8618 goto err_skb1;
8619 }
8620
8621 skb_reserve(skb[i], headroom);
8622 skb_put(skb[i], data_size);
8623 skb[i]->protocol = htons(ETH_P_IP);
8624 skb_reset_network_header(skb[i]);
8625 skb_set_mac_header(skb[i], -ETH_HLEN);
8626
8627 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
8628 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
8629 }
8630
8631 /* setup shinfo */
8632 skb_shinfo(skb[0])->gso_size = 1448;
8633 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
8634 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
8635 skb_shinfo(skb[0])->gso_segs = 0;
8636 skb_shinfo(skb[0])->frag_list = skb[1];
8637
8638 /* adjust skb[0]'s len */
8639 skb[0]->len += skb[1]->len;
8640 skb[0]->data_len += skb[1]->data_len;
8641 skb[0]->truesize += skb[1]->truesize;
8642
8643 return skb[0];
8644
8645err_skb1:
8646 __free_page(page[1]);
8647err_page1:
8648 kfree_skb(skb[0]);
8649err_skb0:
8650 __free_page(page[0]);
8651err_page0:
8652 return NULL;
8653}
8654
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03008655static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
8656{
8657 unsigned int alloc_size = 2000;
8658 unsigned int headroom = 102, doffset = 72, data_size = 1308;
8659 struct sk_buff *skb[2];
8660 int i;
8661
8662 /* skbs linked in a frag_list, both with linear data, with head_frag=0
8663 * (data allocated by kmalloc), both have tcp data of 1308 bytes
8664 * (total payload is 2616 bytes).
8665 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
8666 */
8667 for (i = 0; i < 2; i++) {
8668 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
8669 if (!skb[i]) {
8670 if (i == 0)
8671 goto err_skb0;
8672 else
8673 goto err_skb1;
8674 }
8675
8676 skb[i]->protocol = htons(ETH_P_IPV6);
8677 skb_reserve(skb[i], headroom);
8678 skb_put(skb[i], doffset + data_size);
8679 skb_reset_network_header(skb[i]);
8680 if (i == 0)
8681 skb_reset_mac_header(skb[i]);
8682 else
8683 skb_set_mac_header(skb[i], -ETH_HLEN);
8684 __skb_pull(skb[i], doffset);
8685 }
8686
8687 /* setup shinfo.
8688 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
8689 * reduced gso_size.
8690 */
8691 skb_shinfo(skb[0])->gso_size = 1288;
8692 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
8693 skb_shinfo(skb[0])->gso_segs = 0;
8694 skb_shinfo(skb[0])->frag_list = skb[1];
8695
8696 /* adjust skb[0]'s len */
8697 skb[0]->len += skb[1]->len;
8698 skb[0]->data_len += skb[1]->len;
8699 skb[0]->truesize += skb[1]->truesize;
8700
8701 return skb[0];
8702
8703err_skb1:
8704 kfree_skb(skb[0]);
8705err_skb0:
8706 return NULL;
8707}
8708
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008709struct skb_segment_test {
8710 const char *descr;
8711 struct sk_buff *(*build_skb)(void);
Yonghong Song76db8082018-03-21 16:31:04 -07008712 netdev_features_t features;
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008713};
8714
8715static struct skb_segment_test skb_segment_tests[] __initconst = {
8716 {
8717 .descr = "gso_with_rx_frags",
8718 .build_skb = build_test_skb,
8719 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
8720 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03008721 },
8722 {
8723 .descr = "gso_linear_no_head_frag",
8724 .build_skb = build_test_skb_linear_no_head_frag,
8725 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
8726 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
8727 NETIF_F_LLTX_BIT | NETIF_F_GRO |
8728 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
8729 NETIF_F_HW_VLAN_STAG_TX_BIT
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008730 }
8731};
8732
8733static __init int test_skb_segment_single(const struct skb_segment_test *test)
8734{
Yonghong Song76db8082018-03-21 16:31:04 -07008735 struct sk_buff *skb, *segs;
8736 int ret = -1;
8737
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008738 skb = test->build_skb();
Yonghong Song76db8082018-03-21 16:31:04 -07008739 if (!skb) {
8740 pr_info("%s: failed to build_test_skb", __func__);
8741 goto done;
8742 }
8743
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008744 segs = skb_segment(skb, test->features);
Dan Carpenter99fe29d2018-03-28 14:48:36 +03008745 if (!IS_ERR(segs)) {
Yonghong Song76db8082018-03-21 16:31:04 -07008746 kfree_skb_list(segs);
8747 ret = 0;
Yonghong Song76db8082018-03-21 16:31:04 -07008748 }
8749 kfree_skb(skb);
8750done:
8751 return ret;
8752}
8753
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008754static __init int test_skb_segment(void)
8755{
8756 int i, err_cnt = 0, pass_cnt = 0;
8757
8758 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
8759 const struct skb_segment_test *test = &skb_segment_tests[i];
8760
8761 pr_info("#%d %s ", i, test->descr);
8762
8763 if (test_skb_segment_single(test)) {
8764 pr_cont("FAIL\n");
8765 err_cnt++;
8766 } else {
8767 pr_cont("PASS\n");
8768 pass_cnt++;
8769 }
8770 }
8771
8772 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
8773 pass_cnt, err_cnt);
8774 return err_cnt ? -EINVAL : 0;
8775}
8776
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008777static __init int test_bpf(void)
8778{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008779 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02008780 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008781
8782 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008783 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008784 int err;
8785
Eric Dumazetd40bc962018-02-26 10:52:46 -08008786 cond_resched();
Nicolas Schichand2648d42015-08-04 15:19:10 +02008787 if (exclude_test(i))
8788 continue;
8789
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008790 pr_info("#%d %s ", i, tests[i].descr);
8791
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008792 fp = generate_filter(i, &err);
8793 if (fp == NULL) {
8794 if (err == 0) {
8795 pass_cnt++;
8796 continue;
8797 }
Alexei Starovoitov290af862018-01-09 10:04:29 -08008798 err_cnt++;
8799 continue;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008800 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02008801
8802 pr_cont("jited:%u ", fp->jited);
8803
8804 run_cnt++;
8805 if (fp->jited)
8806 jit_cnt++;
8807
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008808 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008809 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008810
8811 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008812 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008813 err_cnt++;
8814 } else {
8815 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008816 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008817 }
8818 }
8819
Daniel Borkmann327941f2015-04-30 16:17:27 +02008820 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
8821 pass_cnt, err_cnt, jit_cnt, run_cnt);
8822
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008823 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008824}
8825
8826static int __init test_bpf_init(void)
8827{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008828 int ret;
8829
8830 ret = prepare_bpf_tests();
8831 if (ret < 0)
8832 return ret;
8833
8834 ret = test_bpf();
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008835 destroy_bpf_tests();
Yonghong Song76db8082018-03-21 16:31:04 -07008836 if (ret)
8837 return ret;
8838
8839 return test_skb_segment();
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008840}
8841
8842static void __exit test_bpf_exit(void)
8843{
8844}
8845
8846module_init(test_bpf_init);
8847module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008848
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008849MODULE_LICENSE("GPL");