KVM: MTRR: Use default type for non-MTRR-covered gfn before WARN_ON
[linux/fpc-iii.git] / lib / test_bpf.c
blob7f58c735d745049025407806e972bb4c7f124888
1 /*
2 * Testsuite for BPF interpreter and BPF JIT compiler
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/filter.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_vlan.h>
24 #include <linux/random.h>
26 /* General test specific settings */
27 #define MAX_SUBTESTS 3
28 #define MAX_TESTRUNS 10000
29 #define MAX_DATA 128
30 #define MAX_INSNS 512
31 #define MAX_K 0xffffFFFF
33 /* Few constants used to init test 'skb' */
34 #define SKB_TYPE 3
35 #define SKB_MARK 0x1234aaaa
36 #define SKB_HASH 0x1234aaab
37 #define SKB_QUEUE_MAP 123
38 #define SKB_VLAN_TCI 0xffff
39 #define SKB_DEV_IFINDEX 577
40 #define SKB_DEV_TYPE 588
42 /* Redefine REGs to make tests less verbose */
43 #define R0 BPF_REG_0
44 #define R1 BPF_REG_1
45 #define R2 BPF_REG_2
46 #define R3 BPF_REG_3
47 #define R4 BPF_REG_4
48 #define R5 BPF_REG_5
49 #define R6 BPF_REG_6
50 #define R7 BPF_REG_7
51 #define R8 BPF_REG_8
52 #define R9 BPF_REG_9
53 #define R10 BPF_REG_10
55 /* Flags that can be passed to test cases */
56 #define FLAG_NO_DATA BIT(0)
57 #define FLAG_EXPECTED_FAIL BIT(1)
59 enum {
60 CLASSIC = BIT(6), /* Old BPF instructions only. */
61 INTERNAL = BIT(7), /* Extended instruction set. */
64 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
66 struct bpf_test {
67 const char *descr;
68 union {
69 struct sock_filter insns[MAX_INSNS];
70 struct bpf_insn insns_int[MAX_INSNS];
71 struct {
72 void *insns;
73 unsigned int len;
74 } ptr;
75 } u;
76 __u8 aux;
77 __u8 data[MAX_DATA];
78 struct {
79 int data_size;
80 __u32 result;
81 } test[MAX_SUBTESTS];
82 int (*fill_helper)(struct bpf_test *self);
85 /* Large test cases need separate allocation and fill handler. */
87 static int bpf_fill_maxinsns1(struct bpf_test *self)
89 unsigned int len = BPF_MAXINSNS;
90 struct sock_filter *insn;
91 __u32 k = ~0;
92 int i;
94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
95 if (!insn)
96 return -ENOMEM;
98 for (i = 0; i < len; i++, k--)
99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
101 self->u.ptr.insns = insn;
102 self->u.ptr.len = len;
104 return 0;
107 static int bpf_fill_maxinsns2(struct bpf_test *self)
109 unsigned int len = BPF_MAXINSNS;
110 struct sock_filter *insn;
111 int i;
113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
114 if (!insn)
115 return -ENOMEM;
117 for (i = 0; i < len; i++)
118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
120 self->u.ptr.insns = insn;
121 self->u.ptr.len = len;
123 return 0;
126 static int bpf_fill_maxinsns3(struct bpf_test *self)
128 unsigned int len = BPF_MAXINSNS;
129 struct sock_filter *insn;
130 struct rnd_state rnd;
131 int i;
133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
134 if (!insn)
135 return -ENOMEM;
137 prandom_seed_state(&rnd, 3141592653589793238ULL);
139 for (i = 0; i < len - 1; i++) {
140 __u32 k = prandom_u32_state(&rnd);
142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
147 self->u.ptr.insns = insn;
148 self->u.ptr.len = len;
150 return 0;
153 static int bpf_fill_maxinsns4(struct bpf_test *self)
155 unsigned int len = BPF_MAXINSNS + 1;
156 struct sock_filter *insn;
157 int i;
159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
160 if (!insn)
161 return -ENOMEM;
163 for (i = 0; i < len; i++)
164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
166 self->u.ptr.insns = insn;
167 self->u.ptr.len = len;
169 return 0;
172 static int bpf_fill_maxinsns5(struct bpf_test *self)
174 unsigned int len = BPF_MAXINSNS;
175 struct sock_filter *insn;
176 int i;
178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
179 if (!insn)
180 return -ENOMEM;
182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
184 for (i = 1; i < len - 1; i++)
185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
189 self->u.ptr.insns = insn;
190 self->u.ptr.len = len;
192 return 0;
195 static int bpf_fill_maxinsns6(struct bpf_test *self)
197 unsigned int len = BPF_MAXINSNS;
198 struct sock_filter *insn;
199 int i;
201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
202 if (!insn)
203 return -ENOMEM;
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);
209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
211 self->u.ptr.insns = insn;
212 self->u.ptr.len = len;
214 return 0;
217 static int bpf_fill_maxinsns7(struct bpf_test *self)
219 unsigned int len = BPF_MAXINSNS;
220 struct sock_filter *insn;
221 int i;
223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
224 if (!insn)
225 return -ENOMEM;
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);
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);
237 self->u.ptr.insns = insn;
238 self->u.ptr.len = len;
240 return 0;
243 static int bpf_fill_maxinsns8(struct bpf_test *self)
245 unsigned int len = BPF_MAXINSNS;
246 struct sock_filter *insn;
247 int i, jmp_off = len - 3;
249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
250 if (!insn)
251 return -ENOMEM;
253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
255 for (i = 1; i < len - 1; i++)
256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
260 self->u.ptr.insns = insn;
261 self->u.ptr.len = len;
263 return 0;
266 static int bpf_fill_maxinsns9(struct bpf_test *self)
268 unsigned int len = BPF_MAXINSNS;
269 struct bpf_insn *insn;
270 int i;
272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
273 if (!insn)
274 return -ENOMEM;
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();
280 for (i = 3; i < len - 2; i++)
281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
283 insn[len - 2] = BPF_EXIT_INSN();
284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
286 self->u.ptr.insns = insn;
287 self->u.ptr.len = len;
289 return 0;
292 static int bpf_fill_maxinsns10(struct bpf_test *self)
294 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
295 struct bpf_insn *insn;
296 int i;
298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
299 if (!insn)
300 return -ENOMEM;
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);
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();
311 self->u.ptr.insns = insn;
312 self->u.ptr.len = len;
314 return 0;
317 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
318 unsigned int plen)
320 struct sock_filter *insn;
321 unsigned int rlen;
322 int i, j;
324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
325 if (!insn)
326 return -ENOMEM;
328 rlen = (len % plen) - 1;
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);
338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
340 self->u.ptr.insns = insn;
341 self->u.ptr.len = len;
343 return 0;
346 static int bpf_fill_maxinsns11(struct bpf_test *self)
348 /* Hits 70 passes on x86_64, so cannot get JITed there. */
349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
352 static int bpf_fill_ja(struct bpf_test *self)
354 /* Hits exactly 11 passes on x86_64 JIT. */
355 return __bpf_fill_ja(self, 12, 9);
358 static struct bpf_test tests[] = {
360 "TAX",
361 .u.insns = {
362 BPF_STMT(BPF_LD | BPF_IMM, 1),
363 BPF_STMT(BPF_MISC | BPF_TAX, 0),
364 BPF_STMT(BPF_LD | BPF_IMM, 2),
365 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
366 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
367 BPF_STMT(BPF_MISC | BPF_TAX, 0),
368 BPF_STMT(BPF_LD | BPF_LEN, 0),
369 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
370 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
371 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
372 BPF_STMT(BPF_RET | BPF_A, 0)
374 CLASSIC,
375 { 10, 20, 30, 40, 50 },
376 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
379 "TXA",
380 .u.insns = {
381 BPF_STMT(BPF_LDX | BPF_LEN, 0),
382 BPF_STMT(BPF_MISC | BPF_TXA, 0),
383 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
384 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
386 CLASSIC,
387 { 10, 20, 30, 40, 50 },
388 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
391 "ADD_SUB_MUL_K",
392 .u.insns = {
393 BPF_STMT(BPF_LD | BPF_IMM, 1),
394 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
395 BPF_STMT(BPF_LDX | BPF_IMM, 3),
396 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
397 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
398 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
399 BPF_STMT(BPF_RET | BPF_A, 0)
401 CLASSIC | FLAG_NO_DATA,
402 { },
403 { { 0, 0xfffffffd } }
406 "DIV_MOD_KX",
407 .u.insns = {
408 BPF_STMT(BPF_LD | BPF_IMM, 8),
409 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
410 BPF_STMT(BPF_MISC | BPF_TAX, 0),
411 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
412 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
413 BPF_STMT(BPF_MISC | BPF_TAX, 0),
414 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
415 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
416 BPF_STMT(BPF_MISC | BPF_TAX, 0),
417 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
418 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
419 BPF_STMT(BPF_MISC | BPF_TAX, 0),
420 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
421 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
422 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
423 BPF_STMT(BPF_RET | BPF_A, 0)
425 CLASSIC | FLAG_NO_DATA,
426 { },
427 { { 0, 0x20000000 } }
430 "AND_OR_LSH_K",
431 .u.insns = {
432 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
433 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
434 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
435 BPF_STMT(BPF_MISC | BPF_TAX, 0),
436 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
437 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
438 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
439 BPF_STMT(BPF_RET | BPF_A, 0)
441 CLASSIC | FLAG_NO_DATA,
442 { },
443 { { 0, 0x800000ff }, { 1, 0x800000ff } },
446 "LD_IMM_0",
447 .u.insns = {
448 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
449 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
450 BPF_STMT(BPF_RET | BPF_K, 0),
451 BPF_STMT(BPF_RET | BPF_K, 1),
453 CLASSIC,
454 { },
455 { { 1, 1 } },
458 "LD_IND",
459 .u.insns = {
460 BPF_STMT(BPF_LDX | BPF_LEN, 0),
461 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
462 BPF_STMT(BPF_RET | BPF_K, 1)
464 CLASSIC,
465 { },
466 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
469 "LD_ABS",
470 .u.insns = {
471 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
472 BPF_STMT(BPF_RET | BPF_K, 1)
474 CLASSIC,
475 { },
476 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
479 "LD_ABS_LL",
480 .u.insns = {
481 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
482 BPF_STMT(BPF_MISC | BPF_TAX, 0),
483 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
484 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
485 BPF_STMT(BPF_RET | BPF_A, 0)
487 CLASSIC,
488 { 1, 2, 3 },
489 { { 1, 0 }, { 2, 3 } },
492 "LD_IND_LL",
493 .u.insns = {
494 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
495 BPF_STMT(BPF_LDX | BPF_LEN, 0),
496 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
497 BPF_STMT(BPF_MISC | BPF_TAX, 0),
498 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
499 BPF_STMT(BPF_RET | BPF_A, 0)
501 CLASSIC,
502 { 1, 2, 3, 0xff },
503 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
506 "LD_ABS_NET",
507 .u.insns = {
508 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
509 BPF_STMT(BPF_MISC | BPF_TAX, 0),
510 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
511 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
512 BPF_STMT(BPF_RET | BPF_A, 0)
514 CLASSIC,
515 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
516 { { 15, 0 }, { 16, 3 } },
519 "LD_IND_NET",
520 .u.insns = {
521 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
522 BPF_STMT(BPF_LDX | BPF_LEN, 0),
523 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
524 BPF_STMT(BPF_MISC | BPF_TAX, 0),
525 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
526 BPF_STMT(BPF_RET | BPF_A, 0)
528 CLASSIC,
529 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
530 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
533 "LD_PKTTYPE",
534 .u.insns = {
535 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
536 SKF_AD_OFF + SKF_AD_PKTTYPE),
537 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
538 BPF_STMT(BPF_RET | BPF_K, 1),
539 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
540 SKF_AD_OFF + SKF_AD_PKTTYPE),
541 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
542 BPF_STMT(BPF_RET | BPF_K, 1),
543 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
544 SKF_AD_OFF + SKF_AD_PKTTYPE),
545 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
546 BPF_STMT(BPF_RET | BPF_K, 1),
547 BPF_STMT(BPF_RET | BPF_A, 0)
549 CLASSIC,
550 { },
551 { { 1, 3 }, { 10, 3 } },
554 "LD_MARK",
555 .u.insns = {
556 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
557 SKF_AD_OFF + SKF_AD_MARK),
558 BPF_STMT(BPF_RET | BPF_A, 0)
560 CLASSIC,
561 { },
562 { { 1, SKB_MARK}, { 10, SKB_MARK} },
565 "LD_RXHASH",
566 .u.insns = {
567 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
568 SKF_AD_OFF + SKF_AD_RXHASH),
569 BPF_STMT(BPF_RET | BPF_A, 0)
571 CLASSIC,
572 { },
573 { { 1, SKB_HASH}, { 10, SKB_HASH} },
576 "LD_QUEUE",
577 .u.insns = {
578 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
579 SKF_AD_OFF + SKF_AD_QUEUE),
580 BPF_STMT(BPF_RET | BPF_A, 0)
582 CLASSIC,
583 { },
584 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
587 "LD_PROTOCOL",
588 .u.insns = {
589 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
591 BPF_STMT(BPF_RET | BPF_K, 0),
592 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
593 SKF_AD_OFF + SKF_AD_PROTOCOL),
594 BPF_STMT(BPF_MISC | BPF_TAX, 0),
595 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
596 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
597 BPF_STMT(BPF_RET | BPF_K, 0),
598 BPF_STMT(BPF_MISC | BPF_TXA, 0),
599 BPF_STMT(BPF_RET | BPF_A, 0)
601 CLASSIC,
602 { 10, 20, 30 },
603 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
606 "LD_VLAN_TAG",
607 .u.insns = {
608 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
609 SKF_AD_OFF + SKF_AD_VLAN_TAG),
610 BPF_STMT(BPF_RET | BPF_A, 0)
612 CLASSIC,
613 { },
615 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
616 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
620 "LD_VLAN_TAG_PRESENT",
621 .u.insns = {
622 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
623 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
624 BPF_STMT(BPF_RET | BPF_A, 0)
626 CLASSIC,
627 { },
629 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
630 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
634 "LD_IFINDEX",
635 .u.insns = {
636 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
637 SKF_AD_OFF + SKF_AD_IFINDEX),
638 BPF_STMT(BPF_RET | BPF_A, 0)
640 CLASSIC,
641 { },
642 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
645 "LD_HATYPE",
646 .u.insns = {
647 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
648 SKF_AD_OFF + SKF_AD_HATYPE),
649 BPF_STMT(BPF_RET | BPF_A, 0)
651 CLASSIC,
652 { },
653 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
656 "LD_CPU",
657 .u.insns = {
658 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
659 SKF_AD_OFF + SKF_AD_CPU),
660 BPF_STMT(BPF_MISC | BPF_TAX, 0),
661 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
662 SKF_AD_OFF + SKF_AD_CPU),
663 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
664 BPF_STMT(BPF_RET | BPF_A, 0)
666 CLASSIC,
667 { },
668 { { 1, 0 }, { 10, 0 } },
671 "LD_NLATTR",
672 .u.insns = {
673 BPF_STMT(BPF_LDX | BPF_IMM, 2),
674 BPF_STMT(BPF_MISC | BPF_TXA, 0),
675 BPF_STMT(BPF_LDX | BPF_IMM, 3),
676 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
677 SKF_AD_OFF + SKF_AD_NLATTR),
678 BPF_STMT(BPF_RET | BPF_A, 0)
680 CLASSIC,
681 #ifdef __BIG_ENDIAN
682 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
683 #else
684 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
685 #endif
686 { { 4, 0 }, { 20, 6 } },
689 "LD_NLATTR_NEST",
690 .u.insns = {
691 BPF_STMT(BPF_LD | BPF_IMM, 2),
692 BPF_STMT(BPF_LDX | BPF_IMM, 3),
693 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
694 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
695 BPF_STMT(BPF_LD | BPF_IMM, 2),
696 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
697 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
698 BPF_STMT(BPF_LD | BPF_IMM, 2),
699 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
700 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
701 BPF_STMT(BPF_LD | BPF_IMM, 2),
702 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
703 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
704 BPF_STMT(BPF_LD | BPF_IMM, 2),
705 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
706 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
707 BPF_STMT(BPF_LD | BPF_IMM, 2),
708 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
709 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
710 BPF_STMT(BPF_LD | BPF_IMM, 2),
711 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
712 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
713 BPF_STMT(BPF_LD | BPF_IMM, 2),
714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
715 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
716 BPF_STMT(BPF_RET | BPF_A, 0)
718 CLASSIC,
719 #ifdef __BIG_ENDIAN
720 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
721 #else
722 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
723 #endif
724 { { 4, 0 }, { 20, 10 } },
727 "LD_PAYLOAD_OFF",
728 .u.insns = {
729 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
730 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
731 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
732 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
733 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
734 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
735 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
736 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
737 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
738 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
739 BPF_STMT(BPF_RET | BPF_A, 0)
741 CLASSIC,
742 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
743 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
744 * id 9737, seq 1, length 64
746 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
747 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
748 0x08, 0x00,
749 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
750 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
751 { { 30, 0 }, { 100, 42 } },
754 "LD_ANC_XOR",
755 .u.insns = {
756 BPF_STMT(BPF_LD | BPF_IMM, 10),
757 BPF_STMT(BPF_LDX | BPF_IMM, 300),
758 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
759 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
760 BPF_STMT(BPF_RET | BPF_A, 0)
762 CLASSIC,
763 { },
764 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
767 "SPILL_FILL",
768 .u.insns = {
769 BPF_STMT(BPF_LDX | BPF_LEN, 0),
770 BPF_STMT(BPF_LD | BPF_IMM, 2),
771 BPF_STMT(BPF_ALU | BPF_RSH, 1),
772 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
773 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
774 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
775 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
776 BPF_STMT(BPF_STX, 15), /* M3 = len */
777 BPF_STMT(BPF_LDX | BPF_MEM, 1),
778 BPF_STMT(BPF_LD | BPF_MEM, 2),
779 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
780 BPF_STMT(BPF_LDX | BPF_MEM, 15),
781 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
782 BPF_STMT(BPF_RET | BPF_A, 0)
784 CLASSIC,
785 { },
786 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
789 "JEQ",
790 .u.insns = {
791 BPF_STMT(BPF_LDX | BPF_LEN, 0),
792 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
793 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
794 BPF_STMT(BPF_RET | BPF_K, 1),
795 BPF_STMT(BPF_RET | BPF_K, MAX_K)
797 CLASSIC,
798 { 3, 3, 3, 3, 3 },
799 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
802 "JGT",
803 .u.insns = {
804 BPF_STMT(BPF_LDX | BPF_LEN, 0),
805 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
806 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
807 BPF_STMT(BPF_RET | BPF_K, 1),
808 BPF_STMT(BPF_RET | BPF_K, MAX_K)
810 CLASSIC,
811 { 4, 4, 4, 3, 3 },
812 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
815 "JGE",
816 .u.insns = {
817 BPF_STMT(BPF_LDX | BPF_LEN, 0),
818 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
819 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
820 BPF_STMT(BPF_RET | BPF_K, 10),
821 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
822 BPF_STMT(BPF_RET | BPF_K, 20),
823 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
824 BPF_STMT(BPF_RET | BPF_K, 30),
825 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
826 BPF_STMT(BPF_RET | BPF_K, 40),
827 BPF_STMT(BPF_RET | BPF_K, MAX_K)
829 CLASSIC,
830 { 1, 2, 3, 4, 5 },
831 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
834 "JSET",
835 .u.insns = {
836 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
837 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
838 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
839 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
840 BPF_STMT(BPF_LDX | BPF_LEN, 0),
841 BPF_STMT(BPF_MISC | BPF_TXA, 0),
842 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
843 BPF_STMT(BPF_MISC | BPF_TAX, 0),
844 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
845 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
846 BPF_STMT(BPF_RET | BPF_K, 10),
847 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
848 BPF_STMT(BPF_RET | BPF_K, 20),
849 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
850 BPF_STMT(BPF_RET | BPF_K, 30),
851 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
852 BPF_STMT(BPF_RET | BPF_K, 30),
853 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
854 BPF_STMT(BPF_RET | BPF_K, 30),
855 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
856 BPF_STMT(BPF_RET | BPF_K, 30),
857 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
858 BPF_STMT(BPF_RET | BPF_K, 30),
859 BPF_STMT(BPF_RET | BPF_K, MAX_K)
861 CLASSIC,
862 { 0, 0xAA, 0x55, 1 },
863 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
866 "tcpdump port 22",
867 .u.insns = {
868 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
869 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
870 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
871 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
872 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
873 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
874 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
875 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
876 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
877 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
878 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
879 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
880 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
881 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
882 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
883 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
884 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
885 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
886 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
887 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
888 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
889 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
890 BPF_STMT(BPF_RET | BPF_K, 0xffff),
891 BPF_STMT(BPF_RET | BPF_K, 0),
893 CLASSIC,
894 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
895 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
896 * seq 1305692979:1305693027, ack 3650467037, win 65535,
897 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
899 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
900 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
901 0x08, 0x00,
902 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
903 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
904 0x0a, 0x01, 0x01, 0x95, /* ip src */
905 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
906 0xc2, 0x24,
907 0x00, 0x16 /* dst port */ },
908 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
911 "tcpdump complex",
912 .u.insns = {
913 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
914 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
915 * (len > 115 or len < 30000000000)' -d
917 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
918 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
919 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
920 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
921 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
922 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
923 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
924 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
925 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
926 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
927 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
928 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
929 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
930 BPF_STMT(BPF_ST, 1),
931 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
932 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
933 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
934 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
935 BPF_STMT(BPF_LD | BPF_MEM, 1),
936 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
937 BPF_STMT(BPF_ST, 5),
938 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
939 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
940 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
941 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
942 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
943 BPF_STMT(BPF_LD | BPF_MEM, 5),
944 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
945 BPF_STMT(BPF_LD | BPF_LEN, 0),
946 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
947 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
948 BPF_STMT(BPF_RET | BPF_K, 0xffff),
949 BPF_STMT(BPF_RET | BPF_K, 0),
951 CLASSIC,
952 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
953 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
954 0x08, 0x00,
955 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
956 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
957 0x0a, 0x01, 0x01, 0x95, /* ip src */
958 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
959 0xc2, 0x24,
960 0x00, 0x16 /* dst port */ },
961 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
964 "RET_A",
965 .u.insns = {
966 /* check that unitialized X and A contain zeros */
967 BPF_STMT(BPF_MISC | BPF_TXA, 0),
968 BPF_STMT(BPF_RET | BPF_A, 0)
970 CLASSIC,
971 { },
972 { {1, 0}, {2, 0} },
975 "INT: ADD trivial",
976 .u.insns_int = {
977 BPF_ALU64_IMM(BPF_MOV, R1, 1),
978 BPF_ALU64_IMM(BPF_ADD, R1, 2),
979 BPF_ALU64_IMM(BPF_MOV, R2, 3),
980 BPF_ALU64_REG(BPF_SUB, R1, R2),
981 BPF_ALU64_IMM(BPF_ADD, R1, -1),
982 BPF_ALU64_IMM(BPF_MUL, R1, 3),
983 BPF_ALU64_REG(BPF_MOV, R0, R1),
984 BPF_EXIT_INSN(),
986 INTERNAL,
987 { },
988 { { 0, 0xfffffffd } }
991 "INT: MUL_X",
992 .u.insns_int = {
993 BPF_ALU64_IMM(BPF_MOV, R0, -1),
994 BPF_ALU64_IMM(BPF_MOV, R1, -1),
995 BPF_ALU64_IMM(BPF_MOV, R2, 3),
996 BPF_ALU64_REG(BPF_MUL, R1, R2),
997 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
998 BPF_EXIT_INSN(),
999 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1000 BPF_EXIT_INSN(),
1002 INTERNAL,
1003 { },
1004 { { 0, 1 } }
1007 "INT: MUL_X2",
1008 .u.insns_int = {
1009 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1010 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1011 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1012 BPF_ALU64_REG(BPF_MUL, R1, R2),
1013 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1014 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1015 BPF_EXIT_INSN(),
1016 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1017 BPF_EXIT_INSN(),
1019 INTERNAL,
1020 { },
1021 { { 0, 1 } }
1024 "INT: MUL32_X",
1025 .u.insns_int = {
1026 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1027 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1028 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1029 BPF_ALU32_REG(BPF_MUL, R1, R2),
1030 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1031 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1032 BPF_EXIT_INSN(),
1033 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1034 BPF_EXIT_INSN(),
1036 INTERNAL,
1037 { },
1038 { { 0, 1 } }
1041 /* Have to test all register combinations, since
1042 * JITing of different registers will produce
1043 * different asm code.
1045 "INT: ADD 64-bit",
1046 .u.insns_int = {
1047 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1048 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1049 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1050 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1051 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1052 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1053 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1054 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1055 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1056 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1057 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1058 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1059 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1060 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1061 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1062 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1063 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1064 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1065 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1066 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1067 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1068 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1069 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1070 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1071 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1072 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1073 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1074 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1075 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1076 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1077 BPF_ALU64_REG(BPF_ADD, R0, R0),
1078 BPF_ALU64_REG(BPF_ADD, R0, R1),
1079 BPF_ALU64_REG(BPF_ADD, R0, R2),
1080 BPF_ALU64_REG(BPF_ADD, R0, R3),
1081 BPF_ALU64_REG(BPF_ADD, R0, R4),
1082 BPF_ALU64_REG(BPF_ADD, R0, R5),
1083 BPF_ALU64_REG(BPF_ADD, R0, R6),
1084 BPF_ALU64_REG(BPF_ADD, R0, R7),
1085 BPF_ALU64_REG(BPF_ADD, R0, R8),
1086 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1087 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1088 BPF_EXIT_INSN(),
1089 BPF_ALU64_REG(BPF_ADD, R1, R0),
1090 BPF_ALU64_REG(BPF_ADD, R1, R1),
1091 BPF_ALU64_REG(BPF_ADD, R1, R2),
1092 BPF_ALU64_REG(BPF_ADD, R1, R3),
1093 BPF_ALU64_REG(BPF_ADD, R1, R4),
1094 BPF_ALU64_REG(BPF_ADD, R1, R5),
1095 BPF_ALU64_REG(BPF_ADD, R1, R6),
1096 BPF_ALU64_REG(BPF_ADD, R1, R7),
1097 BPF_ALU64_REG(BPF_ADD, R1, R8),
1098 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1099 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1100 BPF_EXIT_INSN(),
1101 BPF_ALU64_REG(BPF_ADD, R2, R0),
1102 BPF_ALU64_REG(BPF_ADD, R2, R1),
1103 BPF_ALU64_REG(BPF_ADD, R2, R2),
1104 BPF_ALU64_REG(BPF_ADD, R2, R3),
1105 BPF_ALU64_REG(BPF_ADD, R2, R4),
1106 BPF_ALU64_REG(BPF_ADD, R2, R5),
1107 BPF_ALU64_REG(BPF_ADD, R2, R6),
1108 BPF_ALU64_REG(BPF_ADD, R2, R7),
1109 BPF_ALU64_REG(BPF_ADD, R2, R8),
1110 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1111 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1112 BPF_EXIT_INSN(),
1113 BPF_ALU64_REG(BPF_ADD, R3, R0),
1114 BPF_ALU64_REG(BPF_ADD, R3, R1),
1115 BPF_ALU64_REG(BPF_ADD, R3, R2),
1116 BPF_ALU64_REG(BPF_ADD, R3, R3),
1117 BPF_ALU64_REG(BPF_ADD, R3, R4),
1118 BPF_ALU64_REG(BPF_ADD, R3, R5),
1119 BPF_ALU64_REG(BPF_ADD, R3, R6),
1120 BPF_ALU64_REG(BPF_ADD, R3, R7),
1121 BPF_ALU64_REG(BPF_ADD, R3, R8),
1122 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1123 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1124 BPF_EXIT_INSN(),
1125 BPF_ALU64_REG(BPF_ADD, R4, R0),
1126 BPF_ALU64_REG(BPF_ADD, R4, R1),
1127 BPF_ALU64_REG(BPF_ADD, R4, R2),
1128 BPF_ALU64_REG(BPF_ADD, R4, R3),
1129 BPF_ALU64_REG(BPF_ADD, R4, R4),
1130 BPF_ALU64_REG(BPF_ADD, R4, R5),
1131 BPF_ALU64_REG(BPF_ADD, R4, R6),
1132 BPF_ALU64_REG(BPF_ADD, R4, R7),
1133 BPF_ALU64_REG(BPF_ADD, R4, R8),
1134 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1135 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1136 BPF_EXIT_INSN(),
1137 BPF_ALU64_REG(BPF_ADD, R5, R0),
1138 BPF_ALU64_REG(BPF_ADD, R5, R1),
1139 BPF_ALU64_REG(BPF_ADD, R5, R2),
1140 BPF_ALU64_REG(BPF_ADD, R5, R3),
1141 BPF_ALU64_REG(BPF_ADD, R5, R4),
1142 BPF_ALU64_REG(BPF_ADD, R5, R5),
1143 BPF_ALU64_REG(BPF_ADD, R5, R6),
1144 BPF_ALU64_REG(BPF_ADD, R5, R7),
1145 BPF_ALU64_REG(BPF_ADD, R5, R8),
1146 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1147 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1148 BPF_EXIT_INSN(),
1149 BPF_ALU64_REG(BPF_ADD, R6, R0),
1150 BPF_ALU64_REG(BPF_ADD, R6, R1),
1151 BPF_ALU64_REG(BPF_ADD, R6, R2),
1152 BPF_ALU64_REG(BPF_ADD, R6, R3),
1153 BPF_ALU64_REG(BPF_ADD, R6, R4),
1154 BPF_ALU64_REG(BPF_ADD, R6, R5),
1155 BPF_ALU64_REG(BPF_ADD, R6, R6),
1156 BPF_ALU64_REG(BPF_ADD, R6, R7),
1157 BPF_ALU64_REG(BPF_ADD, R6, R8),
1158 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1159 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1160 BPF_EXIT_INSN(),
1161 BPF_ALU64_REG(BPF_ADD, R7, R0),
1162 BPF_ALU64_REG(BPF_ADD, R7, R1),
1163 BPF_ALU64_REG(BPF_ADD, R7, R2),
1164 BPF_ALU64_REG(BPF_ADD, R7, R3),
1165 BPF_ALU64_REG(BPF_ADD, R7, R4),
1166 BPF_ALU64_REG(BPF_ADD, R7, R5),
1167 BPF_ALU64_REG(BPF_ADD, R7, R6),
1168 BPF_ALU64_REG(BPF_ADD, R7, R7),
1169 BPF_ALU64_REG(BPF_ADD, R7, R8),
1170 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1171 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1172 BPF_EXIT_INSN(),
1173 BPF_ALU64_REG(BPF_ADD, R8, R0),
1174 BPF_ALU64_REG(BPF_ADD, R8, R1),
1175 BPF_ALU64_REG(BPF_ADD, R8, R2),
1176 BPF_ALU64_REG(BPF_ADD, R8, R3),
1177 BPF_ALU64_REG(BPF_ADD, R8, R4),
1178 BPF_ALU64_REG(BPF_ADD, R8, R5),
1179 BPF_ALU64_REG(BPF_ADD, R8, R6),
1180 BPF_ALU64_REG(BPF_ADD, R8, R7),
1181 BPF_ALU64_REG(BPF_ADD, R8, R8),
1182 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1183 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1184 BPF_EXIT_INSN(),
1185 BPF_ALU64_REG(BPF_ADD, R9, R0),
1186 BPF_ALU64_REG(BPF_ADD, R9, R1),
1187 BPF_ALU64_REG(BPF_ADD, R9, R2),
1188 BPF_ALU64_REG(BPF_ADD, R9, R3),
1189 BPF_ALU64_REG(BPF_ADD, R9, R4),
1190 BPF_ALU64_REG(BPF_ADD, R9, R5),
1191 BPF_ALU64_REG(BPF_ADD, R9, R6),
1192 BPF_ALU64_REG(BPF_ADD, R9, R7),
1193 BPF_ALU64_REG(BPF_ADD, R9, R8),
1194 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1195 BPF_ALU64_REG(BPF_MOV, R0, R9),
1196 BPF_EXIT_INSN(),
1198 INTERNAL,
1199 { },
1200 { { 0, 2957380 } }
1203 "INT: ADD 32-bit",
1204 .u.insns_int = {
1205 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1206 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1207 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1208 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1209 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1210 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1211 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1212 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1213 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1214 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1215 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1216 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1217 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1218 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1219 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1220 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1221 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1222 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1223 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1224 BPF_ALU32_REG(BPF_ADD, R0, R1),
1225 BPF_ALU32_REG(BPF_ADD, R0, R2),
1226 BPF_ALU32_REG(BPF_ADD, R0, R3),
1227 BPF_ALU32_REG(BPF_ADD, R0, R4),
1228 BPF_ALU32_REG(BPF_ADD, R0, R5),
1229 BPF_ALU32_REG(BPF_ADD, R0, R6),
1230 BPF_ALU32_REG(BPF_ADD, R0, R7),
1231 BPF_ALU32_REG(BPF_ADD, R0, R8),
1232 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1233 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1234 BPF_EXIT_INSN(),
1235 BPF_ALU32_REG(BPF_ADD, R1, R0),
1236 BPF_ALU32_REG(BPF_ADD, R1, R1),
1237 BPF_ALU32_REG(BPF_ADD, R1, R2),
1238 BPF_ALU32_REG(BPF_ADD, R1, R3),
1239 BPF_ALU32_REG(BPF_ADD, R1, R4),
1240 BPF_ALU32_REG(BPF_ADD, R1, R5),
1241 BPF_ALU32_REG(BPF_ADD, R1, R6),
1242 BPF_ALU32_REG(BPF_ADD, R1, R7),
1243 BPF_ALU32_REG(BPF_ADD, R1, R8),
1244 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1245 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1246 BPF_EXIT_INSN(),
1247 BPF_ALU32_REG(BPF_ADD, R2, R0),
1248 BPF_ALU32_REG(BPF_ADD, R2, R1),
1249 BPF_ALU32_REG(BPF_ADD, R2, R2),
1250 BPF_ALU32_REG(BPF_ADD, R2, R3),
1251 BPF_ALU32_REG(BPF_ADD, R2, R4),
1252 BPF_ALU32_REG(BPF_ADD, R2, R5),
1253 BPF_ALU32_REG(BPF_ADD, R2, R6),
1254 BPF_ALU32_REG(BPF_ADD, R2, R7),
1255 BPF_ALU32_REG(BPF_ADD, R2, R8),
1256 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1257 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1258 BPF_EXIT_INSN(),
1259 BPF_ALU32_REG(BPF_ADD, R3, R0),
1260 BPF_ALU32_REG(BPF_ADD, R3, R1),
1261 BPF_ALU32_REG(BPF_ADD, R3, R2),
1262 BPF_ALU32_REG(BPF_ADD, R3, R3),
1263 BPF_ALU32_REG(BPF_ADD, R3, R4),
1264 BPF_ALU32_REG(BPF_ADD, R3, R5),
1265 BPF_ALU32_REG(BPF_ADD, R3, R6),
1266 BPF_ALU32_REG(BPF_ADD, R3, R7),
1267 BPF_ALU32_REG(BPF_ADD, R3, R8),
1268 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1269 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1270 BPF_EXIT_INSN(),
1271 BPF_ALU32_REG(BPF_ADD, R4, R0),
1272 BPF_ALU32_REG(BPF_ADD, R4, R1),
1273 BPF_ALU32_REG(BPF_ADD, R4, R2),
1274 BPF_ALU32_REG(BPF_ADD, R4, R3),
1275 BPF_ALU32_REG(BPF_ADD, R4, R4),
1276 BPF_ALU32_REG(BPF_ADD, R4, R5),
1277 BPF_ALU32_REG(BPF_ADD, R4, R6),
1278 BPF_ALU32_REG(BPF_ADD, R4, R7),
1279 BPF_ALU32_REG(BPF_ADD, R4, R8),
1280 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1281 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1282 BPF_EXIT_INSN(),
1283 BPF_ALU32_REG(BPF_ADD, R5, R0),
1284 BPF_ALU32_REG(BPF_ADD, R5, R1),
1285 BPF_ALU32_REG(BPF_ADD, R5, R2),
1286 BPF_ALU32_REG(BPF_ADD, R5, R3),
1287 BPF_ALU32_REG(BPF_ADD, R5, R4),
1288 BPF_ALU32_REG(BPF_ADD, R5, R5),
1289 BPF_ALU32_REG(BPF_ADD, R5, R6),
1290 BPF_ALU32_REG(BPF_ADD, R5, R7),
1291 BPF_ALU32_REG(BPF_ADD, R5, R8),
1292 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1293 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1294 BPF_EXIT_INSN(),
1295 BPF_ALU32_REG(BPF_ADD, R6, R0),
1296 BPF_ALU32_REG(BPF_ADD, R6, R1),
1297 BPF_ALU32_REG(BPF_ADD, R6, R2),
1298 BPF_ALU32_REG(BPF_ADD, R6, R3),
1299 BPF_ALU32_REG(BPF_ADD, R6, R4),
1300 BPF_ALU32_REG(BPF_ADD, R6, R5),
1301 BPF_ALU32_REG(BPF_ADD, R6, R6),
1302 BPF_ALU32_REG(BPF_ADD, R6, R7),
1303 BPF_ALU32_REG(BPF_ADD, R6, R8),
1304 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1305 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1306 BPF_EXIT_INSN(),
1307 BPF_ALU32_REG(BPF_ADD, R7, R0),
1308 BPF_ALU32_REG(BPF_ADD, R7, R1),
1309 BPF_ALU32_REG(BPF_ADD, R7, R2),
1310 BPF_ALU32_REG(BPF_ADD, R7, R3),
1311 BPF_ALU32_REG(BPF_ADD, R7, R4),
1312 BPF_ALU32_REG(BPF_ADD, R7, R5),
1313 BPF_ALU32_REG(BPF_ADD, R7, R6),
1314 BPF_ALU32_REG(BPF_ADD, R7, R7),
1315 BPF_ALU32_REG(BPF_ADD, R7, R8),
1316 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1317 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1318 BPF_EXIT_INSN(),
1319 BPF_ALU32_REG(BPF_ADD, R8, R0),
1320 BPF_ALU32_REG(BPF_ADD, R8, R1),
1321 BPF_ALU32_REG(BPF_ADD, R8, R2),
1322 BPF_ALU32_REG(BPF_ADD, R8, R3),
1323 BPF_ALU32_REG(BPF_ADD, R8, R4),
1324 BPF_ALU32_REG(BPF_ADD, R8, R5),
1325 BPF_ALU32_REG(BPF_ADD, R8, R6),
1326 BPF_ALU32_REG(BPF_ADD, R8, R7),
1327 BPF_ALU32_REG(BPF_ADD, R8, R8),
1328 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1329 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1330 BPF_EXIT_INSN(),
1331 BPF_ALU32_REG(BPF_ADD, R9, R0),
1332 BPF_ALU32_REG(BPF_ADD, R9, R1),
1333 BPF_ALU32_REG(BPF_ADD, R9, R2),
1334 BPF_ALU32_REG(BPF_ADD, R9, R3),
1335 BPF_ALU32_REG(BPF_ADD, R9, R4),
1336 BPF_ALU32_REG(BPF_ADD, R9, R5),
1337 BPF_ALU32_REG(BPF_ADD, R9, R6),
1338 BPF_ALU32_REG(BPF_ADD, R9, R7),
1339 BPF_ALU32_REG(BPF_ADD, R9, R8),
1340 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1341 BPF_ALU32_REG(BPF_MOV, R0, R9),
1342 BPF_EXIT_INSN(),
1344 INTERNAL,
1345 { },
1346 { { 0, 2957380 } }
1348 { /* Mainly checking JIT here. */
1349 "INT: SUB",
1350 .u.insns_int = {
1351 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1352 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1353 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1354 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1355 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1356 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1357 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1358 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1359 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1360 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1361 BPF_ALU64_REG(BPF_SUB, R0, R0),
1362 BPF_ALU64_REG(BPF_SUB, R0, R1),
1363 BPF_ALU64_REG(BPF_SUB, R0, R2),
1364 BPF_ALU64_REG(BPF_SUB, R0, R3),
1365 BPF_ALU64_REG(BPF_SUB, R0, R4),
1366 BPF_ALU64_REG(BPF_SUB, R0, R5),
1367 BPF_ALU64_REG(BPF_SUB, R0, R6),
1368 BPF_ALU64_REG(BPF_SUB, R0, R7),
1369 BPF_ALU64_REG(BPF_SUB, R0, R8),
1370 BPF_ALU64_REG(BPF_SUB, R0, R9),
1371 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1372 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1373 BPF_EXIT_INSN(),
1374 BPF_ALU64_REG(BPF_SUB, R1, R0),
1375 BPF_ALU64_REG(BPF_SUB, R1, R2),
1376 BPF_ALU64_REG(BPF_SUB, R1, R3),
1377 BPF_ALU64_REG(BPF_SUB, R1, R4),
1378 BPF_ALU64_REG(BPF_SUB, R1, R5),
1379 BPF_ALU64_REG(BPF_SUB, R1, R6),
1380 BPF_ALU64_REG(BPF_SUB, R1, R7),
1381 BPF_ALU64_REG(BPF_SUB, R1, R8),
1382 BPF_ALU64_REG(BPF_SUB, R1, R9),
1383 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1384 BPF_ALU64_REG(BPF_SUB, R2, R0),
1385 BPF_ALU64_REG(BPF_SUB, R2, R1),
1386 BPF_ALU64_REG(BPF_SUB, R2, R3),
1387 BPF_ALU64_REG(BPF_SUB, R2, R4),
1388 BPF_ALU64_REG(BPF_SUB, R2, R5),
1389 BPF_ALU64_REG(BPF_SUB, R2, R6),
1390 BPF_ALU64_REG(BPF_SUB, R2, R7),
1391 BPF_ALU64_REG(BPF_SUB, R2, R8),
1392 BPF_ALU64_REG(BPF_SUB, R2, R9),
1393 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1394 BPF_ALU64_REG(BPF_SUB, R3, R0),
1395 BPF_ALU64_REG(BPF_SUB, R3, R1),
1396 BPF_ALU64_REG(BPF_SUB, R3, R2),
1397 BPF_ALU64_REG(BPF_SUB, R3, R4),
1398 BPF_ALU64_REG(BPF_SUB, R3, R5),
1399 BPF_ALU64_REG(BPF_SUB, R3, R6),
1400 BPF_ALU64_REG(BPF_SUB, R3, R7),
1401 BPF_ALU64_REG(BPF_SUB, R3, R8),
1402 BPF_ALU64_REG(BPF_SUB, R3, R9),
1403 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1404 BPF_ALU64_REG(BPF_SUB, R4, R0),
1405 BPF_ALU64_REG(BPF_SUB, R4, R1),
1406 BPF_ALU64_REG(BPF_SUB, R4, R2),
1407 BPF_ALU64_REG(BPF_SUB, R4, R3),
1408 BPF_ALU64_REG(BPF_SUB, R4, R5),
1409 BPF_ALU64_REG(BPF_SUB, R4, R6),
1410 BPF_ALU64_REG(BPF_SUB, R4, R7),
1411 BPF_ALU64_REG(BPF_SUB, R4, R8),
1412 BPF_ALU64_REG(BPF_SUB, R4, R9),
1413 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1414 BPF_ALU64_REG(BPF_SUB, R5, R0),
1415 BPF_ALU64_REG(BPF_SUB, R5, R1),
1416 BPF_ALU64_REG(BPF_SUB, R5, R2),
1417 BPF_ALU64_REG(BPF_SUB, R5, R3),
1418 BPF_ALU64_REG(BPF_SUB, R5, R4),
1419 BPF_ALU64_REG(BPF_SUB, R5, R6),
1420 BPF_ALU64_REG(BPF_SUB, R5, R7),
1421 BPF_ALU64_REG(BPF_SUB, R5, R8),
1422 BPF_ALU64_REG(BPF_SUB, R5, R9),
1423 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1424 BPF_ALU64_REG(BPF_SUB, R6, R0),
1425 BPF_ALU64_REG(BPF_SUB, R6, R1),
1426 BPF_ALU64_REG(BPF_SUB, R6, R2),
1427 BPF_ALU64_REG(BPF_SUB, R6, R3),
1428 BPF_ALU64_REG(BPF_SUB, R6, R4),
1429 BPF_ALU64_REG(BPF_SUB, R6, R5),
1430 BPF_ALU64_REG(BPF_SUB, R6, R7),
1431 BPF_ALU64_REG(BPF_SUB, R6, R8),
1432 BPF_ALU64_REG(BPF_SUB, R6, R9),
1433 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1434 BPF_ALU64_REG(BPF_SUB, R7, R0),
1435 BPF_ALU64_REG(BPF_SUB, R7, R1),
1436 BPF_ALU64_REG(BPF_SUB, R7, R2),
1437 BPF_ALU64_REG(BPF_SUB, R7, R3),
1438 BPF_ALU64_REG(BPF_SUB, R7, R4),
1439 BPF_ALU64_REG(BPF_SUB, R7, R5),
1440 BPF_ALU64_REG(BPF_SUB, R7, R6),
1441 BPF_ALU64_REG(BPF_SUB, R7, R8),
1442 BPF_ALU64_REG(BPF_SUB, R7, R9),
1443 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1444 BPF_ALU64_REG(BPF_SUB, R8, R0),
1445 BPF_ALU64_REG(BPF_SUB, R8, R1),
1446 BPF_ALU64_REG(BPF_SUB, R8, R2),
1447 BPF_ALU64_REG(BPF_SUB, R8, R3),
1448 BPF_ALU64_REG(BPF_SUB, R8, R4),
1449 BPF_ALU64_REG(BPF_SUB, R8, R5),
1450 BPF_ALU64_REG(BPF_SUB, R8, R6),
1451 BPF_ALU64_REG(BPF_SUB, R8, R7),
1452 BPF_ALU64_REG(BPF_SUB, R8, R9),
1453 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1454 BPF_ALU64_REG(BPF_SUB, R9, R0),
1455 BPF_ALU64_REG(BPF_SUB, R9, R1),
1456 BPF_ALU64_REG(BPF_SUB, R9, R2),
1457 BPF_ALU64_REG(BPF_SUB, R9, R3),
1458 BPF_ALU64_REG(BPF_SUB, R9, R4),
1459 BPF_ALU64_REG(BPF_SUB, R9, R5),
1460 BPF_ALU64_REG(BPF_SUB, R9, R6),
1461 BPF_ALU64_REG(BPF_SUB, R9, R7),
1462 BPF_ALU64_REG(BPF_SUB, R9, R8),
1463 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1464 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1465 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1466 BPF_ALU64_REG(BPF_SUB, R0, R1),
1467 BPF_ALU64_REG(BPF_SUB, R0, R2),
1468 BPF_ALU64_REG(BPF_SUB, R0, R3),
1469 BPF_ALU64_REG(BPF_SUB, R0, R4),
1470 BPF_ALU64_REG(BPF_SUB, R0, R5),
1471 BPF_ALU64_REG(BPF_SUB, R0, R6),
1472 BPF_ALU64_REG(BPF_SUB, R0, R7),
1473 BPF_ALU64_REG(BPF_SUB, R0, R8),
1474 BPF_ALU64_REG(BPF_SUB, R0, R9),
1475 BPF_EXIT_INSN(),
1477 INTERNAL,
1478 { },
1479 { { 0, 11 } }
1481 { /* Mainly checking JIT here. */
1482 "INT: XOR",
1483 .u.insns_int = {
1484 BPF_ALU64_REG(BPF_SUB, R0, R0),
1485 BPF_ALU64_REG(BPF_XOR, R1, R1),
1486 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1487 BPF_EXIT_INSN(),
1488 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1489 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1490 BPF_ALU64_REG(BPF_SUB, R1, R1),
1491 BPF_ALU64_REG(BPF_XOR, R2, R2),
1492 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1493 BPF_EXIT_INSN(),
1494 BPF_ALU64_REG(BPF_SUB, R2, R2),
1495 BPF_ALU64_REG(BPF_XOR, R3, R3),
1496 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1497 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1498 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1499 BPF_EXIT_INSN(),
1500 BPF_ALU64_REG(BPF_SUB, R3, R3),
1501 BPF_ALU64_REG(BPF_XOR, R4, R4),
1502 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1503 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1504 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1505 BPF_EXIT_INSN(),
1506 BPF_ALU64_REG(BPF_SUB, R4, R4),
1507 BPF_ALU64_REG(BPF_XOR, R5, R5),
1508 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1509 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1510 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1511 BPF_EXIT_INSN(),
1512 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1513 BPF_ALU64_REG(BPF_SUB, R5, R5),
1514 BPF_ALU64_REG(BPF_XOR, R6, R6),
1515 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1516 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1517 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1518 BPF_EXIT_INSN(),
1519 BPF_ALU64_REG(BPF_SUB, R6, R6),
1520 BPF_ALU64_REG(BPF_XOR, R7, R7),
1521 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1522 BPF_EXIT_INSN(),
1523 BPF_ALU64_REG(BPF_SUB, R7, R7),
1524 BPF_ALU64_REG(BPF_XOR, R8, R8),
1525 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1526 BPF_EXIT_INSN(),
1527 BPF_ALU64_REG(BPF_SUB, R8, R8),
1528 BPF_ALU64_REG(BPF_XOR, R9, R9),
1529 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1530 BPF_EXIT_INSN(),
1531 BPF_ALU64_REG(BPF_SUB, R9, R9),
1532 BPF_ALU64_REG(BPF_XOR, R0, R0),
1533 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1534 BPF_EXIT_INSN(),
1535 BPF_ALU64_REG(BPF_SUB, R1, R1),
1536 BPF_ALU64_REG(BPF_XOR, R0, R0),
1537 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1538 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1539 BPF_EXIT_INSN(),
1540 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1541 BPF_EXIT_INSN(),
1543 INTERNAL,
1544 { },
1545 { { 0, 1 } }
1547 { /* Mainly checking JIT here. */
1548 "INT: MUL",
1549 .u.insns_int = {
1550 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1551 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1552 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1553 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1554 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1555 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1556 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1557 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1558 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1559 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1560 BPF_ALU64_REG(BPF_MUL, R0, R0),
1561 BPF_ALU64_REG(BPF_MUL, R0, R1),
1562 BPF_ALU64_REG(BPF_MUL, R0, R2),
1563 BPF_ALU64_REG(BPF_MUL, R0, R3),
1564 BPF_ALU64_REG(BPF_MUL, R0, R4),
1565 BPF_ALU64_REG(BPF_MUL, R0, R5),
1566 BPF_ALU64_REG(BPF_MUL, R0, R6),
1567 BPF_ALU64_REG(BPF_MUL, R0, R7),
1568 BPF_ALU64_REG(BPF_MUL, R0, R8),
1569 BPF_ALU64_REG(BPF_MUL, R0, R9),
1570 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1571 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1572 BPF_EXIT_INSN(),
1573 BPF_ALU64_REG(BPF_MUL, R1, R0),
1574 BPF_ALU64_REG(BPF_MUL, R1, R2),
1575 BPF_ALU64_REG(BPF_MUL, R1, R3),
1576 BPF_ALU64_REG(BPF_MUL, R1, R4),
1577 BPF_ALU64_REG(BPF_MUL, R1, R5),
1578 BPF_ALU64_REG(BPF_MUL, R1, R6),
1579 BPF_ALU64_REG(BPF_MUL, R1, R7),
1580 BPF_ALU64_REG(BPF_MUL, R1, R8),
1581 BPF_ALU64_REG(BPF_MUL, R1, R9),
1582 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1583 BPF_ALU64_REG(BPF_MOV, R2, R1),
1584 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1585 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1586 BPF_EXIT_INSN(),
1587 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1588 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1589 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1590 BPF_EXIT_INSN(),
1591 BPF_ALU64_REG(BPF_MUL, R2, R0),
1592 BPF_ALU64_REG(BPF_MUL, R2, R1),
1593 BPF_ALU64_REG(BPF_MUL, R2, R3),
1594 BPF_ALU64_REG(BPF_MUL, R2, R4),
1595 BPF_ALU64_REG(BPF_MUL, R2, R5),
1596 BPF_ALU64_REG(BPF_MUL, R2, R6),
1597 BPF_ALU64_REG(BPF_MUL, R2, R7),
1598 BPF_ALU64_REG(BPF_MUL, R2, R8),
1599 BPF_ALU64_REG(BPF_MUL, R2, R9),
1600 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1601 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1602 BPF_ALU64_REG(BPF_MOV, R0, R2),
1603 BPF_EXIT_INSN(),
1605 INTERNAL,
1606 { },
1607 { { 0, 0x35d97ef2 } }
1610 "INT: ALU MIX",
1611 .u.insns_int = {
1612 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1613 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1614 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1615 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1616 BPF_ALU64_REG(BPF_DIV, R0, R2),
1617 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1618 BPF_EXIT_INSN(),
1619 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1620 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1621 BPF_EXIT_INSN(),
1622 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1623 BPF_EXIT_INSN(),
1625 INTERNAL,
1626 { },
1627 { { 0, -1 } }
1630 "INT: shifts by register",
1631 .u.insns_int = {
1632 BPF_MOV64_IMM(R0, -1234),
1633 BPF_MOV64_IMM(R1, 1),
1634 BPF_ALU32_REG(BPF_RSH, R0, R1),
1635 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1636 BPF_EXIT_INSN(),
1637 BPF_MOV64_IMM(R2, 1),
1638 BPF_ALU64_REG(BPF_LSH, R0, R2),
1639 BPF_MOV32_IMM(R4, -1234),
1640 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1641 BPF_EXIT_INSN(),
1642 BPF_ALU64_IMM(BPF_AND, R4, 63),
1643 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1644 BPF_MOV64_IMM(R3, 47),
1645 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1646 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1647 BPF_EXIT_INSN(),
1648 BPF_MOV64_IMM(R2, 1),
1649 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1650 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1651 BPF_EXIT_INSN(),
1652 BPF_MOV64_IMM(R4, 4),
1653 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1654 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1655 BPF_EXIT_INSN(),
1656 BPF_MOV64_IMM(R4, 5),
1657 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1658 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1659 BPF_EXIT_INSN(),
1660 BPF_MOV64_IMM(R0, -1),
1661 BPF_EXIT_INSN(),
1663 INTERNAL,
1664 { },
1665 { { 0, -1 } }
1668 "INT: DIV + ABS",
1669 .u.insns_int = {
1670 BPF_ALU64_REG(BPF_MOV, R6, R1),
1671 BPF_LD_ABS(BPF_B, 3),
1672 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1673 BPF_ALU32_REG(BPF_DIV, R0, R2),
1674 BPF_ALU64_REG(BPF_MOV, R8, R0),
1675 BPF_LD_ABS(BPF_B, 4),
1676 BPF_ALU64_REG(BPF_ADD, R8, R0),
1677 BPF_LD_IND(BPF_B, R8, -70),
1678 BPF_EXIT_INSN(),
1680 INTERNAL,
1681 { 10, 20, 30, 40, 50 },
1682 { { 4, 0 }, { 5, 10 } }
1685 "INT: DIV by zero",
1686 .u.insns_int = {
1687 BPF_ALU64_REG(BPF_MOV, R6, R1),
1688 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1689 BPF_LD_ABS(BPF_B, 3),
1690 BPF_ALU32_REG(BPF_DIV, R0, R7),
1691 BPF_EXIT_INSN(),
1693 INTERNAL,
1694 { 10, 20, 30, 40, 50 },
1695 { { 3, 0 }, { 4, 0 } }
1698 "check: missing ret",
1699 .u.insns = {
1700 BPF_STMT(BPF_LD | BPF_IMM, 1),
1702 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1703 { },
1707 "check: div_k_0",
1708 .u.insns = {
1709 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1710 BPF_STMT(BPF_RET | BPF_K, 0)
1712 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1713 { },
1717 "check: unknown insn",
1718 .u.insns = {
1719 /* seccomp insn, rejected in socket filter */
1720 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1721 BPF_STMT(BPF_RET | BPF_K, 0)
1723 CLASSIC | FLAG_EXPECTED_FAIL,
1724 { },
1728 "check: out of range spill/fill",
1729 .u.insns = {
1730 BPF_STMT(BPF_STX, 16),
1731 BPF_STMT(BPF_RET | BPF_K, 0)
1733 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1734 { },
1738 "JUMPS + HOLES",
1739 .u.insns = {
1740 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1741 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1742 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1743 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1744 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1745 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1746 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1747 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1748 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1749 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1750 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1751 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1752 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1753 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1754 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1755 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1756 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1757 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1758 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1759 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1760 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1761 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1762 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1763 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1764 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1765 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1766 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1767 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1768 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1769 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1770 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1771 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1772 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1773 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1774 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1775 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1776 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1777 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1778 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1779 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1780 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1781 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1782 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1783 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1784 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1785 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1786 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1787 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1788 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1789 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1790 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1791 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1792 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1793 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1794 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1795 BPF_STMT(BPF_RET | BPF_A, 0),
1796 BPF_STMT(BPF_RET | BPF_A, 0),
1798 CLASSIC,
1799 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1800 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1801 0x08, 0x00,
1802 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1803 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1804 0xc0, 0xa8, 0x33, 0x01,
1805 0xc0, 0xa8, 0x33, 0x02,
1806 0xbb, 0xb6,
1807 0xa9, 0xfa,
1808 0x00, 0x14, 0x00, 0x00,
1809 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1810 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1811 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1812 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1813 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1814 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1815 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1816 0xcc, 0xcc, 0xcc, 0xcc },
1817 { { 88, 0x001b } }
1820 "check: RET X",
1821 .u.insns = {
1822 BPF_STMT(BPF_RET | BPF_X, 0),
1824 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1825 { },
1826 { },
1829 "check: LDX + RET X",
1830 .u.insns = {
1831 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1832 BPF_STMT(BPF_RET | BPF_X, 0),
1834 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1835 { },
1836 { },
1838 { /* Mainly checking JIT here. */
1839 "M[]: alt STX + LDX",
1840 .u.insns = {
1841 BPF_STMT(BPF_LDX | BPF_IMM, 100),
1842 BPF_STMT(BPF_STX, 0),
1843 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1844 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1845 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1846 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1847 BPF_STMT(BPF_STX, 1),
1848 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1849 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1850 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1851 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1852 BPF_STMT(BPF_STX, 2),
1853 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1854 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1855 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1856 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1857 BPF_STMT(BPF_STX, 3),
1858 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1859 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1860 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1861 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1862 BPF_STMT(BPF_STX, 4),
1863 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1864 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1865 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1866 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1867 BPF_STMT(BPF_STX, 5),
1868 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1869 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1870 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1871 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1872 BPF_STMT(BPF_STX, 6),
1873 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1874 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1875 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1876 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1877 BPF_STMT(BPF_STX, 7),
1878 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1879 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1880 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1881 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1882 BPF_STMT(BPF_STX, 8),
1883 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1884 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1885 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1886 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1887 BPF_STMT(BPF_STX, 9),
1888 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1889 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1890 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1891 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1892 BPF_STMT(BPF_STX, 10),
1893 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1894 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1895 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1896 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1897 BPF_STMT(BPF_STX, 11),
1898 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1899 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1900 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1901 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1902 BPF_STMT(BPF_STX, 12),
1903 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1904 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1905 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1906 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1907 BPF_STMT(BPF_STX, 13),
1908 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1909 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1910 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1911 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1912 BPF_STMT(BPF_STX, 14),
1913 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1914 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1915 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1916 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1917 BPF_STMT(BPF_STX, 15),
1918 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1919 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1920 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1921 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1922 BPF_STMT(BPF_RET | BPF_A, 0),
1924 CLASSIC | FLAG_NO_DATA,
1925 { },
1926 { { 0, 116 } },
1928 { /* Mainly checking JIT here. */
1929 "M[]: full STX + full LDX",
1930 .u.insns = {
1931 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
1932 BPF_STMT(BPF_STX, 0),
1933 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
1934 BPF_STMT(BPF_STX, 1),
1935 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
1936 BPF_STMT(BPF_STX, 2),
1937 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
1938 BPF_STMT(BPF_STX, 3),
1939 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
1940 BPF_STMT(BPF_STX, 4),
1941 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
1942 BPF_STMT(BPF_STX, 5),
1943 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
1944 BPF_STMT(BPF_STX, 6),
1945 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
1946 BPF_STMT(BPF_STX, 7),
1947 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
1948 BPF_STMT(BPF_STX, 8),
1949 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
1950 BPF_STMT(BPF_STX, 9),
1951 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
1952 BPF_STMT(BPF_STX, 10),
1953 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
1954 BPF_STMT(BPF_STX, 11),
1955 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
1956 BPF_STMT(BPF_STX, 12),
1957 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
1958 BPF_STMT(BPF_STX, 13),
1959 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
1960 BPF_STMT(BPF_STX, 14),
1961 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
1962 BPF_STMT(BPF_STX, 15),
1963 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1964 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1965 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1966 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1967 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1968 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1969 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1970 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1971 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1972 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1973 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1974 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1975 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1976 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1977 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1978 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1979 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1980 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1981 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1982 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1983 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1984 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1985 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1986 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1987 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1988 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1989 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1990 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1991 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1992 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1993 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1994 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1995 BPF_STMT(BPF_RET | BPF_A, 0),
1997 CLASSIC | FLAG_NO_DATA,
1998 { },
1999 { { 0, 0x2a5a5e5 } },
2002 "check: SKF_AD_MAX",
2003 .u.insns = {
2004 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2005 SKF_AD_OFF + SKF_AD_MAX),
2006 BPF_STMT(BPF_RET | BPF_A, 0),
2008 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2009 { },
2010 { },
2012 { /* Passes checker but fails during runtime. */
2013 "LD [SKF_AD_OFF-1]",
2014 .u.insns = {
2015 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2016 SKF_AD_OFF - 1),
2017 BPF_STMT(BPF_RET | BPF_K, 1),
2019 CLASSIC,
2020 { },
2021 { { 1, 0 } },
2024 "load 64-bit immediate",
2025 .u.insns_int = {
2026 BPF_LD_IMM64(R1, 0x567800001234LL),
2027 BPF_MOV64_REG(R2, R1),
2028 BPF_MOV64_REG(R3, R2),
2029 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2030 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2031 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2032 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2033 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2034 BPF_EXIT_INSN(),
2035 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2036 BPF_EXIT_INSN(),
2037 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2038 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2039 BPF_EXIT_INSN(),
2041 INTERNAL,
2042 { },
2043 { { 0, 1 } }
2046 "nmap reduced",
2047 .u.insns_int = {
2048 BPF_MOV64_REG(R6, R1),
2049 BPF_LD_ABS(BPF_H, 12),
2050 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2051 BPF_LD_ABS(BPF_H, 12),
2052 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2053 BPF_MOV32_IMM(R0, 18),
2054 BPF_STX_MEM(BPF_W, R10, R0, -64),
2055 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2056 BPF_LD_IND(BPF_W, R7, 14),
2057 BPF_STX_MEM(BPF_W, R10, R0, -60),
2058 BPF_MOV32_IMM(R0, 280971478),
2059 BPF_STX_MEM(BPF_W, R10, R0, -56),
2060 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2061 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2062 BPF_ALU32_REG(BPF_SUB, R0, R7),
2063 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2064 BPF_LD_ABS(BPF_H, 12),
2065 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2066 BPF_MOV32_IMM(R0, 22),
2067 BPF_STX_MEM(BPF_W, R10, R0, -56),
2068 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2069 BPF_LD_IND(BPF_H, R7, 14),
2070 BPF_STX_MEM(BPF_W, R10, R0, -52),
2071 BPF_MOV32_IMM(R0, 17366),
2072 BPF_STX_MEM(BPF_W, R10, R0, -48),
2073 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2074 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2075 BPF_ALU32_REG(BPF_SUB, R0, R7),
2076 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2077 BPF_MOV32_IMM(R0, 256),
2078 BPF_EXIT_INSN(),
2079 BPF_MOV32_IMM(R0, 0),
2080 BPF_EXIT_INSN(),
2082 INTERNAL,
2083 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2084 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2085 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2086 { { 38, 256 } }
2088 /* BPF_ALU | BPF_MOV | BPF_X */
2090 "ALU_MOV_X: dst = 2",
2091 .u.insns_int = {
2092 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2093 BPF_ALU32_REG(BPF_MOV, R0, R1),
2094 BPF_EXIT_INSN(),
2096 INTERNAL,
2097 { },
2098 { { 0, 2 } },
2101 "ALU_MOV_X: dst = 4294967295",
2102 .u.insns_int = {
2103 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2104 BPF_ALU32_REG(BPF_MOV, R0, R1),
2105 BPF_EXIT_INSN(),
2107 INTERNAL,
2108 { },
2109 { { 0, 4294967295U } },
2112 "ALU64_MOV_X: dst = 2",
2113 .u.insns_int = {
2114 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2115 BPF_ALU64_REG(BPF_MOV, R0, R1),
2116 BPF_EXIT_INSN(),
2118 INTERNAL,
2119 { },
2120 { { 0, 2 } },
2123 "ALU64_MOV_X: dst = 4294967295",
2124 .u.insns_int = {
2125 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2126 BPF_ALU64_REG(BPF_MOV, R0, R1),
2127 BPF_EXIT_INSN(),
2129 INTERNAL,
2130 { },
2131 { { 0, 4294967295U } },
2133 /* BPF_ALU | BPF_MOV | BPF_K */
2135 "ALU_MOV_K: dst = 2",
2136 .u.insns_int = {
2137 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2138 BPF_EXIT_INSN(),
2140 INTERNAL,
2141 { },
2142 { { 0, 2 } },
2145 "ALU_MOV_K: dst = 4294967295",
2146 .u.insns_int = {
2147 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2148 BPF_EXIT_INSN(),
2150 INTERNAL,
2151 { },
2152 { { 0, 4294967295U } },
2155 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2156 .u.insns_int = {
2157 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2158 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2159 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2160 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2161 BPF_MOV32_IMM(R0, 2),
2162 BPF_EXIT_INSN(),
2163 BPF_MOV32_IMM(R0, 1),
2164 BPF_EXIT_INSN(),
2166 INTERNAL,
2167 { },
2168 { { 0, 0x1 } },
2171 "ALU64_MOV_K: dst = 2",
2172 .u.insns_int = {
2173 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2174 BPF_EXIT_INSN(),
2176 INTERNAL,
2177 { },
2178 { { 0, 2 } },
2181 "ALU64_MOV_K: dst = 2147483647",
2182 .u.insns_int = {
2183 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2184 BPF_EXIT_INSN(),
2186 INTERNAL,
2187 { },
2188 { { 0, 2147483647 } },
2191 "ALU64_OR_K: dst = 0x0",
2192 .u.insns_int = {
2193 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2194 BPF_LD_IMM64(R3, 0x0),
2195 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2196 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2197 BPF_MOV32_IMM(R0, 2),
2198 BPF_EXIT_INSN(),
2199 BPF_MOV32_IMM(R0, 1),
2200 BPF_EXIT_INSN(),
2202 INTERNAL,
2203 { },
2204 { { 0, 0x1 } },
2207 "ALU64_MOV_K: dst = -1",
2208 .u.insns_int = {
2209 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2210 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2211 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2212 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2213 BPF_MOV32_IMM(R0, 2),
2214 BPF_EXIT_INSN(),
2215 BPF_MOV32_IMM(R0, 1),
2216 BPF_EXIT_INSN(),
2218 INTERNAL,
2219 { },
2220 { { 0, 0x1 } },
2222 /* BPF_ALU | BPF_ADD | BPF_X */
2224 "ALU_ADD_X: 1 + 2 = 3",
2225 .u.insns_int = {
2226 BPF_LD_IMM64(R0, 1),
2227 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2228 BPF_ALU32_REG(BPF_ADD, R0, R1),
2229 BPF_EXIT_INSN(),
2231 INTERNAL,
2232 { },
2233 { { 0, 3 } },
2236 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2237 .u.insns_int = {
2238 BPF_LD_IMM64(R0, 1),
2239 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2240 BPF_ALU32_REG(BPF_ADD, R0, R1),
2241 BPF_EXIT_INSN(),
2243 INTERNAL,
2244 { },
2245 { { 0, 4294967295U } },
2248 "ALU64_ADD_X: 1 + 2 = 3",
2249 .u.insns_int = {
2250 BPF_LD_IMM64(R0, 1),
2251 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2252 BPF_ALU64_REG(BPF_ADD, R0, R1),
2253 BPF_EXIT_INSN(),
2255 INTERNAL,
2256 { },
2257 { { 0, 3 } },
2260 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2261 .u.insns_int = {
2262 BPF_LD_IMM64(R0, 1),
2263 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2264 BPF_ALU64_REG(BPF_ADD, R0, R1),
2265 BPF_EXIT_INSN(),
2267 INTERNAL,
2268 { },
2269 { { 0, 4294967295U } },
2271 /* BPF_ALU | BPF_ADD | BPF_K */
2273 "ALU_ADD_K: 1 + 2 = 3",
2274 .u.insns_int = {
2275 BPF_LD_IMM64(R0, 1),
2276 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2277 BPF_EXIT_INSN(),
2279 INTERNAL,
2280 { },
2281 { { 0, 3 } },
2284 "ALU_ADD_K: 3 + 0 = 3",
2285 .u.insns_int = {
2286 BPF_LD_IMM64(R0, 3),
2287 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2288 BPF_EXIT_INSN(),
2290 INTERNAL,
2291 { },
2292 { { 0, 3 } },
2295 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2296 .u.insns_int = {
2297 BPF_LD_IMM64(R0, 1),
2298 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2299 BPF_EXIT_INSN(),
2301 INTERNAL,
2302 { },
2303 { { 0, 4294967295U } },
2306 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2307 .u.insns_int = {
2308 BPF_LD_IMM64(R2, 0x0),
2309 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2310 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2311 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2312 BPF_MOV32_IMM(R0, 2),
2313 BPF_EXIT_INSN(),
2314 BPF_MOV32_IMM(R0, 1),
2315 BPF_EXIT_INSN(),
2317 INTERNAL,
2318 { },
2319 { { 0, 0x1 } },
2322 "ALU64_ADD_K: 1 + 2 = 3",
2323 .u.insns_int = {
2324 BPF_LD_IMM64(R0, 1),
2325 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2326 BPF_EXIT_INSN(),
2328 INTERNAL,
2329 { },
2330 { { 0, 3 } },
2333 "ALU64_ADD_K: 3 + 0 = 3",
2334 .u.insns_int = {
2335 BPF_LD_IMM64(R0, 3),
2336 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2337 BPF_EXIT_INSN(),
2339 INTERNAL,
2340 { },
2341 { { 0, 3 } },
2344 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2345 .u.insns_int = {
2346 BPF_LD_IMM64(R0, 1),
2347 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2348 BPF_EXIT_INSN(),
2350 INTERNAL,
2351 { },
2352 { { 0, 2147483647 } },
2355 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2356 .u.insns_int = {
2357 BPF_LD_IMM64(R0, 2147483646),
2358 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2359 BPF_EXIT_INSN(),
2361 INTERNAL,
2362 { },
2363 { { 0, -1 } },
2366 "ALU64_ADD_K: 1 + 0 = 1",
2367 .u.insns_int = {
2368 BPF_LD_IMM64(R2, 0x1),
2369 BPF_LD_IMM64(R3, 0x1),
2370 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2371 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2372 BPF_MOV32_IMM(R0, 2),
2373 BPF_EXIT_INSN(),
2374 BPF_MOV32_IMM(R0, 1),
2375 BPF_EXIT_INSN(),
2377 INTERNAL,
2378 { },
2379 { { 0, 0x1 } },
2382 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2383 .u.insns_int = {
2384 BPF_LD_IMM64(R2, 0x0),
2385 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2386 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2387 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2388 BPF_MOV32_IMM(R0, 2),
2389 BPF_EXIT_INSN(),
2390 BPF_MOV32_IMM(R0, 1),
2391 BPF_EXIT_INSN(),
2393 INTERNAL,
2394 { },
2395 { { 0, 0x1 } },
2397 /* BPF_ALU | BPF_SUB | BPF_X */
2399 "ALU_SUB_X: 3 - 1 = 2",
2400 .u.insns_int = {
2401 BPF_LD_IMM64(R0, 3),
2402 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2403 BPF_ALU32_REG(BPF_SUB, R0, R1),
2404 BPF_EXIT_INSN(),
2406 INTERNAL,
2407 { },
2408 { { 0, 2 } },
2411 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2412 .u.insns_int = {
2413 BPF_LD_IMM64(R0, 4294967295U),
2414 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2415 BPF_ALU32_REG(BPF_SUB, R0, R1),
2416 BPF_EXIT_INSN(),
2418 INTERNAL,
2419 { },
2420 { { 0, 1 } },
2423 "ALU64_SUB_X: 3 - 1 = 2",
2424 .u.insns_int = {
2425 BPF_LD_IMM64(R0, 3),
2426 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2427 BPF_ALU64_REG(BPF_SUB, R0, R1),
2428 BPF_EXIT_INSN(),
2430 INTERNAL,
2431 { },
2432 { { 0, 2 } },
2435 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2436 .u.insns_int = {
2437 BPF_LD_IMM64(R0, 4294967295U),
2438 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2439 BPF_ALU64_REG(BPF_SUB, R0, R1),
2440 BPF_EXIT_INSN(),
2442 INTERNAL,
2443 { },
2444 { { 0, 1 } },
2446 /* BPF_ALU | BPF_SUB | BPF_K */
2448 "ALU_SUB_K: 3 - 1 = 2",
2449 .u.insns_int = {
2450 BPF_LD_IMM64(R0, 3),
2451 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2452 BPF_EXIT_INSN(),
2454 INTERNAL,
2455 { },
2456 { { 0, 2 } },
2459 "ALU_SUB_K: 3 - 0 = 3",
2460 .u.insns_int = {
2461 BPF_LD_IMM64(R0, 3),
2462 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2463 BPF_EXIT_INSN(),
2465 INTERNAL,
2466 { },
2467 { { 0, 3 } },
2470 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2471 .u.insns_int = {
2472 BPF_LD_IMM64(R0, 4294967295U),
2473 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
2474 BPF_EXIT_INSN(),
2476 INTERNAL,
2477 { },
2478 { { 0, 1 } },
2481 "ALU64_SUB_K: 3 - 1 = 2",
2482 .u.insns_int = {
2483 BPF_LD_IMM64(R0, 3),
2484 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2485 BPF_EXIT_INSN(),
2487 INTERNAL,
2488 { },
2489 { { 0, 2 } },
2492 "ALU64_SUB_K: 3 - 0 = 3",
2493 .u.insns_int = {
2494 BPF_LD_IMM64(R0, 3),
2495 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2496 BPF_EXIT_INSN(),
2498 INTERNAL,
2499 { },
2500 { { 0, 3 } },
2503 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2504 .u.insns_int = {
2505 BPF_LD_IMM64(R0, 4294967294U),
2506 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
2507 BPF_EXIT_INSN(),
2509 INTERNAL,
2510 { },
2511 { { 0, -1 } },
2514 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2515 .u.insns_int = {
2516 BPF_LD_IMM64(R0, 2147483646),
2517 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2518 BPF_EXIT_INSN(),
2520 INTERNAL,
2521 { },
2522 { { 0, -1 } },
2524 /* BPF_ALU | BPF_MUL | BPF_X */
2526 "ALU_MUL_X: 2 * 3 = 6",
2527 .u.insns_int = {
2528 BPF_LD_IMM64(R0, 2),
2529 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2530 BPF_ALU32_REG(BPF_MUL, R0, R1),
2531 BPF_EXIT_INSN(),
2533 INTERNAL,
2534 { },
2535 { { 0, 6 } },
2538 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2539 .u.insns_int = {
2540 BPF_LD_IMM64(R0, 2),
2541 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2542 BPF_ALU32_REG(BPF_MUL, R0, R1),
2543 BPF_EXIT_INSN(),
2545 INTERNAL,
2546 { },
2547 { { 0, 0xFFFFFFF0 } },
2550 "ALU_MUL_X: -1 * -1 = 1",
2551 .u.insns_int = {
2552 BPF_LD_IMM64(R0, -1),
2553 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2554 BPF_ALU32_REG(BPF_MUL, R0, R1),
2555 BPF_EXIT_INSN(),
2557 INTERNAL,
2558 { },
2559 { { 0, 1 } },
2562 "ALU64_MUL_X: 2 * 3 = 6",
2563 .u.insns_int = {
2564 BPF_LD_IMM64(R0, 2),
2565 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2566 BPF_ALU64_REG(BPF_MUL, R0, R1),
2567 BPF_EXIT_INSN(),
2569 INTERNAL,
2570 { },
2571 { { 0, 6 } },
2574 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2575 .u.insns_int = {
2576 BPF_LD_IMM64(R0, 1),
2577 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2578 BPF_ALU64_REG(BPF_MUL, R0, R1),
2579 BPF_EXIT_INSN(),
2581 INTERNAL,
2582 { },
2583 { { 0, 2147483647 } },
2585 /* BPF_ALU | BPF_MUL | BPF_K */
2587 "ALU_MUL_K: 2 * 3 = 6",
2588 .u.insns_int = {
2589 BPF_LD_IMM64(R0, 2),
2590 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2591 BPF_EXIT_INSN(),
2593 INTERNAL,
2594 { },
2595 { { 0, 6 } },
2598 "ALU_MUL_K: 3 * 1 = 3",
2599 .u.insns_int = {
2600 BPF_LD_IMM64(R0, 3),
2601 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2602 BPF_EXIT_INSN(),
2604 INTERNAL,
2605 { },
2606 { { 0, 3 } },
2609 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2610 .u.insns_int = {
2611 BPF_LD_IMM64(R0, 2),
2612 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2613 BPF_EXIT_INSN(),
2615 INTERNAL,
2616 { },
2617 { { 0, 0xFFFFFFF0 } },
2620 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
2621 .u.insns_int = {
2622 BPF_LD_IMM64(R2, 0x1),
2623 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2624 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
2625 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2626 BPF_MOV32_IMM(R0, 2),
2627 BPF_EXIT_INSN(),
2628 BPF_MOV32_IMM(R0, 1),
2629 BPF_EXIT_INSN(),
2631 INTERNAL,
2632 { },
2633 { { 0, 0x1 } },
2636 "ALU64_MUL_K: 2 * 3 = 6",
2637 .u.insns_int = {
2638 BPF_LD_IMM64(R0, 2),
2639 BPF_ALU64_IMM(BPF_MUL, R0, 3),
2640 BPF_EXIT_INSN(),
2642 INTERNAL,
2643 { },
2644 { { 0, 6 } },
2647 "ALU64_MUL_K: 3 * 1 = 3",
2648 .u.insns_int = {
2649 BPF_LD_IMM64(R0, 3),
2650 BPF_ALU64_IMM(BPF_MUL, R0, 1),
2651 BPF_EXIT_INSN(),
2653 INTERNAL,
2654 { },
2655 { { 0, 3 } },
2658 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
2659 .u.insns_int = {
2660 BPF_LD_IMM64(R0, 1),
2661 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
2662 BPF_EXIT_INSN(),
2664 INTERNAL,
2665 { },
2666 { { 0, 2147483647 } },
2669 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
2670 .u.insns_int = {
2671 BPF_LD_IMM64(R0, 1),
2672 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
2673 BPF_EXIT_INSN(),
2675 INTERNAL,
2676 { },
2677 { { 0, -2147483647 } },
2680 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
2681 .u.insns_int = {
2682 BPF_LD_IMM64(R2, 0x1),
2683 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2684 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
2685 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2686 BPF_MOV32_IMM(R0, 2),
2687 BPF_EXIT_INSN(),
2688 BPF_MOV32_IMM(R0, 1),
2689 BPF_EXIT_INSN(),
2691 INTERNAL,
2692 { },
2693 { { 0, 0x1 } },
2695 /* BPF_ALU | BPF_DIV | BPF_X */
2697 "ALU_DIV_X: 6 / 2 = 3",
2698 .u.insns_int = {
2699 BPF_LD_IMM64(R0, 6),
2700 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2701 BPF_ALU32_REG(BPF_DIV, R0, R1),
2702 BPF_EXIT_INSN(),
2704 INTERNAL,
2705 { },
2706 { { 0, 3 } },
2709 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
2710 .u.insns_int = {
2711 BPF_LD_IMM64(R0, 4294967295U),
2712 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2713 BPF_ALU32_REG(BPF_DIV, R0, R1),
2714 BPF_EXIT_INSN(),
2716 INTERNAL,
2717 { },
2718 { { 0, 1 } },
2721 "ALU64_DIV_X: 6 / 2 = 3",
2722 .u.insns_int = {
2723 BPF_LD_IMM64(R0, 6),
2724 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2725 BPF_ALU64_REG(BPF_DIV, R0, R1),
2726 BPF_EXIT_INSN(),
2728 INTERNAL,
2729 { },
2730 { { 0, 3 } },
2733 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
2734 .u.insns_int = {
2735 BPF_LD_IMM64(R0, 2147483647),
2736 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2737 BPF_ALU64_REG(BPF_DIV, R0, R1),
2738 BPF_EXIT_INSN(),
2740 INTERNAL,
2741 { },
2742 { { 0, 1 } },
2745 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2746 .u.insns_int = {
2747 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2748 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
2749 BPF_LD_IMM64(R3, 0x0000000000000001LL),
2750 BPF_ALU64_REG(BPF_DIV, R2, R4),
2751 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2752 BPF_MOV32_IMM(R0, 2),
2753 BPF_EXIT_INSN(),
2754 BPF_MOV32_IMM(R0, 1),
2755 BPF_EXIT_INSN(),
2757 INTERNAL,
2758 { },
2759 { { 0, 0x1 } },
2761 /* BPF_ALU | BPF_DIV | BPF_K */
2763 "ALU_DIV_K: 6 / 2 = 3",
2764 .u.insns_int = {
2765 BPF_LD_IMM64(R0, 6),
2766 BPF_ALU32_IMM(BPF_DIV, R0, 2),
2767 BPF_EXIT_INSN(),
2769 INTERNAL,
2770 { },
2771 { { 0, 3 } },
2774 "ALU_DIV_K: 3 / 1 = 3",
2775 .u.insns_int = {
2776 BPF_LD_IMM64(R0, 3),
2777 BPF_ALU32_IMM(BPF_DIV, R0, 1),
2778 BPF_EXIT_INSN(),
2780 INTERNAL,
2781 { },
2782 { { 0, 3 } },
2785 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
2786 .u.insns_int = {
2787 BPF_LD_IMM64(R0, 4294967295U),
2788 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
2789 BPF_EXIT_INSN(),
2791 INTERNAL,
2792 { },
2793 { { 0, 1 } },
2796 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
2797 .u.insns_int = {
2798 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2799 BPF_LD_IMM64(R3, 0x1UL),
2800 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
2801 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2802 BPF_MOV32_IMM(R0, 2),
2803 BPF_EXIT_INSN(),
2804 BPF_MOV32_IMM(R0, 1),
2805 BPF_EXIT_INSN(),
2807 INTERNAL,
2808 { },
2809 { { 0, 0x1 } },
2812 "ALU64_DIV_K: 6 / 2 = 3",
2813 .u.insns_int = {
2814 BPF_LD_IMM64(R0, 6),
2815 BPF_ALU64_IMM(BPF_DIV, R0, 2),
2816 BPF_EXIT_INSN(),
2818 INTERNAL,
2819 { },
2820 { { 0, 3 } },
2823 "ALU64_DIV_K: 3 / 1 = 3",
2824 .u.insns_int = {
2825 BPF_LD_IMM64(R0, 3),
2826 BPF_ALU64_IMM(BPF_DIV, R0, 1),
2827 BPF_EXIT_INSN(),
2829 INTERNAL,
2830 { },
2831 { { 0, 3 } },
2834 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
2835 .u.insns_int = {
2836 BPF_LD_IMM64(R0, 2147483647),
2837 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
2838 BPF_EXIT_INSN(),
2840 INTERNAL,
2841 { },
2842 { { 0, 1 } },
2845 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2846 .u.insns_int = {
2847 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2848 BPF_LD_IMM64(R3, 0x0000000000000001LL),
2849 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
2850 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2851 BPF_MOV32_IMM(R0, 2),
2852 BPF_EXIT_INSN(),
2853 BPF_MOV32_IMM(R0, 1),
2854 BPF_EXIT_INSN(),
2856 INTERNAL,
2857 { },
2858 { { 0, 0x1 } },
2860 /* BPF_ALU | BPF_MOD | BPF_X */
2862 "ALU_MOD_X: 3 % 2 = 1",
2863 .u.insns_int = {
2864 BPF_LD_IMM64(R0, 3),
2865 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2866 BPF_ALU32_REG(BPF_MOD, R0, R1),
2867 BPF_EXIT_INSN(),
2869 INTERNAL,
2870 { },
2871 { { 0, 1 } },
2874 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
2875 .u.insns_int = {
2876 BPF_LD_IMM64(R0, 4294967295U),
2877 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
2878 BPF_ALU32_REG(BPF_MOD, R0, R1),
2879 BPF_EXIT_INSN(),
2881 INTERNAL,
2882 { },
2883 { { 0, 2 } },
2886 "ALU64_MOD_X: 3 % 2 = 1",
2887 .u.insns_int = {
2888 BPF_LD_IMM64(R0, 3),
2889 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2890 BPF_ALU64_REG(BPF_MOD, R0, R1),
2891 BPF_EXIT_INSN(),
2893 INTERNAL,
2894 { },
2895 { { 0, 1 } },
2898 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
2899 .u.insns_int = {
2900 BPF_LD_IMM64(R0, 2147483647),
2901 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
2902 BPF_ALU64_REG(BPF_MOD, R0, R1),
2903 BPF_EXIT_INSN(),
2905 INTERNAL,
2906 { },
2907 { { 0, 2 } },
2909 /* BPF_ALU | BPF_MOD | BPF_K */
2911 "ALU_MOD_K: 3 % 2 = 1",
2912 .u.insns_int = {
2913 BPF_LD_IMM64(R0, 3),
2914 BPF_ALU32_IMM(BPF_MOD, R0, 2),
2915 BPF_EXIT_INSN(),
2917 INTERNAL,
2918 { },
2919 { { 0, 1 } },
2922 "ALU_MOD_K: 3 % 1 = 0",
2923 .u.insns_int = {
2924 BPF_LD_IMM64(R0, 3),
2925 BPF_ALU32_IMM(BPF_MOD, R0, 1),
2926 BPF_EXIT_INSN(),
2928 INTERNAL,
2929 { },
2930 { { 0, 0 } },
2933 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
2934 .u.insns_int = {
2935 BPF_LD_IMM64(R0, 4294967295U),
2936 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
2937 BPF_EXIT_INSN(),
2939 INTERNAL,
2940 { },
2941 { { 0, 2 } },
2944 "ALU64_MOD_K: 3 % 2 = 1",
2945 .u.insns_int = {
2946 BPF_LD_IMM64(R0, 3),
2947 BPF_ALU64_IMM(BPF_MOD, R0, 2),
2948 BPF_EXIT_INSN(),
2950 INTERNAL,
2951 { },
2952 { { 0, 1 } },
2955 "ALU64_MOD_K: 3 % 1 = 0",
2956 .u.insns_int = {
2957 BPF_LD_IMM64(R0, 3),
2958 BPF_ALU64_IMM(BPF_MOD, R0, 1),
2959 BPF_EXIT_INSN(),
2961 INTERNAL,
2962 { },
2963 { { 0, 0 } },
2966 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
2967 .u.insns_int = {
2968 BPF_LD_IMM64(R0, 2147483647),
2969 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
2970 BPF_EXIT_INSN(),
2972 INTERNAL,
2973 { },
2974 { { 0, 2 } },
2976 /* BPF_ALU | BPF_AND | BPF_X */
2978 "ALU_AND_X: 3 & 2 = 2",
2979 .u.insns_int = {
2980 BPF_LD_IMM64(R0, 3),
2981 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2982 BPF_ALU32_REG(BPF_AND, R0, R1),
2983 BPF_EXIT_INSN(),
2985 INTERNAL,
2986 { },
2987 { { 0, 2 } },
2990 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
2991 .u.insns_int = {
2992 BPF_LD_IMM64(R0, 0xffffffff),
2993 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
2994 BPF_ALU32_REG(BPF_AND, R0, R1),
2995 BPF_EXIT_INSN(),
2997 INTERNAL,
2998 { },
2999 { { 0, 0xffffffff } },
3002 "ALU64_AND_X: 3 & 2 = 2",
3003 .u.insns_int = {
3004 BPF_LD_IMM64(R0, 3),
3005 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3006 BPF_ALU64_REG(BPF_AND, R0, R1),
3007 BPF_EXIT_INSN(),
3009 INTERNAL,
3010 { },
3011 { { 0, 2 } },
3014 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3015 .u.insns_int = {
3016 BPF_LD_IMM64(R0, 0xffffffff),
3017 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3018 BPF_ALU64_REG(BPF_AND, R0, R1),
3019 BPF_EXIT_INSN(),
3021 INTERNAL,
3022 { },
3023 { { 0, 0xffffffff } },
3025 /* BPF_ALU | BPF_AND | BPF_K */
3027 "ALU_AND_K: 3 & 2 = 2",
3028 .u.insns_int = {
3029 BPF_LD_IMM64(R0, 3),
3030 BPF_ALU32_IMM(BPF_AND, R0, 2),
3031 BPF_EXIT_INSN(),
3033 INTERNAL,
3034 { },
3035 { { 0, 2 } },
3038 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3039 .u.insns_int = {
3040 BPF_LD_IMM64(R0, 0xffffffff),
3041 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3042 BPF_EXIT_INSN(),
3044 INTERNAL,
3045 { },
3046 { { 0, 0xffffffff } },
3049 "ALU64_AND_K: 3 & 2 = 2",
3050 .u.insns_int = {
3051 BPF_LD_IMM64(R0, 3),
3052 BPF_ALU64_IMM(BPF_AND, R0, 2),
3053 BPF_EXIT_INSN(),
3055 INTERNAL,
3056 { },
3057 { { 0, 2 } },
3060 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3061 .u.insns_int = {
3062 BPF_LD_IMM64(R0, 0xffffffff),
3063 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3064 BPF_EXIT_INSN(),
3066 INTERNAL,
3067 { },
3068 { { 0, 0xffffffff } },
3071 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3072 .u.insns_int = {
3073 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3074 BPF_LD_IMM64(R3, 0x0000000000000000LL),
3075 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3076 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3077 BPF_MOV32_IMM(R0, 2),
3078 BPF_EXIT_INSN(),
3079 BPF_MOV32_IMM(R0, 1),
3080 BPF_EXIT_INSN(),
3082 INTERNAL,
3083 { },
3084 { { 0, 0x1 } },
3087 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3088 .u.insns_int = {
3089 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3090 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3091 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3092 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3093 BPF_MOV32_IMM(R0, 2),
3094 BPF_EXIT_INSN(),
3095 BPF_MOV32_IMM(R0, 1),
3096 BPF_EXIT_INSN(),
3098 INTERNAL,
3099 { },
3100 { { 0, 0x1 } },
3103 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3104 .u.insns_int = {
3105 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3106 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3107 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3108 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3109 BPF_MOV32_IMM(R0, 2),
3110 BPF_EXIT_INSN(),
3111 BPF_MOV32_IMM(R0, 1),
3112 BPF_EXIT_INSN(),
3114 INTERNAL,
3115 { },
3116 { { 0, 0x1 } },
3118 /* BPF_ALU | BPF_OR | BPF_X */
3120 "ALU_OR_X: 1 | 2 = 3",
3121 .u.insns_int = {
3122 BPF_LD_IMM64(R0, 1),
3123 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3124 BPF_ALU32_REG(BPF_OR, R0, R1),
3125 BPF_EXIT_INSN(),
3127 INTERNAL,
3128 { },
3129 { { 0, 3 } },
3132 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3133 .u.insns_int = {
3134 BPF_LD_IMM64(R0, 0),
3135 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3136 BPF_ALU32_REG(BPF_OR, R0, R1),
3137 BPF_EXIT_INSN(),
3139 INTERNAL,
3140 { },
3141 { { 0, 0xffffffff } },
3144 "ALU64_OR_X: 1 | 2 = 3",
3145 .u.insns_int = {
3146 BPF_LD_IMM64(R0, 1),
3147 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3148 BPF_ALU64_REG(BPF_OR, R0, R1),
3149 BPF_EXIT_INSN(),
3151 INTERNAL,
3152 { },
3153 { { 0, 3 } },
3156 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3157 .u.insns_int = {
3158 BPF_LD_IMM64(R0, 0),
3159 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3160 BPF_ALU64_REG(BPF_OR, R0, R1),
3161 BPF_EXIT_INSN(),
3163 INTERNAL,
3164 { },
3165 { { 0, 0xffffffff } },
3167 /* BPF_ALU | BPF_OR | BPF_K */
3169 "ALU_OR_K: 1 | 2 = 3",
3170 .u.insns_int = {
3171 BPF_LD_IMM64(R0, 1),
3172 BPF_ALU32_IMM(BPF_OR, R0, 2),
3173 BPF_EXIT_INSN(),
3175 INTERNAL,
3176 { },
3177 { { 0, 3 } },
3180 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3181 .u.insns_int = {
3182 BPF_LD_IMM64(R0, 0),
3183 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3184 BPF_EXIT_INSN(),
3186 INTERNAL,
3187 { },
3188 { { 0, 0xffffffff } },
3191 "ALU64_OR_K: 1 | 2 = 3",
3192 .u.insns_int = {
3193 BPF_LD_IMM64(R0, 1),
3194 BPF_ALU64_IMM(BPF_OR, R0, 2),
3195 BPF_EXIT_INSN(),
3197 INTERNAL,
3198 { },
3199 { { 0, 3 } },
3202 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3203 .u.insns_int = {
3204 BPF_LD_IMM64(R0, 0),
3205 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3206 BPF_EXIT_INSN(),
3208 INTERNAL,
3209 { },
3210 { { 0, 0xffffffff } },
3213 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3214 .u.insns_int = {
3215 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3216 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3217 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3218 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3219 BPF_MOV32_IMM(R0, 2),
3220 BPF_EXIT_INSN(),
3221 BPF_MOV32_IMM(R0, 1),
3222 BPF_EXIT_INSN(),
3224 INTERNAL,
3225 { },
3226 { { 0, 0x1 } },
3229 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3230 .u.insns_int = {
3231 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3232 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3233 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3234 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3235 BPF_MOV32_IMM(R0, 2),
3236 BPF_EXIT_INSN(),
3237 BPF_MOV32_IMM(R0, 1),
3238 BPF_EXIT_INSN(),
3240 INTERNAL,
3241 { },
3242 { { 0, 0x1 } },
3245 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3246 .u.insns_int = {
3247 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3248 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3249 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3250 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3251 BPF_MOV32_IMM(R0, 2),
3252 BPF_EXIT_INSN(),
3253 BPF_MOV32_IMM(R0, 1),
3254 BPF_EXIT_INSN(),
3256 INTERNAL,
3257 { },
3258 { { 0, 0x1 } },
3260 /* BPF_ALU | BPF_XOR | BPF_X */
3262 "ALU_XOR_X: 5 ^ 6 = 3",
3263 .u.insns_int = {
3264 BPF_LD_IMM64(R0, 5),
3265 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3266 BPF_ALU32_REG(BPF_XOR, R0, R1),
3267 BPF_EXIT_INSN(),
3269 INTERNAL,
3270 { },
3271 { { 0, 3 } },
3274 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3275 .u.insns_int = {
3276 BPF_LD_IMM64(R0, 1),
3277 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3278 BPF_ALU32_REG(BPF_XOR, R0, R1),
3279 BPF_EXIT_INSN(),
3281 INTERNAL,
3282 { },
3283 { { 0, 0xfffffffe } },
3286 "ALU64_XOR_X: 5 ^ 6 = 3",
3287 .u.insns_int = {
3288 BPF_LD_IMM64(R0, 5),
3289 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3290 BPF_ALU64_REG(BPF_XOR, R0, R1),
3291 BPF_EXIT_INSN(),
3293 INTERNAL,
3294 { },
3295 { { 0, 3 } },
3298 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3299 .u.insns_int = {
3300 BPF_LD_IMM64(R0, 1),
3301 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3302 BPF_ALU64_REG(BPF_XOR, R0, R1),
3303 BPF_EXIT_INSN(),
3305 INTERNAL,
3306 { },
3307 { { 0, 0xfffffffe } },
3309 /* BPF_ALU | BPF_XOR | BPF_K */
3311 "ALU_XOR_K: 5 ^ 6 = 3",
3312 .u.insns_int = {
3313 BPF_LD_IMM64(R0, 5),
3314 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3315 BPF_EXIT_INSN(),
3317 INTERNAL,
3318 { },
3319 { { 0, 3 } },
3322 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3323 .u.insns_int = {
3324 BPF_LD_IMM64(R0, 1),
3325 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3326 BPF_EXIT_INSN(),
3328 INTERNAL,
3329 { },
3330 { { 0, 0xfffffffe } },
3333 "ALU64_XOR_K: 5 ^ 6 = 3",
3334 .u.insns_int = {
3335 BPF_LD_IMM64(R0, 5),
3336 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3337 BPF_EXIT_INSN(),
3339 INTERNAL,
3340 { },
3341 { { 0, 3 } },
3344 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3345 .u.insns_int = {
3346 BPF_LD_IMM64(R0, 1),
3347 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3348 BPF_EXIT_INSN(),
3350 INTERNAL,
3351 { },
3352 { { 0, 0xfffffffe } },
3355 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3356 .u.insns_int = {
3357 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3358 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3359 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3360 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3361 BPF_MOV32_IMM(R0, 2),
3362 BPF_EXIT_INSN(),
3363 BPF_MOV32_IMM(R0, 1),
3364 BPF_EXIT_INSN(),
3366 INTERNAL,
3367 { },
3368 { { 0, 0x1 } },
3371 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3372 .u.insns_int = {
3373 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3374 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
3375 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3376 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3377 BPF_MOV32_IMM(R0, 2),
3378 BPF_EXIT_INSN(),
3379 BPF_MOV32_IMM(R0, 1),
3380 BPF_EXIT_INSN(),
3382 INTERNAL,
3383 { },
3384 { { 0, 0x1 } },
3387 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3388 .u.insns_int = {
3389 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3390 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3391 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3392 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3393 BPF_MOV32_IMM(R0, 2),
3394 BPF_EXIT_INSN(),
3395 BPF_MOV32_IMM(R0, 1),
3396 BPF_EXIT_INSN(),
3398 INTERNAL,
3399 { },
3400 { { 0, 0x1 } },
3402 /* BPF_ALU | BPF_LSH | BPF_X */
3404 "ALU_LSH_X: 1 << 1 = 2",
3405 .u.insns_int = {
3406 BPF_LD_IMM64(R0, 1),
3407 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3408 BPF_ALU32_REG(BPF_LSH, R0, R1),
3409 BPF_EXIT_INSN(),
3411 INTERNAL,
3412 { },
3413 { { 0, 2 } },
3416 "ALU_LSH_X: 1 << 31 = 0x80000000",
3417 .u.insns_int = {
3418 BPF_LD_IMM64(R0, 1),
3419 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3420 BPF_ALU32_REG(BPF_LSH, R0, R1),
3421 BPF_EXIT_INSN(),
3423 INTERNAL,
3424 { },
3425 { { 0, 0x80000000 } },
3428 "ALU64_LSH_X: 1 << 1 = 2",
3429 .u.insns_int = {
3430 BPF_LD_IMM64(R0, 1),
3431 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3432 BPF_ALU64_REG(BPF_LSH, R0, R1),
3433 BPF_EXIT_INSN(),
3435 INTERNAL,
3436 { },
3437 { { 0, 2 } },
3440 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3441 .u.insns_int = {
3442 BPF_LD_IMM64(R0, 1),
3443 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3444 BPF_ALU64_REG(BPF_LSH, R0, R1),
3445 BPF_EXIT_INSN(),
3447 INTERNAL,
3448 { },
3449 { { 0, 0x80000000 } },
3451 /* BPF_ALU | BPF_LSH | BPF_K */
3453 "ALU_LSH_K: 1 << 1 = 2",
3454 .u.insns_int = {
3455 BPF_LD_IMM64(R0, 1),
3456 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3457 BPF_EXIT_INSN(),
3459 INTERNAL,
3460 { },
3461 { { 0, 2 } },
3464 "ALU_LSH_K: 1 << 31 = 0x80000000",
3465 .u.insns_int = {
3466 BPF_LD_IMM64(R0, 1),
3467 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3468 BPF_EXIT_INSN(),
3470 INTERNAL,
3471 { },
3472 { { 0, 0x80000000 } },
3475 "ALU64_LSH_K: 1 << 1 = 2",
3476 .u.insns_int = {
3477 BPF_LD_IMM64(R0, 1),
3478 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3479 BPF_EXIT_INSN(),
3481 INTERNAL,
3482 { },
3483 { { 0, 2 } },
3486 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3487 .u.insns_int = {
3488 BPF_LD_IMM64(R0, 1),
3489 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3490 BPF_EXIT_INSN(),
3492 INTERNAL,
3493 { },
3494 { { 0, 0x80000000 } },
3496 /* BPF_ALU | BPF_RSH | BPF_X */
3498 "ALU_RSH_X: 2 >> 1 = 1",
3499 .u.insns_int = {
3500 BPF_LD_IMM64(R0, 2),
3501 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3502 BPF_ALU32_REG(BPF_RSH, R0, R1),
3503 BPF_EXIT_INSN(),
3505 INTERNAL,
3506 { },
3507 { { 0, 1 } },
3510 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3511 .u.insns_int = {
3512 BPF_LD_IMM64(R0, 0x80000000),
3513 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3514 BPF_ALU32_REG(BPF_RSH, R0, R1),
3515 BPF_EXIT_INSN(),
3517 INTERNAL,
3518 { },
3519 { { 0, 1 } },
3522 "ALU64_RSH_X: 2 >> 1 = 1",
3523 .u.insns_int = {
3524 BPF_LD_IMM64(R0, 2),
3525 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3526 BPF_ALU64_REG(BPF_RSH, R0, R1),
3527 BPF_EXIT_INSN(),
3529 INTERNAL,
3530 { },
3531 { { 0, 1 } },
3534 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3535 .u.insns_int = {
3536 BPF_LD_IMM64(R0, 0x80000000),
3537 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3538 BPF_ALU64_REG(BPF_RSH, R0, R1),
3539 BPF_EXIT_INSN(),
3541 INTERNAL,
3542 { },
3543 { { 0, 1 } },
3545 /* BPF_ALU | BPF_RSH | BPF_K */
3547 "ALU_RSH_K: 2 >> 1 = 1",
3548 .u.insns_int = {
3549 BPF_LD_IMM64(R0, 2),
3550 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3551 BPF_EXIT_INSN(),
3553 INTERNAL,
3554 { },
3555 { { 0, 1 } },
3558 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3559 .u.insns_int = {
3560 BPF_LD_IMM64(R0, 0x80000000),
3561 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3562 BPF_EXIT_INSN(),
3564 INTERNAL,
3565 { },
3566 { { 0, 1 } },
3569 "ALU64_RSH_K: 2 >> 1 = 1",
3570 .u.insns_int = {
3571 BPF_LD_IMM64(R0, 2),
3572 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3573 BPF_EXIT_INSN(),
3575 INTERNAL,
3576 { },
3577 { { 0, 1 } },
3580 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3581 .u.insns_int = {
3582 BPF_LD_IMM64(R0, 0x80000000),
3583 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3584 BPF_EXIT_INSN(),
3586 INTERNAL,
3587 { },
3588 { { 0, 1 } },
3590 /* BPF_ALU | BPF_ARSH | BPF_X */
3592 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3593 .u.insns_int = {
3594 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3595 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3596 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3597 BPF_EXIT_INSN(),
3599 INTERNAL,
3600 { },
3601 { { 0, 0xffff00ff } },
3603 /* BPF_ALU | BPF_ARSH | BPF_K */
3605 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3606 .u.insns_int = {
3607 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3608 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3609 BPF_EXIT_INSN(),
3611 INTERNAL,
3612 { },
3613 { { 0, 0xffff00ff } },
3615 /* BPF_ALU | BPF_NEG */
3617 "ALU_NEG: -(3) = -3",
3618 .u.insns_int = {
3619 BPF_ALU32_IMM(BPF_MOV, R0, 3),
3620 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3621 BPF_EXIT_INSN(),
3623 INTERNAL,
3624 { },
3625 { { 0, -3 } },
3628 "ALU_NEG: -(-3) = 3",
3629 .u.insns_int = {
3630 BPF_ALU32_IMM(BPF_MOV, R0, -3),
3631 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3632 BPF_EXIT_INSN(),
3634 INTERNAL,
3635 { },
3636 { { 0, 3 } },
3639 "ALU64_NEG: -(3) = -3",
3640 .u.insns_int = {
3641 BPF_LD_IMM64(R0, 3),
3642 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3643 BPF_EXIT_INSN(),
3645 INTERNAL,
3646 { },
3647 { { 0, -3 } },
3650 "ALU64_NEG: -(-3) = 3",
3651 .u.insns_int = {
3652 BPF_LD_IMM64(R0, -3),
3653 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3654 BPF_EXIT_INSN(),
3656 INTERNAL,
3657 { },
3658 { { 0, 3 } },
3660 /* BPF_ALU | BPF_END | BPF_FROM_BE */
3662 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
3663 .u.insns_int = {
3664 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3665 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
3666 BPF_EXIT_INSN(),
3668 INTERNAL,
3669 { },
3670 { { 0, cpu_to_be16(0xcdef) } },
3673 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
3674 .u.insns_int = {
3675 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3676 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
3677 BPF_EXIT_INSN(),
3679 INTERNAL,
3680 { },
3681 { { 0, cpu_to_be32(0x89abcdef) } },
3684 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
3685 .u.insns_int = {
3686 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3687 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
3688 BPF_EXIT_INSN(),
3690 INTERNAL,
3691 { },
3692 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
3694 /* BPF_ALU | BPF_END | BPF_FROM_LE */
3696 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
3697 .u.insns_int = {
3698 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3699 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
3700 BPF_EXIT_INSN(),
3702 INTERNAL,
3703 { },
3704 { { 0, cpu_to_le16(0xcdef) } },
3707 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
3708 .u.insns_int = {
3709 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3710 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
3711 BPF_EXIT_INSN(),
3713 INTERNAL,
3714 { },
3715 { { 0, cpu_to_le32(0x89abcdef) } },
3718 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
3719 .u.insns_int = {
3720 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3721 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
3722 BPF_EXIT_INSN(),
3724 INTERNAL,
3725 { },
3726 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
3728 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
3730 "ST_MEM_B: Store/Load byte: max negative",
3731 .u.insns_int = {
3732 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3733 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
3734 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3735 BPF_EXIT_INSN(),
3737 INTERNAL,
3738 { },
3739 { { 0, 0xff } },
3742 "ST_MEM_B: Store/Load byte: max positive",
3743 .u.insns_int = {
3744 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3745 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
3746 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3747 BPF_EXIT_INSN(),
3749 INTERNAL,
3750 { },
3751 { { 0, 0x7f } },
3754 "STX_MEM_B: Store/Load byte: max negative",
3755 .u.insns_int = {
3756 BPF_LD_IMM64(R0, 0),
3757 BPF_LD_IMM64(R1, 0xffLL),
3758 BPF_STX_MEM(BPF_B, R10, R1, -40),
3759 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3760 BPF_EXIT_INSN(),
3762 INTERNAL,
3763 { },
3764 { { 0, 0xff } },
3767 "ST_MEM_H: Store/Load half word: max negative",
3768 .u.insns_int = {
3769 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3770 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
3771 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3772 BPF_EXIT_INSN(),
3774 INTERNAL,
3775 { },
3776 { { 0, 0xffff } },
3779 "ST_MEM_H: Store/Load half word: max positive",
3780 .u.insns_int = {
3781 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3782 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
3783 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3784 BPF_EXIT_INSN(),
3786 INTERNAL,
3787 { },
3788 { { 0, 0x7fff } },
3791 "STX_MEM_H: Store/Load half word: max negative",
3792 .u.insns_int = {
3793 BPF_LD_IMM64(R0, 0),
3794 BPF_LD_IMM64(R1, 0xffffLL),
3795 BPF_STX_MEM(BPF_H, R10, R1, -40),
3796 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3797 BPF_EXIT_INSN(),
3799 INTERNAL,
3800 { },
3801 { { 0, 0xffff } },
3804 "ST_MEM_W: Store/Load word: max negative",
3805 .u.insns_int = {
3806 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3807 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
3808 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3809 BPF_EXIT_INSN(),
3811 INTERNAL,
3812 { },
3813 { { 0, 0xffffffff } },
3816 "ST_MEM_W: Store/Load word: max positive",
3817 .u.insns_int = {
3818 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3819 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
3820 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3821 BPF_EXIT_INSN(),
3823 INTERNAL,
3824 { },
3825 { { 0, 0x7fffffff } },
3828 "STX_MEM_W: Store/Load word: max negative",
3829 .u.insns_int = {
3830 BPF_LD_IMM64(R0, 0),
3831 BPF_LD_IMM64(R1, 0xffffffffLL),
3832 BPF_STX_MEM(BPF_W, R10, R1, -40),
3833 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3834 BPF_EXIT_INSN(),
3836 INTERNAL,
3837 { },
3838 { { 0, 0xffffffff } },
3841 "ST_MEM_DW: Store/Load double word: max negative",
3842 .u.insns_int = {
3843 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3844 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3845 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3846 BPF_EXIT_INSN(),
3848 INTERNAL,
3849 { },
3850 { { 0, 0xffffffff } },
3853 "ST_MEM_DW: Store/Load double word: max negative 2",
3854 .u.insns_int = {
3855 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
3856 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3857 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3858 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
3859 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3860 BPF_MOV32_IMM(R0, 2),
3861 BPF_EXIT_INSN(),
3862 BPF_MOV32_IMM(R0, 1),
3863 BPF_EXIT_INSN(),
3865 INTERNAL,
3866 { },
3867 { { 0, 0x1 } },
3870 "ST_MEM_DW: Store/Load double word: max positive",
3871 .u.insns_int = {
3872 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3873 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
3874 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3875 BPF_EXIT_INSN(),
3877 INTERNAL,
3878 { },
3879 { { 0, 0x7fffffff } },
3882 "STX_MEM_DW: Store/Load double word: max negative",
3883 .u.insns_int = {
3884 BPF_LD_IMM64(R0, 0),
3885 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3886 BPF_STX_MEM(BPF_W, R10, R1, -40),
3887 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3888 BPF_EXIT_INSN(),
3890 INTERNAL,
3891 { },
3892 { { 0, 0xffffffff } },
3894 /* BPF_STX | BPF_XADD | BPF_W/DW */
3896 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
3897 .u.insns_int = {
3898 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3899 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
3900 BPF_STX_XADD(BPF_W, R10, R0, -40),
3901 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3902 BPF_EXIT_INSN(),
3904 INTERNAL,
3905 { },
3906 { { 0, 0x22 } },
3909 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
3910 .u.insns_int = {
3911 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3912 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
3913 BPF_STX_XADD(BPF_DW, R10, R0, -40),
3914 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3915 BPF_EXIT_INSN(),
3917 INTERNAL,
3918 { },
3919 { { 0, 0x22 } },
3921 /* BPF_JMP | BPF_EXIT */
3923 "JMP_EXIT",
3924 .u.insns_int = {
3925 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
3926 BPF_EXIT_INSN(),
3927 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
3929 INTERNAL,
3930 { },
3931 { { 0, 0x4711 } },
3933 /* BPF_JMP | BPF_JA */
3935 "JMP_JA: Unconditional jump: if (true) return 1",
3936 .u.insns_int = {
3937 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3938 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
3939 BPF_EXIT_INSN(),
3940 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3941 BPF_EXIT_INSN(),
3943 INTERNAL,
3944 { },
3945 { { 0, 1 } },
3947 /* BPF_JMP | BPF_JSGT | BPF_K */
3949 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
3950 .u.insns_int = {
3951 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3952 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3953 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
3954 BPF_EXIT_INSN(),
3955 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3956 BPF_EXIT_INSN(),
3958 INTERNAL,
3959 { },
3960 { { 0, 1 } },
3963 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
3964 .u.insns_int = {
3965 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3966 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3967 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
3968 BPF_EXIT_INSN(),
3969 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3970 BPF_EXIT_INSN(),
3972 INTERNAL,
3973 { },
3974 { { 0, 1 } },
3976 /* BPF_JMP | BPF_JSGE | BPF_K */
3978 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
3979 .u.insns_int = {
3980 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3981 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3982 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
3983 BPF_EXIT_INSN(),
3984 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3985 BPF_EXIT_INSN(),
3987 INTERNAL,
3988 { },
3989 { { 0, 1 } },
3992 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
3993 .u.insns_int = {
3994 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3995 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3996 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
3997 BPF_EXIT_INSN(),
3998 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3999 BPF_EXIT_INSN(),
4001 INTERNAL,
4002 { },
4003 { { 0, 1 } },
4005 /* BPF_JMP | BPF_JGT | BPF_K */
4007 "JMP_JGT_K: if (3 > 2) return 1",
4008 .u.insns_int = {
4009 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4010 BPF_LD_IMM64(R1, 3),
4011 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4012 BPF_EXIT_INSN(),
4013 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4014 BPF_EXIT_INSN(),
4016 INTERNAL,
4017 { },
4018 { { 0, 1 } },
4020 /* BPF_JMP | BPF_JGE | BPF_K */
4022 "JMP_JGE_K: if (3 >= 2) return 1",
4023 .u.insns_int = {
4024 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4025 BPF_LD_IMM64(R1, 3),
4026 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4027 BPF_EXIT_INSN(),
4028 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4029 BPF_EXIT_INSN(),
4031 INTERNAL,
4032 { },
4033 { { 0, 1 } },
4035 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4037 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4038 .u.insns_int = {
4039 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4040 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4041 BPF_EXIT_INSN(),
4042 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4043 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4044 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4045 BPF_EXIT_INSN(),
4047 INTERNAL,
4048 { },
4049 { { 0, 1 } },
4052 "JMP_JGE_K: if (3 >= 3) return 1",
4053 .u.insns_int = {
4054 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4055 BPF_LD_IMM64(R1, 3),
4056 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4057 BPF_EXIT_INSN(),
4058 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4059 BPF_EXIT_INSN(),
4061 INTERNAL,
4062 { },
4063 { { 0, 1 } },
4065 /* BPF_JMP | BPF_JNE | BPF_K */
4067 "JMP_JNE_K: if (3 != 2) return 1",
4068 .u.insns_int = {
4069 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4070 BPF_LD_IMM64(R1, 3),
4071 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4072 BPF_EXIT_INSN(),
4073 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4074 BPF_EXIT_INSN(),
4076 INTERNAL,
4077 { },
4078 { { 0, 1 } },
4080 /* BPF_JMP | BPF_JEQ | BPF_K */
4082 "JMP_JEQ_K: if (3 == 3) return 1",
4083 .u.insns_int = {
4084 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4085 BPF_LD_IMM64(R1, 3),
4086 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4087 BPF_EXIT_INSN(),
4088 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4089 BPF_EXIT_INSN(),
4091 INTERNAL,
4092 { },
4093 { { 0, 1 } },
4095 /* BPF_JMP | BPF_JSET | BPF_K */
4097 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4098 .u.insns_int = {
4099 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4100 BPF_LD_IMM64(R1, 3),
4101 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4102 BPF_EXIT_INSN(),
4103 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4104 BPF_EXIT_INSN(),
4106 INTERNAL,
4107 { },
4108 { { 0, 1 } },
4111 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4112 .u.insns_int = {
4113 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4114 BPF_LD_IMM64(R1, 3),
4115 BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1),
4116 BPF_EXIT_INSN(),
4117 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4118 BPF_EXIT_INSN(),
4120 INTERNAL,
4121 { },
4122 { { 0, 1 } },
4124 /* BPF_JMP | BPF_JSGT | BPF_X */
4126 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4127 .u.insns_int = {
4128 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4129 BPF_LD_IMM64(R1, -1),
4130 BPF_LD_IMM64(R2, -2),
4131 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4132 BPF_EXIT_INSN(),
4133 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4134 BPF_EXIT_INSN(),
4136 INTERNAL,
4137 { },
4138 { { 0, 1 } },
4141 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4142 .u.insns_int = {
4143 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4144 BPF_LD_IMM64(R1, -1),
4145 BPF_LD_IMM64(R2, -1),
4146 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4147 BPF_EXIT_INSN(),
4148 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4149 BPF_EXIT_INSN(),
4151 INTERNAL,
4152 { },
4153 { { 0, 1 } },
4155 /* BPF_JMP | BPF_JSGE | BPF_X */
4157 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4158 .u.insns_int = {
4159 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4160 BPF_LD_IMM64(R1, -1),
4161 BPF_LD_IMM64(R2, -2),
4162 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4163 BPF_EXIT_INSN(),
4164 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4165 BPF_EXIT_INSN(),
4167 INTERNAL,
4168 { },
4169 { { 0, 1 } },
4172 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4173 .u.insns_int = {
4174 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4175 BPF_LD_IMM64(R1, -1),
4176 BPF_LD_IMM64(R2, -1),
4177 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4178 BPF_EXIT_INSN(),
4179 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4180 BPF_EXIT_INSN(),
4182 INTERNAL,
4183 { },
4184 { { 0, 1 } },
4186 /* BPF_JMP | BPF_JGT | BPF_X */
4188 "JMP_JGT_X: if (3 > 2) return 1",
4189 .u.insns_int = {
4190 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4191 BPF_LD_IMM64(R1, 3),
4192 BPF_LD_IMM64(R2, 2),
4193 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4194 BPF_EXIT_INSN(),
4195 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4196 BPF_EXIT_INSN(),
4198 INTERNAL,
4199 { },
4200 { { 0, 1 } },
4202 /* BPF_JMP | BPF_JGE | BPF_X */
4204 "JMP_JGE_X: if (3 >= 2) return 1",
4205 .u.insns_int = {
4206 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4207 BPF_LD_IMM64(R1, 3),
4208 BPF_LD_IMM64(R2, 2),
4209 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4210 BPF_EXIT_INSN(),
4211 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4212 BPF_EXIT_INSN(),
4214 INTERNAL,
4215 { },
4216 { { 0, 1 } },
4219 "JMP_JGE_X: if (3 >= 3) return 1",
4220 .u.insns_int = {
4221 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4222 BPF_LD_IMM64(R1, 3),
4223 BPF_LD_IMM64(R2, 3),
4224 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4225 BPF_EXIT_INSN(),
4226 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4227 BPF_EXIT_INSN(),
4229 INTERNAL,
4230 { },
4231 { { 0, 1 } },
4233 /* BPF_JMP | BPF_JNE | BPF_X */
4235 "JMP_JNE_X: if (3 != 2) return 1",
4236 .u.insns_int = {
4237 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4238 BPF_LD_IMM64(R1, 3),
4239 BPF_LD_IMM64(R2, 2),
4240 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4241 BPF_EXIT_INSN(),
4242 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4243 BPF_EXIT_INSN(),
4245 INTERNAL,
4246 { },
4247 { { 0, 1 } },
4249 /* BPF_JMP | BPF_JEQ | BPF_X */
4251 "JMP_JEQ_X: if (3 == 3) return 1",
4252 .u.insns_int = {
4253 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4254 BPF_LD_IMM64(R1, 3),
4255 BPF_LD_IMM64(R2, 3),
4256 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4257 BPF_EXIT_INSN(),
4258 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4259 BPF_EXIT_INSN(),
4261 INTERNAL,
4262 { },
4263 { { 0, 1 } },
4265 /* BPF_JMP | BPF_JSET | BPF_X */
4267 "JMP_JSET_X: if (0x3 & 0x2) return 1",
4268 .u.insns_int = {
4269 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4270 BPF_LD_IMM64(R1, 3),
4271 BPF_LD_IMM64(R2, 2),
4272 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4273 BPF_EXIT_INSN(),
4274 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4275 BPF_EXIT_INSN(),
4277 INTERNAL,
4278 { },
4279 { { 0, 1 } },
4282 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
4283 .u.insns_int = {
4284 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4285 BPF_LD_IMM64(R1, 3),
4286 BPF_LD_IMM64(R2, 0xffffffff),
4287 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4288 BPF_EXIT_INSN(),
4289 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4290 BPF_EXIT_INSN(),
4292 INTERNAL,
4293 { },
4294 { { 0, 1 } },
4297 "JMP_JA: Jump, gap, jump, ...",
4298 { },
4299 CLASSIC | FLAG_NO_DATA,
4300 { },
4301 { { 0, 0xababcbac } },
4302 .fill_helper = bpf_fill_ja,
4304 { /* Mainly checking JIT here. */
4305 "BPF_MAXINSNS: Maximum possible literals",
4306 { },
4307 CLASSIC | FLAG_NO_DATA,
4308 { },
4309 { { 0, 0xffffffff } },
4310 .fill_helper = bpf_fill_maxinsns1,
4312 { /* Mainly checking JIT here. */
4313 "BPF_MAXINSNS: Single literal",
4314 { },
4315 CLASSIC | FLAG_NO_DATA,
4316 { },
4317 { { 0, 0xfefefefe } },
4318 .fill_helper = bpf_fill_maxinsns2,
4320 { /* Mainly checking JIT here. */
4321 "BPF_MAXINSNS: Run/add until end",
4322 { },
4323 CLASSIC | FLAG_NO_DATA,
4324 { },
4325 { { 0, 0x947bf368 } },
4326 .fill_helper = bpf_fill_maxinsns3,
4329 "BPF_MAXINSNS: Too many instructions",
4330 { },
4331 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4332 { },
4333 { },
4334 .fill_helper = bpf_fill_maxinsns4,
4336 { /* Mainly checking JIT here. */
4337 "BPF_MAXINSNS: Very long jump",
4338 { },
4339 CLASSIC | FLAG_NO_DATA,
4340 { },
4341 { { 0, 0xabababab } },
4342 .fill_helper = bpf_fill_maxinsns5,
4344 { /* Mainly checking JIT here. */
4345 "BPF_MAXINSNS: Ctx heavy transformations",
4346 { },
4347 CLASSIC,
4348 { },
4350 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
4351 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
4353 .fill_helper = bpf_fill_maxinsns6,
4355 { /* Mainly checking JIT here. */
4356 "BPF_MAXINSNS: Call heavy transformations",
4357 { },
4358 CLASSIC | FLAG_NO_DATA,
4359 { },
4360 { { 1, 0 }, { 10, 0 } },
4361 .fill_helper = bpf_fill_maxinsns7,
4363 { /* Mainly checking JIT here. */
4364 "BPF_MAXINSNS: Jump heavy test",
4365 { },
4366 CLASSIC | FLAG_NO_DATA,
4367 { },
4368 { { 0, 0xffffffff } },
4369 .fill_helper = bpf_fill_maxinsns8,
4371 { /* Mainly checking JIT here. */
4372 "BPF_MAXINSNS: Very long jump backwards",
4373 { },
4374 INTERNAL | FLAG_NO_DATA,
4375 { },
4376 { { 0, 0xcbababab } },
4377 .fill_helper = bpf_fill_maxinsns9,
4379 { /* Mainly checking JIT here. */
4380 "BPF_MAXINSNS: Edge hopping nuthouse",
4381 { },
4382 INTERNAL | FLAG_NO_DATA,
4383 { },
4384 { { 0, 0xabababac } },
4385 .fill_helper = bpf_fill_maxinsns10,
4388 "BPF_MAXINSNS: Jump, gap, jump, ...",
4389 { },
4390 CLASSIC | FLAG_NO_DATA,
4391 { },
4392 { { 0, 0xababcbac } },
4393 .fill_helper = bpf_fill_maxinsns11,
4397 static struct net_device dev;
4399 static struct sk_buff *populate_skb(char *buf, int size)
4401 struct sk_buff *skb;
4403 if (size >= MAX_DATA)
4404 return NULL;
4406 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
4407 if (!skb)
4408 return NULL;
4410 memcpy(__skb_put(skb, size), buf, size);
4412 /* Initialize a fake skb with test pattern. */
4413 skb_reset_mac_header(skb);
4414 skb->protocol = htons(ETH_P_IP);
4415 skb->pkt_type = SKB_TYPE;
4416 skb->mark = SKB_MARK;
4417 skb->hash = SKB_HASH;
4418 skb->queue_mapping = SKB_QUEUE_MAP;
4419 skb->vlan_tci = SKB_VLAN_TCI;
4420 skb->dev = &dev;
4421 skb->dev->ifindex = SKB_DEV_IFINDEX;
4422 skb->dev->type = SKB_DEV_TYPE;
4423 skb_set_network_header(skb, min(size, ETH_HLEN));
4425 return skb;
4428 static void *generate_test_data(struct bpf_test *test, int sub)
4430 if (test->aux & FLAG_NO_DATA)
4431 return NULL;
4433 /* Test case expects an skb, so populate one. Various
4434 * subtests generate skbs of different sizes based on
4435 * the same data.
4437 return populate_skb(test->data, test->test[sub].data_size);
4440 static void release_test_data(const struct bpf_test *test, void *data)
4442 if (test->aux & FLAG_NO_DATA)
4443 return;
4445 kfree_skb(data);
4448 static int filter_length(int which)
4450 struct sock_filter *fp;
4451 int len;
4453 if (tests[which].fill_helper)
4454 return tests[which].u.ptr.len;
4456 fp = tests[which].u.insns;
4457 for (len = MAX_INSNS - 1; len > 0; --len)
4458 if (fp[len].code != 0 || fp[len].k != 0)
4459 break;
4461 return len + 1;
4464 static void *filter_pointer(int which)
4466 if (tests[which].fill_helper)
4467 return tests[which].u.ptr.insns;
4468 else
4469 return tests[which].u.insns;
4472 static struct bpf_prog *generate_filter(int which, int *err)
4474 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
4475 unsigned int flen = filter_length(which);
4476 void *fptr = filter_pointer(which);
4477 struct sock_fprog_kern fprog;
4478 struct bpf_prog *fp;
4480 switch (test_type) {
4481 case CLASSIC:
4482 fprog.filter = fptr;
4483 fprog.len = flen;
4485 *err = bpf_prog_create(&fp, &fprog);
4486 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
4487 if (*err == -EINVAL) {
4488 pr_cont("PASS\n");
4489 /* Verifier rejected filter as expected. */
4490 *err = 0;
4491 return NULL;
4492 } else {
4493 pr_cont("UNEXPECTED_PASS\n");
4494 /* Verifier didn't reject the test that's
4495 * bad enough, just return!
4497 *err = -EINVAL;
4498 return NULL;
4501 /* We don't expect to fail. */
4502 if (*err) {
4503 pr_cont("FAIL to attach err=%d len=%d\n",
4504 *err, fprog.len);
4505 return NULL;
4507 break;
4509 case INTERNAL:
4510 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
4511 if (fp == NULL) {
4512 pr_cont("UNEXPECTED_FAIL no memory left\n");
4513 *err = -ENOMEM;
4514 return NULL;
4517 fp->len = flen;
4518 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
4520 bpf_prog_select_runtime(fp);
4521 break;
4524 *err = 0;
4525 return fp;
4528 static void release_filter(struct bpf_prog *fp, int which)
4530 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
4532 switch (test_type) {
4533 case CLASSIC:
4534 bpf_prog_destroy(fp);
4535 break;
4536 case INTERNAL:
4537 bpf_prog_free(fp);
4538 break;
4542 static int __run_one(const struct bpf_prog *fp, const void *data,
4543 int runs, u64 *duration)
4545 u64 start, finish;
4546 int ret = 0, i;
4548 start = ktime_to_us(ktime_get());
4550 for (i = 0; i < runs; i++)
4551 ret = BPF_PROG_RUN(fp, data);
4553 finish = ktime_to_us(ktime_get());
4555 *duration = (finish - start) * 1000ULL;
4556 do_div(*duration, runs);
4558 return ret;
4561 static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
4563 int err_cnt = 0, i, runs = MAX_TESTRUNS;
4565 for (i = 0; i < MAX_SUBTESTS; i++) {
4566 void *data;
4567 u64 duration;
4568 u32 ret;
4570 if (test->test[i].data_size == 0 &&
4571 test->test[i].result == 0)
4572 break;
4574 data = generate_test_data(test, i);
4575 ret = __run_one(fp, data, runs, &duration);
4576 release_test_data(test, data);
4578 if (ret == test->test[i].result) {
4579 pr_cont("%lld ", duration);
4580 } else {
4581 pr_cont("ret %d != %d ", ret,
4582 test->test[i].result);
4583 err_cnt++;
4587 return err_cnt;
4590 static __init int prepare_bpf_tests(void)
4592 int i;
4594 for (i = 0; i < ARRAY_SIZE(tests); i++) {
4595 if (tests[i].fill_helper &&
4596 tests[i].fill_helper(&tests[i]) < 0)
4597 return -ENOMEM;
4600 return 0;
4603 static __init void destroy_bpf_tests(void)
4605 int i;
4607 for (i = 0; i < ARRAY_SIZE(tests); i++) {
4608 if (tests[i].fill_helper)
4609 kfree(tests[i].u.ptr.insns);
4613 static __init int test_bpf(void)
4615 int i, err_cnt = 0, pass_cnt = 0;
4616 int jit_cnt = 0, run_cnt = 0;
4618 for (i = 0; i < ARRAY_SIZE(tests); i++) {
4619 struct bpf_prog *fp;
4620 int err;
4622 pr_info("#%d %s ", i, tests[i].descr);
4624 fp = generate_filter(i, &err);
4625 if (fp == NULL) {
4626 if (err == 0) {
4627 pass_cnt++;
4628 continue;
4631 return err;
4634 pr_cont("jited:%u ", fp->jited);
4636 run_cnt++;
4637 if (fp->jited)
4638 jit_cnt++;
4640 err = run_one(fp, &tests[i]);
4641 release_filter(fp, i);
4643 if (err) {
4644 pr_cont("FAIL (%d times)\n", err);
4645 err_cnt++;
4646 } else {
4647 pr_cont("PASS\n");
4648 pass_cnt++;
4652 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
4653 pass_cnt, err_cnt, jit_cnt, run_cnt);
4655 return err_cnt ? -EINVAL : 0;
4658 static int __init test_bpf_init(void)
4660 int ret;
4662 ret = prepare_bpf_tests();
4663 if (ret < 0)
4664 return ret;
4666 ret = test_bpf();
4668 destroy_bpf_tests();
4669 return ret;
4672 static void __exit test_bpf_exit(void)
4676 module_init(test_bpf_init);
4677 module_exit(test_bpf_exit);
4679 MODULE_LICENSE("GPL");