Loading...
1/*
2 * Testsuite for BPF interpreter and BPF JIT compiler
3 *
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
5 *
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.
9 *
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.
14 */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
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
28/* General test specific settings */
29#define MAX_SUBTESTS 3
30#define MAX_TESTRUNS 10000
31#define MAX_DATA 128
32#define MAX_INSNS 512
33#define MAX_K 0xffffFFFF
34
35/* Few constants used to init test 'skb' */
36#define SKB_TYPE 3
37#define SKB_MARK 0x1234aaaa
38#define SKB_HASH 0x1234aaab
39#define SKB_QUEUE_MAP 123
40#define SKB_VLAN_TCI 0xffff
41#define SKB_DEV_IFINDEX 577
42#define SKB_DEV_TYPE 588
43
44/* Redefine REGs to make tests less verbose */
45#define R0 BPF_REG_0
46#define R1 BPF_REG_1
47#define R2 BPF_REG_2
48#define R3 BPF_REG_3
49#define R4 BPF_REG_4
50#define R5 BPF_REG_5
51#define R6 BPF_REG_6
52#define R7 BPF_REG_7
53#define R8 BPF_REG_8
54#define R9 BPF_REG_9
55#define R10 BPF_REG_10
56
57/* Flags that can be passed to test cases */
58#define FLAG_NO_DATA BIT(0)
59#define FLAG_EXPECTED_FAIL BIT(1)
60#define FLAG_SKB_FRAG BIT(2)
61
62enum {
63 CLASSIC = BIT(6), /* Old BPF instructions only. */
64 INTERNAL = BIT(7), /* Extended instruction set. */
65};
66
67#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
68
69struct bpf_test {
70 const char *descr;
71 union {
72 struct sock_filter insns[MAX_INSNS];
73 struct bpf_insn insns_int[MAX_INSNS];
74 struct {
75 void *insns;
76 unsigned int len;
77 } ptr;
78 } u;
79 __u8 aux;
80 __u8 data[MAX_DATA];
81 struct {
82 int data_size;
83 __u32 result;
84 } test[MAX_SUBTESTS];
85 int (*fill_helper)(struct bpf_test *self);
86 __u8 frag_data[MAX_DATA];
87};
88
89/* Large test cases need separate allocation and fill handler. */
90
91static int bpf_fill_maxinsns1(struct bpf_test *self)
92{
93 unsigned int len = BPF_MAXINSNS;
94 struct sock_filter *insn;
95 __u32 k = ~0;
96 int i;
97
98 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
99 if (!insn)
100 return -ENOMEM;
101
102 for (i = 0; i < len; i++, k--)
103 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
104
105 self->u.ptr.insns = insn;
106 self->u.ptr.len = len;
107
108 return 0;
109}
110
111static int bpf_fill_maxinsns2(struct bpf_test *self)
112{
113 unsigned int len = BPF_MAXINSNS;
114 struct sock_filter *insn;
115 int i;
116
117 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
118 if (!insn)
119 return -ENOMEM;
120
121 for (i = 0; i < len; i++)
122 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
123
124 self->u.ptr.insns = insn;
125 self->u.ptr.len = len;
126
127 return 0;
128}
129
130static int bpf_fill_maxinsns3(struct bpf_test *self)
131{
132 unsigned int len = BPF_MAXINSNS;
133 struct sock_filter *insn;
134 struct rnd_state rnd;
135 int i;
136
137 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
138 if (!insn)
139 return -ENOMEM;
140
141 prandom_seed_state(&rnd, 3141592653589793238ULL);
142
143 for (i = 0; i < len - 1; i++) {
144 __u32 k = prandom_u32_state(&rnd);
145
146 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
147 }
148
149 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
150
151 self->u.ptr.insns = insn;
152 self->u.ptr.len = len;
153
154 return 0;
155}
156
157static int bpf_fill_maxinsns4(struct bpf_test *self)
158{
159 unsigned int len = BPF_MAXINSNS + 1;
160 struct sock_filter *insn;
161 int i;
162
163 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
164 if (!insn)
165 return -ENOMEM;
166
167 for (i = 0; i < len; i++)
168 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
169
170 self->u.ptr.insns = insn;
171 self->u.ptr.len = len;
172
173 return 0;
174}
175
176static int bpf_fill_maxinsns5(struct bpf_test *self)
177{
178 unsigned int len = BPF_MAXINSNS;
179 struct sock_filter *insn;
180 int i;
181
182 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
183 if (!insn)
184 return -ENOMEM;
185
186 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
187
188 for (i = 1; i < len - 1; i++)
189 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
190
191 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
192
193 self->u.ptr.insns = insn;
194 self->u.ptr.len = len;
195
196 return 0;
197}
198
199static int bpf_fill_maxinsns6(struct bpf_test *self)
200{
201 unsigned int len = BPF_MAXINSNS;
202 struct sock_filter *insn;
203 int i;
204
205 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
206 if (!insn)
207 return -ENOMEM;
208
209 for (i = 0; i < len - 1; i++)
210 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
211 SKF_AD_VLAN_TAG_PRESENT);
212
213 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
214
215 self->u.ptr.insns = insn;
216 self->u.ptr.len = len;
217
218 return 0;
219}
220
221static int bpf_fill_maxinsns7(struct bpf_test *self)
222{
223 unsigned int len = BPF_MAXINSNS;
224 struct sock_filter *insn;
225 int i;
226
227 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
228 if (!insn)
229 return -ENOMEM;
230
231 for (i = 0; i < len - 4; i++)
232 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
233 SKF_AD_CPU);
234
235 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
236 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
237 SKF_AD_CPU);
238 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
239 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
240
241 self->u.ptr.insns = insn;
242 self->u.ptr.len = len;
243
244 return 0;
245}
246
247static int bpf_fill_maxinsns8(struct bpf_test *self)
248{
249 unsigned int len = BPF_MAXINSNS;
250 struct sock_filter *insn;
251 int i, jmp_off = len - 3;
252
253 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
254 if (!insn)
255 return -ENOMEM;
256
257 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
258
259 for (i = 1; i < len - 1; i++)
260 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
261
262 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
263
264 self->u.ptr.insns = insn;
265 self->u.ptr.len = len;
266
267 return 0;
268}
269
270static int bpf_fill_maxinsns9(struct bpf_test *self)
271{
272 unsigned int len = BPF_MAXINSNS;
273 struct bpf_insn *insn;
274 int i;
275
276 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
277 if (!insn)
278 return -ENOMEM;
279
280 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
281 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
282 insn[2] = BPF_EXIT_INSN();
283
284 for (i = 3; i < len - 2; i++)
285 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
286
287 insn[len - 2] = BPF_EXIT_INSN();
288 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
289
290 self->u.ptr.insns = insn;
291 self->u.ptr.len = len;
292
293 return 0;
294}
295
296static int bpf_fill_maxinsns10(struct bpf_test *self)
297{
298 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
299 struct bpf_insn *insn;
300 int i;
301
302 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
303 if (!insn)
304 return -ENOMEM;
305
306 for (i = 0; i < hlen / 2; i++)
307 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
308 for (i = hlen - 1; i > hlen / 2; i--)
309 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
310
311 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
312 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
313 insn[hlen + 1] = BPF_EXIT_INSN();
314
315 self->u.ptr.insns = insn;
316 self->u.ptr.len = len;
317
318 return 0;
319}
320
321static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
322 unsigned int plen)
323{
324 struct sock_filter *insn;
325 unsigned int rlen;
326 int i, j;
327
328 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
329 if (!insn)
330 return -ENOMEM;
331
332 rlen = (len % plen) - 1;
333
334 for (i = 0; i + plen < len; i += plen)
335 for (j = 0; j < plen; j++)
336 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
337 plen - 1 - j, 0, 0);
338 for (j = 0; j < rlen; j++)
339 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
340 0, 0);
341
342 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
343
344 self->u.ptr.insns = insn;
345 self->u.ptr.len = len;
346
347 return 0;
348}
349
350static int bpf_fill_maxinsns11(struct bpf_test *self)
351{
352 /* Hits 70 passes on x86_64, so cannot get JITed there. */
353 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
354}
355
356static int bpf_fill_ja(struct bpf_test *self)
357{
358 /* Hits exactly 11 passes on x86_64 JIT. */
359 return __bpf_fill_ja(self, 12, 9);
360}
361
362static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
363{
364 unsigned int len = BPF_MAXINSNS;
365 struct sock_filter *insn;
366 int i;
367
368 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
369 if (!insn)
370 return -ENOMEM;
371
372 for (i = 0; i < len - 1; i += 2) {
373 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
374 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
375 SKF_AD_OFF + SKF_AD_CPU);
376 }
377
378 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
379
380 self->u.ptr.insns = insn;
381 self->u.ptr.len = len;
382
383 return 0;
384}
385
386#define PUSH_CNT 68
387/* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
388static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
389{
390 unsigned int len = BPF_MAXINSNS;
391 struct bpf_insn *insn;
392 int i = 0, j, k = 0;
393
394 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
395 if (!insn)
396 return -ENOMEM;
397
398 insn[i++] = BPF_MOV64_REG(R6, R1);
399loop:
400 for (j = 0; j < PUSH_CNT; j++) {
401 insn[i++] = BPF_LD_ABS(BPF_B, 0);
402 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
403 i++;
404 insn[i++] = BPF_MOV64_REG(R1, R6);
405 insn[i++] = BPF_MOV64_IMM(R2, 1);
406 insn[i++] = BPF_MOV64_IMM(R3, 2);
407 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
408 bpf_skb_vlan_push_proto.func - __bpf_call_base);
409 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
410 i++;
411 }
412
413 for (j = 0; j < PUSH_CNT; j++) {
414 insn[i++] = BPF_LD_ABS(BPF_B, 0);
415 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
416 i++;
417 insn[i++] = BPF_MOV64_REG(R1, R6);
418 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
419 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
420 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
421 i++;
422 }
423 if (++k < 5)
424 goto loop;
425
426 for (; i < len - 1; i++)
427 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
428
429 insn[len - 1] = BPF_EXIT_INSN();
430
431 self->u.ptr.insns = insn;
432 self->u.ptr.len = len;
433
434 return 0;
435}
436
437static struct bpf_test tests[] = {
438 {
439 "TAX",
440 .u.insns = {
441 BPF_STMT(BPF_LD | BPF_IMM, 1),
442 BPF_STMT(BPF_MISC | BPF_TAX, 0),
443 BPF_STMT(BPF_LD | BPF_IMM, 2),
444 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
445 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
446 BPF_STMT(BPF_MISC | BPF_TAX, 0),
447 BPF_STMT(BPF_LD | BPF_LEN, 0),
448 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
449 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
450 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
451 BPF_STMT(BPF_RET | BPF_A, 0)
452 },
453 CLASSIC,
454 { 10, 20, 30, 40, 50 },
455 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
456 },
457 {
458 "TXA",
459 .u.insns = {
460 BPF_STMT(BPF_LDX | BPF_LEN, 0),
461 BPF_STMT(BPF_MISC | BPF_TXA, 0),
462 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
463 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
464 },
465 CLASSIC,
466 { 10, 20, 30, 40, 50 },
467 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
468 },
469 {
470 "ADD_SUB_MUL_K",
471 .u.insns = {
472 BPF_STMT(BPF_LD | BPF_IMM, 1),
473 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
474 BPF_STMT(BPF_LDX | BPF_IMM, 3),
475 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
476 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
477 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
478 BPF_STMT(BPF_RET | BPF_A, 0)
479 },
480 CLASSIC | FLAG_NO_DATA,
481 { },
482 { { 0, 0xfffffffd } }
483 },
484 {
485 "DIV_MOD_KX",
486 .u.insns = {
487 BPF_STMT(BPF_LD | BPF_IMM, 8),
488 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
489 BPF_STMT(BPF_MISC | BPF_TAX, 0),
490 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
491 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
492 BPF_STMT(BPF_MISC | BPF_TAX, 0),
493 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
494 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
495 BPF_STMT(BPF_MISC | BPF_TAX, 0),
496 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
497 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
498 BPF_STMT(BPF_MISC | BPF_TAX, 0),
499 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
500 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
501 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
502 BPF_STMT(BPF_RET | BPF_A, 0)
503 },
504 CLASSIC | FLAG_NO_DATA,
505 { },
506 { { 0, 0x20000000 } }
507 },
508 {
509 "AND_OR_LSH_K",
510 .u.insns = {
511 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
512 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
513 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
514 BPF_STMT(BPF_MISC | BPF_TAX, 0),
515 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
516 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
517 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
518 BPF_STMT(BPF_RET | BPF_A, 0)
519 },
520 CLASSIC | FLAG_NO_DATA,
521 { },
522 { { 0, 0x800000ff }, { 1, 0x800000ff } },
523 },
524 {
525 "LD_IMM_0",
526 .u.insns = {
527 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
528 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
529 BPF_STMT(BPF_RET | BPF_K, 0),
530 BPF_STMT(BPF_RET | BPF_K, 1),
531 },
532 CLASSIC,
533 { },
534 { { 1, 1 } },
535 },
536 {
537 "LD_IND",
538 .u.insns = {
539 BPF_STMT(BPF_LDX | BPF_LEN, 0),
540 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
541 BPF_STMT(BPF_RET | BPF_K, 1)
542 },
543 CLASSIC,
544 { },
545 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
546 },
547 {
548 "LD_ABS",
549 .u.insns = {
550 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
551 BPF_STMT(BPF_RET | BPF_K, 1)
552 },
553 CLASSIC,
554 { },
555 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
556 },
557 {
558 "LD_ABS_LL",
559 .u.insns = {
560 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
561 BPF_STMT(BPF_MISC | BPF_TAX, 0),
562 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
563 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
564 BPF_STMT(BPF_RET | BPF_A, 0)
565 },
566 CLASSIC,
567 { 1, 2, 3 },
568 { { 1, 0 }, { 2, 3 } },
569 },
570 {
571 "LD_IND_LL",
572 .u.insns = {
573 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
574 BPF_STMT(BPF_LDX | BPF_LEN, 0),
575 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
576 BPF_STMT(BPF_MISC | BPF_TAX, 0),
577 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
578 BPF_STMT(BPF_RET | BPF_A, 0)
579 },
580 CLASSIC,
581 { 1, 2, 3, 0xff },
582 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
583 },
584 {
585 "LD_ABS_NET",
586 .u.insns = {
587 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
590 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
591 BPF_STMT(BPF_RET | BPF_A, 0)
592 },
593 CLASSIC,
594 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
595 { { 15, 0 }, { 16, 3 } },
596 },
597 {
598 "LD_IND_NET",
599 .u.insns = {
600 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
603 BPF_STMT(BPF_MISC | BPF_TAX, 0),
604 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
605 BPF_STMT(BPF_RET | BPF_A, 0)
606 },
607 CLASSIC,
608 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
609 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
610 },
611 {
612 "LD_PKTTYPE",
613 .u.insns = {
614 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
615 SKF_AD_OFF + SKF_AD_PKTTYPE),
616 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
617 BPF_STMT(BPF_RET | BPF_K, 1),
618 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
619 SKF_AD_OFF + SKF_AD_PKTTYPE),
620 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
621 BPF_STMT(BPF_RET | BPF_K, 1),
622 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
623 SKF_AD_OFF + SKF_AD_PKTTYPE),
624 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
625 BPF_STMT(BPF_RET | BPF_K, 1),
626 BPF_STMT(BPF_RET | BPF_A, 0)
627 },
628 CLASSIC,
629 { },
630 { { 1, 3 }, { 10, 3 } },
631 },
632 {
633 "LD_MARK",
634 .u.insns = {
635 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
636 SKF_AD_OFF + SKF_AD_MARK),
637 BPF_STMT(BPF_RET | BPF_A, 0)
638 },
639 CLASSIC,
640 { },
641 { { 1, SKB_MARK}, { 10, SKB_MARK} },
642 },
643 {
644 "LD_RXHASH",
645 .u.insns = {
646 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
647 SKF_AD_OFF + SKF_AD_RXHASH),
648 BPF_STMT(BPF_RET | BPF_A, 0)
649 },
650 CLASSIC,
651 { },
652 { { 1, SKB_HASH}, { 10, SKB_HASH} },
653 },
654 {
655 "LD_QUEUE",
656 .u.insns = {
657 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
658 SKF_AD_OFF + SKF_AD_QUEUE),
659 BPF_STMT(BPF_RET | BPF_A, 0)
660 },
661 CLASSIC,
662 { },
663 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
664 },
665 {
666 "LD_PROTOCOL",
667 .u.insns = {
668 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
669 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
670 BPF_STMT(BPF_RET | BPF_K, 0),
671 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
672 SKF_AD_OFF + SKF_AD_PROTOCOL),
673 BPF_STMT(BPF_MISC | BPF_TAX, 0),
674 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
675 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
676 BPF_STMT(BPF_RET | BPF_K, 0),
677 BPF_STMT(BPF_MISC | BPF_TXA, 0),
678 BPF_STMT(BPF_RET | BPF_A, 0)
679 },
680 CLASSIC,
681 { 10, 20, 30 },
682 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
683 },
684 {
685 "LD_VLAN_TAG",
686 .u.insns = {
687 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
688 SKF_AD_OFF + SKF_AD_VLAN_TAG),
689 BPF_STMT(BPF_RET | BPF_A, 0)
690 },
691 CLASSIC,
692 { },
693 {
694 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
695 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
696 },
697 },
698 {
699 "LD_VLAN_TAG_PRESENT",
700 .u.insns = {
701 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
702 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
703 BPF_STMT(BPF_RET | BPF_A, 0)
704 },
705 CLASSIC,
706 { },
707 {
708 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
709 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
710 },
711 },
712 {
713 "LD_IFINDEX",
714 .u.insns = {
715 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
716 SKF_AD_OFF + SKF_AD_IFINDEX),
717 BPF_STMT(BPF_RET | BPF_A, 0)
718 },
719 CLASSIC,
720 { },
721 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
722 },
723 {
724 "LD_HATYPE",
725 .u.insns = {
726 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
727 SKF_AD_OFF + SKF_AD_HATYPE),
728 BPF_STMT(BPF_RET | BPF_A, 0)
729 },
730 CLASSIC,
731 { },
732 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
733 },
734 {
735 "LD_CPU",
736 .u.insns = {
737 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
738 SKF_AD_OFF + SKF_AD_CPU),
739 BPF_STMT(BPF_MISC | BPF_TAX, 0),
740 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
741 SKF_AD_OFF + SKF_AD_CPU),
742 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
743 BPF_STMT(BPF_RET | BPF_A, 0)
744 },
745 CLASSIC,
746 { },
747 { { 1, 0 }, { 10, 0 } },
748 },
749 {
750 "LD_NLATTR",
751 .u.insns = {
752 BPF_STMT(BPF_LDX | BPF_IMM, 2),
753 BPF_STMT(BPF_MISC | BPF_TXA, 0),
754 BPF_STMT(BPF_LDX | BPF_IMM, 3),
755 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
756 SKF_AD_OFF + SKF_AD_NLATTR),
757 BPF_STMT(BPF_RET | BPF_A, 0)
758 },
759 CLASSIC,
760#ifdef __BIG_ENDIAN
761 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
762#else
763 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
764#endif
765 { { 4, 0 }, { 20, 6 } },
766 },
767 {
768 "LD_NLATTR_NEST",
769 .u.insns = {
770 BPF_STMT(BPF_LD | BPF_IMM, 2),
771 BPF_STMT(BPF_LDX | BPF_IMM, 3),
772 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
773 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
774 BPF_STMT(BPF_LD | BPF_IMM, 2),
775 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
776 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
777 BPF_STMT(BPF_LD | BPF_IMM, 2),
778 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
779 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
780 BPF_STMT(BPF_LD | BPF_IMM, 2),
781 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
782 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
783 BPF_STMT(BPF_LD | BPF_IMM, 2),
784 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
785 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
786 BPF_STMT(BPF_LD | BPF_IMM, 2),
787 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
788 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
789 BPF_STMT(BPF_LD | BPF_IMM, 2),
790 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
791 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
792 BPF_STMT(BPF_LD | BPF_IMM, 2),
793 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
794 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
795 BPF_STMT(BPF_RET | BPF_A, 0)
796 },
797 CLASSIC,
798#ifdef __BIG_ENDIAN
799 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
800#else
801 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
802#endif
803 { { 4, 0 }, { 20, 10 } },
804 },
805 {
806 "LD_PAYLOAD_OFF",
807 .u.insns = {
808 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
809 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
810 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
811 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
812 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
813 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
814 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
815 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
816 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
817 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
818 BPF_STMT(BPF_RET | BPF_A, 0)
819 },
820 CLASSIC,
821 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
822 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
823 * id 9737, seq 1, length 64
824 */
825 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 0x08, 0x00,
828 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
829 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
830 { { 30, 0 }, { 100, 42 } },
831 },
832 {
833 "LD_ANC_XOR",
834 .u.insns = {
835 BPF_STMT(BPF_LD | BPF_IMM, 10),
836 BPF_STMT(BPF_LDX | BPF_IMM, 300),
837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
839 BPF_STMT(BPF_RET | BPF_A, 0)
840 },
841 CLASSIC,
842 { },
843 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
844 },
845 {
846 "SPILL_FILL",
847 .u.insns = {
848 BPF_STMT(BPF_LDX | BPF_LEN, 0),
849 BPF_STMT(BPF_LD | BPF_IMM, 2),
850 BPF_STMT(BPF_ALU | BPF_RSH, 1),
851 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
852 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
853 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
854 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
855 BPF_STMT(BPF_STX, 15), /* M3 = len */
856 BPF_STMT(BPF_LDX | BPF_MEM, 1),
857 BPF_STMT(BPF_LD | BPF_MEM, 2),
858 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
859 BPF_STMT(BPF_LDX | BPF_MEM, 15),
860 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
861 BPF_STMT(BPF_RET | BPF_A, 0)
862 },
863 CLASSIC,
864 { },
865 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
866 },
867 {
868 "JEQ",
869 .u.insns = {
870 BPF_STMT(BPF_LDX | BPF_LEN, 0),
871 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
872 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
873 BPF_STMT(BPF_RET | BPF_K, 1),
874 BPF_STMT(BPF_RET | BPF_K, MAX_K)
875 },
876 CLASSIC,
877 { 3, 3, 3, 3, 3 },
878 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
879 },
880 {
881 "JGT",
882 .u.insns = {
883 BPF_STMT(BPF_LDX | BPF_LEN, 0),
884 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
885 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
886 BPF_STMT(BPF_RET | BPF_K, 1),
887 BPF_STMT(BPF_RET | BPF_K, MAX_K)
888 },
889 CLASSIC,
890 { 4, 4, 4, 3, 3 },
891 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
892 },
893 {
894 "JGE",
895 .u.insns = {
896 BPF_STMT(BPF_LDX | BPF_LEN, 0),
897 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
898 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
899 BPF_STMT(BPF_RET | BPF_K, 10),
900 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
901 BPF_STMT(BPF_RET | BPF_K, 20),
902 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
903 BPF_STMT(BPF_RET | BPF_K, 30),
904 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
905 BPF_STMT(BPF_RET | BPF_K, 40),
906 BPF_STMT(BPF_RET | BPF_K, MAX_K)
907 },
908 CLASSIC,
909 { 1, 2, 3, 4, 5 },
910 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
911 },
912 {
913 "JSET",
914 .u.insns = {
915 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
916 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
917 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
918 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
919 BPF_STMT(BPF_LDX | BPF_LEN, 0),
920 BPF_STMT(BPF_MISC | BPF_TXA, 0),
921 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
922 BPF_STMT(BPF_MISC | BPF_TAX, 0),
923 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
924 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
925 BPF_STMT(BPF_RET | BPF_K, 10),
926 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
927 BPF_STMT(BPF_RET | BPF_K, 20),
928 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
929 BPF_STMT(BPF_RET | BPF_K, 30),
930 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
931 BPF_STMT(BPF_RET | BPF_K, 30),
932 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
933 BPF_STMT(BPF_RET | BPF_K, 30),
934 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
935 BPF_STMT(BPF_RET | BPF_K, 30),
936 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
937 BPF_STMT(BPF_RET | BPF_K, 30),
938 BPF_STMT(BPF_RET | BPF_K, MAX_K)
939 },
940 CLASSIC,
941 { 0, 0xAA, 0x55, 1 },
942 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
943 },
944 {
945 "tcpdump port 22",
946 .u.insns = {
947 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
948 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
949 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
950 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
951 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
952 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
953 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
954 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
955 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
956 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
957 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
958 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
959 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
960 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
961 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
962 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
963 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
964 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
965 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
966 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
967 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
968 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
969 BPF_STMT(BPF_RET | BPF_K, 0xffff),
970 BPF_STMT(BPF_RET | BPF_K, 0),
971 },
972 CLASSIC,
973 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
974 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
975 * seq 1305692979:1305693027, ack 3650467037, win 65535,
976 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
977 */
978 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
979 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
980 0x08, 0x00,
981 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
982 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
983 0x0a, 0x01, 0x01, 0x95, /* ip src */
984 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
985 0xc2, 0x24,
986 0x00, 0x16 /* dst port */ },
987 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
988 },
989 {
990 "tcpdump complex",
991 .u.insns = {
992 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
993 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
994 * (len > 115 or len < 30000000000)' -d
995 */
996 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
997 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
998 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
999 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1000 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1001 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1002 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1003 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1004 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1005 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1006 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1007 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1008 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1009 BPF_STMT(BPF_ST, 1),
1010 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1011 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1012 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1013 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1014 BPF_STMT(BPF_LD | BPF_MEM, 1),
1015 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1016 BPF_STMT(BPF_ST, 5),
1017 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1018 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1019 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1020 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1021 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1022 BPF_STMT(BPF_LD | BPF_MEM, 5),
1023 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1024 BPF_STMT(BPF_LD | BPF_LEN, 0),
1025 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1026 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1027 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1028 BPF_STMT(BPF_RET | BPF_K, 0),
1029 },
1030 CLASSIC,
1031 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1032 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1033 0x08, 0x00,
1034 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1035 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1036 0x0a, 0x01, 0x01, 0x95, /* ip src */
1037 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1038 0xc2, 0x24,
1039 0x00, 0x16 /* dst port */ },
1040 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1041 },
1042 {
1043 "RET_A",
1044 .u.insns = {
1045 /* check that unitialized X and A contain zeros */
1046 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1047 BPF_STMT(BPF_RET | BPF_A, 0)
1048 },
1049 CLASSIC,
1050 { },
1051 { {1, 0}, {2, 0} },
1052 },
1053 {
1054 "INT: ADD trivial",
1055 .u.insns_int = {
1056 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1057 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1058 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1059 BPF_ALU64_REG(BPF_SUB, R1, R2),
1060 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1061 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1062 BPF_ALU64_REG(BPF_MOV, R0, R1),
1063 BPF_EXIT_INSN(),
1064 },
1065 INTERNAL,
1066 { },
1067 { { 0, 0xfffffffd } }
1068 },
1069 {
1070 "INT: MUL_X",
1071 .u.insns_int = {
1072 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1073 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1074 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1075 BPF_ALU64_REG(BPF_MUL, R1, R2),
1076 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1077 BPF_EXIT_INSN(),
1078 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1079 BPF_EXIT_INSN(),
1080 },
1081 INTERNAL,
1082 { },
1083 { { 0, 1 } }
1084 },
1085 {
1086 "INT: MUL_X2",
1087 .u.insns_int = {
1088 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1089 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1090 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1091 BPF_ALU64_REG(BPF_MUL, R1, R2),
1092 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1093 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1094 BPF_EXIT_INSN(),
1095 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1096 BPF_EXIT_INSN(),
1097 },
1098 INTERNAL,
1099 { },
1100 { { 0, 1 } }
1101 },
1102 {
1103 "INT: MUL32_X",
1104 .u.insns_int = {
1105 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1106 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1107 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1108 BPF_ALU32_REG(BPF_MUL, R1, R2),
1109 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1110 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1111 BPF_EXIT_INSN(),
1112 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1113 BPF_EXIT_INSN(),
1114 },
1115 INTERNAL,
1116 { },
1117 { { 0, 1 } }
1118 },
1119 {
1120 /* Have to test all register combinations, since
1121 * JITing of different registers will produce
1122 * different asm code.
1123 */
1124 "INT: ADD 64-bit",
1125 .u.insns_int = {
1126 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1127 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1128 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1129 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1130 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1131 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1132 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1133 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1134 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1135 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1136 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1137 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1138 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1139 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1140 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1141 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1142 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1143 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1144 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1145 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1146 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1147 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1148 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1149 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1150 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1151 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1152 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1153 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1154 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1155 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1156 BPF_ALU64_REG(BPF_ADD, R0, R0),
1157 BPF_ALU64_REG(BPF_ADD, R0, R1),
1158 BPF_ALU64_REG(BPF_ADD, R0, R2),
1159 BPF_ALU64_REG(BPF_ADD, R0, R3),
1160 BPF_ALU64_REG(BPF_ADD, R0, R4),
1161 BPF_ALU64_REG(BPF_ADD, R0, R5),
1162 BPF_ALU64_REG(BPF_ADD, R0, R6),
1163 BPF_ALU64_REG(BPF_ADD, R0, R7),
1164 BPF_ALU64_REG(BPF_ADD, R0, R8),
1165 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1166 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1167 BPF_EXIT_INSN(),
1168 BPF_ALU64_REG(BPF_ADD, R1, R0),
1169 BPF_ALU64_REG(BPF_ADD, R1, R1),
1170 BPF_ALU64_REG(BPF_ADD, R1, R2),
1171 BPF_ALU64_REG(BPF_ADD, R1, R3),
1172 BPF_ALU64_REG(BPF_ADD, R1, R4),
1173 BPF_ALU64_REG(BPF_ADD, R1, R5),
1174 BPF_ALU64_REG(BPF_ADD, R1, R6),
1175 BPF_ALU64_REG(BPF_ADD, R1, R7),
1176 BPF_ALU64_REG(BPF_ADD, R1, R8),
1177 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1178 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1179 BPF_EXIT_INSN(),
1180 BPF_ALU64_REG(BPF_ADD, R2, R0),
1181 BPF_ALU64_REG(BPF_ADD, R2, R1),
1182 BPF_ALU64_REG(BPF_ADD, R2, R2),
1183 BPF_ALU64_REG(BPF_ADD, R2, R3),
1184 BPF_ALU64_REG(BPF_ADD, R2, R4),
1185 BPF_ALU64_REG(BPF_ADD, R2, R5),
1186 BPF_ALU64_REG(BPF_ADD, R2, R6),
1187 BPF_ALU64_REG(BPF_ADD, R2, R7),
1188 BPF_ALU64_REG(BPF_ADD, R2, R8),
1189 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1190 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1191 BPF_EXIT_INSN(),
1192 BPF_ALU64_REG(BPF_ADD, R3, R0),
1193 BPF_ALU64_REG(BPF_ADD, R3, R1),
1194 BPF_ALU64_REG(BPF_ADD, R3, R2),
1195 BPF_ALU64_REG(BPF_ADD, R3, R3),
1196 BPF_ALU64_REG(BPF_ADD, R3, R4),
1197 BPF_ALU64_REG(BPF_ADD, R3, R5),
1198 BPF_ALU64_REG(BPF_ADD, R3, R6),
1199 BPF_ALU64_REG(BPF_ADD, R3, R7),
1200 BPF_ALU64_REG(BPF_ADD, R3, R8),
1201 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1202 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1203 BPF_EXIT_INSN(),
1204 BPF_ALU64_REG(BPF_ADD, R4, R0),
1205 BPF_ALU64_REG(BPF_ADD, R4, R1),
1206 BPF_ALU64_REG(BPF_ADD, R4, R2),
1207 BPF_ALU64_REG(BPF_ADD, R4, R3),
1208 BPF_ALU64_REG(BPF_ADD, R4, R4),
1209 BPF_ALU64_REG(BPF_ADD, R4, R5),
1210 BPF_ALU64_REG(BPF_ADD, R4, R6),
1211 BPF_ALU64_REG(BPF_ADD, R4, R7),
1212 BPF_ALU64_REG(BPF_ADD, R4, R8),
1213 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1214 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1215 BPF_EXIT_INSN(),
1216 BPF_ALU64_REG(BPF_ADD, R5, R0),
1217 BPF_ALU64_REG(BPF_ADD, R5, R1),
1218 BPF_ALU64_REG(BPF_ADD, R5, R2),
1219 BPF_ALU64_REG(BPF_ADD, R5, R3),
1220 BPF_ALU64_REG(BPF_ADD, R5, R4),
1221 BPF_ALU64_REG(BPF_ADD, R5, R5),
1222 BPF_ALU64_REG(BPF_ADD, R5, R6),
1223 BPF_ALU64_REG(BPF_ADD, R5, R7),
1224 BPF_ALU64_REG(BPF_ADD, R5, R8),
1225 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1226 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1227 BPF_EXIT_INSN(),
1228 BPF_ALU64_REG(BPF_ADD, R6, R0),
1229 BPF_ALU64_REG(BPF_ADD, R6, R1),
1230 BPF_ALU64_REG(BPF_ADD, R6, R2),
1231 BPF_ALU64_REG(BPF_ADD, R6, R3),
1232 BPF_ALU64_REG(BPF_ADD, R6, R4),
1233 BPF_ALU64_REG(BPF_ADD, R6, R5),
1234 BPF_ALU64_REG(BPF_ADD, R6, R6),
1235 BPF_ALU64_REG(BPF_ADD, R6, R7),
1236 BPF_ALU64_REG(BPF_ADD, R6, R8),
1237 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1238 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1239 BPF_EXIT_INSN(),
1240 BPF_ALU64_REG(BPF_ADD, R7, R0),
1241 BPF_ALU64_REG(BPF_ADD, R7, R1),
1242 BPF_ALU64_REG(BPF_ADD, R7, R2),
1243 BPF_ALU64_REG(BPF_ADD, R7, R3),
1244 BPF_ALU64_REG(BPF_ADD, R7, R4),
1245 BPF_ALU64_REG(BPF_ADD, R7, R5),
1246 BPF_ALU64_REG(BPF_ADD, R7, R6),
1247 BPF_ALU64_REG(BPF_ADD, R7, R7),
1248 BPF_ALU64_REG(BPF_ADD, R7, R8),
1249 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1250 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1251 BPF_EXIT_INSN(),
1252 BPF_ALU64_REG(BPF_ADD, R8, R0),
1253 BPF_ALU64_REG(BPF_ADD, R8, R1),
1254 BPF_ALU64_REG(BPF_ADD, R8, R2),
1255 BPF_ALU64_REG(BPF_ADD, R8, R3),
1256 BPF_ALU64_REG(BPF_ADD, R8, R4),
1257 BPF_ALU64_REG(BPF_ADD, R8, R5),
1258 BPF_ALU64_REG(BPF_ADD, R8, R6),
1259 BPF_ALU64_REG(BPF_ADD, R8, R7),
1260 BPF_ALU64_REG(BPF_ADD, R8, R8),
1261 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1262 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1263 BPF_EXIT_INSN(),
1264 BPF_ALU64_REG(BPF_ADD, R9, R0),
1265 BPF_ALU64_REG(BPF_ADD, R9, R1),
1266 BPF_ALU64_REG(BPF_ADD, R9, R2),
1267 BPF_ALU64_REG(BPF_ADD, R9, R3),
1268 BPF_ALU64_REG(BPF_ADD, R9, R4),
1269 BPF_ALU64_REG(BPF_ADD, R9, R5),
1270 BPF_ALU64_REG(BPF_ADD, R9, R6),
1271 BPF_ALU64_REG(BPF_ADD, R9, R7),
1272 BPF_ALU64_REG(BPF_ADD, R9, R8),
1273 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1274 BPF_ALU64_REG(BPF_MOV, R0, R9),
1275 BPF_EXIT_INSN(),
1276 },
1277 INTERNAL,
1278 { },
1279 { { 0, 2957380 } }
1280 },
1281 {
1282 "INT: ADD 32-bit",
1283 .u.insns_int = {
1284 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1285 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1286 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1287 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1288 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1289 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1290 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1291 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1292 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1293 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1294 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1295 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1296 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1297 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1298 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1299 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1300 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1301 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1302 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1303 BPF_ALU32_REG(BPF_ADD, R0, R1),
1304 BPF_ALU32_REG(BPF_ADD, R0, R2),
1305 BPF_ALU32_REG(BPF_ADD, R0, R3),
1306 BPF_ALU32_REG(BPF_ADD, R0, R4),
1307 BPF_ALU32_REG(BPF_ADD, R0, R5),
1308 BPF_ALU32_REG(BPF_ADD, R0, R6),
1309 BPF_ALU32_REG(BPF_ADD, R0, R7),
1310 BPF_ALU32_REG(BPF_ADD, R0, R8),
1311 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1312 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1313 BPF_EXIT_INSN(),
1314 BPF_ALU32_REG(BPF_ADD, R1, R0),
1315 BPF_ALU32_REG(BPF_ADD, R1, R1),
1316 BPF_ALU32_REG(BPF_ADD, R1, R2),
1317 BPF_ALU32_REG(BPF_ADD, R1, R3),
1318 BPF_ALU32_REG(BPF_ADD, R1, R4),
1319 BPF_ALU32_REG(BPF_ADD, R1, R5),
1320 BPF_ALU32_REG(BPF_ADD, R1, R6),
1321 BPF_ALU32_REG(BPF_ADD, R1, R7),
1322 BPF_ALU32_REG(BPF_ADD, R1, R8),
1323 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1324 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1325 BPF_EXIT_INSN(),
1326 BPF_ALU32_REG(BPF_ADD, R2, R0),
1327 BPF_ALU32_REG(BPF_ADD, R2, R1),
1328 BPF_ALU32_REG(BPF_ADD, R2, R2),
1329 BPF_ALU32_REG(BPF_ADD, R2, R3),
1330 BPF_ALU32_REG(BPF_ADD, R2, R4),
1331 BPF_ALU32_REG(BPF_ADD, R2, R5),
1332 BPF_ALU32_REG(BPF_ADD, R2, R6),
1333 BPF_ALU32_REG(BPF_ADD, R2, R7),
1334 BPF_ALU32_REG(BPF_ADD, R2, R8),
1335 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1336 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1337 BPF_EXIT_INSN(),
1338 BPF_ALU32_REG(BPF_ADD, R3, R0),
1339 BPF_ALU32_REG(BPF_ADD, R3, R1),
1340 BPF_ALU32_REG(BPF_ADD, R3, R2),
1341 BPF_ALU32_REG(BPF_ADD, R3, R3),
1342 BPF_ALU32_REG(BPF_ADD, R3, R4),
1343 BPF_ALU32_REG(BPF_ADD, R3, R5),
1344 BPF_ALU32_REG(BPF_ADD, R3, R6),
1345 BPF_ALU32_REG(BPF_ADD, R3, R7),
1346 BPF_ALU32_REG(BPF_ADD, R3, R8),
1347 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1348 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1349 BPF_EXIT_INSN(),
1350 BPF_ALU32_REG(BPF_ADD, R4, R0),
1351 BPF_ALU32_REG(BPF_ADD, R4, R1),
1352 BPF_ALU32_REG(BPF_ADD, R4, R2),
1353 BPF_ALU32_REG(BPF_ADD, R4, R3),
1354 BPF_ALU32_REG(BPF_ADD, R4, R4),
1355 BPF_ALU32_REG(BPF_ADD, R4, R5),
1356 BPF_ALU32_REG(BPF_ADD, R4, R6),
1357 BPF_ALU32_REG(BPF_ADD, R4, R7),
1358 BPF_ALU32_REG(BPF_ADD, R4, R8),
1359 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1360 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1361 BPF_EXIT_INSN(),
1362 BPF_ALU32_REG(BPF_ADD, R5, R0),
1363 BPF_ALU32_REG(BPF_ADD, R5, R1),
1364 BPF_ALU32_REG(BPF_ADD, R5, R2),
1365 BPF_ALU32_REG(BPF_ADD, R5, R3),
1366 BPF_ALU32_REG(BPF_ADD, R5, R4),
1367 BPF_ALU32_REG(BPF_ADD, R5, R5),
1368 BPF_ALU32_REG(BPF_ADD, R5, R6),
1369 BPF_ALU32_REG(BPF_ADD, R5, R7),
1370 BPF_ALU32_REG(BPF_ADD, R5, R8),
1371 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1372 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1373 BPF_EXIT_INSN(),
1374 BPF_ALU32_REG(BPF_ADD, R6, R0),
1375 BPF_ALU32_REG(BPF_ADD, R6, R1),
1376 BPF_ALU32_REG(BPF_ADD, R6, R2),
1377 BPF_ALU32_REG(BPF_ADD, R6, R3),
1378 BPF_ALU32_REG(BPF_ADD, R6, R4),
1379 BPF_ALU32_REG(BPF_ADD, R6, R5),
1380 BPF_ALU32_REG(BPF_ADD, R6, R6),
1381 BPF_ALU32_REG(BPF_ADD, R6, R7),
1382 BPF_ALU32_REG(BPF_ADD, R6, R8),
1383 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1384 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1385 BPF_EXIT_INSN(),
1386 BPF_ALU32_REG(BPF_ADD, R7, R0),
1387 BPF_ALU32_REG(BPF_ADD, R7, R1),
1388 BPF_ALU32_REG(BPF_ADD, R7, R2),
1389 BPF_ALU32_REG(BPF_ADD, R7, R3),
1390 BPF_ALU32_REG(BPF_ADD, R7, R4),
1391 BPF_ALU32_REG(BPF_ADD, R7, R5),
1392 BPF_ALU32_REG(BPF_ADD, R7, R6),
1393 BPF_ALU32_REG(BPF_ADD, R7, R7),
1394 BPF_ALU32_REG(BPF_ADD, R7, R8),
1395 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1396 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1397 BPF_EXIT_INSN(),
1398 BPF_ALU32_REG(BPF_ADD, R8, R0),
1399 BPF_ALU32_REG(BPF_ADD, R8, R1),
1400 BPF_ALU32_REG(BPF_ADD, R8, R2),
1401 BPF_ALU32_REG(BPF_ADD, R8, R3),
1402 BPF_ALU32_REG(BPF_ADD, R8, R4),
1403 BPF_ALU32_REG(BPF_ADD, R8, R5),
1404 BPF_ALU32_REG(BPF_ADD, R8, R6),
1405 BPF_ALU32_REG(BPF_ADD, R8, R7),
1406 BPF_ALU32_REG(BPF_ADD, R8, R8),
1407 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1408 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1409 BPF_EXIT_INSN(),
1410 BPF_ALU32_REG(BPF_ADD, R9, R0),
1411 BPF_ALU32_REG(BPF_ADD, R9, R1),
1412 BPF_ALU32_REG(BPF_ADD, R9, R2),
1413 BPF_ALU32_REG(BPF_ADD, R9, R3),
1414 BPF_ALU32_REG(BPF_ADD, R9, R4),
1415 BPF_ALU32_REG(BPF_ADD, R9, R5),
1416 BPF_ALU32_REG(BPF_ADD, R9, R6),
1417 BPF_ALU32_REG(BPF_ADD, R9, R7),
1418 BPF_ALU32_REG(BPF_ADD, R9, R8),
1419 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1420 BPF_ALU32_REG(BPF_MOV, R0, R9),
1421 BPF_EXIT_INSN(),
1422 },
1423 INTERNAL,
1424 { },
1425 { { 0, 2957380 } }
1426 },
1427 { /* Mainly checking JIT here. */
1428 "INT: SUB",
1429 .u.insns_int = {
1430 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1431 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1432 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1433 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1434 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1435 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1436 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1437 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1438 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1439 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1440 BPF_ALU64_REG(BPF_SUB, R0, R0),
1441 BPF_ALU64_REG(BPF_SUB, R0, R1),
1442 BPF_ALU64_REG(BPF_SUB, R0, R2),
1443 BPF_ALU64_REG(BPF_SUB, R0, R3),
1444 BPF_ALU64_REG(BPF_SUB, R0, R4),
1445 BPF_ALU64_REG(BPF_SUB, R0, R5),
1446 BPF_ALU64_REG(BPF_SUB, R0, R6),
1447 BPF_ALU64_REG(BPF_SUB, R0, R7),
1448 BPF_ALU64_REG(BPF_SUB, R0, R8),
1449 BPF_ALU64_REG(BPF_SUB, R0, R9),
1450 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1451 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1452 BPF_EXIT_INSN(),
1453 BPF_ALU64_REG(BPF_SUB, R1, R0),
1454 BPF_ALU64_REG(BPF_SUB, R1, R2),
1455 BPF_ALU64_REG(BPF_SUB, R1, R3),
1456 BPF_ALU64_REG(BPF_SUB, R1, R4),
1457 BPF_ALU64_REG(BPF_SUB, R1, R5),
1458 BPF_ALU64_REG(BPF_SUB, R1, R6),
1459 BPF_ALU64_REG(BPF_SUB, R1, R7),
1460 BPF_ALU64_REG(BPF_SUB, R1, R8),
1461 BPF_ALU64_REG(BPF_SUB, R1, R9),
1462 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1463 BPF_ALU64_REG(BPF_SUB, R2, R0),
1464 BPF_ALU64_REG(BPF_SUB, R2, R1),
1465 BPF_ALU64_REG(BPF_SUB, R2, R3),
1466 BPF_ALU64_REG(BPF_SUB, R2, R4),
1467 BPF_ALU64_REG(BPF_SUB, R2, R5),
1468 BPF_ALU64_REG(BPF_SUB, R2, R6),
1469 BPF_ALU64_REG(BPF_SUB, R2, R7),
1470 BPF_ALU64_REG(BPF_SUB, R2, R8),
1471 BPF_ALU64_REG(BPF_SUB, R2, R9),
1472 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1473 BPF_ALU64_REG(BPF_SUB, R3, R0),
1474 BPF_ALU64_REG(BPF_SUB, R3, R1),
1475 BPF_ALU64_REG(BPF_SUB, R3, R2),
1476 BPF_ALU64_REG(BPF_SUB, R3, R4),
1477 BPF_ALU64_REG(BPF_SUB, R3, R5),
1478 BPF_ALU64_REG(BPF_SUB, R3, R6),
1479 BPF_ALU64_REG(BPF_SUB, R3, R7),
1480 BPF_ALU64_REG(BPF_SUB, R3, R8),
1481 BPF_ALU64_REG(BPF_SUB, R3, R9),
1482 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1483 BPF_ALU64_REG(BPF_SUB, R4, R0),
1484 BPF_ALU64_REG(BPF_SUB, R4, R1),
1485 BPF_ALU64_REG(BPF_SUB, R4, R2),
1486 BPF_ALU64_REG(BPF_SUB, R4, R3),
1487 BPF_ALU64_REG(BPF_SUB, R4, R5),
1488 BPF_ALU64_REG(BPF_SUB, R4, R6),
1489 BPF_ALU64_REG(BPF_SUB, R4, R7),
1490 BPF_ALU64_REG(BPF_SUB, R4, R8),
1491 BPF_ALU64_REG(BPF_SUB, R4, R9),
1492 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1493 BPF_ALU64_REG(BPF_SUB, R5, R0),
1494 BPF_ALU64_REG(BPF_SUB, R5, R1),
1495 BPF_ALU64_REG(BPF_SUB, R5, R2),
1496 BPF_ALU64_REG(BPF_SUB, R5, R3),
1497 BPF_ALU64_REG(BPF_SUB, R5, R4),
1498 BPF_ALU64_REG(BPF_SUB, R5, R6),
1499 BPF_ALU64_REG(BPF_SUB, R5, R7),
1500 BPF_ALU64_REG(BPF_SUB, R5, R8),
1501 BPF_ALU64_REG(BPF_SUB, R5, R9),
1502 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1503 BPF_ALU64_REG(BPF_SUB, R6, R0),
1504 BPF_ALU64_REG(BPF_SUB, R6, R1),
1505 BPF_ALU64_REG(BPF_SUB, R6, R2),
1506 BPF_ALU64_REG(BPF_SUB, R6, R3),
1507 BPF_ALU64_REG(BPF_SUB, R6, R4),
1508 BPF_ALU64_REG(BPF_SUB, R6, R5),
1509 BPF_ALU64_REG(BPF_SUB, R6, R7),
1510 BPF_ALU64_REG(BPF_SUB, R6, R8),
1511 BPF_ALU64_REG(BPF_SUB, R6, R9),
1512 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1513 BPF_ALU64_REG(BPF_SUB, R7, R0),
1514 BPF_ALU64_REG(BPF_SUB, R7, R1),
1515 BPF_ALU64_REG(BPF_SUB, R7, R2),
1516 BPF_ALU64_REG(BPF_SUB, R7, R3),
1517 BPF_ALU64_REG(BPF_SUB, R7, R4),
1518 BPF_ALU64_REG(BPF_SUB, R7, R5),
1519 BPF_ALU64_REG(BPF_SUB, R7, R6),
1520 BPF_ALU64_REG(BPF_SUB, R7, R8),
1521 BPF_ALU64_REG(BPF_SUB, R7, R9),
1522 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1523 BPF_ALU64_REG(BPF_SUB, R8, R0),
1524 BPF_ALU64_REG(BPF_SUB, R8, R1),
1525 BPF_ALU64_REG(BPF_SUB, R8, R2),
1526 BPF_ALU64_REG(BPF_SUB, R8, R3),
1527 BPF_ALU64_REG(BPF_SUB, R8, R4),
1528 BPF_ALU64_REG(BPF_SUB, R8, R5),
1529 BPF_ALU64_REG(BPF_SUB, R8, R6),
1530 BPF_ALU64_REG(BPF_SUB, R8, R7),
1531 BPF_ALU64_REG(BPF_SUB, R8, R9),
1532 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1533 BPF_ALU64_REG(BPF_SUB, R9, R0),
1534 BPF_ALU64_REG(BPF_SUB, R9, R1),
1535 BPF_ALU64_REG(BPF_SUB, R9, R2),
1536 BPF_ALU64_REG(BPF_SUB, R9, R3),
1537 BPF_ALU64_REG(BPF_SUB, R9, R4),
1538 BPF_ALU64_REG(BPF_SUB, R9, R5),
1539 BPF_ALU64_REG(BPF_SUB, R9, R6),
1540 BPF_ALU64_REG(BPF_SUB, R9, R7),
1541 BPF_ALU64_REG(BPF_SUB, R9, R8),
1542 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1543 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1544 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1545 BPF_ALU64_REG(BPF_SUB, R0, R1),
1546 BPF_ALU64_REG(BPF_SUB, R0, R2),
1547 BPF_ALU64_REG(BPF_SUB, R0, R3),
1548 BPF_ALU64_REG(BPF_SUB, R0, R4),
1549 BPF_ALU64_REG(BPF_SUB, R0, R5),
1550 BPF_ALU64_REG(BPF_SUB, R0, R6),
1551 BPF_ALU64_REG(BPF_SUB, R0, R7),
1552 BPF_ALU64_REG(BPF_SUB, R0, R8),
1553 BPF_ALU64_REG(BPF_SUB, R0, R9),
1554 BPF_EXIT_INSN(),
1555 },
1556 INTERNAL,
1557 { },
1558 { { 0, 11 } }
1559 },
1560 { /* Mainly checking JIT here. */
1561 "INT: XOR",
1562 .u.insns_int = {
1563 BPF_ALU64_REG(BPF_SUB, R0, R0),
1564 BPF_ALU64_REG(BPF_XOR, R1, R1),
1565 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1566 BPF_EXIT_INSN(),
1567 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1568 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1569 BPF_ALU64_REG(BPF_SUB, R1, R1),
1570 BPF_ALU64_REG(BPF_XOR, R2, R2),
1571 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1572 BPF_EXIT_INSN(),
1573 BPF_ALU64_REG(BPF_SUB, R2, R2),
1574 BPF_ALU64_REG(BPF_XOR, R3, R3),
1575 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1576 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1577 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1578 BPF_EXIT_INSN(),
1579 BPF_ALU64_REG(BPF_SUB, R3, R3),
1580 BPF_ALU64_REG(BPF_XOR, R4, R4),
1581 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1582 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1583 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1584 BPF_EXIT_INSN(),
1585 BPF_ALU64_REG(BPF_SUB, R4, R4),
1586 BPF_ALU64_REG(BPF_XOR, R5, R5),
1587 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1588 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1589 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1590 BPF_EXIT_INSN(),
1591 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1592 BPF_ALU64_REG(BPF_SUB, R5, R5),
1593 BPF_ALU64_REG(BPF_XOR, R6, R6),
1594 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1595 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1596 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1597 BPF_EXIT_INSN(),
1598 BPF_ALU64_REG(BPF_SUB, R6, R6),
1599 BPF_ALU64_REG(BPF_XOR, R7, R7),
1600 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1601 BPF_EXIT_INSN(),
1602 BPF_ALU64_REG(BPF_SUB, R7, R7),
1603 BPF_ALU64_REG(BPF_XOR, R8, R8),
1604 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1605 BPF_EXIT_INSN(),
1606 BPF_ALU64_REG(BPF_SUB, R8, R8),
1607 BPF_ALU64_REG(BPF_XOR, R9, R9),
1608 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1609 BPF_EXIT_INSN(),
1610 BPF_ALU64_REG(BPF_SUB, R9, R9),
1611 BPF_ALU64_REG(BPF_XOR, R0, R0),
1612 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1613 BPF_EXIT_INSN(),
1614 BPF_ALU64_REG(BPF_SUB, R1, R1),
1615 BPF_ALU64_REG(BPF_XOR, R0, R0),
1616 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1617 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1618 BPF_EXIT_INSN(),
1619 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1620 BPF_EXIT_INSN(),
1621 },
1622 INTERNAL,
1623 { },
1624 { { 0, 1 } }
1625 },
1626 { /* Mainly checking JIT here. */
1627 "INT: MUL",
1628 .u.insns_int = {
1629 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1630 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1631 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1632 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1633 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1634 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1635 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1636 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1637 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1638 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1639 BPF_ALU64_REG(BPF_MUL, R0, R0),
1640 BPF_ALU64_REG(BPF_MUL, R0, R1),
1641 BPF_ALU64_REG(BPF_MUL, R0, R2),
1642 BPF_ALU64_REG(BPF_MUL, R0, R3),
1643 BPF_ALU64_REG(BPF_MUL, R0, R4),
1644 BPF_ALU64_REG(BPF_MUL, R0, R5),
1645 BPF_ALU64_REG(BPF_MUL, R0, R6),
1646 BPF_ALU64_REG(BPF_MUL, R0, R7),
1647 BPF_ALU64_REG(BPF_MUL, R0, R8),
1648 BPF_ALU64_REG(BPF_MUL, R0, R9),
1649 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1650 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1651 BPF_EXIT_INSN(),
1652 BPF_ALU64_REG(BPF_MUL, R1, R0),
1653 BPF_ALU64_REG(BPF_MUL, R1, R2),
1654 BPF_ALU64_REG(BPF_MUL, R1, R3),
1655 BPF_ALU64_REG(BPF_MUL, R1, R4),
1656 BPF_ALU64_REG(BPF_MUL, R1, R5),
1657 BPF_ALU64_REG(BPF_MUL, R1, R6),
1658 BPF_ALU64_REG(BPF_MUL, R1, R7),
1659 BPF_ALU64_REG(BPF_MUL, R1, R8),
1660 BPF_ALU64_REG(BPF_MUL, R1, R9),
1661 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1662 BPF_ALU64_REG(BPF_MOV, R2, R1),
1663 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1664 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1665 BPF_EXIT_INSN(),
1666 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1667 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1668 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1669 BPF_EXIT_INSN(),
1670 BPF_ALU64_REG(BPF_MUL, R2, R0),
1671 BPF_ALU64_REG(BPF_MUL, R2, R1),
1672 BPF_ALU64_REG(BPF_MUL, R2, R3),
1673 BPF_ALU64_REG(BPF_MUL, R2, R4),
1674 BPF_ALU64_REG(BPF_MUL, R2, R5),
1675 BPF_ALU64_REG(BPF_MUL, R2, R6),
1676 BPF_ALU64_REG(BPF_MUL, R2, R7),
1677 BPF_ALU64_REG(BPF_MUL, R2, R8),
1678 BPF_ALU64_REG(BPF_MUL, R2, R9),
1679 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1680 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1681 BPF_ALU64_REG(BPF_MOV, R0, R2),
1682 BPF_EXIT_INSN(),
1683 },
1684 INTERNAL,
1685 { },
1686 { { 0, 0x35d97ef2 } }
1687 },
1688 { /* Mainly checking JIT here. */
1689 "MOV REG64",
1690 .u.insns_int = {
1691 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1692 BPF_MOV64_REG(R1, R0),
1693 BPF_MOV64_REG(R2, R1),
1694 BPF_MOV64_REG(R3, R2),
1695 BPF_MOV64_REG(R4, R3),
1696 BPF_MOV64_REG(R5, R4),
1697 BPF_MOV64_REG(R6, R5),
1698 BPF_MOV64_REG(R7, R6),
1699 BPF_MOV64_REG(R8, R7),
1700 BPF_MOV64_REG(R9, R8),
1701 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1702 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1703 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1704 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1705 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1706 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1707 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1708 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1709 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1710 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1711 BPF_ALU64_REG(BPF_ADD, R0, R0),
1712 BPF_ALU64_REG(BPF_ADD, R0, R1),
1713 BPF_ALU64_REG(BPF_ADD, R0, R2),
1714 BPF_ALU64_REG(BPF_ADD, R0, R3),
1715 BPF_ALU64_REG(BPF_ADD, R0, R4),
1716 BPF_ALU64_REG(BPF_ADD, R0, R5),
1717 BPF_ALU64_REG(BPF_ADD, R0, R6),
1718 BPF_ALU64_REG(BPF_ADD, R0, R7),
1719 BPF_ALU64_REG(BPF_ADD, R0, R8),
1720 BPF_ALU64_REG(BPF_ADD, R0, R9),
1721 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1722 BPF_EXIT_INSN(),
1723 },
1724 INTERNAL,
1725 { },
1726 { { 0, 0xfefe } }
1727 },
1728 { /* Mainly checking JIT here. */
1729 "MOV REG32",
1730 .u.insns_int = {
1731 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1732 BPF_MOV64_REG(R1, R0),
1733 BPF_MOV64_REG(R2, R1),
1734 BPF_MOV64_REG(R3, R2),
1735 BPF_MOV64_REG(R4, R3),
1736 BPF_MOV64_REG(R5, R4),
1737 BPF_MOV64_REG(R6, R5),
1738 BPF_MOV64_REG(R7, R6),
1739 BPF_MOV64_REG(R8, R7),
1740 BPF_MOV64_REG(R9, R8),
1741 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1742 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1743 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1744 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1745 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1746 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1747 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1748 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1749 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1750 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1751 BPF_ALU64_REG(BPF_ADD, R0, R0),
1752 BPF_ALU64_REG(BPF_ADD, R0, R1),
1753 BPF_ALU64_REG(BPF_ADD, R0, R2),
1754 BPF_ALU64_REG(BPF_ADD, R0, R3),
1755 BPF_ALU64_REG(BPF_ADD, R0, R4),
1756 BPF_ALU64_REG(BPF_ADD, R0, R5),
1757 BPF_ALU64_REG(BPF_ADD, R0, R6),
1758 BPF_ALU64_REG(BPF_ADD, R0, R7),
1759 BPF_ALU64_REG(BPF_ADD, R0, R8),
1760 BPF_ALU64_REG(BPF_ADD, R0, R9),
1761 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1762 BPF_EXIT_INSN(),
1763 },
1764 INTERNAL,
1765 { },
1766 { { 0, 0xfefe } }
1767 },
1768 { /* Mainly checking JIT here. */
1769 "LD IMM64",
1770 .u.insns_int = {
1771 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1772 BPF_MOV64_REG(R1, R0),
1773 BPF_MOV64_REG(R2, R1),
1774 BPF_MOV64_REG(R3, R2),
1775 BPF_MOV64_REG(R4, R3),
1776 BPF_MOV64_REG(R5, R4),
1777 BPF_MOV64_REG(R6, R5),
1778 BPF_MOV64_REG(R7, R6),
1779 BPF_MOV64_REG(R8, R7),
1780 BPF_MOV64_REG(R9, R8),
1781 BPF_LD_IMM64(R0, 0x0LL),
1782 BPF_LD_IMM64(R1, 0x0LL),
1783 BPF_LD_IMM64(R2, 0x0LL),
1784 BPF_LD_IMM64(R3, 0x0LL),
1785 BPF_LD_IMM64(R4, 0x0LL),
1786 BPF_LD_IMM64(R5, 0x0LL),
1787 BPF_LD_IMM64(R6, 0x0LL),
1788 BPF_LD_IMM64(R7, 0x0LL),
1789 BPF_LD_IMM64(R8, 0x0LL),
1790 BPF_LD_IMM64(R9, 0x0LL),
1791 BPF_ALU64_REG(BPF_ADD, R0, R0),
1792 BPF_ALU64_REG(BPF_ADD, R0, R1),
1793 BPF_ALU64_REG(BPF_ADD, R0, R2),
1794 BPF_ALU64_REG(BPF_ADD, R0, R3),
1795 BPF_ALU64_REG(BPF_ADD, R0, R4),
1796 BPF_ALU64_REG(BPF_ADD, R0, R5),
1797 BPF_ALU64_REG(BPF_ADD, R0, R6),
1798 BPF_ALU64_REG(BPF_ADD, R0, R7),
1799 BPF_ALU64_REG(BPF_ADD, R0, R8),
1800 BPF_ALU64_REG(BPF_ADD, R0, R9),
1801 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1802 BPF_EXIT_INSN(),
1803 },
1804 INTERNAL,
1805 { },
1806 { { 0, 0xfefe } }
1807 },
1808 {
1809 "INT: ALU MIX",
1810 .u.insns_int = {
1811 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1812 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1813 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1814 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1815 BPF_ALU64_REG(BPF_DIV, R0, R2),
1816 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1817 BPF_EXIT_INSN(),
1818 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1819 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1820 BPF_EXIT_INSN(),
1821 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1822 BPF_EXIT_INSN(),
1823 },
1824 INTERNAL,
1825 { },
1826 { { 0, -1 } }
1827 },
1828 {
1829 "INT: shifts by register",
1830 .u.insns_int = {
1831 BPF_MOV64_IMM(R0, -1234),
1832 BPF_MOV64_IMM(R1, 1),
1833 BPF_ALU32_REG(BPF_RSH, R0, R1),
1834 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1835 BPF_EXIT_INSN(),
1836 BPF_MOV64_IMM(R2, 1),
1837 BPF_ALU64_REG(BPF_LSH, R0, R2),
1838 BPF_MOV32_IMM(R4, -1234),
1839 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1840 BPF_EXIT_INSN(),
1841 BPF_ALU64_IMM(BPF_AND, R4, 63),
1842 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1843 BPF_MOV64_IMM(R3, 47),
1844 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1845 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1846 BPF_EXIT_INSN(),
1847 BPF_MOV64_IMM(R2, 1),
1848 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1849 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1850 BPF_EXIT_INSN(),
1851 BPF_MOV64_IMM(R4, 4),
1852 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1853 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1854 BPF_EXIT_INSN(),
1855 BPF_MOV64_IMM(R4, 5),
1856 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1857 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1858 BPF_EXIT_INSN(),
1859 BPF_MOV64_IMM(R0, -1),
1860 BPF_EXIT_INSN(),
1861 },
1862 INTERNAL,
1863 { },
1864 { { 0, -1 } }
1865 },
1866 {
1867 "INT: DIV + ABS",
1868 .u.insns_int = {
1869 BPF_ALU64_REG(BPF_MOV, R6, R1),
1870 BPF_LD_ABS(BPF_B, 3),
1871 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1872 BPF_ALU32_REG(BPF_DIV, R0, R2),
1873 BPF_ALU64_REG(BPF_MOV, R8, R0),
1874 BPF_LD_ABS(BPF_B, 4),
1875 BPF_ALU64_REG(BPF_ADD, R8, R0),
1876 BPF_LD_IND(BPF_B, R8, -70),
1877 BPF_EXIT_INSN(),
1878 },
1879 INTERNAL,
1880 { 10, 20, 30, 40, 50 },
1881 { { 4, 0 }, { 5, 10 } }
1882 },
1883 {
1884 "INT: DIV by zero",
1885 .u.insns_int = {
1886 BPF_ALU64_REG(BPF_MOV, R6, R1),
1887 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1888 BPF_LD_ABS(BPF_B, 3),
1889 BPF_ALU32_REG(BPF_DIV, R0, R7),
1890 BPF_EXIT_INSN(),
1891 },
1892 INTERNAL,
1893 { 10, 20, 30, 40, 50 },
1894 { { 3, 0 }, { 4, 0 } }
1895 },
1896 {
1897 "check: missing ret",
1898 .u.insns = {
1899 BPF_STMT(BPF_LD | BPF_IMM, 1),
1900 },
1901 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1902 { },
1903 { }
1904 },
1905 {
1906 "check: div_k_0",
1907 .u.insns = {
1908 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1909 BPF_STMT(BPF_RET | BPF_K, 0)
1910 },
1911 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1912 { },
1913 { }
1914 },
1915 {
1916 "check: unknown insn",
1917 .u.insns = {
1918 /* seccomp insn, rejected in socket filter */
1919 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1920 BPF_STMT(BPF_RET | BPF_K, 0)
1921 },
1922 CLASSIC | FLAG_EXPECTED_FAIL,
1923 { },
1924 { }
1925 },
1926 {
1927 "check: out of range spill/fill",
1928 .u.insns = {
1929 BPF_STMT(BPF_STX, 16),
1930 BPF_STMT(BPF_RET | BPF_K, 0)
1931 },
1932 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1933 { },
1934 { }
1935 },
1936 {
1937 "JUMPS + HOLES",
1938 .u.insns = {
1939 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1940 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1941 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1942 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1943 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1944 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1945 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1946 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1947 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1948 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1949 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1950 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1951 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1952 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1953 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1954 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1955 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1956 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1957 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1958 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1959 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1960 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1961 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1962 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1963 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1964 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1965 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1966 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1967 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1968 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1969 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1970 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1971 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1972 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1973 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1974 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1975 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1976 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1977 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1978 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1992 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1993 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1994 BPF_STMT(BPF_RET | BPF_A, 0),
1995 BPF_STMT(BPF_RET | BPF_A, 0),
1996 },
1997 CLASSIC,
1998 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1999 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2000 0x08, 0x00,
2001 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2002 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2003 0xc0, 0xa8, 0x33, 0x01,
2004 0xc0, 0xa8, 0x33, 0x02,
2005 0xbb, 0xb6,
2006 0xa9, 0xfa,
2007 0x00, 0x14, 0x00, 0x00,
2008 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2009 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2010 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2011 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2012 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2013 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2014 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2015 0xcc, 0xcc, 0xcc, 0xcc },
2016 { { 88, 0x001b } }
2017 },
2018 {
2019 "check: RET X",
2020 .u.insns = {
2021 BPF_STMT(BPF_RET | BPF_X, 0),
2022 },
2023 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2024 { },
2025 { },
2026 },
2027 {
2028 "check: LDX + RET X",
2029 .u.insns = {
2030 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2031 BPF_STMT(BPF_RET | BPF_X, 0),
2032 },
2033 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2034 { },
2035 { },
2036 },
2037 { /* Mainly checking JIT here. */
2038 "M[]: alt STX + LDX",
2039 .u.insns = {
2040 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2041 BPF_STMT(BPF_STX, 0),
2042 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2043 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2044 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2045 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2046 BPF_STMT(BPF_STX, 1),
2047 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2048 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2049 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2050 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2051 BPF_STMT(BPF_STX, 2),
2052 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2053 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2054 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2055 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2056 BPF_STMT(BPF_STX, 3),
2057 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2058 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2059 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2060 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2061 BPF_STMT(BPF_STX, 4),
2062 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2063 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2064 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2065 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2066 BPF_STMT(BPF_STX, 5),
2067 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2068 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2069 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2070 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2071 BPF_STMT(BPF_STX, 6),
2072 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2073 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2074 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2075 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2076 BPF_STMT(BPF_STX, 7),
2077 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2078 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2079 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2080 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2081 BPF_STMT(BPF_STX, 8),
2082 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2083 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2084 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2085 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2086 BPF_STMT(BPF_STX, 9),
2087 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2088 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2089 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2090 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2091 BPF_STMT(BPF_STX, 10),
2092 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2093 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2094 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2095 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2096 BPF_STMT(BPF_STX, 11),
2097 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2098 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2099 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2100 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2101 BPF_STMT(BPF_STX, 12),
2102 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2103 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2105 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2106 BPF_STMT(BPF_STX, 13),
2107 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2108 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2109 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2110 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2111 BPF_STMT(BPF_STX, 14),
2112 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2113 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2114 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2115 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2116 BPF_STMT(BPF_STX, 15),
2117 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2118 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2119 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2120 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2121 BPF_STMT(BPF_RET | BPF_A, 0),
2122 },
2123 CLASSIC | FLAG_NO_DATA,
2124 { },
2125 { { 0, 116 } },
2126 },
2127 { /* Mainly checking JIT here. */
2128 "M[]: full STX + full LDX",
2129 .u.insns = {
2130 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2131 BPF_STMT(BPF_STX, 0),
2132 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2133 BPF_STMT(BPF_STX, 1),
2134 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2135 BPF_STMT(BPF_STX, 2),
2136 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2137 BPF_STMT(BPF_STX, 3),
2138 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2139 BPF_STMT(BPF_STX, 4),
2140 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2141 BPF_STMT(BPF_STX, 5),
2142 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2143 BPF_STMT(BPF_STX, 6),
2144 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2145 BPF_STMT(BPF_STX, 7),
2146 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2147 BPF_STMT(BPF_STX, 8),
2148 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2149 BPF_STMT(BPF_STX, 9),
2150 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2151 BPF_STMT(BPF_STX, 10),
2152 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2153 BPF_STMT(BPF_STX, 11),
2154 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2155 BPF_STMT(BPF_STX, 12),
2156 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2157 BPF_STMT(BPF_STX, 13),
2158 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2159 BPF_STMT(BPF_STX, 14),
2160 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2161 BPF_STMT(BPF_STX, 15),
2162 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2163 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2164 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2165 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2166 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2167 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2168 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2169 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2170 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2171 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2172 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2173 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2174 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2175 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2176 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2177 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2178 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2179 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2180 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2181 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2182 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2183 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2184 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2185 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2186 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2187 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2188 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2189 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2190 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2191 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2192 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2193 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2194 BPF_STMT(BPF_RET | BPF_A, 0),
2195 },
2196 CLASSIC | FLAG_NO_DATA,
2197 { },
2198 { { 0, 0x2a5a5e5 } },
2199 },
2200 {
2201 "check: SKF_AD_MAX",
2202 .u.insns = {
2203 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2204 SKF_AD_OFF + SKF_AD_MAX),
2205 BPF_STMT(BPF_RET | BPF_A, 0),
2206 },
2207 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2208 { },
2209 { },
2210 },
2211 { /* Passes checker but fails during runtime. */
2212 "LD [SKF_AD_OFF-1]",
2213 .u.insns = {
2214 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2215 SKF_AD_OFF - 1),
2216 BPF_STMT(BPF_RET | BPF_K, 1),
2217 },
2218 CLASSIC,
2219 { },
2220 { { 1, 0 } },
2221 },
2222 {
2223 "load 64-bit immediate",
2224 .u.insns_int = {
2225 BPF_LD_IMM64(R1, 0x567800001234LL),
2226 BPF_MOV64_REG(R2, R1),
2227 BPF_MOV64_REG(R3, R2),
2228 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2229 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2230 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2231 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2232 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2233 BPF_EXIT_INSN(),
2234 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2235 BPF_EXIT_INSN(),
2236 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2237 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2238 BPF_EXIT_INSN(),
2239 },
2240 INTERNAL,
2241 { },
2242 { { 0, 1 } }
2243 },
2244 {
2245 "nmap reduced",
2246 .u.insns_int = {
2247 BPF_MOV64_REG(R6, R1),
2248 BPF_LD_ABS(BPF_H, 12),
2249 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2250 BPF_LD_ABS(BPF_H, 12),
2251 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2252 BPF_MOV32_IMM(R0, 18),
2253 BPF_STX_MEM(BPF_W, R10, R0, -64),
2254 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2255 BPF_LD_IND(BPF_W, R7, 14),
2256 BPF_STX_MEM(BPF_W, R10, R0, -60),
2257 BPF_MOV32_IMM(R0, 280971478),
2258 BPF_STX_MEM(BPF_W, R10, R0, -56),
2259 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2260 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2261 BPF_ALU32_REG(BPF_SUB, R0, R7),
2262 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2263 BPF_LD_ABS(BPF_H, 12),
2264 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2265 BPF_MOV32_IMM(R0, 22),
2266 BPF_STX_MEM(BPF_W, R10, R0, -56),
2267 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2268 BPF_LD_IND(BPF_H, R7, 14),
2269 BPF_STX_MEM(BPF_W, R10, R0, -52),
2270 BPF_MOV32_IMM(R0, 17366),
2271 BPF_STX_MEM(BPF_W, R10, R0, -48),
2272 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2273 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2274 BPF_ALU32_REG(BPF_SUB, R0, R7),
2275 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2276 BPF_MOV32_IMM(R0, 256),
2277 BPF_EXIT_INSN(),
2278 BPF_MOV32_IMM(R0, 0),
2279 BPF_EXIT_INSN(),
2280 },
2281 INTERNAL,
2282 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2283 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2284 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2285 { { 38, 256 } }
2286 },
2287 /* BPF_ALU | BPF_MOV | BPF_X */
2288 {
2289 "ALU_MOV_X: dst = 2",
2290 .u.insns_int = {
2291 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2292 BPF_ALU32_REG(BPF_MOV, R0, R1),
2293 BPF_EXIT_INSN(),
2294 },
2295 INTERNAL,
2296 { },
2297 { { 0, 2 } },
2298 },
2299 {
2300 "ALU_MOV_X: dst = 4294967295",
2301 .u.insns_int = {
2302 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2303 BPF_ALU32_REG(BPF_MOV, R0, R1),
2304 BPF_EXIT_INSN(),
2305 },
2306 INTERNAL,
2307 { },
2308 { { 0, 4294967295U } },
2309 },
2310 {
2311 "ALU64_MOV_X: dst = 2",
2312 .u.insns_int = {
2313 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2314 BPF_ALU64_REG(BPF_MOV, R0, R1),
2315 BPF_EXIT_INSN(),
2316 },
2317 INTERNAL,
2318 { },
2319 { { 0, 2 } },
2320 },
2321 {
2322 "ALU64_MOV_X: dst = 4294967295",
2323 .u.insns_int = {
2324 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2325 BPF_ALU64_REG(BPF_MOV, R0, R1),
2326 BPF_EXIT_INSN(),
2327 },
2328 INTERNAL,
2329 { },
2330 { { 0, 4294967295U } },
2331 },
2332 /* BPF_ALU | BPF_MOV | BPF_K */
2333 {
2334 "ALU_MOV_K: dst = 2",
2335 .u.insns_int = {
2336 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2337 BPF_EXIT_INSN(),
2338 },
2339 INTERNAL,
2340 { },
2341 { { 0, 2 } },
2342 },
2343 {
2344 "ALU_MOV_K: dst = 4294967295",
2345 .u.insns_int = {
2346 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2347 BPF_EXIT_INSN(),
2348 },
2349 INTERNAL,
2350 { },
2351 { { 0, 4294967295U } },
2352 },
2353 {
2354 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2355 .u.insns_int = {
2356 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2357 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2358 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2359 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2360 BPF_MOV32_IMM(R0, 2),
2361 BPF_EXIT_INSN(),
2362 BPF_MOV32_IMM(R0, 1),
2363 BPF_EXIT_INSN(),
2364 },
2365 INTERNAL,
2366 { },
2367 { { 0, 0x1 } },
2368 },
2369 {
2370 "ALU64_MOV_K: dst = 2",
2371 .u.insns_int = {
2372 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2373 BPF_EXIT_INSN(),
2374 },
2375 INTERNAL,
2376 { },
2377 { { 0, 2 } },
2378 },
2379 {
2380 "ALU64_MOV_K: dst = 2147483647",
2381 .u.insns_int = {
2382 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2383 BPF_EXIT_INSN(),
2384 },
2385 INTERNAL,
2386 { },
2387 { { 0, 2147483647 } },
2388 },
2389 {
2390 "ALU64_OR_K: dst = 0x0",
2391 .u.insns_int = {
2392 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2393 BPF_LD_IMM64(R3, 0x0),
2394 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2395 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2396 BPF_MOV32_IMM(R0, 2),
2397 BPF_EXIT_INSN(),
2398 BPF_MOV32_IMM(R0, 1),
2399 BPF_EXIT_INSN(),
2400 },
2401 INTERNAL,
2402 { },
2403 { { 0, 0x1 } },
2404 },
2405 {
2406 "ALU64_MOV_K: dst = -1",
2407 .u.insns_int = {
2408 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2409 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2410 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2411 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2412 BPF_MOV32_IMM(R0, 2),
2413 BPF_EXIT_INSN(),
2414 BPF_MOV32_IMM(R0, 1),
2415 BPF_EXIT_INSN(),
2416 },
2417 INTERNAL,
2418 { },
2419 { { 0, 0x1 } },
2420 },
2421 /* BPF_ALU | BPF_ADD | BPF_X */
2422 {
2423 "ALU_ADD_X: 1 + 2 = 3",
2424 .u.insns_int = {
2425 BPF_LD_IMM64(R0, 1),
2426 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2427 BPF_ALU32_REG(BPF_ADD, R0, R1),
2428 BPF_EXIT_INSN(),
2429 },
2430 INTERNAL,
2431 { },
2432 { { 0, 3 } },
2433 },
2434 {
2435 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2436 .u.insns_int = {
2437 BPF_LD_IMM64(R0, 1),
2438 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2439 BPF_ALU32_REG(BPF_ADD, R0, R1),
2440 BPF_EXIT_INSN(),
2441 },
2442 INTERNAL,
2443 { },
2444 { { 0, 4294967295U } },
2445 },
2446 {
2447 "ALU_ADD_X: 2 + 4294967294 = 0",
2448 .u.insns_int = {
2449 BPF_LD_IMM64(R0, 2),
2450 BPF_LD_IMM64(R1, 4294967294U),
2451 BPF_ALU32_REG(BPF_ADD, R0, R1),
2452 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2453 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2454 BPF_EXIT_INSN(),
2455 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2456 BPF_EXIT_INSN(),
2457 },
2458 INTERNAL,
2459 { },
2460 { { 0, 1 } },
2461 },
2462 {
2463 "ALU64_ADD_X: 1 + 2 = 3",
2464 .u.insns_int = {
2465 BPF_LD_IMM64(R0, 1),
2466 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2467 BPF_ALU64_REG(BPF_ADD, R0, R1),
2468 BPF_EXIT_INSN(),
2469 },
2470 INTERNAL,
2471 { },
2472 { { 0, 3 } },
2473 },
2474 {
2475 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2476 .u.insns_int = {
2477 BPF_LD_IMM64(R0, 1),
2478 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2479 BPF_ALU64_REG(BPF_ADD, R0, R1),
2480 BPF_EXIT_INSN(),
2481 },
2482 INTERNAL,
2483 { },
2484 { { 0, 4294967295U } },
2485 },
2486 {
2487 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2488 .u.insns_int = {
2489 BPF_LD_IMM64(R0, 2),
2490 BPF_LD_IMM64(R1, 4294967294U),
2491 BPF_LD_IMM64(R2, 4294967296ULL),
2492 BPF_ALU64_REG(BPF_ADD, R0, R1),
2493 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2494 BPF_MOV32_IMM(R0, 0),
2495 BPF_EXIT_INSN(),
2496 BPF_MOV32_IMM(R0, 1),
2497 BPF_EXIT_INSN(),
2498 },
2499 INTERNAL,
2500 { },
2501 { { 0, 1 } },
2502 },
2503 /* BPF_ALU | BPF_ADD | BPF_K */
2504 {
2505 "ALU_ADD_K: 1 + 2 = 3",
2506 .u.insns_int = {
2507 BPF_LD_IMM64(R0, 1),
2508 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2509 BPF_EXIT_INSN(),
2510 },
2511 INTERNAL,
2512 { },
2513 { { 0, 3 } },
2514 },
2515 {
2516 "ALU_ADD_K: 3 + 0 = 3",
2517 .u.insns_int = {
2518 BPF_LD_IMM64(R0, 3),
2519 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2520 BPF_EXIT_INSN(),
2521 },
2522 INTERNAL,
2523 { },
2524 { { 0, 3 } },
2525 },
2526 {
2527 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2528 .u.insns_int = {
2529 BPF_LD_IMM64(R0, 1),
2530 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2531 BPF_EXIT_INSN(),
2532 },
2533 INTERNAL,
2534 { },
2535 { { 0, 4294967295U } },
2536 },
2537 {
2538 "ALU_ADD_K: 4294967294 + 2 = 0",
2539 .u.insns_int = {
2540 BPF_LD_IMM64(R0, 4294967294U),
2541 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2542 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2543 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2544 BPF_EXIT_INSN(),
2545 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2546 BPF_EXIT_INSN(),
2547 },
2548 INTERNAL,
2549 { },
2550 { { 0, 1 } },
2551 },
2552 {
2553 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2554 .u.insns_int = {
2555 BPF_LD_IMM64(R2, 0x0),
2556 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2557 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2558 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2559 BPF_MOV32_IMM(R0, 2),
2560 BPF_EXIT_INSN(),
2561 BPF_MOV32_IMM(R0, 1),
2562 BPF_EXIT_INSN(),
2563 },
2564 INTERNAL,
2565 { },
2566 { { 0, 0x1 } },
2567 },
2568 {
2569 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2570 .u.insns_int = {
2571 BPF_LD_IMM64(R2, 0x0),
2572 BPF_LD_IMM64(R3, 0xffff),
2573 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2574 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2575 BPF_MOV32_IMM(R0, 2),
2576 BPF_EXIT_INSN(),
2577 BPF_MOV32_IMM(R0, 1),
2578 BPF_EXIT_INSN(),
2579 },
2580 INTERNAL,
2581 { },
2582 { { 0, 0x1 } },
2583 },
2584 {
2585 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2586 .u.insns_int = {
2587 BPF_LD_IMM64(R2, 0x0),
2588 BPF_LD_IMM64(R3, 0x7fffffff),
2589 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2590 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2591 BPF_MOV32_IMM(R0, 2),
2592 BPF_EXIT_INSN(),
2593 BPF_MOV32_IMM(R0, 1),
2594 BPF_EXIT_INSN(),
2595 },
2596 INTERNAL,
2597 { },
2598 { { 0, 0x1 } },
2599 },
2600 {
2601 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2602 .u.insns_int = {
2603 BPF_LD_IMM64(R2, 0x0),
2604 BPF_LD_IMM64(R3, 0x80000000),
2605 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2606 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2607 BPF_MOV32_IMM(R0, 2),
2608 BPF_EXIT_INSN(),
2609 BPF_MOV32_IMM(R0, 1),
2610 BPF_EXIT_INSN(),
2611 },
2612 INTERNAL,
2613 { },
2614 { { 0, 0x1 } },
2615 },
2616 {
2617 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2618 .u.insns_int = {
2619 BPF_LD_IMM64(R2, 0x0),
2620 BPF_LD_IMM64(R3, 0x80008000),
2621 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2622 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2623 BPF_MOV32_IMM(R0, 2),
2624 BPF_EXIT_INSN(),
2625 BPF_MOV32_IMM(R0, 1),
2626 BPF_EXIT_INSN(),
2627 },
2628 INTERNAL,
2629 { },
2630 { { 0, 0x1 } },
2631 },
2632 {
2633 "ALU64_ADD_K: 1 + 2 = 3",
2634 .u.insns_int = {
2635 BPF_LD_IMM64(R0, 1),
2636 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2637 BPF_EXIT_INSN(),
2638 },
2639 INTERNAL,
2640 { },
2641 { { 0, 3 } },
2642 },
2643 {
2644 "ALU64_ADD_K: 3 + 0 = 3",
2645 .u.insns_int = {
2646 BPF_LD_IMM64(R0, 3),
2647 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2648 BPF_EXIT_INSN(),
2649 },
2650 INTERNAL,
2651 { },
2652 { { 0, 3 } },
2653 },
2654 {
2655 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2656 .u.insns_int = {
2657 BPF_LD_IMM64(R0, 1),
2658 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2659 BPF_EXIT_INSN(),
2660 },
2661 INTERNAL,
2662 { },
2663 { { 0, 2147483647 } },
2664 },
2665 {
2666 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2667 .u.insns_int = {
2668 BPF_LD_IMM64(R0, 4294967294U),
2669 BPF_LD_IMM64(R1, 4294967296ULL),
2670 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2671 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2672 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2673 BPF_EXIT_INSN(),
2674 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2675 BPF_EXIT_INSN(),
2676 },
2677 INTERNAL,
2678 { },
2679 { { 0, 1 } },
2680 },
2681 {
2682 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2683 .u.insns_int = {
2684 BPF_LD_IMM64(R0, 2147483646),
2685 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2686 BPF_EXIT_INSN(),
2687 },
2688 INTERNAL,
2689 { },
2690 { { 0, -1 } },
2691 },
2692 {
2693 "ALU64_ADD_K: 1 + 0 = 1",
2694 .u.insns_int = {
2695 BPF_LD_IMM64(R2, 0x1),
2696 BPF_LD_IMM64(R3, 0x1),
2697 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2698 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2699 BPF_MOV32_IMM(R0, 2),
2700 BPF_EXIT_INSN(),
2701 BPF_MOV32_IMM(R0, 1),
2702 BPF_EXIT_INSN(),
2703 },
2704 INTERNAL,
2705 { },
2706 { { 0, 0x1 } },
2707 },
2708 {
2709 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2710 .u.insns_int = {
2711 BPF_LD_IMM64(R2, 0x0),
2712 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2713 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2714 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2715 BPF_MOV32_IMM(R0, 2),
2716 BPF_EXIT_INSN(),
2717 BPF_MOV32_IMM(R0, 1),
2718 BPF_EXIT_INSN(),
2719 },
2720 INTERNAL,
2721 { },
2722 { { 0, 0x1 } },
2723 },
2724 {
2725 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2726 .u.insns_int = {
2727 BPF_LD_IMM64(R2, 0x0),
2728 BPF_LD_IMM64(R3, 0xffff),
2729 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2730 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2731 BPF_MOV32_IMM(R0, 2),
2732 BPF_EXIT_INSN(),
2733 BPF_MOV32_IMM(R0, 1),
2734 BPF_EXIT_INSN(),
2735 },
2736 INTERNAL,
2737 { },
2738 { { 0, 0x1 } },
2739 },
2740 {
2741 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2742 .u.insns_int = {
2743 BPF_LD_IMM64(R2, 0x0),
2744 BPF_LD_IMM64(R3, 0x7fffffff),
2745 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2746 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2747 BPF_MOV32_IMM(R0, 2),
2748 BPF_EXIT_INSN(),
2749 BPF_MOV32_IMM(R0, 1),
2750 BPF_EXIT_INSN(),
2751 },
2752 INTERNAL,
2753 { },
2754 { { 0, 0x1 } },
2755 },
2756 {
2757 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2758 .u.insns_int = {
2759 BPF_LD_IMM64(R2, 0x0),
2760 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2761 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2762 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2763 BPF_MOV32_IMM(R0, 2),
2764 BPF_EXIT_INSN(),
2765 BPF_MOV32_IMM(R0, 1),
2766 BPF_EXIT_INSN(),
2767 },
2768 INTERNAL,
2769 { },
2770 { { 0, 0x1 } },
2771 },
2772 {
2773 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2774 .u.insns_int = {
2775 BPF_LD_IMM64(R2, 0x0),
2776 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2777 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2778 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2779 BPF_MOV32_IMM(R0, 2),
2780 BPF_EXIT_INSN(),
2781 BPF_MOV32_IMM(R0, 1),
2782 BPF_EXIT_INSN(),
2783 },
2784 INTERNAL,
2785 { },
2786 { { 0, 0x1 } },
2787 },
2788 /* BPF_ALU | BPF_SUB | BPF_X */
2789 {
2790 "ALU_SUB_X: 3 - 1 = 2",
2791 .u.insns_int = {
2792 BPF_LD_IMM64(R0, 3),
2793 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2794 BPF_ALU32_REG(BPF_SUB, R0, R1),
2795 BPF_EXIT_INSN(),
2796 },
2797 INTERNAL,
2798 { },
2799 { { 0, 2 } },
2800 },
2801 {
2802 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2803 .u.insns_int = {
2804 BPF_LD_IMM64(R0, 4294967295U),
2805 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2806 BPF_ALU32_REG(BPF_SUB, R0, R1),
2807 BPF_EXIT_INSN(),
2808 },
2809 INTERNAL,
2810 { },
2811 { { 0, 1 } },
2812 },
2813 {
2814 "ALU64_SUB_X: 3 - 1 = 2",
2815 .u.insns_int = {
2816 BPF_LD_IMM64(R0, 3),
2817 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2818 BPF_ALU64_REG(BPF_SUB, R0, R1),
2819 BPF_EXIT_INSN(),
2820 },
2821 INTERNAL,
2822 { },
2823 { { 0, 2 } },
2824 },
2825 {
2826 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2827 .u.insns_int = {
2828 BPF_LD_IMM64(R0, 4294967295U),
2829 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2830 BPF_ALU64_REG(BPF_SUB, R0, R1),
2831 BPF_EXIT_INSN(),
2832 },
2833 INTERNAL,
2834 { },
2835 { { 0, 1 } },
2836 },
2837 /* BPF_ALU | BPF_SUB | BPF_K */
2838 {
2839 "ALU_SUB_K: 3 - 1 = 2",
2840 .u.insns_int = {
2841 BPF_LD_IMM64(R0, 3),
2842 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2843 BPF_EXIT_INSN(),
2844 },
2845 INTERNAL,
2846 { },
2847 { { 0, 2 } },
2848 },
2849 {
2850 "ALU_SUB_K: 3 - 0 = 3",
2851 .u.insns_int = {
2852 BPF_LD_IMM64(R0, 3),
2853 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2854 BPF_EXIT_INSN(),
2855 },
2856 INTERNAL,
2857 { },
2858 { { 0, 3 } },
2859 },
2860 {
2861 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2862 .u.insns_int = {
2863 BPF_LD_IMM64(R0, 4294967295U),
2864 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
2865 BPF_EXIT_INSN(),
2866 },
2867 INTERNAL,
2868 { },
2869 { { 0, 1 } },
2870 },
2871 {
2872 "ALU64_SUB_K: 3 - 1 = 2",
2873 .u.insns_int = {
2874 BPF_LD_IMM64(R0, 3),
2875 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2876 BPF_EXIT_INSN(),
2877 },
2878 INTERNAL,
2879 { },
2880 { { 0, 2 } },
2881 },
2882 {
2883 "ALU64_SUB_K: 3 - 0 = 3",
2884 .u.insns_int = {
2885 BPF_LD_IMM64(R0, 3),
2886 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2887 BPF_EXIT_INSN(),
2888 },
2889 INTERNAL,
2890 { },
2891 { { 0, 3 } },
2892 },
2893 {
2894 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2895 .u.insns_int = {
2896 BPF_LD_IMM64(R0, 4294967294U),
2897 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
2898 BPF_EXIT_INSN(),
2899 },
2900 INTERNAL,
2901 { },
2902 { { 0, -1 } },
2903 },
2904 {
2905 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2906 .u.insns_int = {
2907 BPF_LD_IMM64(R0, 2147483646),
2908 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2909 BPF_EXIT_INSN(),
2910 },
2911 INTERNAL,
2912 { },
2913 { { 0, -1 } },
2914 },
2915 /* BPF_ALU | BPF_MUL | BPF_X */
2916 {
2917 "ALU_MUL_X: 2 * 3 = 6",
2918 .u.insns_int = {
2919 BPF_LD_IMM64(R0, 2),
2920 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2921 BPF_ALU32_REG(BPF_MUL, R0, R1),
2922 BPF_EXIT_INSN(),
2923 },
2924 INTERNAL,
2925 { },
2926 { { 0, 6 } },
2927 },
2928 {
2929 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2930 .u.insns_int = {
2931 BPF_LD_IMM64(R0, 2),
2932 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2933 BPF_ALU32_REG(BPF_MUL, R0, R1),
2934 BPF_EXIT_INSN(),
2935 },
2936 INTERNAL,
2937 { },
2938 { { 0, 0xFFFFFFF0 } },
2939 },
2940 {
2941 "ALU_MUL_X: -1 * -1 = 1",
2942 .u.insns_int = {
2943 BPF_LD_IMM64(R0, -1),
2944 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2945 BPF_ALU32_REG(BPF_MUL, R0, R1),
2946 BPF_EXIT_INSN(),
2947 },
2948 INTERNAL,
2949 { },
2950 { { 0, 1 } },
2951 },
2952 {
2953 "ALU64_MUL_X: 2 * 3 = 6",
2954 .u.insns_int = {
2955 BPF_LD_IMM64(R0, 2),
2956 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2957 BPF_ALU64_REG(BPF_MUL, R0, R1),
2958 BPF_EXIT_INSN(),
2959 },
2960 INTERNAL,
2961 { },
2962 { { 0, 6 } },
2963 },
2964 {
2965 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2966 .u.insns_int = {
2967 BPF_LD_IMM64(R0, 1),
2968 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2969 BPF_ALU64_REG(BPF_MUL, R0, R1),
2970 BPF_EXIT_INSN(),
2971 },
2972 INTERNAL,
2973 { },
2974 { { 0, 2147483647 } },
2975 },
2976 /* BPF_ALU | BPF_MUL | BPF_K */
2977 {
2978 "ALU_MUL_K: 2 * 3 = 6",
2979 .u.insns_int = {
2980 BPF_LD_IMM64(R0, 2),
2981 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2982 BPF_EXIT_INSN(),
2983 },
2984 INTERNAL,
2985 { },
2986 { { 0, 6 } },
2987 },
2988 {
2989 "ALU_MUL_K: 3 * 1 = 3",
2990 .u.insns_int = {
2991 BPF_LD_IMM64(R0, 3),
2992 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2993 BPF_EXIT_INSN(),
2994 },
2995 INTERNAL,
2996 { },
2997 { { 0, 3 } },
2998 },
2999 {
3000 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3001 .u.insns_int = {
3002 BPF_LD_IMM64(R0, 2),
3003 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3004 BPF_EXIT_INSN(),
3005 },
3006 INTERNAL,
3007 { },
3008 { { 0, 0xFFFFFFF0 } },
3009 },
3010 {
3011 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3012 .u.insns_int = {
3013 BPF_LD_IMM64(R2, 0x1),
3014 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3015 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3016 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3017 BPF_MOV32_IMM(R0, 2),
3018 BPF_EXIT_INSN(),
3019 BPF_MOV32_IMM(R0, 1),
3020 BPF_EXIT_INSN(),
3021 },
3022 INTERNAL,
3023 { },
3024 { { 0, 0x1 } },
3025 },
3026 {
3027 "ALU64_MUL_K: 2 * 3 = 6",
3028 .u.insns_int = {
3029 BPF_LD_IMM64(R0, 2),
3030 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3031 BPF_EXIT_INSN(),
3032 },
3033 INTERNAL,
3034 { },
3035 { { 0, 6 } },
3036 },
3037 {
3038 "ALU64_MUL_K: 3 * 1 = 3",
3039 .u.insns_int = {
3040 BPF_LD_IMM64(R0, 3),
3041 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3042 BPF_EXIT_INSN(),
3043 },
3044 INTERNAL,
3045 { },
3046 { { 0, 3 } },
3047 },
3048 {
3049 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3050 .u.insns_int = {
3051 BPF_LD_IMM64(R0, 1),
3052 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3053 BPF_EXIT_INSN(),
3054 },
3055 INTERNAL,
3056 { },
3057 { { 0, 2147483647 } },
3058 },
3059 {
3060 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3061 .u.insns_int = {
3062 BPF_LD_IMM64(R0, 1),
3063 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3064 BPF_EXIT_INSN(),
3065 },
3066 INTERNAL,
3067 { },
3068 { { 0, -2147483647 } },
3069 },
3070 {
3071 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3072 .u.insns_int = {
3073 BPF_LD_IMM64(R2, 0x1),
3074 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3075 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3076 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3077 BPF_MOV32_IMM(R0, 2),
3078 BPF_EXIT_INSN(),
3079 BPF_MOV32_IMM(R0, 1),
3080 BPF_EXIT_INSN(),
3081 },
3082 INTERNAL,
3083 { },
3084 { { 0, 0x1 } },
3085 },
3086 /* BPF_ALU | BPF_DIV | BPF_X */
3087 {
3088 "ALU_DIV_X: 6 / 2 = 3",
3089 .u.insns_int = {
3090 BPF_LD_IMM64(R0, 6),
3091 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3092 BPF_ALU32_REG(BPF_DIV, R0, R1),
3093 BPF_EXIT_INSN(),
3094 },
3095 INTERNAL,
3096 { },
3097 { { 0, 3 } },
3098 },
3099 {
3100 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3101 .u.insns_int = {
3102 BPF_LD_IMM64(R0, 4294967295U),
3103 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
3104 BPF_ALU32_REG(BPF_DIV, R0, R1),
3105 BPF_EXIT_INSN(),
3106 },
3107 INTERNAL,
3108 { },
3109 { { 0, 1 } },
3110 },
3111 {
3112 "ALU64_DIV_X: 6 / 2 = 3",
3113 .u.insns_int = {
3114 BPF_LD_IMM64(R0, 6),
3115 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3116 BPF_ALU64_REG(BPF_DIV, R0, R1),
3117 BPF_EXIT_INSN(),
3118 },
3119 INTERNAL,
3120 { },
3121 { { 0, 3 } },
3122 },
3123 {
3124 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3125 .u.insns_int = {
3126 BPF_LD_IMM64(R0, 2147483647),
3127 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3128 BPF_ALU64_REG(BPF_DIV, R0, R1),
3129 BPF_EXIT_INSN(),
3130 },
3131 INTERNAL,
3132 { },
3133 { { 0, 1 } },
3134 },
3135 {
3136 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3137 .u.insns_int = {
3138 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3139 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3140 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3141 BPF_ALU64_REG(BPF_DIV, R2, R4),
3142 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3143 BPF_MOV32_IMM(R0, 2),
3144 BPF_EXIT_INSN(),
3145 BPF_MOV32_IMM(R0, 1),
3146 BPF_EXIT_INSN(),
3147 },
3148 INTERNAL,
3149 { },
3150 { { 0, 0x1 } },
3151 },
3152 /* BPF_ALU | BPF_DIV | BPF_K */
3153 {
3154 "ALU_DIV_K: 6 / 2 = 3",
3155 .u.insns_int = {
3156 BPF_LD_IMM64(R0, 6),
3157 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3158 BPF_EXIT_INSN(),
3159 },
3160 INTERNAL,
3161 { },
3162 { { 0, 3 } },
3163 },
3164 {
3165 "ALU_DIV_K: 3 / 1 = 3",
3166 .u.insns_int = {
3167 BPF_LD_IMM64(R0, 3),
3168 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3169 BPF_EXIT_INSN(),
3170 },
3171 INTERNAL,
3172 { },
3173 { { 0, 3 } },
3174 },
3175 {
3176 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3177 .u.insns_int = {
3178 BPF_LD_IMM64(R0, 4294967295U),
3179 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
3180 BPF_EXIT_INSN(),
3181 },
3182 INTERNAL,
3183 { },
3184 { { 0, 1 } },
3185 },
3186 {
3187 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3188 .u.insns_int = {
3189 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3190 BPF_LD_IMM64(R3, 0x1UL),
3191 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3192 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3193 BPF_MOV32_IMM(R0, 2),
3194 BPF_EXIT_INSN(),
3195 BPF_MOV32_IMM(R0, 1),
3196 BPF_EXIT_INSN(),
3197 },
3198 INTERNAL,
3199 { },
3200 { { 0, 0x1 } },
3201 },
3202 {
3203 "ALU64_DIV_K: 6 / 2 = 3",
3204 .u.insns_int = {
3205 BPF_LD_IMM64(R0, 6),
3206 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3207 BPF_EXIT_INSN(),
3208 },
3209 INTERNAL,
3210 { },
3211 { { 0, 3 } },
3212 },
3213 {
3214 "ALU64_DIV_K: 3 / 1 = 3",
3215 .u.insns_int = {
3216 BPF_LD_IMM64(R0, 3),
3217 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3218 BPF_EXIT_INSN(),
3219 },
3220 INTERNAL,
3221 { },
3222 { { 0, 3 } },
3223 },
3224 {
3225 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3226 .u.insns_int = {
3227 BPF_LD_IMM64(R0, 2147483647),
3228 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3229 BPF_EXIT_INSN(),
3230 },
3231 INTERNAL,
3232 { },
3233 { { 0, 1 } },
3234 },
3235 {
3236 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3237 .u.insns_int = {
3238 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3239 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3240 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3241 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3242 BPF_MOV32_IMM(R0, 2),
3243 BPF_EXIT_INSN(),
3244 BPF_MOV32_IMM(R0, 1),
3245 BPF_EXIT_INSN(),
3246 },
3247 INTERNAL,
3248 { },
3249 { { 0, 0x1 } },
3250 },
3251 /* BPF_ALU | BPF_MOD | BPF_X */
3252 {
3253 "ALU_MOD_X: 3 % 2 = 1",
3254 .u.insns_int = {
3255 BPF_LD_IMM64(R0, 3),
3256 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3257 BPF_ALU32_REG(BPF_MOD, R0, R1),
3258 BPF_EXIT_INSN(),
3259 },
3260 INTERNAL,
3261 { },
3262 { { 0, 1 } },
3263 },
3264 {
3265 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3266 .u.insns_int = {
3267 BPF_LD_IMM64(R0, 4294967295U),
3268 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
3269 BPF_ALU32_REG(BPF_MOD, R0, R1),
3270 BPF_EXIT_INSN(),
3271 },
3272 INTERNAL,
3273 { },
3274 { { 0, 2 } },
3275 },
3276 {
3277 "ALU64_MOD_X: 3 % 2 = 1",
3278 .u.insns_int = {
3279 BPF_LD_IMM64(R0, 3),
3280 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3281 BPF_ALU64_REG(BPF_MOD, R0, R1),
3282 BPF_EXIT_INSN(),
3283 },
3284 INTERNAL,
3285 { },
3286 { { 0, 1 } },
3287 },
3288 {
3289 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3290 .u.insns_int = {
3291 BPF_LD_IMM64(R0, 2147483647),
3292 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3293 BPF_ALU64_REG(BPF_MOD, R0, R1),
3294 BPF_EXIT_INSN(),
3295 },
3296 INTERNAL,
3297 { },
3298 { { 0, 2 } },
3299 },
3300 /* BPF_ALU | BPF_MOD | BPF_K */
3301 {
3302 "ALU_MOD_K: 3 % 2 = 1",
3303 .u.insns_int = {
3304 BPF_LD_IMM64(R0, 3),
3305 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3306 BPF_EXIT_INSN(),
3307 },
3308 INTERNAL,
3309 { },
3310 { { 0, 1 } },
3311 },
3312 {
3313 "ALU_MOD_K: 3 % 1 = 0",
3314 .u.insns_int = {
3315 BPF_LD_IMM64(R0, 3),
3316 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3317 BPF_EXIT_INSN(),
3318 },
3319 INTERNAL,
3320 { },
3321 { { 0, 0 } },
3322 },
3323 {
3324 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3325 .u.insns_int = {
3326 BPF_LD_IMM64(R0, 4294967295U),
3327 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
3328 BPF_EXIT_INSN(),
3329 },
3330 INTERNAL,
3331 { },
3332 { { 0, 2 } },
3333 },
3334 {
3335 "ALU64_MOD_K: 3 % 2 = 1",
3336 .u.insns_int = {
3337 BPF_LD_IMM64(R0, 3),
3338 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3339 BPF_EXIT_INSN(),
3340 },
3341 INTERNAL,
3342 { },
3343 { { 0, 1 } },
3344 },
3345 {
3346 "ALU64_MOD_K: 3 % 1 = 0",
3347 .u.insns_int = {
3348 BPF_LD_IMM64(R0, 3),
3349 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3350 BPF_EXIT_INSN(),
3351 },
3352 INTERNAL,
3353 { },
3354 { { 0, 0 } },
3355 },
3356 {
3357 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3358 .u.insns_int = {
3359 BPF_LD_IMM64(R0, 2147483647),
3360 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3361 BPF_EXIT_INSN(),
3362 },
3363 INTERNAL,
3364 { },
3365 { { 0, 2 } },
3366 },
3367 /* BPF_ALU | BPF_AND | BPF_X */
3368 {
3369 "ALU_AND_X: 3 & 2 = 2",
3370 .u.insns_int = {
3371 BPF_LD_IMM64(R0, 3),
3372 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3373 BPF_ALU32_REG(BPF_AND, R0, R1),
3374 BPF_EXIT_INSN(),
3375 },
3376 INTERNAL,
3377 { },
3378 { { 0, 2 } },
3379 },
3380 {
3381 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3382 .u.insns_int = {
3383 BPF_LD_IMM64(R0, 0xffffffff),
3384 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3385 BPF_ALU32_REG(BPF_AND, R0, R1),
3386 BPF_EXIT_INSN(),
3387 },
3388 INTERNAL,
3389 { },
3390 { { 0, 0xffffffff } },
3391 },
3392 {
3393 "ALU64_AND_X: 3 & 2 = 2",
3394 .u.insns_int = {
3395 BPF_LD_IMM64(R0, 3),
3396 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3397 BPF_ALU64_REG(BPF_AND, R0, R1),
3398 BPF_EXIT_INSN(),
3399 },
3400 INTERNAL,
3401 { },
3402 { { 0, 2 } },
3403 },
3404 {
3405 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3406 .u.insns_int = {
3407 BPF_LD_IMM64(R0, 0xffffffff),
3408 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3409 BPF_ALU64_REG(BPF_AND, R0, R1),
3410 BPF_EXIT_INSN(),
3411 },
3412 INTERNAL,
3413 { },
3414 { { 0, 0xffffffff } },
3415 },
3416 /* BPF_ALU | BPF_AND | BPF_K */
3417 {
3418 "ALU_AND_K: 3 & 2 = 2",
3419 .u.insns_int = {
3420 BPF_LD_IMM64(R0, 3),
3421 BPF_ALU32_IMM(BPF_AND, R0, 2),
3422 BPF_EXIT_INSN(),
3423 },
3424 INTERNAL,
3425 { },
3426 { { 0, 2 } },
3427 },
3428 {
3429 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3430 .u.insns_int = {
3431 BPF_LD_IMM64(R0, 0xffffffff),
3432 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3433 BPF_EXIT_INSN(),
3434 },
3435 INTERNAL,
3436 { },
3437 { { 0, 0xffffffff } },
3438 },
3439 {
3440 "ALU64_AND_K: 3 & 2 = 2",
3441 .u.insns_int = {
3442 BPF_LD_IMM64(R0, 3),
3443 BPF_ALU64_IMM(BPF_AND, R0, 2),
3444 BPF_EXIT_INSN(),
3445 },
3446 INTERNAL,
3447 { },
3448 { { 0, 2 } },
3449 },
3450 {
3451 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3452 .u.insns_int = {
3453 BPF_LD_IMM64(R0, 0xffffffff),
3454 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3455 BPF_EXIT_INSN(),
3456 },
3457 INTERNAL,
3458 { },
3459 { { 0, 0xffffffff } },
3460 },
3461 {
3462 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3463 .u.insns_int = {
3464 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3465 BPF_LD_IMM64(R3, 0x0000000000000000LL),
3466 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3467 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3468 BPF_MOV32_IMM(R0, 2),
3469 BPF_EXIT_INSN(),
3470 BPF_MOV32_IMM(R0, 1),
3471 BPF_EXIT_INSN(),
3472 },
3473 INTERNAL,
3474 { },
3475 { { 0, 0x1 } },
3476 },
3477 {
3478 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3479 .u.insns_int = {
3480 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3481 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3482 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3483 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3484 BPF_MOV32_IMM(R0, 2),
3485 BPF_EXIT_INSN(),
3486 BPF_MOV32_IMM(R0, 1),
3487 BPF_EXIT_INSN(),
3488 },
3489 INTERNAL,
3490 { },
3491 { { 0, 0x1 } },
3492 },
3493 {
3494 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3495 .u.insns_int = {
3496 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3497 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3498 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3499 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3500 BPF_MOV32_IMM(R0, 2),
3501 BPF_EXIT_INSN(),
3502 BPF_MOV32_IMM(R0, 1),
3503 BPF_EXIT_INSN(),
3504 },
3505 INTERNAL,
3506 { },
3507 { { 0, 0x1 } },
3508 },
3509 /* BPF_ALU | BPF_OR | BPF_X */
3510 {
3511 "ALU_OR_X: 1 | 2 = 3",
3512 .u.insns_int = {
3513 BPF_LD_IMM64(R0, 1),
3514 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3515 BPF_ALU32_REG(BPF_OR, R0, R1),
3516 BPF_EXIT_INSN(),
3517 },
3518 INTERNAL,
3519 { },
3520 { { 0, 3 } },
3521 },
3522 {
3523 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3524 .u.insns_int = {
3525 BPF_LD_IMM64(R0, 0),
3526 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3527 BPF_ALU32_REG(BPF_OR, R0, R1),
3528 BPF_EXIT_INSN(),
3529 },
3530 INTERNAL,
3531 { },
3532 { { 0, 0xffffffff } },
3533 },
3534 {
3535 "ALU64_OR_X: 1 | 2 = 3",
3536 .u.insns_int = {
3537 BPF_LD_IMM64(R0, 1),
3538 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3539 BPF_ALU64_REG(BPF_OR, R0, R1),
3540 BPF_EXIT_INSN(),
3541 },
3542 INTERNAL,
3543 { },
3544 { { 0, 3 } },
3545 },
3546 {
3547 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3548 .u.insns_int = {
3549 BPF_LD_IMM64(R0, 0),
3550 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3551 BPF_ALU64_REG(BPF_OR, R0, R1),
3552 BPF_EXIT_INSN(),
3553 },
3554 INTERNAL,
3555 { },
3556 { { 0, 0xffffffff } },
3557 },
3558 /* BPF_ALU | BPF_OR | BPF_K */
3559 {
3560 "ALU_OR_K: 1 | 2 = 3",
3561 .u.insns_int = {
3562 BPF_LD_IMM64(R0, 1),
3563 BPF_ALU32_IMM(BPF_OR, R0, 2),
3564 BPF_EXIT_INSN(),
3565 },
3566 INTERNAL,
3567 { },
3568 { { 0, 3 } },
3569 },
3570 {
3571 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3572 .u.insns_int = {
3573 BPF_LD_IMM64(R0, 0),
3574 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3575 BPF_EXIT_INSN(),
3576 },
3577 INTERNAL,
3578 { },
3579 { { 0, 0xffffffff } },
3580 },
3581 {
3582 "ALU64_OR_K: 1 | 2 = 3",
3583 .u.insns_int = {
3584 BPF_LD_IMM64(R0, 1),
3585 BPF_ALU64_IMM(BPF_OR, R0, 2),
3586 BPF_EXIT_INSN(),
3587 },
3588 INTERNAL,
3589 { },
3590 { { 0, 3 } },
3591 },
3592 {
3593 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3594 .u.insns_int = {
3595 BPF_LD_IMM64(R0, 0),
3596 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3597 BPF_EXIT_INSN(),
3598 },
3599 INTERNAL,
3600 { },
3601 { { 0, 0xffffffff } },
3602 },
3603 {
3604 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3605 .u.insns_int = {
3606 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3607 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3608 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3609 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3610 BPF_MOV32_IMM(R0, 2),
3611 BPF_EXIT_INSN(),
3612 BPF_MOV32_IMM(R0, 1),
3613 BPF_EXIT_INSN(),
3614 },
3615 INTERNAL,
3616 { },
3617 { { 0, 0x1 } },
3618 },
3619 {
3620 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3621 .u.insns_int = {
3622 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3623 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3624 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3625 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3626 BPF_MOV32_IMM(R0, 2),
3627 BPF_EXIT_INSN(),
3628 BPF_MOV32_IMM(R0, 1),
3629 BPF_EXIT_INSN(),
3630 },
3631 INTERNAL,
3632 { },
3633 { { 0, 0x1 } },
3634 },
3635 {
3636 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3637 .u.insns_int = {
3638 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3639 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3640 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3641 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3642 BPF_MOV32_IMM(R0, 2),
3643 BPF_EXIT_INSN(),
3644 BPF_MOV32_IMM(R0, 1),
3645 BPF_EXIT_INSN(),
3646 },
3647 INTERNAL,
3648 { },
3649 { { 0, 0x1 } },
3650 },
3651 /* BPF_ALU | BPF_XOR | BPF_X */
3652 {
3653 "ALU_XOR_X: 5 ^ 6 = 3",
3654 .u.insns_int = {
3655 BPF_LD_IMM64(R0, 5),
3656 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3657 BPF_ALU32_REG(BPF_XOR, R0, R1),
3658 BPF_EXIT_INSN(),
3659 },
3660 INTERNAL,
3661 { },
3662 { { 0, 3 } },
3663 },
3664 {
3665 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3666 .u.insns_int = {
3667 BPF_LD_IMM64(R0, 1),
3668 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3669 BPF_ALU32_REG(BPF_XOR, R0, R1),
3670 BPF_EXIT_INSN(),
3671 },
3672 INTERNAL,
3673 { },
3674 { { 0, 0xfffffffe } },
3675 },
3676 {
3677 "ALU64_XOR_X: 5 ^ 6 = 3",
3678 .u.insns_int = {
3679 BPF_LD_IMM64(R0, 5),
3680 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3681 BPF_ALU64_REG(BPF_XOR, R0, R1),
3682 BPF_EXIT_INSN(),
3683 },
3684 INTERNAL,
3685 { },
3686 { { 0, 3 } },
3687 },
3688 {
3689 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3690 .u.insns_int = {
3691 BPF_LD_IMM64(R0, 1),
3692 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3693 BPF_ALU64_REG(BPF_XOR, R0, R1),
3694 BPF_EXIT_INSN(),
3695 },
3696 INTERNAL,
3697 { },
3698 { { 0, 0xfffffffe } },
3699 },
3700 /* BPF_ALU | BPF_XOR | BPF_K */
3701 {
3702 "ALU_XOR_K: 5 ^ 6 = 3",
3703 .u.insns_int = {
3704 BPF_LD_IMM64(R0, 5),
3705 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3706 BPF_EXIT_INSN(),
3707 },
3708 INTERNAL,
3709 { },
3710 { { 0, 3 } },
3711 },
3712 {
3713 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3714 .u.insns_int = {
3715 BPF_LD_IMM64(R0, 1),
3716 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3717 BPF_EXIT_INSN(),
3718 },
3719 INTERNAL,
3720 { },
3721 { { 0, 0xfffffffe } },
3722 },
3723 {
3724 "ALU64_XOR_K: 5 ^ 6 = 3",
3725 .u.insns_int = {
3726 BPF_LD_IMM64(R0, 5),
3727 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3728 BPF_EXIT_INSN(),
3729 },
3730 INTERNAL,
3731 { },
3732 { { 0, 3 } },
3733 },
3734 {
3735 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3736 .u.insns_int = {
3737 BPF_LD_IMM64(R0, 1),
3738 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3739 BPF_EXIT_INSN(),
3740 },
3741 INTERNAL,
3742 { },
3743 { { 0, 0xfffffffe } },
3744 },
3745 {
3746 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3747 .u.insns_int = {
3748 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3749 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3750 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3751 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3752 BPF_MOV32_IMM(R0, 2),
3753 BPF_EXIT_INSN(),
3754 BPF_MOV32_IMM(R0, 1),
3755 BPF_EXIT_INSN(),
3756 },
3757 INTERNAL,
3758 { },
3759 { { 0, 0x1 } },
3760 },
3761 {
3762 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3763 .u.insns_int = {
3764 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3765 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
3766 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3767 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3768 BPF_MOV32_IMM(R0, 2),
3769 BPF_EXIT_INSN(),
3770 BPF_MOV32_IMM(R0, 1),
3771 BPF_EXIT_INSN(),
3772 },
3773 INTERNAL,
3774 { },
3775 { { 0, 0x1 } },
3776 },
3777 {
3778 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3779 .u.insns_int = {
3780 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3781 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3782 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3783 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3784 BPF_MOV32_IMM(R0, 2),
3785 BPF_EXIT_INSN(),
3786 BPF_MOV32_IMM(R0, 1),
3787 BPF_EXIT_INSN(),
3788 },
3789 INTERNAL,
3790 { },
3791 { { 0, 0x1 } },
3792 },
3793 /* BPF_ALU | BPF_LSH | BPF_X */
3794 {
3795 "ALU_LSH_X: 1 << 1 = 2",
3796 .u.insns_int = {
3797 BPF_LD_IMM64(R0, 1),
3798 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3799 BPF_ALU32_REG(BPF_LSH, R0, R1),
3800 BPF_EXIT_INSN(),
3801 },
3802 INTERNAL,
3803 { },
3804 { { 0, 2 } },
3805 },
3806 {
3807 "ALU_LSH_X: 1 << 31 = 0x80000000",
3808 .u.insns_int = {
3809 BPF_LD_IMM64(R0, 1),
3810 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3811 BPF_ALU32_REG(BPF_LSH, R0, R1),
3812 BPF_EXIT_INSN(),
3813 },
3814 INTERNAL,
3815 { },
3816 { { 0, 0x80000000 } },
3817 },
3818 {
3819 "ALU64_LSH_X: 1 << 1 = 2",
3820 .u.insns_int = {
3821 BPF_LD_IMM64(R0, 1),
3822 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3823 BPF_ALU64_REG(BPF_LSH, R0, R1),
3824 BPF_EXIT_INSN(),
3825 },
3826 INTERNAL,
3827 { },
3828 { { 0, 2 } },
3829 },
3830 {
3831 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3832 .u.insns_int = {
3833 BPF_LD_IMM64(R0, 1),
3834 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3835 BPF_ALU64_REG(BPF_LSH, R0, R1),
3836 BPF_EXIT_INSN(),
3837 },
3838 INTERNAL,
3839 { },
3840 { { 0, 0x80000000 } },
3841 },
3842 /* BPF_ALU | BPF_LSH | BPF_K */
3843 {
3844 "ALU_LSH_K: 1 << 1 = 2",
3845 .u.insns_int = {
3846 BPF_LD_IMM64(R0, 1),
3847 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3848 BPF_EXIT_INSN(),
3849 },
3850 INTERNAL,
3851 { },
3852 { { 0, 2 } },
3853 },
3854 {
3855 "ALU_LSH_K: 1 << 31 = 0x80000000",
3856 .u.insns_int = {
3857 BPF_LD_IMM64(R0, 1),
3858 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3859 BPF_EXIT_INSN(),
3860 },
3861 INTERNAL,
3862 { },
3863 { { 0, 0x80000000 } },
3864 },
3865 {
3866 "ALU64_LSH_K: 1 << 1 = 2",
3867 .u.insns_int = {
3868 BPF_LD_IMM64(R0, 1),
3869 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3870 BPF_EXIT_INSN(),
3871 },
3872 INTERNAL,
3873 { },
3874 { { 0, 2 } },
3875 },
3876 {
3877 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3878 .u.insns_int = {
3879 BPF_LD_IMM64(R0, 1),
3880 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3881 BPF_EXIT_INSN(),
3882 },
3883 INTERNAL,
3884 { },
3885 { { 0, 0x80000000 } },
3886 },
3887 /* BPF_ALU | BPF_RSH | BPF_X */
3888 {
3889 "ALU_RSH_X: 2 >> 1 = 1",
3890 .u.insns_int = {
3891 BPF_LD_IMM64(R0, 2),
3892 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3893 BPF_ALU32_REG(BPF_RSH, R0, R1),
3894 BPF_EXIT_INSN(),
3895 },
3896 INTERNAL,
3897 { },
3898 { { 0, 1 } },
3899 },
3900 {
3901 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3902 .u.insns_int = {
3903 BPF_LD_IMM64(R0, 0x80000000),
3904 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3905 BPF_ALU32_REG(BPF_RSH, R0, R1),
3906 BPF_EXIT_INSN(),
3907 },
3908 INTERNAL,
3909 { },
3910 { { 0, 1 } },
3911 },
3912 {
3913 "ALU64_RSH_X: 2 >> 1 = 1",
3914 .u.insns_int = {
3915 BPF_LD_IMM64(R0, 2),
3916 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3917 BPF_ALU64_REG(BPF_RSH, R0, R1),
3918 BPF_EXIT_INSN(),
3919 },
3920 INTERNAL,
3921 { },
3922 { { 0, 1 } },
3923 },
3924 {
3925 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3926 .u.insns_int = {
3927 BPF_LD_IMM64(R0, 0x80000000),
3928 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3929 BPF_ALU64_REG(BPF_RSH, R0, R1),
3930 BPF_EXIT_INSN(),
3931 },
3932 INTERNAL,
3933 { },
3934 { { 0, 1 } },
3935 },
3936 /* BPF_ALU | BPF_RSH | BPF_K */
3937 {
3938 "ALU_RSH_K: 2 >> 1 = 1",
3939 .u.insns_int = {
3940 BPF_LD_IMM64(R0, 2),
3941 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3942 BPF_EXIT_INSN(),
3943 },
3944 INTERNAL,
3945 { },
3946 { { 0, 1 } },
3947 },
3948 {
3949 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3950 .u.insns_int = {
3951 BPF_LD_IMM64(R0, 0x80000000),
3952 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3953 BPF_EXIT_INSN(),
3954 },
3955 INTERNAL,
3956 { },
3957 { { 0, 1 } },
3958 },
3959 {
3960 "ALU64_RSH_K: 2 >> 1 = 1",
3961 .u.insns_int = {
3962 BPF_LD_IMM64(R0, 2),
3963 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3964 BPF_EXIT_INSN(),
3965 },
3966 INTERNAL,
3967 { },
3968 { { 0, 1 } },
3969 },
3970 {
3971 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3972 .u.insns_int = {
3973 BPF_LD_IMM64(R0, 0x80000000),
3974 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3975 BPF_EXIT_INSN(),
3976 },
3977 INTERNAL,
3978 { },
3979 { { 0, 1 } },
3980 },
3981 /* BPF_ALU | BPF_ARSH | BPF_X */
3982 {
3983 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3984 .u.insns_int = {
3985 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3986 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3987 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3988 BPF_EXIT_INSN(),
3989 },
3990 INTERNAL,
3991 { },
3992 { { 0, 0xffff00ff } },
3993 },
3994 /* BPF_ALU | BPF_ARSH | BPF_K */
3995 {
3996 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3997 .u.insns_int = {
3998 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3999 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
4000 BPF_EXIT_INSN(),
4001 },
4002 INTERNAL,
4003 { },
4004 { { 0, 0xffff00ff } },
4005 },
4006 /* BPF_ALU | BPF_NEG */
4007 {
4008 "ALU_NEG: -(3) = -3",
4009 .u.insns_int = {
4010 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4011 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4012 BPF_EXIT_INSN(),
4013 },
4014 INTERNAL,
4015 { },
4016 { { 0, -3 } },
4017 },
4018 {
4019 "ALU_NEG: -(-3) = 3",
4020 .u.insns_int = {
4021 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4022 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4023 BPF_EXIT_INSN(),
4024 },
4025 INTERNAL,
4026 { },
4027 { { 0, 3 } },
4028 },
4029 {
4030 "ALU64_NEG: -(3) = -3",
4031 .u.insns_int = {
4032 BPF_LD_IMM64(R0, 3),
4033 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4034 BPF_EXIT_INSN(),
4035 },
4036 INTERNAL,
4037 { },
4038 { { 0, -3 } },
4039 },
4040 {
4041 "ALU64_NEG: -(-3) = 3",
4042 .u.insns_int = {
4043 BPF_LD_IMM64(R0, -3),
4044 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4045 BPF_EXIT_INSN(),
4046 },
4047 INTERNAL,
4048 { },
4049 { { 0, 3 } },
4050 },
4051 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4052 {
4053 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4054 .u.insns_int = {
4055 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4056 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4057 BPF_EXIT_INSN(),
4058 },
4059 INTERNAL,
4060 { },
4061 { { 0, cpu_to_be16(0xcdef) } },
4062 },
4063 {
4064 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4065 .u.insns_int = {
4066 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4067 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
4068 BPF_ALU64_REG(BPF_MOV, R1, R0),
4069 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4070 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
4071 BPF_EXIT_INSN(),
4072 },
4073 INTERNAL,
4074 { },
4075 { { 0, cpu_to_be32(0x89abcdef) } },
4076 },
4077 {
4078 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4079 .u.insns_int = {
4080 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4081 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4082 BPF_EXIT_INSN(),
4083 },
4084 INTERNAL,
4085 { },
4086 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4087 },
4088 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4089 {
4090 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4091 .u.insns_int = {
4092 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4093 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4094 BPF_EXIT_INSN(),
4095 },
4096 INTERNAL,
4097 { },
4098 { { 0, cpu_to_le16(0xcdef) } },
4099 },
4100 {
4101 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4102 .u.insns_int = {
4103 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4104 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
4105 BPF_ALU64_REG(BPF_MOV, R1, R0),
4106 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4107 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
4108 BPF_EXIT_INSN(),
4109 },
4110 INTERNAL,
4111 { },
4112 { { 0, cpu_to_le32(0x89abcdef) } },
4113 },
4114 {
4115 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4116 .u.insns_int = {
4117 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4118 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4119 BPF_EXIT_INSN(),
4120 },
4121 INTERNAL,
4122 { },
4123 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4124 },
4125 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4126 {
4127 "ST_MEM_B: Store/Load byte: max negative",
4128 .u.insns_int = {
4129 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4130 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4131 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4132 BPF_EXIT_INSN(),
4133 },
4134 INTERNAL,
4135 { },
4136 { { 0, 0xff } },
4137 },
4138 {
4139 "ST_MEM_B: Store/Load byte: max positive",
4140 .u.insns_int = {
4141 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4142 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4143 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4144 BPF_EXIT_INSN(),
4145 },
4146 INTERNAL,
4147 { },
4148 { { 0, 0x7f } },
4149 },
4150 {
4151 "STX_MEM_B: Store/Load byte: max negative",
4152 .u.insns_int = {
4153 BPF_LD_IMM64(R0, 0),
4154 BPF_LD_IMM64(R1, 0xffLL),
4155 BPF_STX_MEM(BPF_B, R10, R1, -40),
4156 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4157 BPF_EXIT_INSN(),
4158 },
4159 INTERNAL,
4160 { },
4161 { { 0, 0xff } },
4162 },
4163 {
4164 "ST_MEM_H: Store/Load half word: max negative",
4165 .u.insns_int = {
4166 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4167 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4168 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4169 BPF_EXIT_INSN(),
4170 },
4171 INTERNAL,
4172 { },
4173 { { 0, 0xffff } },
4174 },
4175 {
4176 "ST_MEM_H: Store/Load half word: max positive",
4177 .u.insns_int = {
4178 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4179 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4180 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4181 BPF_EXIT_INSN(),
4182 },
4183 INTERNAL,
4184 { },
4185 { { 0, 0x7fff } },
4186 },
4187 {
4188 "STX_MEM_H: Store/Load half word: max negative",
4189 .u.insns_int = {
4190 BPF_LD_IMM64(R0, 0),
4191 BPF_LD_IMM64(R1, 0xffffLL),
4192 BPF_STX_MEM(BPF_H, R10, R1, -40),
4193 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4194 BPF_EXIT_INSN(),
4195 },
4196 INTERNAL,
4197 { },
4198 { { 0, 0xffff } },
4199 },
4200 {
4201 "ST_MEM_W: Store/Load word: max negative",
4202 .u.insns_int = {
4203 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4204 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4205 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4206 BPF_EXIT_INSN(),
4207 },
4208 INTERNAL,
4209 { },
4210 { { 0, 0xffffffff } },
4211 },
4212 {
4213 "ST_MEM_W: Store/Load word: max positive",
4214 .u.insns_int = {
4215 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4216 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4217 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4218 BPF_EXIT_INSN(),
4219 },
4220 INTERNAL,
4221 { },
4222 { { 0, 0x7fffffff } },
4223 },
4224 {
4225 "STX_MEM_W: Store/Load word: max negative",
4226 .u.insns_int = {
4227 BPF_LD_IMM64(R0, 0),
4228 BPF_LD_IMM64(R1, 0xffffffffLL),
4229 BPF_STX_MEM(BPF_W, R10, R1, -40),
4230 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4231 BPF_EXIT_INSN(),
4232 },
4233 INTERNAL,
4234 { },
4235 { { 0, 0xffffffff } },
4236 },
4237 {
4238 "ST_MEM_DW: Store/Load double word: max negative",
4239 .u.insns_int = {
4240 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4241 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4242 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4243 BPF_EXIT_INSN(),
4244 },
4245 INTERNAL,
4246 { },
4247 { { 0, 0xffffffff } },
4248 },
4249 {
4250 "ST_MEM_DW: Store/Load double word: max negative 2",
4251 .u.insns_int = {
4252 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4253 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
4254 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4255 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4256 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4257 BPF_MOV32_IMM(R0, 2),
4258 BPF_EXIT_INSN(),
4259 BPF_MOV32_IMM(R0, 1),
4260 BPF_EXIT_INSN(),
4261 },
4262 INTERNAL,
4263 { },
4264 { { 0, 0x1 } },
4265 },
4266 {
4267 "ST_MEM_DW: Store/Load double word: max positive",
4268 .u.insns_int = {
4269 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4270 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4271 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4272 BPF_EXIT_INSN(),
4273 },
4274 INTERNAL,
4275 { },
4276 { { 0, 0x7fffffff } },
4277 },
4278 {
4279 "STX_MEM_DW: Store/Load double word: max negative",
4280 .u.insns_int = {
4281 BPF_LD_IMM64(R0, 0),
4282 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4283 BPF_STX_MEM(BPF_W, R10, R1, -40),
4284 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4285 BPF_EXIT_INSN(),
4286 },
4287 INTERNAL,
4288 { },
4289 { { 0, 0xffffffff } },
4290 },
4291 /* BPF_STX | BPF_XADD | BPF_W/DW */
4292 {
4293 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4294 .u.insns_int = {
4295 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4296 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4297 BPF_STX_XADD(BPF_W, R10, R0, -40),
4298 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4299 BPF_EXIT_INSN(),
4300 },
4301 INTERNAL,
4302 { },
4303 { { 0, 0x22 } },
4304 },
4305 {
4306 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4307 .u.insns_int = {
4308 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4309 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4310 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4311 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4312 BPF_EXIT_INSN(),
4313 },
4314 INTERNAL,
4315 { },
4316 { { 0, 0x22 } },
4317 },
4318 /* BPF_JMP | BPF_EXIT */
4319 {
4320 "JMP_EXIT",
4321 .u.insns_int = {
4322 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4323 BPF_EXIT_INSN(),
4324 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4325 },
4326 INTERNAL,
4327 { },
4328 { { 0, 0x4711 } },
4329 },
4330 /* BPF_JMP | BPF_JA */
4331 {
4332 "JMP_JA: Unconditional jump: if (true) return 1",
4333 .u.insns_int = {
4334 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4335 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4336 BPF_EXIT_INSN(),
4337 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4338 BPF_EXIT_INSN(),
4339 },
4340 INTERNAL,
4341 { },
4342 { { 0, 1 } },
4343 },
4344 /* BPF_JMP | BPF_JSGT | BPF_K */
4345 {
4346 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4347 .u.insns_int = {
4348 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4349 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4350 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4351 BPF_EXIT_INSN(),
4352 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4353 BPF_EXIT_INSN(),
4354 },
4355 INTERNAL,
4356 { },
4357 { { 0, 1 } },
4358 },
4359 {
4360 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4361 .u.insns_int = {
4362 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4363 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4364 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4365 BPF_EXIT_INSN(),
4366 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4367 BPF_EXIT_INSN(),
4368 },
4369 INTERNAL,
4370 { },
4371 { { 0, 1 } },
4372 },
4373 /* BPF_JMP | BPF_JSGE | BPF_K */
4374 {
4375 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4376 .u.insns_int = {
4377 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4378 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4379 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4380 BPF_EXIT_INSN(),
4381 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4382 BPF_EXIT_INSN(),
4383 },
4384 INTERNAL,
4385 { },
4386 { { 0, 1 } },
4387 },
4388 {
4389 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4390 .u.insns_int = {
4391 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4392 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4393 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4394 BPF_EXIT_INSN(),
4395 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4396 BPF_EXIT_INSN(),
4397 },
4398 INTERNAL,
4399 { },
4400 { { 0, 1 } },
4401 },
4402 /* BPF_JMP | BPF_JGT | BPF_K */
4403 {
4404 "JMP_JGT_K: if (3 > 2) return 1",
4405 .u.insns_int = {
4406 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4407 BPF_LD_IMM64(R1, 3),
4408 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4409 BPF_EXIT_INSN(),
4410 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4411 BPF_EXIT_INSN(),
4412 },
4413 INTERNAL,
4414 { },
4415 { { 0, 1 } },
4416 },
4417 {
4418 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4419 .u.insns_int = {
4420 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4421 BPF_LD_IMM64(R1, -1),
4422 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
4423 BPF_EXIT_INSN(),
4424 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4425 BPF_EXIT_INSN(),
4426 },
4427 INTERNAL,
4428 { },
4429 { { 0, 1 } },
4430 },
4431 /* BPF_JMP | BPF_JGE | BPF_K */
4432 {
4433 "JMP_JGE_K: if (3 >= 2) return 1",
4434 .u.insns_int = {
4435 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4436 BPF_LD_IMM64(R1, 3),
4437 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4438 BPF_EXIT_INSN(),
4439 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4440 BPF_EXIT_INSN(),
4441 },
4442 INTERNAL,
4443 { },
4444 { { 0, 1 } },
4445 },
4446 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4447 {
4448 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4449 .u.insns_int = {
4450 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4451 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4452 BPF_EXIT_INSN(),
4453 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4454 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4455 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4456 BPF_EXIT_INSN(),
4457 },
4458 INTERNAL,
4459 { },
4460 { { 0, 1 } },
4461 },
4462 {
4463 "JMP_JGE_K: if (3 >= 3) return 1",
4464 .u.insns_int = {
4465 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4466 BPF_LD_IMM64(R1, 3),
4467 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4468 BPF_EXIT_INSN(),
4469 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4470 BPF_EXIT_INSN(),
4471 },
4472 INTERNAL,
4473 { },
4474 { { 0, 1 } },
4475 },
4476 /* BPF_JMP | BPF_JNE | BPF_K */
4477 {
4478 "JMP_JNE_K: if (3 != 2) return 1",
4479 .u.insns_int = {
4480 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4481 BPF_LD_IMM64(R1, 3),
4482 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4483 BPF_EXIT_INSN(),
4484 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4485 BPF_EXIT_INSN(),
4486 },
4487 INTERNAL,
4488 { },
4489 { { 0, 1 } },
4490 },
4491 /* BPF_JMP | BPF_JEQ | BPF_K */
4492 {
4493 "JMP_JEQ_K: if (3 == 3) return 1",
4494 .u.insns_int = {
4495 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4496 BPF_LD_IMM64(R1, 3),
4497 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4498 BPF_EXIT_INSN(),
4499 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4500 BPF_EXIT_INSN(),
4501 },
4502 INTERNAL,
4503 { },
4504 { { 0, 1 } },
4505 },
4506 /* BPF_JMP | BPF_JSET | BPF_K */
4507 {
4508 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4509 .u.insns_int = {
4510 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4511 BPF_LD_IMM64(R1, 3),
4512 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
4513 BPF_EXIT_INSN(),
4514 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4515 BPF_EXIT_INSN(),
4516 },
4517 INTERNAL,
4518 { },
4519 { { 0, 1 } },
4520 },
4521 {
4522 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4523 .u.insns_int = {
4524 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4525 BPF_LD_IMM64(R1, 3),
4526 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
4527 BPF_EXIT_INSN(),
4528 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4529 BPF_EXIT_INSN(),
4530 },
4531 INTERNAL,
4532 { },
4533 { { 0, 1 } },
4534 },
4535 /* BPF_JMP | BPF_JSGT | BPF_X */
4536 {
4537 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4538 .u.insns_int = {
4539 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4540 BPF_LD_IMM64(R1, -1),
4541 BPF_LD_IMM64(R2, -2),
4542 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4543 BPF_EXIT_INSN(),
4544 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4545 BPF_EXIT_INSN(),
4546 },
4547 INTERNAL,
4548 { },
4549 { { 0, 1 } },
4550 },
4551 {
4552 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4553 .u.insns_int = {
4554 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4555 BPF_LD_IMM64(R1, -1),
4556 BPF_LD_IMM64(R2, -1),
4557 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4558 BPF_EXIT_INSN(),
4559 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4560 BPF_EXIT_INSN(),
4561 },
4562 INTERNAL,
4563 { },
4564 { { 0, 1 } },
4565 },
4566 /* BPF_JMP | BPF_JSGE | BPF_X */
4567 {
4568 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4569 .u.insns_int = {
4570 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4571 BPF_LD_IMM64(R1, -1),
4572 BPF_LD_IMM64(R2, -2),
4573 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4574 BPF_EXIT_INSN(),
4575 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4576 BPF_EXIT_INSN(),
4577 },
4578 INTERNAL,
4579 { },
4580 { { 0, 1 } },
4581 },
4582 {
4583 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4584 .u.insns_int = {
4585 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4586 BPF_LD_IMM64(R1, -1),
4587 BPF_LD_IMM64(R2, -1),
4588 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4589 BPF_EXIT_INSN(),
4590 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4591 BPF_EXIT_INSN(),
4592 },
4593 INTERNAL,
4594 { },
4595 { { 0, 1 } },
4596 },
4597 /* BPF_JMP | BPF_JGT | BPF_X */
4598 {
4599 "JMP_JGT_X: if (3 > 2) return 1",
4600 .u.insns_int = {
4601 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4602 BPF_LD_IMM64(R1, 3),
4603 BPF_LD_IMM64(R2, 2),
4604 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4605 BPF_EXIT_INSN(),
4606 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4607 BPF_EXIT_INSN(),
4608 },
4609 INTERNAL,
4610 { },
4611 { { 0, 1 } },
4612 },
4613 {
4614 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
4615 .u.insns_int = {
4616 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4617 BPF_LD_IMM64(R1, -1),
4618 BPF_LD_IMM64(R2, 1),
4619 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4620 BPF_EXIT_INSN(),
4621 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4622 BPF_EXIT_INSN(),
4623 },
4624 INTERNAL,
4625 { },
4626 { { 0, 1 } },
4627 },
4628 /* BPF_JMP | BPF_JGE | BPF_X */
4629 {
4630 "JMP_JGE_X: if (3 >= 2) return 1",
4631 .u.insns_int = {
4632 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4633 BPF_LD_IMM64(R1, 3),
4634 BPF_LD_IMM64(R2, 2),
4635 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4636 BPF_EXIT_INSN(),
4637 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4638 BPF_EXIT_INSN(),
4639 },
4640 INTERNAL,
4641 { },
4642 { { 0, 1 } },
4643 },
4644 {
4645 "JMP_JGE_X: if (3 >= 3) return 1",
4646 .u.insns_int = {
4647 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4648 BPF_LD_IMM64(R1, 3),
4649 BPF_LD_IMM64(R2, 3),
4650 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4651 BPF_EXIT_INSN(),
4652 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4653 BPF_EXIT_INSN(),
4654 },
4655 INTERNAL,
4656 { },
4657 { { 0, 1 } },
4658 },
4659 /* BPF_JMP | BPF_JNE | BPF_X */
4660 {
4661 "JMP_JNE_X: if (3 != 2) return 1",
4662 .u.insns_int = {
4663 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4664 BPF_LD_IMM64(R1, 3),
4665 BPF_LD_IMM64(R2, 2),
4666 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4667 BPF_EXIT_INSN(),
4668 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4669 BPF_EXIT_INSN(),
4670 },
4671 INTERNAL,
4672 { },
4673 { { 0, 1 } },
4674 },
4675 /* BPF_JMP | BPF_JEQ | BPF_X */
4676 {
4677 "JMP_JEQ_X: if (3 == 3) return 1",
4678 .u.insns_int = {
4679 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4680 BPF_LD_IMM64(R1, 3),
4681 BPF_LD_IMM64(R2, 3),
4682 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4683 BPF_EXIT_INSN(),
4684 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4685 BPF_EXIT_INSN(),
4686 },
4687 INTERNAL,
4688 { },
4689 { { 0, 1 } },
4690 },
4691 /* BPF_JMP | BPF_JSET | BPF_X */
4692 {
4693 "JMP_JSET_X: if (0x3 & 0x2) return 1",
4694 .u.insns_int = {
4695 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4696 BPF_LD_IMM64(R1, 3),
4697 BPF_LD_IMM64(R2, 2),
4698 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
4699 BPF_EXIT_INSN(),
4700 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4701 BPF_EXIT_INSN(),
4702 },
4703 INTERNAL,
4704 { },
4705 { { 0, 1 } },
4706 },
4707 {
4708 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
4709 .u.insns_int = {
4710 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4711 BPF_LD_IMM64(R1, 3),
4712 BPF_LD_IMM64(R2, 0xffffffff),
4713 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
4714 BPF_EXIT_INSN(),
4715 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4716 BPF_EXIT_INSN(),
4717 },
4718 INTERNAL,
4719 { },
4720 { { 0, 1 } },
4721 },
4722 {
4723 "JMP_JA: Jump, gap, jump, ...",
4724 { },
4725 CLASSIC | FLAG_NO_DATA,
4726 { },
4727 { { 0, 0xababcbac } },
4728 .fill_helper = bpf_fill_ja,
4729 },
4730 { /* Mainly checking JIT here. */
4731 "BPF_MAXINSNS: Maximum possible literals",
4732 { },
4733 CLASSIC | FLAG_NO_DATA,
4734 { },
4735 { { 0, 0xffffffff } },
4736 .fill_helper = bpf_fill_maxinsns1,
4737 },
4738 { /* Mainly checking JIT here. */
4739 "BPF_MAXINSNS: Single literal",
4740 { },
4741 CLASSIC | FLAG_NO_DATA,
4742 { },
4743 { { 0, 0xfefefefe } },
4744 .fill_helper = bpf_fill_maxinsns2,
4745 },
4746 { /* Mainly checking JIT here. */
4747 "BPF_MAXINSNS: Run/add until end",
4748 { },
4749 CLASSIC | FLAG_NO_DATA,
4750 { },
4751 { { 0, 0x947bf368 } },
4752 .fill_helper = bpf_fill_maxinsns3,
4753 },
4754 {
4755 "BPF_MAXINSNS: Too many instructions",
4756 { },
4757 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4758 { },
4759 { },
4760 .fill_helper = bpf_fill_maxinsns4,
4761 },
4762 { /* Mainly checking JIT here. */
4763 "BPF_MAXINSNS: Very long jump",
4764 { },
4765 CLASSIC | FLAG_NO_DATA,
4766 { },
4767 { { 0, 0xabababab } },
4768 .fill_helper = bpf_fill_maxinsns5,
4769 },
4770 { /* Mainly checking JIT here. */
4771 "BPF_MAXINSNS: Ctx heavy transformations",
4772 { },
4773 CLASSIC,
4774 { },
4775 {
4776 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
4777 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
4778 },
4779 .fill_helper = bpf_fill_maxinsns6,
4780 },
4781 { /* Mainly checking JIT here. */
4782 "BPF_MAXINSNS: Call heavy transformations",
4783 { },
4784 CLASSIC | FLAG_NO_DATA,
4785 { },
4786 { { 1, 0 }, { 10, 0 } },
4787 .fill_helper = bpf_fill_maxinsns7,
4788 },
4789 { /* Mainly checking JIT here. */
4790 "BPF_MAXINSNS: Jump heavy test",
4791 { },
4792 CLASSIC | FLAG_NO_DATA,
4793 { },
4794 { { 0, 0xffffffff } },
4795 .fill_helper = bpf_fill_maxinsns8,
4796 },
4797 { /* Mainly checking JIT here. */
4798 "BPF_MAXINSNS: Very long jump backwards",
4799 { },
4800 INTERNAL | FLAG_NO_DATA,
4801 { },
4802 { { 0, 0xcbababab } },
4803 .fill_helper = bpf_fill_maxinsns9,
4804 },
4805 { /* Mainly checking JIT here. */
4806 "BPF_MAXINSNS: Edge hopping nuthouse",
4807 { },
4808 INTERNAL | FLAG_NO_DATA,
4809 { },
4810 { { 0, 0xabababac } },
4811 .fill_helper = bpf_fill_maxinsns10,
4812 },
4813 {
4814 "BPF_MAXINSNS: Jump, gap, jump, ...",
4815 { },
4816 CLASSIC | FLAG_NO_DATA,
4817 { },
4818 { { 0, 0xababcbac } },
4819 .fill_helper = bpf_fill_maxinsns11,
4820 },
4821 {
4822 "BPF_MAXINSNS: ld_abs+get_processor_id",
4823 { },
4824 CLASSIC,
4825 { },
4826 { { 1, 0xbee } },
4827 .fill_helper = bpf_fill_ld_abs_get_processor_id,
4828 },
4829 {
4830 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
4831 { },
4832 INTERNAL,
4833 { 0x34 },
4834 { { ETH_HLEN, 0xbef } },
4835 .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
4836 },
4837 /*
4838 * LD_IND / LD_ABS on fragmented SKBs
4839 */
4840 {
4841 "LD_IND byte frag",
4842 .u.insns = {
4843 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4844 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
4845 BPF_STMT(BPF_RET | BPF_A, 0x0),
4846 },
4847 CLASSIC | FLAG_SKB_FRAG,
4848 { },
4849 { {0x40, 0x42} },
4850 .frag_data = {
4851 0x42, 0x00, 0x00, 0x00,
4852 0x43, 0x44, 0x00, 0x00,
4853 0x21, 0x07, 0x19, 0x83,
4854 },
4855 },
4856 {
4857 "LD_IND halfword frag",
4858 .u.insns = {
4859 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4860 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
4861 BPF_STMT(BPF_RET | BPF_A, 0x0),
4862 },
4863 CLASSIC | FLAG_SKB_FRAG,
4864 { },
4865 { {0x40, 0x4344} },
4866 .frag_data = {
4867 0x42, 0x00, 0x00, 0x00,
4868 0x43, 0x44, 0x00, 0x00,
4869 0x21, 0x07, 0x19, 0x83,
4870 },
4871 },
4872 {
4873 "LD_IND word frag",
4874 .u.insns = {
4875 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4876 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
4877 BPF_STMT(BPF_RET | BPF_A, 0x0),
4878 },
4879 CLASSIC | FLAG_SKB_FRAG,
4880 { },
4881 { {0x40, 0x21071983} },
4882 .frag_data = {
4883 0x42, 0x00, 0x00, 0x00,
4884 0x43, 0x44, 0x00, 0x00,
4885 0x21, 0x07, 0x19, 0x83,
4886 },
4887 },
4888 {
4889 "LD_IND halfword mixed head/frag",
4890 .u.insns = {
4891 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4892 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
4893 BPF_STMT(BPF_RET | BPF_A, 0x0),
4894 },
4895 CLASSIC | FLAG_SKB_FRAG,
4896 { [0x3e] = 0x25, [0x3f] = 0x05, },
4897 { {0x40, 0x0519} },
4898 .frag_data = { 0x19, 0x82 },
4899 },
4900 {
4901 "LD_IND word mixed head/frag",
4902 .u.insns = {
4903 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4904 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
4905 BPF_STMT(BPF_RET | BPF_A, 0x0),
4906 },
4907 CLASSIC | FLAG_SKB_FRAG,
4908 { [0x3e] = 0x25, [0x3f] = 0x05, },
4909 { {0x40, 0x25051982} },
4910 .frag_data = { 0x19, 0x82 },
4911 },
4912 {
4913 "LD_ABS byte frag",
4914 .u.insns = {
4915 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
4916 BPF_STMT(BPF_RET | BPF_A, 0x0),
4917 },
4918 CLASSIC | FLAG_SKB_FRAG,
4919 { },
4920 { {0x40, 0x42} },
4921 .frag_data = {
4922 0x42, 0x00, 0x00, 0x00,
4923 0x43, 0x44, 0x00, 0x00,
4924 0x21, 0x07, 0x19, 0x83,
4925 },
4926 },
4927 {
4928 "LD_ABS halfword frag",
4929 .u.insns = {
4930 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
4931 BPF_STMT(BPF_RET | BPF_A, 0x0),
4932 },
4933 CLASSIC | FLAG_SKB_FRAG,
4934 { },
4935 { {0x40, 0x4344} },
4936 .frag_data = {
4937 0x42, 0x00, 0x00, 0x00,
4938 0x43, 0x44, 0x00, 0x00,
4939 0x21, 0x07, 0x19, 0x83,
4940 },
4941 },
4942 {
4943 "LD_ABS word frag",
4944 .u.insns = {
4945 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
4946 BPF_STMT(BPF_RET | BPF_A, 0x0),
4947 },
4948 CLASSIC | FLAG_SKB_FRAG,
4949 { },
4950 { {0x40, 0x21071983} },
4951 .frag_data = {
4952 0x42, 0x00, 0x00, 0x00,
4953 0x43, 0x44, 0x00, 0x00,
4954 0x21, 0x07, 0x19, 0x83,
4955 },
4956 },
4957 {
4958 "LD_ABS halfword mixed head/frag",
4959 .u.insns = {
4960 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
4961 BPF_STMT(BPF_RET | BPF_A, 0x0),
4962 },
4963 CLASSIC | FLAG_SKB_FRAG,
4964 { [0x3e] = 0x25, [0x3f] = 0x05, },
4965 { {0x40, 0x0519} },
4966 .frag_data = { 0x19, 0x82 },
4967 },
4968 {
4969 "LD_ABS word mixed head/frag",
4970 .u.insns = {
4971 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
4972 BPF_STMT(BPF_RET | BPF_A, 0x0),
4973 },
4974 CLASSIC | FLAG_SKB_FRAG,
4975 { [0x3e] = 0x25, [0x3f] = 0x05, },
4976 { {0x40, 0x25051982} },
4977 .frag_data = { 0x19, 0x82 },
4978 },
4979 /*
4980 * LD_IND / LD_ABS on non fragmented SKBs
4981 */
4982 {
4983 /*
4984 * this tests that the JIT/interpreter correctly resets X
4985 * before using it in an LD_IND instruction.
4986 */
4987 "LD_IND byte default X",
4988 .u.insns = {
4989 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
4990 BPF_STMT(BPF_RET | BPF_A, 0x0),
4991 },
4992 CLASSIC,
4993 { [0x1] = 0x42 },
4994 { {0x40, 0x42 } },
4995 },
4996 {
4997 "LD_IND byte positive offset",
4998 .u.insns = {
4999 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5000 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5001 BPF_STMT(BPF_RET | BPF_A, 0x0),
5002 },
5003 CLASSIC,
5004 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5005 { {0x40, 0x82 } },
5006 },
5007 {
5008 "LD_IND byte negative offset",
5009 .u.insns = {
5010 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5011 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
5012 BPF_STMT(BPF_RET | BPF_A, 0x0),
5013 },
5014 CLASSIC,
5015 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5016 { {0x40, 0x05 } },
5017 },
5018 {
5019 "LD_IND halfword positive offset",
5020 .u.insns = {
5021 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5022 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
5023 BPF_STMT(BPF_RET | BPF_A, 0x0),
5024 },
5025 CLASSIC,
5026 {
5027 [0x1c] = 0xaa, [0x1d] = 0x55,
5028 [0x1e] = 0xbb, [0x1f] = 0x66,
5029 [0x20] = 0xcc, [0x21] = 0x77,
5030 [0x22] = 0xdd, [0x23] = 0x88,
5031 },
5032 { {0x40, 0xdd88 } },
5033 },
5034 {
5035 "LD_IND halfword negative offset",
5036 .u.insns = {
5037 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5038 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
5039 BPF_STMT(BPF_RET | BPF_A, 0x0),
5040 },
5041 CLASSIC,
5042 {
5043 [0x1c] = 0xaa, [0x1d] = 0x55,
5044 [0x1e] = 0xbb, [0x1f] = 0x66,
5045 [0x20] = 0xcc, [0x21] = 0x77,
5046 [0x22] = 0xdd, [0x23] = 0x88,
5047 },
5048 { {0x40, 0xbb66 } },
5049 },
5050 {
5051 "LD_IND halfword unaligned",
5052 .u.insns = {
5053 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5054 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5055 BPF_STMT(BPF_RET | BPF_A, 0x0),
5056 },
5057 CLASSIC,
5058 {
5059 [0x1c] = 0xaa, [0x1d] = 0x55,
5060 [0x1e] = 0xbb, [0x1f] = 0x66,
5061 [0x20] = 0xcc, [0x21] = 0x77,
5062 [0x22] = 0xdd, [0x23] = 0x88,
5063 },
5064 { {0x40, 0x66cc } },
5065 },
5066 {
5067 "LD_IND word positive offset",
5068 .u.insns = {
5069 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5070 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
5071 BPF_STMT(BPF_RET | BPF_A, 0x0),
5072 },
5073 CLASSIC,
5074 {
5075 [0x1c] = 0xaa, [0x1d] = 0x55,
5076 [0x1e] = 0xbb, [0x1f] = 0x66,
5077 [0x20] = 0xcc, [0x21] = 0x77,
5078 [0x22] = 0xdd, [0x23] = 0x88,
5079 [0x24] = 0xee, [0x25] = 0x99,
5080 [0x26] = 0xff, [0x27] = 0xaa,
5081 },
5082 { {0x40, 0xee99ffaa } },
5083 },
5084 {
5085 "LD_IND word negative offset",
5086 .u.insns = {
5087 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5088 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
5089 BPF_STMT(BPF_RET | BPF_A, 0x0),
5090 },
5091 CLASSIC,
5092 {
5093 [0x1c] = 0xaa, [0x1d] = 0x55,
5094 [0x1e] = 0xbb, [0x1f] = 0x66,
5095 [0x20] = 0xcc, [0x21] = 0x77,
5096 [0x22] = 0xdd, [0x23] = 0x88,
5097 [0x24] = 0xee, [0x25] = 0x99,
5098 [0x26] = 0xff, [0x27] = 0xaa,
5099 },
5100 { {0x40, 0xaa55bb66 } },
5101 },
5102 {
5103 "LD_IND word unaligned (addr & 3 == 2)",
5104 .u.insns = {
5105 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5106 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5107 BPF_STMT(BPF_RET | BPF_A, 0x0),
5108 },
5109 CLASSIC,
5110 {
5111 [0x1c] = 0xaa, [0x1d] = 0x55,
5112 [0x1e] = 0xbb, [0x1f] = 0x66,
5113 [0x20] = 0xcc, [0x21] = 0x77,
5114 [0x22] = 0xdd, [0x23] = 0x88,
5115 [0x24] = 0xee, [0x25] = 0x99,
5116 [0x26] = 0xff, [0x27] = 0xaa,
5117 },
5118 { {0x40, 0xbb66cc77 } },
5119 },
5120 {
5121 "LD_IND word unaligned (addr & 3 == 1)",
5122 .u.insns = {
5123 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5124 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
5125 BPF_STMT(BPF_RET | BPF_A, 0x0),
5126 },
5127 CLASSIC,
5128 {
5129 [0x1c] = 0xaa, [0x1d] = 0x55,
5130 [0x1e] = 0xbb, [0x1f] = 0x66,
5131 [0x20] = 0xcc, [0x21] = 0x77,
5132 [0x22] = 0xdd, [0x23] = 0x88,
5133 [0x24] = 0xee, [0x25] = 0x99,
5134 [0x26] = 0xff, [0x27] = 0xaa,
5135 },
5136 { {0x40, 0x55bb66cc } },
5137 },
5138 {
5139 "LD_IND word unaligned (addr & 3 == 3)",
5140 .u.insns = {
5141 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5142 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
5143 BPF_STMT(BPF_RET | BPF_A, 0x0),
5144 },
5145 CLASSIC,
5146 {
5147 [0x1c] = 0xaa, [0x1d] = 0x55,
5148 [0x1e] = 0xbb, [0x1f] = 0x66,
5149 [0x20] = 0xcc, [0x21] = 0x77,
5150 [0x22] = 0xdd, [0x23] = 0x88,
5151 [0x24] = 0xee, [0x25] = 0x99,
5152 [0x26] = 0xff, [0x27] = 0xaa,
5153 },
5154 { {0x40, 0x66cc77dd } },
5155 },
5156 {
5157 "LD_ABS byte",
5158 .u.insns = {
5159 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
5160 BPF_STMT(BPF_RET | BPF_A, 0x0),
5161 },
5162 CLASSIC,
5163 {
5164 [0x1c] = 0xaa, [0x1d] = 0x55,
5165 [0x1e] = 0xbb, [0x1f] = 0x66,
5166 [0x20] = 0xcc, [0x21] = 0x77,
5167 [0x22] = 0xdd, [0x23] = 0x88,
5168 [0x24] = 0xee, [0x25] = 0x99,
5169 [0x26] = 0xff, [0x27] = 0xaa,
5170 },
5171 { {0x40, 0xcc } },
5172 },
5173 {
5174 "LD_ABS halfword",
5175 .u.insns = {
5176 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
5177 BPF_STMT(BPF_RET | BPF_A, 0x0),
5178 },
5179 CLASSIC,
5180 {
5181 [0x1c] = 0xaa, [0x1d] = 0x55,
5182 [0x1e] = 0xbb, [0x1f] = 0x66,
5183 [0x20] = 0xcc, [0x21] = 0x77,
5184 [0x22] = 0xdd, [0x23] = 0x88,
5185 [0x24] = 0xee, [0x25] = 0x99,
5186 [0x26] = 0xff, [0x27] = 0xaa,
5187 },
5188 { {0x40, 0xdd88 } },
5189 },
5190 {
5191 "LD_ABS halfword unaligned",
5192 .u.insns = {
5193 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
5194 BPF_STMT(BPF_RET | BPF_A, 0x0),
5195 },
5196 CLASSIC,
5197 {
5198 [0x1c] = 0xaa, [0x1d] = 0x55,
5199 [0x1e] = 0xbb, [0x1f] = 0x66,
5200 [0x20] = 0xcc, [0x21] = 0x77,
5201 [0x22] = 0xdd, [0x23] = 0x88,
5202 [0x24] = 0xee, [0x25] = 0x99,
5203 [0x26] = 0xff, [0x27] = 0xaa,
5204 },
5205 { {0x40, 0x99ff } },
5206 },
5207 {
5208 "LD_ABS word",
5209 .u.insns = {
5210 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
5211 BPF_STMT(BPF_RET | BPF_A, 0x0),
5212 },
5213 CLASSIC,
5214 {
5215 [0x1c] = 0xaa, [0x1d] = 0x55,
5216 [0x1e] = 0xbb, [0x1f] = 0x66,
5217 [0x20] = 0xcc, [0x21] = 0x77,
5218 [0x22] = 0xdd, [0x23] = 0x88,
5219 [0x24] = 0xee, [0x25] = 0x99,
5220 [0x26] = 0xff, [0x27] = 0xaa,
5221 },
5222 { {0x40, 0xaa55bb66 } },
5223 },
5224 {
5225 "LD_ABS word unaligned (addr & 3 == 2)",
5226 .u.insns = {
5227 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
5228 BPF_STMT(BPF_RET | BPF_A, 0x0),
5229 },
5230 CLASSIC,
5231 {
5232 [0x1c] = 0xaa, [0x1d] = 0x55,
5233 [0x1e] = 0xbb, [0x1f] = 0x66,
5234 [0x20] = 0xcc, [0x21] = 0x77,
5235 [0x22] = 0xdd, [0x23] = 0x88,
5236 [0x24] = 0xee, [0x25] = 0x99,
5237 [0x26] = 0xff, [0x27] = 0xaa,
5238 },
5239 { {0x40, 0xdd88ee99 } },
5240 },
5241 {
5242 "LD_ABS word unaligned (addr & 3 == 1)",
5243 .u.insns = {
5244 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
5245 BPF_STMT(BPF_RET | BPF_A, 0x0),
5246 },
5247 CLASSIC,
5248 {
5249 [0x1c] = 0xaa, [0x1d] = 0x55,
5250 [0x1e] = 0xbb, [0x1f] = 0x66,
5251 [0x20] = 0xcc, [0x21] = 0x77,
5252 [0x22] = 0xdd, [0x23] = 0x88,
5253 [0x24] = 0xee, [0x25] = 0x99,
5254 [0x26] = 0xff, [0x27] = 0xaa,
5255 },
5256 { {0x40, 0x77dd88ee } },
5257 },
5258 {
5259 "LD_ABS word unaligned (addr & 3 == 3)",
5260 .u.insns = {
5261 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
5262 BPF_STMT(BPF_RET | BPF_A, 0x0),
5263 },
5264 CLASSIC,
5265 {
5266 [0x1c] = 0xaa, [0x1d] = 0x55,
5267 [0x1e] = 0xbb, [0x1f] = 0x66,
5268 [0x20] = 0xcc, [0x21] = 0x77,
5269 [0x22] = 0xdd, [0x23] = 0x88,
5270 [0x24] = 0xee, [0x25] = 0x99,
5271 [0x26] = 0xff, [0x27] = 0xaa,
5272 },
5273 { {0x40, 0x88ee99ff } },
5274 },
5275 /*
5276 * verify that the interpreter or JIT correctly sets A and X
5277 * to 0.
5278 */
5279 {
5280 "ADD default X",
5281 .u.insns = {
5282 /*
5283 * A = 0x42
5284 * A = A + X
5285 * ret A
5286 */
5287 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5288 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
5289 BPF_STMT(BPF_RET | BPF_A, 0x0),
5290 },
5291 CLASSIC | FLAG_NO_DATA,
5292 {},
5293 { {0x1, 0x42 } },
5294 },
5295 {
5296 "ADD default A",
5297 .u.insns = {
5298 /*
5299 * A = A + 0x42
5300 * ret A
5301 */
5302 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
5303 BPF_STMT(BPF_RET | BPF_A, 0x0),
5304 },
5305 CLASSIC | FLAG_NO_DATA,
5306 {},
5307 { {0x1, 0x42 } },
5308 },
5309 {
5310 "SUB default X",
5311 .u.insns = {
5312 /*
5313 * A = 0x66
5314 * A = A - X
5315 * ret A
5316 */
5317 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
5318 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
5319 BPF_STMT(BPF_RET | BPF_A, 0x0),
5320 },
5321 CLASSIC | FLAG_NO_DATA,
5322 {},
5323 { {0x1, 0x66 } },
5324 },
5325 {
5326 "SUB default A",
5327 .u.insns = {
5328 /*
5329 * A = A - -0x66
5330 * ret A
5331 */
5332 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
5333 BPF_STMT(BPF_RET | BPF_A, 0x0),
5334 },
5335 CLASSIC | FLAG_NO_DATA,
5336 {},
5337 { {0x1, 0x66 } },
5338 },
5339 {
5340 "MUL default X",
5341 .u.insns = {
5342 /*
5343 * A = 0x42
5344 * A = A * X
5345 * ret A
5346 */
5347 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5348 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
5349 BPF_STMT(BPF_RET | BPF_A, 0x0),
5350 },
5351 CLASSIC | FLAG_NO_DATA,
5352 {},
5353 { {0x1, 0x0 } },
5354 },
5355 {
5356 "MUL default A",
5357 .u.insns = {
5358 /*
5359 * A = A * 0x66
5360 * ret A
5361 */
5362 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
5363 BPF_STMT(BPF_RET | BPF_A, 0x0),
5364 },
5365 CLASSIC | FLAG_NO_DATA,
5366 {},
5367 { {0x1, 0x0 } },
5368 },
5369 {
5370 "DIV default X",
5371 .u.insns = {
5372 /*
5373 * A = 0x42
5374 * A = A / X ; this halt the filter execution if X is 0
5375 * ret 0x42
5376 */
5377 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5378 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
5379 BPF_STMT(BPF_RET | BPF_K, 0x42),
5380 },
5381 CLASSIC | FLAG_NO_DATA,
5382 {},
5383 { {0x1, 0x0 } },
5384 },
5385 {
5386 "DIV default A",
5387 .u.insns = {
5388 /*
5389 * A = A / 1
5390 * ret A
5391 */
5392 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
5393 BPF_STMT(BPF_RET | BPF_A, 0x0),
5394 },
5395 CLASSIC | FLAG_NO_DATA,
5396 {},
5397 { {0x1, 0x0 } },
5398 },
5399 {
5400 "MOD default X",
5401 .u.insns = {
5402 /*
5403 * A = 0x42
5404 * A = A mod X ; this halt the filter execution if X is 0
5405 * ret 0x42
5406 */
5407 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5408 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
5409 BPF_STMT(BPF_RET | BPF_K, 0x42),
5410 },
5411 CLASSIC | FLAG_NO_DATA,
5412 {},
5413 { {0x1, 0x0 } },
5414 },
5415 {
5416 "MOD default A",
5417 .u.insns = {
5418 /*
5419 * A = A mod 1
5420 * ret A
5421 */
5422 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
5423 BPF_STMT(BPF_RET | BPF_A, 0x0),
5424 },
5425 CLASSIC | FLAG_NO_DATA,
5426 {},
5427 { {0x1, 0x0 } },
5428 },
5429 {
5430 "JMP EQ default A",
5431 .u.insns = {
5432 /*
5433 * cmp A, 0x0, 0, 1
5434 * ret 0x42
5435 * ret 0x66
5436 */
5437 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
5438 BPF_STMT(BPF_RET | BPF_K, 0x42),
5439 BPF_STMT(BPF_RET | BPF_K, 0x66),
5440 },
5441 CLASSIC | FLAG_NO_DATA,
5442 {},
5443 { {0x1, 0x42 } },
5444 },
5445 {
5446 "JMP EQ default X",
5447 .u.insns = {
5448 /*
5449 * A = 0x0
5450 * cmp A, X, 0, 1
5451 * ret 0x42
5452 * ret 0x66
5453 */
5454 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
5455 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
5456 BPF_STMT(BPF_RET | BPF_K, 0x42),
5457 BPF_STMT(BPF_RET | BPF_K, 0x66),
5458 },
5459 CLASSIC | FLAG_NO_DATA,
5460 {},
5461 { {0x1, 0x42 } },
5462 },
5463};
5464
5465static struct net_device dev;
5466
5467static struct sk_buff *populate_skb(char *buf, int size)
5468{
5469 struct sk_buff *skb;
5470
5471 if (size >= MAX_DATA)
5472 return NULL;
5473
5474 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
5475 if (!skb)
5476 return NULL;
5477
5478 memcpy(__skb_put(skb, size), buf, size);
5479
5480 /* Initialize a fake skb with test pattern. */
5481 skb_reset_mac_header(skb);
5482 skb->protocol = htons(ETH_P_IP);
5483 skb->pkt_type = SKB_TYPE;
5484 skb->mark = SKB_MARK;
5485 skb->hash = SKB_HASH;
5486 skb->queue_mapping = SKB_QUEUE_MAP;
5487 skb->vlan_tci = SKB_VLAN_TCI;
5488 skb->vlan_proto = htons(ETH_P_IP);
5489 skb->dev = &dev;
5490 skb->dev->ifindex = SKB_DEV_IFINDEX;
5491 skb->dev->type = SKB_DEV_TYPE;
5492 skb_set_network_header(skb, min(size, ETH_HLEN));
5493
5494 return skb;
5495}
5496
5497static void *generate_test_data(struct bpf_test *test, int sub)
5498{
5499 struct sk_buff *skb;
5500 struct page *page;
5501
5502 if (test->aux & FLAG_NO_DATA)
5503 return NULL;
5504
5505 /* Test case expects an skb, so populate one. Various
5506 * subtests generate skbs of different sizes based on
5507 * the same data.
5508 */
5509 skb = populate_skb(test->data, test->test[sub].data_size);
5510 if (!skb)
5511 return NULL;
5512
5513 if (test->aux & FLAG_SKB_FRAG) {
5514 /*
5515 * when the test requires a fragmented skb, add a
5516 * single fragment to the skb, filled with
5517 * test->frag_data.
5518 */
5519 void *ptr;
5520
5521 page = alloc_page(GFP_KERNEL);
5522
5523 if (!page)
5524 goto err_kfree_skb;
5525
5526 ptr = kmap(page);
5527 if (!ptr)
5528 goto err_free_page;
5529 memcpy(ptr, test->frag_data, MAX_DATA);
5530 kunmap(page);
5531 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
5532 }
5533
5534 return skb;
5535
5536err_free_page:
5537 __free_page(page);
5538err_kfree_skb:
5539 kfree_skb(skb);
5540 return NULL;
5541}
5542
5543static void release_test_data(const struct bpf_test *test, void *data)
5544{
5545 if (test->aux & FLAG_NO_DATA)
5546 return;
5547
5548 kfree_skb(data);
5549}
5550
5551static int filter_length(int which)
5552{
5553 struct sock_filter *fp;
5554 int len;
5555
5556 if (tests[which].fill_helper)
5557 return tests[which].u.ptr.len;
5558
5559 fp = tests[which].u.insns;
5560 for (len = MAX_INSNS - 1; len > 0; --len)
5561 if (fp[len].code != 0 || fp[len].k != 0)
5562 break;
5563
5564 return len + 1;
5565}
5566
5567static void *filter_pointer(int which)
5568{
5569 if (tests[which].fill_helper)
5570 return tests[which].u.ptr.insns;
5571 else
5572 return tests[which].u.insns;
5573}
5574
5575static struct bpf_prog *generate_filter(int which, int *err)
5576{
5577 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
5578 unsigned int flen = filter_length(which);
5579 void *fptr = filter_pointer(which);
5580 struct sock_fprog_kern fprog;
5581 struct bpf_prog *fp;
5582
5583 switch (test_type) {
5584 case CLASSIC:
5585 fprog.filter = fptr;
5586 fprog.len = flen;
5587
5588 *err = bpf_prog_create(&fp, &fprog);
5589 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
5590 if (*err == -EINVAL) {
5591 pr_cont("PASS\n");
5592 /* Verifier rejected filter as expected. */
5593 *err = 0;
5594 return NULL;
5595 } else {
5596 pr_cont("UNEXPECTED_PASS\n");
5597 /* Verifier didn't reject the test that's
5598 * bad enough, just return!
5599 */
5600 *err = -EINVAL;
5601 return NULL;
5602 }
5603 }
5604 /* We don't expect to fail. */
5605 if (*err) {
5606 pr_cont("FAIL to attach err=%d len=%d\n",
5607 *err, fprog.len);
5608 return NULL;
5609 }
5610 break;
5611
5612 case INTERNAL:
5613 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
5614 if (fp == NULL) {
5615 pr_cont("UNEXPECTED_FAIL no memory left\n");
5616 *err = -ENOMEM;
5617 return NULL;
5618 }
5619
5620 fp->len = flen;
5621 /* Type doesn't really matter here as long as it's not unspec. */
5622 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
5623 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
5624
5625 /* We cannot error here as we don't need type compatibility
5626 * checks.
5627 */
5628 fp = bpf_prog_select_runtime(fp, err);
5629 break;
5630 }
5631
5632 *err = 0;
5633 return fp;
5634}
5635
5636static void release_filter(struct bpf_prog *fp, int which)
5637{
5638 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
5639
5640 switch (test_type) {
5641 case CLASSIC:
5642 bpf_prog_destroy(fp);
5643 break;
5644 case INTERNAL:
5645 bpf_prog_free(fp);
5646 break;
5647 }
5648}
5649
5650static int __run_one(const struct bpf_prog *fp, const void *data,
5651 int runs, u64 *duration)
5652{
5653 u64 start, finish;
5654 int ret = 0, i;
5655
5656 start = ktime_get_ns();
5657
5658 for (i = 0; i < runs; i++)
5659 ret = BPF_PROG_RUN(fp, data);
5660
5661 finish = ktime_get_ns();
5662
5663 *duration = finish - start;
5664 do_div(*duration, runs);
5665
5666 return ret;
5667}
5668
5669static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
5670{
5671 int err_cnt = 0, i, runs = MAX_TESTRUNS;
5672
5673 for (i = 0; i < MAX_SUBTESTS; i++) {
5674 void *data;
5675 u64 duration;
5676 u32 ret;
5677
5678 if (test->test[i].data_size == 0 &&
5679 test->test[i].result == 0)
5680 break;
5681
5682 data = generate_test_data(test, i);
5683 if (!data && !(test->aux & FLAG_NO_DATA)) {
5684 pr_cont("data generation failed ");
5685 err_cnt++;
5686 break;
5687 }
5688 ret = __run_one(fp, data, runs, &duration);
5689 release_test_data(test, data);
5690
5691 if (ret == test->test[i].result) {
5692 pr_cont("%lld ", duration);
5693 } else {
5694 pr_cont("ret %d != %d ", ret,
5695 test->test[i].result);
5696 err_cnt++;
5697 }
5698 }
5699
5700 return err_cnt;
5701}
5702
5703static char test_name[64];
5704module_param_string(test_name, test_name, sizeof(test_name), 0);
5705
5706static int test_id = -1;
5707module_param(test_id, int, 0);
5708
5709static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
5710module_param_array(test_range, int, NULL, 0);
5711
5712static __init int find_test_index(const char *test_name)
5713{
5714 int i;
5715
5716 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5717 if (!strcmp(tests[i].descr, test_name))
5718 return i;
5719 }
5720 return -1;
5721}
5722
5723static __init int prepare_bpf_tests(void)
5724{
5725 int i;
5726
5727 if (test_id >= 0) {
5728 /*
5729 * if a test_id was specified, use test_range to
5730 * cover only that test.
5731 */
5732 if (test_id >= ARRAY_SIZE(tests)) {
5733 pr_err("test_bpf: invalid test_id specified.\n");
5734 return -EINVAL;
5735 }
5736
5737 test_range[0] = test_id;
5738 test_range[1] = test_id;
5739 } else if (*test_name) {
5740 /*
5741 * if a test_name was specified, find it and setup
5742 * test_range to cover only that test.
5743 */
5744 int idx = find_test_index(test_name);
5745
5746 if (idx < 0) {
5747 pr_err("test_bpf: no test named '%s' found.\n",
5748 test_name);
5749 return -EINVAL;
5750 }
5751 test_range[0] = idx;
5752 test_range[1] = idx;
5753 } else {
5754 /*
5755 * check that the supplied test_range is valid.
5756 */
5757 if (test_range[0] >= ARRAY_SIZE(tests) ||
5758 test_range[1] >= ARRAY_SIZE(tests) ||
5759 test_range[0] < 0 || test_range[1] < 0) {
5760 pr_err("test_bpf: test_range is out of bound.\n");
5761 return -EINVAL;
5762 }
5763
5764 if (test_range[1] < test_range[0]) {
5765 pr_err("test_bpf: test_range is ending before it starts.\n");
5766 return -EINVAL;
5767 }
5768 }
5769
5770 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5771 if (tests[i].fill_helper &&
5772 tests[i].fill_helper(&tests[i]) < 0)
5773 return -ENOMEM;
5774 }
5775
5776 return 0;
5777}
5778
5779static __init void destroy_bpf_tests(void)
5780{
5781 int i;
5782
5783 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5784 if (tests[i].fill_helper)
5785 kfree(tests[i].u.ptr.insns);
5786 }
5787}
5788
5789static bool exclude_test(int test_id)
5790{
5791 return test_id < test_range[0] || test_id > test_range[1];
5792}
5793
5794static __init int test_bpf(void)
5795{
5796 int i, err_cnt = 0, pass_cnt = 0;
5797 int jit_cnt = 0, run_cnt = 0;
5798
5799 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5800 struct bpf_prog *fp;
5801 int err;
5802
5803 if (exclude_test(i))
5804 continue;
5805
5806 pr_info("#%d %s ", i, tests[i].descr);
5807
5808 fp = generate_filter(i, &err);
5809 if (fp == NULL) {
5810 if (err == 0) {
5811 pass_cnt++;
5812 continue;
5813 }
5814
5815 return err;
5816 }
5817
5818 pr_cont("jited:%u ", fp->jited);
5819
5820 run_cnt++;
5821 if (fp->jited)
5822 jit_cnt++;
5823
5824 err = run_one(fp, &tests[i]);
5825 release_filter(fp, i);
5826
5827 if (err) {
5828 pr_cont("FAIL (%d times)\n", err);
5829 err_cnt++;
5830 } else {
5831 pr_cont("PASS\n");
5832 pass_cnt++;
5833 }
5834 }
5835
5836 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
5837 pass_cnt, err_cnt, jit_cnt, run_cnt);
5838
5839 return err_cnt ? -EINVAL : 0;
5840}
5841
5842static int __init test_bpf_init(void)
5843{
5844 int ret;
5845
5846 ret = prepare_bpf_tests();
5847 if (ret < 0)
5848 return ret;
5849
5850 ret = test_bpf();
5851
5852 destroy_bpf_tests();
5853 return ret;
5854}
5855
5856static void __exit test_bpf_exit(void)
5857{
5858}
5859
5860module_init(test_bpf_init);
5861module_exit(test_bpf_exit);
5862
5863MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Testsuite for BPF interpreter and BPF JIT compiler
4 *
5 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
6 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/filter.h>
13#include <linux/bpf.h>
14#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16#include <linux/if_vlan.h>
17#include <linux/random.h>
18#include <linux/highmem.h>
19#include <linux/sched.h>
20
21/* General test specific settings */
22#define MAX_SUBTESTS 3
23#define MAX_TESTRUNS 1000
24#define MAX_DATA 128
25#define MAX_INSNS 512
26#define MAX_K 0xffffFFFF
27
28/* Few constants used to init test 'skb' */
29#define SKB_TYPE 3
30#define SKB_MARK 0x1234aaaa
31#define SKB_HASH 0x1234aaab
32#define SKB_QUEUE_MAP 123
33#define SKB_VLAN_TCI 0xffff
34#define SKB_VLAN_PRESENT 1
35#define SKB_DEV_IFINDEX 577
36#define SKB_DEV_TYPE 588
37
38/* Redefine REGs to make tests less verbose */
39#define R0 BPF_REG_0
40#define R1 BPF_REG_1
41#define R2 BPF_REG_2
42#define R3 BPF_REG_3
43#define R4 BPF_REG_4
44#define R5 BPF_REG_5
45#define R6 BPF_REG_6
46#define R7 BPF_REG_7
47#define R8 BPF_REG_8
48#define R9 BPF_REG_9
49#define R10 BPF_REG_10
50
51/* Flags that can be passed to test cases */
52#define FLAG_NO_DATA BIT(0)
53#define FLAG_EXPECTED_FAIL BIT(1)
54#define FLAG_SKB_FRAG BIT(2)
55
56enum {
57 CLASSIC = BIT(6), /* Old BPF instructions only. */
58 INTERNAL = BIT(7), /* Extended instruction set. */
59};
60
61#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
62
63struct bpf_test {
64 const char *descr;
65 union {
66 struct sock_filter insns[MAX_INSNS];
67 struct bpf_insn insns_int[MAX_INSNS];
68 struct {
69 void *insns;
70 unsigned int len;
71 } ptr;
72 } u;
73 __u8 aux;
74 __u8 data[MAX_DATA];
75 struct {
76 int data_size;
77 __u32 result;
78 } test[MAX_SUBTESTS];
79 int (*fill_helper)(struct bpf_test *self);
80 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
81 __u8 frag_data[MAX_DATA];
82 int stack_depth; /* for eBPF only, since tests don't call verifier */
83};
84
85/* Large test cases need separate allocation and fill handler. */
86
87static int bpf_fill_maxinsns1(struct bpf_test *self)
88{
89 unsigned int len = BPF_MAXINSNS;
90 struct sock_filter *insn;
91 __u32 k = ~0;
92 int i;
93
94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
95 if (!insn)
96 return -ENOMEM;
97
98 for (i = 0; i < len; i++, k--)
99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
100
101 self->u.ptr.insns = insn;
102 self->u.ptr.len = len;
103
104 return 0;
105}
106
107static int bpf_fill_maxinsns2(struct bpf_test *self)
108{
109 unsigned int len = BPF_MAXINSNS;
110 struct sock_filter *insn;
111 int i;
112
113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
114 if (!insn)
115 return -ENOMEM;
116
117 for (i = 0; i < len; i++)
118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
119
120 self->u.ptr.insns = insn;
121 self->u.ptr.len = len;
122
123 return 0;
124}
125
126static int bpf_fill_maxinsns3(struct bpf_test *self)
127{
128 unsigned int len = BPF_MAXINSNS;
129 struct sock_filter *insn;
130 struct rnd_state rnd;
131 int i;
132
133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
134 if (!insn)
135 return -ENOMEM;
136
137 prandom_seed_state(&rnd, 3141592653589793238ULL);
138
139 for (i = 0; i < len - 1; i++) {
140 __u32 k = prandom_u32_state(&rnd);
141
142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
143 }
144
145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
146
147 self->u.ptr.insns = insn;
148 self->u.ptr.len = len;
149
150 return 0;
151}
152
153static int bpf_fill_maxinsns4(struct bpf_test *self)
154{
155 unsigned int len = BPF_MAXINSNS + 1;
156 struct sock_filter *insn;
157 int i;
158
159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
160 if (!insn)
161 return -ENOMEM;
162
163 for (i = 0; i < len; i++)
164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
165
166 self->u.ptr.insns = insn;
167 self->u.ptr.len = len;
168
169 return 0;
170}
171
172static int bpf_fill_maxinsns5(struct bpf_test *self)
173{
174 unsigned int len = BPF_MAXINSNS;
175 struct sock_filter *insn;
176 int i;
177
178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
179 if (!insn)
180 return -ENOMEM;
181
182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
183
184 for (i = 1; i < len - 1; i++)
185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
186
187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
188
189 self->u.ptr.insns = insn;
190 self->u.ptr.len = len;
191
192 return 0;
193}
194
195static int bpf_fill_maxinsns6(struct bpf_test *self)
196{
197 unsigned int len = BPF_MAXINSNS;
198 struct sock_filter *insn;
199 int i;
200
201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
202 if (!insn)
203 return -ENOMEM;
204
205 for (i = 0; i < len - 1; i++)
206 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
207 SKF_AD_VLAN_TAG_PRESENT);
208
209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
210
211 self->u.ptr.insns = insn;
212 self->u.ptr.len = len;
213
214 return 0;
215}
216
217static int bpf_fill_maxinsns7(struct bpf_test *self)
218{
219 unsigned int len = BPF_MAXINSNS;
220 struct sock_filter *insn;
221 int i;
222
223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
224 if (!insn)
225 return -ENOMEM;
226
227 for (i = 0; i < len - 4; i++)
228 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
229 SKF_AD_CPU);
230
231 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
232 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
233 SKF_AD_CPU);
234 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
235 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
236
237 self->u.ptr.insns = insn;
238 self->u.ptr.len = len;
239
240 return 0;
241}
242
243static int bpf_fill_maxinsns8(struct bpf_test *self)
244{
245 unsigned int len = BPF_MAXINSNS;
246 struct sock_filter *insn;
247 int i, jmp_off = len - 3;
248
249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
250 if (!insn)
251 return -ENOMEM;
252
253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
254
255 for (i = 1; i < len - 1; i++)
256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
257
258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
259
260 self->u.ptr.insns = insn;
261 self->u.ptr.len = len;
262
263 return 0;
264}
265
266static int bpf_fill_maxinsns9(struct bpf_test *self)
267{
268 unsigned int len = BPF_MAXINSNS;
269 struct bpf_insn *insn;
270 int i;
271
272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
273 if (!insn)
274 return -ENOMEM;
275
276 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
277 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
278 insn[2] = BPF_EXIT_INSN();
279
280 for (i = 3; i < len - 2; i++)
281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
282
283 insn[len - 2] = BPF_EXIT_INSN();
284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
285
286 self->u.ptr.insns = insn;
287 self->u.ptr.len = len;
288
289 return 0;
290}
291
292static int bpf_fill_maxinsns10(struct bpf_test *self)
293{
294 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
295 struct bpf_insn *insn;
296 int i;
297
298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
299 if (!insn)
300 return -ENOMEM;
301
302 for (i = 0; i < hlen / 2; i++)
303 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
304 for (i = hlen - 1; i > hlen / 2; i--)
305 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
306
307 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
308 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
309 insn[hlen + 1] = BPF_EXIT_INSN();
310
311 self->u.ptr.insns = insn;
312 self->u.ptr.len = len;
313
314 return 0;
315}
316
317static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
318 unsigned int plen)
319{
320 struct sock_filter *insn;
321 unsigned int rlen;
322 int i, j;
323
324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
325 if (!insn)
326 return -ENOMEM;
327
328 rlen = (len % plen) - 1;
329
330 for (i = 0; i + plen < len; i += plen)
331 for (j = 0; j < plen; j++)
332 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
333 plen - 1 - j, 0, 0);
334 for (j = 0; j < rlen; j++)
335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
336 0, 0);
337
338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
339
340 self->u.ptr.insns = insn;
341 self->u.ptr.len = len;
342
343 return 0;
344}
345
346static int bpf_fill_maxinsns11(struct bpf_test *self)
347{
348 /* Hits 70 passes on x86_64, so cannot get JITed there. */
349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
350}
351
352static int bpf_fill_maxinsns12(struct bpf_test *self)
353{
354 unsigned int len = BPF_MAXINSNS;
355 struct sock_filter *insn;
356 int i = 0;
357
358 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
359 if (!insn)
360 return -ENOMEM;
361
362 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
363
364 for (i = 1; i < len - 1; i++)
365 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
366
367 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
368
369 self->u.ptr.insns = insn;
370 self->u.ptr.len = len;
371
372 return 0;
373}
374
375static int bpf_fill_maxinsns13(struct bpf_test *self)
376{
377 unsigned int len = BPF_MAXINSNS;
378 struct sock_filter *insn;
379 int i = 0;
380
381 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
382 if (!insn)
383 return -ENOMEM;
384
385 for (i = 0; i < len - 3; i++)
386 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
387
388 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
389 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
390 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
391
392 self->u.ptr.insns = insn;
393 self->u.ptr.len = len;
394
395 return 0;
396}
397
398static int bpf_fill_ja(struct bpf_test *self)
399{
400 /* Hits exactly 11 passes on x86_64 JIT. */
401 return __bpf_fill_ja(self, 12, 9);
402}
403
404static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
405{
406 unsigned int len = BPF_MAXINSNS;
407 struct sock_filter *insn;
408 int i;
409
410 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
411 if (!insn)
412 return -ENOMEM;
413
414 for (i = 0; i < len - 1; i += 2) {
415 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
416 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
417 SKF_AD_OFF + SKF_AD_CPU);
418 }
419
420 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
421
422 self->u.ptr.insns = insn;
423 self->u.ptr.len = len;
424
425 return 0;
426}
427
428static int __bpf_fill_stxdw(struct bpf_test *self, int size)
429{
430 unsigned int len = BPF_MAXINSNS;
431 struct bpf_insn *insn;
432 int i;
433
434 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
435 if (!insn)
436 return -ENOMEM;
437
438 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
439 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
440
441 for (i = 2; i < len - 2; i++)
442 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
443
444 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
445 insn[len - 1] = BPF_EXIT_INSN();
446
447 self->u.ptr.insns = insn;
448 self->u.ptr.len = len;
449 self->stack_depth = 40;
450
451 return 0;
452}
453
454static int bpf_fill_stxw(struct bpf_test *self)
455{
456 return __bpf_fill_stxdw(self, BPF_W);
457}
458
459static int bpf_fill_stxdw(struct bpf_test *self)
460{
461 return __bpf_fill_stxdw(self, BPF_DW);
462}
463
464static struct bpf_test tests[] = {
465 {
466 "TAX",
467 .u.insns = {
468 BPF_STMT(BPF_LD | BPF_IMM, 1),
469 BPF_STMT(BPF_MISC | BPF_TAX, 0),
470 BPF_STMT(BPF_LD | BPF_IMM, 2),
471 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
472 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
473 BPF_STMT(BPF_MISC | BPF_TAX, 0),
474 BPF_STMT(BPF_LD | BPF_LEN, 0),
475 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
476 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
477 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
478 BPF_STMT(BPF_RET | BPF_A, 0)
479 },
480 CLASSIC,
481 { 10, 20, 30, 40, 50 },
482 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
483 },
484 {
485 "TXA",
486 .u.insns = {
487 BPF_STMT(BPF_LDX | BPF_LEN, 0),
488 BPF_STMT(BPF_MISC | BPF_TXA, 0),
489 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
490 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
491 },
492 CLASSIC,
493 { 10, 20, 30, 40, 50 },
494 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
495 },
496 {
497 "ADD_SUB_MUL_K",
498 .u.insns = {
499 BPF_STMT(BPF_LD | BPF_IMM, 1),
500 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
501 BPF_STMT(BPF_LDX | BPF_IMM, 3),
502 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
503 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
504 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
505 BPF_STMT(BPF_RET | BPF_A, 0)
506 },
507 CLASSIC | FLAG_NO_DATA,
508 { },
509 { { 0, 0xfffffffd } }
510 },
511 {
512 "DIV_MOD_KX",
513 .u.insns = {
514 BPF_STMT(BPF_LD | BPF_IMM, 8),
515 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
516 BPF_STMT(BPF_MISC | BPF_TAX, 0),
517 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
518 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
519 BPF_STMT(BPF_MISC | BPF_TAX, 0),
520 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
521 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
522 BPF_STMT(BPF_MISC | BPF_TAX, 0),
523 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
524 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
525 BPF_STMT(BPF_MISC | BPF_TAX, 0),
526 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
527 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
528 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
529 BPF_STMT(BPF_RET | BPF_A, 0)
530 },
531 CLASSIC | FLAG_NO_DATA,
532 { },
533 { { 0, 0x20000000 } }
534 },
535 {
536 "AND_OR_LSH_K",
537 .u.insns = {
538 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
539 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
540 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
541 BPF_STMT(BPF_MISC | BPF_TAX, 0),
542 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
543 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
544 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
545 BPF_STMT(BPF_RET | BPF_A, 0)
546 },
547 CLASSIC | FLAG_NO_DATA,
548 { },
549 { { 0, 0x800000ff }, { 1, 0x800000ff } },
550 },
551 {
552 "LD_IMM_0",
553 .u.insns = {
554 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
555 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
556 BPF_STMT(BPF_RET | BPF_K, 0),
557 BPF_STMT(BPF_RET | BPF_K, 1),
558 },
559 CLASSIC,
560 { },
561 { { 1, 1 } },
562 },
563 {
564 "LD_IND",
565 .u.insns = {
566 BPF_STMT(BPF_LDX | BPF_LEN, 0),
567 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
568 BPF_STMT(BPF_RET | BPF_K, 1)
569 },
570 CLASSIC,
571 { },
572 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
573 },
574 {
575 "LD_ABS",
576 .u.insns = {
577 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
578 BPF_STMT(BPF_RET | BPF_K, 1)
579 },
580 CLASSIC,
581 { },
582 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
583 },
584 {
585 "LD_ABS_LL",
586 .u.insns = {
587 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
590 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
591 BPF_STMT(BPF_RET | BPF_A, 0)
592 },
593 CLASSIC,
594 { 1, 2, 3 },
595 { { 1, 0 }, { 2, 3 } },
596 },
597 {
598 "LD_IND_LL",
599 .u.insns = {
600 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
603 BPF_STMT(BPF_MISC | BPF_TAX, 0),
604 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
605 BPF_STMT(BPF_RET | BPF_A, 0)
606 },
607 CLASSIC,
608 { 1, 2, 3, 0xff },
609 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
610 },
611 {
612 "LD_ABS_NET",
613 .u.insns = {
614 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
615 BPF_STMT(BPF_MISC | BPF_TAX, 0),
616 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
617 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
618 BPF_STMT(BPF_RET | BPF_A, 0)
619 },
620 CLASSIC,
621 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
622 { { 15, 0 }, { 16, 3 } },
623 },
624 {
625 "LD_IND_NET",
626 .u.insns = {
627 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
628 BPF_STMT(BPF_LDX | BPF_LEN, 0),
629 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
630 BPF_STMT(BPF_MISC | BPF_TAX, 0),
631 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
632 BPF_STMT(BPF_RET | BPF_A, 0)
633 },
634 CLASSIC,
635 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
636 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
637 },
638 {
639 "LD_PKTTYPE",
640 .u.insns = {
641 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
642 SKF_AD_OFF + SKF_AD_PKTTYPE),
643 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
644 BPF_STMT(BPF_RET | BPF_K, 1),
645 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
646 SKF_AD_OFF + SKF_AD_PKTTYPE),
647 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
648 BPF_STMT(BPF_RET | BPF_K, 1),
649 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
650 SKF_AD_OFF + SKF_AD_PKTTYPE),
651 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
652 BPF_STMT(BPF_RET | BPF_K, 1),
653 BPF_STMT(BPF_RET | BPF_A, 0)
654 },
655 CLASSIC,
656 { },
657 { { 1, 3 }, { 10, 3 } },
658 },
659 {
660 "LD_MARK",
661 .u.insns = {
662 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
663 SKF_AD_OFF + SKF_AD_MARK),
664 BPF_STMT(BPF_RET | BPF_A, 0)
665 },
666 CLASSIC,
667 { },
668 { { 1, SKB_MARK}, { 10, SKB_MARK} },
669 },
670 {
671 "LD_RXHASH",
672 .u.insns = {
673 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
674 SKF_AD_OFF + SKF_AD_RXHASH),
675 BPF_STMT(BPF_RET | BPF_A, 0)
676 },
677 CLASSIC,
678 { },
679 { { 1, SKB_HASH}, { 10, SKB_HASH} },
680 },
681 {
682 "LD_QUEUE",
683 .u.insns = {
684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_QUEUE),
686 BPF_STMT(BPF_RET | BPF_A, 0)
687 },
688 CLASSIC,
689 { },
690 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
691 },
692 {
693 "LD_PROTOCOL",
694 .u.insns = {
695 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
696 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
697 BPF_STMT(BPF_RET | BPF_K, 0),
698 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
699 SKF_AD_OFF + SKF_AD_PROTOCOL),
700 BPF_STMT(BPF_MISC | BPF_TAX, 0),
701 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
702 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
703 BPF_STMT(BPF_RET | BPF_K, 0),
704 BPF_STMT(BPF_MISC | BPF_TXA, 0),
705 BPF_STMT(BPF_RET | BPF_A, 0)
706 },
707 CLASSIC,
708 { 10, 20, 30 },
709 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
710 },
711 {
712 "LD_VLAN_TAG",
713 .u.insns = {
714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
715 SKF_AD_OFF + SKF_AD_VLAN_TAG),
716 BPF_STMT(BPF_RET | BPF_A, 0)
717 },
718 CLASSIC,
719 { },
720 {
721 { 1, SKB_VLAN_TCI },
722 { 10, SKB_VLAN_TCI }
723 },
724 },
725 {
726 "LD_VLAN_TAG_PRESENT",
727 .u.insns = {
728 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
729 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
730 BPF_STMT(BPF_RET | BPF_A, 0)
731 },
732 CLASSIC,
733 { },
734 {
735 { 1, SKB_VLAN_PRESENT },
736 { 10, SKB_VLAN_PRESENT }
737 },
738 },
739 {
740 "LD_IFINDEX",
741 .u.insns = {
742 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
743 SKF_AD_OFF + SKF_AD_IFINDEX),
744 BPF_STMT(BPF_RET | BPF_A, 0)
745 },
746 CLASSIC,
747 { },
748 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
749 },
750 {
751 "LD_HATYPE",
752 .u.insns = {
753 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
754 SKF_AD_OFF + SKF_AD_HATYPE),
755 BPF_STMT(BPF_RET | BPF_A, 0)
756 },
757 CLASSIC,
758 { },
759 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
760 },
761 {
762 "LD_CPU",
763 .u.insns = {
764 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
765 SKF_AD_OFF + SKF_AD_CPU),
766 BPF_STMT(BPF_MISC | BPF_TAX, 0),
767 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
768 SKF_AD_OFF + SKF_AD_CPU),
769 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
770 BPF_STMT(BPF_RET | BPF_A, 0)
771 },
772 CLASSIC,
773 { },
774 { { 1, 0 }, { 10, 0 } },
775 },
776 {
777 "LD_NLATTR",
778 .u.insns = {
779 BPF_STMT(BPF_LDX | BPF_IMM, 2),
780 BPF_STMT(BPF_MISC | BPF_TXA, 0),
781 BPF_STMT(BPF_LDX | BPF_IMM, 3),
782 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
783 SKF_AD_OFF + SKF_AD_NLATTR),
784 BPF_STMT(BPF_RET | BPF_A, 0)
785 },
786 CLASSIC,
787#ifdef __BIG_ENDIAN
788 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
789#else
790 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
791#endif
792 { { 4, 0 }, { 20, 6 } },
793 },
794 {
795 "LD_NLATTR_NEST",
796 .u.insns = {
797 BPF_STMT(BPF_LD | BPF_IMM, 2),
798 BPF_STMT(BPF_LDX | BPF_IMM, 3),
799 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
800 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
801 BPF_STMT(BPF_LD | BPF_IMM, 2),
802 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
803 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
804 BPF_STMT(BPF_LD | BPF_IMM, 2),
805 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
806 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
807 BPF_STMT(BPF_LD | BPF_IMM, 2),
808 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
809 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
810 BPF_STMT(BPF_LD | BPF_IMM, 2),
811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
813 BPF_STMT(BPF_LD | BPF_IMM, 2),
814 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
815 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
816 BPF_STMT(BPF_LD | BPF_IMM, 2),
817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
819 BPF_STMT(BPF_LD | BPF_IMM, 2),
820 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
821 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
822 BPF_STMT(BPF_RET | BPF_A, 0)
823 },
824 CLASSIC,
825#ifdef __BIG_ENDIAN
826 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
827#else
828 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
829#endif
830 { { 4, 0 }, { 20, 10 } },
831 },
832 {
833 "LD_PAYLOAD_OFF",
834 .u.insns = {
835 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
836 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
839 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
840 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
841 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
842 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
843 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
844 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
845 BPF_STMT(BPF_RET | BPF_A, 0)
846 },
847 CLASSIC,
848 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
849 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
850 * id 9737, seq 1, length 64
851 */
852 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
853 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
854 0x08, 0x00,
855 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
856 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
857 { { 30, 0 }, { 100, 42 } },
858 },
859 {
860 "LD_ANC_XOR",
861 .u.insns = {
862 BPF_STMT(BPF_LD | BPF_IMM, 10),
863 BPF_STMT(BPF_LDX | BPF_IMM, 300),
864 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
865 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
866 BPF_STMT(BPF_RET | BPF_A, 0)
867 },
868 CLASSIC,
869 { },
870 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
871 },
872 {
873 "SPILL_FILL",
874 .u.insns = {
875 BPF_STMT(BPF_LDX | BPF_LEN, 0),
876 BPF_STMT(BPF_LD | BPF_IMM, 2),
877 BPF_STMT(BPF_ALU | BPF_RSH, 1),
878 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
879 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
880 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
881 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
882 BPF_STMT(BPF_STX, 15), /* M3 = len */
883 BPF_STMT(BPF_LDX | BPF_MEM, 1),
884 BPF_STMT(BPF_LD | BPF_MEM, 2),
885 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
886 BPF_STMT(BPF_LDX | BPF_MEM, 15),
887 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
888 BPF_STMT(BPF_RET | BPF_A, 0)
889 },
890 CLASSIC,
891 { },
892 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
893 },
894 {
895 "JEQ",
896 .u.insns = {
897 BPF_STMT(BPF_LDX | BPF_LEN, 0),
898 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
899 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
900 BPF_STMT(BPF_RET | BPF_K, 1),
901 BPF_STMT(BPF_RET | BPF_K, MAX_K)
902 },
903 CLASSIC,
904 { 3, 3, 3, 3, 3 },
905 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
906 },
907 {
908 "JGT",
909 .u.insns = {
910 BPF_STMT(BPF_LDX | BPF_LEN, 0),
911 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
912 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
913 BPF_STMT(BPF_RET | BPF_K, 1),
914 BPF_STMT(BPF_RET | BPF_K, MAX_K)
915 },
916 CLASSIC,
917 { 4, 4, 4, 3, 3 },
918 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
919 },
920 {
921 "JGE (jt 0), test 1",
922 .u.insns = {
923 BPF_STMT(BPF_LDX | BPF_LEN, 0),
924 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
925 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
926 BPF_STMT(BPF_RET | BPF_K, 1),
927 BPF_STMT(BPF_RET | BPF_K, MAX_K)
928 },
929 CLASSIC,
930 { 4, 4, 4, 3, 3 },
931 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
932 },
933 {
934 "JGE (jt 0), test 2",
935 .u.insns = {
936 BPF_STMT(BPF_LDX | BPF_LEN, 0),
937 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
938 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
939 BPF_STMT(BPF_RET | BPF_K, 1),
940 BPF_STMT(BPF_RET | BPF_K, MAX_K)
941 },
942 CLASSIC,
943 { 4, 4, 5, 3, 3 },
944 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
945 },
946 {
947 "JGE",
948 .u.insns = {
949 BPF_STMT(BPF_LDX | BPF_LEN, 0),
950 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
951 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
952 BPF_STMT(BPF_RET | BPF_K, 10),
953 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
954 BPF_STMT(BPF_RET | BPF_K, 20),
955 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
956 BPF_STMT(BPF_RET | BPF_K, 30),
957 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
958 BPF_STMT(BPF_RET | BPF_K, 40),
959 BPF_STMT(BPF_RET | BPF_K, MAX_K)
960 },
961 CLASSIC,
962 { 1, 2, 3, 4, 5 },
963 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
964 },
965 {
966 "JSET",
967 .u.insns = {
968 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
969 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
970 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
971 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
972 BPF_STMT(BPF_LDX | BPF_LEN, 0),
973 BPF_STMT(BPF_MISC | BPF_TXA, 0),
974 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
975 BPF_STMT(BPF_MISC | BPF_TAX, 0),
976 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
977 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
978 BPF_STMT(BPF_RET | BPF_K, 10),
979 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
980 BPF_STMT(BPF_RET | BPF_K, 20),
981 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
982 BPF_STMT(BPF_RET | BPF_K, 30),
983 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
984 BPF_STMT(BPF_RET | BPF_K, 30),
985 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
986 BPF_STMT(BPF_RET | BPF_K, 30),
987 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
988 BPF_STMT(BPF_RET | BPF_K, 30),
989 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
990 BPF_STMT(BPF_RET | BPF_K, 30),
991 BPF_STMT(BPF_RET | BPF_K, MAX_K)
992 },
993 CLASSIC,
994 { 0, 0xAA, 0x55, 1 },
995 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
996 },
997 {
998 "tcpdump port 22",
999 .u.insns = {
1000 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1001 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1002 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1003 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1004 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1005 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1007 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1008 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1009 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1010 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1011 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1012 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1013 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1014 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1016 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1017 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1018 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1019 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1020 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1021 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1022 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1023 BPF_STMT(BPF_RET | BPF_K, 0),
1024 },
1025 CLASSIC,
1026 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1027 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1028 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1029 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1030 */
1031 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1032 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1033 0x08, 0x00,
1034 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1035 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1036 0x0a, 0x01, 0x01, 0x95, /* ip src */
1037 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1038 0xc2, 0x24,
1039 0x00, 0x16 /* dst port */ },
1040 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1041 },
1042 {
1043 "tcpdump complex",
1044 .u.insns = {
1045 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1046 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1047 * (len > 115 or len < 30000000000)' -d
1048 */
1049 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1050 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1051 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1052 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1053 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1054 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1055 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1056 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1057 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1058 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1059 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1060 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1061 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1062 BPF_STMT(BPF_ST, 1),
1063 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1064 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1065 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1066 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1067 BPF_STMT(BPF_LD | BPF_MEM, 1),
1068 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1069 BPF_STMT(BPF_ST, 5),
1070 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1071 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1072 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1073 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1074 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1075 BPF_STMT(BPF_LD | BPF_MEM, 5),
1076 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1077 BPF_STMT(BPF_LD | BPF_LEN, 0),
1078 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1079 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1080 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1081 BPF_STMT(BPF_RET | BPF_K, 0),
1082 },
1083 CLASSIC,
1084 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1085 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1086 0x08, 0x00,
1087 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1088 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1089 0x0a, 0x01, 0x01, 0x95, /* ip src */
1090 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1091 0xc2, 0x24,
1092 0x00, 0x16 /* dst port */ },
1093 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1094 },
1095 {
1096 "RET_A",
1097 .u.insns = {
1098 /* check that unitialized X and A contain zeros */
1099 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1100 BPF_STMT(BPF_RET | BPF_A, 0)
1101 },
1102 CLASSIC,
1103 { },
1104 { {1, 0}, {2, 0} },
1105 },
1106 {
1107 "INT: ADD trivial",
1108 .u.insns_int = {
1109 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1110 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1111 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1112 BPF_ALU64_REG(BPF_SUB, R1, R2),
1113 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1114 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1115 BPF_ALU64_REG(BPF_MOV, R0, R1),
1116 BPF_EXIT_INSN(),
1117 },
1118 INTERNAL,
1119 { },
1120 { { 0, 0xfffffffd } }
1121 },
1122 {
1123 "INT: MUL_X",
1124 .u.insns_int = {
1125 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1126 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1127 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1128 BPF_ALU64_REG(BPF_MUL, R1, R2),
1129 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1130 BPF_EXIT_INSN(),
1131 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1132 BPF_EXIT_INSN(),
1133 },
1134 INTERNAL,
1135 { },
1136 { { 0, 1 } }
1137 },
1138 {
1139 "INT: MUL_X2",
1140 .u.insns_int = {
1141 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1142 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1143 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1144 BPF_ALU64_REG(BPF_MUL, R1, R2),
1145 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1146 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1147 BPF_EXIT_INSN(),
1148 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1149 BPF_EXIT_INSN(),
1150 },
1151 INTERNAL,
1152 { },
1153 { { 0, 1 } }
1154 },
1155 {
1156 "INT: MUL32_X",
1157 .u.insns_int = {
1158 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1159 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1160 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1161 BPF_ALU32_REG(BPF_MUL, R1, R2),
1162 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1163 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1164 BPF_EXIT_INSN(),
1165 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1166 BPF_EXIT_INSN(),
1167 },
1168 INTERNAL,
1169 { },
1170 { { 0, 1 } }
1171 },
1172 {
1173 /* Have to test all register combinations, since
1174 * JITing of different registers will produce
1175 * different asm code.
1176 */
1177 "INT: ADD 64-bit",
1178 .u.insns_int = {
1179 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1180 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1181 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1182 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1183 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1184 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1185 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1186 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1187 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1188 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1189 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1190 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1191 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1192 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1193 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1194 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1195 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1196 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1197 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1198 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1199 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1200 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1201 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1202 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1203 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1204 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1205 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1206 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1207 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1208 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1209 BPF_ALU64_REG(BPF_ADD, R0, R0),
1210 BPF_ALU64_REG(BPF_ADD, R0, R1),
1211 BPF_ALU64_REG(BPF_ADD, R0, R2),
1212 BPF_ALU64_REG(BPF_ADD, R0, R3),
1213 BPF_ALU64_REG(BPF_ADD, R0, R4),
1214 BPF_ALU64_REG(BPF_ADD, R0, R5),
1215 BPF_ALU64_REG(BPF_ADD, R0, R6),
1216 BPF_ALU64_REG(BPF_ADD, R0, R7),
1217 BPF_ALU64_REG(BPF_ADD, R0, R8),
1218 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1219 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1220 BPF_EXIT_INSN(),
1221 BPF_ALU64_REG(BPF_ADD, R1, R0),
1222 BPF_ALU64_REG(BPF_ADD, R1, R1),
1223 BPF_ALU64_REG(BPF_ADD, R1, R2),
1224 BPF_ALU64_REG(BPF_ADD, R1, R3),
1225 BPF_ALU64_REG(BPF_ADD, R1, R4),
1226 BPF_ALU64_REG(BPF_ADD, R1, R5),
1227 BPF_ALU64_REG(BPF_ADD, R1, R6),
1228 BPF_ALU64_REG(BPF_ADD, R1, R7),
1229 BPF_ALU64_REG(BPF_ADD, R1, R8),
1230 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1231 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1232 BPF_EXIT_INSN(),
1233 BPF_ALU64_REG(BPF_ADD, R2, R0),
1234 BPF_ALU64_REG(BPF_ADD, R2, R1),
1235 BPF_ALU64_REG(BPF_ADD, R2, R2),
1236 BPF_ALU64_REG(BPF_ADD, R2, R3),
1237 BPF_ALU64_REG(BPF_ADD, R2, R4),
1238 BPF_ALU64_REG(BPF_ADD, R2, R5),
1239 BPF_ALU64_REG(BPF_ADD, R2, R6),
1240 BPF_ALU64_REG(BPF_ADD, R2, R7),
1241 BPF_ALU64_REG(BPF_ADD, R2, R8),
1242 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1243 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1244 BPF_EXIT_INSN(),
1245 BPF_ALU64_REG(BPF_ADD, R3, R0),
1246 BPF_ALU64_REG(BPF_ADD, R3, R1),
1247 BPF_ALU64_REG(BPF_ADD, R3, R2),
1248 BPF_ALU64_REG(BPF_ADD, R3, R3),
1249 BPF_ALU64_REG(BPF_ADD, R3, R4),
1250 BPF_ALU64_REG(BPF_ADD, R3, R5),
1251 BPF_ALU64_REG(BPF_ADD, R3, R6),
1252 BPF_ALU64_REG(BPF_ADD, R3, R7),
1253 BPF_ALU64_REG(BPF_ADD, R3, R8),
1254 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1255 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1256 BPF_EXIT_INSN(),
1257 BPF_ALU64_REG(BPF_ADD, R4, R0),
1258 BPF_ALU64_REG(BPF_ADD, R4, R1),
1259 BPF_ALU64_REG(BPF_ADD, R4, R2),
1260 BPF_ALU64_REG(BPF_ADD, R4, R3),
1261 BPF_ALU64_REG(BPF_ADD, R4, R4),
1262 BPF_ALU64_REG(BPF_ADD, R4, R5),
1263 BPF_ALU64_REG(BPF_ADD, R4, R6),
1264 BPF_ALU64_REG(BPF_ADD, R4, R7),
1265 BPF_ALU64_REG(BPF_ADD, R4, R8),
1266 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1267 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1268 BPF_EXIT_INSN(),
1269 BPF_ALU64_REG(BPF_ADD, R5, R0),
1270 BPF_ALU64_REG(BPF_ADD, R5, R1),
1271 BPF_ALU64_REG(BPF_ADD, R5, R2),
1272 BPF_ALU64_REG(BPF_ADD, R5, R3),
1273 BPF_ALU64_REG(BPF_ADD, R5, R4),
1274 BPF_ALU64_REG(BPF_ADD, R5, R5),
1275 BPF_ALU64_REG(BPF_ADD, R5, R6),
1276 BPF_ALU64_REG(BPF_ADD, R5, R7),
1277 BPF_ALU64_REG(BPF_ADD, R5, R8),
1278 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1279 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1280 BPF_EXIT_INSN(),
1281 BPF_ALU64_REG(BPF_ADD, R6, R0),
1282 BPF_ALU64_REG(BPF_ADD, R6, R1),
1283 BPF_ALU64_REG(BPF_ADD, R6, R2),
1284 BPF_ALU64_REG(BPF_ADD, R6, R3),
1285 BPF_ALU64_REG(BPF_ADD, R6, R4),
1286 BPF_ALU64_REG(BPF_ADD, R6, R5),
1287 BPF_ALU64_REG(BPF_ADD, R6, R6),
1288 BPF_ALU64_REG(BPF_ADD, R6, R7),
1289 BPF_ALU64_REG(BPF_ADD, R6, R8),
1290 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1291 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1292 BPF_EXIT_INSN(),
1293 BPF_ALU64_REG(BPF_ADD, R7, R0),
1294 BPF_ALU64_REG(BPF_ADD, R7, R1),
1295 BPF_ALU64_REG(BPF_ADD, R7, R2),
1296 BPF_ALU64_REG(BPF_ADD, R7, R3),
1297 BPF_ALU64_REG(BPF_ADD, R7, R4),
1298 BPF_ALU64_REG(BPF_ADD, R7, R5),
1299 BPF_ALU64_REG(BPF_ADD, R7, R6),
1300 BPF_ALU64_REG(BPF_ADD, R7, R7),
1301 BPF_ALU64_REG(BPF_ADD, R7, R8),
1302 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1303 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1304 BPF_EXIT_INSN(),
1305 BPF_ALU64_REG(BPF_ADD, R8, R0),
1306 BPF_ALU64_REG(BPF_ADD, R8, R1),
1307 BPF_ALU64_REG(BPF_ADD, R8, R2),
1308 BPF_ALU64_REG(BPF_ADD, R8, R3),
1309 BPF_ALU64_REG(BPF_ADD, R8, R4),
1310 BPF_ALU64_REG(BPF_ADD, R8, R5),
1311 BPF_ALU64_REG(BPF_ADD, R8, R6),
1312 BPF_ALU64_REG(BPF_ADD, R8, R7),
1313 BPF_ALU64_REG(BPF_ADD, R8, R8),
1314 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1315 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1316 BPF_EXIT_INSN(),
1317 BPF_ALU64_REG(BPF_ADD, R9, R0),
1318 BPF_ALU64_REG(BPF_ADD, R9, R1),
1319 BPF_ALU64_REG(BPF_ADD, R9, R2),
1320 BPF_ALU64_REG(BPF_ADD, R9, R3),
1321 BPF_ALU64_REG(BPF_ADD, R9, R4),
1322 BPF_ALU64_REG(BPF_ADD, R9, R5),
1323 BPF_ALU64_REG(BPF_ADD, R9, R6),
1324 BPF_ALU64_REG(BPF_ADD, R9, R7),
1325 BPF_ALU64_REG(BPF_ADD, R9, R8),
1326 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1327 BPF_ALU64_REG(BPF_MOV, R0, R9),
1328 BPF_EXIT_INSN(),
1329 },
1330 INTERNAL,
1331 { },
1332 { { 0, 2957380 } }
1333 },
1334 {
1335 "INT: ADD 32-bit",
1336 .u.insns_int = {
1337 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1338 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1339 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1340 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1341 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1342 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1343 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1344 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1345 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1346 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1347 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1348 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1349 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1350 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1351 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1352 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1353 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1354 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1355 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1356 BPF_ALU32_REG(BPF_ADD, R0, R1),
1357 BPF_ALU32_REG(BPF_ADD, R0, R2),
1358 BPF_ALU32_REG(BPF_ADD, R0, R3),
1359 BPF_ALU32_REG(BPF_ADD, R0, R4),
1360 BPF_ALU32_REG(BPF_ADD, R0, R5),
1361 BPF_ALU32_REG(BPF_ADD, R0, R6),
1362 BPF_ALU32_REG(BPF_ADD, R0, R7),
1363 BPF_ALU32_REG(BPF_ADD, R0, R8),
1364 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1365 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1366 BPF_EXIT_INSN(),
1367 BPF_ALU32_REG(BPF_ADD, R1, R0),
1368 BPF_ALU32_REG(BPF_ADD, R1, R1),
1369 BPF_ALU32_REG(BPF_ADD, R1, R2),
1370 BPF_ALU32_REG(BPF_ADD, R1, R3),
1371 BPF_ALU32_REG(BPF_ADD, R1, R4),
1372 BPF_ALU32_REG(BPF_ADD, R1, R5),
1373 BPF_ALU32_REG(BPF_ADD, R1, R6),
1374 BPF_ALU32_REG(BPF_ADD, R1, R7),
1375 BPF_ALU32_REG(BPF_ADD, R1, R8),
1376 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1377 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1378 BPF_EXIT_INSN(),
1379 BPF_ALU32_REG(BPF_ADD, R2, R0),
1380 BPF_ALU32_REG(BPF_ADD, R2, R1),
1381 BPF_ALU32_REG(BPF_ADD, R2, R2),
1382 BPF_ALU32_REG(BPF_ADD, R2, R3),
1383 BPF_ALU32_REG(BPF_ADD, R2, R4),
1384 BPF_ALU32_REG(BPF_ADD, R2, R5),
1385 BPF_ALU32_REG(BPF_ADD, R2, R6),
1386 BPF_ALU32_REG(BPF_ADD, R2, R7),
1387 BPF_ALU32_REG(BPF_ADD, R2, R8),
1388 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1389 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1390 BPF_EXIT_INSN(),
1391 BPF_ALU32_REG(BPF_ADD, R3, R0),
1392 BPF_ALU32_REG(BPF_ADD, R3, R1),
1393 BPF_ALU32_REG(BPF_ADD, R3, R2),
1394 BPF_ALU32_REG(BPF_ADD, R3, R3),
1395 BPF_ALU32_REG(BPF_ADD, R3, R4),
1396 BPF_ALU32_REG(BPF_ADD, R3, R5),
1397 BPF_ALU32_REG(BPF_ADD, R3, R6),
1398 BPF_ALU32_REG(BPF_ADD, R3, R7),
1399 BPF_ALU32_REG(BPF_ADD, R3, R8),
1400 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1401 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1402 BPF_EXIT_INSN(),
1403 BPF_ALU32_REG(BPF_ADD, R4, R0),
1404 BPF_ALU32_REG(BPF_ADD, R4, R1),
1405 BPF_ALU32_REG(BPF_ADD, R4, R2),
1406 BPF_ALU32_REG(BPF_ADD, R4, R3),
1407 BPF_ALU32_REG(BPF_ADD, R4, R4),
1408 BPF_ALU32_REG(BPF_ADD, R4, R5),
1409 BPF_ALU32_REG(BPF_ADD, R4, R6),
1410 BPF_ALU32_REG(BPF_ADD, R4, R7),
1411 BPF_ALU32_REG(BPF_ADD, R4, R8),
1412 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1413 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1414 BPF_EXIT_INSN(),
1415 BPF_ALU32_REG(BPF_ADD, R5, R0),
1416 BPF_ALU32_REG(BPF_ADD, R5, R1),
1417 BPF_ALU32_REG(BPF_ADD, R5, R2),
1418 BPF_ALU32_REG(BPF_ADD, R5, R3),
1419 BPF_ALU32_REG(BPF_ADD, R5, R4),
1420 BPF_ALU32_REG(BPF_ADD, R5, R5),
1421 BPF_ALU32_REG(BPF_ADD, R5, R6),
1422 BPF_ALU32_REG(BPF_ADD, R5, R7),
1423 BPF_ALU32_REG(BPF_ADD, R5, R8),
1424 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1425 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1426 BPF_EXIT_INSN(),
1427 BPF_ALU32_REG(BPF_ADD, R6, R0),
1428 BPF_ALU32_REG(BPF_ADD, R6, R1),
1429 BPF_ALU32_REG(BPF_ADD, R6, R2),
1430 BPF_ALU32_REG(BPF_ADD, R6, R3),
1431 BPF_ALU32_REG(BPF_ADD, R6, R4),
1432 BPF_ALU32_REG(BPF_ADD, R6, R5),
1433 BPF_ALU32_REG(BPF_ADD, R6, R6),
1434 BPF_ALU32_REG(BPF_ADD, R6, R7),
1435 BPF_ALU32_REG(BPF_ADD, R6, R8),
1436 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1437 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1438 BPF_EXIT_INSN(),
1439 BPF_ALU32_REG(BPF_ADD, R7, R0),
1440 BPF_ALU32_REG(BPF_ADD, R7, R1),
1441 BPF_ALU32_REG(BPF_ADD, R7, R2),
1442 BPF_ALU32_REG(BPF_ADD, R7, R3),
1443 BPF_ALU32_REG(BPF_ADD, R7, R4),
1444 BPF_ALU32_REG(BPF_ADD, R7, R5),
1445 BPF_ALU32_REG(BPF_ADD, R7, R6),
1446 BPF_ALU32_REG(BPF_ADD, R7, R7),
1447 BPF_ALU32_REG(BPF_ADD, R7, R8),
1448 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1449 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1450 BPF_EXIT_INSN(),
1451 BPF_ALU32_REG(BPF_ADD, R8, R0),
1452 BPF_ALU32_REG(BPF_ADD, R8, R1),
1453 BPF_ALU32_REG(BPF_ADD, R8, R2),
1454 BPF_ALU32_REG(BPF_ADD, R8, R3),
1455 BPF_ALU32_REG(BPF_ADD, R8, R4),
1456 BPF_ALU32_REG(BPF_ADD, R8, R5),
1457 BPF_ALU32_REG(BPF_ADD, R8, R6),
1458 BPF_ALU32_REG(BPF_ADD, R8, R7),
1459 BPF_ALU32_REG(BPF_ADD, R8, R8),
1460 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1461 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1462 BPF_EXIT_INSN(),
1463 BPF_ALU32_REG(BPF_ADD, R9, R0),
1464 BPF_ALU32_REG(BPF_ADD, R9, R1),
1465 BPF_ALU32_REG(BPF_ADD, R9, R2),
1466 BPF_ALU32_REG(BPF_ADD, R9, R3),
1467 BPF_ALU32_REG(BPF_ADD, R9, R4),
1468 BPF_ALU32_REG(BPF_ADD, R9, R5),
1469 BPF_ALU32_REG(BPF_ADD, R9, R6),
1470 BPF_ALU32_REG(BPF_ADD, R9, R7),
1471 BPF_ALU32_REG(BPF_ADD, R9, R8),
1472 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1473 BPF_ALU32_REG(BPF_MOV, R0, R9),
1474 BPF_EXIT_INSN(),
1475 },
1476 INTERNAL,
1477 { },
1478 { { 0, 2957380 } }
1479 },
1480 { /* Mainly checking JIT here. */
1481 "INT: SUB",
1482 .u.insns_int = {
1483 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1484 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1485 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1486 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1487 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1488 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1489 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1490 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1491 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1492 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1493 BPF_ALU64_REG(BPF_SUB, R0, R0),
1494 BPF_ALU64_REG(BPF_SUB, R0, R1),
1495 BPF_ALU64_REG(BPF_SUB, R0, R2),
1496 BPF_ALU64_REG(BPF_SUB, R0, R3),
1497 BPF_ALU64_REG(BPF_SUB, R0, R4),
1498 BPF_ALU64_REG(BPF_SUB, R0, R5),
1499 BPF_ALU64_REG(BPF_SUB, R0, R6),
1500 BPF_ALU64_REG(BPF_SUB, R0, R7),
1501 BPF_ALU64_REG(BPF_SUB, R0, R8),
1502 BPF_ALU64_REG(BPF_SUB, R0, R9),
1503 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1504 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1505 BPF_EXIT_INSN(),
1506 BPF_ALU64_REG(BPF_SUB, R1, R0),
1507 BPF_ALU64_REG(BPF_SUB, R1, R2),
1508 BPF_ALU64_REG(BPF_SUB, R1, R3),
1509 BPF_ALU64_REG(BPF_SUB, R1, R4),
1510 BPF_ALU64_REG(BPF_SUB, R1, R5),
1511 BPF_ALU64_REG(BPF_SUB, R1, R6),
1512 BPF_ALU64_REG(BPF_SUB, R1, R7),
1513 BPF_ALU64_REG(BPF_SUB, R1, R8),
1514 BPF_ALU64_REG(BPF_SUB, R1, R9),
1515 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1516 BPF_ALU64_REG(BPF_SUB, R2, R0),
1517 BPF_ALU64_REG(BPF_SUB, R2, R1),
1518 BPF_ALU64_REG(BPF_SUB, R2, R3),
1519 BPF_ALU64_REG(BPF_SUB, R2, R4),
1520 BPF_ALU64_REG(BPF_SUB, R2, R5),
1521 BPF_ALU64_REG(BPF_SUB, R2, R6),
1522 BPF_ALU64_REG(BPF_SUB, R2, R7),
1523 BPF_ALU64_REG(BPF_SUB, R2, R8),
1524 BPF_ALU64_REG(BPF_SUB, R2, R9),
1525 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1526 BPF_ALU64_REG(BPF_SUB, R3, R0),
1527 BPF_ALU64_REG(BPF_SUB, R3, R1),
1528 BPF_ALU64_REG(BPF_SUB, R3, R2),
1529 BPF_ALU64_REG(BPF_SUB, R3, R4),
1530 BPF_ALU64_REG(BPF_SUB, R3, R5),
1531 BPF_ALU64_REG(BPF_SUB, R3, R6),
1532 BPF_ALU64_REG(BPF_SUB, R3, R7),
1533 BPF_ALU64_REG(BPF_SUB, R3, R8),
1534 BPF_ALU64_REG(BPF_SUB, R3, R9),
1535 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1536 BPF_ALU64_REG(BPF_SUB, R4, R0),
1537 BPF_ALU64_REG(BPF_SUB, R4, R1),
1538 BPF_ALU64_REG(BPF_SUB, R4, R2),
1539 BPF_ALU64_REG(BPF_SUB, R4, R3),
1540 BPF_ALU64_REG(BPF_SUB, R4, R5),
1541 BPF_ALU64_REG(BPF_SUB, R4, R6),
1542 BPF_ALU64_REG(BPF_SUB, R4, R7),
1543 BPF_ALU64_REG(BPF_SUB, R4, R8),
1544 BPF_ALU64_REG(BPF_SUB, R4, R9),
1545 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1546 BPF_ALU64_REG(BPF_SUB, R5, R0),
1547 BPF_ALU64_REG(BPF_SUB, R5, R1),
1548 BPF_ALU64_REG(BPF_SUB, R5, R2),
1549 BPF_ALU64_REG(BPF_SUB, R5, R3),
1550 BPF_ALU64_REG(BPF_SUB, R5, R4),
1551 BPF_ALU64_REG(BPF_SUB, R5, R6),
1552 BPF_ALU64_REG(BPF_SUB, R5, R7),
1553 BPF_ALU64_REG(BPF_SUB, R5, R8),
1554 BPF_ALU64_REG(BPF_SUB, R5, R9),
1555 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1556 BPF_ALU64_REG(BPF_SUB, R6, R0),
1557 BPF_ALU64_REG(BPF_SUB, R6, R1),
1558 BPF_ALU64_REG(BPF_SUB, R6, R2),
1559 BPF_ALU64_REG(BPF_SUB, R6, R3),
1560 BPF_ALU64_REG(BPF_SUB, R6, R4),
1561 BPF_ALU64_REG(BPF_SUB, R6, R5),
1562 BPF_ALU64_REG(BPF_SUB, R6, R7),
1563 BPF_ALU64_REG(BPF_SUB, R6, R8),
1564 BPF_ALU64_REG(BPF_SUB, R6, R9),
1565 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1566 BPF_ALU64_REG(BPF_SUB, R7, R0),
1567 BPF_ALU64_REG(BPF_SUB, R7, R1),
1568 BPF_ALU64_REG(BPF_SUB, R7, R2),
1569 BPF_ALU64_REG(BPF_SUB, R7, R3),
1570 BPF_ALU64_REG(BPF_SUB, R7, R4),
1571 BPF_ALU64_REG(BPF_SUB, R7, R5),
1572 BPF_ALU64_REG(BPF_SUB, R7, R6),
1573 BPF_ALU64_REG(BPF_SUB, R7, R8),
1574 BPF_ALU64_REG(BPF_SUB, R7, R9),
1575 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1576 BPF_ALU64_REG(BPF_SUB, R8, R0),
1577 BPF_ALU64_REG(BPF_SUB, R8, R1),
1578 BPF_ALU64_REG(BPF_SUB, R8, R2),
1579 BPF_ALU64_REG(BPF_SUB, R8, R3),
1580 BPF_ALU64_REG(BPF_SUB, R8, R4),
1581 BPF_ALU64_REG(BPF_SUB, R8, R5),
1582 BPF_ALU64_REG(BPF_SUB, R8, R6),
1583 BPF_ALU64_REG(BPF_SUB, R8, R7),
1584 BPF_ALU64_REG(BPF_SUB, R8, R9),
1585 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1586 BPF_ALU64_REG(BPF_SUB, R9, R0),
1587 BPF_ALU64_REG(BPF_SUB, R9, R1),
1588 BPF_ALU64_REG(BPF_SUB, R9, R2),
1589 BPF_ALU64_REG(BPF_SUB, R9, R3),
1590 BPF_ALU64_REG(BPF_SUB, R9, R4),
1591 BPF_ALU64_REG(BPF_SUB, R9, R5),
1592 BPF_ALU64_REG(BPF_SUB, R9, R6),
1593 BPF_ALU64_REG(BPF_SUB, R9, R7),
1594 BPF_ALU64_REG(BPF_SUB, R9, R8),
1595 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1596 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1597 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1598 BPF_ALU64_REG(BPF_SUB, R0, R1),
1599 BPF_ALU64_REG(BPF_SUB, R0, R2),
1600 BPF_ALU64_REG(BPF_SUB, R0, R3),
1601 BPF_ALU64_REG(BPF_SUB, R0, R4),
1602 BPF_ALU64_REG(BPF_SUB, R0, R5),
1603 BPF_ALU64_REG(BPF_SUB, R0, R6),
1604 BPF_ALU64_REG(BPF_SUB, R0, R7),
1605 BPF_ALU64_REG(BPF_SUB, R0, R8),
1606 BPF_ALU64_REG(BPF_SUB, R0, R9),
1607 BPF_EXIT_INSN(),
1608 },
1609 INTERNAL,
1610 { },
1611 { { 0, 11 } }
1612 },
1613 { /* Mainly checking JIT here. */
1614 "INT: XOR",
1615 .u.insns_int = {
1616 BPF_ALU64_REG(BPF_SUB, R0, R0),
1617 BPF_ALU64_REG(BPF_XOR, R1, R1),
1618 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1619 BPF_EXIT_INSN(),
1620 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1621 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1622 BPF_ALU64_REG(BPF_SUB, R1, R1),
1623 BPF_ALU64_REG(BPF_XOR, R2, R2),
1624 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1625 BPF_EXIT_INSN(),
1626 BPF_ALU64_REG(BPF_SUB, R2, R2),
1627 BPF_ALU64_REG(BPF_XOR, R3, R3),
1628 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1629 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1630 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1631 BPF_EXIT_INSN(),
1632 BPF_ALU64_REG(BPF_SUB, R3, R3),
1633 BPF_ALU64_REG(BPF_XOR, R4, R4),
1634 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1635 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1636 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1637 BPF_EXIT_INSN(),
1638 BPF_ALU64_REG(BPF_SUB, R4, R4),
1639 BPF_ALU64_REG(BPF_XOR, R5, R5),
1640 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1641 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1642 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1643 BPF_EXIT_INSN(),
1644 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1645 BPF_ALU64_REG(BPF_SUB, R5, R5),
1646 BPF_ALU64_REG(BPF_XOR, R6, R6),
1647 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1648 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1649 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1650 BPF_EXIT_INSN(),
1651 BPF_ALU64_REG(BPF_SUB, R6, R6),
1652 BPF_ALU64_REG(BPF_XOR, R7, R7),
1653 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1654 BPF_EXIT_INSN(),
1655 BPF_ALU64_REG(BPF_SUB, R7, R7),
1656 BPF_ALU64_REG(BPF_XOR, R8, R8),
1657 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1658 BPF_EXIT_INSN(),
1659 BPF_ALU64_REG(BPF_SUB, R8, R8),
1660 BPF_ALU64_REG(BPF_XOR, R9, R9),
1661 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1662 BPF_EXIT_INSN(),
1663 BPF_ALU64_REG(BPF_SUB, R9, R9),
1664 BPF_ALU64_REG(BPF_XOR, R0, R0),
1665 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_REG(BPF_SUB, R1, R1),
1668 BPF_ALU64_REG(BPF_XOR, R0, R0),
1669 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1670 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1671 BPF_EXIT_INSN(),
1672 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1673 BPF_EXIT_INSN(),
1674 },
1675 INTERNAL,
1676 { },
1677 { { 0, 1 } }
1678 },
1679 { /* Mainly checking JIT here. */
1680 "INT: MUL",
1681 .u.insns_int = {
1682 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1683 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1684 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1685 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1686 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1687 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1688 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1689 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1690 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1691 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1692 BPF_ALU64_REG(BPF_MUL, R0, R0),
1693 BPF_ALU64_REG(BPF_MUL, R0, R1),
1694 BPF_ALU64_REG(BPF_MUL, R0, R2),
1695 BPF_ALU64_REG(BPF_MUL, R0, R3),
1696 BPF_ALU64_REG(BPF_MUL, R0, R4),
1697 BPF_ALU64_REG(BPF_MUL, R0, R5),
1698 BPF_ALU64_REG(BPF_MUL, R0, R6),
1699 BPF_ALU64_REG(BPF_MUL, R0, R7),
1700 BPF_ALU64_REG(BPF_MUL, R0, R8),
1701 BPF_ALU64_REG(BPF_MUL, R0, R9),
1702 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1703 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1704 BPF_EXIT_INSN(),
1705 BPF_ALU64_REG(BPF_MUL, R1, R0),
1706 BPF_ALU64_REG(BPF_MUL, R1, R2),
1707 BPF_ALU64_REG(BPF_MUL, R1, R3),
1708 BPF_ALU64_REG(BPF_MUL, R1, R4),
1709 BPF_ALU64_REG(BPF_MUL, R1, R5),
1710 BPF_ALU64_REG(BPF_MUL, R1, R6),
1711 BPF_ALU64_REG(BPF_MUL, R1, R7),
1712 BPF_ALU64_REG(BPF_MUL, R1, R8),
1713 BPF_ALU64_REG(BPF_MUL, R1, R9),
1714 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1715 BPF_ALU64_REG(BPF_MOV, R2, R1),
1716 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1717 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1718 BPF_EXIT_INSN(),
1719 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1720 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1721 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1722 BPF_EXIT_INSN(),
1723 BPF_ALU64_REG(BPF_MUL, R2, R0),
1724 BPF_ALU64_REG(BPF_MUL, R2, R1),
1725 BPF_ALU64_REG(BPF_MUL, R2, R3),
1726 BPF_ALU64_REG(BPF_MUL, R2, R4),
1727 BPF_ALU64_REG(BPF_MUL, R2, R5),
1728 BPF_ALU64_REG(BPF_MUL, R2, R6),
1729 BPF_ALU64_REG(BPF_MUL, R2, R7),
1730 BPF_ALU64_REG(BPF_MUL, R2, R8),
1731 BPF_ALU64_REG(BPF_MUL, R2, R9),
1732 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1733 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1734 BPF_ALU64_REG(BPF_MOV, R0, R2),
1735 BPF_EXIT_INSN(),
1736 },
1737 INTERNAL,
1738 { },
1739 { { 0, 0x35d97ef2 } }
1740 },
1741 { /* Mainly checking JIT here. */
1742 "MOV REG64",
1743 .u.insns_int = {
1744 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1745 BPF_MOV64_REG(R1, R0),
1746 BPF_MOV64_REG(R2, R1),
1747 BPF_MOV64_REG(R3, R2),
1748 BPF_MOV64_REG(R4, R3),
1749 BPF_MOV64_REG(R5, R4),
1750 BPF_MOV64_REG(R6, R5),
1751 BPF_MOV64_REG(R7, R6),
1752 BPF_MOV64_REG(R8, R7),
1753 BPF_MOV64_REG(R9, R8),
1754 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1755 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1756 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1757 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1758 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1759 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1760 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1761 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1762 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1763 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1764 BPF_ALU64_REG(BPF_ADD, R0, R0),
1765 BPF_ALU64_REG(BPF_ADD, R0, R1),
1766 BPF_ALU64_REG(BPF_ADD, R0, R2),
1767 BPF_ALU64_REG(BPF_ADD, R0, R3),
1768 BPF_ALU64_REG(BPF_ADD, R0, R4),
1769 BPF_ALU64_REG(BPF_ADD, R0, R5),
1770 BPF_ALU64_REG(BPF_ADD, R0, R6),
1771 BPF_ALU64_REG(BPF_ADD, R0, R7),
1772 BPF_ALU64_REG(BPF_ADD, R0, R8),
1773 BPF_ALU64_REG(BPF_ADD, R0, R9),
1774 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1775 BPF_EXIT_INSN(),
1776 },
1777 INTERNAL,
1778 { },
1779 { { 0, 0xfefe } }
1780 },
1781 { /* Mainly checking JIT here. */
1782 "MOV REG32",
1783 .u.insns_int = {
1784 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1785 BPF_MOV64_REG(R1, R0),
1786 BPF_MOV64_REG(R2, R1),
1787 BPF_MOV64_REG(R3, R2),
1788 BPF_MOV64_REG(R4, R3),
1789 BPF_MOV64_REG(R5, R4),
1790 BPF_MOV64_REG(R6, R5),
1791 BPF_MOV64_REG(R7, R6),
1792 BPF_MOV64_REG(R8, R7),
1793 BPF_MOV64_REG(R9, R8),
1794 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1795 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1796 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1797 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1798 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1799 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1800 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1801 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1802 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1803 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1804 BPF_ALU64_REG(BPF_ADD, R0, R0),
1805 BPF_ALU64_REG(BPF_ADD, R0, R1),
1806 BPF_ALU64_REG(BPF_ADD, R0, R2),
1807 BPF_ALU64_REG(BPF_ADD, R0, R3),
1808 BPF_ALU64_REG(BPF_ADD, R0, R4),
1809 BPF_ALU64_REG(BPF_ADD, R0, R5),
1810 BPF_ALU64_REG(BPF_ADD, R0, R6),
1811 BPF_ALU64_REG(BPF_ADD, R0, R7),
1812 BPF_ALU64_REG(BPF_ADD, R0, R8),
1813 BPF_ALU64_REG(BPF_ADD, R0, R9),
1814 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1815 BPF_EXIT_INSN(),
1816 },
1817 INTERNAL,
1818 { },
1819 { { 0, 0xfefe } }
1820 },
1821 { /* Mainly checking JIT here. */
1822 "LD IMM64",
1823 .u.insns_int = {
1824 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1825 BPF_MOV64_REG(R1, R0),
1826 BPF_MOV64_REG(R2, R1),
1827 BPF_MOV64_REG(R3, R2),
1828 BPF_MOV64_REG(R4, R3),
1829 BPF_MOV64_REG(R5, R4),
1830 BPF_MOV64_REG(R6, R5),
1831 BPF_MOV64_REG(R7, R6),
1832 BPF_MOV64_REG(R8, R7),
1833 BPF_MOV64_REG(R9, R8),
1834 BPF_LD_IMM64(R0, 0x0LL),
1835 BPF_LD_IMM64(R1, 0x0LL),
1836 BPF_LD_IMM64(R2, 0x0LL),
1837 BPF_LD_IMM64(R3, 0x0LL),
1838 BPF_LD_IMM64(R4, 0x0LL),
1839 BPF_LD_IMM64(R5, 0x0LL),
1840 BPF_LD_IMM64(R6, 0x0LL),
1841 BPF_LD_IMM64(R7, 0x0LL),
1842 BPF_LD_IMM64(R8, 0x0LL),
1843 BPF_LD_IMM64(R9, 0x0LL),
1844 BPF_ALU64_REG(BPF_ADD, R0, R0),
1845 BPF_ALU64_REG(BPF_ADD, R0, R1),
1846 BPF_ALU64_REG(BPF_ADD, R0, R2),
1847 BPF_ALU64_REG(BPF_ADD, R0, R3),
1848 BPF_ALU64_REG(BPF_ADD, R0, R4),
1849 BPF_ALU64_REG(BPF_ADD, R0, R5),
1850 BPF_ALU64_REG(BPF_ADD, R0, R6),
1851 BPF_ALU64_REG(BPF_ADD, R0, R7),
1852 BPF_ALU64_REG(BPF_ADD, R0, R8),
1853 BPF_ALU64_REG(BPF_ADD, R0, R9),
1854 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1855 BPF_EXIT_INSN(),
1856 },
1857 INTERNAL,
1858 { },
1859 { { 0, 0xfefe } }
1860 },
1861 {
1862 "INT: ALU MIX",
1863 .u.insns_int = {
1864 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1865 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1866 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1867 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1868 BPF_ALU64_REG(BPF_DIV, R0, R2),
1869 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1870 BPF_EXIT_INSN(),
1871 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1872 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1873 BPF_EXIT_INSN(),
1874 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1875 BPF_EXIT_INSN(),
1876 },
1877 INTERNAL,
1878 { },
1879 { { 0, -1 } }
1880 },
1881 {
1882 "INT: shifts by register",
1883 .u.insns_int = {
1884 BPF_MOV64_IMM(R0, -1234),
1885 BPF_MOV64_IMM(R1, 1),
1886 BPF_ALU32_REG(BPF_RSH, R0, R1),
1887 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1888 BPF_EXIT_INSN(),
1889 BPF_MOV64_IMM(R2, 1),
1890 BPF_ALU64_REG(BPF_LSH, R0, R2),
1891 BPF_MOV32_IMM(R4, -1234),
1892 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1893 BPF_EXIT_INSN(),
1894 BPF_ALU64_IMM(BPF_AND, R4, 63),
1895 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1896 BPF_MOV64_IMM(R3, 47),
1897 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1898 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1899 BPF_EXIT_INSN(),
1900 BPF_MOV64_IMM(R2, 1),
1901 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1902 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1903 BPF_EXIT_INSN(),
1904 BPF_MOV64_IMM(R4, 4),
1905 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1906 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1907 BPF_EXIT_INSN(),
1908 BPF_MOV64_IMM(R4, 5),
1909 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1910 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1911 BPF_EXIT_INSN(),
1912 BPF_MOV64_IMM(R0, -1),
1913 BPF_EXIT_INSN(),
1914 },
1915 INTERNAL,
1916 { },
1917 { { 0, -1 } }
1918 },
1919 {
1920 "check: missing ret",
1921 .u.insns = {
1922 BPF_STMT(BPF_LD | BPF_IMM, 1),
1923 },
1924 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1925 { },
1926 { },
1927 .fill_helper = NULL,
1928 .expected_errcode = -EINVAL,
1929 },
1930 {
1931 "check: div_k_0",
1932 .u.insns = {
1933 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1934 BPF_STMT(BPF_RET | BPF_K, 0)
1935 },
1936 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1937 { },
1938 { },
1939 .fill_helper = NULL,
1940 .expected_errcode = -EINVAL,
1941 },
1942 {
1943 "check: unknown insn",
1944 .u.insns = {
1945 /* seccomp insn, rejected in socket filter */
1946 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1947 BPF_STMT(BPF_RET | BPF_K, 0)
1948 },
1949 CLASSIC | FLAG_EXPECTED_FAIL,
1950 { },
1951 { },
1952 .fill_helper = NULL,
1953 .expected_errcode = -EINVAL,
1954 },
1955 {
1956 "check: out of range spill/fill",
1957 .u.insns = {
1958 BPF_STMT(BPF_STX, 16),
1959 BPF_STMT(BPF_RET | BPF_K, 0)
1960 },
1961 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1962 { },
1963 { },
1964 .fill_helper = NULL,
1965 .expected_errcode = -EINVAL,
1966 },
1967 {
1968 "JUMPS + HOLES",
1969 .u.insns = {
1970 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1971 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1972 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1973 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1974 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1975 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1976 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1977 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1978 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1986 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1987 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1988 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1989 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1990 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1991 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1992 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1993 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1994 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1995 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1996 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1997 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2005 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2007 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2008 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2009 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2010 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2011 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2012 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2013 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2014 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2023 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2024 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2025 BPF_STMT(BPF_RET | BPF_A, 0),
2026 BPF_STMT(BPF_RET | BPF_A, 0),
2027 },
2028 CLASSIC,
2029 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2030 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2031 0x08, 0x00,
2032 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2033 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2034 0xc0, 0xa8, 0x33, 0x01,
2035 0xc0, 0xa8, 0x33, 0x02,
2036 0xbb, 0xb6,
2037 0xa9, 0xfa,
2038 0x00, 0x14, 0x00, 0x00,
2039 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2040 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2041 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2042 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2043 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2044 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2045 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2046 0xcc, 0xcc, 0xcc, 0xcc },
2047 { { 88, 0x001b } }
2048 },
2049 {
2050 "check: RET X",
2051 .u.insns = {
2052 BPF_STMT(BPF_RET | BPF_X, 0),
2053 },
2054 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2055 { },
2056 { },
2057 .fill_helper = NULL,
2058 .expected_errcode = -EINVAL,
2059 },
2060 {
2061 "check: LDX + RET X",
2062 .u.insns = {
2063 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2064 BPF_STMT(BPF_RET | BPF_X, 0),
2065 },
2066 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2067 { },
2068 { },
2069 .fill_helper = NULL,
2070 .expected_errcode = -EINVAL,
2071 },
2072 { /* Mainly checking JIT here. */
2073 "M[]: alt STX + LDX",
2074 .u.insns = {
2075 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2076 BPF_STMT(BPF_STX, 0),
2077 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2078 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2079 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2080 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2081 BPF_STMT(BPF_STX, 1),
2082 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2083 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2084 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2085 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2086 BPF_STMT(BPF_STX, 2),
2087 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2088 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2089 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2090 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2091 BPF_STMT(BPF_STX, 3),
2092 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2093 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2094 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2095 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2096 BPF_STMT(BPF_STX, 4),
2097 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2098 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2099 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2100 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2101 BPF_STMT(BPF_STX, 5),
2102 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2103 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2105 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2106 BPF_STMT(BPF_STX, 6),
2107 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2108 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2109 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2110 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2111 BPF_STMT(BPF_STX, 7),
2112 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2113 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2114 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2115 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2116 BPF_STMT(BPF_STX, 8),
2117 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2118 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2119 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2120 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2121 BPF_STMT(BPF_STX, 9),
2122 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2123 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2124 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2125 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2126 BPF_STMT(BPF_STX, 10),
2127 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2128 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2129 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2130 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2131 BPF_STMT(BPF_STX, 11),
2132 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2133 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2134 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2135 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2136 BPF_STMT(BPF_STX, 12),
2137 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2138 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2139 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2140 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2141 BPF_STMT(BPF_STX, 13),
2142 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2143 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2144 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2145 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2146 BPF_STMT(BPF_STX, 14),
2147 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2148 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2149 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2150 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2151 BPF_STMT(BPF_STX, 15),
2152 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2153 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2154 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2155 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2156 BPF_STMT(BPF_RET | BPF_A, 0),
2157 },
2158 CLASSIC | FLAG_NO_DATA,
2159 { },
2160 { { 0, 116 } },
2161 },
2162 { /* Mainly checking JIT here. */
2163 "M[]: full STX + full LDX",
2164 .u.insns = {
2165 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2166 BPF_STMT(BPF_STX, 0),
2167 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2168 BPF_STMT(BPF_STX, 1),
2169 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2170 BPF_STMT(BPF_STX, 2),
2171 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2172 BPF_STMT(BPF_STX, 3),
2173 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2174 BPF_STMT(BPF_STX, 4),
2175 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2176 BPF_STMT(BPF_STX, 5),
2177 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2178 BPF_STMT(BPF_STX, 6),
2179 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2180 BPF_STMT(BPF_STX, 7),
2181 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2182 BPF_STMT(BPF_STX, 8),
2183 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2184 BPF_STMT(BPF_STX, 9),
2185 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2186 BPF_STMT(BPF_STX, 10),
2187 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2188 BPF_STMT(BPF_STX, 11),
2189 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2190 BPF_STMT(BPF_STX, 12),
2191 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2192 BPF_STMT(BPF_STX, 13),
2193 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2194 BPF_STMT(BPF_STX, 14),
2195 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2196 BPF_STMT(BPF_STX, 15),
2197 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2198 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2199 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2200 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2201 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2202 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2203 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2204 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2205 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2207 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2208 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2209 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2210 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2211 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2212 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2213 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2214 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2215 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2216 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2217 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2218 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2219 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2220 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2221 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2222 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2223 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2224 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2225 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2227 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2228 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2229 BPF_STMT(BPF_RET | BPF_A, 0),
2230 },
2231 CLASSIC | FLAG_NO_DATA,
2232 { },
2233 { { 0, 0x2a5a5e5 } },
2234 },
2235 {
2236 "check: SKF_AD_MAX",
2237 .u.insns = {
2238 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2239 SKF_AD_OFF + SKF_AD_MAX),
2240 BPF_STMT(BPF_RET | BPF_A, 0),
2241 },
2242 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2243 { },
2244 { },
2245 .fill_helper = NULL,
2246 .expected_errcode = -EINVAL,
2247 },
2248 { /* Passes checker but fails during runtime. */
2249 "LD [SKF_AD_OFF-1]",
2250 .u.insns = {
2251 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2252 SKF_AD_OFF - 1),
2253 BPF_STMT(BPF_RET | BPF_K, 1),
2254 },
2255 CLASSIC,
2256 { },
2257 { { 1, 0 } },
2258 },
2259 {
2260 "load 64-bit immediate",
2261 .u.insns_int = {
2262 BPF_LD_IMM64(R1, 0x567800001234LL),
2263 BPF_MOV64_REG(R2, R1),
2264 BPF_MOV64_REG(R3, R2),
2265 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2266 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2267 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2268 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2269 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2270 BPF_EXIT_INSN(),
2271 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2272 BPF_EXIT_INSN(),
2273 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2274 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2275 BPF_EXIT_INSN(),
2276 },
2277 INTERNAL,
2278 { },
2279 { { 0, 1 } }
2280 },
2281 /* BPF_ALU | BPF_MOV | BPF_X */
2282 {
2283 "ALU_MOV_X: dst = 2",
2284 .u.insns_int = {
2285 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2286 BPF_ALU32_REG(BPF_MOV, R0, R1),
2287 BPF_EXIT_INSN(),
2288 },
2289 INTERNAL,
2290 { },
2291 { { 0, 2 } },
2292 },
2293 {
2294 "ALU_MOV_X: dst = 4294967295",
2295 .u.insns_int = {
2296 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2297 BPF_ALU32_REG(BPF_MOV, R0, R1),
2298 BPF_EXIT_INSN(),
2299 },
2300 INTERNAL,
2301 { },
2302 { { 0, 4294967295U } },
2303 },
2304 {
2305 "ALU64_MOV_X: dst = 2",
2306 .u.insns_int = {
2307 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2308 BPF_ALU64_REG(BPF_MOV, R0, R1),
2309 BPF_EXIT_INSN(),
2310 },
2311 INTERNAL,
2312 { },
2313 { { 0, 2 } },
2314 },
2315 {
2316 "ALU64_MOV_X: dst = 4294967295",
2317 .u.insns_int = {
2318 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2319 BPF_ALU64_REG(BPF_MOV, R0, R1),
2320 BPF_EXIT_INSN(),
2321 },
2322 INTERNAL,
2323 { },
2324 { { 0, 4294967295U } },
2325 },
2326 /* BPF_ALU | BPF_MOV | BPF_K */
2327 {
2328 "ALU_MOV_K: dst = 2",
2329 .u.insns_int = {
2330 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2331 BPF_EXIT_INSN(),
2332 },
2333 INTERNAL,
2334 { },
2335 { { 0, 2 } },
2336 },
2337 {
2338 "ALU_MOV_K: dst = 4294967295",
2339 .u.insns_int = {
2340 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2341 BPF_EXIT_INSN(),
2342 },
2343 INTERNAL,
2344 { },
2345 { { 0, 4294967295U } },
2346 },
2347 {
2348 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2349 .u.insns_int = {
2350 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2351 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2352 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2353 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2354 BPF_MOV32_IMM(R0, 2),
2355 BPF_EXIT_INSN(),
2356 BPF_MOV32_IMM(R0, 1),
2357 BPF_EXIT_INSN(),
2358 },
2359 INTERNAL,
2360 { },
2361 { { 0, 0x1 } },
2362 },
2363 {
2364 "ALU64_MOV_K: dst = 2",
2365 .u.insns_int = {
2366 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2367 BPF_EXIT_INSN(),
2368 },
2369 INTERNAL,
2370 { },
2371 { { 0, 2 } },
2372 },
2373 {
2374 "ALU64_MOV_K: dst = 2147483647",
2375 .u.insns_int = {
2376 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2377 BPF_EXIT_INSN(),
2378 },
2379 INTERNAL,
2380 { },
2381 { { 0, 2147483647 } },
2382 },
2383 {
2384 "ALU64_OR_K: dst = 0x0",
2385 .u.insns_int = {
2386 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2387 BPF_LD_IMM64(R3, 0x0),
2388 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2389 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2390 BPF_MOV32_IMM(R0, 2),
2391 BPF_EXIT_INSN(),
2392 BPF_MOV32_IMM(R0, 1),
2393 BPF_EXIT_INSN(),
2394 },
2395 INTERNAL,
2396 { },
2397 { { 0, 0x1 } },
2398 },
2399 {
2400 "ALU64_MOV_K: dst = -1",
2401 .u.insns_int = {
2402 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2403 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2404 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2405 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2406 BPF_MOV32_IMM(R0, 2),
2407 BPF_EXIT_INSN(),
2408 BPF_MOV32_IMM(R0, 1),
2409 BPF_EXIT_INSN(),
2410 },
2411 INTERNAL,
2412 { },
2413 { { 0, 0x1 } },
2414 },
2415 /* BPF_ALU | BPF_ADD | BPF_X */
2416 {
2417 "ALU_ADD_X: 1 + 2 = 3",
2418 .u.insns_int = {
2419 BPF_LD_IMM64(R0, 1),
2420 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2421 BPF_ALU32_REG(BPF_ADD, R0, R1),
2422 BPF_EXIT_INSN(),
2423 },
2424 INTERNAL,
2425 { },
2426 { { 0, 3 } },
2427 },
2428 {
2429 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2430 .u.insns_int = {
2431 BPF_LD_IMM64(R0, 1),
2432 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2433 BPF_ALU32_REG(BPF_ADD, R0, R1),
2434 BPF_EXIT_INSN(),
2435 },
2436 INTERNAL,
2437 { },
2438 { { 0, 4294967295U } },
2439 },
2440 {
2441 "ALU_ADD_X: 2 + 4294967294 = 0",
2442 .u.insns_int = {
2443 BPF_LD_IMM64(R0, 2),
2444 BPF_LD_IMM64(R1, 4294967294U),
2445 BPF_ALU32_REG(BPF_ADD, R0, R1),
2446 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2447 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2448 BPF_EXIT_INSN(),
2449 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2450 BPF_EXIT_INSN(),
2451 },
2452 INTERNAL,
2453 { },
2454 { { 0, 1 } },
2455 },
2456 {
2457 "ALU64_ADD_X: 1 + 2 = 3",
2458 .u.insns_int = {
2459 BPF_LD_IMM64(R0, 1),
2460 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2461 BPF_ALU64_REG(BPF_ADD, R0, R1),
2462 BPF_EXIT_INSN(),
2463 },
2464 INTERNAL,
2465 { },
2466 { { 0, 3 } },
2467 },
2468 {
2469 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2470 .u.insns_int = {
2471 BPF_LD_IMM64(R0, 1),
2472 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2473 BPF_ALU64_REG(BPF_ADD, R0, R1),
2474 BPF_EXIT_INSN(),
2475 },
2476 INTERNAL,
2477 { },
2478 { { 0, 4294967295U } },
2479 },
2480 {
2481 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2482 .u.insns_int = {
2483 BPF_LD_IMM64(R0, 2),
2484 BPF_LD_IMM64(R1, 4294967294U),
2485 BPF_LD_IMM64(R2, 4294967296ULL),
2486 BPF_ALU64_REG(BPF_ADD, R0, R1),
2487 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2488 BPF_MOV32_IMM(R0, 0),
2489 BPF_EXIT_INSN(),
2490 BPF_MOV32_IMM(R0, 1),
2491 BPF_EXIT_INSN(),
2492 },
2493 INTERNAL,
2494 { },
2495 { { 0, 1 } },
2496 },
2497 /* BPF_ALU | BPF_ADD | BPF_K */
2498 {
2499 "ALU_ADD_K: 1 + 2 = 3",
2500 .u.insns_int = {
2501 BPF_LD_IMM64(R0, 1),
2502 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2503 BPF_EXIT_INSN(),
2504 },
2505 INTERNAL,
2506 { },
2507 { { 0, 3 } },
2508 },
2509 {
2510 "ALU_ADD_K: 3 + 0 = 3",
2511 .u.insns_int = {
2512 BPF_LD_IMM64(R0, 3),
2513 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2514 BPF_EXIT_INSN(),
2515 },
2516 INTERNAL,
2517 { },
2518 { { 0, 3 } },
2519 },
2520 {
2521 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2522 .u.insns_int = {
2523 BPF_LD_IMM64(R0, 1),
2524 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2525 BPF_EXIT_INSN(),
2526 },
2527 INTERNAL,
2528 { },
2529 { { 0, 4294967295U } },
2530 },
2531 {
2532 "ALU_ADD_K: 4294967294 + 2 = 0",
2533 .u.insns_int = {
2534 BPF_LD_IMM64(R0, 4294967294U),
2535 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2536 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2537 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2538 BPF_EXIT_INSN(),
2539 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2540 BPF_EXIT_INSN(),
2541 },
2542 INTERNAL,
2543 { },
2544 { { 0, 1 } },
2545 },
2546 {
2547 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2548 .u.insns_int = {
2549 BPF_LD_IMM64(R2, 0x0),
2550 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2551 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2552 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2553 BPF_MOV32_IMM(R0, 2),
2554 BPF_EXIT_INSN(),
2555 BPF_MOV32_IMM(R0, 1),
2556 BPF_EXIT_INSN(),
2557 },
2558 INTERNAL,
2559 { },
2560 { { 0, 0x1 } },
2561 },
2562 {
2563 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2564 .u.insns_int = {
2565 BPF_LD_IMM64(R2, 0x0),
2566 BPF_LD_IMM64(R3, 0xffff),
2567 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2568 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2569 BPF_MOV32_IMM(R0, 2),
2570 BPF_EXIT_INSN(),
2571 BPF_MOV32_IMM(R0, 1),
2572 BPF_EXIT_INSN(),
2573 },
2574 INTERNAL,
2575 { },
2576 { { 0, 0x1 } },
2577 },
2578 {
2579 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2580 .u.insns_int = {
2581 BPF_LD_IMM64(R2, 0x0),
2582 BPF_LD_IMM64(R3, 0x7fffffff),
2583 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2584 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2585 BPF_MOV32_IMM(R0, 2),
2586 BPF_EXIT_INSN(),
2587 BPF_MOV32_IMM(R0, 1),
2588 BPF_EXIT_INSN(),
2589 },
2590 INTERNAL,
2591 { },
2592 { { 0, 0x1 } },
2593 },
2594 {
2595 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2596 .u.insns_int = {
2597 BPF_LD_IMM64(R2, 0x0),
2598 BPF_LD_IMM64(R3, 0x80000000),
2599 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2600 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2601 BPF_MOV32_IMM(R0, 2),
2602 BPF_EXIT_INSN(),
2603 BPF_MOV32_IMM(R0, 1),
2604 BPF_EXIT_INSN(),
2605 },
2606 INTERNAL,
2607 { },
2608 { { 0, 0x1 } },
2609 },
2610 {
2611 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2612 .u.insns_int = {
2613 BPF_LD_IMM64(R2, 0x0),
2614 BPF_LD_IMM64(R3, 0x80008000),
2615 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2616 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2617 BPF_MOV32_IMM(R0, 2),
2618 BPF_EXIT_INSN(),
2619 BPF_MOV32_IMM(R0, 1),
2620 BPF_EXIT_INSN(),
2621 },
2622 INTERNAL,
2623 { },
2624 { { 0, 0x1 } },
2625 },
2626 {
2627 "ALU64_ADD_K: 1 + 2 = 3",
2628 .u.insns_int = {
2629 BPF_LD_IMM64(R0, 1),
2630 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2631 BPF_EXIT_INSN(),
2632 },
2633 INTERNAL,
2634 { },
2635 { { 0, 3 } },
2636 },
2637 {
2638 "ALU64_ADD_K: 3 + 0 = 3",
2639 .u.insns_int = {
2640 BPF_LD_IMM64(R0, 3),
2641 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2642 BPF_EXIT_INSN(),
2643 },
2644 INTERNAL,
2645 { },
2646 { { 0, 3 } },
2647 },
2648 {
2649 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2650 .u.insns_int = {
2651 BPF_LD_IMM64(R0, 1),
2652 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2653 BPF_EXIT_INSN(),
2654 },
2655 INTERNAL,
2656 { },
2657 { { 0, 2147483647 } },
2658 },
2659 {
2660 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2661 .u.insns_int = {
2662 BPF_LD_IMM64(R0, 4294967294U),
2663 BPF_LD_IMM64(R1, 4294967296ULL),
2664 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2665 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2667 BPF_EXIT_INSN(),
2668 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2669 BPF_EXIT_INSN(),
2670 },
2671 INTERNAL,
2672 { },
2673 { { 0, 1 } },
2674 },
2675 {
2676 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2677 .u.insns_int = {
2678 BPF_LD_IMM64(R0, 2147483646),
2679 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2680 BPF_EXIT_INSN(),
2681 },
2682 INTERNAL,
2683 { },
2684 { { 0, -1 } },
2685 },
2686 {
2687 "ALU64_ADD_K: 1 + 0 = 1",
2688 .u.insns_int = {
2689 BPF_LD_IMM64(R2, 0x1),
2690 BPF_LD_IMM64(R3, 0x1),
2691 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2692 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2693 BPF_MOV32_IMM(R0, 2),
2694 BPF_EXIT_INSN(),
2695 BPF_MOV32_IMM(R0, 1),
2696 BPF_EXIT_INSN(),
2697 },
2698 INTERNAL,
2699 { },
2700 { { 0, 0x1 } },
2701 },
2702 {
2703 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2704 .u.insns_int = {
2705 BPF_LD_IMM64(R2, 0x0),
2706 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2707 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2708 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2709 BPF_MOV32_IMM(R0, 2),
2710 BPF_EXIT_INSN(),
2711 BPF_MOV32_IMM(R0, 1),
2712 BPF_EXIT_INSN(),
2713 },
2714 INTERNAL,
2715 { },
2716 { { 0, 0x1 } },
2717 },
2718 {
2719 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2720 .u.insns_int = {
2721 BPF_LD_IMM64(R2, 0x0),
2722 BPF_LD_IMM64(R3, 0xffff),
2723 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2724 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2725 BPF_MOV32_IMM(R0, 2),
2726 BPF_EXIT_INSN(),
2727 BPF_MOV32_IMM(R0, 1),
2728 BPF_EXIT_INSN(),
2729 },
2730 INTERNAL,
2731 { },
2732 { { 0, 0x1 } },
2733 },
2734 {
2735 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2736 .u.insns_int = {
2737 BPF_LD_IMM64(R2, 0x0),
2738 BPF_LD_IMM64(R3, 0x7fffffff),
2739 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2740 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2741 BPF_MOV32_IMM(R0, 2),
2742 BPF_EXIT_INSN(),
2743 BPF_MOV32_IMM(R0, 1),
2744 BPF_EXIT_INSN(),
2745 },
2746 INTERNAL,
2747 { },
2748 { { 0, 0x1 } },
2749 },
2750 {
2751 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2752 .u.insns_int = {
2753 BPF_LD_IMM64(R2, 0x0),
2754 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2755 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2756 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2757 BPF_MOV32_IMM(R0, 2),
2758 BPF_EXIT_INSN(),
2759 BPF_MOV32_IMM(R0, 1),
2760 BPF_EXIT_INSN(),
2761 },
2762 INTERNAL,
2763 { },
2764 { { 0, 0x1 } },
2765 },
2766 {
2767 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2768 .u.insns_int = {
2769 BPF_LD_IMM64(R2, 0x0),
2770 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2771 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2772 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2773 BPF_MOV32_IMM(R0, 2),
2774 BPF_EXIT_INSN(),
2775 BPF_MOV32_IMM(R0, 1),
2776 BPF_EXIT_INSN(),
2777 },
2778 INTERNAL,
2779 { },
2780 { { 0, 0x1 } },
2781 },
2782 /* BPF_ALU | BPF_SUB | BPF_X */
2783 {
2784 "ALU_SUB_X: 3 - 1 = 2",
2785 .u.insns_int = {
2786 BPF_LD_IMM64(R0, 3),
2787 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2788 BPF_ALU32_REG(BPF_SUB, R0, R1),
2789 BPF_EXIT_INSN(),
2790 },
2791 INTERNAL,
2792 { },
2793 { { 0, 2 } },
2794 },
2795 {
2796 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2797 .u.insns_int = {
2798 BPF_LD_IMM64(R0, 4294967295U),
2799 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2800 BPF_ALU32_REG(BPF_SUB, R0, R1),
2801 BPF_EXIT_INSN(),
2802 },
2803 INTERNAL,
2804 { },
2805 { { 0, 1 } },
2806 },
2807 {
2808 "ALU64_SUB_X: 3 - 1 = 2",
2809 .u.insns_int = {
2810 BPF_LD_IMM64(R0, 3),
2811 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2812 BPF_ALU64_REG(BPF_SUB, R0, R1),
2813 BPF_EXIT_INSN(),
2814 },
2815 INTERNAL,
2816 { },
2817 { { 0, 2 } },
2818 },
2819 {
2820 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2821 .u.insns_int = {
2822 BPF_LD_IMM64(R0, 4294967295U),
2823 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2824 BPF_ALU64_REG(BPF_SUB, R0, R1),
2825 BPF_EXIT_INSN(),
2826 },
2827 INTERNAL,
2828 { },
2829 { { 0, 1 } },
2830 },
2831 /* BPF_ALU | BPF_SUB | BPF_K */
2832 {
2833 "ALU_SUB_K: 3 - 1 = 2",
2834 .u.insns_int = {
2835 BPF_LD_IMM64(R0, 3),
2836 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2837 BPF_EXIT_INSN(),
2838 },
2839 INTERNAL,
2840 { },
2841 { { 0, 2 } },
2842 },
2843 {
2844 "ALU_SUB_K: 3 - 0 = 3",
2845 .u.insns_int = {
2846 BPF_LD_IMM64(R0, 3),
2847 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2848 BPF_EXIT_INSN(),
2849 },
2850 INTERNAL,
2851 { },
2852 { { 0, 3 } },
2853 },
2854 {
2855 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2856 .u.insns_int = {
2857 BPF_LD_IMM64(R0, 4294967295U),
2858 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
2859 BPF_EXIT_INSN(),
2860 },
2861 INTERNAL,
2862 { },
2863 { { 0, 1 } },
2864 },
2865 {
2866 "ALU64_SUB_K: 3 - 1 = 2",
2867 .u.insns_int = {
2868 BPF_LD_IMM64(R0, 3),
2869 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2870 BPF_EXIT_INSN(),
2871 },
2872 INTERNAL,
2873 { },
2874 { { 0, 2 } },
2875 },
2876 {
2877 "ALU64_SUB_K: 3 - 0 = 3",
2878 .u.insns_int = {
2879 BPF_LD_IMM64(R0, 3),
2880 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2881 BPF_EXIT_INSN(),
2882 },
2883 INTERNAL,
2884 { },
2885 { { 0, 3 } },
2886 },
2887 {
2888 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2889 .u.insns_int = {
2890 BPF_LD_IMM64(R0, 4294967294U),
2891 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
2892 BPF_EXIT_INSN(),
2893 },
2894 INTERNAL,
2895 { },
2896 { { 0, -1 } },
2897 },
2898 {
2899 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2900 .u.insns_int = {
2901 BPF_LD_IMM64(R0, 2147483646),
2902 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2903 BPF_EXIT_INSN(),
2904 },
2905 INTERNAL,
2906 { },
2907 { { 0, -1 } },
2908 },
2909 /* BPF_ALU | BPF_MUL | BPF_X */
2910 {
2911 "ALU_MUL_X: 2 * 3 = 6",
2912 .u.insns_int = {
2913 BPF_LD_IMM64(R0, 2),
2914 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2915 BPF_ALU32_REG(BPF_MUL, R0, R1),
2916 BPF_EXIT_INSN(),
2917 },
2918 INTERNAL,
2919 { },
2920 { { 0, 6 } },
2921 },
2922 {
2923 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2924 .u.insns_int = {
2925 BPF_LD_IMM64(R0, 2),
2926 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2927 BPF_ALU32_REG(BPF_MUL, R0, R1),
2928 BPF_EXIT_INSN(),
2929 },
2930 INTERNAL,
2931 { },
2932 { { 0, 0xFFFFFFF0 } },
2933 },
2934 {
2935 "ALU_MUL_X: -1 * -1 = 1",
2936 .u.insns_int = {
2937 BPF_LD_IMM64(R0, -1),
2938 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2939 BPF_ALU32_REG(BPF_MUL, R0, R1),
2940 BPF_EXIT_INSN(),
2941 },
2942 INTERNAL,
2943 { },
2944 { { 0, 1 } },
2945 },
2946 {
2947 "ALU64_MUL_X: 2 * 3 = 6",
2948 .u.insns_int = {
2949 BPF_LD_IMM64(R0, 2),
2950 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2951 BPF_ALU64_REG(BPF_MUL, R0, R1),
2952 BPF_EXIT_INSN(),
2953 },
2954 INTERNAL,
2955 { },
2956 { { 0, 6 } },
2957 },
2958 {
2959 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2960 .u.insns_int = {
2961 BPF_LD_IMM64(R0, 1),
2962 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2963 BPF_ALU64_REG(BPF_MUL, R0, R1),
2964 BPF_EXIT_INSN(),
2965 },
2966 INTERNAL,
2967 { },
2968 { { 0, 2147483647 } },
2969 },
2970 /* BPF_ALU | BPF_MUL | BPF_K */
2971 {
2972 "ALU_MUL_K: 2 * 3 = 6",
2973 .u.insns_int = {
2974 BPF_LD_IMM64(R0, 2),
2975 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2976 BPF_EXIT_INSN(),
2977 },
2978 INTERNAL,
2979 { },
2980 { { 0, 6 } },
2981 },
2982 {
2983 "ALU_MUL_K: 3 * 1 = 3",
2984 .u.insns_int = {
2985 BPF_LD_IMM64(R0, 3),
2986 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2987 BPF_EXIT_INSN(),
2988 },
2989 INTERNAL,
2990 { },
2991 { { 0, 3 } },
2992 },
2993 {
2994 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2995 .u.insns_int = {
2996 BPF_LD_IMM64(R0, 2),
2997 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2998 BPF_EXIT_INSN(),
2999 },
3000 INTERNAL,
3001 { },
3002 { { 0, 0xFFFFFFF0 } },
3003 },
3004 {
3005 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3006 .u.insns_int = {
3007 BPF_LD_IMM64(R2, 0x1),
3008 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3009 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3010 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3011 BPF_MOV32_IMM(R0, 2),
3012 BPF_EXIT_INSN(),
3013 BPF_MOV32_IMM(R0, 1),
3014 BPF_EXIT_INSN(),
3015 },
3016 INTERNAL,
3017 { },
3018 { { 0, 0x1 } },
3019 },
3020 {
3021 "ALU64_MUL_K: 2 * 3 = 6",
3022 .u.insns_int = {
3023 BPF_LD_IMM64(R0, 2),
3024 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3025 BPF_EXIT_INSN(),
3026 },
3027 INTERNAL,
3028 { },
3029 { { 0, 6 } },
3030 },
3031 {
3032 "ALU64_MUL_K: 3 * 1 = 3",
3033 .u.insns_int = {
3034 BPF_LD_IMM64(R0, 3),
3035 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3036 BPF_EXIT_INSN(),
3037 },
3038 INTERNAL,
3039 { },
3040 { { 0, 3 } },
3041 },
3042 {
3043 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3044 .u.insns_int = {
3045 BPF_LD_IMM64(R0, 1),
3046 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3047 BPF_EXIT_INSN(),
3048 },
3049 INTERNAL,
3050 { },
3051 { { 0, 2147483647 } },
3052 },
3053 {
3054 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3055 .u.insns_int = {
3056 BPF_LD_IMM64(R0, 1),
3057 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3058 BPF_EXIT_INSN(),
3059 },
3060 INTERNAL,
3061 { },
3062 { { 0, -2147483647 } },
3063 },
3064 {
3065 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3066 .u.insns_int = {
3067 BPF_LD_IMM64(R2, 0x1),
3068 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3069 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3070 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3071 BPF_MOV32_IMM(R0, 2),
3072 BPF_EXIT_INSN(),
3073 BPF_MOV32_IMM(R0, 1),
3074 BPF_EXIT_INSN(),
3075 },
3076 INTERNAL,
3077 { },
3078 { { 0, 0x1 } },
3079 },
3080 /* BPF_ALU | BPF_DIV | BPF_X */
3081 {
3082 "ALU_DIV_X: 6 / 2 = 3",
3083 .u.insns_int = {
3084 BPF_LD_IMM64(R0, 6),
3085 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3086 BPF_ALU32_REG(BPF_DIV, R0, R1),
3087 BPF_EXIT_INSN(),
3088 },
3089 INTERNAL,
3090 { },
3091 { { 0, 3 } },
3092 },
3093 {
3094 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3095 .u.insns_int = {
3096 BPF_LD_IMM64(R0, 4294967295U),
3097 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
3098 BPF_ALU32_REG(BPF_DIV, R0, R1),
3099 BPF_EXIT_INSN(),
3100 },
3101 INTERNAL,
3102 { },
3103 { { 0, 1 } },
3104 },
3105 {
3106 "ALU64_DIV_X: 6 / 2 = 3",
3107 .u.insns_int = {
3108 BPF_LD_IMM64(R0, 6),
3109 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3110 BPF_ALU64_REG(BPF_DIV, R0, R1),
3111 BPF_EXIT_INSN(),
3112 },
3113 INTERNAL,
3114 { },
3115 { { 0, 3 } },
3116 },
3117 {
3118 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3119 .u.insns_int = {
3120 BPF_LD_IMM64(R0, 2147483647),
3121 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3122 BPF_ALU64_REG(BPF_DIV, R0, R1),
3123 BPF_EXIT_INSN(),
3124 },
3125 INTERNAL,
3126 { },
3127 { { 0, 1 } },
3128 },
3129 {
3130 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3131 .u.insns_int = {
3132 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3133 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3134 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3135 BPF_ALU64_REG(BPF_DIV, R2, R4),
3136 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3137 BPF_MOV32_IMM(R0, 2),
3138 BPF_EXIT_INSN(),
3139 BPF_MOV32_IMM(R0, 1),
3140 BPF_EXIT_INSN(),
3141 },
3142 INTERNAL,
3143 { },
3144 { { 0, 0x1 } },
3145 },
3146 /* BPF_ALU | BPF_DIV | BPF_K */
3147 {
3148 "ALU_DIV_K: 6 / 2 = 3",
3149 .u.insns_int = {
3150 BPF_LD_IMM64(R0, 6),
3151 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3152 BPF_EXIT_INSN(),
3153 },
3154 INTERNAL,
3155 { },
3156 { { 0, 3 } },
3157 },
3158 {
3159 "ALU_DIV_K: 3 / 1 = 3",
3160 .u.insns_int = {
3161 BPF_LD_IMM64(R0, 3),
3162 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3163 BPF_EXIT_INSN(),
3164 },
3165 INTERNAL,
3166 { },
3167 { { 0, 3 } },
3168 },
3169 {
3170 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3171 .u.insns_int = {
3172 BPF_LD_IMM64(R0, 4294967295U),
3173 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
3174 BPF_EXIT_INSN(),
3175 },
3176 INTERNAL,
3177 { },
3178 { { 0, 1 } },
3179 },
3180 {
3181 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3182 .u.insns_int = {
3183 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3184 BPF_LD_IMM64(R3, 0x1UL),
3185 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3186 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3187 BPF_MOV32_IMM(R0, 2),
3188 BPF_EXIT_INSN(),
3189 BPF_MOV32_IMM(R0, 1),
3190 BPF_EXIT_INSN(),
3191 },
3192 INTERNAL,
3193 { },
3194 { { 0, 0x1 } },
3195 },
3196 {
3197 "ALU64_DIV_K: 6 / 2 = 3",
3198 .u.insns_int = {
3199 BPF_LD_IMM64(R0, 6),
3200 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3201 BPF_EXIT_INSN(),
3202 },
3203 INTERNAL,
3204 { },
3205 { { 0, 3 } },
3206 },
3207 {
3208 "ALU64_DIV_K: 3 / 1 = 3",
3209 .u.insns_int = {
3210 BPF_LD_IMM64(R0, 3),
3211 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3212 BPF_EXIT_INSN(),
3213 },
3214 INTERNAL,
3215 { },
3216 { { 0, 3 } },
3217 },
3218 {
3219 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3220 .u.insns_int = {
3221 BPF_LD_IMM64(R0, 2147483647),
3222 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3223 BPF_EXIT_INSN(),
3224 },
3225 INTERNAL,
3226 { },
3227 { { 0, 1 } },
3228 },
3229 {
3230 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3231 .u.insns_int = {
3232 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3233 BPF_LD_IMM64(R3, 0x0000000000000001LL),
3234 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3235 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3236 BPF_MOV32_IMM(R0, 2),
3237 BPF_EXIT_INSN(),
3238 BPF_MOV32_IMM(R0, 1),
3239 BPF_EXIT_INSN(),
3240 },
3241 INTERNAL,
3242 { },
3243 { { 0, 0x1 } },
3244 },
3245 /* BPF_ALU | BPF_MOD | BPF_X */
3246 {
3247 "ALU_MOD_X: 3 % 2 = 1",
3248 .u.insns_int = {
3249 BPF_LD_IMM64(R0, 3),
3250 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3251 BPF_ALU32_REG(BPF_MOD, R0, R1),
3252 BPF_EXIT_INSN(),
3253 },
3254 INTERNAL,
3255 { },
3256 { { 0, 1 } },
3257 },
3258 {
3259 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3260 .u.insns_int = {
3261 BPF_LD_IMM64(R0, 4294967295U),
3262 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
3263 BPF_ALU32_REG(BPF_MOD, R0, R1),
3264 BPF_EXIT_INSN(),
3265 },
3266 INTERNAL,
3267 { },
3268 { { 0, 2 } },
3269 },
3270 {
3271 "ALU64_MOD_X: 3 % 2 = 1",
3272 .u.insns_int = {
3273 BPF_LD_IMM64(R0, 3),
3274 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3275 BPF_ALU64_REG(BPF_MOD, R0, R1),
3276 BPF_EXIT_INSN(),
3277 },
3278 INTERNAL,
3279 { },
3280 { { 0, 1 } },
3281 },
3282 {
3283 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3284 .u.insns_int = {
3285 BPF_LD_IMM64(R0, 2147483647),
3286 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3287 BPF_ALU64_REG(BPF_MOD, R0, R1),
3288 BPF_EXIT_INSN(),
3289 },
3290 INTERNAL,
3291 { },
3292 { { 0, 2 } },
3293 },
3294 /* BPF_ALU | BPF_MOD | BPF_K */
3295 {
3296 "ALU_MOD_K: 3 % 2 = 1",
3297 .u.insns_int = {
3298 BPF_LD_IMM64(R0, 3),
3299 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3300 BPF_EXIT_INSN(),
3301 },
3302 INTERNAL,
3303 { },
3304 { { 0, 1 } },
3305 },
3306 {
3307 "ALU_MOD_K: 3 % 1 = 0",
3308 .u.insns_int = {
3309 BPF_LD_IMM64(R0, 3),
3310 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3311 BPF_EXIT_INSN(),
3312 },
3313 INTERNAL,
3314 { },
3315 { { 0, 0 } },
3316 },
3317 {
3318 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3319 .u.insns_int = {
3320 BPF_LD_IMM64(R0, 4294967295U),
3321 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
3322 BPF_EXIT_INSN(),
3323 },
3324 INTERNAL,
3325 { },
3326 { { 0, 2 } },
3327 },
3328 {
3329 "ALU64_MOD_K: 3 % 2 = 1",
3330 .u.insns_int = {
3331 BPF_LD_IMM64(R0, 3),
3332 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3333 BPF_EXIT_INSN(),
3334 },
3335 INTERNAL,
3336 { },
3337 { { 0, 1 } },
3338 },
3339 {
3340 "ALU64_MOD_K: 3 % 1 = 0",
3341 .u.insns_int = {
3342 BPF_LD_IMM64(R0, 3),
3343 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3344 BPF_EXIT_INSN(),
3345 },
3346 INTERNAL,
3347 { },
3348 { { 0, 0 } },
3349 },
3350 {
3351 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3352 .u.insns_int = {
3353 BPF_LD_IMM64(R0, 2147483647),
3354 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3355 BPF_EXIT_INSN(),
3356 },
3357 INTERNAL,
3358 { },
3359 { { 0, 2 } },
3360 },
3361 /* BPF_ALU | BPF_AND | BPF_X */
3362 {
3363 "ALU_AND_X: 3 & 2 = 2",
3364 .u.insns_int = {
3365 BPF_LD_IMM64(R0, 3),
3366 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3367 BPF_ALU32_REG(BPF_AND, R0, R1),
3368 BPF_EXIT_INSN(),
3369 },
3370 INTERNAL,
3371 { },
3372 { { 0, 2 } },
3373 },
3374 {
3375 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3376 .u.insns_int = {
3377 BPF_LD_IMM64(R0, 0xffffffff),
3378 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3379 BPF_ALU32_REG(BPF_AND, R0, R1),
3380 BPF_EXIT_INSN(),
3381 },
3382 INTERNAL,
3383 { },
3384 { { 0, 0xffffffff } },
3385 },
3386 {
3387 "ALU64_AND_X: 3 & 2 = 2",
3388 .u.insns_int = {
3389 BPF_LD_IMM64(R0, 3),
3390 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3391 BPF_ALU64_REG(BPF_AND, R0, R1),
3392 BPF_EXIT_INSN(),
3393 },
3394 INTERNAL,
3395 { },
3396 { { 0, 2 } },
3397 },
3398 {
3399 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3400 .u.insns_int = {
3401 BPF_LD_IMM64(R0, 0xffffffff),
3402 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3403 BPF_ALU64_REG(BPF_AND, R0, R1),
3404 BPF_EXIT_INSN(),
3405 },
3406 INTERNAL,
3407 { },
3408 { { 0, 0xffffffff } },
3409 },
3410 /* BPF_ALU | BPF_AND | BPF_K */
3411 {
3412 "ALU_AND_K: 3 & 2 = 2",
3413 .u.insns_int = {
3414 BPF_LD_IMM64(R0, 3),
3415 BPF_ALU32_IMM(BPF_AND, R0, 2),
3416 BPF_EXIT_INSN(),
3417 },
3418 INTERNAL,
3419 { },
3420 { { 0, 2 } },
3421 },
3422 {
3423 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3424 .u.insns_int = {
3425 BPF_LD_IMM64(R0, 0xffffffff),
3426 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3427 BPF_EXIT_INSN(),
3428 },
3429 INTERNAL,
3430 { },
3431 { { 0, 0xffffffff } },
3432 },
3433 {
3434 "ALU64_AND_K: 3 & 2 = 2",
3435 .u.insns_int = {
3436 BPF_LD_IMM64(R0, 3),
3437 BPF_ALU64_IMM(BPF_AND, R0, 2),
3438 BPF_EXIT_INSN(),
3439 },
3440 INTERNAL,
3441 { },
3442 { { 0, 2 } },
3443 },
3444 {
3445 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3446 .u.insns_int = {
3447 BPF_LD_IMM64(R0, 0xffffffff),
3448 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3449 BPF_EXIT_INSN(),
3450 },
3451 INTERNAL,
3452 { },
3453 { { 0, 0xffffffff } },
3454 },
3455 {
3456 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3457 .u.insns_int = {
3458 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3459 BPF_LD_IMM64(R3, 0x0000000000000000LL),
3460 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3461 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3462 BPF_MOV32_IMM(R0, 2),
3463 BPF_EXIT_INSN(),
3464 BPF_MOV32_IMM(R0, 1),
3465 BPF_EXIT_INSN(),
3466 },
3467 INTERNAL,
3468 { },
3469 { { 0, 0x1 } },
3470 },
3471 {
3472 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3473 .u.insns_int = {
3474 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3475 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3476 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3477 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3478 BPF_MOV32_IMM(R0, 2),
3479 BPF_EXIT_INSN(),
3480 BPF_MOV32_IMM(R0, 1),
3481 BPF_EXIT_INSN(),
3482 },
3483 INTERNAL,
3484 { },
3485 { { 0, 0x1 } },
3486 },
3487 {
3488 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3489 .u.insns_int = {
3490 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3491 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3492 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3493 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3494 BPF_MOV32_IMM(R0, 2),
3495 BPF_EXIT_INSN(),
3496 BPF_MOV32_IMM(R0, 1),
3497 BPF_EXIT_INSN(),
3498 },
3499 INTERNAL,
3500 { },
3501 { { 0, 0x1 } },
3502 },
3503 /* BPF_ALU | BPF_OR | BPF_X */
3504 {
3505 "ALU_OR_X: 1 | 2 = 3",
3506 .u.insns_int = {
3507 BPF_LD_IMM64(R0, 1),
3508 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3509 BPF_ALU32_REG(BPF_OR, R0, R1),
3510 BPF_EXIT_INSN(),
3511 },
3512 INTERNAL,
3513 { },
3514 { { 0, 3 } },
3515 },
3516 {
3517 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3518 .u.insns_int = {
3519 BPF_LD_IMM64(R0, 0),
3520 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3521 BPF_ALU32_REG(BPF_OR, R0, R1),
3522 BPF_EXIT_INSN(),
3523 },
3524 INTERNAL,
3525 { },
3526 { { 0, 0xffffffff } },
3527 },
3528 {
3529 "ALU64_OR_X: 1 | 2 = 3",
3530 .u.insns_int = {
3531 BPF_LD_IMM64(R0, 1),
3532 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3533 BPF_ALU64_REG(BPF_OR, R0, R1),
3534 BPF_EXIT_INSN(),
3535 },
3536 INTERNAL,
3537 { },
3538 { { 0, 3 } },
3539 },
3540 {
3541 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3542 .u.insns_int = {
3543 BPF_LD_IMM64(R0, 0),
3544 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3545 BPF_ALU64_REG(BPF_OR, R0, R1),
3546 BPF_EXIT_INSN(),
3547 },
3548 INTERNAL,
3549 { },
3550 { { 0, 0xffffffff } },
3551 },
3552 /* BPF_ALU | BPF_OR | BPF_K */
3553 {
3554 "ALU_OR_K: 1 | 2 = 3",
3555 .u.insns_int = {
3556 BPF_LD_IMM64(R0, 1),
3557 BPF_ALU32_IMM(BPF_OR, R0, 2),
3558 BPF_EXIT_INSN(),
3559 },
3560 INTERNAL,
3561 { },
3562 { { 0, 3 } },
3563 },
3564 {
3565 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3566 .u.insns_int = {
3567 BPF_LD_IMM64(R0, 0),
3568 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3569 BPF_EXIT_INSN(),
3570 },
3571 INTERNAL,
3572 { },
3573 { { 0, 0xffffffff } },
3574 },
3575 {
3576 "ALU64_OR_K: 1 | 2 = 3",
3577 .u.insns_int = {
3578 BPF_LD_IMM64(R0, 1),
3579 BPF_ALU64_IMM(BPF_OR, R0, 2),
3580 BPF_EXIT_INSN(),
3581 },
3582 INTERNAL,
3583 { },
3584 { { 0, 3 } },
3585 },
3586 {
3587 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3588 .u.insns_int = {
3589 BPF_LD_IMM64(R0, 0),
3590 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3591 BPF_EXIT_INSN(),
3592 },
3593 INTERNAL,
3594 { },
3595 { { 0, 0xffffffff } },
3596 },
3597 {
3598 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3599 .u.insns_int = {
3600 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3601 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3602 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3603 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3604 BPF_MOV32_IMM(R0, 2),
3605 BPF_EXIT_INSN(),
3606 BPF_MOV32_IMM(R0, 1),
3607 BPF_EXIT_INSN(),
3608 },
3609 INTERNAL,
3610 { },
3611 { { 0, 0x1 } },
3612 },
3613 {
3614 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3615 .u.insns_int = {
3616 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3617 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3618 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3619 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3620 BPF_MOV32_IMM(R0, 2),
3621 BPF_EXIT_INSN(),
3622 BPF_MOV32_IMM(R0, 1),
3623 BPF_EXIT_INSN(),
3624 },
3625 INTERNAL,
3626 { },
3627 { { 0, 0x1 } },
3628 },
3629 {
3630 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3631 .u.insns_int = {
3632 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3633 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3634 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3635 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3636 BPF_MOV32_IMM(R0, 2),
3637 BPF_EXIT_INSN(),
3638 BPF_MOV32_IMM(R0, 1),
3639 BPF_EXIT_INSN(),
3640 },
3641 INTERNAL,
3642 { },
3643 { { 0, 0x1 } },
3644 },
3645 /* BPF_ALU | BPF_XOR | BPF_X */
3646 {
3647 "ALU_XOR_X: 5 ^ 6 = 3",
3648 .u.insns_int = {
3649 BPF_LD_IMM64(R0, 5),
3650 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3651 BPF_ALU32_REG(BPF_XOR, R0, R1),
3652 BPF_EXIT_INSN(),
3653 },
3654 INTERNAL,
3655 { },
3656 { { 0, 3 } },
3657 },
3658 {
3659 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3660 .u.insns_int = {
3661 BPF_LD_IMM64(R0, 1),
3662 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3663 BPF_ALU32_REG(BPF_XOR, R0, R1),
3664 BPF_EXIT_INSN(),
3665 },
3666 INTERNAL,
3667 { },
3668 { { 0, 0xfffffffe } },
3669 },
3670 {
3671 "ALU64_XOR_X: 5 ^ 6 = 3",
3672 .u.insns_int = {
3673 BPF_LD_IMM64(R0, 5),
3674 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3675 BPF_ALU64_REG(BPF_XOR, R0, R1),
3676 BPF_EXIT_INSN(),
3677 },
3678 INTERNAL,
3679 { },
3680 { { 0, 3 } },
3681 },
3682 {
3683 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3684 .u.insns_int = {
3685 BPF_LD_IMM64(R0, 1),
3686 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3687 BPF_ALU64_REG(BPF_XOR, R0, R1),
3688 BPF_EXIT_INSN(),
3689 },
3690 INTERNAL,
3691 { },
3692 { { 0, 0xfffffffe } },
3693 },
3694 /* BPF_ALU | BPF_XOR | BPF_K */
3695 {
3696 "ALU_XOR_K: 5 ^ 6 = 3",
3697 .u.insns_int = {
3698 BPF_LD_IMM64(R0, 5),
3699 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3700 BPF_EXIT_INSN(),
3701 },
3702 INTERNAL,
3703 { },
3704 { { 0, 3 } },
3705 },
3706 {
3707 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3708 .u.insns_int = {
3709 BPF_LD_IMM64(R0, 1),
3710 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3711 BPF_EXIT_INSN(),
3712 },
3713 INTERNAL,
3714 { },
3715 { { 0, 0xfffffffe } },
3716 },
3717 {
3718 "ALU64_XOR_K: 5 ^ 6 = 3",
3719 .u.insns_int = {
3720 BPF_LD_IMM64(R0, 5),
3721 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3722 BPF_EXIT_INSN(),
3723 },
3724 INTERNAL,
3725 { },
3726 { { 0, 3 } },
3727 },
3728 {
3729 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3730 .u.insns_int = {
3731 BPF_LD_IMM64(R0, 1),
3732 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3733 BPF_EXIT_INSN(),
3734 },
3735 INTERNAL,
3736 { },
3737 { { 0, 0xfffffffe } },
3738 },
3739 {
3740 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3741 .u.insns_int = {
3742 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3743 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3744 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3745 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3746 BPF_MOV32_IMM(R0, 2),
3747 BPF_EXIT_INSN(),
3748 BPF_MOV32_IMM(R0, 1),
3749 BPF_EXIT_INSN(),
3750 },
3751 INTERNAL,
3752 { },
3753 { { 0, 0x1 } },
3754 },
3755 {
3756 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3757 .u.insns_int = {
3758 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3759 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
3760 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3761 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3762 BPF_MOV32_IMM(R0, 2),
3763 BPF_EXIT_INSN(),
3764 BPF_MOV32_IMM(R0, 1),
3765 BPF_EXIT_INSN(),
3766 },
3767 INTERNAL,
3768 { },
3769 { { 0, 0x1 } },
3770 },
3771 {
3772 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3773 .u.insns_int = {
3774 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3775 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3776 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3777 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3778 BPF_MOV32_IMM(R0, 2),
3779 BPF_EXIT_INSN(),
3780 BPF_MOV32_IMM(R0, 1),
3781 BPF_EXIT_INSN(),
3782 },
3783 INTERNAL,
3784 { },
3785 { { 0, 0x1 } },
3786 },
3787 /* BPF_ALU | BPF_LSH | BPF_X */
3788 {
3789 "ALU_LSH_X: 1 << 1 = 2",
3790 .u.insns_int = {
3791 BPF_LD_IMM64(R0, 1),
3792 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3793 BPF_ALU32_REG(BPF_LSH, R0, R1),
3794 BPF_EXIT_INSN(),
3795 },
3796 INTERNAL,
3797 { },
3798 { { 0, 2 } },
3799 },
3800 {
3801 "ALU_LSH_X: 1 << 31 = 0x80000000",
3802 .u.insns_int = {
3803 BPF_LD_IMM64(R0, 1),
3804 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3805 BPF_ALU32_REG(BPF_LSH, R0, R1),
3806 BPF_EXIT_INSN(),
3807 },
3808 INTERNAL,
3809 { },
3810 { { 0, 0x80000000 } },
3811 },
3812 {
3813 "ALU64_LSH_X: 1 << 1 = 2",
3814 .u.insns_int = {
3815 BPF_LD_IMM64(R0, 1),
3816 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3817 BPF_ALU64_REG(BPF_LSH, R0, R1),
3818 BPF_EXIT_INSN(),
3819 },
3820 INTERNAL,
3821 { },
3822 { { 0, 2 } },
3823 },
3824 {
3825 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3826 .u.insns_int = {
3827 BPF_LD_IMM64(R0, 1),
3828 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3829 BPF_ALU64_REG(BPF_LSH, R0, R1),
3830 BPF_EXIT_INSN(),
3831 },
3832 INTERNAL,
3833 { },
3834 { { 0, 0x80000000 } },
3835 },
3836 /* BPF_ALU | BPF_LSH | BPF_K */
3837 {
3838 "ALU_LSH_K: 1 << 1 = 2",
3839 .u.insns_int = {
3840 BPF_LD_IMM64(R0, 1),
3841 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3842 BPF_EXIT_INSN(),
3843 },
3844 INTERNAL,
3845 { },
3846 { { 0, 2 } },
3847 },
3848 {
3849 "ALU_LSH_K: 1 << 31 = 0x80000000",
3850 .u.insns_int = {
3851 BPF_LD_IMM64(R0, 1),
3852 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3853 BPF_EXIT_INSN(),
3854 },
3855 INTERNAL,
3856 { },
3857 { { 0, 0x80000000 } },
3858 },
3859 {
3860 "ALU64_LSH_K: 1 << 1 = 2",
3861 .u.insns_int = {
3862 BPF_LD_IMM64(R0, 1),
3863 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3864 BPF_EXIT_INSN(),
3865 },
3866 INTERNAL,
3867 { },
3868 { { 0, 2 } },
3869 },
3870 {
3871 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3872 .u.insns_int = {
3873 BPF_LD_IMM64(R0, 1),
3874 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3875 BPF_EXIT_INSN(),
3876 },
3877 INTERNAL,
3878 { },
3879 { { 0, 0x80000000 } },
3880 },
3881 /* BPF_ALU | BPF_RSH | BPF_X */
3882 {
3883 "ALU_RSH_X: 2 >> 1 = 1",
3884 .u.insns_int = {
3885 BPF_LD_IMM64(R0, 2),
3886 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3887 BPF_ALU32_REG(BPF_RSH, R0, R1),
3888 BPF_EXIT_INSN(),
3889 },
3890 INTERNAL,
3891 { },
3892 { { 0, 1 } },
3893 },
3894 {
3895 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3896 .u.insns_int = {
3897 BPF_LD_IMM64(R0, 0x80000000),
3898 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3899 BPF_ALU32_REG(BPF_RSH, R0, R1),
3900 BPF_EXIT_INSN(),
3901 },
3902 INTERNAL,
3903 { },
3904 { { 0, 1 } },
3905 },
3906 {
3907 "ALU64_RSH_X: 2 >> 1 = 1",
3908 .u.insns_int = {
3909 BPF_LD_IMM64(R0, 2),
3910 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3911 BPF_ALU64_REG(BPF_RSH, R0, R1),
3912 BPF_EXIT_INSN(),
3913 },
3914 INTERNAL,
3915 { },
3916 { { 0, 1 } },
3917 },
3918 {
3919 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3920 .u.insns_int = {
3921 BPF_LD_IMM64(R0, 0x80000000),
3922 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3923 BPF_ALU64_REG(BPF_RSH, R0, R1),
3924 BPF_EXIT_INSN(),
3925 },
3926 INTERNAL,
3927 { },
3928 { { 0, 1 } },
3929 },
3930 /* BPF_ALU | BPF_RSH | BPF_K */
3931 {
3932 "ALU_RSH_K: 2 >> 1 = 1",
3933 .u.insns_int = {
3934 BPF_LD_IMM64(R0, 2),
3935 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3936 BPF_EXIT_INSN(),
3937 },
3938 INTERNAL,
3939 { },
3940 { { 0, 1 } },
3941 },
3942 {
3943 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3944 .u.insns_int = {
3945 BPF_LD_IMM64(R0, 0x80000000),
3946 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3947 BPF_EXIT_INSN(),
3948 },
3949 INTERNAL,
3950 { },
3951 { { 0, 1 } },
3952 },
3953 {
3954 "ALU64_RSH_K: 2 >> 1 = 1",
3955 .u.insns_int = {
3956 BPF_LD_IMM64(R0, 2),
3957 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3958 BPF_EXIT_INSN(),
3959 },
3960 INTERNAL,
3961 { },
3962 { { 0, 1 } },
3963 },
3964 {
3965 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3966 .u.insns_int = {
3967 BPF_LD_IMM64(R0, 0x80000000),
3968 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3969 BPF_EXIT_INSN(),
3970 },
3971 INTERNAL,
3972 { },
3973 { { 0, 1 } },
3974 },
3975 /* BPF_ALU | BPF_ARSH | BPF_X */
3976 {
3977 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3978 .u.insns_int = {
3979 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3980 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3981 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3982 BPF_EXIT_INSN(),
3983 },
3984 INTERNAL,
3985 { },
3986 { { 0, 0xffff00ff } },
3987 },
3988 /* BPF_ALU | BPF_ARSH | BPF_K */
3989 {
3990 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3991 .u.insns_int = {
3992 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3993 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3994 BPF_EXIT_INSN(),
3995 },
3996 INTERNAL,
3997 { },
3998 { { 0, 0xffff00ff } },
3999 },
4000 /* BPF_ALU | BPF_NEG */
4001 {
4002 "ALU_NEG: -(3) = -3",
4003 .u.insns_int = {
4004 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4005 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4006 BPF_EXIT_INSN(),
4007 },
4008 INTERNAL,
4009 { },
4010 { { 0, -3 } },
4011 },
4012 {
4013 "ALU_NEG: -(-3) = 3",
4014 .u.insns_int = {
4015 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4016 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4017 BPF_EXIT_INSN(),
4018 },
4019 INTERNAL,
4020 { },
4021 { { 0, 3 } },
4022 },
4023 {
4024 "ALU64_NEG: -(3) = -3",
4025 .u.insns_int = {
4026 BPF_LD_IMM64(R0, 3),
4027 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4028 BPF_EXIT_INSN(),
4029 },
4030 INTERNAL,
4031 { },
4032 { { 0, -3 } },
4033 },
4034 {
4035 "ALU64_NEG: -(-3) = 3",
4036 .u.insns_int = {
4037 BPF_LD_IMM64(R0, -3),
4038 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4039 BPF_EXIT_INSN(),
4040 },
4041 INTERNAL,
4042 { },
4043 { { 0, 3 } },
4044 },
4045 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4046 {
4047 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4048 .u.insns_int = {
4049 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4050 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4051 BPF_EXIT_INSN(),
4052 },
4053 INTERNAL,
4054 { },
4055 { { 0, cpu_to_be16(0xcdef) } },
4056 },
4057 {
4058 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4059 .u.insns_int = {
4060 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4061 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
4062 BPF_ALU64_REG(BPF_MOV, R1, R0),
4063 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4064 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
4065 BPF_EXIT_INSN(),
4066 },
4067 INTERNAL,
4068 { },
4069 { { 0, cpu_to_be32(0x89abcdef) } },
4070 },
4071 {
4072 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4073 .u.insns_int = {
4074 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4075 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4076 BPF_EXIT_INSN(),
4077 },
4078 INTERNAL,
4079 { },
4080 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4081 },
4082 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4083 {
4084 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4085 .u.insns_int = {
4086 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4087 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4088 BPF_EXIT_INSN(),
4089 },
4090 INTERNAL,
4091 { },
4092 { { 0, cpu_to_le16(0xcdef) } },
4093 },
4094 {
4095 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4096 .u.insns_int = {
4097 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4098 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
4099 BPF_ALU64_REG(BPF_MOV, R1, R0),
4100 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4101 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
4102 BPF_EXIT_INSN(),
4103 },
4104 INTERNAL,
4105 { },
4106 { { 0, cpu_to_le32(0x89abcdef) } },
4107 },
4108 {
4109 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4110 .u.insns_int = {
4111 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4112 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4113 BPF_EXIT_INSN(),
4114 },
4115 INTERNAL,
4116 { },
4117 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4118 },
4119 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4120 {
4121 "ST_MEM_B: Store/Load byte: max negative",
4122 .u.insns_int = {
4123 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4124 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4125 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4126 BPF_EXIT_INSN(),
4127 },
4128 INTERNAL,
4129 { },
4130 { { 0, 0xff } },
4131 .stack_depth = 40,
4132 },
4133 {
4134 "ST_MEM_B: Store/Load byte: max positive",
4135 .u.insns_int = {
4136 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4137 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4138 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4139 BPF_EXIT_INSN(),
4140 },
4141 INTERNAL,
4142 { },
4143 { { 0, 0x7f } },
4144 .stack_depth = 40,
4145 },
4146 {
4147 "STX_MEM_B: Store/Load byte: max negative",
4148 .u.insns_int = {
4149 BPF_LD_IMM64(R0, 0),
4150 BPF_LD_IMM64(R1, 0xffLL),
4151 BPF_STX_MEM(BPF_B, R10, R1, -40),
4152 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4153 BPF_EXIT_INSN(),
4154 },
4155 INTERNAL,
4156 { },
4157 { { 0, 0xff } },
4158 .stack_depth = 40,
4159 },
4160 {
4161 "ST_MEM_H: Store/Load half word: max negative",
4162 .u.insns_int = {
4163 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4164 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4165 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4166 BPF_EXIT_INSN(),
4167 },
4168 INTERNAL,
4169 { },
4170 { { 0, 0xffff } },
4171 .stack_depth = 40,
4172 },
4173 {
4174 "ST_MEM_H: Store/Load half word: max positive",
4175 .u.insns_int = {
4176 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4177 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4178 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4179 BPF_EXIT_INSN(),
4180 },
4181 INTERNAL,
4182 { },
4183 { { 0, 0x7fff } },
4184 .stack_depth = 40,
4185 },
4186 {
4187 "STX_MEM_H: Store/Load half word: max negative",
4188 .u.insns_int = {
4189 BPF_LD_IMM64(R0, 0),
4190 BPF_LD_IMM64(R1, 0xffffLL),
4191 BPF_STX_MEM(BPF_H, R10, R1, -40),
4192 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4193 BPF_EXIT_INSN(),
4194 },
4195 INTERNAL,
4196 { },
4197 { { 0, 0xffff } },
4198 .stack_depth = 40,
4199 },
4200 {
4201 "ST_MEM_W: Store/Load word: max negative",
4202 .u.insns_int = {
4203 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4204 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4205 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4206 BPF_EXIT_INSN(),
4207 },
4208 INTERNAL,
4209 { },
4210 { { 0, 0xffffffff } },
4211 .stack_depth = 40,
4212 },
4213 {
4214 "ST_MEM_W: Store/Load word: max positive",
4215 .u.insns_int = {
4216 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4217 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4218 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4219 BPF_EXIT_INSN(),
4220 },
4221 INTERNAL,
4222 { },
4223 { { 0, 0x7fffffff } },
4224 .stack_depth = 40,
4225 },
4226 {
4227 "STX_MEM_W: Store/Load word: max negative",
4228 .u.insns_int = {
4229 BPF_LD_IMM64(R0, 0),
4230 BPF_LD_IMM64(R1, 0xffffffffLL),
4231 BPF_STX_MEM(BPF_W, R10, R1, -40),
4232 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4233 BPF_EXIT_INSN(),
4234 },
4235 INTERNAL,
4236 { },
4237 { { 0, 0xffffffff } },
4238 .stack_depth = 40,
4239 },
4240 {
4241 "ST_MEM_DW: Store/Load double word: max negative",
4242 .u.insns_int = {
4243 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4244 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4245 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4246 BPF_EXIT_INSN(),
4247 },
4248 INTERNAL,
4249 { },
4250 { { 0, 0xffffffff } },
4251 .stack_depth = 40,
4252 },
4253 {
4254 "ST_MEM_DW: Store/Load double word: max negative 2",
4255 .u.insns_int = {
4256 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4257 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
4258 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4259 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4260 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4261 BPF_MOV32_IMM(R0, 2),
4262 BPF_EXIT_INSN(),
4263 BPF_MOV32_IMM(R0, 1),
4264 BPF_EXIT_INSN(),
4265 },
4266 INTERNAL,
4267 { },
4268 { { 0, 0x1 } },
4269 .stack_depth = 40,
4270 },
4271 {
4272 "ST_MEM_DW: Store/Load double word: max positive",
4273 .u.insns_int = {
4274 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4275 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4276 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4277 BPF_EXIT_INSN(),
4278 },
4279 INTERNAL,
4280 { },
4281 { { 0, 0x7fffffff } },
4282 .stack_depth = 40,
4283 },
4284 {
4285 "STX_MEM_DW: Store/Load double word: max negative",
4286 .u.insns_int = {
4287 BPF_LD_IMM64(R0, 0),
4288 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4289 BPF_STX_MEM(BPF_W, R10, R1, -40),
4290 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4291 BPF_EXIT_INSN(),
4292 },
4293 INTERNAL,
4294 { },
4295 { { 0, 0xffffffff } },
4296 .stack_depth = 40,
4297 },
4298 /* BPF_STX | BPF_XADD | BPF_W/DW */
4299 {
4300 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4301 .u.insns_int = {
4302 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4303 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4304 BPF_STX_XADD(BPF_W, R10, R0, -40),
4305 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4306 BPF_EXIT_INSN(),
4307 },
4308 INTERNAL,
4309 { },
4310 { { 0, 0x22 } },
4311 .stack_depth = 40,
4312 },
4313 {
4314 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4315 .u.insns_int = {
4316 BPF_ALU64_REG(BPF_MOV, R1, R10),
4317 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4318 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4319 BPF_STX_XADD(BPF_W, R10, R0, -40),
4320 BPF_ALU64_REG(BPF_MOV, R0, R10),
4321 BPF_ALU64_REG(BPF_SUB, R0, R1),
4322 BPF_EXIT_INSN(),
4323 },
4324 INTERNAL,
4325 { },
4326 { { 0, 0 } },
4327 .stack_depth = 40,
4328 },
4329 {
4330 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4331 .u.insns_int = {
4332 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4333 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4334 BPF_STX_XADD(BPF_W, R10, R0, -40),
4335 BPF_EXIT_INSN(),
4336 },
4337 INTERNAL,
4338 { },
4339 { { 0, 0x12 } },
4340 .stack_depth = 40,
4341 },
4342 {
4343 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4344 { },
4345 INTERNAL,
4346 { },
4347 { { 0, 4134 } },
4348 .fill_helper = bpf_fill_stxw,
4349 },
4350 {
4351 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4352 .u.insns_int = {
4353 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4354 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4355 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4356 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4357 BPF_EXIT_INSN(),
4358 },
4359 INTERNAL,
4360 { },
4361 { { 0, 0x22 } },
4362 .stack_depth = 40,
4363 },
4364 {
4365 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4366 .u.insns_int = {
4367 BPF_ALU64_REG(BPF_MOV, R1, R10),
4368 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4369 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4370 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4371 BPF_ALU64_REG(BPF_MOV, R0, R10),
4372 BPF_ALU64_REG(BPF_SUB, R0, R1),
4373 BPF_EXIT_INSN(),
4374 },
4375 INTERNAL,
4376 { },
4377 { { 0, 0 } },
4378 .stack_depth = 40,
4379 },
4380 {
4381 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4382 .u.insns_int = {
4383 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4384 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4385 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4386 BPF_EXIT_INSN(),
4387 },
4388 INTERNAL,
4389 { },
4390 { { 0, 0x12 } },
4391 .stack_depth = 40,
4392 },
4393 {
4394 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4395 { },
4396 INTERNAL,
4397 { },
4398 { { 0, 4134 } },
4399 .fill_helper = bpf_fill_stxdw,
4400 },
4401 /* BPF_JMP | BPF_EXIT */
4402 {
4403 "JMP_EXIT",
4404 .u.insns_int = {
4405 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4406 BPF_EXIT_INSN(),
4407 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4408 },
4409 INTERNAL,
4410 { },
4411 { { 0, 0x4711 } },
4412 },
4413 /* BPF_JMP | BPF_JA */
4414 {
4415 "JMP_JA: Unconditional jump: if (true) return 1",
4416 .u.insns_int = {
4417 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4418 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4419 BPF_EXIT_INSN(),
4420 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4421 BPF_EXIT_INSN(),
4422 },
4423 INTERNAL,
4424 { },
4425 { { 0, 1 } },
4426 },
4427 /* BPF_JMP | BPF_JSLT | BPF_K */
4428 {
4429 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4430 .u.insns_int = {
4431 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4432 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4433 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4434 BPF_EXIT_INSN(),
4435 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4436 BPF_EXIT_INSN(),
4437 },
4438 INTERNAL,
4439 { },
4440 { { 0, 1 } },
4441 },
4442 {
4443 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4444 .u.insns_int = {
4445 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4446 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4447 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4448 BPF_EXIT_INSN(),
4449 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4450 BPF_EXIT_INSN(),
4451 },
4452 INTERNAL,
4453 { },
4454 { { 0, 1 } },
4455 },
4456 /* BPF_JMP | BPF_JSGT | BPF_K */
4457 {
4458 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4459 .u.insns_int = {
4460 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4461 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4462 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4463 BPF_EXIT_INSN(),
4464 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4465 BPF_EXIT_INSN(),
4466 },
4467 INTERNAL,
4468 { },
4469 { { 0, 1 } },
4470 },
4471 {
4472 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4473 .u.insns_int = {
4474 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4475 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4476 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4477 BPF_EXIT_INSN(),
4478 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4479 BPF_EXIT_INSN(),
4480 },
4481 INTERNAL,
4482 { },
4483 { { 0, 1 } },
4484 },
4485 /* BPF_JMP | BPF_JSLE | BPF_K */
4486 {
4487 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4488 .u.insns_int = {
4489 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4490 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4491 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4492 BPF_EXIT_INSN(),
4493 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4494 BPF_EXIT_INSN(),
4495 },
4496 INTERNAL,
4497 { },
4498 { { 0, 1 } },
4499 },
4500 {
4501 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4502 .u.insns_int = {
4503 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4504 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4505 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4506 BPF_EXIT_INSN(),
4507 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4508 BPF_EXIT_INSN(),
4509 },
4510 INTERNAL,
4511 { },
4512 { { 0, 1 } },
4513 },
4514 {
4515 "JMP_JSLE_K: Signed jump: value walk 1",
4516 .u.insns_int = {
4517 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4518 BPF_LD_IMM64(R1, 3),
4519 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
4520 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4521 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4522 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4523 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4524 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4525 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4526 BPF_EXIT_INSN(), /* bad exit */
4527 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4528 BPF_EXIT_INSN(),
4529 },
4530 INTERNAL,
4531 { },
4532 { { 0, 1 } },
4533 },
4534 {
4535 "JMP_JSLE_K: Signed jump: value walk 2",
4536 .u.insns_int = {
4537 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4538 BPF_LD_IMM64(R1, 3),
4539 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4540 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4541 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4542 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4543 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4544 BPF_EXIT_INSN(), /* bad exit */
4545 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4546 BPF_EXIT_INSN(),
4547 },
4548 INTERNAL,
4549 { },
4550 { { 0, 1 } },
4551 },
4552 /* BPF_JMP | BPF_JSGE | BPF_K */
4553 {
4554 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4555 .u.insns_int = {
4556 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4557 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4558 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4559 BPF_EXIT_INSN(),
4560 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4561 BPF_EXIT_INSN(),
4562 },
4563 INTERNAL,
4564 { },
4565 { { 0, 1 } },
4566 },
4567 {
4568 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4569 .u.insns_int = {
4570 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4571 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4572 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4573 BPF_EXIT_INSN(),
4574 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4575 BPF_EXIT_INSN(),
4576 },
4577 INTERNAL,
4578 { },
4579 { { 0, 1 } },
4580 },
4581 {
4582 "JMP_JSGE_K: Signed jump: value walk 1",
4583 .u.insns_int = {
4584 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4585 BPF_LD_IMM64(R1, -3),
4586 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
4587 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4588 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4589 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4590 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4591 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4592 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4593 BPF_EXIT_INSN(), /* bad exit */
4594 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4595 BPF_EXIT_INSN(),
4596 },
4597 INTERNAL,
4598 { },
4599 { { 0, 1 } },
4600 },
4601 {
4602 "JMP_JSGE_K: Signed jump: value walk 2",
4603 .u.insns_int = {
4604 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4605 BPF_LD_IMM64(R1, -3),
4606 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4607 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4608 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4609 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4610 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4611 BPF_EXIT_INSN(), /* bad exit */
4612 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4613 BPF_EXIT_INSN(),
4614 },
4615 INTERNAL,
4616 { },
4617 { { 0, 1 } },
4618 },
4619 /* BPF_JMP | BPF_JGT | BPF_K */
4620 {
4621 "JMP_JGT_K: if (3 > 2) return 1",
4622 .u.insns_int = {
4623 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4624 BPF_LD_IMM64(R1, 3),
4625 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4626 BPF_EXIT_INSN(),
4627 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4628 BPF_EXIT_INSN(),
4629 },
4630 INTERNAL,
4631 { },
4632 { { 0, 1 } },
4633 },
4634 {
4635 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4636 .u.insns_int = {
4637 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4638 BPF_LD_IMM64(R1, -1),
4639 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
4640 BPF_EXIT_INSN(),
4641 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4642 BPF_EXIT_INSN(),
4643 },
4644 INTERNAL,
4645 { },
4646 { { 0, 1 } },
4647 },
4648 /* BPF_JMP | BPF_JLT | BPF_K */
4649 {
4650 "JMP_JLT_K: if (2 < 3) return 1",
4651 .u.insns_int = {
4652 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4653 BPF_LD_IMM64(R1, 2),
4654 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
4655 BPF_EXIT_INSN(),
4656 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4657 BPF_EXIT_INSN(),
4658 },
4659 INTERNAL,
4660 { },
4661 { { 0, 1 } },
4662 },
4663 {
4664 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4665 .u.insns_int = {
4666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4667 BPF_LD_IMM64(R1, 1),
4668 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
4669 BPF_EXIT_INSN(),
4670 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4671 BPF_EXIT_INSN(),
4672 },
4673 INTERNAL,
4674 { },
4675 { { 0, 1 } },
4676 },
4677 /* BPF_JMP | BPF_JGE | BPF_K */
4678 {
4679 "JMP_JGE_K: if (3 >= 2) return 1",
4680 .u.insns_int = {
4681 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4682 BPF_LD_IMM64(R1, 3),
4683 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4684 BPF_EXIT_INSN(),
4685 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4686 BPF_EXIT_INSN(),
4687 },
4688 INTERNAL,
4689 { },
4690 { { 0, 1 } },
4691 },
4692 /* BPF_JMP | BPF_JLE | BPF_K */
4693 {
4694 "JMP_JLE_K: if (2 <= 3) return 1",
4695 .u.insns_int = {
4696 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4697 BPF_LD_IMM64(R1, 2),
4698 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4699 BPF_EXIT_INSN(),
4700 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4701 BPF_EXIT_INSN(),
4702 },
4703 INTERNAL,
4704 { },
4705 { { 0, 1 } },
4706 },
4707 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4708 {
4709 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4710 .u.insns_int = {
4711 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4712 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4713 BPF_EXIT_INSN(),
4714 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4715 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4716 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4717 BPF_EXIT_INSN(),
4718 },
4719 INTERNAL,
4720 { },
4721 { { 0, 1 } },
4722 },
4723 {
4724 "JMP_JGE_K: if (3 >= 3) return 1",
4725 .u.insns_int = {
4726 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4727 BPF_LD_IMM64(R1, 3),
4728 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4729 BPF_EXIT_INSN(),
4730 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4731 BPF_EXIT_INSN(),
4732 },
4733 INTERNAL,
4734 { },
4735 { { 0, 1 } },
4736 },
4737 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4738 {
4739 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4740 .u.insns_int = {
4741 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4742 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4743 BPF_EXIT_INSN(),
4744 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4745 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
4746 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
4747 BPF_EXIT_INSN(),
4748 },
4749 INTERNAL,
4750 { },
4751 { { 0, 1 } },
4752 },
4753 {
4754 "JMP_JLE_K: if (3 <= 3) return 1",
4755 .u.insns_int = {
4756 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4757 BPF_LD_IMM64(R1, 3),
4758 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4759 BPF_EXIT_INSN(),
4760 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4761 BPF_EXIT_INSN(),
4762 },
4763 INTERNAL,
4764 { },
4765 { { 0, 1 } },
4766 },
4767 /* BPF_JMP | BPF_JNE | BPF_K */
4768 {
4769 "JMP_JNE_K: if (3 != 2) return 1",
4770 .u.insns_int = {
4771 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4772 BPF_LD_IMM64(R1, 3),
4773 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4774 BPF_EXIT_INSN(),
4775 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4776 BPF_EXIT_INSN(),
4777 },
4778 INTERNAL,
4779 { },
4780 { { 0, 1 } },
4781 },
4782 /* BPF_JMP | BPF_JEQ | BPF_K */
4783 {
4784 "JMP_JEQ_K: if (3 == 3) return 1",
4785 .u.insns_int = {
4786 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4787 BPF_LD_IMM64(R1, 3),
4788 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4789 BPF_EXIT_INSN(),
4790 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4791 BPF_EXIT_INSN(),
4792 },
4793 INTERNAL,
4794 { },
4795 { { 0, 1 } },
4796 },
4797 /* BPF_JMP | BPF_JSET | BPF_K */
4798 {
4799 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4800 .u.insns_int = {
4801 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4802 BPF_LD_IMM64(R1, 3),
4803 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
4804 BPF_EXIT_INSN(),
4805 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4806 BPF_EXIT_INSN(),
4807 },
4808 INTERNAL,
4809 { },
4810 { { 0, 1 } },
4811 },
4812 {
4813 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4814 .u.insns_int = {
4815 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4816 BPF_LD_IMM64(R1, 3),
4817 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
4818 BPF_EXIT_INSN(),
4819 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4820 BPF_EXIT_INSN(),
4821 },
4822 INTERNAL,
4823 { },
4824 { { 0, 1 } },
4825 },
4826 /* BPF_JMP | BPF_JSGT | BPF_X */
4827 {
4828 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4829 .u.insns_int = {
4830 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4831 BPF_LD_IMM64(R1, -1),
4832 BPF_LD_IMM64(R2, -2),
4833 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4834 BPF_EXIT_INSN(),
4835 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4836 BPF_EXIT_INSN(),
4837 },
4838 INTERNAL,
4839 { },
4840 { { 0, 1 } },
4841 },
4842 {
4843 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4844 .u.insns_int = {
4845 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4846 BPF_LD_IMM64(R1, -1),
4847 BPF_LD_IMM64(R2, -1),
4848 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4849 BPF_EXIT_INSN(),
4850 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4851 BPF_EXIT_INSN(),
4852 },
4853 INTERNAL,
4854 { },
4855 { { 0, 1 } },
4856 },
4857 /* BPF_JMP | BPF_JSLT | BPF_X */
4858 {
4859 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4860 .u.insns_int = {
4861 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4862 BPF_LD_IMM64(R1, -1),
4863 BPF_LD_IMM64(R2, -2),
4864 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
4865 BPF_EXIT_INSN(),
4866 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4867 BPF_EXIT_INSN(),
4868 },
4869 INTERNAL,
4870 { },
4871 { { 0, 1 } },
4872 },
4873 {
4874 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
4875 .u.insns_int = {
4876 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4877 BPF_LD_IMM64(R1, -1),
4878 BPF_LD_IMM64(R2, -1),
4879 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
4880 BPF_EXIT_INSN(),
4881 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4882 BPF_EXIT_INSN(),
4883 },
4884 INTERNAL,
4885 { },
4886 { { 0, 1 } },
4887 },
4888 /* BPF_JMP | BPF_JSGE | BPF_X */
4889 {
4890 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4891 .u.insns_int = {
4892 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4893 BPF_LD_IMM64(R1, -1),
4894 BPF_LD_IMM64(R2, -2),
4895 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4896 BPF_EXIT_INSN(),
4897 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4898 BPF_EXIT_INSN(),
4899 },
4900 INTERNAL,
4901 { },
4902 { { 0, 1 } },
4903 },
4904 {
4905 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4906 .u.insns_int = {
4907 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4908 BPF_LD_IMM64(R1, -1),
4909 BPF_LD_IMM64(R2, -1),
4910 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4911 BPF_EXIT_INSN(),
4912 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4913 BPF_EXIT_INSN(),
4914 },
4915 INTERNAL,
4916 { },
4917 { { 0, 1 } },
4918 },
4919 /* BPF_JMP | BPF_JSLE | BPF_X */
4920 {
4921 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
4922 .u.insns_int = {
4923 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4924 BPF_LD_IMM64(R1, -1),
4925 BPF_LD_IMM64(R2, -2),
4926 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
4927 BPF_EXIT_INSN(),
4928 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4929 BPF_EXIT_INSN(),
4930 },
4931 INTERNAL,
4932 { },
4933 { { 0, 1 } },
4934 },
4935 {
4936 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
4937 .u.insns_int = {
4938 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4939 BPF_LD_IMM64(R1, -1),
4940 BPF_LD_IMM64(R2, -1),
4941 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
4942 BPF_EXIT_INSN(),
4943 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4944 BPF_EXIT_INSN(),
4945 },
4946 INTERNAL,
4947 { },
4948 { { 0, 1 } },
4949 },
4950 /* BPF_JMP | BPF_JGT | BPF_X */
4951 {
4952 "JMP_JGT_X: if (3 > 2) return 1",
4953 .u.insns_int = {
4954 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4955 BPF_LD_IMM64(R1, 3),
4956 BPF_LD_IMM64(R2, 2),
4957 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4958 BPF_EXIT_INSN(),
4959 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4960 BPF_EXIT_INSN(),
4961 },
4962 INTERNAL,
4963 { },
4964 { { 0, 1 } },
4965 },
4966 {
4967 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
4968 .u.insns_int = {
4969 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4970 BPF_LD_IMM64(R1, -1),
4971 BPF_LD_IMM64(R2, 1),
4972 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4973 BPF_EXIT_INSN(),
4974 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4975 BPF_EXIT_INSN(),
4976 },
4977 INTERNAL,
4978 { },
4979 { { 0, 1 } },
4980 },
4981 /* BPF_JMP | BPF_JLT | BPF_X */
4982 {
4983 "JMP_JLT_X: if (2 < 3) return 1",
4984 .u.insns_int = {
4985 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4986 BPF_LD_IMM64(R1, 3),
4987 BPF_LD_IMM64(R2, 2),
4988 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
4989 BPF_EXIT_INSN(),
4990 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4991 BPF_EXIT_INSN(),
4992 },
4993 INTERNAL,
4994 { },
4995 { { 0, 1 } },
4996 },
4997 {
4998 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
4999 .u.insns_int = {
5000 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5001 BPF_LD_IMM64(R1, -1),
5002 BPF_LD_IMM64(R2, 1),
5003 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5004 BPF_EXIT_INSN(),
5005 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5006 BPF_EXIT_INSN(),
5007 },
5008 INTERNAL,
5009 { },
5010 { { 0, 1 } },
5011 },
5012 /* BPF_JMP | BPF_JGE | BPF_X */
5013 {
5014 "JMP_JGE_X: if (3 >= 2) return 1",
5015 .u.insns_int = {
5016 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5017 BPF_LD_IMM64(R1, 3),
5018 BPF_LD_IMM64(R2, 2),
5019 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5020 BPF_EXIT_INSN(),
5021 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5022 BPF_EXIT_INSN(),
5023 },
5024 INTERNAL,
5025 { },
5026 { { 0, 1 } },
5027 },
5028 {
5029 "JMP_JGE_X: if (3 >= 3) return 1",
5030 .u.insns_int = {
5031 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5032 BPF_LD_IMM64(R1, 3),
5033 BPF_LD_IMM64(R2, 3),
5034 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5035 BPF_EXIT_INSN(),
5036 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5037 BPF_EXIT_INSN(),
5038 },
5039 INTERNAL,
5040 { },
5041 { { 0, 1 } },
5042 },
5043 /* BPF_JMP | BPF_JLE | BPF_X */
5044 {
5045 "JMP_JLE_X: if (2 <= 3) return 1",
5046 .u.insns_int = {
5047 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5048 BPF_LD_IMM64(R1, 3),
5049 BPF_LD_IMM64(R2, 2),
5050 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
5051 BPF_EXIT_INSN(),
5052 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5053 BPF_EXIT_INSN(),
5054 },
5055 INTERNAL,
5056 { },
5057 { { 0, 1 } },
5058 },
5059 {
5060 "JMP_JLE_X: if (3 <= 3) return 1",
5061 .u.insns_int = {
5062 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5063 BPF_LD_IMM64(R1, 3),
5064 BPF_LD_IMM64(R2, 3),
5065 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
5066 BPF_EXIT_INSN(),
5067 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5068 BPF_EXIT_INSN(),
5069 },
5070 INTERNAL,
5071 { },
5072 { { 0, 1 } },
5073 },
5074 {
5075 /* Mainly testing JIT + imm64 here. */
5076 "JMP_JGE_X: ldimm64 test 1",
5077 .u.insns_int = {
5078 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5079 BPF_LD_IMM64(R1, 3),
5080 BPF_LD_IMM64(R2, 2),
5081 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
5082 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5083 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5084 BPF_EXIT_INSN(),
5085 },
5086 INTERNAL,
5087 { },
5088 { { 0, 0xeeeeeeeeU } },
5089 },
5090 {
5091 "JMP_JGE_X: ldimm64 test 2",
5092 .u.insns_int = {
5093 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5094 BPF_LD_IMM64(R1, 3),
5095 BPF_LD_IMM64(R2, 2),
5096 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
5097 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5098 BPF_EXIT_INSN(),
5099 },
5100 INTERNAL,
5101 { },
5102 { { 0, 0xffffffffU } },
5103 },
5104 {
5105 "JMP_JGE_X: ldimm64 test 3",
5106 .u.insns_int = {
5107 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5108 BPF_LD_IMM64(R1, 3),
5109 BPF_LD_IMM64(R2, 2),
5110 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
5111 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5112 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5113 BPF_EXIT_INSN(),
5114 },
5115 INTERNAL,
5116 { },
5117 { { 0, 1 } },
5118 },
5119 {
5120 "JMP_JLE_X: ldimm64 test 1",
5121 .u.insns_int = {
5122 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5123 BPF_LD_IMM64(R1, 3),
5124 BPF_LD_IMM64(R2, 2),
5125 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
5126 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5127 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5128 BPF_EXIT_INSN(),
5129 },
5130 INTERNAL,
5131 { },
5132 { { 0, 0xeeeeeeeeU } },
5133 },
5134 {
5135 "JMP_JLE_X: ldimm64 test 2",
5136 .u.insns_int = {
5137 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5138 BPF_LD_IMM64(R1, 3),
5139 BPF_LD_IMM64(R2, 2),
5140 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
5141 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5142 BPF_EXIT_INSN(),
5143 },
5144 INTERNAL,
5145 { },
5146 { { 0, 0xffffffffU } },
5147 },
5148 {
5149 "JMP_JLE_X: ldimm64 test 3",
5150 .u.insns_int = {
5151 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5152 BPF_LD_IMM64(R1, 3),
5153 BPF_LD_IMM64(R2, 2),
5154 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
5155 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5156 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5157 BPF_EXIT_INSN(),
5158 },
5159 INTERNAL,
5160 { },
5161 { { 0, 1 } },
5162 },
5163 /* BPF_JMP | BPF_JNE | BPF_X */
5164 {
5165 "JMP_JNE_X: if (3 != 2) return 1",
5166 .u.insns_int = {
5167 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5168 BPF_LD_IMM64(R1, 3),
5169 BPF_LD_IMM64(R2, 2),
5170 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
5171 BPF_EXIT_INSN(),
5172 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5173 BPF_EXIT_INSN(),
5174 },
5175 INTERNAL,
5176 { },
5177 { { 0, 1 } },
5178 },
5179 /* BPF_JMP | BPF_JEQ | BPF_X */
5180 {
5181 "JMP_JEQ_X: if (3 == 3) return 1",
5182 .u.insns_int = {
5183 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5184 BPF_LD_IMM64(R1, 3),
5185 BPF_LD_IMM64(R2, 3),
5186 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
5187 BPF_EXIT_INSN(),
5188 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5189 BPF_EXIT_INSN(),
5190 },
5191 INTERNAL,
5192 { },
5193 { { 0, 1 } },
5194 },
5195 /* BPF_JMP | BPF_JSET | BPF_X */
5196 {
5197 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5198 .u.insns_int = {
5199 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5200 BPF_LD_IMM64(R1, 3),
5201 BPF_LD_IMM64(R2, 2),
5202 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
5203 BPF_EXIT_INSN(),
5204 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5205 BPF_EXIT_INSN(),
5206 },
5207 INTERNAL,
5208 { },
5209 { { 0, 1 } },
5210 },
5211 {
5212 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5213 .u.insns_int = {
5214 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5215 BPF_LD_IMM64(R1, 3),
5216 BPF_LD_IMM64(R2, 0xffffffff),
5217 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
5218 BPF_EXIT_INSN(),
5219 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5220 BPF_EXIT_INSN(),
5221 },
5222 INTERNAL,
5223 { },
5224 { { 0, 1 } },
5225 },
5226 {
5227 "JMP_JA: Jump, gap, jump, ...",
5228 { },
5229 CLASSIC | FLAG_NO_DATA,
5230 { },
5231 { { 0, 0xababcbac } },
5232 .fill_helper = bpf_fill_ja,
5233 },
5234 { /* Mainly checking JIT here. */
5235 "BPF_MAXINSNS: Maximum possible literals",
5236 { },
5237 CLASSIC | FLAG_NO_DATA,
5238 { },
5239 { { 0, 0xffffffff } },
5240 .fill_helper = bpf_fill_maxinsns1,
5241 },
5242 { /* Mainly checking JIT here. */
5243 "BPF_MAXINSNS: Single literal",
5244 { },
5245 CLASSIC | FLAG_NO_DATA,
5246 { },
5247 { { 0, 0xfefefefe } },
5248 .fill_helper = bpf_fill_maxinsns2,
5249 },
5250 { /* Mainly checking JIT here. */
5251 "BPF_MAXINSNS: Run/add until end",
5252 { },
5253 CLASSIC | FLAG_NO_DATA,
5254 { },
5255 { { 0, 0x947bf368 } },
5256 .fill_helper = bpf_fill_maxinsns3,
5257 },
5258 {
5259 "BPF_MAXINSNS: Too many instructions",
5260 { },
5261 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5262 { },
5263 { },
5264 .fill_helper = bpf_fill_maxinsns4,
5265 .expected_errcode = -EINVAL,
5266 },
5267 { /* Mainly checking JIT here. */
5268 "BPF_MAXINSNS: Very long jump",
5269 { },
5270 CLASSIC | FLAG_NO_DATA,
5271 { },
5272 { { 0, 0xabababab } },
5273 .fill_helper = bpf_fill_maxinsns5,
5274 },
5275 { /* Mainly checking JIT here. */
5276 "BPF_MAXINSNS: Ctx heavy transformations",
5277 { },
5278 CLASSIC,
5279 { },
5280 {
5281 { 1, SKB_VLAN_PRESENT },
5282 { 10, SKB_VLAN_PRESENT }
5283 },
5284 .fill_helper = bpf_fill_maxinsns6,
5285 },
5286 { /* Mainly checking JIT here. */
5287 "BPF_MAXINSNS: Call heavy transformations",
5288 { },
5289 CLASSIC | FLAG_NO_DATA,
5290 { },
5291 { { 1, 0 }, { 10, 0 } },
5292 .fill_helper = bpf_fill_maxinsns7,
5293 },
5294 { /* Mainly checking JIT here. */
5295 "BPF_MAXINSNS: Jump heavy test",
5296 { },
5297 CLASSIC | FLAG_NO_DATA,
5298 { },
5299 { { 0, 0xffffffff } },
5300 .fill_helper = bpf_fill_maxinsns8,
5301 },
5302 { /* Mainly checking JIT here. */
5303 "BPF_MAXINSNS: Very long jump backwards",
5304 { },
5305 INTERNAL | FLAG_NO_DATA,
5306 { },
5307 { { 0, 0xcbababab } },
5308 .fill_helper = bpf_fill_maxinsns9,
5309 },
5310 { /* Mainly checking JIT here. */
5311 "BPF_MAXINSNS: Edge hopping nuthouse",
5312 { },
5313 INTERNAL | FLAG_NO_DATA,
5314 { },
5315 { { 0, 0xabababac } },
5316 .fill_helper = bpf_fill_maxinsns10,
5317 },
5318 {
5319 "BPF_MAXINSNS: Jump, gap, jump, ...",
5320 { },
5321#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_X86)
5322 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5323#else
5324 CLASSIC | FLAG_NO_DATA,
5325#endif
5326 { },
5327 { { 0, 0xababcbac } },
5328 .fill_helper = bpf_fill_maxinsns11,
5329 .expected_errcode = -ENOTSUPP,
5330 },
5331 {
5332 "BPF_MAXINSNS: jump over MSH",
5333 { },
5334 CLASSIC | FLAG_EXPECTED_FAIL,
5335 { 0xfa, 0xfb, 0xfc, 0xfd, },
5336 { { 4, 0xabababab } },
5337 .fill_helper = bpf_fill_maxinsns12,
5338 .expected_errcode = -EINVAL,
5339 },
5340 {
5341 "BPF_MAXINSNS: exec all MSH",
5342 { },
5343 CLASSIC,
5344 { 0xfa, 0xfb, 0xfc, 0xfd, },
5345 { { 4, 0xababab83 } },
5346 .fill_helper = bpf_fill_maxinsns13,
5347 },
5348 {
5349 "BPF_MAXINSNS: ld_abs+get_processor_id",
5350 { },
5351 CLASSIC,
5352 { },
5353 { { 1, 0xbee } },
5354 .fill_helper = bpf_fill_ld_abs_get_processor_id,
5355 },
5356 /*
5357 * LD_IND / LD_ABS on fragmented SKBs
5358 */
5359 {
5360 "LD_IND byte frag",
5361 .u.insns = {
5362 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5363 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
5364 BPF_STMT(BPF_RET | BPF_A, 0x0),
5365 },
5366 CLASSIC | FLAG_SKB_FRAG,
5367 { },
5368 { {0x40, 0x42} },
5369 .frag_data = {
5370 0x42, 0x00, 0x00, 0x00,
5371 0x43, 0x44, 0x00, 0x00,
5372 0x21, 0x07, 0x19, 0x83,
5373 },
5374 },
5375 {
5376 "LD_IND halfword frag",
5377 .u.insns = {
5378 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5379 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
5380 BPF_STMT(BPF_RET | BPF_A, 0x0),
5381 },
5382 CLASSIC | FLAG_SKB_FRAG,
5383 { },
5384 { {0x40, 0x4344} },
5385 .frag_data = {
5386 0x42, 0x00, 0x00, 0x00,
5387 0x43, 0x44, 0x00, 0x00,
5388 0x21, 0x07, 0x19, 0x83,
5389 },
5390 },
5391 {
5392 "LD_IND word frag",
5393 .u.insns = {
5394 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5395 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
5396 BPF_STMT(BPF_RET | BPF_A, 0x0),
5397 },
5398 CLASSIC | FLAG_SKB_FRAG,
5399 { },
5400 { {0x40, 0x21071983} },
5401 .frag_data = {
5402 0x42, 0x00, 0x00, 0x00,
5403 0x43, 0x44, 0x00, 0x00,
5404 0x21, 0x07, 0x19, 0x83,
5405 },
5406 },
5407 {
5408 "LD_IND halfword mixed head/frag",
5409 .u.insns = {
5410 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5411 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5412 BPF_STMT(BPF_RET | BPF_A, 0x0),
5413 },
5414 CLASSIC | FLAG_SKB_FRAG,
5415 { [0x3e] = 0x25, [0x3f] = 0x05, },
5416 { {0x40, 0x0519} },
5417 .frag_data = { 0x19, 0x82 },
5418 },
5419 {
5420 "LD_IND word mixed head/frag",
5421 .u.insns = {
5422 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5423 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5424 BPF_STMT(BPF_RET | BPF_A, 0x0),
5425 },
5426 CLASSIC | FLAG_SKB_FRAG,
5427 { [0x3e] = 0x25, [0x3f] = 0x05, },
5428 { {0x40, 0x25051982} },
5429 .frag_data = { 0x19, 0x82 },
5430 },
5431 {
5432 "LD_ABS byte frag",
5433 .u.insns = {
5434 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
5435 BPF_STMT(BPF_RET | BPF_A, 0x0),
5436 },
5437 CLASSIC | FLAG_SKB_FRAG,
5438 { },
5439 { {0x40, 0x42} },
5440 .frag_data = {
5441 0x42, 0x00, 0x00, 0x00,
5442 0x43, 0x44, 0x00, 0x00,
5443 0x21, 0x07, 0x19, 0x83,
5444 },
5445 },
5446 {
5447 "LD_ABS halfword frag",
5448 .u.insns = {
5449 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
5450 BPF_STMT(BPF_RET | BPF_A, 0x0),
5451 },
5452 CLASSIC | FLAG_SKB_FRAG,
5453 { },
5454 { {0x40, 0x4344} },
5455 .frag_data = {
5456 0x42, 0x00, 0x00, 0x00,
5457 0x43, 0x44, 0x00, 0x00,
5458 0x21, 0x07, 0x19, 0x83,
5459 },
5460 },
5461 {
5462 "LD_ABS word frag",
5463 .u.insns = {
5464 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
5465 BPF_STMT(BPF_RET | BPF_A, 0x0),
5466 },
5467 CLASSIC | FLAG_SKB_FRAG,
5468 { },
5469 { {0x40, 0x21071983} },
5470 .frag_data = {
5471 0x42, 0x00, 0x00, 0x00,
5472 0x43, 0x44, 0x00, 0x00,
5473 0x21, 0x07, 0x19, 0x83,
5474 },
5475 },
5476 {
5477 "LD_ABS halfword mixed head/frag",
5478 .u.insns = {
5479 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5480 BPF_STMT(BPF_RET | BPF_A, 0x0),
5481 },
5482 CLASSIC | FLAG_SKB_FRAG,
5483 { [0x3e] = 0x25, [0x3f] = 0x05, },
5484 { {0x40, 0x0519} },
5485 .frag_data = { 0x19, 0x82 },
5486 },
5487 {
5488 "LD_ABS word mixed head/frag",
5489 .u.insns = {
5490 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
5491 BPF_STMT(BPF_RET | BPF_A, 0x0),
5492 },
5493 CLASSIC | FLAG_SKB_FRAG,
5494 { [0x3e] = 0x25, [0x3f] = 0x05, },
5495 { {0x40, 0x25051982} },
5496 .frag_data = { 0x19, 0x82 },
5497 },
5498 /*
5499 * LD_IND / LD_ABS on non fragmented SKBs
5500 */
5501 {
5502 /*
5503 * this tests that the JIT/interpreter correctly resets X
5504 * before using it in an LD_IND instruction.
5505 */
5506 "LD_IND byte default X",
5507 .u.insns = {
5508 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5509 BPF_STMT(BPF_RET | BPF_A, 0x0),
5510 },
5511 CLASSIC,
5512 { [0x1] = 0x42 },
5513 { {0x40, 0x42 } },
5514 },
5515 {
5516 "LD_IND byte positive offset",
5517 .u.insns = {
5518 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5519 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5520 BPF_STMT(BPF_RET | BPF_A, 0x0),
5521 },
5522 CLASSIC,
5523 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5524 { {0x40, 0x82 } },
5525 },
5526 {
5527 "LD_IND byte negative offset",
5528 .u.insns = {
5529 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5530 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
5531 BPF_STMT(BPF_RET | BPF_A, 0x0),
5532 },
5533 CLASSIC,
5534 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5535 { {0x40, 0x05 } },
5536 },
5537 {
5538 "LD_IND byte positive offset, all ff",
5539 .u.insns = {
5540 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5541 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5542 BPF_STMT(BPF_RET | BPF_A, 0x0),
5543 },
5544 CLASSIC,
5545 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5546 { {0x40, 0xff } },
5547 },
5548 {
5549 "LD_IND byte positive offset, out of bounds",
5550 .u.insns = {
5551 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5552 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5553 BPF_STMT(BPF_RET | BPF_A, 0x0),
5554 },
5555 CLASSIC,
5556 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5557 { {0x3f, 0 }, },
5558 },
5559 {
5560 "LD_IND byte negative offset, out of bounds",
5561 .u.insns = {
5562 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5563 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
5564 BPF_STMT(BPF_RET | BPF_A, 0x0),
5565 },
5566 CLASSIC,
5567 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5568 { {0x3f, 0 } },
5569 },
5570 {
5571 "LD_IND byte negative offset, multiple calls",
5572 .u.insns = {
5573 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
5574 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
5575 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
5576 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
5577 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
5578 BPF_STMT(BPF_RET | BPF_A, 0x0),
5579 },
5580 CLASSIC,
5581 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5582 { {0x40, 0x82 }, },
5583 },
5584 {
5585 "LD_IND halfword positive offset",
5586 .u.insns = {
5587 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5588 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
5589 BPF_STMT(BPF_RET | BPF_A, 0x0),
5590 },
5591 CLASSIC,
5592 {
5593 [0x1c] = 0xaa, [0x1d] = 0x55,
5594 [0x1e] = 0xbb, [0x1f] = 0x66,
5595 [0x20] = 0xcc, [0x21] = 0x77,
5596 [0x22] = 0xdd, [0x23] = 0x88,
5597 },
5598 { {0x40, 0xdd88 } },
5599 },
5600 {
5601 "LD_IND halfword negative offset",
5602 .u.insns = {
5603 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5604 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
5605 BPF_STMT(BPF_RET | BPF_A, 0x0),
5606 },
5607 CLASSIC,
5608 {
5609 [0x1c] = 0xaa, [0x1d] = 0x55,
5610 [0x1e] = 0xbb, [0x1f] = 0x66,
5611 [0x20] = 0xcc, [0x21] = 0x77,
5612 [0x22] = 0xdd, [0x23] = 0x88,
5613 },
5614 { {0x40, 0xbb66 } },
5615 },
5616 {
5617 "LD_IND halfword unaligned",
5618 .u.insns = {
5619 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5620 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5621 BPF_STMT(BPF_RET | BPF_A, 0x0),
5622 },
5623 CLASSIC,
5624 {
5625 [0x1c] = 0xaa, [0x1d] = 0x55,
5626 [0x1e] = 0xbb, [0x1f] = 0x66,
5627 [0x20] = 0xcc, [0x21] = 0x77,
5628 [0x22] = 0xdd, [0x23] = 0x88,
5629 },
5630 { {0x40, 0x66cc } },
5631 },
5632 {
5633 "LD_IND halfword positive offset, all ff",
5634 .u.insns = {
5635 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
5636 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
5637 BPF_STMT(BPF_RET | BPF_A, 0x0),
5638 },
5639 CLASSIC,
5640 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5641 { {0x40, 0xffff } },
5642 },
5643 {
5644 "LD_IND halfword positive offset, out of bounds",
5645 .u.insns = {
5646 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5647 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
5648 BPF_STMT(BPF_RET | BPF_A, 0x0),
5649 },
5650 CLASSIC,
5651 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5652 { {0x3f, 0 }, },
5653 },
5654 {
5655 "LD_IND halfword negative offset, out of bounds",
5656 .u.insns = {
5657 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5658 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
5659 BPF_STMT(BPF_RET | BPF_A, 0x0),
5660 },
5661 CLASSIC,
5662 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5663 { {0x3f, 0 } },
5664 },
5665 {
5666 "LD_IND word positive offset",
5667 .u.insns = {
5668 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5669 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
5670 BPF_STMT(BPF_RET | BPF_A, 0x0),
5671 },
5672 CLASSIC,
5673 {
5674 [0x1c] = 0xaa, [0x1d] = 0x55,
5675 [0x1e] = 0xbb, [0x1f] = 0x66,
5676 [0x20] = 0xcc, [0x21] = 0x77,
5677 [0x22] = 0xdd, [0x23] = 0x88,
5678 [0x24] = 0xee, [0x25] = 0x99,
5679 [0x26] = 0xff, [0x27] = 0xaa,
5680 },
5681 { {0x40, 0xee99ffaa } },
5682 },
5683 {
5684 "LD_IND word negative offset",
5685 .u.insns = {
5686 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5687 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
5688 BPF_STMT(BPF_RET | BPF_A, 0x0),
5689 },
5690 CLASSIC,
5691 {
5692 [0x1c] = 0xaa, [0x1d] = 0x55,
5693 [0x1e] = 0xbb, [0x1f] = 0x66,
5694 [0x20] = 0xcc, [0x21] = 0x77,
5695 [0x22] = 0xdd, [0x23] = 0x88,
5696 [0x24] = 0xee, [0x25] = 0x99,
5697 [0x26] = 0xff, [0x27] = 0xaa,
5698 },
5699 { {0x40, 0xaa55bb66 } },
5700 },
5701 {
5702 "LD_IND word unaligned (addr & 3 == 2)",
5703 .u.insns = {
5704 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5705 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5706 BPF_STMT(BPF_RET | BPF_A, 0x0),
5707 },
5708 CLASSIC,
5709 {
5710 [0x1c] = 0xaa, [0x1d] = 0x55,
5711 [0x1e] = 0xbb, [0x1f] = 0x66,
5712 [0x20] = 0xcc, [0x21] = 0x77,
5713 [0x22] = 0xdd, [0x23] = 0x88,
5714 [0x24] = 0xee, [0x25] = 0x99,
5715 [0x26] = 0xff, [0x27] = 0xaa,
5716 },
5717 { {0x40, 0xbb66cc77 } },
5718 },
5719 {
5720 "LD_IND word unaligned (addr & 3 == 1)",
5721 .u.insns = {
5722 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5723 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
5724 BPF_STMT(BPF_RET | BPF_A, 0x0),
5725 },
5726 CLASSIC,
5727 {
5728 [0x1c] = 0xaa, [0x1d] = 0x55,
5729 [0x1e] = 0xbb, [0x1f] = 0x66,
5730 [0x20] = 0xcc, [0x21] = 0x77,
5731 [0x22] = 0xdd, [0x23] = 0x88,
5732 [0x24] = 0xee, [0x25] = 0x99,
5733 [0x26] = 0xff, [0x27] = 0xaa,
5734 },
5735 { {0x40, 0x55bb66cc } },
5736 },
5737 {
5738 "LD_IND word unaligned (addr & 3 == 3)",
5739 .u.insns = {
5740 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5741 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
5742 BPF_STMT(BPF_RET | BPF_A, 0x0),
5743 },
5744 CLASSIC,
5745 {
5746 [0x1c] = 0xaa, [0x1d] = 0x55,
5747 [0x1e] = 0xbb, [0x1f] = 0x66,
5748 [0x20] = 0xcc, [0x21] = 0x77,
5749 [0x22] = 0xdd, [0x23] = 0x88,
5750 [0x24] = 0xee, [0x25] = 0x99,
5751 [0x26] = 0xff, [0x27] = 0xaa,
5752 },
5753 { {0x40, 0x66cc77dd } },
5754 },
5755 {
5756 "LD_IND word positive offset, all ff",
5757 .u.insns = {
5758 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
5759 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
5760 BPF_STMT(BPF_RET | BPF_A, 0x0),
5761 },
5762 CLASSIC,
5763 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5764 { {0x40, 0xffffffff } },
5765 },
5766 {
5767 "LD_IND word positive offset, out of bounds",
5768 .u.insns = {
5769 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5770 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
5771 BPF_STMT(BPF_RET | BPF_A, 0x0),
5772 },
5773 CLASSIC,
5774 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5775 { {0x3f, 0 }, },
5776 },
5777 {
5778 "LD_IND word negative offset, out of bounds",
5779 .u.insns = {
5780 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5781 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
5782 BPF_STMT(BPF_RET | BPF_A, 0x0),
5783 },
5784 CLASSIC,
5785 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5786 { {0x3f, 0 } },
5787 },
5788 {
5789 "LD_ABS byte",
5790 .u.insns = {
5791 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
5792 BPF_STMT(BPF_RET | BPF_A, 0x0),
5793 },
5794 CLASSIC,
5795 {
5796 [0x1c] = 0xaa, [0x1d] = 0x55,
5797 [0x1e] = 0xbb, [0x1f] = 0x66,
5798 [0x20] = 0xcc, [0x21] = 0x77,
5799 [0x22] = 0xdd, [0x23] = 0x88,
5800 [0x24] = 0xee, [0x25] = 0x99,
5801 [0x26] = 0xff, [0x27] = 0xaa,
5802 },
5803 { {0x40, 0xcc } },
5804 },
5805 {
5806 "LD_ABS byte positive offset, all ff",
5807 .u.insns = {
5808 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
5809 BPF_STMT(BPF_RET | BPF_A, 0x0),
5810 },
5811 CLASSIC,
5812 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5813 { {0x40, 0xff } },
5814 },
5815 {
5816 "LD_ABS byte positive offset, out of bounds",
5817 .u.insns = {
5818 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
5819 BPF_STMT(BPF_RET | BPF_A, 0x0),
5820 },
5821 CLASSIC,
5822 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5823 { {0x3f, 0 }, },
5824 },
5825 {
5826 "LD_ABS byte negative offset, out of bounds load",
5827 .u.insns = {
5828 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
5829 BPF_STMT(BPF_RET | BPF_A, 0x0),
5830 },
5831 CLASSIC | FLAG_EXPECTED_FAIL,
5832 .expected_errcode = -EINVAL,
5833 },
5834 {
5835 "LD_ABS byte negative offset, in bounds",
5836 .u.insns = {
5837 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
5838 BPF_STMT(BPF_RET | BPF_A, 0x0),
5839 },
5840 CLASSIC,
5841 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5842 { {0x40, 0x82 }, },
5843 },
5844 {
5845 "LD_ABS byte negative offset, out of bounds",
5846 .u.insns = {
5847 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
5848 BPF_STMT(BPF_RET | BPF_A, 0x0),
5849 },
5850 CLASSIC,
5851 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5852 { {0x3f, 0 }, },
5853 },
5854 {
5855 "LD_ABS byte negative offset, multiple calls",
5856 .u.insns = {
5857 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
5858 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
5859 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
5860 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
5861 BPF_STMT(BPF_RET | BPF_A, 0x0),
5862 },
5863 CLASSIC,
5864 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5865 { {0x40, 0x82 }, },
5866 },
5867 {
5868 "LD_ABS halfword",
5869 .u.insns = {
5870 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
5871 BPF_STMT(BPF_RET | BPF_A, 0x0),
5872 },
5873 CLASSIC,
5874 {
5875 [0x1c] = 0xaa, [0x1d] = 0x55,
5876 [0x1e] = 0xbb, [0x1f] = 0x66,
5877 [0x20] = 0xcc, [0x21] = 0x77,
5878 [0x22] = 0xdd, [0x23] = 0x88,
5879 [0x24] = 0xee, [0x25] = 0x99,
5880 [0x26] = 0xff, [0x27] = 0xaa,
5881 },
5882 { {0x40, 0xdd88 } },
5883 },
5884 {
5885 "LD_ABS halfword unaligned",
5886 .u.insns = {
5887 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
5888 BPF_STMT(BPF_RET | BPF_A, 0x0),
5889 },
5890 CLASSIC,
5891 {
5892 [0x1c] = 0xaa, [0x1d] = 0x55,
5893 [0x1e] = 0xbb, [0x1f] = 0x66,
5894 [0x20] = 0xcc, [0x21] = 0x77,
5895 [0x22] = 0xdd, [0x23] = 0x88,
5896 [0x24] = 0xee, [0x25] = 0x99,
5897 [0x26] = 0xff, [0x27] = 0xaa,
5898 },
5899 { {0x40, 0x99ff } },
5900 },
5901 {
5902 "LD_ABS halfword positive offset, all ff",
5903 .u.insns = {
5904 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
5905 BPF_STMT(BPF_RET | BPF_A, 0x0),
5906 },
5907 CLASSIC,
5908 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5909 { {0x40, 0xffff } },
5910 },
5911 {
5912 "LD_ABS halfword positive offset, out of bounds",
5913 .u.insns = {
5914 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5915 BPF_STMT(BPF_RET | BPF_A, 0x0),
5916 },
5917 CLASSIC,
5918 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5919 { {0x3f, 0 }, },
5920 },
5921 {
5922 "LD_ABS halfword negative offset, out of bounds load",
5923 .u.insns = {
5924 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
5925 BPF_STMT(BPF_RET | BPF_A, 0x0),
5926 },
5927 CLASSIC | FLAG_EXPECTED_FAIL,
5928 .expected_errcode = -EINVAL,
5929 },
5930 {
5931 "LD_ABS halfword negative offset, in bounds",
5932 .u.insns = {
5933 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
5934 BPF_STMT(BPF_RET | BPF_A, 0x0),
5935 },
5936 CLASSIC,
5937 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5938 { {0x40, 0x1982 }, },
5939 },
5940 {
5941 "LD_ABS halfword negative offset, out of bounds",
5942 .u.insns = {
5943 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
5944 BPF_STMT(BPF_RET | BPF_A, 0x0),
5945 },
5946 CLASSIC,
5947 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5948 { {0x3f, 0 }, },
5949 },
5950 {
5951 "LD_ABS word",
5952 .u.insns = {
5953 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
5954 BPF_STMT(BPF_RET | BPF_A, 0x0),
5955 },
5956 CLASSIC,
5957 {
5958 [0x1c] = 0xaa, [0x1d] = 0x55,
5959 [0x1e] = 0xbb, [0x1f] = 0x66,
5960 [0x20] = 0xcc, [0x21] = 0x77,
5961 [0x22] = 0xdd, [0x23] = 0x88,
5962 [0x24] = 0xee, [0x25] = 0x99,
5963 [0x26] = 0xff, [0x27] = 0xaa,
5964 },
5965 { {0x40, 0xaa55bb66 } },
5966 },
5967 {
5968 "LD_ABS word unaligned (addr & 3 == 2)",
5969 .u.insns = {
5970 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
5971 BPF_STMT(BPF_RET | BPF_A, 0x0),
5972 },
5973 CLASSIC,
5974 {
5975 [0x1c] = 0xaa, [0x1d] = 0x55,
5976 [0x1e] = 0xbb, [0x1f] = 0x66,
5977 [0x20] = 0xcc, [0x21] = 0x77,
5978 [0x22] = 0xdd, [0x23] = 0x88,
5979 [0x24] = 0xee, [0x25] = 0x99,
5980 [0x26] = 0xff, [0x27] = 0xaa,
5981 },
5982 { {0x40, 0xdd88ee99 } },
5983 },
5984 {
5985 "LD_ABS word unaligned (addr & 3 == 1)",
5986 .u.insns = {
5987 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
5988 BPF_STMT(BPF_RET | BPF_A, 0x0),
5989 },
5990 CLASSIC,
5991 {
5992 [0x1c] = 0xaa, [0x1d] = 0x55,
5993 [0x1e] = 0xbb, [0x1f] = 0x66,
5994 [0x20] = 0xcc, [0x21] = 0x77,
5995 [0x22] = 0xdd, [0x23] = 0x88,
5996 [0x24] = 0xee, [0x25] = 0x99,
5997 [0x26] = 0xff, [0x27] = 0xaa,
5998 },
5999 { {0x40, 0x77dd88ee } },
6000 },
6001 {
6002 "LD_ABS word unaligned (addr & 3 == 3)",
6003 .u.insns = {
6004 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
6005 BPF_STMT(BPF_RET | BPF_A, 0x0),
6006 },
6007 CLASSIC,
6008 {
6009 [0x1c] = 0xaa, [0x1d] = 0x55,
6010 [0x1e] = 0xbb, [0x1f] = 0x66,
6011 [0x20] = 0xcc, [0x21] = 0x77,
6012 [0x22] = 0xdd, [0x23] = 0x88,
6013 [0x24] = 0xee, [0x25] = 0x99,
6014 [0x26] = 0xff, [0x27] = 0xaa,
6015 },
6016 { {0x40, 0x88ee99ff } },
6017 },
6018 {
6019 "LD_ABS word positive offset, all ff",
6020 .u.insns = {
6021 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
6022 BPF_STMT(BPF_RET | BPF_A, 0x0),
6023 },
6024 CLASSIC,
6025 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6026 { {0x40, 0xffffffff } },
6027 },
6028 {
6029 "LD_ABS word positive offset, out of bounds",
6030 .u.insns = {
6031 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
6032 BPF_STMT(BPF_RET | BPF_A, 0x0),
6033 },
6034 CLASSIC,
6035 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6036 { {0x3f, 0 }, },
6037 },
6038 {
6039 "LD_ABS word negative offset, out of bounds load",
6040 .u.insns = {
6041 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
6042 BPF_STMT(BPF_RET | BPF_A, 0x0),
6043 },
6044 CLASSIC | FLAG_EXPECTED_FAIL,
6045 .expected_errcode = -EINVAL,
6046 },
6047 {
6048 "LD_ABS word negative offset, in bounds",
6049 .u.insns = {
6050 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
6051 BPF_STMT(BPF_RET | BPF_A, 0x0),
6052 },
6053 CLASSIC,
6054 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6055 { {0x40, 0x25051982 }, },
6056 },
6057 {
6058 "LD_ABS word negative offset, out of bounds",
6059 .u.insns = {
6060 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
6061 BPF_STMT(BPF_RET | BPF_A, 0x0),
6062 },
6063 CLASSIC,
6064 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6065 { {0x3f, 0 }, },
6066 },
6067 {
6068 "LDX_MSH standalone, preserved A",
6069 .u.insns = {
6070 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6071 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6072 BPF_STMT(BPF_RET | BPF_A, 0x0),
6073 },
6074 CLASSIC,
6075 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6076 { {0x40, 0xffeebbaa }, },
6077 },
6078 {
6079 "LDX_MSH standalone, preserved A 2",
6080 .u.insns = {
6081 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
6082 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6083 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
6084 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
6085 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
6086 BPF_STMT(BPF_RET | BPF_A, 0x0),
6087 },
6088 CLASSIC,
6089 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6090 { {0x40, 0x175e9d63 }, },
6091 },
6092 {
6093 "LDX_MSH standalone, test result 1",
6094 .u.insns = {
6095 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6096 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6097 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6098 BPF_STMT(BPF_RET | BPF_A, 0x0),
6099 },
6100 CLASSIC,
6101 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6102 { {0x40, 0x14 }, },
6103 },
6104 {
6105 "LDX_MSH standalone, test result 2",
6106 .u.insns = {
6107 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6108 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
6109 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6110 BPF_STMT(BPF_RET | BPF_A, 0x0),
6111 },
6112 CLASSIC,
6113 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6114 { {0x40, 0x24 }, },
6115 },
6116 {
6117 "LDX_MSH standalone, negative offset",
6118 .u.insns = {
6119 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6120 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
6121 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6122 BPF_STMT(BPF_RET | BPF_A, 0x0),
6123 },
6124 CLASSIC,
6125 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6126 { {0x40, 0 }, },
6127 },
6128 {
6129 "LDX_MSH standalone, negative offset 2",
6130 .u.insns = {
6131 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6132 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
6133 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6134 BPF_STMT(BPF_RET | BPF_A, 0x0),
6135 },
6136 CLASSIC,
6137 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6138 { {0x40, 0x24 }, },
6139 },
6140 {
6141 "LDX_MSH standalone, out of bounds",
6142 .u.insns = {
6143 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6144 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
6145 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6146 BPF_STMT(BPF_RET | BPF_A, 0x0),
6147 },
6148 CLASSIC,
6149 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6150 { {0x40, 0 }, },
6151 },
6152 /*
6153 * verify that the interpreter or JIT correctly sets A and X
6154 * to 0.
6155 */
6156 {
6157 "ADD default X",
6158 .u.insns = {
6159 /*
6160 * A = 0x42
6161 * A = A + X
6162 * ret A
6163 */
6164 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6165 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
6166 BPF_STMT(BPF_RET | BPF_A, 0x0),
6167 },
6168 CLASSIC | FLAG_NO_DATA,
6169 {},
6170 { {0x1, 0x42 } },
6171 },
6172 {
6173 "ADD default A",
6174 .u.insns = {
6175 /*
6176 * A = A + 0x42
6177 * ret A
6178 */
6179 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
6180 BPF_STMT(BPF_RET | BPF_A, 0x0),
6181 },
6182 CLASSIC | FLAG_NO_DATA,
6183 {},
6184 { {0x1, 0x42 } },
6185 },
6186 {
6187 "SUB default X",
6188 .u.insns = {
6189 /*
6190 * A = 0x66
6191 * A = A - X
6192 * ret A
6193 */
6194 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
6195 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
6196 BPF_STMT(BPF_RET | BPF_A, 0x0),
6197 },
6198 CLASSIC | FLAG_NO_DATA,
6199 {},
6200 { {0x1, 0x66 } },
6201 },
6202 {
6203 "SUB default A",
6204 .u.insns = {
6205 /*
6206 * A = A - -0x66
6207 * ret A
6208 */
6209 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
6210 BPF_STMT(BPF_RET | BPF_A, 0x0),
6211 },
6212 CLASSIC | FLAG_NO_DATA,
6213 {},
6214 { {0x1, 0x66 } },
6215 },
6216 {
6217 "MUL default X",
6218 .u.insns = {
6219 /*
6220 * A = 0x42
6221 * A = A * X
6222 * ret A
6223 */
6224 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6225 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
6226 BPF_STMT(BPF_RET | BPF_A, 0x0),
6227 },
6228 CLASSIC | FLAG_NO_DATA,
6229 {},
6230 { {0x1, 0x0 } },
6231 },
6232 {
6233 "MUL default A",
6234 .u.insns = {
6235 /*
6236 * A = A * 0x66
6237 * ret A
6238 */
6239 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
6240 BPF_STMT(BPF_RET | BPF_A, 0x0),
6241 },
6242 CLASSIC | FLAG_NO_DATA,
6243 {},
6244 { {0x1, 0x0 } },
6245 },
6246 {
6247 "DIV default X",
6248 .u.insns = {
6249 /*
6250 * A = 0x42
6251 * A = A / X ; this halt the filter execution if X is 0
6252 * ret 0x42
6253 */
6254 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6255 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
6256 BPF_STMT(BPF_RET | BPF_K, 0x42),
6257 },
6258 CLASSIC | FLAG_NO_DATA,
6259 {},
6260 { {0x1, 0x0 } },
6261 },
6262 {
6263 "DIV default A",
6264 .u.insns = {
6265 /*
6266 * A = A / 1
6267 * ret A
6268 */
6269 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
6270 BPF_STMT(BPF_RET | BPF_A, 0x0),
6271 },
6272 CLASSIC | FLAG_NO_DATA,
6273 {},
6274 { {0x1, 0x0 } },
6275 },
6276 {
6277 "MOD default X",
6278 .u.insns = {
6279 /*
6280 * A = 0x42
6281 * A = A mod X ; this halt the filter execution if X is 0
6282 * ret 0x42
6283 */
6284 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6285 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
6286 BPF_STMT(BPF_RET | BPF_K, 0x42),
6287 },
6288 CLASSIC | FLAG_NO_DATA,
6289 {},
6290 { {0x1, 0x0 } },
6291 },
6292 {
6293 "MOD default A",
6294 .u.insns = {
6295 /*
6296 * A = A mod 1
6297 * ret A
6298 */
6299 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
6300 BPF_STMT(BPF_RET | BPF_A, 0x0),
6301 },
6302 CLASSIC | FLAG_NO_DATA,
6303 {},
6304 { {0x1, 0x0 } },
6305 },
6306 {
6307 "JMP EQ default A",
6308 .u.insns = {
6309 /*
6310 * cmp A, 0x0, 0, 1
6311 * ret 0x42
6312 * ret 0x66
6313 */
6314 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
6315 BPF_STMT(BPF_RET | BPF_K, 0x42),
6316 BPF_STMT(BPF_RET | BPF_K, 0x66),
6317 },
6318 CLASSIC | FLAG_NO_DATA,
6319 {},
6320 { {0x1, 0x42 } },
6321 },
6322 {
6323 "JMP EQ default X",
6324 .u.insns = {
6325 /*
6326 * A = 0x0
6327 * cmp A, X, 0, 1
6328 * ret 0x42
6329 * ret 0x66
6330 */
6331 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
6332 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
6333 BPF_STMT(BPF_RET | BPF_K, 0x42),
6334 BPF_STMT(BPF_RET | BPF_K, 0x66),
6335 },
6336 CLASSIC | FLAG_NO_DATA,
6337 {},
6338 { {0x1, 0x42 } },
6339 },
6340 /* Checking interpreter vs JIT wrt signed extended imms. */
6341 {
6342 "JNE signed compare, test 1",
6343 .u.insns_int = {
6344 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6345 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6346 BPF_MOV64_REG(R2, R1),
6347 BPF_ALU64_REG(BPF_AND, R2, R3),
6348 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6349 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
6350 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6351 BPF_EXIT_INSN(),
6352 },
6353 INTERNAL,
6354 { },
6355 { { 0, 1 } },
6356 },
6357 {
6358 "JNE signed compare, test 2",
6359 .u.insns_int = {
6360 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6361 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6362 BPF_MOV64_REG(R2, R1),
6363 BPF_ALU64_REG(BPF_AND, R2, R3),
6364 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6365 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
6366 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6367 BPF_EXIT_INSN(),
6368 },
6369 INTERNAL,
6370 { },
6371 { { 0, 1 } },
6372 },
6373 {
6374 "JNE signed compare, test 3",
6375 .u.insns_int = {
6376 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6377 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6378 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
6379 BPF_MOV64_REG(R2, R1),
6380 BPF_ALU64_REG(BPF_AND, R2, R3),
6381 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6382 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
6383 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6384 BPF_EXIT_INSN(),
6385 },
6386 INTERNAL,
6387 { },
6388 { { 0, 2 } },
6389 },
6390 {
6391 "JNE signed compare, test 4",
6392 .u.insns_int = {
6393 BPF_LD_IMM64(R1, -17104896),
6394 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6395 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
6396 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6397 BPF_EXIT_INSN(),
6398 },
6399 INTERNAL,
6400 { },
6401 { { 0, 2 } },
6402 },
6403 {
6404 "JNE signed compare, test 5",
6405 .u.insns_int = {
6406 BPF_LD_IMM64(R1, 0xfefb0000),
6407 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6408 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
6409 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6410 BPF_EXIT_INSN(),
6411 },
6412 INTERNAL,
6413 { },
6414 { { 0, 1 } },
6415 },
6416 {
6417 "JNE signed compare, test 6",
6418 .u.insns_int = {
6419 BPF_LD_IMM64(R1, 0x7efb0000),
6420 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6421 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
6422 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6423 BPF_EXIT_INSN(),
6424 },
6425 INTERNAL,
6426 { },
6427 { { 0, 2 } },
6428 },
6429 {
6430 "JNE signed compare, test 7",
6431 .u.insns = {
6432 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
6433 BPF_STMT(BPF_MISC | BPF_TAX, 0),
6434 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
6435 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
6436 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
6437 BPF_STMT(BPF_RET | BPF_K, 1),
6438 BPF_STMT(BPF_RET | BPF_K, 2),
6439 },
6440 CLASSIC | FLAG_NO_DATA,
6441 {},
6442 { { 0, 2 } },
6443 },
6444};
6445
6446static struct net_device dev;
6447
6448static struct sk_buff *populate_skb(char *buf, int size)
6449{
6450 struct sk_buff *skb;
6451
6452 if (size >= MAX_DATA)
6453 return NULL;
6454
6455 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
6456 if (!skb)
6457 return NULL;
6458
6459 __skb_put_data(skb, buf, size);
6460
6461 /* Initialize a fake skb with test pattern. */
6462 skb_reset_mac_header(skb);
6463 skb->protocol = htons(ETH_P_IP);
6464 skb->pkt_type = SKB_TYPE;
6465 skb->mark = SKB_MARK;
6466 skb->hash = SKB_HASH;
6467 skb->queue_mapping = SKB_QUEUE_MAP;
6468 skb->vlan_tci = SKB_VLAN_TCI;
6469 skb->vlan_present = SKB_VLAN_PRESENT;
6470 skb->vlan_proto = htons(ETH_P_IP);
6471 dev_net_set(&dev, &init_net);
6472 skb->dev = &dev;
6473 skb->dev->ifindex = SKB_DEV_IFINDEX;
6474 skb->dev->type = SKB_DEV_TYPE;
6475 skb_set_network_header(skb, min(size, ETH_HLEN));
6476
6477 return skb;
6478}
6479
6480static void *generate_test_data(struct bpf_test *test, int sub)
6481{
6482 struct sk_buff *skb;
6483 struct page *page;
6484
6485 if (test->aux & FLAG_NO_DATA)
6486 return NULL;
6487
6488 /* Test case expects an skb, so populate one. Various
6489 * subtests generate skbs of different sizes based on
6490 * the same data.
6491 */
6492 skb = populate_skb(test->data, test->test[sub].data_size);
6493 if (!skb)
6494 return NULL;
6495
6496 if (test->aux & FLAG_SKB_FRAG) {
6497 /*
6498 * when the test requires a fragmented skb, add a
6499 * single fragment to the skb, filled with
6500 * test->frag_data.
6501 */
6502 void *ptr;
6503
6504 page = alloc_page(GFP_KERNEL);
6505
6506 if (!page)
6507 goto err_kfree_skb;
6508
6509 ptr = kmap(page);
6510 if (!ptr)
6511 goto err_free_page;
6512 memcpy(ptr, test->frag_data, MAX_DATA);
6513 kunmap(page);
6514 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
6515 }
6516
6517 return skb;
6518
6519err_free_page:
6520 __free_page(page);
6521err_kfree_skb:
6522 kfree_skb(skb);
6523 return NULL;
6524}
6525
6526static void release_test_data(const struct bpf_test *test, void *data)
6527{
6528 if (test->aux & FLAG_NO_DATA)
6529 return;
6530
6531 kfree_skb(data);
6532}
6533
6534static int filter_length(int which)
6535{
6536 struct sock_filter *fp;
6537 int len;
6538
6539 if (tests[which].fill_helper)
6540 return tests[which].u.ptr.len;
6541
6542 fp = tests[which].u.insns;
6543 for (len = MAX_INSNS - 1; len > 0; --len)
6544 if (fp[len].code != 0 || fp[len].k != 0)
6545 break;
6546
6547 return len + 1;
6548}
6549
6550static void *filter_pointer(int which)
6551{
6552 if (tests[which].fill_helper)
6553 return tests[which].u.ptr.insns;
6554 else
6555 return tests[which].u.insns;
6556}
6557
6558static struct bpf_prog *generate_filter(int which, int *err)
6559{
6560 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
6561 unsigned int flen = filter_length(which);
6562 void *fptr = filter_pointer(which);
6563 struct sock_fprog_kern fprog;
6564 struct bpf_prog *fp;
6565
6566 switch (test_type) {
6567 case CLASSIC:
6568 fprog.filter = fptr;
6569 fprog.len = flen;
6570
6571 *err = bpf_prog_create(&fp, &fprog);
6572 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
6573 if (*err == tests[which].expected_errcode) {
6574 pr_cont("PASS\n");
6575 /* Verifier rejected filter as expected. */
6576 *err = 0;
6577 return NULL;
6578 } else {
6579 pr_cont("UNEXPECTED_PASS\n");
6580 /* Verifier didn't reject the test that's
6581 * bad enough, just return!
6582 */
6583 *err = -EINVAL;
6584 return NULL;
6585 }
6586 }
6587 if (*err) {
6588 pr_cont("FAIL to prog_create err=%d len=%d\n",
6589 *err, fprog.len);
6590 return NULL;
6591 }
6592 break;
6593
6594 case INTERNAL:
6595 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
6596 if (fp == NULL) {
6597 pr_cont("UNEXPECTED_FAIL no memory left\n");
6598 *err = -ENOMEM;
6599 return NULL;
6600 }
6601
6602 fp->len = flen;
6603 /* Type doesn't really matter here as long as it's not unspec. */
6604 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
6605 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
6606 fp->aux->stack_depth = tests[which].stack_depth;
6607
6608 /* We cannot error here as we don't need type compatibility
6609 * checks.
6610 */
6611 fp = bpf_prog_select_runtime(fp, err);
6612 if (*err) {
6613 pr_cont("FAIL to select_runtime err=%d\n", *err);
6614 return NULL;
6615 }
6616 break;
6617 }
6618
6619 *err = 0;
6620 return fp;
6621}
6622
6623static void release_filter(struct bpf_prog *fp, int which)
6624{
6625 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
6626
6627 switch (test_type) {
6628 case CLASSIC:
6629 bpf_prog_destroy(fp);
6630 break;
6631 case INTERNAL:
6632 bpf_prog_free(fp);
6633 break;
6634 }
6635}
6636
6637static int __run_one(const struct bpf_prog *fp, const void *data,
6638 int runs, u64 *duration)
6639{
6640 u64 start, finish;
6641 int ret = 0, i;
6642
6643 migrate_disable();
6644 start = ktime_get_ns();
6645
6646 for (i = 0; i < runs; i++)
6647 ret = BPF_PROG_RUN(fp, data);
6648
6649 finish = ktime_get_ns();
6650 migrate_enable();
6651
6652 *duration = finish - start;
6653 do_div(*duration, runs);
6654
6655 return ret;
6656}
6657
6658static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
6659{
6660 int err_cnt = 0, i, runs = MAX_TESTRUNS;
6661
6662 for (i = 0; i < MAX_SUBTESTS; i++) {
6663 void *data;
6664 u64 duration;
6665 u32 ret;
6666
6667 if (test->test[i].data_size == 0 &&
6668 test->test[i].result == 0)
6669 break;
6670
6671 data = generate_test_data(test, i);
6672 if (!data && !(test->aux & FLAG_NO_DATA)) {
6673 pr_cont("data generation failed ");
6674 err_cnt++;
6675 break;
6676 }
6677 ret = __run_one(fp, data, runs, &duration);
6678 release_test_data(test, data);
6679
6680 if (ret == test->test[i].result) {
6681 pr_cont("%lld ", duration);
6682 } else {
6683 pr_cont("ret %d != %d ", ret,
6684 test->test[i].result);
6685 err_cnt++;
6686 }
6687 }
6688
6689 return err_cnt;
6690}
6691
6692static char test_name[64];
6693module_param_string(test_name, test_name, sizeof(test_name), 0);
6694
6695static int test_id = -1;
6696module_param(test_id, int, 0);
6697
6698static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
6699module_param_array(test_range, int, NULL, 0);
6700
6701static __init int find_test_index(const char *test_name)
6702{
6703 int i;
6704
6705 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6706 if (!strcmp(tests[i].descr, test_name))
6707 return i;
6708 }
6709 return -1;
6710}
6711
6712static __init int prepare_bpf_tests(void)
6713{
6714 int i;
6715
6716 if (test_id >= 0) {
6717 /*
6718 * if a test_id was specified, use test_range to
6719 * cover only that test.
6720 */
6721 if (test_id >= ARRAY_SIZE(tests)) {
6722 pr_err("test_bpf: invalid test_id specified.\n");
6723 return -EINVAL;
6724 }
6725
6726 test_range[0] = test_id;
6727 test_range[1] = test_id;
6728 } else if (*test_name) {
6729 /*
6730 * if a test_name was specified, find it and setup
6731 * test_range to cover only that test.
6732 */
6733 int idx = find_test_index(test_name);
6734
6735 if (idx < 0) {
6736 pr_err("test_bpf: no test named '%s' found.\n",
6737 test_name);
6738 return -EINVAL;
6739 }
6740 test_range[0] = idx;
6741 test_range[1] = idx;
6742 } else {
6743 /*
6744 * check that the supplied test_range is valid.
6745 */
6746 if (test_range[0] >= ARRAY_SIZE(tests) ||
6747 test_range[1] >= ARRAY_SIZE(tests) ||
6748 test_range[0] < 0 || test_range[1] < 0) {
6749 pr_err("test_bpf: test_range is out of bound.\n");
6750 return -EINVAL;
6751 }
6752
6753 if (test_range[1] < test_range[0]) {
6754 pr_err("test_bpf: test_range is ending before it starts.\n");
6755 return -EINVAL;
6756 }
6757 }
6758
6759 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6760 if (tests[i].fill_helper &&
6761 tests[i].fill_helper(&tests[i]) < 0)
6762 return -ENOMEM;
6763 }
6764
6765 return 0;
6766}
6767
6768static __init void destroy_bpf_tests(void)
6769{
6770 int i;
6771
6772 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6773 if (tests[i].fill_helper)
6774 kfree(tests[i].u.ptr.insns);
6775 }
6776}
6777
6778static bool exclude_test(int test_id)
6779{
6780 return test_id < test_range[0] || test_id > test_range[1];
6781}
6782
6783static __init struct sk_buff *build_test_skb(void)
6784{
6785 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
6786 struct sk_buff *skb[2];
6787 struct page *page[2];
6788 int i, data_size = 8;
6789
6790 for (i = 0; i < 2; i++) {
6791 page[i] = alloc_page(GFP_KERNEL);
6792 if (!page[i]) {
6793 if (i == 0)
6794 goto err_page0;
6795 else
6796 goto err_page1;
6797 }
6798
6799 /* this will set skb[i]->head_frag */
6800 skb[i] = dev_alloc_skb(headroom + data_size);
6801 if (!skb[i]) {
6802 if (i == 0)
6803 goto err_skb0;
6804 else
6805 goto err_skb1;
6806 }
6807
6808 skb_reserve(skb[i], headroom);
6809 skb_put(skb[i], data_size);
6810 skb[i]->protocol = htons(ETH_P_IP);
6811 skb_reset_network_header(skb[i]);
6812 skb_set_mac_header(skb[i], -ETH_HLEN);
6813
6814 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
6815 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
6816 }
6817
6818 /* setup shinfo */
6819 skb_shinfo(skb[0])->gso_size = 1448;
6820 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
6821 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
6822 skb_shinfo(skb[0])->gso_segs = 0;
6823 skb_shinfo(skb[0])->frag_list = skb[1];
6824
6825 /* adjust skb[0]'s len */
6826 skb[0]->len += skb[1]->len;
6827 skb[0]->data_len += skb[1]->data_len;
6828 skb[0]->truesize += skb[1]->truesize;
6829
6830 return skb[0];
6831
6832err_skb1:
6833 __free_page(page[1]);
6834err_page1:
6835 kfree_skb(skb[0]);
6836err_skb0:
6837 __free_page(page[0]);
6838err_page0:
6839 return NULL;
6840}
6841
6842static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
6843{
6844 unsigned int alloc_size = 2000;
6845 unsigned int headroom = 102, doffset = 72, data_size = 1308;
6846 struct sk_buff *skb[2];
6847 int i;
6848
6849 /* skbs linked in a frag_list, both with linear data, with head_frag=0
6850 * (data allocated by kmalloc), both have tcp data of 1308 bytes
6851 * (total payload is 2616 bytes).
6852 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
6853 */
6854 for (i = 0; i < 2; i++) {
6855 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
6856 if (!skb[i]) {
6857 if (i == 0)
6858 goto err_skb0;
6859 else
6860 goto err_skb1;
6861 }
6862
6863 skb[i]->protocol = htons(ETH_P_IPV6);
6864 skb_reserve(skb[i], headroom);
6865 skb_put(skb[i], doffset + data_size);
6866 skb_reset_network_header(skb[i]);
6867 if (i == 0)
6868 skb_reset_mac_header(skb[i]);
6869 else
6870 skb_set_mac_header(skb[i], -ETH_HLEN);
6871 __skb_pull(skb[i], doffset);
6872 }
6873
6874 /* setup shinfo.
6875 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
6876 * reduced gso_size.
6877 */
6878 skb_shinfo(skb[0])->gso_size = 1288;
6879 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
6880 skb_shinfo(skb[0])->gso_segs = 0;
6881 skb_shinfo(skb[0])->frag_list = skb[1];
6882
6883 /* adjust skb[0]'s len */
6884 skb[0]->len += skb[1]->len;
6885 skb[0]->data_len += skb[1]->len;
6886 skb[0]->truesize += skb[1]->truesize;
6887
6888 return skb[0];
6889
6890err_skb1:
6891 kfree_skb(skb[0]);
6892err_skb0:
6893 return NULL;
6894}
6895
6896struct skb_segment_test {
6897 const char *descr;
6898 struct sk_buff *(*build_skb)(void);
6899 netdev_features_t features;
6900};
6901
6902static struct skb_segment_test skb_segment_tests[] __initconst = {
6903 {
6904 .descr = "gso_with_rx_frags",
6905 .build_skb = build_test_skb,
6906 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
6907 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
6908 },
6909 {
6910 .descr = "gso_linear_no_head_frag",
6911 .build_skb = build_test_skb_linear_no_head_frag,
6912 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
6913 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
6914 NETIF_F_LLTX_BIT | NETIF_F_GRO |
6915 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
6916 NETIF_F_HW_VLAN_STAG_TX_BIT
6917 }
6918};
6919
6920static __init int test_skb_segment_single(const struct skb_segment_test *test)
6921{
6922 struct sk_buff *skb, *segs;
6923 int ret = -1;
6924
6925 skb = test->build_skb();
6926 if (!skb) {
6927 pr_info("%s: failed to build_test_skb", __func__);
6928 goto done;
6929 }
6930
6931 segs = skb_segment(skb, test->features);
6932 if (!IS_ERR(segs)) {
6933 kfree_skb_list(segs);
6934 ret = 0;
6935 }
6936 kfree_skb(skb);
6937done:
6938 return ret;
6939}
6940
6941static __init int test_skb_segment(void)
6942{
6943 int i, err_cnt = 0, pass_cnt = 0;
6944
6945 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
6946 const struct skb_segment_test *test = &skb_segment_tests[i];
6947
6948 pr_info("#%d %s ", i, test->descr);
6949
6950 if (test_skb_segment_single(test)) {
6951 pr_cont("FAIL\n");
6952 err_cnt++;
6953 } else {
6954 pr_cont("PASS\n");
6955 pass_cnt++;
6956 }
6957 }
6958
6959 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
6960 pass_cnt, err_cnt);
6961 return err_cnt ? -EINVAL : 0;
6962}
6963
6964static __init int test_bpf(void)
6965{
6966 int i, err_cnt = 0, pass_cnt = 0;
6967 int jit_cnt = 0, run_cnt = 0;
6968
6969 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6970 struct bpf_prog *fp;
6971 int err;
6972
6973 cond_resched();
6974 if (exclude_test(i))
6975 continue;
6976
6977 pr_info("#%d %s ", i, tests[i].descr);
6978
6979 fp = generate_filter(i, &err);
6980 if (fp == NULL) {
6981 if (err == 0) {
6982 pass_cnt++;
6983 continue;
6984 }
6985 err_cnt++;
6986 continue;
6987 }
6988
6989 pr_cont("jited:%u ", fp->jited);
6990
6991 run_cnt++;
6992 if (fp->jited)
6993 jit_cnt++;
6994
6995 err = run_one(fp, &tests[i]);
6996 release_filter(fp, i);
6997
6998 if (err) {
6999 pr_cont("FAIL (%d times)\n", err);
7000 err_cnt++;
7001 } else {
7002 pr_cont("PASS\n");
7003 pass_cnt++;
7004 }
7005 }
7006
7007 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
7008 pass_cnt, err_cnt, jit_cnt, run_cnt);
7009
7010 return err_cnt ? -EINVAL : 0;
7011}
7012
7013static int __init test_bpf_init(void)
7014{
7015 int ret;
7016
7017 ret = prepare_bpf_tests();
7018 if (ret < 0)
7019 return ret;
7020
7021 ret = test_bpf();
7022 destroy_bpf_tests();
7023 if (ret)
7024 return ret;
7025
7026 return test_skb_segment();
7027}
7028
7029static void __exit test_bpf_exit(void)
7030{
7031}
7032
7033module_init(test_bpf_init);
7034module_exit(test_bpf_exit);
7035
7036MODULE_LICENSE("GPL");