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