1 /* 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 #include <linux/random.h> 25 26 /* General test specific settings */ 27 #define MAX_SUBTESTS 3 28 #define MAX_TESTRUNS 10000 29 #define MAX_DATA 128 30 #define MAX_INSNS 512 31 #define MAX_K 0xffffFFFF 32 33 /* Few constants used to init test 'skb' */ 34 #define SKB_TYPE 3 35 #define SKB_MARK 0x1234aaaa 36 #define SKB_HASH 0x1234aaab 37 #define SKB_QUEUE_MAP 123 38 #define SKB_VLAN_TCI 0xffff 39 #define SKB_DEV_IFINDEX 577 40 #define SKB_DEV_TYPE 588 41 42 /* Redefine REGs to make tests less verbose */ 43 #define R0 BPF_REG_0 44 #define R1 BPF_REG_1 45 #define R2 BPF_REG_2 46 #define R3 BPF_REG_3 47 #define R4 BPF_REG_4 48 #define R5 BPF_REG_5 49 #define R6 BPF_REG_6 50 #define R7 BPF_REG_7 51 #define R8 BPF_REG_8 52 #define R9 BPF_REG_9 53 #define R10 BPF_REG_10 54 55 /* Flags that can be passed to test cases */ 56 #define FLAG_NO_DATA BIT(0) 57 #define FLAG_EXPECTED_FAIL BIT(1) 58 59 enum { 60 CLASSIC = BIT(6), /* Old BPF instructions only. */ 61 INTERNAL = BIT(7), /* Extended instruction set. */ 62 }; 63 64 #define TEST_TYPE_MASK (CLASSIC | INTERNAL) 65 66 struct bpf_test { 67 const char *descr; 68 union { 69 struct sock_filter insns[MAX_INSNS]; 70 struct bpf_insn insns_int[MAX_INSNS]; 71 struct { 72 void *insns; 73 unsigned int len; 74 } ptr; 75 } u; 76 __u8 aux; 77 __u8 data[MAX_DATA]; 78 struct { 79 int data_size; 80 __u32 result; 81 } test[MAX_SUBTESTS]; 82 int (*fill_helper)(struct bpf_test *self); 83 }; 84 85 /* Large test cases need separate allocation and fill handler. */ 86 87 static int bpf_fill_maxinsns1(struct bpf_test *self) 88 { 89 unsigned int len = BPF_MAXINSNS; 90 struct sock_filter *insn; 91 __u32 k = ~0; 92 int i; 93 94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 95 if (!insn) 96 return -ENOMEM; 97 98 for (i = 0; i < len; i++, k--) 99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k); 100 101 self->u.ptr.insns = insn; 102 self->u.ptr.len = len; 103 104 return 0; 105 } 106 107 static int bpf_fill_maxinsns2(struct bpf_test *self) 108 { 109 unsigned int len = BPF_MAXINSNS; 110 struct sock_filter *insn; 111 int i; 112 113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 114 if (!insn) 115 return -ENOMEM; 116 117 for (i = 0; i < len; i++) 118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe); 119 120 self->u.ptr.insns = insn; 121 self->u.ptr.len = len; 122 123 return 0; 124 } 125 126 static int bpf_fill_maxinsns3(struct bpf_test *self) 127 { 128 unsigned int len = BPF_MAXINSNS; 129 struct sock_filter *insn; 130 struct rnd_state rnd; 131 int i; 132 133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 134 if (!insn) 135 return -ENOMEM; 136 137 prandom_seed_state(&rnd, 3141592653589793238ULL); 138 139 for (i = 0; i < len - 1; i++) { 140 __u32 k = prandom_u32_state(&rnd); 141 142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k); 143 } 144 145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); 146 147 self->u.ptr.insns = insn; 148 self->u.ptr.len = len; 149 150 return 0; 151 } 152 153 static int bpf_fill_maxinsns4(struct bpf_test *self) 154 { 155 unsigned int len = BPF_MAXINSNS + 1; 156 struct sock_filter *insn; 157 int i; 158 159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 160 if (!insn) 161 return -ENOMEM; 162 163 for (i = 0; i < len; i++) 164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe); 165 166 self->u.ptr.insns = insn; 167 self->u.ptr.len = len; 168 169 return 0; 170 } 171 172 static int bpf_fill_maxinsns5(struct bpf_test *self) 173 { 174 unsigned int len = BPF_MAXINSNS; 175 struct sock_filter *insn; 176 int i; 177 178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 179 if (!insn) 180 return -ENOMEM; 181 182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0); 183 184 for (i = 1; i < len - 1; i++) 185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe); 186 187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab); 188 189 self->u.ptr.insns = insn; 190 self->u.ptr.len = len; 191 192 return 0; 193 } 194 195 static int bpf_fill_maxinsns6(struct bpf_test *self) 196 { 197 unsigned int len = BPF_MAXINSNS; 198 struct sock_filter *insn; 199 int i; 200 201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 202 if (!insn) 203 return -ENOMEM; 204 205 for (i = 0; i < len - 1; i++) 206 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF + 207 SKF_AD_VLAN_TAG_PRESENT); 208 209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); 210 211 self->u.ptr.insns = insn; 212 self->u.ptr.len = len; 213 214 return 0; 215 } 216 217 static int bpf_fill_maxinsns7(struct bpf_test *self) 218 { 219 unsigned int len = BPF_MAXINSNS; 220 struct sock_filter *insn; 221 int i; 222 223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 224 if (!insn) 225 return -ENOMEM; 226 227 for (i = 0; i < len - 4; i++) 228 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF + 229 SKF_AD_CPU); 230 231 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0); 232 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF + 233 SKF_AD_CPU); 234 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0); 235 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); 236 237 self->u.ptr.insns = insn; 238 self->u.ptr.len = len; 239 240 return 0; 241 } 242 243 static int bpf_fill_maxinsns8(struct bpf_test *self) 244 { 245 unsigned int len = BPF_MAXINSNS; 246 struct sock_filter *insn; 247 int i, jmp_off = len - 3; 248 249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 250 if (!insn) 251 return -ENOMEM; 252 253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff); 254 255 for (i = 1; i < len - 1; i++) 256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0); 257 258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); 259 260 self->u.ptr.insns = insn; 261 self->u.ptr.len = len; 262 263 return 0; 264 } 265 266 static int bpf_fill_maxinsns9(struct bpf_test *self) 267 { 268 unsigned int len = BPF_MAXINSNS; 269 struct bpf_insn *insn; 270 int i; 271 272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 273 if (!insn) 274 return -ENOMEM; 275 276 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2); 277 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab); 278 insn[2] = BPF_EXIT_INSN(); 279 280 for (i = 3; i < len - 2; i++) 281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe); 282 283 insn[len - 2] = BPF_EXIT_INSN(); 284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1)); 285 286 self->u.ptr.insns = insn; 287 self->u.ptr.len = len; 288 289 return 0; 290 } 291 292 static int bpf_fill_maxinsns10(struct bpf_test *self) 293 { 294 unsigned int len = BPF_MAXINSNS, hlen = len - 2; 295 struct bpf_insn *insn; 296 int i; 297 298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 299 if (!insn) 300 return -ENOMEM; 301 302 for (i = 0; i < hlen / 2; i++) 303 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i); 304 for (i = hlen - 1; i > hlen / 2; i--) 305 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i); 306 307 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1); 308 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac); 309 insn[hlen + 1] = BPF_EXIT_INSN(); 310 311 self->u.ptr.insns = insn; 312 self->u.ptr.len = len; 313 314 return 0; 315 } 316 317 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len, 318 unsigned int plen) 319 { 320 struct sock_filter *insn; 321 unsigned int rlen; 322 int i, j; 323 324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); 325 if (!insn) 326 return -ENOMEM; 327 328 rlen = (len % plen) - 1; 329 330 for (i = 0; i + plen < len; i += plen) 331 for (j = 0; j < plen; j++) 332 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, 333 plen - 1 - j, 0, 0); 334 for (j = 0; j < rlen; j++) 335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j, 336 0, 0); 337 338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac); 339 340 self->u.ptr.insns = insn; 341 self->u.ptr.len = len; 342 343 return 0; 344 } 345 346 static int bpf_fill_maxinsns11(struct bpf_test *self) 347 { 348 /* Hits 70 passes on x86_64, so cannot get JITed there. */ 349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68); 350 } 351 352 static int bpf_fill_ja(struct bpf_test *self) 353 { 354 /* Hits exactly 11 passes on x86_64 JIT. */ 355 return __bpf_fill_ja(self, 12, 9); 356 } 357 358 static struct bpf_test tests[] = { 359 { 360 "TAX", 361 .u.insns = { 362 BPF_STMT(BPF_LD | BPF_IMM, 1), 363 BPF_STMT(BPF_MISC | BPF_TAX, 0), 364 BPF_STMT(BPF_LD | BPF_IMM, 2), 365 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 366 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */ 367 BPF_STMT(BPF_MISC | BPF_TAX, 0), 368 BPF_STMT(BPF_LD | BPF_LEN, 0), 369 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 370 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */ 371 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), 372 BPF_STMT(BPF_RET | BPF_A, 0) 373 }, 374 CLASSIC, 375 { 10, 20, 30, 40, 50 }, 376 { { 2, 10 }, { 3, 20 }, { 4, 30 } }, 377 }, 378 { 379 "TXA", 380 .u.insns = { 381 BPF_STMT(BPF_LDX | BPF_LEN, 0), 382 BPF_STMT(BPF_MISC | BPF_TXA, 0), 383 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 384 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */ 385 }, 386 CLASSIC, 387 { 10, 20, 30, 40, 50 }, 388 { { 1, 2 }, { 3, 6 }, { 4, 8 } }, 389 }, 390 { 391 "ADD_SUB_MUL_K", 392 .u.insns = { 393 BPF_STMT(BPF_LD | BPF_IMM, 1), 394 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2), 395 BPF_STMT(BPF_LDX | BPF_IMM, 3), 396 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 397 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff), 398 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3), 399 BPF_STMT(BPF_RET | BPF_A, 0) 400 }, 401 CLASSIC | FLAG_NO_DATA, 402 { }, 403 { { 0, 0xfffffffd } } 404 }, 405 { 406 "DIV_MOD_KX", 407 .u.insns = { 408 BPF_STMT(BPF_LD | BPF_IMM, 8), 409 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2), 410 BPF_STMT(BPF_MISC | BPF_TAX, 0), 411 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 412 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0), 413 BPF_STMT(BPF_MISC | BPF_TAX, 0), 414 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 415 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000), 416 BPF_STMT(BPF_MISC | BPF_TAX, 0), 417 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 418 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0), 419 BPF_STMT(BPF_MISC | BPF_TAX, 0), 420 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 421 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000), 422 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 423 BPF_STMT(BPF_RET | BPF_A, 0) 424 }, 425 CLASSIC | FLAG_NO_DATA, 426 { }, 427 { { 0, 0x20000000 } } 428 }, 429 { 430 "AND_OR_LSH_K", 431 .u.insns = { 432 BPF_STMT(BPF_LD | BPF_IMM, 0xff), 433 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), 434 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27), 435 BPF_STMT(BPF_MISC | BPF_TAX, 0), 436 BPF_STMT(BPF_LD | BPF_IMM, 0xf), 437 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0), 438 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 439 BPF_STMT(BPF_RET | BPF_A, 0) 440 }, 441 CLASSIC | FLAG_NO_DATA, 442 { }, 443 { { 0, 0x800000ff }, { 1, 0x800000ff } }, 444 }, 445 { 446 "LD_IMM_0", 447 .u.insns = { 448 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */ 449 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0), 450 BPF_STMT(BPF_RET | BPF_K, 0), 451 BPF_STMT(BPF_RET | BPF_K, 1), 452 }, 453 CLASSIC, 454 { }, 455 { { 1, 1 } }, 456 }, 457 { 458 "LD_IND", 459 .u.insns = { 460 BPF_STMT(BPF_LDX | BPF_LEN, 0), 461 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K), 462 BPF_STMT(BPF_RET | BPF_K, 1) 463 }, 464 CLASSIC, 465 { }, 466 { { 1, 0 }, { 10, 0 }, { 60, 0 } }, 467 }, 468 { 469 "LD_ABS", 470 .u.insns = { 471 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000), 472 BPF_STMT(BPF_RET | BPF_K, 1) 473 }, 474 CLASSIC, 475 { }, 476 { { 1, 0 }, { 10, 0 }, { 60, 0 } }, 477 }, 478 { 479 "LD_ABS_LL", 480 .u.insns = { 481 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF), 482 BPF_STMT(BPF_MISC | BPF_TAX, 0), 483 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1), 484 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 485 BPF_STMT(BPF_RET | BPF_A, 0) 486 }, 487 CLASSIC, 488 { 1, 2, 3 }, 489 { { 1, 0 }, { 2, 3 } }, 490 }, 491 { 492 "LD_IND_LL", 493 .u.insns = { 494 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1), 495 BPF_STMT(BPF_LDX | BPF_LEN, 0), 496 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 497 BPF_STMT(BPF_MISC | BPF_TAX, 0), 498 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), 499 BPF_STMT(BPF_RET | BPF_A, 0) 500 }, 501 CLASSIC, 502 { 1, 2, 3, 0xff }, 503 { { 1, 1 }, { 3, 3 }, { 4, 0xff } }, 504 }, 505 { 506 "LD_ABS_NET", 507 .u.insns = { 508 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF), 509 BPF_STMT(BPF_MISC | BPF_TAX, 0), 510 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1), 511 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 512 BPF_STMT(BPF_RET | BPF_A, 0) 513 }, 514 CLASSIC, 515 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, 516 { { 15, 0 }, { 16, 3 } }, 517 }, 518 { 519 "LD_IND_NET", 520 .u.insns = { 521 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15), 522 BPF_STMT(BPF_LDX | BPF_LEN, 0), 523 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 524 BPF_STMT(BPF_MISC | BPF_TAX, 0), 525 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), 526 BPF_STMT(BPF_RET | BPF_A, 0) 527 }, 528 CLASSIC, 529 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, 530 { { 14, 0 }, { 15, 1 }, { 17, 3 } }, 531 }, 532 { 533 "LD_PKTTYPE", 534 .u.insns = { 535 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 536 SKF_AD_OFF + SKF_AD_PKTTYPE), 537 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), 538 BPF_STMT(BPF_RET | BPF_K, 1), 539 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 540 SKF_AD_OFF + SKF_AD_PKTTYPE), 541 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), 542 BPF_STMT(BPF_RET | BPF_K, 1), 543 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 544 SKF_AD_OFF + SKF_AD_PKTTYPE), 545 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), 546 BPF_STMT(BPF_RET | BPF_K, 1), 547 BPF_STMT(BPF_RET | BPF_A, 0) 548 }, 549 CLASSIC, 550 { }, 551 { { 1, 3 }, { 10, 3 } }, 552 }, 553 { 554 "LD_MARK", 555 .u.insns = { 556 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 557 SKF_AD_OFF + SKF_AD_MARK), 558 BPF_STMT(BPF_RET | BPF_A, 0) 559 }, 560 CLASSIC, 561 { }, 562 { { 1, SKB_MARK}, { 10, SKB_MARK} }, 563 }, 564 { 565 "LD_RXHASH", 566 .u.insns = { 567 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 568 SKF_AD_OFF + SKF_AD_RXHASH), 569 BPF_STMT(BPF_RET | BPF_A, 0) 570 }, 571 CLASSIC, 572 { }, 573 { { 1, SKB_HASH}, { 10, SKB_HASH} }, 574 }, 575 { 576 "LD_QUEUE", 577 .u.insns = { 578 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 579 SKF_AD_OFF + SKF_AD_QUEUE), 580 BPF_STMT(BPF_RET | BPF_A, 0) 581 }, 582 CLASSIC, 583 { }, 584 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } }, 585 }, 586 { 587 "LD_PROTOCOL", 588 .u.insns = { 589 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1), 590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0), 591 BPF_STMT(BPF_RET | BPF_K, 0), 592 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 593 SKF_AD_OFF + SKF_AD_PROTOCOL), 594 BPF_STMT(BPF_MISC | BPF_TAX, 0), 595 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), 596 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0), 597 BPF_STMT(BPF_RET | BPF_K, 0), 598 BPF_STMT(BPF_MISC | BPF_TXA, 0), 599 BPF_STMT(BPF_RET | BPF_A, 0) 600 }, 601 CLASSIC, 602 { 10, 20, 30 }, 603 { { 10, ETH_P_IP }, { 100, ETH_P_IP } }, 604 }, 605 { 606 "LD_VLAN_TAG", 607 .u.insns = { 608 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 609 SKF_AD_OFF + SKF_AD_VLAN_TAG), 610 BPF_STMT(BPF_RET | BPF_A, 0) 611 }, 612 CLASSIC, 613 { }, 614 { 615 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }, 616 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT } 617 }, 618 }, 619 { 620 "LD_VLAN_TAG_PRESENT", 621 .u.insns = { 622 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 623 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT), 624 BPF_STMT(BPF_RET | BPF_A, 0) 625 }, 626 CLASSIC, 627 { }, 628 { 629 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, 630 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) } 631 }, 632 }, 633 { 634 "LD_IFINDEX", 635 .u.insns = { 636 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 637 SKF_AD_OFF + SKF_AD_IFINDEX), 638 BPF_STMT(BPF_RET | BPF_A, 0) 639 }, 640 CLASSIC, 641 { }, 642 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } }, 643 }, 644 { 645 "LD_HATYPE", 646 .u.insns = { 647 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 648 SKF_AD_OFF + SKF_AD_HATYPE), 649 BPF_STMT(BPF_RET | BPF_A, 0) 650 }, 651 CLASSIC, 652 { }, 653 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } }, 654 }, 655 { 656 "LD_CPU", 657 .u.insns = { 658 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 659 SKF_AD_OFF + SKF_AD_CPU), 660 BPF_STMT(BPF_MISC | BPF_TAX, 0), 661 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 662 SKF_AD_OFF + SKF_AD_CPU), 663 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 664 BPF_STMT(BPF_RET | BPF_A, 0) 665 }, 666 CLASSIC, 667 { }, 668 { { 1, 0 }, { 10, 0 } }, 669 }, 670 { 671 "LD_NLATTR", 672 .u.insns = { 673 BPF_STMT(BPF_LDX | BPF_IMM, 2), 674 BPF_STMT(BPF_MISC | BPF_TXA, 0), 675 BPF_STMT(BPF_LDX | BPF_IMM, 3), 676 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 677 SKF_AD_OFF + SKF_AD_NLATTR), 678 BPF_STMT(BPF_RET | BPF_A, 0) 679 }, 680 CLASSIC, 681 #ifdef __BIG_ENDIAN 682 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 }, 683 #else 684 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 }, 685 #endif 686 { { 4, 0 }, { 20, 6 } }, 687 }, 688 { 689 "LD_NLATTR_NEST", 690 .u.insns = { 691 BPF_STMT(BPF_LD | BPF_IMM, 2), 692 BPF_STMT(BPF_LDX | BPF_IMM, 3), 693 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 694 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 695 BPF_STMT(BPF_LD | BPF_IMM, 2), 696 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 697 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 698 BPF_STMT(BPF_LD | BPF_IMM, 2), 699 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 700 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 701 BPF_STMT(BPF_LD | BPF_IMM, 2), 702 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 703 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 704 BPF_STMT(BPF_LD | BPF_IMM, 2), 705 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 706 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 707 BPF_STMT(BPF_LD | BPF_IMM, 2), 708 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 709 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 710 BPF_STMT(BPF_LD | BPF_IMM, 2), 711 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 712 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 713 BPF_STMT(BPF_LD | BPF_IMM, 2), 714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 715 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 716 BPF_STMT(BPF_RET | BPF_A, 0) 717 }, 718 CLASSIC, 719 #ifdef __BIG_ENDIAN 720 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 }, 721 #else 722 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 }, 723 #endif 724 { { 4, 0 }, { 20, 10 } }, 725 }, 726 { 727 "LD_PAYLOAD_OFF", 728 .u.insns = { 729 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 730 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 731 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 732 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 733 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 734 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 735 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 736 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 737 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 738 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 739 BPF_STMT(BPF_RET | BPF_A, 0) 740 }, 741 CLASSIC, 742 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800), 743 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request, 744 * id 9737, seq 1, length 64 745 */ 746 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 747 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 748 0x08, 0x00, 749 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40, 750 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 }, 751 { { 30, 0 }, { 100, 42 } }, 752 }, 753 { 754 "LD_ANC_XOR", 755 .u.insns = { 756 BPF_STMT(BPF_LD | BPF_IMM, 10), 757 BPF_STMT(BPF_LDX | BPF_IMM, 300), 758 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 759 SKF_AD_OFF + SKF_AD_ALU_XOR_X), 760 BPF_STMT(BPF_RET | BPF_A, 0) 761 }, 762 CLASSIC, 763 { }, 764 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } }, 765 }, 766 { 767 "SPILL_FILL", 768 .u.insns = { 769 BPF_STMT(BPF_LDX | BPF_LEN, 0), 770 BPF_STMT(BPF_LD | BPF_IMM, 2), 771 BPF_STMT(BPF_ALU | BPF_RSH, 1), 772 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 773 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */ 774 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000), 775 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */ 776 BPF_STMT(BPF_STX, 15), /* M3 = len */ 777 BPF_STMT(BPF_LDX | BPF_MEM, 1), 778 BPF_STMT(BPF_LD | BPF_MEM, 2), 779 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 780 BPF_STMT(BPF_LDX | BPF_MEM, 15), 781 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 782 BPF_STMT(BPF_RET | BPF_A, 0) 783 }, 784 CLASSIC, 785 { }, 786 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } } 787 }, 788 { 789 "JEQ", 790 .u.insns = { 791 BPF_STMT(BPF_LDX | BPF_LEN, 0), 792 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), 793 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1), 794 BPF_STMT(BPF_RET | BPF_K, 1), 795 BPF_STMT(BPF_RET | BPF_K, MAX_K) 796 }, 797 CLASSIC, 798 { 3, 3, 3, 3, 3 }, 799 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } }, 800 }, 801 { 802 "JGT", 803 .u.insns = { 804 BPF_STMT(BPF_LDX | BPF_LEN, 0), 805 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), 806 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1), 807 BPF_STMT(BPF_RET | BPF_K, 1), 808 BPF_STMT(BPF_RET | BPF_K, MAX_K) 809 }, 810 CLASSIC, 811 { 4, 4, 4, 3, 3 }, 812 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } }, 813 }, 814 { 815 "JGE", 816 .u.insns = { 817 BPF_STMT(BPF_LDX | BPF_LEN, 0), 818 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K), 819 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0), 820 BPF_STMT(BPF_RET | BPF_K, 10), 821 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0), 822 BPF_STMT(BPF_RET | BPF_K, 20), 823 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0), 824 BPF_STMT(BPF_RET | BPF_K, 30), 825 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0), 826 BPF_STMT(BPF_RET | BPF_K, 40), 827 BPF_STMT(BPF_RET | BPF_K, MAX_K) 828 }, 829 CLASSIC, 830 { 1, 2, 3, 4, 5 }, 831 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } }, 832 }, 833 { 834 "JSET", 835 .u.insns = { 836 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), 837 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1), 838 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), 839 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), 840 BPF_STMT(BPF_LDX | BPF_LEN, 0), 841 BPF_STMT(BPF_MISC | BPF_TXA, 0), 842 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4), 843 BPF_STMT(BPF_MISC | BPF_TAX, 0), 844 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), 845 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1), 846 BPF_STMT(BPF_RET | BPF_K, 10), 847 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1), 848 BPF_STMT(BPF_RET | BPF_K, 20), 849 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 850 BPF_STMT(BPF_RET | BPF_K, 30), 851 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 852 BPF_STMT(BPF_RET | BPF_K, 30), 853 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 854 BPF_STMT(BPF_RET | BPF_K, 30), 855 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 856 BPF_STMT(BPF_RET | BPF_K, 30), 857 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 858 BPF_STMT(BPF_RET | BPF_K, 30), 859 BPF_STMT(BPF_RET | BPF_K, MAX_K) 860 }, 861 CLASSIC, 862 { 0, 0xAA, 0x55, 1 }, 863 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } }, 864 }, 865 { 866 "tcpdump port 22", 867 .u.insns = { 868 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), 869 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */ 870 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20), 871 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), 872 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), 873 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17), 874 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54), 875 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0), 876 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56), 877 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13), 878 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */ 879 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), 880 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), 881 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), 882 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8), 883 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), 884 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0), 885 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), 886 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), 887 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), 888 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), 889 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1), 890 BPF_STMT(BPF_RET | BPF_K, 0xffff), 891 BPF_STMT(BPF_RET | BPF_K, 0), 892 }, 893 CLASSIC, 894 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800) 895 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.], 896 * seq 1305692979:1305693027, ack 3650467037, win 65535, 897 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48 898 */ 899 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, 900 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, 901 0x08, 0x00, 902 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5, 903 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */ 904 0x0a, 0x01, 0x01, 0x95, /* ip src */ 905 0x0a, 0x01, 0x02, 0x0a, /* ip dst */ 906 0xc2, 0x24, 907 0x00, 0x16 /* dst port */ }, 908 { { 10, 0 }, { 30, 0 }, { 100, 65535 } }, 909 }, 910 { 911 "tcpdump complex", 912 .u.insns = { 913 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] - 914 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and 915 * (len > 115 or len < 30000000000)' -d 916 */ 917 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), 918 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0), 919 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29), 920 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), 921 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27), 922 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), 923 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0), 924 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), 925 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), 926 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), 927 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), 928 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20), 929 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16), 930 BPF_STMT(BPF_ST, 1), 931 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14), 932 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf), 933 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2), 934 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */ 935 BPF_STMT(BPF_LD | BPF_MEM, 1), 936 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 937 BPF_STMT(BPF_ST, 5), 938 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), 939 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26), 940 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), 941 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2), 942 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */ 943 BPF_STMT(BPF_LD | BPF_MEM, 5), 944 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0), 945 BPF_STMT(BPF_LD | BPF_LEN, 0), 946 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0), 947 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0), 948 BPF_STMT(BPF_RET | BPF_K, 0xffff), 949 BPF_STMT(BPF_RET | BPF_K, 0), 950 }, 951 CLASSIC, 952 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, 953 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, 954 0x08, 0x00, 955 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5, 956 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */ 957 0x0a, 0x01, 0x01, 0x95, /* ip src */ 958 0x0a, 0x01, 0x02, 0x0a, /* ip dst */ 959 0xc2, 0x24, 960 0x00, 0x16 /* dst port */ }, 961 { { 10, 0 }, { 30, 0 }, { 100, 65535 } }, 962 }, 963 { 964 "RET_A", 965 .u.insns = { 966 /* check that unitialized X and A contain zeros */ 967 BPF_STMT(BPF_MISC | BPF_TXA, 0), 968 BPF_STMT(BPF_RET | BPF_A, 0) 969 }, 970 CLASSIC, 971 { }, 972 { {1, 0}, {2, 0} }, 973 }, 974 { 975 "INT: ADD trivial", 976 .u.insns_int = { 977 BPF_ALU64_IMM(BPF_MOV, R1, 1), 978 BPF_ALU64_IMM(BPF_ADD, R1, 2), 979 BPF_ALU64_IMM(BPF_MOV, R2, 3), 980 BPF_ALU64_REG(BPF_SUB, R1, R2), 981 BPF_ALU64_IMM(BPF_ADD, R1, -1), 982 BPF_ALU64_IMM(BPF_MUL, R1, 3), 983 BPF_ALU64_REG(BPF_MOV, R0, R1), 984 BPF_EXIT_INSN(), 985 }, 986 INTERNAL, 987 { }, 988 { { 0, 0xfffffffd } } 989 }, 990 { 991 "INT: MUL_X", 992 .u.insns_int = { 993 BPF_ALU64_IMM(BPF_MOV, R0, -1), 994 BPF_ALU64_IMM(BPF_MOV, R1, -1), 995 BPF_ALU64_IMM(BPF_MOV, R2, 3), 996 BPF_ALU64_REG(BPF_MUL, R1, R2), 997 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1), 998 BPF_EXIT_INSN(), 999 BPF_ALU64_IMM(BPF_MOV, R0, 1), 1000 BPF_EXIT_INSN(), 1001 }, 1002 INTERNAL, 1003 { }, 1004 { { 0, 1 } } 1005 }, 1006 { 1007 "INT: MUL_X2", 1008 .u.insns_int = { 1009 BPF_ALU32_IMM(BPF_MOV, R0, -1), 1010 BPF_ALU32_IMM(BPF_MOV, R1, -1), 1011 BPF_ALU32_IMM(BPF_MOV, R2, 3), 1012 BPF_ALU64_REG(BPF_MUL, R1, R2), 1013 BPF_ALU64_IMM(BPF_RSH, R1, 8), 1014 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1), 1015 BPF_EXIT_INSN(), 1016 BPF_ALU32_IMM(BPF_MOV, R0, 1), 1017 BPF_EXIT_INSN(), 1018 }, 1019 INTERNAL, 1020 { }, 1021 { { 0, 1 } } 1022 }, 1023 { 1024 "INT: MUL32_X", 1025 .u.insns_int = { 1026 BPF_ALU32_IMM(BPF_MOV, R0, -1), 1027 BPF_ALU64_IMM(BPF_MOV, R1, -1), 1028 BPF_ALU32_IMM(BPF_MOV, R2, 3), 1029 BPF_ALU32_REG(BPF_MUL, R1, R2), 1030 BPF_ALU64_IMM(BPF_RSH, R1, 8), 1031 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1), 1032 BPF_EXIT_INSN(), 1033 BPF_ALU32_IMM(BPF_MOV, R0, 1), 1034 BPF_EXIT_INSN(), 1035 }, 1036 INTERNAL, 1037 { }, 1038 { { 0, 1 } } 1039 }, 1040 { 1041 /* Have to test all register combinations, since 1042 * JITing of different registers will produce 1043 * different asm code. 1044 */ 1045 "INT: ADD 64-bit", 1046 .u.insns_int = { 1047 BPF_ALU64_IMM(BPF_MOV, R0, 0), 1048 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1049 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1050 BPF_ALU64_IMM(BPF_MOV, R3, 3), 1051 BPF_ALU64_IMM(BPF_MOV, R4, 4), 1052 BPF_ALU64_IMM(BPF_MOV, R5, 5), 1053 BPF_ALU64_IMM(BPF_MOV, R6, 6), 1054 BPF_ALU64_IMM(BPF_MOV, R7, 7), 1055 BPF_ALU64_IMM(BPF_MOV, R8, 8), 1056 BPF_ALU64_IMM(BPF_MOV, R9, 9), 1057 BPF_ALU64_IMM(BPF_ADD, R0, 20), 1058 BPF_ALU64_IMM(BPF_ADD, R1, 20), 1059 BPF_ALU64_IMM(BPF_ADD, R2, 20), 1060 BPF_ALU64_IMM(BPF_ADD, R3, 20), 1061 BPF_ALU64_IMM(BPF_ADD, R4, 20), 1062 BPF_ALU64_IMM(BPF_ADD, R5, 20), 1063 BPF_ALU64_IMM(BPF_ADD, R6, 20), 1064 BPF_ALU64_IMM(BPF_ADD, R7, 20), 1065 BPF_ALU64_IMM(BPF_ADD, R8, 20), 1066 BPF_ALU64_IMM(BPF_ADD, R9, 20), 1067 BPF_ALU64_IMM(BPF_SUB, R0, 10), 1068 BPF_ALU64_IMM(BPF_SUB, R1, 10), 1069 BPF_ALU64_IMM(BPF_SUB, R2, 10), 1070 BPF_ALU64_IMM(BPF_SUB, R3, 10), 1071 BPF_ALU64_IMM(BPF_SUB, R4, 10), 1072 BPF_ALU64_IMM(BPF_SUB, R5, 10), 1073 BPF_ALU64_IMM(BPF_SUB, R6, 10), 1074 BPF_ALU64_IMM(BPF_SUB, R7, 10), 1075 BPF_ALU64_IMM(BPF_SUB, R8, 10), 1076 BPF_ALU64_IMM(BPF_SUB, R9, 10), 1077 BPF_ALU64_REG(BPF_ADD, R0, R0), 1078 BPF_ALU64_REG(BPF_ADD, R0, R1), 1079 BPF_ALU64_REG(BPF_ADD, R0, R2), 1080 BPF_ALU64_REG(BPF_ADD, R0, R3), 1081 BPF_ALU64_REG(BPF_ADD, R0, R4), 1082 BPF_ALU64_REG(BPF_ADD, R0, R5), 1083 BPF_ALU64_REG(BPF_ADD, R0, R6), 1084 BPF_ALU64_REG(BPF_ADD, R0, R7), 1085 BPF_ALU64_REG(BPF_ADD, R0, R8), 1086 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */ 1087 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1), 1088 BPF_EXIT_INSN(), 1089 BPF_ALU64_REG(BPF_ADD, R1, R0), 1090 BPF_ALU64_REG(BPF_ADD, R1, R1), 1091 BPF_ALU64_REG(BPF_ADD, R1, R2), 1092 BPF_ALU64_REG(BPF_ADD, R1, R3), 1093 BPF_ALU64_REG(BPF_ADD, R1, R4), 1094 BPF_ALU64_REG(BPF_ADD, R1, R5), 1095 BPF_ALU64_REG(BPF_ADD, R1, R6), 1096 BPF_ALU64_REG(BPF_ADD, R1, R7), 1097 BPF_ALU64_REG(BPF_ADD, R1, R8), 1098 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */ 1099 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1), 1100 BPF_EXIT_INSN(), 1101 BPF_ALU64_REG(BPF_ADD, R2, R0), 1102 BPF_ALU64_REG(BPF_ADD, R2, R1), 1103 BPF_ALU64_REG(BPF_ADD, R2, R2), 1104 BPF_ALU64_REG(BPF_ADD, R2, R3), 1105 BPF_ALU64_REG(BPF_ADD, R2, R4), 1106 BPF_ALU64_REG(BPF_ADD, R2, R5), 1107 BPF_ALU64_REG(BPF_ADD, R2, R6), 1108 BPF_ALU64_REG(BPF_ADD, R2, R7), 1109 BPF_ALU64_REG(BPF_ADD, R2, R8), 1110 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */ 1111 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1), 1112 BPF_EXIT_INSN(), 1113 BPF_ALU64_REG(BPF_ADD, R3, R0), 1114 BPF_ALU64_REG(BPF_ADD, R3, R1), 1115 BPF_ALU64_REG(BPF_ADD, R3, R2), 1116 BPF_ALU64_REG(BPF_ADD, R3, R3), 1117 BPF_ALU64_REG(BPF_ADD, R3, R4), 1118 BPF_ALU64_REG(BPF_ADD, R3, R5), 1119 BPF_ALU64_REG(BPF_ADD, R3, R6), 1120 BPF_ALU64_REG(BPF_ADD, R3, R7), 1121 BPF_ALU64_REG(BPF_ADD, R3, R8), 1122 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */ 1123 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1), 1124 BPF_EXIT_INSN(), 1125 BPF_ALU64_REG(BPF_ADD, R4, R0), 1126 BPF_ALU64_REG(BPF_ADD, R4, R1), 1127 BPF_ALU64_REG(BPF_ADD, R4, R2), 1128 BPF_ALU64_REG(BPF_ADD, R4, R3), 1129 BPF_ALU64_REG(BPF_ADD, R4, R4), 1130 BPF_ALU64_REG(BPF_ADD, R4, R5), 1131 BPF_ALU64_REG(BPF_ADD, R4, R6), 1132 BPF_ALU64_REG(BPF_ADD, R4, R7), 1133 BPF_ALU64_REG(BPF_ADD, R4, R8), 1134 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */ 1135 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1), 1136 BPF_EXIT_INSN(), 1137 BPF_ALU64_REG(BPF_ADD, R5, R0), 1138 BPF_ALU64_REG(BPF_ADD, R5, R1), 1139 BPF_ALU64_REG(BPF_ADD, R5, R2), 1140 BPF_ALU64_REG(BPF_ADD, R5, R3), 1141 BPF_ALU64_REG(BPF_ADD, R5, R4), 1142 BPF_ALU64_REG(BPF_ADD, R5, R5), 1143 BPF_ALU64_REG(BPF_ADD, R5, R6), 1144 BPF_ALU64_REG(BPF_ADD, R5, R7), 1145 BPF_ALU64_REG(BPF_ADD, R5, R8), 1146 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */ 1147 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1), 1148 BPF_EXIT_INSN(), 1149 BPF_ALU64_REG(BPF_ADD, R6, R0), 1150 BPF_ALU64_REG(BPF_ADD, R6, R1), 1151 BPF_ALU64_REG(BPF_ADD, R6, R2), 1152 BPF_ALU64_REG(BPF_ADD, R6, R3), 1153 BPF_ALU64_REG(BPF_ADD, R6, R4), 1154 BPF_ALU64_REG(BPF_ADD, R6, R5), 1155 BPF_ALU64_REG(BPF_ADD, R6, R6), 1156 BPF_ALU64_REG(BPF_ADD, R6, R7), 1157 BPF_ALU64_REG(BPF_ADD, R6, R8), 1158 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */ 1159 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1), 1160 BPF_EXIT_INSN(), 1161 BPF_ALU64_REG(BPF_ADD, R7, R0), 1162 BPF_ALU64_REG(BPF_ADD, R7, R1), 1163 BPF_ALU64_REG(BPF_ADD, R7, R2), 1164 BPF_ALU64_REG(BPF_ADD, R7, R3), 1165 BPF_ALU64_REG(BPF_ADD, R7, R4), 1166 BPF_ALU64_REG(BPF_ADD, R7, R5), 1167 BPF_ALU64_REG(BPF_ADD, R7, R6), 1168 BPF_ALU64_REG(BPF_ADD, R7, R7), 1169 BPF_ALU64_REG(BPF_ADD, R7, R8), 1170 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */ 1171 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1), 1172 BPF_EXIT_INSN(), 1173 BPF_ALU64_REG(BPF_ADD, R8, R0), 1174 BPF_ALU64_REG(BPF_ADD, R8, R1), 1175 BPF_ALU64_REG(BPF_ADD, R8, R2), 1176 BPF_ALU64_REG(BPF_ADD, R8, R3), 1177 BPF_ALU64_REG(BPF_ADD, R8, R4), 1178 BPF_ALU64_REG(BPF_ADD, R8, R5), 1179 BPF_ALU64_REG(BPF_ADD, R8, R6), 1180 BPF_ALU64_REG(BPF_ADD, R8, R7), 1181 BPF_ALU64_REG(BPF_ADD, R8, R8), 1182 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */ 1183 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1), 1184 BPF_EXIT_INSN(), 1185 BPF_ALU64_REG(BPF_ADD, R9, R0), 1186 BPF_ALU64_REG(BPF_ADD, R9, R1), 1187 BPF_ALU64_REG(BPF_ADD, R9, R2), 1188 BPF_ALU64_REG(BPF_ADD, R9, R3), 1189 BPF_ALU64_REG(BPF_ADD, R9, R4), 1190 BPF_ALU64_REG(BPF_ADD, R9, R5), 1191 BPF_ALU64_REG(BPF_ADD, R9, R6), 1192 BPF_ALU64_REG(BPF_ADD, R9, R7), 1193 BPF_ALU64_REG(BPF_ADD, R9, R8), 1194 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */ 1195 BPF_ALU64_REG(BPF_MOV, R0, R9), 1196 BPF_EXIT_INSN(), 1197 }, 1198 INTERNAL, 1199 { }, 1200 { { 0, 2957380 } } 1201 }, 1202 { 1203 "INT: ADD 32-bit", 1204 .u.insns_int = { 1205 BPF_ALU32_IMM(BPF_MOV, R0, 20), 1206 BPF_ALU32_IMM(BPF_MOV, R1, 1), 1207 BPF_ALU32_IMM(BPF_MOV, R2, 2), 1208 BPF_ALU32_IMM(BPF_MOV, R3, 3), 1209 BPF_ALU32_IMM(BPF_MOV, R4, 4), 1210 BPF_ALU32_IMM(BPF_MOV, R5, 5), 1211 BPF_ALU32_IMM(BPF_MOV, R6, 6), 1212 BPF_ALU32_IMM(BPF_MOV, R7, 7), 1213 BPF_ALU32_IMM(BPF_MOV, R8, 8), 1214 BPF_ALU32_IMM(BPF_MOV, R9, 9), 1215 BPF_ALU64_IMM(BPF_ADD, R1, 10), 1216 BPF_ALU64_IMM(BPF_ADD, R2, 10), 1217 BPF_ALU64_IMM(BPF_ADD, R3, 10), 1218 BPF_ALU64_IMM(BPF_ADD, R4, 10), 1219 BPF_ALU64_IMM(BPF_ADD, R5, 10), 1220 BPF_ALU64_IMM(BPF_ADD, R6, 10), 1221 BPF_ALU64_IMM(BPF_ADD, R7, 10), 1222 BPF_ALU64_IMM(BPF_ADD, R8, 10), 1223 BPF_ALU64_IMM(BPF_ADD, R9, 10), 1224 BPF_ALU32_REG(BPF_ADD, R0, R1), 1225 BPF_ALU32_REG(BPF_ADD, R0, R2), 1226 BPF_ALU32_REG(BPF_ADD, R0, R3), 1227 BPF_ALU32_REG(BPF_ADD, R0, R4), 1228 BPF_ALU32_REG(BPF_ADD, R0, R5), 1229 BPF_ALU32_REG(BPF_ADD, R0, R6), 1230 BPF_ALU32_REG(BPF_ADD, R0, R7), 1231 BPF_ALU32_REG(BPF_ADD, R0, R8), 1232 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */ 1233 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1), 1234 BPF_EXIT_INSN(), 1235 BPF_ALU32_REG(BPF_ADD, R1, R0), 1236 BPF_ALU32_REG(BPF_ADD, R1, R1), 1237 BPF_ALU32_REG(BPF_ADD, R1, R2), 1238 BPF_ALU32_REG(BPF_ADD, R1, R3), 1239 BPF_ALU32_REG(BPF_ADD, R1, R4), 1240 BPF_ALU32_REG(BPF_ADD, R1, R5), 1241 BPF_ALU32_REG(BPF_ADD, R1, R6), 1242 BPF_ALU32_REG(BPF_ADD, R1, R7), 1243 BPF_ALU32_REG(BPF_ADD, R1, R8), 1244 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */ 1245 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1), 1246 BPF_EXIT_INSN(), 1247 BPF_ALU32_REG(BPF_ADD, R2, R0), 1248 BPF_ALU32_REG(BPF_ADD, R2, R1), 1249 BPF_ALU32_REG(BPF_ADD, R2, R2), 1250 BPF_ALU32_REG(BPF_ADD, R2, R3), 1251 BPF_ALU32_REG(BPF_ADD, R2, R4), 1252 BPF_ALU32_REG(BPF_ADD, R2, R5), 1253 BPF_ALU32_REG(BPF_ADD, R2, R6), 1254 BPF_ALU32_REG(BPF_ADD, R2, R7), 1255 BPF_ALU32_REG(BPF_ADD, R2, R8), 1256 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */ 1257 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1), 1258 BPF_EXIT_INSN(), 1259 BPF_ALU32_REG(BPF_ADD, R3, R0), 1260 BPF_ALU32_REG(BPF_ADD, R3, R1), 1261 BPF_ALU32_REG(BPF_ADD, R3, R2), 1262 BPF_ALU32_REG(BPF_ADD, R3, R3), 1263 BPF_ALU32_REG(BPF_ADD, R3, R4), 1264 BPF_ALU32_REG(BPF_ADD, R3, R5), 1265 BPF_ALU32_REG(BPF_ADD, R3, R6), 1266 BPF_ALU32_REG(BPF_ADD, R3, R7), 1267 BPF_ALU32_REG(BPF_ADD, R3, R8), 1268 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */ 1269 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1), 1270 BPF_EXIT_INSN(), 1271 BPF_ALU32_REG(BPF_ADD, R4, R0), 1272 BPF_ALU32_REG(BPF_ADD, R4, R1), 1273 BPF_ALU32_REG(BPF_ADD, R4, R2), 1274 BPF_ALU32_REG(BPF_ADD, R4, R3), 1275 BPF_ALU32_REG(BPF_ADD, R4, R4), 1276 BPF_ALU32_REG(BPF_ADD, R4, R5), 1277 BPF_ALU32_REG(BPF_ADD, R4, R6), 1278 BPF_ALU32_REG(BPF_ADD, R4, R7), 1279 BPF_ALU32_REG(BPF_ADD, R4, R8), 1280 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */ 1281 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1), 1282 BPF_EXIT_INSN(), 1283 BPF_ALU32_REG(BPF_ADD, R5, R0), 1284 BPF_ALU32_REG(BPF_ADD, R5, R1), 1285 BPF_ALU32_REG(BPF_ADD, R5, R2), 1286 BPF_ALU32_REG(BPF_ADD, R5, R3), 1287 BPF_ALU32_REG(BPF_ADD, R5, R4), 1288 BPF_ALU32_REG(BPF_ADD, R5, R5), 1289 BPF_ALU32_REG(BPF_ADD, R5, R6), 1290 BPF_ALU32_REG(BPF_ADD, R5, R7), 1291 BPF_ALU32_REG(BPF_ADD, R5, R8), 1292 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */ 1293 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1), 1294 BPF_EXIT_INSN(), 1295 BPF_ALU32_REG(BPF_ADD, R6, R0), 1296 BPF_ALU32_REG(BPF_ADD, R6, R1), 1297 BPF_ALU32_REG(BPF_ADD, R6, R2), 1298 BPF_ALU32_REG(BPF_ADD, R6, R3), 1299 BPF_ALU32_REG(BPF_ADD, R6, R4), 1300 BPF_ALU32_REG(BPF_ADD, R6, R5), 1301 BPF_ALU32_REG(BPF_ADD, R6, R6), 1302 BPF_ALU32_REG(BPF_ADD, R6, R7), 1303 BPF_ALU32_REG(BPF_ADD, R6, R8), 1304 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */ 1305 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1), 1306 BPF_EXIT_INSN(), 1307 BPF_ALU32_REG(BPF_ADD, R7, R0), 1308 BPF_ALU32_REG(BPF_ADD, R7, R1), 1309 BPF_ALU32_REG(BPF_ADD, R7, R2), 1310 BPF_ALU32_REG(BPF_ADD, R7, R3), 1311 BPF_ALU32_REG(BPF_ADD, R7, R4), 1312 BPF_ALU32_REG(BPF_ADD, R7, R5), 1313 BPF_ALU32_REG(BPF_ADD, R7, R6), 1314 BPF_ALU32_REG(BPF_ADD, R7, R7), 1315 BPF_ALU32_REG(BPF_ADD, R7, R8), 1316 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */ 1317 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1), 1318 BPF_EXIT_INSN(), 1319 BPF_ALU32_REG(BPF_ADD, R8, R0), 1320 BPF_ALU32_REG(BPF_ADD, R8, R1), 1321 BPF_ALU32_REG(BPF_ADD, R8, R2), 1322 BPF_ALU32_REG(BPF_ADD, R8, R3), 1323 BPF_ALU32_REG(BPF_ADD, R8, R4), 1324 BPF_ALU32_REG(BPF_ADD, R8, R5), 1325 BPF_ALU32_REG(BPF_ADD, R8, R6), 1326 BPF_ALU32_REG(BPF_ADD, R8, R7), 1327 BPF_ALU32_REG(BPF_ADD, R8, R8), 1328 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */ 1329 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1), 1330 BPF_EXIT_INSN(), 1331 BPF_ALU32_REG(BPF_ADD, R9, R0), 1332 BPF_ALU32_REG(BPF_ADD, R9, R1), 1333 BPF_ALU32_REG(BPF_ADD, R9, R2), 1334 BPF_ALU32_REG(BPF_ADD, R9, R3), 1335 BPF_ALU32_REG(BPF_ADD, R9, R4), 1336 BPF_ALU32_REG(BPF_ADD, R9, R5), 1337 BPF_ALU32_REG(BPF_ADD, R9, R6), 1338 BPF_ALU32_REG(BPF_ADD, R9, R7), 1339 BPF_ALU32_REG(BPF_ADD, R9, R8), 1340 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */ 1341 BPF_ALU32_REG(BPF_MOV, R0, R9), 1342 BPF_EXIT_INSN(), 1343 }, 1344 INTERNAL, 1345 { }, 1346 { { 0, 2957380 } } 1347 }, 1348 { /* Mainly checking JIT here. */ 1349 "INT: SUB", 1350 .u.insns_int = { 1351 BPF_ALU64_IMM(BPF_MOV, R0, 0), 1352 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1353 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1354 BPF_ALU64_IMM(BPF_MOV, R3, 3), 1355 BPF_ALU64_IMM(BPF_MOV, R4, 4), 1356 BPF_ALU64_IMM(BPF_MOV, R5, 5), 1357 BPF_ALU64_IMM(BPF_MOV, R6, 6), 1358 BPF_ALU64_IMM(BPF_MOV, R7, 7), 1359 BPF_ALU64_IMM(BPF_MOV, R8, 8), 1360 BPF_ALU64_IMM(BPF_MOV, R9, 9), 1361 BPF_ALU64_REG(BPF_SUB, R0, R0), 1362 BPF_ALU64_REG(BPF_SUB, R0, R1), 1363 BPF_ALU64_REG(BPF_SUB, R0, R2), 1364 BPF_ALU64_REG(BPF_SUB, R0, R3), 1365 BPF_ALU64_REG(BPF_SUB, R0, R4), 1366 BPF_ALU64_REG(BPF_SUB, R0, R5), 1367 BPF_ALU64_REG(BPF_SUB, R0, R6), 1368 BPF_ALU64_REG(BPF_SUB, R0, R7), 1369 BPF_ALU64_REG(BPF_SUB, R0, R8), 1370 BPF_ALU64_REG(BPF_SUB, R0, R9), 1371 BPF_ALU64_IMM(BPF_SUB, R0, 10), 1372 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1), 1373 BPF_EXIT_INSN(), 1374 BPF_ALU64_REG(BPF_SUB, R1, R0), 1375 BPF_ALU64_REG(BPF_SUB, R1, R2), 1376 BPF_ALU64_REG(BPF_SUB, R1, R3), 1377 BPF_ALU64_REG(BPF_SUB, R1, R4), 1378 BPF_ALU64_REG(BPF_SUB, R1, R5), 1379 BPF_ALU64_REG(BPF_SUB, R1, R6), 1380 BPF_ALU64_REG(BPF_SUB, R1, R7), 1381 BPF_ALU64_REG(BPF_SUB, R1, R8), 1382 BPF_ALU64_REG(BPF_SUB, R1, R9), 1383 BPF_ALU64_IMM(BPF_SUB, R1, 10), 1384 BPF_ALU64_REG(BPF_SUB, R2, R0), 1385 BPF_ALU64_REG(BPF_SUB, R2, R1), 1386 BPF_ALU64_REG(BPF_SUB, R2, R3), 1387 BPF_ALU64_REG(BPF_SUB, R2, R4), 1388 BPF_ALU64_REG(BPF_SUB, R2, R5), 1389 BPF_ALU64_REG(BPF_SUB, R2, R6), 1390 BPF_ALU64_REG(BPF_SUB, R2, R7), 1391 BPF_ALU64_REG(BPF_SUB, R2, R8), 1392 BPF_ALU64_REG(BPF_SUB, R2, R9), 1393 BPF_ALU64_IMM(BPF_SUB, R2, 10), 1394 BPF_ALU64_REG(BPF_SUB, R3, R0), 1395 BPF_ALU64_REG(BPF_SUB, R3, R1), 1396 BPF_ALU64_REG(BPF_SUB, R3, R2), 1397 BPF_ALU64_REG(BPF_SUB, R3, R4), 1398 BPF_ALU64_REG(BPF_SUB, R3, R5), 1399 BPF_ALU64_REG(BPF_SUB, R3, R6), 1400 BPF_ALU64_REG(BPF_SUB, R3, R7), 1401 BPF_ALU64_REG(BPF_SUB, R3, R8), 1402 BPF_ALU64_REG(BPF_SUB, R3, R9), 1403 BPF_ALU64_IMM(BPF_SUB, R3, 10), 1404 BPF_ALU64_REG(BPF_SUB, R4, R0), 1405 BPF_ALU64_REG(BPF_SUB, R4, R1), 1406 BPF_ALU64_REG(BPF_SUB, R4, R2), 1407 BPF_ALU64_REG(BPF_SUB, R4, R3), 1408 BPF_ALU64_REG(BPF_SUB, R4, R5), 1409 BPF_ALU64_REG(BPF_SUB, R4, R6), 1410 BPF_ALU64_REG(BPF_SUB, R4, R7), 1411 BPF_ALU64_REG(BPF_SUB, R4, R8), 1412 BPF_ALU64_REG(BPF_SUB, R4, R9), 1413 BPF_ALU64_IMM(BPF_SUB, R4, 10), 1414 BPF_ALU64_REG(BPF_SUB, R5, R0), 1415 BPF_ALU64_REG(BPF_SUB, R5, R1), 1416 BPF_ALU64_REG(BPF_SUB, R5, R2), 1417 BPF_ALU64_REG(BPF_SUB, R5, R3), 1418 BPF_ALU64_REG(BPF_SUB, R5, R4), 1419 BPF_ALU64_REG(BPF_SUB, R5, R6), 1420 BPF_ALU64_REG(BPF_SUB, R5, R7), 1421 BPF_ALU64_REG(BPF_SUB, R5, R8), 1422 BPF_ALU64_REG(BPF_SUB, R5, R9), 1423 BPF_ALU64_IMM(BPF_SUB, R5, 10), 1424 BPF_ALU64_REG(BPF_SUB, R6, R0), 1425 BPF_ALU64_REG(BPF_SUB, R6, R1), 1426 BPF_ALU64_REG(BPF_SUB, R6, R2), 1427 BPF_ALU64_REG(BPF_SUB, R6, R3), 1428 BPF_ALU64_REG(BPF_SUB, R6, R4), 1429 BPF_ALU64_REG(BPF_SUB, R6, R5), 1430 BPF_ALU64_REG(BPF_SUB, R6, R7), 1431 BPF_ALU64_REG(BPF_SUB, R6, R8), 1432 BPF_ALU64_REG(BPF_SUB, R6, R9), 1433 BPF_ALU64_IMM(BPF_SUB, R6, 10), 1434 BPF_ALU64_REG(BPF_SUB, R7, R0), 1435 BPF_ALU64_REG(BPF_SUB, R7, R1), 1436 BPF_ALU64_REG(BPF_SUB, R7, R2), 1437 BPF_ALU64_REG(BPF_SUB, R7, R3), 1438 BPF_ALU64_REG(BPF_SUB, R7, R4), 1439 BPF_ALU64_REG(BPF_SUB, R7, R5), 1440 BPF_ALU64_REG(BPF_SUB, R7, R6), 1441 BPF_ALU64_REG(BPF_SUB, R7, R8), 1442 BPF_ALU64_REG(BPF_SUB, R7, R9), 1443 BPF_ALU64_IMM(BPF_SUB, R7, 10), 1444 BPF_ALU64_REG(BPF_SUB, R8, R0), 1445 BPF_ALU64_REG(BPF_SUB, R8, R1), 1446 BPF_ALU64_REG(BPF_SUB, R8, R2), 1447 BPF_ALU64_REG(BPF_SUB, R8, R3), 1448 BPF_ALU64_REG(BPF_SUB, R8, R4), 1449 BPF_ALU64_REG(BPF_SUB, R8, R5), 1450 BPF_ALU64_REG(BPF_SUB, R8, R6), 1451 BPF_ALU64_REG(BPF_SUB, R8, R7), 1452 BPF_ALU64_REG(BPF_SUB, R8, R9), 1453 BPF_ALU64_IMM(BPF_SUB, R8, 10), 1454 BPF_ALU64_REG(BPF_SUB, R9, R0), 1455 BPF_ALU64_REG(BPF_SUB, R9, R1), 1456 BPF_ALU64_REG(BPF_SUB, R9, R2), 1457 BPF_ALU64_REG(BPF_SUB, R9, R3), 1458 BPF_ALU64_REG(BPF_SUB, R9, R4), 1459 BPF_ALU64_REG(BPF_SUB, R9, R5), 1460 BPF_ALU64_REG(BPF_SUB, R9, R6), 1461 BPF_ALU64_REG(BPF_SUB, R9, R7), 1462 BPF_ALU64_REG(BPF_SUB, R9, R8), 1463 BPF_ALU64_IMM(BPF_SUB, R9, 10), 1464 BPF_ALU64_IMM(BPF_SUB, R0, 10), 1465 BPF_ALU64_IMM(BPF_NEG, R0, 0), 1466 BPF_ALU64_REG(BPF_SUB, R0, R1), 1467 BPF_ALU64_REG(BPF_SUB, R0, R2), 1468 BPF_ALU64_REG(BPF_SUB, R0, R3), 1469 BPF_ALU64_REG(BPF_SUB, R0, R4), 1470 BPF_ALU64_REG(BPF_SUB, R0, R5), 1471 BPF_ALU64_REG(BPF_SUB, R0, R6), 1472 BPF_ALU64_REG(BPF_SUB, R0, R7), 1473 BPF_ALU64_REG(BPF_SUB, R0, R8), 1474 BPF_ALU64_REG(BPF_SUB, R0, R9), 1475 BPF_EXIT_INSN(), 1476 }, 1477 INTERNAL, 1478 { }, 1479 { { 0, 11 } } 1480 }, 1481 { /* Mainly checking JIT here. */ 1482 "INT: XOR", 1483 .u.insns_int = { 1484 BPF_ALU64_REG(BPF_SUB, R0, R0), 1485 BPF_ALU64_REG(BPF_XOR, R1, R1), 1486 BPF_JMP_REG(BPF_JEQ, R0, R1, 1), 1487 BPF_EXIT_INSN(), 1488 BPF_ALU64_IMM(BPF_MOV, R0, 10), 1489 BPF_ALU64_IMM(BPF_MOV, R1, -1), 1490 BPF_ALU64_REG(BPF_SUB, R1, R1), 1491 BPF_ALU64_REG(BPF_XOR, R2, R2), 1492 BPF_JMP_REG(BPF_JEQ, R1, R2, 1), 1493 BPF_EXIT_INSN(), 1494 BPF_ALU64_REG(BPF_SUB, R2, R2), 1495 BPF_ALU64_REG(BPF_XOR, R3, R3), 1496 BPF_ALU64_IMM(BPF_MOV, R0, 10), 1497 BPF_ALU64_IMM(BPF_MOV, R1, -1), 1498 BPF_JMP_REG(BPF_JEQ, R2, R3, 1), 1499 BPF_EXIT_INSN(), 1500 BPF_ALU64_REG(BPF_SUB, R3, R3), 1501 BPF_ALU64_REG(BPF_XOR, R4, R4), 1502 BPF_ALU64_IMM(BPF_MOV, R2, 1), 1503 BPF_ALU64_IMM(BPF_MOV, R5, -1), 1504 BPF_JMP_REG(BPF_JEQ, R3, R4, 1), 1505 BPF_EXIT_INSN(), 1506 BPF_ALU64_REG(BPF_SUB, R4, R4), 1507 BPF_ALU64_REG(BPF_XOR, R5, R5), 1508 BPF_ALU64_IMM(BPF_MOV, R3, 1), 1509 BPF_ALU64_IMM(BPF_MOV, R7, -1), 1510 BPF_JMP_REG(BPF_JEQ, R5, R4, 1), 1511 BPF_EXIT_INSN(), 1512 BPF_ALU64_IMM(BPF_MOV, R5, 1), 1513 BPF_ALU64_REG(BPF_SUB, R5, R5), 1514 BPF_ALU64_REG(BPF_XOR, R6, R6), 1515 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1516 BPF_ALU64_IMM(BPF_MOV, R8, -1), 1517 BPF_JMP_REG(BPF_JEQ, R5, R6, 1), 1518 BPF_EXIT_INSN(), 1519 BPF_ALU64_REG(BPF_SUB, R6, R6), 1520 BPF_ALU64_REG(BPF_XOR, R7, R7), 1521 BPF_JMP_REG(BPF_JEQ, R7, R6, 1), 1522 BPF_EXIT_INSN(), 1523 BPF_ALU64_REG(BPF_SUB, R7, R7), 1524 BPF_ALU64_REG(BPF_XOR, R8, R8), 1525 BPF_JMP_REG(BPF_JEQ, R7, R8, 1), 1526 BPF_EXIT_INSN(), 1527 BPF_ALU64_REG(BPF_SUB, R8, R8), 1528 BPF_ALU64_REG(BPF_XOR, R9, R9), 1529 BPF_JMP_REG(BPF_JEQ, R9, R8, 1), 1530 BPF_EXIT_INSN(), 1531 BPF_ALU64_REG(BPF_SUB, R9, R9), 1532 BPF_ALU64_REG(BPF_XOR, R0, R0), 1533 BPF_JMP_REG(BPF_JEQ, R9, R0, 1), 1534 BPF_EXIT_INSN(), 1535 BPF_ALU64_REG(BPF_SUB, R1, R1), 1536 BPF_ALU64_REG(BPF_XOR, R0, R0), 1537 BPF_JMP_REG(BPF_JEQ, R9, R0, 2), 1538 BPF_ALU64_IMM(BPF_MOV, R0, 0), 1539 BPF_EXIT_INSN(), 1540 BPF_ALU64_IMM(BPF_MOV, R0, 1), 1541 BPF_EXIT_INSN(), 1542 }, 1543 INTERNAL, 1544 { }, 1545 { { 0, 1 } } 1546 }, 1547 { /* Mainly checking JIT here. */ 1548 "INT: MUL", 1549 .u.insns_int = { 1550 BPF_ALU64_IMM(BPF_MOV, R0, 11), 1551 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1552 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1553 BPF_ALU64_IMM(BPF_MOV, R3, 3), 1554 BPF_ALU64_IMM(BPF_MOV, R4, 4), 1555 BPF_ALU64_IMM(BPF_MOV, R5, 5), 1556 BPF_ALU64_IMM(BPF_MOV, R6, 6), 1557 BPF_ALU64_IMM(BPF_MOV, R7, 7), 1558 BPF_ALU64_IMM(BPF_MOV, R8, 8), 1559 BPF_ALU64_IMM(BPF_MOV, R9, 9), 1560 BPF_ALU64_REG(BPF_MUL, R0, R0), 1561 BPF_ALU64_REG(BPF_MUL, R0, R1), 1562 BPF_ALU64_REG(BPF_MUL, R0, R2), 1563 BPF_ALU64_REG(BPF_MUL, R0, R3), 1564 BPF_ALU64_REG(BPF_MUL, R0, R4), 1565 BPF_ALU64_REG(BPF_MUL, R0, R5), 1566 BPF_ALU64_REG(BPF_MUL, R0, R6), 1567 BPF_ALU64_REG(BPF_MUL, R0, R7), 1568 BPF_ALU64_REG(BPF_MUL, R0, R8), 1569 BPF_ALU64_REG(BPF_MUL, R0, R9), 1570 BPF_ALU64_IMM(BPF_MUL, R0, 10), 1571 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1), 1572 BPF_EXIT_INSN(), 1573 BPF_ALU64_REG(BPF_MUL, R1, R0), 1574 BPF_ALU64_REG(BPF_MUL, R1, R2), 1575 BPF_ALU64_REG(BPF_MUL, R1, R3), 1576 BPF_ALU64_REG(BPF_MUL, R1, R4), 1577 BPF_ALU64_REG(BPF_MUL, R1, R5), 1578 BPF_ALU64_REG(BPF_MUL, R1, R6), 1579 BPF_ALU64_REG(BPF_MUL, R1, R7), 1580 BPF_ALU64_REG(BPF_MUL, R1, R8), 1581 BPF_ALU64_REG(BPF_MUL, R1, R9), 1582 BPF_ALU64_IMM(BPF_MUL, R1, 10), 1583 BPF_ALU64_REG(BPF_MOV, R2, R1), 1584 BPF_ALU64_IMM(BPF_RSH, R2, 32), 1585 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1), 1586 BPF_EXIT_INSN(), 1587 BPF_ALU64_IMM(BPF_LSH, R1, 32), 1588 BPF_ALU64_IMM(BPF_ARSH, R1, 32), 1589 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1), 1590 BPF_EXIT_INSN(), 1591 BPF_ALU64_REG(BPF_MUL, R2, R0), 1592 BPF_ALU64_REG(BPF_MUL, R2, R1), 1593 BPF_ALU64_REG(BPF_MUL, R2, R3), 1594 BPF_ALU64_REG(BPF_MUL, R2, R4), 1595 BPF_ALU64_REG(BPF_MUL, R2, R5), 1596 BPF_ALU64_REG(BPF_MUL, R2, R6), 1597 BPF_ALU64_REG(BPF_MUL, R2, R7), 1598 BPF_ALU64_REG(BPF_MUL, R2, R8), 1599 BPF_ALU64_REG(BPF_MUL, R2, R9), 1600 BPF_ALU64_IMM(BPF_MUL, R2, 10), 1601 BPF_ALU64_IMM(BPF_RSH, R2, 32), 1602 BPF_ALU64_REG(BPF_MOV, R0, R2), 1603 BPF_EXIT_INSN(), 1604 }, 1605 INTERNAL, 1606 { }, 1607 { { 0, 0x35d97ef2 } } 1608 }, 1609 { 1610 "INT: ALU MIX", 1611 .u.insns_int = { 1612 BPF_ALU64_IMM(BPF_MOV, R0, 11), 1613 BPF_ALU64_IMM(BPF_ADD, R0, -1), 1614 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1615 BPF_ALU64_IMM(BPF_XOR, R2, 3), 1616 BPF_ALU64_REG(BPF_DIV, R0, R2), 1617 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1), 1618 BPF_EXIT_INSN(), 1619 BPF_ALU64_IMM(BPF_MOD, R0, 3), 1620 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1), 1621 BPF_EXIT_INSN(), 1622 BPF_ALU64_IMM(BPF_MOV, R0, -1), 1623 BPF_EXIT_INSN(), 1624 }, 1625 INTERNAL, 1626 { }, 1627 { { 0, -1 } } 1628 }, 1629 { 1630 "INT: shifts by register", 1631 .u.insns_int = { 1632 BPF_MOV64_IMM(R0, -1234), 1633 BPF_MOV64_IMM(R1, 1), 1634 BPF_ALU32_REG(BPF_RSH, R0, R1), 1635 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1), 1636 BPF_EXIT_INSN(), 1637 BPF_MOV64_IMM(R2, 1), 1638 BPF_ALU64_REG(BPF_LSH, R0, R2), 1639 BPF_MOV32_IMM(R4, -1234), 1640 BPF_JMP_REG(BPF_JEQ, R0, R4, 1), 1641 BPF_EXIT_INSN(), 1642 BPF_ALU64_IMM(BPF_AND, R4, 63), 1643 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */ 1644 BPF_MOV64_IMM(R3, 47), 1645 BPF_ALU64_REG(BPF_ARSH, R0, R3), 1646 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1), 1647 BPF_EXIT_INSN(), 1648 BPF_MOV64_IMM(R2, 1), 1649 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */ 1650 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1), 1651 BPF_EXIT_INSN(), 1652 BPF_MOV64_IMM(R4, 4), 1653 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */ 1654 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1), 1655 BPF_EXIT_INSN(), 1656 BPF_MOV64_IMM(R4, 5), 1657 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */ 1658 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1), 1659 BPF_EXIT_INSN(), 1660 BPF_MOV64_IMM(R0, -1), 1661 BPF_EXIT_INSN(), 1662 }, 1663 INTERNAL, 1664 { }, 1665 { { 0, -1 } } 1666 }, 1667 { 1668 "INT: DIV + ABS", 1669 .u.insns_int = { 1670 BPF_ALU64_REG(BPF_MOV, R6, R1), 1671 BPF_LD_ABS(BPF_B, 3), 1672 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1673 BPF_ALU32_REG(BPF_DIV, R0, R2), 1674 BPF_ALU64_REG(BPF_MOV, R8, R0), 1675 BPF_LD_ABS(BPF_B, 4), 1676 BPF_ALU64_REG(BPF_ADD, R8, R0), 1677 BPF_LD_IND(BPF_B, R8, -70), 1678 BPF_EXIT_INSN(), 1679 }, 1680 INTERNAL, 1681 { 10, 20, 30, 40, 50 }, 1682 { { 4, 0 }, { 5, 10 } } 1683 }, 1684 { 1685 "INT: DIV by zero", 1686 .u.insns_int = { 1687 BPF_ALU64_REG(BPF_MOV, R6, R1), 1688 BPF_ALU64_IMM(BPF_MOV, R7, 0), 1689 BPF_LD_ABS(BPF_B, 3), 1690 BPF_ALU32_REG(BPF_DIV, R0, R7), 1691 BPF_EXIT_INSN(), 1692 }, 1693 INTERNAL, 1694 { 10, 20, 30, 40, 50 }, 1695 { { 3, 0 }, { 4, 0 } } 1696 }, 1697 { 1698 "check: missing ret", 1699 .u.insns = { 1700 BPF_STMT(BPF_LD | BPF_IMM, 1), 1701 }, 1702 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1703 { }, 1704 { } 1705 }, 1706 { 1707 "check: div_k_0", 1708 .u.insns = { 1709 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0), 1710 BPF_STMT(BPF_RET | BPF_K, 0) 1711 }, 1712 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1713 { }, 1714 { } 1715 }, 1716 { 1717 "check: unknown insn", 1718 .u.insns = { 1719 /* seccomp insn, rejected in socket filter */ 1720 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0), 1721 BPF_STMT(BPF_RET | BPF_K, 0) 1722 }, 1723 CLASSIC | FLAG_EXPECTED_FAIL, 1724 { }, 1725 { } 1726 }, 1727 { 1728 "check: out of range spill/fill", 1729 .u.insns = { 1730 BPF_STMT(BPF_STX, 16), 1731 BPF_STMT(BPF_RET | BPF_K, 0) 1732 }, 1733 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1734 { }, 1735 { } 1736 }, 1737 { 1738 "JUMPS + HOLES", 1739 .u.insns = { 1740 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1741 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15), 1742 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1743 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1744 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1745 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1746 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1747 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1748 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1749 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1750 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1751 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1752 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1753 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1754 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1755 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4), 1756 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1757 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2), 1758 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1759 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15), 1760 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14), 1761 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1762 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1763 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1764 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1765 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1766 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1767 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1768 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1769 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1770 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1771 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1772 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1773 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1774 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3), 1775 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2), 1776 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1777 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15), 1778 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14), 1779 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1780 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1781 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1782 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1783 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1784 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1785 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1786 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1787 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1788 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1789 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1790 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1791 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1792 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3), 1793 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2), 1794 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1795 BPF_STMT(BPF_RET | BPF_A, 0), 1796 BPF_STMT(BPF_RET | BPF_A, 0), 1797 }, 1798 CLASSIC, 1799 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, 1800 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4, 1801 0x08, 0x00, 1802 0x45, 0x00, 0x00, 0x28, 0x00, 0x00, 1803 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */ 1804 0xc0, 0xa8, 0x33, 0x01, 1805 0xc0, 0xa8, 0x33, 0x02, 1806 0xbb, 0xb6, 1807 0xa9, 0xfa, 1808 0x00, 0x14, 0x00, 0x00, 1809 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1810 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1811 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1812 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1813 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1814 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1815 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1816 0xcc, 0xcc, 0xcc, 0xcc }, 1817 { { 88, 0x001b } } 1818 }, 1819 { 1820 "check: RET X", 1821 .u.insns = { 1822 BPF_STMT(BPF_RET | BPF_X, 0), 1823 }, 1824 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1825 { }, 1826 { }, 1827 }, 1828 { 1829 "check: LDX + RET X", 1830 .u.insns = { 1831 BPF_STMT(BPF_LDX | BPF_IMM, 42), 1832 BPF_STMT(BPF_RET | BPF_X, 0), 1833 }, 1834 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1835 { }, 1836 { }, 1837 }, 1838 { /* Mainly checking JIT here. */ 1839 "M[]: alt STX + LDX", 1840 .u.insns = { 1841 BPF_STMT(BPF_LDX | BPF_IMM, 100), 1842 BPF_STMT(BPF_STX, 0), 1843 BPF_STMT(BPF_LDX | BPF_MEM, 0), 1844 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1845 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1846 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1847 BPF_STMT(BPF_STX, 1), 1848 BPF_STMT(BPF_LDX | BPF_MEM, 1), 1849 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1850 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1851 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1852 BPF_STMT(BPF_STX, 2), 1853 BPF_STMT(BPF_LDX | BPF_MEM, 2), 1854 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1855 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1856 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1857 BPF_STMT(BPF_STX, 3), 1858 BPF_STMT(BPF_LDX | BPF_MEM, 3), 1859 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1860 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1861 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1862 BPF_STMT(BPF_STX, 4), 1863 BPF_STMT(BPF_LDX | BPF_MEM, 4), 1864 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1865 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1866 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1867 BPF_STMT(BPF_STX, 5), 1868 BPF_STMT(BPF_LDX | BPF_MEM, 5), 1869 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1870 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1871 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1872 BPF_STMT(BPF_STX, 6), 1873 BPF_STMT(BPF_LDX | BPF_MEM, 6), 1874 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1875 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1876 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1877 BPF_STMT(BPF_STX, 7), 1878 BPF_STMT(BPF_LDX | BPF_MEM, 7), 1879 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1880 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1881 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1882 BPF_STMT(BPF_STX, 8), 1883 BPF_STMT(BPF_LDX | BPF_MEM, 8), 1884 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1885 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1886 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1887 BPF_STMT(BPF_STX, 9), 1888 BPF_STMT(BPF_LDX | BPF_MEM, 9), 1889 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1890 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1891 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1892 BPF_STMT(BPF_STX, 10), 1893 BPF_STMT(BPF_LDX | BPF_MEM, 10), 1894 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1895 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1896 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1897 BPF_STMT(BPF_STX, 11), 1898 BPF_STMT(BPF_LDX | BPF_MEM, 11), 1899 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1900 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1901 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1902 BPF_STMT(BPF_STX, 12), 1903 BPF_STMT(BPF_LDX | BPF_MEM, 12), 1904 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1905 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1906 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1907 BPF_STMT(BPF_STX, 13), 1908 BPF_STMT(BPF_LDX | BPF_MEM, 13), 1909 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1910 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1911 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1912 BPF_STMT(BPF_STX, 14), 1913 BPF_STMT(BPF_LDX | BPF_MEM, 14), 1914 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1915 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1916 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1917 BPF_STMT(BPF_STX, 15), 1918 BPF_STMT(BPF_LDX | BPF_MEM, 15), 1919 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1920 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1921 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1922 BPF_STMT(BPF_RET | BPF_A, 0), 1923 }, 1924 CLASSIC | FLAG_NO_DATA, 1925 { }, 1926 { { 0, 116 } }, 1927 }, 1928 { /* Mainly checking JIT here. */ 1929 "M[]: full STX + full LDX", 1930 .u.insns = { 1931 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb), 1932 BPF_STMT(BPF_STX, 0), 1933 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae), 1934 BPF_STMT(BPF_STX, 1), 1935 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf), 1936 BPF_STMT(BPF_STX, 2), 1937 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc), 1938 BPF_STMT(BPF_STX, 3), 1939 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb), 1940 BPF_STMT(BPF_STX, 4), 1941 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda), 1942 BPF_STMT(BPF_STX, 5), 1943 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb), 1944 BPF_STMT(BPF_STX, 6), 1945 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade), 1946 BPF_STMT(BPF_STX, 7), 1947 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec), 1948 BPF_STMT(BPF_STX, 8), 1949 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc), 1950 BPF_STMT(BPF_STX, 9), 1951 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac), 1952 BPF_STMT(BPF_STX, 10), 1953 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea), 1954 BPF_STMT(BPF_STX, 11), 1955 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb), 1956 BPF_STMT(BPF_STX, 12), 1957 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf), 1958 BPF_STMT(BPF_STX, 13), 1959 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde), 1960 BPF_STMT(BPF_STX, 14), 1961 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad), 1962 BPF_STMT(BPF_STX, 15), 1963 BPF_STMT(BPF_LDX | BPF_MEM, 0), 1964 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1965 BPF_STMT(BPF_LDX | BPF_MEM, 1), 1966 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1967 BPF_STMT(BPF_LDX | BPF_MEM, 2), 1968 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1969 BPF_STMT(BPF_LDX | BPF_MEM, 3), 1970 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1971 BPF_STMT(BPF_LDX | BPF_MEM, 4), 1972 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1973 BPF_STMT(BPF_LDX | BPF_MEM, 5), 1974 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1975 BPF_STMT(BPF_LDX | BPF_MEM, 6), 1976 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1977 BPF_STMT(BPF_LDX | BPF_MEM, 7), 1978 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1979 BPF_STMT(BPF_LDX | BPF_MEM, 8), 1980 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1981 BPF_STMT(BPF_LDX | BPF_MEM, 9), 1982 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1983 BPF_STMT(BPF_LDX | BPF_MEM, 10), 1984 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1985 BPF_STMT(BPF_LDX | BPF_MEM, 11), 1986 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1987 BPF_STMT(BPF_LDX | BPF_MEM, 12), 1988 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1989 BPF_STMT(BPF_LDX | BPF_MEM, 13), 1990 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1991 BPF_STMT(BPF_LDX | BPF_MEM, 14), 1992 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1993 BPF_STMT(BPF_LDX | BPF_MEM, 15), 1994 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1995 BPF_STMT(BPF_RET | BPF_A, 0), 1996 }, 1997 CLASSIC | FLAG_NO_DATA, 1998 { }, 1999 { { 0, 0x2a5a5e5 } }, 2000 }, 2001 { 2002 "check: SKF_AD_MAX", 2003 .u.insns = { 2004 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 2005 SKF_AD_OFF + SKF_AD_MAX), 2006 BPF_STMT(BPF_RET | BPF_A, 0), 2007 }, 2008 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2009 { }, 2010 { }, 2011 }, 2012 { /* Passes checker but fails during runtime. */ 2013 "LD [SKF_AD_OFF-1]", 2014 .u.insns = { 2015 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 2016 SKF_AD_OFF - 1), 2017 BPF_STMT(BPF_RET | BPF_K, 1), 2018 }, 2019 CLASSIC, 2020 { }, 2021 { { 1, 0 } }, 2022 }, 2023 { 2024 "load 64-bit immediate", 2025 .u.insns_int = { 2026 BPF_LD_IMM64(R1, 0x567800001234LL), 2027 BPF_MOV64_REG(R2, R1), 2028 BPF_MOV64_REG(R3, R2), 2029 BPF_ALU64_IMM(BPF_RSH, R2, 32), 2030 BPF_ALU64_IMM(BPF_LSH, R3, 32), 2031 BPF_ALU64_IMM(BPF_RSH, R3, 32), 2032 BPF_ALU64_IMM(BPF_MOV, R0, 0), 2033 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1), 2034 BPF_EXIT_INSN(), 2035 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1), 2036 BPF_EXIT_INSN(), 2037 BPF_LD_IMM64(R0, 0x1ffffffffLL), 2038 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */ 2039 BPF_EXIT_INSN(), 2040 }, 2041 INTERNAL, 2042 { }, 2043 { { 0, 1 } } 2044 }, 2045 { 2046 "nmap reduced", 2047 .u.insns_int = { 2048 BPF_MOV64_REG(R6, R1), 2049 BPF_LD_ABS(BPF_H, 12), 2050 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28), 2051 BPF_LD_ABS(BPF_H, 12), 2052 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26), 2053 BPF_MOV32_IMM(R0, 18), 2054 BPF_STX_MEM(BPF_W, R10, R0, -64), 2055 BPF_LDX_MEM(BPF_W, R7, R10, -64), 2056 BPF_LD_IND(BPF_W, R7, 14), 2057 BPF_STX_MEM(BPF_W, R10, R0, -60), 2058 BPF_MOV32_IMM(R0, 280971478), 2059 BPF_STX_MEM(BPF_W, R10, R0, -56), 2060 BPF_LDX_MEM(BPF_W, R7, R10, -56), 2061 BPF_LDX_MEM(BPF_W, R0, R10, -60), 2062 BPF_ALU32_REG(BPF_SUB, R0, R7), 2063 BPF_JMP_IMM(BPF_JNE, R0, 0, 15), 2064 BPF_LD_ABS(BPF_H, 12), 2065 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13), 2066 BPF_MOV32_IMM(R0, 22), 2067 BPF_STX_MEM(BPF_W, R10, R0, -56), 2068 BPF_LDX_MEM(BPF_W, R7, R10, -56), 2069 BPF_LD_IND(BPF_H, R7, 14), 2070 BPF_STX_MEM(BPF_W, R10, R0, -52), 2071 BPF_MOV32_IMM(R0, 17366), 2072 BPF_STX_MEM(BPF_W, R10, R0, -48), 2073 BPF_LDX_MEM(BPF_W, R7, R10, -48), 2074 BPF_LDX_MEM(BPF_W, R0, R10, -52), 2075 BPF_ALU32_REG(BPF_SUB, R0, R7), 2076 BPF_JMP_IMM(BPF_JNE, R0, 0, 2), 2077 BPF_MOV32_IMM(R0, 256), 2078 BPF_EXIT_INSN(), 2079 BPF_MOV32_IMM(R0, 0), 2080 BPF_EXIT_INSN(), 2081 }, 2082 INTERNAL, 2083 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0, 2084 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2085 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6}, 2086 { { 38, 256 } } 2087 }, 2088 /* BPF_ALU | BPF_MOV | BPF_X */ 2089 { 2090 "ALU_MOV_X: dst = 2", 2091 .u.insns_int = { 2092 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2093 BPF_ALU32_REG(BPF_MOV, R0, R1), 2094 BPF_EXIT_INSN(), 2095 }, 2096 INTERNAL, 2097 { }, 2098 { { 0, 2 } }, 2099 }, 2100 { 2101 "ALU_MOV_X: dst = 4294967295", 2102 .u.insns_int = { 2103 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), 2104 BPF_ALU32_REG(BPF_MOV, R0, R1), 2105 BPF_EXIT_INSN(), 2106 }, 2107 INTERNAL, 2108 { }, 2109 { { 0, 4294967295U } }, 2110 }, 2111 { 2112 "ALU64_MOV_X: dst = 2", 2113 .u.insns_int = { 2114 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2115 BPF_ALU64_REG(BPF_MOV, R0, R1), 2116 BPF_EXIT_INSN(), 2117 }, 2118 INTERNAL, 2119 { }, 2120 { { 0, 2 } }, 2121 }, 2122 { 2123 "ALU64_MOV_X: dst = 4294967295", 2124 .u.insns_int = { 2125 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), 2126 BPF_ALU64_REG(BPF_MOV, R0, R1), 2127 BPF_EXIT_INSN(), 2128 }, 2129 INTERNAL, 2130 { }, 2131 { { 0, 4294967295U } }, 2132 }, 2133 /* BPF_ALU | BPF_MOV | BPF_K */ 2134 { 2135 "ALU_MOV_K: dst = 2", 2136 .u.insns_int = { 2137 BPF_ALU32_IMM(BPF_MOV, R0, 2), 2138 BPF_EXIT_INSN(), 2139 }, 2140 INTERNAL, 2141 { }, 2142 { { 0, 2 } }, 2143 }, 2144 { 2145 "ALU_MOV_K: dst = 4294967295", 2146 .u.insns_int = { 2147 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U), 2148 BPF_EXIT_INSN(), 2149 }, 2150 INTERNAL, 2151 { }, 2152 { { 0, 4294967295U } }, 2153 }, 2154 { 2155 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff", 2156 .u.insns_int = { 2157 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2158 BPF_LD_IMM64(R3, 0x00000000ffffffffLL), 2159 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff), 2160 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2161 BPF_MOV32_IMM(R0, 2), 2162 BPF_EXIT_INSN(), 2163 BPF_MOV32_IMM(R0, 1), 2164 BPF_EXIT_INSN(), 2165 }, 2166 INTERNAL, 2167 { }, 2168 { { 0, 0x1 } }, 2169 }, 2170 { 2171 "ALU64_MOV_K: dst = 2", 2172 .u.insns_int = { 2173 BPF_ALU64_IMM(BPF_MOV, R0, 2), 2174 BPF_EXIT_INSN(), 2175 }, 2176 INTERNAL, 2177 { }, 2178 { { 0, 2 } }, 2179 }, 2180 { 2181 "ALU64_MOV_K: dst = 2147483647", 2182 .u.insns_int = { 2183 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647), 2184 BPF_EXIT_INSN(), 2185 }, 2186 INTERNAL, 2187 { }, 2188 { { 0, 2147483647 } }, 2189 }, 2190 { 2191 "ALU64_OR_K: dst = 0x0", 2192 .u.insns_int = { 2193 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2194 BPF_LD_IMM64(R3, 0x0), 2195 BPF_ALU64_IMM(BPF_MOV, R2, 0x0), 2196 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2197 BPF_MOV32_IMM(R0, 2), 2198 BPF_EXIT_INSN(), 2199 BPF_MOV32_IMM(R0, 1), 2200 BPF_EXIT_INSN(), 2201 }, 2202 INTERNAL, 2203 { }, 2204 { { 0, 0x1 } }, 2205 }, 2206 { 2207 "ALU64_MOV_K: dst = -1", 2208 .u.insns_int = { 2209 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2210 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 2211 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff), 2212 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2213 BPF_MOV32_IMM(R0, 2), 2214 BPF_EXIT_INSN(), 2215 BPF_MOV32_IMM(R0, 1), 2216 BPF_EXIT_INSN(), 2217 }, 2218 INTERNAL, 2219 { }, 2220 { { 0, 0x1 } }, 2221 }, 2222 /* BPF_ALU | BPF_ADD | BPF_X */ 2223 { 2224 "ALU_ADD_X: 1 + 2 = 3", 2225 .u.insns_int = { 2226 BPF_LD_IMM64(R0, 1), 2227 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2228 BPF_ALU32_REG(BPF_ADD, R0, R1), 2229 BPF_EXIT_INSN(), 2230 }, 2231 INTERNAL, 2232 { }, 2233 { { 0, 3 } }, 2234 }, 2235 { 2236 "ALU_ADD_X: 1 + 4294967294 = 4294967295", 2237 .u.insns_int = { 2238 BPF_LD_IMM64(R0, 1), 2239 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2240 BPF_ALU32_REG(BPF_ADD, R0, R1), 2241 BPF_EXIT_INSN(), 2242 }, 2243 INTERNAL, 2244 { }, 2245 { { 0, 4294967295U } }, 2246 }, 2247 { 2248 "ALU64_ADD_X: 1 + 2 = 3", 2249 .u.insns_int = { 2250 BPF_LD_IMM64(R0, 1), 2251 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2252 BPF_ALU64_REG(BPF_ADD, R0, R1), 2253 BPF_EXIT_INSN(), 2254 }, 2255 INTERNAL, 2256 { }, 2257 { { 0, 3 } }, 2258 }, 2259 { 2260 "ALU64_ADD_X: 1 + 4294967294 = 4294967295", 2261 .u.insns_int = { 2262 BPF_LD_IMM64(R0, 1), 2263 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2264 BPF_ALU64_REG(BPF_ADD, R0, R1), 2265 BPF_EXIT_INSN(), 2266 }, 2267 INTERNAL, 2268 { }, 2269 { { 0, 4294967295U } }, 2270 }, 2271 /* BPF_ALU | BPF_ADD | BPF_K */ 2272 { 2273 "ALU_ADD_K: 1 + 2 = 3", 2274 .u.insns_int = { 2275 BPF_LD_IMM64(R0, 1), 2276 BPF_ALU32_IMM(BPF_ADD, R0, 2), 2277 BPF_EXIT_INSN(), 2278 }, 2279 INTERNAL, 2280 { }, 2281 { { 0, 3 } }, 2282 }, 2283 { 2284 "ALU_ADD_K: 3 + 0 = 3", 2285 .u.insns_int = { 2286 BPF_LD_IMM64(R0, 3), 2287 BPF_ALU32_IMM(BPF_ADD, R0, 0), 2288 BPF_EXIT_INSN(), 2289 }, 2290 INTERNAL, 2291 { }, 2292 { { 0, 3 } }, 2293 }, 2294 { 2295 "ALU_ADD_K: 1 + 4294967294 = 4294967295", 2296 .u.insns_int = { 2297 BPF_LD_IMM64(R0, 1), 2298 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U), 2299 BPF_EXIT_INSN(), 2300 }, 2301 INTERNAL, 2302 { }, 2303 { { 0, 4294967295U } }, 2304 }, 2305 { 2306 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff", 2307 .u.insns_int = { 2308 BPF_LD_IMM64(R2, 0x0), 2309 BPF_LD_IMM64(R3, 0x00000000ffffffff), 2310 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff), 2311 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2312 BPF_MOV32_IMM(R0, 2), 2313 BPF_EXIT_INSN(), 2314 BPF_MOV32_IMM(R0, 1), 2315 BPF_EXIT_INSN(), 2316 }, 2317 INTERNAL, 2318 { }, 2319 { { 0, 0x1 } }, 2320 }, 2321 { 2322 "ALU64_ADD_K: 1 + 2 = 3", 2323 .u.insns_int = { 2324 BPF_LD_IMM64(R0, 1), 2325 BPF_ALU64_IMM(BPF_ADD, R0, 2), 2326 BPF_EXIT_INSN(), 2327 }, 2328 INTERNAL, 2329 { }, 2330 { { 0, 3 } }, 2331 }, 2332 { 2333 "ALU64_ADD_K: 3 + 0 = 3", 2334 .u.insns_int = { 2335 BPF_LD_IMM64(R0, 3), 2336 BPF_ALU64_IMM(BPF_ADD, R0, 0), 2337 BPF_EXIT_INSN(), 2338 }, 2339 INTERNAL, 2340 { }, 2341 { { 0, 3 } }, 2342 }, 2343 { 2344 "ALU64_ADD_K: 1 + 2147483646 = 2147483647", 2345 .u.insns_int = { 2346 BPF_LD_IMM64(R0, 1), 2347 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646), 2348 BPF_EXIT_INSN(), 2349 }, 2350 INTERNAL, 2351 { }, 2352 { { 0, 2147483647 } }, 2353 }, 2354 { 2355 "ALU64_ADD_K: 2147483646 + -2147483647 = -1", 2356 .u.insns_int = { 2357 BPF_LD_IMM64(R0, 2147483646), 2358 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647), 2359 BPF_EXIT_INSN(), 2360 }, 2361 INTERNAL, 2362 { }, 2363 { { 0, -1 } }, 2364 }, 2365 { 2366 "ALU64_ADD_K: 1 + 0 = 1", 2367 .u.insns_int = { 2368 BPF_LD_IMM64(R2, 0x1), 2369 BPF_LD_IMM64(R3, 0x1), 2370 BPF_ALU64_IMM(BPF_ADD, R2, 0x0), 2371 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2372 BPF_MOV32_IMM(R0, 2), 2373 BPF_EXIT_INSN(), 2374 BPF_MOV32_IMM(R0, 1), 2375 BPF_EXIT_INSN(), 2376 }, 2377 INTERNAL, 2378 { }, 2379 { { 0, 0x1 } }, 2380 }, 2381 { 2382 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff", 2383 .u.insns_int = { 2384 BPF_LD_IMM64(R2, 0x0), 2385 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 2386 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff), 2387 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2388 BPF_MOV32_IMM(R0, 2), 2389 BPF_EXIT_INSN(), 2390 BPF_MOV32_IMM(R0, 1), 2391 BPF_EXIT_INSN(), 2392 }, 2393 INTERNAL, 2394 { }, 2395 { { 0, 0x1 } }, 2396 }, 2397 /* BPF_ALU | BPF_SUB | BPF_X */ 2398 { 2399 "ALU_SUB_X: 3 - 1 = 2", 2400 .u.insns_int = { 2401 BPF_LD_IMM64(R0, 3), 2402 BPF_ALU32_IMM(BPF_MOV, R1, 1), 2403 BPF_ALU32_REG(BPF_SUB, R0, R1), 2404 BPF_EXIT_INSN(), 2405 }, 2406 INTERNAL, 2407 { }, 2408 { { 0, 2 } }, 2409 }, 2410 { 2411 "ALU_SUB_X: 4294967295 - 4294967294 = 1", 2412 .u.insns_int = { 2413 BPF_LD_IMM64(R0, 4294967295U), 2414 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2415 BPF_ALU32_REG(BPF_SUB, R0, R1), 2416 BPF_EXIT_INSN(), 2417 }, 2418 INTERNAL, 2419 { }, 2420 { { 0, 1 } }, 2421 }, 2422 { 2423 "ALU64_SUB_X: 3 - 1 = 2", 2424 .u.insns_int = { 2425 BPF_LD_IMM64(R0, 3), 2426 BPF_ALU32_IMM(BPF_MOV, R1, 1), 2427 BPF_ALU64_REG(BPF_SUB, R0, R1), 2428 BPF_EXIT_INSN(), 2429 }, 2430 INTERNAL, 2431 { }, 2432 { { 0, 2 } }, 2433 }, 2434 { 2435 "ALU64_SUB_X: 4294967295 - 4294967294 = 1", 2436 .u.insns_int = { 2437 BPF_LD_IMM64(R0, 4294967295U), 2438 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2439 BPF_ALU64_REG(BPF_SUB, R0, R1), 2440 BPF_EXIT_INSN(), 2441 }, 2442 INTERNAL, 2443 { }, 2444 { { 0, 1 } }, 2445 }, 2446 /* BPF_ALU | BPF_SUB | BPF_K */ 2447 { 2448 "ALU_SUB_K: 3 - 1 = 2", 2449 .u.insns_int = { 2450 BPF_LD_IMM64(R0, 3), 2451 BPF_ALU32_IMM(BPF_SUB, R0, 1), 2452 BPF_EXIT_INSN(), 2453 }, 2454 INTERNAL, 2455 { }, 2456 { { 0, 2 } }, 2457 }, 2458 { 2459 "ALU_SUB_K: 3 - 0 = 3", 2460 .u.insns_int = { 2461 BPF_LD_IMM64(R0, 3), 2462 BPF_ALU32_IMM(BPF_SUB, R0, 0), 2463 BPF_EXIT_INSN(), 2464 }, 2465 INTERNAL, 2466 { }, 2467 { { 0, 3 } }, 2468 }, 2469 { 2470 "ALU_SUB_K: 4294967295 - 4294967294 = 1", 2471 .u.insns_int = { 2472 BPF_LD_IMM64(R0, 4294967295U), 2473 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U), 2474 BPF_EXIT_INSN(), 2475 }, 2476 INTERNAL, 2477 { }, 2478 { { 0, 1 } }, 2479 }, 2480 { 2481 "ALU64_SUB_K: 3 - 1 = 2", 2482 .u.insns_int = { 2483 BPF_LD_IMM64(R0, 3), 2484 BPF_ALU64_IMM(BPF_SUB, R0, 1), 2485 BPF_EXIT_INSN(), 2486 }, 2487 INTERNAL, 2488 { }, 2489 { { 0, 2 } }, 2490 }, 2491 { 2492 "ALU64_SUB_K: 3 - 0 = 3", 2493 .u.insns_int = { 2494 BPF_LD_IMM64(R0, 3), 2495 BPF_ALU64_IMM(BPF_SUB, R0, 0), 2496 BPF_EXIT_INSN(), 2497 }, 2498 INTERNAL, 2499 { }, 2500 { { 0, 3 } }, 2501 }, 2502 { 2503 "ALU64_SUB_K: 4294967294 - 4294967295 = -1", 2504 .u.insns_int = { 2505 BPF_LD_IMM64(R0, 4294967294U), 2506 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U), 2507 BPF_EXIT_INSN(), 2508 }, 2509 INTERNAL, 2510 { }, 2511 { { 0, -1 } }, 2512 }, 2513 { 2514 "ALU64_ADD_K: 2147483646 - 2147483647 = -1", 2515 .u.insns_int = { 2516 BPF_LD_IMM64(R0, 2147483646), 2517 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647), 2518 BPF_EXIT_INSN(), 2519 }, 2520 INTERNAL, 2521 { }, 2522 { { 0, -1 } }, 2523 }, 2524 /* BPF_ALU | BPF_MUL | BPF_X */ 2525 { 2526 "ALU_MUL_X: 2 * 3 = 6", 2527 .u.insns_int = { 2528 BPF_LD_IMM64(R0, 2), 2529 BPF_ALU32_IMM(BPF_MOV, R1, 3), 2530 BPF_ALU32_REG(BPF_MUL, R0, R1), 2531 BPF_EXIT_INSN(), 2532 }, 2533 INTERNAL, 2534 { }, 2535 { { 0, 6 } }, 2536 }, 2537 { 2538 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0", 2539 .u.insns_int = { 2540 BPF_LD_IMM64(R0, 2), 2541 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8), 2542 BPF_ALU32_REG(BPF_MUL, R0, R1), 2543 BPF_EXIT_INSN(), 2544 }, 2545 INTERNAL, 2546 { }, 2547 { { 0, 0xFFFFFFF0 } }, 2548 }, 2549 { 2550 "ALU_MUL_X: -1 * -1 = 1", 2551 .u.insns_int = { 2552 BPF_LD_IMM64(R0, -1), 2553 BPF_ALU32_IMM(BPF_MOV, R1, -1), 2554 BPF_ALU32_REG(BPF_MUL, R0, R1), 2555 BPF_EXIT_INSN(), 2556 }, 2557 INTERNAL, 2558 { }, 2559 { { 0, 1 } }, 2560 }, 2561 { 2562 "ALU64_MUL_X: 2 * 3 = 6", 2563 .u.insns_int = { 2564 BPF_LD_IMM64(R0, 2), 2565 BPF_ALU32_IMM(BPF_MOV, R1, 3), 2566 BPF_ALU64_REG(BPF_MUL, R0, R1), 2567 BPF_EXIT_INSN(), 2568 }, 2569 INTERNAL, 2570 { }, 2571 { { 0, 6 } }, 2572 }, 2573 { 2574 "ALU64_MUL_X: 1 * 2147483647 = 2147483647", 2575 .u.insns_int = { 2576 BPF_LD_IMM64(R0, 1), 2577 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647), 2578 BPF_ALU64_REG(BPF_MUL, R0, R1), 2579 BPF_EXIT_INSN(), 2580 }, 2581 INTERNAL, 2582 { }, 2583 { { 0, 2147483647 } }, 2584 }, 2585 /* BPF_ALU | BPF_MUL | BPF_K */ 2586 { 2587 "ALU_MUL_K: 2 * 3 = 6", 2588 .u.insns_int = { 2589 BPF_LD_IMM64(R0, 2), 2590 BPF_ALU32_IMM(BPF_MUL, R0, 3), 2591 BPF_EXIT_INSN(), 2592 }, 2593 INTERNAL, 2594 { }, 2595 { { 0, 6 } }, 2596 }, 2597 { 2598 "ALU_MUL_K: 3 * 1 = 3", 2599 .u.insns_int = { 2600 BPF_LD_IMM64(R0, 3), 2601 BPF_ALU32_IMM(BPF_MUL, R0, 1), 2602 BPF_EXIT_INSN(), 2603 }, 2604 INTERNAL, 2605 { }, 2606 { { 0, 3 } }, 2607 }, 2608 { 2609 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0", 2610 .u.insns_int = { 2611 BPF_LD_IMM64(R0, 2), 2612 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8), 2613 BPF_EXIT_INSN(), 2614 }, 2615 INTERNAL, 2616 { }, 2617 { { 0, 0xFFFFFFF0 } }, 2618 }, 2619 { 2620 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff", 2621 .u.insns_int = { 2622 BPF_LD_IMM64(R2, 0x1), 2623 BPF_LD_IMM64(R3, 0x00000000ffffffff), 2624 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff), 2625 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2626 BPF_MOV32_IMM(R0, 2), 2627 BPF_EXIT_INSN(), 2628 BPF_MOV32_IMM(R0, 1), 2629 BPF_EXIT_INSN(), 2630 }, 2631 INTERNAL, 2632 { }, 2633 { { 0, 0x1 } }, 2634 }, 2635 { 2636 "ALU64_MUL_K: 2 * 3 = 6", 2637 .u.insns_int = { 2638 BPF_LD_IMM64(R0, 2), 2639 BPF_ALU64_IMM(BPF_MUL, R0, 3), 2640 BPF_EXIT_INSN(), 2641 }, 2642 INTERNAL, 2643 { }, 2644 { { 0, 6 } }, 2645 }, 2646 { 2647 "ALU64_MUL_K: 3 * 1 = 3", 2648 .u.insns_int = { 2649 BPF_LD_IMM64(R0, 3), 2650 BPF_ALU64_IMM(BPF_MUL, R0, 1), 2651 BPF_EXIT_INSN(), 2652 }, 2653 INTERNAL, 2654 { }, 2655 { { 0, 3 } }, 2656 }, 2657 { 2658 "ALU64_MUL_K: 1 * 2147483647 = 2147483647", 2659 .u.insns_int = { 2660 BPF_LD_IMM64(R0, 1), 2661 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647), 2662 BPF_EXIT_INSN(), 2663 }, 2664 INTERNAL, 2665 { }, 2666 { { 0, 2147483647 } }, 2667 }, 2668 { 2669 "ALU64_MUL_K: 1 * -2147483647 = -2147483647", 2670 .u.insns_int = { 2671 BPF_LD_IMM64(R0, 1), 2672 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647), 2673 BPF_EXIT_INSN(), 2674 }, 2675 INTERNAL, 2676 { }, 2677 { { 0, -2147483647 } }, 2678 }, 2679 { 2680 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff", 2681 .u.insns_int = { 2682 BPF_LD_IMM64(R2, 0x1), 2683 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 2684 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff), 2685 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2686 BPF_MOV32_IMM(R0, 2), 2687 BPF_EXIT_INSN(), 2688 BPF_MOV32_IMM(R0, 1), 2689 BPF_EXIT_INSN(), 2690 }, 2691 INTERNAL, 2692 { }, 2693 { { 0, 0x1 } }, 2694 }, 2695 /* BPF_ALU | BPF_DIV | BPF_X */ 2696 { 2697 "ALU_DIV_X: 6 / 2 = 3", 2698 .u.insns_int = { 2699 BPF_LD_IMM64(R0, 6), 2700 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2701 BPF_ALU32_REG(BPF_DIV, R0, R1), 2702 BPF_EXIT_INSN(), 2703 }, 2704 INTERNAL, 2705 { }, 2706 { { 0, 3 } }, 2707 }, 2708 { 2709 "ALU_DIV_X: 4294967295 / 4294967295 = 1", 2710 .u.insns_int = { 2711 BPF_LD_IMM64(R0, 4294967295U), 2712 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), 2713 BPF_ALU32_REG(BPF_DIV, R0, R1), 2714 BPF_EXIT_INSN(), 2715 }, 2716 INTERNAL, 2717 { }, 2718 { { 0, 1 } }, 2719 }, 2720 { 2721 "ALU64_DIV_X: 6 / 2 = 3", 2722 .u.insns_int = { 2723 BPF_LD_IMM64(R0, 6), 2724 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2725 BPF_ALU64_REG(BPF_DIV, R0, R1), 2726 BPF_EXIT_INSN(), 2727 }, 2728 INTERNAL, 2729 { }, 2730 { { 0, 3 } }, 2731 }, 2732 { 2733 "ALU64_DIV_X: 2147483647 / 2147483647 = 1", 2734 .u.insns_int = { 2735 BPF_LD_IMM64(R0, 2147483647), 2736 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647), 2737 BPF_ALU64_REG(BPF_DIV, R0, R1), 2738 BPF_EXIT_INSN(), 2739 }, 2740 INTERNAL, 2741 { }, 2742 { { 0, 1 } }, 2743 }, 2744 { 2745 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001", 2746 .u.insns_int = { 2747 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 2748 BPF_LD_IMM64(R4, 0xffffffffffffffffLL), 2749 BPF_LD_IMM64(R3, 0x0000000000000001LL), 2750 BPF_ALU64_REG(BPF_DIV, R2, R4), 2751 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2752 BPF_MOV32_IMM(R0, 2), 2753 BPF_EXIT_INSN(), 2754 BPF_MOV32_IMM(R0, 1), 2755 BPF_EXIT_INSN(), 2756 }, 2757 INTERNAL, 2758 { }, 2759 { { 0, 0x1 } }, 2760 }, 2761 /* BPF_ALU | BPF_DIV | BPF_K */ 2762 { 2763 "ALU_DIV_K: 6 / 2 = 3", 2764 .u.insns_int = { 2765 BPF_LD_IMM64(R0, 6), 2766 BPF_ALU32_IMM(BPF_DIV, R0, 2), 2767 BPF_EXIT_INSN(), 2768 }, 2769 INTERNAL, 2770 { }, 2771 { { 0, 3 } }, 2772 }, 2773 { 2774 "ALU_DIV_K: 3 / 1 = 3", 2775 .u.insns_int = { 2776 BPF_LD_IMM64(R0, 3), 2777 BPF_ALU32_IMM(BPF_DIV, R0, 1), 2778 BPF_EXIT_INSN(), 2779 }, 2780 INTERNAL, 2781 { }, 2782 { { 0, 3 } }, 2783 }, 2784 { 2785 "ALU_DIV_K: 4294967295 / 4294967295 = 1", 2786 .u.insns_int = { 2787 BPF_LD_IMM64(R0, 4294967295U), 2788 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U), 2789 BPF_EXIT_INSN(), 2790 }, 2791 INTERNAL, 2792 { }, 2793 { { 0, 1 } }, 2794 }, 2795 { 2796 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1", 2797 .u.insns_int = { 2798 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 2799 BPF_LD_IMM64(R3, 0x1UL), 2800 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff), 2801 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2802 BPF_MOV32_IMM(R0, 2), 2803 BPF_EXIT_INSN(), 2804 BPF_MOV32_IMM(R0, 1), 2805 BPF_EXIT_INSN(), 2806 }, 2807 INTERNAL, 2808 { }, 2809 { { 0, 0x1 } }, 2810 }, 2811 { 2812 "ALU64_DIV_K: 6 / 2 = 3", 2813 .u.insns_int = { 2814 BPF_LD_IMM64(R0, 6), 2815 BPF_ALU64_IMM(BPF_DIV, R0, 2), 2816 BPF_EXIT_INSN(), 2817 }, 2818 INTERNAL, 2819 { }, 2820 { { 0, 3 } }, 2821 }, 2822 { 2823 "ALU64_DIV_K: 3 / 1 = 3", 2824 .u.insns_int = { 2825 BPF_LD_IMM64(R0, 3), 2826 BPF_ALU64_IMM(BPF_DIV, R0, 1), 2827 BPF_EXIT_INSN(), 2828 }, 2829 INTERNAL, 2830 { }, 2831 { { 0, 3 } }, 2832 }, 2833 { 2834 "ALU64_DIV_K: 2147483647 / 2147483647 = 1", 2835 .u.insns_int = { 2836 BPF_LD_IMM64(R0, 2147483647), 2837 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647), 2838 BPF_EXIT_INSN(), 2839 }, 2840 INTERNAL, 2841 { }, 2842 { { 0, 1 } }, 2843 }, 2844 { 2845 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001", 2846 .u.insns_int = { 2847 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 2848 BPF_LD_IMM64(R3, 0x0000000000000001LL), 2849 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff), 2850 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2851 BPF_MOV32_IMM(R0, 2), 2852 BPF_EXIT_INSN(), 2853 BPF_MOV32_IMM(R0, 1), 2854 BPF_EXIT_INSN(), 2855 }, 2856 INTERNAL, 2857 { }, 2858 { { 0, 0x1 } }, 2859 }, 2860 /* BPF_ALU | BPF_MOD | BPF_X */ 2861 { 2862 "ALU_MOD_X: 3 % 2 = 1", 2863 .u.insns_int = { 2864 BPF_LD_IMM64(R0, 3), 2865 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2866 BPF_ALU32_REG(BPF_MOD, R0, R1), 2867 BPF_EXIT_INSN(), 2868 }, 2869 INTERNAL, 2870 { }, 2871 { { 0, 1 } }, 2872 }, 2873 { 2874 "ALU_MOD_X: 4294967295 % 4294967293 = 2", 2875 .u.insns_int = { 2876 BPF_LD_IMM64(R0, 4294967295U), 2877 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U), 2878 BPF_ALU32_REG(BPF_MOD, R0, R1), 2879 BPF_EXIT_INSN(), 2880 }, 2881 INTERNAL, 2882 { }, 2883 { { 0, 2 } }, 2884 }, 2885 { 2886 "ALU64_MOD_X: 3 % 2 = 1", 2887 .u.insns_int = { 2888 BPF_LD_IMM64(R0, 3), 2889 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2890 BPF_ALU64_REG(BPF_MOD, R0, R1), 2891 BPF_EXIT_INSN(), 2892 }, 2893 INTERNAL, 2894 { }, 2895 { { 0, 1 } }, 2896 }, 2897 { 2898 "ALU64_MOD_X: 2147483647 % 2147483645 = 2", 2899 .u.insns_int = { 2900 BPF_LD_IMM64(R0, 2147483647), 2901 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645), 2902 BPF_ALU64_REG(BPF_MOD, R0, R1), 2903 BPF_EXIT_INSN(), 2904 }, 2905 INTERNAL, 2906 { }, 2907 { { 0, 2 } }, 2908 }, 2909 /* BPF_ALU | BPF_MOD | BPF_K */ 2910 { 2911 "ALU_MOD_K: 3 % 2 = 1", 2912 .u.insns_int = { 2913 BPF_LD_IMM64(R0, 3), 2914 BPF_ALU32_IMM(BPF_MOD, R0, 2), 2915 BPF_EXIT_INSN(), 2916 }, 2917 INTERNAL, 2918 { }, 2919 { { 0, 1 } }, 2920 }, 2921 { 2922 "ALU_MOD_K: 3 % 1 = 0", 2923 .u.insns_int = { 2924 BPF_LD_IMM64(R0, 3), 2925 BPF_ALU32_IMM(BPF_MOD, R0, 1), 2926 BPF_EXIT_INSN(), 2927 }, 2928 INTERNAL, 2929 { }, 2930 { { 0, 0 } }, 2931 }, 2932 { 2933 "ALU_MOD_K: 4294967295 % 4294967293 = 2", 2934 .u.insns_int = { 2935 BPF_LD_IMM64(R0, 4294967295U), 2936 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U), 2937 BPF_EXIT_INSN(), 2938 }, 2939 INTERNAL, 2940 { }, 2941 { { 0, 2 } }, 2942 }, 2943 { 2944 "ALU64_MOD_K: 3 % 2 = 1", 2945 .u.insns_int = { 2946 BPF_LD_IMM64(R0, 3), 2947 BPF_ALU64_IMM(BPF_MOD, R0, 2), 2948 BPF_EXIT_INSN(), 2949 }, 2950 INTERNAL, 2951 { }, 2952 { { 0, 1 } }, 2953 }, 2954 { 2955 "ALU64_MOD_K: 3 % 1 = 0", 2956 .u.insns_int = { 2957 BPF_LD_IMM64(R0, 3), 2958 BPF_ALU64_IMM(BPF_MOD, R0, 1), 2959 BPF_EXIT_INSN(), 2960 }, 2961 INTERNAL, 2962 { }, 2963 { { 0, 0 } }, 2964 }, 2965 { 2966 "ALU64_MOD_K: 2147483647 % 2147483645 = 2", 2967 .u.insns_int = { 2968 BPF_LD_IMM64(R0, 2147483647), 2969 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645), 2970 BPF_EXIT_INSN(), 2971 }, 2972 INTERNAL, 2973 { }, 2974 { { 0, 2 } }, 2975 }, 2976 /* BPF_ALU | BPF_AND | BPF_X */ 2977 { 2978 "ALU_AND_X: 3 & 2 = 2", 2979 .u.insns_int = { 2980 BPF_LD_IMM64(R0, 3), 2981 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2982 BPF_ALU32_REG(BPF_AND, R0, R1), 2983 BPF_EXIT_INSN(), 2984 }, 2985 INTERNAL, 2986 { }, 2987 { { 0, 2 } }, 2988 }, 2989 { 2990 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff", 2991 .u.insns_int = { 2992 BPF_LD_IMM64(R0, 0xffffffff), 2993 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 2994 BPF_ALU32_REG(BPF_AND, R0, R1), 2995 BPF_EXIT_INSN(), 2996 }, 2997 INTERNAL, 2998 { }, 2999 { { 0, 0xffffffff } }, 3000 }, 3001 { 3002 "ALU64_AND_X: 3 & 2 = 2", 3003 .u.insns_int = { 3004 BPF_LD_IMM64(R0, 3), 3005 BPF_ALU32_IMM(BPF_MOV, R1, 2), 3006 BPF_ALU64_REG(BPF_AND, R0, R1), 3007 BPF_EXIT_INSN(), 3008 }, 3009 INTERNAL, 3010 { }, 3011 { { 0, 2 } }, 3012 }, 3013 { 3014 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff", 3015 .u.insns_int = { 3016 BPF_LD_IMM64(R0, 0xffffffff), 3017 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3018 BPF_ALU64_REG(BPF_AND, R0, R1), 3019 BPF_EXIT_INSN(), 3020 }, 3021 INTERNAL, 3022 { }, 3023 { { 0, 0xffffffff } }, 3024 }, 3025 /* BPF_ALU | BPF_AND | BPF_K */ 3026 { 3027 "ALU_AND_K: 3 & 2 = 2", 3028 .u.insns_int = { 3029 BPF_LD_IMM64(R0, 3), 3030 BPF_ALU32_IMM(BPF_AND, R0, 2), 3031 BPF_EXIT_INSN(), 3032 }, 3033 INTERNAL, 3034 { }, 3035 { { 0, 2 } }, 3036 }, 3037 { 3038 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff", 3039 .u.insns_int = { 3040 BPF_LD_IMM64(R0, 0xffffffff), 3041 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff), 3042 BPF_EXIT_INSN(), 3043 }, 3044 INTERNAL, 3045 { }, 3046 { { 0, 0xffffffff } }, 3047 }, 3048 { 3049 "ALU64_AND_K: 3 & 2 = 2", 3050 .u.insns_int = { 3051 BPF_LD_IMM64(R0, 3), 3052 BPF_ALU64_IMM(BPF_AND, R0, 2), 3053 BPF_EXIT_INSN(), 3054 }, 3055 INTERNAL, 3056 { }, 3057 { { 0, 2 } }, 3058 }, 3059 { 3060 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff", 3061 .u.insns_int = { 3062 BPF_LD_IMM64(R0, 0xffffffff), 3063 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff), 3064 BPF_EXIT_INSN(), 3065 }, 3066 INTERNAL, 3067 { }, 3068 { { 0, 0xffffffff } }, 3069 }, 3070 { 3071 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000", 3072 .u.insns_int = { 3073 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3074 BPF_LD_IMM64(R3, 0x0000000000000000LL), 3075 BPF_ALU64_IMM(BPF_AND, R2, 0x0), 3076 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3077 BPF_MOV32_IMM(R0, 2), 3078 BPF_EXIT_INSN(), 3079 BPF_MOV32_IMM(R0, 1), 3080 BPF_EXIT_INSN(), 3081 }, 3082 INTERNAL, 3083 { }, 3084 { { 0, 0x1 } }, 3085 }, 3086 { 3087 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff", 3088 .u.insns_int = { 3089 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3090 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), 3091 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff), 3092 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3093 BPF_MOV32_IMM(R0, 2), 3094 BPF_EXIT_INSN(), 3095 BPF_MOV32_IMM(R0, 1), 3096 BPF_EXIT_INSN(), 3097 }, 3098 INTERNAL, 3099 { }, 3100 { { 0, 0x1 } }, 3101 }, 3102 { 3103 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff", 3104 .u.insns_int = { 3105 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 3106 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3107 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff), 3108 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3109 BPF_MOV32_IMM(R0, 2), 3110 BPF_EXIT_INSN(), 3111 BPF_MOV32_IMM(R0, 1), 3112 BPF_EXIT_INSN(), 3113 }, 3114 INTERNAL, 3115 { }, 3116 { { 0, 0x1 } }, 3117 }, 3118 /* BPF_ALU | BPF_OR | BPF_X */ 3119 { 3120 "ALU_OR_X: 1 | 2 = 3", 3121 .u.insns_int = { 3122 BPF_LD_IMM64(R0, 1), 3123 BPF_ALU32_IMM(BPF_MOV, R1, 2), 3124 BPF_ALU32_REG(BPF_OR, R0, R1), 3125 BPF_EXIT_INSN(), 3126 }, 3127 INTERNAL, 3128 { }, 3129 { { 0, 3 } }, 3130 }, 3131 { 3132 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff", 3133 .u.insns_int = { 3134 BPF_LD_IMM64(R0, 0), 3135 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3136 BPF_ALU32_REG(BPF_OR, R0, R1), 3137 BPF_EXIT_INSN(), 3138 }, 3139 INTERNAL, 3140 { }, 3141 { { 0, 0xffffffff } }, 3142 }, 3143 { 3144 "ALU64_OR_X: 1 | 2 = 3", 3145 .u.insns_int = { 3146 BPF_LD_IMM64(R0, 1), 3147 BPF_ALU32_IMM(BPF_MOV, R1, 2), 3148 BPF_ALU64_REG(BPF_OR, R0, R1), 3149 BPF_EXIT_INSN(), 3150 }, 3151 INTERNAL, 3152 { }, 3153 { { 0, 3 } }, 3154 }, 3155 { 3156 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff", 3157 .u.insns_int = { 3158 BPF_LD_IMM64(R0, 0), 3159 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3160 BPF_ALU64_REG(BPF_OR, R0, R1), 3161 BPF_EXIT_INSN(), 3162 }, 3163 INTERNAL, 3164 { }, 3165 { { 0, 0xffffffff } }, 3166 }, 3167 /* BPF_ALU | BPF_OR | BPF_K */ 3168 { 3169 "ALU_OR_K: 1 | 2 = 3", 3170 .u.insns_int = { 3171 BPF_LD_IMM64(R0, 1), 3172 BPF_ALU32_IMM(BPF_OR, R0, 2), 3173 BPF_EXIT_INSN(), 3174 }, 3175 INTERNAL, 3176 { }, 3177 { { 0, 3 } }, 3178 }, 3179 { 3180 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff", 3181 .u.insns_int = { 3182 BPF_LD_IMM64(R0, 0), 3183 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff), 3184 BPF_EXIT_INSN(), 3185 }, 3186 INTERNAL, 3187 { }, 3188 { { 0, 0xffffffff } }, 3189 }, 3190 { 3191 "ALU64_OR_K: 1 | 2 = 3", 3192 .u.insns_int = { 3193 BPF_LD_IMM64(R0, 1), 3194 BPF_ALU64_IMM(BPF_OR, R0, 2), 3195 BPF_EXIT_INSN(), 3196 }, 3197 INTERNAL, 3198 { }, 3199 { { 0, 3 } }, 3200 }, 3201 { 3202 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff", 3203 .u.insns_int = { 3204 BPF_LD_IMM64(R0, 0), 3205 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff), 3206 BPF_EXIT_INSN(), 3207 }, 3208 INTERNAL, 3209 { }, 3210 { { 0, 0xffffffff } }, 3211 }, 3212 { 3213 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000", 3214 .u.insns_int = { 3215 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3216 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), 3217 BPF_ALU64_IMM(BPF_OR, R2, 0x0), 3218 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3219 BPF_MOV32_IMM(R0, 2), 3220 BPF_EXIT_INSN(), 3221 BPF_MOV32_IMM(R0, 1), 3222 BPF_EXIT_INSN(), 3223 }, 3224 INTERNAL, 3225 { }, 3226 { { 0, 0x1 } }, 3227 }, 3228 { 3229 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff", 3230 .u.insns_int = { 3231 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3232 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3233 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff), 3234 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3235 BPF_MOV32_IMM(R0, 2), 3236 BPF_EXIT_INSN(), 3237 BPF_MOV32_IMM(R0, 1), 3238 BPF_EXIT_INSN(), 3239 }, 3240 INTERNAL, 3241 { }, 3242 { { 0, 0x1 } }, 3243 }, 3244 { 3245 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff", 3246 .u.insns_int = { 3247 BPF_LD_IMM64(R2, 0x0000000000000000LL), 3248 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3249 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff), 3250 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3251 BPF_MOV32_IMM(R0, 2), 3252 BPF_EXIT_INSN(), 3253 BPF_MOV32_IMM(R0, 1), 3254 BPF_EXIT_INSN(), 3255 }, 3256 INTERNAL, 3257 { }, 3258 { { 0, 0x1 } }, 3259 }, 3260 /* BPF_ALU | BPF_XOR | BPF_X */ 3261 { 3262 "ALU_XOR_X: 5 ^ 6 = 3", 3263 .u.insns_int = { 3264 BPF_LD_IMM64(R0, 5), 3265 BPF_ALU32_IMM(BPF_MOV, R1, 6), 3266 BPF_ALU32_REG(BPF_XOR, R0, R1), 3267 BPF_EXIT_INSN(), 3268 }, 3269 INTERNAL, 3270 { }, 3271 { { 0, 3 } }, 3272 }, 3273 { 3274 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe", 3275 .u.insns_int = { 3276 BPF_LD_IMM64(R0, 1), 3277 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3278 BPF_ALU32_REG(BPF_XOR, R0, R1), 3279 BPF_EXIT_INSN(), 3280 }, 3281 INTERNAL, 3282 { }, 3283 { { 0, 0xfffffffe } }, 3284 }, 3285 { 3286 "ALU64_XOR_X: 5 ^ 6 = 3", 3287 .u.insns_int = { 3288 BPF_LD_IMM64(R0, 5), 3289 BPF_ALU32_IMM(BPF_MOV, R1, 6), 3290 BPF_ALU64_REG(BPF_XOR, R0, R1), 3291 BPF_EXIT_INSN(), 3292 }, 3293 INTERNAL, 3294 { }, 3295 { { 0, 3 } }, 3296 }, 3297 { 3298 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe", 3299 .u.insns_int = { 3300 BPF_LD_IMM64(R0, 1), 3301 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3302 BPF_ALU64_REG(BPF_XOR, R0, R1), 3303 BPF_EXIT_INSN(), 3304 }, 3305 INTERNAL, 3306 { }, 3307 { { 0, 0xfffffffe } }, 3308 }, 3309 /* BPF_ALU | BPF_XOR | BPF_K */ 3310 { 3311 "ALU_XOR_K: 5 ^ 6 = 3", 3312 .u.insns_int = { 3313 BPF_LD_IMM64(R0, 5), 3314 BPF_ALU32_IMM(BPF_XOR, R0, 6), 3315 BPF_EXIT_INSN(), 3316 }, 3317 INTERNAL, 3318 { }, 3319 { { 0, 3 } }, 3320 }, 3321 { 3322 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe", 3323 .u.insns_int = { 3324 BPF_LD_IMM64(R0, 1), 3325 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff), 3326 BPF_EXIT_INSN(), 3327 }, 3328 INTERNAL, 3329 { }, 3330 { { 0, 0xfffffffe } }, 3331 }, 3332 { 3333 "ALU64_XOR_K: 5 ^ 6 = 3", 3334 .u.insns_int = { 3335 BPF_LD_IMM64(R0, 5), 3336 BPF_ALU64_IMM(BPF_XOR, R0, 6), 3337 BPF_EXIT_INSN(), 3338 }, 3339 INTERNAL, 3340 { }, 3341 { { 0, 3 } }, 3342 }, 3343 { 3344 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe", 3345 .u.insns_int = { 3346 BPF_LD_IMM64(R0, 1), 3347 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff), 3348 BPF_EXIT_INSN(), 3349 }, 3350 INTERNAL, 3351 { }, 3352 { { 0, 0xfffffffe } }, 3353 }, 3354 { 3355 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000", 3356 .u.insns_int = { 3357 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3358 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), 3359 BPF_ALU64_IMM(BPF_XOR, R2, 0x0), 3360 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3361 BPF_MOV32_IMM(R0, 2), 3362 BPF_EXIT_INSN(), 3363 BPF_MOV32_IMM(R0, 1), 3364 BPF_EXIT_INSN(), 3365 }, 3366 INTERNAL, 3367 { }, 3368 { { 0, 0x1 } }, 3369 }, 3370 { 3371 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff", 3372 .u.insns_int = { 3373 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3374 BPF_LD_IMM64(R3, 0xffff00000000ffffLL), 3375 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff), 3376 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3377 BPF_MOV32_IMM(R0, 2), 3378 BPF_EXIT_INSN(), 3379 BPF_MOV32_IMM(R0, 1), 3380 BPF_EXIT_INSN(), 3381 }, 3382 INTERNAL, 3383 { }, 3384 { { 0, 0x1 } }, 3385 }, 3386 { 3387 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff", 3388 .u.insns_int = { 3389 BPF_LD_IMM64(R2, 0x0000000000000000LL), 3390 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3391 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff), 3392 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3393 BPF_MOV32_IMM(R0, 2), 3394 BPF_EXIT_INSN(), 3395 BPF_MOV32_IMM(R0, 1), 3396 BPF_EXIT_INSN(), 3397 }, 3398 INTERNAL, 3399 { }, 3400 { { 0, 0x1 } }, 3401 }, 3402 /* BPF_ALU | BPF_LSH | BPF_X */ 3403 { 3404 "ALU_LSH_X: 1 << 1 = 2", 3405 .u.insns_int = { 3406 BPF_LD_IMM64(R0, 1), 3407 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3408 BPF_ALU32_REG(BPF_LSH, R0, R1), 3409 BPF_EXIT_INSN(), 3410 }, 3411 INTERNAL, 3412 { }, 3413 { { 0, 2 } }, 3414 }, 3415 { 3416 "ALU_LSH_X: 1 << 31 = 0x80000000", 3417 .u.insns_int = { 3418 BPF_LD_IMM64(R0, 1), 3419 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3420 BPF_ALU32_REG(BPF_LSH, R0, R1), 3421 BPF_EXIT_INSN(), 3422 }, 3423 INTERNAL, 3424 { }, 3425 { { 0, 0x80000000 } }, 3426 }, 3427 { 3428 "ALU64_LSH_X: 1 << 1 = 2", 3429 .u.insns_int = { 3430 BPF_LD_IMM64(R0, 1), 3431 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3432 BPF_ALU64_REG(BPF_LSH, R0, R1), 3433 BPF_EXIT_INSN(), 3434 }, 3435 INTERNAL, 3436 { }, 3437 { { 0, 2 } }, 3438 }, 3439 { 3440 "ALU64_LSH_X: 1 << 31 = 0x80000000", 3441 .u.insns_int = { 3442 BPF_LD_IMM64(R0, 1), 3443 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3444 BPF_ALU64_REG(BPF_LSH, R0, R1), 3445 BPF_EXIT_INSN(), 3446 }, 3447 INTERNAL, 3448 { }, 3449 { { 0, 0x80000000 } }, 3450 }, 3451 /* BPF_ALU | BPF_LSH | BPF_K */ 3452 { 3453 "ALU_LSH_K: 1 << 1 = 2", 3454 .u.insns_int = { 3455 BPF_LD_IMM64(R0, 1), 3456 BPF_ALU32_IMM(BPF_LSH, R0, 1), 3457 BPF_EXIT_INSN(), 3458 }, 3459 INTERNAL, 3460 { }, 3461 { { 0, 2 } }, 3462 }, 3463 { 3464 "ALU_LSH_K: 1 << 31 = 0x80000000", 3465 .u.insns_int = { 3466 BPF_LD_IMM64(R0, 1), 3467 BPF_ALU32_IMM(BPF_LSH, R0, 31), 3468 BPF_EXIT_INSN(), 3469 }, 3470 INTERNAL, 3471 { }, 3472 { { 0, 0x80000000 } }, 3473 }, 3474 { 3475 "ALU64_LSH_K: 1 << 1 = 2", 3476 .u.insns_int = { 3477 BPF_LD_IMM64(R0, 1), 3478 BPF_ALU64_IMM(BPF_LSH, R0, 1), 3479 BPF_EXIT_INSN(), 3480 }, 3481 INTERNAL, 3482 { }, 3483 { { 0, 2 } }, 3484 }, 3485 { 3486 "ALU64_LSH_K: 1 << 31 = 0x80000000", 3487 .u.insns_int = { 3488 BPF_LD_IMM64(R0, 1), 3489 BPF_ALU64_IMM(BPF_LSH, R0, 31), 3490 BPF_EXIT_INSN(), 3491 }, 3492 INTERNAL, 3493 { }, 3494 { { 0, 0x80000000 } }, 3495 }, 3496 /* BPF_ALU | BPF_RSH | BPF_X */ 3497 { 3498 "ALU_RSH_X: 2 >> 1 = 1", 3499 .u.insns_int = { 3500 BPF_LD_IMM64(R0, 2), 3501 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3502 BPF_ALU32_REG(BPF_RSH, R0, R1), 3503 BPF_EXIT_INSN(), 3504 }, 3505 INTERNAL, 3506 { }, 3507 { { 0, 1 } }, 3508 }, 3509 { 3510 "ALU_RSH_X: 0x80000000 >> 31 = 1", 3511 .u.insns_int = { 3512 BPF_LD_IMM64(R0, 0x80000000), 3513 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3514 BPF_ALU32_REG(BPF_RSH, R0, R1), 3515 BPF_EXIT_INSN(), 3516 }, 3517 INTERNAL, 3518 { }, 3519 { { 0, 1 } }, 3520 }, 3521 { 3522 "ALU64_RSH_X: 2 >> 1 = 1", 3523 .u.insns_int = { 3524 BPF_LD_IMM64(R0, 2), 3525 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3526 BPF_ALU64_REG(BPF_RSH, R0, R1), 3527 BPF_EXIT_INSN(), 3528 }, 3529 INTERNAL, 3530 { }, 3531 { { 0, 1 } }, 3532 }, 3533 { 3534 "ALU64_RSH_X: 0x80000000 >> 31 = 1", 3535 .u.insns_int = { 3536 BPF_LD_IMM64(R0, 0x80000000), 3537 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3538 BPF_ALU64_REG(BPF_RSH, R0, R1), 3539 BPF_EXIT_INSN(), 3540 }, 3541 INTERNAL, 3542 { }, 3543 { { 0, 1 } }, 3544 }, 3545 /* BPF_ALU | BPF_RSH | BPF_K */ 3546 { 3547 "ALU_RSH_K: 2 >> 1 = 1", 3548 .u.insns_int = { 3549 BPF_LD_IMM64(R0, 2), 3550 BPF_ALU32_IMM(BPF_RSH, R0, 1), 3551 BPF_EXIT_INSN(), 3552 }, 3553 INTERNAL, 3554 { }, 3555 { { 0, 1 } }, 3556 }, 3557 { 3558 "ALU_RSH_K: 0x80000000 >> 31 = 1", 3559 .u.insns_int = { 3560 BPF_LD_IMM64(R0, 0x80000000), 3561 BPF_ALU32_IMM(BPF_RSH, R0, 31), 3562 BPF_EXIT_INSN(), 3563 }, 3564 INTERNAL, 3565 { }, 3566 { { 0, 1 } }, 3567 }, 3568 { 3569 "ALU64_RSH_K: 2 >> 1 = 1", 3570 .u.insns_int = { 3571 BPF_LD_IMM64(R0, 2), 3572 BPF_ALU64_IMM(BPF_RSH, R0, 1), 3573 BPF_EXIT_INSN(), 3574 }, 3575 INTERNAL, 3576 { }, 3577 { { 0, 1 } }, 3578 }, 3579 { 3580 "ALU64_RSH_K: 0x80000000 >> 31 = 1", 3581 .u.insns_int = { 3582 BPF_LD_IMM64(R0, 0x80000000), 3583 BPF_ALU64_IMM(BPF_RSH, R0, 31), 3584 BPF_EXIT_INSN(), 3585 }, 3586 INTERNAL, 3587 { }, 3588 { { 0, 1 } }, 3589 }, 3590 /* BPF_ALU | BPF_ARSH | BPF_X */ 3591 { 3592 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff", 3593 .u.insns_int = { 3594 BPF_LD_IMM64(R0, 0xff00ff0000000000LL), 3595 BPF_ALU32_IMM(BPF_MOV, R1, 40), 3596 BPF_ALU64_REG(BPF_ARSH, R0, R1), 3597 BPF_EXIT_INSN(), 3598 }, 3599 INTERNAL, 3600 { }, 3601 { { 0, 0xffff00ff } }, 3602 }, 3603 /* BPF_ALU | BPF_ARSH | BPF_K */ 3604 { 3605 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff", 3606 .u.insns_int = { 3607 BPF_LD_IMM64(R0, 0xff00ff0000000000LL), 3608 BPF_ALU64_IMM(BPF_ARSH, R0, 40), 3609 BPF_EXIT_INSN(), 3610 }, 3611 INTERNAL, 3612 { }, 3613 { { 0, 0xffff00ff } }, 3614 }, 3615 /* BPF_ALU | BPF_NEG */ 3616 { 3617 "ALU_NEG: -(3) = -3", 3618 .u.insns_int = { 3619 BPF_ALU32_IMM(BPF_MOV, R0, 3), 3620 BPF_ALU32_IMM(BPF_NEG, R0, 0), 3621 BPF_EXIT_INSN(), 3622 }, 3623 INTERNAL, 3624 { }, 3625 { { 0, -3 } }, 3626 }, 3627 { 3628 "ALU_NEG: -(-3) = 3", 3629 .u.insns_int = { 3630 BPF_ALU32_IMM(BPF_MOV, R0, -3), 3631 BPF_ALU32_IMM(BPF_NEG, R0, 0), 3632 BPF_EXIT_INSN(), 3633 }, 3634 INTERNAL, 3635 { }, 3636 { { 0, 3 } }, 3637 }, 3638 { 3639 "ALU64_NEG: -(3) = -3", 3640 .u.insns_int = { 3641 BPF_LD_IMM64(R0, 3), 3642 BPF_ALU64_IMM(BPF_NEG, R0, 0), 3643 BPF_EXIT_INSN(), 3644 }, 3645 INTERNAL, 3646 { }, 3647 { { 0, -3 } }, 3648 }, 3649 { 3650 "ALU64_NEG: -(-3) = 3", 3651 .u.insns_int = { 3652 BPF_LD_IMM64(R0, -3), 3653 BPF_ALU64_IMM(BPF_NEG, R0, 0), 3654 BPF_EXIT_INSN(), 3655 }, 3656 INTERNAL, 3657 { }, 3658 { { 0, 3 } }, 3659 }, 3660 /* BPF_ALU | BPF_END | BPF_FROM_BE */ 3661 { 3662 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef", 3663 .u.insns_int = { 3664 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3665 BPF_ENDIAN(BPF_FROM_BE, R0, 16), 3666 BPF_EXIT_INSN(), 3667 }, 3668 INTERNAL, 3669 { }, 3670 { { 0, cpu_to_be16(0xcdef) } }, 3671 }, 3672 { 3673 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef", 3674 .u.insns_int = { 3675 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3676 BPF_ENDIAN(BPF_FROM_BE, R0, 32), 3677 BPF_ALU64_REG(BPF_MOV, R1, R0), 3678 BPF_ALU64_IMM(BPF_RSH, R1, 32), 3679 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */ 3680 BPF_EXIT_INSN(), 3681 }, 3682 INTERNAL, 3683 { }, 3684 { { 0, cpu_to_be32(0x89abcdef) } }, 3685 }, 3686 { 3687 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef", 3688 .u.insns_int = { 3689 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3690 BPF_ENDIAN(BPF_FROM_BE, R0, 64), 3691 BPF_EXIT_INSN(), 3692 }, 3693 INTERNAL, 3694 { }, 3695 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } }, 3696 }, 3697 /* BPF_ALU | BPF_END | BPF_FROM_LE */ 3698 { 3699 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd", 3700 .u.insns_int = { 3701 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3702 BPF_ENDIAN(BPF_FROM_LE, R0, 16), 3703 BPF_EXIT_INSN(), 3704 }, 3705 INTERNAL, 3706 { }, 3707 { { 0, cpu_to_le16(0xcdef) } }, 3708 }, 3709 { 3710 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89", 3711 .u.insns_int = { 3712 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3713 BPF_ENDIAN(BPF_FROM_LE, R0, 32), 3714 BPF_ALU64_REG(BPF_MOV, R1, R0), 3715 BPF_ALU64_IMM(BPF_RSH, R1, 32), 3716 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */ 3717 BPF_EXIT_INSN(), 3718 }, 3719 INTERNAL, 3720 { }, 3721 { { 0, cpu_to_le32(0x89abcdef) } }, 3722 }, 3723 { 3724 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301", 3725 .u.insns_int = { 3726 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3727 BPF_ENDIAN(BPF_FROM_LE, R0, 64), 3728 BPF_EXIT_INSN(), 3729 }, 3730 INTERNAL, 3731 { }, 3732 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } }, 3733 }, 3734 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */ 3735 { 3736 "ST_MEM_B: Store/Load byte: max negative", 3737 .u.insns_int = { 3738 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3739 BPF_ST_MEM(BPF_B, R10, -40, 0xff), 3740 BPF_LDX_MEM(BPF_B, R0, R10, -40), 3741 BPF_EXIT_INSN(), 3742 }, 3743 INTERNAL, 3744 { }, 3745 { { 0, 0xff } }, 3746 }, 3747 { 3748 "ST_MEM_B: Store/Load byte: max positive", 3749 .u.insns_int = { 3750 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3751 BPF_ST_MEM(BPF_H, R10, -40, 0x7f), 3752 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3753 BPF_EXIT_INSN(), 3754 }, 3755 INTERNAL, 3756 { }, 3757 { { 0, 0x7f } }, 3758 }, 3759 { 3760 "STX_MEM_B: Store/Load byte: max negative", 3761 .u.insns_int = { 3762 BPF_LD_IMM64(R0, 0), 3763 BPF_LD_IMM64(R1, 0xffLL), 3764 BPF_STX_MEM(BPF_B, R10, R1, -40), 3765 BPF_LDX_MEM(BPF_B, R0, R10, -40), 3766 BPF_EXIT_INSN(), 3767 }, 3768 INTERNAL, 3769 { }, 3770 { { 0, 0xff } }, 3771 }, 3772 { 3773 "ST_MEM_H: Store/Load half word: max negative", 3774 .u.insns_int = { 3775 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3776 BPF_ST_MEM(BPF_H, R10, -40, 0xffff), 3777 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3778 BPF_EXIT_INSN(), 3779 }, 3780 INTERNAL, 3781 { }, 3782 { { 0, 0xffff } }, 3783 }, 3784 { 3785 "ST_MEM_H: Store/Load half word: max positive", 3786 .u.insns_int = { 3787 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3788 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff), 3789 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3790 BPF_EXIT_INSN(), 3791 }, 3792 INTERNAL, 3793 { }, 3794 { { 0, 0x7fff } }, 3795 }, 3796 { 3797 "STX_MEM_H: Store/Load half word: max negative", 3798 .u.insns_int = { 3799 BPF_LD_IMM64(R0, 0), 3800 BPF_LD_IMM64(R1, 0xffffLL), 3801 BPF_STX_MEM(BPF_H, R10, R1, -40), 3802 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3803 BPF_EXIT_INSN(), 3804 }, 3805 INTERNAL, 3806 { }, 3807 { { 0, 0xffff } }, 3808 }, 3809 { 3810 "ST_MEM_W: Store/Load word: max negative", 3811 .u.insns_int = { 3812 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3813 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff), 3814 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3815 BPF_EXIT_INSN(), 3816 }, 3817 INTERNAL, 3818 { }, 3819 { { 0, 0xffffffff } }, 3820 }, 3821 { 3822 "ST_MEM_W: Store/Load word: max positive", 3823 .u.insns_int = { 3824 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3825 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff), 3826 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3827 BPF_EXIT_INSN(), 3828 }, 3829 INTERNAL, 3830 { }, 3831 { { 0, 0x7fffffff } }, 3832 }, 3833 { 3834 "STX_MEM_W: Store/Load word: max negative", 3835 .u.insns_int = { 3836 BPF_LD_IMM64(R0, 0), 3837 BPF_LD_IMM64(R1, 0xffffffffLL), 3838 BPF_STX_MEM(BPF_W, R10, R1, -40), 3839 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3840 BPF_EXIT_INSN(), 3841 }, 3842 INTERNAL, 3843 { }, 3844 { { 0, 0xffffffff } }, 3845 }, 3846 { 3847 "ST_MEM_DW: Store/Load double word: max negative", 3848 .u.insns_int = { 3849 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3850 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff), 3851 BPF_LDX_MEM(BPF_DW, R0, R10, -40), 3852 BPF_EXIT_INSN(), 3853 }, 3854 INTERNAL, 3855 { }, 3856 { { 0, 0xffffffff } }, 3857 }, 3858 { 3859 "ST_MEM_DW: Store/Load double word: max negative 2", 3860 .u.insns_int = { 3861 BPF_LD_IMM64(R2, 0xffff00000000ffffLL), 3862 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3863 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff), 3864 BPF_LDX_MEM(BPF_DW, R2, R10, -40), 3865 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3866 BPF_MOV32_IMM(R0, 2), 3867 BPF_EXIT_INSN(), 3868 BPF_MOV32_IMM(R0, 1), 3869 BPF_EXIT_INSN(), 3870 }, 3871 INTERNAL, 3872 { }, 3873 { { 0, 0x1 } }, 3874 }, 3875 { 3876 "ST_MEM_DW: Store/Load double word: max positive", 3877 .u.insns_int = { 3878 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3879 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff), 3880 BPF_LDX_MEM(BPF_DW, R0, R10, -40), 3881 BPF_EXIT_INSN(), 3882 }, 3883 INTERNAL, 3884 { }, 3885 { { 0, 0x7fffffff } }, 3886 }, 3887 { 3888 "STX_MEM_DW: Store/Load double word: max negative", 3889 .u.insns_int = { 3890 BPF_LD_IMM64(R0, 0), 3891 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3892 BPF_STX_MEM(BPF_W, R10, R1, -40), 3893 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3894 BPF_EXIT_INSN(), 3895 }, 3896 INTERNAL, 3897 { }, 3898 { { 0, 0xffffffff } }, 3899 }, 3900 /* BPF_STX | BPF_XADD | BPF_W/DW */ 3901 { 3902 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22", 3903 .u.insns_int = { 3904 BPF_ALU32_IMM(BPF_MOV, R0, 0x12), 3905 BPF_ST_MEM(BPF_W, R10, -40, 0x10), 3906 BPF_STX_XADD(BPF_W, R10, R0, -40), 3907 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3908 BPF_EXIT_INSN(), 3909 }, 3910 INTERNAL, 3911 { }, 3912 { { 0, 0x22 } }, 3913 }, 3914 { 3915 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22", 3916 .u.insns_int = { 3917 BPF_ALU32_IMM(BPF_MOV, R0, 0x12), 3918 BPF_ST_MEM(BPF_DW, R10, -40, 0x10), 3919 BPF_STX_XADD(BPF_DW, R10, R0, -40), 3920 BPF_LDX_MEM(BPF_DW, R0, R10, -40), 3921 BPF_EXIT_INSN(), 3922 }, 3923 INTERNAL, 3924 { }, 3925 { { 0, 0x22 } }, 3926 }, 3927 /* BPF_JMP | BPF_EXIT */ 3928 { 3929 "JMP_EXIT", 3930 .u.insns_int = { 3931 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711), 3932 BPF_EXIT_INSN(), 3933 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712), 3934 }, 3935 INTERNAL, 3936 { }, 3937 { { 0, 0x4711 } }, 3938 }, 3939 /* BPF_JMP | BPF_JA */ 3940 { 3941 "JMP_JA: Unconditional jump: if (true) return 1", 3942 .u.insns_int = { 3943 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3944 BPF_JMP_IMM(BPF_JA, 0, 0, 1), 3945 BPF_EXIT_INSN(), 3946 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3947 BPF_EXIT_INSN(), 3948 }, 3949 INTERNAL, 3950 { }, 3951 { { 0, 1 } }, 3952 }, 3953 /* BPF_JMP | BPF_JSGT | BPF_K */ 3954 { 3955 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1", 3956 .u.insns_int = { 3957 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3958 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3959 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1), 3960 BPF_EXIT_INSN(), 3961 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3962 BPF_EXIT_INSN(), 3963 }, 3964 INTERNAL, 3965 { }, 3966 { { 0, 1 } }, 3967 }, 3968 { 3969 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0", 3970 .u.insns_int = { 3971 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3972 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3973 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1), 3974 BPF_EXIT_INSN(), 3975 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3976 BPF_EXIT_INSN(), 3977 }, 3978 INTERNAL, 3979 { }, 3980 { { 0, 1 } }, 3981 }, 3982 /* BPF_JMP | BPF_JSGE | BPF_K */ 3983 { 3984 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1", 3985 .u.insns_int = { 3986 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3987 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3988 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1), 3989 BPF_EXIT_INSN(), 3990 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3991 BPF_EXIT_INSN(), 3992 }, 3993 INTERNAL, 3994 { }, 3995 { { 0, 1 } }, 3996 }, 3997 { 3998 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1", 3999 .u.insns_int = { 4000 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4001 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 4002 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1), 4003 BPF_EXIT_INSN(), 4004 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4005 BPF_EXIT_INSN(), 4006 }, 4007 INTERNAL, 4008 { }, 4009 { { 0, 1 } }, 4010 }, 4011 /* BPF_JMP | BPF_JGT | BPF_K */ 4012 { 4013 "JMP_JGT_K: if (3 > 2) return 1", 4014 .u.insns_int = { 4015 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4016 BPF_LD_IMM64(R1, 3), 4017 BPF_JMP_IMM(BPF_JGT, R1, 2, 1), 4018 BPF_EXIT_INSN(), 4019 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4020 BPF_EXIT_INSN(), 4021 }, 4022 INTERNAL, 4023 { }, 4024 { { 0, 1 } }, 4025 }, 4026 /* BPF_JMP | BPF_JGE | BPF_K */ 4027 { 4028 "JMP_JGE_K: if (3 >= 2) return 1", 4029 .u.insns_int = { 4030 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4031 BPF_LD_IMM64(R1, 3), 4032 BPF_JMP_IMM(BPF_JGE, R1, 2, 1), 4033 BPF_EXIT_INSN(), 4034 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4035 BPF_EXIT_INSN(), 4036 }, 4037 INTERNAL, 4038 { }, 4039 { { 0, 1 } }, 4040 }, 4041 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */ 4042 { 4043 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)", 4044 .u.insns_int = { 4045 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */ 4046 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */ 4047 BPF_EXIT_INSN(), 4048 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */ 4049 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */ 4050 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */ 4051 BPF_EXIT_INSN(), 4052 }, 4053 INTERNAL, 4054 { }, 4055 { { 0, 1 } }, 4056 }, 4057 { 4058 "JMP_JGE_K: if (3 >= 3) return 1", 4059 .u.insns_int = { 4060 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4061 BPF_LD_IMM64(R1, 3), 4062 BPF_JMP_IMM(BPF_JGE, R1, 3, 1), 4063 BPF_EXIT_INSN(), 4064 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4065 BPF_EXIT_INSN(), 4066 }, 4067 INTERNAL, 4068 { }, 4069 { { 0, 1 } }, 4070 }, 4071 /* BPF_JMP | BPF_JNE | BPF_K */ 4072 { 4073 "JMP_JNE_K: if (3 != 2) return 1", 4074 .u.insns_int = { 4075 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4076 BPF_LD_IMM64(R1, 3), 4077 BPF_JMP_IMM(BPF_JNE, R1, 2, 1), 4078 BPF_EXIT_INSN(), 4079 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4080 BPF_EXIT_INSN(), 4081 }, 4082 INTERNAL, 4083 { }, 4084 { { 0, 1 } }, 4085 }, 4086 /* BPF_JMP | BPF_JEQ | BPF_K */ 4087 { 4088 "JMP_JEQ_K: if (3 == 3) return 1", 4089 .u.insns_int = { 4090 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4091 BPF_LD_IMM64(R1, 3), 4092 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1), 4093 BPF_EXIT_INSN(), 4094 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4095 BPF_EXIT_INSN(), 4096 }, 4097 INTERNAL, 4098 { }, 4099 { { 0, 1 } }, 4100 }, 4101 /* BPF_JMP | BPF_JSET | BPF_K */ 4102 { 4103 "JMP_JSET_K: if (0x3 & 0x2) return 1", 4104 .u.insns_int = { 4105 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4106 BPF_LD_IMM64(R1, 3), 4107 BPF_JMP_IMM(BPF_JNE, R1, 2, 1), 4108 BPF_EXIT_INSN(), 4109 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4110 BPF_EXIT_INSN(), 4111 }, 4112 INTERNAL, 4113 { }, 4114 { { 0, 1 } }, 4115 }, 4116 { 4117 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1", 4118 .u.insns_int = { 4119 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4120 BPF_LD_IMM64(R1, 3), 4121 BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1), 4122 BPF_EXIT_INSN(), 4123 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4124 BPF_EXIT_INSN(), 4125 }, 4126 INTERNAL, 4127 { }, 4128 { { 0, 1 } }, 4129 }, 4130 /* BPF_JMP | BPF_JSGT | BPF_X */ 4131 { 4132 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1", 4133 .u.insns_int = { 4134 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4135 BPF_LD_IMM64(R1, -1), 4136 BPF_LD_IMM64(R2, -2), 4137 BPF_JMP_REG(BPF_JSGT, R1, R2, 1), 4138 BPF_EXIT_INSN(), 4139 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4140 BPF_EXIT_INSN(), 4141 }, 4142 INTERNAL, 4143 { }, 4144 { { 0, 1 } }, 4145 }, 4146 { 4147 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0", 4148 .u.insns_int = { 4149 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4150 BPF_LD_IMM64(R1, -1), 4151 BPF_LD_IMM64(R2, -1), 4152 BPF_JMP_REG(BPF_JSGT, R1, R2, 1), 4153 BPF_EXIT_INSN(), 4154 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4155 BPF_EXIT_INSN(), 4156 }, 4157 INTERNAL, 4158 { }, 4159 { { 0, 1 } }, 4160 }, 4161 /* BPF_JMP | BPF_JSGE | BPF_X */ 4162 { 4163 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1", 4164 .u.insns_int = { 4165 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4166 BPF_LD_IMM64(R1, -1), 4167 BPF_LD_IMM64(R2, -2), 4168 BPF_JMP_REG(BPF_JSGE, R1, R2, 1), 4169 BPF_EXIT_INSN(), 4170 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4171 BPF_EXIT_INSN(), 4172 }, 4173 INTERNAL, 4174 { }, 4175 { { 0, 1 } }, 4176 }, 4177 { 4178 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1", 4179 .u.insns_int = { 4180 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4181 BPF_LD_IMM64(R1, -1), 4182 BPF_LD_IMM64(R2, -1), 4183 BPF_JMP_REG(BPF_JSGE, R1, R2, 1), 4184 BPF_EXIT_INSN(), 4185 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4186 BPF_EXIT_INSN(), 4187 }, 4188 INTERNAL, 4189 { }, 4190 { { 0, 1 } }, 4191 }, 4192 /* BPF_JMP | BPF_JGT | BPF_X */ 4193 { 4194 "JMP_JGT_X: if (3 > 2) return 1", 4195 .u.insns_int = { 4196 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4197 BPF_LD_IMM64(R1, 3), 4198 BPF_LD_IMM64(R2, 2), 4199 BPF_JMP_REG(BPF_JGT, R1, R2, 1), 4200 BPF_EXIT_INSN(), 4201 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4202 BPF_EXIT_INSN(), 4203 }, 4204 INTERNAL, 4205 { }, 4206 { { 0, 1 } }, 4207 }, 4208 /* BPF_JMP | BPF_JGE | BPF_X */ 4209 { 4210 "JMP_JGE_X: if (3 >= 2) return 1", 4211 .u.insns_int = { 4212 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4213 BPF_LD_IMM64(R1, 3), 4214 BPF_LD_IMM64(R2, 2), 4215 BPF_JMP_REG(BPF_JGE, R1, R2, 1), 4216 BPF_EXIT_INSN(), 4217 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4218 BPF_EXIT_INSN(), 4219 }, 4220 INTERNAL, 4221 { }, 4222 { { 0, 1 } }, 4223 }, 4224 { 4225 "JMP_JGE_X: if (3 >= 3) return 1", 4226 .u.insns_int = { 4227 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4228 BPF_LD_IMM64(R1, 3), 4229 BPF_LD_IMM64(R2, 3), 4230 BPF_JMP_REG(BPF_JGE, R1, R2, 1), 4231 BPF_EXIT_INSN(), 4232 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4233 BPF_EXIT_INSN(), 4234 }, 4235 INTERNAL, 4236 { }, 4237 { { 0, 1 } }, 4238 }, 4239 /* BPF_JMP | BPF_JNE | BPF_X */ 4240 { 4241 "JMP_JNE_X: if (3 != 2) return 1", 4242 .u.insns_int = { 4243 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4244 BPF_LD_IMM64(R1, 3), 4245 BPF_LD_IMM64(R2, 2), 4246 BPF_JMP_REG(BPF_JNE, R1, R2, 1), 4247 BPF_EXIT_INSN(), 4248 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4249 BPF_EXIT_INSN(), 4250 }, 4251 INTERNAL, 4252 { }, 4253 { { 0, 1 } }, 4254 }, 4255 /* BPF_JMP | BPF_JEQ | BPF_X */ 4256 { 4257 "JMP_JEQ_X: if (3 == 3) return 1", 4258 .u.insns_int = { 4259 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4260 BPF_LD_IMM64(R1, 3), 4261 BPF_LD_IMM64(R2, 3), 4262 BPF_JMP_REG(BPF_JEQ, R1, R2, 1), 4263 BPF_EXIT_INSN(), 4264 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4265 BPF_EXIT_INSN(), 4266 }, 4267 INTERNAL, 4268 { }, 4269 { { 0, 1 } }, 4270 }, 4271 /* BPF_JMP | BPF_JSET | BPF_X */ 4272 { 4273 "JMP_JSET_X: if (0x3 & 0x2) return 1", 4274 .u.insns_int = { 4275 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4276 BPF_LD_IMM64(R1, 3), 4277 BPF_LD_IMM64(R2, 2), 4278 BPF_JMP_REG(BPF_JNE, R1, R2, 1), 4279 BPF_EXIT_INSN(), 4280 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4281 BPF_EXIT_INSN(), 4282 }, 4283 INTERNAL, 4284 { }, 4285 { { 0, 1 } }, 4286 }, 4287 { 4288 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1", 4289 .u.insns_int = { 4290 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4291 BPF_LD_IMM64(R1, 3), 4292 BPF_LD_IMM64(R2, 0xffffffff), 4293 BPF_JMP_REG(BPF_JNE, R1, R2, 1), 4294 BPF_EXIT_INSN(), 4295 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4296 BPF_EXIT_INSN(), 4297 }, 4298 INTERNAL, 4299 { }, 4300 { { 0, 1 } }, 4301 }, 4302 { 4303 "JMP_JA: Jump, gap, jump, ...", 4304 { }, 4305 CLASSIC | FLAG_NO_DATA, 4306 { }, 4307 { { 0, 0xababcbac } }, 4308 .fill_helper = bpf_fill_ja, 4309 }, 4310 { /* Mainly checking JIT here. */ 4311 "BPF_MAXINSNS: Maximum possible literals", 4312 { }, 4313 CLASSIC | FLAG_NO_DATA, 4314 { }, 4315 { { 0, 0xffffffff } }, 4316 .fill_helper = bpf_fill_maxinsns1, 4317 }, 4318 { /* Mainly checking JIT here. */ 4319 "BPF_MAXINSNS: Single literal", 4320 { }, 4321 CLASSIC | FLAG_NO_DATA, 4322 { }, 4323 { { 0, 0xfefefefe } }, 4324 .fill_helper = bpf_fill_maxinsns2, 4325 }, 4326 { /* Mainly checking JIT here. */ 4327 "BPF_MAXINSNS: Run/add until end", 4328 { }, 4329 CLASSIC | FLAG_NO_DATA, 4330 { }, 4331 { { 0, 0x947bf368 } }, 4332 .fill_helper = bpf_fill_maxinsns3, 4333 }, 4334 { 4335 "BPF_MAXINSNS: Too many instructions", 4336 { }, 4337 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 4338 { }, 4339 { }, 4340 .fill_helper = bpf_fill_maxinsns4, 4341 }, 4342 { /* Mainly checking JIT here. */ 4343 "BPF_MAXINSNS: Very long jump", 4344 { }, 4345 CLASSIC | FLAG_NO_DATA, 4346 { }, 4347 { { 0, 0xabababab } }, 4348 .fill_helper = bpf_fill_maxinsns5, 4349 }, 4350 { /* Mainly checking JIT here. */ 4351 "BPF_MAXINSNS: Ctx heavy transformations", 4352 { }, 4353 CLASSIC, 4354 { }, 4355 { 4356 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, 4357 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) } 4358 }, 4359 .fill_helper = bpf_fill_maxinsns6, 4360 }, 4361 { /* Mainly checking JIT here. */ 4362 "BPF_MAXINSNS: Call heavy transformations", 4363 { }, 4364 CLASSIC | FLAG_NO_DATA, 4365 { }, 4366 { { 1, 0 }, { 10, 0 } }, 4367 .fill_helper = bpf_fill_maxinsns7, 4368 }, 4369 { /* Mainly checking JIT here. */ 4370 "BPF_MAXINSNS: Jump heavy test", 4371 { }, 4372 CLASSIC | FLAG_NO_DATA, 4373 { }, 4374 { { 0, 0xffffffff } }, 4375 .fill_helper = bpf_fill_maxinsns8, 4376 }, 4377 { /* Mainly checking JIT here. */ 4378 "BPF_MAXINSNS: Very long jump backwards", 4379 { }, 4380 INTERNAL | FLAG_NO_DATA, 4381 { }, 4382 { { 0, 0xcbababab } }, 4383 .fill_helper = bpf_fill_maxinsns9, 4384 }, 4385 { /* Mainly checking JIT here. */ 4386 "BPF_MAXINSNS: Edge hopping nuthouse", 4387 { }, 4388 INTERNAL | FLAG_NO_DATA, 4389 { }, 4390 { { 0, 0xabababac } }, 4391 .fill_helper = bpf_fill_maxinsns10, 4392 }, 4393 { 4394 "BPF_MAXINSNS: Jump, gap, jump, ...", 4395 { }, 4396 CLASSIC | FLAG_NO_DATA, 4397 { }, 4398 { { 0, 0xababcbac } }, 4399 .fill_helper = bpf_fill_maxinsns11, 4400 }, 4401 }; 4402 4403 static struct net_device dev; 4404 4405 static struct sk_buff *populate_skb(char *buf, int size) 4406 { 4407 struct sk_buff *skb; 4408 4409 if (size >= MAX_DATA) 4410 return NULL; 4411 4412 skb = alloc_skb(MAX_DATA, GFP_KERNEL); 4413 if (!skb) 4414 return NULL; 4415 4416 memcpy(__skb_put(skb, size), buf, size); 4417 4418 /* Initialize a fake skb with test pattern. */ 4419 skb_reset_mac_header(skb); 4420 skb->protocol = htons(ETH_P_IP); 4421 skb->pkt_type = SKB_TYPE; 4422 skb->mark = SKB_MARK; 4423 skb->hash = SKB_HASH; 4424 skb->queue_mapping = SKB_QUEUE_MAP; 4425 skb->vlan_tci = SKB_VLAN_TCI; 4426 skb->dev = &dev; 4427 skb->dev->ifindex = SKB_DEV_IFINDEX; 4428 skb->dev->type = SKB_DEV_TYPE; 4429 skb_set_network_header(skb, min(size, ETH_HLEN)); 4430 4431 return skb; 4432 } 4433 4434 static void *generate_test_data(struct bpf_test *test, int sub) 4435 { 4436 if (test->aux & FLAG_NO_DATA) 4437 return NULL; 4438 4439 /* Test case expects an skb, so populate one. Various 4440 * subtests generate skbs of different sizes based on 4441 * the same data. 4442 */ 4443 return populate_skb(test->data, test->test[sub].data_size); 4444 } 4445 4446 static void release_test_data(const struct bpf_test *test, void *data) 4447 { 4448 if (test->aux & FLAG_NO_DATA) 4449 return; 4450 4451 kfree_skb(data); 4452 } 4453 4454 static int filter_length(int which) 4455 { 4456 struct sock_filter *fp; 4457 int len; 4458 4459 if (tests[which].fill_helper) 4460 return tests[which].u.ptr.len; 4461 4462 fp = tests[which].u.insns; 4463 for (len = MAX_INSNS - 1; len > 0; --len) 4464 if (fp[len].code != 0 || fp[len].k != 0) 4465 break; 4466 4467 return len + 1; 4468 } 4469 4470 static void *filter_pointer(int which) 4471 { 4472 if (tests[which].fill_helper) 4473 return tests[which].u.ptr.insns; 4474 else 4475 return tests[which].u.insns; 4476 } 4477 4478 static struct bpf_prog *generate_filter(int which, int *err) 4479 { 4480 __u8 test_type = tests[which].aux & TEST_TYPE_MASK; 4481 unsigned int flen = filter_length(which); 4482 void *fptr = filter_pointer(which); 4483 struct sock_fprog_kern fprog; 4484 struct bpf_prog *fp; 4485 4486 switch (test_type) { 4487 case CLASSIC: 4488 fprog.filter = fptr; 4489 fprog.len = flen; 4490 4491 *err = bpf_prog_create(&fp, &fprog); 4492 if (tests[which].aux & FLAG_EXPECTED_FAIL) { 4493 if (*err == -EINVAL) { 4494 pr_cont("PASS\n"); 4495 /* Verifier rejected filter as expected. */ 4496 *err = 0; 4497 return NULL; 4498 } else { 4499 pr_cont("UNEXPECTED_PASS\n"); 4500 /* Verifier didn't reject the test that's 4501 * bad enough, just return! 4502 */ 4503 *err = -EINVAL; 4504 return NULL; 4505 } 4506 } 4507 /* We don't expect to fail. */ 4508 if (*err) { 4509 pr_cont("FAIL to attach err=%d len=%d\n", 4510 *err, fprog.len); 4511 return NULL; 4512 } 4513 break; 4514 4515 case INTERNAL: 4516 fp = bpf_prog_alloc(bpf_prog_size(flen), 0); 4517 if (fp == NULL) { 4518 pr_cont("UNEXPECTED_FAIL no memory left\n"); 4519 *err = -ENOMEM; 4520 return NULL; 4521 } 4522 4523 fp->len = flen; 4524 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn)); 4525 4526 bpf_prog_select_runtime(fp); 4527 break; 4528 } 4529 4530 *err = 0; 4531 return fp; 4532 } 4533 4534 static void release_filter(struct bpf_prog *fp, int which) 4535 { 4536 __u8 test_type = tests[which].aux & TEST_TYPE_MASK; 4537 4538 switch (test_type) { 4539 case CLASSIC: 4540 bpf_prog_destroy(fp); 4541 break; 4542 case INTERNAL: 4543 bpf_prog_free(fp); 4544 break; 4545 } 4546 } 4547 4548 static int __run_one(const struct bpf_prog *fp, const void *data, 4549 int runs, u64 *duration) 4550 { 4551 u64 start, finish; 4552 int ret = 0, i; 4553 4554 start = ktime_to_us(ktime_get()); 4555 4556 for (i = 0; i < runs; i++) 4557 ret = BPF_PROG_RUN(fp, data); 4558 4559 finish = ktime_to_us(ktime_get()); 4560 4561 *duration = (finish - start) * 1000ULL; 4562 do_div(*duration, runs); 4563 4564 return ret; 4565 } 4566 4567 static int run_one(const struct bpf_prog *fp, struct bpf_test *test) 4568 { 4569 int err_cnt = 0, i, runs = MAX_TESTRUNS; 4570 4571 for (i = 0; i < MAX_SUBTESTS; i++) { 4572 void *data; 4573 u64 duration; 4574 u32 ret; 4575 4576 if (test->test[i].data_size == 0 && 4577 test->test[i].result == 0) 4578 break; 4579 4580 data = generate_test_data(test, i); 4581 ret = __run_one(fp, data, runs, &duration); 4582 release_test_data(test, data); 4583 4584 if (ret == test->test[i].result) { 4585 pr_cont("%lld ", duration); 4586 } else { 4587 pr_cont("ret %d != %d ", ret, 4588 test->test[i].result); 4589 err_cnt++; 4590 } 4591 } 4592 4593 return err_cnt; 4594 } 4595 4596 static __init int prepare_bpf_tests(void) 4597 { 4598 int i; 4599 4600 for (i = 0; i < ARRAY_SIZE(tests); i++) { 4601 if (tests[i].fill_helper && 4602 tests[i].fill_helper(&tests[i]) < 0) 4603 return -ENOMEM; 4604 } 4605 4606 return 0; 4607 } 4608 4609 static __init void destroy_bpf_tests(void) 4610 { 4611 int i; 4612 4613 for (i = 0; i < ARRAY_SIZE(tests); i++) { 4614 if (tests[i].fill_helper) 4615 kfree(tests[i].u.ptr.insns); 4616 } 4617 } 4618 4619 static __init int test_bpf(void) 4620 { 4621 int i, err_cnt = 0, pass_cnt = 0; 4622 int jit_cnt = 0, run_cnt = 0; 4623 4624 for (i = 0; i < ARRAY_SIZE(tests); i++) { 4625 struct bpf_prog *fp; 4626 int err; 4627 4628 pr_info("#%d %s ", i, tests[i].descr); 4629 4630 fp = generate_filter(i, &err); 4631 if (fp == NULL) { 4632 if (err == 0) { 4633 pass_cnt++; 4634 continue; 4635 } 4636 4637 return err; 4638 } 4639 4640 pr_cont("jited:%u ", fp->jited); 4641 4642 run_cnt++; 4643 if (fp->jited) 4644 jit_cnt++; 4645 4646 err = run_one(fp, &tests[i]); 4647 release_filter(fp, i); 4648 4649 if (err) { 4650 pr_cont("FAIL (%d times)\n", err); 4651 err_cnt++; 4652 } else { 4653 pr_cont("PASS\n"); 4654 pass_cnt++; 4655 } 4656 } 4657 4658 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n", 4659 pass_cnt, err_cnt, jit_cnt, run_cnt); 4660 4661 return err_cnt ? -EINVAL : 0; 4662 } 4663 4664 static int __init test_bpf_init(void) 4665 { 4666 int ret; 4667 4668 ret = prepare_bpf_tests(); 4669 if (ret < 0) 4670 return ret; 4671 4672 ret = test_bpf(); 4673 4674 destroy_bpf_tests(); 4675 return ret; 4676 } 4677 4678 static void __exit test_bpf_exit(void) 4679 { 4680 } 4681 4682 module_init(test_bpf_init); 4683 module_exit(test_bpf_exit); 4684 4685 MODULE_LICENSE("GPL"); 4686