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)
55 #define FLAG_VERIFIER_ZEXT BIT(3)
56 #define FLAG_LARGE_MEM BIT(4)
59 CLASSIC = BIT(6), /* Old BPF instructions only. */
60 INTERNAL = BIT(7), /* Extended instruction set. */
63 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
68 struct sock_filter insns[MAX_INSNS];
69 struct bpf_insn insns_int[MAX_INSNS];
81 int (*fill_helper)(struct bpf_test *self);
82 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
83 __u8 frag_data[MAX_DATA];
84 int stack_depth; /* for eBPF only, since tests don't call verifier */
85 int nr_testruns; /* Custom run count, defaults to MAX_TESTRUNS if 0 */
88 /* Large test cases need separate allocation and fill handler. */
90 static int bpf_fill_maxinsns1(struct bpf_test *self)
92 unsigned int len = BPF_MAXINSNS;
93 struct sock_filter *insn;
97 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
101 for (i = 0; i < len; i++, k--)
102 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
104 self->u.ptr.insns = insn;
105 self->u.ptr.len = len;
110 static int bpf_fill_maxinsns2(struct bpf_test *self)
112 unsigned int len = BPF_MAXINSNS;
113 struct sock_filter *insn;
116 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
120 for (i = 0; i < len; i++)
121 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
123 self->u.ptr.insns = insn;
124 self->u.ptr.len = len;
129 static int bpf_fill_maxinsns3(struct bpf_test *self)
131 unsigned int len = BPF_MAXINSNS;
132 struct sock_filter *insn;
133 struct rnd_state rnd;
136 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
140 prandom_seed_state(&rnd, 3141592653589793238ULL);
142 for (i = 0; i < len - 1; i++) {
143 __u32 k = prandom_u32_state(&rnd);
145 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
148 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
150 self->u.ptr.insns = insn;
151 self->u.ptr.len = len;
156 static int bpf_fill_maxinsns4(struct bpf_test *self)
158 unsigned int len = BPF_MAXINSNS + 1;
159 struct sock_filter *insn;
162 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
166 for (i = 0; i < len; i++)
167 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
169 self->u.ptr.insns = insn;
170 self->u.ptr.len = len;
175 static int bpf_fill_maxinsns5(struct bpf_test *self)
177 unsigned int len = BPF_MAXINSNS;
178 struct sock_filter *insn;
181 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
185 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
187 for (i = 1; i < len - 1; i++)
188 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
190 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
192 self->u.ptr.insns = insn;
193 self->u.ptr.len = len;
198 static int bpf_fill_maxinsns6(struct bpf_test *self)
200 unsigned int len = BPF_MAXINSNS;
201 struct sock_filter *insn;
204 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
208 for (i = 0; i < len - 1; i++)
209 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
210 SKF_AD_VLAN_TAG_PRESENT);
212 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
214 self->u.ptr.insns = insn;
215 self->u.ptr.len = len;
220 static int bpf_fill_maxinsns7(struct bpf_test *self)
222 unsigned int len = BPF_MAXINSNS;
223 struct sock_filter *insn;
226 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
230 for (i = 0; i < len - 4; i++)
231 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
235 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
237 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
238 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
240 self->u.ptr.insns = insn;
241 self->u.ptr.len = len;
246 static int bpf_fill_maxinsns8(struct bpf_test *self)
248 unsigned int len = BPF_MAXINSNS;
249 struct sock_filter *insn;
250 int i, jmp_off = len - 3;
252 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
256 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
258 for (i = 1; i < len - 1; i++)
259 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
261 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
263 self->u.ptr.insns = insn;
264 self->u.ptr.len = len;
269 static int bpf_fill_maxinsns9(struct bpf_test *self)
271 unsigned int len = BPF_MAXINSNS;
272 struct bpf_insn *insn;
275 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
279 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
280 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
281 insn[2] = BPF_EXIT_INSN();
283 for (i = 3; i < len - 2; i++)
284 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
286 insn[len - 2] = BPF_EXIT_INSN();
287 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
289 self->u.ptr.insns = insn;
290 self->u.ptr.len = len;
295 static int bpf_fill_maxinsns10(struct bpf_test *self)
297 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
298 struct bpf_insn *insn;
301 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
305 for (i = 0; i < hlen / 2; i++)
306 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
307 for (i = hlen - 1; i > hlen / 2; i--)
308 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
310 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
311 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
312 insn[hlen + 1] = BPF_EXIT_INSN();
314 self->u.ptr.insns = insn;
315 self->u.ptr.len = len;
320 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
323 struct sock_filter *insn;
327 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
331 rlen = (len % plen) - 1;
333 for (i = 0; i + plen < len; i += plen)
334 for (j = 0; j < plen; j++)
335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
337 for (j = 0; j < rlen; j++)
338 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
341 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
343 self->u.ptr.insns = insn;
344 self->u.ptr.len = len;
349 static int bpf_fill_maxinsns11(struct bpf_test *self)
351 /* Hits 70 passes on x86_64 and triggers NOPs padding. */
352 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
355 static int bpf_fill_maxinsns12(struct bpf_test *self)
357 unsigned int len = BPF_MAXINSNS;
358 struct sock_filter *insn;
361 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
365 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
367 for (i = 1; i < len - 1; i++)
368 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
370 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
372 self->u.ptr.insns = insn;
373 self->u.ptr.len = len;
378 static int bpf_fill_maxinsns13(struct bpf_test *self)
380 unsigned int len = BPF_MAXINSNS;
381 struct sock_filter *insn;
384 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
388 for (i = 0; i < len - 3; i++)
389 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
391 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
392 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
393 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
395 self->u.ptr.insns = insn;
396 self->u.ptr.len = len;
401 static int bpf_fill_ja(struct bpf_test *self)
403 /* Hits exactly 11 passes on x86_64 JIT. */
404 return __bpf_fill_ja(self, 12, 9);
407 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
409 unsigned int len = BPF_MAXINSNS;
410 struct sock_filter *insn;
413 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
417 for (i = 0; i < len - 1; i += 2) {
418 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
419 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
420 SKF_AD_OFF + SKF_AD_CPU);
423 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
425 self->u.ptr.insns = insn;
426 self->u.ptr.len = len;
431 static int __bpf_fill_stxdw(struct bpf_test *self, int size)
433 unsigned int len = BPF_MAXINSNS;
434 struct bpf_insn *insn;
437 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
441 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
442 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
444 for (i = 2; i < len - 2; i++)
445 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
447 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
448 insn[len - 1] = BPF_EXIT_INSN();
450 self->u.ptr.insns = insn;
451 self->u.ptr.len = len;
452 self->stack_depth = 40;
457 static int bpf_fill_stxw(struct bpf_test *self)
459 return __bpf_fill_stxdw(self, BPF_W);
462 static int bpf_fill_stxdw(struct bpf_test *self)
464 return __bpf_fill_stxdw(self, BPF_DW);
467 static int __bpf_ld_imm64(struct bpf_insn insns[2], u8 reg, s64 imm64)
469 struct bpf_insn tmp[] = {BPF_LD_IMM64(reg, imm64)};
471 memcpy(insns, tmp, sizeof(tmp));
476 * Branch conversion tests. Complex operations can expand to a lot
477 * of instructions when JITed. This in turn may cause jump offsets
478 * to overflow the field size of the native instruction, triggering
479 * a branch conversion mechanism in some JITs.
481 static int __bpf_fill_max_jmp(struct bpf_test *self, int jmp, int imm)
483 struct bpf_insn *insns;
484 int len = S16_MAX + 5;
487 insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL);
491 i = __bpf_ld_imm64(insns, R1, 0x0123456789abcdefULL);
492 insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
493 insns[i++] = BPF_JMP_IMM(jmp, R0, imm, S16_MAX);
494 insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 2);
495 insns[i++] = BPF_EXIT_INSN();
497 while (i < len - 1) {
498 static const int ops[] = {
499 BPF_LSH, BPF_RSH, BPF_ARSH, BPF_ADD,
500 BPF_SUB, BPF_MUL, BPF_DIV, BPF_MOD,
502 int op = ops[(i >> 1) % ARRAY_SIZE(ops)];
505 insns[i++] = BPF_ALU32_REG(op, R0, R1);
507 insns[i++] = BPF_ALU64_REG(op, R0, R1);
510 insns[i++] = BPF_EXIT_INSN();
511 self->u.ptr.insns = insns;
512 self->u.ptr.len = len;
518 /* Branch taken by runtime decision */
519 static int bpf_fill_max_jmp_taken(struct bpf_test *self)
521 return __bpf_fill_max_jmp(self, BPF_JEQ, 1);
524 /* Branch not taken by runtime decision */
525 static int bpf_fill_max_jmp_not_taken(struct bpf_test *self)
527 return __bpf_fill_max_jmp(self, BPF_JEQ, 0);
530 /* Branch always taken, known at JIT time */
531 static int bpf_fill_max_jmp_always_taken(struct bpf_test *self)
533 return __bpf_fill_max_jmp(self, BPF_JGE, 0);
536 /* Branch never taken, known at JIT time */
537 static int bpf_fill_max_jmp_never_taken(struct bpf_test *self)
539 return __bpf_fill_max_jmp(self, BPF_JLT, 0);
542 /* ALU result computation used in tests */
543 static bool __bpf_alu_result(u64 *res, u64 v1, u64 v2, u8 op)
567 if (v2 > 0 && v1 > S64_MAX)
568 *res |= ~0ULL << (64 - v2);
582 *res = div64_u64(v1, v2);
587 div64_u64_rem(v1, v2, res);
593 /* Test an ALU shift operation for all valid shift values */
594 static int __bpf_fill_alu_shift(struct bpf_test *self, u8 op,
597 static const s64 regs[] = {
598 0x0123456789abcdefLL, /* dword > 0, word < 0 */
599 0xfedcba9876543210LL, /* dowrd < 0, word > 0 */
600 0xfedcba0198765432LL, /* dowrd < 0, word < 0 */
601 0x0123458967abcdefLL, /* dword > 0, word > 0 */
603 int bits = alu32 ? 32 : 64;
604 int len = (2 + 7 * bits) * ARRAY_SIZE(regs) + 3;
605 struct bpf_insn *insn;
609 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
613 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0);
615 for (k = 0; k < ARRAY_SIZE(regs); k++) {
618 i += __bpf_ld_imm64(&insn[i], R3, reg);
620 for (imm = 0; imm < bits; imm++) {
623 /* Perform operation */
624 insn[i++] = BPF_ALU64_REG(BPF_MOV, R1, R3);
625 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R2, imm);
628 insn[i++] = BPF_ALU32_IMM(op, R1, imm);
630 insn[i++] = BPF_ALU32_REG(op, R1, R2);
636 __bpf_alu_result(&val, reg, imm, op);
640 insn[i++] = BPF_ALU64_IMM(op, R1, imm);
642 insn[i++] = BPF_ALU64_REG(op, R1, R2);
643 __bpf_alu_result(&val, reg, imm, op);
647 * When debugging a JIT that fails this test, one
648 * can write the immediate value to R0 here to find
649 * out which operand values that fail.
652 /* Load reference and check the result */
653 i += __bpf_ld_imm64(&insn[i], R4, val);
654 insn[i++] = BPF_JMP_REG(BPF_JEQ, R1, R4, 1);
655 insn[i++] = BPF_EXIT_INSN();
659 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
660 insn[i++] = BPF_EXIT_INSN();
662 self->u.ptr.insns = insn;
663 self->u.ptr.len = len;
669 static int bpf_fill_alu64_lsh_imm(struct bpf_test *self)
671 return __bpf_fill_alu_shift(self, BPF_LSH, BPF_K, false);
674 static int bpf_fill_alu64_rsh_imm(struct bpf_test *self)
676 return __bpf_fill_alu_shift(self, BPF_RSH, BPF_K, false);
679 static int bpf_fill_alu64_arsh_imm(struct bpf_test *self)
681 return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_K, false);
684 static int bpf_fill_alu64_lsh_reg(struct bpf_test *self)
686 return __bpf_fill_alu_shift(self, BPF_LSH, BPF_X, false);
689 static int bpf_fill_alu64_rsh_reg(struct bpf_test *self)
691 return __bpf_fill_alu_shift(self, BPF_RSH, BPF_X, false);
694 static int bpf_fill_alu64_arsh_reg(struct bpf_test *self)
696 return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_X, false);
699 static int bpf_fill_alu32_lsh_imm(struct bpf_test *self)
701 return __bpf_fill_alu_shift(self, BPF_LSH, BPF_K, true);
704 static int bpf_fill_alu32_rsh_imm(struct bpf_test *self)
706 return __bpf_fill_alu_shift(self, BPF_RSH, BPF_K, true);
709 static int bpf_fill_alu32_arsh_imm(struct bpf_test *self)
711 return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_K, true);
714 static int bpf_fill_alu32_lsh_reg(struct bpf_test *self)
716 return __bpf_fill_alu_shift(self, BPF_LSH, BPF_X, true);
719 static int bpf_fill_alu32_rsh_reg(struct bpf_test *self)
721 return __bpf_fill_alu_shift(self, BPF_RSH, BPF_X, true);
724 static int bpf_fill_alu32_arsh_reg(struct bpf_test *self)
726 return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_X, true);
730 * Test an ALU register shift operation for all valid shift values
731 * for the case when the source and destination are the same.
733 static int __bpf_fill_alu_shift_same_reg(struct bpf_test *self, u8 op,
736 int bits = alu32 ? 32 : 64;
737 int len = 3 + 6 * bits;
738 struct bpf_insn *insn;
742 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
746 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0);
748 for (val = 0; val < bits; val++) {
751 /* Perform operation */
752 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R1, val);
754 insn[i++] = BPF_ALU32_REG(op, R1, R1);
756 insn[i++] = BPF_ALU64_REG(op, R1, R1);
758 /* Compute the reference result */
759 __bpf_alu_result(&res, val, val, op);
762 i += __bpf_ld_imm64(&insn[i], R2, res);
764 /* Check the actual result */
765 insn[i++] = BPF_JMP_REG(BPF_JEQ, R1, R2, 1);
766 insn[i++] = BPF_EXIT_INSN();
769 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
770 insn[i++] = BPF_EXIT_INSN();
772 self->u.ptr.insns = insn;
773 self->u.ptr.len = len;
779 static int bpf_fill_alu64_lsh_same_reg(struct bpf_test *self)
781 return __bpf_fill_alu_shift_same_reg(self, BPF_LSH, false);
784 static int bpf_fill_alu64_rsh_same_reg(struct bpf_test *self)
786 return __bpf_fill_alu_shift_same_reg(self, BPF_RSH, false);
789 static int bpf_fill_alu64_arsh_same_reg(struct bpf_test *self)
791 return __bpf_fill_alu_shift_same_reg(self, BPF_ARSH, false);
794 static int bpf_fill_alu32_lsh_same_reg(struct bpf_test *self)
796 return __bpf_fill_alu_shift_same_reg(self, BPF_LSH, true);
799 static int bpf_fill_alu32_rsh_same_reg(struct bpf_test *self)
801 return __bpf_fill_alu_shift_same_reg(self, BPF_RSH, true);
804 static int bpf_fill_alu32_arsh_same_reg(struct bpf_test *self)
806 return __bpf_fill_alu_shift_same_reg(self, BPF_ARSH, true);
810 * Common operand pattern generator for exhaustive power-of-two magnitudes
811 * tests. The block size parameters can be adjusted to increase/reduce the
812 * number of combinatons tested and thereby execution speed and memory
816 static inline s64 value(int msb, int delta, int sign)
818 return sign * (1LL << msb) + delta;
821 static int __bpf_fill_pattern(struct bpf_test *self, void *arg,
822 int dbits, int sbits, int block1, int block2,
823 int (*emit)(struct bpf_test*, void*,
824 struct bpf_insn*, s64, s64))
826 static const int sgn[][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
827 struct bpf_insn *insns;
828 int di, si, bt, db, sb;
833 /* Total number of iterations for the two pattern */
834 count = (dbits - 1) * (sbits - 1) * block1 * block1 * ARRAY_SIZE(sgn);
835 count += (max(dbits, sbits) - 1) * block2 * block2 * ARRAY_SIZE(sgn);
837 /* Compute the maximum number of insns and allocate the buffer */
838 len = extra + count * (*emit)(self, arg, NULL, 0, 0);
839 insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL);
843 /* Add head instruction(s) */
844 insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0);
847 * Pattern 1: all combinations of power-of-two magnitudes and sign,
848 * and with a block of contiguous values around each magnitude.
850 for (di = 0; di < dbits - 1; di++) /* Dst magnitudes */
851 for (si = 0; si < sbits - 1; si++) /* Src magnitudes */
852 for (k = 0; k < ARRAY_SIZE(sgn); k++) /* Sign combos */
853 for (db = -(block1 / 2);
854 db < (block1 + 1) / 2; db++)
855 for (sb = -(block1 / 2);
856 sb < (block1 + 1) / 2; sb++) {
859 dst = value(di, db, sgn[k][0]);
860 src = value(si, sb, sgn[k][1]);
861 i += (*emit)(self, arg,
866 * Pattern 2: all combinations for a larger block of values
867 * for each power-of-two magnitude and sign, where the magnitude is
868 * the same for both operands.
870 for (bt = 0; bt < max(dbits, sbits) - 1; bt++) /* Magnitude */
871 for (k = 0; k < ARRAY_SIZE(sgn); k++) /* Sign combos */
872 for (db = -(block2 / 2); db < (block2 + 1) / 2; db++)
873 for (sb = -(block2 / 2);
874 sb < (block2 + 1) / 2; sb++) {
877 dst = value(bt % dbits, db, sgn[k][0]);
878 src = value(bt % sbits, sb, sgn[k][1]);
879 i += (*emit)(self, arg, &insns[i],
883 /* Append tail instructions */
884 insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
885 insns[i++] = BPF_EXIT_INSN();
888 self->u.ptr.insns = insns;
895 * Block size parameters used in pattern tests below. une as needed to
896 * increase/reduce the number combinations tested, see following examples.
897 * block values per operand MSB
898 * ----------------------------------------
901 * 2 (1 << MSB) + [-1, 0]
902 * 3 (1 << MSB) + [-1, 0, 1]
904 #define PATTERN_BLOCK1 1
905 #define PATTERN_BLOCK2 5
907 /* Number of test runs for a pattern test */
908 #define NR_PATTERN_RUNS 1
911 * Exhaustive tests of ALU operations for all combinations of power-of-two
912 * magnitudes of the operands, both for positive and negative values. The
913 * test is designed to verify e.g. the ALU and ALU64 operations for JITs that
914 * emit different code depending on the magnitude of the immediate value.
916 static int __bpf_emit_alu64_imm(struct bpf_test *self, void *arg,
917 struct bpf_insn *insns, s64 dst, s64 imm)
919 int op = *(int *)arg;
926 if (__bpf_alu_result(&res, dst, (s32)imm, op)) {
927 i += __bpf_ld_imm64(&insns[i], R1, dst);
928 i += __bpf_ld_imm64(&insns[i], R3, res);
929 insns[i++] = BPF_ALU64_IMM(op, R1, imm);
930 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1);
931 insns[i++] = BPF_EXIT_INSN();
937 static int __bpf_emit_alu32_imm(struct bpf_test *self, void *arg,
938 struct bpf_insn *insns, s64 dst, s64 imm)
940 int op = *(int *)arg;
947 if (__bpf_alu_result(&res, (u32)dst, (u32)imm, op)) {
948 i += __bpf_ld_imm64(&insns[i], R1, dst);
949 i += __bpf_ld_imm64(&insns[i], R3, (u32)res);
950 insns[i++] = BPF_ALU32_IMM(op, R1, imm);
951 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1);
952 insns[i++] = BPF_EXIT_INSN();
958 static int __bpf_emit_alu64_reg(struct bpf_test *self, void *arg,
959 struct bpf_insn *insns, s64 dst, s64 src)
961 int op = *(int *)arg;
968 if (__bpf_alu_result(&res, dst, src, op)) {
969 i += __bpf_ld_imm64(&insns[i], R1, dst);
970 i += __bpf_ld_imm64(&insns[i], R2, src);
971 i += __bpf_ld_imm64(&insns[i], R3, res);
972 insns[i++] = BPF_ALU64_REG(op, R1, R2);
973 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1);
974 insns[i++] = BPF_EXIT_INSN();
980 static int __bpf_emit_alu32_reg(struct bpf_test *self, void *arg,
981 struct bpf_insn *insns, s64 dst, s64 src)
983 int op = *(int *)arg;
990 if (__bpf_alu_result(&res, (u32)dst, (u32)src, op)) {
991 i += __bpf_ld_imm64(&insns[i], R1, dst);
992 i += __bpf_ld_imm64(&insns[i], R2, src);
993 i += __bpf_ld_imm64(&insns[i], R3, (u32)res);
994 insns[i++] = BPF_ALU32_REG(op, R1, R2);
995 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1);
996 insns[i++] = BPF_EXIT_INSN();
1002 static int __bpf_fill_alu64_imm(struct bpf_test *self, int op)
1004 return __bpf_fill_pattern(self, &op, 64, 32,
1005 PATTERN_BLOCK1, PATTERN_BLOCK2,
1006 &__bpf_emit_alu64_imm);
1009 static int __bpf_fill_alu32_imm(struct bpf_test *self, int op)
1011 return __bpf_fill_pattern(self, &op, 64, 32,
1012 PATTERN_BLOCK1, PATTERN_BLOCK2,
1013 &__bpf_emit_alu32_imm);
1016 static int __bpf_fill_alu64_reg(struct bpf_test *self, int op)
1018 return __bpf_fill_pattern(self, &op, 64, 64,
1019 PATTERN_BLOCK1, PATTERN_BLOCK2,
1020 &__bpf_emit_alu64_reg);
1023 static int __bpf_fill_alu32_reg(struct bpf_test *self, int op)
1025 return __bpf_fill_pattern(self, &op, 64, 64,
1026 PATTERN_BLOCK1, PATTERN_BLOCK2,
1027 &__bpf_emit_alu32_reg);
1030 /* ALU64 immediate operations */
1031 static int bpf_fill_alu64_mov_imm(struct bpf_test *self)
1033 return __bpf_fill_alu64_imm(self, BPF_MOV);
1036 static int bpf_fill_alu64_and_imm(struct bpf_test *self)
1038 return __bpf_fill_alu64_imm(self, BPF_AND);
1041 static int bpf_fill_alu64_or_imm(struct bpf_test *self)
1043 return __bpf_fill_alu64_imm(self, BPF_OR);
1046 static int bpf_fill_alu64_xor_imm(struct bpf_test *self)
1048 return __bpf_fill_alu64_imm(self, BPF_XOR);
1051 static int bpf_fill_alu64_add_imm(struct bpf_test *self)
1053 return __bpf_fill_alu64_imm(self, BPF_ADD);
1056 static int bpf_fill_alu64_sub_imm(struct bpf_test *self)
1058 return __bpf_fill_alu64_imm(self, BPF_SUB);
1061 static int bpf_fill_alu64_mul_imm(struct bpf_test *self)
1063 return __bpf_fill_alu64_imm(self, BPF_MUL);
1066 static int bpf_fill_alu64_div_imm(struct bpf_test *self)
1068 return __bpf_fill_alu64_imm(self, BPF_DIV);
1071 static int bpf_fill_alu64_mod_imm(struct bpf_test *self)
1073 return __bpf_fill_alu64_imm(self, BPF_MOD);
1076 /* ALU32 immediate operations */
1077 static int bpf_fill_alu32_mov_imm(struct bpf_test *self)
1079 return __bpf_fill_alu32_imm(self, BPF_MOV);
1082 static int bpf_fill_alu32_and_imm(struct bpf_test *self)
1084 return __bpf_fill_alu32_imm(self, BPF_AND);
1087 static int bpf_fill_alu32_or_imm(struct bpf_test *self)
1089 return __bpf_fill_alu32_imm(self, BPF_OR);
1092 static int bpf_fill_alu32_xor_imm(struct bpf_test *self)
1094 return __bpf_fill_alu32_imm(self, BPF_XOR);
1097 static int bpf_fill_alu32_add_imm(struct bpf_test *self)
1099 return __bpf_fill_alu32_imm(self, BPF_ADD);
1102 static int bpf_fill_alu32_sub_imm(struct bpf_test *self)
1104 return __bpf_fill_alu32_imm(self, BPF_SUB);
1107 static int bpf_fill_alu32_mul_imm(struct bpf_test *self)
1109 return __bpf_fill_alu32_imm(self, BPF_MUL);
1112 static int bpf_fill_alu32_div_imm(struct bpf_test *self)
1114 return __bpf_fill_alu32_imm(self, BPF_DIV);
1117 static int bpf_fill_alu32_mod_imm(struct bpf_test *self)
1119 return __bpf_fill_alu32_imm(self, BPF_MOD);
1122 /* ALU64 register operations */
1123 static int bpf_fill_alu64_mov_reg(struct bpf_test *self)
1125 return __bpf_fill_alu64_reg(self, BPF_MOV);
1128 static int bpf_fill_alu64_and_reg(struct bpf_test *self)
1130 return __bpf_fill_alu64_reg(self, BPF_AND);
1133 static int bpf_fill_alu64_or_reg(struct bpf_test *self)
1135 return __bpf_fill_alu64_reg(self, BPF_OR);
1138 static int bpf_fill_alu64_xor_reg(struct bpf_test *self)
1140 return __bpf_fill_alu64_reg(self, BPF_XOR);
1143 static int bpf_fill_alu64_add_reg(struct bpf_test *self)
1145 return __bpf_fill_alu64_reg(self, BPF_ADD);
1148 static int bpf_fill_alu64_sub_reg(struct bpf_test *self)
1150 return __bpf_fill_alu64_reg(self, BPF_SUB);
1153 static int bpf_fill_alu64_mul_reg(struct bpf_test *self)
1155 return __bpf_fill_alu64_reg(self, BPF_MUL);
1158 static int bpf_fill_alu64_div_reg(struct bpf_test *self)
1160 return __bpf_fill_alu64_reg(self, BPF_DIV);
1163 static int bpf_fill_alu64_mod_reg(struct bpf_test *self)
1165 return __bpf_fill_alu64_reg(self, BPF_MOD);
1168 /* ALU32 register operations */
1169 static int bpf_fill_alu32_mov_reg(struct bpf_test *self)
1171 return __bpf_fill_alu32_reg(self, BPF_MOV);
1174 static int bpf_fill_alu32_and_reg(struct bpf_test *self)
1176 return __bpf_fill_alu32_reg(self, BPF_AND);
1179 static int bpf_fill_alu32_or_reg(struct bpf_test *self)
1181 return __bpf_fill_alu32_reg(self, BPF_OR);
1184 static int bpf_fill_alu32_xor_reg(struct bpf_test *self)
1186 return __bpf_fill_alu32_reg(self, BPF_XOR);
1189 static int bpf_fill_alu32_add_reg(struct bpf_test *self)
1191 return __bpf_fill_alu32_reg(self, BPF_ADD);
1194 static int bpf_fill_alu32_sub_reg(struct bpf_test *self)
1196 return __bpf_fill_alu32_reg(self, BPF_SUB);
1199 static int bpf_fill_alu32_mul_reg(struct bpf_test *self)
1201 return __bpf_fill_alu32_reg(self, BPF_MUL);
1204 static int bpf_fill_alu32_div_reg(struct bpf_test *self)
1206 return __bpf_fill_alu32_reg(self, BPF_DIV);
1209 static int bpf_fill_alu32_mod_reg(struct bpf_test *self)
1211 return __bpf_fill_alu32_reg(self, BPF_MOD);
1215 * Test JITs that implement complex ALU operations as function
1216 * calls, and must re-arrange operands for argument passing.
1218 static int __bpf_fill_alu_imm_regs(struct bpf_test *self, u8 op, bool alu32)
1220 int len = 2 + 10 * 10;
1221 struct bpf_insn *insns;
1227 insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL);
1231 /* Operand and result values according to operation */
1235 dst = 0x7edcba9876543210ULL;
1238 if (op == BPF_LSH || op == BPF_RSH || op == BPF_ARSH)
1241 __bpf_alu_result(&res, dst, imm, op);
1246 /* Check all operand registers */
1247 for (rd = R0; rd <= R9; rd++) {
1248 i += __bpf_ld_imm64(&insns[i], rd, dst);
1251 insns[i++] = BPF_ALU32_IMM(op, rd, imm);
1253 insns[i++] = BPF_ALU64_IMM(op, rd, imm);
1255 insns[i++] = BPF_JMP32_IMM(BPF_JEQ, rd, res, 2);
1256 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1257 insns[i++] = BPF_EXIT_INSN();
1259 insns[i++] = BPF_ALU64_IMM(BPF_RSH, rd, 32);
1260 insns[i++] = BPF_JMP32_IMM(BPF_JEQ, rd, res >> 32, 2);
1261 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1262 insns[i++] = BPF_EXIT_INSN();
1265 insns[i++] = BPF_MOV64_IMM(R0, 1);
1266 insns[i++] = BPF_EXIT_INSN();
1268 self->u.ptr.insns = insns;
1269 self->u.ptr.len = len;
1275 /* ALU64 K registers */
1276 static int bpf_fill_alu64_mov_imm_regs(struct bpf_test *self)
1278 return __bpf_fill_alu_imm_regs(self, BPF_MOV, false);
1281 static int bpf_fill_alu64_and_imm_regs(struct bpf_test *self)
1283 return __bpf_fill_alu_imm_regs(self, BPF_AND, false);
1286 static int bpf_fill_alu64_or_imm_regs(struct bpf_test *self)
1288 return __bpf_fill_alu_imm_regs(self, BPF_OR, false);
1291 static int bpf_fill_alu64_xor_imm_regs(struct bpf_test *self)
1293 return __bpf_fill_alu_imm_regs(self, BPF_XOR, false);
1296 static int bpf_fill_alu64_lsh_imm_regs(struct bpf_test *self)
1298 return __bpf_fill_alu_imm_regs(self, BPF_LSH, false);
1301 static int bpf_fill_alu64_rsh_imm_regs(struct bpf_test *self)
1303 return __bpf_fill_alu_imm_regs(self, BPF_RSH, false);
1306 static int bpf_fill_alu64_arsh_imm_regs(struct bpf_test *self)
1308 return __bpf_fill_alu_imm_regs(self, BPF_ARSH, false);
1311 static int bpf_fill_alu64_add_imm_regs(struct bpf_test *self)
1313 return __bpf_fill_alu_imm_regs(self, BPF_ADD, false);
1316 static int bpf_fill_alu64_sub_imm_regs(struct bpf_test *self)
1318 return __bpf_fill_alu_imm_regs(self, BPF_SUB, false);
1321 static int bpf_fill_alu64_mul_imm_regs(struct bpf_test *self)
1323 return __bpf_fill_alu_imm_regs(self, BPF_MUL, false);
1326 static int bpf_fill_alu64_div_imm_regs(struct bpf_test *self)
1328 return __bpf_fill_alu_imm_regs(self, BPF_DIV, false);
1331 static int bpf_fill_alu64_mod_imm_regs(struct bpf_test *self)
1333 return __bpf_fill_alu_imm_regs(self, BPF_MOD, false);
1336 /* ALU32 K registers */
1337 static int bpf_fill_alu32_mov_imm_regs(struct bpf_test *self)
1339 return __bpf_fill_alu_imm_regs(self, BPF_MOV, true);
1342 static int bpf_fill_alu32_and_imm_regs(struct bpf_test *self)
1344 return __bpf_fill_alu_imm_regs(self, BPF_AND, true);
1347 static int bpf_fill_alu32_or_imm_regs(struct bpf_test *self)
1349 return __bpf_fill_alu_imm_regs(self, BPF_OR, true);
1352 static int bpf_fill_alu32_xor_imm_regs(struct bpf_test *self)
1354 return __bpf_fill_alu_imm_regs(self, BPF_XOR, true);
1357 static int bpf_fill_alu32_lsh_imm_regs(struct bpf_test *self)
1359 return __bpf_fill_alu_imm_regs(self, BPF_LSH, true);
1362 static int bpf_fill_alu32_rsh_imm_regs(struct bpf_test *self)
1364 return __bpf_fill_alu_imm_regs(self, BPF_RSH, true);
1367 static int bpf_fill_alu32_arsh_imm_regs(struct bpf_test *self)
1369 return __bpf_fill_alu_imm_regs(self, BPF_ARSH, true);
1372 static int bpf_fill_alu32_add_imm_regs(struct bpf_test *self)
1374 return __bpf_fill_alu_imm_regs(self, BPF_ADD, true);
1377 static int bpf_fill_alu32_sub_imm_regs(struct bpf_test *self)
1379 return __bpf_fill_alu_imm_regs(self, BPF_SUB, true);
1382 static int bpf_fill_alu32_mul_imm_regs(struct bpf_test *self)
1384 return __bpf_fill_alu_imm_regs(self, BPF_MUL, true);
1387 static int bpf_fill_alu32_div_imm_regs(struct bpf_test *self)
1389 return __bpf_fill_alu_imm_regs(self, BPF_DIV, true);
1392 static int bpf_fill_alu32_mod_imm_regs(struct bpf_test *self)
1394 return __bpf_fill_alu_imm_regs(self, BPF_MOD, true);
1398 * Test JITs that implement complex ALU operations as function
1399 * calls, and must re-arrange operands for argument passing.
1401 static int __bpf_fill_alu_reg_pairs(struct bpf_test *self, u8 op, bool alu32)
1403 int len = 2 + 10 * 10 * 12;
1404 u64 dst, src, res, same;
1405 struct bpf_insn *insns;
1409 insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL);
1413 /* Operand and result values according to operation */
1418 dst = 0x7edcba9876543210ULL;
1419 src = 0x0123456789abcdefULL;
1422 if (op == BPF_LSH || op == BPF_RSH || op == BPF_ARSH)
1425 __bpf_alu_result(&res, dst, src, op);
1426 __bpf_alu_result(&same, src, src, op);
1433 /* Check all combinations of operand registers */
1434 for (rd = R0; rd <= R9; rd++) {
1435 for (rs = R0; rs <= R9; rs++) {
1436 u64 val = rd == rs ? same : res;
1438 i += __bpf_ld_imm64(&insns[i], rd, dst);
1439 i += __bpf_ld_imm64(&insns[i], rs, src);
1442 insns[i++] = BPF_ALU32_REG(op, rd, rs);
1444 insns[i++] = BPF_ALU64_REG(op, rd, rs);
1446 insns[i++] = BPF_JMP32_IMM(BPF_JEQ, rd, val, 2);
1447 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1448 insns[i++] = BPF_EXIT_INSN();
1450 insns[i++] = BPF_ALU64_IMM(BPF_RSH, rd, 32);
1451 insns[i++] = BPF_JMP32_IMM(BPF_JEQ, rd, val >> 32, 2);
1452 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1453 insns[i++] = BPF_EXIT_INSN();
1457 insns[i++] = BPF_MOV64_IMM(R0, 1);
1458 insns[i++] = BPF_EXIT_INSN();
1460 self->u.ptr.insns = insns;
1461 self->u.ptr.len = len;
1467 /* ALU64 X register combinations */
1468 static int bpf_fill_alu64_mov_reg_pairs(struct bpf_test *self)
1470 return __bpf_fill_alu_reg_pairs(self, BPF_MOV, false);
1473 static int bpf_fill_alu64_and_reg_pairs(struct bpf_test *self)
1475 return __bpf_fill_alu_reg_pairs(self, BPF_AND, false);
1478 static int bpf_fill_alu64_or_reg_pairs(struct bpf_test *self)
1480 return __bpf_fill_alu_reg_pairs(self, BPF_OR, false);
1483 static int bpf_fill_alu64_xor_reg_pairs(struct bpf_test *self)
1485 return __bpf_fill_alu_reg_pairs(self, BPF_XOR, false);
1488 static int bpf_fill_alu64_lsh_reg_pairs(struct bpf_test *self)
1490 return __bpf_fill_alu_reg_pairs(self, BPF_LSH, false);
1493 static int bpf_fill_alu64_rsh_reg_pairs(struct bpf_test *self)
1495 return __bpf_fill_alu_reg_pairs(self, BPF_RSH, false);
1498 static int bpf_fill_alu64_arsh_reg_pairs(struct bpf_test *self)
1500 return __bpf_fill_alu_reg_pairs(self, BPF_ARSH, false);
1503 static int bpf_fill_alu64_add_reg_pairs(struct bpf_test *self)
1505 return __bpf_fill_alu_reg_pairs(self, BPF_ADD, false);
1508 static int bpf_fill_alu64_sub_reg_pairs(struct bpf_test *self)
1510 return __bpf_fill_alu_reg_pairs(self, BPF_SUB, false);
1513 static int bpf_fill_alu64_mul_reg_pairs(struct bpf_test *self)
1515 return __bpf_fill_alu_reg_pairs(self, BPF_MUL, false);
1518 static int bpf_fill_alu64_div_reg_pairs(struct bpf_test *self)
1520 return __bpf_fill_alu_reg_pairs(self, BPF_DIV, false);
1523 static int bpf_fill_alu64_mod_reg_pairs(struct bpf_test *self)
1525 return __bpf_fill_alu_reg_pairs(self, BPF_MOD, false);
1528 /* ALU32 X register combinations */
1529 static int bpf_fill_alu32_mov_reg_pairs(struct bpf_test *self)
1531 return __bpf_fill_alu_reg_pairs(self, BPF_MOV, true);
1534 static int bpf_fill_alu32_and_reg_pairs(struct bpf_test *self)
1536 return __bpf_fill_alu_reg_pairs(self, BPF_AND, true);
1539 static int bpf_fill_alu32_or_reg_pairs(struct bpf_test *self)
1541 return __bpf_fill_alu_reg_pairs(self, BPF_OR, true);
1544 static int bpf_fill_alu32_xor_reg_pairs(struct bpf_test *self)
1546 return __bpf_fill_alu_reg_pairs(self, BPF_XOR, true);
1549 static int bpf_fill_alu32_lsh_reg_pairs(struct bpf_test *self)
1551 return __bpf_fill_alu_reg_pairs(self, BPF_LSH, true);
1554 static int bpf_fill_alu32_rsh_reg_pairs(struct bpf_test *self)
1556 return __bpf_fill_alu_reg_pairs(self, BPF_RSH, true);
1559 static int bpf_fill_alu32_arsh_reg_pairs(struct bpf_test *self)
1561 return __bpf_fill_alu_reg_pairs(self, BPF_ARSH, true);
1564 static int bpf_fill_alu32_add_reg_pairs(struct bpf_test *self)
1566 return __bpf_fill_alu_reg_pairs(self, BPF_ADD, true);
1569 static int bpf_fill_alu32_sub_reg_pairs(struct bpf_test *self)
1571 return __bpf_fill_alu_reg_pairs(self, BPF_SUB, true);
1574 static int bpf_fill_alu32_mul_reg_pairs(struct bpf_test *self)
1576 return __bpf_fill_alu_reg_pairs(self, BPF_MUL, true);
1579 static int bpf_fill_alu32_div_reg_pairs(struct bpf_test *self)
1581 return __bpf_fill_alu_reg_pairs(self, BPF_DIV, true);
1584 static int bpf_fill_alu32_mod_reg_pairs(struct bpf_test *self)
1586 return __bpf_fill_alu_reg_pairs(self, BPF_MOD, true);
1590 * Exhaustive tests of atomic operations for all power-of-two operand
1591 * magnitudes, both for positive and negative values.
1594 static int __bpf_emit_atomic64(struct bpf_test *self, void *arg,
1595 struct bpf_insn *insns, s64 dst, s64 src)
1597 int op = *(int *)arg;
1598 u64 keep, fetch, res;
1609 __bpf_alu_result(&res, dst, src, BPF_OP(op));
1612 keep = 0x0123456789abcdefULL;
1618 i += __bpf_ld_imm64(&insns[i], R0, keep);
1619 i += __bpf_ld_imm64(&insns[i], R1, dst);
1620 i += __bpf_ld_imm64(&insns[i], R2, src);
1621 i += __bpf_ld_imm64(&insns[i], R3, res);
1622 i += __bpf_ld_imm64(&insns[i], R4, fetch);
1623 i += __bpf_ld_imm64(&insns[i], R5, keep);
1625 insns[i++] = BPF_STX_MEM(BPF_DW, R10, R1, -8);
1626 insns[i++] = BPF_ATOMIC_OP(BPF_DW, op, R10, R2, -8);
1627 insns[i++] = BPF_LDX_MEM(BPF_DW, R1, R10, -8);
1629 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1);
1630 insns[i++] = BPF_EXIT_INSN();
1632 insns[i++] = BPF_JMP_REG(BPF_JEQ, R2, R4, 1);
1633 insns[i++] = BPF_EXIT_INSN();
1635 insns[i++] = BPF_JMP_REG(BPF_JEQ, R0, R5, 1);
1636 insns[i++] = BPF_EXIT_INSN();
1641 static int __bpf_emit_atomic32(struct bpf_test *self, void *arg,
1642 struct bpf_insn *insns, s64 dst, s64 src)
1644 int op = *(int *)arg;
1645 u64 keep, fetch, res;
1656 __bpf_alu_result(&res, (u32)dst, (u32)src, BPF_OP(op));
1659 keep = 0x0123456789abcdefULL;
1665 i += __bpf_ld_imm64(&insns[i], R0, keep);
1666 i += __bpf_ld_imm64(&insns[i], R1, (u32)dst);
1667 i += __bpf_ld_imm64(&insns[i], R2, src);
1668 i += __bpf_ld_imm64(&insns[i], R3, (u32)res);
1669 i += __bpf_ld_imm64(&insns[i], R4, fetch);
1670 i += __bpf_ld_imm64(&insns[i], R5, keep);
1672 insns[i++] = BPF_STX_MEM(BPF_W, R10, R1, -4);
1673 insns[i++] = BPF_ATOMIC_OP(BPF_W, op, R10, R2, -4);
1674 insns[i++] = BPF_LDX_MEM(BPF_W, R1, R10, -4);
1676 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1);
1677 insns[i++] = BPF_EXIT_INSN();
1679 insns[i++] = BPF_JMP_REG(BPF_JEQ, R2, R4, 1);
1680 insns[i++] = BPF_EXIT_INSN();
1682 insns[i++] = BPF_JMP_REG(BPF_JEQ, R0, R5, 1);
1683 insns[i++] = BPF_EXIT_INSN();
1688 static int __bpf_emit_cmpxchg64(struct bpf_test *self, void *arg,
1689 struct bpf_insn *insns, s64 dst, s64 src)
1696 i += __bpf_ld_imm64(&insns[i], R0, ~dst);
1697 i += __bpf_ld_imm64(&insns[i], R1, dst);
1698 i += __bpf_ld_imm64(&insns[i], R2, src);
1700 /* Result unsuccessful */
1701 insns[i++] = BPF_STX_MEM(BPF_DW, R10, R1, -8);
1702 insns[i++] = BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -8);
1703 insns[i++] = BPF_LDX_MEM(BPF_DW, R3, R10, -8);
1705 insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 2);
1706 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1707 insns[i++] = BPF_EXIT_INSN();
1709 insns[i++] = BPF_JMP_REG(BPF_JEQ, R0, R3, 2);
1710 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1711 insns[i++] = BPF_EXIT_INSN();
1713 /* Result successful */
1714 insns[i++] = BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -8);
1715 insns[i++] = BPF_LDX_MEM(BPF_DW, R3, R10, -8);
1717 insns[i++] = BPF_JMP_REG(BPF_JEQ, R2, R3, 2);
1718 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1719 insns[i++] = BPF_EXIT_INSN();
1721 insns[i++] = BPF_JMP_REG(BPF_JEQ, R0, R1, 2);
1722 insns[i++] = BPF_MOV64_IMM(R0, __LINE__);
1723 insns[i++] = BPF_EXIT_INSN();
1728 static int __bpf_emit_cmpxchg32(struct bpf_test *self, void *arg,
1729 struct bpf_insn *insns, s64 dst, s64 src)
1736 i += __bpf_ld_imm64(&insns[i], R0, ~dst);
1737 i += __bpf_ld_imm64(&insns[i], R1, (u32)dst);
1738 i += __bpf_ld_imm64(&insns[i], R2, src);
1740 /* Result unsuccessful */
1741 insns[i++] = BPF_STX_MEM(BPF_W, R10, R1, -4);
1742 insns[i++] = BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R2, -4);
1743 insns[i++] = BPF_ZEXT_REG(R0), /* Zext always inserted by verifier */
1744 insns[i++] = BPF_LDX_MEM(BPF_W, R3, R10, -4);
1746 insns[i++] = BPF_JMP32_REG(BPF_JEQ, R1, R3, 2);
1747 insns[i++] = BPF_MOV32_IMM(R0, __LINE__);
1748 insns[i++] = BPF_EXIT_INSN();
1750 insns[i++] = BPF_JMP_REG(BPF_JEQ, R0, R3, 2);
1751 insns[i++] = BPF_MOV32_IMM(R0, __LINE__);
1752 insns[i++] = BPF_EXIT_INSN();
1754 /* Result successful */
1755 i += __bpf_ld_imm64(&insns[i], R0, dst);
1756 insns[i++] = BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R2, -4);
1757 insns[i++] = BPF_ZEXT_REG(R0), /* Zext always inserted by verifier */
1758 insns[i++] = BPF_LDX_MEM(BPF_W, R3, R10, -4);
1760 insns[i++] = BPF_JMP32_REG(BPF_JEQ, R2, R3, 2);
1761 insns[i++] = BPF_MOV32_IMM(R0, __LINE__);
1762 insns[i++] = BPF_EXIT_INSN();
1764 insns[i++] = BPF_JMP_REG(BPF_JEQ, R0, R1, 2);
1765 insns[i++] = BPF_MOV32_IMM(R0, __LINE__);
1766 insns[i++] = BPF_EXIT_INSN();
1771 static int __bpf_fill_atomic64(struct bpf_test *self, int op)
1773 return __bpf_fill_pattern(self, &op, 64, 64,
1775 &__bpf_emit_atomic64);
1778 static int __bpf_fill_atomic32(struct bpf_test *self, int op)
1780 return __bpf_fill_pattern(self, &op, 64, 64,
1782 &__bpf_emit_atomic32);
1785 /* 64-bit atomic operations */
1786 static int bpf_fill_atomic64_add(struct bpf_test *self)
1788 return __bpf_fill_atomic64(self, BPF_ADD);
1791 static int bpf_fill_atomic64_and(struct bpf_test *self)
1793 return __bpf_fill_atomic64(self, BPF_AND);
1796 static int bpf_fill_atomic64_or(struct bpf_test *self)
1798 return __bpf_fill_atomic64(self, BPF_OR);
1801 static int bpf_fill_atomic64_xor(struct bpf_test *self)
1803 return __bpf_fill_atomic64(self, BPF_XOR);
1806 static int bpf_fill_atomic64_add_fetch(struct bpf_test *self)
1808 return __bpf_fill_atomic64(self, BPF_ADD | BPF_FETCH);
1811 static int bpf_fill_atomic64_and_fetch(struct bpf_test *self)
1813 return __bpf_fill_atomic64(self, BPF_AND | BPF_FETCH);
1816 static int bpf_fill_atomic64_or_fetch(struct bpf_test *self)
1818 return __bpf_fill_atomic64(self, BPF_OR | BPF_FETCH);
1821 static int bpf_fill_atomic64_xor_fetch(struct bpf_test *self)
1823 return __bpf_fill_atomic64(self, BPF_XOR | BPF_FETCH);
1826 static int bpf_fill_atomic64_xchg(struct bpf_test *self)
1828 return __bpf_fill_atomic64(self, BPF_XCHG);
1831 static int bpf_fill_cmpxchg64(struct bpf_test *self)
1833 return __bpf_fill_pattern(self, NULL, 64, 64, 0, PATTERN_BLOCK2,
1834 &__bpf_emit_cmpxchg64);
1837 /* 32-bit atomic operations */
1838 static int bpf_fill_atomic32_add(struct bpf_test *self)
1840 return __bpf_fill_atomic32(self, BPF_ADD);
1843 static int bpf_fill_atomic32_and(struct bpf_test *self)
1845 return __bpf_fill_atomic32(self, BPF_AND);
1848 static int bpf_fill_atomic32_or(struct bpf_test *self)
1850 return __bpf_fill_atomic32(self, BPF_OR);
1853 static int bpf_fill_atomic32_xor(struct bpf_test *self)
1855 return __bpf_fill_atomic32(self, BPF_XOR);
1858 static int bpf_fill_atomic32_add_fetch(struct bpf_test *self)
1860 return __bpf_fill_atomic32(self, BPF_ADD | BPF_FETCH);
1863 static int bpf_fill_atomic32_and_fetch(struct bpf_test *self)
1865 return __bpf_fill_atomic32(self, BPF_AND | BPF_FETCH);
1868 static int bpf_fill_atomic32_or_fetch(struct bpf_test *self)
1870 return __bpf_fill_atomic32(self, BPF_OR | BPF_FETCH);
1873 static int bpf_fill_atomic32_xor_fetch(struct bpf_test *self)
1875 return __bpf_fill_atomic32(self, BPF_XOR | BPF_FETCH);
1878 static int bpf_fill_atomic32_xchg(struct bpf_test *self)
1880 return __bpf_fill_atomic32(self, BPF_XCHG);
1883 static int bpf_fill_cmpxchg32(struct bpf_test *self)
1885 return __bpf_fill_pattern(self, NULL, 64, 64, 0, PATTERN_BLOCK2,
1886 &__bpf_emit_cmpxchg32);
1890 * Test JITs that implement ATOMIC operations as function calls or
1891 * other primitives, and must re-arrange operands for argument passing.
1893 static int __bpf_fill_atomic_reg_pairs(struct bpf_test *self, u8 width, u8 op)
1895 struct bpf_insn *insn;
1896 int len = 2 + 34 * 10 * 10;
1900 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
1904 /* Operand and memory values */
1905 if (width == BPF_DW) {
1906 mem = 0x0123456789abcdefULL;
1907 upd = 0xfedcba9876543210ULL;
1908 } else { /* BPF_W */
1913 /* Memory updated according to operation */
1922 __bpf_alu_result(&res, mem, upd, BPF_OP(op));
1925 /* Test all operand registers */
1926 for (rd = R0; rd <= R9; rd++) {
1927 for (rs = R0; rs <= R9; rs++) {
1930 /* Initialize value in memory */
1931 i += __bpf_ld_imm64(&insn[i], R0, mem);
1932 insn[i++] = BPF_STX_MEM(width, R10, R0, -8);
1934 /* Initialize registers in order */
1935 i += __bpf_ld_imm64(&insn[i], R0, ~mem);
1936 i += __bpf_ld_imm64(&insn[i], rs, upd);
1937 insn[i++] = BPF_MOV64_REG(rd, R10);
1939 /* Perform atomic operation */
1940 insn[i++] = BPF_ATOMIC_OP(width, op, rd, rs, -8);
1941 if (op == BPF_CMPXCHG && width == BPF_W)
1942 insn[i++] = BPF_ZEXT_REG(R0);
1944 /* Check R0 register value */
1945 if (op == BPF_CMPXCHG)
1946 cmp = mem; /* Expect value from memory */
1947 else if (R0 == rd || R0 == rs)
1948 cmp = 0; /* Aliased, checked below */
1950 cmp = ~mem; /* Expect value to be preserved */
1952 insn[i++] = BPF_JMP32_IMM(BPF_JEQ, R0,
1954 insn[i++] = BPF_MOV32_IMM(R0, __LINE__);
1955 insn[i++] = BPF_EXIT_INSN();
1956 insn[i++] = BPF_ALU64_IMM(BPF_RSH, R0, 32);
1957 insn[i++] = BPF_JMP32_IMM(BPF_JEQ, R0,
1959 insn[i++] = BPF_MOV32_IMM(R0, __LINE__);
1960 insn[i++] = BPF_EXIT_INSN();
1963 /* Check source register value */
1964 if (rs == R0 && op == BPF_CMPXCHG)
1965 src = 0; /* Aliased with R0, checked above */
1966 else if (rs == rd && (op == BPF_CMPXCHG ||
1968 src = 0; /* Aliased with rd, checked below */
1969 else if (op == BPF_CMPXCHG)
1970 src = upd; /* Expect value to be preserved */
1971 else if (op & BPF_FETCH)
1972 src = mem; /* Expect fetched value from mem */
1974 src = upd; /* Expect value to be preserved */
1976 insn[i++] = BPF_JMP32_IMM(BPF_JEQ, rs,
1978 insn[i++] = BPF_MOV32_IMM(R0, __LINE__);
1979 insn[i++] = BPF_EXIT_INSN();
1980 insn[i++] = BPF_ALU64_IMM(BPF_RSH, rs, 32);
1981 insn[i++] = BPF_JMP32_IMM(BPF_JEQ, rs,
1983 insn[i++] = BPF_MOV32_IMM(R0, __LINE__);
1984 insn[i++] = BPF_EXIT_INSN();
1987 /* Check destination register value */
1988 if (!(rd == R0 && op == BPF_CMPXCHG) &&
1989 !(rd == rs && (op & BPF_FETCH))) {
1990 insn[i++] = BPF_JMP_REG(BPF_JEQ, rd, R10, 2);
1991 insn[i++] = BPF_MOV32_IMM(R0, __LINE__);
1992 insn[i++] = BPF_EXIT_INSN();
1995 /* Check value in memory */
1996 if (rs != rd) { /* No aliasing */
1997 i += __bpf_ld_imm64(&insn[i], R1, res);
1998 } else if (op == BPF_XCHG) { /* Aliased, XCHG */
1999 insn[i++] = BPF_MOV64_REG(R1, R10);
2000 } else if (op == BPF_CMPXCHG) { /* Aliased, CMPXCHG */
2001 i += __bpf_ld_imm64(&insn[i], R1, mem);
2002 } else { /* Aliased, ALU oper */
2003 i += __bpf_ld_imm64(&insn[i], R1, mem);
2004 insn[i++] = BPF_ALU64_REG(BPF_OP(op), R1, R10);
2007 insn[i++] = BPF_LDX_MEM(width, R0, R10, -8);
2008 if (width == BPF_DW)
2009 insn[i++] = BPF_JMP_REG(BPF_JEQ, R0, R1, 2);
2010 else /* width == BPF_W */
2011 insn[i++] = BPF_JMP32_REG(BPF_JEQ, R0, R1, 2);
2012 insn[i++] = BPF_MOV32_IMM(R0, __LINE__);
2013 insn[i++] = BPF_EXIT_INSN();
2017 insn[i++] = BPF_MOV64_IMM(R0, 1);
2018 insn[i++] = BPF_EXIT_INSN();
2020 self->u.ptr.insns = insn;
2021 self->u.ptr.len = i;
2027 /* 64-bit atomic register tests */
2028 static int bpf_fill_atomic64_add_reg_pairs(struct bpf_test *self)
2030 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_ADD);
2033 static int bpf_fill_atomic64_and_reg_pairs(struct bpf_test *self)
2035 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_AND);
2038 static int bpf_fill_atomic64_or_reg_pairs(struct bpf_test *self)
2040 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_OR);
2043 static int bpf_fill_atomic64_xor_reg_pairs(struct bpf_test *self)
2045 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_XOR);
2048 static int bpf_fill_atomic64_add_fetch_reg_pairs(struct bpf_test *self)
2050 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_ADD | BPF_FETCH);
2053 static int bpf_fill_atomic64_and_fetch_reg_pairs(struct bpf_test *self)
2055 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_AND | BPF_FETCH);
2058 static int bpf_fill_atomic64_or_fetch_reg_pairs(struct bpf_test *self)
2060 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_OR | BPF_FETCH);
2063 static int bpf_fill_atomic64_xor_fetch_reg_pairs(struct bpf_test *self)
2065 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_XOR | BPF_FETCH);
2068 static int bpf_fill_atomic64_xchg_reg_pairs(struct bpf_test *self)
2070 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_XCHG);
2073 static int bpf_fill_atomic64_cmpxchg_reg_pairs(struct bpf_test *self)
2075 return __bpf_fill_atomic_reg_pairs(self, BPF_DW, BPF_CMPXCHG);
2078 /* 32-bit atomic register tests */
2079 static int bpf_fill_atomic32_add_reg_pairs(struct bpf_test *self)
2081 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_ADD);
2084 static int bpf_fill_atomic32_and_reg_pairs(struct bpf_test *self)
2086 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_AND);
2089 static int bpf_fill_atomic32_or_reg_pairs(struct bpf_test *self)
2091 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_OR);
2094 static int bpf_fill_atomic32_xor_reg_pairs(struct bpf_test *self)
2096 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_XOR);
2099 static int bpf_fill_atomic32_add_fetch_reg_pairs(struct bpf_test *self)
2101 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_ADD | BPF_FETCH);
2104 static int bpf_fill_atomic32_and_fetch_reg_pairs(struct bpf_test *self)
2106 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_AND | BPF_FETCH);
2109 static int bpf_fill_atomic32_or_fetch_reg_pairs(struct bpf_test *self)
2111 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_OR | BPF_FETCH);
2114 static int bpf_fill_atomic32_xor_fetch_reg_pairs(struct bpf_test *self)
2116 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_XOR | BPF_FETCH);
2119 static int bpf_fill_atomic32_xchg_reg_pairs(struct bpf_test *self)
2121 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_XCHG);
2124 static int bpf_fill_atomic32_cmpxchg_reg_pairs(struct bpf_test *self)
2126 return __bpf_fill_atomic_reg_pairs(self, BPF_W, BPF_CMPXCHG);
2130 * Test the two-instruction 64-bit immediate load operation for all
2131 * power-of-two magnitudes of the immediate operand. For each MSB, a block
2132 * of immediate values centered around the power-of-two MSB are tested,
2133 * both for positive and negative values. The test is designed to verify
2134 * the operation for JITs that emit different code depending on the magnitude
2135 * of the immediate value. This is often the case if the native instruction
2136 * immediate field width is narrower than 32 bits.
2138 static int bpf_fill_ld_imm64_magn(struct bpf_test *self)
2140 int block = 64; /* Increase for more tests per MSB position */
2141 int len = 3 + 8 * 63 * block * 2;
2142 struct bpf_insn *insn;
2146 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
2150 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0);
2152 for (bit = 0; bit <= 62; bit++) {
2153 for (adj = -block / 2; adj < block / 2; adj++) {
2154 for (sign = -1; sign <= 1; sign += 2) {
2155 s64 imm = sign * ((1LL << bit) + adj);
2157 /* Perform operation */
2158 i += __bpf_ld_imm64(&insn[i], R1, imm);
2160 /* Load reference */
2161 insn[i++] = BPF_ALU32_IMM(BPF_MOV, R2, imm);
2162 insn[i++] = BPF_ALU32_IMM(BPF_MOV, R3,
2164 insn[i++] = BPF_ALU64_IMM(BPF_LSH, R3, 32);
2165 insn[i++] = BPF_ALU64_REG(BPF_OR, R2, R3);
2168 insn[i++] = BPF_JMP_REG(BPF_JEQ, R1, R2, 1);
2169 insn[i++] = BPF_EXIT_INSN();
2174 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
2175 insn[i++] = BPF_EXIT_INSN();
2177 self->u.ptr.insns = insn;
2178 self->u.ptr.len = len;
2185 * Test the two-instruction 64-bit immediate load operation for different
2186 * combinations of bytes. Each byte in the 64-bit word is constructed as
2187 * (base & mask) | (rand() & ~mask), where rand() is a deterministic LCG.
2188 * All patterns (base1, mask1) and (base2, mask2) bytes are tested.
2190 static int __bpf_fill_ld_imm64_bytes(struct bpf_test *self,
2194 struct bpf_insn *insn;
2195 int len = 3 + 8 * BIT(8);
2200 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
2204 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0);
2206 for (pattern = 0; pattern < BIT(8); pattern++) {
2209 for (index = 0; index < 8; index++) {
2212 if (pattern & BIT(index))
2213 byte = (base1 & mask1) | (rand & ~mask1);
2215 byte = (base2 & mask2) | (rand & ~mask2);
2216 imm = (imm << 8) | byte;
2219 /* Update our LCG */
2220 rand = rand * 1664525 + 1013904223;
2222 /* Perform operation */
2223 i += __bpf_ld_imm64(&insn[i], R1, imm);
2225 /* Load reference */
2226 insn[i++] = BPF_ALU32_IMM(BPF_MOV, R2, imm);
2227 insn[i++] = BPF_ALU32_IMM(BPF_MOV, R3, (u32)(imm >> 32));
2228 insn[i++] = BPF_ALU64_IMM(BPF_LSH, R3, 32);
2229 insn[i++] = BPF_ALU64_REG(BPF_OR, R2, R3);
2232 insn[i++] = BPF_JMP_REG(BPF_JEQ, R1, R2, 1);
2233 insn[i++] = BPF_EXIT_INSN();
2236 insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
2237 insn[i++] = BPF_EXIT_INSN();
2239 self->u.ptr.insns = insn;
2240 self->u.ptr.len = len;
2246 static int bpf_fill_ld_imm64_checker(struct bpf_test *self)
2248 return __bpf_fill_ld_imm64_bytes(self, 0, 0xff, 0xff, 0xff);
2251 static int bpf_fill_ld_imm64_pos_neg(struct bpf_test *self)
2253 return __bpf_fill_ld_imm64_bytes(self, 1, 0x81, 0x80, 0x80);
2256 static int bpf_fill_ld_imm64_pos_zero(struct bpf_test *self)
2258 return __bpf_fill_ld_imm64_bytes(self, 1, 0x81, 0, 0xff);
2261 static int bpf_fill_ld_imm64_neg_zero(struct bpf_test *self)
2263 return __bpf_fill_ld_imm64_bytes(self, 0x80, 0x80, 0, 0xff);
2267 * Exhaustive tests of JMP operations for all combinations of power-of-two
2268 * magnitudes of the operands, both for positive and negative values. The
2269 * test is designed to verify e.g. the JMP and JMP32 operations for JITs that
2270 * emit different code depending on the magnitude of the immediate value.
2273 static bool __bpf_match_jmp_cond(s64 v1, s64 v2, u8 op)
2283 return (u64)v1 > (u64)v2;
2285 return (u64)v1 >= (u64)v2;
2287 return (u64)v1 < (u64)v2;
2289 return (u64)v1 <= (u64)v2;
2302 static int __bpf_emit_jmp_imm(struct bpf_test *self, void *arg,
2303 struct bpf_insn *insns, s64 dst, s64 imm)
2305 int op = *(int *)arg;
2308 bool match = __bpf_match_jmp_cond(dst, (s32)imm, op);
2311 insns[i++] = BPF_ALU32_IMM(BPF_MOV, R0, match);
2313 i += __bpf_ld_imm64(&insns[i], R1, dst);
2314 insns[i++] = BPF_JMP_IMM(op, R1, imm, 1);
2316 insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1);
2317 insns[i++] = BPF_EXIT_INSN();
2325 static int __bpf_emit_jmp32_imm(struct bpf_test *self, void *arg,
2326 struct bpf_insn *insns, s64 dst, s64 imm)
2328 int op = *(int *)arg;
2331 bool match = __bpf_match_jmp_cond((s32)dst, (s32)imm, op);
2334 i += __bpf_ld_imm64(&insns[i], R1, dst);
2335 insns[i++] = BPF_JMP32_IMM(op, R1, imm, 1);
2337 insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1);
2338 insns[i++] = BPF_EXIT_INSN();
2346 static int __bpf_emit_jmp_reg(struct bpf_test *self, void *arg,
2347 struct bpf_insn *insns, s64 dst, s64 src)
2349 int op = *(int *)arg;
2352 bool match = __bpf_match_jmp_cond(dst, src, op);
2355 i += __bpf_ld_imm64(&insns[i], R1, dst);
2356 i += __bpf_ld_imm64(&insns[i], R2, src);
2357 insns[i++] = BPF_JMP_REG(op, R1, R2, 1);
2359 insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1);
2360 insns[i++] = BPF_EXIT_INSN();
2368 static int __bpf_emit_jmp32_reg(struct bpf_test *self, void *arg,
2369 struct bpf_insn *insns, s64 dst, s64 src)
2371 int op = *(int *)arg;
2374 bool match = __bpf_match_jmp_cond((s32)dst, (s32)src, op);
2377 i += __bpf_ld_imm64(&insns[i], R1, dst);
2378 i += __bpf_ld_imm64(&insns[i], R2, src);
2379 insns[i++] = BPF_JMP32_REG(op, R1, R2, 1);
2381 insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1);
2382 insns[i++] = BPF_EXIT_INSN();
2390 static int __bpf_fill_jmp_imm(struct bpf_test *self, int op)
2392 return __bpf_fill_pattern(self, &op, 64, 32,
2393 PATTERN_BLOCK1, PATTERN_BLOCK2,
2394 &__bpf_emit_jmp_imm);
2397 static int __bpf_fill_jmp32_imm(struct bpf_test *self, int op)
2399 return __bpf_fill_pattern(self, &op, 64, 32,
2400 PATTERN_BLOCK1, PATTERN_BLOCK2,
2401 &__bpf_emit_jmp32_imm);
2404 static int __bpf_fill_jmp_reg(struct bpf_test *self, int op)
2406 return __bpf_fill_pattern(self, &op, 64, 64,
2407 PATTERN_BLOCK1, PATTERN_BLOCK2,
2408 &__bpf_emit_jmp_reg);
2411 static int __bpf_fill_jmp32_reg(struct bpf_test *self, int op)
2413 return __bpf_fill_pattern(self, &op, 64, 64,
2414 PATTERN_BLOCK1, PATTERN_BLOCK2,
2415 &__bpf_emit_jmp32_reg);
2418 /* JMP immediate tests */
2419 static int bpf_fill_jmp_jset_imm(struct bpf_test *self)
2421 return __bpf_fill_jmp_imm(self, BPF_JSET);
2424 static int bpf_fill_jmp_jeq_imm(struct bpf_test *self)
2426 return __bpf_fill_jmp_imm(self, BPF_JEQ);
2429 static int bpf_fill_jmp_jne_imm(struct bpf_test *self)
2431 return __bpf_fill_jmp_imm(self, BPF_JNE);
2434 static int bpf_fill_jmp_jgt_imm(struct bpf_test *self)
2436 return __bpf_fill_jmp_imm(self, BPF_JGT);
2439 static int bpf_fill_jmp_jge_imm(struct bpf_test *self)
2441 return __bpf_fill_jmp_imm(self, BPF_JGE);
2444 static int bpf_fill_jmp_jlt_imm(struct bpf_test *self)
2446 return __bpf_fill_jmp_imm(self, BPF_JLT);
2449 static int bpf_fill_jmp_jle_imm(struct bpf_test *self)
2451 return __bpf_fill_jmp_imm(self, BPF_JLE);
2454 static int bpf_fill_jmp_jsgt_imm(struct bpf_test *self)
2456 return __bpf_fill_jmp_imm(self, BPF_JSGT);
2459 static int bpf_fill_jmp_jsge_imm(struct bpf_test *self)
2461 return __bpf_fill_jmp_imm(self, BPF_JSGE);
2464 static int bpf_fill_jmp_jslt_imm(struct bpf_test *self)
2466 return __bpf_fill_jmp_imm(self, BPF_JSLT);
2469 static int bpf_fill_jmp_jsle_imm(struct bpf_test *self)
2471 return __bpf_fill_jmp_imm(self, BPF_JSLE);
2474 /* JMP32 immediate tests */
2475 static int bpf_fill_jmp32_jset_imm(struct bpf_test *self)
2477 return __bpf_fill_jmp32_imm(self, BPF_JSET);
2480 static int bpf_fill_jmp32_jeq_imm(struct bpf_test *self)
2482 return __bpf_fill_jmp32_imm(self, BPF_JEQ);
2485 static int bpf_fill_jmp32_jne_imm(struct bpf_test *self)
2487 return __bpf_fill_jmp32_imm(self, BPF_JNE);
2490 static int bpf_fill_jmp32_jgt_imm(struct bpf_test *self)
2492 return __bpf_fill_jmp32_imm(self, BPF_JGT);
2495 static int bpf_fill_jmp32_jge_imm(struct bpf_test *self)
2497 return __bpf_fill_jmp32_imm(self, BPF_JGE);
2500 static int bpf_fill_jmp32_jlt_imm(struct bpf_test *self)
2502 return __bpf_fill_jmp32_imm(self, BPF_JLT);
2505 static int bpf_fill_jmp32_jle_imm(struct bpf_test *self)
2507 return __bpf_fill_jmp32_imm(self, BPF_JLE);
2510 static int bpf_fill_jmp32_jsgt_imm(struct bpf_test *self)
2512 return __bpf_fill_jmp32_imm(self, BPF_JSGT);
2515 static int bpf_fill_jmp32_jsge_imm(struct bpf_test *self)
2517 return __bpf_fill_jmp32_imm(self, BPF_JSGE);
2520 static int bpf_fill_jmp32_jslt_imm(struct bpf_test *self)
2522 return __bpf_fill_jmp32_imm(self, BPF_JSLT);
2525 static int bpf_fill_jmp32_jsle_imm(struct bpf_test *self)
2527 return __bpf_fill_jmp32_imm(self, BPF_JSLE);
2530 /* JMP register tests */
2531 static int bpf_fill_jmp_jset_reg(struct bpf_test *self)
2533 return __bpf_fill_jmp_reg(self, BPF_JSET);
2536 static int bpf_fill_jmp_jeq_reg(struct bpf_test *self)
2538 return __bpf_fill_jmp_reg(self, BPF_JEQ);
2541 static int bpf_fill_jmp_jne_reg(struct bpf_test *self)
2543 return __bpf_fill_jmp_reg(self, BPF_JNE);
2546 static int bpf_fill_jmp_jgt_reg(struct bpf_test *self)
2548 return __bpf_fill_jmp_reg(self, BPF_JGT);
2551 static int bpf_fill_jmp_jge_reg(struct bpf_test *self)
2553 return __bpf_fill_jmp_reg(self, BPF_JGE);
2556 static int bpf_fill_jmp_jlt_reg(struct bpf_test *self)
2558 return __bpf_fill_jmp_reg(self, BPF_JLT);
2561 static int bpf_fill_jmp_jle_reg(struct bpf_test *self)
2563 return __bpf_fill_jmp_reg(self, BPF_JLE);
2566 static int bpf_fill_jmp_jsgt_reg(struct bpf_test *self)
2568 return __bpf_fill_jmp_reg(self, BPF_JSGT);
2571 static int bpf_fill_jmp_jsge_reg(struct bpf_test *self)
2573 return __bpf_fill_jmp_reg(self, BPF_JSGE);
2576 static int bpf_fill_jmp_jslt_reg(struct bpf_test *self)
2578 return __bpf_fill_jmp_reg(self, BPF_JSLT);
2581 static int bpf_fill_jmp_jsle_reg(struct bpf_test *self)
2583 return __bpf_fill_jmp_reg(self, BPF_JSLE);
2586 /* JMP32 register tests */
2587 static int bpf_fill_jmp32_jset_reg(struct bpf_test *self)
2589 return __bpf_fill_jmp32_reg(self, BPF_JSET);
2592 static int bpf_fill_jmp32_jeq_reg(struct bpf_test *self)
2594 return __bpf_fill_jmp32_reg(self, BPF_JEQ);
2597 static int bpf_fill_jmp32_jne_reg(struct bpf_test *self)
2599 return __bpf_fill_jmp32_reg(self, BPF_JNE);
2602 static int bpf_fill_jmp32_jgt_reg(struct bpf_test *self)
2604 return __bpf_fill_jmp32_reg(self, BPF_JGT);
2607 static int bpf_fill_jmp32_jge_reg(struct bpf_test *self)
2609 return __bpf_fill_jmp32_reg(self, BPF_JGE);
2612 static int bpf_fill_jmp32_jlt_reg(struct bpf_test *self)
2614 return __bpf_fill_jmp32_reg(self, BPF_JLT);
2617 static int bpf_fill_jmp32_jle_reg(struct bpf_test *self)
2619 return __bpf_fill_jmp32_reg(self, BPF_JLE);
2622 static int bpf_fill_jmp32_jsgt_reg(struct bpf_test *self)
2624 return __bpf_fill_jmp32_reg(self, BPF_JSGT);
2627 static int bpf_fill_jmp32_jsge_reg(struct bpf_test *self)
2629 return __bpf_fill_jmp32_reg(self, BPF_JSGE);
2632 static int bpf_fill_jmp32_jslt_reg(struct bpf_test *self)
2634 return __bpf_fill_jmp32_reg(self, BPF_JSLT);
2637 static int bpf_fill_jmp32_jsle_reg(struct bpf_test *self)
2639 return __bpf_fill_jmp32_reg(self, BPF_JSLE);
2643 * Set up a sequence of staggered jumps, forwards and backwards with
2644 * increasing offset. This tests the conversion of relative jumps to
2645 * JITed native jumps. On some architectures, for example MIPS, a large
2646 * PC-relative jump offset may overflow the immediate field of the native
2647 * conditional branch instruction, triggering a conversion to use an
2648 * absolute jump instead. Since this changes the jump offsets, another
2649 * offset computation pass is necessary, and that may in turn trigger
2650 * another branch conversion. This jump sequence is particularly nasty
2653 * The sequence generation is parameterized by size and jump type.
2654 * The size must be even, and the expected result is always size + 1.
2655 * Below is an example with size=8 and result=9.
2657 * ________________________Start
2661 * ,------- JMP +4 * 3______________Preamble: 4 insns
2662 * ,----------|-ind 0- if R0 != 7 JMP 8 * 3 + 1 <--------------------.
2664 * | | JMP +7 * 3 ------------------------.
2665 * | ,--------|-----1- if R0 != 5 JMP 7 * 3 + 1 <--------------. | |
2666 * | | | R0 = 6 | | |
2667 * | | | JMP +5 * 3 ------------------. | |
2668 * | | ,------|-----2- if R0 != 3 JMP 6 * 3 + 1 <--------. | | | |
2669 * | | | | R0 = 4 | | | | |
2670 * | | | | JMP +3 * 3 ------------. | | | |
2671 * | | | ,----|-----3- if R0 != 1 JMP 5 * 3 + 1 <--. | | | | | |
2672 * | | | | | R0 = 2 | | | | | | |
2673 * | | | | | JMP +1 * 3 ------. | | | | | |
2674 * | | | | ,--t=====4> if R0 != 0 JMP 4 * 3 + 1 1 2 3 4 5 6 7 8 loc
2675 * | | | | | R0 = 1 -1 +2 -3 +4 -5 +6 -7 +8 off
2676 * | | | | | JMP -2 * 3 ---' | | | | | | |
2677 * | | | | | ,------5- if R0 != 2 JMP 3 * 3 + 1 <-----' | | | | | |
2678 * | | | | | | R0 = 3 | | | | | |
2679 * | | | | | | JMP -4 * 3 ---------' | | | | |
2680 * | | | | | | ,----6- if R0 != 4 JMP 2 * 3 + 1 <-----------' | | | |
2681 * | | | | | | | R0 = 5 | | | |
2682 * | | | | | | | JMP -6 * 3 ---------------' | | |
2683 * | | | | | | | ,--7- if R0 != 6 JMP 1 * 3 + 1 <-----------------' | |
2684 * | | | | | | | | R0 = 7 | |
2685 * | | Error | | | JMP -8 * 3 ---------------------' |
2686 * | | paths | | | ,8- if R0 != 8 JMP 0 * 3 + 1 <-----------------------'
2687 * | | | | | | | | | R0 = 9__________________Sequence: 3 * size - 1 insns
2688 * `-+-+-+-+-+-+-+-+-> EXIT____________________Return: 1 insn
2692 /* The maximum size parameter */
2693 #define MAX_STAGGERED_JMP_SIZE ((0x7fff / 3) & ~1)
2695 /* We use a reduced number of iterations to get a reasonable execution time */
2696 #define NR_STAGGERED_JMP_RUNS 10
2698 static int __bpf_fill_staggered_jumps(struct bpf_test *self,
2699 const struct bpf_insn *jmp,
2702 int size = self->test[0].result - 1;
2703 int len = 4 + 3 * (size + 1);
2704 struct bpf_insn *insns;
2707 insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL);
2712 insns[0] = BPF_ALU64_IMM(BPF_MOV, R0, 0);
2713 insns[1] = BPF_ALU64_IMM(BPF_MOV, R1, r1);
2714 insns[2] = BPF_ALU64_IMM(BPF_MOV, R2, r2);
2715 insns[3] = BPF_JMP_IMM(BPF_JA, 0, 0, 3 * size / 2);
2718 for (ind = 0, off = size; ind <= size; ind++, off -= 2) {
2719 struct bpf_insn *ins = &insns[4 + 3 * ind];
2726 ins[0] = BPF_JMP_IMM(BPF_JNE, R0, loc - 1,
2727 3 * (size - ind) + 1);
2728 ins[1] = BPF_ALU64_IMM(BPF_MOV, R0, loc);
2730 ins[2].off = 3 * (off - 1);
2734 insns[len - 1] = BPF_EXIT_INSN();
2736 self->u.ptr.insns = insns;
2737 self->u.ptr.len = len;
2742 /* 64-bit unconditional jump */
2743 static int bpf_fill_staggered_ja(struct bpf_test *self)
2745 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JA, 0, 0, 0);
2747 return __bpf_fill_staggered_jumps(self, &jmp, 0, 0);
2750 /* 64-bit immediate jumps */
2751 static int bpf_fill_staggered_jeq_imm(struct bpf_test *self)
2753 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JEQ, R1, 1234, 0);
2755 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2758 static int bpf_fill_staggered_jne_imm(struct bpf_test *self)
2760 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JNE, R1, 1234, 0);
2762 return __bpf_fill_staggered_jumps(self, &jmp, 4321, 0);
2765 static int bpf_fill_staggered_jset_imm(struct bpf_test *self)
2767 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSET, R1, 0x82, 0);
2769 return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0);
2772 static int bpf_fill_staggered_jgt_imm(struct bpf_test *self)
2774 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JGT, R1, 1234, 0);
2776 return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 0);
2779 static int bpf_fill_staggered_jge_imm(struct bpf_test *self)
2781 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JGE, R1, 1234, 0);
2783 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2786 static int bpf_fill_staggered_jlt_imm(struct bpf_test *self)
2788 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JLT, R1, 0x80000000, 0);
2790 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2793 static int bpf_fill_staggered_jle_imm(struct bpf_test *self)
2795 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JLE, R1, 1234, 0);
2797 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2800 static int bpf_fill_staggered_jsgt_imm(struct bpf_test *self)
2802 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSGT, R1, -2, 0);
2804 return __bpf_fill_staggered_jumps(self, &jmp, -1, 0);
2807 static int bpf_fill_staggered_jsge_imm(struct bpf_test *self)
2809 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSGE, R1, -2, 0);
2811 return __bpf_fill_staggered_jumps(self, &jmp, -2, 0);
2814 static int bpf_fill_staggered_jslt_imm(struct bpf_test *self)
2816 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSLT, R1, -1, 0);
2818 return __bpf_fill_staggered_jumps(self, &jmp, -2, 0);
2821 static int bpf_fill_staggered_jsle_imm(struct bpf_test *self)
2823 struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSLE, R1, -1, 0);
2825 return __bpf_fill_staggered_jumps(self, &jmp, -1, 0);
2828 /* 64-bit register jumps */
2829 static int bpf_fill_staggered_jeq_reg(struct bpf_test *self)
2831 struct bpf_insn jmp = BPF_JMP_REG(BPF_JEQ, R1, R2, 0);
2833 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234);
2836 static int bpf_fill_staggered_jne_reg(struct bpf_test *self)
2838 struct bpf_insn jmp = BPF_JMP_REG(BPF_JNE, R1, R2, 0);
2840 return __bpf_fill_staggered_jumps(self, &jmp, 4321, 1234);
2843 static int bpf_fill_staggered_jset_reg(struct bpf_test *self)
2845 struct bpf_insn jmp = BPF_JMP_REG(BPF_JSET, R1, R2, 0);
2847 return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0x82);
2850 static int bpf_fill_staggered_jgt_reg(struct bpf_test *self)
2852 struct bpf_insn jmp = BPF_JMP_REG(BPF_JGT, R1, R2, 0);
2854 return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 1234);
2857 static int bpf_fill_staggered_jge_reg(struct bpf_test *self)
2859 struct bpf_insn jmp = BPF_JMP_REG(BPF_JGE, R1, R2, 0);
2861 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234);
2864 static int bpf_fill_staggered_jlt_reg(struct bpf_test *self)
2866 struct bpf_insn jmp = BPF_JMP_REG(BPF_JLT, R1, R2, 0);
2868 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0x80000000);
2871 static int bpf_fill_staggered_jle_reg(struct bpf_test *self)
2873 struct bpf_insn jmp = BPF_JMP_REG(BPF_JLE, R1, R2, 0);
2875 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234);
2878 static int bpf_fill_staggered_jsgt_reg(struct bpf_test *self)
2880 struct bpf_insn jmp = BPF_JMP_REG(BPF_JSGT, R1, R2, 0);
2882 return __bpf_fill_staggered_jumps(self, &jmp, -1, -2);
2885 static int bpf_fill_staggered_jsge_reg(struct bpf_test *self)
2887 struct bpf_insn jmp = BPF_JMP_REG(BPF_JSGE, R1, R2, 0);
2889 return __bpf_fill_staggered_jumps(self, &jmp, -2, -2);
2892 static int bpf_fill_staggered_jslt_reg(struct bpf_test *self)
2894 struct bpf_insn jmp = BPF_JMP_REG(BPF_JSLT, R1, R2, 0);
2896 return __bpf_fill_staggered_jumps(self, &jmp, -2, -1);
2899 static int bpf_fill_staggered_jsle_reg(struct bpf_test *self)
2901 struct bpf_insn jmp = BPF_JMP_REG(BPF_JSLE, R1, R2, 0);
2903 return __bpf_fill_staggered_jumps(self, &jmp, -1, -1);
2906 /* 32-bit immediate jumps */
2907 static int bpf_fill_staggered_jeq32_imm(struct bpf_test *self)
2909 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JEQ, R1, 1234, 0);
2911 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2914 static int bpf_fill_staggered_jne32_imm(struct bpf_test *self)
2916 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JNE, R1, 1234, 0);
2918 return __bpf_fill_staggered_jumps(self, &jmp, 4321, 0);
2921 static int bpf_fill_staggered_jset32_imm(struct bpf_test *self)
2923 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSET, R1, 0x82, 0);
2925 return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0);
2928 static int bpf_fill_staggered_jgt32_imm(struct bpf_test *self)
2930 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JGT, R1, 1234, 0);
2932 return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 0);
2935 static int bpf_fill_staggered_jge32_imm(struct bpf_test *self)
2937 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JGE, R1, 1234, 0);
2939 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2942 static int bpf_fill_staggered_jlt32_imm(struct bpf_test *self)
2944 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JLT, R1, 0x80000000, 0);
2946 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2949 static int bpf_fill_staggered_jle32_imm(struct bpf_test *self)
2951 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JLE, R1, 1234, 0);
2953 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0);
2956 static int bpf_fill_staggered_jsgt32_imm(struct bpf_test *self)
2958 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSGT, R1, -2, 0);
2960 return __bpf_fill_staggered_jumps(self, &jmp, -1, 0);
2963 static int bpf_fill_staggered_jsge32_imm(struct bpf_test *self)
2965 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSGE, R1, -2, 0);
2967 return __bpf_fill_staggered_jumps(self, &jmp, -2, 0);
2970 static int bpf_fill_staggered_jslt32_imm(struct bpf_test *self)
2972 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSLT, R1, -1, 0);
2974 return __bpf_fill_staggered_jumps(self, &jmp, -2, 0);
2977 static int bpf_fill_staggered_jsle32_imm(struct bpf_test *self)
2979 struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSLE, R1, -1, 0);
2981 return __bpf_fill_staggered_jumps(self, &jmp, -1, 0);
2984 /* 32-bit register jumps */
2985 static int bpf_fill_staggered_jeq32_reg(struct bpf_test *self)
2987 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JEQ, R1, R2, 0);
2989 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234);
2992 static int bpf_fill_staggered_jne32_reg(struct bpf_test *self)
2994 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JNE, R1, R2, 0);
2996 return __bpf_fill_staggered_jumps(self, &jmp, 4321, 1234);
2999 static int bpf_fill_staggered_jset32_reg(struct bpf_test *self)
3001 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSET, R1, R2, 0);
3003 return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0x82);
3006 static int bpf_fill_staggered_jgt32_reg(struct bpf_test *self)
3008 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JGT, R1, R2, 0);
3010 return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 1234);
3013 static int bpf_fill_staggered_jge32_reg(struct bpf_test *self)
3015 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JGE, R1, R2, 0);
3017 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234);
3020 static int bpf_fill_staggered_jlt32_reg(struct bpf_test *self)
3022 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JLT, R1, R2, 0);
3024 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0x80000000);
3027 static int bpf_fill_staggered_jle32_reg(struct bpf_test *self)
3029 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JLE, R1, R2, 0);
3031 return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234);
3034 static int bpf_fill_staggered_jsgt32_reg(struct bpf_test *self)
3036 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSGT, R1, R2, 0);
3038 return __bpf_fill_staggered_jumps(self, &jmp, -1, -2);
3041 static int bpf_fill_staggered_jsge32_reg(struct bpf_test *self)
3043 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSGE, R1, R2, 0);
3045 return __bpf_fill_staggered_jumps(self, &jmp, -2, -2);
3048 static int bpf_fill_staggered_jslt32_reg(struct bpf_test *self)
3050 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSLT, R1, R2, 0);
3052 return __bpf_fill_staggered_jumps(self, &jmp, -2, -1);
3055 static int bpf_fill_staggered_jsle32_reg(struct bpf_test *self)
3057 struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSLE, R1, R2, 0);
3059 return __bpf_fill_staggered_jumps(self, &jmp, -1, -1);
3063 static struct bpf_test tests[] = {
3067 BPF_STMT(BPF_LD | BPF_IMM, 1),
3068 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3069 BPF_STMT(BPF_LD | BPF_IMM, 2),
3070 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3071 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
3072 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3073 BPF_STMT(BPF_LD | BPF_LEN, 0),
3074 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3075 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
3076 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
3077 BPF_STMT(BPF_RET | BPF_A, 0)
3080 { 10, 20, 30, 40, 50 },
3081 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
3086 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3087 BPF_STMT(BPF_MISC | BPF_TXA, 0),
3088 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3089 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
3092 { 10, 20, 30, 40, 50 },
3093 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
3098 BPF_STMT(BPF_LD | BPF_IMM, 1),
3099 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
3100 BPF_STMT(BPF_LDX | BPF_IMM, 3),
3101 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
3102 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
3103 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
3104 BPF_STMT(BPF_RET | BPF_A, 0)
3106 CLASSIC | FLAG_NO_DATA,
3108 { { 0, 0xfffffffd } }
3113 BPF_STMT(BPF_LD | BPF_IMM, 8),
3114 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
3115 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3116 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
3117 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
3118 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3119 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
3120 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
3121 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3122 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
3123 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
3124 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3125 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
3126 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
3127 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3128 BPF_STMT(BPF_RET | BPF_A, 0)
3130 CLASSIC | FLAG_NO_DATA,
3132 { { 0, 0x20000000 } }
3137 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
3138 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
3139 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
3140 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3141 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
3142 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
3143 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3144 BPF_STMT(BPF_RET | BPF_A, 0)
3146 CLASSIC | FLAG_NO_DATA,
3148 { { 0, 0x800000ff }, { 1, 0x800000ff } },
3153 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
3154 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
3155 BPF_STMT(BPF_RET | BPF_K, 0),
3156 BPF_STMT(BPF_RET | BPF_K, 1),
3165 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3166 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
3167 BPF_STMT(BPF_RET | BPF_K, 1)
3171 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
3176 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
3177 BPF_STMT(BPF_RET | BPF_K, 1)
3181 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
3186 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
3187 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3188 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
3189 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3190 BPF_STMT(BPF_RET | BPF_A, 0)
3194 { { 1, 0 }, { 2, 3 } },
3199 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
3200 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3201 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3202 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3203 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
3204 BPF_STMT(BPF_RET | BPF_A, 0)
3208 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
3213 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
3214 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3215 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
3216 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3217 BPF_STMT(BPF_RET | BPF_A, 0)
3220 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
3221 { { 15, 0 }, { 16, 3 } },
3226 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
3227 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3228 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
3229 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3230 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
3231 BPF_STMT(BPF_RET | BPF_A, 0)
3234 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
3235 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
3240 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3241 SKF_AD_OFF + SKF_AD_PKTTYPE),
3242 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
3243 BPF_STMT(BPF_RET | BPF_K, 1),
3244 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3245 SKF_AD_OFF + SKF_AD_PKTTYPE),
3246 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
3247 BPF_STMT(BPF_RET | BPF_K, 1),
3248 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3249 SKF_AD_OFF + SKF_AD_PKTTYPE),
3250 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
3251 BPF_STMT(BPF_RET | BPF_K, 1),
3252 BPF_STMT(BPF_RET | BPF_A, 0)
3256 { { 1, 3 }, { 10, 3 } },
3261 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3262 SKF_AD_OFF + SKF_AD_MARK),
3263 BPF_STMT(BPF_RET | BPF_A, 0)
3267 { { 1, SKB_MARK}, { 10, SKB_MARK} },
3272 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3273 SKF_AD_OFF + SKF_AD_RXHASH),
3274 BPF_STMT(BPF_RET | BPF_A, 0)
3278 { { 1, SKB_HASH}, { 10, SKB_HASH} },
3283 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3284 SKF_AD_OFF + SKF_AD_QUEUE),
3285 BPF_STMT(BPF_RET | BPF_A, 0)
3289 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
3294 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
3295 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
3296 BPF_STMT(BPF_RET | BPF_K, 0),
3297 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3298 SKF_AD_OFF + SKF_AD_PROTOCOL),
3299 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3300 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
3301 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
3302 BPF_STMT(BPF_RET | BPF_K, 0),
3303 BPF_STMT(BPF_MISC | BPF_TXA, 0),
3304 BPF_STMT(BPF_RET | BPF_A, 0)
3308 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
3313 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3314 SKF_AD_OFF + SKF_AD_VLAN_TAG),
3315 BPF_STMT(BPF_RET | BPF_A, 0)
3320 { 1, SKB_VLAN_TCI },
3321 { 10, SKB_VLAN_TCI }
3325 "LD_VLAN_TAG_PRESENT",
3327 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3328 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
3329 BPF_STMT(BPF_RET | BPF_A, 0)
3334 { 1, SKB_VLAN_PRESENT },
3335 { 10, SKB_VLAN_PRESENT }
3341 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3342 SKF_AD_OFF + SKF_AD_IFINDEX),
3343 BPF_STMT(BPF_RET | BPF_A, 0)
3347 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
3352 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3353 SKF_AD_OFF + SKF_AD_HATYPE),
3354 BPF_STMT(BPF_RET | BPF_A, 0)
3358 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
3363 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3364 SKF_AD_OFF + SKF_AD_CPU),
3365 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3366 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3367 SKF_AD_OFF + SKF_AD_CPU),
3368 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
3369 BPF_STMT(BPF_RET | BPF_A, 0)
3373 { { 1, 0 }, { 10, 0 } },
3378 BPF_STMT(BPF_LDX | BPF_IMM, 2),
3379 BPF_STMT(BPF_MISC | BPF_TXA, 0),
3380 BPF_STMT(BPF_LDX | BPF_IMM, 3),
3381 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3382 SKF_AD_OFF + SKF_AD_NLATTR),
3383 BPF_STMT(BPF_RET | BPF_A, 0)
3387 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
3389 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
3391 { { 4, 0 }, { 20, 6 } },
3396 BPF_STMT(BPF_LD | BPF_IMM, 2),
3397 BPF_STMT(BPF_LDX | BPF_IMM, 3),
3398 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3399 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3400 BPF_STMT(BPF_LD | BPF_IMM, 2),
3401 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3402 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3403 BPF_STMT(BPF_LD | BPF_IMM, 2),
3404 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3405 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3406 BPF_STMT(BPF_LD | BPF_IMM, 2),
3407 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3408 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3409 BPF_STMT(BPF_LD | BPF_IMM, 2),
3410 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3411 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3412 BPF_STMT(BPF_LD | BPF_IMM, 2),
3413 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3414 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3415 BPF_STMT(BPF_LD | BPF_IMM, 2),
3416 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3417 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3418 BPF_STMT(BPF_LD | BPF_IMM, 2),
3419 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3420 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
3421 BPF_STMT(BPF_RET | BPF_A, 0)
3425 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
3427 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
3429 { { 4, 0 }, { 20, 10 } },
3434 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3435 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
3436 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3437 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
3438 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3439 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
3440 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3441 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
3442 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3443 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
3444 BPF_STMT(BPF_RET | BPF_A, 0)
3447 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
3448 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
3449 * id 9737, seq 1, length 64
3451 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3452 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3454 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
3455 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
3456 { { 30, 0 }, { 100, 42 } },
3461 BPF_STMT(BPF_LD | BPF_IMM, 10),
3462 BPF_STMT(BPF_LDX | BPF_IMM, 300),
3463 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
3464 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
3465 BPF_STMT(BPF_RET | BPF_A, 0)
3469 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
3474 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3475 BPF_STMT(BPF_LD | BPF_IMM, 2),
3476 BPF_STMT(BPF_ALU | BPF_RSH, 1),
3477 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
3478 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
3479 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
3480 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
3481 BPF_STMT(BPF_STX, 15), /* M3 = len */
3482 BPF_STMT(BPF_LDX | BPF_MEM, 1),
3483 BPF_STMT(BPF_LD | BPF_MEM, 2),
3484 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
3485 BPF_STMT(BPF_LDX | BPF_MEM, 15),
3486 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
3487 BPF_STMT(BPF_RET | BPF_A, 0)
3491 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
3496 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3497 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
3498 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
3499 BPF_STMT(BPF_RET | BPF_K, 1),
3500 BPF_STMT(BPF_RET | BPF_K, MAX_K)
3504 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
3509 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3510 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
3511 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
3512 BPF_STMT(BPF_RET | BPF_K, 1),
3513 BPF_STMT(BPF_RET | BPF_K, MAX_K)
3517 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
3520 "JGE (jt 0), test 1",
3522 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3523 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
3524 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
3525 BPF_STMT(BPF_RET | BPF_K, 1),
3526 BPF_STMT(BPF_RET | BPF_K, MAX_K)
3530 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
3533 "JGE (jt 0), test 2",
3535 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3536 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
3537 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
3538 BPF_STMT(BPF_RET | BPF_K, 1),
3539 BPF_STMT(BPF_RET | BPF_K, MAX_K)
3543 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
3548 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3549 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
3550 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
3551 BPF_STMT(BPF_RET | BPF_K, 10),
3552 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
3553 BPF_STMT(BPF_RET | BPF_K, 20),
3554 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
3555 BPF_STMT(BPF_RET | BPF_K, 30),
3556 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
3557 BPF_STMT(BPF_RET | BPF_K, 40),
3558 BPF_STMT(BPF_RET | BPF_K, MAX_K)
3562 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
3567 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
3568 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
3569 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
3570 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
3571 BPF_STMT(BPF_LDX | BPF_LEN, 0),
3572 BPF_STMT(BPF_MISC | BPF_TXA, 0),
3573 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
3574 BPF_STMT(BPF_MISC | BPF_TAX, 0),
3575 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
3576 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
3577 BPF_STMT(BPF_RET | BPF_K, 10),
3578 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
3579 BPF_STMT(BPF_RET | BPF_K, 20),
3580 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
3581 BPF_STMT(BPF_RET | BPF_K, 30),
3582 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
3583 BPF_STMT(BPF_RET | BPF_K, 30),
3584 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
3585 BPF_STMT(BPF_RET | BPF_K, 30),
3586 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
3587 BPF_STMT(BPF_RET | BPF_K, 30),
3588 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
3589 BPF_STMT(BPF_RET | BPF_K, 30),
3590 BPF_STMT(BPF_RET | BPF_K, MAX_K)
3593 { 0, 0xAA, 0x55, 1 },
3594 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
3599 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
3600 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
3601 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
3602 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
3603 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
3604 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
3605 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
3606 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
3607 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
3608 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
3609 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
3610 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
3611 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
3612 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
3613 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
3614 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
3615 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
3616 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
3617 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
3618 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
3619 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
3620 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
3621 BPF_STMT(BPF_RET | BPF_K, 0xffff),
3622 BPF_STMT(BPF_RET | BPF_K, 0),
3625 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
3626 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
3627 * seq 1305692979:1305693027, ack 3650467037, win 65535,
3628 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
3630 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
3631 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
3633 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
3634 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
3635 0x0a, 0x01, 0x01, 0x95, /* ip src */
3636 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
3638 0x00, 0x16 /* dst port */ },
3639 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
3644 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
3645 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
3646 * (len > 115 or len < 30000000000)' -d
3648 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
3649 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
3650 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
3651 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
3652 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
3653 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
3654 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
3655 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
3656 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
3657 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
3658 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
3659 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
3660 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
3661 BPF_STMT(BPF_ST, 1),
3662 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
3663 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
3664 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
3665 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
3666 BPF_STMT(BPF_LD | BPF_MEM, 1),
3667 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
3668 BPF_STMT(BPF_ST, 5),
3669 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
3670 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
3671 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
3672 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
3673 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
3674 BPF_STMT(BPF_LD | BPF_MEM, 5),
3675 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
3676 BPF_STMT(BPF_LD | BPF_LEN, 0),
3677 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
3678 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
3679 BPF_STMT(BPF_RET | BPF_K, 0xffff),
3680 BPF_STMT(BPF_RET | BPF_K, 0),
3683 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
3684 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
3686 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
3687 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
3688 0x0a, 0x01, 0x01, 0x95, /* ip src */
3689 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
3691 0x00, 0x16 /* dst port */ },
3692 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
3697 /* check that uninitialized X and A contain zeros */
3698 BPF_STMT(BPF_MISC | BPF_TXA, 0),
3699 BPF_STMT(BPF_RET | BPF_A, 0)
3708 BPF_ALU64_IMM(BPF_MOV, R1, 1),
3709 BPF_ALU64_IMM(BPF_ADD, R1, 2),
3710 BPF_ALU64_IMM(BPF_MOV, R2, 3),
3711 BPF_ALU64_REG(BPF_SUB, R1, R2),
3712 BPF_ALU64_IMM(BPF_ADD, R1, -1),
3713 BPF_ALU64_IMM(BPF_MUL, R1, 3),
3714 BPF_ALU64_REG(BPF_MOV, R0, R1),
3719 { { 0, 0xfffffffd } }
3724 BPF_ALU64_IMM(BPF_MOV, R0, -1),
3725 BPF_ALU64_IMM(BPF_MOV, R1, -1),
3726 BPF_ALU64_IMM(BPF_MOV, R2, 3),
3727 BPF_ALU64_REG(BPF_MUL, R1, R2),
3728 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
3730 BPF_ALU64_IMM(BPF_MOV, R0, 1),
3740 BPF_ALU32_IMM(BPF_MOV, R0, -1),
3741 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3742 BPF_ALU32_IMM(BPF_MOV, R2, 3),
3743 BPF_ALU64_REG(BPF_MUL, R1, R2),
3744 BPF_ALU64_IMM(BPF_RSH, R1, 8),
3745 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
3747 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3757 BPF_ALU32_IMM(BPF_MOV, R0, -1),
3758 BPF_ALU64_IMM(BPF_MOV, R1, -1),
3759 BPF_ALU32_IMM(BPF_MOV, R2, 3),
3760 BPF_ALU32_REG(BPF_MUL, R1, R2),
3761 BPF_ALU64_IMM(BPF_RSH, R1, 8),
3762 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
3764 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3772 /* Have to test all register combinations, since
3773 * JITing of different registers will produce
3774 * different asm code.
3778 BPF_ALU64_IMM(BPF_MOV, R0, 0),
3779 BPF_ALU64_IMM(BPF_MOV, R1, 1),
3780 BPF_ALU64_IMM(BPF_MOV, R2, 2),
3781 BPF_ALU64_IMM(BPF_MOV, R3, 3),
3782 BPF_ALU64_IMM(BPF_MOV, R4, 4),
3783 BPF_ALU64_IMM(BPF_MOV, R5, 5),
3784 BPF_ALU64_IMM(BPF_MOV, R6, 6),
3785 BPF_ALU64_IMM(BPF_MOV, R7, 7),
3786 BPF_ALU64_IMM(BPF_MOV, R8, 8),
3787 BPF_ALU64_IMM(BPF_MOV, R9, 9),
3788 BPF_ALU64_IMM(BPF_ADD, R0, 20),
3789 BPF_ALU64_IMM(BPF_ADD, R1, 20),
3790 BPF_ALU64_IMM(BPF_ADD, R2, 20),
3791 BPF_ALU64_IMM(BPF_ADD, R3, 20),
3792 BPF_ALU64_IMM(BPF_ADD, R4, 20),
3793 BPF_ALU64_IMM(BPF_ADD, R5, 20),
3794 BPF_ALU64_IMM(BPF_ADD, R6, 20),
3795 BPF_ALU64_IMM(BPF_ADD, R7, 20),
3796 BPF_ALU64_IMM(BPF_ADD, R8, 20),
3797 BPF_ALU64_IMM(BPF_ADD, R9, 20),
3798 BPF_ALU64_IMM(BPF_SUB, R0, 10),
3799 BPF_ALU64_IMM(BPF_SUB, R1, 10),
3800 BPF_ALU64_IMM(BPF_SUB, R2, 10),
3801 BPF_ALU64_IMM(BPF_SUB, R3, 10),
3802 BPF_ALU64_IMM(BPF_SUB, R4, 10),
3803 BPF_ALU64_IMM(BPF_SUB, R5, 10),
3804 BPF_ALU64_IMM(BPF_SUB, R6, 10),
3805 BPF_ALU64_IMM(BPF_SUB, R7, 10),
3806 BPF_ALU64_IMM(BPF_SUB, R8, 10),
3807 BPF_ALU64_IMM(BPF_SUB, R9, 10),
3808 BPF_ALU64_REG(BPF_ADD, R0, R0),
3809 BPF_ALU64_REG(BPF_ADD, R0, R1),
3810 BPF_ALU64_REG(BPF_ADD, R0, R2),
3811 BPF_ALU64_REG(BPF_ADD, R0, R3),
3812 BPF_ALU64_REG(BPF_ADD, R0, R4),
3813 BPF_ALU64_REG(BPF_ADD, R0, R5),
3814 BPF_ALU64_REG(BPF_ADD, R0, R6),
3815 BPF_ALU64_REG(BPF_ADD, R0, R7),
3816 BPF_ALU64_REG(BPF_ADD, R0, R8),
3817 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
3818 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
3820 BPF_ALU64_REG(BPF_ADD, R1, R0),
3821 BPF_ALU64_REG(BPF_ADD, R1, R1),
3822 BPF_ALU64_REG(BPF_ADD, R1, R2),
3823 BPF_ALU64_REG(BPF_ADD, R1, R3),
3824 BPF_ALU64_REG(BPF_ADD, R1, R4),
3825 BPF_ALU64_REG(BPF_ADD, R1, R5),
3826 BPF_ALU64_REG(BPF_ADD, R1, R6),
3827 BPF_ALU64_REG(BPF_ADD, R1, R7),
3828 BPF_ALU64_REG(BPF_ADD, R1, R8),
3829 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
3830 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
3832 BPF_ALU64_REG(BPF_ADD, R2, R0),
3833 BPF_ALU64_REG(BPF_ADD, R2, R1),
3834 BPF_ALU64_REG(BPF_ADD, R2, R2),
3835 BPF_ALU64_REG(BPF_ADD, R2, R3),
3836 BPF_ALU64_REG(BPF_ADD, R2, R4),
3837 BPF_ALU64_REG(BPF_ADD, R2, R5),
3838 BPF_ALU64_REG(BPF_ADD, R2, R6),
3839 BPF_ALU64_REG(BPF_ADD, R2, R7),
3840 BPF_ALU64_REG(BPF_ADD, R2, R8),
3841 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
3842 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
3844 BPF_ALU64_REG(BPF_ADD, R3, R0),
3845 BPF_ALU64_REG(BPF_ADD, R3, R1),
3846 BPF_ALU64_REG(BPF_ADD, R3, R2),
3847 BPF_ALU64_REG(BPF_ADD, R3, R3),
3848 BPF_ALU64_REG(BPF_ADD, R3, R4),
3849 BPF_ALU64_REG(BPF_ADD, R3, R5),
3850 BPF_ALU64_REG(BPF_ADD, R3, R6),
3851 BPF_ALU64_REG(BPF_ADD, R3, R7),
3852 BPF_ALU64_REG(BPF_ADD, R3, R8),
3853 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
3854 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
3856 BPF_ALU64_REG(BPF_ADD, R4, R0),
3857 BPF_ALU64_REG(BPF_ADD, R4, R1),
3858 BPF_ALU64_REG(BPF_ADD, R4, R2),
3859 BPF_ALU64_REG(BPF_ADD, R4, R3),
3860 BPF_ALU64_REG(BPF_ADD, R4, R4),
3861 BPF_ALU64_REG(BPF_ADD, R4, R5),
3862 BPF_ALU64_REG(BPF_ADD, R4, R6),
3863 BPF_ALU64_REG(BPF_ADD, R4, R7),
3864 BPF_ALU64_REG(BPF_ADD, R4, R8),
3865 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
3866 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
3868 BPF_ALU64_REG(BPF_ADD, R5, R0),
3869 BPF_ALU64_REG(BPF_ADD, R5, R1),
3870 BPF_ALU64_REG(BPF_ADD, R5, R2),
3871 BPF_ALU64_REG(BPF_ADD, R5, R3),
3872 BPF_ALU64_REG(BPF_ADD, R5, R4),
3873 BPF_ALU64_REG(BPF_ADD, R5, R5),
3874 BPF_ALU64_REG(BPF_ADD, R5, R6),
3875 BPF_ALU64_REG(BPF_ADD, R5, R7),
3876 BPF_ALU64_REG(BPF_ADD, R5, R8),
3877 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
3878 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
3880 BPF_ALU64_REG(BPF_ADD, R6, R0),
3881 BPF_ALU64_REG(BPF_ADD, R6, R1),
3882 BPF_ALU64_REG(BPF_ADD, R6, R2),
3883 BPF_ALU64_REG(BPF_ADD, R6, R3),
3884 BPF_ALU64_REG(BPF_ADD, R6, R4),
3885 BPF_ALU64_REG(BPF_ADD, R6, R5),
3886 BPF_ALU64_REG(BPF_ADD, R6, R6),
3887 BPF_ALU64_REG(BPF_ADD, R6, R7),
3888 BPF_ALU64_REG(BPF_ADD, R6, R8),
3889 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
3890 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
3892 BPF_ALU64_REG(BPF_ADD, R7, R0),
3893 BPF_ALU64_REG(BPF_ADD, R7, R1),
3894 BPF_ALU64_REG(BPF_ADD, R7, R2),
3895 BPF_ALU64_REG(BPF_ADD, R7, R3),
3896 BPF_ALU64_REG(BPF_ADD, R7, R4),
3897 BPF_ALU64_REG(BPF_ADD, R7, R5),
3898 BPF_ALU64_REG(BPF_ADD, R7, R6),
3899 BPF_ALU64_REG(BPF_ADD, R7, R7),
3900 BPF_ALU64_REG(BPF_ADD, R7, R8),
3901 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
3902 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
3904 BPF_ALU64_REG(BPF_ADD, R8, R0),
3905 BPF_ALU64_REG(BPF_ADD, R8, R1),
3906 BPF_ALU64_REG(BPF_ADD, R8, R2),
3907 BPF_ALU64_REG(BPF_ADD, R8, R3),
3908 BPF_ALU64_REG(BPF_ADD, R8, R4),
3909 BPF_ALU64_REG(BPF_ADD, R8, R5),
3910 BPF_ALU64_REG(BPF_ADD, R8, R6),
3911 BPF_ALU64_REG(BPF_ADD, R8, R7),
3912 BPF_ALU64_REG(BPF_ADD, R8, R8),
3913 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
3914 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
3916 BPF_ALU64_REG(BPF_ADD, R9, R0),
3917 BPF_ALU64_REG(BPF_ADD, R9, R1),
3918 BPF_ALU64_REG(BPF_ADD, R9, R2),
3919 BPF_ALU64_REG(BPF_ADD, R9, R3),
3920 BPF_ALU64_REG(BPF_ADD, R9, R4),
3921 BPF_ALU64_REG(BPF_ADD, R9, R5),
3922 BPF_ALU64_REG(BPF_ADD, R9, R6),
3923 BPF_ALU64_REG(BPF_ADD, R9, R7),
3924 BPF_ALU64_REG(BPF_ADD, R9, R8),
3925 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
3926 BPF_ALU64_REG(BPF_MOV, R0, R9),
3936 BPF_ALU32_IMM(BPF_MOV, R0, 20),
3937 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3938 BPF_ALU32_IMM(BPF_MOV, R2, 2),
3939 BPF_ALU32_IMM(BPF_MOV, R3, 3),
3940 BPF_ALU32_IMM(BPF_MOV, R4, 4),
3941 BPF_ALU32_IMM(BPF_MOV, R5, 5),
3942 BPF_ALU32_IMM(BPF_MOV, R6, 6),
3943 BPF_ALU32_IMM(BPF_MOV, R7, 7),
3944 BPF_ALU32_IMM(BPF_MOV, R8, 8),
3945 BPF_ALU32_IMM(BPF_MOV, R9, 9),
3946 BPF_ALU64_IMM(BPF_ADD, R1, 10),
3947 BPF_ALU64_IMM(BPF_ADD, R2, 10),
3948 BPF_ALU64_IMM(BPF_ADD, R3, 10),
3949 BPF_ALU64_IMM(BPF_ADD, R4, 10),
3950 BPF_ALU64_IMM(BPF_ADD, R5, 10),
3951 BPF_ALU64_IMM(BPF_ADD, R6, 10),
3952 BPF_ALU64_IMM(BPF_ADD, R7, 10),
3953 BPF_ALU64_IMM(BPF_ADD, R8, 10),
3954 BPF_ALU64_IMM(BPF_ADD, R9, 10),
3955 BPF_ALU32_REG(BPF_ADD, R0, R1),
3956 BPF_ALU32_REG(BPF_ADD, R0, R2),
3957 BPF_ALU32_REG(BPF_ADD, R0, R3),
3958 BPF_ALU32_REG(BPF_ADD, R0, R4),
3959 BPF_ALU32_REG(BPF_ADD, R0, R5),
3960 BPF_ALU32_REG(BPF_ADD, R0, R6),
3961 BPF_ALU32_REG(BPF_ADD, R0, R7),
3962 BPF_ALU32_REG(BPF_ADD, R0, R8),
3963 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
3964 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
3966 BPF_ALU32_REG(BPF_ADD, R1, R0),
3967 BPF_ALU32_REG(BPF_ADD, R1, R1),
3968 BPF_ALU32_REG(BPF_ADD, R1, R2),
3969 BPF_ALU32_REG(BPF_ADD, R1, R3),
3970 BPF_ALU32_REG(BPF_ADD, R1, R4),
3971 BPF_ALU32_REG(BPF_ADD, R1, R5),
3972 BPF_ALU32_REG(BPF_ADD, R1, R6),
3973 BPF_ALU32_REG(BPF_ADD, R1, R7),
3974 BPF_ALU32_REG(BPF_ADD, R1, R8),
3975 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
3976 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
3978 BPF_ALU32_REG(BPF_ADD, R2, R0),
3979 BPF_ALU32_REG(BPF_ADD, R2, R1),
3980 BPF_ALU32_REG(BPF_ADD, R2, R2),
3981 BPF_ALU32_REG(BPF_ADD, R2, R3),
3982 BPF_ALU32_REG(BPF_ADD, R2, R4),
3983 BPF_ALU32_REG(BPF_ADD, R2, R5),
3984 BPF_ALU32_REG(BPF_ADD, R2, R6),
3985 BPF_ALU32_REG(BPF_ADD, R2, R7),
3986 BPF_ALU32_REG(BPF_ADD, R2, R8),
3987 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
3988 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
3990 BPF_ALU32_REG(BPF_ADD, R3, R0),
3991 BPF_ALU32_REG(BPF_ADD, R3, R1),
3992 BPF_ALU32_REG(BPF_ADD, R3, R2),
3993 BPF_ALU32_REG(BPF_ADD, R3, R3),
3994 BPF_ALU32_REG(BPF_ADD, R3, R4),
3995 BPF_ALU32_REG(BPF_ADD, R3, R5),
3996 BPF_ALU32_REG(BPF_ADD, R3, R6),
3997 BPF_ALU32_REG(BPF_ADD, R3, R7),
3998 BPF_ALU32_REG(BPF_ADD, R3, R8),
3999 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
4000 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
4002 BPF_ALU32_REG(BPF_ADD, R4, R0),
4003 BPF_ALU32_REG(BPF_ADD, R4, R1),
4004 BPF_ALU32_REG(BPF_ADD, R4, R2),
4005 BPF_ALU32_REG(BPF_ADD, R4, R3),
4006 BPF_ALU32_REG(BPF_ADD, R4, R4),
4007 BPF_ALU32_REG(BPF_ADD, R4, R5),
4008 BPF_ALU32_REG(BPF_ADD, R4, R6),
4009 BPF_ALU32_REG(BPF_ADD, R4, R7),
4010 BPF_ALU32_REG(BPF_ADD, R4, R8),
4011 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
4012 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
4014 BPF_ALU32_REG(BPF_ADD, R5, R0),
4015 BPF_ALU32_REG(BPF_ADD, R5, R1),
4016 BPF_ALU32_REG(BPF_ADD, R5, R2),
4017 BPF_ALU32_REG(BPF_ADD, R5, R3),
4018 BPF_ALU32_REG(BPF_ADD, R5, R4),
4019 BPF_ALU32_REG(BPF_ADD, R5, R5),
4020 BPF_ALU32_REG(BPF_ADD, R5, R6),
4021 BPF_ALU32_REG(BPF_ADD, R5, R7),
4022 BPF_ALU32_REG(BPF_ADD, R5, R8),
4023 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
4024 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
4026 BPF_ALU32_REG(BPF_ADD, R6, R0),
4027 BPF_ALU32_REG(BPF_ADD, R6, R1),
4028 BPF_ALU32_REG(BPF_ADD, R6, R2),
4029 BPF_ALU32_REG(BPF_ADD, R6, R3),
4030 BPF_ALU32_REG(BPF_ADD, R6, R4),
4031 BPF_ALU32_REG(BPF_ADD, R6, R5),
4032 BPF_ALU32_REG(BPF_ADD, R6, R6),
4033 BPF_ALU32_REG(BPF_ADD, R6, R7),
4034 BPF_ALU32_REG(BPF_ADD, R6, R8),
4035 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
4036 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
4038 BPF_ALU32_REG(BPF_ADD, R7, R0),
4039 BPF_ALU32_REG(BPF_ADD, R7, R1),
4040 BPF_ALU32_REG(BPF_ADD, R7, R2),
4041 BPF_ALU32_REG(BPF_ADD, R7, R3),
4042 BPF_ALU32_REG(BPF_ADD, R7, R4),
4043 BPF_ALU32_REG(BPF_ADD, R7, R5),
4044 BPF_ALU32_REG(BPF_ADD, R7, R6),
4045 BPF_ALU32_REG(BPF_ADD, R7, R7),
4046 BPF_ALU32_REG(BPF_ADD, R7, R8),
4047 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
4048 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
4050 BPF_ALU32_REG(BPF_ADD, R8, R0),
4051 BPF_ALU32_REG(BPF_ADD, R8, R1),
4052 BPF_ALU32_REG(BPF_ADD, R8, R2),
4053 BPF_ALU32_REG(BPF_ADD, R8, R3),
4054 BPF_ALU32_REG(BPF_ADD, R8, R4),
4055 BPF_ALU32_REG(BPF_ADD, R8, R5),
4056 BPF_ALU32_REG(BPF_ADD, R8, R6),
4057 BPF_ALU32_REG(BPF_ADD, R8, R7),
4058 BPF_ALU32_REG(BPF_ADD, R8, R8),
4059 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
4060 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
4062 BPF_ALU32_REG(BPF_ADD, R9, R0),
4063 BPF_ALU32_REG(BPF_ADD, R9, R1),
4064 BPF_ALU32_REG(BPF_ADD, R9, R2),
4065 BPF_ALU32_REG(BPF_ADD, R9, R3),
4066 BPF_ALU32_REG(BPF_ADD, R9, R4),
4067 BPF_ALU32_REG(BPF_ADD, R9, R5),
4068 BPF_ALU32_REG(BPF_ADD, R9, R6),
4069 BPF_ALU32_REG(BPF_ADD, R9, R7),
4070 BPF_ALU32_REG(BPF_ADD, R9, R8),
4071 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
4072 BPF_ALU32_REG(BPF_MOV, R0, R9),
4079 { /* Mainly checking JIT here. */
4082 BPF_ALU64_IMM(BPF_MOV, R0, 0),
4083 BPF_ALU64_IMM(BPF_MOV, R1, 1),
4084 BPF_ALU64_IMM(BPF_MOV, R2, 2),
4085 BPF_ALU64_IMM(BPF_MOV, R3, 3),
4086 BPF_ALU64_IMM(BPF_MOV, R4, 4),
4087 BPF_ALU64_IMM(BPF_MOV, R5, 5),
4088 BPF_ALU64_IMM(BPF_MOV, R6, 6),
4089 BPF_ALU64_IMM(BPF_MOV, R7, 7),
4090 BPF_ALU64_IMM(BPF_MOV, R8, 8),
4091 BPF_ALU64_IMM(BPF_MOV, R9, 9),
4092 BPF_ALU64_REG(BPF_SUB, R0, R0),
4093 BPF_ALU64_REG(BPF_SUB, R0, R1),
4094 BPF_ALU64_REG(BPF_SUB, R0, R2),
4095 BPF_ALU64_REG(BPF_SUB, R0, R3),
4096 BPF_ALU64_REG(BPF_SUB, R0, R4),
4097 BPF_ALU64_REG(BPF_SUB, R0, R5),
4098 BPF_ALU64_REG(BPF_SUB, R0, R6),
4099 BPF_ALU64_REG(BPF_SUB, R0, R7),
4100 BPF_ALU64_REG(BPF_SUB, R0, R8),
4101 BPF_ALU64_REG(BPF_SUB, R0, R9),
4102 BPF_ALU64_IMM(BPF_SUB, R0, 10),
4103 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
4105 BPF_ALU64_REG(BPF_SUB, R1, R0),
4106 BPF_ALU64_REG(BPF_SUB, R1, R2),
4107 BPF_ALU64_REG(BPF_SUB, R1, R3),
4108 BPF_ALU64_REG(BPF_SUB, R1, R4),
4109 BPF_ALU64_REG(BPF_SUB, R1, R5),
4110 BPF_ALU64_REG(BPF_SUB, R1, R6),
4111 BPF_ALU64_REG(BPF_SUB, R1, R7),
4112 BPF_ALU64_REG(BPF_SUB, R1, R8),
4113 BPF_ALU64_REG(BPF_SUB, R1, R9),
4114 BPF_ALU64_IMM(BPF_SUB, R1, 10),
4115 BPF_ALU64_REG(BPF_SUB, R2, R0),
4116 BPF_ALU64_REG(BPF_SUB, R2, R1),
4117 BPF_ALU64_REG(BPF_SUB, R2, R3),
4118 BPF_ALU64_REG(BPF_SUB, R2, R4),
4119 BPF_ALU64_REG(BPF_SUB, R2, R5),
4120 BPF_ALU64_REG(BPF_SUB, R2, R6),
4121 BPF_ALU64_REG(BPF_SUB, R2, R7),
4122 BPF_ALU64_REG(BPF_SUB, R2, R8),
4123 BPF_ALU64_REG(BPF_SUB, R2, R9),
4124 BPF_ALU64_IMM(BPF_SUB, R2, 10),
4125 BPF_ALU64_REG(BPF_SUB, R3, R0),
4126 BPF_ALU64_REG(BPF_SUB, R3, R1),
4127 BPF_ALU64_REG(BPF_SUB, R3, R2),
4128 BPF_ALU64_REG(BPF_SUB, R3, R4),
4129 BPF_ALU64_REG(BPF_SUB, R3, R5),
4130 BPF_ALU64_REG(BPF_SUB, R3, R6),
4131 BPF_ALU64_REG(BPF_SUB, R3, R7),
4132 BPF_ALU64_REG(BPF_SUB, R3, R8),
4133 BPF_ALU64_REG(BPF_SUB, R3, R9),
4134 BPF_ALU64_IMM(BPF_SUB, R3, 10),
4135 BPF_ALU64_REG(BPF_SUB, R4, R0),
4136 BPF_ALU64_REG(BPF_SUB, R4, R1),
4137 BPF_ALU64_REG(BPF_SUB, R4, R2),
4138 BPF_ALU64_REG(BPF_SUB, R4, R3),
4139 BPF_ALU64_REG(BPF_SUB, R4, R5),
4140 BPF_ALU64_REG(BPF_SUB, R4, R6),
4141 BPF_ALU64_REG(BPF_SUB, R4, R7),
4142 BPF_ALU64_REG(BPF_SUB, R4, R8),
4143 BPF_ALU64_REG(BPF_SUB, R4, R9),
4144 BPF_ALU64_IMM(BPF_SUB, R4, 10),
4145 BPF_ALU64_REG(BPF_SUB, R5, R0),
4146 BPF_ALU64_REG(BPF_SUB, R5, R1),
4147 BPF_ALU64_REG(BPF_SUB, R5, R2),
4148 BPF_ALU64_REG(BPF_SUB, R5, R3),
4149 BPF_ALU64_REG(BPF_SUB, R5, R4),
4150 BPF_ALU64_REG(BPF_SUB, R5, R6),
4151 BPF_ALU64_REG(BPF_SUB, R5, R7),
4152 BPF_ALU64_REG(BPF_SUB, R5, R8),
4153 BPF_ALU64_REG(BPF_SUB, R5, R9),
4154 BPF_ALU64_IMM(BPF_SUB, R5, 10),
4155 BPF_ALU64_REG(BPF_SUB, R6, R0),
4156 BPF_ALU64_REG(BPF_SUB, R6, R1),
4157 BPF_ALU64_REG(BPF_SUB, R6, R2),
4158 BPF_ALU64_REG(BPF_SUB, R6, R3),
4159 BPF_ALU64_REG(BPF_SUB, R6, R4),
4160 BPF_ALU64_REG(BPF_SUB, R6, R5),
4161 BPF_ALU64_REG(BPF_SUB, R6, R7),
4162 BPF_ALU64_REG(BPF_SUB, R6, R8),
4163 BPF_ALU64_REG(BPF_SUB, R6, R9),
4164 BPF_ALU64_IMM(BPF_SUB, R6, 10),
4165 BPF_ALU64_REG(BPF_SUB, R7, R0),
4166 BPF_ALU64_REG(BPF_SUB, R7, R1),
4167 BPF_ALU64_REG(BPF_SUB, R7, R2),
4168 BPF_ALU64_REG(BPF_SUB, R7, R3),
4169 BPF_ALU64_REG(BPF_SUB, R7, R4),
4170 BPF_ALU64_REG(BPF_SUB, R7, R5),
4171 BPF_ALU64_REG(BPF_SUB, R7, R6),
4172 BPF_ALU64_REG(BPF_SUB, R7, R8),
4173 BPF_ALU64_REG(BPF_SUB, R7, R9),
4174 BPF_ALU64_IMM(BPF_SUB, R7, 10),
4175 BPF_ALU64_REG(BPF_SUB, R8, R0),
4176 BPF_ALU64_REG(BPF_SUB, R8, R1),
4177 BPF_ALU64_REG(BPF_SUB, R8, R2),
4178 BPF_ALU64_REG(BPF_SUB, R8, R3),
4179 BPF_ALU64_REG(BPF_SUB, R8, R4),
4180 BPF_ALU64_REG(BPF_SUB, R8, R5),
4181 BPF_ALU64_REG(BPF_SUB, R8, R6),
4182 BPF_ALU64_REG(BPF_SUB, R8, R7),
4183 BPF_ALU64_REG(BPF_SUB, R8, R9),
4184 BPF_ALU64_IMM(BPF_SUB, R8, 10),
4185 BPF_ALU64_REG(BPF_SUB, R9, R0),
4186 BPF_ALU64_REG(BPF_SUB, R9, R1),
4187 BPF_ALU64_REG(BPF_SUB, R9, R2),
4188 BPF_ALU64_REG(BPF_SUB, R9, R3),
4189 BPF_ALU64_REG(BPF_SUB, R9, R4),
4190 BPF_ALU64_REG(BPF_SUB, R9, R5),
4191 BPF_ALU64_REG(BPF_SUB, R9, R6),
4192 BPF_ALU64_REG(BPF_SUB, R9, R7),
4193 BPF_ALU64_REG(BPF_SUB, R9, R8),
4194 BPF_ALU64_IMM(BPF_SUB, R9, 10),
4195 BPF_ALU64_IMM(BPF_SUB, R0, 10),
4196 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4197 BPF_ALU64_REG(BPF_SUB, R0, R1),
4198 BPF_ALU64_REG(BPF_SUB, R0, R2),
4199 BPF_ALU64_REG(BPF_SUB, R0, R3),
4200 BPF_ALU64_REG(BPF_SUB, R0, R4),
4201 BPF_ALU64_REG(BPF_SUB, R0, R5),
4202 BPF_ALU64_REG(BPF_SUB, R0, R6),
4203 BPF_ALU64_REG(BPF_SUB, R0, R7),
4204 BPF_ALU64_REG(BPF_SUB, R0, R8),
4205 BPF_ALU64_REG(BPF_SUB, R0, R9),
4212 { /* Mainly checking JIT here. */
4215 BPF_ALU64_REG(BPF_SUB, R0, R0),
4216 BPF_ALU64_REG(BPF_XOR, R1, R1),
4217 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
4219 BPF_ALU64_IMM(BPF_MOV, R0, 10),
4220 BPF_ALU64_IMM(BPF_MOV, R1, -1),
4221 BPF_ALU64_REG(BPF_SUB, R1, R1),
4222 BPF_ALU64_REG(BPF_XOR, R2, R2),
4223 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4225 BPF_ALU64_REG(BPF_SUB, R2, R2),
4226 BPF_ALU64_REG(BPF_XOR, R3, R3),
4227 BPF_ALU64_IMM(BPF_MOV, R0, 10),
4228 BPF_ALU64_IMM(BPF_MOV, R1, -1),
4229 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
4231 BPF_ALU64_REG(BPF_SUB, R3, R3),
4232 BPF_ALU64_REG(BPF_XOR, R4, R4),
4233 BPF_ALU64_IMM(BPF_MOV, R2, 1),
4234 BPF_ALU64_IMM(BPF_MOV, R5, -1),
4235 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
4237 BPF_ALU64_REG(BPF_SUB, R4, R4),
4238 BPF_ALU64_REG(BPF_XOR, R5, R5),
4239 BPF_ALU64_IMM(BPF_MOV, R3, 1),
4240 BPF_ALU64_IMM(BPF_MOV, R7, -1),
4241 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
4243 BPF_ALU64_IMM(BPF_MOV, R5, 1),
4244 BPF_ALU64_REG(BPF_SUB, R5, R5),
4245 BPF_ALU64_REG(BPF_XOR, R6, R6),
4246 BPF_ALU64_IMM(BPF_MOV, R1, 1),
4247 BPF_ALU64_IMM(BPF_MOV, R8, -1),
4248 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
4250 BPF_ALU64_REG(BPF_SUB, R6, R6),
4251 BPF_ALU64_REG(BPF_XOR, R7, R7),
4252 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
4254 BPF_ALU64_REG(BPF_SUB, R7, R7),
4255 BPF_ALU64_REG(BPF_XOR, R8, R8),
4256 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
4258 BPF_ALU64_REG(BPF_SUB, R8, R8),
4259 BPF_ALU64_REG(BPF_XOR, R9, R9),
4260 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
4262 BPF_ALU64_REG(BPF_SUB, R9, R9),
4263 BPF_ALU64_REG(BPF_XOR, R0, R0),
4264 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
4266 BPF_ALU64_REG(BPF_SUB, R1, R1),
4267 BPF_ALU64_REG(BPF_XOR, R0, R0),
4268 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
4269 BPF_ALU64_IMM(BPF_MOV, R0, 0),
4271 BPF_ALU64_IMM(BPF_MOV, R0, 1),
4278 { /* Mainly checking JIT here. */
4281 BPF_ALU64_IMM(BPF_MOV, R0, 11),
4282 BPF_ALU64_IMM(BPF_MOV, R1, 1),
4283 BPF_ALU64_IMM(BPF_MOV, R2, 2),
4284 BPF_ALU64_IMM(BPF_MOV, R3, 3),
4285 BPF_ALU64_IMM(BPF_MOV, R4, 4),
4286 BPF_ALU64_IMM(BPF_MOV, R5, 5),
4287 BPF_ALU64_IMM(BPF_MOV, R6, 6),
4288 BPF_ALU64_IMM(BPF_MOV, R7, 7),
4289 BPF_ALU64_IMM(BPF_MOV, R8, 8),
4290 BPF_ALU64_IMM(BPF_MOV, R9, 9),
4291 BPF_ALU64_REG(BPF_MUL, R0, R0),
4292 BPF_ALU64_REG(BPF_MUL, R0, R1),
4293 BPF_ALU64_REG(BPF_MUL, R0, R2),
4294 BPF_ALU64_REG(BPF_MUL, R0, R3),
4295 BPF_ALU64_REG(BPF_MUL, R0, R4),
4296 BPF_ALU64_REG(BPF_MUL, R0, R5),
4297 BPF_ALU64_REG(BPF_MUL, R0, R6),
4298 BPF_ALU64_REG(BPF_MUL, R0, R7),
4299 BPF_ALU64_REG(BPF_MUL, R0, R8),
4300 BPF_ALU64_REG(BPF_MUL, R0, R9),
4301 BPF_ALU64_IMM(BPF_MUL, R0, 10),
4302 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
4304 BPF_ALU64_REG(BPF_MUL, R1, R0),
4305 BPF_ALU64_REG(BPF_MUL, R1, R2),
4306 BPF_ALU64_REG(BPF_MUL, R1, R3),
4307 BPF_ALU64_REG(BPF_MUL, R1, R4),
4308 BPF_ALU64_REG(BPF_MUL, R1, R5),
4309 BPF_ALU64_REG(BPF_MUL, R1, R6),
4310 BPF_ALU64_REG(BPF_MUL, R1, R7),
4311 BPF_ALU64_REG(BPF_MUL, R1, R8),
4312 BPF_ALU64_REG(BPF_MUL, R1, R9),
4313 BPF_ALU64_IMM(BPF_MUL, R1, 10),
4314 BPF_ALU64_REG(BPF_MOV, R2, R1),
4315 BPF_ALU64_IMM(BPF_RSH, R2, 32),
4316 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
4318 BPF_ALU64_IMM(BPF_LSH, R1, 32),
4319 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
4320 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
4322 BPF_ALU64_REG(BPF_MUL, R2, R0),
4323 BPF_ALU64_REG(BPF_MUL, R2, R1),
4324 BPF_ALU64_REG(BPF_MUL, R2, R3),
4325 BPF_ALU64_REG(BPF_MUL, R2, R4),
4326 BPF_ALU64_REG(BPF_MUL, R2, R5),
4327 BPF_ALU64_REG(BPF_MUL, R2, R6),
4328 BPF_ALU64_REG(BPF_MUL, R2, R7),
4329 BPF_ALU64_REG(BPF_MUL, R2, R8),
4330 BPF_ALU64_REG(BPF_MUL, R2, R9),
4331 BPF_ALU64_IMM(BPF_MUL, R2, 10),
4332 BPF_ALU64_IMM(BPF_RSH, R2, 32),
4333 BPF_ALU64_REG(BPF_MOV, R0, R2),
4338 { { 0, 0x35d97ef2 } }
4340 { /* Mainly checking JIT here. */
4343 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
4344 BPF_MOV64_REG(R1, R0),
4345 BPF_MOV64_REG(R2, R1),
4346 BPF_MOV64_REG(R3, R2),
4347 BPF_MOV64_REG(R4, R3),
4348 BPF_MOV64_REG(R5, R4),
4349 BPF_MOV64_REG(R6, R5),
4350 BPF_MOV64_REG(R7, R6),
4351 BPF_MOV64_REG(R8, R7),
4352 BPF_MOV64_REG(R9, R8),
4353 BPF_ALU64_IMM(BPF_MOV, R0, 0),
4354 BPF_ALU64_IMM(BPF_MOV, R1, 0),
4355 BPF_ALU64_IMM(BPF_MOV, R2, 0),
4356 BPF_ALU64_IMM(BPF_MOV, R3, 0),
4357 BPF_ALU64_IMM(BPF_MOV, R4, 0),
4358 BPF_ALU64_IMM(BPF_MOV, R5, 0),
4359 BPF_ALU64_IMM(BPF_MOV, R6, 0),
4360 BPF_ALU64_IMM(BPF_MOV, R7, 0),
4361 BPF_ALU64_IMM(BPF_MOV, R8, 0),
4362 BPF_ALU64_IMM(BPF_MOV, R9, 0),
4363 BPF_ALU64_REG(BPF_ADD, R0, R0),
4364 BPF_ALU64_REG(BPF_ADD, R0, R1),
4365 BPF_ALU64_REG(BPF_ADD, R0, R2),
4366 BPF_ALU64_REG(BPF_ADD, R0, R3),
4367 BPF_ALU64_REG(BPF_ADD, R0, R4),
4368 BPF_ALU64_REG(BPF_ADD, R0, R5),
4369 BPF_ALU64_REG(BPF_ADD, R0, R6),
4370 BPF_ALU64_REG(BPF_ADD, R0, R7),
4371 BPF_ALU64_REG(BPF_ADD, R0, R8),
4372 BPF_ALU64_REG(BPF_ADD, R0, R9),
4373 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
4380 { /* Mainly checking JIT here. */
4383 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
4384 BPF_MOV64_REG(R1, R0),
4385 BPF_MOV64_REG(R2, R1),
4386 BPF_MOV64_REG(R3, R2),
4387 BPF_MOV64_REG(R4, R3),
4388 BPF_MOV64_REG(R5, R4),
4389 BPF_MOV64_REG(R6, R5),
4390 BPF_MOV64_REG(R7, R6),
4391 BPF_MOV64_REG(R8, R7),
4392 BPF_MOV64_REG(R9, R8),
4393 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4394 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4395 BPF_ALU32_IMM(BPF_MOV, R2, 0),
4396 BPF_ALU32_IMM(BPF_MOV, R3, 0),
4397 BPF_ALU32_IMM(BPF_MOV, R4, 0),
4398 BPF_ALU32_IMM(BPF_MOV, R5, 0),
4399 BPF_ALU32_IMM(BPF_MOV, R6, 0),
4400 BPF_ALU32_IMM(BPF_MOV, R7, 0),
4401 BPF_ALU32_IMM(BPF_MOV, R8, 0),
4402 BPF_ALU32_IMM(BPF_MOV, R9, 0),
4403 BPF_ALU64_REG(BPF_ADD, R0, R0),
4404 BPF_ALU64_REG(BPF_ADD, R0, R1),
4405 BPF_ALU64_REG(BPF_ADD, R0, R2),
4406 BPF_ALU64_REG(BPF_ADD, R0, R3),
4407 BPF_ALU64_REG(BPF_ADD, R0, R4),
4408 BPF_ALU64_REG(BPF_ADD, R0, R5),
4409 BPF_ALU64_REG(BPF_ADD, R0, R6),
4410 BPF_ALU64_REG(BPF_ADD, R0, R7),
4411 BPF_ALU64_REG(BPF_ADD, R0, R8),
4412 BPF_ALU64_REG(BPF_ADD, R0, R9),
4413 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
4420 { /* Mainly checking JIT here. */
4423 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
4424 BPF_MOV64_REG(R1, R0),
4425 BPF_MOV64_REG(R2, R1),
4426 BPF_MOV64_REG(R3, R2),
4427 BPF_MOV64_REG(R4, R3),
4428 BPF_MOV64_REG(R5, R4),
4429 BPF_MOV64_REG(R6, R5),
4430 BPF_MOV64_REG(R7, R6),
4431 BPF_MOV64_REG(R8, R7),
4432 BPF_MOV64_REG(R9, R8),
4433 BPF_LD_IMM64(R0, 0x0LL),
4434 BPF_LD_IMM64(R1, 0x0LL),
4435 BPF_LD_IMM64(R2, 0x0LL),
4436 BPF_LD_IMM64(R3, 0x0LL),
4437 BPF_LD_IMM64(R4, 0x0LL),
4438 BPF_LD_IMM64(R5, 0x0LL),
4439 BPF_LD_IMM64(R6, 0x0LL),
4440 BPF_LD_IMM64(R7, 0x0LL),
4441 BPF_LD_IMM64(R8, 0x0LL),
4442 BPF_LD_IMM64(R9, 0x0LL),
4443 BPF_ALU64_REG(BPF_ADD, R0, R0),
4444 BPF_ALU64_REG(BPF_ADD, R0, R1),
4445 BPF_ALU64_REG(BPF_ADD, R0, R2),
4446 BPF_ALU64_REG(BPF_ADD, R0, R3),
4447 BPF_ALU64_REG(BPF_ADD, R0, R4),
4448 BPF_ALU64_REG(BPF_ADD, R0, R5),
4449 BPF_ALU64_REG(BPF_ADD, R0, R6),
4450 BPF_ALU64_REG(BPF_ADD, R0, R7),
4451 BPF_ALU64_REG(BPF_ADD, R0, R8),
4452 BPF_ALU64_REG(BPF_ADD, R0, R9),
4453 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
4463 BPF_ALU64_IMM(BPF_MOV, R0, 11),
4464 BPF_ALU64_IMM(BPF_ADD, R0, -1),
4465 BPF_ALU64_IMM(BPF_MOV, R2, 2),
4466 BPF_ALU64_IMM(BPF_XOR, R2, 3),
4467 BPF_ALU64_REG(BPF_DIV, R0, R2),
4468 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
4470 BPF_ALU64_IMM(BPF_MOD, R0, 3),
4471 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
4473 BPF_ALU64_IMM(BPF_MOV, R0, -1),
4481 "INT: shifts by register",
4483 BPF_MOV64_IMM(R0, -1234),
4484 BPF_MOV64_IMM(R1, 1),
4485 BPF_ALU32_REG(BPF_RSH, R0, R1),
4486 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
4488 BPF_MOV64_IMM(R2, 1),
4489 BPF_ALU64_REG(BPF_LSH, R0, R2),
4490 BPF_MOV32_IMM(R4, -1234),
4491 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
4493 BPF_ALU64_IMM(BPF_AND, R4, 63),
4494 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
4495 BPF_MOV64_IMM(R3, 47),
4496 BPF_ALU64_REG(BPF_ARSH, R0, R3),
4497 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
4499 BPF_MOV64_IMM(R2, 1),
4500 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
4501 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
4503 BPF_MOV64_IMM(R4, 4),
4504 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
4505 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
4507 BPF_MOV64_IMM(R4, 5),
4508 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
4509 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
4511 BPF_MOV64_IMM(R0, -1),
4520 "INT: 32-bit context pointer word order and zero-extension",
4522 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4523 BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3),
4524 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4525 BPF_JMP32_IMM(BPF_JNE, R1, 0, 1),
4526 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4535 "check: missing ret",
4537 BPF_STMT(BPF_LD | BPF_IMM, 1),
4539 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4542 .fill_helper = NULL,
4543 .expected_errcode = -EINVAL,
4548 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
4549 BPF_STMT(BPF_RET | BPF_K, 0)
4551 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4554 .fill_helper = NULL,
4555 .expected_errcode = -EINVAL,
4558 "check: unknown insn",
4560 /* seccomp insn, rejected in socket filter */
4561 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
4562 BPF_STMT(BPF_RET | BPF_K, 0)
4564 CLASSIC | FLAG_EXPECTED_FAIL,
4567 .fill_helper = NULL,
4568 .expected_errcode = -EINVAL,
4571 "check: out of range spill/fill",
4573 BPF_STMT(BPF_STX, 16),
4574 BPF_STMT(BPF_RET | BPF_K, 0)
4576 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4579 .fill_helper = NULL,
4580 .expected_errcode = -EINVAL,
4585 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4586 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
4587 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4588 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4589 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4590 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4591 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4592 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4593 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4594 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4595 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4596 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4597 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4598 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4599 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4600 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
4601 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4602 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
4603 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4604 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
4605 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
4606 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4607 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4608 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4609 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4610 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4611 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4612 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4613 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4614 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4615 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4616 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4617 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4618 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4619 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
4620 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
4621 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4622 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
4623 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
4624 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4625 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4626 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4627 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4628 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4629 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4630 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4631 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4632 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4633 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4634 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4635 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4636 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4637 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
4638 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
4639 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
4640 BPF_STMT(BPF_RET | BPF_A, 0),
4641 BPF_STMT(BPF_RET | BPF_A, 0),
4644 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
4645 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
4647 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
4648 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
4649 0xc0, 0xa8, 0x33, 0x01,
4650 0xc0, 0xa8, 0x33, 0x02,
4653 0x00, 0x14, 0x00, 0x00,
4654 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4655 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4656 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4657 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4658 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4659 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4660 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
4661 0xcc, 0xcc, 0xcc, 0xcc },
4667 BPF_STMT(BPF_RET | BPF_X, 0),
4669 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4672 .fill_helper = NULL,
4673 .expected_errcode = -EINVAL,
4676 "check: LDX + RET X",
4678 BPF_STMT(BPF_LDX | BPF_IMM, 42),
4679 BPF_STMT(BPF_RET | BPF_X, 0),
4681 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4684 .fill_helper = NULL,
4685 .expected_errcode = -EINVAL,
4687 { /* Mainly checking JIT here. */
4688 "M[]: alt STX + LDX",
4690 BPF_STMT(BPF_LDX | BPF_IMM, 100),
4691 BPF_STMT(BPF_STX, 0),
4692 BPF_STMT(BPF_LDX | BPF_MEM, 0),
4693 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4694 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4695 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4696 BPF_STMT(BPF_STX, 1),
4697 BPF_STMT(BPF_LDX | BPF_MEM, 1),
4698 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4699 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4700 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4701 BPF_STMT(BPF_STX, 2),
4702 BPF_STMT(BPF_LDX | BPF_MEM, 2),
4703 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4704 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4705 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4706 BPF_STMT(BPF_STX, 3),
4707 BPF_STMT(BPF_LDX | BPF_MEM, 3),
4708 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4709 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4710 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4711 BPF_STMT(BPF_STX, 4),
4712 BPF_STMT(BPF_LDX | BPF_MEM, 4),
4713 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4714 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4715 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4716 BPF_STMT(BPF_STX, 5),
4717 BPF_STMT(BPF_LDX | BPF_MEM, 5),
4718 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4719 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4720 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4721 BPF_STMT(BPF_STX, 6),
4722 BPF_STMT(BPF_LDX | BPF_MEM, 6),
4723 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4724 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4725 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4726 BPF_STMT(BPF_STX, 7),
4727 BPF_STMT(BPF_LDX | BPF_MEM, 7),
4728 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4729 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4730 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4731 BPF_STMT(BPF_STX, 8),
4732 BPF_STMT(BPF_LDX | BPF_MEM, 8),
4733 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4734 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4735 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4736 BPF_STMT(BPF_STX, 9),
4737 BPF_STMT(BPF_LDX | BPF_MEM, 9),
4738 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4739 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4740 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4741 BPF_STMT(BPF_STX, 10),
4742 BPF_STMT(BPF_LDX | BPF_MEM, 10),
4743 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4744 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4745 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4746 BPF_STMT(BPF_STX, 11),
4747 BPF_STMT(BPF_LDX | BPF_MEM, 11),
4748 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4749 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4750 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4751 BPF_STMT(BPF_STX, 12),
4752 BPF_STMT(BPF_LDX | BPF_MEM, 12),
4753 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4754 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4755 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4756 BPF_STMT(BPF_STX, 13),
4757 BPF_STMT(BPF_LDX | BPF_MEM, 13),
4758 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4759 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4760 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4761 BPF_STMT(BPF_STX, 14),
4762 BPF_STMT(BPF_LDX | BPF_MEM, 14),
4763 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4764 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4765 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4766 BPF_STMT(BPF_STX, 15),
4767 BPF_STMT(BPF_LDX | BPF_MEM, 15),
4768 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4769 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
4770 BPF_STMT(BPF_MISC | BPF_TAX, 0),
4771 BPF_STMT(BPF_RET | BPF_A, 0),
4773 CLASSIC | FLAG_NO_DATA,
4777 { /* Mainly checking JIT here. */
4778 "M[]: full STX + full LDX",
4780 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
4781 BPF_STMT(BPF_STX, 0),
4782 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
4783 BPF_STMT(BPF_STX, 1),
4784 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
4785 BPF_STMT(BPF_STX, 2),
4786 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
4787 BPF_STMT(BPF_STX, 3),
4788 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
4789 BPF_STMT(BPF_STX, 4),
4790 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
4791 BPF_STMT(BPF_STX, 5),
4792 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
4793 BPF_STMT(BPF_STX, 6),
4794 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
4795 BPF_STMT(BPF_STX, 7),
4796 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
4797 BPF_STMT(BPF_STX, 8),
4798 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
4799 BPF_STMT(BPF_STX, 9),
4800 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
4801 BPF_STMT(BPF_STX, 10),
4802 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
4803 BPF_STMT(BPF_STX, 11),
4804 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
4805 BPF_STMT(BPF_STX, 12),
4806 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
4807 BPF_STMT(BPF_STX, 13),
4808 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
4809 BPF_STMT(BPF_STX, 14),
4810 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
4811 BPF_STMT(BPF_STX, 15),
4812 BPF_STMT(BPF_LDX | BPF_MEM, 0),
4813 BPF_STMT(BPF_MISC | BPF_TXA, 0),
4814 BPF_STMT(BPF_LDX | BPF_MEM, 1),
4815 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4816 BPF_STMT(BPF_LDX | BPF_MEM, 2),
4817 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4818 BPF_STMT(BPF_LDX | BPF_MEM, 3),
4819 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4820 BPF_STMT(BPF_LDX | BPF_MEM, 4),
4821 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4822 BPF_STMT(BPF_LDX | BPF_MEM, 5),
4823 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4824 BPF_STMT(BPF_LDX | BPF_MEM, 6),
4825 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4826 BPF_STMT(BPF_LDX | BPF_MEM, 7),
4827 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4828 BPF_STMT(BPF_LDX | BPF_MEM, 8),
4829 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4830 BPF_STMT(BPF_LDX | BPF_MEM, 9),
4831 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4832 BPF_STMT(BPF_LDX | BPF_MEM, 10),
4833 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4834 BPF_STMT(BPF_LDX | BPF_MEM, 11),
4835 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4836 BPF_STMT(BPF_LDX | BPF_MEM, 12),
4837 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4838 BPF_STMT(BPF_LDX | BPF_MEM, 13),
4839 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4840 BPF_STMT(BPF_LDX | BPF_MEM, 14),
4841 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4842 BPF_STMT(BPF_LDX | BPF_MEM, 15),
4843 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4844 BPF_STMT(BPF_RET | BPF_A, 0),
4846 CLASSIC | FLAG_NO_DATA,
4848 { { 0, 0x2a5a5e5 } },
4851 "check: SKF_AD_MAX",
4853 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
4854 SKF_AD_OFF + SKF_AD_MAX),
4855 BPF_STMT(BPF_RET | BPF_A, 0),
4857 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4860 .fill_helper = NULL,
4861 .expected_errcode = -EINVAL,
4863 { /* Passes checker but fails during runtime. */
4864 "LD [SKF_AD_OFF-1]",
4866 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
4868 BPF_STMT(BPF_RET | BPF_K, 1),
4875 "load 64-bit immediate",
4877 BPF_LD_IMM64(R1, 0x567800001234LL),
4878 BPF_MOV64_REG(R2, R1),
4879 BPF_MOV64_REG(R3, R2),
4880 BPF_ALU64_IMM(BPF_RSH, R2, 32),
4881 BPF_ALU64_IMM(BPF_LSH, R3, 32),
4882 BPF_ALU64_IMM(BPF_RSH, R3, 32),
4883 BPF_ALU64_IMM(BPF_MOV, R0, 0),
4884 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
4886 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
4888 BPF_LD_IMM64(R0, 0x1ffffffffLL),
4889 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
4896 /* BPF_ALU | BPF_MOV | BPF_X */
4898 "ALU_MOV_X: dst = 2",
4900 BPF_ALU32_IMM(BPF_MOV, R1, 2),
4901 BPF_ALU32_REG(BPF_MOV, R0, R1),
4909 "ALU_MOV_X: dst = 4294967295",
4911 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
4912 BPF_ALU32_REG(BPF_MOV, R0, R1),
4917 { { 0, 4294967295U } },
4920 "ALU64_MOV_X: dst = 2",
4922 BPF_ALU32_IMM(BPF_MOV, R1, 2),
4923 BPF_ALU64_REG(BPF_MOV, R0, R1),
4931 "ALU64_MOV_X: dst = 4294967295",
4933 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
4934 BPF_ALU64_REG(BPF_MOV, R0, R1),
4939 { { 0, 4294967295U } },
4941 /* BPF_ALU | BPF_MOV | BPF_K */
4943 "ALU_MOV_K: dst = 2",
4945 BPF_ALU32_IMM(BPF_MOV, R0, 2),
4953 "ALU_MOV_K: dst = 4294967295",
4955 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
4960 { { 0, 4294967295U } },
4963 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
4965 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4966 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
4967 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
4968 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4969 BPF_MOV32_IMM(R0, 2),
4971 BPF_MOV32_IMM(R0, 1),
4979 "ALU_MOV_K: small negative",
4981 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4989 "ALU_MOV_K: small negative zero extension",
4991 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4992 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5000 "ALU_MOV_K: large negative",
5002 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
5007 { { 0, -123456789 } }
5010 "ALU_MOV_K: large negative zero extension",
5012 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
5013 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5021 "ALU64_MOV_K: dst = 2",
5023 BPF_ALU64_IMM(BPF_MOV, R0, 2),
5031 "ALU64_MOV_K: dst = 2147483647",
5033 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
5038 { { 0, 2147483647 } },
5041 "ALU64_OR_K: dst = 0x0",
5043 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
5044 BPF_LD_IMM64(R3, 0x0),
5045 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
5046 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5047 BPF_MOV32_IMM(R0, 2),
5049 BPF_MOV32_IMM(R0, 1),
5057 "ALU64_MOV_K: dst = -1",
5059 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
5060 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
5061 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
5062 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5063 BPF_MOV32_IMM(R0, 2),
5065 BPF_MOV32_IMM(R0, 1),
5073 "ALU64_MOV_K: small negative",
5075 BPF_ALU64_IMM(BPF_MOV, R0, -123),
5083 "ALU64_MOV_K: small negative sign extension",
5085 BPF_ALU64_IMM(BPF_MOV, R0, -123),
5086 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5091 { { 0, 0xffffffff } }
5094 "ALU64_MOV_K: large negative",
5096 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
5101 { { 0, -123456789 } }
5104 "ALU64_MOV_K: large negative sign extension",
5106 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
5107 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5112 { { 0, 0xffffffff } }
5114 /* BPF_ALU | BPF_ADD | BPF_X */
5116 "ALU_ADD_X: 1 + 2 = 3",
5118 BPF_LD_IMM64(R0, 1),
5119 BPF_ALU32_IMM(BPF_MOV, R1, 2),
5120 BPF_ALU32_REG(BPF_ADD, R0, R1),
5128 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
5130 BPF_LD_IMM64(R0, 1),
5131 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
5132 BPF_ALU32_REG(BPF_ADD, R0, R1),
5137 { { 0, 4294967295U } },
5140 "ALU_ADD_X: 2 + 4294967294 = 0",
5142 BPF_LD_IMM64(R0, 2),
5143 BPF_LD_IMM64(R1, 4294967294U),
5144 BPF_ALU32_REG(BPF_ADD, R0, R1),
5145 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
5146 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5148 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5156 "ALU64_ADD_X: 1 + 2 = 3",
5158 BPF_LD_IMM64(R0, 1),
5159 BPF_ALU32_IMM(BPF_MOV, R1, 2),
5160 BPF_ALU64_REG(BPF_ADD, R0, R1),
5168 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
5170 BPF_LD_IMM64(R0, 1),
5171 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
5172 BPF_ALU64_REG(BPF_ADD, R0, R1),
5177 { { 0, 4294967295U } },
5180 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
5182 BPF_LD_IMM64(R0, 2),
5183 BPF_LD_IMM64(R1, 4294967294U),
5184 BPF_LD_IMM64(R2, 4294967296ULL),
5185 BPF_ALU64_REG(BPF_ADD, R0, R1),
5186 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
5187 BPF_MOV32_IMM(R0, 0),
5189 BPF_MOV32_IMM(R0, 1),
5196 /* BPF_ALU | BPF_ADD | BPF_K */
5198 "ALU_ADD_K: 1 + 2 = 3",
5200 BPF_LD_IMM64(R0, 1),
5201 BPF_ALU32_IMM(BPF_ADD, R0, 2),
5209 "ALU_ADD_K: 3 + 0 = 3",
5211 BPF_LD_IMM64(R0, 3),
5212 BPF_ALU32_IMM(BPF_ADD, R0, 0),
5220 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
5222 BPF_LD_IMM64(R0, 1),
5223 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
5228 { { 0, 4294967295U } },
5231 "ALU_ADD_K: 4294967294 + 2 = 0",
5233 BPF_LD_IMM64(R0, 4294967294U),
5234 BPF_ALU32_IMM(BPF_ADD, R0, 2),
5235 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
5236 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5238 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5246 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
5248 BPF_LD_IMM64(R2, 0x0),
5249 BPF_LD_IMM64(R3, 0x00000000ffffffff),
5250 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
5251 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5252 BPF_MOV32_IMM(R0, 2),
5254 BPF_MOV32_IMM(R0, 1),
5262 "ALU_ADD_K: 0 + 0xffff = 0xffff",
5264 BPF_LD_IMM64(R2, 0x0),
5265 BPF_LD_IMM64(R3, 0xffff),
5266 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
5267 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5268 BPF_MOV32_IMM(R0, 2),
5270 BPF_MOV32_IMM(R0, 1),
5278 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
5280 BPF_LD_IMM64(R2, 0x0),
5281 BPF_LD_IMM64(R3, 0x7fffffff),
5282 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
5283 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5284 BPF_MOV32_IMM(R0, 2),
5286 BPF_MOV32_IMM(R0, 1),
5294 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
5296 BPF_LD_IMM64(R2, 0x0),
5297 BPF_LD_IMM64(R3, 0x80000000),
5298 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
5299 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5300 BPF_MOV32_IMM(R0, 2),
5302 BPF_MOV32_IMM(R0, 1),
5310 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
5312 BPF_LD_IMM64(R2, 0x0),
5313 BPF_LD_IMM64(R3, 0x80008000),
5314 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
5315 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5316 BPF_MOV32_IMM(R0, 2),
5318 BPF_MOV32_IMM(R0, 1),
5326 "ALU64_ADD_K: 1 + 2 = 3",
5328 BPF_LD_IMM64(R0, 1),
5329 BPF_ALU64_IMM(BPF_ADD, R0, 2),
5337 "ALU64_ADD_K: 3 + 0 = 3",
5339 BPF_LD_IMM64(R0, 3),
5340 BPF_ALU64_IMM(BPF_ADD, R0, 0),
5348 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
5350 BPF_LD_IMM64(R0, 1),
5351 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
5356 { { 0, 2147483647 } },
5359 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
5361 BPF_LD_IMM64(R0, 4294967294U),
5362 BPF_LD_IMM64(R1, 4294967296ULL),
5363 BPF_ALU64_IMM(BPF_ADD, R0, 2),
5364 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
5365 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5367 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5375 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
5377 BPF_LD_IMM64(R0, 2147483646),
5378 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
5386 "ALU64_ADD_K: 1 + 0 = 1",
5388 BPF_LD_IMM64(R2, 0x1),
5389 BPF_LD_IMM64(R3, 0x1),
5390 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
5391 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5392 BPF_MOV32_IMM(R0, 2),
5394 BPF_MOV32_IMM(R0, 1),
5402 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
5404 BPF_LD_IMM64(R2, 0x0),
5405 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
5406 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
5407 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5408 BPF_MOV32_IMM(R0, 2),
5410 BPF_MOV32_IMM(R0, 1),
5418 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
5420 BPF_LD_IMM64(R2, 0x0),
5421 BPF_LD_IMM64(R3, 0xffff),
5422 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
5423 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5424 BPF_MOV32_IMM(R0, 2),
5426 BPF_MOV32_IMM(R0, 1),
5434 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
5436 BPF_LD_IMM64(R2, 0x0),
5437 BPF_LD_IMM64(R3, 0x7fffffff),
5438 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
5439 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5440 BPF_MOV32_IMM(R0, 2),
5442 BPF_MOV32_IMM(R0, 1),
5450 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
5452 BPF_LD_IMM64(R2, 0x0),
5453 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
5454 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
5455 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5456 BPF_MOV32_IMM(R0, 2),
5458 BPF_MOV32_IMM(R0, 1),
5466 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
5468 BPF_LD_IMM64(R2, 0x0),
5469 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
5470 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
5471 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5472 BPF_MOV32_IMM(R0, 2),
5474 BPF_MOV32_IMM(R0, 1),
5481 /* BPF_ALU | BPF_SUB | BPF_X */
5483 "ALU_SUB_X: 3 - 1 = 2",
5485 BPF_LD_IMM64(R0, 3),
5486 BPF_ALU32_IMM(BPF_MOV, R1, 1),
5487 BPF_ALU32_REG(BPF_SUB, R0, R1),
5495 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
5497 BPF_LD_IMM64(R0, 4294967295U),
5498 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
5499 BPF_ALU32_REG(BPF_SUB, R0, R1),
5507 "ALU64_SUB_X: 3 - 1 = 2",
5509 BPF_LD_IMM64(R0, 3),
5510 BPF_ALU32_IMM(BPF_MOV, R1, 1),
5511 BPF_ALU64_REG(BPF_SUB, R0, R1),
5519 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
5521 BPF_LD_IMM64(R0, 4294967295U),
5522 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
5523 BPF_ALU64_REG(BPF_SUB, R0, R1),
5530 /* BPF_ALU | BPF_SUB | BPF_K */
5532 "ALU_SUB_K: 3 - 1 = 2",
5534 BPF_LD_IMM64(R0, 3),
5535 BPF_ALU32_IMM(BPF_SUB, R0, 1),
5543 "ALU_SUB_K: 3 - 0 = 3",
5545 BPF_LD_IMM64(R0, 3),
5546 BPF_ALU32_IMM(BPF_SUB, R0, 0),
5554 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
5556 BPF_LD_IMM64(R0, 4294967295U),
5557 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
5565 "ALU64_SUB_K: 3 - 1 = 2",
5567 BPF_LD_IMM64(R0, 3),
5568 BPF_ALU64_IMM(BPF_SUB, R0, 1),
5576 "ALU64_SUB_K: 3 - 0 = 3",
5578 BPF_LD_IMM64(R0, 3),
5579 BPF_ALU64_IMM(BPF_SUB, R0, 0),
5587 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
5589 BPF_LD_IMM64(R0, 4294967294U),
5590 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
5598 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
5600 BPF_LD_IMM64(R0, 2147483646),
5601 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
5608 /* BPF_ALU | BPF_MUL | BPF_X */
5610 "ALU_MUL_X: 2 * 3 = 6",
5612 BPF_LD_IMM64(R0, 2),
5613 BPF_ALU32_IMM(BPF_MOV, R1, 3),
5614 BPF_ALU32_REG(BPF_MUL, R0, R1),
5622 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
5624 BPF_LD_IMM64(R0, 2),
5625 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
5626 BPF_ALU32_REG(BPF_MUL, R0, R1),
5631 { { 0, 0xFFFFFFF0 } },
5634 "ALU_MUL_X: -1 * -1 = 1",
5636 BPF_LD_IMM64(R0, -1),
5637 BPF_ALU32_IMM(BPF_MOV, R1, -1),
5638 BPF_ALU32_REG(BPF_MUL, R0, R1),
5646 "ALU64_MUL_X: 2 * 3 = 6",
5648 BPF_LD_IMM64(R0, 2),
5649 BPF_ALU32_IMM(BPF_MOV, R1, 3),
5650 BPF_ALU64_REG(BPF_MUL, R0, R1),
5658 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
5660 BPF_LD_IMM64(R0, 1),
5661 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
5662 BPF_ALU64_REG(BPF_MUL, R0, R1),
5667 { { 0, 2147483647 } },
5670 "ALU64_MUL_X: 64x64 multiply, low word",
5672 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
5673 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
5674 BPF_ALU64_REG(BPF_MUL, R0, R1),
5679 { { 0, 0xe5618cf0 } }
5682 "ALU64_MUL_X: 64x64 multiply, high word",
5684 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
5685 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
5686 BPF_ALU64_REG(BPF_MUL, R0, R1),
5687 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5692 { { 0, 0x2236d88f } }
5694 /* BPF_ALU | BPF_MUL | BPF_K */
5696 "ALU_MUL_K: 2 * 3 = 6",
5698 BPF_LD_IMM64(R0, 2),
5699 BPF_ALU32_IMM(BPF_MUL, R0, 3),
5707 "ALU_MUL_K: 3 * 1 = 3",
5709 BPF_LD_IMM64(R0, 3),
5710 BPF_ALU32_IMM(BPF_MUL, R0, 1),
5718 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
5720 BPF_LD_IMM64(R0, 2),
5721 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
5726 { { 0, 0xFFFFFFF0 } },
5729 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
5731 BPF_LD_IMM64(R2, 0x1),
5732 BPF_LD_IMM64(R3, 0x00000000ffffffff),
5733 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
5734 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5735 BPF_MOV32_IMM(R0, 2),
5737 BPF_MOV32_IMM(R0, 1),
5745 "ALU64_MUL_K: 2 * 3 = 6",
5747 BPF_LD_IMM64(R0, 2),
5748 BPF_ALU64_IMM(BPF_MUL, R0, 3),
5756 "ALU64_MUL_K: 3 * 1 = 3",
5758 BPF_LD_IMM64(R0, 3),
5759 BPF_ALU64_IMM(BPF_MUL, R0, 1),
5767 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
5769 BPF_LD_IMM64(R0, 1),
5770 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
5775 { { 0, 2147483647 } },
5778 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
5780 BPF_LD_IMM64(R0, 1),
5781 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
5786 { { 0, -2147483647 } },
5789 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
5791 BPF_LD_IMM64(R2, 0x1),
5792 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
5793 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
5794 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5795 BPF_MOV32_IMM(R0, 2),
5797 BPF_MOV32_IMM(R0, 1),
5805 "ALU64_MUL_K: 64x32 multiply, low word",
5807 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5808 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
5813 { { 0, 0xe242d208 } }
5816 "ALU64_MUL_K: 64x32 multiply, high word",
5818 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5819 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
5820 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5825 { { 0, 0xc28f5c28 } }
5827 /* BPF_ALU | BPF_DIV | BPF_X */
5829 "ALU_DIV_X: 6 / 2 = 3",
5831 BPF_LD_IMM64(R0, 6),
5832 BPF_ALU32_IMM(BPF_MOV, R1, 2),
5833 BPF_ALU32_REG(BPF_DIV, R0, R1),
5841 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
5843 BPF_LD_IMM64(R0, 4294967295U),
5844 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
5845 BPF_ALU32_REG(BPF_DIV, R0, R1),
5853 "ALU64_DIV_X: 6 / 2 = 3",
5855 BPF_LD_IMM64(R0, 6),
5856 BPF_ALU32_IMM(BPF_MOV, R1, 2),
5857 BPF_ALU64_REG(BPF_DIV, R0, R1),
5865 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
5867 BPF_LD_IMM64(R0, 2147483647),
5868 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
5869 BPF_ALU64_REG(BPF_DIV, R0, R1),
5877 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
5879 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
5880 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
5881 BPF_LD_IMM64(R3, 0x0000000000000001LL),
5882 BPF_ALU64_REG(BPF_DIV, R2, R4),
5883 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5884 BPF_MOV32_IMM(R0, 2),
5886 BPF_MOV32_IMM(R0, 1),
5893 /* BPF_ALU | BPF_DIV | BPF_K */
5895 "ALU_DIV_K: 6 / 2 = 3",
5897 BPF_LD_IMM64(R0, 6),
5898 BPF_ALU32_IMM(BPF_DIV, R0, 2),
5906 "ALU_DIV_K: 3 / 1 = 3",
5908 BPF_LD_IMM64(R0, 3),
5909 BPF_ALU32_IMM(BPF_DIV, R0, 1),
5917 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
5919 BPF_LD_IMM64(R0, 4294967295U),
5920 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
5928 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
5930 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
5931 BPF_LD_IMM64(R3, 0x1UL),
5932 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
5933 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5934 BPF_MOV32_IMM(R0, 2),
5936 BPF_MOV32_IMM(R0, 1),
5944 "ALU64_DIV_K: 6 / 2 = 3",
5946 BPF_LD_IMM64(R0, 6),
5947 BPF_ALU64_IMM(BPF_DIV, R0, 2),
5955 "ALU64_DIV_K: 3 / 1 = 3",
5957 BPF_LD_IMM64(R0, 3),
5958 BPF_ALU64_IMM(BPF_DIV, R0, 1),
5966 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
5968 BPF_LD_IMM64(R0, 2147483647),
5969 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
5977 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
5979 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
5980 BPF_LD_IMM64(R3, 0x0000000000000001LL),
5981 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
5982 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5983 BPF_MOV32_IMM(R0, 2),
5985 BPF_MOV32_IMM(R0, 1),
5992 /* BPF_ALU | BPF_MOD | BPF_X */
5994 "ALU_MOD_X: 3 % 2 = 1",
5996 BPF_LD_IMM64(R0, 3),
5997 BPF_ALU32_IMM(BPF_MOV, R1, 2),
5998 BPF_ALU32_REG(BPF_MOD, R0, R1),
6006 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
6008 BPF_LD_IMM64(R0, 4294967295U),
6009 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
6010 BPF_ALU32_REG(BPF_MOD, R0, R1),
6018 "ALU64_MOD_X: 3 % 2 = 1",
6020 BPF_LD_IMM64(R0, 3),
6021 BPF_ALU32_IMM(BPF_MOV, R1, 2),
6022 BPF_ALU64_REG(BPF_MOD, R0, R1),
6030 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
6032 BPF_LD_IMM64(R0, 2147483647),
6033 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
6034 BPF_ALU64_REG(BPF_MOD, R0, R1),
6041 /* BPF_ALU | BPF_MOD | BPF_K */
6043 "ALU_MOD_K: 3 % 2 = 1",
6045 BPF_LD_IMM64(R0, 3),
6046 BPF_ALU32_IMM(BPF_MOD, R0, 2),
6054 "ALU_MOD_K: 3 % 1 = 0",
6056 BPF_LD_IMM64(R0, 3),
6057 BPF_ALU32_IMM(BPF_MOD, R0, 1),
6065 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
6067 BPF_LD_IMM64(R0, 4294967295U),
6068 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
6076 "ALU64_MOD_K: 3 % 2 = 1",
6078 BPF_LD_IMM64(R0, 3),
6079 BPF_ALU64_IMM(BPF_MOD, R0, 2),
6087 "ALU64_MOD_K: 3 % 1 = 0",
6089 BPF_LD_IMM64(R0, 3),
6090 BPF_ALU64_IMM(BPF_MOD, R0, 1),
6098 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
6100 BPF_LD_IMM64(R0, 2147483647),
6101 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
6108 /* BPF_ALU | BPF_AND | BPF_X */
6110 "ALU_AND_X: 3 & 2 = 2",
6112 BPF_LD_IMM64(R0, 3),
6113 BPF_ALU32_IMM(BPF_MOV, R1, 2),
6114 BPF_ALU32_REG(BPF_AND, R0, R1),
6122 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
6124 BPF_LD_IMM64(R0, 0xffffffff),
6125 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6126 BPF_ALU32_REG(BPF_AND, R0, R1),
6131 { { 0, 0xffffffff } },
6134 "ALU64_AND_X: 3 & 2 = 2",
6136 BPF_LD_IMM64(R0, 3),
6137 BPF_ALU32_IMM(BPF_MOV, R1, 2),
6138 BPF_ALU64_REG(BPF_AND, R0, R1),
6146 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
6148 BPF_LD_IMM64(R0, 0xffffffff),
6149 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6150 BPF_ALU64_REG(BPF_AND, R0, R1),
6155 { { 0, 0xffffffff } },
6157 /* BPF_ALU | BPF_AND | BPF_K */
6159 "ALU_AND_K: 3 & 2 = 2",
6161 BPF_LD_IMM64(R0, 3),
6162 BPF_ALU32_IMM(BPF_AND, R0, 2),
6170 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
6172 BPF_LD_IMM64(R0, 0xffffffff),
6173 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
6178 { { 0, 0xffffffff } },
6181 "ALU_AND_K: Small immediate",
6183 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
6184 BPF_ALU32_IMM(BPF_AND, R0, 15),
6192 "ALU_AND_K: Large immediate",
6194 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
6195 BPF_ALU32_IMM(BPF_AND, R0, 0xafbfcfdf),
6200 { { 0, 0xa1b2c3d4 } }
6203 "ALU_AND_K: Zero extension",
6205 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6206 BPF_LD_IMM64(R1, 0x0000000080a0c0e0LL),
6207 BPF_ALU32_IMM(BPF_AND, R0, 0xf0f0f0f0),
6208 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6209 BPF_MOV32_IMM(R0, 2),
6211 BPF_MOV32_IMM(R0, 1),
6219 "ALU64_AND_K: 3 & 2 = 2",
6221 BPF_LD_IMM64(R0, 3),
6222 BPF_ALU64_IMM(BPF_AND, R0, 2),
6230 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
6232 BPF_LD_IMM64(R0, 0xffffffff),
6233 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
6238 { { 0, 0xffffffff } },
6241 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000000000000000",
6243 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
6244 BPF_LD_IMM64(R3, 0x0000000000000000LL),
6245 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
6246 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6247 BPF_MOV32_IMM(R0, 2),
6249 BPF_MOV32_IMM(R0, 1),
6257 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffff0000",
6259 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
6260 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
6261 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
6262 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6263 BPF_MOV32_IMM(R0, 2),
6265 BPF_MOV32_IMM(R0, 1),
6273 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
6275 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
6276 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
6277 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
6278 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6279 BPF_MOV32_IMM(R0, 2),
6281 BPF_MOV32_IMM(R0, 1),
6289 "ALU64_AND_K: Sign extension 1",
6291 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6292 BPF_LD_IMM64(R1, 0x00000000090b0d0fLL),
6293 BPF_ALU64_IMM(BPF_AND, R0, 0x0f0f0f0f),
6294 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6295 BPF_MOV32_IMM(R0, 2),
6297 BPF_MOV32_IMM(R0, 1),
6305 "ALU64_AND_K: Sign extension 2",
6307 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6308 BPF_LD_IMM64(R1, 0x0123456780a0c0e0LL),
6309 BPF_ALU64_IMM(BPF_AND, R0, 0xf0f0f0f0),
6310 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6311 BPF_MOV32_IMM(R0, 2),
6313 BPF_MOV32_IMM(R0, 1),
6320 /* BPF_ALU | BPF_OR | BPF_X */
6322 "ALU_OR_X: 1 | 2 = 3",
6324 BPF_LD_IMM64(R0, 1),
6325 BPF_ALU32_IMM(BPF_MOV, R1, 2),
6326 BPF_ALU32_REG(BPF_OR, R0, R1),
6334 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
6336 BPF_LD_IMM64(R0, 0),
6337 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6338 BPF_ALU32_REG(BPF_OR, R0, R1),
6343 { { 0, 0xffffffff } },
6346 "ALU64_OR_X: 1 | 2 = 3",
6348 BPF_LD_IMM64(R0, 1),
6349 BPF_ALU32_IMM(BPF_MOV, R1, 2),
6350 BPF_ALU64_REG(BPF_OR, R0, R1),
6358 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
6360 BPF_LD_IMM64(R0, 0),
6361 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6362 BPF_ALU64_REG(BPF_OR, R0, R1),
6367 { { 0, 0xffffffff } },
6369 /* BPF_ALU | BPF_OR | BPF_K */
6371 "ALU_OR_K: 1 | 2 = 3",
6373 BPF_LD_IMM64(R0, 1),
6374 BPF_ALU32_IMM(BPF_OR, R0, 2),
6382 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
6384 BPF_LD_IMM64(R0, 0),
6385 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
6390 { { 0, 0xffffffff } },
6393 "ALU_OR_K: Small immediate",
6395 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
6396 BPF_ALU32_IMM(BPF_OR, R0, 1),
6401 { { 0, 0x01020305 } }
6404 "ALU_OR_K: Large immediate",
6406 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
6407 BPF_ALU32_IMM(BPF_OR, R0, 0xa0b0c0d0),
6412 { { 0, 0xa1b2c3d4 } }
6415 "ALU_OR_K: Zero extension",
6417 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6418 BPF_LD_IMM64(R1, 0x00000000f9fbfdffLL),
6419 BPF_ALU32_IMM(BPF_OR, R0, 0xf0f0f0f0),
6420 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6421 BPF_MOV32_IMM(R0, 2),
6423 BPF_MOV32_IMM(R0, 1),
6431 "ALU64_OR_K: 1 | 2 = 3",
6433 BPF_LD_IMM64(R0, 1),
6434 BPF_ALU64_IMM(BPF_OR, R0, 2),
6442 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
6444 BPF_LD_IMM64(R0, 0),
6445 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
6450 { { 0, 0xffffffff } },
6453 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffffffff0000",
6455 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
6456 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
6457 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
6458 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6459 BPF_MOV32_IMM(R0, 2),
6461 BPF_MOV32_IMM(R0, 1),
6469 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
6471 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
6472 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
6473 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
6474 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6475 BPF_MOV32_IMM(R0, 2),
6477 BPF_MOV32_IMM(R0, 1),
6485 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
6487 BPF_LD_IMM64(R2, 0x0000000000000000LL),
6488 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
6489 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
6490 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6491 BPF_MOV32_IMM(R0, 2),
6493 BPF_MOV32_IMM(R0, 1),
6501 "ALU64_OR_K: Sign extension 1",
6503 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6504 BPF_LD_IMM64(R1, 0x012345678fafcfefLL),
6505 BPF_ALU64_IMM(BPF_OR, R0, 0x0f0f0f0f),
6506 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6507 BPF_MOV32_IMM(R0, 2),
6509 BPF_MOV32_IMM(R0, 1),
6517 "ALU64_OR_K: Sign extension 2",
6519 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6520 BPF_LD_IMM64(R1, 0xfffffffff9fbfdffLL),
6521 BPF_ALU64_IMM(BPF_OR, R0, 0xf0f0f0f0),
6522 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6523 BPF_MOV32_IMM(R0, 2),
6525 BPF_MOV32_IMM(R0, 1),
6532 /* BPF_ALU | BPF_XOR | BPF_X */
6534 "ALU_XOR_X: 5 ^ 6 = 3",
6536 BPF_LD_IMM64(R0, 5),
6537 BPF_ALU32_IMM(BPF_MOV, R1, 6),
6538 BPF_ALU32_REG(BPF_XOR, R0, R1),
6546 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
6548 BPF_LD_IMM64(R0, 1),
6549 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6550 BPF_ALU32_REG(BPF_XOR, R0, R1),
6555 { { 0, 0xfffffffe } },
6558 "ALU64_XOR_X: 5 ^ 6 = 3",
6560 BPF_LD_IMM64(R0, 5),
6561 BPF_ALU32_IMM(BPF_MOV, R1, 6),
6562 BPF_ALU64_REG(BPF_XOR, R0, R1),
6570 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
6572 BPF_LD_IMM64(R0, 1),
6573 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6574 BPF_ALU64_REG(BPF_XOR, R0, R1),
6579 { { 0, 0xfffffffe } },
6581 /* BPF_ALU | BPF_XOR | BPF_K */
6583 "ALU_XOR_K: 5 ^ 6 = 3",
6585 BPF_LD_IMM64(R0, 5),
6586 BPF_ALU32_IMM(BPF_XOR, R0, 6),
6594 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
6596 BPF_LD_IMM64(R0, 1),
6597 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
6602 { { 0, 0xfffffffe } },
6605 "ALU_XOR_K: Small immediate",
6607 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
6608 BPF_ALU32_IMM(BPF_XOR, R0, 15),
6613 { { 0, 0x0102030b } }
6616 "ALU_XOR_K: Large immediate",
6618 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
6619 BPF_ALU32_IMM(BPF_XOR, R0, 0xafbfcfdf),
6624 { { 0, 0x5e4d3c2b } }
6627 "ALU_XOR_K: Zero extension",
6629 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6630 BPF_LD_IMM64(R1, 0x00000000795b3d1fLL),
6631 BPF_ALU32_IMM(BPF_XOR, R0, 0xf0f0f0f0),
6632 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6633 BPF_MOV32_IMM(R0, 2),
6635 BPF_MOV32_IMM(R0, 1),
6643 "ALU64_XOR_K: 5 ^ 6 = 3",
6645 BPF_LD_IMM64(R0, 5),
6646 BPF_ALU64_IMM(BPF_XOR, R0, 6),
6654 "ALU64_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
6656 BPF_LD_IMM64(R0, 1),
6657 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
6662 { { 0, 0xfffffffe } },
6665 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
6667 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
6668 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
6669 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
6670 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6671 BPF_MOV32_IMM(R0, 2),
6673 BPF_MOV32_IMM(R0, 1),
6681 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
6683 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
6684 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
6685 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
6686 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6687 BPF_MOV32_IMM(R0, 2),
6689 BPF_MOV32_IMM(R0, 1),
6697 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
6699 BPF_LD_IMM64(R2, 0x0000000000000000LL),
6700 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
6701 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
6702 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
6703 BPF_MOV32_IMM(R0, 2),
6705 BPF_MOV32_IMM(R0, 1),
6713 "ALU64_XOR_K: Sign extension 1",
6715 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6716 BPF_LD_IMM64(R1, 0x0123456786a4c2e0LL),
6717 BPF_ALU64_IMM(BPF_XOR, R0, 0x0f0f0f0f),
6718 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6719 BPF_MOV32_IMM(R0, 2),
6721 BPF_MOV32_IMM(R0, 1),
6729 "ALU64_XOR_K: Sign extension 2",
6731 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6732 BPF_LD_IMM64(R1, 0xfedcba98795b3d1fLL),
6733 BPF_ALU64_IMM(BPF_XOR, R0, 0xf0f0f0f0),
6734 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
6735 BPF_MOV32_IMM(R0, 2),
6737 BPF_MOV32_IMM(R0, 1),
6744 /* BPF_ALU | BPF_LSH | BPF_X */
6746 "ALU_LSH_X: 1 << 1 = 2",
6748 BPF_LD_IMM64(R0, 1),
6749 BPF_ALU32_IMM(BPF_MOV, R1, 1),
6750 BPF_ALU32_REG(BPF_LSH, R0, R1),
6758 "ALU_LSH_X: 1 << 31 = 0x80000000",
6760 BPF_LD_IMM64(R0, 1),
6761 BPF_ALU32_IMM(BPF_MOV, R1, 31),
6762 BPF_ALU32_REG(BPF_LSH, R0, R1),
6767 { { 0, 0x80000000 } },
6770 "ALU_LSH_X: 0x12345678 << 12 = 0x45678000",
6772 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
6773 BPF_ALU32_IMM(BPF_MOV, R1, 12),
6774 BPF_ALU32_REG(BPF_LSH, R0, R1),
6779 { { 0, 0x45678000 } }
6782 "ALU64_LSH_X: 1 << 1 = 2",
6784 BPF_LD_IMM64(R0, 1),
6785 BPF_ALU32_IMM(BPF_MOV, R1, 1),
6786 BPF_ALU64_REG(BPF_LSH, R0, R1),
6794 "ALU64_LSH_X: 1 << 31 = 0x80000000",
6796 BPF_LD_IMM64(R0, 1),
6797 BPF_ALU32_IMM(BPF_MOV, R1, 31),
6798 BPF_ALU64_REG(BPF_LSH, R0, R1),
6803 { { 0, 0x80000000 } },
6806 "ALU64_LSH_X: Shift < 32, low word",
6808 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6809 BPF_ALU32_IMM(BPF_MOV, R1, 12),
6810 BPF_ALU64_REG(BPF_LSH, R0, R1),
6815 { { 0, 0xbcdef000 } }
6818 "ALU64_LSH_X: Shift < 32, high word",
6820 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6821 BPF_ALU32_IMM(BPF_MOV, R1, 12),
6822 BPF_ALU64_REG(BPF_LSH, R0, R1),
6823 BPF_ALU64_IMM(BPF_RSH, R0, 32),
6828 { { 0, 0x3456789a } }
6831 "ALU64_LSH_X: Shift > 32, low word",
6833 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6834 BPF_ALU32_IMM(BPF_MOV, R1, 36),
6835 BPF_ALU64_REG(BPF_LSH, R0, R1),
6843 "ALU64_LSH_X: Shift > 32, high word",
6845 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6846 BPF_ALU32_IMM(BPF_MOV, R1, 36),
6847 BPF_ALU64_REG(BPF_LSH, R0, R1),
6848 BPF_ALU64_IMM(BPF_RSH, R0, 32),
6853 { { 0, 0x9abcdef0 } }
6856 "ALU64_LSH_X: Shift == 32, low word",
6858 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6859 BPF_ALU32_IMM(BPF_MOV, R1, 32),
6860 BPF_ALU64_REG(BPF_LSH, R0, R1),
6868 "ALU64_LSH_X: Shift == 32, high word",
6870 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6871 BPF_ALU32_IMM(BPF_MOV, R1, 32),
6872 BPF_ALU64_REG(BPF_LSH, R0, R1),
6873 BPF_ALU64_IMM(BPF_RSH, R0, 32),
6878 { { 0, 0x89abcdef } }
6881 "ALU64_LSH_X: Zero shift, low word",
6883 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6884 BPF_ALU32_IMM(BPF_MOV, R1, 0),
6885 BPF_ALU64_REG(BPF_LSH, R0, R1),
6890 { { 0, 0x89abcdef } }
6893 "ALU64_LSH_X: Zero shift, high word",
6895 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6896 BPF_ALU32_IMM(BPF_MOV, R1, 0),
6897 BPF_ALU64_REG(BPF_LSH, R0, R1),
6898 BPF_ALU64_IMM(BPF_RSH, R0, 32),
6903 { { 0, 0x01234567 } }
6905 /* BPF_ALU | BPF_LSH | BPF_K */
6907 "ALU_LSH_K: 1 << 1 = 2",
6909 BPF_LD_IMM64(R0, 1),
6910 BPF_ALU32_IMM(BPF_LSH, R0, 1),
6918 "ALU_LSH_K: 1 << 31 = 0x80000000",
6920 BPF_LD_IMM64(R0, 1),
6921 BPF_ALU32_IMM(BPF_LSH, R0, 31),
6926 { { 0, 0x80000000 } },
6929 "ALU_LSH_K: 0x12345678 << 12 = 0x45678000",
6931 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
6932 BPF_ALU32_IMM(BPF_LSH, R0, 12),
6937 { { 0, 0x45678000 } }
6940 "ALU_LSH_K: 0x12345678 << 0 = 0x12345678",
6942 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
6943 BPF_ALU32_IMM(BPF_LSH, R0, 0),
6948 { { 0, 0x12345678 } }
6951 "ALU64_LSH_K: 1 << 1 = 2",
6953 BPF_LD_IMM64(R0, 1),
6954 BPF_ALU64_IMM(BPF_LSH, R0, 1),
6962 "ALU64_LSH_K: 1 << 31 = 0x80000000",
6964 BPF_LD_IMM64(R0, 1),
6965 BPF_ALU64_IMM(BPF_LSH, R0, 31),
6970 { { 0, 0x80000000 } },
6973 "ALU64_LSH_K: Shift < 32, low word",
6975 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6976 BPF_ALU64_IMM(BPF_LSH, R0, 12),
6981 { { 0, 0xbcdef000 } }
6984 "ALU64_LSH_K: Shift < 32, high word",
6986 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6987 BPF_ALU64_IMM(BPF_LSH, R0, 12),
6988 BPF_ALU64_IMM(BPF_RSH, R0, 32),
6993 { { 0, 0x3456789a } }
6996 "ALU64_LSH_K: Shift > 32, low word",
6998 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
6999 BPF_ALU64_IMM(BPF_LSH, R0, 36),
7007 "ALU64_LSH_K: Shift > 32, high word",
7009 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7010 BPF_ALU64_IMM(BPF_LSH, R0, 36),
7011 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7016 { { 0, 0x9abcdef0 } }
7019 "ALU64_LSH_K: Shift == 32, low word",
7021 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7022 BPF_ALU64_IMM(BPF_LSH, R0, 32),
7030 "ALU64_LSH_K: Shift == 32, high word",
7032 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7033 BPF_ALU64_IMM(BPF_LSH, R0, 32),
7034 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7039 { { 0, 0x89abcdef } }
7042 "ALU64_LSH_K: Zero shift",
7044 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7045 BPF_ALU64_IMM(BPF_LSH, R0, 0),
7050 { { 0, 0x89abcdef } }
7052 /* BPF_ALU | BPF_RSH | BPF_X */
7054 "ALU_RSH_X: 2 >> 1 = 1",
7056 BPF_LD_IMM64(R0, 2),
7057 BPF_ALU32_IMM(BPF_MOV, R1, 1),
7058 BPF_ALU32_REG(BPF_RSH, R0, R1),
7066 "ALU_RSH_X: 0x80000000 >> 31 = 1",
7068 BPF_LD_IMM64(R0, 0x80000000),
7069 BPF_ALU32_IMM(BPF_MOV, R1, 31),
7070 BPF_ALU32_REG(BPF_RSH, R0, R1),
7078 "ALU_RSH_X: 0x12345678 >> 20 = 0x123",
7080 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
7081 BPF_ALU32_IMM(BPF_MOV, R1, 20),
7082 BPF_ALU32_REG(BPF_RSH, R0, R1),
7090 "ALU64_RSH_X: 2 >> 1 = 1",
7092 BPF_LD_IMM64(R0, 2),
7093 BPF_ALU32_IMM(BPF_MOV, R1, 1),
7094 BPF_ALU64_REG(BPF_RSH, R0, R1),
7102 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
7104 BPF_LD_IMM64(R0, 0x80000000),
7105 BPF_ALU32_IMM(BPF_MOV, R1, 31),
7106 BPF_ALU64_REG(BPF_RSH, R0, R1),
7114 "ALU64_RSH_X: Shift < 32, low word",
7116 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7117 BPF_ALU32_IMM(BPF_MOV, R1, 12),
7118 BPF_ALU64_REG(BPF_RSH, R0, R1),
7123 { { 0, 0x56789abc } }
7126 "ALU64_RSH_X: Shift < 32, high word",
7128 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7129 BPF_ALU32_IMM(BPF_MOV, R1, 12),
7130 BPF_ALU64_REG(BPF_RSH, R0, R1),
7131 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7136 { { 0, 0x00081234 } }
7139 "ALU64_RSH_X: Shift > 32, low word",
7141 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7142 BPF_ALU32_IMM(BPF_MOV, R1, 36),
7143 BPF_ALU64_REG(BPF_RSH, R0, R1),
7148 { { 0, 0x08123456 } }
7151 "ALU64_RSH_X: Shift > 32, high word",
7153 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7154 BPF_ALU32_IMM(BPF_MOV, R1, 36),
7155 BPF_ALU64_REG(BPF_RSH, R0, R1),
7156 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7164 "ALU64_RSH_X: Shift == 32, low word",
7166 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7167 BPF_ALU32_IMM(BPF_MOV, R1, 32),
7168 BPF_ALU64_REG(BPF_RSH, R0, R1),
7173 { { 0, 0x81234567 } }
7176 "ALU64_RSH_X: Shift == 32, high word",
7178 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7179 BPF_ALU32_IMM(BPF_MOV, R1, 32),
7180 BPF_ALU64_REG(BPF_RSH, R0, R1),
7181 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7189 "ALU64_RSH_X: Zero shift, low word",
7191 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7192 BPF_ALU32_IMM(BPF_MOV, R1, 0),
7193 BPF_ALU64_REG(BPF_RSH, R0, R1),
7198 { { 0, 0x89abcdef } }
7201 "ALU64_RSH_X: Zero shift, high word",
7203 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7204 BPF_ALU32_IMM(BPF_MOV, R1, 0),
7205 BPF_ALU64_REG(BPF_RSH, R0, R1),
7206 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7211 { { 0, 0x81234567 } }
7213 /* BPF_ALU | BPF_RSH | BPF_K */
7215 "ALU_RSH_K: 2 >> 1 = 1",
7217 BPF_LD_IMM64(R0, 2),
7218 BPF_ALU32_IMM(BPF_RSH, R0, 1),
7226 "ALU_RSH_K: 0x80000000 >> 31 = 1",
7228 BPF_LD_IMM64(R0, 0x80000000),
7229 BPF_ALU32_IMM(BPF_RSH, R0, 31),
7237 "ALU_RSH_K: 0x12345678 >> 20 = 0x123",
7239 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
7240 BPF_ALU32_IMM(BPF_RSH, R0, 20),
7248 "ALU_RSH_K: 0x12345678 >> 0 = 0x12345678",
7250 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
7251 BPF_ALU32_IMM(BPF_RSH, R0, 0),
7256 { { 0, 0x12345678 } }
7259 "ALU64_RSH_K: 2 >> 1 = 1",
7261 BPF_LD_IMM64(R0, 2),
7262 BPF_ALU64_IMM(BPF_RSH, R0, 1),
7270 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
7272 BPF_LD_IMM64(R0, 0x80000000),
7273 BPF_ALU64_IMM(BPF_RSH, R0, 31),
7281 "ALU64_RSH_K: Shift < 32, low word",
7283 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7284 BPF_ALU64_IMM(BPF_RSH, R0, 12),
7289 { { 0, 0x56789abc } }
7292 "ALU64_RSH_K: Shift < 32, high word",
7294 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7295 BPF_ALU64_IMM(BPF_RSH, R0, 12),
7296 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7301 { { 0, 0x00081234 } }
7304 "ALU64_RSH_K: Shift > 32, low word",
7306 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7307 BPF_ALU64_IMM(BPF_RSH, R0, 36),
7312 { { 0, 0x08123456 } }
7315 "ALU64_RSH_K: Shift > 32, high word",
7317 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7318 BPF_ALU64_IMM(BPF_RSH, R0, 36),
7319 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7327 "ALU64_RSH_K: Shift == 32, low word",
7329 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7330 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7335 { { 0, 0x81234567 } }
7338 "ALU64_RSH_K: Shift == 32, high word",
7340 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7341 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7342 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7350 "ALU64_RSH_K: Zero shift",
7352 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7353 BPF_ALU64_IMM(BPF_RSH, R0, 0),
7358 { { 0, 0x89abcdef } }
7360 /* BPF_ALU | BPF_ARSH | BPF_X */
7362 "ALU32_ARSH_X: -1234 >> 7 = -10",
7364 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
7365 BPF_ALU32_IMM(BPF_MOV, R1, 7),
7366 BPF_ALU32_REG(BPF_ARSH, R0, R1),
7374 "ALU64_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
7376 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
7377 BPF_ALU32_IMM(BPF_MOV, R1, 40),
7378 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7383 { { 0, 0xffff00ff } },
7386 "ALU64_ARSH_X: Shift < 32, low word",
7388 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7389 BPF_ALU32_IMM(BPF_MOV, R1, 12),
7390 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7395 { { 0, 0x56789abc } }
7398 "ALU64_ARSH_X: Shift < 32, high word",
7400 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7401 BPF_ALU32_IMM(BPF_MOV, R1, 12),
7402 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7403 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7408 { { 0, 0xfff81234 } }
7411 "ALU64_ARSH_X: Shift > 32, low word",
7413 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7414 BPF_ALU32_IMM(BPF_MOV, R1, 36),
7415 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7420 { { 0, 0xf8123456 } }
7423 "ALU64_ARSH_X: Shift > 32, high word",
7425 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7426 BPF_ALU32_IMM(BPF_MOV, R1, 36),
7427 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7428 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7436 "ALU64_ARSH_X: Shift == 32, low word",
7438 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7439 BPF_ALU32_IMM(BPF_MOV, R1, 32),
7440 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7445 { { 0, 0x81234567 } }
7448 "ALU64_ARSH_X: Shift == 32, high word",
7450 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7451 BPF_ALU32_IMM(BPF_MOV, R1, 32),
7452 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7453 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7461 "ALU64_ARSH_X: Zero shift, low word",
7463 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7464 BPF_ALU32_IMM(BPF_MOV, R1, 0),
7465 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7470 { { 0, 0x89abcdef } }
7473 "ALU64_ARSH_X: Zero shift, high word",
7475 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7476 BPF_ALU32_IMM(BPF_MOV, R1, 0),
7477 BPF_ALU64_REG(BPF_ARSH, R0, R1),
7478 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7483 { { 0, 0x81234567 } }
7485 /* BPF_ALU | BPF_ARSH | BPF_K */
7487 "ALU32_ARSH_K: -1234 >> 7 = -10",
7489 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
7490 BPF_ALU32_IMM(BPF_ARSH, R0, 7),
7498 "ALU32_ARSH_K: -1234 >> 0 = -1234",
7500 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
7501 BPF_ALU32_IMM(BPF_ARSH, R0, 0),
7509 "ALU64_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
7511 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
7512 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
7517 { { 0, 0xffff00ff } },
7520 "ALU64_ARSH_K: Shift < 32, low word",
7522 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7523 BPF_ALU64_IMM(BPF_RSH, R0, 12),
7528 { { 0, 0x56789abc } }
7531 "ALU64_ARSH_K: Shift < 32, high word",
7533 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7534 BPF_ALU64_IMM(BPF_ARSH, R0, 12),
7535 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7540 { { 0, 0xfff81234 } }
7543 "ALU64_ARSH_K: Shift > 32, low word",
7545 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7546 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
7551 { { 0, 0xf8123456 } }
7554 "ALU64_ARSH_K: Shift > 32, high word",
7556 BPF_LD_IMM64(R0, 0xf123456789abcdefLL),
7557 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
7558 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7566 "ALU64_ARSH_K: Shift == 32, low word",
7568 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7569 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
7574 { { 0, 0x81234567 } }
7577 "ALU64_ARSH_K: Shift == 32, high word",
7579 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7580 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
7581 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7589 "ALU64_ARSH_K: Zero shift",
7591 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
7592 BPF_ALU64_IMM(BPF_ARSH, R0, 0),
7597 { { 0, 0x89abcdef } }
7599 /* BPF_ALU | BPF_NEG */
7601 "ALU_NEG: -(3) = -3",
7603 BPF_ALU32_IMM(BPF_MOV, R0, 3),
7604 BPF_ALU32_IMM(BPF_NEG, R0, 0),
7612 "ALU_NEG: -(-3) = 3",
7614 BPF_ALU32_IMM(BPF_MOV, R0, -3),
7615 BPF_ALU32_IMM(BPF_NEG, R0, 0),
7623 "ALU64_NEG: -(3) = -3",
7625 BPF_LD_IMM64(R0, 3),
7626 BPF_ALU64_IMM(BPF_NEG, R0, 0),
7634 "ALU64_NEG: -(-3) = 3",
7636 BPF_LD_IMM64(R0, -3),
7637 BPF_ALU64_IMM(BPF_NEG, R0, 0),
7644 /* BPF_ALU | BPF_END | BPF_FROM_BE */
7646 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
7648 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7649 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
7654 { { 0, cpu_to_be16(0xcdef) } },
7657 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
7659 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7660 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
7661 BPF_ALU64_REG(BPF_MOV, R1, R0),
7662 BPF_ALU64_IMM(BPF_RSH, R1, 32),
7663 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
7668 { { 0, cpu_to_be32(0x89abcdef) } },
7671 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
7673 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7674 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
7679 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
7682 "ALU_END_FROM_BE 64: 0x0123456789abcdef >> 32 -> 0x01234567",
7684 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7685 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
7686 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7691 { { 0, (u32) (cpu_to_be64(0x0123456789abcdefLL) >> 32) } },
7693 /* BPF_ALU | BPF_END | BPF_FROM_BE, reversed */
7695 "ALU_END_FROM_BE 16: 0xfedcba9876543210 -> 0x3210",
7697 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7698 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
7703 { { 0, cpu_to_be16(0x3210) } },
7706 "ALU_END_FROM_BE 32: 0xfedcba9876543210 -> 0x76543210",
7708 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7709 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
7710 BPF_ALU64_REG(BPF_MOV, R1, R0),
7711 BPF_ALU64_IMM(BPF_RSH, R1, 32),
7712 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
7717 { { 0, cpu_to_be32(0x76543210) } },
7720 "ALU_END_FROM_BE 64: 0xfedcba9876543210 -> 0x76543210",
7722 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7723 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
7728 { { 0, (u32) cpu_to_be64(0xfedcba9876543210ULL) } },
7731 "ALU_END_FROM_BE 64: 0xfedcba9876543210 >> 32 -> 0xfedcba98",
7733 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7734 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
7735 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7740 { { 0, (u32) (cpu_to_be64(0xfedcba9876543210ULL) >> 32) } },
7742 /* BPF_ALU | BPF_END | BPF_FROM_LE */
7744 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
7746 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7747 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
7752 { { 0, cpu_to_le16(0xcdef) } },
7755 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
7757 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7758 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
7759 BPF_ALU64_REG(BPF_MOV, R1, R0),
7760 BPF_ALU64_IMM(BPF_RSH, R1, 32),
7761 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
7766 { { 0, cpu_to_le32(0x89abcdef) } },
7769 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
7771 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7772 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
7777 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
7780 "ALU_END_FROM_LE 64: 0x0123456789abcdef >> 32 -> 0xefcdab89",
7782 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
7783 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
7784 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7789 { { 0, (u32) (cpu_to_le64(0x0123456789abcdefLL) >> 32) } },
7791 /* BPF_ALU | BPF_END | BPF_FROM_LE, reversed */
7793 "ALU_END_FROM_LE 16: 0xfedcba9876543210 -> 0x1032",
7795 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7796 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
7801 { { 0, cpu_to_le16(0x3210) } },
7804 "ALU_END_FROM_LE 32: 0xfedcba9876543210 -> 0x10325476",
7806 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7807 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
7808 BPF_ALU64_REG(BPF_MOV, R1, R0),
7809 BPF_ALU64_IMM(BPF_RSH, R1, 32),
7810 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
7815 { { 0, cpu_to_le32(0x76543210) } },
7818 "ALU_END_FROM_LE 64: 0xfedcba9876543210 -> 0x10325476",
7820 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7821 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
7826 { { 0, (u32) cpu_to_le64(0xfedcba9876543210ULL) } },
7829 "ALU_END_FROM_LE 64: 0xfedcba9876543210 >> 32 -> 0x98badcfe",
7831 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
7832 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
7833 BPF_ALU64_IMM(BPF_RSH, R0, 32),
7838 { { 0, (u32) (cpu_to_le64(0xfedcba9876543210ULL) >> 32) } },
7840 /* BPF_LDX_MEM B/H/W/DW */
7842 "BPF_LDX_MEM | BPF_B, base",
7844 BPF_LD_IMM64(R1, 0x0102030405060708ULL),
7845 BPF_LD_IMM64(R2, 0x0000000000000008ULL),
7846 BPF_STX_MEM(BPF_DW, R10, R1, -8),
7848 BPF_LDX_MEM(BPF_B, R0, R10, -1),
7850 BPF_LDX_MEM(BPF_B, R0, R10, -8),
7852 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
7853 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7862 "BPF_LDX_MEM | BPF_B, MSB set",
7864 BPF_LD_IMM64(R1, 0x8182838485868788ULL),
7865 BPF_LD_IMM64(R2, 0x0000000000000088ULL),
7866 BPF_STX_MEM(BPF_DW, R10, R1, -8),
7868 BPF_LDX_MEM(BPF_B, R0, R10, -1),
7870 BPF_LDX_MEM(BPF_B, R0, R10, -8),
7872 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
7873 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7882 "BPF_LDX_MEM | BPF_B, negative offset",
7884 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
7885 BPF_LD_IMM64(R3, 0x0000000000000088ULL),
7886 BPF_ALU64_IMM(BPF_ADD, R1, 512),
7887 BPF_STX_MEM(BPF_B, R1, R2, -256),
7888 BPF_LDX_MEM(BPF_B, R0, R1, -256),
7889 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
7890 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7893 INTERNAL | FLAG_LARGE_MEM,
7899 "BPF_LDX_MEM | BPF_B, small positive offset",
7901 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
7902 BPF_LD_IMM64(R3, 0x0000000000000088ULL),
7903 BPF_STX_MEM(BPF_B, R1, R2, 256),
7904 BPF_LDX_MEM(BPF_B, R0, R1, 256),
7905 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
7906 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7909 INTERNAL | FLAG_LARGE_MEM,
7915 "BPF_LDX_MEM | BPF_B, large positive offset",
7917 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
7918 BPF_LD_IMM64(R3, 0x0000000000000088ULL),
7919 BPF_STX_MEM(BPF_B, R1, R2, 4096),
7920 BPF_LDX_MEM(BPF_B, R0, R1, 4096),
7921 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
7922 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7925 INTERNAL | FLAG_LARGE_MEM,
7927 { { 4096 + 16, 0 } },
7931 "BPF_LDX_MEM | BPF_H, base",
7933 BPF_LD_IMM64(R1, 0x0102030405060708ULL),
7934 BPF_LD_IMM64(R2, 0x0000000000000708ULL),
7935 BPF_STX_MEM(BPF_DW, R10, R1, -8),
7937 BPF_LDX_MEM(BPF_H, R0, R10, -2),
7939 BPF_LDX_MEM(BPF_H, R0, R10, -8),
7941 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
7942 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7951 "BPF_LDX_MEM | BPF_H, MSB set",
7953 BPF_LD_IMM64(R1, 0x8182838485868788ULL),
7954 BPF_LD_IMM64(R2, 0x0000000000008788ULL),
7955 BPF_STX_MEM(BPF_DW, R10, R1, -8),
7957 BPF_LDX_MEM(BPF_H, R0, R10, -2),
7959 BPF_LDX_MEM(BPF_H, R0, R10, -8),
7961 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
7962 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7971 "BPF_LDX_MEM | BPF_H, negative offset",
7973 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
7974 BPF_LD_IMM64(R3, 0x0000000000008788ULL),
7975 BPF_ALU64_IMM(BPF_ADD, R1, 512),
7976 BPF_STX_MEM(BPF_H, R1, R2, -256),
7977 BPF_LDX_MEM(BPF_H, R0, R1, -256),
7978 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
7979 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7982 INTERNAL | FLAG_LARGE_MEM,
7988 "BPF_LDX_MEM | BPF_H, small positive offset",
7990 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
7991 BPF_LD_IMM64(R3, 0x0000000000008788ULL),
7992 BPF_STX_MEM(BPF_H, R1, R2, 256),
7993 BPF_LDX_MEM(BPF_H, R0, R1, 256),
7994 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
7995 BPF_ALU64_IMM(BPF_MOV, R0, 0),
7998 INTERNAL | FLAG_LARGE_MEM,
8004 "BPF_LDX_MEM | BPF_H, large positive offset",
8006 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8007 BPF_LD_IMM64(R3, 0x0000000000008788ULL),
8008 BPF_STX_MEM(BPF_H, R1, R2, 8192),
8009 BPF_LDX_MEM(BPF_H, R0, R1, 8192),
8010 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8011 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8014 INTERNAL | FLAG_LARGE_MEM,
8016 { { 8192 + 16, 0 } },
8020 "BPF_LDX_MEM | BPF_H, unaligned positive offset",
8022 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8023 BPF_LD_IMM64(R3, 0x0000000000008788ULL),
8024 BPF_STX_MEM(BPF_H, R1, R2, 13),
8025 BPF_LDX_MEM(BPF_H, R0, R1, 13),
8026 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8027 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8030 INTERNAL | FLAG_LARGE_MEM,
8036 "BPF_LDX_MEM | BPF_W, base",
8038 BPF_LD_IMM64(R1, 0x0102030405060708ULL),
8039 BPF_LD_IMM64(R2, 0x0000000005060708ULL),
8040 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8042 BPF_LDX_MEM(BPF_W, R0, R10, -4),
8044 BPF_LDX_MEM(BPF_W, R0, R10, -8),
8046 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8047 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8056 "BPF_LDX_MEM | BPF_W, MSB set",
8058 BPF_LD_IMM64(R1, 0x8182838485868788ULL),
8059 BPF_LD_IMM64(R2, 0x0000000085868788ULL),
8060 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8062 BPF_LDX_MEM(BPF_W, R0, R10, -4),
8064 BPF_LDX_MEM(BPF_W, R0, R10, -8),
8066 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8067 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8076 "BPF_LDX_MEM | BPF_W, negative offset",
8078 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8079 BPF_LD_IMM64(R3, 0x0000000085868788ULL),
8080 BPF_ALU64_IMM(BPF_ADD, R1, 512),
8081 BPF_STX_MEM(BPF_W, R1, R2, -256),
8082 BPF_LDX_MEM(BPF_W, R0, R1, -256),
8083 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8084 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8087 INTERNAL | FLAG_LARGE_MEM,
8093 "BPF_LDX_MEM | BPF_W, small positive offset",
8095 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8096 BPF_LD_IMM64(R3, 0x0000000085868788ULL),
8097 BPF_STX_MEM(BPF_W, R1, R2, 256),
8098 BPF_LDX_MEM(BPF_W, R0, R1, 256),
8099 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8100 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8103 INTERNAL | FLAG_LARGE_MEM,
8109 "BPF_LDX_MEM | BPF_W, large positive offset",
8111 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8112 BPF_LD_IMM64(R3, 0x0000000085868788ULL),
8113 BPF_STX_MEM(BPF_W, R1, R2, 16384),
8114 BPF_LDX_MEM(BPF_W, R0, R1, 16384),
8115 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8116 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8119 INTERNAL | FLAG_LARGE_MEM,
8121 { { 16384 + 16, 0 } },
8125 "BPF_LDX_MEM | BPF_W, unaligned positive offset",
8127 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8128 BPF_LD_IMM64(R3, 0x0000000085868788ULL),
8129 BPF_STX_MEM(BPF_W, R1, R2, 13),
8130 BPF_LDX_MEM(BPF_W, R0, R1, 13),
8131 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8132 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8135 INTERNAL | FLAG_LARGE_MEM,
8141 "BPF_LDX_MEM | BPF_DW, base",
8143 BPF_LD_IMM64(R1, 0x0102030405060708ULL),
8144 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8145 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8146 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
8147 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8156 "BPF_LDX_MEM | BPF_DW, MSB set",
8158 BPF_LD_IMM64(R1, 0x8182838485868788ULL),
8159 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8160 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8161 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
8162 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8171 "BPF_LDX_MEM | BPF_DW, negative offset",
8173 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8174 BPF_ALU64_IMM(BPF_ADD, R1, 512),
8175 BPF_STX_MEM(BPF_DW, R1, R2, -256),
8176 BPF_LDX_MEM(BPF_DW, R0, R1, -256),
8177 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8178 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8181 INTERNAL | FLAG_LARGE_MEM,
8187 "BPF_LDX_MEM | BPF_DW, small positive offset",
8189 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8190 BPF_STX_MEM(BPF_DW, R1, R2, 256),
8191 BPF_LDX_MEM(BPF_DW, R0, R1, 256),
8192 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8193 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8196 INTERNAL | FLAG_LARGE_MEM,
8202 "BPF_LDX_MEM | BPF_DW, large positive offset",
8204 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8205 BPF_STX_MEM(BPF_DW, R1, R2, 32760),
8206 BPF_LDX_MEM(BPF_DW, R0, R1, 32760),
8207 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8208 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8211 INTERNAL | FLAG_LARGE_MEM,
8217 "BPF_LDX_MEM | BPF_DW, unaligned positive offset",
8219 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8220 BPF_STX_MEM(BPF_DW, R1, R2, 13),
8221 BPF_LDX_MEM(BPF_DW, R0, R1, 13),
8222 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8223 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8226 INTERNAL | FLAG_LARGE_MEM,
8231 /* BPF_STX_MEM B/H/W/DW */
8233 "BPF_STX_MEM | BPF_B",
8235 BPF_LD_IMM64(R1, 0x8090a0b0c0d0e0f0ULL),
8236 BPF_LD_IMM64(R2, 0x0102030405060708ULL),
8237 BPF_LD_IMM64(R3, 0x8090a0b0c0d0e008ULL),
8238 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8240 BPF_STX_MEM(BPF_B, R10, R2, -1),
8242 BPF_STX_MEM(BPF_B, R10, R2, -8),
8244 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8245 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8246 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8255 "BPF_STX_MEM | BPF_B, MSB set",
8257 BPF_LD_IMM64(R1, 0x8090a0b0c0d0e0f0ULL),
8258 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8259 BPF_LD_IMM64(R3, 0x8090a0b0c0d0e088ULL),
8260 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8262 BPF_STX_MEM(BPF_B, R10, R2, -1),
8264 BPF_STX_MEM(BPF_B, R10, R2, -8),
8266 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8267 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8268 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8277 "BPF_STX_MEM | BPF_H",
8279 BPF_LD_IMM64(R1, 0x8090a0b0c0d0e0f0ULL),
8280 BPF_LD_IMM64(R2, 0x0102030405060708ULL),
8281 BPF_LD_IMM64(R3, 0x8090a0b0c0d00708ULL),
8282 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8284 BPF_STX_MEM(BPF_H, R10, R2, -2),
8286 BPF_STX_MEM(BPF_H, R10, R2, -8),
8288 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8289 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8290 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8299 "BPF_STX_MEM | BPF_H, MSB set",
8301 BPF_LD_IMM64(R1, 0x8090a0b0c0d0e0f0ULL),
8302 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8303 BPF_LD_IMM64(R3, 0x8090a0b0c0d08788ULL),
8304 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8306 BPF_STX_MEM(BPF_H, R10, R2, -2),
8308 BPF_STX_MEM(BPF_H, R10, R2, -8),
8310 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8311 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8312 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8321 "BPF_STX_MEM | BPF_W",
8323 BPF_LD_IMM64(R1, 0x8090a0b0c0d0e0f0ULL),
8324 BPF_LD_IMM64(R2, 0x0102030405060708ULL),
8325 BPF_LD_IMM64(R3, 0x8090a0b005060708ULL),
8326 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8328 BPF_STX_MEM(BPF_W, R10, R2, -4),
8330 BPF_STX_MEM(BPF_W, R10, R2, -8),
8332 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8333 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8334 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8343 "BPF_STX_MEM | BPF_W, MSB set",
8345 BPF_LD_IMM64(R1, 0x8090a0b0c0d0e0f0ULL),
8346 BPF_LD_IMM64(R2, 0x8182838485868788ULL),
8347 BPF_LD_IMM64(R3, 0x8090a0b085868788ULL),
8348 BPF_STX_MEM(BPF_DW, R10, R1, -8),
8350 BPF_STX_MEM(BPF_W, R10, R2, -4),
8352 BPF_STX_MEM(BPF_W, R10, R2, -8),
8354 BPF_LDX_MEM(BPF_DW, R0, R10, -8),
8355 BPF_JMP_REG(BPF_JNE, R0, R3, 1),
8356 BPF_ALU64_IMM(BPF_MOV, R0, 0),
8364 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
8366 "ST_MEM_B: Store/Load byte: max negative",
8368 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8369 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
8370 BPF_LDX_MEM(BPF_B, R0, R10, -40),
8379 "ST_MEM_B: Store/Load byte: max positive",
8381 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8382 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
8383 BPF_LDX_MEM(BPF_H, R0, R10, -40),
8392 "STX_MEM_B: Store/Load byte: max negative",
8394 BPF_LD_IMM64(R0, 0),
8395 BPF_LD_IMM64(R1, 0xffLL),
8396 BPF_STX_MEM(BPF_B, R10, R1, -40),
8397 BPF_LDX_MEM(BPF_B, R0, R10, -40),
8406 "ST_MEM_H: Store/Load half word: max negative",
8408 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8409 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
8410 BPF_LDX_MEM(BPF_H, R0, R10, -40),
8419 "ST_MEM_H: Store/Load half word: max positive",
8421 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8422 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
8423 BPF_LDX_MEM(BPF_H, R0, R10, -40),
8432 "STX_MEM_H: Store/Load half word: max negative",
8434 BPF_LD_IMM64(R0, 0),
8435 BPF_LD_IMM64(R1, 0xffffLL),
8436 BPF_STX_MEM(BPF_H, R10, R1, -40),
8437 BPF_LDX_MEM(BPF_H, R0, R10, -40),
8446 "ST_MEM_W: Store/Load word: max negative",
8448 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8449 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
8450 BPF_LDX_MEM(BPF_W, R0, R10, -40),
8455 { { 0, 0xffffffff } },
8459 "ST_MEM_W: Store/Load word: max positive",
8461 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8462 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
8463 BPF_LDX_MEM(BPF_W, R0, R10, -40),
8468 { { 0, 0x7fffffff } },
8472 "STX_MEM_W: Store/Load word: max negative",
8474 BPF_LD_IMM64(R0, 0),
8475 BPF_LD_IMM64(R1, 0xffffffffLL),
8476 BPF_STX_MEM(BPF_W, R10, R1, -40),
8477 BPF_LDX_MEM(BPF_W, R0, R10, -40),
8482 { { 0, 0xffffffff } },
8486 "ST_MEM_DW: Store/Load double word: max negative",
8488 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8489 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
8490 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
8495 { { 0, 0xffffffff } },
8499 "ST_MEM_DW: Store/Load double word: max negative 2",
8501 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
8502 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
8503 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
8504 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
8505 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
8506 BPF_MOV32_IMM(R0, 2),
8508 BPF_MOV32_IMM(R0, 1),
8517 "ST_MEM_DW: Store/Load double word: max positive",
8519 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8520 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
8521 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
8526 { { 0, 0x7fffffff } },
8530 "STX_MEM_DW: Store/Load double word: max negative",
8532 BPF_LD_IMM64(R0, 0),
8533 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
8534 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8535 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
8540 { { 0, 0xffffffff } },
8544 "STX_MEM_DW: Store double word: first word in memory",
8546 BPF_LD_IMM64(R0, 0),
8547 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
8548 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8549 BPF_LDX_MEM(BPF_W, R0, R10, -40),
8555 { { 0, 0x01234567 } },
8557 { { 0, 0x89abcdef } },
8562 "STX_MEM_DW: Store double word: second word in memory",
8564 BPF_LD_IMM64(R0, 0),
8565 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
8566 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8567 BPF_LDX_MEM(BPF_W, R0, R10, -36),
8573 { { 0, 0x89abcdef } },
8575 { { 0, 0x01234567 } },
8579 /* BPF_STX | BPF_ATOMIC | BPF_W/DW */
8581 "STX_XADD_W: X + 1 + 1 + 1 + ...",
8586 .fill_helper = bpf_fill_stxw,
8589 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
8594 .fill_helper = bpf_fill_stxdw,
8597 * Exhaustive tests of atomic operation variants.
8598 * Individual tests are expanded from template macros for all
8599 * combinations of ALU operation, word size and fetching.
8601 #define BPF_ATOMIC_POISON(width) ((width) == BPF_W ? (0xbaadf00dULL << 32) : 0)
8603 #define BPF_ATOMIC_OP_TEST1(width, op, logic, old, update, result) \
8605 "BPF_ATOMIC | " #width ", " #op ": Test: " \
8606 #old " " #logic " " #update " = " #result, \
8608 BPF_LD_IMM64(R5, (update) | BPF_ATOMIC_POISON(width)), \
8609 BPF_ST_MEM(width, R10, -40, old), \
8610 BPF_ATOMIC_OP(width, op, R10, R5, -40), \
8611 BPF_LDX_MEM(width, R0, R10, -40), \
8612 BPF_ALU64_REG(BPF_MOV, R1, R0), \
8613 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
8614 BPF_ALU64_REG(BPF_OR, R0, R1), \
8619 { { 0, result } }, \
8620 .stack_depth = 40, \
8622 #define BPF_ATOMIC_OP_TEST2(width, op, logic, old, update, result) \
8624 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r10: " \
8625 #old " " #logic " " #update " = " #result, \
8627 BPF_ALU64_REG(BPF_MOV, R1, R10), \
8628 BPF_LD_IMM64(R0, (update) | BPF_ATOMIC_POISON(width)), \
8629 BPF_ST_MEM(BPF_W, R10, -40, old), \
8630 BPF_ATOMIC_OP(width, op, R10, R0, -40), \
8631 BPF_ALU64_REG(BPF_MOV, R0, R10), \
8632 BPF_ALU64_REG(BPF_SUB, R0, R1), \
8633 BPF_ALU64_REG(BPF_MOV, R1, R0), \
8634 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
8635 BPF_ALU64_REG(BPF_OR, R0, R1), \
8641 .stack_depth = 40, \
8643 #define BPF_ATOMIC_OP_TEST3(width, op, logic, old, update, result) \
8645 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r0: " \
8646 #old " " #logic " " #update " = " #result, \
8648 BPF_ALU64_REG(BPF_MOV, R0, R10), \
8649 BPF_LD_IMM64(R1, (update) | BPF_ATOMIC_POISON(width)), \
8650 BPF_ST_MEM(width, R10, -40, old), \
8651 BPF_ATOMIC_OP(width, op, R10, R1, -40), \
8652 BPF_ALU64_REG(BPF_SUB, R0, R10), \
8653 BPF_ALU64_REG(BPF_MOV, R1, R0), \
8654 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
8655 BPF_ALU64_REG(BPF_OR, R0, R1), \
8661 .stack_depth = 40, \
8663 #define BPF_ATOMIC_OP_TEST4(width, op, logic, old, update, result) \
8665 "BPF_ATOMIC | " #width ", " #op ": Test fetch: " \
8666 #old " " #logic " " #update " = " #result, \
8668 BPF_LD_IMM64(R3, (update) | BPF_ATOMIC_POISON(width)), \
8669 BPF_ST_MEM(width, R10, -40, old), \
8670 BPF_ATOMIC_OP(width, op, R10, R3, -40), \
8671 BPF_ALU32_REG(BPF_MOV, R0, R3), \
8676 { { 0, (op) & BPF_FETCH ? old : update } }, \
8677 .stack_depth = 40, \
8679 /* BPF_ATOMIC | BPF_W: BPF_ADD */
8680 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
8681 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
8682 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
8683 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
8684 /* BPF_ATOMIC | BPF_W: BPF_ADD | BPF_FETCH */
8685 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8686 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8687 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8688 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8689 /* BPF_ATOMIC | BPF_DW: BPF_ADD */
8690 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
8691 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
8692 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
8693 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
8694 /* BPF_ATOMIC | BPF_DW: BPF_ADD | BPF_FETCH */
8695 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8696 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8697 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8698 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
8699 /* BPF_ATOMIC | BPF_W: BPF_AND */
8700 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
8701 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
8702 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
8703 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
8704 /* BPF_ATOMIC | BPF_W: BPF_AND | BPF_FETCH */
8705 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8706 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8707 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8708 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8709 /* BPF_ATOMIC | BPF_DW: BPF_AND */
8710 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
8711 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
8712 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
8713 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
8714 /* BPF_ATOMIC | BPF_DW: BPF_AND | BPF_FETCH */
8715 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8716 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8717 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8718 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
8719 /* BPF_ATOMIC | BPF_W: BPF_OR */
8720 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
8721 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
8722 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
8723 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
8724 /* BPF_ATOMIC | BPF_W: BPF_OR | BPF_FETCH */
8725 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8726 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8727 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8728 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8729 /* BPF_ATOMIC | BPF_DW: BPF_OR */
8730 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
8731 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
8732 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
8733 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
8734 /* BPF_ATOMIC | BPF_DW: BPF_OR | BPF_FETCH */
8735 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8736 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8737 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8738 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
8739 /* BPF_ATOMIC | BPF_W: BPF_XOR */
8740 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8741 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8742 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8743 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8744 /* BPF_ATOMIC | BPF_W: BPF_XOR | BPF_FETCH */
8745 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8746 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8747 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8748 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8749 /* BPF_ATOMIC | BPF_DW: BPF_XOR */
8750 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8751 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8752 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8753 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
8754 /* BPF_ATOMIC | BPF_DW: BPF_XOR | BPF_FETCH */
8755 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8756 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8757 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8758 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
8759 /* BPF_ATOMIC | BPF_W: BPF_XCHG */
8760 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8761 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8762 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8763 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8764 /* BPF_ATOMIC | BPF_DW: BPF_XCHG */
8765 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8766 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8767 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8768 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
8769 #undef BPF_ATOMIC_POISON
8770 #undef BPF_ATOMIC_OP_TEST1
8771 #undef BPF_ATOMIC_OP_TEST2
8772 #undef BPF_ATOMIC_OP_TEST3
8773 #undef BPF_ATOMIC_OP_TEST4
8774 /* BPF_ATOMIC | BPF_W, BPF_CMPXCHG */
8776 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful return",
8778 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
8779 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
8780 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
8781 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
8786 { { 0, 0x01234567 } },
8790 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful store",
8792 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
8793 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
8794 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
8795 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
8796 BPF_LDX_MEM(BPF_W, R0, R10, -40),
8801 { { 0, 0x89abcdef } },
8805 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure return",
8807 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
8808 BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210),
8809 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
8810 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
8815 { { 0, 0x01234567 } },
8819 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure store",
8821 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
8822 BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210),
8823 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
8824 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
8825 BPF_LDX_MEM(BPF_W, R0, R10, -40),
8830 { { 0, 0x01234567 } },
8834 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test side effects",
8836 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
8837 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
8838 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
8839 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
8840 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
8841 BPF_ALU32_REG(BPF_MOV, R0, R3),
8846 { { 0, 0x89abcdef } },
8849 /* BPF_ATOMIC | BPF_DW, BPF_CMPXCHG */
8851 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful return",
8853 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
8854 BPF_LD_IMM64(R2, 0xfedcba9876543210ULL),
8855 BPF_ALU64_REG(BPF_MOV, R0, R1),
8856 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8857 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
8858 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
8859 BPF_ALU64_REG(BPF_SUB, R0, R1),
8868 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful store",
8870 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
8871 BPF_LD_IMM64(R2, 0xfedcba9876543210ULL),
8872 BPF_ALU64_REG(BPF_MOV, R0, R1),
8873 BPF_STX_MEM(BPF_DW, R10, R0, -40),
8874 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
8875 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
8876 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8877 BPF_ALU64_REG(BPF_SUB, R0, R2),
8886 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure return",
8888 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
8889 BPF_LD_IMM64(R2, 0xfedcba9876543210ULL),
8890 BPF_ALU64_REG(BPF_MOV, R0, R1),
8891 BPF_ALU64_IMM(BPF_ADD, R0, 1),
8892 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8893 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
8894 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
8895 BPF_ALU64_REG(BPF_SUB, R0, R1),
8904 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure store",
8906 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
8907 BPF_LD_IMM64(R2, 0xfedcba9876543210ULL),
8908 BPF_ALU64_REG(BPF_MOV, R0, R1),
8909 BPF_ALU64_IMM(BPF_ADD, R0, 1),
8910 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8911 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
8912 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
8913 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
8914 BPF_ALU64_REG(BPF_SUB, R0, R1),
8923 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test side effects",
8925 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
8926 BPF_LD_IMM64(R2, 0xfedcba9876543210ULL),
8927 BPF_ALU64_REG(BPF_MOV, R0, R1),
8928 BPF_STX_MEM(BPF_DW, R10, R1, -40),
8929 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
8930 BPF_LD_IMM64(R0, 0xfedcba9876543210ULL),
8931 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
8932 BPF_ALU64_REG(BPF_SUB, R0, R2),
8940 /* BPF_JMP32 | BPF_JEQ | BPF_K */
8942 "JMP32_JEQ_K: Small immediate",
8944 BPF_ALU32_IMM(BPF_MOV, R0, 123),
8945 BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
8946 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
8947 BPF_ALU32_IMM(BPF_MOV, R0, 0),
8955 "JMP32_JEQ_K: Large immediate",
8957 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
8958 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1),
8959 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1),
8960 BPF_ALU32_IMM(BPF_MOV, R0, 0),
8968 "JMP32_JEQ_K: negative immediate",
8970 BPF_ALU32_IMM(BPF_MOV, R0, -123),
8971 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
8972 BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1),
8973 BPF_ALU32_IMM(BPF_MOV, R0, 0),
8980 /* BPF_JMP32 | BPF_JEQ | BPF_X */
8984 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
8985 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
8986 BPF_JMP32_REG(BPF_JEQ, R0, R1, 2),
8987 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
8988 BPF_JMP32_REG(BPF_JEQ, R0, R1, 1),
8989 BPF_ALU32_IMM(BPF_MOV, R0, 0),
8996 /* BPF_JMP32 | BPF_JNE | BPF_K */
8998 "JMP32_JNE_K: Small immediate",
9000 BPF_ALU32_IMM(BPF_MOV, R0, 123),
9001 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
9002 BPF_JMP32_IMM(BPF_JNE, R0, 321, 1),
9003 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9011 "JMP32_JNE_K: Large immediate",
9013 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
9014 BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1),
9015 BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1),
9016 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9024 "JMP32_JNE_K: negative immediate",
9026 BPF_ALU32_IMM(BPF_MOV, R0, -123),
9027 BPF_JMP32_IMM(BPF_JNE, R0, -123, 1),
9028 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
9029 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9036 /* BPF_JMP32 | BPF_JNE | BPF_X */
9040 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
9041 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
9042 BPF_JMP32_REG(BPF_JNE, R0, R1, 2),
9043 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
9044 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
9045 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9052 /* BPF_JMP32 | BPF_JSET | BPF_K */
9054 "JMP32_JSET_K: Small immediate",
9056 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9057 BPF_JMP32_IMM(BPF_JSET, R0, 2, 1),
9058 BPF_JMP32_IMM(BPF_JSET, R0, 3, 1),
9059 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9067 "JMP32_JSET_K: Large immediate",
9069 BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000),
9070 BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1),
9071 BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1),
9072 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9077 { { 0, 0x40000000 } }
9080 "JMP32_JSET_K: negative immediate",
9082 BPF_ALU32_IMM(BPF_MOV, R0, -123),
9083 BPF_JMP32_IMM(BPF_JSET, R0, -1, 1),
9084 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9091 /* BPF_JMP32 | BPF_JSET | BPF_X */
9095 BPF_ALU32_IMM(BPF_MOV, R0, 8),
9096 BPF_ALU32_IMM(BPF_MOV, R1, 7),
9097 BPF_JMP32_REG(BPF_JSET, R0, R1, 2),
9098 BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2),
9099 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
9100 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9107 /* BPF_JMP32 | BPF_JGT | BPF_K */
9109 "JMP32_JGT_K: Small immediate",
9111 BPF_ALU32_IMM(BPF_MOV, R0, 123),
9112 BPF_JMP32_IMM(BPF_JGT, R0, 123, 1),
9113 BPF_JMP32_IMM(BPF_JGT, R0, 122, 1),
9114 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9122 "JMP32_JGT_K: Large immediate",
9124 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9125 BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1),
9126 BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1),
9127 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9132 { { 0, 0xfffffffe } }
9134 /* BPF_JMP32 | BPF_JGT | BPF_X */
9138 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9139 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
9140 BPF_JMP32_REG(BPF_JGT, R0, R1, 2),
9141 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
9142 BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
9143 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9148 { { 0, 0xfffffffe } }
9150 /* BPF_JMP32 | BPF_JGE | BPF_K */
9152 "JMP32_JGE_K: Small immediate",
9154 BPF_ALU32_IMM(BPF_MOV, R0, 123),
9155 BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
9156 BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
9157 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9165 "JMP32_JGE_K: Large immediate",
9167 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9168 BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
9169 BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
9170 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9175 { { 0, 0xfffffffe } }
9177 /* BPF_JMP32 | BPF_JGE | BPF_X */
9181 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9182 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
9183 BPF_JMP32_REG(BPF_JGE, R0, R1, 2),
9184 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
9185 BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
9186 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9191 { { 0, 0xfffffffe } }
9193 /* BPF_JMP32 | BPF_JLT | BPF_K */
9195 "JMP32_JLT_K: Small immediate",
9197 BPF_ALU32_IMM(BPF_MOV, R0, 123),
9198 BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
9199 BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
9200 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9208 "JMP32_JLT_K: Large immediate",
9210 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9211 BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
9212 BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
9213 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9218 { { 0, 0xfffffffe } }
9220 /* BPF_JMP32 | BPF_JLT | BPF_X */
9224 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9225 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
9226 BPF_JMP32_REG(BPF_JLT, R0, R1, 2),
9227 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
9228 BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
9229 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9234 { { 0, 0xfffffffe } }
9236 /* BPF_JMP32 | BPF_JLE | BPF_K */
9238 "JMP32_JLE_K: Small immediate",
9240 BPF_ALU32_IMM(BPF_MOV, R0, 123),
9241 BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
9242 BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
9243 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9251 "JMP32_JLE_K: Large immediate",
9253 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9254 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
9255 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
9256 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9261 { { 0, 0xfffffffe } }
9263 /* BPF_JMP32 | BPF_JLE | BPF_X */
9267 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
9268 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
9269 BPF_JMP32_REG(BPF_JLE, R0, R1, 2),
9270 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
9271 BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
9272 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9277 { { 0, 0xfffffffe } }
9279 /* BPF_JMP32 | BPF_JSGT | BPF_K */
9281 "JMP32_JSGT_K: Small immediate",
9283 BPF_ALU32_IMM(BPF_MOV, R0, -123),
9284 BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
9285 BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
9286 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9294 "JMP32_JSGT_K: Large immediate",
9296 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9297 BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
9298 BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
9299 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9304 { { 0, -12345678 } }
9306 /* BPF_JMP32 | BPF_JSGT | BPF_X */
9310 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9311 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
9312 BPF_JMP32_REG(BPF_JSGT, R0, R1, 2),
9313 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
9314 BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
9315 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9320 { { 0, -12345678 } }
9322 /* BPF_JMP32 | BPF_JSGE | BPF_K */
9324 "JMP32_JSGE_K: Small immediate",
9326 BPF_ALU32_IMM(BPF_MOV, R0, -123),
9327 BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
9328 BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
9329 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9337 "JMP32_JSGE_K: Large immediate",
9339 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9340 BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
9341 BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
9342 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9347 { { 0, -12345678 } }
9349 /* BPF_JMP32 | BPF_JSGE | BPF_X */
9353 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9354 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
9355 BPF_JMP32_REG(BPF_JSGE, R0, R1, 2),
9356 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
9357 BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
9358 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9363 { { 0, -12345678 } }
9365 /* BPF_JMP32 | BPF_JSLT | BPF_K */
9367 "JMP32_JSLT_K: Small immediate",
9369 BPF_ALU32_IMM(BPF_MOV, R0, -123),
9370 BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
9371 BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
9372 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9380 "JMP32_JSLT_K: Large immediate",
9382 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9383 BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
9384 BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
9385 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9390 { { 0, -12345678 } }
9392 /* BPF_JMP32 | BPF_JSLT | BPF_X */
9396 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9397 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
9398 BPF_JMP32_REG(BPF_JSLT, R0, R1, 2),
9399 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
9400 BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
9401 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9406 { { 0, -12345678 } }
9408 /* BPF_JMP32 | BPF_JSLE | BPF_K */
9410 "JMP32_JSLE_K: Small immediate",
9412 BPF_ALU32_IMM(BPF_MOV, R0, -123),
9413 BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
9414 BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
9415 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9423 "JMP32_JSLE_K: Large immediate",
9425 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9426 BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
9427 BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
9428 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9433 { { 0, -12345678 } }
9435 /* BPF_JMP32 | BPF_JSLE | BPF_K */
9439 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
9440 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
9441 BPF_JMP32_REG(BPF_JSLE, R0, R1, 2),
9442 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
9443 BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
9444 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9449 { { 0, -12345678 } }
9451 /* BPF_JMP | BPF_EXIT */
9455 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
9457 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
9463 /* BPF_JMP | BPF_JA */
9465 "JMP_JA: Unconditional jump: if (true) return 1",
9467 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9468 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
9470 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9477 /* BPF_JMP | BPF_JSLT | BPF_K */
9479 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
9481 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9482 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
9483 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
9485 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9493 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
9495 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9496 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
9497 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
9499 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9506 /* BPF_JMP | BPF_JSGT | BPF_K */
9508 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
9510 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9511 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
9512 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
9514 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9522 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
9524 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9525 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
9526 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
9528 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9535 /* BPF_JMP | BPF_JSLE | BPF_K */
9537 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
9539 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9540 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
9541 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
9543 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9551 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
9553 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9554 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
9555 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
9557 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9565 "JMP_JSLE_K: Signed jump: value walk 1",
9567 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9568 BPF_LD_IMM64(R1, 3),
9569 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
9570 BPF_ALU64_IMM(BPF_SUB, R1, 1),
9571 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
9572 BPF_ALU64_IMM(BPF_SUB, R1, 1),
9573 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
9574 BPF_ALU64_IMM(BPF_SUB, R1, 1),
9575 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
9576 BPF_EXIT_INSN(), /* bad exit */
9577 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
9585 "JMP_JSLE_K: Signed jump: value walk 2",
9587 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9588 BPF_LD_IMM64(R1, 3),
9589 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
9590 BPF_ALU64_IMM(BPF_SUB, R1, 2),
9591 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
9592 BPF_ALU64_IMM(BPF_SUB, R1, 2),
9593 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
9594 BPF_EXIT_INSN(), /* bad exit */
9595 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
9602 /* BPF_JMP | BPF_JSGE | BPF_K */
9604 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
9606 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9607 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
9608 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
9610 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9618 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
9620 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9621 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
9622 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
9624 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9632 "JMP_JSGE_K: Signed jump: value walk 1",
9634 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9635 BPF_LD_IMM64(R1, -3),
9636 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
9637 BPF_ALU64_IMM(BPF_ADD, R1, 1),
9638 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
9639 BPF_ALU64_IMM(BPF_ADD, R1, 1),
9640 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
9641 BPF_ALU64_IMM(BPF_ADD, R1, 1),
9642 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
9643 BPF_EXIT_INSN(), /* bad exit */
9644 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
9652 "JMP_JSGE_K: Signed jump: value walk 2",
9654 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9655 BPF_LD_IMM64(R1, -3),
9656 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
9657 BPF_ALU64_IMM(BPF_ADD, R1, 2),
9658 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
9659 BPF_ALU64_IMM(BPF_ADD, R1, 2),
9660 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
9661 BPF_EXIT_INSN(), /* bad exit */
9662 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
9669 /* BPF_JMP | BPF_JGT | BPF_K */
9671 "JMP_JGT_K: if (3 > 2) return 1",
9673 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9674 BPF_LD_IMM64(R1, 3),
9675 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
9677 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9685 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
9687 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9688 BPF_LD_IMM64(R1, -1),
9689 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
9691 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9698 /* BPF_JMP | BPF_JLT | BPF_K */
9700 "JMP_JLT_K: if (2 < 3) return 1",
9702 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9703 BPF_LD_IMM64(R1, 2),
9704 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
9706 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9714 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
9716 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9717 BPF_LD_IMM64(R1, 1),
9718 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
9720 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9727 /* BPF_JMP | BPF_JGE | BPF_K */
9729 "JMP_JGE_K: if (3 >= 2) return 1",
9731 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9732 BPF_LD_IMM64(R1, 3),
9733 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
9735 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9742 /* BPF_JMP | BPF_JLE | BPF_K */
9744 "JMP_JLE_K: if (2 <= 3) return 1",
9746 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9747 BPF_LD_IMM64(R1, 2),
9748 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
9750 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9757 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
9759 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
9761 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
9762 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
9764 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
9765 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
9766 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
9774 "JMP_JGE_K: if (3 >= 3) return 1",
9776 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9777 BPF_LD_IMM64(R1, 3),
9778 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
9780 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9787 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
9789 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
9791 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
9792 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
9794 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
9795 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
9796 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
9804 "JMP_JLE_K: if (3 <= 3) return 1",
9806 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9807 BPF_LD_IMM64(R1, 3),
9808 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
9810 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9817 /* BPF_JMP | BPF_JNE | BPF_K */
9819 "JMP_JNE_K: if (3 != 2) return 1",
9821 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9822 BPF_LD_IMM64(R1, 3),
9823 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
9825 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9832 /* BPF_JMP | BPF_JEQ | BPF_K */
9834 "JMP_JEQ_K: if (3 == 3) return 1",
9836 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9837 BPF_LD_IMM64(R1, 3),
9838 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
9840 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9847 /* BPF_JMP | BPF_JSET | BPF_K */
9849 "JMP_JSET_K: if (0x3 & 0x2) return 1",
9851 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9852 BPF_LD_IMM64(R1, 3),
9853 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
9855 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9863 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
9865 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9866 BPF_LD_IMM64(R1, 3),
9867 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
9869 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9876 /* BPF_JMP | BPF_JSGT | BPF_X */
9878 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
9880 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9881 BPF_LD_IMM64(R1, -1),
9882 BPF_LD_IMM64(R2, -2),
9883 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
9885 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9893 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
9895 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9896 BPF_LD_IMM64(R1, -1),
9897 BPF_LD_IMM64(R2, -1),
9898 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
9900 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9907 /* BPF_JMP | BPF_JSLT | BPF_X */
9909 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
9911 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9912 BPF_LD_IMM64(R1, -1),
9913 BPF_LD_IMM64(R2, -2),
9914 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
9916 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9924 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
9926 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9927 BPF_LD_IMM64(R1, -1),
9928 BPF_LD_IMM64(R2, -1),
9929 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
9931 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9938 /* BPF_JMP | BPF_JSGE | BPF_X */
9940 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
9942 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9943 BPF_LD_IMM64(R1, -1),
9944 BPF_LD_IMM64(R2, -2),
9945 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
9947 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9955 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
9957 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9958 BPF_LD_IMM64(R1, -1),
9959 BPF_LD_IMM64(R2, -1),
9960 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
9962 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9969 /* BPF_JMP | BPF_JSLE | BPF_X */
9971 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
9973 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9974 BPF_LD_IMM64(R1, -1),
9975 BPF_LD_IMM64(R2, -2),
9976 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
9978 BPF_ALU32_IMM(BPF_MOV, R0, 1),
9986 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
9988 BPF_ALU32_IMM(BPF_MOV, R0, 0),
9989 BPF_LD_IMM64(R1, -1),
9990 BPF_LD_IMM64(R2, -1),
9991 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
9993 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10000 /* BPF_JMP | BPF_JGT | BPF_X */
10002 "JMP_JGT_X: if (3 > 2) return 1",
10004 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10005 BPF_LD_IMM64(R1, 3),
10006 BPF_LD_IMM64(R2, 2),
10007 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
10009 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10017 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
10019 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10020 BPF_LD_IMM64(R1, -1),
10021 BPF_LD_IMM64(R2, 1),
10022 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
10024 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10031 /* BPF_JMP | BPF_JLT | BPF_X */
10033 "JMP_JLT_X: if (2 < 3) return 1",
10035 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10036 BPF_LD_IMM64(R1, 3),
10037 BPF_LD_IMM64(R2, 2),
10038 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
10040 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10048 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
10050 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10051 BPF_LD_IMM64(R1, -1),
10052 BPF_LD_IMM64(R2, 1),
10053 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
10055 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10062 /* BPF_JMP | BPF_JGE | BPF_X */
10064 "JMP_JGE_X: if (3 >= 2) return 1",
10066 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10067 BPF_LD_IMM64(R1, 3),
10068 BPF_LD_IMM64(R2, 2),
10069 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
10071 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10079 "JMP_JGE_X: if (3 >= 3) return 1",
10081 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10082 BPF_LD_IMM64(R1, 3),
10083 BPF_LD_IMM64(R2, 3),
10084 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
10086 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10093 /* BPF_JMP | BPF_JLE | BPF_X */
10095 "JMP_JLE_X: if (2 <= 3) return 1",
10097 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10098 BPF_LD_IMM64(R1, 3),
10099 BPF_LD_IMM64(R2, 2),
10100 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
10102 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10110 "JMP_JLE_X: if (3 <= 3) return 1",
10112 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10113 BPF_LD_IMM64(R1, 3),
10114 BPF_LD_IMM64(R2, 3),
10115 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
10117 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10125 /* Mainly testing JIT + imm64 here. */
10126 "JMP_JGE_X: ldimm64 test 1",
10128 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10129 BPF_LD_IMM64(R1, 3),
10130 BPF_LD_IMM64(R2, 2),
10131 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
10132 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
10133 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
10138 { { 0, 0xeeeeeeeeU } },
10141 "JMP_JGE_X: ldimm64 test 2",
10143 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10144 BPF_LD_IMM64(R1, 3),
10145 BPF_LD_IMM64(R2, 2),
10146 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
10147 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
10152 { { 0, 0xffffffffU } },
10155 "JMP_JGE_X: ldimm64 test 3",
10157 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10158 BPF_LD_IMM64(R1, 3),
10159 BPF_LD_IMM64(R2, 2),
10160 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
10161 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
10162 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
10170 "JMP_JLE_X: ldimm64 test 1",
10172 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10173 BPF_LD_IMM64(R1, 3),
10174 BPF_LD_IMM64(R2, 2),
10175 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
10176 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
10177 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
10182 { { 0, 0xeeeeeeeeU } },
10185 "JMP_JLE_X: ldimm64 test 2",
10187 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10188 BPF_LD_IMM64(R1, 3),
10189 BPF_LD_IMM64(R2, 2),
10190 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
10191 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
10196 { { 0, 0xffffffffU } },
10199 "JMP_JLE_X: ldimm64 test 3",
10201 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10202 BPF_LD_IMM64(R1, 3),
10203 BPF_LD_IMM64(R2, 2),
10204 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
10205 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
10206 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
10213 /* BPF_JMP | BPF_JNE | BPF_X */
10215 "JMP_JNE_X: if (3 != 2) return 1",
10217 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10218 BPF_LD_IMM64(R1, 3),
10219 BPF_LD_IMM64(R2, 2),
10220 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
10222 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10229 /* BPF_JMP | BPF_JEQ | BPF_X */
10231 "JMP_JEQ_X: if (3 == 3) return 1",
10233 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10234 BPF_LD_IMM64(R1, 3),
10235 BPF_LD_IMM64(R2, 3),
10236 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
10238 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10245 /* BPF_JMP | BPF_JSET | BPF_X */
10247 "JMP_JSET_X: if (0x3 & 0x2) return 1",
10249 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10250 BPF_LD_IMM64(R1, 3),
10251 BPF_LD_IMM64(R2, 2),
10252 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
10254 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10262 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
10264 BPF_ALU32_IMM(BPF_MOV, R0, 0),
10265 BPF_LD_IMM64(R1, 3),
10266 BPF_LD_IMM64(R2, 0xffffffff),
10267 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
10269 BPF_ALU32_IMM(BPF_MOV, R0, 1),
10277 "JMP_JA: Jump, gap, jump, ...",
10279 CLASSIC | FLAG_NO_DATA,
10281 { { 0, 0xababcbac } },
10282 .fill_helper = bpf_fill_ja,
10284 { /* Mainly checking JIT here. */
10285 "BPF_MAXINSNS: Maximum possible literals",
10287 CLASSIC | FLAG_NO_DATA,
10289 { { 0, 0xffffffff } },
10290 .fill_helper = bpf_fill_maxinsns1,
10292 { /* Mainly checking JIT here. */
10293 "BPF_MAXINSNS: Single literal",
10295 CLASSIC | FLAG_NO_DATA,
10297 { { 0, 0xfefefefe } },
10298 .fill_helper = bpf_fill_maxinsns2,
10300 { /* Mainly checking JIT here. */
10301 "BPF_MAXINSNS: Run/add until end",
10303 CLASSIC | FLAG_NO_DATA,
10305 { { 0, 0x947bf368 } },
10306 .fill_helper = bpf_fill_maxinsns3,
10309 "BPF_MAXINSNS: Too many instructions",
10311 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
10314 .fill_helper = bpf_fill_maxinsns4,
10315 .expected_errcode = -EINVAL,
10317 { /* Mainly checking JIT here. */
10318 "BPF_MAXINSNS: Very long jump",
10320 CLASSIC | FLAG_NO_DATA,
10322 { { 0, 0xabababab } },
10323 .fill_helper = bpf_fill_maxinsns5,
10325 { /* Mainly checking JIT here. */
10326 "BPF_MAXINSNS: Ctx heavy transformations",
10331 { 1, SKB_VLAN_PRESENT },
10332 { 10, SKB_VLAN_PRESENT }
10334 .fill_helper = bpf_fill_maxinsns6,
10336 { /* Mainly checking JIT here. */
10337 "BPF_MAXINSNS: Call heavy transformations",
10339 CLASSIC | FLAG_NO_DATA,
10341 { { 1, 0 }, { 10, 0 } },
10342 .fill_helper = bpf_fill_maxinsns7,
10344 { /* Mainly checking JIT here. */
10345 "BPF_MAXINSNS: Jump heavy test",
10347 CLASSIC | FLAG_NO_DATA,
10349 { { 0, 0xffffffff } },
10350 .fill_helper = bpf_fill_maxinsns8,
10352 { /* Mainly checking JIT here. */
10353 "BPF_MAXINSNS: Very long jump backwards",
10355 INTERNAL | FLAG_NO_DATA,
10357 { { 0, 0xcbababab } },
10358 .fill_helper = bpf_fill_maxinsns9,
10360 { /* Mainly checking JIT here. */
10361 "BPF_MAXINSNS: Edge hopping nuthouse",
10363 INTERNAL | FLAG_NO_DATA,
10365 { { 0, 0xabababac } },
10366 .fill_helper = bpf_fill_maxinsns10,
10369 "BPF_MAXINSNS: Jump, gap, jump, ...",
10371 CLASSIC | FLAG_NO_DATA,
10373 { { 0, 0xababcbac } },
10374 .fill_helper = bpf_fill_maxinsns11,
10377 "BPF_MAXINSNS: jump over MSH",
10379 CLASSIC | FLAG_EXPECTED_FAIL,
10380 { 0xfa, 0xfb, 0xfc, 0xfd, },
10381 { { 4, 0xabababab } },
10382 .fill_helper = bpf_fill_maxinsns12,
10383 .expected_errcode = -EINVAL,
10386 "BPF_MAXINSNS: exec all MSH",
10389 { 0xfa, 0xfb, 0xfc, 0xfd, },
10390 { { 4, 0xababab83 } },
10391 .fill_helper = bpf_fill_maxinsns13,
10394 "BPF_MAXINSNS: ld_abs+get_processor_id",
10399 .fill_helper = bpf_fill_ld_abs_get_processor_id,
10402 * LD_IND / LD_ABS on fragmented SKBs
10405 "LD_IND byte frag",
10407 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
10408 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
10409 BPF_STMT(BPF_RET | BPF_A, 0x0),
10411 CLASSIC | FLAG_SKB_FRAG,
10415 0x42, 0x00, 0x00, 0x00,
10416 0x43, 0x44, 0x00, 0x00,
10417 0x21, 0x07, 0x19, 0x83,
10421 "LD_IND halfword frag",
10423 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
10424 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
10425 BPF_STMT(BPF_RET | BPF_A, 0x0),
10427 CLASSIC | FLAG_SKB_FRAG,
10429 { {0x40, 0x4344} },
10431 0x42, 0x00, 0x00, 0x00,
10432 0x43, 0x44, 0x00, 0x00,
10433 0x21, 0x07, 0x19, 0x83,
10437 "LD_IND word frag",
10439 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
10440 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
10441 BPF_STMT(BPF_RET | BPF_A, 0x0),
10443 CLASSIC | FLAG_SKB_FRAG,
10445 { {0x40, 0x21071983} },
10447 0x42, 0x00, 0x00, 0x00,
10448 0x43, 0x44, 0x00, 0x00,
10449 0x21, 0x07, 0x19, 0x83,
10453 "LD_IND halfword mixed head/frag",
10455 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
10456 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
10457 BPF_STMT(BPF_RET | BPF_A, 0x0),
10459 CLASSIC | FLAG_SKB_FRAG,
10460 { [0x3e] = 0x25, [0x3f] = 0x05, },
10461 { {0x40, 0x0519} },
10462 .frag_data = { 0x19, 0x82 },
10465 "LD_IND word mixed head/frag",
10467 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
10468 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
10469 BPF_STMT(BPF_RET | BPF_A, 0x0),
10471 CLASSIC | FLAG_SKB_FRAG,
10472 { [0x3e] = 0x25, [0x3f] = 0x05, },
10473 { {0x40, 0x25051982} },
10474 .frag_data = { 0x19, 0x82 },
10477 "LD_ABS byte frag",
10479 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
10480 BPF_STMT(BPF_RET | BPF_A, 0x0),
10482 CLASSIC | FLAG_SKB_FRAG,
10486 0x42, 0x00, 0x00, 0x00,
10487 0x43, 0x44, 0x00, 0x00,
10488 0x21, 0x07, 0x19, 0x83,
10492 "LD_ABS halfword frag",
10494 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
10495 BPF_STMT(BPF_RET | BPF_A, 0x0),
10497 CLASSIC | FLAG_SKB_FRAG,
10499 { {0x40, 0x4344} },
10501 0x42, 0x00, 0x00, 0x00,
10502 0x43, 0x44, 0x00, 0x00,
10503 0x21, 0x07, 0x19, 0x83,
10507 "LD_ABS word frag",
10509 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
10510 BPF_STMT(BPF_RET | BPF_A, 0x0),
10512 CLASSIC | FLAG_SKB_FRAG,
10514 { {0x40, 0x21071983} },
10516 0x42, 0x00, 0x00, 0x00,
10517 0x43, 0x44, 0x00, 0x00,
10518 0x21, 0x07, 0x19, 0x83,
10522 "LD_ABS halfword mixed head/frag",
10524 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
10525 BPF_STMT(BPF_RET | BPF_A, 0x0),
10527 CLASSIC | FLAG_SKB_FRAG,
10528 { [0x3e] = 0x25, [0x3f] = 0x05, },
10529 { {0x40, 0x0519} },
10530 .frag_data = { 0x19, 0x82 },
10533 "LD_ABS word mixed head/frag",
10535 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
10536 BPF_STMT(BPF_RET | BPF_A, 0x0),
10538 CLASSIC | FLAG_SKB_FRAG,
10539 { [0x3e] = 0x25, [0x3f] = 0x05, },
10540 { {0x40, 0x25051982} },
10541 .frag_data = { 0x19, 0x82 },
10544 * LD_IND / LD_ABS on non fragmented SKBs
10548 * this tests that the JIT/interpreter correctly resets X
10549 * before using it in an LD_IND instruction.
10551 "LD_IND byte default X",
10553 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
10554 BPF_STMT(BPF_RET | BPF_A, 0x0),
10561 "LD_IND byte positive offset",
10563 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10564 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
10565 BPF_STMT(BPF_RET | BPF_A, 0x0),
10568 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10572 "LD_IND byte negative offset",
10574 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10575 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
10576 BPF_STMT(BPF_RET | BPF_A, 0x0),
10579 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10583 "LD_IND byte positive offset, all ff",
10585 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10586 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
10587 BPF_STMT(BPF_RET | BPF_A, 0x0),
10590 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
10594 "LD_IND byte positive offset, out of bounds",
10596 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10597 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
10598 BPF_STMT(BPF_RET | BPF_A, 0x0),
10601 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10605 "LD_IND byte negative offset, out of bounds",
10607 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10608 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
10609 BPF_STMT(BPF_RET | BPF_A, 0x0),
10612 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10616 "LD_IND byte negative offset, multiple calls",
10618 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
10619 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
10620 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
10621 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
10622 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
10623 BPF_STMT(BPF_RET | BPF_A, 0x0),
10626 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10627 { {0x40, 0x82 }, },
10630 "LD_IND halfword positive offset",
10632 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10633 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
10634 BPF_STMT(BPF_RET | BPF_A, 0x0),
10638 [0x1c] = 0xaa, [0x1d] = 0x55,
10639 [0x1e] = 0xbb, [0x1f] = 0x66,
10640 [0x20] = 0xcc, [0x21] = 0x77,
10641 [0x22] = 0xdd, [0x23] = 0x88,
10643 { {0x40, 0xdd88 } },
10646 "LD_IND halfword negative offset",
10648 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10649 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
10650 BPF_STMT(BPF_RET | BPF_A, 0x0),
10654 [0x1c] = 0xaa, [0x1d] = 0x55,
10655 [0x1e] = 0xbb, [0x1f] = 0x66,
10656 [0x20] = 0xcc, [0x21] = 0x77,
10657 [0x22] = 0xdd, [0x23] = 0x88,
10659 { {0x40, 0xbb66 } },
10662 "LD_IND halfword unaligned",
10664 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10665 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
10666 BPF_STMT(BPF_RET | BPF_A, 0x0),
10670 [0x1c] = 0xaa, [0x1d] = 0x55,
10671 [0x1e] = 0xbb, [0x1f] = 0x66,
10672 [0x20] = 0xcc, [0x21] = 0x77,
10673 [0x22] = 0xdd, [0x23] = 0x88,
10675 { {0x40, 0x66cc } },
10678 "LD_IND halfword positive offset, all ff",
10680 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
10681 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
10682 BPF_STMT(BPF_RET | BPF_A, 0x0),
10685 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
10686 { {0x40, 0xffff } },
10689 "LD_IND halfword positive offset, out of bounds",
10691 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10692 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
10693 BPF_STMT(BPF_RET | BPF_A, 0x0),
10696 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10700 "LD_IND halfword negative offset, out of bounds",
10702 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10703 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
10704 BPF_STMT(BPF_RET | BPF_A, 0x0),
10707 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10711 "LD_IND word positive offset",
10713 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10714 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
10715 BPF_STMT(BPF_RET | BPF_A, 0x0),
10719 [0x1c] = 0xaa, [0x1d] = 0x55,
10720 [0x1e] = 0xbb, [0x1f] = 0x66,
10721 [0x20] = 0xcc, [0x21] = 0x77,
10722 [0x22] = 0xdd, [0x23] = 0x88,
10723 [0x24] = 0xee, [0x25] = 0x99,
10724 [0x26] = 0xff, [0x27] = 0xaa,
10726 { {0x40, 0xee99ffaa } },
10729 "LD_IND word negative offset",
10731 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10732 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
10733 BPF_STMT(BPF_RET | BPF_A, 0x0),
10737 [0x1c] = 0xaa, [0x1d] = 0x55,
10738 [0x1e] = 0xbb, [0x1f] = 0x66,
10739 [0x20] = 0xcc, [0x21] = 0x77,
10740 [0x22] = 0xdd, [0x23] = 0x88,
10741 [0x24] = 0xee, [0x25] = 0x99,
10742 [0x26] = 0xff, [0x27] = 0xaa,
10744 { {0x40, 0xaa55bb66 } },
10747 "LD_IND word unaligned (addr & 3 == 2)",
10749 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10750 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
10751 BPF_STMT(BPF_RET | BPF_A, 0x0),
10755 [0x1c] = 0xaa, [0x1d] = 0x55,
10756 [0x1e] = 0xbb, [0x1f] = 0x66,
10757 [0x20] = 0xcc, [0x21] = 0x77,
10758 [0x22] = 0xdd, [0x23] = 0x88,
10759 [0x24] = 0xee, [0x25] = 0x99,
10760 [0x26] = 0xff, [0x27] = 0xaa,
10762 { {0x40, 0xbb66cc77 } },
10765 "LD_IND word unaligned (addr & 3 == 1)",
10767 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10768 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
10769 BPF_STMT(BPF_RET | BPF_A, 0x0),
10773 [0x1c] = 0xaa, [0x1d] = 0x55,
10774 [0x1e] = 0xbb, [0x1f] = 0x66,
10775 [0x20] = 0xcc, [0x21] = 0x77,
10776 [0x22] = 0xdd, [0x23] = 0x88,
10777 [0x24] = 0xee, [0x25] = 0x99,
10778 [0x26] = 0xff, [0x27] = 0xaa,
10780 { {0x40, 0x55bb66cc } },
10783 "LD_IND word unaligned (addr & 3 == 3)",
10785 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
10786 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
10787 BPF_STMT(BPF_RET | BPF_A, 0x0),
10791 [0x1c] = 0xaa, [0x1d] = 0x55,
10792 [0x1e] = 0xbb, [0x1f] = 0x66,
10793 [0x20] = 0xcc, [0x21] = 0x77,
10794 [0x22] = 0xdd, [0x23] = 0x88,
10795 [0x24] = 0xee, [0x25] = 0x99,
10796 [0x26] = 0xff, [0x27] = 0xaa,
10798 { {0x40, 0x66cc77dd } },
10801 "LD_IND word positive offset, all ff",
10803 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
10804 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
10805 BPF_STMT(BPF_RET | BPF_A, 0x0),
10808 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
10809 { {0x40, 0xffffffff } },
10812 "LD_IND word positive offset, out of bounds",
10814 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10815 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
10816 BPF_STMT(BPF_RET | BPF_A, 0x0),
10819 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10823 "LD_IND word negative offset, out of bounds",
10825 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
10826 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
10827 BPF_STMT(BPF_RET | BPF_A, 0x0),
10830 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10836 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
10837 BPF_STMT(BPF_RET | BPF_A, 0x0),
10841 [0x1c] = 0xaa, [0x1d] = 0x55,
10842 [0x1e] = 0xbb, [0x1f] = 0x66,
10843 [0x20] = 0xcc, [0x21] = 0x77,
10844 [0x22] = 0xdd, [0x23] = 0x88,
10845 [0x24] = 0xee, [0x25] = 0x99,
10846 [0x26] = 0xff, [0x27] = 0xaa,
10851 "LD_ABS byte positive offset, all ff",
10853 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
10854 BPF_STMT(BPF_RET | BPF_A, 0x0),
10857 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
10861 "LD_ABS byte positive offset, out of bounds",
10863 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
10864 BPF_STMT(BPF_RET | BPF_A, 0x0),
10867 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10871 "LD_ABS byte negative offset, out of bounds load",
10873 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
10874 BPF_STMT(BPF_RET | BPF_A, 0x0),
10876 CLASSIC | FLAG_EXPECTED_FAIL,
10877 .expected_errcode = -EINVAL,
10880 "LD_ABS byte negative offset, in bounds",
10882 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
10883 BPF_STMT(BPF_RET | BPF_A, 0x0),
10886 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10887 { {0x40, 0x82 }, },
10890 "LD_ABS byte negative offset, out of bounds",
10892 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
10893 BPF_STMT(BPF_RET | BPF_A, 0x0),
10896 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10900 "LD_ABS byte negative offset, multiple calls",
10902 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
10903 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
10904 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
10905 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
10906 BPF_STMT(BPF_RET | BPF_A, 0x0),
10909 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10910 { {0x40, 0x82 }, },
10915 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
10916 BPF_STMT(BPF_RET | BPF_A, 0x0),
10920 [0x1c] = 0xaa, [0x1d] = 0x55,
10921 [0x1e] = 0xbb, [0x1f] = 0x66,
10922 [0x20] = 0xcc, [0x21] = 0x77,
10923 [0x22] = 0xdd, [0x23] = 0x88,
10924 [0x24] = 0xee, [0x25] = 0x99,
10925 [0x26] = 0xff, [0x27] = 0xaa,
10927 { {0x40, 0xdd88 } },
10930 "LD_ABS halfword unaligned",
10932 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
10933 BPF_STMT(BPF_RET | BPF_A, 0x0),
10937 [0x1c] = 0xaa, [0x1d] = 0x55,
10938 [0x1e] = 0xbb, [0x1f] = 0x66,
10939 [0x20] = 0xcc, [0x21] = 0x77,
10940 [0x22] = 0xdd, [0x23] = 0x88,
10941 [0x24] = 0xee, [0x25] = 0x99,
10942 [0x26] = 0xff, [0x27] = 0xaa,
10944 { {0x40, 0x99ff } },
10947 "LD_ABS halfword positive offset, all ff",
10949 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
10950 BPF_STMT(BPF_RET | BPF_A, 0x0),
10953 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
10954 { {0x40, 0xffff } },
10957 "LD_ABS halfword positive offset, out of bounds",
10959 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
10960 BPF_STMT(BPF_RET | BPF_A, 0x0),
10963 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10967 "LD_ABS halfword negative offset, out of bounds load",
10969 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
10970 BPF_STMT(BPF_RET | BPF_A, 0x0),
10972 CLASSIC | FLAG_EXPECTED_FAIL,
10973 .expected_errcode = -EINVAL,
10976 "LD_ABS halfword negative offset, in bounds",
10978 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
10979 BPF_STMT(BPF_RET | BPF_A, 0x0),
10982 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10983 { {0x40, 0x1982 }, },
10986 "LD_ABS halfword negative offset, out of bounds",
10988 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
10989 BPF_STMT(BPF_RET | BPF_A, 0x0),
10992 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
10998 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
10999 BPF_STMT(BPF_RET | BPF_A, 0x0),
11003 [0x1c] = 0xaa, [0x1d] = 0x55,
11004 [0x1e] = 0xbb, [0x1f] = 0x66,
11005 [0x20] = 0xcc, [0x21] = 0x77,
11006 [0x22] = 0xdd, [0x23] = 0x88,
11007 [0x24] = 0xee, [0x25] = 0x99,
11008 [0x26] = 0xff, [0x27] = 0xaa,
11010 { {0x40, 0xaa55bb66 } },
11013 "LD_ABS word unaligned (addr & 3 == 2)",
11015 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
11016 BPF_STMT(BPF_RET | BPF_A, 0x0),
11020 [0x1c] = 0xaa, [0x1d] = 0x55,
11021 [0x1e] = 0xbb, [0x1f] = 0x66,
11022 [0x20] = 0xcc, [0x21] = 0x77,
11023 [0x22] = 0xdd, [0x23] = 0x88,
11024 [0x24] = 0xee, [0x25] = 0x99,
11025 [0x26] = 0xff, [0x27] = 0xaa,
11027 { {0x40, 0xdd88ee99 } },
11030 "LD_ABS word unaligned (addr & 3 == 1)",
11032 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
11033 BPF_STMT(BPF_RET | BPF_A, 0x0),
11037 [0x1c] = 0xaa, [0x1d] = 0x55,
11038 [0x1e] = 0xbb, [0x1f] = 0x66,
11039 [0x20] = 0xcc, [0x21] = 0x77,
11040 [0x22] = 0xdd, [0x23] = 0x88,
11041 [0x24] = 0xee, [0x25] = 0x99,
11042 [0x26] = 0xff, [0x27] = 0xaa,
11044 { {0x40, 0x77dd88ee } },
11047 "LD_ABS word unaligned (addr & 3 == 3)",
11049 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
11050 BPF_STMT(BPF_RET | BPF_A, 0x0),
11054 [0x1c] = 0xaa, [0x1d] = 0x55,
11055 [0x1e] = 0xbb, [0x1f] = 0x66,
11056 [0x20] = 0xcc, [0x21] = 0x77,
11057 [0x22] = 0xdd, [0x23] = 0x88,
11058 [0x24] = 0xee, [0x25] = 0x99,
11059 [0x26] = 0xff, [0x27] = 0xaa,
11061 { {0x40, 0x88ee99ff } },
11064 "LD_ABS word positive offset, all ff",
11066 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
11067 BPF_STMT(BPF_RET | BPF_A, 0x0),
11070 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
11071 { {0x40, 0xffffffff } },
11074 "LD_ABS word positive offset, out of bounds",
11076 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
11077 BPF_STMT(BPF_RET | BPF_A, 0x0),
11080 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11084 "LD_ABS word negative offset, out of bounds load",
11086 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
11087 BPF_STMT(BPF_RET | BPF_A, 0x0),
11089 CLASSIC | FLAG_EXPECTED_FAIL,
11090 .expected_errcode = -EINVAL,
11093 "LD_ABS word negative offset, in bounds",
11095 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
11096 BPF_STMT(BPF_RET | BPF_A, 0x0),
11099 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11100 { {0x40, 0x25051982 }, },
11103 "LD_ABS word negative offset, out of bounds",
11105 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
11106 BPF_STMT(BPF_RET | BPF_A, 0x0),
11109 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11113 "LDX_MSH standalone, preserved A",
11115 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
11116 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
11117 BPF_STMT(BPF_RET | BPF_A, 0x0),
11120 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11121 { {0x40, 0xffeebbaa }, },
11124 "LDX_MSH standalone, preserved A 2",
11126 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
11127 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
11128 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
11129 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
11130 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
11131 BPF_STMT(BPF_RET | BPF_A, 0x0),
11134 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11135 { {0x40, 0x175e9d63 }, },
11138 "LDX_MSH standalone, test result 1",
11140 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
11141 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
11142 BPF_STMT(BPF_MISC | BPF_TXA, 0),
11143 BPF_STMT(BPF_RET | BPF_A, 0x0),
11146 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11147 { {0x40, 0x14 }, },
11150 "LDX_MSH standalone, test result 2",
11152 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
11153 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
11154 BPF_STMT(BPF_MISC | BPF_TXA, 0),
11155 BPF_STMT(BPF_RET | BPF_A, 0x0),
11158 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11159 { {0x40, 0x24 }, },
11162 "LDX_MSH standalone, negative offset",
11164 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
11165 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
11166 BPF_STMT(BPF_MISC | BPF_TXA, 0),
11167 BPF_STMT(BPF_RET | BPF_A, 0x0),
11170 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11174 "LDX_MSH standalone, negative offset 2",
11176 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
11177 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
11178 BPF_STMT(BPF_MISC | BPF_TXA, 0),
11179 BPF_STMT(BPF_RET | BPF_A, 0x0),
11182 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11183 { {0x40, 0x24 }, },
11186 "LDX_MSH standalone, out of bounds",
11188 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
11189 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
11190 BPF_STMT(BPF_MISC | BPF_TXA, 0),
11191 BPF_STMT(BPF_RET | BPF_A, 0x0),
11194 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
11198 * verify that the interpreter or JIT correctly sets A and X
11209 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
11210 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
11211 BPF_STMT(BPF_RET | BPF_A, 0x0),
11213 CLASSIC | FLAG_NO_DATA,
11224 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
11225 BPF_STMT(BPF_RET | BPF_A, 0x0),
11227 CLASSIC | FLAG_NO_DATA,
11239 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
11240 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
11241 BPF_STMT(BPF_RET | BPF_A, 0x0),
11243 CLASSIC | FLAG_NO_DATA,
11254 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
11255 BPF_STMT(BPF_RET | BPF_A, 0x0),
11257 CLASSIC | FLAG_NO_DATA,
11269 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
11270 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
11271 BPF_STMT(BPF_RET | BPF_A, 0x0),
11273 CLASSIC | FLAG_NO_DATA,
11284 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
11285 BPF_STMT(BPF_RET | BPF_A, 0x0),
11287 CLASSIC | FLAG_NO_DATA,
11296 * A = A / X ; this halt the filter execution if X is 0
11299 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
11300 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
11301 BPF_STMT(BPF_RET | BPF_K, 0x42),
11303 CLASSIC | FLAG_NO_DATA,
11314 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
11315 BPF_STMT(BPF_RET | BPF_A, 0x0),
11317 CLASSIC | FLAG_NO_DATA,
11326 * A = A mod X ; this halt the filter execution if X is 0
11329 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
11330 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
11331 BPF_STMT(BPF_RET | BPF_K, 0x42),
11333 CLASSIC | FLAG_NO_DATA,
11344 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
11345 BPF_STMT(BPF_RET | BPF_A, 0x0),
11347 CLASSIC | FLAG_NO_DATA,
11352 "JMP EQ default A",
11359 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
11360 BPF_STMT(BPF_RET | BPF_K, 0x42),
11361 BPF_STMT(BPF_RET | BPF_K, 0x66),
11363 CLASSIC | FLAG_NO_DATA,
11368 "JMP EQ default X",
11376 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
11377 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
11378 BPF_STMT(BPF_RET | BPF_K, 0x42),
11379 BPF_STMT(BPF_RET | BPF_K, 0x66),
11381 CLASSIC | FLAG_NO_DATA,
11385 /* Checking interpreter vs JIT wrt signed extended imms. */
11387 "JNE signed compare, test 1",
11389 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
11390 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
11391 BPF_MOV64_REG(R2, R1),
11392 BPF_ALU64_REG(BPF_AND, R2, R3),
11393 BPF_ALU32_IMM(BPF_MOV, R0, 1),
11394 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
11395 BPF_ALU32_IMM(BPF_MOV, R0, 2),
11403 "JNE signed compare, test 2",
11405 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
11406 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
11407 BPF_MOV64_REG(R2, R1),
11408 BPF_ALU64_REG(BPF_AND, R2, R3),
11409 BPF_ALU32_IMM(BPF_MOV, R0, 1),
11410 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
11411 BPF_ALU32_IMM(BPF_MOV, R0, 2),
11419 "JNE signed compare, test 3",
11421 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
11422 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
11423 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
11424 BPF_MOV64_REG(R2, R1),
11425 BPF_ALU64_REG(BPF_AND, R2, R3),
11426 BPF_ALU32_IMM(BPF_MOV, R0, 1),
11427 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
11428 BPF_ALU32_IMM(BPF_MOV, R0, 2),
11436 "JNE signed compare, test 4",
11438 BPF_LD_IMM64(R1, -17104896),
11439 BPF_ALU32_IMM(BPF_MOV, R0, 1),
11440 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
11441 BPF_ALU32_IMM(BPF_MOV, R0, 2),
11449 "JNE signed compare, test 5",
11451 BPF_LD_IMM64(R1, 0xfefb0000),
11452 BPF_ALU32_IMM(BPF_MOV, R0, 1),
11453 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
11454 BPF_ALU32_IMM(BPF_MOV, R0, 2),
11462 "JNE signed compare, test 6",
11464 BPF_LD_IMM64(R1, 0x7efb0000),
11465 BPF_ALU32_IMM(BPF_MOV, R0, 1),
11466 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
11467 BPF_ALU32_IMM(BPF_MOV, R0, 2),
11475 "JNE signed compare, test 7",
11477 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
11478 BPF_STMT(BPF_MISC | BPF_TAX, 0),
11479 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
11480 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
11481 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
11482 BPF_STMT(BPF_RET | BPF_K, 1),
11483 BPF_STMT(BPF_RET | BPF_K, 2),
11485 CLASSIC | FLAG_NO_DATA,
11489 /* BPF_LDX_MEM with operand aliasing */
11491 "LDX_MEM_B: operand register aliasing",
11493 BPF_ST_MEM(BPF_B, R10, -8, 123),
11494 BPF_MOV64_REG(R0, R10),
11495 BPF_LDX_MEM(BPF_B, R0, R0, -8),
11504 "LDX_MEM_H: operand register aliasing",
11506 BPF_ST_MEM(BPF_H, R10, -8, 12345),
11507 BPF_MOV64_REG(R0, R10),
11508 BPF_LDX_MEM(BPF_H, R0, R0, -8),
11517 "LDX_MEM_W: operand register aliasing",
11519 BPF_ST_MEM(BPF_W, R10, -8, 123456789),
11520 BPF_MOV64_REG(R0, R10),
11521 BPF_LDX_MEM(BPF_W, R0, R0, -8),
11526 { { 0, 123456789 } },
11530 "LDX_MEM_DW: operand register aliasing",
11532 BPF_LD_IMM64(R1, 0x123456789abcdefULL),
11533 BPF_STX_MEM(BPF_DW, R10, R1, -8),
11534 BPF_MOV64_REG(R0, R10),
11535 BPF_LDX_MEM(BPF_DW, R0, R0, -8),
11536 BPF_ALU64_REG(BPF_SUB, R0, R1),
11537 BPF_MOV64_REG(R1, R0),
11538 BPF_ALU64_IMM(BPF_RSH, R1, 32),
11539 BPF_ALU64_REG(BPF_OR, R0, R1),
11548 * Register (non-)clobbering tests for the case where a JIT implements
11549 * complex ALU or ATOMIC operations via function calls. If so, the
11550 * function call must be transparent to the eBPF registers. The JIT
11551 * must therefore save and restore relevant registers across the call.
11552 * The following tests check that the eBPF registers retain their
11553 * values after such an operation. Mainly intended for complex ALU
11554 * and atomic operation, but we run it for all. You never know...
11556 * Note that each operations should be tested twice with different
11557 * destinations, to check preservation for all registers.
11559 #define BPF_TEST_CLOBBER_ALU(alu, op, dst, src) \
11561 #alu "_" #op " to " #dst ": no clobbering", \
11563 BPF_ALU64_IMM(BPF_MOV, R0, R0), \
11564 BPF_ALU64_IMM(BPF_MOV, R1, R1), \
11565 BPF_ALU64_IMM(BPF_MOV, R2, R2), \
11566 BPF_ALU64_IMM(BPF_MOV, R3, R3), \
11567 BPF_ALU64_IMM(BPF_MOV, R4, R4), \
11568 BPF_ALU64_IMM(BPF_MOV, R5, R5), \
11569 BPF_ALU64_IMM(BPF_MOV, R6, R6), \
11570 BPF_ALU64_IMM(BPF_MOV, R7, R7), \
11571 BPF_ALU64_IMM(BPF_MOV, R8, R8), \
11572 BPF_ALU64_IMM(BPF_MOV, R9, R9), \
11573 BPF_##alu(BPF_ ##op, dst, src), \
11574 BPF_ALU32_IMM(BPF_MOV, dst, dst), \
11575 BPF_JMP_IMM(BPF_JNE, R0, R0, 10), \
11576 BPF_JMP_IMM(BPF_JNE, R1, R1, 9), \
11577 BPF_JMP_IMM(BPF_JNE, R2, R2, 8), \
11578 BPF_JMP_IMM(BPF_JNE, R3, R3, 7), \
11579 BPF_JMP_IMM(BPF_JNE, R4, R4, 6), \
11580 BPF_JMP_IMM(BPF_JNE, R5, R5, 5), \
11581 BPF_JMP_IMM(BPF_JNE, R6, R6, 4), \
11582 BPF_JMP_IMM(BPF_JNE, R7, R7, 3), \
11583 BPF_JMP_IMM(BPF_JNE, R8, R8, 2), \
11584 BPF_JMP_IMM(BPF_JNE, R9, R9, 1), \
11585 BPF_ALU64_IMM(BPF_MOV, R0, 1), \
11592 /* ALU64 operations, register clobbering */
11593 BPF_TEST_CLOBBER_ALU(ALU64_IMM, AND, R8, 123456789),
11594 BPF_TEST_CLOBBER_ALU(ALU64_IMM, AND, R9, 123456789),
11595 BPF_TEST_CLOBBER_ALU(ALU64_IMM, OR, R8, 123456789),
11596 BPF_TEST_CLOBBER_ALU(ALU64_IMM, OR, R9, 123456789),
11597 BPF_TEST_CLOBBER_ALU(ALU64_IMM, XOR, R8, 123456789),
11598 BPF_TEST_CLOBBER_ALU(ALU64_IMM, XOR, R9, 123456789),
11599 BPF_TEST_CLOBBER_ALU(ALU64_IMM, LSH, R8, 12),
11600 BPF_TEST_CLOBBER_ALU(ALU64_IMM, LSH, R9, 12),
11601 BPF_TEST_CLOBBER_ALU(ALU64_IMM, RSH, R8, 12),
11602 BPF_TEST_CLOBBER_ALU(ALU64_IMM, RSH, R9, 12),
11603 BPF_TEST_CLOBBER_ALU(ALU64_IMM, ARSH, R8, 12),
11604 BPF_TEST_CLOBBER_ALU(ALU64_IMM, ARSH, R9, 12),
11605 BPF_TEST_CLOBBER_ALU(ALU64_IMM, ADD, R8, 123456789),
11606 BPF_TEST_CLOBBER_ALU(ALU64_IMM, ADD, R9, 123456789),
11607 BPF_TEST_CLOBBER_ALU(ALU64_IMM, SUB, R8, 123456789),
11608 BPF_TEST_CLOBBER_ALU(ALU64_IMM, SUB, R9, 123456789),
11609 BPF_TEST_CLOBBER_ALU(ALU64_IMM, MUL, R8, 123456789),
11610 BPF_TEST_CLOBBER_ALU(ALU64_IMM, MUL, R9, 123456789),
11611 BPF_TEST_CLOBBER_ALU(ALU64_IMM, DIV, R8, 123456789),
11612 BPF_TEST_CLOBBER_ALU(ALU64_IMM, DIV, R9, 123456789),
11613 BPF_TEST_CLOBBER_ALU(ALU64_IMM, MOD, R8, 123456789),
11614 BPF_TEST_CLOBBER_ALU(ALU64_IMM, MOD, R9, 123456789),
11615 /* ALU32 immediate operations, register clobbering */
11616 BPF_TEST_CLOBBER_ALU(ALU32_IMM, AND, R8, 123456789),
11617 BPF_TEST_CLOBBER_ALU(ALU32_IMM, AND, R9, 123456789),
11618 BPF_TEST_CLOBBER_ALU(ALU32_IMM, OR, R8, 123456789),
11619 BPF_TEST_CLOBBER_ALU(ALU32_IMM, OR, R9, 123456789),
11620 BPF_TEST_CLOBBER_ALU(ALU32_IMM, XOR, R8, 123456789),
11621 BPF_TEST_CLOBBER_ALU(ALU32_IMM, XOR, R9, 123456789),
11622 BPF_TEST_CLOBBER_ALU(ALU32_IMM, LSH, R8, 12),
11623 BPF_TEST_CLOBBER_ALU(ALU32_IMM, LSH, R9, 12),
11624 BPF_TEST_CLOBBER_ALU(ALU32_IMM, RSH, R8, 12),
11625 BPF_TEST_CLOBBER_ALU(ALU32_IMM, RSH, R9, 12),
11626 BPF_TEST_CLOBBER_ALU(ALU32_IMM, ARSH, R8, 12),
11627 BPF_TEST_CLOBBER_ALU(ALU32_IMM, ARSH, R9, 12),
11628 BPF_TEST_CLOBBER_ALU(ALU32_IMM, ADD, R8, 123456789),
11629 BPF_TEST_CLOBBER_ALU(ALU32_IMM, ADD, R9, 123456789),
11630 BPF_TEST_CLOBBER_ALU(ALU32_IMM, SUB, R8, 123456789),
11631 BPF_TEST_CLOBBER_ALU(ALU32_IMM, SUB, R9, 123456789),
11632 BPF_TEST_CLOBBER_ALU(ALU32_IMM, MUL, R8, 123456789),
11633 BPF_TEST_CLOBBER_ALU(ALU32_IMM, MUL, R9, 123456789),
11634 BPF_TEST_CLOBBER_ALU(ALU32_IMM, DIV, R8, 123456789),
11635 BPF_TEST_CLOBBER_ALU(ALU32_IMM, DIV, R9, 123456789),
11636 BPF_TEST_CLOBBER_ALU(ALU32_IMM, MOD, R8, 123456789),
11637 BPF_TEST_CLOBBER_ALU(ALU32_IMM, MOD, R9, 123456789),
11638 /* ALU64 register operations, register clobbering */
11639 BPF_TEST_CLOBBER_ALU(ALU64_REG, AND, R8, R1),
11640 BPF_TEST_CLOBBER_ALU(ALU64_REG, AND, R9, R1),
11641 BPF_TEST_CLOBBER_ALU(ALU64_REG, OR, R8, R1),
11642 BPF_TEST_CLOBBER_ALU(ALU64_REG, OR, R9, R1),
11643 BPF_TEST_CLOBBER_ALU(ALU64_REG, XOR, R8, R1),
11644 BPF_TEST_CLOBBER_ALU(ALU64_REG, XOR, R9, R1),
11645 BPF_TEST_CLOBBER_ALU(ALU64_REG, LSH, R8, R1),
11646 BPF_TEST_CLOBBER_ALU(ALU64_REG, LSH, R9, R1),
11647 BPF_TEST_CLOBBER_ALU(ALU64_REG, RSH, R8, R1),
11648 BPF_TEST_CLOBBER_ALU(ALU64_REG, RSH, R9, R1),
11649 BPF_TEST_CLOBBER_ALU(ALU64_REG, ARSH, R8, R1),
11650 BPF_TEST_CLOBBER_ALU(ALU64_REG, ARSH, R9, R1),
11651 BPF_TEST_CLOBBER_ALU(ALU64_REG, ADD, R8, R1),
11652 BPF_TEST_CLOBBER_ALU(ALU64_REG, ADD, R9, R1),
11653 BPF_TEST_CLOBBER_ALU(ALU64_REG, SUB, R8, R1),
11654 BPF_TEST_CLOBBER_ALU(ALU64_REG, SUB, R9, R1),
11655 BPF_TEST_CLOBBER_ALU(ALU64_REG, MUL, R8, R1),
11656 BPF_TEST_CLOBBER_ALU(ALU64_REG, MUL, R9, R1),
11657 BPF_TEST_CLOBBER_ALU(ALU64_REG, DIV, R8, R1),
11658 BPF_TEST_CLOBBER_ALU(ALU64_REG, DIV, R9, R1),
11659 BPF_TEST_CLOBBER_ALU(ALU64_REG, MOD, R8, R1),
11660 BPF_TEST_CLOBBER_ALU(ALU64_REG, MOD, R9, R1),
11661 /* ALU32 register operations, register clobbering */
11662 BPF_TEST_CLOBBER_ALU(ALU32_REG, AND, R8, R1),
11663 BPF_TEST_CLOBBER_ALU(ALU32_REG, AND, R9, R1),
11664 BPF_TEST_CLOBBER_ALU(ALU32_REG, OR, R8, R1),
11665 BPF_TEST_CLOBBER_ALU(ALU32_REG, OR, R9, R1),
11666 BPF_TEST_CLOBBER_ALU(ALU32_REG, XOR, R8, R1),
11667 BPF_TEST_CLOBBER_ALU(ALU32_REG, XOR, R9, R1),
11668 BPF_TEST_CLOBBER_ALU(ALU32_REG, LSH, R8, R1),
11669 BPF_TEST_CLOBBER_ALU(ALU32_REG, LSH, R9, R1),
11670 BPF_TEST_CLOBBER_ALU(ALU32_REG, RSH, R8, R1),
11671 BPF_TEST_CLOBBER_ALU(ALU32_REG, RSH, R9, R1),
11672 BPF_TEST_CLOBBER_ALU(ALU32_REG, ARSH, R8, R1),
11673 BPF_TEST_CLOBBER_ALU(ALU32_REG, ARSH, R9, R1),
11674 BPF_TEST_CLOBBER_ALU(ALU32_REG, ADD, R8, R1),
11675 BPF_TEST_CLOBBER_ALU(ALU32_REG, ADD, R9, R1),
11676 BPF_TEST_CLOBBER_ALU(ALU32_REG, SUB, R8, R1),
11677 BPF_TEST_CLOBBER_ALU(ALU32_REG, SUB, R9, R1),
11678 BPF_TEST_CLOBBER_ALU(ALU32_REG, MUL, R8, R1),
11679 BPF_TEST_CLOBBER_ALU(ALU32_REG, MUL, R9, R1),
11680 BPF_TEST_CLOBBER_ALU(ALU32_REG, DIV, R8, R1),
11681 BPF_TEST_CLOBBER_ALU(ALU32_REG, DIV, R9, R1),
11682 BPF_TEST_CLOBBER_ALU(ALU32_REG, MOD, R8, R1),
11683 BPF_TEST_CLOBBER_ALU(ALU32_REG, MOD, R9, R1),
11684 #undef BPF_TEST_CLOBBER_ALU
11685 #define BPF_TEST_CLOBBER_ATOMIC(width, op) \
11687 "Atomic_" #width " " #op ": no clobbering", \
11689 BPF_ALU64_IMM(BPF_MOV, R0, 0), \
11690 BPF_ALU64_IMM(BPF_MOV, R1, 1), \
11691 BPF_ALU64_IMM(BPF_MOV, R2, 2), \
11692 BPF_ALU64_IMM(BPF_MOV, R3, 3), \
11693 BPF_ALU64_IMM(BPF_MOV, R4, 4), \
11694 BPF_ALU64_IMM(BPF_MOV, R5, 5), \
11695 BPF_ALU64_IMM(BPF_MOV, R6, 6), \
11696 BPF_ALU64_IMM(BPF_MOV, R7, 7), \
11697 BPF_ALU64_IMM(BPF_MOV, R8, 8), \
11698 BPF_ALU64_IMM(BPF_MOV, R9, 9), \
11699 BPF_ST_MEM(width, R10, -8, \
11700 (op) == BPF_CMPXCHG ? 0 : \
11701 (op) & BPF_FETCH ? 1 : 0), \
11702 BPF_ATOMIC_OP(width, op, R10, R1, -8), \
11703 BPF_JMP_IMM(BPF_JNE, R0, 0, 10), \
11704 BPF_JMP_IMM(BPF_JNE, R1, 1, 9), \
11705 BPF_JMP_IMM(BPF_JNE, R2, 2, 8), \
11706 BPF_JMP_IMM(BPF_JNE, R3, 3, 7), \
11707 BPF_JMP_IMM(BPF_JNE, R4, 4, 6), \
11708 BPF_JMP_IMM(BPF_JNE, R5, 5, 5), \
11709 BPF_JMP_IMM(BPF_JNE, R6, 6, 4), \
11710 BPF_JMP_IMM(BPF_JNE, R7, 7, 3), \
11711 BPF_JMP_IMM(BPF_JNE, R8, 8, 2), \
11712 BPF_JMP_IMM(BPF_JNE, R9, 9, 1), \
11713 BPF_ALU64_IMM(BPF_MOV, R0, 1), \
11719 .stack_depth = 8, \
11721 /* 64-bit atomic operations, register clobbering */
11722 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_ADD),
11723 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_AND),
11724 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_OR),
11725 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_XOR),
11726 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_ADD | BPF_FETCH),
11727 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_AND | BPF_FETCH),
11728 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_OR | BPF_FETCH),
11729 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_XOR | BPF_FETCH),
11730 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_XCHG),
11731 BPF_TEST_CLOBBER_ATOMIC(BPF_DW, BPF_CMPXCHG),
11732 /* 32-bit atomic operations, register clobbering */
11733 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_ADD),
11734 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_AND),
11735 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_OR),
11736 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_XOR),
11737 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_ADD | BPF_FETCH),
11738 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_AND | BPF_FETCH),
11739 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_OR | BPF_FETCH),
11740 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_XOR | BPF_FETCH),
11741 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_XCHG),
11742 BPF_TEST_CLOBBER_ATOMIC(BPF_W, BPF_CMPXCHG),
11743 #undef BPF_TEST_CLOBBER_ATOMIC
11744 /* Checking that ALU32 src is not zero extended in place */
11745 #define BPF_ALU32_SRC_ZEXT(op) \
11747 "ALU32_" #op "_X: src preserved in zext", \
11749 BPF_LD_IMM64(R1, 0x0123456789acbdefULL),\
11750 BPF_LD_IMM64(R2, 0xfedcba9876543210ULL),\
11751 BPF_ALU64_REG(BPF_MOV, R0, R1), \
11752 BPF_ALU32_REG(BPF_##op, R2, R1), \
11753 BPF_ALU64_REG(BPF_SUB, R0, R1), \
11754 BPF_ALU64_REG(BPF_MOV, R1, R0), \
11755 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
11756 BPF_ALU64_REG(BPF_OR, R0, R1), \
11763 BPF_ALU32_SRC_ZEXT(MOV),
11764 BPF_ALU32_SRC_ZEXT(AND),
11765 BPF_ALU32_SRC_ZEXT(OR),
11766 BPF_ALU32_SRC_ZEXT(XOR),
11767 BPF_ALU32_SRC_ZEXT(ADD),
11768 BPF_ALU32_SRC_ZEXT(SUB),
11769 BPF_ALU32_SRC_ZEXT(MUL),
11770 BPF_ALU32_SRC_ZEXT(DIV),
11771 BPF_ALU32_SRC_ZEXT(MOD),
11772 #undef BPF_ALU32_SRC_ZEXT
11773 /* Checking that ATOMIC32 src is not zero extended in place */
11774 #define BPF_ATOMIC32_SRC_ZEXT(op) \
11776 "ATOMIC_W_" #op ": src preserved in zext", \
11778 BPF_LD_IMM64(R0, 0x0123456789acbdefULL), \
11779 BPF_ALU64_REG(BPF_MOV, R1, R0), \
11780 BPF_ST_MEM(BPF_W, R10, -4, 0), \
11781 BPF_ATOMIC_OP(BPF_W, BPF_##op, R10, R1, -4), \
11782 BPF_ALU64_REG(BPF_SUB, R0, R1), \
11783 BPF_ALU64_REG(BPF_MOV, R1, R0), \
11784 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
11785 BPF_ALU64_REG(BPF_OR, R0, R1), \
11791 .stack_depth = 8, \
11793 BPF_ATOMIC32_SRC_ZEXT(ADD),
11794 BPF_ATOMIC32_SRC_ZEXT(AND),
11795 BPF_ATOMIC32_SRC_ZEXT(OR),
11796 BPF_ATOMIC32_SRC_ZEXT(XOR),
11797 #undef BPF_ATOMIC32_SRC_ZEXT
11798 /* Checking that CMPXCHG32 src is not zero extended in place */
11800 "ATOMIC_W_CMPXCHG: src preserved in zext",
11802 BPF_LD_IMM64(R1, 0x0123456789acbdefULL),
11803 BPF_ALU64_REG(BPF_MOV, R2, R1),
11804 BPF_ALU64_REG(BPF_MOV, R0, 0),
11805 BPF_ST_MEM(BPF_W, R10, -4, 0),
11806 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R1, -4),
11807 BPF_ALU64_REG(BPF_SUB, R1, R2),
11808 BPF_ALU64_REG(BPF_MOV, R2, R1),
11809 BPF_ALU64_IMM(BPF_RSH, R2, 32),
11810 BPF_ALU64_REG(BPF_OR, R1, R2),
11811 BPF_ALU64_REG(BPF_MOV, R0, R1),
11819 /* Checking that JMP32 immediate src is not zero extended in place */
11820 #define BPF_JMP32_IMM_ZEXT(op) \
11822 "JMP32_" #op "_K: operand preserved in zext", \
11824 BPF_LD_IMM64(R0, 0x0123456789acbdefULL),\
11825 BPF_ALU64_REG(BPF_MOV, R1, R0), \
11826 BPF_JMP32_IMM(BPF_##op, R0, 1234, 1), \
11827 BPF_JMP_A(0), /* Nop */ \
11828 BPF_ALU64_REG(BPF_SUB, R0, R1), \
11829 BPF_ALU64_REG(BPF_MOV, R1, R0), \
11830 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
11831 BPF_ALU64_REG(BPF_OR, R0, R1), \
11838 BPF_JMP32_IMM_ZEXT(JEQ),
11839 BPF_JMP32_IMM_ZEXT(JNE),
11840 BPF_JMP32_IMM_ZEXT(JSET),
11841 BPF_JMP32_IMM_ZEXT(JGT),
11842 BPF_JMP32_IMM_ZEXT(JGE),
11843 BPF_JMP32_IMM_ZEXT(JLT),
11844 BPF_JMP32_IMM_ZEXT(JLE),
11845 BPF_JMP32_IMM_ZEXT(JSGT),
11846 BPF_JMP32_IMM_ZEXT(JSGE),
11847 BPF_JMP32_IMM_ZEXT(JSGT),
11848 BPF_JMP32_IMM_ZEXT(JSLT),
11849 BPF_JMP32_IMM_ZEXT(JSLE),
11850 #undef BPF_JMP2_IMM_ZEXT
11851 /* Checking that JMP32 dst & src are not zero extended in place */
11852 #define BPF_JMP32_REG_ZEXT(op) \
11854 "JMP32_" #op "_X: operands preserved in zext", \
11856 BPF_LD_IMM64(R0, 0x0123456789acbdefULL),\
11857 BPF_LD_IMM64(R1, 0xfedcba9876543210ULL),\
11858 BPF_ALU64_REG(BPF_MOV, R2, R0), \
11859 BPF_ALU64_REG(BPF_MOV, R3, R1), \
11860 BPF_JMP32_IMM(BPF_##op, R0, R1, 1), \
11861 BPF_JMP_A(0), /* Nop */ \
11862 BPF_ALU64_REG(BPF_SUB, R0, R2), \
11863 BPF_ALU64_REG(BPF_SUB, R1, R3), \
11864 BPF_ALU64_REG(BPF_OR, R0, R1), \
11865 BPF_ALU64_REG(BPF_MOV, R1, R0), \
11866 BPF_ALU64_IMM(BPF_RSH, R1, 32), \
11867 BPF_ALU64_REG(BPF_OR, R0, R1), \
11874 BPF_JMP32_REG_ZEXT(JEQ),
11875 BPF_JMP32_REG_ZEXT(JNE),
11876 BPF_JMP32_REG_ZEXT(JSET),
11877 BPF_JMP32_REG_ZEXT(JGT),
11878 BPF_JMP32_REG_ZEXT(JGE),
11879 BPF_JMP32_REG_ZEXT(JLT),
11880 BPF_JMP32_REG_ZEXT(JLE),
11881 BPF_JMP32_REG_ZEXT(JSGT),
11882 BPF_JMP32_REG_ZEXT(JSGE),
11883 BPF_JMP32_REG_ZEXT(JSGT),
11884 BPF_JMP32_REG_ZEXT(JSLT),
11885 BPF_JMP32_REG_ZEXT(JSLE),
11886 #undef BPF_JMP2_REG_ZEXT
11887 /* ALU64 K register combinations */
11889 "ALU64_MOV_K: registers",
11894 .fill_helper = bpf_fill_alu64_mov_imm_regs,
11897 "ALU64_AND_K: registers",
11902 .fill_helper = bpf_fill_alu64_and_imm_regs,
11905 "ALU64_OR_K: registers",
11910 .fill_helper = bpf_fill_alu64_or_imm_regs,
11913 "ALU64_XOR_K: registers",
11918 .fill_helper = bpf_fill_alu64_xor_imm_regs,
11921 "ALU64_LSH_K: registers",
11926 .fill_helper = bpf_fill_alu64_lsh_imm_regs,
11929 "ALU64_RSH_K: registers",
11934 .fill_helper = bpf_fill_alu64_rsh_imm_regs,
11937 "ALU64_ARSH_K: registers",
11942 .fill_helper = bpf_fill_alu64_arsh_imm_regs,
11945 "ALU64_ADD_K: registers",
11950 .fill_helper = bpf_fill_alu64_add_imm_regs,
11953 "ALU64_SUB_K: registers",
11958 .fill_helper = bpf_fill_alu64_sub_imm_regs,
11961 "ALU64_MUL_K: registers",
11966 .fill_helper = bpf_fill_alu64_mul_imm_regs,
11969 "ALU64_DIV_K: registers",
11974 .fill_helper = bpf_fill_alu64_div_imm_regs,
11977 "ALU64_MOD_K: registers",
11982 .fill_helper = bpf_fill_alu64_mod_imm_regs,
11984 /* ALU32 K registers */
11986 "ALU32_MOV_K: registers",
11991 .fill_helper = bpf_fill_alu32_mov_imm_regs,
11994 "ALU32_AND_K: registers",
11999 .fill_helper = bpf_fill_alu32_and_imm_regs,
12002 "ALU32_OR_K: registers",
12007 .fill_helper = bpf_fill_alu32_or_imm_regs,
12010 "ALU32_XOR_K: registers",
12015 .fill_helper = bpf_fill_alu32_xor_imm_regs,
12018 "ALU32_LSH_K: registers",
12023 .fill_helper = bpf_fill_alu32_lsh_imm_regs,
12026 "ALU32_RSH_K: registers",
12031 .fill_helper = bpf_fill_alu32_rsh_imm_regs,
12034 "ALU32_ARSH_K: registers",
12039 .fill_helper = bpf_fill_alu32_arsh_imm_regs,
12042 "ALU32_ADD_K: registers",
12047 .fill_helper = bpf_fill_alu32_add_imm_regs,
12050 "ALU32_SUB_K: registers",
12055 .fill_helper = bpf_fill_alu32_sub_imm_regs,
12058 "ALU32_MUL_K: registers",
12063 .fill_helper = bpf_fill_alu32_mul_imm_regs,
12066 "ALU32_DIV_K: registers",
12071 .fill_helper = bpf_fill_alu32_div_imm_regs,
12074 "ALU32_MOD_K: registers",
12079 .fill_helper = bpf_fill_alu32_mod_imm_regs,
12081 /* ALU64 X register combinations */
12083 "ALU64_MOV_X: register combinations",
12088 .fill_helper = bpf_fill_alu64_mov_reg_pairs,
12091 "ALU64_AND_X: register combinations",
12096 .fill_helper = bpf_fill_alu64_and_reg_pairs,
12099 "ALU64_OR_X: register combinations",
12104 .fill_helper = bpf_fill_alu64_or_reg_pairs,
12107 "ALU64_XOR_X: register combinations",
12112 .fill_helper = bpf_fill_alu64_xor_reg_pairs,
12115 "ALU64_LSH_X: register combinations",
12120 .fill_helper = bpf_fill_alu64_lsh_reg_pairs,
12123 "ALU64_RSH_X: register combinations",
12128 .fill_helper = bpf_fill_alu64_rsh_reg_pairs,
12131 "ALU64_ARSH_X: register combinations",
12136 .fill_helper = bpf_fill_alu64_arsh_reg_pairs,
12139 "ALU64_ADD_X: register combinations",
12144 .fill_helper = bpf_fill_alu64_add_reg_pairs,
12147 "ALU64_SUB_X: register combinations",
12152 .fill_helper = bpf_fill_alu64_sub_reg_pairs,
12155 "ALU64_MUL_X: register combinations",
12160 .fill_helper = bpf_fill_alu64_mul_reg_pairs,
12163 "ALU64_DIV_X: register combinations",
12168 .fill_helper = bpf_fill_alu64_div_reg_pairs,
12171 "ALU64_MOD_X: register combinations",
12176 .fill_helper = bpf_fill_alu64_mod_reg_pairs,
12178 /* ALU32 X register combinations */
12180 "ALU32_MOV_X: register combinations",
12185 .fill_helper = bpf_fill_alu32_mov_reg_pairs,
12188 "ALU32_AND_X: register combinations",
12193 .fill_helper = bpf_fill_alu32_and_reg_pairs,
12196 "ALU32_OR_X: register combinations",
12201 .fill_helper = bpf_fill_alu32_or_reg_pairs,
12204 "ALU32_XOR_X: register combinations",
12209 .fill_helper = bpf_fill_alu32_xor_reg_pairs,
12212 "ALU32_LSH_X: register combinations",
12217 .fill_helper = bpf_fill_alu32_lsh_reg_pairs,
12220 "ALU32_RSH_X: register combinations",
12225 .fill_helper = bpf_fill_alu32_rsh_reg_pairs,
12228 "ALU32_ARSH_X: register combinations",
12233 .fill_helper = bpf_fill_alu32_arsh_reg_pairs,
12236 "ALU32_ADD_X: register combinations",
12241 .fill_helper = bpf_fill_alu32_add_reg_pairs,
12244 "ALU32_SUB_X: register combinations",
12249 .fill_helper = bpf_fill_alu32_sub_reg_pairs,
12252 "ALU32_MUL_X: register combinations",
12257 .fill_helper = bpf_fill_alu32_mul_reg_pairs,
12260 "ALU32_DIV_X: register combinations",
12265 .fill_helper = bpf_fill_alu32_div_reg_pairs,
12268 "ALU32_MOD_X register combinations",
12273 .fill_helper = bpf_fill_alu32_mod_reg_pairs,
12275 /* Exhaustive test of ALU64 shift operations */
12277 "ALU64_LSH_K: all shift values",
12279 INTERNAL | FLAG_NO_DATA,
12282 .fill_helper = bpf_fill_alu64_lsh_imm,
12285 "ALU64_RSH_K: all shift values",
12287 INTERNAL | FLAG_NO_DATA,
12290 .fill_helper = bpf_fill_alu64_rsh_imm,
12293 "ALU64_ARSH_K: all shift values",
12295 INTERNAL | FLAG_NO_DATA,
12298 .fill_helper = bpf_fill_alu64_arsh_imm,
12301 "ALU64_LSH_X: all shift values",
12303 INTERNAL | FLAG_NO_DATA,
12306 .fill_helper = bpf_fill_alu64_lsh_reg,
12309 "ALU64_RSH_X: all shift values",
12311 INTERNAL | FLAG_NO_DATA,
12314 .fill_helper = bpf_fill_alu64_rsh_reg,
12317 "ALU64_ARSH_X: all shift values",
12319 INTERNAL | FLAG_NO_DATA,
12322 .fill_helper = bpf_fill_alu64_arsh_reg,
12324 /* Exhaustive test of ALU32 shift operations */
12326 "ALU32_LSH_K: all shift values",
12328 INTERNAL | FLAG_NO_DATA,
12331 .fill_helper = bpf_fill_alu32_lsh_imm,
12334 "ALU32_RSH_K: all shift values",
12336 INTERNAL | FLAG_NO_DATA,
12339 .fill_helper = bpf_fill_alu32_rsh_imm,
12342 "ALU32_ARSH_K: all shift values",
12344 INTERNAL | FLAG_NO_DATA,
12347 .fill_helper = bpf_fill_alu32_arsh_imm,
12350 "ALU32_LSH_X: all shift values",
12352 INTERNAL | FLAG_NO_DATA,
12355 .fill_helper = bpf_fill_alu32_lsh_reg,
12358 "ALU32_RSH_X: all shift values",
12360 INTERNAL | FLAG_NO_DATA,
12363 .fill_helper = bpf_fill_alu32_rsh_reg,
12366 "ALU32_ARSH_X: all shift values",
12368 INTERNAL | FLAG_NO_DATA,
12371 .fill_helper = bpf_fill_alu32_arsh_reg,
12374 * Exhaustive test of ALU64 shift operations when
12375 * source and destination register are the same.
12378 "ALU64_LSH_X: all shift values with the same register",
12380 INTERNAL | FLAG_NO_DATA,
12383 .fill_helper = bpf_fill_alu64_lsh_same_reg,
12386 "ALU64_RSH_X: all shift values with the same register",
12388 INTERNAL | FLAG_NO_DATA,
12391 .fill_helper = bpf_fill_alu64_rsh_same_reg,
12394 "ALU64_ARSH_X: all shift values with the same register",
12396 INTERNAL | FLAG_NO_DATA,
12399 .fill_helper = bpf_fill_alu64_arsh_same_reg,
12402 * Exhaustive test of ALU32 shift operations when
12403 * source and destination register are the same.
12406 "ALU32_LSH_X: all shift values with the same register",
12408 INTERNAL | FLAG_NO_DATA,
12411 .fill_helper = bpf_fill_alu32_lsh_same_reg,
12414 "ALU32_RSH_X: all shift values with the same register",
12416 INTERNAL | FLAG_NO_DATA,
12419 .fill_helper = bpf_fill_alu32_rsh_same_reg,
12422 "ALU32_ARSH_X: all shift values with the same register",
12424 INTERNAL | FLAG_NO_DATA,
12427 .fill_helper = bpf_fill_alu32_arsh_same_reg,
12429 /* ALU64 immediate magnitudes */
12431 "ALU64_MOV_K: all immediate value magnitudes",
12433 INTERNAL | FLAG_NO_DATA,
12436 .fill_helper = bpf_fill_alu64_mov_imm,
12437 .nr_testruns = NR_PATTERN_RUNS,
12440 "ALU64_AND_K: all immediate value magnitudes",
12442 INTERNAL | FLAG_NO_DATA,
12445 .fill_helper = bpf_fill_alu64_and_imm,
12446 .nr_testruns = NR_PATTERN_RUNS,
12449 "ALU64_OR_K: all immediate value magnitudes",
12451 INTERNAL | FLAG_NO_DATA,
12454 .fill_helper = bpf_fill_alu64_or_imm,
12455 .nr_testruns = NR_PATTERN_RUNS,
12458 "ALU64_XOR_K: all immediate value magnitudes",
12460 INTERNAL | FLAG_NO_DATA,
12463 .fill_helper = bpf_fill_alu64_xor_imm,
12464 .nr_testruns = NR_PATTERN_RUNS,
12467 "ALU64_ADD_K: all immediate value magnitudes",
12469 INTERNAL | FLAG_NO_DATA,
12472 .fill_helper = bpf_fill_alu64_add_imm,
12473 .nr_testruns = NR_PATTERN_RUNS,
12476 "ALU64_SUB_K: all immediate value magnitudes",
12478 INTERNAL | FLAG_NO_DATA,
12481 .fill_helper = bpf_fill_alu64_sub_imm,
12482 .nr_testruns = NR_PATTERN_RUNS,
12485 "ALU64_MUL_K: all immediate value magnitudes",
12487 INTERNAL | FLAG_NO_DATA,
12490 .fill_helper = bpf_fill_alu64_mul_imm,
12491 .nr_testruns = NR_PATTERN_RUNS,
12494 "ALU64_DIV_K: all immediate value magnitudes",
12496 INTERNAL | FLAG_NO_DATA,
12499 .fill_helper = bpf_fill_alu64_div_imm,
12500 .nr_testruns = NR_PATTERN_RUNS,
12503 "ALU64_MOD_K: all immediate value magnitudes",
12505 INTERNAL | FLAG_NO_DATA,
12508 .fill_helper = bpf_fill_alu64_mod_imm,
12509 .nr_testruns = NR_PATTERN_RUNS,
12511 /* ALU32 immediate magnitudes */
12513 "ALU32_MOV_K: all immediate value magnitudes",
12515 INTERNAL | FLAG_NO_DATA,
12518 .fill_helper = bpf_fill_alu32_mov_imm,
12519 .nr_testruns = NR_PATTERN_RUNS,
12522 "ALU32_AND_K: all immediate value magnitudes",
12524 INTERNAL | FLAG_NO_DATA,
12527 .fill_helper = bpf_fill_alu32_and_imm,
12528 .nr_testruns = NR_PATTERN_RUNS,
12531 "ALU32_OR_K: all immediate value magnitudes",
12533 INTERNAL | FLAG_NO_DATA,
12536 .fill_helper = bpf_fill_alu32_or_imm,
12537 .nr_testruns = NR_PATTERN_RUNS,
12540 "ALU32_XOR_K: all immediate value magnitudes",
12542 INTERNAL | FLAG_NO_DATA,
12545 .fill_helper = bpf_fill_alu32_xor_imm,
12546 .nr_testruns = NR_PATTERN_RUNS,
12549 "ALU32_ADD_K: all immediate value magnitudes",
12551 INTERNAL | FLAG_NO_DATA,
12554 .fill_helper = bpf_fill_alu32_add_imm,
12555 .nr_testruns = NR_PATTERN_RUNS,
12558 "ALU32_SUB_K: all immediate value magnitudes",
12560 INTERNAL | FLAG_NO_DATA,
12563 .fill_helper = bpf_fill_alu32_sub_imm,
12564 .nr_testruns = NR_PATTERN_RUNS,
12567 "ALU32_MUL_K: all immediate value magnitudes",
12569 INTERNAL | FLAG_NO_DATA,
12572 .fill_helper = bpf_fill_alu32_mul_imm,
12573 .nr_testruns = NR_PATTERN_RUNS,
12576 "ALU32_DIV_K: all immediate value magnitudes",
12578 INTERNAL | FLAG_NO_DATA,
12581 .fill_helper = bpf_fill_alu32_div_imm,
12582 .nr_testruns = NR_PATTERN_RUNS,
12585 "ALU32_MOD_K: all immediate value magnitudes",
12587 INTERNAL | FLAG_NO_DATA,
12590 .fill_helper = bpf_fill_alu32_mod_imm,
12591 .nr_testruns = NR_PATTERN_RUNS,
12593 /* ALU64 register magnitudes */
12595 "ALU64_MOV_X: all register value magnitudes",
12597 INTERNAL | FLAG_NO_DATA,
12600 .fill_helper = bpf_fill_alu64_mov_reg,
12601 .nr_testruns = NR_PATTERN_RUNS,
12604 "ALU64_AND_X: all register value magnitudes",
12606 INTERNAL | FLAG_NO_DATA,
12609 .fill_helper = bpf_fill_alu64_and_reg,
12610 .nr_testruns = NR_PATTERN_RUNS,
12613 "ALU64_OR_X: all register value magnitudes",
12615 INTERNAL | FLAG_NO_DATA,
12618 .fill_helper = bpf_fill_alu64_or_reg,
12619 .nr_testruns = NR_PATTERN_RUNS,
12622 "ALU64_XOR_X: all register value magnitudes",
12624 INTERNAL | FLAG_NO_DATA,
12627 .fill_helper = bpf_fill_alu64_xor_reg,
12628 .nr_testruns = NR_PATTERN_RUNS,
12631 "ALU64_ADD_X: all register value magnitudes",
12633 INTERNAL | FLAG_NO_DATA,
12636 .fill_helper = bpf_fill_alu64_add_reg,
12637 .nr_testruns = NR_PATTERN_RUNS,
12640 "ALU64_SUB_X: all register value magnitudes",
12642 INTERNAL | FLAG_NO_DATA,
12645 .fill_helper = bpf_fill_alu64_sub_reg,
12646 .nr_testruns = NR_PATTERN_RUNS,
12649 "ALU64_MUL_X: all register value magnitudes",
12651 INTERNAL | FLAG_NO_DATA,
12654 .fill_helper = bpf_fill_alu64_mul_reg,
12655 .nr_testruns = NR_PATTERN_RUNS,
12658 "ALU64_DIV_X: all register value magnitudes",
12660 INTERNAL | FLAG_NO_DATA,
12663 .fill_helper = bpf_fill_alu64_div_reg,
12664 .nr_testruns = NR_PATTERN_RUNS,
12667 "ALU64_MOD_X: all register value magnitudes",
12669 INTERNAL | FLAG_NO_DATA,
12672 .fill_helper = bpf_fill_alu64_mod_reg,
12673 .nr_testruns = NR_PATTERN_RUNS,
12675 /* ALU32 register magnitudes */
12677 "ALU32_MOV_X: all register value magnitudes",
12679 INTERNAL | FLAG_NO_DATA,
12682 .fill_helper = bpf_fill_alu32_mov_reg,
12683 .nr_testruns = NR_PATTERN_RUNS,
12686 "ALU32_AND_X: all register value magnitudes",
12688 INTERNAL | FLAG_NO_DATA,
12691 .fill_helper = bpf_fill_alu32_and_reg,
12692 .nr_testruns = NR_PATTERN_RUNS,
12695 "ALU32_OR_X: all register value magnitudes",
12697 INTERNAL | FLAG_NO_DATA,
12700 .fill_helper = bpf_fill_alu32_or_reg,
12701 .nr_testruns = NR_PATTERN_RUNS,
12704 "ALU32_XOR_X: all register value magnitudes",
12706 INTERNAL | FLAG_NO_DATA,
12709 .fill_helper = bpf_fill_alu32_xor_reg,
12710 .nr_testruns = NR_PATTERN_RUNS,
12713 "ALU32_ADD_X: all register value magnitudes",
12715 INTERNAL | FLAG_NO_DATA,
12718 .fill_helper = bpf_fill_alu32_add_reg,
12719 .nr_testruns = NR_PATTERN_RUNS,
12722 "ALU32_SUB_X: all register value magnitudes",
12724 INTERNAL | FLAG_NO_DATA,
12727 .fill_helper = bpf_fill_alu32_sub_reg,
12728 .nr_testruns = NR_PATTERN_RUNS,
12731 "ALU32_MUL_X: all register value magnitudes",
12733 INTERNAL | FLAG_NO_DATA,
12736 .fill_helper = bpf_fill_alu32_mul_reg,
12737 .nr_testruns = NR_PATTERN_RUNS,
12740 "ALU32_DIV_X: all register value magnitudes",
12742 INTERNAL | FLAG_NO_DATA,
12745 .fill_helper = bpf_fill_alu32_div_reg,
12746 .nr_testruns = NR_PATTERN_RUNS,
12749 "ALU32_MOD_X: all register value magnitudes",
12751 INTERNAL | FLAG_NO_DATA,
12754 .fill_helper = bpf_fill_alu32_mod_reg,
12755 .nr_testruns = NR_PATTERN_RUNS,
12757 /* LD_IMM64 immediate magnitudes and byte patterns */
12759 "LD_IMM64: all immediate value magnitudes",
12761 INTERNAL | FLAG_NO_DATA,
12764 .fill_helper = bpf_fill_ld_imm64_magn,
12767 "LD_IMM64: checker byte patterns",
12769 INTERNAL | FLAG_NO_DATA,
12772 .fill_helper = bpf_fill_ld_imm64_checker,
12775 "LD_IMM64: random positive and zero byte patterns",
12777 INTERNAL | FLAG_NO_DATA,
12780 .fill_helper = bpf_fill_ld_imm64_pos_zero,
12783 "LD_IMM64: random negative and zero byte patterns",
12785 INTERNAL | FLAG_NO_DATA,
12788 .fill_helper = bpf_fill_ld_imm64_neg_zero,
12791 "LD_IMM64: random positive and negative byte patterns",
12793 INTERNAL | FLAG_NO_DATA,
12796 .fill_helper = bpf_fill_ld_imm64_pos_neg,
12798 /* 64-bit ATOMIC register combinations */
12800 "ATOMIC_DW_ADD: register combinations",
12805 .fill_helper = bpf_fill_atomic64_add_reg_pairs,
12809 "ATOMIC_DW_AND: register combinations",
12814 .fill_helper = bpf_fill_atomic64_and_reg_pairs,
12818 "ATOMIC_DW_OR: register combinations",
12823 .fill_helper = bpf_fill_atomic64_or_reg_pairs,
12827 "ATOMIC_DW_XOR: register combinations",
12832 .fill_helper = bpf_fill_atomic64_xor_reg_pairs,
12836 "ATOMIC_DW_ADD_FETCH: register combinations",
12841 .fill_helper = bpf_fill_atomic64_add_fetch_reg_pairs,
12845 "ATOMIC_DW_AND_FETCH: register combinations",
12850 .fill_helper = bpf_fill_atomic64_and_fetch_reg_pairs,
12854 "ATOMIC_DW_OR_FETCH: register combinations",
12859 .fill_helper = bpf_fill_atomic64_or_fetch_reg_pairs,
12863 "ATOMIC_DW_XOR_FETCH: register combinations",
12868 .fill_helper = bpf_fill_atomic64_xor_fetch_reg_pairs,
12872 "ATOMIC_DW_XCHG: register combinations",
12877 .fill_helper = bpf_fill_atomic64_xchg_reg_pairs,
12881 "ATOMIC_DW_CMPXCHG: register combinations",
12886 .fill_helper = bpf_fill_atomic64_cmpxchg_reg_pairs,
12889 /* 32-bit ATOMIC register combinations */
12891 "ATOMIC_W_ADD: register combinations",
12896 .fill_helper = bpf_fill_atomic32_add_reg_pairs,
12900 "ATOMIC_W_AND: register combinations",
12905 .fill_helper = bpf_fill_atomic32_and_reg_pairs,
12909 "ATOMIC_W_OR: register combinations",
12914 .fill_helper = bpf_fill_atomic32_or_reg_pairs,
12918 "ATOMIC_W_XOR: register combinations",
12923 .fill_helper = bpf_fill_atomic32_xor_reg_pairs,
12927 "ATOMIC_W_ADD_FETCH: register combinations",
12932 .fill_helper = bpf_fill_atomic32_add_fetch_reg_pairs,
12936 "ATOMIC_W_AND_FETCH: register combinations",
12941 .fill_helper = bpf_fill_atomic32_and_fetch_reg_pairs,
12945 "ATOMIC_W_OR_FETCH: register combinations",
12950 .fill_helper = bpf_fill_atomic32_or_fetch_reg_pairs,
12954 "ATOMIC_W_XOR_FETCH: register combinations",
12959 .fill_helper = bpf_fill_atomic32_xor_fetch_reg_pairs,
12963 "ATOMIC_W_XCHG: register combinations",
12968 .fill_helper = bpf_fill_atomic32_xchg_reg_pairs,
12972 "ATOMIC_W_CMPXCHG: register combinations",
12977 .fill_helper = bpf_fill_atomic32_cmpxchg_reg_pairs,
12980 /* 64-bit ATOMIC magnitudes */
12982 "ATOMIC_DW_ADD: all operand magnitudes",
12984 INTERNAL | FLAG_NO_DATA,
12987 .fill_helper = bpf_fill_atomic64_add,
12989 .nr_testruns = NR_PATTERN_RUNS,
12992 "ATOMIC_DW_AND: all operand magnitudes",
12994 INTERNAL | FLAG_NO_DATA,
12997 .fill_helper = bpf_fill_atomic64_and,
12999 .nr_testruns = NR_PATTERN_RUNS,
13002 "ATOMIC_DW_OR: all operand magnitudes",
13004 INTERNAL | FLAG_NO_DATA,
13007 .fill_helper = bpf_fill_atomic64_or,
13009 .nr_testruns = NR_PATTERN_RUNS,
13012 "ATOMIC_DW_XOR: all operand magnitudes",
13014 INTERNAL | FLAG_NO_DATA,
13017 .fill_helper = bpf_fill_atomic64_xor,
13019 .nr_testruns = NR_PATTERN_RUNS,
13022 "ATOMIC_DW_ADD_FETCH: all operand magnitudes",
13024 INTERNAL | FLAG_NO_DATA,
13027 .fill_helper = bpf_fill_atomic64_add_fetch,
13029 .nr_testruns = NR_PATTERN_RUNS,
13032 "ATOMIC_DW_AND_FETCH: all operand magnitudes",
13034 INTERNAL | FLAG_NO_DATA,
13037 .fill_helper = bpf_fill_atomic64_and_fetch,
13039 .nr_testruns = NR_PATTERN_RUNS,
13042 "ATOMIC_DW_OR_FETCH: all operand magnitudes",
13044 INTERNAL | FLAG_NO_DATA,
13047 .fill_helper = bpf_fill_atomic64_or_fetch,
13049 .nr_testruns = NR_PATTERN_RUNS,
13052 "ATOMIC_DW_XOR_FETCH: all operand magnitudes",
13054 INTERNAL | FLAG_NO_DATA,
13057 .fill_helper = bpf_fill_atomic64_xor_fetch,
13059 .nr_testruns = NR_PATTERN_RUNS,
13062 "ATOMIC_DW_XCHG: all operand magnitudes",
13064 INTERNAL | FLAG_NO_DATA,
13067 .fill_helper = bpf_fill_atomic64_xchg,
13069 .nr_testruns = NR_PATTERN_RUNS,
13072 "ATOMIC_DW_CMPXCHG: all operand magnitudes",
13074 INTERNAL | FLAG_NO_DATA,
13077 .fill_helper = bpf_fill_cmpxchg64,
13079 .nr_testruns = NR_PATTERN_RUNS,
13081 /* 64-bit atomic magnitudes */
13083 "ATOMIC_W_ADD: all operand magnitudes",
13085 INTERNAL | FLAG_NO_DATA,
13088 .fill_helper = bpf_fill_atomic32_add,
13090 .nr_testruns = NR_PATTERN_RUNS,
13093 "ATOMIC_W_AND: all operand magnitudes",
13095 INTERNAL | FLAG_NO_DATA,
13098 .fill_helper = bpf_fill_atomic32_and,
13100 .nr_testruns = NR_PATTERN_RUNS,
13103 "ATOMIC_W_OR: all operand magnitudes",
13105 INTERNAL | FLAG_NO_DATA,
13108 .fill_helper = bpf_fill_atomic32_or,
13110 .nr_testruns = NR_PATTERN_RUNS,
13113 "ATOMIC_W_XOR: all operand magnitudes",
13115 INTERNAL | FLAG_NO_DATA,
13118 .fill_helper = bpf_fill_atomic32_xor,
13120 .nr_testruns = NR_PATTERN_RUNS,
13123 "ATOMIC_W_ADD_FETCH: all operand magnitudes",
13125 INTERNAL | FLAG_NO_DATA,
13128 .fill_helper = bpf_fill_atomic32_add_fetch,
13130 .nr_testruns = NR_PATTERN_RUNS,
13133 "ATOMIC_W_AND_FETCH: all operand magnitudes",
13135 INTERNAL | FLAG_NO_DATA,
13138 .fill_helper = bpf_fill_atomic32_and_fetch,
13140 .nr_testruns = NR_PATTERN_RUNS,
13143 "ATOMIC_W_OR_FETCH: all operand magnitudes",
13145 INTERNAL | FLAG_NO_DATA,
13148 .fill_helper = bpf_fill_atomic32_or_fetch,
13150 .nr_testruns = NR_PATTERN_RUNS,
13153 "ATOMIC_W_XOR_FETCH: all operand magnitudes",
13155 INTERNAL | FLAG_NO_DATA,
13158 .fill_helper = bpf_fill_atomic32_xor_fetch,
13160 .nr_testruns = NR_PATTERN_RUNS,
13163 "ATOMIC_W_XCHG: all operand magnitudes",
13165 INTERNAL | FLAG_NO_DATA,
13168 .fill_helper = bpf_fill_atomic32_xchg,
13170 .nr_testruns = NR_PATTERN_RUNS,
13173 "ATOMIC_W_CMPXCHG: all operand magnitudes",
13175 INTERNAL | FLAG_NO_DATA,
13178 .fill_helper = bpf_fill_cmpxchg32,
13180 .nr_testruns = NR_PATTERN_RUNS,
13182 /* JMP immediate magnitudes */
13184 "JMP_JSET_K: all immediate value magnitudes",
13186 INTERNAL | FLAG_NO_DATA,
13189 .fill_helper = bpf_fill_jmp_jset_imm,
13190 .nr_testruns = NR_PATTERN_RUNS,
13193 "JMP_JEQ_K: all immediate value magnitudes",
13195 INTERNAL | FLAG_NO_DATA,
13198 .fill_helper = bpf_fill_jmp_jeq_imm,
13199 .nr_testruns = NR_PATTERN_RUNS,
13202 "JMP_JNE_K: all immediate value magnitudes",
13204 INTERNAL | FLAG_NO_DATA,
13207 .fill_helper = bpf_fill_jmp_jne_imm,
13208 .nr_testruns = NR_PATTERN_RUNS,
13211 "JMP_JGT_K: all immediate value magnitudes",
13213 INTERNAL | FLAG_NO_DATA,
13216 .fill_helper = bpf_fill_jmp_jgt_imm,
13217 .nr_testruns = NR_PATTERN_RUNS,
13220 "JMP_JGE_K: all immediate value magnitudes",
13222 INTERNAL | FLAG_NO_DATA,
13225 .fill_helper = bpf_fill_jmp_jge_imm,
13226 .nr_testruns = NR_PATTERN_RUNS,
13229 "JMP_JLT_K: all immediate value magnitudes",
13231 INTERNAL | FLAG_NO_DATA,
13234 .fill_helper = bpf_fill_jmp_jlt_imm,
13235 .nr_testruns = NR_PATTERN_RUNS,
13238 "JMP_JLE_K: all immediate value magnitudes",
13240 INTERNAL | FLAG_NO_DATA,
13243 .fill_helper = bpf_fill_jmp_jle_imm,
13244 .nr_testruns = NR_PATTERN_RUNS,
13247 "JMP_JSGT_K: all immediate value magnitudes",
13249 INTERNAL | FLAG_NO_DATA,
13252 .fill_helper = bpf_fill_jmp_jsgt_imm,
13253 .nr_testruns = NR_PATTERN_RUNS,
13256 "JMP_JSGE_K: all immediate value magnitudes",
13258 INTERNAL | FLAG_NO_DATA,
13261 .fill_helper = bpf_fill_jmp_jsge_imm,
13262 .nr_testruns = NR_PATTERN_RUNS,
13265 "JMP_JSLT_K: all immediate value magnitudes",
13267 INTERNAL | FLAG_NO_DATA,
13270 .fill_helper = bpf_fill_jmp_jslt_imm,
13271 .nr_testruns = NR_PATTERN_RUNS,
13274 "JMP_JSLE_K: all immediate value magnitudes",
13276 INTERNAL | FLAG_NO_DATA,
13279 .fill_helper = bpf_fill_jmp_jsle_imm,
13280 .nr_testruns = NR_PATTERN_RUNS,
13282 /* JMP register magnitudes */
13284 "JMP_JSET_X: all register value magnitudes",
13286 INTERNAL | FLAG_NO_DATA,
13289 .fill_helper = bpf_fill_jmp_jset_reg,
13290 .nr_testruns = NR_PATTERN_RUNS,
13293 "JMP_JEQ_X: all register value magnitudes",
13295 INTERNAL | FLAG_NO_DATA,
13298 .fill_helper = bpf_fill_jmp_jeq_reg,
13299 .nr_testruns = NR_PATTERN_RUNS,
13302 "JMP_JNE_X: all register value magnitudes",
13304 INTERNAL | FLAG_NO_DATA,
13307 .fill_helper = bpf_fill_jmp_jne_reg,
13308 .nr_testruns = NR_PATTERN_RUNS,
13311 "JMP_JGT_X: all register value magnitudes",
13313 INTERNAL | FLAG_NO_DATA,
13316 .fill_helper = bpf_fill_jmp_jgt_reg,
13317 .nr_testruns = NR_PATTERN_RUNS,
13320 "JMP_JGE_X: all register value magnitudes",
13322 INTERNAL | FLAG_NO_DATA,
13325 .fill_helper = bpf_fill_jmp_jge_reg,
13326 .nr_testruns = NR_PATTERN_RUNS,
13329 "JMP_JLT_X: all register value magnitudes",
13331 INTERNAL | FLAG_NO_DATA,
13334 .fill_helper = bpf_fill_jmp_jlt_reg,
13335 .nr_testruns = NR_PATTERN_RUNS,
13338 "JMP_JLE_X: all register value magnitudes",
13340 INTERNAL | FLAG_NO_DATA,
13343 .fill_helper = bpf_fill_jmp_jle_reg,
13344 .nr_testruns = NR_PATTERN_RUNS,
13347 "JMP_JSGT_X: all register value magnitudes",
13349 INTERNAL | FLAG_NO_DATA,
13352 .fill_helper = bpf_fill_jmp_jsgt_reg,
13353 .nr_testruns = NR_PATTERN_RUNS,
13356 "JMP_JSGE_X: all register value magnitudes",
13358 INTERNAL | FLAG_NO_DATA,
13361 .fill_helper = bpf_fill_jmp_jsge_reg,
13362 .nr_testruns = NR_PATTERN_RUNS,
13365 "JMP_JSLT_X: all register value magnitudes",
13367 INTERNAL | FLAG_NO_DATA,
13370 .fill_helper = bpf_fill_jmp_jslt_reg,
13371 .nr_testruns = NR_PATTERN_RUNS,
13374 "JMP_JSLE_X: all register value magnitudes",
13376 INTERNAL | FLAG_NO_DATA,
13379 .fill_helper = bpf_fill_jmp_jsle_reg,
13380 .nr_testruns = NR_PATTERN_RUNS,
13382 /* JMP32 immediate magnitudes */
13384 "JMP32_JSET_K: all immediate value magnitudes",
13386 INTERNAL | FLAG_NO_DATA,
13389 .fill_helper = bpf_fill_jmp32_jset_imm,
13390 .nr_testruns = NR_PATTERN_RUNS,
13393 "JMP32_JEQ_K: all immediate value magnitudes",
13395 INTERNAL | FLAG_NO_DATA,
13398 .fill_helper = bpf_fill_jmp32_jeq_imm,
13399 .nr_testruns = NR_PATTERN_RUNS,
13402 "JMP32_JNE_K: all immediate value magnitudes",
13404 INTERNAL | FLAG_NO_DATA,
13407 .fill_helper = bpf_fill_jmp32_jne_imm,
13408 .nr_testruns = NR_PATTERN_RUNS,
13411 "JMP32_JGT_K: all immediate value magnitudes",
13413 INTERNAL | FLAG_NO_DATA,
13416 .fill_helper = bpf_fill_jmp32_jgt_imm,
13417 .nr_testruns = NR_PATTERN_RUNS,
13420 "JMP32_JGE_K: all immediate value magnitudes",
13422 INTERNAL | FLAG_NO_DATA,
13425 .fill_helper = bpf_fill_jmp32_jge_imm,
13426 .nr_testruns = NR_PATTERN_RUNS,
13429 "JMP32_JLT_K: all immediate value magnitudes",
13431 INTERNAL | FLAG_NO_DATA,
13434 .fill_helper = bpf_fill_jmp32_jlt_imm,
13435 .nr_testruns = NR_PATTERN_RUNS,
13438 "JMP32_JLE_K: all immediate value magnitudes",
13440 INTERNAL | FLAG_NO_DATA,
13443 .fill_helper = bpf_fill_jmp32_jle_imm,
13444 .nr_testruns = NR_PATTERN_RUNS,
13447 "JMP32_JSGT_K: all immediate value magnitudes",
13449 INTERNAL | FLAG_NO_DATA,
13452 .fill_helper = bpf_fill_jmp32_jsgt_imm,
13453 .nr_testruns = NR_PATTERN_RUNS,
13456 "JMP32_JSGE_K: all immediate value magnitudes",
13458 INTERNAL | FLAG_NO_DATA,
13461 .fill_helper = bpf_fill_jmp32_jsge_imm,
13462 .nr_testruns = NR_PATTERN_RUNS,
13465 "JMP32_JSLT_K: all immediate value magnitudes",
13467 INTERNAL | FLAG_NO_DATA,
13470 .fill_helper = bpf_fill_jmp32_jslt_imm,
13471 .nr_testruns = NR_PATTERN_RUNS,
13474 "JMP32_JSLE_K: all immediate value magnitudes",
13476 INTERNAL | FLAG_NO_DATA,
13479 .fill_helper = bpf_fill_jmp32_jsle_imm,
13480 .nr_testruns = NR_PATTERN_RUNS,
13482 /* JMP32 register magnitudes */
13484 "JMP32_JSET_X: all register value magnitudes",
13486 INTERNAL | FLAG_NO_DATA,
13489 .fill_helper = bpf_fill_jmp32_jset_reg,
13490 .nr_testruns = NR_PATTERN_RUNS,
13493 "JMP32_JEQ_X: all register value magnitudes",
13495 INTERNAL | FLAG_NO_DATA,
13498 .fill_helper = bpf_fill_jmp32_jeq_reg,
13499 .nr_testruns = NR_PATTERN_RUNS,
13502 "JMP32_JNE_X: all register value magnitudes",
13504 INTERNAL | FLAG_NO_DATA,
13507 .fill_helper = bpf_fill_jmp32_jne_reg,
13508 .nr_testruns = NR_PATTERN_RUNS,
13511 "JMP32_JGT_X: all register value magnitudes",
13513 INTERNAL | FLAG_NO_DATA,
13516 .fill_helper = bpf_fill_jmp32_jgt_reg,
13517 .nr_testruns = NR_PATTERN_RUNS,
13520 "JMP32_JGE_X: all register value magnitudes",
13522 INTERNAL | FLAG_NO_DATA,
13525 .fill_helper = bpf_fill_jmp32_jge_reg,
13526 .nr_testruns = NR_PATTERN_RUNS,
13529 "JMP32_JLT_X: all register value magnitudes",
13531 INTERNAL | FLAG_NO_DATA,
13534 .fill_helper = bpf_fill_jmp32_jlt_reg,
13535 .nr_testruns = NR_PATTERN_RUNS,
13538 "JMP32_JLE_X: all register value magnitudes",
13540 INTERNAL | FLAG_NO_DATA,
13543 .fill_helper = bpf_fill_jmp32_jle_reg,
13544 .nr_testruns = NR_PATTERN_RUNS,
13547 "JMP32_JSGT_X: all register value magnitudes",
13549 INTERNAL | FLAG_NO_DATA,
13552 .fill_helper = bpf_fill_jmp32_jsgt_reg,
13553 .nr_testruns = NR_PATTERN_RUNS,
13556 "JMP32_JSGE_X: all register value magnitudes",
13558 INTERNAL | FLAG_NO_DATA,
13561 .fill_helper = bpf_fill_jmp32_jsge_reg,
13562 .nr_testruns = NR_PATTERN_RUNS,
13565 "JMP32_JSLT_X: all register value magnitudes",
13567 INTERNAL | FLAG_NO_DATA,
13570 .fill_helper = bpf_fill_jmp32_jslt_reg,
13571 .nr_testruns = NR_PATTERN_RUNS,
13574 "JMP32_JSLE_X: all register value magnitudes",
13576 INTERNAL | FLAG_NO_DATA,
13579 .fill_helper = bpf_fill_jmp32_jsle_reg,
13580 .nr_testruns = NR_PATTERN_RUNS,
13582 /* Conditional jumps with constant decision */
13584 "JMP_JSET_K: imm = 0 -> never taken",
13586 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13587 BPF_JMP_IMM(BPF_JSET, R1, 0, 1),
13588 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13591 INTERNAL | FLAG_NO_DATA,
13596 "JMP_JLT_K: imm = 0 -> never taken",
13598 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13599 BPF_JMP_IMM(BPF_JLT, R1, 0, 1),
13600 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13603 INTERNAL | FLAG_NO_DATA,
13608 "JMP_JGE_K: imm = 0 -> always taken",
13610 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13611 BPF_JMP_IMM(BPF_JGE, R1, 0, 1),
13612 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13615 INTERNAL | FLAG_NO_DATA,
13620 "JMP_JGT_K: imm = 0xffffffff -> never taken",
13622 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13623 BPF_JMP_IMM(BPF_JGT, R1, U32_MAX, 1),
13624 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13627 INTERNAL | FLAG_NO_DATA,
13632 "JMP_JLE_K: imm = 0xffffffff -> always taken",
13634 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13635 BPF_JMP_IMM(BPF_JLE, R1, U32_MAX, 1),
13636 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13639 INTERNAL | FLAG_NO_DATA,
13644 "JMP32_JSGT_K: imm = 0x7fffffff -> never taken",
13646 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13647 BPF_JMP32_IMM(BPF_JSGT, R1, S32_MAX, 1),
13648 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13651 INTERNAL | FLAG_NO_DATA,
13656 "JMP32_JSGE_K: imm = -0x80000000 -> always taken",
13658 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13659 BPF_JMP32_IMM(BPF_JSGE, R1, S32_MIN, 1),
13660 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13663 INTERNAL | FLAG_NO_DATA,
13668 "JMP32_JSLT_K: imm = -0x80000000 -> never taken",
13670 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13671 BPF_JMP32_IMM(BPF_JSLT, R1, S32_MIN, 1),
13672 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13675 INTERNAL | FLAG_NO_DATA,
13680 "JMP32_JSLE_K: imm = 0x7fffffff -> always taken",
13682 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13683 BPF_JMP32_IMM(BPF_JSLE, R1, S32_MAX, 1),
13684 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13687 INTERNAL | FLAG_NO_DATA,
13692 "JMP_JEQ_X: dst = src -> always taken",
13694 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13695 BPF_JMP_REG(BPF_JEQ, R1, R1, 1),
13696 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13699 INTERNAL | FLAG_NO_DATA,
13704 "JMP_JGE_X: dst = src -> always taken",
13706 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13707 BPF_JMP_REG(BPF_JGE, R1, R1, 1),
13708 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13711 INTERNAL | FLAG_NO_DATA,
13716 "JMP_JLE_X: dst = src -> always taken",
13718 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13719 BPF_JMP_REG(BPF_JLE, R1, R1, 1),
13720 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13723 INTERNAL | FLAG_NO_DATA,
13728 "JMP_JSGE_X: dst = src -> always taken",
13730 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13731 BPF_JMP_REG(BPF_JSGE, R1, R1, 1),
13732 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13735 INTERNAL | FLAG_NO_DATA,
13740 "JMP_JSLE_X: dst = src -> always taken",
13742 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13743 BPF_JMP_REG(BPF_JSLE, R1, R1, 1),
13744 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13747 INTERNAL | FLAG_NO_DATA,
13752 "JMP_JNE_X: dst = src -> never taken",
13754 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13755 BPF_JMP_REG(BPF_JNE, R1, R1, 1),
13756 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13759 INTERNAL | FLAG_NO_DATA,
13764 "JMP_JGT_X: dst = src -> never taken",
13766 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13767 BPF_JMP_REG(BPF_JGT, R1, R1, 1),
13768 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13771 INTERNAL | FLAG_NO_DATA,
13776 "JMP_JLT_X: dst = src -> never taken",
13778 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13779 BPF_JMP_REG(BPF_JLT, R1, R1, 1),
13780 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13783 INTERNAL | FLAG_NO_DATA,
13788 "JMP_JSGT_X: dst = src -> never taken",
13790 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13791 BPF_JMP_REG(BPF_JSGT, R1, R1, 1),
13792 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13795 INTERNAL | FLAG_NO_DATA,
13800 "JMP_JSLT_X: dst = src -> never taken",
13802 BPF_ALU64_IMM(BPF_MOV, R0, 1),
13803 BPF_JMP_REG(BPF_JSLT, R1, R1, 1),
13804 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13807 INTERNAL | FLAG_NO_DATA,
13811 /* Short relative jumps */
13813 "Short relative jump: offset=0",
13815 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13816 BPF_JMP_IMM(BPF_JEQ, R0, 0, 0),
13818 BPF_ALU32_IMM(BPF_MOV, R0, -1),
13820 INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT,
13825 "Short relative jump: offset=1",
13827 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13828 BPF_JMP_IMM(BPF_JEQ, R0, 0, 1),
13829 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13831 BPF_ALU32_IMM(BPF_MOV, R0, -1),
13833 INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT,
13838 "Short relative jump: offset=2",
13840 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13841 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
13842 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13843 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13845 BPF_ALU32_IMM(BPF_MOV, R0, -1),
13847 INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT,
13852 "Short relative jump: offset=3",
13854 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13855 BPF_JMP_IMM(BPF_JEQ, R0, 0, 3),
13856 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13857 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13858 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13860 BPF_ALU32_IMM(BPF_MOV, R0, -1),
13862 INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT,
13867 "Short relative jump: offset=4",
13869 BPF_ALU64_IMM(BPF_MOV, R0, 0),
13870 BPF_JMP_IMM(BPF_JEQ, R0, 0, 4),
13871 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13872 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13873 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13874 BPF_ALU32_IMM(BPF_ADD, R0, 1),
13876 BPF_ALU32_IMM(BPF_MOV, R0, -1),
13878 INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT,
13882 /* Conditional branch conversions */
13884 "Long conditional jump: taken at runtime",
13886 INTERNAL | FLAG_NO_DATA,
13889 .fill_helper = bpf_fill_max_jmp_taken,
13892 "Long conditional jump: not taken at runtime",
13894 INTERNAL | FLAG_NO_DATA,
13897 .fill_helper = bpf_fill_max_jmp_not_taken,
13900 "Long conditional jump: always taken, known at JIT time",
13902 INTERNAL | FLAG_NO_DATA,
13905 .fill_helper = bpf_fill_max_jmp_always_taken,
13908 "Long conditional jump: never taken, known at JIT time",
13910 INTERNAL | FLAG_NO_DATA,
13913 .fill_helper = bpf_fill_max_jmp_never_taken,
13915 /* Staggered jump sequences, immediate */
13917 "Staggered jumps: JMP_JA",
13919 INTERNAL | FLAG_NO_DATA,
13921 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13922 .fill_helper = bpf_fill_staggered_ja,
13923 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13926 "Staggered jumps: JMP_JEQ_K",
13928 INTERNAL | FLAG_NO_DATA,
13930 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13931 .fill_helper = bpf_fill_staggered_jeq_imm,
13932 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13935 "Staggered jumps: JMP_JNE_K",
13937 INTERNAL | FLAG_NO_DATA,
13939 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13940 .fill_helper = bpf_fill_staggered_jne_imm,
13941 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13944 "Staggered jumps: JMP_JSET_K",
13946 INTERNAL | FLAG_NO_DATA,
13948 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13949 .fill_helper = bpf_fill_staggered_jset_imm,
13950 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13953 "Staggered jumps: JMP_JGT_K",
13955 INTERNAL | FLAG_NO_DATA,
13957 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13958 .fill_helper = bpf_fill_staggered_jgt_imm,
13959 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13962 "Staggered jumps: JMP_JGE_K",
13964 INTERNAL | FLAG_NO_DATA,
13966 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13967 .fill_helper = bpf_fill_staggered_jge_imm,
13968 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13971 "Staggered jumps: JMP_JLT_K",
13973 INTERNAL | FLAG_NO_DATA,
13975 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13976 .fill_helper = bpf_fill_staggered_jlt_imm,
13977 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13980 "Staggered jumps: JMP_JLE_K",
13982 INTERNAL | FLAG_NO_DATA,
13984 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13985 .fill_helper = bpf_fill_staggered_jle_imm,
13986 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13989 "Staggered jumps: JMP_JSGT_K",
13991 INTERNAL | FLAG_NO_DATA,
13993 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
13994 .fill_helper = bpf_fill_staggered_jsgt_imm,
13995 .nr_testruns = NR_STAGGERED_JMP_RUNS,
13998 "Staggered jumps: JMP_JSGE_K",
14000 INTERNAL | FLAG_NO_DATA,
14002 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14003 .fill_helper = bpf_fill_staggered_jsge_imm,
14004 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14007 "Staggered jumps: JMP_JSLT_K",
14009 INTERNAL | FLAG_NO_DATA,
14011 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14012 .fill_helper = bpf_fill_staggered_jslt_imm,
14013 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14016 "Staggered jumps: JMP_JSLE_K",
14018 INTERNAL | FLAG_NO_DATA,
14020 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14021 .fill_helper = bpf_fill_staggered_jsle_imm,
14022 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14024 /* Staggered jump sequences, register */
14026 "Staggered jumps: JMP_JEQ_X",
14028 INTERNAL | FLAG_NO_DATA,
14030 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14031 .fill_helper = bpf_fill_staggered_jeq_reg,
14032 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14035 "Staggered jumps: JMP_JNE_X",
14037 INTERNAL | FLAG_NO_DATA,
14039 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14040 .fill_helper = bpf_fill_staggered_jne_reg,
14041 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14044 "Staggered jumps: JMP_JSET_X",
14046 INTERNAL | FLAG_NO_DATA,
14048 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14049 .fill_helper = bpf_fill_staggered_jset_reg,
14050 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14053 "Staggered jumps: JMP_JGT_X",
14055 INTERNAL | FLAG_NO_DATA,
14057 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14058 .fill_helper = bpf_fill_staggered_jgt_reg,
14059 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14062 "Staggered jumps: JMP_JGE_X",
14064 INTERNAL | FLAG_NO_DATA,
14066 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14067 .fill_helper = bpf_fill_staggered_jge_reg,
14068 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14071 "Staggered jumps: JMP_JLT_X",
14073 INTERNAL | FLAG_NO_DATA,
14075 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14076 .fill_helper = bpf_fill_staggered_jlt_reg,
14077 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14080 "Staggered jumps: JMP_JLE_X",
14082 INTERNAL | FLAG_NO_DATA,
14084 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14085 .fill_helper = bpf_fill_staggered_jle_reg,
14086 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14089 "Staggered jumps: JMP_JSGT_X",
14091 INTERNAL | FLAG_NO_DATA,
14093 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14094 .fill_helper = bpf_fill_staggered_jsgt_reg,
14095 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14098 "Staggered jumps: JMP_JSGE_X",
14100 INTERNAL | FLAG_NO_DATA,
14102 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14103 .fill_helper = bpf_fill_staggered_jsge_reg,
14104 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14107 "Staggered jumps: JMP_JSLT_X",
14109 INTERNAL | FLAG_NO_DATA,
14111 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14112 .fill_helper = bpf_fill_staggered_jslt_reg,
14113 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14116 "Staggered jumps: JMP_JSLE_X",
14118 INTERNAL | FLAG_NO_DATA,
14120 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14121 .fill_helper = bpf_fill_staggered_jsle_reg,
14122 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14124 /* Staggered jump sequences, JMP32 immediate */
14126 "Staggered jumps: JMP32_JEQ_K",
14128 INTERNAL | FLAG_NO_DATA,
14130 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14131 .fill_helper = bpf_fill_staggered_jeq32_imm,
14132 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14135 "Staggered jumps: JMP32_JNE_K",
14137 INTERNAL | FLAG_NO_DATA,
14139 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14140 .fill_helper = bpf_fill_staggered_jne32_imm,
14141 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14144 "Staggered jumps: JMP32_JSET_K",
14146 INTERNAL | FLAG_NO_DATA,
14148 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14149 .fill_helper = bpf_fill_staggered_jset32_imm,
14150 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14153 "Staggered jumps: JMP32_JGT_K",
14155 INTERNAL | FLAG_NO_DATA,
14157 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14158 .fill_helper = bpf_fill_staggered_jgt32_imm,
14159 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14162 "Staggered jumps: JMP32_JGE_K",
14164 INTERNAL | FLAG_NO_DATA,
14166 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14167 .fill_helper = bpf_fill_staggered_jge32_imm,
14168 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14171 "Staggered jumps: JMP32_JLT_K",
14173 INTERNAL | FLAG_NO_DATA,
14175 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14176 .fill_helper = bpf_fill_staggered_jlt32_imm,
14177 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14180 "Staggered jumps: JMP32_JLE_K",
14182 INTERNAL | FLAG_NO_DATA,
14184 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14185 .fill_helper = bpf_fill_staggered_jle32_imm,
14186 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14189 "Staggered jumps: JMP32_JSGT_K",
14191 INTERNAL | FLAG_NO_DATA,
14193 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14194 .fill_helper = bpf_fill_staggered_jsgt32_imm,
14195 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14198 "Staggered jumps: JMP32_JSGE_K",
14200 INTERNAL | FLAG_NO_DATA,
14202 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14203 .fill_helper = bpf_fill_staggered_jsge32_imm,
14204 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14207 "Staggered jumps: JMP32_JSLT_K",
14209 INTERNAL | FLAG_NO_DATA,
14211 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14212 .fill_helper = bpf_fill_staggered_jslt32_imm,
14213 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14216 "Staggered jumps: JMP32_JSLE_K",
14218 INTERNAL | FLAG_NO_DATA,
14220 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14221 .fill_helper = bpf_fill_staggered_jsle32_imm,
14222 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14224 /* Staggered jump sequences, JMP32 register */
14226 "Staggered jumps: JMP32_JEQ_X",
14228 INTERNAL | FLAG_NO_DATA,
14230 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14231 .fill_helper = bpf_fill_staggered_jeq32_reg,
14232 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14235 "Staggered jumps: JMP32_JNE_X",
14237 INTERNAL | FLAG_NO_DATA,
14239 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14240 .fill_helper = bpf_fill_staggered_jne32_reg,
14241 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14244 "Staggered jumps: JMP32_JSET_X",
14246 INTERNAL | FLAG_NO_DATA,
14248 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14249 .fill_helper = bpf_fill_staggered_jset32_reg,
14250 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14253 "Staggered jumps: JMP32_JGT_X",
14255 INTERNAL | FLAG_NO_DATA,
14257 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14258 .fill_helper = bpf_fill_staggered_jgt32_reg,
14259 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14262 "Staggered jumps: JMP32_JGE_X",
14264 INTERNAL | FLAG_NO_DATA,
14266 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14267 .fill_helper = bpf_fill_staggered_jge32_reg,
14268 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14271 "Staggered jumps: JMP32_JLT_X",
14273 INTERNAL | FLAG_NO_DATA,
14275 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14276 .fill_helper = bpf_fill_staggered_jlt32_reg,
14277 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14280 "Staggered jumps: JMP32_JLE_X",
14282 INTERNAL | FLAG_NO_DATA,
14284 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14285 .fill_helper = bpf_fill_staggered_jle32_reg,
14286 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14289 "Staggered jumps: JMP32_JSGT_X",
14291 INTERNAL | FLAG_NO_DATA,
14293 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14294 .fill_helper = bpf_fill_staggered_jsgt32_reg,
14295 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14298 "Staggered jumps: JMP32_JSGE_X",
14300 INTERNAL | FLAG_NO_DATA,
14302 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14303 .fill_helper = bpf_fill_staggered_jsge32_reg,
14304 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14307 "Staggered jumps: JMP32_JSLT_X",
14309 INTERNAL | FLAG_NO_DATA,
14311 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14312 .fill_helper = bpf_fill_staggered_jslt32_reg,
14313 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14316 "Staggered jumps: JMP32_JSLE_X",
14318 INTERNAL | FLAG_NO_DATA,
14320 { { 0, MAX_STAGGERED_JMP_SIZE + 1 } },
14321 .fill_helper = bpf_fill_staggered_jsle32_reg,
14322 .nr_testruns = NR_STAGGERED_JMP_RUNS,
14326 static struct net_device dev;
14328 static struct sk_buff *populate_skb(char *buf, int size)
14330 struct sk_buff *skb;
14332 if (size >= MAX_DATA)
14335 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
14339 __skb_put_data(skb, buf, size);
14341 /* Initialize a fake skb with test pattern. */
14342 skb_reset_mac_header(skb);
14343 skb->protocol = htons(ETH_P_IP);
14344 skb->pkt_type = SKB_TYPE;
14345 skb->mark = SKB_MARK;
14346 skb->hash = SKB_HASH;
14347 skb->queue_mapping = SKB_QUEUE_MAP;
14348 skb->vlan_tci = SKB_VLAN_TCI;
14349 skb->vlan_present = SKB_VLAN_PRESENT;
14350 skb->vlan_proto = htons(ETH_P_IP);
14351 dev_net_set(&dev, &init_net);
14353 skb->dev->ifindex = SKB_DEV_IFINDEX;
14354 skb->dev->type = SKB_DEV_TYPE;
14355 skb_set_network_header(skb, min(size, ETH_HLEN));
14360 static void *generate_test_data(struct bpf_test *test, int sub)
14362 struct sk_buff *skb;
14365 if (test->aux & FLAG_NO_DATA)
14368 if (test->aux & FLAG_LARGE_MEM)
14369 return kmalloc(test->test[sub].data_size, GFP_KERNEL);
14371 /* Test case expects an skb, so populate one. Various
14372 * subtests generate skbs of different sizes based on
14375 skb = populate_skb(test->data, test->test[sub].data_size);
14379 if (test->aux & FLAG_SKB_FRAG) {
14381 * when the test requires a fragmented skb, add a
14382 * single fragment to the skb, filled with
14387 page = alloc_page(GFP_KERNEL);
14390 goto err_kfree_skb;
14394 goto err_free_page;
14395 memcpy(ptr, test->frag_data, MAX_DATA);
14397 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
14409 static void release_test_data(const struct bpf_test *test, void *data)
14411 if (test->aux & FLAG_NO_DATA)
14414 if (test->aux & FLAG_LARGE_MEM)
14420 static int filter_length(int which)
14422 struct sock_filter *fp;
14425 if (tests[which].fill_helper)
14426 return tests[which].u.ptr.len;
14428 fp = tests[which].u.insns;
14429 for (len = MAX_INSNS - 1; len > 0; --len)
14430 if (fp[len].code != 0 || fp[len].k != 0)
14436 static void *filter_pointer(int which)
14438 if (tests[which].fill_helper)
14439 return tests[which].u.ptr.insns;
14441 return tests[which].u.insns;
14444 static struct bpf_prog *generate_filter(int which, int *err)
14446 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
14447 unsigned int flen = filter_length(which);
14448 void *fptr = filter_pointer(which);
14449 struct sock_fprog_kern fprog;
14450 struct bpf_prog *fp;
14452 switch (test_type) {
14454 fprog.filter = fptr;
14457 *err = bpf_prog_create(&fp, &fprog);
14458 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
14459 if (*err == tests[which].expected_errcode) {
14461 /* Verifier rejected filter as expected. */
14465 pr_cont("UNEXPECTED_PASS\n");
14466 /* Verifier didn't reject the test that's
14467 * bad enough, just return!
14474 pr_cont("FAIL to prog_create err=%d len=%d\n",
14481 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
14483 pr_cont("UNEXPECTED_FAIL no memory left\n");
14489 /* Type doesn't really matter here as long as it's not unspec. */
14490 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
14491 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
14492 fp->aux->stack_depth = tests[which].stack_depth;
14493 fp->aux->verifier_zext = !!(tests[which].aux &
14494 FLAG_VERIFIER_ZEXT);
14496 /* We cannot error here as we don't need type compatibility
14499 fp = bpf_prog_select_runtime(fp, err);
14501 pr_cont("FAIL to select_runtime err=%d\n", *err);
14511 static void release_filter(struct bpf_prog *fp, int which)
14513 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
14515 switch (test_type) {
14517 bpf_prog_destroy(fp);
14525 static int __run_one(const struct bpf_prog *fp, const void *data,
14526 int runs, u64 *duration)
14532 start = ktime_get_ns();
14534 for (i = 0; i < runs; i++)
14535 ret = bpf_prog_run(fp, data);
14537 finish = ktime_get_ns();
14540 *duration = finish - start;
14541 do_div(*duration, runs);
14546 static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
14548 int err_cnt = 0, i, runs = MAX_TESTRUNS;
14550 if (test->nr_testruns)
14551 runs = min(test->nr_testruns, MAX_TESTRUNS);
14553 for (i = 0; i < MAX_SUBTESTS; i++) {
14559 * NOTE: Several sub-tests may be present, in which case
14560 * a zero {data_size, result} tuple indicates the end of
14561 * the sub-test array. The first test is always run,
14562 * even if both data_size and result happen to be zero.
14565 test->test[i].data_size == 0 &&
14566 test->test[i].result == 0)
14569 data = generate_test_data(test, i);
14570 if (!data && !(test->aux & FLAG_NO_DATA)) {
14571 pr_cont("data generation failed ");
14575 ret = __run_one(fp, data, runs, &duration);
14576 release_test_data(test, data);
14578 if (ret == test->test[i].result) {
14579 pr_cont("%lld ", duration);
14581 pr_cont("ret %d != %d ", ret,
14582 test->test[i].result);
14590 static char test_name[64];
14591 module_param_string(test_name, test_name, sizeof(test_name), 0);
14593 static int test_id = -1;
14594 module_param(test_id, int, 0);
14596 static int test_range[2] = { 0, INT_MAX };
14597 module_param_array(test_range, int, NULL, 0);
14599 static bool exclude_test(int test_id)
14601 return test_id < test_range[0] || test_id > test_range[1];
14604 static __init struct sk_buff *build_test_skb(void)
14606 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
14607 struct sk_buff *skb[2];
14608 struct page *page[2];
14609 int i, data_size = 8;
14611 for (i = 0; i < 2; i++) {
14612 page[i] = alloc_page(GFP_KERNEL);
14620 /* this will set skb[i]->head_frag */
14621 skb[i] = dev_alloc_skb(headroom + data_size);
14629 skb_reserve(skb[i], headroom);
14630 skb_put(skb[i], data_size);
14631 skb[i]->protocol = htons(ETH_P_IP);
14632 skb_reset_network_header(skb[i]);
14633 skb_set_mac_header(skb[i], -ETH_HLEN);
14635 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
14636 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
14640 skb_shinfo(skb[0])->gso_size = 1448;
14641 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
14642 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
14643 skb_shinfo(skb[0])->gso_segs = 0;
14644 skb_shinfo(skb[0])->frag_list = skb[1];
14645 skb_shinfo(skb[0])->hwtstamps.hwtstamp = 1000;
14647 /* adjust skb[0]'s len */
14648 skb[0]->len += skb[1]->len;
14649 skb[0]->data_len += skb[1]->data_len;
14650 skb[0]->truesize += skb[1]->truesize;
14655 __free_page(page[1]);
14659 __free_page(page[0]);
14664 static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
14666 unsigned int alloc_size = 2000;
14667 unsigned int headroom = 102, doffset = 72, data_size = 1308;
14668 struct sk_buff *skb[2];
14671 /* skbs linked in a frag_list, both with linear data, with head_frag=0
14672 * (data allocated by kmalloc), both have tcp data of 1308 bytes
14673 * (total payload is 2616 bytes).
14674 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
14676 for (i = 0; i < 2; i++) {
14677 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
14685 skb[i]->protocol = htons(ETH_P_IPV6);
14686 skb_reserve(skb[i], headroom);
14687 skb_put(skb[i], doffset + data_size);
14688 skb_reset_network_header(skb[i]);
14690 skb_reset_mac_header(skb[i]);
14692 skb_set_mac_header(skb[i], -ETH_HLEN);
14693 __skb_pull(skb[i], doffset);
14697 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
14698 * reduced gso_size.
14700 skb_shinfo(skb[0])->gso_size = 1288;
14701 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
14702 skb_shinfo(skb[0])->gso_segs = 0;
14703 skb_shinfo(skb[0])->frag_list = skb[1];
14705 /* adjust skb[0]'s len */
14706 skb[0]->len += skb[1]->len;
14707 skb[0]->data_len += skb[1]->len;
14708 skb[0]->truesize += skb[1]->truesize;
14718 struct skb_segment_test {
14720 struct sk_buff *(*build_skb)(void);
14721 netdev_features_t features;
14724 static struct skb_segment_test skb_segment_tests[] __initconst = {
14726 .descr = "gso_with_rx_frags",
14727 .build_skb = build_test_skb,
14728 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
14729 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
14732 .descr = "gso_linear_no_head_frag",
14733 .build_skb = build_test_skb_linear_no_head_frag,
14734 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
14735 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
14736 NETIF_F_LLTX | NETIF_F_GRO |
14737 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
14738 NETIF_F_HW_VLAN_STAG_TX
14742 static __init int test_skb_segment_single(const struct skb_segment_test *test)
14744 struct sk_buff *skb, *segs;
14747 skb = test->build_skb();
14749 pr_info("%s: failed to build_test_skb", __func__);
14753 segs = skb_segment(skb, test->features);
14754 if (!IS_ERR(segs)) {
14755 kfree_skb_list(segs);
14763 static __init int test_skb_segment(void)
14765 int i, err_cnt = 0, pass_cnt = 0;
14767 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
14768 const struct skb_segment_test *test = &skb_segment_tests[i];
14771 if (exclude_test(i))
14774 pr_info("#%d %s ", i, test->descr);
14776 if (test_skb_segment_single(test)) {
14785 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
14786 pass_cnt, err_cnt);
14787 return err_cnt ? -EINVAL : 0;
14790 static __init int test_bpf(void)
14792 int i, err_cnt = 0, pass_cnt = 0;
14793 int jit_cnt = 0, run_cnt = 0;
14795 for (i = 0; i < ARRAY_SIZE(tests); i++) {
14796 struct bpf_prog *fp;
14800 if (exclude_test(i))
14803 pr_info("#%d %s ", i, tests[i].descr);
14805 if (tests[i].fill_helper &&
14806 tests[i].fill_helper(&tests[i]) < 0) {
14807 pr_cont("FAIL to prog_fill\n");
14811 fp = generate_filter(i, &err);
14813 if (tests[i].fill_helper) {
14814 kfree(tests[i].u.ptr.insns);
14815 tests[i].u.ptr.insns = NULL;
14827 pr_cont("jited:%u ", fp->jited);
14833 err = run_one(fp, &tests[i]);
14834 release_filter(fp, i);
14837 pr_cont("FAIL (%d times)\n", err);
14845 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
14846 pass_cnt, err_cnt, jit_cnt, run_cnt);
14848 return err_cnt ? -EINVAL : 0;
14851 struct tail_call_test {
14853 struct bpf_insn insns[MAX_INSNS];
14859 /* Flags that can be passed to tail call test cases */
14860 #define FLAG_NEED_STATE BIT(0)
14861 #define FLAG_RESULT_IN_STATE BIT(1)
14864 * Magic marker used in test snippets for tail calls below.
14865 * BPF_LD/MOV to R2 and R2 with this immediate value is replaced
14866 * with the proper values by the test runner.
14868 #define TAIL_CALL_MARKER 0x7a11ca11
14870 /* Special offset to indicate a NULL call target */
14871 #define TAIL_CALL_NULL 0x7fff
14873 /* Special offset to indicate an out-of-range index */
14874 #define TAIL_CALL_INVALID 0x7ffe
14876 #define TAIL_CALL(offset) \
14877 BPF_LD_IMM64(R2, TAIL_CALL_MARKER), \
14878 BPF_RAW_INSN(BPF_ALU | BPF_MOV | BPF_K, R3, 0, \
14879 offset, TAIL_CALL_MARKER), \
14880 BPF_JMP_IMM(BPF_TAIL_CALL, 0, 0, 0)
14883 * A test function to be called from a BPF program, clobbering a lot of
14884 * CPU registers in the process. A JITed BPF program calling this function
14885 * must save and restore any caller-saved registers it uses for internal
14886 * state, for example the current tail call count.
14888 BPF_CALL_1(bpf_test_func, u64, arg)
14900 return snprintf(buf, sizeof(buf),
14901 "%ld %lu %lx %ld %lu %lx %ld %lu %x",
14902 a, b, c, d, e, f, g, h, (int)arg);
14904 #define BPF_FUNC_test_func __BPF_FUNC_MAX_ID
14907 * Tail call tests. Each test case may call any other test in the table,
14908 * including itself, specified as a relative index offset from the calling
14909 * test. The index TAIL_CALL_NULL can be used to specify a NULL target
14910 * function to test the JIT error path. Similarly, the index TAIL_CALL_INVALID
14911 * results in a target index that is out of range.
14913 static struct tail_call_test tail_call_tests[] = {
14917 BPF_ALU64_REG(BPF_MOV, R0, R1),
14918 BPF_ALU64_IMM(BPF_ADD, R0, 1),
14926 BPF_ALU64_IMM(BPF_ADD, R1, 2),
14928 BPF_ALU64_IMM(BPF_MOV, R0, -1),
14936 BPF_ALU64_IMM(BPF_ADD, R1, 3),
14938 BPF_ALU64_IMM(BPF_MOV, R0, -1),
14946 BPF_ALU64_IMM(BPF_ADD, R1, 4),
14948 BPF_ALU64_IMM(BPF_MOV, R0, -1),
14954 "Tail call load/store leaf",
14956 BPF_ALU64_IMM(BPF_MOV, R1, 1),
14957 BPF_ALU64_IMM(BPF_MOV, R2, 2),
14958 BPF_ALU64_REG(BPF_MOV, R3, BPF_REG_FP),
14959 BPF_STX_MEM(BPF_DW, R3, R1, -8),
14960 BPF_STX_MEM(BPF_DW, R3, R2, -16),
14961 BPF_LDX_MEM(BPF_DW, R0, BPF_REG_FP, -8),
14962 BPF_JMP_REG(BPF_JNE, R0, R1, 3),
14963 BPF_LDX_MEM(BPF_DW, R0, BPF_REG_FP, -16),
14964 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
14965 BPF_ALU64_IMM(BPF_MOV, R0, 0),
14972 "Tail call load/store",
14974 BPF_ALU64_IMM(BPF_MOV, R0, 3),
14975 BPF_STX_MEM(BPF_DW, BPF_REG_FP, R0, -8),
14977 BPF_ALU64_IMM(BPF_MOV, R0, -1),
14984 "Tail call error path, max count reached",
14986 BPF_LDX_MEM(BPF_W, R2, R1, 0),
14987 BPF_ALU64_IMM(BPF_ADD, R2, 1),
14988 BPF_STX_MEM(BPF_W, R1, R2, 0),
14992 .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
14993 .result = (MAX_TAIL_CALL_CNT + 1) * MAX_TESTRUNS,
14996 "Tail call count preserved across function calls",
14998 BPF_LDX_MEM(BPF_W, R2, R1, 0),
14999 BPF_ALU64_IMM(BPF_ADD, R2, 1),
15000 BPF_STX_MEM(BPF_W, R1, R2, 0),
15001 BPF_STX_MEM(BPF_DW, R10, R1, -8),
15002 BPF_CALL_REL(BPF_FUNC_get_numa_node_id),
15003 BPF_CALL_REL(BPF_FUNC_ktime_get_ns),
15004 BPF_CALL_REL(BPF_FUNC_ktime_get_boot_ns),
15005 BPF_CALL_REL(BPF_FUNC_ktime_get_coarse_ns),
15006 BPF_CALL_REL(BPF_FUNC_jiffies64),
15007 BPF_CALL_REL(BPF_FUNC_test_func),
15008 BPF_LDX_MEM(BPF_DW, R1, R10, -8),
15009 BPF_ALU32_REG(BPF_MOV, R0, R1),
15014 .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
15015 .result = (MAX_TAIL_CALL_CNT + 1) * MAX_TESTRUNS,
15018 "Tail call error path, NULL target",
15020 BPF_LDX_MEM(BPF_W, R2, R1, 0),
15021 BPF_ALU64_IMM(BPF_ADD, R2, 1),
15022 BPF_STX_MEM(BPF_W, R1, R2, 0),
15023 TAIL_CALL(TAIL_CALL_NULL),
15026 .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
15027 .result = MAX_TESTRUNS,
15030 "Tail call error path, index out of range",
15032 BPF_LDX_MEM(BPF_W, R2, R1, 0),
15033 BPF_ALU64_IMM(BPF_ADD, R2, 1),
15034 BPF_STX_MEM(BPF_W, R1, R2, 0),
15035 TAIL_CALL(TAIL_CALL_INVALID),
15038 .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
15039 .result = MAX_TESTRUNS,
15043 static void __init destroy_tail_call_tests(struct bpf_array *progs)
15047 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++)
15048 if (progs->ptrs[i])
15049 bpf_prog_free(progs->ptrs[i]);
15053 static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
15055 int ntests = ARRAY_SIZE(tail_call_tests);
15056 struct bpf_array *progs;
15059 /* Allocate the table of programs to be used for tall calls */
15060 progs = kzalloc(sizeof(*progs) + (ntests + 1) * sizeof(progs->ptrs[0]),
15065 /* Create all eBPF programs and populate the table */
15066 for (which = 0; which < ntests; which++) {
15067 struct tail_call_test *test = &tail_call_tests[which];
15068 struct bpf_prog *fp;
15071 /* Compute the number of program instructions */
15072 for (len = 0; len < MAX_INSNS; len++) {
15073 struct bpf_insn *insn = &test->insns[len];
15075 if (len < MAX_INSNS - 1 &&
15076 insn->code == (BPF_LD | BPF_DW | BPF_IMM))
15078 if (insn->code == 0)
15082 /* Allocate and initialize the program */
15083 fp = bpf_prog_alloc(bpf_prog_size(len), 0);
15088 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
15089 fp->aux->stack_depth = test->stack_depth;
15090 memcpy(fp->insnsi, test->insns, len * sizeof(struct bpf_insn));
15092 /* Relocate runtime tail call offsets and addresses */
15093 for (i = 0; i < len; i++) {
15094 struct bpf_insn *insn = &fp->insnsi[i];
15097 switch (insn->code) {
15098 case BPF_LD | BPF_DW | BPF_IMM:
15099 if (insn->imm != TAIL_CALL_MARKER)
15101 insn[0].imm = (u32)(long)progs;
15102 insn[1].imm = ((u64)(long)progs) >> 32;
15105 case BPF_ALU | BPF_MOV | BPF_K:
15106 if (insn->imm != TAIL_CALL_MARKER)
15108 if (insn->off == TAIL_CALL_NULL)
15109 insn->imm = ntests;
15110 else if (insn->off == TAIL_CALL_INVALID)
15111 insn->imm = ntests + 1;
15113 insn->imm = which + insn->off;
15117 case BPF_JMP | BPF_CALL:
15118 if (insn->src_reg != BPF_PSEUDO_CALL)
15120 switch (insn->imm) {
15121 case BPF_FUNC_get_numa_node_id:
15122 addr = (long)&numa_node_id;
15124 case BPF_FUNC_ktime_get_ns:
15125 addr = (long)&ktime_get_ns;
15127 case BPF_FUNC_ktime_get_boot_ns:
15128 addr = (long)&ktime_get_boot_fast_ns;
15130 case BPF_FUNC_ktime_get_coarse_ns:
15131 addr = (long)&ktime_get_coarse_ns;
15133 case BPF_FUNC_jiffies64:
15134 addr = (long)&get_jiffies_64;
15136 case BPF_FUNC_test_func:
15137 addr = (long)&bpf_test_func;
15143 *insn = BPF_EMIT_CALL(addr);
15144 if ((long)__bpf_call_base + insn->imm != addr)
15145 *insn = BPF_JMP_A(0); /* Skip: NOP */
15150 fp = bpf_prog_select_runtime(fp, &err);
15154 progs->ptrs[which] = fp;
15157 /* The last entry contains a NULL program pointer */
15158 progs->map.max_entries = ntests + 1;
15167 destroy_tail_call_tests(progs);
15171 static __init int test_tail_calls(struct bpf_array *progs)
15173 int i, err_cnt = 0, pass_cnt = 0;
15174 int jit_cnt = 0, run_cnt = 0;
15176 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
15177 struct tail_call_test *test = &tail_call_tests[i];
15178 struct bpf_prog *fp = progs->ptrs[i];
15185 if (exclude_test(i))
15188 pr_info("#%d %s ", i, test->descr);
15193 pr_cont("jited:%u ", fp->jited);
15199 if (test->flags & FLAG_NEED_STATE)
15201 ret = __run_one(fp, data, MAX_TESTRUNS, &duration);
15202 if (test->flags & FLAG_RESULT_IN_STATE)
15204 if (ret == test->result) {
15205 pr_cont("%lld PASS", duration);
15208 pr_cont("ret %d != %d FAIL", ret, test->result);
15213 pr_info("%s: Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
15214 __func__, pass_cnt, err_cnt, jit_cnt, run_cnt);
15216 return err_cnt ? -EINVAL : 0;
15219 static char test_suite[32];
15220 module_param_string(test_suite, test_suite, sizeof(test_suite), 0);
15222 static __init int find_test_index(const char *test_name)
15226 if (!strcmp(test_suite, "test_bpf")) {
15227 for (i = 0; i < ARRAY_SIZE(tests); i++) {
15228 if (!strcmp(tests[i].descr, test_name))
15233 if (!strcmp(test_suite, "test_tail_calls")) {
15234 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
15235 if (!strcmp(tail_call_tests[i].descr, test_name))
15240 if (!strcmp(test_suite, "test_skb_segment")) {
15241 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
15242 if (!strcmp(skb_segment_tests[i].descr, test_name))
15250 static __init int prepare_test_range(void)
15254 if (!strcmp(test_suite, "test_bpf"))
15255 valid_range = ARRAY_SIZE(tests);
15256 else if (!strcmp(test_suite, "test_tail_calls"))
15257 valid_range = ARRAY_SIZE(tail_call_tests);
15258 else if (!strcmp(test_suite, "test_skb_segment"))
15259 valid_range = ARRAY_SIZE(skb_segment_tests);
15263 if (test_id >= 0) {
15265 * if a test_id was specified, use test_range to
15266 * cover only that test.
15268 if (test_id >= valid_range) {
15269 pr_err("test_bpf: invalid test_id specified for '%s' suite.\n",
15274 test_range[0] = test_id;
15275 test_range[1] = test_id;
15276 } else if (*test_name) {
15278 * if a test_name was specified, find it and setup
15279 * test_range to cover only that test.
15281 int idx = find_test_index(test_name);
15284 pr_err("test_bpf: no test named '%s' found for '%s' suite.\n",
15285 test_name, test_suite);
15288 test_range[0] = idx;
15289 test_range[1] = idx;
15290 } else if (test_range[0] != 0 || test_range[1] != INT_MAX) {
15292 * check that the supplied test_range is valid.
15294 if (test_range[0] < 0 || test_range[1] >= valid_range) {
15295 pr_err("test_bpf: test_range is out of bound for '%s' suite.\n",
15300 if (test_range[1] < test_range[0]) {
15301 pr_err("test_bpf: test_range is ending before it starts.\n");
15309 static int __init test_bpf_init(void)
15311 struct bpf_array *progs = NULL;
15314 if (strlen(test_suite) &&
15315 strcmp(test_suite, "test_bpf") &&
15316 strcmp(test_suite, "test_tail_calls") &&
15317 strcmp(test_suite, "test_skb_segment")) {
15318 pr_err("test_bpf: invalid test_suite '%s' specified.\n", test_suite);
15323 * if test_suite is not specified, but test_id, test_name or test_range
15324 * is specified, set 'test_bpf' as the default test suite.
15326 if (!strlen(test_suite) &&
15327 (test_id != -1 || strlen(test_name) ||
15328 (test_range[0] != 0 || test_range[1] != INT_MAX))) {
15329 pr_info("test_bpf: set 'test_bpf' as the default test_suite.\n");
15330 strscpy(test_suite, "test_bpf", sizeof(test_suite));
15333 ret = prepare_test_range();
15337 if (!strlen(test_suite) || !strcmp(test_suite, "test_bpf")) {
15343 if (!strlen(test_suite) || !strcmp(test_suite, "test_tail_calls")) {
15344 ret = prepare_tail_call_tests(&progs);
15347 ret = test_tail_calls(progs);
15348 destroy_tail_call_tests(progs);
15353 if (!strlen(test_suite) || !strcmp(test_suite, "test_skb_segment"))
15354 return test_skb_segment();
15359 static void __exit test_bpf_exit(void)
15363 module_init(test_bpf_init);
15364 module_exit(test_bpf_exit);
15366 MODULE_LICENSE("GPL");