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