blob: 070bde56474cbd04e720def21c150bbc7a29bff6 [file] [log] [blame]
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001/*
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>
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -070021#include <linux/bpf.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070022#include <linux/skbuff.h>
23#include <linux/netdevice.h>
24#include <linux/if_vlan.h>
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020025#include <linux/random.h>
Nicolas Schichanbac142a2015-08-04 15:19:08 +020026#include <linux/highmem.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070027
Daniel Borkmann10f18e02014-05-23 18:44:00 +020028/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070029#define MAX_SUBTESTS 3
Daniel Borkmann10f18e02014-05-23 18:44:00 +020030#define MAX_TESTRUNS 10000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070031#define MAX_DATA 128
32#define MAX_INSNS 512
33#define MAX_K 0xffffFFFF
34
Daniel Borkmann10f18e02014-05-23 18:44:00 +020035/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070036#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
Daniel Borkmann10f18e02014-05-23 18:44:00 +020044/* 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)
Nicolas Schichanbac142a2015-08-04 15:19:08 +020060#define FLAG_SKB_FRAG BIT(2)
Daniel Borkmann10f18e02014-05-23 18:44:00 +020061
62enum {
63 CLASSIC = BIT(6), /* Old BPF instructions only. */
64 INTERNAL = BIT(7), /* Extended instruction set. */
65};
66
67#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070068
69struct bpf_test {
70 const char *descr;
71 union {
72 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070073 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020074 struct {
75 void *insns;
76 unsigned int len;
77 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070078 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020079 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070080 __u8 data[MAX_DATA];
81 struct {
82 int data_size;
83 __u32 result;
84 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020085 int (*fill_helper)(struct bpf_test *self);
Nicolas Schichanbac142a2015-08-04 15:19:08 +020086 __u8 frag_data[MAX_DATA];
Alexei Starovoitov105c0362017-05-30 13:31:32 -070087 int stack_depth; /* for eBPF only, since tests don't call verifier */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070088};
89
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020090/* Large test cases need separate allocation and fill handler. */
91
92static int bpf_fill_maxinsns1(struct bpf_test *self)
93{
94 unsigned int len = BPF_MAXINSNS;
95 struct sock_filter *insn;
96 __u32 k = ~0;
97 int i;
98
99 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
100 if (!insn)
101 return -ENOMEM;
102
103 for (i = 0; i < len; i++, k--)
104 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
105
106 self->u.ptr.insns = insn;
107 self->u.ptr.len = len;
108
109 return 0;
110}
111
112static int bpf_fill_maxinsns2(struct bpf_test *self)
113{
114 unsigned int len = BPF_MAXINSNS;
115 struct sock_filter *insn;
116 int i;
117
118 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
119 if (!insn)
120 return -ENOMEM;
121
122 for (i = 0; i < len; i++)
123 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
124
125 self->u.ptr.insns = insn;
126 self->u.ptr.len = len;
127
128 return 0;
129}
130
131static int bpf_fill_maxinsns3(struct bpf_test *self)
132{
133 unsigned int len = BPF_MAXINSNS;
134 struct sock_filter *insn;
135 struct rnd_state rnd;
136 int i;
137
138 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
139 if (!insn)
140 return -ENOMEM;
141
142 prandom_seed_state(&rnd, 3141592653589793238ULL);
143
144 for (i = 0; i < len - 1; i++) {
145 __u32 k = prandom_u32_state(&rnd);
146
147 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
148 }
149
150 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
151
152 self->u.ptr.insns = insn;
153 self->u.ptr.len = len;
154
155 return 0;
156}
157
158static int bpf_fill_maxinsns4(struct bpf_test *self)
159{
160 unsigned int len = BPF_MAXINSNS + 1;
161 struct sock_filter *insn;
162 int i;
163
164 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
165 if (!insn)
166 return -ENOMEM;
167
168 for (i = 0; i < len; i++)
169 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
170
171 self->u.ptr.insns = insn;
172 self->u.ptr.len = len;
173
174 return 0;
175}
176
177static int bpf_fill_maxinsns5(struct bpf_test *self)
178{
179 unsigned int len = BPF_MAXINSNS;
180 struct sock_filter *insn;
181 int i;
182
183 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
184 if (!insn)
185 return -ENOMEM;
186
187 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
188
189 for (i = 1; i < len - 1; i++)
190 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
191
192 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
193
194 self->u.ptr.insns = insn;
195 self->u.ptr.len = len;
196
197 return 0;
198}
199
200static int bpf_fill_maxinsns6(struct bpf_test *self)
201{
202 unsigned int len = BPF_MAXINSNS;
203 struct sock_filter *insn;
204 int i;
205
206 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
207 if (!insn)
208 return -ENOMEM;
209
210 for (i = 0; i < len - 1; i++)
211 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
212 SKF_AD_VLAN_TAG_PRESENT);
213
214 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
215
216 self->u.ptr.insns = insn;
217 self->u.ptr.len = len;
218
219 return 0;
220}
221
222static int bpf_fill_maxinsns7(struct bpf_test *self)
223{
224 unsigned int len = BPF_MAXINSNS;
225 struct sock_filter *insn;
226 int i;
227
228 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
229 if (!insn)
230 return -ENOMEM;
231
232 for (i = 0; i < len - 4; i++)
233 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 SKF_AD_CPU);
235
236 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
237 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
238 SKF_AD_CPU);
239 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
240 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
241
242 self->u.ptr.insns = insn;
243 self->u.ptr.len = len;
244
245 return 0;
246}
247
248static int bpf_fill_maxinsns8(struct bpf_test *self)
249{
250 unsigned int len = BPF_MAXINSNS;
251 struct sock_filter *insn;
252 int i, jmp_off = len - 3;
253
254 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
255 if (!insn)
256 return -ENOMEM;
257
258 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
259
260 for (i = 1; i < len - 1; i++)
261 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
262
263 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
264
265 self->u.ptr.insns = insn;
266 self->u.ptr.len = len;
267
268 return 0;
269}
270
Daniel Borkmann3b529602015-05-23 01:10:07 +0200271static int bpf_fill_maxinsns9(struct bpf_test *self)
272{
273 unsigned int len = BPF_MAXINSNS;
274 struct bpf_insn *insn;
275 int i;
276
277 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
278 if (!insn)
279 return -ENOMEM;
280
281 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
282 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
283 insn[2] = BPF_EXIT_INSN();
284
285 for (i = 3; i < len - 2; i++)
286 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
287
288 insn[len - 2] = BPF_EXIT_INSN();
289 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
290
291 self->u.ptr.insns = insn;
292 self->u.ptr.len = len;
293
294 return 0;
295}
296
297static int bpf_fill_maxinsns10(struct bpf_test *self)
298{
299 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
300 struct bpf_insn *insn;
301 int i;
302
303 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
304 if (!insn)
305 return -ENOMEM;
306
307 for (i = 0; i < hlen / 2; i++)
308 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
309 for (i = hlen - 1; i > hlen / 2; i--)
310 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
311
312 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
313 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
314 insn[hlen + 1] = BPF_EXIT_INSN();
315
316 self->u.ptr.insns = insn;
317 self->u.ptr.len = len;
318
319 return 0;
320}
321
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200322static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
323 unsigned int plen)
324{
325 struct sock_filter *insn;
326 unsigned int rlen;
327 int i, j;
328
329 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
330 if (!insn)
331 return -ENOMEM;
332
333 rlen = (len % plen) - 1;
334
335 for (i = 0; i + plen < len; i += plen)
336 for (j = 0; j < plen; j++)
337 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
338 plen - 1 - j, 0, 0);
339 for (j = 0; j < rlen; j++)
340 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
341 0, 0);
342
343 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
344
345 self->u.ptr.insns = insn;
346 self->u.ptr.len = len;
347
348 return 0;
349}
350
351static int bpf_fill_maxinsns11(struct bpf_test *self)
352{
353 /* Hits 70 passes on x86_64, so cannot get JITed there. */
354 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
355}
356
357static int bpf_fill_ja(struct bpf_test *self)
358{
359 /* Hits exactly 11 passes on x86_64 JIT. */
360 return __bpf_fill_ja(self, 12, 9);
361}
362
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700363static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
364{
365 unsigned int len = BPF_MAXINSNS;
366 struct sock_filter *insn;
367 int i;
368
369 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
370 if (!insn)
371 return -ENOMEM;
372
373 for (i = 0; i < len - 1; i += 2) {
374 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
375 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
376 SKF_AD_OFF + SKF_AD_CPU);
377 }
378
379 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
380
381 self->u.ptr.insns = insn;
382 self->u.ptr.len = len;
383
384 return 0;
385}
386
387#define PUSH_CNT 68
388/* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
389static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
390{
391 unsigned int len = BPF_MAXINSNS;
392 struct bpf_insn *insn;
393 int i = 0, j, k = 0;
394
395 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
396 if (!insn)
397 return -ENOMEM;
398
399 insn[i++] = BPF_MOV64_REG(R6, R1);
400loop:
401 for (j = 0; j < PUSH_CNT; j++) {
402 insn[i++] = BPF_LD_ABS(BPF_B, 0);
403 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
404 i++;
405 insn[i++] = BPF_MOV64_REG(R1, R6);
406 insn[i++] = BPF_MOV64_IMM(R2, 1);
407 insn[i++] = BPF_MOV64_IMM(R3, 2);
408 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
409 bpf_skb_vlan_push_proto.func - __bpf_call_base);
410 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
411 i++;
412 }
413
414 for (j = 0; j < PUSH_CNT; j++) {
415 insn[i++] = BPF_LD_ABS(BPF_B, 0);
416 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
417 i++;
418 insn[i++] = BPF_MOV64_REG(R1, R6);
419 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
420 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
421 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
422 i++;
423 }
424 if (++k < 5)
425 goto loop;
426
427 for (; i < len - 1; i++)
428 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
429
430 insn[len - 1] = BPF_EXIT_INSN();
431
432 self->u.ptr.insns = insn;
433 self->u.ptr.len = len;
434
435 return 0;
436}
437
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200438static int __bpf_fill_stxdw(struct bpf_test *self, int size)
439{
440 unsigned int len = BPF_MAXINSNS;
441 struct bpf_insn *insn;
442 int i;
443
444 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
445 if (!insn)
446 return -ENOMEM;
447
448 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
449 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
450
451 for (i = 2; i < len - 2; i++)
452 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
453
454 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
455 insn[len - 1] = BPF_EXIT_INSN();
456
457 self->u.ptr.insns = insn;
458 self->u.ptr.len = len;
Alexei Starovoitov105c0362017-05-30 13:31:32 -0700459 self->stack_depth = 40;
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200460
461 return 0;
462}
463
464static int bpf_fill_stxw(struct bpf_test *self)
465{
466 return __bpf_fill_stxdw(self, BPF_W);
467}
468
469static int bpf_fill_stxdw(struct bpf_test *self)
470{
471 return __bpf_fill_stxdw(self, BPF_DW);
472}
473
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700474static struct bpf_test tests[] = {
475 {
476 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700477 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700478 BPF_STMT(BPF_LD | BPF_IMM, 1),
479 BPF_STMT(BPF_MISC | BPF_TAX, 0),
480 BPF_STMT(BPF_LD | BPF_IMM, 2),
481 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
482 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
483 BPF_STMT(BPF_MISC | BPF_TAX, 0),
484 BPF_STMT(BPF_LD | BPF_LEN, 0),
485 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
486 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
487 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
488 BPF_STMT(BPF_RET | BPF_A, 0)
489 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200490 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700491 { 10, 20, 30, 40, 50 },
492 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
493 },
494 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700495 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700496 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700497 BPF_STMT(BPF_LDX | BPF_LEN, 0),
498 BPF_STMT(BPF_MISC | BPF_TXA, 0),
499 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
500 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
501 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200502 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700503 { 10, 20, 30, 40, 50 },
504 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
505 },
506 {
507 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700508 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700509 BPF_STMT(BPF_LD | BPF_IMM, 1),
510 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
511 BPF_STMT(BPF_LDX | BPF_IMM, 3),
512 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
513 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
514 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
515 BPF_STMT(BPF_RET | BPF_A, 0)
516 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200517 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700518 { },
519 { { 0, 0xfffffffd } }
520 },
521 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300522 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700523 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700524 BPF_STMT(BPF_LD | BPF_IMM, 8),
525 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
526 BPF_STMT(BPF_MISC | BPF_TAX, 0),
527 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
528 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
529 BPF_STMT(BPF_MISC | BPF_TAX, 0),
530 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
531 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300532 BPF_STMT(BPF_MISC | BPF_TAX, 0),
533 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
534 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
535 BPF_STMT(BPF_MISC | BPF_TAX, 0),
536 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
537 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700538 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
539 BPF_STMT(BPF_RET | BPF_A, 0)
540 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200541 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700542 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300543 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700544 },
545 {
546 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700547 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700548 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
549 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
550 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
551 BPF_STMT(BPF_MISC | BPF_TAX, 0),
552 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
553 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
554 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
555 BPF_STMT(BPF_RET | BPF_A, 0)
556 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200557 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700558 { },
559 { { 0, 0x800000ff }, { 1, 0x800000ff } },
560 },
561 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700562 "LD_IMM_0",
563 .u.insns = {
564 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
565 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
566 BPF_STMT(BPF_RET | BPF_K, 0),
567 BPF_STMT(BPF_RET | BPF_K, 1),
568 },
569 CLASSIC,
570 { },
571 { { 1, 1 } },
572 },
573 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700574 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700575 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700576 BPF_STMT(BPF_LDX | BPF_LEN, 0),
577 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
578 BPF_STMT(BPF_RET | BPF_K, 1)
579 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200580 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700581 { },
582 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
583 },
584 {
585 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700586 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700587 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
588 BPF_STMT(BPF_RET | BPF_K, 1)
589 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200590 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700591 { },
592 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
593 },
594 {
595 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700596 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700597 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
598 BPF_STMT(BPF_MISC | BPF_TAX, 0),
599 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
600 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
601 BPF_STMT(BPF_RET | BPF_A, 0)
602 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200603 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700604 { 1, 2, 3 },
605 { { 1, 0 }, { 2, 3 } },
606 },
607 {
608 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700609 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700610 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
611 BPF_STMT(BPF_LDX | BPF_LEN, 0),
612 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
613 BPF_STMT(BPF_MISC | BPF_TAX, 0),
614 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
615 BPF_STMT(BPF_RET | BPF_A, 0)
616 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200617 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700618 { 1, 2, 3, 0xff },
619 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
620 },
621 {
622 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700623 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700624 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
625 BPF_STMT(BPF_MISC | BPF_TAX, 0),
626 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
627 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
628 BPF_STMT(BPF_RET | BPF_A, 0)
629 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200630 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700631 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
632 { { 15, 0 }, { 16, 3 } },
633 },
634 {
635 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700636 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700637 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
638 BPF_STMT(BPF_LDX | BPF_LEN, 0),
639 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
640 BPF_STMT(BPF_MISC | BPF_TAX, 0),
641 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
642 BPF_STMT(BPF_RET | BPF_A, 0)
643 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200644 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700645 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
646 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
647 },
648 {
649 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700650 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700651 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
652 SKF_AD_OFF + SKF_AD_PKTTYPE),
653 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
654 BPF_STMT(BPF_RET | BPF_K, 1),
655 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
656 SKF_AD_OFF + SKF_AD_PKTTYPE),
657 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
658 BPF_STMT(BPF_RET | BPF_K, 1),
659 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
660 SKF_AD_OFF + SKF_AD_PKTTYPE),
661 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
662 BPF_STMT(BPF_RET | BPF_K, 1),
663 BPF_STMT(BPF_RET | BPF_A, 0)
664 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200665 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700666 { },
667 { { 1, 3 }, { 10, 3 } },
668 },
669 {
670 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700671 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700672 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
673 SKF_AD_OFF + SKF_AD_MARK),
674 BPF_STMT(BPF_RET | BPF_A, 0)
675 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200676 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700677 { },
678 { { 1, SKB_MARK}, { 10, SKB_MARK} },
679 },
680 {
681 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700682 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700683 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
684 SKF_AD_OFF + SKF_AD_RXHASH),
685 BPF_STMT(BPF_RET | BPF_A, 0)
686 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200687 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700688 { },
689 { { 1, SKB_HASH}, { 10, SKB_HASH} },
690 },
691 {
692 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700693 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700694 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
695 SKF_AD_OFF + SKF_AD_QUEUE),
696 BPF_STMT(BPF_RET | BPF_A, 0)
697 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200698 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700699 { },
700 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
701 },
702 {
703 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700704 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700705 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
706 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
707 BPF_STMT(BPF_RET | BPF_K, 0),
708 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
709 SKF_AD_OFF + SKF_AD_PROTOCOL),
710 BPF_STMT(BPF_MISC | BPF_TAX, 0),
711 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
712 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
713 BPF_STMT(BPF_RET | BPF_K, 0),
714 BPF_STMT(BPF_MISC | BPF_TXA, 0),
715 BPF_STMT(BPF_RET | BPF_A, 0)
716 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200717 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700718 { 10, 20, 30 },
719 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
720 },
721 {
722 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700723 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700724 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
725 SKF_AD_OFF + SKF_AD_VLAN_TAG),
726 BPF_STMT(BPF_RET | BPF_A, 0)
727 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200728 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700729 { },
730 {
731 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
732 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
733 },
734 },
735 {
736 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700737 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700738 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
739 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
740 BPF_STMT(BPF_RET | BPF_A, 0)
741 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200742 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700743 { },
744 {
745 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
746 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
747 },
748 },
749 {
750 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700751 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700752 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
753 SKF_AD_OFF + SKF_AD_IFINDEX),
754 BPF_STMT(BPF_RET | BPF_A, 0)
755 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200756 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700757 { },
758 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
759 },
760 {
761 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700762 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700763 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
764 SKF_AD_OFF + SKF_AD_HATYPE),
765 BPF_STMT(BPF_RET | BPF_A, 0)
766 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200767 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700768 { },
769 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
770 },
771 {
772 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700773 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700774 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
775 SKF_AD_OFF + SKF_AD_CPU),
776 BPF_STMT(BPF_MISC | BPF_TAX, 0),
777 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
778 SKF_AD_OFF + SKF_AD_CPU),
779 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
780 BPF_STMT(BPF_RET | BPF_A, 0)
781 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200782 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700783 { },
784 { { 1, 0 }, { 10, 0 } },
785 },
786 {
787 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700788 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700789 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700790 BPF_STMT(BPF_MISC | BPF_TXA, 0),
791 BPF_STMT(BPF_LDX | BPF_IMM, 3),
792 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
793 SKF_AD_OFF + SKF_AD_NLATTR),
794 BPF_STMT(BPF_RET | BPF_A, 0)
795 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200796 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700797#ifdef __BIG_ENDIAN
798 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
799#else
800 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
801#endif
802 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700803 },
804 {
805 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700806 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700807 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700808 BPF_STMT(BPF_LDX | BPF_IMM, 3),
809 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
810 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700811 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700812 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
813 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700814 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700815 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
816 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700817 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700818 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
819 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700820 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700821 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
822 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700823 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700824 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
825 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700826 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700827 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
828 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700829 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700830 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
831 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
832 BPF_STMT(BPF_RET | BPF_A, 0)
833 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200834 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700835#ifdef __BIG_ENDIAN
836 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
837#else
838 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
839#endif
840 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700841 },
842 {
843 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700844 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700845 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
846 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
847 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
848 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
849 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
850 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
851 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
852 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
853 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
854 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
855 BPF_STMT(BPF_RET | BPF_A, 0)
856 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200857 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700858 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
859 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
860 * id 9737, seq 1, length 64
861 */
862 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
863 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
864 0x08, 0x00,
865 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
866 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
867 { { 30, 0 }, { 100, 42 } },
868 },
869 {
870 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700871 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700872 BPF_STMT(BPF_LD | BPF_IMM, 10),
873 BPF_STMT(BPF_LDX | BPF_IMM, 300),
874 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
875 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
876 BPF_STMT(BPF_RET | BPF_A, 0)
877 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200878 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700879 { },
880 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
881 },
882 {
883 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700884 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700885 BPF_STMT(BPF_LDX | BPF_LEN, 0),
886 BPF_STMT(BPF_LD | BPF_IMM, 2),
887 BPF_STMT(BPF_ALU | BPF_RSH, 1),
888 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
889 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
890 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
891 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
892 BPF_STMT(BPF_STX, 15), /* M3 = len */
893 BPF_STMT(BPF_LDX | BPF_MEM, 1),
894 BPF_STMT(BPF_LD | BPF_MEM, 2),
895 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
896 BPF_STMT(BPF_LDX | BPF_MEM, 15),
897 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
898 BPF_STMT(BPF_RET | BPF_A, 0)
899 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200900 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700901 { },
902 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
903 },
904 {
905 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700906 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700907 BPF_STMT(BPF_LDX | BPF_LEN, 0),
908 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
909 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
910 BPF_STMT(BPF_RET | BPF_K, 1),
911 BPF_STMT(BPF_RET | BPF_K, MAX_K)
912 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200913 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700914 { 3, 3, 3, 3, 3 },
915 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
916 },
917 {
918 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700919 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700920 BPF_STMT(BPF_LDX | BPF_LEN, 0),
921 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
922 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
923 BPF_STMT(BPF_RET | BPF_K, 1),
924 BPF_STMT(BPF_RET | BPF_K, MAX_K)
925 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200926 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700927 { 4, 4, 4, 3, 3 },
928 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
929 },
930 {
931 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700932 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700933 BPF_STMT(BPF_LDX | BPF_LEN, 0),
934 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
935 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
936 BPF_STMT(BPF_RET | BPF_K, 10),
937 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
938 BPF_STMT(BPF_RET | BPF_K, 20),
939 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
940 BPF_STMT(BPF_RET | BPF_K, 30),
941 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
942 BPF_STMT(BPF_RET | BPF_K, 40),
943 BPF_STMT(BPF_RET | BPF_K, MAX_K)
944 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200945 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700946 { 1, 2, 3, 4, 5 },
947 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
948 },
949 {
950 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700951 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700952 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
953 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
954 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
955 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
956 BPF_STMT(BPF_LDX | BPF_LEN, 0),
957 BPF_STMT(BPF_MISC | BPF_TXA, 0),
958 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
959 BPF_STMT(BPF_MISC | BPF_TAX, 0),
960 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
961 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
962 BPF_STMT(BPF_RET | BPF_K, 10),
963 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
964 BPF_STMT(BPF_RET | BPF_K, 20),
965 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
966 BPF_STMT(BPF_RET | BPF_K, 30),
967 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
968 BPF_STMT(BPF_RET | BPF_K, 30),
969 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
970 BPF_STMT(BPF_RET | BPF_K, 30),
971 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
972 BPF_STMT(BPF_RET | BPF_K, 30),
973 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
974 BPF_STMT(BPF_RET | BPF_K, 30),
975 BPF_STMT(BPF_RET | BPF_K, MAX_K)
976 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200977 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700978 { 0, 0xAA, 0x55, 1 },
979 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
980 },
981 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700982 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -0700983 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +0200984 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
985 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
986 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
987 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
988 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
989 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
990 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
991 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
992 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
993 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
994 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
995 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
996 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
997 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
998 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
999 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1000 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1001 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1002 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1003 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1004 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1005 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1006 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1007 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001008 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001009 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001010 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1011 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1012 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1013 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1014 */
1015 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1016 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1017 0x08, 0x00,
1018 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1019 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1020 0x0a, 0x01, 0x01, 0x95, /* ip src */
1021 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1022 0xc2, 0x24,
1023 0x00, 0x16 /* dst port */ },
1024 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1025 },
1026 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001027 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001028 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001029 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1030 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1031 * (len > 115 or len < 30000000000)' -d
1032 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001033 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1034 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1035 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1036 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1037 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1038 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1039 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1040 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1041 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1042 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1043 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1044 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1045 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1046 BPF_STMT(BPF_ST, 1),
1047 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1048 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1049 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1050 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1051 BPF_STMT(BPF_LD | BPF_MEM, 1),
1052 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1053 BPF_STMT(BPF_ST, 5),
1054 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1055 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1056 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1057 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1058 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1059 BPF_STMT(BPF_LD | BPF_MEM, 5),
1060 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1061 BPF_STMT(BPF_LD | BPF_LEN, 0),
1062 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1063 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1064 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1065 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001066 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001067 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001068 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1069 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1070 0x08, 0x00,
1071 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1072 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1073 0x0a, 0x01, 0x01, 0x95, /* ip src */
1074 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1075 0xc2, 0x24,
1076 0x00, 0x16 /* dst port */ },
1077 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1078 },
1079 {
1080 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001081 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001082 /* check that unitialized X and A contain zeros */
1083 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1084 BPF_STMT(BPF_RET | BPF_A, 0)
1085 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001086 CLASSIC,
1087 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001088 { {1, 0}, {2, 0} },
1089 },
1090 {
1091 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001092 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001093 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1094 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1095 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1096 BPF_ALU64_REG(BPF_SUB, R1, R2),
1097 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1098 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1099 BPF_ALU64_REG(BPF_MOV, R0, R1),
1100 BPF_EXIT_INSN(),
1101 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001102 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001103 { },
1104 { { 0, 0xfffffffd } }
1105 },
1106 {
1107 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001108 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001109 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1110 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1111 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1112 BPF_ALU64_REG(BPF_MUL, R1, R2),
1113 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1114 BPF_EXIT_INSN(),
1115 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1116 BPF_EXIT_INSN(),
1117 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001118 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001119 { },
1120 { { 0, 1 } }
1121 },
1122 {
1123 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001124 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001125 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1126 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1127 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1128 BPF_ALU64_REG(BPF_MUL, R1, R2),
1129 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1130 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1131 BPF_EXIT_INSN(),
1132 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1133 BPF_EXIT_INSN(),
1134 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001135 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001136 { },
1137 { { 0, 1 } }
1138 },
1139 {
1140 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001141 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001142 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1143 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1144 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1145 BPF_ALU32_REG(BPF_MUL, R1, R2),
1146 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1147 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1148 BPF_EXIT_INSN(),
1149 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1150 BPF_EXIT_INSN(),
1151 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001152 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001153 { },
1154 { { 0, 1 } }
1155 },
1156 {
1157 /* Have to test all register combinations, since
1158 * JITing of different registers will produce
1159 * different asm code.
1160 */
1161 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001162 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001163 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1164 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1165 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1166 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1167 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1168 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1169 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1170 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1171 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1172 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1173 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1174 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1175 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1176 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1177 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1178 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1179 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1180 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1181 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1182 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1183 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1184 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1185 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1186 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1187 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1188 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1189 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1190 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1191 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1192 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1193 BPF_ALU64_REG(BPF_ADD, R0, R0),
1194 BPF_ALU64_REG(BPF_ADD, R0, R1),
1195 BPF_ALU64_REG(BPF_ADD, R0, R2),
1196 BPF_ALU64_REG(BPF_ADD, R0, R3),
1197 BPF_ALU64_REG(BPF_ADD, R0, R4),
1198 BPF_ALU64_REG(BPF_ADD, R0, R5),
1199 BPF_ALU64_REG(BPF_ADD, R0, R6),
1200 BPF_ALU64_REG(BPF_ADD, R0, R7),
1201 BPF_ALU64_REG(BPF_ADD, R0, R8),
1202 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1203 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1204 BPF_EXIT_INSN(),
1205 BPF_ALU64_REG(BPF_ADD, R1, R0),
1206 BPF_ALU64_REG(BPF_ADD, R1, R1),
1207 BPF_ALU64_REG(BPF_ADD, R1, R2),
1208 BPF_ALU64_REG(BPF_ADD, R1, R3),
1209 BPF_ALU64_REG(BPF_ADD, R1, R4),
1210 BPF_ALU64_REG(BPF_ADD, R1, R5),
1211 BPF_ALU64_REG(BPF_ADD, R1, R6),
1212 BPF_ALU64_REG(BPF_ADD, R1, R7),
1213 BPF_ALU64_REG(BPF_ADD, R1, R8),
1214 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1215 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1216 BPF_EXIT_INSN(),
1217 BPF_ALU64_REG(BPF_ADD, R2, R0),
1218 BPF_ALU64_REG(BPF_ADD, R2, R1),
1219 BPF_ALU64_REG(BPF_ADD, R2, R2),
1220 BPF_ALU64_REG(BPF_ADD, R2, R3),
1221 BPF_ALU64_REG(BPF_ADD, R2, R4),
1222 BPF_ALU64_REG(BPF_ADD, R2, R5),
1223 BPF_ALU64_REG(BPF_ADD, R2, R6),
1224 BPF_ALU64_REG(BPF_ADD, R2, R7),
1225 BPF_ALU64_REG(BPF_ADD, R2, R8),
1226 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1227 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1228 BPF_EXIT_INSN(),
1229 BPF_ALU64_REG(BPF_ADD, R3, R0),
1230 BPF_ALU64_REG(BPF_ADD, R3, R1),
1231 BPF_ALU64_REG(BPF_ADD, R3, R2),
1232 BPF_ALU64_REG(BPF_ADD, R3, R3),
1233 BPF_ALU64_REG(BPF_ADD, R3, R4),
1234 BPF_ALU64_REG(BPF_ADD, R3, R5),
1235 BPF_ALU64_REG(BPF_ADD, R3, R6),
1236 BPF_ALU64_REG(BPF_ADD, R3, R7),
1237 BPF_ALU64_REG(BPF_ADD, R3, R8),
1238 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1239 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1240 BPF_EXIT_INSN(),
1241 BPF_ALU64_REG(BPF_ADD, R4, R0),
1242 BPF_ALU64_REG(BPF_ADD, R4, R1),
1243 BPF_ALU64_REG(BPF_ADD, R4, R2),
1244 BPF_ALU64_REG(BPF_ADD, R4, R3),
1245 BPF_ALU64_REG(BPF_ADD, R4, R4),
1246 BPF_ALU64_REG(BPF_ADD, R4, R5),
1247 BPF_ALU64_REG(BPF_ADD, R4, R6),
1248 BPF_ALU64_REG(BPF_ADD, R4, R7),
1249 BPF_ALU64_REG(BPF_ADD, R4, R8),
1250 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1251 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1252 BPF_EXIT_INSN(),
1253 BPF_ALU64_REG(BPF_ADD, R5, R0),
1254 BPF_ALU64_REG(BPF_ADD, R5, R1),
1255 BPF_ALU64_REG(BPF_ADD, R5, R2),
1256 BPF_ALU64_REG(BPF_ADD, R5, R3),
1257 BPF_ALU64_REG(BPF_ADD, R5, R4),
1258 BPF_ALU64_REG(BPF_ADD, R5, R5),
1259 BPF_ALU64_REG(BPF_ADD, R5, R6),
1260 BPF_ALU64_REG(BPF_ADD, R5, R7),
1261 BPF_ALU64_REG(BPF_ADD, R5, R8),
1262 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1263 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1264 BPF_EXIT_INSN(),
1265 BPF_ALU64_REG(BPF_ADD, R6, R0),
1266 BPF_ALU64_REG(BPF_ADD, R6, R1),
1267 BPF_ALU64_REG(BPF_ADD, R6, R2),
1268 BPF_ALU64_REG(BPF_ADD, R6, R3),
1269 BPF_ALU64_REG(BPF_ADD, R6, R4),
1270 BPF_ALU64_REG(BPF_ADD, R6, R5),
1271 BPF_ALU64_REG(BPF_ADD, R6, R6),
1272 BPF_ALU64_REG(BPF_ADD, R6, R7),
1273 BPF_ALU64_REG(BPF_ADD, R6, R8),
1274 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1275 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1276 BPF_EXIT_INSN(),
1277 BPF_ALU64_REG(BPF_ADD, R7, R0),
1278 BPF_ALU64_REG(BPF_ADD, R7, R1),
1279 BPF_ALU64_REG(BPF_ADD, R7, R2),
1280 BPF_ALU64_REG(BPF_ADD, R7, R3),
1281 BPF_ALU64_REG(BPF_ADD, R7, R4),
1282 BPF_ALU64_REG(BPF_ADD, R7, R5),
1283 BPF_ALU64_REG(BPF_ADD, R7, R6),
1284 BPF_ALU64_REG(BPF_ADD, R7, R7),
1285 BPF_ALU64_REG(BPF_ADD, R7, R8),
1286 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1287 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1288 BPF_EXIT_INSN(),
1289 BPF_ALU64_REG(BPF_ADD, R8, R0),
1290 BPF_ALU64_REG(BPF_ADD, R8, R1),
1291 BPF_ALU64_REG(BPF_ADD, R8, R2),
1292 BPF_ALU64_REG(BPF_ADD, R8, R3),
1293 BPF_ALU64_REG(BPF_ADD, R8, R4),
1294 BPF_ALU64_REG(BPF_ADD, R8, R5),
1295 BPF_ALU64_REG(BPF_ADD, R8, R6),
1296 BPF_ALU64_REG(BPF_ADD, R8, R7),
1297 BPF_ALU64_REG(BPF_ADD, R8, R8),
1298 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1299 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1300 BPF_EXIT_INSN(),
1301 BPF_ALU64_REG(BPF_ADD, R9, R0),
1302 BPF_ALU64_REG(BPF_ADD, R9, R1),
1303 BPF_ALU64_REG(BPF_ADD, R9, R2),
1304 BPF_ALU64_REG(BPF_ADD, R9, R3),
1305 BPF_ALU64_REG(BPF_ADD, R9, R4),
1306 BPF_ALU64_REG(BPF_ADD, R9, R5),
1307 BPF_ALU64_REG(BPF_ADD, R9, R6),
1308 BPF_ALU64_REG(BPF_ADD, R9, R7),
1309 BPF_ALU64_REG(BPF_ADD, R9, R8),
1310 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1311 BPF_ALU64_REG(BPF_MOV, R0, R9),
1312 BPF_EXIT_INSN(),
1313 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001314 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001315 { },
1316 { { 0, 2957380 } }
1317 },
1318 {
1319 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001320 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001321 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1322 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1323 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1324 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1325 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1326 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1327 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1328 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1329 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1330 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1331 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1332 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1333 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1334 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1335 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1336 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1337 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1338 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1339 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1340 BPF_ALU32_REG(BPF_ADD, R0, R1),
1341 BPF_ALU32_REG(BPF_ADD, R0, R2),
1342 BPF_ALU32_REG(BPF_ADD, R0, R3),
1343 BPF_ALU32_REG(BPF_ADD, R0, R4),
1344 BPF_ALU32_REG(BPF_ADD, R0, R5),
1345 BPF_ALU32_REG(BPF_ADD, R0, R6),
1346 BPF_ALU32_REG(BPF_ADD, R0, R7),
1347 BPF_ALU32_REG(BPF_ADD, R0, R8),
1348 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1349 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1350 BPF_EXIT_INSN(),
1351 BPF_ALU32_REG(BPF_ADD, R1, R0),
1352 BPF_ALU32_REG(BPF_ADD, R1, R1),
1353 BPF_ALU32_REG(BPF_ADD, R1, R2),
1354 BPF_ALU32_REG(BPF_ADD, R1, R3),
1355 BPF_ALU32_REG(BPF_ADD, R1, R4),
1356 BPF_ALU32_REG(BPF_ADD, R1, R5),
1357 BPF_ALU32_REG(BPF_ADD, R1, R6),
1358 BPF_ALU32_REG(BPF_ADD, R1, R7),
1359 BPF_ALU32_REG(BPF_ADD, R1, R8),
1360 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1361 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1362 BPF_EXIT_INSN(),
1363 BPF_ALU32_REG(BPF_ADD, R2, R0),
1364 BPF_ALU32_REG(BPF_ADD, R2, R1),
1365 BPF_ALU32_REG(BPF_ADD, R2, R2),
1366 BPF_ALU32_REG(BPF_ADD, R2, R3),
1367 BPF_ALU32_REG(BPF_ADD, R2, R4),
1368 BPF_ALU32_REG(BPF_ADD, R2, R5),
1369 BPF_ALU32_REG(BPF_ADD, R2, R6),
1370 BPF_ALU32_REG(BPF_ADD, R2, R7),
1371 BPF_ALU32_REG(BPF_ADD, R2, R8),
1372 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1373 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1374 BPF_EXIT_INSN(),
1375 BPF_ALU32_REG(BPF_ADD, R3, R0),
1376 BPF_ALU32_REG(BPF_ADD, R3, R1),
1377 BPF_ALU32_REG(BPF_ADD, R3, R2),
1378 BPF_ALU32_REG(BPF_ADD, R3, R3),
1379 BPF_ALU32_REG(BPF_ADD, R3, R4),
1380 BPF_ALU32_REG(BPF_ADD, R3, R5),
1381 BPF_ALU32_REG(BPF_ADD, R3, R6),
1382 BPF_ALU32_REG(BPF_ADD, R3, R7),
1383 BPF_ALU32_REG(BPF_ADD, R3, R8),
1384 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1385 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1386 BPF_EXIT_INSN(),
1387 BPF_ALU32_REG(BPF_ADD, R4, R0),
1388 BPF_ALU32_REG(BPF_ADD, R4, R1),
1389 BPF_ALU32_REG(BPF_ADD, R4, R2),
1390 BPF_ALU32_REG(BPF_ADD, R4, R3),
1391 BPF_ALU32_REG(BPF_ADD, R4, R4),
1392 BPF_ALU32_REG(BPF_ADD, R4, R5),
1393 BPF_ALU32_REG(BPF_ADD, R4, R6),
1394 BPF_ALU32_REG(BPF_ADD, R4, R7),
1395 BPF_ALU32_REG(BPF_ADD, R4, R8),
1396 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1397 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1398 BPF_EXIT_INSN(),
1399 BPF_ALU32_REG(BPF_ADD, R5, R0),
1400 BPF_ALU32_REG(BPF_ADD, R5, R1),
1401 BPF_ALU32_REG(BPF_ADD, R5, R2),
1402 BPF_ALU32_REG(BPF_ADD, R5, R3),
1403 BPF_ALU32_REG(BPF_ADD, R5, R4),
1404 BPF_ALU32_REG(BPF_ADD, R5, R5),
1405 BPF_ALU32_REG(BPF_ADD, R5, R6),
1406 BPF_ALU32_REG(BPF_ADD, R5, R7),
1407 BPF_ALU32_REG(BPF_ADD, R5, R8),
1408 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1409 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1410 BPF_EXIT_INSN(),
1411 BPF_ALU32_REG(BPF_ADD, R6, R0),
1412 BPF_ALU32_REG(BPF_ADD, R6, R1),
1413 BPF_ALU32_REG(BPF_ADD, R6, R2),
1414 BPF_ALU32_REG(BPF_ADD, R6, R3),
1415 BPF_ALU32_REG(BPF_ADD, R6, R4),
1416 BPF_ALU32_REG(BPF_ADD, R6, R5),
1417 BPF_ALU32_REG(BPF_ADD, R6, R6),
1418 BPF_ALU32_REG(BPF_ADD, R6, R7),
1419 BPF_ALU32_REG(BPF_ADD, R6, R8),
1420 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1421 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1422 BPF_EXIT_INSN(),
1423 BPF_ALU32_REG(BPF_ADD, R7, R0),
1424 BPF_ALU32_REG(BPF_ADD, R7, R1),
1425 BPF_ALU32_REG(BPF_ADD, R7, R2),
1426 BPF_ALU32_REG(BPF_ADD, R7, R3),
1427 BPF_ALU32_REG(BPF_ADD, R7, R4),
1428 BPF_ALU32_REG(BPF_ADD, R7, R5),
1429 BPF_ALU32_REG(BPF_ADD, R7, R6),
1430 BPF_ALU32_REG(BPF_ADD, R7, R7),
1431 BPF_ALU32_REG(BPF_ADD, R7, R8),
1432 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1433 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1434 BPF_EXIT_INSN(),
1435 BPF_ALU32_REG(BPF_ADD, R8, R0),
1436 BPF_ALU32_REG(BPF_ADD, R8, R1),
1437 BPF_ALU32_REG(BPF_ADD, R8, R2),
1438 BPF_ALU32_REG(BPF_ADD, R8, R3),
1439 BPF_ALU32_REG(BPF_ADD, R8, R4),
1440 BPF_ALU32_REG(BPF_ADD, R8, R5),
1441 BPF_ALU32_REG(BPF_ADD, R8, R6),
1442 BPF_ALU32_REG(BPF_ADD, R8, R7),
1443 BPF_ALU32_REG(BPF_ADD, R8, R8),
1444 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1445 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1446 BPF_EXIT_INSN(),
1447 BPF_ALU32_REG(BPF_ADD, R9, R0),
1448 BPF_ALU32_REG(BPF_ADD, R9, R1),
1449 BPF_ALU32_REG(BPF_ADD, R9, R2),
1450 BPF_ALU32_REG(BPF_ADD, R9, R3),
1451 BPF_ALU32_REG(BPF_ADD, R9, R4),
1452 BPF_ALU32_REG(BPF_ADD, R9, R5),
1453 BPF_ALU32_REG(BPF_ADD, R9, R6),
1454 BPF_ALU32_REG(BPF_ADD, R9, R7),
1455 BPF_ALU32_REG(BPF_ADD, R9, R8),
1456 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1457 BPF_ALU32_REG(BPF_MOV, R0, R9),
1458 BPF_EXIT_INSN(),
1459 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001460 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001461 { },
1462 { { 0, 2957380 } }
1463 },
1464 { /* Mainly checking JIT here. */
1465 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001466 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001467 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1468 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1469 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1470 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1471 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1472 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1473 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1474 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1475 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1476 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1477 BPF_ALU64_REG(BPF_SUB, R0, R0),
1478 BPF_ALU64_REG(BPF_SUB, R0, R1),
1479 BPF_ALU64_REG(BPF_SUB, R0, R2),
1480 BPF_ALU64_REG(BPF_SUB, R0, R3),
1481 BPF_ALU64_REG(BPF_SUB, R0, R4),
1482 BPF_ALU64_REG(BPF_SUB, R0, R5),
1483 BPF_ALU64_REG(BPF_SUB, R0, R6),
1484 BPF_ALU64_REG(BPF_SUB, R0, R7),
1485 BPF_ALU64_REG(BPF_SUB, R0, R8),
1486 BPF_ALU64_REG(BPF_SUB, R0, R9),
1487 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1488 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1489 BPF_EXIT_INSN(),
1490 BPF_ALU64_REG(BPF_SUB, R1, R0),
1491 BPF_ALU64_REG(BPF_SUB, R1, R2),
1492 BPF_ALU64_REG(BPF_SUB, R1, R3),
1493 BPF_ALU64_REG(BPF_SUB, R1, R4),
1494 BPF_ALU64_REG(BPF_SUB, R1, R5),
1495 BPF_ALU64_REG(BPF_SUB, R1, R6),
1496 BPF_ALU64_REG(BPF_SUB, R1, R7),
1497 BPF_ALU64_REG(BPF_SUB, R1, R8),
1498 BPF_ALU64_REG(BPF_SUB, R1, R9),
1499 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1500 BPF_ALU64_REG(BPF_SUB, R2, R0),
1501 BPF_ALU64_REG(BPF_SUB, R2, R1),
1502 BPF_ALU64_REG(BPF_SUB, R2, R3),
1503 BPF_ALU64_REG(BPF_SUB, R2, R4),
1504 BPF_ALU64_REG(BPF_SUB, R2, R5),
1505 BPF_ALU64_REG(BPF_SUB, R2, R6),
1506 BPF_ALU64_REG(BPF_SUB, R2, R7),
1507 BPF_ALU64_REG(BPF_SUB, R2, R8),
1508 BPF_ALU64_REG(BPF_SUB, R2, R9),
1509 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1510 BPF_ALU64_REG(BPF_SUB, R3, R0),
1511 BPF_ALU64_REG(BPF_SUB, R3, R1),
1512 BPF_ALU64_REG(BPF_SUB, R3, R2),
1513 BPF_ALU64_REG(BPF_SUB, R3, R4),
1514 BPF_ALU64_REG(BPF_SUB, R3, R5),
1515 BPF_ALU64_REG(BPF_SUB, R3, R6),
1516 BPF_ALU64_REG(BPF_SUB, R3, R7),
1517 BPF_ALU64_REG(BPF_SUB, R3, R8),
1518 BPF_ALU64_REG(BPF_SUB, R3, R9),
1519 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1520 BPF_ALU64_REG(BPF_SUB, R4, R0),
1521 BPF_ALU64_REG(BPF_SUB, R4, R1),
1522 BPF_ALU64_REG(BPF_SUB, R4, R2),
1523 BPF_ALU64_REG(BPF_SUB, R4, R3),
1524 BPF_ALU64_REG(BPF_SUB, R4, R5),
1525 BPF_ALU64_REG(BPF_SUB, R4, R6),
1526 BPF_ALU64_REG(BPF_SUB, R4, R7),
1527 BPF_ALU64_REG(BPF_SUB, R4, R8),
1528 BPF_ALU64_REG(BPF_SUB, R4, R9),
1529 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1530 BPF_ALU64_REG(BPF_SUB, R5, R0),
1531 BPF_ALU64_REG(BPF_SUB, R5, R1),
1532 BPF_ALU64_REG(BPF_SUB, R5, R2),
1533 BPF_ALU64_REG(BPF_SUB, R5, R3),
1534 BPF_ALU64_REG(BPF_SUB, R5, R4),
1535 BPF_ALU64_REG(BPF_SUB, R5, R6),
1536 BPF_ALU64_REG(BPF_SUB, R5, R7),
1537 BPF_ALU64_REG(BPF_SUB, R5, R8),
1538 BPF_ALU64_REG(BPF_SUB, R5, R9),
1539 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1540 BPF_ALU64_REG(BPF_SUB, R6, R0),
1541 BPF_ALU64_REG(BPF_SUB, R6, R1),
1542 BPF_ALU64_REG(BPF_SUB, R6, R2),
1543 BPF_ALU64_REG(BPF_SUB, R6, R3),
1544 BPF_ALU64_REG(BPF_SUB, R6, R4),
1545 BPF_ALU64_REG(BPF_SUB, R6, R5),
1546 BPF_ALU64_REG(BPF_SUB, R6, R7),
1547 BPF_ALU64_REG(BPF_SUB, R6, R8),
1548 BPF_ALU64_REG(BPF_SUB, R6, R9),
1549 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1550 BPF_ALU64_REG(BPF_SUB, R7, R0),
1551 BPF_ALU64_REG(BPF_SUB, R7, R1),
1552 BPF_ALU64_REG(BPF_SUB, R7, R2),
1553 BPF_ALU64_REG(BPF_SUB, R7, R3),
1554 BPF_ALU64_REG(BPF_SUB, R7, R4),
1555 BPF_ALU64_REG(BPF_SUB, R7, R5),
1556 BPF_ALU64_REG(BPF_SUB, R7, R6),
1557 BPF_ALU64_REG(BPF_SUB, R7, R8),
1558 BPF_ALU64_REG(BPF_SUB, R7, R9),
1559 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1560 BPF_ALU64_REG(BPF_SUB, R8, R0),
1561 BPF_ALU64_REG(BPF_SUB, R8, R1),
1562 BPF_ALU64_REG(BPF_SUB, R8, R2),
1563 BPF_ALU64_REG(BPF_SUB, R8, R3),
1564 BPF_ALU64_REG(BPF_SUB, R8, R4),
1565 BPF_ALU64_REG(BPF_SUB, R8, R5),
1566 BPF_ALU64_REG(BPF_SUB, R8, R6),
1567 BPF_ALU64_REG(BPF_SUB, R8, R7),
1568 BPF_ALU64_REG(BPF_SUB, R8, R9),
1569 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1570 BPF_ALU64_REG(BPF_SUB, R9, R0),
1571 BPF_ALU64_REG(BPF_SUB, R9, R1),
1572 BPF_ALU64_REG(BPF_SUB, R9, R2),
1573 BPF_ALU64_REG(BPF_SUB, R9, R3),
1574 BPF_ALU64_REG(BPF_SUB, R9, R4),
1575 BPF_ALU64_REG(BPF_SUB, R9, R5),
1576 BPF_ALU64_REG(BPF_SUB, R9, R6),
1577 BPF_ALU64_REG(BPF_SUB, R9, R7),
1578 BPF_ALU64_REG(BPF_SUB, R9, R8),
1579 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1580 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1581 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1582 BPF_ALU64_REG(BPF_SUB, R0, R1),
1583 BPF_ALU64_REG(BPF_SUB, R0, R2),
1584 BPF_ALU64_REG(BPF_SUB, R0, R3),
1585 BPF_ALU64_REG(BPF_SUB, R0, R4),
1586 BPF_ALU64_REG(BPF_SUB, R0, R5),
1587 BPF_ALU64_REG(BPF_SUB, R0, R6),
1588 BPF_ALU64_REG(BPF_SUB, R0, R7),
1589 BPF_ALU64_REG(BPF_SUB, R0, R8),
1590 BPF_ALU64_REG(BPF_SUB, R0, R9),
1591 BPF_EXIT_INSN(),
1592 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001593 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001594 { },
1595 { { 0, 11 } }
1596 },
1597 { /* Mainly checking JIT here. */
1598 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001599 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001600 BPF_ALU64_REG(BPF_SUB, R0, R0),
1601 BPF_ALU64_REG(BPF_XOR, R1, R1),
1602 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1603 BPF_EXIT_INSN(),
1604 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1605 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1606 BPF_ALU64_REG(BPF_SUB, R1, R1),
1607 BPF_ALU64_REG(BPF_XOR, R2, R2),
1608 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1609 BPF_EXIT_INSN(),
1610 BPF_ALU64_REG(BPF_SUB, R2, R2),
1611 BPF_ALU64_REG(BPF_XOR, R3, R3),
1612 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1613 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1614 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1615 BPF_EXIT_INSN(),
1616 BPF_ALU64_REG(BPF_SUB, R3, R3),
1617 BPF_ALU64_REG(BPF_XOR, R4, R4),
1618 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1619 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1620 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1621 BPF_EXIT_INSN(),
1622 BPF_ALU64_REG(BPF_SUB, R4, R4),
1623 BPF_ALU64_REG(BPF_XOR, R5, R5),
1624 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1625 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1626 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1627 BPF_EXIT_INSN(),
1628 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1629 BPF_ALU64_REG(BPF_SUB, R5, R5),
1630 BPF_ALU64_REG(BPF_XOR, R6, R6),
1631 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1632 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1633 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1634 BPF_EXIT_INSN(),
1635 BPF_ALU64_REG(BPF_SUB, R6, R6),
1636 BPF_ALU64_REG(BPF_XOR, R7, R7),
1637 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1638 BPF_EXIT_INSN(),
1639 BPF_ALU64_REG(BPF_SUB, R7, R7),
1640 BPF_ALU64_REG(BPF_XOR, R8, R8),
1641 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1642 BPF_EXIT_INSN(),
1643 BPF_ALU64_REG(BPF_SUB, R8, R8),
1644 BPF_ALU64_REG(BPF_XOR, R9, R9),
1645 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1646 BPF_EXIT_INSN(),
1647 BPF_ALU64_REG(BPF_SUB, R9, R9),
1648 BPF_ALU64_REG(BPF_XOR, R0, R0),
1649 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1650 BPF_EXIT_INSN(),
1651 BPF_ALU64_REG(BPF_SUB, R1, R1),
1652 BPF_ALU64_REG(BPF_XOR, R0, R0),
1653 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1654 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1655 BPF_EXIT_INSN(),
1656 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1657 BPF_EXIT_INSN(),
1658 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001659 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001660 { },
1661 { { 0, 1 } }
1662 },
1663 { /* Mainly checking JIT here. */
1664 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001665 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001666 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1667 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1668 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1669 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1670 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1671 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1672 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1673 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1674 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1675 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1676 BPF_ALU64_REG(BPF_MUL, R0, R0),
1677 BPF_ALU64_REG(BPF_MUL, R0, R1),
1678 BPF_ALU64_REG(BPF_MUL, R0, R2),
1679 BPF_ALU64_REG(BPF_MUL, R0, R3),
1680 BPF_ALU64_REG(BPF_MUL, R0, R4),
1681 BPF_ALU64_REG(BPF_MUL, R0, R5),
1682 BPF_ALU64_REG(BPF_MUL, R0, R6),
1683 BPF_ALU64_REG(BPF_MUL, R0, R7),
1684 BPF_ALU64_REG(BPF_MUL, R0, R8),
1685 BPF_ALU64_REG(BPF_MUL, R0, R9),
1686 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1687 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1688 BPF_EXIT_INSN(),
1689 BPF_ALU64_REG(BPF_MUL, R1, R0),
1690 BPF_ALU64_REG(BPF_MUL, R1, R2),
1691 BPF_ALU64_REG(BPF_MUL, R1, R3),
1692 BPF_ALU64_REG(BPF_MUL, R1, R4),
1693 BPF_ALU64_REG(BPF_MUL, R1, R5),
1694 BPF_ALU64_REG(BPF_MUL, R1, R6),
1695 BPF_ALU64_REG(BPF_MUL, R1, R7),
1696 BPF_ALU64_REG(BPF_MUL, R1, R8),
1697 BPF_ALU64_REG(BPF_MUL, R1, R9),
1698 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1699 BPF_ALU64_REG(BPF_MOV, R2, R1),
1700 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1701 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1702 BPF_EXIT_INSN(),
1703 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1704 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1705 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1706 BPF_EXIT_INSN(),
1707 BPF_ALU64_REG(BPF_MUL, R2, R0),
1708 BPF_ALU64_REG(BPF_MUL, R2, R1),
1709 BPF_ALU64_REG(BPF_MUL, R2, R3),
1710 BPF_ALU64_REG(BPF_MUL, R2, R4),
1711 BPF_ALU64_REG(BPF_MUL, R2, R5),
1712 BPF_ALU64_REG(BPF_MUL, R2, R6),
1713 BPF_ALU64_REG(BPF_MUL, R2, R7),
1714 BPF_ALU64_REG(BPF_MUL, R2, R8),
1715 BPF_ALU64_REG(BPF_MUL, R2, R9),
1716 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1717 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1718 BPF_ALU64_REG(BPF_MOV, R0, R2),
1719 BPF_EXIT_INSN(),
1720 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001721 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001722 { },
1723 { { 0, 0x35d97ef2 } }
1724 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001725 { /* Mainly checking JIT here. */
1726 "MOV REG64",
1727 .u.insns_int = {
1728 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1729 BPF_MOV64_REG(R1, R0),
1730 BPF_MOV64_REG(R2, R1),
1731 BPF_MOV64_REG(R3, R2),
1732 BPF_MOV64_REG(R4, R3),
1733 BPF_MOV64_REG(R5, R4),
1734 BPF_MOV64_REG(R6, R5),
1735 BPF_MOV64_REG(R7, R6),
1736 BPF_MOV64_REG(R8, R7),
1737 BPF_MOV64_REG(R9, R8),
1738 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1739 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1740 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1741 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1742 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1743 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1744 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1745 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1746 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1747 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1748 BPF_ALU64_REG(BPF_ADD, R0, R0),
1749 BPF_ALU64_REG(BPF_ADD, R0, R1),
1750 BPF_ALU64_REG(BPF_ADD, R0, R2),
1751 BPF_ALU64_REG(BPF_ADD, R0, R3),
1752 BPF_ALU64_REG(BPF_ADD, R0, R4),
1753 BPF_ALU64_REG(BPF_ADD, R0, R5),
1754 BPF_ALU64_REG(BPF_ADD, R0, R6),
1755 BPF_ALU64_REG(BPF_ADD, R0, R7),
1756 BPF_ALU64_REG(BPF_ADD, R0, R8),
1757 BPF_ALU64_REG(BPF_ADD, R0, R9),
1758 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1759 BPF_EXIT_INSN(),
1760 },
1761 INTERNAL,
1762 { },
1763 { { 0, 0xfefe } }
1764 },
1765 { /* Mainly checking JIT here. */
1766 "MOV REG32",
1767 .u.insns_int = {
1768 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1769 BPF_MOV64_REG(R1, R0),
1770 BPF_MOV64_REG(R2, R1),
1771 BPF_MOV64_REG(R3, R2),
1772 BPF_MOV64_REG(R4, R3),
1773 BPF_MOV64_REG(R5, R4),
1774 BPF_MOV64_REG(R6, R5),
1775 BPF_MOV64_REG(R7, R6),
1776 BPF_MOV64_REG(R8, R7),
1777 BPF_MOV64_REG(R9, R8),
1778 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1779 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1780 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1781 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1782 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1783 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1784 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1785 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1786 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1787 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1788 BPF_ALU64_REG(BPF_ADD, R0, R0),
1789 BPF_ALU64_REG(BPF_ADD, R0, R1),
1790 BPF_ALU64_REG(BPF_ADD, R0, R2),
1791 BPF_ALU64_REG(BPF_ADD, R0, R3),
1792 BPF_ALU64_REG(BPF_ADD, R0, R4),
1793 BPF_ALU64_REG(BPF_ADD, R0, R5),
1794 BPF_ALU64_REG(BPF_ADD, R0, R6),
1795 BPF_ALU64_REG(BPF_ADD, R0, R7),
1796 BPF_ALU64_REG(BPF_ADD, R0, R8),
1797 BPF_ALU64_REG(BPF_ADD, R0, R9),
1798 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1799 BPF_EXIT_INSN(),
1800 },
1801 INTERNAL,
1802 { },
1803 { { 0, 0xfefe } }
1804 },
1805 { /* Mainly checking JIT here. */
1806 "LD IMM64",
1807 .u.insns_int = {
1808 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1809 BPF_MOV64_REG(R1, R0),
1810 BPF_MOV64_REG(R2, R1),
1811 BPF_MOV64_REG(R3, R2),
1812 BPF_MOV64_REG(R4, R3),
1813 BPF_MOV64_REG(R5, R4),
1814 BPF_MOV64_REG(R6, R5),
1815 BPF_MOV64_REG(R7, R6),
1816 BPF_MOV64_REG(R8, R7),
1817 BPF_MOV64_REG(R9, R8),
1818 BPF_LD_IMM64(R0, 0x0LL),
1819 BPF_LD_IMM64(R1, 0x0LL),
1820 BPF_LD_IMM64(R2, 0x0LL),
1821 BPF_LD_IMM64(R3, 0x0LL),
1822 BPF_LD_IMM64(R4, 0x0LL),
1823 BPF_LD_IMM64(R5, 0x0LL),
1824 BPF_LD_IMM64(R6, 0x0LL),
1825 BPF_LD_IMM64(R7, 0x0LL),
1826 BPF_LD_IMM64(R8, 0x0LL),
1827 BPF_LD_IMM64(R9, 0x0LL),
1828 BPF_ALU64_REG(BPF_ADD, R0, R0),
1829 BPF_ALU64_REG(BPF_ADD, R0, R1),
1830 BPF_ALU64_REG(BPF_ADD, R0, R2),
1831 BPF_ALU64_REG(BPF_ADD, R0, R3),
1832 BPF_ALU64_REG(BPF_ADD, R0, R4),
1833 BPF_ALU64_REG(BPF_ADD, R0, R5),
1834 BPF_ALU64_REG(BPF_ADD, R0, R6),
1835 BPF_ALU64_REG(BPF_ADD, R0, R7),
1836 BPF_ALU64_REG(BPF_ADD, R0, R8),
1837 BPF_ALU64_REG(BPF_ADD, R0, R9),
1838 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1839 BPF_EXIT_INSN(),
1840 },
1841 INTERNAL,
1842 { },
1843 { { 0, 0xfefe } }
1844 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001845 {
1846 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001847 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001848 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1849 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1850 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1851 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1852 BPF_ALU64_REG(BPF_DIV, R0, R2),
1853 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1854 BPF_EXIT_INSN(),
1855 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1856 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1857 BPF_EXIT_INSN(),
1858 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1859 BPF_EXIT_INSN(),
1860 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001861 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001862 { },
1863 { { 0, -1 } }
1864 },
1865 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001866 "INT: shifts by register",
1867 .u.insns_int = {
1868 BPF_MOV64_IMM(R0, -1234),
1869 BPF_MOV64_IMM(R1, 1),
1870 BPF_ALU32_REG(BPF_RSH, R0, R1),
1871 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1872 BPF_EXIT_INSN(),
1873 BPF_MOV64_IMM(R2, 1),
1874 BPF_ALU64_REG(BPF_LSH, R0, R2),
1875 BPF_MOV32_IMM(R4, -1234),
1876 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1877 BPF_EXIT_INSN(),
1878 BPF_ALU64_IMM(BPF_AND, R4, 63),
1879 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1880 BPF_MOV64_IMM(R3, 47),
1881 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1882 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1883 BPF_EXIT_INSN(),
1884 BPF_MOV64_IMM(R2, 1),
1885 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1886 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1887 BPF_EXIT_INSN(),
1888 BPF_MOV64_IMM(R4, 4),
1889 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1890 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1891 BPF_EXIT_INSN(),
1892 BPF_MOV64_IMM(R4, 5),
1893 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1894 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1895 BPF_EXIT_INSN(),
1896 BPF_MOV64_IMM(R0, -1),
1897 BPF_EXIT_INSN(),
1898 },
1899 INTERNAL,
1900 { },
1901 { { 0, -1 } }
1902 },
1903 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001904 "INT: DIV + ABS",
Andrew Mortonece80492014-05-22 10:16:46 -07001905 .u.insns_int = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001906 BPF_ALU64_REG(BPF_MOV, R6, R1),
1907 BPF_LD_ABS(BPF_B, 3),
1908 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1909 BPF_ALU32_REG(BPF_DIV, R0, R2),
1910 BPF_ALU64_REG(BPF_MOV, R8, R0),
1911 BPF_LD_ABS(BPF_B, 4),
1912 BPF_ALU64_REG(BPF_ADD, R8, R0),
1913 BPF_LD_IND(BPF_B, R8, -70),
1914 BPF_EXIT_INSN(),
1915 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001916 INTERNAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001917 { 10, 20, 30, 40, 50 },
1918 { { 4, 0 }, { 5, 10 } }
1919 },
1920 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001921 "INT: DIV by zero",
Andrew Mortonece80492014-05-22 10:16:46 -07001922 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001923 BPF_ALU64_REG(BPF_MOV, R6, R1),
1924 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1925 BPF_LD_ABS(BPF_B, 3),
1926 BPF_ALU32_REG(BPF_DIV, R0, R7),
1927 BPF_EXIT_INSN(),
1928 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001929 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001930 { 10, 20, 30, 40, 50 },
1931 { { 3, 0 }, { 4, 0 } }
1932 },
1933 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001934 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07001935 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001936 BPF_STMT(BPF_LD | BPF_IMM, 1),
1937 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001938 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001939 { },
1940 { }
1941 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001942 {
1943 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07001944 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001945 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1946 BPF_STMT(BPF_RET | BPF_K, 0)
1947 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001948 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001949 { },
1950 { }
1951 },
1952 {
1953 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07001954 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001955 /* seccomp insn, rejected in socket filter */
1956 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1957 BPF_STMT(BPF_RET | BPF_K, 0)
1958 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001959 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001960 { },
1961 { }
1962 },
1963 {
1964 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07001965 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001966 BPF_STMT(BPF_STX, 16),
1967 BPF_STMT(BPF_RET | BPF_K, 0)
1968 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001969 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001970 { },
1971 { }
1972 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001973 {
1974 "JUMPS + HOLES",
1975 .u.insns = {
1976 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1977 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1978 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1979 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1980 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1981 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1982 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1983 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1984 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1985 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1986 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1987 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1988 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1989 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1990 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1991 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1992 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1993 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1994 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1995 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1996 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1997 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1998 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1999 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2000 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2001 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2002 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2003 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2004 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2005 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2007 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2008 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2009 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2010 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2011 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2012 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2013 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2014 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2016 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2017 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2018 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2019 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2020 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2021 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2022 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2023 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2024 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2025 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2026 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2027 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2028 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2029 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2030 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2031 BPF_STMT(BPF_RET | BPF_A, 0),
2032 BPF_STMT(BPF_RET | BPF_A, 0),
2033 },
2034 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002035 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2036 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2037 0x08, 0x00,
2038 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2039 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2040 0xc0, 0xa8, 0x33, 0x01,
2041 0xc0, 0xa8, 0x33, 0x02,
2042 0xbb, 0xb6,
2043 0xa9, 0xfa,
2044 0x00, 0x14, 0x00, 0x00,
2045 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2046 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2047 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2048 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2049 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2050 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2051 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2052 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002053 { { 88, 0x001b } }
2054 },
2055 {
2056 "check: RET X",
2057 .u.insns = {
2058 BPF_STMT(BPF_RET | BPF_X, 0),
2059 },
2060 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2061 { },
2062 { },
2063 },
2064 {
2065 "check: LDX + RET X",
2066 .u.insns = {
2067 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2068 BPF_STMT(BPF_RET | BPF_X, 0),
2069 },
2070 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2071 { },
2072 { },
2073 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002074 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002075 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002076 .u.insns = {
2077 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2078 BPF_STMT(BPF_STX, 0),
2079 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2080 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2081 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2082 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2083 BPF_STMT(BPF_STX, 1),
2084 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2085 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2086 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2087 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2088 BPF_STMT(BPF_STX, 2),
2089 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2090 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2091 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2092 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2093 BPF_STMT(BPF_STX, 3),
2094 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2095 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2096 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2097 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2098 BPF_STMT(BPF_STX, 4),
2099 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2100 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2101 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2102 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2103 BPF_STMT(BPF_STX, 5),
2104 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2105 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2106 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2107 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2108 BPF_STMT(BPF_STX, 6),
2109 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2110 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2111 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2112 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2113 BPF_STMT(BPF_STX, 7),
2114 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2115 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2116 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2117 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2118 BPF_STMT(BPF_STX, 8),
2119 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2120 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2121 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2122 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2123 BPF_STMT(BPF_STX, 9),
2124 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2125 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2126 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2127 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2128 BPF_STMT(BPF_STX, 10),
2129 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2130 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2131 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2132 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2133 BPF_STMT(BPF_STX, 11),
2134 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2135 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2136 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2137 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2138 BPF_STMT(BPF_STX, 12),
2139 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2140 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2141 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2142 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2143 BPF_STMT(BPF_STX, 13),
2144 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2145 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2146 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2147 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2148 BPF_STMT(BPF_STX, 14),
2149 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2150 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2151 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2152 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2153 BPF_STMT(BPF_STX, 15),
2154 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2155 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2156 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2157 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2158 BPF_STMT(BPF_RET | BPF_A, 0),
2159 },
2160 CLASSIC | FLAG_NO_DATA,
2161 { },
2162 { { 0, 116 } },
2163 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002164 { /* Mainly checking JIT here. */
2165 "M[]: full STX + full LDX",
2166 .u.insns = {
2167 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2168 BPF_STMT(BPF_STX, 0),
2169 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2170 BPF_STMT(BPF_STX, 1),
2171 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2172 BPF_STMT(BPF_STX, 2),
2173 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2174 BPF_STMT(BPF_STX, 3),
2175 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2176 BPF_STMT(BPF_STX, 4),
2177 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2178 BPF_STMT(BPF_STX, 5),
2179 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2180 BPF_STMT(BPF_STX, 6),
2181 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2182 BPF_STMT(BPF_STX, 7),
2183 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2184 BPF_STMT(BPF_STX, 8),
2185 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2186 BPF_STMT(BPF_STX, 9),
2187 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2188 BPF_STMT(BPF_STX, 10),
2189 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2190 BPF_STMT(BPF_STX, 11),
2191 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2192 BPF_STMT(BPF_STX, 12),
2193 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2194 BPF_STMT(BPF_STX, 13),
2195 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2196 BPF_STMT(BPF_STX, 14),
2197 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2198 BPF_STMT(BPF_STX, 15),
2199 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2200 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2201 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2202 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2203 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2204 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2205 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2207 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2208 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2209 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2210 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2211 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2212 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2213 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2214 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2215 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2216 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2217 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2218 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2219 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2220 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2221 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2222 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2223 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2224 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2225 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2227 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2228 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2229 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2230 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2231 BPF_STMT(BPF_RET | BPF_A, 0),
2232 },
2233 CLASSIC | FLAG_NO_DATA,
2234 { },
2235 { { 0, 0x2a5a5e5 } },
2236 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002237 {
2238 "check: SKF_AD_MAX",
2239 .u.insns = {
2240 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2241 SKF_AD_OFF + SKF_AD_MAX),
2242 BPF_STMT(BPF_RET | BPF_A, 0),
2243 },
2244 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2245 { },
2246 { },
2247 },
2248 { /* Passes checker but fails during runtime. */
2249 "LD [SKF_AD_OFF-1]",
2250 .u.insns = {
2251 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2252 SKF_AD_OFF - 1),
2253 BPF_STMT(BPF_RET | BPF_K, 1),
2254 },
2255 CLASSIC,
2256 { },
2257 { { 1, 0 } },
2258 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002259 {
2260 "load 64-bit immediate",
2261 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002262 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002263 BPF_MOV64_REG(R2, R1),
2264 BPF_MOV64_REG(R3, R2),
2265 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2266 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2267 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2268 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2269 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2270 BPF_EXIT_INSN(),
2271 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2272 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002273 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2274 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002275 BPF_EXIT_INSN(),
2276 },
2277 INTERNAL,
2278 { },
2279 { { 0, 1 } }
2280 },
Alexei Starovoitove21ab362014-10-28 15:11:43 -07002281 {
2282 "nmap reduced",
2283 .u.insns_int = {
2284 BPF_MOV64_REG(R6, R1),
2285 BPF_LD_ABS(BPF_H, 12),
2286 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2287 BPF_LD_ABS(BPF_H, 12),
2288 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2289 BPF_MOV32_IMM(R0, 18),
2290 BPF_STX_MEM(BPF_W, R10, R0, -64),
2291 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2292 BPF_LD_IND(BPF_W, R7, 14),
2293 BPF_STX_MEM(BPF_W, R10, R0, -60),
2294 BPF_MOV32_IMM(R0, 280971478),
2295 BPF_STX_MEM(BPF_W, R10, R0, -56),
2296 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2297 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2298 BPF_ALU32_REG(BPF_SUB, R0, R7),
2299 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2300 BPF_LD_ABS(BPF_H, 12),
2301 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2302 BPF_MOV32_IMM(R0, 22),
2303 BPF_STX_MEM(BPF_W, R10, R0, -56),
2304 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2305 BPF_LD_IND(BPF_H, R7, 14),
2306 BPF_STX_MEM(BPF_W, R10, R0, -52),
2307 BPF_MOV32_IMM(R0, 17366),
2308 BPF_STX_MEM(BPF_W, R10, R0, -48),
2309 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2310 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2311 BPF_ALU32_REG(BPF_SUB, R0, R7),
2312 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2313 BPF_MOV32_IMM(R0, 256),
2314 BPF_EXIT_INSN(),
2315 BPF_MOV32_IMM(R0, 0),
2316 BPF_EXIT_INSN(),
2317 },
2318 INTERNAL,
2319 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2320 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2321 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
Alexei Starovoitov105c0362017-05-30 13:31:32 -07002322 { { 38, 256 } },
2323 .stack_depth = 64,
Alexei Starovoitove21ab362014-10-28 15:11:43 -07002324 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002325 /* BPF_ALU | BPF_MOV | BPF_X */
2326 {
2327 "ALU_MOV_X: dst = 2",
2328 .u.insns_int = {
2329 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2330 BPF_ALU32_REG(BPF_MOV, R0, R1),
2331 BPF_EXIT_INSN(),
2332 },
2333 INTERNAL,
2334 { },
2335 { { 0, 2 } },
2336 },
2337 {
2338 "ALU_MOV_X: dst = 4294967295",
2339 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002340 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002341 BPF_ALU32_REG(BPF_MOV, R0, R1),
2342 BPF_EXIT_INSN(),
2343 },
2344 INTERNAL,
2345 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002346 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002347 },
2348 {
2349 "ALU64_MOV_X: dst = 2",
2350 .u.insns_int = {
2351 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2352 BPF_ALU64_REG(BPF_MOV, R0, R1),
2353 BPF_EXIT_INSN(),
2354 },
2355 INTERNAL,
2356 { },
2357 { { 0, 2 } },
2358 },
2359 {
2360 "ALU64_MOV_X: dst = 4294967295",
2361 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002362 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002363 BPF_ALU64_REG(BPF_MOV, R0, R1),
2364 BPF_EXIT_INSN(),
2365 },
2366 INTERNAL,
2367 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002368 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002369 },
2370 /* BPF_ALU | BPF_MOV | BPF_K */
2371 {
2372 "ALU_MOV_K: dst = 2",
2373 .u.insns_int = {
2374 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2375 BPF_EXIT_INSN(),
2376 },
2377 INTERNAL,
2378 { },
2379 { { 0, 2 } },
2380 },
2381 {
2382 "ALU_MOV_K: dst = 4294967295",
2383 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002384 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002385 BPF_EXIT_INSN(),
2386 },
2387 INTERNAL,
2388 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002389 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002390 },
2391 {
2392 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2393 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002394 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2395 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002396 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2397 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2398 BPF_MOV32_IMM(R0, 2),
2399 BPF_EXIT_INSN(),
2400 BPF_MOV32_IMM(R0, 1),
2401 BPF_EXIT_INSN(),
2402 },
2403 INTERNAL,
2404 { },
2405 { { 0, 0x1 } },
2406 },
2407 {
2408 "ALU64_MOV_K: dst = 2",
2409 .u.insns_int = {
2410 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2411 BPF_EXIT_INSN(),
2412 },
2413 INTERNAL,
2414 { },
2415 { { 0, 2 } },
2416 },
2417 {
2418 "ALU64_MOV_K: dst = 2147483647",
2419 .u.insns_int = {
2420 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2421 BPF_EXIT_INSN(),
2422 },
2423 INTERNAL,
2424 { },
2425 { { 0, 2147483647 } },
2426 },
2427 {
2428 "ALU64_OR_K: dst = 0x0",
2429 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002430 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002431 BPF_LD_IMM64(R3, 0x0),
2432 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2433 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2434 BPF_MOV32_IMM(R0, 2),
2435 BPF_EXIT_INSN(),
2436 BPF_MOV32_IMM(R0, 1),
2437 BPF_EXIT_INSN(),
2438 },
2439 INTERNAL,
2440 { },
2441 { { 0, 0x1 } },
2442 },
2443 {
2444 "ALU64_MOV_K: dst = -1",
2445 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002446 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2447 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002448 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2449 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2450 BPF_MOV32_IMM(R0, 2),
2451 BPF_EXIT_INSN(),
2452 BPF_MOV32_IMM(R0, 1),
2453 BPF_EXIT_INSN(),
2454 },
2455 INTERNAL,
2456 { },
2457 { { 0, 0x1 } },
2458 },
2459 /* BPF_ALU | BPF_ADD | BPF_X */
2460 {
2461 "ALU_ADD_X: 1 + 2 = 3",
2462 .u.insns_int = {
2463 BPF_LD_IMM64(R0, 1),
2464 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2465 BPF_ALU32_REG(BPF_ADD, R0, R1),
2466 BPF_EXIT_INSN(),
2467 },
2468 INTERNAL,
2469 { },
2470 { { 0, 3 } },
2471 },
2472 {
2473 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2474 .u.insns_int = {
2475 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002476 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002477 BPF_ALU32_REG(BPF_ADD, R0, R1),
2478 BPF_EXIT_INSN(),
2479 },
2480 INTERNAL,
2481 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002482 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002483 },
2484 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302485 "ALU_ADD_X: 2 + 4294967294 = 0",
2486 .u.insns_int = {
2487 BPF_LD_IMM64(R0, 2),
2488 BPF_LD_IMM64(R1, 4294967294U),
2489 BPF_ALU32_REG(BPF_ADD, R0, R1),
2490 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2491 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2492 BPF_EXIT_INSN(),
2493 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2494 BPF_EXIT_INSN(),
2495 },
2496 INTERNAL,
2497 { },
2498 { { 0, 1 } },
2499 },
2500 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002501 "ALU64_ADD_X: 1 + 2 = 3",
2502 .u.insns_int = {
2503 BPF_LD_IMM64(R0, 1),
2504 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2505 BPF_ALU64_REG(BPF_ADD, R0, R1),
2506 BPF_EXIT_INSN(),
2507 },
2508 INTERNAL,
2509 { },
2510 { { 0, 3 } },
2511 },
2512 {
2513 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2514 .u.insns_int = {
2515 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002516 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002517 BPF_ALU64_REG(BPF_ADD, R0, R1),
2518 BPF_EXIT_INSN(),
2519 },
2520 INTERNAL,
2521 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002522 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002523 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302524 {
2525 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2526 .u.insns_int = {
2527 BPF_LD_IMM64(R0, 2),
2528 BPF_LD_IMM64(R1, 4294967294U),
2529 BPF_LD_IMM64(R2, 4294967296ULL),
2530 BPF_ALU64_REG(BPF_ADD, R0, R1),
2531 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2532 BPF_MOV32_IMM(R0, 0),
2533 BPF_EXIT_INSN(),
2534 BPF_MOV32_IMM(R0, 1),
2535 BPF_EXIT_INSN(),
2536 },
2537 INTERNAL,
2538 { },
2539 { { 0, 1 } },
2540 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002541 /* BPF_ALU | BPF_ADD | BPF_K */
2542 {
2543 "ALU_ADD_K: 1 + 2 = 3",
2544 .u.insns_int = {
2545 BPF_LD_IMM64(R0, 1),
2546 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2547 BPF_EXIT_INSN(),
2548 },
2549 INTERNAL,
2550 { },
2551 { { 0, 3 } },
2552 },
2553 {
2554 "ALU_ADD_K: 3 + 0 = 3",
2555 .u.insns_int = {
2556 BPF_LD_IMM64(R0, 3),
2557 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2558 BPF_EXIT_INSN(),
2559 },
2560 INTERNAL,
2561 { },
2562 { { 0, 3 } },
2563 },
2564 {
2565 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2566 .u.insns_int = {
2567 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002568 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002569 BPF_EXIT_INSN(),
2570 },
2571 INTERNAL,
2572 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002573 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002574 },
2575 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302576 "ALU_ADD_K: 4294967294 + 2 = 0",
2577 .u.insns_int = {
2578 BPF_LD_IMM64(R0, 4294967294U),
2579 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2580 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2581 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2582 BPF_EXIT_INSN(),
2583 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2584 BPF_EXIT_INSN(),
2585 },
2586 INTERNAL,
2587 { },
2588 { { 0, 1 } },
2589 },
2590 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002591 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2592 .u.insns_int = {
2593 BPF_LD_IMM64(R2, 0x0),
2594 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2595 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2596 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2597 BPF_MOV32_IMM(R0, 2),
2598 BPF_EXIT_INSN(),
2599 BPF_MOV32_IMM(R0, 1),
2600 BPF_EXIT_INSN(),
2601 },
2602 INTERNAL,
2603 { },
2604 { { 0, 0x1 } },
2605 },
2606 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302607 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2608 .u.insns_int = {
2609 BPF_LD_IMM64(R2, 0x0),
2610 BPF_LD_IMM64(R3, 0xffff),
2611 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2612 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2613 BPF_MOV32_IMM(R0, 2),
2614 BPF_EXIT_INSN(),
2615 BPF_MOV32_IMM(R0, 1),
2616 BPF_EXIT_INSN(),
2617 },
2618 INTERNAL,
2619 { },
2620 { { 0, 0x1 } },
2621 },
2622 {
2623 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2624 .u.insns_int = {
2625 BPF_LD_IMM64(R2, 0x0),
2626 BPF_LD_IMM64(R3, 0x7fffffff),
2627 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2628 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2629 BPF_MOV32_IMM(R0, 2),
2630 BPF_EXIT_INSN(),
2631 BPF_MOV32_IMM(R0, 1),
2632 BPF_EXIT_INSN(),
2633 },
2634 INTERNAL,
2635 { },
2636 { { 0, 0x1 } },
2637 },
2638 {
2639 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2640 .u.insns_int = {
2641 BPF_LD_IMM64(R2, 0x0),
2642 BPF_LD_IMM64(R3, 0x80000000),
2643 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2644 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2645 BPF_MOV32_IMM(R0, 2),
2646 BPF_EXIT_INSN(),
2647 BPF_MOV32_IMM(R0, 1),
2648 BPF_EXIT_INSN(),
2649 },
2650 INTERNAL,
2651 { },
2652 { { 0, 0x1 } },
2653 },
2654 {
2655 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2656 .u.insns_int = {
2657 BPF_LD_IMM64(R2, 0x0),
2658 BPF_LD_IMM64(R3, 0x80008000),
2659 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2660 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2661 BPF_MOV32_IMM(R0, 2),
2662 BPF_EXIT_INSN(),
2663 BPF_MOV32_IMM(R0, 1),
2664 BPF_EXIT_INSN(),
2665 },
2666 INTERNAL,
2667 { },
2668 { { 0, 0x1 } },
2669 },
2670 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002671 "ALU64_ADD_K: 1 + 2 = 3",
2672 .u.insns_int = {
2673 BPF_LD_IMM64(R0, 1),
2674 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2675 BPF_EXIT_INSN(),
2676 },
2677 INTERNAL,
2678 { },
2679 { { 0, 3 } },
2680 },
2681 {
2682 "ALU64_ADD_K: 3 + 0 = 3",
2683 .u.insns_int = {
2684 BPF_LD_IMM64(R0, 3),
2685 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2686 BPF_EXIT_INSN(),
2687 },
2688 INTERNAL,
2689 { },
2690 { { 0, 3 } },
2691 },
2692 {
2693 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2694 .u.insns_int = {
2695 BPF_LD_IMM64(R0, 1),
2696 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2697 BPF_EXIT_INSN(),
2698 },
2699 INTERNAL,
2700 { },
2701 { { 0, 2147483647 } },
2702 },
2703 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302704 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2705 .u.insns_int = {
2706 BPF_LD_IMM64(R0, 4294967294U),
2707 BPF_LD_IMM64(R1, 4294967296ULL),
2708 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2709 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2710 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2711 BPF_EXIT_INSN(),
2712 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2713 BPF_EXIT_INSN(),
2714 },
2715 INTERNAL,
2716 { },
2717 { { 0, 1 } },
2718 },
2719 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002720 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2721 .u.insns_int = {
2722 BPF_LD_IMM64(R0, 2147483646),
2723 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2724 BPF_EXIT_INSN(),
2725 },
2726 INTERNAL,
2727 { },
2728 { { 0, -1 } },
2729 },
2730 {
2731 "ALU64_ADD_K: 1 + 0 = 1",
2732 .u.insns_int = {
2733 BPF_LD_IMM64(R2, 0x1),
2734 BPF_LD_IMM64(R3, 0x1),
2735 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2736 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2737 BPF_MOV32_IMM(R0, 2),
2738 BPF_EXIT_INSN(),
2739 BPF_MOV32_IMM(R0, 1),
2740 BPF_EXIT_INSN(),
2741 },
2742 INTERNAL,
2743 { },
2744 { { 0, 0x1 } },
2745 },
2746 {
2747 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2748 .u.insns_int = {
2749 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002750 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002751 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2752 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2753 BPF_MOV32_IMM(R0, 2),
2754 BPF_EXIT_INSN(),
2755 BPF_MOV32_IMM(R0, 1),
2756 BPF_EXIT_INSN(),
2757 },
2758 INTERNAL,
2759 { },
2760 { { 0, 0x1 } },
2761 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302762 {
2763 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2764 .u.insns_int = {
2765 BPF_LD_IMM64(R2, 0x0),
2766 BPF_LD_IMM64(R3, 0xffff),
2767 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2768 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2769 BPF_MOV32_IMM(R0, 2),
2770 BPF_EXIT_INSN(),
2771 BPF_MOV32_IMM(R0, 1),
2772 BPF_EXIT_INSN(),
2773 },
2774 INTERNAL,
2775 { },
2776 { { 0, 0x1 } },
2777 },
2778 {
2779 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2780 .u.insns_int = {
2781 BPF_LD_IMM64(R2, 0x0),
2782 BPF_LD_IMM64(R3, 0x7fffffff),
2783 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2784 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2785 BPF_MOV32_IMM(R0, 2),
2786 BPF_EXIT_INSN(),
2787 BPF_MOV32_IMM(R0, 1),
2788 BPF_EXIT_INSN(),
2789 },
2790 INTERNAL,
2791 { },
2792 { { 0, 0x1 } },
2793 },
2794 {
2795 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2796 .u.insns_int = {
2797 BPF_LD_IMM64(R2, 0x0),
2798 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2799 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2800 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2801 BPF_MOV32_IMM(R0, 2),
2802 BPF_EXIT_INSN(),
2803 BPF_MOV32_IMM(R0, 1),
2804 BPF_EXIT_INSN(),
2805 },
2806 INTERNAL,
2807 { },
2808 { { 0, 0x1 } },
2809 },
2810 {
2811 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2812 .u.insns_int = {
2813 BPF_LD_IMM64(R2, 0x0),
2814 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2815 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2816 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2817 BPF_MOV32_IMM(R0, 2),
2818 BPF_EXIT_INSN(),
2819 BPF_MOV32_IMM(R0, 1),
2820 BPF_EXIT_INSN(),
2821 },
2822 INTERNAL,
2823 { },
2824 { { 0, 0x1 } },
2825 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002826 /* BPF_ALU | BPF_SUB | BPF_X */
2827 {
2828 "ALU_SUB_X: 3 - 1 = 2",
2829 .u.insns_int = {
2830 BPF_LD_IMM64(R0, 3),
2831 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2832 BPF_ALU32_REG(BPF_SUB, R0, R1),
2833 BPF_EXIT_INSN(),
2834 },
2835 INTERNAL,
2836 { },
2837 { { 0, 2 } },
2838 },
2839 {
2840 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2841 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002842 BPF_LD_IMM64(R0, 4294967295U),
2843 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002844 BPF_ALU32_REG(BPF_SUB, R0, R1),
2845 BPF_EXIT_INSN(),
2846 },
2847 INTERNAL,
2848 { },
2849 { { 0, 1 } },
2850 },
2851 {
2852 "ALU64_SUB_X: 3 - 1 = 2",
2853 .u.insns_int = {
2854 BPF_LD_IMM64(R0, 3),
2855 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2856 BPF_ALU64_REG(BPF_SUB, R0, R1),
2857 BPF_EXIT_INSN(),
2858 },
2859 INTERNAL,
2860 { },
2861 { { 0, 2 } },
2862 },
2863 {
2864 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2865 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002866 BPF_LD_IMM64(R0, 4294967295U),
2867 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002868 BPF_ALU64_REG(BPF_SUB, R0, R1),
2869 BPF_EXIT_INSN(),
2870 },
2871 INTERNAL,
2872 { },
2873 { { 0, 1 } },
2874 },
2875 /* BPF_ALU | BPF_SUB | BPF_K */
2876 {
2877 "ALU_SUB_K: 3 - 1 = 2",
2878 .u.insns_int = {
2879 BPF_LD_IMM64(R0, 3),
2880 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2881 BPF_EXIT_INSN(),
2882 },
2883 INTERNAL,
2884 { },
2885 { { 0, 2 } },
2886 },
2887 {
2888 "ALU_SUB_K: 3 - 0 = 3",
2889 .u.insns_int = {
2890 BPF_LD_IMM64(R0, 3),
2891 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2892 BPF_EXIT_INSN(),
2893 },
2894 INTERNAL,
2895 { },
2896 { { 0, 3 } },
2897 },
2898 {
2899 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2900 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002901 BPF_LD_IMM64(R0, 4294967295U),
2902 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002903 BPF_EXIT_INSN(),
2904 },
2905 INTERNAL,
2906 { },
2907 { { 0, 1 } },
2908 },
2909 {
2910 "ALU64_SUB_K: 3 - 1 = 2",
2911 .u.insns_int = {
2912 BPF_LD_IMM64(R0, 3),
2913 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2914 BPF_EXIT_INSN(),
2915 },
2916 INTERNAL,
2917 { },
2918 { { 0, 2 } },
2919 },
2920 {
2921 "ALU64_SUB_K: 3 - 0 = 3",
2922 .u.insns_int = {
2923 BPF_LD_IMM64(R0, 3),
2924 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2925 BPF_EXIT_INSN(),
2926 },
2927 INTERNAL,
2928 { },
2929 { { 0, 3 } },
2930 },
2931 {
2932 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2933 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002934 BPF_LD_IMM64(R0, 4294967294U),
2935 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002936 BPF_EXIT_INSN(),
2937 },
2938 INTERNAL,
2939 { },
2940 { { 0, -1 } },
2941 },
2942 {
2943 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2944 .u.insns_int = {
2945 BPF_LD_IMM64(R0, 2147483646),
2946 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2947 BPF_EXIT_INSN(),
2948 },
2949 INTERNAL,
2950 { },
2951 { { 0, -1 } },
2952 },
2953 /* BPF_ALU | BPF_MUL | BPF_X */
2954 {
2955 "ALU_MUL_X: 2 * 3 = 6",
2956 .u.insns_int = {
2957 BPF_LD_IMM64(R0, 2),
2958 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2959 BPF_ALU32_REG(BPF_MUL, R0, R1),
2960 BPF_EXIT_INSN(),
2961 },
2962 INTERNAL,
2963 { },
2964 { { 0, 6 } },
2965 },
2966 {
2967 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2968 .u.insns_int = {
2969 BPF_LD_IMM64(R0, 2),
2970 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2971 BPF_ALU32_REG(BPF_MUL, R0, R1),
2972 BPF_EXIT_INSN(),
2973 },
2974 INTERNAL,
2975 { },
2976 { { 0, 0xFFFFFFF0 } },
2977 },
2978 {
2979 "ALU_MUL_X: -1 * -1 = 1",
2980 .u.insns_int = {
2981 BPF_LD_IMM64(R0, -1),
2982 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2983 BPF_ALU32_REG(BPF_MUL, R0, R1),
2984 BPF_EXIT_INSN(),
2985 },
2986 INTERNAL,
2987 { },
2988 { { 0, 1 } },
2989 },
2990 {
2991 "ALU64_MUL_X: 2 * 3 = 6",
2992 .u.insns_int = {
2993 BPF_LD_IMM64(R0, 2),
2994 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2995 BPF_ALU64_REG(BPF_MUL, R0, R1),
2996 BPF_EXIT_INSN(),
2997 },
2998 INTERNAL,
2999 { },
3000 { { 0, 6 } },
3001 },
3002 {
3003 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3004 .u.insns_int = {
3005 BPF_LD_IMM64(R0, 1),
3006 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3007 BPF_ALU64_REG(BPF_MUL, R0, R1),
3008 BPF_EXIT_INSN(),
3009 },
3010 INTERNAL,
3011 { },
3012 { { 0, 2147483647 } },
3013 },
3014 /* BPF_ALU | BPF_MUL | BPF_K */
3015 {
3016 "ALU_MUL_K: 2 * 3 = 6",
3017 .u.insns_int = {
3018 BPF_LD_IMM64(R0, 2),
3019 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3020 BPF_EXIT_INSN(),
3021 },
3022 INTERNAL,
3023 { },
3024 { { 0, 6 } },
3025 },
3026 {
3027 "ALU_MUL_K: 3 * 1 = 3",
3028 .u.insns_int = {
3029 BPF_LD_IMM64(R0, 3),
3030 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3031 BPF_EXIT_INSN(),
3032 },
3033 INTERNAL,
3034 { },
3035 { { 0, 3 } },
3036 },
3037 {
3038 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3039 .u.insns_int = {
3040 BPF_LD_IMM64(R0, 2),
3041 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3042 BPF_EXIT_INSN(),
3043 },
3044 INTERNAL,
3045 { },
3046 { { 0, 0xFFFFFFF0 } },
3047 },
3048 {
3049 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3050 .u.insns_int = {
3051 BPF_LD_IMM64(R2, 0x1),
3052 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3053 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3054 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3055 BPF_MOV32_IMM(R0, 2),
3056 BPF_EXIT_INSN(),
3057 BPF_MOV32_IMM(R0, 1),
3058 BPF_EXIT_INSN(),
3059 },
3060 INTERNAL,
3061 { },
3062 { { 0, 0x1 } },
3063 },
3064 {
3065 "ALU64_MUL_K: 2 * 3 = 6",
3066 .u.insns_int = {
3067 BPF_LD_IMM64(R0, 2),
3068 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3069 BPF_EXIT_INSN(),
3070 },
3071 INTERNAL,
3072 { },
3073 { { 0, 6 } },
3074 },
3075 {
3076 "ALU64_MUL_K: 3 * 1 = 3",
3077 .u.insns_int = {
3078 BPF_LD_IMM64(R0, 3),
3079 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3080 BPF_EXIT_INSN(),
3081 },
3082 INTERNAL,
3083 { },
3084 { { 0, 3 } },
3085 },
3086 {
3087 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3088 .u.insns_int = {
3089 BPF_LD_IMM64(R0, 1),
3090 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3091 BPF_EXIT_INSN(),
3092 },
3093 INTERNAL,
3094 { },
3095 { { 0, 2147483647 } },
3096 },
3097 {
3098 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3099 .u.insns_int = {
3100 BPF_LD_IMM64(R0, 1),
3101 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3102 BPF_EXIT_INSN(),
3103 },
3104 INTERNAL,
3105 { },
3106 { { 0, -2147483647 } },
3107 },
3108 {
3109 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3110 .u.insns_int = {
3111 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003112 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003113 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3114 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3115 BPF_MOV32_IMM(R0, 2),
3116 BPF_EXIT_INSN(),
3117 BPF_MOV32_IMM(R0, 1),
3118 BPF_EXIT_INSN(),
3119 },
3120 INTERNAL,
3121 { },
3122 { { 0, 0x1 } },
3123 },
3124 /* BPF_ALU | BPF_DIV | BPF_X */
3125 {
3126 "ALU_DIV_X: 6 / 2 = 3",
3127 .u.insns_int = {
3128 BPF_LD_IMM64(R0, 6),
3129 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3130 BPF_ALU32_REG(BPF_DIV, R0, R1),
3131 BPF_EXIT_INSN(),
3132 },
3133 INTERNAL,
3134 { },
3135 { { 0, 3 } },
3136 },
3137 {
3138 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3139 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003140 BPF_LD_IMM64(R0, 4294967295U),
3141 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003142 BPF_ALU32_REG(BPF_DIV, R0, R1),
3143 BPF_EXIT_INSN(),
3144 },
3145 INTERNAL,
3146 { },
3147 { { 0, 1 } },
3148 },
3149 {
3150 "ALU64_DIV_X: 6 / 2 = 3",
3151 .u.insns_int = {
3152 BPF_LD_IMM64(R0, 6),
3153 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3154 BPF_ALU64_REG(BPF_DIV, R0, R1),
3155 BPF_EXIT_INSN(),
3156 },
3157 INTERNAL,
3158 { },
3159 { { 0, 3 } },
3160 },
3161 {
3162 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3163 .u.insns_int = {
3164 BPF_LD_IMM64(R0, 2147483647),
3165 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3166 BPF_ALU64_REG(BPF_DIV, R0, R1),
3167 BPF_EXIT_INSN(),
3168 },
3169 INTERNAL,
3170 { },
3171 { { 0, 1 } },
3172 },
3173 {
3174 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3175 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003176 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3177 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3178 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003179 BPF_ALU64_REG(BPF_DIV, R2, R4),
3180 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3181 BPF_MOV32_IMM(R0, 2),
3182 BPF_EXIT_INSN(),
3183 BPF_MOV32_IMM(R0, 1),
3184 BPF_EXIT_INSN(),
3185 },
3186 INTERNAL,
3187 { },
3188 { { 0, 0x1 } },
3189 },
3190 /* BPF_ALU | BPF_DIV | BPF_K */
3191 {
3192 "ALU_DIV_K: 6 / 2 = 3",
3193 .u.insns_int = {
3194 BPF_LD_IMM64(R0, 6),
3195 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3196 BPF_EXIT_INSN(),
3197 },
3198 INTERNAL,
3199 { },
3200 { { 0, 3 } },
3201 },
3202 {
3203 "ALU_DIV_K: 3 / 1 = 3",
3204 .u.insns_int = {
3205 BPF_LD_IMM64(R0, 3),
3206 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3207 BPF_EXIT_INSN(),
3208 },
3209 INTERNAL,
3210 { },
3211 { { 0, 3 } },
3212 },
3213 {
3214 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3215 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003216 BPF_LD_IMM64(R0, 4294967295U),
3217 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003218 BPF_EXIT_INSN(),
3219 },
3220 INTERNAL,
3221 { },
3222 { { 0, 1 } },
3223 },
3224 {
3225 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3226 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003227 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003228 BPF_LD_IMM64(R3, 0x1UL),
3229 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3230 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3231 BPF_MOV32_IMM(R0, 2),
3232 BPF_EXIT_INSN(),
3233 BPF_MOV32_IMM(R0, 1),
3234 BPF_EXIT_INSN(),
3235 },
3236 INTERNAL,
3237 { },
3238 { { 0, 0x1 } },
3239 },
3240 {
3241 "ALU64_DIV_K: 6 / 2 = 3",
3242 .u.insns_int = {
3243 BPF_LD_IMM64(R0, 6),
3244 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3245 BPF_EXIT_INSN(),
3246 },
3247 INTERNAL,
3248 { },
3249 { { 0, 3 } },
3250 },
3251 {
3252 "ALU64_DIV_K: 3 / 1 = 3",
3253 .u.insns_int = {
3254 BPF_LD_IMM64(R0, 3),
3255 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3256 BPF_EXIT_INSN(),
3257 },
3258 INTERNAL,
3259 { },
3260 { { 0, 3 } },
3261 },
3262 {
3263 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3264 .u.insns_int = {
3265 BPF_LD_IMM64(R0, 2147483647),
3266 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3267 BPF_EXIT_INSN(),
3268 },
3269 INTERNAL,
3270 { },
3271 { { 0, 1 } },
3272 },
3273 {
3274 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3275 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003276 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3277 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003278 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3279 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3280 BPF_MOV32_IMM(R0, 2),
3281 BPF_EXIT_INSN(),
3282 BPF_MOV32_IMM(R0, 1),
3283 BPF_EXIT_INSN(),
3284 },
3285 INTERNAL,
3286 { },
3287 { { 0, 0x1 } },
3288 },
3289 /* BPF_ALU | BPF_MOD | BPF_X */
3290 {
3291 "ALU_MOD_X: 3 % 2 = 1",
3292 .u.insns_int = {
3293 BPF_LD_IMM64(R0, 3),
3294 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3295 BPF_ALU32_REG(BPF_MOD, R0, R1),
3296 BPF_EXIT_INSN(),
3297 },
3298 INTERNAL,
3299 { },
3300 { { 0, 1 } },
3301 },
3302 {
3303 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3304 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003305 BPF_LD_IMM64(R0, 4294967295U),
3306 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003307 BPF_ALU32_REG(BPF_MOD, R0, R1),
3308 BPF_EXIT_INSN(),
3309 },
3310 INTERNAL,
3311 { },
3312 { { 0, 2 } },
3313 },
3314 {
3315 "ALU64_MOD_X: 3 % 2 = 1",
3316 .u.insns_int = {
3317 BPF_LD_IMM64(R0, 3),
3318 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3319 BPF_ALU64_REG(BPF_MOD, R0, R1),
3320 BPF_EXIT_INSN(),
3321 },
3322 INTERNAL,
3323 { },
3324 { { 0, 1 } },
3325 },
3326 {
3327 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3328 .u.insns_int = {
3329 BPF_LD_IMM64(R0, 2147483647),
3330 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3331 BPF_ALU64_REG(BPF_MOD, R0, R1),
3332 BPF_EXIT_INSN(),
3333 },
3334 INTERNAL,
3335 { },
3336 { { 0, 2 } },
3337 },
3338 /* BPF_ALU | BPF_MOD | BPF_K */
3339 {
3340 "ALU_MOD_K: 3 % 2 = 1",
3341 .u.insns_int = {
3342 BPF_LD_IMM64(R0, 3),
3343 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3344 BPF_EXIT_INSN(),
3345 },
3346 INTERNAL,
3347 { },
3348 { { 0, 1 } },
3349 },
3350 {
3351 "ALU_MOD_K: 3 % 1 = 0",
3352 .u.insns_int = {
3353 BPF_LD_IMM64(R0, 3),
3354 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3355 BPF_EXIT_INSN(),
3356 },
3357 INTERNAL,
3358 { },
3359 { { 0, 0 } },
3360 },
3361 {
3362 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3363 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003364 BPF_LD_IMM64(R0, 4294967295U),
3365 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003366 BPF_EXIT_INSN(),
3367 },
3368 INTERNAL,
3369 { },
3370 { { 0, 2 } },
3371 },
3372 {
3373 "ALU64_MOD_K: 3 % 2 = 1",
3374 .u.insns_int = {
3375 BPF_LD_IMM64(R0, 3),
3376 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3377 BPF_EXIT_INSN(),
3378 },
3379 INTERNAL,
3380 { },
3381 { { 0, 1 } },
3382 },
3383 {
3384 "ALU64_MOD_K: 3 % 1 = 0",
3385 .u.insns_int = {
3386 BPF_LD_IMM64(R0, 3),
3387 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3388 BPF_EXIT_INSN(),
3389 },
3390 INTERNAL,
3391 { },
3392 { { 0, 0 } },
3393 },
3394 {
3395 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3396 .u.insns_int = {
3397 BPF_LD_IMM64(R0, 2147483647),
3398 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3399 BPF_EXIT_INSN(),
3400 },
3401 INTERNAL,
3402 { },
3403 { { 0, 2 } },
3404 },
3405 /* BPF_ALU | BPF_AND | BPF_X */
3406 {
3407 "ALU_AND_X: 3 & 2 = 2",
3408 .u.insns_int = {
3409 BPF_LD_IMM64(R0, 3),
3410 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3411 BPF_ALU32_REG(BPF_AND, R0, R1),
3412 BPF_EXIT_INSN(),
3413 },
3414 INTERNAL,
3415 { },
3416 { { 0, 2 } },
3417 },
3418 {
3419 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3420 .u.insns_int = {
3421 BPF_LD_IMM64(R0, 0xffffffff),
3422 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3423 BPF_ALU32_REG(BPF_AND, R0, R1),
3424 BPF_EXIT_INSN(),
3425 },
3426 INTERNAL,
3427 { },
3428 { { 0, 0xffffffff } },
3429 },
3430 {
3431 "ALU64_AND_X: 3 & 2 = 2",
3432 .u.insns_int = {
3433 BPF_LD_IMM64(R0, 3),
3434 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3435 BPF_ALU64_REG(BPF_AND, R0, R1),
3436 BPF_EXIT_INSN(),
3437 },
3438 INTERNAL,
3439 { },
3440 { { 0, 2 } },
3441 },
3442 {
3443 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3444 .u.insns_int = {
3445 BPF_LD_IMM64(R0, 0xffffffff),
3446 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3447 BPF_ALU64_REG(BPF_AND, R0, R1),
3448 BPF_EXIT_INSN(),
3449 },
3450 INTERNAL,
3451 { },
3452 { { 0, 0xffffffff } },
3453 },
3454 /* BPF_ALU | BPF_AND | BPF_K */
3455 {
3456 "ALU_AND_K: 3 & 2 = 2",
3457 .u.insns_int = {
3458 BPF_LD_IMM64(R0, 3),
3459 BPF_ALU32_IMM(BPF_AND, R0, 2),
3460 BPF_EXIT_INSN(),
3461 },
3462 INTERNAL,
3463 { },
3464 { { 0, 2 } },
3465 },
3466 {
3467 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3468 .u.insns_int = {
3469 BPF_LD_IMM64(R0, 0xffffffff),
3470 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3471 BPF_EXIT_INSN(),
3472 },
3473 INTERNAL,
3474 { },
3475 { { 0, 0xffffffff } },
3476 },
3477 {
3478 "ALU64_AND_K: 3 & 2 = 2",
3479 .u.insns_int = {
3480 BPF_LD_IMM64(R0, 3),
3481 BPF_ALU64_IMM(BPF_AND, R0, 2),
3482 BPF_EXIT_INSN(),
3483 },
3484 INTERNAL,
3485 { },
3486 { { 0, 2 } },
3487 },
3488 {
3489 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3490 .u.insns_int = {
3491 BPF_LD_IMM64(R0, 0xffffffff),
3492 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3493 BPF_EXIT_INSN(),
3494 },
3495 INTERNAL,
3496 { },
3497 { { 0, 0xffffffff } },
3498 },
3499 {
3500 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3501 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003502 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3503 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003504 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3505 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3506 BPF_MOV32_IMM(R0, 2),
3507 BPF_EXIT_INSN(),
3508 BPF_MOV32_IMM(R0, 1),
3509 BPF_EXIT_INSN(),
3510 },
3511 INTERNAL,
3512 { },
3513 { { 0, 0x1 } },
3514 },
3515 {
3516 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3517 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003518 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3519 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003520 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3521 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3522 BPF_MOV32_IMM(R0, 2),
3523 BPF_EXIT_INSN(),
3524 BPF_MOV32_IMM(R0, 1),
3525 BPF_EXIT_INSN(),
3526 },
3527 INTERNAL,
3528 { },
3529 { { 0, 0x1 } },
3530 },
3531 {
3532 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3533 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003534 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3535 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003536 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3537 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3538 BPF_MOV32_IMM(R0, 2),
3539 BPF_EXIT_INSN(),
3540 BPF_MOV32_IMM(R0, 1),
3541 BPF_EXIT_INSN(),
3542 },
3543 INTERNAL,
3544 { },
3545 { { 0, 0x1 } },
3546 },
3547 /* BPF_ALU | BPF_OR | BPF_X */
3548 {
3549 "ALU_OR_X: 1 | 2 = 3",
3550 .u.insns_int = {
3551 BPF_LD_IMM64(R0, 1),
3552 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3553 BPF_ALU32_REG(BPF_OR, R0, R1),
3554 BPF_EXIT_INSN(),
3555 },
3556 INTERNAL,
3557 { },
3558 { { 0, 3 } },
3559 },
3560 {
3561 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3562 .u.insns_int = {
3563 BPF_LD_IMM64(R0, 0),
3564 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3565 BPF_ALU32_REG(BPF_OR, R0, R1),
3566 BPF_EXIT_INSN(),
3567 },
3568 INTERNAL,
3569 { },
3570 { { 0, 0xffffffff } },
3571 },
3572 {
3573 "ALU64_OR_X: 1 | 2 = 3",
3574 .u.insns_int = {
3575 BPF_LD_IMM64(R0, 1),
3576 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3577 BPF_ALU64_REG(BPF_OR, R0, R1),
3578 BPF_EXIT_INSN(),
3579 },
3580 INTERNAL,
3581 { },
3582 { { 0, 3 } },
3583 },
3584 {
3585 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3586 .u.insns_int = {
3587 BPF_LD_IMM64(R0, 0),
3588 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3589 BPF_ALU64_REG(BPF_OR, R0, R1),
3590 BPF_EXIT_INSN(),
3591 },
3592 INTERNAL,
3593 { },
3594 { { 0, 0xffffffff } },
3595 },
3596 /* BPF_ALU | BPF_OR | BPF_K */
3597 {
3598 "ALU_OR_K: 1 | 2 = 3",
3599 .u.insns_int = {
3600 BPF_LD_IMM64(R0, 1),
3601 BPF_ALU32_IMM(BPF_OR, R0, 2),
3602 BPF_EXIT_INSN(),
3603 },
3604 INTERNAL,
3605 { },
3606 { { 0, 3 } },
3607 },
3608 {
3609 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3610 .u.insns_int = {
3611 BPF_LD_IMM64(R0, 0),
3612 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3613 BPF_EXIT_INSN(),
3614 },
3615 INTERNAL,
3616 { },
3617 { { 0, 0xffffffff } },
3618 },
3619 {
3620 "ALU64_OR_K: 1 | 2 = 3",
3621 .u.insns_int = {
3622 BPF_LD_IMM64(R0, 1),
3623 BPF_ALU64_IMM(BPF_OR, R0, 2),
3624 BPF_EXIT_INSN(),
3625 },
3626 INTERNAL,
3627 { },
3628 { { 0, 3 } },
3629 },
3630 {
3631 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3632 .u.insns_int = {
3633 BPF_LD_IMM64(R0, 0),
3634 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3635 BPF_EXIT_INSN(),
3636 },
3637 INTERNAL,
3638 { },
3639 { { 0, 0xffffffff } },
3640 },
3641 {
3642 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3643 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003644 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3645 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003646 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3647 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3648 BPF_MOV32_IMM(R0, 2),
3649 BPF_EXIT_INSN(),
3650 BPF_MOV32_IMM(R0, 1),
3651 BPF_EXIT_INSN(),
3652 },
3653 INTERNAL,
3654 { },
3655 { { 0, 0x1 } },
3656 },
3657 {
3658 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3659 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003660 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3661 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003662 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3663 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3664 BPF_MOV32_IMM(R0, 2),
3665 BPF_EXIT_INSN(),
3666 BPF_MOV32_IMM(R0, 1),
3667 BPF_EXIT_INSN(),
3668 },
3669 INTERNAL,
3670 { },
3671 { { 0, 0x1 } },
3672 },
3673 {
3674 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3675 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003676 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3677 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003678 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3679 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3680 BPF_MOV32_IMM(R0, 2),
3681 BPF_EXIT_INSN(),
3682 BPF_MOV32_IMM(R0, 1),
3683 BPF_EXIT_INSN(),
3684 },
3685 INTERNAL,
3686 { },
3687 { { 0, 0x1 } },
3688 },
3689 /* BPF_ALU | BPF_XOR | BPF_X */
3690 {
3691 "ALU_XOR_X: 5 ^ 6 = 3",
3692 .u.insns_int = {
3693 BPF_LD_IMM64(R0, 5),
3694 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3695 BPF_ALU32_REG(BPF_XOR, R0, R1),
3696 BPF_EXIT_INSN(),
3697 },
3698 INTERNAL,
3699 { },
3700 { { 0, 3 } },
3701 },
3702 {
3703 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3704 .u.insns_int = {
3705 BPF_LD_IMM64(R0, 1),
3706 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3707 BPF_ALU32_REG(BPF_XOR, R0, R1),
3708 BPF_EXIT_INSN(),
3709 },
3710 INTERNAL,
3711 { },
3712 { { 0, 0xfffffffe } },
3713 },
3714 {
3715 "ALU64_XOR_X: 5 ^ 6 = 3",
3716 .u.insns_int = {
3717 BPF_LD_IMM64(R0, 5),
3718 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3719 BPF_ALU64_REG(BPF_XOR, R0, R1),
3720 BPF_EXIT_INSN(),
3721 },
3722 INTERNAL,
3723 { },
3724 { { 0, 3 } },
3725 },
3726 {
3727 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3728 .u.insns_int = {
3729 BPF_LD_IMM64(R0, 1),
3730 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3731 BPF_ALU64_REG(BPF_XOR, R0, R1),
3732 BPF_EXIT_INSN(),
3733 },
3734 INTERNAL,
3735 { },
3736 { { 0, 0xfffffffe } },
3737 },
3738 /* BPF_ALU | BPF_XOR | BPF_K */
3739 {
3740 "ALU_XOR_K: 5 ^ 6 = 3",
3741 .u.insns_int = {
3742 BPF_LD_IMM64(R0, 5),
3743 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3744 BPF_EXIT_INSN(),
3745 },
3746 INTERNAL,
3747 { },
3748 { { 0, 3 } },
3749 },
3750 {
3751 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3752 .u.insns_int = {
3753 BPF_LD_IMM64(R0, 1),
3754 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3755 BPF_EXIT_INSN(),
3756 },
3757 INTERNAL,
3758 { },
3759 { { 0, 0xfffffffe } },
3760 },
3761 {
3762 "ALU64_XOR_K: 5 ^ 6 = 3",
3763 .u.insns_int = {
3764 BPF_LD_IMM64(R0, 5),
3765 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3766 BPF_EXIT_INSN(),
3767 },
3768 INTERNAL,
3769 { },
3770 { { 0, 3 } },
3771 },
3772 {
3773 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3774 .u.insns_int = {
3775 BPF_LD_IMM64(R0, 1),
3776 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3777 BPF_EXIT_INSN(),
3778 },
3779 INTERNAL,
3780 { },
3781 { { 0, 0xfffffffe } },
3782 },
3783 {
3784 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3785 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003786 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3787 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003788 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3789 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3790 BPF_MOV32_IMM(R0, 2),
3791 BPF_EXIT_INSN(),
3792 BPF_MOV32_IMM(R0, 1),
3793 BPF_EXIT_INSN(),
3794 },
3795 INTERNAL,
3796 { },
3797 { { 0, 0x1 } },
3798 },
3799 {
3800 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3801 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003802 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3803 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003804 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3805 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3806 BPF_MOV32_IMM(R0, 2),
3807 BPF_EXIT_INSN(),
3808 BPF_MOV32_IMM(R0, 1),
3809 BPF_EXIT_INSN(),
3810 },
3811 INTERNAL,
3812 { },
3813 { { 0, 0x1 } },
3814 },
3815 {
3816 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3817 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003818 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3819 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003820 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3821 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3822 BPF_MOV32_IMM(R0, 2),
3823 BPF_EXIT_INSN(),
3824 BPF_MOV32_IMM(R0, 1),
3825 BPF_EXIT_INSN(),
3826 },
3827 INTERNAL,
3828 { },
3829 { { 0, 0x1 } },
3830 },
3831 /* BPF_ALU | BPF_LSH | BPF_X */
3832 {
3833 "ALU_LSH_X: 1 << 1 = 2",
3834 .u.insns_int = {
3835 BPF_LD_IMM64(R0, 1),
3836 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3837 BPF_ALU32_REG(BPF_LSH, R0, R1),
3838 BPF_EXIT_INSN(),
3839 },
3840 INTERNAL,
3841 { },
3842 { { 0, 2 } },
3843 },
3844 {
3845 "ALU_LSH_X: 1 << 31 = 0x80000000",
3846 .u.insns_int = {
3847 BPF_LD_IMM64(R0, 1),
3848 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3849 BPF_ALU32_REG(BPF_LSH, R0, R1),
3850 BPF_EXIT_INSN(),
3851 },
3852 INTERNAL,
3853 { },
3854 { { 0, 0x80000000 } },
3855 },
3856 {
3857 "ALU64_LSH_X: 1 << 1 = 2",
3858 .u.insns_int = {
3859 BPF_LD_IMM64(R0, 1),
3860 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3861 BPF_ALU64_REG(BPF_LSH, R0, R1),
3862 BPF_EXIT_INSN(),
3863 },
3864 INTERNAL,
3865 { },
3866 { { 0, 2 } },
3867 },
3868 {
3869 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3870 .u.insns_int = {
3871 BPF_LD_IMM64(R0, 1),
3872 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3873 BPF_ALU64_REG(BPF_LSH, R0, R1),
3874 BPF_EXIT_INSN(),
3875 },
3876 INTERNAL,
3877 { },
3878 { { 0, 0x80000000 } },
3879 },
3880 /* BPF_ALU | BPF_LSH | BPF_K */
3881 {
3882 "ALU_LSH_K: 1 << 1 = 2",
3883 .u.insns_int = {
3884 BPF_LD_IMM64(R0, 1),
3885 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3886 BPF_EXIT_INSN(),
3887 },
3888 INTERNAL,
3889 { },
3890 { { 0, 2 } },
3891 },
3892 {
3893 "ALU_LSH_K: 1 << 31 = 0x80000000",
3894 .u.insns_int = {
3895 BPF_LD_IMM64(R0, 1),
3896 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3897 BPF_EXIT_INSN(),
3898 },
3899 INTERNAL,
3900 { },
3901 { { 0, 0x80000000 } },
3902 },
3903 {
3904 "ALU64_LSH_K: 1 << 1 = 2",
3905 .u.insns_int = {
3906 BPF_LD_IMM64(R0, 1),
3907 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3908 BPF_EXIT_INSN(),
3909 },
3910 INTERNAL,
3911 { },
3912 { { 0, 2 } },
3913 },
3914 {
3915 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3916 .u.insns_int = {
3917 BPF_LD_IMM64(R0, 1),
3918 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3919 BPF_EXIT_INSN(),
3920 },
3921 INTERNAL,
3922 { },
3923 { { 0, 0x80000000 } },
3924 },
3925 /* BPF_ALU | BPF_RSH | BPF_X */
3926 {
3927 "ALU_RSH_X: 2 >> 1 = 1",
3928 .u.insns_int = {
3929 BPF_LD_IMM64(R0, 2),
3930 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3931 BPF_ALU32_REG(BPF_RSH, R0, R1),
3932 BPF_EXIT_INSN(),
3933 },
3934 INTERNAL,
3935 { },
3936 { { 0, 1 } },
3937 },
3938 {
3939 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3940 .u.insns_int = {
3941 BPF_LD_IMM64(R0, 0x80000000),
3942 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3943 BPF_ALU32_REG(BPF_RSH, R0, R1),
3944 BPF_EXIT_INSN(),
3945 },
3946 INTERNAL,
3947 { },
3948 { { 0, 1 } },
3949 },
3950 {
3951 "ALU64_RSH_X: 2 >> 1 = 1",
3952 .u.insns_int = {
3953 BPF_LD_IMM64(R0, 2),
3954 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3955 BPF_ALU64_REG(BPF_RSH, R0, R1),
3956 BPF_EXIT_INSN(),
3957 },
3958 INTERNAL,
3959 { },
3960 { { 0, 1 } },
3961 },
3962 {
3963 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3964 .u.insns_int = {
3965 BPF_LD_IMM64(R0, 0x80000000),
3966 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3967 BPF_ALU64_REG(BPF_RSH, R0, R1),
3968 BPF_EXIT_INSN(),
3969 },
3970 INTERNAL,
3971 { },
3972 { { 0, 1 } },
3973 },
3974 /* BPF_ALU | BPF_RSH | BPF_K */
3975 {
3976 "ALU_RSH_K: 2 >> 1 = 1",
3977 .u.insns_int = {
3978 BPF_LD_IMM64(R0, 2),
3979 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3980 BPF_EXIT_INSN(),
3981 },
3982 INTERNAL,
3983 { },
3984 { { 0, 1 } },
3985 },
3986 {
3987 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3988 .u.insns_int = {
3989 BPF_LD_IMM64(R0, 0x80000000),
3990 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3991 BPF_EXIT_INSN(),
3992 },
3993 INTERNAL,
3994 { },
3995 { { 0, 1 } },
3996 },
3997 {
3998 "ALU64_RSH_K: 2 >> 1 = 1",
3999 .u.insns_int = {
4000 BPF_LD_IMM64(R0, 2),
4001 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4002 BPF_EXIT_INSN(),
4003 },
4004 INTERNAL,
4005 { },
4006 { { 0, 1 } },
4007 },
4008 {
4009 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4010 .u.insns_int = {
4011 BPF_LD_IMM64(R0, 0x80000000),
4012 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4013 BPF_EXIT_INSN(),
4014 },
4015 INTERNAL,
4016 { },
4017 { { 0, 1 } },
4018 },
4019 /* BPF_ALU | BPF_ARSH | BPF_X */
4020 {
4021 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4022 .u.insns_int = {
4023 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4024 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4025 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4026 BPF_EXIT_INSN(),
4027 },
4028 INTERNAL,
4029 { },
4030 { { 0, 0xffff00ff } },
4031 },
4032 /* BPF_ALU | BPF_ARSH | BPF_K */
4033 {
4034 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4035 .u.insns_int = {
4036 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4037 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
4038 BPF_EXIT_INSN(),
4039 },
4040 INTERNAL,
4041 { },
4042 { { 0, 0xffff00ff } },
4043 },
4044 /* BPF_ALU | BPF_NEG */
4045 {
4046 "ALU_NEG: -(3) = -3",
4047 .u.insns_int = {
4048 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4049 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4050 BPF_EXIT_INSN(),
4051 },
4052 INTERNAL,
4053 { },
4054 { { 0, -3 } },
4055 },
4056 {
4057 "ALU_NEG: -(-3) = 3",
4058 .u.insns_int = {
4059 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4060 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4061 BPF_EXIT_INSN(),
4062 },
4063 INTERNAL,
4064 { },
4065 { { 0, 3 } },
4066 },
4067 {
4068 "ALU64_NEG: -(3) = -3",
4069 .u.insns_int = {
4070 BPF_LD_IMM64(R0, 3),
4071 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4072 BPF_EXIT_INSN(),
4073 },
4074 INTERNAL,
4075 { },
4076 { { 0, -3 } },
4077 },
4078 {
4079 "ALU64_NEG: -(-3) = 3",
4080 .u.insns_int = {
4081 BPF_LD_IMM64(R0, -3),
4082 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4083 BPF_EXIT_INSN(),
4084 },
4085 INTERNAL,
4086 { },
4087 { { 0, 3 } },
4088 },
4089 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4090 {
4091 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4092 .u.insns_int = {
4093 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4094 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4095 BPF_EXIT_INSN(),
4096 },
4097 INTERNAL,
4098 { },
4099 { { 0, cpu_to_be16(0xcdef) } },
4100 },
4101 {
4102 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4103 .u.insns_int = {
4104 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4105 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004106 BPF_ALU64_REG(BPF_MOV, R1, R0),
4107 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4108 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004109 BPF_EXIT_INSN(),
4110 },
4111 INTERNAL,
4112 { },
4113 { { 0, cpu_to_be32(0x89abcdef) } },
4114 },
4115 {
4116 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4117 .u.insns_int = {
4118 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4119 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4120 BPF_EXIT_INSN(),
4121 },
4122 INTERNAL,
4123 { },
4124 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4125 },
4126 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4127 {
4128 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4129 .u.insns_int = {
4130 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4131 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4132 BPF_EXIT_INSN(),
4133 },
4134 INTERNAL,
4135 { },
4136 { { 0, cpu_to_le16(0xcdef) } },
4137 },
4138 {
4139 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4140 .u.insns_int = {
4141 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4142 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004143 BPF_ALU64_REG(BPF_MOV, R1, R0),
4144 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4145 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004146 BPF_EXIT_INSN(),
4147 },
4148 INTERNAL,
4149 { },
4150 { { 0, cpu_to_le32(0x89abcdef) } },
4151 },
4152 {
4153 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4154 .u.insns_int = {
4155 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4156 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4157 BPF_EXIT_INSN(),
4158 },
4159 INTERNAL,
4160 { },
4161 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4162 },
4163 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4164 {
4165 "ST_MEM_B: Store/Load byte: max negative",
4166 .u.insns_int = {
4167 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4168 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4169 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4170 BPF_EXIT_INSN(),
4171 },
4172 INTERNAL,
4173 { },
4174 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004175 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004176 },
4177 {
4178 "ST_MEM_B: Store/Load byte: max positive",
4179 .u.insns_int = {
4180 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4181 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4182 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4183 BPF_EXIT_INSN(),
4184 },
4185 INTERNAL,
4186 { },
4187 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004188 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004189 },
4190 {
4191 "STX_MEM_B: Store/Load byte: max negative",
4192 .u.insns_int = {
4193 BPF_LD_IMM64(R0, 0),
4194 BPF_LD_IMM64(R1, 0xffLL),
4195 BPF_STX_MEM(BPF_B, R10, R1, -40),
4196 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4197 BPF_EXIT_INSN(),
4198 },
4199 INTERNAL,
4200 { },
4201 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004202 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004203 },
4204 {
4205 "ST_MEM_H: Store/Load half word: max negative",
4206 .u.insns_int = {
4207 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4208 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4209 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4210 BPF_EXIT_INSN(),
4211 },
4212 INTERNAL,
4213 { },
4214 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004215 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004216 },
4217 {
4218 "ST_MEM_H: Store/Load half word: max positive",
4219 .u.insns_int = {
4220 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4221 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4222 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4223 BPF_EXIT_INSN(),
4224 },
4225 INTERNAL,
4226 { },
4227 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004228 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004229 },
4230 {
4231 "STX_MEM_H: Store/Load half word: max negative",
4232 .u.insns_int = {
4233 BPF_LD_IMM64(R0, 0),
4234 BPF_LD_IMM64(R1, 0xffffLL),
4235 BPF_STX_MEM(BPF_H, R10, R1, -40),
4236 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4237 BPF_EXIT_INSN(),
4238 },
4239 INTERNAL,
4240 { },
4241 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004242 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004243 },
4244 {
4245 "ST_MEM_W: Store/Load word: max negative",
4246 .u.insns_int = {
4247 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4248 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4249 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4250 BPF_EXIT_INSN(),
4251 },
4252 INTERNAL,
4253 { },
4254 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004255 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004256 },
4257 {
4258 "ST_MEM_W: Store/Load word: max positive",
4259 .u.insns_int = {
4260 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4261 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4262 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4263 BPF_EXIT_INSN(),
4264 },
4265 INTERNAL,
4266 { },
4267 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004268 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004269 },
4270 {
4271 "STX_MEM_W: Store/Load word: max negative",
4272 .u.insns_int = {
4273 BPF_LD_IMM64(R0, 0),
4274 BPF_LD_IMM64(R1, 0xffffffffLL),
4275 BPF_STX_MEM(BPF_W, R10, R1, -40),
4276 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4277 BPF_EXIT_INSN(),
4278 },
4279 INTERNAL,
4280 { },
4281 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004282 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004283 },
4284 {
4285 "ST_MEM_DW: Store/Load double word: max negative",
4286 .u.insns_int = {
4287 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4288 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4289 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4290 BPF_EXIT_INSN(),
4291 },
4292 INTERNAL,
4293 { },
4294 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004295 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004296 },
4297 {
4298 "ST_MEM_DW: Store/Load double word: max negative 2",
4299 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004300 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4301 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004302 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4303 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4304 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4305 BPF_MOV32_IMM(R0, 2),
4306 BPF_EXIT_INSN(),
4307 BPF_MOV32_IMM(R0, 1),
4308 BPF_EXIT_INSN(),
4309 },
4310 INTERNAL,
4311 { },
4312 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004313 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004314 },
4315 {
4316 "ST_MEM_DW: Store/Load double word: max positive",
4317 .u.insns_int = {
4318 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4319 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4320 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4321 BPF_EXIT_INSN(),
4322 },
4323 INTERNAL,
4324 { },
4325 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004326 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004327 },
4328 {
4329 "STX_MEM_DW: Store/Load double word: max negative",
4330 .u.insns_int = {
4331 BPF_LD_IMM64(R0, 0),
4332 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4333 BPF_STX_MEM(BPF_W, R10, R1, -40),
4334 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4335 BPF_EXIT_INSN(),
4336 },
4337 INTERNAL,
4338 { },
4339 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004340 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004341 },
4342 /* BPF_STX | BPF_XADD | BPF_W/DW */
4343 {
4344 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4345 .u.insns_int = {
4346 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4347 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4348 BPF_STX_XADD(BPF_W, R10, R0, -40),
4349 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4350 BPF_EXIT_INSN(),
4351 },
4352 INTERNAL,
4353 { },
4354 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004355 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004356 },
4357 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004358 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4359 .u.insns_int = {
4360 BPF_ALU64_REG(BPF_MOV, R1, R10),
4361 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4362 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4363 BPF_STX_XADD(BPF_W, R10, R0, -40),
4364 BPF_ALU64_REG(BPF_MOV, R0, R10),
4365 BPF_ALU64_REG(BPF_SUB, R0, R1),
4366 BPF_EXIT_INSN(),
4367 },
4368 INTERNAL,
4369 { },
4370 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004371 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004372 },
4373 {
4374 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4375 .u.insns_int = {
4376 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4377 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4378 BPF_STX_XADD(BPF_W, R10, R0, -40),
4379 BPF_EXIT_INSN(),
4380 },
4381 INTERNAL,
4382 { },
4383 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004384 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004385 },
4386 {
4387 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4388 { },
4389 INTERNAL,
4390 { },
4391 { { 0, 4134 } },
4392 .fill_helper = bpf_fill_stxw,
4393 },
4394 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004395 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4396 .u.insns_int = {
4397 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4398 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4399 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4400 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4401 BPF_EXIT_INSN(),
4402 },
4403 INTERNAL,
4404 { },
4405 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004406 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004407 },
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004408 {
4409 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4410 .u.insns_int = {
4411 BPF_ALU64_REG(BPF_MOV, R1, R10),
4412 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4413 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4414 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4415 BPF_ALU64_REG(BPF_MOV, R0, R10),
4416 BPF_ALU64_REG(BPF_SUB, R0, R1),
4417 BPF_EXIT_INSN(),
4418 },
4419 INTERNAL,
4420 { },
4421 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004422 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004423 },
4424 {
4425 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4426 .u.insns_int = {
4427 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4428 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4429 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4430 BPF_EXIT_INSN(),
4431 },
4432 INTERNAL,
4433 { },
4434 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004435 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004436 },
4437 {
4438 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4439 { },
4440 INTERNAL,
4441 { },
4442 { { 0, 4134 } },
4443 .fill_helper = bpf_fill_stxdw,
4444 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004445 /* BPF_JMP | BPF_EXIT */
4446 {
4447 "JMP_EXIT",
4448 .u.insns_int = {
4449 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4450 BPF_EXIT_INSN(),
4451 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4452 },
4453 INTERNAL,
4454 { },
4455 { { 0, 0x4711 } },
4456 },
4457 /* BPF_JMP | BPF_JA */
4458 {
4459 "JMP_JA: Unconditional jump: if (true) return 1",
4460 .u.insns_int = {
4461 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4462 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4463 BPF_EXIT_INSN(),
4464 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4465 BPF_EXIT_INSN(),
4466 },
4467 INTERNAL,
4468 { },
4469 { { 0, 1 } },
4470 },
4471 /* BPF_JMP | BPF_JSGT | BPF_K */
4472 {
4473 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4474 .u.insns_int = {
4475 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4476 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4477 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4478 BPF_EXIT_INSN(),
4479 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4480 BPF_EXIT_INSN(),
4481 },
4482 INTERNAL,
4483 { },
4484 { { 0, 1 } },
4485 },
4486 {
4487 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4488 .u.insns_int = {
4489 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4490 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4491 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4492 BPF_EXIT_INSN(),
4493 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4494 BPF_EXIT_INSN(),
4495 },
4496 INTERNAL,
4497 { },
4498 { { 0, 1 } },
4499 },
4500 /* BPF_JMP | BPF_JSGE | BPF_K */
4501 {
4502 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4503 .u.insns_int = {
4504 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4505 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4506 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4507 BPF_EXIT_INSN(),
4508 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4509 BPF_EXIT_INSN(),
4510 },
4511 INTERNAL,
4512 { },
4513 { { 0, 1 } },
4514 },
4515 {
4516 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4517 .u.insns_int = {
4518 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4519 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4520 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4521 BPF_EXIT_INSN(),
4522 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4523 BPF_EXIT_INSN(),
4524 },
4525 INTERNAL,
4526 { },
4527 { { 0, 1 } },
4528 },
David Daney791caeb2017-05-24 16:35:49 -07004529 {
4530 "JMP_JSGE_K: Signed jump: value walk 1",
4531 .u.insns_int = {
4532 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4533 BPF_LD_IMM64(R1, -3),
4534 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
4535 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4536 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4537 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4538 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4539 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4540 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4541 BPF_EXIT_INSN(), /* bad exit */
4542 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4543 BPF_EXIT_INSN(),
4544 },
4545 INTERNAL,
4546 { },
4547 { { 0, 1 } },
4548 },
4549 {
4550 "JMP_JSGE_K: Signed jump: value walk 2",
4551 .u.insns_int = {
4552 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4553 BPF_LD_IMM64(R1, -3),
4554 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4555 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4556 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4557 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4558 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4559 BPF_EXIT_INSN(), /* bad exit */
4560 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4561 BPF_EXIT_INSN(),
4562 },
4563 INTERNAL,
4564 { },
4565 { { 0, 1 } },
4566 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004567 /* BPF_JMP | BPF_JGT | BPF_K */
4568 {
4569 "JMP_JGT_K: if (3 > 2) return 1",
4570 .u.insns_int = {
4571 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4572 BPF_LD_IMM64(R1, 3),
4573 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4574 BPF_EXIT_INSN(),
4575 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4576 BPF_EXIT_INSN(),
4577 },
4578 INTERNAL,
4579 { },
4580 { { 0, 1 } },
4581 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05304582 {
4583 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4584 .u.insns_int = {
4585 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4586 BPF_LD_IMM64(R1, -1),
4587 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
4588 BPF_EXIT_INSN(),
4589 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4590 BPF_EXIT_INSN(),
4591 },
4592 INTERNAL,
4593 { },
4594 { { 0, 1 } },
4595 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004596 /* BPF_JMP | BPF_JGE | BPF_K */
4597 {
4598 "JMP_JGE_K: if (3 >= 2) return 1",
4599 .u.insns_int = {
4600 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4601 BPF_LD_IMM64(R1, 3),
4602 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4603 BPF_EXIT_INSN(),
4604 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4605 BPF_EXIT_INSN(),
4606 },
4607 INTERNAL,
4608 { },
4609 { { 0, 1 } },
4610 },
Michael Holzheufe593842015-05-22 08:36:40 -07004611 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4612 {
4613 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4614 .u.insns_int = {
4615 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4616 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4617 BPF_EXIT_INSN(),
4618 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4619 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4620 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4621 BPF_EXIT_INSN(),
4622 },
4623 INTERNAL,
4624 { },
4625 { { 0, 1 } },
4626 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004627 {
4628 "JMP_JGE_K: if (3 >= 3) return 1",
4629 .u.insns_int = {
4630 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4631 BPF_LD_IMM64(R1, 3),
4632 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4633 BPF_EXIT_INSN(),
4634 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4635 BPF_EXIT_INSN(),
4636 },
4637 INTERNAL,
4638 { },
4639 { { 0, 1 } },
4640 },
4641 /* BPF_JMP | BPF_JNE | BPF_K */
4642 {
4643 "JMP_JNE_K: if (3 != 2) return 1",
4644 .u.insns_int = {
4645 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4646 BPF_LD_IMM64(R1, 3),
4647 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4648 BPF_EXIT_INSN(),
4649 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4650 BPF_EXIT_INSN(),
4651 },
4652 INTERNAL,
4653 { },
4654 { { 0, 1 } },
4655 },
4656 /* BPF_JMP | BPF_JEQ | BPF_K */
4657 {
4658 "JMP_JEQ_K: if (3 == 3) return 1",
4659 .u.insns_int = {
4660 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4661 BPF_LD_IMM64(R1, 3),
4662 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4663 BPF_EXIT_INSN(),
4664 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4665 BPF_EXIT_INSN(),
4666 },
4667 INTERNAL,
4668 { },
4669 { { 0, 1 } },
4670 },
4671 /* BPF_JMP | BPF_JSET | BPF_K */
4672 {
4673 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4674 .u.insns_int = {
4675 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4676 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304677 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004678 BPF_EXIT_INSN(),
4679 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4680 BPF_EXIT_INSN(),
4681 },
4682 INTERNAL,
4683 { },
4684 { { 0, 1 } },
4685 },
4686 {
4687 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4688 .u.insns_int = {
4689 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4690 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304691 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004692 BPF_EXIT_INSN(),
4693 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4694 BPF_EXIT_INSN(),
4695 },
4696 INTERNAL,
4697 { },
4698 { { 0, 1 } },
4699 },
4700 /* BPF_JMP | BPF_JSGT | BPF_X */
4701 {
4702 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4703 .u.insns_int = {
4704 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4705 BPF_LD_IMM64(R1, -1),
4706 BPF_LD_IMM64(R2, -2),
4707 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4708 BPF_EXIT_INSN(),
4709 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4710 BPF_EXIT_INSN(),
4711 },
4712 INTERNAL,
4713 { },
4714 { { 0, 1 } },
4715 },
4716 {
4717 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4718 .u.insns_int = {
4719 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4720 BPF_LD_IMM64(R1, -1),
4721 BPF_LD_IMM64(R2, -1),
4722 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4723 BPF_EXIT_INSN(),
4724 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4725 BPF_EXIT_INSN(),
4726 },
4727 INTERNAL,
4728 { },
4729 { { 0, 1 } },
4730 },
4731 /* BPF_JMP | BPF_JSGE | BPF_X */
4732 {
4733 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4734 .u.insns_int = {
4735 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4736 BPF_LD_IMM64(R1, -1),
4737 BPF_LD_IMM64(R2, -2),
4738 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4739 BPF_EXIT_INSN(),
4740 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4741 BPF_EXIT_INSN(),
4742 },
4743 INTERNAL,
4744 { },
4745 { { 0, 1 } },
4746 },
4747 {
4748 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4749 .u.insns_int = {
4750 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4751 BPF_LD_IMM64(R1, -1),
4752 BPF_LD_IMM64(R2, -1),
4753 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4754 BPF_EXIT_INSN(),
4755 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4756 BPF_EXIT_INSN(),
4757 },
4758 INTERNAL,
4759 { },
4760 { { 0, 1 } },
4761 },
4762 /* BPF_JMP | BPF_JGT | BPF_X */
4763 {
4764 "JMP_JGT_X: if (3 > 2) return 1",
4765 .u.insns_int = {
4766 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4767 BPF_LD_IMM64(R1, 3),
4768 BPF_LD_IMM64(R2, 2),
4769 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4770 BPF_EXIT_INSN(),
4771 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4772 BPF_EXIT_INSN(),
4773 },
4774 INTERNAL,
4775 { },
4776 { { 0, 1 } },
4777 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05304778 {
4779 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
4780 .u.insns_int = {
4781 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4782 BPF_LD_IMM64(R1, -1),
4783 BPF_LD_IMM64(R2, 1),
4784 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4785 BPF_EXIT_INSN(),
4786 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4787 BPF_EXIT_INSN(),
4788 },
4789 INTERNAL,
4790 { },
4791 { { 0, 1 } },
4792 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004793 /* BPF_JMP | BPF_JGE | BPF_X */
4794 {
4795 "JMP_JGE_X: if (3 >= 2) return 1",
4796 .u.insns_int = {
4797 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4798 BPF_LD_IMM64(R1, 3),
4799 BPF_LD_IMM64(R2, 2),
4800 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4801 BPF_EXIT_INSN(),
4802 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4803 BPF_EXIT_INSN(),
4804 },
4805 INTERNAL,
4806 { },
4807 { { 0, 1 } },
4808 },
4809 {
4810 "JMP_JGE_X: if (3 >= 3) return 1",
4811 .u.insns_int = {
4812 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4813 BPF_LD_IMM64(R1, 3),
4814 BPF_LD_IMM64(R2, 3),
4815 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4816 BPF_EXIT_INSN(),
4817 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4818 BPF_EXIT_INSN(),
4819 },
4820 INTERNAL,
4821 { },
4822 { { 0, 1 } },
4823 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02004824 {
4825 /* Mainly testing JIT + imm64 here. */
4826 "JMP_JGE_X: ldimm64 test 1",
4827 .u.insns_int = {
4828 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4829 BPF_LD_IMM64(R1, 3),
4830 BPF_LD_IMM64(R2, 2),
4831 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02004832 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
4833 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02004834 BPF_EXIT_INSN(),
4835 },
4836 INTERNAL,
4837 { },
4838 { { 0, 0xeeeeeeeeU } },
4839 },
4840 {
4841 "JMP_JGE_X: ldimm64 test 2",
4842 .u.insns_int = {
4843 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4844 BPF_LD_IMM64(R1, 3),
4845 BPF_LD_IMM64(R2, 2),
4846 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02004847 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02004848 BPF_EXIT_INSN(),
4849 },
4850 INTERNAL,
4851 { },
4852 { { 0, 0xffffffffU } },
4853 },
4854 {
4855 "JMP_JGE_X: ldimm64 test 3",
4856 .u.insns_int = {
4857 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4858 BPF_LD_IMM64(R1, 3),
4859 BPF_LD_IMM64(R2, 2),
4860 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02004861 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
4862 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02004863 BPF_EXIT_INSN(),
4864 },
4865 INTERNAL,
4866 { },
4867 { { 0, 1 } },
4868 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004869 /* BPF_JMP | BPF_JNE | BPF_X */
4870 {
4871 "JMP_JNE_X: if (3 != 2) return 1",
4872 .u.insns_int = {
4873 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4874 BPF_LD_IMM64(R1, 3),
4875 BPF_LD_IMM64(R2, 2),
4876 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4877 BPF_EXIT_INSN(),
4878 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4879 BPF_EXIT_INSN(),
4880 },
4881 INTERNAL,
4882 { },
4883 { { 0, 1 } },
4884 },
4885 /* BPF_JMP | BPF_JEQ | BPF_X */
4886 {
4887 "JMP_JEQ_X: if (3 == 3) return 1",
4888 .u.insns_int = {
4889 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4890 BPF_LD_IMM64(R1, 3),
4891 BPF_LD_IMM64(R2, 3),
4892 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4893 BPF_EXIT_INSN(),
4894 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4895 BPF_EXIT_INSN(),
4896 },
4897 INTERNAL,
4898 { },
4899 { { 0, 1 } },
4900 },
4901 /* BPF_JMP | BPF_JSET | BPF_X */
4902 {
4903 "JMP_JSET_X: if (0x3 & 0x2) return 1",
4904 .u.insns_int = {
4905 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4906 BPF_LD_IMM64(R1, 3),
4907 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304908 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004909 BPF_EXIT_INSN(),
4910 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4911 BPF_EXIT_INSN(),
4912 },
4913 INTERNAL,
4914 { },
4915 { { 0, 1 } },
4916 },
4917 {
4918 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
4919 .u.insns_int = {
4920 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4921 BPF_LD_IMM64(R1, 3),
4922 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304923 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004924 BPF_EXIT_INSN(),
4925 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4926 BPF_EXIT_INSN(),
4927 },
4928 INTERNAL,
4929 { },
4930 { { 0, 1 } },
4931 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02004932 {
4933 "JMP_JA: Jump, gap, jump, ...",
4934 { },
4935 CLASSIC | FLAG_NO_DATA,
4936 { },
4937 { { 0, 0xababcbac } },
4938 .fill_helper = bpf_fill_ja,
4939 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004940 { /* Mainly checking JIT here. */
4941 "BPF_MAXINSNS: Maximum possible literals",
4942 { },
4943 CLASSIC | FLAG_NO_DATA,
4944 { },
4945 { { 0, 0xffffffff } },
4946 .fill_helper = bpf_fill_maxinsns1,
4947 },
4948 { /* Mainly checking JIT here. */
4949 "BPF_MAXINSNS: Single literal",
4950 { },
4951 CLASSIC | FLAG_NO_DATA,
4952 { },
4953 { { 0, 0xfefefefe } },
4954 .fill_helper = bpf_fill_maxinsns2,
4955 },
4956 { /* Mainly checking JIT here. */
4957 "BPF_MAXINSNS: Run/add until end",
4958 { },
4959 CLASSIC | FLAG_NO_DATA,
4960 { },
4961 { { 0, 0x947bf368 } },
4962 .fill_helper = bpf_fill_maxinsns3,
4963 },
4964 {
4965 "BPF_MAXINSNS: Too many instructions",
4966 { },
4967 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4968 { },
4969 { },
4970 .fill_helper = bpf_fill_maxinsns4,
4971 },
4972 { /* Mainly checking JIT here. */
4973 "BPF_MAXINSNS: Very long jump",
4974 { },
4975 CLASSIC | FLAG_NO_DATA,
4976 { },
4977 { { 0, 0xabababab } },
4978 .fill_helper = bpf_fill_maxinsns5,
4979 },
4980 { /* Mainly checking JIT here. */
4981 "BPF_MAXINSNS: Ctx heavy transformations",
4982 { },
4983 CLASSIC,
4984 { },
4985 {
4986 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
4987 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
4988 },
4989 .fill_helper = bpf_fill_maxinsns6,
4990 },
4991 { /* Mainly checking JIT here. */
4992 "BPF_MAXINSNS: Call heavy transformations",
4993 { },
4994 CLASSIC | FLAG_NO_DATA,
4995 { },
4996 { { 1, 0 }, { 10, 0 } },
4997 .fill_helper = bpf_fill_maxinsns7,
4998 },
4999 { /* Mainly checking JIT here. */
5000 "BPF_MAXINSNS: Jump heavy test",
5001 { },
5002 CLASSIC | FLAG_NO_DATA,
5003 { },
5004 { { 0, 0xffffffff } },
5005 .fill_helper = bpf_fill_maxinsns8,
5006 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02005007 { /* Mainly checking JIT here. */
5008 "BPF_MAXINSNS: Very long jump backwards",
5009 { },
5010 INTERNAL | FLAG_NO_DATA,
5011 { },
5012 { { 0, 0xcbababab } },
5013 .fill_helper = bpf_fill_maxinsns9,
5014 },
5015 { /* Mainly checking JIT here. */
5016 "BPF_MAXINSNS: Edge hopping nuthouse",
5017 { },
5018 INTERNAL | FLAG_NO_DATA,
5019 { },
5020 { { 0, 0xabababac } },
5021 .fill_helper = bpf_fill_maxinsns10,
5022 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005023 {
5024 "BPF_MAXINSNS: Jump, gap, jump, ...",
5025 { },
5026 CLASSIC | FLAG_NO_DATA,
5027 { },
5028 { { 0, 0xababcbac } },
5029 .fill_helper = bpf_fill_maxinsns11,
5030 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005031 {
5032 "BPF_MAXINSNS: ld_abs+get_processor_id",
5033 { },
5034 CLASSIC,
5035 { },
5036 { { 1, 0xbee } },
5037 .fill_helper = bpf_fill_ld_abs_get_processor_id,
5038 },
5039 {
5040 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5041 { },
5042 INTERNAL,
5043 { 0x34 },
Daniel Borkmann0d906b12016-10-20 17:13:53 +02005044 { { ETH_HLEN, 0xbef } },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005045 .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
5046 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02005047 /*
5048 * LD_IND / LD_ABS on fragmented SKBs
5049 */
5050 {
5051 "LD_IND byte frag",
5052 .u.insns = {
5053 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5054 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
5055 BPF_STMT(BPF_RET | BPF_A, 0x0),
5056 },
5057 CLASSIC | FLAG_SKB_FRAG,
5058 { },
5059 { {0x40, 0x42} },
5060 .frag_data = {
5061 0x42, 0x00, 0x00, 0x00,
5062 0x43, 0x44, 0x00, 0x00,
5063 0x21, 0x07, 0x19, 0x83,
5064 },
5065 },
5066 {
5067 "LD_IND halfword frag",
5068 .u.insns = {
5069 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5070 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
5071 BPF_STMT(BPF_RET | BPF_A, 0x0),
5072 },
5073 CLASSIC | FLAG_SKB_FRAG,
5074 { },
5075 { {0x40, 0x4344} },
5076 .frag_data = {
5077 0x42, 0x00, 0x00, 0x00,
5078 0x43, 0x44, 0x00, 0x00,
5079 0x21, 0x07, 0x19, 0x83,
5080 },
5081 },
5082 {
5083 "LD_IND word frag",
5084 .u.insns = {
5085 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5086 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
5087 BPF_STMT(BPF_RET | BPF_A, 0x0),
5088 },
5089 CLASSIC | FLAG_SKB_FRAG,
5090 { },
5091 { {0x40, 0x21071983} },
5092 .frag_data = {
5093 0x42, 0x00, 0x00, 0x00,
5094 0x43, 0x44, 0x00, 0x00,
5095 0x21, 0x07, 0x19, 0x83,
5096 },
5097 },
5098 {
5099 "LD_IND halfword mixed head/frag",
5100 .u.insns = {
5101 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5102 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5103 BPF_STMT(BPF_RET | BPF_A, 0x0),
5104 },
5105 CLASSIC | FLAG_SKB_FRAG,
5106 { [0x3e] = 0x25, [0x3f] = 0x05, },
5107 { {0x40, 0x0519} },
5108 .frag_data = { 0x19, 0x82 },
5109 },
5110 {
5111 "LD_IND word mixed head/frag",
5112 .u.insns = {
5113 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5114 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5115 BPF_STMT(BPF_RET | BPF_A, 0x0),
5116 },
5117 CLASSIC | FLAG_SKB_FRAG,
5118 { [0x3e] = 0x25, [0x3f] = 0x05, },
5119 { {0x40, 0x25051982} },
5120 .frag_data = { 0x19, 0x82 },
5121 },
5122 {
5123 "LD_ABS byte frag",
5124 .u.insns = {
5125 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
5126 BPF_STMT(BPF_RET | BPF_A, 0x0),
5127 },
5128 CLASSIC | FLAG_SKB_FRAG,
5129 { },
5130 { {0x40, 0x42} },
5131 .frag_data = {
5132 0x42, 0x00, 0x00, 0x00,
5133 0x43, 0x44, 0x00, 0x00,
5134 0x21, 0x07, 0x19, 0x83,
5135 },
5136 },
5137 {
5138 "LD_ABS halfword frag",
5139 .u.insns = {
5140 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
5141 BPF_STMT(BPF_RET | BPF_A, 0x0),
5142 },
5143 CLASSIC | FLAG_SKB_FRAG,
5144 { },
5145 { {0x40, 0x4344} },
5146 .frag_data = {
5147 0x42, 0x00, 0x00, 0x00,
5148 0x43, 0x44, 0x00, 0x00,
5149 0x21, 0x07, 0x19, 0x83,
5150 },
5151 },
5152 {
5153 "LD_ABS word frag",
5154 .u.insns = {
5155 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
5156 BPF_STMT(BPF_RET | BPF_A, 0x0),
5157 },
5158 CLASSIC | FLAG_SKB_FRAG,
5159 { },
5160 { {0x40, 0x21071983} },
5161 .frag_data = {
5162 0x42, 0x00, 0x00, 0x00,
5163 0x43, 0x44, 0x00, 0x00,
5164 0x21, 0x07, 0x19, 0x83,
5165 },
5166 },
5167 {
5168 "LD_ABS halfword mixed head/frag",
5169 .u.insns = {
5170 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5171 BPF_STMT(BPF_RET | BPF_A, 0x0),
5172 },
5173 CLASSIC | FLAG_SKB_FRAG,
5174 { [0x3e] = 0x25, [0x3f] = 0x05, },
5175 { {0x40, 0x0519} },
5176 .frag_data = { 0x19, 0x82 },
5177 },
5178 {
5179 "LD_ABS word mixed head/frag",
5180 .u.insns = {
5181 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
5182 BPF_STMT(BPF_RET | BPF_A, 0x0),
5183 },
5184 CLASSIC | FLAG_SKB_FRAG,
5185 { [0x3e] = 0x25, [0x3f] = 0x05, },
5186 { {0x40, 0x25051982} },
5187 .frag_data = { 0x19, 0x82 },
5188 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005189 /*
5190 * LD_IND / LD_ABS on non fragmented SKBs
5191 */
5192 {
5193 /*
5194 * this tests that the JIT/interpreter correctly resets X
5195 * before using it in an LD_IND instruction.
5196 */
5197 "LD_IND byte default X",
5198 .u.insns = {
5199 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5200 BPF_STMT(BPF_RET | BPF_A, 0x0),
5201 },
5202 CLASSIC,
5203 { [0x1] = 0x42 },
5204 { {0x40, 0x42 } },
5205 },
5206 {
5207 "LD_IND byte positive offset",
5208 .u.insns = {
5209 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5210 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5211 BPF_STMT(BPF_RET | BPF_A, 0x0),
5212 },
5213 CLASSIC,
5214 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5215 { {0x40, 0x82 } },
5216 },
5217 {
5218 "LD_IND byte negative offset",
5219 .u.insns = {
5220 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5221 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
5222 BPF_STMT(BPF_RET | BPF_A, 0x0),
5223 },
5224 CLASSIC,
5225 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5226 { {0x40, 0x05 } },
5227 },
5228 {
5229 "LD_IND halfword positive offset",
5230 .u.insns = {
5231 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5232 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
5233 BPF_STMT(BPF_RET | BPF_A, 0x0),
5234 },
5235 CLASSIC,
5236 {
5237 [0x1c] = 0xaa, [0x1d] = 0x55,
5238 [0x1e] = 0xbb, [0x1f] = 0x66,
5239 [0x20] = 0xcc, [0x21] = 0x77,
5240 [0x22] = 0xdd, [0x23] = 0x88,
5241 },
5242 { {0x40, 0xdd88 } },
5243 },
5244 {
5245 "LD_IND halfword negative offset",
5246 .u.insns = {
5247 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5248 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
5249 BPF_STMT(BPF_RET | BPF_A, 0x0),
5250 },
5251 CLASSIC,
5252 {
5253 [0x1c] = 0xaa, [0x1d] = 0x55,
5254 [0x1e] = 0xbb, [0x1f] = 0x66,
5255 [0x20] = 0xcc, [0x21] = 0x77,
5256 [0x22] = 0xdd, [0x23] = 0x88,
5257 },
5258 { {0x40, 0xbb66 } },
5259 },
5260 {
5261 "LD_IND halfword unaligned",
5262 .u.insns = {
5263 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5264 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5265 BPF_STMT(BPF_RET | BPF_A, 0x0),
5266 },
5267 CLASSIC,
5268 {
5269 [0x1c] = 0xaa, [0x1d] = 0x55,
5270 [0x1e] = 0xbb, [0x1f] = 0x66,
5271 [0x20] = 0xcc, [0x21] = 0x77,
5272 [0x22] = 0xdd, [0x23] = 0x88,
5273 },
5274 { {0x40, 0x66cc } },
5275 },
5276 {
5277 "LD_IND word positive offset",
5278 .u.insns = {
5279 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5280 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
5281 BPF_STMT(BPF_RET | BPF_A, 0x0),
5282 },
5283 CLASSIC,
5284 {
5285 [0x1c] = 0xaa, [0x1d] = 0x55,
5286 [0x1e] = 0xbb, [0x1f] = 0x66,
5287 [0x20] = 0xcc, [0x21] = 0x77,
5288 [0x22] = 0xdd, [0x23] = 0x88,
5289 [0x24] = 0xee, [0x25] = 0x99,
5290 [0x26] = 0xff, [0x27] = 0xaa,
5291 },
5292 { {0x40, 0xee99ffaa } },
5293 },
5294 {
5295 "LD_IND word negative offset",
5296 .u.insns = {
5297 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5298 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
5299 BPF_STMT(BPF_RET | BPF_A, 0x0),
5300 },
5301 CLASSIC,
5302 {
5303 [0x1c] = 0xaa, [0x1d] = 0x55,
5304 [0x1e] = 0xbb, [0x1f] = 0x66,
5305 [0x20] = 0xcc, [0x21] = 0x77,
5306 [0x22] = 0xdd, [0x23] = 0x88,
5307 [0x24] = 0xee, [0x25] = 0x99,
5308 [0x26] = 0xff, [0x27] = 0xaa,
5309 },
5310 { {0x40, 0xaa55bb66 } },
5311 },
5312 {
5313 "LD_IND word unaligned (addr & 3 == 2)",
5314 .u.insns = {
5315 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5316 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5317 BPF_STMT(BPF_RET | BPF_A, 0x0),
5318 },
5319 CLASSIC,
5320 {
5321 [0x1c] = 0xaa, [0x1d] = 0x55,
5322 [0x1e] = 0xbb, [0x1f] = 0x66,
5323 [0x20] = 0xcc, [0x21] = 0x77,
5324 [0x22] = 0xdd, [0x23] = 0x88,
5325 [0x24] = 0xee, [0x25] = 0x99,
5326 [0x26] = 0xff, [0x27] = 0xaa,
5327 },
5328 { {0x40, 0xbb66cc77 } },
5329 },
5330 {
5331 "LD_IND word unaligned (addr & 3 == 1)",
5332 .u.insns = {
5333 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5334 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
5335 BPF_STMT(BPF_RET | BPF_A, 0x0),
5336 },
5337 CLASSIC,
5338 {
5339 [0x1c] = 0xaa, [0x1d] = 0x55,
5340 [0x1e] = 0xbb, [0x1f] = 0x66,
5341 [0x20] = 0xcc, [0x21] = 0x77,
5342 [0x22] = 0xdd, [0x23] = 0x88,
5343 [0x24] = 0xee, [0x25] = 0x99,
5344 [0x26] = 0xff, [0x27] = 0xaa,
5345 },
5346 { {0x40, 0x55bb66cc } },
5347 },
5348 {
5349 "LD_IND word unaligned (addr & 3 == 3)",
5350 .u.insns = {
5351 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5352 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
5353 BPF_STMT(BPF_RET | BPF_A, 0x0),
5354 },
5355 CLASSIC,
5356 {
5357 [0x1c] = 0xaa, [0x1d] = 0x55,
5358 [0x1e] = 0xbb, [0x1f] = 0x66,
5359 [0x20] = 0xcc, [0x21] = 0x77,
5360 [0x22] = 0xdd, [0x23] = 0x88,
5361 [0x24] = 0xee, [0x25] = 0x99,
5362 [0x26] = 0xff, [0x27] = 0xaa,
5363 },
5364 { {0x40, 0x66cc77dd } },
5365 },
5366 {
5367 "LD_ABS byte",
5368 .u.insns = {
5369 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
5370 BPF_STMT(BPF_RET | BPF_A, 0x0),
5371 },
5372 CLASSIC,
5373 {
5374 [0x1c] = 0xaa, [0x1d] = 0x55,
5375 [0x1e] = 0xbb, [0x1f] = 0x66,
5376 [0x20] = 0xcc, [0x21] = 0x77,
5377 [0x22] = 0xdd, [0x23] = 0x88,
5378 [0x24] = 0xee, [0x25] = 0x99,
5379 [0x26] = 0xff, [0x27] = 0xaa,
5380 },
5381 { {0x40, 0xcc } },
5382 },
5383 {
5384 "LD_ABS halfword",
5385 .u.insns = {
5386 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
5387 BPF_STMT(BPF_RET | BPF_A, 0x0),
5388 },
5389 CLASSIC,
5390 {
5391 [0x1c] = 0xaa, [0x1d] = 0x55,
5392 [0x1e] = 0xbb, [0x1f] = 0x66,
5393 [0x20] = 0xcc, [0x21] = 0x77,
5394 [0x22] = 0xdd, [0x23] = 0x88,
5395 [0x24] = 0xee, [0x25] = 0x99,
5396 [0x26] = 0xff, [0x27] = 0xaa,
5397 },
5398 { {0x40, 0xdd88 } },
5399 },
5400 {
5401 "LD_ABS halfword unaligned",
5402 .u.insns = {
5403 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
5404 BPF_STMT(BPF_RET | BPF_A, 0x0),
5405 },
5406 CLASSIC,
5407 {
5408 [0x1c] = 0xaa, [0x1d] = 0x55,
5409 [0x1e] = 0xbb, [0x1f] = 0x66,
5410 [0x20] = 0xcc, [0x21] = 0x77,
5411 [0x22] = 0xdd, [0x23] = 0x88,
5412 [0x24] = 0xee, [0x25] = 0x99,
5413 [0x26] = 0xff, [0x27] = 0xaa,
5414 },
5415 { {0x40, 0x99ff } },
5416 },
5417 {
5418 "LD_ABS word",
5419 .u.insns = {
5420 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
5421 BPF_STMT(BPF_RET | BPF_A, 0x0),
5422 },
5423 CLASSIC,
5424 {
5425 [0x1c] = 0xaa, [0x1d] = 0x55,
5426 [0x1e] = 0xbb, [0x1f] = 0x66,
5427 [0x20] = 0xcc, [0x21] = 0x77,
5428 [0x22] = 0xdd, [0x23] = 0x88,
5429 [0x24] = 0xee, [0x25] = 0x99,
5430 [0x26] = 0xff, [0x27] = 0xaa,
5431 },
5432 { {0x40, 0xaa55bb66 } },
5433 },
5434 {
5435 "LD_ABS word unaligned (addr & 3 == 2)",
5436 .u.insns = {
5437 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
5438 BPF_STMT(BPF_RET | BPF_A, 0x0),
5439 },
5440 CLASSIC,
5441 {
5442 [0x1c] = 0xaa, [0x1d] = 0x55,
5443 [0x1e] = 0xbb, [0x1f] = 0x66,
5444 [0x20] = 0xcc, [0x21] = 0x77,
5445 [0x22] = 0xdd, [0x23] = 0x88,
5446 [0x24] = 0xee, [0x25] = 0x99,
5447 [0x26] = 0xff, [0x27] = 0xaa,
5448 },
5449 { {0x40, 0xdd88ee99 } },
5450 },
5451 {
5452 "LD_ABS word unaligned (addr & 3 == 1)",
5453 .u.insns = {
5454 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
5455 BPF_STMT(BPF_RET | BPF_A, 0x0),
5456 },
5457 CLASSIC,
5458 {
5459 [0x1c] = 0xaa, [0x1d] = 0x55,
5460 [0x1e] = 0xbb, [0x1f] = 0x66,
5461 [0x20] = 0xcc, [0x21] = 0x77,
5462 [0x22] = 0xdd, [0x23] = 0x88,
5463 [0x24] = 0xee, [0x25] = 0x99,
5464 [0x26] = 0xff, [0x27] = 0xaa,
5465 },
5466 { {0x40, 0x77dd88ee } },
5467 },
5468 {
5469 "LD_ABS word unaligned (addr & 3 == 3)",
5470 .u.insns = {
5471 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
5472 BPF_STMT(BPF_RET | BPF_A, 0x0),
5473 },
5474 CLASSIC,
5475 {
5476 [0x1c] = 0xaa, [0x1d] = 0x55,
5477 [0x1e] = 0xbb, [0x1f] = 0x66,
5478 [0x20] = 0xcc, [0x21] = 0x77,
5479 [0x22] = 0xdd, [0x23] = 0x88,
5480 [0x24] = 0xee, [0x25] = 0x99,
5481 [0x26] = 0xff, [0x27] = 0xaa,
5482 },
5483 { {0x40, 0x88ee99ff } },
5484 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02005485 /*
5486 * verify that the interpreter or JIT correctly sets A and X
5487 * to 0.
5488 */
5489 {
5490 "ADD default X",
5491 .u.insns = {
5492 /*
5493 * A = 0x42
5494 * A = A + X
5495 * ret A
5496 */
5497 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5498 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
5499 BPF_STMT(BPF_RET | BPF_A, 0x0),
5500 },
5501 CLASSIC | FLAG_NO_DATA,
5502 {},
5503 { {0x1, 0x42 } },
5504 },
5505 {
5506 "ADD default A",
5507 .u.insns = {
5508 /*
5509 * A = A + 0x42
5510 * ret A
5511 */
5512 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
5513 BPF_STMT(BPF_RET | BPF_A, 0x0),
5514 },
5515 CLASSIC | FLAG_NO_DATA,
5516 {},
5517 { {0x1, 0x42 } },
5518 },
5519 {
5520 "SUB default X",
5521 .u.insns = {
5522 /*
5523 * A = 0x66
5524 * A = A - X
5525 * ret A
5526 */
5527 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
5528 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
5529 BPF_STMT(BPF_RET | BPF_A, 0x0),
5530 },
5531 CLASSIC | FLAG_NO_DATA,
5532 {},
5533 { {0x1, 0x66 } },
5534 },
5535 {
5536 "SUB default A",
5537 .u.insns = {
5538 /*
5539 * A = A - -0x66
5540 * ret A
5541 */
5542 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
5543 BPF_STMT(BPF_RET | BPF_A, 0x0),
5544 },
5545 CLASSIC | FLAG_NO_DATA,
5546 {},
5547 { {0x1, 0x66 } },
5548 },
5549 {
5550 "MUL default X",
5551 .u.insns = {
5552 /*
5553 * A = 0x42
5554 * A = A * X
5555 * ret A
5556 */
5557 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5558 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
5559 BPF_STMT(BPF_RET | BPF_A, 0x0),
5560 },
5561 CLASSIC | FLAG_NO_DATA,
5562 {},
5563 { {0x1, 0x0 } },
5564 },
5565 {
5566 "MUL default A",
5567 .u.insns = {
5568 /*
5569 * A = A * 0x66
5570 * ret A
5571 */
5572 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
5573 BPF_STMT(BPF_RET | BPF_A, 0x0),
5574 },
5575 CLASSIC | FLAG_NO_DATA,
5576 {},
5577 { {0x1, 0x0 } },
5578 },
5579 {
5580 "DIV default X",
5581 .u.insns = {
5582 /*
5583 * A = 0x42
5584 * A = A / X ; this halt the filter execution if X is 0
5585 * ret 0x42
5586 */
5587 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5588 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
5589 BPF_STMT(BPF_RET | BPF_K, 0x42),
5590 },
5591 CLASSIC | FLAG_NO_DATA,
5592 {},
5593 { {0x1, 0x0 } },
5594 },
5595 {
5596 "DIV default A",
5597 .u.insns = {
5598 /*
5599 * A = A / 1
5600 * ret A
5601 */
5602 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
5603 BPF_STMT(BPF_RET | BPF_A, 0x0),
5604 },
5605 CLASSIC | FLAG_NO_DATA,
5606 {},
5607 { {0x1, 0x0 } },
5608 },
5609 {
Yang Shid4e4bc12015-11-04 11:36:37 -08005610 "MOD default X",
5611 .u.insns = {
5612 /*
5613 * A = 0x42
5614 * A = A mod X ; this halt the filter execution if X is 0
5615 * ret 0x42
5616 */
5617 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5618 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
5619 BPF_STMT(BPF_RET | BPF_K, 0x42),
5620 },
5621 CLASSIC | FLAG_NO_DATA,
5622 {},
5623 { {0x1, 0x0 } },
5624 },
5625 {
5626 "MOD default A",
5627 .u.insns = {
5628 /*
5629 * A = A mod 1
5630 * ret A
5631 */
5632 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
5633 BPF_STMT(BPF_RET | BPF_A, 0x0),
5634 },
5635 CLASSIC | FLAG_NO_DATA,
5636 {},
5637 { {0x1, 0x0 } },
5638 },
5639 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02005640 "JMP EQ default A",
5641 .u.insns = {
5642 /*
5643 * cmp A, 0x0, 0, 1
5644 * ret 0x42
5645 * ret 0x66
5646 */
5647 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
5648 BPF_STMT(BPF_RET | BPF_K, 0x42),
5649 BPF_STMT(BPF_RET | BPF_K, 0x66),
5650 },
5651 CLASSIC | FLAG_NO_DATA,
5652 {},
5653 { {0x1, 0x42 } },
5654 },
5655 {
5656 "JMP EQ default X",
5657 .u.insns = {
5658 /*
5659 * A = 0x0
5660 * cmp A, X, 0, 1
5661 * ret 0x42
5662 * ret 0x66
5663 */
5664 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
5665 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
5666 BPF_STMT(BPF_RET | BPF_K, 0x42),
5667 BPF_STMT(BPF_RET | BPF_K, 0x66),
5668 },
5669 CLASSIC | FLAG_NO_DATA,
5670 {},
5671 { {0x1, 0x42 } },
5672 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005673};
5674
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005675static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005676
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005677static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005678{
5679 struct sk_buff *skb;
5680
5681 if (size >= MAX_DATA)
5682 return NULL;
5683
5684 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
5685 if (!skb)
5686 return NULL;
5687
5688 memcpy(__skb_put(skb, size), buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005689
5690 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005691 skb_reset_mac_header(skb);
5692 skb->protocol = htons(ETH_P_IP);
5693 skb->pkt_type = SKB_TYPE;
5694 skb->mark = SKB_MARK;
5695 skb->hash = SKB_HASH;
5696 skb->queue_mapping = SKB_QUEUE_MAP;
5697 skb->vlan_tci = SKB_VLAN_TCI;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01005698 skb->vlan_proto = htons(ETH_P_IP);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005699 skb->dev = &dev;
5700 skb->dev->ifindex = SKB_DEV_IFINDEX;
5701 skb->dev->type = SKB_DEV_TYPE;
5702 skb_set_network_header(skb, min(size, ETH_HLEN));
5703
5704 return skb;
5705}
5706
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005707static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005708{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02005709 struct sk_buff *skb;
5710 struct page *page;
5711
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005712 if (test->aux & FLAG_NO_DATA)
5713 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005714
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005715 /* Test case expects an skb, so populate one. Various
5716 * subtests generate skbs of different sizes based on
5717 * the same data.
5718 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02005719 skb = populate_skb(test->data, test->test[sub].data_size);
5720 if (!skb)
5721 return NULL;
5722
5723 if (test->aux & FLAG_SKB_FRAG) {
5724 /*
5725 * when the test requires a fragmented skb, add a
5726 * single fragment to the skb, filled with
5727 * test->frag_data.
5728 */
5729 void *ptr;
5730
5731 page = alloc_page(GFP_KERNEL);
5732
5733 if (!page)
5734 goto err_kfree_skb;
5735
5736 ptr = kmap(page);
5737 if (!ptr)
5738 goto err_free_page;
5739 memcpy(ptr, test->frag_data, MAX_DATA);
5740 kunmap(page);
5741 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
5742 }
5743
5744 return skb;
5745
5746err_free_page:
5747 __free_page(page);
5748err_kfree_skb:
5749 kfree_skb(skb);
5750 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005751}
5752
5753static void release_test_data(const struct bpf_test *test, void *data)
5754{
5755 if (test->aux & FLAG_NO_DATA)
5756 return;
5757
5758 kfree_skb(data);
5759}
5760
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005761static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005762{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005763 struct sock_filter *fp;
5764 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005765
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005766 if (tests[which].fill_helper)
5767 return tests[which].u.ptr.len;
5768
5769 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07005770 for (len = MAX_INSNS - 1; len > 0; --len)
5771 if (fp[len].code != 0 || fp[len].k != 0)
5772 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005773
Chema Gonzaleze9d94502014-05-30 10:15:12 -07005774 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005775}
5776
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005777static void *filter_pointer(int which)
5778{
5779 if (tests[which].fill_helper)
5780 return tests[which].u.ptr.insns;
5781 else
5782 return tests[which].u.insns;
5783}
5784
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005785static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005786{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005787 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005788 unsigned int flen = filter_length(which);
5789 void *fptr = filter_pointer(which);
5790 struct sock_fprog_kern fprog;
5791 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005792
5793 switch (test_type) {
5794 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005795 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005796 fprog.len = flen;
5797
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005798 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005799 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
5800 if (*err == -EINVAL) {
5801 pr_cont("PASS\n");
5802 /* Verifier rejected filter as expected. */
5803 *err = 0;
5804 return NULL;
5805 } else {
5806 pr_cont("UNEXPECTED_PASS\n");
5807 /* Verifier didn't reject the test that's
5808 * bad enough, just return!
5809 */
5810 *err = -EINVAL;
5811 return NULL;
5812 }
5813 }
5814 /* We don't expect to fail. */
5815 if (*err) {
5816 pr_cont("FAIL to attach err=%d len=%d\n",
5817 *err, fprog.len);
5818 return NULL;
5819 }
5820 break;
5821
5822 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02005823 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005824 if (fp == NULL) {
5825 pr_cont("UNEXPECTED_FAIL no memory left\n");
5826 *err = -ENOMEM;
5827 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005828 }
5829
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005830 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02005831 /* Type doesn't really matter here as long as it's not unspec. */
5832 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005833 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005834 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005835
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02005836 /* We cannot error here as we don't need type compatibility
5837 * checks.
5838 */
5839 fp = bpf_prog_select_runtime(fp, err);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005840 break;
5841 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005842
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005843 *err = 0;
5844 return fp;
5845}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005846
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005847static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005848{
5849 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005850
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005851 switch (test_type) {
5852 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005853 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005854 break;
5855 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005856 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005857 break;
5858 }
5859}
5860
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005861static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005862 int runs, u64 *duration)
5863{
5864 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07005865 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005866
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005867 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005868
5869 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005870 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005871
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005872 finish = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005873
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005874 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005875 do_div(*duration, runs);
5876
5877 return ret;
5878}
5879
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07005880static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005881{
5882 int err_cnt = 0, i, runs = MAX_TESTRUNS;
5883
5884 for (i = 0; i < MAX_SUBTESTS; i++) {
5885 void *data;
5886 u64 duration;
5887 u32 ret;
5888
5889 if (test->test[i].data_size == 0 &&
5890 test->test[i].result == 0)
5891 break;
5892
5893 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02005894 if (!data && !(test->aux & FLAG_NO_DATA)) {
5895 pr_cont("data generation failed ");
5896 err_cnt++;
5897 break;
5898 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02005899 ret = __run_one(fp, data, runs, &duration);
5900 release_test_data(test, data);
5901
5902 if (ret == test->test[i].result) {
5903 pr_cont("%lld ", duration);
5904 } else {
5905 pr_cont("ret %d != %d ", ret,
5906 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07005907 err_cnt++;
5908 }
5909 }
5910
5911 return err_cnt;
5912}
5913
Nicolas Schichand2648d42015-08-04 15:19:10 +02005914static char test_name[64];
5915module_param_string(test_name, test_name, sizeof(test_name), 0);
5916
5917static int test_id = -1;
5918module_param(test_id, int, 0);
5919
5920static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
5921module_param_array(test_range, int, NULL, 0);
5922
5923static __init int find_test_index(const char *test_name)
5924{
5925 int i;
5926
5927 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5928 if (!strcmp(tests[i].descr, test_name))
5929 return i;
5930 }
5931 return -1;
5932}
5933
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005934static __init int prepare_bpf_tests(void)
5935{
5936 int i;
5937
Nicolas Schichand2648d42015-08-04 15:19:10 +02005938 if (test_id >= 0) {
5939 /*
5940 * if a test_id was specified, use test_range to
5941 * cover only that test.
5942 */
5943 if (test_id >= ARRAY_SIZE(tests)) {
5944 pr_err("test_bpf: invalid test_id specified.\n");
5945 return -EINVAL;
5946 }
5947
5948 test_range[0] = test_id;
5949 test_range[1] = test_id;
5950 } else if (*test_name) {
5951 /*
5952 * if a test_name was specified, find it and setup
5953 * test_range to cover only that test.
5954 */
5955 int idx = find_test_index(test_name);
5956
5957 if (idx < 0) {
5958 pr_err("test_bpf: no test named '%s' found.\n",
5959 test_name);
5960 return -EINVAL;
5961 }
5962 test_range[0] = idx;
5963 test_range[1] = idx;
5964 } else {
5965 /*
5966 * check that the supplied test_range is valid.
5967 */
5968 if (test_range[0] >= ARRAY_SIZE(tests) ||
5969 test_range[1] >= ARRAY_SIZE(tests) ||
5970 test_range[0] < 0 || test_range[1] < 0) {
5971 pr_err("test_bpf: test_range is out of bound.\n");
5972 return -EINVAL;
5973 }
5974
5975 if (test_range[1] < test_range[0]) {
5976 pr_err("test_bpf: test_range is ending before it starts.\n");
5977 return -EINVAL;
5978 }
5979 }
5980
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005981 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5982 if (tests[i].fill_helper &&
5983 tests[i].fill_helper(&tests[i]) < 0)
5984 return -ENOMEM;
5985 }
5986
5987 return 0;
5988}
5989
5990static __init void destroy_bpf_tests(void)
5991{
5992 int i;
5993
5994 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5995 if (tests[i].fill_helper)
5996 kfree(tests[i].u.ptr.insns);
5997 }
5998}
5999
Nicolas Schichand2648d42015-08-04 15:19:10 +02006000static bool exclude_test(int test_id)
6001{
6002 return test_id < test_range[0] || test_id > test_range[1];
6003}
6004
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006005static __init int test_bpf(void)
6006{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006007 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02006008 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006009
6010 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006011 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006012 int err;
6013
Nicolas Schichand2648d42015-08-04 15:19:10 +02006014 if (exclude_test(i))
6015 continue;
6016
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006017 pr_info("#%d %s ", i, tests[i].descr);
6018
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006019 fp = generate_filter(i, &err);
6020 if (fp == NULL) {
6021 if (err == 0) {
6022 pass_cnt++;
6023 continue;
6024 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006025
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006026 return err;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006027 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02006028
6029 pr_cont("jited:%u ", fp->jited);
6030
6031 run_cnt++;
6032 if (fp->jited)
6033 jit_cnt++;
6034
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006035 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006036 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006037
6038 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006039 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006040 err_cnt++;
6041 } else {
6042 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006043 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006044 }
6045 }
6046
Daniel Borkmann327941f2015-04-30 16:17:27 +02006047 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6048 pass_cnt, err_cnt, jit_cnt, run_cnt);
6049
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006050 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006051}
6052
6053static int __init test_bpf_init(void)
6054{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006055 int ret;
6056
6057 ret = prepare_bpf_tests();
6058 if (ret < 0)
6059 return ret;
6060
6061 ret = test_bpf();
6062
6063 destroy_bpf_tests();
6064 return ret;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006065}
6066
6067static void __exit test_bpf_exit(void)
6068{
6069}
6070
6071module_init(test_bpf_init);
6072module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006073
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006074MODULE_LICENSE("GPL");