2 * Testsuite for BPF interpreter and BPF JIT compiler
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/filter.h>
21 #include <linux/bpf.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_vlan.h>
25 #include <linux/random.h>
26 #include <linux/highmem.h>
27 #include <linux/sched.h>
29 /* General test specific settings */
30 #define MAX_SUBTESTS 3
31 #define MAX_TESTRUNS 1000
34 #define MAX_K 0xffffFFFF
36 /* Few constants used to init test 'skb' */
38 #define SKB_MARK 0x1234aaaa
39 #define SKB_HASH 0x1234aaab
40 #define SKB_QUEUE_MAP 123
41 #define SKB_VLAN_TCI 0xffff
42 #define SKB_DEV_IFINDEX 577
43 #define SKB_DEV_TYPE 588
45 /* Redefine REGs to make tests less verbose */
56 #define R10 BPF_REG_10
58 /* Flags that can be passed to test cases */
59 #define FLAG_NO_DATA BIT(0)
60 #define FLAG_EXPECTED_FAIL BIT(1)
61 #define FLAG_SKB_FRAG BIT(2)
64 CLASSIC
= BIT(6), /* Old BPF instructions only. */
65 INTERNAL
= BIT(7), /* Extended instruction set. */
68 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
73 struct sock_filter insns
[MAX_INSNS
];
74 struct bpf_insn insns_int
[MAX_INSNS
];
86 int (*fill_helper
)(struct bpf_test
*self
);
87 int expected_errcode
; /* used when FLAG_EXPECTED_FAIL is set in the aux */
88 __u8 frag_data
[MAX_DATA
];
89 int stack_depth
; /* for eBPF only, since tests don't call verifier */
92 /* Large test cases need separate allocation and fill handler. */
94 static int bpf_fill_maxinsns1(struct bpf_test
*self
)
96 unsigned int len
= BPF_MAXINSNS
;
97 struct sock_filter
*insn
;
101 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
105 for (i
= 0; i
< len
; i
++, k
--)
106 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, k
);
108 self
->u
.ptr
.insns
= insn
;
109 self
->u
.ptr
.len
= len
;
114 static int bpf_fill_maxinsns2(struct bpf_test
*self
)
116 unsigned int len
= BPF_MAXINSNS
;
117 struct sock_filter
*insn
;
120 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
124 for (i
= 0; i
< len
; i
++)
125 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
127 self
->u
.ptr
.insns
= insn
;
128 self
->u
.ptr
.len
= len
;
133 static int bpf_fill_maxinsns3(struct bpf_test
*self
)
135 unsigned int len
= BPF_MAXINSNS
;
136 struct sock_filter
*insn
;
137 struct rnd_state rnd
;
140 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
144 prandom_seed_state(&rnd
, 3141592653589793238ULL);
146 for (i
= 0; i
< len
- 1; i
++) {
147 __u32 k
= prandom_u32_state(&rnd
);
149 insn
[i
] = __BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, k
);
152 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
154 self
->u
.ptr
.insns
= insn
;
155 self
->u
.ptr
.len
= len
;
160 static int bpf_fill_maxinsns4(struct bpf_test
*self
)
162 unsigned int len
= BPF_MAXINSNS
+ 1;
163 struct sock_filter
*insn
;
166 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
170 for (i
= 0; i
< len
; i
++)
171 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
173 self
->u
.ptr
.insns
= insn
;
174 self
->u
.ptr
.len
= len
;
179 static int bpf_fill_maxinsns5(struct bpf_test
*self
)
181 unsigned int len
= BPF_MAXINSNS
;
182 struct sock_filter
*insn
;
185 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
189 insn
[0] = __BPF_JUMP(BPF_JMP
| BPF_JA
, len
- 2, 0, 0);
191 for (i
= 1; i
< len
- 1; i
++)
192 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
194 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xabababab);
196 self
->u
.ptr
.insns
= insn
;
197 self
->u
.ptr
.len
= len
;
202 static int bpf_fill_maxinsns6(struct bpf_test
*self
)
204 unsigned int len
= BPF_MAXINSNS
;
205 struct sock_filter
*insn
;
208 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
212 for (i
= 0; i
< len
- 1; i
++)
213 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
214 SKF_AD_VLAN_TAG_PRESENT
);
216 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
218 self
->u
.ptr
.insns
= insn
;
219 self
->u
.ptr
.len
= len
;
224 static int bpf_fill_maxinsns7(struct bpf_test
*self
)
226 unsigned int len
= BPF_MAXINSNS
;
227 struct sock_filter
*insn
;
230 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
234 for (i
= 0; i
< len
- 4; i
++)
235 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
238 insn
[len
- 4] = __BPF_STMT(BPF_MISC
| BPF_TAX
, 0);
239 insn
[len
- 3] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
241 insn
[len
- 2] = __BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0);
242 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
244 self
->u
.ptr
.insns
= insn
;
245 self
->u
.ptr
.len
= len
;
250 static int bpf_fill_maxinsns8(struct bpf_test
*self
)
252 unsigned int len
= BPF_MAXINSNS
;
253 struct sock_filter
*insn
;
254 int i
, jmp_off
= len
- 3;
256 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
260 insn
[0] = __BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff);
262 for (i
= 1; i
< len
- 1; i
++)
263 insn
[i
] = __BPF_JUMP(BPF_JMP
| BPF_JGT
, 0xffffffff, jmp_off
--, 0);
265 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
267 self
->u
.ptr
.insns
= insn
;
268 self
->u
.ptr
.len
= len
;
273 static int bpf_fill_maxinsns9(struct bpf_test
*self
)
275 unsigned int len
= BPF_MAXINSNS
;
276 struct bpf_insn
*insn
;
279 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
283 insn
[0] = BPF_JMP_IMM(BPF_JA
, 0, 0, len
- 2);
284 insn
[1] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xcbababab);
285 insn
[2] = BPF_EXIT_INSN();
287 for (i
= 3; i
< len
- 2; i
++)
288 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xfefefefe);
290 insn
[len
- 2] = BPF_EXIT_INSN();
291 insn
[len
- 1] = BPF_JMP_IMM(BPF_JA
, 0, 0, -(len
- 1));
293 self
->u
.ptr
.insns
= insn
;
294 self
->u
.ptr
.len
= len
;
299 static int bpf_fill_maxinsns10(struct bpf_test
*self
)
301 unsigned int len
= BPF_MAXINSNS
, hlen
= len
- 2;
302 struct bpf_insn
*insn
;
305 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
309 for (i
= 0; i
< hlen
/ 2; i
++)
310 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 2 - 2 * i
);
311 for (i
= hlen
- 1; i
> hlen
/ 2; i
--)
312 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 1 - 2 * i
);
314 insn
[hlen
/ 2] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
/ 2 - 1);
315 insn
[hlen
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xabababac);
316 insn
[hlen
+ 1] = BPF_EXIT_INSN();
318 self
->u
.ptr
.insns
= insn
;
319 self
->u
.ptr
.len
= len
;
324 static int __bpf_fill_ja(struct bpf_test
*self
, unsigned int len
,
327 struct sock_filter
*insn
;
331 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
335 rlen
= (len
% plen
) - 1;
337 for (i
= 0; i
+ plen
< len
; i
+= plen
)
338 for (j
= 0; j
< plen
; j
++)
339 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
,
341 for (j
= 0; j
< rlen
; j
++)
342 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
, rlen
- 1 - j
,
345 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xababcbac);
347 self
->u
.ptr
.insns
= insn
;
348 self
->u
.ptr
.len
= len
;
353 static int bpf_fill_maxinsns11(struct bpf_test
*self
)
355 /* Hits 70 passes on x86_64, so cannot get JITed there. */
356 return __bpf_fill_ja(self
, BPF_MAXINSNS
, 68);
359 static int bpf_fill_maxinsns12(struct bpf_test
*self
)
361 unsigned int len
= BPF_MAXINSNS
;
362 struct sock_filter
*insn
;
365 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
369 insn
[0] = __BPF_JUMP(BPF_JMP
| BPF_JA
, len
- 2, 0, 0);
371 for (i
= 1; i
< len
- 1; i
++)
372 insn
[i
] = __BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0);
374 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xabababab);
376 self
->u
.ptr
.insns
= insn
;
377 self
->u
.ptr
.len
= len
;
382 static int bpf_fill_maxinsns13(struct bpf_test
*self
)
384 unsigned int len
= BPF_MAXINSNS
;
385 struct sock_filter
*insn
;
388 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
392 for (i
= 0; i
< len
- 3; i
++)
393 insn
[i
] = __BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0);
395 insn
[len
- 3] = __BPF_STMT(BPF_LD
| BPF_IMM
, 0xabababab);
396 insn
[len
- 2] = __BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0);
397 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
399 self
->u
.ptr
.insns
= insn
;
400 self
->u
.ptr
.len
= len
;
405 static int bpf_fill_ja(struct bpf_test
*self
)
407 /* Hits exactly 11 passes on x86_64 JIT. */
408 return __bpf_fill_ja(self
, 12, 9);
411 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test
*self
)
413 unsigned int len
= BPF_MAXINSNS
;
414 struct sock_filter
*insn
;
417 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
421 for (i
= 0; i
< len
- 1; i
+= 2) {
422 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 0);
423 insn
[i
+ 1] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
424 SKF_AD_OFF
+ SKF_AD_CPU
);
427 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xbee);
429 self
->u
.ptr
.insns
= insn
;
430 self
->u
.ptr
.len
= len
;
435 static int __bpf_fill_stxdw(struct bpf_test
*self
, int size
)
437 unsigned int len
= BPF_MAXINSNS
;
438 struct bpf_insn
*insn
;
441 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
445 insn
[0] = BPF_ALU32_IMM(BPF_MOV
, R0
, 1);
446 insn
[1] = BPF_ST_MEM(size
, R10
, -40, 42);
448 for (i
= 2; i
< len
- 2; i
++)
449 insn
[i
] = BPF_STX_XADD(size
, R10
, R0
, -40);
451 insn
[len
- 2] = BPF_LDX_MEM(size
, R0
, R10
, -40);
452 insn
[len
- 1] = BPF_EXIT_INSN();
454 self
->u
.ptr
.insns
= insn
;
455 self
->u
.ptr
.len
= len
;
456 self
->stack_depth
= 40;
461 static int bpf_fill_stxw(struct bpf_test
*self
)
463 return __bpf_fill_stxdw(self
, BPF_W
);
466 static int bpf_fill_stxdw(struct bpf_test
*self
)
468 return __bpf_fill_stxdw(self
, BPF_DW
);
471 static struct bpf_test tests
[] = {
475 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
476 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
477 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
478 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
479 BPF_STMT(BPF_ALU
| BPF_NEG
, 0), /* A == -3 */
480 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
481 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
482 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
483 BPF_STMT(BPF_MISC
| BPF_TAX
, 0), /* X == len - 3 */
484 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
485 BPF_STMT(BPF_RET
| BPF_A
, 0)
488 { 10, 20, 30, 40, 50 },
489 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
494 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
495 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
496 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
497 BPF_STMT(BPF_RET
| BPF_A
, 0) /* A == len * 2 */
500 { 10, 20, 30, 40, 50 },
501 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
506 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
507 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 2),
508 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
509 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
510 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0xffffffff),
511 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 3),
512 BPF_STMT(BPF_RET
| BPF_A
, 0)
514 CLASSIC
| FLAG_NO_DATA
,
516 { { 0, 0xfffffffd } }
521 BPF_STMT(BPF_LD
| BPF_IMM
, 8),
522 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 2),
523 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
524 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
525 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
526 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
527 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
528 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x70000000),
529 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
530 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
531 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
532 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
533 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
534 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x70000000),
535 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
536 BPF_STMT(BPF_RET
| BPF_A
, 0)
538 CLASSIC
| FLAG_NO_DATA
,
540 { { 0, 0x20000000 } }
545 BPF_STMT(BPF_LD
| BPF_IMM
, 0xff),
546 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
547 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 27),
548 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
549 BPF_STMT(BPF_LD
| BPF_IMM
, 0xf),
550 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_K
, 0xf0),
551 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
552 BPF_STMT(BPF_RET
| BPF_A
, 0)
554 CLASSIC
| FLAG_NO_DATA
,
556 { { 0, 0x800000ff }, { 1, 0x800000ff } },
561 BPF_STMT(BPF_LD
| BPF_IMM
, 0), /* ld #0 */
562 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, 1, 0),
563 BPF_STMT(BPF_RET
| BPF_K
, 0),
564 BPF_STMT(BPF_RET
| BPF_K
, 1),
573 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
574 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, MAX_K
),
575 BPF_STMT(BPF_RET
| BPF_K
, 1)
579 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
584 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, 1000),
585 BPF_STMT(BPF_RET
| BPF_K
, 1)
589 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
594 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
),
595 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
596 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
+ 1),
597 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
598 BPF_STMT(BPF_RET
| BPF_A
, 0)
602 { { 1, 0 }, { 2, 3 } },
607 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_LL_OFF
- 1),
608 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
609 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
610 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
611 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
612 BPF_STMT(BPF_RET
| BPF_A
, 0)
616 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
621 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
),
622 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
623 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
+ 1),
624 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
625 BPF_STMT(BPF_RET
| BPF_A
, 0)
628 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
629 { { 15, 0 }, { 16, 3 } },
634 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_NET_OFF
- 15),
635 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
636 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
637 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
638 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
639 BPF_STMT(BPF_RET
| BPF_A
, 0)
642 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
643 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
648 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
649 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
650 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
651 BPF_STMT(BPF_RET
| BPF_K
, 1),
652 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
653 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
654 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
655 BPF_STMT(BPF_RET
| BPF_K
, 1),
656 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
657 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
658 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
659 BPF_STMT(BPF_RET
| BPF_K
, 1),
660 BPF_STMT(BPF_RET
| BPF_A
, 0)
664 { { 1, 3 }, { 10, 3 } },
669 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
670 SKF_AD_OFF
+ SKF_AD_MARK
),
671 BPF_STMT(BPF_RET
| BPF_A
, 0)
675 { { 1, SKB_MARK
}, { 10, SKB_MARK
} },
680 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
681 SKF_AD_OFF
+ SKF_AD_RXHASH
),
682 BPF_STMT(BPF_RET
| BPF_A
, 0)
686 { { 1, SKB_HASH
}, { 10, SKB_HASH
} },
691 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
692 SKF_AD_OFF
+ SKF_AD_QUEUE
),
693 BPF_STMT(BPF_RET
| BPF_A
, 0)
697 { { 1, SKB_QUEUE_MAP
}, { 10, SKB_QUEUE_MAP
} },
702 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 1),
703 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 20, 1, 0),
704 BPF_STMT(BPF_RET
| BPF_K
, 0),
705 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
706 SKF_AD_OFF
+ SKF_AD_PROTOCOL
),
707 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
708 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
709 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 30, 1, 0),
710 BPF_STMT(BPF_RET
| BPF_K
, 0),
711 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
712 BPF_STMT(BPF_RET
| BPF_A
, 0)
716 { { 10, ETH_P_IP
}, { 100, ETH_P_IP
} },
721 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
722 SKF_AD_OFF
+ SKF_AD_VLAN_TAG
),
723 BPF_STMT(BPF_RET
| BPF_A
, 0)
728 { 1, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
},
729 { 10, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
}
733 "LD_VLAN_TAG_PRESENT",
735 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
736 SKF_AD_OFF
+ SKF_AD_VLAN_TAG_PRESENT
),
737 BPF_STMT(BPF_RET
| BPF_A
, 0)
742 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
743 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
749 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
750 SKF_AD_OFF
+ SKF_AD_IFINDEX
),
751 BPF_STMT(BPF_RET
| BPF_A
, 0)
755 { { 1, SKB_DEV_IFINDEX
}, { 10, SKB_DEV_IFINDEX
} },
760 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
761 SKF_AD_OFF
+ SKF_AD_HATYPE
),
762 BPF_STMT(BPF_RET
| BPF_A
, 0)
766 { { 1, SKB_DEV_TYPE
}, { 10, SKB_DEV_TYPE
} },
771 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
772 SKF_AD_OFF
+ SKF_AD_CPU
),
773 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
774 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
775 SKF_AD_OFF
+ SKF_AD_CPU
),
776 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
777 BPF_STMT(BPF_RET
| BPF_A
, 0)
781 { { 1, 0 }, { 10, 0 } },
786 BPF_STMT(BPF_LDX
| BPF_IMM
, 2),
787 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
788 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
789 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
790 SKF_AD_OFF
+ SKF_AD_NLATTR
),
791 BPF_STMT(BPF_RET
| BPF_A
, 0)
795 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
797 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
799 { { 4, 0 }, { 20, 6 } },
804 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
805 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
806 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
807 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
808 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
809 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
810 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
811 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
812 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
813 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
814 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
815 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
816 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
817 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
818 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
819 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
820 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
821 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
822 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
823 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
824 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
825 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
826 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
827 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
828 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
829 BPF_STMT(BPF_RET
| BPF_A
, 0)
833 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
835 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
837 { { 4, 0 }, { 20, 10 } },
842 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
843 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
844 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
845 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
846 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
847 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
848 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
849 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
850 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
851 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
852 BPF_STMT(BPF_RET
| BPF_A
, 0)
855 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
856 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
857 * id 9737, seq 1, length 64
859 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
860 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
862 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
863 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
864 { { 30, 0 }, { 100, 42 } },
869 BPF_STMT(BPF_LD
| BPF_IMM
, 10),
870 BPF_STMT(BPF_LDX
| BPF_IMM
, 300),
871 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
872 SKF_AD_OFF
+ SKF_AD_ALU_XOR_X
),
873 BPF_STMT(BPF_RET
| BPF_A
, 0)
877 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
882 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
883 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
884 BPF_STMT(BPF_ALU
| BPF_RSH
, 1),
885 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
886 BPF_STMT(BPF_ST
, 1), /* M1 = 1 ^ len */
887 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_K
, 0x80000000),
888 BPF_STMT(BPF_ST
, 2), /* M2 = 1 ^ len ^ 0x80000000 */
889 BPF_STMT(BPF_STX
, 15), /* M3 = len */
890 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
891 BPF_STMT(BPF_LD
| BPF_MEM
, 2),
892 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
893 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
894 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
895 BPF_STMT(BPF_RET
| BPF_A
, 0)
899 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
904 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
905 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
906 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 0, 1),
907 BPF_STMT(BPF_RET
| BPF_K
, 1),
908 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
912 { { 1, 0 }, { 3, 1 }, { 4, MAX_K
} },
917 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
918 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
919 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_X
, 0, 0, 1),
920 BPF_STMT(BPF_RET
| BPF_K
, 1),
921 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
925 { { 2, 0 }, { 3, 1 }, { 4, MAX_K
} },
928 "JGE (jt 0), test 1",
930 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
931 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
932 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
933 BPF_STMT(BPF_RET
| BPF_K
, 1),
934 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
938 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
941 "JGE (jt 0), test 2",
943 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
944 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
945 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
946 BPF_STMT(BPF_RET
| BPF_K
, 1),
947 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
951 { { 4, 1 }, { 5, 1 }, { 6, MAX_K
} },
956 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
957 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, MAX_K
),
958 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 1, 1, 0),
959 BPF_STMT(BPF_RET
| BPF_K
, 10),
960 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 2, 1, 0),
961 BPF_STMT(BPF_RET
| BPF_K
, 20),
962 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 3, 1, 0),
963 BPF_STMT(BPF_RET
| BPF_K
, 30),
964 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 4, 1, 0),
965 BPF_STMT(BPF_RET
| BPF_K
, 40),
966 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
970 { { 1, 20 }, { 3, 40 }, { 5, MAX_K
} },
975 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
976 BPF_JUMP(BPF_JMP
| BPF_JA
, 1, 1, 1),
977 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
978 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
979 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
980 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
981 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, 4),
982 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
983 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
984 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 1, 0, 1),
985 BPF_STMT(BPF_RET
| BPF_K
, 10),
986 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x80000000, 0, 1),
987 BPF_STMT(BPF_RET
| BPF_K
, 20),
988 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
989 BPF_STMT(BPF_RET
| BPF_K
, 30),
990 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
991 BPF_STMT(BPF_RET
| BPF_K
, 30),
992 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
993 BPF_STMT(BPF_RET
| BPF_K
, 30),
994 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
995 BPF_STMT(BPF_RET
| BPF_K
, 30),
996 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
997 BPF_STMT(BPF_RET
| BPF_K
, 30),
998 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1001 { 0, 0xAA, 0x55, 1 },
1002 { { 4, 10 }, { 5, 20 }, { 6, MAX_K
} },
1007 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1008 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 0, 8), /* IPv6 */
1009 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 20),
1010 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1011 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1012 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 17),
1013 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 54),
1014 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 14, 0),
1015 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 56),
1016 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 12, 13),
1017 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0800, 0, 12), /* IPv4 */
1018 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1019 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1020 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1021 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 8),
1022 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1023 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 6, 0),
1024 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1025 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1026 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1027 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1028 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 1),
1029 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1030 BPF_STMT(BPF_RET
| BPF_K
, 0),
1033 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1034 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1035 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1036 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1038 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1039 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1041 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1042 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1043 0x0a, 0x01, 0x01, 0x95, /* ip src */
1044 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1046 0x00, 0x16 /* dst port */ },
1047 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1052 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1053 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1054 * (len > 115 or len < 30000000000)' -d
1056 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1057 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 30, 0),
1058 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x800, 0, 29),
1059 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1060 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 0, 27),
1061 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1062 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 25, 0),
1063 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1064 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1065 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1066 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1067 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 20),
1068 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 16),
1069 BPF_STMT(BPF_ST
, 1),
1070 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 14),
1071 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf),
1072 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 2),
1073 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x5), /* libpcap emits K on TAX */
1074 BPF_STMT(BPF_LD
| BPF_MEM
, 1),
1075 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
1076 BPF_STMT(BPF_ST
, 5),
1077 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1078 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 26),
1079 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
1080 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 2),
1081 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x9), /* libpcap emits K on TAX */
1082 BPF_STMT(BPF_LD
| BPF_MEM
, 5),
1083 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 4, 0),
1084 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
1085 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_K
, 0x73, 1, 0),
1086 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 0xfc23ac00, 1, 0),
1087 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1088 BPF_STMT(BPF_RET
| BPF_K
, 0),
1091 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1092 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1094 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1095 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1096 0x0a, 0x01, 0x01, 0x95, /* ip src */
1097 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1099 0x00, 0x16 /* dst port */ },
1100 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1105 /* check that unitialized X and A contain zeros */
1106 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1107 BPF_STMT(BPF_RET
| BPF_A
, 0)
1116 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1117 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
1118 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1119 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1120 BPF_ALU64_IMM(BPF_ADD
, R1
, -1),
1121 BPF_ALU64_IMM(BPF_MUL
, R1
, 3),
1122 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
1127 { { 0, 0xfffffffd } }
1132 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1133 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1134 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1135 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1136 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xfffffffd, 1),
1138 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1148 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1149 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
1150 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1151 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1152 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1153 BPF_JMP_IMM(BPF_JEQ
, R1
, 0x2ffffff, 1),
1155 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1165 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1166 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1167 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1168 BPF_ALU32_REG(BPF_MUL
, R1
, R2
),
1169 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1170 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xffffff, 1),
1172 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1180 /* Have to test all register combinations, since
1181 * JITing of different registers will produce
1182 * different asm code.
1186 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1187 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1188 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1189 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1190 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1191 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1192 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1193 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1194 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1195 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1196 BPF_ALU64_IMM(BPF_ADD
, R0
, 20),
1197 BPF_ALU64_IMM(BPF_ADD
, R1
, 20),
1198 BPF_ALU64_IMM(BPF_ADD
, R2
, 20),
1199 BPF_ALU64_IMM(BPF_ADD
, R3
, 20),
1200 BPF_ALU64_IMM(BPF_ADD
, R4
, 20),
1201 BPF_ALU64_IMM(BPF_ADD
, R5
, 20),
1202 BPF_ALU64_IMM(BPF_ADD
, R6
, 20),
1203 BPF_ALU64_IMM(BPF_ADD
, R7
, 20),
1204 BPF_ALU64_IMM(BPF_ADD
, R8
, 20),
1205 BPF_ALU64_IMM(BPF_ADD
, R9
, 20),
1206 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1207 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1208 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1209 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1210 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1211 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1212 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1213 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1214 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1215 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1216 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1217 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1218 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1219 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1220 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1221 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1222 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1223 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1224 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1225 BPF_ALU64_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1226 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1228 BPF_ALU64_REG(BPF_ADD
, R1
, R0
),
1229 BPF_ALU64_REG(BPF_ADD
, R1
, R1
),
1230 BPF_ALU64_REG(BPF_ADD
, R1
, R2
),
1231 BPF_ALU64_REG(BPF_ADD
, R1
, R3
),
1232 BPF_ALU64_REG(BPF_ADD
, R1
, R4
),
1233 BPF_ALU64_REG(BPF_ADD
, R1
, R5
),
1234 BPF_ALU64_REG(BPF_ADD
, R1
, R6
),
1235 BPF_ALU64_REG(BPF_ADD
, R1
, R7
),
1236 BPF_ALU64_REG(BPF_ADD
, R1
, R8
),
1237 BPF_ALU64_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1238 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1240 BPF_ALU64_REG(BPF_ADD
, R2
, R0
),
1241 BPF_ALU64_REG(BPF_ADD
, R2
, R1
),
1242 BPF_ALU64_REG(BPF_ADD
, R2
, R2
),
1243 BPF_ALU64_REG(BPF_ADD
, R2
, R3
),
1244 BPF_ALU64_REG(BPF_ADD
, R2
, R4
),
1245 BPF_ALU64_REG(BPF_ADD
, R2
, R5
),
1246 BPF_ALU64_REG(BPF_ADD
, R2
, R6
),
1247 BPF_ALU64_REG(BPF_ADD
, R2
, R7
),
1248 BPF_ALU64_REG(BPF_ADD
, R2
, R8
),
1249 BPF_ALU64_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1250 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1252 BPF_ALU64_REG(BPF_ADD
, R3
, R0
),
1253 BPF_ALU64_REG(BPF_ADD
, R3
, R1
),
1254 BPF_ALU64_REG(BPF_ADD
, R3
, R2
),
1255 BPF_ALU64_REG(BPF_ADD
, R3
, R3
),
1256 BPF_ALU64_REG(BPF_ADD
, R3
, R4
),
1257 BPF_ALU64_REG(BPF_ADD
, R3
, R5
),
1258 BPF_ALU64_REG(BPF_ADD
, R3
, R6
),
1259 BPF_ALU64_REG(BPF_ADD
, R3
, R7
),
1260 BPF_ALU64_REG(BPF_ADD
, R3
, R8
),
1261 BPF_ALU64_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1262 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1264 BPF_ALU64_REG(BPF_ADD
, R4
, R0
),
1265 BPF_ALU64_REG(BPF_ADD
, R4
, R1
),
1266 BPF_ALU64_REG(BPF_ADD
, R4
, R2
),
1267 BPF_ALU64_REG(BPF_ADD
, R4
, R3
),
1268 BPF_ALU64_REG(BPF_ADD
, R4
, R4
),
1269 BPF_ALU64_REG(BPF_ADD
, R4
, R5
),
1270 BPF_ALU64_REG(BPF_ADD
, R4
, R6
),
1271 BPF_ALU64_REG(BPF_ADD
, R4
, R7
),
1272 BPF_ALU64_REG(BPF_ADD
, R4
, R8
),
1273 BPF_ALU64_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1274 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1276 BPF_ALU64_REG(BPF_ADD
, R5
, R0
),
1277 BPF_ALU64_REG(BPF_ADD
, R5
, R1
),
1278 BPF_ALU64_REG(BPF_ADD
, R5
, R2
),
1279 BPF_ALU64_REG(BPF_ADD
, R5
, R3
),
1280 BPF_ALU64_REG(BPF_ADD
, R5
, R4
),
1281 BPF_ALU64_REG(BPF_ADD
, R5
, R5
),
1282 BPF_ALU64_REG(BPF_ADD
, R5
, R6
),
1283 BPF_ALU64_REG(BPF_ADD
, R5
, R7
),
1284 BPF_ALU64_REG(BPF_ADD
, R5
, R8
),
1285 BPF_ALU64_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1286 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1288 BPF_ALU64_REG(BPF_ADD
, R6
, R0
),
1289 BPF_ALU64_REG(BPF_ADD
, R6
, R1
),
1290 BPF_ALU64_REG(BPF_ADD
, R6
, R2
),
1291 BPF_ALU64_REG(BPF_ADD
, R6
, R3
),
1292 BPF_ALU64_REG(BPF_ADD
, R6
, R4
),
1293 BPF_ALU64_REG(BPF_ADD
, R6
, R5
),
1294 BPF_ALU64_REG(BPF_ADD
, R6
, R6
),
1295 BPF_ALU64_REG(BPF_ADD
, R6
, R7
),
1296 BPF_ALU64_REG(BPF_ADD
, R6
, R8
),
1297 BPF_ALU64_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1298 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1300 BPF_ALU64_REG(BPF_ADD
, R7
, R0
),
1301 BPF_ALU64_REG(BPF_ADD
, R7
, R1
),
1302 BPF_ALU64_REG(BPF_ADD
, R7
, R2
),
1303 BPF_ALU64_REG(BPF_ADD
, R7
, R3
),
1304 BPF_ALU64_REG(BPF_ADD
, R7
, R4
),
1305 BPF_ALU64_REG(BPF_ADD
, R7
, R5
),
1306 BPF_ALU64_REG(BPF_ADD
, R7
, R6
),
1307 BPF_ALU64_REG(BPF_ADD
, R7
, R7
),
1308 BPF_ALU64_REG(BPF_ADD
, R7
, R8
),
1309 BPF_ALU64_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1310 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1312 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1313 BPF_ALU64_REG(BPF_ADD
, R8
, R1
),
1314 BPF_ALU64_REG(BPF_ADD
, R8
, R2
),
1315 BPF_ALU64_REG(BPF_ADD
, R8
, R3
),
1316 BPF_ALU64_REG(BPF_ADD
, R8
, R4
),
1317 BPF_ALU64_REG(BPF_ADD
, R8
, R5
),
1318 BPF_ALU64_REG(BPF_ADD
, R8
, R6
),
1319 BPF_ALU64_REG(BPF_ADD
, R8
, R7
),
1320 BPF_ALU64_REG(BPF_ADD
, R8
, R8
),
1321 BPF_ALU64_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1322 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1324 BPF_ALU64_REG(BPF_ADD
, R9
, R0
),
1325 BPF_ALU64_REG(BPF_ADD
, R9
, R1
),
1326 BPF_ALU64_REG(BPF_ADD
, R9
, R2
),
1327 BPF_ALU64_REG(BPF_ADD
, R9
, R3
),
1328 BPF_ALU64_REG(BPF_ADD
, R9
, R4
),
1329 BPF_ALU64_REG(BPF_ADD
, R9
, R5
),
1330 BPF_ALU64_REG(BPF_ADD
, R9
, R6
),
1331 BPF_ALU64_REG(BPF_ADD
, R9
, R7
),
1332 BPF_ALU64_REG(BPF_ADD
, R9
, R8
),
1333 BPF_ALU64_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1334 BPF_ALU64_REG(BPF_MOV
, R0
, R9
),
1344 BPF_ALU32_IMM(BPF_MOV
, R0
, 20),
1345 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
1346 BPF_ALU32_IMM(BPF_MOV
, R2
, 2),
1347 BPF_ALU32_IMM(BPF_MOV
, R3
, 3),
1348 BPF_ALU32_IMM(BPF_MOV
, R4
, 4),
1349 BPF_ALU32_IMM(BPF_MOV
, R5
, 5),
1350 BPF_ALU32_IMM(BPF_MOV
, R6
, 6),
1351 BPF_ALU32_IMM(BPF_MOV
, R7
, 7),
1352 BPF_ALU32_IMM(BPF_MOV
, R8
, 8),
1353 BPF_ALU32_IMM(BPF_MOV
, R9
, 9),
1354 BPF_ALU64_IMM(BPF_ADD
, R1
, 10),
1355 BPF_ALU64_IMM(BPF_ADD
, R2
, 10),
1356 BPF_ALU64_IMM(BPF_ADD
, R3
, 10),
1357 BPF_ALU64_IMM(BPF_ADD
, R4
, 10),
1358 BPF_ALU64_IMM(BPF_ADD
, R5
, 10),
1359 BPF_ALU64_IMM(BPF_ADD
, R6
, 10),
1360 BPF_ALU64_IMM(BPF_ADD
, R7
, 10),
1361 BPF_ALU64_IMM(BPF_ADD
, R8
, 10),
1362 BPF_ALU64_IMM(BPF_ADD
, R9
, 10),
1363 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
1364 BPF_ALU32_REG(BPF_ADD
, R0
, R2
),
1365 BPF_ALU32_REG(BPF_ADD
, R0
, R3
),
1366 BPF_ALU32_REG(BPF_ADD
, R0
, R4
),
1367 BPF_ALU32_REG(BPF_ADD
, R0
, R5
),
1368 BPF_ALU32_REG(BPF_ADD
, R0
, R6
),
1369 BPF_ALU32_REG(BPF_ADD
, R0
, R7
),
1370 BPF_ALU32_REG(BPF_ADD
, R0
, R8
),
1371 BPF_ALU32_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1372 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1374 BPF_ALU32_REG(BPF_ADD
, R1
, R0
),
1375 BPF_ALU32_REG(BPF_ADD
, R1
, R1
),
1376 BPF_ALU32_REG(BPF_ADD
, R1
, R2
),
1377 BPF_ALU32_REG(BPF_ADD
, R1
, R3
),
1378 BPF_ALU32_REG(BPF_ADD
, R1
, R4
),
1379 BPF_ALU32_REG(BPF_ADD
, R1
, R5
),
1380 BPF_ALU32_REG(BPF_ADD
, R1
, R6
),
1381 BPF_ALU32_REG(BPF_ADD
, R1
, R7
),
1382 BPF_ALU32_REG(BPF_ADD
, R1
, R8
),
1383 BPF_ALU32_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1384 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1386 BPF_ALU32_REG(BPF_ADD
, R2
, R0
),
1387 BPF_ALU32_REG(BPF_ADD
, R2
, R1
),
1388 BPF_ALU32_REG(BPF_ADD
, R2
, R2
),
1389 BPF_ALU32_REG(BPF_ADD
, R2
, R3
),
1390 BPF_ALU32_REG(BPF_ADD
, R2
, R4
),
1391 BPF_ALU32_REG(BPF_ADD
, R2
, R5
),
1392 BPF_ALU32_REG(BPF_ADD
, R2
, R6
),
1393 BPF_ALU32_REG(BPF_ADD
, R2
, R7
),
1394 BPF_ALU32_REG(BPF_ADD
, R2
, R8
),
1395 BPF_ALU32_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1396 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1398 BPF_ALU32_REG(BPF_ADD
, R3
, R0
),
1399 BPF_ALU32_REG(BPF_ADD
, R3
, R1
),
1400 BPF_ALU32_REG(BPF_ADD
, R3
, R2
),
1401 BPF_ALU32_REG(BPF_ADD
, R3
, R3
),
1402 BPF_ALU32_REG(BPF_ADD
, R3
, R4
),
1403 BPF_ALU32_REG(BPF_ADD
, R3
, R5
),
1404 BPF_ALU32_REG(BPF_ADD
, R3
, R6
),
1405 BPF_ALU32_REG(BPF_ADD
, R3
, R7
),
1406 BPF_ALU32_REG(BPF_ADD
, R3
, R8
),
1407 BPF_ALU32_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1408 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1410 BPF_ALU32_REG(BPF_ADD
, R4
, R0
),
1411 BPF_ALU32_REG(BPF_ADD
, R4
, R1
),
1412 BPF_ALU32_REG(BPF_ADD
, R4
, R2
),
1413 BPF_ALU32_REG(BPF_ADD
, R4
, R3
),
1414 BPF_ALU32_REG(BPF_ADD
, R4
, R4
),
1415 BPF_ALU32_REG(BPF_ADD
, R4
, R5
),
1416 BPF_ALU32_REG(BPF_ADD
, R4
, R6
),
1417 BPF_ALU32_REG(BPF_ADD
, R4
, R7
),
1418 BPF_ALU32_REG(BPF_ADD
, R4
, R8
),
1419 BPF_ALU32_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1420 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1422 BPF_ALU32_REG(BPF_ADD
, R5
, R0
),
1423 BPF_ALU32_REG(BPF_ADD
, R5
, R1
),
1424 BPF_ALU32_REG(BPF_ADD
, R5
, R2
),
1425 BPF_ALU32_REG(BPF_ADD
, R5
, R3
),
1426 BPF_ALU32_REG(BPF_ADD
, R5
, R4
),
1427 BPF_ALU32_REG(BPF_ADD
, R5
, R5
),
1428 BPF_ALU32_REG(BPF_ADD
, R5
, R6
),
1429 BPF_ALU32_REG(BPF_ADD
, R5
, R7
),
1430 BPF_ALU32_REG(BPF_ADD
, R5
, R8
),
1431 BPF_ALU32_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1432 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1434 BPF_ALU32_REG(BPF_ADD
, R6
, R0
),
1435 BPF_ALU32_REG(BPF_ADD
, R6
, R1
),
1436 BPF_ALU32_REG(BPF_ADD
, R6
, R2
),
1437 BPF_ALU32_REG(BPF_ADD
, R6
, R3
),
1438 BPF_ALU32_REG(BPF_ADD
, R6
, R4
),
1439 BPF_ALU32_REG(BPF_ADD
, R6
, R5
),
1440 BPF_ALU32_REG(BPF_ADD
, R6
, R6
),
1441 BPF_ALU32_REG(BPF_ADD
, R6
, R7
),
1442 BPF_ALU32_REG(BPF_ADD
, R6
, R8
),
1443 BPF_ALU32_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1444 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1446 BPF_ALU32_REG(BPF_ADD
, R7
, R0
),
1447 BPF_ALU32_REG(BPF_ADD
, R7
, R1
),
1448 BPF_ALU32_REG(BPF_ADD
, R7
, R2
),
1449 BPF_ALU32_REG(BPF_ADD
, R7
, R3
),
1450 BPF_ALU32_REG(BPF_ADD
, R7
, R4
),
1451 BPF_ALU32_REG(BPF_ADD
, R7
, R5
),
1452 BPF_ALU32_REG(BPF_ADD
, R7
, R6
),
1453 BPF_ALU32_REG(BPF_ADD
, R7
, R7
),
1454 BPF_ALU32_REG(BPF_ADD
, R7
, R8
),
1455 BPF_ALU32_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1456 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1458 BPF_ALU32_REG(BPF_ADD
, R8
, R0
),
1459 BPF_ALU32_REG(BPF_ADD
, R8
, R1
),
1460 BPF_ALU32_REG(BPF_ADD
, R8
, R2
),
1461 BPF_ALU32_REG(BPF_ADD
, R8
, R3
),
1462 BPF_ALU32_REG(BPF_ADD
, R8
, R4
),
1463 BPF_ALU32_REG(BPF_ADD
, R8
, R5
),
1464 BPF_ALU32_REG(BPF_ADD
, R8
, R6
),
1465 BPF_ALU32_REG(BPF_ADD
, R8
, R7
),
1466 BPF_ALU32_REG(BPF_ADD
, R8
, R8
),
1467 BPF_ALU32_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1468 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1470 BPF_ALU32_REG(BPF_ADD
, R9
, R0
),
1471 BPF_ALU32_REG(BPF_ADD
, R9
, R1
),
1472 BPF_ALU32_REG(BPF_ADD
, R9
, R2
),
1473 BPF_ALU32_REG(BPF_ADD
, R9
, R3
),
1474 BPF_ALU32_REG(BPF_ADD
, R9
, R4
),
1475 BPF_ALU32_REG(BPF_ADD
, R9
, R5
),
1476 BPF_ALU32_REG(BPF_ADD
, R9
, R6
),
1477 BPF_ALU32_REG(BPF_ADD
, R9
, R7
),
1478 BPF_ALU32_REG(BPF_ADD
, R9
, R8
),
1479 BPF_ALU32_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1480 BPF_ALU32_REG(BPF_MOV
, R0
, R9
),
1487 { /* Mainly checking JIT here. */
1490 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1491 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1492 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1493 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1494 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1495 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1496 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1497 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1498 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1499 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1500 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1501 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1502 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1503 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1504 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1505 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1506 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1507 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1508 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1509 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1510 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1511 BPF_JMP_IMM(BPF_JEQ
, R0
, -55, 1),
1513 BPF_ALU64_REG(BPF_SUB
, R1
, R0
),
1514 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1515 BPF_ALU64_REG(BPF_SUB
, R1
, R3
),
1516 BPF_ALU64_REG(BPF_SUB
, R1
, R4
),
1517 BPF_ALU64_REG(BPF_SUB
, R1
, R5
),
1518 BPF_ALU64_REG(BPF_SUB
, R1
, R6
),
1519 BPF_ALU64_REG(BPF_SUB
, R1
, R7
),
1520 BPF_ALU64_REG(BPF_SUB
, R1
, R8
),
1521 BPF_ALU64_REG(BPF_SUB
, R1
, R9
),
1522 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1523 BPF_ALU64_REG(BPF_SUB
, R2
, R0
),
1524 BPF_ALU64_REG(BPF_SUB
, R2
, R1
),
1525 BPF_ALU64_REG(BPF_SUB
, R2
, R3
),
1526 BPF_ALU64_REG(BPF_SUB
, R2
, R4
),
1527 BPF_ALU64_REG(BPF_SUB
, R2
, R5
),
1528 BPF_ALU64_REG(BPF_SUB
, R2
, R6
),
1529 BPF_ALU64_REG(BPF_SUB
, R2
, R7
),
1530 BPF_ALU64_REG(BPF_SUB
, R2
, R8
),
1531 BPF_ALU64_REG(BPF_SUB
, R2
, R9
),
1532 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1533 BPF_ALU64_REG(BPF_SUB
, R3
, R0
),
1534 BPF_ALU64_REG(BPF_SUB
, R3
, R1
),
1535 BPF_ALU64_REG(BPF_SUB
, R3
, R2
),
1536 BPF_ALU64_REG(BPF_SUB
, R3
, R4
),
1537 BPF_ALU64_REG(BPF_SUB
, R3
, R5
),
1538 BPF_ALU64_REG(BPF_SUB
, R3
, R6
),
1539 BPF_ALU64_REG(BPF_SUB
, R3
, R7
),
1540 BPF_ALU64_REG(BPF_SUB
, R3
, R8
),
1541 BPF_ALU64_REG(BPF_SUB
, R3
, R9
),
1542 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1543 BPF_ALU64_REG(BPF_SUB
, R4
, R0
),
1544 BPF_ALU64_REG(BPF_SUB
, R4
, R1
),
1545 BPF_ALU64_REG(BPF_SUB
, R4
, R2
),
1546 BPF_ALU64_REG(BPF_SUB
, R4
, R3
),
1547 BPF_ALU64_REG(BPF_SUB
, R4
, R5
),
1548 BPF_ALU64_REG(BPF_SUB
, R4
, R6
),
1549 BPF_ALU64_REG(BPF_SUB
, R4
, R7
),
1550 BPF_ALU64_REG(BPF_SUB
, R4
, R8
),
1551 BPF_ALU64_REG(BPF_SUB
, R4
, R9
),
1552 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1553 BPF_ALU64_REG(BPF_SUB
, R5
, R0
),
1554 BPF_ALU64_REG(BPF_SUB
, R5
, R1
),
1555 BPF_ALU64_REG(BPF_SUB
, R5
, R2
),
1556 BPF_ALU64_REG(BPF_SUB
, R5
, R3
),
1557 BPF_ALU64_REG(BPF_SUB
, R5
, R4
),
1558 BPF_ALU64_REG(BPF_SUB
, R5
, R6
),
1559 BPF_ALU64_REG(BPF_SUB
, R5
, R7
),
1560 BPF_ALU64_REG(BPF_SUB
, R5
, R8
),
1561 BPF_ALU64_REG(BPF_SUB
, R5
, R9
),
1562 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1563 BPF_ALU64_REG(BPF_SUB
, R6
, R0
),
1564 BPF_ALU64_REG(BPF_SUB
, R6
, R1
),
1565 BPF_ALU64_REG(BPF_SUB
, R6
, R2
),
1566 BPF_ALU64_REG(BPF_SUB
, R6
, R3
),
1567 BPF_ALU64_REG(BPF_SUB
, R6
, R4
),
1568 BPF_ALU64_REG(BPF_SUB
, R6
, R5
),
1569 BPF_ALU64_REG(BPF_SUB
, R6
, R7
),
1570 BPF_ALU64_REG(BPF_SUB
, R6
, R8
),
1571 BPF_ALU64_REG(BPF_SUB
, R6
, R9
),
1572 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1573 BPF_ALU64_REG(BPF_SUB
, R7
, R0
),
1574 BPF_ALU64_REG(BPF_SUB
, R7
, R1
),
1575 BPF_ALU64_REG(BPF_SUB
, R7
, R2
),
1576 BPF_ALU64_REG(BPF_SUB
, R7
, R3
),
1577 BPF_ALU64_REG(BPF_SUB
, R7
, R4
),
1578 BPF_ALU64_REG(BPF_SUB
, R7
, R5
),
1579 BPF_ALU64_REG(BPF_SUB
, R7
, R6
),
1580 BPF_ALU64_REG(BPF_SUB
, R7
, R8
),
1581 BPF_ALU64_REG(BPF_SUB
, R7
, R9
),
1582 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1583 BPF_ALU64_REG(BPF_SUB
, R8
, R0
),
1584 BPF_ALU64_REG(BPF_SUB
, R8
, R1
),
1585 BPF_ALU64_REG(BPF_SUB
, R8
, R2
),
1586 BPF_ALU64_REG(BPF_SUB
, R8
, R3
),
1587 BPF_ALU64_REG(BPF_SUB
, R8
, R4
),
1588 BPF_ALU64_REG(BPF_SUB
, R8
, R5
),
1589 BPF_ALU64_REG(BPF_SUB
, R8
, R6
),
1590 BPF_ALU64_REG(BPF_SUB
, R8
, R7
),
1591 BPF_ALU64_REG(BPF_SUB
, R8
, R9
),
1592 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1593 BPF_ALU64_REG(BPF_SUB
, R9
, R0
),
1594 BPF_ALU64_REG(BPF_SUB
, R9
, R1
),
1595 BPF_ALU64_REG(BPF_SUB
, R9
, R2
),
1596 BPF_ALU64_REG(BPF_SUB
, R9
, R3
),
1597 BPF_ALU64_REG(BPF_SUB
, R9
, R4
),
1598 BPF_ALU64_REG(BPF_SUB
, R9
, R5
),
1599 BPF_ALU64_REG(BPF_SUB
, R9
, R6
),
1600 BPF_ALU64_REG(BPF_SUB
, R9
, R7
),
1601 BPF_ALU64_REG(BPF_SUB
, R9
, R8
),
1602 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1603 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1604 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
1605 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1606 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1607 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1608 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1609 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1610 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1611 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1612 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1613 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1620 { /* Mainly checking JIT here. */
1623 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1624 BPF_ALU64_REG(BPF_XOR
, R1
, R1
),
1625 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 1),
1627 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1628 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1629 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1630 BPF_ALU64_REG(BPF_XOR
, R2
, R2
),
1631 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
1633 BPF_ALU64_REG(BPF_SUB
, R2
, R2
),
1634 BPF_ALU64_REG(BPF_XOR
, R3
, R3
),
1635 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1636 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1637 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 1),
1639 BPF_ALU64_REG(BPF_SUB
, R3
, R3
),
1640 BPF_ALU64_REG(BPF_XOR
, R4
, R4
),
1641 BPF_ALU64_IMM(BPF_MOV
, R2
, 1),
1642 BPF_ALU64_IMM(BPF_MOV
, R5
, -1),
1643 BPF_JMP_REG(BPF_JEQ
, R3
, R4
, 1),
1645 BPF_ALU64_REG(BPF_SUB
, R4
, R4
),
1646 BPF_ALU64_REG(BPF_XOR
, R5
, R5
),
1647 BPF_ALU64_IMM(BPF_MOV
, R3
, 1),
1648 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
1649 BPF_JMP_REG(BPF_JEQ
, R5
, R4
, 1),
1651 BPF_ALU64_IMM(BPF_MOV
, R5
, 1),
1652 BPF_ALU64_REG(BPF_SUB
, R5
, R5
),
1653 BPF_ALU64_REG(BPF_XOR
, R6
, R6
),
1654 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1655 BPF_ALU64_IMM(BPF_MOV
, R8
, -1),
1656 BPF_JMP_REG(BPF_JEQ
, R5
, R6
, 1),
1658 BPF_ALU64_REG(BPF_SUB
, R6
, R6
),
1659 BPF_ALU64_REG(BPF_XOR
, R7
, R7
),
1660 BPF_JMP_REG(BPF_JEQ
, R7
, R6
, 1),
1662 BPF_ALU64_REG(BPF_SUB
, R7
, R7
),
1663 BPF_ALU64_REG(BPF_XOR
, R8
, R8
),
1664 BPF_JMP_REG(BPF_JEQ
, R7
, R8
, 1),
1666 BPF_ALU64_REG(BPF_SUB
, R8
, R8
),
1667 BPF_ALU64_REG(BPF_XOR
, R9
, R9
),
1668 BPF_JMP_REG(BPF_JEQ
, R9
, R8
, 1),
1670 BPF_ALU64_REG(BPF_SUB
, R9
, R9
),
1671 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1672 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 1),
1674 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1675 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1676 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 2),
1677 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1679 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1686 { /* Mainly checking JIT here. */
1689 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1690 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1691 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1692 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1693 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1694 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1695 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1696 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1697 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1698 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1699 BPF_ALU64_REG(BPF_MUL
, R0
, R0
),
1700 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
1701 BPF_ALU64_REG(BPF_MUL
, R0
, R2
),
1702 BPF_ALU64_REG(BPF_MUL
, R0
, R3
),
1703 BPF_ALU64_REG(BPF_MUL
, R0
, R4
),
1704 BPF_ALU64_REG(BPF_MUL
, R0
, R5
),
1705 BPF_ALU64_REG(BPF_MUL
, R0
, R6
),
1706 BPF_ALU64_REG(BPF_MUL
, R0
, R7
),
1707 BPF_ALU64_REG(BPF_MUL
, R0
, R8
),
1708 BPF_ALU64_REG(BPF_MUL
, R0
, R9
),
1709 BPF_ALU64_IMM(BPF_MUL
, R0
, 10),
1710 BPF_JMP_IMM(BPF_JEQ
, R0
, 439084800, 1),
1712 BPF_ALU64_REG(BPF_MUL
, R1
, R0
),
1713 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1714 BPF_ALU64_REG(BPF_MUL
, R1
, R3
),
1715 BPF_ALU64_REG(BPF_MUL
, R1
, R4
),
1716 BPF_ALU64_REG(BPF_MUL
, R1
, R5
),
1717 BPF_ALU64_REG(BPF_MUL
, R1
, R6
),
1718 BPF_ALU64_REG(BPF_MUL
, R1
, R7
),
1719 BPF_ALU64_REG(BPF_MUL
, R1
, R8
),
1720 BPF_ALU64_REG(BPF_MUL
, R1
, R9
),
1721 BPF_ALU64_IMM(BPF_MUL
, R1
, 10),
1722 BPF_ALU64_REG(BPF_MOV
, R2
, R1
),
1723 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1724 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5a924, 1),
1726 BPF_ALU64_IMM(BPF_LSH
, R1
, 32),
1727 BPF_ALU64_IMM(BPF_ARSH
, R1
, 32),
1728 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xebb90000, 1),
1730 BPF_ALU64_REG(BPF_MUL
, R2
, R0
),
1731 BPF_ALU64_REG(BPF_MUL
, R2
, R1
),
1732 BPF_ALU64_REG(BPF_MUL
, R2
, R3
),
1733 BPF_ALU64_REG(BPF_MUL
, R2
, R4
),
1734 BPF_ALU64_REG(BPF_MUL
, R2
, R5
),
1735 BPF_ALU64_REG(BPF_MUL
, R2
, R6
),
1736 BPF_ALU64_REG(BPF_MUL
, R2
, R7
),
1737 BPF_ALU64_REG(BPF_MUL
, R2
, R8
),
1738 BPF_ALU64_REG(BPF_MUL
, R2
, R9
),
1739 BPF_ALU64_IMM(BPF_MUL
, R2
, 10),
1740 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1741 BPF_ALU64_REG(BPF_MOV
, R0
, R2
),
1746 { { 0, 0x35d97ef2 } }
1748 { /* Mainly checking JIT here. */
1751 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1752 BPF_MOV64_REG(R1
, R0
),
1753 BPF_MOV64_REG(R2
, R1
),
1754 BPF_MOV64_REG(R3
, R2
),
1755 BPF_MOV64_REG(R4
, R3
),
1756 BPF_MOV64_REG(R5
, R4
),
1757 BPF_MOV64_REG(R6
, R5
),
1758 BPF_MOV64_REG(R7
, R6
),
1759 BPF_MOV64_REG(R8
, R7
),
1760 BPF_MOV64_REG(R9
, R8
),
1761 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1762 BPF_ALU64_IMM(BPF_MOV
, R1
, 0),
1763 BPF_ALU64_IMM(BPF_MOV
, R2
, 0),
1764 BPF_ALU64_IMM(BPF_MOV
, R3
, 0),
1765 BPF_ALU64_IMM(BPF_MOV
, R4
, 0),
1766 BPF_ALU64_IMM(BPF_MOV
, R5
, 0),
1767 BPF_ALU64_IMM(BPF_MOV
, R6
, 0),
1768 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
1769 BPF_ALU64_IMM(BPF_MOV
, R8
, 0),
1770 BPF_ALU64_IMM(BPF_MOV
, R9
, 0),
1771 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1772 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1773 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1774 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1775 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1776 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1777 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1778 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1779 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1780 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1781 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1788 { /* Mainly checking JIT here. */
1791 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1792 BPF_MOV64_REG(R1
, R0
),
1793 BPF_MOV64_REG(R2
, R1
),
1794 BPF_MOV64_REG(R3
, R2
),
1795 BPF_MOV64_REG(R4
, R3
),
1796 BPF_MOV64_REG(R5
, R4
),
1797 BPF_MOV64_REG(R6
, R5
),
1798 BPF_MOV64_REG(R7
, R6
),
1799 BPF_MOV64_REG(R8
, R7
),
1800 BPF_MOV64_REG(R9
, R8
),
1801 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
1802 BPF_ALU32_IMM(BPF_MOV
, R1
, 0),
1803 BPF_ALU32_IMM(BPF_MOV
, R2
, 0),
1804 BPF_ALU32_IMM(BPF_MOV
, R3
, 0),
1805 BPF_ALU32_IMM(BPF_MOV
, R4
, 0),
1806 BPF_ALU32_IMM(BPF_MOV
, R5
, 0),
1807 BPF_ALU32_IMM(BPF_MOV
, R6
, 0),
1808 BPF_ALU32_IMM(BPF_MOV
, R7
, 0),
1809 BPF_ALU32_IMM(BPF_MOV
, R8
, 0),
1810 BPF_ALU32_IMM(BPF_MOV
, R9
, 0),
1811 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1812 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1813 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1814 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1815 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1816 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1817 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1818 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1819 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1820 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1821 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1828 { /* Mainly checking JIT here. */
1831 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1832 BPF_MOV64_REG(R1
, R0
),
1833 BPF_MOV64_REG(R2
, R1
),
1834 BPF_MOV64_REG(R3
, R2
),
1835 BPF_MOV64_REG(R4
, R3
),
1836 BPF_MOV64_REG(R5
, R4
),
1837 BPF_MOV64_REG(R6
, R5
),
1838 BPF_MOV64_REG(R7
, R6
),
1839 BPF_MOV64_REG(R8
, R7
),
1840 BPF_MOV64_REG(R9
, R8
),
1841 BPF_LD_IMM64(R0
, 0x0LL
),
1842 BPF_LD_IMM64(R1
, 0x0LL
),
1843 BPF_LD_IMM64(R2
, 0x0LL
),
1844 BPF_LD_IMM64(R3
, 0x0LL
),
1845 BPF_LD_IMM64(R4
, 0x0LL
),
1846 BPF_LD_IMM64(R5
, 0x0LL
),
1847 BPF_LD_IMM64(R6
, 0x0LL
),
1848 BPF_LD_IMM64(R7
, 0x0LL
),
1849 BPF_LD_IMM64(R8
, 0x0LL
),
1850 BPF_LD_IMM64(R9
, 0x0LL
),
1851 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1852 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1853 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1854 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1855 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1856 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1857 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1858 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1859 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1860 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1861 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1871 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1872 BPF_ALU64_IMM(BPF_ADD
, R0
, -1),
1873 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1874 BPF_ALU64_IMM(BPF_XOR
, R2
, 3),
1875 BPF_ALU64_REG(BPF_DIV
, R0
, R2
),
1876 BPF_JMP_IMM(BPF_JEQ
, R0
, 10, 1),
1878 BPF_ALU64_IMM(BPF_MOD
, R0
, 3),
1879 BPF_JMP_IMM(BPF_JEQ
, R0
, 1, 1),
1881 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1889 "INT: shifts by register",
1891 BPF_MOV64_IMM(R0
, -1234),
1892 BPF_MOV64_IMM(R1
, 1),
1893 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
1894 BPF_JMP_IMM(BPF_JEQ
, R0
, 0x7ffffd97, 1),
1896 BPF_MOV64_IMM(R2
, 1),
1897 BPF_ALU64_REG(BPF_LSH
, R0
, R2
),
1898 BPF_MOV32_IMM(R4
, -1234),
1899 BPF_JMP_REG(BPF_JEQ
, R0
, R4
, 1),
1901 BPF_ALU64_IMM(BPF_AND
, R4
, 63),
1902 BPF_ALU64_REG(BPF_LSH
, R0
, R4
), /* R0 <= 46 */
1903 BPF_MOV64_IMM(R3
, 47),
1904 BPF_ALU64_REG(BPF_ARSH
, R0
, R3
),
1905 BPF_JMP_IMM(BPF_JEQ
, R0
, -617, 1),
1907 BPF_MOV64_IMM(R2
, 1),
1908 BPF_ALU64_REG(BPF_LSH
, R4
, R2
), /* R4 = 46 << 1 */
1909 BPF_JMP_IMM(BPF_JEQ
, R4
, 92, 1),
1911 BPF_MOV64_IMM(R4
, 4),
1912 BPF_ALU64_REG(BPF_LSH
, R4
, R4
), /* R4 = 4 << 4 */
1913 BPF_JMP_IMM(BPF_JEQ
, R4
, 64, 1),
1915 BPF_MOV64_IMM(R4
, 5),
1916 BPF_ALU32_REG(BPF_LSH
, R4
, R4
), /* R4 = 5 << 5 */
1917 BPF_JMP_IMM(BPF_JEQ
, R4
, 160, 1),
1919 BPF_MOV64_IMM(R0
, -1),
1927 "check: missing ret",
1929 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
1931 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
1934 .fill_helper
= NULL
,
1935 .expected_errcode
= -EINVAL
,
1940 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0),
1941 BPF_STMT(BPF_RET
| BPF_K
, 0)
1943 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
1946 .fill_helper
= NULL
,
1947 .expected_errcode
= -EINVAL
,
1950 "check: unknown insn",
1952 /* seccomp insn, rejected in socket filter */
1953 BPF_STMT(BPF_LDX
| BPF_W
| BPF_ABS
, 0),
1954 BPF_STMT(BPF_RET
| BPF_K
, 0)
1956 CLASSIC
| FLAG_EXPECTED_FAIL
,
1959 .fill_helper
= NULL
,
1960 .expected_errcode
= -EINVAL
,
1963 "check: out of range spill/fill",
1965 BPF_STMT(BPF_STX
, 16),
1966 BPF_STMT(BPF_RET
| BPF_K
, 0)
1968 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
1971 .fill_helper
= NULL
,
1972 .expected_errcode
= -EINVAL
,
1977 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1978 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 15),
1979 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1980 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1981 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1982 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1983 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1984 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1985 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1986 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1987 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1988 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1989 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1990 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1991 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1992 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 3, 4),
1993 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1994 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 1, 2),
1995 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1996 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
1997 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
1998 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
1999 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2000 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2001 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2002 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2003 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2004 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2005 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2006 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2007 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2008 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2009 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2010 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2011 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 2, 3),
2012 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 1, 2),
2013 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2014 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2015 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2016 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2017 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2018 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2019 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2020 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2021 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2022 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2023 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2024 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2025 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2026 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2027 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2028 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2029 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 2, 3),
2030 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 1, 2),
2031 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2032 BPF_STMT(BPF_RET
| BPF_A
, 0),
2033 BPF_STMT(BPF_RET
| BPF_A
, 0),
2036 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2037 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2039 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2040 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2041 0xc0, 0xa8, 0x33, 0x01,
2042 0xc0, 0xa8, 0x33, 0x02,
2045 0x00, 0x14, 0x00, 0x00,
2046 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2047 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2048 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2049 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2050 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2051 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2052 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2053 0xcc, 0xcc, 0xcc, 0xcc },
2059 BPF_STMT(BPF_RET
| BPF_X
, 0),
2061 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2064 .fill_helper
= NULL
,
2065 .expected_errcode
= -EINVAL
,
2068 "check: LDX + RET X",
2070 BPF_STMT(BPF_LDX
| BPF_IMM
, 42),
2071 BPF_STMT(BPF_RET
| BPF_X
, 0),
2073 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2076 .fill_helper
= NULL
,
2077 .expected_errcode
= -EINVAL
,
2079 { /* Mainly checking JIT here. */
2080 "M[]: alt STX + LDX",
2082 BPF_STMT(BPF_LDX
| BPF_IMM
, 100),
2083 BPF_STMT(BPF_STX
, 0),
2084 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2085 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2086 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2087 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2088 BPF_STMT(BPF_STX
, 1),
2089 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2090 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2091 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2092 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2093 BPF_STMT(BPF_STX
, 2),
2094 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2095 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2096 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2097 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2098 BPF_STMT(BPF_STX
, 3),
2099 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2100 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2101 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2102 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2103 BPF_STMT(BPF_STX
, 4),
2104 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2105 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2106 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2107 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2108 BPF_STMT(BPF_STX
, 5),
2109 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2110 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2111 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2112 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2113 BPF_STMT(BPF_STX
, 6),
2114 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2115 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2116 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2117 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2118 BPF_STMT(BPF_STX
, 7),
2119 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2120 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2121 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2122 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2123 BPF_STMT(BPF_STX
, 8),
2124 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2125 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2126 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2127 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2128 BPF_STMT(BPF_STX
, 9),
2129 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2130 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2131 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2132 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2133 BPF_STMT(BPF_STX
, 10),
2134 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2135 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2136 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2137 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2138 BPF_STMT(BPF_STX
, 11),
2139 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2140 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2141 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2142 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2143 BPF_STMT(BPF_STX
, 12),
2144 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2145 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2146 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2147 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2148 BPF_STMT(BPF_STX
, 13),
2149 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2150 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2151 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2152 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2153 BPF_STMT(BPF_STX
, 14),
2154 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2155 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2156 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2157 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2158 BPF_STMT(BPF_STX
, 15),
2159 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2160 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2161 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2162 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2163 BPF_STMT(BPF_RET
| BPF_A
, 0),
2165 CLASSIC
| FLAG_NO_DATA
,
2169 { /* Mainly checking JIT here. */
2170 "M[]: full STX + full LDX",
2172 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbadfeedb),
2173 BPF_STMT(BPF_STX
, 0),
2174 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xecabedae),
2175 BPF_STMT(BPF_STX
, 1),
2176 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xafccfeaf),
2177 BPF_STMT(BPF_STX
, 2),
2178 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbffdcedc),
2179 BPF_STMT(BPF_STX
, 3),
2180 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbbbdccb),
2181 BPF_STMT(BPF_STX
, 4),
2182 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbabcbda),
2183 BPF_STMT(BPF_STX
, 5),
2184 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaedecbdb),
2185 BPF_STMT(BPF_STX
, 6),
2186 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xadebbade),
2187 BPF_STMT(BPF_STX
, 7),
2188 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfcfcfaec),
2189 BPF_STMT(BPF_STX
, 8),
2190 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbcdddbdc),
2191 BPF_STMT(BPF_STX
, 9),
2192 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfeefdfac),
2193 BPF_STMT(BPF_STX
, 10),
2194 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xcddcdeea),
2195 BPF_STMT(BPF_STX
, 11),
2196 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaccfaebb),
2197 BPF_STMT(BPF_STX
, 12),
2198 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbdcccdcf),
2199 BPF_STMT(BPF_STX
, 13),
2200 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaaedecde),
2201 BPF_STMT(BPF_STX
, 14),
2202 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfaeacdad),
2203 BPF_STMT(BPF_STX
, 15),
2204 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2205 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2206 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2207 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2208 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2209 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2210 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2211 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2212 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2213 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2214 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2215 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2216 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2217 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2218 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2219 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2220 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2221 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2222 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2223 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2224 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2225 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2226 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2227 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2228 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2229 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2230 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2231 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2232 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2233 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2234 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2235 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2236 BPF_STMT(BPF_RET
| BPF_A
, 0),
2238 CLASSIC
| FLAG_NO_DATA
,
2240 { { 0, 0x2a5a5e5 } },
2243 "check: SKF_AD_MAX",
2245 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2246 SKF_AD_OFF
+ SKF_AD_MAX
),
2247 BPF_STMT(BPF_RET
| BPF_A
, 0),
2249 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2252 .fill_helper
= NULL
,
2253 .expected_errcode
= -EINVAL
,
2255 { /* Passes checker but fails during runtime. */
2256 "LD [SKF_AD_OFF-1]",
2258 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2260 BPF_STMT(BPF_RET
| BPF_K
, 1),
2267 "load 64-bit immediate",
2269 BPF_LD_IMM64(R1
, 0x567800001234LL
),
2270 BPF_MOV64_REG(R2
, R1
),
2271 BPF_MOV64_REG(R3
, R2
),
2272 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
2273 BPF_ALU64_IMM(BPF_LSH
, R3
, 32),
2274 BPF_ALU64_IMM(BPF_RSH
, R3
, 32),
2275 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
2276 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5678, 1),
2278 BPF_JMP_IMM(BPF_JEQ
, R3
, 0x1234, 1),
2280 BPF_LD_IMM64(R0
, 0x1ffffffffLL
),
2281 BPF_ALU64_IMM(BPF_RSH
, R0
, 32), /* R0 = 1 */
2288 /* BPF_ALU | BPF_MOV | BPF_X */
2290 "ALU_MOV_X: dst = 2",
2292 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2293 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2301 "ALU_MOV_X: dst = 4294967295",
2303 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2304 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2309 { { 0, 4294967295U } },
2312 "ALU64_MOV_X: dst = 2",
2314 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2315 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2323 "ALU64_MOV_X: dst = 4294967295",
2325 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2326 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2331 { { 0, 4294967295U } },
2333 /* BPF_ALU | BPF_MOV | BPF_K */
2335 "ALU_MOV_K: dst = 2",
2337 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
2345 "ALU_MOV_K: dst = 4294967295",
2347 BPF_ALU32_IMM(BPF_MOV
, R0
, 4294967295U),
2352 { { 0, 4294967295U } },
2355 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2357 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2358 BPF_LD_IMM64(R3
, 0x00000000ffffffffLL
),
2359 BPF_ALU32_IMM(BPF_MOV
, R2
, 0xffffffff),
2360 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2361 BPF_MOV32_IMM(R0
, 2),
2363 BPF_MOV32_IMM(R0
, 1),
2371 "ALU64_MOV_K: dst = 2",
2373 BPF_ALU64_IMM(BPF_MOV
, R0
, 2),
2381 "ALU64_MOV_K: dst = 2147483647",
2383 BPF_ALU64_IMM(BPF_MOV
, R0
, 2147483647),
2388 { { 0, 2147483647 } },
2391 "ALU64_OR_K: dst = 0x0",
2393 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2394 BPF_LD_IMM64(R3
, 0x0),
2395 BPF_ALU64_IMM(BPF_MOV
, R2
, 0x0),
2396 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2397 BPF_MOV32_IMM(R0
, 2),
2399 BPF_MOV32_IMM(R0
, 1),
2407 "ALU64_MOV_K: dst = -1",
2409 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2410 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2411 BPF_ALU64_IMM(BPF_MOV
, R2
, 0xffffffff),
2412 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2413 BPF_MOV32_IMM(R0
, 2),
2415 BPF_MOV32_IMM(R0
, 1),
2422 /* BPF_ALU | BPF_ADD | BPF_X */
2424 "ALU_ADD_X: 1 + 2 = 3",
2426 BPF_LD_IMM64(R0
, 1),
2427 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2428 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2436 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2438 BPF_LD_IMM64(R0
, 1),
2439 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2440 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2445 { { 0, 4294967295U } },
2448 "ALU_ADD_X: 2 + 4294967294 = 0",
2450 BPF_LD_IMM64(R0
, 2),
2451 BPF_LD_IMM64(R1
, 4294967294U),
2452 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2453 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2454 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2456 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2464 "ALU64_ADD_X: 1 + 2 = 3",
2466 BPF_LD_IMM64(R0
, 1),
2467 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2468 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2476 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2478 BPF_LD_IMM64(R0
, 1),
2479 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2480 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2485 { { 0, 4294967295U } },
2488 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2490 BPF_LD_IMM64(R0
, 2),
2491 BPF_LD_IMM64(R1
, 4294967294U),
2492 BPF_LD_IMM64(R2
, 4294967296ULL),
2493 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2494 BPF_JMP_REG(BPF_JEQ
, R0
, R2
, 2),
2495 BPF_MOV32_IMM(R0
, 0),
2497 BPF_MOV32_IMM(R0
, 1),
2504 /* BPF_ALU | BPF_ADD | BPF_K */
2506 "ALU_ADD_K: 1 + 2 = 3",
2508 BPF_LD_IMM64(R0
, 1),
2509 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2517 "ALU_ADD_K: 3 + 0 = 3",
2519 BPF_LD_IMM64(R0
, 3),
2520 BPF_ALU32_IMM(BPF_ADD
, R0
, 0),
2528 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2530 BPF_LD_IMM64(R0
, 1),
2531 BPF_ALU32_IMM(BPF_ADD
, R0
, 4294967294U),
2536 { { 0, 4294967295U } },
2539 "ALU_ADD_K: 4294967294 + 2 = 0",
2541 BPF_LD_IMM64(R0
, 4294967294U),
2542 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2543 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2544 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2546 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2554 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2556 BPF_LD_IMM64(R2
, 0x0),
2557 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
2558 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffffffff),
2559 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2560 BPF_MOV32_IMM(R0
, 2),
2562 BPF_MOV32_IMM(R0
, 1),
2570 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2572 BPF_LD_IMM64(R2
, 0x0),
2573 BPF_LD_IMM64(R3
, 0xffff),
2574 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffff),
2575 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2576 BPF_MOV32_IMM(R0
, 2),
2578 BPF_MOV32_IMM(R0
, 1),
2586 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2588 BPF_LD_IMM64(R2
, 0x0),
2589 BPF_LD_IMM64(R3
, 0x7fffffff),
2590 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x7fffffff),
2591 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2592 BPF_MOV32_IMM(R0
, 2),
2594 BPF_MOV32_IMM(R0
, 1),
2602 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2604 BPF_LD_IMM64(R2
, 0x0),
2605 BPF_LD_IMM64(R3
, 0x80000000),
2606 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80000000),
2607 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2608 BPF_MOV32_IMM(R0
, 2),
2610 BPF_MOV32_IMM(R0
, 1),
2618 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2620 BPF_LD_IMM64(R2
, 0x0),
2621 BPF_LD_IMM64(R3
, 0x80008000),
2622 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80008000),
2623 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2624 BPF_MOV32_IMM(R0
, 2),
2626 BPF_MOV32_IMM(R0
, 1),
2634 "ALU64_ADD_K: 1 + 2 = 3",
2636 BPF_LD_IMM64(R0
, 1),
2637 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2645 "ALU64_ADD_K: 3 + 0 = 3",
2647 BPF_LD_IMM64(R0
, 3),
2648 BPF_ALU64_IMM(BPF_ADD
, R0
, 0),
2656 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2658 BPF_LD_IMM64(R0
, 1),
2659 BPF_ALU64_IMM(BPF_ADD
, R0
, 2147483646),
2664 { { 0, 2147483647 } },
2667 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2669 BPF_LD_IMM64(R0
, 4294967294U),
2670 BPF_LD_IMM64(R1
, 4294967296ULL),
2671 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2672 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 2),
2673 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2675 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2683 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2685 BPF_LD_IMM64(R0
, 2147483646),
2686 BPF_ALU64_IMM(BPF_ADD
, R0
, -2147483647),
2694 "ALU64_ADD_K: 1 + 0 = 1",
2696 BPF_LD_IMM64(R2
, 0x1),
2697 BPF_LD_IMM64(R3
, 0x1),
2698 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x0),
2699 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2700 BPF_MOV32_IMM(R0
, 2),
2702 BPF_MOV32_IMM(R0
, 1),
2710 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2712 BPF_LD_IMM64(R2
, 0x0),
2713 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2714 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffffffff),
2715 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2716 BPF_MOV32_IMM(R0
, 2),
2718 BPF_MOV32_IMM(R0
, 1),
2726 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2728 BPF_LD_IMM64(R2
, 0x0),
2729 BPF_LD_IMM64(R3
, 0xffff),
2730 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffff),
2731 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2732 BPF_MOV32_IMM(R0
, 2),
2734 BPF_MOV32_IMM(R0
, 1),
2742 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2744 BPF_LD_IMM64(R2
, 0x0),
2745 BPF_LD_IMM64(R3
, 0x7fffffff),
2746 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x7fffffff),
2747 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2748 BPF_MOV32_IMM(R0
, 2),
2750 BPF_MOV32_IMM(R0
, 1),
2758 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2760 BPF_LD_IMM64(R2
, 0x0),
2761 BPF_LD_IMM64(R3
, 0xffffffff80000000LL
),
2762 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80000000),
2763 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2764 BPF_MOV32_IMM(R0
, 2),
2766 BPF_MOV32_IMM(R0
, 1),
2774 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2776 BPF_LD_IMM64(R2
, 0x0),
2777 BPF_LD_IMM64(R3
, 0xffffffff80008000LL
),
2778 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80008000),
2779 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2780 BPF_MOV32_IMM(R0
, 2),
2782 BPF_MOV32_IMM(R0
, 1),
2789 /* BPF_ALU | BPF_SUB | BPF_X */
2791 "ALU_SUB_X: 3 - 1 = 2",
2793 BPF_LD_IMM64(R0
, 3),
2794 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2795 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2803 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2805 BPF_LD_IMM64(R0
, 4294967295U),
2806 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2807 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2815 "ALU64_SUB_X: 3 - 1 = 2",
2817 BPF_LD_IMM64(R0
, 3),
2818 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2819 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2827 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2829 BPF_LD_IMM64(R0
, 4294967295U),
2830 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2831 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2838 /* BPF_ALU | BPF_SUB | BPF_K */
2840 "ALU_SUB_K: 3 - 1 = 2",
2842 BPF_LD_IMM64(R0
, 3),
2843 BPF_ALU32_IMM(BPF_SUB
, R0
, 1),
2851 "ALU_SUB_K: 3 - 0 = 3",
2853 BPF_LD_IMM64(R0
, 3),
2854 BPF_ALU32_IMM(BPF_SUB
, R0
, 0),
2862 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2864 BPF_LD_IMM64(R0
, 4294967295U),
2865 BPF_ALU32_IMM(BPF_SUB
, R0
, 4294967294U),
2873 "ALU64_SUB_K: 3 - 1 = 2",
2875 BPF_LD_IMM64(R0
, 3),
2876 BPF_ALU64_IMM(BPF_SUB
, R0
, 1),
2884 "ALU64_SUB_K: 3 - 0 = 3",
2886 BPF_LD_IMM64(R0
, 3),
2887 BPF_ALU64_IMM(BPF_SUB
, R0
, 0),
2895 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2897 BPF_LD_IMM64(R0
, 4294967294U),
2898 BPF_ALU64_IMM(BPF_SUB
, R0
, 4294967295U),
2906 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2908 BPF_LD_IMM64(R0
, 2147483646),
2909 BPF_ALU64_IMM(BPF_SUB
, R0
, 2147483647),
2916 /* BPF_ALU | BPF_MUL | BPF_X */
2918 "ALU_MUL_X: 2 * 3 = 6",
2920 BPF_LD_IMM64(R0
, 2),
2921 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
2922 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
2930 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2932 BPF_LD_IMM64(R0
, 2),
2933 BPF_ALU32_IMM(BPF_MOV
, R1
, 0x7FFFFFF8),
2934 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
2939 { { 0, 0xFFFFFFF0 } },
2942 "ALU_MUL_X: -1 * -1 = 1",
2944 BPF_LD_IMM64(R0
, -1),
2945 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
2946 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
2954 "ALU64_MUL_X: 2 * 3 = 6",
2956 BPF_LD_IMM64(R0
, 2),
2957 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
2958 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
2966 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2968 BPF_LD_IMM64(R0
, 1),
2969 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
2970 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
2975 { { 0, 2147483647 } },
2977 /* BPF_ALU | BPF_MUL | BPF_K */
2979 "ALU_MUL_K: 2 * 3 = 6",
2981 BPF_LD_IMM64(R0
, 2),
2982 BPF_ALU32_IMM(BPF_MUL
, R0
, 3),
2990 "ALU_MUL_K: 3 * 1 = 3",
2992 BPF_LD_IMM64(R0
, 3),
2993 BPF_ALU32_IMM(BPF_MUL
, R0
, 1),
3001 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3003 BPF_LD_IMM64(R0
, 2),
3004 BPF_ALU32_IMM(BPF_MUL
, R0
, 0x7FFFFFF8),
3009 { { 0, 0xFFFFFFF0 } },
3012 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3014 BPF_LD_IMM64(R2
, 0x1),
3015 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
3016 BPF_ALU32_IMM(BPF_MUL
, R2
, 0xffffffff),
3017 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3018 BPF_MOV32_IMM(R0
, 2),
3020 BPF_MOV32_IMM(R0
, 1),
3028 "ALU64_MUL_K: 2 * 3 = 6",
3030 BPF_LD_IMM64(R0
, 2),
3031 BPF_ALU64_IMM(BPF_MUL
, R0
, 3),
3039 "ALU64_MUL_K: 3 * 1 = 3",
3041 BPF_LD_IMM64(R0
, 3),
3042 BPF_ALU64_IMM(BPF_MUL
, R0
, 1),
3050 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3052 BPF_LD_IMM64(R0
, 1),
3053 BPF_ALU64_IMM(BPF_MUL
, R0
, 2147483647),
3058 { { 0, 2147483647 } },
3061 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3063 BPF_LD_IMM64(R0
, 1),
3064 BPF_ALU64_IMM(BPF_MUL
, R0
, -2147483647),
3069 { { 0, -2147483647 } },
3072 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3074 BPF_LD_IMM64(R2
, 0x1),
3075 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3076 BPF_ALU64_IMM(BPF_MUL
, R2
, 0xffffffff),
3077 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3078 BPF_MOV32_IMM(R0
, 2),
3080 BPF_MOV32_IMM(R0
, 1),
3087 /* BPF_ALU | BPF_DIV | BPF_X */
3089 "ALU_DIV_X: 6 / 2 = 3",
3091 BPF_LD_IMM64(R0
, 6),
3092 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3093 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3101 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3103 BPF_LD_IMM64(R0
, 4294967295U),
3104 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
3105 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3113 "ALU64_DIV_X: 6 / 2 = 3",
3115 BPF_LD_IMM64(R0
, 6),
3116 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3117 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3125 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3127 BPF_LD_IMM64(R0
, 2147483647),
3128 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3129 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3137 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3139 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3140 BPF_LD_IMM64(R4
, 0xffffffffffffffffLL
),
3141 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3142 BPF_ALU64_REG(BPF_DIV
, R2
, R4
),
3143 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3144 BPF_MOV32_IMM(R0
, 2),
3146 BPF_MOV32_IMM(R0
, 1),
3153 /* BPF_ALU | BPF_DIV | BPF_K */
3155 "ALU_DIV_K: 6 / 2 = 3",
3157 BPF_LD_IMM64(R0
, 6),
3158 BPF_ALU32_IMM(BPF_DIV
, R0
, 2),
3166 "ALU_DIV_K: 3 / 1 = 3",
3168 BPF_LD_IMM64(R0
, 3),
3169 BPF_ALU32_IMM(BPF_DIV
, R0
, 1),
3177 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3179 BPF_LD_IMM64(R0
, 4294967295U),
3180 BPF_ALU32_IMM(BPF_DIV
, R0
, 4294967295U),
3188 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3190 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3191 BPF_LD_IMM64(R3
, 0x1UL
),
3192 BPF_ALU32_IMM(BPF_DIV
, R2
, 0xffffffff),
3193 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3194 BPF_MOV32_IMM(R0
, 2),
3196 BPF_MOV32_IMM(R0
, 1),
3204 "ALU64_DIV_K: 6 / 2 = 3",
3206 BPF_LD_IMM64(R0
, 6),
3207 BPF_ALU64_IMM(BPF_DIV
, R0
, 2),
3215 "ALU64_DIV_K: 3 / 1 = 3",
3217 BPF_LD_IMM64(R0
, 3),
3218 BPF_ALU64_IMM(BPF_DIV
, R0
, 1),
3226 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3228 BPF_LD_IMM64(R0
, 2147483647),
3229 BPF_ALU64_IMM(BPF_DIV
, R0
, 2147483647),
3237 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3239 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3240 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3241 BPF_ALU64_IMM(BPF_DIV
, R2
, 0xffffffff),
3242 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3243 BPF_MOV32_IMM(R0
, 2),
3245 BPF_MOV32_IMM(R0
, 1),
3252 /* BPF_ALU | BPF_MOD | BPF_X */
3254 "ALU_MOD_X: 3 % 2 = 1",
3256 BPF_LD_IMM64(R0
, 3),
3257 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3258 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3266 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3268 BPF_LD_IMM64(R0
, 4294967295U),
3269 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967293U),
3270 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3278 "ALU64_MOD_X: 3 % 2 = 1",
3280 BPF_LD_IMM64(R0
, 3),
3281 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3282 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3290 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3292 BPF_LD_IMM64(R0
, 2147483647),
3293 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483645),
3294 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3301 /* BPF_ALU | BPF_MOD | BPF_K */
3303 "ALU_MOD_K: 3 % 2 = 1",
3305 BPF_LD_IMM64(R0
, 3),
3306 BPF_ALU32_IMM(BPF_MOD
, R0
, 2),
3314 "ALU_MOD_K: 3 % 1 = 0",
3316 BPF_LD_IMM64(R0
, 3),
3317 BPF_ALU32_IMM(BPF_MOD
, R0
, 1),
3325 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3327 BPF_LD_IMM64(R0
, 4294967295U),
3328 BPF_ALU32_IMM(BPF_MOD
, R0
, 4294967293U),
3336 "ALU64_MOD_K: 3 % 2 = 1",
3338 BPF_LD_IMM64(R0
, 3),
3339 BPF_ALU64_IMM(BPF_MOD
, R0
, 2),
3347 "ALU64_MOD_K: 3 % 1 = 0",
3349 BPF_LD_IMM64(R0
, 3),
3350 BPF_ALU64_IMM(BPF_MOD
, R0
, 1),
3358 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3360 BPF_LD_IMM64(R0
, 2147483647),
3361 BPF_ALU64_IMM(BPF_MOD
, R0
, 2147483645),
3368 /* BPF_ALU | BPF_AND | BPF_X */
3370 "ALU_AND_X: 3 & 2 = 2",
3372 BPF_LD_IMM64(R0
, 3),
3373 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3374 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3382 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3384 BPF_LD_IMM64(R0
, 0xffffffff),
3385 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3386 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3391 { { 0, 0xffffffff } },
3394 "ALU64_AND_X: 3 & 2 = 2",
3396 BPF_LD_IMM64(R0
, 3),
3397 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3398 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3406 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3408 BPF_LD_IMM64(R0
, 0xffffffff),
3409 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3410 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3415 { { 0, 0xffffffff } },
3417 /* BPF_ALU | BPF_AND | BPF_K */
3419 "ALU_AND_K: 3 & 2 = 2",
3421 BPF_LD_IMM64(R0
, 3),
3422 BPF_ALU32_IMM(BPF_AND
, R0
, 2),
3430 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3432 BPF_LD_IMM64(R0
, 0xffffffff),
3433 BPF_ALU32_IMM(BPF_AND
, R0
, 0xffffffff),
3438 { { 0, 0xffffffff } },
3441 "ALU64_AND_K: 3 & 2 = 2",
3443 BPF_LD_IMM64(R0
, 3),
3444 BPF_ALU64_IMM(BPF_AND
, R0
, 2),
3452 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3454 BPF_LD_IMM64(R0
, 0xffffffff),
3455 BPF_ALU64_IMM(BPF_AND
, R0
, 0xffffffff),
3460 { { 0, 0xffffffff } },
3463 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3465 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3466 BPF_LD_IMM64(R3
, 0x0000000000000000LL
),
3467 BPF_ALU64_IMM(BPF_AND
, R2
, 0x0),
3468 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3469 BPF_MOV32_IMM(R0
, 2),
3471 BPF_MOV32_IMM(R0
, 1),
3479 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3481 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3482 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3483 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3484 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3485 BPF_MOV32_IMM(R0
, 2),
3487 BPF_MOV32_IMM(R0
, 1),
3495 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3497 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3498 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3499 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3500 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3501 BPF_MOV32_IMM(R0
, 2),
3503 BPF_MOV32_IMM(R0
, 1),
3510 /* BPF_ALU | BPF_OR | BPF_X */
3512 "ALU_OR_X: 1 | 2 = 3",
3514 BPF_LD_IMM64(R0
, 1),
3515 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3516 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3524 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3526 BPF_LD_IMM64(R0
, 0),
3527 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3528 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3533 { { 0, 0xffffffff } },
3536 "ALU64_OR_X: 1 | 2 = 3",
3538 BPF_LD_IMM64(R0
, 1),
3539 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3540 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3548 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3550 BPF_LD_IMM64(R0
, 0),
3551 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3552 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3557 { { 0, 0xffffffff } },
3559 /* BPF_ALU | BPF_OR | BPF_K */
3561 "ALU_OR_K: 1 | 2 = 3",
3563 BPF_LD_IMM64(R0
, 1),
3564 BPF_ALU32_IMM(BPF_OR
, R0
, 2),
3572 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3574 BPF_LD_IMM64(R0
, 0),
3575 BPF_ALU32_IMM(BPF_OR
, R0
, 0xffffffff),
3580 { { 0, 0xffffffff } },
3583 "ALU64_OR_K: 1 | 2 = 3",
3585 BPF_LD_IMM64(R0
, 1),
3586 BPF_ALU64_IMM(BPF_OR
, R0
, 2),
3594 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3596 BPF_LD_IMM64(R0
, 0),
3597 BPF_ALU64_IMM(BPF_OR
, R0
, 0xffffffff),
3602 { { 0, 0xffffffff } },
3605 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3607 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3608 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3609 BPF_ALU64_IMM(BPF_OR
, R2
, 0x0),
3610 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3611 BPF_MOV32_IMM(R0
, 2),
3613 BPF_MOV32_IMM(R0
, 1),
3621 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3623 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3624 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3625 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3626 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3627 BPF_MOV32_IMM(R0
, 2),
3629 BPF_MOV32_IMM(R0
, 1),
3637 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3639 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3640 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3641 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3642 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3643 BPF_MOV32_IMM(R0
, 2),
3645 BPF_MOV32_IMM(R0
, 1),
3652 /* BPF_ALU | BPF_XOR | BPF_X */
3654 "ALU_XOR_X: 5 ^ 6 = 3",
3656 BPF_LD_IMM64(R0
, 5),
3657 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3658 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3666 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3668 BPF_LD_IMM64(R0
, 1),
3669 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3670 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3675 { { 0, 0xfffffffe } },
3678 "ALU64_XOR_X: 5 ^ 6 = 3",
3680 BPF_LD_IMM64(R0
, 5),
3681 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3682 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3690 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3692 BPF_LD_IMM64(R0
, 1),
3693 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3694 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3699 { { 0, 0xfffffffe } },
3701 /* BPF_ALU | BPF_XOR | BPF_K */
3703 "ALU_XOR_K: 5 ^ 6 = 3",
3705 BPF_LD_IMM64(R0
, 5),
3706 BPF_ALU32_IMM(BPF_XOR
, R0
, 6),
3714 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3716 BPF_LD_IMM64(R0
, 1),
3717 BPF_ALU32_IMM(BPF_XOR
, R0
, 0xffffffff),
3722 { { 0, 0xfffffffe } },
3725 "ALU64_XOR_K: 5 ^ 6 = 3",
3727 BPF_LD_IMM64(R0
, 5),
3728 BPF_ALU64_IMM(BPF_XOR
, R0
, 6),
3736 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3738 BPF_LD_IMM64(R0
, 1),
3739 BPF_ALU64_IMM(BPF_XOR
, R0
, 0xffffffff),
3744 { { 0, 0xfffffffe } },
3747 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3749 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3750 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3751 BPF_ALU64_IMM(BPF_XOR
, R2
, 0x0),
3752 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3753 BPF_MOV32_IMM(R0
, 2),
3755 BPF_MOV32_IMM(R0
, 1),
3763 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3765 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3766 BPF_LD_IMM64(R3
, 0xffff00000000ffffLL
),
3767 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3768 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3769 BPF_MOV32_IMM(R0
, 2),
3771 BPF_MOV32_IMM(R0
, 1),
3779 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3781 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3782 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3783 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3784 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3785 BPF_MOV32_IMM(R0
, 2),
3787 BPF_MOV32_IMM(R0
, 1),
3794 /* BPF_ALU | BPF_LSH | BPF_X */
3796 "ALU_LSH_X: 1 << 1 = 2",
3798 BPF_LD_IMM64(R0
, 1),
3799 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3800 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3808 "ALU_LSH_X: 1 << 31 = 0x80000000",
3810 BPF_LD_IMM64(R0
, 1),
3811 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3812 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3817 { { 0, 0x80000000 } },
3820 "ALU64_LSH_X: 1 << 1 = 2",
3822 BPF_LD_IMM64(R0
, 1),
3823 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3824 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3832 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3834 BPF_LD_IMM64(R0
, 1),
3835 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3836 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3841 { { 0, 0x80000000 } },
3843 /* BPF_ALU | BPF_LSH | BPF_K */
3845 "ALU_LSH_K: 1 << 1 = 2",
3847 BPF_LD_IMM64(R0
, 1),
3848 BPF_ALU32_IMM(BPF_LSH
, R0
, 1),
3856 "ALU_LSH_K: 1 << 31 = 0x80000000",
3858 BPF_LD_IMM64(R0
, 1),
3859 BPF_ALU32_IMM(BPF_LSH
, R0
, 31),
3864 { { 0, 0x80000000 } },
3867 "ALU64_LSH_K: 1 << 1 = 2",
3869 BPF_LD_IMM64(R0
, 1),
3870 BPF_ALU64_IMM(BPF_LSH
, R0
, 1),
3878 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3880 BPF_LD_IMM64(R0
, 1),
3881 BPF_ALU64_IMM(BPF_LSH
, R0
, 31),
3886 { { 0, 0x80000000 } },
3888 /* BPF_ALU | BPF_RSH | BPF_X */
3890 "ALU_RSH_X: 2 >> 1 = 1",
3892 BPF_LD_IMM64(R0
, 2),
3893 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3894 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
3902 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3904 BPF_LD_IMM64(R0
, 0x80000000),
3905 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3906 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
3914 "ALU64_RSH_X: 2 >> 1 = 1",
3916 BPF_LD_IMM64(R0
, 2),
3917 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3918 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
3926 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3928 BPF_LD_IMM64(R0
, 0x80000000),
3929 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3930 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
3937 /* BPF_ALU | BPF_RSH | BPF_K */
3939 "ALU_RSH_K: 2 >> 1 = 1",
3941 BPF_LD_IMM64(R0
, 2),
3942 BPF_ALU32_IMM(BPF_RSH
, R0
, 1),
3950 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3952 BPF_LD_IMM64(R0
, 0x80000000),
3953 BPF_ALU32_IMM(BPF_RSH
, R0
, 31),
3961 "ALU64_RSH_K: 2 >> 1 = 1",
3963 BPF_LD_IMM64(R0
, 2),
3964 BPF_ALU64_IMM(BPF_RSH
, R0
, 1),
3972 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3974 BPF_LD_IMM64(R0
, 0x80000000),
3975 BPF_ALU64_IMM(BPF_RSH
, R0
, 31),
3982 /* BPF_ALU | BPF_ARSH | BPF_X */
3984 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3986 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
3987 BPF_ALU32_IMM(BPF_MOV
, R1
, 40),
3988 BPF_ALU64_REG(BPF_ARSH
, R0
, R1
),
3993 { { 0, 0xffff00ff } },
3995 /* BPF_ALU | BPF_ARSH | BPF_K */
3997 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3999 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4000 BPF_ALU64_IMM(BPF_ARSH
, R0
, 40),
4005 { { 0, 0xffff00ff } },
4007 /* BPF_ALU | BPF_NEG */
4009 "ALU_NEG: -(3) = -3",
4011 BPF_ALU32_IMM(BPF_MOV
, R0
, 3),
4012 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4020 "ALU_NEG: -(-3) = 3",
4022 BPF_ALU32_IMM(BPF_MOV
, R0
, -3),
4023 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4031 "ALU64_NEG: -(3) = -3",
4033 BPF_LD_IMM64(R0
, 3),
4034 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4042 "ALU64_NEG: -(-3) = 3",
4044 BPF_LD_IMM64(R0
, -3),
4045 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4052 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4054 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4056 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4057 BPF_ENDIAN(BPF_FROM_BE
, R0
, 16),
4062 { { 0, cpu_to_be16(0xcdef) } },
4065 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4067 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4068 BPF_ENDIAN(BPF_FROM_BE
, R0
, 32),
4069 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4070 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4071 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4076 { { 0, cpu_to_be32(0x89abcdef) } },
4079 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4081 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4082 BPF_ENDIAN(BPF_FROM_BE
, R0
, 64),
4087 { { 0, (u32
) cpu_to_be64(0x0123456789abcdefLL
) } },
4089 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4091 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4093 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4094 BPF_ENDIAN(BPF_FROM_LE
, R0
, 16),
4099 { { 0, cpu_to_le16(0xcdef) } },
4102 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4104 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4105 BPF_ENDIAN(BPF_FROM_LE
, R0
, 32),
4106 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4107 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4108 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4113 { { 0, cpu_to_le32(0x89abcdef) } },
4116 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4118 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4119 BPF_ENDIAN(BPF_FROM_LE
, R0
, 64),
4124 { { 0, (u32
) cpu_to_le64(0x0123456789abcdefLL
) } },
4126 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4128 "ST_MEM_B: Store/Load byte: max negative",
4130 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4131 BPF_ST_MEM(BPF_B
, R10
, -40, 0xff),
4132 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4141 "ST_MEM_B: Store/Load byte: max positive",
4143 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4144 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7f),
4145 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4154 "STX_MEM_B: Store/Load byte: max negative",
4156 BPF_LD_IMM64(R0
, 0),
4157 BPF_LD_IMM64(R1
, 0xffLL
),
4158 BPF_STX_MEM(BPF_B
, R10
, R1
, -40),
4159 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4168 "ST_MEM_H: Store/Load half word: max negative",
4170 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4171 BPF_ST_MEM(BPF_H
, R10
, -40, 0xffff),
4172 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4181 "ST_MEM_H: Store/Load half word: max positive",
4183 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4184 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7fff),
4185 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4194 "STX_MEM_H: Store/Load half word: max negative",
4196 BPF_LD_IMM64(R0
, 0),
4197 BPF_LD_IMM64(R1
, 0xffffLL
),
4198 BPF_STX_MEM(BPF_H
, R10
, R1
, -40),
4199 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4208 "ST_MEM_W: Store/Load word: max negative",
4210 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4211 BPF_ST_MEM(BPF_W
, R10
, -40, 0xffffffff),
4212 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4217 { { 0, 0xffffffff } },
4221 "ST_MEM_W: Store/Load word: max positive",
4223 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4224 BPF_ST_MEM(BPF_W
, R10
, -40, 0x7fffffff),
4225 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4230 { { 0, 0x7fffffff } },
4234 "STX_MEM_W: Store/Load word: max negative",
4236 BPF_LD_IMM64(R0
, 0),
4237 BPF_LD_IMM64(R1
, 0xffffffffLL
),
4238 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4239 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4244 { { 0, 0xffffffff } },
4248 "ST_MEM_DW: Store/Load double word: max negative",
4250 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4251 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4252 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4257 { { 0, 0xffffffff } },
4261 "ST_MEM_DW: Store/Load double word: max negative 2",
4263 BPF_LD_IMM64(R2
, 0xffff00000000ffffLL
),
4264 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
4265 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4266 BPF_LDX_MEM(BPF_DW
, R2
, R10
, -40),
4267 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
4268 BPF_MOV32_IMM(R0
, 2),
4270 BPF_MOV32_IMM(R0
, 1),
4279 "ST_MEM_DW: Store/Load double word: max positive",
4281 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4282 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x7fffffff),
4283 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4288 { { 0, 0x7fffffff } },
4292 "STX_MEM_DW: Store/Load double word: max negative",
4294 BPF_LD_IMM64(R0
, 0),
4295 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4296 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4297 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4302 { { 0, 0xffffffff } },
4305 /* BPF_STX | BPF_XADD | BPF_W/DW */
4307 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4309 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4310 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4311 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4312 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4321 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4323 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4324 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4325 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4326 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4327 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4328 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4337 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4339 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4340 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4341 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4350 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4355 .fill_helper
= bpf_fill_stxw
,
4358 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4360 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4361 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4362 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4363 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4372 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4374 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4375 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4376 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4377 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4378 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4379 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4388 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4390 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4391 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4392 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4401 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4406 .fill_helper
= bpf_fill_stxdw
,
4408 /* BPF_JMP | BPF_EXIT */
4412 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4711),
4414 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4712),
4420 /* BPF_JMP | BPF_JA */
4422 "JMP_JA: Unconditional jump: if (true) return 1",
4424 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4425 BPF_JMP_IMM(BPF_JA
, 0, 0, 1),
4427 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4434 /* BPF_JMP | BPF_JSLT | BPF_K */
4436 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4438 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4439 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4440 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4442 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4450 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4452 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4453 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4454 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4456 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4463 /* BPF_JMP | BPF_JSGT | BPF_K */
4465 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4467 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4468 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4469 BPF_JMP_IMM(BPF_JSGT
, R1
, -2, 1),
4471 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4479 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4481 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4482 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4483 BPF_JMP_IMM(BPF_JSGT
, R1
, -1, 1),
4485 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4492 /* BPF_JMP | BPF_JSLE | BPF_K */
4494 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4496 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4497 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4498 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4500 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4508 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4510 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4511 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4512 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4514 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4522 "JMP_JSLE_K: Signed jump: value walk 1",
4524 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4525 BPF_LD_IMM64(R1
, 3),
4526 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 6),
4527 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4528 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4529 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4530 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4531 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4532 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4533 BPF_EXIT_INSN(), /* bad exit */
4534 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4542 "JMP_JSLE_K: Signed jump: value walk 2",
4544 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4545 BPF_LD_IMM64(R1
, 3),
4546 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4547 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4548 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4549 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4550 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4551 BPF_EXIT_INSN(), /* bad exit */
4552 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4559 /* BPF_JMP | BPF_JSGE | BPF_K */
4561 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4563 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4564 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4565 BPF_JMP_IMM(BPF_JSGE
, R1
, -2, 1),
4567 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4575 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4577 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4578 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4579 BPF_JMP_IMM(BPF_JSGE
, R1
, -1, 1),
4581 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4589 "JMP_JSGE_K: Signed jump: value walk 1",
4591 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4592 BPF_LD_IMM64(R1
, -3),
4593 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 6),
4594 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4595 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4596 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4597 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4598 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4599 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4600 BPF_EXIT_INSN(), /* bad exit */
4601 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4609 "JMP_JSGE_K: Signed jump: value walk 2",
4611 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4612 BPF_LD_IMM64(R1
, -3),
4613 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4614 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4615 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4616 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4617 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4618 BPF_EXIT_INSN(), /* bad exit */
4619 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4626 /* BPF_JMP | BPF_JGT | BPF_K */
4628 "JMP_JGT_K: if (3 > 2) return 1",
4630 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4631 BPF_LD_IMM64(R1
, 3),
4632 BPF_JMP_IMM(BPF_JGT
, R1
, 2, 1),
4634 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4642 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4644 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4645 BPF_LD_IMM64(R1
, -1),
4646 BPF_JMP_IMM(BPF_JGT
, R1
, 1, 1),
4648 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4655 /* BPF_JMP | BPF_JLT | BPF_K */
4657 "JMP_JLT_K: if (2 < 3) return 1",
4659 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4660 BPF_LD_IMM64(R1
, 2),
4661 BPF_JMP_IMM(BPF_JLT
, R1
, 3, 1),
4663 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4671 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4673 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4674 BPF_LD_IMM64(R1
, 1),
4675 BPF_JMP_IMM(BPF_JLT
, R1
, -1, 1),
4677 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4684 /* BPF_JMP | BPF_JGE | BPF_K */
4686 "JMP_JGE_K: if (3 >= 2) return 1",
4688 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4689 BPF_LD_IMM64(R1
, 3),
4690 BPF_JMP_IMM(BPF_JGE
, R1
, 2, 1),
4692 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4699 /* BPF_JMP | BPF_JLE | BPF_K */
4701 "JMP_JLE_K: if (2 <= 3) return 1",
4703 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4704 BPF_LD_IMM64(R1
, 2),
4705 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4707 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4714 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4716 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4718 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4719 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4721 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4722 BPF_LD_IMM64(R1
, 3), /* note: this takes 2 insns */
4723 BPF_JMP_IMM(BPF_JGT
, R1
, 2, -6), /* goto out */
4731 "JMP_JGE_K: if (3 >= 3) return 1",
4733 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4734 BPF_LD_IMM64(R1
, 3),
4735 BPF_JMP_IMM(BPF_JGE
, R1
, 3, 1),
4737 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4744 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4746 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4748 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4749 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4751 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4752 BPF_LD_IMM64(R1
, 2), /* note: this takes 2 insns */
4753 BPF_JMP_IMM(BPF_JLT
, R1
, 3, -6), /* goto out */
4761 "JMP_JLE_K: if (3 <= 3) return 1",
4763 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4764 BPF_LD_IMM64(R1
, 3),
4765 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4767 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4774 /* BPF_JMP | BPF_JNE | BPF_K */
4776 "JMP_JNE_K: if (3 != 2) return 1",
4778 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4779 BPF_LD_IMM64(R1
, 3),
4780 BPF_JMP_IMM(BPF_JNE
, R1
, 2, 1),
4782 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4789 /* BPF_JMP | BPF_JEQ | BPF_K */
4791 "JMP_JEQ_K: if (3 == 3) return 1",
4793 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4794 BPF_LD_IMM64(R1
, 3),
4795 BPF_JMP_IMM(BPF_JEQ
, R1
, 3, 1),
4797 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4804 /* BPF_JMP | BPF_JSET | BPF_K */
4806 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4808 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4809 BPF_LD_IMM64(R1
, 3),
4810 BPF_JMP_IMM(BPF_JSET
, R1
, 2, 1),
4812 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4820 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4822 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4823 BPF_LD_IMM64(R1
, 3),
4824 BPF_JMP_IMM(BPF_JSET
, R1
, 0xffffffff, 1),
4826 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4833 /* BPF_JMP | BPF_JSGT | BPF_X */
4835 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4837 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4838 BPF_LD_IMM64(R1
, -1),
4839 BPF_LD_IMM64(R2
, -2),
4840 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4842 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4850 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4852 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4853 BPF_LD_IMM64(R1
, -1),
4854 BPF_LD_IMM64(R2
, -1),
4855 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4857 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4864 /* BPF_JMP | BPF_JSLT | BPF_X */
4866 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4868 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4869 BPF_LD_IMM64(R1
, -1),
4870 BPF_LD_IMM64(R2
, -2),
4871 BPF_JMP_REG(BPF_JSLT
, R2
, R1
, 1),
4873 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4881 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
4883 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4884 BPF_LD_IMM64(R1
, -1),
4885 BPF_LD_IMM64(R2
, -1),
4886 BPF_JMP_REG(BPF_JSLT
, R1
, R2
, 1),
4888 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4895 /* BPF_JMP | BPF_JSGE | BPF_X */
4897 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4899 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4900 BPF_LD_IMM64(R1
, -1),
4901 BPF_LD_IMM64(R2
, -2),
4902 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
4904 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4912 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4914 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4915 BPF_LD_IMM64(R1
, -1),
4916 BPF_LD_IMM64(R2
, -1),
4917 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
4919 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4926 /* BPF_JMP | BPF_JSLE | BPF_X */
4928 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
4930 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4931 BPF_LD_IMM64(R1
, -1),
4932 BPF_LD_IMM64(R2
, -2),
4933 BPF_JMP_REG(BPF_JSLE
, R2
, R1
, 1),
4935 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4943 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
4945 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4946 BPF_LD_IMM64(R1
, -1),
4947 BPF_LD_IMM64(R2
, -1),
4948 BPF_JMP_REG(BPF_JSLE
, R1
, R2
, 1),
4950 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4957 /* BPF_JMP | BPF_JGT | BPF_X */
4959 "JMP_JGT_X: if (3 > 2) return 1",
4961 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4962 BPF_LD_IMM64(R1
, 3),
4963 BPF_LD_IMM64(R2
, 2),
4964 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
4966 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4974 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
4976 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4977 BPF_LD_IMM64(R1
, -1),
4978 BPF_LD_IMM64(R2
, 1),
4979 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
4981 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4988 /* BPF_JMP | BPF_JLT | BPF_X */
4990 "JMP_JLT_X: if (2 < 3) return 1",
4992 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4993 BPF_LD_IMM64(R1
, 3),
4994 BPF_LD_IMM64(R2
, 2),
4995 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
4997 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5005 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5007 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5008 BPF_LD_IMM64(R1
, -1),
5009 BPF_LD_IMM64(R2
, 1),
5010 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5012 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5019 /* BPF_JMP | BPF_JGE | BPF_X */
5021 "JMP_JGE_X: if (3 >= 2) return 1",
5023 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5024 BPF_LD_IMM64(R1
, 3),
5025 BPF_LD_IMM64(R2
, 2),
5026 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5028 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5036 "JMP_JGE_X: if (3 >= 3) return 1",
5038 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5039 BPF_LD_IMM64(R1
, 3),
5040 BPF_LD_IMM64(R2
, 3),
5041 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5043 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5050 /* BPF_JMP | BPF_JLE | BPF_X */
5052 "JMP_JLE_X: if (2 <= 3) return 1",
5054 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5055 BPF_LD_IMM64(R1
, 3),
5056 BPF_LD_IMM64(R2
, 2),
5057 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 1),
5059 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5067 "JMP_JLE_X: if (3 <= 3) return 1",
5069 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5070 BPF_LD_IMM64(R1
, 3),
5071 BPF_LD_IMM64(R2
, 3),
5072 BPF_JMP_REG(BPF_JLE
, R1
, R2
, 1),
5074 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5082 /* Mainly testing JIT + imm64 here. */
5083 "JMP_JGE_X: ldimm64 test 1",
5085 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5086 BPF_LD_IMM64(R1
, 3),
5087 BPF_LD_IMM64(R2
, 2),
5088 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 2),
5089 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5090 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5095 { { 0, 0xeeeeeeeeU
} },
5098 "JMP_JGE_X: ldimm64 test 2",
5100 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5101 BPF_LD_IMM64(R1
, 3),
5102 BPF_LD_IMM64(R2
, 2),
5103 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 0),
5104 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5109 { { 0, 0xffffffffU
} },
5112 "JMP_JGE_X: ldimm64 test 3",
5114 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5115 BPF_LD_IMM64(R1
, 3),
5116 BPF_LD_IMM64(R2
, 2),
5117 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 4),
5118 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5119 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5127 "JMP_JLE_X: ldimm64 test 1",
5129 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5130 BPF_LD_IMM64(R1
, 3),
5131 BPF_LD_IMM64(R2
, 2),
5132 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 2),
5133 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5134 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5139 { { 0, 0xeeeeeeeeU
} },
5142 "JMP_JLE_X: ldimm64 test 2",
5144 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5145 BPF_LD_IMM64(R1
, 3),
5146 BPF_LD_IMM64(R2
, 2),
5147 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 0),
5148 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5153 { { 0, 0xffffffffU
} },
5156 "JMP_JLE_X: ldimm64 test 3",
5158 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5159 BPF_LD_IMM64(R1
, 3),
5160 BPF_LD_IMM64(R2
, 2),
5161 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 4),
5162 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5163 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5170 /* BPF_JMP | BPF_JNE | BPF_X */
5172 "JMP_JNE_X: if (3 != 2) return 1",
5174 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5175 BPF_LD_IMM64(R1
, 3),
5176 BPF_LD_IMM64(R2
, 2),
5177 BPF_JMP_REG(BPF_JNE
, R1
, R2
, 1),
5179 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5186 /* BPF_JMP | BPF_JEQ | BPF_X */
5188 "JMP_JEQ_X: if (3 == 3) return 1",
5190 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5191 BPF_LD_IMM64(R1
, 3),
5192 BPF_LD_IMM64(R2
, 3),
5193 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
5195 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5202 /* BPF_JMP | BPF_JSET | BPF_X */
5204 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5206 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5207 BPF_LD_IMM64(R1
, 3),
5208 BPF_LD_IMM64(R2
, 2),
5209 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5211 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5219 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5221 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5222 BPF_LD_IMM64(R1
, 3),
5223 BPF_LD_IMM64(R2
, 0xffffffff),
5224 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5226 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5234 "JMP_JA: Jump, gap, jump, ...",
5236 CLASSIC
| FLAG_NO_DATA
,
5238 { { 0, 0xababcbac } },
5239 .fill_helper
= bpf_fill_ja
,
5241 { /* Mainly checking JIT here. */
5242 "BPF_MAXINSNS: Maximum possible literals",
5244 CLASSIC
| FLAG_NO_DATA
,
5246 { { 0, 0xffffffff } },
5247 .fill_helper
= bpf_fill_maxinsns1
,
5249 { /* Mainly checking JIT here. */
5250 "BPF_MAXINSNS: Single literal",
5252 CLASSIC
| FLAG_NO_DATA
,
5254 { { 0, 0xfefefefe } },
5255 .fill_helper
= bpf_fill_maxinsns2
,
5257 { /* Mainly checking JIT here. */
5258 "BPF_MAXINSNS: Run/add until end",
5260 CLASSIC
| FLAG_NO_DATA
,
5262 { { 0, 0x947bf368 } },
5263 .fill_helper
= bpf_fill_maxinsns3
,
5266 "BPF_MAXINSNS: Too many instructions",
5268 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5271 .fill_helper
= bpf_fill_maxinsns4
,
5272 .expected_errcode
= -EINVAL
,
5274 { /* Mainly checking JIT here. */
5275 "BPF_MAXINSNS: Very long jump",
5277 CLASSIC
| FLAG_NO_DATA
,
5279 { { 0, 0xabababab } },
5280 .fill_helper
= bpf_fill_maxinsns5
,
5282 { /* Mainly checking JIT here. */
5283 "BPF_MAXINSNS: Ctx heavy transformations",
5285 #if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5286 CLASSIC
| FLAG_EXPECTED_FAIL
,
5292 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
5293 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
5295 .fill_helper
= bpf_fill_maxinsns6
,
5296 .expected_errcode
= -ENOTSUPP
,
5298 { /* Mainly checking JIT here. */
5299 "BPF_MAXINSNS: Call heavy transformations",
5301 #if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5302 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5304 CLASSIC
| FLAG_NO_DATA
,
5307 { { 1, 0 }, { 10, 0 } },
5308 .fill_helper
= bpf_fill_maxinsns7
,
5309 .expected_errcode
= -ENOTSUPP
,
5311 { /* Mainly checking JIT here. */
5312 "BPF_MAXINSNS: Jump heavy test",
5314 CLASSIC
| FLAG_NO_DATA
,
5316 { { 0, 0xffffffff } },
5317 .fill_helper
= bpf_fill_maxinsns8
,
5319 { /* Mainly checking JIT here. */
5320 "BPF_MAXINSNS: Very long jump backwards",
5322 INTERNAL
| FLAG_NO_DATA
,
5324 { { 0, 0xcbababab } },
5325 .fill_helper
= bpf_fill_maxinsns9
,
5327 { /* Mainly checking JIT here. */
5328 "BPF_MAXINSNS: Edge hopping nuthouse",
5330 INTERNAL
| FLAG_NO_DATA
,
5332 { { 0, 0xabababac } },
5333 .fill_helper
= bpf_fill_maxinsns10
,
5336 "BPF_MAXINSNS: Jump, gap, jump, ...",
5338 #if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_X86)
5339 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5341 CLASSIC
| FLAG_NO_DATA
,
5344 { { 0, 0xababcbac } },
5345 .fill_helper
= bpf_fill_maxinsns11
,
5346 .expected_errcode
= -ENOTSUPP
,
5349 "BPF_MAXINSNS: jump over MSH",
5351 CLASSIC
| FLAG_EXPECTED_FAIL
,
5352 { 0xfa, 0xfb, 0xfc, 0xfd, },
5353 { { 4, 0xabababab } },
5354 .fill_helper
= bpf_fill_maxinsns12
,
5355 .expected_errcode
= -EINVAL
,
5358 "BPF_MAXINSNS: exec all MSH",
5360 #if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5361 CLASSIC
| FLAG_EXPECTED_FAIL
,
5365 { 0xfa, 0xfb, 0xfc, 0xfd, },
5366 { { 4, 0xababab83 } },
5367 .fill_helper
= bpf_fill_maxinsns13
,
5368 .expected_errcode
= -ENOTSUPP
,
5371 "BPF_MAXINSNS: ld_abs+get_processor_id",
5373 #if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5374 CLASSIC
| FLAG_EXPECTED_FAIL
,
5380 .fill_helper
= bpf_fill_ld_abs_get_processor_id
,
5381 .expected_errcode
= -ENOTSUPP
,
5384 * LD_IND / LD_ABS on fragmented SKBs
5389 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5390 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x0),
5391 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5393 CLASSIC
| FLAG_SKB_FRAG
,
5397 0x42, 0x00, 0x00, 0x00,
5398 0x43, 0x44, 0x00, 0x00,
5399 0x21, 0x07, 0x19, 0x83,
5403 "LD_IND halfword frag",
5405 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5406 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x4),
5407 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5409 CLASSIC
| FLAG_SKB_FRAG
,
5413 0x42, 0x00, 0x00, 0x00,
5414 0x43, 0x44, 0x00, 0x00,
5415 0x21, 0x07, 0x19, 0x83,
5421 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5422 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x8),
5423 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5425 CLASSIC
| FLAG_SKB_FRAG
,
5427 { {0x40, 0x21071983} },
5429 0x42, 0x00, 0x00, 0x00,
5430 0x43, 0x44, 0x00, 0x00,
5431 0x21, 0x07, 0x19, 0x83,
5435 "LD_IND halfword mixed head/frag",
5437 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5438 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5439 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5441 CLASSIC
| FLAG_SKB_FRAG
,
5442 { [0x3e] = 0x25, [0x3f] = 0x05, },
5444 .frag_data
= { 0x19, 0x82 },
5447 "LD_IND word mixed head/frag",
5449 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5450 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5451 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5453 CLASSIC
| FLAG_SKB_FRAG
,
5454 { [0x3e] = 0x25, [0x3f] = 0x05, },
5455 { {0x40, 0x25051982} },
5456 .frag_data
= { 0x19, 0x82 },
5461 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x40),
5462 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5464 CLASSIC
| FLAG_SKB_FRAG
,
5468 0x42, 0x00, 0x00, 0x00,
5469 0x43, 0x44, 0x00, 0x00,
5470 0x21, 0x07, 0x19, 0x83,
5474 "LD_ABS halfword frag",
5476 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x44),
5477 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5479 CLASSIC
| FLAG_SKB_FRAG
,
5483 0x42, 0x00, 0x00, 0x00,
5484 0x43, 0x44, 0x00, 0x00,
5485 0x21, 0x07, 0x19, 0x83,
5491 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x48),
5492 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5494 CLASSIC
| FLAG_SKB_FRAG
,
5496 { {0x40, 0x21071983} },
5498 0x42, 0x00, 0x00, 0x00,
5499 0x43, 0x44, 0x00, 0x00,
5500 0x21, 0x07, 0x19, 0x83,
5504 "LD_ABS halfword mixed head/frag",
5506 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3f),
5507 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5509 CLASSIC
| FLAG_SKB_FRAG
,
5510 { [0x3e] = 0x25, [0x3f] = 0x05, },
5512 .frag_data
= { 0x19, 0x82 },
5515 "LD_ABS word mixed head/frag",
5517 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3e),
5518 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5520 CLASSIC
| FLAG_SKB_FRAG
,
5521 { [0x3e] = 0x25, [0x3f] = 0x05, },
5522 { {0x40, 0x25051982} },
5523 .frag_data
= { 0x19, 0x82 },
5526 * LD_IND / LD_ABS on non fragmented SKBs
5530 * this tests that the JIT/interpreter correctly resets X
5531 * before using it in an LD_IND instruction.
5533 "LD_IND byte default X",
5535 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5536 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5543 "LD_IND byte positive offset",
5545 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5546 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5547 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5550 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5554 "LD_IND byte negative offset",
5556 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5557 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, -0x1),
5558 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5561 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5565 "LD_IND byte positive offset, all ff",
5567 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5568 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5569 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5572 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5576 "LD_IND byte positive offset, out of bounds",
5578 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5579 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5580 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5583 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5587 "LD_IND byte negative offset, out of bounds",
5589 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5590 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, -0x3f),
5591 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5594 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5598 "LD_IND byte negative offset, multiple calls",
5600 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3b),
5601 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, SKF_LL_OFF
+ 1),
5602 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, SKF_LL_OFF
+ 2),
5603 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, SKF_LL_OFF
+ 3),
5604 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, SKF_LL_OFF
+ 4),
5605 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5608 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5612 "LD_IND halfword positive offset",
5614 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5615 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x2),
5616 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5620 [0x1c] = 0xaa, [0x1d] = 0x55,
5621 [0x1e] = 0xbb, [0x1f] = 0x66,
5622 [0x20] = 0xcc, [0x21] = 0x77,
5623 [0x22] = 0xdd, [0x23] = 0x88,
5625 { {0x40, 0xdd88 } },
5628 "LD_IND halfword negative offset",
5630 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5631 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x2),
5632 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5636 [0x1c] = 0xaa, [0x1d] = 0x55,
5637 [0x1e] = 0xbb, [0x1f] = 0x66,
5638 [0x20] = 0xcc, [0x21] = 0x77,
5639 [0x22] = 0xdd, [0x23] = 0x88,
5641 { {0x40, 0xbb66 } },
5644 "LD_IND halfword unaligned",
5646 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5647 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5648 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5652 [0x1c] = 0xaa, [0x1d] = 0x55,
5653 [0x1e] = 0xbb, [0x1f] = 0x66,
5654 [0x20] = 0xcc, [0x21] = 0x77,
5655 [0x22] = 0xdd, [0x23] = 0x88,
5657 { {0x40, 0x66cc } },
5660 "LD_IND halfword positive offset, all ff",
5662 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3d),
5663 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x1),
5664 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5667 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5668 { {0x40, 0xffff } },
5671 "LD_IND halfword positive offset, out of bounds",
5673 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5674 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x1),
5675 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5678 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5682 "LD_IND halfword negative offset, out of bounds",
5684 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5685 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x3f),
5686 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5689 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5693 "LD_IND word positive offset",
5695 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5696 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x4),
5697 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5701 [0x1c] = 0xaa, [0x1d] = 0x55,
5702 [0x1e] = 0xbb, [0x1f] = 0x66,
5703 [0x20] = 0xcc, [0x21] = 0x77,
5704 [0x22] = 0xdd, [0x23] = 0x88,
5705 [0x24] = 0xee, [0x25] = 0x99,
5706 [0x26] = 0xff, [0x27] = 0xaa,
5708 { {0x40, 0xee99ffaa } },
5711 "LD_IND word negative offset",
5713 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5714 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x4),
5715 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5719 [0x1c] = 0xaa, [0x1d] = 0x55,
5720 [0x1e] = 0xbb, [0x1f] = 0x66,
5721 [0x20] = 0xcc, [0x21] = 0x77,
5722 [0x22] = 0xdd, [0x23] = 0x88,
5723 [0x24] = 0xee, [0x25] = 0x99,
5724 [0x26] = 0xff, [0x27] = 0xaa,
5726 { {0x40, 0xaa55bb66 } },
5729 "LD_IND word unaligned (addr & 3 == 2)",
5731 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5732 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5733 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5737 [0x1c] = 0xaa, [0x1d] = 0x55,
5738 [0x1e] = 0xbb, [0x1f] = 0x66,
5739 [0x20] = 0xcc, [0x21] = 0x77,
5740 [0x22] = 0xdd, [0x23] = 0x88,
5741 [0x24] = 0xee, [0x25] = 0x99,
5742 [0x26] = 0xff, [0x27] = 0xaa,
5744 { {0x40, 0xbb66cc77 } },
5747 "LD_IND word unaligned (addr & 3 == 1)",
5749 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5750 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x3),
5751 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5755 [0x1c] = 0xaa, [0x1d] = 0x55,
5756 [0x1e] = 0xbb, [0x1f] = 0x66,
5757 [0x20] = 0xcc, [0x21] = 0x77,
5758 [0x22] = 0xdd, [0x23] = 0x88,
5759 [0x24] = 0xee, [0x25] = 0x99,
5760 [0x26] = 0xff, [0x27] = 0xaa,
5762 { {0x40, 0x55bb66cc } },
5765 "LD_IND word unaligned (addr & 3 == 3)",
5767 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5768 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x1),
5769 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5773 [0x1c] = 0xaa, [0x1d] = 0x55,
5774 [0x1e] = 0xbb, [0x1f] = 0x66,
5775 [0x20] = 0xcc, [0x21] = 0x77,
5776 [0x22] = 0xdd, [0x23] = 0x88,
5777 [0x24] = 0xee, [0x25] = 0x99,
5778 [0x26] = 0xff, [0x27] = 0xaa,
5780 { {0x40, 0x66cc77dd } },
5783 "LD_IND word positive offset, all ff",
5785 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3b),
5786 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x1),
5787 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5790 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5791 { {0x40, 0xffffffff } },
5794 "LD_IND word positive offset, out of bounds",
5796 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5797 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x1),
5798 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5801 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5805 "LD_IND word negative offset, out of bounds",
5807 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5808 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x3f),
5809 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5812 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5818 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x20),
5819 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5823 [0x1c] = 0xaa, [0x1d] = 0x55,
5824 [0x1e] = 0xbb, [0x1f] = 0x66,
5825 [0x20] = 0xcc, [0x21] = 0x77,
5826 [0x22] = 0xdd, [0x23] = 0x88,
5827 [0x24] = 0xee, [0x25] = 0x99,
5828 [0x26] = 0xff, [0x27] = 0xaa,
5833 "LD_ABS byte positive offset, all ff",
5835 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x3f),
5836 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5839 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5843 "LD_ABS byte positive offset, out of bounds",
5845 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x3f),
5846 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5849 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5853 "LD_ABS byte negative offset, out of bounds load",
5855 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, -1),
5856 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5858 CLASSIC
| FLAG_EXPECTED_FAIL
,
5859 .expected_errcode
= -EINVAL
,
5862 "LD_ABS byte negative offset, in bounds",
5864 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, SKF_LL_OFF
+ 0x3f),
5865 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5868 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5872 "LD_ABS byte negative offset, out of bounds",
5874 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, SKF_LL_OFF
+ 0x3f),
5875 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5878 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5882 "LD_ABS byte negative offset, multiple calls",
5884 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, SKF_LL_OFF
+ 0x3c),
5885 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, SKF_LL_OFF
+ 0x3d),
5886 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, SKF_LL_OFF
+ 0x3e),
5887 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, SKF_LL_OFF
+ 0x3f),
5888 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5891 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5897 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x22),
5898 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5902 [0x1c] = 0xaa, [0x1d] = 0x55,
5903 [0x1e] = 0xbb, [0x1f] = 0x66,
5904 [0x20] = 0xcc, [0x21] = 0x77,
5905 [0x22] = 0xdd, [0x23] = 0x88,
5906 [0x24] = 0xee, [0x25] = 0x99,
5907 [0x26] = 0xff, [0x27] = 0xaa,
5909 { {0x40, 0xdd88 } },
5912 "LD_ABS halfword unaligned",
5914 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x25),
5915 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5919 [0x1c] = 0xaa, [0x1d] = 0x55,
5920 [0x1e] = 0xbb, [0x1f] = 0x66,
5921 [0x20] = 0xcc, [0x21] = 0x77,
5922 [0x22] = 0xdd, [0x23] = 0x88,
5923 [0x24] = 0xee, [0x25] = 0x99,
5924 [0x26] = 0xff, [0x27] = 0xaa,
5926 { {0x40, 0x99ff } },
5929 "LD_ABS halfword positive offset, all ff",
5931 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3e),
5932 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5935 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5936 { {0x40, 0xffff } },
5939 "LD_ABS halfword positive offset, out of bounds",
5941 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3f),
5942 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5945 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5949 "LD_ABS halfword negative offset, out of bounds load",
5951 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, -1),
5952 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5954 CLASSIC
| FLAG_EXPECTED_FAIL
,
5955 .expected_errcode
= -EINVAL
,
5958 "LD_ABS halfword negative offset, in bounds",
5960 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, SKF_LL_OFF
+ 0x3e),
5961 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5964 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5965 { {0x40, 0x1982 }, },
5968 "LD_ABS halfword negative offset, out of bounds",
5970 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, SKF_LL_OFF
+ 0x3e),
5971 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5974 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5980 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x1c),
5981 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5985 [0x1c] = 0xaa, [0x1d] = 0x55,
5986 [0x1e] = 0xbb, [0x1f] = 0x66,
5987 [0x20] = 0xcc, [0x21] = 0x77,
5988 [0x22] = 0xdd, [0x23] = 0x88,
5989 [0x24] = 0xee, [0x25] = 0x99,
5990 [0x26] = 0xff, [0x27] = 0xaa,
5992 { {0x40, 0xaa55bb66 } },
5995 "LD_ABS word unaligned (addr & 3 == 2)",
5997 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x22),
5998 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6002 [0x1c] = 0xaa, [0x1d] = 0x55,
6003 [0x1e] = 0xbb, [0x1f] = 0x66,
6004 [0x20] = 0xcc, [0x21] = 0x77,
6005 [0x22] = 0xdd, [0x23] = 0x88,
6006 [0x24] = 0xee, [0x25] = 0x99,
6007 [0x26] = 0xff, [0x27] = 0xaa,
6009 { {0x40, 0xdd88ee99 } },
6012 "LD_ABS word unaligned (addr & 3 == 1)",
6014 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x21),
6015 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6019 [0x1c] = 0xaa, [0x1d] = 0x55,
6020 [0x1e] = 0xbb, [0x1f] = 0x66,
6021 [0x20] = 0xcc, [0x21] = 0x77,
6022 [0x22] = 0xdd, [0x23] = 0x88,
6023 [0x24] = 0xee, [0x25] = 0x99,
6024 [0x26] = 0xff, [0x27] = 0xaa,
6026 { {0x40, 0x77dd88ee } },
6029 "LD_ABS word unaligned (addr & 3 == 3)",
6031 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x23),
6032 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6036 [0x1c] = 0xaa, [0x1d] = 0x55,
6037 [0x1e] = 0xbb, [0x1f] = 0x66,
6038 [0x20] = 0xcc, [0x21] = 0x77,
6039 [0x22] = 0xdd, [0x23] = 0x88,
6040 [0x24] = 0xee, [0x25] = 0x99,
6041 [0x26] = 0xff, [0x27] = 0xaa,
6043 { {0x40, 0x88ee99ff } },
6046 "LD_ABS word positive offset, all ff",
6048 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3c),
6049 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6052 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6053 { {0x40, 0xffffffff } },
6056 "LD_ABS word positive offset, out of bounds",
6058 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3f),
6059 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6062 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6066 "LD_ABS word negative offset, out of bounds load",
6068 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, -1),
6069 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6071 CLASSIC
| FLAG_EXPECTED_FAIL
,
6072 .expected_errcode
= -EINVAL
,
6075 "LD_ABS word negative offset, in bounds",
6077 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, SKF_LL_OFF
+ 0x3c),
6078 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6081 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6082 { {0x40, 0x25051982 }, },
6085 "LD_ABS word negative offset, out of bounds",
6087 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, SKF_LL_OFF
+ 0x3c),
6088 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6091 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6095 "LDX_MSH standalone, preserved A",
6097 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffeebbaa),
6098 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3c),
6099 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6102 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6103 { {0x40, 0xffeebbaa }, },
6106 "LDX_MSH standalone, preserved A 2",
6108 BPF_STMT(BPF_LD
| BPF_IMM
, 0x175e9d63),
6109 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3c),
6110 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3d),
6111 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3e),
6112 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3f),
6113 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6116 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6117 { {0x40, 0x175e9d63 }, },
6120 "LDX_MSH standalone, test result 1",
6122 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffeebbaa),
6123 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3c),
6124 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
6125 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6128 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6132 "LDX_MSH standalone, test result 2",
6134 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffeebbaa),
6135 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x3e),
6136 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
6137 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6140 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6144 "LDX_MSH standalone, negative offset",
6146 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffeebbaa),
6147 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, -1),
6148 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
6149 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6152 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6156 "LDX_MSH standalone, negative offset 2",
6158 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffeebbaa),
6159 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, SKF_LL_OFF
+ 0x3e),
6160 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
6161 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6164 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6168 "LDX_MSH standalone, out of bounds",
6170 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffeebbaa),
6171 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 0x40),
6172 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
6173 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6176 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6180 * verify that the interpreter or JIT correctly sets A and X
6191 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6192 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
6193 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6195 CLASSIC
| FLAG_NO_DATA
,
6206 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0x42),
6207 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6209 CLASSIC
| FLAG_NO_DATA
,
6221 BPF_STMT(BPF_LD
| BPF_IMM
, 0x66),
6222 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
6223 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6225 CLASSIC
| FLAG_NO_DATA
,
6236 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, -0x66),
6237 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6239 CLASSIC
| FLAG_NO_DATA
,
6251 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6252 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_X
, 0),
6253 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6255 CLASSIC
| FLAG_NO_DATA
,
6266 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 0x66),
6267 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6269 CLASSIC
| FLAG_NO_DATA
,
6278 * A = A / X ; this halt the filter execution if X is 0
6281 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6282 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
6283 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6285 CLASSIC
| FLAG_NO_DATA
,
6296 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x1),
6297 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6299 CLASSIC
| FLAG_NO_DATA
,
6308 * A = A mod X ; this halt the filter execution if X is 0
6311 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6312 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
6313 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6315 CLASSIC
| FLAG_NO_DATA
,
6326 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x1),
6327 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6329 CLASSIC
| FLAG_NO_DATA
,
6341 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0, 0, 1),
6342 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6343 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6345 CLASSIC
| FLAG_NO_DATA
,
6358 BPF_STMT(BPF_LD
| BPF_IMM
, 0x0),
6359 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0x0, 0, 1),
6360 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6361 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6363 CLASSIC
| FLAG_NO_DATA
,
6367 /* Checking interpreter vs JIT wrt signed extended imms. */
6369 "JNE signed compare, test 1",
6371 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6372 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6373 BPF_MOV64_REG(R2
, R1
),
6374 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6375 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6376 BPF_JMP_IMM(BPF_JNE
, R2
, -17104896, 1),
6377 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6385 "JNE signed compare, test 2",
6387 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6388 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6389 BPF_MOV64_REG(R2
, R1
),
6390 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6391 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6392 BPF_JMP_IMM(BPF_JNE
, R2
, 0xfefb0000, 1),
6393 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6401 "JNE signed compare, test 3",
6403 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xfefbbc12),
6404 BPF_ALU32_IMM(BPF_MOV
, R3
, 0xffff0000),
6405 BPF_ALU32_IMM(BPF_MOV
, R4
, 0xfefb0000),
6406 BPF_MOV64_REG(R2
, R1
),
6407 BPF_ALU64_REG(BPF_AND
, R2
, R3
),
6408 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6409 BPF_JMP_REG(BPF_JNE
, R2
, R4
, 1),
6410 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6418 "JNE signed compare, test 4",
6420 BPF_LD_IMM64(R1
, -17104896),
6421 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6422 BPF_JMP_IMM(BPF_JNE
, R1
, -17104896, 1),
6423 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6431 "JNE signed compare, test 5",
6433 BPF_LD_IMM64(R1
, 0xfefb0000),
6434 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6435 BPF_JMP_IMM(BPF_JNE
, R1
, 0xfefb0000, 1),
6436 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6444 "JNE signed compare, test 6",
6446 BPF_LD_IMM64(R1
, 0x7efb0000),
6447 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
6448 BPF_JMP_IMM(BPF_JNE
, R1
, 0x7efb0000, 1),
6449 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
6457 "JNE signed compare, test 7",
6459 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffff0000),
6460 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6461 BPF_STMT(BPF_LD
| BPF_IMM
, 0xfefbbc12),
6462 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_X
, 0),
6463 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xfefb0000, 1, 0),
6464 BPF_STMT(BPF_RET
| BPF_K
, 1),
6465 BPF_STMT(BPF_RET
| BPF_K
, 2),
6467 CLASSIC
| FLAG_NO_DATA
,
6473 static struct net_device dev
;
6475 static struct sk_buff
*populate_skb(char *buf
, int size
)
6477 struct sk_buff
*skb
;
6479 if (size
>= MAX_DATA
)
6482 skb
= alloc_skb(MAX_DATA
, GFP_KERNEL
);
6486 __skb_put_data(skb
, buf
, size
);
6488 /* Initialize a fake skb with test pattern. */
6489 skb_reset_mac_header(skb
);
6490 skb
->protocol
= htons(ETH_P_IP
);
6491 skb
->pkt_type
= SKB_TYPE
;
6492 skb
->mark
= SKB_MARK
;
6493 skb
->hash
= SKB_HASH
;
6494 skb
->queue_mapping
= SKB_QUEUE_MAP
;
6495 skb
->vlan_tci
= SKB_VLAN_TCI
;
6496 skb
->vlan_proto
= htons(ETH_P_IP
);
6498 skb
->dev
->ifindex
= SKB_DEV_IFINDEX
;
6499 skb
->dev
->type
= SKB_DEV_TYPE
;
6500 skb_set_network_header(skb
, min(size
, ETH_HLEN
));
6505 static void *generate_test_data(struct bpf_test
*test
, int sub
)
6507 struct sk_buff
*skb
;
6510 if (test
->aux
& FLAG_NO_DATA
)
6513 /* Test case expects an skb, so populate one. Various
6514 * subtests generate skbs of different sizes based on
6517 skb
= populate_skb(test
->data
, test
->test
[sub
].data_size
);
6521 if (test
->aux
& FLAG_SKB_FRAG
) {
6523 * when the test requires a fragmented skb, add a
6524 * single fragment to the skb, filled with
6529 page
= alloc_page(GFP_KERNEL
);
6537 memcpy(ptr
, test
->frag_data
, MAX_DATA
);
6539 skb_add_rx_frag(skb
, 0, page
, 0, MAX_DATA
, MAX_DATA
);
6551 static void release_test_data(const struct bpf_test
*test
, void *data
)
6553 if (test
->aux
& FLAG_NO_DATA
)
6559 static int filter_length(int which
)
6561 struct sock_filter
*fp
;
6564 if (tests
[which
].fill_helper
)
6565 return tests
[which
].u
.ptr
.len
;
6567 fp
= tests
[which
].u
.insns
;
6568 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
6569 if (fp
[len
].code
!= 0 || fp
[len
].k
!= 0)
6575 static void *filter_pointer(int which
)
6577 if (tests
[which
].fill_helper
)
6578 return tests
[which
].u
.ptr
.insns
;
6580 return tests
[which
].u
.insns
;
6583 static struct bpf_prog
*generate_filter(int which
, int *err
)
6585 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6586 unsigned int flen
= filter_length(which
);
6587 void *fptr
= filter_pointer(which
);
6588 struct sock_fprog_kern fprog
;
6589 struct bpf_prog
*fp
;
6591 switch (test_type
) {
6593 fprog
.filter
= fptr
;
6596 *err
= bpf_prog_create(&fp
, &fprog
);
6597 if (tests
[which
].aux
& FLAG_EXPECTED_FAIL
) {
6598 if (*err
== tests
[which
].expected_errcode
) {
6600 /* Verifier rejected filter as expected. */
6604 pr_cont("UNEXPECTED_PASS\n");
6605 /* Verifier didn't reject the test that's
6606 * bad enough, just return!
6613 pr_cont("FAIL to prog_create err=%d len=%d\n",
6620 fp
= bpf_prog_alloc(bpf_prog_size(flen
), 0);
6622 pr_cont("UNEXPECTED_FAIL no memory left\n");
6628 /* Type doesn't really matter here as long as it's not unspec. */
6629 fp
->type
= BPF_PROG_TYPE_SOCKET_FILTER
;
6630 memcpy(fp
->insnsi
, fptr
, fp
->len
* sizeof(struct bpf_insn
));
6631 fp
->aux
->stack_depth
= tests
[which
].stack_depth
;
6633 /* We cannot error here as we don't need type compatibility
6636 fp
= bpf_prog_select_runtime(fp
, err
);
6638 pr_cont("FAIL to select_runtime err=%d\n", *err
);
6648 static void release_filter(struct bpf_prog
*fp
, int which
)
6650 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6652 switch (test_type
) {
6654 bpf_prog_destroy(fp
);
6662 static int __run_one(const struct bpf_prog
*fp
, const void *data
,
6663 int runs
, u64
*duration
)
6668 start
= ktime_get_ns();
6670 for (i
= 0; i
< runs
; i
++)
6671 ret
= BPF_PROG_RUN(fp
, data
);
6673 finish
= ktime_get_ns();
6675 *duration
= finish
- start
;
6676 do_div(*duration
, runs
);
6681 static int run_one(const struct bpf_prog
*fp
, struct bpf_test
*test
)
6683 int err_cnt
= 0, i
, runs
= MAX_TESTRUNS
;
6685 for (i
= 0; i
< MAX_SUBTESTS
; i
++) {
6690 if (test
->test
[i
].data_size
== 0 &&
6691 test
->test
[i
].result
== 0)
6694 data
= generate_test_data(test
, i
);
6695 if (!data
&& !(test
->aux
& FLAG_NO_DATA
)) {
6696 pr_cont("data generation failed ");
6700 ret
= __run_one(fp
, data
, runs
, &duration
);
6701 release_test_data(test
, data
);
6703 if (ret
== test
->test
[i
].result
) {
6704 pr_cont("%lld ", duration
);
6706 pr_cont("ret %d != %d ", ret
,
6707 test
->test
[i
].result
);
6715 static char test_name
[64];
6716 module_param_string(test_name
, test_name
, sizeof(test_name
), 0);
6718 static int test_id
= -1;
6719 module_param(test_id
, int, 0);
6721 static int test_range
[2] = { 0, ARRAY_SIZE(tests
) - 1 };
6722 module_param_array(test_range
, int, NULL
, 0);
6724 static __init
int find_test_index(const char *test_name
)
6728 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6729 if (!strcmp(tests
[i
].descr
, test_name
))
6735 static __init
int prepare_bpf_tests(void)
6741 * if a test_id was specified, use test_range to
6742 * cover only that test.
6744 if (test_id
>= ARRAY_SIZE(tests
)) {
6745 pr_err("test_bpf: invalid test_id specified.\n");
6749 test_range
[0] = test_id
;
6750 test_range
[1] = test_id
;
6751 } else if (*test_name
) {
6753 * if a test_name was specified, find it and setup
6754 * test_range to cover only that test.
6756 int idx
= find_test_index(test_name
);
6759 pr_err("test_bpf: no test named '%s' found.\n",
6763 test_range
[0] = idx
;
6764 test_range
[1] = idx
;
6767 * check that the supplied test_range is valid.
6769 if (test_range
[0] >= ARRAY_SIZE(tests
) ||
6770 test_range
[1] >= ARRAY_SIZE(tests
) ||
6771 test_range
[0] < 0 || test_range
[1] < 0) {
6772 pr_err("test_bpf: test_range is out of bound.\n");
6776 if (test_range
[1] < test_range
[0]) {
6777 pr_err("test_bpf: test_range is ending before it starts.\n");
6782 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6783 if (tests
[i
].fill_helper
&&
6784 tests
[i
].fill_helper(&tests
[i
]) < 0)
6791 static __init
void destroy_bpf_tests(void)
6795 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6796 if (tests
[i
].fill_helper
)
6797 kfree(tests
[i
].u
.ptr
.insns
);
6801 static bool exclude_test(int test_id
)
6803 return test_id
< test_range
[0] || test_id
> test_range
[1];
6806 static __init
struct sk_buff
*build_test_skb(void)
6808 u32 headroom
= NET_SKB_PAD
+ NET_IP_ALIGN
+ ETH_HLEN
;
6809 struct sk_buff
*skb
[2];
6810 struct page
*page
[2];
6811 int i
, data_size
= 8;
6813 for (i
= 0; i
< 2; i
++) {
6814 page
[i
] = alloc_page(GFP_KERNEL
);
6822 /* this will set skb[i]->head_frag */
6823 skb
[i
] = dev_alloc_skb(headroom
+ data_size
);
6831 skb_reserve(skb
[i
], headroom
);
6832 skb_put(skb
[i
], data_size
);
6833 skb
[i
]->protocol
= htons(ETH_P_IP
);
6834 skb_reset_network_header(skb
[i
]);
6835 skb_set_mac_header(skb
[i
], -ETH_HLEN
);
6837 skb_add_rx_frag(skb
[i
], 0, page
[i
], 0, 64, 64);
6838 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
6842 skb_shinfo(skb
[0])->gso_size
= 1448;
6843 skb_shinfo(skb
[0])->gso_type
= SKB_GSO_TCPV4
;
6844 skb_shinfo(skb
[0])->gso_type
|= SKB_GSO_DODGY
;
6845 skb_shinfo(skb
[0])->gso_segs
= 0;
6846 skb_shinfo(skb
[0])->frag_list
= skb
[1];
6848 /* adjust skb[0]'s len */
6849 skb
[0]->len
+= skb
[1]->len
;
6850 skb
[0]->data_len
+= skb
[1]->data_len
;
6851 skb
[0]->truesize
+= skb
[1]->truesize
;
6856 __free_page(page
[1]);
6860 __free_page(page
[0]);
6865 static __init
int test_skb_segment(void)
6867 netdev_features_t features
;
6868 struct sk_buff
*skb
, *segs
;
6871 features
= NETIF_F_SG
| NETIF_F_GSO_PARTIAL
| NETIF_F_IP_CSUM
|
6873 features
|= NETIF_F_RXCSUM
;
6874 skb
= build_test_skb();
6876 pr_info("%s: failed to build_test_skb", __func__
);
6880 segs
= skb_segment(skb
, features
);
6881 if (!IS_ERR(segs
)) {
6882 kfree_skb_list(segs
);
6884 pr_info("%s: success in skb_segment!", __func__
);
6886 pr_info("%s: failed in skb_segment!", __func__
);
6893 static __init
int test_bpf(void)
6895 int i
, err_cnt
= 0, pass_cnt
= 0;
6896 int jit_cnt
= 0, run_cnt
= 0;
6898 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6899 struct bpf_prog
*fp
;
6903 if (exclude_test(i
))
6906 pr_info("#%d %s ", i
, tests
[i
].descr
);
6908 fp
= generate_filter(i
, &err
);
6918 pr_cont("jited:%u ", fp
->jited
);
6924 err
= run_one(fp
, &tests
[i
]);
6925 release_filter(fp
, i
);
6928 pr_cont("FAIL (%d times)\n", err
);
6936 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6937 pass_cnt
, err_cnt
, jit_cnt
, run_cnt
);
6939 return err_cnt
? -EINVAL
: 0;
6942 static int __init
test_bpf_init(void)
6946 ret
= prepare_bpf_tests();
6951 destroy_bpf_tests();
6955 return test_skb_segment();
6958 static void __exit
test_bpf_exit(void)
6962 module_init(test_bpf_init
);
6963 module_exit(test_bpf_exit
);
6965 MODULE_LICENSE("GPL");