blob: 8bca780e3613235aedd4eea117c16a08934743a0 [file] [log] [blame]
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001/*
2 * Testsuite for BPF interpreter and BPF JIT compiler
3 *
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/filter.h>
21#include <linux/skbuff.h>
22#include <linux/netdevice.h>
23#include <linux/if_vlan.h>
24
Daniel Borkmann10f18e02014-05-23 18:44:00 +020025/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070026#define MAX_SUBTESTS 3
Daniel Borkmann10f18e02014-05-23 18:44:00 +020027#define MAX_TESTRUNS 10000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070028#define MAX_DATA 128
29#define MAX_INSNS 512
30#define MAX_K 0xffffFFFF
31
Daniel Borkmann10f18e02014-05-23 18:44:00 +020032/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070033#define SKB_TYPE 3
34#define SKB_MARK 0x1234aaaa
35#define SKB_HASH 0x1234aaab
36#define SKB_QUEUE_MAP 123
37#define SKB_VLAN_TCI 0xffff
38#define SKB_DEV_IFINDEX 577
39#define SKB_DEV_TYPE 588
40
Daniel Borkmann10f18e02014-05-23 18:44:00 +020041/* Redefine REGs to make tests less verbose */
42#define R0 BPF_REG_0
43#define R1 BPF_REG_1
44#define R2 BPF_REG_2
45#define R3 BPF_REG_3
46#define R4 BPF_REG_4
47#define R5 BPF_REG_5
48#define R6 BPF_REG_6
49#define R7 BPF_REG_7
50#define R8 BPF_REG_8
51#define R9 BPF_REG_9
52#define R10 BPF_REG_10
53
54/* Flags that can be passed to test cases */
55#define FLAG_NO_DATA BIT(0)
56#define FLAG_EXPECTED_FAIL BIT(1)
57
58enum {
59 CLASSIC = BIT(6), /* Old BPF instructions only. */
60 INTERNAL = BIT(7), /* Extended instruction set. */
61};
62
63#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070064
65struct bpf_test {
66 const char *descr;
67 union {
68 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070069 struct bpf_insn insns_int[MAX_INSNS];
Andrew Mortonece80492014-05-22 10:16:46 -070070 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020071 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070072 __u8 data[MAX_DATA];
73 struct {
74 int data_size;
75 __u32 result;
76 } test[MAX_SUBTESTS];
77};
78
79static struct bpf_test tests[] = {
80 {
81 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -070082 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -070083 BPF_STMT(BPF_LD | BPF_IMM, 1),
84 BPF_STMT(BPF_MISC | BPF_TAX, 0),
85 BPF_STMT(BPF_LD | BPF_IMM, 2),
86 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
87 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
88 BPF_STMT(BPF_MISC | BPF_TAX, 0),
89 BPF_STMT(BPF_LD | BPF_LEN, 0),
90 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
91 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
92 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
93 BPF_STMT(BPF_RET | BPF_A, 0)
94 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +020095 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -070096 { 10, 20, 30, 40, 50 },
97 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
98 },
99 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700100 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700101 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700102 BPF_STMT(BPF_LDX | BPF_LEN, 0),
103 BPF_STMT(BPF_MISC | BPF_TXA, 0),
104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
105 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
106 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200107 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700108 { 10, 20, 30, 40, 50 },
109 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
110 },
111 {
112 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700113 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700114 BPF_STMT(BPF_LD | BPF_IMM, 1),
115 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
116 BPF_STMT(BPF_LDX | BPF_IMM, 3),
117 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
118 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
119 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
120 BPF_STMT(BPF_RET | BPF_A, 0)
121 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200122 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700123 { },
124 { { 0, 0xfffffffd } }
125 },
126 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300127 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700128 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700129 BPF_STMT(BPF_LD | BPF_IMM, 8),
130 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
131 BPF_STMT(BPF_MISC | BPF_TAX, 0),
132 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
133 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
134 BPF_STMT(BPF_MISC | BPF_TAX, 0),
135 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
136 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300137 BPF_STMT(BPF_MISC | BPF_TAX, 0),
138 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
139 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
140 BPF_STMT(BPF_MISC | BPF_TAX, 0),
141 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
142 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700143 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
144 BPF_STMT(BPF_RET | BPF_A, 0)
145 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200146 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700147 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300148 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700149 },
150 {
151 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700152 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700153 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
154 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
155 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
156 BPF_STMT(BPF_MISC | BPF_TAX, 0),
157 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
158 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
159 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
160 BPF_STMT(BPF_RET | BPF_A, 0)
161 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200162 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700163 { },
164 { { 0, 0x800000ff }, { 1, 0x800000ff } },
165 },
166 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700167 "LD_IMM_0",
168 .u.insns = {
169 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
170 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
171 BPF_STMT(BPF_RET | BPF_K, 0),
172 BPF_STMT(BPF_RET | BPF_K, 1),
173 },
174 CLASSIC,
175 { },
176 { { 1, 1 } },
177 },
178 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700179 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700180 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700181 BPF_STMT(BPF_LDX | BPF_LEN, 0),
182 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
183 BPF_STMT(BPF_RET | BPF_K, 1)
184 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200185 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700186 { },
187 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
188 },
189 {
190 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700191 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700192 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
193 BPF_STMT(BPF_RET | BPF_K, 1)
194 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200195 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700196 { },
197 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
198 },
199 {
200 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700201 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700202 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
203 BPF_STMT(BPF_MISC | BPF_TAX, 0),
204 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
205 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
206 BPF_STMT(BPF_RET | BPF_A, 0)
207 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200208 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700209 { 1, 2, 3 },
210 { { 1, 0 }, { 2, 3 } },
211 },
212 {
213 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700214 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700215 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
216 BPF_STMT(BPF_LDX | BPF_LEN, 0),
217 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
218 BPF_STMT(BPF_MISC | BPF_TAX, 0),
219 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
220 BPF_STMT(BPF_RET | BPF_A, 0)
221 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200222 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700223 { 1, 2, 3, 0xff },
224 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
225 },
226 {
227 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700228 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700229 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
230 BPF_STMT(BPF_MISC | BPF_TAX, 0),
231 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
232 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
233 BPF_STMT(BPF_RET | BPF_A, 0)
234 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200235 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700236 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
237 { { 15, 0 }, { 16, 3 } },
238 },
239 {
240 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700241 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700242 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
243 BPF_STMT(BPF_LDX | BPF_LEN, 0),
244 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
245 BPF_STMT(BPF_MISC | BPF_TAX, 0),
246 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
247 BPF_STMT(BPF_RET | BPF_A, 0)
248 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200249 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700250 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
251 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
252 },
253 {
254 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700255 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700256 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
257 SKF_AD_OFF + SKF_AD_PKTTYPE),
258 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
259 BPF_STMT(BPF_RET | BPF_K, 1),
260 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
261 SKF_AD_OFF + SKF_AD_PKTTYPE),
262 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
263 BPF_STMT(BPF_RET | BPF_K, 1),
264 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
265 SKF_AD_OFF + SKF_AD_PKTTYPE),
266 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
267 BPF_STMT(BPF_RET | BPF_K, 1),
268 BPF_STMT(BPF_RET | BPF_A, 0)
269 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200270 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700271 { },
272 { { 1, 3 }, { 10, 3 } },
273 },
274 {
275 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700276 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700277 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
278 SKF_AD_OFF + SKF_AD_MARK),
279 BPF_STMT(BPF_RET | BPF_A, 0)
280 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200281 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700282 { },
283 { { 1, SKB_MARK}, { 10, SKB_MARK} },
284 },
285 {
286 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700287 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700288 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
289 SKF_AD_OFF + SKF_AD_RXHASH),
290 BPF_STMT(BPF_RET | BPF_A, 0)
291 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200292 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700293 { },
294 { { 1, SKB_HASH}, { 10, SKB_HASH} },
295 },
296 {
297 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700298 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700299 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
300 SKF_AD_OFF + SKF_AD_QUEUE),
301 BPF_STMT(BPF_RET | BPF_A, 0)
302 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200303 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700304 { },
305 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
306 },
307 {
308 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700309 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700310 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
311 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
312 BPF_STMT(BPF_RET | BPF_K, 0),
313 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
314 SKF_AD_OFF + SKF_AD_PROTOCOL),
315 BPF_STMT(BPF_MISC | BPF_TAX, 0),
316 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
317 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
318 BPF_STMT(BPF_RET | BPF_K, 0),
319 BPF_STMT(BPF_MISC | BPF_TXA, 0),
320 BPF_STMT(BPF_RET | BPF_A, 0)
321 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200322 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700323 { 10, 20, 30 },
324 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
325 },
326 {
327 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700328 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700329 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
330 SKF_AD_OFF + SKF_AD_VLAN_TAG),
331 BPF_STMT(BPF_RET | BPF_A, 0)
332 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200333 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700334 { },
335 {
336 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
337 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
338 },
339 },
340 {
341 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700342 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700343 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
344 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
345 BPF_STMT(BPF_RET | BPF_A, 0)
346 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200347 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700348 { },
349 {
350 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
351 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
352 },
353 },
354 {
355 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700356 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700357 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
358 SKF_AD_OFF + SKF_AD_IFINDEX),
359 BPF_STMT(BPF_RET | BPF_A, 0)
360 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200361 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700362 { },
363 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
364 },
365 {
366 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700367 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700368 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
369 SKF_AD_OFF + SKF_AD_HATYPE),
370 BPF_STMT(BPF_RET | BPF_A, 0)
371 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200372 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700373 { },
374 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
375 },
376 {
377 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700378 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700379 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
380 SKF_AD_OFF + SKF_AD_CPU),
381 BPF_STMT(BPF_MISC | BPF_TAX, 0),
382 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
383 SKF_AD_OFF + SKF_AD_CPU),
384 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
385 BPF_STMT(BPF_RET | BPF_A, 0)
386 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200387 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700388 { },
389 { { 1, 0 }, { 10, 0 } },
390 },
391 {
392 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700393 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700394 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700395 BPF_STMT(BPF_MISC | BPF_TXA, 0),
396 BPF_STMT(BPF_LDX | BPF_IMM, 3),
397 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
398 SKF_AD_OFF + SKF_AD_NLATTR),
399 BPF_STMT(BPF_RET | BPF_A, 0)
400 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200401 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700402#ifdef __BIG_ENDIAN
403 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
404#else
405 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
406#endif
407 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700408 },
409 {
410 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700411 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700412 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700413 BPF_STMT(BPF_LDX | BPF_IMM, 3),
414 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
415 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700416 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700417 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
418 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700419 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700420 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
421 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700422 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700423 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
424 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700425 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700426 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
427 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700428 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700429 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
430 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700431 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700432 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
433 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700434 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700435 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
436 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
437 BPF_STMT(BPF_RET | BPF_A, 0)
438 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200439 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700440#ifdef __BIG_ENDIAN
441 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
442#else
443 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
444#endif
445 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700446 },
447 {
448 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700449 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700450 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
451 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
452 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
453 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
454 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
455 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
456 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
457 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
458 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
459 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
460 BPF_STMT(BPF_RET | BPF_A, 0)
461 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200462 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700463 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
464 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
465 * id 9737, seq 1, length 64
466 */
467 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
468 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
469 0x08, 0x00,
470 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
471 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
472 { { 30, 0 }, { 100, 42 } },
473 },
474 {
475 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700476 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700477 BPF_STMT(BPF_LD | BPF_IMM, 10),
478 BPF_STMT(BPF_LDX | BPF_IMM, 300),
479 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
480 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
481 BPF_STMT(BPF_RET | BPF_A, 0)
482 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200483 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700484 { },
485 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
486 },
487 {
488 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700489 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700490 BPF_STMT(BPF_LDX | BPF_LEN, 0),
491 BPF_STMT(BPF_LD | BPF_IMM, 2),
492 BPF_STMT(BPF_ALU | BPF_RSH, 1),
493 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
494 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
495 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
496 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
497 BPF_STMT(BPF_STX, 15), /* M3 = len */
498 BPF_STMT(BPF_LDX | BPF_MEM, 1),
499 BPF_STMT(BPF_LD | BPF_MEM, 2),
500 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
501 BPF_STMT(BPF_LDX | BPF_MEM, 15),
502 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
503 BPF_STMT(BPF_RET | BPF_A, 0)
504 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200505 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700506 { },
507 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
508 },
509 {
510 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700511 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700512 BPF_STMT(BPF_LDX | BPF_LEN, 0),
513 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
514 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
515 BPF_STMT(BPF_RET | BPF_K, 1),
516 BPF_STMT(BPF_RET | BPF_K, MAX_K)
517 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200518 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700519 { 3, 3, 3, 3, 3 },
520 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
521 },
522 {
523 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700524 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700525 BPF_STMT(BPF_LDX | BPF_LEN, 0),
526 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
527 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
528 BPF_STMT(BPF_RET | BPF_K, 1),
529 BPF_STMT(BPF_RET | BPF_K, MAX_K)
530 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200531 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700532 { 4, 4, 4, 3, 3 },
533 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
534 },
535 {
536 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700537 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700538 BPF_STMT(BPF_LDX | BPF_LEN, 0),
539 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
540 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
541 BPF_STMT(BPF_RET | BPF_K, 10),
542 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
543 BPF_STMT(BPF_RET | BPF_K, 20),
544 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
545 BPF_STMT(BPF_RET | BPF_K, 30),
546 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
547 BPF_STMT(BPF_RET | BPF_K, 40),
548 BPF_STMT(BPF_RET | BPF_K, MAX_K)
549 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200550 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700551 { 1, 2, 3, 4, 5 },
552 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
553 },
554 {
555 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700556 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700557 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
558 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
559 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
560 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
561 BPF_STMT(BPF_LDX | BPF_LEN, 0),
562 BPF_STMT(BPF_MISC | BPF_TXA, 0),
563 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
564 BPF_STMT(BPF_MISC | BPF_TAX, 0),
565 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
566 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
567 BPF_STMT(BPF_RET | BPF_K, 10),
568 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
569 BPF_STMT(BPF_RET | BPF_K, 20),
570 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
571 BPF_STMT(BPF_RET | BPF_K, 30),
572 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
573 BPF_STMT(BPF_RET | BPF_K, 30),
574 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
575 BPF_STMT(BPF_RET | BPF_K, 30),
576 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
577 BPF_STMT(BPF_RET | BPF_K, 30),
578 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
579 BPF_STMT(BPF_RET | BPF_K, 30),
580 BPF_STMT(BPF_RET | BPF_K, MAX_K)
581 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200582 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700583 { 0, 0xAA, 0x55, 1 },
584 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
585 },
586 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700587 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -0700588 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +0200589 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
591 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
592 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
593 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
594 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
595 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
596 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
597 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
598 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
599 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
600 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
601 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
602 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
603 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
604 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
605 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
606 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
607 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
608 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
609 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
610 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
611 BPF_STMT(BPF_RET | BPF_K, 0xffff),
612 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700613 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200614 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700615 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
616 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
617 * seq 1305692979:1305693027, ack 3650467037, win 65535,
618 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
619 */
620 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
621 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
622 0x08, 0x00,
623 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
624 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
625 0x0a, 0x01, 0x01, 0x95, /* ip src */
626 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
627 0xc2, 0x24,
628 0x00, 0x16 /* dst port */ },
629 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
630 },
631 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700632 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -0700633 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700634 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
635 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
636 * (len > 115 or len < 30000000000)' -d
637 */
Daniel Borkmannce25b682014-05-26 20:17:35 +0200638 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
639 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
640 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
641 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
642 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
643 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
644 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
645 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
646 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
647 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
648 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
649 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
650 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
651 BPF_STMT(BPF_ST, 1),
652 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
653 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
654 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
655 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
656 BPF_STMT(BPF_LD | BPF_MEM, 1),
657 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
658 BPF_STMT(BPF_ST, 5),
659 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
660 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
661 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
662 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
663 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
664 BPF_STMT(BPF_LD | BPF_MEM, 5),
665 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
666 BPF_STMT(BPF_LD | BPF_LEN, 0),
667 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
668 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
669 BPF_STMT(BPF_RET | BPF_K, 0xffff),
670 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700671 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200672 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700673 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
674 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
675 0x08, 0x00,
676 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
677 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
678 0x0a, 0x01, 0x01, 0x95, /* ip src */
679 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
680 0xc2, 0x24,
681 0x00, 0x16 /* dst port */ },
682 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
683 },
684 {
685 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -0700686 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700687 /* check that unitialized X and A contain zeros */
688 BPF_STMT(BPF_MISC | BPF_TXA, 0),
689 BPF_STMT(BPF_RET | BPF_A, 0)
690 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200691 CLASSIC,
692 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700693 { {1, 0}, {2, 0} },
694 },
695 {
696 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -0700697 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700698 BPF_ALU64_IMM(BPF_MOV, R1, 1),
699 BPF_ALU64_IMM(BPF_ADD, R1, 2),
700 BPF_ALU64_IMM(BPF_MOV, R2, 3),
701 BPF_ALU64_REG(BPF_SUB, R1, R2),
702 BPF_ALU64_IMM(BPF_ADD, R1, -1),
703 BPF_ALU64_IMM(BPF_MUL, R1, 3),
704 BPF_ALU64_REG(BPF_MOV, R0, R1),
705 BPF_EXIT_INSN(),
706 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200707 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700708 { },
709 { { 0, 0xfffffffd } }
710 },
711 {
712 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -0700713 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700714 BPF_ALU64_IMM(BPF_MOV, R0, -1),
715 BPF_ALU64_IMM(BPF_MOV, R1, -1),
716 BPF_ALU64_IMM(BPF_MOV, R2, 3),
717 BPF_ALU64_REG(BPF_MUL, R1, R2),
718 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
719 BPF_EXIT_INSN(),
720 BPF_ALU64_IMM(BPF_MOV, R0, 1),
721 BPF_EXIT_INSN(),
722 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200723 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700724 { },
725 { { 0, 1 } }
726 },
727 {
728 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -0700729 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700730 BPF_ALU32_IMM(BPF_MOV, R0, -1),
731 BPF_ALU32_IMM(BPF_MOV, R1, -1),
732 BPF_ALU32_IMM(BPF_MOV, R2, 3),
733 BPF_ALU64_REG(BPF_MUL, R1, R2),
734 BPF_ALU64_IMM(BPF_RSH, R1, 8),
735 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
736 BPF_EXIT_INSN(),
737 BPF_ALU32_IMM(BPF_MOV, R0, 1),
738 BPF_EXIT_INSN(),
739 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200740 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700741 { },
742 { { 0, 1 } }
743 },
744 {
745 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -0700746 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700747 BPF_ALU32_IMM(BPF_MOV, R0, -1),
748 BPF_ALU64_IMM(BPF_MOV, R1, -1),
749 BPF_ALU32_IMM(BPF_MOV, R2, 3),
750 BPF_ALU32_REG(BPF_MUL, R1, R2),
751 BPF_ALU64_IMM(BPF_RSH, R1, 8),
752 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
753 BPF_EXIT_INSN(),
754 BPF_ALU32_IMM(BPF_MOV, R0, 1),
755 BPF_EXIT_INSN(),
756 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200757 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700758 { },
759 { { 0, 1 } }
760 },
761 {
762 /* Have to test all register combinations, since
763 * JITing of different registers will produce
764 * different asm code.
765 */
766 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -0700767 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700768 BPF_ALU64_IMM(BPF_MOV, R0, 0),
769 BPF_ALU64_IMM(BPF_MOV, R1, 1),
770 BPF_ALU64_IMM(BPF_MOV, R2, 2),
771 BPF_ALU64_IMM(BPF_MOV, R3, 3),
772 BPF_ALU64_IMM(BPF_MOV, R4, 4),
773 BPF_ALU64_IMM(BPF_MOV, R5, 5),
774 BPF_ALU64_IMM(BPF_MOV, R6, 6),
775 BPF_ALU64_IMM(BPF_MOV, R7, 7),
776 BPF_ALU64_IMM(BPF_MOV, R8, 8),
777 BPF_ALU64_IMM(BPF_MOV, R9, 9),
778 BPF_ALU64_IMM(BPF_ADD, R0, 20),
779 BPF_ALU64_IMM(BPF_ADD, R1, 20),
780 BPF_ALU64_IMM(BPF_ADD, R2, 20),
781 BPF_ALU64_IMM(BPF_ADD, R3, 20),
782 BPF_ALU64_IMM(BPF_ADD, R4, 20),
783 BPF_ALU64_IMM(BPF_ADD, R5, 20),
784 BPF_ALU64_IMM(BPF_ADD, R6, 20),
785 BPF_ALU64_IMM(BPF_ADD, R7, 20),
786 BPF_ALU64_IMM(BPF_ADD, R8, 20),
787 BPF_ALU64_IMM(BPF_ADD, R9, 20),
788 BPF_ALU64_IMM(BPF_SUB, R0, 10),
789 BPF_ALU64_IMM(BPF_SUB, R1, 10),
790 BPF_ALU64_IMM(BPF_SUB, R2, 10),
791 BPF_ALU64_IMM(BPF_SUB, R3, 10),
792 BPF_ALU64_IMM(BPF_SUB, R4, 10),
793 BPF_ALU64_IMM(BPF_SUB, R5, 10),
794 BPF_ALU64_IMM(BPF_SUB, R6, 10),
795 BPF_ALU64_IMM(BPF_SUB, R7, 10),
796 BPF_ALU64_IMM(BPF_SUB, R8, 10),
797 BPF_ALU64_IMM(BPF_SUB, R9, 10),
798 BPF_ALU64_REG(BPF_ADD, R0, R0),
799 BPF_ALU64_REG(BPF_ADD, R0, R1),
800 BPF_ALU64_REG(BPF_ADD, R0, R2),
801 BPF_ALU64_REG(BPF_ADD, R0, R3),
802 BPF_ALU64_REG(BPF_ADD, R0, R4),
803 BPF_ALU64_REG(BPF_ADD, R0, R5),
804 BPF_ALU64_REG(BPF_ADD, R0, R6),
805 BPF_ALU64_REG(BPF_ADD, R0, R7),
806 BPF_ALU64_REG(BPF_ADD, R0, R8),
807 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
808 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
809 BPF_EXIT_INSN(),
810 BPF_ALU64_REG(BPF_ADD, R1, R0),
811 BPF_ALU64_REG(BPF_ADD, R1, R1),
812 BPF_ALU64_REG(BPF_ADD, R1, R2),
813 BPF_ALU64_REG(BPF_ADD, R1, R3),
814 BPF_ALU64_REG(BPF_ADD, R1, R4),
815 BPF_ALU64_REG(BPF_ADD, R1, R5),
816 BPF_ALU64_REG(BPF_ADD, R1, R6),
817 BPF_ALU64_REG(BPF_ADD, R1, R7),
818 BPF_ALU64_REG(BPF_ADD, R1, R8),
819 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
820 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
821 BPF_EXIT_INSN(),
822 BPF_ALU64_REG(BPF_ADD, R2, R0),
823 BPF_ALU64_REG(BPF_ADD, R2, R1),
824 BPF_ALU64_REG(BPF_ADD, R2, R2),
825 BPF_ALU64_REG(BPF_ADD, R2, R3),
826 BPF_ALU64_REG(BPF_ADD, R2, R4),
827 BPF_ALU64_REG(BPF_ADD, R2, R5),
828 BPF_ALU64_REG(BPF_ADD, R2, R6),
829 BPF_ALU64_REG(BPF_ADD, R2, R7),
830 BPF_ALU64_REG(BPF_ADD, R2, R8),
831 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
832 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
833 BPF_EXIT_INSN(),
834 BPF_ALU64_REG(BPF_ADD, R3, R0),
835 BPF_ALU64_REG(BPF_ADD, R3, R1),
836 BPF_ALU64_REG(BPF_ADD, R3, R2),
837 BPF_ALU64_REG(BPF_ADD, R3, R3),
838 BPF_ALU64_REG(BPF_ADD, R3, R4),
839 BPF_ALU64_REG(BPF_ADD, R3, R5),
840 BPF_ALU64_REG(BPF_ADD, R3, R6),
841 BPF_ALU64_REG(BPF_ADD, R3, R7),
842 BPF_ALU64_REG(BPF_ADD, R3, R8),
843 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
844 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
845 BPF_EXIT_INSN(),
846 BPF_ALU64_REG(BPF_ADD, R4, R0),
847 BPF_ALU64_REG(BPF_ADD, R4, R1),
848 BPF_ALU64_REG(BPF_ADD, R4, R2),
849 BPF_ALU64_REG(BPF_ADD, R4, R3),
850 BPF_ALU64_REG(BPF_ADD, R4, R4),
851 BPF_ALU64_REG(BPF_ADD, R4, R5),
852 BPF_ALU64_REG(BPF_ADD, R4, R6),
853 BPF_ALU64_REG(BPF_ADD, R4, R7),
854 BPF_ALU64_REG(BPF_ADD, R4, R8),
855 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
856 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
857 BPF_EXIT_INSN(),
858 BPF_ALU64_REG(BPF_ADD, R5, R0),
859 BPF_ALU64_REG(BPF_ADD, R5, R1),
860 BPF_ALU64_REG(BPF_ADD, R5, R2),
861 BPF_ALU64_REG(BPF_ADD, R5, R3),
862 BPF_ALU64_REG(BPF_ADD, R5, R4),
863 BPF_ALU64_REG(BPF_ADD, R5, R5),
864 BPF_ALU64_REG(BPF_ADD, R5, R6),
865 BPF_ALU64_REG(BPF_ADD, R5, R7),
866 BPF_ALU64_REG(BPF_ADD, R5, R8),
867 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
868 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
869 BPF_EXIT_INSN(),
870 BPF_ALU64_REG(BPF_ADD, R6, R0),
871 BPF_ALU64_REG(BPF_ADD, R6, R1),
872 BPF_ALU64_REG(BPF_ADD, R6, R2),
873 BPF_ALU64_REG(BPF_ADD, R6, R3),
874 BPF_ALU64_REG(BPF_ADD, R6, R4),
875 BPF_ALU64_REG(BPF_ADD, R6, R5),
876 BPF_ALU64_REG(BPF_ADD, R6, R6),
877 BPF_ALU64_REG(BPF_ADD, R6, R7),
878 BPF_ALU64_REG(BPF_ADD, R6, R8),
879 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
880 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
881 BPF_EXIT_INSN(),
882 BPF_ALU64_REG(BPF_ADD, R7, R0),
883 BPF_ALU64_REG(BPF_ADD, R7, R1),
884 BPF_ALU64_REG(BPF_ADD, R7, R2),
885 BPF_ALU64_REG(BPF_ADD, R7, R3),
886 BPF_ALU64_REG(BPF_ADD, R7, R4),
887 BPF_ALU64_REG(BPF_ADD, R7, R5),
888 BPF_ALU64_REG(BPF_ADD, R7, R6),
889 BPF_ALU64_REG(BPF_ADD, R7, R7),
890 BPF_ALU64_REG(BPF_ADD, R7, R8),
891 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
892 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
893 BPF_EXIT_INSN(),
894 BPF_ALU64_REG(BPF_ADD, R8, R0),
895 BPF_ALU64_REG(BPF_ADD, R8, R1),
896 BPF_ALU64_REG(BPF_ADD, R8, R2),
897 BPF_ALU64_REG(BPF_ADD, R8, R3),
898 BPF_ALU64_REG(BPF_ADD, R8, R4),
899 BPF_ALU64_REG(BPF_ADD, R8, R5),
900 BPF_ALU64_REG(BPF_ADD, R8, R6),
901 BPF_ALU64_REG(BPF_ADD, R8, R7),
902 BPF_ALU64_REG(BPF_ADD, R8, R8),
903 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
904 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
905 BPF_EXIT_INSN(),
906 BPF_ALU64_REG(BPF_ADD, R9, R0),
907 BPF_ALU64_REG(BPF_ADD, R9, R1),
908 BPF_ALU64_REG(BPF_ADD, R9, R2),
909 BPF_ALU64_REG(BPF_ADD, R9, R3),
910 BPF_ALU64_REG(BPF_ADD, R9, R4),
911 BPF_ALU64_REG(BPF_ADD, R9, R5),
912 BPF_ALU64_REG(BPF_ADD, R9, R6),
913 BPF_ALU64_REG(BPF_ADD, R9, R7),
914 BPF_ALU64_REG(BPF_ADD, R9, R8),
915 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
916 BPF_ALU64_REG(BPF_MOV, R0, R9),
917 BPF_EXIT_INSN(),
918 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200919 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700920 { },
921 { { 0, 2957380 } }
922 },
923 {
924 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -0700925 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700926 BPF_ALU32_IMM(BPF_MOV, R0, 20),
927 BPF_ALU32_IMM(BPF_MOV, R1, 1),
928 BPF_ALU32_IMM(BPF_MOV, R2, 2),
929 BPF_ALU32_IMM(BPF_MOV, R3, 3),
930 BPF_ALU32_IMM(BPF_MOV, R4, 4),
931 BPF_ALU32_IMM(BPF_MOV, R5, 5),
932 BPF_ALU32_IMM(BPF_MOV, R6, 6),
933 BPF_ALU32_IMM(BPF_MOV, R7, 7),
934 BPF_ALU32_IMM(BPF_MOV, R8, 8),
935 BPF_ALU32_IMM(BPF_MOV, R9, 9),
936 BPF_ALU64_IMM(BPF_ADD, R1, 10),
937 BPF_ALU64_IMM(BPF_ADD, R2, 10),
938 BPF_ALU64_IMM(BPF_ADD, R3, 10),
939 BPF_ALU64_IMM(BPF_ADD, R4, 10),
940 BPF_ALU64_IMM(BPF_ADD, R5, 10),
941 BPF_ALU64_IMM(BPF_ADD, R6, 10),
942 BPF_ALU64_IMM(BPF_ADD, R7, 10),
943 BPF_ALU64_IMM(BPF_ADD, R8, 10),
944 BPF_ALU64_IMM(BPF_ADD, R9, 10),
945 BPF_ALU32_REG(BPF_ADD, R0, R1),
946 BPF_ALU32_REG(BPF_ADD, R0, R2),
947 BPF_ALU32_REG(BPF_ADD, R0, R3),
948 BPF_ALU32_REG(BPF_ADD, R0, R4),
949 BPF_ALU32_REG(BPF_ADD, R0, R5),
950 BPF_ALU32_REG(BPF_ADD, R0, R6),
951 BPF_ALU32_REG(BPF_ADD, R0, R7),
952 BPF_ALU32_REG(BPF_ADD, R0, R8),
953 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
954 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
955 BPF_EXIT_INSN(),
956 BPF_ALU32_REG(BPF_ADD, R1, R0),
957 BPF_ALU32_REG(BPF_ADD, R1, R1),
958 BPF_ALU32_REG(BPF_ADD, R1, R2),
959 BPF_ALU32_REG(BPF_ADD, R1, R3),
960 BPF_ALU32_REG(BPF_ADD, R1, R4),
961 BPF_ALU32_REG(BPF_ADD, R1, R5),
962 BPF_ALU32_REG(BPF_ADD, R1, R6),
963 BPF_ALU32_REG(BPF_ADD, R1, R7),
964 BPF_ALU32_REG(BPF_ADD, R1, R8),
965 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
966 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
967 BPF_EXIT_INSN(),
968 BPF_ALU32_REG(BPF_ADD, R2, R0),
969 BPF_ALU32_REG(BPF_ADD, R2, R1),
970 BPF_ALU32_REG(BPF_ADD, R2, R2),
971 BPF_ALU32_REG(BPF_ADD, R2, R3),
972 BPF_ALU32_REG(BPF_ADD, R2, R4),
973 BPF_ALU32_REG(BPF_ADD, R2, R5),
974 BPF_ALU32_REG(BPF_ADD, R2, R6),
975 BPF_ALU32_REG(BPF_ADD, R2, R7),
976 BPF_ALU32_REG(BPF_ADD, R2, R8),
977 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
978 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
979 BPF_EXIT_INSN(),
980 BPF_ALU32_REG(BPF_ADD, R3, R0),
981 BPF_ALU32_REG(BPF_ADD, R3, R1),
982 BPF_ALU32_REG(BPF_ADD, R3, R2),
983 BPF_ALU32_REG(BPF_ADD, R3, R3),
984 BPF_ALU32_REG(BPF_ADD, R3, R4),
985 BPF_ALU32_REG(BPF_ADD, R3, R5),
986 BPF_ALU32_REG(BPF_ADD, R3, R6),
987 BPF_ALU32_REG(BPF_ADD, R3, R7),
988 BPF_ALU32_REG(BPF_ADD, R3, R8),
989 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
990 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
991 BPF_EXIT_INSN(),
992 BPF_ALU32_REG(BPF_ADD, R4, R0),
993 BPF_ALU32_REG(BPF_ADD, R4, R1),
994 BPF_ALU32_REG(BPF_ADD, R4, R2),
995 BPF_ALU32_REG(BPF_ADD, R4, R3),
996 BPF_ALU32_REG(BPF_ADD, R4, R4),
997 BPF_ALU32_REG(BPF_ADD, R4, R5),
998 BPF_ALU32_REG(BPF_ADD, R4, R6),
999 BPF_ALU32_REG(BPF_ADD, R4, R7),
1000 BPF_ALU32_REG(BPF_ADD, R4, R8),
1001 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1002 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1003 BPF_EXIT_INSN(),
1004 BPF_ALU32_REG(BPF_ADD, R5, R0),
1005 BPF_ALU32_REG(BPF_ADD, R5, R1),
1006 BPF_ALU32_REG(BPF_ADD, R5, R2),
1007 BPF_ALU32_REG(BPF_ADD, R5, R3),
1008 BPF_ALU32_REG(BPF_ADD, R5, R4),
1009 BPF_ALU32_REG(BPF_ADD, R5, R5),
1010 BPF_ALU32_REG(BPF_ADD, R5, R6),
1011 BPF_ALU32_REG(BPF_ADD, R5, R7),
1012 BPF_ALU32_REG(BPF_ADD, R5, R8),
1013 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1014 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1015 BPF_EXIT_INSN(),
1016 BPF_ALU32_REG(BPF_ADD, R6, R0),
1017 BPF_ALU32_REG(BPF_ADD, R6, R1),
1018 BPF_ALU32_REG(BPF_ADD, R6, R2),
1019 BPF_ALU32_REG(BPF_ADD, R6, R3),
1020 BPF_ALU32_REG(BPF_ADD, R6, R4),
1021 BPF_ALU32_REG(BPF_ADD, R6, R5),
1022 BPF_ALU32_REG(BPF_ADD, R6, R6),
1023 BPF_ALU32_REG(BPF_ADD, R6, R7),
1024 BPF_ALU32_REG(BPF_ADD, R6, R8),
1025 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1026 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1027 BPF_EXIT_INSN(),
1028 BPF_ALU32_REG(BPF_ADD, R7, R0),
1029 BPF_ALU32_REG(BPF_ADD, R7, R1),
1030 BPF_ALU32_REG(BPF_ADD, R7, R2),
1031 BPF_ALU32_REG(BPF_ADD, R7, R3),
1032 BPF_ALU32_REG(BPF_ADD, R7, R4),
1033 BPF_ALU32_REG(BPF_ADD, R7, R5),
1034 BPF_ALU32_REG(BPF_ADD, R7, R6),
1035 BPF_ALU32_REG(BPF_ADD, R7, R7),
1036 BPF_ALU32_REG(BPF_ADD, R7, R8),
1037 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1038 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1039 BPF_EXIT_INSN(),
1040 BPF_ALU32_REG(BPF_ADD, R8, R0),
1041 BPF_ALU32_REG(BPF_ADD, R8, R1),
1042 BPF_ALU32_REG(BPF_ADD, R8, R2),
1043 BPF_ALU32_REG(BPF_ADD, R8, R3),
1044 BPF_ALU32_REG(BPF_ADD, R8, R4),
1045 BPF_ALU32_REG(BPF_ADD, R8, R5),
1046 BPF_ALU32_REG(BPF_ADD, R8, R6),
1047 BPF_ALU32_REG(BPF_ADD, R8, R7),
1048 BPF_ALU32_REG(BPF_ADD, R8, R8),
1049 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1050 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1051 BPF_EXIT_INSN(),
1052 BPF_ALU32_REG(BPF_ADD, R9, R0),
1053 BPF_ALU32_REG(BPF_ADD, R9, R1),
1054 BPF_ALU32_REG(BPF_ADD, R9, R2),
1055 BPF_ALU32_REG(BPF_ADD, R9, R3),
1056 BPF_ALU32_REG(BPF_ADD, R9, R4),
1057 BPF_ALU32_REG(BPF_ADD, R9, R5),
1058 BPF_ALU32_REG(BPF_ADD, R9, R6),
1059 BPF_ALU32_REG(BPF_ADD, R9, R7),
1060 BPF_ALU32_REG(BPF_ADD, R9, R8),
1061 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1062 BPF_ALU32_REG(BPF_MOV, R0, R9),
1063 BPF_EXIT_INSN(),
1064 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001065 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001066 { },
1067 { { 0, 2957380 } }
1068 },
1069 { /* Mainly checking JIT here. */
1070 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001071 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001072 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1073 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1074 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1075 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1076 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1077 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1078 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1079 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1080 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1081 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1082 BPF_ALU64_REG(BPF_SUB, R0, R0),
1083 BPF_ALU64_REG(BPF_SUB, R0, R1),
1084 BPF_ALU64_REG(BPF_SUB, R0, R2),
1085 BPF_ALU64_REG(BPF_SUB, R0, R3),
1086 BPF_ALU64_REG(BPF_SUB, R0, R4),
1087 BPF_ALU64_REG(BPF_SUB, R0, R5),
1088 BPF_ALU64_REG(BPF_SUB, R0, R6),
1089 BPF_ALU64_REG(BPF_SUB, R0, R7),
1090 BPF_ALU64_REG(BPF_SUB, R0, R8),
1091 BPF_ALU64_REG(BPF_SUB, R0, R9),
1092 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1093 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1094 BPF_EXIT_INSN(),
1095 BPF_ALU64_REG(BPF_SUB, R1, R0),
1096 BPF_ALU64_REG(BPF_SUB, R1, R2),
1097 BPF_ALU64_REG(BPF_SUB, R1, R3),
1098 BPF_ALU64_REG(BPF_SUB, R1, R4),
1099 BPF_ALU64_REG(BPF_SUB, R1, R5),
1100 BPF_ALU64_REG(BPF_SUB, R1, R6),
1101 BPF_ALU64_REG(BPF_SUB, R1, R7),
1102 BPF_ALU64_REG(BPF_SUB, R1, R8),
1103 BPF_ALU64_REG(BPF_SUB, R1, R9),
1104 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1105 BPF_ALU64_REG(BPF_SUB, R2, R0),
1106 BPF_ALU64_REG(BPF_SUB, R2, R1),
1107 BPF_ALU64_REG(BPF_SUB, R2, R3),
1108 BPF_ALU64_REG(BPF_SUB, R2, R4),
1109 BPF_ALU64_REG(BPF_SUB, R2, R5),
1110 BPF_ALU64_REG(BPF_SUB, R2, R6),
1111 BPF_ALU64_REG(BPF_SUB, R2, R7),
1112 BPF_ALU64_REG(BPF_SUB, R2, R8),
1113 BPF_ALU64_REG(BPF_SUB, R2, R9),
1114 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1115 BPF_ALU64_REG(BPF_SUB, R3, R0),
1116 BPF_ALU64_REG(BPF_SUB, R3, R1),
1117 BPF_ALU64_REG(BPF_SUB, R3, R2),
1118 BPF_ALU64_REG(BPF_SUB, R3, R4),
1119 BPF_ALU64_REG(BPF_SUB, R3, R5),
1120 BPF_ALU64_REG(BPF_SUB, R3, R6),
1121 BPF_ALU64_REG(BPF_SUB, R3, R7),
1122 BPF_ALU64_REG(BPF_SUB, R3, R8),
1123 BPF_ALU64_REG(BPF_SUB, R3, R9),
1124 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1125 BPF_ALU64_REG(BPF_SUB, R4, R0),
1126 BPF_ALU64_REG(BPF_SUB, R4, R1),
1127 BPF_ALU64_REG(BPF_SUB, R4, R2),
1128 BPF_ALU64_REG(BPF_SUB, R4, R3),
1129 BPF_ALU64_REG(BPF_SUB, R4, R5),
1130 BPF_ALU64_REG(BPF_SUB, R4, R6),
1131 BPF_ALU64_REG(BPF_SUB, R4, R7),
1132 BPF_ALU64_REG(BPF_SUB, R4, R8),
1133 BPF_ALU64_REG(BPF_SUB, R4, R9),
1134 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1135 BPF_ALU64_REG(BPF_SUB, R5, R0),
1136 BPF_ALU64_REG(BPF_SUB, R5, R1),
1137 BPF_ALU64_REG(BPF_SUB, R5, R2),
1138 BPF_ALU64_REG(BPF_SUB, R5, R3),
1139 BPF_ALU64_REG(BPF_SUB, R5, R4),
1140 BPF_ALU64_REG(BPF_SUB, R5, R6),
1141 BPF_ALU64_REG(BPF_SUB, R5, R7),
1142 BPF_ALU64_REG(BPF_SUB, R5, R8),
1143 BPF_ALU64_REG(BPF_SUB, R5, R9),
1144 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1145 BPF_ALU64_REG(BPF_SUB, R6, R0),
1146 BPF_ALU64_REG(BPF_SUB, R6, R1),
1147 BPF_ALU64_REG(BPF_SUB, R6, R2),
1148 BPF_ALU64_REG(BPF_SUB, R6, R3),
1149 BPF_ALU64_REG(BPF_SUB, R6, R4),
1150 BPF_ALU64_REG(BPF_SUB, R6, R5),
1151 BPF_ALU64_REG(BPF_SUB, R6, R7),
1152 BPF_ALU64_REG(BPF_SUB, R6, R8),
1153 BPF_ALU64_REG(BPF_SUB, R6, R9),
1154 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1155 BPF_ALU64_REG(BPF_SUB, R7, R0),
1156 BPF_ALU64_REG(BPF_SUB, R7, R1),
1157 BPF_ALU64_REG(BPF_SUB, R7, R2),
1158 BPF_ALU64_REG(BPF_SUB, R7, R3),
1159 BPF_ALU64_REG(BPF_SUB, R7, R4),
1160 BPF_ALU64_REG(BPF_SUB, R7, R5),
1161 BPF_ALU64_REG(BPF_SUB, R7, R6),
1162 BPF_ALU64_REG(BPF_SUB, R7, R8),
1163 BPF_ALU64_REG(BPF_SUB, R7, R9),
1164 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1165 BPF_ALU64_REG(BPF_SUB, R8, R0),
1166 BPF_ALU64_REG(BPF_SUB, R8, R1),
1167 BPF_ALU64_REG(BPF_SUB, R8, R2),
1168 BPF_ALU64_REG(BPF_SUB, R8, R3),
1169 BPF_ALU64_REG(BPF_SUB, R8, R4),
1170 BPF_ALU64_REG(BPF_SUB, R8, R5),
1171 BPF_ALU64_REG(BPF_SUB, R8, R6),
1172 BPF_ALU64_REG(BPF_SUB, R8, R7),
1173 BPF_ALU64_REG(BPF_SUB, R8, R9),
1174 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1175 BPF_ALU64_REG(BPF_SUB, R9, R0),
1176 BPF_ALU64_REG(BPF_SUB, R9, R1),
1177 BPF_ALU64_REG(BPF_SUB, R9, R2),
1178 BPF_ALU64_REG(BPF_SUB, R9, R3),
1179 BPF_ALU64_REG(BPF_SUB, R9, R4),
1180 BPF_ALU64_REG(BPF_SUB, R9, R5),
1181 BPF_ALU64_REG(BPF_SUB, R9, R6),
1182 BPF_ALU64_REG(BPF_SUB, R9, R7),
1183 BPF_ALU64_REG(BPF_SUB, R9, R8),
1184 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1185 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1186 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1187 BPF_ALU64_REG(BPF_SUB, R0, R1),
1188 BPF_ALU64_REG(BPF_SUB, R0, R2),
1189 BPF_ALU64_REG(BPF_SUB, R0, R3),
1190 BPF_ALU64_REG(BPF_SUB, R0, R4),
1191 BPF_ALU64_REG(BPF_SUB, R0, R5),
1192 BPF_ALU64_REG(BPF_SUB, R0, R6),
1193 BPF_ALU64_REG(BPF_SUB, R0, R7),
1194 BPF_ALU64_REG(BPF_SUB, R0, R8),
1195 BPF_ALU64_REG(BPF_SUB, R0, R9),
1196 BPF_EXIT_INSN(),
1197 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001198 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001199 { },
1200 { { 0, 11 } }
1201 },
1202 { /* Mainly checking JIT here. */
1203 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001204 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001205 BPF_ALU64_REG(BPF_SUB, R0, R0),
1206 BPF_ALU64_REG(BPF_XOR, R1, R1),
1207 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1208 BPF_EXIT_INSN(),
1209 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1210 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1211 BPF_ALU64_REG(BPF_SUB, R1, R1),
1212 BPF_ALU64_REG(BPF_XOR, R2, R2),
1213 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1214 BPF_EXIT_INSN(),
1215 BPF_ALU64_REG(BPF_SUB, R2, R2),
1216 BPF_ALU64_REG(BPF_XOR, R3, R3),
1217 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1218 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1219 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1220 BPF_EXIT_INSN(),
1221 BPF_ALU64_REG(BPF_SUB, R3, R3),
1222 BPF_ALU64_REG(BPF_XOR, R4, R4),
1223 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1224 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1225 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1226 BPF_EXIT_INSN(),
1227 BPF_ALU64_REG(BPF_SUB, R4, R4),
1228 BPF_ALU64_REG(BPF_XOR, R5, R5),
1229 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1230 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1231 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1232 BPF_EXIT_INSN(),
1233 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1234 BPF_ALU64_REG(BPF_SUB, R5, R5),
1235 BPF_ALU64_REG(BPF_XOR, R6, R6),
1236 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1237 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1238 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1239 BPF_EXIT_INSN(),
1240 BPF_ALU64_REG(BPF_SUB, R6, R6),
1241 BPF_ALU64_REG(BPF_XOR, R7, R7),
1242 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1243 BPF_EXIT_INSN(),
1244 BPF_ALU64_REG(BPF_SUB, R7, R7),
1245 BPF_ALU64_REG(BPF_XOR, R8, R8),
1246 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1247 BPF_EXIT_INSN(),
1248 BPF_ALU64_REG(BPF_SUB, R8, R8),
1249 BPF_ALU64_REG(BPF_XOR, R9, R9),
1250 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1251 BPF_EXIT_INSN(),
1252 BPF_ALU64_REG(BPF_SUB, R9, R9),
1253 BPF_ALU64_REG(BPF_XOR, R0, R0),
1254 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1255 BPF_EXIT_INSN(),
1256 BPF_ALU64_REG(BPF_SUB, R1, R1),
1257 BPF_ALU64_REG(BPF_XOR, R0, R0),
1258 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1259 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1260 BPF_EXIT_INSN(),
1261 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1262 BPF_EXIT_INSN(),
1263 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001264 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001265 { },
1266 { { 0, 1 } }
1267 },
1268 { /* Mainly checking JIT here. */
1269 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001270 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001271 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1272 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1273 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1274 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1275 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1276 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1277 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1278 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1279 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1280 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1281 BPF_ALU64_REG(BPF_MUL, R0, R0),
1282 BPF_ALU64_REG(BPF_MUL, R0, R1),
1283 BPF_ALU64_REG(BPF_MUL, R0, R2),
1284 BPF_ALU64_REG(BPF_MUL, R0, R3),
1285 BPF_ALU64_REG(BPF_MUL, R0, R4),
1286 BPF_ALU64_REG(BPF_MUL, R0, R5),
1287 BPF_ALU64_REG(BPF_MUL, R0, R6),
1288 BPF_ALU64_REG(BPF_MUL, R0, R7),
1289 BPF_ALU64_REG(BPF_MUL, R0, R8),
1290 BPF_ALU64_REG(BPF_MUL, R0, R9),
1291 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1292 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1293 BPF_EXIT_INSN(),
1294 BPF_ALU64_REG(BPF_MUL, R1, R0),
1295 BPF_ALU64_REG(BPF_MUL, R1, R2),
1296 BPF_ALU64_REG(BPF_MUL, R1, R3),
1297 BPF_ALU64_REG(BPF_MUL, R1, R4),
1298 BPF_ALU64_REG(BPF_MUL, R1, R5),
1299 BPF_ALU64_REG(BPF_MUL, R1, R6),
1300 BPF_ALU64_REG(BPF_MUL, R1, R7),
1301 BPF_ALU64_REG(BPF_MUL, R1, R8),
1302 BPF_ALU64_REG(BPF_MUL, R1, R9),
1303 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1304 BPF_ALU64_REG(BPF_MOV, R2, R1),
1305 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1306 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1307 BPF_EXIT_INSN(),
1308 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1309 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1310 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1311 BPF_EXIT_INSN(),
1312 BPF_ALU64_REG(BPF_MUL, R2, R0),
1313 BPF_ALU64_REG(BPF_MUL, R2, R1),
1314 BPF_ALU64_REG(BPF_MUL, R2, R3),
1315 BPF_ALU64_REG(BPF_MUL, R2, R4),
1316 BPF_ALU64_REG(BPF_MUL, R2, R5),
1317 BPF_ALU64_REG(BPF_MUL, R2, R6),
1318 BPF_ALU64_REG(BPF_MUL, R2, R7),
1319 BPF_ALU64_REG(BPF_MUL, R2, R8),
1320 BPF_ALU64_REG(BPF_MUL, R2, R9),
1321 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1322 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1323 BPF_ALU64_REG(BPF_MOV, R0, R2),
1324 BPF_EXIT_INSN(),
1325 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001326 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001327 { },
1328 { { 0, 0x35d97ef2 } }
1329 },
1330 {
1331 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001332 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001333 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1334 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1335 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1336 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1337 BPF_ALU64_REG(BPF_DIV, R0, R2),
1338 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1339 BPF_EXIT_INSN(),
1340 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1341 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1342 BPF_EXIT_INSN(),
1343 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1344 BPF_EXIT_INSN(),
1345 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001346 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001347 { },
1348 { { 0, -1 } }
1349 },
1350 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001351 "INT: shifts by register",
1352 .u.insns_int = {
1353 BPF_MOV64_IMM(R0, -1234),
1354 BPF_MOV64_IMM(R1, 1),
1355 BPF_ALU32_REG(BPF_RSH, R0, R1),
1356 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1357 BPF_EXIT_INSN(),
1358 BPF_MOV64_IMM(R2, 1),
1359 BPF_ALU64_REG(BPF_LSH, R0, R2),
1360 BPF_MOV32_IMM(R4, -1234),
1361 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1362 BPF_EXIT_INSN(),
1363 BPF_ALU64_IMM(BPF_AND, R4, 63),
1364 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1365 BPF_MOV64_IMM(R3, 47),
1366 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1367 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1368 BPF_EXIT_INSN(),
1369 BPF_MOV64_IMM(R2, 1),
1370 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1371 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1372 BPF_EXIT_INSN(),
1373 BPF_MOV64_IMM(R4, 4),
1374 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1375 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1376 BPF_EXIT_INSN(),
1377 BPF_MOV64_IMM(R4, 5),
1378 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1379 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1380 BPF_EXIT_INSN(),
1381 BPF_MOV64_IMM(R0, -1),
1382 BPF_EXIT_INSN(),
1383 },
1384 INTERNAL,
1385 { },
1386 { { 0, -1 } }
1387 },
1388 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001389 "INT: DIV + ABS",
Andrew Mortonece80492014-05-22 10:16:46 -07001390 .u.insns_int = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001391 BPF_ALU64_REG(BPF_MOV, R6, R1),
1392 BPF_LD_ABS(BPF_B, 3),
1393 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1394 BPF_ALU32_REG(BPF_DIV, R0, R2),
1395 BPF_ALU64_REG(BPF_MOV, R8, R0),
1396 BPF_LD_ABS(BPF_B, 4),
1397 BPF_ALU64_REG(BPF_ADD, R8, R0),
1398 BPF_LD_IND(BPF_B, R8, -70),
1399 BPF_EXIT_INSN(),
1400 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001401 INTERNAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001402 { 10, 20, 30, 40, 50 },
1403 { { 4, 0 }, { 5, 10 } }
1404 },
1405 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001406 "INT: DIV by zero",
Andrew Mortonece80492014-05-22 10:16:46 -07001407 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001408 BPF_ALU64_REG(BPF_MOV, R6, R1),
1409 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1410 BPF_LD_ABS(BPF_B, 3),
1411 BPF_ALU32_REG(BPF_DIV, R0, R7),
1412 BPF_EXIT_INSN(),
1413 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001414 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001415 { 10, 20, 30, 40, 50 },
1416 { { 3, 0 }, { 4, 0 } }
1417 },
1418 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001419 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07001420 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001421 BPF_STMT(BPF_LD | BPF_IMM, 1),
1422 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001423 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001424 { },
1425 { }
1426 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001427 {
1428 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07001429 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001430 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1431 BPF_STMT(BPF_RET | BPF_K, 0)
1432 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001433 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001434 { },
1435 { }
1436 },
1437 {
1438 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07001439 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001440 /* seccomp insn, rejected in socket filter */
1441 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1442 BPF_STMT(BPF_RET | BPF_K, 0)
1443 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001444 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001445 { },
1446 { }
1447 },
1448 {
1449 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07001450 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001451 BPF_STMT(BPF_STX, 16),
1452 BPF_STMT(BPF_RET | BPF_K, 0)
1453 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001454 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001455 { },
1456 { }
1457 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001458 {
1459 "JUMPS + HOLES",
1460 .u.insns = {
1461 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1462 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1463 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1464 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1465 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1466 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1467 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1468 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1469 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1470 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1471 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1472 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1473 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1474 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1475 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1476 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1477 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1478 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1479 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1480 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1481 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1482 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1483 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1484 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1485 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1486 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1487 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1488 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1489 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1490 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1491 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1492 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1493 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1494 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1495 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1496 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1497 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1498 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1499 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1500 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1501 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1502 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1503 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1504 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1505 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1506 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1507 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1508 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1509 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1510 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1511 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1512 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1513 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1514 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1515 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1516 BPF_STMT(BPF_RET | BPF_A, 0),
1517 BPF_STMT(BPF_RET | BPF_A, 0),
1518 },
1519 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02001520 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1521 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1522 0x08, 0x00,
1523 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1524 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1525 0xc0, 0xa8, 0x33, 0x01,
1526 0xc0, 0xa8, 0x33, 0x02,
1527 0xbb, 0xb6,
1528 0xa9, 0xfa,
1529 0x00, 0x14, 0x00, 0x00,
1530 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1531 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1532 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1533 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1534 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1535 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1536 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1537 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001538 { { 88, 0x001b } }
1539 },
1540 {
1541 "check: RET X",
1542 .u.insns = {
1543 BPF_STMT(BPF_RET | BPF_X, 0),
1544 },
1545 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1546 { },
1547 { },
1548 },
1549 {
1550 "check: LDX + RET X",
1551 .u.insns = {
1552 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1553 BPF_STMT(BPF_RET | BPF_X, 0),
1554 },
1555 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1556 { },
1557 { },
1558 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02001559 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02001560 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02001561 .u.insns = {
1562 BPF_STMT(BPF_LDX | BPF_IMM, 100),
1563 BPF_STMT(BPF_STX, 0),
1564 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1565 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1566 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1567 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1568 BPF_STMT(BPF_STX, 1),
1569 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1570 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1571 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1572 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1573 BPF_STMT(BPF_STX, 2),
1574 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1575 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1576 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1577 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1578 BPF_STMT(BPF_STX, 3),
1579 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1580 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1581 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1582 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1583 BPF_STMT(BPF_STX, 4),
1584 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1585 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1586 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1587 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1588 BPF_STMT(BPF_STX, 5),
1589 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1590 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1591 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1592 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1593 BPF_STMT(BPF_STX, 6),
1594 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1595 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1596 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1597 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1598 BPF_STMT(BPF_STX, 7),
1599 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1600 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1601 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1602 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1603 BPF_STMT(BPF_STX, 8),
1604 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1605 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1606 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1607 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1608 BPF_STMT(BPF_STX, 9),
1609 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1610 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1611 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1612 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1613 BPF_STMT(BPF_STX, 10),
1614 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1615 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1616 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1617 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1618 BPF_STMT(BPF_STX, 11),
1619 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1620 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1621 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1622 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1623 BPF_STMT(BPF_STX, 12),
1624 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1625 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1626 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1627 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1628 BPF_STMT(BPF_STX, 13),
1629 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1630 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1631 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1632 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1633 BPF_STMT(BPF_STX, 14),
1634 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1635 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1636 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1637 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1638 BPF_STMT(BPF_STX, 15),
1639 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1640 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1641 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1642 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1643 BPF_STMT(BPF_RET | BPF_A, 0),
1644 },
1645 CLASSIC | FLAG_NO_DATA,
1646 { },
1647 { { 0, 116 } },
1648 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02001649 { /* Mainly checking JIT here. */
1650 "M[]: full STX + full LDX",
1651 .u.insns = {
1652 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
1653 BPF_STMT(BPF_STX, 0),
1654 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
1655 BPF_STMT(BPF_STX, 1),
1656 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
1657 BPF_STMT(BPF_STX, 2),
1658 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
1659 BPF_STMT(BPF_STX, 3),
1660 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
1661 BPF_STMT(BPF_STX, 4),
1662 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
1663 BPF_STMT(BPF_STX, 5),
1664 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
1665 BPF_STMT(BPF_STX, 6),
1666 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
1667 BPF_STMT(BPF_STX, 7),
1668 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
1669 BPF_STMT(BPF_STX, 8),
1670 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
1671 BPF_STMT(BPF_STX, 9),
1672 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
1673 BPF_STMT(BPF_STX, 10),
1674 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
1675 BPF_STMT(BPF_STX, 11),
1676 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
1677 BPF_STMT(BPF_STX, 12),
1678 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
1679 BPF_STMT(BPF_STX, 13),
1680 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
1681 BPF_STMT(BPF_STX, 14),
1682 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
1683 BPF_STMT(BPF_STX, 15),
1684 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1685 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1686 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1687 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1688 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1689 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1690 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1691 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1692 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1693 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1694 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1695 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1696 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1697 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1698 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1699 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1700 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1701 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1702 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1703 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1704 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1705 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1706 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1707 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1708 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1709 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1710 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1711 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1712 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1713 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1714 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1715 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1716 BPF_STMT(BPF_RET | BPF_A, 0),
1717 },
1718 CLASSIC | FLAG_NO_DATA,
1719 { },
1720 { { 0, 0x2a5a5e5 } },
1721 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02001722 {
1723 "check: SKF_AD_MAX",
1724 .u.insns = {
1725 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
1726 SKF_AD_OFF + SKF_AD_MAX),
1727 BPF_STMT(BPF_RET | BPF_A, 0),
1728 },
1729 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1730 { },
1731 { },
1732 },
1733 { /* Passes checker but fails during runtime. */
1734 "LD [SKF_AD_OFF-1]",
1735 .u.insns = {
1736 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
1737 SKF_AD_OFF - 1),
1738 BPF_STMT(BPF_RET | BPF_K, 1),
1739 },
1740 CLASSIC,
1741 { },
1742 { { 1, 0 } },
1743 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07001744 {
1745 "load 64-bit immediate",
1746 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07001747 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07001748 BPF_MOV64_REG(R2, R1),
1749 BPF_MOV64_REG(R3, R2),
1750 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1751 BPF_ALU64_IMM(BPF_LSH, R3, 32),
1752 BPF_ALU64_IMM(BPF_RSH, R3, 32),
1753 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1754 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
1755 BPF_EXIT_INSN(),
1756 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
1757 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04001758 BPF_LD_IMM64(R0, 0x1ffffffffLL),
1759 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07001760 BPF_EXIT_INSN(),
1761 },
1762 INTERNAL,
1763 { },
1764 { { 0, 1 } }
1765 },
Alexei Starovoitove21ab362014-10-28 15:11:43 -07001766 {
1767 "nmap reduced",
1768 .u.insns_int = {
1769 BPF_MOV64_REG(R6, R1),
1770 BPF_LD_ABS(BPF_H, 12),
1771 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
1772 BPF_LD_ABS(BPF_H, 12),
1773 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
1774 BPF_MOV32_IMM(R0, 18),
1775 BPF_STX_MEM(BPF_W, R10, R0, -64),
1776 BPF_LDX_MEM(BPF_W, R7, R10, -64),
1777 BPF_LD_IND(BPF_W, R7, 14),
1778 BPF_STX_MEM(BPF_W, R10, R0, -60),
1779 BPF_MOV32_IMM(R0, 280971478),
1780 BPF_STX_MEM(BPF_W, R10, R0, -56),
1781 BPF_LDX_MEM(BPF_W, R7, R10, -56),
1782 BPF_LDX_MEM(BPF_W, R0, R10, -60),
1783 BPF_ALU32_REG(BPF_SUB, R0, R7),
1784 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
1785 BPF_LD_ABS(BPF_H, 12),
1786 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
1787 BPF_MOV32_IMM(R0, 22),
1788 BPF_STX_MEM(BPF_W, R10, R0, -56),
1789 BPF_LDX_MEM(BPF_W, R7, R10, -56),
1790 BPF_LD_IND(BPF_H, R7, 14),
1791 BPF_STX_MEM(BPF_W, R10, R0, -52),
1792 BPF_MOV32_IMM(R0, 17366),
1793 BPF_STX_MEM(BPF_W, R10, R0, -48),
1794 BPF_LDX_MEM(BPF_W, R7, R10, -48),
1795 BPF_LDX_MEM(BPF_W, R0, R10, -52),
1796 BPF_ALU32_REG(BPF_SUB, R0, R7),
1797 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
1798 BPF_MOV32_IMM(R0, 256),
1799 BPF_EXIT_INSN(),
1800 BPF_MOV32_IMM(R0, 0),
1801 BPF_EXIT_INSN(),
1802 },
1803 INTERNAL,
1804 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
1805 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1806 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
1807 { { 38, 256 } }
1808 },
Michael Holzheucffc6422015-05-11 22:22:44 -07001809 /* BPF_ALU | BPF_MOV | BPF_X */
1810 {
1811 "ALU_MOV_X: dst = 2",
1812 .u.insns_int = {
1813 BPF_ALU32_IMM(BPF_MOV, R1, 2),
1814 BPF_ALU32_REG(BPF_MOV, R0, R1),
1815 BPF_EXIT_INSN(),
1816 },
1817 INTERNAL,
1818 { },
1819 { { 0, 2 } },
1820 },
1821 {
1822 "ALU_MOV_X: dst = 4294967295",
1823 .u.insns_int = {
1824 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295),
1825 BPF_ALU32_REG(BPF_MOV, R0, R1),
1826 BPF_EXIT_INSN(),
1827 },
1828 INTERNAL,
1829 { },
1830 { { 0, 4294967295 } },
1831 },
1832 {
1833 "ALU64_MOV_X: dst = 2",
1834 .u.insns_int = {
1835 BPF_ALU32_IMM(BPF_MOV, R1, 2),
1836 BPF_ALU64_REG(BPF_MOV, R0, R1),
1837 BPF_EXIT_INSN(),
1838 },
1839 INTERNAL,
1840 { },
1841 { { 0, 2 } },
1842 },
1843 {
1844 "ALU64_MOV_X: dst = 4294967295",
1845 .u.insns_int = {
1846 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295),
1847 BPF_ALU64_REG(BPF_MOV, R0, R1),
1848 BPF_EXIT_INSN(),
1849 },
1850 INTERNAL,
1851 { },
1852 { { 0, 4294967295 } },
1853 },
1854 /* BPF_ALU | BPF_MOV | BPF_K */
1855 {
1856 "ALU_MOV_K: dst = 2",
1857 .u.insns_int = {
1858 BPF_ALU32_IMM(BPF_MOV, R0, 2),
1859 BPF_EXIT_INSN(),
1860 },
1861 INTERNAL,
1862 { },
1863 { { 0, 2 } },
1864 },
1865 {
1866 "ALU_MOV_K: dst = 4294967295",
1867 .u.insns_int = {
1868 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295),
1869 BPF_EXIT_INSN(),
1870 },
1871 INTERNAL,
1872 { },
1873 { { 0, 4294967295 } },
1874 },
1875 {
1876 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
1877 .u.insns_int = {
1878 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
1879 BPF_LD_IMM64(R3, 0x00000000ffffffff),
1880 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
1881 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
1882 BPF_MOV32_IMM(R0, 2),
1883 BPF_EXIT_INSN(),
1884 BPF_MOV32_IMM(R0, 1),
1885 BPF_EXIT_INSN(),
1886 },
1887 INTERNAL,
1888 { },
1889 { { 0, 0x1 } },
1890 },
1891 {
1892 "ALU64_MOV_K: dst = 2",
1893 .u.insns_int = {
1894 BPF_ALU64_IMM(BPF_MOV, R0, 2),
1895 BPF_EXIT_INSN(),
1896 },
1897 INTERNAL,
1898 { },
1899 { { 0, 2 } },
1900 },
1901 {
1902 "ALU64_MOV_K: dst = 2147483647",
1903 .u.insns_int = {
1904 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
1905 BPF_EXIT_INSN(),
1906 },
1907 INTERNAL,
1908 { },
1909 { { 0, 2147483647 } },
1910 },
1911 {
1912 "ALU64_OR_K: dst = 0x0",
1913 .u.insns_int = {
1914 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
1915 BPF_LD_IMM64(R3, 0x0),
1916 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
1917 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
1918 BPF_MOV32_IMM(R0, 2),
1919 BPF_EXIT_INSN(),
1920 BPF_MOV32_IMM(R0, 1),
1921 BPF_EXIT_INSN(),
1922 },
1923 INTERNAL,
1924 { },
1925 { { 0, 0x1 } },
1926 },
1927 {
1928 "ALU64_MOV_K: dst = -1",
1929 .u.insns_int = {
1930 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
1931 BPF_LD_IMM64(R3, 0xffffffffffffffff),
1932 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
1933 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
1934 BPF_MOV32_IMM(R0, 2),
1935 BPF_EXIT_INSN(),
1936 BPF_MOV32_IMM(R0, 1),
1937 BPF_EXIT_INSN(),
1938 },
1939 INTERNAL,
1940 { },
1941 { { 0, 0x1 } },
1942 },
1943 /* BPF_ALU | BPF_ADD | BPF_X */
1944 {
1945 "ALU_ADD_X: 1 + 2 = 3",
1946 .u.insns_int = {
1947 BPF_LD_IMM64(R0, 1),
1948 BPF_ALU32_IMM(BPF_MOV, R1, 2),
1949 BPF_ALU32_REG(BPF_ADD, R0, R1),
1950 BPF_EXIT_INSN(),
1951 },
1952 INTERNAL,
1953 { },
1954 { { 0, 3 } },
1955 },
1956 {
1957 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
1958 .u.insns_int = {
1959 BPF_LD_IMM64(R0, 1),
1960 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294),
1961 BPF_ALU32_REG(BPF_ADD, R0, R1),
1962 BPF_EXIT_INSN(),
1963 },
1964 INTERNAL,
1965 { },
1966 { { 0, 4294967295 } },
1967 },
1968 {
1969 "ALU64_ADD_X: 1 + 2 = 3",
1970 .u.insns_int = {
1971 BPF_LD_IMM64(R0, 1),
1972 BPF_ALU32_IMM(BPF_MOV, R1, 2),
1973 BPF_ALU64_REG(BPF_ADD, R0, R1),
1974 BPF_EXIT_INSN(),
1975 },
1976 INTERNAL,
1977 { },
1978 { { 0, 3 } },
1979 },
1980 {
1981 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
1982 .u.insns_int = {
1983 BPF_LD_IMM64(R0, 1),
1984 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294),
1985 BPF_ALU64_REG(BPF_ADD, R0, R1),
1986 BPF_EXIT_INSN(),
1987 },
1988 INTERNAL,
1989 { },
1990 { { 0, 4294967295 } },
1991 },
1992 /* BPF_ALU | BPF_ADD | BPF_K */
1993 {
1994 "ALU_ADD_K: 1 + 2 = 3",
1995 .u.insns_int = {
1996 BPF_LD_IMM64(R0, 1),
1997 BPF_ALU32_IMM(BPF_ADD, R0, 2),
1998 BPF_EXIT_INSN(),
1999 },
2000 INTERNAL,
2001 { },
2002 { { 0, 3 } },
2003 },
2004 {
2005 "ALU_ADD_K: 3 + 0 = 3",
2006 .u.insns_int = {
2007 BPF_LD_IMM64(R0, 3),
2008 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2009 BPF_EXIT_INSN(),
2010 },
2011 INTERNAL,
2012 { },
2013 { { 0, 3 } },
2014 },
2015 {
2016 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2017 .u.insns_int = {
2018 BPF_LD_IMM64(R0, 1),
2019 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294),
2020 BPF_EXIT_INSN(),
2021 },
2022 INTERNAL,
2023 { },
2024 { { 0, 4294967295 } },
2025 },
2026 {
2027 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2028 .u.insns_int = {
2029 BPF_LD_IMM64(R2, 0x0),
2030 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2031 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2032 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2033 BPF_MOV32_IMM(R0, 2),
2034 BPF_EXIT_INSN(),
2035 BPF_MOV32_IMM(R0, 1),
2036 BPF_EXIT_INSN(),
2037 },
2038 INTERNAL,
2039 { },
2040 { { 0, 0x1 } },
2041 },
2042 {
2043 "ALU64_ADD_K: 1 + 2 = 3",
2044 .u.insns_int = {
2045 BPF_LD_IMM64(R0, 1),
2046 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2047 BPF_EXIT_INSN(),
2048 },
2049 INTERNAL,
2050 { },
2051 { { 0, 3 } },
2052 },
2053 {
2054 "ALU64_ADD_K: 3 + 0 = 3",
2055 .u.insns_int = {
2056 BPF_LD_IMM64(R0, 3),
2057 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2058 BPF_EXIT_INSN(),
2059 },
2060 INTERNAL,
2061 { },
2062 { { 0, 3 } },
2063 },
2064 {
2065 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2066 .u.insns_int = {
2067 BPF_LD_IMM64(R0, 1),
2068 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2069 BPF_EXIT_INSN(),
2070 },
2071 INTERNAL,
2072 { },
2073 { { 0, 2147483647 } },
2074 },
2075 {
2076 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2077 .u.insns_int = {
2078 BPF_LD_IMM64(R0, 2147483646),
2079 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2080 BPF_EXIT_INSN(),
2081 },
2082 INTERNAL,
2083 { },
2084 { { 0, -1 } },
2085 },
2086 {
2087 "ALU64_ADD_K: 1 + 0 = 1",
2088 .u.insns_int = {
2089 BPF_LD_IMM64(R2, 0x1),
2090 BPF_LD_IMM64(R3, 0x1),
2091 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2092 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2093 BPF_MOV32_IMM(R0, 2),
2094 BPF_EXIT_INSN(),
2095 BPF_MOV32_IMM(R0, 1),
2096 BPF_EXIT_INSN(),
2097 },
2098 INTERNAL,
2099 { },
2100 { { 0, 0x1 } },
2101 },
2102 {
2103 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2104 .u.insns_int = {
2105 BPF_LD_IMM64(R2, 0x0),
2106 BPF_LD_IMM64(R3, 0xffffffffffffffff),
2107 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2108 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2109 BPF_MOV32_IMM(R0, 2),
2110 BPF_EXIT_INSN(),
2111 BPF_MOV32_IMM(R0, 1),
2112 BPF_EXIT_INSN(),
2113 },
2114 INTERNAL,
2115 { },
2116 { { 0, 0x1 } },
2117 },
2118 /* BPF_ALU | BPF_SUB | BPF_X */
2119 {
2120 "ALU_SUB_X: 3 - 1 = 2",
2121 .u.insns_int = {
2122 BPF_LD_IMM64(R0, 3),
2123 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2124 BPF_ALU32_REG(BPF_SUB, R0, R1),
2125 BPF_EXIT_INSN(),
2126 },
2127 INTERNAL,
2128 { },
2129 { { 0, 2 } },
2130 },
2131 {
2132 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2133 .u.insns_int = {
2134 BPF_LD_IMM64(R0, 4294967295),
2135 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294),
2136 BPF_ALU32_REG(BPF_SUB, R0, R1),
2137 BPF_EXIT_INSN(),
2138 },
2139 INTERNAL,
2140 { },
2141 { { 0, 1 } },
2142 },
2143 {
2144 "ALU64_SUB_X: 3 - 1 = 2",
2145 .u.insns_int = {
2146 BPF_LD_IMM64(R0, 3),
2147 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2148 BPF_ALU64_REG(BPF_SUB, R0, R1),
2149 BPF_EXIT_INSN(),
2150 },
2151 INTERNAL,
2152 { },
2153 { { 0, 2 } },
2154 },
2155 {
2156 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2157 .u.insns_int = {
2158 BPF_LD_IMM64(R0, 4294967295),
2159 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294),
2160 BPF_ALU64_REG(BPF_SUB, R0, R1),
2161 BPF_EXIT_INSN(),
2162 },
2163 INTERNAL,
2164 { },
2165 { { 0, 1 } },
2166 },
2167 /* BPF_ALU | BPF_SUB | BPF_K */
2168 {
2169 "ALU_SUB_K: 3 - 1 = 2",
2170 .u.insns_int = {
2171 BPF_LD_IMM64(R0, 3),
2172 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2173 BPF_EXIT_INSN(),
2174 },
2175 INTERNAL,
2176 { },
2177 { { 0, 2 } },
2178 },
2179 {
2180 "ALU_SUB_K: 3 - 0 = 3",
2181 .u.insns_int = {
2182 BPF_LD_IMM64(R0, 3),
2183 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2184 BPF_EXIT_INSN(),
2185 },
2186 INTERNAL,
2187 { },
2188 { { 0, 3 } },
2189 },
2190 {
2191 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2192 .u.insns_int = {
2193 BPF_LD_IMM64(R0, 4294967295),
2194 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294),
2195 BPF_EXIT_INSN(),
2196 },
2197 INTERNAL,
2198 { },
2199 { { 0, 1 } },
2200 },
2201 {
2202 "ALU64_SUB_K: 3 - 1 = 2",
2203 .u.insns_int = {
2204 BPF_LD_IMM64(R0, 3),
2205 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2206 BPF_EXIT_INSN(),
2207 },
2208 INTERNAL,
2209 { },
2210 { { 0, 2 } },
2211 },
2212 {
2213 "ALU64_SUB_K: 3 - 0 = 3",
2214 .u.insns_int = {
2215 BPF_LD_IMM64(R0, 3),
2216 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2217 BPF_EXIT_INSN(),
2218 },
2219 INTERNAL,
2220 { },
2221 { { 0, 3 } },
2222 },
2223 {
2224 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2225 .u.insns_int = {
2226 BPF_LD_IMM64(R0, 4294967294),
2227 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295),
2228 BPF_EXIT_INSN(),
2229 },
2230 INTERNAL,
2231 { },
2232 { { 0, -1 } },
2233 },
2234 {
2235 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2236 .u.insns_int = {
2237 BPF_LD_IMM64(R0, 2147483646),
2238 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2239 BPF_EXIT_INSN(),
2240 },
2241 INTERNAL,
2242 { },
2243 { { 0, -1 } },
2244 },
2245 /* BPF_ALU | BPF_MUL | BPF_X */
2246 {
2247 "ALU_MUL_X: 2 * 3 = 6",
2248 .u.insns_int = {
2249 BPF_LD_IMM64(R0, 2),
2250 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2251 BPF_ALU32_REG(BPF_MUL, R0, R1),
2252 BPF_EXIT_INSN(),
2253 },
2254 INTERNAL,
2255 { },
2256 { { 0, 6 } },
2257 },
2258 {
2259 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2260 .u.insns_int = {
2261 BPF_LD_IMM64(R0, 2),
2262 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2263 BPF_ALU32_REG(BPF_MUL, R0, R1),
2264 BPF_EXIT_INSN(),
2265 },
2266 INTERNAL,
2267 { },
2268 { { 0, 0xFFFFFFF0 } },
2269 },
2270 {
2271 "ALU_MUL_X: -1 * -1 = 1",
2272 .u.insns_int = {
2273 BPF_LD_IMM64(R0, -1),
2274 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2275 BPF_ALU32_REG(BPF_MUL, R0, R1),
2276 BPF_EXIT_INSN(),
2277 },
2278 INTERNAL,
2279 { },
2280 { { 0, 1 } },
2281 },
2282 {
2283 "ALU64_MUL_X: 2 * 3 = 6",
2284 .u.insns_int = {
2285 BPF_LD_IMM64(R0, 2),
2286 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2287 BPF_ALU64_REG(BPF_MUL, R0, R1),
2288 BPF_EXIT_INSN(),
2289 },
2290 INTERNAL,
2291 { },
2292 { { 0, 6 } },
2293 },
2294 {
2295 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2296 .u.insns_int = {
2297 BPF_LD_IMM64(R0, 1),
2298 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2299 BPF_ALU64_REG(BPF_MUL, R0, R1),
2300 BPF_EXIT_INSN(),
2301 },
2302 INTERNAL,
2303 { },
2304 { { 0, 2147483647 } },
2305 },
2306 /* BPF_ALU | BPF_MUL | BPF_K */
2307 {
2308 "ALU_MUL_K: 2 * 3 = 6",
2309 .u.insns_int = {
2310 BPF_LD_IMM64(R0, 2),
2311 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2312 BPF_EXIT_INSN(),
2313 },
2314 INTERNAL,
2315 { },
2316 { { 0, 6 } },
2317 },
2318 {
2319 "ALU_MUL_K: 3 * 1 = 3",
2320 .u.insns_int = {
2321 BPF_LD_IMM64(R0, 3),
2322 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2323 BPF_EXIT_INSN(),
2324 },
2325 INTERNAL,
2326 { },
2327 { { 0, 3 } },
2328 },
2329 {
2330 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2331 .u.insns_int = {
2332 BPF_LD_IMM64(R0, 2),
2333 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2334 BPF_EXIT_INSN(),
2335 },
2336 INTERNAL,
2337 { },
2338 { { 0, 0xFFFFFFF0 } },
2339 },
2340 {
2341 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
2342 .u.insns_int = {
2343 BPF_LD_IMM64(R2, 0x1),
2344 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2345 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
2346 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2347 BPF_MOV32_IMM(R0, 2),
2348 BPF_EXIT_INSN(),
2349 BPF_MOV32_IMM(R0, 1),
2350 BPF_EXIT_INSN(),
2351 },
2352 INTERNAL,
2353 { },
2354 { { 0, 0x1 } },
2355 },
2356 {
2357 "ALU64_MUL_K: 2 * 3 = 6",
2358 .u.insns_int = {
2359 BPF_LD_IMM64(R0, 2),
2360 BPF_ALU64_IMM(BPF_MUL, R0, 3),
2361 BPF_EXIT_INSN(),
2362 },
2363 INTERNAL,
2364 { },
2365 { { 0, 6 } },
2366 },
2367 {
2368 "ALU64_MUL_K: 3 * 1 = 3",
2369 .u.insns_int = {
2370 BPF_LD_IMM64(R0, 3),
2371 BPF_ALU64_IMM(BPF_MUL, R0, 1),
2372 BPF_EXIT_INSN(),
2373 },
2374 INTERNAL,
2375 { },
2376 { { 0, 3 } },
2377 },
2378 {
2379 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
2380 .u.insns_int = {
2381 BPF_LD_IMM64(R0, 1),
2382 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
2383 BPF_EXIT_INSN(),
2384 },
2385 INTERNAL,
2386 { },
2387 { { 0, 2147483647 } },
2388 },
2389 {
2390 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
2391 .u.insns_int = {
2392 BPF_LD_IMM64(R0, 1),
2393 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
2394 BPF_EXIT_INSN(),
2395 },
2396 INTERNAL,
2397 { },
2398 { { 0, -2147483647 } },
2399 },
2400 {
2401 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
2402 .u.insns_int = {
2403 BPF_LD_IMM64(R2, 0x1),
2404 BPF_LD_IMM64(R3, 0xffffffffffffffff),
2405 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
2406 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2407 BPF_MOV32_IMM(R0, 2),
2408 BPF_EXIT_INSN(),
2409 BPF_MOV32_IMM(R0, 1),
2410 BPF_EXIT_INSN(),
2411 },
2412 INTERNAL,
2413 { },
2414 { { 0, 0x1 } },
2415 },
2416 /* BPF_ALU | BPF_DIV | BPF_X */
2417 {
2418 "ALU_DIV_X: 6 / 2 = 3",
2419 .u.insns_int = {
2420 BPF_LD_IMM64(R0, 6),
2421 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2422 BPF_ALU32_REG(BPF_DIV, R0, R1),
2423 BPF_EXIT_INSN(),
2424 },
2425 INTERNAL,
2426 { },
2427 { { 0, 3 } },
2428 },
2429 {
2430 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
2431 .u.insns_int = {
2432 BPF_LD_IMM64(R0, 4294967295),
2433 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295),
2434 BPF_ALU32_REG(BPF_DIV, R0, R1),
2435 BPF_EXIT_INSN(),
2436 },
2437 INTERNAL,
2438 { },
2439 { { 0, 1 } },
2440 },
2441 {
2442 "ALU64_DIV_X: 6 / 2 = 3",
2443 .u.insns_int = {
2444 BPF_LD_IMM64(R0, 6),
2445 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2446 BPF_ALU64_REG(BPF_DIV, R0, R1),
2447 BPF_EXIT_INSN(),
2448 },
2449 INTERNAL,
2450 { },
2451 { { 0, 3 } },
2452 },
2453 {
2454 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
2455 .u.insns_int = {
2456 BPF_LD_IMM64(R0, 2147483647),
2457 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2458 BPF_ALU64_REG(BPF_DIV, R0, R1),
2459 BPF_EXIT_INSN(),
2460 },
2461 INTERNAL,
2462 { },
2463 { { 0, 1 } },
2464 },
2465 {
2466 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2467 .u.insns_int = {
2468 BPF_LD_IMM64(R2, 0xffffffffffffffffUL),
2469 BPF_LD_IMM64(R4, 0xffffffffffffffffUL),
2470 BPF_LD_IMM64(R3, 0x0000000000000001UL),
2471 BPF_ALU64_REG(BPF_DIV, R2, R4),
2472 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2473 BPF_MOV32_IMM(R0, 2),
2474 BPF_EXIT_INSN(),
2475 BPF_MOV32_IMM(R0, 1),
2476 BPF_EXIT_INSN(),
2477 },
2478 INTERNAL,
2479 { },
2480 { { 0, 0x1 } },
2481 },
2482 /* BPF_ALU | BPF_DIV | BPF_K */
2483 {
2484 "ALU_DIV_K: 6 / 2 = 3",
2485 .u.insns_int = {
2486 BPF_LD_IMM64(R0, 6),
2487 BPF_ALU32_IMM(BPF_DIV, R0, 2),
2488 BPF_EXIT_INSN(),
2489 },
2490 INTERNAL,
2491 { },
2492 { { 0, 3 } },
2493 },
2494 {
2495 "ALU_DIV_K: 3 / 1 = 3",
2496 .u.insns_int = {
2497 BPF_LD_IMM64(R0, 3),
2498 BPF_ALU32_IMM(BPF_DIV, R0, 1),
2499 BPF_EXIT_INSN(),
2500 },
2501 INTERNAL,
2502 { },
2503 { { 0, 3 } },
2504 },
2505 {
2506 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
2507 .u.insns_int = {
2508 BPF_LD_IMM64(R0, 4294967295),
2509 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295),
2510 BPF_EXIT_INSN(),
2511 },
2512 INTERNAL,
2513 { },
2514 { { 0, 1 } },
2515 },
2516 {
2517 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
2518 .u.insns_int = {
2519 BPF_LD_IMM64(R2, 0xffffffffffffffffUL),
2520 BPF_LD_IMM64(R3, 0x1UL),
2521 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
2522 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2523 BPF_MOV32_IMM(R0, 2),
2524 BPF_EXIT_INSN(),
2525 BPF_MOV32_IMM(R0, 1),
2526 BPF_EXIT_INSN(),
2527 },
2528 INTERNAL,
2529 { },
2530 { { 0, 0x1 } },
2531 },
2532 {
2533 "ALU64_DIV_K: 6 / 2 = 3",
2534 .u.insns_int = {
2535 BPF_LD_IMM64(R0, 6),
2536 BPF_ALU64_IMM(BPF_DIV, R0, 2),
2537 BPF_EXIT_INSN(),
2538 },
2539 INTERNAL,
2540 { },
2541 { { 0, 3 } },
2542 },
2543 {
2544 "ALU64_DIV_K: 3 / 1 = 3",
2545 .u.insns_int = {
2546 BPF_LD_IMM64(R0, 3),
2547 BPF_ALU64_IMM(BPF_DIV, R0, 1),
2548 BPF_EXIT_INSN(),
2549 },
2550 INTERNAL,
2551 { },
2552 { { 0, 3 } },
2553 },
2554 {
2555 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
2556 .u.insns_int = {
2557 BPF_LD_IMM64(R0, 2147483647),
2558 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
2559 BPF_EXIT_INSN(),
2560 },
2561 INTERNAL,
2562 { },
2563 { { 0, 1 } },
2564 },
2565 {
2566 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2567 .u.insns_int = {
2568 BPF_LD_IMM64(R2, 0xffffffffffffffffUL),
2569 BPF_LD_IMM64(R3, 0x0000000000000001UL),
2570 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
2571 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2572 BPF_MOV32_IMM(R0, 2),
2573 BPF_EXIT_INSN(),
2574 BPF_MOV32_IMM(R0, 1),
2575 BPF_EXIT_INSN(),
2576 },
2577 INTERNAL,
2578 { },
2579 { { 0, 0x1 } },
2580 },
2581 /* BPF_ALU | BPF_MOD | BPF_X */
2582 {
2583 "ALU_MOD_X: 3 % 2 = 1",
2584 .u.insns_int = {
2585 BPF_LD_IMM64(R0, 3),
2586 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2587 BPF_ALU32_REG(BPF_MOD, R0, R1),
2588 BPF_EXIT_INSN(),
2589 },
2590 INTERNAL,
2591 { },
2592 { { 0, 1 } },
2593 },
2594 {
2595 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
2596 .u.insns_int = {
2597 BPF_LD_IMM64(R0, 4294967295),
2598 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293),
2599 BPF_ALU32_REG(BPF_MOD, R0, R1),
2600 BPF_EXIT_INSN(),
2601 },
2602 INTERNAL,
2603 { },
2604 { { 0, 2 } },
2605 },
2606 {
2607 "ALU64_MOD_X: 3 % 2 = 1",
2608 .u.insns_int = {
2609 BPF_LD_IMM64(R0, 3),
2610 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2611 BPF_ALU64_REG(BPF_MOD, R0, R1),
2612 BPF_EXIT_INSN(),
2613 },
2614 INTERNAL,
2615 { },
2616 { { 0, 1 } },
2617 },
2618 {
2619 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
2620 .u.insns_int = {
2621 BPF_LD_IMM64(R0, 2147483647),
2622 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
2623 BPF_ALU64_REG(BPF_MOD, R0, R1),
2624 BPF_EXIT_INSN(),
2625 },
2626 INTERNAL,
2627 { },
2628 { { 0, 2 } },
2629 },
2630 /* BPF_ALU | BPF_MOD | BPF_K */
2631 {
2632 "ALU_MOD_K: 3 % 2 = 1",
2633 .u.insns_int = {
2634 BPF_LD_IMM64(R0, 3),
2635 BPF_ALU32_IMM(BPF_MOD, R0, 2),
2636 BPF_EXIT_INSN(),
2637 },
2638 INTERNAL,
2639 { },
2640 { { 0, 1 } },
2641 },
2642 {
2643 "ALU_MOD_K: 3 % 1 = 0",
2644 .u.insns_int = {
2645 BPF_LD_IMM64(R0, 3),
2646 BPF_ALU32_IMM(BPF_MOD, R0, 1),
2647 BPF_EXIT_INSN(),
2648 },
2649 INTERNAL,
2650 { },
2651 { { 0, 0 } },
2652 },
2653 {
2654 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
2655 .u.insns_int = {
2656 BPF_LD_IMM64(R0, 4294967295),
2657 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293),
2658 BPF_EXIT_INSN(),
2659 },
2660 INTERNAL,
2661 { },
2662 { { 0, 2 } },
2663 },
2664 {
2665 "ALU64_MOD_K: 3 % 2 = 1",
2666 .u.insns_int = {
2667 BPF_LD_IMM64(R0, 3),
2668 BPF_ALU64_IMM(BPF_MOD, R0, 2),
2669 BPF_EXIT_INSN(),
2670 },
2671 INTERNAL,
2672 { },
2673 { { 0, 1 } },
2674 },
2675 {
2676 "ALU64_MOD_K: 3 % 1 = 0",
2677 .u.insns_int = {
2678 BPF_LD_IMM64(R0, 3),
2679 BPF_ALU64_IMM(BPF_MOD, R0, 1),
2680 BPF_EXIT_INSN(),
2681 },
2682 INTERNAL,
2683 { },
2684 { { 0, 0 } },
2685 },
2686 {
2687 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
2688 .u.insns_int = {
2689 BPF_LD_IMM64(R0, 2147483647),
2690 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
2691 BPF_EXIT_INSN(),
2692 },
2693 INTERNAL,
2694 { },
2695 { { 0, 2 } },
2696 },
2697 /* BPF_ALU | BPF_AND | BPF_X */
2698 {
2699 "ALU_AND_X: 3 & 2 = 2",
2700 .u.insns_int = {
2701 BPF_LD_IMM64(R0, 3),
2702 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2703 BPF_ALU32_REG(BPF_AND, R0, R1),
2704 BPF_EXIT_INSN(),
2705 },
2706 INTERNAL,
2707 { },
2708 { { 0, 2 } },
2709 },
2710 {
2711 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
2712 .u.insns_int = {
2713 BPF_LD_IMM64(R0, 0xffffffff),
2714 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
2715 BPF_ALU32_REG(BPF_AND, R0, R1),
2716 BPF_EXIT_INSN(),
2717 },
2718 INTERNAL,
2719 { },
2720 { { 0, 0xffffffff } },
2721 },
2722 {
2723 "ALU64_AND_X: 3 & 2 = 2",
2724 .u.insns_int = {
2725 BPF_LD_IMM64(R0, 3),
2726 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2727 BPF_ALU64_REG(BPF_AND, R0, R1),
2728 BPF_EXIT_INSN(),
2729 },
2730 INTERNAL,
2731 { },
2732 { { 0, 2 } },
2733 },
2734 {
2735 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
2736 .u.insns_int = {
2737 BPF_LD_IMM64(R0, 0xffffffff),
2738 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
2739 BPF_ALU64_REG(BPF_AND, R0, R1),
2740 BPF_EXIT_INSN(),
2741 },
2742 INTERNAL,
2743 { },
2744 { { 0, 0xffffffff } },
2745 },
2746 /* BPF_ALU | BPF_AND | BPF_K */
2747 {
2748 "ALU_AND_K: 3 & 2 = 2",
2749 .u.insns_int = {
2750 BPF_LD_IMM64(R0, 3),
2751 BPF_ALU32_IMM(BPF_AND, R0, 2),
2752 BPF_EXIT_INSN(),
2753 },
2754 INTERNAL,
2755 { },
2756 { { 0, 2 } },
2757 },
2758 {
2759 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
2760 .u.insns_int = {
2761 BPF_LD_IMM64(R0, 0xffffffff),
2762 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
2763 BPF_EXIT_INSN(),
2764 },
2765 INTERNAL,
2766 { },
2767 { { 0, 0xffffffff } },
2768 },
2769 {
2770 "ALU64_AND_K: 3 & 2 = 2",
2771 .u.insns_int = {
2772 BPF_LD_IMM64(R0, 3),
2773 BPF_ALU64_IMM(BPF_AND, R0, 2),
2774 BPF_EXIT_INSN(),
2775 },
2776 INTERNAL,
2777 { },
2778 { { 0, 2 } },
2779 },
2780 {
2781 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
2782 .u.insns_int = {
2783 BPF_LD_IMM64(R0, 0xffffffff),
2784 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
2785 BPF_EXIT_INSN(),
2786 },
2787 INTERNAL,
2788 { },
2789 { { 0, 0xffffffff } },
2790 },
2791 {
2792 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
2793 .u.insns_int = {
2794 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
2795 BPF_LD_IMM64(R3, 0x0000000000000000),
2796 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
2797 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2798 BPF_MOV32_IMM(R0, 2),
2799 BPF_EXIT_INSN(),
2800 BPF_MOV32_IMM(R0, 1),
2801 BPF_EXIT_INSN(),
2802 },
2803 INTERNAL,
2804 { },
2805 { { 0, 0x1 } },
2806 },
2807 {
2808 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
2809 .u.insns_int = {
2810 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
2811 BPF_LD_IMM64(R3, 0x0000ffffffff0000),
2812 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
2813 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2814 BPF_MOV32_IMM(R0, 2),
2815 BPF_EXIT_INSN(),
2816 BPF_MOV32_IMM(R0, 1),
2817 BPF_EXIT_INSN(),
2818 },
2819 INTERNAL,
2820 { },
2821 { { 0, 0x1 } },
2822 },
2823 {
2824 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
2825 .u.insns_int = {
2826 BPF_LD_IMM64(R2, 0xffffffffffffffff),
2827 BPF_LD_IMM64(R3, 0xffffffffffffffff),
2828 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
2829 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2830 BPF_MOV32_IMM(R0, 2),
2831 BPF_EXIT_INSN(),
2832 BPF_MOV32_IMM(R0, 1),
2833 BPF_EXIT_INSN(),
2834 },
2835 INTERNAL,
2836 { },
2837 { { 0, 0x1 } },
2838 },
2839 /* BPF_ALU | BPF_OR | BPF_X */
2840 {
2841 "ALU_OR_X: 1 | 2 = 3",
2842 .u.insns_int = {
2843 BPF_LD_IMM64(R0, 1),
2844 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2845 BPF_ALU32_REG(BPF_OR, R0, R1),
2846 BPF_EXIT_INSN(),
2847 },
2848 INTERNAL,
2849 { },
2850 { { 0, 3 } },
2851 },
2852 {
2853 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
2854 .u.insns_int = {
2855 BPF_LD_IMM64(R0, 0),
2856 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
2857 BPF_ALU32_REG(BPF_OR, R0, R1),
2858 BPF_EXIT_INSN(),
2859 },
2860 INTERNAL,
2861 { },
2862 { { 0, 0xffffffff } },
2863 },
2864 {
2865 "ALU64_OR_X: 1 | 2 = 3",
2866 .u.insns_int = {
2867 BPF_LD_IMM64(R0, 1),
2868 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2869 BPF_ALU64_REG(BPF_OR, R0, R1),
2870 BPF_EXIT_INSN(),
2871 },
2872 INTERNAL,
2873 { },
2874 { { 0, 3 } },
2875 },
2876 {
2877 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
2878 .u.insns_int = {
2879 BPF_LD_IMM64(R0, 0),
2880 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
2881 BPF_ALU64_REG(BPF_OR, R0, R1),
2882 BPF_EXIT_INSN(),
2883 },
2884 INTERNAL,
2885 { },
2886 { { 0, 0xffffffff } },
2887 },
2888 /* BPF_ALU | BPF_OR | BPF_K */
2889 {
2890 "ALU_OR_K: 1 | 2 = 3",
2891 .u.insns_int = {
2892 BPF_LD_IMM64(R0, 1),
2893 BPF_ALU32_IMM(BPF_OR, R0, 2),
2894 BPF_EXIT_INSN(),
2895 },
2896 INTERNAL,
2897 { },
2898 { { 0, 3 } },
2899 },
2900 {
2901 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
2902 .u.insns_int = {
2903 BPF_LD_IMM64(R0, 0),
2904 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
2905 BPF_EXIT_INSN(),
2906 },
2907 INTERNAL,
2908 { },
2909 { { 0, 0xffffffff } },
2910 },
2911 {
2912 "ALU64_OR_K: 1 | 2 = 3",
2913 .u.insns_int = {
2914 BPF_LD_IMM64(R0, 1),
2915 BPF_ALU64_IMM(BPF_OR, R0, 2),
2916 BPF_EXIT_INSN(),
2917 },
2918 INTERNAL,
2919 { },
2920 { { 0, 3 } },
2921 },
2922 {
2923 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
2924 .u.insns_int = {
2925 BPF_LD_IMM64(R0, 0),
2926 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
2927 BPF_EXIT_INSN(),
2928 },
2929 INTERNAL,
2930 { },
2931 { { 0, 0xffffffff } },
2932 },
2933 {
2934 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
2935 .u.insns_int = {
2936 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
2937 BPF_LD_IMM64(R3, 0x0000ffffffff0000),
2938 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
2939 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2940 BPF_MOV32_IMM(R0, 2),
2941 BPF_EXIT_INSN(),
2942 BPF_MOV32_IMM(R0, 1),
2943 BPF_EXIT_INSN(),
2944 },
2945 INTERNAL,
2946 { },
2947 { { 0, 0x1 } },
2948 },
2949 {
2950 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
2951 .u.insns_int = {
2952 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
2953 BPF_LD_IMM64(R3, 0xffffffffffffffff),
2954 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
2955 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2956 BPF_MOV32_IMM(R0, 2),
2957 BPF_EXIT_INSN(),
2958 BPF_MOV32_IMM(R0, 1),
2959 BPF_EXIT_INSN(),
2960 },
2961 INTERNAL,
2962 { },
2963 { { 0, 0x1 } },
2964 },
2965 {
2966 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
2967 .u.insns_int = {
2968 BPF_LD_IMM64(R2, 0x0000000000000000),
2969 BPF_LD_IMM64(R3, 0xffffffffffffffff),
2970 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
2971 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2972 BPF_MOV32_IMM(R0, 2),
2973 BPF_EXIT_INSN(),
2974 BPF_MOV32_IMM(R0, 1),
2975 BPF_EXIT_INSN(),
2976 },
2977 INTERNAL,
2978 { },
2979 { { 0, 0x1 } },
2980 },
2981 /* BPF_ALU | BPF_XOR | BPF_X */
2982 {
2983 "ALU_XOR_X: 5 ^ 6 = 3",
2984 .u.insns_int = {
2985 BPF_LD_IMM64(R0, 5),
2986 BPF_ALU32_IMM(BPF_MOV, R1, 6),
2987 BPF_ALU32_REG(BPF_XOR, R0, R1),
2988 BPF_EXIT_INSN(),
2989 },
2990 INTERNAL,
2991 { },
2992 { { 0, 3 } },
2993 },
2994 {
2995 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
2996 .u.insns_int = {
2997 BPF_LD_IMM64(R0, 1),
2998 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
2999 BPF_ALU32_REG(BPF_XOR, R0, R1),
3000 BPF_EXIT_INSN(),
3001 },
3002 INTERNAL,
3003 { },
3004 { { 0, 0xfffffffe } },
3005 },
3006 {
3007 "ALU64_XOR_X: 5 ^ 6 = 3",
3008 .u.insns_int = {
3009 BPF_LD_IMM64(R0, 5),
3010 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3011 BPF_ALU64_REG(BPF_XOR, R0, R1),
3012 BPF_EXIT_INSN(),
3013 },
3014 INTERNAL,
3015 { },
3016 { { 0, 3 } },
3017 },
3018 {
3019 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3020 .u.insns_int = {
3021 BPF_LD_IMM64(R0, 1),
3022 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3023 BPF_ALU64_REG(BPF_XOR, R0, R1),
3024 BPF_EXIT_INSN(),
3025 },
3026 INTERNAL,
3027 { },
3028 { { 0, 0xfffffffe } },
3029 },
3030 /* BPF_ALU | BPF_XOR | BPF_K */
3031 {
3032 "ALU_XOR_K: 5 ^ 6 = 3",
3033 .u.insns_int = {
3034 BPF_LD_IMM64(R0, 5),
3035 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3036 BPF_EXIT_INSN(),
3037 },
3038 INTERNAL,
3039 { },
3040 { { 0, 3 } },
3041 },
3042 {
3043 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3044 .u.insns_int = {
3045 BPF_LD_IMM64(R0, 1),
3046 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3047 BPF_EXIT_INSN(),
3048 },
3049 INTERNAL,
3050 { },
3051 { { 0, 0xfffffffe } },
3052 },
3053 {
3054 "ALU64_XOR_K: 5 ^ 6 = 3",
3055 .u.insns_int = {
3056 BPF_LD_IMM64(R0, 5),
3057 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3058 BPF_EXIT_INSN(),
3059 },
3060 INTERNAL,
3061 { },
3062 { { 0, 3 } },
3063 },
3064 {
3065 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3066 .u.insns_int = {
3067 BPF_LD_IMM64(R0, 1),
3068 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3069 BPF_EXIT_INSN(),
3070 },
3071 INTERNAL,
3072 { },
3073 { { 0, 0xfffffffe } },
3074 },
3075 {
3076 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3077 .u.insns_int = {
3078 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
3079 BPF_LD_IMM64(R3, 0x0000ffffffff0000),
3080 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3081 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3082 BPF_MOV32_IMM(R0, 2),
3083 BPF_EXIT_INSN(),
3084 BPF_MOV32_IMM(R0, 1),
3085 BPF_EXIT_INSN(),
3086 },
3087 INTERNAL,
3088 { },
3089 { { 0, 0x1 } },
3090 },
3091 {
3092 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3093 .u.insns_int = {
3094 BPF_LD_IMM64(R2, 0x0000ffffffff0000),
3095 BPF_LD_IMM64(R3, 0xffff00000000ffff),
3096 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3097 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3098 BPF_MOV32_IMM(R0, 2),
3099 BPF_EXIT_INSN(),
3100 BPF_MOV32_IMM(R0, 1),
3101 BPF_EXIT_INSN(),
3102 },
3103 INTERNAL,
3104 { },
3105 { { 0, 0x1 } },
3106 },
3107 {
3108 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3109 .u.insns_int = {
3110 BPF_LD_IMM64(R2, 0x0000000000000000),
3111 BPF_LD_IMM64(R3, 0xffffffffffffffff),
3112 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3113 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3114 BPF_MOV32_IMM(R0, 2),
3115 BPF_EXIT_INSN(),
3116 BPF_MOV32_IMM(R0, 1),
3117 BPF_EXIT_INSN(),
3118 },
3119 INTERNAL,
3120 { },
3121 { { 0, 0x1 } },
3122 },
3123 /* BPF_ALU | BPF_LSH | BPF_X */
3124 {
3125 "ALU_LSH_X: 1 << 1 = 2",
3126 .u.insns_int = {
3127 BPF_LD_IMM64(R0, 1),
3128 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3129 BPF_ALU32_REG(BPF_LSH, R0, R1),
3130 BPF_EXIT_INSN(),
3131 },
3132 INTERNAL,
3133 { },
3134 { { 0, 2 } },
3135 },
3136 {
3137 "ALU_LSH_X: 1 << 31 = 0x80000000",
3138 .u.insns_int = {
3139 BPF_LD_IMM64(R0, 1),
3140 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3141 BPF_ALU32_REG(BPF_LSH, R0, R1),
3142 BPF_EXIT_INSN(),
3143 },
3144 INTERNAL,
3145 { },
3146 { { 0, 0x80000000 } },
3147 },
3148 {
3149 "ALU64_LSH_X: 1 << 1 = 2",
3150 .u.insns_int = {
3151 BPF_LD_IMM64(R0, 1),
3152 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3153 BPF_ALU64_REG(BPF_LSH, R0, R1),
3154 BPF_EXIT_INSN(),
3155 },
3156 INTERNAL,
3157 { },
3158 { { 0, 2 } },
3159 },
3160 {
3161 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3162 .u.insns_int = {
3163 BPF_LD_IMM64(R0, 1),
3164 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3165 BPF_ALU64_REG(BPF_LSH, R0, R1),
3166 BPF_EXIT_INSN(),
3167 },
3168 INTERNAL,
3169 { },
3170 { { 0, 0x80000000 } },
3171 },
3172 /* BPF_ALU | BPF_LSH | BPF_K */
3173 {
3174 "ALU_LSH_K: 1 << 1 = 2",
3175 .u.insns_int = {
3176 BPF_LD_IMM64(R0, 1),
3177 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3178 BPF_EXIT_INSN(),
3179 },
3180 INTERNAL,
3181 { },
3182 { { 0, 2 } },
3183 },
3184 {
3185 "ALU_LSH_K: 1 << 31 = 0x80000000",
3186 .u.insns_int = {
3187 BPF_LD_IMM64(R0, 1),
3188 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3189 BPF_EXIT_INSN(),
3190 },
3191 INTERNAL,
3192 { },
3193 { { 0, 0x80000000 } },
3194 },
3195 {
3196 "ALU64_LSH_K: 1 << 1 = 2",
3197 .u.insns_int = {
3198 BPF_LD_IMM64(R0, 1),
3199 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3200 BPF_EXIT_INSN(),
3201 },
3202 INTERNAL,
3203 { },
3204 { { 0, 2 } },
3205 },
3206 {
3207 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3208 .u.insns_int = {
3209 BPF_LD_IMM64(R0, 1),
3210 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3211 BPF_EXIT_INSN(),
3212 },
3213 INTERNAL,
3214 { },
3215 { { 0, 0x80000000 } },
3216 },
3217 /* BPF_ALU | BPF_RSH | BPF_X */
3218 {
3219 "ALU_RSH_X: 2 >> 1 = 1",
3220 .u.insns_int = {
3221 BPF_LD_IMM64(R0, 2),
3222 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3223 BPF_ALU32_REG(BPF_RSH, R0, R1),
3224 BPF_EXIT_INSN(),
3225 },
3226 INTERNAL,
3227 { },
3228 { { 0, 1 } },
3229 },
3230 {
3231 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3232 .u.insns_int = {
3233 BPF_LD_IMM64(R0, 0x80000000),
3234 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3235 BPF_ALU32_REG(BPF_RSH, R0, R1),
3236 BPF_EXIT_INSN(),
3237 },
3238 INTERNAL,
3239 { },
3240 { { 0, 1 } },
3241 },
3242 {
3243 "ALU64_RSH_X: 2 >> 1 = 1",
3244 .u.insns_int = {
3245 BPF_LD_IMM64(R0, 2),
3246 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3247 BPF_ALU64_REG(BPF_RSH, R0, R1),
3248 BPF_EXIT_INSN(),
3249 },
3250 INTERNAL,
3251 { },
3252 { { 0, 1 } },
3253 },
3254 {
3255 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3256 .u.insns_int = {
3257 BPF_LD_IMM64(R0, 0x80000000),
3258 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3259 BPF_ALU64_REG(BPF_RSH, R0, R1),
3260 BPF_EXIT_INSN(),
3261 },
3262 INTERNAL,
3263 { },
3264 { { 0, 1 } },
3265 },
3266 /* BPF_ALU | BPF_RSH | BPF_K */
3267 {
3268 "ALU_RSH_K: 2 >> 1 = 1",
3269 .u.insns_int = {
3270 BPF_LD_IMM64(R0, 2),
3271 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3272 BPF_EXIT_INSN(),
3273 },
3274 INTERNAL,
3275 { },
3276 { { 0, 1 } },
3277 },
3278 {
3279 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3280 .u.insns_int = {
3281 BPF_LD_IMM64(R0, 0x80000000),
3282 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3283 BPF_EXIT_INSN(),
3284 },
3285 INTERNAL,
3286 { },
3287 { { 0, 1 } },
3288 },
3289 {
3290 "ALU64_RSH_K: 2 >> 1 = 1",
3291 .u.insns_int = {
3292 BPF_LD_IMM64(R0, 2),
3293 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3294 BPF_EXIT_INSN(),
3295 },
3296 INTERNAL,
3297 { },
3298 { { 0, 1 } },
3299 },
3300 {
3301 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3302 .u.insns_int = {
3303 BPF_LD_IMM64(R0, 0x80000000),
3304 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3305 BPF_EXIT_INSN(),
3306 },
3307 INTERNAL,
3308 { },
3309 { { 0, 1 } },
3310 },
3311 /* BPF_ALU | BPF_ARSH | BPF_X */
3312 {
3313 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3314 .u.insns_int = {
3315 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3316 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3317 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3318 BPF_EXIT_INSN(),
3319 },
3320 INTERNAL,
3321 { },
3322 { { 0, 0xffff00ff } },
3323 },
3324 /* BPF_ALU | BPF_ARSH | BPF_K */
3325 {
3326 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3327 .u.insns_int = {
3328 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3329 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3330 BPF_EXIT_INSN(),
3331 },
3332 INTERNAL,
3333 { },
3334 { { 0, 0xffff00ff } },
3335 },
3336 /* BPF_ALU | BPF_NEG */
3337 {
3338 "ALU_NEG: -(3) = -3",
3339 .u.insns_int = {
3340 BPF_ALU32_IMM(BPF_MOV, R0, 3),
3341 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3342 BPF_EXIT_INSN(),
3343 },
3344 INTERNAL,
3345 { },
3346 { { 0, -3 } },
3347 },
3348 {
3349 "ALU_NEG: -(-3) = 3",
3350 .u.insns_int = {
3351 BPF_ALU32_IMM(BPF_MOV, R0, -3),
3352 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3353 BPF_EXIT_INSN(),
3354 },
3355 INTERNAL,
3356 { },
3357 { { 0, 3 } },
3358 },
3359 {
3360 "ALU64_NEG: -(3) = -3",
3361 .u.insns_int = {
3362 BPF_LD_IMM64(R0, 3),
3363 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3364 BPF_EXIT_INSN(),
3365 },
3366 INTERNAL,
3367 { },
3368 { { 0, -3 } },
3369 },
3370 {
3371 "ALU64_NEG: -(-3) = 3",
3372 .u.insns_int = {
3373 BPF_LD_IMM64(R0, -3),
3374 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3375 BPF_EXIT_INSN(),
3376 },
3377 INTERNAL,
3378 { },
3379 { { 0, 3 } },
3380 },
3381 /* BPF_ALU | BPF_END | BPF_FROM_BE */
3382 {
3383 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
3384 .u.insns_int = {
3385 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3386 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
3387 BPF_EXIT_INSN(),
3388 },
3389 INTERNAL,
3390 { },
3391 { { 0, cpu_to_be16(0xcdef) } },
3392 },
3393 {
3394 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
3395 .u.insns_int = {
3396 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3397 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
3398 BPF_EXIT_INSN(),
3399 },
3400 INTERNAL,
3401 { },
3402 { { 0, cpu_to_be32(0x89abcdef) } },
3403 },
3404 {
3405 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
3406 .u.insns_int = {
3407 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3408 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
3409 BPF_EXIT_INSN(),
3410 },
3411 INTERNAL,
3412 { },
3413 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
3414 },
3415 /* BPF_ALU | BPF_END | BPF_FROM_LE */
3416 {
3417 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
3418 .u.insns_int = {
3419 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3420 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
3421 BPF_EXIT_INSN(),
3422 },
3423 INTERNAL,
3424 { },
3425 { { 0, cpu_to_le16(0xcdef) } },
3426 },
3427 {
3428 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
3429 .u.insns_int = {
3430 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3431 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
3432 BPF_EXIT_INSN(),
3433 },
3434 INTERNAL,
3435 { },
3436 { { 0, cpu_to_le32(0x89abcdef) } },
3437 },
3438 {
3439 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
3440 .u.insns_int = {
3441 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3442 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
3443 BPF_EXIT_INSN(),
3444 },
3445 INTERNAL,
3446 { },
3447 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
3448 },
3449 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
3450 {
3451 "ST_MEM_B: Store/Load byte: max negative",
3452 .u.insns_int = {
3453 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3454 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
3455 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3456 BPF_EXIT_INSN(),
3457 },
3458 INTERNAL,
3459 { },
3460 { { 0, 0xff } },
3461 },
3462 {
3463 "ST_MEM_B: Store/Load byte: max positive",
3464 .u.insns_int = {
3465 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3466 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
3467 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3468 BPF_EXIT_INSN(),
3469 },
3470 INTERNAL,
3471 { },
3472 { { 0, 0x7f } },
3473 },
3474 {
3475 "STX_MEM_B: Store/Load byte: max negative",
3476 .u.insns_int = {
3477 BPF_LD_IMM64(R0, 0),
3478 BPF_LD_IMM64(R1, 0xffLL),
3479 BPF_STX_MEM(BPF_B, R10, R1, -40),
3480 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3481 BPF_EXIT_INSN(),
3482 },
3483 INTERNAL,
3484 { },
3485 { { 0, 0xff } },
3486 },
3487 {
3488 "ST_MEM_H: Store/Load half word: max negative",
3489 .u.insns_int = {
3490 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3491 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
3492 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3493 BPF_EXIT_INSN(),
3494 },
3495 INTERNAL,
3496 { },
3497 { { 0, 0xffff } },
3498 },
3499 {
3500 "ST_MEM_H: Store/Load half word: max positive",
3501 .u.insns_int = {
3502 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3503 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
3504 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3505 BPF_EXIT_INSN(),
3506 },
3507 INTERNAL,
3508 { },
3509 { { 0, 0x7fff } },
3510 },
3511 {
3512 "STX_MEM_H: Store/Load half word: max negative",
3513 .u.insns_int = {
3514 BPF_LD_IMM64(R0, 0),
3515 BPF_LD_IMM64(R1, 0xffffLL),
3516 BPF_STX_MEM(BPF_H, R10, R1, -40),
3517 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3518 BPF_EXIT_INSN(),
3519 },
3520 INTERNAL,
3521 { },
3522 { { 0, 0xffff } },
3523 },
3524 {
3525 "ST_MEM_W: Store/Load word: max negative",
3526 .u.insns_int = {
3527 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3528 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
3529 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3530 BPF_EXIT_INSN(),
3531 },
3532 INTERNAL,
3533 { },
3534 { { 0, 0xffffffff } },
3535 },
3536 {
3537 "ST_MEM_W: Store/Load word: max positive",
3538 .u.insns_int = {
3539 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3540 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
3541 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3542 BPF_EXIT_INSN(),
3543 },
3544 INTERNAL,
3545 { },
3546 { { 0, 0x7fffffff } },
3547 },
3548 {
3549 "STX_MEM_W: Store/Load word: max negative",
3550 .u.insns_int = {
3551 BPF_LD_IMM64(R0, 0),
3552 BPF_LD_IMM64(R1, 0xffffffffLL),
3553 BPF_STX_MEM(BPF_W, R10, R1, -40),
3554 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3555 BPF_EXIT_INSN(),
3556 },
3557 INTERNAL,
3558 { },
3559 { { 0, 0xffffffff } },
3560 },
3561 {
3562 "ST_MEM_DW: Store/Load double word: max negative",
3563 .u.insns_int = {
3564 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3565 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3566 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3567 BPF_EXIT_INSN(),
3568 },
3569 INTERNAL,
3570 { },
3571 { { 0, 0xffffffff } },
3572 },
3573 {
3574 "ST_MEM_DW: Store/Load double word: max negative 2",
3575 .u.insns_int = {
3576 BPF_LD_IMM64(R2, 0xffff00000000ffff),
3577 BPF_LD_IMM64(R3, 0xffffffffffffffff),
3578 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3579 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
3580 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3581 BPF_MOV32_IMM(R0, 2),
3582 BPF_EXIT_INSN(),
3583 BPF_MOV32_IMM(R0, 1),
3584 BPF_EXIT_INSN(),
3585 },
3586 INTERNAL,
3587 { },
3588 { { 0, 0x1 } },
3589 },
3590 {
3591 "ST_MEM_DW: Store/Load double word: max positive",
3592 .u.insns_int = {
3593 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3594 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
3595 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3596 BPF_EXIT_INSN(),
3597 },
3598 INTERNAL,
3599 { },
3600 { { 0, 0x7fffffff } },
3601 },
3602 {
3603 "STX_MEM_DW: Store/Load double word: max negative",
3604 .u.insns_int = {
3605 BPF_LD_IMM64(R0, 0),
3606 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3607 BPF_STX_MEM(BPF_W, R10, R1, -40),
3608 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3609 BPF_EXIT_INSN(),
3610 },
3611 INTERNAL,
3612 { },
3613 { { 0, 0xffffffff } },
3614 },
3615 /* BPF_STX | BPF_XADD | BPF_W/DW */
3616 {
3617 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
3618 .u.insns_int = {
3619 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3620 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
3621 BPF_STX_XADD(BPF_W, R10, R0, -40),
3622 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3623 BPF_EXIT_INSN(),
3624 },
3625 INTERNAL,
3626 { },
3627 { { 0, 0x22 } },
3628 },
3629 {
3630 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
3631 .u.insns_int = {
3632 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3633 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
3634 BPF_STX_XADD(BPF_DW, R10, R0, -40),
3635 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3636 BPF_EXIT_INSN(),
3637 },
3638 INTERNAL,
3639 { },
3640 { { 0, 0x22 } },
3641 },
3642 /* BPF_JMP | BPF_EXIT */
3643 {
3644 "JMP_EXIT",
3645 .u.insns_int = {
3646 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
3647 BPF_EXIT_INSN(),
3648 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
3649 },
3650 INTERNAL,
3651 { },
3652 { { 0, 0x4711 } },
3653 },
3654 /* BPF_JMP | BPF_JA */
3655 {
3656 "JMP_JA: Unconditional jump: if (true) return 1",
3657 .u.insns_int = {
3658 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3659 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
3660 BPF_EXIT_INSN(),
3661 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3662 BPF_EXIT_INSN(),
3663 },
3664 INTERNAL,
3665 { },
3666 { { 0, 1 } },
3667 },
3668 /* BPF_JMP | BPF_JSGT | BPF_K */
3669 {
3670 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
3671 .u.insns_int = {
3672 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3673 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3674 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
3675 BPF_EXIT_INSN(),
3676 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3677 BPF_EXIT_INSN(),
3678 },
3679 INTERNAL,
3680 { },
3681 { { 0, 1 } },
3682 },
3683 {
3684 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
3685 .u.insns_int = {
3686 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3687 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3688 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
3689 BPF_EXIT_INSN(),
3690 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3691 BPF_EXIT_INSN(),
3692 },
3693 INTERNAL,
3694 { },
3695 { { 0, 1 } },
3696 },
3697 /* BPF_JMP | BPF_JSGE | BPF_K */
3698 {
3699 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
3700 .u.insns_int = {
3701 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3702 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3703 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
3704 BPF_EXIT_INSN(),
3705 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3706 BPF_EXIT_INSN(),
3707 },
3708 INTERNAL,
3709 { },
3710 { { 0, 1 } },
3711 },
3712 {
3713 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
3714 .u.insns_int = {
3715 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3716 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3717 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
3718 BPF_EXIT_INSN(),
3719 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3720 BPF_EXIT_INSN(),
3721 },
3722 INTERNAL,
3723 { },
3724 { { 0, 1 } },
3725 },
3726 /* BPF_JMP | BPF_JGT | BPF_K */
3727 {
3728 "JMP_JGT_K: if (3 > 2) return 1",
3729 .u.insns_int = {
3730 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3731 BPF_LD_IMM64(R1, 3),
3732 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
3733 BPF_EXIT_INSN(),
3734 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3735 BPF_EXIT_INSN(),
3736 },
3737 INTERNAL,
3738 { },
3739 { { 0, 1 } },
3740 },
3741 /* BPF_JMP | BPF_JGE | BPF_K */
3742 {
3743 "JMP_JGE_K: if (3 >= 2) return 1",
3744 .u.insns_int = {
3745 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3746 BPF_LD_IMM64(R1, 3),
3747 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
3748 BPF_EXIT_INSN(),
3749 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3750 BPF_EXIT_INSN(),
3751 },
3752 INTERNAL,
3753 { },
3754 { { 0, 1 } },
3755 },
3756 {
3757 "JMP_JGE_K: if (3 >= 3) return 1",
3758 .u.insns_int = {
3759 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3760 BPF_LD_IMM64(R1, 3),
3761 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
3762 BPF_EXIT_INSN(),
3763 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3764 BPF_EXIT_INSN(),
3765 },
3766 INTERNAL,
3767 { },
3768 { { 0, 1 } },
3769 },
3770 /* BPF_JMP | BPF_JNE | BPF_K */
3771 {
3772 "JMP_JNE_K: if (3 != 2) return 1",
3773 .u.insns_int = {
3774 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3775 BPF_LD_IMM64(R1, 3),
3776 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
3777 BPF_EXIT_INSN(),
3778 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3779 BPF_EXIT_INSN(),
3780 },
3781 INTERNAL,
3782 { },
3783 { { 0, 1 } },
3784 },
3785 /* BPF_JMP | BPF_JEQ | BPF_K */
3786 {
3787 "JMP_JEQ_K: if (3 == 3) return 1",
3788 .u.insns_int = {
3789 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3790 BPF_LD_IMM64(R1, 3),
3791 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
3792 BPF_EXIT_INSN(),
3793 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3794 BPF_EXIT_INSN(),
3795 },
3796 INTERNAL,
3797 { },
3798 { { 0, 1 } },
3799 },
3800 /* BPF_JMP | BPF_JSET | BPF_K */
3801 {
3802 "JMP_JSET_K: if (0x3 & 0x2) return 1",
3803 .u.insns_int = {
3804 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3805 BPF_LD_IMM64(R1, 3),
3806 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
3807 BPF_EXIT_INSN(),
3808 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3809 BPF_EXIT_INSN(),
3810 },
3811 INTERNAL,
3812 { },
3813 { { 0, 1 } },
3814 },
3815 {
3816 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
3817 .u.insns_int = {
3818 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3819 BPF_LD_IMM64(R1, 3),
3820 BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1),
3821 BPF_EXIT_INSN(),
3822 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3823 BPF_EXIT_INSN(),
3824 },
3825 INTERNAL,
3826 { },
3827 { { 0, 1 } },
3828 },
3829 /* BPF_JMP | BPF_JSGT | BPF_X */
3830 {
3831 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
3832 .u.insns_int = {
3833 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3834 BPF_LD_IMM64(R1, -1),
3835 BPF_LD_IMM64(R2, -2),
3836 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
3837 BPF_EXIT_INSN(),
3838 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3839 BPF_EXIT_INSN(),
3840 },
3841 INTERNAL,
3842 { },
3843 { { 0, 1 } },
3844 },
3845 {
3846 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
3847 .u.insns_int = {
3848 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3849 BPF_LD_IMM64(R1, -1),
3850 BPF_LD_IMM64(R2, -1),
3851 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
3852 BPF_EXIT_INSN(),
3853 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3854 BPF_EXIT_INSN(),
3855 },
3856 INTERNAL,
3857 { },
3858 { { 0, 1 } },
3859 },
3860 /* BPF_JMP | BPF_JSGE | BPF_X */
3861 {
3862 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
3863 .u.insns_int = {
3864 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3865 BPF_LD_IMM64(R1, -1),
3866 BPF_LD_IMM64(R2, -2),
3867 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
3868 BPF_EXIT_INSN(),
3869 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3870 BPF_EXIT_INSN(),
3871 },
3872 INTERNAL,
3873 { },
3874 { { 0, 1 } },
3875 },
3876 {
3877 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
3878 .u.insns_int = {
3879 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3880 BPF_LD_IMM64(R1, -1),
3881 BPF_LD_IMM64(R2, -1),
3882 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
3883 BPF_EXIT_INSN(),
3884 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3885 BPF_EXIT_INSN(),
3886 },
3887 INTERNAL,
3888 { },
3889 { { 0, 1 } },
3890 },
3891 /* BPF_JMP | BPF_JGT | BPF_X */
3892 {
3893 "JMP_JGT_X: if (3 > 2) return 1",
3894 .u.insns_int = {
3895 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3896 BPF_LD_IMM64(R1, 3),
3897 BPF_LD_IMM64(R2, 2),
3898 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
3899 BPF_EXIT_INSN(),
3900 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3901 BPF_EXIT_INSN(),
3902 },
3903 INTERNAL,
3904 { },
3905 { { 0, 1 } },
3906 },
3907 /* BPF_JMP | BPF_JGE | BPF_X */
3908 {
3909 "JMP_JGE_X: if (3 >= 2) return 1",
3910 .u.insns_int = {
3911 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3912 BPF_LD_IMM64(R1, 3),
3913 BPF_LD_IMM64(R2, 2),
3914 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
3915 BPF_EXIT_INSN(),
3916 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3917 BPF_EXIT_INSN(),
3918 },
3919 INTERNAL,
3920 { },
3921 { { 0, 1 } },
3922 },
3923 {
3924 "JMP_JGE_X: if (3 >= 3) return 1",
3925 .u.insns_int = {
3926 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3927 BPF_LD_IMM64(R1, 3),
3928 BPF_LD_IMM64(R2, 3),
3929 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
3930 BPF_EXIT_INSN(),
3931 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3932 BPF_EXIT_INSN(),
3933 },
3934 INTERNAL,
3935 { },
3936 { { 0, 1 } },
3937 },
3938 /* BPF_JMP | BPF_JNE | BPF_X */
3939 {
3940 "JMP_JNE_X: if (3 != 2) return 1",
3941 .u.insns_int = {
3942 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3943 BPF_LD_IMM64(R1, 3),
3944 BPF_LD_IMM64(R2, 2),
3945 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
3946 BPF_EXIT_INSN(),
3947 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3948 BPF_EXIT_INSN(),
3949 },
3950 INTERNAL,
3951 { },
3952 { { 0, 1 } },
3953 },
3954 /* BPF_JMP | BPF_JEQ | BPF_X */
3955 {
3956 "JMP_JEQ_X: if (3 == 3) return 1",
3957 .u.insns_int = {
3958 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3959 BPF_LD_IMM64(R1, 3),
3960 BPF_LD_IMM64(R2, 3),
3961 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
3962 BPF_EXIT_INSN(),
3963 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3964 BPF_EXIT_INSN(),
3965 },
3966 INTERNAL,
3967 { },
3968 { { 0, 1 } },
3969 },
3970 /* BPF_JMP | BPF_JSET | BPF_X */
3971 {
3972 "JMP_JSET_X: if (0x3 & 0x2) return 1",
3973 .u.insns_int = {
3974 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3975 BPF_LD_IMM64(R1, 3),
3976 BPF_LD_IMM64(R2, 2),
3977 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
3978 BPF_EXIT_INSN(),
3979 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3980 BPF_EXIT_INSN(),
3981 },
3982 INTERNAL,
3983 { },
3984 { { 0, 1 } },
3985 },
3986 {
3987 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
3988 .u.insns_int = {
3989 BPF_ALU32_IMM(BPF_MOV, R0, 0),
3990 BPF_LD_IMM64(R1, 3),
3991 BPF_LD_IMM64(R2, 0xffffffff),
3992 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
3993 BPF_EXIT_INSN(),
3994 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3995 BPF_EXIT_INSN(),
3996 },
3997 INTERNAL,
3998 { },
3999 { { 0, 1 } },
4000 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004001};
4002
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004003static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004004
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004005static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004006{
4007 struct sk_buff *skb;
4008
4009 if (size >= MAX_DATA)
4010 return NULL;
4011
4012 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
4013 if (!skb)
4014 return NULL;
4015
4016 memcpy(__skb_put(skb, size), buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004017
4018 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004019 skb_reset_mac_header(skb);
4020 skb->protocol = htons(ETH_P_IP);
4021 skb->pkt_type = SKB_TYPE;
4022 skb->mark = SKB_MARK;
4023 skb->hash = SKB_HASH;
4024 skb->queue_mapping = SKB_QUEUE_MAP;
4025 skb->vlan_tci = SKB_VLAN_TCI;
4026 skb->dev = &dev;
4027 skb->dev->ifindex = SKB_DEV_IFINDEX;
4028 skb->dev->type = SKB_DEV_TYPE;
4029 skb_set_network_header(skb, min(size, ETH_HLEN));
4030
4031 return skb;
4032}
4033
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004034static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004035{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004036 if (test->aux & FLAG_NO_DATA)
4037 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004038
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004039 /* Test case expects an skb, so populate one. Various
4040 * subtests generate skbs of different sizes based on
4041 * the same data.
4042 */
4043 return populate_skb(test->data, test->test[sub].data_size);
4044}
4045
4046static void release_test_data(const struct bpf_test *test, void *data)
4047{
4048 if (test->aux & FLAG_NO_DATA)
4049 return;
4050
4051 kfree_skb(data);
4052}
4053
4054static int probe_filter_length(struct sock_filter *fp)
4055{
4056 int len = 0;
4057
Chema Gonzaleze9d94502014-05-30 10:15:12 -07004058 for (len = MAX_INSNS - 1; len > 0; --len)
4059 if (fp[len].code != 0 || fp[len].k != 0)
4060 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004061
Chema Gonzaleze9d94502014-05-30 10:15:12 -07004062 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004063}
4064
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004065static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004066{
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004067 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004068 struct sock_fprog_kern fprog;
4069 unsigned int flen = probe_filter_length(tests[which].u.insns);
4070 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
4071
4072 switch (test_type) {
4073 case CLASSIC:
4074 fprog.filter = tests[which].u.insns;
4075 fprog.len = flen;
4076
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004077 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004078 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
4079 if (*err == -EINVAL) {
4080 pr_cont("PASS\n");
4081 /* Verifier rejected filter as expected. */
4082 *err = 0;
4083 return NULL;
4084 } else {
4085 pr_cont("UNEXPECTED_PASS\n");
4086 /* Verifier didn't reject the test that's
4087 * bad enough, just return!
4088 */
4089 *err = -EINVAL;
4090 return NULL;
4091 }
4092 }
4093 /* We don't expect to fail. */
4094 if (*err) {
4095 pr_cont("FAIL to attach err=%d len=%d\n",
4096 *err, fprog.len);
4097 return NULL;
4098 }
4099 break;
4100
4101 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02004102 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004103 if (fp == NULL) {
4104 pr_cont("UNEXPECTED_FAIL no memory left\n");
4105 *err = -ENOMEM;
4106 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004107 }
4108
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004109 fp->len = flen;
4110 memcpy(fp->insnsi, tests[which].u.insns_int,
Alexei Starovoitov2695fb52014-07-24 16:38:21 -07004111 fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004112
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004113 bpf_prog_select_runtime(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004114 break;
4115 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004116
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004117 *err = 0;
4118 return fp;
4119}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004120
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004121static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004122{
4123 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004124
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004125 switch (test_type) {
4126 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004127 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004128 break;
4129 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004130 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004131 break;
4132 }
4133}
4134
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004135static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004136 int runs, u64 *duration)
4137{
4138 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07004139 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004140
4141 start = ktime_to_us(ktime_get());
4142
4143 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004144 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004145
4146 finish = ktime_to_us(ktime_get());
4147
4148 *duration = (finish - start) * 1000ULL;
4149 do_div(*duration, runs);
4150
4151 return ret;
4152}
4153
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004154static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004155{
4156 int err_cnt = 0, i, runs = MAX_TESTRUNS;
4157
4158 for (i = 0; i < MAX_SUBTESTS; i++) {
4159 void *data;
4160 u64 duration;
4161 u32 ret;
4162
4163 if (test->test[i].data_size == 0 &&
4164 test->test[i].result == 0)
4165 break;
4166
4167 data = generate_test_data(test, i);
4168 ret = __run_one(fp, data, runs, &duration);
4169 release_test_data(test, data);
4170
4171 if (ret == test->test[i].result) {
4172 pr_cont("%lld ", duration);
4173 } else {
4174 pr_cont("ret %d != %d ", ret,
4175 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004176 err_cnt++;
4177 }
4178 }
4179
4180 return err_cnt;
4181}
4182
4183static __init int test_bpf(void)
4184{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004185 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02004186 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004187
4188 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07004189 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004190 int err;
4191
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004192 pr_info("#%d %s ", i, tests[i].descr);
4193
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004194 fp = generate_filter(i, &err);
4195 if (fp == NULL) {
4196 if (err == 0) {
4197 pass_cnt++;
4198 continue;
4199 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004200
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004201 return err;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004202 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02004203
4204 pr_cont("jited:%u ", fp->jited);
4205
4206 run_cnt++;
4207 if (fp->jited)
4208 jit_cnt++;
4209
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004210 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004211 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004212
4213 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004214 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004215 err_cnt++;
4216 } else {
4217 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004218 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004219 }
4220 }
4221
Daniel Borkmann327941f2015-04-30 16:17:27 +02004222 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
4223 pass_cnt, err_cnt, jit_cnt, run_cnt);
4224
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004225 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004226}
4227
4228static int __init test_bpf_init(void)
4229{
4230 return test_bpf();
4231}
4232
4233static void __exit test_bpf_exit(void)
4234{
4235}
4236
4237module_init(test_bpf_init);
4238module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02004239
Alexei Starovoitov64a89462014-05-08 14:10:52 -07004240MODULE_LICENSE("GPL");