x86/entry/64: Get rid of the ALLOC_PT_GPREGS_ON_STACK and SAVE_AND_CLEAR_REGS macros
[linux-2.6/btrfs-unstable.git] / lib / test_bpf.c
blobf369889e521d7e7f1e237236651532e6a862e0f5
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/bpf.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_vlan.h>
25 #include <linux/random.h>
26 #include <linux/highmem.h>
28 /* General test specific settings */
29 #define MAX_SUBTESTS 3
30 #define MAX_TESTRUNS 10000
31 #define MAX_DATA 128
32 #define MAX_INSNS 512
33 #define MAX_K 0xffffFFFF
35 /* Few constants used to init test 'skb' */
36 #define SKB_TYPE 3
37 #define SKB_MARK 0x1234aaaa
38 #define SKB_HASH 0x1234aaab
39 #define SKB_QUEUE_MAP 123
40 #define SKB_VLAN_TCI 0xffff
41 #define SKB_DEV_IFINDEX 577
42 #define SKB_DEV_TYPE 588
44 /* Redefine REGs to make tests less verbose */
45 #define R0 BPF_REG_0
46 #define R1 BPF_REG_1
47 #define R2 BPF_REG_2
48 #define R3 BPF_REG_3
49 #define R4 BPF_REG_4
50 #define R5 BPF_REG_5
51 #define R6 BPF_REG_6
52 #define R7 BPF_REG_7
53 #define R8 BPF_REG_8
54 #define R9 BPF_REG_9
55 #define R10 BPF_REG_10
57 /* Flags that can be passed to test cases */
58 #define FLAG_NO_DATA BIT(0)
59 #define FLAG_EXPECTED_FAIL BIT(1)
60 #define FLAG_SKB_FRAG BIT(2)
62 enum {
63 CLASSIC = BIT(6), /* Old BPF instructions only. */
64 INTERNAL = BIT(7), /* Extended instruction set. */
67 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
69 struct bpf_test {
70 const char *descr;
71 union {
72 struct sock_filter insns[MAX_INSNS];
73 struct bpf_insn insns_int[MAX_INSNS];
74 struct {
75 void *insns;
76 unsigned int len;
77 } ptr;
78 } u;
79 __u8 aux;
80 __u8 data[MAX_DATA];
81 struct {
82 int data_size;
83 __u32 result;
84 } test[MAX_SUBTESTS];
85 int (*fill_helper)(struct bpf_test *self);
86 __u8 frag_data[MAX_DATA];
87 int stack_depth; /* for eBPF only, since tests don't call verifier */
90 /* Large test cases need separate allocation and fill handler. */
92 static int bpf_fill_maxinsns1(struct bpf_test *self)
94 unsigned int len = BPF_MAXINSNS;
95 struct sock_filter *insn;
96 __u32 k = ~0;
97 int i;
99 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
100 if (!insn)
101 return -ENOMEM;
103 for (i = 0; i < len; i++, k--)
104 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
106 self->u.ptr.insns = insn;
107 self->u.ptr.len = len;
109 return 0;
112 static int bpf_fill_maxinsns2(struct bpf_test *self)
114 unsigned int len = BPF_MAXINSNS;
115 struct sock_filter *insn;
116 int i;
118 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
119 if (!insn)
120 return -ENOMEM;
122 for (i = 0; i < len; i++)
123 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
125 self->u.ptr.insns = insn;
126 self->u.ptr.len = len;
128 return 0;
131 static int bpf_fill_maxinsns3(struct bpf_test *self)
133 unsigned int len = BPF_MAXINSNS;
134 struct sock_filter *insn;
135 struct rnd_state rnd;
136 int i;
138 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
139 if (!insn)
140 return -ENOMEM;
142 prandom_seed_state(&rnd, 3141592653589793238ULL);
144 for (i = 0; i < len - 1; i++) {
145 __u32 k = prandom_u32_state(&rnd);
147 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
150 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
152 self->u.ptr.insns = insn;
153 self->u.ptr.len = len;
155 return 0;
158 static int bpf_fill_maxinsns4(struct bpf_test *self)
160 unsigned int len = BPF_MAXINSNS + 1;
161 struct sock_filter *insn;
162 int i;
164 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
165 if (!insn)
166 return -ENOMEM;
168 for (i = 0; i < len; i++)
169 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
171 self->u.ptr.insns = insn;
172 self->u.ptr.len = len;
174 return 0;
177 static int bpf_fill_maxinsns5(struct bpf_test *self)
179 unsigned int len = BPF_MAXINSNS;
180 struct sock_filter *insn;
181 int i;
183 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
184 if (!insn)
185 return -ENOMEM;
187 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
189 for (i = 1; i < len - 1; i++)
190 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
192 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
194 self->u.ptr.insns = insn;
195 self->u.ptr.len = len;
197 return 0;
200 static int bpf_fill_maxinsns6(struct bpf_test *self)
202 unsigned int len = BPF_MAXINSNS;
203 struct sock_filter *insn;
204 int i;
206 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
207 if (!insn)
208 return -ENOMEM;
210 for (i = 0; i < len - 1; i++)
211 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
212 SKF_AD_VLAN_TAG_PRESENT);
214 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
216 self->u.ptr.insns = insn;
217 self->u.ptr.len = len;
219 return 0;
222 static int bpf_fill_maxinsns7(struct bpf_test *self)
224 unsigned int len = BPF_MAXINSNS;
225 struct sock_filter *insn;
226 int i;
228 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
229 if (!insn)
230 return -ENOMEM;
232 for (i = 0; i < len - 4; i++)
233 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 SKF_AD_CPU);
236 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
237 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
238 SKF_AD_CPU);
239 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
240 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
242 self->u.ptr.insns = insn;
243 self->u.ptr.len = len;
245 return 0;
248 static int bpf_fill_maxinsns8(struct bpf_test *self)
250 unsigned int len = BPF_MAXINSNS;
251 struct sock_filter *insn;
252 int i, jmp_off = len - 3;
254 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
255 if (!insn)
256 return -ENOMEM;
258 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
260 for (i = 1; i < len - 1; i++)
261 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
263 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
265 self->u.ptr.insns = insn;
266 self->u.ptr.len = len;
268 return 0;
271 static int bpf_fill_maxinsns9(struct bpf_test *self)
273 unsigned int len = BPF_MAXINSNS;
274 struct bpf_insn *insn;
275 int i;
277 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
278 if (!insn)
279 return -ENOMEM;
281 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
282 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
283 insn[2] = BPF_EXIT_INSN();
285 for (i = 3; i < len - 2; i++)
286 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
288 insn[len - 2] = BPF_EXIT_INSN();
289 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
291 self->u.ptr.insns = insn;
292 self->u.ptr.len = len;
294 return 0;
297 static int bpf_fill_maxinsns10(struct bpf_test *self)
299 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
300 struct bpf_insn *insn;
301 int i;
303 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
304 if (!insn)
305 return -ENOMEM;
307 for (i = 0; i < hlen / 2; i++)
308 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
309 for (i = hlen - 1; i > hlen / 2; i--)
310 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
312 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
313 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
314 insn[hlen + 1] = BPF_EXIT_INSN();
316 self->u.ptr.insns = insn;
317 self->u.ptr.len = len;
319 return 0;
322 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
323 unsigned int plen)
325 struct sock_filter *insn;
326 unsigned int rlen;
327 int i, j;
329 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
330 if (!insn)
331 return -ENOMEM;
333 rlen = (len % plen) - 1;
335 for (i = 0; i + plen < len; i += plen)
336 for (j = 0; j < plen; j++)
337 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
338 plen - 1 - j, 0, 0);
339 for (j = 0; j < rlen; j++)
340 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
341 0, 0);
343 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
345 self->u.ptr.insns = insn;
346 self->u.ptr.len = len;
348 return 0;
351 static int bpf_fill_maxinsns11(struct bpf_test *self)
353 /* Hits 70 passes on x86_64, so cannot get JITed there. */
354 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
357 static int bpf_fill_ja(struct bpf_test *self)
359 /* Hits exactly 11 passes on x86_64 JIT. */
360 return __bpf_fill_ja(self, 12, 9);
363 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
365 unsigned int len = BPF_MAXINSNS;
366 struct sock_filter *insn;
367 int i;
369 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
370 if (!insn)
371 return -ENOMEM;
373 for (i = 0; i < len - 1; i += 2) {
374 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
375 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
376 SKF_AD_OFF + SKF_AD_CPU);
379 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
381 self->u.ptr.insns = insn;
382 self->u.ptr.len = len;
384 return 0;
387 #define PUSH_CNT 68
388 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
389 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
391 unsigned int len = BPF_MAXINSNS;
392 struct bpf_insn *insn;
393 int i = 0, j, k = 0;
395 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
396 if (!insn)
397 return -ENOMEM;
399 insn[i++] = BPF_MOV64_REG(R6, R1);
400 loop:
401 for (j = 0; j < PUSH_CNT; j++) {
402 insn[i++] = BPF_LD_ABS(BPF_B, 0);
403 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
404 i++;
405 insn[i++] = BPF_MOV64_REG(R1, R6);
406 insn[i++] = BPF_MOV64_IMM(R2, 1);
407 insn[i++] = BPF_MOV64_IMM(R3, 2);
408 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
409 bpf_skb_vlan_push_proto.func - __bpf_call_base);
410 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
411 i++;
414 for (j = 0; j < PUSH_CNT; j++) {
415 insn[i++] = BPF_LD_ABS(BPF_B, 0);
416 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
417 i++;
418 insn[i++] = BPF_MOV64_REG(R1, R6);
419 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
420 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
421 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
422 i++;
424 if (++k < 5)
425 goto loop;
427 for (; i < len - 1; i++)
428 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
430 insn[len - 1] = BPF_EXIT_INSN();
432 self->u.ptr.insns = insn;
433 self->u.ptr.len = len;
435 return 0;
438 static int bpf_fill_ld_abs_vlan_push_pop2(struct bpf_test *self)
440 struct bpf_insn *insn;
442 insn = kmalloc_array(16, sizeof(*insn), GFP_KERNEL);
443 if (!insn)
444 return -ENOMEM;
446 /* Due to func address being non-const, we need to
447 * assemble this here.
449 insn[0] = BPF_MOV64_REG(R6, R1);
450 insn[1] = BPF_LD_ABS(BPF_B, 0);
451 insn[2] = BPF_LD_ABS(BPF_H, 0);
452 insn[3] = BPF_LD_ABS(BPF_W, 0);
453 insn[4] = BPF_MOV64_REG(R7, R6);
454 insn[5] = BPF_MOV64_IMM(R6, 0);
455 insn[6] = BPF_MOV64_REG(R1, R7);
456 insn[7] = BPF_MOV64_IMM(R2, 1);
457 insn[8] = BPF_MOV64_IMM(R3, 2);
458 insn[9] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
459 bpf_skb_vlan_push_proto.func - __bpf_call_base);
460 insn[10] = BPF_MOV64_REG(R6, R7);
461 insn[11] = BPF_LD_ABS(BPF_B, 0);
462 insn[12] = BPF_LD_ABS(BPF_H, 0);
463 insn[13] = BPF_LD_ABS(BPF_W, 0);
464 insn[14] = BPF_MOV64_IMM(R0, 42);
465 insn[15] = BPF_EXIT_INSN();
467 self->u.ptr.insns = insn;
468 self->u.ptr.len = 16;
470 return 0;
473 static int bpf_fill_jump_around_ld_abs(struct bpf_test *self)
475 unsigned int len = BPF_MAXINSNS;
476 struct bpf_insn *insn;
477 int i = 0;
479 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
480 if (!insn)
481 return -ENOMEM;
483 insn[i++] = BPF_MOV64_REG(R6, R1);
484 insn[i++] = BPF_LD_ABS(BPF_B, 0);
485 insn[i] = BPF_JMP_IMM(BPF_JEQ, R0, 10, len - i - 2);
486 i++;
487 while (i < len - 1)
488 insn[i++] = BPF_LD_ABS(BPF_B, 1);
489 insn[i] = BPF_EXIT_INSN();
491 self->u.ptr.insns = insn;
492 self->u.ptr.len = len;
494 return 0;
497 static int __bpf_fill_stxdw(struct bpf_test *self, int size)
499 unsigned int len = BPF_MAXINSNS;
500 struct bpf_insn *insn;
501 int i;
503 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
504 if (!insn)
505 return -ENOMEM;
507 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
508 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
510 for (i = 2; i < len - 2; i++)
511 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
513 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
514 insn[len - 1] = BPF_EXIT_INSN();
516 self->u.ptr.insns = insn;
517 self->u.ptr.len = len;
518 self->stack_depth = 40;
520 return 0;
523 static int bpf_fill_stxw(struct bpf_test *self)
525 return __bpf_fill_stxdw(self, BPF_W);
528 static int bpf_fill_stxdw(struct bpf_test *self)
530 return __bpf_fill_stxdw(self, BPF_DW);
533 static struct bpf_test tests[] = {
535 "TAX",
536 .u.insns = {
537 BPF_STMT(BPF_LD | BPF_IMM, 1),
538 BPF_STMT(BPF_MISC | BPF_TAX, 0),
539 BPF_STMT(BPF_LD | BPF_IMM, 2),
540 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
541 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
542 BPF_STMT(BPF_MISC | BPF_TAX, 0),
543 BPF_STMT(BPF_LD | BPF_LEN, 0),
544 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
545 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
546 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
547 BPF_STMT(BPF_RET | BPF_A, 0)
549 CLASSIC,
550 { 10, 20, 30, 40, 50 },
551 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
554 "TXA",
555 .u.insns = {
556 BPF_STMT(BPF_LDX | BPF_LEN, 0),
557 BPF_STMT(BPF_MISC | BPF_TXA, 0),
558 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
559 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
561 CLASSIC,
562 { 10, 20, 30, 40, 50 },
563 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
566 "ADD_SUB_MUL_K",
567 .u.insns = {
568 BPF_STMT(BPF_LD | BPF_IMM, 1),
569 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
570 BPF_STMT(BPF_LDX | BPF_IMM, 3),
571 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
572 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
573 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
574 BPF_STMT(BPF_RET | BPF_A, 0)
576 CLASSIC | FLAG_NO_DATA,
577 { },
578 { { 0, 0xfffffffd } }
581 "DIV_MOD_KX",
582 .u.insns = {
583 BPF_STMT(BPF_LD | BPF_IMM, 8),
584 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
585 BPF_STMT(BPF_MISC | BPF_TAX, 0),
586 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
587 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
590 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
591 BPF_STMT(BPF_MISC | BPF_TAX, 0),
592 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
593 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
594 BPF_STMT(BPF_MISC | BPF_TAX, 0),
595 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
596 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
597 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
598 BPF_STMT(BPF_RET | BPF_A, 0)
600 CLASSIC | FLAG_NO_DATA,
601 { },
602 { { 0, 0x20000000 } }
605 "AND_OR_LSH_K",
606 .u.insns = {
607 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
608 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
609 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
610 BPF_STMT(BPF_MISC | BPF_TAX, 0),
611 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
612 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
613 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
614 BPF_STMT(BPF_RET | BPF_A, 0)
616 CLASSIC | FLAG_NO_DATA,
617 { },
618 { { 0, 0x800000ff }, { 1, 0x800000ff } },
621 "LD_IMM_0",
622 .u.insns = {
623 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
624 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
625 BPF_STMT(BPF_RET | BPF_K, 0),
626 BPF_STMT(BPF_RET | BPF_K, 1),
628 CLASSIC,
629 { },
630 { { 1, 1 } },
633 "LD_IND",
634 .u.insns = {
635 BPF_STMT(BPF_LDX | BPF_LEN, 0),
636 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
637 BPF_STMT(BPF_RET | BPF_K, 1)
639 CLASSIC,
640 { },
641 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
644 "LD_ABS",
645 .u.insns = {
646 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
647 BPF_STMT(BPF_RET | BPF_K, 1)
649 CLASSIC,
650 { },
651 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
654 "LD_ABS_LL",
655 .u.insns = {
656 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
657 BPF_STMT(BPF_MISC | BPF_TAX, 0),
658 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
659 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
660 BPF_STMT(BPF_RET | BPF_A, 0)
662 CLASSIC,
663 { 1, 2, 3 },
664 { { 1, 0 }, { 2, 3 } },
667 "LD_IND_LL",
668 .u.insns = {
669 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
670 BPF_STMT(BPF_LDX | BPF_LEN, 0),
671 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
672 BPF_STMT(BPF_MISC | BPF_TAX, 0),
673 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
674 BPF_STMT(BPF_RET | BPF_A, 0)
676 CLASSIC,
677 { 1, 2, 3, 0xff },
678 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
681 "LD_ABS_NET",
682 .u.insns = {
683 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
684 BPF_STMT(BPF_MISC | BPF_TAX, 0),
685 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
686 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
687 BPF_STMT(BPF_RET | BPF_A, 0)
689 CLASSIC,
690 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
691 { { 15, 0 }, { 16, 3 } },
694 "LD_IND_NET",
695 .u.insns = {
696 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
697 BPF_STMT(BPF_LDX | BPF_LEN, 0),
698 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
699 BPF_STMT(BPF_MISC | BPF_TAX, 0),
700 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
701 BPF_STMT(BPF_RET | BPF_A, 0)
703 CLASSIC,
704 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
705 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
708 "LD_PKTTYPE",
709 .u.insns = {
710 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
711 SKF_AD_OFF + SKF_AD_PKTTYPE),
712 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
713 BPF_STMT(BPF_RET | BPF_K, 1),
714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
715 SKF_AD_OFF + SKF_AD_PKTTYPE),
716 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
717 BPF_STMT(BPF_RET | BPF_K, 1),
718 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
719 SKF_AD_OFF + SKF_AD_PKTTYPE),
720 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
721 BPF_STMT(BPF_RET | BPF_K, 1),
722 BPF_STMT(BPF_RET | BPF_A, 0)
724 CLASSIC,
725 { },
726 { { 1, 3 }, { 10, 3 } },
729 "LD_MARK",
730 .u.insns = {
731 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
732 SKF_AD_OFF + SKF_AD_MARK),
733 BPF_STMT(BPF_RET | BPF_A, 0)
735 CLASSIC,
736 { },
737 { { 1, SKB_MARK}, { 10, SKB_MARK} },
740 "LD_RXHASH",
741 .u.insns = {
742 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
743 SKF_AD_OFF + SKF_AD_RXHASH),
744 BPF_STMT(BPF_RET | BPF_A, 0)
746 CLASSIC,
747 { },
748 { { 1, SKB_HASH}, { 10, SKB_HASH} },
751 "LD_QUEUE",
752 .u.insns = {
753 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
754 SKF_AD_OFF + SKF_AD_QUEUE),
755 BPF_STMT(BPF_RET | BPF_A, 0)
757 CLASSIC,
758 { },
759 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
762 "LD_PROTOCOL",
763 .u.insns = {
764 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
765 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
766 BPF_STMT(BPF_RET | BPF_K, 0),
767 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
768 SKF_AD_OFF + SKF_AD_PROTOCOL),
769 BPF_STMT(BPF_MISC | BPF_TAX, 0),
770 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
771 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
772 BPF_STMT(BPF_RET | BPF_K, 0),
773 BPF_STMT(BPF_MISC | BPF_TXA, 0),
774 BPF_STMT(BPF_RET | BPF_A, 0)
776 CLASSIC,
777 { 10, 20, 30 },
778 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
781 "LD_VLAN_TAG",
782 .u.insns = {
783 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
784 SKF_AD_OFF + SKF_AD_VLAN_TAG),
785 BPF_STMT(BPF_RET | BPF_A, 0)
787 CLASSIC,
788 { },
790 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
791 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
795 "LD_VLAN_TAG_PRESENT",
796 .u.insns = {
797 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
798 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
799 BPF_STMT(BPF_RET | BPF_A, 0)
801 CLASSIC,
802 { },
804 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
805 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
809 "LD_IFINDEX",
810 .u.insns = {
811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_IFINDEX),
813 BPF_STMT(BPF_RET | BPF_A, 0)
815 CLASSIC,
816 { },
817 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
820 "LD_HATYPE",
821 .u.insns = {
822 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
823 SKF_AD_OFF + SKF_AD_HATYPE),
824 BPF_STMT(BPF_RET | BPF_A, 0)
826 CLASSIC,
827 { },
828 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
831 "LD_CPU",
832 .u.insns = {
833 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
834 SKF_AD_OFF + SKF_AD_CPU),
835 BPF_STMT(BPF_MISC | BPF_TAX, 0),
836 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
837 SKF_AD_OFF + SKF_AD_CPU),
838 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
839 BPF_STMT(BPF_RET | BPF_A, 0)
841 CLASSIC,
842 { },
843 { { 1, 0 }, { 10, 0 } },
846 "LD_NLATTR",
847 .u.insns = {
848 BPF_STMT(BPF_LDX | BPF_IMM, 2),
849 BPF_STMT(BPF_MISC | BPF_TXA, 0),
850 BPF_STMT(BPF_LDX | BPF_IMM, 3),
851 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
852 SKF_AD_OFF + SKF_AD_NLATTR),
853 BPF_STMT(BPF_RET | BPF_A, 0)
855 CLASSIC,
856 #ifdef __BIG_ENDIAN
857 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
858 #else
859 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
860 #endif
861 { { 4, 0 }, { 20, 6 } },
864 "LD_NLATTR_NEST",
865 .u.insns = {
866 BPF_STMT(BPF_LD | BPF_IMM, 2),
867 BPF_STMT(BPF_LDX | BPF_IMM, 3),
868 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
869 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
870 BPF_STMT(BPF_LD | BPF_IMM, 2),
871 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
872 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
873 BPF_STMT(BPF_LD | BPF_IMM, 2),
874 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
875 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
876 BPF_STMT(BPF_LD | BPF_IMM, 2),
877 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
878 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
879 BPF_STMT(BPF_LD | BPF_IMM, 2),
880 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
881 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
882 BPF_STMT(BPF_LD | BPF_IMM, 2),
883 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
884 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
885 BPF_STMT(BPF_LD | BPF_IMM, 2),
886 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
887 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
888 BPF_STMT(BPF_LD | BPF_IMM, 2),
889 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
890 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
891 BPF_STMT(BPF_RET | BPF_A, 0)
893 CLASSIC,
894 #ifdef __BIG_ENDIAN
895 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
896 #else
897 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
898 #endif
899 { { 4, 0 }, { 20, 10 } },
902 "LD_PAYLOAD_OFF",
903 .u.insns = {
904 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
905 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
906 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
907 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
908 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
909 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
910 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
911 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
912 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
913 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
914 BPF_STMT(BPF_RET | BPF_A, 0)
916 CLASSIC,
917 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
918 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
919 * id 9737, seq 1, length 64
921 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
922 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923 0x08, 0x00,
924 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
925 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
926 { { 30, 0 }, { 100, 42 } },
929 "LD_ANC_XOR",
930 .u.insns = {
931 BPF_STMT(BPF_LD | BPF_IMM, 10),
932 BPF_STMT(BPF_LDX | BPF_IMM, 300),
933 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
934 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
935 BPF_STMT(BPF_RET | BPF_A, 0)
937 CLASSIC,
938 { },
939 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
942 "SPILL_FILL",
943 .u.insns = {
944 BPF_STMT(BPF_LDX | BPF_LEN, 0),
945 BPF_STMT(BPF_LD | BPF_IMM, 2),
946 BPF_STMT(BPF_ALU | BPF_RSH, 1),
947 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
948 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
949 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
950 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
951 BPF_STMT(BPF_STX, 15), /* M3 = len */
952 BPF_STMT(BPF_LDX | BPF_MEM, 1),
953 BPF_STMT(BPF_LD | BPF_MEM, 2),
954 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
955 BPF_STMT(BPF_LDX | BPF_MEM, 15),
956 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
957 BPF_STMT(BPF_RET | BPF_A, 0)
959 CLASSIC,
960 { },
961 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
964 "JEQ",
965 .u.insns = {
966 BPF_STMT(BPF_LDX | BPF_LEN, 0),
967 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
968 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
969 BPF_STMT(BPF_RET | BPF_K, 1),
970 BPF_STMT(BPF_RET | BPF_K, MAX_K)
972 CLASSIC,
973 { 3, 3, 3, 3, 3 },
974 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
977 "JGT",
978 .u.insns = {
979 BPF_STMT(BPF_LDX | BPF_LEN, 0),
980 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
981 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
982 BPF_STMT(BPF_RET | BPF_K, 1),
983 BPF_STMT(BPF_RET | BPF_K, MAX_K)
985 CLASSIC,
986 { 4, 4, 4, 3, 3 },
987 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
990 "JGE (jt 0), test 1",
991 .u.insns = {
992 BPF_STMT(BPF_LDX | BPF_LEN, 0),
993 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
994 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
995 BPF_STMT(BPF_RET | BPF_K, 1),
996 BPF_STMT(BPF_RET | BPF_K, MAX_K)
998 CLASSIC,
999 { 4, 4, 4, 3, 3 },
1000 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
1003 "JGE (jt 0), test 2",
1004 .u.insns = {
1005 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1006 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
1007 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
1008 BPF_STMT(BPF_RET | BPF_K, 1),
1009 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1011 CLASSIC,
1012 { 4, 4, 5, 3, 3 },
1013 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
1016 "JGE",
1017 .u.insns = {
1018 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1019 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
1020 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
1021 BPF_STMT(BPF_RET | BPF_K, 10),
1022 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
1023 BPF_STMT(BPF_RET | BPF_K, 20),
1024 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
1025 BPF_STMT(BPF_RET | BPF_K, 30),
1026 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
1027 BPF_STMT(BPF_RET | BPF_K, 40),
1028 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1030 CLASSIC,
1031 { 1, 2, 3, 4, 5 },
1032 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
1035 "JSET",
1036 .u.insns = {
1037 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1038 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
1039 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1040 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1041 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1042 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1043 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
1044 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1045 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
1046 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
1047 BPF_STMT(BPF_RET | BPF_K, 10),
1048 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
1049 BPF_STMT(BPF_RET | BPF_K, 20),
1050 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1051 BPF_STMT(BPF_RET | BPF_K, 30),
1052 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1053 BPF_STMT(BPF_RET | BPF_K, 30),
1054 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1055 BPF_STMT(BPF_RET | BPF_K, 30),
1056 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1057 BPF_STMT(BPF_RET | BPF_K, 30),
1058 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1059 BPF_STMT(BPF_RET | BPF_K, 30),
1060 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1062 CLASSIC,
1063 { 0, 0xAA, 0x55, 1 },
1064 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
1067 "tcpdump port 22",
1068 .u.insns = {
1069 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1070 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1071 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1072 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1073 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1074 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1075 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1076 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1077 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1078 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1079 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1080 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1081 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1082 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1083 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1084 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1085 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1086 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1087 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1088 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1089 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1090 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1091 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1092 BPF_STMT(BPF_RET | BPF_K, 0),
1094 CLASSIC,
1095 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1096 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1097 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1098 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1100 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1101 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1102 0x08, 0x00,
1103 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1104 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1105 0x0a, 0x01, 0x01, 0x95, /* ip src */
1106 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1107 0xc2, 0x24,
1108 0x00, 0x16 /* dst port */ },
1109 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1112 "tcpdump complex",
1113 .u.insns = {
1114 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1115 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1116 * (len > 115 or len < 30000000000)' -d
1118 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1119 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1120 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1121 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1122 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1123 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1124 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1125 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1126 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1127 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1128 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1129 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1130 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1131 BPF_STMT(BPF_ST, 1),
1132 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1133 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1134 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1135 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1136 BPF_STMT(BPF_LD | BPF_MEM, 1),
1137 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1138 BPF_STMT(BPF_ST, 5),
1139 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1140 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1141 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1142 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1143 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1144 BPF_STMT(BPF_LD | BPF_MEM, 5),
1145 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1146 BPF_STMT(BPF_LD | BPF_LEN, 0),
1147 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1148 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1149 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1150 BPF_STMT(BPF_RET | BPF_K, 0),
1152 CLASSIC,
1153 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1154 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1155 0x08, 0x00,
1156 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1157 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1158 0x0a, 0x01, 0x01, 0x95, /* ip src */
1159 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1160 0xc2, 0x24,
1161 0x00, 0x16 /* dst port */ },
1162 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1165 "RET_A",
1166 .u.insns = {
1167 /* check that unitialized X and A contain zeros */
1168 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1169 BPF_STMT(BPF_RET | BPF_A, 0)
1171 CLASSIC,
1172 { },
1173 { {1, 0}, {2, 0} },
1176 "INT: ADD trivial",
1177 .u.insns_int = {
1178 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1179 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1180 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1181 BPF_ALU64_REG(BPF_SUB, R1, R2),
1182 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1183 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1184 BPF_ALU64_REG(BPF_MOV, R0, R1),
1185 BPF_EXIT_INSN(),
1187 INTERNAL,
1188 { },
1189 { { 0, 0xfffffffd } }
1192 "INT: MUL_X",
1193 .u.insns_int = {
1194 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1195 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1196 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1197 BPF_ALU64_REG(BPF_MUL, R1, R2),
1198 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1199 BPF_EXIT_INSN(),
1200 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1201 BPF_EXIT_INSN(),
1203 INTERNAL,
1204 { },
1205 { { 0, 1 } }
1208 "INT: MUL_X2",
1209 .u.insns_int = {
1210 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1211 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1212 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1213 BPF_ALU64_REG(BPF_MUL, R1, R2),
1214 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1215 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1216 BPF_EXIT_INSN(),
1217 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1218 BPF_EXIT_INSN(),
1220 INTERNAL,
1221 { },
1222 { { 0, 1 } }
1225 "INT: MUL32_X",
1226 .u.insns_int = {
1227 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1228 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1229 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1230 BPF_ALU32_REG(BPF_MUL, R1, R2),
1231 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1232 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1233 BPF_EXIT_INSN(),
1234 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1235 BPF_EXIT_INSN(),
1237 INTERNAL,
1238 { },
1239 { { 0, 1 } }
1242 /* Have to test all register combinations, since
1243 * JITing of different registers will produce
1244 * different asm code.
1246 "INT: ADD 64-bit",
1247 .u.insns_int = {
1248 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1249 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1250 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1251 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1252 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1253 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1254 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1255 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1256 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1257 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1258 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1259 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1260 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1261 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1262 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1263 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1264 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1265 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1266 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1267 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1268 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1269 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1270 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1271 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1272 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1273 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1274 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1275 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1276 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1277 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1278 BPF_ALU64_REG(BPF_ADD, R0, R0),
1279 BPF_ALU64_REG(BPF_ADD, R0, R1),
1280 BPF_ALU64_REG(BPF_ADD, R0, R2),
1281 BPF_ALU64_REG(BPF_ADD, R0, R3),
1282 BPF_ALU64_REG(BPF_ADD, R0, R4),
1283 BPF_ALU64_REG(BPF_ADD, R0, R5),
1284 BPF_ALU64_REG(BPF_ADD, R0, R6),
1285 BPF_ALU64_REG(BPF_ADD, R0, R7),
1286 BPF_ALU64_REG(BPF_ADD, R0, R8),
1287 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1288 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1289 BPF_EXIT_INSN(),
1290 BPF_ALU64_REG(BPF_ADD, R1, R0),
1291 BPF_ALU64_REG(BPF_ADD, R1, R1),
1292 BPF_ALU64_REG(BPF_ADD, R1, R2),
1293 BPF_ALU64_REG(BPF_ADD, R1, R3),
1294 BPF_ALU64_REG(BPF_ADD, R1, R4),
1295 BPF_ALU64_REG(BPF_ADD, R1, R5),
1296 BPF_ALU64_REG(BPF_ADD, R1, R6),
1297 BPF_ALU64_REG(BPF_ADD, R1, R7),
1298 BPF_ALU64_REG(BPF_ADD, R1, R8),
1299 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1300 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1301 BPF_EXIT_INSN(),
1302 BPF_ALU64_REG(BPF_ADD, R2, R0),
1303 BPF_ALU64_REG(BPF_ADD, R2, R1),
1304 BPF_ALU64_REG(BPF_ADD, R2, R2),
1305 BPF_ALU64_REG(BPF_ADD, R2, R3),
1306 BPF_ALU64_REG(BPF_ADD, R2, R4),
1307 BPF_ALU64_REG(BPF_ADD, R2, R5),
1308 BPF_ALU64_REG(BPF_ADD, R2, R6),
1309 BPF_ALU64_REG(BPF_ADD, R2, R7),
1310 BPF_ALU64_REG(BPF_ADD, R2, R8),
1311 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1312 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1313 BPF_EXIT_INSN(),
1314 BPF_ALU64_REG(BPF_ADD, R3, R0),
1315 BPF_ALU64_REG(BPF_ADD, R3, R1),
1316 BPF_ALU64_REG(BPF_ADD, R3, R2),
1317 BPF_ALU64_REG(BPF_ADD, R3, R3),
1318 BPF_ALU64_REG(BPF_ADD, R3, R4),
1319 BPF_ALU64_REG(BPF_ADD, R3, R5),
1320 BPF_ALU64_REG(BPF_ADD, R3, R6),
1321 BPF_ALU64_REG(BPF_ADD, R3, R7),
1322 BPF_ALU64_REG(BPF_ADD, R3, R8),
1323 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1324 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1325 BPF_EXIT_INSN(),
1326 BPF_ALU64_REG(BPF_ADD, R4, R0),
1327 BPF_ALU64_REG(BPF_ADD, R4, R1),
1328 BPF_ALU64_REG(BPF_ADD, R4, R2),
1329 BPF_ALU64_REG(BPF_ADD, R4, R3),
1330 BPF_ALU64_REG(BPF_ADD, R4, R4),
1331 BPF_ALU64_REG(BPF_ADD, R4, R5),
1332 BPF_ALU64_REG(BPF_ADD, R4, R6),
1333 BPF_ALU64_REG(BPF_ADD, R4, R7),
1334 BPF_ALU64_REG(BPF_ADD, R4, R8),
1335 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1336 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1337 BPF_EXIT_INSN(),
1338 BPF_ALU64_REG(BPF_ADD, R5, R0),
1339 BPF_ALU64_REG(BPF_ADD, R5, R1),
1340 BPF_ALU64_REG(BPF_ADD, R5, R2),
1341 BPF_ALU64_REG(BPF_ADD, R5, R3),
1342 BPF_ALU64_REG(BPF_ADD, R5, R4),
1343 BPF_ALU64_REG(BPF_ADD, R5, R5),
1344 BPF_ALU64_REG(BPF_ADD, R5, R6),
1345 BPF_ALU64_REG(BPF_ADD, R5, R7),
1346 BPF_ALU64_REG(BPF_ADD, R5, R8),
1347 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1348 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1349 BPF_EXIT_INSN(),
1350 BPF_ALU64_REG(BPF_ADD, R6, R0),
1351 BPF_ALU64_REG(BPF_ADD, R6, R1),
1352 BPF_ALU64_REG(BPF_ADD, R6, R2),
1353 BPF_ALU64_REG(BPF_ADD, R6, R3),
1354 BPF_ALU64_REG(BPF_ADD, R6, R4),
1355 BPF_ALU64_REG(BPF_ADD, R6, R5),
1356 BPF_ALU64_REG(BPF_ADD, R6, R6),
1357 BPF_ALU64_REG(BPF_ADD, R6, R7),
1358 BPF_ALU64_REG(BPF_ADD, R6, R8),
1359 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1360 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1361 BPF_EXIT_INSN(),
1362 BPF_ALU64_REG(BPF_ADD, R7, R0),
1363 BPF_ALU64_REG(BPF_ADD, R7, R1),
1364 BPF_ALU64_REG(BPF_ADD, R7, R2),
1365 BPF_ALU64_REG(BPF_ADD, R7, R3),
1366 BPF_ALU64_REG(BPF_ADD, R7, R4),
1367 BPF_ALU64_REG(BPF_ADD, R7, R5),
1368 BPF_ALU64_REG(BPF_ADD, R7, R6),
1369 BPF_ALU64_REG(BPF_ADD, R7, R7),
1370 BPF_ALU64_REG(BPF_ADD, R7, R8),
1371 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1372 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1373 BPF_EXIT_INSN(),
1374 BPF_ALU64_REG(BPF_ADD, R8, R0),
1375 BPF_ALU64_REG(BPF_ADD, R8, R1),
1376 BPF_ALU64_REG(BPF_ADD, R8, R2),
1377 BPF_ALU64_REG(BPF_ADD, R8, R3),
1378 BPF_ALU64_REG(BPF_ADD, R8, R4),
1379 BPF_ALU64_REG(BPF_ADD, R8, R5),
1380 BPF_ALU64_REG(BPF_ADD, R8, R6),
1381 BPF_ALU64_REG(BPF_ADD, R8, R7),
1382 BPF_ALU64_REG(BPF_ADD, R8, R8),
1383 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1384 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1385 BPF_EXIT_INSN(),
1386 BPF_ALU64_REG(BPF_ADD, R9, R0),
1387 BPF_ALU64_REG(BPF_ADD, R9, R1),
1388 BPF_ALU64_REG(BPF_ADD, R9, R2),
1389 BPF_ALU64_REG(BPF_ADD, R9, R3),
1390 BPF_ALU64_REG(BPF_ADD, R9, R4),
1391 BPF_ALU64_REG(BPF_ADD, R9, R5),
1392 BPF_ALU64_REG(BPF_ADD, R9, R6),
1393 BPF_ALU64_REG(BPF_ADD, R9, R7),
1394 BPF_ALU64_REG(BPF_ADD, R9, R8),
1395 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1396 BPF_ALU64_REG(BPF_MOV, R0, R9),
1397 BPF_EXIT_INSN(),
1399 INTERNAL,
1400 { },
1401 { { 0, 2957380 } }
1404 "INT: ADD 32-bit",
1405 .u.insns_int = {
1406 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1407 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1408 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1409 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1410 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1411 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1412 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1413 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1414 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1415 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1416 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1417 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1418 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1419 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1420 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1421 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1422 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1423 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1424 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1425 BPF_ALU32_REG(BPF_ADD, R0, R1),
1426 BPF_ALU32_REG(BPF_ADD, R0, R2),
1427 BPF_ALU32_REG(BPF_ADD, R0, R3),
1428 BPF_ALU32_REG(BPF_ADD, R0, R4),
1429 BPF_ALU32_REG(BPF_ADD, R0, R5),
1430 BPF_ALU32_REG(BPF_ADD, R0, R6),
1431 BPF_ALU32_REG(BPF_ADD, R0, R7),
1432 BPF_ALU32_REG(BPF_ADD, R0, R8),
1433 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1434 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1435 BPF_EXIT_INSN(),
1436 BPF_ALU32_REG(BPF_ADD, R1, R0),
1437 BPF_ALU32_REG(BPF_ADD, R1, R1),
1438 BPF_ALU32_REG(BPF_ADD, R1, R2),
1439 BPF_ALU32_REG(BPF_ADD, R1, R3),
1440 BPF_ALU32_REG(BPF_ADD, R1, R4),
1441 BPF_ALU32_REG(BPF_ADD, R1, R5),
1442 BPF_ALU32_REG(BPF_ADD, R1, R6),
1443 BPF_ALU32_REG(BPF_ADD, R1, R7),
1444 BPF_ALU32_REG(BPF_ADD, R1, R8),
1445 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1446 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1447 BPF_EXIT_INSN(),
1448 BPF_ALU32_REG(BPF_ADD, R2, R0),
1449 BPF_ALU32_REG(BPF_ADD, R2, R1),
1450 BPF_ALU32_REG(BPF_ADD, R2, R2),
1451 BPF_ALU32_REG(BPF_ADD, R2, R3),
1452 BPF_ALU32_REG(BPF_ADD, R2, R4),
1453 BPF_ALU32_REG(BPF_ADD, R2, R5),
1454 BPF_ALU32_REG(BPF_ADD, R2, R6),
1455 BPF_ALU32_REG(BPF_ADD, R2, R7),
1456 BPF_ALU32_REG(BPF_ADD, R2, R8),
1457 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1458 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1459 BPF_EXIT_INSN(),
1460 BPF_ALU32_REG(BPF_ADD, R3, R0),
1461 BPF_ALU32_REG(BPF_ADD, R3, R1),
1462 BPF_ALU32_REG(BPF_ADD, R3, R2),
1463 BPF_ALU32_REG(BPF_ADD, R3, R3),
1464 BPF_ALU32_REG(BPF_ADD, R3, R4),
1465 BPF_ALU32_REG(BPF_ADD, R3, R5),
1466 BPF_ALU32_REG(BPF_ADD, R3, R6),
1467 BPF_ALU32_REG(BPF_ADD, R3, R7),
1468 BPF_ALU32_REG(BPF_ADD, R3, R8),
1469 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1470 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1471 BPF_EXIT_INSN(),
1472 BPF_ALU32_REG(BPF_ADD, R4, R0),
1473 BPF_ALU32_REG(BPF_ADD, R4, R1),
1474 BPF_ALU32_REG(BPF_ADD, R4, R2),
1475 BPF_ALU32_REG(BPF_ADD, R4, R3),
1476 BPF_ALU32_REG(BPF_ADD, R4, R4),
1477 BPF_ALU32_REG(BPF_ADD, R4, R5),
1478 BPF_ALU32_REG(BPF_ADD, R4, R6),
1479 BPF_ALU32_REG(BPF_ADD, R4, R7),
1480 BPF_ALU32_REG(BPF_ADD, R4, R8),
1481 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1482 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1483 BPF_EXIT_INSN(),
1484 BPF_ALU32_REG(BPF_ADD, R5, R0),
1485 BPF_ALU32_REG(BPF_ADD, R5, R1),
1486 BPF_ALU32_REG(BPF_ADD, R5, R2),
1487 BPF_ALU32_REG(BPF_ADD, R5, R3),
1488 BPF_ALU32_REG(BPF_ADD, R5, R4),
1489 BPF_ALU32_REG(BPF_ADD, R5, R5),
1490 BPF_ALU32_REG(BPF_ADD, R5, R6),
1491 BPF_ALU32_REG(BPF_ADD, R5, R7),
1492 BPF_ALU32_REG(BPF_ADD, R5, R8),
1493 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1494 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1495 BPF_EXIT_INSN(),
1496 BPF_ALU32_REG(BPF_ADD, R6, R0),
1497 BPF_ALU32_REG(BPF_ADD, R6, R1),
1498 BPF_ALU32_REG(BPF_ADD, R6, R2),
1499 BPF_ALU32_REG(BPF_ADD, R6, R3),
1500 BPF_ALU32_REG(BPF_ADD, R6, R4),
1501 BPF_ALU32_REG(BPF_ADD, R6, R5),
1502 BPF_ALU32_REG(BPF_ADD, R6, R6),
1503 BPF_ALU32_REG(BPF_ADD, R6, R7),
1504 BPF_ALU32_REG(BPF_ADD, R6, R8),
1505 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1506 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1507 BPF_EXIT_INSN(),
1508 BPF_ALU32_REG(BPF_ADD, R7, R0),
1509 BPF_ALU32_REG(BPF_ADD, R7, R1),
1510 BPF_ALU32_REG(BPF_ADD, R7, R2),
1511 BPF_ALU32_REG(BPF_ADD, R7, R3),
1512 BPF_ALU32_REG(BPF_ADD, R7, R4),
1513 BPF_ALU32_REG(BPF_ADD, R7, R5),
1514 BPF_ALU32_REG(BPF_ADD, R7, R6),
1515 BPF_ALU32_REG(BPF_ADD, R7, R7),
1516 BPF_ALU32_REG(BPF_ADD, R7, R8),
1517 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1518 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1519 BPF_EXIT_INSN(),
1520 BPF_ALU32_REG(BPF_ADD, R8, R0),
1521 BPF_ALU32_REG(BPF_ADD, R8, R1),
1522 BPF_ALU32_REG(BPF_ADD, R8, R2),
1523 BPF_ALU32_REG(BPF_ADD, R8, R3),
1524 BPF_ALU32_REG(BPF_ADD, R8, R4),
1525 BPF_ALU32_REG(BPF_ADD, R8, R5),
1526 BPF_ALU32_REG(BPF_ADD, R8, R6),
1527 BPF_ALU32_REG(BPF_ADD, R8, R7),
1528 BPF_ALU32_REG(BPF_ADD, R8, R8),
1529 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1530 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1531 BPF_EXIT_INSN(),
1532 BPF_ALU32_REG(BPF_ADD, R9, R0),
1533 BPF_ALU32_REG(BPF_ADD, R9, R1),
1534 BPF_ALU32_REG(BPF_ADD, R9, R2),
1535 BPF_ALU32_REG(BPF_ADD, R9, R3),
1536 BPF_ALU32_REG(BPF_ADD, R9, R4),
1537 BPF_ALU32_REG(BPF_ADD, R9, R5),
1538 BPF_ALU32_REG(BPF_ADD, R9, R6),
1539 BPF_ALU32_REG(BPF_ADD, R9, R7),
1540 BPF_ALU32_REG(BPF_ADD, R9, R8),
1541 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1542 BPF_ALU32_REG(BPF_MOV, R0, R9),
1543 BPF_EXIT_INSN(),
1545 INTERNAL,
1546 { },
1547 { { 0, 2957380 } }
1549 { /* Mainly checking JIT here. */
1550 "INT: SUB",
1551 .u.insns_int = {
1552 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1553 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1554 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1555 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1556 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1557 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1558 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1559 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1560 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1561 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1562 BPF_ALU64_REG(BPF_SUB, R0, R0),
1563 BPF_ALU64_REG(BPF_SUB, R0, R1),
1564 BPF_ALU64_REG(BPF_SUB, R0, R2),
1565 BPF_ALU64_REG(BPF_SUB, R0, R3),
1566 BPF_ALU64_REG(BPF_SUB, R0, R4),
1567 BPF_ALU64_REG(BPF_SUB, R0, R5),
1568 BPF_ALU64_REG(BPF_SUB, R0, R6),
1569 BPF_ALU64_REG(BPF_SUB, R0, R7),
1570 BPF_ALU64_REG(BPF_SUB, R0, R8),
1571 BPF_ALU64_REG(BPF_SUB, R0, R9),
1572 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1573 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1574 BPF_EXIT_INSN(),
1575 BPF_ALU64_REG(BPF_SUB, R1, R0),
1576 BPF_ALU64_REG(BPF_SUB, R1, R2),
1577 BPF_ALU64_REG(BPF_SUB, R1, R3),
1578 BPF_ALU64_REG(BPF_SUB, R1, R4),
1579 BPF_ALU64_REG(BPF_SUB, R1, R5),
1580 BPF_ALU64_REG(BPF_SUB, R1, R6),
1581 BPF_ALU64_REG(BPF_SUB, R1, R7),
1582 BPF_ALU64_REG(BPF_SUB, R1, R8),
1583 BPF_ALU64_REG(BPF_SUB, R1, R9),
1584 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1585 BPF_ALU64_REG(BPF_SUB, R2, R0),
1586 BPF_ALU64_REG(BPF_SUB, R2, R1),
1587 BPF_ALU64_REG(BPF_SUB, R2, R3),
1588 BPF_ALU64_REG(BPF_SUB, R2, R4),
1589 BPF_ALU64_REG(BPF_SUB, R2, R5),
1590 BPF_ALU64_REG(BPF_SUB, R2, R6),
1591 BPF_ALU64_REG(BPF_SUB, R2, R7),
1592 BPF_ALU64_REG(BPF_SUB, R2, R8),
1593 BPF_ALU64_REG(BPF_SUB, R2, R9),
1594 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1595 BPF_ALU64_REG(BPF_SUB, R3, R0),
1596 BPF_ALU64_REG(BPF_SUB, R3, R1),
1597 BPF_ALU64_REG(BPF_SUB, R3, R2),
1598 BPF_ALU64_REG(BPF_SUB, R3, R4),
1599 BPF_ALU64_REG(BPF_SUB, R3, R5),
1600 BPF_ALU64_REG(BPF_SUB, R3, R6),
1601 BPF_ALU64_REG(BPF_SUB, R3, R7),
1602 BPF_ALU64_REG(BPF_SUB, R3, R8),
1603 BPF_ALU64_REG(BPF_SUB, R3, R9),
1604 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1605 BPF_ALU64_REG(BPF_SUB, R4, R0),
1606 BPF_ALU64_REG(BPF_SUB, R4, R1),
1607 BPF_ALU64_REG(BPF_SUB, R4, R2),
1608 BPF_ALU64_REG(BPF_SUB, R4, R3),
1609 BPF_ALU64_REG(BPF_SUB, R4, R5),
1610 BPF_ALU64_REG(BPF_SUB, R4, R6),
1611 BPF_ALU64_REG(BPF_SUB, R4, R7),
1612 BPF_ALU64_REG(BPF_SUB, R4, R8),
1613 BPF_ALU64_REG(BPF_SUB, R4, R9),
1614 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1615 BPF_ALU64_REG(BPF_SUB, R5, R0),
1616 BPF_ALU64_REG(BPF_SUB, R5, R1),
1617 BPF_ALU64_REG(BPF_SUB, R5, R2),
1618 BPF_ALU64_REG(BPF_SUB, R5, R3),
1619 BPF_ALU64_REG(BPF_SUB, R5, R4),
1620 BPF_ALU64_REG(BPF_SUB, R5, R6),
1621 BPF_ALU64_REG(BPF_SUB, R5, R7),
1622 BPF_ALU64_REG(BPF_SUB, R5, R8),
1623 BPF_ALU64_REG(BPF_SUB, R5, R9),
1624 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1625 BPF_ALU64_REG(BPF_SUB, R6, R0),
1626 BPF_ALU64_REG(BPF_SUB, R6, R1),
1627 BPF_ALU64_REG(BPF_SUB, R6, R2),
1628 BPF_ALU64_REG(BPF_SUB, R6, R3),
1629 BPF_ALU64_REG(BPF_SUB, R6, R4),
1630 BPF_ALU64_REG(BPF_SUB, R6, R5),
1631 BPF_ALU64_REG(BPF_SUB, R6, R7),
1632 BPF_ALU64_REG(BPF_SUB, R6, R8),
1633 BPF_ALU64_REG(BPF_SUB, R6, R9),
1634 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1635 BPF_ALU64_REG(BPF_SUB, R7, R0),
1636 BPF_ALU64_REG(BPF_SUB, R7, R1),
1637 BPF_ALU64_REG(BPF_SUB, R7, R2),
1638 BPF_ALU64_REG(BPF_SUB, R7, R3),
1639 BPF_ALU64_REG(BPF_SUB, R7, R4),
1640 BPF_ALU64_REG(BPF_SUB, R7, R5),
1641 BPF_ALU64_REG(BPF_SUB, R7, R6),
1642 BPF_ALU64_REG(BPF_SUB, R7, R8),
1643 BPF_ALU64_REG(BPF_SUB, R7, R9),
1644 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1645 BPF_ALU64_REG(BPF_SUB, R8, R0),
1646 BPF_ALU64_REG(BPF_SUB, R8, R1),
1647 BPF_ALU64_REG(BPF_SUB, R8, R2),
1648 BPF_ALU64_REG(BPF_SUB, R8, R3),
1649 BPF_ALU64_REG(BPF_SUB, R8, R4),
1650 BPF_ALU64_REG(BPF_SUB, R8, R5),
1651 BPF_ALU64_REG(BPF_SUB, R8, R6),
1652 BPF_ALU64_REG(BPF_SUB, R8, R7),
1653 BPF_ALU64_REG(BPF_SUB, R8, R9),
1654 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1655 BPF_ALU64_REG(BPF_SUB, R9, R0),
1656 BPF_ALU64_REG(BPF_SUB, R9, R1),
1657 BPF_ALU64_REG(BPF_SUB, R9, R2),
1658 BPF_ALU64_REG(BPF_SUB, R9, R3),
1659 BPF_ALU64_REG(BPF_SUB, R9, R4),
1660 BPF_ALU64_REG(BPF_SUB, R9, R5),
1661 BPF_ALU64_REG(BPF_SUB, R9, R6),
1662 BPF_ALU64_REG(BPF_SUB, R9, R7),
1663 BPF_ALU64_REG(BPF_SUB, R9, R8),
1664 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1665 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1666 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1667 BPF_ALU64_REG(BPF_SUB, R0, R1),
1668 BPF_ALU64_REG(BPF_SUB, R0, R2),
1669 BPF_ALU64_REG(BPF_SUB, R0, R3),
1670 BPF_ALU64_REG(BPF_SUB, R0, R4),
1671 BPF_ALU64_REG(BPF_SUB, R0, R5),
1672 BPF_ALU64_REG(BPF_SUB, R0, R6),
1673 BPF_ALU64_REG(BPF_SUB, R0, R7),
1674 BPF_ALU64_REG(BPF_SUB, R0, R8),
1675 BPF_ALU64_REG(BPF_SUB, R0, R9),
1676 BPF_EXIT_INSN(),
1678 INTERNAL,
1679 { },
1680 { { 0, 11 } }
1682 { /* Mainly checking JIT here. */
1683 "INT: XOR",
1684 .u.insns_int = {
1685 BPF_ALU64_REG(BPF_SUB, R0, R0),
1686 BPF_ALU64_REG(BPF_XOR, R1, R1),
1687 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1688 BPF_EXIT_INSN(),
1689 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1690 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1691 BPF_ALU64_REG(BPF_SUB, R1, R1),
1692 BPF_ALU64_REG(BPF_XOR, R2, R2),
1693 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1694 BPF_EXIT_INSN(),
1695 BPF_ALU64_REG(BPF_SUB, R2, R2),
1696 BPF_ALU64_REG(BPF_XOR, R3, R3),
1697 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1698 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1699 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1700 BPF_EXIT_INSN(),
1701 BPF_ALU64_REG(BPF_SUB, R3, R3),
1702 BPF_ALU64_REG(BPF_XOR, R4, R4),
1703 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1704 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1705 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1706 BPF_EXIT_INSN(),
1707 BPF_ALU64_REG(BPF_SUB, R4, R4),
1708 BPF_ALU64_REG(BPF_XOR, R5, R5),
1709 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1710 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1711 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1712 BPF_EXIT_INSN(),
1713 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1714 BPF_ALU64_REG(BPF_SUB, R5, R5),
1715 BPF_ALU64_REG(BPF_XOR, R6, R6),
1716 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1717 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1718 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1719 BPF_EXIT_INSN(),
1720 BPF_ALU64_REG(BPF_SUB, R6, R6),
1721 BPF_ALU64_REG(BPF_XOR, R7, R7),
1722 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1723 BPF_EXIT_INSN(),
1724 BPF_ALU64_REG(BPF_SUB, R7, R7),
1725 BPF_ALU64_REG(BPF_XOR, R8, R8),
1726 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1727 BPF_EXIT_INSN(),
1728 BPF_ALU64_REG(BPF_SUB, R8, R8),
1729 BPF_ALU64_REG(BPF_XOR, R9, R9),
1730 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1731 BPF_EXIT_INSN(),
1732 BPF_ALU64_REG(BPF_SUB, R9, R9),
1733 BPF_ALU64_REG(BPF_XOR, R0, R0),
1734 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1735 BPF_EXIT_INSN(),
1736 BPF_ALU64_REG(BPF_SUB, R1, R1),
1737 BPF_ALU64_REG(BPF_XOR, R0, R0),
1738 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1739 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1740 BPF_EXIT_INSN(),
1741 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1742 BPF_EXIT_INSN(),
1744 INTERNAL,
1745 { },
1746 { { 0, 1 } }
1748 { /* Mainly checking JIT here. */
1749 "INT: MUL",
1750 .u.insns_int = {
1751 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1752 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1753 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1754 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1755 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1756 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1757 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1758 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1759 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1760 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1761 BPF_ALU64_REG(BPF_MUL, R0, R0),
1762 BPF_ALU64_REG(BPF_MUL, R0, R1),
1763 BPF_ALU64_REG(BPF_MUL, R0, R2),
1764 BPF_ALU64_REG(BPF_MUL, R0, R3),
1765 BPF_ALU64_REG(BPF_MUL, R0, R4),
1766 BPF_ALU64_REG(BPF_MUL, R0, R5),
1767 BPF_ALU64_REG(BPF_MUL, R0, R6),
1768 BPF_ALU64_REG(BPF_MUL, R0, R7),
1769 BPF_ALU64_REG(BPF_MUL, R0, R8),
1770 BPF_ALU64_REG(BPF_MUL, R0, R9),
1771 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1772 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1773 BPF_EXIT_INSN(),
1774 BPF_ALU64_REG(BPF_MUL, R1, R0),
1775 BPF_ALU64_REG(BPF_MUL, R1, R2),
1776 BPF_ALU64_REG(BPF_MUL, R1, R3),
1777 BPF_ALU64_REG(BPF_MUL, R1, R4),
1778 BPF_ALU64_REG(BPF_MUL, R1, R5),
1779 BPF_ALU64_REG(BPF_MUL, R1, R6),
1780 BPF_ALU64_REG(BPF_MUL, R1, R7),
1781 BPF_ALU64_REG(BPF_MUL, R1, R8),
1782 BPF_ALU64_REG(BPF_MUL, R1, R9),
1783 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1784 BPF_ALU64_REG(BPF_MOV, R2, R1),
1785 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1786 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1787 BPF_EXIT_INSN(),
1788 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1789 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1790 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1791 BPF_EXIT_INSN(),
1792 BPF_ALU64_REG(BPF_MUL, R2, R0),
1793 BPF_ALU64_REG(BPF_MUL, R2, R1),
1794 BPF_ALU64_REG(BPF_MUL, R2, R3),
1795 BPF_ALU64_REG(BPF_MUL, R2, R4),
1796 BPF_ALU64_REG(BPF_MUL, R2, R5),
1797 BPF_ALU64_REG(BPF_MUL, R2, R6),
1798 BPF_ALU64_REG(BPF_MUL, R2, R7),
1799 BPF_ALU64_REG(BPF_MUL, R2, R8),
1800 BPF_ALU64_REG(BPF_MUL, R2, R9),
1801 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1802 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1803 BPF_ALU64_REG(BPF_MOV, R0, R2),
1804 BPF_EXIT_INSN(),
1806 INTERNAL,
1807 { },
1808 { { 0, 0x35d97ef2 } }
1810 { /* Mainly checking JIT here. */
1811 "MOV REG64",
1812 .u.insns_int = {
1813 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1814 BPF_MOV64_REG(R1, R0),
1815 BPF_MOV64_REG(R2, R1),
1816 BPF_MOV64_REG(R3, R2),
1817 BPF_MOV64_REG(R4, R3),
1818 BPF_MOV64_REG(R5, R4),
1819 BPF_MOV64_REG(R6, R5),
1820 BPF_MOV64_REG(R7, R6),
1821 BPF_MOV64_REG(R8, R7),
1822 BPF_MOV64_REG(R9, R8),
1823 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1824 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1825 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1826 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1827 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1828 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1829 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1830 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1831 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1832 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1833 BPF_ALU64_REG(BPF_ADD, R0, R0),
1834 BPF_ALU64_REG(BPF_ADD, R0, R1),
1835 BPF_ALU64_REG(BPF_ADD, R0, R2),
1836 BPF_ALU64_REG(BPF_ADD, R0, R3),
1837 BPF_ALU64_REG(BPF_ADD, R0, R4),
1838 BPF_ALU64_REG(BPF_ADD, R0, R5),
1839 BPF_ALU64_REG(BPF_ADD, R0, R6),
1840 BPF_ALU64_REG(BPF_ADD, R0, R7),
1841 BPF_ALU64_REG(BPF_ADD, R0, R8),
1842 BPF_ALU64_REG(BPF_ADD, R0, R9),
1843 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1844 BPF_EXIT_INSN(),
1846 INTERNAL,
1847 { },
1848 { { 0, 0xfefe } }
1850 { /* Mainly checking JIT here. */
1851 "MOV REG32",
1852 .u.insns_int = {
1853 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1854 BPF_MOV64_REG(R1, R0),
1855 BPF_MOV64_REG(R2, R1),
1856 BPF_MOV64_REG(R3, R2),
1857 BPF_MOV64_REG(R4, R3),
1858 BPF_MOV64_REG(R5, R4),
1859 BPF_MOV64_REG(R6, R5),
1860 BPF_MOV64_REG(R7, R6),
1861 BPF_MOV64_REG(R8, R7),
1862 BPF_MOV64_REG(R9, R8),
1863 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1864 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1865 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1866 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1867 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1868 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1869 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1870 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1871 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1872 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1873 BPF_ALU64_REG(BPF_ADD, R0, R0),
1874 BPF_ALU64_REG(BPF_ADD, R0, R1),
1875 BPF_ALU64_REG(BPF_ADD, R0, R2),
1876 BPF_ALU64_REG(BPF_ADD, R0, R3),
1877 BPF_ALU64_REG(BPF_ADD, R0, R4),
1878 BPF_ALU64_REG(BPF_ADD, R0, R5),
1879 BPF_ALU64_REG(BPF_ADD, R0, R6),
1880 BPF_ALU64_REG(BPF_ADD, R0, R7),
1881 BPF_ALU64_REG(BPF_ADD, R0, R8),
1882 BPF_ALU64_REG(BPF_ADD, R0, R9),
1883 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1884 BPF_EXIT_INSN(),
1886 INTERNAL,
1887 { },
1888 { { 0, 0xfefe } }
1890 { /* Mainly checking JIT here. */
1891 "LD IMM64",
1892 .u.insns_int = {
1893 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1894 BPF_MOV64_REG(R1, R0),
1895 BPF_MOV64_REG(R2, R1),
1896 BPF_MOV64_REG(R3, R2),
1897 BPF_MOV64_REG(R4, R3),
1898 BPF_MOV64_REG(R5, R4),
1899 BPF_MOV64_REG(R6, R5),
1900 BPF_MOV64_REG(R7, R6),
1901 BPF_MOV64_REG(R8, R7),
1902 BPF_MOV64_REG(R9, R8),
1903 BPF_LD_IMM64(R0, 0x0LL),
1904 BPF_LD_IMM64(R1, 0x0LL),
1905 BPF_LD_IMM64(R2, 0x0LL),
1906 BPF_LD_IMM64(R3, 0x0LL),
1907 BPF_LD_IMM64(R4, 0x0LL),
1908 BPF_LD_IMM64(R5, 0x0LL),
1909 BPF_LD_IMM64(R6, 0x0LL),
1910 BPF_LD_IMM64(R7, 0x0LL),
1911 BPF_LD_IMM64(R8, 0x0LL),
1912 BPF_LD_IMM64(R9, 0x0LL),
1913 BPF_ALU64_REG(BPF_ADD, R0, R0),
1914 BPF_ALU64_REG(BPF_ADD, R0, R1),
1915 BPF_ALU64_REG(BPF_ADD, R0, R2),
1916 BPF_ALU64_REG(BPF_ADD, R0, R3),
1917 BPF_ALU64_REG(BPF_ADD, R0, R4),
1918 BPF_ALU64_REG(BPF_ADD, R0, R5),
1919 BPF_ALU64_REG(BPF_ADD, R0, R6),
1920 BPF_ALU64_REG(BPF_ADD, R0, R7),
1921 BPF_ALU64_REG(BPF_ADD, R0, R8),
1922 BPF_ALU64_REG(BPF_ADD, R0, R9),
1923 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1924 BPF_EXIT_INSN(),
1926 INTERNAL,
1927 { },
1928 { { 0, 0xfefe } }
1931 "INT: ALU MIX",
1932 .u.insns_int = {
1933 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1934 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1935 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1936 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1937 BPF_ALU64_REG(BPF_DIV, R0, R2),
1938 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1939 BPF_EXIT_INSN(),
1940 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1941 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1942 BPF_EXIT_INSN(),
1943 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1944 BPF_EXIT_INSN(),
1946 INTERNAL,
1947 { },
1948 { { 0, -1 } }
1951 "INT: shifts by register",
1952 .u.insns_int = {
1953 BPF_MOV64_IMM(R0, -1234),
1954 BPF_MOV64_IMM(R1, 1),
1955 BPF_ALU32_REG(BPF_RSH, R0, R1),
1956 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1957 BPF_EXIT_INSN(),
1958 BPF_MOV64_IMM(R2, 1),
1959 BPF_ALU64_REG(BPF_LSH, R0, R2),
1960 BPF_MOV32_IMM(R4, -1234),
1961 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1962 BPF_EXIT_INSN(),
1963 BPF_ALU64_IMM(BPF_AND, R4, 63),
1964 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1965 BPF_MOV64_IMM(R3, 47),
1966 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1967 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1968 BPF_EXIT_INSN(),
1969 BPF_MOV64_IMM(R2, 1),
1970 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1971 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1972 BPF_EXIT_INSN(),
1973 BPF_MOV64_IMM(R4, 4),
1974 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1975 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1976 BPF_EXIT_INSN(),
1977 BPF_MOV64_IMM(R4, 5),
1978 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1979 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1980 BPF_EXIT_INSN(),
1981 BPF_MOV64_IMM(R0, -1),
1982 BPF_EXIT_INSN(),
1984 INTERNAL,
1985 { },
1986 { { 0, -1 } }
1989 "INT: DIV + ABS",
1990 .u.insns_int = {
1991 BPF_ALU64_REG(BPF_MOV, R6, R1),
1992 BPF_LD_ABS(BPF_B, 3),
1993 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1994 BPF_ALU32_REG(BPF_DIV, R0, R2),
1995 BPF_ALU64_REG(BPF_MOV, R8, R0),
1996 BPF_LD_ABS(BPF_B, 4),
1997 BPF_ALU64_REG(BPF_ADD, R8, R0),
1998 BPF_LD_IND(BPF_B, R8, -70),
1999 BPF_EXIT_INSN(),
2001 INTERNAL,
2002 { 10, 20, 30, 40, 50 },
2003 { { 4, 0 }, { 5, 10 } }
2006 "INT: DIV by zero",
2007 .u.insns_int = {
2008 BPF_ALU64_REG(BPF_MOV, R6, R1),
2009 BPF_ALU64_IMM(BPF_MOV, R7, 0),
2010 BPF_LD_ABS(BPF_B, 3),
2011 BPF_ALU32_REG(BPF_DIV, R0, R7),
2012 BPF_EXIT_INSN(),
2014 INTERNAL,
2015 { 10, 20, 30, 40, 50 },
2016 { { 3, 0 }, { 4, 0 } }
2019 "check: missing ret",
2020 .u.insns = {
2021 BPF_STMT(BPF_LD | BPF_IMM, 1),
2023 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2024 { },
2028 "check: div_k_0",
2029 .u.insns = {
2030 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
2031 BPF_STMT(BPF_RET | BPF_K, 0)
2033 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2034 { },
2038 "check: unknown insn",
2039 .u.insns = {
2040 /* seccomp insn, rejected in socket filter */
2041 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
2042 BPF_STMT(BPF_RET | BPF_K, 0)
2044 CLASSIC | FLAG_EXPECTED_FAIL,
2045 { },
2049 "check: out of range spill/fill",
2050 .u.insns = {
2051 BPF_STMT(BPF_STX, 16),
2052 BPF_STMT(BPF_RET | BPF_K, 0)
2054 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2055 { },
2059 "JUMPS + HOLES",
2060 .u.insns = {
2061 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2062 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
2063 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2064 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2065 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2066 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2067 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2068 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2069 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2070 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2071 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2072 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2073 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2074 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2075 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2076 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
2077 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2078 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
2079 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2080 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2081 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2082 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2083 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2084 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2085 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2086 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2087 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2088 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2089 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2090 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2091 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2092 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2093 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2094 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2095 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2096 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2097 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2098 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2099 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2100 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2101 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2102 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2103 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2104 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2105 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2106 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2107 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2108 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2109 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2110 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2111 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2112 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2113 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2114 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2115 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2116 BPF_STMT(BPF_RET | BPF_A, 0),
2117 BPF_STMT(BPF_RET | BPF_A, 0),
2119 CLASSIC,
2120 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2121 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2122 0x08, 0x00,
2123 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2124 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2125 0xc0, 0xa8, 0x33, 0x01,
2126 0xc0, 0xa8, 0x33, 0x02,
2127 0xbb, 0xb6,
2128 0xa9, 0xfa,
2129 0x00, 0x14, 0x00, 0x00,
2130 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2131 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2132 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2133 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2134 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2135 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2136 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2137 0xcc, 0xcc, 0xcc, 0xcc },
2138 { { 88, 0x001b } }
2141 "check: RET X",
2142 .u.insns = {
2143 BPF_STMT(BPF_RET | BPF_X, 0),
2145 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2146 { },
2147 { },
2150 "check: LDX + RET X",
2151 .u.insns = {
2152 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2153 BPF_STMT(BPF_RET | BPF_X, 0),
2155 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2156 { },
2157 { },
2159 { /* Mainly checking JIT here. */
2160 "M[]: alt STX + LDX",
2161 .u.insns = {
2162 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2163 BPF_STMT(BPF_STX, 0),
2164 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2165 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2166 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2167 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2168 BPF_STMT(BPF_STX, 1),
2169 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2170 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2171 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2172 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2173 BPF_STMT(BPF_STX, 2),
2174 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2175 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2176 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2177 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2178 BPF_STMT(BPF_STX, 3),
2179 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2180 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2181 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2182 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2183 BPF_STMT(BPF_STX, 4),
2184 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2185 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2186 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2187 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2188 BPF_STMT(BPF_STX, 5),
2189 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2190 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2191 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2192 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2193 BPF_STMT(BPF_STX, 6),
2194 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2195 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2196 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2197 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2198 BPF_STMT(BPF_STX, 7),
2199 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2200 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2201 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2202 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2203 BPF_STMT(BPF_STX, 8),
2204 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2205 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2207 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2208 BPF_STMT(BPF_STX, 9),
2209 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2210 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2211 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2212 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2213 BPF_STMT(BPF_STX, 10),
2214 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2215 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2216 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2217 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2218 BPF_STMT(BPF_STX, 11),
2219 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2220 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2221 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2222 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2223 BPF_STMT(BPF_STX, 12),
2224 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2225 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2227 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2228 BPF_STMT(BPF_STX, 13),
2229 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2230 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2231 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2232 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2233 BPF_STMT(BPF_STX, 14),
2234 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2235 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2236 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2237 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2238 BPF_STMT(BPF_STX, 15),
2239 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2240 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2241 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2242 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2243 BPF_STMT(BPF_RET | BPF_A, 0),
2245 CLASSIC | FLAG_NO_DATA,
2246 { },
2247 { { 0, 116 } },
2249 { /* Mainly checking JIT here. */
2250 "M[]: full STX + full LDX",
2251 .u.insns = {
2252 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2253 BPF_STMT(BPF_STX, 0),
2254 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2255 BPF_STMT(BPF_STX, 1),
2256 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2257 BPF_STMT(BPF_STX, 2),
2258 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2259 BPF_STMT(BPF_STX, 3),
2260 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2261 BPF_STMT(BPF_STX, 4),
2262 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2263 BPF_STMT(BPF_STX, 5),
2264 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2265 BPF_STMT(BPF_STX, 6),
2266 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2267 BPF_STMT(BPF_STX, 7),
2268 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2269 BPF_STMT(BPF_STX, 8),
2270 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2271 BPF_STMT(BPF_STX, 9),
2272 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2273 BPF_STMT(BPF_STX, 10),
2274 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2275 BPF_STMT(BPF_STX, 11),
2276 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2277 BPF_STMT(BPF_STX, 12),
2278 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2279 BPF_STMT(BPF_STX, 13),
2280 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2281 BPF_STMT(BPF_STX, 14),
2282 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2283 BPF_STMT(BPF_STX, 15),
2284 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2285 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2286 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2287 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2288 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2289 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2290 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2291 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2292 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2293 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2294 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2295 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2296 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2297 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2298 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2299 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2300 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2301 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2302 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2303 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2304 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2305 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2306 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2307 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2308 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2309 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2310 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2311 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2312 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2313 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2314 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2315 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2316 BPF_STMT(BPF_RET | BPF_A, 0),
2318 CLASSIC | FLAG_NO_DATA,
2319 { },
2320 { { 0, 0x2a5a5e5 } },
2323 "check: SKF_AD_MAX",
2324 .u.insns = {
2325 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2326 SKF_AD_OFF + SKF_AD_MAX),
2327 BPF_STMT(BPF_RET | BPF_A, 0),
2329 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2330 { },
2331 { },
2333 { /* Passes checker but fails during runtime. */
2334 "LD [SKF_AD_OFF-1]",
2335 .u.insns = {
2336 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2337 SKF_AD_OFF - 1),
2338 BPF_STMT(BPF_RET | BPF_K, 1),
2340 CLASSIC,
2341 { },
2342 { { 1, 0 } },
2345 "load 64-bit immediate",
2346 .u.insns_int = {
2347 BPF_LD_IMM64(R1, 0x567800001234LL),
2348 BPF_MOV64_REG(R2, R1),
2349 BPF_MOV64_REG(R3, R2),
2350 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2351 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2352 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2353 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2354 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2355 BPF_EXIT_INSN(),
2356 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2357 BPF_EXIT_INSN(),
2358 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2359 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2360 BPF_EXIT_INSN(),
2362 INTERNAL,
2363 { },
2364 { { 0, 1 } }
2367 "nmap reduced",
2368 .u.insns_int = {
2369 BPF_MOV64_REG(R6, R1),
2370 BPF_LD_ABS(BPF_H, 12),
2371 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2372 BPF_LD_ABS(BPF_H, 12),
2373 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2374 BPF_MOV32_IMM(R0, 18),
2375 BPF_STX_MEM(BPF_W, R10, R0, -64),
2376 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2377 BPF_LD_IND(BPF_W, R7, 14),
2378 BPF_STX_MEM(BPF_W, R10, R0, -60),
2379 BPF_MOV32_IMM(R0, 280971478),
2380 BPF_STX_MEM(BPF_W, R10, R0, -56),
2381 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2382 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2383 BPF_ALU32_REG(BPF_SUB, R0, R7),
2384 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2385 BPF_LD_ABS(BPF_H, 12),
2386 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2387 BPF_MOV32_IMM(R0, 22),
2388 BPF_STX_MEM(BPF_W, R10, R0, -56),
2389 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2390 BPF_LD_IND(BPF_H, R7, 14),
2391 BPF_STX_MEM(BPF_W, R10, R0, -52),
2392 BPF_MOV32_IMM(R0, 17366),
2393 BPF_STX_MEM(BPF_W, R10, R0, -48),
2394 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2395 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2396 BPF_ALU32_REG(BPF_SUB, R0, R7),
2397 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2398 BPF_MOV32_IMM(R0, 256),
2399 BPF_EXIT_INSN(),
2400 BPF_MOV32_IMM(R0, 0),
2401 BPF_EXIT_INSN(),
2403 INTERNAL,
2404 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2405 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2406 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2407 { { 38, 256 } },
2408 .stack_depth = 64,
2410 /* BPF_ALU | BPF_MOV | BPF_X */
2412 "ALU_MOV_X: dst = 2",
2413 .u.insns_int = {
2414 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2415 BPF_ALU32_REG(BPF_MOV, R0, R1),
2416 BPF_EXIT_INSN(),
2418 INTERNAL,
2419 { },
2420 { { 0, 2 } },
2423 "ALU_MOV_X: dst = 4294967295",
2424 .u.insns_int = {
2425 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2426 BPF_ALU32_REG(BPF_MOV, R0, R1),
2427 BPF_EXIT_INSN(),
2429 INTERNAL,
2430 { },
2431 { { 0, 4294967295U } },
2434 "ALU64_MOV_X: dst = 2",
2435 .u.insns_int = {
2436 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2437 BPF_ALU64_REG(BPF_MOV, R0, R1),
2438 BPF_EXIT_INSN(),
2440 INTERNAL,
2441 { },
2442 { { 0, 2 } },
2445 "ALU64_MOV_X: dst = 4294967295",
2446 .u.insns_int = {
2447 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2448 BPF_ALU64_REG(BPF_MOV, R0, R1),
2449 BPF_EXIT_INSN(),
2451 INTERNAL,
2452 { },
2453 { { 0, 4294967295U } },
2455 /* BPF_ALU | BPF_MOV | BPF_K */
2457 "ALU_MOV_K: dst = 2",
2458 .u.insns_int = {
2459 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2460 BPF_EXIT_INSN(),
2462 INTERNAL,
2463 { },
2464 { { 0, 2 } },
2467 "ALU_MOV_K: dst = 4294967295",
2468 .u.insns_int = {
2469 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2470 BPF_EXIT_INSN(),
2472 INTERNAL,
2473 { },
2474 { { 0, 4294967295U } },
2477 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2478 .u.insns_int = {
2479 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2480 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2481 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2482 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2483 BPF_MOV32_IMM(R0, 2),
2484 BPF_EXIT_INSN(),
2485 BPF_MOV32_IMM(R0, 1),
2486 BPF_EXIT_INSN(),
2488 INTERNAL,
2489 { },
2490 { { 0, 0x1 } },
2493 "ALU64_MOV_K: dst = 2",
2494 .u.insns_int = {
2495 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2496 BPF_EXIT_INSN(),
2498 INTERNAL,
2499 { },
2500 { { 0, 2 } },
2503 "ALU64_MOV_K: dst = 2147483647",
2504 .u.insns_int = {
2505 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2506 BPF_EXIT_INSN(),
2508 INTERNAL,
2509 { },
2510 { { 0, 2147483647 } },
2513 "ALU64_OR_K: dst = 0x0",
2514 .u.insns_int = {
2515 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2516 BPF_LD_IMM64(R3, 0x0),
2517 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2518 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2519 BPF_MOV32_IMM(R0, 2),
2520 BPF_EXIT_INSN(),
2521 BPF_MOV32_IMM(R0, 1),
2522 BPF_EXIT_INSN(),
2524 INTERNAL,
2525 { },
2526 { { 0, 0x1 } },
2529 "ALU64_MOV_K: dst = -1",
2530 .u.insns_int = {
2531 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2532 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2533 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2534 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2535 BPF_MOV32_IMM(R0, 2),
2536 BPF_EXIT_INSN(),
2537 BPF_MOV32_IMM(R0, 1),
2538 BPF_EXIT_INSN(),
2540 INTERNAL,
2541 { },
2542 { { 0, 0x1 } },
2544 /* BPF_ALU | BPF_ADD | BPF_X */
2546 "ALU_ADD_X: 1 + 2 = 3",
2547 .u.insns_int = {
2548 BPF_LD_IMM64(R0, 1),
2549 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2550 BPF_ALU32_REG(BPF_ADD, R0, R1),
2551 BPF_EXIT_INSN(),
2553 INTERNAL,
2554 { },
2555 { { 0, 3 } },
2558 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2559 .u.insns_int = {
2560 BPF_LD_IMM64(R0, 1),
2561 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2562 BPF_ALU32_REG(BPF_ADD, R0, R1),
2563 BPF_EXIT_INSN(),
2565 INTERNAL,
2566 { },
2567 { { 0, 4294967295U } },
2570 "ALU_ADD_X: 2 + 4294967294 = 0",
2571 .u.insns_int = {
2572 BPF_LD_IMM64(R0, 2),
2573 BPF_LD_IMM64(R1, 4294967294U),
2574 BPF_ALU32_REG(BPF_ADD, R0, R1),
2575 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2576 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2577 BPF_EXIT_INSN(),
2578 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2579 BPF_EXIT_INSN(),
2581 INTERNAL,
2582 { },
2583 { { 0, 1 } },
2586 "ALU64_ADD_X: 1 + 2 = 3",
2587 .u.insns_int = {
2588 BPF_LD_IMM64(R0, 1),
2589 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2590 BPF_ALU64_REG(BPF_ADD, R0, R1),
2591 BPF_EXIT_INSN(),
2593 INTERNAL,
2594 { },
2595 { { 0, 3 } },
2598 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2599 .u.insns_int = {
2600 BPF_LD_IMM64(R0, 1),
2601 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2602 BPF_ALU64_REG(BPF_ADD, R0, R1),
2603 BPF_EXIT_INSN(),
2605 INTERNAL,
2606 { },
2607 { { 0, 4294967295U } },
2610 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2611 .u.insns_int = {
2612 BPF_LD_IMM64(R0, 2),
2613 BPF_LD_IMM64(R1, 4294967294U),
2614 BPF_LD_IMM64(R2, 4294967296ULL),
2615 BPF_ALU64_REG(BPF_ADD, R0, R1),
2616 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2617 BPF_MOV32_IMM(R0, 0),
2618 BPF_EXIT_INSN(),
2619 BPF_MOV32_IMM(R0, 1),
2620 BPF_EXIT_INSN(),
2622 INTERNAL,
2623 { },
2624 { { 0, 1 } },
2626 /* BPF_ALU | BPF_ADD | BPF_K */
2628 "ALU_ADD_K: 1 + 2 = 3",
2629 .u.insns_int = {
2630 BPF_LD_IMM64(R0, 1),
2631 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2632 BPF_EXIT_INSN(),
2634 INTERNAL,
2635 { },
2636 { { 0, 3 } },
2639 "ALU_ADD_K: 3 + 0 = 3",
2640 .u.insns_int = {
2641 BPF_LD_IMM64(R0, 3),
2642 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2643 BPF_EXIT_INSN(),
2645 INTERNAL,
2646 { },
2647 { { 0, 3 } },
2650 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2651 .u.insns_int = {
2652 BPF_LD_IMM64(R0, 1),
2653 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2654 BPF_EXIT_INSN(),
2656 INTERNAL,
2657 { },
2658 { { 0, 4294967295U } },
2661 "ALU_ADD_K: 4294967294 + 2 = 0",
2662 .u.insns_int = {
2663 BPF_LD_IMM64(R0, 4294967294U),
2664 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2665 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2667 BPF_EXIT_INSN(),
2668 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2669 BPF_EXIT_INSN(),
2671 INTERNAL,
2672 { },
2673 { { 0, 1 } },
2676 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2677 .u.insns_int = {
2678 BPF_LD_IMM64(R2, 0x0),
2679 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2680 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2681 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2682 BPF_MOV32_IMM(R0, 2),
2683 BPF_EXIT_INSN(),
2684 BPF_MOV32_IMM(R0, 1),
2685 BPF_EXIT_INSN(),
2687 INTERNAL,
2688 { },
2689 { { 0, 0x1 } },
2692 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2693 .u.insns_int = {
2694 BPF_LD_IMM64(R2, 0x0),
2695 BPF_LD_IMM64(R3, 0xffff),
2696 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2697 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2698 BPF_MOV32_IMM(R0, 2),
2699 BPF_EXIT_INSN(),
2700 BPF_MOV32_IMM(R0, 1),
2701 BPF_EXIT_INSN(),
2703 INTERNAL,
2704 { },
2705 { { 0, 0x1 } },
2708 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2709 .u.insns_int = {
2710 BPF_LD_IMM64(R2, 0x0),
2711 BPF_LD_IMM64(R3, 0x7fffffff),
2712 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2713 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2714 BPF_MOV32_IMM(R0, 2),
2715 BPF_EXIT_INSN(),
2716 BPF_MOV32_IMM(R0, 1),
2717 BPF_EXIT_INSN(),
2719 INTERNAL,
2720 { },
2721 { { 0, 0x1 } },
2724 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2725 .u.insns_int = {
2726 BPF_LD_IMM64(R2, 0x0),
2727 BPF_LD_IMM64(R3, 0x80000000),
2728 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2729 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2730 BPF_MOV32_IMM(R0, 2),
2731 BPF_EXIT_INSN(),
2732 BPF_MOV32_IMM(R0, 1),
2733 BPF_EXIT_INSN(),
2735 INTERNAL,
2736 { },
2737 { { 0, 0x1 } },
2740 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2741 .u.insns_int = {
2742 BPF_LD_IMM64(R2, 0x0),
2743 BPF_LD_IMM64(R3, 0x80008000),
2744 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2745 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2746 BPF_MOV32_IMM(R0, 2),
2747 BPF_EXIT_INSN(),
2748 BPF_MOV32_IMM(R0, 1),
2749 BPF_EXIT_INSN(),
2751 INTERNAL,
2752 { },
2753 { { 0, 0x1 } },
2756 "ALU64_ADD_K: 1 + 2 = 3",
2757 .u.insns_int = {
2758 BPF_LD_IMM64(R0, 1),
2759 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2760 BPF_EXIT_INSN(),
2762 INTERNAL,
2763 { },
2764 { { 0, 3 } },
2767 "ALU64_ADD_K: 3 + 0 = 3",
2768 .u.insns_int = {
2769 BPF_LD_IMM64(R0, 3),
2770 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2771 BPF_EXIT_INSN(),
2773 INTERNAL,
2774 { },
2775 { { 0, 3 } },
2778 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2779 .u.insns_int = {
2780 BPF_LD_IMM64(R0, 1),
2781 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2782 BPF_EXIT_INSN(),
2784 INTERNAL,
2785 { },
2786 { { 0, 2147483647 } },
2789 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2790 .u.insns_int = {
2791 BPF_LD_IMM64(R0, 4294967294U),
2792 BPF_LD_IMM64(R1, 4294967296ULL),
2793 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2794 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2795 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2796 BPF_EXIT_INSN(),
2797 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2798 BPF_EXIT_INSN(),
2800 INTERNAL,
2801 { },
2802 { { 0, 1 } },
2805 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2806 .u.insns_int = {
2807 BPF_LD_IMM64(R0, 2147483646),
2808 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2809 BPF_EXIT_INSN(),
2811 INTERNAL,
2812 { },
2813 { { 0, -1 } },
2816 "ALU64_ADD_K: 1 + 0 = 1",
2817 .u.insns_int = {
2818 BPF_LD_IMM64(R2, 0x1),
2819 BPF_LD_IMM64(R3, 0x1),
2820 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2821 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2822 BPF_MOV32_IMM(R0, 2),
2823 BPF_EXIT_INSN(),
2824 BPF_MOV32_IMM(R0, 1),
2825 BPF_EXIT_INSN(),
2827 INTERNAL,
2828 { },
2829 { { 0, 0x1 } },
2832 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2833 .u.insns_int = {
2834 BPF_LD_IMM64(R2, 0x0),
2835 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2836 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2837 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2838 BPF_MOV32_IMM(R0, 2),
2839 BPF_EXIT_INSN(),
2840 BPF_MOV32_IMM(R0, 1),
2841 BPF_EXIT_INSN(),
2843 INTERNAL,
2844 { },
2845 { { 0, 0x1 } },
2848 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2849 .u.insns_int = {
2850 BPF_LD_IMM64(R2, 0x0),
2851 BPF_LD_IMM64(R3, 0xffff),
2852 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2853 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2854 BPF_MOV32_IMM(R0, 2),
2855 BPF_EXIT_INSN(),
2856 BPF_MOV32_IMM(R0, 1),
2857 BPF_EXIT_INSN(),
2859 INTERNAL,
2860 { },
2861 { { 0, 0x1 } },
2864 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2865 .u.insns_int = {
2866 BPF_LD_IMM64(R2, 0x0),
2867 BPF_LD_IMM64(R3, 0x7fffffff),
2868 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2869 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2870 BPF_MOV32_IMM(R0, 2),
2871 BPF_EXIT_INSN(),
2872 BPF_MOV32_IMM(R0, 1),
2873 BPF_EXIT_INSN(),
2875 INTERNAL,
2876 { },
2877 { { 0, 0x1 } },
2880 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2881 .u.insns_int = {
2882 BPF_LD_IMM64(R2, 0x0),
2883 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2884 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2885 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2886 BPF_MOV32_IMM(R0, 2),
2887 BPF_EXIT_INSN(),
2888 BPF_MOV32_IMM(R0, 1),
2889 BPF_EXIT_INSN(),
2891 INTERNAL,
2892 { },
2893 { { 0, 0x1 } },
2896 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2897 .u.insns_int = {
2898 BPF_LD_IMM64(R2, 0x0),
2899 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2900 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2901 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2902 BPF_MOV32_IMM(R0, 2),
2903 BPF_EXIT_INSN(),
2904 BPF_MOV32_IMM(R0, 1),
2905 BPF_EXIT_INSN(),
2907 INTERNAL,
2908 { },
2909 { { 0, 0x1 } },
2911 /* BPF_ALU | BPF_SUB | BPF_X */
2913 "ALU_SUB_X: 3 - 1 = 2",
2914 .u.insns_int = {
2915 BPF_LD_IMM64(R0, 3),
2916 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2917 BPF_ALU32_REG(BPF_SUB, R0, R1),
2918 BPF_EXIT_INSN(),
2920 INTERNAL,
2921 { },
2922 { { 0, 2 } },
2925 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2926 .u.insns_int = {
2927 BPF_LD_IMM64(R0, 4294967295U),
2928 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2929 BPF_ALU32_REG(BPF_SUB, R0, R1),
2930 BPF_EXIT_INSN(),
2932 INTERNAL,
2933 { },
2934 { { 0, 1 } },
2937 "ALU64_SUB_X: 3 - 1 = 2",
2938 .u.insns_int = {
2939 BPF_LD_IMM64(R0, 3),
2940 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2941 BPF_ALU64_REG(BPF_SUB, R0, R1),
2942 BPF_EXIT_INSN(),
2944 INTERNAL,
2945 { },
2946 { { 0, 2 } },
2949 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2950 .u.insns_int = {
2951 BPF_LD_IMM64(R0, 4294967295U),
2952 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2953 BPF_ALU64_REG(BPF_SUB, R0, R1),
2954 BPF_EXIT_INSN(),
2956 INTERNAL,
2957 { },
2958 { { 0, 1 } },
2960 /* BPF_ALU | BPF_SUB | BPF_K */
2962 "ALU_SUB_K: 3 - 1 = 2",
2963 .u.insns_int = {
2964 BPF_LD_IMM64(R0, 3),
2965 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2966 BPF_EXIT_INSN(),
2968 INTERNAL,
2969 { },
2970 { { 0, 2 } },
2973 "ALU_SUB_K: 3 - 0 = 3",
2974 .u.insns_int = {
2975 BPF_LD_IMM64(R0, 3),
2976 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2977 BPF_EXIT_INSN(),
2979 INTERNAL,
2980 { },
2981 { { 0, 3 } },
2984 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2985 .u.insns_int = {
2986 BPF_LD_IMM64(R0, 4294967295U),
2987 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
2988 BPF_EXIT_INSN(),
2990 INTERNAL,
2991 { },
2992 { { 0, 1 } },
2995 "ALU64_SUB_K: 3 - 1 = 2",
2996 .u.insns_int = {
2997 BPF_LD_IMM64(R0, 3),
2998 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2999 BPF_EXIT_INSN(),
3001 INTERNAL,
3002 { },
3003 { { 0, 2 } },
3006 "ALU64_SUB_K: 3 - 0 = 3",
3007 .u.insns_int = {
3008 BPF_LD_IMM64(R0, 3),
3009 BPF_ALU64_IMM(BPF_SUB, R0, 0),
3010 BPF_EXIT_INSN(),
3012 INTERNAL,
3013 { },
3014 { { 0, 3 } },
3017 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3018 .u.insns_int = {
3019 BPF_LD_IMM64(R0, 4294967294U),
3020 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
3021 BPF_EXIT_INSN(),
3023 INTERNAL,
3024 { },
3025 { { 0, -1 } },
3028 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3029 .u.insns_int = {
3030 BPF_LD_IMM64(R0, 2147483646),
3031 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
3032 BPF_EXIT_INSN(),
3034 INTERNAL,
3035 { },
3036 { { 0, -1 } },
3038 /* BPF_ALU | BPF_MUL | BPF_X */
3040 "ALU_MUL_X: 2 * 3 = 6",
3041 .u.insns_int = {
3042 BPF_LD_IMM64(R0, 2),
3043 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3044 BPF_ALU32_REG(BPF_MUL, R0, R1),
3045 BPF_EXIT_INSN(),
3047 INTERNAL,
3048 { },
3049 { { 0, 6 } },
3052 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3053 .u.insns_int = {
3054 BPF_LD_IMM64(R0, 2),
3055 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
3056 BPF_ALU32_REG(BPF_MUL, R0, R1),
3057 BPF_EXIT_INSN(),
3059 INTERNAL,
3060 { },
3061 { { 0, 0xFFFFFFF0 } },
3064 "ALU_MUL_X: -1 * -1 = 1",
3065 .u.insns_int = {
3066 BPF_LD_IMM64(R0, -1),
3067 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3068 BPF_ALU32_REG(BPF_MUL, R0, R1),
3069 BPF_EXIT_INSN(),
3071 INTERNAL,
3072 { },
3073 { { 0, 1 } },
3076 "ALU64_MUL_X: 2 * 3 = 6",
3077 .u.insns_int = {
3078 BPF_LD_IMM64(R0, 2),
3079 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3080 BPF_ALU64_REG(BPF_MUL, R0, R1),
3081 BPF_EXIT_INSN(),
3083 INTERNAL,
3084 { },
3085 { { 0, 6 } },
3088 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3089 .u.insns_int = {
3090 BPF_LD_IMM64(R0, 1),
3091 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3092 BPF_ALU64_REG(BPF_MUL, R0, R1),
3093 BPF_EXIT_INSN(),
3095 INTERNAL,
3096 { },
3097 { { 0, 2147483647 } },
3099 /* BPF_ALU | BPF_MUL | BPF_K */
3101 "ALU_MUL_K: 2 * 3 = 6",
3102 .u.insns_int = {
3103 BPF_LD_IMM64(R0, 2),
3104 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3105 BPF_EXIT_INSN(),
3107 INTERNAL,
3108 { },
3109 { { 0, 6 } },
3112 "ALU_MUL_K: 3 * 1 = 3",
3113 .u.insns_int = {
3114 BPF_LD_IMM64(R0, 3),
3115 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3116 BPF_EXIT_INSN(),
3118 INTERNAL,
3119 { },
3120 { { 0, 3 } },
3123 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3124 .u.insns_int = {
3125 BPF_LD_IMM64(R0, 2),
3126 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3127 BPF_EXIT_INSN(),
3129 INTERNAL,
3130 { },
3131 { { 0, 0xFFFFFFF0 } },
3134 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3135 .u.insns_int = {
3136 BPF_LD_IMM64(R2, 0x1),
3137 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3138 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3139 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3140 BPF_MOV32_IMM(R0, 2),
3141 BPF_EXIT_INSN(),
3142 BPF_MOV32_IMM(R0, 1),
3143 BPF_EXIT_INSN(),
3145 INTERNAL,
3146 { },
3147 { { 0, 0x1 } },
3150 "ALU64_MUL_K: 2 * 3 = 6",
3151 .u.insns_int = {
3152 BPF_LD_IMM64(R0, 2),
3153 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3154 BPF_EXIT_INSN(),
3156 INTERNAL,
3157 { },
3158 { { 0, 6 } },
3161 "ALU64_MUL_K: 3 * 1 = 3",
3162 .u.insns_int = {
3163 BPF_LD_IMM64(R0, 3),
3164 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3165 BPF_EXIT_INSN(),
3167 INTERNAL,
3168 { },
3169 { { 0, 3 } },
3172 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3173 .u.insns_int = {
3174 BPF_LD_IMM64(R0, 1),
3175 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3176 BPF_EXIT_INSN(),
3178 INTERNAL,
3179 { },
3180 { { 0, 2147483647 } },
3183 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3184 .u.insns_int = {
3185 BPF_LD_IMM64(R0, 1),
3186 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3187 BPF_EXIT_INSN(),
3189 INTERNAL,
3190 { },
3191 { { 0, -2147483647 } },
3194 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3195 .u.insns_int = {
3196 BPF_LD_IMM64(R2, 0x1),
3197 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3198 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3199 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3200 BPF_MOV32_IMM(R0, 2),
3201 BPF_EXIT_INSN(),
3202 BPF_MOV32_IMM(R0, 1),
3203 BPF_EXIT_INSN(),
3205 INTERNAL,
3206 { },
3207 { { 0, 0x1 } },
3209 /* BPF_ALU | BPF_DIV | BPF_X */
3211 "ALU_DIV_X: 6 / 2 = 3",
3212 .u.insns_int = {
3213 BPF_LD_IMM64(R0, 6),
3214 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3215 BPF_ALU32_REG(BPF_DIV, R0, R1),
3216 BPF_EXIT_INSN(),
3218 INTERNAL,
3219 { },
3220 { { 0, 3 } },
3223 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3224 .u.insns_int = {
3225 BPF_LD_IMM64(R0, 4294967295U),
3226 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
3227 BPF_ALU32_REG(BPF_DIV, R0, R1),
3228 BPF_EXIT_INSN(),
3230 INTERNAL,
3231 { },
3232 { { 0, 1 } },
3235 "ALU64_DIV_X: 6 / 2 = 3",
3236 .u.insns_int = {
3237 BPF_LD_IMM64(R0, 6),
3238 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3239 BPF_ALU64_REG(BPF_DIV, R0, R1),
3240 BPF_EXIT_INSN(),
3242 INTERNAL,
3243 { },
3244 { { 0, 3 } },
3247 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3248 .u.insns_int = {
3249 BPF_LD_IMM64(R0, 2147483647),
3250 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3251 BPF_ALU64_REG(BPF_DIV, R0, R1),
3252 BPF_EXIT_INSN(),
3254 INTERNAL,
3255 { },
3256 { { 0, 1 } },
3259 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3260 .u.insns_int = {
3261 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3262 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3263 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3264 BPF_ALU64_REG(BPF_DIV, R2, R4),
3265 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3266 BPF_MOV32_IMM(R0, 2),
3267 BPF_EXIT_INSN(),
3268 BPF_MOV32_IMM(R0, 1),
3269 BPF_EXIT_INSN(),
3271 INTERNAL,
3272 { },
3273 { { 0, 0x1 } },
3275 /* BPF_ALU | BPF_DIV | BPF_K */
3277 "ALU_DIV_K: 6 / 2 = 3",
3278 .u.insns_int = {
3279 BPF_LD_IMM64(R0, 6),
3280 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3281 BPF_EXIT_INSN(),
3283 INTERNAL,
3284 { },
3285 { { 0, 3 } },
3288 "ALU_DIV_K: 3 / 1 = 3",
3289 .u.insns_int = {
3290 BPF_LD_IMM64(R0, 3),
3291 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3292 BPF_EXIT_INSN(),
3294 INTERNAL,
3295 { },
3296 { { 0, 3 } },
3299 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3300 .u.insns_int = {
3301 BPF_LD_IMM64(R0, 4294967295U),
3302 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
3303 BPF_EXIT_INSN(),
3305 INTERNAL,
3306 { },
3307 { { 0, 1 } },
3310 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3311 .u.insns_int = {
3312 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3313 BPF_LD_IMM64(R3, 0x1UL),
3314 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3315 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3316 BPF_MOV32_IMM(R0, 2),
3317 BPF_EXIT_INSN(),
3318 BPF_MOV32_IMM(R0, 1),
3319 BPF_EXIT_INSN(),
3321 INTERNAL,
3322 { },
3323 { { 0, 0x1 } },
3326 "ALU64_DIV_K: 6 / 2 = 3",
3327 .u.insns_int = {
3328 BPF_LD_IMM64(R0, 6),
3329 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3330 BPF_EXIT_INSN(),
3332 INTERNAL,
3333 { },
3334 { { 0, 3 } },
3337 "ALU64_DIV_K: 3 / 1 = 3",
3338 .u.insns_int = {
3339 BPF_LD_IMM64(R0, 3),
3340 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3341 BPF_EXIT_INSN(),
3343 INTERNAL,
3344 { },
3345 { { 0, 3 } },
3348 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3349 .u.insns_int = {
3350 BPF_LD_IMM64(R0, 2147483647),
3351 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3352 BPF_EXIT_INSN(),
3354 INTERNAL,
3355 { },
3356 { { 0, 1 } },
3359 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3360 .u.insns_int = {
3361 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3362 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3363 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3364 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3365 BPF_MOV32_IMM(R0, 2),
3366 BPF_EXIT_INSN(),
3367 BPF_MOV32_IMM(R0, 1),
3368 BPF_EXIT_INSN(),
3370 INTERNAL,
3371 { },
3372 { { 0, 0x1 } },
3374 /* BPF_ALU | BPF_MOD | BPF_X */
3376 "ALU_MOD_X: 3 % 2 = 1",
3377 .u.insns_int = {
3378 BPF_LD_IMM64(R0, 3),
3379 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3380 BPF_ALU32_REG(BPF_MOD, R0, R1),
3381 BPF_EXIT_INSN(),
3383 INTERNAL,
3384 { },
3385 { { 0, 1 } },
3388 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3389 .u.insns_int = {
3390 BPF_LD_IMM64(R0, 4294967295U),
3391 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
3392 BPF_ALU32_REG(BPF_MOD, R0, R1),
3393 BPF_EXIT_INSN(),
3395 INTERNAL,
3396 { },
3397 { { 0, 2 } },
3400 "ALU64_MOD_X: 3 % 2 = 1",
3401 .u.insns_int = {
3402 BPF_LD_IMM64(R0, 3),
3403 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3404 BPF_ALU64_REG(BPF_MOD, R0, R1),
3405 BPF_EXIT_INSN(),
3407 INTERNAL,
3408 { },
3409 { { 0, 1 } },
3412 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3413 .u.insns_int = {
3414 BPF_LD_IMM64(R0, 2147483647),
3415 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3416 BPF_ALU64_REG(BPF_MOD, R0, R1),
3417 BPF_EXIT_INSN(),
3419 INTERNAL,
3420 { },
3421 { { 0, 2 } },
3423 /* BPF_ALU | BPF_MOD | BPF_K */
3425 "ALU_MOD_K: 3 % 2 = 1",
3426 .u.insns_int = {
3427 BPF_LD_IMM64(R0, 3),
3428 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3429 BPF_EXIT_INSN(),
3431 INTERNAL,
3432 { },
3433 { { 0, 1 } },
3436 "ALU_MOD_K: 3 % 1 = 0",
3437 .u.insns_int = {
3438 BPF_LD_IMM64(R0, 3),
3439 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3440 BPF_EXIT_INSN(),
3442 INTERNAL,
3443 { },
3444 { { 0, 0 } },
3447 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3448 .u.insns_int = {
3449 BPF_LD_IMM64(R0, 4294967295U),
3450 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
3451 BPF_EXIT_INSN(),
3453 INTERNAL,
3454 { },
3455 { { 0, 2 } },
3458 "ALU64_MOD_K: 3 % 2 = 1",
3459 .u.insns_int = {
3460 BPF_LD_IMM64(R0, 3),
3461 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3462 BPF_EXIT_INSN(),
3464 INTERNAL,
3465 { },
3466 { { 0, 1 } },
3469 "ALU64_MOD_K: 3 % 1 = 0",
3470 .u.insns_int = {
3471 BPF_LD_IMM64(R0, 3),
3472 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3473 BPF_EXIT_INSN(),
3475 INTERNAL,
3476 { },
3477 { { 0, 0 } },
3480 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3481 .u.insns_int = {
3482 BPF_LD_IMM64(R0, 2147483647),
3483 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3484 BPF_EXIT_INSN(),
3486 INTERNAL,
3487 { },
3488 { { 0, 2 } },
3490 /* BPF_ALU | BPF_AND | BPF_X */
3492 "ALU_AND_X: 3 & 2 = 2",
3493 .u.insns_int = {
3494 BPF_LD_IMM64(R0, 3),
3495 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3496 BPF_ALU32_REG(BPF_AND, R0, R1),
3497 BPF_EXIT_INSN(),
3499 INTERNAL,
3500 { },
3501 { { 0, 2 } },
3504 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3505 .u.insns_int = {
3506 BPF_LD_IMM64(R0, 0xffffffff),
3507 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3508 BPF_ALU32_REG(BPF_AND, R0, R1),
3509 BPF_EXIT_INSN(),
3511 INTERNAL,
3512 { },
3513 { { 0, 0xffffffff } },
3516 "ALU64_AND_X: 3 & 2 = 2",
3517 .u.insns_int = {
3518 BPF_LD_IMM64(R0, 3),
3519 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3520 BPF_ALU64_REG(BPF_AND, R0, R1),
3521 BPF_EXIT_INSN(),
3523 INTERNAL,
3524 { },
3525 { { 0, 2 } },
3528 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3529 .u.insns_int = {
3530 BPF_LD_IMM64(R0, 0xffffffff),
3531 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3532 BPF_ALU64_REG(BPF_AND, R0, R1),
3533 BPF_EXIT_INSN(),
3535 INTERNAL,
3536 { },
3537 { { 0, 0xffffffff } },
3539 /* BPF_ALU | BPF_AND | BPF_K */
3541 "ALU_AND_K: 3 & 2 = 2",
3542 .u.insns_int = {
3543 BPF_LD_IMM64(R0, 3),
3544 BPF_ALU32_IMM(BPF_AND, R0, 2),
3545 BPF_EXIT_INSN(),
3547 INTERNAL,
3548 { },
3549 { { 0, 2 } },
3552 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3553 .u.insns_int = {
3554 BPF_LD_IMM64(R0, 0xffffffff),
3555 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3556 BPF_EXIT_INSN(),
3558 INTERNAL,
3559 { },
3560 { { 0, 0xffffffff } },
3563 "ALU64_AND_K: 3 & 2 = 2",
3564 .u.insns_int = {
3565 BPF_LD_IMM64(R0, 3),
3566 BPF_ALU64_IMM(BPF_AND, R0, 2),
3567 BPF_EXIT_INSN(),
3569 INTERNAL,
3570 { },
3571 { { 0, 2 } },
3574 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3575 .u.insns_int = {
3576 BPF_LD_IMM64(R0, 0xffffffff),
3577 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3578 BPF_EXIT_INSN(),
3580 INTERNAL,
3581 { },
3582 { { 0, 0xffffffff } },
3585 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3586 .u.insns_int = {
3587 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3588 BPF_LD_IMM64(R3, 0x0000000000000000LL),
3589 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3590 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3591 BPF_MOV32_IMM(R0, 2),
3592 BPF_EXIT_INSN(),
3593 BPF_MOV32_IMM(R0, 1),
3594 BPF_EXIT_INSN(),
3596 INTERNAL,
3597 { },
3598 { { 0, 0x1 } },
3601 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3602 .u.insns_int = {
3603 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3604 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3605 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3606 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3607 BPF_MOV32_IMM(R0, 2),
3608 BPF_EXIT_INSN(),
3609 BPF_MOV32_IMM(R0, 1),
3610 BPF_EXIT_INSN(),
3612 INTERNAL,
3613 { },
3614 { { 0, 0x1 } },
3617 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3618 .u.insns_int = {
3619 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3620 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3621 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3622 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3623 BPF_MOV32_IMM(R0, 2),
3624 BPF_EXIT_INSN(),
3625 BPF_MOV32_IMM(R0, 1),
3626 BPF_EXIT_INSN(),
3628 INTERNAL,
3629 { },
3630 { { 0, 0x1 } },
3632 /* BPF_ALU | BPF_OR | BPF_X */
3634 "ALU_OR_X: 1 | 2 = 3",
3635 .u.insns_int = {
3636 BPF_LD_IMM64(R0, 1),
3637 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3638 BPF_ALU32_REG(BPF_OR, R0, R1),
3639 BPF_EXIT_INSN(),
3641 INTERNAL,
3642 { },
3643 { { 0, 3 } },
3646 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3647 .u.insns_int = {
3648 BPF_LD_IMM64(R0, 0),
3649 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3650 BPF_ALU32_REG(BPF_OR, R0, R1),
3651 BPF_EXIT_INSN(),
3653 INTERNAL,
3654 { },
3655 { { 0, 0xffffffff } },
3658 "ALU64_OR_X: 1 | 2 = 3",
3659 .u.insns_int = {
3660 BPF_LD_IMM64(R0, 1),
3661 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3662 BPF_ALU64_REG(BPF_OR, R0, R1),
3663 BPF_EXIT_INSN(),
3665 INTERNAL,
3666 { },
3667 { { 0, 3 } },
3670 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3671 .u.insns_int = {
3672 BPF_LD_IMM64(R0, 0),
3673 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3674 BPF_ALU64_REG(BPF_OR, R0, R1),
3675 BPF_EXIT_INSN(),
3677 INTERNAL,
3678 { },
3679 { { 0, 0xffffffff } },
3681 /* BPF_ALU | BPF_OR | BPF_K */
3683 "ALU_OR_K: 1 | 2 = 3",
3684 .u.insns_int = {
3685 BPF_LD_IMM64(R0, 1),
3686 BPF_ALU32_IMM(BPF_OR, R0, 2),
3687 BPF_EXIT_INSN(),
3689 INTERNAL,
3690 { },
3691 { { 0, 3 } },
3694 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3695 .u.insns_int = {
3696 BPF_LD_IMM64(R0, 0),
3697 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3698 BPF_EXIT_INSN(),
3700 INTERNAL,
3701 { },
3702 { { 0, 0xffffffff } },
3705 "ALU64_OR_K: 1 | 2 = 3",
3706 .u.insns_int = {
3707 BPF_LD_IMM64(R0, 1),
3708 BPF_ALU64_IMM(BPF_OR, R0, 2),
3709 BPF_EXIT_INSN(),
3711 INTERNAL,
3712 { },
3713 { { 0, 3 } },
3716 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3717 .u.insns_int = {
3718 BPF_LD_IMM64(R0, 0),
3719 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3720 BPF_EXIT_INSN(),
3722 INTERNAL,
3723 { },
3724 { { 0, 0xffffffff } },
3727 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3728 .u.insns_int = {
3729 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3730 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3731 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3732 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3733 BPF_MOV32_IMM(R0, 2),
3734 BPF_EXIT_INSN(),
3735 BPF_MOV32_IMM(R0, 1),
3736 BPF_EXIT_INSN(),
3738 INTERNAL,
3739 { },
3740 { { 0, 0x1 } },
3743 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3744 .u.insns_int = {
3745 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3746 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3747 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3748 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3749 BPF_MOV32_IMM(R0, 2),
3750 BPF_EXIT_INSN(),
3751 BPF_MOV32_IMM(R0, 1),
3752 BPF_EXIT_INSN(),
3754 INTERNAL,
3755 { },
3756 { { 0, 0x1 } },
3759 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3760 .u.insns_int = {
3761 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3762 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3763 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3764 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3765 BPF_MOV32_IMM(R0, 2),
3766 BPF_EXIT_INSN(),
3767 BPF_MOV32_IMM(R0, 1),
3768 BPF_EXIT_INSN(),
3770 INTERNAL,
3771 { },
3772 { { 0, 0x1 } },
3774 /* BPF_ALU | BPF_XOR | BPF_X */
3776 "ALU_XOR_X: 5 ^ 6 = 3",
3777 .u.insns_int = {
3778 BPF_LD_IMM64(R0, 5),
3779 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3780 BPF_ALU32_REG(BPF_XOR, R0, R1),
3781 BPF_EXIT_INSN(),
3783 INTERNAL,
3784 { },
3785 { { 0, 3 } },
3788 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3789 .u.insns_int = {
3790 BPF_LD_IMM64(R0, 1),
3791 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3792 BPF_ALU32_REG(BPF_XOR, R0, R1),
3793 BPF_EXIT_INSN(),
3795 INTERNAL,
3796 { },
3797 { { 0, 0xfffffffe } },
3800 "ALU64_XOR_X: 5 ^ 6 = 3",
3801 .u.insns_int = {
3802 BPF_LD_IMM64(R0, 5),
3803 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3804 BPF_ALU64_REG(BPF_XOR, R0, R1),
3805 BPF_EXIT_INSN(),
3807 INTERNAL,
3808 { },
3809 { { 0, 3 } },
3812 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3813 .u.insns_int = {
3814 BPF_LD_IMM64(R0, 1),
3815 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3816 BPF_ALU64_REG(BPF_XOR, R0, R1),
3817 BPF_EXIT_INSN(),
3819 INTERNAL,
3820 { },
3821 { { 0, 0xfffffffe } },
3823 /* BPF_ALU | BPF_XOR | BPF_K */
3825 "ALU_XOR_K: 5 ^ 6 = 3",
3826 .u.insns_int = {
3827 BPF_LD_IMM64(R0, 5),
3828 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3829 BPF_EXIT_INSN(),
3831 INTERNAL,
3832 { },
3833 { { 0, 3 } },
3836 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3837 .u.insns_int = {
3838 BPF_LD_IMM64(R0, 1),
3839 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3840 BPF_EXIT_INSN(),
3842 INTERNAL,
3843 { },
3844 { { 0, 0xfffffffe } },
3847 "ALU64_XOR_K: 5 ^ 6 = 3",
3848 .u.insns_int = {
3849 BPF_LD_IMM64(R0, 5),
3850 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3851 BPF_EXIT_INSN(),
3853 INTERNAL,
3854 { },
3855 { { 0, 3 } },
3858 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3859 .u.insns_int = {
3860 BPF_LD_IMM64(R0, 1),
3861 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3862 BPF_EXIT_INSN(),
3864 INTERNAL,
3865 { },
3866 { { 0, 0xfffffffe } },
3869 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3870 .u.insns_int = {
3871 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3872 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3873 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3874 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3875 BPF_MOV32_IMM(R0, 2),
3876 BPF_EXIT_INSN(),
3877 BPF_MOV32_IMM(R0, 1),
3878 BPF_EXIT_INSN(),
3880 INTERNAL,
3881 { },
3882 { { 0, 0x1 } },
3885 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3886 .u.insns_int = {
3887 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3888 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
3889 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3890 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3891 BPF_MOV32_IMM(R0, 2),
3892 BPF_EXIT_INSN(),
3893 BPF_MOV32_IMM(R0, 1),
3894 BPF_EXIT_INSN(),
3896 INTERNAL,
3897 { },
3898 { { 0, 0x1 } },
3901 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3902 .u.insns_int = {
3903 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3904 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3905 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3906 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3907 BPF_MOV32_IMM(R0, 2),
3908 BPF_EXIT_INSN(),
3909 BPF_MOV32_IMM(R0, 1),
3910 BPF_EXIT_INSN(),
3912 INTERNAL,
3913 { },
3914 { { 0, 0x1 } },
3916 /* BPF_ALU | BPF_LSH | BPF_X */
3918 "ALU_LSH_X: 1 << 1 = 2",
3919 .u.insns_int = {
3920 BPF_LD_IMM64(R0, 1),
3921 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3922 BPF_ALU32_REG(BPF_LSH, R0, R1),
3923 BPF_EXIT_INSN(),
3925 INTERNAL,
3926 { },
3927 { { 0, 2 } },
3930 "ALU_LSH_X: 1 << 31 = 0x80000000",
3931 .u.insns_int = {
3932 BPF_LD_IMM64(R0, 1),
3933 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3934 BPF_ALU32_REG(BPF_LSH, R0, R1),
3935 BPF_EXIT_INSN(),
3937 INTERNAL,
3938 { },
3939 { { 0, 0x80000000 } },
3942 "ALU64_LSH_X: 1 << 1 = 2",
3943 .u.insns_int = {
3944 BPF_LD_IMM64(R0, 1),
3945 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3946 BPF_ALU64_REG(BPF_LSH, R0, R1),
3947 BPF_EXIT_INSN(),
3949 INTERNAL,
3950 { },
3951 { { 0, 2 } },
3954 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3955 .u.insns_int = {
3956 BPF_LD_IMM64(R0, 1),
3957 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3958 BPF_ALU64_REG(BPF_LSH, R0, R1),
3959 BPF_EXIT_INSN(),
3961 INTERNAL,
3962 { },
3963 { { 0, 0x80000000 } },
3965 /* BPF_ALU | BPF_LSH | BPF_K */
3967 "ALU_LSH_K: 1 << 1 = 2",
3968 .u.insns_int = {
3969 BPF_LD_IMM64(R0, 1),
3970 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3971 BPF_EXIT_INSN(),
3973 INTERNAL,
3974 { },
3975 { { 0, 2 } },
3978 "ALU_LSH_K: 1 << 31 = 0x80000000",
3979 .u.insns_int = {
3980 BPF_LD_IMM64(R0, 1),
3981 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3982 BPF_EXIT_INSN(),
3984 INTERNAL,
3985 { },
3986 { { 0, 0x80000000 } },
3989 "ALU64_LSH_K: 1 << 1 = 2",
3990 .u.insns_int = {
3991 BPF_LD_IMM64(R0, 1),
3992 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3993 BPF_EXIT_INSN(),
3995 INTERNAL,
3996 { },
3997 { { 0, 2 } },
4000 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4001 .u.insns_int = {
4002 BPF_LD_IMM64(R0, 1),
4003 BPF_ALU64_IMM(BPF_LSH, R0, 31),
4004 BPF_EXIT_INSN(),
4006 INTERNAL,
4007 { },
4008 { { 0, 0x80000000 } },
4010 /* BPF_ALU | BPF_RSH | BPF_X */
4012 "ALU_RSH_X: 2 >> 1 = 1",
4013 .u.insns_int = {
4014 BPF_LD_IMM64(R0, 2),
4015 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4016 BPF_ALU32_REG(BPF_RSH, R0, R1),
4017 BPF_EXIT_INSN(),
4019 INTERNAL,
4020 { },
4021 { { 0, 1 } },
4024 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4025 .u.insns_int = {
4026 BPF_LD_IMM64(R0, 0x80000000),
4027 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4028 BPF_ALU32_REG(BPF_RSH, R0, R1),
4029 BPF_EXIT_INSN(),
4031 INTERNAL,
4032 { },
4033 { { 0, 1 } },
4036 "ALU64_RSH_X: 2 >> 1 = 1",
4037 .u.insns_int = {
4038 BPF_LD_IMM64(R0, 2),
4039 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4040 BPF_ALU64_REG(BPF_RSH, R0, R1),
4041 BPF_EXIT_INSN(),
4043 INTERNAL,
4044 { },
4045 { { 0, 1 } },
4048 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4049 .u.insns_int = {
4050 BPF_LD_IMM64(R0, 0x80000000),
4051 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4052 BPF_ALU64_REG(BPF_RSH, R0, R1),
4053 BPF_EXIT_INSN(),
4055 INTERNAL,
4056 { },
4057 { { 0, 1 } },
4059 /* BPF_ALU | BPF_RSH | BPF_K */
4061 "ALU_RSH_K: 2 >> 1 = 1",
4062 .u.insns_int = {
4063 BPF_LD_IMM64(R0, 2),
4064 BPF_ALU32_IMM(BPF_RSH, R0, 1),
4065 BPF_EXIT_INSN(),
4067 INTERNAL,
4068 { },
4069 { { 0, 1 } },
4072 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4073 .u.insns_int = {
4074 BPF_LD_IMM64(R0, 0x80000000),
4075 BPF_ALU32_IMM(BPF_RSH, R0, 31),
4076 BPF_EXIT_INSN(),
4078 INTERNAL,
4079 { },
4080 { { 0, 1 } },
4083 "ALU64_RSH_K: 2 >> 1 = 1",
4084 .u.insns_int = {
4085 BPF_LD_IMM64(R0, 2),
4086 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4087 BPF_EXIT_INSN(),
4089 INTERNAL,
4090 { },
4091 { { 0, 1 } },
4094 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4095 .u.insns_int = {
4096 BPF_LD_IMM64(R0, 0x80000000),
4097 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4098 BPF_EXIT_INSN(),
4100 INTERNAL,
4101 { },
4102 { { 0, 1 } },
4104 /* BPF_ALU | BPF_ARSH | BPF_X */
4106 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4107 .u.insns_int = {
4108 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4109 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4110 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4111 BPF_EXIT_INSN(),
4113 INTERNAL,
4114 { },
4115 { { 0, 0xffff00ff } },
4117 /* BPF_ALU | BPF_ARSH | BPF_K */
4119 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4120 .u.insns_int = {
4121 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4122 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
4123 BPF_EXIT_INSN(),
4125 INTERNAL,
4126 { },
4127 { { 0, 0xffff00ff } },
4129 /* BPF_ALU | BPF_NEG */
4131 "ALU_NEG: -(3) = -3",
4132 .u.insns_int = {
4133 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4134 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4135 BPF_EXIT_INSN(),
4137 INTERNAL,
4138 { },
4139 { { 0, -3 } },
4142 "ALU_NEG: -(-3) = 3",
4143 .u.insns_int = {
4144 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4145 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4146 BPF_EXIT_INSN(),
4148 INTERNAL,
4149 { },
4150 { { 0, 3 } },
4153 "ALU64_NEG: -(3) = -3",
4154 .u.insns_int = {
4155 BPF_LD_IMM64(R0, 3),
4156 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4157 BPF_EXIT_INSN(),
4159 INTERNAL,
4160 { },
4161 { { 0, -3 } },
4164 "ALU64_NEG: -(-3) = 3",
4165 .u.insns_int = {
4166 BPF_LD_IMM64(R0, -3),
4167 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4168 BPF_EXIT_INSN(),
4170 INTERNAL,
4171 { },
4172 { { 0, 3 } },
4174 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4176 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4177 .u.insns_int = {
4178 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4179 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4180 BPF_EXIT_INSN(),
4182 INTERNAL,
4183 { },
4184 { { 0, cpu_to_be16(0xcdef) } },
4187 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4188 .u.insns_int = {
4189 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4190 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
4191 BPF_ALU64_REG(BPF_MOV, R1, R0),
4192 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4193 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
4194 BPF_EXIT_INSN(),
4196 INTERNAL,
4197 { },
4198 { { 0, cpu_to_be32(0x89abcdef) } },
4201 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4202 .u.insns_int = {
4203 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4204 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4205 BPF_EXIT_INSN(),
4207 INTERNAL,
4208 { },
4209 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4211 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4213 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4214 .u.insns_int = {
4215 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4216 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4217 BPF_EXIT_INSN(),
4219 INTERNAL,
4220 { },
4221 { { 0, cpu_to_le16(0xcdef) } },
4224 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4225 .u.insns_int = {
4226 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4227 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
4228 BPF_ALU64_REG(BPF_MOV, R1, R0),
4229 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4230 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
4231 BPF_EXIT_INSN(),
4233 INTERNAL,
4234 { },
4235 { { 0, cpu_to_le32(0x89abcdef) } },
4238 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4239 .u.insns_int = {
4240 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4241 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4242 BPF_EXIT_INSN(),
4244 INTERNAL,
4245 { },
4246 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4248 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4250 "ST_MEM_B: Store/Load byte: max negative",
4251 .u.insns_int = {
4252 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4253 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4254 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4255 BPF_EXIT_INSN(),
4257 INTERNAL,
4258 { },
4259 { { 0, 0xff } },
4260 .stack_depth = 40,
4263 "ST_MEM_B: Store/Load byte: max positive",
4264 .u.insns_int = {
4265 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4266 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4267 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4268 BPF_EXIT_INSN(),
4270 INTERNAL,
4271 { },
4272 { { 0, 0x7f } },
4273 .stack_depth = 40,
4276 "STX_MEM_B: Store/Load byte: max negative",
4277 .u.insns_int = {
4278 BPF_LD_IMM64(R0, 0),
4279 BPF_LD_IMM64(R1, 0xffLL),
4280 BPF_STX_MEM(BPF_B, R10, R1, -40),
4281 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4282 BPF_EXIT_INSN(),
4284 INTERNAL,
4285 { },
4286 { { 0, 0xff } },
4287 .stack_depth = 40,
4290 "ST_MEM_H: Store/Load half word: max negative",
4291 .u.insns_int = {
4292 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4293 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4294 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4295 BPF_EXIT_INSN(),
4297 INTERNAL,
4298 { },
4299 { { 0, 0xffff } },
4300 .stack_depth = 40,
4303 "ST_MEM_H: Store/Load half word: max positive",
4304 .u.insns_int = {
4305 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4306 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4307 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4308 BPF_EXIT_INSN(),
4310 INTERNAL,
4311 { },
4312 { { 0, 0x7fff } },
4313 .stack_depth = 40,
4316 "STX_MEM_H: Store/Load half word: max negative",
4317 .u.insns_int = {
4318 BPF_LD_IMM64(R0, 0),
4319 BPF_LD_IMM64(R1, 0xffffLL),
4320 BPF_STX_MEM(BPF_H, R10, R1, -40),
4321 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4322 BPF_EXIT_INSN(),
4324 INTERNAL,
4325 { },
4326 { { 0, 0xffff } },
4327 .stack_depth = 40,
4330 "ST_MEM_W: Store/Load word: max negative",
4331 .u.insns_int = {
4332 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4333 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4334 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4335 BPF_EXIT_INSN(),
4337 INTERNAL,
4338 { },
4339 { { 0, 0xffffffff } },
4340 .stack_depth = 40,
4343 "ST_MEM_W: Store/Load word: max positive",
4344 .u.insns_int = {
4345 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4346 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4347 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4348 BPF_EXIT_INSN(),
4350 INTERNAL,
4351 { },
4352 { { 0, 0x7fffffff } },
4353 .stack_depth = 40,
4356 "STX_MEM_W: Store/Load word: max negative",
4357 .u.insns_int = {
4358 BPF_LD_IMM64(R0, 0),
4359 BPF_LD_IMM64(R1, 0xffffffffLL),
4360 BPF_STX_MEM(BPF_W, R10, R1, -40),
4361 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4362 BPF_EXIT_INSN(),
4364 INTERNAL,
4365 { },
4366 { { 0, 0xffffffff } },
4367 .stack_depth = 40,
4370 "ST_MEM_DW: Store/Load double word: max negative",
4371 .u.insns_int = {
4372 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4373 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4374 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4375 BPF_EXIT_INSN(),
4377 INTERNAL,
4378 { },
4379 { { 0, 0xffffffff } },
4380 .stack_depth = 40,
4383 "ST_MEM_DW: Store/Load double word: max negative 2",
4384 .u.insns_int = {
4385 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4386 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
4387 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4388 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4389 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4390 BPF_MOV32_IMM(R0, 2),
4391 BPF_EXIT_INSN(),
4392 BPF_MOV32_IMM(R0, 1),
4393 BPF_EXIT_INSN(),
4395 INTERNAL,
4396 { },
4397 { { 0, 0x1 } },
4398 .stack_depth = 40,
4401 "ST_MEM_DW: Store/Load double word: max positive",
4402 .u.insns_int = {
4403 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4404 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4405 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4406 BPF_EXIT_INSN(),
4408 INTERNAL,
4409 { },
4410 { { 0, 0x7fffffff } },
4411 .stack_depth = 40,
4414 "STX_MEM_DW: Store/Load double word: max negative",
4415 .u.insns_int = {
4416 BPF_LD_IMM64(R0, 0),
4417 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4418 BPF_STX_MEM(BPF_W, R10, R1, -40),
4419 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4420 BPF_EXIT_INSN(),
4422 INTERNAL,
4423 { },
4424 { { 0, 0xffffffff } },
4425 .stack_depth = 40,
4427 /* BPF_STX | BPF_XADD | BPF_W/DW */
4429 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4430 .u.insns_int = {
4431 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4432 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4433 BPF_STX_XADD(BPF_W, R10, R0, -40),
4434 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4435 BPF_EXIT_INSN(),
4437 INTERNAL,
4438 { },
4439 { { 0, 0x22 } },
4440 .stack_depth = 40,
4443 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4444 .u.insns_int = {
4445 BPF_ALU64_REG(BPF_MOV, R1, R10),
4446 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4447 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4448 BPF_STX_XADD(BPF_W, R10, R0, -40),
4449 BPF_ALU64_REG(BPF_MOV, R0, R10),
4450 BPF_ALU64_REG(BPF_SUB, R0, R1),
4451 BPF_EXIT_INSN(),
4453 INTERNAL,
4454 { },
4455 { { 0, 0 } },
4456 .stack_depth = 40,
4459 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4460 .u.insns_int = {
4461 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4462 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4463 BPF_STX_XADD(BPF_W, R10, R0, -40),
4464 BPF_EXIT_INSN(),
4466 INTERNAL,
4467 { },
4468 { { 0, 0x12 } },
4469 .stack_depth = 40,
4472 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4473 { },
4474 INTERNAL,
4475 { },
4476 { { 0, 4134 } },
4477 .fill_helper = bpf_fill_stxw,
4480 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4481 .u.insns_int = {
4482 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4483 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4484 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4485 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4486 BPF_EXIT_INSN(),
4488 INTERNAL,
4489 { },
4490 { { 0, 0x22 } },
4491 .stack_depth = 40,
4494 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4495 .u.insns_int = {
4496 BPF_ALU64_REG(BPF_MOV, R1, R10),
4497 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4498 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4499 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4500 BPF_ALU64_REG(BPF_MOV, R0, R10),
4501 BPF_ALU64_REG(BPF_SUB, R0, R1),
4502 BPF_EXIT_INSN(),
4504 INTERNAL,
4505 { },
4506 { { 0, 0 } },
4507 .stack_depth = 40,
4510 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4511 .u.insns_int = {
4512 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4513 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4514 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4515 BPF_EXIT_INSN(),
4517 INTERNAL,
4518 { },
4519 { { 0, 0x12 } },
4520 .stack_depth = 40,
4523 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4524 { },
4525 INTERNAL,
4526 { },
4527 { { 0, 4134 } },
4528 .fill_helper = bpf_fill_stxdw,
4530 /* BPF_JMP | BPF_EXIT */
4532 "JMP_EXIT",
4533 .u.insns_int = {
4534 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4535 BPF_EXIT_INSN(),
4536 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4538 INTERNAL,
4539 { },
4540 { { 0, 0x4711 } },
4542 /* BPF_JMP | BPF_JA */
4544 "JMP_JA: Unconditional jump: if (true) return 1",
4545 .u.insns_int = {
4546 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4547 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4548 BPF_EXIT_INSN(),
4549 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4550 BPF_EXIT_INSN(),
4552 INTERNAL,
4553 { },
4554 { { 0, 1 } },
4556 /* BPF_JMP | BPF_JSLT | BPF_K */
4558 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4559 .u.insns_int = {
4560 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4561 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4562 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4563 BPF_EXIT_INSN(),
4564 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4565 BPF_EXIT_INSN(),
4567 INTERNAL,
4568 { },
4569 { { 0, 1 } },
4572 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4573 .u.insns_int = {
4574 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4575 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4576 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4577 BPF_EXIT_INSN(),
4578 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4579 BPF_EXIT_INSN(),
4581 INTERNAL,
4582 { },
4583 { { 0, 1 } },
4585 /* BPF_JMP | BPF_JSGT | BPF_K */
4587 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4588 .u.insns_int = {
4589 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4590 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4591 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4592 BPF_EXIT_INSN(),
4593 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4594 BPF_EXIT_INSN(),
4596 INTERNAL,
4597 { },
4598 { { 0, 1 } },
4601 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4602 .u.insns_int = {
4603 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4604 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4605 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4606 BPF_EXIT_INSN(),
4607 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4608 BPF_EXIT_INSN(),
4610 INTERNAL,
4611 { },
4612 { { 0, 1 } },
4614 /* BPF_JMP | BPF_JSLE | BPF_K */
4616 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4617 .u.insns_int = {
4618 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4619 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4620 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4621 BPF_EXIT_INSN(),
4622 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4623 BPF_EXIT_INSN(),
4625 INTERNAL,
4626 { },
4627 { { 0, 1 } },
4630 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4631 .u.insns_int = {
4632 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4633 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4634 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4635 BPF_EXIT_INSN(),
4636 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4637 BPF_EXIT_INSN(),
4639 INTERNAL,
4640 { },
4641 { { 0, 1 } },
4644 "JMP_JSLE_K: Signed jump: value walk 1",
4645 .u.insns_int = {
4646 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4647 BPF_LD_IMM64(R1, 3),
4648 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
4649 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4650 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4651 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4652 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4653 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4654 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4655 BPF_EXIT_INSN(), /* bad exit */
4656 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4657 BPF_EXIT_INSN(),
4659 INTERNAL,
4660 { },
4661 { { 0, 1 } },
4664 "JMP_JSLE_K: Signed jump: value walk 2",
4665 .u.insns_int = {
4666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4667 BPF_LD_IMM64(R1, 3),
4668 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4669 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4670 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4671 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4672 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4673 BPF_EXIT_INSN(), /* bad exit */
4674 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4675 BPF_EXIT_INSN(),
4677 INTERNAL,
4678 { },
4679 { { 0, 1 } },
4681 /* BPF_JMP | BPF_JSGE | BPF_K */
4683 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4684 .u.insns_int = {
4685 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4686 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4687 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4688 BPF_EXIT_INSN(),
4689 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4690 BPF_EXIT_INSN(),
4692 INTERNAL,
4693 { },
4694 { { 0, 1 } },
4697 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4698 .u.insns_int = {
4699 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4700 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4701 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4702 BPF_EXIT_INSN(),
4703 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4704 BPF_EXIT_INSN(),
4706 INTERNAL,
4707 { },
4708 { { 0, 1 } },
4711 "JMP_JSGE_K: Signed jump: value walk 1",
4712 .u.insns_int = {
4713 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4714 BPF_LD_IMM64(R1, -3),
4715 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
4716 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4717 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4718 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4719 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4720 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4721 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4722 BPF_EXIT_INSN(), /* bad exit */
4723 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4724 BPF_EXIT_INSN(),
4726 INTERNAL,
4727 { },
4728 { { 0, 1 } },
4731 "JMP_JSGE_K: Signed jump: value walk 2",
4732 .u.insns_int = {
4733 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4734 BPF_LD_IMM64(R1, -3),
4735 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4736 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4737 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4738 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4739 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4740 BPF_EXIT_INSN(), /* bad exit */
4741 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4742 BPF_EXIT_INSN(),
4744 INTERNAL,
4745 { },
4746 { { 0, 1 } },
4748 /* BPF_JMP | BPF_JGT | BPF_K */
4750 "JMP_JGT_K: if (3 > 2) return 1",
4751 .u.insns_int = {
4752 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4753 BPF_LD_IMM64(R1, 3),
4754 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4755 BPF_EXIT_INSN(),
4756 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4757 BPF_EXIT_INSN(),
4759 INTERNAL,
4760 { },
4761 { { 0, 1 } },
4764 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4765 .u.insns_int = {
4766 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4767 BPF_LD_IMM64(R1, -1),
4768 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
4769 BPF_EXIT_INSN(),
4770 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4771 BPF_EXIT_INSN(),
4773 INTERNAL,
4774 { },
4775 { { 0, 1 } },
4777 /* BPF_JMP | BPF_JLT | BPF_K */
4779 "JMP_JLT_K: if (2 < 3) return 1",
4780 .u.insns_int = {
4781 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4782 BPF_LD_IMM64(R1, 2),
4783 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
4784 BPF_EXIT_INSN(),
4785 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4786 BPF_EXIT_INSN(),
4788 INTERNAL,
4789 { },
4790 { { 0, 1 } },
4793 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4794 .u.insns_int = {
4795 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4796 BPF_LD_IMM64(R1, 1),
4797 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
4798 BPF_EXIT_INSN(),
4799 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4800 BPF_EXIT_INSN(),
4802 INTERNAL,
4803 { },
4804 { { 0, 1 } },
4806 /* BPF_JMP | BPF_JGE | BPF_K */
4808 "JMP_JGE_K: if (3 >= 2) return 1",
4809 .u.insns_int = {
4810 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4811 BPF_LD_IMM64(R1, 3),
4812 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4813 BPF_EXIT_INSN(),
4814 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4815 BPF_EXIT_INSN(),
4817 INTERNAL,
4818 { },
4819 { { 0, 1 } },
4821 /* BPF_JMP | BPF_JLE | BPF_K */
4823 "JMP_JLE_K: if (2 <= 3) return 1",
4824 .u.insns_int = {
4825 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4826 BPF_LD_IMM64(R1, 2),
4827 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4828 BPF_EXIT_INSN(),
4829 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4830 BPF_EXIT_INSN(),
4832 INTERNAL,
4833 { },
4834 { { 0, 1 } },
4836 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4838 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4839 .u.insns_int = {
4840 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4841 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4842 BPF_EXIT_INSN(),
4843 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4844 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4845 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4846 BPF_EXIT_INSN(),
4848 INTERNAL,
4849 { },
4850 { { 0, 1 } },
4853 "JMP_JGE_K: if (3 >= 3) return 1",
4854 .u.insns_int = {
4855 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4856 BPF_LD_IMM64(R1, 3),
4857 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4858 BPF_EXIT_INSN(),
4859 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4860 BPF_EXIT_INSN(),
4862 INTERNAL,
4863 { },
4864 { { 0, 1 } },
4866 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4868 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4869 .u.insns_int = {
4870 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4871 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4872 BPF_EXIT_INSN(),
4873 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4874 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
4875 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
4876 BPF_EXIT_INSN(),
4878 INTERNAL,
4879 { },
4880 { { 0, 1 } },
4883 "JMP_JLE_K: if (3 <= 3) return 1",
4884 .u.insns_int = {
4885 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4886 BPF_LD_IMM64(R1, 3),
4887 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4888 BPF_EXIT_INSN(),
4889 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4890 BPF_EXIT_INSN(),
4892 INTERNAL,
4893 { },
4894 { { 0, 1 } },
4896 /* BPF_JMP | BPF_JNE | BPF_K */
4898 "JMP_JNE_K: if (3 != 2) return 1",
4899 .u.insns_int = {
4900 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4901 BPF_LD_IMM64(R1, 3),
4902 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4903 BPF_EXIT_INSN(),
4904 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4905 BPF_EXIT_INSN(),
4907 INTERNAL,
4908 { },
4909 { { 0, 1 } },
4911 /* BPF_JMP | BPF_JEQ | BPF_K */
4913 "JMP_JEQ_K: if (3 == 3) return 1",
4914 .u.insns_int = {
4915 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4916 BPF_LD_IMM64(R1, 3),
4917 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4918 BPF_EXIT_INSN(),
4919 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4920 BPF_EXIT_INSN(),
4922 INTERNAL,
4923 { },
4924 { { 0, 1 } },
4926 /* BPF_JMP | BPF_JSET | BPF_K */
4928 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4929 .u.insns_int = {
4930 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4931 BPF_LD_IMM64(R1, 3),
4932 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
4933 BPF_EXIT_INSN(),
4934 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4935 BPF_EXIT_INSN(),
4937 INTERNAL,
4938 { },
4939 { { 0, 1 } },
4942 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4943 .u.insns_int = {
4944 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4945 BPF_LD_IMM64(R1, 3),
4946 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
4947 BPF_EXIT_INSN(),
4948 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4949 BPF_EXIT_INSN(),
4951 INTERNAL,
4952 { },
4953 { { 0, 1 } },
4955 /* BPF_JMP | BPF_JSGT | BPF_X */
4957 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4958 .u.insns_int = {
4959 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4960 BPF_LD_IMM64(R1, -1),
4961 BPF_LD_IMM64(R2, -2),
4962 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4963 BPF_EXIT_INSN(),
4964 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4965 BPF_EXIT_INSN(),
4967 INTERNAL,
4968 { },
4969 { { 0, 1 } },
4972 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4973 .u.insns_int = {
4974 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4975 BPF_LD_IMM64(R1, -1),
4976 BPF_LD_IMM64(R2, -1),
4977 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4978 BPF_EXIT_INSN(),
4979 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4980 BPF_EXIT_INSN(),
4982 INTERNAL,
4983 { },
4984 { { 0, 1 } },
4986 /* BPF_JMP | BPF_JSLT | BPF_X */
4988 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4989 .u.insns_int = {
4990 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4991 BPF_LD_IMM64(R1, -1),
4992 BPF_LD_IMM64(R2, -2),
4993 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
4994 BPF_EXIT_INSN(),
4995 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4996 BPF_EXIT_INSN(),
4998 INTERNAL,
4999 { },
5000 { { 0, 1 } },
5003 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
5004 .u.insns_int = {
5005 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5006 BPF_LD_IMM64(R1, -1),
5007 BPF_LD_IMM64(R2, -1),
5008 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
5009 BPF_EXIT_INSN(),
5010 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5011 BPF_EXIT_INSN(),
5013 INTERNAL,
5014 { },
5015 { { 0, 1 } },
5017 /* BPF_JMP | BPF_JSGE | BPF_X */
5019 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5020 .u.insns_int = {
5021 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5022 BPF_LD_IMM64(R1, -1),
5023 BPF_LD_IMM64(R2, -2),
5024 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
5025 BPF_EXIT_INSN(),
5026 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5027 BPF_EXIT_INSN(),
5029 INTERNAL,
5030 { },
5031 { { 0, 1 } },
5034 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5035 .u.insns_int = {
5036 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5037 BPF_LD_IMM64(R1, -1),
5038 BPF_LD_IMM64(R2, -1),
5039 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
5040 BPF_EXIT_INSN(),
5041 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5042 BPF_EXIT_INSN(),
5044 INTERNAL,
5045 { },
5046 { { 0, 1 } },
5048 /* BPF_JMP | BPF_JSLE | BPF_X */
5050 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5051 .u.insns_int = {
5052 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5053 BPF_LD_IMM64(R1, -1),
5054 BPF_LD_IMM64(R2, -2),
5055 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
5056 BPF_EXIT_INSN(),
5057 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5058 BPF_EXIT_INSN(),
5060 INTERNAL,
5061 { },
5062 { { 0, 1 } },
5065 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5066 .u.insns_int = {
5067 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5068 BPF_LD_IMM64(R1, -1),
5069 BPF_LD_IMM64(R2, -1),
5070 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
5071 BPF_EXIT_INSN(),
5072 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5073 BPF_EXIT_INSN(),
5075 INTERNAL,
5076 { },
5077 { { 0, 1 } },
5079 /* BPF_JMP | BPF_JGT | BPF_X */
5081 "JMP_JGT_X: if (3 > 2) return 1",
5082 .u.insns_int = {
5083 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5084 BPF_LD_IMM64(R1, 3),
5085 BPF_LD_IMM64(R2, 2),
5086 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
5087 BPF_EXIT_INSN(),
5088 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5089 BPF_EXIT_INSN(),
5091 INTERNAL,
5092 { },
5093 { { 0, 1 } },
5096 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5097 .u.insns_int = {
5098 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5099 BPF_LD_IMM64(R1, -1),
5100 BPF_LD_IMM64(R2, 1),
5101 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
5102 BPF_EXIT_INSN(),
5103 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5104 BPF_EXIT_INSN(),
5106 INTERNAL,
5107 { },
5108 { { 0, 1 } },
5110 /* BPF_JMP | BPF_JLT | BPF_X */
5112 "JMP_JLT_X: if (2 < 3) return 1",
5113 .u.insns_int = {
5114 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5115 BPF_LD_IMM64(R1, 3),
5116 BPF_LD_IMM64(R2, 2),
5117 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5118 BPF_EXIT_INSN(),
5119 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5120 BPF_EXIT_INSN(),
5122 INTERNAL,
5123 { },
5124 { { 0, 1 } },
5127 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5128 .u.insns_int = {
5129 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5130 BPF_LD_IMM64(R1, -1),
5131 BPF_LD_IMM64(R2, 1),
5132 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5133 BPF_EXIT_INSN(),
5134 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5135 BPF_EXIT_INSN(),
5137 INTERNAL,
5138 { },
5139 { { 0, 1 } },
5141 /* BPF_JMP | BPF_JGE | BPF_X */
5143 "JMP_JGE_X: if (3 >= 2) return 1",
5144 .u.insns_int = {
5145 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5146 BPF_LD_IMM64(R1, 3),
5147 BPF_LD_IMM64(R2, 2),
5148 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5149 BPF_EXIT_INSN(),
5150 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5151 BPF_EXIT_INSN(),
5153 INTERNAL,
5154 { },
5155 { { 0, 1 } },
5158 "JMP_JGE_X: if (3 >= 3) return 1",
5159 .u.insns_int = {
5160 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5161 BPF_LD_IMM64(R1, 3),
5162 BPF_LD_IMM64(R2, 3),
5163 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5164 BPF_EXIT_INSN(),
5165 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5166 BPF_EXIT_INSN(),
5168 INTERNAL,
5169 { },
5170 { { 0, 1 } },
5172 /* BPF_JMP | BPF_JLE | BPF_X */
5174 "JMP_JLE_X: if (2 <= 3) return 1",
5175 .u.insns_int = {
5176 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5177 BPF_LD_IMM64(R1, 3),
5178 BPF_LD_IMM64(R2, 2),
5179 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
5180 BPF_EXIT_INSN(),
5181 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5182 BPF_EXIT_INSN(),
5184 INTERNAL,
5185 { },
5186 { { 0, 1 } },
5189 "JMP_JLE_X: if (3 <= 3) return 1",
5190 .u.insns_int = {
5191 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5192 BPF_LD_IMM64(R1, 3),
5193 BPF_LD_IMM64(R2, 3),
5194 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
5195 BPF_EXIT_INSN(),
5196 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5197 BPF_EXIT_INSN(),
5199 INTERNAL,
5200 { },
5201 { { 0, 1 } },
5204 /* Mainly testing JIT + imm64 here. */
5205 "JMP_JGE_X: ldimm64 test 1",
5206 .u.insns_int = {
5207 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5208 BPF_LD_IMM64(R1, 3),
5209 BPF_LD_IMM64(R2, 2),
5210 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
5211 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5212 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5213 BPF_EXIT_INSN(),
5215 INTERNAL,
5216 { },
5217 { { 0, 0xeeeeeeeeU } },
5220 "JMP_JGE_X: ldimm64 test 2",
5221 .u.insns_int = {
5222 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5223 BPF_LD_IMM64(R1, 3),
5224 BPF_LD_IMM64(R2, 2),
5225 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
5226 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5227 BPF_EXIT_INSN(),
5229 INTERNAL,
5230 { },
5231 { { 0, 0xffffffffU } },
5234 "JMP_JGE_X: ldimm64 test 3",
5235 .u.insns_int = {
5236 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5237 BPF_LD_IMM64(R1, 3),
5238 BPF_LD_IMM64(R2, 2),
5239 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
5240 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5241 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5242 BPF_EXIT_INSN(),
5244 INTERNAL,
5245 { },
5246 { { 0, 1 } },
5249 "JMP_JLE_X: ldimm64 test 1",
5250 .u.insns_int = {
5251 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5252 BPF_LD_IMM64(R1, 3),
5253 BPF_LD_IMM64(R2, 2),
5254 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
5255 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5256 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5257 BPF_EXIT_INSN(),
5259 INTERNAL,
5260 { },
5261 { { 0, 0xeeeeeeeeU } },
5264 "JMP_JLE_X: ldimm64 test 2",
5265 .u.insns_int = {
5266 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5267 BPF_LD_IMM64(R1, 3),
5268 BPF_LD_IMM64(R2, 2),
5269 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
5270 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5271 BPF_EXIT_INSN(),
5273 INTERNAL,
5274 { },
5275 { { 0, 0xffffffffU } },
5278 "JMP_JLE_X: ldimm64 test 3",
5279 .u.insns_int = {
5280 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5281 BPF_LD_IMM64(R1, 3),
5282 BPF_LD_IMM64(R2, 2),
5283 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
5284 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5285 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5286 BPF_EXIT_INSN(),
5288 INTERNAL,
5289 { },
5290 { { 0, 1 } },
5292 /* BPF_JMP | BPF_JNE | BPF_X */
5294 "JMP_JNE_X: if (3 != 2) return 1",
5295 .u.insns_int = {
5296 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5297 BPF_LD_IMM64(R1, 3),
5298 BPF_LD_IMM64(R2, 2),
5299 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
5300 BPF_EXIT_INSN(),
5301 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5302 BPF_EXIT_INSN(),
5304 INTERNAL,
5305 { },
5306 { { 0, 1 } },
5308 /* BPF_JMP | BPF_JEQ | BPF_X */
5310 "JMP_JEQ_X: if (3 == 3) return 1",
5311 .u.insns_int = {
5312 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5313 BPF_LD_IMM64(R1, 3),
5314 BPF_LD_IMM64(R2, 3),
5315 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
5316 BPF_EXIT_INSN(),
5317 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5318 BPF_EXIT_INSN(),
5320 INTERNAL,
5321 { },
5322 { { 0, 1 } },
5324 /* BPF_JMP | BPF_JSET | BPF_X */
5326 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5327 .u.insns_int = {
5328 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5329 BPF_LD_IMM64(R1, 3),
5330 BPF_LD_IMM64(R2, 2),
5331 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
5332 BPF_EXIT_INSN(),
5333 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5334 BPF_EXIT_INSN(),
5336 INTERNAL,
5337 { },
5338 { { 0, 1 } },
5341 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5342 .u.insns_int = {
5343 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5344 BPF_LD_IMM64(R1, 3),
5345 BPF_LD_IMM64(R2, 0xffffffff),
5346 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
5347 BPF_EXIT_INSN(),
5348 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5349 BPF_EXIT_INSN(),
5351 INTERNAL,
5352 { },
5353 { { 0, 1 } },
5356 "JMP_JA: Jump, gap, jump, ...",
5357 { },
5358 CLASSIC | FLAG_NO_DATA,
5359 { },
5360 { { 0, 0xababcbac } },
5361 .fill_helper = bpf_fill_ja,
5363 { /* Mainly checking JIT here. */
5364 "BPF_MAXINSNS: Maximum possible literals",
5365 { },
5366 CLASSIC | FLAG_NO_DATA,
5367 { },
5368 { { 0, 0xffffffff } },
5369 .fill_helper = bpf_fill_maxinsns1,
5371 { /* Mainly checking JIT here. */
5372 "BPF_MAXINSNS: Single literal",
5373 { },
5374 CLASSIC | FLAG_NO_DATA,
5375 { },
5376 { { 0, 0xfefefefe } },
5377 .fill_helper = bpf_fill_maxinsns2,
5379 { /* Mainly checking JIT here. */
5380 "BPF_MAXINSNS: Run/add until end",
5381 { },
5382 CLASSIC | FLAG_NO_DATA,
5383 { },
5384 { { 0, 0x947bf368 } },
5385 .fill_helper = bpf_fill_maxinsns3,
5388 "BPF_MAXINSNS: Too many instructions",
5389 { },
5390 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5391 { },
5392 { },
5393 .fill_helper = bpf_fill_maxinsns4,
5395 { /* Mainly checking JIT here. */
5396 "BPF_MAXINSNS: Very long jump",
5397 { },
5398 CLASSIC | FLAG_NO_DATA,
5399 { },
5400 { { 0, 0xabababab } },
5401 .fill_helper = bpf_fill_maxinsns5,
5403 { /* Mainly checking JIT here. */
5404 "BPF_MAXINSNS: Ctx heavy transformations",
5405 { },
5406 CLASSIC,
5407 { },
5409 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
5410 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
5412 .fill_helper = bpf_fill_maxinsns6,
5414 { /* Mainly checking JIT here. */
5415 "BPF_MAXINSNS: Call heavy transformations",
5416 { },
5417 CLASSIC | FLAG_NO_DATA,
5418 { },
5419 { { 1, 0 }, { 10, 0 } },
5420 .fill_helper = bpf_fill_maxinsns7,
5422 { /* Mainly checking JIT here. */
5423 "BPF_MAXINSNS: Jump heavy test",
5424 { },
5425 CLASSIC | FLAG_NO_DATA,
5426 { },
5427 { { 0, 0xffffffff } },
5428 .fill_helper = bpf_fill_maxinsns8,
5430 { /* Mainly checking JIT here. */
5431 "BPF_MAXINSNS: Very long jump backwards",
5432 { },
5433 INTERNAL | FLAG_NO_DATA,
5434 { },
5435 { { 0, 0xcbababab } },
5436 .fill_helper = bpf_fill_maxinsns9,
5438 { /* Mainly checking JIT here. */
5439 "BPF_MAXINSNS: Edge hopping nuthouse",
5440 { },
5441 INTERNAL | FLAG_NO_DATA,
5442 { },
5443 { { 0, 0xabababac } },
5444 .fill_helper = bpf_fill_maxinsns10,
5447 "BPF_MAXINSNS: Jump, gap, jump, ...",
5448 { },
5449 CLASSIC | FLAG_NO_DATA,
5450 { },
5451 { { 0, 0xababcbac } },
5452 .fill_helper = bpf_fill_maxinsns11,
5455 "BPF_MAXINSNS: ld_abs+get_processor_id",
5456 { },
5457 CLASSIC,
5458 { },
5459 { { 1, 0xbee } },
5460 .fill_helper = bpf_fill_ld_abs_get_processor_id,
5463 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5464 { },
5465 INTERNAL,
5466 { 0x34 },
5467 { { ETH_HLEN, 0xbef } },
5468 .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
5471 "BPF_MAXINSNS: jump around ld_abs",
5472 { },
5473 INTERNAL,
5474 { 10, 11 },
5475 { { 2, 10 } },
5476 .fill_helper = bpf_fill_jump_around_ld_abs,
5479 * LD_IND / LD_ABS on fragmented SKBs
5482 "LD_IND byte frag",
5483 .u.insns = {
5484 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5485 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
5486 BPF_STMT(BPF_RET | BPF_A, 0x0),
5488 CLASSIC | FLAG_SKB_FRAG,
5489 { },
5490 { {0x40, 0x42} },
5491 .frag_data = {
5492 0x42, 0x00, 0x00, 0x00,
5493 0x43, 0x44, 0x00, 0x00,
5494 0x21, 0x07, 0x19, 0x83,
5498 "LD_IND halfword frag",
5499 .u.insns = {
5500 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5501 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
5502 BPF_STMT(BPF_RET | BPF_A, 0x0),
5504 CLASSIC | FLAG_SKB_FRAG,
5505 { },
5506 { {0x40, 0x4344} },
5507 .frag_data = {
5508 0x42, 0x00, 0x00, 0x00,
5509 0x43, 0x44, 0x00, 0x00,
5510 0x21, 0x07, 0x19, 0x83,
5514 "LD_IND word frag",
5515 .u.insns = {
5516 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5517 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
5518 BPF_STMT(BPF_RET | BPF_A, 0x0),
5520 CLASSIC | FLAG_SKB_FRAG,
5521 { },
5522 { {0x40, 0x21071983} },
5523 .frag_data = {
5524 0x42, 0x00, 0x00, 0x00,
5525 0x43, 0x44, 0x00, 0x00,
5526 0x21, 0x07, 0x19, 0x83,
5530 "LD_IND halfword mixed head/frag",
5531 .u.insns = {
5532 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5533 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5534 BPF_STMT(BPF_RET | BPF_A, 0x0),
5536 CLASSIC | FLAG_SKB_FRAG,
5537 { [0x3e] = 0x25, [0x3f] = 0x05, },
5538 { {0x40, 0x0519} },
5539 .frag_data = { 0x19, 0x82 },
5542 "LD_IND word mixed head/frag",
5543 .u.insns = {
5544 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5545 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5546 BPF_STMT(BPF_RET | BPF_A, 0x0),
5548 CLASSIC | FLAG_SKB_FRAG,
5549 { [0x3e] = 0x25, [0x3f] = 0x05, },
5550 { {0x40, 0x25051982} },
5551 .frag_data = { 0x19, 0x82 },
5554 "LD_ABS byte frag",
5555 .u.insns = {
5556 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
5557 BPF_STMT(BPF_RET | BPF_A, 0x0),
5559 CLASSIC | FLAG_SKB_FRAG,
5560 { },
5561 { {0x40, 0x42} },
5562 .frag_data = {
5563 0x42, 0x00, 0x00, 0x00,
5564 0x43, 0x44, 0x00, 0x00,
5565 0x21, 0x07, 0x19, 0x83,
5569 "LD_ABS halfword frag",
5570 .u.insns = {
5571 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
5572 BPF_STMT(BPF_RET | BPF_A, 0x0),
5574 CLASSIC | FLAG_SKB_FRAG,
5575 { },
5576 { {0x40, 0x4344} },
5577 .frag_data = {
5578 0x42, 0x00, 0x00, 0x00,
5579 0x43, 0x44, 0x00, 0x00,
5580 0x21, 0x07, 0x19, 0x83,
5584 "LD_ABS word frag",
5585 .u.insns = {
5586 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
5587 BPF_STMT(BPF_RET | BPF_A, 0x0),
5589 CLASSIC | FLAG_SKB_FRAG,
5590 { },
5591 { {0x40, 0x21071983} },
5592 .frag_data = {
5593 0x42, 0x00, 0x00, 0x00,
5594 0x43, 0x44, 0x00, 0x00,
5595 0x21, 0x07, 0x19, 0x83,
5599 "LD_ABS halfword mixed head/frag",
5600 .u.insns = {
5601 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5602 BPF_STMT(BPF_RET | BPF_A, 0x0),
5604 CLASSIC | FLAG_SKB_FRAG,
5605 { [0x3e] = 0x25, [0x3f] = 0x05, },
5606 { {0x40, 0x0519} },
5607 .frag_data = { 0x19, 0x82 },
5610 "LD_ABS word mixed head/frag",
5611 .u.insns = {
5612 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
5613 BPF_STMT(BPF_RET | BPF_A, 0x0),
5615 CLASSIC | FLAG_SKB_FRAG,
5616 { [0x3e] = 0x25, [0x3f] = 0x05, },
5617 { {0x40, 0x25051982} },
5618 .frag_data = { 0x19, 0x82 },
5621 * LD_IND / LD_ABS on non fragmented SKBs
5625 * this tests that the JIT/interpreter correctly resets X
5626 * before using it in an LD_IND instruction.
5628 "LD_IND byte default X",
5629 .u.insns = {
5630 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5631 BPF_STMT(BPF_RET | BPF_A, 0x0),
5633 CLASSIC,
5634 { [0x1] = 0x42 },
5635 { {0x40, 0x42 } },
5638 "LD_IND byte positive offset",
5639 .u.insns = {
5640 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5641 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5642 BPF_STMT(BPF_RET | BPF_A, 0x0),
5644 CLASSIC,
5645 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5646 { {0x40, 0x82 } },
5649 "LD_IND byte negative offset",
5650 .u.insns = {
5651 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5652 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
5653 BPF_STMT(BPF_RET | BPF_A, 0x0),
5655 CLASSIC,
5656 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5657 { {0x40, 0x05 } },
5660 "LD_IND halfword positive offset",
5661 .u.insns = {
5662 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5663 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
5664 BPF_STMT(BPF_RET | BPF_A, 0x0),
5666 CLASSIC,
5668 [0x1c] = 0xaa, [0x1d] = 0x55,
5669 [0x1e] = 0xbb, [0x1f] = 0x66,
5670 [0x20] = 0xcc, [0x21] = 0x77,
5671 [0x22] = 0xdd, [0x23] = 0x88,
5673 { {0x40, 0xdd88 } },
5676 "LD_IND halfword negative offset",
5677 .u.insns = {
5678 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5679 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
5680 BPF_STMT(BPF_RET | BPF_A, 0x0),
5682 CLASSIC,
5684 [0x1c] = 0xaa, [0x1d] = 0x55,
5685 [0x1e] = 0xbb, [0x1f] = 0x66,
5686 [0x20] = 0xcc, [0x21] = 0x77,
5687 [0x22] = 0xdd, [0x23] = 0x88,
5689 { {0x40, 0xbb66 } },
5692 "LD_IND halfword unaligned",
5693 .u.insns = {
5694 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5695 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5696 BPF_STMT(BPF_RET | BPF_A, 0x0),
5698 CLASSIC,
5700 [0x1c] = 0xaa, [0x1d] = 0x55,
5701 [0x1e] = 0xbb, [0x1f] = 0x66,
5702 [0x20] = 0xcc, [0x21] = 0x77,
5703 [0x22] = 0xdd, [0x23] = 0x88,
5705 { {0x40, 0x66cc } },
5708 "LD_IND word positive offset",
5709 .u.insns = {
5710 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5711 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
5712 BPF_STMT(BPF_RET | BPF_A, 0x0),
5714 CLASSIC,
5716 [0x1c] = 0xaa, [0x1d] = 0x55,
5717 [0x1e] = 0xbb, [0x1f] = 0x66,
5718 [0x20] = 0xcc, [0x21] = 0x77,
5719 [0x22] = 0xdd, [0x23] = 0x88,
5720 [0x24] = 0xee, [0x25] = 0x99,
5721 [0x26] = 0xff, [0x27] = 0xaa,
5723 { {0x40, 0xee99ffaa } },
5726 "LD_IND word negative offset",
5727 .u.insns = {
5728 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5729 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
5730 BPF_STMT(BPF_RET | BPF_A, 0x0),
5732 CLASSIC,
5734 [0x1c] = 0xaa, [0x1d] = 0x55,
5735 [0x1e] = 0xbb, [0x1f] = 0x66,
5736 [0x20] = 0xcc, [0x21] = 0x77,
5737 [0x22] = 0xdd, [0x23] = 0x88,
5738 [0x24] = 0xee, [0x25] = 0x99,
5739 [0x26] = 0xff, [0x27] = 0xaa,
5741 { {0x40, 0xaa55bb66 } },
5744 "LD_IND word unaligned (addr & 3 == 2)",
5745 .u.insns = {
5746 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5747 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5748 BPF_STMT(BPF_RET | BPF_A, 0x0),
5750 CLASSIC,
5752 [0x1c] = 0xaa, [0x1d] = 0x55,
5753 [0x1e] = 0xbb, [0x1f] = 0x66,
5754 [0x20] = 0xcc, [0x21] = 0x77,
5755 [0x22] = 0xdd, [0x23] = 0x88,
5756 [0x24] = 0xee, [0x25] = 0x99,
5757 [0x26] = 0xff, [0x27] = 0xaa,
5759 { {0x40, 0xbb66cc77 } },
5762 "LD_IND word unaligned (addr & 3 == 1)",
5763 .u.insns = {
5764 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5765 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
5766 BPF_STMT(BPF_RET | BPF_A, 0x0),
5768 CLASSIC,
5770 [0x1c] = 0xaa, [0x1d] = 0x55,
5771 [0x1e] = 0xbb, [0x1f] = 0x66,
5772 [0x20] = 0xcc, [0x21] = 0x77,
5773 [0x22] = 0xdd, [0x23] = 0x88,
5774 [0x24] = 0xee, [0x25] = 0x99,
5775 [0x26] = 0xff, [0x27] = 0xaa,
5777 { {0x40, 0x55bb66cc } },
5780 "LD_IND word unaligned (addr & 3 == 3)",
5781 .u.insns = {
5782 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5783 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
5784 BPF_STMT(BPF_RET | BPF_A, 0x0),
5786 CLASSIC,
5788 [0x1c] = 0xaa, [0x1d] = 0x55,
5789 [0x1e] = 0xbb, [0x1f] = 0x66,
5790 [0x20] = 0xcc, [0x21] = 0x77,
5791 [0x22] = 0xdd, [0x23] = 0x88,
5792 [0x24] = 0xee, [0x25] = 0x99,
5793 [0x26] = 0xff, [0x27] = 0xaa,
5795 { {0x40, 0x66cc77dd } },
5798 "LD_ABS byte",
5799 .u.insns = {
5800 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
5801 BPF_STMT(BPF_RET | BPF_A, 0x0),
5803 CLASSIC,
5805 [0x1c] = 0xaa, [0x1d] = 0x55,
5806 [0x1e] = 0xbb, [0x1f] = 0x66,
5807 [0x20] = 0xcc, [0x21] = 0x77,
5808 [0x22] = 0xdd, [0x23] = 0x88,
5809 [0x24] = 0xee, [0x25] = 0x99,
5810 [0x26] = 0xff, [0x27] = 0xaa,
5812 { {0x40, 0xcc } },
5815 "LD_ABS halfword",
5816 .u.insns = {
5817 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
5818 BPF_STMT(BPF_RET | BPF_A, 0x0),
5820 CLASSIC,
5822 [0x1c] = 0xaa, [0x1d] = 0x55,
5823 [0x1e] = 0xbb, [0x1f] = 0x66,
5824 [0x20] = 0xcc, [0x21] = 0x77,
5825 [0x22] = 0xdd, [0x23] = 0x88,
5826 [0x24] = 0xee, [0x25] = 0x99,
5827 [0x26] = 0xff, [0x27] = 0xaa,
5829 { {0x40, 0xdd88 } },
5832 "LD_ABS halfword unaligned",
5833 .u.insns = {
5834 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
5835 BPF_STMT(BPF_RET | BPF_A, 0x0),
5837 CLASSIC,
5839 [0x1c] = 0xaa, [0x1d] = 0x55,
5840 [0x1e] = 0xbb, [0x1f] = 0x66,
5841 [0x20] = 0xcc, [0x21] = 0x77,
5842 [0x22] = 0xdd, [0x23] = 0x88,
5843 [0x24] = 0xee, [0x25] = 0x99,
5844 [0x26] = 0xff, [0x27] = 0xaa,
5846 { {0x40, 0x99ff } },
5849 "LD_ABS word",
5850 .u.insns = {
5851 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
5852 BPF_STMT(BPF_RET | BPF_A, 0x0),
5854 CLASSIC,
5856 [0x1c] = 0xaa, [0x1d] = 0x55,
5857 [0x1e] = 0xbb, [0x1f] = 0x66,
5858 [0x20] = 0xcc, [0x21] = 0x77,
5859 [0x22] = 0xdd, [0x23] = 0x88,
5860 [0x24] = 0xee, [0x25] = 0x99,
5861 [0x26] = 0xff, [0x27] = 0xaa,
5863 { {0x40, 0xaa55bb66 } },
5866 "LD_ABS word unaligned (addr & 3 == 2)",
5867 .u.insns = {
5868 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
5869 BPF_STMT(BPF_RET | BPF_A, 0x0),
5871 CLASSIC,
5873 [0x1c] = 0xaa, [0x1d] = 0x55,
5874 [0x1e] = 0xbb, [0x1f] = 0x66,
5875 [0x20] = 0xcc, [0x21] = 0x77,
5876 [0x22] = 0xdd, [0x23] = 0x88,
5877 [0x24] = 0xee, [0x25] = 0x99,
5878 [0x26] = 0xff, [0x27] = 0xaa,
5880 { {0x40, 0xdd88ee99 } },
5883 "LD_ABS word unaligned (addr & 3 == 1)",
5884 .u.insns = {
5885 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
5886 BPF_STMT(BPF_RET | BPF_A, 0x0),
5888 CLASSIC,
5890 [0x1c] = 0xaa, [0x1d] = 0x55,
5891 [0x1e] = 0xbb, [0x1f] = 0x66,
5892 [0x20] = 0xcc, [0x21] = 0x77,
5893 [0x22] = 0xdd, [0x23] = 0x88,
5894 [0x24] = 0xee, [0x25] = 0x99,
5895 [0x26] = 0xff, [0x27] = 0xaa,
5897 { {0x40, 0x77dd88ee } },
5900 "LD_ABS word unaligned (addr & 3 == 3)",
5901 .u.insns = {
5902 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
5903 BPF_STMT(BPF_RET | BPF_A, 0x0),
5905 CLASSIC,
5907 [0x1c] = 0xaa, [0x1d] = 0x55,
5908 [0x1e] = 0xbb, [0x1f] = 0x66,
5909 [0x20] = 0xcc, [0x21] = 0x77,
5910 [0x22] = 0xdd, [0x23] = 0x88,
5911 [0x24] = 0xee, [0x25] = 0x99,
5912 [0x26] = 0xff, [0x27] = 0xaa,
5914 { {0x40, 0x88ee99ff } },
5917 * verify that the interpreter or JIT correctly sets A and X
5918 * to 0.
5921 "ADD default X",
5922 .u.insns = {
5924 * A = 0x42
5925 * A = A + X
5926 * ret A
5928 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5929 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
5930 BPF_STMT(BPF_RET | BPF_A, 0x0),
5932 CLASSIC | FLAG_NO_DATA,
5934 { {0x1, 0x42 } },
5937 "ADD default A",
5938 .u.insns = {
5940 * A = A + 0x42
5941 * ret A
5943 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
5944 BPF_STMT(BPF_RET | BPF_A, 0x0),
5946 CLASSIC | FLAG_NO_DATA,
5948 { {0x1, 0x42 } },
5951 "SUB default X",
5952 .u.insns = {
5954 * A = 0x66
5955 * A = A - X
5956 * ret A
5958 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
5959 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
5960 BPF_STMT(BPF_RET | BPF_A, 0x0),
5962 CLASSIC | FLAG_NO_DATA,
5964 { {0x1, 0x66 } },
5967 "SUB default A",
5968 .u.insns = {
5970 * A = A - -0x66
5971 * ret A
5973 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
5974 BPF_STMT(BPF_RET | BPF_A, 0x0),
5976 CLASSIC | FLAG_NO_DATA,
5978 { {0x1, 0x66 } },
5981 "MUL default X",
5982 .u.insns = {
5984 * A = 0x42
5985 * A = A * X
5986 * ret A
5988 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5989 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
5990 BPF_STMT(BPF_RET | BPF_A, 0x0),
5992 CLASSIC | FLAG_NO_DATA,
5994 { {0x1, 0x0 } },
5997 "MUL default A",
5998 .u.insns = {
6000 * A = A * 0x66
6001 * ret A
6003 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
6004 BPF_STMT(BPF_RET | BPF_A, 0x0),
6006 CLASSIC | FLAG_NO_DATA,
6008 { {0x1, 0x0 } },
6011 "DIV default X",
6012 .u.insns = {
6014 * A = 0x42
6015 * A = A / X ; this halt the filter execution if X is 0
6016 * ret 0x42
6018 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6019 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
6020 BPF_STMT(BPF_RET | BPF_K, 0x42),
6022 CLASSIC | FLAG_NO_DATA,
6024 { {0x1, 0x0 } },
6027 "DIV default A",
6028 .u.insns = {
6030 * A = A / 1
6031 * ret A
6033 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
6034 BPF_STMT(BPF_RET | BPF_A, 0x0),
6036 CLASSIC | FLAG_NO_DATA,
6038 { {0x1, 0x0 } },
6041 "MOD default X",
6042 .u.insns = {
6044 * A = 0x42
6045 * A = A mod X ; this halt the filter execution if X is 0
6046 * ret 0x42
6048 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6049 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
6050 BPF_STMT(BPF_RET | BPF_K, 0x42),
6052 CLASSIC | FLAG_NO_DATA,
6054 { {0x1, 0x0 } },
6057 "MOD default A",
6058 .u.insns = {
6060 * A = A mod 1
6061 * ret A
6063 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
6064 BPF_STMT(BPF_RET | BPF_A, 0x0),
6066 CLASSIC | FLAG_NO_DATA,
6068 { {0x1, 0x0 } },
6071 "JMP EQ default A",
6072 .u.insns = {
6074 * cmp A, 0x0, 0, 1
6075 * ret 0x42
6076 * ret 0x66
6078 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
6079 BPF_STMT(BPF_RET | BPF_K, 0x42),
6080 BPF_STMT(BPF_RET | BPF_K, 0x66),
6082 CLASSIC | FLAG_NO_DATA,
6084 { {0x1, 0x42 } },
6087 "JMP EQ default X",
6088 .u.insns = {
6090 * A = 0x0
6091 * cmp A, X, 0, 1
6092 * ret 0x42
6093 * ret 0x66
6095 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
6096 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
6097 BPF_STMT(BPF_RET | BPF_K, 0x42),
6098 BPF_STMT(BPF_RET | BPF_K, 0x66),
6100 CLASSIC | FLAG_NO_DATA,
6102 { {0x1, 0x42 } },
6105 "LD_ABS with helper changing skb data",
6106 { },
6107 INTERNAL,
6108 { 0x34 },
6109 { { ETH_HLEN, 42 } },
6110 .fill_helper = bpf_fill_ld_abs_vlan_push_pop2,
6114 static struct net_device dev;
6116 static struct sk_buff *populate_skb(char *buf, int size)
6118 struct sk_buff *skb;
6120 if (size >= MAX_DATA)
6121 return NULL;
6123 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
6124 if (!skb)
6125 return NULL;
6127 __skb_put_data(skb, buf, size);
6129 /* Initialize a fake skb with test pattern. */
6130 skb_reset_mac_header(skb);
6131 skb->protocol = htons(ETH_P_IP);
6132 skb->pkt_type = SKB_TYPE;
6133 skb->mark = SKB_MARK;
6134 skb->hash = SKB_HASH;
6135 skb->queue_mapping = SKB_QUEUE_MAP;
6136 skb->vlan_tci = SKB_VLAN_TCI;
6137 skb->vlan_proto = htons(ETH_P_IP);
6138 skb->dev = &dev;
6139 skb->dev->ifindex = SKB_DEV_IFINDEX;
6140 skb->dev->type = SKB_DEV_TYPE;
6141 skb_set_network_header(skb, min(size, ETH_HLEN));
6143 return skb;
6146 static void *generate_test_data(struct bpf_test *test, int sub)
6148 struct sk_buff *skb;
6149 struct page *page;
6151 if (test->aux & FLAG_NO_DATA)
6152 return NULL;
6154 /* Test case expects an skb, so populate one. Various
6155 * subtests generate skbs of different sizes based on
6156 * the same data.
6158 skb = populate_skb(test->data, test->test[sub].data_size);
6159 if (!skb)
6160 return NULL;
6162 if (test->aux & FLAG_SKB_FRAG) {
6164 * when the test requires a fragmented skb, add a
6165 * single fragment to the skb, filled with
6166 * test->frag_data.
6168 void *ptr;
6170 page = alloc_page(GFP_KERNEL);
6172 if (!page)
6173 goto err_kfree_skb;
6175 ptr = kmap(page);
6176 if (!ptr)
6177 goto err_free_page;
6178 memcpy(ptr, test->frag_data, MAX_DATA);
6179 kunmap(page);
6180 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
6183 return skb;
6185 err_free_page:
6186 __free_page(page);
6187 err_kfree_skb:
6188 kfree_skb(skb);
6189 return NULL;
6192 static void release_test_data(const struct bpf_test *test, void *data)
6194 if (test->aux & FLAG_NO_DATA)
6195 return;
6197 kfree_skb(data);
6200 static int filter_length(int which)
6202 struct sock_filter *fp;
6203 int len;
6205 if (tests[which].fill_helper)
6206 return tests[which].u.ptr.len;
6208 fp = tests[which].u.insns;
6209 for (len = MAX_INSNS - 1; len > 0; --len)
6210 if (fp[len].code != 0 || fp[len].k != 0)
6211 break;
6213 return len + 1;
6216 static void *filter_pointer(int which)
6218 if (tests[which].fill_helper)
6219 return tests[which].u.ptr.insns;
6220 else
6221 return tests[which].u.insns;
6224 static struct bpf_prog *generate_filter(int which, int *err)
6226 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
6227 unsigned int flen = filter_length(which);
6228 void *fptr = filter_pointer(which);
6229 struct sock_fprog_kern fprog;
6230 struct bpf_prog *fp;
6232 switch (test_type) {
6233 case CLASSIC:
6234 fprog.filter = fptr;
6235 fprog.len = flen;
6237 *err = bpf_prog_create(&fp, &fprog);
6238 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
6239 if (*err == -EINVAL) {
6240 pr_cont("PASS\n");
6241 /* Verifier rejected filter as expected. */
6242 *err = 0;
6243 return NULL;
6244 } else {
6245 pr_cont("UNEXPECTED_PASS\n");
6246 /* Verifier didn't reject the test that's
6247 * bad enough, just return!
6249 *err = -EINVAL;
6250 return NULL;
6253 if (*err) {
6254 pr_cont("FAIL to prog_create err=%d len=%d\n",
6255 *err, fprog.len);
6256 return NULL;
6258 break;
6260 case INTERNAL:
6261 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
6262 if (fp == NULL) {
6263 pr_cont("UNEXPECTED_FAIL no memory left\n");
6264 *err = -ENOMEM;
6265 return NULL;
6268 fp->len = flen;
6269 /* Type doesn't really matter here as long as it's not unspec. */
6270 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
6271 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
6272 fp->aux->stack_depth = tests[which].stack_depth;
6274 /* We cannot error here as we don't need type compatibility
6275 * checks.
6277 fp = bpf_prog_select_runtime(fp, err);
6278 if (*err) {
6279 pr_cont("FAIL to select_runtime err=%d\n", *err);
6280 return NULL;
6282 break;
6285 *err = 0;
6286 return fp;
6289 static void release_filter(struct bpf_prog *fp, int which)
6291 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
6293 switch (test_type) {
6294 case CLASSIC:
6295 bpf_prog_destroy(fp);
6296 break;
6297 case INTERNAL:
6298 bpf_prog_free(fp);
6299 break;
6303 static int __run_one(const struct bpf_prog *fp, const void *data,
6304 int runs, u64 *duration)
6306 u64 start, finish;
6307 int ret = 0, i;
6309 start = ktime_get_ns();
6311 for (i = 0; i < runs; i++)
6312 ret = BPF_PROG_RUN(fp, data);
6314 finish = ktime_get_ns();
6316 *duration = finish - start;
6317 do_div(*duration, runs);
6319 return ret;
6322 static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
6324 int err_cnt = 0, i, runs = MAX_TESTRUNS;
6326 for (i = 0; i < MAX_SUBTESTS; i++) {
6327 void *data;
6328 u64 duration;
6329 u32 ret;
6331 if (test->test[i].data_size == 0 &&
6332 test->test[i].result == 0)
6333 break;
6335 data = generate_test_data(test, i);
6336 if (!data && !(test->aux & FLAG_NO_DATA)) {
6337 pr_cont("data generation failed ");
6338 err_cnt++;
6339 break;
6341 ret = __run_one(fp, data, runs, &duration);
6342 release_test_data(test, data);
6344 if (ret == test->test[i].result) {
6345 pr_cont("%lld ", duration);
6346 } else {
6347 pr_cont("ret %d != %d ", ret,
6348 test->test[i].result);
6349 err_cnt++;
6353 return err_cnt;
6356 static char test_name[64];
6357 module_param_string(test_name, test_name, sizeof(test_name), 0);
6359 static int test_id = -1;
6360 module_param(test_id, int, 0);
6362 static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
6363 module_param_array(test_range, int, NULL, 0);
6365 static __init int find_test_index(const char *test_name)
6367 int i;
6369 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6370 if (!strcmp(tests[i].descr, test_name))
6371 return i;
6373 return -1;
6376 static __init int prepare_bpf_tests(void)
6378 int i;
6380 if (test_id >= 0) {
6382 * if a test_id was specified, use test_range to
6383 * cover only that test.
6385 if (test_id >= ARRAY_SIZE(tests)) {
6386 pr_err("test_bpf: invalid test_id specified.\n");
6387 return -EINVAL;
6390 test_range[0] = test_id;
6391 test_range[1] = test_id;
6392 } else if (*test_name) {
6394 * if a test_name was specified, find it and setup
6395 * test_range to cover only that test.
6397 int idx = find_test_index(test_name);
6399 if (idx < 0) {
6400 pr_err("test_bpf: no test named '%s' found.\n",
6401 test_name);
6402 return -EINVAL;
6404 test_range[0] = idx;
6405 test_range[1] = idx;
6406 } else {
6408 * check that the supplied test_range is valid.
6410 if (test_range[0] >= ARRAY_SIZE(tests) ||
6411 test_range[1] >= ARRAY_SIZE(tests) ||
6412 test_range[0] < 0 || test_range[1] < 0) {
6413 pr_err("test_bpf: test_range is out of bound.\n");
6414 return -EINVAL;
6417 if (test_range[1] < test_range[0]) {
6418 pr_err("test_bpf: test_range is ending before it starts.\n");
6419 return -EINVAL;
6423 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6424 if (tests[i].fill_helper &&
6425 tests[i].fill_helper(&tests[i]) < 0)
6426 return -ENOMEM;
6429 return 0;
6432 static __init void destroy_bpf_tests(void)
6434 int i;
6436 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6437 if (tests[i].fill_helper)
6438 kfree(tests[i].u.ptr.insns);
6442 static bool exclude_test(int test_id)
6444 return test_id < test_range[0] || test_id > test_range[1];
6447 static __init int test_bpf(void)
6449 int i, err_cnt = 0, pass_cnt = 0;
6450 int jit_cnt = 0, run_cnt = 0;
6452 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6453 struct bpf_prog *fp;
6454 int err;
6456 if (exclude_test(i))
6457 continue;
6459 pr_info("#%d %s ", i, tests[i].descr);
6461 fp = generate_filter(i, &err);
6462 if (fp == NULL) {
6463 if (err == 0) {
6464 pass_cnt++;
6465 continue;
6467 err_cnt++;
6468 continue;
6471 pr_cont("jited:%u ", fp->jited);
6473 run_cnt++;
6474 if (fp->jited)
6475 jit_cnt++;
6477 err = run_one(fp, &tests[i]);
6478 release_filter(fp, i);
6480 if (err) {
6481 pr_cont("FAIL (%d times)\n", err);
6482 err_cnt++;
6483 } else {
6484 pr_cont("PASS\n");
6485 pass_cnt++;
6489 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6490 pass_cnt, err_cnt, jit_cnt, run_cnt);
6492 return err_cnt ? -EINVAL : 0;
6495 static int __init test_bpf_init(void)
6497 int ret;
6499 ret = prepare_bpf_tests();
6500 if (ret < 0)
6501 return ret;
6503 ret = test_bpf();
6505 destroy_bpf_tests();
6506 return ret;
6509 static void __exit test_bpf_exit(void)
6513 module_init(test_bpf_init);
6514 module_exit(test_bpf_exit);
6516 MODULE_LICENSE("GPL");