2 * Testsuite for BPF interpreter and BPF JIT compiler
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/filter.h>
21 #include <linux/bpf.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_vlan.h>
25 #include <linux/random.h>
26 #include <linux/highmem.h>
28 /* General test specific settings */
29 #define MAX_SUBTESTS 3
30 #define MAX_TESTRUNS 10000
33 #define MAX_K 0xffffFFFF
35 /* Few constants used to init test 'skb' */
37 #define SKB_MARK 0x1234aaaa
38 #define SKB_HASH 0x1234aaab
39 #define SKB_QUEUE_MAP 123
40 #define SKB_VLAN_TCI 0xffff
41 #define SKB_DEV_IFINDEX 577
42 #define SKB_DEV_TYPE 588
44 /* Redefine REGs to make tests less verbose */
55 #define R10 BPF_REG_10
57 /* Flags that can be passed to test cases */
58 #define FLAG_NO_DATA BIT(0)
59 #define FLAG_EXPECTED_FAIL BIT(1)
60 #define FLAG_SKB_FRAG BIT(2)
63 CLASSIC
= BIT(6), /* Old BPF instructions only. */
64 INTERNAL
= BIT(7), /* Extended instruction set. */
67 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
72 struct sock_filter insns
[MAX_INSNS
];
73 struct bpf_insn insns_int
[MAX_INSNS
];
85 int (*fill_helper
)(struct bpf_test
*self
);
86 __u8 frag_data
[MAX_DATA
];
87 int stack_depth
; /* for eBPF only, since tests don't call verifier */
90 /* Large test cases need separate allocation and fill handler. */
92 static int bpf_fill_maxinsns1(struct bpf_test
*self
)
94 unsigned int len
= BPF_MAXINSNS
;
95 struct sock_filter
*insn
;
99 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
103 for (i
= 0; i
< len
; i
++, k
--)
104 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, k
);
106 self
->u
.ptr
.insns
= insn
;
107 self
->u
.ptr
.len
= len
;
112 static int bpf_fill_maxinsns2(struct bpf_test
*self
)
114 unsigned int len
= BPF_MAXINSNS
;
115 struct sock_filter
*insn
;
118 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
122 for (i
= 0; i
< len
; i
++)
123 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
125 self
->u
.ptr
.insns
= insn
;
126 self
->u
.ptr
.len
= len
;
131 static int bpf_fill_maxinsns3(struct bpf_test
*self
)
133 unsigned int len
= BPF_MAXINSNS
;
134 struct sock_filter
*insn
;
135 struct rnd_state rnd
;
138 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
142 prandom_seed_state(&rnd
, 3141592653589793238ULL);
144 for (i
= 0; i
< len
- 1; i
++) {
145 __u32 k
= prandom_u32_state(&rnd
);
147 insn
[i
] = __BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, k
);
150 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
152 self
->u
.ptr
.insns
= insn
;
153 self
->u
.ptr
.len
= len
;
158 static int bpf_fill_maxinsns4(struct bpf_test
*self
)
160 unsigned int len
= BPF_MAXINSNS
+ 1;
161 struct sock_filter
*insn
;
164 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
168 for (i
= 0; i
< len
; i
++)
169 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
171 self
->u
.ptr
.insns
= insn
;
172 self
->u
.ptr
.len
= len
;
177 static int bpf_fill_maxinsns5(struct bpf_test
*self
)
179 unsigned int len
= BPF_MAXINSNS
;
180 struct sock_filter
*insn
;
183 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
187 insn
[0] = __BPF_JUMP(BPF_JMP
| BPF_JA
, len
- 2, 0, 0);
189 for (i
= 1; i
< len
- 1; i
++)
190 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
192 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xabababab);
194 self
->u
.ptr
.insns
= insn
;
195 self
->u
.ptr
.len
= len
;
200 static int bpf_fill_maxinsns6(struct bpf_test
*self
)
202 unsigned int len
= BPF_MAXINSNS
;
203 struct sock_filter
*insn
;
206 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
210 for (i
= 0; i
< len
- 1; i
++)
211 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
212 SKF_AD_VLAN_TAG_PRESENT
);
214 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
216 self
->u
.ptr
.insns
= insn
;
217 self
->u
.ptr
.len
= len
;
222 static int bpf_fill_maxinsns7(struct bpf_test
*self
)
224 unsigned int len
= BPF_MAXINSNS
;
225 struct sock_filter
*insn
;
228 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
232 for (i
= 0; i
< len
- 4; i
++)
233 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
236 insn
[len
- 4] = __BPF_STMT(BPF_MISC
| BPF_TAX
, 0);
237 insn
[len
- 3] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
239 insn
[len
- 2] = __BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0);
240 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
242 self
->u
.ptr
.insns
= insn
;
243 self
->u
.ptr
.len
= len
;
248 static int bpf_fill_maxinsns8(struct bpf_test
*self
)
250 unsigned int len
= BPF_MAXINSNS
;
251 struct sock_filter
*insn
;
252 int i
, jmp_off
= len
- 3;
254 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
258 insn
[0] = __BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff);
260 for (i
= 1; i
< len
- 1; i
++)
261 insn
[i
] = __BPF_JUMP(BPF_JMP
| BPF_JGT
, 0xffffffff, jmp_off
--, 0);
263 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
265 self
->u
.ptr
.insns
= insn
;
266 self
->u
.ptr
.len
= len
;
271 static int bpf_fill_maxinsns9(struct bpf_test
*self
)
273 unsigned int len
= BPF_MAXINSNS
;
274 struct bpf_insn
*insn
;
277 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
281 insn
[0] = BPF_JMP_IMM(BPF_JA
, 0, 0, len
- 2);
282 insn
[1] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xcbababab);
283 insn
[2] = BPF_EXIT_INSN();
285 for (i
= 3; i
< len
- 2; i
++)
286 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xfefefefe);
288 insn
[len
- 2] = BPF_EXIT_INSN();
289 insn
[len
- 1] = BPF_JMP_IMM(BPF_JA
, 0, 0, -(len
- 1));
291 self
->u
.ptr
.insns
= insn
;
292 self
->u
.ptr
.len
= len
;
297 static int bpf_fill_maxinsns10(struct bpf_test
*self
)
299 unsigned int len
= BPF_MAXINSNS
, hlen
= len
- 2;
300 struct bpf_insn
*insn
;
303 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
307 for (i
= 0; i
< hlen
/ 2; i
++)
308 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 2 - 2 * i
);
309 for (i
= hlen
- 1; i
> hlen
/ 2; i
--)
310 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 1 - 2 * i
);
312 insn
[hlen
/ 2] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
/ 2 - 1);
313 insn
[hlen
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xabababac);
314 insn
[hlen
+ 1] = BPF_EXIT_INSN();
316 self
->u
.ptr
.insns
= insn
;
317 self
->u
.ptr
.len
= len
;
322 static int __bpf_fill_ja(struct bpf_test
*self
, unsigned int len
,
325 struct sock_filter
*insn
;
329 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
333 rlen
= (len
% plen
) - 1;
335 for (i
= 0; i
+ plen
< len
; i
+= plen
)
336 for (j
= 0; j
< plen
; j
++)
337 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
,
339 for (j
= 0; j
< rlen
; j
++)
340 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
, rlen
- 1 - j
,
343 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xababcbac);
345 self
->u
.ptr
.insns
= insn
;
346 self
->u
.ptr
.len
= len
;
351 static int bpf_fill_maxinsns11(struct bpf_test
*self
)
353 /* Hits 70 passes on x86_64, so cannot get JITed there. */
354 return __bpf_fill_ja(self
, BPF_MAXINSNS
, 68);
357 static int bpf_fill_ja(struct bpf_test
*self
)
359 /* Hits exactly 11 passes on x86_64 JIT. */
360 return __bpf_fill_ja(self
, 12, 9);
363 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test
*self
)
365 unsigned int len
= BPF_MAXINSNS
;
366 struct sock_filter
*insn
;
369 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
373 for (i
= 0; i
< len
- 1; i
+= 2) {
374 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 0);
375 insn
[i
+ 1] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
376 SKF_AD_OFF
+ SKF_AD_CPU
);
379 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xbee);
381 self
->u
.ptr
.insns
= insn
;
382 self
->u
.ptr
.len
= len
;
388 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
389 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test
*self
)
391 unsigned int len
= BPF_MAXINSNS
;
392 struct bpf_insn
*insn
;
395 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
399 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
401 for (j
= 0; j
< PUSH_CNT
; j
++) {
402 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
403 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
405 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
406 insn
[i
++] = BPF_MOV64_IMM(R2
, 1);
407 insn
[i
++] = BPF_MOV64_IMM(R3
, 2);
408 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
409 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
410 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
414 for (j
= 0; j
< PUSH_CNT
; j
++) {
415 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
416 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
418 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
419 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
420 bpf_skb_vlan_pop_proto
.func
- __bpf_call_base
);
421 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
427 for (; i
< len
- 1; i
++)
428 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xbef);
430 insn
[len
- 1] = BPF_EXIT_INSN();
432 self
->u
.ptr
.insns
= insn
;
433 self
->u
.ptr
.len
= len
;
438 static int bpf_fill_ld_abs_vlan_push_pop2(struct bpf_test
*self
)
440 struct bpf_insn
*insn
;
442 insn
= kmalloc_array(16, sizeof(*insn
), GFP_KERNEL
);
446 /* Due to func address being non-const, we need to
447 * assemble this here.
449 insn
[0] = BPF_MOV64_REG(R6
, R1
);
450 insn
[1] = BPF_LD_ABS(BPF_B
, 0);
451 insn
[2] = BPF_LD_ABS(BPF_H
, 0);
452 insn
[3] = BPF_LD_ABS(BPF_W
, 0);
453 insn
[4] = BPF_MOV64_REG(R7
, R6
);
454 insn
[5] = BPF_MOV64_IMM(R6
, 0);
455 insn
[6] = BPF_MOV64_REG(R1
, R7
);
456 insn
[7] = BPF_MOV64_IMM(R2
, 1);
457 insn
[8] = BPF_MOV64_IMM(R3
, 2);
458 insn
[9] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
459 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
460 insn
[10] = BPF_MOV64_REG(R6
, R7
);
461 insn
[11] = BPF_LD_ABS(BPF_B
, 0);
462 insn
[12] = BPF_LD_ABS(BPF_H
, 0);
463 insn
[13] = BPF_LD_ABS(BPF_W
, 0);
464 insn
[14] = BPF_MOV64_IMM(R0
, 42);
465 insn
[15] = BPF_EXIT_INSN();
467 self
->u
.ptr
.insns
= insn
;
468 self
->u
.ptr
.len
= 16;
473 static int bpf_fill_jump_around_ld_abs(struct bpf_test
*self
)
475 unsigned int len
= BPF_MAXINSNS
;
476 struct bpf_insn
*insn
;
479 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
483 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
484 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
485 insn
[i
] = BPF_JMP_IMM(BPF_JEQ
, R0
, 10, len
- i
- 2);
488 insn
[i
++] = BPF_LD_ABS(BPF_B
, 1);
489 insn
[i
] = BPF_EXIT_INSN();
491 self
->u
.ptr
.insns
= insn
;
492 self
->u
.ptr
.len
= len
;
497 static int __bpf_fill_stxdw(struct bpf_test
*self
, int size
)
499 unsigned int len
= BPF_MAXINSNS
;
500 struct bpf_insn
*insn
;
503 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
507 insn
[0] = BPF_ALU32_IMM(BPF_MOV
, R0
, 1);
508 insn
[1] = BPF_ST_MEM(size
, R10
, -40, 42);
510 for (i
= 2; i
< len
- 2; i
++)
511 insn
[i
] = BPF_STX_XADD(size
, R10
, R0
, -40);
513 insn
[len
- 2] = BPF_LDX_MEM(size
, R0
, R10
, -40);
514 insn
[len
- 1] = BPF_EXIT_INSN();
516 self
->u
.ptr
.insns
= insn
;
517 self
->u
.ptr
.len
= len
;
518 self
->stack_depth
= 40;
523 static int bpf_fill_stxw(struct bpf_test
*self
)
525 return __bpf_fill_stxdw(self
, BPF_W
);
528 static int bpf_fill_stxdw(struct bpf_test
*self
)
530 return __bpf_fill_stxdw(self
, BPF_DW
);
533 static struct bpf_test tests
[] = {
537 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
538 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
539 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
540 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
541 BPF_STMT(BPF_ALU
| BPF_NEG
, 0), /* A == -3 */
542 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
543 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
544 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
545 BPF_STMT(BPF_MISC
| BPF_TAX
, 0), /* X == len - 3 */
546 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
547 BPF_STMT(BPF_RET
| BPF_A
, 0)
550 { 10, 20, 30, 40, 50 },
551 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
556 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
557 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
558 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
559 BPF_STMT(BPF_RET
| BPF_A
, 0) /* A == len * 2 */
562 { 10, 20, 30, 40, 50 },
563 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
568 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
569 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 2),
570 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
571 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
572 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0xffffffff),
573 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 3),
574 BPF_STMT(BPF_RET
| BPF_A
, 0)
576 CLASSIC
| FLAG_NO_DATA
,
578 { { 0, 0xfffffffd } }
583 BPF_STMT(BPF_LD
| BPF_IMM
, 8),
584 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 2),
585 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
586 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
587 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
588 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
589 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
590 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x70000000),
591 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
592 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
593 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
594 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
595 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
596 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x70000000),
597 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
598 BPF_STMT(BPF_RET
| BPF_A
, 0)
600 CLASSIC
| FLAG_NO_DATA
,
602 { { 0, 0x20000000 } }
607 BPF_STMT(BPF_LD
| BPF_IMM
, 0xff),
608 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
609 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 27),
610 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
611 BPF_STMT(BPF_LD
| BPF_IMM
, 0xf),
612 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_K
, 0xf0),
613 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
614 BPF_STMT(BPF_RET
| BPF_A
, 0)
616 CLASSIC
| FLAG_NO_DATA
,
618 { { 0, 0x800000ff }, { 1, 0x800000ff } },
623 BPF_STMT(BPF_LD
| BPF_IMM
, 0), /* ld #0 */
624 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, 1, 0),
625 BPF_STMT(BPF_RET
| BPF_K
, 0),
626 BPF_STMT(BPF_RET
| BPF_K
, 1),
635 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
636 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, MAX_K
),
637 BPF_STMT(BPF_RET
| BPF_K
, 1)
641 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
646 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, 1000),
647 BPF_STMT(BPF_RET
| BPF_K
, 1)
651 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
656 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
),
657 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
658 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
+ 1),
659 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
660 BPF_STMT(BPF_RET
| BPF_A
, 0)
664 { { 1, 0 }, { 2, 3 } },
669 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_LL_OFF
- 1),
670 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
671 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
672 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
673 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
674 BPF_STMT(BPF_RET
| BPF_A
, 0)
678 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
683 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
),
684 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
685 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
+ 1),
686 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
687 BPF_STMT(BPF_RET
| BPF_A
, 0)
690 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
691 { { 15, 0 }, { 16, 3 } },
696 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_NET_OFF
- 15),
697 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
698 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
699 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
700 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
701 BPF_STMT(BPF_RET
| BPF_A
, 0)
704 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
705 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
710 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
711 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
712 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
713 BPF_STMT(BPF_RET
| BPF_K
, 1),
714 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
715 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
716 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
717 BPF_STMT(BPF_RET
| BPF_K
, 1),
718 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
719 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
720 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
721 BPF_STMT(BPF_RET
| BPF_K
, 1),
722 BPF_STMT(BPF_RET
| BPF_A
, 0)
726 { { 1, 3 }, { 10, 3 } },
731 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
732 SKF_AD_OFF
+ SKF_AD_MARK
),
733 BPF_STMT(BPF_RET
| BPF_A
, 0)
737 { { 1, SKB_MARK
}, { 10, SKB_MARK
} },
742 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
743 SKF_AD_OFF
+ SKF_AD_RXHASH
),
744 BPF_STMT(BPF_RET
| BPF_A
, 0)
748 { { 1, SKB_HASH
}, { 10, SKB_HASH
} },
753 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
754 SKF_AD_OFF
+ SKF_AD_QUEUE
),
755 BPF_STMT(BPF_RET
| BPF_A
, 0)
759 { { 1, SKB_QUEUE_MAP
}, { 10, SKB_QUEUE_MAP
} },
764 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 1),
765 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 20, 1, 0),
766 BPF_STMT(BPF_RET
| BPF_K
, 0),
767 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
768 SKF_AD_OFF
+ SKF_AD_PROTOCOL
),
769 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
770 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
771 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 30, 1, 0),
772 BPF_STMT(BPF_RET
| BPF_K
, 0),
773 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
774 BPF_STMT(BPF_RET
| BPF_A
, 0)
778 { { 10, ETH_P_IP
}, { 100, ETH_P_IP
} },
783 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
784 SKF_AD_OFF
+ SKF_AD_VLAN_TAG
),
785 BPF_STMT(BPF_RET
| BPF_A
, 0)
790 { 1, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
},
791 { 10, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
}
795 "LD_VLAN_TAG_PRESENT",
797 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
798 SKF_AD_OFF
+ SKF_AD_VLAN_TAG_PRESENT
),
799 BPF_STMT(BPF_RET
| BPF_A
, 0)
804 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
805 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
811 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
812 SKF_AD_OFF
+ SKF_AD_IFINDEX
),
813 BPF_STMT(BPF_RET
| BPF_A
, 0)
817 { { 1, SKB_DEV_IFINDEX
}, { 10, SKB_DEV_IFINDEX
} },
822 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
823 SKF_AD_OFF
+ SKF_AD_HATYPE
),
824 BPF_STMT(BPF_RET
| BPF_A
, 0)
828 { { 1, SKB_DEV_TYPE
}, { 10, SKB_DEV_TYPE
} },
833 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
834 SKF_AD_OFF
+ SKF_AD_CPU
),
835 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
836 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
837 SKF_AD_OFF
+ SKF_AD_CPU
),
838 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
839 BPF_STMT(BPF_RET
| BPF_A
, 0)
843 { { 1, 0 }, { 10, 0 } },
848 BPF_STMT(BPF_LDX
| BPF_IMM
, 2),
849 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
850 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
851 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
852 SKF_AD_OFF
+ SKF_AD_NLATTR
),
853 BPF_STMT(BPF_RET
| BPF_A
, 0)
857 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
859 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
861 { { 4, 0 }, { 20, 6 } },
866 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
867 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
868 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
869 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
870 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
871 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
872 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
873 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
874 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
875 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
876 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
877 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
878 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
879 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
880 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
881 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
882 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
883 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
884 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
885 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
886 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
887 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
888 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
889 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
890 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
891 BPF_STMT(BPF_RET
| BPF_A
, 0)
895 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
897 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
899 { { 4, 0 }, { 20, 10 } },
904 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
905 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
906 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
907 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
908 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
909 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
910 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
911 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
912 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
913 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
914 BPF_STMT(BPF_RET
| BPF_A
, 0)
917 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
918 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
919 * id 9737, seq 1, length 64
921 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
922 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
924 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
925 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
926 { { 30, 0 }, { 100, 42 } },
931 BPF_STMT(BPF_LD
| BPF_IMM
, 10),
932 BPF_STMT(BPF_LDX
| BPF_IMM
, 300),
933 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
934 SKF_AD_OFF
+ SKF_AD_ALU_XOR_X
),
935 BPF_STMT(BPF_RET
| BPF_A
, 0)
939 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
944 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
945 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
946 BPF_STMT(BPF_ALU
| BPF_RSH
, 1),
947 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
948 BPF_STMT(BPF_ST
, 1), /* M1 = 1 ^ len */
949 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_K
, 0x80000000),
950 BPF_STMT(BPF_ST
, 2), /* M2 = 1 ^ len ^ 0x80000000 */
951 BPF_STMT(BPF_STX
, 15), /* M3 = len */
952 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
953 BPF_STMT(BPF_LD
| BPF_MEM
, 2),
954 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
955 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
956 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
957 BPF_STMT(BPF_RET
| BPF_A
, 0)
961 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
966 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
967 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
968 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 0, 1),
969 BPF_STMT(BPF_RET
| BPF_K
, 1),
970 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
974 { { 1, 0 }, { 3, 1 }, { 4, MAX_K
} },
979 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
980 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
981 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_X
, 0, 0, 1),
982 BPF_STMT(BPF_RET
| BPF_K
, 1),
983 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
987 { { 2, 0 }, { 3, 1 }, { 4, MAX_K
} },
990 "JGE (jt 0), test 1",
992 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
993 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
994 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
995 BPF_STMT(BPF_RET
| BPF_K
, 1),
996 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1000 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
1003 "JGE (jt 0), test 2",
1005 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1006 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
1007 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
1008 BPF_STMT(BPF_RET
| BPF_K
, 1),
1009 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1013 { { 4, 1 }, { 5, 1 }, { 6, MAX_K
} },
1018 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1019 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, MAX_K
),
1020 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 1, 1, 0),
1021 BPF_STMT(BPF_RET
| BPF_K
, 10),
1022 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 2, 1, 0),
1023 BPF_STMT(BPF_RET
| BPF_K
, 20),
1024 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 3, 1, 0),
1025 BPF_STMT(BPF_RET
| BPF_K
, 30),
1026 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 4, 1, 0),
1027 BPF_STMT(BPF_RET
| BPF_K
, 40),
1028 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1032 { { 1, 20 }, { 3, 40 }, { 5, MAX_K
} },
1037 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1038 BPF_JUMP(BPF_JMP
| BPF_JA
, 1, 1, 1),
1039 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1040 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1041 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1042 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1043 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, 4),
1044 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
1045 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
1046 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 1, 0, 1),
1047 BPF_STMT(BPF_RET
| BPF_K
, 10),
1048 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x80000000, 0, 1),
1049 BPF_STMT(BPF_RET
| BPF_K
, 20),
1050 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1051 BPF_STMT(BPF_RET
| BPF_K
, 30),
1052 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1053 BPF_STMT(BPF_RET
| BPF_K
, 30),
1054 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1055 BPF_STMT(BPF_RET
| BPF_K
, 30),
1056 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1057 BPF_STMT(BPF_RET
| BPF_K
, 30),
1058 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1059 BPF_STMT(BPF_RET
| BPF_K
, 30),
1060 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1063 { 0, 0xAA, 0x55, 1 },
1064 { { 4, 10 }, { 5, 20 }, { 6, MAX_K
} },
1069 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1070 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 0, 8), /* IPv6 */
1071 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 20),
1072 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1073 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1074 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 17),
1075 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 54),
1076 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 14, 0),
1077 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 56),
1078 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 12, 13),
1079 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0800, 0, 12), /* IPv4 */
1080 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1081 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1082 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1083 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 8),
1084 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1085 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 6, 0),
1086 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1087 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1088 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1089 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1090 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 1),
1091 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1092 BPF_STMT(BPF_RET
| BPF_K
, 0),
1095 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1096 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1097 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1098 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1100 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1101 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1103 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1104 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1105 0x0a, 0x01, 0x01, 0x95, /* ip src */
1106 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1108 0x00, 0x16 /* dst port */ },
1109 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1114 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1115 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1116 * (len > 115 or len < 30000000000)' -d
1118 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1119 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 30, 0),
1120 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x800, 0, 29),
1121 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1122 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 0, 27),
1123 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1124 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 25, 0),
1125 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1126 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1127 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1128 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1129 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 20),
1130 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 16),
1131 BPF_STMT(BPF_ST
, 1),
1132 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 14),
1133 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf),
1134 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 2),
1135 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x5), /* libpcap emits K on TAX */
1136 BPF_STMT(BPF_LD
| BPF_MEM
, 1),
1137 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
1138 BPF_STMT(BPF_ST
, 5),
1139 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1140 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 26),
1141 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
1142 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 2),
1143 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x9), /* libpcap emits K on TAX */
1144 BPF_STMT(BPF_LD
| BPF_MEM
, 5),
1145 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 4, 0),
1146 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
1147 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_K
, 0x73, 1, 0),
1148 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 0xfc23ac00, 1, 0),
1149 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1150 BPF_STMT(BPF_RET
| BPF_K
, 0),
1153 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1154 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1156 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1157 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1158 0x0a, 0x01, 0x01, 0x95, /* ip src */
1159 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1161 0x00, 0x16 /* dst port */ },
1162 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1167 /* check that unitialized X and A contain zeros */
1168 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1169 BPF_STMT(BPF_RET
| BPF_A
, 0)
1178 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1179 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
1180 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1181 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1182 BPF_ALU64_IMM(BPF_ADD
, R1
, -1),
1183 BPF_ALU64_IMM(BPF_MUL
, R1
, 3),
1184 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
1189 { { 0, 0xfffffffd } }
1194 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1195 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1196 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1197 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1198 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xfffffffd, 1),
1200 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1210 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1211 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
1212 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1213 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1214 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1215 BPF_JMP_IMM(BPF_JEQ
, R1
, 0x2ffffff, 1),
1217 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1227 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1228 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1229 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1230 BPF_ALU32_REG(BPF_MUL
, R1
, R2
),
1231 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1232 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xffffff, 1),
1234 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1242 /* Have to test all register combinations, since
1243 * JITing of different registers will produce
1244 * different asm code.
1248 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1249 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1250 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1251 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1252 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1253 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1254 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1255 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1256 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1257 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1258 BPF_ALU64_IMM(BPF_ADD
, R0
, 20),
1259 BPF_ALU64_IMM(BPF_ADD
, R1
, 20),
1260 BPF_ALU64_IMM(BPF_ADD
, R2
, 20),
1261 BPF_ALU64_IMM(BPF_ADD
, R3
, 20),
1262 BPF_ALU64_IMM(BPF_ADD
, R4
, 20),
1263 BPF_ALU64_IMM(BPF_ADD
, R5
, 20),
1264 BPF_ALU64_IMM(BPF_ADD
, R6
, 20),
1265 BPF_ALU64_IMM(BPF_ADD
, R7
, 20),
1266 BPF_ALU64_IMM(BPF_ADD
, R8
, 20),
1267 BPF_ALU64_IMM(BPF_ADD
, R9
, 20),
1268 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1269 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1270 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1271 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1272 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1273 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1274 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1275 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1276 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1277 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1278 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1279 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1280 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1281 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1282 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1283 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1284 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1285 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1286 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1287 BPF_ALU64_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1288 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1290 BPF_ALU64_REG(BPF_ADD
, R1
, R0
),
1291 BPF_ALU64_REG(BPF_ADD
, R1
, R1
),
1292 BPF_ALU64_REG(BPF_ADD
, R1
, R2
),
1293 BPF_ALU64_REG(BPF_ADD
, R1
, R3
),
1294 BPF_ALU64_REG(BPF_ADD
, R1
, R4
),
1295 BPF_ALU64_REG(BPF_ADD
, R1
, R5
),
1296 BPF_ALU64_REG(BPF_ADD
, R1
, R6
),
1297 BPF_ALU64_REG(BPF_ADD
, R1
, R7
),
1298 BPF_ALU64_REG(BPF_ADD
, R1
, R8
),
1299 BPF_ALU64_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1300 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1302 BPF_ALU64_REG(BPF_ADD
, R2
, R0
),
1303 BPF_ALU64_REG(BPF_ADD
, R2
, R1
),
1304 BPF_ALU64_REG(BPF_ADD
, R2
, R2
),
1305 BPF_ALU64_REG(BPF_ADD
, R2
, R3
),
1306 BPF_ALU64_REG(BPF_ADD
, R2
, R4
),
1307 BPF_ALU64_REG(BPF_ADD
, R2
, R5
),
1308 BPF_ALU64_REG(BPF_ADD
, R2
, R6
),
1309 BPF_ALU64_REG(BPF_ADD
, R2
, R7
),
1310 BPF_ALU64_REG(BPF_ADD
, R2
, R8
),
1311 BPF_ALU64_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1312 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1314 BPF_ALU64_REG(BPF_ADD
, R3
, R0
),
1315 BPF_ALU64_REG(BPF_ADD
, R3
, R1
),
1316 BPF_ALU64_REG(BPF_ADD
, R3
, R2
),
1317 BPF_ALU64_REG(BPF_ADD
, R3
, R3
),
1318 BPF_ALU64_REG(BPF_ADD
, R3
, R4
),
1319 BPF_ALU64_REG(BPF_ADD
, R3
, R5
),
1320 BPF_ALU64_REG(BPF_ADD
, R3
, R6
),
1321 BPF_ALU64_REG(BPF_ADD
, R3
, R7
),
1322 BPF_ALU64_REG(BPF_ADD
, R3
, R8
),
1323 BPF_ALU64_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1324 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1326 BPF_ALU64_REG(BPF_ADD
, R4
, R0
),
1327 BPF_ALU64_REG(BPF_ADD
, R4
, R1
),
1328 BPF_ALU64_REG(BPF_ADD
, R4
, R2
),
1329 BPF_ALU64_REG(BPF_ADD
, R4
, R3
),
1330 BPF_ALU64_REG(BPF_ADD
, R4
, R4
),
1331 BPF_ALU64_REG(BPF_ADD
, R4
, R5
),
1332 BPF_ALU64_REG(BPF_ADD
, R4
, R6
),
1333 BPF_ALU64_REG(BPF_ADD
, R4
, R7
),
1334 BPF_ALU64_REG(BPF_ADD
, R4
, R8
),
1335 BPF_ALU64_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1336 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1338 BPF_ALU64_REG(BPF_ADD
, R5
, R0
),
1339 BPF_ALU64_REG(BPF_ADD
, R5
, R1
),
1340 BPF_ALU64_REG(BPF_ADD
, R5
, R2
),
1341 BPF_ALU64_REG(BPF_ADD
, R5
, R3
),
1342 BPF_ALU64_REG(BPF_ADD
, R5
, R4
),
1343 BPF_ALU64_REG(BPF_ADD
, R5
, R5
),
1344 BPF_ALU64_REG(BPF_ADD
, R5
, R6
),
1345 BPF_ALU64_REG(BPF_ADD
, R5
, R7
),
1346 BPF_ALU64_REG(BPF_ADD
, R5
, R8
),
1347 BPF_ALU64_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1348 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1350 BPF_ALU64_REG(BPF_ADD
, R6
, R0
),
1351 BPF_ALU64_REG(BPF_ADD
, R6
, R1
),
1352 BPF_ALU64_REG(BPF_ADD
, R6
, R2
),
1353 BPF_ALU64_REG(BPF_ADD
, R6
, R3
),
1354 BPF_ALU64_REG(BPF_ADD
, R6
, R4
),
1355 BPF_ALU64_REG(BPF_ADD
, R6
, R5
),
1356 BPF_ALU64_REG(BPF_ADD
, R6
, R6
),
1357 BPF_ALU64_REG(BPF_ADD
, R6
, R7
),
1358 BPF_ALU64_REG(BPF_ADD
, R6
, R8
),
1359 BPF_ALU64_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1360 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1362 BPF_ALU64_REG(BPF_ADD
, R7
, R0
),
1363 BPF_ALU64_REG(BPF_ADD
, R7
, R1
),
1364 BPF_ALU64_REG(BPF_ADD
, R7
, R2
),
1365 BPF_ALU64_REG(BPF_ADD
, R7
, R3
),
1366 BPF_ALU64_REG(BPF_ADD
, R7
, R4
),
1367 BPF_ALU64_REG(BPF_ADD
, R7
, R5
),
1368 BPF_ALU64_REG(BPF_ADD
, R7
, R6
),
1369 BPF_ALU64_REG(BPF_ADD
, R7
, R7
),
1370 BPF_ALU64_REG(BPF_ADD
, R7
, R8
),
1371 BPF_ALU64_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1372 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1374 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1375 BPF_ALU64_REG(BPF_ADD
, R8
, R1
),
1376 BPF_ALU64_REG(BPF_ADD
, R8
, R2
),
1377 BPF_ALU64_REG(BPF_ADD
, R8
, R3
),
1378 BPF_ALU64_REG(BPF_ADD
, R8
, R4
),
1379 BPF_ALU64_REG(BPF_ADD
, R8
, R5
),
1380 BPF_ALU64_REG(BPF_ADD
, R8
, R6
),
1381 BPF_ALU64_REG(BPF_ADD
, R8
, R7
),
1382 BPF_ALU64_REG(BPF_ADD
, R8
, R8
),
1383 BPF_ALU64_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1384 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1386 BPF_ALU64_REG(BPF_ADD
, R9
, R0
),
1387 BPF_ALU64_REG(BPF_ADD
, R9
, R1
),
1388 BPF_ALU64_REG(BPF_ADD
, R9
, R2
),
1389 BPF_ALU64_REG(BPF_ADD
, R9
, R3
),
1390 BPF_ALU64_REG(BPF_ADD
, R9
, R4
),
1391 BPF_ALU64_REG(BPF_ADD
, R9
, R5
),
1392 BPF_ALU64_REG(BPF_ADD
, R9
, R6
),
1393 BPF_ALU64_REG(BPF_ADD
, R9
, R7
),
1394 BPF_ALU64_REG(BPF_ADD
, R9
, R8
),
1395 BPF_ALU64_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1396 BPF_ALU64_REG(BPF_MOV
, R0
, R9
),
1406 BPF_ALU32_IMM(BPF_MOV
, R0
, 20),
1407 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
1408 BPF_ALU32_IMM(BPF_MOV
, R2
, 2),
1409 BPF_ALU32_IMM(BPF_MOV
, R3
, 3),
1410 BPF_ALU32_IMM(BPF_MOV
, R4
, 4),
1411 BPF_ALU32_IMM(BPF_MOV
, R5
, 5),
1412 BPF_ALU32_IMM(BPF_MOV
, R6
, 6),
1413 BPF_ALU32_IMM(BPF_MOV
, R7
, 7),
1414 BPF_ALU32_IMM(BPF_MOV
, R8
, 8),
1415 BPF_ALU32_IMM(BPF_MOV
, R9
, 9),
1416 BPF_ALU64_IMM(BPF_ADD
, R1
, 10),
1417 BPF_ALU64_IMM(BPF_ADD
, R2
, 10),
1418 BPF_ALU64_IMM(BPF_ADD
, R3
, 10),
1419 BPF_ALU64_IMM(BPF_ADD
, R4
, 10),
1420 BPF_ALU64_IMM(BPF_ADD
, R5
, 10),
1421 BPF_ALU64_IMM(BPF_ADD
, R6
, 10),
1422 BPF_ALU64_IMM(BPF_ADD
, R7
, 10),
1423 BPF_ALU64_IMM(BPF_ADD
, R8
, 10),
1424 BPF_ALU64_IMM(BPF_ADD
, R9
, 10),
1425 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
1426 BPF_ALU32_REG(BPF_ADD
, R0
, R2
),
1427 BPF_ALU32_REG(BPF_ADD
, R0
, R3
),
1428 BPF_ALU32_REG(BPF_ADD
, R0
, R4
),
1429 BPF_ALU32_REG(BPF_ADD
, R0
, R5
),
1430 BPF_ALU32_REG(BPF_ADD
, R0
, R6
),
1431 BPF_ALU32_REG(BPF_ADD
, R0
, R7
),
1432 BPF_ALU32_REG(BPF_ADD
, R0
, R8
),
1433 BPF_ALU32_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1434 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1436 BPF_ALU32_REG(BPF_ADD
, R1
, R0
),
1437 BPF_ALU32_REG(BPF_ADD
, R1
, R1
),
1438 BPF_ALU32_REG(BPF_ADD
, R1
, R2
),
1439 BPF_ALU32_REG(BPF_ADD
, R1
, R3
),
1440 BPF_ALU32_REG(BPF_ADD
, R1
, R4
),
1441 BPF_ALU32_REG(BPF_ADD
, R1
, R5
),
1442 BPF_ALU32_REG(BPF_ADD
, R1
, R6
),
1443 BPF_ALU32_REG(BPF_ADD
, R1
, R7
),
1444 BPF_ALU32_REG(BPF_ADD
, R1
, R8
),
1445 BPF_ALU32_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1446 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1448 BPF_ALU32_REG(BPF_ADD
, R2
, R0
),
1449 BPF_ALU32_REG(BPF_ADD
, R2
, R1
),
1450 BPF_ALU32_REG(BPF_ADD
, R2
, R2
),
1451 BPF_ALU32_REG(BPF_ADD
, R2
, R3
),
1452 BPF_ALU32_REG(BPF_ADD
, R2
, R4
),
1453 BPF_ALU32_REG(BPF_ADD
, R2
, R5
),
1454 BPF_ALU32_REG(BPF_ADD
, R2
, R6
),
1455 BPF_ALU32_REG(BPF_ADD
, R2
, R7
),
1456 BPF_ALU32_REG(BPF_ADD
, R2
, R8
),
1457 BPF_ALU32_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1458 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1460 BPF_ALU32_REG(BPF_ADD
, R3
, R0
),
1461 BPF_ALU32_REG(BPF_ADD
, R3
, R1
),
1462 BPF_ALU32_REG(BPF_ADD
, R3
, R2
),
1463 BPF_ALU32_REG(BPF_ADD
, R3
, R3
),
1464 BPF_ALU32_REG(BPF_ADD
, R3
, R4
),
1465 BPF_ALU32_REG(BPF_ADD
, R3
, R5
),
1466 BPF_ALU32_REG(BPF_ADD
, R3
, R6
),
1467 BPF_ALU32_REG(BPF_ADD
, R3
, R7
),
1468 BPF_ALU32_REG(BPF_ADD
, R3
, R8
),
1469 BPF_ALU32_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1470 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1472 BPF_ALU32_REG(BPF_ADD
, R4
, R0
),
1473 BPF_ALU32_REG(BPF_ADD
, R4
, R1
),
1474 BPF_ALU32_REG(BPF_ADD
, R4
, R2
),
1475 BPF_ALU32_REG(BPF_ADD
, R4
, R3
),
1476 BPF_ALU32_REG(BPF_ADD
, R4
, R4
),
1477 BPF_ALU32_REG(BPF_ADD
, R4
, R5
),
1478 BPF_ALU32_REG(BPF_ADD
, R4
, R6
),
1479 BPF_ALU32_REG(BPF_ADD
, R4
, R7
),
1480 BPF_ALU32_REG(BPF_ADD
, R4
, R8
),
1481 BPF_ALU32_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1482 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1484 BPF_ALU32_REG(BPF_ADD
, R5
, R0
),
1485 BPF_ALU32_REG(BPF_ADD
, R5
, R1
),
1486 BPF_ALU32_REG(BPF_ADD
, R5
, R2
),
1487 BPF_ALU32_REG(BPF_ADD
, R5
, R3
),
1488 BPF_ALU32_REG(BPF_ADD
, R5
, R4
),
1489 BPF_ALU32_REG(BPF_ADD
, R5
, R5
),
1490 BPF_ALU32_REG(BPF_ADD
, R5
, R6
),
1491 BPF_ALU32_REG(BPF_ADD
, R5
, R7
),
1492 BPF_ALU32_REG(BPF_ADD
, R5
, R8
),
1493 BPF_ALU32_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1494 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1496 BPF_ALU32_REG(BPF_ADD
, R6
, R0
),
1497 BPF_ALU32_REG(BPF_ADD
, R6
, R1
),
1498 BPF_ALU32_REG(BPF_ADD
, R6
, R2
),
1499 BPF_ALU32_REG(BPF_ADD
, R6
, R3
),
1500 BPF_ALU32_REG(BPF_ADD
, R6
, R4
),
1501 BPF_ALU32_REG(BPF_ADD
, R6
, R5
),
1502 BPF_ALU32_REG(BPF_ADD
, R6
, R6
),
1503 BPF_ALU32_REG(BPF_ADD
, R6
, R7
),
1504 BPF_ALU32_REG(BPF_ADD
, R6
, R8
),
1505 BPF_ALU32_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1506 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1508 BPF_ALU32_REG(BPF_ADD
, R7
, R0
),
1509 BPF_ALU32_REG(BPF_ADD
, R7
, R1
),
1510 BPF_ALU32_REG(BPF_ADD
, R7
, R2
),
1511 BPF_ALU32_REG(BPF_ADD
, R7
, R3
),
1512 BPF_ALU32_REG(BPF_ADD
, R7
, R4
),
1513 BPF_ALU32_REG(BPF_ADD
, R7
, R5
),
1514 BPF_ALU32_REG(BPF_ADD
, R7
, R6
),
1515 BPF_ALU32_REG(BPF_ADD
, R7
, R7
),
1516 BPF_ALU32_REG(BPF_ADD
, R7
, R8
),
1517 BPF_ALU32_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1518 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1520 BPF_ALU32_REG(BPF_ADD
, R8
, R0
),
1521 BPF_ALU32_REG(BPF_ADD
, R8
, R1
),
1522 BPF_ALU32_REG(BPF_ADD
, R8
, R2
),
1523 BPF_ALU32_REG(BPF_ADD
, R8
, R3
),
1524 BPF_ALU32_REG(BPF_ADD
, R8
, R4
),
1525 BPF_ALU32_REG(BPF_ADD
, R8
, R5
),
1526 BPF_ALU32_REG(BPF_ADD
, R8
, R6
),
1527 BPF_ALU32_REG(BPF_ADD
, R8
, R7
),
1528 BPF_ALU32_REG(BPF_ADD
, R8
, R8
),
1529 BPF_ALU32_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1530 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1532 BPF_ALU32_REG(BPF_ADD
, R9
, R0
),
1533 BPF_ALU32_REG(BPF_ADD
, R9
, R1
),
1534 BPF_ALU32_REG(BPF_ADD
, R9
, R2
),
1535 BPF_ALU32_REG(BPF_ADD
, R9
, R3
),
1536 BPF_ALU32_REG(BPF_ADD
, R9
, R4
),
1537 BPF_ALU32_REG(BPF_ADD
, R9
, R5
),
1538 BPF_ALU32_REG(BPF_ADD
, R9
, R6
),
1539 BPF_ALU32_REG(BPF_ADD
, R9
, R7
),
1540 BPF_ALU32_REG(BPF_ADD
, R9
, R8
),
1541 BPF_ALU32_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1542 BPF_ALU32_REG(BPF_MOV
, R0
, R9
),
1549 { /* Mainly checking JIT here. */
1552 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1553 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1554 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1555 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1556 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1557 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1558 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1559 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1560 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1561 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1562 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1563 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1564 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1565 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1566 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1567 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1568 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1569 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1570 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1571 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1572 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1573 BPF_JMP_IMM(BPF_JEQ
, R0
, -55, 1),
1575 BPF_ALU64_REG(BPF_SUB
, R1
, R0
),
1576 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1577 BPF_ALU64_REG(BPF_SUB
, R1
, R3
),
1578 BPF_ALU64_REG(BPF_SUB
, R1
, R4
),
1579 BPF_ALU64_REG(BPF_SUB
, R1
, R5
),
1580 BPF_ALU64_REG(BPF_SUB
, R1
, R6
),
1581 BPF_ALU64_REG(BPF_SUB
, R1
, R7
),
1582 BPF_ALU64_REG(BPF_SUB
, R1
, R8
),
1583 BPF_ALU64_REG(BPF_SUB
, R1
, R9
),
1584 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1585 BPF_ALU64_REG(BPF_SUB
, R2
, R0
),
1586 BPF_ALU64_REG(BPF_SUB
, R2
, R1
),
1587 BPF_ALU64_REG(BPF_SUB
, R2
, R3
),
1588 BPF_ALU64_REG(BPF_SUB
, R2
, R4
),
1589 BPF_ALU64_REG(BPF_SUB
, R2
, R5
),
1590 BPF_ALU64_REG(BPF_SUB
, R2
, R6
),
1591 BPF_ALU64_REG(BPF_SUB
, R2
, R7
),
1592 BPF_ALU64_REG(BPF_SUB
, R2
, R8
),
1593 BPF_ALU64_REG(BPF_SUB
, R2
, R9
),
1594 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1595 BPF_ALU64_REG(BPF_SUB
, R3
, R0
),
1596 BPF_ALU64_REG(BPF_SUB
, R3
, R1
),
1597 BPF_ALU64_REG(BPF_SUB
, R3
, R2
),
1598 BPF_ALU64_REG(BPF_SUB
, R3
, R4
),
1599 BPF_ALU64_REG(BPF_SUB
, R3
, R5
),
1600 BPF_ALU64_REG(BPF_SUB
, R3
, R6
),
1601 BPF_ALU64_REG(BPF_SUB
, R3
, R7
),
1602 BPF_ALU64_REG(BPF_SUB
, R3
, R8
),
1603 BPF_ALU64_REG(BPF_SUB
, R3
, R9
),
1604 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1605 BPF_ALU64_REG(BPF_SUB
, R4
, R0
),
1606 BPF_ALU64_REG(BPF_SUB
, R4
, R1
),
1607 BPF_ALU64_REG(BPF_SUB
, R4
, R2
),
1608 BPF_ALU64_REG(BPF_SUB
, R4
, R3
),
1609 BPF_ALU64_REG(BPF_SUB
, R4
, R5
),
1610 BPF_ALU64_REG(BPF_SUB
, R4
, R6
),
1611 BPF_ALU64_REG(BPF_SUB
, R4
, R7
),
1612 BPF_ALU64_REG(BPF_SUB
, R4
, R8
),
1613 BPF_ALU64_REG(BPF_SUB
, R4
, R9
),
1614 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1615 BPF_ALU64_REG(BPF_SUB
, R5
, R0
),
1616 BPF_ALU64_REG(BPF_SUB
, R5
, R1
),
1617 BPF_ALU64_REG(BPF_SUB
, R5
, R2
),
1618 BPF_ALU64_REG(BPF_SUB
, R5
, R3
),
1619 BPF_ALU64_REG(BPF_SUB
, R5
, R4
),
1620 BPF_ALU64_REG(BPF_SUB
, R5
, R6
),
1621 BPF_ALU64_REG(BPF_SUB
, R5
, R7
),
1622 BPF_ALU64_REG(BPF_SUB
, R5
, R8
),
1623 BPF_ALU64_REG(BPF_SUB
, R5
, R9
),
1624 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1625 BPF_ALU64_REG(BPF_SUB
, R6
, R0
),
1626 BPF_ALU64_REG(BPF_SUB
, R6
, R1
),
1627 BPF_ALU64_REG(BPF_SUB
, R6
, R2
),
1628 BPF_ALU64_REG(BPF_SUB
, R6
, R3
),
1629 BPF_ALU64_REG(BPF_SUB
, R6
, R4
),
1630 BPF_ALU64_REG(BPF_SUB
, R6
, R5
),
1631 BPF_ALU64_REG(BPF_SUB
, R6
, R7
),
1632 BPF_ALU64_REG(BPF_SUB
, R6
, R8
),
1633 BPF_ALU64_REG(BPF_SUB
, R6
, R9
),
1634 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1635 BPF_ALU64_REG(BPF_SUB
, R7
, R0
),
1636 BPF_ALU64_REG(BPF_SUB
, R7
, R1
),
1637 BPF_ALU64_REG(BPF_SUB
, R7
, R2
),
1638 BPF_ALU64_REG(BPF_SUB
, R7
, R3
),
1639 BPF_ALU64_REG(BPF_SUB
, R7
, R4
),
1640 BPF_ALU64_REG(BPF_SUB
, R7
, R5
),
1641 BPF_ALU64_REG(BPF_SUB
, R7
, R6
),
1642 BPF_ALU64_REG(BPF_SUB
, R7
, R8
),
1643 BPF_ALU64_REG(BPF_SUB
, R7
, R9
),
1644 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1645 BPF_ALU64_REG(BPF_SUB
, R8
, R0
),
1646 BPF_ALU64_REG(BPF_SUB
, R8
, R1
),
1647 BPF_ALU64_REG(BPF_SUB
, R8
, R2
),
1648 BPF_ALU64_REG(BPF_SUB
, R8
, R3
),
1649 BPF_ALU64_REG(BPF_SUB
, R8
, R4
),
1650 BPF_ALU64_REG(BPF_SUB
, R8
, R5
),
1651 BPF_ALU64_REG(BPF_SUB
, R8
, R6
),
1652 BPF_ALU64_REG(BPF_SUB
, R8
, R7
),
1653 BPF_ALU64_REG(BPF_SUB
, R8
, R9
),
1654 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1655 BPF_ALU64_REG(BPF_SUB
, R9
, R0
),
1656 BPF_ALU64_REG(BPF_SUB
, R9
, R1
),
1657 BPF_ALU64_REG(BPF_SUB
, R9
, R2
),
1658 BPF_ALU64_REG(BPF_SUB
, R9
, R3
),
1659 BPF_ALU64_REG(BPF_SUB
, R9
, R4
),
1660 BPF_ALU64_REG(BPF_SUB
, R9
, R5
),
1661 BPF_ALU64_REG(BPF_SUB
, R9
, R6
),
1662 BPF_ALU64_REG(BPF_SUB
, R9
, R7
),
1663 BPF_ALU64_REG(BPF_SUB
, R9
, R8
),
1664 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1665 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1666 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
1667 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1668 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1669 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1670 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1671 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1672 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1673 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1674 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1675 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1682 { /* Mainly checking JIT here. */
1685 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1686 BPF_ALU64_REG(BPF_XOR
, R1
, R1
),
1687 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 1),
1689 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1690 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1691 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1692 BPF_ALU64_REG(BPF_XOR
, R2
, R2
),
1693 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
1695 BPF_ALU64_REG(BPF_SUB
, R2
, R2
),
1696 BPF_ALU64_REG(BPF_XOR
, R3
, R3
),
1697 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1698 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1699 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 1),
1701 BPF_ALU64_REG(BPF_SUB
, R3
, R3
),
1702 BPF_ALU64_REG(BPF_XOR
, R4
, R4
),
1703 BPF_ALU64_IMM(BPF_MOV
, R2
, 1),
1704 BPF_ALU64_IMM(BPF_MOV
, R5
, -1),
1705 BPF_JMP_REG(BPF_JEQ
, R3
, R4
, 1),
1707 BPF_ALU64_REG(BPF_SUB
, R4
, R4
),
1708 BPF_ALU64_REG(BPF_XOR
, R5
, R5
),
1709 BPF_ALU64_IMM(BPF_MOV
, R3
, 1),
1710 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
1711 BPF_JMP_REG(BPF_JEQ
, R5
, R4
, 1),
1713 BPF_ALU64_IMM(BPF_MOV
, R5
, 1),
1714 BPF_ALU64_REG(BPF_SUB
, R5
, R5
),
1715 BPF_ALU64_REG(BPF_XOR
, R6
, R6
),
1716 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1717 BPF_ALU64_IMM(BPF_MOV
, R8
, -1),
1718 BPF_JMP_REG(BPF_JEQ
, R5
, R6
, 1),
1720 BPF_ALU64_REG(BPF_SUB
, R6
, R6
),
1721 BPF_ALU64_REG(BPF_XOR
, R7
, R7
),
1722 BPF_JMP_REG(BPF_JEQ
, R7
, R6
, 1),
1724 BPF_ALU64_REG(BPF_SUB
, R7
, R7
),
1725 BPF_ALU64_REG(BPF_XOR
, R8
, R8
),
1726 BPF_JMP_REG(BPF_JEQ
, R7
, R8
, 1),
1728 BPF_ALU64_REG(BPF_SUB
, R8
, R8
),
1729 BPF_ALU64_REG(BPF_XOR
, R9
, R9
),
1730 BPF_JMP_REG(BPF_JEQ
, R9
, R8
, 1),
1732 BPF_ALU64_REG(BPF_SUB
, R9
, R9
),
1733 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1734 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 1),
1736 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1737 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1738 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 2),
1739 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1741 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1748 { /* Mainly checking JIT here. */
1751 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1752 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1753 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1754 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1755 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1756 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1757 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1758 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1759 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1760 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1761 BPF_ALU64_REG(BPF_MUL
, R0
, R0
),
1762 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
1763 BPF_ALU64_REG(BPF_MUL
, R0
, R2
),
1764 BPF_ALU64_REG(BPF_MUL
, R0
, R3
),
1765 BPF_ALU64_REG(BPF_MUL
, R0
, R4
),
1766 BPF_ALU64_REG(BPF_MUL
, R0
, R5
),
1767 BPF_ALU64_REG(BPF_MUL
, R0
, R6
),
1768 BPF_ALU64_REG(BPF_MUL
, R0
, R7
),
1769 BPF_ALU64_REG(BPF_MUL
, R0
, R8
),
1770 BPF_ALU64_REG(BPF_MUL
, R0
, R9
),
1771 BPF_ALU64_IMM(BPF_MUL
, R0
, 10),
1772 BPF_JMP_IMM(BPF_JEQ
, R0
, 439084800, 1),
1774 BPF_ALU64_REG(BPF_MUL
, R1
, R0
),
1775 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1776 BPF_ALU64_REG(BPF_MUL
, R1
, R3
),
1777 BPF_ALU64_REG(BPF_MUL
, R1
, R4
),
1778 BPF_ALU64_REG(BPF_MUL
, R1
, R5
),
1779 BPF_ALU64_REG(BPF_MUL
, R1
, R6
),
1780 BPF_ALU64_REG(BPF_MUL
, R1
, R7
),
1781 BPF_ALU64_REG(BPF_MUL
, R1
, R8
),
1782 BPF_ALU64_REG(BPF_MUL
, R1
, R9
),
1783 BPF_ALU64_IMM(BPF_MUL
, R1
, 10),
1784 BPF_ALU64_REG(BPF_MOV
, R2
, R1
),
1785 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1786 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5a924, 1),
1788 BPF_ALU64_IMM(BPF_LSH
, R1
, 32),
1789 BPF_ALU64_IMM(BPF_ARSH
, R1
, 32),
1790 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xebb90000, 1),
1792 BPF_ALU64_REG(BPF_MUL
, R2
, R0
),
1793 BPF_ALU64_REG(BPF_MUL
, R2
, R1
),
1794 BPF_ALU64_REG(BPF_MUL
, R2
, R3
),
1795 BPF_ALU64_REG(BPF_MUL
, R2
, R4
),
1796 BPF_ALU64_REG(BPF_MUL
, R2
, R5
),
1797 BPF_ALU64_REG(BPF_MUL
, R2
, R6
),
1798 BPF_ALU64_REG(BPF_MUL
, R2
, R7
),
1799 BPF_ALU64_REG(BPF_MUL
, R2
, R8
),
1800 BPF_ALU64_REG(BPF_MUL
, R2
, R9
),
1801 BPF_ALU64_IMM(BPF_MUL
, R2
, 10),
1802 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1803 BPF_ALU64_REG(BPF_MOV
, R0
, R2
),
1808 { { 0, 0x35d97ef2 } }
1810 { /* Mainly checking JIT here. */
1813 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1814 BPF_MOV64_REG(R1
, R0
),
1815 BPF_MOV64_REG(R2
, R1
),
1816 BPF_MOV64_REG(R3
, R2
),
1817 BPF_MOV64_REG(R4
, R3
),
1818 BPF_MOV64_REG(R5
, R4
),
1819 BPF_MOV64_REG(R6
, R5
),
1820 BPF_MOV64_REG(R7
, R6
),
1821 BPF_MOV64_REG(R8
, R7
),
1822 BPF_MOV64_REG(R9
, R8
),
1823 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1824 BPF_ALU64_IMM(BPF_MOV
, R1
, 0),
1825 BPF_ALU64_IMM(BPF_MOV
, R2
, 0),
1826 BPF_ALU64_IMM(BPF_MOV
, R3
, 0),
1827 BPF_ALU64_IMM(BPF_MOV
, R4
, 0),
1828 BPF_ALU64_IMM(BPF_MOV
, R5
, 0),
1829 BPF_ALU64_IMM(BPF_MOV
, R6
, 0),
1830 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
1831 BPF_ALU64_IMM(BPF_MOV
, R8
, 0),
1832 BPF_ALU64_IMM(BPF_MOV
, R9
, 0),
1833 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1834 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1835 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1836 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1837 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1838 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1839 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1840 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1841 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1842 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1843 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1850 { /* Mainly checking JIT here. */
1853 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1854 BPF_MOV64_REG(R1
, R0
),
1855 BPF_MOV64_REG(R2
, R1
),
1856 BPF_MOV64_REG(R3
, R2
),
1857 BPF_MOV64_REG(R4
, R3
),
1858 BPF_MOV64_REG(R5
, R4
),
1859 BPF_MOV64_REG(R6
, R5
),
1860 BPF_MOV64_REG(R7
, R6
),
1861 BPF_MOV64_REG(R8
, R7
),
1862 BPF_MOV64_REG(R9
, R8
),
1863 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
1864 BPF_ALU32_IMM(BPF_MOV
, R1
, 0),
1865 BPF_ALU32_IMM(BPF_MOV
, R2
, 0),
1866 BPF_ALU32_IMM(BPF_MOV
, R3
, 0),
1867 BPF_ALU32_IMM(BPF_MOV
, R4
, 0),
1868 BPF_ALU32_IMM(BPF_MOV
, R5
, 0),
1869 BPF_ALU32_IMM(BPF_MOV
, R6
, 0),
1870 BPF_ALU32_IMM(BPF_MOV
, R7
, 0),
1871 BPF_ALU32_IMM(BPF_MOV
, R8
, 0),
1872 BPF_ALU32_IMM(BPF_MOV
, R9
, 0),
1873 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1874 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1875 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1876 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1877 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1878 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1879 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1880 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1881 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1882 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1883 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1890 { /* Mainly checking JIT here. */
1893 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1894 BPF_MOV64_REG(R1
, R0
),
1895 BPF_MOV64_REG(R2
, R1
),
1896 BPF_MOV64_REG(R3
, R2
),
1897 BPF_MOV64_REG(R4
, R3
),
1898 BPF_MOV64_REG(R5
, R4
),
1899 BPF_MOV64_REG(R6
, R5
),
1900 BPF_MOV64_REG(R7
, R6
),
1901 BPF_MOV64_REG(R8
, R7
),
1902 BPF_MOV64_REG(R9
, R8
),
1903 BPF_LD_IMM64(R0
, 0x0LL
),
1904 BPF_LD_IMM64(R1
, 0x0LL
),
1905 BPF_LD_IMM64(R2
, 0x0LL
),
1906 BPF_LD_IMM64(R3
, 0x0LL
),
1907 BPF_LD_IMM64(R4
, 0x0LL
),
1908 BPF_LD_IMM64(R5
, 0x0LL
),
1909 BPF_LD_IMM64(R6
, 0x0LL
),
1910 BPF_LD_IMM64(R7
, 0x0LL
),
1911 BPF_LD_IMM64(R8
, 0x0LL
),
1912 BPF_LD_IMM64(R9
, 0x0LL
),
1913 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1914 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1915 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1916 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1917 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1918 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1919 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1920 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1921 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1922 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1923 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1933 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1934 BPF_ALU64_IMM(BPF_ADD
, R0
, -1),
1935 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1936 BPF_ALU64_IMM(BPF_XOR
, R2
, 3),
1937 BPF_ALU64_REG(BPF_DIV
, R0
, R2
),
1938 BPF_JMP_IMM(BPF_JEQ
, R0
, 10, 1),
1940 BPF_ALU64_IMM(BPF_MOD
, R0
, 3),
1941 BPF_JMP_IMM(BPF_JEQ
, R0
, 1, 1),
1943 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1951 "INT: shifts by register",
1953 BPF_MOV64_IMM(R0
, -1234),
1954 BPF_MOV64_IMM(R1
, 1),
1955 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
1956 BPF_JMP_IMM(BPF_JEQ
, R0
, 0x7ffffd97, 1),
1958 BPF_MOV64_IMM(R2
, 1),
1959 BPF_ALU64_REG(BPF_LSH
, R0
, R2
),
1960 BPF_MOV32_IMM(R4
, -1234),
1961 BPF_JMP_REG(BPF_JEQ
, R0
, R4
, 1),
1963 BPF_ALU64_IMM(BPF_AND
, R4
, 63),
1964 BPF_ALU64_REG(BPF_LSH
, R0
, R4
), /* R0 <= 46 */
1965 BPF_MOV64_IMM(R3
, 47),
1966 BPF_ALU64_REG(BPF_ARSH
, R0
, R3
),
1967 BPF_JMP_IMM(BPF_JEQ
, R0
, -617, 1),
1969 BPF_MOV64_IMM(R2
, 1),
1970 BPF_ALU64_REG(BPF_LSH
, R4
, R2
), /* R4 = 46 << 1 */
1971 BPF_JMP_IMM(BPF_JEQ
, R4
, 92, 1),
1973 BPF_MOV64_IMM(R4
, 4),
1974 BPF_ALU64_REG(BPF_LSH
, R4
, R4
), /* R4 = 4 << 4 */
1975 BPF_JMP_IMM(BPF_JEQ
, R4
, 64, 1),
1977 BPF_MOV64_IMM(R4
, 5),
1978 BPF_ALU32_REG(BPF_LSH
, R4
, R4
), /* R4 = 5 << 5 */
1979 BPF_JMP_IMM(BPF_JEQ
, R4
, 160, 1),
1981 BPF_MOV64_IMM(R0
, -1),
1991 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
1992 BPF_LD_ABS(BPF_B
, 3),
1993 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1994 BPF_ALU32_REG(BPF_DIV
, R0
, R2
),
1995 BPF_ALU64_REG(BPF_MOV
, R8
, R0
),
1996 BPF_LD_ABS(BPF_B
, 4),
1997 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1998 BPF_LD_IND(BPF_B
, R8
, -70),
2002 { 10, 20, 30, 40, 50 },
2003 { { 4, 0 }, { 5, 10 } }
2008 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
2009 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
2010 BPF_LD_ABS(BPF_B
, 3),
2011 BPF_ALU32_REG(BPF_DIV
, R0
, R7
),
2015 { 10, 20, 30, 40, 50 },
2016 { { 3, 0 }, { 4, 0 } }
2019 "check: missing ret",
2021 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
2023 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2030 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0),
2031 BPF_STMT(BPF_RET
| BPF_K
, 0)
2033 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2038 "check: unknown insn",
2040 /* seccomp insn, rejected in socket filter */
2041 BPF_STMT(BPF_LDX
| BPF_W
| BPF_ABS
, 0),
2042 BPF_STMT(BPF_RET
| BPF_K
, 0)
2044 CLASSIC
| FLAG_EXPECTED_FAIL
,
2049 "check: out of range spill/fill",
2051 BPF_STMT(BPF_STX
, 16),
2052 BPF_STMT(BPF_RET
| BPF_K
, 0)
2054 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2061 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2062 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 15),
2063 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2064 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2065 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2066 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2067 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2068 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2069 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2070 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2071 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2072 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2073 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2074 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2075 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2076 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 3, 4),
2077 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2078 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 1, 2),
2079 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2080 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2081 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2082 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2083 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2084 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2085 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2086 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2087 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2088 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2089 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2090 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2091 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2092 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2093 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2094 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2095 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 2, 3),
2096 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 1, 2),
2097 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2098 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2099 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2100 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2101 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2102 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2103 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2104 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2105 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2106 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2107 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2108 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2109 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2110 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2111 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2112 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2113 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 2, 3),
2114 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 1, 2),
2115 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2116 BPF_STMT(BPF_RET
| BPF_A
, 0),
2117 BPF_STMT(BPF_RET
| BPF_A
, 0),
2120 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2121 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2123 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2124 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2125 0xc0, 0xa8, 0x33, 0x01,
2126 0xc0, 0xa8, 0x33, 0x02,
2129 0x00, 0x14, 0x00, 0x00,
2130 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2131 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2132 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2133 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2134 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2135 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2136 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2137 0xcc, 0xcc, 0xcc, 0xcc },
2143 BPF_STMT(BPF_RET
| BPF_X
, 0),
2145 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2150 "check: LDX + RET X",
2152 BPF_STMT(BPF_LDX
| BPF_IMM
, 42),
2153 BPF_STMT(BPF_RET
| BPF_X
, 0),
2155 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2159 { /* Mainly checking JIT here. */
2160 "M[]: alt STX + LDX",
2162 BPF_STMT(BPF_LDX
| BPF_IMM
, 100),
2163 BPF_STMT(BPF_STX
, 0),
2164 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2165 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2166 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2167 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2168 BPF_STMT(BPF_STX
, 1),
2169 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2170 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2171 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2172 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2173 BPF_STMT(BPF_STX
, 2),
2174 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2175 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2176 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2177 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2178 BPF_STMT(BPF_STX
, 3),
2179 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2180 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2181 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2182 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2183 BPF_STMT(BPF_STX
, 4),
2184 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2185 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2186 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2187 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2188 BPF_STMT(BPF_STX
, 5),
2189 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2190 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2191 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2192 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2193 BPF_STMT(BPF_STX
, 6),
2194 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2195 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2196 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2197 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2198 BPF_STMT(BPF_STX
, 7),
2199 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2200 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2201 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2202 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2203 BPF_STMT(BPF_STX
, 8),
2204 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2205 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2206 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2207 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2208 BPF_STMT(BPF_STX
, 9),
2209 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2210 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2211 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2212 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2213 BPF_STMT(BPF_STX
, 10),
2214 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2215 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2216 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2217 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2218 BPF_STMT(BPF_STX
, 11),
2219 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2220 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2221 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2222 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2223 BPF_STMT(BPF_STX
, 12),
2224 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2225 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2226 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2227 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2228 BPF_STMT(BPF_STX
, 13),
2229 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2230 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2231 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2232 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2233 BPF_STMT(BPF_STX
, 14),
2234 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2235 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2236 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2237 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2238 BPF_STMT(BPF_STX
, 15),
2239 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2240 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2241 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2242 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2243 BPF_STMT(BPF_RET
| BPF_A
, 0),
2245 CLASSIC
| FLAG_NO_DATA
,
2249 { /* Mainly checking JIT here. */
2250 "M[]: full STX + full LDX",
2252 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbadfeedb),
2253 BPF_STMT(BPF_STX
, 0),
2254 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xecabedae),
2255 BPF_STMT(BPF_STX
, 1),
2256 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xafccfeaf),
2257 BPF_STMT(BPF_STX
, 2),
2258 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbffdcedc),
2259 BPF_STMT(BPF_STX
, 3),
2260 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbbbdccb),
2261 BPF_STMT(BPF_STX
, 4),
2262 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbabcbda),
2263 BPF_STMT(BPF_STX
, 5),
2264 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaedecbdb),
2265 BPF_STMT(BPF_STX
, 6),
2266 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xadebbade),
2267 BPF_STMT(BPF_STX
, 7),
2268 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfcfcfaec),
2269 BPF_STMT(BPF_STX
, 8),
2270 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbcdddbdc),
2271 BPF_STMT(BPF_STX
, 9),
2272 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfeefdfac),
2273 BPF_STMT(BPF_STX
, 10),
2274 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xcddcdeea),
2275 BPF_STMT(BPF_STX
, 11),
2276 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaccfaebb),
2277 BPF_STMT(BPF_STX
, 12),
2278 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbdcccdcf),
2279 BPF_STMT(BPF_STX
, 13),
2280 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaaedecde),
2281 BPF_STMT(BPF_STX
, 14),
2282 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfaeacdad),
2283 BPF_STMT(BPF_STX
, 15),
2284 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2285 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2286 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2287 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2288 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2289 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2290 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2291 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2292 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2293 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2294 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2295 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2296 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2297 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2298 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2299 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2300 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2301 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2302 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2303 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2304 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2305 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2306 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2307 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2308 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2309 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2310 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2311 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2312 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2313 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2314 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2315 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2316 BPF_STMT(BPF_RET
| BPF_A
, 0),
2318 CLASSIC
| FLAG_NO_DATA
,
2320 { { 0, 0x2a5a5e5 } },
2323 "check: SKF_AD_MAX",
2325 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2326 SKF_AD_OFF
+ SKF_AD_MAX
),
2327 BPF_STMT(BPF_RET
| BPF_A
, 0),
2329 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2333 { /* Passes checker but fails during runtime. */
2334 "LD [SKF_AD_OFF-1]",
2336 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2338 BPF_STMT(BPF_RET
| BPF_K
, 1),
2345 "load 64-bit immediate",
2347 BPF_LD_IMM64(R1
, 0x567800001234LL
),
2348 BPF_MOV64_REG(R2
, R1
),
2349 BPF_MOV64_REG(R3
, R2
),
2350 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
2351 BPF_ALU64_IMM(BPF_LSH
, R3
, 32),
2352 BPF_ALU64_IMM(BPF_RSH
, R3
, 32),
2353 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
2354 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5678, 1),
2356 BPF_JMP_IMM(BPF_JEQ
, R3
, 0x1234, 1),
2358 BPF_LD_IMM64(R0
, 0x1ffffffffLL
),
2359 BPF_ALU64_IMM(BPF_RSH
, R0
, 32), /* R0 = 1 */
2369 BPF_MOV64_REG(R6
, R1
),
2370 BPF_LD_ABS(BPF_H
, 12),
2371 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 28),
2372 BPF_LD_ABS(BPF_H
, 12),
2373 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 26),
2374 BPF_MOV32_IMM(R0
, 18),
2375 BPF_STX_MEM(BPF_W
, R10
, R0
, -64),
2376 BPF_LDX_MEM(BPF_W
, R7
, R10
, -64),
2377 BPF_LD_IND(BPF_W
, R7
, 14),
2378 BPF_STX_MEM(BPF_W
, R10
, R0
, -60),
2379 BPF_MOV32_IMM(R0
, 280971478),
2380 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2381 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2382 BPF_LDX_MEM(BPF_W
, R0
, R10
, -60),
2383 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2384 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 15),
2385 BPF_LD_ABS(BPF_H
, 12),
2386 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 13),
2387 BPF_MOV32_IMM(R0
, 22),
2388 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2389 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2390 BPF_LD_IND(BPF_H
, R7
, 14),
2391 BPF_STX_MEM(BPF_W
, R10
, R0
, -52),
2392 BPF_MOV32_IMM(R0
, 17366),
2393 BPF_STX_MEM(BPF_W
, R10
, R0
, -48),
2394 BPF_LDX_MEM(BPF_W
, R7
, R10
, -48),
2395 BPF_LDX_MEM(BPF_W
, R0
, R10
, -52),
2396 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2397 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 2),
2398 BPF_MOV32_IMM(R0
, 256),
2400 BPF_MOV32_IMM(R0
, 0),
2404 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2405 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2406 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2410 /* BPF_ALU | BPF_MOV | BPF_X */
2412 "ALU_MOV_X: dst = 2",
2414 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2415 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2423 "ALU_MOV_X: dst = 4294967295",
2425 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2426 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2431 { { 0, 4294967295U } },
2434 "ALU64_MOV_X: dst = 2",
2436 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2437 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2445 "ALU64_MOV_X: dst = 4294967295",
2447 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2448 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2453 { { 0, 4294967295U } },
2455 /* BPF_ALU | BPF_MOV | BPF_K */
2457 "ALU_MOV_K: dst = 2",
2459 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
2467 "ALU_MOV_K: dst = 4294967295",
2469 BPF_ALU32_IMM(BPF_MOV
, R0
, 4294967295U),
2474 { { 0, 4294967295U } },
2477 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2479 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2480 BPF_LD_IMM64(R3
, 0x00000000ffffffffLL
),
2481 BPF_ALU32_IMM(BPF_MOV
, R2
, 0xffffffff),
2482 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2483 BPF_MOV32_IMM(R0
, 2),
2485 BPF_MOV32_IMM(R0
, 1),
2493 "ALU64_MOV_K: dst = 2",
2495 BPF_ALU64_IMM(BPF_MOV
, R0
, 2),
2503 "ALU64_MOV_K: dst = 2147483647",
2505 BPF_ALU64_IMM(BPF_MOV
, R0
, 2147483647),
2510 { { 0, 2147483647 } },
2513 "ALU64_OR_K: dst = 0x0",
2515 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2516 BPF_LD_IMM64(R3
, 0x0),
2517 BPF_ALU64_IMM(BPF_MOV
, R2
, 0x0),
2518 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2519 BPF_MOV32_IMM(R0
, 2),
2521 BPF_MOV32_IMM(R0
, 1),
2529 "ALU64_MOV_K: dst = -1",
2531 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2532 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2533 BPF_ALU64_IMM(BPF_MOV
, R2
, 0xffffffff),
2534 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2535 BPF_MOV32_IMM(R0
, 2),
2537 BPF_MOV32_IMM(R0
, 1),
2544 /* BPF_ALU | BPF_ADD | BPF_X */
2546 "ALU_ADD_X: 1 + 2 = 3",
2548 BPF_LD_IMM64(R0
, 1),
2549 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2550 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2558 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2560 BPF_LD_IMM64(R0
, 1),
2561 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2562 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2567 { { 0, 4294967295U } },
2570 "ALU_ADD_X: 2 + 4294967294 = 0",
2572 BPF_LD_IMM64(R0
, 2),
2573 BPF_LD_IMM64(R1
, 4294967294U),
2574 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2575 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2576 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2578 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2586 "ALU64_ADD_X: 1 + 2 = 3",
2588 BPF_LD_IMM64(R0
, 1),
2589 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2590 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2598 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2600 BPF_LD_IMM64(R0
, 1),
2601 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2602 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2607 { { 0, 4294967295U } },
2610 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2612 BPF_LD_IMM64(R0
, 2),
2613 BPF_LD_IMM64(R1
, 4294967294U),
2614 BPF_LD_IMM64(R2
, 4294967296ULL),
2615 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2616 BPF_JMP_REG(BPF_JEQ
, R0
, R2
, 2),
2617 BPF_MOV32_IMM(R0
, 0),
2619 BPF_MOV32_IMM(R0
, 1),
2626 /* BPF_ALU | BPF_ADD | BPF_K */
2628 "ALU_ADD_K: 1 + 2 = 3",
2630 BPF_LD_IMM64(R0
, 1),
2631 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2639 "ALU_ADD_K: 3 + 0 = 3",
2641 BPF_LD_IMM64(R0
, 3),
2642 BPF_ALU32_IMM(BPF_ADD
, R0
, 0),
2650 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2652 BPF_LD_IMM64(R0
, 1),
2653 BPF_ALU32_IMM(BPF_ADD
, R0
, 4294967294U),
2658 { { 0, 4294967295U } },
2661 "ALU_ADD_K: 4294967294 + 2 = 0",
2663 BPF_LD_IMM64(R0
, 4294967294U),
2664 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2665 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2666 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2668 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2676 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2678 BPF_LD_IMM64(R2
, 0x0),
2679 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
2680 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffffffff),
2681 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2682 BPF_MOV32_IMM(R0
, 2),
2684 BPF_MOV32_IMM(R0
, 1),
2692 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2694 BPF_LD_IMM64(R2
, 0x0),
2695 BPF_LD_IMM64(R3
, 0xffff),
2696 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffff),
2697 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2698 BPF_MOV32_IMM(R0
, 2),
2700 BPF_MOV32_IMM(R0
, 1),
2708 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2710 BPF_LD_IMM64(R2
, 0x0),
2711 BPF_LD_IMM64(R3
, 0x7fffffff),
2712 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x7fffffff),
2713 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2714 BPF_MOV32_IMM(R0
, 2),
2716 BPF_MOV32_IMM(R0
, 1),
2724 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2726 BPF_LD_IMM64(R2
, 0x0),
2727 BPF_LD_IMM64(R3
, 0x80000000),
2728 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80000000),
2729 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2730 BPF_MOV32_IMM(R0
, 2),
2732 BPF_MOV32_IMM(R0
, 1),
2740 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2742 BPF_LD_IMM64(R2
, 0x0),
2743 BPF_LD_IMM64(R3
, 0x80008000),
2744 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80008000),
2745 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2746 BPF_MOV32_IMM(R0
, 2),
2748 BPF_MOV32_IMM(R0
, 1),
2756 "ALU64_ADD_K: 1 + 2 = 3",
2758 BPF_LD_IMM64(R0
, 1),
2759 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2767 "ALU64_ADD_K: 3 + 0 = 3",
2769 BPF_LD_IMM64(R0
, 3),
2770 BPF_ALU64_IMM(BPF_ADD
, R0
, 0),
2778 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2780 BPF_LD_IMM64(R0
, 1),
2781 BPF_ALU64_IMM(BPF_ADD
, R0
, 2147483646),
2786 { { 0, 2147483647 } },
2789 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2791 BPF_LD_IMM64(R0
, 4294967294U),
2792 BPF_LD_IMM64(R1
, 4294967296ULL),
2793 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2794 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 2),
2795 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2797 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2805 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2807 BPF_LD_IMM64(R0
, 2147483646),
2808 BPF_ALU64_IMM(BPF_ADD
, R0
, -2147483647),
2816 "ALU64_ADD_K: 1 + 0 = 1",
2818 BPF_LD_IMM64(R2
, 0x1),
2819 BPF_LD_IMM64(R3
, 0x1),
2820 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x0),
2821 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2822 BPF_MOV32_IMM(R0
, 2),
2824 BPF_MOV32_IMM(R0
, 1),
2832 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2834 BPF_LD_IMM64(R2
, 0x0),
2835 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2836 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffffffff),
2837 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2838 BPF_MOV32_IMM(R0
, 2),
2840 BPF_MOV32_IMM(R0
, 1),
2848 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2850 BPF_LD_IMM64(R2
, 0x0),
2851 BPF_LD_IMM64(R3
, 0xffff),
2852 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffff),
2853 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2854 BPF_MOV32_IMM(R0
, 2),
2856 BPF_MOV32_IMM(R0
, 1),
2864 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2866 BPF_LD_IMM64(R2
, 0x0),
2867 BPF_LD_IMM64(R3
, 0x7fffffff),
2868 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x7fffffff),
2869 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2870 BPF_MOV32_IMM(R0
, 2),
2872 BPF_MOV32_IMM(R0
, 1),
2880 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2882 BPF_LD_IMM64(R2
, 0x0),
2883 BPF_LD_IMM64(R3
, 0xffffffff80000000LL
),
2884 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80000000),
2885 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2886 BPF_MOV32_IMM(R0
, 2),
2888 BPF_MOV32_IMM(R0
, 1),
2896 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2898 BPF_LD_IMM64(R2
, 0x0),
2899 BPF_LD_IMM64(R3
, 0xffffffff80008000LL
),
2900 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80008000),
2901 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2902 BPF_MOV32_IMM(R0
, 2),
2904 BPF_MOV32_IMM(R0
, 1),
2911 /* BPF_ALU | BPF_SUB | BPF_X */
2913 "ALU_SUB_X: 3 - 1 = 2",
2915 BPF_LD_IMM64(R0
, 3),
2916 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2917 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2925 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2927 BPF_LD_IMM64(R0
, 4294967295U),
2928 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2929 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2937 "ALU64_SUB_X: 3 - 1 = 2",
2939 BPF_LD_IMM64(R0
, 3),
2940 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2941 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2949 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2951 BPF_LD_IMM64(R0
, 4294967295U),
2952 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2953 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2960 /* BPF_ALU | BPF_SUB | BPF_K */
2962 "ALU_SUB_K: 3 - 1 = 2",
2964 BPF_LD_IMM64(R0
, 3),
2965 BPF_ALU32_IMM(BPF_SUB
, R0
, 1),
2973 "ALU_SUB_K: 3 - 0 = 3",
2975 BPF_LD_IMM64(R0
, 3),
2976 BPF_ALU32_IMM(BPF_SUB
, R0
, 0),
2984 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2986 BPF_LD_IMM64(R0
, 4294967295U),
2987 BPF_ALU32_IMM(BPF_SUB
, R0
, 4294967294U),
2995 "ALU64_SUB_K: 3 - 1 = 2",
2997 BPF_LD_IMM64(R0
, 3),
2998 BPF_ALU64_IMM(BPF_SUB
, R0
, 1),
3006 "ALU64_SUB_K: 3 - 0 = 3",
3008 BPF_LD_IMM64(R0
, 3),
3009 BPF_ALU64_IMM(BPF_SUB
, R0
, 0),
3017 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3019 BPF_LD_IMM64(R0
, 4294967294U),
3020 BPF_ALU64_IMM(BPF_SUB
, R0
, 4294967295U),
3028 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3030 BPF_LD_IMM64(R0
, 2147483646),
3031 BPF_ALU64_IMM(BPF_SUB
, R0
, 2147483647),
3038 /* BPF_ALU | BPF_MUL | BPF_X */
3040 "ALU_MUL_X: 2 * 3 = 6",
3042 BPF_LD_IMM64(R0
, 2),
3043 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3044 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3052 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3054 BPF_LD_IMM64(R0
, 2),
3055 BPF_ALU32_IMM(BPF_MOV
, R1
, 0x7FFFFFF8),
3056 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3061 { { 0, 0xFFFFFFF0 } },
3064 "ALU_MUL_X: -1 * -1 = 1",
3066 BPF_LD_IMM64(R0
, -1),
3067 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
3068 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3076 "ALU64_MUL_X: 2 * 3 = 6",
3078 BPF_LD_IMM64(R0
, 2),
3079 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3080 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3088 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3090 BPF_LD_IMM64(R0
, 1),
3091 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3092 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3097 { { 0, 2147483647 } },
3099 /* BPF_ALU | BPF_MUL | BPF_K */
3101 "ALU_MUL_K: 2 * 3 = 6",
3103 BPF_LD_IMM64(R0
, 2),
3104 BPF_ALU32_IMM(BPF_MUL
, R0
, 3),
3112 "ALU_MUL_K: 3 * 1 = 3",
3114 BPF_LD_IMM64(R0
, 3),
3115 BPF_ALU32_IMM(BPF_MUL
, R0
, 1),
3123 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3125 BPF_LD_IMM64(R0
, 2),
3126 BPF_ALU32_IMM(BPF_MUL
, R0
, 0x7FFFFFF8),
3131 { { 0, 0xFFFFFFF0 } },
3134 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3136 BPF_LD_IMM64(R2
, 0x1),
3137 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
3138 BPF_ALU32_IMM(BPF_MUL
, R2
, 0xffffffff),
3139 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3140 BPF_MOV32_IMM(R0
, 2),
3142 BPF_MOV32_IMM(R0
, 1),
3150 "ALU64_MUL_K: 2 * 3 = 6",
3152 BPF_LD_IMM64(R0
, 2),
3153 BPF_ALU64_IMM(BPF_MUL
, R0
, 3),
3161 "ALU64_MUL_K: 3 * 1 = 3",
3163 BPF_LD_IMM64(R0
, 3),
3164 BPF_ALU64_IMM(BPF_MUL
, R0
, 1),
3172 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3174 BPF_LD_IMM64(R0
, 1),
3175 BPF_ALU64_IMM(BPF_MUL
, R0
, 2147483647),
3180 { { 0, 2147483647 } },
3183 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3185 BPF_LD_IMM64(R0
, 1),
3186 BPF_ALU64_IMM(BPF_MUL
, R0
, -2147483647),
3191 { { 0, -2147483647 } },
3194 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3196 BPF_LD_IMM64(R2
, 0x1),
3197 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3198 BPF_ALU64_IMM(BPF_MUL
, R2
, 0xffffffff),
3199 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3200 BPF_MOV32_IMM(R0
, 2),
3202 BPF_MOV32_IMM(R0
, 1),
3209 /* BPF_ALU | BPF_DIV | BPF_X */
3211 "ALU_DIV_X: 6 / 2 = 3",
3213 BPF_LD_IMM64(R0
, 6),
3214 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3215 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3223 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3225 BPF_LD_IMM64(R0
, 4294967295U),
3226 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
3227 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3235 "ALU64_DIV_X: 6 / 2 = 3",
3237 BPF_LD_IMM64(R0
, 6),
3238 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3239 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3247 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3249 BPF_LD_IMM64(R0
, 2147483647),
3250 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3251 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3259 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3261 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3262 BPF_LD_IMM64(R4
, 0xffffffffffffffffLL
),
3263 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3264 BPF_ALU64_REG(BPF_DIV
, R2
, R4
),
3265 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3266 BPF_MOV32_IMM(R0
, 2),
3268 BPF_MOV32_IMM(R0
, 1),
3275 /* BPF_ALU | BPF_DIV | BPF_K */
3277 "ALU_DIV_K: 6 / 2 = 3",
3279 BPF_LD_IMM64(R0
, 6),
3280 BPF_ALU32_IMM(BPF_DIV
, R0
, 2),
3288 "ALU_DIV_K: 3 / 1 = 3",
3290 BPF_LD_IMM64(R0
, 3),
3291 BPF_ALU32_IMM(BPF_DIV
, R0
, 1),
3299 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3301 BPF_LD_IMM64(R0
, 4294967295U),
3302 BPF_ALU32_IMM(BPF_DIV
, R0
, 4294967295U),
3310 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3312 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3313 BPF_LD_IMM64(R3
, 0x1UL
),
3314 BPF_ALU32_IMM(BPF_DIV
, R2
, 0xffffffff),
3315 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3316 BPF_MOV32_IMM(R0
, 2),
3318 BPF_MOV32_IMM(R0
, 1),
3326 "ALU64_DIV_K: 6 / 2 = 3",
3328 BPF_LD_IMM64(R0
, 6),
3329 BPF_ALU64_IMM(BPF_DIV
, R0
, 2),
3337 "ALU64_DIV_K: 3 / 1 = 3",
3339 BPF_LD_IMM64(R0
, 3),
3340 BPF_ALU64_IMM(BPF_DIV
, R0
, 1),
3348 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3350 BPF_LD_IMM64(R0
, 2147483647),
3351 BPF_ALU64_IMM(BPF_DIV
, R0
, 2147483647),
3359 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3361 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3362 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3363 BPF_ALU64_IMM(BPF_DIV
, R2
, 0xffffffff),
3364 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3365 BPF_MOV32_IMM(R0
, 2),
3367 BPF_MOV32_IMM(R0
, 1),
3374 /* BPF_ALU | BPF_MOD | BPF_X */
3376 "ALU_MOD_X: 3 % 2 = 1",
3378 BPF_LD_IMM64(R0
, 3),
3379 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3380 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3388 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3390 BPF_LD_IMM64(R0
, 4294967295U),
3391 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967293U),
3392 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3400 "ALU64_MOD_X: 3 % 2 = 1",
3402 BPF_LD_IMM64(R0
, 3),
3403 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3404 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3412 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3414 BPF_LD_IMM64(R0
, 2147483647),
3415 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483645),
3416 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3423 /* BPF_ALU | BPF_MOD | BPF_K */
3425 "ALU_MOD_K: 3 % 2 = 1",
3427 BPF_LD_IMM64(R0
, 3),
3428 BPF_ALU32_IMM(BPF_MOD
, R0
, 2),
3436 "ALU_MOD_K: 3 % 1 = 0",
3438 BPF_LD_IMM64(R0
, 3),
3439 BPF_ALU32_IMM(BPF_MOD
, R0
, 1),
3447 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3449 BPF_LD_IMM64(R0
, 4294967295U),
3450 BPF_ALU32_IMM(BPF_MOD
, R0
, 4294967293U),
3458 "ALU64_MOD_K: 3 % 2 = 1",
3460 BPF_LD_IMM64(R0
, 3),
3461 BPF_ALU64_IMM(BPF_MOD
, R0
, 2),
3469 "ALU64_MOD_K: 3 % 1 = 0",
3471 BPF_LD_IMM64(R0
, 3),
3472 BPF_ALU64_IMM(BPF_MOD
, R0
, 1),
3480 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3482 BPF_LD_IMM64(R0
, 2147483647),
3483 BPF_ALU64_IMM(BPF_MOD
, R0
, 2147483645),
3490 /* BPF_ALU | BPF_AND | BPF_X */
3492 "ALU_AND_X: 3 & 2 = 2",
3494 BPF_LD_IMM64(R0
, 3),
3495 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3496 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3504 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3506 BPF_LD_IMM64(R0
, 0xffffffff),
3507 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3508 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3513 { { 0, 0xffffffff } },
3516 "ALU64_AND_X: 3 & 2 = 2",
3518 BPF_LD_IMM64(R0
, 3),
3519 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3520 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3528 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3530 BPF_LD_IMM64(R0
, 0xffffffff),
3531 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3532 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3537 { { 0, 0xffffffff } },
3539 /* BPF_ALU | BPF_AND | BPF_K */
3541 "ALU_AND_K: 3 & 2 = 2",
3543 BPF_LD_IMM64(R0
, 3),
3544 BPF_ALU32_IMM(BPF_AND
, R0
, 2),
3552 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3554 BPF_LD_IMM64(R0
, 0xffffffff),
3555 BPF_ALU32_IMM(BPF_AND
, R0
, 0xffffffff),
3560 { { 0, 0xffffffff } },
3563 "ALU64_AND_K: 3 & 2 = 2",
3565 BPF_LD_IMM64(R0
, 3),
3566 BPF_ALU64_IMM(BPF_AND
, R0
, 2),
3574 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3576 BPF_LD_IMM64(R0
, 0xffffffff),
3577 BPF_ALU64_IMM(BPF_AND
, R0
, 0xffffffff),
3582 { { 0, 0xffffffff } },
3585 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3587 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3588 BPF_LD_IMM64(R3
, 0x0000000000000000LL
),
3589 BPF_ALU64_IMM(BPF_AND
, R2
, 0x0),
3590 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3591 BPF_MOV32_IMM(R0
, 2),
3593 BPF_MOV32_IMM(R0
, 1),
3601 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3603 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3604 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3605 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3606 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3607 BPF_MOV32_IMM(R0
, 2),
3609 BPF_MOV32_IMM(R0
, 1),
3617 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3619 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3620 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3621 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3622 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3623 BPF_MOV32_IMM(R0
, 2),
3625 BPF_MOV32_IMM(R0
, 1),
3632 /* BPF_ALU | BPF_OR | BPF_X */
3634 "ALU_OR_X: 1 | 2 = 3",
3636 BPF_LD_IMM64(R0
, 1),
3637 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3638 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3646 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3648 BPF_LD_IMM64(R0
, 0),
3649 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3650 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3655 { { 0, 0xffffffff } },
3658 "ALU64_OR_X: 1 | 2 = 3",
3660 BPF_LD_IMM64(R0
, 1),
3661 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3662 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3670 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3672 BPF_LD_IMM64(R0
, 0),
3673 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3674 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3679 { { 0, 0xffffffff } },
3681 /* BPF_ALU | BPF_OR | BPF_K */
3683 "ALU_OR_K: 1 | 2 = 3",
3685 BPF_LD_IMM64(R0
, 1),
3686 BPF_ALU32_IMM(BPF_OR
, R0
, 2),
3694 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3696 BPF_LD_IMM64(R0
, 0),
3697 BPF_ALU32_IMM(BPF_OR
, R0
, 0xffffffff),
3702 { { 0, 0xffffffff } },
3705 "ALU64_OR_K: 1 | 2 = 3",
3707 BPF_LD_IMM64(R0
, 1),
3708 BPF_ALU64_IMM(BPF_OR
, R0
, 2),
3716 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3718 BPF_LD_IMM64(R0
, 0),
3719 BPF_ALU64_IMM(BPF_OR
, R0
, 0xffffffff),
3724 { { 0, 0xffffffff } },
3727 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3729 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3730 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3731 BPF_ALU64_IMM(BPF_OR
, R2
, 0x0),
3732 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3733 BPF_MOV32_IMM(R0
, 2),
3735 BPF_MOV32_IMM(R0
, 1),
3743 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3745 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3746 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3747 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3748 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3749 BPF_MOV32_IMM(R0
, 2),
3751 BPF_MOV32_IMM(R0
, 1),
3759 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3761 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3762 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3763 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3764 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3765 BPF_MOV32_IMM(R0
, 2),
3767 BPF_MOV32_IMM(R0
, 1),
3774 /* BPF_ALU | BPF_XOR | BPF_X */
3776 "ALU_XOR_X: 5 ^ 6 = 3",
3778 BPF_LD_IMM64(R0
, 5),
3779 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3780 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3788 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3790 BPF_LD_IMM64(R0
, 1),
3791 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3792 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3797 { { 0, 0xfffffffe } },
3800 "ALU64_XOR_X: 5 ^ 6 = 3",
3802 BPF_LD_IMM64(R0
, 5),
3803 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3804 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3812 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3814 BPF_LD_IMM64(R0
, 1),
3815 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3816 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3821 { { 0, 0xfffffffe } },
3823 /* BPF_ALU | BPF_XOR | BPF_K */
3825 "ALU_XOR_K: 5 ^ 6 = 3",
3827 BPF_LD_IMM64(R0
, 5),
3828 BPF_ALU32_IMM(BPF_XOR
, R0
, 6),
3836 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3838 BPF_LD_IMM64(R0
, 1),
3839 BPF_ALU32_IMM(BPF_XOR
, R0
, 0xffffffff),
3844 { { 0, 0xfffffffe } },
3847 "ALU64_XOR_K: 5 ^ 6 = 3",
3849 BPF_LD_IMM64(R0
, 5),
3850 BPF_ALU64_IMM(BPF_XOR
, R0
, 6),
3858 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3860 BPF_LD_IMM64(R0
, 1),
3861 BPF_ALU64_IMM(BPF_XOR
, R0
, 0xffffffff),
3866 { { 0, 0xfffffffe } },
3869 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3871 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3872 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3873 BPF_ALU64_IMM(BPF_XOR
, R2
, 0x0),
3874 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3875 BPF_MOV32_IMM(R0
, 2),
3877 BPF_MOV32_IMM(R0
, 1),
3885 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3887 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3888 BPF_LD_IMM64(R3
, 0xffff00000000ffffLL
),
3889 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3890 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3891 BPF_MOV32_IMM(R0
, 2),
3893 BPF_MOV32_IMM(R0
, 1),
3901 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3903 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3904 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3905 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3906 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3907 BPF_MOV32_IMM(R0
, 2),
3909 BPF_MOV32_IMM(R0
, 1),
3916 /* BPF_ALU | BPF_LSH | BPF_X */
3918 "ALU_LSH_X: 1 << 1 = 2",
3920 BPF_LD_IMM64(R0
, 1),
3921 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3922 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3930 "ALU_LSH_X: 1 << 31 = 0x80000000",
3932 BPF_LD_IMM64(R0
, 1),
3933 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3934 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3939 { { 0, 0x80000000 } },
3942 "ALU64_LSH_X: 1 << 1 = 2",
3944 BPF_LD_IMM64(R0
, 1),
3945 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3946 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3954 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3956 BPF_LD_IMM64(R0
, 1),
3957 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3958 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3963 { { 0, 0x80000000 } },
3965 /* BPF_ALU | BPF_LSH | BPF_K */
3967 "ALU_LSH_K: 1 << 1 = 2",
3969 BPF_LD_IMM64(R0
, 1),
3970 BPF_ALU32_IMM(BPF_LSH
, R0
, 1),
3978 "ALU_LSH_K: 1 << 31 = 0x80000000",
3980 BPF_LD_IMM64(R0
, 1),
3981 BPF_ALU32_IMM(BPF_LSH
, R0
, 31),
3986 { { 0, 0x80000000 } },
3989 "ALU64_LSH_K: 1 << 1 = 2",
3991 BPF_LD_IMM64(R0
, 1),
3992 BPF_ALU64_IMM(BPF_LSH
, R0
, 1),
4000 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4002 BPF_LD_IMM64(R0
, 1),
4003 BPF_ALU64_IMM(BPF_LSH
, R0
, 31),
4008 { { 0, 0x80000000 } },
4010 /* BPF_ALU | BPF_RSH | BPF_X */
4012 "ALU_RSH_X: 2 >> 1 = 1",
4014 BPF_LD_IMM64(R0
, 2),
4015 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4016 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4024 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4026 BPF_LD_IMM64(R0
, 0x80000000),
4027 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4028 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4036 "ALU64_RSH_X: 2 >> 1 = 1",
4038 BPF_LD_IMM64(R0
, 2),
4039 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4040 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4048 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4050 BPF_LD_IMM64(R0
, 0x80000000),
4051 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4052 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4059 /* BPF_ALU | BPF_RSH | BPF_K */
4061 "ALU_RSH_K: 2 >> 1 = 1",
4063 BPF_LD_IMM64(R0
, 2),
4064 BPF_ALU32_IMM(BPF_RSH
, R0
, 1),
4072 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4074 BPF_LD_IMM64(R0
, 0x80000000),
4075 BPF_ALU32_IMM(BPF_RSH
, R0
, 31),
4083 "ALU64_RSH_K: 2 >> 1 = 1",
4085 BPF_LD_IMM64(R0
, 2),
4086 BPF_ALU64_IMM(BPF_RSH
, R0
, 1),
4094 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4096 BPF_LD_IMM64(R0
, 0x80000000),
4097 BPF_ALU64_IMM(BPF_RSH
, R0
, 31),
4104 /* BPF_ALU | BPF_ARSH | BPF_X */
4106 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4108 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4109 BPF_ALU32_IMM(BPF_MOV
, R1
, 40),
4110 BPF_ALU64_REG(BPF_ARSH
, R0
, R1
),
4115 { { 0, 0xffff00ff } },
4117 /* BPF_ALU | BPF_ARSH | BPF_K */
4119 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4121 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4122 BPF_ALU64_IMM(BPF_ARSH
, R0
, 40),
4127 { { 0, 0xffff00ff } },
4129 /* BPF_ALU | BPF_NEG */
4131 "ALU_NEG: -(3) = -3",
4133 BPF_ALU32_IMM(BPF_MOV
, R0
, 3),
4134 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4142 "ALU_NEG: -(-3) = 3",
4144 BPF_ALU32_IMM(BPF_MOV
, R0
, -3),
4145 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4153 "ALU64_NEG: -(3) = -3",
4155 BPF_LD_IMM64(R0
, 3),
4156 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4164 "ALU64_NEG: -(-3) = 3",
4166 BPF_LD_IMM64(R0
, -3),
4167 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4174 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4176 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4178 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4179 BPF_ENDIAN(BPF_FROM_BE
, R0
, 16),
4184 { { 0, cpu_to_be16(0xcdef) } },
4187 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4189 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4190 BPF_ENDIAN(BPF_FROM_BE
, R0
, 32),
4191 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4192 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4193 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4198 { { 0, cpu_to_be32(0x89abcdef) } },
4201 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4203 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4204 BPF_ENDIAN(BPF_FROM_BE
, R0
, 64),
4209 { { 0, (u32
) cpu_to_be64(0x0123456789abcdefLL
) } },
4211 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4213 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4215 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4216 BPF_ENDIAN(BPF_FROM_LE
, R0
, 16),
4221 { { 0, cpu_to_le16(0xcdef) } },
4224 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4226 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4227 BPF_ENDIAN(BPF_FROM_LE
, R0
, 32),
4228 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4229 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4230 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4235 { { 0, cpu_to_le32(0x89abcdef) } },
4238 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4240 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4241 BPF_ENDIAN(BPF_FROM_LE
, R0
, 64),
4246 { { 0, (u32
) cpu_to_le64(0x0123456789abcdefLL
) } },
4248 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4250 "ST_MEM_B: Store/Load byte: max negative",
4252 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4253 BPF_ST_MEM(BPF_B
, R10
, -40, 0xff),
4254 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4263 "ST_MEM_B: Store/Load byte: max positive",
4265 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4266 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7f),
4267 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4276 "STX_MEM_B: Store/Load byte: max negative",
4278 BPF_LD_IMM64(R0
, 0),
4279 BPF_LD_IMM64(R1
, 0xffLL
),
4280 BPF_STX_MEM(BPF_B
, R10
, R1
, -40),
4281 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4290 "ST_MEM_H: Store/Load half word: max negative",
4292 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4293 BPF_ST_MEM(BPF_H
, R10
, -40, 0xffff),
4294 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4303 "ST_MEM_H: Store/Load half word: max positive",
4305 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4306 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7fff),
4307 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4316 "STX_MEM_H: Store/Load half word: max negative",
4318 BPF_LD_IMM64(R0
, 0),
4319 BPF_LD_IMM64(R1
, 0xffffLL
),
4320 BPF_STX_MEM(BPF_H
, R10
, R1
, -40),
4321 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4330 "ST_MEM_W: Store/Load word: max negative",
4332 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4333 BPF_ST_MEM(BPF_W
, R10
, -40, 0xffffffff),
4334 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4339 { { 0, 0xffffffff } },
4343 "ST_MEM_W: Store/Load word: max positive",
4345 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4346 BPF_ST_MEM(BPF_W
, R10
, -40, 0x7fffffff),
4347 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4352 { { 0, 0x7fffffff } },
4356 "STX_MEM_W: Store/Load word: max negative",
4358 BPF_LD_IMM64(R0
, 0),
4359 BPF_LD_IMM64(R1
, 0xffffffffLL
),
4360 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4361 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4366 { { 0, 0xffffffff } },
4370 "ST_MEM_DW: Store/Load double word: max negative",
4372 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4373 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4374 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4379 { { 0, 0xffffffff } },
4383 "ST_MEM_DW: Store/Load double word: max negative 2",
4385 BPF_LD_IMM64(R2
, 0xffff00000000ffffLL
),
4386 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
4387 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4388 BPF_LDX_MEM(BPF_DW
, R2
, R10
, -40),
4389 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
4390 BPF_MOV32_IMM(R0
, 2),
4392 BPF_MOV32_IMM(R0
, 1),
4401 "ST_MEM_DW: Store/Load double word: max positive",
4403 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4404 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x7fffffff),
4405 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4410 { { 0, 0x7fffffff } },
4414 "STX_MEM_DW: Store/Load double word: max negative",
4416 BPF_LD_IMM64(R0
, 0),
4417 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4418 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4419 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4424 { { 0, 0xffffffff } },
4427 /* BPF_STX | BPF_XADD | BPF_W/DW */
4429 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4431 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4432 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4433 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4434 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4443 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4445 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4446 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4447 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4448 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4449 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4450 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4459 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4461 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4462 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4463 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4472 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4477 .fill_helper
= bpf_fill_stxw
,
4480 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4482 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4483 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4484 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4485 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4494 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4496 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4497 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4498 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4499 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4500 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4501 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4510 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4512 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4513 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4514 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4523 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4528 .fill_helper
= bpf_fill_stxdw
,
4530 /* BPF_JMP | BPF_EXIT */
4534 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4711),
4536 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4712),
4542 /* BPF_JMP | BPF_JA */
4544 "JMP_JA: Unconditional jump: if (true) return 1",
4546 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4547 BPF_JMP_IMM(BPF_JA
, 0, 0, 1),
4549 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4556 /* BPF_JMP | BPF_JSLT | BPF_K */
4558 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4560 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4561 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4562 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4564 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4572 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4574 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4575 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4576 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4578 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4585 /* BPF_JMP | BPF_JSGT | BPF_K */
4587 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4589 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4590 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4591 BPF_JMP_IMM(BPF_JSGT
, R1
, -2, 1),
4593 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4601 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4603 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4604 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4605 BPF_JMP_IMM(BPF_JSGT
, R1
, -1, 1),
4607 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4614 /* BPF_JMP | BPF_JSLE | BPF_K */
4616 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4618 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4619 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4620 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4622 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4630 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4632 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4633 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4634 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4636 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4644 "JMP_JSLE_K: Signed jump: value walk 1",
4646 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4647 BPF_LD_IMM64(R1
, 3),
4648 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 6),
4649 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4650 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4651 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4652 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4653 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4654 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4655 BPF_EXIT_INSN(), /* bad exit */
4656 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4664 "JMP_JSLE_K: Signed jump: value walk 2",
4666 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4667 BPF_LD_IMM64(R1
, 3),
4668 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4669 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4670 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4671 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4672 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4673 BPF_EXIT_INSN(), /* bad exit */
4674 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4681 /* BPF_JMP | BPF_JSGE | BPF_K */
4683 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4685 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4686 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4687 BPF_JMP_IMM(BPF_JSGE
, R1
, -2, 1),
4689 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4697 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4699 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4700 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4701 BPF_JMP_IMM(BPF_JSGE
, R1
, -1, 1),
4703 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4711 "JMP_JSGE_K: Signed jump: value walk 1",
4713 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4714 BPF_LD_IMM64(R1
, -3),
4715 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 6),
4716 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4717 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4718 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4719 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4720 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4721 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4722 BPF_EXIT_INSN(), /* bad exit */
4723 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4731 "JMP_JSGE_K: Signed jump: value walk 2",
4733 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4734 BPF_LD_IMM64(R1
, -3),
4735 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4736 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4737 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4738 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4739 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4740 BPF_EXIT_INSN(), /* bad exit */
4741 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4748 /* BPF_JMP | BPF_JGT | BPF_K */
4750 "JMP_JGT_K: if (3 > 2) return 1",
4752 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4753 BPF_LD_IMM64(R1
, 3),
4754 BPF_JMP_IMM(BPF_JGT
, R1
, 2, 1),
4756 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4764 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4766 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4767 BPF_LD_IMM64(R1
, -1),
4768 BPF_JMP_IMM(BPF_JGT
, R1
, 1, 1),
4770 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4777 /* BPF_JMP | BPF_JLT | BPF_K */
4779 "JMP_JLT_K: if (2 < 3) return 1",
4781 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4782 BPF_LD_IMM64(R1
, 2),
4783 BPF_JMP_IMM(BPF_JLT
, R1
, 3, 1),
4785 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4793 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4795 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4796 BPF_LD_IMM64(R1
, 1),
4797 BPF_JMP_IMM(BPF_JLT
, R1
, -1, 1),
4799 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4806 /* BPF_JMP | BPF_JGE | BPF_K */
4808 "JMP_JGE_K: if (3 >= 2) return 1",
4810 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4811 BPF_LD_IMM64(R1
, 3),
4812 BPF_JMP_IMM(BPF_JGE
, R1
, 2, 1),
4814 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4821 /* BPF_JMP | BPF_JLE | BPF_K */
4823 "JMP_JLE_K: if (2 <= 3) return 1",
4825 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4826 BPF_LD_IMM64(R1
, 2),
4827 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4829 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4836 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4838 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4840 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4841 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4843 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4844 BPF_LD_IMM64(R1
, 3), /* note: this takes 2 insns */
4845 BPF_JMP_IMM(BPF_JGT
, R1
, 2, -6), /* goto out */
4853 "JMP_JGE_K: if (3 >= 3) return 1",
4855 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4856 BPF_LD_IMM64(R1
, 3),
4857 BPF_JMP_IMM(BPF_JGE
, R1
, 3, 1),
4859 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4866 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4868 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4870 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4871 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4873 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4874 BPF_LD_IMM64(R1
, 2), /* note: this takes 2 insns */
4875 BPF_JMP_IMM(BPF_JLT
, R1
, 3, -6), /* goto out */
4883 "JMP_JLE_K: if (3 <= 3) return 1",
4885 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4886 BPF_LD_IMM64(R1
, 3),
4887 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4889 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4896 /* BPF_JMP | BPF_JNE | BPF_K */
4898 "JMP_JNE_K: if (3 != 2) return 1",
4900 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4901 BPF_LD_IMM64(R1
, 3),
4902 BPF_JMP_IMM(BPF_JNE
, R1
, 2, 1),
4904 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4911 /* BPF_JMP | BPF_JEQ | BPF_K */
4913 "JMP_JEQ_K: if (3 == 3) return 1",
4915 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4916 BPF_LD_IMM64(R1
, 3),
4917 BPF_JMP_IMM(BPF_JEQ
, R1
, 3, 1),
4919 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4926 /* BPF_JMP | BPF_JSET | BPF_K */
4928 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4930 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4931 BPF_LD_IMM64(R1
, 3),
4932 BPF_JMP_IMM(BPF_JSET
, R1
, 2, 1),
4934 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4942 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4944 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4945 BPF_LD_IMM64(R1
, 3),
4946 BPF_JMP_IMM(BPF_JSET
, R1
, 0xffffffff, 1),
4948 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4955 /* BPF_JMP | BPF_JSGT | BPF_X */
4957 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4959 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4960 BPF_LD_IMM64(R1
, -1),
4961 BPF_LD_IMM64(R2
, -2),
4962 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4964 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4972 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4974 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4975 BPF_LD_IMM64(R1
, -1),
4976 BPF_LD_IMM64(R2
, -1),
4977 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4979 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4986 /* BPF_JMP | BPF_JSLT | BPF_X */
4988 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4990 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4991 BPF_LD_IMM64(R1
, -1),
4992 BPF_LD_IMM64(R2
, -2),
4993 BPF_JMP_REG(BPF_JSLT
, R2
, R1
, 1),
4995 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5003 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
5005 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5006 BPF_LD_IMM64(R1
, -1),
5007 BPF_LD_IMM64(R2
, -1),
5008 BPF_JMP_REG(BPF_JSLT
, R1
, R2
, 1),
5010 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5017 /* BPF_JMP | BPF_JSGE | BPF_X */
5019 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5021 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5022 BPF_LD_IMM64(R1
, -1),
5023 BPF_LD_IMM64(R2
, -2),
5024 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5026 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5034 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5036 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5037 BPF_LD_IMM64(R1
, -1),
5038 BPF_LD_IMM64(R2
, -1),
5039 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5041 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5048 /* BPF_JMP | BPF_JSLE | BPF_X */
5050 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5052 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5053 BPF_LD_IMM64(R1
, -1),
5054 BPF_LD_IMM64(R2
, -2),
5055 BPF_JMP_REG(BPF_JSLE
, R2
, R1
, 1),
5057 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5065 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5067 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5068 BPF_LD_IMM64(R1
, -1),
5069 BPF_LD_IMM64(R2
, -1),
5070 BPF_JMP_REG(BPF_JSLE
, R1
, R2
, 1),
5072 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5079 /* BPF_JMP | BPF_JGT | BPF_X */
5081 "JMP_JGT_X: if (3 > 2) return 1",
5083 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5084 BPF_LD_IMM64(R1
, 3),
5085 BPF_LD_IMM64(R2
, 2),
5086 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5088 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5096 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5098 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5099 BPF_LD_IMM64(R1
, -1),
5100 BPF_LD_IMM64(R2
, 1),
5101 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5103 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5110 /* BPF_JMP | BPF_JLT | BPF_X */
5112 "JMP_JLT_X: if (2 < 3) return 1",
5114 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5115 BPF_LD_IMM64(R1
, 3),
5116 BPF_LD_IMM64(R2
, 2),
5117 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5119 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5127 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5129 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5130 BPF_LD_IMM64(R1
, -1),
5131 BPF_LD_IMM64(R2
, 1),
5132 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5134 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5141 /* BPF_JMP | BPF_JGE | BPF_X */
5143 "JMP_JGE_X: if (3 >= 2) return 1",
5145 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5146 BPF_LD_IMM64(R1
, 3),
5147 BPF_LD_IMM64(R2
, 2),
5148 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5150 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5158 "JMP_JGE_X: if (3 >= 3) return 1",
5160 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5161 BPF_LD_IMM64(R1
, 3),
5162 BPF_LD_IMM64(R2
, 3),
5163 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5165 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5172 /* BPF_JMP | BPF_JLE | BPF_X */
5174 "JMP_JLE_X: if (2 <= 3) return 1",
5176 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5177 BPF_LD_IMM64(R1
, 3),
5178 BPF_LD_IMM64(R2
, 2),
5179 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 1),
5181 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5189 "JMP_JLE_X: if (3 <= 3) return 1",
5191 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5192 BPF_LD_IMM64(R1
, 3),
5193 BPF_LD_IMM64(R2
, 3),
5194 BPF_JMP_REG(BPF_JLE
, R1
, R2
, 1),
5196 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5204 /* Mainly testing JIT + imm64 here. */
5205 "JMP_JGE_X: ldimm64 test 1",
5207 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5208 BPF_LD_IMM64(R1
, 3),
5209 BPF_LD_IMM64(R2
, 2),
5210 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 2),
5211 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5212 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5217 { { 0, 0xeeeeeeeeU
} },
5220 "JMP_JGE_X: ldimm64 test 2",
5222 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5223 BPF_LD_IMM64(R1
, 3),
5224 BPF_LD_IMM64(R2
, 2),
5225 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 0),
5226 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5231 { { 0, 0xffffffffU
} },
5234 "JMP_JGE_X: ldimm64 test 3",
5236 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5237 BPF_LD_IMM64(R1
, 3),
5238 BPF_LD_IMM64(R2
, 2),
5239 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 4),
5240 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5241 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5249 "JMP_JLE_X: ldimm64 test 1",
5251 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5252 BPF_LD_IMM64(R1
, 3),
5253 BPF_LD_IMM64(R2
, 2),
5254 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 2),
5255 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5256 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5261 { { 0, 0xeeeeeeeeU
} },
5264 "JMP_JLE_X: ldimm64 test 2",
5266 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5267 BPF_LD_IMM64(R1
, 3),
5268 BPF_LD_IMM64(R2
, 2),
5269 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 0),
5270 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5275 { { 0, 0xffffffffU
} },
5278 "JMP_JLE_X: ldimm64 test 3",
5280 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5281 BPF_LD_IMM64(R1
, 3),
5282 BPF_LD_IMM64(R2
, 2),
5283 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 4),
5284 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5285 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5292 /* BPF_JMP | BPF_JNE | BPF_X */
5294 "JMP_JNE_X: if (3 != 2) return 1",
5296 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5297 BPF_LD_IMM64(R1
, 3),
5298 BPF_LD_IMM64(R2
, 2),
5299 BPF_JMP_REG(BPF_JNE
, R1
, R2
, 1),
5301 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5308 /* BPF_JMP | BPF_JEQ | BPF_X */
5310 "JMP_JEQ_X: if (3 == 3) return 1",
5312 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5313 BPF_LD_IMM64(R1
, 3),
5314 BPF_LD_IMM64(R2
, 3),
5315 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
5317 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5324 /* BPF_JMP | BPF_JSET | BPF_X */
5326 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5328 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5329 BPF_LD_IMM64(R1
, 3),
5330 BPF_LD_IMM64(R2
, 2),
5331 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5333 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5341 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5343 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5344 BPF_LD_IMM64(R1
, 3),
5345 BPF_LD_IMM64(R2
, 0xffffffff),
5346 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5348 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5356 "JMP_JA: Jump, gap, jump, ...",
5358 CLASSIC
| FLAG_NO_DATA
,
5360 { { 0, 0xababcbac } },
5361 .fill_helper
= bpf_fill_ja
,
5363 { /* Mainly checking JIT here. */
5364 "BPF_MAXINSNS: Maximum possible literals",
5366 CLASSIC
| FLAG_NO_DATA
,
5368 { { 0, 0xffffffff } },
5369 .fill_helper
= bpf_fill_maxinsns1
,
5371 { /* Mainly checking JIT here. */
5372 "BPF_MAXINSNS: Single literal",
5374 CLASSIC
| FLAG_NO_DATA
,
5376 { { 0, 0xfefefefe } },
5377 .fill_helper
= bpf_fill_maxinsns2
,
5379 { /* Mainly checking JIT here. */
5380 "BPF_MAXINSNS: Run/add until end",
5382 CLASSIC
| FLAG_NO_DATA
,
5384 { { 0, 0x947bf368 } },
5385 .fill_helper
= bpf_fill_maxinsns3
,
5388 "BPF_MAXINSNS: Too many instructions",
5390 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5393 .fill_helper
= bpf_fill_maxinsns4
,
5395 { /* Mainly checking JIT here. */
5396 "BPF_MAXINSNS: Very long jump",
5398 CLASSIC
| FLAG_NO_DATA
,
5400 { { 0, 0xabababab } },
5401 .fill_helper
= bpf_fill_maxinsns5
,
5403 { /* Mainly checking JIT here. */
5404 "BPF_MAXINSNS: Ctx heavy transformations",
5409 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
5410 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
5412 .fill_helper
= bpf_fill_maxinsns6
,
5414 { /* Mainly checking JIT here. */
5415 "BPF_MAXINSNS: Call heavy transformations",
5417 CLASSIC
| FLAG_NO_DATA
,
5419 { { 1, 0 }, { 10, 0 } },
5420 .fill_helper
= bpf_fill_maxinsns7
,
5422 { /* Mainly checking JIT here. */
5423 "BPF_MAXINSNS: Jump heavy test",
5425 CLASSIC
| FLAG_NO_DATA
,
5427 { { 0, 0xffffffff } },
5428 .fill_helper
= bpf_fill_maxinsns8
,
5430 { /* Mainly checking JIT here. */
5431 "BPF_MAXINSNS: Very long jump backwards",
5433 INTERNAL
| FLAG_NO_DATA
,
5435 { { 0, 0xcbababab } },
5436 .fill_helper
= bpf_fill_maxinsns9
,
5438 { /* Mainly checking JIT here. */
5439 "BPF_MAXINSNS: Edge hopping nuthouse",
5441 INTERNAL
| FLAG_NO_DATA
,
5443 { { 0, 0xabababac } },
5444 .fill_helper
= bpf_fill_maxinsns10
,
5447 "BPF_MAXINSNS: Jump, gap, jump, ...",
5449 CLASSIC
| FLAG_NO_DATA
,
5451 { { 0, 0xababcbac } },
5452 .fill_helper
= bpf_fill_maxinsns11
,
5455 "BPF_MAXINSNS: ld_abs+get_processor_id",
5460 .fill_helper
= bpf_fill_ld_abs_get_processor_id
,
5463 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5467 { { ETH_HLEN
, 0xbef } },
5468 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop
,
5471 "BPF_MAXINSNS: jump around ld_abs",
5476 .fill_helper
= bpf_fill_jump_around_ld_abs
,
5479 * LD_IND / LD_ABS on fragmented SKBs
5484 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5485 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x0),
5486 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5488 CLASSIC
| FLAG_SKB_FRAG
,
5492 0x42, 0x00, 0x00, 0x00,
5493 0x43, 0x44, 0x00, 0x00,
5494 0x21, 0x07, 0x19, 0x83,
5498 "LD_IND halfword frag",
5500 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5501 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x4),
5502 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5504 CLASSIC
| FLAG_SKB_FRAG
,
5508 0x42, 0x00, 0x00, 0x00,
5509 0x43, 0x44, 0x00, 0x00,
5510 0x21, 0x07, 0x19, 0x83,
5516 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5517 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x8),
5518 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5520 CLASSIC
| FLAG_SKB_FRAG
,
5522 { {0x40, 0x21071983} },
5524 0x42, 0x00, 0x00, 0x00,
5525 0x43, 0x44, 0x00, 0x00,
5526 0x21, 0x07, 0x19, 0x83,
5530 "LD_IND halfword mixed head/frag",
5532 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5533 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5534 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5536 CLASSIC
| FLAG_SKB_FRAG
,
5537 { [0x3e] = 0x25, [0x3f] = 0x05, },
5539 .frag_data
= { 0x19, 0x82 },
5542 "LD_IND word mixed head/frag",
5544 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5545 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5546 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5548 CLASSIC
| FLAG_SKB_FRAG
,
5549 { [0x3e] = 0x25, [0x3f] = 0x05, },
5550 { {0x40, 0x25051982} },
5551 .frag_data
= { 0x19, 0x82 },
5556 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x40),
5557 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5559 CLASSIC
| FLAG_SKB_FRAG
,
5563 0x42, 0x00, 0x00, 0x00,
5564 0x43, 0x44, 0x00, 0x00,
5565 0x21, 0x07, 0x19, 0x83,
5569 "LD_ABS halfword frag",
5571 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x44),
5572 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5574 CLASSIC
| FLAG_SKB_FRAG
,
5578 0x42, 0x00, 0x00, 0x00,
5579 0x43, 0x44, 0x00, 0x00,
5580 0x21, 0x07, 0x19, 0x83,
5586 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x48),
5587 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5589 CLASSIC
| FLAG_SKB_FRAG
,
5591 { {0x40, 0x21071983} },
5593 0x42, 0x00, 0x00, 0x00,
5594 0x43, 0x44, 0x00, 0x00,
5595 0x21, 0x07, 0x19, 0x83,
5599 "LD_ABS halfword mixed head/frag",
5601 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3f),
5602 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5604 CLASSIC
| FLAG_SKB_FRAG
,
5605 { [0x3e] = 0x25, [0x3f] = 0x05, },
5607 .frag_data
= { 0x19, 0x82 },
5610 "LD_ABS word mixed head/frag",
5612 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3e),
5613 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5615 CLASSIC
| FLAG_SKB_FRAG
,
5616 { [0x3e] = 0x25, [0x3f] = 0x05, },
5617 { {0x40, 0x25051982} },
5618 .frag_data
= { 0x19, 0x82 },
5621 * LD_IND / LD_ABS on non fragmented SKBs
5625 * this tests that the JIT/interpreter correctly resets X
5626 * before using it in an LD_IND instruction.
5628 "LD_IND byte default X",
5630 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5631 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5638 "LD_IND byte positive offset",
5640 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5641 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5642 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5645 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5649 "LD_IND byte negative offset",
5651 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5652 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, -0x1),
5653 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5656 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5660 "LD_IND halfword positive offset",
5662 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5663 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x2),
5664 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5668 [0x1c] = 0xaa, [0x1d] = 0x55,
5669 [0x1e] = 0xbb, [0x1f] = 0x66,
5670 [0x20] = 0xcc, [0x21] = 0x77,
5671 [0x22] = 0xdd, [0x23] = 0x88,
5673 { {0x40, 0xdd88 } },
5676 "LD_IND halfword negative offset",
5678 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5679 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x2),
5680 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5684 [0x1c] = 0xaa, [0x1d] = 0x55,
5685 [0x1e] = 0xbb, [0x1f] = 0x66,
5686 [0x20] = 0xcc, [0x21] = 0x77,
5687 [0x22] = 0xdd, [0x23] = 0x88,
5689 { {0x40, 0xbb66 } },
5692 "LD_IND halfword unaligned",
5694 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5695 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5696 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5700 [0x1c] = 0xaa, [0x1d] = 0x55,
5701 [0x1e] = 0xbb, [0x1f] = 0x66,
5702 [0x20] = 0xcc, [0x21] = 0x77,
5703 [0x22] = 0xdd, [0x23] = 0x88,
5705 { {0x40, 0x66cc } },
5708 "LD_IND word positive offset",
5710 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5711 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x4),
5712 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5716 [0x1c] = 0xaa, [0x1d] = 0x55,
5717 [0x1e] = 0xbb, [0x1f] = 0x66,
5718 [0x20] = 0xcc, [0x21] = 0x77,
5719 [0x22] = 0xdd, [0x23] = 0x88,
5720 [0x24] = 0xee, [0x25] = 0x99,
5721 [0x26] = 0xff, [0x27] = 0xaa,
5723 { {0x40, 0xee99ffaa } },
5726 "LD_IND word negative offset",
5728 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5729 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x4),
5730 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5734 [0x1c] = 0xaa, [0x1d] = 0x55,
5735 [0x1e] = 0xbb, [0x1f] = 0x66,
5736 [0x20] = 0xcc, [0x21] = 0x77,
5737 [0x22] = 0xdd, [0x23] = 0x88,
5738 [0x24] = 0xee, [0x25] = 0x99,
5739 [0x26] = 0xff, [0x27] = 0xaa,
5741 { {0x40, 0xaa55bb66 } },
5744 "LD_IND word unaligned (addr & 3 == 2)",
5746 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5747 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5748 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5752 [0x1c] = 0xaa, [0x1d] = 0x55,
5753 [0x1e] = 0xbb, [0x1f] = 0x66,
5754 [0x20] = 0xcc, [0x21] = 0x77,
5755 [0x22] = 0xdd, [0x23] = 0x88,
5756 [0x24] = 0xee, [0x25] = 0x99,
5757 [0x26] = 0xff, [0x27] = 0xaa,
5759 { {0x40, 0xbb66cc77 } },
5762 "LD_IND word unaligned (addr & 3 == 1)",
5764 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5765 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x3),
5766 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5770 [0x1c] = 0xaa, [0x1d] = 0x55,
5771 [0x1e] = 0xbb, [0x1f] = 0x66,
5772 [0x20] = 0xcc, [0x21] = 0x77,
5773 [0x22] = 0xdd, [0x23] = 0x88,
5774 [0x24] = 0xee, [0x25] = 0x99,
5775 [0x26] = 0xff, [0x27] = 0xaa,
5777 { {0x40, 0x55bb66cc } },
5780 "LD_IND word unaligned (addr & 3 == 3)",
5782 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5783 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x1),
5784 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5788 [0x1c] = 0xaa, [0x1d] = 0x55,
5789 [0x1e] = 0xbb, [0x1f] = 0x66,
5790 [0x20] = 0xcc, [0x21] = 0x77,
5791 [0x22] = 0xdd, [0x23] = 0x88,
5792 [0x24] = 0xee, [0x25] = 0x99,
5793 [0x26] = 0xff, [0x27] = 0xaa,
5795 { {0x40, 0x66cc77dd } },
5800 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x20),
5801 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5805 [0x1c] = 0xaa, [0x1d] = 0x55,
5806 [0x1e] = 0xbb, [0x1f] = 0x66,
5807 [0x20] = 0xcc, [0x21] = 0x77,
5808 [0x22] = 0xdd, [0x23] = 0x88,
5809 [0x24] = 0xee, [0x25] = 0x99,
5810 [0x26] = 0xff, [0x27] = 0xaa,
5817 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x22),
5818 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5822 [0x1c] = 0xaa, [0x1d] = 0x55,
5823 [0x1e] = 0xbb, [0x1f] = 0x66,
5824 [0x20] = 0xcc, [0x21] = 0x77,
5825 [0x22] = 0xdd, [0x23] = 0x88,
5826 [0x24] = 0xee, [0x25] = 0x99,
5827 [0x26] = 0xff, [0x27] = 0xaa,
5829 { {0x40, 0xdd88 } },
5832 "LD_ABS halfword unaligned",
5834 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x25),
5835 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5839 [0x1c] = 0xaa, [0x1d] = 0x55,
5840 [0x1e] = 0xbb, [0x1f] = 0x66,
5841 [0x20] = 0xcc, [0x21] = 0x77,
5842 [0x22] = 0xdd, [0x23] = 0x88,
5843 [0x24] = 0xee, [0x25] = 0x99,
5844 [0x26] = 0xff, [0x27] = 0xaa,
5846 { {0x40, 0x99ff } },
5851 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x1c),
5852 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5856 [0x1c] = 0xaa, [0x1d] = 0x55,
5857 [0x1e] = 0xbb, [0x1f] = 0x66,
5858 [0x20] = 0xcc, [0x21] = 0x77,
5859 [0x22] = 0xdd, [0x23] = 0x88,
5860 [0x24] = 0xee, [0x25] = 0x99,
5861 [0x26] = 0xff, [0x27] = 0xaa,
5863 { {0x40, 0xaa55bb66 } },
5866 "LD_ABS word unaligned (addr & 3 == 2)",
5868 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x22),
5869 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5873 [0x1c] = 0xaa, [0x1d] = 0x55,
5874 [0x1e] = 0xbb, [0x1f] = 0x66,
5875 [0x20] = 0xcc, [0x21] = 0x77,
5876 [0x22] = 0xdd, [0x23] = 0x88,
5877 [0x24] = 0xee, [0x25] = 0x99,
5878 [0x26] = 0xff, [0x27] = 0xaa,
5880 { {0x40, 0xdd88ee99 } },
5883 "LD_ABS word unaligned (addr & 3 == 1)",
5885 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x21),
5886 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5890 [0x1c] = 0xaa, [0x1d] = 0x55,
5891 [0x1e] = 0xbb, [0x1f] = 0x66,
5892 [0x20] = 0xcc, [0x21] = 0x77,
5893 [0x22] = 0xdd, [0x23] = 0x88,
5894 [0x24] = 0xee, [0x25] = 0x99,
5895 [0x26] = 0xff, [0x27] = 0xaa,
5897 { {0x40, 0x77dd88ee } },
5900 "LD_ABS word unaligned (addr & 3 == 3)",
5902 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x23),
5903 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5907 [0x1c] = 0xaa, [0x1d] = 0x55,
5908 [0x1e] = 0xbb, [0x1f] = 0x66,
5909 [0x20] = 0xcc, [0x21] = 0x77,
5910 [0x22] = 0xdd, [0x23] = 0x88,
5911 [0x24] = 0xee, [0x25] = 0x99,
5912 [0x26] = 0xff, [0x27] = 0xaa,
5914 { {0x40, 0x88ee99ff } },
5917 * verify that the interpreter or JIT correctly sets A and X
5928 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
5929 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
5930 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5932 CLASSIC
| FLAG_NO_DATA
,
5943 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0x42),
5944 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5946 CLASSIC
| FLAG_NO_DATA
,
5958 BPF_STMT(BPF_LD
| BPF_IMM
, 0x66),
5959 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
5960 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5962 CLASSIC
| FLAG_NO_DATA
,
5973 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, -0x66),
5974 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5976 CLASSIC
| FLAG_NO_DATA
,
5988 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
5989 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_X
, 0),
5990 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5992 CLASSIC
| FLAG_NO_DATA
,
6003 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 0x66),
6004 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6006 CLASSIC
| FLAG_NO_DATA
,
6015 * A = A / X ; this halt the filter execution if X is 0
6018 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6019 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
6020 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6022 CLASSIC
| FLAG_NO_DATA
,
6033 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x1),
6034 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6036 CLASSIC
| FLAG_NO_DATA
,
6045 * A = A mod X ; this halt the filter execution if X is 0
6048 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6049 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
6050 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6052 CLASSIC
| FLAG_NO_DATA
,
6063 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x1),
6064 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6066 CLASSIC
| FLAG_NO_DATA
,
6078 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0, 0, 1),
6079 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6080 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6082 CLASSIC
| FLAG_NO_DATA
,
6095 BPF_STMT(BPF_LD
| BPF_IMM
, 0x0),
6096 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0x0, 0, 1),
6097 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6098 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6100 CLASSIC
| FLAG_NO_DATA
,
6105 "LD_ABS with helper changing skb data",
6109 { { ETH_HLEN
, 42 } },
6110 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop2
,
6114 static struct net_device dev
;
6116 static struct sk_buff
*populate_skb(char *buf
, int size
)
6118 struct sk_buff
*skb
;
6120 if (size
>= MAX_DATA
)
6123 skb
= alloc_skb(MAX_DATA
, GFP_KERNEL
);
6127 __skb_put_data(skb
, buf
, size
);
6129 /* Initialize a fake skb with test pattern. */
6130 skb_reset_mac_header(skb
);
6131 skb
->protocol
= htons(ETH_P_IP
);
6132 skb
->pkt_type
= SKB_TYPE
;
6133 skb
->mark
= SKB_MARK
;
6134 skb
->hash
= SKB_HASH
;
6135 skb
->queue_mapping
= SKB_QUEUE_MAP
;
6136 skb
->vlan_tci
= SKB_VLAN_TCI
;
6137 skb
->vlan_proto
= htons(ETH_P_IP
);
6139 skb
->dev
->ifindex
= SKB_DEV_IFINDEX
;
6140 skb
->dev
->type
= SKB_DEV_TYPE
;
6141 skb_set_network_header(skb
, min(size
, ETH_HLEN
));
6146 static void *generate_test_data(struct bpf_test
*test
, int sub
)
6148 struct sk_buff
*skb
;
6151 if (test
->aux
& FLAG_NO_DATA
)
6154 /* Test case expects an skb, so populate one. Various
6155 * subtests generate skbs of different sizes based on
6158 skb
= populate_skb(test
->data
, test
->test
[sub
].data_size
);
6162 if (test
->aux
& FLAG_SKB_FRAG
) {
6164 * when the test requires a fragmented skb, add a
6165 * single fragment to the skb, filled with
6170 page
= alloc_page(GFP_KERNEL
);
6178 memcpy(ptr
, test
->frag_data
, MAX_DATA
);
6180 skb_add_rx_frag(skb
, 0, page
, 0, MAX_DATA
, MAX_DATA
);
6192 static void release_test_data(const struct bpf_test
*test
, void *data
)
6194 if (test
->aux
& FLAG_NO_DATA
)
6200 static int filter_length(int which
)
6202 struct sock_filter
*fp
;
6205 if (tests
[which
].fill_helper
)
6206 return tests
[which
].u
.ptr
.len
;
6208 fp
= tests
[which
].u
.insns
;
6209 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
6210 if (fp
[len
].code
!= 0 || fp
[len
].k
!= 0)
6216 static void *filter_pointer(int which
)
6218 if (tests
[which
].fill_helper
)
6219 return tests
[which
].u
.ptr
.insns
;
6221 return tests
[which
].u
.insns
;
6224 static struct bpf_prog
*generate_filter(int which
, int *err
)
6226 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6227 unsigned int flen
= filter_length(which
);
6228 void *fptr
= filter_pointer(which
);
6229 struct sock_fprog_kern fprog
;
6230 struct bpf_prog
*fp
;
6232 switch (test_type
) {
6234 fprog
.filter
= fptr
;
6237 *err
= bpf_prog_create(&fp
, &fprog
);
6238 if (tests
[which
].aux
& FLAG_EXPECTED_FAIL
) {
6239 if (*err
== -EINVAL
) {
6241 /* Verifier rejected filter as expected. */
6245 pr_cont("UNEXPECTED_PASS\n");
6246 /* Verifier didn't reject the test that's
6247 * bad enough, just return!
6254 pr_cont("FAIL to prog_create err=%d len=%d\n",
6261 fp
= bpf_prog_alloc(bpf_prog_size(flen
), 0);
6263 pr_cont("UNEXPECTED_FAIL no memory left\n");
6269 /* Type doesn't really matter here as long as it's not unspec. */
6270 fp
->type
= BPF_PROG_TYPE_SOCKET_FILTER
;
6271 memcpy(fp
->insnsi
, fptr
, fp
->len
* sizeof(struct bpf_insn
));
6272 fp
->aux
->stack_depth
= tests
[which
].stack_depth
;
6274 /* We cannot error here as we don't need type compatibility
6277 fp
= bpf_prog_select_runtime(fp
, err
);
6279 pr_cont("FAIL to select_runtime err=%d\n", *err
);
6289 static void release_filter(struct bpf_prog
*fp
, int which
)
6291 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6293 switch (test_type
) {
6295 bpf_prog_destroy(fp
);
6303 static int __run_one(const struct bpf_prog
*fp
, const void *data
,
6304 int runs
, u64
*duration
)
6309 start
= ktime_get_ns();
6311 for (i
= 0; i
< runs
; i
++)
6312 ret
= BPF_PROG_RUN(fp
, data
);
6314 finish
= ktime_get_ns();
6316 *duration
= finish
- start
;
6317 do_div(*duration
, runs
);
6322 static int run_one(const struct bpf_prog
*fp
, struct bpf_test
*test
)
6324 int err_cnt
= 0, i
, runs
= MAX_TESTRUNS
;
6326 for (i
= 0; i
< MAX_SUBTESTS
; i
++) {
6331 if (test
->test
[i
].data_size
== 0 &&
6332 test
->test
[i
].result
== 0)
6335 data
= generate_test_data(test
, i
);
6336 if (!data
&& !(test
->aux
& FLAG_NO_DATA
)) {
6337 pr_cont("data generation failed ");
6341 ret
= __run_one(fp
, data
, runs
, &duration
);
6342 release_test_data(test
, data
);
6344 if (ret
== test
->test
[i
].result
) {
6345 pr_cont("%lld ", duration
);
6347 pr_cont("ret %d != %d ", ret
,
6348 test
->test
[i
].result
);
6356 static char test_name
[64];
6357 module_param_string(test_name
, test_name
, sizeof(test_name
), 0);
6359 static int test_id
= -1;
6360 module_param(test_id
, int, 0);
6362 static int test_range
[2] = { 0, ARRAY_SIZE(tests
) - 1 };
6363 module_param_array(test_range
, int, NULL
, 0);
6365 static __init
int find_test_index(const char *test_name
)
6369 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6370 if (!strcmp(tests
[i
].descr
, test_name
))
6376 static __init
int prepare_bpf_tests(void)
6382 * if a test_id was specified, use test_range to
6383 * cover only that test.
6385 if (test_id
>= ARRAY_SIZE(tests
)) {
6386 pr_err("test_bpf: invalid test_id specified.\n");
6390 test_range
[0] = test_id
;
6391 test_range
[1] = test_id
;
6392 } else if (*test_name
) {
6394 * if a test_name was specified, find it and setup
6395 * test_range to cover only that test.
6397 int idx
= find_test_index(test_name
);
6400 pr_err("test_bpf: no test named '%s' found.\n",
6404 test_range
[0] = idx
;
6405 test_range
[1] = idx
;
6408 * check that the supplied test_range is valid.
6410 if (test_range
[0] >= ARRAY_SIZE(tests
) ||
6411 test_range
[1] >= ARRAY_SIZE(tests
) ||
6412 test_range
[0] < 0 || test_range
[1] < 0) {
6413 pr_err("test_bpf: test_range is out of bound.\n");
6417 if (test_range
[1] < test_range
[0]) {
6418 pr_err("test_bpf: test_range is ending before it starts.\n");
6423 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6424 if (tests
[i
].fill_helper
&&
6425 tests
[i
].fill_helper(&tests
[i
]) < 0)
6432 static __init
void destroy_bpf_tests(void)
6436 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6437 if (tests
[i
].fill_helper
)
6438 kfree(tests
[i
].u
.ptr
.insns
);
6442 static bool exclude_test(int test_id
)
6444 return test_id
< test_range
[0] || test_id
> test_range
[1];
6447 static __init
int test_bpf(void)
6449 int i
, err_cnt
= 0, pass_cnt
= 0;
6450 int jit_cnt
= 0, run_cnt
= 0;
6452 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6453 struct bpf_prog
*fp
;
6456 if (exclude_test(i
))
6459 pr_info("#%d %s ", i
, tests
[i
].descr
);
6461 fp
= generate_filter(i
, &err
);
6471 pr_cont("jited:%u ", fp
->jited
);
6477 err
= run_one(fp
, &tests
[i
]);
6478 release_filter(fp
, i
);
6481 pr_cont("FAIL (%d times)\n", err
);
6489 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6490 pass_cnt
, err_cnt
, jit_cnt
, run_cnt
);
6492 return err_cnt
? -EINVAL
: 0;
6495 static int __init
test_bpf_init(void)
6499 ret
= prepare_bpf_tests();
6505 destroy_bpf_tests();
6509 static void __exit
test_bpf_exit(void)
6513 module_init(test_bpf_init
);
6514 module_exit(test_bpf_exit
);
6516 MODULE_LICENSE("GPL");