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