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>
27 #include <linux/sched.h>
29 /* General test specific settings */
30 #define MAX_SUBTESTS 3
31 #define MAX_TESTRUNS 1000
34 #define MAX_K 0xffffFFFF
36 /* Few constants used to init test 'skb' */
38 #define SKB_MARK 0x1234aaaa
39 #define SKB_HASH 0x1234aaab
40 #define SKB_QUEUE_MAP 123
41 #define SKB_VLAN_TCI 0xffff
42 #define SKB_DEV_IFINDEX 577
43 #define SKB_DEV_TYPE 588
45 /* Redefine REGs to make tests less verbose */
56 #define R10 BPF_REG_10
58 /* Flags that can be passed to test cases */
59 #define FLAG_NO_DATA BIT(0)
60 #define FLAG_EXPECTED_FAIL BIT(1)
61 #define FLAG_SKB_FRAG BIT(2)
64 CLASSIC
= BIT(6), /* Old BPF instructions only. */
65 INTERNAL
= BIT(7), /* Extended instruction set. */
68 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
73 struct sock_filter insns
[MAX_INSNS
];
74 struct bpf_insn insns_int
[MAX_INSNS
];
86 int (*fill_helper
)(struct bpf_test
*self
);
87 int expected_errcode
; /* used when FLAG_EXPECTED_FAIL is set in the aux */
88 __u8 frag_data
[MAX_DATA
];
89 int stack_depth
; /* for eBPF only, since tests don't call verifier */
92 /* Large test cases need separate allocation and fill handler. */
94 static int bpf_fill_maxinsns1(struct bpf_test
*self
)
96 unsigned int len
= BPF_MAXINSNS
;
97 struct sock_filter
*insn
;
101 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
105 for (i
= 0; i
< len
; i
++, k
--)
106 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, k
);
108 self
->u
.ptr
.insns
= insn
;
109 self
->u
.ptr
.len
= len
;
114 static int bpf_fill_maxinsns2(struct bpf_test
*self
)
116 unsigned int len
= BPF_MAXINSNS
;
117 struct sock_filter
*insn
;
120 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
124 for (i
= 0; i
< len
; i
++)
125 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
127 self
->u
.ptr
.insns
= insn
;
128 self
->u
.ptr
.len
= len
;
133 static int bpf_fill_maxinsns3(struct bpf_test
*self
)
135 unsigned int len
= BPF_MAXINSNS
;
136 struct sock_filter
*insn
;
137 struct rnd_state rnd
;
140 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
144 prandom_seed_state(&rnd
, 3141592653589793238ULL);
146 for (i
= 0; i
< len
- 1; i
++) {
147 __u32 k
= prandom_u32_state(&rnd
);
149 insn
[i
] = __BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, k
);
152 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
154 self
->u
.ptr
.insns
= insn
;
155 self
->u
.ptr
.len
= len
;
160 static int bpf_fill_maxinsns4(struct bpf_test
*self
)
162 unsigned int len
= BPF_MAXINSNS
+ 1;
163 struct sock_filter
*insn
;
166 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
170 for (i
= 0; i
< len
; i
++)
171 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
173 self
->u
.ptr
.insns
= insn
;
174 self
->u
.ptr
.len
= len
;
179 static int bpf_fill_maxinsns5(struct bpf_test
*self
)
181 unsigned int len
= BPF_MAXINSNS
;
182 struct sock_filter
*insn
;
185 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
189 insn
[0] = __BPF_JUMP(BPF_JMP
| BPF_JA
, len
- 2, 0, 0);
191 for (i
= 1; i
< len
- 1; i
++)
192 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
194 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xabababab);
196 self
->u
.ptr
.insns
= insn
;
197 self
->u
.ptr
.len
= len
;
202 static int bpf_fill_maxinsns6(struct bpf_test
*self
)
204 unsigned int len
= BPF_MAXINSNS
;
205 struct sock_filter
*insn
;
208 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
212 for (i
= 0; i
< len
- 1; i
++)
213 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
214 SKF_AD_VLAN_TAG_PRESENT
);
216 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
218 self
->u
.ptr
.insns
= insn
;
219 self
->u
.ptr
.len
= len
;
224 static int bpf_fill_maxinsns7(struct bpf_test
*self
)
226 unsigned int len
= BPF_MAXINSNS
;
227 struct sock_filter
*insn
;
230 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
234 for (i
= 0; i
< len
- 4; i
++)
235 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
238 insn
[len
- 4] = __BPF_STMT(BPF_MISC
| BPF_TAX
, 0);
239 insn
[len
- 3] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
241 insn
[len
- 2] = __BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0);
242 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
244 self
->u
.ptr
.insns
= insn
;
245 self
->u
.ptr
.len
= len
;
250 static int bpf_fill_maxinsns8(struct bpf_test
*self
)
252 unsigned int len
= BPF_MAXINSNS
;
253 struct sock_filter
*insn
;
254 int i
, jmp_off
= len
- 3;
256 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
260 insn
[0] = __BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff);
262 for (i
= 1; i
< len
- 1; i
++)
263 insn
[i
] = __BPF_JUMP(BPF_JMP
| BPF_JGT
, 0xffffffff, jmp_off
--, 0);
265 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
267 self
->u
.ptr
.insns
= insn
;
268 self
->u
.ptr
.len
= len
;
273 static int bpf_fill_maxinsns9(struct bpf_test
*self
)
275 unsigned int len
= BPF_MAXINSNS
;
276 struct bpf_insn
*insn
;
279 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
283 insn
[0] = BPF_JMP_IMM(BPF_JA
, 0, 0, len
- 2);
284 insn
[1] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xcbababab);
285 insn
[2] = BPF_EXIT_INSN();
287 for (i
= 3; i
< len
- 2; i
++)
288 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xfefefefe);
290 insn
[len
- 2] = BPF_EXIT_INSN();
291 insn
[len
- 1] = BPF_JMP_IMM(BPF_JA
, 0, 0, -(len
- 1));
293 self
->u
.ptr
.insns
= insn
;
294 self
->u
.ptr
.len
= len
;
299 static int bpf_fill_maxinsns10(struct bpf_test
*self
)
301 unsigned int len
= BPF_MAXINSNS
, hlen
= len
- 2;
302 struct bpf_insn
*insn
;
305 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
309 for (i
= 0; i
< hlen
/ 2; i
++)
310 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 2 - 2 * i
);
311 for (i
= hlen
- 1; i
> hlen
/ 2; i
--)
312 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 1 - 2 * i
);
314 insn
[hlen
/ 2] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
/ 2 - 1);
315 insn
[hlen
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xabababac);
316 insn
[hlen
+ 1] = BPF_EXIT_INSN();
318 self
->u
.ptr
.insns
= insn
;
319 self
->u
.ptr
.len
= len
;
324 static int __bpf_fill_ja(struct bpf_test
*self
, unsigned int len
,
327 struct sock_filter
*insn
;
331 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
335 rlen
= (len
% plen
) - 1;
337 for (i
= 0; i
+ plen
< len
; i
+= plen
)
338 for (j
= 0; j
< plen
; j
++)
339 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
,
341 for (j
= 0; j
< rlen
; j
++)
342 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
, rlen
- 1 - j
,
345 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xababcbac);
347 self
->u
.ptr
.insns
= insn
;
348 self
->u
.ptr
.len
= len
;
353 static int bpf_fill_maxinsns11(struct bpf_test
*self
)
355 /* Hits 70 passes on x86_64, so cannot get JITed there. */
356 return __bpf_fill_ja(self
, BPF_MAXINSNS
, 68);
359 static int bpf_fill_ja(struct bpf_test
*self
)
361 /* Hits exactly 11 passes on x86_64 JIT. */
362 return __bpf_fill_ja(self
, 12, 9);
365 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test
*self
)
367 unsigned int len
= BPF_MAXINSNS
;
368 struct sock_filter
*insn
;
371 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
375 for (i
= 0; i
< len
- 1; i
+= 2) {
376 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 0);
377 insn
[i
+ 1] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
378 SKF_AD_OFF
+ SKF_AD_CPU
);
381 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xbee);
383 self
->u
.ptr
.insns
= insn
;
384 self
->u
.ptr
.len
= len
;
390 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
391 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test
*self
)
393 unsigned int len
= BPF_MAXINSNS
;
394 struct bpf_insn
*insn
;
397 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
401 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
403 for (j
= 0; j
< PUSH_CNT
; j
++) {
404 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
405 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
407 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
408 insn
[i
++] = BPF_MOV64_IMM(R2
, 1);
409 insn
[i
++] = BPF_MOV64_IMM(R3
, 2);
410 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
411 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
412 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
416 for (j
= 0; j
< PUSH_CNT
; j
++) {
417 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
418 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
420 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
421 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
422 bpf_skb_vlan_pop_proto
.func
- __bpf_call_base
);
423 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
429 for (; i
< len
- 1; i
++)
430 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xbef);
432 insn
[len
- 1] = BPF_EXIT_INSN();
434 self
->u
.ptr
.insns
= insn
;
435 self
->u
.ptr
.len
= len
;
440 static int bpf_fill_ld_abs_vlan_push_pop2(struct bpf_test
*self
)
442 struct bpf_insn
*insn
;
444 insn
= kmalloc_array(16, sizeof(*insn
), GFP_KERNEL
);
448 /* Due to func address being non-const, we need to
449 * assemble this here.
451 insn
[0] = BPF_MOV64_REG(R6
, R1
);
452 insn
[1] = BPF_LD_ABS(BPF_B
, 0);
453 insn
[2] = BPF_LD_ABS(BPF_H
, 0);
454 insn
[3] = BPF_LD_ABS(BPF_W
, 0);
455 insn
[4] = BPF_MOV64_REG(R7
, R6
);
456 insn
[5] = BPF_MOV64_IMM(R6
, 0);
457 insn
[6] = BPF_MOV64_REG(R1
, R7
);
458 insn
[7] = BPF_MOV64_IMM(R2
, 1);
459 insn
[8] = BPF_MOV64_IMM(R3
, 2);
460 insn
[9] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
461 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
462 insn
[10] = BPF_MOV64_REG(R6
, R7
);
463 insn
[11] = BPF_LD_ABS(BPF_B
, 0);
464 insn
[12] = BPF_LD_ABS(BPF_H
, 0);
465 insn
[13] = BPF_LD_ABS(BPF_W
, 0);
466 insn
[14] = BPF_MOV64_IMM(R0
, 42);
467 insn
[15] = BPF_EXIT_INSN();
469 self
->u
.ptr
.insns
= insn
;
470 self
->u
.ptr
.len
= 16;
475 static int bpf_fill_jump_around_ld_abs(struct bpf_test
*self
)
477 unsigned int len
= BPF_MAXINSNS
;
478 struct bpf_insn
*insn
;
481 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
485 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
486 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
487 insn
[i
] = BPF_JMP_IMM(BPF_JEQ
, R0
, 10, len
- i
- 2);
490 insn
[i
++] = BPF_LD_ABS(BPF_B
, 1);
491 insn
[i
] = BPF_EXIT_INSN();
493 self
->u
.ptr
.insns
= insn
;
494 self
->u
.ptr
.len
= len
;
499 static int __bpf_fill_stxdw(struct bpf_test
*self
, int size
)
501 unsigned int len
= BPF_MAXINSNS
;
502 struct bpf_insn
*insn
;
505 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
509 insn
[0] = BPF_ALU32_IMM(BPF_MOV
, R0
, 1);
510 insn
[1] = BPF_ST_MEM(size
, R10
, -40, 42);
512 for (i
= 2; i
< len
- 2; i
++)
513 insn
[i
] = BPF_STX_XADD(size
, R10
, R0
, -40);
515 insn
[len
- 2] = BPF_LDX_MEM(size
, R0
, R10
, -40);
516 insn
[len
- 1] = BPF_EXIT_INSN();
518 self
->u
.ptr
.insns
= insn
;
519 self
->u
.ptr
.len
= len
;
520 self
->stack_depth
= 40;
525 static int bpf_fill_stxw(struct bpf_test
*self
)
527 return __bpf_fill_stxdw(self
, BPF_W
);
530 static int bpf_fill_stxdw(struct bpf_test
*self
)
532 return __bpf_fill_stxdw(self
, BPF_DW
);
535 static struct bpf_test tests
[] = {
539 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
540 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
541 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
542 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
543 BPF_STMT(BPF_ALU
| BPF_NEG
, 0), /* A == -3 */
544 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
545 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
546 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
547 BPF_STMT(BPF_MISC
| BPF_TAX
, 0), /* X == len - 3 */
548 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
549 BPF_STMT(BPF_RET
| BPF_A
, 0)
552 { 10, 20, 30, 40, 50 },
553 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
558 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
559 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
560 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
561 BPF_STMT(BPF_RET
| BPF_A
, 0) /* A == len * 2 */
564 { 10, 20, 30, 40, 50 },
565 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
570 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
571 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 2),
572 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
573 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
574 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0xffffffff),
575 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 3),
576 BPF_STMT(BPF_RET
| BPF_A
, 0)
578 CLASSIC
| FLAG_NO_DATA
,
580 { { 0, 0xfffffffd } }
585 BPF_STMT(BPF_LD
| BPF_IMM
, 8),
586 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 2),
587 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
588 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
589 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
590 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
591 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
592 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x70000000),
593 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
594 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
595 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
596 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
597 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
598 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x70000000),
599 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
600 BPF_STMT(BPF_RET
| BPF_A
, 0)
602 CLASSIC
| FLAG_NO_DATA
,
604 { { 0, 0x20000000 } }
609 BPF_STMT(BPF_LD
| BPF_IMM
, 0xff),
610 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
611 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 27),
612 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
613 BPF_STMT(BPF_LD
| BPF_IMM
, 0xf),
614 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_K
, 0xf0),
615 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
616 BPF_STMT(BPF_RET
| BPF_A
, 0)
618 CLASSIC
| FLAG_NO_DATA
,
620 { { 0, 0x800000ff }, { 1, 0x800000ff } },
625 BPF_STMT(BPF_LD
| BPF_IMM
, 0), /* ld #0 */
626 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, 1, 0),
627 BPF_STMT(BPF_RET
| BPF_K
, 0),
628 BPF_STMT(BPF_RET
| BPF_K
, 1),
637 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
638 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, MAX_K
),
639 BPF_STMT(BPF_RET
| BPF_K
, 1)
643 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
648 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, 1000),
649 BPF_STMT(BPF_RET
| BPF_K
, 1)
653 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
658 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
),
659 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
660 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
+ 1),
661 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
662 BPF_STMT(BPF_RET
| BPF_A
, 0)
666 { { 1, 0 }, { 2, 3 } },
671 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_LL_OFF
- 1),
672 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
673 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
674 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
675 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
676 BPF_STMT(BPF_RET
| BPF_A
, 0)
680 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
685 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
),
686 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
687 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
+ 1),
688 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
689 BPF_STMT(BPF_RET
| BPF_A
, 0)
692 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
693 { { 15, 0 }, { 16, 3 } },
698 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_NET_OFF
- 15),
699 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
700 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
701 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
702 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
703 BPF_STMT(BPF_RET
| BPF_A
, 0)
706 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
707 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
712 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
713 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
714 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
715 BPF_STMT(BPF_RET
| BPF_K
, 1),
716 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
717 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
718 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
719 BPF_STMT(BPF_RET
| BPF_K
, 1),
720 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
721 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
722 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
723 BPF_STMT(BPF_RET
| BPF_K
, 1),
724 BPF_STMT(BPF_RET
| BPF_A
, 0)
728 { { 1, 3 }, { 10, 3 } },
733 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
734 SKF_AD_OFF
+ SKF_AD_MARK
),
735 BPF_STMT(BPF_RET
| BPF_A
, 0)
739 { { 1, SKB_MARK
}, { 10, SKB_MARK
} },
744 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
745 SKF_AD_OFF
+ SKF_AD_RXHASH
),
746 BPF_STMT(BPF_RET
| BPF_A
, 0)
750 { { 1, SKB_HASH
}, { 10, SKB_HASH
} },
755 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
756 SKF_AD_OFF
+ SKF_AD_QUEUE
),
757 BPF_STMT(BPF_RET
| BPF_A
, 0)
761 { { 1, SKB_QUEUE_MAP
}, { 10, SKB_QUEUE_MAP
} },
766 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 1),
767 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 20, 1, 0),
768 BPF_STMT(BPF_RET
| BPF_K
, 0),
769 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
770 SKF_AD_OFF
+ SKF_AD_PROTOCOL
),
771 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
772 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
773 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 30, 1, 0),
774 BPF_STMT(BPF_RET
| BPF_K
, 0),
775 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
776 BPF_STMT(BPF_RET
| BPF_A
, 0)
780 { { 10, ETH_P_IP
}, { 100, ETH_P_IP
} },
785 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
786 SKF_AD_OFF
+ SKF_AD_VLAN_TAG
),
787 BPF_STMT(BPF_RET
| BPF_A
, 0)
792 { 1, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
},
793 { 10, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
}
797 "LD_VLAN_TAG_PRESENT",
799 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
800 SKF_AD_OFF
+ SKF_AD_VLAN_TAG_PRESENT
),
801 BPF_STMT(BPF_RET
| BPF_A
, 0)
806 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
807 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
813 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
814 SKF_AD_OFF
+ SKF_AD_IFINDEX
),
815 BPF_STMT(BPF_RET
| BPF_A
, 0)
819 { { 1, SKB_DEV_IFINDEX
}, { 10, SKB_DEV_IFINDEX
} },
824 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
825 SKF_AD_OFF
+ SKF_AD_HATYPE
),
826 BPF_STMT(BPF_RET
| BPF_A
, 0)
830 { { 1, SKB_DEV_TYPE
}, { 10, SKB_DEV_TYPE
} },
835 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
836 SKF_AD_OFF
+ SKF_AD_CPU
),
837 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
838 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
839 SKF_AD_OFF
+ SKF_AD_CPU
),
840 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
841 BPF_STMT(BPF_RET
| BPF_A
, 0)
845 { { 1, 0 }, { 10, 0 } },
850 BPF_STMT(BPF_LDX
| BPF_IMM
, 2),
851 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
852 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
853 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
854 SKF_AD_OFF
+ SKF_AD_NLATTR
),
855 BPF_STMT(BPF_RET
| BPF_A
, 0)
859 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
861 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
863 { { 4, 0 }, { 20, 6 } },
868 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
869 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
870 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
871 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
872 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
873 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
874 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
875 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
876 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
877 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
878 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
879 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
880 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
881 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
882 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
883 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
884 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
885 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
886 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
887 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
888 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
889 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
890 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
891 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
892 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
893 BPF_STMT(BPF_RET
| BPF_A
, 0)
897 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
899 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
901 { { 4, 0 }, { 20, 10 } },
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_LD
| BPF_W
| BPF_ABS
,
915 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
916 BPF_STMT(BPF_RET
| BPF_A
, 0)
919 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
920 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
921 * id 9737, seq 1, length 64
923 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
924 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
926 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
927 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
928 { { 30, 0 }, { 100, 42 } },
933 BPF_STMT(BPF_LD
| BPF_IMM
, 10),
934 BPF_STMT(BPF_LDX
| BPF_IMM
, 300),
935 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
936 SKF_AD_OFF
+ SKF_AD_ALU_XOR_X
),
937 BPF_STMT(BPF_RET
| BPF_A
, 0)
941 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
946 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
947 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
948 BPF_STMT(BPF_ALU
| BPF_RSH
, 1),
949 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
950 BPF_STMT(BPF_ST
, 1), /* M1 = 1 ^ len */
951 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_K
, 0x80000000),
952 BPF_STMT(BPF_ST
, 2), /* M2 = 1 ^ len ^ 0x80000000 */
953 BPF_STMT(BPF_STX
, 15), /* M3 = len */
954 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
955 BPF_STMT(BPF_LD
| BPF_MEM
, 2),
956 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
957 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
958 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
959 BPF_STMT(BPF_RET
| BPF_A
, 0)
963 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
968 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
969 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
970 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 0, 1),
971 BPF_STMT(BPF_RET
| BPF_K
, 1),
972 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
976 { { 1, 0 }, { 3, 1 }, { 4, MAX_K
} },
981 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
982 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
983 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_X
, 0, 0, 1),
984 BPF_STMT(BPF_RET
| BPF_K
, 1),
985 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
989 { { 2, 0 }, { 3, 1 }, { 4, MAX_K
} },
992 "JGE (jt 0), test 1",
994 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
995 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
996 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
997 BPF_STMT(BPF_RET
| BPF_K
, 1),
998 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1002 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
1005 "JGE (jt 0), test 2",
1007 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1008 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
1009 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
1010 BPF_STMT(BPF_RET
| BPF_K
, 1),
1011 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1015 { { 4, 1 }, { 5, 1 }, { 6, MAX_K
} },
1020 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1021 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, MAX_K
),
1022 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 1, 1, 0),
1023 BPF_STMT(BPF_RET
| BPF_K
, 10),
1024 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 2, 1, 0),
1025 BPF_STMT(BPF_RET
| BPF_K
, 20),
1026 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 3, 1, 0),
1027 BPF_STMT(BPF_RET
| BPF_K
, 30),
1028 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 4, 1, 0),
1029 BPF_STMT(BPF_RET
| BPF_K
, 40),
1030 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1034 { { 1, 20 }, { 3, 40 }, { 5, MAX_K
} },
1039 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1040 BPF_JUMP(BPF_JMP
| BPF_JA
, 1, 1, 1),
1041 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1042 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1043 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1044 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1045 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, 4),
1046 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
1047 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
1048 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 1, 0, 1),
1049 BPF_STMT(BPF_RET
| BPF_K
, 10),
1050 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x80000000, 0, 1),
1051 BPF_STMT(BPF_RET
| BPF_K
, 20),
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_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1061 BPF_STMT(BPF_RET
| BPF_K
, 30),
1062 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1065 { 0, 0xAA, 0x55, 1 },
1066 { { 4, 10 }, { 5, 20 }, { 6, MAX_K
} },
1071 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1072 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 0, 8), /* IPv6 */
1073 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 20),
1074 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1075 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1076 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 17),
1077 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 54),
1078 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 14, 0),
1079 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 56),
1080 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 12, 13),
1081 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0800, 0, 12), /* IPv4 */
1082 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1083 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1084 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1085 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 8),
1086 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1087 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 6, 0),
1088 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1089 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1090 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1091 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1092 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 1),
1093 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1094 BPF_STMT(BPF_RET
| BPF_K
, 0),
1097 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1098 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1099 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1100 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1102 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1103 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1105 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1106 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1107 0x0a, 0x01, 0x01, 0x95, /* ip src */
1108 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1110 0x00, 0x16 /* dst port */ },
1111 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1116 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1117 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1118 * (len > 115 or len < 30000000000)' -d
1120 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1121 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 30, 0),
1122 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x800, 0, 29),
1123 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1124 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 0, 27),
1125 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1126 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 25, 0),
1127 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1128 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1129 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1130 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1131 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 20),
1132 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 16),
1133 BPF_STMT(BPF_ST
, 1),
1134 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 14),
1135 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf),
1136 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 2),
1137 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x5), /* libpcap emits K on TAX */
1138 BPF_STMT(BPF_LD
| BPF_MEM
, 1),
1139 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
1140 BPF_STMT(BPF_ST
, 5),
1141 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1142 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 26),
1143 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
1144 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 2),
1145 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x9), /* libpcap emits K on TAX */
1146 BPF_STMT(BPF_LD
| BPF_MEM
, 5),
1147 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 4, 0),
1148 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
1149 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_K
, 0x73, 1, 0),
1150 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 0xfc23ac00, 1, 0),
1151 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1152 BPF_STMT(BPF_RET
| BPF_K
, 0),
1155 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1156 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1158 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1159 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1160 0x0a, 0x01, 0x01, 0x95, /* ip src */
1161 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1163 0x00, 0x16 /* dst port */ },
1164 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1169 /* check that unitialized X and A contain zeros */
1170 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1171 BPF_STMT(BPF_RET
| BPF_A
, 0)
1180 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1181 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
1182 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1183 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1184 BPF_ALU64_IMM(BPF_ADD
, R1
, -1),
1185 BPF_ALU64_IMM(BPF_MUL
, R1
, 3),
1186 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
1191 { { 0, 0xfffffffd } }
1196 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1197 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1198 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1199 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1200 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xfffffffd, 1),
1202 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1212 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1213 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
1214 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1215 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1216 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1217 BPF_JMP_IMM(BPF_JEQ
, R1
, 0x2ffffff, 1),
1219 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1229 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1230 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1231 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1232 BPF_ALU32_REG(BPF_MUL
, R1
, R2
),
1233 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1234 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xffffff, 1),
1236 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1244 /* Have to test all register combinations, since
1245 * JITing of different registers will produce
1246 * different asm code.
1250 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1251 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1252 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1253 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1254 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1255 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1256 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1257 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1258 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1259 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1260 BPF_ALU64_IMM(BPF_ADD
, R0
, 20),
1261 BPF_ALU64_IMM(BPF_ADD
, R1
, 20),
1262 BPF_ALU64_IMM(BPF_ADD
, R2
, 20),
1263 BPF_ALU64_IMM(BPF_ADD
, R3
, 20),
1264 BPF_ALU64_IMM(BPF_ADD
, R4
, 20),
1265 BPF_ALU64_IMM(BPF_ADD
, R5
, 20),
1266 BPF_ALU64_IMM(BPF_ADD
, R6
, 20),
1267 BPF_ALU64_IMM(BPF_ADD
, R7
, 20),
1268 BPF_ALU64_IMM(BPF_ADD
, R8
, 20),
1269 BPF_ALU64_IMM(BPF_ADD
, R9
, 20),
1270 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1271 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1272 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1273 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1274 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1275 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1276 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1277 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1278 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1279 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1280 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1281 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1282 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1283 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1284 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1285 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1286 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1287 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1288 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1289 BPF_ALU64_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1290 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1292 BPF_ALU64_REG(BPF_ADD
, R1
, R0
),
1293 BPF_ALU64_REG(BPF_ADD
, R1
, R1
),
1294 BPF_ALU64_REG(BPF_ADD
, R1
, R2
),
1295 BPF_ALU64_REG(BPF_ADD
, R1
, R3
),
1296 BPF_ALU64_REG(BPF_ADD
, R1
, R4
),
1297 BPF_ALU64_REG(BPF_ADD
, R1
, R5
),
1298 BPF_ALU64_REG(BPF_ADD
, R1
, R6
),
1299 BPF_ALU64_REG(BPF_ADD
, R1
, R7
),
1300 BPF_ALU64_REG(BPF_ADD
, R1
, R8
),
1301 BPF_ALU64_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1302 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1304 BPF_ALU64_REG(BPF_ADD
, R2
, R0
),
1305 BPF_ALU64_REG(BPF_ADD
, R2
, R1
),
1306 BPF_ALU64_REG(BPF_ADD
, R2
, R2
),
1307 BPF_ALU64_REG(BPF_ADD
, R2
, R3
),
1308 BPF_ALU64_REG(BPF_ADD
, R2
, R4
),
1309 BPF_ALU64_REG(BPF_ADD
, R2
, R5
),
1310 BPF_ALU64_REG(BPF_ADD
, R2
, R6
),
1311 BPF_ALU64_REG(BPF_ADD
, R2
, R7
),
1312 BPF_ALU64_REG(BPF_ADD
, R2
, R8
),
1313 BPF_ALU64_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1314 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1316 BPF_ALU64_REG(BPF_ADD
, R3
, R0
),
1317 BPF_ALU64_REG(BPF_ADD
, R3
, R1
),
1318 BPF_ALU64_REG(BPF_ADD
, R3
, R2
),
1319 BPF_ALU64_REG(BPF_ADD
, R3
, R3
),
1320 BPF_ALU64_REG(BPF_ADD
, R3
, R4
),
1321 BPF_ALU64_REG(BPF_ADD
, R3
, R5
),
1322 BPF_ALU64_REG(BPF_ADD
, R3
, R6
),
1323 BPF_ALU64_REG(BPF_ADD
, R3
, R7
),
1324 BPF_ALU64_REG(BPF_ADD
, R3
, R8
),
1325 BPF_ALU64_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1326 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1328 BPF_ALU64_REG(BPF_ADD
, R4
, R0
),
1329 BPF_ALU64_REG(BPF_ADD
, R4
, R1
),
1330 BPF_ALU64_REG(BPF_ADD
, R4
, R2
),
1331 BPF_ALU64_REG(BPF_ADD
, R4
, R3
),
1332 BPF_ALU64_REG(BPF_ADD
, R4
, R4
),
1333 BPF_ALU64_REG(BPF_ADD
, R4
, R5
),
1334 BPF_ALU64_REG(BPF_ADD
, R4
, R6
),
1335 BPF_ALU64_REG(BPF_ADD
, R4
, R7
),
1336 BPF_ALU64_REG(BPF_ADD
, R4
, R8
),
1337 BPF_ALU64_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1338 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1340 BPF_ALU64_REG(BPF_ADD
, R5
, R0
),
1341 BPF_ALU64_REG(BPF_ADD
, R5
, R1
),
1342 BPF_ALU64_REG(BPF_ADD
, R5
, R2
),
1343 BPF_ALU64_REG(BPF_ADD
, R5
, R3
),
1344 BPF_ALU64_REG(BPF_ADD
, R5
, R4
),
1345 BPF_ALU64_REG(BPF_ADD
, R5
, R5
),
1346 BPF_ALU64_REG(BPF_ADD
, R5
, R6
),
1347 BPF_ALU64_REG(BPF_ADD
, R5
, R7
),
1348 BPF_ALU64_REG(BPF_ADD
, R5
, R8
),
1349 BPF_ALU64_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1350 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1352 BPF_ALU64_REG(BPF_ADD
, R6
, R0
),
1353 BPF_ALU64_REG(BPF_ADD
, R6
, R1
),
1354 BPF_ALU64_REG(BPF_ADD
, R6
, R2
),
1355 BPF_ALU64_REG(BPF_ADD
, R6
, R3
),
1356 BPF_ALU64_REG(BPF_ADD
, R6
, R4
),
1357 BPF_ALU64_REG(BPF_ADD
, R6
, R5
),
1358 BPF_ALU64_REG(BPF_ADD
, R6
, R6
),
1359 BPF_ALU64_REG(BPF_ADD
, R6
, R7
),
1360 BPF_ALU64_REG(BPF_ADD
, R6
, R8
),
1361 BPF_ALU64_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1362 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1364 BPF_ALU64_REG(BPF_ADD
, R7
, R0
),
1365 BPF_ALU64_REG(BPF_ADD
, R7
, R1
),
1366 BPF_ALU64_REG(BPF_ADD
, R7
, R2
),
1367 BPF_ALU64_REG(BPF_ADD
, R7
, R3
),
1368 BPF_ALU64_REG(BPF_ADD
, R7
, R4
),
1369 BPF_ALU64_REG(BPF_ADD
, R7
, R5
),
1370 BPF_ALU64_REG(BPF_ADD
, R7
, R6
),
1371 BPF_ALU64_REG(BPF_ADD
, R7
, R7
),
1372 BPF_ALU64_REG(BPF_ADD
, R7
, R8
),
1373 BPF_ALU64_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1374 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1376 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1377 BPF_ALU64_REG(BPF_ADD
, R8
, R1
),
1378 BPF_ALU64_REG(BPF_ADD
, R8
, R2
),
1379 BPF_ALU64_REG(BPF_ADD
, R8
, R3
),
1380 BPF_ALU64_REG(BPF_ADD
, R8
, R4
),
1381 BPF_ALU64_REG(BPF_ADD
, R8
, R5
),
1382 BPF_ALU64_REG(BPF_ADD
, R8
, R6
),
1383 BPF_ALU64_REG(BPF_ADD
, R8
, R7
),
1384 BPF_ALU64_REG(BPF_ADD
, R8
, R8
),
1385 BPF_ALU64_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1386 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1388 BPF_ALU64_REG(BPF_ADD
, R9
, R0
),
1389 BPF_ALU64_REG(BPF_ADD
, R9
, R1
),
1390 BPF_ALU64_REG(BPF_ADD
, R9
, R2
),
1391 BPF_ALU64_REG(BPF_ADD
, R9
, R3
),
1392 BPF_ALU64_REG(BPF_ADD
, R9
, R4
),
1393 BPF_ALU64_REG(BPF_ADD
, R9
, R5
),
1394 BPF_ALU64_REG(BPF_ADD
, R9
, R6
),
1395 BPF_ALU64_REG(BPF_ADD
, R9
, R7
),
1396 BPF_ALU64_REG(BPF_ADD
, R9
, R8
),
1397 BPF_ALU64_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1398 BPF_ALU64_REG(BPF_MOV
, R0
, R9
),
1408 BPF_ALU32_IMM(BPF_MOV
, R0
, 20),
1409 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
1410 BPF_ALU32_IMM(BPF_MOV
, R2
, 2),
1411 BPF_ALU32_IMM(BPF_MOV
, R3
, 3),
1412 BPF_ALU32_IMM(BPF_MOV
, R4
, 4),
1413 BPF_ALU32_IMM(BPF_MOV
, R5
, 5),
1414 BPF_ALU32_IMM(BPF_MOV
, R6
, 6),
1415 BPF_ALU32_IMM(BPF_MOV
, R7
, 7),
1416 BPF_ALU32_IMM(BPF_MOV
, R8
, 8),
1417 BPF_ALU32_IMM(BPF_MOV
, R9
, 9),
1418 BPF_ALU64_IMM(BPF_ADD
, R1
, 10),
1419 BPF_ALU64_IMM(BPF_ADD
, R2
, 10),
1420 BPF_ALU64_IMM(BPF_ADD
, R3
, 10),
1421 BPF_ALU64_IMM(BPF_ADD
, R4
, 10),
1422 BPF_ALU64_IMM(BPF_ADD
, R5
, 10),
1423 BPF_ALU64_IMM(BPF_ADD
, R6
, 10),
1424 BPF_ALU64_IMM(BPF_ADD
, R7
, 10),
1425 BPF_ALU64_IMM(BPF_ADD
, R8
, 10),
1426 BPF_ALU64_IMM(BPF_ADD
, R9
, 10),
1427 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
1428 BPF_ALU32_REG(BPF_ADD
, R0
, R2
),
1429 BPF_ALU32_REG(BPF_ADD
, R0
, R3
),
1430 BPF_ALU32_REG(BPF_ADD
, R0
, R4
),
1431 BPF_ALU32_REG(BPF_ADD
, R0
, R5
),
1432 BPF_ALU32_REG(BPF_ADD
, R0
, R6
),
1433 BPF_ALU32_REG(BPF_ADD
, R0
, R7
),
1434 BPF_ALU32_REG(BPF_ADD
, R0
, R8
),
1435 BPF_ALU32_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1436 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1438 BPF_ALU32_REG(BPF_ADD
, R1
, R0
),
1439 BPF_ALU32_REG(BPF_ADD
, R1
, R1
),
1440 BPF_ALU32_REG(BPF_ADD
, R1
, R2
),
1441 BPF_ALU32_REG(BPF_ADD
, R1
, R3
),
1442 BPF_ALU32_REG(BPF_ADD
, R1
, R4
),
1443 BPF_ALU32_REG(BPF_ADD
, R1
, R5
),
1444 BPF_ALU32_REG(BPF_ADD
, R1
, R6
),
1445 BPF_ALU32_REG(BPF_ADD
, R1
, R7
),
1446 BPF_ALU32_REG(BPF_ADD
, R1
, R8
),
1447 BPF_ALU32_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1448 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1450 BPF_ALU32_REG(BPF_ADD
, R2
, R0
),
1451 BPF_ALU32_REG(BPF_ADD
, R2
, R1
),
1452 BPF_ALU32_REG(BPF_ADD
, R2
, R2
),
1453 BPF_ALU32_REG(BPF_ADD
, R2
, R3
),
1454 BPF_ALU32_REG(BPF_ADD
, R2
, R4
),
1455 BPF_ALU32_REG(BPF_ADD
, R2
, R5
),
1456 BPF_ALU32_REG(BPF_ADD
, R2
, R6
),
1457 BPF_ALU32_REG(BPF_ADD
, R2
, R7
),
1458 BPF_ALU32_REG(BPF_ADD
, R2
, R8
),
1459 BPF_ALU32_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1460 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1462 BPF_ALU32_REG(BPF_ADD
, R3
, R0
),
1463 BPF_ALU32_REG(BPF_ADD
, R3
, R1
),
1464 BPF_ALU32_REG(BPF_ADD
, R3
, R2
),
1465 BPF_ALU32_REG(BPF_ADD
, R3
, R3
),
1466 BPF_ALU32_REG(BPF_ADD
, R3
, R4
),
1467 BPF_ALU32_REG(BPF_ADD
, R3
, R5
),
1468 BPF_ALU32_REG(BPF_ADD
, R3
, R6
),
1469 BPF_ALU32_REG(BPF_ADD
, R3
, R7
),
1470 BPF_ALU32_REG(BPF_ADD
, R3
, R8
),
1471 BPF_ALU32_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1472 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1474 BPF_ALU32_REG(BPF_ADD
, R4
, R0
),
1475 BPF_ALU32_REG(BPF_ADD
, R4
, R1
),
1476 BPF_ALU32_REG(BPF_ADD
, R4
, R2
),
1477 BPF_ALU32_REG(BPF_ADD
, R4
, R3
),
1478 BPF_ALU32_REG(BPF_ADD
, R4
, R4
),
1479 BPF_ALU32_REG(BPF_ADD
, R4
, R5
),
1480 BPF_ALU32_REG(BPF_ADD
, R4
, R6
),
1481 BPF_ALU32_REG(BPF_ADD
, R4
, R7
),
1482 BPF_ALU32_REG(BPF_ADD
, R4
, R8
),
1483 BPF_ALU32_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1484 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1486 BPF_ALU32_REG(BPF_ADD
, R5
, R0
),
1487 BPF_ALU32_REG(BPF_ADD
, R5
, R1
),
1488 BPF_ALU32_REG(BPF_ADD
, R5
, R2
),
1489 BPF_ALU32_REG(BPF_ADD
, R5
, R3
),
1490 BPF_ALU32_REG(BPF_ADD
, R5
, R4
),
1491 BPF_ALU32_REG(BPF_ADD
, R5
, R5
),
1492 BPF_ALU32_REG(BPF_ADD
, R5
, R6
),
1493 BPF_ALU32_REG(BPF_ADD
, R5
, R7
),
1494 BPF_ALU32_REG(BPF_ADD
, R5
, R8
),
1495 BPF_ALU32_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1496 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1498 BPF_ALU32_REG(BPF_ADD
, R6
, R0
),
1499 BPF_ALU32_REG(BPF_ADD
, R6
, R1
),
1500 BPF_ALU32_REG(BPF_ADD
, R6
, R2
),
1501 BPF_ALU32_REG(BPF_ADD
, R6
, R3
),
1502 BPF_ALU32_REG(BPF_ADD
, R6
, R4
),
1503 BPF_ALU32_REG(BPF_ADD
, R6
, R5
),
1504 BPF_ALU32_REG(BPF_ADD
, R6
, R6
),
1505 BPF_ALU32_REG(BPF_ADD
, R6
, R7
),
1506 BPF_ALU32_REG(BPF_ADD
, R6
, R8
),
1507 BPF_ALU32_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1508 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1510 BPF_ALU32_REG(BPF_ADD
, R7
, R0
),
1511 BPF_ALU32_REG(BPF_ADD
, R7
, R1
),
1512 BPF_ALU32_REG(BPF_ADD
, R7
, R2
),
1513 BPF_ALU32_REG(BPF_ADD
, R7
, R3
),
1514 BPF_ALU32_REG(BPF_ADD
, R7
, R4
),
1515 BPF_ALU32_REG(BPF_ADD
, R7
, R5
),
1516 BPF_ALU32_REG(BPF_ADD
, R7
, R6
),
1517 BPF_ALU32_REG(BPF_ADD
, R7
, R7
),
1518 BPF_ALU32_REG(BPF_ADD
, R7
, R8
),
1519 BPF_ALU32_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1520 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1522 BPF_ALU32_REG(BPF_ADD
, R8
, R0
),
1523 BPF_ALU32_REG(BPF_ADD
, R8
, R1
),
1524 BPF_ALU32_REG(BPF_ADD
, R8
, R2
),
1525 BPF_ALU32_REG(BPF_ADD
, R8
, R3
),
1526 BPF_ALU32_REG(BPF_ADD
, R8
, R4
),
1527 BPF_ALU32_REG(BPF_ADD
, R8
, R5
),
1528 BPF_ALU32_REG(BPF_ADD
, R8
, R6
),
1529 BPF_ALU32_REG(BPF_ADD
, R8
, R7
),
1530 BPF_ALU32_REG(BPF_ADD
, R8
, R8
),
1531 BPF_ALU32_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1532 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1534 BPF_ALU32_REG(BPF_ADD
, R9
, R0
),
1535 BPF_ALU32_REG(BPF_ADD
, R9
, R1
),
1536 BPF_ALU32_REG(BPF_ADD
, R9
, R2
),
1537 BPF_ALU32_REG(BPF_ADD
, R9
, R3
),
1538 BPF_ALU32_REG(BPF_ADD
, R9
, R4
),
1539 BPF_ALU32_REG(BPF_ADD
, R9
, R5
),
1540 BPF_ALU32_REG(BPF_ADD
, R9
, R6
),
1541 BPF_ALU32_REG(BPF_ADD
, R9
, R7
),
1542 BPF_ALU32_REG(BPF_ADD
, R9
, R8
),
1543 BPF_ALU32_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1544 BPF_ALU32_REG(BPF_MOV
, R0
, R9
),
1551 { /* Mainly checking JIT here. */
1554 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1555 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1556 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1557 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1558 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1559 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1560 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1561 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1562 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1563 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1564 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1565 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1566 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1567 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1568 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1569 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1570 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1571 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1572 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1573 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1574 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1575 BPF_JMP_IMM(BPF_JEQ
, R0
, -55, 1),
1577 BPF_ALU64_REG(BPF_SUB
, R1
, R0
),
1578 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1579 BPF_ALU64_REG(BPF_SUB
, R1
, R3
),
1580 BPF_ALU64_REG(BPF_SUB
, R1
, R4
),
1581 BPF_ALU64_REG(BPF_SUB
, R1
, R5
),
1582 BPF_ALU64_REG(BPF_SUB
, R1
, R6
),
1583 BPF_ALU64_REG(BPF_SUB
, R1
, R7
),
1584 BPF_ALU64_REG(BPF_SUB
, R1
, R8
),
1585 BPF_ALU64_REG(BPF_SUB
, R1
, R9
),
1586 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1587 BPF_ALU64_REG(BPF_SUB
, R2
, R0
),
1588 BPF_ALU64_REG(BPF_SUB
, R2
, R1
),
1589 BPF_ALU64_REG(BPF_SUB
, R2
, R3
),
1590 BPF_ALU64_REG(BPF_SUB
, R2
, R4
),
1591 BPF_ALU64_REG(BPF_SUB
, R2
, R5
),
1592 BPF_ALU64_REG(BPF_SUB
, R2
, R6
),
1593 BPF_ALU64_REG(BPF_SUB
, R2
, R7
),
1594 BPF_ALU64_REG(BPF_SUB
, R2
, R8
),
1595 BPF_ALU64_REG(BPF_SUB
, R2
, R9
),
1596 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1597 BPF_ALU64_REG(BPF_SUB
, R3
, R0
),
1598 BPF_ALU64_REG(BPF_SUB
, R3
, R1
),
1599 BPF_ALU64_REG(BPF_SUB
, R3
, R2
),
1600 BPF_ALU64_REG(BPF_SUB
, R3
, R4
),
1601 BPF_ALU64_REG(BPF_SUB
, R3
, R5
),
1602 BPF_ALU64_REG(BPF_SUB
, R3
, R6
),
1603 BPF_ALU64_REG(BPF_SUB
, R3
, R7
),
1604 BPF_ALU64_REG(BPF_SUB
, R3
, R8
),
1605 BPF_ALU64_REG(BPF_SUB
, R3
, R9
),
1606 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1607 BPF_ALU64_REG(BPF_SUB
, R4
, R0
),
1608 BPF_ALU64_REG(BPF_SUB
, R4
, R1
),
1609 BPF_ALU64_REG(BPF_SUB
, R4
, R2
),
1610 BPF_ALU64_REG(BPF_SUB
, R4
, R3
),
1611 BPF_ALU64_REG(BPF_SUB
, R4
, R5
),
1612 BPF_ALU64_REG(BPF_SUB
, R4
, R6
),
1613 BPF_ALU64_REG(BPF_SUB
, R4
, R7
),
1614 BPF_ALU64_REG(BPF_SUB
, R4
, R8
),
1615 BPF_ALU64_REG(BPF_SUB
, R4
, R9
),
1616 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1617 BPF_ALU64_REG(BPF_SUB
, R5
, R0
),
1618 BPF_ALU64_REG(BPF_SUB
, R5
, R1
),
1619 BPF_ALU64_REG(BPF_SUB
, R5
, R2
),
1620 BPF_ALU64_REG(BPF_SUB
, R5
, R3
),
1621 BPF_ALU64_REG(BPF_SUB
, R5
, R4
),
1622 BPF_ALU64_REG(BPF_SUB
, R5
, R6
),
1623 BPF_ALU64_REG(BPF_SUB
, R5
, R7
),
1624 BPF_ALU64_REG(BPF_SUB
, R5
, R8
),
1625 BPF_ALU64_REG(BPF_SUB
, R5
, R9
),
1626 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1627 BPF_ALU64_REG(BPF_SUB
, R6
, R0
),
1628 BPF_ALU64_REG(BPF_SUB
, R6
, R1
),
1629 BPF_ALU64_REG(BPF_SUB
, R6
, R2
),
1630 BPF_ALU64_REG(BPF_SUB
, R6
, R3
),
1631 BPF_ALU64_REG(BPF_SUB
, R6
, R4
),
1632 BPF_ALU64_REG(BPF_SUB
, R6
, R5
),
1633 BPF_ALU64_REG(BPF_SUB
, R6
, R7
),
1634 BPF_ALU64_REG(BPF_SUB
, R6
, R8
),
1635 BPF_ALU64_REG(BPF_SUB
, R6
, R9
),
1636 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1637 BPF_ALU64_REG(BPF_SUB
, R7
, R0
),
1638 BPF_ALU64_REG(BPF_SUB
, R7
, R1
),
1639 BPF_ALU64_REG(BPF_SUB
, R7
, R2
),
1640 BPF_ALU64_REG(BPF_SUB
, R7
, R3
),
1641 BPF_ALU64_REG(BPF_SUB
, R7
, R4
),
1642 BPF_ALU64_REG(BPF_SUB
, R7
, R5
),
1643 BPF_ALU64_REG(BPF_SUB
, R7
, R6
),
1644 BPF_ALU64_REG(BPF_SUB
, R7
, R8
),
1645 BPF_ALU64_REG(BPF_SUB
, R7
, R9
),
1646 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1647 BPF_ALU64_REG(BPF_SUB
, R8
, R0
),
1648 BPF_ALU64_REG(BPF_SUB
, R8
, R1
),
1649 BPF_ALU64_REG(BPF_SUB
, R8
, R2
),
1650 BPF_ALU64_REG(BPF_SUB
, R8
, R3
),
1651 BPF_ALU64_REG(BPF_SUB
, R8
, R4
),
1652 BPF_ALU64_REG(BPF_SUB
, R8
, R5
),
1653 BPF_ALU64_REG(BPF_SUB
, R8
, R6
),
1654 BPF_ALU64_REG(BPF_SUB
, R8
, R7
),
1655 BPF_ALU64_REG(BPF_SUB
, R8
, R9
),
1656 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1657 BPF_ALU64_REG(BPF_SUB
, R9
, R0
),
1658 BPF_ALU64_REG(BPF_SUB
, R9
, R1
),
1659 BPF_ALU64_REG(BPF_SUB
, R9
, R2
),
1660 BPF_ALU64_REG(BPF_SUB
, R9
, R3
),
1661 BPF_ALU64_REG(BPF_SUB
, R9
, R4
),
1662 BPF_ALU64_REG(BPF_SUB
, R9
, R5
),
1663 BPF_ALU64_REG(BPF_SUB
, R9
, R6
),
1664 BPF_ALU64_REG(BPF_SUB
, R9
, R7
),
1665 BPF_ALU64_REG(BPF_SUB
, R9
, R8
),
1666 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1667 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1668 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
1669 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1670 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1671 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1672 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1673 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1674 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1675 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1676 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1677 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1684 { /* Mainly checking JIT here. */
1687 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1688 BPF_ALU64_REG(BPF_XOR
, R1
, R1
),
1689 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 1),
1691 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1692 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1693 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1694 BPF_ALU64_REG(BPF_XOR
, R2
, R2
),
1695 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
1697 BPF_ALU64_REG(BPF_SUB
, R2
, R2
),
1698 BPF_ALU64_REG(BPF_XOR
, R3
, R3
),
1699 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1700 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1701 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 1),
1703 BPF_ALU64_REG(BPF_SUB
, R3
, R3
),
1704 BPF_ALU64_REG(BPF_XOR
, R4
, R4
),
1705 BPF_ALU64_IMM(BPF_MOV
, R2
, 1),
1706 BPF_ALU64_IMM(BPF_MOV
, R5
, -1),
1707 BPF_JMP_REG(BPF_JEQ
, R3
, R4
, 1),
1709 BPF_ALU64_REG(BPF_SUB
, R4
, R4
),
1710 BPF_ALU64_REG(BPF_XOR
, R5
, R5
),
1711 BPF_ALU64_IMM(BPF_MOV
, R3
, 1),
1712 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
1713 BPF_JMP_REG(BPF_JEQ
, R5
, R4
, 1),
1715 BPF_ALU64_IMM(BPF_MOV
, R5
, 1),
1716 BPF_ALU64_REG(BPF_SUB
, R5
, R5
),
1717 BPF_ALU64_REG(BPF_XOR
, R6
, R6
),
1718 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1719 BPF_ALU64_IMM(BPF_MOV
, R8
, -1),
1720 BPF_JMP_REG(BPF_JEQ
, R5
, R6
, 1),
1722 BPF_ALU64_REG(BPF_SUB
, R6
, R6
),
1723 BPF_ALU64_REG(BPF_XOR
, R7
, R7
),
1724 BPF_JMP_REG(BPF_JEQ
, R7
, R6
, 1),
1726 BPF_ALU64_REG(BPF_SUB
, R7
, R7
),
1727 BPF_ALU64_REG(BPF_XOR
, R8
, R8
),
1728 BPF_JMP_REG(BPF_JEQ
, R7
, R8
, 1),
1730 BPF_ALU64_REG(BPF_SUB
, R8
, R8
),
1731 BPF_ALU64_REG(BPF_XOR
, R9
, R9
),
1732 BPF_JMP_REG(BPF_JEQ
, R9
, R8
, 1),
1734 BPF_ALU64_REG(BPF_SUB
, R9
, R9
),
1735 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1736 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 1),
1738 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1739 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1740 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 2),
1741 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1743 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1750 { /* Mainly checking JIT here. */
1753 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1754 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1755 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1756 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1757 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1758 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1759 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1760 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1761 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1762 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1763 BPF_ALU64_REG(BPF_MUL
, R0
, R0
),
1764 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
1765 BPF_ALU64_REG(BPF_MUL
, R0
, R2
),
1766 BPF_ALU64_REG(BPF_MUL
, R0
, R3
),
1767 BPF_ALU64_REG(BPF_MUL
, R0
, R4
),
1768 BPF_ALU64_REG(BPF_MUL
, R0
, R5
),
1769 BPF_ALU64_REG(BPF_MUL
, R0
, R6
),
1770 BPF_ALU64_REG(BPF_MUL
, R0
, R7
),
1771 BPF_ALU64_REG(BPF_MUL
, R0
, R8
),
1772 BPF_ALU64_REG(BPF_MUL
, R0
, R9
),
1773 BPF_ALU64_IMM(BPF_MUL
, R0
, 10),
1774 BPF_JMP_IMM(BPF_JEQ
, R0
, 439084800, 1),
1776 BPF_ALU64_REG(BPF_MUL
, R1
, R0
),
1777 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1778 BPF_ALU64_REG(BPF_MUL
, R1
, R3
),
1779 BPF_ALU64_REG(BPF_MUL
, R1
, R4
),
1780 BPF_ALU64_REG(BPF_MUL
, R1
, R5
),
1781 BPF_ALU64_REG(BPF_MUL
, R1
, R6
),
1782 BPF_ALU64_REG(BPF_MUL
, R1
, R7
),
1783 BPF_ALU64_REG(BPF_MUL
, R1
, R8
),
1784 BPF_ALU64_REG(BPF_MUL
, R1
, R9
),
1785 BPF_ALU64_IMM(BPF_MUL
, R1
, 10),
1786 BPF_ALU64_REG(BPF_MOV
, R2
, R1
),
1787 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1788 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5a924, 1),
1790 BPF_ALU64_IMM(BPF_LSH
, R1
, 32),
1791 BPF_ALU64_IMM(BPF_ARSH
, R1
, 32),
1792 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xebb90000, 1),
1794 BPF_ALU64_REG(BPF_MUL
, R2
, R0
),
1795 BPF_ALU64_REG(BPF_MUL
, R2
, R1
),
1796 BPF_ALU64_REG(BPF_MUL
, R2
, R3
),
1797 BPF_ALU64_REG(BPF_MUL
, R2
, R4
),
1798 BPF_ALU64_REG(BPF_MUL
, R2
, R5
),
1799 BPF_ALU64_REG(BPF_MUL
, R2
, R6
),
1800 BPF_ALU64_REG(BPF_MUL
, R2
, R7
),
1801 BPF_ALU64_REG(BPF_MUL
, R2
, R8
),
1802 BPF_ALU64_REG(BPF_MUL
, R2
, R9
),
1803 BPF_ALU64_IMM(BPF_MUL
, R2
, 10),
1804 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1805 BPF_ALU64_REG(BPF_MOV
, R0
, R2
),
1810 { { 0, 0x35d97ef2 } }
1812 { /* Mainly checking JIT here. */
1815 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1816 BPF_MOV64_REG(R1
, R0
),
1817 BPF_MOV64_REG(R2
, R1
),
1818 BPF_MOV64_REG(R3
, R2
),
1819 BPF_MOV64_REG(R4
, R3
),
1820 BPF_MOV64_REG(R5
, R4
),
1821 BPF_MOV64_REG(R6
, R5
),
1822 BPF_MOV64_REG(R7
, R6
),
1823 BPF_MOV64_REG(R8
, R7
),
1824 BPF_MOV64_REG(R9
, R8
),
1825 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1826 BPF_ALU64_IMM(BPF_MOV
, R1
, 0),
1827 BPF_ALU64_IMM(BPF_MOV
, R2
, 0),
1828 BPF_ALU64_IMM(BPF_MOV
, R3
, 0),
1829 BPF_ALU64_IMM(BPF_MOV
, R4
, 0),
1830 BPF_ALU64_IMM(BPF_MOV
, R5
, 0),
1831 BPF_ALU64_IMM(BPF_MOV
, R6
, 0),
1832 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
1833 BPF_ALU64_IMM(BPF_MOV
, R8
, 0),
1834 BPF_ALU64_IMM(BPF_MOV
, R9
, 0),
1835 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1836 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1837 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1838 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1839 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1840 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1841 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1842 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1843 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1844 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1845 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1852 { /* Mainly checking JIT here. */
1855 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1856 BPF_MOV64_REG(R1
, R0
),
1857 BPF_MOV64_REG(R2
, R1
),
1858 BPF_MOV64_REG(R3
, R2
),
1859 BPF_MOV64_REG(R4
, R3
),
1860 BPF_MOV64_REG(R5
, R4
),
1861 BPF_MOV64_REG(R6
, R5
),
1862 BPF_MOV64_REG(R7
, R6
),
1863 BPF_MOV64_REG(R8
, R7
),
1864 BPF_MOV64_REG(R9
, R8
),
1865 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
1866 BPF_ALU32_IMM(BPF_MOV
, R1
, 0),
1867 BPF_ALU32_IMM(BPF_MOV
, R2
, 0),
1868 BPF_ALU32_IMM(BPF_MOV
, R3
, 0),
1869 BPF_ALU32_IMM(BPF_MOV
, R4
, 0),
1870 BPF_ALU32_IMM(BPF_MOV
, R5
, 0),
1871 BPF_ALU32_IMM(BPF_MOV
, R6
, 0),
1872 BPF_ALU32_IMM(BPF_MOV
, R7
, 0),
1873 BPF_ALU32_IMM(BPF_MOV
, R8
, 0),
1874 BPF_ALU32_IMM(BPF_MOV
, R9
, 0),
1875 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1876 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1877 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1878 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1879 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1880 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1881 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1882 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1883 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1884 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1885 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1892 { /* Mainly checking JIT here. */
1895 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1896 BPF_MOV64_REG(R1
, R0
),
1897 BPF_MOV64_REG(R2
, R1
),
1898 BPF_MOV64_REG(R3
, R2
),
1899 BPF_MOV64_REG(R4
, R3
),
1900 BPF_MOV64_REG(R5
, R4
),
1901 BPF_MOV64_REG(R6
, R5
),
1902 BPF_MOV64_REG(R7
, R6
),
1903 BPF_MOV64_REG(R8
, R7
),
1904 BPF_MOV64_REG(R9
, R8
),
1905 BPF_LD_IMM64(R0
, 0x0LL
),
1906 BPF_LD_IMM64(R1
, 0x0LL
),
1907 BPF_LD_IMM64(R2
, 0x0LL
),
1908 BPF_LD_IMM64(R3
, 0x0LL
),
1909 BPF_LD_IMM64(R4
, 0x0LL
),
1910 BPF_LD_IMM64(R5
, 0x0LL
),
1911 BPF_LD_IMM64(R6
, 0x0LL
),
1912 BPF_LD_IMM64(R7
, 0x0LL
),
1913 BPF_LD_IMM64(R8
, 0x0LL
),
1914 BPF_LD_IMM64(R9
, 0x0LL
),
1915 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1916 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1917 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1918 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1919 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1920 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1921 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1922 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1923 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1924 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1925 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1935 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1936 BPF_ALU64_IMM(BPF_ADD
, R0
, -1),
1937 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1938 BPF_ALU64_IMM(BPF_XOR
, R2
, 3),
1939 BPF_ALU64_REG(BPF_DIV
, R0
, R2
),
1940 BPF_JMP_IMM(BPF_JEQ
, R0
, 10, 1),
1942 BPF_ALU64_IMM(BPF_MOD
, R0
, 3),
1943 BPF_JMP_IMM(BPF_JEQ
, R0
, 1, 1),
1945 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1953 "INT: shifts by register",
1955 BPF_MOV64_IMM(R0
, -1234),
1956 BPF_MOV64_IMM(R1
, 1),
1957 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
1958 BPF_JMP_IMM(BPF_JEQ
, R0
, 0x7ffffd97, 1),
1960 BPF_MOV64_IMM(R2
, 1),
1961 BPF_ALU64_REG(BPF_LSH
, R0
, R2
),
1962 BPF_MOV32_IMM(R4
, -1234),
1963 BPF_JMP_REG(BPF_JEQ
, R0
, R4
, 1),
1965 BPF_ALU64_IMM(BPF_AND
, R4
, 63),
1966 BPF_ALU64_REG(BPF_LSH
, R0
, R4
), /* R0 <= 46 */
1967 BPF_MOV64_IMM(R3
, 47),
1968 BPF_ALU64_REG(BPF_ARSH
, R0
, R3
),
1969 BPF_JMP_IMM(BPF_JEQ
, R0
, -617, 1),
1971 BPF_MOV64_IMM(R2
, 1),
1972 BPF_ALU64_REG(BPF_LSH
, R4
, R2
), /* R4 = 46 << 1 */
1973 BPF_JMP_IMM(BPF_JEQ
, R4
, 92, 1),
1975 BPF_MOV64_IMM(R4
, 4),
1976 BPF_ALU64_REG(BPF_LSH
, R4
, R4
), /* R4 = 4 << 4 */
1977 BPF_JMP_IMM(BPF_JEQ
, R4
, 64, 1),
1979 BPF_MOV64_IMM(R4
, 5),
1980 BPF_ALU32_REG(BPF_LSH
, R4
, R4
), /* R4 = 5 << 5 */
1981 BPF_JMP_IMM(BPF_JEQ
, R4
, 160, 1),
1983 BPF_MOV64_IMM(R0
, -1),
1993 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
1994 BPF_LD_ABS(BPF_B
, 3),
1995 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1996 BPF_ALU32_REG(BPF_DIV
, R0
, R2
),
1997 BPF_ALU64_REG(BPF_MOV
, R8
, R0
),
1998 BPF_LD_ABS(BPF_B
, 4),
1999 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
2000 BPF_LD_IND(BPF_B
, R8
, -70),
2004 { 10, 20, 30, 40, 50 },
2005 { { 4, 0 }, { 5, 10 } }
2008 /* This one doesn't go through verifier, but is just raw insn
2009 * as opposed to cBPF tests from here. Thus div by 0 tests are
2010 * done in test_verifier in BPF kselftests.
2014 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
2015 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
2016 BPF_LD_ABS(BPF_B
, 3),
2017 BPF_ALU32_REG(BPF_DIV
, R0
, R7
),
2021 { 10, 20, 30, 40, 50 },
2022 { { 3, 0 }, { 4, 0 } }
2025 "check: missing ret",
2027 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
2029 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2032 .fill_helper
= NULL
,
2033 .expected_errcode
= -EINVAL
,
2038 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0),
2039 BPF_STMT(BPF_RET
| BPF_K
, 0)
2041 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2044 .fill_helper
= NULL
,
2045 .expected_errcode
= -EINVAL
,
2048 "check: unknown insn",
2050 /* seccomp insn, rejected in socket filter */
2051 BPF_STMT(BPF_LDX
| BPF_W
| BPF_ABS
, 0),
2052 BPF_STMT(BPF_RET
| BPF_K
, 0)
2054 CLASSIC
| FLAG_EXPECTED_FAIL
,
2057 .fill_helper
= NULL
,
2058 .expected_errcode
= -EINVAL
,
2061 "check: out of range spill/fill",
2063 BPF_STMT(BPF_STX
, 16),
2064 BPF_STMT(BPF_RET
| BPF_K
, 0)
2066 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2069 .fill_helper
= NULL
,
2070 .expected_errcode
= -EINVAL
,
2075 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2076 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 15),
2077 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2078 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2079 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2080 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2081 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
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_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 3, 4),
2091 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2092 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 1, 2),
2093 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2094 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2095 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2096 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2097 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2098 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2099 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
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_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 2, 3),
2110 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 1, 2),
2111 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2112 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2113 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2114 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2115 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2116 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2117 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2118 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2119 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2120 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2121 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2122 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2123 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2124 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2125 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2126 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2127 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 2, 3),
2128 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 1, 2),
2129 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2130 BPF_STMT(BPF_RET
| BPF_A
, 0),
2131 BPF_STMT(BPF_RET
| BPF_A
, 0),
2134 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2135 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2137 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2138 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2139 0xc0, 0xa8, 0x33, 0x01,
2140 0xc0, 0xa8, 0x33, 0x02,
2143 0x00, 0x14, 0x00, 0x00,
2144 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2145 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2146 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2147 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2148 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2149 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2150 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2151 0xcc, 0xcc, 0xcc, 0xcc },
2157 BPF_STMT(BPF_RET
| BPF_X
, 0),
2159 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2162 .fill_helper
= NULL
,
2163 .expected_errcode
= -EINVAL
,
2166 "check: LDX + RET X",
2168 BPF_STMT(BPF_LDX
| BPF_IMM
, 42),
2169 BPF_STMT(BPF_RET
| BPF_X
, 0),
2171 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2174 .fill_helper
= NULL
,
2175 .expected_errcode
= -EINVAL
,
2177 { /* Mainly checking JIT here. */
2178 "M[]: alt STX + LDX",
2180 BPF_STMT(BPF_LDX
| BPF_IMM
, 100),
2181 BPF_STMT(BPF_STX
, 0),
2182 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2183 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2184 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2185 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2186 BPF_STMT(BPF_STX
, 1),
2187 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2188 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2189 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2190 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2191 BPF_STMT(BPF_STX
, 2),
2192 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2193 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2194 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2195 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2196 BPF_STMT(BPF_STX
, 3),
2197 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2198 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2199 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2200 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2201 BPF_STMT(BPF_STX
, 4),
2202 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2203 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2204 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2205 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2206 BPF_STMT(BPF_STX
, 5),
2207 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2208 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2209 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2210 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2211 BPF_STMT(BPF_STX
, 6),
2212 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2213 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2214 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2215 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2216 BPF_STMT(BPF_STX
, 7),
2217 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2218 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2219 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2220 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2221 BPF_STMT(BPF_STX
, 8),
2222 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2223 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2224 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2225 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2226 BPF_STMT(BPF_STX
, 9),
2227 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2228 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2229 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2230 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2231 BPF_STMT(BPF_STX
, 10),
2232 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2233 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2234 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2235 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2236 BPF_STMT(BPF_STX
, 11),
2237 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2238 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2239 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2240 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2241 BPF_STMT(BPF_STX
, 12),
2242 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2243 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2244 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2245 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2246 BPF_STMT(BPF_STX
, 13),
2247 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2248 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2249 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2250 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2251 BPF_STMT(BPF_STX
, 14),
2252 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2253 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2254 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2255 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2256 BPF_STMT(BPF_STX
, 15),
2257 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2258 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2259 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2260 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2261 BPF_STMT(BPF_RET
| BPF_A
, 0),
2263 CLASSIC
| FLAG_NO_DATA
,
2267 { /* Mainly checking JIT here. */
2268 "M[]: full STX + full LDX",
2270 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbadfeedb),
2271 BPF_STMT(BPF_STX
, 0),
2272 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xecabedae),
2273 BPF_STMT(BPF_STX
, 1),
2274 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xafccfeaf),
2275 BPF_STMT(BPF_STX
, 2),
2276 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbffdcedc),
2277 BPF_STMT(BPF_STX
, 3),
2278 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbbbdccb),
2279 BPF_STMT(BPF_STX
, 4),
2280 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbabcbda),
2281 BPF_STMT(BPF_STX
, 5),
2282 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaedecbdb),
2283 BPF_STMT(BPF_STX
, 6),
2284 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xadebbade),
2285 BPF_STMT(BPF_STX
, 7),
2286 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfcfcfaec),
2287 BPF_STMT(BPF_STX
, 8),
2288 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbcdddbdc),
2289 BPF_STMT(BPF_STX
, 9),
2290 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfeefdfac),
2291 BPF_STMT(BPF_STX
, 10),
2292 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xcddcdeea),
2293 BPF_STMT(BPF_STX
, 11),
2294 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaccfaebb),
2295 BPF_STMT(BPF_STX
, 12),
2296 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbdcccdcf),
2297 BPF_STMT(BPF_STX
, 13),
2298 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaaedecde),
2299 BPF_STMT(BPF_STX
, 14),
2300 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfaeacdad),
2301 BPF_STMT(BPF_STX
, 15),
2302 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2303 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2304 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2305 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2306 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2307 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2308 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2309 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2310 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2311 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2312 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2313 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2314 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2315 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2316 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2317 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2318 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2319 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2320 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2321 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2322 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2323 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2324 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2325 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2326 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2327 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2328 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2329 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2330 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2331 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2332 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2333 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2334 BPF_STMT(BPF_RET
| BPF_A
, 0),
2336 CLASSIC
| FLAG_NO_DATA
,
2338 { { 0, 0x2a5a5e5 } },
2341 "check: SKF_AD_MAX",
2343 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2344 SKF_AD_OFF
+ SKF_AD_MAX
),
2345 BPF_STMT(BPF_RET
| BPF_A
, 0),
2347 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2350 .fill_helper
= NULL
,
2351 .expected_errcode
= -EINVAL
,
2353 { /* Passes checker but fails during runtime. */
2354 "LD [SKF_AD_OFF-1]",
2356 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2358 BPF_STMT(BPF_RET
| BPF_K
, 1),
2365 "load 64-bit immediate",
2367 BPF_LD_IMM64(R1
, 0x567800001234LL
),
2368 BPF_MOV64_REG(R2
, R1
),
2369 BPF_MOV64_REG(R3
, R2
),
2370 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
2371 BPF_ALU64_IMM(BPF_LSH
, R3
, 32),
2372 BPF_ALU64_IMM(BPF_RSH
, R3
, 32),
2373 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
2374 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5678, 1),
2376 BPF_JMP_IMM(BPF_JEQ
, R3
, 0x1234, 1),
2378 BPF_LD_IMM64(R0
, 0x1ffffffffLL
),
2379 BPF_ALU64_IMM(BPF_RSH
, R0
, 32), /* R0 = 1 */
2389 BPF_MOV64_REG(R6
, R1
),
2390 BPF_LD_ABS(BPF_H
, 12),
2391 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 28),
2392 BPF_LD_ABS(BPF_H
, 12),
2393 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 26),
2394 BPF_MOV32_IMM(R0
, 18),
2395 BPF_STX_MEM(BPF_W
, R10
, R0
, -64),
2396 BPF_LDX_MEM(BPF_W
, R7
, R10
, -64),
2397 BPF_LD_IND(BPF_W
, R7
, 14),
2398 BPF_STX_MEM(BPF_W
, R10
, R0
, -60),
2399 BPF_MOV32_IMM(R0
, 280971478),
2400 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2401 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2402 BPF_LDX_MEM(BPF_W
, R0
, R10
, -60),
2403 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2404 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 15),
2405 BPF_LD_ABS(BPF_H
, 12),
2406 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 13),
2407 BPF_MOV32_IMM(R0
, 22),
2408 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2409 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2410 BPF_LD_IND(BPF_H
, R7
, 14),
2411 BPF_STX_MEM(BPF_W
, R10
, R0
, -52),
2412 BPF_MOV32_IMM(R0
, 17366),
2413 BPF_STX_MEM(BPF_W
, R10
, R0
, -48),
2414 BPF_LDX_MEM(BPF_W
, R7
, R10
, -48),
2415 BPF_LDX_MEM(BPF_W
, R0
, R10
, -52),
2416 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2417 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 2),
2418 BPF_MOV32_IMM(R0
, 256),
2420 BPF_MOV32_IMM(R0
, 0),
2424 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2426 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2430 /* BPF_ALU | BPF_MOV | BPF_X */
2432 "ALU_MOV_X: dst = 2",
2434 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2435 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2443 "ALU_MOV_X: dst = 4294967295",
2445 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2446 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2451 { { 0, 4294967295U } },
2454 "ALU64_MOV_X: dst = 2",
2456 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2457 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2465 "ALU64_MOV_X: dst = 4294967295",
2467 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2468 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2473 { { 0, 4294967295U } },
2475 /* BPF_ALU | BPF_MOV | BPF_K */
2477 "ALU_MOV_K: dst = 2",
2479 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
2487 "ALU_MOV_K: dst = 4294967295",
2489 BPF_ALU32_IMM(BPF_MOV
, R0
, 4294967295U),
2494 { { 0, 4294967295U } },
2497 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2499 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2500 BPF_LD_IMM64(R3
, 0x00000000ffffffffLL
),
2501 BPF_ALU32_IMM(BPF_MOV
, R2
, 0xffffffff),
2502 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2503 BPF_MOV32_IMM(R0
, 2),
2505 BPF_MOV32_IMM(R0
, 1),
2513 "ALU64_MOV_K: dst = 2",
2515 BPF_ALU64_IMM(BPF_MOV
, R0
, 2),
2523 "ALU64_MOV_K: dst = 2147483647",
2525 BPF_ALU64_IMM(BPF_MOV
, R0
, 2147483647),
2530 { { 0, 2147483647 } },
2533 "ALU64_OR_K: dst = 0x0",
2535 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2536 BPF_LD_IMM64(R3
, 0x0),
2537 BPF_ALU64_IMM(BPF_MOV
, R2
, 0x0),
2538 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2539 BPF_MOV32_IMM(R0
, 2),
2541 BPF_MOV32_IMM(R0
, 1),
2549 "ALU64_MOV_K: dst = -1",
2551 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2552 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2553 BPF_ALU64_IMM(BPF_MOV
, R2
, 0xffffffff),
2554 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2555 BPF_MOV32_IMM(R0
, 2),
2557 BPF_MOV32_IMM(R0
, 1),
2564 /* BPF_ALU | BPF_ADD | BPF_X */
2566 "ALU_ADD_X: 1 + 2 = 3",
2568 BPF_LD_IMM64(R0
, 1),
2569 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2570 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2578 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2580 BPF_LD_IMM64(R0
, 1),
2581 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2582 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2587 { { 0, 4294967295U } },
2590 "ALU_ADD_X: 2 + 4294967294 = 0",
2592 BPF_LD_IMM64(R0
, 2),
2593 BPF_LD_IMM64(R1
, 4294967294U),
2594 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2595 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2596 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2598 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2606 "ALU64_ADD_X: 1 + 2 = 3",
2608 BPF_LD_IMM64(R0
, 1),
2609 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2610 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2618 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2620 BPF_LD_IMM64(R0
, 1),
2621 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2622 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2627 { { 0, 4294967295U } },
2630 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2632 BPF_LD_IMM64(R0
, 2),
2633 BPF_LD_IMM64(R1
, 4294967294U),
2634 BPF_LD_IMM64(R2
, 4294967296ULL),
2635 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2636 BPF_JMP_REG(BPF_JEQ
, R0
, R2
, 2),
2637 BPF_MOV32_IMM(R0
, 0),
2639 BPF_MOV32_IMM(R0
, 1),
2646 /* BPF_ALU | BPF_ADD | BPF_K */
2648 "ALU_ADD_K: 1 + 2 = 3",
2650 BPF_LD_IMM64(R0
, 1),
2651 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2659 "ALU_ADD_K: 3 + 0 = 3",
2661 BPF_LD_IMM64(R0
, 3),
2662 BPF_ALU32_IMM(BPF_ADD
, R0
, 0),
2670 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2672 BPF_LD_IMM64(R0
, 1),
2673 BPF_ALU32_IMM(BPF_ADD
, R0
, 4294967294U),
2678 { { 0, 4294967295U } },
2681 "ALU_ADD_K: 4294967294 + 2 = 0",
2683 BPF_LD_IMM64(R0
, 4294967294U),
2684 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2685 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2686 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2688 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2696 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2698 BPF_LD_IMM64(R2
, 0x0),
2699 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
2700 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffffffff),
2701 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2702 BPF_MOV32_IMM(R0
, 2),
2704 BPF_MOV32_IMM(R0
, 1),
2712 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2714 BPF_LD_IMM64(R2
, 0x0),
2715 BPF_LD_IMM64(R3
, 0xffff),
2716 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffff),
2717 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2718 BPF_MOV32_IMM(R0
, 2),
2720 BPF_MOV32_IMM(R0
, 1),
2728 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2730 BPF_LD_IMM64(R2
, 0x0),
2731 BPF_LD_IMM64(R3
, 0x7fffffff),
2732 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x7fffffff),
2733 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2734 BPF_MOV32_IMM(R0
, 2),
2736 BPF_MOV32_IMM(R0
, 1),
2744 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2746 BPF_LD_IMM64(R2
, 0x0),
2747 BPF_LD_IMM64(R3
, 0x80000000),
2748 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80000000),
2749 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2750 BPF_MOV32_IMM(R0
, 2),
2752 BPF_MOV32_IMM(R0
, 1),
2760 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2762 BPF_LD_IMM64(R2
, 0x0),
2763 BPF_LD_IMM64(R3
, 0x80008000),
2764 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80008000),
2765 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2766 BPF_MOV32_IMM(R0
, 2),
2768 BPF_MOV32_IMM(R0
, 1),
2776 "ALU64_ADD_K: 1 + 2 = 3",
2778 BPF_LD_IMM64(R0
, 1),
2779 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2787 "ALU64_ADD_K: 3 + 0 = 3",
2789 BPF_LD_IMM64(R0
, 3),
2790 BPF_ALU64_IMM(BPF_ADD
, R0
, 0),
2798 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2800 BPF_LD_IMM64(R0
, 1),
2801 BPF_ALU64_IMM(BPF_ADD
, R0
, 2147483646),
2806 { { 0, 2147483647 } },
2809 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2811 BPF_LD_IMM64(R0
, 4294967294U),
2812 BPF_LD_IMM64(R1
, 4294967296ULL),
2813 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2814 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 2),
2815 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2817 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2825 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2827 BPF_LD_IMM64(R0
, 2147483646),
2828 BPF_ALU64_IMM(BPF_ADD
, R0
, -2147483647),
2836 "ALU64_ADD_K: 1 + 0 = 1",
2838 BPF_LD_IMM64(R2
, 0x1),
2839 BPF_LD_IMM64(R3
, 0x1),
2840 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x0),
2841 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2842 BPF_MOV32_IMM(R0
, 2),
2844 BPF_MOV32_IMM(R0
, 1),
2852 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2854 BPF_LD_IMM64(R2
, 0x0),
2855 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2856 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffffffff),
2857 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2858 BPF_MOV32_IMM(R0
, 2),
2860 BPF_MOV32_IMM(R0
, 1),
2868 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2870 BPF_LD_IMM64(R2
, 0x0),
2871 BPF_LD_IMM64(R3
, 0xffff),
2872 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffff),
2873 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2874 BPF_MOV32_IMM(R0
, 2),
2876 BPF_MOV32_IMM(R0
, 1),
2884 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2886 BPF_LD_IMM64(R2
, 0x0),
2887 BPF_LD_IMM64(R3
, 0x7fffffff),
2888 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x7fffffff),
2889 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2890 BPF_MOV32_IMM(R0
, 2),
2892 BPF_MOV32_IMM(R0
, 1),
2900 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2902 BPF_LD_IMM64(R2
, 0x0),
2903 BPF_LD_IMM64(R3
, 0xffffffff80000000LL
),
2904 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80000000),
2905 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2906 BPF_MOV32_IMM(R0
, 2),
2908 BPF_MOV32_IMM(R0
, 1),
2916 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2918 BPF_LD_IMM64(R2
, 0x0),
2919 BPF_LD_IMM64(R3
, 0xffffffff80008000LL
),
2920 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80008000),
2921 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2922 BPF_MOV32_IMM(R0
, 2),
2924 BPF_MOV32_IMM(R0
, 1),
2931 /* BPF_ALU | BPF_SUB | BPF_X */
2933 "ALU_SUB_X: 3 - 1 = 2",
2935 BPF_LD_IMM64(R0
, 3),
2936 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2937 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2945 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2947 BPF_LD_IMM64(R0
, 4294967295U),
2948 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2949 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2957 "ALU64_SUB_X: 3 - 1 = 2",
2959 BPF_LD_IMM64(R0
, 3),
2960 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2961 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2969 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2971 BPF_LD_IMM64(R0
, 4294967295U),
2972 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2973 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2980 /* BPF_ALU | BPF_SUB | BPF_K */
2982 "ALU_SUB_K: 3 - 1 = 2",
2984 BPF_LD_IMM64(R0
, 3),
2985 BPF_ALU32_IMM(BPF_SUB
, R0
, 1),
2993 "ALU_SUB_K: 3 - 0 = 3",
2995 BPF_LD_IMM64(R0
, 3),
2996 BPF_ALU32_IMM(BPF_SUB
, R0
, 0),
3004 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
3006 BPF_LD_IMM64(R0
, 4294967295U),
3007 BPF_ALU32_IMM(BPF_SUB
, R0
, 4294967294U),
3015 "ALU64_SUB_K: 3 - 1 = 2",
3017 BPF_LD_IMM64(R0
, 3),
3018 BPF_ALU64_IMM(BPF_SUB
, R0
, 1),
3026 "ALU64_SUB_K: 3 - 0 = 3",
3028 BPF_LD_IMM64(R0
, 3),
3029 BPF_ALU64_IMM(BPF_SUB
, R0
, 0),
3037 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3039 BPF_LD_IMM64(R0
, 4294967294U),
3040 BPF_ALU64_IMM(BPF_SUB
, R0
, 4294967295U),
3048 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3050 BPF_LD_IMM64(R0
, 2147483646),
3051 BPF_ALU64_IMM(BPF_SUB
, R0
, 2147483647),
3058 /* BPF_ALU | BPF_MUL | BPF_X */
3060 "ALU_MUL_X: 2 * 3 = 6",
3062 BPF_LD_IMM64(R0
, 2),
3063 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3064 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3072 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3074 BPF_LD_IMM64(R0
, 2),
3075 BPF_ALU32_IMM(BPF_MOV
, R1
, 0x7FFFFFF8),
3076 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3081 { { 0, 0xFFFFFFF0 } },
3084 "ALU_MUL_X: -1 * -1 = 1",
3086 BPF_LD_IMM64(R0
, -1),
3087 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
3088 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3096 "ALU64_MUL_X: 2 * 3 = 6",
3098 BPF_LD_IMM64(R0
, 2),
3099 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3100 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3108 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3110 BPF_LD_IMM64(R0
, 1),
3111 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3112 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3117 { { 0, 2147483647 } },
3119 /* BPF_ALU | BPF_MUL | BPF_K */
3121 "ALU_MUL_K: 2 * 3 = 6",
3123 BPF_LD_IMM64(R0
, 2),
3124 BPF_ALU32_IMM(BPF_MUL
, R0
, 3),
3132 "ALU_MUL_K: 3 * 1 = 3",
3134 BPF_LD_IMM64(R0
, 3),
3135 BPF_ALU32_IMM(BPF_MUL
, R0
, 1),
3143 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3145 BPF_LD_IMM64(R0
, 2),
3146 BPF_ALU32_IMM(BPF_MUL
, R0
, 0x7FFFFFF8),
3151 { { 0, 0xFFFFFFF0 } },
3154 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3156 BPF_LD_IMM64(R2
, 0x1),
3157 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
3158 BPF_ALU32_IMM(BPF_MUL
, R2
, 0xffffffff),
3159 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3160 BPF_MOV32_IMM(R0
, 2),
3162 BPF_MOV32_IMM(R0
, 1),
3170 "ALU64_MUL_K: 2 * 3 = 6",
3172 BPF_LD_IMM64(R0
, 2),
3173 BPF_ALU64_IMM(BPF_MUL
, R0
, 3),
3181 "ALU64_MUL_K: 3 * 1 = 3",
3183 BPF_LD_IMM64(R0
, 3),
3184 BPF_ALU64_IMM(BPF_MUL
, R0
, 1),
3192 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3194 BPF_LD_IMM64(R0
, 1),
3195 BPF_ALU64_IMM(BPF_MUL
, R0
, 2147483647),
3200 { { 0, 2147483647 } },
3203 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3205 BPF_LD_IMM64(R0
, 1),
3206 BPF_ALU64_IMM(BPF_MUL
, R0
, -2147483647),
3211 { { 0, -2147483647 } },
3214 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3216 BPF_LD_IMM64(R2
, 0x1),
3217 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3218 BPF_ALU64_IMM(BPF_MUL
, R2
, 0xffffffff),
3219 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3220 BPF_MOV32_IMM(R0
, 2),
3222 BPF_MOV32_IMM(R0
, 1),
3229 /* BPF_ALU | BPF_DIV | BPF_X */
3231 "ALU_DIV_X: 6 / 2 = 3",
3233 BPF_LD_IMM64(R0
, 6),
3234 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3235 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3243 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3245 BPF_LD_IMM64(R0
, 4294967295U),
3246 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
3247 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3255 "ALU64_DIV_X: 6 / 2 = 3",
3257 BPF_LD_IMM64(R0
, 6),
3258 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3259 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3267 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3269 BPF_LD_IMM64(R0
, 2147483647),
3270 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3271 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3279 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3281 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3282 BPF_LD_IMM64(R4
, 0xffffffffffffffffLL
),
3283 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3284 BPF_ALU64_REG(BPF_DIV
, R2
, R4
),
3285 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3286 BPF_MOV32_IMM(R0
, 2),
3288 BPF_MOV32_IMM(R0
, 1),
3295 /* BPF_ALU | BPF_DIV | BPF_K */
3297 "ALU_DIV_K: 6 / 2 = 3",
3299 BPF_LD_IMM64(R0
, 6),
3300 BPF_ALU32_IMM(BPF_DIV
, R0
, 2),
3308 "ALU_DIV_K: 3 / 1 = 3",
3310 BPF_LD_IMM64(R0
, 3),
3311 BPF_ALU32_IMM(BPF_DIV
, R0
, 1),
3319 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3321 BPF_LD_IMM64(R0
, 4294967295U),
3322 BPF_ALU32_IMM(BPF_DIV
, R0
, 4294967295U),
3330 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3332 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3333 BPF_LD_IMM64(R3
, 0x1UL
),
3334 BPF_ALU32_IMM(BPF_DIV
, R2
, 0xffffffff),
3335 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3336 BPF_MOV32_IMM(R0
, 2),
3338 BPF_MOV32_IMM(R0
, 1),
3346 "ALU64_DIV_K: 6 / 2 = 3",
3348 BPF_LD_IMM64(R0
, 6),
3349 BPF_ALU64_IMM(BPF_DIV
, R0
, 2),
3357 "ALU64_DIV_K: 3 / 1 = 3",
3359 BPF_LD_IMM64(R0
, 3),
3360 BPF_ALU64_IMM(BPF_DIV
, R0
, 1),
3368 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3370 BPF_LD_IMM64(R0
, 2147483647),
3371 BPF_ALU64_IMM(BPF_DIV
, R0
, 2147483647),
3379 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3381 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3382 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3383 BPF_ALU64_IMM(BPF_DIV
, R2
, 0xffffffff),
3384 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3385 BPF_MOV32_IMM(R0
, 2),
3387 BPF_MOV32_IMM(R0
, 1),
3394 /* BPF_ALU | BPF_MOD | BPF_X */
3396 "ALU_MOD_X: 3 % 2 = 1",
3398 BPF_LD_IMM64(R0
, 3),
3399 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3400 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3408 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3410 BPF_LD_IMM64(R0
, 4294967295U),
3411 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967293U),
3412 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3420 "ALU64_MOD_X: 3 % 2 = 1",
3422 BPF_LD_IMM64(R0
, 3),
3423 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3424 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3432 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3434 BPF_LD_IMM64(R0
, 2147483647),
3435 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483645),
3436 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3443 /* BPF_ALU | BPF_MOD | BPF_K */
3445 "ALU_MOD_K: 3 % 2 = 1",
3447 BPF_LD_IMM64(R0
, 3),
3448 BPF_ALU32_IMM(BPF_MOD
, R0
, 2),
3456 "ALU_MOD_K: 3 % 1 = 0",
3458 BPF_LD_IMM64(R0
, 3),
3459 BPF_ALU32_IMM(BPF_MOD
, R0
, 1),
3467 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3469 BPF_LD_IMM64(R0
, 4294967295U),
3470 BPF_ALU32_IMM(BPF_MOD
, R0
, 4294967293U),
3478 "ALU64_MOD_K: 3 % 2 = 1",
3480 BPF_LD_IMM64(R0
, 3),
3481 BPF_ALU64_IMM(BPF_MOD
, R0
, 2),
3489 "ALU64_MOD_K: 3 % 1 = 0",
3491 BPF_LD_IMM64(R0
, 3),
3492 BPF_ALU64_IMM(BPF_MOD
, R0
, 1),
3500 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3502 BPF_LD_IMM64(R0
, 2147483647),
3503 BPF_ALU64_IMM(BPF_MOD
, R0
, 2147483645),
3510 /* BPF_ALU | BPF_AND | BPF_X */
3512 "ALU_AND_X: 3 & 2 = 2",
3514 BPF_LD_IMM64(R0
, 3),
3515 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3516 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3524 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3526 BPF_LD_IMM64(R0
, 0xffffffff),
3527 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3528 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3533 { { 0, 0xffffffff } },
3536 "ALU64_AND_X: 3 & 2 = 2",
3538 BPF_LD_IMM64(R0
, 3),
3539 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3540 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3548 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3550 BPF_LD_IMM64(R0
, 0xffffffff),
3551 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3552 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3557 { { 0, 0xffffffff } },
3559 /* BPF_ALU | BPF_AND | BPF_K */
3561 "ALU_AND_K: 3 & 2 = 2",
3563 BPF_LD_IMM64(R0
, 3),
3564 BPF_ALU32_IMM(BPF_AND
, R0
, 2),
3572 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3574 BPF_LD_IMM64(R0
, 0xffffffff),
3575 BPF_ALU32_IMM(BPF_AND
, R0
, 0xffffffff),
3580 { { 0, 0xffffffff } },
3583 "ALU64_AND_K: 3 & 2 = 2",
3585 BPF_LD_IMM64(R0
, 3),
3586 BPF_ALU64_IMM(BPF_AND
, R0
, 2),
3594 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3596 BPF_LD_IMM64(R0
, 0xffffffff),
3597 BPF_ALU64_IMM(BPF_AND
, R0
, 0xffffffff),
3602 { { 0, 0xffffffff } },
3605 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3607 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3608 BPF_LD_IMM64(R3
, 0x0000000000000000LL
),
3609 BPF_ALU64_IMM(BPF_AND
, R2
, 0x0),
3610 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3611 BPF_MOV32_IMM(R0
, 2),
3613 BPF_MOV32_IMM(R0
, 1),
3621 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3623 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3624 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3625 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3626 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3627 BPF_MOV32_IMM(R0
, 2),
3629 BPF_MOV32_IMM(R0
, 1),
3637 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3639 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3640 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3641 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3642 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3643 BPF_MOV32_IMM(R0
, 2),
3645 BPF_MOV32_IMM(R0
, 1),
3652 /* BPF_ALU | BPF_OR | BPF_X */
3654 "ALU_OR_X: 1 | 2 = 3",
3656 BPF_LD_IMM64(R0
, 1),
3657 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3658 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3666 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3668 BPF_LD_IMM64(R0
, 0),
3669 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3670 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3675 { { 0, 0xffffffff } },
3678 "ALU64_OR_X: 1 | 2 = 3",
3680 BPF_LD_IMM64(R0
, 1),
3681 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3682 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3690 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3692 BPF_LD_IMM64(R0
, 0),
3693 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3694 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3699 { { 0, 0xffffffff } },
3701 /* BPF_ALU | BPF_OR | BPF_K */
3703 "ALU_OR_K: 1 | 2 = 3",
3705 BPF_LD_IMM64(R0
, 1),
3706 BPF_ALU32_IMM(BPF_OR
, R0
, 2),
3714 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3716 BPF_LD_IMM64(R0
, 0),
3717 BPF_ALU32_IMM(BPF_OR
, R0
, 0xffffffff),
3722 { { 0, 0xffffffff } },
3725 "ALU64_OR_K: 1 | 2 = 3",
3727 BPF_LD_IMM64(R0
, 1),
3728 BPF_ALU64_IMM(BPF_OR
, R0
, 2),
3736 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3738 BPF_LD_IMM64(R0
, 0),
3739 BPF_ALU64_IMM(BPF_OR
, R0
, 0xffffffff),
3744 { { 0, 0xffffffff } },
3747 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3749 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3750 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3751 BPF_ALU64_IMM(BPF_OR
, R2
, 0x0),
3752 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3753 BPF_MOV32_IMM(R0
, 2),
3755 BPF_MOV32_IMM(R0
, 1),
3763 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3765 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3766 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3767 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3768 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3769 BPF_MOV32_IMM(R0
, 2),
3771 BPF_MOV32_IMM(R0
, 1),
3779 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3781 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3782 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3783 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3784 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3785 BPF_MOV32_IMM(R0
, 2),
3787 BPF_MOV32_IMM(R0
, 1),
3794 /* BPF_ALU | BPF_XOR | BPF_X */
3796 "ALU_XOR_X: 5 ^ 6 = 3",
3798 BPF_LD_IMM64(R0
, 5),
3799 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3800 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3808 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3810 BPF_LD_IMM64(R0
, 1),
3811 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3812 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3817 { { 0, 0xfffffffe } },
3820 "ALU64_XOR_X: 5 ^ 6 = 3",
3822 BPF_LD_IMM64(R0
, 5),
3823 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3824 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3832 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3834 BPF_LD_IMM64(R0
, 1),
3835 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3836 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3841 { { 0, 0xfffffffe } },
3843 /* BPF_ALU | BPF_XOR | BPF_K */
3845 "ALU_XOR_K: 5 ^ 6 = 3",
3847 BPF_LD_IMM64(R0
, 5),
3848 BPF_ALU32_IMM(BPF_XOR
, R0
, 6),
3856 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3858 BPF_LD_IMM64(R0
, 1),
3859 BPF_ALU32_IMM(BPF_XOR
, R0
, 0xffffffff),
3864 { { 0, 0xfffffffe } },
3867 "ALU64_XOR_K: 5 ^ 6 = 3",
3869 BPF_LD_IMM64(R0
, 5),
3870 BPF_ALU64_IMM(BPF_XOR
, R0
, 6),
3878 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3880 BPF_LD_IMM64(R0
, 1),
3881 BPF_ALU64_IMM(BPF_XOR
, R0
, 0xffffffff),
3886 { { 0, 0xfffffffe } },
3889 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3891 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3892 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3893 BPF_ALU64_IMM(BPF_XOR
, R2
, 0x0),
3894 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3895 BPF_MOV32_IMM(R0
, 2),
3897 BPF_MOV32_IMM(R0
, 1),
3905 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3907 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3908 BPF_LD_IMM64(R3
, 0xffff00000000ffffLL
),
3909 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3910 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3911 BPF_MOV32_IMM(R0
, 2),
3913 BPF_MOV32_IMM(R0
, 1),
3921 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3923 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3924 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3925 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3926 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3927 BPF_MOV32_IMM(R0
, 2),
3929 BPF_MOV32_IMM(R0
, 1),
3936 /* BPF_ALU | BPF_LSH | BPF_X */
3938 "ALU_LSH_X: 1 << 1 = 2",
3940 BPF_LD_IMM64(R0
, 1),
3941 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3942 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3950 "ALU_LSH_X: 1 << 31 = 0x80000000",
3952 BPF_LD_IMM64(R0
, 1),
3953 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3954 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3959 { { 0, 0x80000000 } },
3962 "ALU64_LSH_X: 1 << 1 = 2",
3964 BPF_LD_IMM64(R0
, 1),
3965 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3966 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3974 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3976 BPF_LD_IMM64(R0
, 1),
3977 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3978 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3983 { { 0, 0x80000000 } },
3985 /* BPF_ALU | BPF_LSH | BPF_K */
3987 "ALU_LSH_K: 1 << 1 = 2",
3989 BPF_LD_IMM64(R0
, 1),
3990 BPF_ALU32_IMM(BPF_LSH
, R0
, 1),
3998 "ALU_LSH_K: 1 << 31 = 0x80000000",
4000 BPF_LD_IMM64(R0
, 1),
4001 BPF_ALU32_IMM(BPF_LSH
, R0
, 31),
4006 { { 0, 0x80000000 } },
4009 "ALU64_LSH_K: 1 << 1 = 2",
4011 BPF_LD_IMM64(R0
, 1),
4012 BPF_ALU64_IMM(BPF_LSH
, R0
, 1),
4020 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4022 BPF_LD_IMM64(R0
, 1),
4023 BPF_ALU64_IMM(BPF_LSH
, R0
, 31),
4028 { { 0, 0x80000000 } },
4030 /* BPF_ALU | BPF_RSH | BPF_X */
4032 "ALU_RSH_X: 2 >> 1 = 1",
4034 BPF_LD_IMM64(R0
, 2),
4035 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4036 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4044 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4046 BPF_LD_IMM64(R0
, 0x80000000),
4047 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4048 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4056 "ALU64_RSH_X: 2 >> 1 = 1",
4058 BPF_LD_IMM64(R0
, 2),
4059 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4060 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4068 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4070 BPF_LD_IMM64(R0
, 0x80000000),
4071 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4072 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4079 /* BPF_ALU | BPF_RSH | BPF_K */
4081 "ALU_RSH_K: 2 >> 1 = 1",
4083 BPF_LD_IMM64(R0
, 2),
4084 BPF_ALU32_IMM(BPF_RSH
, R0
, 1),
4092 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4094 BPF_LD_IMM64(R0
, 0x80000000),
4095 BPF_ALU32_IMM(BPF_RSH
, R0
, 31),
4103 "ALU64_RSH_K: 2 >> 1 = 1",
4105 BPF_LD_IMM64(R0
, 2),
4106 BPF_ALU64_IMM(BPF_RSH
, R0
, 1),
4114 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4116 BPF_LD_IMM64(R0
, 0x80000000),
4117 BPF_ALU64_IMM(BPF_RSH
, R0
, 31),
4124 /* BPF_ALU | BPF_ARSH | BPF_X */
4126 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4128 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4129 BPF_ALU32_IMM(BPF_MOV
, R1
, 40),
4130 BPF_ALU64_REG(BPF_ARSH
, R0
, R1
),
4135 { { 0, 0xffff00ff } },
4137 /* BPF_ALU | BPF_ARSH | BPF_K */
4139 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4141 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4142 BPF_ALU64_IMM(BPF_ARSH
, R0
, 40),
4147 { { 0, 0xffff00ff } },
4149 /* BPF_ALU | BPF_NEG */
4151 "ALU_NEG: -(3) = -3",
4153 BPF_ALU32_IMM(BPF_MOV
, R0
, 3),
4154 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4162 "ALU_NEG: -(-3) = 3",
4164 BPF_ALU32_IMM(BPF_MOV
, R0
, -3),
4165 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4173 "ALU64_NEG: -(3) = -3",
4175 BPF_LD_IMM64(R0
, 3),
4176 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4184 "ALU64_NEG: -(-3) = 3",
4186 BPF_LD_IMM64(R0
, -3),
4187 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4194 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4196 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4198 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4199 BPF_ENDIAN(BPF_FROM_BE
, R0
, 16),
4204 { { 0, cpu_to_be16(0xcdef) } },
4207 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4209 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4210 BPF_ENDIAN(BPF_FROM_BE
, R0
, 32),
4211 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4212 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4213 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4218 { { 0, cpu_to_be32(0x89abcdef) } },
4221 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4223 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4224 BPF_ENDIAN(BPF_FROM_BE
, R0
, 64),
4229 { { 0, (u32
) cpu_to_be64(0x0123456789abcdefLL
) } },
4231 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4233 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4235 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4236 BPF_ENDIAN(BPF_FROM_LE
, R0
, 16),
4241 { { 0, cpu_to_le16(0xcdef) } },
4244 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4246 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4247 BPF_ENDIAN(BPF_FROM_LE
, R0
, 32),
4248 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4249 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4250 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4255 { { 0, cpu_to_le32(0x89abcdef) } },
4258 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4260 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4261 BPF_ENDIAN(BPF_FROM_LE
, R0
, 64),
4266 { { 0, (u32
) cpu_to_le64(0x0123456789abcdefLL
) } },
4268 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4270 "ST_MEM_B: Store/Load byte: max negative",
4272 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4273 BPF_ST_MEM(BPF_B
, R10
, -40, 0xff),
4274 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4283 "ST_MEM_B: Store/Load byte: max positive",
4285 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4286 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7f),
4287 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4296 "STX_MEM_B: Store/Load byte: max negative",
4298 BPF_LD_IMM64(R0
, 0),
4299 BPF_LD_IMM64(R1
, 0xffLL
),
4300 BPF_STX_MEM(BPF_B
, R10
, R1
, -40),
4301 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4310 "ST_MEM_H: Store/Load half word: max negative",
4312 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4313 BPF_ST_MEM(BPF_H
, R10
, -40, 0xffff),
4314 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4323 "ST_MEM_H: Store/Load half word: max positive",
4325 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4326 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7fff),
4327 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4336 "STX_MEM_H: Store/Load half word: max negative",
4338 BPF_LD_IMM64(R0
, 0),
4339 BPF_LD_IMM64(R1
, 0xffffLL
),
4340 BPF_STX_MEM(BPF_H
, R10
, R1
, -40),
4341 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4350 "ST_MEM_W: Store/Load word: max negative",
4352 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4353 BPF_ST_MEM(BPF_W
, R10
, -40, 0xffffffff),
4354 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4359 { { 0, 0xffffffff } },
4363 "ST_MEM_W: Store/Load word: max positive",
4365 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4366 BPF_ST_MEM(BPF_W
, R10
, -40, 0x7fffffff),
4367 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4372 { { 0, 0x7fffffff } },
4376 "STX_MEM_W: Store/Load word: max negative",
4378 BPF_LD_IMM64(R0
, 0),
4379 BPF_LD_IMM64(R1
, 0xffffffffLL
),
4380 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4381 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4386 { { 0, 0xffffffff } },
4390 "ST_MEM_DW: Store/Load double word: max negative",
4392 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4393 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4394 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4399 { { 0, 0xffffffff } },
4403 "ST_MEM_DW: Store/Load double word: max negative 2",
4405 BPF_LD_IMM64(R2
, 0xffff00000000ffffLL
),
4406 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
4407 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4408 BPF_LDX_MEM(BPF_DW
, R2
, R10
, -40),
4409 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
4410 BPF_MOV32_IMM(R0
, 2),
4412 BPF_MOV32_IMM(R0
, 1),
4421 "ST_MEM_DW: Store/Load double word: max positive",
4423 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4424 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x7fffffff),
4425 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4430 { { 0, 0x7fffffff } },
4434 "STX_MEM_DW: Store/Load double word: max negative",
4436 BPF_LD_IMM64(R0
, 0),
4437 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4438 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4439 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4444 { { 0, 0xffffffff } },
4447 /* BPF_STX | BPF_XADD | BPF_W/DW */
4449 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4451 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4452 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4453 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4454 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4463 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4465 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4466 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4467 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4468 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4469 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4470 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4479 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4481 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4482 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4483 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4492 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4497 .fill_helper
= bpf_fill_stxw
,
4500 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4502 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4503 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4504 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4505 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4514 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4516 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4517 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4518 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4519 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4520 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4521 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4530 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4532 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4533 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4534 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4543 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4548 .fill_helper
= bpf_fill_stxdw
,
4550 /* BPF_JMP | BPF_EXIT */
4554 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4711),
4556 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4712),
4562 /* BPF_JMP | BPF_JA */
4564 "JMP_JA: Unconditional jump: if (true) return 1",
4566 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4567 BPF_JMP_IMM(BPF_JA
, 0, 0, 1),
4569 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4576 /* BPF_JMP | BPF_JSLT | BPF_K */
4578 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4580 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4581 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4582 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4584 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4592 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4594 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4595 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4596 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4598 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4605 /* BPF_JMP | BPF_JSGT | BPF_K */
4607 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4609 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4610 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4611 BPF_JMP_IMM(BPF_JSGT
, R1
, -2, 1),
4613 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4621 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4623 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4624 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4625 BPF_JMP_IMM(BPF_JSGT
, R1
, -1, 1),
4627 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4634 /* BPF_JMP | BPF_JSLE | BPF_K */
4636 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4638 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4639 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4640 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4642 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4650 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4652 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4653 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4654 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4656 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4664 "JMP_JSLE_K: Signed jump: value walk 1",
4666 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4667 BPF_LD_IMM64(R1
, 3),
4668 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 6),
4669 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4670 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4671 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4672 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4673 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4674 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4675 BPF_EXIT_INSN(), /* bad exit */
4676 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4684 "JMP_JSLE_K: Signed jump: value walk 2",
4686 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4687 BPF_LD_IMM64(R1
, 3),
4688 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4689 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4690 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4691 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4692 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4693 BPF_EXIT_INSN(), /* bad exit */
4694 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4701 /* BPF_JMP | BPF_JSGE | BPF_K */
4703 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4705 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4706 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4707 BPF_JMP_IMM(BPF_JSGE
, R1
, -2, 1),
4709 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4717 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4719 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4720 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4721 BPF_JMP_IMM(BPF_JSGE
, R1
, -1, 1),
4723 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4731 "JMP_JSGE_K: Signed jump: value walk 1",
4733 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4734 BPF_LD_IMM64(R1
, -3),
4735 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 6),
4736 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4737 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4738 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4739 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4740 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4741 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4742 BPF_EXIT_INSN(), /* bad exit */
4743 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4751 "JMP_JSGE_K: Signed jump: value walk 2",
4753 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4754 BPF_LD_IMM64(R1
, -3),
4755 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4756 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4757 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4758 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4759 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4760 BPF_EXIT_INSN(), /* bad exit */
4761 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4768 /* BPF_JMP | BPF_JGT | BPF_K */
4770 "JMP_JGT_K: if (3 > 2) return 1",
4772 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4773 BPF_LD_IMM64(R1
, 3),
4774 BPF_JMP_IMM(BPF_JGT
, R1
, 2, 1),
4776 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4784 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4786 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4787 BPF_LD_IMM64(R1
, -1),
4788 BPF_JMP_IMM(BPF_JGT
, R1
, 1, 1),
4790 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4797 /* BPF_JMP | BPF_JLT | BPF_K */
4799 "JMP_JLT_K: if (2 < 3) return 1",
4801 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4802 BPF_LD_IMM64(R1
, 2),
4803 BPF_JMP_IMM(BPF_JLT
, R1
, 3, 1),
4805 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4813 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4815 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4816 BPF_LD_IMM64(R1
, 1),
4817 BPF_JMP_IMM(BPF_JLT
, R1
, -1, 1),
4819 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4826 /* BPF_JMP | BPF_JGE | BPF_K */
4828 "JMP_JGE_K: if (3 >= 2) return 1",
4830 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4831 BPF_LD_IMM64(R1
, 3),
4832 BPF_JMP_IMM(BPF_JGE
, R1
, 2, 1),
4834 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4841 /* BPF_JMP | BPF_JLE | BPF_K */
4843 "JMP_JLE_K: if (2 <= 3) return 1",
4845 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4846 BPF_LD_IMM64(R1
, 2),
4847 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4849 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4856 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4858 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4860 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4861 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4863 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4864 BPF_LD_IMM64(R1
, 3), /* note: this takes 2 insns */
4865 BPF_JMP_IMM(BPF_JGT
, R1
, 2, -6), /* goto out */
4873 "JMP_JGE_K: if (3 >= 3) return 1",
4875 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4876 BPF_LD_IMM64(R1
, 3),
4877 BPF_JMP_IMM(BPF_JGE
, R1
, 3, 1),
4879 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4886 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4888 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4890 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4891 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4893 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4894 BPF_LD_IMM64(R1
, 2), /* note: this takes 2 insns */
4895 BPF_JMP_IMM(BPF_JLT
, R1
, 3, -6), /* goto out */
4903 "JMP_JLE_K: if (3 <= 3) return 1",
4905 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4906 BPF_LD_IMM64(R1
, 3),
4907 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4909 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4916 /* BPF_JMP | BPF_JNE | BPF_K */
4918 "JMP_JNE_K: if (3 != 2) return 1",
4920 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4921 BPF_LD_IMM64(R1
, 3),
4922 BPF_JMP_IMM(BPF_JNE
, R1
, 2, 1),
4924 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4931 /* BPF_JMP | BPF_JEQ | BPF_K */
4933 "JMP_JEQ_K: if (3 == 3) return 1",
4935 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4936 BPF_LD_IMM64(R1
, 3),
4937 BPF_JMP_IMM(BPF_JEQ
, R1
, 3, 1),
4939 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4946 /* BPF_JMP | BPF_JSET | BPF_K */
4948 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4950 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4951 BPF_LD_IMM64(R1
, 3),
4952 BPF_JMP_IMM(BPF_JSET
, R1
, 2, 1),
4954 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4962 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4964 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4965 BPF_LD_IMM64(R1
, 3),
4966 BPF_JMP_IMM(BPF_JSET
, R1
, 0xffffffff, 1),
4968 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4975 /* BPF_JMP | BPF_JSGT | BPF_X */
4977 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4979 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4980 BPF_LD_IMM64(R1
, -1),
4981 BPF_LD_IMM64(R2
, -2),
4982 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4984 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4992 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4994 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4995 BPF_LD_IMM64(R1
, -1),
4996 BPF_LD_IMM64(R2
, -1),
4997 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4999 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5006 /* BPF_JMP | BPF_JSLT | BPF_X */
5008 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
5010 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5011 BPF_LD_IMM64(R1
, -1),
5012 BPF_LD_IMM64(R2
, -2),
5013 BPF_JMP_REG(BPF_JSLT
, R2
, R1
, 1),
5015 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5023 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
5025 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5026 BPF_LD_IMM64(R1
, -1),
5027 BPF_LD_IMM64(R2
, -1),
5028 BPF_JMP_REG(BPF_JSLT
, R1
, R2
, 1),
5030 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5037 /* BPF_JMP | BPF_JSGE | BPF_X */
5039 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5041 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5042 BPF_LD_IMM64(R1
, -1),
5043 BPF_LD_IMM64(R2
, -2),
5044 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5046 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5054 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5056 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5057 BPF_LD_IMM64(R1
, -1),
5058 BPF_LD_IMM64(R2
, -1),
5059 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5061 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5068 /* BPF_JMP | BPF_JSLE | BPF_X */
5070 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5072 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5073 BPF_LD_IMM64(R1
, -1),
5074 BPF_LD_IMM64(R2
, -2),
5075 BPF_JMP_REG(BPF_JSLE
, R2
, R1
, 1),
5077 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5085 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5087 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5088 BPF_LD_IMM64(R1
, -1),
5089 BPF_LD_IMM64(R2
, -1),
5090 BPF_JMP_REG(BPF_JSLE
, R1
, R2
, 1),
5092 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5099 /* BPF_JMP | BPF_JGT | BPF_X */
5101 "JMP_JGT_X: if (3 > 2) return 1",
5103 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5104 BPF_LD_IMM64(R1
, 3),
5105 BPF_LD_IMM64(R2
, 2),
5106 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5108 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5116 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5118 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5119 BPF_LD_IMM64(R1
, -1),
5120 BPF_LD_IMM64(R2
, 1),
5121 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5123 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5130 /* BPF_JMP | BPF_JLT | BPF_X */
5132 "JMP_JLT_X: if (2 < 3) return 1",
5134 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5135 BPF_LD_IMM64(R1
, 3),
5136 BPF_LD_IMM64(R2
, 2),
5137 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5139 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5147 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5149 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5150 BPF_LD_IMM64(R1
, -1),
5151 BPF_LD_IMM64(R2
, 1),
5152 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5154 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5161 /* BPF_JMP | BPF_JGE | BPF_X */
5163 "JMP_JGE_X: if (3 >= 2) return 1",
5165 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5166 BPF_LD_IMM64(R1
, 3),
5167 BPF_LD_IMM64(R2
, 2),
5168 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5170 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5178 "JMP_JGE_X: if (3 >= 3) return 1",
5180 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5181 BPF_LD_IMM64(R1
, 3),
5182 BPF_LD_IMM64(R2
, 3),
5183 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5185 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5192 /* BPF_JMP | BPF_JLE | BPF_X */
5194 "JMP_JLE_X: if (2 <= 3) return 1",
5196 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5197 BPF_LD_IMM64(R1
, 3),
5198 BPF_LD_IMM64(R2
, 2),
5199 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 1),
5201 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5209 "JMP_JLE_X: if (3 <= 3) return 1",
5211 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5212 BPF_LD_IMM64(R1
, 3),
5213 BPF_LD_IMM64(R2
, 3),
5214 BPF_JMP_REG(BPF_JLE
, R1
, R2
, 1),
5216 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5224 /* Mainly testing JIT + imm64 here. */
5225 "JMP_JGE_X: ldimm64 test 1",
5227 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5228 BPF_LD_IMM64(R1
, 3),
5229 BPF_LD_IMM64(R2
, 2),
5230 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 2),
5231 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5232 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5237 { { 0, 0xeeeeeeeeU
} },
5240 "JMP_JGE_X: ldimm64 test 2",
5242 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5243 BPF_LD_IMM64(R1
, 3),
5244 BPF_LD_IMM64(R2
, 2),
5245 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 0),
5246 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5251 { { 0, 0xffffffffU
} },
5254 "JMP_JGE_X: ldimm64 test 3",
5256 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5257 BPF_LD_IMM64(R1
, 3),
5258 BPF_LD_IMM64(R2
, 2),
5259 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 4),
5260 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5261 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5269 "JMP_JLE_X: ldimm64 test 1",
5271 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5272 BPF_LD_IMM64(R1
, 3),
5273 BPF_LD_IMM64(R2
, 2),
5274 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 2),
5275 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5276 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5281 { { 0, 0xeeeeeeeeU
} },
5284 "JMP_JLE_X: ldimm64 test 2",
5286 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5287 BPF_LD_IMM64(R1
, 3),
5288 BPF_LD_IMM64(R2
, 2),
5289 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 0),
5290 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5295 { { 0, 0xffffffffU
} },
5298 "JMP_JLE_X: ldimm64 test 3",
5300 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5301 BPF_LD_IMM64(R1
, 3),
5302 BPF_LD_IMM64(R2
, 2),
5303 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 4),
5304 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5305 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5312 /* BPF_JMP | BPF_JNE | BPF_X */
5314 "JMP_JNE_X: if (3 != 2) return 1",
5316 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5317 BPF_LD_IMM64(R1
, 3),
5318 BPF_LD_IMM64(R2
, 2),
5319 BPF_JMP_REG(BPF_JNE
, R1
, R2
, 1),
5321 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5328 /* BPF_JMP | BPF_JEQ | BPF_X */
5330 "JMP_JEQ_X: if (3 == 3) return 1",
5332 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5333 BPF_LD_IMM64(R1
, 3),
5334 BPF_LD_IMM64(R2
, 3),
5335 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
5337 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5344 /* BPF_JMP | BPF_JSET | BPF_X */
5346 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5348 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5349 BPF_LD_IMM64(R1
, 3),
5350 BPF_LD_IMM64(R2
, 2),
5351 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5353 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5361 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5363 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5364 BPF_LD_IMM64(R1
, 3),
5365 BPF_LD_IMM64(R2
, 0xffffffff),
5366 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5368 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5376 "JMP_JA: Jump, gap, jump, ...",
5378 CLASSIC
| FLAG_NO_DATA
,
5380 { { 0, 0xababcbac } },
5381 .fill_helper
= bpf_fill_ja
,
5383 { /* Mainly checking JIT here. */
5384 "BPF_MAXINSNS: Maximum possible literals",
5386 CLASSIC
| FLAG_NO_DATA
,
5388 { { 0, 0xffffffff } },
5389 .fill_helper
= bpf_fill_maxinsns1
,
5391 { /* Mainly checking JIT here. */
5392 "BPF_MAXINSNS: Single literal",
5394 CLASSIC
| FLAG_NO_DATA
,
5396 { { 0, 0xfefefefe } },
5397 .fill_helper
= bpf_fill_maxinsns2
,
5399 { /* Mainly checking JIT here. */
5400 "BPF_MAXINSNS: Run/add until end",
5402 CLASSIC
| FLAG_NO_DATA
,
5404 { { 0, 0x947bf368 } },
5405 .fill_helper
= bpf_fill_maxinsns3
,
5408 "BPF_MAXINSNS: Too many instructions",
5410 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5413 .fill_helper
= bpf_fill_maxinsns4
,
5414 .expected_errcode
= -EINVAL
,
5416 { /* Mainly checking JIT here. */
5417 "BPF_MAXINSNS: Very long jump",
5419 CLASSIC
| FLAG_NO_DATA
,
5421 { { 0, 0xabababab } },
5422 .fill_helper
= bpf_fill_maxinsns5
,
5424 { /* Mainly checking JIT here. */
5425 "BPF_MAXINSNS: Ctx heavy transformations",
5430 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
5431 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
5433 .fill_helper
= bpf_fill_maxinsns6
,
5435 { /* Mainly checking JIT here. */
5436 "BPF_MAXINSNS: Call heavy transformations",
5438 CLASSIC
| FLAG_NO_DATA
,
5440 { { 1, 0 }, { 10, 0 } },
5441 .fill_helper
= bpf_fill_maxinsns7
,
5443 { /* Mainly checking JIT here. */
5444 "BPF_MAXINSNS: Jump heavy test",
5446 CLASSIC
| FLAG_NO_DATA
,
5448 { { 0, 0xffffffff } },
5449 .fill_helper
= bpf_fill_maxinsns8
,
5451 { /* Mainly checking JIT here. */
5452 "BPF_MAXINSNS: Very long jump backwards",
5454 INTERNAL
| FLAG_NO_DATA
,
5456 { { 0, 0xcbababab } },
5457 .fill_helper
= bpf_fill_maxinsns9
,
5459 { /* Mainly checking JIT here. */
5460 "BPF_MAXINSNS: Edge hopping nuthouse",
5462 INTERNAL
| FLAG_NO_DATA
,
5464 { { 0, 0xabababac } },
5465 .fill_helper
= bpf_fill_maxinsns10
,
5468 "BPF_MAXINSNS: Jump, gap, jump, ...",
5470 #ifdef CONFIG_BPF_JIT_ALWAYS_ON
5471 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5473 CLASSIC
| FLAG_NO_DATA
,
5476 { { 0, 0xababcbac } },
5477 .fill_helper
= bpf_fill_maxinsns11
,
5478 .expected_errcode
= -ENOTSUPP
,
5481 "BPF_MAXINSNS: ld_abs+get_processor_id",
5486 .fill_helper
= bpf_fill_ld_abs_get_processor_id
,
5489 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5493 { { ETH_HLEN
, 0xbef } },
5494 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop
,
5497 "BPF_MAXINSNS: jump around ld_abs",
5502 .fill_helper
= bpf_fill_jump_around_ld_abs
,
5505 * LD_IND / LD_ABS on fragmented SKBs
5510 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5511 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x0),
5512 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5514 CLASSIC
| FLAG_SKB_FRAG
,
5518 0x42, 0x00, 0x00, 0x00,
5519 0x43, 0x44, 0x00, 0x00,
5520 0x21, 0x07, 0x19, 0x83,
5524 "LD_IND halfword frag",
5526 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5527 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x4),
5528 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5530 CLASSIC
| FLAG_SKB_FRAG
,
5534 0x42, 0x00, 0x00, 0x00,
5535 0x43, 0x44, 0x00, 0x00,
5536 0x21, 0x07, 0x19, 0x83,
5542 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5543 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x8),
5544 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5546 CLASSIC
| FLAG_SKB_FRAG
,
5548 { {0x40, 0x21071983} },
5550 0x42, 0x00, 0x00, 0x00,
5551 0x43, 0x44, 0x00, 0x00,
5552 0x21, 0x07, 0x19, 0x83,
5556 "LD_IND halfword mixed head/frag",
5558 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5559 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5560 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5562 CLASSIC
| FLAG_SKB_FRAG
,
5563 { [0x3e] = 0x25, [0x3f] = 0x05, },
5565 .frag_data
= { 0x19, 0x82 },
5568 "LD_IND word mixed head/frag",
5570 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5571 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5572 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5574 CLASSIC
| FLAG_SKB_FRAG
,
5575 { [0x3e] = 0x25, [0x3f] = 0x05, },
5576 { {0x40, 0x25051982} },
5577 .frag_data
= { 0x19, 0x82 },
5582 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x40),
5583 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5585 CLASSIC
| FLAG_SKB_FRAG
,
5589 0x42, 0x00, 0x00, 0x00,
5590 0x43, 0x44, 0x00, 0x00,
5591 0x21, 0x07, 0x19, 0x83,
5595 "LD_ABS halfword frag",
5597 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x44),
5598 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5600 CLASSIC
| FLAG_SKB_FRAG
,
5604 0x42, 0x00, 0x00, 0x00,
5605 0x43, 0x44, 0x00, 0x00,
5606 0x21, 0x07, 0x19, 0x83,
5612 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x48),
5613 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5615 CLASSIC
| FLAG_SKB_FRAG
,
5617 { {0x40, 0x21071983} },
5619 0x42, 0x00, 0x00, 0x00,
5620 0x43, 0x44, 0x00, 0x00,
5621 0x21, 0x07, 0x19, 0x83,
5625 "LD_ABS halfword mixed head/frag",
5627 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3f),
5628 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5630 CLASSIC
| FLAG_SKB_FRAG
,
5631 { [0x3e] = 0x25, [0x3f] = 0x05, },
5633 .frag_data
= { 0x19, 0x82 },
5636 "LD_ABS word mixed head/frag",
5638 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3e),
5639 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5641 CLASSIC
| FLAG_SKB_FRAG
,
5642 { [0x3e] = 0x25, [0x3f] = 0x05, },
5643 { {0x40, 0x25051982} },
5644 .frag_data
= { 0x19, 0x82 },
5647 * LD_IND / LD_ABS on non fragmented SKBs
5651 * this tests that the JIT/interpreter correctly resets X
5652 * before using it in an LD_IND instruction.
5654 "LD_IND byte default X",
5656 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5657 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5664 "LD_IND byte positive offset",
5666 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5667 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5668 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5671 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5675 "LD_IND byte negative offset",
5677 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5678 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, -0x1),
5679 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5682 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5686 "LD_IND halfword positive offset",
5688 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5689 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x2),
5690 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5694 [0x1c] = 0xaa, [0x1d] = 0x55,
5695 [0x1e] = 0xbb, [0x1f] = 0x66,
5696 [0x20] = 0xcc, [0x21] = 0x77,
5697 [0x22] = 0xdd, [0x23] = 0x88,
5699 { {0x40, 0xdd88 } },
5702 "LD_IND halfword negative offset",
5704 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5705 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x2),
5706 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5710 [0x1c] = 0xaa, [0x1d] = 0x55,
5711 [0x1e] = 0xbb, [0x1f] = 0x66,
5712 [0x20] = 0xcc, [0x21] = 0x77,
5713 [0x22] = 0xdd, [0x23] = 0x88,
5715 { {0x40, 0xbb66 } },
5718 "LD_IND halfword unaligned",
5720 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5721 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5722 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5726 [0x1c] = 0xaa, [0x1d] = 0x55,
5727 [0x1e] = 0xbb, [0x1f] = 0x66,
5728 [0x20] = 0xcc, [0x21] = 0x77,
5729 [0x22] = 0xdd, [0x23] = 0x88,
5731 { {0x40, 0x66cc } },
5734 "LD_IND word positive offset",
5736 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5737 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x4),
5738 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5742 [0x1c] = 0xaa, [0x1d] = 0x55,
5743 [0x1e] = 0xbb, [0x1f] = 0x66,
5744 [0x20] = 0xcc, [0x21] = 0x77,
5745 [0x22] = 0xdd, [0x23] = 0x88,
5746 [0x24] = 0xee, [0x25] = 0x99,
5747 [0x26] = 0xff, [0x27] = 0xaa,
5749 { {0x40, 0xee99ffaa } },
5752 "LD_IND word negative offset",
5754 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5755 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x4),
5756 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5760 [0x1c] = 0xaa, [0x1d] = 0x55,
5761 [0x1e] = 0xbb, [0x1f] = 0x66,
5762 [0x20] = 0xcc, [0x21] = 0x77,
5763 [0x22] = 0xdd, [0x23] = 0x88,
5764 [0x24] = 0xee, [0x25] = 0x99,
5765 [0x26] = 0xff, [0x27] = 0xaa,
5767 { {0x40, 0xaa55bb66 } },
5770 "LD_IND word unaligned (addr & 3 == 2)",
5772 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5773 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5774 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5778 [0x1c] = 0xaa, [0x1d] = 0x55,
5779 [0x1e] = 0xbb, [0x1f] = 0x66,
5780 [0x20] = 0xcc, [0x21] = 0x77,
5781 [0x22] = 0xdd, [0x23] = 0x88,
5782 [0x24] = 0xee, [0x25] = 0x99,
5783 [0x26] = 0xff, [0x27] = 0xaa,
5785 { {0x40, 0xbb66cc77 } },
5788 "LD_IND word unaligned (addr & 3 == 1)",
5790 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5791 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x3),
5792 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5796 [0x1c] = 0xaa, [0x1d] = 0x55,
5797 [0x1e] = 0xbb, [0x1f] = 0x66,
5798 [0x20] = 0xcc, [0x21] = 0x77,
5799 [0x22] = 0xdd, [0x23] = 0x88,
5800 [0x24] = 0xee, [0x25] = 0x99,
5801 [0x26] = 0xff, [0x27] = 0xaa,
5803 { {0x40, 0x55bb66cc } },
5806 "LD_IND word unaligned (addr & 3 == 3)",
5808 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5809 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x1),
5810 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5814 [0x1c] = 0xaa, [0x1d] = 0x55,
5815 [0x1e] = 0xbb, [0x1f] = 0x66,
5816 [0x20] = 0xcc, [0x21] = 0x77,
5817 [0x22] = 0xdd, [0x23] = 0x88,
5818 [0x24] = 0xee, [0x25] = 0x99,
5819 [0x26] = 0xff, [0x27] = 0xaa,
5821 { {0x40, 0x66cc77dd } },
5826 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x20),
5827 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5831 [0x1c] = 0xaa, [0x1d] = 0x55,
5832 [0x1e] = 0xbb, [0x1f] = 0x66,
5833 [0x20] = 0xcc, [0x21] = 0x77,
5834 [0x22] = 0xdd, [0x23] = 0x88,
5835 [0x24] = 0xee, [0x25] = 0x99,
5836 [0x26] = 0xff, [0x27] = 0xaa,
5843 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x22),
5844 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5848 [0x1c] = 0xaa, [0x1d] = 0x55,
5849 [0x1e] = 0xbb, [0x1f] = 0x66,
5850 [0x20] = 0xcc, [0x21] = 0x77,
5851 [0x22] = 0xdd, [0x23] = 0x88,
5852 [0x24] = 0xee, [0x25] = 0x99,
5853 [0x26] = 0xff, [0x27] = 0xaa,
5855 { {0x40, 0xdd88 } },
5858 "LD_ABS halfword unaligned",
5860 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x25),
5861 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5865 [0x1c] = 0xaa, [0x1d] = 0x55,
5866 [0x1e] = 0xbb, [0x1f] = 0x66,
5867 [0x20] = 0xcc, [0x21] = 0x77,
5868 [0x22] = 0xdd, [0x23] = 0x88,
5869 [0x24] = 0xee, [0x25] = 0x99,
5870 [0x26] = 0xff, [0x27] = 0xaa,
5872 { {0x40, 0x99ff } },
5877 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x1c),
5878 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5882 [0x1c] = 0xaa, [0x1d] = 0x55,
5883 [0x1e] = 0xbb, [0x1f] = 0x66,
5884 [0x20] = 0xcc, [0x21] = 0x77,
5885 [0x22] = 0xdd, [0x23] = 0x88,
5886 [0x24] = 0xee, [0x25] = 0x99,
5887 [0x26] = 0xff, [0x27] = 0xaa,
5889 { {0x40, 0xaa55bb66 } },
5892 "LD_ABS word unaligned (addr & 3 == 2)",
5894 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x22),
5895 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5899 [0x1c] = 0xaa, [0x1d] = 0x55,
5900 [0x1e] = 0xbb, [0x1f] = 0x66,
5901 [0x20] = 0xcc, [0x21] = 0x77,
5902 [0x22] = 0xdd, [0x23] = 0x88,
5903 [0x24] = 0xee, [0x25] = 0x99,
5904 [0x26] = 0xff, [0x27] = 0xaa,
5906 { {0x40, 0xdd88ee99 } },
5909 "LD_ABS word unaligned (addr & 3 == 1)",
5911 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x21),
5912 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5916 [0x1c] = 0xaa, [0x1d] = 0x55,
5917 [0x1e] = 0xbb, [0x1f] = 0x66,
5918 [0x20] = 0xcc, [0x21] = 0x77,
5919 [0x22] = 0xdd, [0x23] = 0x88,
5920 [0x24] = 0xee, [0x25] = 0x99,
5921 [0x26] = 0xff, [0x27] = 0xaa,
5923 { {0x40, 0x77dd88ee } },
5926 "LD_ABS word unaligned (addr & 3 == 3)",
5928 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x23),
5929 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5933 [0x1c] = 0xaa, [0x1d] = 0x55,
5934 [0x1e] = 0xbb, [0x1f] = 0x66,
5935 [0x20] = 0xcc, [0x21] = 0x77,
5936 [0x22] = 0xdd, [0x23] = 0x88,
5937 [0x24] = 0xee, [0x25] = 0x99,
5938 [0x26] = 0xff, [0x27] = 0xaa,
5940 { {0x40, 0x88ee99ff } },
5943 * verify that the interpreter or JIT correctly sets A and X
5954 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
5955 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
5956 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5958 CLASSIC
| FLAG_NO_DATA
,
5969 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0x42),
5970 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5972 CLASSIC
| FLAG_NO_DATA
,
5984 BPF_STMT(BPF_LD
| BPF_IMM
, 0x66),
5985 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
5986 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5988 CLASSIC
| FLAG_NO_DATA
,
5999 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, -0x66),
6000 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6002 CLASSIC
| FLAG_NO_DATA
,
6014 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6015 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_X
, 0),
6016 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6018 CLASSIC
| FLAG_NO_DATA
,
6029 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 0x66),
6030 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6032 CLASSIC
| FLAG_NO_DATA
,
6041 * A = A / X ; this halt the filter execution if X is 0
6044 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6045 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
6046 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6048 CLASSIC
| FLAG_NO_DATA
,
6059 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x1),
6060 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6062 CLASSIC
| FLAG_NO_DATA
,
6071 * A = A mod X ; this halt the filter execution if X is 0
6074 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6075 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
6076 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6078 CLASSIC
| FLAG_NO_DATA
,
6089 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x1),
6090 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6092 CLASSIC
| FLAG_NO_DATA
,
6104 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0, 0, 1),
6105 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6106 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6108 CLASSIC
| FLAG_NO_DATA
,
6121 BPF_STMT(BPF_LD
| BPF_IMM
, 0x0),
6122 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0x0, 0, 1),
6123 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6124 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6126 CLASSIC
| FLAG_NO_DATA
,
6131 "LD_ABS with helper changing skb data",
6135 { { ETH_HLEN
, 42 } },
6136 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop2
,
6138 /* Checking interpreter vs JIT wrt signed extended imms. */
6140 "JNE signed compare, test 1",
6142 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6143 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6144 BPF_MOV64_REG(R2
, R1
),
6145 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6146 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6147 BPF_JMP_IMM(BPF_JNE
, R2
, -17104896, 1),
6148 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6156 "JNE signed compare, test 2",
6158 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6159 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6160 BPF_MOV64_REG(R2
, R1
),
6161 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6162 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6163 BPF_JMP_IMM(BPF_JNE
, R2
, 0xfefb0000, 1),
6164 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6172 "JNE signed compare, test 3",
6174 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6175 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6176 BPF_ALU32_IMM(BPF_MOV
, R4
, 0xfefb0000),
6177 BPF_MOV64_REG(R2
, R1
),
6178 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6179 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6180 BPF_JMP_REG(BPF_JNE
, R2
, R4
, 1),
6181 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6189 "JNE signed compare, test 4",
6191 BPF_LD_IMM64(R1
, -17104896),
6192 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6193 BPF_JMP_IMM(BPF_JNE
, R1
, -17104896, 1),
6194 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6202 "JNE signed compare, test 5",
6204 BPF_LD_IMM64(R1
, 0xfefb0000),
6205 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6206 BPF_JMP_IMM(BPF_JNE
, R1
, 0xfefb0000, 1),
6207 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6215 "JNE signed compare, test 6",
6217 BPF_LD_IMM64(R1
, 0x7efb0000),
6218 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6219 BPF_JMP_IMM(BPF_JNE
, R1
, 0x7efb0000, 1),
6220 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6228 "JNE signed compare, test 7",
6230 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffff0000),
6231 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6232 BPF_STMT(BPF_LD
| BPF_IMM
, 0xfefbbc12),
6233 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_X
, 0),
6234 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xfefb0000, 1, 0),
6235 BPF_STMT(BPF_RET
| BPF_K
, 1),
6236 BPF_STMT(BPF_RET
| BPF_K
, 2),
6238 CLASSIC
| FLAG_NO_DATA
,
6244 static struct net_device dev
;
6246 static struct sk_buff
*populate_skb(char *buf
, int size
)
6248 struct sk_buff
*skb
;
6250 if (size
>= MAX_DATA
)
6253 skb
= alloc_skb(MAX_DATA
, GFP_KERNEL
);
6257 __skb_put_data(skb
, buf
, size
);
6259 /* Initialize a fake skb with test pattern. */
6260 skb_reset_mac_header(skb
);
6261 skb
->protocol
= htons(ETH_P_IP
);
6262 skb
->pkt_type
= SKB_TYPE
;
6263 skb
->mark
= SKB_MARK
;
6264 skb
->hash
= SKB_HASH
;
6265 skb
->queue_mapping
= SKB_QUEUE_MAP
;
6266 skb
->vlan_tci
= SKB_VLAN_TCI
;
6267 skb
->vlan_proto
= htons(ETH_P_IP
);
6269 skb
->dev
->ifindex
= SKB_DEV_IFINDEX
;
6270 skb
->dev
->type
= SKB_DEV_TYPE
;
6271 skb_set_network_header(skb
, min(size
, ETH_HLEN
));
6276 static void *generate_test_data(struct bpf_test
*test
, int sub
)
6278 struct sk_buff
*skb
;
6281 if (test
->aux
& FLAG_NO_DATA
)
6284 /* Test case expects an skb, so populate one. Various
6285 * subtests generate skbs of different sizes based on
6288 skb
= populate_skb(test
->data
, test
->test
[sub
].data_size
);
6292 if (test
->aux
& FLAG_SKB_FRAG
) {
6294 * when the test requires a fragmented skb, add a
6295 * single fragment to the skb, filled with
6300 page
= alloc_page(GFP_KERNEL
);
6308 memcpy(ptr
, test
->frag_data
, MAX_DATA
);
6310 skb_add_rx_frag(skb
, 0, page
, 0, MAX_DATA
, MAX_DATA
);
6322 static void release_test_data(const struct bpf_test
*test
, void *data
)
6324 if (test
->aux
& FLAG_NO_DATA
)
6330 static int filter_length(int which
)
6332 struct sock_filter
*fp
;
6335 if (tests
[which
].fill_helper
)
6336 return tests
[which
].u
.ptr
.len
;
6338 fp
= tests
[which
].u
.insns
;
6339 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
6340 if (fp
[len
].code
!= 0 || fp
[len
].k
!= 0)
6346 static void *filter_pointer(int which
)
6348 if (tests
[which
].fill_helper
)
6349 return tests
[which
].u
.ptr
.insns
;
6351 return tests
[which
].u
.insns
;
6354 static struct bpf_prog
*generate_filter(int which
, int *err
)
6356 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6357 unsigned int flen
= filter_length(which
);
6358 void *fptr
= filter_pointer(which
);
6359 struct sock_fprog_kern fprog
;
6360 struct bpf_prog
*fp
;
6362 switch (test_type
) {
6364 fprog
.filter
= fptr
;
6367 *err
= bpf_prog_create(&fp
, &fprog
);
6368 if (tests
[which
].aux
& FLAG_EXPECTED_FAIL
) {
6369 if (*err
== tests
[which
].expected_errcode
) {
6371 /* Verifier rejected filter as expected. */
6375 pr_cont("UNEXPECTED_PASS\n");
6376 /* Verifier didn't reject the test that's
6377 * bad enough, just return!
6384 pr_cont("FAIL to prog_create err=%d len=%d\n",
6391 fp
= bpf_prog_alloc(bpf_prog_size(flen
), 0);
6393 pr_cont("UNEXPECTED_FAIL no memory left\n");
6399 /* Type doesn't really matter here as long as it's not unspec. */
6400 fp
->type
= BPF_PROG_TYPE_SOCKET_FILTER
;
6401 memcpy(fp
->insnsi
, fptr
, fp
->len
* sizeof(struct bpf_insn
));
6402 fp
->aux
->stack_depth
= tests
[which
].stack_depth
;
6404 /* We cannot error here as we don't need type compatibility
6407 fp
= bpf_prog_select_runtime(fp
, err
);
6409 pr_cont("FAIL to select_runtime err=%d\n", *err
);
6419 static void release_filter(struct bpf_prog
*fp
, int which
)
6421 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6423 switch (test_type
) {
6425 bpf_prog_destroy(fp
);
6433 static int __run_one(const struct bpf_prog
*fp
, const void *data
,
6434 int runs
, u64
*duration
)
6439 start
= ktime_get_ns();
6441 for (i
= 0; i
< runs
; i
++)
6442 ret
= BPF_PROG_RUN(fp
, data
);
6444 finish
= ktime_get_ns();
6446 *duration
= finish
- start
;
6447 do_div(*duration
, runs
);
6452 static int run_one(const struct bpf_prog
*fp
, struct bpf_test
*test
)
6454 int err_cnt
= 0, i
, runs
= MAX_TESTRUNS
;
6456 for (i
= 0; i
< MAX_SUBTESTS
; i
++) {
6461 if (test
->test
[i
].data_size
== 0 &&
6462 test
->test
[i
].result
== 0)
6465 data
= generate_test_data(test
, i
);
6466 if (!data
&& !(test
->aux
& FLAG_NO_DATA
)) {
6467 pr_cont("data generation failed ");
6471 ret
= __run_one(fp
, data
, runs
, &duration
);
6472 release_test_data(test
, data
);
6474 if (ret
== test
->test
[i
].result
) {
6475 pr_cont("%lld ", duration
);
6477 pr_cont("ret %d != %d ", ret
,
6478 test
->test
[i
].result
);
6486 static char test_name
[64];
6487 module_param_string(test_name
, test_name
, sizeof(test_name
), 0);
6489 static int test_id
= -1;
6490 module_param(test_id
, int, 0);
6492 static int test_range
[2] = { 0, ARRAY_SIZE(tests
) - 1 };
6493 module_param_array(test_range
, int, NULL
, 0);
6495 static __init
int find_test_index(const char *test_name
)
6499 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6500 if (!strcmp(tests
[i
].descr
, test_name
))
6506 static __init
int prepare_bpf_tests(void)
6512 * if a test_id was specified, use test_range to
6513 * cover only that test.
6515 if (test_id
>= ARRAY_SIZE(tests
)) {
6516 pr_err("test_bpf: invalid test_id specified.\n");
6520 test_range
[0] = test_id
;
6521 test_range
[1] = test_id
;
6522 } else if (*test_name
) {
6524 * if a test_name was specified, find it and setup
6525 * test_range to cover only that test.
6527 int idx
= find_test_index(test_name
);
6530 pr_err("test_bpf: no test named '%s' found.\n",
6534 test_range
[0] = idx
;
6535 test_range
[1] = idx
;
6538 * check that the supplied test_range is valid.
6540 if (test_range
[0] >= ARRAY_SIZE(tests
) ||
6541 test_range
[1] >= ARRAY_SIZE(tests
) ||
6542 test_range
[0] < 0 || test_range
[1] < 0) {
6543 pr_err("test_bpf: test_range is out of bound.\n");
6547 if (test_range
[1] < test_range
[0]) {
6548 pr_err("test_bpf: test_range is ending before it starts.\n");
6553 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6554 if (tests
[i
].fill_helper
&&
6555 tests
[i
].fill_helper(&tests
[i
]) < 0)
6562 static __init
void destroy_bpf_tests(void)
6566 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6567 if (tests
[i
].fill_helper
)
6568 kfree(tests
[i
].u
.ptr
.insns
);
6572 static bool exclude_test(int test_id
)
6574 return test_id
< test_range
[0] || test_id
> test_range
[1];
6577 static __init
int test_bpf(void)
6579 int i
, err_cnt
= 0, pass_cnt
= 0;
6580 int jit_cnt
= 0, run_cnt
= 0;
6582 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6583 struct bpf_prog
*fp
;
6587 if (exclude_test(i
))
6590 pr_info("#%d %s ", i
, tests
[i
].descr
);
6592 fp
= generate_filter(i
, &err
);
6602 pr_cont("jited:%u ", fp
->jited
);
6608 err
= run_one(fp
, &tests
[i
]);
6609 release_filter(fp
, i
);
6612 pr_cont("FAIL (%d times)\n", err
);
6620 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6621 pass_cnt
, err_cnt
, jit_cnt
, run_cnt
);
6623 return err_cnt
? -EINVAL
: 0;
6626 static int __init
test_bpf_init(void)
6630 ret
= prepare_bpf_tests();
6636 destroy_bpf_tests();
6640 static void __exit
test_bpf_exit(void)
6644 module_init(test_bpf_init
);
6645 module_exit(test_bpf_exit
);
6647 MODULE_LICENSE("GPL");