2 * Testsuite for BPF interpreter and BPF JIT compiler
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/filter.h>
21 #include <linux/bpf.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_vlan.h>
25 #include <linux/random.h>
26 #include <linux/highmem.h>
28 /* General test specific settings */
29 #define MAX_SUBTESTS 3
30 #define MAX_TESTRUNS 10000
33 #define MAX_K 0xffffFFFF
35 /* Few constants used to init test 'skb' */
37 #define SKB_MARK 0x1234aaaa
38 #define SKB_HASH 0x1234aaab
39 #define SKB_QUEUE_MAP 123
40 #define SKB_VLAN_TCI 0xffff
41 #define SKB_DEV_IFINDEX 577
42 #define SKB_DEV_TYPE 588
44 /* Redefine REGs to make tests less verbose */
55 #define R10 BPF_REG_10
57 /* Flags that can be passed to test cases */
58 #define FLAG_NO_DATA BIT(0)
59 #define FLAG_EXPECTED_FAIL BIT(1)
60 #define FLAG_SKB_FRAG BIT(2)
63 CLASSIC
= BIT(6), /* Old BPF instructions only. */
64 INTERNAL
= BIT(7), /* Extended instruction set. */
67 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
72 struct sock_filter insns
[MAX_INSNS
];
73 struct bpf_insn insns_int
[MAX_INSNS
];
85 int (*fill_helper
)(struct bpf_test
*self
);
86 int expected_errcode
; /* used when FLAG_EXPECTED_FAIL is set in the aux */
87 __u8 frag_data
[MAX_DATA
];
88 int stack_depth
; /* for eBPF only, since tests don't call verifier */
91 /* Large test cases need separate allocation and fill handler. */
93 static int bpf_fill_maxinsns1(struct bpf_test
*self
)
95 unsigned int len
= BPF_MAXINSNS
;
96 struct sock_filter
*insn
;
100 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
104 for (i
= 0; i
< len
; i
++, k
--)
105 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, k
);
107 self
->u
.ptr
.insns
= insn
;
108 self
->u
.ptr
.len
= len
;
113 static int bpf_fill_maxinsns2(struct bpf_test
*self
)
115 unsigned int len
= BPF_MAXINSNS
;
116 struct sock_filter
*insn
;
119 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
123 for (i
= 0; i
< len
; i
++)
124 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
126 self
->u
.ptr
.insns
= insn
;
127 self
->u
.ptr
.len
= len
;
132 static int bpf_fill_maxinsns3(struct bpf_test
*self
)
134 unsigned int len
= BPF_MAXINSNS
;
135 struct sock_filter
*insn
;
136 struct rnd_state rnd
;
139 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
143 prandom_seed_state(&rnd
, 3141592653589793238ULL);
145 for (i
= 0; i
< len
- 1; i
++) {
146 __u32 k
= prandom_u32_state(&rnd
);
148 insn
[i
] = __BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, k
);
151 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
153 self
->u
.ptr
.insns
= insn
;
154 self
->u
.ptr
.len
= len
;
159 static int bpf_fill_maxinsns4(struct bpf_test
*self
)
161 unsigned int len
= BPF_MAXINSNS
+ 1;
162 struct sock_filter
*insn
;
165 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
169 for (i
= 0; i
< len
; i
++)
170 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
172 self
->u
.ptr
.insns
= insn
;
173 self
->u
.ptr
.len
= len
;
178 static int bpf_fill_maxinsns5(struct bpf_test
*self
)
180 unsigned int len
= BPF_MAXINSNS
;
181 struct sock_filter
*insn
;
184 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
188 insn
[0] = __BPF_JUMP(BPF_JMP
| BPF_JA
, len
- 2, 0, 0);
190 for (i
= 1; i
< len
- 1; i
++)
191 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
193 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xabababab);
195 self
->u
.ptr
.insns
= insn
;
196 self
->u
.ptr
.len
= len
;
201 static int bpf_fill_maxinsns6(struct bpf_test
*self
)
203 unsigned int len
= BPF_MAXINSNS
;
204 struct sock_filter
*insn
;
207 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
211 for (i
= 0; i
< len
- 1; i
++)
212 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
213 SKF_AD_VLAN_TAG_PRESENT
);
215 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
217 self
->u
.ptr
.insns
= insn
;
218 self
->u
.ptr
.len
= len
;
223 static int bpf_fill_maxinsns7(struct bpf_test
*self
)
225 unsigned int len
= BPF_MAXINSNS
;
226 struct sock_filter
*insn
;
229 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
233 for (i
= 0; i
< len
- 4; i
++)
234 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
237 insn
[len
- 4] = __BPF_STMT(BPF_MISC
| BPF_TAX
, 0);
238 insn
[len
- 3] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
240 insn
[len
- 2] = __BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0);
241 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
243 self
->u
.ptr
.insns
= insn
;
244 self
->u
.ptr
.len
= len
;
249 static int bpf_fill_maxinsns8(struct bpf_test
*self
)
251 unsigned int len
= BPF_MAXINSNS
;
252 struct sock_filter
*insn
;
253 int i
, jmp_off
= len
- 3;
255 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
259 insn
[0] = __BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff);
261 for (i
= 1; i
< len
- 1; i
++)
262 insn
[i
] = __BPF_JUMP(BPF_JMP
| BPF_JGT
, 0xffffffff, jmp_off
--, 0);
264 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
266 self
->u
.ptr
.insns
= insn
;
267 self
->u
.ptr
.len
= len
;
272 static int bpf_fill_maxinsns9(struct bpf_test
*self
)
274 unsigned int len
= BPF_MAXINSNS
;
275 struct bpf_insn
*insn
;
278 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
282 insn
[0] = BPF_JMP_IMM(BPF_JA
, 0, 0, len
- 2);
283 insn
[1] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xcbababab);
284 insn
[2] = BPF_EXIT_INSN();
286 for (i
= 3; i
< len
- 2; i
++)
287 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xfefefefe);
289 insn
[len
- 2] = BPF_EXIT_INSN();
290 insn
[len
- 1] = BPF_JMP_IMM(BPF_JA
, 0, 0, -(len
- 1));
292 self
->u
.ptr
.insns
= insn
;
293 self
->u
.ptr
.len
= len
;
298 static int bpf_fill_maxinsns10(struct bpf_test
*self
)
300 unsigned int len
= BPF_MAXINSNS
, hlen
= len
- 2;
301 struct bpf_insn
*insn
;
304 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
308 for (i
= 0; i
< hlen
/ 2; i
++)
309 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 2 - 2 * i
);
310 for (i
= hlen
- 1; i
> hlen
/ 2; i
--)
311 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 1 - 2 * i
);
313 insn
[hlen
/ 2] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
/ 2 - 1);
314 insn
[hlen
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xabababac);
315 insn
[hlen
+ 1] = BPF_EXIT_INSN();
317 self
->u
.ptr
.insns
= insn
;
318 self
->u
.ptr
.len
= len
;
323 static int __bpf_fill_ja(struct bpf_test
*self
, unsigned int len
,
326 struct sock_filter
*insn
;
330 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
334 rlen
= (len
% plen
) - 1;
336 for (i
= 0; i
+ plen
< len
; i
+= plen
)
337 for (j
= 0; j
< plen
; j
++)
338 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
,
340 for (j
= 0; j
< rlen
; j
++)
341 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
, rlen
- 1 - j
,
344 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xababcbac);
346 self
->u
.ptr
.insns
= insn
;
347 self
->u
.ptr
.len
= len
;
352 static int bpf_fill_maxinsns11(struct bpf_test
*self
)
354 /* Hits 70 passes on x86_64, so cannot get JITed there. */
355 return __bpf_fill_ja(self
, BPF_MAXINSNS
, 68);
358 static int bpf_fill_ja(struct bpf_test
*self
)
360 /* Hits exactly 11 passes on x86_64 JIT. */
361 return __bpf_fill_ja(self
, 12, 9);
364 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test
*self
)
366 unsigned int len
= BPF_MAXINSNS
;
367 struct sock_filter
*insn
;
370 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
374 for (i
= 0; i
< len
- 1; i
+= 2) {
375 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 0);
376 insn
[i
+ 1] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
377 SKF_AD_OFF
+ SKF_AD_CPU
);
380 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xbee);
382 self
->u
.ptr
.insns
= insn
;
383 self
->u
.ptr
.len
= len
;
389 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
390 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test
*self
)
392 unsigned int len
= BPF_MAXINSNS
;
393 struct bpf_insn
*insn
;
396 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
400 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
402 for (j
= 0; j
< PUSH_CNT
; j
++) {
403 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
404 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
406 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
407 insn
[i
++] = BPF_MOV64_IMM(R2
, 1);
408 insn
[i
++] = BPF_MOV64_IMM(R3
, 2);
409 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
410 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
411 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
415 for (j
= 0; j
< PUSH_CNT
; j
++) {
416 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
417 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
419 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
420 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
421 bpf_skb_vlan_pop_proto
.func
- __bpf_call_base
);
422 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
428 for (; i
< len
- 1; i
++)
429 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xbef);
431 insn
[len
- 1] = BPF_EXIT_INSN();
433 self
->u
.ptr
.insns
= insn
;
434 self
->u
.ptr
.len
= len
;
439 static int bpf_fill_ld_abs_vlan_push_pop2(struct bpf_test
*self
)
441 struct bpf_insn
*insn
;
443 insn
= kmalloc_array(16, sizeof(*insn
), GFP_KERNEL
);
447 /* Due to func address being non-const, we need to
448 * assemble this here.
450 insn
[0] = BPF_MOV64_REG(R6
, R1
);
451 insn
[1] = BPF_LD_ABS(BPF_B
, 0);
452 insn
[2] = BPF_LD_ABS(BPF_H
, 0);
453 insn
[3] = BPF_LD_ABS(BPF_W
, 0);
454 insn
[4] = BPF_MOV64_REG(R7
, R6
);
455 insn
[5] = BPF_MOV64_IMM(R6
, 0);
456 insn
[6] = BPF_MOV64_REG(R1
, R7
);
457 insn
[7] = BPF_MOV64_IMM(R2
, 1);
458 insn
[8] = BPF_MOV64_IMM(R3
, 2);
459 insn
[9] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
460 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
461 insn
[10] = BPF_MOV64_REG(R6
, R7
);
462 insn
[11] = BPF_LD_ABS(BPF_B
, 0);
463 insn
[12] = BPF_LD_ABS(BPF_H
, 0);
464 insn
[13] = BPF_LD_ABS(BPF_W
, 0);
465 insn
[14] = BPF_MOV64_IMM(R0
, 42);
466 insn
[15] = BPF_EXIT_INSN();
468 self
->u
.ptr
.insns
= insn
;
469 self
->u
.ptr
.len
= 16;
474 static int bpf_fill_jump_around_ld_abs(struct bpf_test
*self
)
476 unsigned int len
= BPF_MAXINSNS
;
477 struct bpf_insn
*insn
;
480 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
484 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
485 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
486 insn
[i
] = BPF_JMP_IMM(BPF_JEQ
, R0
, 10, len
- i
- 2);
489 insn
[i
++] = BPF_LD_ABS(BPF_B
, 1);
490 insn
[i
] = BPF_EXIT_INSN();
492 self
->u
.ptr
.insns
= insn
;
493 self
->u
.ptr
.len
= len
;
498 static int __bpf_fill_stxdw(struct bpf_test
*self
, int size
)
500 unsigned int len
= BPF_MAXINSNS
;
501 struct bpf_insn
*insn
;
504 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
508 insn
[0] = BPF_ALU32_IMM(BPF_MOV
, R0
, 1);
509 insn
[1] = BPF_ST_MEM(size
, R10
, -40, 42);
511 for (i
= 2; i
< len
- 2; i
++)
512 insn
[i
] = BPF_STX_XADD(size
, R10
, R0
, -40);
514 insn
[len
- 2] = BPF_LDX_MEM(size
, R0
, R10
, -40);
515 insn
[len
- 1] = BPF_EXIT_INSN();
517 self
->u
.ptr
.insns
= insn
;
518 self
->u
.ptr
.len
= len
;
519 self
->stack_depth
= 40;
524 static int bpf_fill_stxw(struct bpf_test
*self
)
526 return __bpf_fill_stxdw(self
, BPF_W
);
529 static int bpf_fill_stxdw(struct bpf_test
*self
)
531 return __bpf_fill_stxdw(self
, BPF_DW
);
534 static struct bpf_test tests
[] = {
538 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
539 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
540 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
541 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
542 BPF_STMT(BPF_ALU
| BPF_NEG
, 0), /* A == -3 */
543 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
544 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
545 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
546 BPF_STMT(BPF_MISC
| BPF_TAX
, 0), /* X == len - 3 */
547 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
548 BPF_STMT(BPF_RET
| BPF_A
, 0)
551 { 10, 20, 30, 40, 50 },
552 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
557 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
558 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
559 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
560 BPF_STMT(BPF_RET
| BPF_A
, 0) /* A == len * 2 */
563 { 10, 20, 30, 40, 50 },
564 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
569 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
570 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 2),
571 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
572 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
573 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0xffffffff),
574 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 3),
575 BPF_STMT(BPF_RET
| BPF_A
, 0)
577 CLASSIC
| FLAG_NO_DATA
,
579 { { 0, 0xfffffffd } }
584 BPF_STMT(BPF_LD
| BPF_IMM
, 8),
585 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 2),
586 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
587 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
588 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
589 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
590 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
591 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x70000000),
592 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
593 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
594 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
595 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
596 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
597 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x70000000),
598 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
599 BPF_STMT(BPF_RET
| BPF_A
, 0)
601 CLASSIC
| FLAG_NO_DATA
,
603 { { 0, 0x20000000 } }
608 BPF_STMT(BPF_LD
| BPF_IMM
, 0xff),
609 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
610 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 27),
611 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
612 BPF_STMT(BPF_LD
| BPF_IMM
, 0xf),
613 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_K
, 0xf0),
614 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
615 BPF_STMT(BPF_RET
| BPF_A
, 0)
617 CLASSIC
| FLAG_NO_DATA
,
619 { { 0, 0x800000ff }, { 1, 0x800000ff } },
624 BPF_STMT(BPF_LD
| BPF_IMM
, 0), /* ld #0 */
625 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, 1, 0),
626 BPF_STMT(BPF_RET
| BPF_K
, 0),
627 BPF_STMT(BPF_RET
| BPF_K
, 1),
636 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
637 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, MAX_K
),
638 BPF_STMT(BPF_RET
| BPF_K
, 1)
642 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
647 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, 1000),
648 BPF_STMT(BPF_RET
| BPF_K
, 1)
652 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
657 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
),
658 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
659 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
+ 1),
660 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
661 BPF_STMT(BPF_RET
| BPF_A
, 0)
665 { { 1, 0 }, { 2, 3 } },
670 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_LL_OFF
- 1),
671 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
672 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
673 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
674 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
675 BPF_STMT(BPF_RET
| BPF_A
, 0)
679 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
684 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
),
685 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
686 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
+ 1),
687 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
688 BPF_STMT(BPF_RET
| BPF_A
, 0)
691 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
692 { { 15, 0 }, { 16, 3 } },
697 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_NET_OFF
- 15),
698 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
699 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
700 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
701 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
702 BPF_STMT(BPF_RET
| BPF_A
, 0)
705 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
706 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
711 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
712 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
713 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
714 BPF_STMT(BPF_RET
| BPF_K
, 1),
715 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
716 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
717 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
718 BPF_STMT(BPF_RET
| BPF_K
, 1),
719 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
720 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
721 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
722 BPF_STMT(BPF_RET
| BPF_K
, 1),
723 BPF_STMT(BPF_RET
| BPF_A
, 0)
727 { { 1, 3 }, { 10, 3 } },
732 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
733 SKF_AD_OFF
+ SKF_AD_MARK
),
734 BPF_STMT(BPF_RET
| BPF_A
, 0)
738 { { 1, SKB_MARK
}, { 10, SKB_MARK
} },
743 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
744 SKF_AD_OFF
+ SKF_AD_RXHASH
),
745 BPF_STMT(BPF_RET
| BPF_A
, 0)
749 { { 1, SKB_HASH
}, { 10, SKB_HASH
} },
754 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
755 SKF_AD_OFF
+ SKF_AD_QUEUE
),
756 BPF_STMT(BPF_RET
| BPF_A
, 0)
760 { { 1, SKB_QUEUE_MAP
}, { 10, SKB_QUEUE_MAP
} },
765 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 1),
766 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 20, 1, 0),
767 BPF_STMT(BPF_RET
| BPF_K
, 0),
768 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
769 SKF_AD_OFF
+ SKF_AD_PROTOCOL
),
770 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
771 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
772 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 30, 1, 0),
773 BPF_STMT(BPF_RET
| BPF_K
, 0),
774 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
775 BPF_STMT(BPF_RET
| BPF_A
, 0)
779 { { 10, ETH_P_IP
}, { 100, ETH_P_IP
} },
784 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
785 SKF_AD_OFF
+ SKF_AD_VLAN_TAG
),
786 BPF_STMT(BPF_RET
| BPF_A
, 0)
791 { 1, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
},
792 { 10, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
}
796 "LD_VLAN_TAG_PRESENT",
798 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
799 SKF_AD_OFF
+ SKF_AD_VLAN_TAG_PRESENT
),
800 BPF_STMT(BPF_RET
| BPF_A
, 0)
805 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
806 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
812 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
813 SKF_AD_OFF
+ SKF_AD_IFINDEX
),
814 BPF_STMT(BPF_RET
| BPF_A
, 0)
818 { { 1, SKB_DEV_IFINDEX
}, { 10, SKB_DEV_IFINDEX
} },
823 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
824 SKF_AD_OFF
+ SKF_AD_HATYPE
),
825 BPF_STMT(BPF_RET
| BPF_A
, 0)
829 { { 1, SKB_DEV_TYPE
}, { 10, SKB_DEV_TYPE
} },
834 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
835 SKF_AD_OFF
+ SKF_AD_CPU
),
836 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
837 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
838 SKF_AD_OFF
+ SKF_AD_CPU
),
839 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
840 BPF_STMT(BPF_RET
| BPF_A
, 0)
844 { { 1, 0 }, { 10, 0 } },
849 BPF_STMT(BPF_LDX
| BPF_IMM
, 2),
850 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
851 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
852 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
853 SKF_AD_OFF
+ SKF_AD_NLATTR
),
854 BPF_STMT(BPF_RET
| BPF_A
, 0)
858 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
860 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
862 { { 4, 0 }, { 20, 6 } },
867 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
868 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
869 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
870 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
871 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
872 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
873 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
874 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
875 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
876 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
877 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
878 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
879 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
880 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
881 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
882 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
883 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
884 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
885 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
886 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
887 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
888 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
889 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
890 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
891 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
892 BPF_STMT(BPF_RET
| BPF_A
, 0)
896 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
898 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
900 { { 4, 0 }, { 20, 10 } },
905 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
906 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
907 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
908 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
909 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
910 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
911 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
912 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
913 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
914 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
915 BPF_STMT(BPF_RET
| BPF_A
, 0)
918 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
919 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
920 * id 9737, seq 1, length 64
922 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
925 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
926 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
927 { { 30, 0 }, { 100, 42 } },
932 BPF_STMT(BPF_LD
| BPF_IMM
, 10),
933 BPF_STMT(BPF_LDX
| BPF_IMM
, 300),
934 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
935 SKF_AD_OFF
+ SKF_AD_ALU_XOR_X
),
936 BPF_STMT(BPF_RET
| BPF_A
, 0)
940 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
945 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
946 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
947 BPF_STMT(BPF_ALU
| BPF_RSH
, 1),
948 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
949 BPF_STMT(BPF_ST
, 1), /* M1 = 1 ^ len */
950 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_K
, 0x80000000),
951 BPF_STMT(BPF_ST
, 2), /* M2 = 1 ^ len ^ 0x80000000 */
952 BPF_STMT(BPF_STX
, 15), /* M3 = len */
953 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
954 BPF_STMT(BPF_LD
| BPF_MEM
, 2),
955 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
956 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
957 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
958 BPF_STMT(BPF_RET
| BPF_A
, 0)
962 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
967 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
968 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
969 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 0, 1),
970 BPF_STMT(BPF_RET
| BPF_K
, 1),
971 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
975 { { 1, 0 }, { 3, 1 }, { 4, MAX_K
} },
980 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
981 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
982 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_X
, 0, 0, 1),
983 BPF_STMT(BPF_RET
| BPF_K
, 1),
984 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
988 { { 2, 0 }, { 3, 1 }, { 4, MAX_K
} },
991 "JGE (jt 0), test 1",
993 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
994 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
995 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
996 BPF_STMT(BPF_RET
| BPF_K
, 1),
997 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1001 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
1004 "JGE (jt 0), test 2",
1006 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1007 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
1008 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
1009 BPF_STMT(BPF_RET
| BPF_K
, 1),
1010 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1014 { { 4, 1 }, { 5, 1 }, { 6, MAX_K
} },
1019 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1020 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, MAX_K
),
1021 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 1, 1, 0),
1022 BPF_STMT(BPF_RET
| BPF_K
, 10),
1023 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 2, 1, 0),
1024 BPF_STMT(BPF_RET
| BPF_K
, 20),
1025 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 3, 1, 0),
1026 BPF_STMT(BPF_RET
| BPF_K
, 30),
1027 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 4, 1, 0),
1028 BPF_STMT(BPF_RET
| BPF_K
, 40),
1029 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1033 { { 1, 20 }, { 3, 40 }, { 5, MAX_K
} },
1038 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1039 BPF_JUMP(BPF_JMP
| BPF_JA
, 1, 1, 1),
1040 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1041 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1042 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1043 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1044 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, 4),
1045 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
1046 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
1047 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 1, 0, 1),
1048 BPF_STMT(BPF_RET
| BPF_K
, 10),
1049 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x80000000, 0, 1),
1050 BPF_STMT(BPF_RET
| BPF_K
, 20),
1051 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1052 BPF_STMT(BPF_RET
| BPF_K
, 30),
1053 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1054 BPF_STMT(BPF_RET
| BPF_K
, 30),
1055 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1056 BPF_STMT(BPF_RET
| BPF_K
, 30),
1057 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1058 BPF_STMT(BPF_RET
| BPF_K
, 30),
1059 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1060 BPF_STMT(BPF_RET
| BPF_K
, 30),
1061 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1064 { 0, 0xAA, 0x55, 1 },
1065 { { 4, 10 }, { 5, 20 }, { 6, MAX_K
} },
1070 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1071 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 0, 8), /* IPv6 */
1072 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 20),
1073 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1074 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1075 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 17),
1076 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 54),
1077 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 14, 0),
1078 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 56),
1079 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 12, 13),
1080 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0800, 0, 12), /* IPv4 */
1081 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1082 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1083 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1084 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 8),
1085 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1086 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 6, 0),
1087 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1088 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1089 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1090 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1091 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 1),
1092 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1093 BPF_STMT(BPF_RET
| BPF_K
, 0),
1096 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1097 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1098 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1099 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1101 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1102 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1104 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1105 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1106 0x0a, 0x01, 0x01, 0x95, /* ip src */
1107 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1109 0x00, 0x16 /* dst port */ },
1110 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1115 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1116 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1117 * (len > 115 or len < 30000000000)' -d
1119 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1120 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 30, 0),
1121 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x800, 0, 29),
1122 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1123 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 0, 27),
1124 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1125 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 25, 0),
1126 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1127 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1128 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1129 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1130 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 20),
1131 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 16),
1132 BPF_STMT(BPF_ST
, 1),
1133 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 14),
1134 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf),
1135 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 2),
1136 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x5), /* libpcap emits K on TAX */
1137 BPF_STMT(BPF_LD
| BPF_MEM
, 1),
1138 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
1139 BPF_STMT(BPF_ST
, 5),
1140 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1141 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 26),
1142 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
1143 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 2),
1144 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x9), /* libpcap emits K on TAX */
1145 BPF_STMT(BPF_LD
| BPF_MEM
, 5),
1146 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 4, 0),
1147 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
1148 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_K
, 0x73, 1, 0),
1149 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 0xfc23ac00, 1, 0),
1150 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1151 BPF_STMT(BPF_RET
| BPF_K
, 0),
1154 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1155 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1157 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1158 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1159 0x0a, 0x01, 0x01, 0x95, /* ip src */
1160 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1162 0x00, 0x16 /* dst port */ },
1163 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1168 /* check that unitialized X and A contain zeros */
1169 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1170 BPF_STMT(BPF_RET
| BPF_A
, 0)
1179 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1180 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
1181 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1182 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1183 BPF_ALU64_IMM(BPF_ADD
, R1
, -1),
1184 BPF_ALU64_IMM(BPF_MUL
, R1
, 3),
1185 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
1190 { { 0, 0xfffffffd } }
1195 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1196 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1197 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1198 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1199 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xfffffffd, 1),
1201 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1211 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1212 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
1213 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1214 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1215 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1216 BPF_JMP_IMM(BPF_JEQ
, R1
, 0x2ffffff, 1),
1218 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1228 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1229 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1230 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1231 BPF_ALU32_REG(BPF_MUL
, R1
, R2
),
1232 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1233 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xffffff, 1),
1235 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1243 /* Have to test all register combinations, since
1244 * JITing of different registers will produce
1245 * different asm code.
1249 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1250 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1251 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1252 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1253 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1254 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1255 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1256 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1257 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1258 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1259 BPF_ALU64_IMM(BPF_ADD
, R0
, 20),
1260 BPF_ALU64_IMM(BPF_ADD
, R1
, 20),
1261 BPF_ALU64_IMM(BPF_ADD
, R2
, 20),
1262 BPF_ALU64_IMM(BPF_ADD
, R3
, 20),
1263 BPF_ALU64_IMM(BPF_ADD
, R4
, 20),
1264 BPF_ALU64_IMM(BPF_ADD
, R5
, 20),
1265 BPF_ALU64_IMM(BPF_ADD
, R6
, 20),
1266 BPF_ALU64_IMM(BPF_ADD
, R7
, 20),
1267 BPF_ALU64_IMM(BPF_ADD
, R8
, 20),
1268 BPF_ALU64_IMM(BPF_ADD
, R9
, 20),
1269 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1270 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1271 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1272 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1273 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1274 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1275 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1276 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1277 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1278 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1279 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1280 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1281 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1282 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1283 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1284 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1285 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1286 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1287 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1288 BPF_ALU64_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1289 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1291 BPF_ALU64_REG(BPF_ADD
, R1
, R0
),
1292 BPF_ALU64_REG(BPF_ADD
, R1
, R1
),
1293 BPF_ALU64_REG(BPF_ADD
, R1
, R2
),
1294 BPF_ALU64_REG(BPF_ADD
, R1
, R3
),
1295 BPF_ALU64_REG(BPF_ADD
, R1
, R4
),
1296 BPF_ALU64_REG(BPF_ADD
, R1
, R5
),
1297 BPF_ALU64_REG(BPF_ADD
, R1
, R6
),
1298 BPF_ALU64_REG(BPF_ADD
, R1
, R7
),
1299 BPF_ALU64_REG(BPF_ADD
, R1
, R8
),
1300 BPF_ALU64_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1301 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1303 BPF_ALU64_REG(BPF_ADD
, R2
, R0
),
1304 BPF_ALU64_REG(BPF_ADD
, R2
, R1
),
1305 BPF_ALU64_REG(BPF_ADD
, R2
, R2
),
1306 BPF_ALU64_REG(BPF_ADD
, R2
, R3
),
1307 BPF_ALU64_REG(BPF_ADD
, R2
, R4
),
1308 BPF_ALU64_REG(BPF_ADD
, R2
, R5
),
1309 BPF_ALU64_REG(BPF_ADD
, R2
, R6
),
1310 BPF_ALU64_REG(BPF_ADD
, R2
, R7
),
1311 BPF_ALU64_REG(BPF_ADD
, R2
, R8
),
1312 BPF_ALU64_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1313 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1315 BPF_ALU64_REG(BPF_ADD
, R3
, R0
),
1316 BPF_ALU64_REG(BPF_ADD
, R3
, R1
),
1317 BPF_ALU64_REG(BPF_ADD
, R3
, R2
),
1318 BPF_ALU64_REG(BPF_ADD
, R3
, R3
),
1319 BPF_ALU64_REG(BPF_ADD
, R3
, R4
),
1320 BPF_ALU64_REG(BPF_ADD
, R3
, R5
),
1321 BPF_ALU64_REG(BPF_ADD
, R3
, R6
),
1322 BPF_ALU64_REG(BPF_ADD
, R3
, R7
),
1323 BPF_ALU64_REG(BPF_ADD
, R3
, R8
),
1324 BPF_ALU64_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1325 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1327 BPF_ALU64_REG(BPF_ADD
, R4
, R0
),
1328 BPF_ALU64_REG(BPF_ADD
, R4
, R1
),
1329 BPF_ALU64_REG(BPF_ADD
, R4
, R2
),
1330 BPF_ALU64_REG(BPF_ADD
, R4
, R3
),
1331 BPF_ALU64_REG(BPF_ADD
, R4
, R4
),
1332 BPF_ALU64_REG(BPF_ADD
, R4
, R5
),
1333 BPF_ALU64_REG(BPF_ADD
, R4
, R6
),
1334 BPF_ALU64_REG(BPF_ADD
, R4
, R7
),
1335 BPF_ALU64_REG(BPF_ADD
, R4
, R8
),
1336 BPF_ALU64_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1337 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1339 BPF_ALU64_REG(BPF_ADD
, R5
, R0
),
1340 BPF_ALU64_REG(BPF_ADD
, R5
, R1
),
1341 BPF_ALU64_REG(BPF_ADD
, R5
, R2
),
1342 BPF_ALU64_REG(BPF_ADD
, R5
, R3
),
1343 BPF_ALU64_REG(BPF_ADD
, R5
, R4
),
1344 BPF_ALU64_REG(BPF_ADD
, R5
, R5
),
1345 BPF_ALU64_REG(BPF_ADD
, R5
, R6
),
1346 BPF_ALU64_REG(BPF_ADD
, R5
, R7
),
1347 BPF_ALU64_REG(BPF_ADD
, R5
, R8
),
1348 BPF_ALU64_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1349 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1351 BPF_ALU64_REG(BPF_ADD
, R6
, R0
),
1352 BPF_ALU64_REG(BPF_ADD
, R6
, R1
),
1353 BPF_ALU64_REG(BPF_ADD
, R6
, R2
),
1354 BPF_ALU64_REG(BPF_ADD
, R6
, R3
),
1355 BPF_ALU64_REG(BPF_ADD
, R6
, R4
),
1356 BPF_ALU64_REG(BPF_ADD
, R6
, R5
),
1357 BPF_ALU64_REG(BPF_ADD
, R6
, R6
),
1358 BPF_ALU64_REG(BPF_ADD
, R6
, R7
),
1359 BPF_ALU64_REG(BPF_ADD
, R6
, R8
),
1360 BPF_ALU64_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1361 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1363 BPF_ALU64_REG(BPF_ADD
, R7
, R0
),
1364 BPF_ALU64_REG(BPF_ADD
, R7
, R1
),
1365 BPF_ALU64_REG(BPF_ADD
, R7
, R2
),
1366 BPF_ALU64_REG(BPF_ADD
, R7
, R3
),
1367 BPF_ALU64_REG(BPF_ADD
, R7
, R4
),
1368 BPF_ALU64_REG(BPF_ADD
, R7
, R5
),
1369 BPF_ALU64_REG(BPF_ADD
, R7
, R6
),
1370 BPF_ALU64_REG(BPF_ADD
, R7
, R7
),
1371 BPF_ALU64_REG(BPF_ADD
, R7
, R8
),
1372 BPF_ALU64_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1373 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1375 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1376 BPF_ALU64_REG(BPF_ADD
, R8
, R1
),
1377 BPF_ALU64_REG(BPF_ADD
, R8
, R2
),
1378 BPF_ALU64_REG(BPF_ADD
, R8
, R3
),
1379 BPF_ALU64_REG(BPF_ADD
, R8
, R4
),
1380 BPF_ALU64_REG(BPF_ADD
, R8
, R5
),
1381 BPF_ALU64_REG(BPF_ADD
, R8
, R6
),
1382 BPF_ALU64_REG(BPF_ADD
, R8
, R7
),
1383 BPF_ALU64_REG(BPF_ADD
, R8
, R8
),
1384 BPF_ALU64_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1385 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1387 BPF_ALU64_REG(BPF_ADD
, R9
, R0
),
1388 BPF_ALU64_REG(BPF_ADD
, R9
, R1
),
1389 BPF_ALU64_REG(BPF_ADD
, R9
, R2
),
1390 BPF_ALU64_REG(BPF_ADD
, R9
, R3
),
1391 BPF_ALU64_REG(BPF_ADD
, R9
, R4
),
1392 BPF_ALU64_REG(BPF_ADD
, R9
, R5
),
1393 BPF_ALU64_REG(BPF_ADD
, R9
, R6
),
1394 BPF_ALU64_REG(BPF_ADD
, R9
, R7
),
1395 BPF_ALU64_REG(BPF_ADD
, R9
, R8
),
1396 BPF_ALU64_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1397 BPF_ALU64_REG(BPF_MOV
, R0
, R9
),
1407 BPF_ALU32_IMM(BPF_MOV
, R0
, 20),
1408 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
1409 BPF_ALU32_IMM(BPF_MOV
, R2
, 2),
1410 BPF_ALU32_IMM(BPF_MOV
, R3
, 3),
1411 BPF_ALU32_IMM(BPF_MOV
, R4
, 4),
1412 BPF_ALU32_IMM(BPF_MOV
, R5
, 5),
1413 BPF_ALU32_IMM(BPF_MOV
, R6
, 6),
1414 BPF_ALU32_IMM(BPF_MOV
, R7
, 7),
1415 BPF_ALU32_IMM(BPF_MOV
, R8
, 8),
1416 BPF_ALU32_IMM(BPF_MOV
, R9
, 9),
1417 BPF_ALU64_IMM(BPF_ADD
, R1
, 10),
1418 BPF_ALU64_IMM(BPF_ADD
, R2
, 10),
1419 BPF_ALU64_IMM(BPF_ADD
, R3
, 10),
1420 BPF_ALU64_IMM(BPF_ADD
, R4
, 10),
1421 BPF_ALU64_IMM(BPF_ADD
, R5
, 10),
1422 BPF_ALU64_IMM(BPF_ADD
, R6
, 10),
1423 BPF_ALU64_IMM(BPF_ADD
, R7
, 10),
1424 BPF_ALU64_IMM(BPF_ADD
, R8
, 10),
1425 BPF_ALU64_IMM(BPF_ADD
, R9
, 10),
1426 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
1427 BPF_ALU32_REG(BPF_ADD
, R0
, R2
),
1428 BPF_ALU32_REG(BPF_ADD
, R0
, R3
),
1429 BPF_ALU32_REG(BPF_ADD
, R0
, R4
),
1430 BPF_ALU32_REG(BPF_ADD
, R0
, R5
),
1431 BPF_ALU32_REG(BPF_ADD
, R0
, R6
),
1432 BPF_ALU32_REG(BPF_ADD
, R0
, R7
),
1433 BPF_ALU32_REG(BPF_ADD
, R0
, R8
),
1434 BPF_ALU32_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1435 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1437 BPF_ALU32_REG(BPF_ADD
, R1
, R0
),
1438 BPF_ALU32_REG(BPF_ADD
, R1
, R1
),
1439 BPF_ALU32_REG(BPF_ADD
, R1
, R2
),
1440 BPF_ALU32_REG(BPF_ADD
, R1
, R3
),
1441 BPF_ALU32_REG(BPF_ADD
, R1
, R4
),
1442 BPF_ALU32_REG(BPF_ADD
, R1
, R5
),
1443 BPF_ALU32_REG(BPF_ADD
, R1
, R6
),
1444 BPF_ALU32_REG(BPF_ADD
, R1
, R7
),
1445 BPF_ALU32_REG(BPF_ADD
, R1
, R8
),
1446 BPF_ALU32_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1447 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1449 BPF_ALU32_REG(BPF_ADD
, R2
, R0
),
1450 BPF_ALU32_REG(BPF_ADD
, R2
, R1
),
1451 BPF_ALU32_REG(BPF_ADD
, R2
, R2
),
1452 BPF_ALU32_REG(BPF_ADD
, R2
, R3
),
1453 BPF_ALU32_REG(BPF_ADD
, R2
, R4
),
1454 BPF_ALU32_REG(BPF_ADD
, R2
, R5
),
1455 BPF_ALU32_REG(BPF_ADD
, R2
, R6
),
1456 BPF_ALU32_REG(BPF_ADD
, R2
, R7
),
1457 BPF_ALU32_REG(BPF_ADD
, R2
, R8
),
1458 BPF_ALU32_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1459 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1461 BPF_ALU32_REG(BPF_ADD
, R3
, R0
),
1462 BPF_ALU32_REG(BPF_ADD
, R3
, R1
),
1463 BPF_ALU32_REG(BPF_ADD
, R3
, R2
),
1464 BPF_ALU32_REG(BPF_ADD
, R3
, R3
),
1465 BPF_ALU32_REG(BPF_ADD
, R3
, R4
),
1466 BPF_ALU32_REG(BPF_ADD
, R3
, R5
),
1467 BPF_ALU32_REG(BPF_ADD
, R3
, R6
),
1468 BPF_ALU32_REG(BPF_ADD
, R3
, R7
),
1469 BPF_ALU32_REG(BPF_ADD
, R3
, R8
),
1470 BPF_ALU32_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1471 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1473 BPF_ALU32_REG(BPF_ADD
, R4
, R0
),
1474 BPF_ALU32_REG(BPF_ADD
, R4
, R1
),
1475 BPF_ALU32_REG(BPF_ADD
, R4
, R2
),
1476 BPF_ALU32_REG(BPF_ADD
, R4
, R3
),
1477 BPF_ALU32_REG(BPF_ADD
, R4
, R4
),
1478 BPF_ALU32_REG(BPF_ADD
, R4
, R5
),
1479 BPF_ALU32_REG(BPF_ADD
, R4
, R6
),
1480 BPF_ALU32_REG(BPF_ADD
, R4
, R7
),
1481 BPF_ALU32_REG(BPF_ADD
, R4
, R8
),
1482 BPF_ALU32_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1483 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1485 BPF_ALU32_REG(BPF_ADD
, R5
, R0
),
1486 BPF_ALU32_REG(BPF_ADD
, R5
, R1
),
1487 BPF_ALU32_REG(BPF_ADD
, R5
, R2
),
1488 BPF_ALU32_REG(BPF_ADD
, R5
, R3
),
1489 BPF_ALU32_REG(BPF_ADD
, R5
, R4
),
1490 BPF_ALU32_REG(BPF_ADD
, R5
, R5
),
1491 BPF_ALU32_REG(BPF_ADD
, R5
, R6
),
1492 BPF_ALU32_REG(BPF_ADD
, R5
, R7
),
1493 BPF_ALU32_REG(BPF_ADD
, R5
, R8
),
1494 BPF_ALU32_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1495 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1497 BPF_ALU32_REG(BPF_ADD
, R6
, R0
),
1498 BPF_ALU32_REG(BPF_ADD
, R6
, R1
),
1499 BPF_ALU32_REG(BPF_ADD
, R6
, R2
),
1500 BPF_ALU32_REG(BPF_ADD
, R6
, R3
),
1501 BPF_ALU32_REG(BPF_ADD
, R6
, R4
),
1502 BPF_ALU32_REG(BPF_ADD
, R6
, R5
),
1503 BPF_ALU32_REG(BPF_ADD
, R6
, R6
),
1504 BPF_ALU32_REG(BPF_ADD
, R6
, R7
),
1505 BPF_ALU32_REG(BPF_ADD
, R6
, R8
),
1506 BPF_ALU32_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1507 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1509 BPF_ALU32_REG(BPF_ADD
, R7
, R0
),
1510 BPF_ALU32_REG(BPF_ADD
, R7
, R1
),
1511 BPF_ALU32_REG(BPF_ADD
, R7
, R2
),
1512 BPF_ALU32_REG(BPF_ADD
, R7
, R3
),
1513 BPF_ALU32_REG(BPF_ADD
, R7
, R4
),
1514 BPF_ALU32_REG(BPF_ADD
, R7
, R5
),
1515 BPF_ALU32_REG(BPF_ADD
, R7
, R6
),
1516 BPF_ALU32_REG(BPF_ADD
, R7
, R7
),
1517 BPF_ALU32_REG(BPF_ADD
, R7
, R8
),
1518 BPF_ALU32_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1519 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1521 BPF_ALU32_REG(BPF_ADD
, R8
, R0
),
1522 BPF_ALU32_REG(BPF_ADD
, R8
, R1
),
1523 BPF_ALU32_REG(BPF_ADD
, R8
, R2
),
1524 BPF_ALU32_REG(BPF_ADD
, R8
, R3
),
1525 BPF_ALU32_REG(BPF_ADD
, R8
, R4
),
1526 BPF_ALU32_REG(BPF_ADD
, R8
, R5
),
1527 BPF_ALU32_REG(BPF_ADD
, R8
, R6
),
1528 BPF_ALU32_REG(BPF_ADD
, R8
, R7
),
1529 BPF_ALU32_REG(BPF_ADD
, R8
, R8
),
1530 BPF_ALU32_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1531 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1533 BPF_ALU32_REG(BPF_ADD
, R9
, R0
),
1534 BPF_ALU32_REG(BPF_ADD
, R9
, R1
),
1535 BPF_ALU32_REG(BPF_ADD
, R9
, R2
),
1536 BPF_ALU32_REG(BPF_ADD
, R9
, R3
),
1537 BPF_ALU32_REG(BPF_ADD
, R9
, R4
),
1538 BPF_ALU32_REG(BPF_ADD
, R9
, R5
),
1539 BPF_ALU32_REG(BPF_ADD
, R9
, R6
),
1540 BPF_ALU32_REG(BPF_ADD
, R9
, R7
),
1541 BPF_ALU32_REG(BPF_ADD
, R9
, R8
),
1542 BPF_ALU32_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1543 BPF_ALU32_REG(BPF_MOV
, R0
, R9
),
1550 { /* Mainly checking JIT here. */
1553 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1554 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1555 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1556 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1557 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1558 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1559 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1560 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1561 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1562 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1563 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1564 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1565 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1566 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1567 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1568 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1569 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1570 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1571 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1572 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1573 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1574 BPF_JMP_IMM(BPF_JEQ
, R0
, -55, 1),
1576 BPF_ALU64_REG(BPF_SUB
, R1
, R0
),
1577 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1578 BPF_ALU64_REG(BPF_SUB
, R1
, R3
),
1579 BPF_ALU64_REG(BPF_SUB
, R1
, R4
),
1580 BPF_ALU64_REG(BPF_SUB
, R1
, R5
),
1581 BPF_ALU64_REG(BPF_SUB
, R1
, R6
),
1582 BPF_ALU64_REG(BPF_SUB
, R1
, R7
),
1583 BPF_ALU64_REG(BPF_SUB
, R1
, R8
),
1584 BPF_ALU64_REG(BPF_SUB
, R1
, R9
),
1585 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1586 BPF_ALU64_REG(BPF_SUB
, R2
, R0
),
1587 BPF_ALU64_REG(BPF_SUB
, R2
, R1
),
1588 BPF_ALU64_REG(BPF_SUB
, R2
, R3
),
1589 BPF_ALU64_REG(BPF_SUB
, R2
, R4
),
1590 BPF_ALU64_REG(BPF_SUB
, R2
, R5
),
1591 BPF_ALU64_REG(BPF_SUB
, R2
, R6
),
1592 BPF_ALU64_REG(BPF_SUB
, R2
, R7
),
1593 BPF_ALU64_REG(BPF_SUB
, R2
, R8
),
1594 BPF_ALU64_REG(BPF_SUB
, R2
, R9
),
1595 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1596 BPF_ALU64_REG(BPF_SUB
, R3
, R0
),
1597 BPF_ALU64_REG(BPF_SUB
, R3
, R1
),
1598 BPF_ALU64_REG(BPF_SUB
, R3
, R2
),
1599 BPF_ALU64_REG(BPF_SUB
, R3
, R4
),
1600 BPF_ALU64_REG(BPF_SUB
, R3
, R5
),
1601 BPF_ALU64_REG(BPF_SUB
, R3
, R6
),
1602 BPF_ALU64_REG(BPF_SUB
, R3
, R7
),
1603 BPF_ALU64_REG(BPF_SUB
, R3
, R8
),
1604 BPF_ALU64_REG(BPF_SUB
, R3
, R9
),
1605 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1606 BPF_ALU64_REG(BPF_SUB
, R4
, R0
),
1607 BPF_ALU64_REG(BPF_SUB
, R4
, R1
),
1608 BPF_ALU64_REG(BPF_SUB
, R4
, R2
),
1609 BPF_ALU64_REG(BPF_SUB
, R4
, R3
),
1610 BPF_ALU64_REG(BPF_SUB
, R4
, R5
),
1611 BPF_ALU64_REG(BPF_SUB
, R4
, R6
),
1612 BPF_ALU64_REG(BPF_SUB
, R4
, R7
),
1613 BPF_ALU64_REG(BPF_SUB
, R4
, R8
),
1614 BPF_ALU64_REG(BPF_SUB
, R4
, R9
),
1615 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1616 BPF_ALU64_REG(BPF_SUB
, R5
, R0
),
1617 BPF_ALU64_REG(BPF_SUB
, R5
, R1
),
1618 BPF_ALU64_REG(BPF_SUB
, R5
, R2
),
1619 BPF_ALU64_REG(BPF_SUB
, R5
, R3
),
1620 BPF_ALU64_REG(BPF_SUB
, R5
, R4
),
1621 BPF_ALU64_REG(BPF_SUB
, R5
, R6
),
1622 BPF_ALU64_REG(BPF_SUB
, R5
, R7
),
1623 BPF_ALU64_REG(BPF_SUB
, R5
, R8
),
1624 BPF_ALU64_REG(BPF_SUB
, R5
, R9
),
1625 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1626 BPF_ALU64_REG(BPF_SUB
, R6
, R0
),
1627 BPF_ALU64_REG(BPF_SUB
, R6
, R1
),
1628 BPF_ALU64_REG(BPF_SUB
, R6
, R2
),
1629 BPF_ALU64_REG(BPF_SUB
, R6
, R3
),
1630 BPF_ALU64_REG(BPF_SUB
, R6
, R4
),
1631 BPF_ALU64_REG(BPF_SUB
, R6
, R5
),
1632 BPF_ALU64_REG(BPF_SUB
, R6
, R7
),
1633 BPF_ALU64_REG(BPF_SUB
, R6
, R8
),
1634 BPF_ALU64_REG(BPF_SUB
, R6
, R9
),
1635 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1636 BPF_ALU64_REG(BPF_SUB
, R7
, R0
),
1637 BPF_ALU64_REG(BPF_SUB
, R7
, R1
),
1638 BPF_ALU64_REG(BPF_SUB
, R7
, R2
),
1639 BPF_ALU64_REG(BPF_SUB
, R7
, R3
),
1640 BPF_ALU64_REG(BPF_SUB
, R7
, R4
),
1641 BPF_ALU64_REG(BPF_SUB
, R7
, R5
),
1642 BPF_ALU64_REG(BPF_SUB
, R7
, R6
),
1643 BPF_ALU64_REG(BPF_SUB
, R7
, R8
),
1644 BPF_ALU64_REG(BPF_SUB
, R7
, R9
),
1645 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1646 BPF_ALU64_REG(BPF_SUB
, R8
, R0
),
1647 BPF_ALU64_REG(BPF_SUB
, R8
, R1
),
1648 BPF_ALU64_REG(BPF_SUB
, R8
, R2
),
1649 BPF_ALU64_REG(BPF_SUB
, R8
, R3
),
1650 BPF_ALU64_REG(BPF_SUB
, R8
, R4
),
1651 BPF_ALU64_REG(BPF_SUB
, R8
, R5
),
1652 BPF_ALU64_REG(BPF_SUB
, R8
, R6
),
1653 BPF_ALU64_REG(BPF_SUB
, R8
, R7
),
1654 BPF_ALU64_REG(BPF_SUB
, R8
, R9
),
1655 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1656 BPF_ALU64_REG(BPF_SUB
, R9
, R0
),
1657 BPF_ALU64_REG(BPF_SUB
, R9
, R1
),
1658 BPF_ALU64_REG(BPF_SUB
, R9
, R2
),
1659 BPF_ALU64_REG(BPF_SUB
, R9
, R3
),
1660 BPF_ALU64_REG(BPF_SUB
, R9
, R4
),
1661 BPF_ALU64_REG(BPF_SUB
, R9
, R5
),
1662 BPF_ALU64_REG(BPF_SUB
, R9
, R6
),
1663 BPF_ALU64_REG(BPF_SUB
, R9
, R7
),
1664 BPF_ALU64_REG(BPF_SUB
, R9
, R8
),
1665 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1666 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1667 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
1668 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1669 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1670 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1671 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1672 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1673 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1674 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1675 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1676 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1683 { /* Mainly checking JIT here. */
1686 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1687 BPF_ALU64_REG(BPF_XOR
, R1
, R1
),
1688 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 1),
1690 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1691 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1692 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1693 BPF_ALU64_REG(BPF_XOR
, R2
, R2
),
1694 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
1696 BPF_ALU64_REG(BPF_SUB
, R2
, R2
),
1697 BPF_ALU64_REG(BPF_XOR
, R3
, R3
),
1698 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1699 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1700 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 1),
1702 BPF_ALU64_REG(BPF_SUB
, R3
, R3
),
1703 BPF_ALU64_REG(BPF_XOR
, R4
, R4
),
1704 BPF_ALU64_IMM(BPF_MOV
, R2
, 1),
1705 BPF_ALU64_IMM(BPF_MOV
, R5
, -1),
1706 BPF_JMP_REG(BPF_JEQ
, R3
, R4
, 1),
1708 BPF_ALU64_REG(BPF_SUB
, R4
, R4
),
1709 BPF_ALU64_REG(BPF_XOR
, R5
, R5
),
1710 BPF_ALU64_IMM(BPF_MOV
, R3
, 1),
1711 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
1712 BPF_JMP_REG(BPF_JEQ
, R5
, R4
, 1),
1714 BPF_ALU64_IMM(BPF_MOV
, R5
, 1),
1715 BPF_ALU64_REG(BPF_SUB
, R5
, R5
),
1716 BPF_ALU64_REG(BPF_XOR
, R6
, R6
),
1717 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1718 BPF_ALU64_IMM(BPF_MOV
, R8
, -1),
1719 BPF_JMP_REG(BPF_JEQ
, R5
, R6
, 1),
1721 BPF_ALU64_REG(BPF_SUB
, R6
, R6
),
1722 BPF_ALU64_REG(BPF_XOR
, R7
, R7
),
1723 BPF_JMP_REG(BPF_JEQ
, R7
, R6
, 1),
1725 BPF_ALU64_REG(BPF_SUB
, R7
, R7
),
1726 BPF_ALU64_REG(BPF_XOR
, R8
, R8
),
1727 BPF_JMP_REG(BPF_JEQ
, R7
, R8
, 1),
1729 BPF_ALU64_REG(BPF_SUB
, R8
, R8
),
1730 BPF_ALU64_REG(BPF_XOR
, R9
, R9
),
1731 BPF_JMP_REG(BPF_JEQ
, R9
, R8
, 1),
1733 BPF_ALU64_REG(BPF_SUB
, R9
, R9
),
1734 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1735 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 1),
1737 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1738 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1739 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 2),
1740 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1742 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1749 { /* Mainly checking JIT here. */
1752 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1753 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1754 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1755 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1756 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1757 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1758 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1759 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1760 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1761 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1762 BPF_ALU64_REG(BPF_MUL
, R0
, R0
),
1763 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
1764 BPF_ALU64_REG(BPF_MUL
, R0
, R2
),
1765 BPF_ALU64_REG(BPF_MUL
, R0
, R3
),
1766 BPF_ALU64_REG(BPF_MUL
, R0
, R4
),
1767 BPF_ALU64_REG(BPF_MUL
, R0
, R5
),
1768 BPF_ALU64_REG(BPF_MUL
, R0
, R6
),
1769 BPF_ALU64_REG(BPF_MUL
, R0
, R7
),
1770 BPF_ALU64_REG(BPF_MUL
, R0
, R8
),
1771 BPF_ALU64_REG(BPF_MUL
, R0
, R9
),
1772 BPF_ALU64_IMM(BPF_MUL
, R0
, 10),
1773 BPF_JMP_IMM(BPF_JEQ
, R0
, 439084800, 1),
1775 BPF_ALU64_REG(BPF_MUL
, R1
, R0
),
1776 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1777 BPF_ALU64_REG(BPF_MUL
, R1
, R3
),
1778 BPF_ALU64_REG(BPF_MUL
, R1
, R4
),
1779 BPF_ALU64_REG(BPF_MUL
, R1
, R5
),
1780 BPF_ALU64_REG(BPF_MUL
, R1
, R6
),
1781 BPF_ALU64_REG(BPF_MUL
, R1
, R7
),
1782 BPF_ALU64_REG(BPF_MUL
, R1
, R8
),
1783 BPF_ALU64_REG(BPF_MUL
, R1
, R9
),
1784 BPF_ALU64_IMM(BPF_MUL
, R1
, 10),
1785 BPF_ALU64_REG(BPF_MOV
, R2
, R1
),
1786 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1787 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5a924, 1),
1789 BPF_ALU64_IMM(BPF_LSH
, R1
, 32),
1790 BPF_ALU64_IMM(BPF_ARSH
, R1
, 32),
1791 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xebb90000, 1),
1793 BPF_ALU64_REG(BPF_MUL
, R2
, R0
),
1794 BPF_ALU64_REG(BPF_MUL
, R2
, R1
),
1795 BPF_ALU64_REG(BPF_MUL
, R2
, R3
),
1796 BPF_ALU64_REG(BPF_MUL
, R2
, R4
),
1797 BPF_ALU64_REG(BPF_MUL
, R2
, R5
),
1798 BPF_ALU64_REG(BPF_MUL
, R2
, R6
),
1799 BPF_ALU64_REG(BPF_MUL
, R2
, R7
),
1800 BPF_ALU64_REG(BPF_MUL
, R2
, R8
),
1801 BPF_ALU64_REG(BPF_MUL
, R2
, R9
),
1802 BPF_ALU64_IMM(BPF_MUL
, R2
, 10),
1803 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1804 BPF_ALU64_REG(BPF_MOV
, R0
, R2
),
1809 { { 0, 0x35d97ef2 } }
1811 { /* Mainly checking JIT here. */
1814 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1815 BPF_MOV64_REG(R1
, R0
),
1816 BPF_MOV64_REG(R2
, R1
),
1817 BPF_MOV64_REG(R3
, R2
),
1818 BPF_MOV64_REG(R4
, R3
),
1819 BPF_MOV64_REG(R5
, R4
),
1820 BPF_MOV64_REG(R6
, R5
),
1821 BPF_MOV64_REG(R7
, R6
),
1822 BPF_MOV64_REG(R8
, R7
),
1823 BPF_MOV64_REG(R9
, R8
),
1824 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1825 BPF_ALU64_IMM(BPF_MOV
, R1
, 0),
1826 BPF_ALU64_IMM(BPF_MOV
, R2
, 0),
1827 BPF_ALU64_IMM(BPF_MOV
, R3
, 0),
1828 BPF_ALU64_IMM(BPF_MOV
, R4
, 0),
1829 BPF_ALU64_IMM(BPF_MOV
, R5
, 0),
1830 BPF_ALU64_IMM(BPF_MOV
, R6
, 0),
1831 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
1832 BPF_ALU64_IMM(BPF_MOV
, R8
, 0),
1833 BPF_ALU64_IMM(BPF_MOV
, R9
, 0),
1834 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1835 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1836 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1837 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1838 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1839 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1840 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1841 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1842 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1843 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1844 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1851 { /* Mainly checking JIT here. */
1854 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1855 BPF_MOV64_REG(R1
, R0
),
1856 BPF_MOV64_REG(R2
, R1
),
1857 BPF_MOV64_REG(R3
, R2
),
1858 BPF_MOV64_REG(R4
, R3
),
1859 BPF_MOV64_REG(R5
, R4
),
1860 BPF_MOV64_REG(R6
, R5
),
1861 BPF_MOV64_REG(R7
, R6
),
1862 BPF_MOV64_REG(R8
, R7
),
1863 BPF_MOV64_REG(R9
, R8
),
1864 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
1865 BPF_ALU32_IMM(BPF_MOV
, R1
, 0),
1866 BPF_ALU32_IMM(BPF_MOV
, R2
, 0),
1867 BPF_ALU32_IMM(BPF_MOV
, R3
, 0),
1868 BPF_ALU32_IMM(BPF_MOV
, R4
, 0),
1869 BPF_ALU32_IMM(BPF_MOV
, R5
, 0),
1870 BPF_ALU32_IMM(BPF_MOV
, R6
, 0),
1871 BPF_ALU32_IMM(BPF_MOV
, R7
, 0),
1872 BPF_ALU32_IMM(BPF_MOV
, R8
, 0),
1873 BPF_ALU32_IMM(BPF_MOV
, R9
, 0),
1874 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1875 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1876 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1877 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1878 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1879 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1880 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1881 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1882 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1883 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1884 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1891 { /* Mainly checking JIT here. */
1894 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1895 BPF_MOV64_REG(R1
, R0
),
1896 BPF_MOV64_REG(R2
, R1
),
1897 BPF_MOV64_REG(R3
, R2
),
1898 BPF_MOV64_REG(R4
, R3
),
1899 BPF_MOV64_REG(R5
, R4
),
1900 BPF_MOV64_REG(R6
, R5
),
1901 BPF_MOV64_REG(R7
, R6
),
1902 BPF_MOV64_REG(R8
, R7
),
1903 BPF_MOV64_REG(R9
, R8
),
1904 BPF_LD_IMM64(R0
, 0x0LL
),
1905 BPF_LD_IMM64(R1
, 0x0LL
),
1906 BPF_LD_IMM64(R2
, 0x0LL
),
1907 BPF_LD_IMM64(R3
, 0x0LL
),
1908 BPF_LD_IMM64(R4
, 0x0LL
),
1909 BPF_LD_IMM64(R5
, 0x0LL
),
1910 BPF_LD_IMM64(R6
, 0x0LL
),
1911 BPF_LD_IMM64(R7
, 0x0LL
),
1912 BPF_LD_IMM64(R8
, 0x0LL
),
1913 BPF_LD_IMM64(R9
, 0x0LL
),
1914 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1915 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1916 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1917 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1918 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1919 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1920 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1921 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1922 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1923 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1924 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1934 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1935 BPF_ALU64_IMM(BPF_ADD
, R0
, -1),
1936 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1937 BPF_ALU64_IMM(BPF_XOR
, R2
, 3),
1938 BPF_ALU64_REG(BPF_DIV
, R0
, R2
),
1939 BPF_JMP_IMM(BPF_JEQ
, R0
, 10, 1),
1941 BPF_ALU64_IMM(BPF_MOD
, R0
, 3),
1942 BPF_JMP_IMM(BPF_JEQ
, R0
, 1, 1),
1944 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1952 "INT: shifts by register",
1954 BPF_MOV64_IMM(R0
, -1234),
1955 BPF_MOV64_IMM(R1
, 1),
1956 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
1957 BPF_JMP_IMM(BPF_JEQ
, R0
, 0x7ffffd97, 1),
1959 BPF_MOV64_IMM(R2
, 1),
1960 BPF_ALU64_REG(BPF_LSH
, R0
, R2
),
1961 BPF_MOV32_IMM(R4
, -1234),
1962 BPF_JMP_REG(BPF_JEQ
, R0
, R4
, 1),
1964 BPF_ALU64_IMM(BPF_AND
, R4
, 63),
1965 BPF_ALU64_REG(BPF_LSH
, R0
, R4
), /* R0 <= 46 */
1966 BPF_MOV64_IMM(R3
, 47),
1967 BPF_ALU64_REG(BPF_ARSH
, R0
, R3
),
1968 BPF_JMP_IMM(BPF_JEQ
, R0
, -617, 1),
1970 BPF_MOV64_IMM(R2
, 1),
1971 BPF_ALU64_REG(BPF_LSH
, R4
, R2
), /* R4 = 46 << 1 */
1972 BPF_JMP_IMM(BPF_JEQ
, R4
, 92, 1),
1974 BPF_MOV64_IMM(R4
, 4),
1975 BPF_ALU64_REG(BPF_LSH
, R4
, R4
), /* R4 = 4 << 4 */
1976 BPF_JMP_IMM(BPF_JEQ
, R4
, 64, 1),
1978 BPF_MOV64_IMM(R4
, 5),
1979 BPF_ALU32_REG(BPF_LSH
, R4
, R4
), /* R4 = 5 << 5 */
1980 BPF_JMP_IMM(BPF_JEQ
, R4
, 160, 1),
1982 BPF_MOV64_IMM(R0
, -1),
1992 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
1993 BPF_LD_ABS(BPF_B
, 3),
1994 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1995 BPF_ALU32_REG(BPF_DIV
, R0
, R2
),
1996 BPF_ALU64_REG(BPF_MOV
, R8
, R0
),
1997 BPF_LD_ABS(BPF_B
, 4),
1998 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1999 BPF_LD_IND(BPF_B
, R8
, -70),
2003 { 10, 20, 30, 40, 50 },
2004 { { 4, 0 }, { 5, 10 } }
2007 /* This one doesn't go through verifier, but is just raw insn
2008 * as opposed to cBPF tests from here. Thus div by 0 tests are
2009 * done in test_verifier in BPF kselftests.
2013 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
2014 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
2015 BPF_LD_ABS(BPF_B
, 3),
2016 BPF_ALU32_REG(BPF_DIV
, R0
, R7
),
2020 { 10, 20, 30, 40, 50 },
2021 { { 3, 0 }, { 4, 0 } }
2024 "check: missing ret",
2026 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
2028 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2031 .fill_helper
= NULL
,
2032 .expected_errcode
= -EINVAL
,
2037 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0),
2038 BPF_STMT(BPF_RET
| BPF_K
, 0)
2040 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2043 .fill_helper
= NULL
,
2044 .expected_errcode
= -EINVAL
,
2047 "check: unknown insn",
2049 /* seccomp insn, rejected in socket filter */
2050 BPF_STMT(BPF_LDX
| BPF_W
| BPF_ABS
, 0),
2051 BPF_STMT(BPF_RET
| BPF_K
, 0)
2053 CLASSIC
| FLAG_EXPECTED_FAIL
,
2056 .fill_helper
= NULL
,
2057 .expected_errcode
= -EINVAL
,
2060 "check: out of range spill/fill",
2062 BPF_STMT(BPF_STX
, 16),
2063 BPF_STMT(BPF_RET
| BPF_K
, 0)
2065 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2068 .fill_helper
= NULL
,
2069 .expected_errcode
= -EINVAL
,
2074 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2075 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 15),
2076 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
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_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 3, 4),
2090 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2091 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 1, 2),
2092 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2093 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2094 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2095 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
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_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 2, 3),
2109 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 1, 2),
2110 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2111 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2112 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2113 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
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_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 2, 3),
2127 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 1, 2),
2128 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2129 BPF_STMT(BPF_RET
| BPF_A
, 0),
2130 BPF_STMT(BPF_RET
| BPF_A
, 0),
2133 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2134 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2136 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2137 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2138 0xc0, 0xa8, 0x33, 0x01,
2139 0xc0, 0xa8, 0x33, 0x02,
2142 0x00, 0x14, 0x00, 0x00,
2143 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
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 },
2156 BPF_STMT(BPF_RET
| BPF_X
, 0),
2158 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2161 .fill_helper
= NULL
,
2162 .expected_errcode
= -EINVAL
,
2165 "check: LDX + RET X",
2167 BPF_STMT(BPF_LDX
| BPF_IMM
, 42),
2168 BPF_STMT(BPF_RET
| BPF_X
, 0),
2170 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2173 .fill_helper
= NULL
,
2174 .expected_errcode
= -EINVAL
,
2176 { /* Mainly checking JIT here. */
2177 "M[]: alt STX + LDX",
2179 BPF_STMT(BPF_LDX
| BPF_IMM
, 100),
2180 BPF_STMT(BPF_STX
, 0),
2181 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2182 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2183 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2184 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2185 BPF_STMT(BPF_STX
, 1),
2186 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2187 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2188 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2189 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2190 BPF_STMT(BPF_STX
, 2),
2191 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2192 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2193 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2194 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2195 BPF_STMT(BPF_STX
, 3),
2196 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2197 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2198 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2199 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2200 BPF_STMT(BPF_STX
, 4),
2201 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2202 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2203 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2204 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2205 BPF_STMT(BPF_STX
, 5),
2206 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2207 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2208 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2209 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2210 BPF_STMT(BPF_STX
, 6),
2211 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2212 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2213 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2214 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2215 BPF_STMT(BPF_STX
, 7),
2216 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2217 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2218 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2219 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2220 BPF_STMT(BPF_STX
, 8),
2221 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2222 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2223 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2224 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2225 BPF_STMT(BPF_STX
, 9),
2226 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2227 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2228 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2229 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2230 BPF_STMT(BPF_STX
, 10),
2231 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2232 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2233 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2234 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2235 BPF_STMT(BPF_STX
, 11),
2236 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2237 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2238 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2239 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2240 BPF_STMT(BPF_STX
, 12),
2241 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2242 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2243 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2244 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2245 BPF_STMT(BPF_STX
, 13),
2246 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2247 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2248 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2249 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2250 BPF_STMT(BPF_STX
, 14),
2251 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2252 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2253 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2254 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2255 BPF_STMT(BPF_STX
, 15),
2256 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2257 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2258 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2259 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2260 BPF_STMT(BPF_RET
| BPF_A
, 0),
2262 CLASSIC
| FLAG_NO_DATA
,
2266 { /* Mainly checking JIT here. */
2267 "M[]: full STX + full LDX",
2269 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbadfeedb),
2270 BPF_STMT(BPF_STX
, 0),
2271 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xecabedae),
2272 BPF_STMT(BPF_STX
, 1),
2273 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xafccfeaf),
2274 BPF_STMT(BPF_STX
, 2),
2275 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbffdcedc),
2276 BPF_STMT(BPF_STX
, 3),
2277 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbbbdccb),
2278 BPF_STMT(BPF_STX
, 4),
2279 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbabcbda),
2280 BPF_STMT(BPF_STX
, 5),
2281 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaedecbdb),
2282 BPF_STMT(BPF_STX
, 6),
2283 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xadebbade),
2284 BPF_STMT(BPF_STX
, 7),
2285 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfcfcfaec),
2286 BPF_STMT(BPF_STX
, 8),
2287 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbcdddbdc),
2288 BPF_STMT(BPF_STX
, 9),
2289 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfeefdfac),
2290 BPF_STMT(BPF_STX
, 10),
2291 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xcddcdeea),
2292 BPF_STMT(BPF_STX
, 11),
2293 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaccfaebb),
2294 BPF_STMT(BPF_STX
, 12),
2295 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbdcccdcf),
2296 BPF_STMT(BPF_STX
, 13),
2297 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaaedecde),
2298 BPF_STMT(BPF_STX
, 14),
2299 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfaeacdad),
2300 BPF_STMT(BPF_STX
, 15),
2301 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2302 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2303 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2304 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2305 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2306 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2307 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2308 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2309 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2310 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2311 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2312 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2313 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2314 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2315 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2316 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2317 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2318 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2319 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2320 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2321 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2322 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2323 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2324 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2325 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2326 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2327 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2328 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2329 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2330 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2331 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2332 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2333 BPF_STMT(BPF_RET
| BPF_A
, 0),
2335 CLASSIC
| FLAG_NO_DATA
,
2337 { { 0, 0x2a5a5e5 } },
2340 "check: SKF_AD_MAX",
2342 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2343 SKF_AD_OFF
+ SKF_AD_MAX
),
2344 BPF_STMT(BPF_RET
| BPF_A
, 0),
2346 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2349 .fill_helper
= NULL
,
2350 .expected_errcode
= -EINVAL
,
2352 { /* Passes checker but fails during runtime. */
2353 "LD [SKF_AD_OFF-1]",
2355 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2357 BPF_STMT(BPF_RET
| BPF_K
, 1),
2364 "load 64-bit immediate",
2366 BPF_LD_IMM64(R1
, 0x567800001234LL
),
2367 BPF_MOV64_REG(R2
, R1
),
2368 BPF_MOV64_REG(R3
, R2
),
2369 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
2370 BPF_ALU64_IMM(BPF_LSH
, R3
, 32),
2371 BPF_ALU64_IMM(BPF_RSH
, R3
, 32),
2372 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
2373 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5678, 1),
2375 BPF_JMP_IMM(BPF_JEQ
, R3
, 0x1234, 1),
2377 BPF_LD_IMM64(R0
, 0x1ffffffffLL
),
2378 BPF_ALU64_IMM(BPF_RSH
, R0
, 32), /* R0 = 1 */
2388 BPF_MOV64_REG(R6
, R1
),
2389 BPF_LD_ABS(BPF_H
, 12),
2390 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 28),
2391 BPF_LD_ABS(BPF_H
, 12),
2392 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 26),
2393 BPF_MOV32_IMM(R0
, 18),
2394 BPF_STX_MEM(BPF_W
, R10
, R0
, -64),
2395 BPF_LDX_MEM(BPF_W
, R7
, R10
, -64),
2396 BPF_LD_IND(BPF_W
, R7
, 14),
2397 BPF_STX_MEM(BPF_W
, R10
, R0
, -60),
2398 BPF_MOV32_IMM(R0
, 280971478),
2399 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2400 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2401 BPF_LDX_MEM(BPF_W
, R0
, R10
, -60),
2402 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2403 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 15),
2404 BPF_LD_ABS(BPF_H
, 12),
2405 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 13),
2406 BPF_MOV32_IMM(R0
, 22),
2407 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2408 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2409 BPF_LD_IND(BPF_H
, R7
, 14),
2410 BPF_STX_MEM(BPF_W
, R10
, R0
, -52),
2411 BPF_MOV32_IMM(R0
, 17366),
2412 BPF_STX_MEM(BPF_W
, R10
, R0
, -48),
2413 BPF_LDX_MEM(BPF_W
, R7
, R10
, -48),
2414 BPF_LDX_MEM(BPF_W
, R0
, R10
, -52),
2415 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2416 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 2),
2417 BPF_MOV32_IMM(R0
, 256),
2419 BPF_MOV32_IMM(R0
, 0),
2423 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2424 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2425 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2429 /* BPF_ALU | BPF_MOV | BPF_X */
2431 "ALU_MOV_X: dst = 2",
2433 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2434 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2442 "ALU_MOV_X: dst = 4294967295",
2444 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2445 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2450 { { 0, 4294967295U } },
2453 "ALU64_MOV_X: dst = 2",
2455 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2456 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2464 "ALU64_MOV_X: dst = 4294967295",
2466 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2467 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2472 { { 0, 4294967295U } },
2474 /* BPF_ALU | BPF_MOV | BPF_K */
2476 "ALU_MOV_K: dst = 2",
2478 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
2486 "ALU_MOV_K: dst = 4294967295",
2488 BPF_ALU32_IMM(BPF_MOV
, R0
, 4294967295U),
2493 { { 0, 4294967295U } },
2496 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2498 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2499 BPF_LD_IMM64(R3
, 0x00000000ffffffffLL
),
2500 BPF_ALU32_IMM(BPF_MOV
, R2
, 0xffffffff),
2501 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2502 BPF_MOV32_IMM(R0
, 2),
2504 BPF_MOV32_IMM(R0
, 1),
2512 "ALU64_MOV_K: dst = 2",
2514 BPF_ALU64_IMM(BPF_MOV
, R0
, 2),
2522 "ALU64_MOV_K: dst = 2147483647",
2524 BPF_ALU64_IMM(BPF_MOV
, R0
, 2147483647),
2529 { { 0, 2147483647 } },
2532 "ALU64_OR_K: dst = 0x0",
2534 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2535 BPF_LD_IMM64(R3
, 0x0),
2536 BPF_ALU64_IMM(BPF_MOV
, R2
, 0x0),
2537 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2538 BPF_MOV32_IMM(R0
, 2),
2540 BPF_MOV32_IMM(R0
, 1),
2548 "ALU64_MOV_K: dst = -1",
2550 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2551 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2552 BPF_ALU64_IMM(BPF_MOV
, R2
, 0xffffffff),
2553 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2554 BPF_MOV32_IMM(R0
, 2),
2556 BPF_MOV32_IMM(R0
, 1),
2563 /* BPF_ALU | BPF_ADD | BPF_X */
2565 "ALU_ADD_X: 1 + 2 = 3",
2567 BPF_LD_IMM64(R0
, 1),
2568 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2569 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2577 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2579 BPF_LD_IMM64(R0
, 1),
2580 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2581 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2586 { { 0, 4294967295U } },
2589 "ALU_ADD_X: 2 + 4294967294 = 0",
2591 BPF_LD_IMM64(R0
, 2),
2592 BPF_LD_IMM64(R1
, 4294967294U),
2593 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2594 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2595 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2597 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2605 "ALU64_ADD_X: 1 + 2 = 3",
2607 BPF_LD_IMM64(R0
, 1),
2608 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2609 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2617 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2619 BPF_LD_IMM64(R0
, 1),
2620 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2621 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2626 { { 0, 4294967295U } },
2629 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2631 BPF_LD_IMM64(R0
, 2),
2632 BPF_LD_IMM64(R1
, 4294967294U),
2633 BPF_LD_IMM64(R2
, 4294967296ULL),
2634 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2635 BPF_JMP_REG(BPF_JEQ
, R0
, R2
, 2),
2636 BPF_MOV32_IMM(R0
, 0),
2638 BPF_MOV32_IMM(R0
, 1),
2645 /* BPF_ALU | BPF_ADD | BPF_K */
2647 "ALU_ADD_K: 1 + 2 = 3",
2649 BPF_LD_IMM64(R0
, 1),
2650 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2658 "ALU_ADD_K: 3 + 0 = 3",
2660 BPF_LD_IMM64(R0
, 3),
2661 BPF_ALU32_IMM(BPF_ADD
, R0
, 0),
2669 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2671 BPF_LD_IMM64(R0
, 1),
2672 BPF_ALU32_IMM(BPF_ADD
, R0
, 4294967294U),
2677 { { 0, 4294967295U } },
2680 "ALU_ADD_K: 4294967294 + 2 = 0",
2682 BPF_LD_IMM64(R0
, 4294967294U),
2683 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2684 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2685 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2687 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2695 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2697 BPF_LD_IMM64(R2
, 0x0),
2698 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
2699 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffffffff),
2700 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2701 BPF_MOV32_IMM(R0
, 2),
2703 BPF_MOV32_IMM(R0
, 1),
2711 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2713 BPF_LD_IMM64(R2
, 0x0),
2714 BPF_LD_IMM64(R3
, 0xffff),
2715 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffff),
2716 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2717 BPF_MOV32_IMM(R0
, 2),
2719 BPF_MOV32_IMM(R0
, 1),
2727 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2729 BPF_LD_IMM64(R2
, 0x0),
2730 BPF_LD_IMM64(R3
, 0x7fffffff),
2731 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x7fffffff),
2732 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2733 BPF_MOV32_IMM(R0
, 2),
2735 BPF_MOV32_IMM(R0
, 1),
2743 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2745 BPF_LD_IMM64(R2
, 0x0),
2746 BPF_LD_IMM64(R3
, 0x80000000),
2747 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80000000),
2748 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2749 BPF_MOV32_IMM(R0
, 2),
2751 BPF_MOV32_IMM(R0
, 1),
2759 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2761 BPF_LD_IMM64(R2
, 0x0),
2762 BPF_LD_IMM64(R3
, 0x80008000),
2763 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80008000),
2764 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2765 BPF_MOV32_IMM(R0
, 2),
2767 BPF_MOV32_IMM(R0
, 1),
2775 "ALU64_ADD_K: 1 + 2 = 3",
2777 BPF_LD_IMM64(R0
, 1),
2778 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2786 "ALU64_ADD_K: 3 + 0 = 3",
2788 BPF_LD_IMM64(R0
, 3),
2789 BPF_ALU64_IMM(BPF_ADD
, R0
, 0),
2797 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2799 BPF_LD_IMM64(R0
, 1),
2800 BPF_ALU64_IMM(BPF_ADD
, R0
, 2147483646),
2805 { { 0, 2147483647 } },
2808 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2810 BPF_LD_IMM64(R0
, 4294967294U),
2811 BPF_LD_IMM64(R1
, 4294967296ULL),
2812 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2813 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 2),
2814 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2816 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2824 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2826 BPF_LD_IMM64(R0
, 2147483646),
2827 BPF_ALU64_IMM(BPF_ADD
, R0
, -2147483647),
2835 "ALU64_ADD_K: 1 + 0 = 1",
2837 BPF_LD_IMM64(R2
, 0x1),
2838 BPF_LD_IMM64(R3
, 0x1),
2839 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x0),
2840 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2841 BPF_MOV32_IMM(R0
, 2),
2843 BPF_MOV32_IMM(R0
, 1),
2851 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2853 BPF_LD_IMM64(R2
, 0x0),
2854 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2855 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffffffff),
2856 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2857 BPF_MOV32_IMM(R0
, 2),
2859 BPF_MOV32_IMM(R0
, 1),
2867 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2869 BPF_LD_IMM64(R2
, 0x0),
2870 BPF_LD_IMM64(R3
, 0xffff),
2871 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffff),
2872 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2873 BPF_MOV32_IMM(R0
, 2),
2875 BPF_MOV32_IMM(R0
, 1),
2883 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2885 BPF_LD_IMM64(R2
, 0x0),
2886 BPF_LD_IMM64(R3
, 0x7fffffff),
2887 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x7fffffff),
2888 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2889 BPF_MOV32_IMM(R0
, 2),
2891 BPF_MOV32_IMM(R0
, 1),
2899 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2901 BPF_LD_IMM64(R2
, 0x0),
2902 BPF_LD_IMM64(R3
, 0xffffffff80000000LL
),
2903 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80000000),
2904 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2905 BPF_MOV32_IMM(R0
, 2),
2907 BPF_MOV32_IMM(R0
, 1),
2915 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2917 BPF_LD_IMM64(R2
, 0x0),
2918 BPF_LD_IMM64(R3
, 0xffffffff80008000LL
),
2919 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80008000),
2920 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2921 BPF_MOV32_IMM(R0
, 2),
2923 BPF_MOV32_IMM(R0
, 1),
2930 /* BPF_ALU | BPF_SUB | BPF_X */
2932 "ALU_SUB_X: 3 - 1 = 2",
2934 BPF_LD_IMM64(R0
, 3),
2935 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2936 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2944 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2946 BPF_LD_IMM64(R0
, 4294967295U),
2947 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2948 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2956 "ALU64_SUB_X: 3 - 1 = 2",
2958 BPF_LD_IMM64(R0
, 3),
2959 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2960 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2968 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2970 BPF_LD_IMM64(R0
, 4294967295U),
2971 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2972 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2979 /* BPF_ALU | BPF_SUB | BPF_K */
2981 "ALU_SUB_K: 3 - 1 = 2",
2983 BPF_LD_IMM64(R0
, 3),
2984 BPF_ALU32_IMM(BPF_SUB
, R0
, 1),
2992 "ALU_SUB_K: 3 - 0 = 3",
2994 BPF_LD_IMM64(R0
, 3),
2995 BPF_ALU32_IMM(BPF_SUB
, R0
, 0),
3003 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
3005 BPF_LD_IMM64(R0
, 4294967295U),
3006 BPF_ALU32_IMM(BPF_SUB
, R0
, 4294967294U),
3014 "ALU64_SUB_K: 3 - 1 = 2",
3016 BPF_LD_IMM64(R0
, 3),
3017 BPF_ALU64_IMM(BPF_SUB
, R0
, 1),
3025 "ALU64_SUB_K: 3 - 0 = 3",
3027 BPF_LD_IMM64(R0
, 3),
3028 BPF_ALU64_IMM(BPF_SUB
, R0
, 0),
3036 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3038 BPF_LD_IMM64(R0
, 4294967294U),
3039 BPF_ALU64_IMM(BPF_SUB
, R0
, 4294967295U),
3047 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3049 BPF_LD_IMM64(R0
, 2147483646),
3050 BPF_ALU64_IMM(BPF_SUB
, R0
, 2147483647),
3057 /* BPF_ALU | BPF_MUL | BPF_X */
3059 "ALU_MUL_X: 2 * 3 = 6",
3061 BPF_LD_IMM64(R0
, 2),
3062 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3063 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3071 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3073 BPF_LD_IMM64(R0
, 2),
3074 BPF_ALU32_IMM(BPF_MOV
, R1
, 0x7FFFFFF8),
3075 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3080 { { 0, 0xFFFFFFF0 } },
3083 "ALU_MUL_X: -1 * -1 = 1",
3085 BPF_LD_IMM64(R0
, -1),
3086 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
3087 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3095 "ALU64_MUL_X: 2 * 3 = 6",
3097 BPF_LD_IMM64(R0
, 2),
3098 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3099 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3107 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3109 BPF_LD_IMM64(R0
, 1),
3110 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3111 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3116 { { 0, 2147483647 } },
3118 /* BPF_ALU | BPF_MUL | BPF_K */
3120 "ALU_MUL_K: 2 * 3 = 6",
3122 BPF_LD_IMM64(R0
, 2),
3123 BPF_ALU32_IMM(BPF_MUL
, R0
, 3),
3131 "ALU_MUL_K: 3 * 1 = 3",
3133 BPF_LD_IMM64(R0
, 3),
3134 BPF_ALU32_IMM(BPF_MUL
, R0
, 1),
3142 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3144 BPF_LD_IMM64(R0
, 2),
3145 BPF_ALU32_IMM(BPF_MUL
, R0
, 0x7FFFFFF8),
3150 { { 0, 0xFFFFFFF0 } },
3153 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3155 BPF_LD_IMM64(R2
, 0x1),
3156 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
3157 BPF_ALU32_IMM(BPF_MUL
, R2
, 0xffffffff),
3158 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3159 BPF_MOV32_IMM(R0
, 2),
3161 BPF_MOV32_IMM(R0
, 1),
3169 "ALU64_MUL_K: 2 * 3 = 6",
3171 BPF_LD_IMM64(R0
, 2),
3172 BPF_ALU64_IMM(BPF_MUL
, R0
, 3),
3180 "ALU64_MUL_K: 3 * 1 = 3",
3182 BPF_LD_IMM64(R0
, 3),
3183 BPF_ALU64_IMM(BPF_MUL
, R0
, 1),
3191 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3193 BPF_LD_IMM64(R0
, 1),
3194 BPF_ALU64_IMM(BPF_MUL
, R0
, 2147483647),
3199 { { 0, 2147483647 } },
3202 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3204 BPF_LD_IMM64(R0
, 1),
3205 BPF_ALU64_IMM(BPF_MUL
, R0
, -2147483647),
3210 { { 0, -2147483647 } },
3213 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3215 BPF_LD_IMM64(R2
, 0x1),
3216 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3217 BPF_ALU64_IMM(BPF_MUL
, R2
, 0xffffffff),
3218 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3219 BPF_MOV32_IMM(R0
, 2),
3221 BPF_MOV32_IMM(R0
, 1),
3228 /* BPF_ALU | BPF_DIV | BPF_X */
3230 "ALU_DIV_X: 6 / 2 = 3",
3232 BPF_LD_IMM64(R0
, 6),
3233 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3234 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3242 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3244 BPF_LD_IMM64(R0
, 4294967295U),
3245 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
3246 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3254 "ALU64_DIV_X: 6 / 2 = 3",
3256 BPF_LD_IMM64(R0
, 6),
3257 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3258 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3266 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3268 BPF_LD_IMM64(R0
, 2147483647),
3269 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3270 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3278 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3280 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3281 BPF_LD_IMM64(R4
, 0xffffffffffffffffLL
),
3282 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3283 BPF_ALU64_REG(BPF_DIV
, R2
, R4
),
3284 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3285 BPF_MOV32_IMM(R0
, 2),
3287 BPF_MOV32_IMM(R0
, 1),
3294 /* BPF_ALU | BPF_DIV | BPF_K */
3296 "ALU_DIV_K: 6 / 2 = 3",
3298 BPF_LD_IMM64(R0
, 6),
3299 BPF_ALU32_IMM(BPF_DIV
, R0
, 2),
3307 "ALU_DIV_K: 3 / 1 = 3",
3309 BPF_LD_IMM64(R0
, 3),
3310 BPF_ALU32_IMM(BPF_DIV
, R0
, 1),
3318 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3320 BPF_LD_IMM64(R0
, 4294967295U),
3321 BPF_ALU32_IMM(BPF_DIV
, R0
, 4294967295U),
3329 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3331 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3332 BPF_LD_IMM64(R3
, 0x1UL
),
3333 BPF_ALU32_IMM(BPF_DIV
, R2
, 0xffffffff),
3334 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3335 BPF_MOV32_IMM(R0
, 2),
3337 BPF_MOV32_IMM(R0
, 1),
3345 "ALU64_DIV_K: 6 / 2 = 3",
3347 BPF_LD_IMM64(R0
, 6),
3348 BPF_ALU64_IMM(BPF_DIV
, R0
, 2),
3356 "ALU64_DIV_K: 3 / 1 = 3",
3358 BPF_LD_IMM64(R0
, 3),
3359 BPF_ALU64_IMM(BPF_DIV
, R0
, 1),
3367 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3369 BPF_LD_IMM64(R0
, 2147483647),
3370 BPF_ALU64_IMM(BPF_DIV
, R0
, 2147483647),
3378 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3380 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3381 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3382 BPF_ALU64_IMM(BPF_DIV
, R2
, 0xffffffff),
3383 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3384 BPF_MOV32_IMM(R0
, 2),
3386 BPF_MOV32_IMM(R0
, 1),
3393 /* BPF_ALU | BPF_MOD | BPF_X */
3395 "ALU_MOD_X: 3 % 2 = 1",
3397 BPF_LD_IMM64(R0
, 3),
3398 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3399 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3407 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3409 BPF_LD_IMM64(R0
, 4294967295U),
3410 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967293U),
3411 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3419 "ALU64_MOD_X: 3 % 2 = 1",
3421 BPF_LD_IMM64(R0
, 3),
3422 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3423 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3431 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3433 BPF_LD_IMM64(R0
, 2147483647),
3434 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483645),
3435 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3442 /* BPF_ALU | BPF_MOD | BPF_K */
3444 "ALU_MOD_K: 3 % 2 = 1",
3446 BPF_LD_IMM64(R0
, 3),
3447 BPF_ALU32_IMM(BPF_MOD
, R0
, 2),
3455 "ALU_MOD_K: 3 % 1 = 0",
3457 BPF_LD_IMM64(R0
, 3),
3458 BPF_ALU32_IMM(BPF_MOD
, R0
, 1),
3466 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3468 BPF_LD_IMM64(R0
, 4294967295U),
3469 BPF_ALU32_IMM(BPF_MOD
, R0
, 4294967293U),
3477 "ALU64_MOD_K: 3 % 2 = 1",
3479 BPF_LD_IMM64(R0
, 3),
3480 BPF_ALU64_IMM(BPF_MOD
, R0
, 2),
3488 "ALU64_MOD_K: 3 % 1 = 0",
3490 BPF_LD_IMM64(R0
, 3),
3491 BPF_ALU64_IMM(BPF_MOD
, R0
, 1),
3499 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3501 BPF_LD_IMM64(R0
, 2147483647),
3502 BPF_ALU64_IMM(BPF_MOD
, R0
, 2147483645),
3509 /* BPF_ALU | BPF_AND | BPF_X */
3511 "ALU_AND_X: 3 & 2 = 2",
3513 BPF_LD_IMM64(R0
, 3),
3514 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3515 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3523 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3525 BPF_LD_IMM64(R0
, 0xffffffff),
3526 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3527 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3532 { { 0, 0xffffffff } },
3535 "ALU64_AND_X: 3 & 2 = 2",
3537 BPF_LD_IMM64(R0
, 3),
3538 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3539 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3547 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3549 BPF_LD_IMM64(R0
, 0xffffffff),
3550 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3551 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3556 { { 0, 0xffffffff } },
3558 /* BPF_ALU | BPF_AND | BPF_K */
3560 "ALU_AND_K: 3 & 2 = 2",
3562 BPF_LD_IMM64(R0
, 3),
3563 BPF_ALU32_IMM(BPF_AND
, R0
, 2),
3571 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3573 BPF_LD_IMM64(R0
, 0xffffffff),
3574 BPF_ALU32_IMM(BPF_AND
, R0
, 0xffffffff),
3579 { { 0, 0xffffffff } },
3582 "ALU64_AND_K: 3 & 2 = 2",
3584 BPF_LD_IMM64(R0
, 3),
3585 BPF_ALU64_IMM(BPF_AND
, R0
, 2),
3593 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3595 BPF_LD_IMM64(R0
, 0xffffffff),
3596 BPF_ALU64_IMM(BPF_AND
, R0
, 0xffffffff),
3601 { { 0, 0xffffffff } },
3604 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3606 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3607 BPF_LD_IMM64(R3
, 0x0000000000000000LL
),
3608 BPF_ALU64_IMM(BPF_AND
, R2
, 0x0),
3609 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3610 BPF_MOV32_IMM(R0
, 2),
3612 BPF_MOV32_IMM(R0
, 1),
3620 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3622 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3623 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3624 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3625 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3626 BPF_MOV32_IMM(R0
, 2),
3628 BPF_MOV32_IMM(R0
, 1),
3636 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3638 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3639 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3640 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3641 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3642 BPF_MOV32_IMM(R0
, 2),
3644 BPF_MOV32_IMM(R0
, 1),
3651 /* BPF_ALU | BPF_OR | BPF_X */
3653 "ALU_OR_X: 1 | 2 = 3",
3655 BPF_LD_IMM64(R0
, 1),
3656 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3657 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3665 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3667 BPF_LD_IMM64(R0
, 0),
3668 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3669 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3674 { { 0, 0xffffffff } },
3677 "ALU64_OR_X: 1 | 2 = 3",
3679 BPF_LD_IMM64(R0
, 1),
3680 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3681 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3689 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3691 BPF_LD_IMM64(R0
, 0),
3692 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3693 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3698 { { 0, 0xffffffff } },
3700 /* BPF_ALU | BPF_OR | BPF_K */
3702 "ALU_OR_K: 1 | 2 = 3",
3704 BPF_LD_IMM64(R0
, 1),
3705 BPF_ALU32_IMM(BPF_OR
, R0
, 2),
3713 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3715 BPF_LD_IMM64(R0
, 0),
3716 BPF_ALU32_IMM(BPF_OR
, R0
, 0xffffffff),
3721 { { 0, 0xffffffff } },
3724 "ALU64_OR_K: 1 | 2 = 3",
3726 BPF_LD_IMM64(R0
, 1),
3727 BPF_ALU64_IMM(BPF_OR
, R0
, 2),
3735 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3737 BPF_LD_IMM64(R0
, 0),
3738 BPF_ALU64_IMM(BPF_OR
, R0
, 0xffffffff),
3743 { { 0, 0xffffffff } },
3746 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3748 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3749 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3750 BPF_ALU64_IMM(BPF_OR
, R2
, 0x0),
3751 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3752 BPF_MOV32_IMM(R0
, 2),
3754 BPF_MOV32_IMM(R0
, 1),
3762 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3764 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3765 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3766 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3767 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3768 BPF_MOV32_IMM(R0
, 2),
3770 BPF_MOV32_IMM(R0
, 1),
3778 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3780 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3781 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3782 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3783 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3784 BPF_MOV32_IMM(R0
, 2),
3786 BPF_MOV32_IMM(R0
, 1),
3793 /* BPF_ALU | BPF_XOR | BPF_X */
3795 "ALU_XOR_X: 5 ^ 6 = 3",
3797 BPF_LD_IMM64(R0
, 5),
3798 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3799 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3807 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3809 BPF_LD_IMM64(R0
, 1),
3810 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3811 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3816 { { 0, 0xfffffffe } },
3819 "ALU64_XOR_X: 5 ^ 6 = 3",
3821 BPF_LD_IMM64(R0
, 5),
3822 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3823 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3831 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3833 BPF_LD_IMM64(R0
, 1),
3834 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3835 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3840 { { 0, 0xfffffffe } },
3842 /* BPF_ALU | BPF_XOR | BPF_K */
3844 "ALU_XOR_K: 5 ^ 6 = 3",
3846 BPF_LD_IMM64(R0
, 5),
3847 BPF_ALU32_IMM(BPF_XOR
, R0
, 6),
3855 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3857 BPF_LD_IMM64(R0
, 1),
3858 BPF_ALU32_IMM(BPF_XOR
, R0
, 0xffffffff),
3863 { { 0, 0xfffffffe } },
3866 "ALU64_XOR_K: 5 ^ 6 = 3",
3868 BPF_LD_IMM64(R0
, 5),
3869 BPF_ALU64_IMM(BPF_XOR
, R0
, 6),
3877 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3879 BPF_LD_IMM64(R0
, 1),
3880 BPF_ALU64_IMM(BPF_XOR
, R0
, 0xffffffff),
3885 { { 0, 0xfffffffe } },
3888 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3890 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3891 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3892 BPF_ALU64_IMM(BPF_XOR
, R2
, 0x0),
3893 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3894 BPF_MOV32_IMM(R0
, 2),
3896 BPF_MOV32_IMM(R0
, 1),
3904 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3906 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3907 BPF_LD_IMM64(R3
, 0xffff00000000ffffLL
),
3908 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3909 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3910 BPF_MOV32_IMM(R0
, 2),
3912 BPF_MOV32_IMM(R0
, 1),
3920 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3922 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3923 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3924 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3925 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3926 BPF_MOV32_IMM(R0
, 2),
3928 BPF_MOV32_IMM(R0
, 1),
3935 /* BPF_ALU | BPF_LSH | BPF_X */
3937 "ALU_LSH_X: 1 << 1 = 2",
3939 BPF_LD_IMM64(R0
, 1),
3940 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3941 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3949 "ALU_LSH_X: 1 << 31 = 0x80000000",
3951 BPF_LD_IMM64(R0
, 1),
3952 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3953 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3958 { { 0, 0x80000000 } },
3961 "ALU64_LSH_X: 1 << 1 = 2",
3963 BPF_LD_IMM64(R0
, 1),
3964 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3965 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3973 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3975 BPF_LD_IMM64(R0
, 1),
3976 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3977 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3982 { { 0, 0x80000000 } },
3984 /* BPF_ALU | BPF_LSH | BPF_K */
3986 "ALU_LSH_K: 1 << 1 = 2",
3988 BPF_LD_IMM64(R0
, 1),
3989 BPF_ALU32_IMM(BPF_LSH
, R0
, 1),
3997 "ALU_LSH_K: 1 << 31 = 0x80000000",
3999 BPF_LD_IMM64(R0
, 1),
4000 BPF_ALU32_IMM(BPF_LSH
, R0
, 31),
4005 { { 0, 0x80000000 } },
4008 "ALU64_LSH_K: 1 << 1 = 2",
4010 BPF_LD_IMM64(R0
, 1),
4011 BPF_ALU64_IMM(BPF_LSH
, R0
, 1),
4019 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4021 BPF_LD_IMM64(R0
, 1),
4022 BPF_ALU64_IMM(BPF_LSH
, R0
, 31),
4027 { { 0, 0x80000000 } },
4029 /* BPF_ALU | BPF_RSH | BPF_X */
4031 "ALU_RSH_X: 2 >> 1 = 1",
4033 BPF_LD_IMM64(R0
, 2),
4034 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4035 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4043 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4045 BPF_LD_IMM64(R0
, 0x80000000),
4046 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4047 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4055 "ALU64_RSH_X: 2 >> 1 = 1",
4057 BPF_LD_IMM64(R0
, 2),
4058 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4059 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4067 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4069 BPF_LD_IMM64(R0
, 0x80000000),
4070 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4071 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4078 /* BPF_ALU | BPF_RSH | BPF_K */
4080 "ALU_RSH_K: 2 >> 1 = 1",
4082 BPF_LD_IMM64(R0
, 2),
4083 BPF_ALU32_IMM(BPF_RSH
, R0
, 1),
4091 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4093 BPF_LD_IMM64(R0
, 0x80000000),
4094 BPF_ALU32_IMM(BPF_RSH
, R0
, 31),
4102 "ALU64_RSH_K: 2 >> 1 = 1",
4104 BPF_LD_IMM64(R0
, 2),
4105 BPF_ALU64_IMM(BPF_RSH
, R0
, 1),
4113 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4115 BPF_LD_IMM64(R0
, 0x80000000),
4116 BPF_ALU64_IMM(BPF_RSH
, R0
, 31),
4123 /* BPF_ALU | BPF_ARSH | BPF_X */
4125 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4127 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4128 BPF_ALU32_IMM(BPF_MOV
, R1
, 40),
4129 BPF_ALU64_REG(BPF_ARSH
, R0
, R1
),
4134 { { 0, 0xffff00ff } },
4136 /* BPF_ALU | BPF_ARSH | BPF_K */
4138 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4140 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4141 BPF_ALU64_IMM(BPF_ARSH
, R0
, 40),
4146 { { 0, 0xffff00ff } },
4148 /* BPF_ALU | BPF_NEG */
4150 "ALU_NEG: -(3) = -3",
4152 BPF_ALU32_IMM(BPF_MOV
, R0
, 3),
4153 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4161 "ALU_NEG: -(-3) = 3",
4163 BPF_ALU32_IMM(BPF_MOV
, R0
, -3),
4164 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4172 "ALU64_NEG: -(3) = -3",
4174 BPF_LD_IMM64(R0
, 3),
4175 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4183 "ALU64_NEG: -(-3) = 3",
4185 BPF_LD_IMM64(R0
, -3),
4186 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4193 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4195 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4197 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4198 BPF_ENDIAN(BPF_FROM_BE
, R0
, 16),
4203 { { 0, cpu_to_be16(0xcdef) } },
4206 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4208 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4209 BPF_ENDIAN(BPF_FROM_BE
, R0
, 32),
4210 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4211 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4212 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4217 { { 0, cpu_to_be32(0x89abcdef) } },
4220 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4222 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4223 BPF_ENDIAN(BPF_FROM_BE
, R0
, 64),
4228 { { 0, (u32
) cpu_to_be64(0x0123456789abcdefLL
) } },
4230 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4232 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4234 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4235 BPF_ENDIAN(BPF_FROM_LE
, R0
, 16),
4240 { { 0, cpu_to_le16(0xcdef) } },
4243 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4245 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4246 BPF_ENDIAN(BPF_FROM_LE
, R0
, 32),
4247 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4248 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4249 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4254 { { 0, cpu_to_le32(0x89abcdef) } },
4257 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4259 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4260 BPF_ENDIAN(BPF_FROM_LE
, R0
, 64),
4265 { { 0, (u32
) cpu_to_le64(0x0123456789abcdefLL
) } },
4267 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4269 "ST_MEM_B: Store/Load byte: max negative",
4271 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4272 BPF_ST_MEM(BPF_B
, R10
, -40, 0xff),
4273 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4282 "ST_MEM_B: Store/Load byte: max positive",
4284 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4285 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7f),
4286 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4295 "STX_MEM_B: Store/Load byte: max negative",
4297 BPF_LD_IMM64(R0
, 0),
4298 BPF_LD_IMM64(R1
, 0xffLL
),
4299 BPF_STX_MEM(BPF_B
, R10
, R1
, -40),
4300 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4309 "ST_MEM_H: Store/Load half word: max negative",
4311 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4312 BPF_ST_MEM(BPF_H
, R10
, -40, 0xffff),
4313 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4322 "ST_MEM_H: Store/Load half word: max positive",
4324 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4325 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7fff),
4326 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4335 "STX_MEM_H: Store/Load half word: max negative",
4337 BPF_LD_IMM64(R0
, 0),
4338 BPF_LD_IMM64(R1
, 0xffffLL
),
4339 BPF_STX_MEM(BPF_H
, R10
, R1
, -40),
4340 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4349 "ST_MEM_W: Store/Load word: max negative",
4351 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4352 BPF_ST_MEM(BPF_W
, R10
, -40, 0xffffffff),
4353 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4358 { { 0, 0xffffffff } },
4362 "ST_MEM_W: Store/Load word: max positive",
4364 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4365 BPF_ST_MEM(BPF_W
, R10
, -40, 0x7fffffff),
4366 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4371 { { 0, 0x7fffffff } },
4375 "STX_MEM_W: Store/Load word: max negative",
4377 BPF_LD_IMM64(R0
, 0),
4378 BPF_LD_IMM64(R1
, 0xffffffffLL
),
4379 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4380 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4385 { { 0, 0xffffffff } },
4389 "ST_MEM_DW: Store/Load double word: max negative",
4391 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4392 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4393 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4398 { { 0, 0xffffffff } },
4402 "ST_MEM_DW: Store/Load double word: max negative 2",
4404 BPF_LD_IMM64(R2
, 0xffff00000000ffffLL
),
4405 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
4406 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4407 BPF_LDX_MEM(BPF_DW
, R2
, R10
, -40),
4408 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
4409 BPF_MOV32_IMM(R0
, 2),
4411 BPF_MOV32_IMM(R0
, 1),
4420 "ST_MEM_DW: Store/Load double word: max positive",
4422 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4423 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x7fffffff),
4424 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4429 { { 0, 0x7fffffff } },
4433 "STX_MEM_DW: Store/Load double word: max negative",
4435 BPF_LD_IMM64(R0
, 0),
4436 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4437 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4438 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4443 { { 0, 0xffffffff } },
4446 /* BPF_STX | BPF_XADD | BPF_W/DW */
4448 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4450 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4451 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4452 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4453 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4462 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4464 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4465 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4466 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4467 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4468 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4469 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4478 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4480 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4481 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4482 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4491 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4496 .fill_helper
= bpf_fill_stxw
,
4499 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4501 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4502 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4503 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4504 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4513 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4515 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4516 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4517 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4518 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4519 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4520 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4529 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4531 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4532 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4533 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4542 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4547 .fill_helper
= bpf_fill_stxdw
,
4549 /* BPF_JMP | BPF_EXIT */
4553 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4711),
4555 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4712),
4561 /* BPF_JMP | BPF_JA */
4563 "JMP_JA: Unconditional jump: if (true) return 1",
4565 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4566 BPF_JMP_IMM(BPF_JA
, 0, 0, 1),
4568 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4575 /* BPF_JMP | BPF_JSLT | BPF_K */
4577 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4579 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4580 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4581 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4583 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4591 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4593 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4594 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4595 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4597 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4604 /* BPF_JMP | BPF_JSGT | BPF_K */
4606 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4608 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4609 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4610 BPF_JMP_IMM(BPF_JSGT
, R1
, -2, 1),
4612 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4620 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4622 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4623 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4624 BPF_JMP_IMM(BPF_JSGT
, R1
, -1, 1),
4626 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4633 /* BPF_JMP | BPF_JSLE | BPF_K */
4635 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4637 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4638 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4639 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4641 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4649 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4651 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4652 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4653 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4655 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4663 "JMP_JSLE_K: Signed jump: value walk 1",
4665 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4666 BPF_LD_IMM64(R1
, 3),
4667 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 6),
4668 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4669 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4670 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4671 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4672 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4673 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4674 BPF_EXIT_INSN(), /* bad exit */
4675 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4683 "JMP_JSLE_K: Signed jump: value walk 2",
4685 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4686 BPF_LD_IMM64(R1
, 3),
4687 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4688 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4689 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4690 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4691 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4692 BPF_EXIT_INSN(), /* bad exit */
4693 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4700 /* BPF_JMP | BPF_JSGE | BPF_K */
4702 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4704 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4705 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4706 BPF_JMP_IMM(BPF_JSGE
, R1
, -2, 1),
4708 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4716 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4718 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4719 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4720 BPF_JMP_IMM(BPF_JSGE
, R1
, -1, 1),
4722 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4730 "JMP_JSGE_K: Signed jump: value walk 1",
4732 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4733 BPF_LD_IMM64(R1
, -3),
4734 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 6),
4735 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4736 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4737 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4738 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4739 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4740 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4741 BPF_EXIT_INSN(), /* bad exit */
4742 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4750 "JMP_JSGE_K: Signed jump: value walk 2",
4752 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4753 BPF_LD_IMM64(R1
, -3),
4754 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4755 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4756 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4757 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4758 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4759 BPF_EXIT_INSN(), /* bad exit */
4760 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4767 /* BPF_JMP | BPF_JGT | BPF_K */
4769 "JMP_JGT_K: if (3 > 2) return 1",
4771 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4772 BPF_LD_IMM64(R1
, 3),
4773 BPF_JMP_IMM(BPF_JGT
, R1
, 2, 1),
4775 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4783 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4785 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4786 BPF_LD_IMM64(R1
, -1),
4787 BPF_JMP_IMM(BPF_JGT
, R1
, 1, 1),
4789 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4796 /* BPF_JMP | BPF_JLT | BPF_K */
4798 "JMP_JLT_K: if (2 < 3) return 1",
4800 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4801 BPF_LD_IMM64(R1
, 2),
4802 BPF_JMP_IMM(BPF_JLT
, R1
, 3, 1),
4804 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4812 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4814 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4815 BPF_LD_IMM64(R1
, 1),
4816 BPF_JMP_IMM(BPF_JLT
, R1
, -1, 1),
4818 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4825 /* BPF_JMP | BPF_JGE | BPF_K */
4827 "JMP_JGE_K: if (3 >= 2) return 1",
4829 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4830 BPF_LD_IMM64(R1
, 3),
4831 BPF_JMP_IMM(BPF_JGE
, R1
, 2, 1),
4833 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4840 /* BPF_JMP | BPF_JLE | BPF_K */
4842 "JMP_JLE_K: if (2 <= 3) return 1",
4844 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4845 BPF_LD_IMM64(R1
, 2),
4846 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4848 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4855 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4857 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4859 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4860 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4862 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4863 BPF_LD_IMM64(R1
, 3), /* note: this takes 2 insns */
4864 BPF_JMP_IMM(BPF_JGT
, R1
, 2, -6), /* goto out */
4872 "JMP_JGE_K: if (3 >= 3) return 1",
4874 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4875 BPF_LD_IMM64(R1
, 3),
4876 BPF_JMP_IMM(BPF_JGE
, R1
, 3, 1),
4878 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4885 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4887 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4889 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4890 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4892 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4893 BPF_LD_IMM64(R1
, 2), /* note: this takes 2 insns */
4894 BPF_JMP_IMM(BPF_JLT
, R1
, 3, -6), /* goto out */
4902 "JMP_JLE_K: if (3 <= 3) return 1",
4904 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4905 BPF_LD_IMM64(R1
, 3),
4906 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4908 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4915 /* BPF_JMP | BPF_JNE | BPF_K */
4917 "JMP_JNE_K: if (3 != 2) return 1",
4919 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4920 BPF_LD_IMM64(R1
, 3),
4921 BPF_JMP_IMM(BPF_JNE
, R1
, 2, 1),
4923 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4930 /* BPF_JMP | BPF_JEQ | BPF_K */
4932 "JMP_JEQ_K: if (3 == 3) return 1",
4934 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4935 BPF_LD_IMM64(R1
, 3),
4936 BPF_JMP_IMM(BPF_JEQ
, R1
, 3, 1),
4938 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4945 /* BPF_JMP | BPF_JSET | BPF_K */
4947 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4949 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4950 BPF_LD_IMM64(R1
, 3),
4951 BPF_JMP_IMM(BPF_JSET
, R1
, 2, 1),
4953 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4961 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4963 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4964 BPF_LD_IMM64(R1
, 3),
4965 BPF_JMP_IMM(BPF_JSET
, R1
, 0xffffffff, 1),
4967 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4974 /* BPF_JMP | BPF_JSGT | BPF_X */
4976 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4978 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4979 BPF_LD_IMM64(R1
, -1),
4980 BPF_LD_IMM64(R2
, -2),
4981 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4983 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4991 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4993 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4994 BPF_LD_IMM64(R1
, -1),
4995 BPF_LD_IMM64(R2
, -1),
4996 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4998 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5005 /* BPF_JMP | BPF_JSLT | BPF_X */
5007 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
5009 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5010 BPF_LD_IMM64(R1
, -1),
5011 BPF_LD_IMM64(R2
, -2),
5012 BPF_JMP_REG(BPF_JSLT
, R2
, R1
, 1),
5014 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5022 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
5024 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5025 BPF_LD_IMM64(R1
, -1),
5026 BPF_LD_IMM64(R2
, -1),
5027 BPF_JMP_REG(BPF_JSLT
, R1
, R2
, 1),
5029 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5036 /* BPF_JMP | BPF_JSGE | BPF_X */
5038 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5040 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5041 BPF_LD_IMM64(R1
, -1),
5042 BPF_LD_IMM64(R2
, -2),
5043 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5045 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5053 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5055 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5056 BPF_LD_IMM64(R1
, -1),
5057 BPF_LD_IMM64(R2
, -1),
5058 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5060 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5067 /* BPF_JMP | BPF_JSLE | BPF_X */
5069 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5071 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5072 BPF_LD_IMM64(R1
, -1),
5073 BPF_LD_IMM64(R2
, -2),
5074 BPF_JMP_REG(BPF_JSLE
, R2
, R1
, 1),
5076 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5084 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5086 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5087 BPF_LD_IMM64(R1
, -1),
5088 BPF_LD_IMM64(R2
, -1),
5089 BPF_JMP_REG(BPF_JSLE
, R1
, R2
, 1),
5091 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5098 /* BPF_JMP | BPF_JGT | BPF_X */
5100 "JMP_JGT_X: if (3 > 2) return 1",
5102 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5103 BPF_LD_IMM64(R1
, 3),
5104 BPF_LD_IMM64(R2
, 2),
5105 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5107 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5115 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5117 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5118 BPF_LD_IMM64(R1
, -1),
5119 BPF_LD_IMM64(R2
, 1),
5120 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5122 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5129 /* BPF_JMP | BPF_JLT | BPF_X */
5131 "JMP_JLT_X: if (2 < 3) return 1",
5133 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5134 BPF_LD_IMM64(R1
, 3),
5135 BPF_LD_IMM64(R2
, 2),
5136 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5138 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5146 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5148 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5149 BPF_LD_IMM64(R1
, -1),
5150 BPF_LD_IMM64(R2
, 1),
5151 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5153 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5160 /* BPF_JMP | BPF_JGE | BPF_X */
5162 "JMP_JGE_X: if (3 >= 2) return 1",
5164 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5165 BPF_LD_IMM64(R1
, 3),
5166 BPF_LD_IMM64(R2
, 2),
5167 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5169 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5177 "JMP_JGE_X: if (3 >= 3) return 1",
5179 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5180 BPF_LD_IMM64(R1
, 3),
5181 BPF_LD_IMM64(R2
, 3),
5182 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5184 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5191 /* BPF_JMP | BPF_JLE | BPF_X */
5193 "JMP_JLE_X: if (2 <= 3) return 1",
5195 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5196 BPF_LD_IMM64(R1
, 3),
5197 BPF_LD_IMM64(R2
, 2),
5198 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 1),
5200 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5208 "JMP_JLE_X: if (3 <= 3) return 1",
5210 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5211 BPF_LD_IMM64(R1
, 3),
5212 BPF_LD_IMM64(R2
, 3),
5213 BPF_JMP_REG(BPF_JLE
, R1
, R2
, 1),
5215 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5223 /* Mainly testing JIT + imm64 here. */
5224 "JMP_JGE_X: ldimm64 test 1",
5226 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5227 BPF_LD_IMM64(R1
, 3),
5228 BPF_LD_IMM64(R2
, 2),
5229 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 2),
5230 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5231 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5236 { { 0, 0xeeeeeeeeU
} },
5239 "JMP_JGE_X: ldimm64 test 2",
5241 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5242 BPF_LD_IMM64(R1
, 3),
5243 BPF_LD_IMM64(R2
, 2),
5244 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 0),
5245 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5250 { { 0, 0xffffffffU
} },
5253 "JMP_JGE_X: ldimm64 test 3",
5255 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5256 BPF_LD_IMM64(R1
, 3),
5257 BPF_LD_IMM64(R2
, 2),
5258 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 4),
5259 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5260 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5268 "JMP_JLE_X: ldimm64 test 1",
5270 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5271 BPF_LD_IMM64(R1
, 3),
5272 BPF_LD_IMM64(R2
, 2),
5273 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 2),
5274 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5275 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5280 { { 0, 0xeeeeeeeeU
} },
5283 "JMP_JLE_X: ldimm64 test 2",
5285 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5286 BPF_LD_IMM64(R1
, 3),
5287 BPF_LD_IMM64(R2
, 2),
5288 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 0),
5289 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5294 { { 0, 0xffffffffU
} },
5297 "JMP_JLE_X: ldimm64 test 3",
5299 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5300 BPF_LD_IMM64(R1
, 3),
5301 BPF_LD_IMM64(R2
, 2),
5302 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 4),
5303 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5304 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5311 /* BPF_JMP | BPF_JNE | BPF_X */
5313 "JMP_JNE_X: if (3 != 2) return 1",
5315 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5316 BPF_LD_IMM64(R1
, 3),
5317 BPF_LD_IMM64(R2
, 2),
5318 BPF_JMP_REG(BPF_JNE
, R1
, R2
, 1),
5320 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5327 /* BPF_JMP | BPF_JEQ | BPF_X */
5329 "JMP_JEQ_X: if (3 == 3) return 1",
5331 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5332 BPF_LD_IMM64(R1
, 3),
5333 BPF_LD_IMM64(R2
, 3),
5334 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
5336 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5343 /* BPF_JMP | BPF_JSET | BPF_X */
5345 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5347 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5348 BPF_LD_IMM64(R1
, 3),
5349 BPF_LD_IMM64(R2
, 2),
5350 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5352 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5360 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5362 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5363 BPF_LD_IMM64(R1
, 3),
5364 BPF_LD_IMM64(R2
, 0xffffffff),
5365 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5367 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5375 "JMP_JA: Jump, gap, jump, ...",
5377 CLASSIC
| FLAG_NO_DATA
,
5379 { { 0, 0xababcbac } },
5380 .fill_helper
= bpf_fill_ja
,
5382 { /* Mainly checking JIT here. */
5383 "BPF_MAXINSNS: Maximum possible literals",
5385 CLASSIC
| FLAG_NO_DATA
,
5387 { { 0, 0xffffffff } },
5388 .fill_helper
= bpf_fill_maxinsns1
,
5390 { /* Mainly checking JIT here. */
5391 "BPF_MAXINSNS: Single literal",
5393 CLASSIC
| FLAG_NO_DATA
,
5395 { { 0, 0xfefefefe } },
5396 .fill_helper
= bpf_fill_maxinsns2
,
5398 { /* Mainly checking JIT here. */
5399 "BPF_MAXINSNS: Run/add until end",
5401 CLASSIC
| FLAG_NO_DATA
,
5403 { { 0, 0x947bf368 } },
5404 .fill_helper
= bpf_fill_maxinsns3
,
5407 "BPF_MAXINSNS: Too many instructions",
5409 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5412 .fill_helper
= bpf_fill_maxinsns4
,
5413 .expected_errcode
= -EINVAL
,
5415 { /* Mainly checking JIT here. */
5416 "BPF_MAXINSNS: Very long jump",
5418 CLASSIC
| FLAG_NO_DATA
,
5420 { { 0, 0xabababab } },
5421 .fill_helper
= bpf_fill_maxinsns5
,
5423 { /* Mainly checking JIT here. */
5424 "BPF_MAXINSNS: Ctx heavy transformations",
5429 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
5430 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
5432 .fill_helper
= bpf_fill_maxinsns6
,
5434 { /* Mainly checking JIT here. */
5435 "BPF_MAXINSNS: Call heavy transformations",
5437 CLASSIC
| FLAG_NO_DATA
,
5439 { { 1, 0 }, { 10, 0 } },
5440 .fill_helper
= bpf_fill_maxinsns7
,
5442 { /* Mainly checking JIT here. */
5443 "BPF_MAXINSNS: Jump heavy test",
5445 CLASSIC
| FLAG_NO_DATA
,
5447 { { 0, 0xffffffff } },
5448 .fill_helper
= bpf_fill_maxinsns8
,
5450 { /* Mainly checking JIT here. */
5451 "BPF_MAXINSNS: Very long jump backwards",
5453 INTERNAL
| FLAG_NO_DATA
,
5455 { { 0, 0xcbababab } },
5456 .fill_helper
= bpf_fill_maxinsns9
,
5458 { /* Mainly checking JIT here. */
5459 "BPF_MAXINSNS: Edge hopping nuthouse",
5461 INTERNAL
| FLAG_NO_DATA
,
5463 { { 0, 0xabababac } },
5464 .fill_helper
= bpf_fill_maxinsns10
,
5467 "BPF_MAXINSNS: Jump, gap, jump, ...",
5469 #ifdef CONFIG_BPF_JIT_ALWAYS_ON
5470 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5472 CLASSIC
| FLAG_NO_DATA
,
5475 { { 0, 0xababcbac } },
5476 .fill_helper
= bpf_fill_maxinsns11
,
5477 .expected_errcode
= -ENOTSUPP
,
5480 "BPF_MAXINSNS: ld_abs+get_processor_id",
5485 .fill_helper
= bpf_fill_ld_abs_get_processor_id
,
5488 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5492 { { ETH_HLEN
, 0xbef } },
5493 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop
,
5496 "BPF_MAXINSNS: jump around ld_abs",
5501 .fill_helper
= bpf_fill_jump_around_ld_abs
,
5504 * LD_IND / LD_ABS on fragmented SKBs
5509 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5510 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x0),
5511 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5513 CLASSIC
| FLAG_SKB_FRAG
,
5517 0x42, 0x00, 0x00, 0x00,
5518 0x43, 0x44, 0x00, 0x00,
5519 0x21, 0x07, 0x19, 0x83,
5523 "LD_IND halfword frag",
5525 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5526 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x4),
5527 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5529 CLASSIC
| FLAG_SKB_FRAG
,
5533 0x42, 0x00, 0x00, 0x00,
5534 0x43, 0x44, 0x00, 0x00,
5535 0x21, 0x07, 0x19, 0x83,
5541 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5542 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x8),
5543 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5545 CLASSIC
| FLAG_SKB_FRAG
,
5547 { {0x40, 0x21071983} },
5549 0x42, 0x00, 0x00, 0x00,
5550 0x43, 0x44, 0x00, 0x00,
5551 0x21, 0x07, 0x19, 0x83,
5555 "LD_IND halfword mixed head/frag",
5557 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5558 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5559 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5561 CLASSIC
| FLAG_SKB_FRAG
,
5562 { [0x3e] = 0x25, [0x3f] = 0x05, },
5564 .frag_data
= { 0x19, 0x82 },
5567 "LD_IND word mixed head/frag",
5569 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5570 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5571 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5573 CLASSIC
| FLAG_SKB_FRAG
,
5574 { [0x3e] = 0x25, [0x3f] = 0x05, },
5575 { {0x40, 0x25051982} },
5576 .frag_data
= { 0x19, 0x82 },
5581 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x40),
5582 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5584 CLASSIC
| FLAG_SKB_FRAG
,
5588 0x42, 0x00, 0x00, 0x00,
5589 0x43, 0x44, 0x00, 0x00,
5590 0x21, 0x07, 0x19, 0x83,
5594 "LD_ABS halfword frag",
5596 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x44),
5597 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5599 CLASSIC
| FLAG_SKB_FRAG
,
5603 0x42, 0x00, 0x00, 0x00,
5604 0x43, 0x44, 0x00, 0x00,
5605 0x21, 0x07, 0x19, 0x83,
5611 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x48),
5612 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5614 CLASSIC
| FLAG_SKB_FRAG
,
5616 { {0x40, 0x21071983} },
5618 0x42, 0x00, 0x00, 0x00,
5619 0x43, 0x44, 0x00, 0x00,
5620 0x21, 0x07, 0x19, 0x83,
5624 "LD_ABS halfword mixed head/frag",
5626 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3f),
5627 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5629 CLASSIC
| FLAG_SKB_FRAG
,
5630 { [0x3e] = 0x25, [0x3f] = 0x05, },
5632 .frag_data
= { 0x19, 0x82 },
5635 "LD_ABS word mixed head/frag",
5637 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3e),
5638 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5640 CLASSIC
| FLAG_SKB_FRAG
,
5641 { [0x3e] = 0x25, [0x3f] = 0x05, },
5642 { {0x40, 0x25051982} },
5643 .frag_data
= { 0x19, 0x82 },
5646 * LD_IND / LD_ABS on non fragmented SKBs
5650 * this tests that the JIT/interpreter correctly resets X
5651 * before using it in an LD_IND instruction.
5653 "LD_IND byte default X",
5655 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5656 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5663 "LD_IND byte positive offset",
5665 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5666 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5667 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5670 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5674 "LD_IND byte negative offset",
5676 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5677 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, -0x1),
5678 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5681 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5685 "LD_IND halfword positive offset",
5687 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5688 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x2),
5689 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5693 [0x1c] = 0xaa, [0x1d] = 0x55,
5694 [0x1e] = 0xbb, [0x1f] = 0x66,
5695 [0x20] = 0xcc, [0x21] = 0x77,
5696 [0x22] = 0xdd, [0x23] = 0x88,
5698 { {0x40, 0xdd88 } },
5701 "LD_IND halfword negative offset",
5703 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5704 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x2),
5705 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5709 [0x1c] = 0xaa, [0x1d] = 0x55,
5710 [0x1e] = 0xbb, [0x1f] = 0x66,
5711 [0x20] = 0xcc, [0x21] = 0x77,
5712 [0x22] = 0xdd, [0x23] = 0x88,
5714 { {0x40, 0xbb66 } },
5717 "LD_IND halfword unaligned",
5719 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5720 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5721 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5725 [0x1c] = 0xaa, [0x1d] = 0x55,
5726 [0x1e] = 0xbb, [0x1f] = 0x66,
5727 [0x20] = 0xcc, [0x21] = 0x77,
5728 [0x22] = 0xdd, [0x23] = 0x88,
5730 { {0x40, 0x66cc } },
5733 "LD_IND word positive offset",
5735 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5736 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x4),
5737 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5741 [0x1c] = 0xaa, [0x1d] = 0x55,
5742 [0x1e] = 0xbb, [0x1f] = 0x66,
5743 [0x20] = 0xcc, [0x21] = 0x77,
5744 [0x22] = 0xdd, [0x23] = 0x88,
5745 [0x24] = 0xee, [0x25] = 0x99,
5746 [0x26] = 0xff, [0x27] = 0xaa,
5748 { {0x40, 0xee99ffaa } },
5751 "LD_IND word negative offset",
5753 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5754 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x4),
5755 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5759 [0x1c] = 0xaa, [0x1d] = 0x55,
5760 [0x1e] = 0xbb, [0x1f] = 0x66,
5761 [0x20] = 0xcc, [0x21] = 0x77,
5762 [0x22] = 0xdd, [0x23] = 0x88,
5763 [0x24] = 0xee, [0x25] = 0x99,
5764 [0x26] = 0xff, [0x27] = 0xaa,
5766 { {0x40, 0xaa55bb66 } },
5769 "LD_IND word unaligned (addr & 3 == 2)",
5771 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5772 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5773 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5777 [0x1c] = 0xaa, [0x1d] = 0x55,
5778 [0x1e] = 0xbb, [0x1f] = 0x66,
5779 [0x20] = 0xcc, [0x21] = 0x77,
5780 [0x22] = 0xdd, [0x23] = 0x88,
5781 [0x24] = 0xee, [0x25] = 0x99,
5782 [0x26] = 0xff, [0x27] = 0xaa,
5784 { {0x40, 0xbb66cc77 } },
5787 "LD_IND word unaligned (addr & 3 == 1)",
5789 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5790 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x3),
5791 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5795 [0x1c] = 0xaa, [0x1d] = 0x55,
5796 [0x1e] = 0xbb, [0x1f] = 0x66,
5797 [0x20] = 0xcc, [0x21] = 0x77,
5798 [0x22] = 0xdd, [0x23] = 0x88,
5799 [0x24] = 0xee, [0x25] = 0x99,
5800 [0x26] = 0xff, [0x27] = 0xaa,
5802 { {0x40, 0x55bb66cc } },
5805 "LD_IND word unaligned (addr & 3 == 3)",
5807 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5808 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x1),
5809 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5813 [0x1c] = 0xaa, [0x1d] = 0x55,
5814 [0x1e] = 0xbb, [0x1f] = 0x66,
5815 [0x20] = 0xcc, [0x21] = 0x77,
5816 [0x22] = 0xdd, [0x23] = 0x88,
5817 [0x24] = 0xee, [0x25] = 0x99,
5818 [0x26] = 0xff, [0x27] = 0xaa,
5820 { {0x40, 0x66cc77dd } },
5825 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x20),
5826 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5830 [0x1c] = 0xaa, [0x1d] = 0x55,
5831 [0x1e] = 0xbb, [0x1f] = 0x66,
5832 [0x20] = 0xcc, [0x21] = 0x77,
5833 [0x22] = 0xdd, [0x23] = 0x88,
5834 [0x24] = 0xee, [0x25] = 0x99,
5835 [0x26] = 0xff, [0x27] = 0xaa,
5842 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x22),
5843 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5847 [0x1c] = 0xaa, [0x1d] = 0x55,
5848 [0x1e] = 0xbb, [0x1f] = 0x66,
5849 [0x20] = 0xcc, [0x21] = 0x77,
5850 [0x22] = 0xdd, [0x23] = 0x88,
5851 [0x24] = 0xee, [0x25] = 0x99,
5852 [0x26] = 0xff, [0x27] = 0xaa,
5854 { {0x40, 0xdd88 } },
5857 "LD_ABS halfword unaligned",
5859 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x25),
5860 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5864 [0x1c] = 0xaa, [0x1d] = 0x55,
5865 [0x1e] = 0xbb, [0x1f] = 0x66,
5866 [0x20] = 0xcc, [0x21] = 0x77,
5867 [0x22] = 0xdd, [0x23] = 0x88,
5868 [0x24] = 0xee, [0x25] = 0x99,
5869 [0x26] = 0xff, [0x27] = 0xaa,
5871 { {0x40, 0x99ff } },
5876 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x1c),
5877 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5881 [0x1c] = 0xaa, [0x1d] = 0x55,
5882 [0x1e] = 0xbb, [0x1f] = 0x66,
5883 [0x20] = 0xcc, [0x21] = 0x77,
5884 [0x22] = 0xdd, [0x23] = 0x88,
5885 [0x24] = 0xee, [0x25] = 0x99,
5886 [0x26] = 0xff, [0x27] = 0xaa,
5888 { {0x40, 0xaa55bb66 } },
5891 "LD_ABS word unaligned (addr & 3 == 2)",
5893 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x22),
5894 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5898 [0x1c] = 0xaa, [0x1d] = 0x55,
5899 [0x1e] = 0xbb, [0x1f] = 0x66,
5900 [0x20] = 0xcc, [0x21] = 0x77,
5901 [0x22] = 0xdd, [0x23] = 0x88,
5902 [0x24] = 0xee, [0x25] = 0x99,
5903 [0x26] = 0xff, [0x27] = 0xaa,
5905 { {0x40, 0xdd88ee99 } },
5908 "LD_ABS word unaligned (addr & 3 == 1)",
5910 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x21),
5911 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5915 [0x1c] = 0xaa, [0x1d] = 0x55,
5916 [0x1e] = 0xbb, [0x1f] = 0x66,
5917 [0x20] = 0xcc, [0x21] = 0x77,
5918 [0x22] = 0xdd, [0x23] = 0x88,
5919 [0x24] = 0xee, [0x25] = 0x99,
5920 [0x26] = 0xff, [0x27] = 0xaa,
5922 { {0x40, 0x77dd88ee } },
5925 "LD_ABS word unaligned (addr & 3 == 3)",
5927 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x23),
5928 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5932 [0x1c] = 0xaa, [0x1d] = 0x55,
5933 [0x1e] = 0xbb, [0x1f] = 0x66,
5934 [0x20] = 0xcc, [0x21] = 0x77,
5935 [0x22] = 0xdd, [0x23] = 0x88,
5936 [0x24] = 0xee, [0x25] = 0x99,
5937 [0x26] = 0xff, [0x27] = 0xaa,
5939 { {0x40, 0x88ee99ff } },
5942 * verify that the interpreter or JIT correctly sets A and X
5953 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
5954 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
5955 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5957 CLASSIC
| FLAG_NO_DATA
,
5968 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0x42),
5969 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5971 CLASSIC
| FLAG_NO_DATA
,
5983 BPF_STMT(BPF_LD
| BPF_IMM
, 0x66),
5984 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
5985 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5987 CLASSIC
| FLAG_NO_DATA
,
5998 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, -0x66),
5999 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6001 CLASSIC
| FLAG_NO_DATA
,
6013 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6014 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_X
, 0),
6015 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6017 CLASSIC
| FLAG_NO_DATA
,
6028 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 0x66),
6029 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6031 CLASSIC
| FLAG_NO_DATA
,
6040 * A = A / X ; this halt the filter execution if X is 0
6043 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6044 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
6045 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6047 CLASSIC
| FLAG_NO_DATA
,
6058 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x1),
6059 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6061 CLASSIC
| FLAG_NO_DATA
,
6070 * A = A mod X ; this halt the filter execution if X is 0
6073 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6074 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
6075 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6077 CLASSIC
| FLAG_NO_DATA
,
6088 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x1),
6089 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6091 CLASSIC
| FLAG_NO_DATA
,
6103 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0, 0, 1),
6104 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6105 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6107 CLASSIC
| FLAG_NO_DATA
,
6120 BPF_STMT(BPF_LD
| BPF_IMM
, 0x0),
6121 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0x0, 0, 1),
6122 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6123 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6125 CLASSIC
| FLAG_NO_DATA
,
6130 "LD_ABS with helper changing skb data",
6134 { { ETH_HLEN
, 42 } },
6135 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop2
,
6137 /* Checking interpreter vs JIT wrt signed extended imms. */
6139 "JNE signed compare, test 1",
6141 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6142 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6143 BPF_MOV64_REG(R2
, R1
),
6144 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6145 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6146 BPF_JMP_IMM(BPF_JNE
, R2
, -17104896, 1),
6147 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6155 "JNE signed compare, test 2",
6157 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6158 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6159 BPF_MOV64_REG(R2
, R1
),
6160 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6161 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6162 BPF_JMP_IMM(BPF_JNE
, R2
, 0xfefb0000, 1),
6163 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6171 "JNE signed compare, test 3",
6173 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6174 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6175 BPF_ALU32_IMM(BPF_MOV
, R4
, 0xfefb0000),
6176 BPF_MOV64_REG(R2
, R1
),
6177 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6178 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6179 BPF_JMP_REG(BPF_JNE
, R2
, R4
, 1),
6180 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6188 "JNE signed compare, test 4",
6190 BPF_LD_IMM64(R1
, -17104896),
6191 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6192 BPF_JMP_IMM(BPF_JNE
, R1
, -17104896, 1),
6193 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6201 "JNE signed compare, test 5",
6203 BPF_LD_IMM64(R1
, 0xfefb0000),
6204 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6205 BPF_JMP_IMM(BPF_JNE
, R1
, 0xfefb0000, 1),
6206 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6214 "JNE signed compare, test 6",
6216 BPF_LD_IMM64(R1
, 0x7efb0000),
6217 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6218 BPF_JMP_IMM(BPF_JNE
, R1
, 0x7efb0000, 1),
6219 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6227 "JNE signed compare, test 7",
6229 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffff0000),
6230 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6231 BPF_STMT(BPF_LD
| BPF_IMM
, 0xfefbbc12),
6232 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_X
, 0),
6233 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xfefb0000, 1, 0),
6234 BPF_STMT(BPF_RET
| BPF_K
, 1),
6235 BPF_STMT(BPF_RET
| BPF_K
, 2),
6237 CLASSIC
| FLAG_NO_DATA
,
6243 static struct net_device dev
;
6245 static struct sk_buff
*populate_skb(char *buf
, int size
)
6247 struct sk_buff
*skb
;
6249 if (size
>= MAX_DATA
)
6252 skb
= alloc_skb(MAX_DATA
, GFP_KERNEL
);
6256 __skb_put_data(skb
, buf
, size
);
6258 /* Initialize a fake skb with test pattern. */
6259 skb_reset_mac_header(skb
);
6260 skb
->protocol
= htons(ETH_P_IP
);
6261 skb
->pkt_type
= SKB_TYPE
;
6262 skb
->mark
= SKB_MARK
;
6263 skb
->hash
= SKB_HASH
;
6264 skb
->queue_mapping
= SKB_QUEUE_MAP
;
6265 skb
->vlan_tci
= SKB_VLAN_TCI
;
6266 skb
->vlan_proto
= htons(ETH_P_IP
);
6268 skb
->dev
->ifindex
= SKB_DEV_IFINDEX
;
6269 skb
->dev
->type
= SKB_DEV_TYPE
;
6270 skb_set_network_header(skb
, min(size
, ETH_HLEN
));
6275 static void *generate_test_data(struct bpf_test
*test
, int sub
)
6277 struct sk_buff
*skb
;
6280 if (test
->aux
& FLAG_NO_DATA
)
6283 /* Test case expects an skb, so populate one. Various
6284 * subtests generate skbs of different sizes based on
6287 skb
= populate_skb(test
->data
, test
->test
[sub
].data_size
);
6291 if (test
->aux
& FLAG_SKB_FRAG
) {
6293 * when the test requires a fragmented skb, add a
6294 * single fragment to the skb, filled with
6299 page
= alloc_page(GFP_KERNEL
);
6307 memcpy(ptr
, test
->frag_data
, MAX_DATA
);
6309 skb_add_rx_frag(skb
, 0, page
, 0, MAX_DATA
, MAX_DATA
);
6321 static void release_test_data(const struct bpf_test
*test
, void *data
)
6323 if (test
->aux
& FLAG_NO_DATA
)
6329 static int filter_length(int which
)
6331 struct sock_filter
*fp
;
6334 if (tests
[which
].fill_helper
)
6335 return tests
[which
].u
.ptr
.len
;
6337 fp
= tests
[which
].u
.insns
;
6338 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
6339 if (fp
[len
].code
!= 0 || fp
[len
].k
!= 0)
6345 static void *filter_pointer(int which
)
6347 if (tests
[which
].fill_helper
)
6348 return tests
[which
].u
.ptr
.insns
;
6350 return tests
[which
].u
.insns
;
6353 static struct bpf_prog
*generate_filter(int which
, int *err
)
6355 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6356 unsigned int flen
= filter_length(which
);
6357 void *fptr
= filter_pointer(which
);
6358 struct sock_fprog_kern fprog
;
6359 struct bpf_prog
*fp
;
6361 switch (test_type
) {
6363 fprog
.filter
= fptr
;
6366 *err
= bpf_prog_create(&fp
, &fprog
);
6367 if (tests
[which
].aux
& FLAG_EXPECTED_FAIL
) {
6368 if (*err
== tests
[which
].expected_errcode
) {
6370 /* Verifier rejected filter as expected. */
6374 pr_cont("UNEXPECTED_PASS\n");
6375 /* Verifier didn't reject the test that's
6376 * bad enough, just return!
6383 pr_cont("FAIL to prog_create err=%d len=%d\n",
6390 fp
= bpf_prog_alloc(bpf_prog_size(flen
), 0);
6392 pr_cont("UNEXPECTED_FAIL no memory left\n");
6398 /* Type doesn't really matter here as long as it's not unspec. */
6399 fp
->type
= BPF_PROG_TYPE_SOCKET_FILTER
;
6400 memcpy(fp
->insnsi
, fptr
, fp
->len
* sizeof(struct bpf_insn
));
6401 fp
->aux
->stack_depth
= tests
[which
].stack_depth
;
6403 /* We cannot error here as we don't need type compatibility
6406 fp
= bpf_prog_select_runtime(fp
, err
);
6408 pr_cont("FAIL to select_runtime err=%d\n", *err
);
6418 static void release_filter(struct bpf_prog
*fp
, int which
)
6420 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6422 switch (test_type
) {
6424 bpf_prog_destroy(fp
);
6432 static int __run_one(const struct bpf_prog
*fp
, const void *data
,
6433 int runs
, u64
*duration
)
6438 start
= ktime_get_ns();
6440 for (i
= 0; i
< runs
; i
++)
6441 ret
= BPF_PROG_RUN(fp
, data
);
6443 finish
= ktime_get_ns();
6445 *duration
= finish
- start
;
6446 do_div(*duration
, runs
);
6451 static int run_one(const struct bpf_prog
*fp
, struct bpf_test
*test
)
6453 int err_cnt
= 0, i
, runs
= MAX_TESTRUNS
;
6455 for (i
= 0; i
< MAX_SUBTESTS
; i
++) {
6460 if (test
->test
[i
].data_size
== 0 &&
6461 test
->test
[i
].result
== 0)
6464 data
= generate_test_data(test
, i
);
6465 if (!data
&& !(test
->aux
& FLAG_NO_DATA
)) {
6466 pr_cont("data generation failed ");
6470 ret
= __run_one(fp
, data
, runs
, &duration
);
6471 release_test_data(test
, data
);
6473 if (ret
== test
->test
[i
].result
) {
6474 pr_cont("%lld ", duration
);
6476 pr_cont("ret %d != %d ", ret
,
6477 test
->test
[i
].result
);
6485 static char test_name
[64];
6486 module_param_string(test_name
, test_name
, sizeof(test_name
), 0);
6488 static int test_id
= -1;
6489 module_param(test_id
, int, 0);
6491 static int test_range
[2] = { 0, ARRAY_SIZE(tests
) - 1 };
6492 module_param_array(test_range
, int, NULL
, 0);
6494 static __init
int find_test_index(const char *test_name
)
6498 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6499 if (!strcmp(tests
[i
].descr
, test_name
))
6505 static __init
int prepare_bpf_tests(void)
6511 * if a test_id was specified, use test_range to
6512 * cover only that test.
6514 if (test_id
>= ARRAY_SIZE(tests
)) {
6515 pr_err("test_bpf: invalid test_id specified.\n");
6519 test_range
[0] = test_id
;
6520 test_range
[1] = test_id
;
6521 } else if (*test_name
) {
6523 * if a test_name was specified, find it and setup
6524 * test_range to cover only that test.
6526 int idx
= find_test_index(test_name
);
6529 pr_err("test_bpf: no test named '%s' found.\n",
6533 test_range
[0] = idx
;
6534 test_range
[1] = idx
;
6537 * check that the supplied test_range is valid.
6539 if (test_range
[0] >= ARRAY_SIZE(tests
) ||
6540 test_range
[1] >= ARRAY_SIZE(tests
) ||
6541 test_range
[0] < 0 || test_range
[1] < 0) {
6542 pr_err("test_bpf: test_range is out of bound.\n");
6546 if (test_range
[1] < test_range
[0]) {
6547 pr_err("test_bpf: test_range is ending before it starts.\n");
6552 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6553 if (tests
[i
].fill_helper
&&
6554 tests
[i
].fill_helper(&tests
[i
]) < 0)
6561 static __init
void destroy_bpf_tests(void)
6565 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6566 if (tests
[i
].fill_helper
)
6567 kfree(tests
[i
].u
.ptr
.insns
);
6571 static bool exclude_test(int test_id
)
6573 return test_id
< test_range
[0] || test_id
> test_range
[1];
6576 static __init
int test_bpf(void)
6578 int i
, err_cnt
= 0, pass_cnt
= 0;
6579 int jit_cnt
= 0, run_cnt
= 0;
6581 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6582 struct bpf_prog
*fp
;
6585 if (exclude_test(i
))
6588 pr_info("#%d %s ", i
, tests
[i
].descr
);
6590 fp
= generate_filter(i
, &err
);
6600 pr_cont("jited:%u ", fp
->jited
);
6606 err
= run_one(fp
, &tests
[i
]);
6607 release_filter(fp
, i
);
6610 pr_cont("FAIL (%d times)\n", err
);
6618 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6619 pass_cnt
, err_cnt
, jit_cnt
, run_cnt
);
6621 return err_cnt
? -EINVAL
: 0;
6624 static int __init
test_bpf_init(void)
6628 ret
= prepare_bpf_tests();
6634 destroy_bpf_tests();
6638 static void __exit
test_bpf_exit(void)
6642 module_init(test_bpf_init
);
6643 module_exit(test_bpf_exit
);
6645 MODULE_LICENSE("GPL");