blob: 80d78c51f65fc2bf007b2cc9222bb0714d4b3e68 [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(),
1758 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1759 BPF_EXIT_INSN(),
1760 },
1761 INTERNAL,
1762 { },
1763 { { 0, 1 } }
1764 },
Alexei Starovoitove21ab362014-10-28 15:11:43 -07001765 {
1766 "nmap reduced",
1767 .u.insns_int = {
1768 BPF_MOV64_REG(R6, R1),
1769 BPF_LD_ABS(BPF_H, 12),
1770 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
1771 BPF_LD_ABS(BPF_H, 12),
1772 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
1773 BPF_MOV32_IMM(R0, 18),
1774 BPF_STX_MEM(BPF_W, R10, R0, -64),
1775 BPF_LDX_MEM(BPF_W, R7, R10, -64),
1776 BPF_LD_IND(BPF_W, R7, 14),
1777 BPF_STX_MEM(BPF_W, R10, R0, -60),
1778 BPF_MOV32_IMM(R0, 280971478),
1779 BPF_STX_MEM(BPF_W, R10, R0, -56),
1780 BPF_LDX_MEM(BPF_W, R7, R10, -56),
1781 BPF_LDX_MEM(BPF_W, R0, R10, -60),
1782 BPF_ALU32_REG(BPF_SUB, R0, R7),
1783 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
1784 BPF_LD_ABS(BPF_H, 12),
1785 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
1786 BPF_MOV32_IMM(R0, 22),
1787 BPF_STX_MEM(BPF_W, R10, R0, -56),
1788 BPF_LDX_MEM(BPF_W, R7, R10, -56),
1789 BPF_LD_IND(BPF_H, R7, 14),
1790 BPF_STX_MEM(BPF_W, R10, R0, -52),
1791 BPF_MOV32_IMM(R0, 17366),
1792 BPF_STX_MEM(BPF_W, R10, R0, -48),
1793 BPF_LDX_MEM(BPF_W, R7, R10, -48),
1794 BPF_LDX_MEM(BPF_W, R0, R10, -52),
1795 BPF_ALU32_REG(BPF_SUB, R0, R7),
1796 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
1797 BPF_MOV32_IMM(R0, 256),
1798 BPF_EXIT_INSN(),
1799 BPF_MOV32_IMM(R0, 0),
1800 BPF_EXIT_INSN(),
1801 },
1802 INTERNAL,
1803 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
1804 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1805 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
1806 { { 38, 256 } }
1807 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001808};
1809
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001810static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001811
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001812static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001813{
1814 struct sk_buff *skb;
1815
1816 if (size >= MAX_DATA)
1817 return NULL;
1818
1819 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
1820 if (!skb)
1821 return NULL;
1822
1823 memcpy(__skb_put(skb, size), buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001824
1825 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001826 skb_reset_mac_header(skb);
1827 skb->protocol = htons(ETH_P_IP);
1828 skb->pkt_type = SKB_TYPE;
1829 skb->mark = SKB_MARK;
1830 skb->hash = SKB_HASH;
1831 skb->queue_mapping = SKB_QUEUE_MAP;
1832 skb->vlan_tci = SKB_VLAN_TCI;
1833 skb->dev = &dev;
1834 skb->dev->ifindex = SKB_DEV_IFINDEX;
1835 skb->dev->type = SKB_DEV_TYPE;
1836 skb_set_network_header(skb, min(size, ETH_HLEN));
1837
1838 return skb;
1839}
1840
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001841static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001842{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001843 if (test->aux & FLAG_NO_DATA)
1844 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001845
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001846 /* Test case expects an skb, so populate one. Various
1847 * subtests generate skbs of different sizes based on
1848 * the same data.
1849 */
1850 return populate_skb(test->data, test->test[sub].data_size);
1851}
1852
1853static void release_test_data(const struct bpf_test *test, void *data)
1854{
1855 if (test->aux & FLAG_NO_DATA)
1856 return;
1857
1858 kfree_skb(data);
1859}
1860
1861static int probe_filter_length(struct sock_filter *fp)
1862{
1863 int len = 0;
1864
Chema Gonzaleze9d94502014-05-30 10:15:12 -07001865 for (len = MAX_INSNS - 1; len > 0; --len)
1866 if (fp[len].code != 0 || fp[len].k != 0)
1867 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001868
Chema Gonzaleze9d94502014-05-30 10:15:12 -07001869 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001870}
1871
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001872static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001873{
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001874 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001875 struct sock_fprog_kern fprog;
1876 unsigned int flen = probe_filter_length(tests[which].u.insns);
1877 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
1878
1879 switch (test_type) {
1880 case CLASSIC:
1881 fprog.filter = tests[which].u.insns;
1882 fprog.len = flen;
1883
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001884 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001885 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
1886 if (*err == -EINVAL) {
1887 pr_cont("PASS\n");
1888 /* Verifier rejected filter as expected. */
1889 *err = 0;
1890 return NULL;
1891 } else {
1892 pr_cont("UNEXPECTED_PASS\n");
1893 /* Verifier didn't reject the test that's
1894 * bad enough, just return!
1895 */
1896 *err = -EINVAL;
1897 return NULL;
1898 }
1899 }
1900 /* We don't expect to fail. */
1901 if (*err) {
1902 pr_cont("FAIL to attach err=%d len=%d\n",
1903 *err, fprog.len);
1904 return NULL;
1905 }
1906 break;
1907
1908 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02001909 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001910 if (fp == NULL) {
1911 pr_cont("UNEXPECTED_FAIL no memory left\n");
1912 *err = -ENOMEM;
1913 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001914 }
1915
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001916 fp->len = flen;
1917 memcpy(fp->insnsi, tests[which].u.insns_int,
Alexei Starovoitov2695fb52014-07-24 16:38:21 -07001918 fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001919
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001920 bpf_prog_select_runtime(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001921 break;
1922 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001923
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001924 *err = 0;
1925 return fp;
1926}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001927
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001928static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001929{
1930 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001931
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001932 switch (test_type) {
1933 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001934 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001935 break;
1936 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001937 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001938 break;
1939 }
1940}
1941
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001942static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001943 int runs, u64 *duration)
1944{
1945 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07001946 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001947
1948 start = ktime_to_us(ktime_get());
1949
1950 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001951 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001952
1953 finish = ktime_to_us(ktime_get());
1954
1955 *duration = (finish - start) * 1000ULL;
1956 do_div(*duration, runs);
1957
1958 return ret;
1959}
1960
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001961static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001962{
1963 int err_cnt = 0, i, runs = MAX_TESTRUNS;
1964
1965 for (i = 0; i < MAX_SUBTESTS; i++) {
1966 void *data;
1967 u64 duration;
1968 u32 ret;
1969
1970 if (test->test[i].data_size == 0 &&
1971 test->test[i].result == 0)
1972 break;
1973
1974 data = generate_test_data(test, i);
1975 ret = __run_one(fp, data, runs, &duration);
1976 release_test_data(test, data);
1977
1978 if (ret == test->test[i].result) {
1979 pr_cont("%lld ", duration);
1980 } else {
1981 pr_cont("ret %d != %d ", ret,
1982 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001983 err_cnt++;
1984 }
1985 }
1986
1987 return err_cnt;
1988}
1989
1990static __init int test_bpf(void)
1991{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001992 int i, err_cnt = 0, pass_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001993
1994 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001995 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001996 int err;
1997
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001998 pr_info("#%d %s ", i, tests[i].descr);
1999
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002000 fp = generate_filter(i, &err);
2001 if (fp == NULL) {
2002 if (err == 0) {
2003 pass_cnt++;
2004 continue;
2005 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002006
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002007 return err;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002008 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002009 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002010 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002011
2012 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002013 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002014 err_cnt++;
2015 } else {
2016 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002017 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002018 }
2019 }
2020
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002021 pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
2022 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002023}
2024
2025static int __init test_bpf_init(void)
2026{
2027 return test_bpf();
2028}
2029
2030static void __exit test_bpf_exit(void)
2031{
2032}
2033
2034module_init(test_bpf_init);
2035module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002036
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002037MODULE_LICENSE("GPL");