xref: /openbmc/linux/lib/test_bpf.c (revision 8b235f2f)
1 /*
2  * Testsuite for BPF interpreter and BPF JIT compiler
3  *
4  * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  */
15 
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/filter.h>
21 #include <linux/bpf.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_vlan.h>
25 #include <linux/random.h>
26 #include <linux/highmem.h>
27 
28 /* General test specific settings */
29 #define MAX_SUBTESTS	3
30 #define MAX_TESTRUNS	10000
31 #define MAX_DATA	128
32 #define MAX_INSNS	512
33 #define MAX_K		0xffffFFFF
34 
35 /* Few constants used to init test 'skb' */
36 #define SKB_TYPE	3
37 #define SKB_MARK	0x1234aaaa
38 #define SKB_HASH	0x1234aaab
39 #define SKB_QUEUE_MAP	123
40 #define SKB_VLAN_TCI	0xffff
41 #define SKB_DEV_IFINDEX	577
42 #define SKB_DEV_TYPE	588
43 
44 /* Redefine REGs to make tests less verbose */
45 #define R0		BPF_REG_0
46 #define R1		BPF_REG_1
47 #define R2		BPF_REG_2
48 #define R3		BPF_REG_3
49 #define R4		BPF_REG_4
50 #define R5		BPF_REG_5
51 #define R6		BPF_REG_6
52 #define R7		BPF_REG_7
53 #define R8		BPF_REG_8
54 #define R9		BPF_REG_9
55 #define R10		BPF_REG_10
56 
57 /* Flags that can be passed to test cases */
58 #define FLAG_NO_DATA		BIT(0)
59 #define FLAG_EXPECTED_FAIL	BIT(1)
60 #define FLAG_SKB_FRAG		BIT(2)
61 
62 enum {
63 	CLASSIC  = BIT(6),	/* Old BPF instructions only. */
64 	INTERNAL = BIT(7),	/* Extended instruction set.  */
65 };
66 
67 #define TEST_TYPE_MASK		(CLASSIC | INTERNAL)
68 
69 struct bpf_test {
70 	const char *descr;
71 	union {
72 		struct sock_filter insns[MAX_INSNS];
73 		struct bpf_insn insns_int[MAX_INSNS];
74 		struct {
75 			void *insns;
76 			unsigned int len;
77 		} ptr;
78 	} u;
79 	__u8 aux;
80 	__u8 data[MAX_DATA];
81 	struct {
82 		int data_size;
83 		__u32 result;
84 	} test[MAX_SUBTESTS];
85 	int (*fill_helper)(struct bpf_test *self);
86 	__u8 frag_data[MAX_DATA];
87 };
88 
89 /* Large test cases need separate allocation and fill handler. */
90 
91 static int bpf_fill_maxinsns1(struct bpf_test *self)
92 {
93 	unsigned int len = BPF_MAXINSNS;
94 	struct sock_filter *insn;
95 	__u32 k = ~0;
96 	int i;
97 
98 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
99 	if (!insn)
100 		return -ENOMEM;
101 
102 	for (i = 0; i < len; i++, k--)
103 		insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
104 
105 	self->u.ptr.insns = insn;
106 	self->u.ptr.len = len;
107 
108 	return 0;
109 }
110 
111 static int bpf_fill_maxinsns2(struct bpf_test *self)
112 {
113 	unsigned int len = BPF_MAXINSNS;
114 	struct sock_filter *insn;
115 	int i;
116 
117 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
118 	if (!insn)
119 		return -ENOMEM;
120 
121 	for (i = 0; i < len; i++)
122 		insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
123 
124 	self->u.ptr.insns = insn;
125 	self->u.ptr.len = len;
126 
127 	return 0;
128 }
129 
130 static int bpf_fill_maxinsns3(struct bpf_test *self)
131 {
132 	unsigned int len = BPF_MAXINSNS;
133 	struct sock_filter *insn;
134 	struct rnd_state rnd;
135 	int i;
136 
137 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
138 	if (!insn)
139 		return -ENOMEM;
140 
141 	prandom_seed_state(&rnd, 3141592653589793238ULL);
142 
143 	for (i = 0; i < len - 1; i++) {
144 		__u32 k = prandom_u32_state(&rnd);
145 
146 		insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
147 	}
148 
149 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
150 
151 	self->u.ptr.insns = insn;
152 	self->u.ptr.len = len;
153 
154 	return 0;
155 }
156 
157 static int bpf_fill_maxinsns4(struct bpf_test *self)
158 {
159 	unsigned int len = BPF_MAXINSNS + 1;
160 	struct sock_filter *insn;
161 	int i;
162 
163 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
164 	if (!insn)
165 		return -ENOMEM;
166 
167 	for (i = 0; i < len; i++)
168 		insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
169 
170 	self->u.ptr.insns = insn;
171 	self->u.ptr.len = len;
172 
173 	return 0;
174 }
175 
176 static int bpf_fill_maxinsns5(struct bpf_test *self)
177 {
178 	unsigned int len = BPF_MAXINSNS;
179 	struct sock_filter *insn;
180 	int i;
181 
182 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
183 	if (!insn)
184 		return -ENOMEM;
185 
186 	insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
187 
188 	for (i = 1; i < len - 1; i++)
189 		insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
190 
191 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
192 
193 	self->u.ptr.insns = insn;
194 	self->u.ptr.len = len;
195 
196 	return 0;
197 }
198 
199 static int bpf_fill_maxinsns6(struct bpf_test *self)
200 {
201 	unsigned int len = BPF_MAXINSNS;
202 	struct sock_filter *insn;
203 	int i;
204 
205 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
206 	if (!insn)
207 		return -ENOMEM;
208 
209 	for (i = 0; i < len - 1; i++)
210 		insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
211 				     SKF_AD_VLAN_TAG_PRESENT);
212 
213 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
214 
215 	self->u.ptr.insns = insn;
216 	self->u.ptr.len = len;
217 
218 	return 0;
219 }
220 
221 static int bpf_fill_maxinsns7(struct bpf_test *self)
222 {
223 	unsigned int len = BPF_MAXINSNS;
224 	struct sock_filter *insn;
225 	int i;
226 
227 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
228 	if (!insn)
229 		return -ENOMEM;
230 
231 	for (i = 0; i < len - 4; i++)
232 		insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
233 				     SKF_AD_CPU);
234 
235 	insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
236 	insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
237 				   SKF_AD_CPU);
238 	insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
239 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
240 
241 	self->u.ptr.insns = insn;
242 	self->u.ptr.len = len;
243 
244 	return 0;
245 }
246 
247 static int bpf_fill_maxinsns8(struct bpf_test *self)
248 {
249 	unsigned int len = BPF_MAXINSNS;
250 	struct sock_filter *insn;
251 	int i, jmp_off = len - 3;
252 
253 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
254 	if (!insn)
255 		return -ENOMEM;
256 
257 	insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
258 
259 	for (i = 1; i < len - 1; i++)
260 		insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
261 
262 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
263 
264 	self->u.ptr.insns = insn;
265 	self->u.ptr.len = len;
266 
267 	return 0;
268 }
269 
270 static int bpf_fill_maxinsns9(struct bpf_test *self)
271 {
272 	unsigned int len = BPF_MAXINSNS;
273 	struct bpf_insn *insn;
274 	int i;
275 
276 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
277 	if (!insn)
278 		return -ENOMEM;
279 
280 	insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
281 	insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
282 	insn[2] = BPF_EXIT_INSN();
283 
284 	for (i = 3; i < len - 2; i++)
285 		insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
286 
287 	insn[len - 2] = BPF_EXIT_INSN();
288 	insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
289 
290 	self->u.ptr.insns = insn;
291 	self->u.ptr.len = len;
292 
293 	return 0;
294 }
295 
296 static int bpf_fill_maxinsns10(struct bpf_test *self)
297 {
298 	unsigned int len = BPF_MAXINSNS, hlen = len - 2;
299 	struct bpf_insn *insn;
300 	int i;
301 
302 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
303 	if (!insn)
304 		return -ENOMEM;
305 
306 	for (i = 0; i < hlen / 2; i++)
307 		insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
308 	for (i = hlen - 1; i > hlen / 2; i--)
309 		insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
310 
311 	insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
312 	insn[hlen]     = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
313 	insn[hlen + 1] = BPF_EXIT_INSN();
314 
315 	self->u.ptr.insns = insn;
316 	self->u.ptr.len = len;
317 
318 	return 0;
319 }
320 
321 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
322 			 unsigned int plen)
323 {
324 	struct sock_filter *insn;
325 	unsigned int rlen;
326 	int i, j;
327 
328 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
329 	if (!insn)
330 		return -ENOMEM;
331 
332 	rlen = (len % plen) - 1;
333 
334 	for (i = 0; i + plen < len; i += plen)
335 		for (j = 0; j < plen; j++)
336 			insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
337 						 plen - 1 - j, 0, 0);
338 	for (j = 0; j < rlen; j++)
339 		insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
340 					 0, 0);
341 
342 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
343 
344 	self->u.ptr.insns = insn;
345 	self->u.ptr.len = len;
346 
347 	return 0;
348 }
349 
350 static int bpf_fill_maxinsns11(struct bpf_test *self)
351 {
352 	/* Hits 70 passes on x86_64, so cannot get JITed there. */
353 	return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
354 }
355 
356 static int bpf_fill_ja(struct bpf_test *self)
357 {
358 	/* Hits exactly 11 passes on x86_64 JIT. */
359 	return __bpf_fill_ja(self, 12, 9);
360 }
361 
362 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
363 {
364 	unsigned int len = BPF_MAXINSNS;
365 	struct sock_filter *insn;
366 	int i;
367 
368 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
369 	if (!insn)
370 		return -ENOMEM;
371 
372 	for (i = 0; i < len - 1; i += 2) {
373 		insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
374 		insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
375 					 SKF_AD_OFF + SKF_AD_CPU);
376 	}
377 
378 	insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
379 
380 	self->u.ptr.insns = insn;
381 	self->u.ptr.len = len;
382 
383 	return 0;
384 }
385 
386 #define PUSH_CNT 68
387 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
388 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
389 {
390 	unsigned int len = BPF_MAXINSNS;
391 	struct bpf_insn *insn;
392 	int i = 0, j, k = 0;
393 
394 	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
395 	if (!insn)
396 		return -ENOMEM;
397 
398 	insn[i++] = BPF_MOV64_REG(R6, R1);
399 loop:
400 	for (j = 0; j < PUSH_CNT; j++) {
401 		insn[i++] = BPF_LD_ABS(BPF_B, 0);
402 		insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
403 		i++;
404 		insn[i++] = BPF_MOV64_REG(R1, R6);
405 		insn[i++] = BPF_MOV64_IMM(R2, 1);
406 		insn[i++] = BPF_MOV64_IMM(R3, 2);
407 		insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
408 					 bpf_skb_vlan_push_proto.func - __bpf_call_base);
409 		insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
410 		i++;
411 	}
412 
413 	for (j = 0; j < PUSH_CNT; j++) {
414 		insn[i++] = BPF_LD_ABS(BPF_B, 0);
415 		insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
416 		i++;
417 		insn[i++] = BPF_MOV64_REG(R1, R6);
418 		insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
419 					 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
420 		insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
421 		i++;
422 	}
423 	if (++k < 5)
424 		goto loop;
425 
426 	for (; i < len - 1; i++)
427 		insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
428 
429 	insn[len - 1] = BPF_EXIT_INSN();
430 
431 	self->u.ptr.insns = insn;
432 	self->u.ptr.len = len;
433 
434 	return 0;
435 }
436 
437 static struct bpf_test tests[] = {
438 	{
439 		"TAX",
440 		.u.insns = {
441 			BPF_STMT(BPF_LD | BPF_IMM, 1),
442 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
443 			BPF_STMT(BPF_LD | BPF_IMM, 2),
444 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
445 			BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
446 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
447 			BPF_STMT(BPF_LD | BPF_LEN, 0),
448 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
449 			BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
450 			BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
451 			BPF_STMT(BPF_RET | BPF_A, 0)
452 		},
453 		CLASSIC,
454 		{ 10, 20, 30, 40, 50 },
455 		{ { 2, 10 }, { 3, 20 }, { 4, 30 } },
456 	},
457 	{
458 		"TXA",
459 		.u.insns = {
460 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
461 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
462 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
463 			BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
464 		},
465 		CLASSIC,
466 		{ 10, 20, 30, 40, 50 },
467 		{ { 1, 2 }, { 3, 6 }, { 4, 8 } },
468 	},
469 	{
470 		"ADD_SUB_MUL_K",
471 		.u.insns = {
472 			BPF_STMT(BPF_LD | BPF_IMM, 1),
473 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
474 			BPF_STMT(BPF_LDX | BPF_IMM, 3),
475 			BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
476 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
477 			BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
478 			BPF_STMT(BPF_RET | BPF_A, 0)
479 		},
480 		CLASSIC | FLAG_NO_DATA,
481 		{ },
482 		{ { 0, 0xfffffffd } }
483 	},
484 	{
485 		"DIV_MOD_KX",
486 		.u.insns = {
487 			BPF_STMT(BPF_LD | BPF_IMM, 8),
488 			BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
489 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
490 			BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
491 			BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
492 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
493 			BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
494 			BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
495 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
496 			BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
497 			BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
498 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
499 			BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
500 			BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
501 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
502 			BPF_STMT(BPF_RET | BPF_A, 0)
503 		},
504 		CLASSIC | FLAG_NO_DATA,
505 		{ },
506 		{ { 0, 0x20000000 } }
507 	},
508 	{
509 		"AND_OR_LSH_K",
510 		.u.insns = {
511 			BPF_STMT(BPF_LD | BPF_IMM, 0xff),
512 			BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
513 			BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
514 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
515 			BPF_STMT(BPF_LD | BPF_IMM, 0xf),
516 			BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
517 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
518 			BPF_STMT(BPF_RET | BPF_A, 0)
519 		},
520 		CLASSIC | FLAG_NO_DATA,
521 		{ },
522 		{ { 0, 0x800000ff }, { 1, 0x800000ff } },
523 	},
524 	{
525 		"LD_IMM_0",
526 		.u.insns = {
527 			BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
528 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
529 			BPF_STMT(BPF_RET | BPF_K, 0),
530 			BPF_STMT(BPF_RET | BPF_K, 1),
531 		},
532 		CLASSIC,
533 		{ },
534 		{ { 1, 1 } },
535 	},
536 	{
537 		"LD_IND",
538 		.u.insns = {
539 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
540 			BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
541 			BPF_STMT(BPF_RET | BPF_K, 1)
542 		},
543 		CLASSIC,
544 		{ },
545 		{ { 1, 0 }, { 10, 0 }, { 60, 0 } },
546 	},
547 	{
548 		"LD_ABS",
549 		.u.insns = {
550 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
551 			BPF_STMT(BPF_RET | BPF_K, 1)
552 		},
553 		CLASSIC,
554 		{ },
555 		{ { 1, 0 }, { 10, 0 }, { 60, 0 } },
556 	},
557 	{
558 		"LD_ABS_LL",
559 		.u.insns = {
560 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
561 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
562 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
563 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
564 			BPF_STMT(BPF_RET | BPF_A, 0)
565 		},
566 		CLASSIC,
567 		{ 1, 2, 3 },
568 		{ { 1, 0 }, { 2, 3 } },
569 	},
570 	{
571 		"LD_IND_LL",
572 		.u.insns = {
573 			BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
574 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
575 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
576 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
577 			BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
578 			BPF_STMT(BPF_RET | BPF_A, 0)
579 		},
580 		CLASSIC,
581 		{ 1, 2, 3, 0xff },
582 		{ { 1, 1 }, { 3, 3 }, { 4, 0xff } },
583 	},
584 	{
585 		"LD_ABS_NET",
586 		.u.insns = {
587 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
588 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
590 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
591 			BPF_STMT(BPF_RET | BPF_A, 0)
592 		},
593 		CLASSIC,
594 		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
595 		{ { 15, 0 }, { 16, 3 } },
596 	},
597 	{
598 		"LD_IND_NET",
599 		.u.insns = {
600 			BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
601 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
603 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
604 			BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
605 			BPF_STMT(BPF_RET | BPF_A, 0)
606 		},
607 		CLASSIC,
608 		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
609 		{ { 14, 0 }, { 15, 1 }, { 17, 3 } },
610 	},
611 	{
612 		"LD_PKTTYPE",
613 		.u.insns = {
614 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
615 				 SKF_AD_OFF + SKF_AD_PKTTYPE),
616 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
617 			BPF_STMT(BPF_RET | BPF_K, 1),
618 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
619 				 SKF_AD_OFF + SKF_AD_PKTTYPE),
620 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
621 			BPF_STMT(BPF_RET | BPF_K, 1),
622 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
623 				 SKF_AD_OFF + SKF_AD_PKTTYPE),
624 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
625 			BPF_STMT(BPF_RET | BPF_K, 1),
626 			BPF_STMT(BPF_RET | BPF_A, 0)
627 		},
628 		CLASSIC,
629 		{ },
630 		{ { 1, 3 }, { 10, 3 } },
631 	},
632 	{
633 		"LD_MARK",
634 		.u.insns = {
635 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
636 				 SKF_AD_OFF + SKF_AD_MARK),
637 			BPF_STMT(BPF_RET | BPF_A, 0)
638 		},
639 		CLASSIC,
640 		{ },
641 		{ { 1, SKB_MARK}, { 10, SKB_MARK} },
642 	},
643 	{
644 		"LD_RXHASH",
645 		.u.insns = {
646 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
647 				 SKF_AD_OFF + SKF_AD_RXHASH),
648 			BPF_STMT(BPF_RET | BPF_A, 0)
649 		},
650 		CLASSIC,
651 		{ },
652 		{ { 1, SKB_HASH}, { 10, SKB_HASH} },
653 	},
654 	{
655 		"LD_QUEUE",
656 		.u.insns = {
657 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
658 				 SKF_AD_OFF + SKF_AD_QUEUE),
659 			BPF_STMT(BPF_RET | BPF_A, 0)
660 		},
661 		CLASSIC,
662 		{ },
663 		{ { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
664 	},
665 	{
666 		"LD_PROTOCOL",
667 		.u.insns = {
668 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
669 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
670 			BPF_STMT(BPF_RET | BPF_K, 0),
671 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
672 				 SKF_AD_OFF + SKF_AD_PROTOCOL),
673 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
674 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
675 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
676 			BPF_STMT(BPF_RET | BPF_K, 0),
677 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
678 			BPF_STMT(BPF_RET | BPF_A, 0)
679 		},
680 		CLASSIC,
681 		{ 10, 20, 30 },
682 		{ { 10, ETH_P_IP }, { 100, ETH_P_IP } },
683 	},
684 	{
685 		"LD_VLAN_TAG",
686 		.u.insns = {
687 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
688 				 SKF_AD_OFF + SKF_AD_VLAN_TAG),
689 			BPF_STMT(BPF_RET | BPF_A, 0)
690 		},
691 		CLASSIC,
692 		{ },
693 		{
694 			{ 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
695 			{ 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
696 		},
697 	},
698 	{
699 		"LD_VLAN_TAG_PRESENT",
700 		.u.insns = {
701 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
702 				 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
703 			BPF_STMT(BPF_RET | BPF_A, 0)
704 		},
705 		CLASSIC,
706 		{ },
707 		{
708 			{ 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
709 			{ 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
710 		},
711 	},
712 	{
713 		"LD_IFINDEX",
714 		.u.insns = {
715 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
716 				 SKF_AD_OFF + SKF_AD_IFINDEX),
717 			BPF_STMT(BPF_RET | BPF_A, 0)
718 		},
719 		CLASSIC,
720 		{ },
721 		{ { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
722 	},
723 	{
724 		"LD_HATYPE",
725 		.u.insns = {
726 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
727 				 SKF_AD_OFF + SKF_AD_HATYPE),
728 			BPF_STMT(BPF_RET | BPF_A, 0)
729 		},
730 		CLASSIC,
731 		{ },
732 		{ { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
733 	},
734 	{
735 		"LD_CPU",
736 		.u.insns = {
737 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
738 				 SKF_AD_OFF + SKF_AD_CPU),
739 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
740 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
741 				 SKF_AD_OFF + SKF_AD_CPU),
742 			BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
743 			BPF_STMT(BPF_RET | BPF_A, 0)
744 		},
745 		CLASSIC,
746 		{ },
747 		{ { 1, 0 }, { 10, 0 } },
748 	},
749 	{
750 		"LD_NLATTR",
751 		.u.insns = {
752 			BPF_STMT(BPF_LDX | BPF_IMM, 2),
753 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
754 			BPF_STMT(BPF_LDX | BPF_IMM, 3),
755 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
756 				 SKF_AD_OFF + SKF_AD_NLATTR),
757 			BPF_STMT(BPF_RET | BPF_A, 0)
758 		},
759 		CLASSIC,
760 #ifdef __BIG_ENDIAN
761 		{ 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
762 #else
763 		{ 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
764 #endif
765 		{ { 4, 0 }, { 20, 6 } },
766 	},
767 	{
768 		"LD_NLATTR_NEST",
769 		.u.insns = {
770 			BPF_STMT(BPF_LD | BPF_IMM, 2),
771 			BPF_STMT(BPF_LDX | BPF_IMM, 3),
772 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
773 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
774 			BPF_STMT(BPF_LD | BPF_IMM, 2),
775 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
776 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
777 			BPF_STMT(BPF_LD | BPF_IMM, 2),
778 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
779 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
780 			BPF_STMT(BPF_LD | BPF_IMM, 2),
781 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
782 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
783 			BPF_STMT(BPF_LD | BPF_IMM, 2),
784 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
785 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
786 			BPF_STMT(BPF_LD | BPF_IMM, 2),
787 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
788 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
789 			BPF_STMT(BPF_LD | BPF_IMM, 2),
790 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
791 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
792 			BPF_STMT(BPF_LD | BPF_IMM, 2),
793 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
794 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
795 			BPF_STMT(BPF_RET | BPF_A, 0)
796 		},
797 		CLASSIC,
798 #ifdef __BIG_ENDIAN
799 		{ 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
800 #else
801 		{ 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
802 #endif
803 		{ { 4, 0 }, { 20, 10 } },
804 	},
805 	{
806 		"LD_PAYLOAD_OFF",
807 		.u.insns = {
808 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
809 				 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
810 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
811 				 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
812 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
813 				 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
814 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
815 				 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
816 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
817 				 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
818 			BPF_STMT(BPF_RET | BPF_A, 0)
819 		},
820 		CLASSIC,
821 		/* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
822 		 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
823 		 * id 9737, seq 1, length 64
824 		 */
825 		{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 		  0x08, 0x00,
828 		  0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
829 		  0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
830 		{ { 30, 0 }, { 100, 42 } },
831 	},
832 	{
833 		"LD_ANC_XOR",
834 		.u.insns = {
835 			BPF_STMT(BPF_LD | BPF_IMM, 10),
836 			BPF_STMT(BPF_LDX | BPF_IMM, 300),
837 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 				 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
839 			BPF_STMT(BPF_RET | BPF_A, 0)
840 		},
841 		CLASSIC,
842 		{ },
843 		{ { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
844 	},
845 	{
846 		"SPILL_FILL",
847 		.u.insns = {
848 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
849 			BPF_STMT(BPF_LD | BPF_IMM, 2),
850 			BPF_STMT(BPF_ALU | BPF_RSH, 1),
851 			BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
852 			BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
853 			BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
854 			BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
855 			BPF_STMT(BPF_STX, 15), /* M3 = len */
856 			BPF_STMT(BPF_LDX | BPF_MEM, 1),
857 			BPF_STMT(BPF_LD | BPF_MEM, 2),
858 			BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
859 			BPF_STMT(BPF_LDX | BPF_MEM, 15),
860 			BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
861 			BPF_STMT(BPF_RET | BPF_A, 0)
862 		},
863 		CLASSIC,
864 		{ },
865 		{ { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
866 	},
867 	{
868 		"JEQ",
869 		.u.insns = {
870 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
871 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
872 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
873 			BPF_STMT(BPF_RET | BPF_K, 1),
874 			BPF_STMT(BPF_RET | BPF_K, MAX_K)
875 		},
876 		CLASSIC,
877 		{ 3, 3, 3, 3, 3 },
878 		{ { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
879 	},
880 	{
881 		"JGT",
882 		.u.insns = {
883 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
884 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
885 			BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
886 			BPF_STMT(BPF_RET | BPF_K, 1),
887 			BPF_STMT(BPF_RET | BPF_K, MAX_K)
888 		},
889 		CLASSIC,
890 		{ 4, 4, 4, 3, 3 },
891 		{ { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
892 	},
893 	{
894 		"JGE",
895 		.u.insns = {
896 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
897 			BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
898 			BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
899 			BPF_STMT(BPF_RET | BPF_K, 10),
900 			BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
901 			BPF_STMT(BPF_RET | BPF_K, 20),
902 			BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
903 			BPF_STMT(BPF_RET | BPF_K, 30),
904 			BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
905 			BPF_STMT(BPF_RET | BPF_K, 40),
906 			BPF_STMT(BPF_RET | BPF_K, MAX_K)
907 		},
908 		CLASSIC,
909 		{ 1, 2, 3, 4, 5 },
910 		{ { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
911 	},
912 	{
913 		"JSET",
914 		.u.insns = {
915 			BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
916 			BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
917 			BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
918 			BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
919 			BPF_STMT(BPF_LDX | BPF_LEN, 0),
920 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
921 			BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
922 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
923 			BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
924 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
925 			BPF_STMT(BPF_RET | BPF_K, 10),
926 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
927 			BPF_STMT(BPF_RET | BPF_K, 20),
928 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
929 			BPF_STMT(BPF_RET | BPF_K, 30),
930 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
931 			BPF_STMT(BPF_RET | BPF_K, 30),
932 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
933 			BPF_STMT(BPF_RET | BPF_K, 30),
934 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
935 			BPF_STMT(BPF_RET | BPF_K, 30),
936 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
937 			BPF_STMT(BPF_RET | BPF_K, 30),
938 			BPF_STMT(BPF_RET | BPF_K, MAX_K)
939 		},
940 		CLASSIC,
941 		{ 0, 0xAA, 0x55, 1 },
942 		{ { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
943 	},
944 	{
945 		"tcpdump port 22",
946 		.u.insns = {
947 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
948 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
949 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
950 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
951 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
952 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
953 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
954 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
955 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
956 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
957 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
958 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
959 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
960 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
961 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
962 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
963 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
964 			BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
965 			BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
966 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
967 			BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
968 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
969 			BPF_STMT(BPF_RET | BPF_K, 0xffff),
970 			BPF_STMT(BPF_RET | BPF_K, 0),
971 		},
972 		CLASSIC,
973 		/* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
974 		 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
975 		 * seq 1305692979:1305693027, ack 3650467037, win 65535,
976 		 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
977 		 */
978 		{ 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
979 		  0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
980 		  0x08, 0x00,
981 		  0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
982 		  0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
983 		  0x0a, 0x01, 0x01, 0x95, /* ip src */
984 		  0x0a, 0x01, 0x02, 0x0a, /* ip dst */
985 		  0xc2, 0x24,
986 		  0x00, 0x16 /* dst port */ },
987 		{ { 10, 0 }, { 30, 0 }, { 100, 65535 } },
988 	},
989 	{
990 		"tcpdump complex",
991 		.u.insns = {
992 			/* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
993 			 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
994 			 * (len > 115 or len < 30000000000)' -d
995 			 */
996 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
997 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
998 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
999 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1000 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1001 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1002 			BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1003 			BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1004 			BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1005 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1006 			BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1007 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1008 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1009 			BPF_STMT(BPF_ST, 1),
1010 			BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1011 			BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1012 			BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1013 			BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1014 			BPF_STMT(BPF_LD | BPF_MEM, 1),
1015 			BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1016 			BPF_STMT(BPF_ST, 5),
1017 			BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1018 			BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1019 			BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1020 			BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1021 			BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1022 			BPF_STMT(BPF_LD | BPF_MEM, 5),
1023 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1024 			BPF_STMT(BPF_LD | BPF_LEN, 0),
1025 			BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1026 			BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1027 			BPF_STMT(BPF_RET | BPF_K, 0xffff),
1028 			BPF_STMT(BPF_RET | BPF_K, 0),
1029 		},
1030 		CLASSIC,
1031 		{ 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1032 		  0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1033 		  0x08, 0x00,
1034 		  0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1035 		  0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1036 		  0x0a, 0x01, 0x01, 0x95, /* ip src */
1037 		  0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1038 		  0xc2, 0x24,
1039 		  0x00, 0x16 /* dst port */ },
1040 		{ { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1041 	},
1042 	{
1043 		"RET_A",
1044 		.u.insns = {
1045 			/* check that unitialized X and A contain zeros */
1046 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1047 			BPF_STMT(BPF_RET | BPF_A, 0)
1048 		},
1049 		CLASSIC,
1050 		{ },
1051 		{ {1, 0}, {2, 0} },
1052 	},
1053 	{
1054 		"INT: ADD trivial",
1055 		.u.insns_int = {
1056 			BPF_ALU64_IMM(BPF_MOV, R1, 1),
1057 			BPF_ALU64_IMM(BPF_ADD, R1, 2),
1058 			BPF_ALU64_IMM(BPF_MOV, R2, 3),
1059 			BPF_ALU64_REG(BPF_SUB, R1, R2),
1060 			BPF_ALU64_IMM(BPF_ADD, R1, -1),
1061 			BPF_ALU64_IMM(BPF_MUL, R1, 3),
1062 			BPF_ALU64_REG(BPF_MOV, R0, R1),
1063 			BPF_EXIT_INSN(),
1064 		},
1065 		INTERNAL,
1066 		{ },
1067 		{ { 0, 0xfffffffd } }
1068 	},
1069 	{
1070 		"INT: MUL_X",
1071 		.u.insns_int = {
1072 			BPF_ALU64_IMM(BPF_MOV, R0, -1),
1073 			BPF_ALU64_IMM(BPF_MOV, R1, -1),
1074 			BPF_ALU64_IMM(BPF_MOV, R2, 3),
1075 			BPF_ALU64_REG(BPF_MUL, R1, R2),
1076 			BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1077 			BPF_EXIT_INSN(),
1078 			BPF_ALU64_IMM(BPF_MOV, R0, 1),
1079 			BPF_EXIT_INSN(),
1080 		},
1081 		INTERNAL,
1082 		{ },
1083 		{ { 0, 1 } }
1084 	},
1085 	{
1086 		"INT: MUL_X2",
1087 		.u.insns_int = {
1088 			BPF_ALU32_IMM(BPF_MOV, R0, -1),
1089 			BPF_ALU32_IMM(BPF_MOV, R1, -1),
1090 			BPF_ALU32_IMM(BPF_MOV, R2, 3),
1091 			BPF_ALU64_REG(BPF_MUL, R1, R2),
1092 			BPF_ALU64_IMM(BPF_RSH, R1, 8),
1093 			BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1094 			BPF_EXIT_INSN(),
1095 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
1096 			BPF_EXIT_INSN(),
1097 		},
1098 		INTERNAL,
1099 		{ },
1100 		{ { 0, 1 } }
1101 	},
1102 	{
1103 		"INT: MUL32_X",
1104 		.u.insns_int = {
1105 			BPF_ALU32_IMM(BPF_MOV, R0, -1),
1106 			BPF_ALU64_IMM(BPF_MOV, R1, -1),
1107 			BPF_ALU32_IMM(BPF_MOV, R2, 3),
1108 			BPF_ALU32_REG(BPF_MUL, R1, R2),
1109 			BPF_ALU64_IMM(BPF_RSH, R1, 8),
1110 			BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1111 			BPF_EXIT_INSN(),
1112 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
1113 			BPF_EXIT_INSN(),
1114 		},
1115 		INTERNAL,
1116 		{ },
1117 		{ { 0, 1 } }
1118 	},
1119 	{
1120 		/* Have to test all register combinations, since
1121 		 * JITing of different registers will produce
1122 		 * different asm code.
1123 		 */
1124 		"INT: ADD 64-bit",
1125 		.u.insns_int = {
1126 			BPF_ALU64_IMM(BPF_MOV, R0, 0),
1127 			BPF_ALU64_IMM(BPF_MOV, R1, 1),
1128 			BPF_ALU64_IMM(BPF_MOV, R2, 2),
1129 			BPF_ALU64_IMM(BPF_MOV, R3, 3),
1130 			BPF_ALU64_IMM(BPF_MOV, R4, 4),
1131 			BPF_ALU64_IMM(BPF_MOV, R5, 5),
1132 			BPF_ALU64_IMM(BPF_MOV, R6, 6),
1133 			BPF_ALU64_IMM(BPF_MOV, R7, 7),
1134 			BPF_ALU64_IMM(BPF_MOV, R8, 8),
1135 			BPF_ALU64_IMM(BPF_MOV, R9, 9),
1136 			BPF_ALU64_IMM(BPF_ADD, R0, 20),
1137 			BPF_ALU64_IMM(BPF_ADD, R1, 20),
1138 			BPF_ALU64_IMM(BPF_ADD, R2, 20),
1139 			BPF_ALU64_IMM(BPF_ADD, R3, 20),
1140 			BPF_ALU64_IMM(BPF_ADD, R4, 20),
1141 			BPF_ALU64_IMM(BPF_ADD, R5, 20),
1142 			BPF_ALU64_IMM(BPF_ADD, R6, 20),
1143 			BPF_ALU64_IMM(BPF_ADD, R7, 20),
1144 			BPF_ALU64_IMM(BPF_ADD, R8, 20),
1145 			BPF_ALU64_IMM(BPF_ADD, R9, 20),
1146 			BPF_ALU64_IMM(BPF_SUB, R0, 10),
1147 			BPF_ALU64_IMM(BPF_SUB, R1, 10),
1148 			BPF_ALU64_IMM(BPF_SUB, R2, 10),
1149 			BPF_ALU64_IMM(BPF_SUB, R3, 10),
1150 			BPF_ALU64_IMM(BPF_SUB, R4, 10),
1151 			BPF_ALU64_IMM(BPF_SUB, R5, 10),
1152 			BPF_ALU64_IMM(BPF_SUB, R6, 10),
1153 			BPF_ALU64_IMM(BPF_SUB, R7, 10),
1154 			BPF_ALU64_IMM(BPF_SUB, R8, 10),
1155 			BPF_ALU64_IMM(BPF_SUB, R9, 10),
1156 			BPF_ALU64_REG(BPF_ADD, R0, R0),
1157 			BPF_ALU64_REG(BPF_ADD, R0, R1),
1158 			BPF_ALU64_REG(BPF_ADD, R0, R2),
1159 			BPF_ALU64_REG(BPF_ADD, R0, R3),
1160 			BPF_ALU64_REG(BPF_ADD, R0, R4),
1161 			BPF_ALU64_REG(BPF_ADD, R0, R5),
1162 			BPF_ALU64_REG(BPF_ADD, R0, R6),
1163 			BPF_ALU64_REG(BPF_ADD, R0, R7),
1164 			BPF_ALU64_REG(BPF_ADD, R0, R8),
1165 			BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1166 			BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1167 			BPF_EXIT_INSN(),
1168 			BPF_ALU64_REG(BPF_ADD, R1, R0),
1169 			BPF_ALU64_REG(BPF_ADD, R1, R1),
1170 			BPF_ALU64_REG(BPF_ADD, R1, R2),
1171 			BPF_ALU64_REG(BPF_ADD, R1, R3),
1172 			BPF_ALU64_REG(BPF_ADD, R1, R4),
1173 			BPF_ALU64_REG(BPF_ADD, R1, R5),
1174 			BPF_ALU64_REG(BPF_ADD, R1, R6),
1175 			BPF_ALU64_REG(BPF_ADD, R1, R7),
1176 			BPF_ALU64_REG(BPF_ADD, R1, R8),
1177 			BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1178 			BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1179 			BPF_EXIT_INSN(),
1180 			BPF_ALU64_REG(BPF_ADD, R2, R0),
1181 			BPF_ALU64_REG(BPF_ADD, R2, R1),
1182 			BPF_ALU64_REG(BPF_ADD, R2, R2),
1183 			BPF_ALU64_REG(BPF_ADD, R2, R3),
1184 			BPF_ALU64_REG(BPF_ADD, R2, R4),
1185 			BPF_ALU64_REG(BPF_ADD, R2, R5),
1186 			BPF_ALU64_REG(BPF_ADD, R2, R6),
1187 			BPF_ALU64_REG(BPF_ADD, R2, R7),
1188 			BPF_ALU64_REG(BPF_ADD, R2, R8),
1189 			BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1190 			BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1191 			BPF_EXIT_INSN(),
1192 			BPF_ALU64_REG(BPF_ADD, R3, R0),
1193 			BPF_ALU64_REG(BPF_ADD, R3, R1),
1194 			BPF_ALU64_REG(BPF_ADD, R3, R2),
1195 			BPF_ALU64_REG(BPF_ADD, R3, R3),
1196 			BPF_ALU64_REG(BPF_ADD, R3, R4),
1197 			BPF_ALU64_REG(BPF_ADD, R3, R5),
1198 			BPF_ALU64_REG(BPF_ADD, R3, R6),
1199 			BPF_ALU64_REG(BPF_ADD, R3, R7),
1200 			BPF_ALU64_REG(BPF_ADD, R3, R8),
1201 			BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1202 			BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1203 			BPF_EXIT_INSN(),
1204 			BPF_ALU64_REG(BPF_ADD, R4, R0),
1205 			BPF_ALU64_REG(BPF_ADD, R4, R1),
1206 			BPF_ALU64_REG(BPF_ADD, R4, R2),
1207 			BPF_ALU64_REG(BPF_ADD, R4, R3),
1208 			BPF_ALU64_REG(BPF_ADD, R4, R4),
1209 			BPF_ALU64_REG(BPF_ADD, R4, R5),
1210 			BPF_ALU64_REG(BPF_ADD, R4, R6),
1211 			BPF_ALU64_REG(BPF_ADD, R4, R7),
1212 			BPF_ALU64_REG(BPF_ADD, R4, R8),
1213 			BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1214 			BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1215 			BPF_EXIT_INSN(),
1216 			BPF_ALU64_REG(BPF_ADD, R5, R0),
1217 			BPF_ALU64_REG(BPF_ADD, R5, R1),
1218 			BPF_ALU64_REG(BPF_ADD, R5, R2),
1219 			BPF_ALU64_REG(BPF_ADD, R5, R3),
1220 			BPF_ALU64_REG(BPF_ADD, R5, R4),
1221 			BPF_ALU64_REG(BPF_ADD, R5, R5),
1222 			BPF_ALU64_REG(BPF_ADD, R5, R6),
1223 			BPF_ALU64_REG(BPF_ADD, R5, R7),
1224 			BPF_ALU64_REG(BPF_ADD, R5, R8),
1225 			BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1226 			BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1227 			BPF_EXIT_INSN(),
1228 			BPF_ALU64_REG(BPF_ADD, R6, R0),
1229 			BPF_ALU64_REG(BPF_ADD, R6, R1),
1230 			BPF_ALU64_REG(BPF_ADD, R6, R2),
1231 			BPF_ALU64_REG(BPF_ADD, R6, R3),
1232 			BPF_ALU64_REG(BPF_ADD, R6, R4),
1233 			BPF_ALU64_REG(BPF_ADD, R6, R5),
1234 			BPF_ALU64_REG(BPF_ADD, R6, R6),
1235 			BPF_ALU64_REG(BPF_ADD, R6, R7),
1236 			BPF_ALU64_REG(BPF_ADD, R6, R8),
1237 			BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1238 			BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1239 			BPF_EXIT_INSN(),
1240 			BPF_ALU64_REG(BPF_ADD, R7, R0),
1241 			BPF_ALU64_REG(BPF_ADD, R7, R1),
1242 			BPF_ALU64_REG(BPF_ADD, R7, R2),
1243 			BPF_ALU64_REG(BPF_ADD, R7, R3),
1244 			BPF_ALU64_REG(BPF_ADD, R7, R4),
1245 			BPF_ALU64_REG(BPF_ADD, R7, R5),
1246 			BPF_ALU64_REG(BPF_ADD, R7, R6),
1247 			BPF_ALU64_REG(BPF_ADD, R7, R7),
1248 			BPF_ALU64_REG(BPF_ADD, R7, R8),
1249 			BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1250 			BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1251 			BPF_EXIT_INSN(),
1252 			BPF_ALU64_REG(BPF_ADD, R8, R0),
1253 			BPF_ALU64_REG(BPF_ADD, R8, R1),
1254 			BPF_ALU64_REG(BPF_ADD, R8, R2),
1255 			BPF_ALU64_REG(BPF_ADD, R8, R3),
1256 			BPF_ALU64_REG(BPF_ADD, R8, R4),
1257 			BPF_ALU64_REG(BPF_ADD, R8, R5),
1258 			BPF_ALU64_REG(BPF_ADD, R8, R6),
1259 			BPF_ALU64_REG(BPF_ADD, R8, R7),
1260 			BPF_ALU64_REG(BPF_ADD, R8, R8),
1261 			BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1262 			BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1263 			BPF_EXIT_INSN(),
1264 			BPF_ALU64_REG(BPF_ADD, R9, R0),
1265 			BPF_ALU64_REG(BPF_ADD, R9, R1),
1266 			BPF_ALU64_REG(BPF_ADD, R9, R2),
1267 			BPF_ALU64_REG(BPF_ADD, R9, R3),
1268 			BPF_ALU64_REG(BPF_ADD, R9, R4),
1269 			BPF_ALU64_REG(BPF_ADD, R9, R5),
1270 			BPF_ALU64_REG(BPF_ADD, R9, R6),
1271 			BPF_ALU64_REG(BPF_ADD, R9, R7),
1272 			BPF_ALU64_REG(BPF_ADD, R9, R8),
1273 			BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1274 			BPF_ALU64_REG(BPF_MOV, R0, R9),
1275 			BPF_EXIT_INSN(),
1276 		},
1277 		INTERNAL,
1278 		{ },
1279 		{ { 0, 2957380 } }
1280 	},
1281 	{
1282 		"INT: ADD 32-bit",
1283 		.u.insns_int = {
1284 			BPF_ALU32_IMM(BPF_MOV, R0, 20),
1285 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
1286 			BPF_ALU32_IMM(BPF_MOV, R2, 2),
1287 			BPF_ALU32_IMM(BPF_MOV, R3, 3),
1288 			BPF_ALU32_IMM(BPF_MOV, R4, 4),
1289 			BPF_ALU32_IMM(BPF_MOV, R5, 5),
1290 			BPF_ALU32_IMM(BPF_MOV, R6, 6),
1291 			BPF_ALU32_IMM(BPF_MOV, R7, 7),
1292 			BPF_ALU32_IMM(BPF_MOV, R8, 8),
1293 			BPF_ALU32_IMM(BPF_MOV, R9, 9),
1294 			BPF_ALU64_IMM(BPF_ADD, R1, 10),
1295 			BPF_ALU64_IMM(BPF_ADD, R2, 10),
1296 			BPF_ALU64_IMM(BPF_ADD, R3, 10),
1297 			BPF_ALU64_IMM(BPF_ADD, R4, 10),
1298 			BPF_ALU64_IMM(BPF_ADD, R5, 10),
1299 			BPF_ALU64_IMM(BPF_ADD, R6, 10),
1300 			BPF_ALU64_IMM(BPF_ADD, R7, 10),
1301 			BPF_ALU64_IMM(BPF_ADD, R8, 10),
1302 			BPF_ALU64_IMM(BPF_ADD, R9, 10),
1303 			BPF_ALU32_REG(BPF_ADD, R0, R1),
1304 			BPF_ALU32_REG(BPF_ADD, R0, R2),
1305 			BPF_ALU32_REG(BPF_ADD, R0, R3),
1306 			BPF_ALU32_REG(BPF_ADD, R0, R4),
1307 			BPF_ALU32_REG(BPF_ADD, R0, R5),
1308 			BPF_ALU32_REG(BPF_ADD, R0, R6),
1309 			BPF_ALU32_REG(BPF_ADD, R0, R7),
1310 			BPF_ALU32_REG(BPF_ADD, R0, R8),
1311 			BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1312 			BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1313 			BPF_EXIT_INSN(),
1314 			BPF_ALU32_REG(BPF_ADD, R1, R0),
1315 			BPF_ALU32_REG(BPF_ADD, R1, R1),
1316 			BPF_ALU32_REG(BPF_ADD, R1, R2),
1317 			BPF_ALU32_REG(BPF_ADD, R1, R3),
1318 			BPF_ALU32_REG(BPF_ADD, R1, R4),
1319 			BPF_ALU32_REG(BPF_ADD, R1, R5),
1320 			BPF_ALU32_REG(BPF_ADD, R1, R6),
1321 			BPF_ALU32_REG(BPF_ADD, R1, R7),
1322 			BPF_ALU32_REG(BPF_ADD, R1, R8),
1323 			BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1324 			BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1325 			BPF_EXIT_INSN(),
1326 			BPF_ALU32_REG(BPF_ADD, R2, R0),
1327 			BPF_ALU32_REG(BPF_ADD, R2, R1),
1328 			BPF_ALU32_REG(BPF_ADD, R2, R2),
1329 			BPF_ALU32_REG(BPF_ADD, R2, R3),
1330 			BPF_ALU32_REG(BPF_ADD, R2, R4),
1331 			BPF_ALU32_REG(BPF_ADD, R2, R5),
1332 			BPF_ALU32_REG(BPF_ADD, R2, R6),
1333 			BPF_ALU32_REG(BPF_ADD, R2, R7),
1334 			BPF_ALU32_REG(BPF_ADD, R2, R8),
1335 			BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1336 			BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1337 			BPF_EXIT_INSN(),
1338 			BPF_ALU32_REG(BPF_ADD, R3, R0),
1339 			BPF_ALU32_REG(BPF_ADD, R3, R1),
1340 			BPF_ALU32_REG(BPF_ADD, R3, R2),
1341 			BPF_ALU32_REG(BPF_ADD, R3, R3),
1342 			BPF_ALU32_REG(BPF_ADD, R3, R4),
1343 			BPF_ALU32_REG(BPF_ADD, R3, R5),
1344 			BPF_ALU32_REG(BPF_ADD, R3, R6),
1345 			BPF_ALU32_REG(BPF_ADD, R3, R7),
1346 			BPF_ALU32_REG(BPF_ADD, R3, R8),
1347 			BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1348 			BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1349 			BPF_EXIT_INSN(),
1350 			BPF_ALU32_REG(BPF_ADD, R4, R0),
1351 			BPF_ALU32_REG(BPF_ADD, R4, R1),
1352 			BPF_ALU32_REG(BPF_ADD, R4, R2),
1353 			BPF_ALU32_REG(BPF_ADD, R4, R3),
1354 			BPF_ALU32_REG(BPF_ADD, R4, R4),
1355 			BPF_ALU32_REG(BPF_ADD, R4, R5),
1356 			BPF_ALU32_REG(BPF_ADD, R4, R6),
1357 			BPF_ALU32_REG(BPF_ADD, R4, R7),
1358 			BPF_ALU32_REG(BPF_ADD, R4, R8),
1359 			BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1360 			BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1361 			BPF_EXIT_INSN(),
1362 			BPF_ALU32_REG(BPF_ADD, R5, R0),
1363 			BPF_ALU32_REG(BPF_ADD, R5, R1),
1364 			BPF_ALU32_REG(BPF_ADD, R5, R2),
1365 			BPF_ALU32_REG(BPF_ADD, R5, R3),
1366 			BPF_ALU32_REG(BPF_ADD, R5, R4),
1367 			BPF_ALU32_REG(BPF_ADD, R5, R5),
1368 			BPF_ALU32_REG(BPF_ADD, R5, R6),
1369 			BPF_ALU32_REG(BPF_ADD, R5, R7),
1370 			BPF_ALU32_REG(BPF_ADD, R5, R8),
1371 			BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1372 			BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1373 			BPF_EXIT_INSN(),
1374 			BPF_ALU32_REG(BPF_ADD, R6, R0),
1375 			BPF_ALU32_REG(BPF_ADD, R6, R1),
1376 			BPF_ALU32_REG(BPF_ADD, R6, R2),
1377 			BPF_ALU32_REG(BPF_ADD, R6, R3),
1378 			BPF_ALU32_REG(BPF_ADD, R6, R4),
1379 			BPF_ALU32_REG(BPF_ADD, R6, R5),
1380 			BPF_ALU32_REG(BPF_ADD, R6, R6),
1381 			BPF_ALU32_REG(BPF_ADD, R6, R7),
1382 			BPF_ALU32_REG(BPF_ADD, R6, R8),
1383 			BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1384 			BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1385 			BPF_EXIT_INSN(),
1386 			BPF_ALU32_REG(BPF_ADD, R7, R0),
1387 			BPF_ALU32_REG(BPF_ADD, R7, R1),
1388 			BPF_ALU32_REG(BPF_ADD, R7, R2),
1389 			BPF_ALU32_REG(BPF_ADD, R7, R3),
1390 			BPF_ALU32_REG(BPF_ADD, R7, R4),
1391 			BPF_ALU32_REG(BPF_ADD, R7, R5),
1392 			BPF_ALU32_REG(BPF_ADD, R7, R6),
1393 			BPF_ALU32_REG(BPF_ADD, R7, R7),
1394 			BPF_ALU32_REG(BPF_ADD, R7, R8),
1395 			BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1396 			BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1397 			BPF_EXIT_INSN(),
1398 			BPF_ALU32_REG(BPF_ADD, R8, R0),
1399 			BPF_ALU32_REG(BPF_ADD, R8, R1),
1400 			BPF_ALU32_REG(BPF_ADD, R8, R2),
1401 			BPF_ALU32_REG(BPF_ADD, R8, R3),
1402 			BPF_ALU32_REG(BPF_ADD, R8, R4),
1403 			BPF_ALU32_REG(BPF_ADD, R8, R5),
1404 			BPF_ALU32_REG(BPF_ADD, R8, R6),
1405 			BPF_ALU32_REG(BPF_ADD, R8, R7),
1406 			BPF_ALU32_REG(BPF_ADD, R8, R8),
1407 			BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1408 			BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1409 			BPF_EXIT_INSN(),
1410 			BPF_ALU32_REG(BPF_ADD, R9, R0),
1411 			BPF_ALU32_REG(BPF_ADD, R9, R1),
1412 			BPF_ALU32_REG(BPF_ADD, R9, R2),
1413 			BPF_ALU32_REG(BPF_ADD, R9, R3),
1414 			BPF_ALU32_REG(BPF_ADD, R9, R4),
1415 			BPF_ALU32_REG(BPF_ADD, R9, R5),
1416 			BPF_ALU32_REG(BPF_ADD, R9, R6),
1417 			BPF_ALU32_REG(BPF_ADD, R9, R7),
1418 			BPF_ALU32_REG(BPF_ADD, R9, R8),
1419 			BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1420 			BPF_ALU32_REG(BPF_MOV, R0, R9),
1421 			BPF_EXIT_INSN(),
1422 		},
1423 		INTERNAL,
1424 		{ },
1425 		{ { 0, 2957380 } }
1426 	},
1427 	{	/* Mainly checking JIT here. */
1428 		"INT: SUB",
1429 		.u.insns_int = {
1430 			BPF_ALU64_IMM(BPF_MOV, R0, 0),
1431 			BPF_ALU64_IMM(BPF_MOV, R1, 1),
1432 			BPF_ALU64_IMM(BPF_MOV, R2, 2),
1433 			BPF_ALU64_IMM(BPF_MOV, R3, 3),
1434 			BPF_ALU64_IMM(BPF_MOV, R4, 4),
1435 			BPF_ALU64_IMM(BPF_MOV, R5, 5),
1436 			BPF_ALU64_IMM(BPF_MOV, R6, 6),
1437 			BPF_ALU64_IMM(BPF_MOV, R7, 7),
1438 			BPF_ALU64_IMM(BPF_MOV, R8, 8),
1439 			BPF_ALU64_IMM(BPF_MOV, R9, 9),
1440 			BPF_ALU64_REG(BPF_SUB, R0, R0),
1441 			BPF_ALU64_REG(BPF_SUB, R0, R1),
1442 			BPF_ALU64_REG(BPF_SUB, R0, R2),
1443 			BPF_ALU64_REG(BPF_SUB, R0, R3),
1444 			BPF_ALU64_REG(BPF_SUB, R0, R4),
1445 			BPF_ALU64_REG(BPF_SUB, R0, R5),
1446 			BPF_ALU64_REG(BPF_SUB, R0, R6),
1447 			BPF_ALU64_REG(BPF_SUB, R0, R7),
1448 			BPF_ALU64_REG(BPF_SUB, R0, R8),
1449 			BPF_ALU64_REG(BPF_SUB, R0, R9),
1450 			BPF_ALU64_IMM(BPF_SUB, R0, 10),
1451 			BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1452 			BPF_EXIT_INSN(),
1453 			BPF_ALU64_REG(BPF_SUB, R1, R0),
1454 			BPF_ALU64_REG(BPF_SUB, R1, R2),
1455 			BPF_ALU64_REG(BPF_SUB, R1, R3),
1456 			BPF_ALU64_REG(BPF_SUB, R1, R4),
1457 			BPF_ALU64_REG(BPF_SUB, R1, R5),
1458 			BPF_ALU64_REG(BPF_SUB, R1, R6),
1459 			BPF_ALU64_REG(BPF_SUB, R1, R7),
1460 			BPF_ALU64_REG(BPF_SUB, R1, R8),
1461 			BPF_ALU64_REG(BPF_SUB, R1, R9),
1462 			BPF_ALU64_IMM(BPF_SUB, R1, 10),
1463 			BPF_ALU64_REG(BPF_SUB, R2, R0),
1464 			BPF_ALU64_REG(BPF_SUB, R2, R1),
1465 			BPF_ALU64_REG(BPF_SUB, R2, R3),
1466 			BPF_ALU64_REG(BPF_SUB, R2, R4),
1467 			BPF_ALU64_REG(BPF_SUB, R2, R5),
1468 			BPF_ALU64_REG(BPF_SUB, R2, R6),
1469 			BPF_ALU64_REG(BPF_SUB, R2, R7),
1470 			BPF_ALU64_REG(BPF_SUB, R2, R8),
1471 			BPF_ALU64_REG(BPF_SUB, R2, R9),
1472 			BPF_ALU64_IMM(BPF_SUB, R2, 10),
1473 			BPF_ALU64_REG(BPF_SUB, R3, R0),
1474 			BPF_ALU64_REG(BPF_SUB, R3, R1),
1475 			BPF_ALU64_REG(BPF_SUB, R3, R2),
1476 			BPF_ALU64_REG(BPF_SUB, R3, R4),
1477 			BPF_ALU64_REG(BPF_SUB, R3, R5),
1478 			BPF_ALU64_REG(BPF_SUB, R3, R6),
1479 			BPF_ALU64_REG(BPF_SUB, R3, R7),
1480 			BPF_ALU64_REG(BPF_SUB, R3, R8),
1481 			BPF_ALU64_REG(BPF_SUB, R3, R9),
1482 			BPF_ALU64_IMM(BPF_SUB, R3, 10),
1483 			BPF_ALU64_REG(BPF_SUB, R4, R0),
1484 			BPF_ALU64_REG(BPF_SUB, R4, R1),
1485 			BPF_ALU64_REG(BPF_SUB, R4, R2),
1486 			BPF_ALU64_REG(BPF_SUB, R4, R3),
1487 			BPF_ALU64_REG(BPF_SUB, R4, R5),
1488 			BPF_ALU64_REG(BPF_SUB, R4, R6),
1489 			BPF_ALU64_REG(BPF_SUB, R4, R7),
1490 			BPF_ALU64_REG(BPF_SUB, R4, R8),
1491 			BPF_ALU64_REG(BPF_SUB, R4, R9),
1492 			BPF_ALU64_IMM(BPF_SUB, R4, 10),
1493 			BPF_ALU64_REG(BPF_SUB, R5, R0),
1494 			BPF_ALU64_REG(BPF_SUB, R5, R1),
1495 			BPF_ALU64_REG(BPF_SUB, R5, R2),
1496 			BPF_ALU64_REG(BPF_SUB, R5, R3),
1497 			BPF_ALU64_REG(BPF_SUB, R5, R4),
1498 			BPF_ALU64_REG(BPF_SUB, R5, R6),
1499 			BPF_ALU64_REG(BPF_SUB, R5, R7),
1500 			BPF_ALU64_REG(BPF_SUB, R5, R8),
1501 			BPF_ALU64_REG(BPF_SUB, R5, R9),
1502 			BPF_ALU64_IMM(BPF_SUB, R5, 10),
1503 			BPF_ALU64_REG(BPF_SUB, R6, R0),
1504 			BPF_ALU64_REG(BPF_SUB, R6, R1),
1505 			BPF_ALU64_REG(BPF_SUB, R6, R2),
1506 			BPF_ALU64_REG(BPF_SUB, R6, R3),
1507 			BPF_ALU64_REG(BPF_SUB, R6, R4),
1508 			BPF_ALU64_REG(BPF_SUB, R6, R5),
1509 			BPF_ALU64_REG(BPF_SUB, R6, R7),
1510 			BPF_ALU64_REG(BPF_SUB, R6, R8),
1511 			BPF_ALU64_REG(BPF_SUB, R6, R9),
1512 			BPF_ALU64_IMM(BPF_SUB, R6, 10),
1513 			BPF_ALU64_REG(BPF_SUB, R7, R0),
1514 			BPF_ALU64_REG(BPF_SUB, R7, R1),
1515 			BPF_ALU64_REG(BPF_SUB, R7, R2),
1516 			BPF_ALU64_REG(BPF_SUB, R7, R3),
1517 			BPF_ALU64_REG(BPF_SUB, R7, R4),
1518 			BPF_ALU64_REG(BPF_SUB, R7, R5),
1519 			BPF_ALU64_REG(BPF_SUB, R7, R6),
1520 			BPF_ALU64_REG(BPF_SUB, R7, R8),
1521 			BPF_ALU64_REG(BPF_SUB, R7, R9),
1522 			BPF_ALU64_IMM(BPF_SUB, R7, 10),
1523 			BPF_ALU64_REG(BPF_SUB, R8, R0),
1524 			BPF_ALU64_REG(BPF_SUB, R8, R1),
1525 			BPF_ALU64_REG(BPF_SUB, R8, R2),
1526 			BPF_ALU64_REG(BPF_SUB, R8, R3),
1527 			BPF_ALU64_REG(BPF_SUB, R8, R4),
1528 			BPF_ALU64_REG(BPF_SUB, R8, R5),
1529 			BPF_ALU64_REG(BPF_SUB, R8, R6),
1530 			BPF_ALU64_REG(BPF_SUB, R8, R7),
1531 			BPF_ALU64_REG(BPF_SUB, R8, R9),
1532 			BPF_ALU64_IMM(BPF_SUB, R8, 10),
1533 			BPF_ALU64_REG(BPF_SUB, R9, R0),
1534 			BPF_ALU64_REG(BPF_SUB, R9, R1),
1535 			BPF_ALU64_REG(BPF_SUB, R9, R2),
1536 			BPF_ALU64_REG(BPF_SUB, R9, R3),
1537 			BPF_ALU64_REG(BPF_SUB, R9, R4),
1538 			BPF_ALU64_REG(BPF_SUB, R9, R5),
1539 			BPF_ALU64_REG(BPF_SUB, R9, R6),
1540 			BPF_ALU64_REG(BPF_SUB, R9, R7),
1541 			BPF_ALU64_REG(BPF_SUB, R9, R8),
1542 			BPF_ALU64_IMM(BPF_SUB, R9, 10),
1543 			BPF_ALU64_IMM(BPF_SUB, R0, 10),
1544 			BPF_ALU64_IMM(BPF_NEG, R0, 0),
1545 			BPF_ALU64_REG(BPF_SUB, R0, R1),
1546 			BPF_ALU64_REG(BPF_SUB, R0, R2),
1547 			BPF_ALU64_REG(BPF_SUB, R0, R3),
1548 			BPF_ALU64_REG(BPF_SUB, R0, R4),
1549 			BPF_ALU64_REG(BPF_SUB, R0, R5),
1550 			BPF_ALU64_REG(BPF_SUB, R0, R6),
1551 			BPF_ALU64_REG(BPF_SUB, R0, R7),
1552 			BPF_ALU64_REG(BPF_SUB, R0, R8),
1553 			BPF_ALU64_REG(BPF_SUB, R0, R9),
1554 			BPF_EXIT_INSN(),
1555 		},
1556 		INTERNAL,
1557 		{ },
1558 		{ { 0, 11 } }
1559 	},
1560 	{	/* Mainly checking JIT here. */
1561 		"INT: XOR",
1562 		.u.insns_int = {
1563 			BPF_ALU64_REG(BPF_SUB, R0, R0),
1564 			BPF_ALU64_REG(BPF_XOR, R1, R1),
1565 			BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1566 			BPF_EXIT_INSN(),
1567 			BPF_ALU64_IMM(BPF_MOV, R0, 10),
1568 			BPF_ALU64_IMM(BPF_MOV, R1, -1),
1569 			BPF_ALU64_REG(BPF_SUB, R1, R1),
1570 			BPF_ALU64_REG(BPF_XOR, R2, R2),
1571 			BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1572 			BPF_EXIT_INSN(),
1573 			BPF_ALU64_REG(BPF_SUB, R2, R2),
1574 			BPF_ALU64_REG(BPF_XOR, R3, R3),
1575 			BPF_ALU64_IMM(BPF_MOV, R0, 10),
1576 			BPF_ALU64_IMM(BPF_MOV, R1, -1),
1577 			BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1578 			BPF_EXIT_INSN(),
1579 			BPF_ALU64_REG(BPF_SUB, R3, R3),
1580 			BPF_ALU64_REG(BPF_XOR, R4, R4),
1581 			BPF_ALU64_IMM(BPF_MOV, R2, 1),
1582 			BPF_ALU64_IMM(BPF_MOV, R5, -1),
1583 			BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1584 			BPF_EXIT_INSN(),
1585 			BPF_ALU64_REG(BPF_SUB, R4, R4),
1586 			BPF_ALU64_REG(BPF_XOR, R5, R5),
1587 			BPF_ALU64_IMM(BPF_MOV, R3, 1),
1588 			BPF_ALU64_IMM(BPF_MOV, R7, -1),
1589 			BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1590 			BPF_EXIT_INSN(),
1591 			BPF_ALU64_IMM(BPF_MOV, R5, 1),
1592 			BPF_ALU64_REG(BPF_SUB, R5, R5),
1593 			BPF_ALU64_REG(BPF_XOR, R6, R6),
1594 			BPF_ALU64_IMM(BPF_MOV, R1, 1),
1595 			BPF_ALU64_IMM(BPF_MOV, R8, -1),
1596 			BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1597 			BPF_EXIT_INSN(),
1598 			BPF_ALU64_REG(BPF_SUB, R6, R6),
1599 			BPF_ALU64_REG(BPF_XOR, R7, R7),
1600 			BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1601 			BPF_EXIT_INSN(),
1602 			BPF_ALU64_REG(BPF_SUB, R7, R7),
1603 			BPF_ALU64_REG(BPF_XOR, R8, R8),
1604 			BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1605 			BPF_EXIT_INSN(),
1606 			BPF_ALU64_REG(BPF_SUB, R8, R8),
1607 			BPF_ALU64_REG(BPF_XOR, R9, R9),
1608 			BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1609 			BPF_EXIT_INSN(),
1610 			BPF_ALU64_REG(BPF_SUB, R9, R9),
1611 			BPF_ALU64_REG(BPF_XOR, R0, R0),
1612 			BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1613 			BPF_EXIT_INSN(),
1614 			BPF_ALU64_REG(BPF_SUB, R1, R1),
1615 			BPF_ALU64_REG(BPF_XOR, R0, R0),
1616 			BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1617 			BPF_ALU64_IMM(BPF_MOV, R0, 0),
1618 			BPF_EXIT_INSN(),
1619 			BPF_ALU64_IMM(BPF_MOV, R0, 1),
1620 			BPF_EXIT_INSN(),
1621 		},
1622 		INTERNAL,
1623 		{ },
1624 		{ { 0, 1 } }
1625 	},
1626 	{	/* Mainly checking JIT here. */
1627 		"INT: MUL",
1628 		.u.insns_int = {
1629 			BPF_ALU64_IMM(BPF_MOV, R0, 11),
1630 			BPF_ALU64_IMM(BPF_MOV, R1, 1),
1631 			BPF_ALU64_IMM(BPF_MOV, R2, 2),
1632 			BPF_ALU64_IMM(BPF_MOV, R3, 3),
1633 			BPF_ALU64_IMM(BPF_MOV, R4, 4),
1634 			BPF_ALU64_IMM(BPF_MOV, R5, 5),
1635 			BPF_ALU64_IMM(BPF_MOV, R6, 6),
1636 			BPF_ALU64_IMM(BPF_MOV, R7, 7),
1637 			BPF_ALU64_IMM(BPF_MOV, R8, 8),
1638 			BPF_ALU64_IMM(BPF_MOV, R9, 9),
1639 			BPF_ALU64_REG(BPF_MUL, R0, R0),
1640 			BPF_ALU64_REG(BPF_MUL, R0, R1),
1641 			BPF_ALU64_REG(BPF_MUL, R0, R2),
1642 			BPF_ALU64_REG(BPF_MUL, R0, R3),
1643 			BPF_ALU64_REG(BPF_MUL, R0, R4),
1644 			BPF_ALU64_REG(BPF_MUL, R0, R5),
1645 			BPF_ALU64_REG(BPF_MUL, R0, R6),
1646 			BPF_ALU64_REG(BPF_MUL, R0, R7),
1647 			BPF_ALU64_REG(BPF_MUL, R0, R8),
1648 			BPF_ALU64_REG(BPF_MUL, R0, R9),
1649 			BPF_ALU64_IMM(BPF_MUL, R0, 10),
1650 			BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1651 			BPF_EXIT_INSN(),
1652 			BPF_ALU64_REG(BPF_MUL, R1, R0),
1653 			BPF_ALU64_REG(BPF_MUL, R1, R2),
1654 			BPF_ALU64_REG(BPF_MUL, R1, R3),
1655 			BPF_ALU64_REG(BPF_MUL, R1, R4),
1656 			BPF_ALU64_REG(BPF_MUL, R1, R5),
1657 			BPF_ALU64_REG(BPF_MUL, R1, R6),
1658 			BPF_ALU64_REG(BPF_MUL, R1, R7),
1659 			BPF_ALU64_REG(BPF_MUL, R1, R8),
1660 			BPF_ALU64_REG(BPF_MUL, R1, R9),
1661 			BPF_ALU64_IMM(BPF_MUL, R1, 10),
1662 			BPF_ALU64_REG(BPF_MOV, R2, R1),
1663 			BPF_ALU64_IMM(BPF_RSH, R2, 32),
1664 			BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1665 			BPF_EXIT_INSN(),
1666 			BPF_ALU64_IMM(BPF_LSH, R1, 32),
1667 			BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1668 			BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1669 			BPF_EXIT_INSN(),
1670 			BPF_ALU64_REG(BPF_MUL, R2, R0),
1671 			BPF_ALU64_REG(BPF_MUL, R2, R1),
1672 			BPF_ALU64_REG(BPF_MUL, R2, R3),
1673 			BPF_ALU64_REG(BPF_MUL, R2, R4),
1674 			BPF_ALU64_REG(BPF_MUL, R2, R5),
1675 			BPF_ALU64_REG(BPF_MUL, R2, R6),
1676 			BPF_ALU64_REG(BPF_MUL, R2, R7),
1677 			BPF_ALU64_REG(BPF_MUL, R2, R8),
1678 			BPF_ALU64_REG(BPF_MUL, R2, R9),
1679 			BPF_ALU64_IMM(BPF_MUL, R2, 10),
1680 			BPF_ALU64_IMM(BPF_RSH, R2, 32),
1681 			BPF_ALU64_REG(BPF_MOV, R0, R2),
1682 			BPF_EXIT_INSN(),
1683 		},
1684 		INTERNAL,
1685 		{ },
1686 		{ { 0, 0x35d97ef2 } }
1687 	},
1688 	{
1689 		"INT: ALU MIX",
1690 		.u.insns_int = {
1691 			BPF_ALU64_IMM(BPF_MOV, R0, 11),
1692 			BPF_ALU64_IMM(BPF_ADD, R0, -1),
1693 			BPF_ALU64_IMM(BPF_MOV, R2, 2),
1694 			BPF_ALU64_IMM(BPF_XOR, R2, 3),
1695 			BPF_ALU64_REG(BPF_DIV, R0, R2),
1696 			BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1697 			BPF_EXIT_INSN(),
1698 			BPF_ALU64_IMM(BPF_MOD, R0, 3),
1699 			BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1700 			BPF_EXIT_INSN(),
1701 			BPF_ALU64_IMM(BPF_MOV, R0, -1),
1702 			BPF_EXIT_INSN(),
1703 		},
1704 		INTERNAL,
1705 		{ },
1706 		{ { 0, -1 } }
1707 	},
1708 	{
1709 		"INT: shifts by register",
1710 		.u.insns_int = {
1711 			BPF_MOV64_IMM(R0, -1234),
1712 			BPF_MOV64_IMM(R1, 1),
1713 			BPF_ALU32_REG(BPF_RSH, R0, R1),
1714 			BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1715 			BPF_EXIT_INSN(),
1716 			BPF_MOV64_IMM(R2, 1),
1717 			BPF_ALU64_REG(BPF_LSH, R0, R2),
1718 			BPF_MOV32_IMM(R4, -1234),
1719 			BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1720 			BPF_EXIT_INSN(),
1721 			BPF_ALU64_IMM(BPF_AND, R4, 63),
1722 			BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1723 			BPF_MOV64_IMM(R3, 47),
1724 			BPF_ALU64_REG(BPF_ARSH, R0, R3),
1725 			BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1726 			BPF_EXIT_INSN(),
1727 			BPF_MOV64_IMM(R2, 1),
1728 			BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1729 			BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1730 			BPF_EXIT_INSN(),
1731 			BPF_MOV64_IMM(R4, 4),
1732 			BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1733 			BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1734 			BPF_EXIT_INSN(),
1735 			BPF_MOV64_IMM(R4, 5),
1736 			BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1737 			BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1738 			BPF_EXIT_INSN(),
1739 			BPF_MOV64_IMM(R0, -1),
1740 			BPF_EXIT_INSN(),
1741 		},
1742 		INTERNAL,
1743 		{ },
1744 		{ { 0, -1 } }
1745 	},
1746 	{
1747 		"INT: DIV + ABS",
1748 		.u.insns_int = {
1749 			BPF_ALU64_REG(BPF_MOV, R6, R1),
1750 			BPF_LD_ABS(BPF_B, 3),
1751 			BPF_ALU64_IMM(BPF_MOV, R2, 2),
1752 			BPF_ALU32_REG(BPF_DIV, R0, R2),
1753 			BPF_ALU64_REG(BPF_MOV, R8, R0),
1754 			BPF_LD_ABS(BPF_B, 4),
1755 			BPF_ALU64_REG(BPF_ADD, R8, R0),
1756 			BPF_LD_IND(BPF_B, R8, -70),
1757 			BPF_EXIT_INSN(),
1758 		},
1759 		INTERNAL,
1760 		{ 10, 20, 30, 40, 50 },
1761 		{ { 4, 0 }, { 5, 10 } }
1762 	},
1763 	{
1764 		"INT: DIV by zero",
1765 		.u.insns_int = {
1766 			BPF_ALU64_REG(BPF_MOV, R6, R1),
1767 			BPF_ALU64_IMM(BPF_MOV, R7, 0),
1768 			BPF_LD_ABS(BPF_B, 3),
1769 			BPF_ALU32_REG(BPF_DIV, R0, R7),
1770 			BPF_EXIT_INSN(),
1771 		},
1772 		INTERNAL,
1773 		{ 10, 20, 30, 40, 50 },
1774 		{ { 3, 0 }, { 4, 0 } }
1775 	},
1776 	{
1777 		"check: missing ret",
1778 		.u.insns = {
1779 			BPF_STMT(BPF_LD | BPF_IMM, 1),
1780 		},
1781 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1782 		{ },
1783 		{ }
1784 	},
1785 	{
1786 		"check: div_k_0",
1787 		.u.insns = {
1788 			BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1789 			BPF_STMT(BPF_RET | BPF_K, 0)
1790 		},
1791 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1792 		{ },
1793 		{ }
1794 	},
1795 	{
1796 		"check: unknown insn",
1797 		.u.insns = {
1798 			/* seccomp insn, rejected in socket filter */
1799 			BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1800 			BPF_STMT(BPF_RET | BPF_K, 0)
1801 		},
1802 		CLASSIC | FLAG_EXPECTED_FAIL,
1803 		{ },
1804 		{ }
1805 	},
1806 	{
1807 		"check: out of range spill/fill",
1808 		.u.insns = {
1809 			BPF_STMT(BPF_STX, 16),
1810 			BPF_STMT(BPF_RET | BPF_K, 0)
1811 		},
1812 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1813 		{ },
1814 		{ }
1815 	},
1816 	{
1817 		"JUMPS + HOLES",
1818 		.u.insns = {
1819 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1820 			BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1821 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1822 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1823 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1824 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1825 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1826 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1827 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1828 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1829 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1830 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1831 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1832 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1833 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1834 			BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1835 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1836 			BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1837 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1838 			BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1839 			BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1840 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1841 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1842 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1843 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1844 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1845 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1846 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1847 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1848 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1849 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1850 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1851 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1852 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1853 			BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1854 			BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1855 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1856 			BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1857 			BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1858 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1859 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1860 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1861 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1862 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1863 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1864 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1865 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1866 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1867 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1868 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1869 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1870 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1871 			BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1872 			BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1873 			BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1874 			BPF_STMT(BPF_RET | BPF_A, 0),
1875 			BPF_STMT(BPF_RET | BPF_A, 0),
1876 		},
1877 		CLASSIC,
1878 		{ 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1879 		  0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1880 		  0x08, 0x00,
1881 		  0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1882 		  0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1883 		  0xc0, 0xa8, 0x33, 0x01,
1884 		  0xc0, 0xa8, 0x33, 0x02,
1885 		  0xbb, 0xb6,
1886 		  0xa9, 0xfa,
1887 		  0x00, 0x14, 0x00, 0x00,
1888 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1889 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1890 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1891 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1892 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1893 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1894 		  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1895 		  0xcc, 0xcc, 0xcc, 0xcc },
1896 		{ { 88, 0x001b } }
1897 	},
1898 	{
1899 		"check: RET X",
1900 		.u.insns = {
1901 			BPF_STMT(BPF_RET | BPF_X, 0),
1902 		},
1903 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1904 		{ },
1905 		{ },
1906 	},
1907 	{
1908 		"check: LDX + RET X",
1909 		.u.insns = {
1910 			BPF_STMT(BPF_LDX | BPF_IMM, 42),
1911 			BPF_STMT(BPF_RET | BPF_X, 0),
1912 		},
1913 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1914 		{ },
1915 		{ },
1916 	},
1917 	{	/* Mainly checking JIT here. */
1918 		"M[]: alt STX + LDX",
1919 		.u.insns = {
1920 			BPF_STMT(BPF_LDX | BPF_IMM, 100),
1921 			BPF_STMT(BPF_STX, 0),
1922 			BPF_STMT(BPF_LDX | BPF_MEM, 0),
1923 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1924 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1925 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1926 			BPF_STMT(BPF_STX, 1),
1927 			BPF_STMT(BPF_LDX | BPF_MEM, 1),
1928 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1929 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1930 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1931 			BPF_STMT(BPF_STX, 2),
1932 			BPF_STMT(BPF_LDX | BPF_MEM, 2),
1933 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1934 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1935 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1936 			BPF_STMT(BPF_STX, 3),
1937 			BPF_STMT(BPF_LDX | BPF_MEM, 3),
1938 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1939 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1940 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1941 			BPF_STMT(BPF_STX, 4),
1942 			BPF_STMT(BPF_LDX | BPF_MEM, 4),
1943 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1944 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1945 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1946 			BPF_STMT(BPF_STX, 5),
1947 			BPF_STMT(BPF_LDX | BPF_MEM, 5),
1948 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1949 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1950 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1951 			BPF_STMT(BPF_STX, 6),
1952 			BPF_STMT(BPF_LDX | BPF_MEM, 6),
1953 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1954 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1955 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1956 			BPF_STMT(BPF_STX, 7),
1957 			BPF_STMT(BPF_LDX | BPF_MEM, 7),
1958 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1959 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1960 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1961 			BPF_STMT(BPF_STX, 8),
1962 			BPF_STMT(BPF_LDX | BPF_MEM, 8),
1963 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1964 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1965 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1966 			BPF_STMT(BPF_STX, 9),
1967 			BPF_STMT(BPF_LDX | BPF_MEM, 9),
1968 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1969 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1970 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1971 			BPF_STMT(BPF_STX, 10),
1972 			BPF_STMT(BPF_LDX | BPF_MEM, 10),
1973 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1974 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1975 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1976 			BPF_STMT(BPF_STX, 11),
1977 			BPF_STMT(BPF_LDX | BPF_MEM, 11),
1978 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1979 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1980 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1981 			BPF_STMT(BPF_STX, 12),
1982 			BPF_STMT(BPF_LDX | BPF_MEM, 12),
1983 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1984 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1985 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1986 			BPF_STMT(BPF_STX, 13),
1987 			BPF_STMT(BPF_LDX | BPF_MEM, 13),
1988 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1989 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1990 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1991 			BPF_STMT(BPF_STX, 14),
1992 			BPF_STMT(BPF_LDX | BPF_MEM, 14),
1993 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1994 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1995 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
1996 			BPF_STMT(BPF_STX, 15),
1997 			BPF_STMT(BPF_LDX | BPF_MEM, 15),
1998 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
1999 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2000 			BPF_STMT(BPF_MISC | BPF_TAX, 0),
2001 			BPF_STMT(BPF_RET | BPF_A, 0),
2002 		},
2003 		CLASSIC | FLAG_NO_DATA,
2004 		{ },
2005 		{ { 0, 116 } },
2006 	},
2007 	{	/* Mainly checking JIT here. */
2008 		"M[]: full STX + full LDX",
2009 		.u.insns = {
2010 			BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2011 			BPF_STMT(BPF_STX, 0),
2012 			BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2013 			BPF_STMT(BPF_STX, 1),
2014 			BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2015 			BPF_STMT(BPF_STX, 2),
2016 			BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2017 			BPF_STMT(BPF_STX, 3),
2018 			BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2019 			BPF_STMT(BPF_STX, 4),
2020 			BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2021 			BPF_STMT(BPF_STX, 5),
2022 			BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2023 			BPF_STMT(BPF_STX, 6),
2024 			BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2025 			BPF_STMT(BPF_STX, 7),
2026 			BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2027 			BPF_STMT(BPF_STX, 8),
2028 			BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2029 			BPF_STMT(BPF_STX, 9),
2030 			BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2031 			BPF_STMT(BPF_STX, 10),
2032 			BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2033 			BPF_STMT(BPF_STX, 11),
2034 			BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2035 			BPF_STMT(BPF_STX, 12),
2036 			BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2037 			BPF_STMT(BPF_STX, 13),
2038 			BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2039 			BPF_STMT(BPF_STX, 14),
2040 			BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2041 			BPF_STMT(BPF_STX, 15),
2042 			BPF_STMT(BPF_LDX | BPF_MEM, 0),
2043 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
2044 			BPF_STMT(BPF_LDX | BPF_MEM, 1),
2045 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2046 			BPF_STMT(BPF_LDX | BPF_MEM, 2),
2047 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2048 			BPF_STMT(BPF_LDX | BPF_MEM, 3),
2049 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2050 			BPF_STMT(BPF_LDX | BPF_MEM, 4),
2051 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2052 			BPF_STMT(BPF_LDX | BPF_MEM, 5),
2053 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2054 			BPF_STMT(BPF_LDX | BPF_MEM, 6),
2055 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2056 			BPF_STMT(BPF_LDX | BPF_MEM, 7),
2057 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2058 			BPF_STMT(BPF_LDX | BPF_MEM, 8),
2059 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2060 			BPF_STMT(BPF_LDX | BPF_MEM, 9),
2061 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2062 			BPF_STMT(BPF_LDX | BPF_MEM, 10),
2063 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2064 			BPF_STMT(BPF_LDX | BPF_MEM, 11),
2065 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2066 			BPF_STMT(BPF_LDX | BPF_MEM, 12),
2067 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2068 			BPF_STMT(BPF_LDX | BPF_MEM, 13),
2069 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2070 			BPF_STMT(BPF_LDX | BPF_MEM, 14),
2071 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2072 			BPF_STMT(BPF_LDX | BPF_MEM, 15),
2073 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2074 			BPF_STMT(BPF_RET | BPF_A, 0),
2075 		},
2076 		CLASSIC | FLAG_NO_DATA,
2077 		{ },
2078 		{ { 0, 0x2a5a5e5 } },
2079 	},
2080 	{
2081 		"check: SKF_AD_MAX",
2082 		.u.insns = {
2083 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2084 				 SKF_AD_OFF + SKF_AD_MAX),
2085 			BPF_STMT(BPF_RET | BPF_A, 0),
2086 		},
2087 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2088 		{ },
2089 		{ },
2090 	},
2091 	{	/* Passes checker but fails during runtime. */
2092 		"LD [SKF_AD_OFF-1]",
2093 		.u.insns = {
2094 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2095 				 SKF_AD_OFF - 1),
2096 			BPF_STMT(BPF_RET | BPF_K, 1),
2097 		},
2098 		CLASSIC,
2099 		{ },
2100 		{ { 1, 0 } },
2101 	},
2102 	{
2103 		"load 64-bit immediate",
2104 		.u.insns_int = {
2105 			BPF_LD_IMM64(R1, 0x567800001234LL),
2106 			BPF_MOV64_REG(R2, R1),
2107 			BPF_MOV64_REG(R3, R2),
2108 			BPF_ALU64_IMM(BPF_RSH, R2, 32),
2109 			BPF_ALU64_IMM(BPF_LSH, R3, 32),
2110 			BPF_ALU64_IMM(BPF_RSH, R3, 32),
2111 			BPF_ALU64_IMM(BPF_MOV, R0, 0),
2112 			BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2113 			BPF_EXIT_INSN(),
2114 			BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2115 			BPF_EXIT_INSN(),
2116 			BPF_LD_IMM64(R0, 0x1ffffffffLL),
2117 			BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2118 			BPF_EXIT_INSN(),
2119 		},
2120 		INTERNAL,
2121 		{ },
2122 		{ { 0, 1 } }
2123 	},
2124 	{
2125 		"nmap reduced",
2126 		.u.insns_int = {
2127 			BPF_MOV64_REG(R6, R1),
2128 			BPF_LD_ABS(BPF_H, 12),
2129 			BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2130 			BPF_LD_ABS(BPF_H, 12),
2131 			BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2132 			BPF_MOV32_IMM(R0, 18),
2133 			BPF_STX_MEM(BPF_W, R10, R0, -64),
2134 			BPF_LDX_MEM(BPF_W, R7, R10, -64),
2135 			BPF_LD_IND(BPF_W, R7, 14),
2136 			BPF_STX_MEM(BPF_W, R10, R0, -60),
2137 			BPF_MOV32_IMM(R0, 280971478),
2138 			BPF_STX_MEM(BPF_W, R10, R0, -56),
2139 			BPF_LDX_MEM(BPF_W, R7, R10, -56),
2140 			BPF_LDX_MEM(BPF_W, R0, R10, -60),
2141 			BPF_ALU32_REG(BPF_SUB, R0, R7),
2142 			BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2143 			BPF_LD_ABS(BPF_H, 12),
2144 			BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2145 			BPF_MOV32_IMM(R0, 22),
2146 			BPF_STX_MEM(BPF_W, R10, R0, -56),
2147 			BPF_LDX_MEM(BPF_W, R7, R10, -56),
2148 			BPF_LD_IND(BPF_H, R7, 14),
2149 			BPF_STX_MEM(BPF_W, R10, R0, -52),
2150 			BPF_MOV32_IMM(R0, 17366),
2151 			BPF_STX_MEM(BPF_W, R10, R0, -48),
2152 			BPF_LDX_MEM(BPF_W, R7, R10, -48),
2153 			BPF_LDX_MEM(BPF_W, R0, R10, -52),
2154 			BPF_ALU32_REG(BPF_SUB, R0, R7),
2155 			BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2156 			BPF_MOV32_IMM(R0, 256),
2157 			BPF_EXIT_INSN(),
2158 			BPF_MOV32_IMM(R0, 0),
2159 			BPF_EXIT_INSN(),
2160 		},
2161 		INTERNAL,
2162 		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2163 		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2164 		  0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2165 		{ { 38, 256 } }
2166 	},
2167 	/* BPF_ALU | BPF_MOV | BPF_X */
2168 	{
2169 		"ALU_MOV_X: dst = 2",
2170 		.u.insns_int = {
2171 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2172 			BPF_ALU32_REG(BPF_MOV, R0, R1),
2173 			BPF_EXIT_INSN(),
2174 		},
2175 		INTERNAL,
2176 		{ },
2177 		{ { 0, 2 } },
2178 	},
2179 	{
2180 		"ALU_MOV_X: dst = 4294967295",
2181 		.u.insns_int = {
2182 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2183 			BPF_ALU32_REG(BPF_MOV, R0, R1),
2184 			BPF_EXIT_INSN(),
2185 		},
2186 		INTERNAL,
2187 		{ },
2188 		{ { 0, 4294967295U } },
2189 	},
2190 	{
2191 		"ALU64_MOV_X: dst = 2",
2192 		.u.insns_int = {
2193 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2194 			BPF_ALU64_REG(BPF_MOV, R0, R1),
2195 			BPF_EXIT_INSN(),
2196 		},
2197 		INTERNAL,
2198 		{ },
2199 		{ { 0, 2 } },
2200 	},
2201 	{
2202 		"ALU64_MOV_X: dst = 4294967295",
2203 		.u.insns_int = {
2204 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2205 			BPF_ALU64_REG(BPF_MOV, R0, R1),
2206 			BPF_EXIT_INSN(),
2207 		},
2208 		INTERNAL,
2209 		{ },
2210 		{ { 0, 4294967295U } },
2211 	},
2212 	/* BPF_ALU | BPF_MOV | BPF_K */
2213 	{
2214 		"ALU_MOV_K: dst = 2",
2215 		.u.insns_int = {
2216 			BPF_ALU32_IMM(BPF_MOV, R0, 2),
2217 			BPF_EXIT_INSN(),
2218 		},
2219 		INTERNAL,
2220 		{ },
2221 		{ { 0, 2 } },
2222 	},
2223 	{
2224 		"ALU_MOV_K: dst = 4294967295",
2225 		.u.insns_int = {
2226 			BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2227 			BPF_EXIT_INSN(),
2228 		},
2229 		INTERNAL,
2230 		{ },
2231 		{ { 0, 4294967295U } },
2232 	},
2233 	{
2234 		"ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2235 		.u.insns_int = {
2236 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2237 			BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2238 			BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2239 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2240 			BPF_MOV32_IMM(R0, 2),
2241 			BPF_EXIT_INSN(),
2242 			BPF_MOV32_IMM(R0, 1),
2243 			BPF_EXIT_INSN(),
2244 		},
2245 		INTERNAL,
2246 		{ },
2247 		{ { 0, 0x1 } },
2248 	},
2249 	{
2250 		"ALU64_MOV_K: dst = 2",
2251 		.u.insns_int = {
2252 			BPF_ALU64_IMM(BPF_MOV, R0, 2),
2253 			BPF_EXIT_INSN(),
2254 		},
2255 		INTERNAL,
2256 		{ },
2257 		{ { 0, 2 } },
2258 	},
2259 	{
2260 		"ALU64_MOV_K: dst = 2147483647",
2261 		.u.insns_int = {
2262 			BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2263 			BPF_EXIT_INSN(),
2264 		},
2265 		INTERNAL,
2266 		{ },
2267 		{ { 0, 2147483647 } },
2268 	},
2269 	{
2270 		"ALU64_OR_K: dst = 0x0",
2271 		.u.insns_int = {
2272 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2273 			BPF_LD_IMM64(R3, 0x0),
2274 			BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2275 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2276 			BPF_MOV32_IMM(R0, 2),
2277 			BPF_EXIT_INSN(),
2278 			BPF_MOV32_IMM(R0, 1),
2279 			BPF_EXIT_INSN(),
2280 		},
2281 		INTERNAL,
2282 		{ },
2283 		{ { 0, 0x1 } },
2284 	},
2285 	{
2286 		"ALU64_MOV_K: dst = -1",
2287 		.u.insns_int = {
2288 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2289 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2290 			BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2291 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2292 			BPF_MOV32_IMM(R0, 2),
2293 			BPF_EXIT_INSN(),
2294 			BPF_MOV32_IMM(R0, 1),
2295 			BPF_EXIT_INSN(),
2296 		},
2297 		INTERNAL,
2298 		{ },
2299 		{ { 0, 0x1 } },
2300 	},
2301 	/* BPF_ALU | BPF_ADD | BPF_X */
2302 	{
2303 		"ALU_ADD_X: 1 + 2 = 3",
2304 		.u.insns_int = {
2305 			BPF_LD_IMM64(R0, 1),
2306 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2307 			BPF_ALU32_REG(BPF_ADD, R0, R1),
2308 			BPF_EXIT_INSN(),
2309 		},
2310 		INTERNAL,
2311 		{ },
2312 		{ { 0, 3 } },
2313 	},
2314 	{
2315 		"ALU_ADD_X: 1 + 4294967294 = 4294967295",
2316 		.u.insns_int = {
2317 			BPF_LD_IMM64(R0, 1),
2318 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2319 			BPF_ALU32_REG(BPF_ADD, R0, R1),
2320 			BPF_EXIT_INSN(),
2321 		},
2322 		INTERNAL,
2323 		{ },
2324 		{ { 0, 4294967295U } },
2325 	},
2326 	{
2327 		"ALU64_ADD_X: 1 + 2 = 3",
2328 		.u.insns_int = {
2329 			BPF_LD_IMM64(R0, 1),
2330 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2331 			BPF_ALU64_REG(BPF_ADD, R0, R1),
2332 			BPF_EXIT_INSN(),
2333 		},
2334 		INTERNAL,
2335 		{ },
2336 		{ { 0, 3 } },
2337 	},
2338 	{
2339 		"ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2340 		.u.insns_int = {
2341 			BPF_LD_IMM64(R0, 1),
2342 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2343 			BPF_ALU64_REG(BPF_ADD, R0, R1),
2344 			BPF_EXIT_INSN(),
2345 		},
2346 		INTERNAL,
2347 		{ },
2348 		{ { 0, 4294967295U } },
2349 	},
2350 	/* BPF_ALU | BPF_ADD | BPF_K */
2351 	{
2352 		"ALU_ADD_K: 1 + 2 = 3",
2353 		.u.insns_int = {
2354 			BPF_LD_IMM64(R0, 1),
2355 			BPF_ALU32_IMM(BPF_ADD, R0, 2),
2356 			BPF_EXIT_INSN(),
2357 		},
2358 		INTERNAL,
2359 		{ },
2360 		{ { 0, 3 } },
2361 	},
2362 	{
2363 		"ALU_ADD_K: 3 + 0 = 3",
2364 		.u.insns_int = {
2365 			BPF_LD_IMM64(R0, 3),
2366 			BPF_ALU32_IMM(BPF_ADD, R0, 0),
2367 			BPF_EXIT_INSN(),
2368 		},
2369 		INTERNAL,
2370 		{ },
2371 		{ { 0, 3 } },
2372 	},
2373 	{
2374 		"ALU_ADD_K: 1 + 4294967294 = 4294967295",
2375 		.u.insns_int = {
2376 			BPF_LD_IMM64(R0, 1),
2377 			BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2378 			BPF_EXIT_INSN(),
2379 		},
2380 		INTERNAL,
2381 		{ },
2382 		{ { 0, 4294967295U } },
2383 	},
2384 	{
2385 		"ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2386 		.u.insns_int = {
2387 			BPF_LD_IMM64(R2, 0x0),
2388 			BPF_LD_IMM64(R3, 0x00000000ffffffff),
2389 			BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2390 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2391 			BPF_MOV32_IMM(R0, 2),
2392 			BPF_EXIT_INSN(),
2393 			BPF_MOV32_IMM(R0, 1),
2394 			BPF_EXIT_INSN(),
2395 		},
2396 		INTERNAL,
2397 		{ },
2398 		{ { 0, 0x1 } },
2399 	},
2400 	{
2401 		"ALU64_ADD_K: 1 + 2 = 3",
2402 		.u.insns_int = {
2403 			BPF_LD_IMM64(R0, 1),
2404 			BPF_ALU64_IMM(BPF_ADD, R0, 2),
2405 			BPF_EXIT_INSN(),
2406 		},
2407 		INTERNAL,
2408 		{ },
2409 		{ { 0, 3 } },
2410 	},
2411 	{
2412 		"ALU64_ADD_K: 3 + 0 = 3",
2413 		.u.insns_int = {
2414 			BPF_LD_IMM64(R0, 3),
2415 			BPF_ALU64_IMM(BPF_ADD, R0, 0),
2416 			BPF_EXIT_INSN(),
2417 		},
2418 		INTERNAL,
2419 		{ },
2420 		{ { 0, 3 } },
2421 	},
2422 	{
2423 		"ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2424 		.u.insns_int = {
2425 			BPF_LD_IMM64(R0, 1),
2426 			BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2427 			BPF_EXIT_INSN(),
2428 		},
2429 		INTERNAL,
2430 		{ },
2431 		{ { 0, 2147483647 } },
2432 	},
2433 	{
2434 		"ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2435 		.u.insns_int = {
2436 			BPF_LD_IMM64(R0, 2147483646),
2437 			BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2438 			BPF_EXIT_INSN(),
2439 		},
2440 		INTERNAL,
2441 		{ },
2442 		{ { 0, -1 } },
2443 	},
2444 	{
2445 		"ALU64_ADD_K: 1 + 0 = 1",
2446 		.u.insns_int = {
2447 			BPF_LD_IMM64(R2, 0x1),
2448 			BPF_LD_IMM64(R3, 0x1),
2449 			BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2450 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2451 			BPF_MOV32_IMM(R0, 2),
2452 			BPF_EXIT_INSN(),
2453 			BPF_MOV32_IMM(R0, 1),
2454 			BPF_EXIT_INSN(),
2455 		},
2456 		INTERNAL,
2457 		{ },
2458 		{ { 0, 0x1 } },
2459 	},
2460 	{
2461 		"ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2462 		.u.insns_int = {
2463 			BPF_LD_IMM64(R2, 0x0),
2464 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2465 			BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2466 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2467 			BPF_MOV32_IMM(R0, 2),
2468 			BPF_EXIT_INSN(),
2469 			BPF_MOV32_IMM(R0, 1),
2470 			BPF_EXIT_INSN(),
2471 		},
2472 		INTERNAL,
2473 		{ },
2474 		{ { 0, 0x1 } },
2475 	},
2476 	/* BPF_ALU | BPF_SUB | BPF_X */
2477 	{
2478 		"ALU_SUB_X: 3 - 1 = 2",
2479 		.u.insns_int = {
2480 			BPF_LD_IMM64(R0, 3),
2481 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
2482 			BPF_ALU32_REG(BPF_SUB, R0, R1),
2483 			BPF_EXIT_INSN(),
2484 		},
2485 		INTERNAL,
2486 		{ },
2487 		{ { 0, 2 } },
2488 	},
2489 	{
2490 		"ALU_SUB_X: 4294967295 - 4294967294 = 1",
2491 		.u.insns_int = {
2492 			BPF_LD_IMM64(R0, 4294967295U),
2493 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2494 			BPF_ALU32_REG(BPF_SUB, R0, R1),
2495 			BPF_EXIT_INSN(),
2496 		},
2497 		INTERNAL,
2498 		{ },
2499 		{ { 0, 1 } },
2500 	},
2501 	{
2502 		"ALU64_SUB_X: 3 - 1 = 2",
2503 		.u.insns_int = {
2504 			BPF_LD_IMM64(R0, 3),
2505 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
2506 			BPF_ALU64_REG(BPF_SUB, R0, R1),
2507 			BPF_EXIT_INSN(),
2508 		},
2509 		INTERNAL,
2510 		{ },
2511 		{ { 0, 2 } },
2512 	},
2513 	{
2514 		"ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2515 		.u.insns_int = {
2516 			BPF_LD_IMM64(R0, 4294967295U),
2517 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2518 			BPF_ALU64_REG(BPF_SUB, R0, R1),
2519 			BPF_EXIT_INSN(),
2520 		},
2521 		INTERNAL,
2522 		{ },
2523 		{ { 0, 1 } },
2524 	},
2525 	/* BPF_ALU | BPF_SUB | BPF_K */
2526 	{
2527 		"ALU_SUB_K: 3 - 1 = 2",
2528 		.u.insns_int = {
2529 			BPF_LD_IMM64(R0, 3),
2530 			BPF_ALU32_IMM(BPF_SUB, R0, 1),
2531 			BPF_EXIT_INSN(),
2532 		},
2533 		INTERNAL,
2534 		{ },
2535 		{ { 0, 2 } },
2536 	},
2537 	{
2538 		"ALU_SUB_K: 3 - 0 = 3",
2539 		.u.insns_int = {
2540 			BPF_LD_IMM64(R0, 3),
2541 			BPF_ALU32_IMM(BPF_SUB, R0, 0),
2542 			BPF_EXIT_INSN(),
2543 		},
2544 		INTERNAL,
2545 		{ },
2546 		{ { 0, 3 } },
2547 	},
2548 	{
2549 		"ALU_SUB_K: 4294967295 - 4294967294 = 1",
2550 		.u.insns_int = {
2551 			BPF_LD_IMM64(R0, 4294967295U),
2552 			BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
2553 			BPF_EXIT_INSN(),
2554 		},
2555 		INTERNAL,
2556 		{ },
2557 		{ { 0, 1 } },
2558 	},
2559 	{
2560 		"ALU64_SUB_K: 3 - 1 = 2",
2561 		.u.insns_int = {
2562 			BPF_LD_IMM64(R0, 3),
2563 			BPF_ALU64_IMM(BPF_SUB, R0, 1),
2564 			BPF_EXIT_INSN(),
2565 		},
2566 		INTERNAL,
2567 		{ },
2568 		{ { 0, 2 } },
2569 	},
2570 	{
2571 		"ALU64_SUB_K: 3 - 0 = 3",
2572 		.u.insns_int = {
2573 			BPF_LD_IMM64(R0, 3),
2574 			BPF_ALU64_IMM(BPF_SUB, R0, 0),
2575 			BPF_EXIT_INSN(),
2576 		},
2577 		INTERNAL,
2578 		{ },
2579 		{ { 0, 3 } },
2580 	},
2581 	{
2582 		"ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2583 		.u.insns_int = {
2584 			BPF_LD_IMM64(R0, 4294967294U),
2585 			BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
2586 			BPF_EXIT_INSN(),
2587 		},
2588 		INTERNAL,
2589 		{ },
2590 		{ { 0, -1 } },
2591 	},
2592 	{
2593 		"ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2594 		.u.insns_int = {
2595 			BPF_LD_IMM64(R0, 2147483646),
2596 			BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2597 			BPF_EXIT_INSN(),
2598 		},
2599 		INTERNAL,
2600 		{ },
2601 		{ { 0, -1 } },
2602 	},
2603 	/* BPF_ALU | BPF_MUL | BPF_X */
2604 	{
2605 		"ALU_MUL_X: 2 * 3 = 6",
2606 		.u.insns_int = {
2607 			BPF_LD_IMM64(R0, 2),
2608 			BPF_ALU32_IMM(BPF_MOV, R1, 3),
2609 			BPF_ALU32_REG(BPF_MUL, R0, R1),
2610 			BPF_EXIT_INSN(),
2611 		},
2612 		INTERNAL,
2613 		{ },
2614 		{ { 0, 6 } },
2615 	},
2616 	{
2617 		"ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2618 		.u.insns_int = {
2619 			BPF_LD_IMM64(R0, 2),
2620 			BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2621 			BPF_ALU32_REG(BPF_MUL, R0, R1),
2622 			BPF_EXIT_INSN(),
2623 		},
2624 		INTERNAL,
2625 		{ },
2626 		{ { 0, 0xFFFFFFF0 } },
2627 	},
2628 	{
2629 		"ALU_MUL_X: -1 * -1 = 1",
2630 		.u.insns_int = {
2631 			BPF_LD_IMM64(R0, -1),
2632 			BPF_ALU32_IMM(BPF_MOV, R1, -1),
2633 			BPF_ALU32_REG(BPF_MUL, R0, R1),
2634 			BPF_EXIT_INSN(),
2635 		},
2636 		INTERNAL,
2637 		{ },
2638 		{ { 0, 1 } },
2639 	},
2640 	{
2641 		"ALU64_MUL_X: 2 * 3 = 6",
2642 		.u.insns_int = {
2643 			BPF_LD_IMM64(R0, 2),
2644 			BPF_ALU32_IMM(BPF_MOV, R1, 3),
2645 			BPF_ALU64_REG(BPF_MUL, R0, R1),
2646 			BPF_EXIT_INSN(),
2647 		},
2648 		INTERNAL,
2649 		{ },
2650 		{ { 0, 6 } },
2651 	},
2652 	{
2653 		"ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2654 		.u.insns_int = {
2655 			BPF_LD_IMM64(R0, 1),
2656 			BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2657 			BPF_ALU64_REG(BPF_MUL, R0, R1),
2658 			BPF_EXIT_INSN(),
2659 		},
2660 		INTERNAL,
2661 		{ },
2662 		{ { 0, 2147483647 } },
2663 	},
2664 	/* BPF_ALU | BPF_MUL | BPF_K */
2665 	{
2666 		"ALU_MUL_K: 2 * 3 = 6",
2667 		.u.insns_int = {
2668 			BPF_LD_IMM64(R0, 2),
2669 			BPF_ALU32_IMM(BPF_MUL, R0, 3),
2670 			BPF_EXIT_INSN(),
2671 		},
2672 		INTERNAL,
2673 		{ },
2674 		{ { 0, 6 } },
2675 	},
2676 	{
2677 		"ALU_MUL_K: 3 * 1 = 3",
2678 		.u.insns_int = {
2679 			BPF_LD_IMM64(R0, 3),
2680 			BPF_ALU32_IMM(BPF_MUL, R0, 1),
2681 			BPF_EXIT_INSN(),
2682 		},
2683 		INTERNAL,
2684 		{ },
2685 		{ { 0, 3 } },
2686 	},
2687 	{
2688 		"ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2689 		.u.insns_int = {
2690 			BPF_LD_IMM64(R0, 2),
2691 			BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2692 			BPF_EXIT_INSN(),
2693 		},
2694 		INTERNAL,
2695 		{ },
2696 		{ { 0, 0xFFFFFFF0 } },
2697 	},
2698 	{
2699 		"ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
2700 		.u.insns_int = {
2701 			BPF_LD_IMM64(R2, 0x1),
2702 			BPF_LD_IMM64(R3, 0x00000000ffffffff),
2703 			BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
2704 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2705 			BPF_MOV32_IMM(R0, 2),
2706 			BPF_EXIT_INSN(),
2707 			BPF_MOV32_IMM(R0, 1),
2708 			BPF_EXIT_INSN(),
2709 		},
2710 		INTERNAL,
2711 		{ },
2712 		{ { 0, 0x1 } },
2713 	},
2714 	{
2715 		"ALU64_MUL_K: 2 * 3 = 6",
2716 		.u.insns_int = {
2717 			BPF_LD_IMM64(R0, 2),
2718 			BPF_ALU64_IMM(BPF_MUL, R0, 3),
2719 			BPF_EXIT_INSN(),
2720 		},
2721 		INTERNAL,
2722 		{ },
2723 		{ { 0, 6 } },
2724 	},
2725 	{
2726 		"ALU64_MUL_K: 3 * 1 = 3",
2727 		.u.insns_int = {
2728 			BPF_LD_IMM64(R0, 3),
2729 			BPF_ALU64_IMM(BPF_MUL, R0, 1),
2730 			BPF_EXIT_INSN(),
2731 		},
2732 		INTERNAL,
2733 		{ },
2734 		{ { 0, 3 } },
2735 	},
2736 	{
2737 		"ALU64_MUL_K: 1 * 2147483647 = 2147483647",
2738 		.u.insns_int = {
2739 			BPF_LD_IMM64(R0, 1),
2740 			BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
2741 			BPF_EXIT_INSN(),
2742 		},
2743 		INTERNAL,
2744 		{ },
2745 		{ { 0, 2147483647 } },
2746 	},
2747 	{
2748 		"ALU64_MUL_K: 1 * -2147483647 = -2147483647",
2749 		.u.insns_int = {
2750 			BPF_LD_IMM64(R0, 1),
2751 			BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
2752 			BPF_EXIT_INSN(),
2753 		},
2754 		INTERNAL,
2755 		{ },
2756 		{ { 0, -2147483647 } },
2757 	},
2758 	{
2759 		"ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
2760 		.u.insns_int = {
2761 			BPF_LD_IMM64(R2, 0x1),
2762 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2763 			BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
2764 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2765 			BPF_MOV32_IMM(R0, 2),
2766 			BPF_EXIT_INSN(),
2767 			BPF_MOV32_IMM(R0, 1),
2768 			BPF_EXIT_INSN(),
2769 		},
2770 		INTERNAL,
2771 		{ },
2772 		{ { 0, 0x1 } },
2773 	},
2774 	/* BPF_ALU | BPF_DIV | BPF_X */
2775 	{
2776 		"ALU_DIV_X: 6 / 2 = 3",
2777 		.u.insns_int = {
2778 			BPF_LD_IMM64(R0, 6),
2779 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2780 			BPF_ALU32_REG(BPF_DIV, R0, R1),
2781 			BPF_EXIT_INSN(),
2782 		},
2783 		INTERNAL,
2784 		{ },
2785 		{ { 0, 3 } },
2786 	},
2787 	{
2788 		"ALU_DIV_X: 4294967295 / 4294967295 = 1",
2789 		.u.insns_int = {
2790 			BPF_LD_IMM64(R0, 4294967295U),
2791 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2792 			BPF_ALU32_REG(BPF_DIV, R0, R1),
2793 			BPF_EXIT_INSN(),
2794 		},
2795 		INTERNAL,
2796 		{ },
2797 		{ { 0, 1 } },
2798 	},
2799 	{
2800 		"ALU64_DIV_X: 6 / 2 = 3",
2801 		.u.insns_int = {
2802 			BPF_LD_IMM64(R0, 6),
2803 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2804 			BPF_ALU64_REG(BPF_DIV, R0, R1),
2805 			BPF_EXIT_INSN(),
2806 		},
2807 		INTERNAL,
2808 		{ },
2809 		{ { 0, 3 } },
2810 	},
2811 	{
2812 		"ALU64_DIV_X: 2147483647 / 2147483647 = 1",
2813 		.u.insns_int = {
2814 			BPF_LD_IMM64(R0, 2147483647),
2815 			BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2816 			BPF_ALU64_REG(BPF_DIV, R0, R1),
2817 			BPF_EXIT_INSN(),
2818 		},
2819 		INTERNAL,
2820 		{ },
2821 		{ { 0, 1 } },
2822 	},
2823 	{
2824 		"ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2825 		.u.insns_int = {
2826 			BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2827 			BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
2828 			BPF_LD_IMM64(R3, 0x0000000000000001LL),
2829 			BPF_ALU64_REG(BPF_DIV, R2, R4),
2830 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2831 			BPF_MOV32_IMM(R0, 2),
2832 			BPF_EXIT_INSN(),
2833 			BPF_MOV32_IMM(R0, 1),
2834 			BPF_EXIT_INSN(),
2835 		},
2836 		INTERNAL,
2837 		{ },
2838 		{ { 0, 0x1 } },
2839 	},
2840 	/* BPF_ALU | BPF_DIV | BPF_K */
2841 	{
2842 		"ALU_DIV_K: 6 / 2 = 3",
2843 		.u.insns_int = {
2844 			BPF_LD_IMM64(R0, 6),
2845 			BPF_ALU32_IMM(BPF_DIV, R0, 2),
2846 			BPF_EXIT_INSN(),
2847 		},
2848 		INTERNAL,
2849 		{ },
2850 		{ { 0, 3 } },
2851 	},
2852 	{
2853 		"ALU_DIV_K: 3 / 1 = 3",
2854 		.u.insns_int = {
2855 			BPF_LD_IMM64(R0, 3),
2856 			BPF_ALU32_IMM(BPF_DIV, R0, 1),
2857 			BPF_EXIT_INSN(),
2858 		},
2859 		INTERNAL,
2860 		{ },
2861 		{ { 0, 3 } },
2862 	},
2863 	{
2864 		"ALU_DIV_K: 4294967295 / 4294967295 = 1",
2865 		.u.insns_int = {
2866 			BPF_LD_IMM64(R0, 4294967295U),
2867 			BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
2868 			BPF_EXIT_INSN(),
2869 		},
2870 		INTERNAL,
2871 		{ },
2872 		{ { 0, 1 } },
2873 	},
2874 	{
2875 		"ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
2876 		.u.insns_int = {
2877 			BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2878 			BPF_LD_IMM64(R3, 0x1UL),
2879 			BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
2880 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2881 			BPF_MOV32_IMM(R0, 2),
2882 			BPF_EXIT_INSN(),
2883 			BPF_MOV32_IMM(R0, 1),
2884 			BPF_EXIT_INSN(),
2885 		},
2886 		INTERNAL,
2887 		{ },
2888 		{ { 0, 0x1 } },
2889 	},
2890 	{
2891 		"ALU64_DIV_K: 6 / 2 = 3",
2892 		.u.insns_int = {
2893 			BPF_LD_IMM64(R0, 6),
2894 			BPF_ALU64_IMM(BPF_DIV, R0, 2),
2895 			BPF_EXIT_INSN(),
2896 		},
2897 		INTERNAL,
2898 		{ },
2899 		{ { 0, 3 } },
2900 	},
2901 	{
2902 		"ALU64_DIV_K: 3 / 1 = 3",
2903 		.u.insns_int = {
2904 			BPF_LD_IMM64(R0, 3),
2905 			BPF_ALU64_IMM(BPF_DIV, R0, 1),
2906 			BPF_EXIT_INSN(),
2907 		},
2908 		INTERNAL,
2909 		{ },
2910 		{ { 0, 3 } },
2911 	},
2912 	{
2913 		"ALU64_DIV_K: 2147483647 / 2147483647 = 1",
2914 		.u.insns_int = {
2915 			BPF_LD_IMM64(R0, 2147483647),
2916 			BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
2917 			BPF_EXIT_INSN(),
2918 		},
2919 		INTERNAL,
2920 		{ },
2921 		{ { 0, 1 } },
2922 	},
2923 	{
2924 		"ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2925 		.u.insns_int = {
2926 			BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2927 			BPF_LD_IMM64(R3, 0x0000000000000001LL),
2928 			BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
2929 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2930 			BPF_MOV32_IMM(R0, 2),
2931 			BPF_EXIT_INSN(),
2932 			BPF_MOV32_IMM(R0, 1),
2933 			BPF_EXIT_INSN(),
2934 		},
2935 		INTERNAL,
2936 		{ },
2937 		{ { 0, 0x1 } },
2938 	},
2939 	/* BPF_ALU | BPF_MOD | BPF_X */
2940 	{
2941 		"ALU_MOD_X: 3 % 2 = 1",
2942 		.u.insns_int = {
2943 			BPF_LD_IMM64(R0, 3),
2944 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2945 			BPF_ALU32_REG(BPF_MOD, R0, R1),
2946 			BPF_EXIT_INSN(),
2947 		},
2948 		INTERNAL,
2949 		{ },
2950 		{ { 0, 1 } },
2951 	},
2952 	{
2953 		"ALU_MOD_X: 4294967295 % 4294967293 = 2",
2954 		.u.insns_int = {
2955 			BPF_LD_IMM64(R0, 4294967295U),
2956 			BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
2957 			BPF_ALU32_REG(BPF_MOD, R0, R1),
2958 			BPF_EXIT_INSN(),
2959 		},
2960 		INTERNAL,
2961 		{ },
2962 		{ { 0, 2 } },
2963 	},
2964 	{
2965 		"ALU64_MOD_X: 3 % 2 = 1",
2966 		.u.insns_int = {
2967 			BPF_LD_IMM64(R0, 3),
2968 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
2969 			BPF_ALU64_REG(BPF_MOD, R0, R1),
2970 			BPF_EXIT_INSN(),
2971 		},
2972 		INTERNAL,
2973 		{ },
2974 		{ { 0, 1 } },
2975 	},
2976 	{
2977 		"ALU64_MOD_X: 2147483647 % 2147483645 = 2",
2978 		.u.insns_int = {
2979 			BPF_LD_IMM64(R0, 2147483647),
2980 			BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
2981 			BPF_ALU64_REG(BPF_MOD, R0, R1),
2982 			BPF_EXIT_INSN(),
2983 		},
2984 		INTERNAL,
2985 		{ },
2986 		{ { 0, 2 } },
2987 	},
2988 	/* BPF_ALU | BPF_MOD | BPF_K */
2989 	{
2990 		"ALU_MOD_K: 3 % 2 = 1",
2991 		.u.insns_int = {
2992 			BPF_LD_IMM64(R0, 3),
2993 			BPF_ALU32_IMM(BPF_MOD, R0, 2),
2994 			BPF_EXIT_INSN(),
2995 		},
2996 		INTERNAL,
2997 		{ },
2998 		{ { 0, 1 } },
2999 	},
3000 	{
3001 		"ALU_MOD_K: 3 % 1 = 0",
3002 		.u.insns_int = {
3003 			BPF_LD_IMM64(R0, 3),
3004 			BPF_ALU32_IMM(BPF_MOD, R0, 1),
3005 			BPF_EXIT_INSN(),
3006 		},
3007 		INTERNAL,
3008 		{ },
3009 		{ { 0, 0 } },
3010 	},
3011 	{
3012 		"ALU_MOD_K: 4294967295 % 4294967293 = 2",
3013 		.u.insns_int = {
3014 			BPF_LD_IMM64(R0, 4294967295U),
3015 			BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
3016 			BPF_EXIT_INSN(),
3017 		},
3018 		INTERNAL,
3019 		{ },
3020 		{ { 0, 2 } },
3021 	},
3022 	{
3023 		"ALU64_MOD_K: 3 % 2 = 1",
3024 		.u.insns_int = {
3025 			BPF_LD_IMM64(R0, 3),
3026 			BPF_ALU64_IMM(BPF_MOD, R0, 2),
3027 			BPF_EXIT_INSN(),
3028 		},
3029 		INTERNAL,
3030 		{ },
3031 		{ { 0, 1 } },
3032 	},
3033 	{
3034 		"ALU64_MOD_K: 3 % 1 = 0",
3035 		.u.insns_int = {
3036 			BPF_LD_IMM64(R0, 3),
3037 			BPF_ALU64_IMM(BPF_MOD, R0, 1),
3038 			BPF_EXIT_INSN(),
3039 		},
3040 		INTERNAL,
3041 		{ },
3042 		{ { 0, 0 } },
3043 	},
3044 	{
3045 		"ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3046 		.u.insns_int = {
3047 			BPF_LD_IMM64(R0, 2147483647),
3048 			BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3049 			BPF_EXIT_INSN(),
3050 		},
3051 		INTERNAL,
3052 		{ },
3053 		{ { 0, 2 } },
3054 	},
3055 	/* BPF_ALU | BPF_AND | BPF_X */
3056 	{
3057 		"ALU_AND_X: 3 & 2 = 2",
3058 		.u.insns_int = {
3059 			BPF_LD_IMM64(R0, 3),
3060 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
3061 			BPF_ALU32_REG(BPF_AND, R0, R1),
3062 			BPF_EXIT_INSN(),
3063 		},
3064 		INTERNAL,
3065 		{ },
3066 		{ { 0, 2 } },
3067 	},
3068 	{
3069 		"ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3070 		.u.insns_int = {
3071 			BPF_LD_IMM64(R0, 0xffffffff),
3072 			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3073 			BPF_ALU32_REG(BPF_AND, R0, R1),
3074 			BPF_EXIT_INSN(),
3075 		},
3076 		INTERNAL,
3077 		{ },
3078 		{ { 0, 0xffffffff } },
3079 	},
3080 	{
3081 		"ALU64_AND_X: 3 & 2 = 2",
3082 		.u.insns_int = {
3083 			BPF_LD_IMM64(R0, 3),
3084 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
3085 			BPF_ALU64_REG(BPF_AND, R0, R1),
3086 			BPF_EXIT_INSN(),
3087 		},
3088 		INTERNAL,
3089 		{ },
3090 		{ { 0, 2 } },
3091 	},
3092 	{
3093 		"ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3094 		.u.insns_int = {
3095 			BPF_LD_IMM64(R0, 0xffffffff),
3096 			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3097 			BPF_ALU64_REG(BPF_AND, R0, R1),
3098 			BPF_EXIT_INSN(),
3099 		},
3100 		INTERNAL,
3101 		{ },
3102 		{ { 0, 0xffffffff } },
3103 	},
3104 	/* BPF_ALU | BPF_AND | BPF_K */
3105 	{
3106 		"ALU_AND_K: 3 & 2 = 2",
3107 		.u.insns_int = {
3108 			BPF_LD_IMM64(R0, 3),
3109 			BPF_ALU32_IMM(BPF_AND, R0, 2),
3110 			BPF_EXIT_INSN(),
3111 		},
3112 		INTERNAL,
3113 		{ },
3114 		{ { 0, 2 } },
3115 	},
3116 	{
3117 		"ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3118 		.u.insns_int = {
3119 			BPF_LD_IMM64(R0, 0xffffffff),
3120 			BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3121 			BPF_EXIT_INSN(),
3122 		},
3123 		INTERNAL,
3124 		{ },
3125 		{ { 0, 0xffffffff } },
3126 	},
3127 	{
3128 		"ALU64_AND_K: 3 & 2 = 2",
3129 		.u.insns_int = {
3130 			BPF_LD_IMM64(R0, 3),
3131 			BPF_ALU64_IMM(BPF_AND, R0, 2),
3132 			BPF_EXIT_INSN(),
3133 		},
3134 		INTERNAL,
3135 		{ },
3136 		{ { 0, 2 } },
3137 	},
3138 	{
3139 		"ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3140 		.u.insns_int = {
3141 			BPF_LD_IMM64(R0, 0xffffffff),
3142 			BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3143 			BPF_EXIT_INSN(),
3144 		},
3145 		INTERNAL,
3146 		{ },
3147 		{ { 0, 0xffffffff } },
3148 	},
3149 	{
3150 		"ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3151 		.u.insns_int = {
3152 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3153 			BPF_LD_IMM64(R3, 0x0000000000000000LL),
3154 			BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3155 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3156 			BPF_MOV32_IMM(R0, 2),
3157 			BPF_EXIT_INSN(),
3158 			BPF_MOV32_IMM(R0, 1),
3159 			BPF_EXIT_INSN(),
3160 		},
3161 		INTERNAL,
3162 		{ },
3163 		{ { 0, 0x1 } },
3164 	},
3165 	{
3166 		"ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3167 		.u.insns_int = {
3168 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3169 			BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3170 			BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3171 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3172 			BPF_MOV32_IMM(R0, 2),
3173 			BPF_EXIT_INSN(),
3174 			BPF_MOV32_IMM(R0, 1),
3175 			BPF_EXIT_INSN(),
3176 		},
3177 		INTERNAL,
3178 		{ },
3179 		{ { 0, 0x1 } },
3180 	},
3181 	{
3182 		"ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3183 		.u.insns_int = {
3184 			BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3185 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3186 			BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3187 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3188 			BPF_MOV32_IMM(R0, 2),
3189 			BPF_EXIT_INSN(),
3190 			BPF_MOV32_IMM(R0, 1),
3191 			BPF_EXIT_INSN(),
3192 		},
3193 		INTERNAL,
3194 		{ },
3195 		{ { 0, 0x1 } },
3196 	},
3197 	/* BPF_ALU | BPF_OR | BPF_X */
3198 	{
3199 		"ALU_OR_X: 1 | 2 = 3",
3200 		.u.insns_int = {
3201 			BPF_LD_IMM64(R0, 1),
3202 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
3203 			BPF_ALU32_REG(BPF_OR, R0, R1),
3204 			BPF_EXIT_INSN(),
3205 		},
3206 		INTERNAL,
3207 		{ },
3208 		{ { 0, 3 } },
3209 	},
3210 	{
3211 		"ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3212 		.u.insns_int = {
3213 			BPF_LD_IMM64(R0, 0),
3214 			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3215 			BPF_ALU32_REG(BPF_OR, R0, R1),
3216 			BPF_EXIT_INSN(),
3217 		},
3218 		INTERNAL,
3219 		{ },
3220 		{ { 0, 0xffffffff } },
3221 	},
3222 	{
3223 		"ALU64_OR_X: 1 | 2 = 3",
3224 		.u.insns_int = {
3225 			BPF_LD_IMM64(R0, 1),
3226 			BPF_ALU32_IMM(BPF_MOV, R1, 2),
3227 			BPF_ALU64_REG(BPF_OR, R0, R1),
3228 			BPF_EXIT_INSN(),
3229 		},
3230 		INTERNAL,
3231 		{ },
3232 		{ { 0, 3 } },
3233 	},
3234 	{
3235 		"ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3236 		.u.insns_int = {
3237 			BPF_LD_IMM64(R0, 0),
3238 			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3239 			BPF_ALU64_REG(BPF_OR, R0, R1),
3240 			BPF_EXIT_INSN(),
3241 		},
3242 		INTERNAL,
3243 		{ },
3244 		{ { 0, 0xffffffff } },
3245 	},
3246 	/* BPF_ALU | BPF_OR | BPF_K */
3247 	{
3248 		"ALU_OR_K: 1 | 2 = 3",
3249 		.u.insns_int = {
3250 			BPF_LD_IMM64(R0, 1),
3251 			BPF_ALU32_IMM(BPF_OR, R0, 2),
3252 			BPF_EXIT_INSN(),
3253 		},
3254 		INTERNAL,
3255 		{ },
3256 		{ { 0, 3 } },
3257 	},
3258 	{
3259 		"ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3260 		.u.insns_int = {
3261 			BPF_LD_IMM64(R0, 0),
3262 			BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3263 			BPF_EXIT_INSN(),
3264 		},
3265 		INTERNAL,
3266 		{ },
3267 		{ { 0, 0xffffffff } },
3268 	},
3269 	{
3270 		"ALU64_OR_K: 1 | 2 = 3",
3271 		.u.insns_int = {
3272 			BPF_LD_IMM64(R0, 1),
3273 			BPF_ALU64_IMM(BPF_OR, R0, 2),
3274 			BPF_EXIT_INSN(),
3275 		},
3276 		INTERNAL,
3277 		{ },
3278 		{ { 0, 3 } },
3279 	},
3280 	{
3281 		"ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3282 		.u.insns_int = {
3283 			BPF_LD_IMM64(R0, 0),
3284 			BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3285 			BPF_EXIT_INSN(),
3286 		},
3287 		INTERNAL,
3288 		{ },
3289 		{ { 0, 0xffffffff } },
3290 	},
3291 	{
3292 		"ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3293 		.u.insns_int = {
3294 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3295 			BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3296 			BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3297 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3298 			BPF_MOV32_IMM(R0, 2),
3299 			BPF_EXIT_INSN(),
3300 			BPF_MOV32_IMM(R0, 1),
3301 			BPF_EXIT_INSN(),
3302 		},
3303 		INTERNAL,
3304 		{ },
3305 		{ { 0, 0x1 } },
3306 	},
3307 	{
3308 		"ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3309 		.u.insns_int = {
3310 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3311 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3312 			BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3313 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3314 			BPF_MOV32_IMM(R0, 2),
3315 			BPF_EXIT_INSN(),
3316 			BPF_MOV32_IMM(R0, 1),
3317 			BPF_EXIT_INSN(),
3318 		},
3319 		INTERNAL,
3320 		{ },
3321 		{ { 0, 0x1 } },
3322 	},
3323 	{
3324 		"ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3325 		.u.insns_int = {
3326 			BPF_LD_IMM64(R2, 0x0000000000000000LL),
3327 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3328 			BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3329 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3330 			BPF_MOV32_IMM(R0, 2),
3331 			BPF_EXIT_INSN(),
3332 			BPF_MOV32_IMM(R0, 1),
3333 			BPF_EXIT_INSN(),
3334 		},
3335 		INTERNAL,
3336 		{ },
3337 		{ { 0, 0x1 } },
3338 	},
3339 	/* BPF_ALU | BPF_XOR | BPF_X */
3340 	{
3341 		"ALU_XOR_X: 5 ^ 6 = 3",
3342 		.u.insns_int = {
3343 			BPF_LD_IMM64(R0, 5),
3344 			BPF_ALU32_IMM(BPF_MOV, R1, 6),
3345 			BPF_ALU32_REG(BPF_XOR, R0, R1),
3346 			BPF_EXIT_INSN(),
3347 		},
3348 		INTERNAL,
3349 		{ },
3350 		{ { 0, 3 } },
3351 	},
3352 	{
3353 		"ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3354 		.u.insns_int = {
3355 			BPF_LD_IMM64(R0, 1),
3356 			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3357 			BPF_ALU32_REG(BPF_XOR, R0, R1),
3358 			BPF_EXIT_INSN(),
3359 		},
3360 		INTERNAL,
3361 		{ },
3362 		{ { 0, 0xfffffffe } },
3363 	},
3364 	{
3365 		"ALU64_XOR_X: 5 ^ 6 = 3",
3366 		.u.insns_int = {
3367 			BPF_LD_IMM64(R0, 5),
3368 			BPF_ALU32_IMM(BPF_MOV, R1, 6),
3369 			BPF_ALU64_REG(BPF_XOR, R0, R1),
3370 			BPF_EXIT_INSN(),
3371 		},
3372 		INTERNAL,
3373 		{ },
3374 		{ { 0, 3 } },
3375 	},
3376 	{
3377 		"ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3378 		.u.insns_int = {
3379 			BPF_LD_IMM64(R0, 1),
3380 			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3381 			BPF_ALU64_REG(BPF_XOR, R0, R1),
3382 			BPF_EXIT_INSN(),
3383 		},
3384 		INTERNAL,
3385 		{ },
3386 		{ { 0, 0xfffffffe } },
3387 	},
3388 	/* BPF_ALU | BPF_XOR | BPF_K */
3389 	{
3390 		"ALU_XOR_K: 5 ^ 6 = 3",
3391 		.u.insns_int = {
3392 			BPF_LD_IMM64(R0, 5),
3393 			BPF_ALU32_IMM(BPF_XOR, R0, 6),
3394 			BPF_EXIT_INSN(),
3395 		},
3396 		INTERNAL,
3397 		{ },
3398 		{ { 0, 3 } },
3399 	},
3400 	{
3401 		"ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3402 		.u.insns_int = {
3403 			BPF_LD_IMM64(R0, 1),
3404 			BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3405 			BPF_EXIT_INSN(),
3406 		},
3407 		INTERNAL,
3408 		{ },
3409 		{ { 0, 0xfffffffe } },
3410 	},
3411 	{
3412 		"ALU64_XOR_K: 5 ^ 6 = 3",
3413 		.u.insns_int = {
3414 			BPF_LD_IMM64(R0, 5),
3415 			BPF_ALU64_IMM(BPF_XOR, R0, 6),
3416 			BPF_EXIT_INSN(),
3417 		},
3418 		INTERNAL,
3419 		{ },
3420 		{ { 0, 3 } },
3421 	},
3422 	{
3423 		"ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3424 		.u.insns_int = {
3425 			BPF_LD_IMM64(R0, 1),
3426 			BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3427 			BPF_EXIT_INSN(),
3428 		},
3429 		INTERNAL,
3430 		{ },
3431 		{ { 0, 0xfffffffe } },
3432 	},
3433 	{
3434 		"ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3435 		.u.insns_int = {
3436 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3437 			BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3438 			BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3439 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3440 			BPF_MOV32_IMM(R0, 2),
3441 			BPF_EXIT_INSN(),
3442 			BPF_MOV32_IMM(R0, 1),
3443 			BPF_EXIT_INSN(),
3444 		},
3445 		INTERNAL,
3446 		{ },
3447 		{ { 0, 0x1 } },
3448 	},
3449 	{
3450 		"ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3451 		.u.insns_int = {
3452 			BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3453 			BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
3454 			BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3455 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3456 			BPF_MOV32_IMM(R0, 2),
3457 			BPF_EXIT_INSN(),
3458 			BPF_MOV32_IMM(R0, 1),
3459 			BPF_EXIT_INSN(),
3460 		},
3461 		INTERNAL,
3462 		{ },
3463 		{ { 0, 0x1 } },
3464 	},
3465 	{
3466 		"ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3467 		.u.insns_int = {
3468 			BPF_LD_IMM64(R2, 0x0000000000000000LL),
3469 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3470 			BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3471 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3472 			BPF_MOV32_IMM(R0, 2),
3473 			BPF_EXIT_INSN(),
3474 			BPF_MOV32_IMM(R0, 1),
3475 			BPF_EXIT_INSN(),
3476 		},
3477 		INTERNAL,
3478 		{ },
3479 		{ { 0, 0x1 } },
3480 	},
3481 	/* BPF_ALU | BPF_LSH | BPF_X */
3482 	{
3483 		"ALU_LSH_X: 1 << 1 = 2",
3484 		.u.insns_int = {
3485 			BPF_LD_IMM64(R0, 1),
3486 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
3487 			BPF_ALU32_REG(BPF_LSH, R0, R1),
3488 			BPF_EXIT_INSN(),
3489 		},
3490 		INTERNAL,
3491 		{ },
3492 		{ { 0, 2 } },
3493 	},
3494 	{
3495 		"ALU_LSH_X: 1 << 31 = 0x80000000",
3496 		.u.insns_int = {
3497 			BPF_LD_IMM64(R0, 1),
3498 			BPF_ALU32_IMM(BPF_MOV, R1, 31),
3499 			BPF_ALU32_REG(BPF_LSH, R0, R1),
3500 			BPF_EXIT_INSN(),
3501 		},
3502 		INTERNAL,
3503 		{ },
3504 		{ { 0, 0x80000000 } },
3505 	},
3506 	{
3507 		"ALU64_LSH_X: 1 << 1 = 2",
3508 		.u.insns_int = {
3509 			BPF_LD_IMM64(R0, 1),
3510 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
3511 			BPF_ALU64_REG(BPF_LSH, R0, R1),
3512 			BPF_EXIT_INSN(),
3513 		},
3514 		INTERNAL,
3515 		{ },
3516 		{ { 0, 2 } },
3517 	},
3518 	{
3519 		"ALU64_LSH_X: 1 << 31 = 0x80000000",
3520 		.u.insns_int = {
3521 			BPF_LD_IMM64(R0, 1),
3522 			BPF_ALU32_IMM(BPF_MOV, R1, 31),
3523 			BPF_ALU64_REG(BPF_LSH, R0, R1),
3524 			BPF_EXIT_INSN(),
3525 		},
3526 		INTERNAL,
3527 		{ },
3528 		{ { 0, 0x80000000 } },
3529 	},
3530 	/* BPF_ALU | BPF_LSH | BPF_K */
3531 	{
3532 		"ALU_LSH_K: 1 << 1 = 2",
3533 		.u.insns_int = {
3534 			BPF_LD_IMM64(R0, 1),
3535 			BPF_ALU32_IMM(BPF_LSH, R0, 1),
3536 			BPF_EXIT_INSN(),
3537 		},
3538 		INTERNAL,
3539 		{ },
3540 		{ { 0, 2 } },
3541 	},
3542 	{
3543 		"ALU_LSH_K: 1 << 31 = 0x80000000",
3544 		.u.insns_int = {
3545 			BPF_LD_IMM64(R0, 1),
3546 			BPF_ALU32_IMM(BPF_LSH, R0, 31),
3547 			BPF_EXIT_INSN(),
3548 		},
3549 		INTERNAL,
3550 		{ },
3551 		{ { 0, 0x80000000 } },
3552 	},
3553 	{
3554 		"ALU64_LSH_K: 1 << 1 = 2",
3555 		.u.insns_int = {
3556 			BPF_LD_IMM64(R0, 1),
3557 			BPF_ALU64_IMM(BPF_LSH, R0, 1),
3558 			BPF_EXIT_INSN(),
3559 		},
3560 		INTERNAL,
3561 		{ },
3562 		{ { 0, 2 } },
3563 	},
3564 	{
3565 		"ALU64_LSH_K: 1 << 31 = 0x80000000",
3566 		.u.insns_int = {
3567 			BPF_LD_IMM64(R0, 1),
3568 			BPF_ALU64_IMM(BPF_LSH, R0, 31),
3569 			BPF_EXIT_INSN(),
3570 		},
3571 		INTERNAL,
3572 		{ },
3573 		{ { 0, 0x80000000 } },
3574 	},
3575 	/* BPF_ALU | BPF_RSH | BPF_X */
3576 	{
3577 		"ALU_RSH_X: 2 >> 1 = 1",
3578 		.u.insns_int = {
3579 			BPF_LD_IMM64(R0, 2),
3580 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
3581 			BPF_ALU32_REG(BPF_RSH, R0, R1),
3582 			BPF_EXIT_INSN(),
3583 		},
3584 		INTERNAL,
3585 		{ },
3586 		{ { 0, 1 } },
3587 	},
3588 	{
3589 		"ALU_RSH_X: 0x80000000 >> 31 = 1",
3590 		.u.insns_int = {
3591 			BPF_LD_IMM64(R0, 0x80000000),
3592 			BPF_ALU32_IMM(BPF_MOV, R1, 31),
3593 			BPF_ALU32_REG(BPF_RSH, R0, R1),
3594 			BPF_EXIT_INSN(),
3595 		},
3596 		INTERNAL,
3597 		{ },
3598 		{ { 0, 1 } },
3599 	},
3600 	{
3601 		"ALU64_RSH_X: 2 >> 1 = 1",
3602 		.u.insns_int = {
3603 			BPF_LD_IMM64(R0, 2),
3604 			BPF_ALU32_IMM(BPF_MOV, R1, 1),
3605 			BPF_ALU64_REG(BPF_RSH, R0, R1),
3606 			BPF_EXIT_INSN(),
3607 		},
3608 		INTERNAL,
3609 		{ },
3610 		{ { 0, 1 } },
3611 	},
3612 	{
3613 		"ALU64_RSH_X: 0x80000000 >> 31 = 1",
3614 		.u.insns_int = {
3615 			BPF_LD_IMM64(R0, 0x80000000),
3616 			BPF_ALU32_IMM(BPF_MOV, R1, 31),
3617 			BPF_ALU64_REG(BPF_RSH, R0, R1),
3618 			BPF_EXIT_INSN(),
3619 		},
3620 		INTERNAL,
3621 		{ },
3622 		{ { 0, 1 } },
3623 	},
3624 	/* BPF_ALU | BPF_RSH | BPF_K */
3625 	{
3626 		"ALU_RSH_K: 2 >> 1 = 1",
3627 		.u.insns_int = {
3628 			BPF_LD_IMM64(R0, 2),
3629 			BPF_ALU32_IMM(BPF_RSH, R0, 1),
3630 			BPF_EXIT_INSN(),
3631 		},
3632 		INTERNAL,
3633 		{ },
3634 		{ { 0, 1 } },
3635 	},
3636 	{
3637 		"ALU_RSH_K: 0x80000000 >> 31 = 1",
3638 		.u.insns_int = {
3639 			BPF_LD_IMM64(R0, 0x80000000),
3640 			BPF_ALU32_IMM(BPF_RSH, R0, 31),
3641 			BPF_EXIT_INSN(),
3642 		},
3643 		INTERNAL,
3644 		{ },
3645 		{ { 0, 1 } },
3646 	},
3647 	{
3648 		"ALU64_RSH_K: 2 >> 1 = 1",
3649 		.u.insns_int = {
3650 			BPF_LD_IMM64(R0, 2),
3651 			BPF_ALU64_IMM(BPF_RSH, R0, 1),
3652 			BPF_EXIT_INSN(),
3653 		},
3654 		INTERNAL,
3655 		{ },
3656 		{ { 0, 1 } },
3657 	},
3658 	{
3659 		"ALU64_RSH_K: 0x80000000 >> 31 = 1",
3660 		.u.insns_int = {
3661 			BPF_LD_IMM64(R0, 0x80000000),
3662 			BPF_ALU64_IMM(BPF_RSH, R0, 31),
3663 			BPF_EXIT_INSN(),
3664 		},
3665 		INTERNAL,
3666 		{ },
3667 		{ { 0, 1 } },
3668 	},
3669 	/* BPF_ALU | BPF_ARSH | BPF_X */
3670 	{
3671 		"ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3672 		.u.insns_int = {
3673 			BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3674 			BPF_ALU32_IMM(BPF_MOV, R1, 40),
3675 			BPF_ALU64_REG(BPF_ARSH, R0, R1),
3676 			BPF_EXIT_INSN(),
3677 		},
3678 		INTERNAL,
3679 		{ },
3680 		{ { 0, 0xffff00ff } },
3681 	},
3682 	/* BPF_ALU | BPF_ARSH | BPF_K */
3683 	{
3684 		"ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3685 		.u.insns_int = {
3686 			BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3687 			BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3688 			BPF_EXIT_INSN(),
3689 		},
3690 		INTERNAL,
3691 		{ },
3692 		{ { 0, 0xffff00ff } },
3693 	},
3694 	/* BPF_ALU | BPF_NEG */
3695 	{
3696 		"ALU_NEG: -(3) = -3",
3697 		.u.insns_int = {
3698 			BPF_ALU32_IMM(BPF_MOV, R0, 3),
3699 			BPF_ALU32_IMM(BPF_NEG, R0, 0),
3700 			BPF_EXIT_INSN(),
3701 		},
3702 		INTERNAL,
3703 		{ },
3704 		{ { 0, -3 } },
3705 	},
3706 	{
3707 		"ALU_NEG: -(-3) = 3",
3708 		.u.insns_int = {
3709 			BPF_ALU32_IMM(BPF_MOV, R0, -3),
3710 			BPF_ALU32_IMM(BPF_NEG, R0, 0),
3711 			BPF_EXIT_INSN(),
3712 		},
3713 		INTERNAL,
3714 		{ },
3715 		{ { 0, 3 } },
3716 	},
3717 	{
3718 		"ALU64_NEG: -(3) = -3",
3719 		.u.insns_int = {
3720 			BPF_LD_IMM64(R0, 3),
3721 			BPF_ALU64_IMM(BPF_NEG, R0, 0),
3722 			BPF_EXIT_INSN(),
3723 		},
3724 		INTERNAL,
3725 		{ },
3726 		{ { 0, -3 } },
3727 	},
3728 	{
3729 		"ALU64_NEG: -(-3) = 3",
3730 		.u.insns_int = {
3731 			BPF_LD_IMM64(R0, -3),
3732 			BPF_ALU64_IMM(BPF_NEG, R0, 0),
3733 			BPF_EXIT_INSN(),
3734 		},
3735 		INTERNAL,
3736 		{ },
3737 		{ { 0, 3 } },
3738 	},
3739 	/* BPF_ALU | BPF_END | BPF_FROM_BE */
3740 	{
3741 		"ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
3742 		.u.insns_int = {
3743 			BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3744 			BPF_ENDIAN(BPF_FROM_BE, R0, 16),
3745 			BPF_EXIT_INSN(),
3746 		},
3747 		INTERNAL,
3748 		{ },
3749 		{ { 0,  cpu_to_be16(0xcdef) } },
3750 	},
3751 	{
3752 		"ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
3753 		.u.insns_int = {
3754 			BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3755 			BPF_ENDIAN(BPF_FROM_BE, R0, 32),
3756 			BPF_ALU64_REG(BPF_MOV, R1, R0),
3757 			BPF_ALU64_IMM(BPF_RSH, R1, 32),
3758 			BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
3759 			BPF_EXIT_INSN(),
3760 		},
3761 		INTERNAL,
3762 		{ },
3763 		{ { 0, cpu_to_be32(0x89abcdef) } },
3764 	},
3765 	{
3766 		"ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
3767 		.u.insns_int = {
3768 			BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3769 			BPF_ENDIAN(BPF_FROM_BE, R0, 64),
3770 			BPF_EXIT_INSN(),
3771 		},
3772 		INTERNAL,
3773 		{ },
3774 		{ { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
3775 	},
3776 	/* BPF_ALU | BPF_END | BPF_FROM_LE */
3777 	{
3778 		"ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
3779 		.u.insns_int = {
3780 			BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3781 			BPF_ENDIAN(BPF_FROM_LE, R0, 16),
3782 			BPF_EXIT_INSN(),
3783 		},
3784 		INTERNAL,
3785 		{ },
3786 		{ { 0, cpu_to_le16(0xcdef) } },
3787 	},
3788 	{
3789 		"ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
3790 		.u.insns_int = {
3791 			BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3792 			BPF_ENDIAN(BPF_FROM_LE, R0, 32),
3793 			BPF_ALU64_REG(BPF_MOV, R1, R0),
3794 			BPF_ALU64_IMM(BPF_RSH, R1, 32),
3795 			BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
3796 			BPF_EXIT_INSN(),
3797 		},
3798 		INTERNAL,
3799 		{ },
3800 		{ { 0, cpu_to_le32(0x89abcdef) } },
3801 	},
3802 	{
3803 		"ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
3804 		.u.insns_int = {
3805 			BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3806 			BPF_ENDIAN(BPF_FROM_LE, R0, 64),
3807 			BPF_EXIT_INSN(),
3808 		},
3809 		INTERNAL,
3810 		{ },
3811 		{ { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
3812 	},
3813 	/* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
3814 	{
3815 		"ST_MEM_B: Store/Load byte: max negative",
3816 		.u.insns_int = {
3817 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3818 			BPF_ST_MEM(BPF_B, R10, -40, 0xff),
3819 			BPF_LDX_MEM(BPF_B, R0, R10, -40),
3820 			BPF_EXIT_INSN(),
3821 		},
3822 		INTERNAL,
3823 		{ },
3824 		{ { 0, 0xff } },
3825 	},
3826 	{
3827 		"ST_MEM_B: Store/Load byte: max positive",
3828 		.u.insns_int = {
3829 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3830 			BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
3831 			BPF_LDX_MEM(BPF_H, R0, R10, -40),
3832 			BPF_EXIT_INSN(),
3833 		},
3834 		INTERNAL,
3835 		{ },
3836 		{ { 0, 0x7f } },
3837 	},
3838 	{
3839 		"STX_MEM_B: Store/Load byte: max negative",
3840 		.u.insns_int = {
3841 			BPF_LD_IMM64(R0, 0),
3842 			BPF_LD_IMM64(R1, 0xffLL),
3843 			BPF_STX_MEM(BPF_B, R10, R1, -40),
3844 			BPF_LDX_MEM(BPF_B, R0, R10, -40),
3845 			BPF_EXIT_INSN(),
3846 		},
3847 		INTERNAL,
3848 		{ },
3849 		{ { 0, 0xff } },
3850 	},
3851 	{
3852 		"ST_MEM_H: Store/Load half word: max negative",
3853 		.u.insns_int = {
3854 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3855 			BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
3856 			BPF_LDX_MEM(BPF_H, R0, R10, -40),
3857 			BPF_EXIT_INSN(),
3858 		},
3859 		INTERNAL,
3860 		{ },
3861 		{ { 0, 0xffff } },
3862 	},
3863 	{
3864 		"ST_MEM_H: Store/Load half word: max positive",
3865 		.u.insns_int = {
3866 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3867 			BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
3868 			BPF_LDX_MEM(BPF_H, R0, R10, -40),
3869 			BPF_EXIT_INSN(),
3870 		},
3871 		INTERNAL,
3872 		{ },
3873 		{ { 0, 0x7fff } },
3874 	},
3875 	{
3876 		"STX_MEM_H: Store/Load half word: max negative",
3877 		.u.insns_int = {
3878 			BPF_LD_IMM64(R0, 0),
3879 			BPF_LD_IMM64(R1, 0xffffLL),
3880 			BPF_STX_MEM(BPF_H, R10, R1, -40),
3881 			BPF_LDX_MEM(BPF_H, R0, R10, -40),
3882 			BPF_EXIT_INSN(),
3883 		},
3884 		INTERNAL,
3885 		{ },
3886 		{ { 0, 0xffff } },
3887 	},
3888 	{
3889 		"ST_MEM_W: Store/Load word: max negative",
3890 		.u.insns_int = {
3891 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3892 			BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
3893 			BPF_LDX_MEM(BPF_W, R0, R10, -40),
3894 			BPF_EXIT_INSN(),
3895 		},
3896 		INTERNAL,
3897 		{ },
3898 		{ { 0, 0xffffffff } },
3899 	},
3900 	{
3901 		"ST_MEM_W: Store/Load word: max positive",
3902 		.u.insns_int = {
3903 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3904 			BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
3905 			BPF_LDX_MEM(BPF_W, R0, R10, -40),
3906 			BPF_EXIT_INSN(),
3907 		},
3908 		INTERNAL,
3909 		{ },
3910 		{ { 0, 0x7fffffff } },
3911 	},
3912 	{
3913 		"STX_MEM_W: Store/Load word: max negative",
3914 		.u.insns_int = {
3915 			BPF_LD_IMM64(R0, 0),
3916 			BPF_LD_IMM64(R1, 0xffffffffLL),
3917 			BPF_STX_MEM(BPF_W, R10, R1, -40),
3918 			BPF_LDX_MEM(BPF_W, R0, R10, -40),
3919 			BPF_EXIT_INSN(),
3920 		},
3921 		INTERNAL,
3922 		{ },
3923 		{ { 0, 0xffffffff } },
3924 	},
3925 	{
3926 		"ST_MEM_DW: Store/Load double word: max negative",
3927 		.u.insns_int = {
3928 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3929 			BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3930 			BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3931 			BPF_EXIT_INSN(),
3932 		},
3933 		INTERNAL,
3934 		{ },
3935 		{ { 0, 0xffffffff } },
3936 	},
3937 	{
3938 		"ST_MEM_DW: Store/Load double word: max negative 2",
3939 		.u.insns_int = {
3940 			BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
3941 			BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3942 			BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3943 			BPF_LDX_MEM(BPF_DW, R2, R10, -40),
3944 			BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3945 			BPF_MOV32_IMM(R0, 2),
3946 			BPF_EXIT_INSN(),
3947 			BPF_MOV32_IMM(R0, 1),
3948 			BPF_EXIT_INSN(),
3949 		},
3950 		INTERNAL,
3951 		{ },
3952 		{ { 0, 0x1 } },
3953 	},
3954 	{
3955 		"ST_MEM_DW: Store/Load double word: max positive",
3956 		.u.insns_int = {
3957 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
3958 			BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
3959 			BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3960 			BPF_EXIT_INSN(),
3961 		},
3962 		INTERNAL,
3963 		{ },
3964 		{ { 0, 0x7fffffff } },
3965 	},
3966 	{
3967 		"STX_MEM_DW: Store/Load double word: max negative",
3968 		.u.insns_int = {
3969 			BPF_LD_IMM64(R0, 0),
3970 			BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3971 			BPF_STX_MEM(BPF_W, R10, R1, -40),
3972 			BPF_LDX_MEM(BPF_W, R0, R10, -40),
3973 			BPF_EXIT_INSN(),
3974 		},
3975 		INTERNAL,
3976 		{ },
3977 		{ { 0, 0xffffffff } },
3978 	},
3979 	/* BPF_STX | BPF_XADD | BPF_W/DW */
3980 	{
3981 		"STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
3982 		.u.insns_int = {
3983 			BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3984 			BPF_ST_MEM(BPF_W, R10, -40, 0x10),
3985 			BPF_STX_XADD(BPF_W, R10, R0, -40),
3986 			BPF_LDX_MEM(BPF_W, R0, R10, -40),
3987 			BPF_EXIT_INSN(),
3988 		},
3989 		INTERNAL,
3990 		{ },
3991 		{ { 0, 0x22 } },
3992 	},
3993 	{
3994 		"STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
3995 		.u.insns_int = {
3996 			BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3997 			BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
3998 			BPF_STX_XADD(BPF_DW, R10, R0, -40),
3999 			BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4000 			BPF_EXIT_INSN(),
4001 		},
4002 		INTERNAL,
4003 		{ },
4004 		{ { 0, 0x22 } },
4005 	},
4006 	/* BPF_JMP | BPF_EXIT */
4007 	{
4008 		"JMP_EXIT",
4009 		.u.insns_int = {
4010 			BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4011 			BPF_EXIT_INSN(),
4012 			BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4013 		},
4014 		INTERNAL,
4015 		{ },
4016 		{ { 0, 0x4711 } },
4017 	},
4018 	/* BPF_JMP | BPF_JA */
4019 	{
4020 		"JMP_JA: Unconditional jump: if (true) return 1",
4021 		.u.insns_int = {
4022 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4023 			BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4024 			BPF_EXIT_INSN(),
4025 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4026 			BPF_EXIT_INSN(),
4027 		},
4028 		INTERNAL,
4029 		{ },
4030 		{ { 0, 1 } },
4031 	},
4032 	/* BPF_JMP | BPF_JSGT | BPF_K */
4033 	{
4034 		"JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4035 		.u.insns_int = {
4036 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4037 			BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4038 			BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4039 			BPF_EXIT_INSN(),
4040 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4041 			BPF_EXIT_INSN(),
4042 		},
4043 		INTERNAL,
4044 		{ },
4045 		{ { 0, 1 } },
4046 	},
4047 	{
4048 		"JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4049 		.u.insns_int = {
4050 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4051 			BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4052 			BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4053 			BPF_EXIT_INSN(),
4054 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4055 			BPF_EXIT_INSN(),
4056 		},
4057 		INTERNAL,
4058 		{ },
4059 		{ { 0, 1 } },
4060 	},
4061 	/* BPF_JMP | BPF_JSGE | BPF_K */
4062 	{
4063 		"JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4064 		.u.insns_int = {
4065 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4066 			BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4067 			BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4068 			BPF_EXIT_INSN(),
4069 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4070 			BPF_EXIT_INSN(),
4071 		},
4072 		INTERNAL,
4073 		{ },
4074 		{ { 0, 1 } },
4075 	},
4076 	{
4077 		"JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4078 		.u.insns_int = {
4079 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4080 			BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4081 			BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4082 			BPF_EXIT_INSN(),
4083 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4084 			BPF_EXIT_INSN(),
4085 		},
4086 		INTERNAL,
4087 		{ },
4088 		{ { 0, 1 } },
4089 	},
4090 	/* BPF_JMP | BPF_JGT | BPF_K */
4091 	{
4092 		"JMP_JGT_K: if (3 > 2) return 1",
4093 		.u.insns_int = {
4094 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4095 			BPF_LD_IMM64(R1, 3),
4096 			BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4097 			BPF_EXIT_INSN(),
4098 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4099 			BPF_EXIT_INSN(),
4100 		},
4101 		INTERNAL,
4102 		{ },
4103 		{ { 0, 1 } },
4104 	},
4105 	/* BPF_JMP | BPF_JGE | BPF_K */
4106 	{
4107 		"JMP_JGE_K: if (3 >= 2) return 1",
4108 		.u.insns_int = {
4109 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4110 			BPF_LD_IMM64(R1, 3),
4111 			BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4112 			BPF_EXIT_INSN(),
4113 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4114 			BPF_EXIT_INSN(),
4115 		},
4116 		INTERNAL,
4117 		{ },
4118 		{ { 0, 1 } },
4119 	},
4120 	/* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4121 	{
4122 		"JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4123 		.u.insns_int = {
4124 			BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4125 			BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4126 			BPF_EXIT_INSN(),
4127 			BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4128 			BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4129 			BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4130 			BPF_EXIT_INSN(),
4131 		},
4132 		INTERNAL,
4133 		{ },
4134 		{ { 0, 1 } },
4135 	},
4136 	{
4137 		"JMP_JGE_K: if (3 >= 3) return 1",
4138 		.u.insns_int = {
4139 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4140 			BPF_LD_IMM64(R1, 3),
4141 			BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4142 			BPF_EXIT_INSN(),
4143 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4144 			BPF_EXIT_INSN(),
4145 		},
4146 		INTERNAL,
4147 		{ },
4148 		{ { 0, 1 } },
4149 	},
4150 	/* BPF_JMP | BPF_JNE | BPF_K */
4151 	{
4152 		"JMP_JNE_K: if (3 != 2) return 1",
4153 		.u.insns_int = {
4154 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4155 			BPF_LD_IMM64(R1, 3),
4156 			BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4157 			BPF_EXIT_INSN(),
4158 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4159 			BPF_EXIT_INSN(),
4160 		},
4161 		INTERNAL,
4162 		{ },
4163 		{ { 0, 1 } },
4164 	},
4165 	/* BPF_JMP | BPF_JEQ | BPF_K */
4166 	{
4167 		"JMP_JEQ_K: if (3 == 3) return 1",
4168 		.u.insns_int = {
4169 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4170 			BPF_LD_IMM64(R1, 3),
4171 			BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4172 			BPF_EXIT_INSN(),
4173 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4174 			BPF_EXIT_INSN(),
4175 		},
4176 		INTERNAL,
4177 		{ },
4178 		{ { 0, 1 } },
4179 	},
4180 	/* BPF_JMP | BPF_JSET | BPF_K */
4181 	{
4182 		"JMP_JSET_K: if (0x3 & 0x2) return 1",
4183 		.u.insns_int = {
4184 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4185 			BPF_LD_IMM64(R1, 3),
4186 			BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4187 			BPF_EXIT_INSN(),
4188 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4189 			BPF_EXIT_INSN(),
4190 		},
4191 		INTERNAL,
4192 		{ },
4193 		{ { 0, 1 } },
4194 	},
4195 	{
4196 		"JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4197 		.u.insns_int = {
4198 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4199 			BPF_LD_IMM64(R1, 3),
4200 			BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1),
4201 			BPF_EXIT_INSN(),
4202 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4203 			BPF_EXIT_INSN(),
4204 		},
4205 		INTERNAL,
4206 		{ },
4207 		{ { 0, 1 } },
4208 	},
4209 	/* BPF_JMP | BPF_JSGT | BPF_X */
4210 	{
4211 		"JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4212 		.u.insns_int = {
4213 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4214 			BPF_LD_IMM64(R1, -1),
4215 			BPF_LD_IMM64(R2, -2),
4216 			BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4217 			BPF_EXIT_INSN(),
4218 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4219 			BPF_EXIT_INSN(),
4220 		},
4221 		INTERNAL,
4222 		{ },
4223 		{ { 0, 1 } },
4224 	},
4225 	{
4226 		"JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4227 		.u.insns_int = {
4228 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4229 			BPF_LD_IMM64(R1, -1),
4230 			BPF_LD_IMM64(R2, -1),
4231 			BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4232 			BPF_EXIT_INSN(),
4233 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4234 			BPF_EXIT_INSN(),
4235 		},
4236 		INTERNAL,
4237 		{ },
4238 		{ { 0, 1 } },
4239 	},
4240 	/* BPF_JMP | BPF_JSGE | BPF_X */
4241 	{
4242 		"JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4243 		.u.insns_int = {
4244 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4245 			BPF_LD_IMM64(R1, -1),
4246 			BPF_LD_IMM64(R2, -2),
4247 			BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4248 			BPF_EXIT_INSN(),
4249 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4250 			BPF_EXIT_INSN(),
4251 		},
4252 		INTERNAL,
4253 		{ },
4254 		{ { 0, 1 } },
4255 	},
4256 	{
4257 		"JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4258 		.u.insns_int = {
4259 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4260 			BPF_LD_IMM64(R1, -1),
4261 			BPF_LD_IMM64(R2, -1),
4262 			BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4263 			BPF_EXIT_INSN(),
4264 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4265 			BPF_EXIT_INSN(),
4266 		},
4267 		INTERNAL,
4268 		{ },
4269 		{ { 0, 1 } },
4270 	},
4271 	/* BPF_JMP | BPF_JGT | BPF_X */
4272 	{
4273 		"JMP_JGT_X: if (3 > 2) return 1",
4274 		.u.insns_int = {
4275 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4276 			BPF_LD_IMM64(R1, 3),
4277 			BPF_LD_IMM64(R2, 2),
4278 			BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4279 			BPF_EXIT_INSN(),
4280 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4281 			BPF_EXIT_INSN(),
4282 		},
4283 		INTERNAL,
4284 		{ },
4285 		{ { 0, 1 } },
4286 	},
4287 	/* BPF_JMP | BPF_JGE | BPF_X */
4288 	{
4289 		"JMP_JGE_X: if (3 >= 2) return 1",
4290 		.u.insns_int = {
4291 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4292 			BPF_LD_IMM64(R1, 3),
4293 			BPF_LD_IMM64(R2, 2),
4294 			BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4295 			BPF_EXIT_INSN(),
4296 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4297 			BPF_EXIT_INSN(),
4298 		},
4299 		INTERNAL,
4300 		{ },
4301 		{ { 0, 1 } },
4302 	},
4303 	{
4304 		"JMP_JGE_X: if (3 >= 3) return 1",
4305 		.u.insns_int = {
4306 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4307 			BPF_LD_IMM64(R1, 3),
4308 			BPF_LD_IMM64(R2, 3),
4309 			BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4310 			BPF_EXIT_INSN(),
4311 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4312 			BPF_EXIT_INSN(),
4313 		},
4314 		INTERNAL,
4315 		{ },
4316 		{ { 0, 1 } },
4317 	},
4318 	/* BPF_JMP | BPF_JNE | BPF_X */
4319 	{
4320 		"JMP_JNE_X: if (3 != 2) return 1",
4321 		.u.insns_int = {
4322 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4323 			BPF_LD_IMM64(R1, 3),
4324 			BPF_LD_IMM64(R2, 2),
4325 			BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4326 			BPF_EXIT_INSN(),
4327 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4328 			BPF_EXIT_INSN(),
4329 		},
4330 		INTERNAL,
4331 		{ },
4332 		{ { 0, 1 } },
4333 	},
4334 	/* BPF_JMP | BPF_JEQ | BPF_X */
4335 	{
4336 		"JMP_JEQ_X: if (3 == 3) return 1",
4337 		.u.insns_int = {
4338 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4339 			BPF_LD_IMM64(R1, 3),
4340 			BPF_LD_IMM64(R2, 3),
4341 			BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4342 			BPF_EXIT_INSN(),
4343 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4344 			BPF_EXIT_INSN(),
4345 		},
4346 		INTERNAL,
4347 		{ },
4348 		{ { 0, 1 } },
4349 	},
4350 	/* BPF_JMP | BPF_JSET | BPF_X */
4351 	{
4352 		"JMP_JSET_X: if (0x3 & 0x2) return 1",
4353 		.u.insns_int = {
4354 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4355 			BPF_LD_IMM64(R1, 3),
4356 			BPF_LD_IMM64(R2, 2),
4357 			BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4358 			BPF_EXIT_INSN(),
4359 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4360 			BPF_EXIT_INSN(),
4361 		},
4362 		INTERNAL,
4363 		{ },
4364 		{ { 0, 1 } },
4365 	},
4366 	{
4367 		"JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
4368 		.u.insns_int = {
4369 			BPF_ALU32_IMM(BPF_MOV, R0, 0),
4370 			BPF_LD_IMM64(R1, 3),
4371 			BPF_LD_IMM64(R2, 0xffffffff),
4372 			BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4373 			BPF_EXIT_INSN(),
4374 			BPF_ALU32_IMM(BPF_MOV, R0, 1),
4375 			BPF_EXIT_INSN(),
4376 		},
4377 		INTERNAL,
4378 		{ },
4379 		{ { 0, 1 } },
4380 	},
4381 	{
4382 		"JMP_JA: Jump, gap, jump, ...",
4383 		{ },
4384 		CLASSIC | FLAG_NO_DATA,
4385 		{ },
4386 		{ { 0, 0xababcbac } },
4387 		.fill_helper = bpf_fill_ja,
4388 	},
4389 	{	/* Mainly checking JIT here. */
4390 		"BPF_MAXINSNS: Maximum possible literals",
4391 		{ },
4392 		CLASSIC | FLAG_NO_DATA,
4393 		{ },
4394 		{ { 0, 0xffffffff } },
4395 		.fill_helper = bpf_fill_maxinsns1,
4396 	},
4397 	{	/* Mainly checking JIT here. */
4398 		"BPF_MAXINSNS: Single literal",
4399 		{ },
4400 		CLASSIC | FLAG_NO_DATA,
4401 		{ },
4402 		{ { 0, 0xfefefefe } },
4403 		.fill_helper = bpf_fill_maxinsns2,
4404 	},
4405 	{	/* Mainly checking JIT here. */
4406 		"BPF_MAXINSNS: Run/add until end",
4407 		{ },
4408 		CLASSIC | FLAG_NO_DATA,
4409 		{ },
4410 		{ { 0, 0x947bf368 } },
4411 		.fill_helper = bpf_fill_maxinsns3,
4412 	},
4413 	{
4414 		"BPF_MAXINSNS: Too many instructions",
4415 		{ },
4416 		CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4417 		{ },
4418 		{ },
4419 		.fill_helper = bpf_fill_maxinsns4,
4420 	},
4421 	{	/* Mainly checking JIT here. */
4422 		"BPF_MAXINSNS: Very long jump",
4423 		{ },
4424 		CLASSIC | FLAG_NO_DATA,
4425 		{ },
4426 		{ { 0, 0xabababab } },
4427 		.fill_helper = bpf_fill_maxinsns5,
4428 	},
4429 	{	/* Mainly checking JIT here. */
4430 		"BPF_MAXINSNS: Ctx heavy transformations",
4431 		{ },
4432 		CLASSIC,
4433 		{ },
4434 		{
4435 			{  1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
4436 			{ 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
4437 		},
4438 		.fill_helper = bpf_fill_maxinsns6,
4439 	},
4440 	{	/* Mainly checking JIT here. */
4441 		"BPF_MAXINSNS: Call heavy transformations",
4442 		{ },
4443 		CLASSIC | FLAG_NO_DATA,
4444 		{ },
4445 		{ { 1, 0 }, { 10, 0 } },
4446 		.fill_helper = bpf_fill_maxinsns7,
4447 	},
4448 	{	/* Mainly checking JIT here. */
4449 		"BPF_MAXINSNS: Jump heavy test",
4450 		{ },
4451 		CLASSIC | FLAG_NO_DATA,
4452 		{ },
4453 		{ { 0, 0xffffffff } },
4454 		.fill_helper = bpf_fill_maxinsns8,
4455 	},
4456 	{	/* Mainly checking JIT here. */
4457 		"BPF_MAXINSNS: Very long jump backwards",
4458 		{ },
4459 		INTERNAL | FLAG_NO_DATA,
4460 		{ },
4461 		{ { 0, 0xcbababab } },
4462 		.fill_helper = bpf_fill_maxinsns9,
4463 	},
4464 	{	/* Mainly checking JIT here. */
4465 		"BPF_MAXINSNS: Edge hopping nuthouse",
4466 		{ },
4467 		INTERNAL | FLAG_NO_DATA,
4468 		{ },
4469 		{ { 0, 0xabababac } },
4470 		.fill_helper = bpf_fill_maxinsns10,
4471 	},
4472 	{
4473 		"BPF_MAXINSNS: Jump, gap, jump, ...",
4474 		{ },
4475 		CLASSIC | FLAG_NO_DATA,
4476 		{ },
4477 		{ { 0, 0xababcbac } },
4478 		.fill_helper = bpf_fill_maxinsns11,
4479 	},
4480 	{
4481 		"BPF_MAXINSNS: ld_abs+get_processor_id",
4482 		{ },
4483 		CLASSIC,
4484 		{ },
4485 		{ { 1, 0xbee } },
4486 		.fill_helper = bpf_fill_ld_abs_get_processor_id,
4487 	},
4488 	{
4489 		"BPF_MAXINSNS: ld_abs+vlan_push/pop",
4490 		{ },
4491 		INTERNAL,
4492 		{ 0x34 },
4493 		{ { 1, 0xbef } },
4494 		.fill_helper = bpf_fill_ld_abs_vlan_push_pop,
4495 	},
4496 	/*
4497 	 * LD_IND / LD_ABS on fragmented SKBs
4498 	 */
4499 	{
4500 		"LD_IND byte frag",
4501 		.u.insns = {
4502 			BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4503 			BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
4504 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4505 		},
4506 		CLASSIC | FLAG_SKB_FRAG,
4507 		{ },
4508 		{ {0x40, 0x42} },
4509 		.frag_data = {
4510 			0x42, 0x00, 0x00, 0x00,
4511 			0x43, 0x44, 0x00, 0x00,
4512 			0x21, 0x07, 0x19, 0x83,
4513 		},
4514 	},
4515 	{
4516 		"LD_IND halfword frag",
4517 		.u.insns = {
4518 			BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4519 			BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
4520 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4521 		},
4522 		CLASSIC | FLAG_SKB_FRAG,
4523 		{ },
4524 		{ {0x40, 0x4344} },
4525 		.frag_data = {
4526 			0x42, 0x00, 0x00, 0x00,
4527 			0x43, 0x44, 0x00, 0x00,
4528 			0x21, 0x07, 0x19, 0x83,
4529 		},
4530 	},
4531 	{
4532 		"LD_IND word frag",
4533 		.u.insns = {
4534 			BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4535 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
4536 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4537 		},
4538 		CLASSIC | FLAG_SKB_FRAG,
4539 		{ },
4540 		{ {0x40, 0x21071983} },
4541 		.frag_data = {
4542 			0x42, 0x00, 0x00, 0x00,
4543 			0x43, 0x44, 0x00, 0x00,
4544 			0x21, 0x07, 0x19, 0x83,
4545 		},
4546 	},
4547 	{
4548 		"LD_IND halfword mixed head/frag",
4549 		.u.insns = {
4550 			BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4551 			BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
4552 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4553 		},
4554 		CLASSIC | FLAG_SKB_FRAG,
4555 		{ [0x3e] = 0x25, [0x3f] = 0x05, },
4556 		{ {0x40, 0x0519} },
4557 		.frag_data = { 0x19, 0x82 },
4558 	},
4559 	{
4560 		"LD_IND word mixed head/frag",
4561 		.u.insns = {
4562 			BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4563 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
4564 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4565 		},
4566 		CLASSIC | FLAG_SKB_FRAG,
4567 		{ [0x3e] = 0x25, [0x3f] = 0x05, },
4568 		{ {0x40, 0x25051982} },
4569 		.frag_data = { 0x19, 0x82 },
4570 	},
4571 	{
4572 		"LD_ABS byte frag",
4573 		.u.insns = {
4574 			BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
4575 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4576 		},
4577 		CLASSIC | FLAG_SKB_FRAG,
4578 		{ },
4579 		{ {0x40, 0x42} },
4580 		.frag_data = {
4581 			0x42, 0x00, 0x00, 0x00,
4582 			0x43, 0x44, 0x00, 0x00,
4583 			0x21, 0x07, 0x19, 0x83,
4584 		},
4585 	},
4586 	{
4587 		"LD_ABS halfword frag",
4588 		.u.insns = {
4589 			BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
4590 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4591 		},
4592 		CLASSIC | FLAG_SKB_FRAG,
4593 		{ },
4594 		{ {0x40, 0x4344} },
4595 		.frag_data = {
4596 			0x42, 0x00, 0x00, 0x00,
4597 			0x43, 0x44, 0x00, 0x00,
4598 			0x21, 0x07, 0x19, 0x83,
4599 		},
4600 	},
4601 	{
4602 		"LD_ABS word frag",
4603 		.u.insns = {
4604 			BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
4605 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4606 		},
4607 		CLASSIC | FLAG_SKB_FRAG,
4608 		{ },
4609 		{ {0x40, 0x21071983} },
4610 		.frag_data = {
4611 			0x42, 0x00, 0x00, 0x00,
4612 			0x43, 0x44, 0x00, 0x00,
4613 			0x21, 0x07, 0x19, 0x83,
4614 		},
4615 	},
4616 	{
4617 		"LD_ABS halfword mixed head/frag",
4618 		.u.insns = {
4619 			BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
4620 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4621 		},
4622 		CLASSIC | FLAG_SKB_FRAG,
4623 		{ [0x3e] = 0x25, [0x3f] = 0x05, },
4624 		{ {0x40, 0x0519} },
4625 		.frag_data = { 0x19, 0x82 },
4626 	},
4627 	{
4628 		"LD_ABS word mixed head/frag",
4629 		.u.insns = {
4630 			BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
4631 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4632 		},
4633 		CLASSIC | FLAG_SKB_FRAG,
4634 		{ [0x3e] = 0x25, [0x3f] = 0x05, },
4635 		{ {0x40, 0x25051982} },
4636 		.frag_data = { 0x19, 0x82 },
4637 	},
4638 	/*
4639 	 * LD_IND / LD_ABS on non fragmented SKBs
4640 	 */
4641 	{
4642 		/*
4643 		 * this tests that the JIT/interpreter correctly resets X
4644 		 * before using it in an LD_IND instruction.
4645 		 */
4646 		"LD_IND byte default X",
4647 		.u.insns = {
4648 			BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
4649 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4650 		},
4651 		CLASSIC,
4652 		{ [0x1] = 0x42 },
4653 		{ {0x40, 0x42 } },
4654 	},
4655 	{
4656 		"LD_IND byte positive offset",
4657 		.u.insns = {
4658 			BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
4659 			BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
4660 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4661 		},
4662 		CLASSIC,
4663 		{ [0x3c] = 0x25, [0x3d] = 0x05,  [0x3e] = 0x19, [0x3f] = 0x82 },
4664 		{ {0x40, 0x82 } },
4665 	},
4666 	{
4667 		"LD_IND byte negative offset",
4668 		.u.insns = {
4669 			BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
4670 			BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
4671 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4672 		},
4673 		CLASSIC,
4674 		{ [0x3c] = 0x25, [0x3d] = 0x05,  [0x3e] = 0x19, [0x3f] = 0x82 },
4675 		{ {0x40, 0x05 } },
4676 	},
4677 	{
4678 		"LD_IND halfword positive offset",
4679 		.u.insns = {
4680 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4681 			BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
4682 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4683 		},
4684 		CLASSIC,
4685 		{
4686 			[0x1c] = 0xaa, [0x1d] = 0x55,
4687 			[0x1e] = 0xbb, [0x1f] = 0x66,
4688 			[0x20] = 0xcc, [0x21] = 0x77,
4689 			[0x22] = 0xdd, [0x23] = 0x88,
4690 		},
4691 		{ {0x40, 0xdd88 } },
4692 	},
4693 	{
4694 		"LD_IND halfword negative offset",
4695 		.u.insns = {
4696 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4697 			BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
4698 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4699 		},
4700 		CLASSIC,
4701 		{
4702 			[0x1c] = 0xaa, [0x1d] = 0x55,
4703 			[0x1e] = 0xbb, [0x1f] = 0x66,
4704 			[0x20] = 0xcc, [0x21] = 0x77,
4705 			[0x22] = 0xdd, [0x23] = 0x88,
4706 		},
4707 		{ {0x40, 0xbb66 } },
4708 	},
4709 	{
4710 		"LD_IND halfword unaligned",
4711 		.u.insns = {
4712 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4713 			BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
4714 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4715 		},
4716 		CLASSIC,
4717 		{
4718 			[0x1c] = 0xaa, [0x1d] = 0x55,
4719 			[0x1e] = 0xbb, [0x1f] = 0x66,
4720 			[0x20] = 0xcc, [0x21] = 0x77,
4721 			[0x22] = 0xdd, [0x23] = 0x88,
4722 		},
4723 		{ {0x40, 0x66cc } },
4724 	},
4725 	{
4726 		"LD_IND word positive offset",
4727 		.u.insns = {
4728 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4729 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
4730 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4731 		},
4732 		CLASSIC,
4733 		{
4734 			[0x1c] = 0xaa, [0x1d] = 0x55,
4735 			[0x1e] = 0xbb, [0x1f] = 0x66,
4736 			[0x20] = 0xcc, [0x21] = 0x77,
4737 			[0x22] = 0xdd, [0x23] = 0x88,
4738 			[0x24] = 0xee, [0x25] = 0x99,
4739 			[0x26] = 0xff, [0x27] = 0xaa,
4740 		},
4741 		{ {0x40, 0xee99ffaa } },
4742 	},
4743 	{
4744 		"LD_IND word negative offset",
4745 		.u.insns = {
4746 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4747 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
4748 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4749 		},
4750 		CLASSIC,
4751 		{
4752 			[0x1c] = 0xaa, [0x1d] = 0x55,
4753 			[0x1e] = 0xbb, [0x1f] = 0x66,
4754 			[0x20] = 0xcc, [0x21] = 0x77,
4755 			[0x22] = 0xdd, [0x23] = 0x88,
4756 			[0x24] = 0xee, [0x25] = 0x99,
4757 			[0x26] = 0xff, [0x27] = 0xaa,
4758 		},
4759 		{ {0x40, 0xaa55bb66 } },
4760 	},
4761 	{
4762 		"LD_IND word unaligned (addr & 3 == 2)",
4763 		.u.insns = {
4764 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4765 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
4766 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4767 		},
4768 		CLASSIC,
4769 		{
4770 			[0x1c] = 0xaa, [0x1d] = 0x55,
4771 			[0x1e] = 0xbb, [0x1f] = 0x66,
4772 			[0x20] = 0xcc, [0x21] = 0x77,
4773 			[0x22] = 0xdd, [0x23] = 0x88,
4774 			[0x24] = 0xee, [0x25] = 0x99,
4775 			[0x26] = 0xff, [0x27] = 0xaa,
4776 		},
4777 		{ {0x40, 0xbb66cc77 } },
4778 	},
4779 	{
4780 		"LD_IND word unaligned (addr & 3 == 1)",
4781 		.u.insns = {
4782 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4783 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
4784 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4785 		},
4786 		CLASSIC,
4787 		{
4788 			[0x1c] = 0xaa, [0x1d] = 0x55,
4789 			[0x1e] = 0xbb, [0x1f] = 0x66,
4790 			[0x20] = 0xcc, [0x21] = 0x77,
4791 			[0x22] = 0xdd, [0x23] = 0x88,
4792 			[0x24] = 0xee, [0x25] = 0x99,
4793 			[0x26] = 0xff, [0x27] = 0xaa,
4794 		},
4795 		{ {0x40, 0x55bb66cc } },
4796 	},
4797 	{
4798 		"LD_IND word unaligned (addr & 3 == 3)",
4799 		.u.insns = {
4800 			BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4801 			BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
4802 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4803 		},
4804 		CLASSIC,
4805 		{
4806 			[0x1c] = 0xaa, [0x1d] = 0x55,
4807 			[0x1e] = 0xbb, [0x1f] = 0x66,
4808 			[0x20] = 0xcc, [0x21] = 0x77,
4809 			[0x22] = 0xdd, [0x23] = 0x88,
4810 			[0x24] = 0xee, [0x25] = 0x99,
4811 			[0x26] = 0xff, [0x27] = 0xaa,
4812 		},
4813 		{ {0x40, 0x66cc77dd } },
4814 	},
4815 	{
4816 		"LD_ABS byte",
4817 		.u.insns = {
4818 			BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
4819 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4820 		},
4821 		CLASSIC,
4822 		{
4823 			[0x1c] = 0xaa, [0x1d] = 0x55,
4824 			[0x1e] = 0xbb, [0x1f] = 0x66,
4825 			[0x20] = 0xcc, [0x21] = 0x77,
4826 			[0x22] = 0xdd, [0x23] = 0x88,
4827 			[0x24] = 0xee, [0x25] = 0x99,
4828 			[0x26] = 0xff, [0x27] = 0xaa,
4829 		},
4830 		{ {0x40, 0xcc } },
4831 	},
4832 	{
4833 		"LD_ABS halfword",
4834 		.u.insns = {
4835 			BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
4836 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4837 		},
4838 		CLASSIC,
4839 		{
4840 			[0x1c] = 0xaa, [0x1d] = 0x55,
4841 			[0x1e] = 0xbb, [0x1f] = 0x66,
4842 			[0x20] = 0xcc, [0x21] = 0x77,
4843 			[0x22] = 0xdd, [0x23] = 0x88,
4844 			[0x24] = 0xee, [0x25] = 0x99,
4845 			[0x26] = 0xff, [0x27] = 0xaa,
4846 		},
4847 		{ {0x40, 0xdd88 } },
4848 	},
4849 	{
4850 		"LD_ABS halfword unaligned",
4851 		.u.insns = {
4852 			BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
4853 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4854 		},
4855 		CLASSIC,
4856 		{
4857 			[0x1c] = 0xaa, [0x1d] = 0x55,
4858 			[0x1e] = 0xbb, [0x1f] = 0x66,
4859 			[0x20] = 0xcc, [0x21] = 0x77,
4860 			[0x22] = 0xdd, [0x23] = 0x88,
4861 			[0x24] = 0xee, [0x25] = 0x99,
4862 			[0x26] = 0xff, [0x27] = 0xaa,
4863 		},
4864 		{ {0x40, 0x99ff } },
4865 	},
4866 	{
4867 		"LD_ABS word",
4868 		.u.insns = {
4869 			BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
4870 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4871 		},
4872 		CLASSIC,
4873 		{
4874 			[0x1c] = 0xaa, [0x1d] = 0x55,
4875 			[0x1e] = 0xbb, [0x1f] = 0x66,
4876 			[0x20] = 0xcc, [0x21] = 0x77,
4877 			[0x22] = 0xdd, [0x23] = 0x88,
4878 			[0x24] = 0xee, [0x25] = 0x99,
4879 			[0x26] = 0xff, [0x27] = 0xaa,
4880 		},
4881 		{ {0x40, 0xaa55bb66 } },
4882 	},
4883 	{
4884 		"LD_ABS word unaligned (addr & 3 == 2)",
4885 		.u.insns = {
4886 			BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
4887 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4888 		},
4889 		CLASSIC,
4890 		{
4891 			[0x1c] = 0xaa, [0x1d] = 0x55,
4892 			[0x1e] = 0xbb, [0x1f] = 0x66,
4893 			[0x20] = 0xcc, [0x21] = 0x77,
4894 			[0x22] = 0xdd, [0x23] = 0x88,
4895 			[0x24] = 0xee, [0x25] = 0x99,
4896 			[0x26] = 0xff, [0x27] = 0xaa,
4897 		},
4898 		{ {0x40, 0xdd88ee99 } },
4899 	},
4900 	{
4901 		"LD_ABS word unaligned (addr & 3 == 1)",
4902 		.u.insns = {
4903 			BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
4904 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4905 		},
4906 		CLASSIC,
4907 		{
4908 			[0x1c] = 0xaa, [0x1d] = 0x55,
4909 			[0x1e] = 0xbb, [0x1f] = 0x66,
4910 			[0x20] = 0xcc, [0x21] = 0x77,
4911 			[0x22] = 0xdd, [0x23] = 0x88,
4912 			[0x24] = 0xee, [0x25] = 0x99,
4913 			[0x26] = 0xff, [0x27] = 0xaa,
4914 		},
4915 		{ {0x40, 0x77dd88ee } },
4916 	},
4917 	{
4918 		"LD_ABS word unaligned (addr & 3 == 3)",
4919 		.u.insns = {
4920 			BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
4921 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4922 		},
4923 		CLASSIC,
4924 		{
4925 			[0x1c] = 0xaa, [0x1d] = 0x55,
4926 			[0x1e] = 0xbb, [0x1f] = 0x66,
4927 			[0x20] = 0xcc, [0x21] = 0x77,
4928 			[0x22] = 0xdd, [0x23] = 0x88,
4929 			[0x24] = 0xee, [0x25] = 0x99,
4930 			[0x26] = 0xff, [0x27] = 0xaa,
4931 		},
4932 		{ {0x40, 0x88ee99ff } },
4933 	},
4934 	/*
4935 	 * verify that the interpreter or JIT correctly sets A and X
4936 	 * to 0.
4937 	 */
4938 	{
4939 		"ADD default X",
4940 		.u.insns = {
4941 			/*
4942 			 * A = 0x42
4943 			 * A = A + X
4944 			 * ret A
4945 			 */
4946 			BPF_STMT(BPF_LD | BPF_IMM, 0x42),
4947 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
4948 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4949 		},
4950 		CLASSIC | FLAG_NO_DATA,
4951 		{},
4952 		{ {0x1, 0x42 } },
4953 	},
4954 	{
4955 		"ADD default A",
4956 		.u.insns = {
4957 			/*
4958 			 * A = A + 0x42
4959 			 * ret A
4960 			 */
4961 			BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
4962 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4963 		},
4964 		CLASSIC | FLAG_NO_DATA,
4965 		{},
4966 		{ {0x1, 0x42 } },
4967 	},
4968 	{
4969 		"SUB default X",
4970 		.u.insns = {
4971 			/*
4972 			 * A = 0x66
4973 			 * A = A - X
4974 			 * ret A
4975 			 */
4976 			BPF_STMT(BPF_LD | BPF_IMM, 0x66),
4977 			BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
4978 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4979 		},
4980 		CLASSIC | FLAG_NO_DATA,
4981 		{},
4982 		{ {0x1, 0x66 } },
4983 	},
4984 	{
4985 		"SUB default A",
4986 		.u.insns = {
4987 			/*
4988 			 * A = A - -0x66
4989 			 * ret A
4990 			 */
4991 			BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
4992 			BPF_STMT(BPF_RET | BPF_A, 0x0),
4993 		},
4994 		CLASSIC | FLAG_NO_DATA,
4995 		{},
4996 		{ {0x1, 0x66 } },
4997 	},
4998 	{
4999 		"MUL default X",
5000 		.u.insns = {
5001 			/*
5002 			 * A = 0x42
5003 			 * A = A * X
5004 			 * ret A
5005 			 */
5006 			BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5007 			BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
5008 			BPF_STMT(BPF_RET | BPF_A, 0x0),
5009 		},
5010 		CLASSIC | FLAG_NO_DATA,
5011 		{},
5012 		{ {0x1, 0x0 } },
5013 	},
5014 	{
5015 		"MUL default A",
5016 		.u.insns = {
5017 			/*
5018 			 * A = A * 0x66
5019 			 * ret A
5020 			 */
5021 			BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
5022 			BPF_STMT(BPF_RET | BPF_A, 0x0),
5023 		},
5024 		CLASSIC | FLAG_NO_DATA,
5025 		{},
5026 		{ {0x1, 0x0 } },
5027 	},
5028 	{
5029 		"DIV default X",
5030 		.u.insns = {
5031 			/*
5032 			 * A = 0x42
5033 			 * A = A / X ; this halt the filter execution if X is 0
5034 			 * ret 0x42
5035 			 */
5036 			BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5037 			BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
5038 			BPF_STMT(BPF_RET | BPF_K, 0x42),
5039 		},
5040 		CLASSIC | FLAG_NO_DATA,
5041 		{},
5042 		{ {0x1, 0x0 } },
5043 	},
5044 	{
5045 		"DIV default A",
5046 		.u.insns = {
5047 			/*
5048 			 * A = A / 1
5049 			 * ret A
5050 			 */
5051 			BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
5052 			BPF_STMT(BPF_RET | BPF_A, 0x0),
5053 		},
5054 		CLASSIC | FLAG_NO_DATA,
5055 		{},
5056 		{ {0x1, 0x0 } },
5057 	},
5058 	{
5059 		"JMP EQ default A",
5060 		.u.insns = {
5061 			/*
5062 			 * cmp A, 0x0, 0, 1
5063 			 * ret 0x42
5064 			 * ret 0x66
5065 			 */
5066 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
5067 			BPF_STMT(BPF_RET | BPF_K, 0x42),
5068 			BPF_STMT(BPF_RET | BPF_K, 0x66),
5069 		},
5070 		CLASSIC | FLAG_NO_DATA,
5071 		{},
5072 		{ {0x1, 0x42 } },
5073 	},
5074 	{
5075 		"JMP EQ default X",
5076 		.u.insns = {
5077 			/*
5078 			 * A = 0x0
5079 			 * cmp A, X, 0, 1
5080 			 * ret 0x42
5081 			 * ret 0x66
5082 			 */
5083 			BPF_STMT(BPF_LD | BPF_IMM, 0x0),
5084 			BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
5085 			BPF_STMT(BPF_RET | BPF_K, 0x42),
5086 			BPF_STMT(BPF_RET | BPF_K, 0x66),
5087 		},
5088 		CLASSIC | FLAG_NO_DATA,
5089 		{},
5090 		{ {0x1, 0x42 } },
5091 	},
5092 };
5093 
5094 static struct net_device dev;
5095 
5096 static struct sk_buff *populate_skb(char *buf, int size)
5097 {
5098 	struct sk_buff *skb;
5099 
5100 	if (size >= MAX_DATA)
5101 		return NULL;
5102 
5103 	skb = alloc_skb(MAX_DATA, GFP_KERNEL);
5104 	if (!skb)
5105 		return NULL;
5106 
5107 	memcpy(__skb_put(skb, size), buf, size);
5108 
5109 	/* Initialize a fake skb with test pattern. */
5110 	skb_reset_mac_header(skb);
5111 	skb->protocol = htons(ETH_P_IP);
5112 	skb->pkt_type = SKB_TYPE;
5113 	skb->mark = SKB_MARK;
5114 	skb->hash = SKB_HASH;
5115 	skb->queue_mapping = SKB_QUEUE_MAP;
5116 	skb->vlan_tci = SKB_VLAN_TCI;
5117 	skb->dev = &dev;
5118 	skb->dev->ifindex = SKB_DEV_IFINDEX;
5119 	skb->dev->type = SKB_DEV_TYPE;
5120 	skb_set_network_header(skb, min(size, ETH_HLEN));
5121 
5122 	return skb;
5123 }
5124 
5125 static void *generate_test_data(struct bpf_test *test, int sub)
5126 {
5127 	struct sk_buff *skb;
5128 	struct page *page;
5129 
5130 	if (test->aux & FLAG_NO_DATA)
5131 		return NULL;
5132 
5133 	/* Test case expects an skb, so populate one. Various
5134 	 * subtests generate skbs of different sizes based on
5135 	 * the same data.
5136 	 */
5137 	skb = populate_skb(test->data, test->test[sub].data_size);
5138 	if (!skb)
5139 		return NULL;
5140 
5141 	if (test->aux & FLAG_SKB_FRAG) {
5142 		/*
5143 		 * when the test requires a fragmented skb, add a
5144 		 * single fragment to the skb, filled with
5145 		 * test->frag_data.
5146 		 */
5147 		void *ptr;
5148 
5149 		page = alloc_page(GFP_KERNEL);
5150 
5151 		if (!page)
5152 			goto err_kfree_skb;
5153 
5154 		ptr = kmap(page);
5155 		if (!ptr)
5156 			goto err_free_page;
5157 		memcpy(ptr, test->frag_data, MAX_DATA);
5158 		kunmap(page);
5159 		skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
5160 	}
5161 
5162 	return skb;
5163 
5164 err_free_page:
5165 	__free_page(page);
5166 err_kfree_skb:
5167 	kfree_skb(skb);
5168 	return NULL;
5169 }
5170 
5171 static void release_test_data(const struct bpf_test *test, void *data)
5172 {
5173 	if (test->aux & FLAG_NO_DATA)
5174 		return;
5175 
5176 	kfree_skb(data);
5177 }
5178 
5179 static int filter_length(int which)
5180 {
5181 	struct sock_filter *fp;
5182 	int len;
5183 
5184 	if (tests[which].fill_helper)
5185 		return tests[which].u.ptr.len;
5186 
5187 	fp = tests[which].u.insns;
5188 	for (len = MAX_INSNS - 1; len > 0; --len)
5189 		if (fp[len].code != 0 || fp[len].k != 0)
5190 			break;
5191 
5192 	return len + 1;
5193 }
5194 
5195 static void *filter_pointer(int which)
5196 {
5197 	if (tests[which].fill_helper)
5198 		return tests[which].u.ptr.insns;
5199 	else
5200 		return tests[which].u.insns;
5201 }
5202 
5203 static struct bpf_prog *generate_filter(int which, int *err)
5204 {
5205 	__u8 test_type = tests[which].aux & TEST_TYPE_MASK;
5206 	unsigned int flen = filter_length(which);
5207 	void *fptr = filter_pointer(which);
5208 	struct sock_fprog_kern fprog;
5209 	struct bpf_prog *fp;
5210 
5211 	switch (test_type) {
5212 	case CLASSIC:
5213 		fprog.filter = fptr;
5214 		fprog.len = flen;
5215 
5216 		*err = bpf_prog_create(&fp, &fprog);
5217 		if (tests[which].aux & FLAG_EXPECTED_FAIL) {
5218 			if (*err == -EINVAL) {
5219 				pr_cont("PASS\n");
5220 				/* Verifier rejected filter as expected. */
5221 				*err = 0;
5222 				return NULL;
5223 			} else {
5224 				pr_cont("UNEXPECTED_PASS\n");
5225 				/* Verifier didn't reject the test that's
5226 				 * bad enough, just return!
5227 				 */
5228 				*err = -EINVAL;
5229 				return NULL;
5230 			}
5231 		}
5232 		/* We don't expect to fail. */
5233 		if (*err) {
5234 			pr_cont("FAIL to attach err=%d len=%d\n",
5235 				*err, fprog.len);
5236 			return NULL;
5237 		}
5238 		break;
5239 
5240 	case INTERNAL:
5241 		fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
5242 		if (fp == NULL) {
5243 			pr_cont("UNEXPECTED_FAIL no memory left\n");
5244 			*err = -ENOMEM;
5245 			return NULL;
5246 		}
5247 
5248 		fp->len = flen;
5249 		/* Type doesn't really matter here as long as it's not unspec. */
5250 		fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
5251 		memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
5252 
5253 		bpf_prog_select_runtime(fp);
5254 		break;
5255 	}
5256 
5257 	*err = 0;
5258 	return fp;
5259 }
5260 
5261 static void release_filter(struct bpf_prog *fp, int which)
5262 {
5263 	__u8 test_type = tests[which].aux & TEST_TYPE_MASK;
5264 
5265 	switch (test_type) {
5266 	case CLASSIC:
5267 		bpf_prog_destroy(fp);
5268 		break;
5269 	case INTERNAL:
5270 		bpf_prog_free(fp);
5271 		break;
5272 	}
5273 }
5274 
5275 static int __run_one(const struct bpf_prog *fp, const void *data,
5276 		     int runs, u64 *duration)
5277 {
5278 	u64 start, finish;
5279 	int ret = 0, i;
5280 
5281 	start = ktime_get_ns();
5282 
5283 	for (i = 0; i < runs; i++)
5284 		ret = BPF_PROG_RUN(fp, data);
5285 
5286 	finish = ktime_get_ns();
5287 
5288 	*duration = finish - start;
5289 	do_div(*duration, runs);
5290 
5291 	return ret;
5292 }
5293 
5294 static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
5295 {
5296 	int err_cnt = 0, i, runs = MAX_TESTRUNS;
5297 
5298 	for (i = 0; i < MAX_SUBTESTS; i++) {
5299 		void *data;
5300 		u64 duration;
5301 		u32 ret;
5302 
5303 		if (test->test[i].data_size == 0 &&
5304 		    test->test[i].result == 0)
5305 			break;
5306 
5307 		data = generate_test_data(test, i);
5308 		if (!data && !(test->aux & FLAG_NO_DATA)) {
5309 			pr_cont("data generation failed ");
5310 			err_cnt++;
5311 			break;
5312 		}
5313 		ret = __run_one(fp, data, runs, &duration);
5314 		release_test_data(test, data);
5315 
5316 		if (ret == test->test[i].result) {
5317 			pr_cont("%lld ", duration);
5318 		} else {
5319 			pr_cont("ret %d != %d ", ret,
5320 				test->test[i].result);
5321 			err_cnt++;
5322 		}
5323 	}
5324 
5325 	return err_cnt;
5326 }
5327 
5328 static char test_name[64];
5329 module_param_string(test_name, test_name, sizeof(test_name), 0);
5330 
5331 static int test_id = -1;
5332 module_param(test_id, int, 0);
5333 
5334 static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
5335 module_param_array(test_range, int, NULL, 0);
5336 
5337 static __init int find_test_index(const char *test_name)
5338 {
5339 	int i;
5340 
5341 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
5342 		if (!strcmp(tests[i].descr, test_name))
5343 			return i;
5344 	}
5345 	return -1;
5346 }
5347 
5348 static __init int prepare_bpf_tests(void)
5349 {
5350 	int i;
5351 
5352 	if (test_id >= 0) {
5353 		/*
5354 		 * if a test_id was specified, use test_range to
5355 		 * cover only that test.
5356 		 */
5357 		if (test_id >= ARRAY_SIZE(tests)) {
5358 			pr_err("test_bpf: invalid test_id specified.\n");
5359 			return -EINVAL;
5360 		}
5361 
5362 		test_range[0] = test_id;
5363 		test_range[1] = test_id;
5364 	} else if (*test_name) {
5365 		/*
5366 		 * if a test_name was specified, find it and setup
5367 		 * test_range to cover only that test.
5368 		 */
5369 		int idx = find_test_index(test_name);
5370 
5371 		if (idx < 0) {
5372 			pr_err("test_bpf: no test named '%s' found.\n",
5373 			       test_name);
5374 			return -EINVAL;
5375 		}
5376 		test_range[0] = idx;
5377 		test_range[1] = idx;
5378 	} else {
5379 		/*
5380 		 * check that the supplied test_range is valid.
5381 		 */
5382 		if (test_range[0] >= ARRAY_SIZE(tests) ||
5383 		    test_range[1] >= ARRAY_SIZE(tests) ||
5384 		    test_range[0] < 0 || test_range[1] < 0) {
5385 			pr_err("test_bpf: test_range is out of bound.\n");
5386 			return -EINVAL;
5387 		}
5388 
5389 		if (test_range[1] < test_range[0]) {
5390 			pr_err("test_bpf: test_range is ending before it starts.\n");
5391 			return -EINVAL;
5392 		}
5393 	}
5394 
5395 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
5396 		if (tests[i].fill_helper &&
5397 		    tests[i].fill_helper(&tests[i]) < 0)
5398 			return -ENOMEM;
5399 	}
5400 
5401 	return 0;
5402 }
5403 
5404 static __init void destroy_bpf_tests(void)
5405 {
5406 	int i;
5407 
5408 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
5409 		if (tests[i].fill_helper)
5410 			kfree(tests[i].u.ptr.insns);
5411 	}
5412 }
5413 
5414 static bool exclude_test(int test_id)
5415 {
5416 	return test_id < test_range[0] || test_id > test_range[1];
5417 }
5418 
5419 static __init int test_bpf(void)
5420 {
5421 	int i, err_cnt = 0, pass_cnt = 0;
5422 	int jit_cnt = 0, run_cnt = 0;
5423 
5424 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
5425 		struct bpf_prog *fp;
5426 		int err;
5427 
5428 		if (exclude_test(i))
5429 			continue;
5430 
5431 		pr_info("#%d %s ", i, tests[i].descr);
5432 
5433 		fp = generate_filter(i, &err);
5434 		if (fp == NULL) {
5435 			if (err == 0) {
5436 				pass_cnt++;
5437 				continue;
5438 			}
5439 
5440 			return err;
5441 		}
5442 
5443 		pr_cont("jited:%u ", fp->jited);
5444 
5445 		run_cnt++;
5446 		if (fp->jited)
5447 			jit_cnt++;
5448 
5449 		err = run_one(fp, &tests[i]);
5450 		release_filter(fp, i);
5451 
5452 		if (err) {
5453 			pr_cont("FAIL (%d times)\n", err);
5454 			err_cnt++;
5455 		} else {
5456 			pr_cont("PASS\n");
5457 			pass_cnt++;
5458 		}
5459 	}
5460 
5461 	pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
5462 		pass_cnt, err_cnt, jit_cnt, run_cnt);
5463 
5464 	return err_cnt ? -EINVAL : 0;
5465 }
5466 
5467 static int __init test_bpf_init(void)
5468 {
5469 	int ret;
5470 
5471 	ret = prepare_bpf_tests();
5472 	if (ret < 0)
5473 		return ret;
5474 
5475 	ret = test_bpf();
5476 
5477 	destroy_bpf_tests();
5478 	return ret;
5479 }
5480 
5481 static void __exit test_bpf_exit(void)
5482 {
5483 }
5484 
5485 module_init(test_bpf_init);
5486 module_exit(test_bpf_exit);
5487 
5488 MODULE_LICENSE("GPL");
5489