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