blob: 402c199cc119d0882bb5988fe4973a981ea50164 [file] [log] [blame]
Thomas Gleixner5b497af2019-05-29 07:18:09 -07001// SPDX-License-Identifier: GPL-2.0-only
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002/*
3 * Testsuite for BPF interpreter and BPF JIT compiler
4 *
5 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/filter.h>
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -070013#include <linux/bpf.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070014#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16#include <linux/if_vlan.h>
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020017#include <linux/random.h>
Nicolas Schichanbac142a2015-08-04 15:19:08 +020018#include <linux/highmem.h>
Eric Dumazetd40bc962018-02-26 10:52:46 -080019#include <linux/sched.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070020
Daniel Borkmann10f18e02014-05-23 18:44:00 +020021/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070022#define MAX_SUBTESTS 3
Eric Dumazet9960d762018-02-28 08:39:20 -080023#define MAX_TESTRUNS 1000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070024#define MAX_DATA 128
25#define MAX_INSNS 512
26#define MAX_K 0xffffFFFF
27
Daniel Borkmann10f18e02014-05-23 18:44:00 +020028/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070029#define SKB_TYPE 3
30#define SKB_MARK 0x1234aaaa
31#define SKB_HASH 0x1234aaab
32#define SKB_QUEUE_MAP 123
33#define SKB_VLAN_TCI 0xffff
Michał Mirosław0c4b2d32018-11-10 19:58:36 +010034#define SKB_VLAN_PRESENT 1
Alexei Starovoitov64a89462014-05-08 14:10:52 -070035#define SKB_DEV_IFINDEX 577
36#define SKB_DEV_TYPE 588
37
Daniel Borkmann10f18e02014-05-23 18:44:00 +020038/* Redefine REGs to make tests less verbose */
39#define R0 BPF_REG_0
40#define R1 BPF_REG_1
41#define R2 BPF_REG_2
42#define R3 BPF_REG_3
43#define R4 BPF_REG_4
44#define R5 BPF_REG_5
45#define R6 BPF_REG_6
46#define R7 BPF_REG_7
47#define R8 BPF_REG_8
48#define R9 BPF_REG_9
49#define R10 BPF_REG_10
50
51/* Flags that can be passed to test cases */
52#define FLAG_NO_DATA BIT(0)
53#define FLAG_EXPECTED_FAIL BIT(1)
Nicolas Schichanbac142a2015-08-04 15:19:08 +020054#define FLAG_SKB_FRAG BIT(2)
Daniel Borkmann10f18e02014-05-23 18:44:00 +020055
56enum {
57 CLASSIC = BIT(6), /* Old BPF instructions only. */
58 INTERNAL = BIT(7), /* Extended instruction set. */
59};
60
61#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070062
63struct bpf_test {
64 const char *descr;
65 union {
66 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070067 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020068 struct {
69 void *insns;
70 unsigned int len;
71 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070072 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020073 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070074 __u8 data[MAX_DATA];
75 struct {
76 int data_size;
77 __u32 result;
78 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020079 int (*fill_helper)(struct bpf_test *self);
Yonghong Song09584b42018-02-02 22:37:15 -080080 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
Nicolas Schichanbac142a2015-08-04 15:19:08 +020081 __u8 frag_data[MAX_DATA];
Alexei Starovoitov105c0362017-05-30 13:31:32 -070082 int stack_depth; /* for eBPF only, since tests don't call verifier */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070083};
84
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020085/* Large test cases need separate allocation and fill handler. */
86
87static int bpf_fill_maxinsns1(struct bpf_test *self)
88{
89 unsigned int len = BPF_MAXINSNS;
90 struct sock_filter *insn;
91 __u32 k = ~0;
92 int i;
93
94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
95 if (!insn)
96 return -ENOMEM;
97
98 for (i = 0; i < len; i++, k--)
99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
100
101 self->u.ptr.insns = insn;
102 self->u.ptr.len = len;
103
104 return 0;
105}
106
107static int bpf_fill_maxinsns2(struct bpf_test *self)
108{
109 unsigned int len = BPF_MAXINSNS;
110 struct sock_filter *insn;
111 int i;
112
113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
114 if (!insn)
115 return -ENOMEM;
116
117 for (i = 0; i < len; i++)
118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
119
120 self->u.ptr.insns = insn;
121 self->u.ptr.len = len;
122
123 return 0;
124}
125
126static int bpf_fill_maxinsns3(struct bpf_test *self)
127{
128 unsigned int len = BPF_MAXINSNS;
129 struct sock_filter *insn;
130 struct rnd_state rnd;
131 int i;
132
133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
134 if (!insn)
135 return -ENOMEM;
136
137 prandom_seed_state(&rnd, 3141592653589793238ULL);
138
139 for (i = 0; i < len - 1; i++) {
140 __u32 k = prandom_u32_state(&rnd);
141
142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
143 }
144
145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
146
147 self->u.ptr.insns = insn;
148 self->u.ptr.len = len;
149
150 return 0;
151}
152
153static int bpf_fill_maxinsns4(struct bpf_test *self)
154{
155 unsigned int len = BPF_MAXINSNS + 1;
156 struct sock_filter *insn;
157 int i;
158
159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
160 if (!insn)
161 return -ENOMEM;
162
163 for (i = 0; i < len; i++)
164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
165
166 self->u.ptr.insns = insn;
167 self->u.ptr.len = len;
168
169 return 0;
170}
171
172static int bpf_fill_maxinsns5(struct bpf_test *self)
173{
174 unsigned int len = BPF_MAXINSNS;
175 struct sock_filter *insn;
176 int i;
177
178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
179 if (!insn)
180 return -ENOMEM;
181
182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
183
184 for (i = 1; i < len - 1; i++)
185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
186
187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
188
189 self->u.ptr.insns = insn;
190 self->u.ptr.len = len;
191
192 return 0;
193}
194
195static int bpf_fill_maxinsns6(struct bpf_test *self)
196{
197 unsigned int len = BPF_MAXINSNS;
198 struct sock_filter *insn;
199 int i;
200
201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
202 if (!insn)
203 return -ENOMEM;
204
205 for (i = 0; i < len - 1; i++)
206 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
207 SKF_AD_VLAN_TAG_PRESENT);
208
209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
210
211 self->u.ptr.insns = insn;
212 self->u.ptr.len = len;
213
214 return 0;
215}
216
217static int bpf_fill_maxinsns7(struct bpf_test *self)
218{
219 unsigned int len = BPF_MAXINSNS;
220 struct sock_filter *insn;
221 int i;
222
223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
224 if (!insn)
225 return -ENOMEM;
226
227 for (i = 0; i < len - 4; i++)
228 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
229 SKF_AD_CPU);
230
231 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
232 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
233 SKF_AD_CPU);
234 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
235 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
236
237 self->u.ptr.insns = insn;
238 self->u.ptr.len = len;
239
240 return 0;
241}
242
243static int bpf_fill_maxinsns8(struct bpf_test *self)
244{
245 unsigned int len = BPF_MAXINSNS;
246 struct sock_filter *insn;
247 int i, jmp_off = len - 3;
248
249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
250 if (!insn)
251 return -ENOMEM;
252
253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
254
255 for (i = 1; i < len - 1; i++)
256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
257
258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
259
260 self->u.ptr.insns = insn;
261 self->u.ptr.len = len;
262
263 return 0;
264}
265
Daniel Borkmann3b529602015-05-23 01:10:07 +0200266static int bpf_fill_maxinsns9(struct bpf_test *self)
267{
268 unsigned int len = BPF_MAXINSNS;
269 struct bpf_insn *insn;
270 int i;
271
272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
273 if (!insn)
274 return -ENOMEM;
275
276 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
277 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
278 insn[2] = BPF_EXIT_INSN();
279
280 for (i = 3; i < len - 2; i++)
281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
282
283 insn[len - 2] = BPF_EXIT_INSN();
284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
285
286 self->u.ptr.insns = insn;
287 self->u.ptr.len = len;
288
289 return 0;
290}
291
292static int bpf_fill_maxinsns10(struct bpf_test *self)
293{
294 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
295 struct bpf_insn *insn;
296 int i;
297
298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
299 if (!insn)
300 return -ENOMEM;
301
302 for (i = 0; i < hlen / 2; i++)
303 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
304 for (i = hlen - 1; i > hlen / 2; i--)
305 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
306
307 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
308 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
309 insn[hlen + 1] = BPF_EXIT_INSN();
310
311 self->u.ptr.insns = insn;
312 self->u.ptr.len = len;
313
314 return 0;
315}
316
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200317static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
318 unsigned int plen)
319{
320 struct sock_filter *insn;
321 unsigned int rlen;
322 int i, j;
323
324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
325 if (!insn)
326 return -ENOMEM;
327
328 rlen = (len % plen) - 1;
329
330 for (i = 0; i + plen < len; i += plen)
331 for (j = 0; j < plen; j++)
332 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
333 plen - 1 - j, 0, 0);
334 for (j = 0; j < rlen; j++)
335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
336 0, 0);
337
338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
339
340 self->u.ptr.insns = insn;
341 self->u.ptr.len = len;
342
343 return 0;
344}
345
346static int bpf_fill_maxinsns11(struct bpf_test *self)
347{
Gary Lin16a660e2021-01-19 18:25:00 +0800348 /* Hits 70 passes on x86_64 and triggers NOPs padding. */
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
350}
351
Daniel Borkmannbe088152018-06-02 23:06:32 +0200352static int bpf_fill_maxinsns12(struct bpf_test *self)
353{
354 unsigned int len = BPF_MAXINSNS;
355 struct sock_filter *insn;
356 int i = 0;
357
358 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
359 if (!insn)
360 return -ENOMEM;
361
362 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
363
364 for (i = 1; i < len - 1; i++)
365 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
366
367 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
368
369 self->u.ptr.insns = insn;
370 self->u.ptr.len = len;
371
372 return 0;
373}
374
375static int bpf_fill_maxinsns13(struct bpf_test *self)
376{
377 unsigned int len = BPF_MAXINSNS;
378 struct sock_filter *insn;
379 int i = 0;
380
381 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
382 if (!insn)
383 return -ENOMEM;
384
385 for (i = 0; i < len - 3; i++)
386 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
387
388 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
389 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
390 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
391
392 self->u.ptr.insns = insn;
393 self->u.ptr.len = len;
394
395 return 0;
396}
397
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200398static int bpf_fill_ja(struct bpf_test *self)
399{
400 /* Hits exactly 11 passes on x86_64 JIT. */
401 return __bpf_fill_ja(self, 12, 9);
402}
403
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700404static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
405{
406 unsigned int len = BPF_MAXINSNS;
407 struct sock_filter *insn;
408 int i;
409
410 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
411 if (!insn)
412 return -ENOMEM;
413
414 for (i = 0; i < len - 1; i += 2) {
415 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
416 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
417 SKF_AD_OFF + SKF_AD_CPU);
418 }
419
420 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
421
422 self->u.ptr.insns = insn;
423 self->u.ptr.len = len;
424
425 return 0;
426}
427
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200428static int __bpf_fill_stxdw(struct bpf_test *self, int size)
429{
430 unsigned int len = BPF_MAXINSNS;
431 struct bpf_insn *insn;
432 int i;
433
434 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
435 if (!insn)
436 return -ENOMEM;
437
438 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
439 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
440
441 for (i = 2; i < len - 2; i++)
442 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
443
444 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
445 insn[len - 1] = BPF_EXIT_INSN();
446
447 self->u.ptr.insns = insn;
448 self->u.ptr.len = len;
Alexei Starovoitov105c0362017-05-30 13:31:32 -0700449 self->stack_depth = 40;
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200450
451 return 0;
452}
453
454static int bpf_fill_stxw(struct bpf_test *self)
455{
456 return __bpf_fill_stxdw(self, BPF_W);
457}
458
459static int bpf_fill_stxdw(struct bpf_test *self)
460{
461 return __bpf_fill_stxdw(self, BPF_DW);
462}
463
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700464static struct bpf_test tests[] = {
465 {
466 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700467 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700468 BPF_STMT(BPF_LD | BPF_IMM, 1),
469 BPF_STMT(BPF_MISC | BPF_TAX, 0),
470 BPF_STMT(BPF_LD | BPF_IMM, 2),
471 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
472 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
473 BPF_STMT(BPF_MISC | BPF_TAX, 0),
474 BPF_STMT(BPF_LD | BPF_LEN, 0),
475 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
476 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
477 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
478 BPF_STMT(BPF_RET | BPF_A, 0)
479 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200480 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700481 { 10, 20, 30, 40, 50 },
482 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
483 },
484 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700485 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700486 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700487 BPF_STMT(BPF_LDX | BPF_LEN, 0),
488 BPF_STMT(BPF_MISC | BPF_TXA, 0),
489 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
490 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
491 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200492 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700493 { 10, 20, 30, 40, 50 },
494 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
495 },
496 {
497 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700498 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700499 BPF_STMT(BPF_LD | BPF_IMM, 1),
500 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
501 BPF_STMT(BPF_LDX | BPF_IMM, 3),
502 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
503 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
504 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
505 BPF_STMT(BPF_RET | BPF_A, 0)
506 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200507 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700508 { },
509 { { 0, 0xfffffffd } }
510 },
511 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300512 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700513 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700514 BPF_STMT(BPF_LD | BPF_IMM, 8),
515 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
516 BPF_STMT(BPF_MISC | BPF_TAX, 0),
517 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
518 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
519 BPF_STMT(BPF_MISC | BPF_TAX, 0),
520 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
521 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300522 BPF_STMT(BPF_MISC | BPF_TAX, 0),
523 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
524 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
525 BPF_STMT(BPF_MISC | BPF_TAX, 0),
526 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
527 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700528 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
529 BPF_STMT(BPF_RET | BPF_A, 0)
530 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200531 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700532 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300533 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700534 },
535 {
536 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700537 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700538 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
539 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
540 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
541 BPF_STMT(BPF_MISC | BPF_TAX, 0),
542 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
543 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
544 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
545 BPF_STMT(BPF_RET | BPF_A, 0)
546 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200547 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700548 { },
549 { { 0, 0x800000ff }, { 1, 0x800000ff } },
550 },
551 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700552 "LD_IMM_0",
553 .u.insns = {
554 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
555 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
556 BPF_STMT(BPF_RET | BPF_K, 0),
557 BPF_STMT(BPF_RET | BPF_K, 1),
558 },
559 CLASSIC,
560 { },
561 { { 1, 1 } },
562 },
563 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700564 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700565 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700566 BPF_STMT(BPF_LDX | BPF_LEN, 0),
567 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
568 BPF_STMT(BPF_RET | BPF_K, 1)
569 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200570 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700571 { },
572 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
573 },
574 {
575 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700576 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700577 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
578 BPF_STMT(BPF_RET | BPF_K, 1)
579 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200580 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700581 { },
582 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
583 },
584 {
585 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700586 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700587 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
590 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
591 BPF_STMT(BPF_RET | BPF_A, 0)
592 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200593 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700594 { 1, 2, 3 },
595 { { 1, 0 }, { 2, 3 } },
596 },
597 {
598 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700599 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700600 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
603 BPF_STMT(BPF_MISC | BPF_TAX, 0),
604 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
605 BPF_STMT(BPF_RET | BPF_A, 0)
606 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200607 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700608 { 1, 2, 3, 0xff },
609 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
610 },
611 {
612 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700613 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700614 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
615 BPF_STMT(BPF_MISC | BPF_TAX, 0),
616 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
617 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
618 BPF_STMT(BPF_RET | BPF_A, 0)
619 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200620 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700621 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
622 { { 15, 0 }, { 16, 3 } },
623 },
624 {
625 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700626 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700627 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
628 BPF_STMT(BPF_LDX | BPF_LEN, 0),
629 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
630 BPF_STMT(BPF_MISC | BPF_TAX, 0),
631 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
632 BPF_STMT(BPF_RET | BPF_A, 0)
633 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200634 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700635 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
636 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
637 },
638 {
639 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700640 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700641 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
642 SKF_AD_OFF + SKF_AD_PKTTYPE),
643 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
644 BPF_STMT(BPF_RET | BPF_K, 1),
645 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
646 SKF_AD_OFF + SKF_AD_PKTTYPE),
647 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
648 BPF_STMT(BPF_RET | BPF_K, 1),
649 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
650 SKF_AD_OFF + SKF_AD_PKTTYPE),
651 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
652 BPF_STMT(BPF_RET | BPF_K, 1),
653 BPF_STMT(BPF_RET | BPF_A, 0)
654 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200655 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700656 { },
657 { { 1, 3 }, { 10, 3 } },
658 },
659 {
660 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700661 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700662 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
663 SKF_AD_OFF + SKF_AD_MARK),
664 BPF_STMT(BPF_RET | BPF_A, 0)
665 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200666 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700667 { },
668 { { 1, SKB_MARK}, { 10, SKB_MARK} },
669 },
670 {
671 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700672 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700673 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
674 SKF_AD_OFF + SKF_AD_RXHASH),
675 BPF_STMT(BPF_RET | BPF_A, 0)
676 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200677 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700678 { },
679 { { 1, SKB_HASH}, { 10, SKB_HASH} },
680 },
681 {
682 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700683 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_QUEUE),
686 BPF_STMT(BPF_RET | BPF_A, 0)
687 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200688 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700689 { },
690 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
691 },
692 {
693 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700694 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700695 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
696 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
697 BPF_STMT(BPF_RET | BPF_K, 0),
698 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
699 SKF_AD_OFF + SKF_AD_PROTOCOL),
700 BPF_STMT(BPF_MISC | BPF_TAX, 0),
701 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
702 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
703 BPF_STMT(BPF_RET | BPF_K, 0),
704 BPF_STMT(BPF_MISC | BPF_TXA, 0),
705 BPF_STMT(BPF_RET | BPF_A, 0)
706 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200707 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700708 { 10, 20, 30 },
709 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
710 },
711 {
712 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700713 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
715 SKF_AD_OFF + SKF_AD_VLAN_TAG),
716 BPF_STMT(BPF_RET | BPF_A, 0)
717 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200718 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700719 { },
720 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100721 { 1, SKB_VLAN_TCI },
722 { 10, SKB_VLAN_TCI }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700723 },
724 },
725 {
726 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700727 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700728 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
729 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
730 BPF_STMT(BPF_RET | BPF_A, 0)
731 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200732 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700733 { },
734 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100735 { 1, SKB_VLAN_PRESENT },
736 { 10, SKB_VLAN_PRESENT }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700737 },
738 },
739 {
740 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700741 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700742 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
743 SKF_AD_OFF + SKF_AD_IFINDEX),
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, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
749 },
750 {
751 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700752 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700753 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
754 SKF_AD_OFF + SKF_AD_HATYPE),
755 BPF_STMT(BPF_RET | BPF_A, 0)
756 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200757 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700758 { },
759 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
760 },
761 {
762 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700763 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700764 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
765 SKF_AD_OFF + SKF_AD_CPU),
766 BPF_STMT(BPF_MISC | BPF_TAX, 0),
767 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
768 SKF_AD_OFF + SKF_AD_CPU),
769 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
770 BPF_STMT(BPF_RET | BPF_A, 0)
771 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200772 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700773 { },
774 { { 1, 0 }, { 10, 0 } },
775 },
776 {
777 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700778 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700779 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700780 BPF_STMT(BPF_MISC | BPF_TXA, 0),
781 BPF_STMT(BPF_LDX | BPF_IMM, 3),
782 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
783 SKF_AD_OFF + SKF_AD_NLATTR),
784 BPF_STMT(BPF_RET | BPF_A, 0)
785 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200786 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700787#ifdef __BIG_ENDIAN
788 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
789#else
790 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
791#endif
792 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700793 },
794 {
795 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700796 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700797 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700798 BPF_STMT(BPF_LDX | BPF_IMM, 3),
799 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
800 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700801 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700802 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
803 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700804 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700805 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
806 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700807 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700808 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
809 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700810 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700813 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700814 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
815 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700816 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700819 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700820 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
821 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
822 BPF_STMT(BPF_RET | BPF_A, 0)
823 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200824 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700825#ifdef __BIG_ENDIAN
826 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
827#else
828 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
829#endif
830 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700831 },
832 {
833 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700834 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700835 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
836 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
839 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
840 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
841 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
842 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
843 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
844 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
845 BPF_STMT(BPF_RET | BPF_A, 0)
846 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200847 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700848 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
849 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
850 * id 9737, seq 1, length 64
851 */
852 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
853 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
854 0x08, 0x00,
855 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
856 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
857 { { 30, 0 }, { 100, 42 } },
858 },
859 {
860 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700861 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700862 BPF_STMT(BPF_LD | BPF_IMM, 10),
863 BPF_STMT(BPF_LDX | BPF_IMM, 300),
864 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
865 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
866 BPF_STMT(BPF_RET | BPF_A, 0)
867 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200868 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700869 { },
Nathan Chancellor09845432019-08-18 21:34:20 -0700870 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700871 },
872 {
873 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700874 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700875 BPF_STMT(BPF_LDX | BPF_LEN, 0),
876 BPF_STMT(BPF_LD | BPF_IMM, 2),
877 BPF_STMT(BPF_ALU | BPF_RSH, 1),
878 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
879 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
880 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
881 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
882 BPF_STMT(BPF_STX, 15), /* M3 = len */
883 BPF_STMT(BPF_LDX | BPF_MEM, 1),
884 BPF_STMT(BPF_LD | BPF_MEM, 2),
885 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
886 BPF_STMT(BPF_LDX | BPF_MEM, 15),
887 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
888 BPF_STMT(BPF_RET | BPF_A, 0)
889 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200890 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700891 { },
892 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
893 },
894 {
895 "JEQ",
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_ABS, 2),
899 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
900 BPF_STMT(BPF_RET | BPF_K, 1),
901 BPF_STMT(BPF_RET | BPF_K, MAX_K)
902 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200903 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700904 { 3, 3, 3, 3, 3 },
905 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
906 },
907 {
908 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700909 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700910 BPF_STMT(BPF_LDX | BPF_LEN, 0),
911 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
912 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
913 BPF_STMT(BPF_RET | BPF_K, 1),
914 BPF_STMT(BPF_RET | BPF_K, MAX_K)
915 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200916 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700917 { 4, 4, 4, 3, 3 },
918 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
919 },
920 {
Daniel Borkmann92b31a92017-08-10 01:39:55 +0200921 "JGE (jt 0), test 1",
922 .u.insns = {
923 BPF_STMT(BPF_LDX | BPF_LEN, 0),
924 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
925 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
926 BPF_STMT(BPF_RET | BPF_K, 1),
927 BPF_STMT(BPF_RET | BPF_K, MAX_K)
928 },
929 CLASSIC,
930 { 4, 4, 4, 3, 3 },
931 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
932 },
933 {
934 "JGE (jt 0), test 2",
935 .u.insns = {
936 BPF_STMT(BPF_LDX | BPF_LEN, 0),
937 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
938 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
939 BPF_STMT(BPF_RET | BPF_K, 1),
940 BPF_STMT(BPF_RET | BPF_K, MAX_K)
941 },
942 CLASSIC,
943 { 4, 4, 5, 3, 3 },
944 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
945 },
946 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700947 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700948 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700949 BPF_STMT(BPF_LDX | BPF_LEN, 0),
950 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
951 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
952 BPF_STMT(BPF_RET | BPF_K, 10),
953 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
954 BPF_STMT(BPF_RET | BPF_K, 20),
955 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
956 BPF_STMT(BPF_RET | BPF_K, 30),
957 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
958 BPF_STMT(BPF_RET | BPF_K, 40),
959 BPF_STMT(BPF_RET | BPF_K, MAX_K)
960 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200961 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700962 { 1, 2, 3, 4, 5 },
963 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
964 },
965 {
966 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700967 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700968 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
969 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
970 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
971 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
972 BPF_STMT(BPF_LDX | BPF_LEN, 0),
973 BPF_STMT(BPF_MISC | BPF_TXA, 0),
974 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
975 BPF_STMT(BPF_MISC | BPF_TAX, 0),
976 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
977 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
978 BPF_STMT(BPF_RET | BPF_K, 10),
979 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
980 BPF_STMT(BPF_RET | BPF_K, 20),
981 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
982 BPF_STMT(BPF_RET | BPF_K, 30),
983 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
984 BPF_STMT(BPF_RET | BPF_K, 30),
985 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
986 BPF_STMT(BPF_RET | BPF_K, 30),
987 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
988 BPF_STMT(BPF_RET | BPF_K, 30),
989 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
990 BPF_STMT(BPF_RET | BPF_K, 30),
991 BPF_STMT(BPF_RET | BPF_K, MAX_K)
992 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200993 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700994 { 0, 0xAA, 0x55, 1 },
995 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
996 },
997 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700998 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -0700999 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +02001000 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1001 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1002 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1003 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1004 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1005 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1007 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1008 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1009 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1010 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1011 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1012 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1013 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1014 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1016 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1017 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1018 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1019 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1020 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1021 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1022 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1023 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001024 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001025 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001026 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1027 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1028 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1029 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1030 */
1031 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1032 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1033 0x08, 0x00,
1034 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1035 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1036 0x0a, 0x01, 0x01, 0x95, /* ip src */
1037 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1038 0xc2, 0x24,
1039 0x00, 0x16 /* dst port */ },
1040 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1041 },
1042 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001043 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001044 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001045 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1046 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1047 * (len > 115 or len < 30000000000)' -d
1048 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001049 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1050 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1051 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1052 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1053 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1054 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1055 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1056 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1057 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1058 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1059 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1060 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1061 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1062 BPF_STMT(BPF_ST, 1),
1063 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1064 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1065 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1066 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1067 BPF_STMT(BPF_LD | BPF_MEM, 1),
1068 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1069 BPF_STMT(BPF_ST, 5),
1070 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1071 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1072 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1073 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1074 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1075 BPF_STMT(BPF_LD | BPF_MEM, 5),
1076 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1077 BPF_STMT(BPF_LD | BPF_LEN, 0),
1078 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1079 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1080 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1081 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001082 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001083 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001084 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1085 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1086 0x08, 0x00,
1087 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1088 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1089 0x0a, 0x01, 0x01, 0x95, /* ip src */
1090 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1091 0xc2, 0x24,
1092 0x00, 0x16 /* dst port */ },
1093 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1094 },
1095 {
1096 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001097 .u.insns = {
Zhen Lei53b0fe32021-07-07 18:07:28 -07001098 /* check that uninitialized X and A contain zeros */
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001099 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1100 BPF_STMT(BPF_RET | BPF_A, 0)
1101 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001102 CLASSIC,
1103 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001104 { {1, 0}, {2, 0} },
1105 },
1106 {
1107 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001108 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001109 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1110 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1111 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1112 BPF_ALU64_REG(BPF_SUB, R1, R2),
1113 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1114 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1115 BPF_ALU64_REG(BPF_MOV, R0, R1),
1116 BPF_EXIT_INSN(),
1117 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001118 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001119 { },
1120 { { 0, 0xfffffffd } }
1121 },
1122 {
1123 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001124 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001125 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1126 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1127 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1128 BPF_ALU64_REG(BPF_MUL, R1, R2),
1129 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1130 BPF_EXIT_INSN(),
1131 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1132 BPF_EXIT_INSN(),
1133 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001134 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001135 { },
1136 { { 0, 1 } }
1137 },
1138 {
1139 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001140 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001141 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1142 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1143 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1144 BPF_ALU64_REG(BPF_MUL, R1, R2),
1145 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1146 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1147 BPF_EXIT_INSN(),
1148 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1149 BPF_EXIT_INSN(),
1150 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001151 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001152 { },
1153 { { 0, 1 } }
1154 },
1155 {
1156 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001157 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001158 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1159 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1160 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1161 BPF_ALU32_REG(BPF_MUL, R1, R2),
1162 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1163 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1164 BPF_EXIT_INSN(),
1165 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1166 BPF_EXIT_INSN(),
1167 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001168 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001169 { },
1170 { { 0, 1 } }
1171 },
1172 {
1173 /* Have to test all register combinations, since
1174 * JITing of different registers will produce
1175 * different asm code.
1176 */
1177 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001178 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001179 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1180 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1181 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1182 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1183 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1184 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1185 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1186 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1187 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1188 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1189 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1190 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1191 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1192 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1193 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1194 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1195 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1196 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1197 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1198 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1199 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1200 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1201 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1202 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1203 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1204 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1205 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1206 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1207 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1208 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1209 BPF_ALU64_REG(BPF_ADD, R0, R0),
1210 BPF_ALU64_REG(BPF_ADD, R0, R1),
1211 BPF_ALU64_REG(BPF_ADD, R0, R2),
1212 BPF_ALU64_REG(BPF_ADD, R0, R3),
1213 BPF_ALU64_REG(BPF_ADD, R0, R4),
1214 BPF_ALU64_REG(BPF_ADD, R0, R5),
1215 BPF_ALU64_REG(BPF_ADD, R0, R6),
1216 BPF_ALU64_REG(BPF_ADD, R0, R7),
1217 BPF_ALU64_REG(BPF_ADD, R0, R8),
1218 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1219 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1220 BPF_EXIT_INSN(),
1221 BPF_ALU64_REG(BPF_ADD, R1, R0),
1222 BPF_ALU64_REG(BPF_ADD, R1, R1),
1223 BPF_ALU64_REG(BPF_ADD, R1, R2),
1224 BPF_ALU64_REG(BPF_ADD, R1, R3),
1225 BPF_ALU64_REG(BPF_ADD, R1, R4),
1226 BPF_ALU64_REG(BPF_ADD, R1, R5),
1227 BPF_ALU64_REG(BPF_ADD, R1, R6),
1228 BPF_ALU64_REG(BPF_ADD, R1, R7),
1229 BPF_ALU64_REG(BPF_ADD, R1, R8),
1230 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1231 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1232 BPF_EXIT_INSN(),
1233 BPF_ALU64_REG(BPF_ADD, R2, R0),
1234 BPF_ALU64_REG(BPF_ADD, R2, R1),
1235 BPF_ALU64_REG(BPF_ADD, R2, R2),
1236 BPF_ALU64_REG(BPF_ADD, R2, R3),
1237 BPF_ALU64_REG(BPF_ADD, R2, R4),
1238 BPF_ALU64_REG(BPF_ADD, R2, R5),
1239 BPF_ALU64_REG(BPF_ADD, R2, R6),
1240 BPF_ALU64_REG(BPF_ADD, R2, R7),
1241 BPF_ALU64_REG(BPF_ADD, R2, R8),
1242 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1243 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1244 BPF_EXIT_INSN(),
1245 BPF_ALU64_REG(BPF_ADD, R3, R0),
1246 BPF_ALU64_REG(BPF_ADD, R3, R1),
1247 BPF_ALU64_REG(BPF_ADD, R3, R2),
1248 BPF_ALU64_REG(BPF_ADD, R3, R3),
1249 BPF_ALU64_REG(BPF_ADD, R3, R4),
1250 BPF_ALU64_REG(BPF_ADD, R3, R5),
1251 BPF_ALU64_REG(BPF_ADD, R3, R6),
1252 BPF_ALU64_REG(BPF_ADD, R3, R7),
1253 BPF_ALU64_REG(BPF_ADD, R3, R8),
1254 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1255 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1256 BPF_EXIT_INSN(),
1257 BPF_ALU64_REG(BPF_ADD, R4, R0),
1258 BPF_ALU64_REG(BPF_ADD, R4, R1),
1259 BPF_ALU64_REG(BPF_ADD, R4, R2),
1260 BPF_ALU64_REG(BPF_ADD, R4, R3),
1261 BPF_ALU64_REG(BPF_ADD, R4, R4),
1262 BPF_ALU64_REG(BPF_ADD, R4, R5),
1263 BPF_ALU64_REG(BPF_ADD, R4, R6),
1264 BPF_ALU64_REG(BPF_ADD, R4, R7),
1265 BPF_ALU64_REG(BPF_ADD, R4, R8),
1266 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1267 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1268 BPF_EXIT_INSN(),
1269 BPF_ALU64_REG(BPF_ADD, R5, R0),
1270 BPF_ALU64_REG(BPF_ADD, R5, R1),
1271 BPF_ALU64_REG(BPF_ADD, R5, R2),
1272 BPF_ALU64_REG(BPF_ADD, R5, R3),
1273 BPF_ALU64_REG(BPF_ADD, R5, R4),
1274 BPF_ALU64_REG(BPF_ADD, R5, R5),
1275 BPF_ALU64_REG(BPF_ADD, R5, R6),
1276 BPF_ALU64_REG(BPF_ADD, R5, R7),
1277 BPF_ALU64_REG(BPF_ADD, R5, R8),
1278 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1279 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1280 BPF_EXIT_INSN(),
1281 BPF_ALU64_REG(BPF_ADD, R6, R0),
1282 BPF_ALU64_REG(BPF_ADD, R6, R1),
1283 BPF_ALU64_REG(BPF_ADD, R6, R2),
1284 BPF_ALU64_REG(BPF_ADD, R6, R3),
1285 BPF_ALU64_REG(BPF_ADD, R6, R4),
1286 BPF_ALU64_REG(BPF_ADD, R6, R5),
1287 BPF_ALU64_REG(BPF_ADD, R6, R6),
1288 BPF_ALU64_REG(BPF_ADD, R6, R7),
1289 BPF_ALU64_REG(BPF_ADD, R6, R8),
1290 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1291 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1292 BPF_EXIT_INSN(),
1293 BPF_ALU64_REG(BPF_ADD, R7, R0),
1294 BPF_ALU64_REG(BPF_ADD, R7, R1),
1295 BPF_ALU64_REG(BPF_ADD, R7, R2),
1296 BPF_ALU64_REG(BPF_ADD, R7, R3),
1297 BPF_ALU64_REG(BPF_ADD, R7, R4),
1298 BPF_ALU64_REG(BPF_ADD, R7, R5),
1299 BPF_ALU64_REG(BPF_ADD, R7, R6),
1300 BPF_ALU64_REG(BPF_ADD, R7, R7),
1301 BPF_ALU64_REG(BPF_ADD, R7, R8),
1302 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1303 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1304 BPF_EXIT_INSN(),
1305 BPF_ALU64_REG(BPF_ADD, R8, R0),
1306 BPF_ALU64_REG(BPF_ADD, R8, R1),
1307 BPF_ALU64_REG(BPF_ADD, R8, R2),
1308 BPF_ALU64_REG(BPF_ADD, R8, R3),
1309 BPF_ALU64_REG(BPF_ADD, R8, R4),
1310 BPF_ALU64_REG(BPF_ADD, R8, R5),
1311 BPF_ALU64_REG(BPF_ADD, R8, R6),
1312 BPF_ALU64_REG(BPF_ADD, R8, R7),
1313 BPF_ALU64_REG(BPF_ADD, R8, R8),
1314 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1315 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1316 BPF_EXIT_INSN(),
1317 BPF_ALU64_REG(BPF_ADD, R9, R0),
1318 BPF_ALU64_REG(BPF_ADD, R9, R1),
1319 BPF_ALU64_REG(BPF_ADD, R9, R2),
1320 BPF_ALU64_REG(BPF_ADD, R9, R3),
1321 BPF_ALU64_REG(BPF_ADD, R9, R4),
1322 BPF_ALU64_REG(BPF_ADD, R9, R5),
1323 BPF_ALU64_REG(BPF_ADD, R9, R6),
1324 BPF_ALU64_REG(BPF_ADD, R9, R7),
1325 BPF_ALU64_REG(BPF_ADD, R9, R8),
1326 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1327 BPF_ALU64_REG(BPF_MOV, R0, R9),
1328 BPF_EXIT_INSN(),
1329 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001330 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001331 { },
1332 { { 0, 2957380 } }
1333 },
1334 {
1335 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001336 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001337 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1338 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1339 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1340 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1341 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1342 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1343 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1344 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1345 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1346 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1347 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1348 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1349 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1350 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1351 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1352 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1353 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1354 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1355 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1356 BPF_ALU32_REG(BPF_ADD, R0, R1),
1357 BPF_ALU32_REG(BPF_ADD, R0, R2),
1358 BPF_ALU32_REG(BPF_ADD, R0, R3),
1359 BPF_ALU32_REG(BPF_ADD, R0, R4),
1360 BPF_ALU32_REG(BPF_ADD, R0, R5),
1361 BPF_ALU32_REG(BPF_ADD, R0, R6),
1362 BPF_ALU32_REG(BPF_ADD, R0, R7),
1363 BPF_ALU32_REG(BPF_ADD, R0, R8),
1364 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1365 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1366 BPF_EXIT_INSN(),
1367 BPF_ALU32_REG(BPF_ADD, R1, R0),
1368 BPF_ALU32_REG(BPF_ADD, R1, R1),
1369 BPF_ALU32_REG(BPF_ADD, R1, R2),
1370 BPF_ALU32_REG(BPF_ADD, R1, R3),
1371 BPF_ALU32_REG(BPF_ADD, R1, R4),
1372 BPF_ALU32_REG(BPF_ADD, R1, R5),
1373 BPF_ALU32_REG(BPF_ADD, R1, R6),
1374 BPF_ALU32_REG(BPF_ADD, R1, R7),
1375 BPF_ALU32_REG(BPF_ADD, R1, R8),
1376 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1377 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1378 BPF_EXIT_INSN(),
1379 BPF_ALU32_REG(BPF_ADD, R2, R0),
1380 BPF_ALU32_REG(BPF_ADD, R2, R1),
1381 BPF_ALU32_REG(BPF_ADD, R2, R2),
1382 BPF_ALU32_REG(BPF_ADD, R2, R3),
1383 BPF_ALU32_REG(BPF_ADD, R2, R4),
1384 BPF_ALU32_REG(BPF_ADD, R2, R5),
1385 BPF_ALU32_REG(BPF_ADD, R2, R6),
1386 BPF_ALU32_REG(BPF_ADD, R2, R7),
1387 BPF_ALU32_REG(BPF_ADD, R2, R8),
1388 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1389 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1390 BPF_EXIT_INSN(),
1391 BPF_ALU32_REG(BPF_ADD, R3, R0),
1392 BPF_ALU32_REG(BPF_ADD, R3, R1),
1393 BPF_ALU32_REG(BPF_ADD, R3, R2),
1394 BPF_ALU32_REG(BPF_ADD, R3, R3),
1395 BPF_ALU32_REG(BPF_ADD, R3, R4),
1396 BPF_ALU32_REG(BPF_ADD, R3, R5),
1397 BPF_ALU32_REG(BPF_ADD, R3, R6),
1398 BPF_ALU32_REG(BPF_ADD, R3, R7),
1399 BPF_ALU32_REG(BPF_ADD, R3, R8),
1400 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1401 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1402 BPF_EXIT_INSN(),
1403 BPF_ALU32_REG(BPF_ADD, R4, R0),
1404 BPF_ALU32_REG(BPF_ADD, R4, R1),
1405 BPF_ALU32_REG(BPF_ADD, R4, R2),
1406 BPF_ALU32_REG(BPF_ADD, R4, R3),
1407 BPF_ALU32_REG(BPF_ADD, R4, R4),
1408 BPF_ALU32_REG(BPF_ADD, R4, R5),
1409 BPF_ALU32_REG(BPF_ADD, R4, R6),
1410 BPF_ALU32_REG(BPF_ADD, R4, R7),
1411 BPF_ALU32_REG(BPF_ADD, R4, R8),
1412 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1413 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1414 BPF_EXIT_INSN(),
1415 BPF_ALU32_REG(BPF_ADD, R5, R0),
1416 BPF_ALU32_REG(BPF_ADD, R5, R1),
1417 BPF_ALU32_REG(BPF_ADD, R5, R2),
1418 BPF_ALU32_REG(BPF_ADD, R5, R3),
1419 BPF_ALU32_REG(BPF_ADD, R5, R4),
1420 BPF_ALU32_REG(BPF_ADD, R5, R5),
1421 BPF_ALU32_REG(BPF_ADD, R5, R6),
1422 BPF_ALU32_REG(BPF_ADD, R5, R7),
1423 BPF_ALU32_REG(BPF_ADD, R5, R8),
1424 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1425 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1426 BPF_EXIT_INSN(),
1427 BPF_ALU32_REG(BPF_ADD, R6, R0),
1428 BPF_ALU32_REG(BPF_ADD, R6, R1),
1429 BPF_ALU32_REG(BPF_ADD, R6, R2),
1430 BPF_ALU32_REG(BPF_ADD, R6, R3),
1431 BPF_ALU32_REG(BPF_ADD, R6, R4),
1432 BPF_ALU32_REG(BPF_ADD, R6, R5),
1433 BPF_ALU32_REG(BPF_ADD, R6, R6),
1434 BPF_ALU32_REG(BPF_ADD, R6, R7),
1435 BPF_ALU32_REG(BPF_ADD, R6, R8),
1436 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1437 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1438 BPF_EXIT_INSN(),
1439 BPF_ALU32_REG(BPF_ADD, R7, R0),
1440 BPF_ALU32_REG(BPF_ADD, R7, R1),
1441 BPF_ALU32_REG(BPF_ADD, R7, R2),
1442 BPF_ALU32_REG(BPF_ADD, R7, R3),
1443 BPF_ALU32_REG(BPF_ADD, R7, R4),
1444 BPF_ALU32_REG(BPF_ADD, R7, R5),
1445 BPF_ALU32_REG(BPF_ADD, R7, R6),
1446 BPF_ALU32_REG(BPF_ADD, R7, R7),
1447 BPF_ALU32_REG(BPF_ADD, R7, R8),
1448 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1449 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1450 BPF_EXIT_INSN(),
1451 BPF_ALU32_REG(BPF_ADD, R8, R0),
1452 BPF_ALU32_REG(BPF_ADD, R8, R1),
1453 BPF_ALU32_REG(BPF_ADD, R8, R2),
1454 BPF_ALU32_REG(BPF_ADD, R8, R3),
1455 BPF_ALU32_REG(BPF_ADD, R8, R4),
1456 BPF_ALU32_REG(BPF_ADD, R8, R5),
1457 BPF_ALU32_REG(BPF_ADD, R8, R6),
1458 BPF_ALU32_REG(BPF_ADD, R8, R7),
1459 BPF_ALU32_REG(BPF_ADD, R8, R8),
1460 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1461 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1462 BPF_EXIT_INSN(),
1463 BPF_ALU32_REG(BPF_ADD, R9, R0),
1464 BPF_ALU32_REG(BPF_ADD, R9, R1),
1465 BPF_ALU32_REG(BPF_ADD, R9, R2),
1466 BPF_ALU32_REG(BPF_ADD, R9, R3),
1467 BPF_ALU32_REG(BPF_ADD, R9, R4),
1468 BPF_ALU32_REG(BPF_ADD, R9, R5),
1469 BPF_ALU32_REG(BPF_ADD, R9, R6),
1470 BPF_ALU32_REG(BPF_ADD, R9, R7),
1471 BPF_ALU32_REG(BPF_ADD, R9, R8),
1472 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1473 BPF_ALU32_REG(BPF_MOV, R0, R9),
1474 BPF_EXIT_INSN(),
1475 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001476 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001477 { },
1478 { { 0, 2957380 } }
1479 },
1480 { /* Mainly checking JIT here. */
1481 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001482 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001483 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1484 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1485 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1486 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1487 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1488 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1489 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1490 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1491 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1492 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1493 BPF_ALU64_REG(BPF_SUB, R0, R0),
1494 BPF_ALU64_REG(BPF_SUB, R0, R1),
1495 BPF_ALU64_REG(BPF_SUB, R0, R2),
1496 BPF_ALU64_REG(BPF_SUB, R0, R3),
1497 BPF_ALU64_REG(BPF_SUB, R0, R4),
1498 BPF_ALU64_REG(BPF_SUB, R0, R5),
1499 BPF_ALU64_REG(BPF_SUB, R0, R6),
1500 BPF_ALU64_REG(BPF_SUB, R0, R7),
1501 BPF_ALU64_REG(BPF_SUB, R0, R8),
1502 BPF_ALU64_REG(BPF_SUB, R0, R9),
1503 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1504 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1505 BPF_EXIT_INSN(),
1506 BPF_ALU64_REG(BPF_SUB, R1, R0),
1507 BPF_ALU64_REG(BPF_SUB, R1, R2),
1508 BPF_ALU64_REG(BPF_SUB, R1, R3),
1509 BPF_ALU64_REG(BPF_SUB, R1, R4),
1510 BPF_ALU64_REG(BPF_SUB, R1, R5),
1511 BPF_ALU64_REG(BPF_SUB, R1, R6),
1512 BPF_ALU64_REG(BPF_SUB, R1, R7),
1513 BPF_ALU64_REG(BPF_SUB, R1, R8),
1514 BPF_ALU64_REG(BPF_SUB, R1, R9),
1515 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1516 BPF_ALU64_REG(BPF_SUB, R2, R0),
1517 BPF_ALU64_REG(BPF_SUB, R2, R1),
1518 BPF_ALU64_REG(BPF_SUB, R2, R3),
1519 BPF_ALU64_REG(BPF_SUB, R2, R4),
1520 BPF_ALU64_REG(BPF_SUB, R2, R5),
1521 BPF_ALU64_REG(BPF_SUB, R2, R6),
1522 BPF_ALU64_REG(BPF_SUB, R2, R7),
1523 BPF_ALU64_REG(BPF_SUB, R2, R8),
1524 BPF_ALU64_REG(BPF_SUB, R2, R9),
1525 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1526 BPF_ALU64_REG(BPF_SUB, R3, R0),
1527 BPF_ALU64_REG(BPF_SUB, R3, R1),
1528 BPF_ALU64_REG(BPF_SUB, R3, R2),
1529 BPF_ALU64_REG(BPF_SUB, R3, R4),
1530 BPF_ALU64_REG(BPF_SUB, R3, R5),
1531 BPF_ALU64_REG(BPF_SUB, R3, R6),
1532 BPF_ALU64_REG(BPF_SUB, R3, R7),
1533 BPF_ALU64_REG(BPF_SUB, R3, R8),
1534 BPF_ALU64_REG(BPF_SUB, R3, R9),
1535 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1536 BPF_ALU64_REG(BPF_SUB, R4, R0),
1537 BPF_ALU64_REG(BPF_SUB, R4, R1),
1538 BPF_ALU64_REG(BPF_SUB, R4, R2),
1539 BPF_ALU64_REG(BPF_SUB, R4, R3),
1540 BPF_ALU64_REG(BPF_SUB, R4, R5),
1541 BPF_ALU64_REG(BPF_SUB, R4, R6),
1542 BPF_ALU64_REG(BPF_SUB, R4, R7),
1543 BPF_ALU64_REG(BPF_SUB, R4, R8),
1544 BPF_ALU64_REG(BPF_SUB, R4, R9),
1545 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1546 BPF_ALU64_REG(BPF_SUB, R5, R0),
1547 BPF_ALU64_REG(BPF_SUB, R5, R1),
1548 BPF_ALU64_REG(BPF_SUB, R5, R2),
1549 BPF_ALU64_REG(BPF_SUB, R5, R3),
1550 BPF_ALU64_REG(BPF_SUB, R5, R4),
1551 BPF_ALU64_REG(BPF_SUB, R5, R6),
1552 BPF_ALU64_REG(BPF_SUB, R5, R7),
1553 BPF_ALU64_REG(BPF_SUB, R5, R8),
1554 BPF_ALU64_REG(BPF_SUB, R5, R9),
1555 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1556 BPF_ALU64_REG(BPF_SUB, R6, R0),
1557 BPF_ALU64_REG(BPF_SUB, R6, R1),
1558 BPF_ALU64_REG(BPF_SUB, R6, R2),
1559 BPF_ALU64_REG(BPF_SUB, R6, R3),
1560 BPF_ALU64_REG(BPF_SUB, R6, R4),
1561 BPF_ALU64_REG(BPF_SUB, R6, R5),
1562 BPF_ALU64_REG(BPF_SUB, R6, R7),
1563 BPF_ALU64_REG(BPF_SUB, R6, R8),
1564 BPF_ALU64_REG(BPF_SUB, R6, R9),
1565 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1566 BPF_ALU64_REG(BPF_SUB, R7, R0),
1567 BPF_ALU64_REG(BPF_SUB, R7, R1),
1568 BPF_ALU64_REG(BPF_SUB, R7, R2),
1569 BPF_ALU64_REG(BPF_SUB, R7, R3),
1570 BPF_ALU64_REG(BPF_SUB, R7, R4),
1571 BPF_ALU64_REG(BPF_SUB, R7, R5),
1572 BPF_ALU64_REG(BPF_SUB, R7, R6),
1573 BPF_ALU64_REG(BPF_SUB, R7, R8),
1574 BPF_ALU64_REG(BPF_SUB, R7, R9),
1575 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1576 BPF_ALU64_REG(BPF_SUB, R8, R0),
1577 BPF_ALU64_REG(BPF_SUB, R8, R1),
1578 BPF_ALU64_REG(BPF_SUB, R8, R2),
1579 BPF_ALU64_REG(BPF_SUB, R8, R3),
1580 BPF_ALU64_REG(BPF_SUB, R8, R4),
1581 BPF_ALU64_REG(BPF_SUB, R8, R5),
1582 BPF_ALU64_REG(BPF_SUB, R8, R6),
1583 BPF_ALU64_REG(BPF_SUB, R8, R7),
1584 BPF_ALU64_REG(BPF_SUB, R8, R9),
1585 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1586 BPF_ALU64_REG(BPF_SUB, R9, R0),
1587 BPF_ALU64_REG(BPF_SUB, R9, R1),
1588 BPF_ALU64_REG(BPF_SUB, R9, R2),
1589 BPF_ALU64_REG(BPF_SUB, R9, R3),
1590 BPF_ALU64_REG(BPF_SUB, R9, R4),
1591 BPF_ALU64_REG(BPF_SUB, R9, R5),
1592 BPF_ALU64_REG(BPF_SUB, R9, R6),
1593 BPF_ALU64_REG(BPF_SUB, R9, R7),
1594 BPF_ALU64_REG(BPF_SUB, R9, R8),
1595 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1596 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1597 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1598 BPF_ALU64_REG(BPF_SUB, R0, R1),
1599 BPF_ALU64_REG(BPF_SUB, R0, R2),
1600 BPF_ALU64_REG(BPF_SUB, R0, R3),
1601 BPF_ALU64_REG(BPF_SUB, R0, R4),
1602 BPF_ALU64_REG(BPF_SUB, R0, R5),
1603 BPF_ALU64_REG(BPF_SUB, R0, R6),
1604 BPF_ALU64_REG(BPF_SUB, R0, R7),
1605 BPF_ALU64_REG(BPF_SUB, R0, R8),
1606 BPF_ALU64_REG(BPF_SUB, R0, R9),
1607 BPF_EXIT_INSN(),
1608 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001609 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001610 { },
1611 { { 0, 11 } }
1612 },
1613 { /* Mainly checking JIT here. */
1614 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001615 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001616 BPF_ALU64_REG(BPF_SUB, R0, R0),
1617 BPF_ALU64_REG(BPF_XOR, R1, R1),
1618 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1619 BPF_EXIT_INSN(),
1620 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1621 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1622 BPF_ALU64_REG(BPF_SUB, R1, R1),
1623 BPF_ALU64_REG(BPF_XOR, R2, R2),
1624 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1625 BPF_EXIT_INSN(),
1626 BPF_ALU64_REG(BPF_SUB, R2, R2),
1627 BPF_ALU64_REG(BPF_XOR, R3, R3),
1628 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1629 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1630 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1631 BPF_EXIT_INSN(),
1632 BPF_ALU64_REG(BPF_SUB, R3, R3),
1633 BPF_ALU64_REG(BPF_XOR, R4, R4),
1634 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1635 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1636 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1637 BPF_EXIT_INSN(),
1638 BPF_ALU64_REG(BPF_SUB, R4, R4),
1639 BPF_ALU64_REG(BPF_XOR, R5, R5),
1640 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1641 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1642 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1643 BPF_EXIT_INSN(),
1644 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1645 BPF_ALU64_REG(BPF_SUB, R5, R5),
1646 BPF_ALU64_REG(BPF_XOR, R6, R6),
1647 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1648 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1649 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1650 BPF_EXIT_INSN(),
1651 BPF_ALU64_REG(BPF_SUB, R6, R6),
1652 BPF_ALU64_REG(BPF_XOR, R7, R7),
1653 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1654 BPF_EXIT_INSN(),
1655 BPF_ALU64_REG(BPF_SUB, R7, R7),
1656 BPF_ALU64_REG(BPF_XOR, R8, R8),
1657 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1658 BPF_EXIT_INSN(),
1659 BPF_ALU64_REG(BPF_SUB, R8, R8),
1660 BPF_ALU64_REG(BPF_XOR, R9, R9),
1661 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1662 BPF_EXIT_INSN(),
1663 BPF_ALU64_REG(BPF_SUB, R9, R9),
1664 BPF_ALU64_REG(BPF_XOR, R0, R0),
1665 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_REG(BPF_SUB, R1, R1),
1668 BPF_ALU64_REG(BPF_XOR, R0, R0),
1669 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1670 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1671 BPF_EXIT_INSN(),
1672 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1673 BPF_EXIT_INSN(),
1674 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001675 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001676 { },
1677 { { 0, 1 } }
1678 },
1679 { /* Mainly checking JIT here. */
1680 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001681 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001682 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1683 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1684 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1685 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1686 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1687 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1688 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1689 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1690 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1691 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1692 BPF_ALU64_REG(BPF_MUL, R0, R0),
1693 BPF_ALU64_REG(BPF_MUL, R0, R1),
1694 BPF_ALU64_REG(BPF_MUL, R0, R2),
1695 BPF_ALU64_REG(BPF_MUL, R0, R3),
1696 BPF_ALU64_REG(BPF_MUL, R0, R4),
1697 BPF_ALU64_REG(BPF_MUL, R0, R5),
1698 BPF_ALU64_REG(BPF_MUL, R0, R6),
1699 BPF_ALU64_REG(BPF_MUL, R0, R7),
1700 BPF_ALU64_REG(BPF_MUL, R0, R8),
1701 BPF_ALU64_REG(BPF_MUL, R0, R9),
1702 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1703 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1704 BPF_EXIT_INSN(),
1705 BPF_ALU64_REG(BPF_MUL, R1, R0),
1706 BPF_ALU64_REG(BPF_MUL, R1, R2),
1707 BPF_ALU64_REG(BPF_MUL, R1, R3),
1708 BPF_ALU64_REG(BPF_MUL, R1, R4),
1709 BPF_ALU64_REG(BPF_MUL, R1, R5),
1710 BPF_ALU64_REG(BPF_MUL, R1, R6),
1711 BPF_ALU64_REG(BPF_MUL, R1, R7),
1712 BPF_ALU64_REG(BPF_MUL, R1, R8),
1713 BPF_ALU64_REG(BPF_MUL, R1, R9),
1714 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1715 BPF_ALU64_REG(BPF_MOV, R2, R1),
1716 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1717 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1718 BPF_EXIT_INSN(),
1719 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1720 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1721 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1722 BPF_EXIT_INSN(),
1723 BPF_ALU64_REG(BPF_MUL, R2, R0),
1724 BPF_ALU64_REG(BPF_MUL, R2, R1),
1725 BPF_ALU64_REG(BPF_MUL, R2, R3),
1726 BPF_ALU64_REG(BPF_MUL, R2, R4),
1727 BPF_ALU64_REG(BPF_MUL, R2, R5),
1728 BPF_ALU64_REG(BPF_MUL, R2, R6),
1729 BPF_ALU64_REG(BPF_MUL, R2, R7),
1730 BPF_ALU64_REG(BPF_MUL, R2, R8),
1731 BPF_ALU64_REG(BPF_MUL, R2, R9),
1732 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1733 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1734 BPF_ALU64_REG(BPF_MOV, R0, R2),
1735 BPF_EXIT_INSN(),
1736 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001737 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001738 { },
1739 { { 0, 0x35d97ef2 } }
1740 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001741 { /* Mainly checking JIT here. */
1742 "MOV REG64",
1743 .u.insns_int = {
1744 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1745 BPF_MOV64_REG(R1, R0),
1746 BPF_MOV64_REG(R2, R1),
1747 BPF_MOV64_REG(R3, R2),
1748 BPF_MOV64_REG(R4, R3),
1749 BPF_MOV64_REG(R5, R4),
1750 BPF_MOV64_REG(R6, R5),
1751 BPF_MOV64_REG(R7, R6),
1752 BPF_MOV64_REG(R8, R7),
1753 BPF_MOV64_REG(R9, R8),
1754 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1755 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1756 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1757 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1758 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1759 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1760 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1761 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1762 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1763 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1764 BPF_ALU64_REG(BPF_ADD, R0, R0),
1765 BPF_ALU64_REG(BPF_ADD, R0, R1),
1766 BPF_ALU64_REG(BPF_ADD, R0, R2),
1767 BPF_ALU64_REG(BPF_ADD, R0, R3),
1768 BPF_ALU64_REG(BPF_ADD, R0, R4),
1769 BPF_ALU64_REG(BPF_ADD, R0, R5),
1770 BPF_ALU64_REG(BPF_ADD, R0, R6),
1771 BPF_ALU64_REG(BPF_ADD, R0, R7),
1772 BPF_ALU64_REG(BPF_ADD, R0, R8),
1773 BPF_ALU64_REG(BPF_ADD, R0, R9),
1774 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1775 BPF_EXIT_INSN(),
1776 },
1777 INTERNAL,
1778 { },
1779 { { 0, 0xfefe } }
1780 },
1781 { /* Mainly checking JIT here. */
1782 "MOV REG32",
1783 .u.insns_int = {
1784 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1785 BPF_MOV64_REG(R1, R0),
1786 BPF_MOV64_REG(R2, R1),
1787 BPF_MOV64_REG(R3, R2),
1788 BPF_MOV64_REG(R4, R3),
1789 BPF_MOV64_REG(R5, R4),
1790 BPF_MOV64_REG(R6, R5),
1791 BPF_MOV64_REG(R7, R6),
1792 BPF_MOV64_REG(R8, R7),
1793 BPF_MOV64_REG(R9, R8),
1794 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1795 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1796 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1797 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1798 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1799 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1800 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1801 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1802 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1803 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1804 BPF_ALU64_REG(BPF_ADD, R0, R0),
1805 BPF_ALU64_REG(BPF_ADD, R0, R1),
1806 BPF_ALU64_REG(BPF_ADD, R0, R2),
1807 BPF_ALU64_REG(BPF_ADD, R0, R3),
1808 BPF_ALU64_REG(BPF_ADD, R0, R4),
1809 BPF_ALU64_REG(BPF_ADD, R0, R5),
1810 BPF_ALU64_REG(BPF_ADD, R0, R6),
1811 BPF_ALU64_REG(BPF_ADD, R0, R7),
1812 BPF_ALU64_REG(BPF_ADD, R0, R8),
1813 BPF_ALU64_REG(BPF_ADD, R0, R9),
1814 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1815 BPF_EXIT_INSN(),
1816 },
1817 INTERNAL,
1818 { },
1819 { { 0, 0xfefe } }
1820 },
1821 { /* Mainly checking JIT here. */
1822 "LD IMM64",
1823 .u.insns_int = {
1824 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1825 BPF_MOV64_REG(R1, R0),
1826 BPF_MOV64_REG(R2, R1),
1827 BPF_MOV64_REG(R3, R2),
1828 BPF_MOV64_REG(R4, R3),
1829 BPF_MOV64_REG(R5, R4),
1830 BPF_MOV64_REG(R6, R5),
1831 BPF_MOV64_REG(R7, R6),
1832 BPF_MOV64_REG(R8, R7),
1833 BPF_MOV64_REG(R9, R8),
1834 BPF_LD_IMM64(R0, 0x0LL),
1835 BPF_LD_IMM64(R1, 0x0LL),
1836 BPF_LD_IMM64(R2, 0x0LL),
1837 BPF_LD_IMM64(R3, 0x0LL),
1838 BPF_LD_IMM64(R4, 0x0LL),
1839 BPF_LD_IMM64(R5, 0x0LL),
1840 BPF_LD_IMM64(R6, 0x0LL),
1841 BPF_LD_IMM64(R7, 0x0LL),
1842 BPF_LD_IMM64(R8, 0x0LL),
1843 BPF_LD_IMM64(R9, 0x0LL),
1844 BPF_ALU64_REG(BPF_ADD, R0, R0),
1845 BPF_ALU64_REG(BPF_ADD, R0, R1),
1846 BPF_ALU64_REG(BPF_ADD, R0, R2),
1847 BPF_ALU64_REG(BPF_ADD, R0, R3),
1848 BPF_ALU64_REG(BPF_ADD, R0, R4),
1849 BPF_ALU64_REG(BPF_ADD, R0, R5),
1850 BPF_ALU64_REG(BPF_ADD, R0, R6),
1851 BPF_ALU64_REG(BPF_ADD, R0, R7),
1852 BPF_ALU64_REG(BPF_ADD, R0, R8),
1853 BPF_ALU64_REG(BPF_ADD, R0, R9),
1854 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1855 BPF_EXIT_INSN(),
1856 },
1857 INTERNAL,
1858 { },
1859 { { 0, 0xfefe } }
1860 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001861 {
1862 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001863 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001864 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1865 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1866 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1867 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1868 BPF_ALU64_REG(BPF_DIV, R0, R2),
1869 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1870 BPF_EXIT_INSN(),
1871 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1872 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1873 BPF_EXIT_INSN(),
1874 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1875 BPF_EXIT_INSN(),
1876 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001877 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001878 { },
1879 { { 0, -1 } }
1880 },
1881 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001882 "INT: shifts by register",
1883 .u.insns_int = {
1884 BPF_MOV64_IMM(R0, -1234),
1885 BPF_MOV64_IMM(R1, 1),
1886 BPF_ALU32_REG(BPF_RSH, R0, R1),
1887 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1888 BPF_EXIT_INSN(),
1889 BPF_MOV64_IMM(R2, 1),
1890 BPF_ALU64_REG(BPF_LSH, R0, R2),
1891 BPF_MOV32_IMM(R4, -1234),
1892 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1893 BPF_EXIT_INSN(),
1894 BPF_ALU64_IMM(BPF_AND, R4, 63),
1895 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1896 BPF_MOV64_IMM(R3, 47),
1897 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1898 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1899 BPF_EXIT_INSN(),
1900 BPF_MOV64_IMM(R2, 1),
1901 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1902 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1903 BPF_EXIT_INSN(),
1904 BPF_MOV64_IMM(R4, 4),
1905 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1906 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1907 BPF_EXIT_INSN(),
1908 BPF_MOV64_IMM(R4, 5),
1909 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1910 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1911 BPF_EXIT_INSN(),
1912 BPF_MOV64_IMM(R0, -1),
1913 BPF_EXIT_INSN(),
1914 },
1915 INTERNAL,
1916 { },
1917 { { 0, -1 } }
1918 },
1919 {
Johan Almbladh84024a42021-08-09 11:18:23 +02001920 /*
1921 * Register (non-)clobbering test, in the case where a 32-bit
1922 * JIT implements complex ALU64 operations via function calls.
1923 * If so, the function call must be invisible in the eBPF
1924 * registers. The JIT must then save and restore relevant
1925 * registers during the call. The following tests check that
1926 * the eBPF registers retain their values after such a call.
1927 */
1928 "INT: Register clobbering, R1 updated",
1929 .u.insns_int = {
1930 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1931 BPF_ALU32_IMM(BPF_MOV, R1, 123456789),
1932 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1933 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1934 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1935 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1936 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1937 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1938 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1939 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1940 BPF_ALU64_IMM(BPF_DIV, R1, 123456789),
1941 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
1942 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
1943 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
1944 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
1945 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
1946 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
1947 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
1948 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
1949 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
1950 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
1951 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1952 BPF_EXIT_INSN(),
1953 },
1954 INTERNAL,
1955 { },
1956 { { 0, 1 } }
1957 },
1958 {
1959 "INT: Register clobbering, R2 updated",
1960 .u.insns_int = {
1961 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1962 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1963 BPF_ALU32_IMM(BPF_MOV, R2, 2 * 123456789),
1964 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1965 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1966 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1967 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1968 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1969 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1970 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1971 BPF_ALU64_IMM(BPF_DIV, R2, 123456789),
1972 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
1973 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
1974 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
1975 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
1976 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
1977 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
1978 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
1979 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
1980 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
1981 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
1982 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1983 BPF_EXIT_INSN(),
1984 },
1985 INTERNAL,
1986 { },
1987 { { 0, 1 } }
1988 },
1989 {
1990 /*
1991 * Test 32-bit JITs that implement complex ALU64 operations as
1992 * function calls R0 = f(R1, R2), and must re-arrange operands.
1993 */
1994#define NUMER 0xfedcba9876543210ULL
1995#define DENOM 0x0123456789abcdefULL
1996 "ALU64_DIV X: Operand register permutations",
1997 .u.insns_int = {
1998 /* R0 / R2 */
1999 BPF_LD_IMM64(R0, NUMER),
2000 BPF_LD_IMM64(R2, DENOM),
2001 BPF_ALU64_REG(BPF_DIV, R0, R2),
2002 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2003 BPF_EXIT_INSN(),
2004 /* R1 / R0 */
2005 BPF_LD_IMM64(R1, NUMER),
2006 BPF_LD_IMM64(R0, DENOM),
2007 BPF_ALU64_REG(BPF_DIV, R1, R0),
2008 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2009 BPF_EXIT_INSN(),
2010 /* R0 / R1 */
2011 BPF_LD_IMM64(R0, NUMER),
2012 BPF_LD_IMM64(R1, DENOM),
2013 BPF_ALU64_REG(BPF_DIV, R0, R1),
2014 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2015 BPF_EXIT_INSN(),
2016 /* R2 / R0 */
2017 BPF_LD_IMM64(R2, NUMER),
2018 BPF_LD_IMM64(R0, DENOM),
2019 BPF_ALU64_REG(BPF_DIV, R2, R0),
2020 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2021 BPF_EXIT_INSN(),
2022 /* R2 / R1 */
2023 BPF_LD_IMM64(R2, NUMER),
2024 BPF_LD_IMM64(R1, DENOM),
2025 BPF_ALU64_REG(BPF_DIV, R2, R1),
2026 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2027 BPF_EXIT_INSN(),
2028 /* R1 / R2 */
2029 BPF_LD_IMM64(R1, NUMER),
2030 BPF_LD_IMM64(R2, DENOM),
2031 BPF_ALU64_REG(BPF_DIV, R1, R2),
2032 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2033 BPF_EXIT_INSN(),
2034 /* R1 / R1 */
2035 BPF_LD_IMM64(R1, NUMER),
2036 BPF_ALU64_REG(BPF_DIV, R1, R1),
2037 BPF_JMP_IMM(BPF_JEQ, R1, 1, 1),
2038 BPF_EXIT_INSN(),
2039 /* R2 / R2 */
2040 BPF_LD_IMM64(R2, DENOM),
2041 BPF_ALU64_REG(BPF_DIV, R2, R2),
2042 BPF_JMP_IMM(BPF_JEQ, R2, 1, 1),
2043 BPF_EXIT_INSN(),
2044 /* R3 / R4 */
2045 BPF_LD_IMM64(R3, NUMER),
2046 BPF_LD_IMM64(R4, DENOM),
2047 BPF_ALU64_REG(BPF_DIV, R3, R4),
2048 BPF_JMP_IMM(BPF_JEQ, R3, NUMER / DENOM, 1),
2049 BPF_EXIT_INSN(),
2050 /* Successful return */
2051 BPF_LD_IMM64(R0, 1),
2052 BPF_EXIT_INSN(),
2053 },
2054 INTERNAL,
2055 { },
2056 { { 0, 1 } },
2057#undef NUMER
2058#undef DENOM
2059 },
2060 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002061 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07002062 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002063 BPF_STMT(BPF_LD | BPF_IMM, 1),
2064 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002065 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002066 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002067 { },
2068 .fill_helper = NULL,
2069 .expected_errcode = -EINVAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002070 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002071 {
2072 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07002073 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002074 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
2075 BPF_STMT(BPF_RET | BPF_K, 0)
2076 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002077 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002078 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002079 { },
2080 .fill_helper = NULL,
2081 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002082 },
2083 {
2084 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07002085 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002086 /* seccomp insn, rejected in socket filter */
2087 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
2088 BPF_STMT(BPF_RET | BPF_K, 0)
2089 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002090 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002091 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002092 { },
2093 .fill_helper = NULL,
2094 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002095 },
2096 {
2097 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07002098 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002099 BPF_STMT(BPF_STX, 16),
2100 BPF_STMT(BPF_RET | BPF_K, 0)
2101 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002102 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002103 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002104 { },
2105 .fill_helper = NULL,
2106 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002107 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002108 {
2109 "JUMPS + HOLES",
2110 .u.insns = {
2111 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2112 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
2113 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2114 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2115 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2116 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2117 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2118 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2119 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2120 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2121 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2122 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2123 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2124 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2125 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2126 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
2127 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2128 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
2129 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2130 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2131 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2132 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2133 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2134 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2135 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2136 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2137 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2138 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2139 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2140 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2141 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2142 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2143 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2144 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2145 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2146 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2147 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2148 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2149 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2150 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2151 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2152 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2153 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2154 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2155 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2156 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2157 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2158 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2159 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2160 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2161 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2162 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2163 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2164 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2165 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2166 BPF_STMT(BPF_RET | BPF_A, 0),
2167 BPF_STMT(BPF_RET | BPF_A, 0),
2168 },
2169 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002170 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2171 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2172 0x08, 0x00,
2173 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2174 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2175 0xc0, 0xa8, 0x33, 0x01,
2176 0xc0, 0xa8, 0x33, 0x02,
2177 0xbb, 0xb6,
2178 0xa9, 0xfa,
2179 0x00, 0x14, 0x00, 0x00,
2180 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2181 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2182 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2183 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2184 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2185 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2186 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2187 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002188 { { 88, 0x001b } }
2189 },
2190 {
2191 "check: RET X",
2192 .u.insns = {
2193 BPF_STMT(BPF_RET | BPF_X, 0),
2194 },
2195 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2196 { },
2197 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002198 .fill_helper = NULL,
2199 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002200 },
2201 {
2202 "check: LDX + RET X",
2203 .u.insns = {
2204 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2205 BPF_STMT(BPF_RET | BPF_X, 0),
2206 },
2207 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2208 { },
2209 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002210 .fill_helper = NULL,
2211 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002212 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002213 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002214 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002215 .u.insns = {
2216 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2217 BPF_STMT(BPF_STX, 0),
2218 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2219 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2220 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2221 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2222 BPF_STMT(BPF_STX, 1),
2223 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2224 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2225 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2226 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2227 BPF_STMT(BPF_STX, 2),
2228 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2229 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2230 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2231 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2232 BPF_STMT(BPF_STX, 3),
2233 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2234 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2235 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2236 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2237 BPF_STMT(BPF_STX, 4),
2238 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2239 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2240 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2241 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2242 BPF_STMT(BPF_STX, 5),
2243 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2244 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2245 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2246 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2247 BPF_STMT(BPF_STX, 6),
2248 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2249 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2250 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2251 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2252 BPF_STMT(BPF_STX, 7),
2253 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2254 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2255 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2256 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2257 BPF_STMT(BPF_STX, 8),
2258 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2259 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2260 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2261 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2262 BPF_STMT(BPF_STX, 9),
2263 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2264 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2265 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2266 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2267 BPF_STMT(BPF_STX, 10),
2268 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2269 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2270 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2271 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2272 BPF_STMT(BPF_STX, 11),
2273 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2274 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2275 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2276 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2277 BPF_STMT(BPF_STX, 12),
2278 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2279 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2280 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2281 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2282 BPF_STMT(BPF_STX, 13),
2283 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2284 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2285 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2286 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2287 BPF_STMT(BPF_STX, 14),
2288 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2289 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2290 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2291 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2292 BPF_STMT(BPF_STX, 15),
2293 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2294 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2295 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2296 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2297 BPF_STMT(BPF_RET | BPF_A, 0),
2298 },
2299 CLASSIC | FLAG_NO_DATA,
2300 { },
2301 { { 0, 116 } },
2302 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002303 { /* Mainly checking JIT here. */
2304 "M[]: full STX + full LDX",
2305 .u.insns = {
2306 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2307 BPF_STMT(BPF_STX, 0),
2308 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2309 BPF_STMT(BPF_STX, 1),
2310 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2311 BPF_STMT(BPF_STX, 2),
2312 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2313 BPF_STMT(BPF_STX, 3),
2314 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2315 BPF_STMT(BPF_STX, 4),
2316 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2317 BPF_STMT(BPF_STX, 5),
2318 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2319 BPF_STMT(BPF_STX, 6),
2320 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2321 BPF_STMT(BPF_STX, 7),
2322 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2323 BPF_STMT(BPF_STX, 8),
2324 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2325 BPF_STMT(BPF_STX, 9),
2326 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2327 BPF_STMT(BPF_STX, 10),
2328 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2329 BPF_STMT(BPF_STX, 11),
2330 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2331 BPF_STMT(BPF_STX, 12),
2332 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2333 BPF_STMT(BPF_STX, 13),
2334 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2335 BPF_STMT(BPF_STX, 14),
2336 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2337 BPF_STMT(BPF_STX, 15),
2338 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2339 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2340 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2341 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2342 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2343 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2344 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2345 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2346 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2347 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2348 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2349 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2350 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2351 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2352 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2353 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2354 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2355 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2356 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2357 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2358 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2359 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2360 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2361 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2362 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2363 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2364 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2365 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2366 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2367 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2368 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2369 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2370 BPF_STMT(BPF_RET | BPF_A, 0),
2371 },
2372 CLASSIC | FLAG_NO_DATA,
2373 { },
2374 { { 0, 0x2a5a5e5 } },
2375 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002376 {
2377 "check: SKF_AD_MAX",
2378 .u.insns = {
2379 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2380 SKF_AD_OFF + SKF_AD_MAX),
2381 BPF_STMT(BPF_RET | BPF_A, 0),
2382 },
2383 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2384 { },
2385 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002386 .fill_helper = NULL,
2387 .expected_errcode = -EINVAL,
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002388 },
2389 { /* Passes checker but fails during runtime. */
2390 "LD [SKF_AD_OFF-1]",
2391 .u.insns = {
2392 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2393 SKF_AD_OFF - 1),
2394 BPF_STMT(BPF_RET | BPF_K, 1),
2395 },
2396 CLASSIC,
2397 { },
2398 { { 1, 0 } },
2399 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002400 {
2401 "load 64-bit immediate",
2402 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002403 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002404 BPF_MOV64_REG(R2, R1),
2405 BPF_MOV64_REG(R3, R2),
2406 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2407 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2408 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2409 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2410 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2411 BPF_EXIT_INSN(),
2412 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2413 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002414 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2415 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002416 BPF_EXIT_INSN(),
2417 },
2418 INTERNAL,
2419 { },
2420 { { 0, 1 } }
2421 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002422 /* BPF_ALU | BPF_MOV | BPF_X */
2423 {
2424 "ALU_MOV_X: dst = 2",
2425 .u.insns_int = {
2426 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2427 BPF_ALU32_REG(BPF_MOV, R0, R1),
2428 BPF_EXIT_INSN(),
2429 },
2430 INTERNAL,
2431 { },
2432 { { 0, 2 } },
2433 },
2434 {
2435 "ALU_MOV_X: dst = 4294967295",
2436 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002437 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002438 BPF_ALU32_REG(BPF_MOV, R0, R1),
2439 BPF_EXIT_INSN(),
2440 },
2441 INTERNAL,
2442 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002443 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002444 },
2445 {
2446 "ALU64_MOV_X: dst = 2",
2447 .u.insns_int = {
2448 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2449 BPF_ALU64_REG(BPF_MOV, R0, R1),
2450 BPF_EXIT_INSN(),
2451 },
2452 INTERNAL,
2453 { },
2454 { { 0, 2 } },
2455 },
2456 {
2457 "ALU64_MOV_X: dst = 4294967295",
2458 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002459 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002460 BPF_ALU64_REG(BPF_MOV, R0, R1),
2461 BPF_EXIT_INSN(),
2462 },
2463 INTERNAL,
2464 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002465 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002466 },
2467 /* BPF_ALU | BPF_MOV | BPF_K */
2468 {
2469 "ALU_MOV_K: dst = 2",
2470 .u.insns_int = {
2471 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2472 BPF_EXIT_INSN(),
2473 },
2474 INTERNAL,
2475 { },
2476 { { 0, 2 } },
2477 },
2478 {
2479 "ALU_MOV_K: dst = 4294967295",
2480 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002481 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002482 BPF_EXIT_INSN(),
2483 },
2484 INTERNAL,
2485 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002486 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002487 },
2488 {
2489 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2490 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002491 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2492 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002493 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2494 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2495 BPF_MOV32_IMM(R0, 2),
2496 BPF_EXIT_INSN(),
2497 BPF_MOV32_IMM(R0, 1),
2498 BPF_EXIT_INSN(),
2499 },
2500 INTERNAL,
2501 { },
2502 { { 0, 0x1 } },
2503 },
2504 {
Johan Almbladh565731a2021-08-09 11:18:17 +02002505 "ALU_MOV_K: small negative",
2506 .u.insns_int = {
2507 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2508 BPF_EXIT_INSN(),
2509 },
2510 INTERNAL,
2511 { },
2512 { { 0, -123 } }
2513 },
2514 {
2515 "ALU_MOV_K: small negative zero extension",
2516 .u.insns_int = {
2517 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2518 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2519 BPF_EXIT_INSN(),
2520 },
2521 INTERNAL,
2522 { },
2523 { { 0, 0 } }
2524 },
2525 {
2526 "ALU_MOV_K: large negative",
2527 .u.insns_int = {
2528 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2529 BPF_EXIT_INSN(),
2530 },
2531 INTERNAL,
2532 { },
2533 { { 0, -123456789 } }
2534 },
2535 {
2536 "ALU_MOV_K: large negative zero extension",
2537 .u.insns_int = {
2538 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2539 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2540 BPF_EXIT_INSN(),
2541 },
2542 INTERNAL,
2543 { },
2544 { { 0, 0 } }
2545 },
2546 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002547 "ALU64_MOV_K: dst = 2",
2548 .u.insns_int = {
2549 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2550 BPF_EXIT_INSN(),
2551 },
2552 INTERNAL,
2553 { },
2554 { { 0, 2 } },
2555 },
2556 {
2557 "ALU64_MOV_K: dst = 2147483647",
2558 .u.insns_int = {
2559 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2560 BPF_EXIT_INSN(),
2561 },
2562 INTERNAL,
2563 { },
2564 { { 0, 2147483647 } },
2565 },
2566 {
2567 "ALU64_OR_K: dst = 0x0",
2568 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002569 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002570 BPF_LD_IMM64(R3, 0x0),
2571 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2572 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2573 BPF_MOV32_IMM(R0, 2),
2574 BPF_EXIT_INSN(),
2575 BPF_MOV32_IMM(R0, 1),
2576 BPF_EXIT_INSN(),
2577 },
2578 INTERNAL,
2579 { },
2580 { { 0, 0x1 } },
2581 },
2582 {
2583 "ALU64_MOV_K: dst = -1",
2584 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002585 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2586 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002587 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2588 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2589 BPF_MOV32_IMM(R0, 2),
2590 BPF_EXIT_INSN(),
2591 BPF_MOV32_IMM(R0, 1),
2592 BPF_EXIT_INSN(),
2593 },
2594 INTERNAL,
2595 { },
2596 { { 0, 0x1 } },
2597 },
Johan Almbladh565731a2021-08-09 11:18:17 +02002598 {
2599 "ALU64_MOV_K: small negative",
2600 .u.insns_int = {
2601 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2602 BPF_EXIT_INSN(),
2603 },
2604 INTERNAL,
2605 { },
2606 { { 0, -123 } }
2607 },
2608 {
2609 "ALU64_MOV_K: small negative sign extension",
2610 .u.insns_int = {
2611 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2612 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2613 BPF_EXIT_INSN(),
2614 },
2615 INTERNAL,
2616 { },
2617 { { 0, 0xffffffff } }
2618 },
2619 {
2620 "ALU64_MOV_K: large negative",
2621 .u.insns_int = {
2622 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2623 BPF_EXIT_INSN(),
2624 },
2625 INTERNAL,
2626 { },
2627 { { 0, -123456789 } }
2628 },
2629 {
2630 "ALU64_MOV_K: large negative sign extension",
2631 .u.insns_int = {
2632 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2633 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2634 BPF_EXIT_INSN(),
2635 },
2636 INTERNAL,
2637 { },
2638 { { 0, 0xffffffff } }
2639 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002640 /* BPF_ALU | BPF_ADD | BPF_X */
2641 {
2642 "ALU_ADD_X: 1 + 2 = 3",
2643 .u.insns_int = {
2644 BPF_LD_IMM64(R0, 1),
2645 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2646 BPF_ALU32_REG(BPF_ADD, R0, R1),
2647 BPF_EXIT_INSN(),
2648 },
2649 INTERNAL,
2650 { },
2651 { { 0, 3 } },
2652 },
2653 {
2654 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2655 .u.insns_int = {
2656 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002657 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002658 BPF_ALU32_REG(BPF_ADD, R0, R1),
2659 BPF_EXIT_INSN(),
2660 },
2661 INTERNAL,
2662 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002663 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002664 },
2665 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302666 "ALU_ADD_X: 2 + 4294967294 = 0",
2667 .u.insns_int = {
2668 BPF_LD_IMM64(R0, 2),
2669 BPF_LD_IMM64(R1, 4294967294U),
2670 BPF_ALU32_REG(BPF_ADD, R0, R1),
2671 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2672 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2673 BPF_EXIT_INSN(),
2674 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2675 BPF_EXIT_INSN(),
2676 },
2677 INTERNAL,
2678 { },
2679 { { 0, 1 } },
2680 },
2681 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002682 "ALU64_ADD_X: 1 + 2 = 3",
2683 .u.insns_int = {
2684 BPF_LD_IMM64(R0, 1),
2685 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2686 BPF_ALU64_REG(BPF_ADD, R0, R1),
2687 BPF_EXIT_INSN(),
2688 },
2689 INTERNAL,
2690 { },
2691 { { 0, 3 } },
2692 },
2693 {
2694 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2695 .u.insns_int = {
2696 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002697 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002698 BPF_ALU64_REG(BPF_ADD, R0, R1),
2699 BPF_EXIT_INSN(),
2700 },
2701 INTERNAL,
2702 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002703 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002704 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302705 {
2706 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2707 .u.insns_int = {
2708 BPF_LD_IMM64(R0, 2),
2709 BPF_LD_IMM64(R1, 4294967294U),
2710 BPF_LD_IMM64(R2, 4294967296ULL),
2711 BPF_ALU64_REG(BPF_ADD, R0, R1),
2712 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2713 BPF_MOV32_IMM(R0, 0),
2714 BPF_EXIT_INSN(),
2715 BPF_MOV32_IMM(R0, 1),
2716 BPF_EXIT_INSN(),
2717 },
2718 INTERNAL,
2719 { },
2720 { { 0, 1 } },
2721 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002722 /* BPF_ALU | BPF_ADD | BPF_K */
2723 {
2724 "ALU_ADD_K: 1 + 2 = 3",
2725 .u.insns_int = {
2726 BPF_LD_IMM64(R0, 1),
2727 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2728 BPF_EXIT_INSN(),
2729 },
2730 INTERNAL,
2731 { },
2732 { { 0, 3 } },
2733 },
2734 {
2735 "ALU_ADD_K: 3 + 0 = 3",
2736 .u.insns_int = {
2737 BPF_LD_IMM64(R0, 3),
2738 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2739 BPF_EXIT_INSN(),
2740 },
2741 INTERNAL,
2742 { },
2743 { { 0, 3 } },
2744 },
2745 {
2746 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2747 .u.insns_int = {
2748 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002749 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002750 BPF_EXIT_INSN(),
2751 },
2752 INTERNAL,
2753 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002754 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002755 },
2756 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302757 "ALU_ADD_K: 4294967294 + 2 = 0",
2758 .u.insns_int = {
2759 BPF_LD_IMM64(R0, 4294967294U),
2760 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2761 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2762 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2763 BPF_EXIT_INSN(),
2764 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2765 BPF_EXIT_INSN(),
2766 },
2767 INTERNAL,
2768 { },
2769 { { 0, 1 } },
2770 },
2771 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002772 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2773 .u.insns_int = {
2774 BPF_LD_IMM64(R2, 0x0),
2775 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2776 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
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 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302788 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2789 .u.insns_int = {
2790 BPF_LD_IMM64(R2, 0x0),
2791 BPF_LD_IMM64(R3, 0xffff),
2792 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
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 },
2803 {
2804 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2805 .u.insns_int = {
2806 BPF_LD_IMM64(R2, 0x0),
2807 BPF_LD_IMM64(R3, 0x7fffffff),
2808 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2809 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2810 BPF_MOV32_IMM(R0, 2),
2811 BPF_EXIT_INSN(),
2812 BPF_MOV32_IMM(R0, 1),
2813 BPF_EXIT_INSN(),
2814 },
2815 INTERNAL,
2816 { },
2817 { { 0, 0x1 } },
2818 },
2819 {
2820 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2821 .u.insns_int = {
2822 BPF_LD_IMM64(R2, 0x0),
2823 BPF_LD_IMM64(R3, 0x80000000),
2824 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2825 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2826 BPF_MOV32_IMM(R0, 2),
2827 BPF_EXIT_INSN(),
2828 BPF_MOV32_IMM(R0, 1),
2829 BPF_EXIT_INSN(),
2830 },
2831 INTERNAL,
2832 { },
2833 { { 0, 0x1 } },
2834 },
2835 {
2836 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2837 .u.insns_int = {
2838 BPF_LD_IMM64(R2, 0x0),
2839 BPF_LD_IMM64(R3, 0x80008000),
2840 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2841 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2842 BPF_MOV32_IMM(R0, 2),
2843 BPF_EXIT_INSN(),
2844 BPF_MOV32_IMM(R0, 1),
2845 BPF_EXIT_INSN(),
2846 },
2847 INTERNAL,
2848 { },
2849 { { 0, 0x1 } },
2850 },
2851 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002852 "ALU64_ADD_K: 1 + 2 = 3",
2853 .u.insns_int = {
2854 BPF_LD_IMM64(R0, 1),
2855 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2856 BPF_EXIT_INSN(),
2857 },
2858 INTERNAL,
2859 { },
2860 { { 0, 3 } },
2861 },
2862 {
2863 "ALU64_ADD_K: 3 + 0 = 3",
2864 .u.insns_int = {
2865 BPF_LD_IMM64(R0, 3),
2866 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2867 BPF_EXIT_INSN(),
2868 },
2869 INTERNAL,
2870 { },
2871 { { 0, 3 } },
2872 },
2873 {
2874 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2875 .u.insns_int = {
2876 BPF_LD_IMM64(R0, 1),
2877 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2878 BPF_EXIT_INSN(),
2879 },
2880 INTERNAL,
2881 { },
2882 { { 0, 2147483647 } },
2883 },
2884 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302885 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2886 .u.insns_int = {
2887 BPF_LD_IMM64(R0, 4294967294U),
2888 BPF_LD_IMM64(R1, 4294967296ULL),
2889 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2890 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2891 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2892 BPF_EXIT_INSN(),
2893 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2894 BPF_EXIT_INSN(),
2895 },
2896 INTERNAL,
2897 { },
2898 { { 0, 1 } },
2899 },
2900 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002901 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2902 .u.insns_int = {
2903 BPF_LD_IMM64(R0, 2147483646),
2904 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2905 BPF_EXIT_INSN(),
2906 },
2907 INTERNAL,
2908 { },
2909 { { 0, -1 } },
2910 },
2911 {
2912 "ALU64_ADD_K: 1 + 0 = 1",
2913 .u.insns_int = {
2914 BPF_LD_IMM64(R2, 0x1),
2915 BPF_LD_IMM64(R3, 0x1),
2916 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2917 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2918 BPF_MOV32_IMM(R0, 2),
2919 BPF_EXIT_INSN(),
2920 BPF_MOV32_IMM(R0, 1),
2921 BPF_EXIT_INSN(),
2922 },
2923 INTERNAL,
2924 { },
2925 { { 0, 0x1 } },
2926 },
2927 {
2928 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2929 .u.insns_int = {
2930 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002931 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002932 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2933 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2934 BPF_MOV32_IMM(R0, 2),
2935 BPF_EXIT_INSN(),
2936 BPF_MOV32_IMM(R0, 1),
2937 BPF_EXIT_INSN(),
2938 },
2939 INTERNAL,
2940 { },
2941 { { 0, 0x1 } },
2942 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302943 {
2944 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2945 .u.insns_int = {
2946 BPF_LD_IMM64(R2, 0x0),
2947 BPF_LD_IMM64(R3, 0xffff),
2948 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2949 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2950 BPF_MOV32_IMM(R0, 2),
2951 BPF_EXIT_INSN(),
2952 BPF_MOV32_IMM(R0, 1),
2953 BPF_EXIT_INSN(),
2954 },
2955 INTERNAL,
2956 { },
2957 { { 0, 0x1 } },
2958 },
2959 {
2960 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2961 .u.insns_int = {
2962 BPF_LD_IMM64(R2, 0x0),
2963 BPF_LD_IMM64(R3, 0x7fffffff),
2964 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2965 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2966 BPF_MOV32_IMM(R0, 2),
2967 BPF_EXIT_INSN(),
2968 BPF_MOV32_IMM(R0, 1),
2969 BPF_EXIT_INSN(),
2970 },
2971 INTERNAL,
2972 { },
2973 { { 0, 0x1 } },
2974 },
2975 {
2976 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2977 .u.insns_int = {
2978 BPF_LD_IMM64(R2, 0x0),
2979 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2980 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2981 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2982 BPF_MOV32_IMM(R0, 2),
2983 BPF_EXIT_INSN(),
2984 BPF_MOV32_IMM(R0, 1),
2985 BPF_EXIT_INSN(),
2986 },
2987 INTERNAL,
2988 { },
2989 { { 0, 0x1 } },
2990 },
2991 {
2992 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2993 .u.insns_int = {
2994 BPF_LD_IMM64(R2, 0x0),
2995 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2996 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2997 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2998 BPF_MOV32_IMM(R0, 2),
2999 BPF_EXIT_INSN(),
3000 BPF_MOV32_IMM(R0, 1),
3001 BPF_EXIT_INSN(),
3002 },
3003 INTERNAL,
3004 { },
3005 { { 0, 0x1 } },
3006 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003007 /* BPF_ALU | BPF_SUB | BPF_X */
3008 {
3009 "ALU_SUB_X: 3 - 1 = 2",
3010 .u.insns_int = {
3011 BPF_LD_IMM64(R0, 3),
3012 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3013 BPF_ALU32_REG(BPF_SUB, R0, R1),
3014 BPF_EXIT_INSN(),
3015 },
3016 INTERNAL,
3017 { },
3018 { { 0, 2 } },
3019 },
3020 {
3021 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
3022 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003023 BPF_LD_IMM64(R0, 4294967295U),
3024 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003025 BPF_ALU32_REG(BPF_SUB, R0, R1),
3026 BPF_EXIT_INSN(),
3027 },
3028 INTERNAL,
3029 { },
3030 { { 0, 1 } },
3031 },
3032 {
3033 "ALU64_SUB_X: 3 - 1 = 2",
3034 .u.insns_int = {
3035 BPF_LD_IMM64(R0, 3),
3036 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3037 BPF_ALU64_REG(BPF_SUB, R0, R1),
3038 BPF_EXIT_INSN(),
3039 },
3040 INTERNAL,
3041 { },
3042 { { 0, 2 } },
3043 },
3044 {
3045 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
3046 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003047 BPF_LD_IMM64(R0, 4294967295U),
3048 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003049 BPF_ALU64_REG(BPF_SUB, R0, R1),
3050 BPF_EXIT_INSN(),
3051 },
3052 INTERNAL,
3053 { },
3054 { { 0, 1 } },
3055 },
3056 /* BPF_ALU | BPF_SUB | BPF_K */
3057 {
3058 "ALU_SUB_K: 3 - 1 = 2",
3059 .u.insns_int = {
3060 BPF_LD_IMM64(R0, 3),
3061 BPF_ALU32_IMM(BPF_SUB, R0, 1),
3062 BPF_EXIT_INSN(),
3063 },
3064 INTERNAL,
3065 { },
3066 { { 0, 2 } },
3067 },
3068 {
3069 "ALU_SUB_K: 3 - 0 = 3",
3070 .u.insns_int = {
3071 BPF_LD_IMM64(R0, 3),
3072 BPF_ALU32_IMM(BPF_SUB, R0, 0),
3073 BPF_EXIT_INSN(),
3074 },
3075 INTERNAL,
3076 { },
3077 { { 0, 3 } },
3078 },
3079 {
3080 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
3081 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003082 BPF_LD_IMM64(R0, 4294967295U),
3083 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003084 BPF_EXIT_INSN(),
3085 },
3086 INTERNAL,
3087 { },
3088 { { 0, 1 } },
3089 },
3090 {
3091 "ALU64_SUB_K: 3 - 1 = 2",
3092 .u.insns_int = {
3093 BPF_LD_IMM64(R0, 3),
3094 BPF_ALU64_IMM(BPF_SUB, R0, 1),
3095 BPF_EXIT_INSN(),
3096 },
3097 INTERNAL,
3098 { },
3099 { { 0, 2 } },
3100 },
3101 {
3102 "ALU64_SUB_K: 3 - 0 = 3",
3103 .u.insns_int = {
3104 BPF_LD_IMM64(R0, 3),
3105 BPF_ALU64_IMM(BPF_SUB, R0, 0),
3106 BPF_EXIT_INSN(),
3107 },
3108 INTERNAL,
3109 { },
3110 { { 0, 3 } },
3111 },
3112 {
3113 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3114 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003115 BPF_LD_IMM64(R0, 4294967294U),
3116 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003117 BPF_EXIT_INSN(),
3118 },
3119 INTERNAL,
3120 { },
3121 { { 0, -1 } },
3122 },
3123 {
3124 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3125 .u.insns_int = {
3126 BPF_LD_IMM64(R0, 2147483646),
3127 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
3128 BPF_EXIT_INSN(),
3129 },
3130 INTERNAL,
3131 { },
3132 { { 0, -1 } },
3133 },
3134 /* BPF_ALU | BPF_MUL | BPF_X */
3135 {
3136 "ALU_MUL_X: 2 * 3 = 6",
3137 .u.insns_int = {
3138 BPF_LD_IMM64(R0, 2),
3139 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3140 BPF_ALU32_REG(BPF_MUL, R0, R1),
3141 BPF_EXIT_INSN(),
3142 },
3143 INTERNAL,
3144 { },
3145 { { 0, 6 } },
3146 },
3147 {
3148 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3149 .u.insns_int = {
3150 BPF_LD_IMM64(R0, 2),
3151 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
3152 BPF_ALU32_REG(BPF_MUL, R0, R1),
3153 BPF_EXIT_INSN(),
3154 },
3155 INTERNAL,
3156 { },
3157 { { 0, 0xFFFFFFF0 } },
3158 },
3159 {
3160 "ALU_MUL_X: -1 * -1 = 1",
3161 .u.insns_int = {
3162 BPF_LD_IMM64(R0, -1),
3163 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3164 BPF_ALU32_REG(BPF_MUL, R0, R1),
3165 BPF_EXIT_INSN(),
3166 },
3167 INTERNAL,
3168 { },
3169 { { 0, 1 } },
3170 },
3171 {
3172 "ALU64_MUL_X: 2 * 3 = 6",
3173 .u.insns_int = {
3174 BPF_LD_IMM64(R0, 2),
3175 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3176 BPF_ALU64_REG(BPF_MUL, R0, R1),
3177 BPF_EXIT_INSN(),
3178 },
3179 INTERNAL,
3180 { },
3181 { { 0, 6 } },
3182 },
3183 {
3184 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3185 .u.insns_int = {
3186 BPF_LD_IMM64(R0, 1),
3187 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3188 BPF_ALU64_REG(BPF_MUL, R0, R1),
3189 BPF_EXIT_INSN(),
3190 },
3191 INTERNAL,
3192 { },
3193 { { 0, 2147483647 } },
3194 },
Johan Almbladhfaa57622021-08-09 11:18:22 +02003195 {
3196 "ALU64_MUL_X: 64x64 multiply, low word",
3197 .u.insns_int = {
3198 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3199 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3200 BPF_ALU64_REG(BPF_MUL, R0, R1),
3201 BPF_EXIT_INSN(),
3202 },
3203 INTERNAL,
3204 { },
3205 { { 0, 0xe5618cf0 } }
3206 },
3207 {
3208 "ALU64_MUL_X: 64x64 multiply, high word",
3209 .u.insns_int = {
3210 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3211 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3212 BPF_ALU64_REG(BPF_MUL, R0, R1),
3213 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3214 BPF_EXIT_INSN(),
3215 },
3216 INTERNAL,
3217 { },
3218 { { 0, 0x2236d88f } }
3219 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003220 /* BPF_ALU | BPF_MUL | BPF_K */
3221 {
3222 "ALU_MUL_K: 2 * 3 = 6",
3223 .u.insns_int = {
3224 BPF_LD_IMM64(R0, 2),
3225 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3226 BPF_EXIT_INSN(),
3227 },
3228 INTERNAL,
3229 { },
3230 { { 0, 6 } },
3231 },
3232 {
3233 "ALU_MUL_K: 3 * 1 = 3",
3234 .u.insns_int = {
3235 BPF_LD_IMM64(R0, 3),
3236 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3237 BPF_EXIT_INSN(),
3238 },
3239 INTERNAL,
3240 { },
3241 { { 0, 3 } },
3242 },
3243 {
3244 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3245 .u.insns_int = {
3246 BPF_LD_IMM64(R0, 2),
3247 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3248 BPF_EXIT_INSN(),
3249 },
3250 INTERNAL,
3251 { },
3252 { { 0, 0xFFFFFFF0 } },
3253 },
3254 {
3255 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3256 .u.insns_int = {
3257 BPF_LD_IMM64(R2, 0x1),
3258 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3259 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3260 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3261 BPF_MOV32_IMM(R0, 2),
3262 BPF_EXIT_INSN(),
3263 BPF_MOV32_IMM(R0, 1),
3264 BPF_EXIT_INSN(),
3265 },
3266 INTERNAL,
3267 { },
3268 { { 0, 0x1 } },
3269 },
3270 {
3271 "ALU64_MUL_K: 2 * 3 = 6",
3272 .u.insns_int = {
3273 BPF_LD_IMM64(R0, 2),
3274 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3275 BPF_EXIT_INSN(),
3276 },
3277 INTERNAL,
3278 { },
3279 { { 0, 6 } },
3280 },
3281 {
3282 "ALU64_MUL_K: 3 * 1 = 3",
3283 .u.insns_int = {
3284 BPF_LD_IMM64(R0, 3),
3285 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3286 BPF_EXIT_INSN(),
3287 },
3288 INTERNAL,
3289 { },
3290 { { 0, 3 } },
3291 },
3292 {
3293 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3294 .u.insns_int = {
3295 BPF_LD_IMM64(R0, 1),
3296 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3297 BPF_EXIT_INSN(),
3298 },
3299 INTERNAL,
3300 { },
3301 { { 0, 2147483647 } },
3302 },
3303 {
3304 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3305 .u.insns_int = {
3306 BPF_LD_IMM64(R0, 1),
3307 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3308 BPF_EXIT_INSN(),
3309 },
3310 INTERNAL,
3311 { },
3312 { { 0, -2147483647 } },
3313 },
3314 {
3315 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3316 .u.insns_int = {
3317 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003318 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003319 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3320 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3321 BPF_MOV32_IMM(R0, 2),
3322 BPF_EXIT_INSN(),
3323 BPF_MOV32_IMM(R0, 1),
3324 BPF_EXIT_INSN(),
3325 },
3326 INTERNAL,
3327 { },
3328 { { 0, 0x1 } },
3329 },
Johan Almbladhfaa57622021-08-09 11:18:22 +02003330 {
3331 "ALU64_MUL_K: 64x32 multiply, low word",
3332 .u.insns_int = {
3333 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3334 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3335 BPF_EXIT_INSN(),
3336 },
3337 INTERNAL,
3338 { },
3339 { { 0, 0xe242d208 } }
3340 },
3341 {
3342 "ALU64_MUL_K: 64x32 multiply, high word",
3343 .u.insns_int = {
3344 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3345 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3346 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3347 BPF_EXIT_INSN(),
3348 },
3349 INTERNAL,
3350 { },
3351 { { 0, 0xc28f5c28 } }
3352 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003353 /* BPF_ALU | BPF_DIV | BPF_X */
3354 {
3355 "ALU_DIV_X: 6 / 2 = 3",
3356 .u.insns_int = {
3357 BPF_LD_IMM64(R0, 6),
3358 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3359 BPF_ALU32_REG(BPF_DIV, R0, R1),
3360 BPF_EXIT_INSN(),
3361 },
3362 INTERNAL,
3363 { },
3364 { { 0, 3 } },
3365 },
3366 {
3367 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3368 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003369 BPF_LD_IMM64(R0, 4294967295U),
3370 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003371 BPF_ALU32_REG(BPF_DIV, R0, R1),
3372 BPF_EXIT_INSN(),
3373 },
3374 INTERNAL,
3375 { },
3376 { { 0, 1 } },
3377 },
3378 {
3379 "ALU64_DIV_X: 6 / 2 = 3",
3380 .u.insns_int = {
3381 BPF_LD_IMM64(R0, 6),
3382 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3383 BPF_ALU64_REG(BPF_DIV, R0, R1),
3384 BPF_EXIT_INSN(),
3385 },
3386 INTERNAL,
3387 { },
3388 { { 0, 3 } },
3389 },
3390 {
3391 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3392 .u.insns_int = {
3393 BPF_LD_IMM64(R0, 2147483647),
3394 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3395 BPF_ALU64_REG(BPF_DIV, R0, R1),
3396 BPF_EXIT_INSN(),
3397 },
3398 INTERNAL,
3399 { },
3400 { { 0, 1 } },
3401 },
3402 {
3403 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3404 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003405 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3406 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3407 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003408 BPF_ALU64_REG(BPF_DIV, R2, R4),
3409 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3410 BPF_MOV32_IMM(R0, 2),
3411 BPF_EXIT_INSN(),
3412 BPF_MOV32_IMM(R0, 1),
3413 BPF_EXIT_INSN(),
3414 },
3415 INTERNAL,
3416 { },
3417 { { 0, 0x1 } },
3418 },
3419 /* BPF_ALU | BPF_DIV | BPF_K */
3420 {
3421 "ALU_DIV_K: 6 / 2 = 3",
3422 .u.insns_int = {
3423 BPF_LD_IMM64(R0, 6),
3424 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3425 BPF_EXIT_INSN(),
3426 },
3427 INTERNAL,
3428 { },
3429 { { 0, 3 } },
3430 },
3431 {
3432 "ALU_DIV_K: 3 / 1 = 3",
3433 .u.insns_int = {
3434 BPF_LD_IMM64(R0, 3),
3435 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3436 BPF_EXIT_INSN(),
3437 },
3438 INTERNAL,
3439 { },
3440 { { 0, 3 } },
3441 },
3442 {
3443 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3444 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003445 BPF_LD_IMM64(R0, 4294967295U),
3446 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003447 BPF_EXIT_INSN(),
3448 },
3449 INTERNAL,
3450 { },
3451 { { 0, 1 } },
3452 },
3453 {
3454 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3455 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003456 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003457 BPF_LD_IMM64(R3, 0x1UL),
3458 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3459 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3460 BPF_MOV32_IMM(R0, 2),
3461 BPF_EXIT_INSN(),
3462 BPF_MOV32_IMM(R0, 1),
3463 BPF_EXIT_INSN(),
3464 },
3465 INTERNAL,
3466 { },
3467 { { 0, 0x1 } },
3468 },
3469 {
3470 "ALU64_DIV_K: 6 / 2 = 3",
3471 .u.insns_int = {
3472 BPF_LD_IMM64(R0, 6),
3473 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3474 BPF_EXIT_INSN(),
3475 },
3476 INTERNAL,
3477 { },
3478 { { 0, 3 } },
3479 },
3480 {
3481 "ALU64_DIV_K: 3 / 1 = 3",
3482 .u.insns_int = {
3483 BPF_LD_IMM64(R0, 3),
3484 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3485 BPF_EXIT_INSN(),
3486 },
3487 INTERNAL,
3488 { },
3489 { { 0, 3 } },
3490 },
3491 {
3492 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3493 .u.insns_int = {
3494 BPF_LD_IMM64(R0, 2147483647),
3495 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3496 BPF_EXIT_INSN(),
3497 },
3498 INTERNAL,
3499 { },
3500 { { 0, 1 } },
3501 },
3502 {
3503 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3504 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003505 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3506 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003507 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3508 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3509 BPF_MOV32_IMM(R0, 2),
3510 BPF_EXIT_INSN(),
3511 BPF_MOV32_IMM(R0, 1),
3512 BPF_EXIT_INSN(),
3513 },
3514 INTERNAL,
3515 { },
3516 { { 0, 0x1 } },
3517 },
3518 /* BPF_ALU | BPF_MOD | BPF_X */
3519 {
3520 "ALU_MOD_X: 3 % 2 = 1",
3521 .u.insns_int = {
3522 BPF_LD_IMM64(R0, 3),
3523 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3524 BPF_ALU32_REG(BPF_MOD, R0, R1),
3525 BPF_EXIT_INSN(),
3526 },
3527 INTERNAL,
3528 { },
3529 { { 0, 1 } },
3530 },
3531 {
3532 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3533 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003534 BPF_LD_IMM64(R0, 4294967295U),
3535 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003536 BPF_ALU32_REG(BPF_MOD, R0, R1),
3537 BPF_EXIT_INSN(),
3538 },
3539 INTERNAL,
3540 { },
3541 { { 0, 2 } },
3542 },
3543 {
3544 "ALU64_MOD_X: 3 % 2 = 1",
3545 .u.insns_int = {
3546 BPF_LD_IMM64(R0, 3),
3547 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3548 BPF_ALU64_REG(BPF_MOD, R0, R1),
3549 BPF_EXIT_INSN(),
3550 },
3551 INTERNAL,
3552 { },
3553 { { 0, 1 } },
3554 },
3555 {
3556 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3557 .u.insns_int = {
3558 BPF_LD_IMM64(R0, 2147483647),
3559 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3560 BPF_ALU64_REG(BPF_MOD, R0, R1),
3561 BPF_EXIT_INSN(),
3562 },
3563 INTERNAL,
3564 { },
3565 { { 0, 2 } },
3566 },
3567 /* BPF_ALU | BPF_MOD | BPF_K */
3568 {
3569 "ALU_MOD_K: 3 % 2 = 1",
3570 .u.insns_int = {
3571 BPF_LD_IMM64(R0, 3),
3572 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3573 BPF_EXIT_INSN(),
3574 },
3575 INTERNAL,
3576 { },
3577 { { 0, 1 } },
3578 },
3579 {
3580 "ALU_MOD_K: 3 % 1 = 0",
3581 .u.insns_int = {
3582 BPF_LD_IMM64(R0, 3),
3583 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3584 BPF_EXIT_INSN(),
3585 },
3586 INTERNAL,
3587 { },
3588 { { 0, 0 } },
3589 },
3590 {
3591 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3592 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003593 BPF_LD_IMM64(R0, 4294967295U),
3594 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003595 BPF_EXIT_INSN(),
3596 },
3597 INTERNAL,
3598 { },
3599 { { 0, 2 } },
3600 },
3601 {
3602 "ALU64_MOD_K: 3 % 2 = 1",
3603 .u.insns_int = {
3604 BPF_LD_IMM64(R0, 3),
3605 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3606 BPF_EXIT_INSN(),
3607 },
3608 INTERNAL,
3609 { },
3610 { { 0, 1 } },
3611 },
3612 {
3613 "ALU64_MOD_K: 3 % 1 = 0",
3614 .u.insns_int = {
3615 BPF_LD_IMM64(R0, 3),
3616 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3617 BPF_EXIT_INSN(),
3618 },
3619 INTERNAL,
3620 { },
3621 { { 0, 0 } },
3622 },
3623 {
3624 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3625 .u.insns_int = {
3626 BPF_LD_IMM64(R0, 2147483647),
3627 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3628 BPF_EXIT_INSN(),
3629 },
3630 INTERNAL,
3631 { },
3632 { { 0, 2 } },
3633 },
3634 /* BPF_ALU | BPF_AND | BPF_X */
3635 {
3636 "ALU_AND_X: 3 & 2 = 2",
3637 .u.insns_int = {
3638 BPF_LD_IMM64(R0, 3),
3639 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3640 BPF_ALU32_REG(BPF_AND, R0, R1),
3641 BPF_EXIT_INSN(),
3642 },
3643 INTERNAL,
3644 { },
3645 { { 0, 2 } },
3646 },
3647 {
3648 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3649 .u.insns_int = {
3650 BPF_LD_IMM64(R0, 0xffffffff),
3651 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3652 BPF_ALU32_REG(BPF_AND, R0, R1),
3653 BPF_EXIT_INSN(),
3654 },
3655 INTERNAL,
3656 { },
3657 { { 0, 0xffffffff } },
3658 },
3659 {
3660 "ALU64_AND_X: 3 & 2 = 2",
3661 .u.insns_int = {
3662 BPF_LD_IMM64(R0, 3),
3663 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3664 BPF_ALU64_REG(BPF_AND, R0, R1),
3665 BPF_EXIT_INSN(),
3666 },
3667 INTERNAL,
3668 { },
3669 { { 0, 2 } },
3670 },
3671 {
3672 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3673 .u.insns_int = {
3674 BPF_LD_IMM64(R0, 0xffffffff),
3675 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3676 BPF_ALU64_REG(BPF_AND, R0, R1),
3677 BPF_EXIT_INSN(),
3678 },
3679 INTERNAL,
3680 { },
3681 { { 0, 0xffffffff } },
3682 },
3683 /* BPF_ALU | BPF_AND | BPF_K */
3684 {
3685 "ALU_AND_K: 3 & 2 = 2",
3686 .u.insns_int = {
3687 BPF_LD_IMM64(R0, 3),
3688 BPF_ALU32_IMM(BPF_AND, R0, 2),
3689 BPF_EXIT_INSN(),
3690 },
3691 INTERNAL,
3692 { },
3693 { { 0, 2 } },
3694 },
3695 {
3696 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3697 .u.insns_int = {
3698 BPF_LD_IMM64(R0, 0xffffffff),
3699 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3700 BPF_EXIT_INSN(),
3701 },
3702 INTERNAL,
3703 { },
3704 { { 0, 0xffffffff } },
3705 },
3706 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003707 "ALU_AND_K: Small immediate",
3708 .u.insns_int = {
3709 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3710 BPF_ALU32_IMM(BPF_AND, R0, 15),
3711 BPF_EXIT_INSN(),
3712 },
3713 INTERNAL,
3714 { },
3715 { { 0, 4 } }
3716 },
3717 {
3718 "ALU_AND_K: Large immediate",
3719 .u.insns_int = {
3720 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
3721 BPF_ALU32_IMM(BPF_AND, R0, 0xafbfcfdf),
3722 BPF_EXIT_INSN(),
3723 },
3724 INTERNAL,
3725 { },
3726 { { 0, 0xa1b2c3d4 } }
3727 },
3728 {
3729 "ALU_AND_K: Zero extension",
3730 .u.insns_int = {
3731 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3732 BPF_LD_IMM64(R1, 0x0000000080a0c0e0LL),
3733 BPF_ALU32_IMM(BPF_AND, R0, 0xf0f0f0f0),
3734 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3735 BPF_MOV32_IMM(R0, 2),
3736 BPF_EXIT_INSN(),
3737 BPF_MOV32_IMM(R0, 1),
3738 BPF_EXIT_INSN(),
3739 },
3740 INTERNAL,
3741 { },
3742 { { 0, 1 } }
3743 },
3744 {
Michael Holzheucffc6422015-05-11 22:22:44 -07003745 "ALU64_AND_K: 3 & 2 = 2",
3746 .u.insns_int = {
3747 BPF_LD_IMM64(R0, 3),
3748 BPF_ALU64_IMM(BPF_AND, R0, 2),
3749 BPF_EXIT_INSN(),
3750 },
3751 INTERNAL,
3752 { },
3753 { { 0, 2 } },
3754 },
3755 {
3756 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3757 .u.insns_int = {
3758 BPF_LD_IMM64(R0, 0xffffffff),
3759 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3760 BPF_EXIT_INSN(),
3761 },
3762 INTERNAL,
3763 { },
3764 { { 0, 0xffffffff } },
3765 },
3766 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003767 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000000000000000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003768 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003769 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3770 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003771 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3772 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3773 BPF_MOV32_IMM(R0, 2),
3774 BPF_EXIT_INSN(),
3775 BPF_MOV32_IMM(R0, 1),
3776 BPF_EXIT_INSN(),
3777 },
3778 INTERNAL,
3779 { },
3780 { { 0, 0x1 } },
3781 },
3782 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003783 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffff0000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003784 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003785 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3786 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003787 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3788 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3789 BPF_MOV32_IMM(R0, 2),
3790 BPF_EXIT_INSN(),
3791 BPF_MOV32_IMM(R0, 1),
3792 BPF_EXIT_INSN(),
3793 },
3794 INTERNAL,
3795 { },
3796 { { 0, 0x1 } },
3797 },
3798 {
3799 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3800 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003801 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3802 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003803 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3804 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3805 BPF_MOV32_IMM(R0, 2),
3806 BPF_EXIT_INSN(),
3807 BPF_MOV32_IMM(R0, 1),
3808 BPF_EXIT_INSN(),
3809 },
3810 INTERNAL,
3811 { },
3812 { { 0, 0x1 } },
3813 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003814 {
3815 "ALU64_AND_K: Sign extension 1",
3816 .u.insns_int = {
3817 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3818 BPF_LD_IMM64(R1, 0x00000000090b0d0fLL),
3819 BPF_ALU64_IMM(BPF_AND, R0, 0x0f0f0f0f),
3820 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3821 BPF_MOV32_IMM(R0, 2),
3822 BPF_EXIT_INSN(),
3823 BPF_MOV32_IMM(R0, 1),
3824 BPF_EXIT_INSN(),
3825 },
3826 INTERNAL,
3827 { },
3828 { { 0, 1 } }
3829 },
3830 {
3831 "ALU64_AND_K: Sign extension 2",
3832 .u.insns_int = {
3833 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3834 BPF_LD_IMM64(R1, 0x0123456780a0c0e0LL),
3835 BPF_ALU64_IMM(BPF_AND, R0, 0xf0f0f0f0),
3836 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3837 BPF_MOV32_IMM(R0, 2),
3838 BPF_EXIT_INSN(),
3839 BPF_MOV32_IMM(R0, 1),
3840 BPF_EXIT_INSN(),
3841 },
3842 INTERNAL,
3843 { },
3844 { { 0, 1 } }
3845 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003846 /* BPF_ALU | BPF_OR | BPF_X */
3847 {
3848 "ALU_OR_X: 1 | 2 = 3",
3849 .u.insns_int = {
3850 BPF_LD_IMM64(R0, 1),
3851 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3852 BPF_ALU32_REG(BPF_OR, R0, R1),
3853 BPF_EXIT_INSN(),
3854 },
3855 INTERNAL,
3856 { },
3857 { { 0, 3 } },
3858 },
3859 {
3860 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3861 .u.insns_int = {
3862 BPF_LD_IMM64(R0, 0),
3863 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3864 BPF_ALU32_REG(BPF_OR, R0, R1),
3865 BPF_EXIT_INSN(),
3866 },
3867 INTERNAL,
3868 { },
3869 { { 0, 0xffffffff } },
3870 },
3871 {
3872 "ALU64_OR_X: 1 | 2 = 3",
3873 .u.insns_int = {
3874 BPF_LD_IMM64(R0, 1),
3875 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3876 BPF_ALU64_REG(BPF_OR, R0, R1),
3877 BPF_EXIT_INSN(),
3878 },
3879 INTERNAL,
3880 { },
3881 { { 0, 3 } },
3882 },
3883 {
3884 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3885 .u.insns_int = {
3886 BPF_LD_IMM64(R0, 0),
3887 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3888 BPF_ALU64_REG(BPF_OR, R0, R1),
3889 BPF_EXIT_INSN(),
3890 },
3891 INTERNAL,
3892 { },
3893 { { 0, 0xffffffff } },
3894 },
3895 /* BPF_ALU | BPF_OR | BPF_K */
3896 {
3897 "ALU_OR_K: 1 | 2 = 3",
3898 .u.insns_int = {
3899 BPF_LD_IMM64(R0, 1),
3900 BPF_ALU32_IMM(BPF_OR, R0, 2),
3901 BPF_EXIT_INSN(),
3902 },
3903 INTERNAL,
3904 { },
3905 { { 0, 3 } },
3906 },
3907 {
3908 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3909 .u.insns_int = {
3910 BPF_LD_IMM64(R0, 0),
3911 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3912 BPF_EXIT_INSN(),
3913 },
3914 INTERNAL,
3915 { },
3916 { { 0, 0xffffffff } },
3917 },
3918 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003919 "ALU_OR_K: Small immediate",
3920 .u.insns_int = {
3921 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3922 BPF_ALU32_IMM(BPF_OR, R0, 1),
3923 BPF_EXIT_INSN(),
3924 },
3925 INTERNAL,
3926 { },
3927 { { 0, 0x01020305 } }
3928 },
3929 {
3930 "ALU_OR_K: Large immediate",
3931 .u.insns_int = {
3932 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3933 BPF_ALU32_IMM(BPF_OR, R0, 0xa0b0c0d0),
3934 BPF_EXIT_INSN(),
3935 },
3936 INTERNAL,
3937 { },
3938 { { 0, 0xa1b2c3d4 } }
3939 },
3940 {
3941 "ALU_OR_K: Zero extension",
3942 .u.insns_int = {
3943 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3944 BPF_LD_IMM64(R1, 0x00000000f9fbfdffLL),
3945 BPF_ALU32_IMM(BPF_OR, R0, 0xf0f0f0f0),
3946 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3947 BPF_MOV32_IMM(R0, 2),
3948 BPF_EXIT_INSN(),
3949 BPF_MOV32_IMM(R0, 1),
3950 BPF_EXIT_INSN(),
3951 },
3952 INTERNAL,
3953 { },
3954 { { 0, 1 } }
3955 },
3956 {
Michael Holzheucffc6422015-05-11 22:22:44 -07003957 "ALU64_OR_K: 1 | 2 = 3",
3958 .u.insns_int = {
3959 BPF_LD_IMM64(R0, 1),
3960 BPF_ALU64_IMM(BPF_OR, R0, 2),
3961 BPF_EXIT_INSN(),
3962 },
3963 INTERNAL,
3964 { },
3965 { { 0, 3 } },
3966 },
3967 {
3968 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3969 .u.insns_int = {
3970 BPF_LD_IMM64(R0, 0),
3971 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3972 BPF_EXIT_INSN(),
3973 },
3974 INTERNAL,
3975 { },
3976 { { 0, 0xffffffff } },
3977 },
3978 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003979 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffffffff0000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003980 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003981 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3982 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003983 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3984 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3985 BPF_MOV32_IMM(R0, 2),
3986 BPF_EXIT_INSN(),
3987 BPF_MOV32_IMM(R0, 1),
3988 BPF_EXIT_INSN(),
3989 },
3990 INTERNAL,
3991 { },
3992 { { 0, 0x1 } },
3993 },
3994 {
3995 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3996 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003997 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3998 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003999 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4000 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4001 BPF_MOV32_IMM(R0, 2),
4002 BPF_EXIT_INSN(),
4003 BPF_MOV32_IMM(R0, 1),
4004 BPF_EXIT_INSN(),
4005 },
4006 INTERNAL,
4007 { },
4008 { { 0, 0x1 } },
4009 },
4010 {
4011 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
4012 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004013 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4014 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004015 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4016 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4017 BPF_MOV32_IMM(R0, 2),
4018 BPF_EXIT_INSN(),
4019 BPF_MOV32_IMM(R0, 1),
4020 BPF_EXIT_INSN(),
4021 },
4022 INTERNAL,
4023 { },
4024 { { 0, 0x1 } },
4025 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004026 {
4027 "ALU64_OR_K: Sign extension 1",
4028 .u.insns_int = {
4029 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4030 BPF_LD_IMM64(R1, 0x012345678fafcfefLL),
4031 BPF_ALU64_IMM(BPF_OR, R0, 0x0f0f0f0f),
4032 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4033 BPF_MOV32_IMM(R0, 2),
4034 BPF_EXIT_INSN(),
4035 BPF_MOV32_IMM(R0, 1),
4036 BPF_EXIT_INSN(),
4037 },
4038 INTERNAL,
4039 { },
4040 { { 0, 1 } }
4041 },
4042 {
4043 "ALU64_OR_K: Sign extension 2",
4044 .u.insns_int = {
4045 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4046 BPF_LD_IMM64(R1, 0xfffffffff9fbfdffLL),
4047 BPF_ALU64_IMM(BPF_OR, R0, 0xf0f0f0f0),
4048 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4049 BPF_MOV32_IMM(R0, 2),
4050 BPF_EXIT_INSN(),
4051 BPF_MOV32_IMM(R0, 1),
4052 BPF_EXIT_INSN(),
4053 },
4054 INTERNAL,
4055 { },
4056 { { 0, 1 } }
4057 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004058 /* BPF_ALU | BPF_XOR | BPF_X */
4059 {
4060 "ALU_XOR_X: 5 ^ 6 = 3",
4061 .u.insns_int = {
4062 BPF_LD_IMM64(R0, 5),
4063 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4064 BPF_ALU32_REG(BPF_XOR, R0, R1),
4065 BPF_EXIT_INSN(),
4066 },
4067 INTERNAL,
4068 { },
4069 { { 0, 3 } },
4070 },
4071 {
4072 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
4073 .u.insns_int = {
4074 BPF_LD_IMM64(R0, 1),
4075 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4076 BPF_ALU32_REG(BPF_XOR, R0, R1),
4077 BPF_EXIT_INSN(),
4078 },
4079 INTERNAL,
4080 { },
4081 { { 0, 0xfffffffe } },
4082 },
4083 {
4084 "ALU64_XOR_X: 5 ^ 6 = 3",
4085 .u.insns_int = {
4086 BPF_LD_IMM64(R0, 5),
4087 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4088 BPF_ALU64_REG(BPF_XOR, R0, R1),
4089 BPF_EXIT_INSN(),
4090 },
4091 INTERNAL,
4092 { },
4093 { { 0, 3 } },
4094 },
4095 {
4096 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
4097 .u.insns_int = {
4098 BPF_LD_IMM64(R0, 1),
4099 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4100 BPF_ALU64_REG(BPF_XOR, R0, R1),
4101 BPF_EXIT_INSN(),
4102 },
4103 INTERNAL,
4104 { },
4105 { { 0, 0xfffffffe } },
4106 },
4107 /* BPF_ALU | BPF_XOR | BPF_K */
4108 {
4109 "ALU_XOR_K: 5 ^ 6 = 3",
4110 .u.insns_int = {
4111 BPF_LD_IMM64(R0, 5),
4112 BPF_ALU32_IMM(BPF_XOR, R0, 6),
4113 BPF_EXIT_INSN(),
4114 },
4115 INTERNAL,
4116 { },
4117 { { 0, 3 } },
4118 },
4119 {
4120 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
4121 .u.insns_int = {
4122 BPF_LD_IMM64(R0, 1),
4123 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
4124 BPF_EXIT_INSN(),
4125 },
4126 INTERNAL,
4127 { },
4128 { { 0, 0xfffffffe } },
4129 },
4130 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004131 "ALU_XOR_K: Small immediate",
4132 .u.insns_int = {
4133 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
4134 BPF_ALU32_IMM(BPF_XOR, R0, 15),
4135 BPF_EXIT_INSN(),
4136 },
4137 INTERNAL,
4138 { },
4139 { { 0, 0x0102030b } }
4140 },
4141 {
4142 "ALU_XOR_K: Large immediate",
4143 .u.insns_int = {
4144 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
4145 BPF_ALU32_IMM(BPF_XOR, R0, 0xafbfcfdf),
4146 BPF_EXIT_INSN(),
4147 },
4148 INTERNAL,
4149 { },
4150 { { 0, 0x5e4d3c2b } }
4151 },
4152 {
4153 "ALU_XOR_K: Zero extension",
4154 .u.insns_int = {
4155 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4156 BPF_LD_IMM64(R1, 0x00000000795b3d1fLL),
4157 BPF_ALU32_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4158 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4159 BPF_MOV32_IMM(R0, 2),
4160 BPF_EXIT_INSN(),
4161 BPF_MOV32_IMM(R0, 1),
4162 BPF_EXIT_INSN(),
4163 },
4164 INTERNAL,
4165 { },
4166 { { 0, 1 } }
4167 },
4168 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004169 "ALU64_XOR_K: 5 ^ 6 = 3",
4170 .u.insns_int = {
4171 BPF_LD_IMM64(R0, 5),
4172 BPF_ALU64_IMM(BPF_XOR, R0, 6),
4173 BPF_EXIT_INSN(),
4174 },
4175 INTERNAL,
4176 { },
4177 { { 0, 3 } },
4178 },
4179 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02004180 "ALU64_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
Michael Holzheucffc6422015-05-11 22:22:44 -07004181 .u.insns_int = {
4182 BPF_LD_IMM64(R0, 1),
4183 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
4184 BPF_EXIT_INSN(),
4185 },
4186 INTERNAL,
4187 { },
4188 { { 0, 0xfffffffe } },
4189 },
4190 {
4191 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
4192 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004193 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4194 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004195 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
4196 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4197 BPF_MOV32_IMM(R0, 2),
4198 BPF_EXIT_INSN(),
4199 BPF_MOV32_IMM(R0, 1),
4200 BPF_EXIT_INSN(),
4201 },
4202 INTERNAL,
4203 { },
4204 { { 0, 0x1 } },
4205 },
4206 {
4207 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
4208 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004209 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4210 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004211 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4212 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4213 BPF_MOV32_IMM(R0, 2),
4214 BPF_EXIT_INSN(),
4215 BPF_MOV32_IMM(R0, 1),
4216 BPF_EXIT_INSN(),
4217 },
4218 INTERNAL,
4219 { },
4220 { { 0, 0x1 } },
4221 },
4222 {
4223 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
4224 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004225 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4226 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004227 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4228 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4229 BPF_MOV32_IMM(R0, 2),
4230 BPF_EXIT_INSN(),
4231 BPF_MOV32_IMM(R0, 1),
4232 BPF_EXIT_INSN(),
4233 },
4234 INTERNAL,
4235 { },
4236 { { 0, 0x1 } },
4237 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004238 {
4239 "ALU64_XOR_K: Sign extension 1",
4240 .u.insns_int = {
4241 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4242 BPF_LD_IMM64(R1, 0x0123456786a4c2e0LL),
4243 BPF_ALU64_IMM(BPF_XOR, R0, 0x0f0f0f0f),
4244 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4245 BPF_MOV32_IMM(R0, 2),
4246 BPF_EXIT_INSN(),
4247 BPF_MOV32_IMM(R0, 1),
4248 BPF_EXIT_INSN(),
4249 },
4250 INTERNAL,
4251 { },
4252 { { 0, 1 } }
4253 },
4254 {
4255 "ALU64_XOR_K: Sign extension 2",
4256 .u.insns_int = {
4257 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4258 BPF_LD_IMM64(R1, 0xfedcba98795b3d1fLL),
4259 BPF_ALU64_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4260 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4261 BPF_MOV32_IMM(R0, 2),
4262 BPF_EXIT_INSN(),
4263 BPF_MOV32_IMM(R0, 1),
4264 BPF_EXIT_INSN(),
4265 },
4266 INTERNAL,
4267 { },
4268 { { 0, 1 } }
4269 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004270 /* BPF_ALU | BPF_LSH | BPF_X */
4271 {
4272 "ALU_LSH_X: 1 << 1 = 2",
4273 .u.insns_int = {
4274 BPF_LD_IMM64(R0, 1),
4275 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4276 BPF_ALU32_REG(BPF_LSH, R0, R1),
4277 BPF_EXIT_INSN(),
4278 },
4279 INTERNAL,
4280 { },
4281 { { 0, 2 } },
4282 },
4283 {
4284 "ALU_LSH_X: 1 << 31 = 0x80000000",
4285 .u.insns_int = {
4286 BPF_LD_IMM64(R0, 1),
4287 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4288 BPF_ALU32_REG(BPF_LSH, R0, R1),
4289 BPF_EXIT_INSN(),
4290 },
4291 INTERNAL,
4292 { },
4293 { { 0, 0x80000000 } },
4294 },
4295 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004296 "ALU_LSH_X: 0x12345678 << 12 = 0x45678000",
4297 .u.insns_int = {
4298 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4299 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4300 BPF_ALU32_REG(BPF_LSH, R0, R1),
4301 BPF_EXIT_INSN(),
4302 },
4303 INTERNAL,
4304 { },
4305 { { 0, 0x45678000 } }
4306 },
4307 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004308 "ALU64_LSH_X: 1 << 1 = 2",
4309 .u.insns_int = {
4310 BPF_LD_IMM64(R0, 1),
4311 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4312 BPF_ALU64_REG(BPF_LSH, R0, R1),
4313 BPF_EXIT_INSN(),
4314 },
4315 INTERNAL,
4316 { },
4317 { { 0, 2 } },
4318 },
4319 {
4320 "ALU64_LSH_X: 1 << 31 = 0x80000000",
4321 .u.insns_int = {
4322 BPF_LD_IMM64(R0, 1),
4323 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4324 BPF_ALU64_REG(BPF_LSH, R0, R1),
4325 BPF_EXIT_INSN(),
4326 },
4327 INTERNAL,
4328 { },
4329 { { 0, 0x80000000 } },
4330 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004331 {
4332 "ALU64_LSH_X: Shift < 32, low word",
4333 .u.insns_int = {
4334 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4335 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4336 BPF_ALU64_REG(BPF_LSH, R0, R1),
4337 BPF_EXIT_INSN(),
4338 },
4339 INTERNAL,
4340 { },
4341 { { 0, 0xbcdef000 } }
4342 },
4343 {
4344 "ALU64_LSH_X: Shift < 32, high word",
4345 .u.insns_int = {
4346 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4347 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4348 BPF_ALU64_REG(BPF_LSH, R0, R1),
4349 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4350 BPF_EXIT_INSN(),
4351 },
4352 INTERNAL,
4353 { },
4354 { { 0, 0x3456789a } }
4355 },
4356 {
4357 "ALU64_LSH_X: Shift > 32, low word",
4358 .u.insns_int = {
4359 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4360 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4361 BPF_ALU64_REG(BPF_LSH, R0, R1),
4362 BPF_EXIT_INSN(),
4363 },
4364 INTERNAL,
4365 { },
4366 { { 0, 0 } }
4367 },
4368 {
4369 "ALU64_LSH_X: Shift > 32, high word",
4370 .u.insns_int = {
4371 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4372 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4373 BPF_ALU64_REG(BPF_LSH, R0, R1),
4374 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4375 BPF_EXIT_INSN(),
4376 },
4377 INTERNAL,
4378 { },
4379 { { 0, 0x9abcdef0 } }
4380 },
4381 {
4382 "ALU64_LSH_X: Shift == 32, low word",
4383 .u.insns_int = {
4384 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4385 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4386 BPF_ALU64_REG(BPF_LSH, R0, R1),
4387 BPF_EXIT_INSN(),
4388 },
4389 INTERNAL,
4390 { },
4391 { { 0, 0 } }
4392 },
4393 {
4394 "ALU64_LSH_X: Shift == 32, high word",
4395 .u.insns_int = {
4396 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4397 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4398 BPF_ALU64_REG(BPF_LSH, R0, R1),
4399 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4400 BPF_EXIT_INSN(),
4401 },
4402 INTERNAL,
4403 { },
4404 { { 0, 0x89abcdef } }
4405 },
4406 {
4407 "ALU64_LSH_X: Zero shift, low word",
4408 .u.insns_int = {
4409 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4410 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4411 BPF_ALU64_REG(BPF_LSH, R0, R1),
4412 BPF_EXIT_INSN(),
4413 },
4414 INTERNAL,
4415 { },
4416 { { 0, 0x89abcdef } }
4417 },
4418 {
4419 "ALU64_LSH_X: Zero shift, high word",
4420 .u.insns_int = {
4421 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4422 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4423 BPF_ALU64_REG(BPF_LSH, R0, R1),
4424 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4425 BPF_EXIT_INSN(),
4426 },
4427 INTERNAL,
4428 { },
4429 { { 0, 0x01234567 } }
4430 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004431 /* BPF_ALU | BPF_LSH | BPF_K */
4432 {
4433 "ALU_LSH_K: 1 << 1 = 2",
4434 .u.insns_int = {
4435 BPF_LD_IMM64(R0, 1),
4436 BPF_ALU32_IMM(BPF_LSH, R0, 1),
4437 BPF_EXIT_INSN(),
4438 },
4439 INTERNAL,
4440 { },
4441 { { 0, 2 } },
4442 },
4443 {
4444 "ALU_LSH_K: 1 << 31 = 0x80000000",
4445 .u.insns_int = {
4446 BPF_LD_IMM64(R0, 1),
4447 BPF_ALU32_IMM(BPF_LSH, R0, 31),
4448 BPF_EXIT_INSN(),
4449 },
4450 INTERNAL,
4451 { },
4452 { { 0, 0x80000000 } },
4453 },
4454 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004455 "ALU_LSH_K: 0x12345678 << 12 = 0x45678000",
4456 .u.insns_int = {
4457 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4458 BPF_ALU32_IMM(BPF_LSH, R0, 12),
4459 BPF_EXIT_INSN(),
4460 },
4461 INTERNAL,
4462 { },
4463 { { 0, 0x45678000 } }
4464 },
4465 {
4466 "ALU_LSH_K: 0x12345678 << 0 = 0x12345678",
4467 .u.insns_int = {
4468 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4469 BPF_ALU32_IMM(BPF_LSH, R0, 0),
4470 BPF_EXIT_INSN(),
4471 },
4472 INTERNAL,
4473 { },
4474 { { 0, 0x12345678 } }
4475 },
4476 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004477 "ALU64_LSH_K: 1 << 1 = 2",
4478 .u.insns_int = {
4479 BPF_LD_IMM64(R0, 1),
4480 BPF_ALU64_IMM(BPF_LSH, R0, 1),
4481 BPF_EXIT_INSN(),
4482 },
4483 INTERNAL,
4484 { },
4485 { { 0, 2 } },
4486 },
4487 {
4488 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4489 .u.insns_int = {
4490 BPF_LD_IMM64(R0, 1),
4491 BPF_ALU64_IMM(BPF_LSH, R0, 31),
4492 BPF_EXIT_INSN(),
4493 },
4494 INTERNAL,
4495 { },
4496 { { 0, 0x80000000 } },
4497 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004498 {
4499 "ALU64_LSH_K: Shift < 32, low word",
4500 .u.insns_int = {
4501 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4502 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4503 BPF_EXIT_INSN(),
4504 },
4505 INTERNAL,
4506 { },
4507 { { 0, 0xbcdef000 } }
4508 },
4509 {
4510 "ALU64_LSH_K: Shift < 32, high word",
4511 .u.insns_int = {
4512 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4513 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4514 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4515 BPF_EXIT_INSN(),
4516 },
4517 INTERNAL,
4518 { },
4519 { { 0, 0x3456789a } }
4520 },
4521 {
4522 "ALU64_LSH_K: Shift > 32, low word",
4523 .u.insns_int = {
4524 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4525 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4526 BPF_EXIT_INSN(),
4527 },
4528 INTERNAL,
4529 { },
4530 { { 0, 0 } }
4531 },
4532 {
4533 "ALU64_LSH_K: Shift > 32, high word",
4534 .u.insns_int = {
4535 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4536 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4537 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4538 BPF_EXIT_INSN(),
4539 },
4540 INTERNAL,
4541 { },
4542 { { 0, 0x9abcdef0 } }
4543 },
4544 {
4545 "ALU64_LSH_K: Shift == 32, low word",
4546 .u.insns_int = {
4547 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4548 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4549 BPF_EXIT_INSN(),
4550 },
4551 INTERNAL,
4552 { },
4553 { { 0, 0 } }
4554 },
4555 {
4556 "ALU64_LSH_K: Shift == 32, high word",
4557 .u.insns_int = {
4558 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4559 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4560 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4561 BPF_EXIT_INSN(),
4562 },
4563 INTERNAL,
4564 { },
4565 { { 0, 0x89abcdef } }
4566 },
4567 {
4568 "ALU64_LSH_K: Zero shift",
4569 .u.insns_int = {
4570 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4571 BPF_ALU64_IMM(BPF_LSH, R0, 0),
4572 BPF_EXIT_INSN(),
4573 },
4574 INTERNAL,
4575 { },
4576 { { 0, 0x89abcdef } }
4577 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004578 /* BPF_ALU | BPF_RSH | BPF_X */
4579 {
4580 "ALU_RSH_X: 2 >> 1 = 1",
4581 .u.insns_int = {
4582 BPF_LD_IMM64(R0, 2),
4583 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4584 BPF_ALU32_REG(BPF_RSH, R0, R1),
4585 BPF_EXIT_INSN(),
4586 },
4587 INTERNAL,
4588 { },
4589 { { 0, 1 } },
4590 },
4591 {
4592 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4593 .u.insns_int = {
4594 BPF_LD_IMM64(R0, 0x80000000),
4595 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4596 BPF_ALU32_REG(BPF_RSH, R0, R1),
4597 BPF_EXIT_INSN(),
4598 },
4599 INTERNAL,
4600 { },
4601 { { 0, 1 } },
4602 },
4603 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004604 "ALU_RSH_X: 0x12345678 >> 20 = 0x123",
4605 .u.insns_int = {
4606 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4607 BPF_ALU32_IMM(BPF_MOV, R1, 20),
4608 BPF_ALU32_REG(BPF_RSH, R0, R1),
4609 BPF_EXIT_INSN(),
4610 },
4611 INTERNAL,
4612 { },
4613 { { 0, 0x123 } }
4614 },
4615 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004616 "ALU64_RSH_X: 2 >> 1 = 1",
4617 .u.insns_int = {
4618 BPF_LD_IMM64(R0, 2),
4619 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4620 BPF_ALU64_REG(BPF_RSH, R0, R1),
4621 BPF_EXIT_INSN(),
4622 },
4623 INTERNAL,
4624 { },
4625 { { 0, 1 } },
4626 },
4627 {
4628 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4629 .u.insns_int = {
4630 BPF_LD_IMM64(R0, 0x80000000),
4631 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4632 BPF_ALU64_REG(BPF_RSH, R0, R1),
4633 BPF_EXIT_INSN(),
4634 },
4635 INTERNAL,
4636 { },
4637 { { 0, 1 } },
4638 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004639 {
4640 "ALU64_RSH_X: Shift < 32, low word",
4641 .u.insns_int = {
4642 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4643 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4644 BPF_ALU64_REG(BPF_RSH, R0, R1),
4645 BPF_EXIT_INSN(),
4646 },
4647 INTERNAL,
4648 { },
4649 { { 0, 0x56789abc } }
4650 },
4651 {
4652 "ALU64_RSH_X: Shift < 32, high word",
4653 .u.insns_int = {
4654 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4655 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4656 BPF_ALU64_REG(BPF_RSH, R0, R1),
4657 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4658 BPF_EXIT_INSN(),
4659 },
4660 INTERNAL,
4661 { },
4662 { { 0, 0x00081234 } }
4663 },
4664 {
4665 "ALU64_RSH_X: Shift > 32, low word",
4666 .u.insns_int = {
4667 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4668 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4669 BPF_ALU64_REG(BPF_RSH, R0, R1),
4670 BPF_EXIT_INSN(),
4671 },
4672 INTERNAL,
4673 { },
4674 { { 0, 0x08123456 } }
4675 },
4676 {
4677 "ALU64_RSH_X: Shift > 32, high word",
4678 .u.insns_int = {
4679 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4680 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4681 BPF_ALU64_REG(BPF_RSH, R0, R1),
4682 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4683 BPF_EXIT_INSN(),
4684 },
4685 INTERNAL,
4686 { },
4687 { { 0, 0 } }
4688 },
4689 {
4690 "ALU64_RSH_X: Shift == 32, low word",
4691 .u.insns_int = {
4692 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4693 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4694 BPF_ALU64_REG(BPF_RSH, R0, R1),
4695 BPF_EXIT_INSN(),
4696 },
4697 INTERNAL,
4698 { },
4699 { { 0, 0x81234567 } }
4700 },
4701 {
4702 "ALU64_RSH_X: Shift == 32, high word",
4703 .u.insns_int = {
4704 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4705 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4706 BPF_ALU64_REG(BPF_RSH, R0, R1),
4707 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4708 BPF_EXIT_INSN(),
4709 },
4710 INTERNAL,
4711 { },
4712 { { 0, 0 } }
4713 },
4714 {
4715 "ALU64_RSH_X: Zero shift, low word",
4716 .u.insns_int = {
4717 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4718 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4719 BPF_ALU64_REG(BPF_RSH, R0, R1),
4720 BPF_EXIT_INSN(),
4721 },
4722 INTERNAL,
4723 { },
4724 { { 0, 0x89abcdef } }
4725 },
4726 {
4727 "ALU64_RSH_X: Zero shift, high word",
4728 .u.insns_int = {
4729 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4730 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4731 BPF_ALU64_REG(BPF_RSH, R0, R1),
4732 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4733 BPF_EXIT_INSN(),
4734 },
4735 INTERNAL,
4736 { },
4737 { { 0, 0x81234567 } }
4738 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004739 /* BPF_ALU | BPF_RSH | BPF_K */
4740 {
4741 "ALU_RSH_K: 2 >> 1 = 1",
4742 .u.insns_int = {
4743 BPF_LD_IMM64(R0, 2),
4744 BPF_ALU32_IMM(BPF_RSH, R0, 1),
4745 BPF_EXIT_INSN(),
4746 },
4747 INTERNAL,
4748 { },
4749 { { 0, 1 } },
4750 },
4751 {
4752 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4753 .u.insns_int = {
4754 BPF_LD_IMM64(R0, 0x80000000),
4755 BPF_ALU32_IMM(BPF_RSH, R0, 31),
4756 BPF_EXIT_INSN(),
4757 },
4758 INTERNAL,
4759 { },
4760 { { 0, 1 } },
4761 },
4762 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004763 "ALU_RSH_K: 0x12345678 >> 20 = 0x123",
4764 .u.insns_int = {
4765 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4766 BPF_ALU32_IMM(BPF_RSH, R0, 20),
4767 BPF_EXIT_INSN(),
4768 },
4769 INTERNAL,
4770 { },
4771 { { 0, 0x123 } }
4772 },
4773 {
4774 "ALU_RSH_K: 0x12345678 >> 0 = 0x12345678",
4775 .u.insns_int = {
4776 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4777 BPF_ALU32_IMM(BPF_RSH, R0, 0),
4778 BPF_EXIT_INSN(),
4779 },
4780 INTERNAL,
4781 { },
4782 { { 0, 0x12345678 } }
4783 },
4784 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004785 "ALU64_RSH_K: 2 >> 1 = 1",
4786 .u.insns_int = {
4787 BPF_LD_IMM64(R0, 2),
4788 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4789 BPF_EXIT_INSN(),
4790 },
4791 INTERNAL,
4792 { },
4793 { { 0, 1 } },
4794 },
4795 {
4796 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4797 .u.insns_int = {
4798 BPF_LD_IMM64(R0, 0x80000000),
4799 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4800 BPF_EXIT_INSN(),
4801 },
4802 INTERNAL,
4803 { },
4804 { { 0, 1 } },
4805 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004806 {
4807 "ALU64_RSH_K: Shift < 32, low word",
4808 .u.insns_int = {
4809 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4810 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4811 BPF_EXIT_INSN(),
4812 },
4813 INTERNAL,
4814 { },
4815 { { 0, 0x56789abc } }
4816 },
4817 {
4818 "ALU64_RSH_K: Shift < 32, high word",
4819 .u.insns_int = {
4820 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4821 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4822 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4823 BPF_EXIT_INSN(),
4824 },
4825 INTERNAL,
4826 { },
4827 { { 0, 0x00081234 } }
4828 },
4829 {
4830 "ALU64_RSH_K: Shift > 32, low word",
4831 .u.insns_int = {
4832 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4833 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4834 BPF_EXIT_INSN(),
4835 },
4836 INTERNAL,
4837 { },
4838 { { 0, 0x08123456 } }
4839 },
4840 {
4841 "ALU64_RSH_K: Shift > 32, high word",
4842 .u.insns_int = {
4843 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4844 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4845 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4846 BPF_EXIT_INSN(),
4847 },
4848 INTERNAL,
4849 { },
4850 { { 0, 0 } }
4851 },
4852 {
4853 "ALU64_RSH_K: Shift == 32, low word",
4854 .u.insns_int = {
4855 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4856 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4857 BPF_EXIT_INSN(),
4858 },
4859 INTERNAL,
4860 { },
4861 { { 0, 0x81234567 } }
4862 },
4863 {
4864 "ALU64_RSH_K: Shift == 32, high word",
4865 .u.insns_int = {
4866 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4867 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4868 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4869 BPF_EXIT_INSN(),
4870 },
4871 INTERNAL,
4872 { },
4873 { { 0, 0 } }
4874 },
4875 {
4876 "ALU64_RSH_K: Zero shift",
4877 .u.insns_int = {
4878 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4879 BPF_ALU64_IMM(BPF_RSH, R0, 0),
4880 BPF_EXIT_INSN(),
4881 },
4882 INTERNAL,
4883 { },
4884 { { 0, 0x89abcdef } }
4885 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004886 /* BPF_ALU | BPF_ARSH | BPF_X */
4887 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004888 "ALU32_ARSH_X: -1234 >> 7 = -10",
4889 .u.insns_int = {
4890 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
4891 BPF_ALU32_IMM(BPF_MOV, R1, 7),
4892 BPF_ALU32_REG(BPF_ARSH, R0, R1),
4893 BPF_EXIT_INSN(),
4894 },
4895 INTERNAL,
4896 { },
4897 { { 0, -10 } }
4898 },
4899 {
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004900 "ALU64_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
Michael Holzheucffc6422015-05-11 22:22:44 -07004901 .u.insns_int = {
4902 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4903 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4904 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4905 BPF_EXIT_INSN(),
4906 },
4907 INTERNAL,
4908 { },
4909 { { 0, 0xffff00ff } },
4910 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004911 {
4912 "ALU64_ARSH_X: Shift < 32, low word",
4913 .u.insns_int = {
4914 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4915 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4916 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4917 BPF_EXIT_INSN(),
4918 },
4919 INTERNAL,
4920 { },
4921 { { 0, 0x56789abc } }
4922 },
4923 {
4924 "ALU64_ARSH_X: Shift < 32, high word",
4925 .u.insns_int = {
4926 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4927 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4928 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4929 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4930 BPF_EXIT_INSN(),
4931 },
4932 INTERNAL,
4933 { },
4934 { { 0, 0xfff81234 } }
4935 },
4936 {
4937 "ALU64_ARSH_X: Shift > 32, low word",
4938 .u.insns_int = {
4939 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4940 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4941 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4942 BPF_EXIT_INSN(),
4943 },
4944 INTERNAL,
4945 { },
4946 { { 0, 0xf8123456 } }
4947 },
4948 {
4949 "ALU64_ARSH_X: Shift > 32, high word",
4950 .u.insns_int = {
4951 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4952 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4953 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4954 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4955 BPF_EXIT_INSN(),
4956 },
4957 INTERNAL,
4958 { },
4959 { { 0, -1 } }
4960 },
4961 {
4962 "ALU64_ARSH_X: Shift == 32, low word",
4963 .u.insns_int = {
4964 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4965 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4966 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4967 BPF_EXIT_INSN(),
4968 },
4969 INTERNAL,
4970 { },
4971 { { 0, 0x81234567 } }
4972 },
4973 {
4974 "ALU64_ARSH_X: Shift == 32, high word",
4975 .u.insns_int = {
4976 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4977 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4978 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4979 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4980 BPF_EXIT_INSN(),
4981 },
4982 INTERNAL,
4983 { },
4984 { { 0, -1 } }
4985 },
4986 {
4987 "ALU64_ARSH_X: Zero shift, low word",
4988 .u.insns_int = {
4989 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4990 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4991 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4992 BPF_EXIT_INSN(),
4993 },
4994 INTERNAL,
4995 { },
4996 { { 0, 0x89abcdef } }
4997 },
4998 {
4999 "ALU64_ARSH_X: Zero shift, high word",
5000 .u.insns_int = {
5001 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5002 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5003 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5004 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5005 BPF_EXIT_INSN(),
5006 },
5007 INTERNAL,
5008 { },
5009 { { 0, 0x81234567 } }
5010 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005011 /* BPF_ALU | BPF_ARSH | BPF_K */
5012 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02005013 "ALU32_ARSH_K: -1234 >> 7 = -10",
5014 .u.insns_int = {
5015 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5016 BPF_ALU32_IMM(BPF_ARSH, R0, 7),
5017 BPF_EXIT_INSN(),
5018 },
5019 INTERNAL,
5020 { },
5021 { { 0, -10 } }
5022 },
5023 {
5024 "ALU32_ARSH_K: -1234 >> 0 = -1234",
5025 .u.insns_int = {
5026 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5027 BPF_ALU32_IMM(BPF_ARSH, R0, 0),
5028 BPF_EXIT_INSN(),
5029 },
5030 INTERNAL,
5031 { },
5032 { { 0, -1234 } }
5033 },
5034 {
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005035 "ALU64_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
Michael Holzheucffc6422015-05-11 22:22:44 -07005036 .u.insns_int = {
5037 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
5038 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
5039 BPF_EXIT_INSN(),
5040 },
5041 INTERNAL,
5042 { },
5043 { { 0, 0xffff00ff } },
5044 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005045 {
5046 "ALU64_ARSH_K: Shift < 32, low word",
5047 .u.insns_int = {
5048 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5049 BPF_ALU64_IMM(BPF_RSH, R0, 12),
5050 BPF_EXIT_INSN(),
5051 },
5052 INTERNAL,
5053 { },
5054 { { 0, 0x56789abc } }
5055 },
5056 {
5057 "ALU64_ARSH_K: Shift < 32, high word",
5058 .u.insns_int = {
5059 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5060 BPF_ALU64_IMM(BPF_ARSH, R0, 12),
5061 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5062 BPF_EXIT_INSN(),
5063 },
5064 INTERNAL,
5065 { },
5066 { { 0, 0xfff81234 } }
5067 },
5068 {
5069 "ALU64_ARSH_K: Shift > 32, low word",
5070 .u.insns_int = {
5071 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5072 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5073 BPF_EXIT_INSN(),
5074 },
5075 INTERNAL,
5076 { },
5077 { { 0, 0xf8123456 } }
5078 },
5079 {
5080 "ALU64_ARSH_K: Shift > 32, high word",
5081 .u.insns_int = {
5082 BPF_LD_IMM64(R0, 0xf123456789abcdefLL),
5083 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5084 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5085 BPF_EXIT_INSN(),
5086 },
5087 INTERNAL,
5088 { },
5089 { { 0, -1 } }
5090 },
5091 {
5092 "ALU64_ARSH_K: Shift == 32, low word",
5093 .u.insns_int = {
5094 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5095 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5096 BPF_EXIT_INSN(),
5097 },
5098 INTERNAL,
5099 { },
5100 { { 0, 0x81234567 } }
5101 },
5102 {
5103 "ALU64_ARSH_K: Shift == 32, high word",
5104 .u.insns_int = {
5105 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5106 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5107 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5108 BPF_EXIT_INSN(),
5109 },
5110 INTERNAL,
5111 { },
5112 { { 0, -1 } }
5113 },
5114 {
5115 "ALU64_ARSH_K: Zero shoft",
5116 .u.insns_int = {
5117 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5118 BPF_ALU64_IMM(BPF_ARSH, R0, 0),
5119 BPF_EXIT_INSN(),
5120 },
5121 INTERNAL,
5122 { },
5123 { { 0, 0x89abcdef } }
5124 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005125 /* BPF_ALU | BPF_NEG */
5126 {
5127 "ALU_NEG: -(3) = -3",
5128 .u.insns_int = {
5129 BPF_ALU32_IMM(BPF_MOV, R0, 3),
5130 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5131 BPF_EXIT_INSN(),
5132 },
5133 INTERNAL,
5134 { },
5135 { { 0, -3 } },
5136 },
5137 {
5138 "ALU_NEG: -(-3) = 3",
5139 .u.insns_int = {
5140 BPF_ALU32_IMM(BPF_MOV, R0, -3),
5141 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5142 BPF_EXIT_INSN(),
5143 },
5144 INTERNAL,
5145 { },
5146 { { 0, 3 } },
5147 },
5148 {
5149 "ALU64_NEG: -(3) = -3",
5150 .u.insns_int = {
5151 BPF_LD_IMM64(R0, 3),
5152 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5153 BPF_EXIT_INSN(),
5154 },
5155 INTERNAL,
5156 { },
5157 { { 0, -3 } },
5158 },
5159 {
5160 "ALU64_NEG: -(-3) = 3",
5161 .u.insns_int = {
5162 BPF_LD_IMM64(R0, -3),
5163 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5164 BPF_EXIT_INSN(),
5165 },
5166 INTERNAL,
5167 { },
5168 { { 0, 3 } },
5169 },
5170 /* BPF_ALU | BPF_END | BPF_FROM_BE */
5171 {
5172 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
5173 .u.insns_int = {
5174 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5175 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
5176 BPF_EXIT_INSN(),
5177 },
5178 INTERNAL,
5179 { },
5180 { { 0, cpu_to_be16(0xcdef) } },
5181 },
5182 {
5183 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
5184 .u.insns_int = {
5185 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5186 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07005187 BPF_ALU64_REG(BPF_MOV, R1, R0),
5188 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5189 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07005190 BPF_EXIT_INSN(),
5191 },
5192 INTERNAL,
5193 { },
5194 { { 0, cpu_to_be32(0x89abcdef) } },
5195 },
5196 {
5197 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
5198 .u.insns_int = {
5199 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5200 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
5201 BPF_EXIT_INSN(),
5202 },
5203 INTERNAL,
5204 { },
5205 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
5206 },
5207 /* BPF_ALU | BPF_END | BPF_FROM_LE */
5208 {
5209 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
5210 .u.insns_int = {
5211 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5212 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
5213 BPF_EXIT_INSN(),
5214 },
5215 INTERNAL,
5216 { },
5217 { { 0, cpu_to_le16(0xcdef) } },
5218 },
5219 {
5220 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
5221 .u.insns_int = {
5222 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5223 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07005224 BPF_ALU64_REG(BPF_MOV, R1, R0),
5225 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5226 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07005227 BPF_EXIT_INSN(),
5228 },
5229 INTERNAL,
5230 { },
5231 { { 0, cpu_to_le32(0x89abcdef) } },
5232 },
5233 {
5234 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
5235 .u.insns_int = {
5236 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5237 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
5238 BPF_EXIT_INSN(),
5239 },
5240 INTERNAL,
5241 { },
5242 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
5243 },
5244 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
5245 {
5246 "ST_MEM_B: Store/Load byte: max negative",
5247 .u.insns_int = {
5248 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5249 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
5250 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5251 BPF_EXIT_INSN(),
5252 },
5253 INTERNAL,
5254 { },
5255 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005256 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005257 },
5258 {
5259 "ST_MEM_B: Store/Load byte: max positive",
5260 .u.insns_int = {
5261 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5262 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
5263 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5264 BPF_EXIT_INSN(),
5265 },
5266 INTERNAL,
5267 { },
5268 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005269 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005270 },
5271 {
5272 "STX_MEM_B: Store/Load byte: max negative",
5273 .u.insns_int = {
5274 BPF_LD_IMM64(R0, 0),
5275 BPF_LD_IMM64(R1, 0xffLL),
5276 BPF_STX_MEM(BPF_B, R10, R1, -40),
5277 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5278 BPF_EXIT_INSN(),
5279 },
5280 INTERNAL,
5281 { },
5282 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005283 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005284 },
5285 {
5286 "ST_MEM_H: Store/Load half word: max negative",
5287 .u.insns_int = {
5288 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5289 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
5290 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5291 BPF_EXIT_INSN(),
5292 },
5293 INTERNAL,
5294 { },
5295 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005296 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005297 },
5298 {
5299 "ST_MEM_H: Store/Load half word: max positive",
5300 .u.insns_int = {
5301 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5302 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
5303 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5304 BPF_EXIT_INSN(),
5305 },
5306 INTERNAL,
5307 { },
5308 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005309 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005310 },
5311 {
5312 "STX_MEM_H: Store/Load half word: max negative",
5313 .u.insns_int = {
5314 BPF_LD_IMM64(R0, 0),
5315 BPF_LD_IMM64(R1, 0xffffLL),
5316 BPF_STX_MEM(BPF_H, R10, R1, -40),
5317 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5318 BPF_EXIT_INSN(),
5319 },
5320 INTERNAL,
5321 { },
5322 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005323 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005324 },
5325 {
5326 "ST_MEM_W: Store/Load word: max negative",
5327 .u.insns_int = {
5328 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5329 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
5330 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5331 BPF_EXIT_INSN(),
5332 },
5333 INTERNAL,
5334 { },
5335 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005336 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005337 },
5338 {
5339 "ST_MEM_W: Store/Load word: max positive",
5340 .u.insns_int = {
5341 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5342 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
5343 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5344 BPF_EXIT_INSN(),
5345 },
5346 INTERNAL,
5347 { },
5348 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005349 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005350 },
5351 {
5352 "STX_MEM_W: Store/Load word: max negative",
5353 .u.insns_int = {
5354 BPF_LD_IMM64(R0, 0),
5355 BPF_LD_IMM64(R1, 0xffffffffLL),
5356 BPF_STX_MEM(BPF_W, R10, R1, -40),
5357 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5358 BPF_EXIT_INSN(),
5359 },
5360 INTERNAL,
5361 { },
5362 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005363 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005364 },
5365 {
5366 "ST_MEM_DW: Store/Load double word: max negative",
5367 .u.insns_int = {
5368 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5369 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5370 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5371 BPF_EXIT_INSN(),
5372 },
5373 INTERNAL,
5374 { },
5375 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005376 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005377 },
5378 {
5379 "ST_MEM_DW: Store/Load double word: max negative 2",
5380 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07005381 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
5382 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07005383 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5384 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
5385 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5386 BPF_MOV32_IMM(R0, 2),
5387 BPF_EXIT_INSN(),
5388 BPF_MOV32_IMM(R0, 1),
5389 BPF_EXIT_INSN(),
5390 },
5391 INTERNAL,
5392 { },
5393 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005394 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005395 },
5396 {
5397 "ST_MEM_DW: Store/Load double word: max positive",
5398 .u.insns_int = {
5399 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5400 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
5401 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5402 BPF_EXIT_INSN(),
5403 },
5404 INTERNAL,
5405 { },
5406 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005407 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005408 },
5409 {
5410 "STX_MEM_DW: Store/Load double word: max negative",
5411 .u.insns_int = {
5412 BPF_LD_IMM64(R0, 0),
5413 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
Johan Almbladhae7f4702021-07-21 12:40:58 +02005414 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5415 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07005416 BPF_EXIT_INSN(),
5417 },
5418 INTERNAL,
5419 { },
5420 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005421 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005422 },
Johan Almbladhe5009b42021-08-09 11:18:24 +02005423 {
5424 "STX_MEM_DW: Store double word: first word in memory",
5425 .u.insns_int = {
5426 BPF_LD_IMM64(R0, 0),
5427 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5428 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5429 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5430 BPF_EXIT_INSN(),
5431 },
5432 INTERNAL,
5433 { },
5434#ifdef __BIG_ENDIAN
5435 { { 0, 0x01234567 } },
5436#else
5437 { { 0, 0x89abcdef } },
5438#endif
5439 .stack_depth = 40,
5440 },
5441 {
5442 "STX_MEM_DW: Store double word: second word in memory",
5443 .u.insns_int = {
5444 BPF_LD_IMM64(R0, 0),
5445 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5446 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5447 BPF_LDX_MEM(BPF_W, R0, R10, -36),
5448 BPF_EXIT_INSN(),
5449 },
5450 INTERNAL,
5451 { },
5452#ifdef __BIG_ENDIAN
5453 { { 0, 0x89abcdef } },
5454#else
5455 { { 0, 0x01234567 } },
5456#endif
5457 .stack_depth = 40,
5458 },
Brendan Jackman91c960b2021-01-14 18:17:44 +00005459 /* BPF_STX | BPF_ATOMIC | BPF_W/DW */
Michael Holzheucffc6422015-05-11 22:22:44 -07005460 {
5461 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
5462 .u.insns_int = {
5463 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
5464 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00005465 BPF_ATOMIC_OP(BPF_W, BPF_ADD, R10, R0, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07005466 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5467 BPF_EXIT_INSN(),
5468 },
5469 INTERNAL,
5470 { },
5471 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005472 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005473 },
5474 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005475 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
5476 .u.insns_int = {
5477 BPF_ALU64_REG(BPF_MOV, R1, R10),
5478 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
5479 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00005480 BPF_ATOMIC_OP(BPF_W, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005481 BPF_ALU64_REG(BPF_MOV, R0, R10),
5482 BPF_ALU64_REG(BPF_SUB, R0, R1),
5483 BPF_EXIT_INSN(),
5484 },
5485 INTERNAL,
5486 { },
5487 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005488 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005489 },
5490 {
5491 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
5492 .u.insns_int = {
5493 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
5494 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00005495 BPF_ATOMIC_OP(BPF_W, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005496 BPF_EXIT_INSN(),
5497 },
5498 INTERNAL,
5499 { },
5500 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005501 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005502 },
5503 {
5504 "STX_XADD_W: X + 1 + 1 + 1 + ...",
5505 { },
5506 INTERNAL,
5507 { },
5508 { { 0, 4134 } },
5509 .fill_helper = bpf_fill_stxw,
5510 },
5511 {
Michael Holzheucffc6422015-05-11 22:22:44 -07005512 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
5513 .u.insns_int = {
5514 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
5515 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00005516 BPF_ATOMIC_OP(BPF_DW, BPF_ADD, R10, R0, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07005517 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5518 BPF_EXIT_INSN(),
5519 },
5520 INTERNAL,
5521 { },
5522 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005523 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005524 },
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005525 {
5526 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
5527 .u.insns_int = {
5528 BPF_ALU64_REG(BPF_MOV, R1, R10),
5529 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
5530 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00005531 BPF_ATOMIC_OP(BPF_DW, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005532 BPF_ALU64_REG(BPF_MOV, R0, R10),
5533 BPF_ALU64_REG(BPF_SUB, R0, R1),
5534 BPF_EXIT_INSN(),
5535 },
5536 INTERNAL,
5537 { },
5538 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005539 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005540 },
5541 {
5542 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
5543 .u.insns_int = {
5544 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
5545 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00005546 BPF_ATOMIC_OP(BPF_DW, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005547 BPF_EXIT_INSN(),
5548 },
5549 INTERNAL,
5550 { },
5551 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005552 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005553 },
5554 {
5555 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
5556 { },
5557 INTERNAL,
5558 { },
5559 { { 0, 4134 } },
5560 .fill_helper = bpf_fill_stxdw,
5561 },
Johan Almbladhb55dfa82021-08-09 11:18:16 +02005562 /* BPF_JMP32 | BPF_JEQ | BPF_K */
5563 {
5564 "JMP32_JEQ_K: Small immediate",
5565 .u.insns_int = {
5566 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5567 BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
5568 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5569 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5570 BPF_EXIT_INSN(),
5571 },
5572 INTERNAL,
5573 { },
5574 { { 0, 123 } }
5575 },
5576 {
5577 "JMP32_JEQ_K: Large immediate",
5578 .u.insns_int = {
5579 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5580 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1),
5581 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1),
5582 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5583 BPF_EXIT_INSN(),
5584 },
5585 INTERNAL,
5586 { },
5587 { { 0, 12345678 } }
5588 },
5589 {
5590 "JMP32_JEQ_K: negative immediate",
5591 .u.insns_int = {
5592 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5593 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5594 BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1),
5595 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5596 BPF_EXIT_INSN(),
5597 },
5598 INTERNAL,
5599 { },
5600 { { 0, -123 } }
5601 },
5602 /* BPF_JMP32 | BPF_JEQ | BPF_X */
5603 {
5604 "JMP32_JEQ_X",
5605 .u.insns_int = {
5606 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5607 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5608 BPF_JMP32_REG(BPF_JEQ, R0, R1, 2),
5609 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5610 BPF_JMP32_REG(BPF_JEQ, R0, R1, 1),
5611 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5612 BPF_EXIT_INSN(),
5613 },
5614 INTERNAL,
5615 { },
5616 { { 0, 1234 } }
5617 },
5618 /* BPF_JMP32 | BPF_JNE | BPF_K */
5619 {
5620 "JMP32_JNE_K: Small immediate",
5621 .u.insns_int = {
5622 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5623 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5624 BPF_JMP32_IMM(BPF_JNE, R0, 321, 1),
5625 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5626 BPF_EXIT_INSN(),
5627 },
5628 INTERNAL,
5629 { },
5630 { { 0, 123 } }
5631 },
5632 {
5633 "JMP32_JNE_K: Large immediate",
5634 .u.insns_int = {
5635 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5636 BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1),
5637 BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1),
5638 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5639 BPF_EXIT_INSN(),
5640 },
5641 INTERNAL,
5642 { },
5643 { { 0, 12345678 } }
5644 },
5645 {
5646 "JMP32_JNE_K: negative immediate",
5647 .u.insns_int = {
5648 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5649 BPF_JMP32_IMM(BPF_JNE, R0, -123, 1),
5650 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5651 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5652 BPF_EXIT_INSN(),
5653 },
5654 INTERNAL,
5655 { },
5656 { { 0, -123 } }
5657 },
5658 /* BPF_JMP32 | BPF_JNE | BPF_X */
5659 {
5660 "JMP32_JNE_X",
5661 .u.insns_int = {
5662 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5663 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5664 BPF_JMP32_REG(BPF_JNE, R0, R1, 2),
5665 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5666 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
5667 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5668 BPF_EXIT_INSN(),
5669 },
5670 INTERNAL,
5671 { },
5672 { { 0, 1234 } }
5673 },
5674 /* BPF_JMP32 | BPF_JSET | BPF_K */
5675 {
5676 "JMP32_JSET_K: Small immediate",
5677 .u.insns_int = {
5678 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5679 BPF_JMP32_IMM(BPF_JSET, R0, 2, 1),
5680 BPF_JMP32_IMM(BPF_JSET, R0, 3, 1),
5681 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5682 BPF_EXIT_INSN(),
5683 },
5684 INTERNAL,
5685 { },
5686 { { 0, 1 } }
5687 },
5688 {
5689 "JMP32_JSET_K: Large immediate",
5690 .u.insns_int = {
5691 BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000),
5692 BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1),
5693 BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1),
5694 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5695 BPF_EXIT_INSN(),
5696 },
5697 INTERNAL,
5698 { },
5699 { { 0, 0x40000000 } }
5700 },
5701 {
5702 "JMP32_JSET_K: negative immediate",
5703 .u.insns_int = {
5704 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5705 BPF_JMP32_IMM(BPF_JSET, R0, -1, 1),
5706 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5707 BPF_EXIT_INSN(),
5708 },
5709 INTERNAL,
5710 { },
5711 { { 0, -123 } }
5712 },
5713 /* BPF_JMP32 | BPF_JSET | BPF_X */
5714 {
5715 "JMP32_JSET_X",
5716 .u.insns_int = {
5717 BPF_ALU32_IMM(BPF_MOV, R0, 8),
5718 BPF_ALU32_IMM(BPF_MOV, R1, 7),
5719 BPF_JMP32_REG(BPF_JSET, R0, R1, 2),
5720 BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2),
5721 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
5722 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5723 BPF_EXIT_INSN(),
5724 },
5725 INTERNAL,
5726 { },
5727 { { 0, 8 } }
5728 },
5729 /* BPF_JMP32 | BPF_JGT | BPF_K */
5730 {
5731 "JMP32_JGT_K: Small immediate",
5732 .u.insns_int = {
5733 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5734 BPF_JMP32_IMM(BPF_JGT, R0, 123, 1),
5735 BPF_JMP32_IMM(BPF_JGT, R0, 122, 1),
5736 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5737 BPF_EXIT_INSN(),
5738 },
5739 INTERNAL,
5740 { },
5741 { { 0, 123 } }
5742 },
5743 {
5744 "JMP32_JGT_K: Large immediate",
5745 .u.insns_int = {
5746 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5747 BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1),
5748 BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1),
5749 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5750 BPF_EXIT_INSN(),
5751 },
5752 INTERNAL,
5753 { },
5754 { { 0, 0xfffffffe } }
5755 },
5756 /* BPF_JMP32 | BPF_JGT | BPF_X */
5757 {
5758 "JMP32_JGT_X",
5759 .u.insns_int = {
5760 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5761 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
5762 BPF_JMP32_REG(BPF_JGT, R0, R1, 2),
5763 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
5764 BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
5765 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5766 BPF_EXIT_INSN(),
5767 },
5768 INTERNAL,
5769 { },
5770 { { 0, 0xfffffffe } }
5771 },
5772 /* BPF_JMP32 | BPF_JGE | BPF_K */
5773 {
5774 "JMP32_JGE_K: Small immediate",
5775 .u.insns_int = {
5776 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5777 BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
5778 BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
5779 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5780 BPF_EXIT_INSN(),
5781 },
5782 INTERNAL,
5783 { },
5784 { { 0, 123 } }
5785 },
5786 {
5787 "JMP32_JGE_K: Large immediate",
5788 .u.insns_int = {
5789 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5790 BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
5791 BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
5792 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5793 BPF_EXIT_INSN(),
5794 },
5795 INTERNAL,
5796 { },
5797 { { 0, 0xfffffffe } }
5798 },
5799 /* BPF_JMP32 | BPF_JGE | BPF_X */
5800 {
5801 "JMP32_JGE_X",
5802 .u.insns_int = {
5803 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5804 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
5805 BPF_JMP32_REG(BPF_JGE, R0, R1, 2),
5806 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
5807 BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
5808 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5809 BPF_EXIT_INSN(),
5810 },
5811 INTERNAL,
5812 { },
5813 { { 0, 0xfffffffe } }
5814 },
5815 /* BPF_JMP32 | BPF_JLT | BPF_K */
5816 {
5817 "JMP32_JLT_K: Small immediate",
5818 .u.insns_int = {
5819 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5820 BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
5821 BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
5822 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5823 BPF_EXIT_INSN(),
5824 },
5825 INTERNAL,
5826 { },
5827 { { 0, 123 } }
5828 },
5829 {
5830 "JMP32_JLT_K: Large immediate",
5831 .u.insns_int = {
5832 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5833 BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
5834 BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
5835 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5836 BPF_EXIT_INSN(),
5837 },
5838 INTERNAL,
5839 { },
5840 { { 0, 0xfffffffe } }
5841 },
5842 /* BPF_JMP32 | BPF_JLT | BPF_X */
5843 {
5844 "JMP32_JLT_X",
5845 .u.insns_int = {
5846 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5847 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
5848 BPF_JMP32_REG(BPF_JLT, R0, R1, 2),
5849 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
5850 BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
5851 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5852 BPF_EXIT_INSN(),
5853 },
5854 INTERNAL,
5855 { },
5856 { { 0, 0xfffffffe } }
5857 },
5858 /* BPF_JMP32 | BPF_JLE | BPF_K */
5859 {
5860 "JMP32_JLE_K: Small immediate",
5861 .u.insns_int = {
5862 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5863 BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
5864 BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
5865 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5866 BPF_EXIT_INSN(),
5867 },
5868 INTERNAL,
5869 { },
5870 { { 0, 123 } }
5871 },
5872 {
5873 "JMP32_JLE_K: Large immediate",
5874 .u.insns_int = {
5875 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5876 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
5877 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
5878 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5879 BPF_EXIT_INSN(),
5880 },
5881 INTERNAL,
5882 { },
5883 { { 0, 0xfffffffe } }
5884 },
5885 /* BPF_JMP32 | BPF_JLE | BPF_X */
5886 {
5887 "JMP32_JLE_X",
5888 .u.insns_int = {
5889 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
5890 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
5891 BPF_JMP32_REG(BPF_JLE, R0, R1, 2),
5892 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
5893 BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
5894 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5895 BPF_EXIT_INSN(),
5896 },
5897 INTERNAL,
5898 { },
5899 { { 0, 0xfffffffe } }
5900 },
5901 /* BPF_JMP32 | BPF_JSGT | BPF_K */
5902 {
5903 "JMP32_JSGT_K: Small immediate",
5904 .u.insns_int = {
5905 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5906 BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
5907 BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
5908 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5909 BPF_EXIT_INSN(),
5910 },
5911 INTERNAL,
5912 { },
5913 { { 0, -123 } }
5914 },
5915 {
5916 "JMP32_JSGT_K: Large immediate",
5917 .u.insns_int = {
5918 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
5919 BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
5920 BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
5921 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5922 BPF_EXIT_INSN(),
5923 },
5924 INTERNAL,
5925 { },
5926 { { 0, -12345678 } }
5927 },
5928 /* BPF_JMP32 | BPF_JSGT | BPF_X */
5929 {
5930 "JMP32_JSGT_X",
5931 .u.insns_int = {
5932 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
5933 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
5934 BPF_JMP32_REG(BPF_JSGT, R0, R1, 2),
5935 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
5936 BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
5937 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5938 BPF_EXIT_INSN(),
5939 },
5940 INTERNAL,
5941 { },
5942 { { 0, -12345678 } }
5943 },
5944 /* BPF_JMP32 | BPF_JSGE | BPF_K */
5945 {
5946 "JMP32_JSGE_K: Small immediate",
5947 .u.insns_int = {
5948 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5949 BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
5950 BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
5951 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5952 BPF_EXIT_INSN(),
5953 },
5954 INTERNAL,
5955 { },
5956 { { 0, -123 } }
5957 },
5958 {
5959 "JMP32_JSGE_K: Large immediate",
5960 .u.insns_int = {
5961 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
5962 BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
5963 BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
5964 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5965 BPF_EXIT_INSN(),
5966 },
5967 INTERNAL,
5968 { },
5969 { { 0, -12345678 } }
5970 },
5971 /* BPF_JMP32 | BPF_JSGE | BPF_X */
5972 {
5973 "JMP32_JSGE_X",
5974 .u.insns_int = {
5975 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
5976 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
5977 BPF_JMP32_REG(BPF_JSGE, R0, R1, 2),
5978 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
5979 BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
5980 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5981 BPF_EXIT_INSN(),
5982 },
5983 INTERNAL,
5984 { },
5985 { { 0, -12345678 } }
5986 },
5987 /* BPF_JMP32 | BPF_JSLT | BPF_K */
5988 {
5989 "JMP32_JSLT_K: Small immediate",
5990 .u.insns_int = {
5991 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5992 BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
5993 BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
5994 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5995 BPF_EXIT_INSN(),
5996 },
5997 INTERNAL,
5998 { },
5999 { { 0, -123 } }
6000 },
6001 {
6002 "JMP32_JSLT_K: Large immediate",
6003 .u.insns_int = {
6004 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6005 BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
6006 BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
6007 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6008 BPF_EXIT_INSN(),
6009 },
6010 INTERNAL,
6011 { },
6012 { { 0, -12345678 } }
6013 },
6014 /* BPF_JMP32 | BPF_JSLT | BPF_X */
6015 {
6016 "JMP32_JSLT_X",
6017 .u.insns_int = {
6018 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6019 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6020 BPF_JMP32_REG(BPF_JSLT, R0, R1, 2),
6021 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6022 BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
6023 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6024 BPF_EXIT_INSN(),
6025 },
6026 INTERNAL,
6027 { },
6028 { { 0, -12345678 } }
6029 },
6030 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6031 {
6032 "JMP32_JSLE_K: Small immediate",
6033 .u.insns_int = {
6034 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6035 BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
6036 BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
6037 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6038 BPF_EXIT_INSN(),
6039 },
6040 INTERNAL,
6041 { },
6042 { { 0, -123 } }
6043 },
6044 {
6045 "JMP32_JSLE_K: Large immediate",
6046 .u.insns_int = {
6047 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6048 BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
6049 BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
6050 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6051 BPF_EXIT_INSN(),
6052 },
6053 INTERNAL,
6054 { },
6055 { { 0, -12345678 } }
6056 },
6057 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6058 {
6059 "JMP32_JSLE_X",
6060 .u.insns_int = {
6061 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6062 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6063 BPF_JMP32_REG(BPF_JSLE, R0, R1, 2),
6064 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6065 BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
6066 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6067 BPF_EXIT_INSN(),
6068 },
6069 INTERNAL,
6070 { },
6071 { { 0, -12345678 } }
6072 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006073 /* BPF_JMP | BPF_EXIT */
6074 {
6075 "JMP_EXIT",
6076 .u.insns_int = {
6077 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
6078 BPF_EXIT_INSN(),
6079 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
6080 },
6081 INTERNAL,
6082 { },
6083 { { 0, 0x4711 } },
6084 },
6085 /* BPF_JMP | BPF_JA */
6086 {
6087 "JMP_JA: Unconditional jump: if (true) return 1",
6088 .u.insns_int = {
6089 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6090 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
6091 BPF_EXIT_INSN(),
6092 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6093 BPF_EXIT_INSN(),
6094 },
6095 INTERNAL,
6096 { },
6097 { { 0, 1 } },
6098 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006099 /* BPF_JMP | BPF_JSLT | BPF_K */
6100 {
6101 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
6102 .u.insns_int = {
6103 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6104 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6105 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6106 BPF_EXIT_INSN(),
6107 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6108 BPF_EXIT_INSN(),
6109 },
6110 INTERNAL,
6111 { },
6112 { { 0, 1 } },
6113 },
6114 {
6115 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
6116 .u.insns_int = {
6117 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6118 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6119 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6120 BPF_EXIT_INSN(),
6121 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6122 BPF_EXIT_INSN(),
6123 },
6124 INTERNAL,
6125 { },
6126 { { 0, 1 } },
6127 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006128 /* BPF_JMP | BPF_JSGT | BPF_K */
6129 {
6130 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
6131 .u.insns_int = {
6132 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6133 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6134 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
6135 BPF_EXIT_INSN(),
6136 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6137 BPF_EXIT_INSN(),
6138 },
6139 INTERNAL,
6140 { },
6141 { { 0, 1 } },
6142 },
6143 {
6144 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
6145 .u.insns_int = {
6146 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6147 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6148 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
6149 BPF_EXIT_INSN(),
6150 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6151 BPF_EXIT_INSN(),
6152 },
6153 INTERNAL,
6154 { },
6155 { { 0, 1 } },
6156 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006157 /* BPF_JMP | BPF_JSLE | BPF_K */
6158 {
6159 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
6160 .u.insns_int = {
6161 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6162 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6163 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6164 BPF_EXIT_INSN(),
6165 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6166 BPF_EXIT_INSN(),
6167 },
6168 INTERNAL,
6169 { },
6170 { { 0, 1 } },
6171 },
6172 {
6173 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
6174 .u.insns_int = {
6175 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6176 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6177 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6178 BPF_EXIT_INSN(),
6179 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6180 BPF_EXIT_INSN(),
6181 },
6182 INTERNAL,
6183 { },
6184 { { 0, 1 } },
6185 },
6186 {
6187 "JMP_JSLE_K: Signed jump: value walk 1",
6188 .u.insns_int = {
6189 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6190 BPF_LD_IMM64(R1, 3),
6191 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
6192 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6193 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6194 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6195 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6196 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6197 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6198 BPF_EXIT_INSN(), /* bad exit */
6199 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6200 BPF_EXIT_INSN(),
6201 },
6202 INTERNAL,
6203 { },
6204 { { 0, 1 } },
6205 },
6206 {
6207 "JMP_JSLE_K: Signed jump: value walk 2",
6208 .u.insns_int = {
6209 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6210 BPF_LD_IMM64(R1, 3),
6211 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6212 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6213 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6214 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6215 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6216 BPF_EXIT_INSN(), /* bad exit */
6217 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6218 BPF_EXIT_INSN(),
6219 },
6220 INTERNAL,
6221 { },
6222 { { 0, 1 } },
6223 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006224 /* BPF_JMP | BPF_JSGE | BPF_K */
6225 {
6226 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
6227 .u.insns_int = {
6228 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6229 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6230 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
6231 BPF_EXIT_INSN(),
6232 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6233 BPF_EXIT_INSN(),
6234 },
6235 INTERNAL,
6236 { },
6237 { { 0, 1 } },
6238 },
6239 {
6240 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
6241 .u.insns_int = {
6242 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6243 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6244 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
6245 BPF_EXIT_INSN(),
6246 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6247 BPF_EXIT_INSN(),
6248 },
6249 INTERNAL,
6250 { },
6251 { { 0, 1 } },
6252 },
David Daney791caeb2017-05-24 16:35:49 -07006253 {
6254 "JMP_JSGE_K: Signed jump: value walk 1",
6255 .u.insns_int = {
6256 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6257 BPF_LD_IMM64(R1, -3),
6258 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
6259 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6260 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6261 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6262 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6263 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6264 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6265 BPF_EXIT_INSN(), /* bad exit */
6266 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6267 BPF_EXIT_INSN(),
6268 },
6269 INTERNAL,
6270 { },
6271 { { 0, 1 } },
6272 },
6273 {
6274 "JMP_JSGE_K: Signed jump: value walk 2",
6275 .u.insns_int = {
6276 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6277 BPF_LD_IMM64(R1, -3),
6278 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6279 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6280 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6281 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6282 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6283 BPF_EXIT_INSN(), /* bad exit */
6284 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6285 BPF_EXIT_INSN(),
6286 },
6287 INTERNAL,
6288 { },
6289 { { 0, 1 } },
6290 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006291 /* BPF_JMP | BPF_JGT | BPF_K */
6292 {
6293 "JMP_JGT_K: if (3 > 2) return 1",
6294 .u.insns_int = {
6295 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6296 BPF_LD_IMM64(R1, 3),
6297 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
6298 BPF_EXIT_INSN(),
6299 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6300 BPF_EXIT_INSN(),
6301 },
6302 INTERNAL,
6303 { },
6304 { { 0, 1 } },
6305 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05306306 {
6307 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
6308 .u.insns_int = {
6309 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6310 BPF_LD_IMM64(R1, -1),
6311 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
6312 BPF_EXIT_INSN(),
6313 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6314 BPF_EXIT_INSN(),
6315 },
6316 INTERNAL,
6317 { },
6318 { { 0, 1 } },
6319 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006320 /* BPF_JMP | BPF_JLT | BPF_K */
6321 {
6322 "JMP_JLT_K: if (2 < 3) return 1",
6323 .u.insns_int = {
6324 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6325 BPF_LD_IMM64(R1, 2),
6326 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
6327 BPF_EXIT_INSN(),
6328 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6329 BPF_EXIT_INSN(),
6330 },
6331 INTERNAL,
6332 { },
6333 { { 0, 1 } },
6334 },
6335 {
6336 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
6337 .u.insns_int = {
6338 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6339 BPF_LD_IMM64(R1, 1),
6340 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
6341 BPF_EXIT_INSN(),
6342 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6343 BPF_EXIT_INSN(),
6344 },
6345 INTERNAL,
6346 { },
6347 { { 0, 1 } },
6348 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006349 /* BPF_JMP | BPF_JGE | BPF_K */
6350 {
6351 "JMP_JGE_K: if (3 >= 2) return 1",
6352 .u.insns_int = {
6353 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6354 BPF_LD_IMM64(R1, 3),
6355 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
6356 BPF_EXIT_INSN(),
6357 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6358 BPF_EXIT_INSN(),
6359 },
6360 INTERNAL,
6361 { },
6362 { { 0, 1 } },
6363 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006364 /* BPF_JMP | BPF_JLE | BPF_K */
6365 {
6366 "JMP_JLE_K: if (2 <= 3) return 1",
6367 .u.insns_int = {
6368 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6369 BPF_LD_IMM64(R1, 2),
6370 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6371 BPF_EXIT_INSN(),
6372 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6373 BPF_EXIT_INSN(),
6374 },
6375 INTERNAL,
6376 { },
6377 { { 0, 1 } },
6378 },
Michael Holzheufe593842015-05-22 08:36:40 -07006379 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
6380 {
6381 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
6382 .u.insns_int = {
6383 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6384 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6385 BPF_EXIT_INSN(),
6386 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6387 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
6388 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
6389 BPF_EXIT_INSN(),
6390 },
6391 INTERNAL,
6392 { },
6393 { { 0, 1 } },
6394 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006395 {
6396 "JMP_JGE_K: if (3 >= 3) return 1",
6397 .u.insns_int = {
6398 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6399 BPF_LD_IMM64(R1, 3),
6400 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
6401 BPF_EXIT_INSN(),
6402 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6403 BPF_EXIT_INSN(),
6404 },
6405 INTERNAL,
6406 { },
6407 { { 0, 1 } },
6408 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006409 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
6410 {
6411 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
6412 .u.insns_int = {
6413 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6414 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6415 BPF_EXIT_INSN(),
6416 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6417 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
6418 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
6419 BPF_EXIT_INSN(),
6420 },
6421 INTERNAL,
6422 { },
6423 { { 0, 1 } },
6424 },
6425 {
6426 "JMP_JLE_K: if (3 <= 3) return 1",
6427 .u.insns_int = {
6428 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6429 BPF_LD_IMM64(R1, 3),
6430 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6431 BPF_EXIT_INSN(),
6432 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6433 BPF_EXIT_INSN(),
6434 },
6435 INTERNAL,
6436 { },
6437 { { 0, 1 } },
6438 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006439 /* BPF_JMP | BPF_JNE | BPF_K */
6440 {
6441 "JMP_JNE_K: if (3 != 2) return 1",
6442 .u.insns_int = {
6443 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6444 BPF_LD_IMM64(R1, 3),
6445 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
6446 BPF_EXIT_INSN(),
6447 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6448 BPF_EXIT_INSN(),
6449 },
6450 INTERNAL,
6451 { },
6452 { { 0, 1 } },
6453 },
6454 /* BPF_JMP | BPF_JEQ | BPF_K */
6455 {
6456 "JMP_JEQ_K: if (3 == 3) return 1",
6457 .u.insns_int = {
6458 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6459 BPF_LD_IMM64(R1, 3),
6460 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
6461 BPF_EXIT_INSN(),
6462 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6463 BPF_EXIT_INSN(),
6464 },
6465 INTERNAL,
6466 { },
6467 { { 0, 1 } },
6468 },
6469 /* BPF_JMP | BPF_JSET | BPF_K */
6470 {
6471 "JMP_JSET_K: if (0x3 & 0x2) return 1",
6472 .u.insns_int = {
6473 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6474 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306475 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006476 BPF_EXIT_INSN(),
6477 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6478 BPF_EXIT_INSN(),
6479 },
6480 INTERNAL,
6481 { },
6482 { { 0, 1 } },
6483 },
6484 {
6485 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
6486 .u.insns_int = {
6487 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6488 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306489 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006490 BPF_EXIT_INSN(),
6491 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6492 BPF_EXIT_INSN(),
6493 },
6494 INTERNAL,
6495 { },
6496 { { 0, 1 } },
6497 },
6498 /* BPF_JMP | BPF_JSGT | BPF_X */
6499 {
6500 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
6501 .u.insns_int = {
6502 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6503 BPF_LD_IMM64(R1, -1),
6504 BPF_LD_IMM64(R2, -2),
6505 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6506 BPF_EXIT_INSN(),
6507 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6508 BPF_EXIT_INSN(),
6509 },
6510 INTERNAL,
6511 { },
6512 { { 0, 1 } },
6513 },
6514 {
6515 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
6516 .u.insns_int = {
6517 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6518 BPF_LD_IMM64(R1, -1),
6519 BPF_LD_IMM64(R2, -1),
6520 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6521 BPF_EXIT_INSN(),
6522 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6523 BPF_EXIT_INSN(),
6524 },
6525 INTERNAL,
6526 { },
6527 { { 0, 1 } },
6528 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006529 /* BPF_JMP | BPF_JSLT | BPF_X */
6530 {
6531 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
6532 .u.insns_int = {
6533 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6534 BPF_LD_IMM64(R1, -1),
6535 BPF_LD_IMM64(R2, -2),
6536 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
6537 BPF_EXIT_INSN(),
6538 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6539 BPF_EXIT_INSN(),
6540 },
6541 INTERNAL,
6542 { },
6543 { { 0, 1 } },
6544 },
6545 {
6546 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
6547 .u.insns_int = {
6548 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6549 BPF_LD_IMM64(R1, -1),
6550 BPF_LD_IMM64(R2, -1),
6551 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
6552 BPF_EXIT_INSN(),
6553 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6554 BPF_EXIT_INSN(),
6555 },
6556 INTERNAL,
6557 { },
6558 { { 0, 1 } },
6559 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006560 /* BPF_JMP | BPF_JSGE | BPF_X */
6561 {
6562 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
6563 .u.insns_int = {
6564 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6565 BPF_LD_IMM64(R1, -1),
6566 BPF_LD_IMM64(R2, -2),
6567 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6568 BPF_EXIT_INSN(),
6569 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6570 BPF_EXIT_INSN(),
6571 },
6572 INTERNAL,
6573 { },
6574 { { 0, 1 } },
6575 },
6576 {
6577 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
6578 .u.insns_int = {
6579 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6580 BPF_LD_IMM64(R1, -1),
6581 BPF_LD_IMM64(R2, -1),
6582 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6583 BPF_EXIT_INSN(),
6584 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6585 BPF_EXIT_INSN(),
6586 },
6587 INTERNAL,
6588 { },
6589 { { 0, 1 } },
6590 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006591 /* BPF_JMP | BPF_JSLE | BPF_X */
6592 {
6593 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
6594 .u.insns_int = {
6595 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6596 BPF_LD_IMM64(R1, -1),
6597 BPF_LD_IMM64(R2, -2),
6598 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
6599 BPF_EXIT_INSN(),
6600 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6601 BPF_EXIT_INSN(),
6602 },
6603 INTERNAL,
6604 { },
6605 { { 0, 1 } },
6606 },
6607 {
6608 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
6609 .u.insns_int = {
6610 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6611 BPF_LD_IMM64(R1, -1),
6612 BPF_LD_IMM64(R2, -1),
6613 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
6614 BPF_EXIT_INSN(),
6615 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6616 BPF_EXIT_INSN(),
6617 },
6618 INTERNAL,
6619 { },
6620 { { 0, 1 } },
6621 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006622 /* BPF_JMP | BPF_JGT | BPF_X */
6623 {
6624 "JMP_JGT_X: if (3 > 2) return 1",
6625 .u.insns_int = {
6626 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6627 BPF_LD_IMM64(R1, 3),
6628 BPF_LD_IMM64(R2, 2),
6629 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6630 BPF_EXIT_INSN(),
6631 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6632 BPF_EXIT_INSN(),
6633 },
6634 INTERNAL,
6635 { },
6636 { { 0, 1 } },
6637 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05306638 {
6639 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
6640 .u.insns_int = {
6641 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6642 BPF_LD_IMM64(R1, -1),
6643 BPF_LD_IMM64(R2, 1),
6644 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6645 BPF_EXIT_INSN(),
6646 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6647 BPF_EXIT_INSN(),
6648 },
6649 INTERNAL,
6650 { },
6651 { { 0, 1 } },
6652 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006653 /* BPF_JMP | BPF_JLT | BPF_X */
6654 {
6655 "JMP_JLT_X: if (2 < 3) return 1",
6656 .u.insns_int = {
6657 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6658 BPF_LD_IMM64(R1, 3),
6659 BPF_LD_IMM64(R2, 2),
6660 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6661 BPF_EXIT_INSN(),
6662 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6663 BPF_EXIT_INSN(),
6664 },
6665 INTERNAL,
6666 { },
6667 { { 0, 1 } },
6668 },
6669 {
6670 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
6671 .u.insns_int = {
6672 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6673 BPF_LD_IMM64(R1, -1),
6674 BPF_LD_IMM64(R2, 1),
6675 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6676 BPF_EXIT_INSN(),
6677 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6678 BPF_EXIT_INSN(),
6679 },
6680 INTERNAL,
6681 { },
6682 { { 0, 1 } },
6683 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006684 /* BPF_JMP | BPF_JGE | BPF_X */
6685 {
6686 "JMP_JGE_X: if (3 >= 2) return 1",
6687 .u.insns_int = {
6688 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6689 BPF_LD_IMM64(R1, 3),
6690 BPF_LD_IMM64(R2, 2),
6691 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
6692 BPF_EXIT_INSN(),
6693 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6694 BPF_EXIT_INSN(),
6695 },
6696 INTERNAL,
6697 { },
6698 { { 0, 1 } },
6699 },
6700 {
6701 "JMP_JGE_X: if (3 >= 3) return 1",
6702 .u.insns_int = {
6703 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6704 BPF_LD_IMM64(R1, 3),
6705 BPF_LD_IMM64(R2, 3),
6706 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
6707 BPF_EXIT_INSN(),
6708 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6709 BPF_EXIT_INSN(),
6710 },
6711 INTERNAL,
6712 { },
6713 { { 0, 1 } },
6714 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006715 /* BPF_JMP | BPF_JLE | BPF_X */
6716 {
6717 "JMP_JLE_X: if (2 <= 3) return 1",
6718 .u.insns_int = {
6719 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6720 BPF_LD_IMM64(R1, 3),
6721 BPF_LD_IMM64(R2, 2),
6722 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
6723 BPF_EXIT_INSN(),
6724 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6725 BPF_EXIT_INSN(),
6726 },
6727 INTERNAL,
6728 { },
6729 { { 0, 1 } },
6730 },
6731 {
6732 "JMP_JLE_X: if (3 <= 3) return 1",
6733 .u.insns_int = {
6734 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6735 BPF_LD_IMM64(R1, 3),
6736 BPF_LD_IMM64(R2, 3),
6737 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
6738 BPF_EXIT_INSN(),
6739 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6740 BPF_EXIT_INSN(),
6741 },
6742 INTERNAL,
6743 { },
6744 { { 0, 1 } },
6745 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006746 {
6747 /* Mainly testing JIT + imm64 here. */
6748 "JMP_JGE_X: ldimm64 test 1",
6749 .u.insns_int = {
6750 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6751 BPF_LD_IMM64(R1, 3),
6752 BPF_LD_IMM64(R2, 2),
6753 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02006754 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6755 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006756 BPF_EXIT_INSN(),
6757 },
6758 INTERNAL,
6759 { },
6760 { { 0, 0xeeeeeeeeU } },
6761 },
6762 {
6763 "JMP_JGE_X: ldimm64 test 2",
6764 .u.insns_int = {
6765 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6766 BPF_LD_IMM64(R1, 3),
6767 BPF_LD_IMM64(R2, 2),
6768 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02006769 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006770 BPF_EXIT_INSN(),
6771 },
6772 INTERNAL,
6773 { },
6774 { { 0, 0xffffffffU } },
6775 },
6776 {
6777 "JMP_JGE_X: ldimm64 test 3",
6778 .u.insns_int = {
6779 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6780 BPF_LD_IMM64(R1, 3),
6781 BPF_LD_IMM64(R2, 2),
6782 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02006783 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6784 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02006785 BPF_EXIT_INSN(),
6786 },
6787 INTERNAL,
6788 { },
6789 { { 0, 1 } },
6790 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006791 {
6792 "JMP_JLE_X: ldimm64 test 1",
6793 .u.insns_int = {
6794 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6795 BPF_LD_IMM64(R1, 3),
6796 BPF_LD_IMM64(R2, 2),
6797 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
6798 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6799 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
6800 BPF_EXIT_INSN(),
6801 },
6802 INTERNAL,
6803 { },
6804 { { 0, 0xeeeeeeeeU } },
6805 },
6806 {
6807 "JMP_JLE_X: ldimm64 test 2",
6808 .u.insns_int = {
6809 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6810 BPF_LD_IMM64(R1, 3),
6811 BPF_LD_IMM64(R2, 2),
6812 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
6813 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6814 BPF_EXIT_INSN(),
6815 },
6816 INTERNAL,
6817 { },
6818 { { 0, 0xffffffffU } },
6819 },
6820 {
6821 "JMP_JLE_X: ldimm64 test 3",
6822 .u.insns_int = {
6823 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6824 BPF_LD_IMM64(R1, 3),
6825 BPF_LD_IMM64(R2, 2),
6826 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
6827 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
6828 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
6829 BPF_EXIT_INSN(),
6830 },
6831 INTERNAL,
6832 { },
6833 { { 0, 1 } },
6834 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006835 /* BPF_JMP | BPF_JNE | BPF_X */
6836 {
6837 "JMP_JNE_X: if (3 != 2) return 1",
6838 .u.insns_int = {
6839 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6840 BPF_LD_IMM64(R1, 3),
6841 BPF_LD_IMM64(R2, 2),
6842 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
6843 BPF_EXIT_INSN(),
6844 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6845 BPF_EXIT_INSN(),
6846 },
6847 INTERNAL,
6848 { },
6849 { { 0, 1 } },
6850 },
6851 /* BPF_JMP | BPF_JEQ | BPF_X */
6852 {
6853 "JMP_JEQ_X: if (3 == 3) return 1",
6854 .u.insns_int = {
6855 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6856 BPF_LD_IMM64(R1, 3),
6857 BPF_LD_IMM64(R2, 3),
6858 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
6859 BPF_EXIT_INSN(),
6860 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6861 BPF_EXIT_INSN(),
6862 },
6863 INTERNAL,
6864 { },
6865 { { 0, 1 } },
6866 },
6867 /* BPF_JMP | BPF_JSET | BPF_X */
6868 {
6869 "JMP_JSET_X: if (0x3 & 0x2) return 1",
6870 .u.insns_int = {
6871 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6872 BPF_LD_IMM64(R1, 3),
6873 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306874 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006875 BPF_EXIT_INSN(),
6876 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6877 BPF_EXIT_INSN(),
6878 },
6879 INTERNAL,
6880 { },
6881 { { 0, 1 } },
6882 },
6883 {
6884 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
6885 .u.insns_int = {
6886 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6887 BPF_LD_IMM64(R1, 3),
6888 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306889 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006890 BPF_EXIT_INSN(),
6891 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6892 BPF_EXIT_INSN(),
6893 },
6894 INTERNAL,
6895 { },
6896 { { 0, 1 } },
6897 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02006898 {
6899 "JMP_JA: Jump, gap, jump, ...",
6900 { },
6901 CLASSIC | FLAG_NO_DATA,
6902 { },
6903 { { 0, 0xababcbac } },
6904 .fill_helper = bpf_fill_ja,
6905 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006906 { /* Mainly checking JIT here. */
6907 "BPF_MAXINSNS: Maximum possible literals",
6908 { },
6909 CLASSIC | FLAG_NO_DATA,
6910 { },
6911 { { 0, 0xffffffff } },
6912 .fill_helper = bpf_fill_maxinsns1,
6913 },
6914 { /* Mainly checking JIT here. */
6915 "BPF_MAXINSNS: Single literal",
6916 { },
6917 CLASSIC | FLAG_NO_DATA,
6918 { },
6919 { { 0, 0xfefefefe } },
6920 .fill_helper = bpf_fill_maxinsns2,
6921 },
6922 { /* Mainly checking JIT here. */
6923 "BPF_MAXINSNS: Run/add until end",
6924 { },
6925 CLASSIC | FLAG_NO_DATA,
6926 { },
6927 { { 0, 0x947bf368 } },
6928 .fill_helper = bpf_fill_maxinsns3,
6929 },
6930 {
6931 "BPF_MAXINSNS: Too many instructions",
6932 { },
6933 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
6934 { },
6935 { },
6936 .fill_helper = bpf_fill_maxinsns4,
Yonghong Song09584b42018-02-02 22:37:15 -08006937 .expected_errcode = -EINVAL,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006938 },
6939 { /* Mainly checking JIT here. */
6940 "BPF_MAXINSNS: Very long jump",
6941 { },
6942 CLASSIC | FLAG_NO_DATA,
6943 { },
6944 { { 0, 0xabababab } },
6945 .fill_helper = bpf_fill_maxinsns5,
6946 },
6947 { /* Mainly checking JIT here. */
6948 "BPF_MAXINSNS: Ctx heavy transformations",
6949 { },
6950 CLASSIC,
6951 { },
6952 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01006953 { 1, SKB_VLAN_PRESENT },
6954 { 10, SKB_VLAN_PRESENT }
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006955 },
6956 .fill_helper = bpf_fill_maxinsns6,
6957 },
6958 { /* Mainly checking JIT here. */
6959 "BPF_MAXINSNS: Call heavy transformations",
6960 { },
6961 CLASSIC | FLAG_NO_DATA,
6962 { },
6963 { { 1, 0 }, { 10, 0 } },
6964 .fill_helper = bpf_fill_maxinsns7,
6965 },
6966 { /* Mainly checking JIT here. */
6967 "BPF_MAXINSNS: Jump heavy test",
6968 { },
6969 CLASSIC | FLAG_NO_DATA,
6970 { },
6971 { { 0, 0xffffffff } },
6972 .fill_helper = bpf_fill_maxinsns8,
6973 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02006974 { /* Mainly checking JIT here. */
6975 "BPF_MAXINSNS: Very long jump backwards",
6976 { },
6977 INTERNAL | FLAG_NO_DATA,
6978 { },
6979 { { 0, 0xcbababab } },
6980 .fill_helper = bpf_fill_maxinsns9,
6981 },
6982 { /* Mainly checking JIT here. */
6983 "BPF_MAXINSNS: Edge hopping nuthouse",
6984 { },
6985 INTERNAL | FLAG_NO_DATA,
6986 { },
6987 { { 0, 0xabababac } },
6988 .fill_helper = bpf_fill_maxinsns10,
6989 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02006990 {
6991 "BPF_MAXINSNS: Jump, gap, jump, ...",
6992 { },
6993 CLASSIC | FLAG_NO_DATA,
6994 { },
6995 { { 0, 0xababcbac } },
6996 .fill_helper = bpf_fill_maxinsns11,
6997 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006998 {
Daniel Borkmannbe088152018-06-02 23:06:32 +02006999 "BPF_MAXINSNS: jump over MSH",
7000 { },
7001 CLASSIC | FLAG_EXPECTED_FAIL,
7002 { 0xfa, 0xfb, 0xfc, 0xfd, },
7003 { { 4, 0xabababab } },
7004 .fill_helper = bpf_fill_maxinsns12,
7005 .expected_errcode = -EINVAL,
7006 },
7007 {
7008 "BPF_MAXINSNS: exec all MSH",
7009 { },
7010 CLASSIC,
7011 { 0xfa, 0xfb, 0xfc, 0xfd, },
7012 { { 4, 0xababab83 } },
7013 .fill_helper = bpf_fill_maxinsns13,
7014 },
7015 {
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007016 "BPF_MAXINSNS: ld_abs+get_processor_id",
7017 { },
7018 CLASSIC,
7019 { },
7020 { { 1, 0xbee } },
7021 .fill_helper = bpf_fill_ld_abs_get_processor_id,
7022 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02007023 /*
7024 * LD_IND / LD_ABS on fragmented SKBs
7025 */
7026 {
7027 "LD_IND byte frag",
7028 .u.insns = {
7029 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7030 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
7031 BPF_STMT(BPF_RET | BPF_A, 0x0),
7032 },
7033 CLASSIC | FLAG_SKB_FRAG,
7034 { },
7035 { {0x40, 0x42} },
7036 .frag_data = {
7037 0x42, 0x00, 0x00, 0x00,
7038 0x43, 0x44, 0x00, 0x00,
7039 0x21, 0x07, 0x19, 0x83,
7040 },
7041 },
7042 {
7043 "LD_IND halfword frag",
7044 .u.insns = {
7045 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7046 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
7047 BPF_STMT(BPF_RET | BPF_A, 0x0),
7048 },
7049 CLASSIC | FLAG_SKB_FRAG,
7050 { },
7051 { {0x40, 0x4344} },
7052 .frag_data = {
7053 0x42, 0x00, 0x00, 0x00,
7054 0x43, 0x44, 0x00, 0x00,
7055 0x21, 0x07, 0x19, 0x83,
7056 },
7057 },
7058 {
7059 "LD_IND word frag",
7060 .u.insns = {
7061 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7062 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
7063 BPF_STMT(BPF_RET | BPF_A, 0x0),
7064 },
7065 CLASSIC | FLAG_SKB_FRAG,
7066 { },
7067 { {0x40, 0x21071983} },
7068 .frag_data = {
7069 0x42, 0x00, 0x00, 0x00,
7070 0x43, 0x44, 0x00, 0x00,
7071 0x21, 0x07, 0x19, 0x83,
7072 },
7073 },
7074 {
7075 "LD_IND halfword mixed head/frag",
7076 .u.insns = {
7077 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7078 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7079 BPF_STMT(BPF_RET | BPF_A, 0x0),
7080 },
7081 CLASSIC | FLAG_SKB_FRAG,
7082 { [0x3e] = 0x25, [0x3f] = 0x05, },
7083 { {0x40, 0x0519} },
7084 .frag_data = { 0x19, 0x82 },
7085 },
7086 {
7087 "LD_IND word mixed head/frag",
7088 .u.insns = {
7089 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7090 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7091 BPF_STMT(BPF_RET | BPF_A, 0x0),
7092 },
7093 CLASSIC | FLAG_SKB_FRAG,
7094 { [0x3e] = 0x25, [0x3f] = 0x05, },
7095 { {0x40, 0x25051982} },
7096 .frag_data = { 0x19, 0x82 },
7097 },
7098 {
7099 "LD_ABS byte frag",
7100 .u.insns = {
7101 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
7102 BPF_STMT(BPF_RET | BPF_A, 0x0),
7103 },
7104 CLASSIC | FLAG_SKB_FRAG,
7105 { },
7106 { {0x40, 0x42} },
7107 .frag_data = {
7108 0x42, 0x00, 0x00, 0x00,
7109 0x43, 0x44, 0x00, 0x00,
7110 0x21, 0x07, 0x19, 0x83,
7111 },
7112 },
7113 {
7114 "LD_ABS halfword frag",
7115 .u.insns = {
7116 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
7117 BPF_STMT(BPF_RET | BPF_A, 0x0),
7118 },
7119 CLASSIC | FLAG_SKB_FRAG,
7120 { },
7121 { {0x40, 0x4344} },
7122 .frag_data = {
7123 0x42, 0x00, 0x00, 0x00,
7124 0x43, 0x44, 0x00, 0x00,
7125 0x21, 0x07, 0x19, 0x83,
7126 },
7127 },
7128 {
7129 "LD_ABS word frag",
7130 .u.insns = {
7131 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
7132 BPF_STMT(BPF_RET | BPF_A, 0x0),
7133 },
7134 CLASSIC | FLAG_SKB_FRAG,
7135 { },
7136 { {0x40, 0x21071983} },
7137 .frag_data = {
7138 0x42, 0x00, 0x00, 0x00,
7139 0x43, 0x44, 0x00, 0x00,
7140 0x21, 0x07, 0x19, 0x83,
7141 },
7142 },
7143 {
7144 "LD_ABS halfword mixed head/frag",
7145 .u.insns = {
7146 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7147 BPF_STMT(BPF_RET | BPF_A, 0x0),
7148 },
7149 CLASSIC | FLAG_SKB_FRAG,
7150 { [0x3e] = 0x25, [0x3f] = 0x05, },
7151 { {0x40, 0x0519} },
7152 .frag_data = { 0x19, 0x82 },
7153 },
7154 {
7155 "LD_ABS word mixed head/frag",
7156 .u.insns = {
7157 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
7158 BPF_STMT(BPF_RET | BPF_A, 0x0),
7159 },
7160 CLASSIC | FLAG_SKB_FRAG,
7161 { [0x3e] = 0x25, [0x3f] = 0x05, },
7162 { {0x40, 0x25051982} },
7163 .frag_data = { 0x19, 0x82 },
7164 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007165 /*
7166 * LD_IND / LD_ABS on non fragmented SKBs
7167 */
7168 {
7169 /*
7170 * this tests that the JIT/interpreter correctly resets X
7171 * before using it in an LD_IND instruction.
7172 */
7173 "LD_IND byte default X",
7174 .u.insns = {
7175 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7176 BPF_STMT(BPF_RET | BPF_A, 0x0),
7177 },
7178 CLASSIC,
7179 { [0x1] = 0x42 },
7180 { {0x40, 0x42 } },
7181 },
7182 {
7183 "LD_IND byte positive offset",
7184 .u.insns = {
7185 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7186 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7187 BPF_STMT(BPF_RET | BPF_A, 0x0),
7188 },
7189 CLASSIC,
7190 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7191 { {0x40, 0x82 } },
7192 },
7193 {
7194 "LD_IND byte negative offset",
7195 .u.insns = {
7196 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7197 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
7198 BPF_STMT(BPF_RET | BPF_A, 0x0),
7199 },
7200 CLASSIC,
7201 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7202 { {0x40, 0x05 } },
7203 },
7204 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007205 "LD_IND byte positive offset, all ff",
7206 .u.insns = {
7207 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7208 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7209 BPF_STMT(BPF_RET | BPF_A, 0x0),
7210 },
7211 CLASSIC,
7212 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7213 { {0x40, 0xff } },
7214 },
7215 {
7216 "LD_IND byte positive offset, out of bounds",
7217 .u.insns = {
7218 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7219 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7220 BPF_STMT(BPF_RET | BPF_A, 0x0),
7221 },
7222 CLASSIC,
7223 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7224 { {0x3f, 0 }, },
7225 },
7226 {
7227 "LD_IND byte negative offset, out of bounds",
7228 .u.insns = {
7229 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7230 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
7231 BPF_STMT(BPF_RET | BPF_A, 0x0),
7232 },
7233 CLASSIC,
7234 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7235 { {0x3f, 0 } },
7236 },
7237 {
7238 "LD_IND byte negative offset, multiple calls",
7239 .u.insns = {
7240 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7241 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
7242 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
7243 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
7244 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
7245 BPF_STMT(BPF_RET | BPF_A, 0x0),
7246 },
7247 CLASSIC,
7248 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7249 { {0x40, 0x82 }, },
7250 },
7251 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007252 "LD_IND halfword positive offset",
7253 .u.insns = {
7254 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7255 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
7256 BPF_STMT(BPF_RET | BPF_A, 0x0),
7257 },
7258 CLASSIC,
7259 {
7260 [0x1c] = 0xaa, [0x1d] = 0x55,
7261 [0x1e] = 0xbb, [0x1f] = 0x66,
7262 [0x20] = 0xcc, [0x21] = 0x77,
7263 [0x22] = 0xdd, [0x23] = 0x88,
7264 },
7265 { {0x40, 0xdd88 } },
7266 },
7267 {
7268 "LD_IND halfword negative offset",
7269 .u.insns = {
7270 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7271 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
7272 BPF_STMT(BPF_RET | BPF_A, 0x0),
7273 },
7274 CLASSIC,
7275 {
7276 [0x1c] = 0xaa, [0x1d] = 0x55,
7277 [0x1e] = 0xbb, [0x1f] = 0x66,
7278 [0x20] = 0xcc, [0x21] = 0x77,
7279 [0x22] = 0xdd, [0x23] = 0x88,
7280 },
7281 { {0x40, 0xbb66 } },
7282 },
7283 {
7284 "LD_IND halfword unaligned",
7285 .u.insns = {
7286 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7287 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7288 BPF_STMT(BPF_RET | BPF_A, 0x0),
7289 },
7290 CLASSIC,
7291 {
7292 [0x1c] = 0xaa, [0x1d] = 0x55,
7293 [0x1e] = 0xbb, [0x1f] = 0x66,
7294 [0x20] = 0xcc, [0x21] = 0x77,
7295 [0x22] = 0xdd, [0x23] = 0x88,
7296 },
7297 { {0x40, 0x66cc } },
7298 },
7299 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007300 "LD_IND halfword positive offset, all ff",
7301 .u.insns = {
7302 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
7303 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7304 BPF_STMT(BPF_RET | BPF_A, 0x0),
7305 },
7306 CLASSIC,
7307 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7308 { {0x40, 0xffff } },
7309 },
7310 {
7311 "LD_IND halfword positive offset, out of bounds",
7312 .u.insns = {
7313 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7314 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7315 BPF_STMT(BPF_RET | BPF_A, 0x0),
7316 },
7317 CLASSIC,
7318 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7319 { {0x3f, 0 }, },
7320 },
7321 {
7322 "LD_IND halfword negative offset, out of bounds",
7323 .u.insns = {
7324 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7325 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
7326 BPF_STMT(BPF_RET | BPF_A, 0x0),
7327 },
7328 CLASSIC,
7329 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7330 { {0x3f, 0 } },
7331 },
7332 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007333 "LD_IND word positive offset",
7334 .u.insns = {
7335 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7336 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
7337 BPF_STMT(BPF_RET | BPF_A, 0x0),
7338 },
7339 CLASSIC,
7340 {
7341 [0x1c] = 0xaa, [0x1d] = 0x55,
7342 [0x1e] = 0xbb, [0x1f] = 0x66,
7343 [0x20] = 0xcc, [0x21] = 0x77,
7344 [0x22] = 0xdd, [0x23] = 0x88,
7345 [0x24] = 0xee, [0x25] = 0x99,
7346 [0x26] = 0xff, [0x27] = 0xaa,
7347 },
7348 { {0x40, 0xee99ffaa } },
7349 },
7350 {
7351 "LD_IND word negative offset",
7352 .u.insns = {
7353 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7354 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
7355 BPF_STMT(BPF_RET | BPF_A, 0x0),
7356 },
7357 CLASSIC,
7358 {
7359 [0x1c] = 0xaa, [0x1d] = 0x55,
7360 [0x1e] = 0xbb, [0x1f] = 0x66,
7361 [0x20] = 0xcc, [0x21] = 0x77,
7362 [0x22] = 0xdd, [0x23] = 0x88,
7363 [0x24] = 0xee, [0x25] = 0x99,
7364 [0x26] = 0xff, [0x27] = 0xaa,
7365 },
7366 { {0x40, 0xaa55bb66 } },
7367 },
7368 {
7369 "LD_IND word unaligned (addr & 3 == 2)",
7370 .u.insns = {
7371 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7372 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7373 BPF_STMT(BPF_RET | BPF_A, 0x0),
7374 },
7375 CLASSIC,
7376 {
7377 [0x1c] = 0xaa, [0x1d] = 0x55,
7378 [0x1e] = 0xbb, [0x1f] = 0x66,
7379 [0x20] = 0xcc, [0x21] = 0x77,
7380 [0x22] = 0xdd, [0x23] = 0x88,
7381 [0x24] = 0xee, [0x25] = 0x99,
7382 [0x26] = 0xff, [0x27] = 0xaa,
7383 },
7384 { {0x40, 0xbb66cc77 } },
7385 },
7386 {
7387 "LD_IND word unaligned (addr & 3 == 1)",
7388 .u.insns = {
7389 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7390 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
7391 BPF_STMT(BPF_RET | BPF_A, 0x0),
7392 },
7393 CLASSIC,
7394 {
7395 [0x1c] = 0xaa, [0x1d] = 0x55,
7396 [0x1e] = 0xbb, [0x1f] = 0x66,
7397 [0x20] = 0xcc, [0x21] = 0x77,
7398 [0x22] = 0xdd, [0x23] = 0x88,
7399 [0x24] = 0xee, [0x25] = 0x99,
7400 [0x26] = 0xff, [0x27] = 0xaa,
7401 },
7402 { {0x40, 0x55bb66cc } },
7403 },
7404 {
7405 "LD_IND word unaligned (addr & 3 == 3)",
7406 .u.insns = {
7407 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7408 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
7409 BPF_STMT(BPF_RET | BPF_A, 0x0),
7410 },
7411 CLASSIC,
7412 {
7413 [0x1c] = 0xaa, [0x1d] = 0x55,
7414 [0x1e] = 0xbb, [0x1f] = 0x66,
7415 [0x20] = 0xcc, [0x21] = 0x77,
7416 [0x22] = 0xdd, [0x23] = 0x88,
7417 [0x24] = 0xee, [0x25] = 0x99,
7418 [0x26] = 0xff, [0x27] = 0xaa,
7419 },
7420 { {0x40, 0x66cc77dd } },
7421 },
7422 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007423 "LD_IND word positive offset, all ff",
7424 .u.insns = {
7425 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7426 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7427 BPF_STMT(BPF_RET | BPF_A, 0x0),
7428 },
7429 CLASSIC,
7430 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7431 { {0x40, 0xffffffff } },
7432 },
7433 {
7434 "LD_IND word positive offset, out of bounds",
7435 .u.insns = {
7436 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7437 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7438 BPF_STMT(BPF_RET | BPF_A, 0x0),
7439 },
7440 CLASSIC,
7441 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7442 { {0x3f, 0 }, },
7443 },
7444 {
7445 "LD_IND word negative offset, out of bounds",
7446 .u.insns = {
7447 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7448 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
7449 BPF_STMT(BPF_RET | BPF_A, 0x0),
7450 },
7451 CLASSIC,
7452 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7453 { {0x3f, 0 } },
7454 },
7455 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007456 "LD_ABS byte",
7457 .u.insns = {
7458 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
7459 BPF_STMT(BPF_RET | BPF_A, 0x0),
7460 },
7461 CLASSIC,
7462 {
7463 [0x1c] = 0xaa, [0x1d] = 0x55,
7464 [0x1e] = 0xbb, [0x1f] = 0x66,
7465 [0x20] = 0xcc, [0x21] = 0x77,
7466 [0x22] = 0xdd, [0x23] = 0x88,
7467 [0x24] = 0xee, [0x25] = 0x99,
7468 [0x26] = 0xff, [0x27] = 0xaa,
7469 },
7470 { {0x40, 0xcc } },
7471 },
7472 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007473 "LD_ABS byte positive offset, all ff",
7474 .u.insns = {
7475 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7476 BPF_STMT(BPF_RET | BPF_A, 0x0),
7477 },
7478 CLASSIC,
7479 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7480 { {0x40, 0xff } },
7481 },
7482 {
7483 "LD_ABS byte positive offset, out of bounds",
7484 .u.insns = {
7485 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7486 BPF_STMT(BPF_RET | BPF_A, 0x0),
7487 },
7488 CLASSIC,
7489 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7490 { {0x3f, 0 }, },
7491 },
7492 {
7493 "LD_ABS byte negative offset, out of bounds load",
7494 .u.insns = {
7495 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
7496 BPF_STMT(BPF_RET | BPF_A, 0x0),
7497 },
7498 CLASSIC | FLAG_EXPECTED_FAIL,
7499 .expected_errcode = -EINVAL,
7500 },
7501 {
7502 "LD_ABS byte negative offset, in bounds",
7503 .u.insns = {
7504 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7505 BPF_STMT(BPF_RET | BPF_A, 0x0),
7506 },
7507 CLASSIC,
7508 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7509 { {0x40, 0x82 }, },
7510 },
7511 {
7512 "LD_ABS byte negative offset, out of bounds",
7513 .u.insns = {
7514 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7515 BPF_STMT(BPF_RET | BPF_A, 0x0),
7516 },
7517 CLASSIC,
7518 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7519 { {0x3f, 0 }, },
7520 },
7521 {
7522 "LD_ABS byte negative offset, multiple calls",
7523 .u.insns = {
7524 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
7525 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
7526 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
7527 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7528 BPF_STMT(BPF_RET | BPF_A, 0x0),
7529 },
7530 CLASSIC,
7531 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7532 { {0x40, 0x82 }, },
7533 },
7534 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007535 "LD_ABS halfword",
7536 .u.insns = {
7537 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
7538 BPF_STMT(BPF_RET | BPF_A, 0x0),
7539 },
7540 CLASSIC,
7541 {
7542 [0x1c] = 0xaa, [0x1d] = 0x55,
7543 [0x1e] = 0xbb, [0x1f] = 0x66,
7544 [0x20] = 0xcc, [0x21] = 0x77,
7545 [0x22] = 0xdd, [0x23] = 0x88,
7546 [0x24] = 0xee, [0x25] = 0x99,
7547 [0x26] = 0xff, [0x27] = 0xaa,
7548 },
7549 { {0x40, 0xdd88 } },
7550 },
7551 {
7552 "LD_ABS halfword unaligned",
7553 .u.insns = {
7554 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
7555 BPF_STMT(BPF_RET | BPF_A, 0x0),
7556 },
7557 CLASSIC,
7558 {
7559 [0x1c] = 0xaa, [0x1d] = 0x55,
7560 [0x1e] = 0xbb, [0x1f] = 0x66,
7561 [0x20] = 0xcc, [0x21] = 0x77,
7562 [0x22] = 0xdd, [0x23] = 0x88,
7563 [0x24] = 0xee, [0x25] = 0x99,
7564 [0x26] = 0xff, [0x27] = 0xaa,
7565 },
7566 { {0x40, 0x99ff } },
7567 },
7568 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007569 "LD_ABS halfword positive offset, all ff",
7570 .u.insns = {
7571 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
7572 BPF_STMT(BPF_RET | BPF_A, 0x0),
7573 },
7574 CLASSIC,
7575 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7576 { {0x40, 0xffff } },
7577 },
7578 {
7579 "LD_ABS halfword positive offset, out of bounds",
7580 .u.insns = {
7581 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7582 BPF_STMT(BPF_RET | BPF_A, 0x0),
7583 },
7584 CLASSIC,
7585 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7586 { {0x3f, 0 }, },
7587 },
7588 {
7589 "LD_ABS halfword negative offset, out of bounds load",
7590 .u.insns = {
7591 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
7592 BPF_STMT(BPF_RET | BPF_A, 0x0),
7593 },
7594 CLASSIC | FLAG_EXPECTED_FAIL,
7595 .expected_errcode = -EINVAL,
7596 },
7597 {
7598 "LD_ABS halfword negative offset, in bounds",
7599 .u.insns = {
7600 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7601 BPF_STMT(BPF_RET | BPF_A, 0x0),
7602 },
7603 CLASSIC,
7604 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7605 { {0x40, 0x1982 }, },
7606 },
7607 {
7608 "LD_ABS halfword negative offset, out of bounds",
7609 .u.insns = {
7610 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7611 BPF_STMT(BPF_RET | BPF_A, 0x0),
7612 },
7613 CLASSIC,
7614 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7615 { {0x3f, 0 }, },
7616 },
7617 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007618 "LD_ABS word",
7619 .u.insns = {
7620 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
7621 BPF_STMT(BPF_RET | BPF_A, 0x0),
7622 },
7623 CLASSIC,
7624 {
7625 [0x1c] = 0xaa, [0x1d] = 0x55,
7626 [0x1e] = 0xbb, [0x1f] = 0x66,
7627 [0x20] = 0xcc, [0x21] = 0x77,
7628 [0x22] = 0xdd, [0x23] = 0x88,
7629 [0x24] = 0xee, [0x25] = 0x99,
7630 [0x26] = 0xff, [0x27] = 0xaa,
7631 },
7632 { {0x40, 0xaa55bb66 } },
7633 },
7634 {
7635 "LD_ABS word unaligned (addr & 3 == 2)",
7636 .u.insns = {
7637 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
7638 BPF_STMT(BPF_RET | BPF_A, 0x0),
7639 },
7640 CLASSIC,
7641 {
7642 [0x1c] = 0xaa, [0x1d] = 0x55,
7643 [0x1e] = 0xbb, [0x1f] = 0x66,
7644 [0x20] = 0xcc, [0x21] = 0x77,
7645 [0x22] = 0xdd, [0x23] = 0x88,
7646 [0x24] = 0xee, [0x25] = 0x99,
7647 [0x26] = 0xff, [0x27] = 0xaa,
7648 },
7649 { {0x40, 0xdd88ee99 } },
7650 },
7651 {
7652 "LD_ABS word unaligned (addr & 3 == 1)",
7653 .u.insns = {
7654 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
7655 BPF_STMT(BPF_RET | BPF_A, 0x0),
7656 },
7657 CLASSIC,
7658 {
7659 [0x1c] = 0xaa, [0x1d] = 0x55,
7660 [0x1e] = 0xbb, [0x1f] = 0x66,
7661 [0x20] = 0xcc, [0x21] = 0x77,
7662 [0x22] = 0xdd, [0x23] = 0x88,
7663 [0x24] = 0xee, [0x25] = 0x99,
7664 [0x26] = 0xff, [0x27] = 0xaa,
7665 },
7666 { {0x40, 0x77dd88ee } },
7667 },
7668 {
7669 "LD_ABS word unaligned (addr & 3 == 3)",
7670 .u.insns = {
7671 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
7672 BPF_STMT(BPF_RET | BPF_A, 0x0),
7673 },
7674 CLASSIC,
7675 {
7676 [0x1c] = 0xaa, [0x1d] = 0x55,
7677 [0x1e] = 0xbb, [0x1f] = 0x66,
7678 [0x20] = 0xcc, [0x21] = 0x77,
7679 [0x22] = 0xdd, [0x23] = 0x88,
7680 [0x24] = 0xee, [0x25] = 0x99,
7681 [0x26] = 0xff, [0x27] = 0xaa,
7682 },
7683 { {0x40, 0x88ee99ff } },
7684 },
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007685 {
7686 "LD_ABS word positive offset, all ff",
7687 .u.insns = {
7688 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
7689 BPF_STMT(BPF_RET | BPF_A, 0x0),
7690 },
7691 CLASSIC,
7692 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7693 { {0x40, 0xffffffff } },
7694 },
7695 {
7696 "LD_ABS word positive offset, out of bounds",
7697 .u.insns = {
7698 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
7699 BPF_STMT(BPF_RET | BPF_A, 0x0),
7700 },
7701 CLASSIC,
7702 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7703 { {0x3f, 0 }, },
7704 },
7705 {
7706 "LD_ABS word negative offset, out of bounds load",
7707 .u.insns = {
7708 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
7709 BPF_STMT(BPF_RET | BPF_A, 0x0),
7710 },
7711 CLASSIC | FLAG_EXPECTED_FAIL,
7712 .expected_errcode = -EINVAL,
7713 },
7714 {
7715 "LD_ABS word negative offset, in bounds",
7716 .u.insns = {
7717 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
7718 BPF_STMT(BPF_RET | BPF_A, 0x0),
7719 },
7720 CLASSIC,
7721 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7722 { {0x40, 0x25051982 }, },
7723 },
7724 {
7725 "LD_ABS word negative offset, out of bounds",
7726 .u.insns = {
7727 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
7728 BPF_STMT(BPF_RET | BPF_A, 0x0),
7729 },
7730 CLASSIC,
7731 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7732 { {0x3f, 0 }, },
7733 },
7734 {
7735 "LDX_MSH standalone, preserved A",
7736 .u.insns = {
7737 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7738 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
7739 BPF_STMT(BPF_RET | BPF_A, 0x0),
7740 },
7741 CLASSIC,
7742 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7743 { {0x40, 0xffeebbaa }, },
7744 },
7745 {
7746 "LDX_MSH standalone, preserved A 2",
7747 .u.insns = {
7748 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
7749 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
7750 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
7751 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
7752 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
7753 BPF_STMT(BPF_RET | BPF_A, 0x0),
7754 },
7755 CLASSIC,
7756 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7757 { {0x40, 0x175e9d63 }, },
7758 },
7759 {
7760 "LDX_MSH standalone, test result 1",
7761 .u.insns = {
7762 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7763 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
7764 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7765 BPF_STMT(BPF_RET | BPF_A, 0x0),
7766 },
7767 CLASSIC,
7768 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7769 { {0x40, 0x14 }, },
7770 },
7771 {
7772 "LDX_MSH standalone, test result 2",
7773 .u.insns = {
7774 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7775 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
7776 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7777 BPF_STMT(BPF_RET | BPF_A, 0x0),
7778 },
7779 CLASSIC,
7780 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7781 { {0x40, 0x24 }, },
7782 },
7783 {
7784 "LDX_MSH standalone, negative offset",
7785 .u.insns = {
7786 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7787 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
7788 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7789 BPF_STMT(BPF_RET | BPF_A, 0x0),
7790 },
7791 CLASSIC,
7792 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7793 { {0x40, 0 }, },
7794 },
7795 {
7796 "LDX_MSH standalone, negative offset 2",
7797 .u.insns = {
7798 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7799 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
7800 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7801 BPF_STMT(BPF_RET | BPF_A, 0x0),
7802 },
7803 CLASSIC,
7804 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7805 { {0x40, 0x24 }, },
7806 },
7807 {
7808 "LDX_MSH standalone, out of bounds",
7809 .u.insns = {
7810 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
7811 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
7812 BPF_STMT(BPF_MISC | BPF_TXA, 0),
7813 BPF_STMT(BPF_RET | BPF_A, 0x0),
7814 },
7815 CLASSIC,
7816 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7817 { {0x40, 0 }, },
7818 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02007819 /*
7820 * verify that the interpreter or JIT correctly sets A and X
7821 * to 0.
7822 */
7823 {
7824 "ADD default X",
7825 .u.insns = {
7826 /*
7827 * A = 0x42
7828 * A = A + X
7829 * ret A
7830 */
7831 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
7832 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
7833 BPF_STMT(BPF_RET | BPF_A, 0x0),
7834 },
7835 CLASSIC | FLAG_NO_DATA,
7836 {},
7837 { {0x1, 0x42 } },
7838 },
7839 {
7840 "ADD default A",
7841 .u.insns = {
7842 /*
7843 * A = A + 0x42
7844 * ret A
7845 */
7846 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
7847 BPF_STMT(BPF_RET | BPF_A, 0x0),
7848 },
7849 CLASSIC | FLAG_NO_DATA,
7850 {},
7851 { {0x1, 0x42 } },
7852 },
7853 {
7854 "SUB default X",
7855 .u.insns = {
7856 /*
7857 * A = 0x66
7858 * A = A - X
7859 * ret A
7860 */
7861 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
7862 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
7863 BPF_STMT(BPF_RET | BPF_A, 0x0),
7864 },
7865 CLASSIC | FLAG_NO_DATA,
7866 {},
7867 { {0x1, 0x66 } },
7868 },
7869 {
7870 "SUB default A",
7871 .u.insns = {
7872 /*
7873 * A = A - -0x66
7874 * ret A
7875 */
7876 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
7877 BPF_STMT(BPF_RET | BPF_A, 0x0),
7878 },
7879 CLASSIC | FLAG_NO_DATA,
7880 {},
7881 { {0x1, 0x66 } },
7882 },
7883 {
7884 "MUL default X",
7885 .u.insns = {
7886 /*
7887 * A = 0x42
7888 * A = A * X
7889 * ret A
7890 */
7891 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
7892 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
7893 BPF_STMT(BPF_RET | BPF_A, 0x0),
7894 },
7895 CLASSIC | FLAG_NO_DATA,
7896 {},
7897 { {0x1, 0x0 } },
7898 },
7899 {
7900 "MUL default A",
7901 .u.insns = {
7902 /*
7903 * A = A * 0x66
7904 * ret A
7905 */
7906 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
7907 BPF_STMT(BPF_RET | BPF_A, 0x0),
7908 },
7909 CLASSIC | FLAG_NO_DATA,
7910 {},
7911 { {0x1, 0x0 } },
7912 },
7913 {
7914 "DIV default X",
7915 .u.insns = {
7916 /*
7917 * A = 0x42
7918 * A = A / X ; this halt the filter execution if X is 0
7919 * ret 0x42
7920 */
7921 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
7922 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
7923 BPF_STMT(BPF_RET | BPF_K, 0x42),
7924 },
7925 CLASSIC | FLAG_NO_DATA,
7926 {},
7927 { {0x1, 0x0 } },
7928 },
7929 {
7930 "DIV default A",
7931 .u.insns = {
7932 /*
7933 * A = A / 1
7934 * ret A
7935 */
7936 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
7937 BPF_STMT(BPF_RET | BPF_A, 0x0),
7938 },
7939 CLASSIC | FLAG_NO_DATA,
7940 {},
7941 { {0x1, 0x0 } },
7942 },
7943 {
Yang Shid4e4bc12015-11-04 11:36:37 -08007944 "MOD default X",
7945 .u.insns = {
7946 /*
7947 * A = 0x42
7948 * A = A mod X ; this halt the filter execution if X is 0
7949 * ret 0x42
7950 */
7951 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
7952 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
7953 BPF_STMT(BPF_RET | BPF_K, 0x42),
7954 },
7955 CLASSIC | FLAG_NO_DATA,
7956 {},
7957 { {0x1, 0x0 } },
7958 },
7959 {
7960 "MOD default A",
7961 .u.insns = {
7962 /*
7963 * A = A mod 1
7964 * ret A
7965 */
7966 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
7967 BPF_STMT(BPF_RET | BPF_A, 0x0),
7968 },
7969 CLASSIC | FLAG_NO_DATA,
7970 {},
7971 { {0x1, 0x0 } },
7972 },
7973 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02007974 "JMP EQ default A",
7975 .u.insns = {
7976 /*
7977 * cmp A, 0x0, 0, 1
7978 * ret 0x42
7979 * ret 0x66
7980 */
7981 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
7982 BPF_STMT(BPF_RET | BPF_K, 0x42),
7983 BPF_STMT(BPF_RET | BPF_K, 0x66),
7984 },
7985 CLASSIC | FLAG_NO_DATA,
7986 {},
7987 { {0x1, 0x42 } },
7988 },
7989 {
7990 "JMP EQ default X",
7991 .u.insns = {
7992 /*
7993 * A = 0x0
7994 * cmp A, X, 0, 1
7995 * ret 0x42
7996 * ret 0x66
7997 */
7998 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
7999 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
8000 BPF_STMT(BPF_RET | BPF_K, 0x42),
8001 BPF_STMT(BPF_RET | BPF_K, 0x66),
8002 },
8003 CLASSIC | FLAG_NO_DATA,
8004 {},
8005 { {0x1, 0x42 } },
8006 },
Daniel Borkmannfcd1c912018-01-20 01:24:31 +01008007 /* Checking interpreter vs JIT wrt signed extended imms. */
8008 {
8009 "JNE signed compare, test 1",
8010 .u.insns_int = {
8011 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8012 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8013 BPF_MOV64_REG(R2, R1),
8014 BPF_ALU64_REG(BPF_AND, R2, R3),
8015 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8016 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
8017 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8018 BPF_EXIT_INSN(),
8019 },
8020 INTERNAL,
8021 { },
8022 { { 0, 1 } },
8023 },
8024 {
8025 "JNE signed compare, test 2",
8026 .u.insns_int = {
8027 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8028 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8029 BPF_MOV64_REG(R2, R1),
8030 BPF_ALU64_REG(BPF_AND, R2, R3),
8031 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8032 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
8033 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8034 BPF_EXIT_INSN(),
8035 },
8036 INTERNAL,
8037 { },
8038 { { 0, 1 } },
8039 },
8040 {
8041 "JNE signed compare, test 3",
8042 .u.insns_int = {
8043 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8044 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8045 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
8046 BPF_MOV64_REG(R2, R1),
8047 BPF_ALU64_REG(BPF_AND, R2, R3),
8048 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8049 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
8050 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8051 BPF_EXIT_INSN(),
8052 },
8053 INTERNAL,
8054 { },
8055 { { 0, 2 } },
8056 },
8057 {
8058 "JNE signed compare, test 4",
8059 .u.insns_int = {
8060 BPF_LD_IMM64(R1, -17104896),
8061 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8062 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
8063 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8064 BPF_EXIT_INSN(),
8065 },
8066 INTERNAL,
8067 { },
8068 { { 0, 2 } },
8069 },
8070 {
8071 "JNE signed compare, test 5",
8072 .u.insns_int = {
8073 BPF_LD_IMM64(R1, 0xfefb0000),
8074 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8075 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
8076 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8077 BPF_EXIT_INSN(),
8078 },
8079 INTERNAL,
8080 { },
8081 { { 0, 1 } },
8082 },
8083 {
8084 "JNE signed compare, test 6",
8085 .u.insns_int = {
8086 BPF_LD_IMM64(R1, 0x7efb0000),
8087 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8088 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
8089 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8090 BPF_EXIT_INSN(),
8091 },
8092 INTERNAL,
8093 { },
8094 { { 0, 2 } },
8095 },
8096 {
8097 "JNE signed compare, test 7",
8098 .u.insns = {
8099 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
8100 BPF_STMT(BPF_MISC | BPF_TAX, 0),
8101 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
8102 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
8103 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
8104 BPF_STMT(BPF_RET | BPF_K, 1),
8105 BPF_STMT(BPF_RET | BPF_K, 2),
8106 },
8107 CLASSIC | FLAG_NO_DATA,
8108 {},
8109 { { 0, 2 } },
8110 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008111};
8112
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008113static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008114
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008115static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008116{
8117 struct sk_buff *skb;
8118
8119 if (size >= MAX_DATA)
8120 return NULL;
8121
8122 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
8123 if (!skb)
8124 return NULL;
8125
yuan linyude77b962017-06-18 22:48:17 +08008126 __skb_put_data(skb, buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008127
8128 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008129 skb_reset_mac_header(skb);
8130 skb->protocol = htons(ETH_P_IP);
8131 skb->pkt_type = SKB_TYPE;
8132 skb->mark = SKB_MARK;
8133 skb->hash = SKB_HASH;
8134 skb->queue_mapping = SKB_QUEUE_MAP;
8135 skb->vlan_tci = SKB_VLAN_TCI;
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01008136 skb->vlan_present = SKB_VLAN_PRESENT;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01008137 skb->vlan_proto = htons(ETH_P_IP);
Song Liu100811932018-09-27 09:34:41 -07008138 dev_net_set(&dev, &init_net);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008139 skb->dev = &dev;
8140 skb->dev->ifindex = SKB_DEV_IFINDEX;
8141 skb->dev->type = SKB_DEV_TYPE;
8142 skb_set_network_header(skb, min(size, ETH_HLEN));
8143
8144 return skb;
8145}
8146
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008147static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008148{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02008149 struct sk_buff *skb;
8150 struct page *page;
8151
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008152 if (test->aux & FLAG_NO_DATA)
8153 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008154
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008155 /* Test case expects an skb, so populate one. Various
8156 * subtests generate skbs of different sizes based on
8157 * the same data.
8158 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02008159 skb = populate_skb(test->data, test->test[sub].data_size);
8160 if (!skb)
8161 return NULL;
8162
8163 if (test->aux & FLAG_SKB_FRAG) {
8164 /*
8165 * when the test requires a fragmented skb, add a
8166 * single fragment to the skb, filled with
8167 * test->frag_data.
8168 */
8169 void *ptr;
8170
8171 page = alloc_page(GFP_KERNEL);
8172
8173 if (!page)
8174 goto err_kfree_skb;
8175
8176 ptr = kmap(page);
8177 if (!ptr)
8178 goto err_free_page;
8179 memcpy(ptr, test->frag_data, MAX_DATA);
8180 kunmap(page);
8181 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
8182 }
8183
8184 return skb;
8185
8186err_free_page:
8187 __free_page(page);
8188err_kfree_skb:
8189 kfree_skb(skb);
8190 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008191}
8192
8193static void release_test_data(const struct bpf_test *test, void *data)
8194{
8195 if (test->aux & FLAG_NO_DATA)
8196 return;
8197
8198 kfree_skb(data);
8199}
8200
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008201static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008202{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008203 struct sock_filter *fp;
8204 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008205
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008206 if (tests[which].fill_helper)
8207 return tests[which].u.ptr.len;
8208
8209 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07008210 for (len = MAX_INSNS - 1; len > 0; --len)
8211 if (fp[len].code != 0 || fp[len].k != 0)
8212 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008213
Chema Gonzaleze9d94502014-05-30 10:15:12 -07008214 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008215}
8216
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008217static void *filter_pointer(int which)
8218{
8219 if (tests[which].fill_helper)
8220 return tests[which].u.ptr.insns;
8221 else
8222 return tests[which].u.insns;
8223}
8224
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008225static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008226{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008227 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008228 unsigned int flen = filter_length(which);
8229 void *fptr = filter_pointer(which);
8230 struct sock_fprog_kern fprog;
8231 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008232
8233 switch (test_type) {
8234 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008235 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008236 fprog.len = flen;
8237
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008238 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008239 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
Yonghong Song09584b42018-02-02 22:37:15 -08008240 if (*err == tests[which].expected_errcode) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008241 pr_cont("PASS\n");
8242 /* Verifier rejected filter as expected. */
8243 *err = 0;
8244 return NULL;
8245 } else {
8246 pr_cont("UNEXPECTED_PASS\n");
8247 /* Verifier didn't reject the test that's
8248 * bad enough, just return!
8249 */
8250 *err = -EINVAL;
8251 return NULL;
8252 }
8253 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008254 if (*err) {
Alexei Starovoitov290af862018-01-09 10:04:29 -08008255 pr_cont("FAIL to prog_create err=%d len=%d\n",
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008256 *err, fprog.len);
8257 return NULL;
8258 }
8259 break;
8260
8261 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02008262 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008263 if (fp == NULL) {
8264 pr_cont("UNEXPECTED_FAIL no memory left\n");
8265 *err = -ENOMEM;
8266 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008267 }
8268
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008269 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02008270 /* Type doesn't really matter here as long as it's not unspec. */
8271 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008272 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07008273 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008274
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02008275 /* We cannot error here as we don't need type compatibility
8276 * checks.
8277 */
8278 fp = bpf_prog_select_runtime(fp, err);
Alexei Starovoitov290af862018-01-09 10:04:29 -08008279 if (*err) {
8280 pr_cont("FAIL to select_runtime err=%d\n", *err);
8281 return NULL;
8282 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008283 break;
8284 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008285
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008286 *err = 0;
8287 return fp;
8288}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008289
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008290static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008291{
8292 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008293
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008294 switch (test_type) {
8295 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008296 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008297 break;
8298 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008299 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008300 break;
8301 }
8302}
8303
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008304static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008305 int runs, u64 *duration)
8306{
8307 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07008308 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008309
David Miller6eac7792020-02-24 15:01:44 +01008310 migrate_disable();
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008311 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008312
8313 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008314 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008315
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008316 finish = ktime_get_ns();
David Miller6eac7792020-02-24 15:01:44 +01008317 migrate_enable();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008318
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008319 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008320 do_div(*duration, runs);
8321
8322 return ret;
8323}
8324
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008325static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008326{
8327 int err_cnt = 0, i, runs = MAX_TESTRUNS;
8328
8329 for (i = 0; i < MAX_SUBTESTS; i++) {
8330 void *data;
8331 u64 duration;
8332 u32 ret;
8333
Johan Almbladh2b7e9f22021-07-21 12:38:22 +02008334 /*
8335 * NOTE: Several sub-tests may be present, in which case
8336 * a zero {data_size, result} tuple indicates the end of
8337 * the sub-test array. The first test is always run,
8338 * even if both data_size and result happen to be zero.
8339 */
8340 if (i > 0 &&
8341 test->test[i].data_size == 0 &&
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008342 test->test[i].result == 0)
8343 break;
8344
8345 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02008346 if (!data && !(test->aux & FLAG_NO_DATA)) {
8347 pr_cont("data generation failed ");
8348 err_cnt++;
8349 break;
8350 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008351 ret = __run_one(fp, data, runs, &duration);
8352 release_test_data(test, data);
8353
8354 if (ret == test->test[i].result) {
8355 pr_cont("%lld ", duration);
8356 } else {
8357 pr_cont("ret %d != %d ", ret,
8358 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008359 err_cnt++;
8360 }
8361 }
8362
8363 return err_cnt;
8364}
8365
Nicolas Schichand2648d42015-08-04 15:19:10 +02008366static char test_name[64];
8367module_param_string(test_name, test_name, sizeof(test_name), 0);
8368
8369static int test_id = -1;
8370module_param(test_id, int, 0);
8371
8372static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
8373module_param_array(test_range, int, NULL, 0);
8374
8375static __init int find_test_index(const char *test_name)
8376{
8377 int i;
8378
8379 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8380 if (!strcmp(tests[i].descr, test_name))
8381 return i;
8382 }
8383 return -1;
8384}
8385
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008386static __init int prepare_bpf_tests(void)
8387{
8388 int i;
8389
Nicolas Schichand2648d42015-08-04 15:19:10 +02008390 if (test_id >= 0) {
8391 /*
8392 * if a test_id was specified, use test_range to
8393 * cover only that test.
8394 */
8395 if (test_id >= ARRAY_SIZE(tests)) {
8396 pr_err("test_bpf: invalid test_id specified.\n");
8397 return -EINVAL;
8398 }
8399
8400 test_range[0] = test_id;
8401 test_range[1] = test_id;
8402 } else if (*test_name) {
8403 /*
8404 * if a test_name was specified, find it and setup
8405 * test_range to cover only that test.
8406 */
8407 int idx = find_test_index(test_name);
8408
8409 if (idx < 0) {
8410 pr_err("test_bpf: no test named '%s' found.\n",
8411 test_name);
8412 return -EINVAL;
8413 }
8414 test_range[0] = idx;
8415 test_range[1] = idx;
8416 } else {
8417 /*
8418 * check that the supplied test_range is valid.
8419 */
8420 if (test_range[0] >= ARRAY_SIZE(tests) ||
8421 test_range[1] >= ARRAY_SIZE(tests) ||
8422 test_range[0] < 0 || test_range[1] < 0) {
8423 pr_err("test_bpf: test_range is out of bound.\n");
8424 return -EINVAL;
8425 }
8426
8427 if (test_range[1] < test_range[0]) {
8428 pr_err("test_bpf: test_range is ending before it starts.\n");
8429 return -EINVAL;
8430 }
8431 }
8432
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008433 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8434 if (tests[i].fill_helper &&
8435 tests[i].fill_helper(&tests[i]) < 0)
8436 return -ENOMEM;
8437 }
8438
8439 return 0;
8440}
8441
8442static __init void destroy_bpf_tests(void)
8443{
8444 int i;
8445
8446 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8447 if (tests[i].fill_helper)
8448 kfree(tests[i].u.ptr.insns);
8449 }
8450}
8451
Nicolas Schichand2648d42015-08-04 15:19:10 +02008452static bool exclude_test(int test_id)
8453{
8454 return test_id < test_range[0] || test_id > test_range[1];
8455}
8456
Yonghong Song76db8082018-03-21 16:31:04 -07008457static __init struct sk_buff *build_test_skb(void)
8458{
8459 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
8460 struct sk_buff *skb[2];
8461 struct page *page[2];
8462 int i, data_size = 8;
8463
8464 for (i = 0; i < 2; i++) {
8465 page[i] = alloc_page(GFP_KERNEL);
8466 if (!page[i]) {
8467 if (i == 0)
8468 goto err_page0;
8469 else
8470 goto err_page1;
8471 }
8472
8473 /* this will set skb[i]->head_frag */
8474 skb[i] = dev_alloc_skb(headroom + data_size);
8475 if (!skb[i]) {
8476 if (i == 0)
8477 goto err_skb0;
8478 else
8479 goto err_skb1;
8480 }
8481
8482 skb_reserve(skb[i], headroom);
8483 skb_put(skb[i], data_size);
8484 skb[i]->protocol = htons(ETH_P_IP);
8485 skb_reset_network_header(skb[i]);
8486 skb_set_mac_header(skb[i], -ETH_HLEN);
8487
8488 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
8489 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
8490 }
8491
8492 /* setup shinfo */
8493 skb_shinfo(skb[0])->gso_size = 1448;
8494 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
8495 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
8496 skb_shinfo(skb[0])->gso_segs = 0;
8497 skb_shinfo(skb[0])->frag_list = skb[1];
8498
8499 /* adjust skb[0]'s len */
8500 skb[0]->len += skb[1]->len;
8501 skb[0]->data_len += skb[1]->data_len;
8502 skb[0]->truesize += skb[1]->truesize;
8503
8504 return skb[0];
8505
8506err_skb1:
8507 __free_page(page[1]);
8508err_page1:
8509 kfree_skb(skb[0]);
8510err_skb0:
8511 __free_page(page[0]);
8512err_page0:
8513 return NULL;
8514}
8515
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03008516static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
8517{
8518 unsigned int alloc_size = 2000;
8519 unsigned int headroom = 102, doffset = 72, data_size = 1308;
8520 struct sk_buff *skb[2];
8521 int i;
8522
8523 /* skbs linked in a frag_list, both with linear data, with head_frag=0
8524 * (data allocated by kmalloc), both have tcp data of 1308 bytes
8525 * (total payload is 2616 bytes).
8526 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
8527 */
8528 for (i = 0; i < 2; i++) {
8529 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
8530 if (!skb[i]) {
8531 if (i == 0)
8532 goto err_skb0;
8533 else
8534 goto err_skb1;
8535 }
8536
8537 skb[i]->protocol = htons(ETH_P_IPV6);
8538 skb_reserve(skb[i], headroom);
8539 skb_put(skb[i], doffset + data_size);
8540 skb_reset_network_header(skb[i]);
8541 if (i == 0)
8542 skb_reset_mac_header(skb[i]);
8543 else
8544 skb_set_mac_header(skb[i], -ETH_HLEN);
8545 __skb_pull(skb[i], doffset);
8546 }
8547
8548 /* setup shinfo.
8549 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
8550 * reduced gso_size.
8551 */
8552 skb_shinfo(skb[0])->gso_size = 1288;
8553 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
8554 skb_shinfo(skb[0])->gso_segs = 0;
8555 skb_shinfo(skb[0])->frag_list = skb[1];
8556
8557 /* adjust skb[0]'s len */
8558 skb[0]->len += skb[1]->len;
8559 skb[0]->data_len += skb[1]->len;
8560 skb[0]->truesize += skb[1]->truesize;
8561
8562 return skb[0];
8563
8564err_skb1:
8565 kfree_skb(skb[0]);
8566err_skb0:
8567 return NULL;
8568}
8569
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008570struct skb_segment_test {
8571 const char *descr;
8572 struct sk_buff *(*build_skb)(void);
Yonghong Song76db8082018-03-21 16:31:04 -07008573 netdev_features_t features;
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008574};
8575
8576static struct skb_segment_test skb_segment_tests[] __initconst = {
8577 {
8578 .descr = "gso_with_rx_frags",
8579 .build_skb = build_test_skb,
8580 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
8581 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03008582 },
8583 {
8584 .descr = "gso_linear_no_head_frag",
8585 .build_skb = build_test_skb_linear_no_head_frag,
8586 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
8587 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
8588 NETIF_F_LLTX_BIT | NETIF_F_GRO |
8589 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
8590 NETIF_F_HW_VLAN_STAG_TX_BIT
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008591 }
8592};
8593
8594static __init int test_skb_segment_single(const struct skb_segment_test *test)
8595{
Yonghong Song76db8082018-03-21 16:31:04 -07008596 struct sk_buff *skb, *segs;
8597 int ret = -1;
8598
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008599 skb = test->build_skb();
Yonghong Song76db8082018-03-21 16:31:04 -07008600 if (!skb) {
8601 pr_info("%s: failed to build_test_skb", __func__);
8602 goto done;
8603 }
8604
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008605 segs = skb_segment(skb, test->features);
Dan Carpenter99fe29d2018-03-28 14:48:36 +03008606 if (!IS_ERR(segs)) {
Yonghong Song76db8082018-03-21 16:31:04 -07008607 kfree_skb_list(segs);
8608 ret = 0;
Yonghong Song76db8082018-03-21 16:31:04 -07008609 }
8610 kfree_skb(skb);
8611done:
8612 return ret;
8613}
8614
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008615static __init int test_skb_segment(void)
8616{
8617 int i, err_cnt = 0, pass_cnt = 0;
8618
8619 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
8620 const struct skb_segment_test *test = &skb_segment_tests[i];
8621
8622 pr_info("#%d %s ", i, test->descr);
8623
8624 if (test_skb_segment_single(test)) {
8625 pr_cont("FAIL\n");
8626 err_cnt++;
8627 } else {
8628 pr_cont("PASS\n");
8629 pass_cnt++;
8630 }
8631 }
8632
8633 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
8634 pass_cnt, err_cnt);
8635 return err_cnt ? -EINVAL : 0;
8636}
8637
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008638static __init int test_bpf(void)
8639{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008640 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02008641 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008642
8643 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008644 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008645 int err;
8646
Eric Dumazetd40bc962018-02-26 10:52:46 -08008647 cond_resched();
Nicolas Schichand2648d42015-08-04 15:19:10 +02008648 if (exclude_test(i))
8649 continue;
8650
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008651 pr_info("#%d %s ", i, tests[i].descr);
8652
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008653 fp = generate_filter(i, &err);
8654 if (fp == NULL) {
8655 if (err == 0) {
8656 pass_cnt++;
8657 continue;
8658 }
Alexei Starovoitov290af862018-01-09 10:04:29 -08008659 err_cnt++;
8660 continue;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008661 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02008662
8663 pr_cont("jited:%u ", fp->jited);
8664
8665 run_cnt++;
8666 if (fp->jited)
8667 jit_cnt++;
8668
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008669 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008670 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008671
8672 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008673 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008674 err_cnt++;
8675 } else {
8676 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008677 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008678 }
8679 }
8680
Daniel Borkmann327941f2015-04-30 16:17:27 +02008681 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
8682 pass_cnt, err_cnt, jit_cnt, run_cnt);
8683
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008684 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008685}
8686
8687static int __init test_bpf_init(void)
8688{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008689 int ret;
8690
8691 ret = prepare_bpf_tests();
8692 if (ret < 0)
8693 return ret;
8694
8695 ret = test_bpf();
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008696 destroy_bpf_tests();
Yonghong Song76db8082018-03-21 16:31:04 -07008697 if (ret)
8698 return ret;
8699
8700 return test_skb_segment();
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008701}
8702
8703static void __exit test_bpf_exit(void)
8704{
8705}
8706
8707module_init(test_bpf_init);
8708module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008709
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008710MODULE_LICENSE("GPL");