1 // SPDX-License-Identifier: GPL-2.0-only
3 * Testsuite for BPF interpreter and BPF JIT compiler
5 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/filter.h>
13 #include <linux/bpf.h>
14 #include <linux/skbuff.h>
15 #include <linux/netdevice.h>
16 #include <linux/if_vlan.h>
17 #include <linux/random.h>
18 #include <linux/highmem.h>
19 #include <linux/sched.h>
21 /* General test specific settings */
22 #define MAX_SUBTESTS 3
23 #define MAX_TESTRUNS 1000
26 #define MAX_K 0xffffFFFF
28 /* Few constants used to init test 'skb' */
30 #define SKB_MARK 0x1234aaaa
31 #define SKB_HASH 0x1234aaab
32 #define SKB_QUEUE_MAP 123
33 #define SKB_VLAN_TCI 0xffff
34 #define SKB_VLAN_PRESENT 1
35 #define SKB_DEV_IFINDEX 577
36 #define SKB_DEV_TYPE 588
38 /* Redefine REGs to make tests less verbose */
49 #define R10 BPF_REG_10
51 /* Flags that can be passed to test cases */
52 #define FLAG_NO_DATA BIT(0)
53 #define FLAG_EXPECTED_FAIL BIT(1)
54 #define FLAG_SKB_FRAG BIT(2)
57 CLASSIC = BIT(6), /* Old BPF instructions only. */
58 INTERNAL = BIT(7), /* Extended instruction set. */
61 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
66 struct sock_filter insns[MAX_INSNS];
67 struct bpf_insn insns_int[MAX_INSNS];
79 int (*fill_helper)(struct bpf_test *self);
80 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
81 __u8 frag_data[MAX_DATA];
82 int stack_depth; /* for eBPF only, since tests don't call verifier */
85 /* Large test cases need separate allocation and fill handler. */
87 static int bpf_fill_maxinsns1(struct bpf_test *self)
89 unsigned int len = BPF_MAXINSNS;
90 struct sock_filter *insn;
94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
98 for (i = 0; i < len; i++, k--)
99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
101 self->u.ptr.insns = insn;
102 self->u.ptr.len = len;
107 static int bpf_fill_maxinsns2(struct bpf_test *self)
109 unsigned int len = BPF_MAXINSNS;
110 struct sock_filter *insn;
113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
117 for (i = 0; i < len; i++)
118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
120 self->u.ptr.insns = insn;
121 self->u.ptr.len = len;
126 static int bpf_fill_maxinsns3(struct bpf_test *self)
128 unsigned int len = BPF_MAXINSNS;
129 struct sock_filter *insn;
130 struct rnd_state rnd;
133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
137 prandom_seed_state(&rnd, 3141592653589793238ULL);
139 for (i = 0; i < len - 1; i++) {
140 __u32 k = prandom_u32_state(&rnd);
142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
147 self->u.ptr.insns = insn;
148 self->u.ptr.len = len;
153 static int bpf_fill_maxinsns4(struct bpf_test *self)
155 unsigned int len = BPF_MAXINSNS + 1;
156 struct sock_filter *insn;
159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
163 for (i = 0; i < len; i++)
164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
166 self->u.ptr.insns = insn;
167 self->u.ptr.len = len;
172 static int bpf_fill_maxinsns5(struct bpf_test *self)
174 unsigned int len = BPF_MAXINSNS;
175 struct sock_filter *insn;
178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
184 for (i = 1; i < len - 1; i++)
185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
189 self->u.ptr.insns = insn;
190 self->u.ptr.len = len;
195 static int bpf_fill_maxinsns6(struct bpf_test *self)
197 unsigned int len = BPF_MAXINSNS;
198 struct sock_filter *insn;
201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
205 for (i = 0; i < len - 1; i++)
206 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
207 SKF_AD_VLAN_TAG_PRESENT);
209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
211 self->u.ptr.insns = insn;
212 self->u.ptr.len = len;
217 static int bpf_fill_maxinsns7(struct bpf_test *self)
219 unsigned int len = BPF_MAXINSNS;
220 struct sock_filter *insn;
223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
227 for (i = 0; i < len - 4; i++)
228 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
231 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
232 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
235 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
237 self->u.ptr.insns = insn;
238 self->u.ptr.len = len;
243 static int bpf_fill_maxinsns8(struct bpf_test *self)
245 unsigned int len = BPF_MAXINSNS;
246 struct sock_filter *insn;
247 int i, jmp_off = len - 3;
249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
255 for (i = 1; i < len - 1; i++)
256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
260 self->u.ptr.insns = insn;
261 self->u.ptr.len = len;
266 static int bpf_fill_maxinsns9(struct bpf_test *self)
268 unsigned int len = BPF_MAXINSNS;
269 struct bpf_insn *insn;
272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
276 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
277 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
278 insn[2] = BPF_EXIT_INSN();
280 for (i = 3; i < len - 2; i++)
281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
283 insn[len - 2] = BPF_EXIT_INSN();
284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
286 self->u.ptr.insns = insn;
287 self->u.ptr.len = len;
292 static int bpf_fill_maxinsns10(struct bpf_test *self)
294 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
295 struct bpf_insn *insn;
298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
302 for (i = 0; i < hlen / 2; i++)
303 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
304 for (i = hlen - 1; i > hlen / 2; i--)
305 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
307 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
308 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
309 insn[hlen + 1] = BPF_EXIT_INSN();
311 self->u.ptr.insns = insn;
312 self->u.ptr.len = len;
317 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
320 struct sock_filter *insn;
324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
328 rlen = (len % plen) - 1;
330 for (i = 0; i + plen < len; i += plen)
331 for (j = 0; j < plen; j++)
332 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
334 for (j = 0; j < rlen; j++)
335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
340 self->u.ptr.insns = insn;
341 self->u.ptr.len = len;
346 static int bpf_fill_maxinsns11(struct bpf_test *self)
348 /* Hits 70 passes on x86_64 and triggers NOPs padding. */
349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
352 static int bpf_fill_maxinsns12(struct bpf_test *self)
354 unsigned int len = BPF_MAXINSNS;
355 struct sock_filter *insn;
358 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
362 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
364 for (i = 1; i < len - 1; i++)
365 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
367 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
369 self->u.ptr.insns = insn;
370 self->u.ptr.len = len;
375 static int bpf_fill_maxinsns13(struct bpf_test *self)
377 unsigned int len = BPF_MAXINSNS;
378 struct sock_filter *insn;
381 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
385 for (i = 0; i < len - 3; i++)
386 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
388 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
389 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
390 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
392 self->u.ptr.insns = insn;
393 self->u.ptr.len = len;
398 static int bpf_fill_ja(struct bpf_test *self)
400 /* Hits exactly 11 passes on x86_64 JIT. */
401 return __bpf_fill_ja(self, 12, 9);
404 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
406 unsigned int len = BPF_MAXINSNS;
407 struct sock_filter *insn;
410 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
414 for (i = 0; i < len - 1; i += 2) {
415 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
416 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
417 SKF_AD_OFF + SKF_AD_CPU);
420 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
422 self->u.ptr.insns = insn;
423 self->u.ptr.len = len;
428 static int __bpf_fill_stxdw(struct bpf_test *self, int size)
430 unsigned int len = BPF_MAXINSNS;
431 struct bpf_insn *insn;
434 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
438 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
439 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
441 for (i = 2; i < len - 2; i++)
442 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
444 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
445 insn[len - 1] = BPF_EXIT_INSN();
447 self->u.ptr.insns = insn;
448 self->u.ptr.len = len;
449 self->stack_depth = 40;
454 static int bpf_fill_stxw(struct bpf_test *self)
456 return __bpf_fill_stxdw(self, BPF_W);
459 static int bpf_fill_stxdw(struct bpf_test *self)
461 return __bpf_fill_stxdw(self, BPF_DW);
464 static int bpf_fill_long_jmp(struct bpf_test *self)
466 unsigned int len = BPF_MAXINSNS;
467 struct bpf_insn *insn;
470 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
474 insn[0] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
475 insn[1] = BPF_JMP_IMM(BPF_JEQ, R0, 1, len - 2 - 1);
478 * Fill with a complex 64-bit operation that expands to a lot of
479 * instructions on 32-bit JITs. The large jump offset can then
480 * overflow the conditional branch field size, triggering a branch
481 * conversion mechanism in some JITs.
483 * Note: BPF_MAXINSNS of ALU64 MUL is enough to trigger such branch
484 * conversion on the 32-bit MIPS JIT. For other JITs, the instruction
485 * count and/or operation may need to be modified to trigger the
488 for (i = 2; i < len - 1; i++)
489 insn[i] = BPF_ALU64_IMM(BPF_MUL, R0, (i << 16) + i);
491 insn[len - 1] = BPF_EXIT_INSN();
493 self->u.ptr.insns = insn;
494 self->u.ptr.len = len;
499 static struct bpf_test tests[] = {
503 BPF_STMT(BPF_LD | BPF_IMM, 1),
504 BPF_STMT(BPF_MISC | BPF_TAX, 0),
505 BPF_STMT(BPF_LD | BPF_IMM, 2),
506 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
507 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
508 BPF_STMT(BPF_MISC | BPF_TAX, 0),
509 BPF_STMT(BPF_LD | BPF_LEN, 0),
510 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
511 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
512 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
513 BPF_STMT(BPF_RET | BPF_A, 0)
516 { 10, 20, 30, 40, 50 },
517 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
522 BPF_STMT(BPF_LDX | BPF_LEN, 0),
523 BPF_STMT(BPF_MISC | BPF_TXA, 0),
524 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
525 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
528 { 10, 20, 30, 40, 50 },
529 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
534 BPF_STMT(BPF_LD | BPF_IMM, 1),
535 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
536 BPF_STMT(BPF_LDX | BPF_IMM, 3),
537 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
538 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
539 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
540 BPF_STMT(BPF_RET | BPF_A, 0)
542 CLASSIC | FLAG_NO_DATA,
544 { { 0, 0xfffffffd } }
549 BPF_STMT(BPF_LD | BPF_IMM, 8),
550 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
551 BPF_STMT(BPF_MISC | BPF_TAX, 0),
552 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
553 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
554 BPF_STMT(BPF_MISC | BPF_TAX, 0),
555 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
556 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
557 BPF_STMT(BPF_MISC | BPF_TAX, 0),
558 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
559 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
560 BPF_STMT(BPF_MISC | BPF_TAX, 0),
561 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
562 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
563 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
564 BPF_STMT(BPF_RET | BPF_A, 0)
566 CLASSIC | FLAG_NO_DATA,
568 { { 0, 0x20000000 } }
573 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
574 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
575 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
576 BPF_STMT(BPF_MISC | BPF_TAX, 0),
577 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
578 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
579 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
580 BPF_STMT(BPF_RET | BPF_A, 0)
582 CLASSIC | FLAG_NO_DATA,
584 { { 0, 0x800000ff }, { 1, 0x800000ff } },
589 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
591 BPF_STMT(BPF_RET | BPF_K, 0),
592 BPF_STMT(BPF_RET | BPF_K, 1),
601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
603 BPF_STMT(BPF_RET | BPF_K, 1)
607 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
612 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
613 BPF_STMT(BPF_RET | BPF_K, 1)
617 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
622 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
623 BPF_STMT(BPF_MISC | BPF_TAX, 0),
624 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
625 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
626 BPF_STMT(BPF_RET | BPF_A, 0)
630 { { 1, 0 }, { 2, 3 } },
635 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
636 BPF_STMT(BPF_LDX | BPF_LEN, 0),
637 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
638 BPF_STMT(BPF_MISC | BPF_TAX, 0),
639 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
640 BPF_STMT(BPF_RET | BPF_A, 0)
644 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
649 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
650 BPF_STMT(BPF_MISC | BPF_TAX, 0),
651 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
652 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
653 BPF_STMT(BPF_RET | BPF_A, 0)
656 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
657 { { 15, 0 }, { 16, 3 } },
662 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
663 BPF_STMT(BPF_LDX | BPF_LEN, 0),
664 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
665 BPF_STMT(BPF_MISC | BPF_TAX, 0),
666 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
667 BPF_STMT(BPF_RET | BPF_A, 0)
670 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
671 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
676 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
677 SKF_AD_OFF + SKF_AD_PKTTYPE),
678 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
679 BPF_STMT(BPF_RET | BPF_K, 1),
680 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
681 SKF_AD_OFF + SKF_AD_PKTTYPE),
682 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
683 BPF_STMT(BPF_RET | BPF_K, 1),
684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_PKTTYPE),
686 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
687 BPF_STMT(BPF_RET | BPF_K, 1),
688 BPF_STMT(BPF_RET | BPF_A, 0)
692 { { 1, 3 }, { 10, 3 } },
697 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
698 SKF_AD_OFF + SKF_AD_MARK),
699 BPF_STMT(BPF_RET | BPF_A, 0)
703 { { 1, SKB_MARK}, { 10, SKB_MARK} },
708 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
709 SKF_AD_OFF + SKF_AD_RXHASH),
710 BPF_STMT(BPF_RET | BPF_A, 0)
714 { { 1, SKB_HASH}, { 10, SKB_HASH} },
719 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
720 SKF_AD_OFF + SKF_AD_QUEUE),
721 BPF_STMT(BPF_RET | BPF_A, 0)
725 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
730 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
731 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
732 BPF_STMT(BPF_RET | BPF_K, 0),
733 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
734 SKF_AD_OFF + SKF_AD_PROTOCOL),
735 BPF_STMT(BPF_MISC | BPF_TAX, 0),
736 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
737 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
738 BPF_STMT(BPF_RET | BPF_K, 0),
739 BPF_STMT(BPF_MISC | BPF_TXA, 0),
740 BPF_STMT(BPF_RET | BPF_A, 0)
744 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
749 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
750 SKF_AD_OFF + SKF_AD_VLAN_TAG),
751 BPF_STMT(BPF_RET | BPF_A, 0)
761 "LD_VLAN_TAG_PRESENT",
763 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
764 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
765 BPF_STMT(BPF_RET | BPF_A, 0)
770 { 1, SKB_VLAN_PRESENT },
771 { 10, SKB_VLAN_PRESENT }
777 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
778 SKF_AD_OFF + SKF_AD_IFINDEX),
779 BPF_STMT(BPF_RET | BPF_A, 0)
783 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
788 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
789 SKF_AD_OFF + SKF_AD_HATYPE),
790 BPF_STMT(BPF_RET | BPF_A, 0)
794 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
799 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
800 SKF_AD_OFF + SKF_AD_CPU),
801 BPF_STMT(BPF_MISC | BPF_TAX, 0),
802 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
803 SKF_AD_OFF + SKF_AD_CPU),
804 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
805 BPF_STMT(BPF_RET | BPF_A, 0)
809 { { 1, 0 }, { 10, 0 } },
814 BPF_STMT(BPF_LDX | BPF_IMM, 2),
815 BPF_STMT(BPF_MISC | BPF_TXA, 0),
816 BPF_STMT(BPF_LDX | BPF_IMM, 3),
817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_NLATTR),
819 BPF_STMT(BPF_RET | BPF_A, 0)
823 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
825 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
827 { { 4, 0 }, { 20, 6 } },
832 BPF_STMT(BPF_LD | BPF_IMM, 2),
833 BPF_STMT(BPF_LDX | BPF_IMM, 3),
834 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
835 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
836 BPF_STMT(BPF_LD | BPF_IMM, 2),
837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
839 BPF_STMT(BPF_LD | BPF_IMM, 2),
840 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
841 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
842 BPF_STMT(BPF_LD | BPF_IMM, 2),
843 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
844 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
845 BPF_STMT(BPF_LD | BPF_IMM, 2),
846 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
847 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
848 BPF_STMT(BPF_LD | BPF_IMM, 2),
849 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
850 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
851 BPF_STMT(BPF_LD | BPF_IMM, 2),
852 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
853 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
854 BPF_STMT(BPF_LD | BPF_IMM, 2),
855 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
856 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
857 BPF_STMT(BPF_RET | BPF_A, 0)
861 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
863 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
865 { { 4, 0 }, { 20, 10 } },
870 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
871 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
872 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
873 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
874 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
875 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
876 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
877 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
878 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
879 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
880 BPF_STMT(BPF_RET | BPF_A, 0)
883 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
884 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
885 * id 9737, seq 1, length 64
887 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
890 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
891 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
892 { { 30, 0 }, { 100, 42 } },
897 BPF_STMT(BPF_LD | BPF_IMM, 10),
898 BPF_STMT(BPF_LDX | BPF_IMM, 300),
899 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
900 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
901 BPF_STMT(BPF_RET | BPF_A, 0)
905 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
910 BPF_STMT(BPF_LDX | BPF_LEN, 0),
911 BPF_STMT(BPF_LD | BPF_IMM, 2),
912 BPF_STMT(BPF_ALU | BPF_RSH, 1),
913 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
914 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
915 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
916 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
917 BPF_STMT(BPF_STX, 15), /* M3 = len */
918 BPF_STMT(BPF_LDX | BPF_MEM, 1),
919 BPF_STMT(BPF_LD | BPF_MEM, 2),
920 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
921 BPF_STMT(BPF_LDX | BPF_MEM, 15),
922 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
923 BPF_STMT(BPF_RET | BPF_A, 0)
927 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
932 BPF_STMT(BPF_LDX | BPF_LEN, 0),
933 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
934 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
935 BPF_STMT(BPF_RET | BPF_K, 1),
936 BPF_STMT(BPF_RET | BPF_K, MAX_K)
940 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
945 BPF_STMT(BPF_LDX | BPF_LEN, 0),
946 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
947 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
948 BPF_STMT(BPF_RET | BPF_K, 1),
949 BPF_STMT(BPF_RET | BPF_K, MAX_K)
953 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
956 "JGE (jt 0), test 1",
958 BPF_STMT(BPF_LDX | BPF_LEN, 0),
959 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
960 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
961 BPF_STMT(BPF_RET | BPF_K, 1),
962 BPF_STMT(BPF_RET | BPF_K, MAX_K)
966 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
969 "JGE (jt 0), test 2",
971 BPF_STMT(BPF_LDX | BPF_LEN, 0),
972 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
973 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
974 BPF_STMT(BPF_RET | BPF_K, 1),
975 BPF_STMT(BPF_RET | BPF_K, MAX_K)
979 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
984 BPF_STMT(BPF_LDX | BPF_LEN, 0),
985 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
986 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
987 BPF_STMT(BPF_RET | BPF_K, 10),
988 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
989 BPF_STMT(BPF_RET | BPF_K, 20),
990 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
991 BPF_STMT(BPF_RET | BPF_K, 30),
992 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
993 BPF_STMT(BPF_RET | BPF_K, 40),
994 BPF_STMT(BPF_RET | BPF_K, MAX_K)
998 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
1003 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1004 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
1005 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1006 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1007 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1008 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1009 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
1010 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1011 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
1012 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
1013 BPF_STMT(BPF_RET | BPF_K, 10),
1014 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
1015 BPF_STMT(BPF_RET | BPF_K, 20),
1016 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1017 BPF_STMT(BPF_RET | BPF_K, 30),
1018 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1019 BPF_STMT(BPF_RET | BPF_K, 30),
1020 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1021 BPF_STMT(BPF_RET | BPF_K, 30),
1022 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1023 BPF_STMT(BPF_RET | BPF_K, 30),
1024 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1025 BPF_STMT(BPF_RET | BPF_K, 30),
1026 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1029 { 0, 0xAA, 0x55, 1 },
1030 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
1035 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1036 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1037 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1038 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1039 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1040 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1041 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1042 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1043 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1044 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1045 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1046 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1047 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1048 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1049 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1050 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1051 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1052 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1053 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1054 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1055 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1056 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1057 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1058 BPF_STMT(BPF_RET | BPF_K, 0),
1061 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1062 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1063 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1064 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1066 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1067 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1069 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1070 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1071 0x0a, 0x01, 0x01, 0x95, /* ip src */
1072 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1074 0x00, 0x16 /* dst port */ },
1075 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1080 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1081 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1082 * (len > 115 or len < 30000000000)' -d
1084 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1085 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1086 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1087 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1088 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1089 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1090 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1091 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1092 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1093 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1094 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1095 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1096 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1097 BPF_STMT(BPF_ST, 1),
1098 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1099 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1100 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1101 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1102 BPF_STMT(BPF_LD | BPF_MEM, 1),
1103 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1104 BPF_STMT(BPF_ST, 5),
1105 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1106 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1107 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1108 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1109 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1110 BPF_STMT(BPF_LD | BPF_MEM, 5),
1111 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1112 BPF_STMT(BPF_LD | BPF_LEN, 0),
1113 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1114 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1115 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1116 BPF_STMT(BPF_RET | BPF_K, 0),
1119 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1120 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1122 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1123 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1124 0x0a, 0x01, 0x01, 0x95, /* ip src */
1125 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1127 0x00, 0x16 /* dst port */ },
1128 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1133 /* check that uninitialized X and A contain zeros */
1134 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1135 BPF_STMT(BPF_RET | BPF_A, 0)
1144 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1145 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1146 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1147 BPF_ALU64_REG(BPF_SUB, R1, R2),
1148 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1149 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1150 BPF_ALU64_REG(BPF_MOV, R0, R1),
1155 { { 0, 0xfffffffd } }
1160 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1161 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1162 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1163 BPF_ALU64_REG(BPF_MUL, R1, R2),
1164 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1166 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1176 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1177 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1178 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1179 BPF_ALU64_REG(BPF_MUL, R1, R2),
1180 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1181 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1183 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1193 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1194 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1195 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1196 BPF_ALU32_REG(BPF_MUL, R1, R2),
1197 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1198 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1200 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1208 /* Have to test all register combinations, since
1209 * JITing of different registers will produce
1210 * different asm code.
1214 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1215 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1216 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1217 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1218 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1219 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1220 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1221 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1222 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1223 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1224 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1225 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1226 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1227 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1228 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1229 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1230 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1231 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1232 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1233 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1234 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1235 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1236 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1237 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1238 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1239 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1240 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1241 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1242 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1243 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1244 BPF_ALU64_REG(BPF_ADD, R0, R0),
1245 BPF_ALU64_REG(BPF_ADD, R0, R1),
1246 BPF_ALU64_REG(BPF_ADD, R0, R2),
1247 BPF_ALU64_REG(BPF_ADD, R0, R3),
1248 BPF_ALU64_REG(BPF_ADD, R0, R4),
1249 BPF_ALU64_REG(BPF_ADD, R0, R5),
1250 BPF_ALU64_REG(BPF_ADD, R0, R6),
1251 BPF_ALU64_REG(BPF_ADD, R0, R7),
1252 BPF_ALU64_REG(BPF_ADD, R0, R8),
1253 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1254 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1256 BPF_ALU64_REG(BPF_ADD, R1, R0),
1257 BPF_ALU64_REG(BPF_ADD, R1, R1),
1258 BPF_ALU64_REG(BPF_ADD, R1, R2),
1259 BPF_ALU64_REG(BPF_ADD, R1, R3),
1260 BPF_ALU64_REG(BPF_ADD, R1, R4),
1261 BPF_ALU64_REG(BPF_ADD, R1, R5),
1262 BPF_ALU64_REG(BPF_ADD, R1, R6),
1263 BPF_ALU64_REG(BPF_ADD, R1, R7),
1264 BPF_ALU64_REG(BPF_ADD, R1, R8),
1265 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1266 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1268 BPF_ALU64_REG(BPF_ADD, R2, R0),
1269 BPF_ALU64_REG(BPF_ADD, R2, R1),
1270 BPF_ALU64_REG(BPF_ADD, R2, R2),
1271 BPF_ALU64_REG(BPF_ADD, R2, R3),
1272 BPF_ALU64_REG(BPF_ADD, R2, R4),
1273 BPF_ALU64_REG(BPF_ADD, R2, R5),
1274 BPF_ALU64_REG(BPF_ADD, R2, R6),
1275 BPF_ALU64_REG(BPF_ADD, R2, R7),
1276 BPF_ALU64_REG(BPF_ADD, R2, R8),
1277 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1278 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1280 BPF_ALU64_REG(BPF_ADD, R3, R0),
1281 BPF_ALU64_REG(BPF_ADD, R3, R1),
1282 BPF_ALU64_REG(BPF_ADD, R3, R2),
1283 BPF_ALU64_REG(BPF_ADD, R3, R3),
1284 BPF_ALU64_REG(BPF_ADD, R3, R4),
1285 BPF_ALU64_REG(BPF_ADD, R3, R5),
1286 BPF_ALU64_REG(BPF_ADD, R3, R6),
1287 BPF_ALU64_REG(BPF_ADD, R3, R7),
1288 BPF_ALU64_REG(BPF_ADD, R3, R8),
1289 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1290 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1292 BPF_ALU64_REG(BPF_ADD, R4, R0),
1293 BPF_ALU64_REG(BPF_ADD, R4, R1),
1294 BPF_ALU64_REG(BPF_ADD, R4, R2),
1295 BPF_ALU64_REG(BPF_ADD, R4, R3),
1296 BPF_ALU64_REG(BPF_ADD, R4, R4),
1297 BPF_ALU64_REG(BPF_ADD, R4, R5),
1298 BPF_ALU64_REG(BPF_ADD, R4, R6),
1299 BPF_ALU64_REG(BPF_ADD, R4, R7),
1300 BPF_ALU64_REG(BPF_ADD, R4, R8),
1301 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1302 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1304 BPF_ALU64_REG(BPF_ADD, R5, R0),
1305 BPF_ALU64_REG(BPF_ADD, R5, R1),
1306 BPF_ALU64_REG(BPF_ADD, R5, R2),
1307 BPF_ALU64_REG(BPF_ADD, R5, R3),
1308 BPF_ALU64_REG(BPF_ADD, R5, R4),
1309 BPF_ALU64_REG(BPF_ADD, R5, R5),
1310 BPF_ALU64_REG(BPF_ADD, R5, R6),
1311 BPF_ALU64_REG(BPF_ADD, R5, R7),
1312 BPF_ALU64_REG(BPF_ADD, R5, R8),
1313 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1314 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1316 BPF_ALU64_REG(BPF_ADD, R6, R0),
1317 BPF_ALU64_REG(BPF_ADD, R6, R1),
1318 BPF_ALU64_REG(BPF_ADD, R6, R2),
1319 BPF_ALU64_REG(BPF_ADD, R6, R3),
1320 BPF_ALU64_REG(BPF_ADD, R6, R4),
1321 BPF_ALU64_REG(BPF_ADD, R6, R5),
1322 BPF_ALU64_REG(BPF_ADD, R6, R6),
1323 BPF_ALU64_REG(BPF_ADD, R6, R7),
1324 BPF_ALU64_REG(BPF_ADD, R6, R8),
1325 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1326 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1328 BPF_ALU64_REG(BPF_ADD, R7, R0),
1329 BPF_ALU64_REG(BPF_ADD, R7, R1),
1330 BPF_ALU64_REG(BPF_ADD, R7, R2),
1331 BPF_ALU64_REG(BPF_ADD, R7, R3),
1332 BPF_ALU64_REG(BPF_ADD, R7, R4),
1333 BPF_ALU64_REG(BPF_ADD, R7, R5),
1334 BPF_ALU64_REG(BPF_ADD, R7, R6),
1335 BPF_ALU64_REG(BPF_ADD, R7, R7),
1336 BPF_ALU64_REG(BPF_ADD, R7, R8),
1337 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1338 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1340 BPF_ALU64_REG(BPF_ADD, R8, R0),
1341 BPF_ALU64_REG(BPF_ADD, R8, R1),
1342 BPF_ALU64_REG(BPF_ADD, R8, R2),
1343 BPF_ALU64_REG(BPF_ADD, R8, R3),
1344 BPF_ALU64_REG(BPF_ADD, R8, R4),
1345 BPF_ALU64_REG(BPF_ADD, R8, R5),
1346 BPF_ALU64_REG(BPF_ADD, R8, R6),
1347 BPF_ALU64_REG(BPF_ADD, R8, R7),
1348 BPF_ALU64_REG(BPF_ADD, R8, R8),
1349 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1350 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1352 BPF_ALU64_REG(BPF_ADD, R9, R0),
1353 BPF_ALU64_REG(BPF_ADD, R9, R1),
1354 BPF_ALU64_REG(BPF_ADD, R9, R2),
1355 BPF_ALU64_REG(BPF_ADD, R9, R3),
1356 BPF_ALU64_REG(BPF_ADD, R9, R4),
1357 BPF_ALU64_REG(BPF_ADD, R9, R5),
1358 BPF_ALU64_REG(BPF_ADD, R9, R6),
1359 BPF_ALU64_REG(BPF_ADD, R9, R7),
1360 BPF_ALU64_REG(BPF_ADD, R9, R8),
1361 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1362 BPF_ALU64_REG(BPF_MOV, R0, R9),
1372 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1373 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1374 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1375 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1376 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1377 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1378 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1379 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1380 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1381 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1382 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1383 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1384 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1385 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1386 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1387 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1388 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1389 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1390 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1391 BPF_ALU32_REG(BPF_ADD, R0, R1),
1392 BPF_ALU32_REG(BPF_ADD, R0, R2),
1393 BPF_ALU32_REG(BPF_ADD, R0, R3),
1394 BPF_ALU32_REG(BPF_ADD, R0, R4),
1395 BPF_ALU32_REG(BPF_ADD, R0, R5),
1396 BPF_ALU32_REG(BPF_ADD, R0, R6),
1397 BPF_ALU32_REG(BPF_ADD, R0, R7),
1398 BPF_ALU32_REG(BPF_ADD, R0, R8),
1399 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1400 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1402 BPF_ALU32_REG(BPF_ADD, R1, R0),
1403 BPF_ALU32_REG(BPF_ADD, R1, R1),
1404 BPF_ALU32_REG(BPF_ADD, R1, R2),
1405 BPF_ALU32_REG(BPF_ADD, R1, R3),
1406 BPF_ALU32_REG(BPF_ADD, R1, R4),
1407 BPF_ALU32_REG(BPF_ADD, R1, R5),
1408 BPF_ALU32_REG(BPF_ADD, R1, R6),
1409 BPF_ALU32_REG(BPF_ADD, R1, R7),
1410 BPF_ALU32_REG(BPF_ADD, R1, R8),
1411 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1412 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1414 BPF_ALU32_REG(BPF_ADD, R2, R0),
1415 BPF_ALU32_REG(BPF_ADD, R2, R1),
1416 BPF_ALU32_REG(BPF_ADD, R2, R2),
1417 BPF_ALU32_REG(BPF_ADD, R2, R3),
1418 BPF_ALU32_REG(BPF_ADD, R2, R4),
1419 BPF_ALU32_REG(BPF_ADD, R2, R5),
1420 BPF_ALU32_REG(BPF_ADD, R2, R6),
1421 BPF_ALU32_REG(BPF_ADD, R2, R7),
1422 BPF_ALU32_REG(BPF_ADD, R2, R8),
1423 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1424 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1426 BPF_ALU32_REG(BPF_ADD, R3, R0),
1427 BPF_ALU32_REG(BPF_ADD, R3, R1),
1428 BPF_ALU32_REG(BPF_ADD, R3, R2),
1429 BPF_ALU32_REG(BPF_ADD, R3, R3),
1430 BPF_ALU32_REG(BPF_ADD, R3, R4),
1431 BPF_ALU32_REG(BPF_ADD, R3, R5),
1432 BPF_ALU32_REG(BPF_ADD, R3, R6),
1433 BPF_ALU32_REG(BPF_ADD, R3, R7),
1434 BPF_ALU32_REG(BPF_ADD, R3, R8),
1435 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1436 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1438 BPF_ALU32_REG(BPF_ADD, R4, R0),
1439 BPF_ALU32_REG(BPF_ADD, R4, R1),
1440 BPF_ALU32_REG(BPF_ADD, R4, R2),
1441 BPF_ALU32_REG(BPF_ADD, R4, R3),
1442 BPF_ALU32_REG(BPF_ADD, R4, R4),
1443 BPF_ALU32_REG(BPF_ADD, R4, R5),
1444 BPF_ALU32_REG(BPF_ADD, R4, R6),
1445 BPF_ALU32_REG(BPF_ADD, R4, R7),
1446 BPF_ALU32_REG(BPF_ADD, R4, R8),
1447 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1448 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1450 BPF_ALU32_REG(BPF_ADD, R5, R0),
1451 BPF_ALU32_REG(BPF_ADD, R5, R1),
1452 BPF_ALU32_REG(BPF_ADD, R5, R2),
1453 BPF_ALU32_REG(BPF_ADD, R5, R3),
1454 BPF_ALU32_REG(BPF_ADD, R5, R4),
1455 BPF_ALU32_REG(BPF_ADD, R5, R5),
1456 BPF_ALU32_REG(BPF_ADD, R5, R6),
1457 BPF_ALU32_REG(BPF_ADD, R5, R7),
1458 BPF_ALU32_REG(BPF_ADD, R5, R8),
1459 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1460 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1462 BPF_ALU32_REG(BPF_ADD, R6, R0),
1463 BPF_ALU32_REG(BPF_ADD, R6, R1),
1464 BPF_ALU32_REG(BPF_ADD, R6, R2),
1465 BPF_ALU32_REG(BPF_ADD, R6, R3),
1466 BPF_ALU32_REG(BPF_ADD, R6, R4),
1467 BPF_ALU32_REG(BPF_ADD, R6, R5),
1468 BPF_ALU32_REG(BPF_ADD, R6, R6),
1469 BPF_ALU32_REG(BPF_ADD, R6, R7),
1470 BPF_ALU32_REG(BPF_ADD, R6, R8),
1471 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1472 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1474 BPF_ALU32_REG(BPF_ADD, R7, R0),
1475 BPF_ALU32_REG(BPF_ADD, R7, R1),
1476 BPF_ALU32_REG(BPF_ADD, R7, R2),
1477 BPF_ALU32_REG(BPF_ADD, R7, R3),
1478 BPF_ALU32_REG(BPF_ADD, R7, R4),
1479 BPF_ALU32_REG(BPF_ADD, R7, R5),
1480 BPF_ALU32_REG(BPF_ADD, R7, R6),
1481 BPF_ALU32_REG(BPF_ADD, R7, R7),
1482 BPF_ALU32_REG(BPF_ADD, R7, R8),
1483 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1484 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1486 BPF_ALU32_REG(BPF_ADD, R8, R0),
1487 BPF_ALU32_REG(BPF_ADD, R8, R1),
1488 BPF_ALU32_REG(BPF_ADD, R8, R2),
1489 BPF_ALU32_REG(BPF_ADD, R8, R3),
1490 BPF_ALU32_REG(BPF_ADD, R8, R4),
1491 BPF_ALU32_REG(BPF_ADD, R8, R5),
1492 BPF_ALU32_REG(BPF_ADD, R8, R6),
1493 BPF_ALU32_REG(BPF_ADD, R8, R7),
1494 BPF_ALU32_REG(BPF_ADD, R8, R8),
1495 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1496 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1498 BPF_ALU32_REG(BPF_ADD, R9, R0),
1499 BPF_ALU32_REG(BPF_ADD, R9, R1),
1500 BPF_ALU32_REG(BPF_ADD, R9, R2),
1501 BPF_ALU32_REG(BPF_ADD, R9, R3),
1502 BPF_ALU32_REG(BPF_ADD, R9, R4),
1503 BPF_ALU32_REG(BPF_ADD, R9, R5),
1504 BPF_ALU32_REG(BPF_ADD, R9, R6),
1505 BPF_ALU32_REG(BPF_ADD, R9, R7),
1506 BPF_ALU32_REG(BPF_ADD, R9, R8),
1507 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1508 BPF_ALU32_REG(BPF_MOV, R0, R9),
1515 { /* Mainly checking JIT here. */
1518 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1519 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1520 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1521 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1522 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1523 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1524 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1525 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1526 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1527 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1528 BPF_ALU64_REG(BPF_SUB, R0, R0),
1529 BPF_ALU64_REG(BPF_SUB, R0, R1),
1530 BPF_ALU64_REG(BPF_SUB, R0, R2),
1531 BPF_ALU64_REG(BPF_SUB, R0, R3),
1532 BPF_ALU64_REG(BPF_SUB, R0, R4),
1533 BPF_ALU64_REG(BPF_SUB, R0, R5),
1534 BPF_ALU64_REG(BPF_SUB, R0, R6),
1535 BPF_ALU64_REG(BPF_SUB, R0, R7),
1536 BPF_ALU64_REG(BPF_SUB, R0, R8),
1537 BPF_ALU64_REG(BPF_SUB, R0, R9),
1538 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1539 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1541 BPF_ALU64_REG(BPF_SUB, R1, R0),
1542 BPF_ALU64_REG(BPF_SUB, R1, R2),
1543 BPF_ALU64_REG(BPF_SUB, R1, R3),
1544 BPF_ALU64_REG(BPF_SUB, R1, R4),
1545 BPF_ALU64_REG(BPF_SUB, R1, R5),
1546 BPF_ALU64_REG(BPF_SUB, R1, R6),
1547 BPF_ALU64_REG(BPF_SUB, R1, R7),
1548 BPF_ALU64_REG(BPF_SUB, R1, R8),
1549 BPF_ALU64_REG(BPF_SUB, R1, R9),
1550 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1551 BPF_ALU64_REG(BPF_SUB, R2, R0),
1552 BPF_ALU64_REG(BPF_SUB, R2, R1),
1553 BPF_ALU64_REG(BPF_SUB, R2, R3),
1554 BPF_ALU64_REG(BPF_SUB, R2, R4),
1555 BPF_ALU64_REG(BPF_SUB, R2, R5),
1556 BPF_ALU64_REG(BPF_SUB, R2, R6),
1557 BPF_ALU64_REG(BPF_SUB, R2, R7),
1558 BPF_ALU64_REG(BPF_SUB, R2, R8),
1559 BPF_ALU64_REG(BPF_SUB, R2, R9),
1560 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1561 BPF_ALU64_REG(BPF_SUB, R3, R0),
1562 BPF_ALU64_REG(BPF_SUB, R3, R1),
1563 BPF_ALU64_REG(BPF_SUB, R3, R2),
1564 BPF_ALU64_REG(BPF_SUB, R3, R4),
1565 BPF_ALU64_REG(BPF_SUB, R3, R5),
1566 BPF_ALU64_REG(BPF_SUB, R3, R6),
1567 BPF_ALU64_REG(BPF_SUB, R3, R7),
1568 BPF_ALU64_REG(BPF_SUB, R3, R8),
1569 BPF_ALU64_REG(BPF_SUB, R3, R9),
1570 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1571 BPF_ALU64_REG(BPF_SUB, R4, R0),
1572 BPF_ALU64_REG(BPF_SUB, R4, R1),
1573 BPF_ALU64_REG(BPF_SUB, R4, R2),
1574 BPF_ALU64_REG(BPF_SUB, R4, R3),
1575 BPF_ALU64_REG(BPF_SUB, R4, R5),
1576 BPF_ALU64_REG(BPF_SUB, R4, R6),
1577 BPF_ALU64_REG(BPF_SUB, R4, R7),
1578 BPF_ALU64_REG(BPF_SUB, R4, R8),
1579 BPF_ALU64_REG(BPF_SUB, R4, R9),
1580 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1581 BPF_ALU64_REG(BPF_SUB, R5, R0),
1582 BPF_ALU64_REG(BPF_SUB, R5, R1),
1583 BPF_ALU64_REG(BPF_SUB, R5, R2),
1584 BPF_ALU64_REG(BPF_SUB, R5, R3),
1585 BPF_ALU64_REG(BPF_SUB, R5, R4),
1586 BPF_ALU64_REG(BPF_SUB, R5, R6),
1587 BPF_ALU64_REG(BPF_SUB, R5, R7),
1588 BPF_ALU64_REG(BPF_SUB, R5, R8),
1589 BPF_ALU64_REG(BPF_SUB, R5, R9),
1590 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1591 BPF_ALU64_REG(BPF_SUB, R6, R0),
1592 BPF_ALU64_REG(BPF_SUB, R6, R1),
1593 BPF_ALU64_REG(BPF_SUB, R6, R2),
1594 BPF_ALU64_REG(BPF_SUB, R6, R3),
1595 BPF_ALU64_REG(BPF_SUB, R6, R4),
1596 BPF_ALU64_REG(BPF_SUB, R6, R5),
1597 BPF_ALU64_REG(BPF_SUB, R6, R7),
1598 BPF_ALU64_REG(BPF_SUB, R6, R8),
1599 BPF_ALU64_REG(BPF_SUB, R6, R9),
1600 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1601 BPF_ALU64_REG(BPF_SUB, R7, R0),
1602 BPF_ALU64_REG(BPF_SUB, R7, R1),
1603 BPF_ALU64_REG(BPF_SUB, R7, R2),
1604 BPF_ALU64_REG(BPF_SUB, R7, R3),
1605 BPF_ALU64_REG(BPF_SUB, R7, R4),
1606 BPF_ALU64_REG(BPF_SUB, R7, R5),
1607 BPF_ALU64_REG(BPF_SUB, R7, R6),
1608 BPF_ALU64_REG(BPF_SUB, R7, R8),
1609 BPF_ALU64_REG(BPF_SUB, R7, R9),
1610 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1611 BPF_ALU64_REG(BPF_SUB, R8, R0),
1612 BPF_ALU64_REG(BPF_SUB, R8, R1),
1613 BPF_ALU64_REG(BPF_SUB, R8, R2),
1614 BPF_ALU64_REG(BPF_SUB, R8, R3),
1615 BPF_ALU64_REG(BPF_SUB, R8, R4),
1616 BPF_ALU64_REG(BPF_SUB, R8, R5),
1617 BPF_ALU64_REG(BPF_SUB, R8, R6),
1618 BPF_ALU64_REG(BPF_SUB, R8, R7),
1619 BPF_ALU64_REG(BPF_SUB, R8, R9),
1620 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1621 BPF_ALU64_REG(BPF_SUB, R9, R0),
1622 BPF_ALU64_REG(BPF_SUB, R9, R1),
1623 BPF_ALU64_REG(BPF_SUB, R9, R2),
1624 BPF_ALU64_REG(BPF_SUB, R9, R3),
1625 BPF_ALU64_REG(BPF_SUB, R9, R4),
1626 BPF_ALU64_REG(BPF_SUB, R9, R5),
1627 BPF_ALU64_REG(BPF_SUB, R9, R6),
1628 BPF_ALU64_REG(BPF_SUB, R9, R7),
1629 BPF_ALU64_REG(BPF_SUB, R9, R8),
1630 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1631 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1632 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1633 BPF_ALU64_REG(BPF_SUB, R0, R1),
1634 BPF_ALU64_REG(BPF_SUB, R0, R2),
1635 BPF_ALU64_REG(BPF_SUB, R0, R3),
1636 BPF_ALU64_REG(BPF_SUB, R0, R4),
1637 BPF_ALU64_REG(BPF_SUB, R0, R5),
1638 BPF_ALU64_REG(BPF_SUB, R0, R6),
1639 BPF_ALU64_REG(BPF_SUB, R0, R7),
1640 BPF_ALU64_REG(BPF_SUB, R0, R8),
1641 BPF_ALU64_REG(BPF_SUB, R0, R9),
1648 { /* Mainly checking JIT here. */
1651 BPF_ALU64_REG(BPF_SUB, R0, R0),
1652 BPF_ALU64_REG(BPF_XOR, R1, R1),
1653 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1655 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1656 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1657 BPF_ALU64_REG(BPF_SUB, R1, R1),
1658 BPF_ALU64_REG(BPF_XOR, R2, R2),
1659 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1661 BPF_ALU64_REG(BPF_SUB, R2, R2),
1662 BPF_ALU64_REG(BPF_XOR, R3, R3),
1663 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1664 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1665 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1667 BPF_ALU64_REG(BPF_SUB, R3, R3),
1668 BPF_ALU64_REG(BPF_XOR, R4, R4),
1669 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1670 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1671 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1673 BPF_ALU64_REG(BPF_SUB, R4, R4),
1674 BPF_ALU64_REG(BPF_XOR, R5, R5),
1675 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1676 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1677 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1679 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1680 BPF_ALU64_REG(BPF_SUB, R5, R5),
1681 BPF_ALU64_REG(BPF_XOR, R6, R6),
1682 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1683 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1684 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1686 BPF_ALU64_REG(BPF_SUB, R6, R6),
1687 BPF_ALU64_REG(BPF_XOR, R7, R7),
1688 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1690 BPF_ALU64_REG(BPF_SUB, R7, R7),
1691 BPF_ALU64_REG(BPF_XOR, R8, R8),
1692 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1694 BPF_ALU64_REG(BPF_SUB, R8, R8),
1695 BPF_ALU64_REG(BPF_XOR, R9, R9),
1696 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1698 BPF_ALU64_REG(BPF_SUB, R9, R9),
1699 BPF_ALU64_REG(BPF_XOR, R0, R0),
1700 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1702 BPF_ALU64_REG(BPF_SUB, R1, R1),
1703 BPF_ALU64_REG(BPF_XOR, R0, R0),
1704 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1705 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1707 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1714 { /* Mainly checking JIT here. */
1717 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1718 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1719 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1720 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1721 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1722 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1723 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1724 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1725 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1726 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1727 BPF_ALU64_REG(BPF_MUL, R0, R0),
1728 BPF_ALU64_REG(BPF_MUL, R0, R1),
1729 BPF_ALU64_REG(BPF_MUL, R0, R2),
1730 BPF_ALU64_REG(BPF_MUL, R0, R3),
1731 BPF_ALU64_REG(BPF_MUL, R0, R4),
1732 BPF_ALU64_REG(BPF_MUL, R0, R5),
1733 BPF_ALU64_REG(BPF_MUL, R0, R6),
1734 BPF_ALU64_REG(BPF_MUL, R0, R7),
1735 BPF_ALU64_REG(BPF_MUL, R0, R8),
1736 BPF_ALU64_REG(BPF_MUL, R0, R9),
1737 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1738 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1740 BPF_ALU64_REG(BPF_MUL, R1, R0),
1741 BPF_ALU64_REG(BPF_MUL, R1, R2),
1742 BPF_ALU64_REG(BPF_MUL, R1, R3),
1743 BPF_ALU64_REG(BPF_MUL, R1, R4),
1744 BPF_ALU64_REG(BPF_MUL, R1, R5),
1745 BPF_ALU64_REG(BPF_MUL, R1, R6),
1746 BPF_ALU64_REG(BPF_MUL, R1, R7),
1747 BPF_ALU64_REG(BPF_MUL, R1, R8),
1748 BPF_ALU64_REG(BPF_MUL, R1, R9),
1749 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1750 BPF_ALU64_REG(BPF_MOV, R2, R1),
1751 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1752 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1754 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1755 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1756 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1758 BPF_ALU64_REG(BPF_MUL, R2, R0),
1759 BPF_ALU64_REG(BPF_MUL, R2, R1),
1760 BPF_ALU64_REG(BPF_MUL, R2, R3),
1761 BPF_ALU64_REG(BPF_MUL, R2, R4),
1762 BPF_ALU64_REG(BPF_MUL, R2, R5),
1763 BPF_ALU64_REG(BPF_MUL, R2, R6),
1764 BPF_ALU64_REG(BPF_MUL, R2, R7),
1765 BPF_ALU64_REG(BPF_MUL, R2, R8),
1766 BPF_ALU64_REG(BPF_MUL, R2, R9),
1767 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1768 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1769 BPF_ALU64_REG(BPF_MOV, R0, R2),
1774 { { 0, 0x35d97ef2 } }
1776 { /* Mainly checking JIT here. */
1779 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1780 BPF_MOV64_REG(R1, R0),
1781 BPF_MOV64_REG(R2, R1),
1782 BPF_MOV64_REG(R3, R2),
1783 BPF_MOV64_REG(R4, R3),
1784 BPF_MOV64_REG(R5, R4),
1785 BPF_MOV64_REG(R6, R5),
1786 BPF_MOV64_REG(R7, R6),
1787 BPF_MOV64_REG(R8, R7),
1788 BPF_MOV64_REG(R9, R8),
1789 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1790 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1791 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1792 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1793 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1794 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1795 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1796 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1797 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1798 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1799 BPF_ALU64_REG(BPF_ADD, R0, R0),
1800 BPF_ALU64_REG(BPF_ADD, R0, R1),
1801 BPF_ALU64_REG(BPF_ADD, R0, R2),
1802 BPF_ALU64_REG(BPF_ADD, R0, R3),
1803 BPF_ALU64_REG(BPF_ADD, R0, R4),
1804 BPF_ALU64_REG(BPF_ADD, R0, R5),
1805 BPF_ALU64_REG(BPF_ADD, R0, R6),
1806 BPF_ALU64_REG(BPF_ADD, R0, R7),
1807 BPF_ALU64_REG(BPF_ADD, R0, R8),
1808 BPF_ALU64_REG(BPF_ADD, R0, R9),
1809 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1816 { /* Mainly checking JIT here. */
1819 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1820 BPF_MOV64_REG(R1, R0),
1821 BPF_MOV64_REG(R2, R1),
1822 BPF_MOV64_REG(R3, R2),
1823 BPF_MOV64_REG(R4, R3),
1824 BPF_MOV64_REG(R5, R4),
1825 BPF_MOV64_REG(R6, R5),
1826 BPF_MOV64_REG(R7, R6),
1827 BPF_MOV64_REG(R8, R7),
1828 BPF_MOV64_REG(R9, R8),
1829 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1830 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1831 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1832 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1833 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1834 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1835 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1836 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1837 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1838 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1839 BPF_ALU64_REG(BPF_ADD, R0, R0),
1840 BPF_ALU64_REG(BPF_ADD, R0, R1),
1841 BPF_ALU64_REG(BPF_ADD, R0, R2),
1842 BPF_ALU64_REG(BPF_ADD, R0, R3),
1843 BPF_ALU64_REG(BPF_ADD, R0, R4),
1844 BPF_ALU64_REG(BPF_ADD, R0, R5),
1845 BPF_ALU64_REG(BPF_ADD, R0, R6),
1846 BPF_ALU64_REG(BPF_ADD, R0, R7),
1847 BPF_ALU64_REG(BPF_ADD, R0, R8),
1848 BPF_ALU64_REG(BPF_ADD, R0, R9),
1849 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1856 { /* Mainly checking JIT here. */
1859 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1860 BPF_MOV64_REG(R1, R0),
1861 BPF_MOV64_REG(R2, R1),
1862 BPF_MOV64_REG(R3, R2),
1863 BPF_MOV64_REG(R4, R3),
1864 BPF_MOV64_REG(R5, R4),
1865 BPF_MOV64_REG(R6, R5),
1866 BPF_MOV64_REG(R7, R6),
1867 BPF_MOV64_REG(R8, R7),
1868 BPF_MOV64_REG(R9, R8),
1869 BPF_LD_IMM64(R0, 0x0LL),
1870 BPF_LD_IMM64(R1, 0x0LL),
1871 BPF_LD_IMM64(R2, 0x0LL),
1872 BPF_LD_IMM64(R3, 0x0LL),
1873 BPF_LD_IMM64(R4, 0x0LL),
1874 BPF_LD_IMM64(R5, 0x0LL),
1875 BPF_LD_IMM64(R6, 0x0LL),
1876 BPF_LD_IMM64(R7, 0x0LL),
1877 BPF_LD_IMM64(R8, 0x0LL),
1878 BPF_LD_IMM64(R9, 0x0LL),
1879 BPF_ALU64_REG(BPF_ADD, R0, R0),
1880 BPF_ALU64_REG(BPF_ADD, R0, R1),
1881 BPF_ALU64_REG(BPF_ADD, R0, R2),
1882 BPF_ALU64_REG(BPF_ADD, R0, R3),
1883 BPF_ALU64_REG(BPF_ADD, R0, R4),
1884 BPF_ALU64_REG(BPF_ADD, R0, R5),
1885 BPF_ALU64_REG(BPF_ADD, R0, R6),
1886 BPF_ALU64_REG(BPF_ADD, R0, R7),
1887 BPF_ALU64_REG(BPF_ADD, R0, R8),
1888 BPF_ALU64_REG(BPF_ADD, R0, R9),
1889 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1899 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1900 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1901 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1902 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1903 BPF_ALU64_REG(BPF_DIV, R0, R2),
1904 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1906 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1907 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1909 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1917 "INT: shifts by register",
1919 BPF_MOV64_IMM(R0, -1234),
1920 BPF_MOV64_IMM(R1, 1),
1921 BPF_ALU32_REG(BPF_RSH, R0, R1),
1922 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1924 BPF_MOV64_IMM(R2, 1),
1925 BPF_ALU64_REG(BPF_LSH, R0, R2),
1926 BPF_MOV32_IMM(R4, -1234),
1927 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1929 BPF_ALU64_IMM(BPF_AND, R4, 63),
1930 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1931 BPF_MOV64_IMM(R3, 47),
1932 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1933 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1935 BPF_MOV64_IMM(R2, 1),
1936 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1937 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1939 BPF_MOV64_IMM(R4, 4),
1940 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1941 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1943 BPF_MOV64_IMM(R4, 5),
1944 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1945 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1947 BPF_MOV64_IMM(R0, -1),
1956 * Register (non-)clobbering test, in the case where a 32-bit
1957 * JIT implements complex ALU64 operations via function calls.
1958 * If so, the function call must be invisible in the eBPF
1959 * registers. The JIT must then save and restore relevant
1960 * registers during the call. The following tests check that
1961 * the eBPF registers retain their values after such a call.
1963 "INT: Register clobbering, R1 updated",
1965 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1966 BPF_ALU32_IMM(BPF_MOV, R1, 123456789),
1967 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1968 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1969 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1970 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1971 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1972 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1973 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1974 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1975 BPF_ALU64_IMM(BPF_DIV, R1, 123456789),
1976 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
1977 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
1978 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
1979 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
1980 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
1981 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
1982 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
1983 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
1984 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
1985 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
1986 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1994 "INT: Register clobbering, R2 updated",
1996 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1997 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1998 BPF_ALU32_IMM(BPF_MOV, R2, 2 * 123456789),
1999 BPF_ALU32_IMM(BPF_MOV, R3, 3),
2000 BPF_ALU32_IMM(BPF_MOV, R4, 4),
2001 BPF_ALU32_IMM(BPF_MOV, R5, 5),
2002 BPF_ALU32_IMM(BPF_MOV, R6, 6),
2003 BPF_ALU32_IMM(BPF_MOV, R7, 7),
2004 BPF_ALU32_IMM(BPF_MOV, R8, 8),
2005 BPF_ALU32_IMM(BPF_MOV, R9, 9),
2006 BPF_ALU64_IMM(BPF_DIV, R2, 123456789),
2007 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
2008 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
2009 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
2010 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
2011 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
2012 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
2013 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
2014 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
2015 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
2016 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
2017 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2026 * Test 32-bit JITs that implement complex ALU64 operations as
2027 * function calls R0 = f(R1, R2), and must re-arrange operands.
2029 #define NUMER 0xfedcba9876543210ULL
2030 #define DENOM 0x0123456789abcdefULL
2031 "ALU64_DIV X: Operand register permutations",
2034 BPF_LD_IMM64(R0, NUMER),
2035 BPF_LD_IMM64(R2, DENOM),
2036 BPF_ALU64_REG(BPF_DIV, R0, R2),
2037 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2040 BPF_LD_IMM64(R1, NUMER),
2041 BPF_LD_IMM64(R0, DENOM),
2042 BPF_ALU64_REG(BPF_DIV, R1, R0),
2043 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2046 BPF_LD_IMM64(R0, NUMER),
2047 BPF_LD_IMM64(R1, DENOM),
2048 BPF_ALU64_REG(BPF_DIV, R0, R1),
2049 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2052 BPF_LD_IMM64(R2, NUMER),
2053 BPF_LD_IMM64(R0, DENOM),
2054 BPF_ALU64_REG(BPF_DIV, R2, R0),
2055 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2058 BPF_LD_IMM64(R2, NUMER),
2059 BPF_LD_IMM64(R1, DENOM),
2060 BPF_ALU64_REG(BPF_DIV, R2, R1),
2061 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2064 BPF_LD_IMM64(R1, NUMER),
2065 BPF_LD_IMM64(R2, DENOM),
2066 BPF_ALU64_REG(BPF_DIV, R1, R2),
2067 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2070 BPF_LD_IMM64(R1, NUMER),
2071 BPF_ALU64_REG(BPF_DIV, R1, R1),
2072 BPF_JMP_IMM(BPF_JEQ, R1, 1, 1),
2075 BPF_LD_IMM64(R2, DENOM),
2076 BPF_ALU64_REG(BPF_DIV, R2, R2),
2077 BPF_JMP_IMM(BPF_JEQ, R2, 1, 1),
2080 BPF_LD_IMM64(R3, NUMER),
2081 BPF_LD_IMM64(R4, DENOM),
2082 BPF_ALU64_REG(BPF_DIV, R3, R4),
2083 BPF_JMP_IMM(BPF_JEQ, R3, NUMER / DENOM, 1),
2085 /* Successful return */
2086 BPF_LD_IMM64(R0, 1),
2097 "INT: 32-bit context pointer word order and zero-extension",
2099 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2100 BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3),
2101 BPF_ALU64_IMM(BPF_RSH, R1, 32),
2102 BPF_JMP32_IMM(BPF_JNE, R1, 0, 1),
2103 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2112 "check: missing ret",
2114 BPF_STMT(BPF_LD | BPF_IMM, 1),
2116 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2119 .fill_helper = NULL,
2120 .expected_errcode = -EINVAL,
2125 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
2126 BPF_STMT(BPF_RET | BPF_K, 0)
2128 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2131 .fill_helper = NULL,
2132 .expected_errcode = -EINVAL,
2135 "check: unknown insn",
2137 /* seccomp insn, rejected in socket filter */
2138 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
2139 BPF_STMT(BPF_RET | BPF_K, 0)
2141 CLASSIC | FLAG_EXPECTED_FAIL,
2144 .fill_helper = NULL,
2145 .expected_errcode = -EINVAL,
2148 "check: out of range spill/fill",
2150 BPF_STMT(BPF_STX, 16),
2151 BPF_STMT(BPF_RET | BPF_K, 0)
2153 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2156 .fill_helper = NULL,
2157 .expected_errcode = -EINVAL,
2162 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2163 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
2164 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2165 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2166 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2167 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2168 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2169 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2170 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2171 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2172 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2173 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2174 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2175 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2176 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2177 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
2178 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2179 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
2180 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2181 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2182 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2183 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2184 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2185 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2186 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2187 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2188 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2189 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2190 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2191 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2192 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2193 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2194 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2195 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2196 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2197 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2198 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2199 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2200 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2201 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2202 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2203 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2204 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2205 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2206 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2207 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2208 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2209 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2210 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2211 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2212 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2213 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2214 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2215 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2216 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2217 BPF_STMT(BPF_RET | BPF_A, 0),
2218 BPF_STMT(BPF_RET | BPF_A, 0),
2221 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2222 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2224 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2225 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2226 0xc0, 0xa8, 0x33, 0x01,
2227 0xc0, 0xa8, 0x33, 0x02,
2230 0x00, 0x14, 0x00, 0x00,
2231 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2232 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2233 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2234 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2235 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2236 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2237 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2238 0xcc, 0xcc, 0xcc, 0xcc },
2244 BPF_STMT(BPF_RET | BPF_X, 0),
2246 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2249 .fill_helper = NULL,
2250 .expected_errcode = -EINVAL,
2253 "check: LDX + RET X",
2255 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2256 BPF_STMT(BPF_RET | BPF_X, 0),
2258 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2261 .fill_helper = NULL,
2262 .expected_errcode = -EINVAL,
2264 { /* Mainly checking JIT here. */
2265 "M[]: alt STX + LDX",
2267 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2268 BPF_STMT(BPF_STX, 0),
2269 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2270 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2271 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2272 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2273 BPF_STMT(BPF_STX, 1),
2274 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2275 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2276 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2277 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2278 BPF_STMT(BPF_STX, 2),
2279 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2280 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2281 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2282 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2283 BPF_STMT(BPF_STX, 3),
2284 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2285 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2286 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2287 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2288 BPF_STMT(BPF_STX, 4),
2289 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2290 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2291 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2292 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2293 BPF_STMT(BPF_STX, 5),
2294 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2295 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2296 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2297 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2298 BPF_STMT(BPF_STX, 6),
2299 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2300 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2301 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2302 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2303 BPF_STMT(BPF_STX, 7),
2304 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2305 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2306 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2307 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2308 BPF_STMT(BPF_STX, 8),
2309 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2310 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2311 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2312 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2313 BPF_STMT(BPF_STX, 9),
2314 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2315 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2316 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2317 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2318 BPF_STMT(BPF_STX, 10),
2319 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2320 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2321 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2322 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2323 BPF_STMT(BPF_STX, 11),
2324 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2325 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2326 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2327 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2328 BPF_STMT(BPF_STX, 12),
2329 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2330 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2331 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2332 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2333 BPF_STMT(BPF_STX, 13),
2334 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2335 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2336 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2337 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2338 BPF_STMT(BPF_STX, 14),
2339 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2340 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2341 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2342 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2343 BPF_STMT(BPF_STX, 15),
2344 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2345 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2346 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2347 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2348 BPF_STMT(BPF_RET | BPF_A, 0),
2350 CLASSIC | FLAG_NO_DATA,
2354 { /* Mainly checking JIT here. */
2355 "M[]: full STX + full LDX",
2357 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2358 BPF_STMT(BPF_STX, 0),
2359 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2360 BPF_STMT(BPF_STX, 1),
2361 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2362 BPF_STMT(BPF_STX, 2),
2363 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2364 BPF_STMT(BPF_STX, 3),
2365 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2366 BPF_STMT(BPF_STX, 4),
2367 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2368 BPF_STMT(BPF_STX, 5),
2369 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2370 BPF_STMT(BPF_STX, 6),
2371 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2372 BPF_STMT(BPF_STX, 7),
2373 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2374 BPF_STMT(BPF_STX, 8),
2375 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2376 BPF_STMT(BPF_STX, 9),
2377 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2378 BPF_STMT(BPF_STX, 10),
2379 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2380 BPF_STMT(BPF_STX, 11),
2381 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2382 BPF_STMT(BPF_STX, 12),
2383 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2384 BPF_STMT(BPF_STX, 13),
2385 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2386 BPF_STMT(BPF_STX, 14),
2387 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2388 BPF_STMT(BPF_STX, 15),
2389 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2390 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2391 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2392 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2393 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2394 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2395 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2396 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2397 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2398 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2399 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2400 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2401 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2402 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2403 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2404 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2405 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2406 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2407 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2408 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2409 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2410 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2411 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2412 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2413 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2414 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2415 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2416 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2417 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2418 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2419 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2420 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2421 BPF_STMT(BPF_RET | BPF_A, 0),
2423 CLASSIC | FLAG_NO_DATA,
2425 { { 0, 0x2a5a5e5 } },
2428 "check: SKF_AD_MAX",
2430 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2431 SKF_AD_OFF + SKF_AD_MAX),
2432 BPF_STMT(BPF_RET | BPF_A, 0),
2434 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2437 .fill_helper = NULL,
2438 .expected_errcode = -EINVAL,
2440 { /* Passes checker but fails during runtime. */
2441 "LD [SKF_AD_OFF-1]",
2443 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2445 BPF_STMT(BPF_RET | BPF_K, 1),
2452 "load 64-bit immediate",
2454 BPF_LD_IMM64(R1, 0x567800001234LL),
2455 BPF_MOV64_REG(R2, R1),
2456 BPF_MOV64_REG(R3, R2),
2457 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2458 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2459 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2460 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2461 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2463 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2465 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2466 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2473 /* BPF_ALU | BPF_MOV | BPF_X */
2475 "ALU_MOV_X: dst = 2",
2477 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2478 BPF_ALU32_REG(BPF_MOV, R0, R1),
2486 "ALU_MOV_X: dst = 4294967295",
2488 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2489 BPF_ALU32_REG(BPF_MOV, R0, R1),
2494 { { 0, 4294967295U } },
2497 "ALU64_MOV_X: dst = 2",
2499 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2500 BPF_ALU64_REG(BPF_MOV, R0, R1),
2508 "ALU64_MOV_X: dst = 4294967295",
2510 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2511 BPF_ALU64_REG(BPF_MOV, R0, R1),
2516 { { 0, 4294967295U } },
2518 /* BPF_ALU | BPF_MOV | BPF_K */
2520 "ALU_MOV_K: dst = 2",
2522 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2530 "ALU_MOV_K: dst = 4294967295",
2532 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2537 { { 0, 4294967295U } },
2540 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2542 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2543 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2544 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2545 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2546 BPF_MOV32_IMM(R0, 2),
2548 BPF_MOV32_IMM(R0, 1),
2556 "ALU_MOV_K: small negative",
2558 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2566 "ALU_MOV_K: small negative zero extension",
2568 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2569 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2577 "ALU_MOV_K: large negative",
2579 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2584 { { 0, -123456789 } }
2587 "ALU_MOV_K: large negative zero extension",
2589 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2590 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2598 "ALU64_MOV_K: dst = 2",
2600 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2608 "ALU64_MOV_K: dst = 2147483647",
2610 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2615 { { 0, 2147483647 } },
2618 "ALU64_OR_K: dst = 0x0",
2620 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2621 BPF_LD_IMM64(R3, 0x0),
2622 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2623 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2624 BPF_MOV32_IMM(R0, 2),
2626 BPF_MOV32_IMM(R0, 1),
2634 "ALU64_MOV_K: dst = -1",
2636 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2637 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2638 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2639 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2640 BPF_MOV32_IMM(R0, 2),
2642 BPF_MOV32_IMM(R0, 1),
2650 "ALU64_MOV_K: small negative",
2652 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2660 "ALU64_MOV_K: small negative sign extension",
2662 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2663 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2668 { { 0, 0xffffffff } }
2671 "ALU64_MOV_K: large negative",
2673 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2678 { { 0, -123456789 } }
2681 "ALU64_MOV_K: large negative sign extension",
2683 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2684 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2689 { { 0, 0xffffffff } }
2691 /* BPF_ALU | BPF_ADD | BPF_X */
2693 "ALU_ADD_X: 1 + 2 = 3",
2695 BPF_LD_IMM64(R0, 1),
2696 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2697 BPF_ALU32_REG(BPF_ADD, R0, R1),
2705 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2707 BPF_LD_IMM64(R0, 1),
2708 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2709 BPF_ALU32_REG(BPF_ADD, R0, R1),
2714 { { 0, 4294967295U } },
2717 "ALU_ADD_X: 2 + 4294967294 = 0",
2719 BPF_LD_IMM64(R0, 2),
2720 BPF_LD_IMM64(R1, 4294967294U),
2721 BPF_ALU32_REG(BPF_ADD, R0, R1),
2722 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2723 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2725 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2733 "ALU64_ADD_X: 1 + 2 = 3",
2735 BPF_LD_IMM64(R0, 1),
2736 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2737 BPF_ALU64_REG(BPF_ADD, R0, R1),
2745 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2747 BPF_LD_IMM64(R0, 1),
2748 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2749 BPF_ALU64_REG(BPF_ADD, R0, R1),
2754 { { 0, 4294967295U } },
2757 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2759 BPF_LD_IMM64(R0, 2),
2760 BPF_LD_IMM64(R1, 4294967294U),
2761 BPF_LD_IMM64(R2, 4294967296ULL),
2762 BPF_ALU64_REG(BPF_ADD, R0, R1),
2763 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2764 BPF_MOV32_IMM(R0, 0),
2766 BPF_MOV32_IMM(R0, 1),
2773 /* BPF_ALU | BPF_ADD | BPF_K */
2775 "ALU_ADD_K: 1 + 2 = 3",
2777 BPF_LD_IMM64(R0, 1),
2778 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2786 "ALU_ADD_K: 3 + 0 = 3",
2788 BPF_LD_IMM64(R0, 3),
2789 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2797 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2799 BPF_LD_IMM64(R0, 1),
2800 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2805 { { 0, 4294967295U } },
2808 "ALU_ADD_K: 4294967294 + 2 = 0",
2810 BPF_LD_IMM64(R0, 4294967294U),
2811 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2812 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2813 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2815 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2823 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2825 BPF_LD_IMM64(R2, 0x0),
2826 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2827 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2828 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2829 BPF_MOV32_IMM(R0, 2),
2831 BPF_MOV32_IMM(R0, 1),
2839 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2841 BPF_LD_IMM64(R2, 0x0),
2842 BPF_LD_IMM64(R3, 0xffff),
2843 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2844 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2845 BPF_MOV32_IMM(R0, 2),
2847 BPF_MOV32_IMM(R0, 1),
2855 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2857 BPF_LD_IMM64(R2, 0x0),
2858 BPF_LD_IMM64(R3, 0x7fffffff),
2859 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2860 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2861 BPF_MOV32_IMM(R0, 2),
2863 BPF_MOV32_IMM(R0, 1),
2871 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2873 BPF_LD_IMM64(R2, 0x0),
2874 BPF_LD_IMM64(R3, 0x80000000),
2875 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2876 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2877 BPF_MOV32_IMM(R0, 2),
2879 BPF_MOV32_IMM(R0, 1),
2887 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2889 BPF_LD_IMM64(R2, 0x0),
2890 BPF_LD_IMM64(R3, 0x80008000),
2891 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2892 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2893 BPF_MOV32_IMM(R0, 2),
2895 BPF_MOV32_IMM(R0, 1),
2903 "ALU64_ADD_K: 1 + 2 = 3",
2905 BPF_LD_IMM64(R0, 1),
2906 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2914 "ALU64_ADD_K: 3 + 0 = 3",
2916 BPF_LD_IMM64(R0, 3),
2917 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2925 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2927 BPF_LD_IMM64(R0, 1),
2928 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2933 { { 0, 2147483647 } },
2936 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2938 BPF_LD_IMM64(R0, 4294967294U),
2939 BPF_LD_IMM64(R1, 4294967296ULL),
2940 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2941 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2942 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2944 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2952 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2954 BPF_LD_IMM64(R0, 2147483646),
2955 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2963 "ALU64_ADD_K: 1 + 0 = 1",
2965 BPF_LD_IMM64(R2, 0x1),
2966 BPF_LD_IMM64(R3, 0x1),
2967 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2968 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2969 BPF_MOV32_IMM(R0, 2),
2971 BPF_MOV32_IMM(R0, 1),
2979 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2981 BPF_LD_IMM64(R2, 0x0),
2982 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2983 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2984 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2985 BPF_MOV32_IMM(R0, 2),
2987 BPF_MOV32_IMM(R0, 1),
2995 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2997 BPF_LD_IMM64(R2, 0x0),
2998 BPF_LD_IMM64(R3, 0xffff),
2999 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
3000 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3001 BPF_MOV32_IMM(R0, 2),
3003 BPF_MOV32_IMM(R0, 1),
3011 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
3013 BPF_LD_IMM64(R2, 0x0),
3014 BPF_LD_IMM64(R3, 0x7fffffff),
3015 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
3016 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3017 BPF_MOV32_IMM(R0, 2),
3019 BPF_MOV32_IMM(R0, 1),
3027 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
3029 BPF_LD_IMM64(R2, 0x0),
3030 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
3031 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
3032 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3033 BPF_MOV32_IMM(R0, 2),
3035 BPF_MOV32_IMM(R0, 1),
3043 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
3045 BPF_LD_IMM64(R2, 0x0),
3046 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
3047 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
3048 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3049 BPF_MOV32_IMM(R0, 2),
3051 BPF_MOV32_IMM(R0, 1),
3058 /* BPF_ALU | BPF_SUB | BPF_X */
3060 "ALU_SUB_X: 3 - 1 = 2",
3062 BPF_LD_IMM64(R0, 3),
3063 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3064 BPF_ALU32_REG(BPF_SUB, R0, R1),
3072 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
3074 BPF_LD_IMM64(R0, 4294967295U),
3075 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
3076 BPF_ALU32_REG(BPF_SUB, R0, R1),
3084 "ALU64_SUB_X: 3 - 1 = 2",
3086 BPF_LD_IMM64(R0, 3),
3087 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3088 BPF_ALU64_REG(BPF_SUB, R0, R1),
3096 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
3098 BPF_LD_IMM64(R0, 4294967295U),
3099 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
3100 BPF_ALU64_REG(BPF_SUB, R0, R1),
3107 /* BPF_ALU | BPF_SUB | BPF_K */
3109 "ALU_SUB_K: 3 - 1 = 2",
3111 BPF_LD_IMM64(R0, 3),
3112 BPF_ALU32_IMM(BPF_SUB, R0, 1),
3120 "ALU_SUB_K: 3 - 0 = 3",
3122 BPF_LD_IMM64(R0, 3),
3123 BPF_ALU32_IMM(BPF_SUB, R0, 0),
3131 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
3133 BPF_LD_IMM64(R0, 4294967295U),
3134 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
3142 "ALU64_SUB_K: 3 - 1 = 2",
3144 BPF_LD_IMM64(R0, 3),
3145 BPF_ALU64_IMM(BPF_SUB, R0, 1),
3153 "ALU64_SUB_K: 3 - 0 = 3",
3155 BPF_LD_IMM64(R0, 3),
3156 BPF_ALU64_IMM(BPF_SUB, R0, 0),
3164 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3166 BPF_LD_IMM64(R0, 4294967294U),
3167 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
3175 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3177 BPF_LD_IMM64(R0, 2147483646),
3178 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
3185 /* BPF_ALU | BPF_MUL | BPF_X */
3187 "ALU_MUL_X: 2 * 3 = 6",
3189 BPF_LD_IMM64(R0, 2),
3190 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3191 BPF_ALU32_REG(BPF_MUL, R0, R1),
3199 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3201 BPF_LD_IMM64(R0, 2),
3202 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
3203 BPF_ALU32_REG(BPF_MUL, R0, R1),
3208 { { 0, 0xFFFFFFF0 } },
3211 "ALU_MUL_X: -1 * -1 = 1",
3213 BPF_LD_IMM64(R0, -1),
3214 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3215 BPF_ALU32_REG(BPF_MUL, R0, R1),
3223 "ALU64_MUL_X: 2 * 3 = 6",
3225 BPF_LD_IMM64(R0, 2),
3226 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3227 BPF_ALU64_REG(BPF_MUL, R0, R1),
3235 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3237 BPF_LD_IMM64(R0, 1),
3238 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3239 BPF_ALU64_REG(BPF_MUL, R0, R1),
3244 { { 0, 2147483647 } },
3247 "ALU64_MUL_X: 64x64 multiply, low word",
3249 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3250 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3251 BPF_ALU64_REG(BPF_MUL, R0, R1),
3256 { { 0, 0xe5618cf0 } }
3259 "ALU64_MUL_X: 64x64 multiply, high word",
3261 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3262 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3263 BPF_ALU64_REG(BPF_MUL, R0, R1),
3264 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3269 { { 0, 0x2236d88f } }
3271 /* BPF_ALU | BPF_MUL | BPF_K */
3273 "ALU_MUL_K: 2 * 3 = 6",
3275 BPF_LD_IMM64(R0, 2),
3276 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3284 "ALU_MUL_K: 3 * 1 = 3",
3286 BPF_LD_IMM64(R0, 3),
3287 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3295 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3297 BPF_LD_IMM64(R0, 2),
3298 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3303 { { 0, 0xFFFFFFF0 } },
3306 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3308 BPF_LD_IMM64(R2, 0x1),
3309 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3310 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3311 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3312 BPF_MOV32_IMM(R0, 2),
3314 BPF_MOV32_IMM(R0, 1),
3322 "ALU64_MUL_K: 2 * 3 = 6",
3324 BPF_LD_IMM64(R0, 2),
3325 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3333 "ALU64_MUL_K: 3 * 1 = 3",
3335 BPF_LD_IMM64(R0, 3),
3336 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3344 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3346 BPF_LD_IMM64(R0, 1),
3347 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3352 { { 0, 2147483647 } },
3355 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3357 BPF_LD_IMM64(R0, 1),
3358 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3363 { { 0, -2147483647 } },
3366 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3368 BPF_LD_IMM64(R2, 0x1),
3369 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3370 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3371 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3372 BPF_MOV32_IMM(R0, 2),
3374 BPF_MOV32_IMM(R0, 1),
3382 "ALU64_MUL_K: 64x32 multiply, low word",
3384 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3385 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3390 { { 0, 0xe242d208 } }
3393 "ALU64_MUL_K: 64x32 multiply, high word",
3395 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3396 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3397 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3402 { { 0, 0xc28f5c28 } }
3404 /* BPF_ALU | BPF_DIV | BPF_X */
3406 "ALU_DIV_X: 6 / 2 = 3",
3408 BPF_LD_IMM64(R0, 6),
3409 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3410 BPF_ALU32_REG(BPF_DIV, R0, R1),
3418 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3420 BPF_LD_IMM64(R0, 4294967295U),
3421 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
3422 BPF_ALU32_REG(BPF_DIV, R0, R1),
3430 "ALU64_DIV_X: 6 / 2 = 3",
3432 BPF_LD_IMM64(R0, 6),
3433 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3434 BPF_ALU64_REG(BPF_DIV, R0, R1),
3442 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3444 BPF_LD_IMM64(R0, 2147483647),
3445 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3446 BPF_ALU64_REG(BPF_DIV, R0, R1),
3454 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3456 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3457 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3458 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3459 BPF_ALU64_REG(BPF_DIV, R2, R4),
3460 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3461 BPF_MOV32_IMM(R0, 2),
3463 BPF_MOV32_IMM(R0, 1),
3470 /* BPF_ALU | BPF_DIV | BPF_K */
3472 "ALU_DIV_K: 6 / 2 = 3",
3474 BPF_LD_IMM64(R0, 6),
3475 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3483 "ALU_DIV_K: 3 / 1 = 3",
3485 BPF_LD_IMM64(R0, 3),
3486 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3494 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3496 BPF_LD_IMM64(R0, 4294967295U),
3497 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
3505 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3507 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3508 BPF_LD_IMM64(R3, 0x1UL),
3509 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3510 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3511 BPF_MOV32_IMM(R0, 2),
3513 BPF_MOV32_IMM(R0, 1),
3521 "ALU64_DIV_K: 6 / 2 = 3",
3523 BPF_LD_IMM64(R0, 6),
3524 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3532 "ALU64_DIV_K: 3 / 1 = 3",
3534 BPF_LD_IMM64(R0, 3),
3535 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3543 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3545 BPF_LD_IMM64(R0, 2147483647),
3546 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3554 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3556 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3557 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3558 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3559 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3560 BPF_MOV32_IMM(R0, 2),
3562 BPF_MOV32_IMM(R0, 1),
3569 /* BPF_ALU | BPF_MOD | BPF_X */
3571 "ALU_MOD_X: 3 % 2 = 1",
3573 BPF_LD_IMM64(R0, 3),
3574 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3575 BPF_ALU32_REG(BPF_MOD, R0, R1),
3583 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3585 BPF_LD_IMM64(R0, 4294967295U),
3586 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
3587 BPF_ALU32_REG(BPF_MOD, R0, R1),
3595 "ALU64_MOD_X: 3 % 2 = 1",
3597 BPF_LD_IMM64(R0, 3),
3598 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3599 BPF_ALU64_REG(BPF_MOD, R0, R1),
3607 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3609 BPF_LD_IMM64(R0, 2147483647),
3610 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3611 BPF_ALU64_REG(BPF_MOD, R0, R1),
3618 /* BPF_ALU | BPF_MOD | BPF_K */
3620 "ALU_MOD_K: 3 % 2 = 1",
3622 BPF_LD_IMM64(R0, 3),
3623 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3631 "ALU_MOD_K: 3 % 1 = 0",
3633 BPF_LD_IMM64(R0, 3),
3634 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3642 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3644 BPF_LD_IMM64(R0, 4294967295U),
3645 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
3653 "ALU64_MOD_K: 3 % 2 = 1",
3655 BPF_LD_IMM64(R0, 3),
3656 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3664 "ALU64_MOD_K: 3 % 1 = 0",
3666 BPF_LD_IMM64(R0, 3),
3667 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3675 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3677 BPF_LD_IMM64(R0, 2147483647),
3678 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3685 /* BPF_ALU | BPF_AND | BPF_X */
3687 "ALU_AND_X: 3 & 2 = 2",
3689 BPF_LD_IMM64(R0, 3),
3690 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3691 BPF_ALU32_REG(BPF_AND, R0, R1),
3699 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3701 BPF_LD_IMM64(R0, 0xffffffff),
3702 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3703 BPF_ALU32_REG(BPF_AND, R0, R1),
3708 { { 0, 0xffffffff } },
3711 "ALU64_AND_X: 3 & 2 = 2",
3713 BPF_LD_IMM64(R0, 3),
3714 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3715 BPF_ALU64_REG(BPF_AND, R0, R1),
3723 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3725 BPF_LD_IMM64(R0, 0xffffffff),
3726 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3727 BPF_ALU64_REG(BPF_AND, R0, R1),
3732 { { 0, 0xffffffff } },
3734 /* BPF_ALU | BPF_AND | BPF_K */
3736 "ALU_AND_K: 3 & 2 = 2",
3738 BPF_LD_IMM64(R0, 3),
3739 BPF_ALU32_IMM(BPF_AND, R0, 2),
3747 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3749 BPF_LD_IMM64(R0, 0xffffffff),
3750 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3755 { { 0, 0xffffffff } },
3758 "ALU_AND_K: Small immediate",
3760 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3761 BPF_ALU32_IMM(BPF_AND, R0, 15),
3769 "ALU_AND_K: Large immediate",
3771 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
3772 BPF_ALU32_IMM(BPF_AND, R0, 0xafbfcfdf),
3777 { { 0, 0xa1b2c3d4 } }
3780 "ALU_AND_K: Zero extension",
3782 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3783 BPF_LD_IMM64(R1, 0x0000000080a0c0e0LL),
3784 BPF_ALU32_IMM(BPF_AND, R0, 0xf0f0f0f0),
3785 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3786 BPF_MOV32_IMM(R0, 2),
3788 BPF_MOV32_IMM(R0, 1),
3796 "ALU64_AND_K: 3 & 2 = 2",
3798 BPF_LD_IMM64(R0, 3),
3799 BPF_ALU64_IMM(BPF_AND, R0, 2),
3807 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3809 BPF_LD_IMM64(R0, 0xffffffff),
3810 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3815 { { 0, 0xffffffff } },
3818 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000000000000000",
3820 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3821 BPF_LD_IMM64(R3, 0x0000000000000000LL),
3822 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3823 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3824 BPF_MOV32_IMM(R0, 2),
3826 BPF_MOV32_IMM(R0, 1),
3834 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffff0000",
3836 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3837 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3838 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3839 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3840 BPF_MOV32_IMM(R0, 2),
3842 BPF_MOV32_IMM(R0, 1),
3850 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3852 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3853 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3854 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3855 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3856 BPF_MOV32_IMM(R0, 2),
3858 BPF_MOV32_IMM(R0, 1),
3866 "ALU64_AND_K: Sign extension 1",
3868 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3869 BPF_LD_IMM64(R1, 0x00000000090b0d0fLL),
3870 BPF_ALU64_IMM(BPF_AND, R0, 0x0f0f0f0f),
3871 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3872 BPF_MOV32_IMM(R0, 2),
3874 BPF_MOV32_IMM(R0, 1),
3882 "ALU64_AND_K: Sign extension 2",
3884 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3885 BPF_LD_IMM64(R1, 0x0123456780a0c0e0LL),
3886 BPF_ALU64_IMM(BPF_AND, R0, 0xf0f0f0f0),
3887 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3888 BPF_MOV32_IMM(R0, 2),
3890 BPF_MOV32_IMM(R0, 1),
3897 /* BPF_ALU | BPF_OR | BPF_X */
3899 "ALU_OR_X: 1 | 2 = 3",
3901 BPF_LD_IMM64(R0, 1),
3902 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3903 BPF_ALU32_REG(BPF_OR, R0, R1),
3911 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3913 BPF_LD_IMM64(R0, 0),
3914 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3915 BPF_ALU32_REG(BPF_OR, R0, R1),
3920 { { 0, 0xffffffff } },
3923 "ALU64_OR_X: 1 | 2 = 3",
3925 BPF_LD_IMM64(R0, 1),
3926 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3927 BPF_ALU64_REG(BPF_OR, R0, R1),
3935 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3937 BPF_LD_IMM64(R0, 0),
3938 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3939 BPF_ALU64_REG(BPF_OR, R0, R1),
3944 { { 0, 0xffffffff } },
3946 /* BPF_ALU | BPF_OR | BPF_K */
3948 "ALU_OR_K: 1 | 2 = 3",
3950 BPF_LD_IMM64(R0, 1),
3951 BPF_ALU32_IMM(BPF_OR, R0, 2),
3959 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3961 BPF_LD_IMM64(R0, 0),
3962 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3967 { { 0, 0xffffffff } },
3970 "ALU_OR_K: Small immediate",
3972 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3973 BPF_ALU32_IMM(BPF_OR, R0, 1),
3978 { { 0, 0x01020305 } }
3981 "ALU_OR_K: Large immediate",
3983 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3984 BPF_ALU32_IMM(BPF_OR, R0, 0xa0b0c0d0),
3989 { { 0, 0xa1b2c3d4 } }
3992 "ALU_OR_K: Zero extension",
3994 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3995 BPF_LD_IMM64(R1, 0x00000000f9fbfdffLL),
3996 BPF_ALU32_IMM(BPF_OR, R0, 0xf0f0f0f0),
3997 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3998 BPF_MOV32_IMM(R0, 2),
4000 BPF_MOV32_IMM(R0, 1),
4008 "ALU64_OR_K: 1 | 2 = 3",
4010 BPF_LD_IMM64(R0, 1),
4011 BPF_ALU64_IMM(BPF_OR, R0, 2),
4019 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
4021 BPF_LD_IMM64(R0, 0),
4022 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
4027 { { 0, 0xffffffff } },
4030 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffffffff0000",
4032 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4033 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
4034 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
4035 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4036 BPF_MOV32_IMM(R0, 2),
4038 BPF_MOV32_IMM(R0, 1),
4046 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
4048 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4049 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
4050 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4051 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4052 BPF_MOV32_IMM(R0, 2),
4054 BPF_MOV32_IMM(R0, 1),
4062 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
4064 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4065 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
4066 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4067 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4068 BPF_MOV32_IMM(R0, 2),
4070 BPF_MOV32_IMM(R0, 1),
4078 "ALU64_OR_K: Sign extension 1",
4080 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4081 BPF_LD_IMM64(R1, 0x012345678fafcfefLL),
4082 BPF_ALU64_IMM(BPF_OR, R0, 0x0f0f0f0f),
4083 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4084 BPF_MOV32_IMM(R0, 2),
4086 BPF_MOV32_IMM(R0, 1),
4094 "ALU64_OR_K: Sign extension 2",
4096 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4097 BPF_LD_IMM64(R1, 0xfffffffff9fbfdffLL),
4098 BPF_ALU64_IMM(BPF_OR, R0, 0xf0f0f0f0),
4099 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4100 BPF_MOV32_IMM(R0, 2),
4102 BPF_MOV32_IMM(R0, 1),
4109 /* BPF_ALU | BPF_XOR | BPF_X */
4111 "ALU_XOR_X: 5 ^ 6 = 3",
4113 BPF_LD_IMM64(R0, 5),
4114 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4115 BPF_ALU32_REG(BPF_XOR, R0, R1),
4123 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
4125 BPF_LD_IMM64(R0, 1),
4126 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4127 BPF_ALU32_REG(BPF_XOR, R0, R1),
4132 { { 0, 0xfffffffe } },
4135 "ALU64_XOR_X: 5 ^ 6 = 3",
4137 BPF_LD_IMM64(R0, 5),
4138 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4139 BPF_ALU64_REG(BPF_XOR, R0, R1),
4147 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
4149 BPF_LD_IMM64(R0, 1),
4150 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4151 BPF_ALU64_REG(BPF_XOR, R0, R1),
4156 { { 0, 0xfffffffe } },
4158 /* BPF_ALU | BPF_XOR | BPF_K */
4160 "ALU_XOR_K: 5 ^ 6 = 3",
4162 BPF_LD_IMM64(R0, 5),
4163 BPF_ALU32_IMM(BPF_XOR, R0, 6),
4171 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
4173 BPF_LD_IMM64(R0, 1),
4174 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
4179 { { 0, 0xfffffffe } },
4182 "ALU_XOR_K: Small immediate",
4184 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
4185 BPF_ALU32_IMM(BPF_XOR, R0, 15),
4190 { { 0, 0x0102030b } }
4193 "ALU_XOR_K: Large immediate",
4195 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
4196 BPF_ALU32_IMM(BPF_XOR, R0, 0xafbfcfdf),
4201 { { 0, 0x5e4d3c2b } }
4204 "ALU_XOR_K: Zero extension",
4206 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4207 BPF_LD_IMM64(R1, 0x00000000795b3d1fLL),
4208 BPF_ALU32_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4209 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4210 BPF_MOV32_IMM(R0, 2),
4212 BPF_MOV32_IMM(R0, 1),
4220 "ALU64_XOR_K: 5 ^ 6 = 3",
4222 BPF_LD_IMM64(R0, 5),
4223 BPF_ALU64_IMM(BPF_XOR, R0, 6),
4231 "ALU64_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
4233 BPF_LD_IMM64(R0, 1),
4234 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
4239 { { 0, 0xfffffffe } },
4242 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
4244 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4245 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
4246 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
4247 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4248 BPF_MOV32_IMM(R0, 2),
4250 BPF_MOV32_IMM(R0, 1),
4258 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
4260 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4261 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
4262 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4263 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4264 BPF_MOV32_IMM(R0, 2),
4266 BPF_MOV32_IMM(R0, 1),
4274 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
4276 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4277 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
4278 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4279 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4280 BPF_MOV32_IMM(R0, 2),
4282 BPF_MOV32_IMM(R0, 1),
4290 "ALU64_XOR_K: Sign extension 1",
4292 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4293 BPF_LD_IMM64(R1, 0x0123456786a4c2e0LL),
4294 BPF_ALU64_IMM(BPF_XOR, R0, 0x0f0f0f0f),
4295 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4296 BPF_MOV32_IMM(R0, 2),
4298 BPF_MOV32_IMM(R0, 1),
4306 "ALU64_XOR_K: Sign extension 2",
4308 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4309 BPF_LD_IMM64(R1, 0xfedcba98795b3d1fLL),
4310 BPF_ALU64_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4311 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4312 BPF_MOV32_IMM(R0, 2),
4314 BPF_MOV32_IMM(R0, 1),
4321 /* BPF_ALU | BPF_LSH | BPF_X */
4323 "ALU_LSH_X: 1 << 1 = 2",
4325 BPF_LD_IMM64(R0, 1),
4326 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4327 BPF_ALU32_REG(BPF_LSH, R0, R1),
4335 "ALU_LSH_X: 1 << 31 = 0x80000000",
4337 BPF_LD_IMM64(R0, 1),
4338 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4339 BPF_ALU32_REG(BPF_LSH, R0, R1),
4344 { { 0, 0x80000000 } },
4347 "ALU_LSH_X: 0x12345678 << 12 = 0x45678000",
4349 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4350 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4351 BPF_ALU32_REG(BPF_LSH, R0, R1),
4356 { { 0, 0x45678000 } }
4359 "ALU64_LSH_X: 1 << 1 = 2",
4361 BPF_LD_IMM64(R0, 1),
4362 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4363 BPF_ALU64_REG(BPF_LSH, R0, R1),
4371 "ALU64_LSH_X: 1 << 31 = 0x80000000",
4373 BPF_LD_IMM64(R0, 1),
4374 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4375 BPF_ALU64_REG(BPF_LSH, R0, R1),
4380 { { 0, 0x80000000 } },
4383 "ALU64_LSH_X: Shift < 32, low word",
4385 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4386 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4387 BPF_ALU64_REG(BPF_LSH, R0, R1),
4392 { { 0, 0xbcdef000 } }
4395 "ALU64_LSH_X: Shift < 32, high word",
4397 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4398 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4399 BPF_ALU64_REG(BPF_LSH, R0, R1),
4400 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4405 { { 0, 0x3456789a } }
4408 "ALU64_LSH_X: Shift > 32, low word",
4410 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4411 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4412 BPF_ALU64_REG(BPF_LSH, R0, R1),
4420 "ALU64_LSH_X: Shift > 32, high word",
4422 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4423 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4424 BPF_ALU64_REG(BPF_LSH, R0, R1),
4425 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4430 { { 0, 0x9abcdef0 } }
4433 "ALU64_LSH_X: Shift == 32, low word",
4435 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4436 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4437 BPF_ALU64_REG(BPF_LSH, R0, R1),
4445 "ALU64_LSH_X: Shift == 32, high word",
4447 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4448 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4449 BPF_ALU64_REG(BPF_LSH, R0, R1),
4450 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4455 { { 0, 0x89abcdef } }
4458 "ALU64_LSH_X: Zero shift, low word",
4460 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4461 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4462 BPF_ALU64_REG(BPF_LSH, R0, R1),
4467 { { 0, 0x89abcdef } }
4470 "ALU64_LSH_X: Zero shift, high word",
4472 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4473 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4474 BPF_ALU64_REG(BPF_LSH, R0, R1),
4475 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4480 { { 0, 0x01234567 } }
4482 /* BPF_ALU | BPF_LSH | BPF_K */
4484 "ALU_LSH_K: 1 << 1 = 2",
4486 BPF_LD_IMM64(R0, 1),
4487 BPF_ALU32_IMM(BPF_LSH, R0, 1),
4495 "ALU_LSH_K: 1 << 31 = 0x80000000",
4497 BPF_LD_IMM64(R0, 1),
4498 BPF_ALU32_IMM(BPF_LSH, R0, 31),
4503 { { 0, 0x80000000 } },
4506 "ALU_LSH_K: 0x12345678 << 12 = 0x45678000",
4508 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4509 BPF_ALU32_IMM(BPF_LSH, R0, 12),
4514 { { 0, 0x45678000 } }
4517 "ALU_LSH_K: 0x12345678 << 0 = 0x12345678",
4519 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4520 BPF_ALU32_IMM(BPF_LSH, R0, 0),
4525 { { 0, 0x12345678 } }
4528 "ALU64_LSH_K: 1 << 1 = 2",
4530 BPF_LD_IMM64(R0, 1),
4531 BPF_ALU64_IMM(BPF_LSH, R0, 1),
4539 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4541 BPF_LD_IMM64(R0, 1),
4542 BPF_ALU64_IMM(BPF_LSH, R0, 31),
4547 { { 0, 0x80000000 } },
4550 "ALU64_LSH_K: Shift < 32, low word",
4552 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4553 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4558 { { 0, 0xbcdef000 } }
4561 "ALU64_LSH_K: Shift < 32, high word",
4563 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4564 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4565 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4570 { { 0, 0x3456789a } }
4573 "ALU64_LSH_K: Shift > 32, low word",
4575 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4576 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4584 "ALU64_LSH_K: Shift > 32, high word",
4586 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4587 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4588 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4593 { { 0, 0x9abcdef0 } }
4596 "ALU64_LSH_K: Shift == 32, low word",
4598 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4599 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4607 "ALU64_LSH_K: Shift == 32, high word",
4609 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4610 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4611 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4616 { { 0, 0x89abcdef } }
4619 "ALU64_LSH_K: Zero shift",
4621 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4622 BPF_ALU64_IMM(BPF_LSH, R0, 0),
4627 { { 0, 0x89abcdef } }
4629 /* BPF_ALU | BPF_RSH | BPF_X */
4631 "ALU_RSH_X: 2 >> 1 = 1",
4633 BPF_LD_IMM64(R0, 2),
4634 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4635 BPF_ALU32_REG(BPF_RSH, R0, R1),
4643 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4645 BPF_LD_IMM64(R0, 0x80000000),
4646 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4647 BPF_ALU32_REG(BPF_RSH, R0, R1),
4655 "ALU_RSH_X: 0x12345678 >> 20 = 0x123",
4657 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4658 BPF_ALU32_IMM(BPF_MOV, R1, 20),
4659 BPF_ALU32_REG(BPF_RSH, R0, R1),
4667 "ALU64_RSH_X: 2 >> 1 = 1",
4669 BPF_LD_IMM64(R0, 2),
4670 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4671 BPF_ALU64_REG(BPF_RSH, R0, R1),
4679 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4681 BPF_LD_IMM64(R0, 0x80000000),
4682 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4683 BPF_ALU64_REG(BPF_RSH, R0, R1),
4691 "ALU64_RSH_X: Shift < 32, low word",
4693 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4694 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4695 BPF_ALU64_REG(BPF_RSH, R0, R1),
4700 { { 0, 0x56789abc } }
4703 "ALU64_RSH_X: Shift < 32, high word",
4705 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4706 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4707 BPF_ALU64_REG(BPF_RSH, R0, R1),
4708 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4713 { { 0, 0x00081234 } }
4716 "ALU64_RSH_X: Shift > 32, low word",
4718 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4719 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4720 BPF_ALU64_REG(BPF_RSH, R0, R1),
4725 { { 0, 0x08123456 } }
4728 "ALU64_RSH_X: Shift > 32, high word",
4730 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4731 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4732 BPF_ALU64_REG(BPF_RSH, R0, R1),
4733 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4741 "ALU64_RSH_X: Shift == 32, low word",
4743 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4744 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4745 BPF_ALU64_REG(BPF_RSH, R0, R1),
4750 { { 0, 0x81234567 } }
4753 "ALU64_RSH_X: Shift == 32, high word",
4755 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4756 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4757 BPF_ALU64_REG(BPF_RSH, R0, R1),
4758 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4766 "ALU64_RSH_X: Zero shift, low word",
4768 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4769 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4770 BPF_ALU64_REG(BPF_RSH, R0, R1),
4775 { { 0, 0x89abcdef } }
4778 "ALU64_RSH_X: Zero shift, high word",
4780 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4781 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4782 BPF_ALU64_REG(BPF_RSH, R0, R1),
4783 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4788 { { 0, 0x81234567 } }
4790 /* BPF_ALU | BPF_RSH | BPF_K */
4792 "ALU_RSH_K: 2 >> 1 = 1",
4794 BPF_LD_IMM64(R0, 2),
4795 BPF_ALU32_IMM(BPF_RSH, R0, 1),
4803 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4805 BPF_LD_IMM64(R0, 0x80000000),
4806 BPF_ALU32_IMM(BPF_RSH, R0, 31),
4814 "ALU_RSH_K: 0x12345678 >> 20 = 0x123",
4816 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4817 BPF_ALU32_IMM(BPF_RSH, R0, 20),
4825 "ALU_RSH_K: 0x12345678 >> 0 = 0x12345678",
4827 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4828 BPF_ALU32_IMM(BPF_RSH, R0, 0),
4833 { { 0, 0x12345678 } }
4836 "ALU64_RSH_K: 2 >> 1 = 1",
4838 BPF_LD_IMM64(R0, 2),
4839 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4847 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4849 BPF_LD_IMM64(R0, 0x80000000),
4850 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4858 "ALU64_RSH_K: Shift < 32, low word",
4860 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4861 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4866 { { 0, 0x56789abc } }
4869 "ALU64_RSH_K: Shift < 32, high word",
4871 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4872 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4873 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4878 { { 0, 0x00081234 } }
4881 "ALU64_RSH_K: Shift > 32, low word",
4883 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4884 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4889 { { 0, 0x08123456 } }
4892 "ALU64_RSH_K: Shift > 32, high word",
4894 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4895 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4896 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4904 "ALU64_RSH_K: Shift == 32, low word",
4906 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4907 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4912 { { 0, 0x81234567 } }
4915 "ALU64_RSH_K: Shift == 32, high word",
4917 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4918 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4919 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4927 "ALU64_RSH_K: Zero shift",
4929 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4930 BPF_ALU64_IMM(BPF_RSH, R0, 0),
4935 { { 0, 0x89abcdef } }
4937 /* BPF_ALU | BPF_ARSH | BPF_X */
4939 "ALU32_ARSH_X: -1234 >> 7 = -10",
4941 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
4942 BPF_ALU32_IMM(BPF_MOV, R1, 7),
4943 BPF_ALU32_REG(BPF_ARSH, R0, R1),
4951 "ALU64_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4953 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4954 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4955 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4960 { { 0, 0xffff00ff } },
4963 "ALU64_ARSH_X: Shift < 32, low word",
4965 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4966 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4967 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4972 { { 0, 0x56789abc } }
4975 "ALU64_ARSH_X: Shift < 32, high word",
4977 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4978 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4979 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4980 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4985 { { 0, 0xfff81234 } }
4988 "ALU64_ARSH_X: Shift > 32, low word",
4990 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4991 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4992 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4997 { { 0, 0xf8123456 } }
5000 "ALU64_ARSH_X: Shift > 32, high word",
5002 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5003 BPF_ALU32_IMM(BPF_MOV, R1, 36),
5004 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5005 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5013 "ALU64_ARSH_X: Shift == 32, low word",
5015 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5016 BPF_ALU32_IMM(BPF_MOV, R1, 32),
5017 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5022 { { 0, 0x81234567 } }
5025 "ALU64_ARSH_X: Shift == 32, high word",
5027 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5028 BPF_ALU32_IMM(BPF_MOV, R1, 32),
5029 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5030 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5038 "ALU64_ARSH_X: Zero shift, low word",
5040 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5041 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5042 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5047 { { 0, 0x89abcdef } }
5050 "ALU64_ARSH_X: Zero shift, high word",
5052 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5053 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5054 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5055 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5060 { { 0, 0x81234567 } }
5062 /* BPF_ALU | BPF_ARSH | BPF_K */
5064 "ALU32_ARSH_K: -1234 >> 7 = -10",
5066 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5067 BPF_ALU32_IMM(BPF_ARSH, R0, 7),
5075 "ALU32_ARSH_K: -1234 >> 0 = -1234",
5077 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5078 BPF_ALU32_IMM(BPF_ARSH, R0, 0),
5086 "ALU64_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
5088 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
5089 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
5094 { { 0, 0xffff00ff } },
5097 "ALU64_ARSH_K: Shift < 32, low word",
5099 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5100 BPF_ALU64_IMM(BPF_RSH, R0, 12),
5105 { { 0, 0x56789abc } }
5108 "ALU64_ARSH_K: Shift < 32, high word",
5110 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5111 BPF_ALU64_IMM(BPF_ARSH, R0, 12),
5112 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5117 { { 0, 0xfff81234 } }
5120 "ALU64_ARSH_K: Shift > 32, low word",
5122 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5123 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5128 { { 0, 0xf8123456 } }
5131 "ALU64_ARSH_K: Shift > 32, high word",
5133 BPF_LD_IMM64(R0, 0xf123456789abcdefLL),
5134 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5135 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5143 "ALU64_ARSH_K: Shift == 32, low word",
5145 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5146 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5151 { { 0, 0x81234567 } }
5154 "ALU64_ARSH_K: Shift == 32, high word",
5156 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5157 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5158 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5166 "ALU64_ARSH_K: Zero shift",
5168 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5169 BPF_ALU64_IMM(BPF_ARSH, R0, 0),
5174 { { 0, 0x89abcdef } }
5176 /* BPF_ALU | BPF_NEG */
5178 "ALU_NEG: -(3) = -3",
5180 BPF_ALU32_IMM(BPF_MOV, R0, 3),
5181 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5189 "ALU_NEG: -(-3) = 3",
5191 BPF_ALU32_IMM(BPF_MOV, R0, -3),
5192 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5200 "ALU64_NEG: -(3) = -3",
5202 BPF_LD_IMM64(R0, 3),
5203 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5211 "ALU64_NEG: -(-3) = 3",
5213 BPF_LD_IMM64(R0, -3),
5214 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5221 /* BPF_ALU | BPF_END | BPF_FROM_BE */
5223 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
5225 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5226 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
5231 { { 0, cpu_to_be16(0xcdef) } },
5234 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
5236 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5237 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
5238 BPF_ALU64_REG(BPF_MOV, R1, R0),
5239 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5240 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
5245 { { 0, cpu_to_be32(0x89abcdef) } },
5248 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
5250 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5251 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
5256 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
5258 /* BPF_ALU | BPF_END | BPF_FROM_LE */
5260 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
5262 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5263 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
5268 { { 0, cpu_to_le16(0xcdef) } },
5271 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
5273 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5274 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
5275 BPF_ALU64_REG(BPF_MOV, R1, R0),
5276 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5277 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
5282 { { 0, cpu_to_le32(0x89abcdef) } },
5285 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
5287 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5288 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
5293 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
5295 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
5297 "ST_MEM_B: Store/Load byte: max negative",
5299 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5300 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
5301 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5310 "ST_MEM_B: Store/Load byte: max positive",
5312 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5313 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
5314 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5323 "STX_MEM_B: Store/Load byte: max negative",
5325 BPF_LD_IMM64(R0, 0),
5326 BPF_LD_IMM64(R1, 0xffLL),
5327 BPF_STX_MEM(BPF_B, R10, R1, -40),
5328 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5337 "ST_MEM_H: Store/Load half word: max negative",
5339 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5340 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
5341 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5350 "ST_MEM_H: Store/Load half word: max positive",
5352 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5353 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
5354 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5363 "STX_MEM_H: Store/Load half word: max negative",
5365 BPF_LD_IMM64(R0, 0),
5366 BPF_LD_IMM64(R1, 0xffffLL),
5367 BPF_STX_MEM(BPF_H, R10, R1, -40),
5368 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5377 "ST_MEM_W: Store/Load word: max negative",
5379 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5380 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
5381 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5386 { { 0, 0xffffffff } },
5390 "ST_MEM_W: Store/Load word: max positive",
5392 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5393 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
5394 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5399 { { 0, 0x7fffffff } },
5403 "STX_MEM_W: Store/Load word: max negative",
5405 BPF_LD_IMM64(R0, 0),
5406 BPF_LD_IMM64(R1, 0xffffffffLL),
5407 BPF_STX_MEM(BPF_W, R10, R1, -40),
5408 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5413 { { 0, 0xffffffff } },
5417 "ST_MEM_DW: Store/Load double word: max negative",
5419 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5420 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5421 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5426 { { 0, 0xffffffff } },
5430 "ST_MEM_DW: Store/Load double word: max negative 2",
5432 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
5433 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
5434 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5435 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
5436 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5437 BPF_MOV32_IMM(R0, 2),
5439 BPF_MOV32_IMM(R0, 1),
5448 "ST_MEM_DW: Store/Load double word: max positive",
5450 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5451 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
5452 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5457 { { 0, 0x7fffffff } },
5461 "STX_MEM_DW: Store/Load double word: max negative",
5463 BPF_LD_IMM64(R0, 0),
5464 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
5465 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5466 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5471 { { 0, 0xffffffff } },
5475 "STX_MEM_DW: Store double word: first word in memory",
5477 BPF_LD_IMM64(R0, 0),
5478 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5479 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5480 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5486 { { 0, 0x01234567 } },
5488 { { 0, 0x89abcdef } },
5493 "STX_MEM_DW: Store double word: second word in memory",
5495 BPF_LD_IMM64(R0, 0),
5496 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5497 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5498 BPF_LDX_MEM(BPF_W, R0, R10, -36),
5504 { { 0, 0x89abcdef } },
5506 { { 0, 0x01234567 } },
5510 /* BPF_STX | BPF_ATOMIC | BPF_W/DW */
5512 "STX_XADD_W: X + 1 + 1 + 1 + ...",
5517 .fill_helper = bpf_fill_stxw,
5520 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
5525 .fill_helper = bpf_fill_stxdw,
5528 * Exhaustive tests of atomic operation variants.
5529 * Individual tests are expanded from template macros for all
5530 * combinations of ALU operation, word size and fetching.
5532 #define BPF_ATOMIC_OP_TEST1(width, op, logic, old, update, result) \
5534 "BPF_ATOMIC | " #width ", " #op ": Test: " \
5535 #old " " #logic " " #update " = " #result, \
5537 BPF_ALU32_IMM(BPF_MOV, R5, update), \
5538 BPF_ST_MEM(width, R10, -40, old), \
5539 BPF_ATOMIC_OP(width, op, R10, R5, -40), \
5540 BPF_LDX_MEM(width, R0, R10, -40), \
5545 { { 0, result } }, \
5546 .stack_depth = 40, \
5548 #define BPF_ATOMIC_OP_TEST2(width, op, logic, old, update, result) \
5550 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r10: " \
5551 #old " " #logic " " #update " = " #result, \
5553 BPF_ALU64_REG(BPF_MOV, R1, R10), \
5554 BPF_ALU32_IMM(BPF_MOV, R0, update), \
5555 BPF_ST_MEM(BPF_W, R10, -40, old), \
5556 BPF_ATOMIC_OP(width, op, R10, R0, -40), \
5557 BPF_ALU64_REG(BPF_MOV, R0, R10), \
5558 BPF_ALU64_REG(BPF_SUB, R0, R1), \
5564 .stack_depth = 40, \
5566 #define BPF_ATOMIC_OP_TEST3(width, op, logic, old, update, result) \
5568 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r0: " \
5569 #old " " #logic " " #update " = " #result, \
5571 BPF_ALU64_REG(BPF_MOV, R0, R10), \
5572 BPF_ALU32_IMM(BPF_MOV, R1, update), \
5573 BPF_ST_MEM(width, R10, -40, old), \
5574 BPF_ATOMIC_OP(width, op, R10, R1, -40), \
5575 BPF_ALU64_REG(BPF_SUB, R0, R10), \
5581 .stack_depth = 40, \
5583 #define BPF_ATOMIC_OP_TEST4(width, op, logic, old, update, result) \
5585 "BPF_ATOMIC | " #width ", " #op ": Test fetch: " \
5586 #old " " #logic " " #update " = " #result, \
5588 BPF_ALU32_IMM(BPF_MOV, R3, update), \
5589 BPF_ST_MEM(width, R10, -40, old), \
5590 BPF_ATOMIC_OP(width, op, R10, R3, -40), \
5591 BPF_ALU64_REG(BPF_MOV, R0, R3), \
5596 { { 0, (op) & BPF_FETCH ? old : update } }, \
5597 .stack_depth = 40, \
5599 /* BPF_ATOMIC | BPF_W: BPF_ADD */
5600 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5601 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5602 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5603 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5604 /* BPF_ATOMIC | BPF_W: BPF_ADD | BPF_FETCH */
5605 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5606 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5607 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5608 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5609 /* BPF_ATOMIC | BPF_DW: BPF_ADD */
5610 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5611 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5612 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5613 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5614 /* BPF_ATOMIC | BPF_DW: BPF_ADD | BPF_FETCH */
5615 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5616 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5617 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5618 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5619 /* BPF_ATOMIC | BPF_W: BPF_AND */
5620 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5621 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5622 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5623 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5624 /* BPF_ATOMIC | BPF_W: BPF_AND | BPF_FETCH */
5625 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5626 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5627 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5628 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5629 /* BPF_ATOMIC | BPF_DW: BPF_AND */
5630 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5631 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5632 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5633 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5634 /* BPF_ATOMIC | BPF_DW: BPF_AND | BPF_FETCH */
5635 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5636 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5637 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5638 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5639 /* BPF_ATOMIC | BPF_W: BPF_OR */
5640 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5641 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5642 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5643 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5644 /* BPF_ATOMIC | BPF_W: BPF_OR | BPF_FETCH */
5645 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5646 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5647 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5648 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5649 /* BPF_ATOMIC | BPF_DW: BPF_OR */
5650 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5651 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5652 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5653 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5654 /* BPF_ATOMIC | BPF_DW: BPF_OR | BPF_FETCH */
5655 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5656 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5657 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5658 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5659 /* BPF_ATOMIC | BPF_W: BPF_XOR */
5660 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5661 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5662 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5663 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5664 /* BPF_ATOMIC | BPF_W: BPF_XOR | BPF_FETCH */
5665 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5666 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5667 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5668 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5669 /* BPF_ATOMIC | BPF_DW: BPF_XOR */
5670 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5671 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5672 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5673 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5674 /* BPF_ATOMIC | BPF_DW: BPF_XOR | BPF_FETCH */
5675 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5676 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5677 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5678 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5679 /* BPF_ATOMIC | BPF_W: BPF_XCHG */
5680 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5681 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5682 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5683 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5684 /* BPF_ATOMIC | BPF_DW: BPF_XCHG */
5685 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5686 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5687 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5688 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5689 #undef BPF_ATOMIC_OP_TEST1
5690 #undef BPF_ATOMIC_OP_TEST2
5691 #undef BPF_ATOMIC_OP_TEST3
5692 #undef BPF_ATOMIC_OP_TEST4
5693 /* BPF_ATOMIC | BPF_W, BPF_CMPXCHG */
5695 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful return",
5697 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5698 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
5699 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5700 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5705 { { 0, 0x01234567 } },
5709 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful store",
5711 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5712 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
5713 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5714 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5715 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5720 { { 0, 0x89abcdef } },
5724 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure return",
5726 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5727 BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210),
5728 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5729 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5734 { { 0, 0x01234567 } },
5738 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure store",
5740 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5741 BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210),
5742 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5743 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5744 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5749 { { 0, 0x01234567 } },
5753 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test side effects",
5755 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5756 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
5757 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5758 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5759 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5760 BPF_ALU32_REG(BPF_MOV, R0, R3),
5765 { { 0, 0x89abcdef } },
5768 /* BPF_ATOMIC | BPF_DW, BPF_CMPXCHG */
5770 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful return",
5772 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5773 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5774 BPF_ALU64_REG(BPF_MOV, R0, R1),
5775 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5776 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5777 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
5778 BPF_ALU64_REG(BPF_SUB, R0, R1),
5787 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful store",
5789 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5790 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5791 BPF_ALU64_REG(BPF_MOV, R0, R1),
5792 BPF_STX_MEM(BPF_DW, R10, R0, -40),
5793 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5794 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5795 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
5796 BPF_ALU64_REG(BPF_SUB, R0, R2),
5805 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure return",
5807 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5808 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5809 BPF_ALU64_REG(BPF_MOV, R0, R1),
5810 BPF_ALU64_IMM(BPF_ADD, R0, 1),
5811 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5812 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5813 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
5814 BPF_ALU64_REG(BPF_SUB, R0, R1),
5823 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure store",
5825 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5826 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5827 BPF_ALU64_REG(BPF_MOV, R0, R1),
5828 BPF_ALU64_IMM(BPF_ADD, R0, 1),
5829 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5830 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5831 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5832 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
5833 BPF_ALU64_REG(BPF_SUB, R0, R1),
5842 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test side effects",
5844 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5845 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5846 BPF_ALU64_REG(BPF_MOV, R0, R1),
5847 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5848 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5849 BPF_LD_IMM64(R0, 0xfecdba9876543210ULL),
5850 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
5851 BPF_ALU64_REG(BPF_SUB, R0, R2),
5859 /* BPF_JMP32 | BPF_JEQ | BPF_K */
5861 "JMP32_JEQ_K: Small immediate",
5863 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5864 BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
5865 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5866 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5874 "JMP32_JEQ_K: Large immediate",
5876 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5877 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1),
5878 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1),
5879 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5887 "JMP32_JEQ_K: negative immediate",
5889 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5890 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5891 BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1),
5892 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5899 /* BPF_JMP32 | BPF_JEQ | BPF_X */
5903 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5904 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5905 BPF_JMP32_REG(BPF_JEQ, R0, R1, 2),
5906 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5907 BPF_JMP32_REG(BPF_JEQ, R0, R1, 1),
5908 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5915 /* BPF_JMP32 | BPF_JNE | BPF_K */
5917 "JMP32_JNE_K: Small immediate",
5919 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5920 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5921 BPF_JMP32_IMM(BPF_JNE, R0, 321, 1),
5922 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5930 "JMP32_JNE_K: Large immediate",
5932 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5933 BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1),
5934 BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1),
5935 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5943 "JMP32_JNE_K: negative immediate",
5945 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5946 BPF_JMP32_IMM(BPF_JNE, R0, -123, 1),
5947 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5948 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5955 /* BPF_JMP32 | BPF_JNE | BPF_X */
5959 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5960 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5961 BPF_JMP32_REG(BPF_JNE, R0, R1, 2),
5962 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5963 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
5964 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5971 /* BPF_JMP32 | BPF_JSET | BPF_K */
5973 "JMP32_JSET_K: Small immediate",
5975 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5976 BPF_JMP32_IMM(BPF_JSET, R0, 2, 1),
5977 BPF_JMP32_IMM(BPF_JSET, R0, 3, 1),
5978 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5986 "JMP32_JSET_K: Large immediate",
5988 BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000),
5989 BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1),
5990 BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1),
5991 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5996 { { 0, 0x40000000 } }
5999 "JMP32_JSET_K: negative immediate",
6001 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6002 BPF_JMP32_IMM(BPF_JSET, R0, -1, 1),
6003 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6010 /* BPF_JMP32 | BPF_JSET | BPF_X */
6014 BPF_ALU32_IMM(BPF_MOV, R0, 8),
6015 BPF_ALU32_IMM(BPF_MOV, R1, 7),
6016 BPF_JMP32_REG(BPF_JSET, R0, R1, 2),
6017 BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2),
6018 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
6019 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6026 /* BPF_JMP32 | BPF_JGT | BPF_K */
6028 "JMP32_JGT_K: Small immediate",
6030 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6031 BPF_JMP32_IMM(BPF_JGT, R0, 123, 1),
6032 BPF_JMP32_IMM(BPF_JGT, R0, 122, 1),
6033 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6041 "JMP32_JGT_K: Large immediate",
6043 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6044 BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1),
6045 BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1),
6046 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6051 { { 0, 0xfffffffe } }
6053 /* BPF_JMP32 | BPF_JGT | BPF_X */
6057 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6058 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6059 BPF_JMP32_REG(BPF_JGT, R0, R1, 2),
6060 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6061 BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
6062 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6067 { { 0, 0xfffffffe } }
6069 /* BPF_JMP32 | BPF_JGE | BPF_K */
6071 "JMP32_JGE_K: Small immediate",
6073 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6074 BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
6075 BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
6076 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6084 "JMP32_JGE_K: Large immediate",
6086 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6087 BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
6088 BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
6089 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6094 { { 0, 0xfffffffe } }
6096 /* BPF_JMP32 | BPF_JGE | BPF_X */
6100 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6101 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6102 BPF_JMP32_REG(BPF_JGE, R0, R1, 2),
6103 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
6104 BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
6105 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6110 { { 0, 0xfffffffe } }
6112 /* BPF_JMP32 | BPF_JLT | BPF_K */
6114 "JMP32_JLT_K: Small immediate",
6116 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6117 BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
6118 BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
6119 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6127 "JMP32_JLT_K: Large immediate",
6129 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6130 BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
6131 BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
6132 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6137 { { 0, 0xfffffffe } }
6139 /* BPF_JMP32 | BPF_JLT | BPF_X */
6143 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6144 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6145 BPF_JMP32_REG(BPF_JLT, R0, R1, 2),
6146 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6147 BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
6148 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6153 { { 0, 0xfffffffe } }
6155 /* BPF_JMP32 | BPF_JLE | BPF_K */
6157 "JMP32_JLE_K: Small immediate",
6159 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6160 BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
6161 BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
6162 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6170 "JMP32_JLE_K: Large immediate",
6172 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6173 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
6174 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
6175 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6180 { { 0, 0xfffffffe } }
6182 /* BPF_JMP32 | BPF_JLE | BPF_X */
6186 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6187 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6188 BPF_JMP32_REG(BPF_JLE, R0, R1, 2),
6189 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
6190 BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
6191 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6196 { { 0, 0xfffffffe } }
6198 /* BPF_JMP32 | BPF_JSGT | BPF_K */
6200 "JMP32_JSGT_K: Small immediate",
6202 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6203 BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
6204 BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
6205 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6213 "JMP32_JSGT_K: Large immediate",
6215 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6216 BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
6217 BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
6218 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6223 { { 0, -12345678 } }
6225 /* BPF_JMP32 | BPF_JSGT | BPF_X */
6229 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6230 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6231 BPF_JMP32_REG(BPF_JSGT, R0, R1, 2),
6232 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6233 BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
6234 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6239 { { 0, -12345678 } }
6241 /* BPF_JMP32 | BPF_JSGE | BPF_K */
6243 "JMP32_JSGE_K: Small immediate",
6245 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6246 BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
6247 BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
6248 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6256 "JMP32_JSGE_K: Large immediate",
6258 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6259 BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
6260 BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
6261 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6266 { { 0, -12345678 } }
6268 /* BPF_JMP32 | BPF_JSGE | BPF_X */
6272 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6273 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6274 BPF_JMP32_REG(BPF_JSGE, R0, R1, 2),
6275 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6276 BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
6277 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6282 { { 0, -12345678 } }
6284 /* BPF_JMP32 | BPF_JSLT | BPF_K */
6286 "JMP32_JSLT_K: Small immediate",
6288 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6289 BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
6290 BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
6291 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6299 "JMP32_JSLT_K: Large immediate",
6301 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6302 BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
6303 BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
6304 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6309 { { 0, -12345678 } }
6311 /* BPF_JMP32 | BPF_JSLT | BPF_X */
6315 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6316 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6317 BPF_JMP32_REG(BPF_JSLT, R0, R1, 2),
6318 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6319 BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
6320 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6325 { { 0, -12345678 } }
6327 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6329 "JMP32_JSLE_K: Small immediate",
6331 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6332 BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
6333 BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
6334 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6342 "JMP32_JSLE_K: Large immediate",
6344 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6345 BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
6346 BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
6347 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6352 { { 0, -12345678 } }
6354 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6358 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6359 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6360 BPF_JMP32_REG(BPF_JSLE, R0, R1, 2),
6361 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6362 BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
6363 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6368 { { 0, -12345678 } }
6370 /* BPF_JMP | BPF_EXIT */
6374 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
6376 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
6382 /* BPF_JMP | BPF_JA */
6384 "JMP_JA: Unconditional jump: if (true) return 1",
6386 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6387 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
6389 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6396 /* BPF_JMP | BPF_JSLT | BPF_K */
6398 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
6400 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6401 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6402 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6404 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6412 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
6414 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6415 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6416 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6418 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6425 /* BPF_JMP | BPF_JSGT | BPF_K */
6427 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
6429 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6430 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6431 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
6433 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6441 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
6443 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6444 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6445 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
6447 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6454 /* BPF_JMP | BPF_JSLE | BPF_K */
6456 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
6458 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6459 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6460 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6462 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6470 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
6472 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6473 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6474 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6476 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6484 "JMP_JSLE_K: Signed jump: value walk 1",
6486 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6487 BPF_LD_IMM64(R1, 3),
6488 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
6489 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6490 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6491 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6492 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6493 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6494 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6495 BPF_EXIT_INSN(), /* bad exit */
6496 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6504 "JMP_JSLE_K: Signed jump: value walk 2",
6506 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6507 BPF_LD_IMM64(R1, 3),
6508 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6509 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6510 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6511 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6512 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6513 BPF_EXIT_INSN(), /* bad exit */
6514 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6521 /* BPF_JMP | BPF_JSGE | BPF_K */
6523 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
6525 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6526 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6527 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
6529 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6537 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
6539 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6540 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6541 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
6543 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6551 "JMP_JSGE_K: Signed jump: value walk 1",
6553 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6554 BPF_LD_IMM64(R1, -3),
6555 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
6556 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6557 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6558 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6559 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6560 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6561 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6562 BPF_EXIT_INSN(), /* bad exit */
6563 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6571 "JMP_JSGE_K: Signed jump: value walk 2",
6573 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6574 BPF_LD_IMM64(R1, -3),
6575 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6576 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6577 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6578 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6579 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6580 BPF_EXIT_INSN(), /* bad exit */
6581 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6588 /* BPF_JMP | BPF_JGT | BPF_K */
6590 "JMP_JGT_K: if (3 > 2) return 1",
6592 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6593 BPF_LD_IMM64(R1, 3),
6594 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
6596 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6604 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
6606 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6607 BPF_LD_IMM64(R1, -1),
6608 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
6610 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6617 /* BPF_JMP | BPF_JLT | BPF_K */
6619 "JMP_JLT_K: if (2 < 3) return 1",
6621 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6622 BPF_LD_IMM64(R1, 2),
6623 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
6625 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6633 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
6635 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6636 BPF_LD_IMM64(R1, 1),
6637 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
6639 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6646 /* BPF_JMP | BPF_JGE | BPF_K */
6648 "JMP_JGE_K: if (3 >= 2) return 1",
6650 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6651 BPF_LD_IMM64(R1, 3),
6652 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
6654 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6661 /* BPF_JMP | BPF_JLE | BPF_K */
6663 "JMP_JLE_K: if (2 <= 3) return 1",
6665 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6666 BPF_LD_IMM64(R1, 2),
6667 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6669 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6676 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
6678 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
6680 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6681 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6683 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6684 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
6685 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
6693 "JMP_JGE_K: if (3 >= 3) return 1",
6695 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6696 BPF_LD_IMM64(R1, 3),
6697 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
6699 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6706 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
6708 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
6710 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6711 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6713 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6714 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
6715 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
6723 "JMP_JLE_K: if (3 <= 3) return 1",
6725 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6726 BPF_LD_IMM64(R1, 3),
6727 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6729 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6736 /* BPF_JMP | BPF_JNE | BPF_K */
6738 "JMP_JNE_K: if (3 != 2) return 1",
6740 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6741 BPF_LD_IMM64(R1, 3),
6742 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
6744 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6751 /* BPF_JMP | BPF_JEQ | BPF_K */
6753 "JMP_JEQ_K: if (3 == 3) return 1",
6755 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6756 BPF_LD_IMM64(R1, 3),
6757 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
6759 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6766 /* BPF_JMP | BPF_JSET | BPF_K */
6768 "JMP_JSET_K: if (0x3 & 0x2) return 1",
6770 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6771 BPF_LD_IMM64(R1, 3),
6772 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
6774 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6782 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
6784 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6785 BPF_LD_IMM64(R1, 3),
6786 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
6788 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6795 /* BPF_JMP | BPF_JSGT | BPF_X */
6797 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
6799 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6800 BPF_LD_IMM64(R1, -1),
6801 BPF_LD_IMM64(R2, -2),
6802 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6804 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6812 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
6814 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6815 BPF_LD_IMM64(R1, -1),
6816 BPF_LD_IMM64(R2, -1),
6817 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6819 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6826 /* BPF_JMP | BPF_JSLT | BPF_X */
6828 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
6830 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6831 BPF_LD_IMM64(R1, -1),
6832 BPF_LD_IMM64(R2, -2),
6833 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
6835 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6843 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
6845 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6846 BPF_LD_IMM64(R1, -1),
6847 BPF_LD_IMM64(R2, -1),
6848 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
6850 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6857 /* BPF_JMP | BPF_JSGE | BPF_X */
6859 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
6861 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6862 BPF_LD_IMM64(R1, -1),
6863 BPF_LD_IMM64(R2, -2),
6864 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6866 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6874 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
6876 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6877 BPF_LD_IMM64(R1, -1),
6878 BPF_LD_IMM64(R2, -1),
6879 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6881 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6888 /* BPF_JMP | BPF_JSLE | BPF_X */
6890 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
6892 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6893 BPF_LD_IMM64(R1, -1),
6894 BPF_LD_IMM64(R2, -2),
6895 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
6897 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6905 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
6907 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6908 BPF_LD_IMM64(R1, -1),
6909 BPF_LD_IMM64(R2, -1),
6910 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
6912 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6919 /* BPF_JMP | BPF_JGT | BPF_X */
6921 "JMP_JGT_X: if (3 > 2) return 1",
6923 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6924 BPF_LD_IMM64(R1, 3),
6925 BPF_LD_IMM64(R2, 2),
6926 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6928 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6936 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
6938 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6939 BPF_LD_IMM64(R1, -1),
6940 BPF_LD_IMM64(R2, 1),
6941 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6943 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6950 /* BPF_JMP | BPF_JLT | BPF_X */
6952 "JMP_JLT_X: if (2 < 3) return 1",
6954 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6955 BPF_LD_IMM64(R1, 3),
6956 BPF_LD_IMM64(R2, 2),
6957 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6959 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6967 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
6969 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6970 BPF_LD_IMM64(R1, -1),
6971 BPF_LD_IMM64(R2, 1),
6972 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6974 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6981 /* BPF_JMP | BPF_JGE | BPF_X */
6983 "JMP_JGE_X: if (3 >= 2) return 1",
6985 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6986 BPF_LD_IMM64(R1, 3),
6987 BPF_LD_IMM64(R2, 2),
6988 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
6990 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6998 "JMP_JGE_X: if (3 >= 3) return 1",
7000 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7001 BPF_LD_IMM64(R1, 3),
7002 BPF_LD_IMM64(R2, 3),
7003 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
7005 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7012 /* BPF_JMP | BPF_JLE | BPF_X */
7014 "JMP_JLE_X: if (2 <= 3) return 1",
7016 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7017 BPF_LD_IMM64(R1, 3),
7018 BPF_LD_IMM64(R2, 2),
7019 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
7021 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7029 "JMP_JLE_X: if (3 <= 3) return 1",
7031 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7032 BPF_LD_IMM64(R1, 3),
7033 BPF_LD_IMM64(R2, 3),
7034 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
7036 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7044 /* Mainly testing JIT + imm64 here. */
7045 "JMP_JGE_X: ldimm64 test 1",
7047 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7048 BPF_LD_IMM64(R1, 3),
7049 BPF_LD_IMM64(R2, 2),
7050 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
7051 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7052 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
7057 { { 0, 0xeeeeeeeeU } },
7060 "JMP_JGE_X: ldimm64 test 2",
7062 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7063 BPF_LD_IMM64(R1, 3),
7064 BPF_LD_IMM64(R2, 2),
7065 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
7066 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7071 { { 0, 0xffffffffU } },
7074 "JMP_JGE_X: ldimm64 test 3",
7076 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7077 BPF_LD_IMM64(R1, 3),
7078 BPF_LD_IMM64(R2, 2),
7079 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
7080 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7081 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
7089 "JMP_JLE_X: ldimm64 test 1",
7091 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7092 BPF_LD_IMM64(R1, 3),
7093 BPF_LD_IMM64(R2, 2),
7094 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
7095 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7096 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
7101 { { 0, 0xeeeeeeeeU } },
7104 "JMP_JLE_X: ldimm64 test 2",
7106 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7107 BPF_LD_IMM64(R1, 3),
7108 BPF_LD_IMM64(R2, 2),
7109 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
7110 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7115 { { 0, 0xffffffffU } },
7118 "JMP_JLE_X: ldimm64 test 3",
7120 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7121 BPF_LD_IMM64(R1, 3),
7122 BPF_LD_IMM64(R2, 2),
7123 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
7124 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7125 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
7132 /* BPF_JMP | BPF_JNE | BPF_X */
7134 "JMP_JNE_X: if (3 != 2) return 1",
7136 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7137 BPF_LD_IMM64(R1, 3),
7138 BPF_LD_IMM64(R2, 2),
7139 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
7141 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7148 /* BPF_JMP | BPF_JEQ | BPF_X */
7150 "JMP_JEQ_X: if (3 == 3) return 1",
7152 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7153 BPF_LD_IMM64(R1, 3),
7154 BPF_LD_IMM64(R2, 3),
7155 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
7157 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7164 /* BPF_JMP | BPF_JSET | BPF_X */
7166 "JMP_JSET_X: if (0x3 & 0x2) return 1",
7168 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7169 BPF_LD_IMM64(R1, 3),
7170 BPF_LD_IMM64(R2, 2),
7171 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
7173 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7181 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
7183 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7184 BPF_LD_IMM64(R1, 3),
7185 BPF_LD_IMM64(R2, 0xffffffff),
7186 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
7188 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7195 { /* Mainly checking JIT here. */
7196 "BPF_MAXINSNS: Very long conditional jump",
7198 INTERNAL | FLAG_NO_DATA,
7201 .fill_helper = bpf_fill_long_jmp,
7204 "JMP_JA: Jump, gap, jump, ...",
7206 CLASSIC | FLAG_NO_DATA,
7208 { { 0, 0xababcbac } },
7209 .fill_helper = bpf_fill_ja,
7211 { /* Mainly checking JIT here. */
7212 "BPF_MAXINSNS: Maximum possible literals",
7214 CLASSIC | FLAG_NO_DATA,
7216 { { 0, 0xffffffff } },
7217 .fill_helper = bpf_fill_maxinsns1,
7219 { /* Mainly checking JIT here. */
7220 "BPF_MAXINSNS: Single literal",
7222 CLASSIC | FLAG_NO_DATA,
7224 { { 0, 0xfefefefe } },
7225 .fill_helper = bpf_fill_maxinsns2,
7227 { /* Mainly checking JIT here. */
7228 "BPF_MAXINSNS: Run/add until end",
7230 CLASSIC | FLAG_NO_DATA,
7232 { { 0, 0x947bf368 } },
7233 .fill_helper = bpf_fill_maxinsns3,
7236 "BPF_MAXINSNS: Too many instructions",
7238 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
7241 .fill_helper = bpf_fill_maxinsns4,
7242 .expected_errcode = -EINVAL,
7244 { /* Mainly checking JIT here. */
7245 "BPF_MAXINSNS: Very long jump",
7247 CLASSIC | FLAG_NO_DATA,
7249 { { 0, 0xabababab } },
7250 .fill_helper = bpf_fill_maxinsns5,
7252 { /* Mainly checking JIT here. */
7253 "BPF_MAXINSNS: Ctx heavy transformations",
7258 { 1, SKB_VLAN_PRESENT },
7259 { 10, SKB_VLAN_PRESENT }
7261 .fill_helper = bpf_fill_maxinsns6,
7263 { /* Mainly checking JIT here. */
7264 "BPF_MAXINSNS: Call heavy transformations",
7266 CLASSIC | FLAG_NO_DATA,
7268 { { 1, 0 }, { 10, 0 } },
7269 .fill_helper = bpf_fill_maxinsns7,
7271 { /* Mainly checking JIT here. */
7272 "BPF_MAXINSNS: Jump heavy test",
7274 CLASSIC | FLAG_NO_DATA,
7276 { { 0, 0xffffffff } },
7277 .fill_helper = bpf_fill_maxinsns8,
7279 { /* Mainly checking JIT here. */
7280 "BPF_MAXINSNS: Very long jump backwards",
7282 INTERNAL | FLAG_NO_DATA,
7284 { { 0, 0xcbababab } },
7285 .fill_helper = bpf_fill_maxinsns9,
7287 { /* Mainly checking JIT here. */
7288 "BPF_MAXINSNS: Edge hopping nuthouse",
7290 INTERNAL | FLAG_NO_DATA,
7292 { { 0, 0xabababac } },
7293 .fill_helper = bpf_fill_maxinsns10,
7296 "BPF_MAXINSNS: Jump, gap, jump, ...",
7298 CLASSIC | FLAG_NO_DATA,
7300 { { 0, 0xababcbac } },
7301 .fill_helper = bpf_fill_maxinsns11,
7304 "BPF_MAXINSNS: jump over MSH",
7306 CLASSIC | FLAG_EXPECTED_FAIL,
7307 { 0xfa, 0xfb, 0xfc, 0xfd, },
7308 { { 4, 0xabababab } },
7309 .fill_helper = bpf_fill_maxinsns12,
7310 .expected_errcode = -EINVAL,
7313 "BPF_MAXINSNS: exec all MSH",
7316 { 0xfa, 0xfb, 0xfc, 0xfd, },
7317 { { 4, 0xababab83 } },
7318 .fill_helper = bpf_fill_maxinsns13,
7321 "BPF_MAXINSNS: ld_abs+get_processor_id",
7326 .fill_helper = bpf_fill_ld_abs_get_processor_id,
7329 * LD_IND / LD_ABS on fragmented SKBs
7334 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7335 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
7336 BPF_STMT(BPF_RET | BPF_A, 0x0),
7338 CLASSIC | FLAG_SKB_FRAG,
7342 0x42, 0x00, 0x00, 0x00,
7343 0x43, 0x44, 0x00, 0x00,
7344 0x21, 0x07, 0x19, 0x83,
7348 "LD_IND halfword frag",
7350 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7351 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
7352 BPF_STMT(BPF_RET | BPF_A, 0x0),
7354 CLASSIC | FLAG_SKB_FRAG,
7358 0x42, 0x00, 0x00, 0x00,
7359 0x43, 0x44, 0x00, 0x00,
7360 0x21, 0x07, 0x19, 0x83,
7366 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7367 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
7368 BPF_STMT(BPF_RET | BPF_A, 0x0),
7370 CLASSIC | FLAG_SKB_FRAG,
7372 { {0x40, 0x21071983} },
7374 0x42, 0x00, 0x00, 0x00,
7375 0x43, 0x44, 0x00, 0x00,
7376 0x21, 0x07, 0x19, 0x83,
7380 "LD_IND halfword mixed head/frag",
7382 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7383 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7384 BPF_STMT(BPF_RET | BPF_A, 0x0),
7386 CLASSIC | FLAG_SKB_FRAG,
7387 { [0x3e] = 0x25, [0x3f] = 0x05, },
7389 .frag_data = { 0x19, 0x82 },
7392 "LD_IND word mixed head/frag",
7394 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7395 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7396 BPF_STMT(BPF_RET | BPF_A, 0x0),
7398 CLASSIC | FLAG_SKB_FRAG,
7399 { [0x3e] = 0x25, [0x3f] = 0x05, },
7400 { {0x40, 0x25051982} },
7401 .frag_data = { 0x19, 0x82 },
7406 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
7407 BPF_STMT(BPF_RET | BPF_A, 0x0),
7409 CLASSIC | FLAG_SKB_FRAG,
7413 0x42, 0x00, 0x00, 0x00,
7414 0x43, 0x44, 0x00, 0x00,
7415 0x21, 0x07, 0x19, 0x83,
7419 "LD_ABS halfword frag",
7421 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
7422 BPF_STMT(BPF_RET | BPF_A, 0x0),
7424 CLASSIC | FLAG_SKB_FRAG,
7428 0x42, 0x00, 0x00, 0x00,
7429 0x43, 0x44, 0x00, 0x00,
7430 0x21, 0x07, 0x19, 0x83,
7436 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
7437 BPF_STMT(BPF_RET | BPF_A, 0x0),
7439 CLASSIC | FLAG_SKB_FRAG,
7441 { {0x40, 0x21071983} },
7443 0x42, 0x00, 0x00, 0x00,
7444 0x43, 0x44, 0x00, 0x00,
7445 0x21, 0x07, 0x19, 0x83,
7449 "LD_ABS halfword mixed head/frag",
7451 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7452 BPF_STMT(BPF_RET | BPF_A, 0x0),
7454 CLASSIC | FLAG_SKB_FRAG,
7455 { [0x3e] = 0x25, [0x3f] = 0x05, },
7457 .frag_data = { 0x19, 0x82 },
7460 "LD_ABS word mixed head/frag",
7462 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
7463 BPF_STMT(BPF_RET | BPF_A, 0x0),
7465 CLASSIC | FLAG_SKB_FRAG,
7466 { [0x3e] = 0x25, [0x3f] = 0x05, },
7467 { {0x40, 0x25051982} },
7468 .frag_data = { 0x19, 0x82 },
7471 * LD_IND / LD_ABS on non fragmented SKBs
7475 * this tests that the JIT/interpreter correctly resets X
7476 * before using it in an LD_IND instruction.
7478 "LD_IND byte default X",
7480 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7481 BPF_STMT(BPF_RET | BPF_A, 0x0),
7488 "LD_IND byte positive offset",
7490 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7491 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7492 BPF_STMT(BPF_RET | BPF_A, 0x0),
7495 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7499 "LD_IND byte negative offset",
7501 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7502 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
7503 BPF_STMT(BPF_RET | BPF_A, 0x0),
7506 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7510 "LD_IND byte positive offset, all ff",
7512 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7513 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7514 BPF_STMT(BPF_RET | BPF_A, 0x0),
7517 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7521 "LD_IND byte positive offset, out of bounds",
7523 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7524 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7525 BPF_STMT(BPF_RET | BPF_A, 0x0),
7528 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7532 "LD_IND byte negative offset, out of bounds",
7534 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7535 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
7536 BPF_STMT(BPF_RET | BPF_A, 0x0),
7539 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7543 "LD_IND byte negative offset, multiple calls",
7545 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7546 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
7547 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
7548 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
7549 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
7550 BPF_STMT(BPF_RET | BPF_A, 0x0),
7553 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7557 "LD_IND halfword positive offset",
7559 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7560 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
7561 BPF_STMT(BPF_RET | BPF_A, 0x0),
7565 [0x1c] = 0xaa, [0x1d] = 0x55,
7566 [0x1e] = 0xbb, [0x1f] = 0x66,
7567 [0x20] = 0xcc, [0x21] = 0x77,
7568 [0x22] = 0xdd, [0x23] = 0x88,
7570 { {0x40, 0xdd88 } },
7573 "LD_IND halfword negative offset",
7575 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7576 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
7577 BPF_STMT(BPF_RET | BPF_A, 0x0),
7581 [0x1c] = 0xaa, [0x1d] = 0x55,
7582 [0x1e] = 0xbb, [0x1f] = 0x66,
7583 [0x20] = 0xcc, [0x21] = 0x77,
7584 [0x22] = 0xdd, [0x23] = 0x88,
7586 { {0x40, 0xbb66 } },
7589 "LD_IND halfword unaligned",
7591 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7592 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7593 BPF_STMT(BPF_RET | BPF_A, 0x0),
7597 [0x1c] = 0xaa, [0x1d] = 0x55,
7598 [0x1e] = 0xbb, [0x1f] = 0x66,
7599 [0x20] = 0xcc, [0x21] = 0x77,
7600 [0x22] = 0xdd, [0x23] = 0x88,
7602 { {0x40, 0x66cc } },
7605 "LD_IND halfword positive offset, all ff",
7607 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
7608 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7609 BPF_STMT(BPF_RET | BPF_A, 0x0),
7612 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7613 { {0x40, 0xffff } },
7616 "LD_IND halfword positive offset, out of bounds",
7618 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7619 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7620 BPF_STMT(BPF_RET | BPF_A, 0x0),
7623 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7627 "LD_IND halfword negative offset, out of bounds",
7629 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7630 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
7631 BPF_STMT(BPF_RET | BPF_A, 0x0),
7634 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7638 "LD_IND word positive offset",
7640 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7641 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
7642 BPF_STMT(BPF_RET | BPF_A, 0x0),
7646 [0x1c] = 0xaa, [0x1d] = 0x55,
7647 [0x1e] = 0xbb, [0x1f] = 0x66,
7648 [0x20] = 0xcc, [0x21] = 0x77,
7649 [0x22] = 0xdd, [0x23] = 0x88,
7650 [0x24] = 0xee, [0x25] = 0x99,
7651 [0x26] = 0xff, [0x27] = 0xaa,
7653 { {0x40, 0xee99ffaa } },
7656 "LD_IND word negative offset",
7658 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7659 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
7660 BPF_STMT(BPF_RET | BPF_A, 0x0),
7664 [0x1c] = 0xaa, [0x1d] = 0x55,
7665 [0x1e] = 0xbb, [0x1f] = 0x66,
7666 [0x20] = 0xcc, [0x21] = 0x77,
7667 [0x22] = 0xdd, [0x23] = 0x88,
7668 [0x24] = 0xee, [0x25] = 0x99,
7669 [0x26] = 0xff, [0x27] = 0xaa,
7671 { {0x40, 0xaa55bb66 } },
7674 "LD_IND word unaligned (addr & 3 == 2)",
7676 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7677 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7678 BPF_STMT(BPF_RET | BPF_A, 0x0),
7682 [0x1c] = 0xaa, [0x1d] = 0x55,
7683 [0x1e] = 0xbb, [0x1f] = 0x66,
7684 [0x20] = 0xcc, [0x21] = 0x77,
7685 [0x22] = 0xdd, [0x23] = 0x88,
7686 [0x24] = 0xee, [0x25] = 0x99,
7687 [0x26] = 0xff, [0x27] = 0xaa,
7689 { {0x40, 0xbb66cc77 } },
7692 "LD_IND word unaligned (addr & 3 == 1)",
7694 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7695 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
7696 BPF_STMT(BPF_RET | BPF_A, 0x0),
7700 [0x1c] = 0xaa, [0x1d] = 0x55,
7701 [0x1e] = 0xbb, [0x1f] = 0x66,
7702 [0x20] = 0xcc, [0x21] = 0x77,
7703 [0x22] = 0xdd, [0x23] = 0x88,
7704 [0x24] = 0xee, [0x25] = 0x99,
7705 [0x26] = 0xff, [0x27] = 0xaa,
7707 { {0x40, 0x55bb66cc } },
7710 "LD_IND word unaligned (addr & 3 == 3)",
7712 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7713 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
7714 BPF_STMT(BPF_RET | BPF_A, 0x0),
7718 [0x1c] = 0xaa, [0x1d] = 0x55,
7719 [0x1e] = 0xbb, [0x1f] = 0x66,
7720 [0x20] = 0xcc, [0x21] = 0x77,
7721 [0x22] = 0xdd, [0x23] = 0x88,
7722 [0x24] = 0xee, [0x25] = 0x99,
7723 [0x26] = 0xff, [0x27] = 0xaa,
7725 { {0x40, 0x66cc77dd } },
7728 "LD_IND word positive offset, all ff",
7730 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7731 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7732 BPF_STMT(BPF_RET | BPF_A, 0x0),
7735 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7736 { {0x40, 0xffffffff } },
7739 "LD_IND word positive offset, out of bounds",
7741 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7742 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7743 BPF_STMT(BPF_RET | BPF_A, 0x0),
7746 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7750 "LD_IND word negative offset, out of bounds",
7752 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7753 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
7754 BPF_STMT(BPF_RET | BPF_A, 0x0),
7757 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7763 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
7764 BPF_STMT(BPF_RET | BPF_A, 0x0),
7768 [0x1c] = 0xaa, [0x1d] = 0x55,
7769 [0x1e] = 0xbb, [0x1f] = 0x66,
7770 [0x20] = 0xcc, [0x21] = 0x77,
7771 [0x22] = 0xdd, [0x23] = 0x88,
7772 [0x24] = 0xee, [0x25] = 0x99,
7773 [0x26] = 0xff, [0x27] = 0xaa,
7778 "LD_ABS byte positive offset, all ff",
7780 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7781 BPF_STMT(BPF_RET | BPF_A, 0x0),
7784 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7788 "LD_ABS byte positive offset, out of bounds",
7790 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7791 BPF_STMT(BPF_RET | BPF_A, 0x0),
7794 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7798 "LD_ABS byte negative offset, out of bounds load",
7800 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
7801 BPF_STMT(BPF_RET | BPF_A, 0x0),
7803 CLASSIC | FLAG_EXPECTED_FAIL,
7804 .expected_errcode = -EINVAL,
7807 "LD_ABS byte negative offset, in bounds",
7809 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7810 BPF_STMT(BPF_RET | BPF_A, 0x0),
7813 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7817 "LD_ABS byte negative offset, out of bounds",
7819 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7820 BPF_STMT(BPF_RET | BPF_A, 0x0),
7823 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7827 "LD_ABS byte negative offset, multiple calls",
7829 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
7830 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
7831 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
7832 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7833 BPF_STMT(BPF_RET | BPF_A, 0x0),
7836 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7842 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
7843 BPF_STMT(BPF_RET | BPF_A, 0x0),
7847 [0x1c] = 0xaa, [0x1d] = 0x55,
7848 [0x1e] = 0xbb, [0x1f] = 0x66,
7849 [0x20] = 0xcc, [0x21] = 0x77,
7850 [0x22] = 0xdd, [0x23] = 0x88,
7851 [0x24] = 0xee, [0x25] = 0x99,
7852 [0x26] = 0xff, [0x27] = 0xaa,
7854 { {0x40, 0xdd88 } },
7857 "LD_ABS halfword unaligned",
7859 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
7860 BPF_STMT(BPF_RET | BPF_A, 0x0),
7864 [0x1c] = 0xaa, [0x1d] = 0x55,
7865 [0x1e] = 0xbb, [0x1f] = 0x66,
7866 [0x20] = 0xcc, [0x21] = 0x77,
7867 [0x22] = 0xdd, [0x23] = 0x88,
7868 [0x24] = 0xee, [0x25] = 0x99,
7869 [0x26] = 0xff, [0x27] = 0xaa,
7871 { {0x40, 0x99ff } },
7874 "LD_ABS halfword positive offset, all ff",
7876 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
7877 BPF_STMT(BPF_RET | BPF_A, 0x0),
7880 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7881 { {0x40, 0xffff } },
7884 "LD_ABS halfword positive offset, out of bounds",
7886 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7887 BPF_STMT(BPF_RET | BPF_A, 0x0),
7890 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7894 "LD_ABS halfword negative offset, out of bounds load",
7896 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
7897 BPF_STMT(BPF_RET | BPF_A, 0x0),
7899 CLASSIC | FLAG_EXPECTED_FAIL,
7900 .expected_errcode = -EINVAL,
7903 "LD_ABS halfword negative offset, in bounds",
7905 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7906 BPF_STMT(BPF_RET | BPF_A, 0x0),
7909 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7910 { {0x40, 0x1982 }, },
7913 "LD_ABS halfword negative offset, out of bounds",
7915 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7916 BPF_STMT(BPF_RET | BPF_A, 0x0),
7919 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7925 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
7926 BPF_STMT(BPF_RET | BPF_A, 0x0),
7930 [0x1c] = 0xaa, [0x1d] = 0x55,
7931 [0x1e] = 0xbb, [0x1f] = 0x66,
7932 [0x20] = 0xcc, [0x21] = 0x77,
7933 [0x22] = 0xdd, [0x23] = 0x88,
7934 [0x24] = 0xee, [0x25] = 0x99,
7935 [0x26] = 0xff, [0x27] = 0xaa,
7937 { {0x40, 0xaa55bb66 } },
7940 "LD_ABS word unaligned (addr & 3 == 2)",
7942 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
7943 BPF_STMT(BPF_RET | BPF_A, 0x0),
7947 [0x1c] = 0xaa, [0x1d] = 0x55,
7948 [0x1e] = 0xbb, [0x1f] = 0x66,
7949 [0x20] = 0xcc, [0x21] = 0x77,
7950 [0x22] = 0xdd, [0x23] = 0x88,
7951 [0x24] = 0xee, [0x25] = 0x99,
7952 [0x26] = 0xff, [0x27] = 0xaa,
7954 { {0x40, 0xdd88ee99 } },
7957 "LD_ABS word unaligned (addr & 3 == 1)",
7959 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
7960 BPF_STMT(BPF_RET | BPF_A, 0x0),
7964 [0x1c] = 0xaa, [0x1d] = 0x55,
7965 [0x1e] = 0xbb, [0x1f] = 0x66,
7966 [0x20] = 0xcc, [0x21] = 0x77,
7967 [0x22] = 0xdd, [0x23] = 0x88,
7968 [0x24] = 0xee, [0x25] = 0x99,
7969 [0x26] = 0xff, [0x27] = 0xaa,
7971 { {0x40, 0x77dd88ee } },
7974 "LD_ABS word unaligned (addr & 3 == 3)",
7976 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
7977 BPF_STMT(BPF_RET | BPF_A, 0x0),
7981 [0x1c] = 0xaa, [0x1d] = 0x55,
7982 [0x1e] = 0xbb, [0x1f] = 0x66,
7983 [0x20] = 0xcc, [0x21] = 0x77,
7984 [0x22] = 0xdd, [0x23] = 0x88,
7985 [0x24] = 0xee, [0x25] = 0x99,
7986 [0x26] = 0xff, [0x27] = 0xaa,
7988 { {0x40, 0x88ee99ff } },
7991 "LD_ABS word positive offset, all ff",
7993 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
7994 BPF_STMT(BPF_RET | BPF_A, 0x0),
7997 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7998 { {0x40, 0xffffffff } },
8001 "LD_ABS word positive offset, out of bounds",
8003 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
8004 BPF_STMT(BPF_RET | BPF_A, 0x0),
8007 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8011 "LD_ABS word negative offset, out of bounds load",
8013 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
8014 BPF_STMT(BPF_RET | BPF_A, 0x0),
8016 CLASSIC | FLAG_EXPECTED_FAIL,
8017 .expected_errcode = -EINVAL,
8020 "LD_ABS word negative offset, in bounds",
8022 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
8023 BPF_STMT(BPF_RET | BPF_A, 0x0),
8026 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8027 { {0x40, 0x25051982 }, },
8030 "LD_ABS word negative offset, out of bounds",
8032 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
8033 BPF_STMT(BPF_RET | BPF_A, 0x0),
8036 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8040 "LDX_MSH standalone, preserved A",
8042 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8043 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
8044 BPF_STMT(BPF_RET | BPF_A, 0x0),
8047 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8048 { {0x40, 0xffeebbaa }, },
8051 "LDX_MSH standalone, preserved A 2",
8053 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
8054 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
8055 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
8056 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
8057 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
8058 BPF_STMT(BPF_RET | BPF_A, 0x0),
8061 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8062 { {0x40, 0x175e9d63 }, },
8065 "LDX_MSH standalone, test result 1",
8067 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8068 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
8069 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8070 BPF_STMT(BPF_RET | BPF_A, 0x0),
8073 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8077 "LDX_MSH standalone, test result 2",
8079 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8080 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
8081 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8082 BPF_STMT(BPF_RET | BPF_A, 0x0),
8085 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8089 "LDX_MSH standalone, negative offset",
8091 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8092 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
8093 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8094 BPF_STMT(BPF_RET | BPF_A, 0x0),
8097 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8101 "LDX_MSH standalone, negative offset 2",
8103 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8104 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
8105 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8106 BPF_STMT(BPF_RET | BPF_A, 0x0),
8109 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8113 "LDX_MSH standalone, out of bounds",
8115 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8116 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
8117 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8118 BPF_STMT(BPF_RET | BPF_A, 0x0),
8121 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8125 * verify that the interpreter or JIT correctly sets A and X
8136 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8137 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
8138 BPF_STMT(BPF_RET | BPF_A, 0x0),
8140 CLASSIC | FLAG_NO_DATA,
8151 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
8152 BPF_STMT(BPF_RET | BPF_A, 0x0),
8154 CLASSIC | FLAG_NO_DATA,
8166 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
8167 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
8168 BPF_STMT(BPF_RET | BPF_A, 0x0),
8170 CLASSIC | FLAG_NO_DATA,
8181 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
8182 BPF_STMT(BPF_RET | BPF_A, 0x0),
8184 CLASSIC | FLAG_NO_DATA,
8196 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8197 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
8198 BPF_STMT(BPF_RET | BPF_A, 0x0),
8200 CLASSIC | FLAG_NO_DATA,
8211 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
8212 BPF_STMT(BPF_RET | BPF_A, 0x0),
8214 CLASSIC | FLAG_NO_DATA,
8223 * A = A / X ; this halt the filter execution if X is 0
8226 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8227 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
8228 BPF_STMT(BPF_RET | BPF_K, 0x42),
8230 CLASSIC | FLAG_NO_DATA,
8241 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
8242 BPF_STMT(BPF_RET | BPF_A, 0x0),
8244 CLASSIC | FLAG_NO_DATA,
8253 * A = A mod X ; this halt the filter execution if X is 0
8256 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8257 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
8258 BPF_STMT(BPF_RET | BPF_K, 0x42),
8260 CLASSIC | FLAG_NO_DATA,
8271 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
8272 BPF_STMT(BPF_RET | BPF_A, 0x0),
8274 CLASSIC | FLAG_NO_DATA,
8286 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
8287 BPF_STMT(BPF_RET | BPF_K, 0x42),
8288 BPF_STMT(BPF_RET | BPF_K, 0x66),
8290 CLASSIC | FLAG_NO_DATA,
8303 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
8304 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
8305 BPF_STMT(BPF_RET | BPF_K, 0x42),
8306 BPF_STMT(BPF_RET | BPF_K, 0x66),
8308 CLASSIC | FLAG_NO_DATA,
8312 /* Checking interpreter vs JIT wrt signed extended imms. */
8314 "JNE signed compare, test 1",
8316 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8317 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8318 BPF_MOV64_REG(R2, R1),
8319 BPF_ALU64_REG(BPF_AND, R2, R3),
8320 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8321 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
8322 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8330 "JNE signed compare, test 2",
8332 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8333 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8334 BPF_MOV64_REG(R2, R1),
8335 BPF_ALU64_REG(BPF_AND, R2, R3),
8336 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8337 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
8338 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8346 "JNE signed compare, test 3",
8348 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8349 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8350 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
8351 BPF_MOV64_REG(R2, R1),
8352 BPF_ALU64_REG(BPF_AND, R2, R3),
8353 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8354 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
8355 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8363 "JNE signed compare, test 4",
8365 BPF_LD_IMM64(R1, -17104896),
8366 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8367 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
8368 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8376 "JNE signed compare, test 5",
8378 BPF_LD_IMM64(R1, 0xfefb0000),
8379 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8380 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
8381 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8389 "JNE signed compare, test 6",
8391 BPF_LD_IMM64(R1, 0x7efb0000),
8392 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8393 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
8394 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8402 "JNE signed compare, test 7",
8404 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
8405 BPF_STMT(BPF_MISC | BPF_TAX, 0),
8406 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
8407 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
8408 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
8409 BPF_STMT(BPF_RET | BPF_K, 1),
8410 BPF_STMT(BPF_RET | BPF_K, 2),
8412 CLASSIC | FLAG_NO_DATA,
8418 static struct net_device dev;
8420 static struct sk_buff *populate_skb(char *buf, int size)
8422 struct sk_buff *skb;
8424 if (size >= MAX_DATA)
8427 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
8431 __skb_put_data(skb, buf, size);
8433 /* Initialize a fake skb with test pattern. */
8434 skb_reset_mac_header(skb);
8435 skb->protocol = htons(ETH_P_IP);
8436 skb->pkt_type = SKB_TYPE;
8437 skb->mark = SKB_MARK;
8438 skb->hash = SKB_HASH;
8439 skb->queue_mapping = SKB_QUEUE_MAP;
8440 skb->vlan_tci = SKB_VLAN_TCI;
8441 skb->vlan_present = SKB_VLAN_PRESENT;
8442 skb->vlan_proto = htons(ETH_P_IP);
8443 dev_net_set(&dev, &init_net);
8445 skb->dev->ifindex = SKB_DEV_IFINDEX;
8446 skb->dev->type = SKB_DEV_TYPE;
8447 skb_set_network_header(skb, min(size, ETH_HLEN));
8452 static void *generate_test_data(struct bpf_test *test, int sub)
8454 struct sk_buff *skb;
8457 if (test->aux & FLAG_NO_DATA)
8460 /* Test case expects an skb, so populate one. Various
8461 * subtests generate skbs of different sizes based on
8464 skb = populate_skb(test->data, test->test[sub].data_size);
8468 if (test->aux & FLAG_SKB_FRAG) {
8470 * when the test requires a fragmented skb, add a
8471 * single fragment to the skb, filled with
8476 page = alloc_page(GFP_KERNEL);
8484 memcpy(ptr, test->frag_data, MAX_DATA);
8486 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
8498 static void release_test_data(const struct bpf_test *test, void *data)
8500 if (test->aux & FLAG_NO_DATA)
8506 static int filter_length(int which)
8508 struct sock_filter *fp;
8511 if (tests[which].fill_helper)
8512 return tests[which].u.ptr.len;
8514 fp = tests[which].u.insns;
8515 for (len = MAX_INSNS - 1; len > 0; --len)
8516 if (fp[len].code != 0 || fp[len].k != 0)
8522 static void *filter_pointer(int which)
8524 if (tests[which].fill_helper)
8525 return tests[which].u.ptr.insns;
8527 return tests[which].u.insns;
8530 static struct bpf_prog *generate_filter(int which, int *err)
8532 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
8533 unsigned int flen = filter_length(which);
8534 void *fptr = filter_pointer(which);
8535 struct sock_fprog_kern fprog;
8536 struct bpf_prog *fp;
8538 switch (test_type) {
8540 fprog.filter = fptr;
8543 *err = bpf_prog_create(&fp, &fprog);
8544 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
8545 if (*err == tests[which].expected_errcode) {
8547 /* Verifier rejected filter as expected. */
8551 pr_cont("UNEXPECTED_PASS\n");
8552 /* Verifier didn't reject the test that's
8553 * bad enough, just return!
8560 pr_cont("FAIL to prog_create err=%d len=%d\n",
8567 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
8569 pr_cont("UNEXPECTED_FAIL no memory left\n");
8575 /* Type doesn't really matter here as long as it's not unspec. */
8576 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
8577 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
8578 fp->aux->stack_depth = tests[which].stack_depth;
8580 /* We cannot error here as we don't need type compatibility
8583 fp = bpf_prog_select_runtime(fp, err);
8585 pr_cont("FAIL to select_runtime err=%d\n", *err);
8595 static void release_filter(struct bpf_prog *fp, int which)
8597 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
8599 switch (test_type) {
8601 bpf_prog_destroy(fp);
8609 static int __run_one(const struct bpf_prog *fp, const void *data,
8610 int runs, u64 *duration)
8616 start = ktime_get_ns();
8618 for (i = 0; i < runs; i++)
8619 ret = bpf_prog_run(fp, data);
8621 finish = ktime_get_ns();
8624 *duration = finish - start;
8625 do_div(*duration, runs);
8630 static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
8632 int err_cnt = 0, i, runs = MAX_TESTRUNS;
8634 for (i = 0; i < MAX_SUBTESTS; i++) {
8640 * NOTE: Several sub-tests may be present, in which case
8641 * a zero {data_size, result} tuple indicates the end of
8642 * the sub-test array. The first test is always run,
8643 * even if both data_size and result happen to be zero.
8646 test->test[i].data_size == 0 &&
8647 test->test[i].result == 0)
8650 data = generate_test_data(test, i);
8651 if (!data && !(test->aux & FLAG_NO_DATA)) {
8652 pr_cont("data generation failed ");
8656 ret = __run_one(fp, data, runs, &duration);
8657 release_test_data(test, data);
8659 if (ret == test->test[i].result) {
8660 pr_cont("%lld ", duration);
8662 pr_cont("ret %d != %d ", ret,
8663 test->test[i].result);
8671 static char test_name[64];
8672 module_param_string(test_name, test_name, sizeof(test_name), 0);
8674 static int test_id = -1;
8675 module_param(test_id, int, 0);
8677 static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
8678 module_param_array(test_range, int, NULL, 0);
8680 static __init int find_test_index(const char *test_name)
8684 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8685 if (!strcmp(tests[i].descr, test_name))
8691 static __init int prepare_bpf_tests(void)
8697 * if a test_id was specified, use test_range to
8698 * cover only that test.
8700 if (test_id >= ARRAY_SIZE(tests)) {
8701 pr_err("test_bpf: invalid test_id specified.\n");
8705 test_range[0] = test_id;
8706 test_range[1] = test_id;
8707 } else if (*test_name) {
8709 * if a test_name was specified, find it and setup
8710 * test_range to cover only that test.
8712 int idx = find_test_index(test_name);
8715 pr_err("test_bpf: no test named '%s' found.\n",
8719 test_range[0] = idx;
8720 test_range[1] = idx;
8723 * check that the supplied test_range is valid.
8725 if (test_range[0] >= ARRAY_SIZE(tests) ||
8726 test_range[1] >= ARRAY_SIZE(tests) ||
8727 test_range[0] < 0 || test_range[1] < 0) {
8728 pr_err("test_bpf: test_range is out of bound.\n");
8732 if (test_range[1] < test_range[0]) {
8733 pr_err("test_bpf: test_range is ending before it starts.\n");
8738 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8739 if (tests[i].fill_helper &&
8740 tests[i].fill_helper(&tests[i]) < 0)
8747 static __init void destroy_bpf_tests(void)
8751 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8752 if (tests[i].fill_helper)
8753 kfree(tests[i].u.ptr.insns);
8757 static bool exclude_test(int test_id)
8759 return test_id < test_range[0] || test_id > test_range[1];
8762 static __init struct sk_buff *build_test_skb(void)
8764 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
8765 struct sk_buff *skb[2];
8766 struct page *page[2];
8767 int i, data_size = 8;
8769 for (i = 0; i < 2; i++) {
8770 page[i] = alloc_page(GFP_KERNEL);
8778 /* this will set skb[i]->head_frag */
8779 skb[i] = dev_alloc_skb(headroom + data_size);
8787 skb_reserve(skb[i], headroom);
8788 skb_put(skb[i], data_size);
8789 skb[i]->protocol = htons(ETH_P_IP);
8790 skb_reset_network_header(skb[i]);
8791 skb_set_mac_header(skb[i], -ETH_HLEN);
8793 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
8794 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
8798 skb_shinfo(skb[0])->gso_size = 1448;
8799 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
8800 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
8801 skb_shinfo(skb[0])->gso_segs = 0;
8802 skb_shinfo(skb[0])->frag_list = skb[1];
8804 /* adjust skb[0]'s len */
8805 skb[0]->len += skb[1]->len;
8806 skb[0]->data_len += skb[1]->data_len;
8807 skb[0]->truesize += skb[1]->truesize;
8812 __free_page(page[1]);
8816 __free_page(page[0]);
8821 static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
8823 unsigned int alloc_size = 2000;
8824 unsigned int headroom = 102, doffset = 72, data_size = 1308;
8825 struct sk_buff *skb[2];
8828 /* skbs linked in a frag_list, both with linear data, with head_frag=0
8829 * (data allocated by kmalloc), both have tcp data of 1308 bytes
8830 * (total payload is 2616 bytes).
8831 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
8833 for (i = 0; i < 2; i++) {
8834 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
8842 skb[i]->protocol = htons(ETH_P_IPV6);
8843 skb_reserve(skb[i], headroom);
8844 skb_put(skb[i], doffset + data_size);
8845 skb_reset_network_header(skb[i]);
8847 skb_reset_mac_header(skb[i]);
8849 skb_set_mac_header(skb[i], -ETH_HLEN);
8850 __skb_pull(skb[i], doffset);
8854 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
8857 skb_shinfo(skb[0])->gso_size = 1288;
8858 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
8859 skb_shinfo(skb[0])->gso_segs = 0;
8860 skb_shinfo(skb[0])->frag_list = skb[1];
8862 /* adjust skb[0]'s len */
8863 skb[0]->len += skb[1]->len;
8864 skb[0]->data_len += skb[1]->len;
8865 skb[0]->truesize += skb[1]->truesize;
8875 struct skb_segment_test {
8877 struct sk_buff *(*build_skb)(void);
8878 netdev_features_t features;
8881 static struct skb_segment_test skb_segment_tests[] __initconst = {
8883 .descr = "gso_with_rx_frags",
8884 .build_skb = build_test_skb,
8885 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
8886 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
8889 .descr = "gso_linear_no_head_frag",
8890 .build_skb = build_test_skb_linear_no_head_frag,
8891 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
8892 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
8893 NETIF_F_LLTX_BIT | NETIF_F_GRO |
8894 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
8895 NETIF_F_HW_VLAN_STAG_TX_BIT
8899 static __init int test_skb_segment_single(const struct skb_segment_test *test)
8901 struct sk_buff *skb, *segs;
8904 skb = test->build_skb();
8906 pr_info("%s: failed to build_test_skb", __func__);
8910 segs = skb_segment(skb, test->features);
8911 if (!IS_ERR(segs)) {
8912 kfree_skb_list(segs);
8920 static __init int test_skb_segment(void)
8922 int i, err_cnt = 0, pass_cnt = 0;
8924 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
8925 const struct skb_segment_test *test = &skb_segment_tests[i];
8927 pr_info("#%d %s ", i, test->descr);
8929 if (test_skb_segment_single(test)) {
8938 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
8940 return err_cnt ? -EINVAL : 0;
8943 static __init int test_bpf(void)
8945 int i, err_cnt = 0, pass_cnt = 0;
8946 int jit_cnt = 0, run_cnt = 0;
8948 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8949 struct bpf_prog *fp;
8953 if (exclude_test(i))
8956 pr_info("#%d %s ", i, tests[i].descr);
8958 fp = generate_filter(i, &err);
8968 pr_cont("jited:%u ", fp->jited);
8974 err = run_one(fp, &tests[i]);
8975 release_filter(fp, i);
8978 pr_cont("FAIL (%d times)\n", err);
8986 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
8987 pass_cnt, err_cnt, jit_cnt, run_cnt);
8989 return err_cnt ? -EINVAL : 0;
8992 struct tail_call_test {
8994 struct bpf_insn insns[MAX_INSNS];
9000 * Magic marker used in test snippets for tail calls below.
9001 * BPF_LD/MOV to R2 and R2 with this immediate value is replaced
9002 * with the proper values by the test runner.
9004 #define TAIL_CALL_MARKER 0x7a11ca11
9006 /* Special offset to indicate a NULL call target */
9007 #define TAIL_CALL_NULL 0x7fff
9009 /* Special offset to indicate an out-of-range index */
9010 #define TAIL_CALL_INVALID 0x7ffe
9012 #define TAIL_CALL(offset) \
9013 BPF_LD_IMM64(R2, TAIL_CALL_MARKER), \
9014 BPF_RAW_INSN(BPF_ALU | BPF_MOV | BPF_K, R3, 0, \
9015 offset, TAIL_CALL_MARKER), \
9016 BPF_JMP_IMM(BPF_TAIL_CALL, 0, 0, 0)
9019 * Tail call tests. Each test case may call any other test in the table,
9020 * including itself, specified as a relative index offset from the calling
9021 * test. The index TAIL_CALL_NULL can be used to specify a NULL target
9022 * function to test the JIT error path. Similarly, the index TAIL_CALL_INVALID
9023 * results in a target index that is out of range.
9025 static struct tail_call_test tail_call_tests[] = {
9029 BPF_ALU64_REG(BPF_MOV, R0, R1),
9030 BPF_ALU64_IMM(BPF_ADD, R0, 1),
9038 BPF_ALU64_IMM(BPF_ADD, R1, 2),
9040 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9048 BPF_ALU64_IMM(BPF_ADD, R1, 3),
9050 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9058 BPF_ALU64_IMM(BPF_ADD, R1, 4),
9060 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9066 "Tail call error path, max count reached",
9068 BPF_ALU64_IMM(BPF_ADD, R1, 1),
9069 BPF_ALU64_REG(BPF_MOV, R0, R1),
9073 .result = MAX_TAIL_CALL_CNT + 1,
9076 "Tail call error path, NULL target",
9078 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9079 TAIL_CALL(TAIL_CALL_NULL),
9080 BPF_ALU64_IMM(BPF_MOV, R0, 1),
9086 "Tail call error path, index out of range",
9088 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9089 TAIL_CALL(TAIL_CALL_INVALID),
9090 BPF_ALU64_IMM(BPF_MOV, R0, 1),
9097 static void __init destroy_tail_call_tests(struct bpf_array *progs)
9101 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++)
9103 bpf_prog_free(progs->ptrs[i]);
9107 static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
9109 int ntests = ARRAY_SIZE(tail_call_tests);
9110 struct bpf_array *progs;
9113 /* Allocate the table of programs to be used for tall calls */
9114 progs = kzalloc(sizeof(*progs) + (ntests + 1) * sizeof(progs->ptrs[0]),
9119 /* Create all eBPF programs and populate the table */
9120 for (which = 0; which < ntests; which++) {
9121 struct tail_call_test *test = &tail_call_tests[which];
9122 struct bpf_prog *fp;
9125 /* Compute the number of program instructions */
9126 for (len = 0; len < MAX_INSNS; len++) {
9127 struct bpf_insn *insn = &test->insns[len];
9129 if (len < MAX_INSNS - 1 &&
9130 insn->code == (BPF_LD | BPF_DW | BPF_IMM))
9132 if (insn->code == 0)
9136 /* Allocate and initialize the program */
9137 fp = bpf_prog_alloc(bpf_prog_size(len), 0);
9142 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
9143 fp->aux->stack_depth = test->stack_depth;
9144 memcpy(fp->insnsi, test->insns, len * sizeof(struct bpf_insn));
9146 /* Relocate runtime tail call offsets and addresses */
9147 for (i = 0; i < len; i++) {
9148 struct bpf_insn *insn = &fp->insnsi[i];
9150 if (insn->imm != TAIL_CALL_MARKER)
9153 switch (insn->code) {
9154 case BPF_LD | BPF_DW | BPF_IMM:
9155 insn[0].imm = (u32)(long)progs;
9156 insn[1].imm = ((u64)(long)progs) >> 32;
9159 case BPF_ALU | BPF_MOV | BPF_K:
9160 if (insn->off == TAIL_CALL_NULL)
9162 else if (insn->off == TAIL_CALL_INVALID)
9163 insn->imm = ntests + 1;
9165 insn->imm = which + insn->off;
9170 fp = bpf_prog_select_runtime(fp, &err);
9174 progs->ptrs[which] = fp;
9177 /* The last entry contains a NULL program pointer */
9178 progs->map.max_entries = ntests + 1;
9187 destroy_tail_call_tests(progs);
9191 static __init int test_tail_calls(struct bpf_array *progs)
9193 int i, err_cnt = 0, pass_cnt = 0;
9194 int jit_cnt = 0, run_cnt = 0;
9196 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
9197 struct tail_call_test *test = &tail_call_tests[i];
9198 struct bpf_prog *fp = progs->ptrs[i];
9204 pr_info("#%d %s ", i, test->descr);
9209 pr_cont("jited:%u ", fp->jited);
9215 ret = __run_one(fp, NULL, MAX_TESTRUNS, &duration);
9216 if (ret == test->result) {
9217 pr_cont("%lld PASS", duration);
9220 pr_cont("ret %d != %d FAIL", ret, test->result);
9225 pr_info("%s: Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
9226 __func__, pass_cnt, err_cnt, jit_cnt, run_cnt);
9228 return err_cnt ? -EINVAL : 0;
9231 static int __init test_bpf_init(void)
9233 struct bpf_array *progs = NULL;
9236 ret = prepare_bpf_tests();
9241 destroy_bpf_tests();
9245 ret = prepare_tail_call_tests(&progs);
9248 ret = test_tail_calls(progs);
9249 destroy_tail_call_tests(progs);
9253 return test_skb_segment();
9256 static void __exit test_bpf_exit(void)
9260 module_init(test_bpf_init);
9261 module_exit(test_bpf_exit);
9263 MODULE_LICENSE("GPL");