blob: 6843d0b6203295910bf500691f7301cb1b695e93 [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>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070026
Daniel Borkmann10f18e02014-05-23 18:44:00 +020027/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070028#define MAX_SUBTESTS 3
Daniel Borkmann10f18e02014-05-23 18:44:00 +020029#define MAX_TESTRUNS 10000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070030#define MAX_DATA 128
31#define MAX_INSNS 512
32#define MAX_K 0xffffFFFF
33
Daniel Borkmann10f18e02014-05-23 18:44:00 +020034/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070035#define SKB_TYPE 3
36#define SKB_MARK 0x1234aaaa
37#define SKB_HASH 0x1234aaab
38#define SKB_QUEUE_MAP 123
39#define SKB_VLAN_TCI 0xffff
40#define SKB_DEV_IFINDEX 577
41#define SKB_DEV_TYPE 588
42
Daniel Borkmann10f18e02014-05-23 18:44:00 +020043/* Redefine REGs to make tests less verbose */
44#define R0 BPF_REG_0
45#define R1 BPF_REG_1
46#define R2 BPF_REG_2
47#define R3 BPF_REG_3
48#define R4 BPF_REG_4
49#define R5 BPF_REG_5
50#define R6 BPF_REG_6
51#define R7 BPF_REG_7
52#define R8 BPF_REG_8
53#define R9 BPF_REG_9
54#define R10 BPF_REG_10
55
56/* Flags that can be passed to test cases */
57#define FLAG_NO_DATA BIT(0)
58#define FLAG_EXPECTED_FAIL BIT(1)
59
60enum {
61 CLASSIC = BIT(6), /* Old BPF instructions only. */
62 INTERNAL = BIT(7), /* Extended instruction set. */
63};
64
65#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070066
67struct bpf_test {
68 const char *descr;
69 union {
70 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070071 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020072 struct {
73 void *insns;
74 unsigned int len;
75 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070076 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020077 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070078 __u8 data[MAX_DATA];
79 struct {
80 int data_size;
81 __u32 result;
82 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020083 int (*fill_helper)(struct bpf_test *self);
Alexei Starovoitov64a89462014-05-08 14:10:52 -070084};
85
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020086/* Large test cases need separate allocation and fill handler. */
87
88static int bpf_fill_maxinsns1(struct bpf_test *self)
89{
90 unsigned int len = BPF_MAXINSNS;
91 struct sock_filter *insn;
92 __u32 k = ~0;
93 int i;
94
95 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
96 if (!insn)
97 return -ENOMEM;
98
99 for (i = 0; i < len; i++, k--)
100 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
101
102 self->u.ptr.insns = insn;
103 self->u.ptr.len = len;
104
105 return 0;
106}
107
108static int bpf_fill_maxinsns2(struct bpf_test *self)
109{
110 unsigned int len = BPF_MAXINSNS;
111 struct sock_filter *insn;
112 int i;
113
114 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
115 if (!insn)
116 return -ENOMEM;
117
118 for (i = 0; i < len; i++)
119 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
120
121 self->u.ptr.insns = insn;
122 self->u.ptr.len = len;
123
124 return 0;
125}
126
127static int bpf_fill_maxinsns3(struct bpf_test *self)
128{
129 unsigned int len = BPF_MAXINSNS;
130 struct sock_filter *insn;
131 struct rnd_state rnd;
132 int i;
133
134 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
135 if (!insn)
136 return -ENOMEM;
137
138 prandom_seed_state(&rnd, 3141592653589793238ULL);
139
140 for (i = 0; i < len - 1; i++) {
141 __u32 k = prandom_u32_state(&rnd);
142
143 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
144 }
145
146 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
147
148 self->u.ptr.insns = insn;
149 self->u.ptr.len = len;
150
151 return 0;
152}
153
154static int bpf_fill_maxinsns4(struct bpf_test *self)
155{
156 unsigned int len = BPF_MAXINSNS + 1;
157 struct sock_filter *insn;
158 int i;
159
160 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
161 if (!insn)
162 return -ENOMEM;
163
164 for (i = 0; i < len; i++)
165 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
166
167 self->u.ptr.insns = insn;
168 self->u.ptr.len = len;
169
170 return 0;
171}
172
173static int bpf_fill_maxinsns5(struct bpf_test *self)
174{
175 unsigned int len = BPF_MAXINSNS;
176 struct sock_filter *insn;
177 int i;
178
179 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
180 if (!insn)
181 return -ENOMEM;
182
183 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
184
185 for (i = 1; i < len - 1; i++)
186 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
187
188 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
189
190 self->u.ptr.insns = insn;
191 self->u.ptr.len = len;
192
193 return 0;
194}
195
196static int bpf_fill_maxinsns6(struct bpf_test *self)
197{
198 unsigned int len = BPF_MAXINSNS;
199 struct sock_filter *insn;
200 int i;
201
202 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
203 if (!insn)
204 return -ENOMEM;
205
206 for (i = 0; i < len - 1; i++)
207 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
208 SKF_AD_VLAN_TAG_PRESENT);
209
210 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
211
212 self->u.ptr.insns = insn;
213 self->u.ptr.len = len;
214
215 return 0;
216}
217
218static int bpf_fill_maxinsns7(struct bpf_test *self)
219{
220 unsigned int len = BPF_MAXINSNS;
221 struct sock_filter *insn;
222 int i;
223
224 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
225 if (!insn)
226 return -ENOMEM;
227
228 for (i = 0; i < len - 4; i++)
229 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
230 SKF_AD_CPU);
231
232 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
233 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 SKF_AD_CPU);
235 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
236 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
237
238 self->u.ptr.insns = insn;
239 self->u.ptr.len = len;
240
241 return 0;
242}
243
244static int bpf_fill_maxinsns8(struct bpf_test *self)
245{
246 unsigned int len = BPF_MAXINSNS;
247 struct sock_filter *insn;
248 int i, jmp_off = len - 3;
249
250 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
251 if (!insn)
252 return -ENOMEM;
253
254 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
255
256 for (i = 1; i < len - 1; i++)
257 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
258
259 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
260
261 self->u.ptr.insns = insn;
262 self->u.ptr.len = len;
263
264 return 0;
265}
266
Daniel Borkmann3b529602015-05-23 01:10:07 +0200267static int bpf_fill_maxinsns9(struct bpf_test *self)
268{
269 unsigned int len = BPF_MAXINSNS;
270 struct bpf_insn *insn;
271 int i;
272
273 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
274 if (!insn)
275 return -ENOMEM;
276
277 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
278 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
279 insn[2] = BPF_EXIT_INSN();
280
281 for (i = 3; i < len - 2; i++)
282 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
283
284 insn[len - 2] = BPF_EXIT_INSN();
285 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
286
287 self->u.ptr.insns = insn;
288 self->u.ptr.len = len;
289
290 return 0;
291}
292
293static int bpf_fill_maxinsns10(struct bpf_test *self)
294{
295 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
296 struct bpf_insn *insn;
297 int i;
298
299 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
300 if (!insn)
301 return -ENOMEM;
302
303 for (i = 0; i < hlen / 2; i++)
304 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
305 for (i = hlen - 1; i > hlen / 2; i--)
306 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
307
308 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
309 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
310 insn[hlen + 1] = BPF_EXIT_INSN();
311
312 self->u.ptr.insns = insn;
313 self->u.ptr.len = len;
314
315 return 0;
316}
317
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200318static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
319 unsigned int plen)
320{
321 struct sock_filter *insn;
322 unsigned int rlen;
323 int i, j;
324
325 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
326 if (!insn)
327 return -ENOMEM;
328
329 rlen = (len % plen) - 1;
330
331 for (i = 0; i + plen < len; i += plen)
332 for (j = 0; j < plen; j++)
333 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
334 plen - 1 - j, 0, 0);
335 for (j = 0; j < rlen; j++)
336 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
337 0, 0);
338
339 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
340
341 self->u.ptr.insns = insn;
342 self->u.ptr.len = len;
343
344 return 0;
345}
346
347static int bpf_fill_maxinsns11(struct bpf_test *self)
348{
349 /* Hits 70 passes on x86_64, so cannot get JITed there. */
350 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
351}
352
353static int bpf_fill_ja(struct bpf_test *self)
354{
355 /* Hits exactly 11 passes on x86_64 JIT. */
356 return __bpf_fill_ja(self, 12, 9);
357}
358
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700359static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
360{
361 unsigned int len = BPF_MAXINSNS;
362 struct sock_filter *insn;
363 int i;
364
365 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
366 if (!insn)
367 return -ENOMEM;
368
369 for (i = 0; i < len - 1; i += 2) {
370 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
371 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
372 SKF_AD_OFF + SKF_AD_CPU);
373 }
374
375 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
376
377 self->u.ptr.insns = insn;
378 self->u.ptr.len = len;
379
380 return 0;
381}
382
383#define PUSH_CNT 68
384/* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
385static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
386{
387 unsigned int len = BPF_MAXINSNS;
388 struct bpf_insn *insn;
389 int i = 0, j, k = 0;
390
391 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
392 if (!insn)
393 return -ENOMEM;
394
395 insn[i++] = BPF_MOV64_REG(R6, R1);
396loop:
397 for (j = 0; j < PUSH_CNT; j++) {
398 insn[i++] = BPF_LD_ABS(BPF_B, 0);
399 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
400 i++;
401 insn[i++] = BPF_MOV64_REG(R1, R6);
402 insn[i++] = BPF_MOV64_IMM(R2, 1);
403 insn[i++] = BPF_MOV64_IMM(R3, 2);
404 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
405 bpf_skb_vlan_push_proto.func - __bpf_call_base);
406 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
407 i++;
408 }
409
410 for (j = 0; j < PUSH_CNT; j++) {
411 insn[i++] = BPF_LD_ABS(BPF_B, 0);
412 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
413 i++;
414 insn[i++] = BPF_MOV64_REG(R1, R6);
415 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
416 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
417 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
418 i++;
419 }
420 if (++k < 5)
421 goto loop;
422
423 for (; i < len - 1; i++)
424 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
425
426 insn[len - 1] = BPF_EXIT_INSN();
427
428 self->u.ptr.insns = insn;
429 self->u.ptr.len = len;
430
431 return 0;
432}
433
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700434static struct bpf_test tests[] = {
435 {
436 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700437 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700438 BPF_STMT(BPF_LD | BPF_IMM, 1),
439 BPF_STMT(BPF_MISC | BPF_TAX, 0),
440 BPF_STMT(BPF_LD | BPF_IMM, 2),
441 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
442 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
443 BPF_STMT(BPF_MISC | BPF_TAX, 0),
444 BPF_STMT(BPF_LD | BPF_LEN, 0),
445 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
446 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
447 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
448 BPF_STMT(BPF_RET | BPF_A, 0)
449 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200450 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700451 { 10, 20, 30, 40, 50 },
452 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
453 },
454 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700455 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700456 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700457 BPF_STMT(BPF_LDX | BPF_LEN, 0),
458 BPF_STMT(BPF_MISC | BPF_TXA, 0),
459 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
460 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
461 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200462 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700463 { 10, 20, 30, 40, 50 },
464 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
465 },
466 {
467 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700468 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700469 BPF_STMT(BPF_LD | BPF_IMM, 1),
470 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
471 BPF_STMT(BPF_LDX | BPF_IMM, 3),
472 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
473 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
474 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
475 BPF_STMT(BPF_RET | BPF_A, 0)
476 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200477 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700478 { },
479 { { 0, 0xfffffffd } }
480 },
481 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300482 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700483 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700484 BPF_STMT(BPF_LD | BPF_IMM, 8),
485 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
486 BPF_STMT(BPF_MISC | BPF_TAX, 0),
487 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
488 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
489 BPF_STMT(BPF_MISC | BPF_TAX, 0),
490 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
491 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300492 BPF_STMT(BPF_MISC | BPF_TAX, 0),
493 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
494 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
495 BPF_STMT(BPF_MISC | BPF_TAX, 0),
496 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
497 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700498 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
499 BPF_STMT(BPF_RET | BPF_A, 0)
500 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200501 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700502 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300503 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700504 },
505 {
506 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700507 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700508 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
509 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
510 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
511 BPF_STMT(BPF_MISC | BPF_TAX, 0),
512 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
513 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
514 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
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, 0x800000ff }, { 1, 0x800000ff } },
520 },
521 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700522 "LD_IMM_0",
523 .u.insns = {
524 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
525 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
526 BPF_STMT(BPF_RET | BPF_K, 0),
527 BPF_STMT(BPF_RET | BPF_K, 1),
528 },
529 CLASSIC,
530 { },
531 { { 1, 1 } },
532 },
533 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700534 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700535 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700536 BPF_STMT(BPF_LDX | BPF_LEN, 0),
537 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
538 BPF_STMT(BPF_RET | BPF_K, 1)
539 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200540 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700541 { },
542 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
543 },
544 {
545 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700546 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700547 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
548 BPF_STMT(BPF_RET | BPF_K, 1)
549 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200550 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700551 { },
552 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
553 },
554 {
555 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700556 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700557 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
558 BPF_STMT(BPF_MISC | BPF_TAX, 0),
559 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
560 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
561 BPF_STMT(BPF_RET | BPF_A, 0)
562 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200563 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700564 { 1, 2, 3 },
565 { { 1, 0 }, { 2, 3 } },
566 },
567 {
568 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700569 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700570 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
571 BPF_STMT(BPF_LDX | BPF_LEN, 0),
572 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
573 BPF_STMT(BPF_MISC | BPF_TAX, 0),
574 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
575 BPF_STMT(BPF_RET | BPF_A, 0)
576 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200577 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700578 { 1, 2, 3, 0xff },
579 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
580 },
581 {
582 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700583 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700584 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
585 BPF_STMT(BPF_MISC | BPF_TAX, 0),
586 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
587 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
588 BPF_STMT(BPF_RET | BPF_A, 0)
589 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200590 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700591 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
592 { { 15, 0 }, { 16, 3 } },
593 },
594 {
595 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700596 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700597 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
598 BPF_STMT(BPF_LDX | BPF_LEN, 0),
599 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
600 BPF_STMT(BPF_MISC | BPF_TAX, 0),
601 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
602 BPF_STMT(BPF_RET | BPF_A, 0)
603 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200604 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700605 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
606 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
607 },
608 {
609 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700610 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700611 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
612 SKF_AD_OFF + SKF_AD_PKTTYPE),
613 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
614 BPF_STMT(BPF_RET | BPF_K, 1),
615 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
616 SKF_AD_OFF + SKF_AD_PKTTYPE),
617 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
618 BPF_STMT(BPF_RET | BPF_K, 1),
619 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
620 SKF_AD_OFF + SKF_AD_PKTTYPE),
621 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
622 BPF_STMT(BPF_RET | BPF_K, 1),
623 BPF_STMT(BPF_RET | BPF_A, 0)
624 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200625 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700626 { },
627 { { 1, 3 }, { 10, 3 } },
628 },
629 {
630 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700631 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700632 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
633 SKF_AD_OFF + SKF_AD_MARK),
634 BPF_STMT(BPF_RET | BPF_A, 0)
635 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200636 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700637 { },
638 { { 1, SKB_MARK}, { 10, SKB_MARK} },
639 },
640 {
641 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700642 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700643 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
644 SKF_AD_OFF + SKF_AD_RXHASH),
645 BPF_STMT(BPF_RET | BPF_A, 0)
646 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200647 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700648 { },
649 { { 1, SKB_HASH}, { 10, SKB_HASH} },
650 },
651 {
652 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700653 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700654 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
655 SKF_AD_OFF + SKF_AD_QUEUE),
656 BPF_STMT(BPF_RET | BPF_A, 0)
657 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200658 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700659 { },
660 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
661 },
662 {
663 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700664 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700665 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
666 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
667 BPF_STMT(BPF_RET | BPF_K, 0),
668 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
669 SKF_AD_OFF + SKF_AD_PROTOCOL),
670 BPF_STMT(BPF_MISC | BPF_TAX, 0),
671 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
672 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
673 BPF_STMT(BPF_RET | BPF_K, 0),
674 BPF_STMT(BPF_MISC | BPF_TXA, 0),
675 BPF_STMT(BPF_RET | BPF_A, 0)
676 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200677 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700678 { 10, 20, 30 },
679 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
680 },
681 {
682 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700683 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_VLAN_TAG),
686 BPF_STMT(BPF_RET | BPF_A, 0)
687 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200688 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700689 { },
690 {
691 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
692 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
693 },
694 },
695 {
696 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700697 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700698 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
699 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
700 BPF_STMT(BPF_RET | BPF_A, 0)
701 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200702 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700703 { },
704 {
705 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
706 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
707 },
708 },
709 {
710 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700711 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700712 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
713 SKF_AD_OFF + SKF_AD_IFINDEX),
714 BPF_STMT(BPF_RET | BPF_A, 0)
715 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200716 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700717 { },
718 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
719 },
720 {
721 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700722 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700723 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
724 SKF_AD_OFF + SKF_AD_HATYPE),
725 BPF_STMT(BPF_RET | BPF_A, 0)
726 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200727 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700728 { },
729 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
730 },
731 {
732 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700733 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700734 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
735 SKF_AD_OFF + SKF_AD_CPU),
736 BPF_STMT(BPF_MISC | BPF_TAX, 0),
737 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
738 SKF_AD_OFF + SKF_AD_CPU),
739 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
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 { { 1, 0 }, { 10, 0 } },
745 },
746 {
747 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700748 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700749 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700750 BPF_STMT(BPF_MISC | BPF_TXA, 0),
751 BPF_STMT(BPF_LDX | BPF_IMM, 3),
752 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
753 SKF_AD_OFF + SKF_AD_NLATTR),
754 BPF_STMT(BPF_RET | BPF_A, 0)
755 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200756 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700757#ifdef __BIG_ENDIAN
758 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
759#else
760 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
761#endif
762 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700763 },
764 {
765 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700766 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700767 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700768 BPF_STMT(BPF_LDX | BPF_IMM, 3),
769 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
770 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700771 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700772 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
773 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700774 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700775 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
776 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700777 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700778 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
779 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700780 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700781 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
782 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700783 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700784 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
785 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700786 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700787 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
788 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700789 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700790 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
791 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
792 BPF_STMT(BPF_RET | BPF_A, 0)
793 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200794 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700795#ifdef __BIG_ENDIAN
796 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
797#else
798 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
799#endif
800 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700801 },
802 {
803 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700804 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700805 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
806 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
807 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
808 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
809 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
810 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
813 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
814 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
815 BPF_STMT(BPF_RET | BPF_A, 0)
816 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200817 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700818 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
819 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
820 * id 9737, seq 1, length 64
821 */
822 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
823 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
824 0x08, 0x00,
825 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
826 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
827 { { 30, 0 }, { 100, 42 } },
828 },
829 {
830 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700831 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700832 BPF_STMT(BPF_LD | BPF_IMM, 10),
833 BPF_STMT(BPF_LDX | BPF_IMM, 300),
834 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
835 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
836 BPF_STMT(BPF_RET | BPF_A, 0)
837 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200838 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700839 { },
840 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
841 },
842 {
843 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700844 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700845 BPF_STMT(BPF_LDX | BPF_LEN, 0),
846 BPF_STMT(BPF_LD | BPF_IMM, 2),
847 BPF_STMT(BPF_ALU | BPF_RSH, 1),
848 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
849 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
850 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
851 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
852 BPF_STMT(BPF_STX, 15), /* M3 = len */
853 BPF_STMT(BPF_LDX | BPF_MEM, 1),
854 BPF_STMT(BPF_LD | BPF_MEM, 2),
855 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
856 BPF_STMT(BPF_LDX | BPF_MEM, 15),
857 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
858 BPF_STMT(BPF_RET | BPF_A, 0)
859 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200860 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700861 { },
862 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
863 },
864 {
865 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700866 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700867 BPF_STMT(BPF_LDX | BPF_LEN, 0),
868 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
869 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
870 BPF_STMT(BPF_RET | BPF_K, 1),
871 BPF_STMT(BPF_RET | BPF_K, MAX_K)
872 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200873 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700874 { 3, 3, 3, 3, 3 },
875 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
876 },
877 {
878 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700879 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700880 BPF_STMT(BPF_LDX | BPF_LEN, 0),
881 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
882 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
883 BPF_STMT(BPF_RET | BPF_K, 1),
884 BPF_STMT(BPF_RET | BPF_K, MAX_K)
885 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200886 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700887 { 4, 4, 4, 3, 3 },
888 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
889 },
890 {
891 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700892 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700893 BPF_STMT(BPF_LDX | BPF_LEN, 0),
894 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
895 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
896 BPF_STMT(BPF_RET | BPF_K, 10),
897 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
898 BPF_STMT(BPF_RET | BPF_K, 20),
899 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
900 BPF_STMT(BPF_RET | BPF_K, 30),
901 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
902 BPF_STMT(BPF_RET | BPF_K, 40),
903 BPF_STMT(BPF_RET | BPF_K, MAX_K)
904 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200905 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700906 { 1, 2, 3, 4, 5 },
907 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
908 },
909 {
910 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700911 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700912 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
913 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
914 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
915 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
916 BPF_STMT(BPF_LDX | BPF_LEN, 0),
917 BPF_STMT(BPF_MISC | BPF_TXA, 0),
918 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
919 BPF_STMT(BPF_MISC | BPF_TAX, 0),
920 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
921 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
922 BPF_STMT(BPF_RET | BPF_K, 10),
923 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
924 BPF_STMT(BPF_RET | BPF_K, 20),
925 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
926 BPF_STMT(BPF_RET | BPF_K, 30),
927 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
928 BPF_STMT(BPF_RET | BPF_K, 30),
929 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
930 BPF_STMT(BPF_RET | BPF_K, 30),
931 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
932 BPF_STMT(BPF_RET | BPF_K, 30),
933 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
934 BPF_STMT(BPF_RET | BPF_K, 30),
935 BPF_STMT(BPF_RET | BPF_K, MAX_K)
936 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200937 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700938 { 0, 0xAA, 0x55, 1 },
939 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
940 },
941 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700942 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -0700943 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +0200944 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
945 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
946 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
947 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
948 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
949 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
950 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
951 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
952 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
953 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
954 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
955 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
956 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
957 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
958 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
959 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
960 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
961 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
962 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
963 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
964 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
965 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
966 BPF_STMT(BPF_RET | BPF_K, 0xffff),
967 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700968 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200969 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700970 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
971 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
972 * seq 1305692979:1305693027, ack 3650467037, win 65535,
973 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
974 */
975 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
976 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
977 0x08, 0x00,
978 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
979 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
980 0x0a, 0x01, 0x01, 0x95, /* ip src */
981 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
982 0xc2, 0x24,
983 0x00, 0x16 /* dst port */ },
984 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
985 },
986 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700987 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -0700988 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700989 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
990 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
991 * (len > 115 or len < 30000000000)' -d
992 */
Daniel Borkmannce25b682014-05-26 20:17:35 +0200993 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
994 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
995 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
996 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
997 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
998 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
999 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1000 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1001 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1002 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1003 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1004 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1005 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1006 BPF_STMT(BPF_ST, 1),
1007 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1008 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1009 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1010 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1011 BPF_STMT(BPF_LD | BPF_MEM, 1),
1012 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1013 BPF_STMT(BPF_ST, 5),
1014 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1015 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1016 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1017 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1018 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1019 BPF_STMT(BPF_LD | BPF_MEM, 5),
1020 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1021 BPF_STMT(BPF_LD | BPF_LEN, 0),
1022 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1023 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1024 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1025 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001026 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001027 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001028 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1029 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1030 0x08, 0x00,
1031 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1032 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1033 0x0a, 0x01, 0x01, 0x95, /* ip src */
1034 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1035 0xc2, 0x24,
1036 0x00, 0x16 /* dst port */ },
1037 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1038 },
1039 {
1040 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001041 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001042 /* check that unitialized X and A contain zeros */
1043 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1044 BPF_STMT(BPF_RET | BPF_A, 0)
1045 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001046 CLASSIC,
1047 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001048 { {1, 0}, {2, 0} },
1049 },
1050 {
1051 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001052 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001053 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1054 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1055 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1056 BPF_ALU64_REG(BPF_SUB, R1, R2),
1057 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1058 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1059 BPF_ALU64_REG(BPF_MOV, R0, R1),
1060 BPF_EXIT_INSN(),
1061 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001062 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001063 { },
1064 { { 0, 0xfffffffd } }
1065 },
1066 {
1067 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001068 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001069 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1070 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1071 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1072 BPF_ALU64_REG(BPF_MUL, R1, R2),
1073 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1074 BPF_EXIT_INSN(),
1075 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1076 BPF_EXIT_INSN(),
1077 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001078 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001079 { },
1080 { { 0, 1 } }
1081 },
1082 {
1083 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001084 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001085 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1086 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1087 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1088 BPF_ALU64_REG(BPF_MUL, R1, R2),
1089 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1090 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1091 BPF_EXIT_INSN(),
1092 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1093 BPF_EXIT_INSN(),
1094 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001095 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001096 { },
1097 { { 0, 1 } }
1098 },
1099 {
1100 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001101 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001102 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1103 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1104 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1105 BPF_ALU32_REG(BPF_MUL, R1, R2),
1106 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1107 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1108 BPF_EXIT_INSN(),
1109 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1110 BPF_EXIT_INSN(),
1111 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001112 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001113 { },
1114 { { 0, 1 } }
1115 },
1116 {
1117 /* Have to test all register combinations, since
1118 * JITing of different registers will produce
1119 * different asm code.
1120 */
1121 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001122 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001123 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1124 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1125 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1126 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1127 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1128 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1129 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1130 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1131 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1132 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1133 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1134 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1135 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1136 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1137 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1138 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1139 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1140 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1141 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1142 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1143 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1144 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1145 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1146 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1147 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1148 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1149 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1150 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1151 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1152 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1153 BPF_ALU64_REG(BPF_ADD, R0, R0),
1154 BPF_ALU64_REG(BPF_ADD, R0, R1),
1155 BPF_ALU64_REG(BPF_ADD, R0, R2),
1156 BPF_ALU64_REG(BPF_ADD, R0, R3),
1157 BPF_ALU64_REG(BPF_ADD, R0, R4),
1158 BPF_ALU64_REG(BPF_ADD, R0, R5),
1159 BPF_ALU64_REG(BPF_ADD, R0, R6),
1160 BPF_ALU64_REG(BPF_ADD, R0, R7),
1161 BPF_ALU64_REG(BPF_ADD, R0, R8),
1162 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1163 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1164 BPF_EXIT_INSN(),
1165 BPF_ALU64_REG(BPF_ADD, R1, R0),
1166 BPF_ALU64_REG(BPF_ADD, R1, R1),
1167 BPF_ALU64_REG(BPF_ADD, R1, R2),
1168 BPF_ALU64_REG(BPF_ADD, R1, R3),
1169 BPF_ALU64_REG(BPF_ADD, R1, R4),
1170 BPF_ALU64_REG(BPF_ADD, R1, R5),
1171 BPF_ALU64_REG(BPF_ADD, R1, R6),
1172 BPF_ALU64_REG(BPF_ADD, R1, R7),
1173 BPF_ALU64_REG(BPF_ADD, R1, R8),
1174 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1175 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1176 BPF_EXIT_INSN(),
1177 BPF_ALU64_REG(BPF_ADD, R2, R0),
1178 BPF_ALU64_REG(BPF_ADD, R2, R1),
1179 BPF_ALU64_REG(BPF_ADD, R2, R2),
1180 BPF_ALU64_REG(BPF_ADD, R2, R3),
1181 BPF_ALU64_REG(BPF_ADD, R2, R4),
1182 BPF_ALU64_REG(BPF_ADD, R2, R5),
1183 BPF_ALU64_REG(BPF_ADD, R2, R6),
1184 BPF_ALU64_REG(BPF_ADD, R2, R7),
1185 BPF_ALU64_REG(BPF_ADD, R2, R8),
1186 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1187 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1188 BPF_EXIT_INSN(),
1189 BPF_ALU64_REG(BPF_ADD, R3, R0),
1190 BPF_ALU64_REG(BPF_ADD, R3, R1),
1191 BPF_ALU64_REG(BPF_ADD, R3, R2),
1192 BPF_ALU64_REG(BPF_ADD, R3, R3),
1193 BPF_ALU64_REG(BPF_ADD, R3, R4),
1194 BPF_ALU64_REG(BPF_ADD, R3, R5),
1195 BPF_ALU64_REG(BPF_ADD, R3, R6),
1196 BPF_ALU64_REG(BPF_ADD, R3, R7),
1197 BPF_ALU64_REG(BPF_ADD, R3, R8),
1198 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1199 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1200 BPF_EXIT_INSN(),
1201 BPF_ALU64_REG(BPF_ADD, R4, R0),
1202 BPF_ALU64_REG(BPF_ADD, R4, R1),
1203 BPF_ALU64_REG(BPF_ADD, R4, R2),
1204 BPF_ALU64_REG(BPF_ADD, R4, R3),
1205 BPF_ALU64_REG(BPF_ADD, R4, R4),
1206 BPF_ALU64_REG(BPF_ADD, R4, R5),
1207 BPF_ALU64_REG(BPF_ADD, R4, R6),
1208 BPF_ALU64_REG(BPF_ADD, R4, R7),
1209 BPF_ALU64_REG(BPF_ADD, R4, R8),
1210 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1211 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1212 BPF_EXIT_INSN(),
1213 BPF_ALU64_REG(BPF_ADD, R5, R0),
1214 BPF_ALU64_REG(BPF_ADD, R5, R1),
1215 BPF_ALU64_REG(BPF_ADD, R5, R2),
1216 BPF_ALU64_REG(BPF_ADD, R5, R3),
1217 BPF_ALU64_REG(BPF_ADD, R5, R4),
1218 BPF_ALU64_REG(BPF_ADD, R5, R5),
1219 BPF_ALU64_REG(BPF_ADD, R5, R6),
1220 BPF_ALU64_REG(BPF_ADD, R5, R7),
1221 BPF_ALU64_REG(BPF_ADD, R5, R8),
1222 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1223 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1224 BPF_EXIT_INSN(),
1225 BPF_ALU64_REG(BPF_ADD, R6, R0),
1226 BPF_ALU64_REG(BPF_ADD, R6, R1),
1227 BPF_ALU64_REG(BPF_ADD, R6, R2),
1228 BPF_ALU64_REG(BPF_ADD, R6, R3),
1229 BPF_ALU64_REG(BPF_ADD, R6, R4),
1230 BPF_ALU64_REG(BPF_ADD, R6, R5),
1231 BPF_ALU64_REG(BPF_ADD, R6, R6),
1232 BPF_ALU64_REG(BPF_ADD, R6, R7),
1233 BPF_ALU64_REG(BPF_ADD, R6, R8),
1234 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1235 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1236 BPF_EXIT_INSN(),
1237 BPF_ALU64_REG(BPF_ADD, R7, R0),
1238 BPF_ALU64_REG(BPF_ADD, R7, R1),
1239 BPF_ALU64_REG(BPF_ADD, R7, R2),
1240 BPF_ALU64_REG(BPF_ADD, R7, R3),
1241 BPF_ALU64_REG(BPF_ADD, R7, R4),
1242 BPF_ALU64_REG(BPF_ADD, R7, R5),
1243 BPF_ALU64_REG(BPF_ADD, R7, R6),
1244 BPF_ALU64_REG(BPF_ADD, R7, R7),
1245 BPF_ALU64_REG(BPF_ADD, R7, R8),
1246 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1247 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1248 BPF_EXIT_INSN(),
1249 BPF_ALU64_REG(BPF_ADD, R8, R0),
1250 BPF_ALU64_REG(BPF_ADD, R8, R1),
1251 BPF_ALU64_REG(BPF_ADD, R8, R2),
1252 BPF_ALU64_REG(BPF_ADD, R8, R3),
1253 BPF_ALU64_REG(BPF_ADD, R8, R4),
1254 BPF_ALU64_REG(BPF_ADD, R8, R5),
1255 BPF_ALU64_REG(BPF_ADD, R8, R6),
1256 BPF_ALU64_REG(BPF_ADD, R8, R7),
1257 BPF_ALU64_REG(BPF_ADD, R8, R8),
1258 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1259 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1260 BPF_EXIT_INSN(),
1261 BPF_ALU64_REG(BPF_ADD, R9, R0),
1262 BPF_ALU64_REG(BPF_ADD, R9, R1),
1263 BPF_ALU64_REG(BPF_ADD, R9, R2),
1264 BPF_ALU64_REG(BPF_ADD, R9, R3),
1265 BPF_ALU64_REG(BPF_ADD, R9, R4),
1266 BPF_ALU64_REG(BPF_ADD, R9, R5),
1267 BPF_ALU64_REG(BPF_ADD, R9, R6),
1268 BPF_ALU64_REG(BPF_ADD, R9, R7),
1269 BPF_ALU64_REG(BPF_ADD, R9, R8),
1270 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1271 BPF_ALU64_REG(BPF_MOV, R0, R9),
1272 BPF_EXIT_INSN(),
1273 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001274 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001275 { },
1276 { { 0, 2957380 } }
1277 },
1278 {
1279 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001280 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001281 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1282 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1283 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1284 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1285 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1286 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1287 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1288 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1289 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1290 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1291 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1292 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1293 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1294 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1295 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1296 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1297 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1298 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1299 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1300 BPF_ALU32_REG(BPF_ADD, R0, R1),
1301 BPF_ALU32_REG(BPF_ADD, R0, R2),
1302 BPF_ALU32_REG(BPF_ADD, R0, R3),
1303 BPF_ALU32_REG(BPF_ADD, R0, R4),
1304 BPF_ALU32_REG(BPF_ADD, R0, R5),
1305 BPF_ALU32_REG(BPF_ADD, R0, R6),
1306 BPF_ALU32_REG(BPF_ADD, R0, R7),
1307 BPF_ALU32_REG(BPF_ADD, R0, R8),
1308 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1309 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1310 BPF_EXIT_INSN(),
1311 BPF_ALU32_REG(BPF_ADD, R1, R0),
1312 BPF_ALU32_REG(BPF_ADD, R1, R1),
1313 BPF_ALU32_REG(BPF_ADD, R1, R2),
1314 BPF_ALU32_REG(BPF_ADD, R1, R3),
1315 BPF_ALU32_REG(BPF_ADD, R1, R4),
1316 BPF_ALU32_REG(BPF_ADD, R1, R5),
1317 BPF_ALU32_REG(BPF_ADD, R1, R6),
1318 BPF_ALU32_REG(BPF_ADD, R1, R7),
1319 BPF_ALU32_REG(BPF_ADD, R1, R8),
1320 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1321 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1322 BPF_EXIT_INSN(),
1323 BPF_ALU32_REG(BPF_ADD, R2, R0),
1324 BPF_ALU32_REG(BPF_ADD, R2, R1),
1325 BPF_ALU32_REG(BPF_ADD, R2, R2),
1326 BPF_ALU32_REG(BPF_ADD, R2, R3),
1327 BPF_ALU32_REG(BPF_ADD, R2, R4),
1328 BPF_ALU32_REG(BPF_ADD, R2, R5),
1329 BPF_ALU32_REG(BPF_ADD, R2, R6),
1330 BPF_ALU32_REG(BPF_ADD, R2, R7),
1331 BPF_ALU32_REG(BPF_ADD, R2, R8),
1332 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1333 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1334 BPF_EXIT_INSN(),
1335 BPF_ALU32_REG(BPF_ADD, R3, R0),
1336 BPF_ALU32_REG(BPF_ADD, R3, R1),
1337 BPF_ALU32_REG(BPF_ADD, R3, R2),
1338 BPF_ALU32_REG(BPF_ADD, R3, R3),
1339 BPF_ALU32_REG(BPF_ADD, R3, R4),
1340 BPF_ALU32_REG(BPF_ADD, R3, R5),
1341 BPF_ALU32_REG(BPF_ADD, R3, R6),
1342 BPF_ALU32_REG(BPF_ADD, R3, R7),
1343 BPF_ALU32_REG(BPF_ADD, R3, R8),
1344 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1345 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1346 BPF_EXIT_INSN(),
1347 BPF_ALU32_REG(BPF_ADD, R4, R0),
1348 BPF_ALU32_REG(BPF_ADD, R4, R1),
1349 BPF_ALU32_REG(BPF_ADD, R4, R2),
1350 BPF_ALU32_REG(BPF_ADD, R4, R3),
1351 BPF_ALU32_REG(BPF_ADD, R4, R4),
1352 BPF_ALU32_REG(BPF_ADD, R4, R5),
1353 BPF_ALU32_REG(BPF_ADD, R4, R6),
1354 BPF_ALU32_REG(BPF_ADD, R4, R7),
1355 BPF_ALU32_REG(BPF_ADD, R4, R8),
1356 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1357 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1358 BPF_EXIT_INSN(),
1359 BPF_ALU32_REG(BPF_ADD, R5, R0),
1360 BPF_ALU32_REG(BPF_ADD, R5, R1),
1361 BPF_ALU32_REG(BPF_ADD, R5, R2),
1362 BPF_ALU32_REG(BPF_ADD, R5, R3),
1363 BPF_ALU32_REG(BPF_ADD, R5, R4),
1364 BPF_ALU32_REG(BPF_ADD, R5, R5),
1365 BPF_ALU32_REG(BPF_ADD, R5, R6),
1366 BPF_ALU32_REG(BPF_ADD, R5, R7),
1367 BPF_ALU32_REG(BPF_ADD, R5, R8),
1368 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1369 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1370 BPF_EXIT_INSN(),
1371 BPF_ALU32_REG(BPF_ADD, R6, R0),
1372 BPF_ALU32_REG(BPF_ADD, R6, R1),
1373 BPF_ALU32_REG(BPF_ADD, R6, R2),
1374 BPF_ALU32_REG(BPF_ADD, R6, R3),
1375 BPF_ALU32_REG(BPF_ADD, R6, R4),
1376 BPF_ALU32_REG(BPF_ADD, R6, R5),
1377 BPF_ALU32_REG(BPF_ADD, R6, R6),
1378 BPF_ALU32_REG(BPF_ADD, R6, R7),
1379 BPF_ALU32_REG(BPF_ADD, R6, R8),
1380 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1381 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1382 BPF_EXIT_INSN(),
1383 BPF_ALU32_REG(BPF_ADD, R7, R0),
1384 BPF_ALU32_REG(BPF_ADD, R7, R1),
1385 BPF_ALU32_REG(BPF_ADD, R7, R2),
1386 BPF_ALU32_REG(BPF_ADD, R7, R3),
1387 BPF_ALU32_REG(BPF_ADD, R7, R4),
1388 BPF_ALU32_REG(BPF_ADD, R7, R5),
1389 BPF_ALU32_REG(BPF_ADD, R7, R6),
1390 BPF_ALU32_REG(BPF_ADD, R7, R7),
1391 BPF_ALU32_REG(BPF_ADD, R7, R8),
1392 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1393 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1394 BPF_EXIT_INSN(),
1395 BPF_ALU32_REG(BPF_ADD, R8, R0),
1396 BPF_ALU32_REG(BPF_ADD, R8, R1),
1397 BPF_ALU32_REG(BPF_ADD, R8, R2),
1398 BPF_ALU32_REG(BPF_ADD, R8, R3),
1399 BPF_ALU32_REG(BPF_ADD, R8, R4),
1400 BPF_ALU32_REG(BPF_ADD, R8, R5),
1401 BPF_ALU32_REG(BPF_ADD, R8, R6),
1402 BPF_ALU32_REG(BPF_ADD, R8, R7),
1403 BPF_ALU32_REG(BPF_ADD, R8, R8),
1404 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1405 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1406 BPF_EXIT_INSN(),
1407 BPF_ALU32_REG(BPF_ADD, R9, R0),
1408 BPF_ALU32_REG(BPF_ADD, R9, R1),
1409 BPF_ALU32_REG(BPF_ADD, R9, R2),
1410 BPF_ALU32_REG(BPF_ADD, R9, R3),
1411 BPF_ALU32_REG(BPF_ADD, R9, R4),
1412 BPF_ALU32_REG(BPF_ADD, R9, R5),
1413 BPF_ALU32_REG(BPF_ADD, R9, R6),
1414 BPF_ALU32_REG(BPF_ADD, R9, R7),
1415 BPF_ALU32_REG(BPF_ADD, R9, R8),
1416 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1417 BPF_ALU32_REG(BPF_MOV, R0, R9),
1418 BPF_EXIT_INSN(),
1419 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001420 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001421 { },
1422 { { 0, 2957380 } }
1423 },
1424 { /* Mainly checking JIT here. */
1425 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001426 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001427 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1428 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1429 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1430 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1431 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1432 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1433 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1434 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1435 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1436 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1437 BPF_ALU64_REG(BPF_SUB, R0, R0),
1438 BPF_ALU64_REG(BPF_SUB, R0, R1),
1439 BPF_ALU64_REG(BPF_SUB, R0, R2),
1440 BPF_ALU64_REG(BPF_SUB, R0, R3),
1441 BPF_ALU64_REG(BPF_SUB, R0, R4),
1442 BPF_ALU64_REG(BPF_SUB, R0, R5),
1443 BPF_ALU64_REG(BPF_SUB, R0, R6),
1444 BPF_ALU64_REG(BPF_SUB, R0, R7),
1445 BPF_ALU64_REG(BPF_SUB, R0, R8),
1446 BPF_ALU64_REG(BPF_SUB, R0, R9),
1447 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1448 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1449 BPF_EXIT_INSN(),
1450 BPF_ALU64_REG(BPF_SUB, R1, R0),
1451 BPF_ALU64_REG(BPF_SUB, R1, R2),
1452 BPF_ALU64_REG(BPF_SUB, R1, R3),
1453 BPF_ALU64_REG(BPF_SUB, R1, R4),
1454 BPF_ALU64_REG(BPF_SUB, R1, R5),
1455 BPF_ALU64_REG(BPF_SUB, R1, R6),
1456 BPF_ALU64_REG(BPF_SUB, R1, R7),
1457 BPF_ALU64_REG(BPF_SUB, R1, R8),
1458 BPF_ALU64_REG(BPF_SUB, R1, R9),
1459 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1460 BPF_ALU64_REG(BPF_SUB, R2, R0),
1461 BPF_ALU64_REG(BPF_SUB, R2, R1),
1462 BPF_ALU64_REG(BPF_SUB, R2, R3),
1463 BPF_ALU64_REG(BPF_SUB, R2, R4),
1464 BPF_ALU64_REG(BPF_SUB, R2, R5),
1465 BPF_ALU64_REG(BPF_SUB, R2, R6),
1466 BPF_ALU64_REG(BPF_SUB, R2, R7),
1467 BPF_ALU64_REG(BPF_SUB, R2, R8),
1468 BPF_ALU64_REG(BPF_SUB, R2, R9),
1469 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1470 BPF_ALU64_REG(BPF_SUB, R3, R0),
1471 BPF_ALU64_REG(BPF_SUB, R3, R1),
1472 BPF_ALU64_REG(BPF_SUB, R3, R2),
1473 BPF_ALU64_REG(BPF_SUB, R3, R4),
1474 BPF_ALU64_REG(BPF_SUB, R3, R5),
1475 BPF_ALU64_REG(BPF_SUB, R3, R6),
1476 BPF_ALU64_REG(BPF_SUB, R3, R7),
1477 BPF_ALU64_REG(BPF_SUB, R3, R8),
1478 BPF_ALU64_REG(BPF_SUB, R3, R9),
1479 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1480 BPF_ALU64_REG(BPF_SUB, R4, R0),
1481 BPF_ALU64_REG(BPF_SUB, R4, R1),
1482 BPF_ALU64_REG(BPF_SUB, R4, R2),
1483 BPF_ALU64_REG(BPF_SUB, R4, R3),
1484 BPF_ALU64_REG(BPF_SUB, R4, R5),
1485 BPF_ALU64_REG(BPF_SUB, R4, R6),
1486 BPF_ALU64_REG(BPF_SUB, R4, R7),
1487 BPF_ALU64_REG(BPF_SUB, R4, R8),
1488 BPF_ALU64_REG(BPF_SUB, R4, R9),
1489 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1490 BPF_ALU64_REG(BPF_SUB, R5, R0),
1491 BPF_ALU64_REG(BPF_SUB, R5, R1),
1492 BPF_ALU64_REG(BPF_SUB, R5, R2),
1493 BPF_ALU64_REG(BPF_SUB, R5, R3),
1494 BPF_ALU64_REG(BPF_SUB, R5, R4),
1495 BPF_ALU64_REG(BPF_SUB, R5, R6),
1496 BPF_ALU64_REG(BPF_SUB, R5, R7),
1497 BPF_ALU64_REG(BPF_SUB, R5, R8),
1498 BPF_ALU64_REG(BPF_SUB, R5, R9),
1499 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1500 BPF_ALU64_REG(BPF_SUB, R6, R0),
1501 BPF_ALU64_REG(BPF_SUB, R6, R1),
1502 BPF_ALU64_REG(BPF_SUB, R6, R2),
1503 BPF_ALU64_REG(BPF_SUB, R6, R3),
1504 BPF_ALU64_REG(BPF_SUB, R6, R4),
1505 BPF_ALU64_REG(BPF_SUB, R6, R5),
1506 BPF_ALU64_REG(BPF_SUB, R6, R7),
1507 BPF_ALU64_REG(BPF_SUB, R6, R8),
1508 BPF_ALU64_REG(BPF_SUB, R6, R9),
1509 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1510 BPF_ALU64_REG(BPF_SUB, R7, R0),
1511 BPF_ALU64_REG(BPF_SUB, R7, R1),
1512 BPF_ALU64_REG(BPF_SUB, R7, R2),
1513 BPF_ALU64_REG(BPF_SUB, R7, R3),
1514 BPF_ALU64_REG(BPF_SUB, R7, R4),
1515 BPF_ALU64_REG(BPF_SUB, R7, R5),
1516 BPF_ALU64_REG(BPF_SUB, R7, R6),
1517 BPF_ALU64_REG(BPF_SUB, R7, R8),
1518 BPF_ALU64_REG(BPF_SUB, R7, R9),
1519 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1520 BPF_ALU64_REG(BPF_SUB, R8, R0),
1521 BPF_ALU64_REG(BPF_SUB, R8, R1),
1522 BPF_ALU64_REG(BPF_SUB, R8, R2),
1523 BPF_ALU64_REG(BPF_SUB, R8, R3),
1524 BPF_ALU64_REG(BPF_SUB, R8, R4),
1525 BPF_ALU64_REG(BPF_SUB, R8, R5),
1526 BPF_ALU64_REG(BPF_SUB, R8, R6),
1527 BPF_ALU64_REG(BPF_SUB, R8, R7),
1528 BPF_ALU64_REG(BPF_SUB, R8, R9),
1529 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1530 BPF_ALU64_REG(BPF_SUB, R9, R0),
1531 BPF_ALU64_REG(BPF_SUB, R9, R1),
1532 BPF_ALU64_REG(BPF_SUB, R9, R2),
1533 BPF_ALU64_REG(BPF_SUB, R9, R3),
1534 BPF_ALU64_REG(BPF_SUB, R9, R4),
1535 BPF_ALU64_REG(BPF_SUB, R9, R5),
1536 BPF_ALU64_REG(BPF_SUB, R9, R6),
1537 BPF_ALU64_REG(BPF_SUB, R9, R7),
1538 BPF_ALU64_REG(BPF_SUB, R9, R8),
1539 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1540 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1541 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1542 BPF_ALU64_REG(BPF_SUB, R0, R1),
1543 BPF_ALU64_REG(BPF_SUB, R0, R2),
1544 BPF_ALU64_REG(BPF_SUB, R0, R3),
1545 BPF_ALU64_REG(BPF_SUB, R0, R4),
1546 BPF_ALU64_REG(BPF_SUB, R0, R5),
1547 BPF_ALU64_REG(BPF_SUB, R0, R6),
1548 BPF_ALU64_REG(BPF_SUB, R0, R7),
1549 BPF_ALU64_REG(BPF_SUB, R0, R8),
1550 BPF_ALU64_REG(BPF_SUB, R0, R9),
1551 BPF_EXIT_INSN(),
1552 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001553 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001554 { },
1555 { { 0, 11 } }
1556 },
1557 { /* Mainly checking JIT here. */
1558 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001559 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001560 BPF_ALU64_REG(BPF_SUB, R0, R0),
1561 BPF_ALU64_REG(BPF_XOR, R1, R1),
1562 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1563 BPF_EXIT_INSN(),
1564 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1565 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1566 BPF_ALU64_REG(BPF_SUB, R1, R1),
1567 BPF_ALU64_REG(BPF_XOR, R2, R2),
1568 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1569 BPF_EXIT_INSN(),
1570 BPF_ALU64_REG(BPF_SUB, R2, R2),
1571 BPF_ALU64_REG(BPF_XOR, R3, R3),
1572 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1573 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1574 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1575 BPF_EXIT_INSN(),
1576 BPF_ALU64_REG(BPF_SUB, R3, R3),
1577 BPF_ALU64_REG(BPF_XOR, R4, R4),
1578 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1579 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1580 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1581 BPF_EXIT_INSN(),
1582 BPF_ALU64_REG(BPF_SUB, R4, R4),
1583 BPF_ALU64_REG(BPF_XOR, R5, R5),
1584 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1585 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1586 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1587 BPF_EXIT_INSN(),
1588 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1589 BPF_ALU64_REG(BPF_SUB, R5, R5),
1590 BPF_ALU64_REG(BPF_XOR, R6, R6),
1591 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1592 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1593 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1594 BPF_EXIT_INSN(),
1595 BPF_ALU64_REG(BPF_SUB, R6, R6),
1596 BPF_ALU64_REG(BPF_XOR, R7, R7),
1597 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1598 BPF_EXIT_INSN(),
1599 BPF_ALU64_REG(BPF_SUB, R7, R7),
1600 BPF_ALU64_REG(BPF_XOR, R8, R8),
1601 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1602 BPF_EXIT_INSN(),
1603 BPF_ALU64_REG(BPF_SUB, R8, R8),
1604 BPF_ALU64_REG(BPF_XOR, R9, R9),
1605 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1606 BPF_EXIT_INSN(),
1607 BPF_ALU64_REG(BPF_SUB, R9, R9),
1608 BPF_ALU64_REG(BPF_XOR, R0, R0),
1609 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1610 BPF_EXIT_INSN(),
1611 BPF_ALU64_REG(BPF_SUB, R1, R1),
1612 BPF_ALU64_REG(BPF_XOR, R0, R0),
1613 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1614 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1615 BPF_EXIT_INSN(),
1616 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1617 BPF_EXIT_INSN(),
1618 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001619 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001620 { },
1621 { { 0, 1 } }
1622 },
1623 { /* Mainly checking JIT here. */
1624 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001625 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001626 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1627 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1628 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1629 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1630 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1631 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1632 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1633 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1634 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1635 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1636 BPF_ALU64_REG(BPF_MUL, R0, R0),
1637 BPF_ALU64_REG(BPF_MUL, R0, R1),
1638 BPF_ALU64_REG(BPF_MUL, R0, R2),
1639 BPF_ALU64_REG(BPF_MUL, R0, R3),
1640 BPF_ALU64_REG(BPF_MUL, R0, R4),
1641 BPF_ALU64_REG(BPF_MUL, R0, R5),
1642 BPF_ALU64_REG(BPF_MUL, R0, R6),
1643 BPF_ALU64_REG(BPF_MUL, R0, R7),
1644 BPF_ALU64_REG(BPF_MUL, R0, R8),
1645 BPF_ALU64_REG(BPF_MUL, R0, R9),
1646 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1647 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1648 BPF_EXIT_INSN(),
1649 BPF_ALU64_REG(BPF_MUL, R1, R0),
1650 BPF_ALU64_REG(BPF_MUL, R1, R2),
1651 BPF_ALU64_REG(BPF_MUL, R1, R3),
1652 BPF_ALU64_REG(BPF_MUL, R1, R4),
1653 BPF_ALU64_REG(BPF_MUL, R1, R5),
1654 BPF_ALU64_REG(BPF_MUL, R1, R6),
1655 BPF_ALU64_REG(BPF_MUL, R1, R7),
1656 BPF_ALU64_REG(BPF_MUL, R1, R8),
1657 BPF_ALU64_REG(BPF_MUL, R1, R9),
1658 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1659 BPF_ALU64_REG(BPF_MOV, R2, R1),
1660 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1661 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1662 BPF_EXIT_INSN(),
1663 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1664 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1665 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_REG(BPF_MUL, R2, R0),
1668 BPF_ALU64_REG(BPF_MUL, R2, R1),
1669 BPF_ALU64_REG(BPF_MUL, R2, R3),
1670 BPF_ALU64_REG(BPF_MUL, R2, R4),
1671 BPF_ALU64_REG(BPF_MUL, R2, R5),
1672 BPF_ALU64_REG(BPF_MUL, R2, R6),
1673 BPF_ALU64_REG(BPF_MUL, R2, R7),
1674 BPF_ALU64_REG(BPF_MUL, R2, R8),
1675 BPF_ALU64_REG(BPF_MUL, R2, R9),
1676 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1677 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1678 BPF_ALU64_REG(BPF_MOV, R0, R2),
1679 BPF_EXIT_INSN(),
1680 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001681 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001682 { },
1683 { { 0, 0x35d97ef2 } }
1684 },
1685 {
1686 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001687 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001688 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1689 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1690 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1691 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1692 BPF_ALU64_REG(BPF_DIV, R0, R2),
1693 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1694 BPF_EXIT_INSN(),
1695 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1696 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1697 BPF_EXIT_INSN(),
1698 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1699 BPF_EXIT_INSN(),
1700 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001701 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001702 { },
1703 { { 0, -1 } }
1704 },
1705 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001706 "INT: shifts by register",
1707 .u.insns_int = {
1708 BPF_MOV64_IMM(R0, -1234),
1709 BPF_MOV64_IMM(R1, 1),
1710 BPF_ALU32_REG(BPF_RSH, R0, R1),
1711 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1712 BPF_EXIT_INSN(),
1713 BPF_MOV64_IMM(R2, 1),
1714 BPF_ALU64_REG(BPF_LSH, R0, R2),
1715 BPF_MOV32_IMM(R4, -1234),
1716 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1717 BPF_EXIT_INSN(),
1718 BPF_ALU64_IMM(BPF_AND, R4, 63),
1719 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1720 BPF_MOV64_IMM(R3, 47),
1721 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1722 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1723 BPF_EXIT_INSN(),
1724 BPF_MOV64_IMM(R2, 1),
1725 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1726 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1727 BPF_EXIT_INSN(),
1728 BPF_MOV64_IMM(R4, 4),
1729 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1730 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1731 BPF_EXIT_INSN(),
1732 BPF_MOV64_IMM(R4, 5),
1733 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1734 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1735 BPF_EXIT_INSN(),
1736 BPF_MOV64_IMM(R0, -1),
1737 BPF_EXIT_INSN(),
1738 },
1739 INTERNAL,
1740 { },
1741 { { 0, -1 } }
1742 },
1743 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001744 "INT: DIV + ABS",
Andrew Mortonece80492014-05-22 10:16:46 -07001745 .u.insns_int = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001746 BPF_ALU64_REG(BPF_MOV, R6, R1),
1747 BPF_LD_ABS(BPF_B, 3),
1748 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1749 BPF_ALU32_REG(BPF_DIV, R0, R2),
1750 BPF_ALU64_REG(BPF_MOV, R8, R0),
1751 BPF_LD_ABS(BPF_B, 4),
1752 BPF_ALU64_REG(BPF_ADD, R8, R0),
1753 BPF_LD_IND(BPF_B, R8, -70),
1754 BPF_EXIT_INSN(),
1755 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001756 INTERNAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001757 { 10, 20, 30, 40, 50 },
1758 { { 4, 0 }, { 5, 10 } }
1759 },
1760 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001761 "INT: DIV by zero",
Andrew Mortonece80492014-05-22 10:16:46 -07001762 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001763 BPF_ALU64_REG(BPF_MOV, R6, R1),
1764 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1765 BPF_LD_ABS(BPF_B, 3),
1766 BPF_ALU32_REG(BPF_DIV, R0, R7),
1767 BPF_EXIT_INSN(),
1768 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001769 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001770 { 10, 20, 30, 40, 50 },
1771 { { 3, 0 }, { 4, 0 } }
1772 },
1773 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001774 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07001775 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001776 BPF_STMT(BPF_LD | BPF_IMM, 1),
1777 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001778 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001779 { },
1780 { }
1781 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001782 {
1783 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07001784 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001785 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1786 BPF_STMT(BPF_RET | BPF_K, 0)
1787 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001788 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001789 { },
1790 { }
1791 },
1792 {
1793 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07001794 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001795 /* seccomp insn, rejected in socket filter */
1796 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1797 BPF_STMT(BPF_RET | BPF_K, 0)
1798 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001799 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001800 { },
1801 { }
1802 },
1803 {
1804 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07001805 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001806 BPF_STMT(BPF_STX, 16),
1807 BPF_STMT(BPF_RET | BPF_K, 0)
1808 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001809 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001810 { },
1811 { }
1812 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001813 {
1814 "JUMPS + HOLES",
1815 .u.insns = {
1816 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1817 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1818 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1819 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1820 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1821 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1822 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1823 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1824 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1825 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1826 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1827 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1828 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1829 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1830 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1831 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1832 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1833 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1834 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1835 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1836 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1837 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1838 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1839 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1840 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1841 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1842 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1843 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1844 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1845 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1846 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1847 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1848 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1849 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1850 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1851 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1852 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1853 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1854 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1855 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1856 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1857 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1858 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1859 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1860 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1861 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1862 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1863 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1864 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1865 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1866 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1867 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1868 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1869 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1870 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1871 BPF_STMT(BPF_RET | BPF_A, 0),
1872 BPF_STMT(BPF_RET | BPF_A, 0),
1873 },
1874 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02001875 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1876 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1877 0x08, 0x00,
1878 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1879 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1880 0xc0, 0xa8, 0x33, 0x01,
1881 0xc0, 0xa8, 0x33, 0x02,
1882 0xbb, 0xb6,
1883 0xa9, 0xfa,
1884 0x00, 0x14, 0x00, 0x00,
1885 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1886 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1887 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1888 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1889 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1890 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1891 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1892 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001893 { { 88, 0x001b } }
1894 },
1895 {
1896 "check: RET X",
1897 .u.insns = {
1898 BPF_STMT(BPF_RET | BPF_X, 0),
1899 },
1900 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1901 { },
1902 { },
1903 },
1904 {
1905 "check: LDX + RET X",
1906 .u.insns = {
1907 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1908 BPF_STMT(BPF_RET | BPF_X, 0),
1909 },
1910 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1911 { },
1912 { },
1913 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02001914 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02001915 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02001916 .u.insns = {
1917 BPF_STMT(BPF_LDX | BPF_IMM, 100),
1918 BPF_STMT(BPF_STX, 0),
1919 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1920 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1921 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1922 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1923 BPF_STMT(BPF_STX, 1),
1924 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1925 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1926 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1927 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1928 BPF_STMT(BPF_STX, 2),
1929 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1930 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1931 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1932 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1933 BPF_STMT(BPF_STX, 3),
1934 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1935 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1936 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1937 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1938 BPF_STMT(BPF_STX, 4),
1939 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1940 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1941 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1942 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1943 BPF_STMT(BPF_STX, 5),
1944 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1945 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1946 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1947 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1948 BPF_STMT(BPF_STX, 6),
1949 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1950 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1951 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1952 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1953 BPF_STMT(BPF_STX, 7),
1954 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1955 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1956 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1957 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1958 BPF_STMT(BPF_STX, 8),
1959 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1960 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1961 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1962 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1963 BPF_STMT(BPF_STX, 9),
1964 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1965 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1966 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1967 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1968 BPF_STMT(BPF_STX, 10),
1969 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1970 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1971 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1972 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1973 BPF_STMT(BPF_STX, 11),
1974 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1975 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1976 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1977 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1978 BPF_STMT(BPF_STX, 12),
1979 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1980 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1981 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1982 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1983 BPF_STMT(BPF_STX, 13),
1984 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1985 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1986 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1987 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1988 BPF_STMT(BPF_STX, 14),
1989 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1990 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1991 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1992 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1993 BPF_STMT(BPF_STX, 15),
1994 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1995 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1996 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1997 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1998 BPF_STMT(BPF_RET | BPF_A, 0),
1999 },
2000 CLASSIC | FLAG_NO_DATA,
2001 { },
2002 { { 0, 116 } },
2003 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002004 { /* Mainly checking JIT here. */
2005 "M[]: full STX + full LDX",
2006 .u.insns = {
2007 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2008 BPF_STMT(BPF_STX, 0),
2009 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2010 BPF_STMT(BPF_STX, 1),
2011 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2012 BPF_STMT(BPF_STX, 2),
2013 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2014 BPF_STMT(BPF_STX, 3),
2015 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2016 BPF_STMT(BPF_STX, 4),
2017 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2018 BPF_STMT(BPF_STX, 5),
2019 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2020 BPF_STMT(BPF_STX, 6),
2021 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2022 BPF_STMT(BPF_STX, 7),
2023 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2024 BPF_STMT(BPF_STX, 8),
2025 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2026 BPF_STMT(BPF_STX, 9),
2027 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2028 BPF_STMT(BPF_STX, 10),
2029 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2030 BPF_STMT(BPF_STX, 11),
2031 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2032 BPF_STMT(BPF_STX, 12),
2033 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2034 BPF_STMT(BPF_STX, 13),
2035 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2036 BPF_STMT(BPF_STX, 14),
2037 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2038 BPF_STMT(BPF_STX, 15),
2039 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2040 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2041 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2042 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2043 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2044 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2045 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2046 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2047 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2048 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2049 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2050 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2051 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2052 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2053 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2054 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2055 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2056 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2057 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2058 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2059 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2060 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2061 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2062 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2063 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2064 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2065 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2066 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2067 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2068 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2069 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2070 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2071 BPF_STMT(BPF_RET | BPF_A, 0),
2072 },
2073 CLASSIC | FLAG_NO_DATA,
2074 { },
2075 { { 0, 0x2a5a5e5 } },
2076 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002077 {
2078 "check: SKF_AD_MAX",
2079 .u.insns = {
2080 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2081 SKF_AD_OFF + SKF_AD_MAX),
2082 BPF_STMT(BPF_RET | BPF_A, 0),
2083 },
2084 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2085 { },
2086 { },
2087 },
2088 { /* Passes checker but fails during runtime. */
2089 "LD [SKF_AD_OFF-1]",
2090 .u.insns = {
2091 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2092 SKF_AD_OFF - 1),
2093 BPF_STMT(BPF_RET | BPF_K, 1),
2094 },
2095 CLASSIC,
2096 { },
2097 { { 1, 0 } },
2098 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002099 {
2100 "load 64-bit immediate",
2101 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002102 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002103 BPF_MOV64_REG(R2, R1),
2104 BPF_MOV64_REG(R3, R2),
2105 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2106 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2107 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2108 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2109 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2110 BPF_EXIT_INSN(),
2111 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2112 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002113 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2114 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002115 BPF_EXIT_INSN(),
2116 },
2117 INTERNAL,
2118 { },
2119 { { 0, 1 } }
2120 },
Alexei Starovoitove21ab362014-10-28 15:11:43 -07002121 {
2122 "nmap reduced",
2123 .u.insns_int = {
2124 BPF_MOV64_REG(R6, R1),
2125 BPF_LD_ABS(BPF_H, 12),
2126 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2127 BPF_LD_ABS(BPF_H, 12),
2128 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2129 BPF_MOV32_IMM(R0, 18),
2130 BPF_STX_MEM(BPF_W, R10, R0, -64),
2131 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2132 BPF_LD_IND(BPF_W, R7, 14),
2133 BPF_STX_MEM(BPF_W, R10, R0, -60),
2134 BPF_MOV32_IMM(R0, 280971478),
2135 BPF_STX_MEM(BPF_W, R10, R0, -56),
2136 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2137 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2138 BPF_ALU32_REG(BPF_SUB, R0, R7),
2139 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2140 BPF_LD_ABS(BPF_H, 12),
2141 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2142 BPF_MOV32_IMM(R0, 22),
2143 BPF_STX_MEM(BPF_W, R10, R0, -56),
2144 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2145 BPF_LD_IND(BPF_H, R7, 14),
2146 BPF_STX_MEM(BPF_W, R10, R0, -52),
2147 BPF_MOV32_IMM(R0, 17366),
2148 BPF_STX_MEM(BPF_W, R10, R0, -48),
2149 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2150 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2151 BPF_ALU32_REG(BPF_SUB, R0, R7),
2152 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2153 BPF_MOV32_IMM(R0, 256),
2154 BPF_EXIT_INSN(),
2155 BPF_MOV32_IMM(R0, 0),
2156 BPF_EXIT_INSN(),
2157 },
2158 INTERNAL,
2159 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2161 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2162 { { 38, 256 } }
2163 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002164 /* BPF_ALU | BPF_MOV | BPF_X */
2165 {
2166 "ALU_MOV_X: dst = 2",
2167 .u.insns_int = {
2168 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2169 BPF_ALU32_REG(BPF_MOV, R0, R1),
2170 BPF_EXIT_INSN(),
2171 },
2172 INTERNAL,
2173 { },
2174 { { 0, 2 } },
2175 },
2176 {
2177 "ALU_MOV_X: dst = 4294967295",
2178 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002179 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002180 BPF_ALU32_REG(BPF_MOV, R0, R1),
2181 BPF_EXIT_INSN(),
2182 },
2183 INTERNAL,
2184 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002185 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002186 },
2187 {
2188 "ALU64_MOV_X: dst = 2",
2189 .u.insns_int = {
2190 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2191 BPF_ALU64_REG(BPF_MOV, R0, R1),
2192 BPF_EXIT_INSN(),
2193 },
2194 INTERNAL,
2195 { },
2196 { { 0, 2 } },
2197 },
2198 {
2199 "ALU64_MOV_X: dst = 4294967295",
2200 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002201 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002202 BPF_ALU64_REG(BPF_MOV, R0, R1),
2203 BPF_EXIT_INSN(),
2204 },
2205 INTERNAL,
2206 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002207 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002208 },
2209 /* BPF_ALU | BPF_MOV | BPF_K */
2210 {
2211 "ALU_MOV_K: dst = 2",
2212 .u.insns_int = {
2213 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2214 BPF_EXIT_INSN(),
2215 },
2216 INTERNAL,
2217 { },
2218 { { 0, 2 } },
2219 },
2220 {
2221 "ALU_MOV_K: dst = 4294967295",
2222 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002223 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002224 BPF_EXIT_INSN(),
2225 },
2226 INTERNAL,
2227 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002228 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002229 },
2230 {
2231 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2232 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002233 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2234 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002235 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2236 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2237 BPF_MOV32_IMM(R0, 2),
2238 BPF_EXIT_INSN(),
2239 BPF_MOV32_IMM(R0, 1),
2240 BPF_EXIT_INSN(),
2241 },
2242 INTERNAL,
2243 { },
2244 { { 0, 0x1 } },
2245 },
2246 {
2247 "ALU64_MOV_K: dst = 2",
2248 .u.insns_int = {
2249 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2250 BPF_EXIT_INSN(),
2251 },
2252 INTERNAL,
2253 { },
2254 { { 0, 2 } },
2255 },
2256 {
2257 "ALU64_MOV_K: dst = 2147483647",
2258 .u.insns_int = {
2259 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2260 BPF_EXIT_INSN(),
2261 },
2262 INTERNAL,
2263 { },
2264 { { 0, 2147483647 } },
2265 },
2266 {
2267 "ALU64_OR_K: dst = 0x0",
2268 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002269 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002270 BPF_LD_IMM64(R3, 0x0),
2271 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2272 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2273 BPF_MOV32_IMM(R0, 2),
2274 BPF_EXIT_INSN(),
2275 BPF_MOV32_IMM(R0, 1),
2276 BPF_EXIT_INSN(),
2277 },
2278 INTERNAL,
2279 { },
2280 { { 0, 0x1 } },
2281 },
2282 {
2283 "ALU64_MOV_K: dst = -1",
2284 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002285 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2286 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002287 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2288 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2289 BPF_MOV32_IMM(R0, 2),
2290 BPF_EXIT_INSN(),
2291 BPF_MOV32_IMM(R0, 1),
2292 BPF_EXIT_INSN(),
2293 },
2294 INTERNAL,
2295 { },
2296 { { 0, 0x1 } },
2297 },
2298 /* BPF_ALU | BPF_ADD | BPF_X */
2299 {
2300 "ALU_ADD_X: 1 + 2 = 3",
2301 .u.insns_int = {
2302 BPF_LD_IMM64(R0, 1),
2303 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2304 BPF_ALU32_REG(BPF_ADD, R0, R1),
2305 BPF_EXIT_INSN(),
2306 },
2307 INTERNAL,
2308 { },
2309 { { 0, 3 } },
2310 },
2311 {
2312 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2313 .u.insns_int = {
2314 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002315 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002316 BPF_ALU32_REG(BPF_ADD, R0, R1),
2317 BPF_EXIT_INSN(),
2318 },
2319 INTERNAL,
2320 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002321 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002322 },
2323 {
2324 "ALU64_ADD_X: 1 + 2 = 3",
2325 .u.insns_int = {
2326 BPF_LD_IMM64(R0, 1),
2327 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2328 BPF_ALU64_REG(BPF_ADD, R0, R1),
2329 BPF_EXIT_INSN(),
2330 },
2331 INTERNAL,
2332 { },
2333 { { 0, 3 } },
2334 },
2335 {
2336 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2337 .u.insns_int = {
2338 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002339 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002340 BPF_ALU64_REG(BPF_ADD, R0, R1),
2341 BPF_EXIT_INSN(),
2342 },
2343 INTERNAL,
2344 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002345 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002346 },
2347 /* BPF_ALU | BPF_ADD | BPF_K */
2348 {
2349 "ALU_ADD_K: 1 + 2 = 3",
2350 .u.insns_int = {
2351 BPF_LD_IMM64(R0, 1),
2352 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2353 BPF_EXIT_INSN(),
2354 },
2355 INTERNAL,
2356 { },
2357 { { 0, 3 } },
2358 },
2359 {
2360 "ALU_ADD_K: 3 + 0 = 3",
2361 .u.insns_int = {
2362 BPF_LD_IMM64(R0, 3),
2363 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2364 BPF_EXIT_INSN(),
2365 },
2366 INTERNAL,
2367 { },
2368 { { 0, 3 } },
2369 },
2370 {
2371 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2372 .u.insns_int = {
2373 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002374 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002375 BPF_EXIT_INSN(),
2376 },
2377 INTERNAL,
2378 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002379 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002380 },
2381 {
2382 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2383 .u.insns_int = {
2384 BPF_LD_IMM64(R2, 0x0),
2385 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2386 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2387 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2388 BPF_MOV32_IMM(R0, 2),
2389 BPF_EXIT_INSN(),
2390 BPF_MOV32_IMM(R0, 1),
2391 BPF_EXIT_INSN(),
2392 },
2393 INTERNAL,
2394 { },
2395 { { 0, 0x1 } },
2396 },
2397 {
2398 "ALU64_ADD_K: 1 + 2 = 3",
2399 .u.insns_int = {
2400 BPF_LD_IMM64(R0, 1),
2401 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2402 BPF_EXIT_INSN(),
2403 },
2404 INTERNAL,
2405 { },
2406 { { 0, 3 } },
2407 },
2408 {
2409 "ALU64_ADD_K: 3 + 0 = 3",
2410 .u.insns_int = {
2411 BPF_LD_IMM64(R0, 3),
2412 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2413 BPF_EXIT_INSN(),
2414 },
2415 INTERNAL,
2416 { },
2417 { { 0, 3 } },
2418 },
2419 {
2420 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2421 .u.insns_int = {
2422 BPF_LD_IMM64(R0, 1),
2423 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2424 BPF_EXIT_INSN(),
2425 },
2426 INTERNAL,
2427 { },
2428 { { 0, 2147483647 } },
2429 },
2430 {
2431 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2432 .u.insns_int = {
2433 BPF_LD_IMM64(R0, 2147483646),
2434 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2435 BPF_EXIT_INSN(),
2436 },
2437 INTERNAL,
2438 { },
2439 { { 0, -1 } },
2440 },
2441 {
2442 "ALU64_ADD_K: 1 + 0 = 1",
2443 .u.insns_int = {
2444 BPF_LD_IMM64(R2, 0x1),
2445 BPF_LD_IMM64(R3, 0x1),
2446 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2447 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2448 BPF_MOV32_IMM(R0, 2),
2449 BPF_EXIT_INSN(),
2450 BPF_MOV32_IMM(R0, 1),
2451 BPF_EXIT_INSN(),
2452 },
2453 INTERNAL,
2454 { },
2455 { { 0, 0x1 } },
2456 },
2457 {
2458 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2459 .u.insns_int = {
2460 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002461 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002462 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2463 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2464 BPF_MOV32_IMM(R0, 2),
2465 BPF_EXIT_INSN(),
2466 BPF_MOV32_IMM(R0, 1),
2467 BPF_EXIT_INSN(),
2468 },
2469 INTERNAL,
2470 { },
2471 { { 0, 0x1 } },
2472 },
2473 /* BPF_ALU | BPF_SUB | BPF_X */
2474 {
2475 "ALU_SUB_X: 3 - 1 = 2",
2476 .u.insns_int = {
2477 BPF_LD_IMM64(R0, 3),
2478 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2479 BPF_ALU32_REG(BPF_SUB, R0, R1),
2480 BPF_EXIT_INSN(),
2481 },
2482 INTERNAL,
2483 { },
2484 { { 0, 2 } },
2485 },
2486 {
2487 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2488 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002489 BPF_LD_IMM64(R0, 4294967295U),
2490 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002491 BPF_ALU32_REG(BPF_SUB, R0, R1),
2492 BPF_EXIT_INSN(),
2493 },
2494 INTERNAL,
2495 { },
2496 { { 0, 1 } },
2497 },
2498 {
2499 "ALU64_SUB_X: 3 - 1 = 2",
2500 .u.insns_int = {
2501 BPF_LD_IMM64(R0, 3),
2502 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2503 BPF_ALU64_REG(BPF_SUB, R0, R1),
2504 BPF_EXIT_INSN(),
2505 },
2506 INTERNAL,
2507 { },
2508 { { 0, 2 } },
2509 },
2510 {
2511 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2512 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002513 BPF_LD_IMM64(R0, 4294967295U),
2514 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002515 BPF_ALU64_REG(BPF_SUB, R0, R1),
2516 BPF_EXIT_INSN(),
2517 },
2518 INTERNAL,
2519 { },
2520 { { 0, 1 } },
2521 },
2522 /* BPF_ALU | BPF_SUB | BPF_K */
2523 {
2524 "ALU_SUB_K: 3 - 1 = 2",
2525 .u.insns_int = {
2526 BPF_LD_IMM64(R0, 3),
2527 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2528 BPF_EXIT_INSN(),
2529 },
2530 INTERNAL,
2531 { },
2532 { { 0, 2 } },
2533 },
2534 {
2535 "ALU_SUB_K: 3 - 0 = 3",
2536 .u.insns_int = {
2537 BPF_LD_IMM64(R0, 3),
2538 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2539 BPF_EXIT_INSN(),
2540 },
2541 INTERNAL,
2542 { },
2543 { { 0, 3 } },
2544 },
2545 {
2546 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2547 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002548 BPF_LD_IMM64(R0, 4294967295U),
2549 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002550 BPF_EXIT_INSN(),
2551 },
2552 INTERNAL,
2553 { },
2554 { { 0, 1 } },
2555 },
2556 {
2557 "ALU64_SUB_K: 3 - 1 = 2",
2558 .u.insns_int = {
2559 BPF_LD_IMM64(R0, 3),
2560 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2561 BPF_EXIT_INSN(),
2562 },
2563 INTERNAL,
2564 { },
2565 { { 0, 2 } },
2566 },
2567 {
2568 "ALU64_SUB_K: 3 - 0 = 3",
2569 .u.insns_int = {
2570 BPF_LD_IMM64(R0, 3),
2571 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2572 BPF_EXIT_INSN(),
2573 },
2574 INTERNAL,
2575 { },
2576 { { 0, 3 } },
2577 },
2578 {
2579 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2580 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002581 BPF_LD_IMM64(R0, 4294967294U),
2582 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002583 BPF_EXIT_INSN(),
2584 },
2585 INTERNAL,
2586 { },
2587 { { 0, -1 } },
2588 },
2589 {
2590 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2591 .u.insns_int = {
2592 BPF_LD_IMM64(R0, 2147483646),
2593 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2594 BPF_EXIT_INSN(),
2595 },
2596 INTERNAL,
2597 { },
2598 { { 0, -1 } },
2599 },
2600 /* BPF_ALU | BPF_MUL | BPF_X */
2601 {
2602 "ALU_MUL_X: 2 * 3 = 6",
2603 .u.insns_int = {
2604 BPF_LD_IMM64(R0, 2),
2605 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2606 BPF_ALU32_REG(BPF_MUL, R0, R1),
2607 BPF_EXIT_INSN(),
2608 },
2609 INTERNAL,
2610 { },
2611 { { 0, 6 } },
2612 },
2613 {
2614 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2615 .u.insns_int = {
2616 BPF_LD_IMM64(R0, 2),
2617 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2618 BPF_ALU32_REG(BPF_MUL, R0, R1),
2619 BPF_EXIT_INSN(),
2620 },
2621 INTERNAL,
2622 { },
2623 { { 0, 0xFFFFFFF0 } },
2624 },
2625 {
2626 "ALU_MUL_X: -1 * -1 = 1",
2627 .u.insns_int = {
2628 BPF_LD_IMM64(R0, -1),
2629 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2630 BPF_ALU32_REG(BPF_MUL, R0, R1),
2631 BPF_EXIT_INSN(),
2632 },
2633 INTERNAL,
2634 { },
2635 { { 0, 1 } },
2636 },
2637 {
2638 "ALU64_MUL_X: 2 * 3 = 6",
2639 .u.insns_int = {
2640 BPF_LD_IMM64(R0, 2),
2641 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2642 BPF_ALU64_REG(BPF_MUL, R0, R1),
2643 BPF_EXIT_INSN(),
2644 },
2645 INTERNAL,
2646 { },
2647 { { 0, 6 } },
2648 },
2649 {
2650 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2651 .u.insns_int = {
2652 BPF_LD_IMM64(R0, 1),
2653 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2654 BPF_ALU64_REG(BPF_MUL, R0, R1),
2655 BPF_EXIT_INSN(),
2656 },
2657 INTERNAL,
2658 { },
2659 { { 0, 2147483647 } },
2660 },
2661 /* BPF_ALU | BPF_MUL | BPF_K */
2662 {
2663 "ALU_MUL_K: 2 * 3 = 6",
2664 .u.insns_int = {
2665 BPF_LD_IMM64(R0, 2),
2666 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2667 BPF_EXIT_INSN(),
2668 },
2669 INTERNAL,
2670 { },
2671 { { 0, 6 } },
2672 },
2673 {
2674 "ALU_MUL_K: 3 * 1 = 3",
2675 .u.insns_int = {
2676 BPF_LD_IMM64(R0, 3),
2677 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2678 BPF_EXIT_INSN(),
2679 },
2680 INTERNAL,
2681 { },
2682 { { 0, 3 } },
2683 },
2684 {
2685 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2686 .u.insns_int = {
2687 BPF_LD_IMM64(R0, 2),
2688 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2689 BPF_EXIT_INSN(),
2690 },
2691 INTERNAL,
2692 { },
2693 { { 0, 0xFFFFFFF0 } },
2694 },
2695 {
2696 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
2697 .u.insns_int = {
2698 BPF_LD_IMM64(R2, 0x1),
2699 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2700 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
2701 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2702 BPF_MOV32_IMM(R0, 2),
2703 BPF_EXIT_INSN(),
2704 BPF_MOV32_IMM(R0, 1),
2705 BPF_EXIT_INSN(),
2706 },
2707 INTERNAL,
2708 { },
2709 { { 0, 0x1 } },
2710 },
2711 {
2712 "ALU64_MUL_K: 2 * 3 = 6",
2713 .u.insns_int = {
2714 BPF_LD_IMM64(R0, 2),
2715 BPF_ALU64_IMM(BPF_MUL, R0, 3),
2716 BPF_EXIT_INSN(),
2717 },
2718 INTERNAL,
2719 { },
2720 { { 0, 6 } },
2721 },
2722 {
2723 "ALU64_MUL_K: 3 * 1 = 3",
2724 .u.insns_int = {
2725 BPF_LD_IMM64(R0, 3),
2726 BPF_ALU64_IMM(BPF_MUL, R0, 1),
2727 BPF_EXIT_INSN(),
2728 },
2729 INTERNAL,
2730 { },
2731 { { 0, 3 } },
2732 },
2733 {
2734 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
2735 .u.insns_int = {
2736 BPF_LD_IMM64(R0, 1),
2737 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
2738 BPF_EXIT_INSN(),
2739 },
2740 INTERNAL,
2741 { },
2742 { { 0, 2147483647 } },
2743 },
2744 {
2745 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
2746 .u.insns_int = {
2747 BPF_LD_IMM64(R0, 1),
2748 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
2749 BPF_EXIT_INSN(),
2750 },
2751 INTERNAL,
2752 { },
2753 { { 0, -2147483647 } },
2754 },
2755 {
2756 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
2757 .u.insns_int = {
2758 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002759 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002760 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
2761 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2762 BPF_MOV32_IMM(R0, 2),
2763 BPF_EXIT_INSN(),
2764 BPF_MOV32_IMM(R0, 1),
2765 BPF_EXIT_INSN(),
2766 },
2767 INTERNAL,
2768 { },
2769 { { 0, 0x1 } },
2770 },
2771 /* BPF_ALU | BPF_DIV | BPF_X */
2772 {
2773 "ALU_DIV_X: 6 / 2 = 3",
2774 .u.insns_int = {
2775 BPF_LD_IMM64(R0, 6),
2776 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2777 BPF_ALU32_REG(BPF_DIV, R0, R1),
2778 BPF_EXIT_INSN(),
2779 },
2780 INTERNAL,
2781 { },
2782 { { 0, 3 } },
2783 },
2784 {
2785 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
2786 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002787 BPF_LD_IMM64(R0, 4294967295U),
2788 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002789 BPF_ALU32_REG(BPF_DIV, R0, R1),
2790 BPF_EXIT_INSN(),
2791 },
2792 INTERNAL,
2793 { },
2794 { { 0, 1 } },
2795 },
2796 {
2797 "ALU64_DIV_X: 6 / 2 = 3",
2798 .u.insns_int = {
2799 BPF_LD_IMM64(R0, 6),
2800 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2801 BPF_ALU64_REG(BPF_DIV, R0, R1),
2802 BPF_EXIT_INSN(),
2803 },
2804 INTERNAL,
2805 { },
2806 { { 0, 3 } },
2807 },
2808 {
2809 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
2810 .u.insns_int = {
2811 BPF_LD_IMM64(R0, 2147483647),
2812 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2813 BPF_ALU64_REG(BPF_DIV, R0, R1),
2814 BPF_EXIT_INSN(),
2815 },
2816 INTERNAL,
2817 { },
2818 { { 0, 1 } },
2819 },
2820 {
2821 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2822 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002823 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2824 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
2825 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002826 BPF_ALU64_REG(BPF_DIV, R2, R4),
2827 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2828 BPF_MOV32_IMM(R0, 2),
2829 BPF_EXIT_INSN(),
2830 BPF_MOV32_IMM(R0, 1),
2831 BPF_EXIT_INSN(),
2832 },
2833 INTERNAL,
2834 { },
2835 { { 0, 0x1 } },
2836 },
2837 /* BPF_ALU | BPF_DIV | BPF_K */
2838 {
2839 "ALU_DIV_K: 6 / 2 = 3",
2840 .u.insns_int = {
2841 BPF_LD_IMM64(R0, 6),
2842 BPF_ALU32_IMM(BPF_DIV, R0, 2),
2843 BPF_EXIT_INSN(),
2844 },
2845 INTERNAL,
2846 { },
2847 { { 0, 3 } },
2848 },
2849 {
2850 "ALU_DIV_K: 3 / 1 = 3",
2851 .u.insns_int = {
2852 BPF_LD_IMM64(R0, 3),
2853 BPF_ALU32_IMM(BPF_DIV, R0, 1),
2854 BPF_EXIT_INSN(),
2855 },
2856 INTERNAL,
2857 { },
2858 { { 0, 3 } },
2859 },
2860 {
2861 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
2862 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002863 BPF_LD_IMM64(R0, 4294967295U),
2864 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002865 BPF_EXIT_INSN(),
2866 },
2867 INTERNAL,
2868 { },
2869 { { 0, 1 } },
2870 },
2871 {
2872 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
2873 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002874 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002875 BPF_LD_IMM64(R3, 0x1UL),
2876 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
2877 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2878 BPF_MOV32_IMM(R0, 2),
2879 BPF_EXIT_INSN(),
2880 BPF_MOV32_IMM(R0, 1),
2881 BPF_EXIT_INSN(),
2882 },
2883 INTERNAL,
2884 { },
2885 { { 0, 0x1 } },
2886 },
2887 {
2888 "ALU64_DIV_K: 6 / 2 = 3",
2889 .u.insns_int = {
2890 BPF_LD_IMM64(R0, 6),
2891 BPF_ALU64_IMM(BPF_DIV, R0, 2),
2892 BPF_EXIT_INSN(),
2893 },
2894 INTERNAL,
2895 { },
2896 { { 0, 3 } },
2897 },
2898 {
2899 "ALU64_DIV_K: 3 / 1 = 3",
2900 .u.insns_int = {
2901 BPF_LD_IMM64(R0, 3),
2902 BPF_ALU64_IMM(BPF_DIV, R0, 1),
2903 BPF_EXIT_INSN(),
2904 },
2905 INTERNAL,
2906 { },
2907 { { 0, 3 } },
2908 },
2909 {
2910 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
2911 .u.insns_int = {
2912 BPF_LD_IMM64(R0, 2147483647),
2913 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
2914 BPF_EXIT_INSN(),
2915 },
2916 INTERNAL,
2917 { },
2918 { { 0, 1 } },
2919 },
2920 {
2921 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2922 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002923 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2924 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002925 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
2926 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2927 BPF_MOV32_IMM(R0, 2),
2928 BPF_EXIT_INSN(),
2929 BPF_MOV32_IMM(R0, 1),
2930 BPF_EXIT_INSN(),
2931 },
2932 INTERNAL,
2933 { },
2934 { { 0, 0x1 } },
2935 },
2936 /* BPF_ALU | BPF_MOD | BPF_X */
2937 {
2938 "ALU_MOD_X: 3 % 2 = 1",
2939 .u.insns_int = {
2940 BPF_LD_IMM64(R0, 3),
2941 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2942 BPF_ALU32_REG(BPF_MOD, R0, R1),
2943 BPF_EXIT_INSN(),
2944 },
2945 INTERNAL,
2946 { },
2947 { { 0, 1 } },
2948 },
2949 {
2950 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
2951 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002952 BPF_LD_IMM64(R0, 4294967295U),
2953 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002954 BPF_ALU32_REG(BPF_MOD, R0, R1),
2955 BPF_EXIT_INSN(),
2956 },
2957 INTERNAL,
2958 { },
2959 { { 0, 2 } },
2960 },
2961 {
2962 "ALU64_MOD_X: 3 % 2 = 1",
2963 .u.insns_int = {
2964 BPF_LD_IMM64(R0, 3),
2965 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2966 BPF_ALU64_REG(BPF_MOD, R0, R1),
2967 BPF_EXIT_INSN(),
2968 },
2969 INTERNAL,
2970 { },
2971 { { 0, 1 } },
2972 },
2973 {
2974 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
2975 .u.insns_int = {
2976 BPF_LD_IMM64(R0, 2147483647),
2977 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
2978 BPF_ALU64_REG(BPF_MOD, R0, R1),
2979 BPF_EXIT_INSN(),
2980 },
2981 INTERNAL,
2982 { },
2983 { { 0, 2 } },
2984 },
2985 /* BPF_ALU | BPF_MOD | BPF_K */
2986 {
2987 "ALU_MOD_K: 3 % 2 = 1",
2988 .u.insns_int = {
2989 BPF_LD_IMM64(R0, 3),
2990 BPF_ALU32_IMM(BPF_MOD, R0, 2),
2991 BPF_EXIT_INSN(),
2992 },
2993 INTERNAL,
2994 { },
2995 { { 0, 1 } },
2996 },
2997 {
2998 "ALU_MOD_K: 3 % 1 = 0",
2999 .u.insns_int = {
3000 BPF_LD_IMM64(R0, 3),
3001 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3002 BPF_EXIT_INSN(),
3003 },
3004 INTERNAL,
3005 { },
3006 { { 0, 0 } },
3007 },
3008 {
3009 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3010 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003011 BPF_LD_IMM64(R0, 4294967295U),
3012 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003013 BPF_EXIT_INSN(),
3014 },
3015 INTERNAL,
3016 { },
3017 { { 0, 2 } },
3018 },
3019 {
3020 "ALU64_MOD_K: 3 % 2 = 1",
3021 .u.insns_int = {
3022 BPF_LD_IMM64(R0, 3),
3023 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3024 BPF_EXIT_INSN(),
3025 },
3026 INTERNAL,
3027 { },
3028 { { 0, 1 } },
3029 },
3030 {
3031 "ALU64_MOD_K: 3 % 1 = 0",
3032 .u.insns_int = {
3033 BPF_LD_IMM64(R0, 3),
3034 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3035 BPF_EXIT_INSN(),
3036 },
3037 INTERNAL,
3038 { },
3039 { { 0, 0 } },
3040 },
3041 {
3042 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3043 .u.insns_int = {
3044 BPF_LD_IMM64(R0, 2147483647),
3045 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3046 BPF_EXIT_INSN(),
3047 },
3048 INTERNAL,
3049 { },
3050 { { 0, 2 } },
3051 },
3052 /* BPF_ALU | BPF_AND | BPF_X */
3053 {
3054 "ALU_AND_X: 3 & 2 = 2",
3055 .u.insns_int = {
3056 BPF_LD_IMM64(R0, 3),
3057 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3058 BPF_ALU32_REG(BPF_AND, R0, R1),
3059 BPF_EXIT_INSN(),
3060 },
3061 INTERNAL,
3062 { },
3063 { { 0, 2 } },
3064 },
3065 {
3066 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3067 .u.insns_int = {
3068 BPF_LD_IMM64(R0, 0xffffffff),
3069 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3070 BPF_ALU32_REG(BPF_AND, R0, R1),
3071 BPF_EXIT_INSN(),
3072 },
3073 INTERNAL,
3074 { },
3075 { { 0, 0xffffffff } },
3076 },
3077 {
3078 "ALU64_AND_X: 3 & 2 = 2",
3079 .u.insns_int = {
3080 BPF_LD_IMM64(R0, 3),
3081 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3082 BPF_ALU64_REG(BPF_AND, R0, R1),
3083 BPF_EXIT_INSN(),
3084 },
3085 INTERNAL,
3086 { },
3087 { { 0, 2 } },
3088 },
3089 {
3090 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3091 .u.insns_int = {
3092 BPF_LD_IMM64(R0, 0xffffffff),
3093 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3094 BPF_ALU64_REG(BPF_AND, R0, R1),
3095 BPF_EXIT_INSN(),
3096 },
3097 INTERNAL,
3098 { },
3099 { { 0, 0xffffffff } },
3100 },
3101 /* BPF_ALU | BPF_AND | BPF_K */
3102 {
3103 "ALU_AND_K: 3 & 2 = 2",
3104 .u.insns_int = {
3105 BPF_LD_IMM64(R0, 3),
3106 BPF_ALU32_IMM(BPF_AND, R0, 2),
3107 BPF_EXIT_INSN(),
3108 },
3109 INTERNAL,
3110 { },
3111 { { 0, 2 } },
3112 },
3113 {
3114 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3115 .u.insns_int = {
3116 BPF_LD_IMM64(R0, 0xffffffff),
3117 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3118 BPF_EXIT_INSN(),
3119 },
3120 INTERNAL,
3121 { },
3122 { { 0, 0xffffffff } },
3123 },
3124 {
3125 "ALU64_AND_K: 3 & 2 = 2",
3126 .u.insns_int = {
3127 BPF_LD_IMM64(R0, 3),
3128 BPF_ALU64_IMM(BPF_AND, R0, 2),
3129 BPF_EXIT_INSN(),
3130 },
3131 INTERNAL,
3132 { },
3133 { { 0, 2 } },
3134 },
3135 {
3136 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3137 .u.insns_int = {
3138 BPF_LD_IMM64(R0, 0xffffffff),
3139 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3140 BPF_EXIT_INSN(),
3141 },
3142 INTERNAL,
3143 { },
3144 { { 0, 0xffffffff } },
3145 },
3146 {
3147 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3148 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003149 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3150 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003151 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3152 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3153 BPF_MOV32_IMM(R0, 2),
3154 BPF_EXIT_INSN(),
3155 BPF_MOV32_IMM(R0, 1),
3156 BPF_EXIT_INSN(),
3157 },
3158 INTERNAL,
3159 { },
3160 { { 0, 0x1 } },
3161 },
3162 {
3163 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3164 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003165 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3166 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003167 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3168 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3169 BPF_MOV32_IMM(R0, 2),
3170 BPF_EXIT_INSN(),
3171 BPF_MOV32_IMM(R0, 1),
3172 BPF_EXIT_INSN(),
3173 },
3174 INTERNAL,
3175 { },
3176 { { 0, 0x1 } },
3177 },
3178 {
3179 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3180 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003181 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3182 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003183 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3184 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3185 BPF_MOV32_IMM(R0, 2),
3186 BPF_EXIT_INSN(),
3187 BPF_MOV32_IMM(R0, 1),
3188 BPF_EXIT_INSN(),
3189 },
3190 INTERNAL,
3191 { },
3192 { { 0, 0x1 } },
3193 },
3194 /* BPF_ALU | BPF_OR | BPF_X */
3195 {
3196 "ALU_OR_X: 1 | 2 = 3",
3197 .u.insns_int = {
3198 BPF_LD_IMM64(R0, 1),
3199 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3200 BPF_ALU32_REG(BPF_OR, R0, R1),
3201 BPF_EXIT_INSN(),
3202 },
3203 INTERNAL,
3204 { },
3205 { { 0, 3 } },
3206 },
3207 {
3208 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3209 .u.insns_int = {
3210 BPF_LD_IMM64(R0, 0),
3211 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3212 BPF_ALU32_REG(BPF_OR, R0, R1),
3213 BPF_EXIT_INSN(),
3214 },
3215 INTERNAL,
3216 { },
3217 { { 0, 0xffffffff } },
3218 },
3219 {
3220 "ALU64_OR_X: 1 | 2 = 3",
3221 .u.insns_int = {
3222 BPF_LD_IMM64(R0, 1),
3223 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3224 BPF_ALU64_REG(BPF_OR, R0, R1),
3225 BPF_EXIT_INSN(),
3226 },
3227 INTERNAL,
3228 { },
3229 { { 0, 3 } },
3230 },
3231 {
3232 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3233 .u.insns_int = {
3234 BPF_LD_IMM64(R0, 0),
3235 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3236 BPF_ALU64_REG(BPF_OR, R0, R1),
3237 BPF_EXIT_INSN(),
3238 },
3239 INTERNAL,
3240 { },
3241 { { 0, 0xffffffff } },
3242 },
3243 /* BPF_ALU | BPF_OR | BPF_K */
3244 {
3245 "ALU_OR_K: 1 | 2 = 3",
3246 .u.insns_int = {
3247 BPF_LD_IMM64(R0, 1),
3248 BPF_ALU32_IMM(BPF_OR, R0, 2),
3249 BPF_EXIT_INSN(),
3250 },
3251 INTERNAL,
3252 { },
3253 { { 0, 3 } },
3254 },
3255 {
3256 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3257 .u.insns_int = {
3258 BPF_LD_IMM64(R0, 0),
3259 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3260 BPF_EXIT_INSN(),
3261 },
3262 INTERNAL,
3263 { },
3264 { { 0, 0xffffffff } },
3265 },
3266 {
3267 "ALU64_OR_K: 1 | 2 = 3",
3268 .u.insns_int = {
3269 BPF_LD_IMM64(R0, 1),
3270 BPF_ALU64_IMM(BPF_OR, R0, 2),
3271 BPF_EXIT_INSN(),
3272 },
3273 INTERNAL,
3274 { },
3275 { { 0, 3 } },
3276 },
3277 {
3278 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3279 .u.insns_int = {
3280 BPF_LD_IMM64(R0, 0),
3281 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3282 BPF_EXIT_INSN(),
3283 },
3284 INTERNAL,
3285 { },
3286 { { 0, 0xffffffff } },
3287 },
3288 {
3289 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3290 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003291 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3292 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003293 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3294 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3295 BPF_MOV32_IMM(R0, 2),
3296 BPF_EXIT_INSN(),
3297 BPF_MOV32_IMM(R0, 1),
3298 BPF_EXIT_INSN(),
3299 },
3300 INTERNAL,
3301 { },
3302 { { 0, 0x1 } },
3303 },
3304 {
3305 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3306 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003307 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3308 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003309 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3310 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3311 BPF_MOV32_IMM(R0, 2),
3312 BPF_EXIT_INSN(),
3313 BPF_MOV32_IMM(R0, 1),
3314 BPF_EXIT_INSN(),
3315 },
3316 INTERNAL,
3317 { },
3318 { { 0, 0x1 } },
3319 },
3320 {
3321 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3322 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003323 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3324 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003325 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3326 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3327 BPF_MOV32_IMM(R0, 2),
3328 BPF_EXIT_INSN(),
3329 BPF_MOV32_IMM(R0, 1),
3330 BPF_EXIT_INSN(),
3331 },
3332 INTERNAL,
3333 { },
3334 { { 0, 0x1 } },
3335 },
3336 /* BPF_ALU | BPF_XOR | BPF_X */
3337 {
3338 "ALU_XOR_X: 5 ^ 6 = 3",
3339 .u.insns_int = {
3340 BPF_LD_IMM64(R0, 5),
3341 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3342 BPF_ALU32_REG(BPF_XOR, R0, R1),
3343 BPF_EXIT_INSN(),
3344 },
3345 INTERNAL,
3346 { },
3347 { { 0, 3 } },
3348 },
3349 {
3350 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3351 .u.insns_int = {
3352 BPF_LD_IMM64(R0, 1),
3353 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3354 BPF_ALU32_REG(BPF_XOR, R0, R1),
3355 BPF_EXIT_INSN(),
3356 },
3357 INTERNAL,
3358 { },
3359 { { 0, 0xfffffffe } },
3360 },
3361 {
3362 "ALU64_XOR_X: 5 ^ 6 = 3",
3363 .u.insns_int = {
3364 BPF_LD_IMM64(R0, 5),
3365 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3366 BPF_ALU64_REG(BPF_XOR, R0, R1),
3367 BPF_EXIT_INSN(),
3368 },
3369 INTERNAL,
3370 { },
3371 { { 0, 3 } },
3372 },
3373 {
3374 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3375 .u.insns_int = {
3376 BPF_LD_IMM64(R0, 1),
3377 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3378 BPF_ALU64_REG(BPF_XOR, R0, R1),
3379 BPF_EXIT_INSN(),
3380 },
3381 INTERNAL,
3382 { },
3383 { { 0, 0xfffffffe } },
3384 },
3385 /* BPF_ALU | BPF_XOR | BPF_K */
3386 {
3387 "ALU_XOR_K: 5 ^ 6 = 3",
3388 .u.insns_int = {
3389 BPF_LD_IMM64(R0, 5),
3390 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3391 BPF_EXIT_INSN(),
3392 },
3393 INTERNAL,
3394 { },
3395 { { 0, 3 } },
3396 },
3397 {
3398 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3399 .u.insns_int = {
3400 BPF_LD_IMM64(R0, 1),
3401 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3402 BPF_EXIT_INSN(),
3403 },
3404 INTERNAL,
3405 { },
3406 { { 0, 0xfffffffe } },
3407 },
3408 {
3409 "ALU64_XOR_K: 5 ^ 6 = 3",
3410 .u.insns_int = {
3411 BPF_LD_IMM64(R0, 5),
3412 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3413 BPF_EXIT_INSN(),
3414 },
3415 INTERNAL,
3416 { },
3417 { { 0, 3 } },
3418 },
3419 {
3420 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3421 .u.insns_int = {
3422 BPF_LD_IMM64(R0, 1),
3423 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3424 BPF_EXIT_INSN(),
3425 },
3426 INTERNAL,
3427 { },
3428 { { 0, 0xfffffffe } },
3429 },
3430 {
3431 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3432 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003433 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3434 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003435 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3436 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3437 BPF_MOV32_IMM(R0, 2),
3438 BPF_EXIT_INSN(),
3439 BPF_MOV32_IMM(R0, 1),
3440 BPF_EXIT_INSN(),
3441 },
3442 INTERNAL,
3443 { },
3444 { { 0, 0x1 } },
3445 },
3446 {
3447 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3448 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003449 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3450 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003451 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3452 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3453 BPF_MOV32_IMM(R0, 2),
3454 BPF_EXIT_INSN(),
3455 BPF_MOV32_IMM(R0, 1),
3456 BPF_EXIT_INSN(),
3457 },
3458 INTERNAL,
3459 { },
3460 { { 0, 0x1 } },
3461 },
3462 {
3463 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3464 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003465 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3466 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003467 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3468 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3469 BPF_MOV32_IMM(R0, 2),
3470 BPF_EXIT_INSN(),
3471 BPF_MOV32_IMM(R0, 1),
3472 BPF_EXIT_INSN(),
3473 },
3474 INTERNAL,
3475 { },
3476 { { 0, 0x1 } },
3477 },
3478 /* BPF_ALU | BPF_LSH | BPF_X */
3479 {
3480 "ALU_LSH_X: 1 << 1 = 2",
3481 .u.insns_int = {
3482 BPF_LD_IMM64(R0, 1),
3483 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3484 BPF_ALU32_REG(BPF_LSH, R0, R1),
3485 BPF_EXIT_INSN(),
3486 },
3487 INTERNAL,
3488 { },
3489 { { 0, 2 } },
3490 },
3491 {
3492 "ALU_LSH_X: 1 << 31 = 0x80000000",
3493 .u.insns_int = {
3494 BPF_LD_IMM64(R0, 1),
3495 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3496 BPF_ALU32_REG(BPF_LSH, R0, R1),
3497 BPF_EXIT_INSN(),
3498 },
3499 INTERNAL,
3500 { },
3501 { { 0, 0x80000000 } },
3502 },
3503 {
3504 "ALU64_LSH_X: 1 << 1 = 2",
3505 .u.insns_int = {
3506 BPF_LD_IMM64(R0, 1),
3507 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3508 BPF_ALU64_REG(BPF_LSH, R0, R1),
3509 BPF_EXIT_INSN(),
3510 },
3511 INTERNAL,
3512 { },
3513 { { 0, 2 } },
3514 },
3515 {
3516 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3517 .u.insns_int = {
3518 BPF_LD_IMM64(R0, 1),
3519 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3520 BPF_ALU64_REG(BPF_LSH, R0, R1),
3521 BPF_EXIT_INSN(),
3522 },
3523 INTERNAL,
3524 { },
3525 { { 0, 0x80000000 } },
3526 },
3527 /* BPF_ALU | BPF_LSH | BPF_K */
3528 {
3529 "ALU_LSH_K: 1 << 1 = 2",
3530 .u.insns_int = {
3531 BPF_LD_IMM64(R0, 1),
3532 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3533 BPF_EXIT_INSN(),
3534 },
3535 INTERNAL,
3536 { },
3537 { { 0, 2 } },
3538 },
3539 {
3540 "ALU_LSH_K: 1 << 31 = 0x80000000",
3541 .u.insns_int = {
3542 BPF_LD_IMM64(R0, 1),
3543 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3544 BPF_EXIT_INSN(),
3545 },
3546 INTERNAL,
3547 { },
3548 { { 0, 0x80000000 } },
3549 },
3550 {
3551 "ALU64_LSH_K: 1 << 1 = 2",
3552 .u.insns_int = {
3553 BPF_LD_IMM64(R0, 1),
3554 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3555 BPF_EXIT_INSN(),
3556 },
3557 INTERNAL,
3558 { },
3559 { { 0, 2 } },
3560 },
3561 {
3562 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3563 .u.insns_int = {
3564 BPF_LD_IMM64(R0, 1),
3565 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3566 BPF_EXIT_INSN(),
3567 },
3568 INTERNAL,
3569 { },
3570 { { 0, 0x80000000 } },
3571 },
3572 /* BPF_ALU | BPF_RSH | BPF_X */
3573 {
3574 "ALU_RSH_X: 2 >> 1 = 1",
3575 .u.insns_int = {
3576 BPF_LD_IMM64(R0, 2),
3577 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3578 BPF_ALU32_REG(BPF_RSH, R0, R1),
3579 BPF_EXIT_INSN(),
3580 },
3581 INTERNAL,
3582 { },
3583 { { 0, 1 } },
3584 },
3585 {
3586 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3587 .u.insns_int = {
3588 BPF_LD_IMM64(R0, 0x80000000),
3589 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3590 BPF_ALU32_REG(BPF_RSH, R0, R1),
3591 BPF_EXIT_INSN(),
3592 },
3593 INTERNAL,
3594 { },
3595 { { 0, 1 } },
3596 },
3597 {
3598 "ALU64_RSH_X: 2 >> 1 = 1",
3599 .u.insns_int = {
3600 BPF_LD_IMM64(R0, 2),
3601 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3602 BPF_ALU64_REG(BPF_RSH, R0, R1),
3603 BPF_EXIT_INSN(),
3604 },
3605 INTERNAL,
3606 { },
3607 { { 0, 1 } },
3608 },
3609 {
3610 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3611 .u.insns_int = {
3612 BPF_LD_IMM64(R0, 0x80000000),
3613 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3614 BPF_ALU64_REG(BPF_RSH, R0, R1),
3615 BPF_EXIT_INSN(),
3616 },
3617 INTERNAL,
3618 { },
3619 { { 0, 1 } },
3620 },
3621 /* BPF_ALU | BPF_RSH | BPF_K */
3622 {
3623 "ALU_RSH_K: 2 >> 1 = 1",
3624 .u.insns_int = {
3625 BPF_LD_IMM64(R0, 2),
3626 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3627 BPF_EXIT_INSN(),
3628 },
3629 INTERNAL,
3630 { },
3631 { { 0, 1 } },
3632 },
3633 {
3634 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3635 .u.insns_int = {
3636 BPF_LD_IMM64(R0, 0x80000000),
3637 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3638 BPF_EXIT_INSN(),
3639 },
3640 INTERNAL,
3641 { },
3642 { { 0, 1 } },
3643 },
3644 {
3645 "ALU64_RSH_K: 2 >> 1 = 1",
3646 .u.insns_int = {
3647 BPF_LD_IMM64(R0, 2),
3648 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3649 BPF_EXIT_INSN(),
3650 },
3651 INTERNAL,
3652 { },
3653 { { 0, 1 } },
3654 },
3655 {
3656 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3657 .u.insns_int = {
3658 BPF_LD_IMM64(R0, 0x80000000),
3659 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3660 BPF_EXIT_INSN(),
3661 },
3662 INTERNAL,
3663 { },
3664 { { 0, 1 } },
3665 },
3666 /* BPF_ALU | BPF_ARSH | BPF_X */
3667 {
3668 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3669 .u.insns_int = {
3670 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3671 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3672 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3673 BPF_EXIT_INSN(),
3674 },
3675 INTERNAL,
3676 { },
3677 { { 0, 0xffff00ff } },
3678 },
3679 /* BPF_ALU | BPF_ARSH | BPF_K */
3680 {
3681 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3682 .u.insns_int = {
3683 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3684 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3685 BPF_EXIT_INSN(),
3686 },
3687 INTERNAL,
3688 { },
3689 { { 0, 0xffff00ff } },
3690 },
3691 /* BPF_ALU | BPF_NEG */
3692 {
3693 "ALU_NEG: -(3) = -3",
3694 .u.insns_int = {
3695 BPF_ALU32_IMM(BPF_MOV, R0, 3),
3696 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3697 BPF_EXIT_INSN(),
3698 },
3699 INTERNAL,
3700 { },
3701 { { 0, -3 } },
3702 },
3703 {
3704 "ALU_NEG: -(-3) = 3",
3705 .u.insns_int = {
3706 BPF_ALU32_IMM(BPF_MOV, R0, -3),
3707 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3708 BPF_EXIT_INSN(),
3709 },
3710 INTERNAL,
3711 { },
3712 { { 0, 3 } },
3713 },
3714 {
3715 "ALU64_NEG: -(3) = -3",
3716 .u.insns_int = {
3717 BPF_LD_IMM64(R0, 3),
3718 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3719 BPF_EXIT_INSN(),
3720 },
3721 INTERNAL,
3722 { },
3723 { { 0, -3 } },
3724 },
3725 {
3726 "ALU64_NEG: -(-3) = 3",
3727 .u.insns_int = {
3728 BPF_LD_IMM64(R0, -3),
3729 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3730 BPF_EXIT_INSN(),
3731 },
3732 INTERNAL,
3733 { },
3734 { { 0, 3 } },
3735 },
3736 /* BPF_ALU | BPF_END | BPF_FROM_BE */
3737 {
3738 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
3739 .u.insns_int = {
3740 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3741 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
3742 BPF_EXIT_INSN(),
3743 },
3744 INTERNAL,
3745 { },
3746 { { 0, cpu_to_be16(0xcdef) } },
3747 },
3748 {
3749 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
3750 .u.insns_int = {
3751 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3752 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07003753 BPF_ALU64_REG(BPF_MOV, R1, R0),
3754 BPF_ALU64_IMM(BPF_RSH, R1, 32),
3755 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07003756 BPF_EXIT_INSN(),
3757 },
3758 INTERNAL,
3759 { },
3760 { { 0, cpu_to_be32(0x89abcdef) } },
3761 },
3762 {
3763 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
3764 .u.insns_int = {
3765 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3766 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
3767 BPF_EXIT_INSN(),
3768 },
3769 INTERNAL,
3770 { },
3771 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
3772 },
3773 /* BPF_ALU | BPF_END | BPF_FROM_LE */
3774 {
3775 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
3776 .u.insns_int = {
3777 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3778 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
3779 BPF_EXIT_INSN(),
3780 },
3781 INTERNAL,
3782 { },
3783 { { 0, cpu_to_le16(0xcdef) } },
3784 },
3785 {
3786 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
3787 .u.insns_int = {
3788 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3789 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07003790 BPF_ALU64_REG(BPF_MOV, R1, R0),
3791 BPF_ALU64_IMM(BPF_RSH, R1, 32),
3792 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07003793 BPF_EXIT_INSN(),
3794 },
3795 INTERNAL,
3796 { },
3797 { { 0, cpu_to_le32(0x89abcdef) } },
3798 },
3799 {
3800 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
3801 .u.insns_int = {
3802 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3803 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
3804 BPF_EXIT_INSN(),
3805 },
3806 INTERNAL,
3807 { },
3808 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
3809 },
3810 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
3811 {
3812 "ST_MEM_B: Store/Load byte: max negative",
3813 .u.insns_int = {
3814 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3815 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
3816 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3817 BPF_EXIT_INSN(),
3818 },
3819 INTERNAL,
3820 { },
3821 { { 0, 0xff } },
3822 },
3823 {
3824 "ST_MEM_B: Store/Load byte: max positive",
3825 .u.insns_int = {
3826 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3827 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
3828 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3829 BPF_EXIT_INSN(),
3830 },
3831 INTERNAL,
3832 { },
3833 { { 0, 0x7f } },
3834 },
3835 {
3836 "STX_MEM_B: Store/Load byte: max negative",
3837 .u.insns_int = {
3838 BPF_LD_IMM64(R0, 0),
3839 BPF_LD_IMM64(R1, 0xffLL),
3840 BPF_STX_MEM(BPF_B, R10, R1, -40),
3841 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3842 BPF_EXIT_INSN(),
3843 },
3844 INTERNAL,
3845 { },
3846 { { 0, 0xff } },
3847 },
3848 {
3849 "ST_MEM_H: Store/Load half word: max negative",
3850 .u.insns_int = {
3851 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3852 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
3853 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3854 BPF_EXIT_INSN(),
3855 },
3856 INTERNAL,
3857 { },
3858 { { 0, 0xffff } },
3859 },
3860 {
3861 "ST_MEM_H: Store/Load half word: max positive",
3862 .u.insns_int = {
3863 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3864 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
3865 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3866 BPF_EXIT_INSN(),
3867 },
3868 INTERNAL,
3869 { },
3870 { { 0, 0x7fff } },
3871 },
3872 {
3873 "STX_MEM_H: Store/Load half word: max negative",
3874 .u.insns_int = {
3875 BPF_LD_IMM64(R0, 0),
3876 BPF_LD_IMM64(R1, 0xffffLL),
3877 BPF_STX_MEM(BPF_H, R10, R1, -40),
3878 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3879 BPF_EXIT_INSN(),
3880 },
3881 INTERNAL,
3882 { },
3883 { { 0, 0xffff } },
3884 },
3885 {
3886 "ST_MEM_W: Store/Load word: max negative",
3887 .u.insns_int = {
3888 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3889 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
3890 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3891 BPF_EXIT_INSN(),
3892 },
3893 INTERNAL,
3894 { },
3895 { { 0, 0xffffffff } },
3896 },
3897 {
3898 "ST_MEM_W: Store/Load word: max positive",
3899 .u.insns_int = {
3900 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3901 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
3902 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3903 BPF_EXIT_INSN(),
3904 },
3905 INTERNAL,
3906 { },
3907 { { 0, 0x7fffffff } },
3908 },
3909 {
3910 "STX_MEM_W: Store/Load word: max negative",
3911 .u.insns_int = {
3912 BPF_LD_IMM64(R0, 0),
3913 BPF_LD_IMM64(R1, 0xffffffffLL),
3914 BPF_STX_MEM(BPF_W, R10, R1, -40),
3915 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3916 BPF_EXIT_INSN(),
3917 },
3918 INTERNAL,
3919 { },
3920 { { 0, 0xffffffff } },
3921 },
3922 {
3923 "ST_MEM_DW: Store/Load double word: max negative",
3924 .u.insns_int = {
3925 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3926 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3927 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3928 BPF_EXIT_INSN(),
3929 },
3930 INTERNAL,
3931 { },
3932 { { 0, 0xffffffff } },
3933 },
3934 {
3935 "ST_MEM_DW: Store/Load double word: max negative 2",
3936 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003937 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
3938 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003939 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3940 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
3941 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3942 BPF_MOV32_IMM(R0, 2),
3943 BPF_EXIT_INSN(),
3944 BPF_MOV32_IMM(R0, 1),
3945 BPF_EXIT_INSN(),
3946 },
3947 INTERNAL,
3948 { },
3949 { { 0, 0x1 } },
3950 },
3951 {
3952 "ST_MEM_DW: Store/Load double word: max positive",
3953 .u.insns_int = {
3954 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3955 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
3956 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3957 BPF_EXIT_INSN(),
3958 },
3959 INTERNAL,
3960 { },
3961 { { 0, 0x7fffffff } },
3962 },
3963 {
3964 "STX_MEM_DW: Store/Load double word: max negative",
3965 .u.insns_int = {
3966 BPF_LD_IMM64(R0, 0),
3967 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3968 BPF_STX_MEM(BPF_W, R10, R1, -40),
3969 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3970 BPF_EXIT_INSN(),
3971 },
3972 INTERNAL,
3973 { },
3974 { { 0, 0xffffffff } },
3975 },
3976 /* BPF_STX | BPF_XADD | BPF_W/DW */
3977 {
3978 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
3979 .u.insns_int = {
3980 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3981 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
3982 BPF_STX_XADD(BPF_W, R10, R0, -40),
3983 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3984 BPF_EXIT_INSN(),
3985 },
3986 INTERNAL,
3987 { },
3988 { { 0, 0x22 } },
3989 },
3990 {
3991 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
3992 .u.insns_int = {
3993 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3994 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
3995 BPF_STX_XADD(BPF_DW, R10, R0, -40),
3996 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3997 BPF_EXIT_INSN(),
3998 },
3999 INTERNAL,
4000 { },
4001 { { 0, 0x22 } },
4002 },
4003 /* BPF_JMP | BPF_EXIT */
4004 {
4005 "JMP_EXIT",
4006 .u.insns_int = {
4007 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4008 BPF_EXIT_INSN(),
4009 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4010 },
4011 INTERNAL,
4012 { },
4013 { { 0, 0x4711 } },
4014 },
4015 /* BPF_JMP | BPF_JA */
4016 {
4017 "JMP_JA: Unconditional jump: if (true) return 1",
4018 .u.insns_int = {
4019 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4020 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4021 BPF_EXIT_INSN(),
4022 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4023 BPF_EXIT_INSN(),
4024 },
4025 INTERNAL,
4026 { },
4027 { { 0, 1 } },
4028 },
4029 /* BPF_JMP | BPF_JSGT | BPF_K */
4030 {
4031 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4032 .u.insns_int = {
4033 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4034 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4035 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4036 BPF_EXIT_INSN(),
4037 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4038 BPF_EXIT_INSN(),
4039 },
4040 INTERNAL,
4041 { },
4042 { { 0, 1 } },
4043 },
4044 {
4045 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4046 .u.insns_int = {
4047 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4048 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4049 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4050 BPF_EXIT_INSN(),
4051 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4052 BPF_EXIT_INSN(),
4053 },
4054 INTERNAL,
4055 { },
4056 { { 0, 1 } },
4057 },
4058 /* BPF_JMP | BPF_JSGE | BPF_K */
4059 {
4060 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4061 .u.insns_int = {
4062 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4063 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4064 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4065 BPF_EXIT_INSN(),
4066 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4067 BPF_EXIT_INSN(),
4068 },
4069 INTERNAL,
4070 { },
4071 { { 0, 1 } },
4072 },
4073 {
4074 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4075 .u.insns_int = {
4076 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4077 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4078 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4079 BPF_EXIT_INSN(),
4080 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4081 BPF_EXIT_INSN(),
4082 },
4083 INTERNAL,
4084 { },
4085 { { 0, 1 } },
4086 },
4087 /* BPF_JMP | BPF_JGT | BPF_K */
4088 {
4089 "JMP_JGT_K: if (3 > 2) return 1",
4090 .u.insns_int = {
4091 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4092 BPF_LD_IMM64(R1, 3),
4093 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4094 BPF_EXIT_INSN(),
4095 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4096 BPF_EXIT_INSN(),
4097 },
4098 INTERNAL,
4099 { },
4100 { { 0, 1 } },
4101 },
4102 /* BPF_JMP | BPF_JGE | BPF_K */
4103 {
4104 "JMP_JGE_K: if (3 >= 2) return 1",
4105 .u.insns_int = {
4106 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4107 BPF_LD_IMM64(R1, 3),
4108 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4109 BPF_EXIT_INSN(),
4110 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4111 BPF_EXIT_INSN(),
4112 },
4113 INTERNAL,
4114 { },
4115 { { 0, 1 } },
4116 },
Michael Holzheufe593842015-05-22 08:36:40 -07004117 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4118 {
4119 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4120 .u.insns_int = {
4121 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4122 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4123 BPF_EXIT_INSN(),
4124 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4125 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4126 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4127 BPF_EXIT_INSN(),
4128 },
4129 INTERNAL,
4130 { },
4131 { { 0, 1 } },
4132 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004133 {
4134 "JMP_JGE_K: if (3 >= 3) return 1",
4135 .u.insns_int = {
4136 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4137 BPF_LD_IMM64(R1, 3),
4138 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4139 BPF_EXIT_INSN(),
4140 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4141 BPF_EXIT_INSN(),
4142 },
4143 INTERNAL,
4144 { },
4145 { { 0, 1 } },
4146 },
4147 /* BPF_JMP | BPF_JNE | BPF_K */
4148 {
4149 "JMP_JNE_K: if (3 != 2) return 1",
4150 .u.insns_int = {
4151 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4152 BPF_LD_IMM64(R1, 3),
4153 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4154 BPF_EXIT_INSN(),
4155 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4156 BPF_EXIT_INSN(),
4157 },
4158 INTERNAL,
4159 { },
4160 { { 0, 1 } },
4161 },
4162 /* BPF_JMP | BPF_JEQ | BPF_K */
4163 {
4164 "JMP_JEQ_K: if (3 == 3) return 1",
4165 .u.insns_int = {
4166 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4167 BPF_LD_IMM64(R1, 3),
4168 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4169 BPF_EXIT_INSN(),
4170 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4171 BPF_EXIT_INSN(),
4172 },
4173 INTERNAL,
4174 { },
4175 { { 0, 1 } },
4176 },
4177 /* BPF_JMP | BPF_JSET | BPF_K */
4178 {
4179 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4180 .u.insns_int = {
4181 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4182 BPF_LD_IMM64(R1, 3),
4183 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4184 BPF_EXIT_INSN(),
4185 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4186 BPF_EXIT_INSN(),
4187 },
4188 INTERNAL,
4189 { },
4190 { { 0, 1 } },
4191 },
4192 {
4193 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4194 .u.insns_int = {
4195 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4196 BPF_LD_IMM64(R1, 3),
4197 BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1),
4198 BPF_EXIT_INSN(),
4199 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4200 BPF_EXIT_INSN(),
4201 },
4202 INTERNAL,
4203 { },
4204 { { 0, 1 } },
4205 },
4206 /* BPF_JMP | BPF_JSGT | BPF_X */
4207 {
4208 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4209 .u.insns_int = {
4210 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4211 BPF_LD_IMM64(R1, -1),
4212 BPF_LD_IMM64(R2, -2),
4213 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4214 BPF_EXIT_INSN(),
4215 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4216 BPF_EXIT_INSN(),
4217 },
4218 INTERNAL,
4219 { },
4220 { { 0, 1 } },
4221 },
4222 {
4223 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4224 .u.insns_int = {
4225 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4226 BPF_LD_IMM64(R1, -1),
4227 BPF_LD_IMM64(R2, -1),
4228 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4229 BPF_EXIT_INSN(),
4230 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4231 BPF_EXIT_INSN(),
4232 },
4233 INTERNAL,
4234 { },
4235 { { 0, 1 } },
4236 },
4237 /* BPF_JMP | BPF_JSGE | BPF_X */
4238 {
4239 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4240 .u.insns_int = {
4241 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4242 BPF_LD_IMM64(R1, -1),
4243 BPF_LD_IMM64(R2, -2),
4244 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4245 BPF_EXIT_INSN(),
4246 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4247 BPF_EXIT_INSN(),
4248 },
4249 INTERNAL,
4250 { },
4251 { { 0, 1 } },
4252 },
4253 {
4254 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4255 .u.insns_int = {
4256 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4257 BPF_LD_IMM64(R1, -1),
4258 BPF_LD_IMM64(R2, -1),
4259 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4260 BPF_EXIT_INSN(),
4261 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4262 BPF_EXIT_INSN(),
4263 },
4264 INTERNAL,
4265 { },
4266 { { 0, 1 } },
4267 },
4268 /* BPF_JMP | BPF_JGT | BPF_X */
4269 {
4270 "JMP_JGT_X: if (3 > 2) return 1",
4271 .u.insns_int = {
4272 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4273 BPF_LD_IMM64(R1, 3),
4274 BPF_LD_IMM64(R2, 2),
4275 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4276 BPF_EXIT_INSN(),
4277 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4278 BPF_EXIT_INSN(),
4279 },
4280 INTERNAL,
4281 { },
4282 { { 0, 1 } },
4283 },
4284 /* BPF_JMP | BPF_JGE | BPF_X */
4285 {
4286 "JMP_JGE_X: if (3 >= 2) return 1",
4287 .u.insns_int = {
4288 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4289 BPF_LD_IMM64(R1, 3),
4290 BPF_LD_IMM64(R2, 2),
4291 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4292 BPF_EXIT_INSN(),
4293 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4294 BPF_EXIT_INSN(),
4295 },
4296 INTERNAL,
4297 { },
4298 { { 0, 1 } },
4299 },
4300 {
4301 "JMP_JGE_X: if (3 >= 3) return 1",
4302 .u.insns_int = {
4303 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4304 BPF_LD_IMM64(R1, 3),
4305 BPF_LD_IMM64(R2, 3),
4306 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4307 BPF_EXIT_INSN(),
4308 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4309 BPF_EXIT_INSN(),
4310 },
4311 INTERNAL,
4312 { },
4313 { { 0, 1 } },
4314 },
4315 /* BPF_JMP | BPF_JNE | BPF_X */
4316 {
4317 "JMP_JNE_X: if (3 != 2) return 1",
4318 .u.insns_int = {
4319 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4320 BPF_LD_IMM64(R1, 3),
4321 BPF_LD_IMM64(R2, 2),
4322 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4323 BPF_EXIT_INSN(),
4324 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4325 BPF_EXIT_INSN(),
4326 },
4327 INTERNAL,
4328 { },
4329 { { 0, 1 } },
4330 },
4331 /* BPF_JMP | BPF_JEQ | BPF_X */
4332 {
4333 "JMP_JEQ_X: if (3 == 3) return 1",
4334 .u.insns_int = {
4335 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4336 BPF_LD_IMM64(R1, 3),
4337 BPF_LD_IMM64(R2, 3),
4338 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4339 BPF_EXIT_INSN(),
4340 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4341 BPF_EXIT_INSN(),
4342 },
4343 INTERNAL,
4344 { },
4345 { { 0, 1 } },
4346 },
4347 /* BPF_JMP | BPF_JSET | BPF_X */
4348 {
4349 "JMP_JSET_X: if (0x3 & 0x2) return 1",
4350 .u.insns_int = {
4351 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4352 BPF_LD_IMM64(R1, 3),
4353 BPF_LD_IMM64(R2, 2),
4354 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4355 BPF_EXIT_INSN(),
4356 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4357 BPF_EXIT_INSN(),
4358 },
4359 INTERNAL,
4360 { },
4361 { { 0, 1 } },
4362 },
4363 {
4364 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
4365 .u.insns_int = {
4366 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4367 BPF_LD_IMM64(R1, 3),
4368 BPF_LD_IMM64(R2, 0xffffffff),
4369 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4370 BPF_EXIT_INSN(),
4371 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4372 BPF_EXIT_INSN(),
4373 },
4374 INTERNAL,
4375 { },
4376 { { 0, 1 } },
4377 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02004378 {
4379 "JMP_JA: Jump, gap, jump, ...",
4380 { },
4381 CLASSIC | FLAG_NO_DATA,
4382 { },
4383 { { 0, 0xababcbac } },
4384 .fill_helper = bpf_fill_ja,
4385 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004386 { /* Mainly checking JIT here. */
4387 "BPF_MAXINSNS: Maximum possible literals",
4388 { },
4389 CLASSIC | FLAG_NO_DATA,
4390 { },
4391 { { 0, 0xffffffff } },
4392 .fill_helper = bpf_fill_maxinsns1,
4393 },
4394 { /* Mainly checking JIT here. */
4395 "BPF_MAXINSNS: Single literal",
4396 { },
4397 CLASSIC | FLAG_NO_DATA,
4398 { },
4399 { { 0, 0xfefefefe } },
4400 .fill_helper = bpf_fill_maxinsns2,
4401 },
4402 { /* Mainly checking JIT here. */
4403 "BPF_MAXINSNS: Run/add until end",
4404 { },
4405 CLASSIC | FLAG_NO_DATA,
4406 { },
4407 { { 0, 0x947bf368 } },
4408 .fill_helper = bpf_fill_maxinsns3,
4409 },
4410 {
4411 "BPF_MAXINSNS: Too many instructions",
4412 { },
4413 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4414 { },
4415 { },
4416 .fill_helper = bpf_fill_maxinsns4,
4417 },
4418 { /* Mainly checking JIT here. */
4419 "BPF_MAXINSNS: Very long jump",
4420 { },
4421 CLASSIC | FLAG_NO_DATA,
4422 { },
4423 { { 0, 0xabababab } },
4424 .fill_helper = bpf_fill_maxinsns5,
4425 },
4426 { /* Mainly checking JIT here. */
4427 "BPF_MAXINSNS: Ctx heavy transformations",
4428 { },
4429 CLASSIC,
4430 { },
4431 {
4432 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
4433 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
4434 },
4435 .fill_helper = bpf_fill_maxinsns6,
4436 },
4437 { /* Mainly checking JIT here. */
4438 "BPF_MAXINSNS: Call heavy transformations",
4439 { },
4440 CLASSIC | FLAG_NO_DATA,
4441 { },
4442 { { 1, 0 }, { 10, 0 } },
4443 .fill_helper = bpf_fill_maxinsns7,
4444 },
4445 { /* Mainly checking JIT here. */
4446 "BPF_MAXINSNS: Jump heavy test",
4447 { },
4448 CLASSIC | FLAG_NO_DATA,
4449 { },
4450 { { 0, 0xffffffff } },
4451 .fill_helper = bpf_fill_maxinsns8,
4452 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02004453 { /* Mainly checking JIT here. */
4454 "BPF_MAXINSNS: Very long jump backwards",
4455 { },
4456 INTERNAL | FLAG_NO_DATA,
4457 { },
4458 { { 0, 0xcbababab } },
4459 .fill_helper = bpf_fill_maxinsns9,
4460 },
4461 { /* Mainly checking JIT here. */
4462 "BPF_MAXINSNS: Edge hopping nuthouse",
4463 { },
4464 INTERNAL | FLAG_NO_DATA,
4465 { },
4466 { { 0, 0xabababac } },
4467 .fill_helper = bpf_fill_maxinsns10,
4468 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02004469 {
4470 "BPF_MAXINSNS: Jump, gap, jump, ...",
4471 { },
4472 CLASSIC | FLAG_NO_DATA,
4473 { },
4474 { { 0, 0xababcbac } },
4475 .fill_helper = bpf_fill_maxinsns11,
4476 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07004477 {
4478 "BPF_MAXINSNS: ld_abs+get_processor_id",
4479 { },
4480 CLASSIC,
4481 { },
4482 { { 1, 0xbee } },
4483 .fill_helper = bpf_fill_ld_abs_get_processor_id,
4484 },
4485 {
4486 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
4487 { },
4488 INTERNAL,
4489 { 0x34 },
4490 { { 1, 0xbef } },
4491 .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
4492 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004493};
4494
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004495static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004496
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004497static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004498{
4499 struct sk_buff *skb;
4500
4501 if (size >= MAX_DATA)
4502 return NULL;
4503
4504 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
4505 if (!skb)
4506 return NULL;
4507
4508 memcpy(__skb_put(skb, size), buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004509
4510 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004511 skb_reset_mac_header(skb);
4512 skb->protocol = htons(ETH_P_IP);
4513 skb->pkt_type = SKB_TYPE;
4514 skb->mark = SKB_MARK;
4515 skb->hash = SKB_HASH;
4516 skb->queue_mapping = SKB_QUEUE_MAP;
4517 skb->vlan_tci = SKB_VLAN_TCI;
4518 skb->dev = &dev;
4519 skb->dev->ifindex = SKB_DEV_IFINDEX;
4520 skb->dev->type = SKB_DEV_TYPE;
4521 skb_set_network_header(skb, min(size, ETH_HLEN));
4522
4523 return skb;
4524}
4525
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004526static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004527{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004528 if (test->aux & FLAG_NO_DATA)
4529 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004530
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004531 /* Test case expects an skb, so populate one. Various
4532 * subtests generate skbs of different sizes based on
4533 * the same data.
4534 */
4535 return populate_skb(test->data, test->test[sub].data_size);
4536}
4537
4538static void release_test_data(const struct bpf_test *test, void *data)
4539{
4540 if (test->aux & FLAG_NO_DATA)
4541 return;
4542
4543 kfree_skb(data);
4544}
4545
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004546static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004547{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004548 struct sock_filter *fp;
4549 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004550
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004551 if (tests[which].fill_helper)
4552 return tests[which].u.ptr.len;
4553
4554 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07004555 for (len = MAX_INSNS - 1; len > 0; --len)
4556 if (fp[len].code != 0 || fp[len].k != 0)
4557 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004558
Chema Gonzaleze9d94502014-05-30 10:15:12 -07004559 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004560}
4561
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004562static void *filter_pointer(int which)
4563{
4564 if (tests[which].fill_helper)
4565 return tests[which].u.ptr.insns;
4566 else
4567 return tests[which].u.insns;
4568}
4569
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004570static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004571{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004572 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004573 unsigned int flen = filter_length(which);
4574 void *fptr = filter_pointer(which);
4575 struct sock_fprog_kern fprog;
4576 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004577
4578 switch (test_type) {
4579 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004580 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004581 fprog.len = flen;
4582
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004583 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004584 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
4585 if (*err == -EINVAL) {
4586 pr_cont("PASS\n");
4587 /* Verifier rejected filter as expected. */
4588 *err = 0;
4589 return NULL;
4590 } else {
4591 pr_cont("UNEXPECTED_PASS\n");
4592 /* Verifier didn't reject the test that's
4593 * bad enough, just return!
4594 */
4595 *err = -EINVAL;
4596 return NULL;
4597 }
4598 }
4599 /* We don't expect to fail. */
4600 if (*err) {
4601 pr_cont("FAIL to attach err=%d len=%d\n",
4602 *err, fprog.len);
4603 return NULL;
4604 }
4605 break;
4606
4607 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02004608 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004609 if (fp == NULL) {
4610 pr_cont("UNEXPECTED_FAIL no memory left\n");
4611 *err = -ENOMEM;
4612 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004613 }
4614
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004615 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02004616 /* Type doesn't really matter here as long as it's not unspec. */
4617 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004618 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004619
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004620 bpf_prog_select_runtime(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004621 break;
4622 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004623
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004624 *err = 0;
4625 return fp;
4626}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004627
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004628static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004629{
4630 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004631
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004632 switch (test_type) {
4633 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004634 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004635 break;
4636 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004637 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004638 break;
4639 }
4640}
4641
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004642static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004643 int runs, u64 *duration)
4644{
4645 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07004646 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004647
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07004648 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004649
4650 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004651 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004652
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07004653 finish = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004654
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07004655 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004656 do_div(*duration, runs);
4657
4658 return ret;
4659}
4660
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004661static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004662{
4663 int err_cnt = 0, i, runs = MAX_TESTRUNS;
4664
4665 for (i = 0; i < MAX_SUBTESTS; i++) {
4666 void *data;
4667 u64 duration;
4668 u32 ret;
4669
4670 if (test->test[i].data_size == 0 &&
4671 test->test[i].result == 0)
4672 break;
4673
4674 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02004675 if (!data && !(test->aux & FLAG_NO_DATA)) {
4676 pr_cont("data generation failed ");
4677 err_cnt++;
4678 break;
4679 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004680 ret = __run_one(fp, data, runs, &duration);
4681 release_test_data(test, data);
4682
4683 if (ret == test->test[i].result) {
4684 pr_cont("%lld ", duration);
4685 } else {
4686 pr_cont("ret %d != %d ", ret,
4687 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004688 err_cnt++;
4689 }
4690 }
4691
4692 return err_cnt;
4693}
4694
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004695static __init int prepare_bpf_tests(void)
4696{
4697 int i;
4698
4699 for (i = 0; i < ARRAY_SIZE(tests); i++) {
4700 if (tests[i].fill_helper &&
4701 tests[i].fill_helper(&tests[i]) < 0)
4702 return -ENOMEM;
4703 }
4704
4705 return 0;
4706}
4707
4708static __init void destroy_bpf_tests(void)
4709{
4710 int i;
4711
4712 for (i = 0; i < ARRAY_SIZE(tests); i++) {
4713 if (tests[i].fill_helper)
4714 kfree(tests[i].u.ptr.insns);
4715 }
4716}
4717
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004718static __init int test_bpf(void)
4719{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004720 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02004721 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004722
4723 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004724 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004725 int err;
4726
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004727 pr_info("#%d %s ", i, tests[i].descr);
4728
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004729 fp = generate_filter(i, &err);
4730 if (fp == NULL) {
4731 if (err == 0) {
4732 pass_cnt++;
4733 continue;
4734 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004735
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004736 return err;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004737 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02004738
4739 pr_cont("jited:%u ", fp->jited);
4740
4741 run_cnt++;
4742 if (fp->jited)
4743 jit_cnt++;
4744
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004745 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004746 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004747
4748 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004749 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004750 err_cnt++;
4751 } else {
4752 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004753 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004754 }
4755 }
4756
Daniel Borkmann327941f2015-04-30 16:17:27 +02004757 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
4758 pass_cnt, err_cnt, jit_cnt, run_cnt);
4759
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004760 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004761}
4762
4763static int __init test_bpf_init(void)
4764{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02004765 int ret;
4766
4767 ret = prepare_bpf_tests();
4768 if (ret < 0)
4769 return ret;
4770
4771 ret = test_bpf();
4772
4773 destroy_bpf_tests();
4774 return ret;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004775}
4776
4777static void __exit test_bpf_exit(void)
4778{
4779}
4780
4781module_init(test_bpf_init);
4782module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004783
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004784MODULE_LICENSE("GPL");