blob: 0018d51b93b0a3908cbb9c20241d9f3b9f450870 [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
Johan Almbladh66e5eb82021-08-09 11:18:25 +0200464static int bpf_fill_long_jmp(struct bpf_test *self)
465{
466 unsigned int len = BPF_MAXINSNS;
467 struct bpf_insn *insn;
468 int i;
469
470 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
471 if (!insn)
472 return -ENOMEM;
473
474 insn[0] = BPF_ALU64_IMM(BPF_MOV, R0, 1);
475 insn[1] = BPF_JMP_IMM(BPF_JEQ, R0, 1, len - 2 - 1);
476
477 /*
478 * Fill with a complex 64-bit operation that expands to a lot of
479 * instructions on 32-bit JITs. The large jump offset can then
480 * overflow the conditional branch field size, triggering a branch
481 * conversion mechanism in some JITs.
482 *
483 * Note: BPF_MAXINSNS of ALU64 MUL is enough to trigger such branch
484 * conversion on the 32-bit MIPS JIT. For other JITs, the instruction
485 * count and/or operation may need to be modified to trigger the
486 * branch conversion.
487 */
488 for (i = 2; i < len - 1; i++)
489 insn[i] = BPF_ALU64_IMM(BPF_MUL, R0, (i << 16) + i);
490
491 insn[len - 1] = BPF_EXIT_INSN();
492
493 self->u.ptr.insns = insn;
494 self->u.ptr.len = len;
495
496 return 0;
497}
498
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700499static struct bpf_test tests[] = {
500 {
501 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700502 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700503 BPF_STMT(BPF_LD | BPF_IMM, 1),
504 BPF_STMT(BPF_MISC | BPF_TAX, 0),
505 BPF_STMT(BPF_LD | BPF_IMM, 2),
506 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
507 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
508 BPF_STMT(BPF_MISC | BPF_TAX, 0),
509 BPF_STMT(BPF_LD | BPF_LEN, 0),
510 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
511 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
512 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
513 BPF_STMT(BPF_RET | BPF_A, 0)
514 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200515 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700516 { 10, 20, 30, 40, 50 },
517 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
518 },
519 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700520 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700521 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700522 BPF_STMT(BPF_LDX | BPF_LEN, 0),
523 BPF_STMT(BPF_MISC | BPF_TXA, 0),
524 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
525 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
526 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200527 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700528 { 10, 20, 30, 40, 50 },
529 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
530 },
531 {
532 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700533 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700534 BPF_STMT(BPF_LD | BPF_IMM, 1),
535 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
536 BPF_STMT(BPF_LDX | BPF_IMM, 3),
537 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
538 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
539 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
540 BPF_STMT(BPF_RET | BPF_A, 0)
541 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200542 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700543 { },
544 { { 0, 0xfffffffd } }
545 },
546 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300547 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700548 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700549 BPF_STMT(BPF_LD | BPF_IMM, 8),
550 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
551 BPF_STMT(BPF_MISC | BPF_TAX, 0),
552 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
553 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
554 BPF_STMT(BPF_MISC | BPF_TAX, 0),
555 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
556 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300557 BPF_STMT(BPF_MISC | BPF_TAX, 0),
558 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
559 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
560 BPF_STMT(BPF_MISC | BPF_TAX, 0),
561 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
562 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700563 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
564 BPF_STMT(BPF_RET | BPF_A, 0)
565 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200566 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700567 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300568 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700569 },
570 {
571 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700572 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700573 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
574 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
575 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
576 BPF_STMT(BPF_MISC | BPF_TAX, 0),
577 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
578 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
579 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
580 BPF_STMT(BPF_RET | BPF_A, 0)
581 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200582 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700583 { },
584 { { 0, 0x800000ff }, { 1, 0x800000ff } },
585 },
586 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700587 "LD_IMM_0",
588 .u.insns = {
589 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
591 BPF_STMT(BPF_RET | BPF_K, 0),
592 BPF_STMT(BPF_RET | BPF_K, 1),
593 },
594 CLASSIC,
595 { },
596 { { 1, 1 } },
597 },
598 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700599 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700600 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
603 BPF_STMT(BPF_RET | BPF_K, 1)
604 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200605 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700606 { },
607 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
608 },
609 {
610 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700611 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700612 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
613 BPF_STMT(BPF_RET | BPF_K, 1)
614 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200615 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700616 { },
617 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
618 },
619 {
620 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700621 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700622 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
623 BPF_STMT(BPF_MISC | BPF_TAX, 0),
624 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
625 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
626 BPF_STMT(BPF_RET | BPF_A, 0)
627 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200628 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700629 { 1, 2, 3 },
630 { { 1, 0 }, { 2, 3 } },
631 },
632 {
633 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700634 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700635 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
636 BPF_STMT(BPF_LDX | BPF_LEN, 0),
637 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
638 BPF_STMT(BPF_MISC | BPF_TAX, 0),
639 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
640 BPF_STMT(BPF_RET | BPF_A, 0)
641 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200642 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700643 { 1, 2, 3, 0xff },
644 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
645 },
646 {
647 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700648 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700649 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
650 BPF_STMT(BPF_MISC | BPF_TAX, 0),
651 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
652 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
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 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
657 { { 15, 0 }, { 16, 3 } },
658 },
659 {
660 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700661 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700662 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
663 BPF_STMT(BPF_LDX | BPF_LEN, 0),
664 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
665 BPF_STMT(BPF_MISC | BPF_TAX, 0),
666 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
667 BPF_STMT(BPF_RET | BPF_A, 0)
668 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200669 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700670 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
671 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
672 },
673 {
674 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700675 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700676 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
677 SKF_AD_OFF + SKF_AD_PKTTYPE),
678 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
679 BPF_STMT(BPF_RET | BPF_K, 1),
680 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
681 SKF_AD_OFF + SKF_AD_PKTTYPE),
682 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
683 BPF_STMT(BPF_RET | BPF_K, 1),
684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_PKTTYPE),
686 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
687 BPF_STMT(BPF_RET | BPF_K, 1),
688 BPF_STMT(BPF_RET | BPF_A, 0)
689 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200690 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700691 { },
692 { { 1, 3 }, { 10, 3 } },
693 },
694 {
695 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700696 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700697 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
698 SKF_AD_OFF + SKF_AD_MARK),
699 BPF_STMT(BPF_RET | BPF_A, 0)
700 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200701 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700702 { },
703 { { 1, SKB_MARK}, { 10, SKB_MARK} },
704 },
705 {
706 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700707 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700708 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
709 SKF_AD_OFF + SKF_AD_RXHASH),
710 BPF_STMT(BPF_RET | BPF_A, 0)
711 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200712 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700713 { },
714 { { 1, SKB_HASH}, { 10, SKB_HASH} },
715 },
716 {
717 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700718 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700719 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
720 SKF_AD_OFF + SKF_AD_QUEUE),
721 BPF_STMT(BPF_RET | BPF_A, 0)
722 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200723 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700724 { },
725 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
726 },
727 {
728 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700729 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700730 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
731 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
732 BPF_STMT(BPF_RET | BPF_K, 0),
733 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
734 SKF_AD_OFF + SKF_AD_PROTOCOL),
735 BPF_STMT(BPF_MISC | BPF_TAX, 0),
736 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
737 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
738 BPF_STMT(BPF_RET | BPF_K, 0),
739 BPF_STMT(BPF_MISC | BPF_TXA, 0),
740 BPF_STMT(BPF_RET | BPF_A, 0)
741 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200742 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700743 { 10, 20, 30 },
744 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
745 },
746 {
747 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700748 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700749 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
750 SKF_AD_OFF + SKF_AD_VLAN_TAG),
751 BPF_STMT(BPF_RET | BPF_A, 0)
752 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200753 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700754 { },
755 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100756 { 1, SKB_VLAN_TCI },
757 { 10, SKB_VLAN_TCI }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700758 },
759 },
760 {
761 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700762 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700763 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
764 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
765 BPF_STMT(BPF_RET | BPF_A, 0)
766 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200767 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700768 { },
769 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100770 { 1, SKB_VLAN_PRESENT },
771 { 10, SKB_VLAN_PRESENT }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700772 },
773 },
774 {
775 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700776 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700777 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
778 SKF_AD_OFF + SKF_AD_IFINDEX),
779 BPF_STMT(BPF_RET | BPF_A, 0)
780 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200781 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700782 { },
783 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
784 },
785 {
786 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700787 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700788 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
789 SKF_AD_OFF + SKF_AD_HATYPE),
790 BPF_STMT(BPF_RET | BPF_A, 0)
791 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200792 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700793 { },
794 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
795 },
796 {
797 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700798 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700799 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
800 SKF_AD_OFF + SKF_AD_CPU),
801 BPF_STMT(BPF_MISC | BPF_TAX, 0),
802 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
803 SKF_AD_OFF + SKF_AD_CPU),
804 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
805 BPF_STMT(BPF_RET | BPF_A, 0)
806 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200807 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700808 { },
809 { { 1, 0 }, { 10, 0 } },
810 },
811 {
812 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700813 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700814 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700815 BPF_STMT(BPF_MISC | BPF_TXA, 0),
816 BPF_STMT(BPF_LDX | BPF_IMM, 3),
817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_NLATTR),
819 BPF_STMT(BPF_RET | BPF_A, 0)
820 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200821 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700822#ifdef __BIG_ENDIAN
823 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
824#else
825 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
826#endif
827 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700828 },
829 {
830 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700831 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700832 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700833 BPF_STMT(BPF_LDX | BPF_IMM, 3),
834 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
835 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700836 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700839 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700840 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
841 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700842 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700843 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
844 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700845 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700846 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
847 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700848 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700849 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
850 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700851 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700852 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
853 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700854 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700855 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
856 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
857 BPF_STMT(BPF_RET | BPF_A, 0)
858 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200859 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700860#ifdef __BIG_ENDIAN
861 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
862#else
863 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
864#endif
865 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700866 },
867 {
868 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700869 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700870 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
871 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
872 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
873 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
874 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
875 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
876 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
877 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
878 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
879 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
880 BPF_STMT(BPF_RET | BPF_A, 0)
881 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200882 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700883 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
884 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
885 * id 9737, seq 1, length 64
886 */
887 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
889 0x08, 0x00,
890 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
891 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
892 { { 30, 0 }, { 100, 42 } },
893 },
894 {
895 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700896 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700897 BPF_STMT(BPF_LD | BPF_IMM, 10),
898 BPF_STMT(BPF_LDX | BPF_IMM, 300),
899 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
900 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
901 BPF_STMT(BPF_RET | BPF_A, 0)
902 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200903 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700904 { },
Nathan Chancellor09845432019-08-18 21:34:20 -0700905 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700906 },
907 {
908 "SPILL_FILL",
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_IMM, 2),
912 BPF_STMT(BPF_ALU | BPF_RSH, 1),
913 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
914 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
915 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
916 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
917 BPF_STMT(BPF_STX, 15), /* M3 = len */
918 BPF_STMT(BPF_LDX | BPF_MEM, 1),
919 BPF_STMT(BPF_LD | BPF_MEM, 2),
920 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
921 BPF_STMT(BPF_LDX | BPF_MEM, 15),
922 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
923 BPF_STMT(BPF_RET | BPF_A, 0)
924 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200925 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700926 { },
927 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
928 },
929 {
930 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700931 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700932 BPF_STMT(BPF_LDX | BPF_LEN, 0),
933 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
934 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
935 BPF_STMT(BPF_RET | BPF_K, 1),
936 BPF_STMT(BPF_RET | BPF_K, MAX_K)
937 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200938 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700939 { 3, 3, 3, 3, 3 },
940 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
941 },
942 {
943 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700944 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700945 BPF_STMT(BPF_LDX | BPF_LEN, 0),
946 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
947 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
948 BPF_STMT(BPF_RET | BPF_K, 1),
949 BPF_STMT(BPF_RET | BPF_K, MAX_K)
950 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200951 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700952 { 4, 4, 4, 3, 3 },
953 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
954 },
955 {
Daniel Borkmann92b31a92017-08-10 01:39:55 +0200956 "JGE (jt 0), test 1",
957 .u.insns = {
958 BPF_STMT(BPF_LDX | BPF_LEN, 0),
959 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
960 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
961 BPF_STMT(BPF_RET | BPF_K, 1),
962 BPF_STMT(BPF_RET | BPF_K, MAX_K)
963 },
964 CLASSIC,
965 { 4, 4, 4, 3, 3 },
966 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
967 },
968 {
969 "JGE (jt 0), test 2",
970 .u.insns = {
971 BPF_STMT(BPF_LDX | BPF_LEN, 0),
972 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
973 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
974 BPF_STMT(BPF_RET | BPF_K, 1),
975 BPF_STMT(BPF_RET | BPF_K, MAX_K)
976 },
977 CLASSIC,
978 { 4, 4, 5, 3, 3 },
979 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
980 },
981 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700982 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700983 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700984 BPF_STMT(BPF_LDX | BPF_LEN, 0),
985 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
986 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
987 BPF_STMT(BPF_RET | BPF_K, 10),
988 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
989 BPF_STMT(BPF_RET | BPF_K, 20),
990 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
991 BPF_STMT(BPF_RET | BPF_K, 30),
992 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
993 BPF_STMT(BPF_RET | BPF_K, 40),
994 BPF_STMT(BPF_RET | BPF_K, MAX_K)
995 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200996 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700997 { 1, 2, 3, 4, 5 },
998 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
999 },
1000 {
1001 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -07001002 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001003 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1004 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
1005 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1006 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1007 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1008 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1009 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
1010 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1011 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
1012 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
1013 BPF_STMT(BPF_RET | BPF_K, 10),
1014 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
1015 BPF_STMT(BPF_RET | BPF_K, 20),
1016 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1017 BPF_STMT(BPF_RET | BPF_K, 30),
1018 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1019 BPF_STMT(BPF_RET | BPF_K, 30),
1020 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1021 BPF_STMT(BPF_RET | BPF_K, 30),
1022 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1023 BPF_STMT(BPF_RET | BPF_K, 30),
1024 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1025 BPF_STMT(BPF_RET | BPF_K, 30),
1026 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1027 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001028 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001029 { 0, 0xAA, 0x55, 1 },
1030 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
1031 },
1032 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001033 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -07001034 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +02001035 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1036 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1037 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1038 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1039 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1040 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1041 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1042 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1043 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1044 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1045 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1046 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1047 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1048 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1049 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1050 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1051 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1052 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1053 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1054 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1055 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1056 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1057 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1058 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001059 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001060 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001061 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1062 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1063 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1064 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1065 */
1066 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1067 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1068 0x08, 0x00,
1069 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1070 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1071 0x0a, 0x01, 0x01, 0x95, /* ip src */
1072 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1073 0xc2, 0x24,
1074 0x00, 0x16 /* dst port */ },
1075 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1076 },
1077 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001078 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001079 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001080 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1081 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1082 * (len > 115 or len < 30000000000)' -d
1083 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001084 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1085 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1086 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1087 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1088 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1089 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1090 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1091 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1092 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1093 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1094 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1095 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1096 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1097 BPF_STMT(BPF_ST, 1),
1098 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1099 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1100 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1101 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1102 BPF_STMT(BPF_LD | BPF_MEM, 1),
1103 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1104 BPF_STMT(BPF_ST, 5),
1105 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1106 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1107 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1108 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1109 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1110 BPF_STMT(BPF_LD | BPF_MEM, 5),
1111 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1112 BPF_STMT(BPF_LD | BPF_LEN, 0),
1113 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1114 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1115 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1116 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001117 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001118 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001119 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1120 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1121 0x08, 0x00,
1122 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1123 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1124 0x0a, 0x01, 0x01, 0x95, /* ip src */
1125 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1126 0xc2, 0x24,
1127 0x00, 0x16 /* dst port */ },
1128 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1129 },
1130 {
1131 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001132 .u.insns = {
Zhen Lei53b0fe32021-07-07 18:07:28 -07001133 /* check that uninitialized X and A contain zeros */
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001134 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1135 BPF_STMT(BPF_RET | BPF_A, 0)
1136 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001137 CLASSIC,
1138 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001139 { {1, 0}, {2, 0} },
1140 },
1141 {
1142 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001143 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001144 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1145 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1146 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1147 BPF_ALU64_REG(BPF_SUB, R1, R2),
1148 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1149 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1150 BPF_ALU64_REG(BPF_MOV, R0, R1),
1151 BPF_EXIT_INSN(),
1152 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001153 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001154 { },
1155 { { 0, 0xfffffffd } }
1156 },
1157 {
1158 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001159 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001160 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1161 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1162 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1163 BPF_ALU64_REG(BPF_MUL, R1, R2),
1164 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1165 BPF_EXIT_INSN(),
1166 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1167 BPF_EXIT_INSN(),
1168 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001169 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001170 { },
1171 { { 0, 1 } }
1172 },
1173 {
1174 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001175 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001176 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1177 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1178 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1179 BPF_ALU64_REG(BPF_MUL, R1, R2),
1180 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1181 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1182 BPF_EXIT_INSN(),
1183 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1184 BPF_EXIT_INSN(),
1185 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001186 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001187 { },
1188 { { 0, 1 } }
1189 },
1190 {
1191 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001192 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001193 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1194 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1195 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1196 BPF_ALU32_REG(BPF_MUL, R1, R2),
1197 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1198 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1199 BPF_EXIT_INSN(),
1200 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1201 BPF_EXIT_INSN(),
1202 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001203 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001204 { },
1205 { { 0, 1 } }
1206 },
1207 {
1208 /* Have to test all register combinations, since
1209 * JITing of different registers will produce
1210 * different asm code.
1211 */
1212 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001213 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001214 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1215 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1216 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1217 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1218 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1219 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1220 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1221 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1222 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1223 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1224 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1225 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1226 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1227 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1228 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1229 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1230 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1231 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1232 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1233 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1234 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1235 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1236 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1237 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1238 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1239 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1240 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1241 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1242 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1243 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1244 BPF_ALU64_REG(BPF_ADD, R0, R0),
1245 BPF_ALU64_REG(BPF_ADD, R0, R1),
1246 BPF_ALU64_REG(BPF_ADD, R0, R2),
1247 BPF_ALU64_REG(BPF_ADD, R0, R3),
1248 BPF_ALU64_REG(BPF_ADD, R0, R4),
1249 BPF_ALU64_REG(BPF_ADD, R0, R5),
1250 BPF_ALU64_REG(BPF_ADD, R0, R6),
1251 BPF_ALU64_REG(BPF_ADD, R0, R7),
1252 BPF_ALU64_REG(BPF_ADD, R0, R8),
1253 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1254 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1255 BPF_EXIT_INSN(),
1256 BPF_ALU64_REG(BPF_ADD, R1, R0),
1257 BPF_ALU64_REG(BPF_ADD, R1, R1),
1258 BPF_ALU64_REG(BPF_ADD, R1, R2),
1259 BPF_ALU64_REG(BPF_ADD, R1, R3),
1260 BPF_ALU64_REG(BPF_ADD, R1, R4),
1261 BPF_ALU64_REG(BPF_ADD, R1, R5),
1262 BPF_ALU64_REG(BPF_ADD, R1, R6),
1263 BPF_ALU64_REG(BPF_ADD, R1, R7),
1264 BPF_ALU64_REG(BPF_ADD, R1, R8),
1265 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1266 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1267 BPF_EXIT_INSN(),
1268 BPF_ALU64_REG(BPF_ADD, R2, R0),
1269 BPF_ALU64_REG(BPF_ADD, R2, R1),
1270 BPF_ALU64_REG(BPF_ADD, R2, R2),
1271 BPF_ALU64_REG(BPF_ADD, R2, R3),
1272 BPF_ALU64_REG(BPF_ADD, R2, R4),
1273 BPF_ALU64_REG(BPF_ADD, R2, R5),
1274 BPF_ALU64_REG(BPF_ADD, R2, R6),
1275 BPF_ALU64_REG(BPF_ADD, R2, R7),
1276 BPF_ALU64_REG(BPF_ADD, R2, R8),
1277 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1278 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1279 BPF_EXIT_INSN(),
1280 BPF_ALU64_REG(BPF_ADD, R3, R0),
1281 BPF_ALU64_REG(BPF_ADD, R3, R1),
1282 BPF_ALU64_REG(BPF_ADD, R3, R2),
1283 BPF_ALU64_REG(BPF_ADD, R3, R3),
1284 BPF_ALU64_REG(BPF_ADD, R3, R4),
1285 BPF_ALU64_REG(BPF_ADD, R3, R5),
1286 BPF_ALU64_REG(BPF_ADD, R3, R6),
1287 BPF_ALU64_REG(BPF_ADD, R3, R7),
1288 BPF_ALU64_REG(BPF_ADD, R3, R8),
1289 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1290 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1291 BPF_EXIT_INSN(),
1292 BPF_ALU64_REG(BPF_ADD, R4, R0),
1293 BPF_ALU64_REG(BPF_ADD, R4, R1),
1294 BPF_ALU64_REG(BPF_ADD, R4, R2),
1295 BPF_ALU64_REG(BPF_ADD, R4, R3),
1296 BPF_ALU64_REG(BPF_ADD, R4, R4),
1297 BPF_ALU64_REG(BPF_ADD, R4, R5),
1298 BPF_ALU64_REG(BPF_ADD, R4, R6),
1299 BPF_ALU64_REG(BPF_ADD, R4, R7),
1300 BPF_ALU64_REG(BPF_ADD, R4, R8),
1301 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1302 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1303 BPF_EXIT_INSN(),
1304 BPF_ALU64_REG(BPF_ADD, R5, R0),
1305 BPF_ALU64_REG(BPF_ADD, R5, R1),
1306 BPF_ALU64_REG(BPF_ADD, R5, R2),
1307 BPF_ALU64_REG(BPF_ADD, R5, R3),
1308 BPF_ALU64_REG(BPF_ADD, R5, R4),
1309 BPF_ALU64_REG(BPF_ADD, R5, R5),
1310 BPF_ALU64_REG(BPF_ADD, R5, R6),
1311 BPF_ALU64_REG(BPF_ADD, R5, R7),
1312 BPF_ALU64_REG(BPF_ADD, R5, R8),
1313 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1314 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1315 BPF_EXIT_INSN(),
1316 BPF_ALU64_REG(BPF_ADD, R6, R0),
1317 BPF_ALU64_REG(BPF_ADD, R6, R1),
1318 BPF_ALU64_REG(BPF_ADD, R6, R2),
1319 BPF_ALU64_REG(BPF_ADD, R6, R3),
1320 BPF_ALU64_REG(BPF_ADD, R6, R4),
1321 BPF_ALU64_REG(BPF_ADD, R6, R5),
1322 BPF_ALU64_REG(BPF_ADD, R6, R6),
1323 BPF_ALU64_REG(BPF_ADD, R6, R7),
1324 BPF_ALU64_REG(BPF_ADD, R6, R8),
1325 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1326 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1327 BPF_EXIT_INSN(),
1328 BPF_ALU64_REG(BPF_ADD, R7, R0),
1329 BPF_ALU64_REG(BPF_ADD, R7, R1),
1330 BPF_ALU64_REG(BPF_ADD, R7, R2),
1331 BPF_ALU64_REG(BPF_ADD, R7, R3),
1332 BPF_ALU64_REG(BPF_ADD, R7, R4),
1333 BPF_ALU64_REG(BPF_ADD, R7, R5),
1334 BPF_ALU64_REG(BPF_ADD, R7, R6),
1335 BPF_ALU64_REG(BPF_ADD, R7, R7),
1336 BPF_ALU64_REG(BPF_ADD, R7, R8),
1337 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1338 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1339 BPF_EXIT_INSN(),
1340 BPF_ALU64_REG(BPF_ADD, R8, R0),
1341 BPF_ALU64_REG(BPF_ADD, R8, R1),
1342 BPF_ALU64_REG(BPF_ADD, R8, R2),
1343 BPF_ALU64_REG(BPF_ADD, R8, R3),
1344 BPF_ALU64_REG(BPF_ADD, R8, R4),
1345 BPF_ALU64_REG(BPF_ADD, R8, R5),
1346 BPF_ALU64_REG(BPF_ADD, R8, R6),
1347 BPF_ALU64_REG(BPF_ADD, R8, R7),
1348 BPF_ALU64_REG(BPF_ADD, R8, R8),
1349 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1350 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1351 BPF_EXIT_INSN(),
1352 BPF_ALU64_REG(BPF_ADD, R9, R0),
1353 BPF_ALU64_REG(BPF_ADD, R9, R1),
1354 BPF_ALU64_REG(BPF_ADD, R9, R2),
1355 BPF_ALU64_REG(BPF_ADD, R9, R3),
1356 BPF_ALU64_REG(BPF_ADD, R9, R4),
1357 BPF_ALU64_REG(BPF_ADD, R9, R5),
1358 BPF_ALU64_REG(BPF_ADD, R9, R6),
1359 BPF_ALU64_REG(BPF_ADD, R9, R7),
1360 BPF_ALU64_REG(BPF_ADD, R9, R8),
1361 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1362 BPF_ALU64_REG(BPF_MOV, R0, R9),
1363 BPF_EXIT_INSN(),
1364 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001365 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001366 { },
1367 { { 0, 2957380 } }
1368 },
1369 {
1370 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001371 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001372 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1373 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1374 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1375 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1376 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1377 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1378 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1379 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1380 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1381 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1382 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1383 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1384 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1385 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1386 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1387 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1388 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1389 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1390 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1391 BPF_ALU32_REG(BPF_ADD, R0, R1),
1392 BPF_ALU32_REG(BPF_ADD, R0, R2),
1393 BPF_ALU32_REG(BPF_ADD, R0, R3),
1394 BPF_ALU32_REG(BPF_ADD, R0, R4),
1395 BPF_ALU32_REG(BPF_ADD, R0, R5),
1396 BPF_ALU32_REG(BPF_ADD, R0, R6),
1397 BPF_ALU32_REG(BPF_ADD, R0, R7),
1398 BPF_ALU32_REG(BPF_ADD, R0, R8),
1399 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1400 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1401 BPF_EXIT_INSN(),
1402 BPF_ALU32_REG(BPF_ADD, R1, R0),
1403 BPF_ALU32_REG(BPF_ADD, R1, R1),
1404 BPF_ALU32_REG(BPF_ADD, R1, R2),
1405 BPF_ALU32_REG(BPF_ADD, R1, R3),
1406 BPF_ALU32_REG(BPF_ADD, R1, R4),
1407 BPF_ALU32_REG(BPF_ADD, R1, R5),
1408 BPF_ALU32_REG(BPF_ADD, R1, R6),
1409 BPF_ALU32_REG(BPF_ADD, R1, R7),
1410 BPF_ALU32_REG(BPF_ADD, R1, R8),
1411 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1412 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1413 BPF_EXIT_INSN(),
1414 BPF_ALU32_REG(BPF_ADD, R2, R0),
1415 BPF_ALU32_REG(BPF_ADD, R2, R1),
1416 BPF_ALU32_REG(BPF_ADD, R2, R2),
1417 BPF_ALU32_REG(BPF_ADD, R2, R3),
1418 BPF_ALU32_REG(BPF_ADD, R2, R4),
1419 BPF_ALU32_REG(BPF_ADD, R2, R5),
1420 BPF_ALU32_REG(BPF_ADD, R2, R6),
1421 BPF_ALU32_REG(BPF_ADD, R2, R7),
1422 BPF_ALU32_REG(BPF_ADD, R2, R8),
1423 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1424 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1425 BPF_EXIT_INSN(),
1426 BPF_ALU32_REG(BPF_ADD, R3, R0),
1427 BPF_ALU32_REG(BPF_ADD, R3, R1),
1428 BPF_ALU32_REG(BPF_ADD, R3, R2),
1429 BPF_ALU32_REG(BPF_ADD, R3, R3),
1430 BPF_ALU32_REG(BPF_ADD, R3, R4),
1431 BPF_ALU32_REG(BPF_ADD, R3, R5),
1432 BPF_ALU32_REG(BPF_ADD, R3, R6),
1433 BPF_ALU32_REG(BPF_ADD, R3, R7),
1434 BPF_ALU32_REG(BPF_ADD, R3, R8),
1435 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1436 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1437 BPF_EXIT_INSN(),
1438 BPF_ALU32_REG(BPF_ADD, R4, R0),
1439 BPF_ALU32_REG(BPF_ADD, R4, R1),
1440 BPF_ALU32_REG(BPF_ADD, R4, R2),
1441 BPF_ALU32_REG(BPF_ADD, R4, R3),
1442 BPF_ALU32_REG(BPF_ADD, R4, R4),
1443 BPF_ALU32_REG(BPF_ADD, R4, R5),
1444 BPF_ALU32_REG(BPF_ADD, R4, R6),
1445 BPF_ALU32_REG(BPF_ADD, R4, R7),
1446 BPF_ALU32_REG(BPF_ADD, R4, R8),
1447 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1448 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1449 BPF_EXIT_INSN(),
1450 BPF_ALU32_REG(BPF_ADD, R5, R0),
1451 BPF_ALU32_REG(BPF_ADD, R5, R1),
1452 BPF_ALU32_REG(BPF_ADD, R5, R2),
1453 BPF_ALU32_REG(BPF_ADD, R5, R3),
1454 BPF_ALU32_REG(BPF_ADD, R5, R4),
1455 BPF_ALU32_REG(BPF_ADD, R5, R5),
1456 BPF_ALU32_REG(BPF_ADD, R5, R6),
1457 BPF_ALU32_REG(BPF_ADD, R5, R7),
1458 BPF_ALU32_REG(BPF_ADD, R5, R8),
1459 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1460 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1461 BPF_EXIT_INSN(),
1462 BPF_ALU32_REG(BPF_ADD, R6, R0),
1463 BPF_ALU32_REG(BPF_ADD, R6, R1),
1464 BPF_ALU32_REG(BPF_ADD, R6, R2),
1465 BPF_ALU32_REG(BPF_ADD, R6, R3),
1466 BPF_ALU32_REG(BPF_ADD, R6, R4),
1467 BPF_ALU32_REG(BPF_ADD, R6, R5),
1468 BPF_ALU32_REG(BPF_ADD, R6, R6),
1469 BPF_ALU32_REG(BPF_ADD, R6, R7),
1470 BPF_ALU32_REG(BPF_ADD, R6, R8),
1471 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1472 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1473 BPF_EXIT_INSN(),
1474 BPF_ALU32_REG(BPF_ADD, R7, R0),
1475 BPF_ALU32_REG(BPF_ADD, R7, R1),
1476 BPF_ALU32_REG(BPF_ADD, R7, R2),
1477 BPF_ALU32_REG(BPF_ADD, R7, R3),
1478 BPF_ALU32_REG(BPF_ADD, R7, R4),
1479 BPF_ALU32_REG(BPF_ADD, R7, R5),
1480 BPF_ALU32_REG(BPF_ADD, R7, R6),
1481 BPF_ALU32_REG(BPF_ADD, R7, R7),
1482 BPF_ALU32_REG(BPF_ADD, R7, R8),
1483 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1484 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1485 BPF_EXIT_INSN(),
1486 BPF_ALU32_REG(BPF_ADD, R8, R0),
1487 BPF_ALU32_REG(BPF_ADD, R8, R1),
1488 BPF_ALU32_REG(BPF_ADD, R8, R2),
1489 BPF_ALU32_REG(BPF_ADD, R8, R3),
1490 BPF_ALU32_REG(BPF_ADD, R8, R4),
1491 BPF_ALU32_REG(BPF_ADD, R8, R5),
1492 BPF_ALU32_REG(BPF_ADD, R8, R6),
1493 BPF_ALU32_REG(BPF_ADD, R8, R7),
1494 BPF_ALU32_REG(BPF_ADD, R8, R8),
1495 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1496 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1497 BPF_EXIT_INSN(),
1498 BPF_ALU32_REG(BPF_ADD, R9, R0),
1499 BPF_ALU32_REG(BPF_ADD, R9, R1),
1500 BPF_ALU32_REG(BPF_ADD, R9, R2),
1501 BPF_ALU32_REG(BPF_ADD, R9, R3),
1502 BPF_ALU32_REG(BPF_ADD, R9, R4),
1503 BPF_ALU32_REG(BPF_ADD, R9, R5),
1504 BPF_ALU32_REG(BPF_ADD, R9, R6),
1505 BPF_ALU32_REG(BPF_ADD, R9, R7),
1506 BPF_ALU32_REG(BPF_ADD, R9, R8),
1507 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1508 BPF_ALU32_REG(BPF_MOV, R0, R9),
1509 BPF_EXIT_INSN(),
1510 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001511 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001512 { },
1513 { { 0, 2957380 } }
1514 },
1515 { /* Mainly checking JIT here. */
1516 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001517 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001518 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1519 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1520 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1521 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1522 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1523 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1524 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1525 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1526 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1527 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1528 BPF_ALU64_REG(BPF_SUB, R0, R0),
1529 BPF_ALU64_REG(BPF_SUB, R0, R1),
1530 BPF_ALU64_REG(BPF_SUB, R0, R2),
1531 BPF_ALU64_REG(BPF_SUB, R0, R3),
1532 BPF_ALU64_REG(BPF_SUB, R0, R4),
1533 BPF_ALU64_REG(BPF_SUB, R0, R5),
1534 BPF_ALU64_REG(BPF_SUB, R0, R6),
1535 BPF_ALU64_REG(BPF_SUB, R0, R7),
1536 BPF_ALU64_REG(BPF_SUB, R0, R8),
1537 BPF_ALU64_REG(BPF_SUB, R0, R9),
1538 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1539 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1540 BPF_EXIT_INSN(),
1541 BPF_ALU64_REG(BPF_SUB, R1, R0),
1542 BPF_ALU64_REG(BPF_SUB, R1, R2),
1543 BPF_ALU64_REG(BPF_SUB, R1, R3),
1544 BPF_ALU64_REG(BPF_SUB, R1, R4),
1545 BPF_ALU64_REG(BPF_SUB, R1, R5),
1546 BPF_ALU64_REG(BPF_SUB, R1, R6),
1547 BPF_ALU64_REG(BPF_SUB, R1, R7),
1548 BPF_ALU64_REG(BPF_SUB, R1, R8),
1549 BPF_ALU64_REG(BPF_SUB, R1, R9),
1550 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1551 BPF_ALU64_REG(BPF_SUB, R2, R0),
1552 BPF_ALU64_REG(BPF_SUB, R2, R1),
1553 BPF_ALU64_REG(BPF_SUB, R2, R3),
1554 BPF_ALU64_REG(BPF_SUB, R2, R4),
1555 BPF_ALU64_REG(BPF_SUB, R2, R5),
1556 BPF_ALU64_REG(BPF_SUB, R2, R6),
1557 BPF_ALU64_REG(BPF_SUB, R2, R7),
1558 BPF_ALU64_REG(BPF_SUB, R2, R8),
1559 BPF_ALU64_REG(BPF_SUB, R2, R9),
1560 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1561 BPF_ALU64_REG(BPF_SUB, R3, R0),
1562 BPF_ALU64_REG(BPF_SUB, R3, R1),
1563 BPF_ALU64_REG(BPF_SUB, R3, R2),
1564 BPF_ALU64_REG(BPF_SUB, R3, R4),
1565 BPF_ALU64_REG(BPF_SUB, R3, R5),
1566 BPF_ALU64_REG(BPF_SUB, R3, R6),
1567 BPF_ALU64_REG(BPF_SUB, R3, R7),
1568 BPF_ALU64_REG(BPF_SUB, R3, R8),
1569 BPF_ALU64_REG(BPF_SUB, R3, R9),
1570 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1571 BPF_ALU64_REG(BPF_SUB, R4, R0),
1572 BPF_ALU64_REG(BPF_SUB, R4, R1),
1573 BPF_ALU64_REG(BPF_SUB, R4, R2),
1574 BPF_ALU64_REG(BPF_SUB, R4, R3),
1575 BPF_ALU64_REG(BPF_SUB, R4, R5),
1576 BPF_ALU64_REG(BPF_SUB, R4, R6),
1577 BPF_ALU64_REG(BPF_SUB, R4, R7),
1578 BPF_ALU64_REG(BPF_SUB, R4, R8),
1579 BPF_ALU64_REG(BPF_SUB, R4, R9),
1580 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1581 BPF_ALU64_REG(BPF_SUB, R5, R0),
1582 BPF_ALU64_REG(BPF_SUB, R5, R1),
1583 BPF_ALU64_REG(BPF_SUB, R5, R2),
1584 BPF_ALU64_REG(BPF_SUB, R5, R3),
1585 BPF_ALU64_REG(BPF_SUB, R5, R4),
1586 BPF_ALU64_REG(BPF_SUB, R5, R6),
1587 BPF_ALU64_REG(BPF_SUB, R5, R7),
1588 BPF_ALU64_REG(BPF_SUB, R5, R8),
1589 BPF_ALU64_REG(BPF_SUB, R5, R9),
1590 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1591 BPF_ALU64_REG(BPF_SUB, R6, R0),
1592 BPF_ALU64_REG(BPF_SUB, R6, R1),
1593 BPF_ALU64_REG(BPF_SUB, R6, R2),
1594 BPF_ALU64_REG(BPF_SUB, R6, R3),
1595 BPF_ALU64_REG(BPF_SUB, R6, R4),
1596 BPF_ALU64_REG(BPF_SUB, R6, R5),
1597 BPF_ALU64_REG(BPF_SUB, R6, R7),
1598 BPF_ALU64_REG(BPF_SUB, R6, R8),
1599 BPF_ALU64_REG(BPF_SUB, R6, R9),
1600 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1601 BPF_ALU64_REG(BPF_SUB, R7, R0),
1602 BPF_ALU64_REG(BPF_SUB, R7, R1),
1603 BPF_ALU64_REG(BPF_SUB, R7, R2),
1604 BPF_ALU64_REG(BPF_SUB, R7, R3),
1605 BPF_ALU64_REG(BPF_SUB, R7, R4),
1606 BPF_ALU64_REG(BPF_SUB, R7, R5),
1607 BPF_ALU64_REG(BPF_SUB, R7, R6),
1608 BPF_ALU64_REG(BPF_SUB, R7, R8),
1609 BPF_ALU64_REG(BPF_SUB, R7, R9),
1610 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1611 BPF_ALU64_REG(BPF_SUB, R8, R0),
1612 BPF_ALU64_REG(BPF_SUB, R8, R1),
1613 BPF_ALU64_REG(BPF_SUB, R8, R2),
1614 BPF_ALU64_REG(BPF_SUB, R8, R3),
1615 BPF_ALU64_REG(BPF_SUB, R8, R4),
1616 BPF_ALU64_REG(BPF_SUB, R8, R5),
1617 BPF_ALU64_REG(BPF_SUB, R8, R6),
1618 BPF_ALU64_REG(BPF_SUB, R8, R7),
1619 BPF_ALU64_REG(BPF_SUB, R8, R9),
1620 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1621 BPF_ALU64_REG(BPF_SUB, R9, R0),
1622 BPF_ALU64_REG(BPF_SUB, R9, R1),
1623 BPF_ALU64_REG(BPF_SUB, R9, R2),
1624 BPF_ALU64_REG(BPF_SUB, R9, R3),
1625 BPF_ALU64_REG(BPF_SUB, R9, R4),
1626 BPF_ALU64_REG(BPF_SUB, R9, R5),
1627 BPF_ALU64_REG(BPF_SUB, R9, R6),
1628 BPF_ALU64_REG(BPF_SUB, R9, R7),
1629 BPF_ALU64_REG(BPF_SUB, R9, R8),
1630 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1631 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1632 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1633 BPF_ALU64_REG(BPF_SUB, R0, R1),
1634 BPF_ALU64_REG(BPF_SUB, R0, R2),
1635 BPF_ALU64_REG(BPF_SUB, R0, R3),
1636 BPF_ALU64_REG(BPF_SUB, R0, R4),
1637 BPF_ALU64_REG(BPF_SUB, R0, R5),
1638 BPF_ALU64_REG(BPF_SUB, R0, R6),
1639 BPF_ALU64_REG(BPF_SUB, R0, R7),
1640 BPF_ALU64_REG(BPF_SUB, R0, R8),
1641 BPF_ALU64_REG(BPF_SUB, R0, R9),
1642 BPF_EXIT_INSN(),
1643 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001644 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001645 { },
1646 { { 0, 11 } }
1647 },
1648 { /* Mainly checking JIT here. */
1649 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001650 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001651 BPF_ALU64_REG(BPF_SUB, R0, R0),
1652 BPF_ALU64_REG(BPF_XOR, R1, R1),
1653 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1654 BPF_EXIT_INSN(),
1655 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1656 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1657 BPF_ALU64_REG(BPF_SUB, R1, R1),
1658 BPF_ALU64_REG(BPF_XOR, R2, R2),
1659 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1660 BPF_EXIT_INSN(),
1661 BPF_ALU64_REG(BPF_SUB, R2, R2),
1662 BPF_ALU64_REG(BPF_XOR, R3, R3),
1663 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1664 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1665 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_REG(BPF_SUB, R3, R3),
1668 BPF_ALU64_REG(BPF_XOR, R4, R4),
1669 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1670 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1671 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1672 BPF_EXIT_INSN(),
1673 BPF_ALU64_REG(BPF_SUB, R4, R4),
1674 BPF_ALU64_REG(BPF_XOR, R5, R5),
1675 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1676 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1677 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1678 BPF_EXIT_INSN(),
1679 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1680 BPF_ALU64_REG(BPF_SUB, R5, R5),
1681 BPF_ALU64_REG(BPF_XOR, R6, R6),
1682 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1683 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1684 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1685 BPF_EXIT_INSN(),
1686 BPF_ALU64_REG(BPF_SUB, R6, R6),
1687 BPF_ALU64_REG(BPF_XOR, R7, R7),
1688 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1689 BPF_EXIT_INSN(),
1690 BPF_ALU64_REG(BPF_SUB, R7, R7),
1691 BPF_ALU64_REG(BPF_XOR, R8, R8),
1692 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1693 BPF_EXIT_INSN(),
1694 BPF_ALU64_REG(BPF_SUB, R8, R8),
1695 BPF_ALU64_REG(BPF_XOR, R9, R9),
1696 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1697 BPF_EXIT_INSN(),
1698 BPF_ALU64_REG(BPF_SUB, R9, R9),
1699 BPF_ALU64_REG(BPF_XOR, R0, R0),
1700 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1701 BPF_EXIT_INSN(),
1702 BPF_ALU64_REG(BPF_SUB, R1, R1),
1703 BPF_ALU64_REG(BPF_XOR, R0, R0),
1704 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1705 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1706 BPF_EXIT_INSN(),
1707 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1708 BPF_EXIT_INSN(),
1709 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001710 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001711 { },
1712 { { 0, 1 } }
1713 },
1714 { /* Mainly checking JIT here. */
1715 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001716 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001717 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1718 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1719 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1720 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1721 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1722 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1723 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1724 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1725 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1726 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1727 BPF_ALU64_REG(BPF_MUL, R0, R0),
1728 BPF_ALU64_REG(BPF_MUL, R0, R1),
1729 BPF_ALU64_REG(BPF_MUL, R0, R2),
1730 BPF_ALU64_REG(BPF_MUL, R0, R3),
1731 BPF_ALU64_REG(BPF_MUL, R0, R4),
1732 BPF_ALU64_REG(BPF_MUL, R0, R5),
1733 BPF_ALU64_REG(BPF_MUL, R0, R6),
1734 BPF_ALU64_REG(BPF_MUL, R0, R7),
1735 BPF_ALU64_REG(BPF_MUL, R0, R8),
1736 BPF_ALU64_REG(BPF_MUL, R0, R9),
1737 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1738 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1739 BPF_EXIT_INSN(),
1740 BPF_ALU64_REG(BPF_MUL, R1, R0),
1741 BPF_ALU64_REG(BPF_MUL, R1, R2),
1742 BPF_ALU64_REG(BPF_MUL, R1, R3),
1743 BPF_ALU64_REG(BPF_MUL, R1, R4),
1744 BPF_ALU64_REG(BPF_MUL, R1, R5),
1745 BPF_ALU64_REG(BPF_MUL, R1, R6),
1746 BPF_ALU64_REG(BPF_MUL, R1, R7),
1747 BPF_ALU64_REG(BPF_MUL, R1, R8),
1748 BPF_ALU64_REG(BPF_MUL, R1, R9),
1749 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1750 BPF_ALU64_REG(BPF_MOV, R2, R1),
1751 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1752 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1753 BPF_EXIT_INSN(),
1754 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1755 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1756 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1757 BPF_EXIT_INSN(),
1758 BPF_ALU64_REG(BPF_MUL, R2, R0),
1759 BPF_ALU64_REG(BPF_MUL, R2, R1),
1760 BPF_ALU64_REG(BPF_MUL, R2, R3),
1761 BPF_ALU64_REG(BPF_MUL, R2, R4),
1762 BPF_ALU64_REG(BPF_MUL, R2, R5),
1763 BPF_ALU64_REG(BPF_MUL, R2, R6),
1764 BPF_ALU64_REG(BPF_MUL, R2, R7),
1765 BPF_ALU64_REG(BPF_MUL, R2, R8),
1766 BPF_ALU64_REG(BPF_MUL, R2, R9),
1767 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1768 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1769 BPF_ALU64_REG(BPF_MOV, R0, R2),
1770 BPF_EXIT_INSN(),
1771 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001772 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001773 { },
1774 { { 0, 0x35d97ef2 } }
1775 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001776 { /* Mainly checking JIT here. */
1777 "MOV REG64",
1778 .u.insns_int = {
1779 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1780 BPF_MOV64_REG(R1, R0),
1781 BPF_MOV64_REG(R2, R1),
1782 BPF_MOV64_REG(R3, R2),
1783 BPF_MOV64_REG(R4, R3),
1784 BPF_MOV64_REG(R5, R4),
1785 BPF_MOV64_REG(R6, R5),
1786 BPF_MOV64_REG(R7, R6),
1787 BPF_MOV64_REG(R8, R7),
1788 BPF_MOV64_REG(R9, R8),
1789 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1790 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1791 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1792 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1793 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1794 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1795 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1796 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1797 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1798 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1799 BPF_ALU64_REG(BPF_ADD, R0, R0),
1800 BPF_ALU64_REG(BPF_ADD, R0, R1),
1801 BPF_ALU64_REG(BPF_ADD, R0, R2),
1802 BPF_ALU64_REG(BPF_ADD, R0, R3),
1803 BPF_ALU64_REG(BPF_ADD, R0, R4),
1804 BPF_ALU64_REG(BPF_ADD, R0, R5),
1805 BPF_ALU64_REG(BPF_ADD, R0, R6),
1806 BPF_ALU64_REG(BPF_ADD, R0, R7),
1807 BPF_ALU64_REG(BPF_ADD, R0, R8),
1808 BPF_ALU64_REG(BPF_ADD, R0, R9),
1809 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1810 BPF_EXIT_INSN(),
1811 },
1812 INTERNAL,
1813 { },
1814 { { 0, 0xfefe } }
1815 },
1816 { /* Mainly checking JIT here. */
1817 "MOV REG32",
1818 .u.insns_int = {
1819 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1820 BPF_MOV64_REG(R1, R0),
1821 BPF_MOV64_REG(R2, R1),
1822 BPF_MOV64_REG(R3, R2),
1823 BPF_MOV64_REG(R4, R3),
1824 BPF_MOV64_REG(R5, R4),
1825 BPF_MOV64_REG(R6, R5),
1826 BPF_MOV64_REG(R7, R6),
1827 BPF_MOV64_REG(R8, R7),
1828 BPF_MOV64_REG(R9, R8),
1829 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1830 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1831 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1832 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1833 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1834 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1835 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1836 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1837 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1838 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1839 BPF_ALU64_REG(BPF_ADD, R0, R0),
1840 BPF_ALU64_REG(BPF_ADD, R0, R1),
1841 BPF_ALU64_REG(BPF_ADD, R0, R2),
1842 BPF_ALU64_REG(BPF_ADD, R0, R3),
1843 BPF_ALU64_REG(BPF_ADD, R0, R4),
1844 BPF_ALU64_REG(BPF_ADD, R0, R5),
1845 BPF_ALU64_REG(BPF_ADD, R0, R6),
1846 BPF_ALU64_REG(BPF_ADD, R0, R7),
1847 BPF_ALU64_REG(BPF_ADD, R0, R8),
1848 BPF_ALU64_REG(BPF_ADD, R0, R9),
1849 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1850 BPF_EXIT_INSN(),
1851 },
1852 INTERNAL,
1853 { },
1854 { { 0, 0xfefe } }
1855 },
1856 { /* Mainly checking JIT here. */
1857 "LD IMM64",
1858 .u.insns_int = {
1859 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1860 BPF_MOV64_REG(R1, R0),
1861 BPF_MOV64_REG(R2, R1),
1862 BPF_MOV64_REG(R3, R2),
1863 BPF_MOV64_REG(R4, R3),
1864 BPF_MOV64_REG(R5, R4),
1865 BPF_MOV64_REG(R6, R5),
1866 BPF_MOV64_REG(R7, R6),
1867 BPF_MOV64_REG(R8, R7),
1868 BPF_MOV64_REG(R9, R8),
1869 BPF_LD_IMM64(R0, 0x0LL),
1870 BPF_LD_IMM64(R1, 0x0LL),
1871 BPF_LD_IMM64(R2, 0x0LL),
1872 BPF_LD_IMM64(R3, 0x0LL),
1873 BPF_LD_IMM64(R4, 0x0LL),
1874 BPF_LD_IMM64(R5, 0x0LL),
1875 BPF_LD_IMM64(R6, 0x0LL),
1876 BPF_LD_IMM64(R7, 0x0LL),
1877 BPF_LD_IMM64(R8, 0x0LL),
1878 BPF_LD_IMM64(R9, 0x0LL),
1879 BPF_ALU64_REG(BPF_ADD, R0, R0),
1880 BPF_ALU64_REG(BPF_ADD, R0, R1),
1881 BPF_ALU64_REG(BPF_ADD, R0, R2),
1882 BPF_ALU64_REG(BPF_ADD, R0, R3),
1883 BPF_ALU64_REG(BPF_ADD, R0, R4),
1884 BPF_ALU64_REG(BPF_ADD, R0, R5),
1885 BPF_ALU64_REG(BPF_ADD, R0, R6),
1886 BPF_ALU64_REG(BPF_ADD, R0, R7),
1887 BPF_ALU64_REG(BPF_ADD, R0, R8),
1888 BPF_ALU64_REG(BPF_ADD, R0, R9),
1889 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1890 BPF_EXIT_INSN(),
1891 },
1892 INTERNAL,
1893 { },
1894 { { 0, 0xfefe } }
1895 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001896 {
1897 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001898 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001899 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1900 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1901 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1902 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1903 BPF_ALU64_REG(BPF_DIV, R0, R2),
1904 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1905 BPF_EXIT_INSN(),
1906 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1907 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1908 BPF_EXIT_INSN(),
1909 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1910 BPF_EXIT_INSN(),
1911 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001912 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001913 { },
1914 { { 0, -1 } }
1915 },
1916 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001917 "INT: shifts by register",
1918 .u.insns_int = {
1919 BPF_MOV64_IMM(R0, -1234),
1920 BPF_MOV64_IMM(R1, 1),
1921 BPF_ALU32_REG(BPF_RSH, R0, R1),
1922 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1923 BPF_EXIT_INSN(),
1924 BPF_MOV64_IMM(R2, 1),
1925 BPF_ALU64_REG(BPF_LSH, R0, R2),
1926 BPF_MOV32_IMM(R4, -1234),
1927 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1928 BPF_EXIT_INSN(),
1929 BPF_ALU64_IMM(BPF_AND, R4, 63),
1930 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1931 BPF_MOV64_IMM(R3, 47),
1932 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1933 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1934 BPF_EXIT_INSN(),
1935 BPF_MOV64_IMM(R2, 1),
1936 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1937 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1938 BPF_EXIT_INSN(),
1939 BPF_MOV64_IMM(R4, 4),
1940 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1941 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1942 BPF_EXIT_INSN(),
1943 BPF_MOV64_IMM(R4, 5),
1944 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1945 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1946 BPF_EXIT_INSN(),
1947 BPF_MOV64_IMM(R0, -1),
1948 BPF_EXIT_INSN(),
1949 },
1950 INTERNAL,
1951 { },
1952 { { 0, -1 } }
1953 },
1954 {
Johan Almbladh84024a42021-08-09 11:18:23 +02001955 /*
1956 * Register (non-)clobbering test, in the case where a 32-bit
1957 * JIT implements complex ALU64 operations via function calls.
1958 * If so, the function call must be invisible in the eBPF
1959 * registers. The JIT must then save and restore relevant
1960 * registers during the call. The following tests check that
1961 * the eBPF registers retain their values after such a call.
1962 */
1963 "INT: Register clobbering, R1 updated",
1964 .u.insns_int = {
1965 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1966 BPF_ALU32_IMM(BPF_MOV, R1, 123456789),
1967 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1968 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1969 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1970 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1971 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1972 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1973 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1974 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1975 BPF_ALU64_IMM(BPF_DIV, R1, 123456789),
1976 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
1977 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
1978 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
1979 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
1980 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
1981 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
1982 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
1983 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
1984 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
1985 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
1986 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1987 BPF_EXIT_INSN(),
1988 },
1989 INTERNAL,
1990 { },
1991 { { 0, 1 } }
1992 },
1993 {
1994 "INT: Register clobbering, R2 updated",
1995 .u.insns_int = {
1996 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1997 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1998 BPF_ALU32_IMM(BPF_MOV, R2, 2 * 123456789),
1999 BPF_ALU32_IMM(BPF_MOV, R3, 3),
2000 BPF_ALU32_IMM(BPF_MOV, R4, 4),
2001 BPF_ALU32_IMM(BPF_MOV, R5, 5),
2002 BPF_ALU32_IMM(BPF_MOV, R6, 6),
2003 BPF_ALU32_IMM(BPF_MOV, R7, 7),
2004 BPF_ALU32_IMM(BPF_MOV, R8, 8),
2005 BPF_ALU32_IMM(BPF_MOV, R9, 9),
2006 BPF_ALU64_IMM(BPF_DIV, R2, 123456789),
2007 BPF_JMP_IMM(BPF_JNE, R0, 0, 10),
2008 BPF_JMP_IMM(BPF_JNE, R1, 1, 9),
2009 BPF_JMP_IMM(BPF_JNE, R2, 2, 8),
2010 BPF_JMP_IMM(BPF_JNE, R3, 3, 7),
2011 BPF_JMP_IMM(BPF_JNE, R4, 4, 6),
2012 BPF_JMP_IMM(BPF_JNE, R5, 5, 5),
2013 BPF_JMP_IMM(BPF_JNE, R6, 6, 4),
2014 BPF_JMP_IMM(BPF_JNE, R7, 7, 3),
2015 BPF_JMP_IMM(BPF_JNE, R8, 8, 2),
2016 BPF_JMP_IMM(BPF_JNE, R9, 9, 1),
2017 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2018 BPF_EXIT_INSN(),
2019 },
2020 INTERNAL,
2021 { },
2022 { { 0, 1 } }
2023 },
2024 {
2025 /*
2026 * Test 32-bit JITs that implement complex ALU64 operations as
2027 * function calls R0 = f(R1, R2), and must re-arrange operands.
2028 */
2029#define NUMER 0xfedcba9876543210ULL
2030#define DENOM 0x0123456789abcdefULL
2031 "ALU64_DIV X: Operand register permutations",
2032 .u.insns_int = {
2033 /* R0 / R2 */
2034 BPF_LD_IMM64(R0, NUMER),
2035 BPF_LD_IMM64(R2, DENOM),
2036 BPF_ALU64_REG(BPF_DIV, R0, R2),
2037 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2038 BPF_EXIT_INSN(),
2039 /* R1 / R0 */
2040 BPF_LD_IMM64(R1, NUMER),
2041 BPF_LD_IMM64(R0, DENOM),
2042 BPF_ALU64_REG(BPF_DIV, R1, R0),
2043 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2044 BPF_EXIT_INSN(),
2045 /* R0 / R1 */
2046 BPF_LD_IMM64(R0, NUMER),
2047 BPF_LD_IMM64(R1, DENOM),
2048 BPF_ALU64_REG(BPF_DIV, R0, R1),
2049 BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1),
2050 BPF_EXIT_INSN(),
2051 /* R2 / R0 */
2052 BPF_LD_IMM64(R2, NUMER),
2053 BPF_LD_IMM64(R0, DENOM),
2054 BPF_ALU64_REG(BPF_DIV, R2, R0),
2055 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2056 BPF_EXIT_INSN(),
2057 /* R2 / R1 */
2058 BPF_LD_IMM64(R2, NUMER),
2059 BPF_LD_IMM64(R1, DENOM),
2060 BPF_ALU64_REG(BPF_DIV, R2, R1),
2061 BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1),
2062 BPF_EXIT_INSN(),
2063 /* R1 / R2 */
2064 BPF_LD_IMM64(R1, NUMER),
2065 BPF_LD_IMM64(R2, DENOM),
2066 BPF_ALU64_REG(BPF_DIV, R1, R2),
2067 BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1),
2068 BPF_EXIT_INSN(),
2069 /* R1 / R1 */
2070 BPF_LD_IMM64(R1, NUMER),
2071 BPF_ALU64_REG(BPF_DIV, R1, R1),
2072 BPF_JMP_IMM(BPF_JEQ, R1, 1, 1),
2073 BPF_EXIT_INSN(),
2074 /* R2 / R2 */
2075 BPF_LD_IMM64(R2, DENOM),
2076 BPF_ALU64_REG(BPF_DIV, R2, R2),
2077 BPF_JMP_IMM(BPF_JEQ, R2, 1, 1),
2078 BPF_EXIT_INSN(),
2079 /* R3 / R4 */
2080 BPF_LD_IMM64(R3, NUMER),
2081 BPF_LD_IMM64(R4, DENOM),
2082 BPF_ALU64_REG(BPF_DIV, R3, R4),
2083 BPF_JMP_IMM(BPF_JEQ, R3, NUMER / DENOM, 1),
2084 BPF_EXIT_INSN(),
2085 /* Successful return */
2086 BPF_LD_IMM64(R0, 1),
2087 BPF_EXIT_INSN(),
2088 },
2089 INTERNAL,
2090 { },
2091 { { 0, 1 } },
2092#undef NUMER
2093#undef DENOM
2094 },
Johan Almbladh53e33f92021-08-09 11:18:26 +02002095#ifdef CONFIG_32BIT
2096 {
2097 "INT: 32-bit context pointer word order and zero-extension",
2098 .u.insns_int = {
2099 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2100 BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3),
2101 BPF_ALU64_IMM(BPF_RSH, R1, 32),
2102 BPF_JMP32_IMM(BPF_JNE, R1, 0, 1),
2103 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2104 BPF_EXIT_INSN(),
2105 },
2106 INTERNAL,
2107 { },
2108 { { 0, 1 } }
2109 },
2110#endif
Johan Almbladh84024a42021-08-09 11:18:23 +02002111 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002112 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07002113 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002114 BPF_STMT(BPF_LD | BPF_IMM, 1),
2115 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002116 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002117 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002118 { },
2119 .fill_helper = NULL,
2120 .expected_errcode = -EINVAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002121 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002122 {
2123 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07002124 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002125 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
2126 BPF_STMT(BPF_RET | BPF_K, 0)
2127 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002128 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002129 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002130 { },
2131 .fill_helper = NULL,
2132 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002133 },
2134 {
2135 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07002136 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002137 /* seccomp insn, rejected in socket filter */
2138 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
2139 BPF_STMT(BPF_RET | BPF_K, 0)
2140 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002141 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002142 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002143 { },
2144 .fill_helper = NULL,
2145 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002146 },
2147 {
2148 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07002149 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002150 BPF_STMT(BPF_STX, 16),
2151 BPF_STMT(BPF_RET | BPF_K, 0)
2152 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002153 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002154 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002155 { },
2156 .fill_helper = NULL,
2157 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002158 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002159 {
2160 "JUMPS + HOLES",
2161 .u.insns = {
2162 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2163 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
2164 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2165 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2166 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2167 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2168 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2169 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2170 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2171 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2172 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2173 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2174 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2175 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2176 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2177 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
2178 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2179 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
2180 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2181 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2182 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2183 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2184 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2185 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2186 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2187 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2188 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2189 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2190 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2191 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2192 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2193 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2194 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2195 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2196 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2197 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2198 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2199 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2200 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2201 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2202 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2203 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2204 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2205 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2206 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2207 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2208 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2209 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2210 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2211 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2212 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2213 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2214 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2215 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2216 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2217 BPF_STMT(BPF_RET | BPF_A, 0),
2218 BPF_STMT(BPF_RET | BPF_A, 0),
2219 },
2220 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002221 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2222 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2223 0x08, 0x00,
2224 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2225 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2226 0xc0, 0xa8, 0x33, 0x01,
2227 0xc0, 0xa8, 0x33, 0x02,
2228 0xbb, 0xb6,
2229 0xa9, 0xfa,
2230 0x00, 0x14, 0x00, 0x00,
2231 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2232 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2233 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2234 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2235 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2236 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2237 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2238 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002239 { { 88, 0x001b } }
2240 },
2241 {
2242 "check: RET X",
2243 .u.insns = {
2244 BPF_STMT(BPF_RET | BPF_X, 0),
2245 },
2246 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2247 { },
2248 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002249 .fill_helper = NULL,
2250 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002251 },
2252 {
2253 "check: LDX + RET X",
2254 .u.insns = {
2255 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2256 BPF_STMT(BPF_RET | BPF_X, 0),
2257 },
2258 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2259 { },
2260 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002261 .fill_helper = NULL,
2262 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002263 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002264 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002265 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002266 .u.insns = {
2267 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2268 BPF_STMT(BPF_STX, 0),
2269 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2270 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2271 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2272 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2273 BPF_STMT(BPF_STX, 1),
2274 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2275 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2276 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2277 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2278 BPF_STMT(BPF_STX, 2),
2279 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2280 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2281 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2282 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2283 BPF_STMT(BPF_STX, 3),
2284 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2285 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2286 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2287 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2288 BPF_STMT(BPF_STX, 4),
2289 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2290 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2291 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2292 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2293 BPF_STMT(BPF_STX, 5),
2294 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2295 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2296 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2297 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2298 BPF_STMT(BPF_STX, 6),
2299 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2300 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2301 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2302 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2303 BPF_STMT(BPF_STX, 7),
2304 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2305 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2306 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2307 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2308 BPF_STMT(BPF_STX, 8),
2309 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2310 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2311 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2312 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2313 BPF_STMT(BPF_STX, 9),
2314 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2315 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2316 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2317 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2318 BPF_STMT(BPF_STX, 10),
2319 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2320 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2321 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2322 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2323 BPF_STMT(BPF_STX, 11),
2324 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2325 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2326 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2327 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2328 BPF_STMT(BPF_STX, 12),
2329 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2330 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2331 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2332 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2333 BPF_STMT(BPF_STX, 13),
2334 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2335 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2336 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2337 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2338 BPF_STMT(BPF_STX, 14),
2339 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2340 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2341 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2342 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2343 BPF_STMT(BPF_STX, 15),
2344 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2345 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2346 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2347 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2348 BPF_STMT(BPF_RET | BPF_A, 0),
2349 },
2350 CLASSIC | FLAG_NO_DATA,
2351 { },
2352 { { 0, 116 } },
2353 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002354 { /* Mainly checking JIT here. */
2355 "M[]: full STX + full LDX",
2356 .u.insns = {
2357 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2358 BPF_STMT(BPF_STX, 0),
2359 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2360 BPF_STMT(BPF_STX, 1),
2361 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2362 BPF_STMT(BPF_STX, 2),
2363 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2364 BPF_STMT(BPF_STX, 3),
2365 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2366 BPF_STMT(BPF_STX, 4),
2367 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2368 BPF_STMT(BPF_STX, 5),
2369 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2370 BPF_STMT(BPF_STX, 6),
2371 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2372 BPF_STMT(BPF_STX, 7),
2373 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2374 BPF_STMT(BPF_STX, 8),
2375 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2376 BPF_STMT(BPF_STX, 9),
2377 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2378 BPF_STMT(BPF_STX, 10),
2379 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2380 BPF_STMT(BPF_STX, 11),
2381 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2382 BPF_STMT(BPF_STX, 12),
2383 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2384 BPF_STMT(BPF_STX, 13),
2385 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2386 BPF_STMT(BPF_STX, 14),
2387 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2388 BPF_STMT(BPF_STX, 15),
2389 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2390 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2391 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2392 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2393 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2394 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2395 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2396 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2397 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2398 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2399 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2400 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2401 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2402 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2403 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2404 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2405 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2406 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2407 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2408 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2409 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2410 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2411 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2412 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2413 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2414 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2415 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2416 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2417 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2418 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2419 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2420 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2421 BPF_STMT(BPF_RET | BPF_A, 0),
2422 },
2423 CLASSIC | FLAG_NO_DATA,
2424 { },
2425 { { 0, 0x2a5a5e5 } },
2426 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002427 {
2428 "check: SKF_AD_MAX",
2429 .u.insns = {
2430 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2431 SKF_AD_OFF + SKF_AD_MAX),
2432 BPF_STMT(BPF_RET | BPF_A, 0),
2433 },
2434 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2435 { },
2436 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002437 .fill_helper = NULL,
2438 .expected_errcode = -EINVAL,
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002439 },
2440 { /* Passes checker but fails during runtime. */
2441 "LD [SKF_AD_OFF-1]",
2442 .u.insns = {
2443 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2444 SKF_AD_OFF - 1),
2445 BPF_STMT(BPF_RET | BPF_K, 1),
2446 },
2447 CLASSIC,
2448 { },
2449 { { 1, 0 } },
2450 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002451 {
2452 "load 64-bit immediate",
2453 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002454 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002455 BPF_MOV64_REG(R2, R1),
2456 BPF_MOV64_REG(R3, R2),
2457 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2458 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2459 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2460 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2461 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2462 BPF_EXIT_INSN(),
2463 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2464 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002465 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2466 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002467 BPF_EXIT_INSN(),
2468 },
2469 INTERNAL,
2470 { },
2471 { { 0, 1 } }
2472 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002473 /* BPF_ALU | BPF_MOV | BPF_X */
2474 {
2475 "ALU_MOV_X: dst = 2",
2476 .u.insns_int = {
2477 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2478 BPF_ALU32_REG(BPF_MOV, R0, R1),
2479 BPF_EXIT_INSN(),
2480 },
2481 INTERNAL,
2482 { },
2483 { { 0, 2 } },
2484 },
2485 {
2486 "ALU_MOV_X: dst = 4294967295",
2487 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002488 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002489 BPF_ALU32_REG(BPF_MOV, R0, R1),
2490 BPF_EXIT_INSN(),
2491 },
2492 INTERNAL,
2493 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002494 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002495 },
2496 {
2497 "ALU64_MOV_X: dst = 2",
2498 .u.insns_int = {
2499 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2500 BPF_ALU64_REG(BPF_MOV, R0, R1),
2501 BPF_EXIT_INSN(),
2502 },
2503 INTERNAL,
2504 { },
2505 { { 0, 2 } },
2506 },
2507 {
2508 "ALU64_MOV_X: dst = 4294967295",
2509 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002510 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002511 BPF_ALU64_REG(BPF_MOV, R0, R1),
2512 BPF_EXIT_INSN(),
2513 },
2514 INTERNAL,
2515 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002516 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002517 },
2518 /* BPF_ALU | BPF_MOV | BPF_K */
2519 {
2520 "ALU_MOV_K: dst = 2",
2521 .u.insns_int = {
2522 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2523 BPF_EXIT_INSN(),
2524 },
2525 INTERNAL,
2526 { },
2527 { { 0, 2 } },
2528 },
2529 {
2530 "ALU_MOV_K: dst = 4294967295",
2531 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002532 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002533 BPF_EXIT_INSN(),
2534 },
2535 INTERNAL,
2536 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002537 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002538 },
2539 {
2540 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2541 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002542 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2543 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002544 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2545 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2546 BPF_MOV32_IMM(R0, 2),
2547 BPF_EXIT_INSN(),
2548 BPF_MOV32_IMM(R0, 1),
2549 BPF_EXIT_INSN(),
2550 },
2551 INTERNAL,
2552 { },
2553 { { 0, 0x1 } },
2554 },
2555 {
Johan Almbladh565731a2021-08-09 11:18:17 +02002556 "ALU_MOV_K: small negative",
2557 .u.insns_int = {
2558 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2559 BPF_EXIT_INSN(),
2560 },
2561 INTERNAL,
2562 { },
2563 { { 0, -123 } }
2564 },
2565 {
2566 "ALU_MOV_K: small negative zero extension",
2567 .u.insns_int = {
2568 BPF_ALU32_IMM(BPF_MOV, R0, -123),
2569 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2570 BPF_EXIT_INSN(),
2571 },
2572 INTERNAL,
2573 { },
2574 { { 0, 0 } }
2575 },
2576 {
2577 "ALU_MOV_K: large negative",
2578 .u.insns_int = {
2579 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2580 BPF_EXIT_INSN(),
2581 },
2582 INTERNAL,
2583 { },
2584 { { 0, -123456789 } }
2585 },
2586 {
2587 "ALU_MOV_K: large negative zero extension",
2588 .u.insns_int = {
2589 BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
2590 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2591 BPF_EXIT_INSN(),
2592 },
2593 INTERNAL,
2594 { },
2595 { { 0, 0 } }
2596 },
2597 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002598 "ALU64_MOV_K: dst = 2",
2599 .u.insns_int = {
2600 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2601 BPF_EXIT_INSN(),
2602 },
2603 INTERNAL,
2604 { },
2605 { { 0, 2 } },
2606 },
2607 {
2608 "ALU64_MOV_K: dst = 2147483647",
2609 .u.insns_int = {
2610 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2611 BPF_EXIT_INSN(),
2612 },
2613 INTERNAL,
2614 { },
2615 { { 0, 2147483647 } },
2616 },
2617 {
2618 "ALU64_OR_K: dst = 0x0",
2619 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002620 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002621 BPF_LD_IMM64(R3, 0x0),
2622 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2623 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2624 BPF_MOV32_IMM(R0, 2),
2625 BPF_EXIT_INSN(),
2626 BPF_MOV32_IMM(R0, 1),
2627 BPF_EXIT_INSN(),
2628 },
2629 INTERNAL,
2630 { },
2631 { { 0, 0x1 } },
2632 },
2633 {
2634 "ALU64_MOV_K: dst = -1",
2635 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002636 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2637 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002638 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2639 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2640 BPF_MOV32_IMM(R0, 2),
2641 BPF_EXIT_INSN(),
2642 BPF_MOV32_IMM(R0, 1),
2643 BPF_EXIT_INSN(),
2644 },
2645 INTERNAL,
2646 { },
2647 { { 0, 0x1 } },
2648 },
Johan Almbladh565731a2021-08-09 11:18:17 +02002649 {
2650 "ALU64_MOV_K: small negative",
2651 .u.insns_int = {
2652 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2653 BPF_EXIT_INSN(),
2654 },
2655 INTERNAL,
2656 { },
2657 { { 0, -123 } }
2658 },
2659 {
2660 "ALU64_MOV_K: small negative sign extension",
2661 .u.insns_int = {
2662 BPF_ALU64_IMM(BPF_MOV, R0, -123),
2663 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2664 BPF_EXIT_INSN(),
2665 },
2666 INTERNAL,
2667 { },
2668 { { 0, 0xffffffff } }
2669 },
2670 {
2671 "ALU64_MOV_K: large negative",
2672 .u.insns_int = {
2673 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2674 BPF_EXIT_INSN(),
2675 },
2676 INTERNAL,
2677 { },
2678 { { 0, -123456789 } }
2679 },
2680 {
2681 "ALU64_MOV_K: large negative sign extension",
2682 .u.insns_int = {
2683 BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
2684 BPF_ALU64_IMM(BPF_RSH, R0, 32),
2685 BPF_EXIT_INSN(),
2686 },
2687 INTERNAL,
2688 { },
2689 { { 0, 0xffffffff } }
2690 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002691 /* BPF_ALU | BPF_ADD | BPF_X */
2692 {
2693 "ALU_ADD_X: 1 + 2 = 3",
2694 .u.insns_int = {
2695 BPF_LD_IMM64(R0, 1),
2696 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2697 BPF_ALU32_REG(BPF_ADD, R0, R1),
2698 BPF_EXIT_INSN(),
2699 },
2700 INTERNAL,
2701 { },
2702 { { 0, 3 } },
2703 },
2704 {
2705 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2706 .u.insns_int = {
2707 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002708 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002709 BPF_ALU32_REG(BPF_ADD, R0, R1),
2710 BPF_EXIT_INSN(),
2711 },
2712 INTERNAL,
2713 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002714 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002715 },
2716 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302717 "ALU_ADD_X: 2 + 4294967294 = 0",
2718 .u.insns_int = {
2719 BPF_LD_IMM64(R0, 2),
2720 BPF_LD_IMM64(R1, 4294967294U),
2721 BPF_ALU32_REG(BPF_ADD, R0, R1),
2722 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2723 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2724 BPF_EXIT_INSN(),
2725 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2726 BPF_EXIT_INSN(),
2727 },
2728 INTERNAL,
2729 { },
2730 { { 0, 1 } },
2731 },
2732 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002733 "ALU64_ADD_X: 1 + 2 = 3",
2734 .u.insns_int = {
2735 BPF_LD_IMM64(R0, 1),
2736 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2737 BPF_ALU64_REG(BPF_ADD, R0, R1),
2738 BPF_EXIT_INSN(),
2739 },
2740 INTERNAL,
2741 { },
2742 { { 0, 3 } },
2743 },
2744 {
2745 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2746 .u.insns_int = {
2747 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002748 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002749 BPF_ALU64_REG(BPF_ADD, R0, R1),
2750 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 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302756 {
2757 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2758 .u.insns_int = {
2759 BPF_LD_IMM64(R0, 2),
2760 BPF_LD_IMM64(R1, 4294967294U),
2761 BPF_LD_IMM64(R2, 4294967296ULL),
2762 BPF_ALU64_REG(BPF_ADD, R0, R1),
2763 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2764 BPF_MOV32_IMM(R0, 0),
2765 BPF_EXIT_INSN(),
2766 BPF_MOV32_IMM(R0, 1),
2767 BPF_EXIT_INSN(),
2768 },
2769 INTERNAL,
2770 { },
2771 { { 0, 1 } },
2772 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002773 /* BPF_ALU | BPF_ADD | BPF_K */
2774 {
2775 "ALU_ADD_K: 1 + 2 = 3",
2776 .u.insns_int = {
2777 BPF_LD_IMM64(R0, 1),
2778 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2779 BPF_EXIT_INSN(),
2780 },
2781 INTERNAL,
2782 { },
2783 { { 0, 3 } },
2784 },
2785 {
2786 "ALU_ADD_K: 3 + 0 = 3",
2787 .u.insns_int = {
2788 BPF_LD_IMM64(R0, 3),
2789 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2790 BPF_EXIT_INSN(),
2791 },
2792 INTERNAL,
2793 { },
2794 { { 0, 3 } },
2795 },
2796 {
2797 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2798 .u.insns_int = {
2799 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002800 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002801 BPF_EXIT_INSN(),
2802 },
2803 INTERNAL,
2804 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002805 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002806 },
2807 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302808 "ALU_ADD_K: 4294967294 + 2 = 0",
2809 .u.insns_int = {
2810 BPF_LD_IMM64(R0, 4294967294U),
2811 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2812 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2813 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2814 BPF_EXIT_INSN(),
2815 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2816 BPF_EXIT_INSN(),
2817 },
2818 INTERNAL,
2819 { },
2820 { { 0, 1 } },
2821 },
2822 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002823 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2824 .u.insns_int = {
2825 BPF_LD_IMM64(R2, 0x0),
2826 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2827 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2828 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2829 BPF_MOV32_IMM(R0, 2),
2830 BPF_EXIT_INSN(),
2831 BPF_MOV32_IMM(R0, 1),
2832 BPF_EXIT_INSN(),
2833 },
2834 INTERNAL,
2835 { },
2836 { { 0, 0x1 } },
2837 },
2838 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302839 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2840 .u.insns_int = {
2841 BPF_LD_IMM64(R2, 0x0),
2842 BPF_LD_IMM64(R3, 0xffff),
2843 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2844 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2845 BPF_MOV32_IMM(R0, 2),
2846 BPF_EXIT_INSN(),
2847 BPF_MOV32_IMM(R0, 1),
2848 BPF_EXIT_INSN(),
2849 },
2850 INTERNAL,
2851 { },
2852 { { 0, 0x1 } },
2853 },
2854 {
2855 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2856 .u.insns_int = {
2857 BPF_LD_IMM64(R2, 0x0),
2858 BPF_LD_IMM64(R3, 0x7fffffff),
2859 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2860 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2861 BPF_MOV32_IMM(R0, 2),
2862 BPF_EXIT_INSN(),
2863 BPF_MOV32_IMM(R0, 1),
2864 BPF_EXIT_INSN(),
2865 },
2866 INTERNAL,
2867 { },
2868 { { 0, 0x1 } },
2869 },
2870 {
2871 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2872 .u.insns_int = {
2873 BPF_LD_IMM64(R2, 0x0),
2874 BPF_LD_IMM64(R3, 0x80000000),
2875 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2876 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2877 BPF_MOV32_IMM(R0, 2),
2878 BPF_EXIT_INSN(),
2879 BPF_MOV32_IMM(R0, 1),
2880 BPF_EXIT_INSN(),
2881 },
2882 INTERNAL,
2883 { },
2884 { { 0, 0x1 } },
2885 },
2886 {
2887 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2888 .u.insns_int = {
2889 BPF_LD_IMM64(R2, 0x0),
2890 BPF_LD_IMM64(R3, 0x80008000),
2891 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2892 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2893 BPF_MOV32_IMM(R0, 2),
2894 BPF_EXIT_INSN(),
2895 BPF_MOV32_IMM(R0, 1),
2896 BPF_EXIT_INSN(),
2897 },
2898 INTERNAL,
2899 { },
2900 { { 0, 0x1 } },
2901 },
2902 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002903 "ALU64_ADD_K: 1 + 2 = 3",
2904 .u.insns_int = {
2905 BPF_LD_IMM64(R0, 1),
2906 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2907 BPF_EXIT_INSN(),
2908 },
2909 INTERNAL,
2910 { },
2911 { { 0, 3 } },
2912 },
2913 {
2914 "ALU64_ADD_K: 3 + 0 = 3",
2915 .u.insns_int = {
2916 BPF_LD_IMM64(R0, 3),
2917 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2918 BPF_EXIT_INSN(),
2919 },
2920 INTERNAL,
2921 { },
2922 { { 0, 3 } },
2923 },
2924 {
2925 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2926 .u.insns_int = {
2927 BPF_LD_IMM64(R0, 1),
2928 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2929 BPF_EXIT_INSN(),
2930 },
2931 INTERNAL,
2932 { },
2933 { { 0, 2147483647 } },
2934 },
2935 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302936 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2937 .u.insns_int = {
2938 BPF_LD_IMM64(R0, 4294967294U),
2939 BPF_LD_IMM64(R1, 4294967296ULL),
2940 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2941 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2942 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2943 BPF_EXIT_INSN(),
2944 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2945 BPF_EXIT_INSN(),
2946 },
2947 INTERNAL,
2948 { },
2949 { { 0, 1 } },
2950 },
2951 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002952 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2953 .u.insns_int = {
2954 BPF_LD_IMM64(R0, 2147483646),
2955 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2956 BPF_EXIT_INSN(),
2957 },
2958 INTERNAL,
2959 { },
2960 { { 0, -1 } },
2961 },
2962 {
2963 "ALU64_ADD_K: 1 + 0 = 1",
2964 .u.insns_int = {
2965 BPF_LD_IMM64(R2, 0x1),
2966 BPF_LD_IMM64(R3, 0x1),
2967 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2968 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2969 BPF_MOV32_IMM(R0, 2),
2970 BPF_EXIT_INSN(),
2971 BPF_MOV32_IMM(R0, 1),
2972 BPF_EXIT_INSN(),
2973 },
2974 INTERNAL,
2975 { },
2976 { { 0, 0x1 } },
2977 },
2978 {
2979 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2980 .u.insns_int = {
2981 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002982 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002983 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2984 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2985 BPF_MOV32_IMM(R0, 2),
2986 BPF_EXIT_INSN(),
2987 BPF_MOV32_IMM(R0, 1),
2988 BPF_EXIT_INSN(),
2989 },
2990 INTERNAL,
2991 { },
2992 { { 0, 0x1 } },
2993 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302994 {
2995 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2996 .u.insns_int = {
2997 BPF_LD_IMM64(R2, 0x0),
2998 BPF_LD_IMM64(R3, 0xffff),
2999 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
3000 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3001 BPF_MOV32_IMM(R0, 2),
3002 BPF_EXIT_INSN(),
3003 BPF_MOV32_IMM(R0, 1),
3004 BPF_EXIT_INSN(),
3005 },
3006 INTERNAL,
3007 { },
3008 { { 0, 0x1 } },
3009 },
3010 {
3011 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
3012 .u.insns_int = {
3013 BPF_LD_IMM64(R2, 0x0),
3014 BPF_LD_IMM64(R3, 0x7fffffff),
3015 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
3016 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3017 BPF_MOV32_IMM(R0, 2),
3018 BPF_EXIT_INSN(),
3019 BPF_MOV32_IMM(R0, 1),
3020 BPF_EXIT_INSN(),
3021 },
3022 INTERNAL,
3023 { },
3024 { { 0, 0x1 } },
3025 },
3026 {
3027 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
3028 .u.insns_int = {
3029 BPF_LD_IMM64(R2, 0x0),
3030 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
3031 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
3032 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3033 BPF_MOV32_IMM(R0, 2),
3034 BPF_EXIT_INSN(),
3035 BPF_MOV32_IMM(R0, 1),
3036 BPF_EXIT_INSN(),
3037 },
3038 INTERNAL,
3039 { },
3040 { { 0, 0x1 } },
3041 },
3042 {
3043 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
3044 .u.insns_int = {
3045 BPF_LD_IMM64(R2, 0x0),
3046 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
3047 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
3048 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3049 BPF_MOV32_IMM(R0, 2),
3050 BPF_EXIT_INSN(),
3051 BPF_MOV32_IMM(R0, 1),
3052 BPF_EXIT_INSN(),
3053 },
3054 INTERNAL,
3055 { },
3056 { { 0, 0x1 } },
3057 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003058 /* BPF_ALU | BPF_SUB | BPF_X */
3059 {
3060 "ALU_SUB_X: 3 - 1 = 2",
3061 .u.insns_int = {
3062 BPF_LD_IMM64(R0, 3),
3063 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3064 BPF_ALU32_REG(BPF_SUB, R0, R1),
3065 BPF_EXIT_INSN(),
3066 },
3067 INTERNAL,
3068 { },
3069 { { 0, 2 } },
3070 },
3071 {
3072 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
3073 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003074 BPF_LD_IMM64(R0, 4294967295U),
3075 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003076 BPF_ALU32_REG(BPF_SUB, R0, R1),
3077 BPF_EXIT_INSN(),
3078 },
3079 INTERNAL,
3080 { },
3081 { { 0, 1 } },
3082 },
3083 {
3084 "ALU64_SUB_X: 3 - 1 = 2",
3085 .u.insns_int = {
3086 BPF_LD_IMM64(R0, 3),
3087 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3088 BPF_ALU64_REG(BPF_SUB, R0, R1),
3089 BPF_EXIT_INSN(),
3090 },
3091 INTERNAL,
3092 { },
3093 { { 0, 2 } },
3094 },
3095 {
3096 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
3097 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003098 BPF_LD_IMM64(R0, 4294967295U),
3099 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003100 BPF_ALU64_REG(BPF_SUB, R0, R1),
3101 BPF_EXIT_INSN(),
3102 },
3103 INTERNAL,
3104 { },
3105 { { 0, 1 } },
3106 },
3107 /* BPF_ALU | BPF_SUB | BPF_K */
3108 {
3109 "ALU_SUB_K: 3 - 1 = 2",
3110 .u.insns_int = {
3111 BPF_LD_IMM64(R0, 3),
3112 BPF_ALU32_IMM(BPF_SUB, R0, 1),
3113 BPF_EXIT_INSN(),
3114 },
3115 INTERNAL,
3116 { },
3117 { { 0, 2 } },
3118 },
3119 {
3120 "ALU_SUB_K: 3 - 0 = 3",
3121 .u.insns_int = {
3122 BPF_LD_IMM64(R0, 3),
3123 BPF_ALU32_IMM(BPF_SUB, R0, 0),
3124 BPF_EXIT_INSN(),
3125 },
3126 INTERNAL,
3127 { },
3128 { { 0, 3 } },
3129 },
3130 {
3131 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
3132 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003133 BPF_LD_IMM64(R0, 4294967295U),
3134 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003135 BPF_EXIT_INSN(),
3136 },
3137 INTERNAL,
3138 { },
3139 { { 0, 1 } },
3140 },
3141 {
3142 "ALU64_SUB_K: 3 - 1 = 2",
3143 .u.insns_int = {
3144 BPF_LD_IMM64(R0, 3),
3145 BPF_ALU64_IMM(BPF_SUB, R0, 1),
3146 BPF_EXIT_INSN(),
3147 },
3148 INTERNAL,
3149 { },
3150 { { 0, 2 } },
3151 },
3152 {
3153 "ALU64_SUB_K: 3 - 0 = 3",
3154 .u.insns_int = {
3155 BPF_LD_IMM64(R0, 3),
3156 BPF_ALU64_IMM(BPF_SUB, R0, 0),
3157 BPF_EXIT_INSN(),
3158 },
3159 INTERNAL,
3160 { },
3161 { { 0, 3 } },
3162 },
3163 {
3164 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3165 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003166 BPF_LD_IMM64(R0, 4294967294U),
3167 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003168 BPF_EXIT_INSN(),
3169 },
3170 INTERNAL,
3171 { },
3172 { { 0, -1 } },
3173 },
3174 {
3175 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3176 .u.insns_int = {
3177 BPF_LD_IMM64(R0, 2147483646),
3178 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
3179 BPF_EXIT_INSN(),
3180 },
3181 INTERNAL,
3182 { },
3183 { { 0, -1 } },
3184 },
3185 /* BPF_ALU | BPF_MUL | BPF_X */
3186 {
3187 "ALU_MUL_X: 2 * 3 = 6",
3188 .u.insns_int = {
3189 BPF_LD_IMM64(R0, 2),
3190 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3191 BPF_ALU32_REG(BPF_MUL, R0, R1),
3192 BPF_EXIT_INSN(),
3193 },
3194 INTERNAL,
3195 { },
3196 { { 0, 6 } },
3197 },
3198 {
3199 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3200 .u.insns_int = {
3201 BPF_LD_IMM64(R0, 2),
3202 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
3203 BPF_ALU32_REG(BPF_MUL, R0, R1),
3204 BPF_EXIT_INSN(),
3205 },
3206 INTERNAL,
3207 { },
3208 { { 0, 0xFFFFFFF0 } },
3209 },
3210 {
3211 "ALU_MUL_X: -1 * -1 = 1",
3212 .u.insns_int = {
3213 BPF_LD_IMM64(R0, -1),
3214 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3215 BPF_ALU32_REG(BPF_MUL, R0, R1),
3216 BPF_EXIT_INSN(),
3217 },
3218 INTERNAL,
3219 { },
3220 { { 0, 1 } },
3221 },
3222 {
3223 "ALU64_MUL_X: 2 * 3 = 6",
3224 .u.insns_int = {
3225 BPF_LD_IMM64(R0, 2),
3226 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3227 BPF_ALU64_REG(BPF_MUL, R0, R1),
3228 BPF_EXIT_INSN(),
3229 },
3230 INTERNAL,
3231 { },
3232 { { 0, 6 } },
3233 },
3234 {
3235 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3236 .u.insns_int = {
3237 BPF_LD_IMM64(R0, 1),
3238 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3239 BPF_ALU64_REG(BPF_MUL, R0, R1),
3240 BPF_EXIT_INSN(),
3241 },
3242 INTERNAL,
3243 { },
3244 { { 0, 2147483647 } },
3245 },
Johan Almbladhfaa57622021-08-09 11:18:22 +02003246 {
3247 "ALU64_MUL_X: 64x64 multiply, low word",
3248 .u.insns_int = {
3249 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3250 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3251 BPF_ALU64_REG(BPF_MUL, R0, R1),
3252 BPF_EXIT_INSN(),
3253 },
3254 INTERNAL,
3255 { },
3256 { { 0, 0xe5618cf0 } }
3257 },
3258 {
3259 "ALU64_MUL_X: 64x64 multiply, high word",
3260 .u.insns_int = {
3261 BPF_LD_IMM64(R0, 0x0fedcba987654321LL),
3262 BPF_LD_IMM64(R1, 0x123456789abcdef0LL),
3263 BPF_ALU64_REG(BPF_MUL, R0, R1),
3264 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3265 BPF_EXIT_INSN(),
3266 },
3267 INTERNAL,
3268 { },
3269 { { 0, 0x2236d88f } }
3270 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003271 /* BPF_ALU | BPF_MUL | BPF_K */
3272 {
3273 "ALU_MUL_K: 2 * 3 = 6",
3274 .u.insns_int = {
3275 BPF_LD_IMM64(R0, 2),
3276 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3277 BPF_EXIT_INSN(),
3278 },
3279 INTERNAL,
3280 { },
3281 { { 0, 6 } },
3282 },
3283 {
3284 "ALU_MUL_K: 3 * 1 = 3",
3285 .u.insns_int = {
3286 BPF_LD_IMM64(R0, 3),
3287 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3288 BPF_EXIT_INSN(),
3289 },
3290 INTERNAL,
3291 { },
3292 { { 0, 3 } },
3293 },
3294 {
3295 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3296 .u.insns_int = {
3297 BPF_LD_IMM64(R0, 2),
3298 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3299 BPF_EXIT_INSN(),
3300 },
3301 INTERNAL,
3302 { },
3303 { { 0, 0xFFFFFFF0 } },
3304 },
3305 {
3306 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3307 .u.insns_int = {
3308 BPF_LD_IMM64(R2, 0x1),
3309 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3310 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3311 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3312 BPF_MOV32_IMM(R0, 2),
3313 BPF_EXIT_INSN(),
3314 BPF_MOV32_IMM(R0, 1),
3315 BPF_EXIT_INSN(),
3316 },
3317 INTERNAL,
3318 { },
3319 { { 0, 0x1 } },
3320 },
3321 {
3322 "ALU64_MUL_K: 2 * 3 = 6",
3323 .u.insns_int = {
3324 BPF_LD_IMM64(R0, 2),
3325 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3326 BPF_EXIT_INSN(),
3327 },
3328 INTERNAL,
3329 { },
3330 { { 0, 6 } },
3331 },
3332 {
3333 "ALU64_MUL_K: 3 * 1 = 3",
3334 .u.insns_int = {
3335 BPF_LD_IMM64(R0, 3),
3336 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3337 BPF_EXIT_INSN(),
3338 },
3339 INTERNAL,
3340 { },
3341 { { 0, 3 } },
3342 },
3343 {
3344 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3345 .u.insns_int = {
3346 BPF_LD_IMM64(R0, 1),
3347 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3348 BPF_EXIT_INSN(),
3349 },
3350 INTERNAL,
3351 { },
3352 { { 0, 2147483647 } },
3353 },
3354 {
3355 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3356 .u.insns_int = {
3357 BPF_LD_IMM64(R0, 1),
3358 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3359 BPF_EXIT_INSN(),
3360 },
3361 INTERNAL,
3362 { },
3363 { { 0, -2147483647 } },
3364 },
3365 {
3366 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3367 .u.insns_int = {
3368 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003369 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003370 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3371 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3372 BPF_MOV32_IMM(R0, 2),
3373 BPF_EXIT_INSN(),
3374 BPF_MOV32_IMM(R0, 1),
3375 BPF_EXIT_INSN(),
3376 },
3377 INTERNAL,
3378 { },
3379 { { 0, 0x1 } },
3380 },
Johan Almbladhfaa57622021-08-09 11:18:22 +02003381 {
3382 "ALU64_MUL_K: 64x32 multiply, low word",
3383 .u.insns_int = {
3384 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3385 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3386 BPF_EXIT_INSN(),
3387 },
3388 INTERNAL,
3389 { },
3390 { { 0, 0xe242d208 } }
3391 },
3392 {
3393 "ALU64_MUL_K: 64x32 multiply, high word",
3394 .u.insns_int = {
3395 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3396 BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678),
3397 BPF_ALU64_IMM(BPF_RSH, R0, 32),
3398 BPF_EXIT_INSN(),
3399 },
3400 INTERNAL,
3401 { },
3402 { { 0, 0xc28f5c28 } }
3403 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003404 /* BPF_ALU | BPF_DIV | BPF_X */
3405 {
3406 "ALU_DIV_X: 6 / 2 = 3",
3407 .u.insns_int = {
3408 BPF_LD_IMM64(R0, 6),
3409 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3410 BPF_ALU32_REG(BPF_DIV, R0, R1),
3411 BPF_EXIT_INSN(),
3412 },
3413 INTERNAL,
3414 { },
3415 { { 0, 3 } },
3416 },
3417 {
3418 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3419 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003420 BPF_LD_IMM64(R0, 4294967295U),
3421 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003422 BPF_ALU32_REG(BPF_DIV, R0, R1),
3423 BPF_EXIT_INSN(),
3424 },
3425 INTERNAL,
3426 { },
3427 { { 0, 1 } },
3428 },
3429 {
3430 "ALU64_DIV_X: 6 / 2 = 3",
3431 .u.insns_int = {
3432 BPF_LD_IMM64(R0, 6),
3433 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3434 BPF_ALU64_REG(BPF_DIV, R0, R1),
3435 BPF_EXIT_INSN(),
3436 },
3437 INTERNAL,
3438 { },
3439 { { 0, 3 } },
3440 },
3441 {
3442 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3443 .u.insns_int = {
3444 BPF_LD_IMM64(R0, 2147483647),
3445 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3446 BPF_ALU64_REG(BPF_DIV, R0, R1),
3447 BPF_EXIT_INSN(),
3448 },
3449 INTERNAL,
3450 { },
3451 { { 0, 1 } },
3452 },
3453 {
3454 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3455 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003456 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3457 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3458 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003459 BPF_ALU64_REG(BPF_DIV, R2, R4),
3460 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3461 BPF_MOV32_IMM(R0, 2),
3462 BPF_EXIT_INSN(),
3463 BPF_MOV32_IMM(R0, 1),
3464 BPF_EXIT_INSN(),
3465 },
3466 INTERNAL,
3467 { },
3468 { { 0, 0x1 } },
3469 },
3470 /* BPF_ALU | BPF_DIV | BPF_K */
3471 {
3472 "ALU_DIV_K: 6 / 2 = 3",
3473 .u.insns_int = {
3474 BPF_LD_IMM64(R0, 6),
3475 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3476 BPF_EXIT_INSN(),
3477 },
3478 INTERNAL,
3479 { },
3480 { { 0, 3 } },
3481 },
3482 {
3483 "ALU_DIV_K: 3 / 1 = 3",
3484 .u.insns_int = {
3485 BPF_LD_IMM64(R0, 3),
3486 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3487 BPF_EXIT_INSN(),
3488 },
3489 INTERNAL,
3490 { },
3491 { { 0, 3 } },
3492 },
3493 {
3494 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3495 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003496 BPF_LD_IMM64(R0, 4294967295U),
3497 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003498 BPF_EXIT_INSN(),
3499 },
3500 INTERNAL,
3501 { },
3502 { { 0, 1 } },
3503 },
3504 {
3505 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3506 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003507 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003508 BPF_LD_IMM64(R3, 0x1UL),
3509 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3510 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3511 BPF_MOV32_IMM(R0, 2),
3512 BPF_EXIT_INSN(),
3513 BPF_MOV32_IMM(R0, 1),
3514 BPF_EXIT_INSN(),
3515 },
3516 INTERNAL,
3517 { },
3518 { { 0, 0x1 } },
3519 },
3520 {
3521 "ALU64_DIV_K: 6 / 2 = 3",
3522 .u.insns_int = {
3523 BPF_LD_IMM64(R0, 6),
3524 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3525 BPF_EXIT_INSN(),
3526 },
3527 INTERNAL,
3528 { },
3529 { { 0, 3 } },
3530 },
3531 {
3532 "ALU64_DIV_K: 3 / 1 = 3",
3533 .u.insns_int = {
3534 BPF_LD_IMM64(R0, 3),
3535 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3536 BPF_EXIT_INSN(),
3537 },
3538 INTERNAL,
3539 { },
3540 { { 0, 3 } },
3541 },
3542 {
3543 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3544 .u.insns_int = {
3545 BPF_LD_IMM64(R0, 2147483647),
3546 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3547 BPF_EXIT_INSN(),
3548 },
3549 INTERNAL,
3550 { },
3551 { { 0, 1 } },
3552 },
3553 {
3554 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3555 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003556 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3557 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003558 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3559 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3560 BPF_MOV32_IMM(R0, 2),
3561 BPF_EXIT_INSN(),
3562 BPF_MOV32_IMM(R0, 1),
3563 BPF_EXIT_INSN(),
3564 },
3565 INTERNAL,
3566 { },
3567 { { 0, 0x1 } },
3568 },
3569 /* BPF_ALU | BPF_MOD | BPF_X */
3570 {
3571 "ALU_MOD_X: 3 % 2 = 1",
3572 .u.insns_int = {
3573 BPF_LD_IMM64(R0, 3),
3574 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3575 BPF_ALU32_REG(BPF_MOD, R0, R1),
3576 BPF_EXIT_INSN(),
3577 },
3578 INTERNAL,
3579 { },
3580 { { 0, 1 } },
3581 },
3582 {
3583 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3584 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003585 BPF_LD_IMM64(R0, 4294967295U),
3586 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003587 BPF_ALU32_REG(BPF_MOD, R0, R1),
3588 BPF_EXIT_INSN(),
3589 },
3590 INTERNAL,
3591 { },
3592 { { 0, 2 } },
3593 },
3594 {
3595 "ALU64_MOD_X: 3 % 2 = 1",
3596 .u.insns_int = {
3597 BPF_LD_IMM64(R0, 3),
3598 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3599 BPF_ALU64_REG(BPF_MOD, R0, R1),
3600 BPF_EXIT_INSN(),
3601 },
3602 INTERNAL,
3603 { },
3604 { { 0, 1 } },
3605 },
3606 {
3607 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3608 .u.insns_int = {
3609 BPF_LD_IMM64(R0, 2147483647),
3610 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3611 BPF_ALU64_REG(BPF_MOD, R0, R1),
3612 BPF_EXIT_INSN(),
3613 },
3614 INTERNAL,
3615 { },
3616 { { 0, 2 } },
3617 },
3618 /* BPF_ALU | BPF_MOD | BPF_K */
3619 {
3620 "ALU_MOD_K: 3 % 2 = 1",
3621 .u.insns_int = {
3622 BPF_LD_IMM64(R0, 3),
3623 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3624 BPF_EXIT_INSN(),
3625 },
3626 INTERNAL,
3627 { },
3628 { { 0, 1 } },
3629 },
3630 {
3631 "ALU_MOD_K: 3 % 1 = 0",
3632 .u.insns_int = {
3633 BPF_LD_IMM64(R0, 3),
3634 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3635 BPF_EXIT_INSN(),
3636 },
3637 INTERNAL,
3638 { },
3639 { { 0, 0 } },
3640 },
3641 {
3642 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3643 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003644 BPF_LD_IMM64(R0, 4294967295U),
3645 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003646 BPF_EXIT_INSN(),
3647 },
3648 INTERNAL,
3649 { },
3650 { { 0, 2 } },
3651 },
3652 {
3653 "ALU64_MOD_K: 3 % 2 = 1",
3654 .u.insns_int = {
3655 BPF_LD_IMM64(R0, 3),
3656 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3657 BPF_EXIT_INSN(),
3658 },
3659 INTERNAL,
3660 { },
3661 { { 0, 1 } },
3662 },
3663 {
3664 "ALU64_MOD_K: 3 % 1 = 0",
3665 .u.insns_int = {
3666 BPF_LD_IMM64(R0, 3),
3667 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3668 BPF_EXIT_INSN(),
3669 },
3670 INTERNAL,
3671 { },
3672 { { 0, 0 } },
3673 },
3674 {
3675 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3676 .u.insns_int = {
3677 BPF_LD_IMM64(R0, 2147483647),
3678 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3679 BPF_EXIT_INSN(),
3680 },
3681 INTERNAL,
3682 { },
3683 { { 0, 2 } },
3684 },
3685 /* BPF_ALU | BPF_AND | BPF_X */
3686 {
3687 "ALU_AND_X: 3 & 2 = 2",
3688 .u.insns_int = {
3689 BPF_LD_IMM64(R0, 3),
3690 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3691 BPF_ALU32_REG(BPF_AND, R0, R1),
3692 BPF_EXIT_INSN(),
3693 },
3694 INTERNAL,
3695 { },
3696 { { 0, 2 } },
3697 },
3698 {
3699 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3700 .u.insns_int = {
3701 BPF_LD_IMM64(R0, 0xffffffff),
3702 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3703 BPF_ALU32_REG(BPF_AND, R0, R1),
3704 BPF_EXIT_INSN(),
3705 },
3706 INTERNAL,
3707 { },
3708 { { 0, 0xffffffff } },
3709 },
3710 {
3711 "ALU64_AND_X: 3 & 2 = 2",
3712 .u.insns_int = {
3713 BPF_LD_IMM64(R0, 3),
3714 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3715 BPF_ALU64_REG(BPF_AND, R0, R1),
3716 BPF_EXIT_INSN(),
3717 },
3718 INTERNAL,
3719 { },
3720 { { 0, 2 } },
3721 },
3722 {
3723 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3724 .u.insns_int = {
3725 BPF_LD_IMM64(R0, 0xffffffff),
3726 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3727 BPF_ALU64_REG(BPF_AND, R0, R1),
3728 BPF_EXIT_INSN(),
3729 },
3730 INTERNAL,
3731 { },
3732 { { 0, 0xffffffff } },
3733 },
3734 /* BPF_ALU | BPF_AND | BPF_K */
3735 {
3736 "ALU_AND_K: 3 & 2 = 2",
3737 .u.insns_int = {
3738 BPF_LD_IMM64(R0, 3),
3739 BPF_ALU32_IMM(BPF_AND, R0, 2),
3740 BPF_EXIT_INSN(),
3741 },
3742 INTERNAL,
3743 { },
3744 { { 0, 2 } },
3745 },
3746 {
3747 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3748 .u.insns_int = {
3749 BPF_LD_IMM64(R0, 0xffffffff),
3750 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3751 BPF_EXIT_INSN(),
3752 },
3753 INTERNAL,
3754 { },
3755 { { 0, 0xffffffff } },
3756 },
3757 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003758 "ALU_AND_K: Small immediate",
3759 .u.insns_int = {
3760 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3761 BPF_ALU32_IMM(BPF_AND, R0, 15),
3762 BPF_EXIT_INSN(),
3763 },
3764 INTERNAL,
3765 { },
3766 { { 0, 4 } }
3767 },
3768 {
3769 "ALU_AND_K: Large immediate",
3770 .u.insns_int = {
3771 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
3772 BPF_ALU32_IMM(BPF_AND, R0, 0xafbfcfdf),
3773 BPF_EXIT_INSN(),
3774 },
3775 INTERNAL,
3776 { },
3777 { { 0, 0xa1b2c3d4 } }
3778 },
3779 {
3780 "ALU_AND_K: Zero extension",
3781 .u.insns_int = {
3782 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3783 BPF_LD_IMM64(R1, 0x0000000080a0c0e0LL),
3784 BPF_ALU32_IMM(BPF_AND, R0, 0xf0f0f0f0),
3785 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3786 BPF_MOV32_IMM(R0, 2),
3787 BPF_EXIT_INSN(),
3788 BPF_MOV32_IMM(R0, 1),
3789 BPF_EXIT_INSN(),
3790 },
3791 INTERNAL,
3792 { },
3793 { { 0, 1 } }
3794 },
3795 {
Michael Holzheucffc6422015-05-11 22:22:44 -07003796 "ALU64_AND_K: 3 & 2 = 2",
3797 .u.insns_int = {
3798 BPF_LD_IMM64(R0, 3),
3799 BPF_ALU64_IMM(BPF_AND, R0, 2),
3800 BPF_EXIT_INSN(),
3801 },
3802 INTERNAL,
3803 { },
3804 { { 0, 2 } },
3805 },
3806 {
3807 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3808 .u.insns_int = {
3809 BPF_LD_IMM64(R0, 0xffffffff),
3810 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3811 BPF_EXIT_INSN(),
3812 },
3813 INTERNAL,
3814 { },
3815 { { 0, 0xffffffff } },
3816 },
3817 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003818 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000000000000000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003819 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003820 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3821 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003822 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3823 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3824 BPF_MOV32_IMM(R0, 2),
3825 BPF_EXIT_INSN(),
3826 BPF_MOV32_IMM(R0, 1),
3827 BPF_EXIT_INSN(),
3828 },
3829 INTERNAL,
3830 { },
3831 { { 0, 0x1 } },
3832 },
3833 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02003834 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffff0000",
Michael Holzheucffc6422015-05-11 22:22:44 -07003835 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003836 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3837 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003838 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3839 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3840 BPF_MOV32_IMM(R0, 2),
3841 BPF_EXIT_INSN(),
3842 BPF_MOV32_IMM(R0, 1),
3843 BPF_EXIT_INSN(),
3844 },
3845 INTERNAL,
3846 { },
3847 { { 0, 0x1 } },
3848 },
3849 {
3850 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3851 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003852 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3853 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003854 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3855 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3856 BPF_MOV32_IMM(R0, 2),
3857 BPF_EXIT_INSN(),
3858 BPF_MOV32_IMM(R0, 1),
3859 BPF_EXIT_INSN(),
3860 },
3861 INTERNAL,
3862 { },
3863 { { 0, 0x1 } },
3864 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003865 {
3866 "ALU64_AND_K: Sign extension 1",
3867 .u.insns_int = {
3868 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3869 BPF_LD_IMM64(R1, 0x00000000090b0d0fLL),
3870 BPF_ALU64_IMM(BPF_AND, R0, 0x0f0f0f0f),
3871 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3872 BPF_MOV32_IMM(R0, 2),
3873 BPF_EXIT_INSN(),
3874 BPF_MOV32_IMM(R0, 1),
3875 BPF_EXIT_INSN(),
3876 },
3877 INTERNAL,
3878 { },
3879 { { 0, 1 } }
3880 },
3881 {
3882 "ALU64_AND_K: Sign extension 2",
3883 .u.insns_int = {
3884 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3885 BPF_LD_IMM64(R1, 0x0123456780a0c0e0LL),
3886 BPF_ALU64_IMM(BPF_AND, R0, 0xf0f0f0f0),
3887 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3888 BPF_MOV32_IMM(R0, 2),
3889 BPF_EXIT_INSN(),
3890 BPF_MOV32_IMM(R0, 1),
3891 BPF_EXIT_INSN(),
3892 },
3893 INTERNAL,
3894 { },
3895 { { 0, 1 } }
3896 },
Michael Holzheucffc6422015-05-11 22:22:44 -07003897 /* BPF_ALU | BPF_OR | BPF_X */
3898 {
3899 "ALU_OR_X: 1 | 2 = 3",
3900 .u.insns_int = {
3901 BPF_LD_IMM64(R0, 1),
3902 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3903 BPF_ALU32_REG(BPF_OR, R0, R1),
3904 BPF_EXIT_INSN(),
3905 },
3906 INTERNAL,
3907 { },
3908 { { 0, 3 } },
3909 },
3910 {
3911 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3912 .u.insns_int = {
3913 BPF_LD_IMM64(R0, 0),
3914 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3915 BPF_ALU32_REG(BPF_OR, R0, R1),
3916 BPF_EXIT_INSN(),
3917 },
3918 INTERNAL,
3919 { },
3920 { { 0, 0xffffffff } },
3921 },
3922 {
3923 "ALU64_OR_X: 1 | 2 = 3",
3924 .u.insns_int = {
3925 BPF_LD_IMM64(R0, 1),
3926 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3927 BPF_ALU64_REG(BPF_OR, R0, R1),
3928 BPF_EXIT_INSN(),
3929 },
3930 INTERNAL,
3931 { },
3932 { { 0, 3 } },
3933 },
3934 {
3935 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3936 .u.insns_int = {
3937 BPF_LD_IMM64(R0, 0),
3938 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3939 BPF_ALU64_REG(BPF_OR, R0, R1),
3940 BPF_EXIT_INSN(),
3941 },
3942 INTERNAL,
3943 { },
3944 { { 0, 0xffffffff } },
3945 },
3946 /* BPF_ALU | BPF_OR | BPF_K */
3947 {
3948 "ALU_OR_K: 1 | 2 = 3",
3949 .u.insns_int = {
3950 BPF_LD_IMM64(R0, 1),
3951 BPF_ALU32_IMM(BPF_OR, R0, 2),
3952 BPF_EXIT_INSN(),
3953 },
3954 INTERNAL,
3955 { },
3956 { { 0, 3 } },
3957 },
3958 {
3959 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3960 .u.insns_int = {
3961 BPF_LD_IMM64(R0, 0),
3962 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3963 BPF_EXIT_INSN(),
3964 },
3965 INTERNAL,
3966 { },
3967 { { 0, 0xffffffff } },
3968 },
3969 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02003970 "ALU_OR_K: Small immediate",
3971 .u.insns_int = {
3972 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3973 BPF_ALU32_IMM(BPF_OR, R0, 1),
3974 BPF_EXIT_INSN(),
3975 },
3976 INTERNAL,
3977 { },
3978 { { 0, 0x01020305 } }
3979 },
3980 {
3981 "ALU_OR_K: Large immediate",
3982 .u.insns_int = {
3983 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
3984 BPF_ALU32_IMM(BPF_OR, R0, 0xa0b0c0d0),
3985 BPF_EXIT_INSN(),
3986 },
3987 INTERNAL,
3988 { },
3989 { { 0, 0xa1b2c3d4 } }
3990 },
3991 {
3992 "ALU_OR_K: Zero extension",
3993 .u.insns_int = {
3994 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3995 BPF_LD_IMM64(R1, 0x00000000f9fbfdffLL),
3996 BPF_ALU32_IMM(BPF_OR, R0, 0xf0f0f0f0),
3997 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
3998 BPF_MOV32_IMM(R0, 2),
3999 BPF_EXIT_INSN(),
4000 BPF_MOV32_IMM(R0, 1),
4001 BPF_EXIT_INSN(),
4002 },
4003 INTERNAL,
4004 { },
4005 { { 0, 1 } }
4006 },
4007 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004008 "ALU64_OR_K: 1 | 2 = 3",
4009 .u.insns_int = {
4010 BPF_LD_IMM64(R0, 1),
4011 BPF_ALU64_IMM(BPF_OR, R0, 2),
4012 BPF_EXIT_INSN(),
4013 },
4014 INTERNAL,
4015 { },
4016 { { 0, 3 } },
4017 },
4018 {
4019 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
4020 .u.insns_int = {
4021 BPF_LD_IMM64(R0, 0),
4022 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
4023 BPF_EXIT_INSN(),
4024 },
4025 INTERNAL,
4026 { },
4027 { { 0, 0xffffffff } },
4028 },
4029 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02004030 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffffffff0000",
Michael Holzheucffc6422015-05-11 22:22:44 -07004031 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004032 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4033 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004034 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
4035 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4036 BPF_MOV32_IMM(R0, 2),
4037 BPF_EXIT_INSN(),
4038 BPF_MOV32_IMM(R0, 1),
4039 BPF_EXIT_INSN(),
4040 },
4041 INTERNAL,
4042 { },
4043 { { 0, 0x1 } },
4044 },
4045 {
4046 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
4047 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004048 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4049 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004050 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4051 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4052 BPF_MOV32_IMM(R0, 2),
4053 BPF_EXIT_INSN(),
4054 BPF_MOV32_IMM(R0, 1),
4055 BPF_EXIT_INSN(),
4056 },
4057 INTERNAL,
4058 { },
4059 { { 0, 0x1 } },
4060 },
4061 {
4062 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
4063 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004064 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4065 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004066 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
4067 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4068 BPF_MOV32_IMM(R0, 2),
4069 BPF_EXIT_INSN(),
4070 BPF_MOV32_IMM(R0, 1),
4071 BPF_EXIT_INSN(),
4072 },
4073 INTERNAL,
4074 { },
4075 { { 0, 0x1 } },
4076 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004077 {
4078 "ALU64_OR_K: Sign extension 1",
4079 .u.insns_int = {
4080 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4081 BPF_LD_IMM64(R1, 0x012345678fafcfefLL),
4082 BPF_ALU64_IMM(BPF_OR, R0, 0x0f0f0f0f),
4083 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4084 BPF_MOV32_IMM(R0, 2),
4085 BPF_EXIT_INSN(),
4086 BPF_MOV32_IMM(R0, 1),
4087 BPF_EXIT_INSN(),
4088 },
4089 INTERNAL,
4090 { },
4091 { { 0, 1 } }
4092 },
4093 {
4094 "ALU64_OR_K: Sign extension 2",
4095 .u.insns_int = {
4096 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4097 BPF_LD_IMM64(R1, 0xfffffffff9fbfdffLL),
4098 BPF_ALU64_IMM(BPF_OR, R0, 0xf0f0f0f0),
4099 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4100 BPF_MOV32_IMM(R0, 2),
4101 BPF_EXIT_INSN(),
4102 BPF_MOV32_IMM(R0, 1),
4103 BPF_EXIT_INSN(),
4104 },
4105 INTERNAL,
4106 { },
4107 { { 0, 1 } }
4108 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004109 /* BPF_ALU | BPF_XOR | BPF_X */
4110 {
4111 "ALU_XOR_X: 5 ^ 6 = 3",
4112 .u.insns_int = {
4113 BPF_LD_IMM64(R0, 5),
4114 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4115 BPF_ALU32_REG(BPF_XOR, R0, R1),
4116 BPF_EXIT_INSN(),
4117 },
4118 INTERNAL,
4119 { },
4120 { { 0, 3 } },
4121 },
4122 {
4123 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
4124 .u.insns_int = {
4125 BPF_LD_IMM64(R0, 1),
4126 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4127 BPF_ALU32_REG(BPF_XOR, R0, R1),
4128 BPF_EXIT_INSN(),
4129 },
4130 INTERNAL,
4131 { },
4132 { { 0, 0xfffffffe } },
4133 },
4134 {
4135 "ALU64_XOR_X: 5 ^ 6 = 3",
4136 .u.insns_int = {
4137 BPF_LD_IMM64(R0, 5),
4138 BPF_ALU32_IMM(BPF_MOV, R1, 6),
4139 BPF_ALU64_REG(BPF_XOR, R0, R1),
4140 BPF_EXIT_INSN(),
4141 },
4142 INTERNAL,
4143 { },
4144 { { 0, 3 } },
4145 },
4146 {
4147 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
4148 .u.insns_int = {
4149 BPF_LD_IMM64(R0, 1),
4150 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4151 BPF_ALU64_REG(BPF_XOR, R0, R1),
4152 BPF_EXIT_INSN(),
4153 },
4154 INTERNAL,
4155 { },
4156 { { 0, 0xfffffffe } },
4157 },
4158 /* BPF_ALU | BPF_XOR | BPF_K */
4159 {
4160 "ALU_XOR_K: 5 ^ 6 = 3",
4161 .u.insns_int = {
4162 BPF_LD_IMM64(R0, 5),
4163 BPF_ALU32_IMM(BPF_XOR, R0, 6),
4164 BPF_EXIT_INSN(),
4165 },
4166 INTERNAL,
4167 { },
4168 { { 0, 3 } },
4169 },
4170 {
4171 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
4172 .u.insns_int = {
4173 BPF_LD_IMM64(R0, 1),
4174 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
4175 BPF_EXIT_INSN(),
4176 },
4177 INTERNAL,
4178 { },
4179 { { 0, 0xfffffffe } },
4180 },
4181 {
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004182 "ALU_XOR_K: Small immediate",
4183 .u.insns_int = {
4184 BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304),
4185 BPF_ALU32_IMM(BPF_XOR, R0, 15),
4186 BPF_EXIT_INSN(),
4187 },
4188 INTERNAL,
4189 { },
4190 { { 0, 0x0102030b } }
4191 },
4192 {
4193 "ALU_XOR_K: Large immediate",
4194 .u.insns_int = {
4195 BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4),
4196 BPF_ALU32_IMM(BPF_XOR, R0, 0xafbfcfdf),
4197 BPF_EXIT_INSN(),
4198 },
4199 INTERNAL,
4200 { },
4201 { { 0, 0x5e4d3c2b } }
4202 },
4203 {
4204 "ALU_XOR_K: Zero extension",
4205 .u.insns_int = {
4206 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4207 BPF_LD_IMM64(R1, 0x00000000795b3d1fLL),
4208 BPF_ALU32_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4209 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4210 BPF_MOV32_IMM(R0, 2),
4211 BPF_EXIT_INSN(),
4212 BPF_MOV32_IMM(R0, 1),
4213 BPF_EXIT_INSN(),
4214 },
4215 INTERNAL,
4216 { },
4217 { { 0, 1 } }
4218 },
4219 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004220 "ALU64_XOR_K: 5 ^ 6 = 3",
4221 .u.insns_int = {
4222 BPF_LD_IMM64(R0, 5),
4223 BPF_ALU64_IMM(BPF_XOR, R0, 6),
4224 BPF_EXIT_INSN(),
4225 },
4226 INTERNAL,
4227 { },
4228 { { 0, 3 } },
4229 },
4230 {
Johan Almbladhe92c8132021-08-09 11:18:18 +02004231 "ALU64_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
Michael Holzheucffc6422015-05-11 22:22:44 -07004232 .u.insns_int = {
4233 BPF_LD_IMM64(R0, 1),
4234 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
4235 BPF_EXIT_INSN(),
4236 },
4237 INTERNAL,
4238 { },
4239 { { 0, 0xfffffffe } },
4240 },
4241 {
4242 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
4243 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004244 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4245 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004246 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
4247 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4248 BPF_MOV32_IMM(R0, 2),
4249 BPF_EXIT_INSN(),
4250 BPF_MOV32_IMM(R0, 1),
4251 BPF_EXIT_INSN(),
4252 },
4253 INTERNAL,
4254 { },
4255 { { 0, 0x1 } },
4256 },
4257 {
4258 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
4259 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004260 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
4261 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004262 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4263 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4264 BPF_MOV32_IMM(R0, 2),
4265 BPF_EXIT_INSN(),
4266 BPF_MOV32_IMM(R0, 1),
4267 BPF_EXIT_INSN(),
4268 },
4269 INTERNAL,
4270 { },
4271 { { 0, 0x1 } },
4272 },
4273 {
4274 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
4275 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004276 BPF_LD_IMM64(R2, 0x0000000000000000LL),
4277 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004278 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
4279 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4280 BPF_MOV32_IMM(R0, 2),
4281 BPF_EXIT_INSN(),
4282 BPF_MOV32_IMM(R0, 1),
4283 BPF_EXIT_INSN(),
4284 },
4285 INTERNAL,
4286 { },
4287 { { 0, 0x1 } },
4288 },
Johan Almbladhba89bcf2021-08-09 11:18:19 +02004289 {
4290 "ALU64_XOR_K: Sign extension 1",
4291 .u.insns_int = {
4292 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4293 BPF_LD_IMM64(R1, 0x0123456786a4c2e0LL),
4294 BPF_ALU64_IMM(BPF_XOR, R0, 0x0f0f0f0f),
4295 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4296 BPF_MOV32_IMM(R0, 2),
4297 BPF_EXIT_INSN(),
4298 BPF_MOV32_IMM(R0, 1),
4299 BPF_EXIT_INSN(),
4300 },
4301 INTERNAL,
4302 { },
4303 { { 0, 1 } }
4304 },
4305 {
4306 "ALU64_XOR_K: Sign extension 2",
4307 .u.insns_int = {
4308 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4309 BPF_LD_IMM64(R1, 0xfedcba98795b3d1fLL),
4310 BPF_ALU64_IMM(BPF_XOR, R0, 0xf0f0f0f0),
4311 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
4312 BPF_MOV32_IMM(R0, 2),
4313 BPF_EXIT_INSN(),
4314 BPF_MOV32_IMM(R0, 1),
4315 BPF_EXIT_INSN(),
4316 },
4317 INTERNAL,
4318 { },
4319 { { 0, 1 } }
4320 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004321 /* BPF_ALU | BPF_LSH | BPF_X */
4322 {
4323 "ALU_LSH_X: 1 << 1 = 2",
4324 .u.insns_int = {
4325 BPF_LD_IMM64(R0, 1),
4326 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4327 BPF_ALU32_REG(BPF_LSH, R0, R1),
4328 BPF_EXIT_INSN(),
4329 },
4330 INTERNAL,
4331 { },
4332 { { 0, 2 } },
4333 },
4334 {
4335 "ALU_LSH_X: 1 << 31 = 0x80000000",
4336 .u.insns_int = {
4337 BPF_LD_IMM64(R0, 1),
4338 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4339 BPF_ALU32_REG(BPF_LSH, R0, R1),
4340 BPF_EXIT_INSN(),
4341 },
4342 INTERNAL,
4343 { },
4344 { { 0, 0x80000000 } },
4345 },
4346 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004347 "ALU_LSH_X: 0x12345678 << 12 = 0x45678000",
4348 .u.insns_int = {
4349 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4350 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4351 BPF_ALU32_REG(BPF_LSH, R0, R1),
4352 BPF_EXIT_INSN(),
4353 },
4354 INTERNAL,
4355 { },
4356 { { 0, 0x45678000 } }
4357 },
4358 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004359 "ALU64_LSH_X: 1 << 1 = 2",
4360 .u.insns_int = {
4361 BPF_LD_IMM64(R0, 1),
4362 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4363 BPF_ALU64_REG(BPF_LSH, R0, R1),
4364 BPF_EXIT_INSN(),
4365 },
4366 INTERNAL,
4367 { },
4368 { { 0, 2 } },
4369 },
4370 {
4371 "ALU64_LSH_X: 1 << 31 = 0x80000000",
4372 .u.insns_int = {
4373 BPF_LD_IMM64(R0, 1),
4374 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4375 BPF_ALU64_REG(BPF_LSH, R0, R1),
4376 BPF_EXIT_INSN(),
4377 },
4378 INTERNAL,
4379 { },
4380 { { 0, 0x80000000 } },
4381 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004382 {
4383 "ALU64_LSH_X: Shift < 32, low word",
4384 .u.insns_int = {
4385 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4386 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4387 BPF_ALU64_REG(BPF_LSH, R0, R1),
4388 BPF_EXIT_INSN(),
4389 },
4390 INTERNAL,
4391 { },
4392 { { 0, 0xbcdef000 } }
4393 },
4394 {
4395 "ALU64_LSH_X: Shift < 32, high word",
4396 .u.insns_int = {
4397 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4398 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4399 BPF_ALU64_REG(BPF_LSH, R0, R1),
4400 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4401 BPF_EXIT_INSN(),
4402 },
4403 INTERNAL,
4404 { },
4405 { { 0, 0x3456789a } }
4406 },
4407 {
4408 "ALU64_LSH_X: Shift > 32, low word",
4409 .u.insns_int = {
4410 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4411 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4412 BPF_ALU64_REG(BPF_LSH, R0, R1),
4413 BPF_EXIT_INSN(),
4414 },
4415 INTERNAL,
4416 { },
4417 { { 0, 0 } }
4418 },
4419 {
4420 "ALU64_LSH_X: Shift > 32, high word",
4421 .u.insns_int = {
4422 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4423 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4424 BPF_ALU64_REG(BPF_LSH, R0, R1),
4425 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4426 BPF_EXIT_INSN(),
4427 },
4428 INTERNAL,
4429 { },
4430 { { 0, 0x9abcdef0 } }
4431 },
4432 {
4433 "ALU64_LSH_X: Shift == 32, low word",
4434 .u.insns_int = {
4435 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4436 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4437 BPF_ALU64_REG(BPF_LSH, R0, R1),
4438 BPF_EXIT_INSN(),
4439 },
4440 INTERNAL,
4441 { },
4442 { { 0, 0 } }
4443 },
4444 {
4445 "ALU64_LSH_X: Shift == 32, high word",
4446 .u.insns_int = {
4447 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4448 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4449 BPF_ALU64_REG(BPF_LSH, R0, R1),
4450 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4451 BPF_EXIT_INSN(),
4452 },
4453 INTERNAL,
4454 { },
4455 { { 0, 0x89abcdef } }
4456 },
4457 {
4458 "ALU64_LSH_X: Zero shift, low word",
4459 .u.insns_int = {
4460 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4461 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4462 BPF_ALU64_REG(BPF_LSH, R0, R1),
4463 BPF_EXIT_INSN(),
4464 },
4465 INTERNAL,
4466 { },
4467 { { 0, 0x89abcdef } }
4468 },
4469 {
4470 "ALU64_LSH_X: Zero shift, high word",
4471 .u.insns_int = {
4472 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4473 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4474 BPF_ALU64_REG(BPF_LSH, R0, R1),
4475 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4476 BPF_EXIT_INSN(),
4477 },
4478 INTERNAL,
4479 { },
4480 { { 0, 0x01234567 } }
4481 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004482 /* BPF_ALU | BPF_LSH | BPF_K */
4483 {
4484 "ALU_LSH_K: 1 << 1 = 2",
4485 .u.insns_int = {
4486 BPF_LD_IMM64(R0, 1),
4487 BPF_ALU32_IMM(BPF_LSH, R0, 1),
4488 BPF_EXIT_INSN(),
4489 },
4490 INTERNAL,
4491 { },
4492 { { 0, 2 } },
4493 },
4494 {
4495 "ALU_LSH_K: 1 << 31 = 0x80000000",
4496 .u.insns_int = {
4497 BPF_LD_IMM64(R0, 1),
4498 BPF_ALU32_IMM(BPF_LSH, R0, 31),
4499 BPF_EXIT_INSN(),
4500 },
4501 INTERNAL,
4502 { },
4503 { { 0, 0x80000000 } },
4504 },
4505 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004506 "ALU_LSH_K: 0x12345678 << 12 = 0x45678000",
4507 .u.insns_int = {
4508 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4509 BPF_ALU32_IMM(BPF_LSH, R0, 12),
4510 BPF_EXIT_INSN(),
4511 },
4512 INTERNAL,
4513 { },
4514 { { 0, 0x45678000 } }
4515 },
4516 {
4517 "ALU_LSH_K: 0x12345678 << 0 = 0x12345678",
4518 .u.insns_int = {
4519 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4520 BPF_ALU32_IMM(BPF_LSH, R0, 0),
4521 BPF_EXIT_INSN(),
4522 },
4523 INTERNAL,
4524 { },
4525 { { 0, 0x12345678 } }
4526 },
4527 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004528 "ALU64_LSH_K: 1 << 1 = 2",
4529 .u.insns_int = {
4530 BPF_LD_IMM64(R0, 1),
4531 BPF_ALU64_IMM(BPF_LSH, R0, 1),
4532 BPF_EXIT_INSN(),
4533 },
4534 INTERNAL,
4535 { },
4536 { { 0, 2 } },
4537 },
4538 {
4539 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4540 .u.insns_int = {
4541 BPF_LD_IMM64(R0, 1),
4542 BPF_ALU64_IMM(BPF_LSH, R0, 31),
4543 BPF_EXIT_INSN(),
4544 },
4545 INTERNAL,
4546 { },
4547 { { 0, 0x80000000 } },
4548 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004549 {
4550 "ALU64_LSH_K: Shift < 32, low word",
4551 .u.insns_int = {
4552 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4553 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4554 BPF_EXIT_INSN(),
4555 },
4556 INTERNAL,
4557 { },
4558 { { 0, 0xbcdef000 } }
4559 },
4560 {
4561 "ALU64_LSH_K: Shift < 32, high word",
4562 .u.insns_int = {
4563 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4564 BPF_ALU64_IMM(BPF_LSH, R0, 12),
4565 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4566 BPF_EXIT_INSN(),
4567 },
4568 INTERNAL,
4569 { },
4570 { { 0, 0x3456789a } }
4571 },
4572 {
4573 "ALU64_LSH_K: Shift > 32, low word",
4574 .u.insns_int = {
4575 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4576 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4577 BPF_EXIT_INSN(),
4578 },
4579 INTERNAL,
4580 { },
4581 { { 0, 0 } }
4582 },
4583 {
4584 "ALU64_LSH_K: Shift > 32, high word",
4585 .u.insns_int = {
4586 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4587 BPF_ALU64_IMM(BPF_LSH, R0, 36),
4588 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4589 BPF_EXIT_INSN(),
4590 },
4591 INTERNAL,
4592 { },
4593 { { 0, 0x9abcdef0 } }
4594 },
4595 {
4596 "ALU64_LSH_K: Shift == 32, low word",
4597 .u.insns_int = {
4598 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4599 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4600 BPF_EXIT_INSN(),
4601 },
4602 INTERNAL,
4603 { },
4604 { { 0, 0 } }
4605 },
4606 {
4607 "ALU64_LSH_K: Shift == 32, high word",
4608 .u.insns_int = {
4609 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4610 BPF_ALU64_IMM(BPF_LSH, R0, 32),
4611 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4612 BPF_EXIT_INSN(),
4613 },
4614 INTERNAL,
4615 { },
4616 { { 0, 0x89abcdef } }
4617 },
4618 {
4619 "ALU64_LSH_K: Zero shift",
4620 .u.insns_int = {
4621 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4622 BPF_ALU64_IMM(BPF_LSH, R0, 0),
4623 BPF_EXIT_INSN(),
4624 },
4625 INTERNAL,
4626 { },
4627 { { 0, 0x89abcdef } }
4628 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004629 /* BPF_ALU | BPF_RSH | BPF_X */
4630 {
4631 "ALU_RSH_X: 2 >> 1 = 1",
4632 .u.insns_int = {
4633 BPF_LD_IMM64(R0, 2),
4634 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4635 BPF_ALU32_REG(BPF_RSH, R0, R1),
4636 BPF_EXIT_INSN(),
4637 },
4638 INTERNAL,
4639 { },
4640 { { 0, 1 } },
4641 },
4642 {
4643 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4644 .u.insns_int = {
4645 BPF_LD_IMM64(R0, 0x80000000),
4646 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4647 BPF_ALU32_REG(BPF_RSH, R0, R1),
4648 BPF_EXIT_INSN(),
4649 },
4650 INTERNAL,
4651 { },
4652 { { 0, 1 } },
4653 },
4654 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004655 "ALU_RSH_X: 0x12345678 >> 20 = 0x123",
4656 .u.insns_int = {
4657 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4658 BPF_ALU32_IMM(BPF_MOV, R1, 20),
4659 BPF_ALU32_REG(BPF_RSH, R0, R1),
4660 BPF_EXIT_INSN(),
4661 },
4662 INTERNAL,
4663 { },
4664 { { 0, 0x123 } }
4665 },
4666 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004667 "ALU64_RSH_X: 2 >> 1 = 1",
4668 .u.insns_int = {
4669 BPF_LD_IMM64(R0, 2),
4670 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4671 BPF_ALU64_REG(BPF_RSH, R0, R1),
4672 BPF_EXIT_INSN(),
4673 },
4674 INTERNAL,
4675 { },
4676 { { 0, 1 } },
4677 },
4678 {
4679 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4680 .u.insns_int = {
4681 BPF_LD_IMM64(R0, 0x80000000),
4682 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4683 BPF_ALU64_REG(BPF_RSH, R0, R1),
4684 BPF_EXIT_INSN(),
4685 },
4686 INTERNAL,
4687 { },
4688 { { 0, 1 } },
4689 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004690 {
4691 "ALU64_RSH_X: Shift < 32, low word",
4692 .u.insns_int = {
4693 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4694 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4695 BPF_ALU64_REG(BPF_RSH, R0, R1),
4696 BPF_EXIT_INSN(),
4697 },
4698 INTERNAL,
4699 { },
4700 { { 0, 0x56789abc } }
4701 },
4702 {
4703 "ALU64_RSH_X: Shift < 32, high word",
4704 .u.insns_int = {
4705 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4706 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4707 BPF_ALU64_REG(BPF_RSH, R0, R1),
4708 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4709 BPF_EXIT_INSN(),
4710 },
4711 INTERNAL,
4712 { },
4713 { { 0, 0x00081234 } }
4714 },
4715 {
4716 "ALU64_RSH_X: Shift > 32, low word",
4717 .u.insns_int = {
4718 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4719 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4720 BPF_ALU64_REG(BPF_RSH, R0, R1),
4721 BPF_EXIT_INSN(),
4722 },
4723 INTERNAL,
4724 { },
4725 { { 0, 0x08123456 } }
4726 },
4727 {
4728 "ALU64_RSH_X: Shift > 32, high word",
4729 .u.insns_int = {
4730 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4731 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4732 BPF_ALU64_REG(BPF_RSH, R0, R1),
4733 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4734 BPF_EXIT_INSN(),
4735 },
4736 INTERNAL,
4737 { },
4738 { { 0, 0 } }
4739 },
4740 {
4741 "ALU64_RSH_X: Shift == 32, low word",
4742 .u.insns_int = {
4743 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4744 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4745 BPF_ALU64_REG(BPF_RSH, R0, R1),
4746 BPF_EXIT_INSN(),
4747 },
4748 INTERNAL,
4749 { },
4750 { { 0, 0x81234567 } }
4751 },
4752 {
4753 "ALU64_RSH_X: Shift == 32, high word",
4754 .u.insns_int = {
4755 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4756 BPF_ALU32_IMM(BPF_MOV, R1, 32),
4757 BPF_ALU64_REG(BPF_RSH, R0, R1),
4758 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4759 BPF_EXIT_INSN(),
4760 },
4761 INTERNAL,
4762 { },
4763 { { 0, 0 } }
4764 },
4765 {
4766 "ALU64_RSH_X: Zero shift, low word",
4767 .u.insns_int = {
4768 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4769 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4770 BPF_ALU64_REG(BPF_RSH, R0, R1),
4771 BPF_EXIT_INSN(),
4772 },
4773 INTERNAL,
4774 { },
4775 { { 0, 0x89abcdef } }
4776 },
4777 {
4778 "ALU64_RSH_X: Zero shift, high word",
4779 .u.insns_int = {
4780 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4781 BPF_ALU32_IMM(BPF_MOV, R1, 0),
4782 BPF_ALU64_REG(BPF_RSH, R0, R1),
4783 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4784 BPF_EXIT_INSN(),
4785 },
4786 INTERNAL,
4787 { },
4788 { { 0, 0x81234567 } }
4789 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004790 /* BPF_ALU | BPF_RSH | BPF_K */
4791 {
4792 "ALU_RSH_K: 2 >> 1 = 1",
4793 .u.insns_int = {
4794 BPF_LD_IMM64(R0, 2),
4795 BPF_ALU32_IMM(BPF_RSH, R0, 1),
4796 BPF_EXIT_INSN(),
4797 },
4798 INTERNAL,
4799 { },
4800 { { 0, 1 } },
4801 },
4802 {
4803 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4804 .u.insns_int = {
4805 BPF_LD_IMM64(R0, 0x80000000),
4806 BPF_ALU32_IMM(BPF_RSH, R0, 31),
4807 BPF_EXIT_INSN(),
4808 },
4809 INTERNAL,
4810 { },
4811 { { 0, 1 } },
4812 },
4813 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004814 "ALU_RSH_K: 0x12345678 >> 20 = 0x123",
4815 .u.insns_int = {
4816 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4817 BPF_ALU32_IMM(BPF_RSH, R0, 20),
4818 BPF_EXIT_INSN(),
4819 },
4820 INTERNAL,
4821 { },
4822 { { 0, 0x123 } }
4823 },
4824 {
4825 "ALU_RSH_K: 0x12345678 >> 0 = 0x12345678",
4826 .u.insns_int = {
4827 BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678),
4828 BPF_ALU32_IMM(BPF_RSH, R0, 0),
4829 BPF_EXIT_INSN(),
4830 },
4831 INTERNAL,
4832 { },
4833 { { 0, 0x12345678 } }
4834 },
4835 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004836 "ALU64_RSH_K: 2 >> 1 = 1",
4837 .u.insns_int = {
4838 BPF_LD_IMM64(R0, 2),
4839 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4840 BPF_EXIT_INSN(),
4841 },
4842 INTERNAL,
4843 { },
4844 { { 0, 1 } },
4845 },
4846 {
4847 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4848 .u.insns_int = {
4849 BPF_LD_IMM64(R0, 0x80000000),
4850 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4851 BPF_EXIT_INSN(),
4852 },
4853 INTERNAL,
4854 { },
4855 { { 0, 1 } },
4856 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004857 {
4858 "ALU64_RSH_K: Shift < 32, low word",
4859 .u.insns_int = {
4860 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4861 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4862 BPF_EXIT_INSN(),
4863 },
4864 INTERNAL,
4865 { },
4866 { { 0, 0x56789abc } }
4867 },
4868 {
4869 "ALU64_RSH_K: Shift < 32, high word",
4870 .u.insns_int = {
4871 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4872 BPF_ALU64_IMM(BPF_RSH, R0, 12),
4873 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4874 BPF_EXIT_INSN(),
4875 },
4876 INTERNAL,
4877 { },
4878 { { 0, 0x00081234 } }
4879 },
4880 {
4881 "ALU64_RSH_K: Shift > 32, low word",
4882 .u.insns_int = {
4883 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4884 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4885 BPF_EXIT_INSN(),
4886 },
4887 INTERNAL,
4888 { },
4889 { { 0, 0x08123456 } }
4890 },
4891 {
4892 "ALU64_RSH_K: Shift > 32, high word",
4893 .u.insns_int = {
4894 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4895 BPF_ALU64_IMM(BPF_RSH, R0, 36),
4896 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4897 BPF_EXIT_INSN(),
4898 },
4899 INTERNAL,
4900 { },
4901 { { 0, 0 } }
4902 },
4903 {
4904 "ALU64_RSH_K: Shift == 32, low word",
4905 .u.insns_int = {
4906 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4907 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4908 BPF_EXIT_INSN(),
4909 },
4910 INTERNAL,
4911 { },
4912 { { 0, 0x81234567 } }
4913 },
4914 {
4915 "ALU64_RSH_K: Shift == 32, high word",
4916 .u.insns_int = {
4917 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4918 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4919 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4920 BPF_EXIT_INSN(),
4921 },
4922 INTERNAL,
4923 { },
4924 { { 0, 0 } }
4925 },
4926 {
4927 "ALU64_RSH_K: Zero shift",
4928 .u.insns_int = {
4929 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4930 BPF_ALU64_IMM(BPF_RSH, R0, 0),
4931 BPF_EXIT_INSN(),
4932 },
4933 INTERNAL,
4934 { },
4935 { { 0, 0x89abcdef } }
4936 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004937 /* BPF_ALU | BPF_ARSH | BPF_X */
4938 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02004939 "ALU32_ARSH_X: -1234 >> 7 = -10",
4940 .u.insns_int = {
4941 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
4942 BPF_ALU32_IMM(BPF_MOV, R1, 7),
4943 BPF_ALU32_REG(BPF_ARSH, R0, R1),
4944 BPF_EXIT_INSN(),
4945 },
4946 INTERNAL,
4947 { },
4948 { { 0, -10 } }
4949 },
4950 {
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004951 "ALU64_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
Michael Holzheucffc6422015-05-11 22:22:44 -07004952 .u.insns_int = {
4953 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4954 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4955 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4956 BPF_EXIT_INSN(),
4957 },
4958 INTERNAL,
4959 { },
4960 { { 0, 0xffff00ff } },
4961 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02004962 {
4963 "ALU64_ARSH_X: Shift < 32, low word",
4964 .u.insns_int = {
4965 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4966 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4967 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4968 BPF_EXIT_INSN(),
4969 },
4970 INTERNAL,
4971 { },
4972 { { 0, 0x56789abc } }
4973 },
4974 {
4975 "ALU64_ARSH_X: Shift < 32, high word",
4976 .u.insns_int = {
4977 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4978 BPF_ALU32_IMM(BPF_MOV, R1, 12),
4979 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4980 BPF_ALU64_IMM(BPF_RSH, R0, 32),
4981 BPF_EXIT_INSN(),
4982 },
4983 INTERNAL,
4984 { },
4985 { { 0, 0xfff81234 } }
4986 },
4987 {
4988 "ALU64_ARSH_X: Shift > 32, low word",
4989 .u.insns_int = {
4990 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
4991 BPF_ALU32_IMM(BPF_MOV, R1, 36),
4992 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4993 BPF_EXIT_INSN(),
4994 },
4995 INTERNAL,
4996 { },
4997 { { 0, 0xf8123456 } }
4998 },
4999 {
5000 "ALU64_ARSH_X: Shift > 32, high word",
5001 .u.insns_int = {
5002 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5003 BPF_ALU32_IMM(BPF_MOV, R1, 36),
5004 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5005 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5006 BPF_EXIT_INSN(),
5007 },
5008 INTERNAL,
5009 { },
5010 { { 0, -1 } }
5011 },
5012 {
5013 "ALU64_ARSH_X: Shift == 32, low word",
5014 .u.insns_int = {
5015 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5016 BPF_ALU32_IMM(BPF_MOV, R1, 32),
5017 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5018 BPF_EXIT_INSN(),
5019 },
5020 INTERNAL,
5021 { },
5022 { { 0, 0x81234567 } }
5023 },
5024 {
5025 "ALU64_ARSH_X: Shift == 32, high word",
5026 .u.insns_int = {
5027 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5028 BPF_ALU32_IMM(BPF_MOV, R1, 32),
5029 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5030 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5031 BPF_EXIT_INSN(),
5032 },
5033 INTERNAL,
5034 { },
5035 { { 0, -1 } }
5036 },
5037 {
5038 "ALU64_ARSH_X: Zero shift, low word",
5039 .u.insns_int = {
5040 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5041 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5042 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5043 BPF_EXIT_INSN(),
5044 },
5045 INTERNAL,
5046 { },
5047 { { 0, 0x89abcdef } }
5048 },
5049 {
5050 "ALU64_ARSH_X: Zero shift, high word",
5051 .u.insns_int = {
5052 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5053 BPF_ALU32_IMM(BPF_MOV, R1, 0),
5054 BPF_ALU64_REG(BPF_ARSH, R0, R1),
5055 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5056 BPF_EXIT_INSN(),
5057 },
5058 INTERNAL,
5059 { },
5060 { { 0, 0x81234567 } }
5061 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005062 /* BPF_ALU | BPF_ARSH | BPF_K */
5063 {
Johan Almbladh0f2fca12021-08-09 11:18:20 +02005064 "ALU32_ARSH_K: -1234 >> 7 = -10",
5065 .u.insns_int = {
5066 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5067 BPF_ALU32_IMM(BPF_ARSH, R0, 7),
5068 BPF_EXIT_INSN(),
5069 },
5070 INTERNAL,
5071 { },
5072 { { 0, -10 } }
5073 },
5074 {
5075 "ALU32_ARSH_K: -1234 >> 0 = -1234",
5076 .u.insns_int = {
5077 BPF_ALU32_IMM(BPF_MOV, R0, -1234),
5078 BPF_ALU32_IMM(BPF_ARSH, R0, 0),
5079 BPF_EXIT_INSN(),
5080 },
5081 INTERNAL,
5082 { },
5083 { { 0, -1234 } }
5084 },
5085 {
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005086 "ALU64_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
Michael Holzheucffc6422015-05-11 22:22:44 -07005087 .u.insns_int = {
5088 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
5089 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
5090 BPF_EXIT_INSN(),
5091 },
5092 INTERNAL,
5093 { },
5094 { { 0, 0xffff00ff } },
5095 },
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005096 {
5097 "ALU64_ARSH_K: Shift < 32, low word",
5098 .u.insns_int = {
5099 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5100 BPF_ALU64_IMM(BPF_RSH, R0, 12),
5101 BPF_EXIT_INSN(),
5102 },
5103 INTERNAL,
5104 { },
5105 { { 0, 0x56789abc } }
5106 },
5107 {
5108 "ALU64_ARSH_K: Shift < 32, high word",
5109 .u.insns_int = {
5110 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5111 BPF_ALU64_IMM(BPF_ARSH, R0, 12),
5112 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5113 BPF_EXIT_INSN(),
5114 },
5115 INTERNAL,
5116 { },
5117 { { 0, 0xfff81234 } }
5118 },
5119 {
5120 "ALU64_ARSH_K: Shift > 32, low word",
5121 .u.insns_int = {
5122 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5123 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5124 BPF_EXIT_INSN(),
5125 },
5126 INTERNAL,
5127 { },
5128 { { 0, 0xf8123456 } }
5129 },
5130 {
5131 "ALU64_ARSH_K: Shift > 32, high word",
5132 .u.insns_int = {
5133 BPF_LD_IMM64(R0, 0xf123456789abcdefLL),
5134 BPF_ALU64_IMM(BPF_ARSH, R0, 36),
5135 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5136 BPF_EXIT_INSN(),
5137 },
5138 INTERNAL,
5139 { },
5140 { { 0, -1 } }
5141 },
5142 {
5143 "ALU64_ARSH_K: Shift == 32, low word",
5144 .u.insns_int = {
5145 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5146 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5147 BPF_EXIT_INSN(),
5148 },
5149 INTERNAL,
5150 { },
5151 { { 0, 0x81234567 } }
5152 },
5153 {
5154 "ALU64_ARSH_K: Shift == 32, high word",
5155 .u.insns_int = {
5156 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5157 BPF_ALU64_IMM(BPF_ARSH, R0, 32),
5158 BPF_ALU64_IMM(BPF_RSH, R0, 32),
5159 BPF_EXIT_INSN(),
5160 },
5161 INTERNAL,
5162 { },
5163 { { 0, -1 } }
5164 },
5165 {
Colin Ian King1bda52f2021-08-15 22:39:50 +01005166 "ALU64_ARSH_K: Zero shift",
Johan Almbladh3b9890e2021-08-09 11:18:21 +02005167 .u.insns_int = {
5168 BPF_LD_IMM64(R0, 0x8123456789abcdefLL),
5169 BPF_ALU64_IMM(BPF_ARSH, R0, 0),
5170 BPF_EXIT_INSN(),
5171 },
5172 INTERNAL,
5173 { },
5174 { { 0, 0x89abcdef } }
5175 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005176 /* BPF_ALU | BPF_NEG */
5177 {
5178 "ALU_NEG: -(3) = -3",
5179 .u.insns_int = {
5180 BPF_ALU32_IMM(BPF_MOV, R0, 3),
5181 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5182 BPF_EXIT_INSN(),
5183 },
5184 INTERNAL,
5185 { },
5186 { { 0, -3 } },
5187 },
5188 {
5189 "ALU_NEG: -(-3) = 3",
5190 .u.insns_int = {
5191 BPF_ALU32_IMM(BPF_MOV, R0, -3),
5192 BPF_ALU32_IMM(BPF_NEG, R0, 0),
5193 BPF_EXIT_INSN(),
5194 },
5195 INTERNAL,
5196 { },
5197 { { 0, 3 } },
5198 },
5199 {
5200 "ALU64_NEG: -(3) = -3",
5201 .u.insns_int = {
5202 BPF_LD_IMM64(R0, 3),
5203 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5204 BPF_EXIT_INSN(),
5205 },
5206 INTERNAL,
5207 { },
5208 { { 0, -3 } },
5209 },
5210 {
5211 "ALU64_NEG: -(-3) = 3",
5212 .u.insns_int = {
5213 BPF_LD_IMM64(R0, -3),
5214 BPF_ALU64_IMM(BPF_NEG, R0, 0),
5215 BPF_EXIT_INSN(),
5216 },
5217 INTERNAL,
5218 { },
5219 { { 0, 3 } },
5220 },
5221 /* BPF_ALU | BPF_END | BPF_FROM_BE */
5222 {
5223 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
5224 .u.insns_int = {
5225 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5226 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
5227 BPF_EXIT_INSN(),
5228 },
5229 INTERNAL,
5230 { },
5231 { { 0, cpu_to_be16(0xcdef) } },
5232 },
5233 {
5234 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
5235 .u.insns_int = {
5236 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5237 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07005238 BPF_ALU64_REG(BPF_MOV, R1, R0),
5239 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5240 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07005241 BPF_EXIT_INSN(),
5242 },
5243 INTERNAL,
5244 { },
5245 { { 0, cpu_to_be32(0x89abcdef) } },
5246 },
5247 {
5248 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
5249 .u.insns_int = {
5250 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5251 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
5252 BPF_EXIT_INSN(),
5253 },
5254 INTERNAL,
5255 { },
5256 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
5257 },
5258 /* BPF_ALU | BPF_END | BPF_FROM_LE */
5259 {
5260 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
5261 .u.insns_int = {
5262 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5263 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
5264 BPF_EXIT_INSN(),
5265 },
5266 INTERNAL,
5267 { },
5268 { { 0, cpu_to_le16(0xcdef) } },
5269 },
5270 {
5271 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
5272 .u.insns_int = {
5273 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5274 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07005275 BPF_ALU64_REG(BPF_MOV, R1, R0),
5276 BPF_ALU64_IMM(BPF_RSH, R1, 32),
5277 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07005278 BPF_EXIT_INSN(),
5279 },
5280 INTERNAL,
5281 { },
5282 { { 0, cpu_to_le32(0x89abcdef) } },
5283 },
5284 {
5285 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
5286 .u.insns_int = {
5287 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
5288 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
5289 BPF_EXIT_INSN(),
5290 },
5291 INTERNAL,
5292 { },
5293 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
5294 },
5295 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
5296 {
5297 "ST_MEM_B: Store/Load byte: max negative",
5298 .u.insns_int = {
5299 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5300 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
5301 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5302 BPF_EXIT_INSN(),
5303 },
5304 INTERNAL,
5305 { },
5306 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005307 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005308 },
5309 {
5310 "ST_MEM_B: Store/Load byte: max positive",
5311 .u.insns_int = {
5312 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5313 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
5314 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5315 BPF_EXIT_INSN(),
5316 },
5317 INTERNAL,
5318 { },
5319 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005320 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005321 },
5322 {
5323 "STX_MEM_B: Store/Load byte: max negative",
5324 .u.insns_int = {
5325 BPF_LD_IMM64(R0, 0),
5326 BPF_LD_IMM64(R1, 0xffLL),
5327 BPF_STX_MEM(BPF_B, R10, R1, -40),
5328 BPF_LDX_MEM(BPF_B, R0, R10, -40),
5329 BPF_EXIT_INSN(),
5330 },
5331 INTERNAL,
5332 { },
5333 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005334 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005335 },
5336 {
5337 "ST_MEM_H: Store/Load half word: max negative",
5338 .u.insns_int = {
5339 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5340 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
5341 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5342 BPF_EXIT_INSN(),
5343 },
5344 INTERNAL,
5345 { },
5346 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005347 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005348 },
5349 {
5350 "ST_MEM_H: Store/Load half word: max positive",
5351 .u.insns_int = {
5352 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5353 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
5354 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5355 BPF_EXIT_INSN(),
5356 },
5357 INTERNAL,
5358 { },
5359 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005360 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005361 },
5362 {
5363 "STX_MEM_H: Store/Load half word: max negative",
5364 .u.insns_int = {
5365 BPF_LD_IMM64(R0, 0),
5366 BPF_LD_IMM64(R1, 0xffffLL),
5367 BPF_STX_MEM(BPF_H, R10, R1, -40),
5368 BPF_LDX_MEM(BPF_H, R0, R10, -40),
5369 BPF_EXIT_INSN(),
5370 },
5371 INTERNAL,
5372 { },
5373 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005374 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005375 },
5376 {
5377 "ST_MEM_W: Store/Load word: max negative",
5378 .u.insns_int = {
5379 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5380 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
5381 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5382 BPF_EXIT_INSN(),
5383 },
5384 INTERNAL,
5385 { },
5386 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005387 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005388 },
5389 {
5390 "ST_MEM_W: Store/Load word: max positive",
5391 .u.insns_int = {
5392 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5393 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
5394 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5395 BPF_EXIT_INSN(),
5396 },
5397 INTERNAL,
5398 { },
5399 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005400 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005401 },
5402 {
5403 "STX_MEM_W: Store/Load word: max negative",
5404 .u.insns_int = {
5405 BPF_LD_IMM64(R0, 0),
5406 BPF_LD_IMM64(R1, 0xffffffffLL),
5407 BPF_STX_MEM(BPF_W, R10, R1, -40),
5408 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5409 BPF_EXIT_INSN(),
5410 },
5411 INTERNAL,
5412 { },
5413 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005414 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005415 },
5416 {
5417 "ST_MEM_DW: Store/Load double word: max negative",
5418 .u.insns_int = {
5419 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5420 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5421 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5422 BPF_EXIT_INSN(),
5423 },
5424 INTERNAL,
5425 { },
5426 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005427 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005428 },
5429 {
5430 "ST_MEM_DW: Store/Load double word: max negative 2",
5431 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07005432 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
5433 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07005434 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
5435 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
5436 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
5437 BPF_MOV32_IMM(R0, 2),
5438 BPF_EXIT_INSN(),
5439 BPF_MOV32_IMM(R0, 1),
5440 BPF_EXIT_INSN(),
5441 },
5442 INTERNAL,
5443 { },
5444 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005445 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005446 },
5447 {
5448 "ST_MEM_DW: Store/Load double word: max positive",
5449 .u.insns_int = {
5450 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5451 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
5452 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5453 BPF_EXIT_INSN(),
5454 },
5455 INTERNAL,
5456 { },
5457 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005458 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005459 },
5460 {
5461 "STX_MEM_DW: Store/Load double word: max negative",
5462 .u.insns_int = {
5463 BPF_LD_IMM64(R0, 0),
5464 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
Johan Almbladhae7f4702021-07-21 12:40:58 +02005465 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5466 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07005467 BPF_EXIT_INSN(),
5468 },
5469 INTERNAL,
5470 { },
5471 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07005472 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07005473 },
Johan Almbladhe5009b42021-08-09 11:18:24 +02005474 {
5475 "STX_MEM_DW: Store double word: first word in memory",
5476 .u.insns_int = {
5477 BPF_LD_IMM64(R0, 0),
5478 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5479 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5480 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5481 BPF_EXIT_INSN(),
5482 },
5483 INTERNAL,
5484 { },
5485#ifdef __BIG_ENDIAN
5486 { { 0, 0x01234567 } },
5487#else
5488 { { 0, 0x89abcdef } },
5489#endif
5490 .stack_depth = 40,
5491 },
5492 {
5493 "STX_MEM_DW: Store double word: second word in memory",
5494 .u.insns_int = {
5495 BPF_LD_IMM64(R0, 0),
5496 BPF_LD_IMM64(R1, 0x0123456789abcdefLL),
5497 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5498 BPF_LDX_MEM(BPF_W, R0, R10, -36),
5499 BPF_EXIT_INSN(),
5500 },
5501 INTERNAL,
5502 { },
5503#ifdef __BIG_ENDIAN
5504 { { 0, 0x89abcdef } },
5505#else
5506 { { 0, 0x01234567 } },
5507#endif
5508 .stack_depth = 40,
5509 },
Brendan Jackman91c960b2021-01-14 18:17:44 +00005510 /* BPF_STX | BPF_ATOMIC | BPF_W/DW */
Michael Holzheucffc6422015-05-11 22:22:44 -07005511 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005512 "STX_XADD_W: X + 1 + 1 + 1 + ...",
5513 { },
5514 INTERNAL,
5515 { },
5516 { { 0, 4134 } },
5517 .fill_helper = bpf_fill_stxw,
5518 },
5519 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02005520 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
5521 { },
5522 INTERNAL,
5523 { },
5524 { { 0, 4134 } },
5525 .fill_helper = bpf_fill_stxdw,
5526 },
Johan Almbladhe4517b32021-08-09 11:18:27 +02005527 /*
5528 * Exhaustive tests of atomic operation variants.
5529 * Individual tests are expanded from template macros for all
5530 * combinations of ALU operation, word size and fetching.
5531 */
5532#define BPF_ATOMIC_OP_TEST1(width, op, logic, old, update, result) \
5533{ \
5534 "BPF_ATOMIC | " #width ", " #op ": Test: " \
5535 #old " " #logic " " #update " = " #result, \
5536 .u.insns_int = { \
5537 BPF_ALU32_IMM(BPF_MOV, R5, update), \
5538 BPF_ST_MEM(width, R10, -40, old), \
5539 BPF_ATOMIC_OP(width, op, R10, R5, -40), \
5540 BPF_LDX_MEM(width, R0, R10, -40), \
5541 BPF_EXIT_INSN(), \
5542 }, \
5543 INTERNAL, \
5544 { }, \
5545 { { 0, result } }, \
5546 .stack_depth = 40, \
5547}
5548#define BPF_ATOMIC_OP_TEST2(width, op, logic, old, update, result) \
5549{ \
5550 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r10: " \
5551 #old " " #logic " " #update " = " #result, \
5552 .u.insns_int = { \
5553 BPF_ALU64_REG(BPF_MOV, R1, R10), \
5554 BPF_ALU32_IMM(BPF_MOV, R0, update), \
5555 BPF_ST_MEM(BPF_W, R10, -40, old), \
5556 BPF_ATOMIC_OP(width, op, R10, R0, -40), \
5557 BPF_ALU64_REG(BPF_MOV, R0, R10), \
5558 BPF_ALU64_REG(BPF_SUB, R0, R1), \
5559 BPF_EXIT_INSN(), \
5560 }, \
5561 INTERNAL, \
5562 { }, \
5563 { { 0, 0 } }, \
5564 .stack_depth = 40, \
5565}
5566#define BPF_ATOMIC_OP_TEST3(width, op, logic, old, update, result) \
5567{ \
5568 "BPF_ATOMIC | " #width ", " #op ": Test side effects, r0: " \
5569 #old " " #logic " " #update " = " #result, \
5570 .u.insns_int = { \
5571 BPF_ALU64_REG(BPF_MOV, R0, R10), \
5572 BPF_ALU32_IMM(BPF_MOV, R1, update), \
5573 BPF_ST_MEM(width, R10, -40, old), \
5574 BPF_ATOMIC_OP(width, op, R10, R1, -40), \
5575 BPF_ALU64_REG(BPF_SUB, R0, R10), \
5576 BPF_EXIT_INSN(), \
5577 }, \
5578 INTERNAL, \
5579 { }, \
5580 { { 0, 0 } }, \
5581 .stack_depth = 40, \
5582}
5583#define BPF_ATOMIC_OP_TEST4(width, op, logic, old, update, result) \
5584{ \
5585 "BPF_ATOMIC | " #width ", " #op ": Test fetch: " \
5586 #old " " #logic " " #update " = " #result, \
5587 .u.insns_int = { \
5588 BPF_ALU32_IMM(BPF_MOV, R3, update), \
5589 BPF_ST_MEM(width, R10, -40, old), \
5590 BPF_ATOMIC_OP(width, op, R10, R3, -40), \
5591 BPF_ALU64_REG(BPF_MOV, R0, R3), \
5592 BPF_EXIT_INSN(), \
5593 }, \
5594 INTERNAL, \
5595 { }, \
5596 { { 0, (op) & BPF_FETCH ? old : update } }, \
5597 .stack_depth = 40, \
5598}
5599 /* BPF_ATOMIC | BPF_W: BPF_ADD */
5600 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5601 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5602 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5603 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd),
5604 /* BPF_ATOMIC | BPF_W: BPF_ADD | BPF_FETCH */
5605 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5606 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5607 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5608 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5609 /* BPF_ATOMIC | BPF_DW: BPF_ADD */
5610 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5611 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5612 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5613 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd),
5614 /* BPF_ATOMIC | BPF_DW: BPF_ADD | BPF_FETCH */
5615 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5616 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5617 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5618 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd),
5619 /* BPF_ATOMIC | BPF_W: BPF_AND */
5620 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5621 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5622 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5623 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02),
5624 /* BPF_ATOMIC | BPF_W: BPF_AND | BPF_FETCH */
5625 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5626 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5627 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5628 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5629 /* BPF_ATOMIC | BPF_DW: BPF_AND */
5630 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5631 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5632 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5633 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02),
5634 /* BPF_ATOMIC | BPF_DW: BPF_AND | BPF_FETCH */
5635 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5636 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5637 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5638 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02),
5639 /* BPF_ATOMIC | BPF_W: BPF_OR */
5640 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5641 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5642 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5643 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb),
5644 /* BPF_ATOMIC | BPF_W: BPF_OR | BPF_FETCH */
5645 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5646 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5647 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5648 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5649 /* BPF_ATOMIC | BPF_DW: BPF_OR */
5650 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5651 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5652 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5653 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb),
5654 /* BPF_ATOMIC | BPF_DW: BPF_OR | BPF_FETCH */
5655 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5656 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5657 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5658 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb),
5659 /* BPF_ATOMIC | BPF_W: BPF_XOR */
5660 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5661 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5662 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5663 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5664 /* BPF_ATOMIC | BPF_W: BPF_XOR | BPF_FETCH */
5665 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5666 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5667 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5668 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5669 /* BPF_ATOMIC | BPF_DW: BPF_XOR */
5670 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5671 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5672 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5673 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9),
5674 /* BPF_ATOMIC | BPF_DW: BPF_XOR | BPF_FETCH */
5675 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5676 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5677 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5678 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9),
5679 /* BPF_ATOMIC | BPF_W: BPF_XCHG */
5680 BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5681 BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5682 BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5683 BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5684 /* BPF_ATOMIC | BPF_DW: BPF_XCHG */
5685 BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5686 BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5687 BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5688 BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab),
5689#undef BPF_ATOMIC_OP_TEST1
5690#undef BPF_ATOMIC_OP_TEST2
5691#undef BPF_ATOMIC_OP_TEST3
5692#undef BPF_ATOMIC_OP_TEST4
Johan Almbladh6a3b24c2021-08-09 11:18:28 +02005693 /* BPF_ATOMIC | BPF_W, BPF_CMPXCHG */
5694 {
5695 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful return",
5696 .u.insns_int = {
5697 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5698 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
5699 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5700 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5701 BPF_EXIT_INSN(),
5702 },
5703 INTERNAL,
5704 { },
5705 { { 0, 0x01234567 } },
5706 .stack_depth = 40,
5707 },
5708 {
5709 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful store",
5710 .u.insns_int = {
5711 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5712 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
5713 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5714 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5715 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5716 BPF_EXIT_INSN(),
5717 },
5718 INTERNAL,
5719 { },
5720 { { 0, 0x89abcdef } },
5721 .stack_depth = 40,
5722 },
5723 {
5724 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure return",
5725 .u.insns_int = {
5726 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5727 BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210),
5728 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5729 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5730 BPF_EXIT_INSN(),
5731 },
5732 INTERNAL,
5733 { },
5734 { { 0, 0x01234567 } },
5735 .stack_depth = 40,
5736 },
5737 {
5738 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure store",
5739 .u.insns_int = {
5740 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5741 BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210),
5742 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5743 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5744 BPF_LDX_MEM(BPF_W, R0, R10, -40),
5745 BPF_EXIT_INSN(),
5746 },
5747 INTERNAL,
5748 { },
5749 { { 0, 0x01234567 } },
5750 .stack_depth = 40,
5751 },
5752 {
5753 "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test side effects",
5754 .u.insns_int = {
5755 BPF_ST_MEM(BPF_W, R10, -40, 0x01234567),
5756 BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567),
5757 BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef),
5758 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5759 BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40),
5760 BPF_ALU32_REG(BPF_MOV, R0, R3),
5761 BPF_EXIT_INSN(),
5762 },
5763 INTERNAL,
5764 { },
5765 { { 0, 0x89abcdef } },
5766 .stack_depth = 40,
5767 },
5768 /* BPF_ATOMIC | BPF_DW, BPF_CMPXCHG */
5769 {
5770 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful return",
5771 .u.insns_int = {
5772 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5773 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5774 BPF_ALU64_REG(BPF_MOV, R0, R1),
5775 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5776 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5777 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
5778 BPF_ALU64_REG(BPF_SUB, R0, R1),
5779 BPF_EXIT_INSN(),
5780 },
5781 INTERNAL,
5782 { },
5783 { { 0, 0 } },
5784 .stack_depth = 40,
5785 },
5786 {
5787 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful store",
5788 .u.insns_int = {
5789 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5790 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5791 BPF_ALU64_REG(BPF_MOV, R0, R1),
5792 BPF_STX_MEM(BPF_DW, R10, R0, -40),
5793 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5794 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5795 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
5796 BPF_ALU64_REG(BPF_SUB, R0, R2),
5797 BPF_EXIT_INSN(),
5798 },
5799 INTERNAL,
5800 { },
5801 { { 0, 0 } },
5802 .stack_depth = 40,
5803 },
5804 {
5805 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure return",
5806 .u.insns_int = {
5807 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5808 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5809 BPF_ALU64_REG(BPF_MOV, R0, R1),
5810 BPF_ALU64_IMM(BPF_ADD, R0, 1),
5811 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5812 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5813 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
5814 BPF_ALU64_REG(BPF_SUB, R0, R1),
5815 BPF_EXIT_INSN(),
5816 },
5817 INTERNAL,
5818 { },
5819 { { 0, 0 } },
5820 .stack_depth = 40,
5821 },
5822 {
5823 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure store",
5824 .u.insns_int = {
5825 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5826 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5827 BPF_ALU64_REG(BPF_MOV, R0, R1),
5828 BPF_ALU64_IMM(BPF_ADD, R0, 1),
5829 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5830 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5831 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
5832 BPF_JMP_REG(BPF_JNE, R0, R1, 1),
5833 BPF_ALU64_REG(BPF_SUB, R0, R1),
5834 BPF_EXIT_INSN(),
5835 },
5836 INTERNAL,
5837 { },
5838 { { 0, 0 } },
5839 .stack_depth = 40,
5840 },
5841 {
5842 "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test side effects",
5843 .u.insns_int = {
5844 BPF_LD_IMM64(R1, 0x0123456789abcdefULL),
5845 BPF_LD_IMM64(R2, 0xfecdba9876543210ULL),
5846 BPF_ALU64_REG(BPF_MOV, R0, R1),
5847 BPF_STX_MEM(BPF_DW, R10, R1, -40),
5848 BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40),
5849 BPF_LD_IMM64(R0, 0xfecdba9876543210ULL),
5850 BPF_JMP_REG(BPF_JNE, R0, R2, 1),
5851 BPF_ALU64_REG(BPF_SUB, R0, R2),
5852 BPF_EXIT_INSN(),
5853 },
5854 INTERNAL,
5855 { },
5856 { { 0, 0 } },
5857 .stack_depth = 40,
5858 },
Johan Almbladhb55dfa82021-08-09 11:18:16 +02005859 /* BPF_JMP32 | BPF_JEQ | BPF_K */
5860 {
5861 "JMP32_JEQ_K: Small immediate",
5862 .u.insns_int = {
5863 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5864 BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
5865 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5866 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5867 BPF_EXIT_INSN(),
5868 },
5869 INTERNAL,
5870 { },
5871 { { 0, 123 } }
5872 },
5873 {
5874 "JMP32_JEQ_K: Large immediate",
5875 .u.insns_int = {
5876 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5877 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1),
5878 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1),
5879 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5880 BPF_EXIT_INSN(),
5881 },
5882 INTERNAL,
5883 { },
5884 { { 0, 12345678 } }
5885 },
5886 {
5887 "JMP32_JEQ_K: negative immediate",
5888 .u.insns_int = {
5889 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5890 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
5891 BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1),
5892 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5893 BPF_EXIT_INSN(),
5894 },
5895 INTERNAL,
5896 { },
5897 { { 0, -123 } }
5898 },
5899 /* BPF_JMP32 | BPF_JEQ | BPF_X */
5900 {
5901 "JMP32_JEQ_X",
5902 .u.insns_int = {
5903 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5904 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5905 BPF_JMP32_REG(BPF_JEQ, R0, R1, 2),
5906 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5907 BPF_JMP32_REG(BPF_JEQ, R0, R1, 1),
5908 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5909 BPF_EXIT_INSN(),
5910 },
5911 INTERNAL,
5912 { },
5913 { { 0, 1234 } }
5914 },
5915 /* BPF_JMP32 | BPF_JNE | BPF_K */
5916 {
5917 "JMP32_JNE_K: Small immediate",
5918 .u.insns_int = {
5919 BPF_ALU32_IMM(BPF_MOV, R0, 123),
5920 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5921 BPF_JMP32_IMM(BPF_JNE, R0, 321, 1),
5922 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5923 BPF_EXIT_INSN(),
5924 },
5925 INTERNAL,
5926 { },
5927 { { 0, 123 } }
5928 },
5929 {
5930 "JMP32_JNE_K: Large immediate",
5931 .u.insns_int = {
5932 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
5933 BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1),
5934 BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1),
5935 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5936 BPF_EXIT_INSN(),
5937 },
5938 INTERNAL,
5939 { },
5940 { { 0, 12345678 } }
5941 },
5942 {
5943 "JMP32_JNE_K: negative immediate",
5944 .u.insns_int = {
5945 BPF_ALU32_IMM(BPF_MOV, R0, -123),
5946 BPF_JMP32_IMM(BPF_JNE, R0, -123, 1),
5947 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
5948 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5949 BPF_EXIT_INSN(),
5950 },
5951 INTERNAL,
5952 { },
5953 { { 0, -123 } }
5954 },
5955 /* BPF_JMP32 | BPF_JNE | BPF_X */
5956 {
5957 "JMP32_JNE_X",
5958 .u.insns_int = {
5959 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
5960 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
5961 BPF_JMP32_REG(BPF_JNE, R0, R1, 2),
5962 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
5963 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
5964 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5965 BPF_EXIT_INSN(),
5966 },
5967 INTERNAL,
5968 { },
5969 { { 0, 1234 } }
5970 },
5971 /* BPF_JMP32 | BPF_JSET | BPF_K */
5972 {
5973 "JMP32_JSET_K: Small immediate",
5974 .u.insns_int = {
5975 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5976 BPF_JMP32_IMM(BPF_JSET, R0, 2, 1),
5977 BPF_JMP32_IMM(BPF_JSET, R0, 3, 1),
5978 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5979 BPF_EXIT_INSN(),
5980 },
5981 INTERNAL,
5982 { },
5983 { { 0, 1 } }
5984 },
5985 {
5986 "JMP32_JSET_K: Large immediate",
5987 .u.insns_int = {
5988 BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000),
5989 BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1),
5990 BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1),
5991 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5992 BPF_EXIT_INSN(),
5993 },
5994 INTERNAL,
5995 { },
5996 { { 0, 0x40000000 } }
5997 },
5998 {
5999 "JMP32_JSET_K: negative immediate",
6000 .u.insns_int = {
6001 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6002 BPF_JMP32_IMM(BPF_JSET, R0, -1, 1),
6003 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6004 BPF_EXIT_INSN(),
6005 },
6006 INTERNAL,
6007 { },
6008 { { 0, -123 } }
6009 },
6010 /* BPF_JMP32 | BPF_JSET | BPF_X */
6011 {
6012 "JMP32_JSET_X",
6013 .u.insns_int = {
6014 BPF_ALU32_IMM(BPF_MOV, R0, 8),
6015 BPF_ALU32_IMM(BPF_MOV, R1, 7),
6016 BPF_JMP32_REG(BPF_JSET, R0, R1, 2),
6017 BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2),
6018 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
6019 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6020 BPF_EXIT_INSN(),
6021 },
6022 INTERNAL,
6023 { },
6024 { { 0, 8 } }
6025 },
6026 /* BPF_JMP32 | BPF_JGT | BPF_K */
6027 {
6028 "JMP32_JGT_K: Small immediate",
6029 .u.insns_int = {
6030 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6031 BPF_JMP32_IMM(BPF_JGT, R0, 123, 1),
6032 BPF_JMP32_IMM(BPF_JGT, R0, 122, 1),
6033 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6034 BPF_EXIT_INSN(),
6035 },
6036 INTERNAL,
6037 { },
6038 { { 0, 123 } }
6039 },
6040 {
6041 "JMP32_JGT_K: Large immediate",
6042 .u.insns_int = {
6043 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6044 BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1),
6045 BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1),
6046 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6047 BPF_EXIT_INSN(),
6048 },
6049 INTERNAL,
6050 { },
6051 { { 0, 0xfffffffe } }
6052 },
6053 /* BPF_JMP32 | BPF_JGT | BPF_X */
6054 {
6055 "JMP32_JGT_X",
6056 .u.insns_int = {
6057 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6058 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6059 BPF_JMP32_REG(BPF_JGT, R0, R1, 2),
6060 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6061 BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
6062 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6063 BPF_EXIT_INSN(),
6064 },
6065 INTERNAL,
6066 { },
6067 { { 0, 0xfffffffe } }
6068 },
6069 /* BPF_JMP32 | BPF_JGE | BPF_K */
6070 {
6071 "JMP32_JGE_K: Small immediate",
6072 .u.insns_int = {
6073 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6074 BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
6075 BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
6076 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6077 BPF_EXIT_INSN(),
6078 },
6079 INTERNAL,
6080 { },
6081 { { 0, 123 } }
6082 },
6083 {
6084 "JMP32_JGE_K: Large immediate",
6085 .u.insns_int = {
6086 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6087 BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
6088 BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
6089 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6090 BPF_EXIT_INSN(),
6091 },
6092 INTERNAL,
6093 { },
6094 { { 0, 0xfffffffe } }
6095 },
6096 /* BPF_JMP32 | BPF_JGE | BPF_X */
6097 {
6098 "JMP32_JGE_X",
6099 .u.insns_int = {
6100 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6101 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6102 BPF_JMP32_REG(BPF_JGE, R0, R1, 2),
6103 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
6104 BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
6105 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6106 BPF_EXIT_INSN(),
6107 },
6108 INTERNAL,
6109 { },
6110 { { 0, 0xfffffffe } }
6111 },
6112 /* BPF_JMP32 | BPF_JLT | BPF_K */
6113 {
6114 "JMP32_JLT_K: Small immediate",
6115 .u.insns_int = {
6116 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6117 BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
6118 BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
6119 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6120 BPF_EXIT_INSN(),
6121 },
6122 INTERNAL,
6123 { },
6124 { { 0, 123 } }
6125 },
6126 {
6127 "JMP32_JLT_K: Large immediate",
6128 .u.insns_int = {
6129 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6130 BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
6131 BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
6132 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6133 BPF_EXIT_INSN(),
6134 },
6135 INTERNAL,
6136 { },
6137 { { 0, 0xfffffffe } }
6138 },
6139 /* BPF_JMP32 | BPF_JLT | BPF_X */
6140 {
6141 "JMP32_JLT_X",
6142 .u.insns_int = {
6143 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6144 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6145 BPF_JMP32_REG(BPF_JLT, R0, R1, 2),
6146 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
6147 BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
6148 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6149 BPF_EXIT_INSN(),
6150 },
6151 INTERNAL,
6152 { },
6153 { { 0, 0xfffffffe } }
6154 },
6155 /* BPF_JMP32 | BPF_JLE | BPF_K */
6156 {
6157 "JMP32_JLE_K: Small immediate",
6158 .u.insns_int = {
6159 BPF_ALU32_IMM(BPF_MOV, R0, 123),
6160 BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
6161 BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
6162 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6163 BPF_EXIT_INSN(),
6164 },
6165 INTERNAL,
6166 { },
6167 { { 0, 123 } }
6168 },
6169 {
6170 "JMP32_JLE_K: Large immediate",
6171 .u.insns_int = {
6172 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6173 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
6174 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
6175 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6176 BPF_EXIT_INSN(),
6177 },
6178 INTERNAL,
6179 { },
6180 { { 0, 0xfffffffe } }
6181 },
6182 /* BPF_JMP32 | BPF_JLE | BPF_X */
6183 {
6184 "JMP32_JLE_X",
6185 .u.insns_int = {
6186 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
6187 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
6188 BPF_JMP32_REG(BPF_JLE, R0, R1, 2),
6189 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
6190 BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
6191 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6192 BPF_EXIT_INSN(),
6193 },
6194 INTERNAL,
6195 { },
6196 { { 0, 0xfffffffe } }
6197 },
6198 /* BPF_JMP32 | BPF_JSGT | BPF_K */
6199 {
6200 "JMP32_JSGT_K: Small immediate",
6201 .u.insns_int = {
6202 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6203 BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
6204 BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
6205 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6206 BPF_EXIT_INSN(),
6207 },
6208 INTERNAL,
6209 { },
6210 { { 0, -123 } }
6211 },
6212 {
6213 "JMP32_JSGT_K: Large immediate",
6214 .u.insns_int = {
6215 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6216 BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
6217 BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
6218 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6219 BPF_EXIT_INSN(),
6220 },
6221 INTERNAL,
6222 { },
6223 { { 0, -12345678 } }
6224 },
6225 /* BPF_JMP32 | BPF_JSGT | BPF_X */
6226 {
6227 "JMP32_JSGT_X",
6228 .u.insns_int = {
6229 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6230 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6231 BPF_JMP32_REG(BPF_JSGT, R0, R1, 2),
6232 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6233 BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
6234 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6235 BPF_EXIT_INSN(),
6236 },
6237 INTERNAL,
6238 { },
6239 { { 0, -12345678 } }
6240 },
6241 /* BPF_JMP32 | BPF_JSGE | BPF_K */
6242 {
6243 "JMP32_JSGE_K: Small immediate",
6244 .u.insns_int = {
6245 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6246 BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
6247 BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
6248 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6249 BPF_EXIT_INSN(),
6250 },
6251 INTERNAL,
6252 { },
6253 { { 0, -123 } }
6254 },
6255 {
6256 "JMP32_JSGE_K: Large immediate",
6257 .u.insns_int = {
6258 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6259 BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
6260 BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
6261 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6262 BPF_EXIT_INSN(),
6263 },
6264 INTERNAL,
6265 { },
6266 { { 0, -12345678 } }
6267 },
6268 /* BPF_JMP32 | BPF_JSGE | BPF_X */
6269 {
6270 "JMP32_JSGE_X",
6271 .u.insns_int = {
6272 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6273 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6274 BPF_JMP32_REG(BPF_JSGE, R0, R1, 2),
6275 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6276 BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
6277 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6278 BPF_EXIT_INSN(),
6279 },
6280 INTERNAL,
6281 { },
6282 { { 0, -12345678 } }
6283 },
6284 /* BPF_JMP32 | BPF_JSLT | BPF_K */
6285 {
6286 "JMP32_JSLT_K: Small immediate",
6287 .u.insns_int = {
6288 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6289 BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
6290 BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
6291 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6292 BPF_EXIT_INSN(),
6293 },
6294 INTERNAL,
6295 { },
6296 { { 0, -123 } }
6297 },
6298 {
6299 "JMP32_JSLT_K: Large immediate",
6300 .u.insns_int = {
6301 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6302 BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
6303 BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
6304 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6305 BPF_EXIT_INSN(),
6306 },
6307 INTERNAL,
6308 { },
6309 { { 0, -12345678 } }
6310 },
6311 /* BPF_JMP32 | BPF_JSLT | BPF_X */
6312 {
6313 "JMP32_JSLT_X",
6314 .u.insns_int = {
6315 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6316 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6317 BPF_JMP32_REG(BPF_JSLT, R0, R1, 2),
6318 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
6319 BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
6320 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6321 BPF_EXIT_INSN(),
6322 },
6323 INTERNAL,
6324 { },
6325 { { 0, -12345678 } }
6326 },
6327 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6328 {
6329 "JMP32_JSLE_K: Small immediate",
6330 .u.insns_int = {
6331 BPF_ALU32_IMM(BPF_MOV, R0, -123),
6332 BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
6333 BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
6334 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6335 BPF_EXIT_INSN(),
6336 },
6337 INTERNAL,
6338 { },
6339 { { 0, -123 } }
6340 },
6341 {
6342 "JMP32_JSLE_K: Large immediate",
6343 .u.insns_int = {
6344 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6345 BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
6346 BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
6347 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6348 BPF_EXIT_INSN(),
6349 },
6350 INTERNAL,
6351 { },
6352 { { 0, -12345678 } }
6353 },
6354 /* BPF_JMP32 | BPF_JSLE | BPF_K */
6355 {
6356 "JMP32_JSLE_X",
6357 .u.insns_int = {
6358 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
6359 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
6360 BPF_JMP32_REG(BPF_JSLE, R0, R1, 2),
6361 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
6362 BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
6363 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6364 BPF_EXIT_INSN(),
6365 },
6366 INTERNAL,
6367 { },
6368 { { 0, -12345678 } }
6369 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006370 /* BPF_JMP | BPF_EXIT */
6371 {
6372 "JMP_EXIT",
6373 .u.insns_int = {
6374 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
6375 BPF_EXIT_INSN(),
6376 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
6377 },
6378 INTERNAL,
6379 { },
6380 { { 0, 0x4711 } },
6381 },
6382 /* BPF_JMP | BPF_JA */
6383 {
6384 "JMP_JA: Unconditional jump: if (true) return 1",
6385 .u.insns_int = {
6386 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6387 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
6388 BPF_EXIT_INSN(),
6389 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6390 BPF_EXIT_INSN(),
6391 },
6392 INTERNAL,
6393 { },
6394 { { 0, 1 } },
6395 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006396 /* BPF_JMP | BPF_JSLT | BPF_K */
6397 {
6398 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
6399 .u.insns_int = {
6400 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6401 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6402 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6403 BPF_EXIT_INSN(),
6404 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6405 BPF_EXIT_INSN(),
6406 },
6407 INTERNAL,
6408 { },
6409 { { 0, 1 } },
6410 },
6411 {
6412 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
6413 .u.insns_int = {
6414 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6415 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6416 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
6417 BPF_EXIT_INSN(),
6418 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6419 BPF_EXIT_INSN(),
6420 },
6421 INTERNAL,
6422 { },
6423 { { 0, 1 } },
6424 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006425 /* BPF_JMP | BPF_JSGT | BPF_K */
6426 {
6427 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
6428 .u.insns_int = {
6429 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6430 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6431 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
6432 BPF_EXIT_INSN(),
6433 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6434 BPF_EXIT_INSN(),
6435 },
6436 INTERNAL,
6437 { },
6438 { { 0, 1 } },
6439 },
6440 {
6441 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
6442 .u.insns_int = {
6443 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6444 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6445 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
6446 BPF_EXIT_INSN(),
6447 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6448 BPF_EXIT_INSN(),
6449 },
6450 INTERNAL,
6451 { },
6452 { { 0, 1 } },
6453 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006454 /* BPF_JMP | BPF_JSLE | BPF_K */
6455 {
6456 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
6457 .u.insns_int = {
6458 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6459 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
6460 BPF_JMP_IMM(BPF_JSLE, R1, -1, 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 {
6470 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
6471 .u.insns_int = {
6472 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6473 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6474 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
6475 BPF_EXIT_INSN(),
6476 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6477 BPF_EXIT_INSN(),
6478 },
6479 INTERNAL,
6480 { },
6481 { { 0, 1 } },
6482 },
6483 {
6484 "JMP_JSLE_K: Signed jump: value walk 1",
6485 .u.insns_int = {
6486 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6487 BPF_LD_IMM64(R1, 3),
6488 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
6489 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6490 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6491 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6492 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6493 BPF_ALU64_IMM(BPF_SUB, R1, 1),
6494 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6495 BPF_EXIT_INSN(), /* bad exit */
6496 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6497 BPF_EXIT_INSN(),
6498 },
6499 INTERNAL,
6500 { },
6501 { { 0, 1 } },
6502 },
6503 {
6504 "JMP_JSLE_K: Signed jump: value walk 2",
6505 .u.insns_int = {
6506 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6507 BPF_LD_IMM64(R1, 3),
6508 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
6509 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6510 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
6511 BPF_ALU64_IMM(BPF_SUB, R1, 2),
6512 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
6513 BPF_EXIT_INSN(), /* bad exit */
6514 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6515 BPF_EXIT_INSN(),
6516 },
6517 INTERNAL,
6518 { },
6519 { { 0, 1 } },
6520 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006521 /* BPF_JMP | BPF_JSGE | BPF_K */
6522 {
6523 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
6524 .u.insns_int = {
6525 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6526 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6527 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
6528 BPF_EXIT_INSN(),
6529 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6530 BPF_EXIT_INSN(),
6531 },
6532 INTERNAL,
6533 { },
6534 { { 0, 1 } },
6535 },
6536 {
6537 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
6538 .u.insns_int = {
6539 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6540 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
6541 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
6542 BPF_EXIT_INSN(),
6543 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6544 BPF_EXIT_INSN(),
6545 },
6546 INTERNAL,
6547 { },
6548 { { 0, 1 } },
6549 },
David Daney791caeb2017-05-24 16:35:49 -07006550 {
6551 "JMP_JSGE_K: Signed jump: value walk 1",
6552 .u.insns_int = {
6553 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6554 BPF_LD_IMM64(R1, -3),
6555 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
6556 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6557 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6558 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6559 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6560 BPF_ALU64_IMM(BPF_ADD, R1, 1),
6561 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6562 BPF_EXIT_INSN(), /* bad exit */
6563 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6564 BPF_EXIT_INSN(),
6565 },
6566 INTERNAL,
6567 { },
6568 { { 0, 1 } },
6569 },
6570 {
6571 "JMP_JSGE_K: Signed jump: value walk 2",
6572 .u.insns_int = {
6573 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6574 BPF_LD_IMM64(R1, -3),
6575 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
6576 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6577 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
6578 BPF_ALU64_IMM(BPF_ADD, R1, 2),
6579 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
6580 BPF_EXIT_INSN(), /* bad exit */
6581 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
6582 BPF_EXIT_INSN(),
6583 },
6584 INTERNAL,
6585 { },
6586 { { 0, 1 } },
6587 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006588 /* BPF_JMP | BPF_JGT | BPF_K */
6589 {
6590 "JMP_JGT_K: if (3 > 2) return 1",
6591 .u.insns_int = {
6592 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6593 BPF_LD_IMM64(R1, 3),
6594 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
6595 BPF_EXIT_INSN(),
6596 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6597 BPF_EXIT_INSN(),
6598 },
6599 INTERNAL,
6600 { },
6601 { { 0, 1 } },
6602 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05306603 {
6604 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
6605 .u.insns_int = {
6606 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6607 BPF_LD_IMM64(R1, -1),
6608 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
6609 BPF_EXIT_INSN(),
6610 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6611 BPF_EXIT_INSN(),
6612 },
6613 INTERNAL,
6614 { },
6615 { { 0, 1 } },
6616 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006617 /* BPF_JMP | BPF_JLT | BPF_K */
6618 {
6619 "JMP_JLT_K: if (2 < 3) return 1",
6620 .u.insns_int = {
6621 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6622 BPF_LD_IMM64(R1, 2),
6623 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
6624 BPF_EXIT_INSN(),
6625 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6626 BPF_EXIT_INSN(),
6627 },
6628 INTERNAL,
6629 { },
6630 { { 0, 1 } },
6631 },
6632 {
6633 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
6634 .u.insns_int = {
6635 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6636 BPF_LD_IMM64(R1, 1),
6637 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
6638 BPF_EXIT_INSN(),
6639 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6640 BPF_EXIT_INSN(),
6641 },
6642 INTERNAL,
6643 { },
6644 { { 0, 1 } },
6645 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006646 /* BPF_JMP | BPF_JGE | BPF_K */
6647 {
6648 "JMP_JGE_K: if (3 >= 2) return 1",
6649 .u.insns_int = {
6650 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6651 BPF_LD_IMM64(R1, 3),
6652 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
6653 BPF_EXIT_INSN(),
6654 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6655 BPF_EXIT_INSN(),
6656 },
6657 INTERNAL,
6658 { },
6659 { { 0, 1 } },
6660 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006661 /* BPF_JMP | BPF_JLE | BPF_K */
6662 {
6663 "JMP_JLE_K: if (2 <= 3) return 1",
6664 .u.insns_int = {
6665 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6666 BPF_LD_IMM64(R1, 2),
6667 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6668 BPF_EXIT_INSN(),
6669 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6670 BPF_EXIT_INSN(),
6671 },
6672 INTERNAL,
6673 { },
6674 { { 0, 1 } },
6675 },
Michael Holzheufe593842015-05-22 08:36:40 -07006676 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
6677 {
6678 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
6679 .u.insns_int = {
6680 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6681 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6682 BPF_EXIT_INSN(),
6683 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6684 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
6685 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
6686 BPF_EXIT_INSN(),
6687 },
6688 INTERNAL,
6689 { },
6690 { { 0, 1 } },
6691 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006692 {
6693 "JMP_JGE_K: if (3 >= 3) return 1",
6694 .u.insns_int = {
6695 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6696 BPF_LD_IMM64(R1, 3),
6697 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
6698 BPF_EXIT_INSN(),
6699 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6700 BPF_EXIT_INSN(),
6701 },
6702 INTERNAL,
6703 { },
6704 { { 0, 1 } },
6705 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006706 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
6707 {
6708 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
6709 .u.insns_int = {
6710 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
6711 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
6712 BPF_EXIT_INSN(),
6713 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
6714 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
6715 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
6716 BPF_EXIT_INSN(),
6717 },
6718 INTERNAL,
6719 { },
6720 { { 0, 1 } },
6721 },
6722 {
6723 "JMP_JLE_K: if (3 <= 3) return 1",
6724 .u.insns_int = {
6725 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6726 BPF_LD_IMM64(R1, 3),
6727 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
6728 BPF_EXIT_INSN(),
6729 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6730 BPF_EXIT_INSN(),
6731 },
6732 INTERNAL,
6733 { },
6734 { { 0, 1 } },
6735 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006736 /* BPF_JMP | BPF_JNE | BPF_K */
6737 {
6738 "JMP_JNE_K: if (3 != 2) return 1",
6739 .u.insns_int = {
6740 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6741 BPF_LD_IMM64(R1, 3),
6742 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
6743 BPF_EXIT_INSN(),
6744 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6745 BPF_EXIT_INSN(),
6746 },
6747 INTERNAL,
6748 { },
6749 { { 0, 1 } },
6750 },
6751 /* BPF_JMP | BPF_JEQ | BPF_K */
6752 {
6753 "JMP_JEQ_K: if (3 == 3) return 1",
6754 .u.insns_int = {
6755 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6756 BPF_LD_IMM64(R1, 3),
6757 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
6758 BPF_EXIT_INSN(),
6759 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6760 BPF_EXIT_INSN(),
6761 },
6762 INTERNAL,
6763 { },
6764 { { 0, 1 } },
6765 },
6766 /* BPF_JMP | BPF_JSET | BPF_K */
6767 {
6768 "JMP_JSET_K: if (0x3 & 0x2) return 1",
6769 .u.insns_int = {
6770 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6771 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306772 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006773 BPF_EXIT_INSN(),
6774 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6775 BPF_EXIT_INSN(),
6776 },
6777 INTERNAL,
6778 { },
6779 { { 0, 1 } },
6780 },
6781 {
6782 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
6783 .u.insns_int = {
6784 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6785 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05306786 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07006787 BPF_EXIT_INSN(),
6788 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6789 BPF_EXIT_INSN(),
6790 },
6791 INTERNAL,
6792 { },
6793 { { 0, 1 } },
6794 },
6795 /* BPF_JMP | BPF_JSGT | BPF_X */
6796 {
6797 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
6798 .u.insns_int = {
6799 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6800 BPF_LD_IMM64(R1, -1),
6801 BPF_LD_IMM64(R2, -2),
6802 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6803 BPF_EXIT_INSN(),
6804 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6805 BPF_EXIT_INSN(),
6806 },
6807 INTERNAL,
6808 { },
6809 { { 0, 1 } },
6810 },
6811 {
6812 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
6813 .u.insns_int = {
6814 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6815 BPF_LD_IMM64(R1, -1),
6816 BPF_LD_IMM64(R2, -1),
6817 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
6818 BPF_EXIT_INSN(),
6819 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6820 BPF_EXIT_INSN(),
6821 },
6822 INTERNAL,
6823 { },
6824 { { 0, 1 } },
6825 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006826 /* BPF_JMP | BPF_JSLT | BPF_X */
6827 {
6828 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
6829 .u.insns_int = {
6830 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6831 BPF_LD_IMM64(R1, -1),
6832 BPF_LD_IMM64(R2, -2),
6833 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
6834 BPF_EXIT_INSN(),
6835 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6836 BPF_EXIT_INSN(),
6837 },
6838 INTERNAL,
6839 { },
6840 { { 0, 1 } },
6841 },
6842 {
6843 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
6844 .u.insns_int = {
6845 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6846 BPF_LD_IMM64(R1, -1),
6847 BPF_LD_IMM64(R2, -1),
6848 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
6849 BPF_EXIT_INSN(),
6850 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6851 BPF_EXIT_INSN(),
6852 },
6853 INTERNAL,
6854 { },
6855 { { 0, 1 } },
6856 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006857 /* BPF_JMP | BPF_JSGE | BPF_X */
6858 {
6859 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
6860 .u.insns_int = {
6861 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6862 BPF_LD_IMM64(R1, -1),
6863 BPF_LD_IMM64(R2, -2),
6864 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6865 BPF_EXIT_INSN(),
6866 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6867 BPF_EXIT_INSN(),
6868 },
6869 INTERNAL,
6870 { },
6871 { { 0, 1 } },
6872 },
6873 {
6874 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
6875 .u.insns_int = {
6876 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6877 BPF_LD_IMM64(R1, -1),
6878 BPF_LD_IMM64(R2, -1),
6879 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
6880 BPF_EXIT_INSN(),
6881 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6882 BPF_EXIT_INSN(),
6883 },
6884 INTERNAL,
6885 { },
6886 { { 0, 1 } },
6887 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006888 /* BPF_JMP | BPF_JSLE | BPF_X */
6889 {
6890 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
6891 .u.insns_int = {
6892 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6893 BPF_LD_IMM64(R1, -1),
6894 BPF_LD_IMM64(R2, -2),
6895 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
6896 BPF_EXIT_INSN(),
6897 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6898 BPF_EXIT_INSN(),
6899 },
6900 INTERNAL,
6901 { },
6902 { { 0, 1 } },
6903 },
6904 {
6905 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
6906 .u.insns_int = {
6907 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6908 BPF_LD_IMM64(R1, -1),
6909 BPF_LD_IMM64(R2, -1),
6910 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
6911 BPF_EXIT_INSN(),
6912 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6913 BPF_EXIT_INSN(),
6914 },
6915 INTERNAL,
6916 { },
6917 { { 0, 1 } },
6918 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006919 /* BPF_JMP | BPF_JGT | BPF_X */
6920 {
6921 "JMP_JGT_X: if (3 > 2) return 1",
6922 .u.insns_int = {
6923 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6924 BPF_LD_IMM64(R1, 3),
6925 BPF_LD_IMM64(R2, 2),
6926 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6927 BPF_EXIT_INSN(),
6928 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6929 BPF_EXIT_INSN(),
6930 },
6931 INTERNAL,
6932 { },
6933 { { 0, 1 } },
6934 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05306935 {
6936 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
6937 .u.insns_int = {
6938 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6939 BPF_LD_IMM64(R1, -1),
6940 BPF_LD_IMM64(R2, 1),
6941 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
6942 BPF_EXIT_INSN(),
6943 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6944 BPF_EXIT_INSN(),
6945 },
6946 INTERNAL,
6947 { },
6948 { { 0, 1 } },
6949 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02006950 /* BPF_JMP | BPF_JLT | BPF_X */
6951 {
6952 "JMP_JLT_X: if (2 < 3) return 1",
6953 .u.insns_int = {
6954 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6955 BPF_LD_IMM64(R1, 3),
6956 BPF_LD_IMM64(R2, 2),
6957 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6958 BPF_EXIT_INSN(),
6959 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6960 BPF_EXIT_INSN(),
6961 },
6962 INTERNAL,
6963 { },
6964 { { 0, 1 } },
6965 },
6966 {
6967 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
6968 .u.insns_int = {
6969 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6970 BPF_LD_IMM64(R1, -1),
6971 BPF_LD_IMM64(R2, 1),
6972 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
6973 BPF_EXIT_INSN(),
6974 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6975 BPF_EXIT_INSN(),
6976 },
6977 INTERNAL,
6978 { },
6979 { { 0, 1 } },
6980 },
Michael Holzheucffc6422015-05-11 22:22:44 -07006981 /* BPF_JMP | BPF_JGE | BPF_X */
6982 {
6983 "JMP_JGE_X: if (3 >= 2) return 1",
6984 .u.insns_int = {
6985 BPF_ALU32_IMM(BPF_MOV, R0, 0),
6986 BPF_LD_IMM64(R1, 3),
6987 BPF_LD_IMM64(R2, 2),
6988 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
6989 BPF_EXIT_INSN(),
6990 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6991 BPF_EXIT_INSN(),
6992 },
6993 INTERNAL,
6994 { },
6995 { { 0, 1 } },
6996 },
6997 {
6998 "JMP_JGE_X: if (3 >= 3) return 1",
6999 .u.insns_int = {
7000 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7001 BPF_LD_IMM64(R1, 3),
7002 BPF_LD_IMM64(R2, 3),
7003 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
7004 BPF_EXIT_INSN(),
7005 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7006 BPF_EXIT_INSN(),
7007 },
7008 INTERNAL,
7009 { },
7010 { { 0, 1 } },
7011 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02007012 /* BPF_JMP | BPF_JLE | BPF_X */
7013 {
7014 "JMP_JLE_X: if (2 <= 3) return 1",
7015 .u.insns_int = {
7016 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7017 BPF_LD_IMM64(R1, 3),
7018 BPF_LD_IMM64(R2, 2),
7019 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
7020 BPF_EXIT_INSN(),
7021 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7022 BPF_EXIT_INSN(),
7023 },
7024 INTERNAL,
7025 { },
7026 { { 0, 1 } },
7027 },
7028 {
7029 "JMP_JLE_X: if (3 <= 3) return 1",
7030 .u.insns_int = {
7031 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7032 BPF_LD_IMM64(R1, 3),
7033 BPF_LD_IMM64(R2, 3),
7034 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
7035 BPF_EXIT_INSN(),
7036 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7037 BPF_EXIT_INSN(),
7038 },
7039 INTERNAL,
7040 { },
7041 { { 0, 1 } },
7042 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02007043 {
7044 /* Mainly testing JIT + imm64 here. */
7045 "JMP_JGE_X: ldimm64 test 1",
7046 .u.insns_int = {
7047 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7048 BPF_LD_IMM64(R1, 3),
7049 BPF_LD_IMM64(R2, 2),
7050 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02007051 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7052 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02007053 BPF_EXIT_INSN(),
7054 },
7055 INTERNAL,
7056 { },
7057 { { 0, 0xeeeeeeeeU } },
7058 },
7059 {
7060 "JMP_JGE_X: ldimm64 test 2",
7061 .u.insns_int = {
7062 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7063 BPF_LD_IMM64(R1, 3),
7064 BPF_LD_IMM64(R2, 2),
7065 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02007066 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02007067 BPF_EXIT_INSN(),
7068 },
7069 INTERNAL,
7070 { },
7071 { { 0, 0xffffffffU } },
7072 },
7073 {
7074 "JMP_JGE_X: ldimm64 test 3",
7075 .u.insns_int = {
7076 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7077 BPF_LD_IMM64(R1, 3),
7078 BPF_LD_IMM64(R2, 2),
7079 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02007080 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7081 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02007082 BPF_EXIT_INSN(),
7083 },
7084 INTERNAL,
7085 { },
7086 { { 0, 1 } },
7087 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02007088 {
7089 "JMP_JLE_X: ldimm64 test 1",
7090 .u.insns_int = {
7091 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7092 BPF_LD_IMM64(R1, 3),
7093 BPF_LD_IMM64(R2, 2),
7094 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
7095 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7096 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
7097 BPF_EXIT_INSN(),
7098 },
7099 INTERNAL,
7100 { },
7101 { { 0, 0xeeeeeeeeU } },
7102 },
7103 {
7104 "JMP_JLE_X: ldimm64 test 2",
7105 .u.insns_int = {
7106 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7107 BPF_LD_IMM64(R1, 3),
7108 BPF_LD_IMM64(R2, 2),
7109 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
7110 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7111 BPF_EXIT_INSN(),
7112 },
7113 INTERNAL,
7114 { },
7115 { { 0, 0xffffffffU } },
7116 },
7117 {
7118 "JMP_JLE_X: ldimm64 test 3",
7119 .u.insns_int = {
7120 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7121 BPF_LD_IMM64(R1, 3),
7122 BPF_LD_IMM64(R2, 2),
7123 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
7124 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
7125 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
7126 BPF_EXIT_INSN(),
7127 },
7128 INTERNAL,
7129 { },
7130 { { 0, 1 } },
7131 },
Michael Holzheucffc6422015-05-11 22:22:44 -07007132 /* BPF_JMP | BPF_JNE | BPF_X */
7133 {
7134 "JMP_JNE_X: if (3 != 2) return 1",
7135 .u.insns_int = {
7136 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7137 BPF_LD_IMM64(R1, 3),
7138 BPF_LD_IMM64(R2, 2),
7139 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
7140 BPF_EXIT_INSN(),
7141 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7142 BPF_EXIT_INSN(),
7143 },
7144 INTERNAL,
7145 { },
7146 { { 0, 1 } },
7147 },
7148 /* BPF_JMP | BPF_JEQ | BPF_X */
7149 {
7150 "JMP_JEQ_X: if (3 == 3) return 1",
7151 .u.insns_int = {
7152 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7153 BPF_LD_IMM64(R1, 3),
7154 BPF_LD_IMM64(R2, 3),
7155 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
7156 BPF_EXIT_INSN(),
7157 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7158 BPF_EXIT_INSN(),
7159 },
7160 INTERNAL,
7161 { },
7162 { { 0, 1 } },
7163 },
7164 /* BPF_JMP | BPF_JSET | BPF_X */
7165 {
7166 "JMP_JSET_X: if (0x3 & 0x2) return 1",
7167 .u.insns_int = {
7168 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7169 BPF_LD_IMM64(R1, 3),
7170 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05307171 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07007172 BPF_EXIT_INSN(),
7173 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7174 BPF_EXIT_INSN(),
7175 },
7176 INTERNAL,
7177 { },
7178 { { 0, 1 } },
7179 },
7180 {
7181 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
7182 .u.insns_int = {
7183 BPF_ALU32_IMM(BPF_MOV, R0, 0),
7184 BPF_LD_IMM64(R1, 3),
7185 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05307186 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07007187 BPF_EXIT_INSN(),
7188 BPF_ALU32_IMM(BPF_MOV, R0, 1),
7189 BPF_EXIT_INSN(),
7190 },
7191 INTERNAL,
7192 { },
7193 { { 0, 1 } },
7194 },
Johan Almbladh66e5eb82021-08-09 11:18:25 +02007195 { /* Mainly checking JIT here. */
7196 "BPF_MAXINSNS: Very long conditional jump",
7197 { },
7198 INTERNAL | FLAG_NO_DATA,
7199 { },
7200 { { 0, 1 } },
7201 .fill_helper = bpf_fill_long_jmp,
7202 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02007203 {
7204 "JMP_JA: Jump, gap, jump, ...",
7205 { },
7206 CLASSIC | FLAG_NO_DATA,
7207 { },
7208 { { 0, 0xababcbac } },
7209 .fill_helper = bpf_fill_ja,
7210 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007211 { /* Mainly checking JIT here. */
7212 "BPF_MAXINSNS: Maximum possible literals",
7213 { },
7214 CLASSIC | FLAG_NO_DATA,
7215 { },
7216 { { 0, 0xffffffff } },
7217 .fill_helper = bpf_fill_maxinsns1,
7218 },
7219 { /* Mainly checking JIT here. */
7220 "BPF_MAXINSNS: Single literal",
7221 { },
7222 CLASSIC | FLAG_NO_DATA,
7223 { },
7224 { { 0, 0xfefefefe } },
7225 .fill_helper = bpf_fill_maxinsns2,
7226 },
7227 { /* Mainly checking JIT here. */
7228 "BPF_MAXINSNS: Run/add until end",
7229 { },
7230 CLASSIC | FLAG_NO_DATA,
7231 { },
7232 { { 0, 0x947bf368 } },
7233 .fill_helper = bpf_fill_maxinsns3,
7234 },
7235 {
7236 "BPF_MAXINSNS: Too many instructions",
7237 { },
7238 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
7239 { },
7240 { },
7241 .fill_helper = bpf_fill_maxinsns4,
Yonghong Song09584b42018-02-02 22:37:15 -08007242 .expected_errcode = -EINVAL,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007243 },
7244 { /* Mainly checking JIT here. */
7245 "BPF_MAXINSNS: Very long jump",
7246 { },
7247 CLASSIC | FLAG_NO_DATA,
7248 { },
7249 { { 0, 0xabababab } },
7250 .fill_helper = bpf_fill_maxinsns5,
7251 },
7252 { /* Mainly checking JIT here. */
7253 "BPF_MAXINSNS: Ctx heavy transformations",
7254 { },
7255 CLASSIC,
7256 { },
7257 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01007258 { 1, SKB_VLAN_PRESENT },
7259 { 10, SKB_VLAN_PRESENT }
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007260 },
7261 .fill_helper = bpf_fill_maxinsns6,
7262 },
7263 { /* Mainly checking JIT here. */
7264 "BPF_MAXINSNS: Call heavy transformations",
7265 { },
7266 CLASSIC | FLAG_NO_DATA,
7267 { },
7268 { { 1, 0 }, { 10, 0 } },
7269 .fill_helper = bpf_fill_maxinsns7,
7270 },
7271 { /* Mainly checking JIT here. */
7272 "BPF_MAXINSNS: Jump heavy test",
7273 { },
7274 CLASSIC | FLAG_NO_DATA,
7275 { },
7276 { { 0, 0xffffffff } },
7277 .fill_helper = bpf_fill_maxinsns8,
7278 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02007279 { /* Mainly checking JIT here. */
7280 "BPF_MAXINSNS: Very long jump backwards",
7281 { },
7282 INTERNAL | FLAG_NO_DATA,
7283 { },
7284 { { 0, 0xcbababab } },
7285 .fill_helper = bpf_fill_maxinsns9,
7286 },
7287 { /* Mainly checking JIT here. */
7288 "BPF_MAXINSNS: Edge hopping nuthouse",
7289 { },
7290 INTERNAL | FLAG_NO_DATA,
7291 { },
7292 { { 0, 0xabababac } },
7293 .fill_helper = bpf_fill_maxinsns10,
7294 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02007295 {
7296 "BPF_MAXINSNS: Jump, gap, jump, ...",
7297 { },
7298 CLASSIC | FLAG_NO_DATA,
7299 { },
7300 { { 0, 0xababcbac } },
7301 .fill_helper = bpf_fill_maxinsns11,
7302 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007303 {
Daniel Borkmannbe088152018-06-02 23:06:32 +02007304 "BPF_MAXINSNS: jump over MSH",
7305 { },
7306 CLASSIC | FLAG_EXPECTED_FAIL,
7307 { 0xfa, 0xfb, 0xfc, 0xfd, },
7308 { { 4, 0xabababab } },
7309 .fill_helper = bpf_fill_maxinsns12,
7310 .expected_errcode = -EINVAL,
7311 },
7312 {
7313 "BPF_MAXINSNS: exec all MSH",
7314 { },
7315 CLASSIC,
7316 { 0xfa, 0xfb, 0xfc, 0xfd, },
7317 { { 4, 0xababab83 } },
7318 .fill_helper = bpf_fill_maxinsns13,
7319 },
7320 {
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007321 "BPF_MAXINSNS: ld_abs+get_processor_id",
7322 { },
7323 CLASSIC,
7324 { },
7325 { { 1, 0xbee } },
7326 .fill_helper = bpf_fill_ld_abs_get_processor_id,
7327 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02007328 /*
7329 * LD_IND / LD_ABS on fragmented SKBs
7330 */
7331 {
7332 "LD_IND byte frag",
7333 .u.insns = {
7334 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7335 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
7336 BPF_STMT(BPF_RET | BPF_A, 0x0),
7337 },
7338 CLASSIC | FLAG_SKB_FRAG,
7339 { },
7340 { {0x40, 0x42} },
7341 .frag_data = {
7342 0x42, 0x00, 0x00, 0x00,
7343 0x43, 0x44, 0x00, 0x00,
7344 0x21, 0x07, 0x19, 0x83,
7345 },
7346 },
7347 {
7348 "LD_IND halfword frag",
7349 .u.insns = {
7350 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7351 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
7352 BPF_STMT(BPF_RET | BPF_A, 0x0),
7353 },
7354 CLASSIC | FLAG_SKB_FRAG,
7355 { },
7356 { {0x40, 0x4344} },
7357 .frag_data = {
7358 0x42, 0x00, 0x00, 0x00,
7359 0x43, 0x44, 0x00, 0x00,
7360 0x21, 0x07, 0x19, 0x83,
7361 },
7362 },
7363 {
7364 "LD_IND word frag",
7365 .u.insns = {
7366 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7367 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
7368 BPF_STMT(BPF_RET | BPF_A, 0x0),
7369 },
7370 CLASSIC | FLAG_SKB_FRAG,
7371 { },
7372 { {0x40, 0x21071983} },
7373 .frag_data = {
7374 0x42, 0x00, 0x00, 0x00,
7375 0x43, 0x44, 0x00, 0x00,
7376 0x21, 0x07, 0x19, 0x83,
7377 },
7378 },
7379 {
7380 "LD_IND halfword mixed head/frag",
7381 .u.insns = {
7382 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7383 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7384 BPF_STMT(BPF_RET | BPF_A, 0x0),
7385 },
7386 CLASSIC | FLAG_SKB_FRAG,
7387 { [0x3e] = 0x25, [0x3f] = 0x05, },
7388 { {0x40, 0x0519} },
7389 .frag_data = { 0x19, 0x82 },
7390 },
7391 {
7392 "LD_IND word mixed head/frag",
7393 .u.insns = {
7394 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
7395 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7396 BPF_STMT(BPF_RET | BPF_A, 0x0),
7397 },
7398 CLASSIC | FLAG_SKB_FRAG,
7399 { [0x3e] = 0x25, [0x3f] = 0x05, },
7400 { {0x40, 0x25051982} },
7401 .frag_data = { 0x19, 0x82 },
7402 },
7403 {
7404 "LD_ABS byte frag",
7405 .u.insns = {
7406 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
7407 BPF_STMT(BPF_RET | BPF_A, 0x0),
7408 },
7409 CLASSIC | FLAG_SKB_FRAG,
7410 { },
7411 { {0x40, 0x42} },
7412 .frag_data = {
7413 0x42, 0x00, 0x00, 0x00,
7414 0x43, 0x44, 0x00, 0x00,
7415 0x21, 0x07, 0x19, 0x83,
7416 },
7417 },
7418 {
7419 "LD_ABS halfword frag",
7420 .u.insns = {
7421 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
7422 BPF_STMT(BPF_RET | BPF_A, 0x0),
7423 },
7424 CLASSIC | FLAG_SKB_FRAG,
7425 { },
7426 { {0x40, 0x4344} },
7427 .frag_data = {
7428 0x42, 0x00, 0x00, 0x00,
7429 0x43, 0x44, 0x00, 0x00,
7430 0x21, 0x07, 0x19, 0x83,
7431 },
7432 },
7433 {
7434 "LD_ABS word frag",
7435 .u.insns = {
7436 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
7437 BPF_STMT(BPF_RET | BPF_A, 0x0),
7438 },
7439 CLASSIC | FLAG_SKB_FRAG,
7440 { },
7441 { {0x40, 0x21071983} },
7442 .frag_data = {
7443 0x42, 0x00, 0x00, 0x00,
7444 0x43, 0x44, 0x00, 0x00,
7445 0x21, 0x07, 0x19, 0x83,
7446 },
7447 },
7448 {
7449 "LD_ABS halfword mixed head/frag",
7450 .u.insns = {
7451 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7452 BPF_STMT(BPF_RET | BPF_A, 0x0),
7453 },
7454 CLASSIC | FLAG_SKB_FRAG,
7455 { [0x3e] = 0x25, [0x3f] = 0x05, },
7456 { {0x40, 0x0519} },
7457 .frag_data = { 0x19, 0x82 },
7458 },
7459 {
7460 "LD_ABS word mixed head/frag",
7461 .u.insns = {
7462 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
7463 BPF_STMT(BPF_RET | BPF_A, 0x0),
7464 },
7465 CLASSIC | FLAG_SKB_FRAG,
7466 { [0x3e] = 0x25, [0x3f] = 0x05, },
7467 { {0x40, 0x25051982} },
7468 .frag_data = { 0x19, 0x82 },
7469 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007470 /*
7471 * LD_IND / LD_ABS on non fragmented SKBs
7472 */
7473 {
7474 /*
7475 * this tests that the JIT/interpreter correctly resets X
7476 * before using it in an LD_IND instruction.
7477 */
7478 "LD_IND byte default X",
7479 .u.insns = {
7480 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7481 BPF_STMT(BPF_RET | BPF_A, 0x0),
7482 },
7483 CLASSIC,
7484 { [0x1] = 0x42 },
7485 { {0x40, 0x42 } },
7486 },
7487 {
7488 "LD_IND byte positive offset",
7489 .u.insns = {
7490 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7491 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7492 BPF_STMT(BPF_RET | BPF_A, 0x0),
7493 },
7494 CLASSIC,
7495 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7496 { {0x40, 0x82 } },
7497 },
7498 {
7499 "LD_IND byte negative offset",
7500 .u.insns = {
7501 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7502 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
7503 BPF_STMT(BPF_RET | BPF_A, 0x0),
7504 },
7505 CLASSIC,
7506 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7507 { {0x40, 0x05 } },
7508 },
7509 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007510 "LD_IND byte positive offset, all ff",
7511 .u.insns = {
7512 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7513 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7514 BPF_STMT(BPF_RET | BPF_A, 0x0),
7515 },
7516 CLASSIC,
7517 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7518 { {0x40, 0xff } },
7519 },
7520 {
7521 "LD_IND byte positive offset, out of bounds",
7522 .u.insns = {
7523 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7524 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
7525 BPF_STMT(BPF_RET | BPF_A, 0x0),
7526 },
7527 CLASSIC,
7528 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7529 { {0x3f, 0 }, },
7530 },
7531 {
7532 "LD_IND byte negative offset, out of bounds",
7533 .u.insns = {
7534 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7535 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
7536 BPF_STMT(BPF_RET | BPF_A, 0x0),
7537 },
7538 CLASSIC,
7539 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7540 { {0x3f, 0 } },
7541 },
7542 {
7543 "LD_IND byte negative offset, multiple calls",
7544 .u.insns = {
7545 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7546 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
7547 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
7548 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
7549 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
7550 BPF_STMT(BPF_RET | BPF_A, 0x0),
7551 },
7552 CLASSIC,
7553 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7554 { {0x40, 0x82 }, },
7555 },
7556 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007557 "LD_IND halfword positive offset",
7558 .u.insns = {
7559 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7560 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
7561 BPF_STMT(BPF_RET | BPF_A, 0x0),
7562 },
7563 CLASSIC,
7564 {
7565 [0x1c] = 0xaa, [0x1d] = 0x55,
7566 [0x1e] = 0xbb, [0x1f] = 0x66,
7567 [0x20] = 0xcc, [0x21] = 0x77,
7568 [0x22] = 0xdd, [0x23] = 0x88,
7569 },
7570 { {0x40, 0xdd88 } },
7571 },
7572 {
7573 "LD_IND halfword negative offset",
7574 .u.insns = {
7575 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7576 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
7577 BPF_STMT(BPF_RET | BPF_A, 0x0),
7578 },
7579 CLASSIC,
7580 {
7581 [0x1c] = 0xaa, [0x1d] = 0x55,
7582 [0x1e] = 0xbb, [0x1f] = 0x66,
7583 [0x20] = 0xcc, [0x21] = 0x77,
7584 [0x22] = 0xdd, [0x23] = 0x88,
7585 },
7586 { {0x40, 0xbb66 } },
7587 },
7588 {
7589 "LD_IND halfword unaligned",
7590 .u.insns = {
7591 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7592 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
7593 BPF_STMT(BPF_RET | BPF_A, 0x0),
7594 },
7595 CLASSIC,
7596 {
7597 [0x1c] = 0xaa, [0x1d] = 0x55,
7598 [0x1e] = 0xbb, [0x1f] = 0x66,
7599 [0x20] = 0xcc, [0x21] = 0x77,
7600 [0x22] = 0xdd, [0x23] = 0x88,
7601 },
7602 { {0x40, 0x66cc } },
7603 },
7604 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007605 "LD_IND halfword positive offset, all ff",
7606 .u.insns = {
7607 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
7608 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7609 BPF_STMT(BPF_RET | BPF_A, 0x0),
7610 },
7611 CLASSIC,
7612 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7613 { {0x40, 0xffff } },
7614 },
7615 {
7616 "LD_IND halfword positive offset, out of bounds",
7617 .u.insns = {
7618 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7619 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
7620 BPF_STMT(BPF_RET | BPF_A, 0x0),
7621 },
7622 CLASSIC,
7623 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7624 { {0x3f, 0 }, },
7625 },
7626 {
7627 "LD_IND halfword negative offset, out of bounds",
7628 .u.insns = {
7629 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7630 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
7631 BPF_STMT(BPF_RET | BPF_A, 0x0),
7632 },
7633 CLASSIC,
7634 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7635 { {0x3f, 0 } },
7636 },
7637 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007638 "LD_IND word positive offset",
7639 .u.insns = {
7640 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7641 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
7642 BPF_STMT(BPF_RET | BPF_A, 0x0),
7643 },
7644 CLASSIC,
7645 {
7646 [0x1c] = 0xaa, [0x1d] = 0x55,
7647 [0x1e] = 0xbb, [0x1f] = 0x66,
7648 [0x20] = 0xcc, [0x21] = 0x77,
7649 [0x22] = 0xdd, [0x23] = 0x88,
7650 [0x24] = 0xee, [0x25] = 0x99,
7651 [0x26] = 0xff, [0x27] = 0xaa,
7652 },
7653 { {0x40, 0xee99ffaa } },
7654 },
7655 {
7656 "LD_IND word negative offset",
7657 .u.insns = {
7658 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7659 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
7660 BPF_STMT(BPF_RET | BPF_A, 0x0),
7661 },
7662 CLASSIC,
7663 {
7664 [0x1c] = 0xaa, [0x1d] = 0x55,
7665 [0x1e] = 0xbb, [0x1f] = 0x66,
7666 [0x20] = 0xcc, [0x21] = 0x77,
7667 [0x22] = 0xdd, [0x23] = 0x88,
7668 [0x24] = 0xee, [0x25] = 0x99,
7669 [0x26] = 0xff, [0x27] = 0xaa,
7670 },
7671 { {0x40, 0xaa55bb66 } },
7672 },
7673 {
7674 "LD_IND word unaligned (addr & 3 == 2)",
7675 .u.insns = {
7676 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7677 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
7678 BPF_STMT(BPF_RET | BPF_A, 0x0),
7679 },
7680 CLASSIC,
7681 {
7682 [0x1c] = 0xaa, [0x1d] = 0x55,
7683 [0x1e] = 0xbb, [0x1f] = 0x66,
7684 [0x20] = 0xcc, [0x21] = 0x77,
7685 [0x22] = 0xdd, [0x23] = 0x88,
7686 [0x24] = 0xee, [0x25] = 0x99,
7687 [0x26] = 0xff, [0x27] = 0xaa,
7688 },
7689 { {0x40, 0xbb66cc77 } },
7690 },
7691 {
7692 "LD_IND word unaligned (addr & 3 == 1)",
7693 .u.insns = {
7694 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7695 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
7696 BPF_STMT(BPF_RET | BPF_A, 0x0),
7697 },
7698 CLASSIC,
7699 {
7700 [0x1c] = 0xaa, [0x1d] = 0x55,
7701 [0x1e] = 0xbb, [0x1f] = 0x66,
7702 [0x20] = 0xcc, [0x21] = 0x77,
7703 [0x22] = 0xdd, [0x23] = 0x88,
7704 [0x24] = 0xee, [0x25] = 0x99,
7705 [0x26] = 0xff, [0x27] = 0xaa,
7706 },
7707 { {0x40, 0x55bb66cc } },
7708 },
7709 {
7710 "LD_IND word unaligned (addr & 3 == 3)",
7711 .u.insns = {
7712 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
7713 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
7714 BPF_STMT(BPF_RET | BPF_A, 0x0),
7715 },
7716 CLASSIC,
7717 {
7718 [0x1c] = 0xaa, [0x1d] = 0x55,
7719 [0x1e] = 0xbb, [0x1f] = 0x66,
7720 [0x20] = 0xcc, [0x21] = 0x77,
7721 [0x22] = 0xdd, [0x23] = 0x88,
7722 [0x24] = 0xee, [0x25] = 0x99,
7723 [0x26] = 0xff, [0x27] = 0xaa,
7724 },
7725 { {0x40, 0x66cc77dd } },
7726 },
7727 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007728 "LD_IND word positive offset, all ff",
7729 .u.insns = {
7730 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
7731 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7732 BPF_STMT(BPF_RET | BPF_A, 0x0),
7733 },
7734 CLASSIC,
7735 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7736 { {0x40, 0xffffffff } },
7737 },
7738 {
7739 "LD_IND word positive offset, out of bounds",
7740 .u.insns = {
7741 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7742 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
7743 BPF_STMT(BPF_RET | BPF_A, 0x0),
7744 },
7745 CLASSIC,
7746 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7747 { {0x3f, 0 }, },
7748 },
7749 {
7750 "LD_IND word negative offset, out of bounds",
7751 .u.insns = {
7752 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
7753 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
7754 BPF_STMT(BPF_RET | BPF_A, 0x0),
7755 },
7756 CLASSIC,
7757 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7758 { {0x3f, 0 } },
7759 },
7760 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007761 "LD_ABS byte",
7762 .u.insns = {
7763 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
7764 BPF_STMT(BPF_RET | BPF_A, 0x0),
7765 },
7766 CLASSIC,
7767 {
7768 [0x1c] = 0xaa, [0x1d] = 0x55,
7769 [0x1e] = 0xbb, [0x1f] = 0x66,
7770 [0x20] = 0xcc, [0x21] = 0x77,
7771 [0x22] = 0xdd, [0x23] = 0x88,
7772 [0x24] = 0xee, [0x25] = 0x99,
7773 [0x26] = 0xff, [0x27] = 0xaa,
7774 },
7775 { {0x40, 0xcc } },
7776 },
7777 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007778 "LD_ABS byte positive offset, all ff",
7779 .u.insns = {
7780 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7781 BPF_STMT(BPF_RET | BPF_A, 0x0),
7782 },
7783 CLASSIC,
7784 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7785 { {0x40, 0xff } },
7786 },
7787 {
7788 "LD_ABS byte positive offset, out of bounds",
7789 .u.insns = {
7790 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
7791 BPF_STMT(BPF_RET | BPF_A, 0x0),
7792 },
7793 CLASSIC,
7794 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7795 { {0x3f, 0 }, },
7796 },
7797 {
7798 "LD_ABS byte negative offset, out of bounds load",
7799 .u.insns = {
7800 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
7801 BPF_STMT(BPF_RET | BPF_A, 0x0),
7802 },
7803 CLASSIC | FLAG_EXPECTED_FAIL,
7804 .expected_errcode = -EINVAL,
7805 },
7806 {
7807 "LD_ABS byte negative offset, in bounds",
7808 .u.insns = {
7809 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7810 BPF_STMT(BPF_RET | BPF_A, 0x0),
7811 },
7812 CLASSIC,
7813 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7814 { {0x40, 0x82 }, },
7815 },
7816 {
7817 "LD_ABS byte negative offset, out of bounds",
7818 .u.insns = {
7819 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7820 BPF_STMT(BPF_RET | BPF_A, 0x0),
7821 },
7822 CLASSIC,
7823 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7824 { {0x3f, 0 }, },
7825 },
7826 {
7827 "LD_ABS byte negative offset, multiple calls",
7828 .u.insns = {
7829 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
7830 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
7831 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
7832 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
7833 BPF_STMT(BPF_RET | BPF_A, 0x0),
7834 },
7835 CLASSIC,
7836 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7837 { {0x40, 0x82 }, },
7838 },
7839 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007840 "LD_ABS halfword",
7841 .u.insns = {
7842 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
7843 BPF_STMT(BPF_RET | BPF_A, 0x0),
7844 },
7845 CLASSIC,
7846 {
7847 [0x1c] = 0xaa, [0x1d] = 0x55,
7848 [0x1e] = 0xbb, [0x1f] = 0x66,
7849 [0x20] = 0xcc, [0x21] = 0x77,
7850 [0x22] = 0xdd, [0x23] = 0x88,
7851 [0x24] = 0xee, [0x25] = 0x99,
7852 [0x26] = 0xff, [0x27] = 0xaa,
7853 },
7854 { {0x40, 0xdd88 } },
7855 },
7856 {
7857 "LD_ABS halfword unaligned",
7858 .u.insns = {
7859 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
7860 BPF_STMT(BPF_RET | BPF_A, 0x0),
7861 },
7862 CLASSIC,
7863 {
7864 [0x1c] = 0xaa, [0x1d] = 0x55,
7865 [0x1e] = 0xbb, [0x1f] = 0x66,
7866 [0x20] = 0xcc, [0x21] = 0x77,
7867 [0x22] = 0xdd, [0x23] = 0x88,
7868 [0x24] = 0xee, [0x25] = 0x99,
7869 [0x26] = 0xff, [0x27] = 0xaa,
7870 },
7871 { {0x40, 0x99ff } },
7872 },
7873 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007874 "LD_ABS halfword positive offset, all ff",
7875 .u.insns = {
7876 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
7877 BPF_STMT(BPF_RET | BPF_A, 0x0),
7878 },
7879 CLASSIC,
7880 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7881 { {0x40, 0xffff } },
7882 },
7883 {
7884 "LD_ABS halfword positive offset, out of bounds",
7885 .u.insns = {
7886 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
7887 BPF_STMT(BPF_RET | BPF_A, 0x0),
7888 },
7889 CLASSIC,
7890 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7891 { {0x3f, 0 }, },
7892 },
7893 {
7894 "LD_ABS halfword negative offset, out of bounds load",
7895 .u.insns = {
7896 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
7897 BPF_STMT(BPF_RET | BPF_A, 0x0),
7898 },
7899 CLASSIC | FLAG_EXPECTED_FAIL,
7900 .expected_errcode = -EINVAL,
7901 },
7902 {
7903 "LD_ABS halfword negative offset, in bounds",
7904 .u.insns = {
7905 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7906 BPF_STMT(BPF_RET | BPF_A, 0x0),
7907 },
7908 CLASSIC,
7909 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7910 { {0x40, 0x1982 }, },
7911 },
7912 {
7913 "LD_ABS halfword negative offset, out of bounds",
7914 .u.insns = {
7915 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
7916 BPF_STMT(BPF_RET | BPF_A, 0x0),
7917 },
7918 CLASSIC,
7919 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
7920 { {0x3f, 0 }, },
7921 },
7922 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02007923 "LD_ABS word",
7924 .u.insns = {
7925 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
7926 BPF_STMT(BPF_RET | BPF_A, 0x0),
7927 },
7928 CLASSIC,
7929 {
7930 [0x1c] = 0xaa, [0x1d] = 0x55,
7931 [0x1e] = 0xbb, [0x1f] = 0x66,
7932 [0x20] = 0xcc, [0x21] = 0x77,
7933 [0x22] = 0xdd, [0x23] = 0x88,
7934 [0x24] = 0xee, [0x25] = 0x99,
7935 [0x26] = 0xff, [0x27] = 0xaa,
7936 },
7937 { {0x40, 0xaa55bb66 } },
7938 },
7939 {
7940 "LD_ABS word unaligned (addr & 3 == 2)",
7941 .u.insns = {
7942 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
7943 BPF_STMT(BPF_RET | BPF_A, 0x0),
7944 },
7945 CLASSIC,
7946 {
7947 [0x1c] = 0xaa, [0x1d] = 0x55,
7948 [0x1e] = 0xbb, [0x1f] = 0x66,
7949 [0x20] = 0xcc, [0x21] = 0x77,
7950 [0x22] = 0xdd, [0x23] = 0x88,
7951 [0x24] = 0xee, [0x25] = 0x99,
7952 [0x26] = 0xff, [0x27] = 0xaa,
7953 },
7954 { {0x40, 0xdd88ee99 } },
7955 },
7956 {
7957 "LD_ABS word unaligned (addr & 3 == 1)",
7958 .u.insns = {
7959 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
7960 BPF_STMT(BPF_RET | BPF_A, 0x0),
7961 },
7962 CLASSIC,
7963 {
7964 [0x1c] = 0xaa, [0x1d] = 0x55,
7965 [0x1e] = 0xbb, [0x1f] = 0x66,
7966 [0x20] = 0xcc, [0x21] = 0x77,
7967 [0x22] = 0xdd, [0x23] = 0x88,
7968 [0x24] = 0xee, [0x25] = 0x99,
7969 [0x26] = 0xff, [0x27] = 0xaa,
7970 },
7971 { {0x40, 0x77dd88ee } },
7972 },
7973 {
7974 "LD_ABS word unaligned (addr & 3 == 3)",
7975 .u.insns = {
7976 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
7977 BPF_STMT(BPF_RET | BPF_A, 0x0),
7978 },
7979 CLASSIC,
7980 {
7981 [0x1c] = 0xaa, [0x1d] = 0x55,
7982 [0x1e] = 0xbb, [0x1f] = 0x66,
7983 [0x20] = 0xcc, [0x21] = 0x77,
7984 [0x22] = 0xdd, [0x23] = 0x88,
7985 [0x24] = 0xee, [0x25] = 0x99,
7986 [0x26] = 0xff, [0x27] = 0xaa,
7987 },
7988 { {0x40, 0x88ee99ff } },
7989 },
Daniel Borkmann93731ef2018-05-04 01:08:13 +02007990 {
7991 "LD_ABS word positive offset, all ff",
7992 .u.insns = {
7993 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
7994 BPF_STMT(BPF_RET | BPF_A, 0x0),
7995 },
7996 CLASSIC,
7997 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
7998 { {0x40, 0xffffffff } },
7999 },
8000 {
8001 "LD_ABS word positive offset, out of bounds",
8002 .u.insns = {
8003 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
8004 BPF_STMT(BPF_RET | BPF_A, 0x0),
8005 },
8006 CLASSIC,
8007 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8008 { {0x3f, 0 }, },
8009 },
8010 {
8011 "LD_ABS word negative offset, out of bounds load",
8012 .u.insns = {
8013 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
8014 BPF_STMT(BPF_RET | BPF_A, 0x0),
8015 },
8016 CLASSIC | FLAG_EXPECTED_FAIL,
8017 .expected_errcode = -EINVAL,
8018 },
8019 {
8020 "LD_ABS word negative offset, in bounds",
8021 .u.insns = {
8022 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
8023 BPF_STMT(BPF_RET | BPF_A, 0x0),
8024 },
8025 CLASSIC,
8026 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8027 { {0x40, 0x25051982 }, },
8028 },
8029 {
8030 "LD_ABS word negative offset, out of bounds",
8031 .u.insns = {
8032 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
8033 BPF_STMT(BPF_RET | BPF_A, 0x0),
8034 },
8035 CLASSIC,
8036 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8037 { {0x3f, 0 }, },
8038 },
8039 {
8040 "LDX_MSH standalone, preserved A",
8041 .u.insns = {
8042 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8043 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
8044 BPF_STMT(BPF_RET | BPF_A, 0x0),
8045 },
8046 CLASSIC,
8047 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8048 { {0x40, 0xffeebbaa }, },
8049 },
8050 {
8051 "LDX_MSH standalone, preserved A 2",
8052 .u.insns = {
8053 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
8054 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
8055 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
8056 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
8057 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
8058 BPF_STMT(BPF_RET | BPF_A, 0x0),
8059 },
8060 CLASSIC,
8061 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8062 { {0x40, 0x175e9d63 }, },
8063 },
8064 {
8065 "LDX_MSH standalone, test result 1",
8066 .u.insns = {
8067 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8068 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
8069 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8070 BPF_STMT(BPF_RET | BPF_A, 0x0),
8071 },
8072 CLASSIC,
8073 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8074 { {0x40, 0x14 }, },
8075 },
8076 {
8077 "LDX_MSH standalone, test result 2",
8078 .u.insns = {
8079 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8080 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
8081 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8082 BPF_STMT(BPF_RET | BPF_A, 0x0),
8083 },
8084 CLASSIC,
8085 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8086 { {0x40, 0x24 }, },
8087 },
8088 {
8089 "LDX_MSH standalone, negative offset",
8090 .u.insns = {
8091 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8092 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
8093 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8094 BPF_STMT(BPF_RET | BPF_A, 0x0),
8095 },
8096 CLASSIC,
8097 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8098 { {0x40, 0 }, },
8099 },
8100 {
8101 "LDX_MSH standalone, negative offset 2",
8102 .u.insns = {
8103 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8104 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
8105 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8106 BPF_STMT(BPF_RET | BPF_A, 0x0),
8107 },
8108 CLASSIC,
8109 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8110 { {0x40, 0x24 }, },
8111 },
8112 {
8113 "LDX_MSH standalone, out of bounds",
8114 .u.insns = {
8115 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
8116 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
8117 BPF_STMT(BPF_MISC | BPF_TXA, 0),
8118 BPF_STMT(BPF_RET | BPF_A, 0x0),
8119 },
8120 CLASSIC,
8121 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
8122 { {0x40, 0 }, },
8123 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02008124 /*
8125 * verify that the interpreter or JIT correctly sets A and X
8126 * to 0.
8127 */
8128 {
8129 "ADD default X",
8130 .u.insns = {
8131 /*
8132 * A = 0x42
8133 * A = A + X
8134 * ret A
8135 */
8136 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8137 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
8138 BPF_STMT(BPF_RET | BPF_A, 0x0),
8139 },
8140 CLASSIC | FLAG_NO_DATA,
8141 {},
8142 { {0x1, 0x42 } },
8143 },
8144 {
8145 "ADD default A",
8146 .u.insns = {
8147 /*
8148 * A = A + 0x42
8149 * ret A
8150 */
8151 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
8152 BPF_STMT(BPF_RET | BPF_A, 0x0),
8153 },
8154 CLASSIC | FLAG_NO_DATA,
8155 {},
8156 { {0x1, 0x42 } },
8157 },
8158 {
8159 "SUB default X",
8160 .u.insns = {
8161 /*
8162 * A = 0x66
8163 * A = A - X
8164 * ret A
8165 */
8166 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
8167 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
8168 BPF_STMT(BPF_RET | BPF_A, 0x0),
8169 },
8170 CLASSIC | FLAG_NO_DATA,
8171 {},
8172 { {0x1, 0x66 } },
8173 },
8174 {
8175 "SUB default A",
8176 .u.insns = {
8177 /*
8178 * A = A - -0x66
8179 * ret A
8180 */
8181 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
8182 BPF_STMT(BPF_RET | BPF_A, 0x0),
8183 },
8184 CLASSIC | FLAG_NO_DATA,
8185 {},
8186 { {0x1, 0x66 } },
8187 },
8188 {
8189 "MUL default X",
8190 .u.insns = {
8191 /*
8192 * A = 0x42
8193 * A = A * X
8194 * ret A
8195 */
8196 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8197 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
8198 BPF_STMT(BPF_RET | BPF_A, 0x0),
8199 },
8200 CLASSIC | FLAG_NO_DATA,
8201 {},
8202 { {0x1, 0x0 } },
8203 },
8204 {
8205 "MUL default A",
8206 .u.insns = {
8207 /*
8208 * A = A * 0x66
8209 * ret A
8210 */
8211 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
8212 BPF_STMT(BPF_RET | BPF_A, 0x0),
8213 },
8214 CLASSIC | FLAG_NO_DATA,
8215 {},
8216 { {0x1, 0x0 } },
8217 },
8218 {
8219 "DIV default X",
8220 .u.insns = {
8221 /*
8222 * A = 0x42
8223 * A = A / X ; this halt the filter execution if X is 0
8224 * ret 0x42
8225 */
8226 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8227 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
8228 BPF_STMT(BPF_RET | BPF_K, 0x42),
8229 },
8230 CLASSIC | FLAG_NO_DATA,
8231 {},
8232 { {0x1, 0x0 } },
8233 },
8234 {
8235 "DIV default A",
8236 .u.insns = {
8237 /*
8238 * A = A / 1
8239 * ret A
8240 */
8241 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
8242 BPF_STMT(BPF_RET | BPF_A, 0x0),
8243 },
8244 CLASSIC | FLAG_NO_DATA,
8245 {},
8246 { {0x1, 0x0 } },
8247 },
8248 {
Yang Shid4e4bc12015-11-04 11:36:37 -08008249 "MOD default X",
8250 .u.insns = {
8251 /*
8252 * A = 0x42
8253 * A = A mod X ; this halt the filter execution if X is 0
8254 * ret 0x42
8255 */
8256 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
8257 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
8258 BPF_STMT(BPF_RET | BPF_K, 0x42),
8259 },
8260 CLASSIC | FLAG_NO_DATA,
8261 {},
8262 { {0x1, 0x0 } },
8263 },
8264 {
8265 "MOD default A",
8266 .u.insns = {
8267 /*
8268 * A = A mod 1
8269 * ret A
8270 */
8271 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
8272 BPF_STMT(BPF_RET | BPF_A, 0x0),
8273 },
8274 CLASSIC | FLAG_NO_DATA,
8275 {},
8276 { {0x1, 0x0 } },
8277 },
8278 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02008279 "JMP EQ default A",
8280 .u.insns = {
8281 /*
8282 * cmp A, 0x0, 0, 1
8283 * ret 0x42
8284 * ret 0x66
8285 */
8286 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
8287 BPF_STMT(BPF_RET | BPF_K, 0x42),
8288 BPF_STMT(BPF_RET | BPF_K, 0x66),
8289 },
8290 CLASSIC | FLAG_NO_DATA,
8291 {},
8292 { {0x1, 0x42 } },
8293 },
8294 {
8295 "JMP EQ default X",
8296 .u.insns = {
8297 /*
8298 * A = 0x0
8299 * cmp A, X, 0, 1
8300 * ret 0x42
8301 * ret 0x66
8302 */
8303 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
8304 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
8305 BPF_STMT(BPF_RET | BPF_K, 0x42),
8306 BPF_STMT(BPF_RET | BPF_K, 0x66),
8307 },
8308 CLASSIC | FLAG_NO_DATA,
8309 {},
8310 { {0x1, 0x42 } },
8311 },
Daniel Borkmannfcd1c912018-01-20 01:24:31 +01008312 /* Checking interpreter vs JIT wrt signed extended imms. */
8313 {
8314 "JNE signed compare, test 1",
8315 .u.insns_int = {
8316 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8317 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8318 BPF_MOV64_REG(R2, R1),
8319 BPF_ALU64_REG(BPF_AND, R2, R3),
8320 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8321 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
8322 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8323 BPF_EXIT_INSN(),
8324 },
8325 INTERNAL,
8326 { },
8327 { { 0, 1 } },
8328 },
8329 {
8330 "JNE signed compare, test 2",
8331 .u.insns_int = {
8332 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8333 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8334 BPF_MOV64_REG(R2, R1),
8335 BPF_ALU64_REG(BPF_AND, R2, R3),
8336 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8337 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
8338 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8339 BPF_EXIT_INSN(),
8340 },
8341 INTERNAL,
8342 { },
8343 { { 0, 1 } },
8344 },
8345 {
8346 "JNE signed compare, test 3",
8347 .u.insns_int = {
8348 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
8349 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
8350 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
8351 BPF_MOV64_REG(R2, R1),
8352 BPF_ALU64_REG(BPF_AND, R2, R3),
8353 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8354 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
8355 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8356 BPF_EXIT_INSN(),
8357 },
8358 INTERNAL,
8359 { },
8360 { { 0, 2 } },
8361 },
8362 {
8363 "JNE signed compare, test 4",
8364 .u.insns_int = {
8365 BPF_LD_IMM64(R1, -17104896),
8366 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8367 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
8368 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8369 BPF_EXIT_INSN(),
8370 },
8371 INTERNAL,
8372 { },
8373 { { 0, 2 } },
8374 },
8375 {
8376 "JNE signed compare, test 5",
8377 .u.insns_int = {
8378 BPF_LD_IMM64(R1, 0xfefb0000),
8379 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8380 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
8381 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8382 BPF_EXIT_INSN(),
8383 },
8384 INTERNAL,
8385 { },
8386 { { 0, 1 } },
8387 },
8388 {
8389 "JNE signed compare, test 6",
8390 .u.insns_int = {
8391 BPF_LD_IMM64(R1, 0x7efb0000),
8392 BPF_ALU32_IMM(BPF_MOV, R0, 1),
8393 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
8394 BPF_ALU32_IMM(BPF_MOV, R0, 2),
8395 BPF_EXIT_INSN(),
8396 },
8397 INTERNAL,
8398 { },
8399 { { 0, 2 } },
8400 },
8401 {
8402 "JNE signed compare, test 7",
8403 .u.insns = {
8404 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
8405 BPF_STMT(BPF_MISC | BPF_TAX, 0),
8406 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
8407 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
8408 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
8409 BPF_STMT(BPF_RET | BPF_K, 1),
8410 BPF_STMT(BPF_RET | BPF_K, 2),
8411 },
8412 CLASSIC | FLAG_NO_DATA,
8413 {},
8414 { { 0, 2 } },
8415 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008416};
8417
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008418static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008419
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008420static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008421{
8422 struct sk_buff *skb;
8423
8424 if (size >= MAX_DATA)
8425 return NULL;
8426
8427 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
8428 if (!skb)
8429 return NULL;
8430
yuan linyude77b962017-06-18 22:48:17 +08008431 __skb_put_data(skb, buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008432
8433 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008434 skb_reset_mac_header(skb);
8435 skb->protocol = htons(ETH_P_IP);
8436 skb->pkt_type = SKB_TYPE;
8437 skb->mark = SKB_MARK;
8438 skb->hash = SKB_HASH;
8439 skb->queue_mapping = SKB_QUEUE_MAP;
8440 skb->vlan_tci = SKB_VLAN_TCI;
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01008441 skb->vlan_present = SKB_VLAN_PRESENT;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01008442 skb->vlan_proto = htons(ETH_P_IP);
Song Liu100811932018-09-27 09:34:41 -07008443 dev_net_set(&dev, &init_net);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008444 skb->dev = &dev;
8445 skb->dev->ifindex = SKB_DEV_IFINDEX;
8446 skb->dev->type = SKB_DEV_TYPE;
8447 skb_set_network_header(skb, min(size, ETH_HLEN));
8448
8449 return skb;
8450}
8451
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008452static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008453{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02008454 struct sk_buff *skb;
8455 struct page *page;
8456
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008457 if (test->aux & FLAG_NO_DATA)
8458 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008459
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008460 /* Test case expects an skb, so populate one. Various
8461 * subtests generate skbs of different sizes based on
8462 * the same data.
8463 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02008464 skb = populate_skb(test->data, test->test[sub].data_size);
8465 if (!skb)
8466 return NULL;
8467
8468 if (test->aux & FLAG_SKB_FRAG) {
8469 /*
8470 * when the test requires a fragmented skb, add a
8471 * single fragment to the skb, filled with
8472 * test->frag_data.
8473 */
8474 void *ptr;
8475
8476 page = alloc_page(GFP_KERNEL);
8477
8478 if (!page)
8479 goto err_kfree_skb;
8480
8481 ptr = kmap(page);
8482 if (!ptr)
8483 goto err_free_page;
8484 memcpy(ptr, test->frag_data, MAX_DATA);
8485 kunmap(page);
8486 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
8487 }
8488
8489 return skb;
8490
8491err_free_page:
8492 __free_page(page);
8493err_kfree_skb:
8494 kfree_skb(skb);
8495 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008496}
8497
8498static void release_test_data(const struct bpf_test *test, void *data)
8499{
8500 if (test->aux & FLAG_NO_DATA)
8501 return;
8502
8503 kfree_skb(data);
8504}
8505
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008506static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008507{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008508 struct sock_filter *fp;
8509 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008510
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008511 if (tests[which].fill_helper)
8512 return tests[which].u.ptr.len;
8513
8514 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07008515 for (len = MAX_INSNS - 1; len > 0; --len)
8516 if (fp[len].code != 0 || fp[len].k != 0)
8517 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008518
Chema Gonzaleze9d94502014-05-30 10:15:12 -07008519 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008520}
8521
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008522static void *filter_pointer(int which)
8523{
8524 if (tests[which].fill_helper)
8525 return tests[which].u.ptr.insns;
8526 else
8527 return tests[which].u.insns;
8528}
8529
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008530static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008531{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008532 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008533 unsigned int flen = filter_length(which);
8534 void *fptr = filter_pointer(which);
8535 struct sock_fprog_kern fprog;
8536 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008537
8538 switch (test_type) {
8539 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008540 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008541 fprog.len = flen;
8542
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008543 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008544 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
Yonghong Song09584b42018-02-02 22:37:15 -08008545 if (*err == tests[which].expected_errcode) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008546 pr_cont("PASS\n");
8547 /* Verifier rejected filter as expected. */
8548 *err = 0;
8549 return NULL;
8550 } else {
8551 pr_cont("UNEXPECTED_PASS\n");
8552 /* Verifier didn't reject the test that's
8553 * bad enough, just return!
8554 */
8555 *err = -EINVAL;
8556 return NULL;
8557 }
8558 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008559 if (*err) {
Alexei Starovoitov290af862018-01-09 10:04:29 -08008560 pr_cont("FAIL to prog_create err=%d len=%d\n",
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008561 *err, fprog.len);
8562 return NULL;
8563 }
8564 break;
8565
8566 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02008567 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008568 if (fp == NULL) {
8569 pr_cont("UNEXPECTED_FAIL no memory left\n");
8570 *err = -ENOMEM;
8571 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008572 }
8573
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008574 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02008575 /* Type doesn't really matter here as long as it's not unspec. */
8576 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008577 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07008578 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008579
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02008580 /* We cannot error here as we don't need type compatibility
8581 * checks.
8582 */
8583 fp = bpf_prog_select_runtime(fp, err);
Alexei Starovoitov290af862018-01-09 10:04:29 -08008584 if (*err) {
8585 pr_cont("FAIL to select_runtime err=%d\n", *err);
8586 return NULL;
8587 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008588 break;
8589 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008590
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008591 *err = 0;
8592 return fp;
8593}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008594
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008595static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008596{
8597 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008598
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008599 switch (test_type) {
8600 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008601 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008602 break;
8603 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008604 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008605 break;
8606 }
8607}
8608
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008609static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008610 int runs, u64 *duration)
8611{
8612 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07008613 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008614
David Miller6eac7792020-02-24 15:01:44 +01008615 migrate_disable();
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008616 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008617
8618 for (i = 0; i < runs; i++)
Andrii Nakryikofb7dd8b2021-08-15 00:05:54 -07008619 ret = bpf_prog_run(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008620
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008621 finish = ktime_get_ns();
David Miller6eac7792020-02-24 15:01:44 +01008622 migrate_enable();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008623
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07008624 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008625 do_div(*duration, runs);
8626
8627 return ret;
8628}
8629
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008630static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008631{
8632 int err_cnt = 0, i, runs = MAX_TESTRUNS;
8633
8634 for (i = 0; i < MAX_SUBTESTS; i++) {
8635 void *data;
8636 u64 duration;
8637 u32 ret;
8638
Johan Almbladh2b7e9f22021-07-21 12:38:22 +02008639 /*
8640 * NOTE: Several sub-tests may be present, in which case
8641 * a zero {data_size, result} tuple indicates the end of
8642 * the sub-test array. The first test is always run,
8643 * even if both data_size and result happen to be zero.
8644 */
8645 if (i > 0 &&
8646 test->test[i].data_size == 0 &&
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008647 test->test[i].result == 0)
8648 break;
8649
8650 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02008651 if (!data && !(test->aux & FLAG_NO_DATA)) {
8652 pr_cont("data generation failed ");
8653 err_cnt++;
8654 break;
8655 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008656 ret = __run_one(fp, data, runs, &duration);
8657 release_test_data(test, data);
8658
8659 if (ret == test->test[i].result) {
8660 pr_cont("%lld ", duration);
8661 } else {
8662 pr_cont("ret %d != %d ", ret,
8663 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008664 err_cnt++;
8665 }
8666 }
8667
8668 return err_cnt;
8669}
8670
Nicolas Schichand2648d42015-08-04 15:19:10 +02008671static char test_name[64];
8672module_param_string(test_name, test_name, sizeof(test_name), 0);
8673
8674static int test_id = -1;
8675module_param(test_id, int, 0);
8676
8677static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
8678module_param_array(test_range, int, NULL, 0);
8679
8680static __init int find_test_index(const char *test_name)
8681{
8682 int i;
8683
8684 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8685 if (!strcmp(tests[i].descr, test_name))
8686 return i;
8687 }
8688 return -1;
8689}
8690
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008691static __init int prepare_bpf_tests(void)
8692{
8693 int i;
8694
Nicolas Schichand2648d42015-08-04 15:19:10 +02008695 if (test_id >= 0) {
8696 /*
8697 * if a test_id was specified, use test_range to
8698 * cover only that test.
8699 */
8700 if (test_id >= ARRAY_SIZE(tests)) {
8701 pr_err("test_bpf: invalid test_id specified.\n");
8702 return -EINVAL;
8703 }
8704
8705 test_range[0] = test_id;
8706 test_range[1] = test_id;
8707 } else if (*test_name) {
8708 /*
8709 * if a test_name was specified, find it and setup
8710 * test_range to cover only that test.
8711 */
8712 int idx = find_test_index(test_name);
8713
8714 if (idx < 0) {
8715 pr_err("test_bpf: no test named '%s' found.\n",
8716 test_name);
8717 return -EINVAL;
8718 }
8719 test_range[0] = idx;
8720 test_range[1] = idx;
8721 } else {
8722 /*
8723 * check that the supplied test_range is valid.
8724 */
8725 if (test_range[0] >= ARRAY_SIZE(tests) ||
8726 test_range[1] >= ARRAY_SIZE(tests) ||
8727 test_range[0] < 0 || test_range[1] < 0) {
8728 pr_err("test_bpf: test_range is out of bound.\n");
8729 return -EINVAL;
8730 }
8731
8732 if (test_range[1] < test_range[0]) {
8733 pr_err("test_bpf: test_range is ending before it starts.\n");
8734 return -EINVAL;
8735 }
8736 }
8737
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02008738 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8739 if (tests[i].fill_helper &&
8740 tests[i].fill_helper(&tests[i]) < 0)
8741 return -ENOMEM;
8742 }
8743
8744 return 0;
8745}
8746
8747static __init void destroy_bpf_tests(void)
8748{
8749 int i;
8750
8751 for (i = 0; i < ARRAY_SIZE(tests); i++) {
8752 if (tests[i].fill_helper)
8753 kfree(tests[i].u.ptr.insns);
8754 }
8755}
8756
Nicolas Schichand2648d42015-08-04 15:19:10 +02008757static bool exclude_test(int test_id)
8758{
8759 return test_id < test_range[0] || test_id > test_range[1];
8760}
8761
Yonghong Song76db8082018-03-21 16:31:04 -07008762static __init struct sk_buff *build_test_skb(void)
8763{
8764 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
8765 struct sk_buff *skb[2];
8766 struct page *page[2];
8767 int i, data_size = 8;
8768
8769 for (i = 0; i < 2; i++) {
8770 page[i] = alloc_page(GFP_KERNEL);
8771 if (!page[i]) {
8772 if (i == 0)
8773 goto err_page0;
8774 else
8775 goto err_page1;
8776 }
8777
8778 /* this will set skb[i]->head_frag */
8779 skb[i] = dev_alloc_skb(headroom + data_size);
8780 if (!skb[i]) {
8781 if (i == 0)
8782 goto err_skb0;
8783 else
8784 goto err_skb1;
8785 }
8786
8787 skb_reserve(skb[i], headroom);
8788 skb_put(skb[i], data_size);
8789 skb[i]->protocol = htons(ETH_P_IP);
8790 skb_reset_network_header(skb[i]);
8791 skb_set_mac_header(skb[i], -ETH_HLEN);
8792
8793 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
8794 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
8795 }
8796
8797 /* setup shinfo */
8798 skb_shinfo(skb[0])->gso_size = 1448;
8799 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
8800 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
8801 skb_shinfo(skb[0])->gso_segs = 0;
8802 skb_shinfo(skb[0])->frag_list = skb[1];
Vadim Fedorenko3384c7c2021-09-10 01:04:09 +03008803 skb_shinfo(skb[0])->hwtstamps.hwtstamp = 1000;
Yonghong Song76db8082018-03-21 16:31:04 -07008804
8805 /* adjust skb[0]'s len */
8806 skb[0]->len += skb[1]->len;
8807 skb[0]->data_len += skb[1]->data_len;
8808 skb[0]->truesize += skb[1]->truesize;
8809
8810 return skb[0];
8811
8812err_skb1:
8813 __free_page(page[1]);
8814err_page1:
8815 kfree_skb(skb[0]);
8816err_skb0:
8817 __free_page(page[0]);
8818err_page0:
8819 return NULL;
8820}
8821
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03008822static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
8823{
8824 unsigned int alloc_size = 2000;
8825 unsigned int headroom = 102, doffset = 72, data_size = 1308;
8826 struct sk_buff *skb[2];
8827 int i;
8828
8829 /* skbs linked in a frag_list, both with linear data, with head_frag=0
8830 * (data allocated by kmalloc), both have tcp data of 1308 bytes
8831 * (total payload is 2616 bytes).
8832 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
8833 */
8834 for (i = 0; i < 2; i++) {
8835 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
8836 if (!skb[i]) {
8837 if (i == 0)
8838 goto err_skb0;
8839 else
8840 goto err_skb1;
8841 }
8842
8843 skb[i]->protocol = htons(ETH_P_IPV6);
8844 skb_reserve(skb[i], headroom);
8845 skb_put(skb[i], doffset + data_size);
8846 skb_reset_network_header(skb[i]);
8847 if (i == 0)
8848 skb_reset_mac_header(skb[i]);
8849 else
8850 skb_set_mac_header(skb[i], -ETH_HLEN);
8851 __skb_pull(skb[i], doffset);
8852 }
8853
8854 /* setup shinfo.
8855 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
8856 * reduced gso_size.
8857 */
8858 skb_shinfo(skb[0])->gso_size = 1288;
8859 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
8860 skb_shinfo(skb[0])->gso_segs = 0;
8861 skb_shinfo(skb[0])->frag_list = skb[1];
8862
8863 /* adjust skb[0]'s len */
8864 skb[0]->len += skb[1]->len;
8865 skb[0]->data_len += skb[1]->len;
8866 skb[0]->truesize += skb[1]->truesize;
8867
8868 return skb[0];
8869
8870err_skb1:
8871 kfree_skb(skb[0]);
8872err_skb0:
8873 return NULL;
8874}
8875
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008876struct skb_segment_test {
8877 const char *descr;
8878 struct sk_buff *(*build_skb)(void);
Yonghong Song76db8082018-03-21 16:31:04 -07008879 netdev_features_t features;
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008880};
8881
8882static struct skb_segment_test skb_segment_tests[] __initconst = {
8883 {
8884 .descr = "gso_with_rx_frags",
8885 .build_skb = build_test_skb,
8886 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
8887 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03008888 },
8889 {
8890 .descr = "gso_linear_no_head_frag",
8891 .build_skb = build_test_skb_linear_no_head_frag,
8892 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
8893 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
8894 NETIF_F_LLTX_BIT | NETIF_F_GRO |
8895 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
8896 NETIF_F_HW_VLAN_STAG_TX_BIT
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008897 }
8898};
8899
8900static __init int test_skb_segment_single(const struct skb_segment_test *test)
8901{
Yonghong Song76db8082018-03-21 16:31:04 -07008902 struct sk_buff *skb, *segs;
8903 int ret = -1;
8904
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008905 skb = test->build_skb();
Yonghong Song76db8082018-03-21 16:31:04 -07008906 if (!skb) {
8907 pr_info("%s: failed to build_test_skb", __func__);
8908 goto done;
8909 }
8910
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008911 segs = skb_segment(skb, test->features);
Dan Carpenter99fe29d2018-03-28 14:48:36 +03008912 if (!IS_ERR(segs)) {
Yonghong Song76db8082018-03-21 16:31:04 -07008913 kfree_skb_list(segs);
8914 ret = 0;
Yonghong Song76db8082018-03-21 16:31:04 -07008915 }
8916 kfree_skb(skb);
8917done:
8918 return ret;
8919}
8920
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03008921static __init int test_skb_segment(void)
8922{
8923 int i, err_cnt = 0, pass_cnt = 0;
8924
8925 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
8926 const struct skb_segment_test *test = &skb_segment_tests[i];
8927
8928 pr_info("#%d %s ", i, test->descr);
8929
8930 if (test_skb_segment_single(test)) {
8931 pr_cont("FAIL\n");
8932 err_cnt++;
8933 } else {
8934 pr_cont("PASS\n");
8935 pass_cnt++;
8936 }
8937 }
8938
8939 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
8940 pass_cnt, err_cnt);
8941 return err_cnt ? -EINVAL : 0;
8942}
8943
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008944static __init int test_bpf(void)
8945{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008946 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02008947 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008948
8949 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07008950 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008951 int err;
8952
Eric Dumazetd40bc962018-02-26 10:52:46 -08008953 cond_resched();
Nicolas Schichand2648d42015-08-04 15:19:10 +02008954 if (exclude_test(i))
8955 continue;
8956
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008957 pr_info("#%d %s ", i, tests[i].descr);
8958
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008959 fp = generate_filter(i, &err);
8960 if (fp == NULL) {
8961 if (err == 0) {
8962 pass_cnt++;
8963 continue;
8964 }
Alexei Starovoitov290af862018-01-09 10:04:29 -08008965 err_cnt++;
8966 continue;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008967 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02008968
8969 pr_cont("jited:%u ", fp->jited);
8970
8971 run_cnt++;
8972 if (fp->jited)
8973 jit_cnt++;
8974
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008975 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008976 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008977
8978 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008979 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008980 err_cnt++;
8981 } else {
8982 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008983 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008984 }
8985 }
8986
Daniel Borkmann327941f2015-04-30 16:17:27 +02008987 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
8988 pass_cnt, err_cnt, jit_cnt, run_cnt);
8989
Daniel Borkmann10f18e02014-05-23 18:44:00 +02008990 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07008991}
8992
Johan Almbladh874be052021-08-09 11:18:29 +02008993struct tail_call_test {
8994 const char *descr;
8995 struct bpf_insn insns[MAX_INSNS];
8996 int result;
8997 int stack_depth;
8998};
8999
9000/*
9001 * Magic marker used in test snippets for tail calls below.
9002 * BPF_LD/MOV to R2 and R2 with this immediate value is replaced
9003 * with the proper values by the test runner.
9004 */
9005#define TAIL_CALL_MARKER 0x7a11ca11
9006
9007/* Special offset to indicate a NULL call target */
9008#define TAIL_CALL_NULL 0x7fff
9009
9010/* Special offset to indicate an out-of-range index */
9011#define TAIL_CALL_INVALID 0x7ffe
9012
9013#define TAIL_CALL(offset) \
9014 BPF_LD_IMM64(R2, TAIL_CALL_MARKER), \
9015 BPF_RAW_INSN(BPF_ALU | BPF_MOV | BPF_K, R3, 0, \
9016 offset, TAIL_CALL_MARKER), \
9017 BPF_JMP_IMM(BPF_TAIL_CALL, 0, 0, 0)
9018
9019/*
9020 * Tail call tests. Each test case may call any other test in the table,
9021 * including itself, specified as a relative index offset from the calling
9022 * test. The index TAIL_CALL_NULL can be used to specify a NULL target
9023 * function to test the JIT error path. Similarly, the index TAIL_CALL_INVALID
9024 * results in a target index that is out of range.
9025 */
9026static struct tail_call_test tail_call_tests[] = {
9027 {
9028 "Tail call leaf",
9029 .insns = {
9030 BPF_ALU64_REG(BPF_MOV, R0, R1),
9031 BPF_ALU64_IMM(BPF_ADD, R0, 1),
9032 BPF_EXIT_INSN(),
9033 },
9034 .result = 1,
9035 },
9036 {
9037 "Tail call 2",
9038 .insns = {
9039 BPF_ALU64_IMM(BPF_ADD, R1, 2),
9040 TAIL_CALL(-1),
9041 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9042 BPF_EXIT_INSN(),
9043 },
9044 .result = 3,
9045 },
9046 {
9047 "Tail call 3",
9048 .insns = {
9049 BPF_ALU64_IMM(BPF_ADD, R1, 3),
9050 TAIL_CALL(-1),
9051 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9052 BPF_EXIT_INSN(),
9053 },
9054 .result = 6,
9055 },
9056 {
9057 "Tail call 4",
9058 .insns = {
9059 BPF_ALU64_IMM(BPF_ADD, R1, 4),
9060 TAIL_CALL(-1),
9061 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9062 BPF_EXIT_INSN(),
9063 },
9064 .result = 10,
9065 },
9066 {
9067 "Tail call error path, max count reached",
9068 .insns = {
9069 BPF_ALU64_IMM(BPF_ADD, R1, 1),
9070 BPF_ALU64_REG(BPF_MOV, R0, R1),
9071 TAIL_CALL(0),
9072 BPF_EXIT_INSN(),
9073 },
9074 .result = MAX_TAIL_CALL_CNT + 1,
9075 },
9076 {
9077 "Tail call error path, NULL target",
9078 .insns = {
9079 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9080 TAIL_CALL(TAIL_CALL_NULL),
9081 BPF_ALU64_IMM(BPF_MOV, R0, 1),
9082 BPF_EXIT_INSN(),
9083 },
9084 .result = 1,
9085 },
9086 {
9087 "Tail call error path, index out of range",
9088 .insns = {
9089 BPF_ALU64_IMM(BPF_MOV, R0, -1),
9090 TAIL_CALL(TAIL_CALL_INVALID),
9091 BPF_ALU64_IMM(BPF_MOV, R0, 1),
9092 BPF_EXIT_INSN(),
9093 },
9094 .result = 1,
9095 },
9096};
9097
9098static void __init destroy_tail_call_tests(struct bpf_array *progs)
9099{
9100 int i;
9101
9102 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++)
9103 if (progs->ptrs[i])
9104 bpf_prog_free(progs->ptrs[i]);
9105 kfree(progs);
9106}
9107
9108static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
9109{
9110 int ntests = ARRAY_SIZE(tail_call_tests);
9111 struct bpf_array *progs;
9112 int which, err;
9113
9114 /* Allocate the table of programs to be used for tall calls */
9115 progs = kzalloc(sizeof(*progs) + (ntests + 1) * sizeof(progs->ptrs[0]),
9116 GFP_KERNEL);
9117 if (!progs)
9118 goto out_nomem;
9119
9120 /* Create all eBPF programs and populate the table */
9121 for (which = 0; which < ntests; which++) {
9122 struct tail_call_test *test = &tail_call_tests[which];
9123 struct bpf_prog *fp;
9124 int len, i;
9125
9126 /* Compute the number of program instructions */
9127 for (len = 0; len < MAX_INSNS; len++) {
9128 struct bpf_insn *insn = &test->insns[len];
9129
9130 if (len < MAX_INSNS - 1 &&
9131 insn->code == (BPF_LD | BPF_DW | BPF_IMM))
9132 len++;
9133 if (insn->code == 0)
9134 break;
9135 }
9136
9137 /* Allocate and initialize the program */
9138 fp = bpf_prog_alloc(bpf_prog_size(len), 0);
9139 if (!fp)
9140 goto out_nomem;
9141
9142 fp->len = len;
9143 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
9144 fp->aux->stack_depth = test->stack_depth;
9145 memcpy(fp->insnsi, test->insns, len * sizeof(struct bpf_insn));
9146
9147 /* Relocate runtime tail call offsets and addresses */
9148 for (i = 0; i < len; i++) {
9149 struct bpf_insn *insn = &fp->insnsi[i];
9150
9151 if (insn->imm != TAIL_CALL_MARKER)
9152 continue;
9153
9154 switch (insn->code) {
9155 case BPF_LD | BPF_DW | BPF_IMM:
9156 insn[0].imm = (u32)(long)progs;
9157 insn[1].imm = ((u64)(long)progs) >> 32;
9158 break;
9159
9160 case BPF_ALU | BPF_MOV | BPF_K:
9161 if (insn->off == TAIL_CALL_NULL)
9162 insn->imm = ntests;
9163 else if (insn->off == TAIL_CALL_INVALID)
9164 insn->imm = ntests + 1;
9165 else
9166 insn->imm = which + insn->off;
9167 insn->off = 0;
9168 }
9169 }
9170
9171 fp = bpf_prog_select_runtime(fp, &err);
9172 if (err)
9173 goto out_err;
9174
9175 progs->ptrs[which] = fp;
9176 }
9177
9178 /* The last entry contains a NULL program pointer */
9179 progs->map.max_entries = ntests + 1;
9180 *pprogs = progs;
9181 return 0;
9182
9183out_nomem:
9184 err = -ENOMEM;
9185
9186out_err:
9187 if (progs)
9188 destroy_tail_call_tests(progs);
9189 return err;
9190}
9191
9192static __init int test_tail_calls(struct bpf_array *progs)
9193{
9194 int i, err_cnt = 0, pass_cnt = 0;
9195 int jit_cnt = 0, run_cnt = 0;
9196
9197 for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
9198 struct tail_call_test *test = &tail_call_tests[i];
9199 struct bpf_prog *fp = progs->ptrs[i];
9200 u64 duration;
9201 int ret;
9202
9203 cond_resched();
9204
9205 pr_info("#%d %s ", i, test->descr);
9206 if (!fp) {
9207 err_cnt++;
9208 continue;
9209 }
9210 pr_cont("jited:%u ", fp->jited);
9211
9212 run_cnt++;
9213 if (fp->jited)
9214 jit_cnt++;
9215
9216 ret = __run_one(fp, NULL, MAX_TESTRUNS, &duration);
9217 if (ret == test->result) {
9218 pr_cont("%lld PASS", duration);
9219 pass_cnt++;
9220 } else {
9221 pr_cont("ret %d != %d FAIL", ret, test->result);
9222 err_cnt++;
9223 }
9224 }
9225
9226 pr_info("%s: Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
9227 __func__, pass_cnt, err_cnt, jit_cnt, run_cnt);
9228
9229 return err_cnt ? -EINVAL : 0;
9230}
9231
Alexei Starovoitov64a89462014-05-08 14:10:52 -07009232static int __init test_bpf_init(void)
9233{
Johan Almbladh874be052021-08-09 11:18:29 +02009234 struct bpf_array *progs = NULL;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02009235 int ret;
9236
9237 ret = prepare_bpf_tests();
9238 if (ret < 0)
9239 return ret;
9240
9241 ret = test_bpf();
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02009242 destroy_bpf_tests();
Yonghong Song76db8082018-03-21 16:31:04 -07009243 if (ret)
9244 return ret;
9245
Johan Almbladh874be052021-08-09 11:18:29 +02009246 ret = prepare_tail_call_tests(&progs);
9247 if (ret)
9248 return ret;
9249 ret = test_tail_calls(progs);
9250 destroy_tail_call_tests(progs);
9251 if (ret)
9252 return ret;
9253
Yonghong Song76db8082018-03-21 16:31:04 -07009254 return test_skb_segment();
Alexei Starovoitov64a89462014-05-08 14:10:52 -07009255}
9256
9257static void __exit test_bpf_exit(void)
9258{
9259}
9260
9261module_init(test_bpf_init);
9262module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02009263
Alexei Starovoitov64a89462014-05-08 14:10:52 -07009264MODULE_LICENSE("GPL");