Thomas Gleixner | 5b497af | 2019-05-29 07:18:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Testsuite for BPF interpreter and BPF JIT compiler |
| 4 | * |
| 5 | * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/filter.h> |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 13 | #include <linux/bpf.h> |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 14 | #include <linux/skbuff.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/if_vlan.h> |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 17 | #include <linux/random.h> |
Nicolas Schichan | bac142a | 2015-08-04 15:19:08 +0200 | [diff] [blame] | 18 | #include <linux/highmem.h> |
Eric Dumazet | d40bc96 | 2018-02-26 10:52:46 -0800 | [diff] [blame] | 19 | #include <linux/sched.h> |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 20 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 21 | /* General test specific settings */ |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 22 | #define MAX_SUBTESTS 3 |
Eric Dumazet | 9960d76 | 2018-02-28 08:39:20 -0800 | [diff] [blame] | 23 | #define MAX_TESTRUNS 1000 |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 24 | #define MAX_DATA 128 |
| 25 | #define MAX_INSNS 512 |
| 26 | #define MAX_K 0xffffFFFF |
| 27 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 28 | /* Few constants used to init test 'skb' */ |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 29 | #define SKB_TYPE 3 |
| 30 | #define SKB_MARK 0x1234aaaa |
| 31 | #define SKB_HASH 0x1234aaab |
| 32 | #define SKB_QUEUE_MAP 123 |
| 33 | #define SKB_VLAN_TCI 0xffff |
Michał Mirosław | 0c4b2d3 | 2018-11-10 19:58:36 +0100 | [diff] [blame] | 34 | #define SKB_VLAN_PRESENT 1 |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 35 | #define SKB_DEV_IFINDEX 577 |
| 36 | #define SKB_DEV_TYPE 588 |
| 37 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 38 | /* Redefine REGs to make tests less verbose */ |
| 39 | #define R0 BPF_REG_0 |
| 40 | #define R1 BPF_REG_1 |
| 41 | #define R2 BPF_REG_2 |
| 42 | #define R3 BPF_REG_3 |
| 43 | #define R4 BPF_REG_4 |
| 44 | #define R5 BPF_REG_5 |
| 45 | #define R6 BPF_REG_6 |
| 46 | #define R7 BPF_REG_7 |
| 47 | #define R8 BPF_REG_8 |
| 48 | #define R9 BPF_REG_9 |
| 49 | #define R10 BPF_REG_10 |
| 50 | |
| 51 | /* Flags that can be passed to test cases */ |
| 52 | #define FLAG_NO_DATA BIT(0) |
| 53 | #define FLAG_EXPECTED_FAIL BIT(1) |
Nicolas Schichan | bac142a | 2015-08-04 15:19:08 +0200 | [diff] [blame] | 54 | #define FLAG_SKB_FRAG BIT(2) |
Johan Almbladh | 27cc6da | 2021-09-14 11:18:36 +0200 | [diff] [blame] | 55 | #define FLAG_VERIFIER_ZEXT BIT(3) |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 56 | |
| 57 | enum { |
| 58 | CLASSIC = BIT(6), /* Old BPF instructions only. */ |
| 59 | INTERNAL = BIT(7), /* Extended instruction set. */ |
| 60 | }; |
| 61 | |
| 62 | #define TEST_TYPE_MASK (CLASSIC | INTERNAL) |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 63 | |
| 64 | struct bpf_test { |
| 65 | const char *descr; |
| 66 | union { |
| 67 | struct sock_filter insns[MAX_INSNS]; |
Alexei Starovoitov | 2695fb5 | 2014-07-24 16:38:21 -0700 | [diff] [blame] | 68 | struct bpf_insn insns_int[MAX_INSNS]; |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 69 | struct { |
| 70 | void *insns; |
| 71 | unsigned int len; |
| 72 | } ptr; |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 73 | } u; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 74 | __u8 aux; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 75 | __u8 data[MAX_DATA]; |
| 76 | struct { |
| 77 | int data_size; |
| 78 | __u32 result; |
| 79 | } test[MAX_SUBTESTS]; |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 80 | int (*fill_helper)(struct bpf_test *self); |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 81 | int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */ |
Nicolas Schichan | bac142a | 2015-08-04 15:19:08 +0200 | [diff] [blame] | 82 | __u8 frag_data[MAX_DATA]; |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 83 | int stack_depth; /* for eBPF only, since tests don't call verifier */ |
Johan Almbladh | c2a228d | 2021-09-14 11:18:29 +0200 | [diff] [blame] | 84 | int nr_testruns; /* Custom run count, defaults to MAX_TESTRUNS if 0 */ |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 87 | /* Large test cases need separate allocation and fill handler. */ |
| 88 | |
| 89 | static int bpf_fill_maxinsns1(struct bpf_test *self) |
| 90 | { |
| 91 | unsigned int len = BPF_MAXINSNS; |
| 92 | struct sock_filter *insn; |
| 93 | __u32 k = ~0; |
| 94 | int i; |
| 95 | |
| 96 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 97 | if (!insn) |
| 98 | return -ENOMEM; |
| 99 | |
| 100 | for (i = 0; i < len; i++, k--) |
| 101 | insn[i] = __BPF_STMT(BPF_RET | BPF_K, k); |
| 102 | |
| 103 | self->u.ptr.insns = insn; |
| 104 | self->u.ptr.len = len; |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int bpf_fill_maxinsns2(struct bpf_test *self) |
| 110 | { |
| 111 | unsigned int len = BPF_MAXINSNS; |
| 112 | struct sock_filter *insn; |
| 113 | int i; |
| 114 | |
| 115 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 116 | if (!insn) |
| 117 | return -ENOMEM; |
| 118 | |
| 119 | for (i = 0; i < len; i++) |
| 120 | insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe); |
| 121 | |
| 122 | self->u.ptr.insns = insn; |
| 123 | self->u.ptr.len = len; |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int bpf_fill_maxinsns3(struct bpf_test *self) |
| 129 | { |
| 130 | unsigned int len = BPF_MAXINSNS; |
| 131 | struct sock_filter *insn; |
| 132 | struct rnd_state rnd; |
| 133 | int i; |
| 134 | |
| 135 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 136 | if (!insn) |
| 137 | return -ENOMEM; |
| 138 | |
| 139 | prandom_seed_state(&rnd, 3141592653589793238ULL); |
| 140 | |
| 141 | for (i = 0; i < len - 1; i++) { |
| 142 | __u32 k = prandom_u32_state(&rnd); |
| 143 | |
| 144 | insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k); |
| 145 | } |
| 146 | |
| 147 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); |
| 148 | |
| 149 | self->u.ptr.insns = insn; |
| 150 | self->u.ptr.len = len; |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int bpf_fill_maxinsns4(struct bpf_test *self) |
| 156 | { |
| 157 | unsigned int len = BPF_MAXINSNS + 1; |
| 158 | struct sock_filter *insn; |
| 159 | int i; |
| 160 | |
| 161 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 162 | if (!insn) |
| 163 | return -ENOMEM; |
| 164 | |
| 165 | for (i = 0; i < len; i++) |
| 166 | insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe); |
| 167 | |
| 168 | self->u.ptr.insns = insn; |
| 169 | self->u.ptr.len = len; |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int bpf_fill_maxinsns5(struct bpf_test *self) |
| 175 | { |
| 176 | unsigned int len = BPF_MAXINSNS; |
| 177 | struct sock_filter *insn; |
| 178 | int i; |
| 179 | |
| 180 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 181 | if (!insn) |
| 182 | return -ENOMEM; |
| 183 | |
| 184 | insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0); |
| 185 | |
| 186 | for (i = 1; i < len - 1; i++) |
| 187 | insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe); |
| 188 | |
| 189 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab); |
| 190 | |
| 191 | self->u.ptr.insns = insn; |
| 192 | self->u.ptr.len = len; |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int bpf_fill_maxinsns6(struct bpf_test *self) |
| 198 | { |
| 199 | unsigned int len = BPF_MAXINSNS; |
| 200 | struct sock_filter *insn; |
| 201 | int i; |
| 202 | |
| 203 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 204 | if (!insn) |
| 205 | return -ENOMEM; |
| 206 | |
| 207 | for (i = 0; i < len - 1; i++) |
| 208 | insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF + |
| 209 | SKF_AD_VLAN_TAG_PRESENT); |
| 210 | |
| 211 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); |
| 212 | |
| 213 | self->u.ptr.insns = insn; |
| 214 | self->u.ptr.len = len; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int bpf_fill_maxinsns7(struct bpf_test *self) |
| 220 | { |
| 221 | unsigned int len = BPF_MAXINSNS; |
| 222 | struct sock_filter *insn; |
| 223 | int i; |
| 224 | |
| 225 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 226 | if (!insn) |
| 227 | return -ENOMEM; |
| 228 | |
| 229 | for (i = 0; i < len - 4; i++) |
| 230 | insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF + |
| 231 | SKF_AD_CPU); |
| 232 | |
| 233 | insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0); |
| 234 | insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF + |
| 235 | SKF_AD_CPU); |
| 236 | insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0); |
| 237 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); |
| 238 | |
| 239 | self->u.ptr.insns = insn; |
| 240 | self->u.ptr.len = len; |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int bpf_fill_maxinsns8(struct bpf_test *self) |
| 246 | { |
| 247 | unsigned int len = BPF_MAXINSNS; |
| 248 | struct sock_filter *insn; |
| 249 | int i, jmp_off = len - 3; |
| 250 | |
| 251 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 252 | if (!insn) |
| 253 | return -ENOMEM; |
| 254 | |
| 255 | insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff); |
| 256 | |
| 257 | for (i = 1; i < len - 1; i++) |
| 258 | insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0); |
| 259 | |
| 260 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); |
| 261 | |
| 262 | self->u.ptr.insns = insn; |
| 263 | self->u.ptr.len = len; |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
Daniel Borkmann | 3b52960 | 2015-05-23 01:10:07 +0200 | [diff] [blame] | 268 | static int bpf_fill_maxinsns9(struct bpf_test *self) |
| 269 | { |
| 270 | unsigned int len = BPF_MAXINSNS; |
| 271 | struct bpf_insn *insn; |
| 272 | int i; |
| 273 | |
| 274 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 275 | if (!insn) |
| 276 | return -ENOMEM; |
| 277 | |
| 278 | insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2); |
| 279 | insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab); |
| 280 | insn[2] = BPF_EXIT_INSN(); |
| 281 | |
| 282 | for (i = 3; i < len - 2; i++) |
| 283 | insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe); |
| 284 | |
| 285 | insn[len - 2] = BPF_EXIT_INSN(); |
| 286 | insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1)); |
| 287 | |
| 288 | self->u.ptr.insns = insn; |
| 289 | self->u.ptr.len = len; |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int bpf_fill_maxinsns10(struct bpf_test *self) |
| 295 | { |
| 296 | unsigned int len = BPF_MAXINSNS, hlen = len - 2; |
| 297 | struct bpf_insn *insn; |
| 298 | int i; |
| 299 | |
| 300 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 301 | if (!insn) |
| 302 | return -ENOMEM; |
| 303 | |
| 304 | for (i = 0; i < hlen / 2; i++) |
| 305 | insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i); |
| 306 | for (i = hlen - 1; i > hlen / 2; i--) |
| 307 | insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i); |
| 308 | |
| 309 | insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1); |
| 310 | insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac); |
| 311 | insn[hlen + 1] = BPF_EXIT_INSN(); |
| 312 | |
| 313 | self->u.ptr.insns = insn; |
| 314 | self->u.ptr.len = len; |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Daniel Borkmann | bde28bc | 2015-05-26 22:35:43 +0200 | [diff] [blame] | 319 | static int __bpf_fill_ja(struct bpf_test *self, unsigned int len, |
| 320 | unsigned int plen) |
| 321 | { |
| 322 | struct sock_filter *insn; |
| 323 | unsigned int rlen; |
| 324 | int i, j; |
| 325 | |
| 326 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 327 | if (!insn) |
| 328 | return -ENOMEM; |
| 329 | |
| 330 | rlen = (len % plen) - 1; |
| 331 | |
| 332 | for (i = 0; i + plen < len; i += plen) |
| 333 | for (j = 0; j < plen; j++) |
| 334 | insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, |
| 335 | plen - 1 - j, 0, 0); |
| 336 | for (j = 0; j < rlen; j++) |
| 337 | insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j, |
| 338 | 0, 0); |
| 339 | |
| 340 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac); |
| 341 | |
| 342 | self->u.ptr.insns = insn; |
| 343 | self->u.ptr.len = len; |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static int bpf_fill_maxinsns11(struct bpf_test *self) |
| 349 | { |
Gary Lin | 16a660e | 2021-01-19 18:25:00 +0800 | [diff] [blame] | 350 | /* Hits 70 passes on x86_64 and triggers NOPs padding. */ |
Daniel Borkmann | bde28bc | 2015-05-26 22:35:43 +0200 | [diff] [blame] | 351 | return __bpf_fill_ja(self, BPF_MAXINSNS, 68); |
| 352 | } |
| 353 | |
Daniel Borkmann | be08815 | 2018-06-02 23:06:32 +0200 | [diff] [blame] | 354 | static int bpf_fill_maxinsns12(struct bpf_test *self) |
| 355 | { |
| 356 | unsigned int len = BPF_MAXINSNS; |
| 357 | struct sock_filter *insn; |
| 358 | int i = 0; |
| 359 | |
| 360 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 361 | if (!insn) |
| 362 | return -ENOMEM; |
| 363 | |
| 364 | insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0); |
| 365 | |
| 366 | for (i = 1; i < len - 1; i++) |
| 367 | insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0); |
| 368 | |
| 369 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab); |
| 370 | |
| 371 | self->u.ptr.insns = insn; |
| 372 | self->u.ptr.len = len; |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static int bpf_fill_maxinsns13(struct bpf_test *self) |
| 378 | { |
| 379 | unsigned int len = BPF_MAXINSNS; |
| 380 | struct sock_filter *insn; |
| 381 | int i = 0; |
| 382 | |
| 383 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 384 | if (!insn) |
| 385 | return -ENOMEM; |
| 386 | |
| 387 | for (i = 0; i < len - 3; i++) |
| 388 | insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0); |
| 389 | |
| 390 | insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab); |
| 391 | insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0); |
| 392 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0); |
| 393 | |
| 394 | self->u.ptr.insns = insn; |
| 395 | self->u.ptr.len = len; |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
Daniel Borkmann | bde28bc | 2015-05-26 22:35:43 +0200 | [diff] [blame] | 400 | static int bpf_fill_ja(struct bpf_test *self) |
| 401 | { |
| 402 | /* Hits exactly 11 passes on x86_64 JIT. */ |
| 403 | return __bpf_fill_ja(self, 12, 9); |
| 404 | } |
| 405 | |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 406 | static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self) |
| 407 | { |
| 408 | unsigned int len = BPF_MAXINSNS; |
| 409 | struct sock_filter *insn; |
| 410 | int i; |
| 411 | |
| 412 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 413 | if (!insn) |
| 414 | return -ENOMEM; |
| 415 | |
| 416 | for (i = 0; i < len - 1; i += 2) { |
| 417 | insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0); |
| 418 | insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 419 | SKF_AD_OFF + SKF_AD_CPU); |
| 420 | } |
| 421 | |
| 422 | insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee); |
| 423 | |
| 424 | self->u.ptr.insns = insn; |
| 425 | self->u.ptr.len = len; |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Daniel Borkmann | 85f68fe | 2017-05-01 02:57:20 +0200 | [diff] [blame] | 430 | static int __bpf_fill_stxdw(struct bpf_test *self, int size) |
| 431 | { |
| 432 | unsigned int len = BPF_MAXINSNS; |
| 433 | struct bpf_insn *insn; |
| 434 | int i; |
| 435 | |
| 436 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 437 | if (!insn) |
| 438 | return -ENOMEM; |
| 439 | |
| 440 | insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1); |
| 441 | insn[1] = BPF_ST_MEM(size, R10, -40, 42); |
| 442 | |
| 443 | for (i = 2; i < len - 2; i++) |
| 444 | insn[i] = BPF_STX_XADD(size, R10, R0, -40); |
| 445 | |
| 446 | insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40); |
| 447 | insn[len - 1] = BPF_EXIT_INSN(); |
| 448 | |
| 449 | self->u.ptr.insns = insn; |
| 450 | self->u.ptr.len = len; |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 451 | self->stack_depth = 40; |
Daniel Borkmann | 85f68fe | 2017-05-01 02:57:20 +0200 | [diff] [blame] | 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | static int bpf_fill_stxw(struct bpf_test *self) |
| 457 | { |
| 458 | return __bpf_fill_stxdw(self, BPF_W); |
| 459 | } |
| 460 | |
| 461 | static int bpf_fill_stxdw(struct bpf_test *self) |
| 462 | { |
| 463 | return __bpf_fill_stxdw(self, BPF_DW); |
| 464 | } |
| 465 | |
Johan Almbladh | 68c956f | 2021-09-14 11:18:31 +0200 | [diff] [blame] | 466 | static int __bpf_ld_imm64(struct bpf_insn insns[2], u8 reg, s64 imm64) |
| 467 | { |
| 468 | struct bpf_insn tmp[] = {BPF_LD_IMM64(reg, imm64)}; |
| 469 | |
| 470 | memcpy(insns, tmp, sizeof(tmp)); |
| 471 | return 2; |
| 472 | } |
| 473 | |
Johan Almbladh | f1517eb | 2021-09-14 11:18:39 +0200 | [diff] [blame] | 474 | /* |
| 475 | * Branch conversion tests. Complex operations can expand to a lot |
| 476 | * of instructions when JITed. This in turn may cause jump offsets |
| 477 | * to overflow the field size of the native instruction, triggering |
| 478 | * a branch conversion mechanism in some JITs. |
| 479 | */ |
| 480 | static int __bpf_fill_max_jmp(struct bpf_test *self, int jmp, int imm) |
| 481 | { |
| 482 | struct bpf_insn *insns; |
| 483 | int len = S16_MAX + 5; |
| 484 | int i; |
| 485 | |
| 486 | insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL); |
| 487 | if (!insns) |
| 488 | return -ENOMEM; |
| 489 | |
| 490 | i = __bpf_ld_imm64(insns, R1, 0x0123456789abcdefULL); |
| 491 | insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1); |
| 492 | insns[i++] = BPF_JMP_IMM(jmp, R0, imm, S16_MAX); |
| 493 | insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 2); |
| 494 | insns[i++] = BPF_EXIT_INSN(); |
| 495 | |
| 496 | while (i < len - 1) { |
| 497 | static const int ops[] = { |
| 498 | BPF_LSH, BPF_RSH, BPF_ARSH, BPF_ADD, |
| 499 | BPF_SUB, BPF_MUL, BPF_DIV, BPF_MOD, |
| 500 | }; |
| 501 | int op = ops[(i >> 1) % ARRAY_SIZE(ops)]; |
| 502 | |
| 503 | if (i & 1) |
| 504 | insns[i++] = BPF_ALU32_REG(op, R0, R1); |
| 505 | else |
| 506 | insns[i++] = BPF_ALU64_REG(op, R0, R1); |
| 507 | } |
| 508 | |
| 509 | insns[i++] = BPF_EXIT_INSN(); |
| 510 | self->u.ptr.insns = insns; |
| 511 | self->u.ptr.len = len; |
| 512 | BUG_ON(i != len); |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | /* Branch taken by runtime decision */ |
| 518 | static int bpf_fill_max_jmp_taken(struct bpf_test *self) |
| 519 | { |
| 520 | return __bpf_fill_max_jmp(self, BPF_JEQ, 1); |
| 521 | } |
| 522 | |
| 523 | /* Branch not taken by runtime decision */ |
| 524 | static int bpf_fill_max_jmp_not_taken(struct bpf_test *self) |
| 525 | { |
| 526 | return __bpf_fill_max_jmp(self, BPF_JEQ, 0); |
| 527 | } |
| 528 | |
| 529 | /* Branch always taken, known at JIT time */ |
| 530 | static int bpf_fill_max_jmp_always_taken(struct bpf_test *self) |
| 531 | { |
| 532 | return __bpf_fill_max_jmp(self, BPF_JGE, 0); |
| 533 | } |
| 534 | |
| 535 | /* Branch never taken, known at JIT time */ |
| 536 | static int bpf_fill_max_jmp_never_taken(struct bpf_test *self) |
| 537 | { |
| 538 | return __bpf_fill_max_jmp(self, BPF_JLT, 0); |
| 539 | } |
| 540 | |
Johan Almbladh | 68c956f | 2021-09-14 11:18:31 +0200 | [diff] [blame] | 541 | /* Test an ALU shift operation for all valid shift values */ |
| 542 | static int __bpf_fill_alu_shift(struct bpf_test *self, u8 op, |
| 543 | u8 mode, bool alu32) |
| 544 | { |
| 545 | static const s64 regs[] = { |
| 546 | 0x0123456789abcdefLL, /* dword > 0, word < 0 */ |
| 547 | 0xfedcba9876543210LL, /* dowrd < 0, word > 0 */ |
| 548 | 0xfedcba0198765432LL, /* dowrd < 0, word < 0 */ |
| 549 | 0x0123458967abcdefLL, /* dword > 0, word > 0 */ |
| 550 | }; |
| 551 | int bits = alu32 ? 32 : 64; |
| 552 | int len = (2 + 7 * bits) * ARRAY_SIZE(regs) + 3; |
| 553 | struct bpf_insn *insn; |
| 554 | int imm, k; |
| 555 | int i = 0; |
| 556 | |
| 557 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 558 | if (!insn) |
| 559 | return -ENOMEM; |
| 560 | |
| 561 | insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0); |
| 562 | |
| 563 | for (k = 0; k < ARRAY_SIZE(regs); k++) { |
| 564 | s64 reg = regs[k]; |
| 565 | |
| 566 | i += __bpf_ld_imm64(&insn[i], R3, reg); |
| 567 | |
| 568 | for (imm = 0; imm < bits; imm++) { |
| 569 | u64 val; |
| 570 | |
| 571 | /* Perform operation */ |
| 572 | insn[i++] = BPF_ALU64_REG(BPF_MOV, R1, R3); |
| 573 | insn[i++] = BPF_ALU64_IMM(BPF_MOV, R2, imm); |
| 574 | if (alu32) { |
| 575 | if (mode == BPF_K) |
| 576 | insn[i++] = BPF_ALU32_IMM(op, R1, imm); |
| 577 | else |
| 578 | insn[i++] = BPF_ALU32_REG(op, R1, R2); |
| 579 | switch (op) { |
| 580 | case BPF_LSH: |
| 581 | val = (u32)reg << imm; |
| 582 | break; |
| 583 | case BPF_RSH: |
| 584 | val = (u32)reg >> imm; |
| 585 | break; |
| 586 | case BPF_ARSH: |
| 587 | val = (u32)reg >> imm; |
| 588 | if (imm > 0 && (reg & 0x80000000)) |
| 589 | val |= ~(u32)0 << (32 - imm); |
| 590 | break; |
| 591 | } |
| 592 | } else { |
| 593 | if (mode == BPF_K) |
| 594 | insn[i++] = BPF_ALU64_IMM(op, R1, imm); |
| 595 | else |
| 596 | insn[i++] = BPF_ALU64_REG(op, R1, R2); |
| 597 | switch (op) { |
| 598 | case BPF_LSH: |
| 599 | val = (u64)reg << imm; |
| 600 | break; |
| 601 | case BPF_RSH: |
| 602 | val = (u64)reg >> imm; |
| 603 | break; |
| 604 | case BPF_ARSH: |
| 605 | val = (u64)reg >> imm; |
| 606 | if (imm > 0 && reg < 0) |
| 607 | val |= ~(u64)0 << (64 - imm); |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * When debugging a JIT that fails this test, one |
| 614 | * can write the immediate value to R0 here to find |
| 615 | * out which operand values that fail. |
| 616 | */ |
| 617 | |
| 618 | /* Load reference and check the result */ |
| 619 | i += __bpf_ld_imm64(&insn[i], R4, val); |
| 620 | insn[i++] = BPF_JMP_REG(BPF_JEQ, R1, R4, 1); |
| 621 | insn[i++] = BPF_EXIT_INSN(); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1); |
| 626 | insn[i++] = BPF_EXIT_INSN(); |
| 627 | |
| 628 | self->u.ptr.insns = insn; |
| 629 | self->u.ptr.len = len; |
| 630 | BUG_ON(i > len); |
| 631 | |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | static int bpf_fill_alu_lsh_imm(struct bpf_test *self) |
| 636 | { |
| 637 | return __bpf_fill_alu_shift(self, BPF_LSH, BPF_K, false); |
| 638 | } |
| 639 | |
| 640 | static int bpf_fill_alu_rsh_imm(struct bpf_test *self) |
| 641 | { |
| 642 | return __bpf_fill_alu_shift(self, BPF_RSH, BPF_K, false); |
| 643 | } |
| 644 | |
| 645 | static int bpf_fill_alu_arsh_imm(struct bpf_test *self) |
| 646 | { |
| 647 | return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_K, false); |
| 648 | } |
| 649 | |
| 650 | static int bpf_fill_alu_lsh_reg(struct bpf_test *self) |
| 651 | { |
| 652 | return __bpf_fill_alu_shift(self, BPF_LSH, BPF_X, false); |
| 653 | } |
| 654 | |
| 655 | static int bpf_fill_alu_rsh_reg(struct bpf_test *self) |
| 656 | { |
| 657 | return __bpf_fill_alu_shift(self, BPF_RSH, BPF_X, false); |
| 658 | } |
| 659 | |
| 660 | static int bpf_fill_alu_arsh_reg(struct bpf_test *self) |
| 661 | { |
| 662 | return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_X, false); |
| 663 | } |
| 664 | |
| 665 | static int bpf_fill_alu32_lsh_imm(struct bpf_test *self) |
| 666 | { |
| 667 | return __bpf_fill_alu_shift(self, BPF_LSH, BPF_K, true); |
| 668 | } |
| 669 | |
| 670 | static int bpf_fill_alu32_rsh_imm(struct bpf_test *self) |
| 671 | { |
| 672 | return __bpf_fill_alu_shift(self, BPF_RSH, BPF_K, true); |
| 673 | } |
| 674 | |
| 675 | static int bpf_fill_alu32_arsh_imm(struct bpf_test *self) |
| 676 | { |
| 677 | return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_K, true); |
| 678 | } |
| 679 | |
| 680 | static int bpf_fill_alu32_lsh_reg(struct bpf_test *self) |
| 681 | { |
| 682 | return __bpf_fill_alu_shift(self, BPF_LSH, BPF_X, true); |
| 683 | } |
| 684 | |
| 685 | static int bpf_fill_alu32_rsh_reg(struct bpf_test *self) |
| 686 | { |
| 687 | return __bpf_fill_alu_shift(self, BPF_RSH, BPF_X, true); |
| 688 | } |
| 689 | |
| 690 | static int bpf_fill_alu32_arsh_reg(struct bpf_test *self) |
| 691 | { |
| 692 | return __bpf_fill_alu_shift(self, BPF_ARSH, BPF_X, true); |
| 693 | } |
| 694 | |
Johan Almbladh | 9298e63 | 2021-09-14 11:18:32 +0200 | [diff] [blame] | 695 | /* |
| 696 | * Common operand pattern generator for exhaustive power-of-two magnitudes |
| 697 | * tests. The block size parameters can be adjusted to increase/reduce the |
| 698 | * number of combinatons tested and thereby execution speed and memory |
| 699 | * footprint. |
| 700 | */ |
| 701 | |
| 702 | static inline s64 value(int msb, int delta, int sign) |
| 703 | { |
| 704 | return sign * (1LL << msb) + delta; |
| 705 | } |
| 706 | |
| 707 | static int __bpf_fill_pattern(struct bpf_test *self, void *arg, |
| 708 | int dbits, int sbits, int block1, int block2, |
| 709 | int (*emit)(struct bpf_test*, void*, |
| 710 | struct bpf_insn*, s64, s64)) |
| 711 | { |
| 712 | static const int sgn[][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; |
| 713 | struct bpf_insn *insns; |
| 714 | int di, si, bt, db, sb; |
| 715 | int count, len, k; |
| 716 | int extra = 1 + 2; |
| 717 | int i = 0; |
| 718 | |
| 719 | /* Total number of iterations for the two pattern */ |
| 720 | count = (dbits - 1) * (sbits - 1) * block1 * block1 * ARRAY_SIZE(sgn); |
| 721 | count += (max(dbits, sbits) - 1) * block2 * block2 * ARRAY_SIZE(sgn); |
| 722 | |
| 723 | /* Compute the maximum number of insns and allocate the buffer */ |
| 724 | len = extra + count * (*emit)(self, arg, NULL, 0, 0); |
| 725 | insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL); |
| 726 | if (!insns) |
| 727 | return -ENOMEM; |
| 728 | |
| 729 | /* Add head instruction(s) */ |
| 730 | insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0); |
| 731 | |
| 732 | /* |
| 733 | * Pattern 1: all combinations of power-of-two magnitudes and sign, |
| 734 | * and with a block of contiguous values around each magnitude. |
| 735 | */ |
| 736 | for (di = 0; di < dbits - 1; di++) /* Dst magnitudes */ |
| 737 | for (si = 0; si < sbits - 1; si++) /* Src magnitudes */ |
| 738 | for (k = 0; k < ARRAY_SIZE(sgn); k++) /* Sign combos */ |
| 739 | for (db = -(block1 / 2); |
| 740 | db < (block1 + 1) / 2; db++) |
| 741 | for (sb = -(block1 / 2); |
| 742 | sb < (block1 + 1) / 2; sb++) { |
| 743 | s64 dst, src; |
| 744 | |
| 745 | dst = value(di, db, sgn[k][0]); |
| 746 | src = value(si, sb, sgn[k][1]); |
| 747 | i += (*emit)(self, arg, |
| 748 | &insns[i], |
| 749 | dst, src); |
| 750 | } |
| 751 | /* |
| 752 | * Pattern 2: all combinations for a larger block of values |
| 753 | * for each power-of-two magnitude and sign, where the magnitude is |
| 754 | * the same for both operands. |
| 755 | */ |
| 756 | for (bt = 0; bt < max(dbits, sbits) - 1; bt++) /* Magnitude */ |
| 757 | for (k = 0; k < ARRAY_SIZE(sgn); k++) /* Sign combos */ |
| 758 | for (db = -(block2 / 2); db < (block2 + 1) / 2; db++) |
| 759 | for (sb = -(block2 / 2); |
| 760 | sb < (block2 + 1) / 2; sb++) { |
| 761 | s64 dst, src; |
| 762 | |
| 763 | dst = value(bt % dbits, db, sgn[k][0]); |
| 764 | src = value(bt % sbits, sb, sgn[k][1]); |
| 765 | i += (*emit)(self, arg, &insns[i], |
| 766 | dst, src); |
| 767 | } |
| 768 | |
| 769 | /* Append tail instructions */ |
| 770 | insns[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1); |
| 771 | insns[i++] = BPF_EXIT_INSN(); |
| 772 | BUG_ON(i > len); |
| 773 | |
| 774 | self->u.ptr.insns = insns; |
| 775 | self->u.ptr.len = i; |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /* |
| 781 | * Block size parameters used in pattern tests below. une as needed to |
| 782 | * increase/reduce the number combinations tested, see following examples. |
| 783 | * block values per operand MSB |
| 784 | * ---------------------------------------- |
| 785 | * 0 none |
| 786 | * 1 (1 << MSB) |
| 787 | * 2 (1 << MSB) + [-1, 0] |
| 788 | * 3 (1 << MSB) + [-1, 0, 1] |
| 789 | */ |
| 790 | #define PATTERN_BLOCK1 1 |
| 791 | #define PATTERN_BLOCK2 5 |
| 792 | |
| 793 | /* Number of test runs for a pattern test */ |
| 794 | #define NR_PATTERN_RUNS 1 |
| 795 | |
| 796 | /* |
| 797 | * Exhaustive tests of ALU operations for all combinations of power-of-two |
| 798 | * magnitudes of the operands, both for positive and negative values. The |
| 799 | * test is designed to verify e.g. the JMP and JMP32 operations for JITs that |
| 800 | * emit different code depending on the magnitude of the immediate value. |
| 801 | */ |
| 802 | |
| 803 | static bool __bpf_alu_result(u64 *res, u64 v1, u64 v2, u8 op) |
| 804 | { |
| 805 | *res = 0; |
| 806 | switch (op) { |
| 807 | case BPF_MOV: |
| 808 | *res = v2; |
| 809 | break; |
| 810 | case BPF_AND: |
| 811 | *res = v1 & v2; |
| 812 | break; |
| 813 | case BPF_OR: |
| 814 | *res = v1 | v2; |
| 815 | break; |
| 816 | case BPF_XOR: |
| 817 | *res = v1 ^ v2; |
| 818 | break; |
| 819 | case BPF_ADD: |
| 820 | *res = v1 + v2; |
| 821 | break; |
| 822 | case BPF_SUB: |
| 823 | *res = v1 - v2; |
| 824 | break; |
| 825 | case BPF_MUL: |
| 826 | *res = v1 * v2; |
| 827 | break; |
| 828 | case BPF_DIV: |
| 829 | if (v2 == 0) |
| 830 | return false; |
| 831 | *res = div64_u64(v1, v2); |
| 832 | break; |
| 833 | case BPF_MOD: |
| 834 | if (v2 == 0) |
| 835 | return false; |
| 836 | div64_u64_rem(v1, v2, res); |
| 837 | break; |
| 838 | } |
| 839 | return true; |
| 840 | } |
| 841 | |
| 842 | static int __bpf_emit_alu64_imm(struct bpf_test *self, void *arg, |
| 843 | struct bpf_insn *insns, s64 dst, s64 imm) |
| 844 | { |
| 845 | int op = *(int *)arg; |
| 846 | int i = 0; |
| 847 | u64 res; |
| 848 | |
| 849 | if (!insns) |
| 850 | return 7; |
| 851 | |
| 852 | if (__bpf_alu_result(&res, dst, (s32)imm, op)) { |
| 853 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 854 | i += __bpf_ld_imm64(&insns[i], R3, res); |
| 855 | insns[i++] = BPF_ALU64_IMM(op, R1, imm); |
| 856 | insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1); |
| 857 | insns[i++] = BPF_EXIT_INSN(); |
| 858 | } |
| 859 | |
| 860 | return i; |
| 861 | } |
| 862 | |
| 863 | static int __bpf_emit_alu32_imm(struct bpf_test *self, void *arg, |
| 864 | struct bpf_insn *insns, s64 dst, s64 imm) |
| 865 | { |
| 866 | int op = *(int *)arg; |
| 867 | int i = 0; |
| 868 | u64 res; |
| 869 | |
| 870 | if (!insns) |
| 871 | return 7; |
| 872 | |
| 873 | if (__bpf_alu_result(&res, (u32)dst, (u32)imm, op)) { |
| 874 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 875 | i += __bpf_ld_imm64(&insns[i], R3, (u32)res); |
| 876 | insns[i++] = BPF_ALU32_IMM(op, R1, imm); |
| 877 | insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1); |
| 878 | insns[i++] = BPF_EXIT_INSN(); |
| 879 | } |
| 880 | |
| 881 | return i; |
| 882 | } |
| 883 | |
| 884 | static int __bpf_emit_alu64_reg(struct bpf_test *self, void *arg, |
| 885 | struct bpf_insn *insns, s64 dst, s64 src) |
| 886 | { |
| 887 | int op = *(int *)arg; |
| 888 | int i = 0; |
| 889 | u64 res; |
| 890 | |
| 891 | if (!insns) |
| 892 | return 9; |
| 893 | |
| 894 | if (__bpf_alu_result(&res, dst, src, op)) { |
| 895 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 896 | i += __bpf_ld_imm64(&insns[i], R2, src); |
| 897 | i += __bpf_ld_imm64(&insns[i], R3, res); |
| 898 | insns[i++] = BPF_ALU64_REG(op, R1, R2); |
| 899 | insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1); |
| 900 | insns[i++] = BPF_EXIT_INSN(); |
| 901 | } |
| 902 | |
| 903 | return i; |
| 904 | } |
| 905 | |
| 906 | static int __bpf_emit_alu32_reg(struct bpf_test *self, void *arg, |
| 907 | struct bpf_insn *insns, s64 dst, s64 src) |
| 908 | { |
| 909 | int op = *(int *)arg; |
| 910 | int i = 0; |
| 911 | u64 res; |
| 912 | |
| 913 | if (!insns) |
| 914 | return 9; |
| 915 | |
| 916 | if (__bpf_alu_result(&res, (u32)dst, (u32)src, op)) { |
| 917 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 918 | i += __bpf_ld_imm64(&insns[i], R2, src); |
| 919 | i += __bpf_ld_imm64(&insns[i], R3, (u32)res); |
| 920 | insns[i++] = BPF_ALU32_REG(op, R1, R2); |
| 921 | insns[i++] = BPF_JMP_REG(BPF_JEQ, R1, R3, 1); |
| 922 | insns[i++] = BPF_EXIT_INSN(); |
| 923 | } |
| 924 | |
| 925 | return i; |
| 926 | } |
| 927 | |
| 928 | static int __bpf_fill_alu64_imm(struct bpf_test *self, int op) |
| 929 | { |
| 930 | return __bpf_fill_pattern(self, &op, 64, 32, |
| 931 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 932 | &__bpf_emit_alu64_imm); |
| 933 | } |
| 934 | |
| 935 | static int __bpf_fill_alu32_imm(struct bpf_test *self, int op) |
| 936 | { |
| 937 | return __bpf_fill_pattern(self, &op, 64, 32, |
| 938 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 939 | &__bpf_emit_alu32_imm); |
| 940 | } |
| 941 | |
| 942 | static int __bpf_fill_alu64_reg(struct bpf_test *self, int op) |
| 943 | { |
| 944 | return __bpf_fill_pattern(self, &op, 64, 64, |
| 945 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 946 | &__bpf_emit_alu64_reg); |
| 947 | } |
| 948 | |
| 949 | static int __bpf_fill_alu32_reg(struct bpf_test *self, int op) |
| 950 | { |
| 951 | return __bpf_fill_pattern(self, &op, 64, 64, |
| 952 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 953 | &__bpf_emit_alu32_reg); |
| 954 | } |
| 955 | |
| 956 | /* ALU64 immediate operations */ |
| 957 | static int bpf_fill_alu64_mov_imm(struct bpf_test *self) |
| 958 | { |
| 959 | return __bpf_fill_alu64_imm(self, BPF_MOV); |
| 960 | } |
| 961 | |
| 962 | static int bpf_fill_alu64_and_imm(struct bpf_test *self) |
| 963 | { |
| 964 | return __bpf_fill_alu64_imm(self, BPF_AND); |
| 965 | } |
| 966 | |
| 967 | static int bpf_fill_alu64_or_imm(struct bpf_test *self) |
| 968 | { |
| 969 | return __bpf_fill_alu64_imm(self, BPF_OR); |
| 970 | } |
| 971 | |
| 972 | static int bpf_fill_alu64_xor_imm(struct bpf_test *self) |
| 973 | { |
| 974 | return __bpf_fill_alu64_imm(self, BPF_XOR); |
| 975 | } |
| 976 | |
| 977 | static int bpf_fill_alu64_add_imm(struct bpf_test *self) |
| 978 | { |
| 979 | return __bpf_fill_alu64_imm(self, BPF_ADD); |
| 980 | } |
| 981 | |
| 982 | static int bpf_fill_alu64_sub_imm(struct bpf_test *self) |
| 983 | { |
| 984 | return __bpf_fill_alu64_imm(self, BPF_SUB); |
| 985 | } |
| 986 | |
| 987 | static int bpf_fill_alu64_mul_imm(struct bpf_test *self) |
| 988 | { |
| 989 | return __bpf_fill_alu64_imm(self, BPF_MUL); |
| 990 | } |
| 991 | |
| 992 | static int bpf_fill_alu64_div_imm(struct bpf_test *self) |
| 993 | { |
| 994 | return __bpf_fill_alu64_imm(self, BPF_DIV); |
| 995 | } |
| 996 | |
| 997 | static int bpf_fill_alu64_mod_imm(struct bpf_test *self) |
| 998 | { |
| 999 | return __bpf_fill_alu64_imm(self, BPF_MOD); |
| 1000 | } |
| 1001 | |
| 1002 | /* ALU32 immediate operations */ |
| 1003 | static int bpf_fill_alu32_mov_imm(struct bpf_test *self) |
| 1004 | { |
| 1005 | return __bpf_fill_alu32_imm(self, BPF_MOV); |
| 1006 | } |
| 1007 | |
| 1008 | static int bpf_fill_alu32_and_imm(struct bpf_test *self) |
| 1009 | { |
| 1010 | return __bpf_fill_alu32_imm(self, BPF_AND); |
| 1011 | } |
| 1012 | |
| 1013 | static int bpf_fill_alu32_or_imm(struct bpf_test *self) |
| 1014 | { |
| 1015 | return __bpf_fill_alu32_imm(self, BPF_OR); |
| 1016 | } |
| 1017 | |
| 1018 | static int bpf_fill_alu32_xor_imm(struct bpf_test *self) |
| 1019 | { |
| 1020 | return __bpf_fill_alu32_imm(self, BPF_XOR); |
| 1021 | } |
| 1022 | |
| 1023 | static int bpf_fill_alu32_add_imm(struct bpf_test *self) |
| 1024 | { |
| 1025 | return __bpf_fill_alu32_imm(self, BPF_ADD); |
| 1026 | } |
| 1027 | |
| 1028 | static int bpf_fill_alu32_sub_imm(struct bpf_test *self) |
| 1029 | { |
| 1030 | return __bpf_fill_alu32_imm(self, BPF_SUB); |
| 1031 | } |
| 1032 | |
| 1033 | static int bpf_fill_alu32_mul_imm(struct bpf_test *self) |
| 1034 | { |
| 1035 | return __bpf_fill_alu32_imm(self, BPF_MUL); |
| 1036 | } |
| 1037 | |
| 1038 | static int bpf_fill_alu32_div_imm(struct bpf_test *self) |
| 1039 | { |
| 1040 | return __bpf_fill_alu32_imm(self, BPF_DIV); |
| 1041 | } |
| 1042 | |
| 1043 | static int bpf_fill_alu32_mod_imm(struct bpf_test *self) |
| 1044 | { |
| 1045 | return __bpf_fill_alu32_imm(self, BPF_MOD); |
| 1046 | } |
| 1047 | |
| 1048 | /* ALU64 register operations */ |
| 1049 | static int bpf_fill_alu64_mov_reg(struct bpf_test *self) |
| 1050 | { |
| 1051 | return __bpf_fill_alu64_reg(self, BPF_MOV); |
| 1052 | } |
| 1053 | |
| 1054 | static int bpf_fill_alu64_and_reg(struct bpf_test *self) |
| 1055 | { |
| 1056 | return __bpf_fill_alu64_reg(self, BPF_AND); |
| 1057 | } |
| 1058 | |
| 1059 | static int bpf_fill_alu64_or_reg(struct bpf_test *self) |
| 1060 | { |
| 1061 | return __bpf_fill_alu64_reg(self, BPF_OR); |
| 1062 | } |
| 1063 | |
| 1064 | static int bpf_fill_alu64_xor_reg(struct bpf_test *self) |
| 1065 | { |
| 1066 | return __bpf_fill_alu64_reg(self, BPF_XOR); |
| 1067 | } |
| 1068 | |
| 1069 | static int bpf_fill_alu64_add_reg(struct bpf_test *self) |
| 1070 | { |
| 1071 | return __bpf_fill_alu64_reg(self, BPF_ADD); |
| 1072 | } |
| 1073 | |
| 1074 | static int bpf_fill_alu64_sub_reg(struct bpf_test *self) |
| 1075 | { |
| 1076 | return __bpf_fill_alu64_reg(self, BPF_SUB); |
| 1077 | } |
| 1078 | |
| 1079 | static int bpf_fill_alu64_mul_reg(struct bpf_test *self) |
| 1080 | { |
| 1081 | return __bpf_fill_alu64_reg(self, BPF_MUL); |
| 1082 | } |
| 1083 | |
| 1084 | static int bpf_fill_alu64_div_reg(struct bpf_test *self) |
| 1085 | { |
| 1086 | return __bpf_fill_alu64_reg(self, BPF_DIV); |
| 1087 | } |
| 1088 | |
| 1089 | static int bpf_fill_alu64_mod_reg(struct bpf_test *self) |
| 1090 | { |
| 1091 | return __bpf_fill_alu64_reg(self, BPF_MOD); |
| 1092 | } |
| 1093 | |
| 1094 | /* ALU32 register operations */ |
| 1095 | static int bpf_fill_alu32_mov_reg(struct bpf_test *self) |
| 1096 | { |
| 1097 | return __bpf_fill_alu32_reg(self, BPF_MOV); |
| 1098 | } |
| 1099 | |
| 1100 | static int bpf_fill_alu32_and_reg(struct bpf_test *self) |
| 1101 | { |
| 1102 | return __bpf_fill_alu32_reg(self, BPF_AND); |
| 1103 | } |
| 1104 | |
| 1105 | static int bpf_fill_alu32_or_reg(struct bpf_test *self) |
| 1106 | { |
| 1107 | return __bpf_fill_alu32_reg(self, BPF_OR); |
| 1108 | } |
| 1109 | |
| 1110 | static int bpf_fill_alu32_xor_reg(struct bpf_test *self) |
| 1111 | { |
| 1112 | return __bpf_fill_alu32_reg(self, BPF_XOR); |
| 1113 | } |
| 1114 | |
| 1115 | static int bpf_fill_alu32_add_reg(struct bpf_test *self) |
| 1116 | { |
| 1117 | return __bpf_fill_alu32_reg(self, BPF_ADD); |
| 1118 | } |
| 1119 | |
| 1120 | static int bpf_fill_alu32_sub_reg(struct bpf_test *self) |
| 1121 | { |
| 1122 | return __bpf_fill_alu32_reg(self, BPF_SUB); |
| 1123 | } |
| 1124 | |
| 1125 | static int bpf_fill_alu32_mul_reg(struct bpf_test *self) |
| 1126 | { |
| 1127 | return __bpf_fill_alu32_reg(self, BPF_MUL); |
| 1128 | } |
| 1129 | |
| 1130 | static int bpf_fill_alu32_div_reg(struct bpf_test *self) |
| 1131 | { |
| 1132 | return __bpf_fill_alu32_reg(self, BPF_DIV); |
| 1133 | } |
| 1134 | |
| 1135 | static int bpf_fill_alu32_mod_reg(struct bpf_test *self) |
| 1136 | { |
| 1137 | return __bpf_fill_alu32_reg(self, BPF_MOD); |
| 1138 | } |
| 1139 | |
Johan Almbladh | 2e80761 | 2021-09-14 11:18:35 +0200 | [diff] [blame] | 1140 | /* |
| 1141 | * Test the two-instruction 64-bit immediate load operation for all |
| 1142 | * power-of-two magnitudes of the immediate operand. For each MSB, a block |
| 1143 | * of immediate values centered around the power-of-two MSB are tested, |
| 1144 | * both for positive and negative values. The test is designed to verify |
| 1145 | * the operation for JITs that emit different code depending on the magnitude |
| 1146 | * of the immediate value. This is often the case if the native instruction |
| 1147 | * immediate field width is narrower than 32 bits. |
| 1148 | */ |
| 1149 | static int bpf_fill_ld_imm64(struct bpf_test *self) |
| 1150 | { |
| 1151 | int block = 64; /* Increase for more tests per MSB position */ |
| 1152 | int len = 3 + 8 * 63 * block * 2; |
| 1153 | struct bpf_insn *insn; |
| 1154 | int bit, adj, sign; |
| 1155 | int i = 0; |
| 1156 | |
| 1157 | insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); |
| 1158 | if (!insn) |
| 1159 | return -ENOMEM; |
| 1160 | |
| 1161 | insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 0); |
| 1162 | |
| 1163 | for (bit = 0; bit <= 62; bit++) { |
| 1164 | for (adj = -block / 2; adj < block / 2; adj++) { |
| 1165 | for (sign = -1; sign <= 1; sign += 2) { |
| 1166 | s64 imm = sign * ((1LL << bit) + adj); |
| 1167 | |
| 1168 | /* Perform operation */ |
| 1169 | i += __bpf_ld_imm64(&insn[i], R1, imm); |
| 1170 | |
| 1171 | /* Load reference */ |
| 1172 | insn[i++] = BPF_ALU32_IMM(BPF_MOV, R2, imm); |
| 1173 | insn[i++] = BPF_ALU32_IMM(BPF_MOV, R3, |
| 1174 | (u32)(imm >> 32)); |
| 1175 | insn[i++] = BPF_ALU64_IMM(BPF_LSH, R3, 32); |
| 1176 | insn[i++] = BPF_ALU64_REG(BPF_OR, R2, R3); |
| 1177 | |
| 1178 | /* Check result */ |
| 1179 | insn[i++] = BPF_JMP_REG(BPF_JEQ, R1, R2, 1); |
| 1180 | insn[i++] = BPF_EXIT_INSN(); |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | insn[i++] = BPF_ALU64_IMM(BPF_MOV, R0, 1); |
| 1186 | insn[i++] = BPF_EXIT_INSN(); |
| 1187 | |
| 1188 | self->u.ptr.insns = insn; |
| 1189 | self->u.ptr.len = len; |
| 1190 | BUG_ON(i != len); |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
Johan Almbladh | a5a3654 | 2021-09-14 11:18:33 +0200 | [diff] [blame] | 1194 | |
| 1195 | /* |
| 1196 | * Exhaustive tests of JMP operations for all combinations of power-of-two |
| 1197 | * magnitudes of the operands, both for positive and negative values. The |
| 1198 | * test is designed to verify e.g. the JMP and JMP32 operations for JITs that |
| 1199 | * emit different code depending on the magnitude of the immediate value. |
| 1200 | */ |
| 1201 | |
| 1202 | static bool __bpf_match_jmp_cond(s64 v1, s64 v2, u8 op) |
| 1203 | { |
| 1204 | switch (op) { |
| 1205 | case BPF_JSET: |
| 1206 | return !!(v1 & v2); |
| 1207 | case BPF_JEQ: |
| 1208 | return v1 == v2; |
| 1209 | case BPF_JNE: |
| 1210 | return v1 != v2; |
| 1211 | case BPF_JGT: |
| 1212 | return (u64)v1 > (u64)v2; |
| 1213 | case BPF_JGE: |
| 1214 | return (u64)v1 >= (u64)v2; |
| 1215 | case BPF_JLT: |
| 1216 | return (u64)v1 < (u64)v2; |
| 1217 | case BPF_JLE: |
| 1218 | return (u64)v1 <= (u64)v2; |
| 1219 | case BPF_JSGT: |
| 1220 | return v1 > v2; |
| 1221 | case BPF_JSGE: |
| 1222 | return v1 >= v2; |
| 1223 | case BPF_JSLT: |
| 1224 | return v1 < v2; |
| 1225 | case BPF_JSLE: |
| 1226 | return v1 <= v2; |
| 1227 | } |
| 1228 | return false; |
| 1229 | } |
| 1230 | |
| 1231 | static int __bpf_emit_jmp_imm(struct bpf_test *self, void *arg, |
| 1232 | struct bpf_insn *insns, s64 dst, s64 imm) |
| 1233 | { |
| 1234 | int op = *(int *)arg; |
| 1235 | |
| 1236 | if (insns) { |
| 1237 | bool match = __bpf_match_jmp_cond(dst, (s32)imm, op); |
| 1238 | int i = 0; |
| 1239 | |
| 1240 | insns[i++] = BPF_ALU32_IMM(BPF_MOV, R0, match); |
| 1241 | |
| 1242 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 1243 | insns[i++] = BPF_JMP_IMM(op, R1, imm, 1); |
| 1244 | if (!match) |
| 1245 | insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1); |
| 1246 | insns[i++] = BPF_EXIT_INSN(); |
| 1247 | |
| 1248 | return i; |
| 1249 | } |
| 1250 | |
| 1251 | return 5 + 1; |
| 1252 | } |
| 1253 | |
| 1254 | static int __bpf_emit_jmp32_imm(struct bpf_test *self, void *arg, |
| 1255 | struct bpf_insn *insns, s64 dst, s64 imm) |
| 1256 | { |
| 1257 | int op = *(int *)arg; |
| 1258 | |
| 1259 | if (insns) { |
| 1260 | bool match = __bpf_match_jmp_cond((s32)dst, (s32)imm, op); |
| 1261 | int i = 0; |
| 1262 | |
| 1263 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 1264 | insns[i++] = BPF_JMP32_IMM(op, R1, imm, 1); |
| 1265 | if (!match) |
| 1266 | insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1); |
| 1267 | insns[i++] = BPF_EXIT_INSN(); |
| 1268 | |
| 1269 | return i; |
| 1270 | } |
| 1271 | |
| 1272 | return 5; |
| 1273 | } |
| 1274 | |
| 1275 | static int __bpf_emit_jmp_reg(struct bpf_test *self, void *arg, |
| 1276 | struct bpf_insn *insns, s64 dst, s64 src) |
| 1277 | { |
| 1278 | int op = *(int *)arg; |
| 1279 | |
| 1280 | if (insns) { |
| 1281 | bool match = __bpf_match_jmp_cond(dst, src, op); |
| 1282 | int i = 0; |
| 1283 | |
| 1284 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 1285 | i += __bpf_ld_imm64(&insns[i], R2, src); |
| 1286 | insns[i++] = BPF_JMP_REG(op, R1, R2, 1); |
| 1287 | if (!match) |
| 1288 | insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1); |
| 1289 | insns[i++] = BPF_EXIT_INSN(); |
| 1290 | |
| 1291 | return i; |
| 1292 | } |
| 1293 | |
| 1294 | return 7; |
| 1295 | } |
| 1296 | |
| 1297 | static int __bpf_emit_jmp32_reg(struct bpf_test *self, void *arg, |
| 1298 | struct bpf_insn *insns, s64 dst, s64 src) |
| 1299 | { |
| 1300 | int op = *(int *)arg; |
| 1301 | |
| 1302 | if (insns) { |
| 1303 | bool match = __bpf_match_jmp_cond((s32)dst, (s32)src, op); |
| 1304 | int i = 0; |
| 1305 | |
| 1306 | i += __bpf_ld_imm64(&insns[i], R1, dst); |
| 1307 | i += __bpf_ld_imm64(&insns[i], R2, src); |
| 1308 | insns[i++] = BPF_JMP32_REG(op, R1, R2, 1); |
| 1309 | if (!match) |
| 1310 | insns[i++] = BPF_JMP_IMM(BPF_JA, 0, 0, 1); |
| 1311 | insns[i++] = BPF_EXIT_INSN(); |
| 1312 | |
| 1313 | return i; |
| 1314 | } |
| 1315 | |
| 1316 | return 7; |
| 1317 | } |
| 1318 | |
| 1319 | static int __bpf_fill_jmp_imm(struct bpf_test *self, int op) |
| 1320 | { |
| 1321 | return __bpf_fill_pattern(self, &op, 64, 32, |
| 1322 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 1323 | &__bpf_emit_jmp_imm); |
| 1324 | } |
| 1325 | |
| 1326 | static int __bpf_fill_jmp32_imm(struct bpf_test *self, int op) |
| 1327 | { |
| 1328 | return __bpf_fill_pattern(self, &op, 64, 32, |
| 1329 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 1330 | &__bpf_emit_jmp32_imm); |
| 1331 | } |
| 1332 | |
| 1333 | static int __bpf_fill_jmp_reg(struct bpf_test *self, int op) |
| 1334 | { |
| 1335 | return __bpf_fill_pattern(self, &op, 64, 64, |
| 1336 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 1337 | &__bpf_emit_jmp_reg); |
| 1338 | } |
| 1339 | |
| 1340 | static int __bpf_fill_jmp32_reg(struct bpf_test *self, int op) |
| 1341 | { |
| 1342 | return __bpf_fill_pattern(self, &op, 64, 64, |
| 1343 | PATTERN_BLOCK1, PATTERN_BLOCK2, |
| 1344 | &__bpf_emit_jmp32_reg); |
| 1345 | } |
| 1346 | |
| 1347 | /* JMP immediate tests */ |
| 1348 | static int bpf_fill_jmp_jset_imm(struct bpf_test *self) |
| 1349 | { |
| 1350 | return __bpf_fill_jmp_imm(self, BPF_JSET); |
| 1351 | } |
| 1352 | |
| 1353 | static int bpf_fill_jmp_jeq_imm(struct bpf_test *self) |
| 1354 | { |
| 1355 | return __bpf_fill_jmp_imm(self, BPF_JEQ); |
| 1356 | } |
| 1357 | |
| 1358 | static int bpf_fill_jmp_jne_imm(struct bpf_test *self) |
| 1359 | { |
| 1360 | return __bpf_fill_jmp_imm(self, BPF_JNE); |
| 1361 | } |
| 1362 | |
| 1363 | static int bpf_fill_jmp_jgt_imm(struct bpf_test *self) |
| 1364 | { |
| 1365 | return __bpf_fill_jmp_imm(self, BPF_JGT); |
| 1366 | } |
| 1367 | |
| 1368 | static int bpf_fill_jmp_jge_imm(struct bpf_test *self) |
| 1369 | { |
| 1370 | return __bpf_fill_jmp_imm(self, BPF_JGE); |
| 1371 | } |
| 1372 | |
| 1373 | static int bpf_fill_jmp_jlt_imm(struct bpf_test *self) |
| 1374 | { |
| 1375 | return __bpf_fill_jmp_imm(self, BPF_JLT); |
| 1376 | } |
| 1377 | |
| 1378 | static int bpf_fill_jmp_jle_imm(struct bpf_test *self) |
| 1379 | { |
| 1380 | return __bpf_fill_jmp_imm(self, BPF_JLE); |
| 1381 | } |
| 1382 | |
| 1383 | static int bpf_fill_jmp_jsgt_imm(struct bpf_test *self) |
| 1384 | { |
| 1385 | return __bpf_fill_jmp_imm(self, BPF_JSGT); |
| 1386 | } |
| 1387 | |
| 1388 | static int bpf_fill_jmp_jsge_imm(struct bpf_test *self) |
| 1389 | { |
| 1390 | return __bpf_fill_jmp_imm(self, BPF_JSGE); |
| 1391 | } |
| 1392 | |
| 1393 | static int bpf_fill_jmp_jslt_imm(struct bpf_test *self) |
| 1394 | { |
| 1395 | return __bpf_fill_jmp_imm(self, BPF_JSLT); |
| 1396 | } |
| 1397 | |
| 1398 | static int bpf_fill_jmp_jsle_imm(struct bpf_test *self) |
| 1399 | { |
| 1400 | return __bpf_fill_jmp_imm(self, BPF_JSLE); |
| 1401 | } |
| 1402 | |
| 1403 | /* JMP32 immediate tests */ |
| 1404 | static int bpf_fill_jmp32_jset_imm(struct bpf_test *self) |
| 1405 | { |
| 1406 | return __bpf_fill_jmp32_imm(self, BPF_JSET); |
| 1407 | } |
| 1408 | |
| 1409 | static int bpf_fill_jmp32_jeq_imm(struct bpf_test *self) |
| 1410 | { |
| 1411 | return __bpf_fill_jmp32_imm(self, BPF_JEQ); |
| 1412 | } |
| 1413 | |
| 1414 | static int bpf_fill_jmp32_jne_imm(struct bpf_test *self) |
| 1415 | { |
| 1416 | return __bpf_fill_jmp32_imm(self, BPF_JNE); |
| 1417 | } |
| 1418 | |
| 1419 | static int bpf_fill_jmp32_jgt_imm(struct bpf_test *self) |
| 1420 | { |
| 1421 | return __bpf_fill_jmp32_imm(self, BPF_JGT); |
| 1422 | } |
| 1423 | |
| 1424 | static int bpf_fill_jmp32_jge_imm(struct bpf_test *self) |
| 1425 | { |
| 1426 | return __bpf_fill_jmp32_imm(self, BPF_JGE); |
| 1427 | } |
| 1428 | |
| 1429 | static int bpf_fill_jmp32_jlt_imm(struct bpf_test *self) |
| 1430 | { |
| 1431 | return __bpf_fill_jmp32_imm(self, BPF_JLT); |
| 1432 | } |
| 1433 | |
| 1434 | static int bpf_fill_jmp32_jle_imm(struct bpf_test *self) |
| 1435 | { |
| 1436 | return __bpf_fill_jmp32_imm(self, BPF_JLE); |
| 1437 | } |
| 1438 | |
| 1439 | static int bpf_fill_jmp32_jsgt_imm(struct bpf_test *self) |
| 1440 | { |
| 1441 | return __bpf_fill_jmp32_imm(self, BPF_JSGT); |
| 1442 | } |
| 1443 | |
| 1444 | static int bpf_fill_jmp32_jsge_imm(struct bpf_test *self) |
| 1445 | { |
| 1446 | return __bpf_fill_jmp32_imm(self, BPF_JSGE); |
| 1447 | } |
| 1448 | |
| 1449 | static int bpf_fill_jmp32_jslt_imm(struct bpf_test *self) |
| 1450 | { |
| 1451 | return __bpf_fill_jmp32_imm(self, BPF_JSLT); |
| 1452 | } |
| 1453 | |
| 1454 | static int bpf_fill_jmp32_jsle_imm(struct bpf_test *self) |
| 1455 | { |
| 1456 | return __bpf_fill_jmp32_imm(self, BPF_JSLE); |
| 1457 | } |
| 1458 | |
| 1459 | /* JMP register tests */ |
| 1460 | static int bpf_fill_jmp_jset_reg(struct bpf_test *self) |
| 1461 | { |
| 1462 | return __bpf_fill_jmp_reg(self, BPF_JSET); |
| 1463 | } |
| 1464 | |
| 1465 | static int bpf_fill_jmp_jeq_reg(struct bpf_test *self) |
| 1466 | { |
| 1467 | return __bpf_fill_jmp_reg(self, BPF_JEQ); |
| 1468 | } |
| 1469 | |
| 1470 | static int bpf_fill_jmp_jne_reg(struct bpf_test *self) |
| 1471 | { |
| 1472 | return __bpf_fill_jmp_reg(self, BPF_JNE); |
| 1473 | } |
| 1474 | |
| 1475 | static int bpf_fill_jmp_jgt_reg(struct bpf_test *self) |
| 1476 | { |
| 1477 | return __bpf_fill_jmp_reg(self, BPF_JGT); |
| 1478 | } |
| 1479 | |
| 1480 | static int bpf_fill_jmp_jge_reg(struct bpf_test *self) |
| 1481 | { |
| 1482 | return __bpf_fill_jmp_reg(self, BPF_JGE); |
| 1483 | } |
| 1484 | |
| 1485 | static int bpf_fill_jmp_jlt_reg(struct bpf_test *self) |
| 1486 | { |
| 1487 | return __bpf_fill_jmp_reg(self, BPF_JLT); |
| 1488 | } |
| 1489 | |
| 1490 | static int bpf_fill_jmp_jle_reg(struct bpf_test *self) |
| 1491 | { |
| 1492 | return __bpf_fill_jmp_reg(self, BPF_JLE); |
| 1493 | } |
| 1494 | |
| 1495 | static int bpf_fill_jmp_jsgt_reg(struct bpf_test *self) |
| 1496 | { |
| 1497 | return __bpf_fill_jmp_reg(self, BPF_JSGT); |
| 1498 | } |
| 1499 | |
| 1500 | static int bpf_fill_jmp_jsge_reg(struct bpf_test *self) |
| 1501 | { |
| 1502 | return __bpf_fill_jmp_reg(self, BPF_JSGE); |
| 1503 | } |
| 1504 | |
| 1505 | static int bpf_fill_jmp_jslt_reg(struct bpf_test *self) |
| 1506 | { |
| 1507 | return __bpf_fill_jmp_reg(self, BPF_JSLT); |
| 1508 | } |
| 1509 | |
| 1510 | static int bpf_fill_jmp_jsle_reg(struct bpf_test *self) |
| 1511 | { |
| 1512 | return __bpf_fill_jmp_reg(self, BPF_JSLE); |
| 1513 | } |
| 1514 | |
| 1515 | /* JMP32 register tests */ |
| 1516 | static int bpf_fill_jmp32_jset_reg(struct bpf_test *self) |
| 1517 | { |
| 1518 | return __bpf_fill_jmp32_reg(self, BPF_JSET); |
| 1519 | } |
| 1520 | |
| 1521 | static int bpf_fill_jmp32_jeq_reg(struct bpf_test *self) |
| 1522 | { |
| 1523 | return __bpf_fill_jmp32_reg(self, BPF_JEQ); |
| 1524 | } |
| 1525 | |
| 1526 | static int bpf_fill_jmp32_jne_reg(struct bpf_test *self) |
| 1527 | { |
| 1528 | return __bpf_fill_jmp32_reg(self, BPF_JNE); |
| 1529 | } |
| 1530 | |
| 1531 | static int bpf_fill_jmp32_jgt_reg(struct bpf_test *self) |
| 1532 | { |
| 1533 | return __bpf_fill_jmp32_reg(self, BPF_JGT); |
| 1534 | } |
| 1535 | |
| 1536 | static int bpf_fill_jmp32_jge_reg(struct bpf_test *self) |
| 1537 | { |
| 1538 | return __bpf_fill_jmp32_reg(self, BPF_JGE); |
| 1539 | } |
| 1540 | |
| 1541 | static int bpf_fill_jmp32_jlt_reg(struct bpf_test *self) |
| 1542 | { |
| 1543 | return __bpf_fill_jmp32_reg(self, BPF_JLT); |
| 1544 | } |
| 1545 | |
| 1546 | static int bpf_fill_jmp32_jle_reg(struct bpf_test *self) |
| 1547 | { |
| 1548 | return __bpf_fill_jmp32_reg(self, BPF_JLE); |
| 1549 | } |
| 1550 | |
| 1551 | static int bpf_fill_jmp32_jsgt_reg(struct bpf_test *self) |
| 1552 | { |
| 1553 | return __bpf_fill_jmp32_reg(self, BPF_JSGT); |
| 1554 | } |
| 1555 | |
| 1556 | static int bpf_fill_jmp32_jsge_reg(struct bpf_test *self) |
| 1557 | { |
| 1558 | return __bpf_fill_jmp32_reg(self, BPF_JSGE); |
| 1559 | } |
| 1560 | |
| 1561 | static int bpf_fill_jmp32_jslt_reg(struct bpf_test *self) |
| 1562 | { |
| 1563 | return __bpf_fill_jmp32_reg(self, BPF_JSLT); |
| 1564 | } |
| 1565 | |
| 1566 | static int bpf_fill_jmp32_jsle_reg(struct bpf_test *self) |
| 1567 | { |
| 1568 | return __bpf_fill_jmp32_reg(self, BPF_JSLE); |
| 1569 | } |
| 1570 | |
Johan Almbladh | a7d2e75 | 2021-09-14 11:18:34 +0200 | [diff] [blame] | 1571 | /* |
| 1572 | * Set up a sequence of staggered jumps, forwards and backwards with |
| 1573 | * increasing offset. This tests the conversion of relative jumps to |
| 1574 | * JITed native jumps. On some architectures, for example MIPS, a large |
| 1575 | * PC-relative jump offset may overflow the immediate field of the native |
| 1576 | * conditional branch instruction, triggering a conversion to use an |
| 1577 | * absolute jump instead. Since this changes the jump offsets, another |
| 1578 | * offset computation pass is necessary, and that may in turn trigger |
| 1579 | * another branch conversion. This jump sequence is particularly nasty |
| 1580 | * in that regard. |
| 1581 | * |
| 1582 | * The sequence generation is parameterized by size and jump type. |
| 1583 | * The size must be even, and the expected result is always size + 1. |
| 1584 | * Below is an example with size=8 and result=9. |
| 1585 | * |
| 1586 | * ________________________Start |
| 1587 | * R0 = 0 |
| 1588 | * R1 = r1 |
| 1589 | * R2 = r2 |
| 1590 | * ,------- JMP +4 * 3______________Preamble: 4 insns |
| 1591 | * ,----------|-ind 0- if R0 != 7 JMP 8 * 3 + 1 <--------------------. |
| 1592 | * | | R0 = 8 | |
| 1593 | * | | JMP +7 * 3 ------------------------. |
| 1594 | * | ,--------|-----1- if R0 != 5 JMP 7 * 3 + 1 <--------------. | | |
| 1595 | * | | | R0 = 6 | | | |
| 1596 | * | | | JMP +5 * 3 ------------------. | | |
| 1597 | * | | ,------|-----2- if R0 != 3 JMP 6 * 3 + 1 <--------. | | | | |
| 1598 | * | | | | R0 = 4 | | | | | |
| 1599 | * | | | | JMP +3 * 3 ------------. | | | | |
| 1600 | * | | | ,----|-----3- if R0 != 1 JMP 5 * 3 + 1 <--. | | | | | | |
| 1601 | * | | | | | R0 = 2 | | | | | | | |
| 1602 | * | | | | | JMP +1 * 3 ------. | | | | | | |
| 1603 | * | | | | ,--t=====4> if R0 != 0 JMP 4 * 3 + 1 1 2 3 4 5 6 7 8 loc |
| 1604 | * | | | | | R0 = 1 -1 +2 -3 +4 -5 +6 -7 +8 off |
| 1605 | * | | | | | JMP -2 * 3 ---' | | | | | | | |
| 1606 | * | | | | | ,------5- if R0 != 2 JMP 3 * 3 + 1 <-----' | | | | | | |
| 1607 | * | | | | | | R0 = 3 | | | | | | |
| 1608 | * | | | | | | JMP -4 * 3 ---------' | | | | | |
| 1609 | * | | | | | | ,----6- if R0 != 4 JMP 2 * 3 + 1 <-----------' | | | | |
| 1610 | * | | | | | | | R0 = 5 | | | | |
| 1611 | * | | | | | | | JMP -6 * 3 ---------------' | | | |
| 1612 | * | | | | | | | ,--7- if R0 != 6 JMP 1 * 3 + 1 <-----------------' | | |
| 1613 | * | | | | | | | | R0 = 7 | | |
| 1614 | * | | Error | | | JMP -8 * 3 ---------------------' | |
| 1615 | * | | paths | | | ,8- if R0 != 8 JMP 0 * 3 + 1 <-----------------------' |
| 1616 | * | | | | | | | | | R0 = 9__________________Sequence: 3 * size - 1 insns |
| 1617 | * `-+-+-+-+-+-+-+-+-> EXIT____________________Return: 1 insn |
| 1618 | * |
| 1619 | */ |
| 1620 | |
| 1621 | /* The maximum size parameter */ |
| 1622 | #define MAX_STAGGERED_JMP_SIZE ((0x7fff / 3) & ~1) |
| 1623 | |
| 1624 | /* We use a reduced number of iterations to get a reasonable execution time */ |
| 1625 | #define NR_STAGGERED_JMP_RUNS 10 |
| 1626 | |
| 1627 | static int __bpf_fill_staggered_jumps(struct bpf_test *self, |
| 1628 | const struct bpf_insn *jmp, |
| 1629 | u64 r1, u64 r2) |
| 1630 | { |
| 1631 | int size = self->test[0].result - 1; |
| 1632 | int len = 4 + 3 * (size + 1); |
| 1633 | struct bpf_insn *insns; |
| 1634 | int off, ind; |
| 1635 | |
| 1636 | insns = kmalloc_array(len, sizeof(*insns), GFP_KERNEL); |
| 1637 | if (!insns) |
| 1638 | return -ENOMEM; |
| 1639 | |
| 1640 | /* Preamble */ |
| 1641 | insns[0] = BPF_ALU64_IMM(BPF_MOV, R0, 0); |
| 1642 | insns[1] = BPF_ALU64_IMM(BPF_MOV, R1, r1); |
| 1643 | insns[2] = BPF_ALU64_IMM(BPF_MOV, R2, r2); |
| 1644 | insns[3] = BPF_JMP_IMM(BPF_JA, 0, 0, 3 * size / 2); |
| 1645 | |
| 1646 | /* Sequence */ |
| 1647 | for (ind = 0, off = size; ind <= size; ind++, off -= 2) { |
| 1648 | struct bpf_insn *ins = &insns[4 + 3 * ind]; |
| 1649 | int loc; |
| 1650 | |
| 1651 | if (off == 0) |
| 1652 | off--; |
| 1653 | |
| 1654 | loc = abs(off); |
| 1655 | ins[0] = BPF_JMP_IMM(BPF_JNE, R0, loc - 1, |
| 1656 | 3 * (size - ind) + 1); |
| 1657 | ins[1] = BPF_ALU64_IMM(BPF_MOV, R0, loc); |
| 1658 | ins[2] = *jmp; |
| 1659 | ins[2].off = 3 * (off - 1); |
| 1660 | } |
| 1661 | |
| 1662 | /* Return */ |
| 1663 | insns[len - 1] = BPF_EXIT_INSN(); |
| 1664 | |
| 1665 | self->u.ptr.insns = insns; |
| 1666 | self->u.ptr.len = len; |
| 1667 | |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | /* 64-bit unconditional jump */ |
| 1672 | static int bpf_fill_staggered_ja(struct bpf_test *self) |
| 1673 | { |
| 1674 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JA, 0, 0, 0); |
| 1675 | |
| 1676 | return __bpf_fill_staggered_jumps(self, &jmp, 0, 0); |
| 1677 | } |
| 1678 | |
| 1679 | /* 64-bit immediate jumps */ |
| 1680 | static int bpf_fill_staggered_jeq_imm(struct bpf_test *self) |
| 1681 | { |
| 1682 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JEQ, R1, 1234, 0); |
| 1683 | |
| 1684 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1685 | } |
| 1686 | |
| 1687 | static int bpf_fill_staggered_jne_imm(struct bpf_test *self) |
| 1688 | { |
| 1689 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JNE, R1, 1234, 0); |
| 1690 | |
| 1691 | return __bpf_fill_staggered_jumps(self, &jmp, 4321, 0); |
| 1692 | } |
| 1693 | |
| 1694 | static int bpf_fill_staggered_jset_imm(struct bpf_test *self) |
| 1695 | { |
| 1696 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSET, R1, 0x82, 0); |
| 1697 | |
| 1698 | return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0); |
| 1699 | } |
| 1700 | |
| 1701 | static int bpf_fill_staggered_jgt_imm(struct bpf_test *self) |
| 1702 | { |
| 1703 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JGT, R1, 1234, 0); |
| 1704 | |
| 1705 | return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 0); |
| 1706 | } |
| 1707 | |
| 1708 | static int bpf_fill_staggered_jge_imm(struct bpf_test *self) |
| 1709 | { |
| 1710 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JGE, R1, 1234, 0); |
| 1711 | |
| 1712 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1713 | } |
| 1714 | |
| 1715 | static int bpf_fill_staggered_jlt_imm(struct bpf_test *self) |
| 1716 | { |
| 1717 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JLT, R1, 0x80000000, 0); |
| 1718 | |
| 1719 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1720 | } |
| 1721 | |
| 1722 | static int bpf_fill_staggered_jle_imm(struct bpf_test *self) |
| 1723 | { |
| 1724 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JLE, R1, 1234, 0); |
| 1725 | |
| 1726 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1727 | } |
| 1728 | |
| 1729 | static int bpf_fill_staggered_jsgt_imm(struct bpf_test *self) |
| 1730 | { |
| 1731 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSGT, R1, -2, 0); |
| 1732 | |
| 1733 | return __bpf_fill_staggered_jumps(self, &jmp, -1, 0); |
| 1734 | } |
| 1735 | |
| 1736 | static int bpf_fill_staggered_jsge_imm(struct bpf_test *self) |
| 1737 | { |
| 1738 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSGE, R1, -2, 0); |
| 1739 | |
| 1740 | return __bpf_fill_staggered_jumps(self, &jmp, -2, 0); |
| 1741 | } |
| 1742 | |
| 1743 | static int bpf_fill_staggered_jslt_imm(struct bpf_test *self) |
| 1744 | { |
| 1745 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSLT, R1, -1, 0); |
| 1746 | |
| 1747 | return __bpf_fill_staggered_jumps(self, &jmp, -2, 0); |
| 1748 | } |
| 1749 | |
| 1750 | static int bpf_fill_staggered_jsle_imm(struct bpf_test *self) |
| 1751 | { |
| 1752 | struct bpf_insn jmp = BPF_JMP_IMM(BPF_JSLE, R1, -1, 0); |
| 1753 | |
| 1754 | return __bpf_fill_staggered_jumps(self, &jmp, -1, 0); |
| 1755 | } |
| 1756 | |
| 1757 | /* 64-bit register jumps */ |
| 1758 | static int bpf_fill_staggered_jeq_reg(struct bpf_test *self) |
| 1759 | { |
| 1760 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JEQ, R1, R2, 0); |
| 1761 | |
| 1762 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234); |
| 1763 | } |
| 1764 | |
| 1765 | static int bpf_fill_staggered_jne_reg(struct bpf_test *self) |
| 1766 | { |
| 1767 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JNE, R1, R2, 0); |
| 1768 | |
| 1769 | return __bpf_fill_staggered_jumps(self, &jmp, 4321, 1234); |
| 1770 | } |
| 1771 | |
| 1772 | static int bpf_fill_staggered_jset_reg(struct bpf_test *self) |
| 1773 | { |
| 1774 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JSET, R1, R2, 0); |
| 1775 | |
| 1776 | return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0x82); |
| 1777 | } |
| 1778 | |
| 1779 | static int bpf_fill_staggered_jgt_reg(struct bpf_test *self) |
| 1780 | { |
| 1781 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JGT, R1, R2, 0); |
| 1782 | |
| 1783 | return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 1234); |
| 1784 | } |
| 1785 | |
| 1786 | static int bpf_fill_staggered_jge_reg(struct bpf_test *self) |
| 1787 | { |
| 1788 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JGE, R1, R2, 0); |
| 1789 | |
| 1790 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234); |
| 1791 | } |
| 1792 | |
| 1793 | static int bpf_fill_staggered_jlt_reg(struct bpf_test *self) |
| 1794 | { |
| 1795 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JLT, R1, R2, 0); |
| 1796 | |
| 1797 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0x80000000); |
| 1798 | } |
| 1799 | |
| 1800 | static int bpf_fill_staggered_jle_reg(struct bpf_test *self) |
| 1801 | { |
| 1802 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JLE, R1, R2, 0); |
| 1803 | |
| 1804 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234); |
| 1805 | } |
| 1806 | |
| 1807 | static int bpf_fill_staggered_jsgt_reg(struct bpf_test *self) |
| 1808 | { |
| 1809 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JSGT, R1, R2, 0); |
| 1810 | |
| 1811 | return __bpf_fill_staggered_jumps(self, &jmp, -1, -2); |
| 1812 | } |
| 1813 | |
| 1814 | static int bpf_fill_staggered_jsge_reg(struct bpf_test *self) |
| 1815 | { |
| 1816 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JSGE, R1, R2, 0); |
| 1817 | |
| 1818 | return __bpf_fill_staggered_jumps(self, &jmp, -2, -2); |
| 1819 | } |
| 1820 | |
| 1821 | static int bpf_fill_staggered_jslt_reg(struct bpf_test *self) |
| 1822 | { |
| 1823 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JSLT, R1, R2, 0); |
| 1824 | |
| 1825 | return __bpf_fill_staggered_jumps(self, &jmp, -2, -1); |
| 1826 | } |
| 1827 | |
| 1828 | static int bpf_fill_staggered_jsle_reg(struct bpf_test *self) |
| 1829 | { |
| 1830 | struct bpf_insn jmp = BPF_JMP_REG(BPF_JSLE, R1, R2, 0); |
| 1831 | |
| 1832 | return __bpf_fill_staggered_jumps(self, &jmp, -1, -1); |
| 1833 | } |
| 1834 | |
| 1835 | /* 32-bit immediate jumps */ |
| 1836 | static int bpf_fill_staggered_jeq32_imm(struct bpf_test *self) |
| 1837 | { |
| 1838 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JEQ, R1, 1234, 0); |
| 1839 | |
| 1840 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1841 | } |
| 1842 | |
| 1843 | static int bpf_fill_staggered_jne32_imm(struct bpf_test *self) |
| 1844 | { |
| 1845 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JNE, R1, 1234, 0); |
| 1846 | |
| 1847 | return __bpf_fill_staggered_jumps(self, &jmp, 4321, 0); |
| 1848 | } |
| 1849 | |
| 1850 | static int bpf_fill_staggered_jset32_imm(struct bpf_test *self) |
| 1851 | { |
| 1852 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSET, R1, 0x82, 0); |
| 1853 | |
| 1854 | return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0); |
| 1855 | } |
| 1856 | |
| 1857 | static int bpf_fill_staggered_jgt32_imm(struct bpf_test *self) |
| 1858 | { |
| 1859 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JGT, R1, 1234, 0); |
| 1860 | |
| 1861 | return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 0); |
| 1862 | } |
| 1863 | |
| 1864 | static int bpf_fill_staggered_jge32_imm(struct bpf_test *self) |
| 1865 | { |
| 1866 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JGE, R1, 1234, 0); |
| 1867 | |
| 1868 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1869 | } |
| 1870 | |
| 1871 | static int bpf_fill_staggered_jlt32_imm(struct bpf_test *self) |
| 1872 | { |
| 1873 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JLT, R1, 0x80000000, 0); |
| 1874 | |
| 1875 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1876 | } |
| 1877 | |
| 1878 | static int bpf_fill_staggered_jle32_imm(struct bpf_test *self) |
| 1879 | { |
| 1880 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JLE, R1, 1234, 0); |
| 1881 | |
| 1882 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0); |
| 1883 | } |
| 1884 | |
| 1885 | static int bpf_fill_staggered_jsgt32_imm(struct bpf_test *self) |
| 1886 | { |
| 1887 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSGT, R1, -2, 0); |
| 1888 | |
| 1889 | return __bpf_fill_staggered_jumps(self, &jmp, -1, 0); |
| 1890 | } |
| 1891 | |
| 1892 | static int bpf_fill_staggered_jsge32_imm(struct bpf_test *self) |
| 1893 | { |
| 1894 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSGE, R1, -2, 0); |
| 1895 | |
| 1896 | return __bpf_fill_staggered_jumps(self, &jmp, -2, 0); |
| 1897 | } |
| 1898 | |
| 1899 | static int bpf_fill_staggered_jslt32_imm(struct bpf_test *self) |
| 1900 | { |
| 1901 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSLT, R1, -1, 0); |
| 1902 | |
| 1903 | return __bpf_fill_staggered_jumps(self, &jmp, -2, 0); |
| 1904 | } |
| 1905 | |
| 1906 | static int bpf_fill_staggered_jsle32_imm(struct bpf_test *self) |
| 1907 | { |
| 1908 | struct bpf_insn jmp = BPF_JMP32_IMM(BPF_JSLE, R1, -1, 0); |
| 1909 | |
| 1910 | return __bpf_fill_staggered_jumps(self, &jmp, -1, 0); |
| 1911 | } |
| 1912 | |
| 1913 | /* 32-bit register jumps */ |
| 1914 | static int bpf_fill_staggered_jeq32_reg(struct bpf_test *self) |
| 1915 | { |
| 1916 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JEQ, R1, R2, 0); |
| 1917 | |
| 1918 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234); |
| 1919 | } |
| 1920 | |
| 1921 | static int bpf_fill_staggered_jne32_reg(struct bpf_test *self) |
| 1922 | { |
| 1923 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JNE, R1, R2, 0); |
| 1924 | |
| 1925 | return __bpf_fill_staggered_jumps(self, &jmp, 4321, 1234); |
| 1926 | } |
| 1927 | |
| 1928 | static int bpf_fill_staggered_jset32_reg(struct bpf_test *self) |
| 1929 | { |
| 1930 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSET, R1, R2, 0); |
| 1931 | |
| 1932 | return __bpf_fill_staggered_jumps(self, &jmp, 0x86, 0x82); |
| 1933 | } |
| 1934 | |
| 1935 | static int bpf_fill_staggered_jgt32_reg(struct bpf_test *self) |
| 1936 | { |
| 1937 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JGT, R1, R2, 0); |
| 1938 | |
| 1939 | return __bpf_fill_staggered_jumps(self, &jmp, 0x80000000, 1234); |
| 1940 | } |
| 1941 | |
| 1942 | static int bpf_fill_staggered_jge32_reg(struct bpf_test *self) |
| 1943 | { |
| 1944 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JGE, R1, R2, 0); |
| 1945 | |
| 1946 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234); |
| 1947 | } |
| 1948 | |
| 1949 | static int bpf_fill_staggered_jlt32_reg(struct bpf_test *self) |
| 1950 | { |
| 1951 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JLT, R1, R2, 0); |
| 1952 | |
| 1953 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 0x80000000); |
| 1954 | } |
| 1955 | |
| 1956 | static int bpf_fill_staggered_jle32_reg(struct bpf_test *self) |
| 1957 | { |
| 1958 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JLE, R1, R2, 0); |
| 1959 | |
| 1960 | return __bpf_fill_staggered_jumps(self, &jmp, 1234, 1234); |
| 1961 | } |
| 1962 | |
| 1963 | static int bpf_fill_staggered_jsgt32_reg(struct bpf_test *self) |
| 1964 | { |
| 1965 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSGT, R1, R2, 0); |
| 1966 | |
| 1967 | return __bpf_fill_staggered_jumps(self, &jmp, -1, -2); |
| 1968 | } |
| 1969 | |
| 1970 | static int bpf_fill_staggered_jsge32_reg(struct bpf_test *self) |
| 1971 | { |
| 1972 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSGE, R1, R2, 0); |
| 1973 | |
| 1974 | return __bpf_fill_staggered_jumps(self, &jmp, -2, -2); |
| 1975 | } |
| 1976 | |
| 1977 | static int bpf_fill_staggered_jslt32_reg(struct bpf_test *self) |
| 1978 | { |
| 1979 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSLT, R1, R2, 0); |
| 1980 | |
| 1981 | return __bpf_fill_staggered_jumps(self, &jmp, -2, -1); |
| 1982 | } |
| 1983 | |
| 1984 | static int bpf_fill_staggered_jsle32_reg(struct bpf_test *self) |
| 1985 | { |
| 1986 | struct bpf_insn jmp = BPF_JMP32_REG(BPF_JSLE, R1, R2, 0); |
| 1987 | |
| 1988 | return __bpf_fill_staggered_jumps(self, &jmp, -1, -1); |
| 1989 | } |
| 1990 | |
Johan Almbladh | a5a3654 | 2021-09-14 11:18:33 +0200 | [diff] [blame] | 1991 | |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 1992 | static struct bpf_test tests[] = { |
| 1993 | { |
| 1994 | "TAX", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 1995 | .u.insns = { |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 1996 | BPF_STMT(BPF_LD | BPF_IMM, 1), |
| 1997 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 1998 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
| 1999 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2000 | BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */ |
| 2001 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2002 | BPF_STMT(BPF_LD | BPF_LEN, 0), |
| 2003 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2004 | BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */ |
| 2005 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
| 2006 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2007 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2008 | CLASSIC, |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 2009 | { 10, 20, 30, 40, 50 }, |
| 2010 | { { 2, 10 }, { 3, 20 }, { 4, 30 } }, |
| 2011 | }, |
| 2012 | { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2013 | "TXA", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2014 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2015 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2016 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 2017 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2018 | BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */ |
| 2019 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2020 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2021 | { 10, 20, 30, 40, 50 }, |
| 2022 | { { 1, 2 }, { 3, 6 }, { 4, 8 } }, |
| 2023 | }, |
| 2024 | { |
| 2025 | "ADD_SUB_MUL_K", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2026 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2027 | BPF_STMT(BPF_LD | BPF_IMM, 1), |
| 2028 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2), |
| 2029 | BPF_STMT(BPF_LDX | BPF_IMM, 3), |
| 2030 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), |
| 2031 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff), |
| 2032 | BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3), |
| 2033 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2034 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2035 | CLASSIC | FLAG_NO_DATA, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2036 | { }, |
| 2037 | { { 0, 0xfffffffd } } |
| 2038 | }, |
| 2039 | { |
Denis Kirjanov | 6867b17 | 2014-12-01 13:12:25 +0300 | [diff] [blame] | 2040 | "DIV_MOD_KX", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2041 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2042 | BPF_STMT(BPF_LD | BPF_IMM, 8), |
| 2043 | BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2), |
| 2044 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2045 | BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), |
| 2046 | BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0), |
| 2047 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2048 | BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), |
| 2049 | BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000), |
Denis Kirjanov | 6867b17 | 2014-12-01 13:12:25 +0300 | [diff] [blame] | 2050 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2051 | BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), |
| 2052 | BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0), |
| 2053 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2054 | BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), |
| 2055 | BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2056 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2057 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2058 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2059 | CLASSIC | FLAG_NO_DATA, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2060 | { }, |
Denis Kirjanov | 6867b17 | 2014-12-01 13:12:25 +0300 | [diff] [blame] | 2061 | { { 0, 0x20000000 } } |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2062 | }, |
| 2063 | { |
| 2064 | "AND_OR_LSH_K", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2065 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2066 | BPF_STMT(BPF_LD | BPF_IMM, 0xff), |
| 2067 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), |
| 2068 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27), |
| 2069 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2070 | BPF_STMT(BPF_LD | BPF_IMM, 0xf), |
| 2071 | BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0), |
| 2072 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2073 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2074 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2075 | CLASSIC | FLAG_NO_DATA, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2076 | { }, |
| 2077 | { { 0, 0x800000ff }, { 1, 0x800000ff } }, |
| 2078 | }, |
| 2079 | { |
Chema Gonzalez | e9d9450 | 2014-05-30 10:15:12 -0700 | [diff] [blame] | 2080 | "LD_IMM_0", |
| 2081 | .u.insns = { |
| 2082 | BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */ |
| 2083 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0), |
| 2084 | BPF_STMT(BPF_RET | BPF_K, 0), |
| 2085 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2086 | }, |
| 2087 | CLASSIC, |
| 2088 | { }, |
| 2089 | { { 1, 1 } }, |
| 2090 | }, |
| 2091 | { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2092 | "LD_IND", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2093 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2094 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2095 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K), |
| 2096 | BPF_STMT(BPF_RET | BPF_K, 1) |
| 2097 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2098 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2099 | { }, |
| 2100 | { { 1, 0 }, { 10, 0 }, { 60, 0 } }, |
| 2101 | }, |
| 2102 | { |
| 2103 | "LD_ABS", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2104 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2105 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000), |
| 2106 | BPF_STMT(BPF_RET | BPF_K, 1) |
| 2107 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2108 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2109 | { }, |
| 2110 | { { 1, 0 }, { 10, 0 }, { 60, 0 } }, |
| 2111 | }, |
| 2112 | { |
| 2113 | "LD_ABS_LL", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2114 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2115 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF), |
| 2116 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2117 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1), |
| 2118 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2119 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2120 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2121 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2122 | { 1, 2, 3 }, |
| 2123 | { { 1, 0 }, { 2, 3 } }, |
| 2124 | }, |
| 2125 | { |
| 2126 | "LD_IND_LL", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2127 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2128 | BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1), |
| 2129 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2130 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2131 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2132 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 2133 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2134 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2135 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2136 | { 1, 2, 3, 0xff }, |
| 2137 | { { 1, 1 }, { 3, 3 }, { 4, 0xff } }, |
| 2138 | }, |
| 2139 | { |
| 2140 | "LD_ABS_NET", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2141 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2142 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF), |
| 2143 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2144 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1), |
| 2145 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2146 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2147 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2148 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2149 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, |
| 2150 | { { 15, 0 }, { 16, 3 } }, |
| 2151 | }, |
| 2152 | { |
| 2153 | "LD_IND_NET", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2154 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2155 | BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15), |
| 2156 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2157 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 2158 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2159 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 2160 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2161 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2162 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2163 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, |
| 2164 | { { 14, 0 }, { 15, 1 }, { 17, 3 } }, |
| 2165 | }, |
| 2166 | { |
| 2167 | "LD_PKTTYPE", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2168 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2169 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2170 | SKF_AD_OFF + SKF_AD_PKTTYPE), |
| 2171 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), |
| 2172 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2173 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2174 | SKF_AD_OFF + SKF_AD_PKTTYPE), |
| 2175 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), |
| 2176 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2177 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2178 | SKF_AD_OFF + SKF_AD_PKTTYPE), |
| 2179 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), |
| 2180 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2181 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2182 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2183 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2184 | { }, |
| 2185 | { { 1, 3 }, { 10, 3 } }, |
| 2186 | }, |
| 2187 | { |
| 2188 | "LD_MARK", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2189 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2190 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2191 | SKF_AD_OFF + SKF_AD_MARK), |
| 2192 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2193 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2194 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2195 | { }, |
| 2196 | { { 1, SKB_MARK}, { 10, SKB_MARK} }, |
| 2197 | }, |
| 2198 | { |
| 2199 | "LD_RXHASH", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2200 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2201 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2202 | SKF_AD_OFF + SKF_AD_RXHASH), |
| 2203 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2204 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2205 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2206 | { }, |
| 2207 | { { 1, SKB_HASH}, { 10, SKB_HASH} }, |
| 2208 | }, |
| 2209 | { |
| 2210 | "LD_QUEUE", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2211 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2212 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2213 | SKF_AD_OFF + SKF_AD_QUEUE), |
| 2214 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2215 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2216 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2217 | { }, |
| 2218 | { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } }, |
| 2219 | }, |
| 2220 | { |
| 2221 | "LD_PROTOCOL", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2222 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2223 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1), |
| 2224 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0), |
| 2225 | BPF_STMT(BPF_RET | BPF_K, 0), |
| 2226 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2227 | SKF_AD_OFF + SKF_AD_PROTOCOL), |
| 2228 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2229 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 2230 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0), |
| 2231 | BPF_STMT(BPF_RET | BPF_K, 0), |
| 2232 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 2233 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2234 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2235 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2236 | { 10, 20, 30 }, |
| 2237 | { { 10, ETH_P_IP }, { 100, ETH_P_IP } }, |
| 2238 | }, |
| 2239 | { |
| 2240 | "LD_VLAN_TAG", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2241 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2242 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2243 | SKF_AD_OFF + SKF_AD_VLAN_TAG), |
| 2244 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2245 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2246 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2247 | { }, |
| 2248 | { |
Michał Mirosław | 0c4b2d3 | 2018-11-10 19:58:36 +0100 | [diff] [blame] | 2249 | { 1, SKB_VLAN_TCI }, |
| 2250 | { 10, SKB_VLAN_TCI } |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2251 | }, |
| 2252 | }, |
| 2253 | { |
| 2254 | "LD_VLAN_TAG_PRESENT", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2255 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2256 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2257 | SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT), |
| 2258 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2259 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2260 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2261 | { }, |
| 2262 | { |
Michał Mirosław | 0c4b2d3 | 2018-11-10 19:58:36 +0100 | [diff] [blame] | 2263 | { 1, SKB_VLAN_PRESENT }, |
| 2264 | { 10, SKB_VLAN_PRESENT } |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2265 | }, |
| 2266 | }, |
| 2267 | { |
| 2268 | "LD_IFINDEX", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2269 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2270 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2271 | SKF_AD_OFF + SKF_AD_IFINDEX), |
| 2272 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2273 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2274 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2275 | { }, |
| 2276 | { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } }, |
| 2277 | }, |
| 2278 | { |
| 2279 | "LD_HATYPE", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2280 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2281 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2282 | SKF_AD_OFF + SKF_AD_HATYPE), |
| 2283 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2284 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2285 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2286 | { }, |
| 2287 | { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } }, |
| 2288 | }, |
| 2289 | { |
| 2290 | "LD_CPU", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2291 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2292 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2293 | SKF_AD_OFF + SKF_AD_CPU), |
| 2294 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2295 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2296 | SKF_AD_OFF + SKF_AD_CPU), |
| 2297 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), |
| 2298 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2299 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2300 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2301 | { }, |
| 2302 | { { 1, 0 }, { 10, 0 } }, |
| 2303 | }, |
| 2304 | { |
| 2305 | "LD_NLATTR", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2306 | .u.insns = { |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2307 | BPF_STMT(BPF_LDX | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2308 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 2309 | BPF_STMT(BPF_LDX | BPF_IMM, 3), |
| 2310 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2311 | SKF_AD_OFF + SKF_AD_NLATTR), |
| 2312 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2313 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2314 | CLASSIC, |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2315 | #ifdef __BIG_ENDIAN |
| 2316 | { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 }, |
| 2317 | #else |
| 2318 | { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 }, |
| 2319 | #endif |
| 2320 | { { 4, 0 }, { 20, 6 } }, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2321 | }, |
| 2322 | { |
| 2323 | "LD_NLATTR_NEST", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2324 | .u.insns = { |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2325 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2326 | BPF_STMT(BPF_LDX | BPF_IMM, 3), |
| 2327 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2328 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2329 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2330 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2331 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2332 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2333 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2334 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2335 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2336 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2337 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2338 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2339 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2340 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2341 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2342 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2343 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2344 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2345 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2346 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2347 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2348 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2349 | SKF_AD_OFF + SKF_AD_NLATTR_NEST), |
| 2350 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2351 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2352 | CLASSIC, |
Alexei Starovoitov | df6d0f983 | 2014-06-06 17:48:20 -0700 | [diff] [blame] | 2353 | #ifdef __BIG_ENDIAN |
| 2354 | { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 }, |
| 2355 | #else |
| 2356 | { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 }, |
| 2357 | #endif |
| 2358 | { { 4, 0 }, { 20, 10 } }, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2359 | }, |
| 2360 | { |
| 2361 | "LD_PAYLOAD_OFF", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2362 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2363 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2364 | SKF_AD_OFF + SKF_AD_PAY_OFFSET), |
| 2365 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2366 | SKF_AD_OFF + SKF_AD_PAY_OFFSET), |
| 2367 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2368 | SKF_AD_OFF + SKF_AD_PAY_OFFSET), |
| 2369 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2370 | SKF_AD_OFF + SKF_AD_PAY_OFFSET), |
| 2371 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2372 | SKF_AD_OFF + SKF_AD_PAY_OFFSET), |
| 2373 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2374 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2375 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2376 | /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800), |
| 2377 | * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request, |
| 2378 | * id 9737, seq 1, length 64 |
| 2379 | */ |
| 2380 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2381 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2382 | 0x08, 0x00, |
| 2383 | 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40, |
| 2384 | 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 }, |
| 2385 | { { 30, 0 }, { 100, 42 } }, |
| 2386 | }, |
| 2387 | { |
| 2388 | "LD_ANC_XOR", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2389 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2390 | BPF_STMT(BPF_LD | BPF_IMM, 10), |
| 2391 | BPF_STMT(BPF_LDX | BPF_IMM, 300), |
| 2392 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 2393 | SKF_AD_OFF + SKF_AD_ALU_XOR_X), |
| 2394 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2395 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2396 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2397 | { }, |
Nathan Chancellor | 0984543 | 2019-08-18 21:34:20 -0700 | [diff] [blame] | 2398 | { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } }, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2399 | }, |
| 2400 | { |
| 2401 | "SPILL_FILL", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2402 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2403 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2404 | BPF_STMT(BPF_LD | BPF_IMM, 2), |
| 2405 | BPF_STMT(BPF_ALU | BPF_RSH, 1), |
| 2406 | BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), |
| 2407 | BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */ |
| 2408 | BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000), |
| 2409 | BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */ |
| 2410 | BPF_STMT(BPF_STX, 15), /* M3 = len */ |
| 2411 | BPF_STMT(BPF_LDX | BPF_MEM, 1), |
| 2412 | BPF_STMT(BPF_LD | BPF_MEM, 2), |
| 2413 | BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), |
| 2414 | BPF_STMT(BPF_LDX | BPF_MEM, 15), |
| 2415 | BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), |
| 2416 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2417 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2418 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2419 | { }, |
| 2420 | { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } } |
| 2421 | }, |
| 2422 | { |
| 2423 | "JEQ", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2424 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2425 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2426 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 2427 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1), |
| 2428 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2429 | BPF_STMT(BPF_RET | BPF_K, MAX_K) |
| 2430 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2431 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2432 | { 3, 3, 3, 3, 3 }, |
| 2433 | { { 1, 0 }, { 3, 1 }, { 4, MAX_K } }, |
| 2434 | }, |
| 2435 | { |
| 2436 | "JGT", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2437 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2438 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2439 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 2440 | BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1), |
| 2441 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2442 | BPF_STMT(BPF_RET | BPF_K, MAX_K) |
| 2443 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2444 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2445 | { 4, 4, 4, 3, 3 }, |
| 2446 | { { 2, 0 }, { 3, 1 }, { 4, MAX_K } }, |
| 2447 | }, |
| 2448 | { |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 2449 | "JGE (jt 0), test 1", |
| 2450 | .u.insns = { |
| 2451 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2452 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 2453 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1), |
| 2454 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2455 | BPF_STMT(BPF_RET | BPF_K, MAX_K) |
| 2456 | }, |
| 2457 | CLASSIC, |
| 2458 | { 4, 4, 4, 3, 3 }, |
| 2459 | { { 2, 0 }, { 3, 1 }, { 4, 1 } }, |
| 2460 | }, |
| 2461 | { |
| 2462 | "JGE (jt 0), test 2", |
| 2463 | .u.insns = { |
| 2464 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2465 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 2466 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1), |
| 2467 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 2468 | BPF_STMT(BPF_RET | BPF_K, MAX_K) |
| 2469 | }, |
| 2470 | CLASSIC, |
| 2471 | { 4, 4, 5, 3, 3 }, |
| 2472 | { { 4, 1 }, { 5, 1 }, { 6, MAX_K } }, |
| 2473 | }, |
| 2474 | { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2475 | "JGE", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2476 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2477 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2478 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K), |
| 2479 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0), |
| 2480 | BPF_STMT(BPF_RET | BPF_K, 10), |
| 2481 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0), |
| 2482 | BPF_STMT(BPF_RET | BPF_K, 20), |
| 2483 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0), |
| 2484 | BPF_STMT(BPF_RET | BPF_K, 30), |
| 2485 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0), |
| 2486 | BPF_STMT(BPF_RET | BPF_K, 40), |
| 2487 | BPF_STMT(BPF_RET | BPF_K, MAX_K) |
| 2488 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2489 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2490 | { 1, 2, 3, 4, 5 }, |
| 2491 | { { 1, 20 }, { 3, 40 }, { 5, MAX_K } }, |
| 2492 | }, |
| 2493 | { |
| 2494 | "JSET", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2495 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2496 | BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), |
| 2497 | BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1), |
| 2498 | BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), |
| 2499 | BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), |
| 2500 | BPF_STMT(BPF_LDX | BPF_LEN, 0), |
| 2501 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 2502 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4), |
| 2503 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 2504 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), |
| 2505 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1), |
| 2506 | BPF_STMT(BPF_RET | BPF_K, 10), |
| 2507 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1), |
| 2508 | BPF_STMT(BPF_RET | BPF_K, 20), |
| 2509 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), |
| 2510 | BPF_STMT(BPF_RET | BPF_K, 30), |
| 2511 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), |
| 2512 | BPF_STMT(BPF_RET | BPF_K, 30), |
| 2513 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), |
| 2514 | BPF_STMT(BPF_RET | BPF_K, 30), |
| 2515 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), |
| 2516 | BPF_STMT(BPF_RET | BPF_K, 30), |
| 2517 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), |
| 2518 | BPF_STMT(BPF_RET | BPF_K, 30), |
| 2519 | BPF_STMT(BPF_RET | BPF_K, MAX_K) |
| 2520 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2521 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2522 | { 0, 0xAA, 0x55, 1 }, |
| 2523 | { { 4, 10 }, { 5, 20 }, { 6, MAX_K } }, |
| 2524 | }, |
| 2525 | { |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 2526 | "tcpdump port 22", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2527 | .u.insns = { |
Daniel Borkmann | ce25b68 | 2014-05-26 20:17:35 +0200 | [diff] [blame] | 2528 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), |
| 2529 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */ |
| 2530 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20), |
| 2531 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), |
| 2532 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), |
| 2533 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17), |
| 2534 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54), |
| 2535 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0), |
| 2536 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56), |
| 2537 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13), |
| 2538 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */ |
| 2539 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), |
| 2540 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), |
| 2541 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), |
| 2542 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8), |
| 2543 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), |
| 2544 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0), |
| 2545 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), |
| 2546 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), |
| 2547 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), |
| 2548 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), |
| 2549 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1), |
| 2550 | BPF_STMT(BPF_RET | BPF_K, 0xffff), |
| 2551 | BPF_STMT(BPF_RET | BPF_K, 0), |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 2552 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2553 | CLASSIC, |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 2554 | /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800) |
| 2555 | * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.], |
| 2556 | * seq 1305692979:1305693027, ack 3650467037, win 65535, |
| 2557 | * options [nop,nop,TS val 2502645400 ecr 3971138], length 48 |
| 2558 | */ |
| 2559 | { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, |
| 2560 | 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, |
| 2561 | 0x08, 0x00, |
| 2562 | 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5, |
| 2563 | 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */ |
| 2564 | 0x0a, 0x01, 0x01, 0x95, /* ip src */ |
| 2565 | 0x0a, 0x01, 0x02, 0x0a, /* ip dst */ |
| 2566 | 0xc2, 0x24, |
| 2567 | 0x00, 0x16 /* dst port */ }, |
| 2568 | { { 10, 0 }, { 30, 0 }, { 100, 65535 } }, |
| 2569 | }, |
| 2570 | { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2571 | "tcpdump complex", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2572 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2573 | /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] - |
| 2574 | * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and |
| 2575 | * (len > 115 or len < 30000000000)' -d |
| 2576 | */ |
Daniel Borkmann | ce25b68 | 2014-05-26 20:17:35 +0200 | [diff] [blame] | 2577 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), |
| 2578 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0), |
| 2579 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29), |
| 2580 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), |
| 2581 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27), |
| 2582 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), |
| 2583 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0), |
| 2584 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), |
| 2585 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), |
| 2586 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), |
| 2587 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), |
| 2588 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20), |
| 2589 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16), |
| 2590 | BPF_STMT(BPF_ST, 1), |
| 2591 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14), |
| 2592 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf), |
| 2593 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2), |
| 2594 | BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */ |
| 2595 | BPF_STMT(BPF_LD | BPF_MEM, 1), |
| 2596 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), |
| 2597 | BPF_STMT(BPF_ST, 5), |
| 2598 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), |
| 2599 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26), |
| 2600 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), |
| 2601 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2), |
| 2602 | BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */ |
| 2603 | BPF_STMT(BPF_LD | BPF_MEM, 5), |
| 2604 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0), |
| 2605 | BPF_STMT(BPF_LD | BPF_LEN, 0), |
| 2606 | BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0), |
| 2607 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0), |
| 2608 | BPF_STMT(BPF_RET | BPF_K, 0xffff), |
| 2609 | BPF_STMT(BPF_RET | BPF_K, 0), |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2610 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2611 | CLASSIC, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2612 | { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, |
| 2613 | 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, |
| 2614 | 0x08, 0x00, |
| 2615 | 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5, |
| 2616 | 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */ |
| 2617 | 0x0a, 0x01, 0x01, 0x95, /* ip src */ |
| 2618 | 0x0a, 0x01, 0x02, 0x0a, /* ip dst */ |
| 2619 | 0xc2, 0x24, |
| 2620 | 0x00, 0x16 /* dst port */ }, |
| 2621 | { { 10, 0 }, { 30, 0 }, { 100, 65535 } }, |
| 2622 | }, |
| 2623 | { |
| 2624 | "RET_A", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2625 | .u.insns = { |
Zhen Lei | 53b0fe3 | 2021-07-07 18:07:28 -0700 | [diff] [blame] | 2626 | /* check that uninitialized X and A contain zeros */ |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2627 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 2628 | BPF_STMT(BPF_RET | BPF_A, 0) |
| 2629 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2630 | CLASSIC, |
| 2631 | { }, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2632 | { {1, 0}, {2, 0} }, |
| 2633 | }, |
| 2634 | { |
| 2635 | "INT: ADD trivial", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2636 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2637 | BPF_ALU64_IMM(BPF_MOV, R1, 1), |
| 2638 | BPF_ALU64_IMM(BPF_ADD, R1, 2), |
| 2639 | BPF_ALU64_IMM(BPF_MOV, R2, 3), |
| 2640 | BPF_ALU64_REG(BPF_SUB, R1, R2), |
| 2641 | BPF_ALU64_IMM(BPF_ADD, R1, -1), |
| 2642 | BPF_ALU64_IMM(BPF_MUL, R1, 3), |
| 2643 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 2644 | BPF_EXIT_INSN(), |
| 2645 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2646 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2647 | { }, |
| 2648 | { { 0, 0xfffffffd } } |
| 2649 | }, |
| 2650 | { |
| 2651 | "INT: MUL_X", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2652 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2653 | BPF_ALU64_IMM(BPF_MOV, R0, -1), |
| 2654 | BPF_ALU64_IMM(BPF_MOV, R1, -1), |
| 2655 | BPF_ALU64_IMM(BPF_MOV, R2, 3), |
| 2656 | BPF_ALU64_REG(BPF_MUL, R1, R2), |
| 2657 | BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1), |
| 2658 | BPF_EXIT_INSN(), |
| 2659 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 2660 | BPF_EXIT_INSN(), |
| 2661 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2662 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2663 | { }, |
| 2664 | { { 0, 1 } } |
| 2665 | }, |
| 2666 | { |
| 2667 | "INT: MUL_X2", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2668 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2669 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 2670 | BPF_ALU32_IMM(BPF_MOV, R1, -1), |
| 2671 | BPF_ALU32_IMM(BPF_MOV, R2, 3), |
| 2672 | BPF_ALU64_REG(BPF_MUL, R1, R2), |
| 2673 | BPF_ALU64_IMM(BPF_RSH, R1, 8), |
| 2674 | BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1), |
| 2675 | BPF_EXIT_INSN(), |
| 2676 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 2677 | BPF_EXIT_INSN(), |
| 2678 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2679 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2680 | { }, |
| 2681 | { { 0, 1 } } |
| 2682 | }, |
| 2683 | { |
| 2684 | "INT: MUL32_X", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2685 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2686 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 2687 | BPF_ALU64_IMM(BPF_MOV, R1, -1), |
| 2688 | BPF_ALU32_IMM(BPF_MOV, R2, 3), |
| 2689 | BPF_ALU32_REG(BPF_MUL, R1, R2), |
| 2690 | BPF_ALU64_IMM(BPF_RSH, R1, 8), |
| 2691 | BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1), |
| 2692 | BPF_EXIT_INSN(), |
| 2693 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 2694 | BPF_EXIT_INSN(), |
| 2695 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2696 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2697 | { }, |
| 2698 | { { 0, 1 } } |
| 2699 | }, |
| 2700 | { |
| 2701 | /* Have to test all register combinations, since |
| 2702 | * JITing of different registers will produce |
| 2703 | * different asm code. |
| 2704 | */ |
| 2705 | "INT: ADD 64-bit", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2706 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2707 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 2708 | BPF_ALU64_IMM(BPF_MOV, R1, 1), |
| 2709 | BPF_ALU64_IMM(BPF_MOV, R2, 2), |
| 2710 | BPF_ALU64_IMM(BPF_MOV, R3, 3), |
| 2711 | BPF_ALU64_IMM(BPF_MOV, R4, 4), |
| 2712 | BPF_ALU64_IMM(BPF_MOV, R5, 5), |
| 2713 | BPF_ALU64_IMM(BPF_MOV, R6, 6), |
| 2714 | BPF_ALU64_IMM(BPF_MOV, R7, 7), |
| 2715 | BPF_ALU64_IMM(BPF_MOV, R8, 8), |
| 2716 | BPF_ALU64_IMM(BPF_MOV, R9, 9), |
| 2717 | BPF_ALU64_IMM(BPF_ADD, R0, 20), |
| 2718 | BPF_ALU64_IMM(BPF_ADD, R1, 20), |
| 2719 | BPF_ALU64_IMM(BPF_ADD, R2, 20), |
| 2720 | BPF_ALU64_IMM(BPF_ADD, R3, 20), |
| 2721 | BPF_ALU64_IMM(BPF_ADD, R4, 20), |
| 2722 | BPF_ALU64_IMM(BPF_ADD, R5, 20), |
| 2723 | BPF_ALU64_IMM(BPF_ADD, R6, 20), |
| 2724 | BPF_ALU64_IMM(BPF_ADD, R7, 20), |
| 2725 | BPF_ALU64_IMM(BPF_ADD, R8, 20), |
| 2726 | BPF_ALU64_IMM(BPF_ADD, R9, 20), |
| 2727 | BPF_ALU64_IMM(BPF_SUB, R0, 10), |
| 2728 | BPF_ALU64_IMM(BPF_SUB, R1, 10), |
| 2729 | BPF_ALU64_IMM(BPF_SUB, R2, 10), |
| 2730 | BPF_ALU64_IMM(BPF_SUB, R3, 10), |
| 2731 | BPF_ALU64_IMM(BPF_SUB, R4, 10), |
| 2732 | BPF_ALU64_IMM(BPF_SUB, R5, 10), |
| 2733 | BPF_ALU64_IMM(BPF_SUB, R6, 10), |
| 2734 | BPF_ALU64_IMM(BPF_SUB, R7, 10), |
| 2735 | BPF_ALU64_IMM(BPF_SUB, R8, 10), |
| 2736 | BPF_ALU64_IMM(BPF_SUB, R9, 10), |
| 2737 | BPF_ALU64_REG(BPF_ADD, R0, R0), |
| 2738 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 2739 | BPF_ALU64_REG(BPF_ADD, R0, R2), |
| 2740 | BPF_ALU64_REG(BPF_ADD, R0, R3), |
| 2741 | BPF_ALU64_REG(BPF_ADD, R0, R4), |
| 2742 | BPF_ALU64_REG(BPF_ADD, R0, R5), |
| 2743 | BPF_ALU64_REG(BPF_ADD, R0, R6), |
| 2744 | BPF_ALU64_REG(BPF_ADD, R0, R7), |
| 2745 | BPF_ALU64_REG(BPF_ADD, R0, R8), |
| 2746 | BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */ |
| 2747 | BPF_JMP_IMM(BPF_JEQ, R0, 155, 1), |
| 2748 | BPF_EXIT_INSN(), |
| 2749 | BPF_ALU64_REG(BPF_ADD, R1, R0), |
| 2750 | BPF_ALU64_REG(BPF_ADD, R1, R1), |
| 2751 | BPF_ALU64_REG(BPF_ADD, R1, R2), |
| 2752 | BPF_ALU64_REG(BPF_ADD, R1, R3), |
| 2753 | BPF_ALU64_REG(BPF_ADD, R1, R4), |
| 2754 | BPF_ALU64_REG(BPF_ADD, R1, R5), |
| 2755 | BPF_ALU64_REG(BPF_ADD, R1, R6), |
| 2756 | BPF_ALU64_REG(BPF_ADD, R1, R7), |
| 2757 | BPF_ALU64_REG(BPF_ADD, R1, R8), |
| 2758 | BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */ |
| 2759 | BPF_JMP_IMM(BPF_JEQ, R1, 456, 1), |
| 2760 | BPF_EXIT_INSN(), |
| 2761 | BPF_ALU64_REG(BPF_ADD, R2, R0), |
| 2762 | BPF_ALU64_REG(BPF_ADD, R2, R1), |
| 2763 | BPF_ALU64_REG(BPF_ADD, R2, R2), |
| 2764 | BPF_ALU64_REG(BPF_ADD, R2, R3), |
| 2765 | BPF_ALU64_REG(BPF_ADD, R2, R4), |
| 2766 | BPF_ALU64_REG(BPF_ADD, R2, R5), |
| 2767 | BPF_ALU64_REG(BPF_ADD, R2, R6), |
| 2768 | BPF_ALU64_REG(BPF_ADD, R2, R7), |
| 2769 | BPF_ALU64_REG(BPF_ADD, R2, R8), |
| 2770 | BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */ |
| 2771 | BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1), |
| 2772 | BPF_EXIT_INSN(), |
| 2773 | BPF_ALU64_REG(BPF_ADD, R3, R0), |
| 2774 | BPF_ALU64_REG(BPF_ADD, R3, R1), |
| 2775 | BPF_ALU64_REG(BPF_ADD, R3, R2), |
| 2776 | BPF_ALU64_REG(BPF_ADD, R3, R3), |
| 2777 | BPF_ALU64_REG(BPF_ADD, R3, R4), |
| 2778 | BPF_ALU64_REG(BPF_ADD, R3, R5), |
| 2779 | BPF_ALU64_REG(BPF_ADD, R3, R6), |
| 2780 | BPF_ALU64_REG(BPF_ADD, R3, R7), |
| 2781 | BPF_ALU64_REG(BPF_ADD, R3, R8), |
| 2782 | BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */ |
| 2783 | BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1), |
| 2784 | BPF_EXIT_INSN(), |
| 2785 | BPF_ALU64_REG(BPF_ADD, R4, R0), |
| 2786 | BPF_ALU64_REG(BPF_ADD, R4, R1), |
| 2787 | BPF_ALU64_REG(BPF_ADD, R4, R2), |
| 2788 | BPF_ALU64_REG(BPF_ADD, R4, R3), |
| 2789 | BPF_ALU64_REG(BPF_ADD, R4, R4), |
| 2790 | BPF_ALU64_REG(BPF_ADD, R4, R5), |
| 2791 | BPF_ALU64_REG(BPF_ADD, R4, R6), |
| 2792 | BPF_ALU64_REG(BPF_ADD, R4, R7), |
| 2793 | BPF_ALU64_REG(BPF_ADD, R4, R8), |
| 2794 | BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */ |
| 2795 | BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1), |
| 2796 | BPF_EXIT_INSN(), |
| 2797 | BPF_ALU64_REG(BPF_ADD, R5, R0), |
| 2798 | BPF_ALU64_REG(BPF_ADD, R5, R1), |
| 2799 | BPF_ALU64_REG(BPF_ADD, R5, R2), |
| 2800 | BPF_ALU64_REG(BPF_ADD, R5, R3), |
| 2801 | BPF_ALU64_REG(BPF_ADD, R5, R4), |
| 2802 | BPF_ALU64_REG(BPF_ADD, R5, R5), |
| 2803 | BPF_ALU64_REG(BPF_ADD, R5, R6), |
| 2804 | BPF_ALU64_REG(BPF_ADD, R5, R7), |
| 2805 | BPF_ALU64_REG(BPF_ADD, R5, R8), |
| 2806 | BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */ |
| 2807 | BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1), |
| 2808 | BPF_EXIT_INSN(), |
| 2809 | BPF_ALU64_REG(BPF_ADD, R6, R0), |
| 2810 | BPF_ALU64_REG(BPF_ADD, R6, R1), |
| 2811 | BPF_ALU64_REG(BPF_ADD, R6, R2), |
| 2812 | BPF_ALU64_REG(BPF_ADD, R6, R3), |
| 2813 | BPF_ALU64_REG(BPF_ADD, R6, R4), |
| 2814 | BPF_ALU64_REG(BPF_ADD, R6, R5), |
| 2815 | BPF_ALU64_REG(BPF_ADD, R6, R6), |
| 2816 | BPF_ALU64_REG(BPF_ADD, R6, R7), |
| 2817 | BPF_ALU64_REG(BPF_ADD, R6, R8), |
| 2818 | BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */ |
| 2819 | BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1), |
| 2820 | BPF_EXIT_INSN(), |
| 2821 | BPF_ALU64_REG(BPF_ADD, R7, R0), |
| 2822 | BPF_ALU64_REG(BPF_ADD, R7, R1), |
| 2823 | BPF_ALU64_REG(BPF_ADD, R7, R2), |
| 2824 | BPF_ALU64_REG(BPF_ADD, R7, R3), |
| 2825 | BPF_ALU64_REG(BPF_ADD, R7, R4), |
| 2826 | BPF_ALU64_REG(BPF_ADD, R7, R5), |
| 2827 | BPF_ALU64_REG(BPF_ADD, R7, R6), |
| 2828 | BPF_ALU64_REG(BPF_ADD, R7, R7), |
| 2829 | BPF_ALU64_REG(BPF_ADD, R7, R8), |
| 2830 | BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */ |
| 2831 | BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1), |
| 2832 | BPF_EXIT_INSN(), |
| 2833 | BPF_ALU64_REG(BPF_ADD, R8, R0), |
| 2834 | BPF_ALU64_REG(BPF_ADD, R8, R1), |
| 2835 | BPF_ALU64_REG(BPF_ADD, R8, R2), |
| 2836 | BPF_ALU64_REG(BPF_ADD, R8, R3), |
| 2837 | BPF_ALU64_REG(BPF_ADD, R8, R4), |
| 2838 | BPF_ALU64_REG(BPF_ADD, R8, R5), |
| 2839 | BPF_ALU64_REG(BPF_ADD, R8, R6), |
| 2840 | BPF_ALU64_REG(BPF_ADD, R8, R7), |
| 2841 | BPF_ALU64_REG(BPF_ADD, R8, R8), |
| 2842 | BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */ |
| 2843 | BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1), |
| 2844 | BPF_EXIT_INSN(), |
| 2845 | BPF_ALU64_REG(BPF_ADD, R9, R0), |
| 2846 | BPF_ALU64_REG(BPF_ADD, R9, R1), |
| 2847 | BPF_ALU64_REG(BPF_ADD, R9, R2), |
| 2848 | BPF_ALU64_REG(BPF_ADD, R9, R3), |
| 2849 | BPF_ALU64_REG(BPF_ADD, R9, R4), |
| 2850 | BPF_ALU64_REG(BPF_ADD, R9, R5), |
| 2851 | BPF_ALU64_REG(BPF_ADD, R9, R6), |
| 2852 | BPF_ALU64_REG(BPF_ADD, R9, R7), |
| 2853 | BPF_ALU64_REG(BPF_ADD, R9, R8), |
| 2854 | BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */ |
| 2855 | BPF_ALU64_REG(BPF_MOV, R0, R9), |
| 2856 | BPF_EXIT_INSN(), |
| 2857 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 2858 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2859 | { }, |
| 2860 | { { 0, 2957380 } } |
| 2861 | }, |
| 2862 | { |
| 2863 | "INT: ADD 32-bit", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 2864 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 2865 | BPF_ALU32_IMM(BPF_MOV, R0, 20), |
| 2866 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 2867 | BPF_ALU32_IMM(BPF_MOV, R2, 2), |
| 2868 | BPF_ALU32_IMM(BPF_MOV, R3, 3), |
| 2869 | BPF_ALU32_IMM(BPF_MOV, R4, 4), |
| 2870 | BPF_ALU32_IMM(BPF_MOV, R5, 5), |
| 2871 | BPF_ALU32_IMM(BPF_MOV, R6, 6), |
| 2872 | BPF_ALU32_IMM(BPF_MOV, R7, 7), |
| 2873 | BPF_ALU32_IMM(BPF_MOV, R8, 8), |
| 2874 | BPF_ALU32_IMM(BPF_MOV, R9, 9), |
| 2875 | BPF_ALU64_IMM(BPF_ADD, R1, 10), |
| 2876 | BPF_ALU64_IMM(BPF_ADD, R2, 10), |
| 2877 | BPF_ALU64_IMM(BPF_ADD, R3, 10), |
| 2878 | BPF_ALU64_IMM(BPF_ADD, R4, 10), |
| 2879 | BPF_ALU64_IMM(BPF_ADD, R5, 10), |
| 2880 | BPF_ALU64_IMM(BPF_ADD, R6, 10), |
| 2881 | BPF_ALU64_IMM(BPF_ADD, R7, 10), |
| 2882 | BPF_ALU64_IMM(BPF_ADD, R8, 10), |
| 2883 | BPF_ALU64_IMM(BPF_ADD, R9, 10), |
| 2884 | BPF_ALU32_REG(BPF_ADD, R0, R1), |
| 2885 | BPF_ALU32_REG(BPF_ADD, R0, R2), |
| 2886 | BPF_ALU32_REG(BPF_ADD, R0, R3), |
| 2887 | BPF_ALU32_REG(BPF_ADD, R0, R4), |
| 2888 | BPF_ALU32_REG(BPF_ADD, R0, R5), |
| 2889 | BPF_ALU32_REG(BPF_ADD, R0, R6), |
| 2890 | BPF_ALU32_REG(BPF_ADD, R0, R7), |
| 2891 | BPF_ALU32_REG(BPF_ADD, R0, R8), |
| 2892 | BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */ |
| 2893 | BPF_JMP_IMM(BPF_JEQ, R0, 155, 1), |
| 2894 | BPF_EXIT_INSN(), |
| 2895 | BPF_ALU32_REG(BPF_ADD, R1, R0), |
| 2896 | BPF_ALU32_REG(BPF_ADD, R1, R1), |
| 2897 | BPF_ALU32_REG(BPF_ADD, R1, R2), |
| 2898 | BPF_ALU32_REG(BPF_ADD, R1, R3), |
| 2899 | BPF_ALU32_REG(BPF_ADD, R1, R4), |
| 2900 | BPF_ALU32_REG(BPF_ADD, R1, R5), |
| 2901 | BPF_ALU32_REG(BPF_ADD, R1, R6), |
| 2902 | BPF_ALU32_REG(BPF_ADD, R1, R7), |
| 2903 | BPF_ALU32_REG(BPF_ADD, R1, R8), |
| 2904 | BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */ |
| 2905 | BPF_JMP_IMM(BPF_JEQ, R1, 456, 1), |
| 2906 | BPF_EXIT_INSN(), |
| 2907 | BPF_ALU32_REG(BPF_ADD, R2, R0), |
| 2908 | BPF_ALU32_REG(BPF_ADD, R2, R1), |
| 2909 | BPF_ALU32_REG(BPF_ADD, R2, R2), |
| 2910 | BPF_ALU32_REG(BPF_ADD, R2, R3), |
| 2911 | BPF_ALU32_REG(BPF_ADD, R2, R4), |
| 2912 | BPF_ALU32_REG(BPF_ADD, R2, R5), |
| 2913 | BPF_ALU32_REG(BPF_ADD, R2, R6), |
| 2914 | BPF_ALU32_REG(BPF_ADD, R2, R7), |
| 2915 | BPF_ALU32_REG(BPF_ADD, R2, R8), |
| 2916 | BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */ |
| 2917 | BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1), |
| 2918 | BPF_EXIT_INSN(), |
| 2919 | BPF_ALU32_REG(BPF_ADD, R3, R0), |
| 2920 | BPF_ALU32_REG(BPF_ADD, R3, R1), |
| 2921 | BPF_ALU32_REG(BPF_ADD, R3, R2), |
| 2922 | BPF_ALU32_REG(BPF_ADD, R3, R3), |
| 2923 | BPF_ALU32_REG(BPF_ADD, R3, R4), |
| 2924 | BPF_ALU32_REG(BPF_ADD, R3, R5), |
| 2925 | BPF_ALU32_REG(BPF_ADD, R3, R6), |
| 2926 | BPF_ALU32_REG(BPF_ADD, R3, R7), |
| 2927 | BPF_ALU32_REG(BPF_ADD, R3, R8), |
| 2928 | BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */ |
| 2929 | BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1), |
| 2930 | BPF_EXIT_INSN(), |
| 2931 | BPF_ALU32_REG(BPF_ADD, R4, R0), |
| 2932 | BPF_ALU32_REG(BPF_ADD, R4, R1), |
| 2933 | BPF_ALU32_REG(BPF_ADD, R4, R2), |
| 2934 | BPF_ALU32_REG(BPF_ADD, R4, R3), |
| 2935 | BPF_ALU32_REG(BPF_ADD, R4, R4), |
| 2936 | BPF_ALU32_REG(BPF_ADD, R4, R5), |
| 2937 | BPF_ALU32_REG(BPF_ADD, R4, R6), |
| 2938 | BPF_ALU32_REG(BPF_ADD, R4, R7), |
| 2939 | BPF_ALU32_REG(BPF_ADD, R4, R8), |
| 2940 | BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */ |
| 2941 | BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1), |
| 2942 | BPF_EXIT_INSN(), |
| 2943 | BPF_ALU32_REG(BPF_ADD, R5, R0), |
| 2944 | BPF_ALU32_REG(BPF_ADD, R5, R1), |
| 2945 | BPF_ALU32_REG(BPF_ADD, R5, R2), |
| 2946 | BPF_ALU32_REG(BPF_ADD, R5, R3), |
| 2947 | BPF_ALU32_REG(BPF_ADD, R5, R4), |
| 2948 | BPF_ALU32_REG(BPF_ADD, R5, R5), |
| 2949 | BPF_ALU32_REG(BPF_ADD, R5, R6), |
| 2950 | BPF_ALU32_REG(BPF_ADD, R5, R7), |
| 2951 | BPF_ALU32_REG(BPF_ADD, R5, R8), |
| 2952 | BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */ |
| 2953 | BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1), |
| 2954 | BPF_EXIT_INSN(), |
| 2955 | BPF_ALU32_REG(BPF_ADD, R6, R0), |
| 2956 | BPF_ALU32_REG(BPF_ADD, R6, R1), |
| 2957 | BPF_ALU32_REG(BPF_ADD, R6, R2), |
| 2958 | BPF_ALU32_REG(BPF_ADD, R6, R3), |
| 2959 | BPF_ALU32_REG(BPF_ADD, R6, R4), |
| 2960 | BPF_ALU32_REG(BPF_ADD, R6, R5), |
| 2961 | BPF_ALU32_REG(BPF_ADD, R6, R6), |
| 2962 | BPF_ALU32_REG(BPF_ADD, R6, R7), |
| 2963 | BPF_ALU32_REG(BPF_ADD, R6, R8), |
| 2964 | BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */ |
| 2965 | BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1), |
| 2966 | BPF_EXIT_INSN(), |
| 2967 | BPF_ALU32_REG(BPF_ADD, R7, R0), |
| 2968 | BPF_ALU32_REG(BPF_ADD, R7, R1), |
| 2969 | BPF_ALU32_REG(BPF_ADD, R7, R2), |
| 2970 | BPF_ALU32_REG(BPF_ADD, R7, R3), |
| 2971 | BPF_ALU32_REG(BPF_ADD, R7, R4), |
| 2972 | BPF_ALU32_REG(BPF_ADD, R7, R5), |
| 2973 | BPF_ALU32_REG(BPF_ADD, R7, R6), |
| 2974 | BPF_ALU32_REG(BPF_ADD, R7, R7), |
| 2975 | BPF_ALU32_REG(BPF_ADD, R7, R8), |
| 2976 | BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */ |
| 2977 | BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1), |
| 2978 | BPF_EXIT_INSN(), |
| 2979 | BPF_ALU32_REG(BPF_ADD, R8, R0), |
| 2980 | BPF_ALU32_REG(BPF_ADD, R8, R1), |
| 2981 | BPF_ALU32_REG(BPF_ADD, R8, R2), |
| 2982 | BPF_ALU32_REG(BPF_ADD, R8, R3), |
| 2983 | BPF_ALU32_REG(BPF_ADD, R8, R4), |
| 2984 | BPF_ALU32_REG(BPF_ADD, R8, R5), |
| 2985 | BPF_ALU32_REG(BPF_ADD, R8, R6), |
| 2986 | BPF_ALU32_REG(BPF_ADD, R8, R7), |
| 2987 | BPF_ALU32_REG(BPF_ADD, R8, R8), |
| 2988 | BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */ |
| 2989 | BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1), |
| 2990 | BPF_EXIT_INSN(), |
| 2991 | BPF_ALU32_REG(BPF_ADD, R9, R0), |
| 2992 | BPF_ALU32_REG(BPF_ADD, R9, R1), |
| 2993 | BPF_ALU32_REG(BPF_ADD, R9, R2), |
| 2994 | BPF_ALU32_REG(BPF_ADD, R9, R3), |
| 2995 | BPF_ALU32_REG(BPF_ADD, R9, R4), |
| 2996 | BPF_ALU32_REG(BPF_ADD, R9, R5), |
| 2997 | BPF_ALU32_REG(BPF_ADD, R9, R6), |
| 2998 | BPF_ALU32_REG(BPF_ADD, R9, R7), |
| 2999 | BPF_ALU32_REG(BPF_ADD, R9, R8), |
| 3000 | BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */ |
| 3001 | BPF_ALU32_REG(BPF_MOV, R0, R9), |
| 3002 | BPF_EXIT_INSN(), |
| 3003 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3004 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3005 | { }, |
| 3006 | { { 0, 2957380 } } |
| 3007 | }, |
| 3008 | { /* Mainly checking JIT here. */ |
| 3009 | "INT: SUB", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3010 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3011 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 3012 | BPF_ALU64_IMM(BPF_MOV, R1, 1), |
| 3013 | BPF_ALU64_IMM(BPF_MOV, R2, 2), |
| 3014 | BPF_ALU64_IMM(BPF_MOV, R3, 3), |
| 3015 | BPF_ALU64_IMM(BPF_MOV, R4, 4), |
| 3016 | BPF_ALU64_IMM(BPF_MOV, R5, 5), |
| 3017 | BPF_ALU64_IMM(BPF_MOV, R6, 6), |
| 3018 | BPF_ALU64_IMM(BPF_MOV, R7, 7), |
| 3019 | BPF_ALU64_IMM(BPF_MOV, R8, 8), |
| 3020 | BPF_ALU64_IMM(BPF_MOV, R9, 9), |
| 3021 | BPF_ALU64_REG(BPF_SUB, R0, R0), |
| 3022 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 3023 | BPF_ALU64_REG(BPF_SUB, R0, R2), |
| 3024 | BPF_ALU64_REG(BPF_SUB, R0, R3), |
| 3025 | BPF_ALU64_REG(BPF_SUB, R0, R4), |
| 3026 | BPF_ALU64_REG(BPF_SUB, R0, R5), |
| 3027 | BPF_ALU64_REG(BPF_SUB, R0, R6), |
| 3028 | BPF_ALU64_REG(BPF_SUB, R0, R7), |
| 3029 | BPF_ALU64_REG(BPF_SUB, R0, R8), |
| 3030 | BPF_ALU64_REG(BPF_SUB, R0, R9), |
| 3031 | BPF_ALU64_IMM(BPF_SUB, R0, 10), |
| 3032 | BPF_JMP_IMM(BPF_JEQ, R0, -55, 1), |
| 3033 | BPF_EXIT_INSN(), |
| 3034 | BPF_ALU64_REG(BPF_SUB, R1, R0), |
| 3035 | BPF_ALU64_REG(BPF_SUB, R1, R2), |
| 3036 | BPF_ALU64_REG(BPF_SUB, R1, R3), |
| 3037 | BPF_ALU64_REG(BPF_SUB, R1, R4), |
| 3038 | BPF_ALU64_REG(BPF_SUB, R1, R5), |
| 3039 | BPF_ALU64_REG(BPF_SUB, R1, R6), |
| 3040 | BPF_ALU64_REG(BPF_SUB, R1, R7), |
| 3041 | BPF_ALU64_REG(BPF_SUB, R1, R8), |
| 3042 | BPF_ALU64_REG(BPF_SUB, R1, R9), |
| 3043 | BPF_ALU64_IMM(BPF_SUB, R1, 10), |
| 3044 | BPF_ALU64_REG(BPF_SUB, R2, R0), |
| 3045 | BPF_ALU64_REG(BPF_SUB, R2, R1), |
| 3046 | BPF_ALU64_REG(BPF_SUB, R2, R3), |
| 3047 | BPF_ALU64_REG(BPF_SUB, R2, R4), |
| 3048 | BPF_ALU64_REG(BPF_SUB, R2, R5), |
| 3049 | BPF_ALU64_REG(BPF_SUB, R2, R6), |
| 3050 | BPF_ALU64_REG(BPF_SUB, R2, R7), |
| 3051 | BPF_ALU64_REG(BPF_SUB, R2, R8), |
| 3052 | BPF_ALU64_REG(BPF_SUB, R2, R9), |
| 3053 | BPF_ALU64_IMM(BPF_SUB, R2, 10), |
| 3054 | BPF_ALU64_REG(BPF_SUB, R3, R0), |
| 3055 | BPF_ALU64_REG(BPF_SUB, R3, R1), |
| 3056 | BPF_ALU64_REG(BPF_SUB, R3, R2), |
| 3057 | BPF_ALU64_REG(BPF_SUB, R3, R4), |
| 3058 | BPF_ALU64_REG(BPF_SUB, R3, R5), |
| 3059 | BPF_ALU64_REG(BPF_SUB, R3, R6), |
| 3060 | BPF_ALU64_REG(BPF_SUB, R3, R7), |
| 3061 | BPF_ALU64_REG(BPF_SUB, R3, R8), |
| 3062 | BPF_ALU64_REG(BPF_SUB, R3, R9), |
| 3063 | BPF_ALU64_IMM(BPF_SUB, R3, 10), |
| 3064 | BPF_ALU64_REG(BPF_SUB, R4, R0), |
| 3065 | BPF_ALU64_REG(BPF_SUB, R4, R1), |
| 3066 | BPF_ALU64_REG(BPF_SUB, R4, R2), |
| 3067 | BPF_ALU64_REG(BPF_SUB, R4, R3), |
| 3068 | BPF_ALU64_REG(BPF_SUB, R4, R5), |
| 3069 | BPF_ALU64_REG(BPF_SUB, R4, R6), |
| 3070 | BPF_ALU64_REG(BPF_SUB, R4, R7), |
| 3071 | BPF_ALU64_REG(BPF_SUB, R4, R8), |
| 3072 | BPF_ALU64_REG(BPF_SUB, R4, R9), |
| 3073 | BPF_ALU64_IMM(BPF_SUB, R4, 10), |
| 3074 | BPF_ALU64_REG(BPF_SUB, R5, R0), |
| 3075 | BPF_ALU64_REG(BPF_SUB, R5, R1), |
| 3076 | BPF_ALU64_REG(BPF_SUB, R5, R2), |
| 3077 | BPF_ALU64_REG(BPF_SUB, R5, R3), |
| 3078 | BPF_ALU64_REG(BPF_SUB, R5, R4), |
| 3079 | BPF_ALU64_REG(BPF_SUB, R5, R6), |
| 3080 | BPF_ALU64_REG(BPF_SUB, R5, R7), |
| 3081 | BPF_ALU64_REG(BPF_SUB, R5, R8), |
| 3082 | BPF_ALU64_REG(BPF_SUB, R5, R9), |
| 3083 | BPF_ALU64_IMM(BPF_SUB, R5, 10), |
| 3084 | BPF_ALU64_REG(BPF_SUB, R6, R0), |
| 3085 | BPF_ALU64_REG(BPF_SUB, R6, R1), |
| 3086 | BPF_ALU64_REG(BPF_SUB, R6, R2), |
| 3087 | BPF_ALU64_REG(BPF_SUB, R6, R3), |
| 3088 | BPF_ALU64_REG(BPF_SUB, R6, R4), |
| 3089 | BPF_ALU64_REG(BPF_SUB, R6, R5), |
| 3090 | BPF_ALU64_REG(BPF_SUB, R6, R7), |
| 3091 | BPF_ALU64_REG(BPF_SUB, R6, R8), |
| 3092 | BPF_ALU64_REG(BPF_SUB, R6, R9), |
| 3093 | BPF_ALU64_IMM(BPF_SUB, R6, 10), |
| 3094 | BPF_ALU64_REG(BPF_SUB, R7, R0), |
| 3095 | BPF_ALU64_REG(BPF_SUB, R7, R1), |
| 3096 | BPF_ALU64_REG(BPF_SUB, R7, R2), |
| 3097 | BPF_ALU64_REG(BPF_SUB, R7, R3), |
| 3098 | BPF_ALU64_REG(BPF_SUB, R7, R4), |
| 3099 | BPF_ALU64_REG(BPF_SUB, R7, R5), |
| 3100 | BPF_ALU64_REG(BPF_SUB, R7, R6), |
| 3101 | BPF_ALU64_REG(BPF_SUB, R7, R8), |
| 3102 | BPF_ALU64_REG(BPF_SUB, R7, R9), |
| 3103 | BPF_ALU64_IMM(BPF_SUB, R7, 10), |
| 3104 | BPF_ALU64_REG(BPF_SUB, R8, R0), |
| 3105 | BPF_ALU64_REG(BPF_SUB, R8, R1), |
| 3106 | BPF_ALU64_REG(BPF_SUB, R8, R2), |
| 3107 | BPF_ALU64_REG(BPF_SUB, R8, R3), |
| 3108 | BPF_ALU64_REG(BPF_SUB, R8, R4), |
| 3109 | BPF_ALU64_REG(BPF_SUB, R8, R5), |
| 3110 | BPF_ALU64_REG(BPF_SUB, R8, R6), |
| 3111 | BPF_ALU64_REG(BPF_SUB, R8, R7), |
| 3112 | BPF_ALU64_REG(BPF_SUB, R8, R9), |
| 3113 | BPF_ALU64_IMM(BPF_SUB, R8, 10), |
| 3114 | BPF_ALU64_REG(BPF_SUB, R9, R0), |
| 3115 | BPF_ALU64_REG(BPF_SUB, R9, R1), |
| 3116 | BPF_ALU64_REG(BPF_SUB, R9, R2), |
| 3117 | BPF_ALU64_REG(BPF_SUB, R9, R3), |
| 3118 | BPF_ALU64_REG(BPF_SUB, R9, R4), |
| 3119 | BPF_ALU64_REG(BPF_SUB, R9, R5), |
| 3120 | BPF_ALU64_REG(BPF_SUB, R9, R6), |
| 3121 | BPF_ALU64_REG(BPF_SUB, R9, R7), |
| 3122 | BPF_ALU64_REG(BPF_SUB, R9, R8), |
| 3123 | BPF_ALU64_IMM(BPF_SUB, R9, 10), |
| 3124 | BPF_ALU64_IMM(BPF_SUB, R0, 10), |
| 3125 | BPF_ALU64_IMM(BPF_NEG, R0, 0), |
| 3126 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 3127 | BPF_ALU64_REG(BPF_SUB, R0, R2), |
| 3128 | BPF_ALU64_REG(BPF_SUB, R0, R3), |
| 3129 | BPF_ALU64_REG(BPF_SUB, R0, R4), |
| 3130 | BPF_ALU64_REG(BPF_SUB, R0, R5), |
| 3131 | BPF_ALU64_REG(BPF_SUB, R0, R6), |
| 3132 | BPF_ALU64_REG(BPF_SUB, R0, R7), |
| 3133 | BPF_ALU64_REG(BPF_SUB, R0, R8), |
| 3134 | BPF_ALU64_REG(BPF_SUB, R0, R9), |
| 3135 | BPF_EXIT_INSN(), |
| 3136 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3137 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3138 | { }, |
| 3139 | { { 0, 11 } } |
| 3140 | }, |
| 3141 | { /* Mainly checking JIT here. */ |
| 3142 | "INT: XOR", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3143 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3144 | BPF_ALU64_REG(BPF_SUB, R0, R0), |
| 3145 | BPF_ALU64_REG(BPF_XOR, R1, R1), |
| 3146 | BPF_JMP_REG(BPF_JEQ, R0, R1, 1), |
| 3147 | BPF_EXIT_INSN(), |
| 3148 | BPF_ALU64_IMM(BPF_MOV, R0, 10), |
| 3149 | BPF_ALU64_IMM(BPF_MOV, R1, -1), |
| 3150 | BPF_ALU64_REG(BPF_SUB, R1, R1), |
| 3151 | BPF_ALU64_REG(BPF_XOR, R2, R2), |
| 3152 | BPF_JMP_REG(BPF_JEQ, R1, R2, 1), |
| 3153 | BPF_EXIT_INSN(), |
| 3154 | BPF_ALU64_REG(BPF_SUB, R2, R2), |
| 3155 | BPF_ALU64_REG(BPF_XOR, R3, R3), |
| 3156 | BPF_ALU64_IMM(BPF_MOV, R0, 10), |
| 3157 | BPF_ALU64_IMM(BPF_MOV, R1, -1), |
| 3158 | BPF_JMP_REG(BPF_JEQ, R2, R3, 1), |
| 3159 | BPF_EXIT_INSN(), |
| 3160 | BPF_ALU64_REG(BPF_SUB, R3, R3), |
| 3161 | BPF_ALU64_REG(BPF_XOR, R4, R4), |
| 3162 | BPF_ALU64_IMM(BPF_MOV, R2, 1), |
| 3163 | BPF_ALU64_IMM(BPF_MOV, R5, -1), |
| 3164 | BPF_JMP_REG(BPF_JEQ, R3, R4, 1), |
| 3165 | BPF_EXIT_INSN(), |
| 3166 | BPF_ALU64_REG(BPF_SUB, R4, R4), |
| 3167 | BPF_ALU64_REG(BPF_XOR, R5, R5), |
| 3168 | BPF_ALU64_IMM(BPF_MOV, R3, 1), |
| 3169 | BPF_ALU64_IMM(BPF_MOV, R7, -1), |
| 3170 | BPF_JMP_REG(BPF_JEQ, R5, R4, 1), |
| 3171 | BPF_EXIT_INSN(), |
| 3172 | BPF_ALU64_IMM(BPF_MOV, R5, 1), |
| 3173 | BPF_ALU64_REG(BPF_SUB, R5, R5), |
| 3174 | BPF_ALU64_REG(BPF_XOR, R6, R6), |
| 3175 | BPF_ALU64_IMM(BPF_MOV, R1, 1), |
| 3176 | BPF_ALU64_IMM(BPF_MOV, R8, -1), |
| 3177 | BPF_JMP_REG(BPF_JEQ, R5, R6, 1), |
| 3178 | BPF_EXIT_INSN(), |
| 3179 | BPF_ALU64_REG(BPF_SUB, R6, R6), |
| 3180 | BPF_ALU64_REG(BPF_XOR, R7, R7), |
| 3181 | BPF_JMP_REG(BPF_JEQ, R7, R6, 1), |
| 3182 | BPF_EXIT_INSN(), |
| 3183 | BPF_ALU64_REG(BPF_SUB, R7, R7), |
| 3184 | BPF_ALU64_REG(BPF_XOR, R8, R8), |
| 3185 | BPF_JMP_REG(BPF_JEQ, R7, R8, 1), |
| 3186 | BPF_EXIT_INSN(), |
| 3187 | BPF_ALU64_REG(BPF_SUB, R8, R8), |
| 3188 | BPF_ALU64_REG(BPF_XOR, R9, R9), |
| 3189 | BPF_JMP_REG(BPF_JEQ, R9, R8, 1), |
| 3190 | BPF_EXIT_INSN(), |
| 3191 | BPF_ALU64_REG(BPF_SUB, R9, R9), |
| 3192 | BPF_ALU64_REG(BPF_XOR, R0, R0), |
| 3193 | BPF_JMP_REG(BPF_JEQ, R9, R0, 1), |
| 3194 | BPF_EXIT_INSN(), |
| 3195 | BPF_ALU64_REG(BPF_SUB, R1, R1), |
| 3196 | BPF_ALU64_REG(BPF_XOR, R0, R0), |
| 3197 | BPF_JMP_REG(BPF_JEQ, R9, R0, 2), |
| 3198 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 3199 | BPF_EXIT_INSN(), |
| 3200 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 3201 | BPF_EXIT_INSN(), |
| 3202 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3203 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3204 | { }, |
| 3205 | { { 0, 1 } } |
| 3206 | }, |
| 3207 | { /* Mainly checking JIT here. */ |
| 3208 | "INT: MUL", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3209 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3210 | BPF_ALU64_IMM(BPF_MOV, R0, 11), |
| 3211 | BPF_ALU64_IMM(BPF_MOV, R1, 1), |
| 3212 | BPF_ALU64_IMM(BPF_MOV, R2, 2), |
| 3213 | BPF_ALU64_IMM(BPF_MOV, R3, 3), |
| 3214 | BPF_ALU64_IMM(BPF_MOV, R4, 4), |
| 3215 | BPF_ALU64_IMM(BPF_MOV, R5, 5), |
| 3216 | BPF_ALU64_IMM(BPF_MOV, R6, 6), |
| 3217 | BPF_ALU64_IMM(BPF_MOV, R7, 7), |
| 3218 | BPF_ALU64_IMM(BPF_MOV, R8, 8), |
| 3219 | BPF_ALU64_IMM(BPF_MOV, R9, 9), |
| 3220 | BPF_ALU64_REG(BPF_MUL, R0, R0), |
| 3221 | BPF_ALU64_REG(BPF_MUL, R0, R1), |
| 3222 | BPF_ALU64_REG(BPF_MUL, R0, R2), |
| 3223 | BPF_ALU64_REG(BPF_MUL, R0, R3), |
| 3224 | BPF_ALU64_REG(BPF_MUL, R0, R4), |
| 3225 | BPF_ALU64_REG(BPF_MUL, R0, R5), |
| 3226 | BPF_ALU64_REG(BPF_MUL, R0, R6), |
| 3227 | BPF_ALU64_REG(BPF_MUL, R0, R7), |
| 3228 | BPF_ALU64_REG(BPF_MUL, R0, R8), |
| 3229 | BPF_ALU64_REG(BPF_MUL, R0, R9), |
| 3230 | BPF_ALU64_IMM(BPF_MUL, R0, 10), |
| 3231 | BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1), |
| 3232 | BPF_EXIT_INSN(), |
| 3233 | BPF_ALU64_REG(BPF_MUL, R1, R0), |
| 3234 | BPF_ALU64_REG(BPF_MUL, R1, R2), |
| 3235 | BPF_ALU64_REG(BPF_MUL, R1, R3), |
| 3236 | BPF_ALU64_REG(BPF_MUL, R1, R4), |
| 3237 | BPF_ALU64_REG(BPF_MUL, R1, R5), |
| 3238 | BPF_ALU64_REG(BPF_MUL, R1, R6), |
| 3239 | BPF_ALU64_REG(BPF_MUL, R1, R7), |
| 3240 | BPF_ALU64_REG(BPF_MUL, R1, R8), |
| 3241 | BPF_ALU64_REG(BPF_MUL, R1, R9), |
| 3242 | BPF_ALU64_IMM(BPF_MUL, R1, 10), |
| 3243 | BPF_ALU64_REG(BPF_MOV, R2, R1), |
| 3244 | BPF_ALU64_IMM(BPF_RSH, R2, 32), |
| 3245 | BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1), |
| 3246 | BPF_EXIT_INSN(), |
| 3247 | BPF_ALU64_IMM(BPF_LSH, R1, 32), |
| 3248 | BPF_ALU64_IMM(BPF_ARSH, R1, 32), |
| 3249 | BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1), |
| 3250 | BPF_EXIT_INSN(), |
| 3251 | BPF_ALU64_REG(BPF_MUL, R2, R0), |
| 3252 | BPF_ALU64_REG(BPF_MUL, R2, R1), |
| 3253 | BPF_ALU64_REG(BPF_MUL, R2, R3), |
| 3254 | BPF_ALU64_REG(BPF_MUL, R2, R4), |
| 3255 | BPF_ALU64_REG(BPF_MUL, R2, R5), |
| 3256 | BPF_ALU64_REG(BPF_MUL, R2, R6), |
| 3257 | BPF_ALU64_REG(BPF_MUL, R2, R7), |
| 3258 | BPF_ALU64_REG(BPF_MUL, R2, R8), |
| 3259 | BPF_ALU64_REG(BPF_MUL, R2, R9), |
| 3260 | BPF_ALU64_IMM(BPF_MUL, R2, 10), |
| 3261 | BPF_ALU64_IMM(BPF_RSH, R2, 32), |
| 3262 | BPF_ALU64_REG(BPF_MOV, R0, R2), |
| 3263 | BPF_EXIT_INSN(), |
| 3264 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3265 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3266 | { }, |
| 3267 | { { 0, 0x35d97ef2 } } |
| 3268 | }, |
Daniel Borkmann | 9dd2af8 | 2015-12-17 23:51:57 +0100 | [diff] [blame] | 3269 | { /* Mainly checking JIT here. */ |
| 3270 | "MOV REG64", |
| 3271 | .u.insns_int = { |
| 3272 | BPF_LD_IMM64(R0, 0xffffffffffffffffLL), |
| 3273 | BPF_MOV64_REG(R1, R0), |
| 3274 | BPF_MOV64_REG(R2, R1), |
| 3275 | BPF_MOV64_REG(R3, R2), |
| 3276 | BPF_MOV64_REG(R4, R3), |
| 3277 | BPF_MOV64_REG(R5, R4), |
| 3278 | BPF_MOV64_REG(R6, R5), |
| 3279 | BPF_MOV64_REG(R7, R6), |
| 3280 | BPF_MOV64_REG(R8, R7), |
| 3281 | BPF_MOV64_REG(R9, R8), |
| 3282 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 3283 | BPF_ALU64_IMM(BPF_MOV, R1, 0), |
| 3284 | BPF_ALU64_IMM(BPF_MOV, R2, 0), |
| 3285 | BPF_ALU64_IMM(BPF_MOV, R3, 0), |
| 3286 | BPF_ALU64_IMM(BPF_MOV, R4, 0), |
| 3287 | BPF_ALU64_IMM(BPF_MOV, R5, 0), |
| 3288 | BPF_ALU64_IMM(BPF_MOV, R6, 0), |
| 3289 | BPF_ALU64_IMM(BPF_MOV, R7, 0), |
| 3290 | BPF_ALU64_IMM(BPF_MOV, R8, 0), |
| 3291 | BPF_ALU64_IMM(BPF_MOV, R9, 0), |
| 3292 | BPF_ALU64_REG(BPF_ADD, R0, R0), |
| 3293 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 3294 | BPF_ALU64_REG(BPF_ADD, R0, R2), |
| 3295 | BPF_ALU64_REG(BPF_ADD, R0, R3), |
| 3296 | BPF_ALU64_REG(BPF_ADD, R0, R4), |
| 3297 | BPF_ALU64_REG(BPF_ADD, R0, R5), |
| 3298 | BPF_ALU64_REG(BPF_ADD, R0, R6), |
| 3299 | BPF_ALU64_REG(BPF_ADD, R0, R7), |
| 3300 | BPF_ALU64_REG(BPF_ADD, R0, R8), |
| 3301 | BPF_ALU64_REG(BPF_ADD, R0, R9), |
| 3302 | BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe), |
| 3303 | BPF_EXIT_INSN(), |
| 3304 | }, |
| 3305 | INTERNAL, |
| 3306 | { }, |
| 3307 | { { 0, 0xfefe } } |
| 3308 | }, |
| 3309 | { /* Mainly checking JIT here. */ |
| 3310 | "MOV REG32", |
| 3311 | .u.insns_int = { |
| 3312 | BPF_LD_IMM64(R0, 0xffffffffffffffffLL), |
| 3313 | BPF_MOV64_REG(R1, R0), |
| 3314 | BPF_MOV64_REG(R2, R1), |
| 3315 | BPF_MOV64_REG(R3, R2), |
| 3316 | BPF_MOV64_REG(R4, R3), |
| 3317 | BPF_MOV64_REG(R5, R4), |
| 3318 | BPF_MOV64_REG(R6, R5), |
| 3319 | BPF_MOV64_REG(R7, R6), |
| 3320 | BPF_MOV64_REG(R8, R7), |
| 3321 | BPF_MOV64_REG(R9, R8), |
| 3322 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 3323 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 3324 | BPF_ALU32_IMM(BPF_MOV, R2, 0), |
| 3325 | BPF_ALU32_IMM(BPF_MOV, R3, 0), |
| 3326 | BPF_ALU32_IMM(BPF_MOV, R4, 0), |
| 3327 | BPF_ALU32_IMM(BPF_MOV, R5, 0), |
| 3328 | BPF_ALU32_IMM(BPF_MOV, R6, 0), |
| 3329 | BPF_ALU32_IMM(BPF_MOV, R7, 0), |
| 3330 | BPF_ALU32_IMM(BPF_MOV, R8, 0), |
| 3331 | BPF_ALU32_IMM(BPF_MOV, R9, 0), |
| 3332 | BPF_ALU64_REG(BPF_ADD, R0, R0), |
| 3333 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 3334 | BPF_ALU64_REG(BPF_ADD, R0, R2), |
| 3335 | BPF_ALU64_REG(BPF_ADD, R0, R3), |
| 3336 | BPF_ALU64_REG(BPF_ADD, R0, R4), |
| 3337 | BPF_ALU64_REG(BPF_ADD, R0, R5), |
| 3338 | BPF_ALU64_REG(BPF_ADD, R0, R6), |
| 3339 | BPF_ALU64_REG(BPF_ADD, R0, R7), |
| 3340 | BPF_ALU64_REG(BPF_ADD, R0, R8), |
| 3341 | BPF_ALU64_REG(BPF_ADD, R0, R9), |
| 3342 | BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe), |
| 3343 | BPF_EXIT_INSN(), |
| 3344 | }, |
| 3345 | INTERNAL, |
| 3346 | { }, |
| 3347 | { { 0, 0xfefe } } |
| 3348 | }, |
| 3349 | { /* Mainly checking JIT here. */ |
| 3350 | "LD IMM64", |
| 3351 | .u.insns_int = { |
| 3352 | BPF_LD_IMM64(R0, 0xffffffffffffffffLL), |
| 3353 | BPF_MOV64_REG(R1, R0), |
| 3354 | BPF_MOV64_REG(R2, R1), |
| 3355 | BPF_MOV64_REG(R3, R2), |
| 3356 | BPF_MOV64_REG(R4, R3), |
| 3357 | BPF_MOV64_REG(R5, R4), |
| 3358 | BPF_MOV64_REG(R6, R5), |
| 3359 | BPF_MOV64_REG(R7, R6), |
| 3360 | BPF_MOV64_REG(R8, R7), |
| 3361 | BPF_MOV64_REG(R9, R8), |
| 3362 | BPF_LD_IMM64(R0, 0x0LL), |
| 3363 | BPF_LD_IMM64(R1, 0x0LL), |
| 3364 | BPF_LD_IMM64(R2, 0x0LL), |
| 3365 | BPF_LD_IMM64(R3, 0x0LL), |
| 3366 | BPF_LD_IMM64(R4, 0x0LL), |
| 3367 | BPF_LD_IMM64(R5, 0x0LL), |
| 3368 | BPF_LD_IMM64(R6, 0x0LL), |
| 3369 | BPF_LD_IMM64(R7, 0x0LL), |
| 3370 | BPF_LD_IMM64(R8, 0x0LL), |
| 3371 | BPF_LD_IMM64(R9, 0x0LL), |
| 3372 | BPF_ALU64_REG(BPF_ADD, R0, R0), |
| 3373 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 3374 | BPF_ALU64_REG(BPF_ADD, R0, R2), |
| 3375 | BPF_ALU64_REG(BPF_ADD, R0, R3), |
| 3376 | BPF_ALU64_REG(BPF_ADD, R0, R4), |
| 3377 | BPF_ALU64_REG(BPF_ADD, R0, R5), |
| 3378 | BPF_ALU64_REG(BPF_ADD, R0, R6), |
| 3379 | BPF_ALU64_REG(BPF_ADD, R0, R7), |
| 3380 | BPF_ALU64_REG(BPF_ADD, R0, R8), |
| 3381 | BPF_ALU64_REG(BPF_ADD, R0, R9), |
| 3382 | BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe), |
| 3383 | BPF_EXIT_INSN(), |
| 3384 | }, |
| 3385 | INTERNAL, |
| 3386 | { }, |
| 3387 | { { 0, 0xfefe } } |
| 3388 | }, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3389 | { |
| 3390 | "INT: ALU MIX", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3391 | .u.insns_int = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3392 | BPF_ALU64_IMM(BPF_MOV, R0, 11), |
| 3393 | BPF_ALU64_IMM(BPF_ADD, R0, -1), |
| 3394 | BPF_ALU64_IMM(BPF_MOV, R2, 2), |
| 3395 | BPF_ALU64_IMM(BPF_XOR, R2, 3), |
| 3396 | BPF_ALU64_REG(BPF_DIV, R0, R2), |
| 3397 | BPF_JMP_IMM(BPF_JEQ, R0, 10, 1), |
| 3398 | BPF_EXIT_INSN(), |
| 3399 | BPF_ALU64_IMM(BPF_MOD, R0, 3), |
| 3400 | BPF_JMP_IMM(BPF_JEQ, R0, 1, 1), |
| 3401 | BPF_EXIT_INSN(), |
| 3402 | BPF_ALU64_IMM(BPF_MOV, R0, -1), |
| 3403 | BPF_EXIT_INSN(), |
| 3404 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3405 | INTERNAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3406 | { }, |
| 3407 | { { 0, -1 } } |
| 3408 | }, |
| 3409 | { |
Alexei Starovoitov | 72b603e | 2014-08-25 12:27:02 -0700 | [diff] [blame] | 3410 | "INT: shifts by register", |
| 3411 | .u.insns_int = { |
| 3412 | BPF_MOV64_IMM(R0, -1234), |
| 3413 | BPF_MOV64_IMM(R1, 1), |
| 3414 | BPF_ALU32_REG(BPF_RSH, R0, R1), |
| 3415 | BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1), |
| 3416 | BPF_EXIT_INSN(), |
| 3417 | BPF_MOV64_IMM(R2, 1), |
| 3418 | BPF_ALU64_REG(BPF_LSH, R0, R2), |
| 3419 | BPF_MOV32_IMM(R4, -1234), |
| 3420 | BPF_JMP_REG(BPF_JEQ, R0, R4, 1), |
| 3421 | BPF_EXIT_INSN(), |
| 3422 | BPF_ALU64_IMM(BPF_AND, R4, 63), |
| 3423 | BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */ |
| 3424 | BPF_MOV64_IMM(R3, 47), |
| 3425 | BPF_ALU64_REG(BPF_ARSH, R0, R3), |
| 3426 | BPF_JMP_IMM(BPF_JEQ, R0, -617, 1), |
| 3427 | BPF_EXIT_INSN(), |
| 3428 | BPF_MOV64_IMM(R2, 1), |
| 3429 | BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */ |
| 3430 | BPF_JMP_IMM(BPF_JEQ, R4, 92, 1), |
| 3431 | BPF_EXIT_INSN(), |
| 3432 | BPF_MOV64_IMM(R4, 4), |
| 3433 | BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */ |
| 3434 | BPF_JMP_IMM(BPF_JEQ, R4, 64, 1), |
| 3435 | BPF_EXIT_INSN(), |
| 3436 | BPF_MOV64_IMM(R4, 5), |
| 3437 | BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */ |
| 3438 | BPF_JMP_IMM(BPF_JEQ, R4, 160, 1), |
| 3439 | BPF_EXIT_INSN(), |
| 3440 | BPF_MOV64_IMM(R0, -1), |
| 3441 | BPF_EXIT_INSN(), |
| 3442 | }, |
| 3443 | INTERNAL, |
| 3444 | { }, |
| 3445 | { { 0, -1 } } |
| 3446 | }, |
| 3447 | { |
Johan Almbladh | 84024a4 | 2021-08-09 11:18:23 +0200 | [diff] [blame] | 3448 | /* |
| 3449 | * Register (non-)clobbering test, in the case where a 32-bit |
| 3450 | * JIT implements complex ALU64 operations via function calls. |
| 3451 | * If so, the function call must be invisible in the eBPF |
| 3452 | * registers. The JIT must then save and restore relevant |
| 3453 | * registers during the call. The following tests check that |
| 3454 | * the eBPF registers retain their values after such a call. |
| 3455 | */ |
| 3456 | "INT: Register clobbering, R1 updated", |
| 3457 | .u.insns_int = { |
| 3458 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 3459 | BPF_ALU32_IMM(BPF_MOV, R1, 123456789), |
| 3460 | BPF_ALU32_IMM(BPF_MOV, R2, 2), |
| 3461 | BPF_ALU32_IMM(BPF_MOV, R3, 3), |
| 3462 | BPF_ALU32_IMM(BPF_MOV, R4, 4), |
| 3463 | BPF_ALU32_IMM(BPF_MOV, R5, 5), |
| 3464 | BPF_ALU32_IMM(BPF_MOV, R6, 6), |
| 3465 | BPF_ALU32_IMM(BPF_MOV, R7, 7), |
| 3466 | BPF_ALU32_IMM(BPF_MOV, R8, 8), |
| 3467 | BPF_ALU32_IMM(BPF_MOV, R9, 9), |
| 3468 | BPF_ALU64_IMM(BPF_DIV, R1, 123456789), |
| 3469 | BPF_JMP_IMM(BPF_JNE, R0, 0, 10), |
| 3470 | BPF_JMP_IMM(BPF_JNE, R1, 1, 9), |
| 3471 | BPF_JMP_IMM(BPF_JNE, R2, 2, 8), |
| 3472 | BPF_JMP_IMM(BPF_JNE, R3, 3, 7), |
| 3473 | BPF_JMP_IMM(BPF_JNE, R4, 4, 6), |
| 3474 | BPF_JMP_IMM(BPF_JNE, R5, 5, 5), |
| 3475 | BPF_JMP_IMM(BPF_JNE, R6, 6, 4), |
| 3476 | BPF_JMP_IMM(BPF_JNE, R7, 7, 3), |
| 3477 | BPF_JMP_IMM(BPF_JNE, R8, 8, 2), |
| 3478 | BPF_JMP_IMM(BPF_JNE, R9, 9, 1), |
| 3479 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 3480 | BPF_EXIT_INSN(), |
| 3481 | }, |
| 3482 | INTERNAL, |
| 3483 | { }, |
| 3484 | { { 0, 1 } } |
| 3485 | }, |
| 3486 | { |
| 3487 | "INT: Register clobbering, R2 updated", |
| 3488 | .u.insns_int = { |
| 3489 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 3490 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 3491 | BPF_ALU32_IMM(BPF_MOV, R2, 2 * 123456789), |
| 3492 | BPF_ALU32_IMM(BPF_MOV, R3, 3), |
| 3493 | BPF_ALU32_IMM(BPF_MOV, R4, 4), |
| 3494 | BPF_ALU32_IMM(BPF_MOV, R5, 5), |
| 3495 | BPF_ALU32_IMM(BPF_MOV, R6, 6), |
| 3496 | BPF_ALU32_IMM(BPF_MOV, R7, 7), |
| 3497 | BPF_ALU32_IMM(BPF_MOV, R8, 8), |
| 3498 | BPF_ALU32_IMM(BPF_MOV, R9, 9), |
| 3499 | BPF_ALU64_IMM(BPF_DIV, R2, 123456789), |
| 3500 | BPF_JMP_IMM(BPF_JNE, R0, 0, 10), |
| 3501 | BPF_JMP_IMM(BPF_JNE, R1, 1, 9), |
| 3502 | BPF_JMP_IMM(BPF_JNE, R2, 2, 8), |
| 3503 | BPF_JMP_IMM(BPF_JNE, R3, 3, 7), |
| 3504 | BPF_JMP_IMM(BPF_JNE, R4, 4, 6), |
| 3505 | BPF_JMP_IMM(BPF_JNE, R5, 5, 5), |
| 3506 | BPF_JMP_IMM(BPF_JNE, R6, 6, 4), |
| 3507 | BPF_JMP_IMM(BPF_JNE, R7, 7, 3), |
| 3508 | BPF_JMP_IMM(BPF_JNE, R8, 8, 2), |
| 3509 | BPF_JMP_IMM(BPF_JNE, R9, 9, 1), |
| 3510 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 3511 | BPF_EXIT_INSN(), |
| 3512 | }, |
| 3513 | INTERNAL, |
| 3514 | { }, |
| 3515 | { { 0, 1 } } |
| 3516 | }, |
| 3517 | { |
| 3518 | /* |
| 3519 | * Test 32-bit JITs that implement complex ALU64 operations as |
| 3520 | * function calls R0 = f(R1, R2), and must re-arrange operands. |
| 3521 | */ |
| 3522 | #define NUMER 0xfedcba9876543210ULL |
| 3523 | #define DENOM 0x0123456789abcdefULL |
| 3524 | "ALU64_DIV X: Operand register permutations", |
| 3525 | .u.insns_int = { |
| 3526 | /* R0 / R2 */ |
| 3527 | BPF_LD_IMM64(R0, NUMER), |
| 3528 | BPF_LD_IMM64(R2, DENOM), |
| 3529 | BPF_ALU64_REG(BPF_DIV, R0, R2), |
| 3530 | BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1), |
| 3531 | BPF_EXIT_INSN(), |
| 3532 | /* R1 / R0 */ |
| 3533 | BPF_LD_IMM64(R1, NUMER), |
| 3534 | BPF_LD_IMM64(R0, DENOM), |
| 3535 | BPF_ALU64_REG(BPF_DIV, R1, R0), |
| 3536 | BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1), |
| 3537 | BPF_EXIT_INSN(), |
| 3538 | /* R0 / R1 */ |
| 3539 | BPF_LD_IMM64(R0, NUMER), |
| 3540 | BPF_LD_IMM64(R1, DENOM), |
| 3541 | BPF_ALU64_REG(BPF_DIV, R0, R1), |
| 3542 | BPF_JMP_IMM(BPF_JEQ, R0, NUMER / DENOM, 1), |
| 3543 | BPF_EXIT_INSN(), |
| 3544 | /* R2 / R0 */ |
| 3545 | BPF_LD_IMM64(R2, NUMER), |
| 3546 | BPF_LD_IMM64(R0, DENOM), |
| 3547 | BPF_ALU64_REG(BPF_DIV, R2, R0), |
| 3548 | BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1), |
| 3549 | BPF_EXIT_INSN(), |
| 3550 | /* R2 / R1 */ |
| 3551 | BPF_LD_IMM64(R2, NUMER), |
| 3552 | BPF_LD_IMM64(R1, DENOM), |
| 3553 | BPF_ALU64_REG(BPF_DIV, R2, R1), |
| 3554 | BPF_JMP_IMM(BPF_JEQ, R2, NUMER / DENOM, 1), |
| 3555 | BPF_EXIT_INSN(), |
| 3556 | /* R1 / R2 */ |
| 3557 | BPF_LD_IMM64(R1, NUMER), |
| 3558 | BPF_LD_IMM64(R2, DENOM), |
| 3559 | BPF_ALU64_REG(BPF_DIV, R1, R2), |
| 3560 | BPF_JMP_IMM(BPF_JEQ, R1, NUMER / DENOM, 1), |
| 3561 | BPF_EXIT_INSN(), |
| 3562 | /* R1 / R1 */ |
| 3563 | BPF_LD_IMM64(R1, NUMER), |
| 3564 | BPF_ALU64_REG(BPF_DIV, R1, R1), |
| 3565 | BPF_JMP_IMM(BPF_JEQ, R1, 1, 1), |
| 3566 | BPF_EXIT_INSN(), |
| 3567 | /* R2 / R2 */ |
| 3568 | BPF_LD_IMM64(R2, DENOM), |
| 3569 | BPF_ALU64_REG(BPF_DIV, R2, R2), |
| 3570 | BPF_JMP_IMM(BPF_JEQ, R2, 1, 1), |
| 3571 | BPF_EXIT_INSN(), |
| 3572 | /* R3 / R4 */ |
| 3573 | BPF_LD_IMM64(R3, NUMER), |
| 3574 | BPF_LD_IMM64(R4, DENOM), |
| 3575 | BPF_ALU64_REG(BPF_DIV, R3, R4), |
| 3576 | BPF_JMP_IMM(BPF_JEQ, R3, NUMER / DENOM, 1), |
| 3577 | BPF_EXIT_INSN(), |
| 3578 | /* Successful return */ |
| 3579 | BPF_LD_IMM64(R0, 1), |
| 3580 | BPF_EXIT_INSN(), |
| 3581 | }, |
| 3582 | INTERNAL, |
| 3583 | { }, |
| 3584 | { { 0, 1 } }, |
| 3585 | #undef NUMER |
| 3586 | #undef DENOM |
| 3587 | }, |
Johan Almbladh | 53e33f9 | 2021-08-09 11:18:26 +0200 | [diff] [blame] | 3588 | #ifdef CONFIG_32BIT |
| 3589 | { |
| 3590 | "INT: 32-bit context pointer word order and zero-extension", |
| 3591 | .u.insns_int = { |
| 3592 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 3593 | BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3), |
| 3594 | BPF_ALU64_IMM(BPF_RSH, R1, 32), |
| 3595 | BPF_JMP32_IMM(BPF_JNE, R1, 0, 1), |
| 3596 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 3597 | BPF_EXIT_INSN(), |
| 3598 | }, |
| 3599 | INTERNAL, |
| 3600 | { }, |
| 3601 | { { 0, 1 } } |
| 3602 | }, |
| 3603 | #endif |
Johan Almbladh | 84024a4 | 2021-08-09 11:18:23 +0200 | [diff] [blame] | 3604 | { |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 3605 | "check: missing ret", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3606 | .u.insns = { |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 3607 | BPF_STMT(BPF_LD | BPF_IMM, 1), |
| 3608 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3609 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 3610 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3611 | { }, |
| 3612 | .fill_helper = NULL, |
| 3613 | .expected_errcode = -EINVAL, |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 3614 | }, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3615 | { |
| 3616 | "check: div_k_0", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3617 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3618 | BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0), |
| 3619 | BPF_STMT(BPF_RET | BPF_K, 0) |
| 3620 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3621 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3622 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3623 | { }, |
| 3624 | .fill_helper = NULL, |
| 3625 | .expected_errcode = -EINVAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3626 | }, |
| 3627 | { |
| 3628 | "check: unknown insn", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3629 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3630 | /* seccomp insn, rejected in socket filter */ |
| 3631 | BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0), |
| 3632 | BPF_STMT(BPF_RET | BPF_K, 0) |
| 3633 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3634 | CLASSIC | FLAG_EXPECTED_FAIL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3635 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3636 | { }, |
| 3637 | .fill_helper = NULL, |
| 3638 | .expected_errcode = -EINVAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3639 | }, |
| 3640 | { |
| 3641 | "check: out of range spill/fill", |
Andrew Morton | ece8049 | 2014-05-22 10:16:46 -0700 | [diff] [blame] | 3642 | .u.insns = { |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3643 | BPF_STMT(BPF_STX, 16), |
| 3644 | BPF_STMT(BPF_RET | BPF_K, 0) |
| 3645 | }, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 3646 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3647 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3648 | { }, |
| 3649 | .fill_helper = NULL, |
| 3650 | .expected_errcode = -EINVAL, |
Alexei Starovoitov | 9def624 | 2014-05-08 14:10:53 -0700 | [diff] [blame] | 3651 | }, |
Daniel Borkmann | 2e8a83c | 2014-05-23 18:44:01 +0200 | [diff] [blame] | 3652 | { |
| 3653 | "JUMPS + HOLES", |
| 3654 | .u.insns = { |
| 3655 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3656 | BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15), |
| 3657 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3658 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3659 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3660 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3661 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3662 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3663 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3664 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3665 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3666 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3667 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3668 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3669 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3670 | BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4), |
| 3671 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3672 | BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2), |
| 3673 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3674 | BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15), |
| 3675 | BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14), |
| 3676 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3677 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3678 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3679 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3680 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3681 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3682 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3683 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3684 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3685 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3686 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3687 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3688 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3689 | BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3), |
| 3690 | BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2), |
| 3691 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3692 | BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15), |
| 3693 | BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14), |
| 3694 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3695 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3696 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3697 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3698 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3699 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3700 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3701 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3702 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3703 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3704 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3705 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3706 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3707 | BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3), |
| 3708 | BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2), |
| 3709 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), |
| 3710 | BPF_STMT(BPF_RET | BPF_A, 0), |
| 3711 | BPF_STMT(BPF_RET | BPF_A, 0), |
| 3712 | }, |
| 3713 | CLASSIC, |
Daniel Borkmann | ce25b68 | 2014-05-26 20:17:35 +0200 | [diff] [blame] | 3714 | { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, |
| 3715 | 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4, |
| 3716 | 0x08, 0x00, |
| 3717 | 0x45, 0x00, 0x00, 0x28, 0x00, 0x00, |
| 3718 | 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */ |
| 3719 | 0xc0, 0xa8, 0x33, 0x01, |
| 3720 | 0xc0, 0xa8, 0x33, 0x02, |
| 3721 | 0xbb, 0xb6, |
| 3722 | 0xa9, 0xfa, |
| 3723 | 0x00, 0x14, 0x00, 0x00, |
| 3724 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3725 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3726 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3727 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3728 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3729 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3730 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 3731 | 0xcc, 0xcc, 0xcc, 0xcc }, |
Daniel Borkmann | 2e8a83c | 2014-05-23 18:44:01 +0200 | [diff] [blame] | 3732 | { { 88, 0x001b } } |
| 3733 | }, |
| 3734 | { |
| 3735 | "check: RET X", |
| 3736 | .u.insns = { |
| 3737 | BPF_STMT(BPF_RET | BPF_X, 0), |
| 3738 | }, |
| 3739 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
| 3740 | { }, |
| 3741 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3742 | .fill_helper = NULL, |
| 3743 | .expected_errcode = -EINVAL, |
Daniel Borkmann | 2e8a83c | 2014-05-23 18:44:01 +0200 | [diff] [blame] | 3744 | }, |
| 3745 | { |
| 3746 | "check: LDX + RET X", |
| 3747 | .u.insns = { |
| 3748 | BPF_STMT(BPF_LDX | BPF_IMM, 42), |
| 3749 | BPF_STMT(BPF_RET | BPF_X, 0), |
| 3750 | }, |
| 3751 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
| 3752 | { }, |
| 3753 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3754 | .fill_helper = NULL, |
| 3755 | .expected_errcode = -EINVAL, |
Daniel Borkmann | 2e8a83c | 2014-05-23 18:44:01 +0200 | [diff] [blame] | 3756 | }, |
Daniel Borkmann | 108cc22 | 2014-05-26 20:17:34 +0200 | [diff] [blame] | 3757 | { /* Mainly checking JIT here. */ |
Daniel Borkmann | 9fe13ba | 2014-05-29 10:22:48 +0200 | [diff] [blame] | 3758 | "M[]: alt STX + LDX", |
Daniel Borkmann | 108cc22 | 2014-05-26 20:17:34 +0200 | [diff] [blame] | 3759 | .u.insns = { |
| 3760 | BPF_STMT(BPF_LDX | BPF_IMM, 100), |
| 3761 | BPF_STMT(BPF_STX, 0), |
| 3762 | BPF_STMT(BPF_LDX | BPF_MEM, 0), |
| 3763 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3764 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3765 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3766 | BPF_STMT(BPF_STX, 1), |
| 3767 | BPF_STMT(BPF_LDX | BPF_MEM, 1), |
| 3768 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3769 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3770 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3771 | BPF_STMT(BPF_STX, 2), |
| 3772 | BPF_STMT(BPF_LDX | BPF_MEM, 2), |
| 3773 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3774 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3775 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3776 | BPF_STMT(BPF_STX, 3), |
| 3777 | BPF_STMT(BPF_LDX | BPF_MEM, 3), |
| 3778 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3779 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3780 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3781 | BPF_STMT(BPF_STX, 4), |
| 3782 | BPF_STMT(BPF_LDX | BPF_MEM, 4), |
| 3783 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3784 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3785 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3786 | BPF_STMT(BPF_STX, 5), |
| 3787 | BPF_STMT(BPF_LDX | BPF_MEM, 5), |
| 3788 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3789 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3790 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3791 | BPF_STMT(BPF_STX, 6), |
| 3792 | BPF_STMT(BPF_LDX | BPF_MEM, 6), |
| 3793 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3794 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3795 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3796 | BPF_STMT(BPF_STX, 7), |
| 3797 | BPF_STMT(BPF_LDX | BPF_MEM, 7), |
| 3798 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3799 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3800 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3801 | BPF_STMT(BPF_STX, 8), |
| 3802 | BPF_STMT(BPF_LDX | BPF_MEM, 8), |
| 3803 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3804 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3805 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3806 | BPF_STMT(BPF_STX, 9), |
| 3807 | BPF_STMT(BPF_LDX | BPF_MEM, 9), |
| 3808 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3809 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3810 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3811 | BPF_STMT(BPF_STX, 10), |
| 3812 | BPF_STMT(BPF_LDX | BPF_MEM, 10), |
| 3813 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3814 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3815 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3816 | BPF_STMT(BPF_STX, 11), |
| 3817 | BPF_STMT(BPF_LDX | BPF_MEM, 11), |
| 3818 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3819 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3820 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3821 | BPF_STMT(BPF_STX, 12), |
| 3822 | BPF_STMT(BPF_LDX | BPF_MEM, 12), |
| 3823 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3824 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3825 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3826 | BPF_STMT(BPF_STX, 13), |
| 3827 | BPF_STMT(BPF_LDX | BPF_MEM, 13), |
| 3828 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3829 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3830 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3831 | BPF_STMT(BPF_STX, 14), |
| 3832 | BPF_STMT(BPF_LDX | BPF_MEM, 14), |
| 3833 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3834 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3835 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3836 | BPF_STMT(BPF_STX, 15), |
| 3837 | BPF_STMT(BPF_LDX | BPF_MEM, 15), |
| 3838 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3839 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), |
| 3840 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 3841 | BPF_STMT(BPF_RET | BPF_A, 0), |
| 3842 | }, |
| 3843 | CLASSIC | FLAG_NO_DATA, |
| 3844 | { }, |
| 3845 | { { 0, 116 } }, |
| 3846 | }, |
Daniel Borkmann | 9fe13ba | 2014-05-29 10:22:48 +0200 | [diff] [blame] | 3847 | { /* Mainly checking JIT here. */ |
| 3848 | "M[]: full STX + full LDX", |
| 3849 | .u.insns = { |
| 3850 | BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb), |
| 3851 | BPF_STMT(BPF_STX, 0), |
| 3852 | BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae), |
| 3853 | BPF_STMT(BPF_STX, 1), |
| 3854 | BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf), |
| 3855 | BPF_STMT(BPF_STX, 2), |
| 3856 | BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc), |
| 3857 | BPF_STMT(BPF_STX, 3), |
| 3858 | BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb), |
| 3859 | BPF_STMT(BPF_STX, 4), |
| 3860 | BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda), |
| 3861 | BPF_STMT(BPF_STX, 5), |
| 3862 | BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb), |
| 3863 | BPF_STMT(BPF_STX, 6), |
| 3864 | BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade), |
| 3865 | BPF_STMT(BPF_STX, 7), |
| 3866 | BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec), |
| 3867 | BPF_STMT(BPF_STX, 8), |
| 3868 | BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc), |
| 3869 | BPF_STMT(BPF_STX, 9), |
| 3870 | BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac), |
| 3871 | BPF_STMT(BPF_STX, 10), |
| 3872 | BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea), |
| 3873 | BPF_STMT(BPF_STX, 11), |
| 3874 | BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb), |
| 3875 | BPF_STMT(BPF_STX, 12), |
| 3876 | BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf), |
| 3877 | BPF_STMT(BPF_STX, 13), |
| 3878 | BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde), |
| 3879 | BPF_STMT(BPF_STX, 14), |
| 3880 | BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad), |
| 3881 | BPF_STMT(BPF_STX, 15), |
| 3882 | BPF_STMT(BPF_LDX | BPF_MEM, 0), |
| 3883 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 3884 | BPF_STMT(BPF_LDX | BPF_MEM, 1), |
| 3885 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3886 | BPF_STMT(BPF_LDX | BPF_MEM, 2), |
| 3887 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3888 | BPF_STMT(BPF_LDX | BPF_MEM, 3), |
| 3889 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3890 | BPF_STMT(BPF_LDX | BPF_MEM, 4), |
| 3891 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3892 | BPF_STMT(BPF_LDX | BPF_MEM, 5), |
| 3893 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3894 | BPF_STMT(BPF_LDX | BPF_MEM, 6), |
| 3895 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3896 | BPF_STMT(BPF_LDX | BPF_MEM, 7), |
| 3897 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3898 | BPF_STMT(BPF_LDX | BPF_MEM, 8), |
| 3899 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3900 | BPF_STMT(BPF_LDX | BPF_MEM, 9), |
| 3901 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3902 | BPF_STMT(BPF_LDX | BPF_MEM, 10), |
| 3903 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3904 | BPF_STMT(BPF_LDX | BPF_MEM, 11), |
| 3905 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3906 | BPF_STMT(BPF_LDX | BPF_MEM, 12), |
| 3907 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3908 | BPF_STMT(BPF_LDX | BPF_MEM, 13), |
| 3909 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3910 | BPF_STMT(BPF_LDX | BPF_MEM, 14), |
| 3911 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3912 | BPF_STMT(BPF_LDX | BPF_MEM, 15), |
| 3913 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 3914 | BPF_STMT(BPF_RET | BPF_A, 0), |
| 3915 | }, |
| 3916 | CLASSIC | FLAG_NO_DATA, |
| 3917 | { }, |
| 3918 | { { 0, 0x2a5a5e5 } }, |
| 3919 | }, |
Daniel Borkmann | d50bc15 | 2014-05-29 10:22:49 +0200 | [diff] [blame] | 3920 | { |
| 3921 | "check: SKF_AD_MAX", |
| 3922 | .u.insns = { |
| 3923 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 3924 | SKF_AD_OFF + SKF_AD_MAX), |
| 3925 | BPF_STMT(BPF_RET | BPF_A, 0), |
| 3926 | }, |
| 3927 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
| 3928 | { }, |
| 3929 | { }, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 3930 | .fill_helper = NULL, |
| 3931 | .expected_errcode = -EINVAL, |
Daniel Borkmann | d50bc15 | 2014-05-29 10:22:49 +0200 | [diff] [blame] | 3932 | }, |
| 3933 | { /* Passes checker but fails during runtime. */ |
| 3934 | "LD [SKF_AD_OFF-1]", |
| 3935 | .u.insns = { |
| 3936 | BPF_STMT(BPF_LD | BPF_W | BPF_ABS, |
| 3937 | SKF_AD_OFF - 1), |
| 3938 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 3939 | }, |
| 3940 | CLASSIC, |
| 3941 | { }, |
| 3942 | { { 1, 0 } }, |
| 3943 | }, |
Alexei Starovoitov | 02ab695 | 2014-09-04 22:17:17 -0700 | [diff] [blame] | 3944 | { |
| 3945 | "load 64-bit immediate", |
| 3946 | .u.insns_int = { |
Alexei Starovoitov | 25ee732 | 2014-09-19 13:53:51 -0700 | [diff] [blame] | 3947 | BPF_LD_IMM64(R1, 0x567800001234LL), |
Alexei Starovoitov | 02ab695 | 2014-09-04 22:17:17 -0700 | [diff] [blame] | 3948 | BPF_MOV64_REG(R2, R1), |
| 3949 | BPF_MOV64_REG(R3, R2), |
| 3950 | BPF_ALU64_IMM(BPF_RSH, R2, 32), |
| 3951 | BPF_ALU64_IMM(BPF_LSH, R3, 32), |
| 3952 | BPF_ALU64_IMM(BPF_RSH, R3, 32), |
| 3953 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 3954 | BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1), |
| 3955 | BPF_EXIT_INSN(), |
| 3956 | BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1), |
| 3957 | BPF_EXIT_INSN(), |
Xi Wang | 986ccfd | 2015-05-09 04:14:30 -0400 | [diff] [blame] | 3958 | BPF_LD_IMM64(R0, 0x1ffffffffLL), |
| 3959 | BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */ |
Alexei Starovoitov | 02ab695 | 2014-09-04 22:17:17 -0700 | [diff] [blame] | 3960 | BPF_EXIT_INSN(), |
| 3961 | }, |
| 3962 | INTERNAL, |
| 3963 | { }, |
| 3964 | { { 0, 1 } } |
| 3965 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 3966 | /* BPF_ALU | BPF_MOV | BPF_X */ |
| 3967 | { |
| 3968 | "ALU_MOV_X: dst = 2", |
| 3969 | .u.insns_int = { |
| 3970 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 3971 | BPF_ALU32_REG(BPF_MOV, R0, R1), |
| 3972 | BPF_EXIT_INSN(), |
| 3973 | }, |
| 3974 | INTERNAL, |
| 3975 | { }, |
| 3976 | { { 0, 2 } }, |
| 3977 | }, |
| 3978 | { |
| 3979 | "ALU_MOV_X: dst = 4294967295", |
| 3980 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 3981 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 3982 | BPF_ALU32_REG(BPF_MOV, R0, R1), |
| 3983 | BPF_EXIT_INSN(), |
| 3984 | }, |
| 3985 | INTERNAL, |
| 3986 | { }, |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 3987 | { { 0, 4294967295U } }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 3988 | }, |
| 3989 | { |
| 3990 | "ALU64_MOV_X: dst = 2", |
| 3991 | .u.insns_int = { |
| 3992 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 3993 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 3994 | BPF_EXIT_INSN(), |
| 3995 | }, |
| 3996 | INTERNAL, |
| 3997 | { }, |
| 3998 | { { 0, 2 } }, |
| 3999 | }, |
| 4000 | { |
| 4001 | "ALU64_MOV_X: dst = 4294967295", |
| 4002 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4003 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4004 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 4005 | BPF_EXIT_INSN(), |
| 4006 | }, |
| 4007 | INTERNAL, |
| 4008 | { }, |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4009 | { { 0, 4294967295U } }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4010 | }, |
| 4011 | /* BPF_ALU | BPF_MOV | BPF_K */ |
| 4012 | { |
| 4013 | "ALU_MOV_K: dst = 2", |
| 4014 | .u.insns_int = { |
| 4015 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 4016 | BPF_EXIT_INSN(), |
| 4017 | }, |
| 4018 | INTERNAL, |
| 4019 | { }, |
| 4020 | { { 0, 2 } }, |
| 4021 | }, |
| 4022 | { |
| 4023 | "ALU_MOV_K: dst = 4294967295", |
| 4024 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4025 | BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4026 | BPF_EXIT_INSN(), |
| 4027 | }, |
| 4028 | INTERNAL, |
| 4029 | { }, |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4030 | { { 0, 4294967295U } }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4031 | }, |
| 4032 | { |
| 4033 | "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff", |
| 4034 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4035 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 4036 | BPF_LD_IMM64(R3, 0x00000000ffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4037 | BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff), |
| 4038 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4039 | BPF_MOV32_IMM(R0, 2), |
| 4040 | BPF_EXIT_INSN(), |
| 4041 | BPF_MOV32_IMM(R0, 1), |
| 4042 | BPF_EXIT_INSN(), |
| 4043 | }, |
| 4044 | INTERNAL, |
| 4045 | { }, |
| 4046 | { { 0, 0x1 } }, |
| 4047 | }, |
| 4048 | { |
Johan Almbladh | 565731a | 2021-08-09 11:18:17 +0200 | [diff] [blame] | 4049 | "ALU_MOV_K: small negative", |
| 4050 | .u.insns_int = { |
| 4051 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 4052 | BPF_EXIT_INSN(), |
| 4053 | }, |
| 4054 | INTERNAL, |
| 4055 | { }, |
| 4056 | { { 0, -123 } } |
| 4057 | }, |
| 4058 | { |
| 4059 | "ALU_MOV_K: small negative zero extension", |
| 4060 | .u.insns_int = { |
| 4061 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 4062 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 4063 | BPF_EXIT_INSN(), |
| 4064 | }, |
| 4065 | INTERNAL, |
| 4066 | { }, |
| 4067 | { { 0, 0 } } |
| 4068 | }, |
| 4069 | { |
| 4070 | "ALU_MOV_K: large negative", |
| 4071 | .u.insns_int = { |
| 4072 | BPF_ALU32_IMM(BPF_MOV, R0, -123456789), |
| 4073 | BPF_EXIT_INSN(), |
| 4074 | }, |
| 4075 | INTERNAL, |
| 4076 | { }, |
| 4077 | { { 0, -123456789 } } |
| 4078 | }, |
| 4079 | { |
| 4080 | "ALU_MOV_K: large negative zero extension", |
| 4081 | .u.insns_int = { |
| 4082 | BPF_ALU32_IMM(BPF_MOV, R0, -123456789), |
| 4083 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 4084 | BPF_EXIT_INSN(), |
| 4085 | }, |
| 4086 | INTERNAL, |
| 4087 | { }, |
| 4088 | { { 0, 0 } } |
| 4089 | }, |
| 4090 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4091 | "ALU64_MOV_K: dst = 2", |
| 4092 | .u.insns_int = { |
| 4093 | BPF_ALU64_IMM(BPF_MOV, R0, 2), |
| 4094 | BPF_EXIT_INSN(), |
| 4095 | }, |
| 4096 | INTERNAL, |
| 4097 | { }, |
| 4098 | { { 0, 2 } }, |
| 4099 | }, |
| 4100 | { |
| 4101 | "ALU64_MOV_K: dst = 2147483647", |
| 4102 | .u.insns_int = { |
| 4103 | BPF_ALU64_IMM(BPF_MOV, R0, 2147483647), |
| 4104 | BPF_EXIT_INSN(), |
| 4105 | }, |
| 4106 | INTERNAL, |
| 4107 | { }, |
| 4108 | { { 0, 2147483647 } }, |
| 4109 | }, |
| 4110 | { |
| 4111 | "ALU64_OR_K: dst = 0x0", |
| 4112 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4113 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4114 | BPF_LD_IMM64(R3, 0x0), |
| 4115 | BPF_ALU64_IMM(BPF_MOV, R2, 0x0), |
| 4116 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4117 | BPF_MOV32_IMM(R0, 2), |
| 4118 | BPF_EXIT_INSN(), |
| 4119 | BPF_MOV32_IMM(R0, 1), |
| 4120 | BPF_EXIT_INSN(), |
| 4121 | }, |
| 4122 | INTERNAL, |
| 4123 | { }, |
| 4124 | { { 0, 0x1 } }, |
| 4125 | }, |
| 4126 | { |
| 4127 | "ALU64_MOV_K: dst = -1", |
| 4128 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4129 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 4130 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4131 | BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff), |
| 4132 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4133 | BPF_MOV32_IMM(R0, 2), |
| 4134 | BPF_EXIT_INSN(), |
| 4135 | BPF_MOV32_IMM(R0, 1), |
| 4136 | BPF_EXIT_INSN(), |
| 4137 | }, |
| 4138 | INTERNAL, |
| 4139 | { }, |
| 4140 | { { 0, 0x1 } }, |
| 4141 | }, |
Johan Almbladh | 565731a | 2021-08-09 11:18:17 +0200 | [diff] [blame] | 4142 | { |
| 4143 | "ALU64_MOV_K: small negative", |
| 4144 | .u.insns_int = { |
| 4145 | BPF_ALU64_IMM(BPF_MOV, R0, -123), |
| 4146 | BPF_EXIT_INSN(), |
| 4147 | }, |
| 4148 | INTERNAL, |
| 4149 | { }, |
| 4150 | { { 0, -123 } } |
| 4151 | }, |
| 4152 | { |
| 4153 | "ALU64_MOV_K: small negative sign extension", |
| 4154 | .u.insns_int = { |
| 4155 | BPF_ALU64_IMM(BPF_MOV, R0, -123), |
| 4156 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 4157 | BPF_EXIT_INSN(), |
| 4158 | }, |
| 4159 | INTERNAL, |
| 4160 | { }, |
| 4161 | { { 0, 0xffffffff } } |
| 4162 | }, |
| 4163 | { |
| 4164 | "ALU64_MOV_K: large negative", |
| 4165 | .u.insns_int = { |
| 4166 | BPF_ALU64_IMM(BPF_MOV, R0, -123456789), |
| 4167 | BPF_EXIT_INSN(), |
| 4168 | }, |
| 4169 | INTERNAL, |
| 4170 | { }, |
| 4171 | { { 0, -123456789 } } |
| 4172 | }, |
| 4173 | { |
| 4174 | "ALU64_MOV_K: large negative sign extension", |
| 4175 | .u.insns_int = { |
| 4176 | BPF_ALU64_IMM(BPF_MOV, R0, -123456789), |
| 4177 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 4178 | BPF_EXIT_INSN(), |
| 4179 | }, |
| 4180 | INTERNAL, |
| 4181 | { }, |
| 4182 | { { 0, 0xffffffff } } |
| 4183 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4184 | /* BPF_ALU | BPF_ADD | BPF_X */ |
| 4185 | { |
| 4186 | "ALU_ADD_X: 1 + 2 = 3", |
| 4187 | .u.insns_int = { |
| 4188 | BPF_LD_IMM64(R0, 1), |
| 4189 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 4190 | BPF_ALU32_REG(BPF_ADD, R0, R1), |
| 4191 | BPF_EXIT_INSN(), |
| 4192 | }, |
| 4193 | INTERNAL, |
| 4194 | { }, |
| 4195 | { { 0, 3 } }, |
| 4196 | }, |
| 4197 | { |
| 4198 | "ALU_ADD_X: 1 + 4294967294 = 4294967295", |
| 4199 | .u.insns_int = { |
| 4200 | BPF_LD_IMM64(R0, 1), |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4201 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4202 | BPF_ALU32_REG(BPF_ADD, R0, R1), |
| 4203 | BPF_EXIT_INSN(), |
| 4204 | }, |
| 4205 | INTERNAL, |
| 4206 | { }, |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4207 | { { 0, 4294967295U } }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4208 | }, |
| 4209 | { |
Naveen N. Rao | b64b50e | 2016-04-05 15:32:55 +0530 | [diff] [blame] | 4210 | "ALU_ADD_X: 2 + 4294967294 = 0", |
| 4211 | .u.insns_int = { |
| 4212 | BPF_LD_IMM64(R0, 2), |
| 4213 | BPF_LD_IMM64(R1, 4294967294U), |
| 4214 | BPF_ALU32_REG(BPF_ADD, R0, R1), |
| 4215 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 2), |
| 4216 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 4217 | BPF_EXIT_INSN(), |
| 4218 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 4219 | BPF_EXIT_INSN(), |
| 4220 | }, |
| 4221 | INTERNAL, |
| 4222 | { }, |
| 4223 | { { 0, 1 } }, |
| 4224 | }, |
| 4225 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4226 | "ALU64_ADD_X: 1 + 2 = 3", |
| 4227 | .u.insns_int = { |
| 4228 | BPF_LD_IMM64(R0, 1), |
| 4229 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 4230 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 4231 | BPF_EXIT_INSN(), |
| 4232 | }, |
| 4233 | INTERNAL, |
| 4234 | { }, |
| 4235 | { { 0, 3 } }, |
| 4236 | }, |
| 4237 | { |
| 4238 | "ALU64_ADD_X: 1 + 4294967294 = 4294967295", |
| 4239 | .u.insns_int = { |
| 4240 | BPF_LD_IMM64(R0, 1), |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4241 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4242 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 4243 | BPF_EXIT_INSN(), |
| 4244 | }, |
| 4245 | INTERNAL, |
| 4246 | { }, |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4247 | { { 0, 4294967295U } }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4248 | }, |
Naveen N. Rao | b64b50e | 2016-04-05 15:32:55 +0530 | [diff] [blame] | 4249 | { |
| 4250 | "ALU64_ADD_X: 2 + 4294967294 = 4294967296", |
| 4251 | .u.insns_int = { |
| 4252 | BPF_LD_IMM64(R0, 2), |
| 4253 | BPF_LD_IMM64(R1, 4294967294U), |
| 4254 | BPF_LD_IMM64(R2, 4294967296ULL), |
| 4255 | BPF_ALU64_REG(BPF_ADD, R0, R1), |
| 4256 | BPF_JMP_REG(BPF_JEQ, R0, R2, 2), |
| 4257 | BPF_MOV32_IMM(R0, 0), |
| 4258 | BPF_EXIT_INSN(), |
| 4259 | BPF_MOV32_IMM(R0, 1), |
| 4260 | BPF_EXIT_INSN(), |
| 4261 | }, |
| 4262 | INTERNAL, |
| 4263 | { }, |
| 4264 | { { 0, 1 } }, |
| 4265 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4266 | /* BPF_ALU | BPF_ADD | BPF_K */ |
| 4267 | { |
| 4268 | "ALU_ADD_K: 1 + 2 = 3", |
| 4269 | .u.insns_int = { |
| 4270 | BPF_LD_IMM64(R0, 1), |
| 4271 | BPF_ALU32_IMM(BPF_ADD, R0, 2), |
| 4272 | BPF_EXIT_INSN(), |
| 4273 | }, |
| 4274 | INTERNAL, |
| 4275 | { }, |
| 4276 | { { 0, 3 } }, |
| 4277 | }, |
| 4278 | { |
| 4279 | "ALU_ADD_K: 3 + 0 = 3", |
| 4280 | .u.insns_int = { |
| 4281 | BPF_LD_IMM64(R0, 3), |
| 4282 | BPF_ALU32_IMM(BPF_ADD, R0, 0), |
| 4283 | BPF_EXIT_INSN(), |
| 4284 | }, |
| 4285 | INTERNAL, |
| 4286 | { }, |
| 4287 | { { 0, 3 } }, |
| 4288 | }, |
| 4289 | { |
| 4290 | "ALU_ADD_K: 1 + 4294967294 = 4294967295", |
| 4291 | .u.insns_int = { |
| 4292 | BPF_LD_IMM64(R0, 1), |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4293 | BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4294 | BPF_EXIT_INSN(), |
| 4295 | }, |
| 4296 | INTERNAL, |
| 4297 | { }, |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4298 | { { 0, 4294967295U } }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4299 | }, |
| 4300 | { |
Naveen N. Rao | b64b50e | 2016-04-05 15:32:55 +0530 | [diff] [blame] | 4301 | "ALU_ADD_K: 4294967294 + 2 = 0", |
| 4302 | .u.insns_int = { |
| 4303 | BPF_LD_IMM64(R0, 4294967294U), |
| 4304 | BPF_ALU32_IMM(BPF_ADD, R0, 2), |
| 4305 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 2), |
| 4306 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 4307 | BPF_EXIT_INSN(), |
| 4308 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 4309 | BPF_EXIT_INSN(), |
| 4310 | }, |
| 4311 | INTERNAL, |
| 4312 | { }, |
| 4313 | { { 0, 1 } }, |
| 4314 | }, |
| 4315 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4316 | "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff", |
| 4317 | .u.insns_int = { |
| 4318 | BPF_LD_IMM64(R2, 0x0), |
| 4319 | BPF_LD_IMM64(R3, 0x00000000ffffffff), |
| 4320 | BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff), |
| 4321 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4322 | BPF_MOV32_IMM(R0, 2), |
| 4323 | BPF_EXIT_INSN(), |
| 4324 | BPF_MOV32_IMM(R0, 1), |
| 4325 | BPF_EXIT_INSN(), |
| 4326 | }, |
| 4327 | INTERNAL, |
| 4328 | { }, |
| 4329 | { { 0, 0x1 } }, |
| 4330 | }, |
| 4331 | { |
Naveen N. Rao | 9c94f6c | 2016-04-05 15:32:56 +0530 | [diff] [blame] | 4332 | "ALU_ADD_K: 0 + 0xffff = 0xffff", |
| 4333 | .u.insns_int = { |
| 4334 | BPF_LD_IMM64(R2, 0x0), |
| 4335 | BPF_LD_IMM64(R3, 0xffff), |
| 4336 | BPF_ALU32_IMM(BPF_ADD, R2, 0xffff), |
| 4337 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4338 | BPF_MOV32_IMM(R0, 2), |
| 4339 | BPF_EXIT_INSN(), |
| 4340 | BPF_MOV32_IMM(R0, 1), |
| 4341 | BPF_EXIT_INSN(), |
| 4342 | }, |
| 4343 | INTERNAL, |
| 4344 | { }, |
| 4345 | { { 0, 0x1 } }, |
| 4346 | }, |
| 4347 | { |
| 4348 | "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff", |
| 4349 | .u.insns_int = { |
| 4350 | BPF_LD_IMM64(R2, 0x0), |
| 4351 | BPF_LD_IMM64(R3, 0x7fffffff), |
| 4352 | BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff), |
| 4353 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4354 | BPF_MOV32_IMM(R0, 2), |
| 4355 | BPF_EXIT_INSN(), |
| 4356 | BPF_MOV32_IMM(R0, 1), |
| 4357 | BPF_EXIT_INSN(), |
| 4358 | }, |
| 4359 | INTERNAL, |
| 4360 | { }, |
| 4361 | { { 0, 0x1 } }, |
| 4362 | }, |
| 4363 | { |
| 4364 | "ALU_ADD_K: 0 + 0x80000000 = 0x80000000", |
| 4365 | .u.insns_int = { |
| 4366 | BPF_LD_IMM64(R2, 0x0), |
| 4367 | BPF_LD_IMM64(R3, 0x80000000), |
| 4368 | BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000), |
| 4369 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4370 | BPF_MOV32_IMM(R0, 2), |
| 4371 | BPF_EXIT_INSN(), |
| 4372 | BPF_MOV32_IMM(R0, 1), |
| 4373 | BPF_EXIT_INSN(), |
| 4374 | }, |
| 4375 | INTERNAL, |
| 4376 | { }, |
| 4377 | { { 0, 0x1 } }, |
| 4378 | }, |
| 4379 | { |
| 4380 | "ALU_ADD_K: 0 + 0x80008000 = 0x80008000", |
| 4381 | .u.insns_int = { |
| 4382 | BPF_LD_IMM64(R2, 0x0), |
| 4383 | BPF_LD_IMM64(R3, 0x80008000), |
| 4384 | BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000), |
| 4385 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4386 | BPF_MOV32_IMM(R0, 2), |
| 4387 | BPF_EXIT_INSN(), |
| 4388 | BPF_MOV32_IMM(R0, 1), |
| 4389 | BPF_EXIT_INSN(), |
| 4390 | }, |
| 4391 | INTERNAL, |
| 4392 | { }, |
| 4393 | { { 0, 0x1 } }, |
| 4394 | }, |
| 4395 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4396 | "ALU64_ADD_K: 1 + 2 = 3", |
| 4397 | .u.insns_int = { |
| 4398 | BPF_LD_IMM64(R0, 1), |
| 4399 | BPF_ALU64_IMM(BPF_ADD, R0, 2), |
| 4400 | BPF_EXIT_INSN(), |
| 4401 | }, |
| 4402 | INTERNAL, |
| 4403 | { }, |
| 4404 | { { 0, 3 } }, |
| 4405 | }, |
| 4406 | { |
| 4407 | "ALU64_ADD_K: 3 + 0 = 3", |
| 4408 | .u.insns_int = { |
| 4409 | BPF_LD_IMM64(R0, 3), |
| 4410 | BPF_ALU64_IMM(BPF_ADD, R0, 0), |
| 4411 | BPF_EXIT_INSN(), |
| 4412 | }, |
| 4413 | INTERNAL, |
| 4414 | { }, |
| 4415 | { { 0, 3 } }, |
| 4416 | }, |
| 4417 | { |
| 4418 | "ALU64_ADD_K: 1 + 2147483646 = 2147483647", |
| 4419 | .u.insns_int = { |
| 4420 | BPF_LD_IMM64(R0, 1), |
| 4421 | BPF_ALU64_IMM(BPF_ADD, R0, 2147483646), |
| 4422 | BPF_EXIT_INSN(), |
| 4423 | }, |
| 4424 | INTERNAL, |
| 4425 | { }, |
| 4426 | { { 0, 2147483647 } }, |
| 4427 | }, |
| 4428 | { |
Naveen N. Rao | b64b50e | 2016-04-05 15:32:55 +0530 | [diff] [blame] | 4429 | "ALU64_ADD_K: 4294967294 + 2 = 4294967296", |
| 4430 | .u.insns_int = { |
| 4431 | BPF_LD_IMM64(R0, 4294967294U), |
| 4432 | BPF_LD_IMM64(R1, 4294967296ULL), |
| 4433 | BPF_ALU64_IMM(BPF_ADD, R0, 2), |
| 4434 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 4435 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 4436 | BPF_EXIT_INSN(), |
| 4437 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 4438 | BPF_EXIT_INSN(), |
| 4439 | }, |
| 4440 | INTERNAL, |
| 4441 | { }, |
| 4442 | { { 0, 1 } }, |
| 4443 | }, |
| 4444 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4445 | "ALU64_ADD_K: 2147483646 + -2147483647 = -1", |
| 4446 | .u.insns_int = { |
| 4447 | BPF_LD_IMM64(R0, 2147483646), |
| 4448 | BPF_ALU64_IMM(BPF_ADD, R0, -2147483647), |
| 4449 | BPF_EXIT_INSN(), |
| 4450 | }, |
| 4451 | INTERNAL, |
| 4452 | { }, |
| 4453 | { { 0, -1 } }, |
| 4454 | }, |
| 4455 | { |
| 4456 | "ALU64_ADD_K: 1 + 0 = 1", |
| 4457 | .u.insns_int = { |
| 4458 | BPF_LD_IMM64(R2, 0x1), |
| 4459 | BPF_LD_IMM64(R3, 0x1), |
| 4460 | BPF_ALU64_IMM(BPF_ADD, R2, 0x0), |
| 4461 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4462 | BPF_MOV32_IMM(R0, 2), |
| 4463 | BPF_EXIT_INSN(), |
| 4464 | BPF_MOV32_IMM(R0, 1), |
| 4465 | BPF_EXIT_INSN(), |
| 4466 | }, |
| 4467 | INTERNAL, |
| 4468 | { }, |
| 4469 | { { 0, 0x1 } }, |
| 4470 | }, |
| 4471 | { |
| 4472 | "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff", |
| 4473 | .u.insns_int = { |
| 4474 | BPF_LD_IMM64(R2, 0x0), |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4475 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4476 | BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff), |
| 4477 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4478 | BPF_MOV32_IMM(R0, 2), |
| 4479 | BPF_EXIT_INSN(), |
| 4480 | BPF_MOV32_IMM(R0, 1), |
| 4481 | BPF_EXIT_INSN(), |
| 4482 | }, |
| 4483 | INTERNAL, |
| 4484 | { }, |
| 4485 | { { 0, 0x1 } }, |
| 4486 | }, |
Naveen N. Rao | 9c94f6c | 2016-04-05 15:32:56 +0530 | [diff] [blame] | 4487 | { |
| 4488 | "ALU64_ADD_K: 0 + 0xffff = 0xffff", |
| 4489 | .u.insns_int = { |
| 4490 | BPF_LD_IMM64(R2, 0x0), |
| 4491 | BPF_LD_IMM64(R3, 0xffff), |
| 4492 | BPF_ALU64_IMM(BPF_ADD, R2, 0xffff), |
| 4493 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4494 | BPF_MOV32_IMM(R0, 2), |
| 4495 | BPF_EXIT_INSN(), |
| 4496 | BPF_MOV32_IMM(R0, 1), |
| 4497 | BPF_EXIT_INSN(), |
| 4498 | }, |
| 4499 | INTERNAL, |
| 4500 | { }, |
| 4501 | { { 0, 0x1 } }, |
| 4502 | }, |
| 4503 | { |
| 4504 | "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff", |
| 4505 | .u.insns_int = { |
| 4506 | BPF_LD_IMM64(R2, 0x0), |
| 4507 | BPF_LD_IMM64(R3, 0x7fffffff), |
| 4508 | BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff), |
| 4509 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4510 | BPF_MOV32_IMM(R0, 2), |
| 4511 | BPF_EXIT_INSN(), |
| 4512 | BPF_MOV32_IMM(R0, 1), |
| 4513 | BPF_EXIT_INSN(), |
| 4514 | }, |
| 4515 | INTERNAL, |
| 4516 | { }, |
| 4517 | { { 0, 0x1 } }, |
| 4518 | }, |
| 4519 | { |
| 4520 | "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000", |
| 4521 | .u.insns_int = { |
| 4522 | BPF_LD_IMM64(R2, 0x0), |
| 4523 | BPF_LD_IMM64(R3, 0xffffffff80000000LL), |
| 4524 | BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000), |
| 4525 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4526 | BPF_MOV32_IMM(R0, 2), |
| 4527 | BPF_EXIT_INSN(), |
| 4528 | BPF_MOV32_IMM(R0, 1), |
| 4529 | BPF_EXIT_INSN(), |
| 4530 | }, |
| 4531 | INTERNAL, |
| 4532 | { }, |
| 4533 | { { 0, 0x1 } }, |
| 4534 | }, |
| 4535 | { |
| 4536 | "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000", |
| 4537 | .u.insns_int = { |
| 4538 | BPF_LD_IMM64(R2, 0x0), |
| 4539 | BPF_LD_IMM64(R3, 0xffffffff80008000LL), |
| 4540 | BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000), |
| 4541 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4542 | BPF_MOV32_IMM(R0, 2), |
| 4543 | BPF_EXIT_INSN(), |
| 4544 | BPF_MOV32_IMM(R0, 1), |
| 4545 | BPF_EXIT_INSN(), |
| 4546 | }, |
| 4547 | INTERNAL, |
| 4548 | { }, |
| 4549 | { { 0, 0x1 } }, |
| 4550 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4551 | /* BPF_ALU | BPF_SUB | BPF_X */ |
| 4552 | { |
| 4553 | "ALU_SUB_X: 3 - 1 = 2", |
| 4554 | .u.insns_int = { |
| 4555 | BPF_LD_IMM64(R0, 3), |
| 4556 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 4557 | BPF_ALU32_REG(BPF_SUB, R0, R1), |
| 4558 | BPF_EXIT_INSN(), |
| 4559 | }, |
| 4560 | INTERNAL, |
| 4561 | { }, |
| 4562 | { { 0, 2 } }, |
| 4563 | }, |
| 4564 | { |
| 4565 | "ALU_SUB_X: 4294967295 - 4294967294 = 1", |
| 4566 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4567 | BPF_LD_IMM64(R0, 4294967295U), |
| 4568 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4569 | BPF_ALU32_REG(BPF_SUB, R0, R1), |
| 4570 | BPF_EXIT_INSN(), |
| 4571 | }, |
| 4572 | INTERNAL, |
| 4573 | { }, |
| 4574 | { { 0, 1 } }, |
| 4575 | }, |
| 4576 | { |
| 4577 | "ALU64_SUB_X: 3 - 1 = 2", |
| 4578 | .u.insns_int = { |
| 4579 | BPF_LD_IMM64(R0, 3), |
| 4580 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 4581 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 4582 | BPF_EXIT_INSN(), |
| 4583 | }, |
| 4584 | INTERNAL, |
| 4585 | { }, |
| 4586 | { { 0, 2 } }, |
| 4587 | }, |
| 4588 | { |
| 4589 | "ALU64_SUB_X: 4294967295 - 4294967294 = 1", |
| 4590 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4591 | BPF_LD_IMM64(R0, 4294967295U), |
| 4592 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4593 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 4594 | BPF_EXIT_INSN(), |
| 4595 | }, |
| 4596 | INTERNAL, |
| 4597 | { }, |
| 4598 | { { 0, 1 } }, |
| 4599 | }, |
| 4600 | /* BPF_ALU | BPF_SUB | BPF_K */ |
| 4601 | { |
| 4602 | "ALU_SUB_K: 3 - 1 = 2", |
| 4603 | .u.insns_int = { |
| 4604 | BPF_LD_IMM64(R0, 3), |
| 4605 | BPF_ALU32_IMM(BPF_SUB, R0, 1), |
| 4606 | BPF_EXIT_INSN(), |
| 4607 | }, |
| 4608 | INTERNAL, |
| 4609 | { }, |
| 4610 | { { 0, 2 } }, |
| 4611 | }, |
| 4612 | { |
| 4613 | "ALU_SUB_K: 3 - 0 = 3", |
| 4614 | .u.insns_int = { |
| 4615 | BPF_LD_IMM64(R0, 3), |
| 4616 | BPF_ALU32_IMM(BPF_SUB, R0, 0), |
| 4617 | BPF_EXIT_INSN(), |
| 4618 | }, |
| 4619 | INTERNAL, |
| 4620 | { }, |
| 4621 | { { 0, 3 } }, |
| 4622 | }, |
| 4623 | { |
| 4624 | "ALU_SUB_K: 4294967295 - 4294967294 = 1", |
| 4625 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4626 | BPF_LD_IMM64(R0, 4294967295U), |
| 4627 | BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4628 | BPF_EXIT_INSN(), |
| 4629 | }, |
| 4630 | INTERNAL, |
| 4631 | { }, |
| 4632 | { { 0, 1 } }, |
| 4633 | }, |
| 4634 | { |
| 4635 | "ALU64_SUB_K: 3 - 1 = 2", |
| 4636 | .u.insns_int = { |
| 4637 | BPF_LD_IMM64(R0, 3), |
| 4638 | BPF_ALU64_IMM(BPF_SUB, R0, 1), |
| 4639 | BPF_EXIT_INSN(), |
| 4640 | }, |
| 4641 | INTERNAL, |
| 4642 | { }, |
| 4643 | { { 0, 2 } }, |
| 4644 | }, |
| 4645 | { |
| 4646 | "ALU64_SUB_K: 3 - 0 = 3", |
| 4647 | .u.insns_int = { |
| 4648 | BPF_LD_IMM64(R0, 3), |
| 4649 | BPF_ALU64_IMM(BPF_SUB, R0, 0), |
| 4650 | BPF_EXIT_INSN(), |
| 4651 | }, |
| 4652 | INTERNAL, |
| 4653 | { }, |
| 4654 | { { 0, 3 } }, |
| 4655 | }, |
| 4656 | { |
| 4657 | "ALU64_SUB_K: 4294967294 - 4294967295 = -1", |
| 4658 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4659 | BPF_LD_IMM64(R0, 4294967294U), |
| 4660 | BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4661 | BPF_EXIT_INSN(), |
| 4662 | }, |
| 4663 | INTERNAL, |
| 4664 | { }, |
| 4665 | { { 0, -1 } }, |
| 4666 | }, |
| 4667 | { |
| 4668 | "ALU64_ADD_K: 2147483646 - 2147483647 = -1", |
| 4669 | .u.insns_int = { |
| 4670 | BPF_LD_IMM64(R0, 2147483646), |
| 4671 | BPF_ALU64_IMM(BPF_SUB, R0, 2147483647), |
| 4672 | BPF_EXIT_INSN(), |
| 4673 | }, |
| 4674 | INTERNAL, |
| 4675 | { }, |
| 4676 | { { 0, -1 } }, |
| 4677 | }, |
| 4678 | /* BPF_ALU | BPF_MUL | BPF_X */ |
| 4679 | { |
| 4680 | "ALU_MUL_X: 2 * 3 = 6", |
| 4681 | .u.insns_int = { |
| 4682 | BPF_LD_IMM64(R0, 2), |
| 4683 | BPF_ALU32_IMM(BPF_MOV, R1, 3), |
| 4684 | BPF_ALU32_REG(BPF_MUL, R0, R1), |
| 4685 | BPF_EXIT_INSN(), |
| 4686 | }, |
| 4687 | INTERNAL, |
| 4688 | { }, |
| 4689 | { { 0, 6 } }, |
| 4690 | }, |
| 4691 | { |
| 4692 | "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0", |
| 4693 | .u.insns_int = { |
| 4694 | BPF_LD_IMM64(R0, 2), |
| 4695 | BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8), |
| 4696 | BPF_ALU32_REG(BPF_MUL, R0, R1), |
| 4697 | BPF_EXIT_INSN(), |
| 4698 | }, |
| 4699 | INTERNAL, |
| 4700 | { }, |
| 4701 | { { 0, 0xFFFFFFF0 } }, |
| 4702 | }, |
| 4703 | { |
| 4704 | "ALU_MUL_X: -1 * -1 = 1", |
| 4705 | .u.insns_int = { |
| 4706 | BPF_LD_IMM64(R0, -1), |
| 4707 | BPF_ALU32_IMM(BPF_MOV, R1, -1), |
| 4708 | BPF_ALU32_REG(BPF_MUL, R0, R1), |
| 4709 | BPF_EXIT_INSN(), |
| 4710 | }, |
| 4711 | INTERNAL, |
| 4712 | { }, |
| 4713 | { { 0, 1 } }, |
| 4714 | }, |
| 4715 | { |
| 4716 | "ALU64_MUL_X: 2 * 3 = 6", |
| 4717 | .u.insns_int = { |
| 4718 | BPF_LD_IMM64(R0, 2), |
| 4719 | BPF_ALU32_IMM(BPF_MOV, R1, 3), |
| 4720 | BPF_ALU64_REG(BPF_MUL, R0, R1), |
| 4721 | BPF_EXIT_INSN(), |
| 4722 | }, |
| 4723 | INTERNAL, |
| 4724 | { }, |
| 4725 | { { 0, 6 } }, |
| 4726 | }, |
| 4727 | { |
| 4728 | "ALU64_MUL_X: 1 * 2147483647 = 2147483647", |
| 4729 | .u.insns_int = { |
| 4730 | BPF_LD_IMM64(R0, 1), |
| 4731 | BPF_ALU32_IMM(BPF_MOV, R1, 2147483647), |
| 4732 | BPF_ALU64_REG(BPF_MUL, R0, R1), |
| 4733 | BPF_EXIT_INSN(), |
| 4734 | }, |
| 4735 | INTERNAL, |
| 4736 | { }, |
| 4737 | { { 0, 2147483647 } }, |
| 4738 | }, |
Johan Almbladh | faa5762 | 2021-08-09 11:18:22 +0200 | [diff] [blame] | 4739 | { |
| 4740 | "ALU64_MUL_X: 64x64 multiply, low word", |
| 4741 | .u.insns_int = { |
| 4742 | BPF_LD_IMM64(R0, 0x0fedcba987654321LL), |
| 4743 | BPF_LD_IMM64(R1, 0x123456789abcdef0LL), |
| 4744 | BPF_ALU64_REG(BPF_MUL, R0, R1), |
| 4745 | BPF_EXIT_INSN(), |
| 4746 | }, |
| 4747 | INTERNAL, |
| 4748 | { }, |
| 4749 | { { 0, 0xe5618cf0 } } |
| 4750 | }, |
| 4751 | { |
| 4752 | "ALU64_MUL_X: 64x64 multiply, high word", |
| 4753 | .u.insns_int = { |
| 4754 | BPF_LD_IMM64(R0, 0x0fedcba987654321LL), |
| 4755 | BPF_LD_IMM64(R1, 0x123456789abcdef0LL), |
| 4756 | BPF_ALU64_REG(BPF_MUL, R0, R1), |
| 4757 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 4758 | BPF_EXIT_INSN(), |
| 4759 | }, |
| 4760 | INTERNAL, |
| 4761 | { }, |
| 4762 | { { 0, 0x2236d88f } } |
| 4763 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4764 | /* BPF_ALU | BPF_MUL | BPF_K */ |
| 4765 | { |
| 4766 | "ALU_MUL_K: 2 * 3 = 6", |
| 4767 | .u.insns_int = { |
| 4768 | BPF_LD_IMM64(R0, 2), |
| 4769 | BPF_ALU32_IMM(BPF_MUL, R0, 3), |
| 4770 | BPF_EXIT_INSN(), |
| 4771 | }, |
| 4772 | INTERNAL, |
| 4773 | { }, |
| 4774 | { { 0, 6 } }, |
| 4775 | }, |
| 4776 | { |
| 4777 | "ALU_MUL_K: 3 * 1 = 3", |
| 4778 | .u.insns_int = { |
| 4779 | BPF_LD_IMM64(R0, 3), |
| 4780 | BPF_ALU32_IMM(BPF_MUL, R0, 1), |
| 4781 | BPF_EXIT_INSN(), |
| 4782 | }, |
| 4783 | INTERNAL, |
| 4784 | { }, |
| 4785 | { { 0, 3 } }, |
| 4786 | }, |
| 4787 | { |
| 4788 | "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0", |
| 4789 | .u.insns_int = { |
| 4790 | BPF_LD_IMM64(R0, 2), |
| 4791 | BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8), |
| 4792 | BPF_EXIT_INSN(), |
| 4793 | }, |
| 4794 | INTERNAL, |
| 4795 | { }, |
| 4796 | { { 0, 0xFFFFFFF0 } }, |
| 4797 | }, |
| 4798 | { |
| 4799 | "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff", |
| 4800 | .u.insns_int = { |
| 4801 | BPF_LD_IMM64(R2, 0x1), |
| 4802 | BPF_LD_IMM64(R3, 0x00000000ffffffff), |
| 4803 | BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff), |
| 4804 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4805 | BPF_MOV32_IMM(R0, 2), |
| 4806 | BPF_EXIT_INSN(), |
| 4807 | BPF_MOV32_IMM(R0, 1), |
| 4808 | BPF_EXIT_INSN(), |
| 4809 | }, |
| 4810 | INTERNAL, |
| 4811 | { }, |
| 4812 | { { 0, 0x1 } }, |
| 4813 | }, |
| 4814 | { |
| 4815 | "ALU64_MUL_K: 2 * 3 = 6", |
| 4816 | .u.insns_int = { |
| 4817 | BPF_LD_IMM64(R0, 2), |
| 4818 | BPF_ALU64_IMM(BPF_MUL, R0, 3), |
| 4819 | BPF_EXIT_INSN(), |
| 4820 | }, |
| 4821 | INTERNAL, |
| 4822 | { }, |
| 4823 | { { 0, 6 } }, |
| 4824 | }, |
| 4825 | { |
| 4826 | "ALU64_MUL_K: 3 * 1 = 3", |
| 4827 | .u.insns_int = { |
| 4828 | BPF_LD_IMM64(R0, 3), |
| 4829 | BPF_ALU64_IMM(BPF_MUL, R0, 1), |
| 4830 | BPF_EXIT_INSN(), |
| 4831 | }, |
| 4832 | INTERNAL, |
| 4833 | { }, |
| 4834 | { { 0, 3 } }, |
| 4835 | }, |
| 4836 | { |
| 4837 | "ALU64_MUL_K: 1 * 2147483647 = 2147483647", |
| 4838 | .u.insns_int = { |
| 4839 | BPF_LD_IMM64(R0, 1), |
| 4840 | BPF_ALU64_IMM(BPF_MUL, R0, 2147483647), |
| 4841 | BPF_EXIT_INSN(), |
| 4842 | }, |
| 4843 | INTERNAL, |
| 4844 | { }, |
| 4845 | { { 0, 2147483647 } }, |
| 4846 | }, |
| 4847 | { |
| 4848 | "ALU64_MUL_K: 1 * -2147483647 = -2147483647", |
| 4849 | .u.insns_int = { |
| 4850 | BPF_LD_IMM64(R0, 1), |
| 4851 | BPF_ALU64_IMM(BPF_MUL, R0, -2147483647), |
| 4852 | BPF_EXIT_INSN(), |
| 4853 | }, |
| 4854 | INTERNAL, |
| 4855 | { }, |
| 4856 | { { 0, -2147483647 } }, |
| 4857 | }, |
| 4858 | { |
| 4859 | "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff", |
| 4860 | .u.insns_int = { |
| 4861 | BPF_LD_IMM64(R2, 0x1), |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4862 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4863 | BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff), |
| 4864 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4865 | BPF_MOV32_IMM(R0, 2), |
| 4866 | BPF_EXIT_INSN(), |
| 4867 | BPF_MOV32_IMM(R0, 1), |
| 4868 | BPF_EXIT_INSN(), |
| 4869 | }, |
| 4870 | INTERNAL, |
| 4871 | { }, |
| 4872 | { { 0, 0x1 } }, |
| 4873 | }, |
Johan Almbladh | faa5762 | 2021-08-09 11:18:22 +0200 | [diff] [blame] | 4874 | { |
| 4875 | "ALU64_MUL_K: 64x32 multiply, low word", |
| 4876 | .u.insns_int = { |
| 4877 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 4878 | BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678), |
| 4879 | BPF_EXIT_INSN(), |
| 4880 | }, |
| 4881 | INTERNAL, |
| 4882 | { }, |
| 4883 | { { 0, 0xe242d208 } } |
| 4884 | }, |
| 4885 | { |
| 4886 | "ALU64_MUL_K: 64x32 multiply, high word", |
| 4887 | .u.insns_int = { |
| 4888 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 4889 | BPF_ALU64_IMM(BPF_MUL, R0, 0x12345678), |
| 4890 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 4891 | BPF_EXIT_INSN(), |
| 4892 | }, |
| 4893 | INTERNAL, |
| 4894 | { }, |
| 4895 | { { 0, 0xc28f5c28 } } |
| 4896 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4897 | /* BPF_ALU | BPF_DIV | BPF_X */ |
| 4898 | { |
| 4899 | "ALU_DIV_X: 6 / 2 = 3", |
| 4900 | .u.insns_int = { |
| 4901 | BPF_LD_IMM64(R0, 6), |
| 4902 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 4903 | BPF_ALU32_REG(BPF_DIV, R0, R1), |
| 4904 | BPF_EXIT_INSN(), |
| 4905 | }, |
| 4906 | INTERNAL, |
| 4907 | { }, |
| 4908 | { { 0, 3 } }, |
| 4909 | }, |
| 4910 | { |
| 4911 | "ALU_DIV_X: 4294967295 / 4294967295 = 1", |
| 4912 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4913 | BPF_LD_IMM64(R0, 4294967295U), |
| 4914 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4915 | BPF_ALU32_REG(BPF_DIV, R0, R1), |
| 4916 | BPF_EXIT_INSN(), |
| 4917 | }, |
| 4918 | INTERNAL, |
| 4919 | { }, |
| 4920 | { { 0, 1 } }, |
| 4921 | }, |
| 4922 | { |
| 4923 | "ALU64_DIV_X: 6 / 2 = 3", |
| 4924 | .u.insns_int = { |
| 4925 | BPF_LD_IMM64(R0, 6), |
| 4926 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 4927 | BPF_ALU64_REG(BPF_DIV, R0, R1), |
| 4928 | BPF_EXIT_INSN(), |
| 4929 | }, |
| 4930 | INTERNAL, |
| 4931 | { }, |
| 4932 | { { 0, 3 } }, |
| 4933 | }, |
| 4934 | { |
| 4935 | "ALU64_DIV_X: 2147483647 / 2147483647 = 1", |
| 4936 | .u.insns_int = { |
| 4937 | BPF_LD_IMM64(R0, 2147483647), |
| 4938 | BPF_ALU32_IMM(BPF_MOV, R1, 2147483647), |
| 4939 | BPF_ALU64_REG(BPF_DIV, R0, R1), |
| 4940 | BPF_EXIT_INSN(), |
| 4941 | }, |
| 4942 | INTERNAL, |
| 4943 | { }, |
| 4944 | { { 0, 1 } }, |
| 4945 | }, |
| 4946 | { |
| 4947 | "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001", |
| 4948 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4949 | BPF_LD_IMM64(R2, 0xffffffffffffffffLL), |
| 4950 | BPF_LD_IMM64(R4, 0xffffffffffffffffLL), |
| 4951 | BPF_LD_IMM64(R3, 0x0000000000000001LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4952 | BPF_ALU64_REG(BPF_DIV, R2, R4), |
| 4953 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 4954 | BPF_MOV32_IMM(R0, 2), |
| 4955 | BPF_EXIT_INSN(), |
| 4956 | BPF_MOV32_IMM(R0, 1), |
| 4957 | BPF_EXIT_INSN(), |
| 4958 | }, |
| 4959 | INTERNAL, |
| 4960 | { }, |
| 4961 | { { 0, 0x1 } }, |
| 4962 | }, |
| 4963 | /* BPF_ALU | BPF_DIV | BPF_K */ |
| 4964 | { |
| 4965 | "ALU_DIV_K: 6 / 2 = 3", |
| 4966 | .u.insns_int = { |
| 4967 | BPF_LD_IMM64(R0, 6), |
| 4968 | BPF_ALU32_IMM(BPF_DIV, R0, 2), |
| 4969 | BPF_EXIT_INSN(), |
| 4970 | }, |
| 4971 | INTERNAL, |
| 4972 | { }, |
| 4973 | { { 0, 3 } }, |
| 4974 | }, |
| 4975 | { |
| 4976 | "ALU_DIV_K: 3 / 1 = 3", |
| 4977 | .u.insns_int = { |
| 4978 | BPF_LD_IMM64(R0, 3), |
| 4979 | BPF_ALU32_IMM(BPF_DIV, R0, 1), |
| 4980 | BPF_EXIT_INSN(), |
| 4981 | }, |
| 4982 | INTERNAL, |
| 4983 | { }, |
| 4984 | { { 0, 3 } }, |
| 4985 | }, |
| 4986 | { |
| 4987 | "ALU_DIV_K: 4294967295 / 4294967295 = 1", |
| 4988 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 4989 | BPF_LD_IMM64(R0, 4294967295U), |
| 4990 | BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 4991 | BPF_EXIT_INSN(), |
| 4992 | }, |
| 4993 | INTERNAL, |
| 4994 | { }, |
| 4995 | { { 0, 1 } }, |
| 4996 | }, |
| 4997 | { |
| 4998 | "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1", |
| 4999 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5000 | BPF_LD_IMM64(R2, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5001 | BPF_LD_IMM64(R3, 0x1UL), |
| 5002 | BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff), |
| 5003 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5004 | BPF_MOV32_IMM(R0, 2), |
| 5005 | BPF_EXIT_INSN(), |
| 5006 | BPF_MOV32_IMM(R0, 1), |
| 5007 | BPF_EXIT_INSN(), |
| 5008 | }, |
| 5009 | INTERNAL, |
| 5010 | { }, |
| 5011 | { { 0, 0x1 } }, |
| 5012 | }, |
| 5013 | { |
| 5014 | "ALU64_DIV_K: 6 / 2 = 3", |
| 5015 | .u.insns_int = { |
| 5016 | BPF_LD_IMM64(R0, 6), |
| 5017 | BPF_ALU64_IMM(BPF_DIV, R0, 2), |
| 5018 | BPF_EXIT_INSN(), |
| 5019 | }, |
| 5020 | INTERNAL, |
| 5021 | { }, |
| 5022 | { { 0, 3 } }, |
| 5023 | }, |
| 5024 | { |
| 5025 | "ALU64_DIV_K: 3 / 1 = 3", |
| 5026 | .u.insns_int = { |
| 5027 | BPF_LD_IMM64(R0, 3), |
| 5028 | BPF_ALU64_IMM(BPF_DIV, R0, 1), |
| 5029 | BPF_EXIT_INSN(), |
| 5030 | }, |
| 5031 | INTERNAL, |
| 5032 | { }, |
| 5033 | { { 0, 3 } }, |
| 5034 | }, |
| 5035 | { |
| 5036 | "ALU64_DIV_K: 2147483647 / 2147483647 = 1", |
| 5037 | .u.insns_int = { |
| 5038 | BPF_LD_IMM64(R0, 2147483647), |
| 5039 | BPF_ALU64_IMM(BPF_DIV, R0, 2147483647), |
| 5040 | BPF_EXIT_INSN(), |
| 5041 | }, |
| 5042 | INTERNAL, |
| 5043 | { }, |
| 5044 | { { 0, 1 } }, |
| 5045 | }, |
| 5046 | { |
| 5047 | "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001", |
| 5048 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5049 | BPF_LD_IMM64(R2, 0xffffffffffffffffLL), |
| 5050 | BPF_LD_IMM64(R3, 0x0000000000000001LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5051 | BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff), |
| 5052 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5053 | BPF_MOV32_IMM(R0, 2), |
| 5054 | BPF_EXIT_INSN(), |
| 5055 | BPF_MOV32_IMM(R0, 1), |
| 5056 | BPF_EXIT_INSN(), |
| 5057 | }, |
| 5058 | INTERNAL, |
| 5059 | { }, |
| 5060 | { { 0, 0x1 } }, |
| 5061 | }, |
| 5062 | /* BPF_ALU | BPF_MOD | BPF_X */ |
| 5063 | { |
| 5064 | "ALU_MOD_X: 3 % 2 = 1", |
| 5065 | .u.insns_int = { |
| 5066 | BPF_LD_IMM64(R0, 3), |
| 5067 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 5068 | BPF_ALU32_REG(BPF_MOD, R0, R1), |
| 5069 | BPF_EXIT_INSN(), |
| 5070 | }, |
| 5071 | INTERNAL, |
| 5072 | { }, |
| 5073 | { { 0, 1 } }, |
| 5074 | }, |
| 5075 | { |
| 5076 | "ALU_MOD_X: 4294967295 % 4294967293 = 2", |
| 5077 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5078 | BPF_LD_IMM64(R0, 4294967295U), |
| 5079 | BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5080 | BPF_ALU32_REG(BPF_MOD, R0, R1), |
| 5081 | BPF_EXIT_INSN(), |
| 5082 | }, |
| 5083 | INTERNAL, |
| 5084 | { }, |
| 5085 | { { 0, 2 } }, |
| 5086 | }, |
| 5087 | { |
| 5088 | "ALU64_MOD_X: 3 % 2 = 1", |
| 5089 | .u.insns_int = { |
| 5090 | BPF_LD_IMM64(R0, 3), |
| 5091 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 5092 | BPF_ALU64_REG(BPF_MOD, R0, R1), |
| 5093 | BPF_EXIT_INSN(), |
| 5094 | }, |
| 5095 | INTERNAL, |
| 5096 | { }, |
| 5097 | { { 0, 1 } }, |
| 5098 | }, |
| 5099 | { |
| 5100 | "ALU64_MOD_X: 2147483647 % 2147483645 = 2", |
| 5101 | .u.insns_int = { |
| 5102 | BPF_LD_IMM64(R0, 2147483647), |
| 5103 | BPF_ALU32_IMM(BPF_MOV, R1, 2147483645), |
| 5104 | BPF_ALU64_REG(BPF_MOD, R0, R1), |
| 5105 | BPF_EXIT_INSN(), |
| 5106 | }, |
| 5107 | INTERNAL, |
| 5108 | { }, |
| 5109 | { { 0, 2 } }, |
| 5110 | }, |
| 5111 | /* BPF_ALU | BPF_MOD | BPF_K */ |
| 5112 | { |
| 5113 | "ALU_MOD_K: 3 % 2 = 1", |
| 5114 | .u.insns_int = { |
| 5115 | BPF_LD_IMM64(R0, 3), |
| 5116 | BPF_ALU32_IMM(BPF_MOD, R0, 2), |
| 5117 | BPF_EXIT_INSN(), |
| 5118 | }, |
| 5119 | INTERNAL, |
| 5120 | { }, |
| 5121 | { { 0, 1 } }, |
| 5122 | }, |
| 5123 | { |
| 5124 | "ALU_MOD_K: 3 % 1 = 0", |
| 5125 | .u.insns_int = { |
| 5126 | BPF_LD_IMM64(R0, 3), |
| 5127 | BPF_ALU32_IMM(BPF_MOD, R0, 1), |
| 5128 | BPF_EXIT_INSN(), |
| 5129 | }, |
| 5130 | INTERNAL, |
| 5131 | { }, |
| 5132 | { { 0, 0 } }, |
| 5133 | }, |
| 5134 | { |
| 5135 | "ALU_MOD_K: 4294967295 % 4294967293 = 2", |
| 5136 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5137 | BPF_LD_IMM64(R0, 4294967295U), |
| 5138 | BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5139 | BPF_EXIT_INSN(), |
| 5140 | }, |
| 5141 | INTERNAL, |
| 5142 | { }, |
| 5143 | { { 0, 2 } }, |
| 5144 | }, |
| 5145 | { |
| 5146 | "ALU64_MOD_K: 3 % 2 = 1", |
| 5147 | .u.insns_int = { |
| 5148 | BPF_LD_IMM64(R0, 3), |
| 5149 | BPF_ALU64_IMM(BPF_MOD, R0, 2), |
| 5150 | BPF_EXIT_INSN(), |
| 5151 | }, |
| 5152 | INTERNAL, |
| 5153 | { }, |
| 5154 | { { 0, 1 } }, |
| 5155 | }, |
| 5156 | { |
| 5157 | "ALU64_MOD_K: 3 % 1 = 0", |
| 5158 | .u.insns_int = { |
| 5159 | BPF_LD_IMM64(R0, 3), |
| 5160 | BPF_ALU64_IMM(BPF_MOD, R0, 1), |
| 5161 | BPF_EXIT_INSN(), |
| 5162 | }, |
| 5163 | INTERNAL, |
| 5164 | { }, |
| 5165 | { { 0, 0 } }, |
| 5166 | }, |
| 5167 | { |
| 5168 | "ALU64_MOD_K: 2147483647 % 2147483645 = 2", |
| 5169 | .u.insns_int = { |
| 5170 | BPF_LD_IMM64(R0, 2147483647), |
| 5171 | BPF_ALU64_IMM(BPF_MOD, R0, 2147483645), |
| 5172 | BPF_EXIT_INSN(), |
| 5173 | }, |
| 5174 | INTERNAL, |
| 5175 | { }, |
| 5176 | { { 0, 2 } }, |
| 5177 | }, |
| 5178 | /* BPF_ALU | BPF_AND | BPF_X */ |
| 5179 | { |
| 5180 | "ALU_AND_X: 3 & 2 = 2", |
| 5181 | .u.insns_int = { |
| 5182 | BPF_LD_IMM64(R0, 3), |
| 5183 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 5184 | BPF_ALU32_REG(BPF_AND, R0, R1), |
| 5185 | BPF_EXIT_INSN(), |
| 5186 | }, |
| 5187 | INTERNAL, |
| 5188 | { }, |
| 5189 | { { 0, 2 } }, |
| 5190 | }, |
| 5191 | { |
| 5192 | "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff", |
| 5193 | .u.insns_int = { |
| 5194 | BPF_LD_IMM64(R0, 0xffffffff), |
| 5195 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 5196 | BPF_ALU32_REG(BPF_AND, R0, R1), |
| 5197 | BPF_EXIT_INSN(), |
| 5198 | }, |
| 5199 | INTERNAL, |
| 5200 | { }, |
| 5201 | { { 0, 0xffffffff } }, |
| 5202 | }, |
| 5203 | { |
| 5204 | "ALU64_AND_X: 3 & 2 = 2", |
| 5205 | .u.insns_int = { |
| 5206 | BPF_LD_IMM64(R0, 3), |
| 5207 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 5208 | BPF_ALU64_REG(BPF_AND, R0, R1), |
| 5209 | BPF_EXIT_INSN(), |
| 5210 | }, |
| 5211 | INTERNAL, |
| 5212 | { }, |
| 5213 | { { 0, 2 } }, |
| 5214 | }, |
| 5215 | { |
| 5216 | "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff", |
| 5217 | .u.insns_int = { |
| 5218 | BPF_LD_IMM64(R0, 0xffffffff), |
| 5219 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 5220 | BPF_ALU64_REG(BPF_AND, R0, R1), |
| 5221 | BPF_EXIT_INSN(), |
| 5222 | }, |
| 5223 | INTERNAL, |
| 5224 | { }, |
| 5225 | { { 0, 0xffffffff } }, |
| 5226 | }, |
| 5227 | /* BPF_ALU | BPF_AND | BPF_K */ |
| 5228 | { |
| 5229 | "ALU_AND_K: 3 & 2 = 2", |
| 5230 | .u.insns_int = { |
| 5231 | BPF_LD_IMM64(R0, 3), |
| 5232 | BPF_ALU32_IMM(BPF_AND, R0, 2), |
| 5233 | BPF_EXIT_INSN(), |
| 5234 | }, |
| 5235 | INTERNAL, |
| 5236 | { }, |
| 5237 | { { 0, 2 } }, |
| 5238 | }, |
| 5239 | { |
| 5240 | "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff", |
| 5241 | .u.insns_int = { |
| 5242 | BPF_LD_IMM64(R0, 0xffffffff), |
| 5243 | BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff), |
| 5244 | BPF_EXIT_INSN(), |
| 5245 | }, |
| 5246 | INTERNAL, |
| 5247 | { }, |
| 5248 | { { 0, 0xffffffff } }, |
| 5249 | }, |
| 5250 | { |
Johan Almbladh | ba89bcf | 2021-08-09 11:18:19 +0200 | [diff] [blame] | 5251 | "ALU_AND_K: Small immediate", |
| 5252 | .u.insns_int = { |
| 5253 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304), |
| 5254 | BPF_ALU32_IMM(BPF_AND, R0, 15), |
| 5255 | BPF_EXIT_INSN(), |
| 5256 | }, |
| 5257 | INTERNAL, |
| 5258 | { }, |
| 5259 | { { 0, 4 } } |
| 5260 | }, |
| 5261 | { |
| 5262 | "ALU_AND_K: Large immediate", |
| 5263 | .u.insns_int = { |
| 5264 | BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4), |
| 5265 | BPF_ALU32_IMM(BPF_AND, R0, 0xafbfcfdf), |
| 5266 | BPF_EXIT_INSN(), |
| 5267 | }, |
| 5268 | INTERNAL, |
| 5269 | { }, |
| 5270 | { { 0, 0xa1b2c3d4 } } |
| 5271 | }, |
| 5272 | { |
| 5273 | "ALU_AND_K: Zero extension", |
| 5274 | .u.insns_int = { |
| 5275 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5276 | BPF_LD_IMM64(R1, 0x0000000080a0c0e0LL), |
| 5277 | BPF_ALU32_IMM(BPF_AND, R0, 0xf0f0f0f0), |
| 5278 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5279 | BPF_MOV32_IMM(R0, 2), |
| 5280 | BPF_EXIT_INSN(), |
| 5281 | BPF_MOV32_IMM(R0, 1), |
| 5282 | BPF_EXIT_INSN(), |
| 5283 | }, |
| 5284 | INTERNAL, |
| 5285 | { }, |
| 5286 | { { 0, 1 } } |
| 5287 | }, |
| 5288 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5289 | "ALU64_AND_K: 3 & 2 = 2", |
| 5290 | .u.insns_int = { |
| 5291 | BPF_LD_IMM64(R0, 3), |
| 5292 | BPF_ALU64_IMM(BPF_AND, R0, 2), |
| 5293 | BPF_EXIT_INSN(), |
| 5294 | }, |
| 5295 | INTERNAL, |
| 5296 | { }, |
| 5297 | { { 0, 2 } }, |
| 5298 | }, |
| 5299 | { |
| 5300 | "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff", |
| 5301 | .u.insns_int = { |
| 5302 | BPF_LD_IMM64(R0, 0xffffffff), |
| 5303 | BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff), |
| 5304 | BPF_EXIT_INSN(), |
| 5305 | }, |
| 5306 | INTERNAL, |
| 5307 | { }, |
| 5308 | { { 0, 0xffffffff } }, |
| 5309 | }, |
| 5310 | { |
Johan Almbladh | e92c813 | 2021-08-09 11:18:18 +0200 | [diff] [blame] | 5311 | "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000000000000000", |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5312 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5313 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 5314 | BPF_LD_IMM64(R3, 0x0000000000000000LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5315 | BPF_ALU64_IMM(BPF_AND, R2, 0x0), |
| 5316 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5317 | BPF_MOV32_IMM(R0, 2), |
| 5318 | BPF_EXIT_INSN(), |
| 5319 | BPF_MOV32_IMM(R0, 1), |
| 5320 | BPF_EXIT_INSN(), |
| 5321 | }, |
| 5322 | INTERNAL, |
| 5323 | { }, |
| 5324 | { { 0, 0x1 } }, |
| 5325 | }, |
| 5326 | { |
Johan Almbladh | e92c813 | 2021-08-09 11:18:18 +0200 | [diff] [blame] | 5327 | "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffff0000", |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5328 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5329 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 5330 | BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5331 | BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff), |
| 5332 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5333 | BPF_MOV32_IMM(R0, 2), |
| 5334 | BPF_EXIT_INSN(), |
| 5335 | BPF_MOV32_IMM(R0, 1), |
| 5336 | BPF_EXIT_INSN(), |
| 5337 | }, |
| 5338 | INTERNAL, |
| 5339 | { }, |
| 5340 | { { 0, 0x1 } }, |
| 5341 | }, |
| 5342 | { |
| 5343 | "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff", |
| 5344 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5345 | BPF_LD_IMM64(R2, 0xffffffffffffffffLL), |
| 5346 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5347 | BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff), |
| 5348 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5349 | BPF_MOV32_IMM(R0, 2), |
| 5350 | BPF_EXIT_INSN(), |
| 5351 | BPF_MOV32_IMM(R0, 1), |
| 5352 | BPF_EXIT_INSN(), |
| 5353 | }, |
| 5354 | INTERNAL, |
| 5355 | { }, |
| 5356 | { { 0, 0x1 } }, |
| 5357 | }, |
Johan Almbladh | ba89bcf | 2021-08-09 11:18:19 +0200 | [diff] [blame] | 5358 | { |
| 5359 | "ALU64_AND_K: Sign extension 1", |
| 5360 | .u.insns_int = { |
| 5361 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5362 | BPF_LD_IMM64(R1, 0x00000000090b0d0fLL), |
| 5363 | BPF_ALU64_IMM(BPF_AND, R0, 0x0f0f0f0f), |
| 5364 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5365 | BPF_MOV32_IMM(R0, 2), |
| 5366 | BPF_EXIT_INSN(), |
| 5367 | BPF_MOV32_IMM(R0, 1), |
| 5368 | BPF_EXIT_INSN(), |
| 5369 | }, |
| 5370 | INTERNAL, |
| 5371 | { }, |
| 5372 | { { 0, 1 } } |
| 5373 | }, |
| 5374 | { |
| 5375 | "ALU64_AND_K: Sign extension 2", |
| 5376 | .u.insns_int = { |
| 5377 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5378 | BPF_LD_IMM64(R1, 0x0123456780a0c0e0LL), |
| 5379 | BPF_ALU64_IMM(BPF_AND, R0, 0xf0f0f0f0), |
| 5380 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5381 | BPF_MOV32_IMM(R0, 2), |
| 5382 | BPF_EXIT_INSN(), |
| 5383 | BPF_MOV32_IMM(R0, 1), |
| 5384 | BPF_EXIT_INSN(), |
| 5385 | }, |
| 5386 | INTERNAL, |
| 5387 | { }, |
| 5388 | { { 0, 1 } } |
| 5389 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5390 | /* BPF_ALU | BPF_OR | BPF_X */ |
| 5391 | { |
| 5392 | "ALU_OR_X: 1 | 2 = 3", |
| 5393 | .u.insns_int = { |
| 5394 | BPF_LD_IMM64(R0, 1), |
| 5395 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 5396 | BPF_ALU32_REG(BPF_OR, R0, R1), |
| 5397 | BPF_EXIT_INSN(), |
| 5398 | }, |
| 5399 | INTERNAL, |
| 5400 | { }, |
| 5401 | { { 0, 3 } }, |
| 5402 | }, |
| 5403 | { |
| 5404 | "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff", |
| 5405 | .u.insns_int = { |
| 5406 | BPF_LD_IMM64(R0, 0), |
| 5407 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 5408 | BPF_ALU32_REG(BPF_OR, R0, R1), |
| 5409 | BPF_EXIT_INSN(), |
| 5410 | }, |
| 5411 | INTERNAL, |
| 5412 | { }, |
| 5413 | { { 0, 0xffffffff } }, |
| 5414 | }, |
| 5415 | { |
| 5416 | "ALU64_OR_X: 1 | 2 = 3", |
| 5417 | .u.insns_int = { |
| 5418 | BPF_LD_IMM64(R0, 1), |
| 5419 | BPF_ALU32_IMM(BPF_MOV, R1, 2), |
| 5420 | BPF_ALU64_REG(BPF_OR, R0, R1), |
| 5421 | BPF_EXIT_INSN(), |
| 5422 | }, |
| 5423 | INTERNAL, |
| 5424 | { }, |
| 5425 | { { 0, 3 } }, |
| 5426 | }, |
| 5427 | { |
| 5428 | "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff", |
| 5429 | .u.insns_int = { |
| 5430 | BPF_LD_IMM64(R0, 0), |
| 5431 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 5432 | BPF_ALU64_REG(BPF_OR, R0, R1), |
| 5433 | BPF_EXIT_INSN(), |
| 5434 | }, |
| 5435 | INTERNAL, |
| 5436 | { }, |
| 5437 | { { 0, 0xffffffff } }, |
| 5438 | }, |
| 5439 | /* BPF_ALU | BPF_OR | BPF_K */ |
| 5440 | { |
| 5441 | "ALU_OR_K: 1 | 2 = 3", |
| 5442 | .u.insns_int = { |
| 5443 | BPF_LD_IMM64(R0, 1), |
| 5444 | BPF_ALU32_IMM(BPF_OR, R0, 2), |
| 5445 | BPF_EXIT_INSN(), |
| 5446 | }, |
| 5447 | INTERNAL, |
| 5448 | { }, |
| 5449 | { { 0, 3 } }, |
| 5450 | }, |
| 5451 | { |
| 5452 | "ALU_OR_K: 0 & 0xffffffff = 0xffffffff", |
| 5453 | .u.insns_int = { |
| 5454 | BPF_LD_IMM64(R0, 0), |
| 5455 | BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff), |
| 5456 | BPF_EXIT_INSN(), |
| 5457 | }, |
| 5458 | INTERNAL, |
| 5459 | { }, |
| 5460 | { { 0, 0xffffffff } }, |
| 5461 | }, |
| 5462 | { |
Johan Almbladh | ba89bcf | 2021-08-09 11:18:19 +0200 | [diff] [blame] | 5463 | "ALU_OR_K: Small immediate", |
| 5464 | .u.insns_int = { |
| 5465 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304), |
| 5466 | BPF_ALU32_IMM(BPF_OR, R0, 1), |
| 5467 | BPF_EXIT_INSN(), |
| 5468 | }, |
| 5469 | INTERNAL, |
| 5470 | { }, |
| 5471 | { { 0, 0x01020305 } } |
| 5472 | }, |
| 5473 | { |
| 5474 | "ALU_OR_K: Large immediate", |
| 5475 | .u.insns_int = { |
| 5476 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304), |
| 5477 | BPF_ALU32_IMM(BPF_OR, R0, 0xa0b0c0d0), |
| 5478 | BPF_EXIT_INSN(), |
| 5479 | }, |
| 5480 | INTERNAL, |
| 5481 | { }, |
| 5482 | { { 0, 0xa1b2c3d4 } } |
| 5483 | }, |
| 5484 | { |
| 5485 | "ALU_OR_K: Zero extension", |
| 5486 | .u.insns_int = { |
| 5487 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5488 | BPF_LD_IMM64(R1, 0x00000000f9fbfdffLL), |
| 5489 | BPF_ALU32_IMM(BPF_OR, R0, 0xf0f0f0f0), |
| 5490 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5491 | BPF_MOV32_IMM(R0, 2), |
| 5492 | BPF_EXIT_INSN(), |
| 5493 | BPF_MOV32_IMM(R0, 1), |
| 5494 | BPF_EXIT_INSN(), |
| 5495 | }, |
| 5496 | INTERNAL, |
| 5497 | { }, |
| 5498 | { { 0, 1 } } |
| 5499 | }, |
| 5500 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5501 | "ALU64_OR_K: 1 | 2 = 3", |
| 5502 | .u.insns_int = { |
| 5503 | BPF_LD_IMM64(R0, 1), |
| 5504 | BPF_ALU64_IMM(BPF_OR, R0, 2), |
| 5505 | BPF_EXIT_INSN(), |
| 5506 | }, |
| 5507 | INTERNAL, |
| 5508 | { }, |
| 5509 | { { 0, 3 } }, |
| 5510 | }, |
| 5511 | { |
| 5512 | "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff", |
| 5513 | .u.insns_int = { |
| 5514 | BPF_LD_IMM64(R0, 0), |
| 5515 | BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff), |
| 5516 | BPF_EXIT_INSN(), |
| 5517 | }, |
| 5518 | INTERNAL, |
| 5519 | { }, |
| 5520 | { { 0, 0xffffffff } }, |
| 5521 | }, |
| 5522 | { |
Johan Almbladh | e92c813 | 2021-08-09 11:18:18 +0200 | [diff] [blame] | 5523 | "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffffffff0000", |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5524 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5525 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 5526 | BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5527 | BPF_ALU64_IMM(BPF_OR, R2, 0x0), |
| 5528 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5529 | BPF_MOV32_IMM(R0, 2), |
| 5530 | BPF_EXIT_INSN(), |
| 5531 | BPF_MOV32_IMM(R0, 1), |
| 5532 | BPF_EXIT_INSN(), |
| 5533 | }, |
| 5534 | INTERNAL, |
| 5535 | { }, |
| 5536 | { { 0, 0x1 } }, |
| 5537 | }, |
| 5538 | { |
| 5539 | "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff", |
| 5540 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5541 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 5542 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5543 | BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff), |
| 5544 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5545 | BPF_MOV32_IMM(R0, 2), |
| 5546 | BPF_EXIT_INSN(), |
| 5547 | BPF_MOV32_IMM(R0, 1), |
| 5548 | BPF_EXIT_INSN(), |
| 5549 | }, |
| 5550 | INTERNAL, |
| 5551 | { }, |
| 5552 | { { 0, 0x1 } }, |
| 5553 | }, |
| 5554 | { |
| 5555 | "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff", |
| 5556 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5557 | BPF_LD_IMM64(R2, 0x0000000000000000LL), |
| 5558 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5559 | BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff), |
| 5560 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5561 | BPF_MOV32_IMM(R0, 2), |
| 5562 | BPF_EXIT_INSN(), |
| 5563 | BPF_MOV32_IMM(R0, 1), |
| 5564 | BPF_EXIT_INSN(), |
| 5565 | }, |
| 5566 | INTERNAL, |
| 5567 | { }, |
| 5568 | { { 0, 0x1 } }, |
| 5569 | }, |
Johan Almbladh | ba89bcf | 2021-08-09 11:18:19 +0200 | [diff] [blame] | 5570 | { |
| 5571 | "ALU64_OR_K: Sign extension 1", |
| 5572 | .u.insns_int = { |
| 5573 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5574 | BPF_LD_IMM64(R1, 0x012345678fafcfefLL), |
| 5575 | BPF_ALU64_IMM(BPF_OR, R0, 0x0f0f0f0f), |
| 5576 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5577 | BPF_MOV32_IMM(R0, 2), |
| 5578 | BPF_EXIT_INSN(), |
| 5579 | BPF_MOV32_IMM(R0, 1), |
| 5580 | BPF_EXIT_INSN(), |
| 5581 | }, |
| 5582 | INTERNAL, |
| 5583 | { }, |
| 5584 | { { 0, 1 } } |
| 5585 | }, |
| 5586 | { |
| 5587 | "ALU64_OR_K: Sign extension 2", |
| 5588 | .u.insns_int = { |
| 5589 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5590 | BPF_LD_IMM64(R1, 0xfffffffff9fbfdffLL), |
| 5591 | BPF_ALU64_IMM(BPF_OR, R0, 0xf0f0f0f0), |
| 5592 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5593 | BPF_MOV32_IMM(R0, 2), |
| 5594 | BPF_EXIT_INSN(), |
| 5595 | BPF_MOV32_IMM(R0, 1), |
| 5596 | BPF_EXIT_INSN(), |
| 5597 | }, |
| 5598 | INTERNAL, |
| 5599 | { }, |
| 5600 | { { 0, 1 } } |
| 5601 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5602 | /* BPF_ALU | BPF_XOR | BPF_X */ |
| 5603 | { |
| 5604 | "ALU_XOR_X: 5 ^ 6 = 3", |
| 5605 | .u.insns_int = { |
| 5606 | BPF_LD_IMM64(R0, 5), |
| 5607 | BPF_ALU32_IMM(BPF_MOV, R1, 6), |
| 5608 | BPF_ALU32_REG(BPF_XOR, R0, R1), |
| 5609 | BPF_EXIT_INSN(), |
| 5610 | }, |
| 5611 | INTERNAL, |
| 5612 | { }, |
| 5613 | { { 0, 3 } }, |
| 5614 | }, |
| 5615 | { |
| 5616 | "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe", |
| 5617 | .u.insns_int = { |
| 5618 | BPF_LD_IMM64(R0, 1), |
| 5619 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 5620 | BPF_ALU32_REG(BPF_XOR, R0, R1), |
| 5621 | BPF_EXIT_INSN(), |
| 5622 | }, |
| 5623 | INTERNAL, |
| 5624 | { }, |
| 5625 | { { 0, 0xfffffffe } }, |
| 5626 | }, |
| 5627 | { |
| 5628 | "ALU64_XOR_X: 5 ^ 6 = 3", |
| 5629 | .u.insns_int = { |
| 5630 | BPF_LD_IMM64(R0, 5), |
| 5631 | BPF_ALU32_IMM(BPF_MOV, R1, 6), |
| 5632 | BPF_ALU64_REG(BPF_XOR, R0, R1), |
| 5633 | BPF_EXIT_INSN(), |
| 5634 | }, |
| 5635 | INTERNAL, |
| 5636 | { }, |
| 5637 | { { 0, 3 } }, |
| 5638 | }, |
| 5639 | { |
| 5640 | "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe", |
| 5641 | .u.insns_int = { |
| 5642 | BPF_LD_IMM64(R0, 1), |
| 5643 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 5644 | BPF_ALU64_REG(BPF_XOR, R0, R1), |
| 5645 | BPF_EXIT_INSN(), |
| 5646 | }, |
| 5647 | INTERNAL, |
| 5648 | { }, |
| 5649 | { { 0, 0xfffffffe } }, |
| 5650 | }, |
| 5651 | /* BPF_ALU | BPF_XOR | BPF_K */ |
| 5652 | { |
| 5653 | "ALU_XOR_K: 5 ^ 6 = 3", |
| 5654 | .u.insns_int = { |
| 5655 | BPF_LD_IMM64(R0, 5), |
| 5656 | BPF_ALU32_IMM(BPF_XOR, R0, 6), |
| 5657 | BPF_EXIT_INSN(), |
| 5658 | }, |
| 5659 | INTERNAL, |
| 5660 | { }, |
| 5661 | { { 0, 3 } }, |
| 5662 | }, |
| 5663 | { |
| 5664 | "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe", |
| 5665 | .u.insns_int = { |
| 5666 | BPF_LD_IMM64(R0, 1), |
| 5667 | BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff), |
| 5668 | BPF_EXIT_INSN(), |
| 5669 | }, |
| 5670 | INTERNAL, |
| 5671 | { }, |
| 5672 | { { 0, 0xfffffffe } }, |
| 5673 | }, |
| 5674 | { |
Johan Almbladh | ba89bcf | 2021-08-09 11:18:19 +0200 | [diff] [blame] | 5675 | "ALU_XOR_K: Small immediate", |
| 5676 | .u.insns_int = { |
| 5677 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01020304), |
| 5678 | BPF_ALU32_IMM(BPF_XOR, R0, 15), |
| 5679 | BPF_EXIT_INSN(), |
| 5680 | }, |
| 5681 | INTERNAL, |
| 5682 | { }, |
| 5683 | { { 0, 0x0102030b } } |
| 5684 | }, |
| 5685 | { |
| 5686 | "ALU_XOR_K: Large immediate", |
| 5687 | .u.insns_int = { |
| 5688 | BPF_ALU32_IMM(BPF_MOV, R0, 0xf1f2f3f4), |
| 5689 | BPF_ALU32_IMM(BPF_XOR, R0, 0xafbfcfdf), |
| 5690 | BPF_EXIT_INSN(), |
| 5691 | }, |
| 5692 | INTERNAL, |
| 5693 | { }, |
| 5694 | { { 0, 0x5e4d3c2b } } |
| 5695 | }, |
| 5696 | { |
| 5697 | "ALU_XOR_K: Zero extension", |
| 5698 | .u.insns_int = { |
| 5699 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5700 | BPF_LD_IMM64(R1, 0x00000000795b3d1fLL), |
| 5701 | BPF_ALU32_IMM(BPF_XOR, R0, 0xf0f0f0f0), |
| 5702 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5703 | BPF_MOV32_IMM(R0, 2), |
| 5704 | BPF_EXIT_INSN(), |
| 5705 | BPF_MOV32_IMM(R0, 1), |
| 5706 | BPF_EXIT_INSN(), |
| 5707 | }, |
| 5708 | INTERNAL, |
| 5709 | { }, |
| 5710 | { { 0, 1 } } |
| 5711 | }, |
| 5712 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5713 | "ALU64_XOR_K: 5 ^ 6 = 3", |
| 5714 | .u.insns_int = { |
| 5715 | BPF_LD_IMM64(R0, 5), |
| 5716 | BPF_ALU64_IMM(BPF_XOR, R0, 6), |
| 5717 | BPF_EXIT_INSN(), |
| 5718 | }, |
| 5719 | INTERNAL, |
| 5720 | { }, |
| 5721 | { { 0, 3 } }, |
| 5722 | }, |
| 5723 | { |
Johan Almbladh | e92c813 | 2021-08-09 11:18:18 +0200 | [diff] [blame] | 5724 | "ALU64_XOR_K: 1 ^ 0xffffffff = 0xfffffffe", |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5725 | .u.insns_int = { |
| 5726 | BPF_LD_IMM64(R0, 1), |
| 5727 | BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff), |
| 5728 | BPF_EXIT_INSN(), |
| 5729 | }, |
| 5730 | INTERNAL, |
| 5731 | { }, |
| 5732 | { { 0, 0xfffffffe } }, |
| 5733 | }, |
| 5734 | { |
| 5735 | "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000", |
| 5736 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5737 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 5738 | BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5739 | BPF_ALU64_IMM(BPF_XOR, R2, 0x0), |
| 5740 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5741 | BPF_MOV32_IMM(R0, 2), |
| 5742 | BPF_EXIT_INSN(), |
| 5743 | BPF_MOV32_IMM(R0, 1), |
| 5744 | BPF_EXIT_INSN(), |
| 5745 | }, |
| 5746 | INTERNAL, |
| 5747 | { }, |
| 5748 | { { 0, 0x1 } }, |
| 5749 | }, |
| 5750 | { |
| 5751 | "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff", |
| 5752 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5753 | BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), |
| 5754 | BPF_LD_IMM64(R3, 0xffff00000000ffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5755 | BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff), |
| 5756 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5757 | BPF_MOV32_IMM(R0, 2), |
| 5758 | BPF_EXIT_INSN(), |
| 5759 | BPF_MOV32_IMM(R0, 1), |
| 5760 | BPF_EXIT_INSN(), |
| 5761 | }, |
| 5762 | INTERNAL, |
| 5763 | { }, |
| 5764 | { { 0, 0x1 } }, |
| 5765 | }, |
| 5766 | { |
| 5767 | "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff", |
| 5768 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 5769 | BPF_LD_IMM64(R2, 0x0000000000000000LL), |
| 5770 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5771 | BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff), |
| 5772 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 5773 | BPF_MOV32_IMM(R0, 2), |
| 5774 | BPF_EXIT_INSN(), |
| 5775 | BPF_MOV32_IMM(R0, 1), |
| 5776 | BPF_EXIT_INSN(), |
| 5777 | }, |
| 5778 | INTERNAL, |
| 5779 | { }, |
| 5780 | { { 0, 0x1 } }, |
| 5781 | }, |
Johan Almbladh | ba89bcf | 2021-08-09 11:18:19 +0200 | [diff] [blame] | 5782 | { |
| 5783 | "ALU64_XOR_K: Sign extension 1", |
| 5784 | .u.insns_int = { |
| 5785 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5786 | BPF_LD_IMM64(R1, 0x0123456786a4c2e0LL), |
| 5787 | BPF_ALU64_IMM(BPF_XOR, R0, 0x0f0f0f0f), |
| 5788 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5789 | BPF_MOV32_IMM(R0, 2), |
| 5790 | BPF_EXIT_INSN(), |
| 5791 | BPF_MOV32_IMM(R0, 1), |
| 5792 | BPF_EXIT_INSN(), |
| 5793 | }, |
| 5794 | INTERNAL, |
| 5795 | { }, |
| 5796 | { { 0, 1 } } |
| 5797 | }, |
| 5798 | { |
| 5799 | "ALU64_XOR_K: Sign extension 2", |
| 5800 | .u.insns_int = { |
| 5801 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5802 | BPF_LD_IMM64(R1, 0xfedcba98795b3d1fLL), |
| 5803 | BPF_ALU64_IMM(BPF_XOR, R0, 0xf0f0f0f0), |
| 5804 | BPF_JMP_REG(BPF_JEQ, R0, R1, 2), |
| 5805 | BPF_MOV32_IMM(R0, 2), |
| 5806 | BPF_EXIT_INSN(), |
| 5807 | BPF_MOV32_IMM(R0, 1), |
| 5808 | BPF_EXIT_INSN(), |
| 5809 | }, |
| 5810 | INTERNAL, |
| 5811 | { }, |
| 5812 | { { 0, 1 } } |
| 5813 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5814 | /* BPF_ALU | BPF_LSH | BPF_X */ |
| 5815 | { |
| 5816 | "ALU_LSH_X: 1 << 1 = 2", |
| 5817 | .u.insns_int = { |
| 5818 | BPF_LD_IMM64(R0, 1), |
| 5819 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 5820 | BPF_ALU32_REG(BPF_LSH, R0, R1), |
| 5821 | BPF_EXIT_INSN(), |
| 5822 | }, |
| 5823 | INTERNAL, |
| 5824 | { }, |
| 5825 | { { 0, 2 } }, |
| 5826 | }, |
| 5827 | { |
| 5828 | "ALU_LSH_X: 1 << 31 = 0x80000000", |
| 5829 | .u.insns_int = { |
| 5830 | BPF_LD_IMM64(R0, 1), |
| 5831 | BPF_ALU32_IMM(BPF_MOV, R1, 31), |
| 5832 | BPF_ALU32_REG(BPF_LSH, R0, R1), |
| 5833 | BPF_EXIT_INSN(), |
| 5834 | }, |
| 5835 | INTERNAL, |
| 5836 | { }, |
| 5837 | { { 0, 0x80000000 } }, |
| 5838 | }, |
| 5839 | { |
Johan Almbladh | 0f2fca1 | 2021-08-09 11:18:20 +0200 | [diff] [blame] | 5840 | "ALU_LSH_X: 0x12345678 << 12 = 0x45678000", |
| 5841 | .u.insns_int = { |
| 5842 | BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678), |
| 5843 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 5844 | BPF_ALU32_REG(BPF_LSH, R0, R1), |
| 5845 | BPF_EXIT_INSN(), |
| 5846 | }, |
| 5847 | INTERNAL, |
| 5848 | { }, |
| 5849 | { { 0, 0x45678000 } } |
| 5850 | }, |
| 5851 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5852 | "ALU64_LSH_X: 1 << 1 = 2", |
| 5853 | .u.insns_int = { |
| 5854 | BPF_LD_IMM64(R0, 1), |
| 5855 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 5856 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5857 | BPF_EXIT_INSN(), |
| 5858 | }, |
| 5859 | INTERNAL, |
| 5860 | { }, |
| 5861 | { { 0, 2 } }, |
| 5862 | }, |
| 5863 | { |
| 5864 | "ALU64_LSH_X: 1 << 31 = 0x80000000", |
| 5865 | .u.insns_int = { |
| 5866 | BPF_LD_IMM64(R0, 1), |
| 5867 | BPF_ALU32_IMM(BPF_MOV, R1, 31), |
| 5868 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5869 | BPF_EXIT_INSN(), |
| 5870 | }, |
| 5871 | INTERNAL, |
| 5872 | { }, |
| 5873 | { { 0, 0x80000000 } }, |
| 5874 | }, |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 5875 | { |
| 5876 | "ALU64_LSH_X: Shift < 32, low word", |
| 5877 | .u.insns_int = { |
| 5878 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5879 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 5880 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5881 | BPF_EXIT_INSN(), |
| 5882 | }, |
| 5883 | INTERNAL, |
| 5884 | { }, |
| 5885 | { { 0, 0xbcdef000 } } |
| 5886 | }, |
| 5887 | { |
| 5888 | "ALU64_LSH_X: Shift < 32, high word", |
| 5889 | .u.insns_int = { |
| 5890 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5891 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 5892 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5893 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 5894 | BPF_EXIT_INSN(), |
| 5895 | }, |
| 5896 | INTERNAL, |
| 5897 | { }, |
| 5898 | { { 0, 0x3456789a } } |
| 5899 | }, |
| 5900 | { |
| 5901 | "ALU64_LSH_X: Shift > 32, low word", |
| 5902 | .u.insns_int = { |
| 5903 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5904 | BPF_ALU32_IMM(BPF_MOV, R1, 36), |
| 5905 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5906 | BPF_EXIT_INSN(), |
| 5907 | }, |
| 5908 | INTERNAL, |
| 5909 | { }, |
| 5910 | { { 0, 0 } } |
| 5911 | }, |
| 5912 | { |
| 5913 | "ALU64_LSH_X: Shift > 32, high word", |
| 5914 | .u.insns_int = { |
| 5915 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5916 | BPF_ALU32_IMM(BPF_MOV, R1, 36), |
| 5917 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5918 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 5919 | BPF_EXIT_INSN(), |
| 5920 | }, |
| 5921 | INTERNAL, |
| 5922 | { }, |
| 5923 | { { 0, 0x9abcdef0 } } |
| 5924 | }, |
| 5925 | { |
| 5926 | "ALU64_LSH_X: Shift == 32, low word", |
| 5927 | .u.insns_int = { |
| 5928 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5929 | BPF_ALU32_IMM(BPF_MOV, R1, 32), |
| 5930 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5931 | BPF_EXIT_INSN(), |
| 5932 | }, |
| 5933 | INTERNAL, |
| 5934 | { }, |
| 5935 | { { 0, 0 } } |
| 5936 | }, |
| 5937 | { |
| 5938 | "ALU64_LSH_X: Shift == 32, high word", |
| 5939 | .u.insns_int = { |
| 5940 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5941 | BPF_ALU32_IMM(BPF_MOV, R1, 32), |
| 5942 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5943 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 5944 | BPF_EXIT_INSN(), |
| 5945 | }, |
| 5946 | INTERNAL, |
| 5947 | { }, |
| 5948 | { { 0, 0x89abcdef } } |
| 5949 | }, |
| 5950 | { |
| 5951 | "ALU64_LSH_X: Zero shift, low word", |
| 5952 | .u.insns_int = { |
| 5953 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5954 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 5955 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5956 | BPF_EXIT_INSN(), |
| 5957 | }, |
| 5958 | INTERNAL, |
| 5959 | { }, |
| 5960 | { { 0, 0x89abcdef } } |
| 5961 | }, |
| 5962 | { |
| 5963 | "ALU64_LSH_X: Zero shift, high word", |
| 5964 | .u.insns_int = { |
| 5965 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 5966 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 5967 | BPF_ALU64_REG(BPF_LSH, R0, R1), |
| 5968 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 5969 | BPF_EXIT_INSN(), |
| 5970 | }, |
| 5971 | INTERNAL, |
| 5972 | { }, |
| 5973 | { { 0, 0x01234567 } } |
| 5974 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 5975 | /* BPF_ALU | BPF_LSH | BPF_K */ |
| 5976 | { |
| 5977 | "ALU_LSH_K: 1 << 1 = 2", |
| 5978 | .u.insns_int = { |
| 5979 | BPF_LD_IMM64(R0, 1), |
| 5980 | BPF_ALU32_IMM(BPF_LSH, R0, 1), |
| 5981 | BPF_EXIT_INSN(), |
| 5982 | }, |
| 5983 | INTERNAL, |
| 5984 | { }, |
| 5985 | { { 0, 2 } }, |
| 5986 | }, |
| 5987 | { |
| 5988 | "ALU_LSH_K: 1 << 31 = 0x80000000", |
| 5989 | .u.insns_int = { |
| 5990 | BPF_LD_IMM64(R0, 1), |
| 5991 | BPF_ALU32_IMM(BPF_LSH, R0, 31), |
| 5992 | BPF_EXIT_INSN(), |
| 5993 | }, |
| 5994 | INTERNAL, |
| 5995 | { }, |
| 5996 | { { 0, 0x80000000 } }, |
| 5997 | }, |
| 5998 | { |
Johan Almbladh | 0f2fca1 | 2021-08-09 11:18:20 +0200 | [diff] [blame] | 5999 | "ALU_LSH_K: 0x12345678 << 12 = 0x45678000", |
| 6000 | .u.insns_int = { |
| 6001 | BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678), |
| 6002 | BPF_ALU32_IMM(BPF_LSH, R0, 12), |
| 6003 | BPF_EXIT_INSN(), |
| 6004 | }, |
| 6005 | INTERNAL, |
| 6006 | { }, |
| 6007 | { { 0, 0x45678000 } } |
| 6008 | }, |
| 6009 | { |
| 6010 | "ALU_LSH_K: 0x12345678 << 0 = 0x12345678", |
| 6011 | .u.insns_int = { |
| 6012 | BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678), |
| 6013 | BPF_ALU32_IMM(BPF_LSH, R0, 0), |
| 6014 | BPF_EXIT_INSN(), |
| 6015 | }, |
| 6016 | INTERNAL, |
| 6017 | { }, |
| 6018 | { { 0, 0x12345678 } } |
| 6019 | }, |
| 6020 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6021 | "ALU64_LSH_K: 1 << 1 = 2", |
| 6022 | .u.insns_int = { |
| 6023 | BPF_LD_IMM64(R0, 1), |
| 6024 | BPF_ALU64_IMM(BPF_LSH, R0, 1), |
| 6025 | BPF_EXIT_INSN(), |
| 6026 | }, |
| 6027 | INTERNAL, |
| 6028 | { }, |
| 6029 | { { 0, 2 } }, |
| 6030 | }, |
| 6031 | { |
| 6032 | "ALU64_LSH_K: 1 << 31 = 0x80000000", |
| 6033 | .u.insns_int = { |
| 6034 | BPF_LD_IMM64(R0, 1), |
| 6035 | BPF_ALU64_IMM(BPF_LSH, R0, 31), |
| 6036 | BPF_EXIT_INSN(), |
| 6037 | }, |
| 6038 | INTERNAL, |
| 6039 | { }, |
| 6040 | { { 0, 0x80000000 } }, |
| 6041 | }, |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6042 | { |
| 6043 | "ALU64_LSH_K: Shift < 32, low word", |
| 6044 | .u.insns_int = { |
| 6045 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6046 | BPF_ALU64_IMM(BPF_LSH, R0, 12), |
| 6047 | BPF_EXIT_INSN(), |
| 6048 | }, |
| 6049 | INTERNAL, |
| 6050 | { }, |
| 6051 | { { 0, 0xbcdef000 } } |
| 6052 | }, |
| 6053 | { |
| 6054 | "ALU64_LSH_K: Shift < 32, high word", |
| 6055 | .u.insns_int = { |
| 6056 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6057 | BPF_ALU64_IMM(BPF_LSH, R0, 12), |
| 6058 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6059 | BPF_EXIT_INSN(), |
| 6060 | }, |
| 6061 | INTERNAL, |
| 6062 | { }, |
| 6063 | { { 0, 0x3456789a } } |
| 6064 | }, |
| 6065 | { |
| 6066 | "ALU64_LSH_K: Shift > 32, low word", |
| 6067 | .u.insns_int = { |
| 6068 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6069 | BPF_ALU64_IMM(BPF_LSH, R0, 36), |
| 6070 | BPF_EXIT_INSN(), |
| 6071 | }, |
| 6072 | INTERNAL, |
| 6073 | { }, |
| 6074 | { { 0, 0 } } |
| 6075 | }, |
| 6076 | { |
| 6077 | "ALU64_LSH_K: Shift > 32, high word", |
| 6078 | .u.insns_int = { |
| 6079 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6080 | BPF_ALU64_IMM(BPF_LSH, R0, 36), |
| 6081 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6082 | BPF_EXIT_INSN(), |
| 6083 | }, |
| 6084 | INTERNAL, |
| 6085 | { }, |
| 6086 | { { 0, 0x9abcdef0 } } |
| 6087 | }, |
| 6088 | { |
| 6089 | "ALU64_LSH_K: Shift == 32, low word", |
| 6090 | .u.insns_int = { |
| 6091 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6092 | BPF_ALU64_IMM(BPF_LSH, R0, 32), |
| 6093 | BPF_EXIT_INSN(), |
| 6094 | }, |
| 6095 | INTERNAL, |
| 6096 | { }, |
| 6097 | { { 0, 0 } } |
| 6098 | }, |
| 6099 | { |
| 6100 | "ALU64_LSH_K: Shift == 32, high word", |
| 6101 | .u.insns_int = { |
| 6102 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6103 | BPF_ALU64_IMM(BPF_LSH, R0, 32), |
| 6104 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6105 | BPF_EXIT_INSN(), |
| 6106 | }, |
| 6107 | INTERNAL, |
| 6108 | { }, |
| 6109 | { { 0, 0x89abcdef } } |
| 6110 | }, |
| 6111 | { |
| 6112 | "ALU64_LSH_K: Zero shift", |
| 6113 | .u.insns_int = { |
| 6114 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6115 | BPF_ALU64_IMM(BPF_LSH, R0, 0), |
| 6116 | BPF_EXIT_INSN(), |
| 6117 | }, |
| 6118 | INTERNAL, |
| 6119 | { }, |
| 6120 | { { 0, 0x89abcdef } } |
| 6121 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6122 | /* BPF_ALU | BPF_RSH | BPF_X */ |
| 6123 | { |
| 6124 | "ALU_RSH_X: 2 >> 1 = 1", |
| 6125 | .u.insns_int = { |
| 6126 | BPF_LD_IMM64(R0, 2), |
| 6127 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 6128 | BPF_ALU32_REG(BPF_RSH, R0, R1), |
| 6129 | BPF_EXIT_INSN(), |
| 6130 | }, |
| 6131 | INTERNAL, |
| 6132 | { }, |
| 6133 | { { 0, 1 } }, |
| 6134 | }, |
| 6135 | { |
| 6136 | "ALU_RSH_X: 0x80000000 >> 31 = 1", |
| 6137 | .u.insns_int = { |
| 6138 | BPF_LD_IMM64(R0, 0x80000000), |
| 6139 | BPF_ALU32_IMM(BPF_MOV, R1, 31), |
| 6140 | BPF_ALU32_REG(BPF_RSH, R0, R1), |
| 6141 | BPF_EXIT_INSN(), |
| 6142 | }, |
| 6143 | INTERNAL, |
| 6144 | { }, |
| 6145 | { { 0, 1 } }, |
| 6146 | }, |
| 6147 | { |
Johan Almbladh | 0f2fca1 | 2021-08-09 11:18:20 +0200 | [diff] [blame] | 6148 | "ALU_RSH_X: 0x12345678 >> 20 = 0x123", |
| 6149 | .u.insns_int = { |
| 6150 | BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678), |
| 6151 | BPF_ALU32_IMM(BPF_MOV, R1, 20), |
| 6152 | BPF_ALU32_REG(BPF_RSH, R0, R1), |
| 6153 | BPF_EXIT_INSN(), |
| 6154 | }, |
| 6155 | INTERNAL, |
| 6156 | { }, |
| 6157 | { { 0, 0x123 } } |
| 6158 | }, |
| 6159 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6160 | "ALU64_RSH_X: 2 >> 1 = 1", |
| 6161 | .u.insns_int = { |
| 6162 | BPF_LD_IMM64(R0, 2), |
| 6163 | BPF_ALU32_IMM(BPF_MOV, R1, 1), |
| 6164 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6165 | BPF_EXIT_INSN(), |
| 6166 | }, |
| 6167 | INTERNAL, |
| 6168 | { }, |
| 6169 | { { 0, 1 } }, |
| 6170 | }, |
| 6171 | { |
| 6172 | "ALU64_RSH_X: 0x80000000 >> 31 = 1", |
| 6173 | .u.insns_int = { |
| 6174 | BPF_LD_IMM64(R0, 0x80000000), |
| 6175 | BPF_ALU32_IMM(BPF_MOV, R1, 31), |
| 6176 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6177 | BPF_EXIT_INSN(), |
| 6178 | }, |
| 6179 | INTERNAL, |
| 6180 | { }, |
| 6181 | { { 0, 1 } }, |
| 6182 | }, |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6183 | { |
| 6184 | "ALU64_RSH_X: Shift < 32, low word", |
| 6185 | .u.insns_int = { |
| 6186 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6187 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 6188 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6189 | BPF_EXIT_INSN(), |
| 6190 | }, |
| 6191 | INTERNAL, |
| 6192 | { }, |
| 6193 | { { 0, 0x56789abc } } |
| 6194 | }, |
| 6195 | { |
| 6196 | "ALU64_RSH_X: Shift < 32, high word", |
| 6197 | .u.insns_int = { |
| 6198 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6199 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 6200 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6201 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6202 | BPF_EXIT_INSN(), |
| 6203 | }, |
| 6204 | INTERNAL, |
| 6205 | { }, |
| 6206 | { { 0, 0x00081234 } } |
| 6207 | }, |
| 6208 | { |
| 6209 | "ALU64_RSH_X: Shift > 32, low word", |
| 6210 | .u.insns_int = { |
| 6211 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6212 | BPF_ALU32_IMM(BPF_MOV, R1, 36), |
| 6213 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6214 | BPF_EXIT_INSN(), |
| 6215 | }, |
| 6216 | INTERNAL, |
| 6217 | { }, |
| 6218 | { { 0, 0x08123456 } } |
| 6219 | }, |
| 6220 | { |
| 6221 | "ALU64_RSH_X: Shift > 32, high word", |
| 6222 | .u.insns_int = { |
| 6223 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6224 | BPF_ALU32_IMM(BPF_MOV, R1, 36), |
| 6225 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6226 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6227 | BPF_EXIT_INSN(), |
| 6228 | }, |
| 6229 | INTERNAL, |
| 6230 | { }, |
| 6231 | { { 0, 0 } } |
| 6232 | }, |
| 6233 | { |
| 6234 | "ALU64_RSH_X: Shift == 32, low word", |
| 6235 | .u.insns_int = { |
| 6236 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6237 | BPF_ALU32_IMM(BPF_MOV, R1, 32), |
| 6238 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6239 | BPF_EXIT_INSN(), |
| 6240 | }, |
| 6241 | INTERNAL, |
| 6242 | { }, |
| 6243 | { { 0, 0x81234567 } } |
| 6244 | }, |
| 6245 | { |
| 6246 | "ALU64_RSH_X: Shift == 32, high word", |
| 6247 | .u.insns_int = { |
| 6248 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6249 | BPF_ALU32_IMM(BPF_MOV, R1, 32), |
| 6250 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6251 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6252 | BPF_EXIT_INSN(), |
| 6253 | }, |
| 6254 | INTERNAL, |
| 6255 | { }, |
| 6256 | { { 0, 0 } } |
| 6257 | }, |
| 6258 | { |
| 6259 | "ALU64_RSH_X: Zero shift, low word", |
| 6260 | .u.insns_int = { |
| 6261 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6262 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 6263 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6264 | BPF_EXIT_INSN(), |
| 6265 | }, |
| 6266 | INTERNAL, |
| 6267 | { }, |
| 6268 | { { 0, 0x89abcdef } } |
| 6269 | }, |
| 6270 | { |
| 6271 | "ALU64_RSH_X: Zero shift, high word", |
| 6272 | .u.insns_int = { |
| 6273 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6274 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 6275 | BPF_ALU64_REG(BPF_RSH, R0, R1), |
| 6276 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6277 | BPF_EXIT_INSN(), |
| 6278 | }, |
| 6279 | INTERNAL, |
| 6280 | { }, |
| 6281 | { { 0, 0x81234567 } } |
| 6282 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6283 | /* BPF_ALU | BPF_RSH | BPF_K */ |
| 6284 | { |
| 6285 | "ALU_RSH_K: 2 >> 1 = 1", |
| 6286 | .u.insns_int = { |
| 6287 | BPF_LD_IMM64(R0, 2), |
| 6288 | BPF_ALU32_IMM(BPF_RSH, R0, 1), |
| 6289 | BPF_EXIT_INSN(), |
| 6290 | }, |
| 6291 | INTERNAL, |
| 6292 | { }, |
| 6293 | { { 0, 1 } }, |
| 6294 | }, |
| 6295 | { |
| 6296 | "ALU_RSH_K: 0x80000000 >> 31 = 1", |
| 6297 | .u.insns_int = { |
| 6298 | BPF_LD_IMM64(R0, 0x80000000), |
| 6299 | BPF_ALU32_IMM(BPF_RSH, R0, 31), |
| 6300 | BPF_EXIT_INSN(), |
| 6301 | }, |
| 6302 | INTERNAL, |
| 6303 | { }, |
| 6304 | { { 0, 1 } }, |
| 6305 | }, |
| 6306 | { |
Johan Almbladh | 0f2fca1 | 2021-08-09 11:18:20 +0200 | [diff] [blame] | 6307 | "ALU_RSH_K: 0x12345678 >> 20 = 0x123", |
| 6308 | .u.insns_int = { |
| 6309 | BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678), |
| 6310 | BPF_ALU32_IMM(BPF_RSH, R0, 20), |
| 6311 | BPF_EXIT_INSN(), |
| 6312 | }, |
| 6313 | INTERNAL, |
| 6314 | { }, |
| 6315 | { { 0, 0x123 } } |
| 6316 | }, |
| 6317 | { |
| 6318 | "ALU_RSH_K: 0x12345678 >> 0 = 0x12345678", |
| 6319 | .u.insns_int = { |
| 6320 | BPF_ALU32_IMM(BPF_MOV, R0, 0x12345678), |
| 6321 | BPF_ALU32_IMM(BPF_RSH, R0, 0), |
| 6322 | BPF_EXIT_INSN(), |
| 6323 | }, |
| 6324 | INTERNAL, |
| 6325 | { }, |
| 6326 | { { 0, 0x12345678 } } |
| 6327 | }, |
| 6328 | { |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6329 | "ALU64_RSH_K: 2 >> 1 = 1", |
| 6330 | .u.insns_int = { |
| 6331 | BPF_LD_IMM64(R0, 2), |
| 6332 | BPF_ALU64_IMM(BPF_RSH, R0, 1), |
| 6333 | BPF_EXIT_INSN(), |
| 6334 | }, |
| 6335 | INTERNAL, |
| 6336 | { }, |
| 6337 | { { 0, 1 } }, |
| 6338 | }, |
| 6339 | { |
| 6340 | "ALU64_RSH_K: 0x80000000 >> 31 = 1", |
| 6341 | .u.insns_int = { |
| 6342 | BPF_LD_IMM64(R0, 0x80000000), |
| 6343 | BPF_ALU64_IMM(BPF_RSH, R0, 31), |
| 6344 | BPF_EXIT_INSN(), |
| 6345 | }, |
| 6346 | INTERNAL, |
| 6347 | { }, |
| 6348 | { { 0, 1 } }, |
| 6349 | }, |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6350 | { |
| 6351 | "ALU64_RSH_K: Shift < 32, low word", |
| 6352 | .u.insns_int = { |
| 6353 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6354 | BPF_ALU64_IMM(BPF_RSH, R0, 12), |
| 6355 | BPF_EXIT_INSN(), |
| 6356 | }, |
| 6357 | INTERNAL, |
| 6358 | { }, |
| 6359 | { { 0, 0x56789abc } } |
| 6360 | }, |
| 6361 | { |
| 6362 | "ALU64_RSH_K: Shift < 32, high word", |
| 6363 | .u.insns_int = { |
| 6364 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6365 | BPF_ALU64_IMM(BPF_RSH, R0, 12), |
| 6366 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6367 | BPF_EXIT_INSN(), |
| 6368 | }, |
| 6369 | INTERNAL, |
| 6370 | { }, |
| 6371 | { { 0, 0x00081234 } } |
| 6372 | }, |
| 6373 | { |
| 6374 | "ALU64_RSH_K: Shift > 32, low word", |
| 6375 | .u.insns_int = { |
| 6376 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6377 | BPF_ALU64_IMM(BPF_RSH, R0, 36), |
| 6378 | BPF_EXIT_INSN(), |
| 6379 | }, |
| 6380 | INTERNAL, |
| 6381 | { }, |
| 6382 | { { 0, 0x08123456 } } |
| 6383 | }, |
| 6384 | { |
| 6385 | "ALU64_RSH_K: Shift > 32, high word", |
| 6386 | .u.insns_int = { |
| 6387 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6388 | BPF_ALU64_IMM(BPF_RSH, R0, 36), |
| 6389 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6390 | BPF_EXIT_INSN(), |
| 6391 | }, |
| 6392 | INTERNAL, |
| 6393 | { }, |
| 6394 | { { 0, 0 } } |
| 6395 | }, |
| 6396 | { |
| 6397 | "ALU64_RSH_K: Shift == 32, low word", |
| 6398 | .u.insns_int = { |
| 6399 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6400 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6401 | BPF_EXIT_INSN(), |
| 6402 | }, |
| 6403 | INTERNAL, |
| 6404 | { }, |
| 6405 | { { 0, 0x81234567 } } |
| 6406 | }, |
| 6407 | { |
| 6408 | "ALU64_RSH_K: Shift == 32, high word", |
| 6409 | .u.insns_int = { |
| 6410 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6411 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6412 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6413 | BPF_EXIT_INSN(), |
| 6414 | }, |
| 6415 | INTERNAL, |
| 6416 | { }, |
| 6417 | { { 0, 0 } } |
| 6418 | }, |
| 6419 | { |
| 6420 | "ALU64_RSH_K: Zero shift", |
| 6421 | .u.insns_int = { |
| 6422 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6423 | BPF_ALU64_IMM(BPF_RSH, R0, 0), |
| 6424 | BPF_EXIT_INSN(), |
| 6425 | }, |
| 6426 | INTERNAL, |
| 6427 | { }, |
| 6428 | { { 0, 0x89abcdef } } |
| 6429 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6430 | /* BPF_ALU | BPF_ARSH | BPF_X */ |
| 6431 | { |
Johan Almbladh | 0f2fca1 | 2021-08-09 11:18:20 +0200 | [diff] [blame] | 6432 | "ALU32_ARSH_X: -1234 >> 7 = -10", |
| 6433 | .u.insns_int = { |
| 6434 | BPF_ALU32_IMM(BPF_MOV, R0, -1234), |
| 6435 | BPF_ALU32_IMM(BPF_MOV, R1, 7), |
| 6436 | BPF_ALU32_REG(BPF_ARSH, R0, R1), |
| 6437 | BPF_EXIT_INSN(), |
| 6438 | }, |
| 6439 | INTERNAL, |
| 6440 | { }, |
| 6441 | { { 0, -10 } } |
| 6442 | }, |
| 6443 | { |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6444 | "ALU64_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff", |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6445 | .u.insns_int = { |
| 6446 | BPF_LD_IMM64(R0, 0xff00ff0000000000LL), |
| 6447 | BPF_ALU32_IMM(BPF_MOV, R1, 40), |
| 6448 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6449 | BPF_EXIT_INSN(), |
| 6450 | }, |
| 6451 | INTERNAL, |
| 6452 | { }, |
| 6453 | { { 0, 0xffff00ff } }, |
| 6454 | }, |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6455 | { |
| 6456 | "ALU64_ARSH_X: Shift < 32, low word", |
| 6457 | .u.insns_int = { |
| 6458 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6459 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 6460 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6461 | BPF_EXIT_INSN(), |
| 6462 | }, |
| 6463 | INTERNAL, |
| 6464 | { }, |
| 6465 | { { 0, 0x56789abc } } |
| 6466 | }, |
| 6467 | { |
| 6468 | "ALU64_ARSH_X: Shift < 32, high word", |
| 6469 | .u.insns_int = { |
| 6470 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6471 | BPF_ALU32_IMM(BPF_MOV, R1, 12), |
| 6472 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6473 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6474 | BPF_EXIT_INSN(), |
| 6475 | }, |
| 6476 | INTERNAL, |
| 6477 | { }, |
| 6478 | { { 0, 0xfff81234 } } |
| 6479 | }, |
| 6480 | { |
| 6481 | "ALU64_ARSH_X: Shift > 32, low word", |
| 6482 | .u.insns_int = { |
| 6483 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6484 | BPF_ALU32_IMM(BPF_MOV, R1, 36), |
| 6485 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6486 | BPF_EXIT_INSN(), |
| 6487 | }, |
| 6488 | INTERNAL, |
| 6489 | { }, |
| 6490 | { { 0, 0xf8123456 } } |
| 6491 | }, |
| 6492 | { |
| 6493 | "ALU64_ARSH_X: Shift > 32, high word", |
| 6494 | .u.insns_int = { |
| 6495 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6496 | BPF_ALU32_IMM(BPF_MOV, R1, 36), |
| 6497 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6498 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6499 | BPF_EXIT_INSN(), |
| 6500 | }, |
| 6501 | INTERNAL, |
| 6502 | { }, |
| 6503 | { { 0, -1 } } |
| 6504 | }, |
| 6505 | { |
| 6506 | "ALU64_ARSH_X: Shift == 32, low word", |
| 6507 | .u.insns_int = { |
| 6508 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6509 | BPF_ALU32_IMM(BPF_MOV, R1, 32), |
| 6510 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6511 | BPF_EXIT_INSN(), |
| 6512 | }, |
| 6513 | INTERNAL, |
| 6514 | { }, |
| 6515 | { { 0, 0x81234567 } } |
| 6516 | }, |
| 6517 | { |
| 6518 | "ALU64_ARSH_X: Shift == 32, high word", |
| 6519 | .u.insns_int = { |
| 6520 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6521 | BPF_ALU32_IMM(BPF_MOV, R1, 32), |
| 6522 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6523 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6524 | BPF_EXIT_INSN(), |
| 6525 | }, |
| 6526 | INTERNAL, |
| 6527 | { }, |
| 6528 | { { 0, -1 } } |
| 6529 | }, |
| 6530 | { |
| 6531 | "ALU64_ARSH_X: Zero shift, low word", |
| 6532 | .u.insns_int = { |
| 6533 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6534 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 6535 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6536 | BPF_EXIT_INSN(), |
| 6537 | }, |
| 6538 | INTERNAL, |
| 6539 | { }, |
| 6540 | { { 0, 0x89abcdef } } |
| 6541 | }, |
| 6542 | { |
| 6543 | "ALU64_ARSH_X: Zero shift, high word", |
| 6544 | .u.insns_int = { |
| 6545 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6546 | BPF_ALU32_IMM(BPF_MOV, R1, 0), |
| 6547 | BPF_ALU64_REG(BPF_ARSH, R0, R1), |
| 6548 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6549 | BPF_EXIT_INSN(), |
| 6550 | }, |
| 6551 | INTERNAL, |
| 6552 | { }, |
| 6553 | { { 0, 0x81234567 } } |
| 6554 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6555 | /* BPF_ALU | BPF_ARSH | BPF_K */ |
| 6556 | { |
Johan Almbladh | 0f2fca1 | 2021-08-09 11:18:20 +0200 | [diff] [blame] | 6557 | "ALU32_ARSH_K: -1234 >> 7 = -10", |
| 6558 | .u.insns_int = { |
| 6559 | BPF_ALU32_IMM(BPF_MOV, R0, -1234), |
| 6560 | BPF_ALU32_IMM(BPF_ARSH, R0, 7), |
| 6561 | BPF_EXIT_INSN(), |
| 6562 | }, |
| 6563 | INTERNAL, |
| 6564 | { }, |
| 6565 | { { 0, -10 } } |
| 6566 | }, |
| 6567 | { |
| 6568 | "ALU32_ARSH_K: -1234 >> 0 = -1234", |
| 6569 | .u.insns_int = { |
| 6570 | BPF_ALU32_IMM(BPF_MOV, R0, -1234), |
| 6571 | BPF_ALU32_IMM(BPF_ARSH, R0, 0), |
| 6572 | BPF_EXIT_INSN(), |
| 6573 | }, |
| 6574 | INTERNAL, |
| 6575 | { }, |
| 6576 | { { 0, -1234 } } |
| 6577 | }, |
| 6578 | { |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6579 | "ALU64_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff", |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6580 | .u.insns_int = { |
| 6581 | BPF_LD_IMM64(R0, 0xff00ff0000000000LL), |
| 6582 | BPF_ALU64_IMM(BPF_ARSH, R0, 40), |
| 6583 | BPF_EXIT_INSN(), |
| 6584 | }, |
| 6585 | INTERNAL, |
| 6586 | { }, |
| 6587 | { { 0, 0xffff00ff } }, |
| 6588 | }, |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6589 | { |
| 6590 | "ALU64_ARSH_K: Shift < 32, low word", |
| 6591 | .u.insns_int = { |
| 6592 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6593 | BPF_ALU64_IMM(BPF_RSH, R0, 12), |
| 6594 | BPF_EXIT_INSN(), |
| 6595 | }, |
| 6596 | INTERNAL, |
| 6597 | { }, |
| 6598 | { { 0, 0x56789abc } } |
| 6599 | }, |
| 6600 | { |
| 6601 | "ALU64_ARSH_K: Shift < 32, high word", |
| 6602 | .u.insns_int = { |
| 6603 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6604 | BPF_ALU64_IMM(BPF_ARSH, R0, 12), |
| 6605 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6606 | BPF_EXIT_INSN(), |
| 6607 | }, |
| 6608 | INTERNAL, |
| 6609 | { }, |
| 6610 | { { 0, 0xfff81234 } } |
| 6611 | }, |
| 6612 | { |
| 6613 | "ALU64_ARSH_K: Shift > 32, low word", |
| 6614 | .u.insns_int = { |
| 6615 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6616 | BPF_ALU64_IMM(BPF_ARSH, R0, 36), |
| 6617 | BPF_EXIT_INSN(), |
| 6618 | }, |
| 6619 | INTERNAL, |
| 6620 | { }, |
| 6621 | { { 0, 0xf8123456 } } |
| 6622 | }, |
| 6623 | { |
| 6624 | "ALU64_ARSH_K: Shift > 32, high word", |
| 6625 | .u.insns_int = { |
| 6626 | BPF_LD_IMM64(R0, 0xf123456789abcdefLL), |
| 6627 | BPF_ALU64_IMM(BPF_ARSH, R0, 36), |
| 6628 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6629 | BPF_EXIT_INSN(), |
| 6630 | }, |
| 6631 | INTERNAL, |
| 6632 | { }, |
| 6633 | { { 0, -1 } } |
| 6634 | }, |
| 6635 | { |
| 6636 | "ALU64_ARSH_K: Shift == 32, low word", |
| 6637 | .u.insns_int = { |
| 6638 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6639 | BPF_ALU64_IMM(BPF_ARSH, R0, 32), |
| 6640 | BPF_EXIT_INSN(), |
| 6641 | }, |
| 6642 | INTERNAL, |
| 6643 | { }, |
| 6644 | { { 0, 0x81234567 } } |
| 6645 | }, |
| 6646 | { |
| 6647 | "ALU64_ARSH_K: Shift == 32, high word", |
| 6648 | .u.insns_int = { |
| 6649 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6650 | BPF_ALU64_IMM(BPF_ARSH, R0, 32), |
| 6651 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6652 | BPF_EXIT_INSN(), |
| 6653 | }, |
| 6654 | INTERNAL, |
| 6655 | { }, |
| 6656 | { { 0, -1 } } |
| 6657 | }, |
| 6658 | { |
Colin Ian King | 1bda52f | 2021-08-15 22:39:50 +0100 | [diff] [blame] | 6659 | "ALU64_ARSH_K: Zero shift", |
Johan Almbladh | 3b9890e | 2021-08-09 11:18:21 +0200 | [diff] [blame] | 6660 | .u.insns_int = { |
| 6661 | BPF_LD_IMM64(R0, 0x8123456789abcdefLL), |
| 6662 | BPF_ALU64_IMM(BPF_ARSH, R0, 0), |
| 6663 | BPF_EXIT_INSN(), |
| 6664 | }, |
| 6665 | INTERNAL, |
| 6666 | { }, |
| 6667 | { { 0, 0x89abcdef } } |
| 6668 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6669 | /* BPF_ALU | BPF_NEG */ |
| 6670 | { |
| 6671 | "ALU_NEG: -(3) = -3", |
| 6672 | .u.insns_int = { |
| 6673 | BPF_ALU32_IMM(BPF_MOV, R0, 3), |
| 6674 | BPF_ALU32_IMM(BPF_NEG, R0, 0), |
| 6675 | BPF_EXIT_INSN(), |
| 6676 | }, |
| 6677 | INTERNAL, |
| 6678 | { }, |
| 6679 | { { 0, -3 } }, |
| 6680 | }, |
| 6681 | { |
| 6682 | "ALU_NEG: -(-3) = 3", |
| 6683 | .u.insns_int = { |
| 6684 | BPF_ALU32_IMM(BPF_MOV, R0, -3), |
| 6685 | BPF_ALU32_IMM(BPF_NEG, R0, 0), |
| 6686 | BPF_EXIT_INSN(), |
| 6687 | }, |
| 6688 | INTERNAL, |
| 6689 | { }, |
| 6690 | { { 0, 3 } }, |
| 6691 | }, |
| 6692 | { |
| 6693 | "ALU64_NEG: -(3) = -3", |
| 6694 | .u.insns_int = { |
| 6695 | BPF_LD_IMM64(R0, 3), |
| 6696 | BPF_ALU64_IMM(BPF_NEG, R0, 0), |
| 6697 | BPF_EXIT_INSN(), |
| 6698 | }, |
| 6699 | INTERNAL, |
| 6700 | { }, |
| 6701 | { { 0, -3 } }, |
| 6702 | }, |
| 6703 | { |
| 6704 | "ALU64_NEG: -(-3) = 3", |
| 6705 | .u.insns_int = { |
| 6706 | BPF_LD_IMM64(R0, -3), |
| 6707 | BPF_ALU64_IMM(BPF_NEG, R0, 0), |
| 6708 | BPF_EXIT_INSN(), |
| 6709 | }, |
| 6710 | INTERNAL, |
| 6711 | { }, |
| 6712 | { { 0, 3 } }, |
| 6713 | }, |
| 6714 | /* BPF_ALU | BPF_END | BPF_FROM_BE */ |
| 6715 | { |
| 6716 | "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef", |
| 6717 | .u.insns_int = { |
| 6718 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6719 | BPF_ENDIAN(BPF_FROM_BE, R0, 16), |
| 6720 | BPF_EXIT_INSN(), |
| 6721 | }, |
| 6722 | INTERNAL, |
| 6723 | { }, |
| 6724 | { { 0, cpu_to_be16(0xcdef) } }, |
| 6725 | }, |
| 6726 | { |
| 6727 | "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef", |
| 6728 | .u.insns_int = { |
| 6729 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6730 | BPF_ENDIAN(BPF_FROM_BE, R0, 32), |
Xi Wang | ba29bec | 2015-07-08 14:00:56 -0700 | [diff] [blame] | 6731 | BPF_ALU64_REG(BPF_MOV, R1, R0), |
| 6732 | BPF_ALU64_IMM(BPF_RSH, R1, 32), |
| 6733 | BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */ |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6734 | BPF_EXIT_INSN(), |
| 6735 | }, |
| 6736 | INTERNAL, |
| 6737 | { }, |
| 6738 | { { 0, cpu_to_be32(0x89abcdef) } }, |
| 6739 | }, |
| 6740 | { |
| 6741 | "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef", |
| 6742 | .u.insns_int = { |
| 6743 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6744 | BPF_ENDIAN(BPF_FROM_BE, R0, 64), |
| 6745 | BPF_EXIT_INSN(), |
| 6746 | }, |
| 6747 | INTERNAL, |
| 6748 | { }, |
| 6749 | { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } }, |
| 6750 | }, |
Johan Almbladh | f536a7c | 2021-09-14 11:18:40 +0200 | [diff] [blame] | 6751 | { |
| 6752 | "ALU_END_FROM_BE 64: 0x0123456789abcdef >> 32 -> 0x01234567", |
| 6753 | .u.insns_int = { |
| 6754 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6755 | BPF_ENDIAN(BPF_FROM_BE, R0, 64), |
| 6756 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6757 | BPF_EXIT_INSN(), |
| 6758 | }, |
| 6759 | INTERNAL, |
| 6760 | { }, |
| 6761 | { { 0, (u32) (cpu_to_be64(0x0123456789abcdefLL) >> 32) } }, |
| 6762 | }, |
| 6763 | /* BPF_ALU | BPF_END | BPF_FROM_BE, reversed */ |
| 6764 | { |
| 6765 | "ALU_END_FROM_BE 16: 0xfedcba9876543210 -> 0x3210", |
| 6766 | .u.insns_int = { |
| 6767 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6768 | BPF_ENDIAN(BPF_FROM_BE, R0, 16), |
| 6769 | BPF_EXIT_INSN(), |
| 6770 | }, |
| 6771 | INTERNAL, |
| 6772 | { }, |
| 6773 | { { 0, cpu_to_be16(0x3210) } }, |
| 6774 | }, |
| 6775 | { |
| 6776 | "ALU_END_FROM_BE 32: 0xfedcba9876543210 -> 0x76543210", |
| 6777 | .u.insns_int = { |
| 6778 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6779 | BPF_ENDIAN(BPF_FROM_BE, R0, 32), |
| 6780 | BPF_ALU64_REG(BPF_MOV, R1, R0), |
| 6781 | BPF_ALU64_IMM(BPF_RSH, R1, 32), |
| 6782 | BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */ |
| 6783 | BPF_EXIT_INSN(), |
| 6784 | }, |
| 6785 | INTERNAL, |
| 6786 | { }, |
| 6787 | { { 0, cpu_to_be32(0x76543210) } }, |
| 6788 | }, |
| 6789 | { |
| 6790 | "ALU_END_FROM_BE 64: 0xfedcba9876543210 -> 0x76543210", |
| 6791 | .u.insns_int = { |
| 6792 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6793 | BPF_ENDIAN(BPF_FROM_BE, R0, 64), |
| 6794 | BPF_EXIT_INSN(), |
| 6795 | }, |
| 6796 | INTERNAL, |
| 6797 | { }, |
| 6798 | { { 0, (u32) cpu_to_be64(0xfedcba9876543210ULL) } }, |
| 6799 | }, |
| 6800 | { |
| 6801 | "ALU_END_FROM_BE 64: 0xfedcba9876543210 >> 32 -> 0xfedcba98", |
| 6802 | .u.insns_int = { |
| 6803 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6804 | BPF_ENDIAN(BPF_FROM_BE, R0, 64), |
| 6805 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6806 | BPF_EXIT_INSN(), |
| 6807 | }, |
| 6808 | INTERNAL, |
| 6809 | { }, |
| 6810 | { { 0, (u32) (cpu_to_be64(0xfedcba9876543210ULL) >> 32) } }, |
| 6811 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6812 | /* BPF_ALU | BPF_END | BPF_FROM_LE */ |
| 6813 | { |
| 6814 | "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd", |
| 6815 | .u.insns_int = { |
| 6816 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6817 | BPF_ENDIAN(BPF_FROM_LE, R0, 16), |
| 6818 | BPF_EXIT_INSN(), |
| 6819 | }, |
| 6820 | INTERNAL, |
| 6821 | { }, |
| 6822 | { { 0, cpu_to_le16(0xcdef) } }, |
| 6823 | }, |
| 6824 | { |
| 6825 | "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89", |
| 6826 | .u.insns_int = { |
| 6827 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6828 | BPF_ENDIAN(BPF_FROM_LE, R0, 32), |
Xi Wang | ba29bec | 2015-07-08 14:00:56 -0700 | [diff] [blame] | 6829 | BPF_ALU64_REG(BPF_MOV, R1, R0), |
| 6830 | BPF_ALU64_IMM(BPF_RSH, R1, 32), |
| 6831 | BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */ |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6832 | BPF_EXIT_INSN(), |
| 6833 | }, |
| 6834 | INTERNAL, |
| 6835 | { }, |
| 6836 | { { 0, cpu_to_le32(0x89abcdef) } }, |
| 6837 | }, |
| 6838 | { |
| 6839 | "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301", |
| 6840 | .u.insns_int = { |
| 6841 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6842 | BPF_ENDIAN(BPF_FROM_LE, R0, 64), |
| 6843 | BPF_EXIT_INSN(), |
| 6844 | }, |
| 6845 | INTERNAL, |
| 6846 | { }, |
| 6847 | { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } }, |
| 6848 | }, |
Johan Almbladh | f536a7c | 2021-09-14 11:18:40 +0200 | [diff] [blame] | 6849 | { |
| 6850 | "ALU_END_FROM_LE 64: 0x0123456789abcdef >> 32 -> 0xefcdab89", |
| 6851 | .u.insns_int = { |
| 6852 | BPF_LD_IMM64(R0, 0x0123456789abcdefLL), |
| 6853 | BPF_ENDIAN(BPF_FROM_LE, R0, 64), |
| 6854 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6855 | BPF_EXIT_INSN(), |
| 6856 | }, |
| 6857 | INTERNAL, |
| 6858 | { }, |
| 6859 | { { 0, (u32) (cpu_to_le64(0x0123456789abcdefLL) >> 32) } }, |
| 6860 | }, |
| 6861 | /* BPF_ALU | BPF_END | BPF_FROM_LE, reversed */ |
| 6862 | { |
| 6863 | "ALU_END_FROM_LE 16: 0xfedcba9876543210 -> 0x1032", |
| 6864 | .u.insns_int = { |
| 6865 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6866 | BPF_ENDIAN(BPF_FROM_LE, R0, 16), |
| 6867 | BPF_EXIT_INSN(), |
| 6868 | }, |
| 6869 | INTERNAL, |
| 6870 | { }, |
| 6871 | { { 0, cpu_to_le16(0x3210) } }, |
| 6872 | }, |
| 6873 | { |
| 6874 | "ALU_END_FROM_LE 32: 0xfedcba9876543210 -> 0x10325476", |
| 6875 | .u.insns_int = { |
| 6876 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6877 | BPF_ENDIAN(BPF_FROM_LE, R0, 32), |
| 6878 | BPF_ALU64_REG(BPF_MOV, R1, R0), |
| 6879 | BPF_ALU64_IMM(BPF_RSH, R1, 32), |
| 6880 | BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */ |
| 6881 | BPF_EXIT_INSN(), |
| 6882 | }, |
| 6883 | INTERNAL, |
| 6884 | { }, |
| 6885 | { { 0, cpu_to_le32(0x76543210) } }, |
| 6886 | }, |
| 6887 | { |
| 6888 | "ALU_END_FROM_LE 64: 0xfedcba9876543210 -> 0x10325476", |
| 6889 | .u.insns_int = { |
| 6890 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6891 | BPF_ENDIAN(BPF_FROM_LE, R0, 64), |
| 6892 | BPF_EXIT_INSN(), |
| 6893 | }, |
| 6894 | INTERNAL, |
| 6895 | { }, |
| 6896 | { { 0, (u32) cpu_to_le64(0xfedcba9876543210ULL) } }, |
| 6897 | }, |
| 6898 | { |
| 6899 | "ALU_END_FROM_LE 64: 0xfedcba9876543210 >> 32 -> 0x98badcfe", |
| 6900 | .u.insns_int = { |
| 6901 | BPF_LD_IMM64(R0, 0xfedcba9876543210ULL), |
| 6902 | BPF_ENDIAN(BPF_FROM_LE, R0, 64), |
| 6903 | BPF_ALU64_IMM(BPF_RSH, R0, 32), |
| 6904 | BPF_EXIT_INSN(), |
| 6905 | }, |
| 6906 | INTERNAL, |
| 6907 | { }, |
| 6908 | { { 0, (u32) (cpu_to_le64(0xfedcba9876543210ULL) >> 32) } }, |
| 6909 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6910 | /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */ |
| 6911 | { |
| 6912 | "ST_MEM_B: Store/Load byte: max negative", |
| 6913 | .u.insns_int = { |
| 6914 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 6915 | BPF_ST_MEM(BPF_B, R10, -40, 0xff), |
| 6916 | BPF_LDX_MEM(BPF_B, R0, R10, -40), |
| 6917 | BPF_EXIT_INSN(), |
| 6918 | }, |
| 6919 | INTERNAL, |
| 6920 | { }, |
| 6921 | { { 0, 0xff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 6922 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6923 | }, |
| 6924 | { |
| 6925 | "ST_MEM_B: Store/Load byte: max positive", |
| 6926 | .u.insns_int = { |
| 6927 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 6928 | BPF_ST_MEM(BPF_H, R10, -40, 0x7f), |
| 6929 | BPF_LDX_MEM(BPF_H, R0, R10, -40), |
| 6930 | BPF_EXIT_INSN(), |
| 6931 | }, |
| 6932 | INTERNAL, |
| 6933 | { }, |
| 6934 | { { 0, 0x7f } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 6935 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6936 | }, |
| 6937 | { |
| 6938 | "STX_MEM_B: Store/Load byte: max negative", |
| 6939 | .u.insns_int = { |
| 6940 | BPF_LD_IMM64(R0, 0), |
| 6941 | BPF_LD_IMM64(R1, 0xffLL), |
| 6942 | BPF_STX_MEM(BPF_B, R10, R1, -40), |
| 6943 | BPF_LDX_MEM(BPF_B, R0, R10, -40), |
| 6944 | BPF_EXIT_INSN(), |
| 6945 | }, |
| 6946 | INTERNAL, |
| 6947 | { }, |
| 6948 | { { 0, 0xff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 6949 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6950 | }, |
| 6951 | { |
| 6952 | "ST_MEM_H: Store/Load half word: max negative", |
| 6953 | .u.insns_int = { |
| 6954 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 6955 | BPF_ST_MEM(BPF_H, R10, -40, 0xffff), |
| 6956 | BPF_LDX_MEM(BPF_H, R0, R10, -40), |
| 6957 | BPF_EXIT_INSN(), |
| 6958 | }, |
| 6959 | INTERNAL, |
| 6960 | { }, |
| 6961 | { { 0, 0xffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 6962 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6963 | }, |
| 6964 | { |
| 6965 | "ST_MEM_H: Store/Load half word: max positive", |
| 6966 | .u.insns_int = { |
| 6967 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 6968 | BPF_ST_MEM(BPF_H, R10, -40, 0x7fff), |
| 6969 | BPF_LDX_MEM(BPF_H, R0, R10, -40), |
| 6970 | BPF_EXIT_INSN(), |
| 6971 | }, |
| 6972 | INTERNAL, |
| 6973 | { }, |
| 6974 | { { 0, 0x7fff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 6975 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6976 | }, |
| 6977 | { |
| 6978 | "STX_MEM_H: Store/Load half word: max negative", |
| 6979 | .u.insns_int = { |
| 6980 | BPF_LD_IMM64(R0, 0), |
| 6981 | BPF_LD_IMM64(R1, 0xffffLL), |
| 6982 | BPF_STX_MEM(BPF_H, R10, R1, -40), |
| 6983 | BPF_LDX_MEM(BPF_H, R0, R10, -40), |
| 6984 | BPF_EXIT_INSN(), |
| 6985 | }, |
| 6986 | INTERNAL, |
| 6987 | { }, |
| 6988 | { { 0, 0xffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 6989 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 6990 | }, |
| 6991 | { |
| 6992 | "ST_MEM_W: Store/Load word: max negative", |
| 6993 | .u.insns_int = { |
| 6994 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 6995 | BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff), |
| 6996 | BPF_LDX_MEM(BPF_W, R0, R10, -40), |
| 6997 | BPF_EXIT_INSN(), |
| 6998 | }, |
| 6999 | INTERNAL, |
| 7000 | { }, |
| 7001 | { { 0, 0xffffffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7002 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7003 | }, |
| 7004 | { |
| 7005 | "ST_MEM_W: Store/Load word: max positive", |
| 7006 | .u.insns_int = { |
| 7007 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 7008 | BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff), |
| 7009 | BPF_LDX_MEM(BPF_W, R0, R10, -40), |
| 7010 | BPF_EXIT_INSN(), |
| 7011 | }, |
| 7012 | INTERNAL, |
| 7013 | { }, |
| 7014 | { { 0, 0x7fffffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7015 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7016 | }, |
| 7017 | { |
| 7018 | "STX_MEM_W: Store/Load word: max negative", |
| 7019 | .u.insns_int = { |
| 7020 | BPF_LD_IMM64(R0, 0), |
| 7021 | BPF_LD_IMM64(R1, 0xffffffffLL), |
| 7022 | BPF_STX_MEM(BPF_W, R10, R1, -40), |
| 7023 | BPF_LDX_MEM(BPF_W, R0, R10, -40), |
| 7024 | BPF_EXIT_INSN(), |
| 7025 | }, |
| 7026 | INTERNAL, |
| 7027 | { }, |
| 7028 | { { 0, 0xffffffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7029 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7030 | }, |
| 7031 | { |
| 7032 | "ST_MEM_DW: Store/Load double word: max negative", |
| 7033 | .u.insns_int = { |
| 7034 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 7035 | BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff), |
| 7036 | BPF_LDX_MEM(BPF_DW, R0, R10, -40), |
| 7037 | BPF_EXIT_INSN(), |
| 7038 | }, |
| 7039 | INTERNAL, |
| 7040 | { }, |
| 7041 | { { 0, 0xffffffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7042 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7043 | }, |
| 7044 | { |
| 7045 | "ST_MEM_DW: Store/Load double word: max negative 2", |
| 7046 | .u.insns_int = { |
Michael Holzheu | 56cbaa4 | 2015-05-13 20:40:39 -0700 | [diff] [blame] | 7047 | BPF_LD_IMM64(R2, 0xffff00000000ffffLL), |
| 7048 | BPF_LD_IMM64(R3, 0xffffffffffffffffLL), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7049 | BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff), |
| 7050 | BPF_LDX_MEM(BPF_DW, R2, R10, -40), |
| 7051 | BPF_JMP_REG(BPF_JEQ, R2, R3, 2), |
| 7052 | BPF_MOV32_IMM(R0, 2), |
| 7053 | BPF_EXIT_INSN(), |
| 7054 | BPF_MOV32_IMM(R0, 1), |
| 7055 | BPF_EXIT_INSN(), |
| 7056 | }, |
| 7057 | INTERNAL, |
| 7058 | { }, |
| 7059 | { { 0, 0x1 } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7060 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7061 | }, |
| 7062 | { |
| 7063 | "ST_MEM_DW: Store/Load double word: max positive", |
| 7064 | .u.insns_int = { |
| 7065 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 7066 | BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff), |
| 7067 | BPF_LDX_MEM(BPF_DW, R0, R10, -40), |
| 7068 | BPF_EXIT_INSN(), |
| 7069 | }, |
| 7070 | INTERNAL, |
| 7071 | { }, |
| 7072 | { { 0, 0x7fffffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7073 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7074 | }, |
| 7075 | { |
| 7076 | "STX_MEM_DW: Store/Load double word: max negative", |
| 7077 | .u.insns_int = { |
| 7078 | BPF_LD_IMM64(R0, 0), |
| 7079 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
Johan Almbladh | ae7f470 | 2021-07-21 12:40:58 +0200 | [diff] [blame] | 7080 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7081 | BPF_LDX_MEM(BPF_DW, R0, R10, -40), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7082 | BPF_EXIT_INSN(), |
| 7083 | }, |
| 7084 | INTERNAL, |
| 7085 | { }, |
| 7086 | { { 0, 0xffffffff } }, |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 7087 | .stack_depth = 40, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7088 | }, |
Johan Almbladh | e5009b4 | 2021-08-09 11:18:24 +0200 | [diff] [blame] | 7089 | { |
| 7090 | "STX_MEM_DW: Store double word: first word in memory", |
| 7091 | .u.insns_int = { |
| 7092 | BPF_LD_IMM64(R0, 0), |
| 7093 | BPF_LD_IMM64(R1, 0x0123456789abcdefLL), |
| 7094 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7095 | BPF_LDX_MEM(BPF_W, R0, R10, -40), |
| 7096 | BPF_EXIT_INSN(), |
| 7097 | }, |
| 7098 | INTERNAL, |
| 7099 | { }, |
| 7100 | #ifdef __BIG_ENDIAN |
| 7101 | { { 0, 0x01234567 } }, |
| 7102 | #else |
| 7103 | { { 0, 0x89abcdef } }, |
| 7104 | #endif |
| 7105 | .stack_depth = 40, |
| 7106 | }, |
| 7107 | { |
| 7108 | "STX_MEM_DW: Store double word: second word in memory", |
| 7109 | .u.insns_int = { |
| 7110 | BPF_LD_IMM64(R0, 0), |
| 7111 | BPF_LD_IMM64(R1, 0x0123456789abcdefLL), |
| 7112 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7113 | BPF_LDX_MEM(BPF_W, R0, R10, -36), |
| 7114 | BPF_EXIT_INSN(), |
| 7115 | }, |
| 7116 | INTERNAL, |
| 7117 | { }, |
| 7118 | #ifdef __BIG_ENDIAN |
| 7119 | { { 0, 0x89abcdef } }, |
| 7120 | #else |
| 7121 | { { 0, 0x01234567 } }, |
| 7122 | #endif |
| 7123 | .stack_depth = 40, |
| 7124 | }, |
Brendan Jackman | 91c960b | 2021-01-14 18:17:44 +0000 | [diff] [blame] | 7125 | /* BPF_STX | BPF_ATOMIC | BPF_W/DW */ |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7126 | { |
Daniel Borkmann | 85f68fe | 2017-05-01 02:57:20 +0200 | [diff] [blame] | 7127 | "STX_XADD_W: X + 1 + 1 + 1 + ...", |
| 7128 | { }, |
| 7129 | INTERNAL, |
| 7130 | { }, |
| 7131 | { { 0, 4134 } }, |
| 7132 | .fill_helper = bpf_fill_stxw, |
| 7133 | }, |
| 7134 | { |
Daniel Borkmann | 85f68fe | 2017-05-01 02:57:20 +0200 | [diff] [blame] | 7135 | "STX_XADD_DW: X + 1 + 1 + 1 + ...", |
| 7136 | { }, |
| 7137 | INTERNAL, |
| 7138 | { }, |
| 7139 | { { 0, 4134 } }, |
| 7140 | .fill_helper = bpf_fill_stxdw, |
| 7141 | }, |
Johan Almbladh | e4517b3 | 2021-08-09 11:18:27 +0200 | [diff] [blame] | 7142 | /* |
| 7143 | * Exhaustive tests of atomic operation variants. |
| 7144 | * Individual tests are expanded from template macros for all |
| 7145 | * combinations of ALU operation, word size and fetching. |
| 7146 | */ |
| 7147 | #define BPF_ATOMIC_OP_TEST1(width, op, logic, old, update, result) \ |
| 7148 | { \ |
| 7149 | "BPF_ATOMIC | " #width ", " #op ": Test: " \ |
| 7150 | #old " " #logic " " #update " = " #result, \ |
| 7151 | .u.insns_int = { \ |
| 7152 | BPF_ALU32_IMM(BPF_MOV, R5, update), \ |
| 7153 | BPF_ST_MEM(width, R10, -40, old), \ |
| 7154 | BPF_ATOMIC_OP(width, op, R10, R5, -40), \ |
| 7155 | BPF_LDX_MEM(width, R0, R10, -40), \ |
| 7156 | BPF_EXIT_INSN(), \ |
| 7157 | }, \ |
| 7158 | INTERNAL, \ |
| 7159 | { }, \ |
| 7160 | { { 0, result } }, \ |
| 7161 | .stack_depth = 40, \ |
| 7162 | } |
| 7163 | #define BPF_ATOMIC_OP_TEST2(width, op, logic, old, update, result) \ |
| 7164 | { \ |
| 7165 | "BPF_ATOMIC | " #width ", " #op ": Test side effects, r10: " \ |
| 7166 | #old " " #logic " " #update " = " #result, \ |
| 7167 | .u.insns_int = { \ |
| 7168 | BPF_ALU64_REG(BPF_MOV, R1, R10), \ |
| 7169 | BPF_ALU32_IMM(BPF_MOV, R0, update), \ |
| 7170 | BPF_ST_MEM(BPF_W, R10, -40, old), \ |
| 7171 | BPF_ATOMIC_OP(width, op, R10, R0, -40), \ |
| 7172 | BPF_ALU64_REG(BPF_MOV, R0, R10), \ |
| 7173 | BPF_ALU64_REG(BPF_SUB, R0, R1), \ |
| 7174 | BPF_EXIT_INSN(), \ |
| 7175 | }, \ |
| 7176 | INTERNAL, \ |
| 7177 | { }, \ |
| 7178 | { { 0, 0 } }, \ |
| 7179 | .stack_depth = 40, \ |
| 7180 | } |
| 7181 | #define BPF_ATOMIC_OP_TEST3(width, op, logic, old, update, result) \ |
| 7182 | { \ |
| 7183 | "BPF_ATOMIC | " #width ", " #op ": Test side effects, r0: " \ |
| 7184 | #old " " #logic " " #update " = " #result, \ |
| 7185 | .u.insns_int = { \ |
| 7186 | BPF_ALU64_REG(BPF_MOV, R0, R10), \ |
| 7187 | BPF_ALU32_IMM(BPF_MOV, R1, update), \ |
| 7188 | BPF_ST_MEM(width, R10, -40, old), \ |
| 7189 | BPF_ATOMIC_OP(width, op, R10, R1, -40), \ |
| 7190 | BPF_ALU64_REG(BPF_SUB, R0, R10), \ |
| 7191 | BPF_EXIT_INSN(), \ |
| 7192 | }, \ |
| 7193 | INTERNAL, \ |
| 7194 | { }, \ |
| 7195 | { { 0, 0 } }, \ |
| 7196 | .stack_depth = 40, \ |
| 7197 | } |
| 7198 | #define BPF_ATOMIC_OP_TEST4(width, op, logic, old, update, result) \ |
| 7199 | { \ |
| 7200 | "BPF_ATOMIC | " #width ", " #op ": Test fetch: " \ |
| 7201 | #old " " #logic " " #update " = " #result, \ |
| 7202 | .u.insns_int = { \ |
| 7203 | BPF_ALU32_IMM(BPF_MOV, R3, update), \ |
| 7204 | BPF_ST_MEM(width, R10, -40, old), \ |
| 7205 | BPF_ATOMIC_OP(width, op, R10, R3, -40), \ |
| 7206 | BPF_ALU64_REG(BPF_MOV, R0, R3), \ |
| 7207 | BPF_EXIT_INSN(), \ |
| 7208 | }, \ |
| 7209 | INTERNAL, \ |
| 7210 | { }, \ |
| 7211 | { { 0, (op) & BPF_FETCH ? old : update } }, \ |
| 7212 | .stack_depth = 40, \ |
| 7213 | } |
| 7214 | /* BPF_ATOMIC | BPF_W: BPF_ADD */ |
| 7215 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7216 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7217 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7218 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7219 | /* BPF_ATOMIC | BPF_W: BPF_ADD | BPF_FETCH */ |
| 7220 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7221 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7222 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7223 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7224 | /* BPF_ATOMIC | BPF_DW: BPF_ADD */ |
| 7225 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7226 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7227 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7228 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD, +, 0x12, 0xab, 0xbd), |
| 7229 | /* BPF_ATOMIC | BPF_DW: BPF_ADD | BPF_FETCH */ |
| 7230 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7231 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7232 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7233 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_ADD | BPF_FETCH, +, 0x12, 0xab, 0xbd), |
| 7234 | /* BPF_ATOMIC | BPF_W: BPF_AND */ |
| 7235 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7236 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7237 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7238 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7239 | /* BPF_ATOMIC | BPF_W: BPF_AND | BPF_FETCH */ |
| 7240 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7241 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7242 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7243 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7244 | /* BPF_ATOMIC | BPF_DW: BPF_AND */ |
| 7245 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7246 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7247 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7248 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND, &, 0x12, 0xab, 0x02), |
| 7249 | /* BPF_ATOMIC | BPF_DW: BPF_AND | BPF_FETCH */ |
| 7250 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7251 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7252 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7253 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_AND | BPF_FETCH, &, 0x12, 0xab, 0x02), |
| 7254 | /* BPF_ATOMIC | BPF_W: BPF_OR */ |
| 7255 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7256 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7257 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7258 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7259 | /* BPF_ATOMIC | BPF_W: BPF_OR | BPF_FETCH */ |
| 7260 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7261 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7262 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7263 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7264 | /* BPF_ATOMIC | BPF_DW: BPF_OR */ |
| 7265 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7266 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7267 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7268 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR, |, 0x12, 0xab, 0xbb), |
| 7269 | /* BPF_ATOMIC | BPF_DW: BPF_OR | BPF_FETCH */ |
| 7270 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7271 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7272 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7273 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_OR | BPF_FETCH, |, 0x12, 0xab, 0xbb), |
| 7274 | /* BPF_ATOMIC | BPF_W: BPF_XOR */ |
| 7275 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7276 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7277 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7278 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7279 | /* BPF_ATOMIC | BPF_W: BPF_XOR | BPF_FETCH */ |
| 7280 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7281 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7282 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7283 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7284 | /* BPF_ATOMIC | BPF_DW: BPF_XOR */ |
| 7285 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7286 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7287 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7288 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR, ^, 0x12, 0xab, 0xb9), |
| 7289 | /* BPF_ATOMIC | BPF_DW: BPF_XOR | BPF_FETCH */ |
| 7290 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7291 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7292 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7293 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XOR | BPF_FETCH, ^, 0x12, 0xab, 0xb9), |
| 7294 | /* BPF_ATOMIC | BPF_W: BPF_XCHG */ |
| 7295 | BPF_ATOMIC_OP_TEST1(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7296 | BPF_ATOMIC_OP_TEST2(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7297 | BPF_ATOMIC_OP_TEST3(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7298 | BPF_ATOMIC_OP_TEST4(BPF_W, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7299 | /* BPF_ATOMIC | BPF_DW: BPF_XCHG */ |
| 7300 | BPF_ATOMIC_OP_TEST1(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7301 | BPF_ATOMIC_OP_TEST2(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7302 | BPF_ATOMIC_OP_TEST3(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7303 | BPF_ATOMIC_OP_TEST4(BPF_DW, BPF_XCHG, xchg, 0x12, 0xab, 0xab), |
| 7304 | #undef BPF_ATOMIC_OP_TEST1 |
| 7305 | #undef BPF_ATOMIC_OP_TEST2 |
| 7306 | #undef BPF_ATOMIC_OP_TEST3 |
| 7307 | #undef BPF_ATOMIC_OP_TEST4 |
Johan Almbladh | 6a3b24c | 2021-08-09 11:18:28 +0200 | [diff] [blame] | 7308 | /* BPF_ATOMIC | BPF_W, BPF_CMPXCHG */ |
| 7309 | { |
| 7310 | "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful return", |
| 7311 | .u.insns_int = { |
| 7312 | BPF_ST_MEM(BPF_W, R10, -40, 0x01234567), |
| 7313 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567), |
| 7314 | BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef), |
| 7315 | BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40), |
| 7316 | BPF_EXIT_INSN(), |
| 7317 | }, |
| 7318 | INTERNAL, |
| 7319 | { }, |
| 7320 | { { 0, 0x01234567 } }, |
| 7321 | .stack_depth = 40, |
| 7322 | }, |
| 7323 | { |
| 7324 | "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test successful store", |
| 7325 | .u.insns_int = { |
| 7326 | BPF_ST_MEM(BPF_W, R10, -40, 0x01234567), |
| 7327 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567), |
| 7328 | BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef), |
| 7329 | BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40), |
| 7330 | BPF_LDX_MEM(BPF_W, R0, R10, -40), |
| 7331 | BPF_EXIT_INSN(), |
| 7332 | }, |
| 7333 | INTERNAL, |
| 7334 | { }, |
| 7335 | { { 0, 0x89abcdef } }, |
| 7336 | .stack_depth = 40, |
| 7337 | }, |
| 7338 | { |
| 7339 | "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure return", |
| 7340 | .u.insns_int = { |
| 7341 | BPF_ST_MEM(BPF_W, R10, -40, 0x01234567), |
| 7342 | BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210), |
| 7343 | BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef), |
| 7344 | BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40), |
| 7345 | BPF_EXIT_INSN(), |
| 7346 | }, |
| 7347 | INTERNAL, |
| 7348 | { }, |
| 7349 | { { 0, 0x01234567 } }, |
| 7350 | .stack_depth = 40, |
| 7351 | }, |
| 7352 | { |
| 7353 | "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test failure store", |
| 7354 | .u.insns_int = { |
| 7355 | BPF_ST_MEM(BPF_W, R10, -40, 0x01234567), |
| 7356 | BPF_ALU32_IMM(BPF_MOV, R0, 0x76543210), |
| 7357 | BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef), |
| 7358 | BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40), |
| 7359 | BPF_LDX_MEM(BPF_W, R0, R10, -40), |
| 7360 | BPF_EXIT_INSN(), |
| 7361 | }, |
| 7362 | INTERNAL, |
| 7363 | { }, |
| 7364 | { { 0, 0x01234567 } }, |
| 7365 | .stack_depth = 40, |
| 7366 | }, |
| 7367 | { |
| 7368 | "BPF_ATOMIC | BPF_W, BPF_CMPXCHG: Test side effects", |
| 7369 | .u.insns_int = { |
| 7370 | BPF_ST_MEM(BPF_W, R10, -40, 0x01234567), |
| 7371 | BPF_ALU32_IMM(BPF_MOV, R0, 0x01234567), |
| 7372 | BPF_ALU32_IMM(BPF_MOV, R3, 0x89abcdef), |
| 7373 | BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40), |
| 7374 | BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, R10, R3, -40), |
| 7375 | BPF_ALU32_REG(BPF_MOV, R0, R3), |
| 7376 | BPF_EXIT_INSN(), |
| 7377 | }, |
| 7378 | INTERNAL, |
| 7379 | { }, |
| 7380 | { { 0, 0x89abcdef } }, |
| 7381 | .stack_depth = 40, |
| 7382 | }, |
| 7383 | /* BPF_ATOMIC | BPF_DW, BPF_CMPXCHG */ |
| 7384 | { |
| 7385 | "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful return", |
| 7386 | .u.insns_int = { |
| 7387 | BPF_LD_IMM64(R1, 0x0123456789abcdefULL), |
| 7388 | BPF_LD_IMM64(R2, 0xfecdba9876543210ULL), |
| 7389 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 7390 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7391 | BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40), |
| 7392 | BPF_JMP_REG(BPF_JNE, R0, R1, 1), |
| 7393 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 7394 | BPF_EXIT_INSN(), |
| 7395 | }, |
| 7396 | INTERNAL, |
| 7397 | { }, |
| 7398 | { { 0, 0 } }, |
| 7399 | .stack_depth = 40, |
| 7400 | }, |
| 7401 | { |
| 7402 | "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test successful store", |
| 7403 | .u.insns_int = { |
| 7404 | BPF_LD_IMM64(R1, 0x0123456789abcdefULL), |
| 7405 | BPF_LD_IMM64(R2, 0xfecdba9876543210ULL), |
| 7406 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 7407 | BPF_STX_MEM(BPF_DW, R10, R0, -40), |
| 7408 | BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40), |
| 7409 | BPF_LDX_MEM(BPF_DW, R0, R10, -40), |
| 7410 | BPF_JMP_REG(BPF_JNE, R0, R2, 1), |
| 7411 | BPF_ALU64_REG(BPF_SUB, R0, R2), |
| 7412 | BPF_EXIT_INSN(), |
| 7413 | }, |
| 7414 | INTERNAL, |
| 7415 | { }, |
| 7416 | { { 0, 0 } }, |
| 7417 | .stack_depth = 40, |
| 7418 | }, |
| 7419 | { |
| 7420 | "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure return", |
| 7421 | .u.insns_int = { |
| 7422 | BPF_LD_IMM64(R1, 0x0123456789abcdefULL), |
| 7423 | BPF_LD_IMM64(R2, 0xfecdba9876543210ULL), |
| 7424 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 7425 | BPF_ALU64_IMM(BPF_ADD, R0, 1), |
| 7426 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7427 | BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40), |
| 7428 | BPF_JMP_REG(BPF_JNE, R0, R1, 1), |
| 7429 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 7430 | BPF_EXIT_INSN(), |
| 7431 | }, |
| 7432 | INTERNAL, |
| 7433 | { }, |
| 7434 | { { 0, 0 } }, |
| 7435 | .stack_depth = 40, |
| 7436 | }, |
| 7437 | { |
| 7438 | "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test failure store", |
| 7439 | .u.insns_int = { |
| 7440 | BPF_LD_IMM64(R1, 0x0123456789abcdefULL), |
| 7441 | BPF_LD_IMM64(R2, 0xfecdba9876543210ULL), |
| 7442 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 7443 | BPF_ALU64_IMM(BPF_ADD, R0, 1), |
| 7444 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7445 | BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40), |
| 7446 | BPF_LDX_MEM(BPF_DW, R0, R10, -40), |
| 7447 | BPF_JMP_REG(BPF_JNE, R0, R1, 1), |
| 7448 | BPF_ALU64_REG(BPF_SUB, R0, R1), |
| 7449 | BPF_EXIT_INSN(), |
| 7450 | }, |
| 7451 | INTERNAL, |
| 7452 | { }, |
| 7453 | { { 0, 0 } }, |
| 7454 | .stack_depth = 40, |
| 7455 | }, |
| 7456 | { |
| 7457 | "BPF_ATOMIC | BPF_DW, BPF_CMPXCHG: Test side effects", |
| 7458 | .u.insns_int = { |
| 7459 | BPF_LD_IMM64(R1, 0x0123456789abcdefULL), |
| 7460 | BPF_LD_IMM64(R2, 0xfecdba9876543210ULL), |
| 7461 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 7462 | BPF_STX_MEM(BPF_DW, R10, R1, -40), |
| 7463 | BPF_ATOMIC_OP(BPF_DW, BPF_CMPXCHG, R10, R2, -40), |
| 7464 | BPF_LD_IMM64(R0, 0xfecdba9876543210ULL), |
| 7465 | BPF_JMP_REG(BPF_JNE, R0, R2, 1), |
| 7466 | BPF_ALU64_REG(BPF_SUB, R0, R2), |
| 7467 | BPF_EXIT_INSN(), |
| 7468 | }, |
| 7469 | INTERNAL, |
| 7470 | { }, |
| 7471 | { { 0, 0 } }, |
| 7472 | .stack_depth = 40, |
| 7473 | }, |
Johan Almbladh | b55dfa8 | 2021-08-09 11:18:16 +0200 | [diff] [blame] | 7474 | /* BPF_JMP32 | BPF_JEQ | BPF_K */ |
| 7475 | { |
| 7476 | "JMP32_JEQ_K: Small immediate", |
| 7477 | .u.insns_int = { |
| 7478 | BPF_ALU32_IMM(BPF_MOV, R0, 123), |
| 7479 | BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1), |
| 7480 | BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1), |
| 7481 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7482 | BPF_EXIT_INSN(), |
| 7483 | }, |
| 7484 | INTERNAL, |
| 7485 | { }, |
| 7486 | { { 0, 123 } } |
| 7487 | }, |
| 7488 | { |
| 7489 | "JMP32_JEQ_K: Large immediate", |
| 7490 | .u.insns_int = { |
| 7491 | BPF_ALU32_IMM(BPF_MOV, R0, 12345678), |
| 7492 | BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1), |
| 7493 | BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1), |
| 7494 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7495 | BPF_EXIT_INSN(), |
| 7496 | }, |
| 7497 | INTERNAL, |
| 7498 | { }, |
| 7499 | { { 0, 12345678 } } |
| 7500 | }, |
| 7501 | { |
| 7502 | "JMP32_JEQ_K: negative immediate", |
| 7503 | .u.insns_int = { |
| 7504 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7505 | BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1), |
| 7506 | BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1), |
| 7507 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7508 | BPF_EXIT_INSN(), |
| 7509 | }, |
| 7510 | INTERNAL, |
| 7511 | { }, |
| 7512 | { { 0, -123 } } |
| 7513 | }, |
| 7514 | /* BPF_JMP32 | BPF_JEQ | BPF_X */ |
| 7515 | { |
| 7516 | "JMP32_JEQ_X", |
| 7517 | .u.insns_int = { |
| 7518 | BPF_ALU32_IMM(BPF_MOV, R0, 1234), |
| 7519 | BPF_ALU32_IMM(BPF_MOV, R1, 4321), |
| 7520 | BPF_JMP32_REG(BPF_JEQ, R0, R1, 2), |
| 7521 | BPF_ALU32_IMM(BPF_MOV, R1, 1234), |
| 7522 | BPF_JMP32_REG(BPF_JEQ, R0, R1, 1), |
| 7523 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7524 | BPF_EXIT_INSN(), |
| 7525 | }, |
| 7526 | INTERNAL, |
| 7527 | { }, |
| 7528 | { { 0, 1234 } } |
| 7529 | }, |
| 7530 | /* BPF_JMP32 | BPF_JNE | BPF_K */ |
| 7531 | { |
| 7532 | "JMP32_JNE_K: Small immediate", |
| 7533 | .u.insns_int = { |
| 7534 | BPF_ALU32_IMM(BPF_MOV, R0, 123), |
| 7535 | BPF_JMP32_IMM(BPF_JNE, R0, 123, 1), |
| 7536 | BPF_JMP32_IMM(BPF_JNE, R0, 321, 1), |
| 7537 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7538 | BPF_EXIT_INSN(), |
| 7539 | }, |
| 7540 | INTERNAL, |
| 7541 | { }, |
| 7542 | { { 0, 123 } } |
| 7543 | }, |
| 7544 | { |
| 7545 | "JMP32_JNE_K: Large immediate", |
| 7546 | .u.insns_int = { |
| 7547 | BPF_ALU32_IMM(BPF_MOV, R0, 12345678), |
| 7548 | BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1), |
| 7549 | BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1), |
| 7550 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7551 | BPF_EXIT_INSN(), |
| 7552 | }, |
| 7553 | INTERNAL, |
| 7554 | { }, |
| 7555 | { { 0, 12345678 } } |
| 7556 | }, |
| 7557 | { |
| 7558 | "JMP32_JNE_K: negative immediate", |
| 7559 | .u.insns_int = { |
| 7560 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7561 | BPF_JMP32_IMM(BPF_JNE, R0, -123, 1), |
| 7562 | BPF_JMP32_IMM(BPF_JNE, R0, 123, 1), |
| 7563 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7564 | BPF_EXIT_INSN(), |
| 7565 | }, |
| 7566 | INTERNAL, |
| 7567 | { }, |
| 7568 | { { 0, -123 } } |
| 7569 | }, |
| 7570 | /* BPF_JMP32 | BPF_JNE | BPF_X */ |
| 7571 | { |
| 7572 | "JMP32_JNE_X", |
| 7573 | .u.insns_int = { |
| 7574 | BPF_ALU32_IMM(BPF_MOV, R0, 1234), |
| 7575 | BPF_ALU32_IMM(BPF_MOV, R1, 1234), |
| 7576 | BPF_JMP32_REG(BPF_JNE, R0, R1, 2), |
| 7577 | BPF_ALU32_IMM(BPF_MOV, R1, 4321), |
| 7578 | BPF_JMP32_REG(BPF_JNE, R0, R1, 1), |
| 7579 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7580 | BPF_EXIT_INSN(), |
| 7581 | }, |
| 7582 | INTERNAL, |
| 7583 | { }, |
| 7584 | { { 0, 1234 } } |
| 7585 | }, |
| 7586 | /* BPF_JMP32 | BPF_JSET | BPF_K */ |
| 7587 | { |
| 7588 | "JMP32_JSET_K: Small immediate", |
| 7589 | .u.insns_int = { |
| 7590 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 7591 | BPF_JMP32_IMM(BPF_JSET, R0, 2, 1), |
| 7592 | BPF_JMP32_IMM(BPF_JSET, R0, 3, 1), |
| 7593 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7594 | BPF_EXIT_INSN(), |
| 7595 | }, |
| 7596 | INTERNAL, |
| 7597 | { }, |
| 7598 | { { 0, 1 } } |
| 7599 | }, |
| 7600 | { |
| 7601 | "JMP32_JSET_K: Large immediate", |
| 7602 | .u.insns_int = { |
| 7603 | BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000), |
| 7604 | BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1), |
| 7605 | BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1), |
| 7606 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7607 | BPF_EXIT_INSN(), |
| 7608 | }, |
| 7609 | INTERNAL, |
| 7610 | { }, |
| 7611 | { { 0, 0x40000000 } } |
| 7612 | }, |
| 7613 | { |
| 7614 | "JMP32_JSET_K: negative immediate", |
| 7615 | .u.insns_int = { |
| 7616 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7617 | BPF_JMP32_IMM(BPF_JSET, R0, -1, 1), |
| 7618 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7619 | BPF_EXIT_INSN(), |
| 7620 | }, |
| 7621 | INTERNAL, |
| 7622 | { }, |
| 7623 | { { 0, -123 } } |
| 7624 | }, |
| 7625 | /* BPF_JMP32 | BPF_JSET | BPF_X */ |
| 7626 | { |
| 7627 | "JMP32_JSET_X", |
| 7628 | .u.insns_int = { |
| 7629 | BPF_ALU32_IMM(BPF_MOV, R0, 8), |
| 7630 | BPF_ALU32_IMM(BPF_MOV, R1, 7), |
| 7631 | BPF_JMP32_REG(BPF_JSET, R0, R1, 2), |
| 7632 | BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2), |
| 7633 | BPF_JMP32_REG(BPF_JNE, R0, R1, 1), |
| 7634 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7635 | BPF_EXIT_INSN(), |
| 7636 | }, |
| 7637 | INTERNAL, |
| 7638 | { }, |
| 7639 | { { 0, 8 } } |
| 7640 | }, |
| 7641 | /* BPF_JMP32 | BPF_JGT | BPF_K */ |
| 7642 | { |
| 7643 | "JMP32_JGT_K: Small immediate", |
| 7644 | .u.insns_int = { |
| 7645 | BPF_ALU32_IMM(BPF_MOV, R0, 123), |
| 7646 | BPF_JMP32_IMM(BPF_JGT, R0, 123, 1), |
| 7647 | BPF_JMP32_IMM(BPF_JGT, R0, 122, 1), |
| 7648 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7649 | BPF_EXIT_INSN(), |
| 7650 | }, |
| 7651 | INTERNAL, |
| 7652 | { }, |
| 7653 | { { 0, 123 } } |
| 7654 | }, |
| 7655 | { |
| 7656 | "JMP32_JGT_K: Large immediate", |
| 7657 | .u.insns_int = { |
| 7658 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7659 | BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1), |
| 7660 | BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1), |
| 7661 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7662 | BPF_EXIT_INSN(), |
| 7663 | }, |
| 7664 | INTERNAL, |
| 7665 | { }, |
| 7666 | { { 0, 0xfffffffe } } |
| 7667 | }, |
| 7668 | /* BPF_JMP32 | BPF_JGT | BPF_X */ |
| 7669 | { |
| 7670 | "JMP32_JGT_X", |
| 7671 | .u.insns_int = { |
| 7672 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7673 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 7674 | BPF_JMP32_REG(BPF_JGT, R0, R1, 2), |
| 7675 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd), |
| 7676 | BPF_JMP32_REG(BPF_JGT, R0, R1, 1), |
| 7677 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7678 | BPF_EXIT_INSN(), |
| 7679 | }, |
| 7680 | INTERNAL, |
| 7681 | { }, |
| 7682 | { { 0, 0xfffffffe } } |
| 7683 | }, |
| 7684 | /* BPF_JMP32 | BPF_JGE | BPF_K */ |
| 7685 | { |
| 7686 | "JMP32_JGE_K: Small immediate", |
| 7687 | .u.insns_int = { |
| 7688 | BPF_ALU32_IMM(BPF_MOV, R0, 123), |
| 7689 | BPF_JMP32_IMM(BPF_JGE, R0, 124, 1), |
| 7690 | BPF_JMP32_IMM(BPF_JGE, R0, 123, 1), |
| 7691 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7692 | BPF_EXIT_INSN(), |
| 7693 | }, |
| 7694 | INTERNAL, |
| 7695 | { }, |
| 7696 | { { 0, 123 } } |
| 7697 | }, |
| 7698 | { |
| 7699 | "JMP32_JGE_K: Large immediate", |
| 7700 | .u.insns_int = { |
| 7701 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7702 | BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1), |
| 7703 | BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1), |
| 7704 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7705 | BPF_EXIT_INSN(), |
| 7706 | }, |
| 7707 | INTERNAL, |
| 7708 | { }, |
| 7709 | { { 0, 0xfffffffe } } |
| 7710 | }, |
| 7711 | /* BPF_JMP32 | BPF_JGE | BPF_X */ |
| 7712 | { |
| 7713 | "JMP32_JGE_X", |
| 7714 | .u.insns_int = { |
| 7715 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7716 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 7717 | BPF_JMP32_REG(BPF_JGE, R0, R1, 2), |
| 7718 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe), |
| 7719 | BPF_JMP32_REG(BPF_JGE, R0, R1, 1), |
| 7720 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7721 | BPF_EXIT_INSN(), |
| 7722 | }, |
| 7723 | INTERNAL, |
| 7724 | { }, |
| 7725 | { { 0, 0xfffffffe } } |
| 7726 | }, |
| 7727 | /* BPF_JMP32 | BPF_JLT | BPF_K */ |
| 7728 | { |
| 7729 | "JMP32_JLT_K: Small immediate", |
| 7730 | .u.insns_int = { |
| 7731 | BPF_ALU32_IMM(BPF_MOV, R0, 123), |
| 7732 | BPF_JMP32_IMM(BPF_JLT, R0, 123, 1), |
| 7733 | BPF_JMP32_IMM(BPF_JLT, R0, 124, 1), |
| 7734 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7735 | BPF_EXIT_INSN(), |
| 7736 | }, |
| 7737 | INTERNAL, |
| 7738 | { }, |
| 7739 | { { 0, 123 } } |
| 7740 | }, |
| 7741 | { |
| 7742 | "JMP32_JLT_K: Large immediate", |
| 7743 | .u.insns_int = { |
| 7744 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7745 | BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1), |
| 7746 | BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1), |
| 7747 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7748 | BPF_EXIT_INSN(), |
| 7749 | }, |
| 7750 | INTERNAL, |
| 7751 | { }, |
| 7752 | { { 0, 0xfffffffe } } |
| 7753 | }, |
| 7754 | /* BPF_JMP32 | BPF_JLT | BPF_X */ |
| 7755 | { |
| 7756 | "JMP32_JLT_X", |
| 7757 | .u.insns_int = { |
| 7758 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7759 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd), |
| 7760 | BPF_JMP32_REG(BPF_JLT, R0, R1, 2), |
| 7761 | BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), |
| 7762 | BPF_JMP32_REG(BPF_JLT, R0, R1, 1), |
| 7763 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7764 | BPF_EXIT_INSN(), |
| 7765 | }, |
| 7766 | INTERNAL, |
| 7767 | { }, |
| 7768 | { { 0, 0xfffffffe } } |
| 7769 | }, |
| 7770 | /* BPF_JMP32 | BPF_JLE | BPF_K */ |
| 7771 | { |
| 7772 | "JMP32_JLE_K: Small immediate", |
| 7773 | .u.insns_int = { |
| 7774 | BPF_ALU32_IMM(BPF_MOV, R0, 123), |
| 7775 | BPF_JMP32_IMM(BPF_JLE, R0, 122, 1), |
| 7776 | BPF_JMP32_IMM(BPF_JLE, R0, 123, 1), |
| 7777 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7778 | BPF_EXIT_INSN(), |
| 7779 | }, |
| 7780 | INTERNAL, |
| 7781 | { }, |
| 7782 | { { 0, 123 } } |
| 7783 | }, |
| 7784 | { |
| 7785 | "JMP32_JLE_K: Large immediate", |
| 7786 | .u.insns_int = { |
| 7787 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7788 | BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1), |
| 7789 | BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1), |
| 7790 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7791 | BPF_EXIT_INSN(), |
| 7792 | }, |
| 7793 | INTERNAL, |
| 7794 | { }, |
| 7795 | { { 0, 0xfffffffe } } |
| 7796 | }, |
| 7797 | /* BPF_JMP32 | BPF_JLE | BPF_X */ |
| 7798 | { |
| 7799 | "JMP32_JLE_X", |
| 7800 | .u.insns_int = { |
| 7801 | BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe), |
| 7802 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd), |
| 7803 | BPF_JMP32_REG(BPF_JLE, R0, R1, 2), |
| 7804 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe), |
| 7805 | BPF_JMP32_REG(BPF_JLE, R0, R1, 1), |
| 7806 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7807 | BPF_EXIT_INSN(), |
| 7808 | }, |
| 7809 | INTERNAL, |
| 7810 | { }, |
| 7811 | { { 0, 0xfffffffe } } |
| 7812 | }, |
| 7813 | /* BPF_JMP32 | BPF_JSGT | BPF_K */ |
| 7814 | { |
| 7815 | "JMP32_JSGT_K: Small immediate", |
| 7816 | .u.insns_int = { |
| 7817 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7818 | BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1), |
| 7819 | BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1), |
| 7820 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7821 | BPF_EXIT_INSN(), |
| 7822 | }, |
| 7823 | INTERNAL, |
| 7824 | { }, |
| 7825 | { { 0, -123 } } |
| 7826 | }, |
| 7827 | { |
| 7828 | "JMP32_JSGT_K: Large immediate", |
| 7829 | .u.insns_int = { |
| 7830 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7831 | BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1), |
| 7832 | BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1), |
| 7833 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7834 | BPF_EXIT_INSN(), |
| 7835 | }, |
| 7836 | INTERNAL, |
| 7837 | { }, |
| 7838 | { { 0, -12345678 } } |
| 7839 | }, |
| 7840 | /* BPF_JMP32 | BPF_JSGT | BPF_X */ |
| 7841 | { |
| 7842 | "JMP32_JSGT_X", |
| 7843 | .u.insns_int = { |
| 7844 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7845 | BPF_ALU32_IMM(BPF_MOV, R1, -12345678), |
| 7846 | BPF_JMP32_REG(BPF_JSGT, R0, R1, 2), |
| 7847 | BPF_ALU32_IMM(BPF_MOV, R1, -12345679), |
| 7848 | BPF_JMP32_REG(BPF_JSGT, R0, R1, 1), |
| 7849 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7850 | BPF_EXIT_INSN(), |
| 7851 | }, |
| 7852 | INTERNAL, |
| 7853 | { }, |
| 7854 | { { 0, -12345678 } } |
| 7855 | }, |
| 7856 | /* BPF_JMP32 | BPF_JSGE | BPF_K */ |
| 7857 | { |
| 7858 | "JMP32_JSGE_K: Small immediate", |
| 7859 | .u.insns_int = { |
| 7860 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7861 | BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1), |
| 7862 | BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1), |
| 7863 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7864 | BPF_EXIT_INSN(), |
| 7865 | }, |
| 7866 | INTERNAL, |
| 7867 | { }, |
| 7868 | { { 0, -123 } } |
| 7869 | }, |
| 7870 | { |
| 7871 | "JMP32_JSGE_K: Large immediate", |
| 7872 | .u.insns_int = { |
| 7873 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7874 | BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1), |
| 7875 | BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1), |
| 7876 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7877 | BPF_EXIT_INSN(), |
| 7878 | }, |
| 7879 | INTERNAL, |
| 7880 | { }, |
| 7881 | { { 0, -12345678 } } |
| 7882 | }, |
| 7883 | /* BPF_JMP32 | BPF_JSGE | BPF_X */ |
| 7884 | { |
| 7885 | "JMP32_JSGE_X", |
| 7886 | .u.insns_int = { |
| 7887 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7888 | BPF_ALU32_IMM(BPF_MOV, R1, -12345677), |
| 7889 | BPF_JMP32_REG(BPF_JSGE, R0, R1, 2), |
| 7890 | BPF_ALU32_IMM(BPF_MOV, R1, -12345678), |
| 7891 | BPF_JMP32_REG(BPF_JSGE, R0, R1, 1), |
| 7892 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7893 | BPF_EXIT_INSN(), |
| 7894 | }, |
| 7895 | INTERNAL, |
| 7896 | { }, |
| 7897 | { { 0, -12345678 } } |
| 7898 | }, |
| 7899 | /* BPF_JMP32 | BPF_JSLT | BPF_K */ |
| 7900 | { |
| 7901 | "JMP32_JSLT_K: Small immediate", |
| 7902 | .u.insns_int = { |
| 7903 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7904 | BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1), |
| 7905 | BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1), |
| 7906 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7907 | BPF_EXIT_INSN(), |
| 7908 | }, |
| 7909 | INTERNAL, |
| 7910 | { }, |
| 7911 | { { 0, -123 } } |
| 7912 | }, |
| 7913 | { |
| 7914 | "JMP32_JSLT_K: Large immediate", |
| 7915 | .u.insns_int = { |
| 7916 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7917 | BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1), |
| 7918 | BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1), |
| 7919 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7920 | BPF_EXIT_INSN(), |
| 7921 | }, |
| 7922 | INTERNAL, |
| 7923 | { }, |
| 7924 | { { 0, -12345678 } } |
| 7925 | }, |
| 7926 | /* BPF_JMP32 | BPF_JSLT | BPF_X */ |
| 7927 | { |
| 7928 | "JMP32_JSLT_X", |
| 7929 | .u.insns_int = { |
| 7930 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7931 | BPF_ALU32_IMM(BPF_MOV, R1, -12345678), |
| 7932 | BPF_JMP32_REG(BPF_JSLT, R0, R1, 2), |
| 7933 | BPF_ALU32_IMM(BPF_MOV, R1, -12345677), |
| 7934 | BPF_JMP32_REG(BPF_JSLT, R0, R1, 1), |
| 7935 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7936 | BPF_EXIT_INSN(), |
| 7937 | }, |
| 7938 | INTERNAL, |
| 7939 | { }, |
| 7940 | { { 0, -12345678 } } |
| 7941 | }, |
| 7942 | /* BPF_JMP32 | BPF_JSLE | BPF_K */ |
| 7943 | { |
| 7944 | "JMP32_JSLE_K: Small immediate", |
| 7945 | .u.insns_int = { |
| 7946 | BPF_ALU32_IMM(BPF_MOV, R0, -123), |
| 7947 | BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1), |
| 7948 | BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1), |
| 7949 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7950 | BPF_EXIT_INSN(), |
| 7951 | }, |
| 7952 | INTERNAL, |
| 7953 | { }, |
| 7954 | { { 0, -123 } } |
| 7955 | }, |
| 7956 | { |
| 7957 | "JMP32_JSLE_K: Large immediate", |
| 7958 | .u.insns_int = { |
| 7959 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7960 | BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1), |
| 7961 | BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1), |
| 7962 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7963 | BPF_EXIT_INSN(), |
| 7964 | }, |
| 7965 | INTERNAL, |
| 7966 | { }, |
| 7967 | { { 0, -12345678 } } |
| 7968 | }, |
| 7969 | /* BPF_JMP32 | BPF_JSLE | BPF_K */ |
| 7970 | { |
| 7971 | "JMP32_JSLE_X", |
| 7972 | .u.insns_int = { |
| 7973 | BPF_ALU32_IMM(BPF_MOV, R0, -12345678), |
| 7974 | BPF_ALU32_IMM(BPF_MOV, R1, -12345679), |
| 7975 | BPF_JMP32_REG(BPF_JSLE, R0, R1, 2), |
| 7976 | BPF_ALU32_IMM(BPF_MOV, R1, -12345678), |
| 7977 | BPF_JMP32_REG(BPF_JSLE, R0, R1, 1), |
| 7978 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 7979 | BPF_EXIT_INSN(), |
| 7980 | }, |
| 7981 | INTERNAL, |
| 7982 | { }, |
| 7983 | { { 0, -12345678 } } |
| 7984 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 7985 | /* BPF_JMP | BPF_EXIT */ |
| 7986 | { |
| 7987 | "JMP_EXIT", |
| 7988 | .u.insns_int = { |
| 7989 | BPF_ALU32_IMM(BPF_MOV, R0, 0x4711), |
| 7990 | BPF_EXIT_INSN(), |
| 7991 | BPF_ALU32_IMM(BPF_MOV, R0, 0x4712), |
| 7992 | }, |
| 7993 | INTERNAL, |
| 7994 | { }, |
| 7995 | { { 0, 0x4711 } }, |
| 7996 | }, |
| 7997 | /* BPF_JMP | BPF_JA */ |
| 7998 | { |
| 7999 | "JMP_JA: Unconditional jump: if (true) return 1", |
| 8000 | .u.insns_int = { |
| 8001 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8002 | BPF_JMP_IMM(BPF_JA, 0, 0, 1), |
| 8003 | BPF_EXIT_INSN(), |
| 8004 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8005 | BPF_EXIT_INSN(), |
| 8006 | }, |
| 8007 | INTERNAL, |
| 8008 | { }, |
| 8009 | { { 0, 1 } }, |
| 8010 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8011 | /* BPF_JMP | BPF_JSLT | BPF_K */ |
| 8012 | { |
| 8013 | "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1", |
| 8014 | .u.insns_int = { |
| 8015 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8016 | BPF_LD_IMM64(R1, 0xfffffffffffffffeLL), |
| 8017 | BPF_JMP_IMM(BPF_JSLT, R1, -1, 1), |
| 8018 | BPF_EXIT_INSN(), |
| 8019 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8020 | BPF_EXIT_INSN(), |
| 8021 | }, |
| 8022 | INTERNAL, |
| 8023 | { }, |
| 8024 | { { 0, 1 } }, |
| 8025 | }, |
| 8026 | { |
| 8027 | "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0", |
| 8028 | .u.insns_int = { |
| 8029 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8030 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
| 8031 | BPF_JMP_IMM(BPF_JSLT, R1, -1, 1), |
| 8032 | BPF_EXIT_INSN(), |
| 8033 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8034 | BPF_EXIT_INSN(), |
| 8035 | }, |
| 8036 | INTERNAL, |
| 8037 | { }, |
| 8038 | { { 0, 1 } }, |
| 8039 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8040 | /* BPF_JMP | BPF_JSGT | BPF_K */ |
| 8041 | { |
| 8042 | "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1", |
| 8043 | .u.insns_int = { |
| 8044 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8045 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
| 8046 | BPF_JMP_IMM(BPF_JSGT, R1, -2, 1), |
| 8047 | BPF_EXIT_INSN(), |
| 8048 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8049 | BPF_EXIT_INSN(), |
| 8050 | }, |
| 8051 | INTERNAL, |
| 8052 | { }, |
| 8053 | { { 0, 1 } }, |
| 8054 | }, |
| 8055 | { |
| 8056 | "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0", |
| 8057 | .u.insns_int = { |
| 8058 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8059 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
| 8060 | BPF_JMP_IMM(BPF_JSGT, R1, -1, 1), |
| 8061 | BPF_EXIT_INSN(), |
| 8062 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8063 | BPF_EXIT_INSN(), |
| 8064 | }, |
| 8065 | INTERNAL, |
| 8066 | { }, |
| 8067 | { { 0, 1 } }, |
| 8068 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8069 | /* BPF_JMP | BPF_JSLE | BPF_K */ |
| 8070 | { |
| 8071 | "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1", |
| 8072 | .u.insns_int = { |
| 8073 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8074 | BPF_LD_IMM64(R1, 0xfffffffffffffffeLL), |
| 8075 | BPF_JMP_IMM(BPF_JSLE, R1, -1, 1), |
| 8076 | BPF_EXIT_INSN(), |
| 8077 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8078 | BPF_EXIT_INSN(), |
| 8079 | }, |
| 8080 | INTERNAL, |
| 8081 | { }, |
| 8082 | { { 0, 1 } }, |
| 8083 | }, |
| 8084 | { |
| 8085 | "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1", |
| 8086 | .u.insns_int = { |
| 8087 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8088 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
| 8089 | BPF_JMP_IMM(BPF_JSLE, R1, -1, 1), |
| 8090 | BPF_EXIT_INSN(), |
| 8091 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8092 | BPF_EXIT_INSN(), |
| 8093 | }, |
| 8094 | INTERNAL, |
| 8095 | { }, |
| 8096 | { { 0, 1 } }, |
| 8097 | }, |
| 8098 | { |
| 8099 | "JMP_JSLE_K: Signed jump: value walk 1", |
| 8100 | .u.insns_int = { |
| 8101 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8102 | BPF_LD_IMM64(R1, 3), |
| 8103 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 6), |
| 8104 | BPF_ALU64_IMM(BPF_SUB, R1, 1), |
| 8105 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 4), |
| 8106 | BPF_ALU64_IMM(BPF_SUB, R1, 1), |
| 8107 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 2), |
| 8108 | BPF_ALU64_IMM(BPF_SUB, R1, 1), |
| 8109 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 1), |
| 8110 | BPF_EXIT_INSN(), /* bad exit */ |
| 8111 | BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */ |
| 8112 | BPF_EXIT_INSN(), |
| 8113 | }, |
| 8114 | INTERNAL, |
| 8115 | { }, |
| 8116 | { { 0, 1 } }, |
| 8117 | }, |
| 8118 | { |
| 8119 | "JMP_JSLE_K: Signed jump: value walk 2", |
| 8120 | .u.insns_int = { |
| 8121 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8122 | BPF_LD_IMM64(R1, 3), |
| 8123 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 4), |
| 8124 | BPF_ALU64_IMM(BPF_SUB, R1, 2), |
| 8125 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 2), |
| 8126 | BPF_ALU64_IMM(BPF_SUB, R1, 2), |
| 8127 | BPF_JMP_IMM(BPF_JSLE, R1, 0, 1), |
| 8128 | BPF_EXIT_INSN(), /* bad exit */ |
| 8129 | BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */ |
| 8130 | BPF_EXIT_INSN(), |
| 8131 | }, |
| 8132 | INTERNAL, |
| 8133 | { }, |
| 8134 | { { 0, 1 } }, |
| 8135 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8136 | /* BPF_JMP | BPF_JSGE | BPF_K */ |
| 8137 | { |
| 8138 | "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1", |
| 8139 | .u.insns_int = { |
| 8140 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8141 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
| 8142 | BPF_JMP_IMM(BPF_JSGE, R1, -2, 1), |
| 8143 | BPF_EXIT_INSN(), |
| 8144 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8145 | BPF_EXIT_INSN(), |
| 8146 | }, |
| 8147 | INTERNAL, |
| 8148 | { }, |
| 8149 | { { 0, 1 } }, |
| 8150 | }, |
| 8151 | { |
| 8152 | "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1", |
| 8153 | .u.insns_int = { |
| 8154 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8155 | BPF_LD_IMM64(R1, 0xffffffffffffffffLL), |
| 8156 | BPF_JMP_IMM(BPF_JSGE, R1, -1, 1), |
| 8157 | BPF_EXIT_INSN(), |
| 8158 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8159 | BPF_EXIT_INSN(), |
| 8160 | }, |
| 8161 | INTERNAL, |
| 8162 | { }, |
| 8163 | { { 0, 1 } }, |
| 8164 | }, |
David Daney | 791caeb | 2017-05-24 16:35:49 -0700 | [diff] [blame] | 8165 | { |
| 8166 | "JMP_JSGE_K: Signed jump: value walk 1", |
| 8167 | .u.insns_int = { |
| 8168 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8169 | BPF_LD_IMM64(R1, -3), |
| 8170 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 6), |
| 8171 | BPF_ALU64_IMM(BPF_ADD, R1, 1), |
| 8172 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 4), |
| 8173 | BPF_ALU64_IMM(BPF_ADD, R1, 1), |
| 8174 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 2), |
| 8175 | BPF_ALU64_IMM(BPF_ADD, R1, 1), |
| 8176 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 1), |
| 8177 | BPF_EXIT_INSN(), /* bad exit */ |
| 8178 | BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */ |
| 8179 | BPF_EXIT_INSN(), |
| 8180 | }, |
| 8181 | INTERNAL, |
| 8182 | { }, |
| 8183 | { { 0, 1 } }, |
| 8184 | }, |
| 8185 | { |
| 8186 | "JMP_JSGE_K: Signed jump: value walk 2", |
| 8187 | .u.insns_int = { |
| 8188 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8189 | BPF_LD_IMM64(R1, -3), |
| 8190 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 4), |
| 8191 | BPF_ALU64_IMM(BPF_ADD, R1, 2), |
| 8192 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 2), |
| 8193 | BPF_ALU64_IMM(BPF_ADD, R1, 2), |
| 8194 | BPF_JMP_IMM(BPF_JSGE, R1, 0, 1), |
| 8195 | BPF_EXIT_INSN(), /* bad exit */ |
| 8196 | BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */ |
| 8197 | BPF_EXIT_INSN(), |
| 8198 | }, |
| 8199 | INTERNAL, |
| 8200 | { }, |
| 8201 | { { 0, 1 } }, |
| 8202 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8203 | /* BPF_JMP | BPF_JGT | BPF_K */ |
| 8204 | { |
| 8205 | "JMP_JGT_K: if (3 > 2) return 1", |
| 8206 | .u.insns_int = { |
| 8207 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8208 | BPF_LD_IMM64(R1, 3), |
| 8209 | BPF_JMP_IMM(BPF_JGT, R1, 2, 1), |
| 8210 | BPF_EXIT_INSN(), |
| 8211 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8212 | BPF_EXIT_INSN(), |
| 8213 | }, |
| 8214 | INTERNAL, |
| 8215 | { }, |
| 8216 | { { 0, 1 } }, |
| 8217 | }, |
Naveen N. Rao | c7395d6 | 2016-04-05 15:32:54 +0530 | [diff] [blame] | 8218 | { |
| 8219 | "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1", |
| 8220 | .u.insns_int = { |
| 8221 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8222 | BPF_LD_IMM64(R1, -1), |
| 8223 | BPF_JMP_IMM(BPF_JGT, R1, 1, 1), |
| 8224 | BPF_EXIT_INSN(), |
| 8225 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8226 | BPF_EXIT_INSN(), |
| 8227 | }, |
| 8228 | INTERNAL, |
| 8229 | { }, |
| 8230 | { { 0, 1 } }, |
| 8231 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8232 | /* BPF_JMP | BPF_JLT | BPF_K */ |
| 8233 | { |
| 8234 | "JMP_JLT_K: if (2 < 3) return 1", |
| 8235 | .u.insns_int = { |
| 8236 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8237 | BPF_LD_IMM64(R1, 2), |
| 8238 | BPF_JMP_IMM(BPF_JLT, R1, 3, 1), |
| 8239 | BPF_EXIT_INSN(), |
| 8240 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8241 | BPF_EXIT_INSN(), |
| 8242 | }, |
| 8243 | INTERNAL, |
| 8244 | { }, |
| 8245 | { { 0, 1 } }, |
| 8246 | }, |
| 8247 | { |
| 8248 | "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1", |
| 8249 | .u.insns_int = { |
| 8250 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8251 | BPF_LD_IMM64(R1, 1), |
| 8252 | BPF_JMP_IMM(BPF_JLT, R1, -1, 1), |
| 8253 | BPF_EXIT_INSN(), |
| 8254 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8255 | BPF_EXIT_INSN(), |
| 8256 | }, |
| 8257 | INTERNAL, |
| 8258 | { }, |
| 8259 | { { 0, 1 } }, |
| 8260 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8261 | /* BPF_JMP | BPF_JGE | BPF_K */ |
| 8262 | { |
| 8263 | "JMP_JGE_K: if (3 >= 2) return 1", |
| 8264 | .u.insns_int = { |
| 8265 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8266 | BPF_LD_IMM64(R1, 3), |
| 8267 | BPF_JMP_IMM(BPF_JGE, R1, 2, 1), |
| 8268 | BPF_EXIT_INSN(), |
| 8269 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8270 | BPF_EXIT_INSN(), |
| 8271 | }, |
| 8272 | INTERNAL, |
| 8273 | { }, |
| 8274 | { { 0, 1 } }, |
| 8275 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8276 | /* BPF_JMP | BPF_JLE | BPF_K */ |
| 8277 | { |
| 8278 | "JMP_JLE_K: if (2 <= 3) return 1", |
| 8279 | .u.insns_int = { |
| 8280 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8281 | BPF_LD_IMM64(R1, 2), |
| 8282 | BPF_JMP_IMM(BPF_JLE, R1, 3, 1), |
| 8283 | BPF_EXIT_INSN(), |
| 8284 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8285 | BPF_EXIT_INSN(), |
| 8286 | }, |
| 8287 | INTERNAL, |
| 8288 | { }, |
| 8289 | { { 0, 1 } }, |
| 8290 | }, |
Michael Holzheu | fe59384 | 2015-05-22 08:36:40 -0700 | [diff] [blame] | 8291 | /* BPF_JMP | BPF_JGT | BPF_K jump backwards */ |
| 8292 | { |
| 8293 | "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)", |
| 8294 | .u.insns_int = { |
| 8295 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */ |
| 8296 | BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */ |
| 8297 | BPF_EXIT_INSN(), |
| 8298 | BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */ |
| 8299 | BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */ |
| 8300 | BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */ |
| 8301 | BPF_EXIT_INSN(), |
| 8302 | }, |
| 8303 | INTERNAL, |
| 8304 | { }, |
| 8305 | { { 0, 1 } }, |
| 8306 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8307 | { |
| 8308 | "JMP_JGE_K: if (3 >= 3) return 1", |
| 8309 | .u.insns_int = { |
| 8310 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8311 | BPF_LD_IMM64(R1, 3), |
| 8312 | BPF_JMP_IMM(BPF_JGE, R1, 3, 1), |
| 8313 | BPF_EXIT_INSN(), |
| 8314 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8315 | BPF_EXIT_INSN(), |
| 8316 | }, |
| 8317 | INTERNAL, |
| 8318 | { }, |
| 8319 | { { 0, 1 } }, |
| 8320 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8321 | /* BPF_JMP | BPF_JLT | BPF_K jump backwards */ |
| 8322 | { |
| 8323 | "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)", |
| 8324 | .u.insns_int = { |
| 8325 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */ |
| 8326 | BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */ |
| 8327 | BPF_EXIT_INSN(), |
| 8328 | BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */ |
| 8329 | BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */ |
| 8330 | BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */ |
| 8331 | BPF_EXIT_INSN(), |
| 8332 | }, |
| 8333 | INTERNAL, |
| 8334 | { }, |
| 8335 | { { 0, 1 } }, |
| 8336 | }, |
| 8337 | { |
| 8338 | "JMP_JLE_K: if (3 <= 3) return 1", |
| 8339 | .u.insns_int = { |
| 8340 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8341 | BPF_LD_IMM64(R1, 3), |
| 8342 | BPF_JMP_IMM(BPF_JLE, R1, 3, 1), |
| 8343 | BPF_EXIT_INSN(), |
| 8344 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8345 | BPF_EXIT_INSN(), |
| 8346 | }, |
| 8347 | INTERNAL, |
| 8348 | { }, |
| 8349 | { { 0, 1 } }, |
| 8350 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8351 | /* BPF_JMP | BPF_JNE | BPF_K */ |
| 8352 | { |
| 8353 | "JMP_JNE_K: if (3 != 2) return 1", |
| 8354 | .u.insns_int = { |
| 8355 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8356 | BPF_LD_IMM64(R1, 3), |
| 8357 | BPF_JMP_IMM(BPF_JNE, R1, 2, 1), |
| 8358 | BPF_EXIT_INSN(), |
| 8359 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8360 | BPF_EXIT_INSN(), |
| 8361 | }, |
| 8362 | INTERNAL, |
| 8363 | { }, |
| 8364 | { { 0, 1 } }, |
| 8365 | }, |
| 8366 | /* BPF_JMP | BPF_JEQ | BPF_K */ |
| 8367 | { |
| 8368 | "JMP_JEQ_K: if (3 == 3) return 1", |
| 8369 | .u.insns_int = { |
| 8370 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8371 | BPF_LD_IMM64(R1, 3), |
| 8372 | BPF_JMP_IMM(BPF_JEQ, R1, 3, 1), |
| 8373 | BPF_EXIT_INSN(), |
| 8374 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8375 | BPF_EXIT_INSN(), |
| 8376 | }, |
| 8377 | INTERNAL, |
| 8378 | { }, |
| 8379 | { { 0, 1 } }, |
| 8380 | }, |
| 8381 | /* BPF_JMP | BPF_JSET | BPF_K */ |
| 8382 | { |
| 8383 | "JMP_JSET_K: if (0x3 & 0x2) return 1", |
| 8384 | .u.insns_int = { |
| 8385 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8386 | BPF_LD_IMM64(R1, 3), |
Naveen N. Rao | 9f134c3 | 2016-04-05 15:32:53 +0530 | [diff] [blame] | 8387 | BPF_JMP_IMM(BPF_JSET, R1, 2, 1), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8388 | BPF_EXIT_INSN(), |
| 8389 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8390 | BPF_EXIT_INSN(), |
| 8391 | }, |
| 8392 | INTERNAL, |
| 8393 | { }, |
| 8394 | { { 0, 1 } }, |
| 8395 | }, |
| 8396 | { |
| 8397 | "JMP_JSET_K: if (0x3 & 0xffffffff) return 1", |
| 8398 | .u.insns_int = { |
| 8399 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8400 | BPF_LD_IMM64(R1, 3), |
Naveen N. Rao | 9f134c3 | 2016-04-05 15:32:53 +0530 | [diff] [blame] | 8401 | BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8402 | BPF_EXIT_INSN(), |
| 8403 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8404 | BPF_EXIT_INSN(), |
| 8405 | }, |
| 8406 | INTERNAL, |
| 8407 | { }, |
| 8408 | { { 0, 1 } }, |
| 8409 | }, |
| 8410 | /* BPF_JMP | BPF_JSGT | BPF_X */ |
| 8411 | { |
| 8412 | "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1", |
| 8413 | .u.insns_int = { |
| 8414 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8415 | BPF_LD_IMM64(R1, -1), |
| 8416 | BPF_LD_IMM64(R2, -2), |
| 8417 | BPF_JMP_REG(BPF_JSGT, R1, R2, 1), |
| 8418 | BPF_EXIT_INSN(), |
| 8419 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8420 | BPF_EXIT_INSN(), |
| 8421 | }, |
| 8422 | INTERNAL, |
| 8423 | { }, |
| 8424 | { { 0, 1 } }, |
| 8425 | }, |
| 8426 | { |
| 8427 | "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0", |
| 8428 | .u.insns_int = { |
| 8429 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8430 | BPF_LD_IMM64(R1, -1), |
| 8431 | BPF_LD_IMM64(R2, -1), |
| 8432 | BPF_JMP_REG(BPF_JSGT, R1, R2, 1), |
| 8433 | BPF_EXIT_INSN(), |
| 8434 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8435 | BPF_EXIT_INSN(), |
| 8436 | }, |
| 8437 | INTERNAL, |
| 8438 | { }, |
| 8439 | { { 0, 1 } }, |
| 8440 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8441 | /* BPF_JMP | BPF_JSLT | BPF_X */ |
| 8442 | { |
| 8443 | "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1", |
| 8444 | .u.insns_int = { |
| 8445 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8446 | BPF_LD_IMM64(R1, -1), |
| 8447 | BPF_LD_IMM64(R2, -2), |
| 8448 | BPF_JMP_REG(BPF_JSLT, R2, R1, 1), |
| 8449 | BPF_EXIT_INSN(), |
| 8450 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8451 | BPF_EXIT_INSN(), |
| 8452 | }, |
| 8453 | INTERNAL, |
| 8454 | { }, |
| 8455 | { { 0, 1 } }, |
| 8456 | }, |
| 8457 | { |
| 8458 | "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0", |
| 8459 | .u.insns_int = { |
| 8460 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8461 | BPF_LD_IMM64(R1, -1), |
| 8462 | BPF_LD_IMM64(R2, -1), |
| 8463 | BPF_JMP_REG(BPF_JSLT, R1, R2, 1), |
| 8464 | BPF_EXIT_INSN(), |
| 8465 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8466 | BPF_EXIT_INSN(), |
| 8467 | }, |
| 8468 | INTERNAL, |
| 8469 | { }, |
| 8470 | { { 0, 1 } }, |
| 8471 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8472 | /* BPF_JMP | BPF_JSGE | BPF_X */ |
| 8473 | { |
| 8474 | "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1", |
| 8475 | .u.insns_int = { |
| 8476 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8477 | BPF_LD_IMM64(R1, -1), |
| 8478 | BPF_LD_IMM64(R2, -2), |
| 8479 | BPF_JMP_REG(BPF_JSGE, R1, R2, 1), |
| 8480 | BPF_EXIT_INSN(), |
| 8481 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8482 | BPF_EXIT_INSN(), |
| 8483 | }, |
| 8484 | INTERNAL, |
| 8485 | { }, |
| 8486 | { { 0, 1 } }, |
| 8487 | }, |
| 8488 | { |
| 8489 | "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1", |
| 8490 | .u.insns_int = { |
| 8491 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8492 | BPF_LD_IMM64(R1, -1), |
| 8493 | BPF_LD_IMM64(R2, -1), |
| 8494 | BPF_JMP_REG(BPF_JSGE, R1, R2, 1), |
| 8495 | BPF_EXIT_INSN(), |
| 8496 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8497 | BPF_EXIT_INSN(), |
| 8498 | }, |
| 8499 | INTERNAL, |
| 8500 | { }, |
| 8501 | { { 0, 1 } }, |
| 8502 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8503 | /* BPF_JMP | BPF_JSLE | BPF_X */ |
| 8504 | { |
| 8505 | "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1", |
| 8506 | .u.insns_int = { |
| 8507 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8508 | BPF_LD_IMM64(R1, -1), |
| 8509 | BPF_LD_IMM64(R2, -2), |
| 8510 | BPF_JMP_REG(BPF_JSLE, R2, R1, 1), |
| 8511 | BPF_EXIT_INSN(), |
| 8512 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8513 | BPF_EXIT_INSN(), |
| 8514 | }, |
| 8515 | INTERNAL, |
| 8516 | { }, |
| 8517 | { { 0, 1 } }, |
| 8518 | }, |
| 8519 | { |
| 8520 | "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1", |
| 8521 | .u.insns_int = { |
| 8522 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8523 | BPF_LD_IMM64(R1, -1), |
| 8524 | BPF_LD_IMM64(R2, -1), |
| 8525 | BPF_JMP_REG(BPF_JSLE, R1, R2, 1), |
| 8526 | BPF_EXIT_INSN(), |
| 8527 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8528 | BPF_EXIT_INSN(), |
| 8529 | }, |
| 8530 | INTERNAL, |
| 8531 | { }, |
| 8532 | { { 0, 1 } }, |
| 8533 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8534 | /* BPF_JMP | BPF_JGT | BPF_X */ |
| 8535 | { |
| 8536 | "JMP_JGT_X: if (3 > 2) return 1", |
| 8537 | .u.insns_int = { |
| 8538 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8539 | BPF_LD_IMM64(R1, 3), |
| 8540 | BPF_LD_IMM64(R2, 2), |
| 8541 | BPF_JMP_REG(BPF_JGT, R1, R2, 1), |
| 8542 | BPF_EXIT_INSN(), |
| 8543 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8544 | BPF_EXIT_INSN(), |
| 8545 | }, |
| 8546 | INTERNAL, |
| 8547 | { }, |
| 8548 | { { 0, 1 } }, |
| 8549 | }, |
Naveen N. Rao | c7395d6 | 2016-04-05 15:32:54 +0530 | [diff] [blame] | 8550 | { |
| 8551 | "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1", |
| 8552 | .u.insns_int = { |
| 8553 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8554 | BPF_LD_IMM64(R1, -1), |
| 8555 | BPF_LD_IMM64(R2, 1), |
| 8556 | BPF_JMP_REG(BPF_JGT, R1, R2, 1), |
| 8557 | BPF_EXIT_INSN(), |
| 8558 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8559 | BPF_EXIT_INSN(), |
| 8560 | }, |
| 8561 | INTERNAL, |
| 8562 | { }, |
| 8563 | { { 0, 1 } }, |
| 8564 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8565 | /* BPF_JMP | BPF_JLT | BPF_X */ |
| 8566 | { |
| 8567 | "JMP_JLT_X: if (2 < 3) return 1", |
| 8568 | .u.insns_int = { |
| 8569 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8570 | BPF_LD_IMM64(R1, 3), |
| 8571 | BPF_LD_IMM64(R2, 2), |
| 8572 | BPF_JMP_REG(BPF_JLT, R2, R1, 1), |
| 8573 | BPF_EXIT_INSN(), |
| 8574 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8575 | BPF_EXIT_INSN(), |
| 8576 | }, |
| 8577 | INTERNAL, |
| 8578 | { }, |
| 8579 | { { 0, 1 } }, |
| 8580 | }, |
| 8581 | { |
| 8582 | "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1", |
| 8583 | .u.insns_int = { |
| 8584 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8585 | BPF_LD_IMM64(R1, -1), |
| 8586 | BPF_LD_IMM64(R2, 1), |
| 8587 | BPF_JMP_REG(BPF_JLT, R2, R1, 1), |
| 8588 | BPF_EXIT_INSN(), |
| 8589 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8590 | BPF_EXIT_INSN(), |
| 8591 | }, |
| 8592 | INTERNAL, |
| 8593 | { }, |
| 8594 | { { 0, 1 } }, |
| 8595 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8596 | /* BPF_JMP | BPF_JGE | BPF_X */ |
| 8597 | { |
| 8598 | "JMP_JGE_X: if (3 >= 2) return 1", |
| 8599 | .u.insns_int = { |
| 8600 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8601 | BPF_LD_IMM64(R1, 3), |
| 8602 | BPF_LD_IMM64(R2, 2), |
| 8603 | BPF_JMP_REG(BPF_JGE, R1, R2, 1), |
| 8604 | BPF_EXIT_INSN(), |
| 8605 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8606 | BPF_EXIT_INSN(), |
| 8607 | }, |
| 8608 | INTERNAL, |
| 8609 | { }, |
| 8610 | { { 0, 1 } }, |
| 8611 | }, |
| 8612 | { |
| 8613 | "JMP_JGE_X: if (3 >= 3) return 1", |
| 8614 | .u.insns_int = { |
| 8615 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8616 | BPF_LD_IMM64(R1, 3), |
| 8617 | BPF_LD_IMM64(R2, 3), |
| 8618 | BPF_JMP_REG(BPF_JGE, R1, R2, 1), |
| 8619 | BPF_EXIT_INSN(), |
| 8620 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8621 | BPF_EXIT_INSN(), |
| 8622 | }, |
| 8623 | INTERNAL, |
| 8624 | { }, |
| 8625 | { { 0, 1 } }, |
| 8626 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8627 | /* BPF_JMP | BPF_JLE | BPF_X */ |
| 8628 | { |
| 8629 | "JMP_JLE_X: if (2 <= 3) return 1", |
| 8630 | .u.insns_int = { |
| 8631 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8632 | BPF_LD_IMM64(R1, 3), |
| 8633 | BPF_LD_IMM64(R2, 2), |
| 8634 | BPF_JMP_REG(BPF_JLE, R2, R1, 1), |
| 8635 | BPF_EXIT_INSN(), |
| 8636 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8637 | BPF_EXIT_INSN(), |
| 8638 | }, |
| 8639 | INTERNAL, |
| 8640 | { }, |
| 8641 | { { 0, 1 } }, |
| 8642 | }, |
| 8643 | { |
| 8644 | "JMP_JLE_X: if (3 <= 3) return 1", |
| 8645 | .u.insns_int = { |
| 8646 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8647 | BPF_LD_IMM64(R1, 3), |
| 8648 | BPF_LD_IMM64(R2, 3), |
| 8649 | BPF_JMP_REG(BPF_JLE, R1, R2, 1), |
| 8650 | BPF_EXIT_INSN(), |
| 8651 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8652 | BPF_EXIT_INSN(), |
| 8653 | }, |
| 8654 | INTERNAL, |
| 8655 | { }, |
| 8656 | { { 0, 1 } }, |
| 8657 | }, |
Daniel Borkmann | ddc665a | 2017-05-02 20:34:54 +0200 | [diff] [blame] | 8658 | { |
| 8659 | /* Mainly testing JIT + imm64 here. */ |
| 8660 | "JMP_JGE_X: ldimm64 test 1", |
| 8661 | .u.insns_int = { |
| 8662 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8663 | BPF_LD_IMM64(R1, 3), |
| 8664 | BPF_LD_IMM64(R2, 2), |
| 8665 | BPF_JMP_REG(BPF_JGE, R1, R2, 2), |
Geert Uytterhoeven | 86f8e24 | 2017-05-03 13:31:04 +0200 | [diff] [blame] | 8666 | BPF_LD_IMM64(R0, 0xffffffffffffffffULL), |
| 8667 | BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL), |
Daniel Borkmann | ddc665a | 2017-05-02 20:34:54 +0200 | [diff] [blame] | 8668 | BPF_EXIT_INSN(), |
| 8669 | }, |
| 8670 | INTERNAL, |
| 8671 | { }, |
| 8672 | { { 0, 0xeeeeeeeeU } }, |
| 8673 | }, |
| 8674 | { |
| 8675 | "JMP_JGE_X: ldimm64 test 2", |
| 8676 | .u.insns_int = { |
| 8677 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8678 | BPF_LD_IMM64(R1, 3), |
| 8679 | BPF_LD_IMM64(R2, 2), |
| 8680 | BPF_JMP_REG(BPF_JGE, R1, R2, 0), |
Geert Uytterhoeven | 86f8e24 | 2017-05-03 13:31:04 +0200 | [diff] [blame] | 8681 | BPF_LD_IMM64(R0, 0xffffffffffffffffULL), |
Daniel Borkmann | ddc665a | 2017-05-02 20:34:54 +0200 | [diff] [blame] | 8682 | BPF_EXIT_INSN(), |
| 8683 | }, |
| 8684 | INTERNAL, |
| 8685 | { }, |
| 8686 | { { 0, 0xffffffffU } }, |
| 8687 | }, |
| 8688 | { |
| 8689 | "JMP_JGE_X: ldimm64 test 3", |
| 8690 | .u.insns_int = { |
| 8691 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8692 | BPF_LD_IMM64(R1, 3), |
| 8693 | BPF_LD_IMM64(R2, 2), |
| 8694 | BPF_JMP_REG(BPF_JGE, R1, R2, 4), |
Geert Uytterhoeven | 86f8e24 | 2017-05-03 13:31:04 +0200 | [diff] [blame] | 8695 | BPF_LD_IMM64(R0, 0xffffffffffffffffULL), |
| 8696 | BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL), |
Daniel Borkmann | ddc665a | 2017-05-02 20:34:54 +0200 | [diff] [blame] | 8697 | BPF_EXIT_INSN(), |
| 8698 | }, |
| 8699 | INTERNAL, |
| 8700 | { }, |
| 8701 | { { 0, 1 } }, |
| 8702 | }, |
Daniel Borkmann | 92b31a9 | 2017-08-10 01:39:55 +0200 | [diff] [blame] | 8703 | { |
| 8704 | "JMP_JLE_X: ldimm64 test 1", |
| 8705 | .u.insns_int = { |
| 8706 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8707 | BPF_LD_IMM64(R1, 3), |
| 8708 | BPF_LD_IMM64(R2, 2), |
| 8709 | BPF_JMP_REG(BPF_JLE, R2, R1, 2), |
| 8710 | BPF_LD_IMM64(R0, 0xffffffffffffffffULL), |
| 8711 | BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL), |
| 8712 | BPF_EXIT_INSN(), |
| 8713 | }, |
| 8714 | INTERNAL, |
| 8715 | { }, |
| 8716 | { { 0, 0xeeeeeeeeU } }, |
| 8717 | }, |
| 8718 | { |
| 8719 | "JMP_JLE_X: ldimm64 test 2", |
| 8720 | .u.insns_int = { |
| 8721 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8722 | BPF_LD_IMM64(R1, 3), |
| 8723 | BPF_LD_IMM64(R2, 2), |
| 8724 | BPF_JMP_REG(BPF_JLE, R2, R1, 0), |
| 8725 | BPF_LD_IMM64(R0, 0xffffffffffffffffULL), |
| 8726 | BPF_EXIT_INSN(), |
| 8727 | }, |
| 8728 | INTERNAL, |
| 8729 | { }, |
| 8730 | { { 0, 0xffffffffU } }, |
| 8731 | }, |
| 8732 | { |
| 8733 | "JMP_JLE_X: ldimm64 test 3", |
| 8734 | .u.insns_int = { |
| 8735 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8736 | BPF_LD_IMM64(R1, 3), |
| 8737 | BPF_LD_IMM64(R2, 2), |
| 8738 | BPF_JMP_REG(BPF_JLE, R2, R1, 4), |
| 8739 | BPF_LD_IMM64(R0, 0xffffffffffffffffULL), |
| 8740 | BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL), |
| 8741 | BPF_EXIT_INSN(), |
| 8742 | }, |
| 8743 | INTERNAL, |
| 8744 | { }, |
| 8745 | { { 0, 1 } }, |
| 8746 | }, |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8747 | /* BPF_JMP | BPF_JNE | BPF_X */ |
| 8748 | { |
| 8749 | "JMP_JNE_X: if (3 != 2) return 1", |
| 8750 | .u.insns_int = { |
| 8751 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8752 | BPF_LD_IMM64(R1, 3), |
| 8753 | BPF_LD_IMM64(R2, 2), |
| 8754 | BPF_JMP_REG(BPF_JNE, R1, R2, 1), |
| 8755 | BPF_EXIT_INSN(), |
| 8756 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8757 | BPF_EXIT_INSN(), |
| 8758 | }, |
| 8759 | INTERNAL, |
| 8760 | { }, |
| 8761 | { { 0, 1 } }, |
| 8762 | }, |
| 8763 | /* BPF_JMP | BPF_JEQ | BPF_X */ |
| 8764 | { |
| 8765 | "JMP_JEQ_X: if (3 == 3) return 1", |
| 8766 | .u.insns_int = { |
| 8767 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8768 | BPF_LD_IMM64(R1, 3), |
| 8769 | BPF_LD_IMM64(R2, 3), |
| 8770 | BPF_JMP_REG(BPF_JEQ, R1, R2, 1), |
| 8771 | BPF_EXIT_INSN(), |
| 8772 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8773 | BPF_EXIT_INSN(), |
| 8774 | }, |
| 8775 | INTERNAL, |
| 8776 | { }, |
| 8777 | { { 0, 1 } }, |
| 8778 | }, |
| 8779 | /* BPF_JMP | BPF_JSET | BPF_X */ |
| 8780 | { |
| 8781 | "JMP_JSET_X: if (0x3 & 0x2) return 1", |
| 8782 | .u.insns_int = { |
| 8783 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8784 | BPF_LD_IMM64(R1, 3), |
| 8785 | BPF_LD_IMM64(R2, 2), |
Naveen N. Rao | 9f134c3 | 2016-04-05 15:32:53 +0530 | [diff] [blame] | 8786 | BPF_JMP_REG(BPF_JSET, R1, R2, 1), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8787 | BPF_EXIT_INSN(), |
| 8788 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8789 | BPF_EXIT_INSN(), |
| 8790 | }, |
| 8791 | INTERNAL, |
| 8792 | { }, |
| 8793 | { { 0, 1 } }, |
| 8794 | }, |
| 8795 | { |
| 8796 | "JMP_JSET_X: if (0x3 & 0xffffffff) return 1", |
| 8797 | .u.insns_int = { |
| 8798 | BPF_ALU32_IMM(BPF_MOV, R0, 0), |
| 8799 | BPF_LD_IMM64(R1, 3), |
| 8800 | BPF_LD_IMM64(R2, 0xffffffff), |
Naveen N. Rao | 9f134c3 | 2016-04-05 15:32:53 +0530 | [diff] [blame] | 8801 | BPF_JMP_REG(BPF_JSET, R1, R2, 1), |
Michael Holzheu | cffc642 | 2015-05-11 22:22:44 -0700 | [diff] [blame] | 8802 | BPF_EXIT_INSN(), |
| 8803 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 8804 | BPF_EXIT_INSN(), |
| 8805 | }, |
| 8806 | INTERNAL, |
| 8807 | { }, |
| 8808 | { { 0, 1 } }, |
| 8809 | }, |
Daniel Borkmann | bde28bc | 2015-05-26 22:35:43 +0200 | [diff] [blame] | 8810 | { |
| 8811 | "JMP_JA: Jump, gap, jump, ...", |
| 8812 | { }, |
| 8813 | CLASSIC | FLAG_NO_DATA, |
| 8814 | { }, |
| 8815 | { { 0, 0xababcbac } }, |
| 8816 | .fill_helper = bpf_fill_ja, |
| 8817 | }, |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 8818 | { /* Mainly checking JIT here. */ |
| 8819 | "BPF_MAXINSNS: Maximum possible literals", |
| 8820 | { }, |
| 8821 | CLASSIC | FLAG_NO_DATA, |
| 8822 | { }, |
| 8823 | { { 0, 0xffffffff } }, |
| 8824 | .fill_helper = bpf_fill_maxinsns1, |
| 8825 | }, |
| 8826 | { /* Mainly checking JIT here. */ |
| 8827 | "BPF_MAXINSNS: Single literal", |
| 8828 | { }, |
| 8829 | CLASSIC | FLAG_NO_DATA, |
| 8830 | { }, |
| 8831 | { { 0, 0xfefefefe } }, |
| 8832 | .fill_helper = bpf_fill_maxinsns2, |
| 8833 | }, |
| 8834 | { /* Mainly checking JIT here. */ |
| 8835 | "BPF_MAXINSNS: Run/add until end", |
| 8836 | { }, |
| 8837 | CLASSIC | FLAG_NO_DATA, |
| 8838 | { }, |
| 8839 | { { 0, 0x947bf368 } }, |
| 8840 | .fill_helper = bpf_fill_maxinsns3, |
| 8841 | }, |
| 8842 | { |
| 8843 | "BPF_MAXINSNS: Too many instructions", |
| 8844 | { }, |
| 8845 | CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, |
| 8846 | { }, |
| 8847 | { }, |
| 8848 | .fill_helper = bpf_fill_maxinsns4, |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 8849 | .expected_errcode = -EINVAL, |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 8850 | }, |
| 8851 | { /* Mainly checking JIT here. */ |
| 8852 | "BPF_MAXINSNS: Very long jump", |
| 8853 | { }, |
| 8854 | CLASSIC | FLAG_NO_DATA, |
| 8855 | { }, |
| 8856 | { { 0, 0xabababab } }, |
| 8857 | .fill_helper = bpf_fill_maxinsns5, |
| 8858 | }, |
| 8859 | { /* Mainly checking JIT here. */ |
| 8860 | "BPF_MAXINSNS: Ctx heavy transformations", |
| 8861 | { }, |
| 8862 | CLASSIC, |
| 8863 | { }, |
| 8864 | { |
Michał Mirosław | 0c4b2d3 | 2018-11-10 19:58:36 +0100 | [diff] [blame] | 8865 | { 1, SKB_VLAN_PRESENT }, |
| 8866 | { 10, SKB_VLAN_PRESENT } |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 8867 | }, |
| 8868 | .fill_helper = bpf_fill_maxinsns6, |
| 8869 | }, |
| 8870 | { /* Mainly checking JIT here. */ |
| 8871 | "BPF_MAXINSNS: Call heavy transformations", |
| 8872 | { }, |
| 8873 | CLASSIC | FLAG_NO_DATA, |
| 8874 | { }, |
| 8875 | { { 1, 0 }, { 10, 0 } }, |
| 8876 | .fill_helper = bpf_fill_maxinsns7, |
| 8877 | }, |
| 8878 | { /* Mainly checking JIT here. */ |
| 8879 | "BPF_MAXINSNS: Jump heavy test", |
| 8880 | { }, |
| 8881 | CLASSIC | FLAG_NO_DATA, |
| 8882 | { }, |
| 8883 | { { 0, 0xffffffff } }, |
| 8884 | .fill_helper = bpf_fill_maxinsns8, |
| 8885 | }, |
Daniel Borkmann | 3b52960 | 2015-05-23 01:10:07 +0200 | [diff] [blame] | 8886 | { /* Mainly checking JIT here. */ |
| 8887 | "BPF_MAXINSNS: Very long jump backwards", |
| 8888 | { }, |
| 8889 | INTERNAL | FLAG_NO_DATA, |
| 8890 | { }, |
| 8891 | { { 0, 0xcbababab } }, |
| 8892 | .fill_helper = bpf_fill_maxinsns9, |
| 8893 | }, |
| 8894 | { /* Mainly checking JIT here. */ |
| 8895 | "BPF_MAXINSNS: Edge hopping nuthouse", |
| 8896 | { }, |
| 8897 | INTERNAL | FLAG_NO_DATA, |
| 8898 | { }, |
| 8899 | { { 0, 0xabababac } }, |
| 8900 | .fill_helper = bpf_fill_maxinsns10, |
| 8901 | }, |
Daniel Borkmann | bde28bc | 2015-05-26 22:35:43 +0200 | [diff] [blame] | 8902 | { |
| 8903 | "BPF_MAXINSNS: Jump, gap, jump, ...", |
| 8904 | { }, |
| 8905 | CLASSIC | FLAG_NO_DATA, |
| 8906 | { }, |
| 8907 | { { 0, 0xababcbac } }, |
| 8908 | .fill_helper = bpf_fill_maxinsns11, |
| 8909 | }, |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 8910 | { |
Daniel Borkmann | be08815 | 2018-06-02 23:06:32 +0200 | [diff] [blame] | 8911 | "BPF_MAXINSNS: jump over MSH", |
| 8912 | { }, |
| 8913 | CLASSIC | FLAG_EXPECTED_FAIL, |
| 8914 | { 0xfa, 0xfb, 0xfc, 0xfd, }, |
| 8915 | { { 4, 0xabababab } }, |
| 8916 | .fill_helper = bpf_fill_maxinsns12, |
| 8917 | .expected_errcode = -EINVAL, |
| 8918 | }, |
| 8919 | { |
| 8920 | "BPF_MAXINSNS: exec all MSH", |
| 8921 | { }, |
| 8922 | CLASSIC, |
| 8923 | { 0xfa, 0xfb, 0xfc, 0xfd, }, |
| 8924 | { { 4, 0xababab83 } }, |
| 8925 | .fill_helper = bpf_fill_maxinsns13, |
| 8926 | }, |
| 8927 | { |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 8928 | "BPF_MAXINSNS: ld_abs+get_processor_id", |
| 8929 | { }, |
| 8930 | CLASSIC, |
| 8931 | { }, |
| 8932 | { { 1, 0xbee } }, |
| 8933 | .fill_helper = bpf_fill_ld_abs_get_processor_id, |
| 8934 | }, |
Nicolas Schichan | 2cf1ad7 | 2015-08-04 15:19:09 +0200 | [diff] [blame] | 8935 | /* |
| 8936 | * LD_IND / LD_ABS on fragmented SKBs |
| 8937 | */ |
| 8938 | { |
| 8939 | "LD_IND byte frag", |
| 8940 | .u.insns = { |
| 8941 | BPF_STMT(BPF_LDX | BPF_IMM, 0x40), |
| 8942 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0), |
| 8943 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 8944 | }, |
| 8945 | CLASSIC | FLAG_SKB_FRAG, |
| 8946 | { }, |
| 8947 | { {0x40, 0x42} }, |
| 8948 | .frag_data = { |
| 8949 | 0x42, 0x00, 0x00, 0x00, |
| 8950 | 0x43, 0x44, 0x00, 0x00, |
| 8951 | 0x21, 0x07, 0x19, 0x83, |
| 8952 | }, |
| 8953 | }, |
| 8954 | { |
| 8955 | "LD_IND halfword frag", |
| 8956 | .u.insns = { |
| 8957 | BPF_STMT(BPF_LDX | BPF_IMM, 0x40), |
| 8958 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4), |
| 8959 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 8960 | }, |
| 8961 | CLASSIC | FLAG_SKB_FRAG, |
| 8962 | { }, |
| 8963 | { {0x40, 0x4344} }, |
| 8964 | .frag_data = { |
| 8965 | 0x42, 0x00, 0x00, 0x00, |
| 8966 | 0x43, 0x44, 0x00, 0x00, |
| 8967 | 0x21, 0x07, 0x19, 0x83, |
| 8968 | }, |
| 8969 | }, |
| 8970 | { |
| 8971 | "LD_IND word frag", |
| 8972 | .u.insns = { |
| 8973 | BPF_STMT(BPF_LDX | BPF_IMM, 0x40), |
| 8974 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8), |
| 8975 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 8976 | }, |
| 8977 | CLASSIC | FLAG_SKB_FRAG, |
| 8978 | { }, |
| 8979 | { {0x40, 0x21071983} }, |
| 8980 | .frag_data = { |
| 8981 | 0x42, 0x00, 0x00, 0x00, |
| 8982 | 0x43, 0x44, 0x00, 0x00, |
| 8983 | 0x21, 0x07, 0x19, 0x83, |
| 8984 | }, |
| 8985 | }, |
| 8986 | { |
| 8987 | "LD_IND halfword mixed head/frag", |
| 8988 | .u.insns = { |
| 8989 | BPF_STMT(BPF_LDX | BPF_IMM, 0x40), |
| 8990 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1), |
| 8991 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 8992 | }, |
| 8993 | CLASSIC | FLAG_SKB_FRAG, |
| 8994 | { [0x3e] = 0x25, [0x3f] = 0x05, }, |
| 8995 | { {0x40, 0x0519} }, |
| 8996 | .frag_data = { 0x19, 0x82 }, |
| 8997 | }, |
| 8998 | { |
| 8999 | "LD_IND word mixed head/frag", |
| 9000 | .u.insns = { |
| 9001 | BPF_STMT(BPF_LDX | BPF_IMM, 0x40), |
| 9002 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2), |
| 9003 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9004 | }, |
| 9005 | CLASSIC | FLAG_SKB_FRAG, |
| 9006 | { [0x3e] = 0x25, [0x3f] = 0x05, }, |
| 9007 | { {0x40, 0x25051982} }, |
| 9008 | .frag_data = { 0x19, 0x82 }, |
| 9009 | }, |
| 9010 | { |
| 9011 | "LD_ABS byte frag", |
| 9012 | .u.insns = { |
| 9013 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40), |
| 9014 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9015 | }, |
| 9016 | CLASSIC | FLAG_SKB_FRAG, |
| 9017 | { }, |
| 9018 | { {0x40, 0x42} }, |
| 9019 | .frag_data = { |
| 9020 | 0x42, 0x00, 0x00, 0x00, |
| 9021 | 0x43, 0x44, 0x00, 0x00, |
| 9022 | 0x21, 0x07, 0x19, 0x83, |
| 9023 | }, |
| 9024 | }, |
| 9025 | { |
| 9026 | "LD_ABS halfword frag", |
| 9027 | .u.insns = { |
| 9028 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44), |
| 9029 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9030 | }, |
| 9031 | CLASSIC | FLAG_SKB_FRAG, |
| 9032 | { }, |
| 9033 | { {0x40, 0x4344} }, |
| 9034 | .frag_data = { |
| 9035 | 0x42, 0x00, 0x00, 0x00, |
| 9036 | 0x43, 0x44, 0x00, 0x00, |
| 9037 | 0x21, 0x07, 0x19, 0x83, |
| 9038 | }, |
| 9039 | }, |
| 9040 | { |
| 9041 | "LD_ABS word frag", |
| 9042 | .u.insns = { |
| 9043 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48), |
| 9044 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9045 | }, |
| 9046 | CLASSIC | FLAG_SKB_FRAG, |
| 9047 | { }, |
| 9048 | { {0x40, 0x21071983} }, |
| 9049 | .frag_data = { |
| 9050 | 0x42, 0x00, 0x00, 0x00, |
| 9051 | 0x43, 0x44, 0x00, 0x00, |
| 9052 | 0x21, 0x07, 0x19, 0x83, |
| 9053 | }, |
| 9054 | }, |
| 9055 | { |
| 9056 | "LD_ABS halfword mixed head/frag", |
| 9057 | .u.insns = { |
| 9058 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f), |
| 9059 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9060 | }, |
| 9061 | CLASSIC | FLAG_SKB_FRAG, |
| 9062 | { [0x3e] = 0x25, [0x3f] = 0x05, }, |
| 9063 | { {0x40, 0x0519} }, |
| 9064 | .frag_data = { 0x19, 0x82 }, |
| 9065 | }, |
| 9066 | { |
| 9067 | "LD_ABS word mixed head/frag", |
| 9068 | .u.insns = { |
| 9069 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e), |
| 9070 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9071 | }, |
| 9072 | CLASSIC | FLAG_SKB_FRAG, |
| 9073 | { [0x3e] = 0x25, [0x3f] = 0x05, }, |
| 9074 | { {0x40, 0x25051982} }, |
| 9075 | .frag_data = { 0x19, 0x82 }, |
| 9076 | }, |
Nicolas Schichan | 08fcb08 | 2015-08-04 15:19:11 +0200 | [diff] [blame] | 9077 | /* |
| 9078 | * LD_IND / LD_ABS on non fragmented SKBs |
| 9079 | */ |
| 9080 | { |
| 9081 | /* |
| 9082 | * this tests that the JIT/interpreter correctly resets X |
| 9083 | * before using it in an LD_IND instruction. |
| 9084 | */ |
| 9085 | "LD_IND byte default X", |
| 9086 | .u.insns = { |
| 9087 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1), |
| 9088 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9089 | }, |
| 9090 | CLASSIC, |
| 9091 | { [0x1] = 0x42 }, |
| 9092 | { {0x40, 0x42 } }, |
| 9093 | }, |
| 9094 | { |
| 9095 | "LD_IND byte positive offset", |
| 9096 | .u.insns = { |
| 9097 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9098 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1), |
| 9099 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9100 | }, |
| 9101 | CLASSIC, |
| 9102 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9103 | { {0x40, 0x82 } }, |
| 9104 | }, |
| 9105 | { |
| 9106 | "LD_IND byte negative offset", |
| 9107 | .u.insns = { |
| 9108 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9109 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1), |
| 9110 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9111 | }, |
| 9112 | CLASSIC, |
| 9113 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9114 | { {0x40, 0x05 } }, |
| 9115 | }, |
| 9116 | { |
Daniel Borkmann | 93731ef | 2018-05-04 01:08:13 +0200 | [diff] [blame] | 9117 | "LD_IND byte positive offset, all ff", |
| 9118 | .u.insns = { |
| 9119 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9120 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1), |
| 9121 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9122 | }, |
| 9123 | CLASSIC, |
| 9124 | { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff }, |
| 9125 | { {0x40, 0xff } }, |
| 9126 | }, |
| 9127 | { |
| 9128 | "LD_IND byte positive offset, out of bounds", |
| 9129 | .u.insns = { |
| 9130 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9131 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1), |
| 9132 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9133 | }, |
| 9134 | CLASSIC, |
| 9135 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9136 | { {0x3f, 0 }, }, |
| 9137 | }, |
| 9138 | { |
| 9139 | "LD_IND byte negative offset, out of bounds", |
| 9140 | .u.insns = { |
| 9141 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9142 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f), |
| 9143 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9144 | }, |
| 9145 | CLASSIC, |
| 9146 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9147 | { {0x3f, 0 } }, |
| 9148 | }, |
| 9149 | { |
| 9150 | "LD_IND byte negative offset, multiple calls", |
| 9151 | .u.insns = { |
| 9152 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3b), |
| 9153 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1), |
| 9154 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2), |
| 9155 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3), |
| 9156 | BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4), |
| 9157 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9158 | }, |
| 9159 | CLASSIC, |
| 9160 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9161 | { {0x40, 0x82 }, }, |
| 9162 | }, |
| 9163 | { |
Nicolas Schichan | 08fcb08 | 2015-08-04 15:19:11 +0200 | [diff] [blame] | 9164 | "LD_IND halfword positive offset", |
| 9165 | .u.insns = { |
| 9166 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9167 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2), |
| 9168 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9169 | }, |
| 9170 | CLASSIC, |
| 9171 | { |
| 9172 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9173 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9174 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9175 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9176 | }, |
| 9177 | { {0x40, 0xdd88 } }, |
| 9178 | }, |
| 9179 | { |
| 9180 | "LD_IND halfword negative offset", |
| 9181 | .u.insns = { |
| 9182 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9183 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2), |
| 9184 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9185 | }, |
| 9186 | CLASSIC, |
| 9187 | { |
| 9188 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9189 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9190 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9191 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9192 | }, |
| 9193 | { {0x40, 0xbb66 } }, |
| 9194 | }, |
| 9195 | { |
| 9196 | "LD_IND halfword unaligned", |
| 9197 | .u.insns = { |
| 9198 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9199 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1), |
| 9200 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9201 | }, |
| 9202 | CLASSIC, |
| 9203 | { |
| 9204 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9205 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9206 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9207 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9208 | }, |
| 9209 | { {0x40, 0x66cc } }, |
| 9210 | }, |
| 9211 | { |
Daniel Borkmann | 93731ef | 2018-05-04 01:08:13 +0200 | [diff] [blame] | 9212 | "LD_IND halfword positive offset, all ff", |
| 9213 | .u.insns = { |
| 9214 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3d), |
| 9215 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1), |
| 9216 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9217 | }, |
| 9218 | CLASSIC, |
| 9219 | { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff }, |
| 9220 | { {0x40, 0xffff } }, |
| 9221 | }, |
| 9222 | { |
| 9223 | "LD_IND halfword positive offset, out of bounds", |
| 9224 | .u.insns = { |
| 9225 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9226 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1), |
| 9227 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9228 | }, |
| 9229 | CLASSIC, |
| 9230 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9231 | { {0x3f, 0 }, }, |
| 9232 | }, |
| 9233 | { |
| 9234 | "LD_IND halfword negative offset, out of bounds", |
| 9235 | .u.insns = { |
| 9236 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9237 | BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f), |
| 9238 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9239 | }, |
| 9240 | CLASSIC, |
| 9241 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9242 | { {0x3f, 0 } }, |
| 9243 | }, |
| 9244 | { |
Nicolas Schichan | 08fcb08 | 2015-08-04 15:19:11 +0200 | [diff] [blame] | 9245 | "LD_IND word positive offset", |
| 9246 | .u.insns = { |
| 9247 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9248 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4), |
| 9249 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9250 | }, |
| 9251 | CLASSIC, |
| 9252 | { |
| 9253 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9254 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9255 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9256 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9257 | [0x24] = 0xee, [0x25] = 0x99, |
| 9258 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9259 | }, |
| 9260 | { {0x40, 0xee99ffaa } }, |
| 9261 | }, |
| 9262 | { |
| 9263 | "LD_IND word negative offset", |
| 9264 | .u.insns = { |
| 9265 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9266 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4), |
| 9267 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9268 | }, |
| 9269 | CLASSIC, |
| 9270 | { |
| 9271 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9272 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9273 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9274 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9275 | [0x24] = 0xee, [0x25] = 0x99, |
| 9276 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9277 | }, |
| 9278 | { {0x40, 0xaa55bb66 } }, |
| 9279 | }, |
| 9280 | { |
| 9281 | "LD_IND word unaligned (addr & 3 == 2)", |
| 9282 | .u.insns = { |
| 9283 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9284 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2), |
| 9285 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9286 | }, |
| 9287 | CLASSIC, |
| 9288 | { |
| 9289 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9290 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9291 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9292 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9293 | [0x24] = 0xee, [0x25] = 0x99, |
| 9294 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9295 | }, |
| 9296 | { {0x40, 0xbb66cc77 } }, |
| 9297 | }, |
| 9298 | { |
| 9299 | "LD_IND word unaligned (addr & 3 == 1)", |
| 9300 | .u.insns = { |
| 9301 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9302 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3), |
| 9303 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9304 | }, |
| 9305 | CLASSIC, |
| 9306 | { |
| 9307 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9308 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9309 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9310 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9311 | [0x24] = 0xee, [0x25] = 0x99, |
| 9312 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9313 | }, |
| 9314 | { {0x40, 0x55bb66cc } }, |
| 9315 | }, |
| 9316 | { |
| 9317 | "LD_IND word unaligned (addr & 3 == 3)", |
| 9318 | .u.insns = { |
| 9319 | BPF_STMT(BPF_LDX | BPF_IMM, 0x20), |
| 9320 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1), |
| 9321 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9322 | }, |
| 9323 | CLASSIC, |
| 9324 | { |
| 9325 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9326 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9327 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9328 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9329 | [0x24] = 0xee, [0x25] = 0x99, |
| 9330 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9331 | }, |
| 9332 | { {0x40, 0x66cc77dd } }, |
| 9333 | }, |
| 9334 | { |
Daniel Borkmann | 93731ef | 2018-05-04 01:08:13 +0200 | [diff] [blame] | 9335 | "LD_IND word positive offset, all ff", |
| 9336 | .u.insns = { |
| 9337 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3b), |
| 9338 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1), |
| 9339 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9340 | }, |
| 9341 | CLASSIC, |
| 9342 | { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff }, |
| 9343 | { {0x40, 0xffffffff } }, |
| 9344 | }, |
| 9345 | { |
| 9346 | "LD_IND word positive offset, out of bounds", |
| 9347 | .u.insns = { |
| 9348 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9349 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1), |
| 9350 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9351 | }, |
| 9352 | CLASSIC, |
| 9353 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9354 | { {0x3f, 0 }, }, |
| 9355 | }, |
| 9356 | { |
| 9357 | "LD_IND word negative offset, out of bounds", |
| 9358 | .u.insns = { |
| 9359 | BPF_STMT(BPF_LDX | BPF_IMM, 0x3e), |
| 9360 | BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f), |
| 9361 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9362 | }, |
| 9363 | CLASSIC, |
| 9364 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9365 | { {0x3f, 0 } }, |
| 9366 | }, |
| 9367 | { |
Nicolas Schichan | 08fcb08 | 2015-08-04 15:19:11 +0200 | [diff] [blame] | 9368 | "LD_ABS byte", |
| 9369 | .u.insns = { |
| 9370 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20), |
| 9371 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9372 | }, |
| 9373 | CLASSIC, |
| 9374 | { |
| 9375 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9376 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9377 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9378 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9379 | [0x24] = 0xee, [0x25] = 0x99, |
| 9380 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9381 | }, |
| 9382 | { {0x40, 0xcc } }, |
| 9383 | }, |
| 9384 | { |
Daniel Borkmann | 93731ef | 2018-05-04 01:08:13 +0200 | [diff] [blame] | 9385 | "LD_ABS byte positive offset, all ff", |
| 9386 | .u.insns = { |
| 9387 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f), |
| 9388 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9389 | }, |
| 9390 | CLASSIC, |
| 9391 | { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff }, |
| 9392 | { {0x40, 0xff } }, |
| 9393 | }, |
| 9394 | { |
| 9395 | "LD_ABS byte positive offset, out of bounds", |
| 9396 | .u.insns = { |
| 9397 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f), |
| 9398 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9399 | }, |
| 9400 | CLASSIC, |
| 9401 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9402 | { {0x3f, 0 }, }, |
| 9403 | }, |
| 9404 | { |
| 9405 | "LD_ABS byte negative offset, out of bounds load", |
| 9406 | .u.insns = { |
| 9407 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1), |
| 9408 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9409 | }, |
| 9410 | CLASSIC | FLAG_EXPECTED_FAIL, |
| 9411 | .expected_errcode = -EINVAL, |
| 9412 | }, |
| 9413 | { |
| 9414 | "LD_ABS byte negative offset, in bounds", |
| 9415 | .u.insns = { |
| 9416 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f), |
| 9417 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9418 | }, |
| 9419 | CLASSIC, |
| 9420 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9421 | { {0x40, 0x82 }, }, |
| 9422 | }, |
| 9423 | { |
| 9424 | "LD_ABS byte negative offset, out of bounds", |
| 9425 | .u.insns = { |
| 9426 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f), |
| 9427 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9428 | }, |
| 9429 | CLASSIC, |
| 9430 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9431 | { {0x3f, 0 }, }, |
| 9432 | }, |
| 9433 | { |
| 9434 | "LD_ABS byte negative offset, multiple calls", |
| 9435 | .u.insns = { |
| 9436 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c), |
| 9437 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d), |
| 9438 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e), |
| 9439 | BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f), |
| 9440 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9441 | }, |
| 9442 | CLASSIC, |
| 9443 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9444 | { {0x40, 0x82 }, }, |
| 9445 | }, |
| 9446 | { |
Nicolas Schichan | 08fcb08 | 2015-08-04 15:19:11 +0200 | [diff] [blame] | 9447 | "LD_ABS halfword", |
| 9448 | .u.insns = { |
| 9449 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22), |
| 9450 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9451 | }, |
| 9452 | CLASSIC, |
| 9453 | { |
| 9454 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9455 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9456 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9457 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9458 | [0x24] = 0xee, [0x25] = 0x99, |
| 9459 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9460 | }, |
| 9461 | { {0x40, 0xdd88 } }, |
| 9462 | }, |
| 9463 | { |
| 9464 | "LD_ABS halfword unaligned", |
| 9465 | .u.insns = { |
| 9466 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25), |
| 9467 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9468 | }, |
| 9469 | CLASSIC, |
| 9470 | { |
| 9471 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9472 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9473 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9474 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9475 | [0x24] = 0xee, [0x25] = 0x99, |
| 9476 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9477 | }, |
| 9478 | { {0x40, 0x99ff } }, |
| 9479 | }, |
| 9480 | { |
Daniel Borkmann | 93731ef | 2018-05-04 01:08:13 +0200 | [diff] [blame] | 9481 | "LD_ABS halfword positive offset, all ff", |
| 9482 | .u.insns = { |
| 9483 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e), |
| 9484 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9485 | }, |
| 9486 | CLASSIC, |
| 9487 | { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff }, |
| 9488 | { {0x40, 0xffff } }, |
| 9489 | }, |
| 9490 | { |
| 9491 | "LD_ABS halfword positive offset, out of bounds", |
| 9492 | .u.insns = { |
| 9493 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f), |
| 9494 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9495 | }, |
| 9496 | CLASSIC, |
| 9497 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9498 | { {0x3f, 0 }, }, |
| 9499 | }, |
| 9500 | { |
| 9501 | "LD_ABS halfword negative offset, out of bounds load", |
| 9502 | .u.insns = { |
| 9503 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1), |
| 9504 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9505 | }, |
| 9506 | CLASSIC | FLAG_EXPECTED_FAIL, |
| 9507 | .expected_errcode = -EINVAL, |
| 9508 | }, |
| 9509 | { |
| 9510 | "LD_ABS halfword negative offset, in bounds", |
| 9511 | .u.insns = { |
| 9512 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e), |
| 9513 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9514 | }, |
| 9515 | CLASSIC, |
| 9516 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9517 | { {0x40, 0x1982 }, }, |
| 9518 | }, |
| 9519 | { |
| 9520 | "LD_ABS halfword negative offset, out of bounds", |
| 9521 | .u.insns = { |
| 9522 | BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e), |
| 9523 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9524 | }, |
| 9525 | CLASSIC, |
| 9526 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9527 | { {0x3f, 0 }, }, |
| 9528 | }, |
| 9529 | { |
Nicolas Schichan | 08fcb08 | 2015-08-04 15:19:11 +0200 | [diff] [blame] | 9530 | "LD_ABS word", |
| 9531 | .u.insns = { |
| 9532 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c), |
| 9533 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9534 | }, |
| 9535 | CLASSIC, |
| 9536 | { |
| 9537 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9538 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9539 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9540 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9541 | [0x24] = 0xee, [0x25] = 0x99, |
| 9542 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9543 | }, |
| 9544 | { {0x40, 0xaa55bb66 } }, |
| 9545 | }, |
| 9546 | { |
| 9547 | "LD_ABS word unaligned (addr & 3 == 2)", |
| 9548 | .u.insns = { |
| 9549 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22), |
| 9550 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9551 | }, |
| 9552 | CLASSIC, |
| 9553 | { |
| 9554 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9555 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9556 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9557 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9558 | [0x24] = 0xee, [0x25] = 0x99, |
| 9559 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9560 | }, |
| 9561 | { {0x40, 0xdd88ee99 } }, |
| 9562 | }, |
| 9563 | { |
| 9564 | "LD_ABS word unaligned (addr & 3 == 1)", |
| 9565 | .u.insns = { |
| 9566 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21), |
| 9567 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9568 | }, |
| 9569 | CLASSIC, |
| 9570 | { |
| 9571 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9572 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9573 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9574 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9575 | [0x24] = 0xee, [0x25] = 0x99, |
| 9576 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9577 | }, |
| 9578 | { {0x40, 0x77dd88ee } }, |
| 9579 | }, |
| 9580 | { |
| 9581 | "LD_ABS word unaligned (addr & 3 == 3)", |
| 9582 | .u.insns = { |
| 9583 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23), |
| 9584 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9585 | }, |
| 9586 | CLASSIC, |
| 9587 | { |
| 9588 | [0x1c] = 0xaa, [0x1d] = 0x55, |
| 9589 | [0x1e] = 0xbb, [0x1f] = 0x66, |
| 9590 | [0x20] = 0xcc, [0x21] = 0x77, |
| 9591 | [0x22] = 0xdd, [0x23] = 0x88, |
| 9592 | [0x24] = 0xee, [0x25] = 0x99, |
| 9593 | [0x26] = 0xff, [0x27] = 0xaa, |
| 9594 | }, |
| 9595 | { {0x40, 0x88ee99ff } }, |
| 9596 | }, |
Daniel Borkmann | 93731ef | 2018-05-04 01:08:13 +0200 | [diff] [blame] | 9597 | { |
| 9598 | "LD_ABS word positive offset, all ff", |
| 9599 | .u.insns = { |
| 9600 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c), |
| 9601 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9602 | }, |
| 9603 | CLASSIC, |
| 9604 | { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff }, |
| 9605 | { {0x40, 0xffffffff } }, |
| 9606 | }, |
| 9607 | { |
| 9608 | "LD_ABS word positive offset, out of bounds", |
| 9609 | .u.insns = { |
| 9610 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f), |
| 9611 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9612 | }, |
| 9613 | CLASSIC, |
| 9614 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9615 | { {0x3f, 0 }, }, |
| 9616 | }, |
| 9617 | { |
| 9618 | "LD_ABS word negative offset, out of bounds load", |
| 9619 | .u.insns = { |
| 9620 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1), |
| 9621 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9622 | }, |
| 9623 | CLASSIC | FLAG_EXPECTED_FAIL, |
| 9624 | .expected_errcode = -EINVAL, |
| 9625 | }, |
| 9626 | { |
| 9627 | "LD_ABS word negative offset, in bounds", |
| 9628 | .u.insns = { |
| 9629 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c), |
| 9630 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9631 | }, |
| 9632 | CLASSIC, |
| 9633 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9634 | { {0x40, 0x25051982 }, }, |
| 9635 | }, |
| 9636 | { |
| 9637 | "LD_ABS word negative offset, out of bounds", |
| 9638 | .u.insns = { |
| 9639 | BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c), |
| 9640 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9641 | }, |
| 9642 | CLASSIC, |
| 9643 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9644 | { {0x3f, 0 }, }, |
| 9645 | }, |
| 9646 | { |
| 9647 | "LDX_MSH standalone, preserved A", |
| 9648 | .u.insns = { |
| 9649 | BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa), |
| 9650 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c), |
| 9651 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9652 | }, |
| 9653 | CLASSIC, |
| 9654 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9655 | { {0x40, 0xffeebbaa }, }, |
| 9656 | }, |
| 9657 | { |
| 9658 | "LDX_MSH standalone, preserved A 2", |
| 9659 | .u.insns = { |
| 9660 | BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63), |
| 9661 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c), |
| 9662 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d), |
| 9663 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e), |
| 9664 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f), |
| 9665 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9666 | }, |
| 9667 | CLASSIC, |
| 9668 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9669 | { {0x40, 0x175e9d63 }, }, |
| 9670 | }, |
| 9671 | { |
| 9672 | "LDX_MSH standalone, test result 1", |
| 9673 | .u.insns = { |
| 9674 | BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa), |
| 9675 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c), |
| 9676 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 9677 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9678 | }, |
| 9679 | CLASSIC, |
| 9680 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9681 | { {0x40, 0x14 }, }, |
| 9682 | }, |
| 9683 | { |
| 9684 | "LDX_MSH standalone, test result 2", |
| 9685 | .u.insns = { |
| 9686 | BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa), |
| 9687 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e), |
| 9688 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 9689 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9690 | }, |
| 9691 | CLASSIC, |
| 9692 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9693 | { {0x40, 0x24 }, }, |
| 9694 | }, |
| 9695 | { |
| 9696 | "LDX_MSH standalone, negative offset", |
| 9697 | .u.insns = { |
| 9698 | BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa), |
| 9699 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1), |
| 9700 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 9701 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9702 | }, |
| 9703 | CLASSIC, |
| 9704 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9705 | { {0x40, 0 }, }, |
| 9706 | }, |
| 9707 | { |
| 9708 | "LDX_MSH standalone, negative offset 2", |
| 9709 | .u.insns = { |
| 9710 | BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa), |
| 9711 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e), |
| 9712 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 9713 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9714 | }, |
| 9715 | CLASSIC, |
| 9716 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9717 | { {0x40, 0x24 }, }, |
| 9718 | }, |
| 9719 | { |
| 9720 | "LDX_MSH standalone, out of bounds", |
| 9721 | .u.insns = { |
| 9722 | BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa), |
| 9723 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40), |
| 9724 | BPF_STMT(BPF_MISC | BPF_TXA, 0), |
| 9725 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9726 | }, |
| 9727 | CLASSIC, |
| 9728 | { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 }, |
| 9729 | { {0x40, 0 }, }, |
| 9730 | }, |
Nicolas Schichan | 86bf172 | 2015-08-04 15:19:12 +0200 | [diff] [blame] | 9731 | /* |
| 9732 | * verify that the interpreter or JIT correctly sets A and X |
| 9733 | * to 0. |
| 9734 | */ |
| 9735 | { |
| 9736 | "ADD default X", |
| 9737 | .u.insns = { |
| 9738 | /* |
| 9739 | * A = 0x42 |
| 9740 | * A = A + X |
| 9741 | * ret A |
| 9742 | */ |
| 9743 | BPF_STMT(BPF_LD | BPF_IMM, 0x42), |
| 9744 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 9745 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9746 | }, |
| 9747 | CLASSIC | FLAG_NO_DATA, |
| 9748 | {}, |
| 9749 | { {0x1, 0x42 } }, |
| 9750 | }, |
| 9751 | { |
| 9752 | "ADD default A", |
| 9753 | .u.insns = { |
| 9754 | /* |
| 9755 | * A = A + 0x42 |
| 9756 | * ret A |
| 9757 | */ |
| 9758 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42), |
| 9759 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9760 | }, |
| 9761 | CLASSIC | FLAG_NO_DATA, |
| 9762 | {}, |
| 9763 | { {0x1, 0x42 } }, |
| 9764 | }, |
| 9765 | { |
| 9766 | "SUB default X", |
| 9767 | .u.insns = { |
| 9768 | /* |
| 9769 | * A = 0x66 |
| 9770 | * A = A - X |
| 9771 | * ret A |
| 9772 | */ |
| 9773 | BPF_STMT(BPF_LD | BPF_IMM, 0x66), |
| 9774 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), |
| 9775 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9776 | }, |
| 9777 | CLASSIC | FLAG_NO_DATA, |
| 9778 | {}, |
| 9779 | { {0x1, 0x66 } }, |
| 9780 | }, |
| 9781 | { |
| 9782 | "SUB default A", |
| 9783 | .u.insns = { |
| 9784 | /* |
| 9785 | * A = A - -0x66 |
| 9786 | * ret A |
| 9787 | */ |
| 9788 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66), |
| 9789 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9790 | }, |
| 9791 | CLASSIC | FLAG_NO_DATA, |
| 9792 | {}, |
| 9793 | { {0x1, 0x66 } }, |
| 9794 | }, |
| 9795 | { |
| 9796 | "MUL default X", |
| 9797 | .u.insns = { |
| 9798 | /* |
| 9799 | * A = 0x42 |
| 9800 | * A = A * X |
| 9801 | * ret A |
| 9802 | */ |
| 9803 | BPF_STMT(BPF_LD | BPF_IMM, 0x42), |
| 9804 | BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0), |
| 9805 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9806 | }, |
| 9807 | CLASSIC | FLAG_NO_DATA, |
| 9808 | {}, |
| 9809 | { {0x1, 0x0 } }, |
| 9810 | }, |
| 9811 | { |
| 9812 | "MUL default A", |
| 9813 | .u.insns = { |
| 9814 | /* |
| 9815 | * A = A * 0x66 |
| 9816 | * ret A |
| 9817 | */ |
| 9818 | BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66), |
| 9819 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9820 | }, |
| 9821 | CLASSIC | FLAG_NO_DATA, |
| 9822 | {}, |
| 9823 | { {0x1, 0x0 } }, |
| 9824 | }, |
| 9825 | { |
| 9826 | "DIV default X", |
| 9827 | .u.insns = { |
| 9828 | /* |
| 9829 | * A = 0x42 |
| 9830 | * A = A / X ; this halt the filter execution if X is 0 |
| 9831 | * ret 0x42 |
| 9832 | */ |
| 9833 | BPF_STMT(BPF_LD | BPF_IMM, 0x42), |
| 9834 | BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0), |
| 9835 | BPF_STMT(BPF_RET | BPF_K, 0x42), |
| 9836 | }, |
| 9837 | CLASSIC | FLAG_NO_DATA, |
| 9838 | {}, |
| 9839 | { {0x1, 0x0 } }, |
| 9840 | }, |
| 9841 | { |
| 9842 | "DIV default A", |
| 9843 | .u.insns = { |
| 9844 | /* |
| 9845 | * A = A / 1 |
| 9846 | * ret A |
| 9847 | */ |
| 9848 | BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1), |
| 9849 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9850 | }, |
| 9851 | CLASSIC | FLAG_NO_DATA, |
| 9852 | {}, |
| 9853 | { {0x1, 0x0 } }, |
| 9854 | }, |
| 9855 | { |
Yang Shi | d4e4bc1 | 2015-11-04 11:36:37 -0800 | [diff] [blame] | 9856 | "MOD default X", |
| 9857 | .u.insns = { |
| 9858 | /* |
| 9859 | * A = 0x42 |
| 9860 | * A = A mod X ; this halt the filter execution if X is 0 |
| 9861 | * ret 0x42 |
| 9862 | */ |
| 9863 | BPF_STMT(BPF_LD | BPF_IMM, 0x42), |
| 9864 | BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0), |
| 9865 | BPF_STMT(BPF_RET | BPF_K, 0x42), |
| 9866 | }, |
| 9867 | CLASSIC | FLAG_NO_DATA, |
| 9868 | {}, |
| 9869 | { {0x1, 0x0 } }, |
| 9870 | }, |
| 9871 | { |
| 9872 | "MOD default A", |
| 9873 | .u.insns = { |
| 9874 | /* |
| 9875 | * A = A mod 1 |
| 9876 | * ret A |
| 9877 | */ |
| 9878 | BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1), |
| 9879 | BPF_STMT(BPF_RET | BPF_A, 0x0), |
| 9880 | }, |
| 9881 | CLASSIC | FLAG_NO_DATA, |
| 9882 | {}, |
| 9883 | { {0x1, 0x0 } }, |
| 9884 | }, |
| 9885 | { |
Nicolas Schichan | 86bf172 | 2015-08-04 15:19:12 +0200 | [diff] [blame] | 9886 | "JMP EQ default A", |
| 9887 | .u.insns = { |
| 9888 | /* |
| 9889 | * cmp A, 0x0, 0, 1 |
| 9890 | * ret 0x42 |
| 9891 | * ret 0x66 |
| 9892 | */ |
| 9893 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1), |
| 9894 | BPF_STMT(BPF_RET | BPF_K, 0x42), |
| 9895 | BPF_STMT(BPF_RET | BPF_K, 0x66), |
| 9896 | }, |
| 9897 | CLASSIC | FLAG_NO_DATA, |
| 9898 | {}, |
| 9899 | { {0x1, 0x42 } }, |
| 9900 | }, |
| 9901 | { |
| 9902 | "JMP EQ default X", |
| 9903 | .u.insns = { |
| 9904 | /* |
| 9905 | * A = 0x0 |
| 9906 | * cmp A, X, 0, 1 |
| 9907 | * ret 0x42 |
| 9908 | * ret 0x66 |
| 9909 | */ |
| 9910 | BPF_STMT(BPF_LD | BPF_IMM, 0x0), |
| 9911 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1), |
| 9912 | BPF_STMT(BPF_RET | BPF_K, 0x42), |
| 9913 | BPF_STMT(BPF_RET | BPF_K, 0x66), |
| 9914 | }, |
| 9915 | CLASSIC | FLAG_NO_DATA, |
| 9916 | {}, |
| 9917 | { {0x1, 0x42 } }, |
| 9918 | }, |
Daniel Borkmann | fcd1c91 | 2018-01-20 01:24:31 +0100 | [diff] [blame] | 9919 | /* Checking interpreter vs JIT wrt signed extended imms. */ |
| 9920 | { |
| 9921 | "JNE signed compare, test 1", |
| 9922 | .u.insns_int = { |
| 9923 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12), |
| 9924 | BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000), |
| 9925 | BPF_MOV64_REG(R2, R1), |
| 9926 | BPF_ALU64_REG(BPF_AND, R2, R3), |
| 9927 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 9928 | BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1), |
| 9929 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 9930 | BPF_EXIT_INSN(), |
| 9931 | }, |
| 9932 | INTERNAL, |
| 9933 | { }, |
| 9934 | { { 0, 1 } }, |
| 9935 | }, |
| 9936 | { |
| 9937 | "JNE signed compare, test 2", |
| 9938 | .u.insns_int = { |
| 9939 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12), |
| 9940 | BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000), |
| 9941 | BPF_MOV64_REG(R2, R1), |
| 9942 | BPF_ALU64_REG(BPF_AND, R2, R3), |
| 9943 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 9944 | BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1), |
| 9945 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 9946 | BPF_EXIT_INSN(), |
| 9947 | }, |
| 9948 | INTERNAL, |
| 9949 | { }, |
| 9950 | { { 0, 1 } }, |
| 9951 | }, |
| 9952 | { |
| 9953 | "JNE signed compare, test 3", |
| 9954 | .u.insns_int = { |
| 9955 | BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12), |
| 9956 | BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000), |
| 9957 | BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000), |
| 9958 | BPF_MOV64_REG(R2, R1), |
| 9959 | BPF_ALU64_REG(BPF_AND, R2, R3), |
| 9960 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 9961 | BPF_JMP_REG(BPF_JNE, R2, R4, 1), |
| 9962 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 9963 | BPF_EXIT_INSN(), |
| 9964 | }, |
| 9965 | INTERNAL, |
| 9966 | { }, |
| 9967 | { { 0, 2 } }, |
| 9968 | }, |
| 9969 | { |
| 9970 | "JNE signed compare, test 4", |
| 9971 | .u.insns_int = { |
| 9972 | BPF_LD_IMM64(R1, -17104896), |
| 9973 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 9974 | BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1), |
| 9975 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 9976 | BPF_EXIT_INSN(), |
| 9977 | }, |
| 9978 | INTERNAL, |
| 9979 | { }, |
| 9980 | { { 0, 2 } }, |
| 9981 | }, |
| 9982 | { |
| 9983 | "JNE signed compare, test 5", |
| 9984 | .u.insns_int = { |
| 9985 | BPF_LD_IMM64(R1, 0xfefb0000), |
| 9986 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 9987 | BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1), |
| 9988 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 9989 | BPF_EXIT_INSN(), |
| 9990 | }, |
| 9991 | INTERNAL, |
| 9992 | { }, |
| 9993 | { { 0, 1 } }, |
| 9994 | }, |
| 9995 | { |
| 9996 | "JNE signed compare, test 6", |
| 9997 | .u.insns_int = { |
| 9998 | BPF_LD_IMM64(R1, 0x7efb0000), |
| 9999 | BPF_ALU32_IMM(BPF_MOV, R0, 1), |
| 10000 | BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1), |
| 10001 | BPF_ALU32_IMM(BPF_MOV, R0, 2), |
| 10002 | BPF_EXIT_INSN(), |
| 10003 | }, |
| 10004 | INTERNAL, |
| 10005 | { }, |
| 10006 | { { 0, 2 } }, |
| 10007 | }, |
| 10008 | { |
| 10009 | "JNE signed compare, test 7", |
| 10010 | .u.insns = { |
| 10011 | BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000), |
| 10012 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 10013 | BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12), |
| 10014 | BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0), |
| 10015 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0), |
| 10016 | BPF_STMT(BPF_RET | BPF_K, 1), |
| 10017 | BPF_STMT(BPF_RET | BPF_K, 2), |
| 10018 | }, |
| 10019 | CLASSIC | FLAG_NO_DATA, |
| 10020 | {}, |
| 10021 | { { 0, 2 } }, |
| 10022 | }, |
Johan Almbladh | 68c956f | 2021-09-14 11:18:31 +0200 | [diff] [blame] | 10023 | /* Exhaustive test of ALU64 shift operations */ |
| 10024 | { |
| 10025 | "ALU64_LSH_K: all shift values", |
| 10026 | { }, |
| 10027 | INTERNAL | FLAG_NO_DATA, |
| 10028 | { }, |
| 10029 | { { 0, 1 } }, |
| 10030 | .fill_helper = bpf_fill_alu_lsh_imm, |
| 10031 | }, |
| 10032 | { |
| 10033 | "ALU64_RSH_K: all shift values", |
| 10034 | { }, |
| 10035 | INTERNAL | FLAG_NO_DATA, |
| 10036 | { }, |
| 10037 | { { 0, 1 } }, |
| 10038 | .fill_helper = bpf_fill_alu_rsh_imm, |
| 10039 | }, |
| 10040 | { |
| 10041 | "ALU64_ARSH_K: all shift values", |
| 10042 | { }, |
| 10043 | INTERNAL | FLAG_NO_DATA, |
| 10044 | { }, |
| 10045 | { { 0, 1 } }, |
| 10046 | .fill_helper = bpf_fill_alu_arsh_imm, |
| 10047 | }, |
| 10048 | { |
| 10049 | "ALU64_LSH_X: all shift values", |
| 10050 | { }, |
| 10051 | INTERNAL | FLAG_NO_DATA, |
| 10052 | { }, |
| 10053 | { { 0, 1 } }, |
| 10054 | .fill_helper = bpf_fill_alu_lsh_reg, |
| 10055 | }, |
| 10056 | { |
| 10057 | "ALU64_RSH_X: all shift values", |
| 10058 | { }, |
| 10059 | INTERNAL | FLAG_NO_DATA, |
| 10060 | { }, |
| 10061 | { { 0, 1 } }, |
| 10062 | .fill_helper = bpf_fill_alu_rsh_reg, |
| 10063 | }, |
| 10064 | { |
| 10065 | "ALU64_ARSH_X: all shift values", |
| 10066 | { }, |
| 10067 | INTERNAL | FLAG_NO_DATA, |
| 10068 | { }, |
| 10069 | { { 0, 1 } }, |
| 10070 | .fill_helper = bpf_fill_alu_arsh_reg, |
| 10071 | }, |
| 10072 | /* Exhaustive test of ALU32 shift operations */ |
| 10073 | { |
| 10074 | "ALU32_LSH_K: all shift values", |
| 10075 | { }, |
| 10076 | INTERNAL | FLAG_NO_DATA, |
| 10077 | { }, |
| 10078 | { { 0, 1 } }, |
| 10079 | .fill_helper = bpf_fill_alu32_lsh_imm, |
| 10080 | }, |
| 10081 | { |
| 10082 | "ALU32_RSH_K: all shift values", |
| 10083 | { }, |
| 10084 | INTERNAL | FLAG_NO_DATA, |
| 10085 | { }, |
| 10086 | { { 0, 1 } }, |
| 10087 | .fill_helper = bpf_fill_alu32_rsh_imm, |
| 10088 | }, |
| 10089 | { |
| 10090 | "ALU32_ARSH_K: all shift values", |
| 10091 | { }, |
| 10092 | INTERNAL | FLAG_NO_DATA, |
| 10093 | { }, |
| 10094 | { { 0, 1 } }, |
| 10095 | .fill_helper = bpf_fill_alu32_arsh_imm, |
| 10096 | }, |
| 10097 | { |
| 10098 | "ALU32_LSH_X: all shift values", |
| 10099 | { }, |
| 10100 | INTERNAL | FLAG_NO_DATA, |
| 10101 | { }, |
| 10102 | { { 0, 1 } }, |
| 10103 | .fill_helper = bpf_fill_alu32_lsh_reg, |
| 10104 | }, |
| 10105 | { |
| 10106 | "ALU32_RSH_X: all shift values", |
| 10107 | { }, |
| 10108 | INTERNAL | FLAG_NO_DATA, |
| 10109 | { }, |
| 10110 | { { 0, 1 } }, |
| 10111 | .fill_helper = bpf_fill_alu32_rsh_reg, |
| 10112 | }, |
| 10113 | { |
| 10114 | "ALU32_ARSH_X: all shift values", |
| 10115 | { }, |
| 10116 | INTERNAL | FLAG_NO_DATA, |
| 10117 | { }, |
| 10118 | { { 0, 1 } }, |
| 10119 | .fill_helper = bpf_fill_alu32_arsh_reg, |
| 10120 | }, |
Johan Almbladh | 9298e63 | 2021-09-14 11:18:32 +0200 | [diff] [blame] | 10121 | /* ALU64 immediate magnitudes */ |
| 10122 | { |
| 10123 | "ALU64_MOV_K: all immediate value magnitudes", |
| 10124 | { }, |
| 10125 | INTERNAL | FLAG_NO_DATA, |
| 10126 | { }, |
| 10127 | { { 0, 1 } }, |
| 10128 | .fill_helper = bpf_fill_alu64_mov_imm, |
| 10129 | .nr_testruns = NR_PATTERN_RUNS, |
| 10130 | }, |
| 10131 | { |
| 10132 | "ALU64_AND_K: all immediate value magnitudes", |
| 10133 | { }, |
| 10134 | INTERNAL | FLAG_NO_DATA, |
| 10135 | { }, |
| 10136 | { { 0, 1 } }, |
| 10137 | .fill_helper = bpf_fill_alu64_and_imm, |
| 10138 | .nr_testruns = NR_PATTERN_RUNS, |
| 10139 | }, |
| 10140 | { |
| 10141 | "ALU64_OR_K: all immediate value magnitudes", |
| 10142 | { }, |
| 10143 | INTERNAL | FLAG_NO_DATA, |
| 10144 | { }, |
| 10145 | { { 0, 1 } }, |
| 10146 | .fill_helper = bpf_fill_alu64_or_imm, |
| 10147 | .nr_testruns = NR_PATTERN_RUNS, |
| 10148 | }, |
| 10149 | { |
| 10150 | "ALU64_XOR_K: all immediate value magnitudes", |
| 10151 | { }, |
| 10152 | INTERNAL | FLAG_NO_DATA, |
| 10153 | { }, |
| 10154 | { { 0, 1 } }, |
| 10155 | .fill_helper = bpf_fill_alu64_xor_imm, |
| 10156 | .nr_testruns = NR_PATTERN_RUNS, |
| 10157 | }, |
| 10158 | { |
| 10159 | "ALU64_ADD_K: all immediate value magnitudes", |
| 10160 | { }, |
| 10161 | INTERNAL | FLAG_NO_DATA, |
| 10162 | { }, |
| 10163 | { { 0, 1 } }, |
| 10164 | .fill_helper = bpf_fill_alu64_add_imm, |
| 10165 | .nr_testruns = NR_PATTERN_RUNS, |
| 10166 | }, |
| 10167 | { |
| 10168 | "ALU64_SUB_K: all immediate value magnitudes", |
| 10169 | { }, |
| 10170 | INTERNAL | FLAG_NO_DATA, |
| 10171 | { }, |
| 10172 | { { 0, 1 } }, |
| 10173 | .fill_helper = bpf_fill_alu64_sub_imm, |
| 10174 | .nr_testruns = NR_PATTERN_RUNS, |
| 10175 | }, |
| 10176 | { |
| 10177 | "ALU64_MUL_K: all immediate value magnitudes", |
| 10178 | { }, |
| 10179 | INTERNAL | FLAG_NO_DATA, |
| 10180 | { }, |
| 10181 | { { 0, 1 } }, |
| 10182 | .fill_helper = bpf_fill_alu64_mul_imm, |
| 10183 | .nr_testruns = NR_PATTERN_RUNS, |
| 10184 | }, |
| 10185 | { |
| 10186 | "ALU64_DIV_K: all immediate value magnitudes", |
| 10187 | { }, |
| 10188 | INTERNAL | FLAG_NO_DATA, |
| 10189 | { }, |
| 10190 | { { 0, 1 } }, |
| 10191 | .fill_helper = bpf_fill_alu64_div_imm, |
| 10192 | .nr_testruns = NR_PATTERN_RUNS, |
| 10193 | }, |
| 10194 | { |
| 10195 | "ALU64_MOD_K: all immediate value magnitudes", |
| 10196 | { }, |
| 10197 | INTERNAL | FLAG_NO_DATA, |
| 10198 | { }, |
| 10199 | { { 0, 1 } }, |
| 10200 | .fill_helper = bpf_fill_alu64_mod_imm, |
| 10201 | .nr_testruns = NR_PATTERN_RUNS, |
| 10202 | }, |
| 10203 | /* ALU32 immediate magnitudes */ |
| 10204 | { |
| 10205 | "ALU32_MOV_K: all immediate value magnitudes", |
| 10206 | { }, |
| 10207 | INTERNAL | FLAG_NO_DATA, |
| 10208 | { }, |
| 10209 | { { 0, 1 } }, |
| 10210 | .fill_helper = bpf_fill_alu32_mov_imm, |
| 10211 | .nr_testruns = NR_PATTERN_RUNS, |
| 10212 | }, |
| 10213 | { |
| 10214 | "ALU32_AND_K: all immediate value magnitudes", |
| 10215 | { }, |
| 10216 | INTERNAL | FLAG_NO_DATA, |
| 10217 | { }, |
| 10218 | { { 0, 1 } }, |
| 10219 | .fill_helper = bpf_fill_alu32_and_imm, |
| 10220 | .nr_testruns = NR_PATTERN_RUNS, |
| 10221 | }, |
| 10222 | { |
| 10223 | "ALU32_OR_K: all immediate value magnitudes", |
| 10224 | { }, |
| 10225 | INTERNAL | FLAG_NO_DATA, |
| 10226 | { }, |
| 10227 | { { 0, 1 } }, |
| 10228 | .fill_helper = bpf_fill_alu32_or_imm, |
| 10229 | .nr_testruns = NR_PATTERN_RUNS, |
| 10230 | }, |
| 10231 | { |
| 10232 | "ALU32_XOR_K: all immediate value magnitudes", |
| 10233 | { }, |
| 10234 | INTERNAL | FLAG_NO_DATA, |
| 10235 | { }, |
| 10236 | { { 0, 1 } }, |
| 10237 | .fill_helper = bpf_fill_alu32_xor_imm, |
| 10238 | .nr_testruns = NR_PATTERN_RUNS, |
| 10239 | }, |
| 10240 | { |
| 10241 | "ALU32_ADD_K: all immediate value magnitudes", |
| 10242 | { }, |
| 10243 | INTERNAL | FLAG_NO_DATA, |
| 10244 | { }, |
| 10245 | { { 0, 1 } }, |
| 10246 | .fill_helper = bpf_fill_alu32_add_imm, |
| 10247 | .nr_testruns = NR_PATTERN_RUNS, |
| 10248 | }, |
| 10249 | { |
| 10250 | "ALU32_SUB_K: all immediate value magnitudes", |
| 10251 | { }, |
| 10252 | INTERNAL | FLAG_NO_DATA, |
| 10253 | { }, |
| 10254 | { { 0, 1 } }, |
| 10255 | .fill_helper = bpf_fill_alu32_sub_imm, |
| 10256 | .nr_testruns = NR_PATTERN_RUNS, |
| 10257 | }, |
| 10258 | { |
| 10259 | "ALU32_MUL_K: all immediate value magnitudes", |
| 10260 | { }, |
| 10261 | INTERNAL | FLAG_NO_DATA, |
| 10262 | { }, |
| 10263 | { { 0, 1 } }, |
| 10264 | .fill_helper = bpf_fill_alu32_mul_imm, |
| 10265 | .nr_testruns = NR_PATTERN_RUNS, |
| 10266 | }, |
| 10267 | { |
| 10268 | "ALU32_DIV_K: all immediate value magnitudes", |
| 10269 | { }, |
| 10270 | INTERNAL | FLAG_NO_DATA, |
| 10271 | { }, |
| 10272 | { { 0, 1 } }, |
| 10273 | .fill_helper = bpf_fill_alu32_div_imm, |
| 10274 | .nr_testruns = NR_PATTERN_RUNS, |
| 10275 | }, |
| 10276 | { |
| 10277 | "ALU32_MOD_K: all immediate value magnitudes", |
| 10278 | { }, |
| 10279 | INTERNAL | FLAG_NO_DATA, |
| 10280 | { }, |
| 10281 | { { 0, 1 } }, |
| 10282 | .fill_helper = bpf_fill_alu32_mod_imm, |
Johan Almbladh | a5a3654 | 2021-09-14 11:18:33 +0200 | [diff] [blame] | 10283 | .nr_testruns = NR_PATTERN_RUNS, |
Johan Almbladh | 9298e63 | 2021-09-14 11:18:32 +0200 | [diff] [blame] | 10284 | }, |
| 10285 | /* ALU64 register magnitudes */ |
| 10286 | { |
| 10287 | "ALU64_MOV_X: all register value magnitudes", |
| 10288 | { }, |
| 10289 | INTERNAL | FLAG_NO_DATA, |
| 10290 | { }, |
| 10291 | { { 0, 1 } }, |
| 10292 | .fill_helper = bpf_fill_alu64_mov_reg, |
| 10293 | .nr_testruns = NR_PATTERN_RUNS, |
| 10294 | }, |
| 10295 | { |
| 10296 | "ALU64_AND_X: all register value magnitudes", |
| 10297 | { }, |
| 10298 | INTERNAL | FLAG_NO_DATA, |
| 10299 | { }, |
| 10300 | { { 0, 1 } }, |
| 10301 | .fill_helper = bpf_fill_alu64_and_reg, |
| 10302 | .nr_testruns = NR_PATTERN_RUNS, |
| 10303 | }, |
| 10304 | { |
| 10305 | "ALU64_OR_X: all register value magnitudes", |
| 10306 | { }, |
| 10307 | INTERNAL | FLAG_NO_DATA, |
| 10308 | { }, |
| 10309 | { { 0, 1 } }, |
| 10310 | .fill_helper = bpf_fill_alu64_or_reg, |
| 10311 | .nr_testruns = NR_PATTERN_RUNS, |
| 10312 | }, |
| 10313 | { |
| 10314 | "ALU64_XOR_X: all register value magnitudes", |
| 10315 | { }, |
| 10316 | INTERNAL | FLAG_NO_DATA, |
| 10317 | { }, |
| 10318 | { { 0, 1 } }, |
| 10319 | .fill_helper = bpf_fill_alu64_xor_reg, |
| 10320 | .nr_testruns = NR_PATTERN_RUNS, |
| 10321 | }, |
| 10322 | { |
| 10323 | "ALU64_ADD_X: all register value magnitudes", |
| 10324 | { }, |
| 10325 | INTERNAL | FLAG_NO_DATA, |
| 10326 | { }, |
| 10327 | { { 0, 1 } }, |
| 10328 | .fill_helper = bpf_fill_alu64_add_reg, |
| 10329 | .nr_testruns = NR_PATTERN_RUNS, |
| 10330 | }, |
| 10331 | { |
| 10332 | "ALU64_SUB_X: all register value magnitudes", |
| 10333 | { }, |
| 10334 | INTERNAL | FLAG_NO_DATA, |
| 10335 | { }, |
| 10336 | { { 0, 1 } }, |
| 10337 | .fill_helper = bpf_fill_alu64_sub_reg, |
| 10338 | .nr_testruns = NR_PATTERN_RUNS, |
| 10339 | }, |
| 10340 | { |
| 10341 | "ALU64_MUL_X: all register value magnitudes", |
| 10342 | { }, |
| 10343 | INTERNAL | FLAG_NO_DATA, |
| 10344 | { }, |
| 10345 | { { 0, 1 } }, |
| 10346 | .fill_helper = bpf_fill_alu64_mul_reg, |
| 10347 | .nr_testruns = NR_PATTERN_RUNS, |
| 10348 | }, |
| 10349 | { |
| 10350 | "ALU64_DIV_X: all register value magnitudes", |
| 10351 | { }, |
| 10352 | INTERNAL | FLAG_NO_DATA, |
| 10353 | { }, |
| 10354 | { { 0, 1 } }, |
| 10355 | .fill_helper = bpf_fill_alu64_div_reg, |
| 10356 | .nr_testruns = NR_PATTERN_RUNS, |
| 10357 | }, |
| 10358 | { |
| 10359 | "ALU64_MOD_X: all register value magnitudes", |
| 10360 | { }, |
| 10361 | INTERNAL | FLAG_NO_DATA, |
| 10362 | { }, |
| 10363 | { { 0, 1 } }, |
| 10364 | .fill_helper = bpf_fill_alu64_mod_reg, |
| 10365 | .nr_testruns = NR_PATTERN_RUNS, |
| 10366 | }, |
| 10367 | /* ALU32 register magnitudes */ |
| 10368 | { |
| 10369 | "ALU32_MOV_X: all register value magnitudes", |
| 10370 | { }, |
| 10371 | INTERNAL | FLAG_NO_DATA, |
| 10372 | { }, |
| 10373 | { { 0, 1 } }, |
| 10374 | .fill_helper = bpf_fill_alu32_mov_reg, |
| 10375 | .nr_testruns = NR_PATTERN_RUNS, |
| 10376 | }, |
| 10377 | { |
| 10378 | "ALU32_AND_X: all register value magnitudes", |
| 10379 | { }, |
| 10380 | INTERNAL | FLAG_NO_DATA, |
| 10381 | { }, |
| 10382 | { { 0, 1 } }, |
| 10383 | .fill_helper = bpf_fill_alu32_and_reg, |
| 10384 | .nr_testruns = NR_PATTERN_RUNS, |
| 10385 | }, |
| 10386 | { |
| 10387 | "ALU32_OR_X: all register value magnitudes", |
| 10388 | { }, |
| 10389 | INTERNAL | FLAG_NO_DATA, |
| 10390 | { }, |
| 10391 | { { 0, 1 } }, |
| 10392 | .fill_helper = bpf_fill_alu32_or_reg, |
| 10393 | .nr_testruns = NR_PATTERN_RUNS, |
| 10394 | }, |
| 10395 | { |
| 10396 | "ALU32_XOR_X: all register value magnitudes", |
| 10397 | { }, |
| 10398 | INTERNAL | FLAG_NO_DATA, |
| 10399 | { }, |
| 10400 | { { 0, 1 } }, |
| 10401 | .fill_helper = bpf_fill_alu32_xor_reg, |
| 10402 | .nr_testruns = NR_PATTERN_RUNS, |
| 10403 | }, |
| 10404 | { |
| 10405 | "ALU32_ADD_X: all register value magnitudes", |
| 10406 | { }, |
| 10407 | INTERNAL | FLAG_NO_DATA, |
| 10408 | { }, |
| 10409 | { { 0, 1 } }, |
| 10410 | .fill_helper = bpf_fill_alu32_add_reg, |
| 10411 | .nr_testruns = NR_PATTERN_RUNS, |
| 10412 | }, |
| 10413 | { |
| 10414 | "ALU32_SUB_X: all register value magnitudes", |
| 10415 | { }, |
| 10416 | INTERNAL | FLAG_NO_DATA, |
| 10417 | { }, |
| 10418 | { { 0, 1 } }, |
| 10419 | .fill_helper = bpf_fill_alu32_sub_reg, |
| 10420 | .nr_testruns = NR_PATTERN_RUNS, |
| 10421 | }, |
| 10422 | { |
| 10423 | "ALU32_MUL_X: all register value magnitudes", |
| 10424 | { }, |
| 10425 | INTERNAL | FLAG_NO_DATA, |
| 10426 | { }, |
| 10427 | { { 0, 1 } }, |
| 10428 | .fill_helper = bpf_fill_alu32_mul_reg, |
| 10429 | .nr_testruns = NR_PATTERN_RUNS, |
| 10430 | }, |
| 10431 | { |
| 10432 | "ALU32_DIV_X: all register value magnitudes", |
| 10433 | { }, |
| 10434 | INTERNAL | FLAG_NO_DATA, |
| 10435 | { }, |
| 10436 | { { 0, 1 } }, |
| 10437 | .fill_helper = bpf_fill_alu32_div_reg, |
| 10438 | .nr_testruns = NR_PATTERN_RUNS, |
| 10439 | }, |
| 10440 | { |
| 10441 | "ALU32_MOD_X: all register value magnitudes", |
| 10442 | { }, |
| 10443 | INTERNAL | FLAG_NO_DATA, |
| 10444 | { }, |
| 10445 | { { 0, 1 } }, |
| 10446 | .fill_helper = bpf_fill_alu32_mod_reg, |
| 10447 | .nr_testruns = NR_PATTERN_RUNS, |
| 10448 | }, |
Johan Almbladh | 2e80761 | 2021-09-14 11:18:35 +0200 | [diff] [blame] | 10449 | /* LD_IMM64 immediate magnitudes */ |
| 10450 | { |
| 10451 | "LD_IMM64: all immediate value magnitudes", |
| 10452 | { }, |
| 10453 | INTERNAL | FLAG_NO_DATA, |
| 10454 | { }, |
| 10455 | { { 0, 1 } }, |
| 10456 | .fill_helper = bpf_fill_ld_imm64, |
| 10457 | }, |
Johan Almbladh | a5a3654 | 2021-09-14 11:18:33 +0200 | [diff] [blame] | 10458 | /* JMP immediate magnitudes */ |
| 10459 | { |
| 10460 | "JMP_JSET_K: all immediate value magnitudes", |
| 10461 | { }, |
| 10462 | INTERNAL | FLAG_NO_DATA, |
| 10463 | { }, |
| 10464 | { { 0, 1 } }, |
| 10465 | .fill_helper = bpf_fill_jmp_jset_imm, |
| 10466 | .nr_testruns = NR_PATTERN_RUNS, |
| 10467 | }, |
| 10468 | { |
| 10469 | "JMP_JEQ_K: all immediate value magnitudes", |
| 10470 | { }, |
| 10471 | INTERNAL | FLAG_NO_DATA, |
| 10472 | { }, |
| 10473 | { { 0, 1 } }, |
| 10474 | .fill_helper = bpf_fill_jmp_jeq_imm, |
| 10475 | .nr_testruns = NR_PATTERN_RUNS, |
| 10476 | }, |
| 10477 | { |
| 10478 | "JMP_JNE_K: all immediate value magnitudes", |
| 10479 | { }, |
| 10480 | INTERNAL | FLAG_NO_DATA, |
| 10481 | { }, |
| 10482 | { { 0, 1 } }, |
| 10483 | .fill_helper = bpf_fill_jmp_jne_imm, |
| 10484 | .nr_testruns = NR_PATTERN_RUNS, |
| 10485 | }, |
| 10486 | { |
| 10487 | "JMP_JGT_K: all immediate value magnitudes", |
| 10488 | { }, |
| 10489 | INTERNAL | FLAG_NO_DATA, |
| 10490 | { }, |
| 10491 | { { 0, 1 } }, |
| 10492 | .fill_helper = bpf_fill_jmp_jgt_imm, |
| 10493 | .nr_testruns = NR_PATTERN_RUNS, |
| 10494 | }, |
| 10495 | { |
| 10496 | "JMP_JGE_K: all immediate value magnitudes", |
| 10497 | { }, |
| 10498 | INTERNAL | FLAG_NO_DATA, |
| 10499 | { }, |
| 10500 | { { 0, 1 } }, |
| 10501 | .fill_helper = bpf_fill_jmp_jge_imm, |
| 10502 | .nr_testruns = NR_PATTERN_RUNS, |
| 10503 | }, |
| 10504 | { |
| 10505 | "JMP_JLT_K: all immediate value magnitudes", |
| 10506 | { }, |
| 10507 | INTERNAL | FLAG_NO_DATA, |
| 10508 | { }, |
| 10509 | { { 0, 1 } }, |
| 10510 | .fill_helper = bpf_fill_jmp_jlt_imm, |
| 10511 | .nr_testruns = NR_PATTERN_RUNS, |
| 10512 | }, |
| 10513 | { |
| 10514 | "JMP_JLE_K: all immediate value magnitudes", |
| 10515 | { }, |
| 10516 | INTERNAL | FLAG_NO_DATA, |
| 10517 | { }, |
| 10518 | { { 0, 1 } }, |
| 10519 | .fill_helper = bpf_fill_jmp_jle_imm, |
| 10520 | .nr_testruns = NR_PATTERN_RUNS, |
| 10521 | }, |
| 10522 | { |
| 10523 | "JMP_JSGT_K: all immediate value magnitudes", |
| 10524 | { }, |
| 10525 | INTERNAL | FLAG_NO_DATA, |
| 10526 | { }, |
| 10527 | { { 0, 1 } }, |
| 10528 | .fill_helper = bpf_fill_jmp_jsgt_imm, |
| 10529 | .nr_testruns = NR_PATTERN_RUNS, |
| 10530 | }, |
| 10531 | { |
| 10532 | "JMP_JSGE_K: all immediate value magnitudes", |
| 10533 | { }, |
| 10534 | INTERNAL | FLAG_NO_DATA, |
| 10535 | { }, |
| 10536 | { { 0, 1 } }, |
| 10537 | .fill_helper = bpf_fill_jmp_jsge_imm, |
| 10538 | .nr_testruns = NR_PATTERN_RUNS, |
| 10539 | }, |
| 10540 | { |
| 10541 | "JMP_JSLT_K: all immediate value magnitudes", |
| 10542 | { }, |
| 10543 | INTERNAL | FLAG_NO_DATA, |
| 10544 | { }, |
| 10545 | { { 0, 1 } }, |
| 10546 | .fill_helper = bpf_fill_jmp_jslt_imm, |
| 10547 | .nr_testruns = NR_PATTERN_RUNS, |
| 10548 | }, |
| 10549 | { |
| 10550 | "JMP_JSLE_K: all immediate value magnitudes", |
| 10551 | { }, |
| 10552 | INTERNAL | FLAG_NO_DATA, |
| 10553 | { }, |
| 10554 | { { 0, 1 } }, |
| 10555 | .fill_helper = bpf_fill_jmp_jsle_imm, |
| 10556 | .nr_testruns = NR_PATTERN_RUNS, |
| 10557 | }, |
| 10558 | /* JMP register magnitudes */ |
| 10559 | { |
| 10560 | "JMP_JSET_X: all register value magnitudes", |
| 10561 | { }, |
| 10562 | INTERNAL | FLAG_NO_DATA, |
| 10563 | { }, |
| 10564 | { { 0, 1 } }, |
| 10565 | .fill_helper = bpf_fill_jmp_jset_reg, |
| 10566 | .nr_testruns = NR_PATTERN_RUNS, |
| 10567 | }, |
| 10568 | { |
| 10569 | "JMP_JEQ_X: all register value magnitudes", |
| 10570 | { }, |
| 10571 | INTERNAL | FLAG_NO_DATA, |
| 10572 | { }, |
| 10573 | { { 0, 1 } }, |
| 10574 | .fill_helper = bpf_fill_jmp_jeq_reg, |
| 10575 | .nr_testruns = NR_PATTERN_RUNS, |
| 10576 | }, |
| 10577 | { |
| 10578 | "JMP_JNE_X: all register value magnitudes", |
| 10579 | { }, |
| 10580 | INTERNAL | FLAG_NO_DATA, |
| 10581 | { }, |
| 10582 | { { 0, 1 } }, |
| 10583 | .fill_helper = bpf_fill_jmp_jne_reg, |
| 10584 | .nr_testruns = NR_PATTERN_RUNS, |
| 10585 | }, |
| 10586 | { |
| 10587 | "JMP_JGT_X: all register value magnitudes", |
| 10588 | { }, |
| 10589 | INTERNAL | FLAG_NO_DATA, |
| 10590 | { }, |
| 10591 | { { 0, 1 } }, |
| 10592 | .fill_helper = bpf_fill_jmp_jgt_reg, |
| 10593 | .nr_testruns = NR_PATTERN_RUNS, |
| 10594 | }, |
| 10595 | { |
| 10596 | "JMP_JGE_X: all register value magnitudes", |
| 10597 | { }, |
| 10598 | INTERNAL | FLAG_NO_DATA, |
| 10599 | { }, |
| 10600 | { { 0, 1 } }, |
| 10601 | .fill_helper = bpf_fill_jmp_jge_reg, |
| 10602 | .nr_testruns = NR_PATTERN_RUNS, |
| 10603 | }, |
| 10604 | { |
| 10605 | "JMP_JLT_X: all register value magnitudes", |
| 10606 | { }, |
| 10607 | INTERNAL | FLAG_NO_DATA, |
| 10608 | { }, |
| 10609 | { { 0, 1 } }, |
| 10610 | .fill_helper = bpf_fill_jmp_jlt_reg, |
| 10611 | .nr_testruns = NR_PATTERN_RUNS, |
| 10612 | }, |
| 10613 | { |
| 10614 | "JMP_JLE_X: all register value magnitudes", |
| 10615 | { }, |
| 10616 | INTERNAL | FLAG_NO_DATA, |
| 10617 | { }, |
| 10618 | { { 0, 1 } }, |
| 10619 | .fill_helper = bpf_fill_jmp_jle_reg, |
| 10620 | .nr_testruns = NR_PATTERN_RUNS, |
| 10621 | }, |
| 10622 | { |
| 10623 | "JMP_JSGT_X: all register value magnitudes", |
| 10624 | { }, |
| 10625 | INTERNAL | FLAG_NO_DATA, |
| 10626 | { }, |
| 10627 | { { 0, 1 } }, |
| 10628 | .fill_helper = bpf_fill_jmp_jsgt_reg, |
| 10629 | .nr_testruns = NR_PATTERN_RUNS, |
| 10630 | }, |
| 10631 | { |
| 10632 | "JMP_JSGE_X: all register value magnitudes", |
| 10633 | { }, |
| 10634 | INTERNAL | FLAG_NO_DATA, |
| 10635 | { }, |
| 10636 | { { 0, 1 } }, |
| 10637 | .fill_helper = bpf_fill_jmp_jsge_reg, |
| 10638 | .nr_testruns = NR_PATTERN_RUNS, |
| 10639 | }, |
| 10640 | { |
| 10641 | "JMP_JSLT_X: all register value magnitudes", |
| 10642 | { }, |
| 10643 | INTERNAL | FLAG_NO_DATA, |
| 10644 | { }, |
| 10645 | { { 0, 1 } }, |
| 10646 | .fill_helper = bpf_fill_jmp_jslt_reg, |
| 10647 | .nr_testruns = NR_PATTERN_RUNS, |
| 10648 | }, |
| 10649 | { |
| 10650 | "JMP_JSLE_X: all register value magnitudes", |
| 10651 | { }, |
| 10652 | INTERNAL | FLAG_NO_DATA, |
| 10653 | { }, |
| 10654 | { { 0, 1 } }, |
| 10655 | .fill_helper = bpf_fill_jmp_jsle_reg, |
| 10656 | .nr_testruns = NR_PATTERN_RUNS, |
| 10657 | }, |
| 10658 | /* JMP32 immediate magnitudes */ |
| 10659 | { |
| 10660 | "JMP32_JSET_K: all immediate value magnitudes", |
| 10661 | { }, |
| 10662 | INTERNAL | FLAG_NO_DATA, |
| 10663 | { }, |
| 10664 | { { 0, 1 } }, |
| 10665 | .fill_helper = bpf_fill_jmp32_jset_imm, |
| 10666 | .nr_testruns = NR_PATTERN_RUNS, |
| 10667 | }, |
| 10668 | { |
| 10669 | "JMP32_JEQ_K: all immediate value magnitudes", |
| 10670 | { }, |
| 10671 | INTERNAL | FLAG_NO_DATA, |
| 10672 | { }, |
| 10673 | { { 0, 1 } }, |
| 10674 | .fill_helper = bpf_fill_jmp32_jeq_imm, |
| 10675 | .nr_testruns = NR_PATTERN_RUNS, |
| 10676 | }, |
| 10677 | { |
| 10678 | "JMP32_JNE_K: all immediate value magnitudes", |
| 10679 | { }, |
| 10680 | INTERNAL | FLAG_NO_DATA, |
| 10681 | { }, |
| 10682 | { { 0, 1 } }, |
| 10683 | .fill_helper = bpf_fill_jmp32_jne_imm, |
| 10684 | .nr_testruns = NR_PATTERN_RUNS, |
| 10685 | }, |
| 10686 | { |
| 10687 | "JMP32_JGT_K: all immediate value magnitudes", |
| 10688 | { }, |
| 10689 | INTERNAL | FLAG_NO_DATA, |
| 10690 | { }, |
| 10691 | { { 0, 1 } }, |
| 10692 | .fill_helper = bpf_fill_jmp32_jgt_imm, |
| 10693 | .nr_testruns = NR_PATTERN_RUNS, |
| 10694 | }, |
| 10695 | { |
| 10696 | "JMP32_JGE_K: all immediate value magnitudes", |
| 10697 | { }, |
| 10698 | INTERNAL | FLAG_NO_DATA, |
| 10699 | { }, |
| 10700 | { { 0, 1 } }, |
| 10701 | .fill_helper = bpf_fill_jmp32_jge_imm, |
| 10702 | .nr_testruns = NR_PATTERN_RUNS, |
| 10703 | }, |
| 10704 | { |
| 10705 | "JMP32_JLT_K: all immediate value magnitudes", |
| 10706 | { }, |
| 10707 | INTERNAL | FLAG_NO_DATA, |
| 10708 | { }, |
| 10709 | { { 0, 1 } }, |
| 10710 | .fill_helper = bpf_fill_jmp32_jlt_imm, |
| 10711 | .nr_testruns = NR_PATTERN_RUNS, |
| 10712 | }, |
| 10713 | { |
| 10714 | "JMP32_JLE_K: all immediate value magnitudes", |
| 10715 | { }, |
| 10716 | INTERNAL | FLAG_NO_DATA, |
| 10717 | { }, |
| 10718 | { { 0, 1 } }, |
| 10719 | .fill_helper = bpf_fill_jmp32_jle_imm, |
| 10720 | .nr_testruns = NR_PATTERN_RUNS, |
| 10721 | }, |
| 10722 | { |
| 10723 | "JMP32_JSGT_K: all immediate value magnitudes", |
| 10724 | { }, |
| 10725 | INTERNAL | FLAG_NO_DATA, |
| 10726 | { }, |
| 10727 | { { 0, 1 } }, |
| 10728 | .fill_helper = bpf_fill_jmp32_jsgt_imm, |
| 10729 | .nr_testruns = NR_PATTERN_RUNS, |
| 10730 | }, |
| 10731 | { |
| 10732 | "JMP32_JSGE_K: all immediate value magnitudes", |
| 10733 | { }, |
| 10734 | INTERNAL | FLAG_NO_DATA, |
| 10735 | { }, |
| 10736 | { { 0, 1 } }, |
| 10737 | .fill_helper = bpf_fill_jmp32_jsge_imm, |
| 10738 | .nr_testruns = NR_PATTERN_RUNS, |
| 10739 | }, |
| 10740 | { |
| 10741 | "JMP32_JSLT_K: all immediate value magnitudes", |
| 10742 | { }, |
| 10743 | INTERNAL | FLAG_NO_DATA, |
| 10744 | { }, |
| 10745 | { { 0, 1 } }, |
| 10746 | .fill_helper = bpf_fill_jmp32_jslt_imm, |
| 10747 | .nr_testruns = NR_PATTERN_RUNS, |
| 10748 | }, |
| 10749 | { |
| 10750 | "JMP32_JSLE_K: all immediate value magnitudes", |
| 10751 | { }, |
| 10752 | INTERNAL | FLAG_NO_DATA, |
| 10753 | { }, |
| 10754 | { { 0, 1 } }, |
| 10755 | .fill_helper = bpf_fill_jmp32_jsle_imm, |
| 10756 | .nr_testruns = NR_PATTERN_RUNS, |
| 10757 | }, |
| 10758 | /* JMP32 register magnitudes */ |
| 10759 | { |
| 10760 | "JMP32_JSET_X: all register value magnitudes", |
| 10761 | { }, |
| 10762 | INTERNAL | FLAG_NO_DATA, |
| 10763 | { }, |
| 10764 | { { 0, 1 } }, |
| 10765 | .fill_helper = bpf_fill_jmp32_jset_reg, |
| 10766 | .nr_testruns = NR_PATTERN_RUNS, |
| 10767 | }, |
| 10768 | { |
| 10769 | "JMP32_JEQ_X: all register value magnitudes", |
| 10770 | { }, |
| 10771 | INTERNAL | FLAG_NO_DATA, |
| 10772 | { }, |
| 10773 | { { 0, 1 } }, |
| 10774 | .fill_helper = bpf_fill_jmp32_jeq_reg, |
| 10775 | .nr_testruns = NR_PATTERN_RUNS, |
| 10776 | }, |
| 10777 | { |
| 10778 | "JMP32_JNE_X: all register value magnitudes", |
| 10779 | { }, |
| 10780 | INTERNAL | FLAG_NO_DATA, |
| 10781 | { }, |
| 10782 | { { 0, 1 } }, |
| 10783 | .fill_helper = bpf_fill_jmp32_jne_reg, |
| 10784 | .nr_testruns = NR_PATTERN_RUNS, |
| 10785 | }, |
| 10786 | { |
| 10787 | "JMP32_JGT_X: all register value magnitudes", |
| 10788 | { }, |
| 10789 | INTERNAL | FLAG_NO_DATA, |
| 10790 | { }, |
| 10791 | { { 0, 1 } }, |
| 10792 | .fill_helper = bpf_fill_jmp32_jgt_reg, |
| 10793 | .nr_testruns = NR_PATTERN_RUNS, |
| 10794 | }, |
| 10795 | { |
| 10796 | "JMP32_JGE_X: all register value magnitudes", |
| 10797 | { }, |
| 10798 | INTERNAL | FLAG_NO_DATA, |
| 10799 | { }, |
| 10800 | { { 0, 1 } }, |
| 10801 | .fill_helper = bpf_fill_jmp32_jge_reg, |
| 10802 | .nr_testruns = NR_PATTERN_RUNS, |
| 10803 | }, |
| 10804 | { |
| 10805 | "JMP32_JLT_X: all register value magnitudes", |
| 10806 | { }, |
| 10807 | INTERNAL | FLAG_NO_DATA, |
| 10808 | { }, |
| 10809 | { { 0, 1 } }, |
| 10810 | .fill_helper = bpf_fill_jmp32_jlt_reg, |
| 10811 | .nr_testruns = NR_PATTERN_RUNS, |
| 10812 | }, |
| 10813 | { |
| 10814 | "JMP32_JLE_X: all register value magnitudes", |
| 10815 | { }, |
| 10816 | INTERNAL | FLAG_NO_DATA, |
| 10817 | { }, |
| 10818 | { { 0, 1 } }, |
| 10819 | .fill_helper = bpf_fill_jmp32_jle_reg, |
| 10820 | .nr_testruns = NR_PATTERN_RUNS, |
| 10821 | }, |
| 10822 | { |
| 10823 | "JMP32_JSGT_X: all register value magnitudes", |
| 10824 | { }, |
| 10825 | INTERNAL | FLAG_NO_DATA, |
| 10826 | { }, |
| 10827 | { { 0, 1 } }, |
| 10828 | .fill_helper = bpf_fill_jmp32_jsgt_reg, |
| 10829 | .nr_testruns = NR_PATTERN_RUNS, |
| 10830 | }, |
| 10831 | { |
| 10832 | "JMP32_JSGE_X: all register value magnitudes", |
| 10833 | { }, |
| 10834 | INTERNAL | FLAG_NO_DATA, |
| 10835 | { }, |
| 10836 | { { 0, 1 } }, |
| 10837 | .fill_helper = bpf_fill_jmp32_jsge_reg, |
| 10838 | .nr_testruns = NR_PATTERN_RUNS, |
| 10839 | }, |
| 10840 | { |
| 10841 | "JMP32_JSLT_X: all register value magnitudes", |
| 10842 | { }, |
| 10843 | INTERNAL | FLAG_NO_DATA, |
| 10844 | { }, |
| 10845 | { { 0, 1 } }, |
| 10846 | .fill_helper = bpf_fill_jmp32_jslt_reg, |
| 10847 | .nr_testruns = NR_PATTERN_RUNS, |
| 10848 | }, |
| 10849 | { |
| 10850 | "JMP32_JSLE_X: all register value magnitudes", |
| 10851 | { }, |
| 10852 | INTERNAL | FLAG_NO_DATA, |
| 10853 | { }, |
| 10854 | { { 0, 1 } }, |
| 10855 | .fill_helper = bpf_fill_jmp32_jsle_reg, |
| 10856 | .nr_testruns = NR_PATTERN_RUNS, |
| 10857 | }, |
Johan Almbladh | c4df455 | 2021-09-14 11:18:38 +0200 | [diff] [blame] | 10858 | /* Conditional jumps with constant decision */ |
| 10859 | { |
| 10860 | "JMP_JSET_K: imm = 0 -> never taken", |
| 10861 | .u.insns_int = { |
| 10862 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10863 | BPF_JMP_IMM(BPF_JSET, R1, 0, 1), |
| 10864 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10865 | BPF_EXIT_INSN(), |
| 10866 | }, |
| 10867 | INTERNAL | FLAG_NO_DATA, |
| 10868 | { }, |
| 10869 | { { 0, 0 } }, |
| 10870 | }, |
| 10871 | { |
| 10872 | "JMP_JLT_K: imm = 0 -> never taken", |
| 10873 | .u.insns_int = { |
| 10874 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10875 | BPF_JMP_IMM(BPF_JLT, R1, 0, 1), |
| 10876 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10877 | BPF_EXIT_INSN(), |
| 10878 | }, |
| 10879 | INTERNAL | FLAG_NO_DATA, |
| 10880 | { }, |
| 10881 | { { 0, 0 } }, |
| 10882 | }, |
| 10883 | { |
| 10884 | "JMP_JGE_K: imm = 0 -> always taken", |
| 10885 | .u.insns_int = { |
| 10886 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10887 | BPF_JMP_IMM(BPF_JGE, R1, 0, 1), |
| 10888 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10889 | BPF_EXIT_INSN(), |
| 10890 | }, |
| 10891 | INTERNAL | FLAG_NO_DATA, |
| 10892 | { }, |
| 10893 | { { 0, 1 } }, |
| 10894 | }, |
| 10895 | { |
| 10896 | "JMP_JGT_K: imm = 0xffffffff -> never taken", |
| 10897 | .u.insns_int = { |
| 10898 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10899 | BPF_JMP_IMM(BPF_JGT, R1, U32_MAX, 1), |
| 10900 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10901 | BPF_EXIT_INSN(), |
| 10902 | }, |
| 10903 | INTERNAL | FLAG_NO_DATA, |
| 10904 | { }, |
| 10905 | { { 0, 0 } }, |
| 10906 | }, |
| 10907 | { |
| 10908 | "JMP_JLE_K: imm = 0xffffffff -> always taken", |
| 10909 | .u.insns_int = { |
| 10910 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10911 | BPF_JMP_IMM(BPF_JLE, R1, U32_MAX, 1), |
| 10912 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10913 | BPF_EXIT_INSN(), |
| 10914 | }, |
| 10915 | INTERNAL | FLAG_NO_DATA, |
| 10916 | { }, |
| 10917 | { { 0, 1 } }, |
| 10918 | }, |
| 10919 | { |
| 10920 | "JMP32_JSGT_K: imm = 0x7fffffff -> never taken", |
| 10921 | .u.insns_int = { |
| 10922 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10923 | BPF_JMP32_IMM(BPF_JSGT, R1, S32_MAX, 1), |
| 10924 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10925 | BPF_EXIT_INSN(), |
| 10926 | }, |
| 10927 | INTERNAL | FLAG_NO_DATA, |
| 10928 | { }, |
| 10929 | { { 0, 0 } }, |
| 10930 | }, |
| 10931 | { |
| 10932 | "JMP32_JSGE_K: imm = -0x80000000 -> always taken", |
| 10933 | .u.insns_int = { |
| 10934 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10935 | BPF_JMP32_IMM(BPF_JSGE, R1, S32_MIN, 1), |
| 10936 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10937 | BPF_EXIT_INSN(), |
| 10938 | }, |
| 10939 | INTERNAL | FLAG_NO_DATA, |
| 10940 | { }, |
| 10941 | { { 0, 1 } }, |
| 10942 | }, |
| 10943 | { |
| 10944 | "JMP32_JSLT_K: imm = -0x80000000 -> never taken", |
| 10945 | .u.insns_int = { |
| 10946 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10947 | BPF_JMP32_IMM(BPF_JSLT, R1, S32_MIN, 1), |
| 10948 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10949 | BPF_EXIT_INSN(), |
| 10950 | }, |
| 10951 | INTERNAL | FLAG_NO_DATA, |
| 10952 | { }, |
| 10953 | { { 0, 0 } }, |
| 10954 | }, |
| 10955 | { |
| 10956 | "JMP32_JSLE_K: imm = 0x7fffffff -> always taken", |
| 10957 | .u.insns_int = { |
| 10958 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10959 | BPF_JMP32_IMM(BPF_JSLE, R1, S32_MAX, 1), |
| 10960 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10961 | BPF_EXIT_INSN(), |
| 10962 | }, |
| 10963 | INTERNAL | FLAG_NO_DATA, |
| 10964 | { }, |
| 10965 | { { 0, 1 } }, |
| 10966 | }, |
| 10967 | { |
| 10968 | "JMP_JEQ_X: dst = src -> always taken", |
| 10969 | .u.insns_int = { |
| 10970 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10971 | BPF_JMP_REG(BPF_JEQ, R1, R1, 1), |
| 10972 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10973 | BPF_EXIT_INSN(), |
| 10974 | }, |
| 10975 | INTERNAL | FLAG_NO_DATA, |
| 10976 | { }, |
| 10977 | { { 0, 1 } }, |
| 10978 | }, |
| 10979 | { |
| 10980 | "JMP_JGE_X: dst = src -> always taken", |
| 10981 | .u.insns_int = { |
| 10982 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10983 | BPF_JMP_REG(BPF_JGE, R1, R1, 1), |
| 10984 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10985 | BPF_EXIT_INSN(), |
| 10986 | }, |
| 10987 | INTERNAL | FLAG_NO_DATA, |
| 10988 | { }, |
| 10989 | { { 0, 1 } }, |
| 10990 | }, |
| 10991 | { |
| 10992 | "JMP_JLE_X: dst = src -> always taken", |
| 10993 | .u.insns_int = { |
| 10994 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 10995 | BPF_JMP_REG(BPF_JLE, R1, R1, 1), |
| 10996 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 10997 | BPF_EXIT_INSN(), |
| 10998 | }, |
| 10999 | INTERNAL | FLAG_NO_DATA, |
| 11000 | { }, |
| 11001 | { { 0, 1 } }, |
| 11002 | }, |
| 11003 | { |
| 11004 | "JMP_JSGE_X: dst = src -> always taken", |
| 11005 | .u.insns_int = { |
| 11006 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11007 | BPF_JMP_REG(BPF_JSGE, R1, R1, 1), |
| 11008 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11009 | BPF_EXIT_INSN(), |
| 11010 | }, |
| 11011 | INTERNAL | FLAG_NO_DATA, |
| 11012 | { }, |
| 11013 | { { 0, 1 } }, |
| 11014 | }, |
| 11015 | { |
| 11016 | "JMP_JSLE_X: dst = src -> always taken", |
| 11017 | .u.insns_int = { |
| 11018 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11019 | BPF_JMP_REG(BPF_JSLE, R1, R1, 1), |
| 11020 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11021 | BPF_EXIT_INSN(), |
| 11022 | }, |
| 11023 | INTERNAL | FLAG_NO_DATA, |
| 11024 | { }, |
| 11025 | { { 0, 1 } }, |
| 11026 | }, |
| 11027 | { |
| 11028 | "JMP_JNE_X: dst = src -> never taken", |
| 11029 | .u.insns_int = { |
| 11030 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11031 | BPF_JMP_REG(BPF_JNE, R1, R1, 1), |
| 11032 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11033 | BPF_EXIT_INSN(), |
| 11034 | }, |
| 11035 | INTERNAL | FLAG_NO_DATA, |
| 11036 | { }, |
| 11037 | { { 0, 0 } }, |
| 11038 | }, |
| 11039 | { |
| 11040 | "JMP_JGT_X: dst = src -> never taken", |
| 11041 | .u.insns_int = { |
| 11042 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11043 | BPF_JMP_REG(BPF_JGT, R1, R1, 1), |
| 11044 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11045 | BPF_EXIT_INSN(), |
| 11046 | }, |
| 11047 | INTERNAL | FLAG_NO_DATA, |
| 11048 | { }, |
| 11049 | { { 0, 0 } }, |
| 11050 | }, |
| 11051 | { |
| 11052 | "JMP_JLT_X: dst = src -> never taken", |
| 11053 | .u.insns_int = { |
| 11054 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11055 | BPF_JMP_REG(BPF_JLT, R1, R1, 1), |
| 11056 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11057 | BPF_EXIT_INSN(), |
| 11058 | }, |
| 11059 | INTERNAL | FLAG_NO_DATA, |
| 11060 | { }, |
| 11061 | { { 0, 0 } }, |
| 11062 | }, |
| 11063 | { |
| 11064 | "JMP_JSGT_X: dst = src -> never taken", |
| 11065 | .u.insns_int = { |
| 11066 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11067 | BPF_JMP_REG(BPF_JSGT, R1, R1, 1), |
| 11068 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11069 | BPF_EXIT_INSN(), |
| 11070 | }, |
| 11071 | INTERNAL | FLAG_NO_DATA, |
| 11072 | { }, |
| 11073 | { { 0, 0 } }, |
| 11074 | }, |
| 11075 | { |
| 11076 | "JMP_JSLT_X: dst = src -> never taken", |
| 11077 | .u.insns_int = { |
| 11078 | BPF_ALU64_IMM(BPF_MOV, R0, 1), |
| 11079 | BPF_JMP_REG(BPF_JSLT, R1, R1, 1), |
| 11080 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11081 | BPF_EXIT_INSN(), |
| 11082 | }, |
| 11083 | INTERNAL | FLAG_NO_DATA, |
| 11084 | { }, |
| 11085 | { { 0, 0 } }, |
| 11086 | }, |
Johan Almbladh | d4ff9ee | 2021-09-14 11:18:37 +0200 | [diff] [blame] | 11087 | /* Short relative jumps */ |
| 11088 | { |
| 11089 | "Short relative jump: offset=0", |
| 11090 | .u.insns_int = { |
| 11091 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11092 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 0), |
| 11093 | BPF_EXIT_INSN(), |
| 11094 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 11095 | }, |
| 11096 | INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT, |
| 11097 | { }, |
| 11098 | { { 0, 0 } }, |
| 11099 | }, |
| 11100 | { |
| 11101 | "Short relative jump: offset=1", |
| 11102 | .u.insns_int = { |
| 11103 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11104 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 1), |
| 11105 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11106 | BPF_EXIT_INSN(), |
| 11107 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 11108 | }, |
| 11109 | INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT, |
| 11110 | { }, |
| 11111 | { { 0, 0 } }, |
| 11112 | }, |
| 11113 | { |
| 11114 | "Short relative jump: offset=2", |
| 11115 | .u.insns_int = { |
| 11116 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11117 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 2), |
| 11118 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11119 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11120 | BPF_EXIT_INSN(), |
| 11121 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 11122 | }, |
| 11123 | INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT, |
| 11124 | { }, |
| 11125 | { { 0, 0 } }, |
| 11126 | }, |
| 11127 | { |
| 11128 | "Short relative jump: offset=3", |
| 11129 | .u.insns_int = { |
| 11130 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11131 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 3), |
| 11132 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11133 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11134 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11135 | BPF_EXIT_INSN(), |
| 11136 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 11137 | }, |
| 11138 | INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT, |
| 11139 | { }, |
| 11140 | { { 0, 0 } }, |
| 11141 | }, |
| 11142 | { |
| 11143 | "Short relative jump: offset=4", |
| 11144 | .u.insns_int = { |
| 11145 | BPF_ALU64_IMM(BPF_MOV, R0, 0), |
| 11146 | BPF_JMP_IMM(BPF_JEQ, R0, 0, 4), |
| 11147 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11148 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11149 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11150 | BPF_ALU32_IMM(BPF_ADD, R0, 1), |
| 11151 | BPF_EXIT_INSN(), |
| 11152 | BPF_ALU32_IMM(BPF_MOV, R0, -1), |
| 11153 | }, |
| 11154 | INTERNAL | FLAG_NO_DATA | FLAG_VERIFIER_ZEXT, |
| 11155 | { }, |
| 11156 | { { 0, 0 } }, |
| 11157 | }, |
Johan Almbladh | f1517eb | 2021-09-14 11:18:39 +0200 | [diff] [blame] | 11158 | /* Conditional branch conversions */ |
| 11159 | { |
| 11160 | "Long conditional jump: taken at runtime", |
| 11161 | { }, |
| 11162 | INTERNAL | FLAG_NO_DATA, |
| 11163 | { }, |
| 11164 | { { 0, 1 } }, |
| 11165 | .fill_helper = bpf_fill_max_jmp_taken, |
| 11166 | }, |
| 11167 | { |
| 11168 | "Long conditional jump: not taken at runtime", |
| 11169 | { }, |
| 11170 | INTERNAL | FLAG_NO_DATA, |
| 11171 | { }, |
| 11172 | { { 0, 2 } }, |
| 11173 | .fill_helper = bpf_fill_max_jmp_not_taken, |
| 11174 | }, |
| 11175 | { |
| 11176 | "Long conditional jump: always taken, known at JIT time", |
| 11177 | { }, |
| 11178 | INTERNAL | FLAG_NO_DATA, |
| 11179 | { }, |
| 11180 | { { 0, 1 } }, |
| 11181 | .fill_helper = bpf_fill_max_jmp_always_taken, |
| 11182 | }, |
| 11183 | { |
| 11184 | "Long conditional jump: never taken, known at JIT time", |
| 11185 | { }, |
| 11186 | INTERNAL | FLAG_NO_DATA, |
| 11187 | { }, |
| 11188 | { { 0, 2 } }, |
| 11189 | .fill_helper = bpf_fill_max_jmp_never_taken, |
| 11190 | }, |
Johan Almbladh | a7d2e75 | 2021-09-14 11:18:34 +0200 | [diff] [blame] | 11191 | /* Staggered jump sequences, immediate */ |
| 11192 | { |
| 11193 | "Staggered jumps: JMP_JA", |
| 11194 | { }, |
| 11195 | INTERNAL | FLAG_NO_DATA, |
| 11196 | { }, |
| 11197 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11198 | .fill_helper = bpf_fill_staggered_ja, |
| 11199 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11200 | }, |
| 11201 | { |
| 11202 | "Staggered jumps: JMP_JEQ_K", |
| 11203 | { }, |
| 11204 | INTERNAL | FLAG_NO_DATA, |
| 11205 | { }, |
| 11206 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11207 | .fill_helper = bpf_fill_staggered_jeq_imm, |
| 11208 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11209 | }, |
| 11210 | { |
| 11211 | "Staggered jumps: JMP_JNE_K", |
| 11212 | { }, |
| 11213 | INTERNAL | FLAG_NO_DATA, |
| 11214 | { }, |
| 11215 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11216 | .fill_helper = bpf_fill_staggered_jne_imm, |
| 11217 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11218 | }, |
| 11219 | { |
| 11220 | "Staggered jumps: JMP_JSET_K", |
| 11221 | { }, |
| 11222 | INTERNAL | FLAG_NO_DATA, |
| 11223 | { }, |
| 11224 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11225 | .fill_helper = bpf_fill_staggered_jset_imm, |
| 11226 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11227 | }, |
| 11228 | { |
| 11229 | "Staggered jumps: JMP_JGT_K", |
| 11230 | { }, |
| 11231 | INTERNAL | FLAG_NO_DATA, |
| 11232 | { }, |
| 11233 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11234 | .fill_helper = bpf_fill_staggered_jgt_imm, |
| 11235 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11236 | }, |
| 11237 | { |
| 11238 | "Staggered jumps: JMP_JGE_K", |
| 11239 | { }, |
| 11240 | INTERNAL | FLAG_NO_DATA, |
| 11241 | { }, |
| 11242 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11243 | .fill_helper = bpf_fill_staggered_jge_imm, |
| 11244 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11245 | }, |
| 11246 | { |
| 11247 | "Staggered jumps: JMP_JLT_K", |
| 11248 | { }, |
| 11249 | INTERNAL | FLAG_NO_DATA, |
| 11250 | { }, |
| 11251 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11252 | .fill_helper = bpf_fill_staggered_jlt_imm, |
| 11253 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11254 | }, |
| 11255 | { |
| 11256 | "Staggered jumps: JMP_JLE_K", |
| 11257 | { }, |
| 11258 | INTERNAL | FLAG_NO_DATA, |
| 11259 | { }, |
| 11260 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11261 | .fill_helper = bpf_fill_staggered_jle_imm, |
| 11262 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11263 | }, |
| 11264 | { |
| 11265 | "Staggered jumps: JMP_JSGT_K", |
| 11266 | { }, |
| 11267 | INTERNAL | FLAG_NO_DATA, |
| 11268 | { }, |
| 11269 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11270 | .fill_helper = bpf_fill_staggered_jsgt_imm, |
| 11271 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11272 | }, |
| 11273 | { |
| 11274 | "Staggered jumps: JMP_JSGE_K", |
| 11275 | { }, |
| 11276 | INTERNAL | FLAG_NO_DATA, |
| 11277 | { }, |
| 11278 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11279 | .fill_helper = bpf_fill_staggered_jsge_imm, |
| 11280 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11281 | }, |
| 11282 | { |
| 11283 | "Staggered jumps: JMP_JSLT_K", |
| 11284 | { }, |
| 11285 | INTERNAL | FLAG_NO_DATA, |
| 11286 | { }, |
| 11287 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11288 | .fill_helper = bpf_fill_staggered_jslt_imm, |
| 11289 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11290 | }, |
| 11291 | { |
| 11292 | "Staggered jumps: JMP_JSLE_K", |
| 11293 | { }, |
| 11294 | INTERNAL | FLAG_NO_DATA, |
| 11295 | { }, |
| 11296 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11297 | .fill_helper = bpf_fill_staggered_jsle_imm, |
| 11298 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11299 | }, |
| 11300 | /* Staggered jump sequences, register */ |
| 11301 | { |
| 11302 | "Staggered jumps: JMP_JEQ_X", |
| 11303 | { }, |
| 11304 | INTERNAL | FLAG_NO_DATA, |
| 11305 | { }, |
| 11306 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11307 | .fill_helper = bpf_fill_staggered_jeq_reg, |
| 11308 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11309 | }, |
| 11310 | { |
| 11311 | "Staggered jumps: JMP_JNE_X", |
| 11312 | { }, |
| 11313 | INTERNAL | FLAG_NO_DATA, |
| 11314 | { }, |
| 11315 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11316 | .fill_helper = bpf_fill_staggered_jne_reg, |
| 11317 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11318 | }, |
| 11319 | { |
| 11320 | "Staggered jumps: JMP_JSET_X", |
| 11321 | { }, |
| 11322 | INTERNAL | FLAG_NO_DATA, |
| 11323 | { }, |
| 11324 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11325 | .fill_helper = bpf_fill_staggered_jset_reg, |
| 11326 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11327 | }, |
| 11328 | { |
| 11329 | "Staggered jumps: JMP_JGT_X", |
| 11330 | { }, |
| 11331 | INTERNAL | FLAG_NO_DATA, |
| 11332 | { }, |
| 11333 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11334 | .fill_helper = bpf_fill_staggered_jgt_reg, |
| 11335 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11336 | }, |
| 11337 | { |
| 11338 | "Staggered jumps: JMP_JGE_X", |
| 11339 | { }, |
| 11340 | INTERNAL | FLAG_NO_DATA, |
| 11341 | { }, |
| 11342 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11343 | .fill_helper = bpf_fill_staggered_jge_reg, |
| 11344 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11345 | }, |
| 11346 | { |
| 11347 | "Staggered jumps: JMP_JLT_X", |
| 11348 | { }, |
| 11349 | INTERNAL | FLAG_NO_DATA, |
| 11350 | { }, |
| 11351 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11352 | .fill_helper = bpf_fill_staggered_jlt_reg, |
| 11353 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11354 | }, |
| 11355 | { |
| 11356 | "Staggered jumps: JMP_JLE_X", |
| 11357 | { }, |
| 11358 | INTERNAL | FLAG_NO_DATA, |
| 11359 | { }, |
| 11360 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11361 | .fill_helper = bpf_fill_staggered_jle_reg, |
| 11362 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11363 | }, |
| 11364 | { |
| 11365 | "Staggered jumps: JMP_JSGT_X", |
| 11366 | { }, |
| 11367 | INTERNAL | FLAG_NO_DATA, |
| 11368 | { }, |
| 11369 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11370 | .fill_helper = bpf_fill_staggered_jsgt_reg, |
| 11371 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11372 | }, |
| 11373 | { |
| 11374 | "Staggered jumps: JMP_JSGE_X", |
| 11375 | { }, |
| 11376 | INTERNAL | FLAG_NO_DATA, |
| 11377 | { }, |
| 11378 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11379 | .fill_helper = bpf_fill_staggered_jsge_reg, |
| 11380 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11381 | }, |
| 11382 | { |
| 11383 | "Staggered jumps: JMP_JSLT_X", |
| 11384 | { }, |
| 11385 | INTERNAL | FLAG_NO_DATA, |
| 11386 | { }, |
| 11387 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11388 | .fill_helper = bpf_fill_staggered_jslt_reg, |
| 11389 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11390 | }, |
| 11391 | { |
| 11392 | "Staggered jumps: JMP_JSLE_X", |
| 11393 | { }, |
| 11394 | INTERNAL | FLAG_NO_DATA, |
| 11395 | { }, |
| 11396 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11397 | .fill_helper = bpf_fill_staggered_jsle_reg, |
| 11398 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11399 | }, |
| 11400 | /* Staggered jump sequences, JMP32 immediate */ |
| 11401 | { |
| 11402 | "Staggered jumps: JMP32_JEQ_K", |
| 11403 | { }, |
| 11404 | INTERNAL | FLAG_NO_DATA, |
| 11405 | { }, |
| 11406 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11407 | .fill_helper = bpf_fill_staggered_jeq32_imm, |
| 11408 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11409 | }, |
| 11410 | { |
| 11411 | "Staggered jumps: JMP32_JNE_K", |
| 11412 | { }, |
| 11413 | INTERNAL | FLAG_NO_DATA, |
| 11414 | { }, |
| 11415 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11416 | .fill_helper = bpf_fill_staggered_jne32_imm, |
| 11417 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11418 | }, |
| 11419 | { |
| 11420 | "Staggered jumps: JMP32_JSET_K", |
| 11421 | { }, |
| 11422 | INTERNAL | FLAG_NO_DATA, |
| 11423 | { }, |
| 11424 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11425 | .fill_helper = bpf_fill_staggered_jset32_imm, |
| 11426 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11427 | }, |
| 11428 | { |
| 11429 | "Staggered jumps: JMP32_JGT_K", |
| 11430 | { }, |
| 11431 | INTERNAL | FLAG_NO_DATA, |
| 11432 | { }, |
| 11433 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11434 | .fill_helper = bpf_fill_staggered_jgt32_imm, |
| 11435 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11436 | }, |
| 11437 | { |
| 11438 | "Staggered jumps: JMP32_JGE_K", |
| 11439 | { }, |
| 11440 | INTERNAL | FLAG_NO_DATA, |
| 11441 | { }, |
| 11442 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11443 | .fill_helper = bpf_fill_staggered_jge32_imm, |
| 11444 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11445 | }, |
| 11446 | { |
| 11447 | "Staggered jumps: JMP32_JLT_K", |
| 11448 | { }, |
| 11449 | INTERNAL | FLAG_NO_DATA, |
| 11450 | { }, |
| 11451 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11452 | .fill_helper = bpf_fill_staggered_jlt32_imm, |
| 11453 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11454 | }, |
| 11455 | { |
| 11456 | "Staggered jumps: JMP32_JLE_K", |
| 11457 | { }, |
| 11458 | INTERNAL | FLAG_NO_DATA, |
| 11459 | { }, |
| 11460 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11461 | .fill_helper = bpf_fill_staggered_jle32_imm, |
| 11462 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11463 | }, |
| 11464 | { |
| 11465 | "Staggered jumps: JMP32_JSGT_K", |
| 11466 | { }, |
| 11467 | INTERNAL | FLAG_NO_DATA, |
| 11468 | { }, |
| 11469 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11470 | .fill_helper = bpf_fill_staggered_jsgt32_imm, |
| 11471 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11472 | }, |
| 11473 | { |
| 11474 | "Staggered jumps: JMP32_JSGE_K", |
| 11475 | { }, |
| 11476 | INTERNAL | FLAG_NO_DATA, |
| 11477 | { }, |
| 11478 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11479 | .fill_helper = bpf_fill_staggered_jsge32_imm, |
| 11480 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11481 | }, |
| 11482 | { |
| 11483 | "Staggered jumps: JMP32_JSLT_K", |
| 11484 | { }, |
| 11485 | INTERNAL | FLAG_NO_DATA, |
| 11486 | { }, |
| 11487 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11488 | .fill_helper = bpf_fill_staggered_jslt32_imm, |
| 11489 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11490 | }, |
| 11491 | { |
| 11492 | "Staggered jumps: JMP32_JSLE_K", |
| 11493 | { }, |
| 11494 | INTERNAL | FLAG_NO_DATA, |
| 11495 | { }, |
| 11496 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11497 | .fill_helper = bpf_fill_staggered_jsle32_imm, |
| 11498 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11499 | }, |
| 11500 | /* Staggered jump sequences, JMP32 register */ |
| 11501 | { |
| 11502 | "Staggered jumps: JMP32_JEQ_X", |
| 11503 | { }, |
| 11504 | INTERNAL | FLAG_NO_DATA, |
| 11505 | { }, |
| 11506 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11507 | .fill_helper = bpf_fill_staggered_jeq32_reg, |
| 11508 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11509 | }, |
| 11510 | { |
| 11511 | "Staggered jumps: JMP32_JNE_X", |
| 11512 | { }, |
| 11513 | INTERNAL | FLAG_NO_DATA, |
| 11514 | { }, |
| 11515 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11516 | .fill_helper = bpf_fill_staggered_jne32_reg, |
| 11517 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11518 | }, |
| 11519 | { |
| 11520 | "Staggered jumps: JMP32_JSET_X", |
| 11521 | { }, |
| 11522 | INTERNAL | FLAG_NO_DATA, |
| 11523 | { }, |
| 11524 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11525 | .fill_helper = bpf_fill_staggered_jset32_reg, |
| 11526 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11527 | }, |
| 11528 | { |
| 11529 | "Staggered jumps: JMP32_JGT_X", |
| 11530 | { }, |
| 11531 | INTERNAL | FLAG_NO_DATA, |
| 11532 | { }, |
| 11533 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11534 | .fill_helper = bpf_fill_staggered_jgt32_reg, |
| 11535 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11536 | }, |
| 11537 | { |
| 11538 | "Staggered jumps: JMP32_JGE_X", |
| 11539 | { }, |
| 11540 | INTERNAL | FLAG_NO_DATA, |
| 11541 | { }, |
| 11542 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11543 | .fill_helper = bpf_fill_staggered_jge32_reg, |
| 11544 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11545 | }, |
| 11546 | { |
| 11547 | "Staggered jumps: JMP32_JLT_X", |
| 11548 | { }, |
| 11549 | INTERNAL | FLAG_NO_DATA, |
| 11550 | { }, |
| 11551 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11552 | .fill_helper = bpf_fill_staggered_jlt32_reg, |
| 11553 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11554 | }, |
| 11555 | { |
| 11556 | "Staggered jumps: JMP32_JLE_X", |
| 11557 | { }, |
| 11558 | INTERNAL | FLAG_NO_DATA, |
| 11559 | { }, |
| 11560 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11561 | .fill_helper = bpf_fill_staggered_jle32_reg, |
| 11562 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11563 | }, |
| 11564 | { |
| 11565 | "Staggered jumps: JMP32_JSGT_X", |
| 11566 | { }, |
| 11567 | INTERNAL | FLAG_NO_DATA, |
| 11568 | { }, |
| 11569 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11570 | .fill_helper = bpf_fill_staggered_jsgt32_reg, |
| 11571 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11572 | }, |
| 11573 | { |
| 11574 | "Staggered jumps: JMP32_JSGE_X", |
| 11575 | { }, |
| 11576 | INTERNAL | FLAG_NO_DATA, |
| 11577 | { }, |
| 11578 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11579 | .fill_helper = bpf_fill_staggered_jsge32_reg, |
| 11580 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11581 | }, |
| 11582 | { |
| 11583 | "Staggered jumps: JMP32_JSLT_X", |
| 11584 | { }, |
| 11585 | INTERNAL | FLAG_NO_DATA, |
| 11586 | { }, |
| 11587 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11588 | .fill_helper = bpf_fill_staggered_jslt32_reg, |
| 11589 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11590 | }, |
| 11591 | { |
| 11592 | "Staggered jumps: JMP32_JSLE_X", |
| 11593 | { }, |
| 11594 | INTERNAL | FLAG_NO_DATA, |
| 11595 | { }, |
| 11596 | { { 0, MAX_STAGGERED_JMP_SIZE + 1 } }, |
| 11597 | .fill_helper = bpf_fill_staggered_jsle32_reg, |
| 11598 | .nr_testruns = NR_STAGGERED_JMP_RUNS, |
| 11599 | }, |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11600 | }; |
| 11601 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11602 | static struct net_device dev; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11603 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11604 | static struct sk_buff *populate_skb(char *buf, int size) |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11605 | { |
| 11606 | struct sk_buff *skb; |
| 11607 | |
| 11608 | if (size >= MAX_DATA) |
| 11609 | return NULL; |
| 11610 | |
| 11611 | skb = alloc_skb(MAX_DATA, GFP_KERNEL); |
| 11612 | if (!skb) |
| 11613 | return NULL; |
| 11614 | |
yuan linyu | de77b96 | 2017-06-18 22:48:17 +0800 | [diff] [blame] | 11615 | __skb_put_data(skb, buf, size); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11616 | |
| 11617 | /* Initialize a fake skb with test pattern. */ |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11618 | skb_reset_mac_header(skb); |
| 11619 | skb->protocol = htons(ETH_P_IP); |
| 11620 | skb->pkt_type = SKB_TYPE; |
| 11621 | skb->mark = SKB_MARK; |
| 11622 | skb->hash = SKB_HASH; |
| 11623 | skb->queue_mapping = SKB_QUEUE_MAP; |
| 11624 | skb->vlan_tci = SKB_VLAN_TCI; |
Michał Mirosław | 0c4b2d3 | 2018-11-10 19:58:36 +0100 | [diff] [blame] | 11625 | skb->vlan_present = SKB_VLAN_PRESENT; |
Jakub Kicinski | 5c0ca3f | 2016-09-12 13:04:57 +0100 | [diff] [blame] | 11626 | skb->vlan_proto = htons(ETH_P_IP); |
Song Liu | 10081193 | 2018-09-27 09:34:41 -0700 | [diff] [blame] | 11627 | dev_net_set(&dev, &init_net); |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11628 | skb->dev = &dev; |
| 11629 | skb->dev->ifindex = SKB_DEV_IFINDEX; |
| 11630 | skb->dev->type = SKB_DEV_TYPE; |
| 11631 | skb_set_network_header(skb, min(size, ETH_HLEN)); |
| 11632 | |
| 11633 | return skb; |
| 11634 | } |
| 11635 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11636 | static void *generate_test_data(struct bpf_test *test, int sub) |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11637 | { |
Nicolas Schichan | bac142a | 2015-08-04 15:19:08 +0200 | [diff] [blame] | 11638 | struct sk_buff *skb; |
| 11639 | struct page *page; |
| 11640 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11641 | if (test->aux & FLAG_NO_DATA) |
| 11642 | return NULL; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11643 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11644 | /* Test case expects an skb, so populate one. Various |
| 11645 | * subtests generate skbs of different sizes based on |
| 11646 | * the same data. |
| 11647 | */ |
Nicolas Schichan | bac142a | 2015-08-04 15:19:08 +0200 | [diff] [blame] | 11648 | skb = populate_skb(test->data, test->test[sub].data_size); |
| 11649 | if (!skb) |
| 11650 | return NULL; |
| 11651 | |
| 11652 | if (test->aux & FLAG_SKB_FRAG) { |
| 11653 | /* |
| 11654 | * when the test requires a fragmented skb, add a |
| 11655 | * single fragment to the skb, filled with |
| 11656 | * test->frag_data. |
| 11657 | */ |
| 11658 | void *ptr; |
| 11659 | |
| 11660 | page = alloc_page(GFP_KERNEL); |
| 11661 | |
| 11662 | if (!page) |
| 11663 | goto err_kfree_skb; |
| 11664 | |
| 11665 | ptr = kmap(page); |
| 11666 | if (!ptr) |
| 11667 | goto err_free_page; |
| 11668 | memcpy(ptr, test->frag_data, MAX_DATA); |
| 11669 | kunmap(page); |
| 11670 | skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA); |
| 11671 | } |
| 11672 | |
| 11673 | return skb; |
| 11674 | |
| 11675 | err_free_page: |
| 11676 | __free_page(page); |
| 11677 | err_kfree_skb: |
| 11678 | kfree_skb(skb); |
| 11679 | return NULL; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11680 | } |
| 11681 | |
| 11682 | static void release_test_data(const struct bpf_test *test, void *data) |
| 11683 | { |
| 11684 | if (test->aux & FLAG_NO_DATA) |
| 11685 | return; |
| 11686 | |
| 11687 | kfree_skb(data); |
| 11688 | } |
| 11689 | |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11690 | static int filter_length(int which) |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11691 | { |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11692 | struct sock_filter *fp; |
| 11693 | int len; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11694 | |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11695 | if (tests[which].fill_helper) |
| 11696 | return tests[which].u.ptr.len; |
| 11697 | |
| 11698 | fp = tests[which].u.insns; |
Chema Gonzalez | e9d9450 | 2014-05-30 10:15:12 -0700 | [diff] [blame] | 11699 | for (len = MAX_INSNS - 1; len > 0; --len) |
| 11700 | if (fp[len].code != 0 || fp[len].k != 0) |
| 11701 | break; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11702 | |
Chema Gonzalez | e9d9450 | 2014-05-30 10:15:12 -0700 | [diff] [blame] | 11703 | return len + 1; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11704 | } |
| 11705 | |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11706 | static void *filter_pointer(int which) |
| 11707 | { |
| 11708 | if (tests[which].fill_helper) |
| 11709 | return tests[which].u.ptr.insns; |
| 11710 | else |
| 11711 | return tests[which].u.insns; |
| 11712 | } |
| 11713 | |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11714 | static struct bpf_prog *generate_filter(int which, int *err) |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11715 | { |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11716 | __u8 test_type = tests[which].aux & TEST_TYPE_MASK; |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11717 | unsigned int flen = filter_length(which); |
| 11718 | void *fptr = filter_pointer(which); |
| 11719 | struct sock_fprog_kern fprog; |
| 11720 | struct bpf_prog *fp; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11721 | |
| 11722 | switch (test_type) { |
| 11723 | case CLASSIC: |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11724 | fprog.filter = fptr; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11725 | fprog.len = flen; |
| 11726 | |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11727 | *err = bpf_prog_create(&fp, &fprog); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11728 | if (tests[which].aux & FLAG_EXPECTED_FAIL) { |
Yonghong Song | 09584b4 | 2018-02-02 22:37:15 -0800 | [diff] [blame] | 11729 | if (*err == tests[which].expected_errcode) { |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11730 | pr_cont("PASS\n"); |
| 11731 | /* Verifier rejected filter as expected. */ |
| 11732 | *err = 0; |
| 11733 | return NULL; |
| 11734 | } else { |
| 11735 | pr_cont("UNEXPECTED_PASS\n"); |
| 11736 | /* Verifier didn't reject the test that's |
| 11737 | * bad enough, just return! |
| 11738 | */ |
| 11739 | *err = -EINVAL; |
| 11740 | return NULL; |
| 11741 | } |
| 11742 | } |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11743 | if (*err) { |
Alexei Starovoitov | 290af86 | 2018-01-09 10:04:29 -0800 | [diff] [blame] | 11744 | pr_cont("FAIL to prog_create err=%d len=%d\n", |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11745 | *err, fprog.len); |
| 11746 | return NULL; |
| 11747 | } |
| 11748 | break; |
| 11749 | |
| 11750 | case INTERNAL: |
Daniel Borkmann | 60a3b22 | 2014-09-02 22:53:44 +0200 | [diff] [blame] | 11751 | fp = bpf_prog_alloc(bpf_prog_size(flen), 0); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11752 | if (fp == NULL) { |
| 11753 | pr_cont("UNEXPECTED_FAIL no memory left\n"); |
| 11754 | *err = -ENOMEM; |
| 11755 | return NULL; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11756 | } |
| 11757 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11758 | fp->len = flen; |
Daniel Borkmann | 4962fa1 | 2015-07-30 12:42:46 +0200 | [diff] [blame] | 11759 | /* Type doesn't really matter here as long as it's not unspec. */ |
| 11760 | fp->type = BPF_PROG_TYPE_SOCKET_FILTER; |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11761 | memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn)); |
Alexei Starovoitov | 105c036 | 2017-05-30 13:31:32 -0700 | [diff] [blame] | 11762 | fp->aux->stack_depth = tests[which].stack_depth; |
Johan Almbladh | 27cc6da | 2021-09-14 11:18:36 +0200 | [diff] [blame] | 11763 | fp->aux->verifier_zext = !!(tests[which].aux & |
| 11764 | FLAG_VERIFIER_ZEXT); |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11765 | |
Daniel Borkmann | d1c55ab | 2016-05-13 19:08:31 +0200 | [diff] [blame] | 11766 | /* We cannot error here as we don't need type compatibility |
| 11767 | * checks. |
| 11768 | */ |
| 11769 | fp = bpf_prog_select_runtime(fp, err); |
Alexei Starovoitov | 290af86 | 2018-01-09 10:04:29 -0800 | [diff] [blame] | 11770 | if (*err) { |
| 11771 | pr_cont("FAIL to select_runtime err=%d\n", *err); |
| 11772 | return NULL; |
| 11773 | } |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11774 | break; |
| 11775 | } |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11776 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11777 | *err = 0; |
| 11778 | return fp; |
| 11779 | } |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11780 | |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11781 | static void release_filter(struct bpf_prog *fp, int which) |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11782 | { |
| 11783 | __u8 test_type = tests[which].aux & TEST_TYPE_MASK; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11784 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11785 | switch (test_type) { |
| 11786 | case CLASSIC: |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11787 | bpf_prog_destroy(fp); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11788 | break; |
| 11789 | case INTERNAL: |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11790 | bpf_prog_free(fp); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11791 | break; |
| 11792 | } |
| 11793 | } |
| 11794 | |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11795 | static int __run_one(const struct bpf_prog *fp, const void *data, |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11796 | int runs, u64 *duration) |
| 11797 | { |
| 11798 | u64 start, finish; |
Alexei Starovoitov | 25ee732 | 2014-09-19 13:53:51 -0700 | [diff] [blame] | 11799 | int ret = 0, i; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11800 | |
David Miller | 6eac779 | 2020-02-24 15:01:44 +0100 | [diff] [blame] | 11801 | migrate_disable(); |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 11802 | start = ktime_get_ns(); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11803 | |
| 11804 | for (i = 0; i < runs; i++) |
Andrii Nakryiko | fb7dd8b | 2021-08-15 00:05:54 -0700 | [diff] [blame] | 11805 | ret = bpf_prog_run(fp, data); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11806 | |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 11807 | finish = ktime_get_ns(); |
David Miller | 6eac779 | 2020-02-24 15:01:44 +0100 | [diff] [blame] | 11808 | migrate_enable(); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11809 | |
Alexei Starovoitov | 4d9c5c5 | 2015-07-20 20:34:19 -0700 | [diff] [blame] | 11810 | *duration = finish - start; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11811 | do_div(*duration, runs); |
| 11812 | |
| 11813 | return ret; |
| 11814 | } |
| 11815 | |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 11816 | static int run_one(const struct bpf_prog *fp, struct bpf_test *test) |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11817 | { |
| 11818 | int err_cnt = 0, i, runs = MAX_TESTRUNS; |
| 11819 | |
Johan Almbladh | c2a228d | 2021-09-14 11:18:29 +0200 | [diff] [blame] | 11820 | if (test->nr_testruns) |
| 11821 | runs = min(test->nr_testruns, MAX_TESTRUNS); |
| 11822 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11823 | for (i = 0; i < MAX_SUBTESTS; i++) { |
| 11824 | void *data; |
| 11825 | u64 duration; |
| 11826 | u32 ret; |
| 11827 | |
Johan Almbladh | 2b7e9f2 | 2021-07-21 12:38:22 +0200 | [diff] [blame] | 11828 | /* |
| 11829 | * NOTE: Several sub-tests may be present, in which case |
| 11830 | * a zero {data_size, result} tuple indicates the end of |
| 11831 | * the sub-test array. The first test is always run, |
| 11832 | * even if both data_size and result happen to be zero. |
| 11833 | */ |
| 11834 | if (i > 0 && |
| 11835 | test->test[i].data_size == 0 && |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11836 | test->test[i].result == 0) |
| 11837 | break; |
| 11838 | |
| 11839 | data = generate_test_data(test, i); |
Nicolas Schichan | e34684f | 2015-08-04 15:19:07 +0200 | [diff] [blame] | 11840 | if (!data && !(test->aux & FLAG_NO_DATA)) { |
| 11841 | pr_cont("data generation failed "); |
| 11842 | err_cnt++; |
| 11843 | break; |
| 11844 | } |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 11845 | ret = __run_one(fp, data, runs, &duration); |
| 11846 | release_test_data(test, data); |
| 11847 | |
| 11848 | if (ret == test->test[i].result) { |
| 11849 | pr_cont("%lld ", duration); |
| 11850 | } else { |
| 11851 | pr_cont("ret %d != %d ", ret, |
| 11852 | test->test[i].result); |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 11853 | err_cnt++; |
| 11854 | } |
| 11855 | } |
| 11856 | |
| 11857 | return err_cnt; |
| 11858 | } |
| 11859 | |
Nicolas Schichan | d2648d4 | 2015-08-04 15:19:10 +0200 | [diff] [blame] | 11860 | static char test_name[64]; |
| 11861 | module_param_string(test_name, test_name, sizeof(test_name), 0); |
| 11862 | |
| 11863 | static int test_id = -1; |
| 11864 | module_param(test_id, int, 0); |
| 11865 | |
| 11866 | static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 }; |
| 11867 | module_param_array(test_range, int, NULL, 0); |
| 11868 | |
| 11869 | static __init int find_test_index(const char *test_name) |
| 11870 | { |
| 11871 | int i; |
| 11872 | |
| 11873 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
| 11874 | if (!strcmp(tests[i].descr, test_name)) |
| 11875 | return i; |
| 11876 | } |
| 11877 | return -1; |
| 11878 | } |
| 11879 | |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11880 | static __init int prepare_bpf_tests(void) |
| 11881 | { |
Nicolas Schichan | d2648d4 | 2015-08-04 15:19:10 +0200 | [diff] [blame] | 11882 | if (test_id >= 0) { |
| 11883 | /* |
| 11884 | * if a test_id was specified, use test_range to |
| 11885 | * cover only that test. |
| 11886 | */ |
| 11887 | if (test_id >= ARRAY_SIZE(tests)) { |
| 11888 | pr_err("test_bpf: invalid test_id specified.\n"); |
| 11889 | return -EINVAL; |
| 11890 | } |
| 11891 | |
| 11892 | test_range[0] = test_id; |
| 11893 | test_range[1] = test_id; |
| 11894 | } else if (*test_name) { |
| 11895 | /* |
| 11896 | * if a test_name was specified, find it and setup |
| 11897 | * test_range to cover only that test. |
| 11898 | */ |
| 11899 | int idx = find_test_index(test_name); |
| 11900 | |
| 11901 | if (idx < 0) { |
| 11902 | pr_err("test_bpf: no test named '%s' found.\n", |
| 11903 | test_name); |
| 11904 | return -EINVAL; |
| 11905 | } |
| 11906 | test_range[0] = idx; |
| 11907 | test_range[1] = idx; |
| 11908 | } else { |
| 11909 | /* |
| 11910 | * check that the supplied test_range is valid. |
| 11911 | */ |
| 11912 | if (test_range[0] >= ARRAY_SIZE(tests) || |
| 11913 | test_range[1] >= ARRAY_SIZE(tests) || |
| 11914 | test_range[0] < 0 || test_range[1] < 0) { |
| 11915 | pr_err("test_bpf: test_range is out of bound.\n"); |
| 11916 | return -EINVAL; |
| 11917 | } |
| 11918 | |
| 11919 | if (test_range[1] < test_range[0]) { |
| 11920 | pr_err("test_bpf: test_range is ending before it starts.\n"); |
| 11921 | return -EINVAL; |
| 11922 | } |
| 11923 | } |
| 11924 | |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11925 | return 0; |
| 11926 | } |
| 11927 | |
| 11928 | static __init void destroy_bpf_tests(void) |
| 11929 | { |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 11930 | } |
| 11931 | |
Nicolas Schichan | d2648d4 | 2015-08-04 15:19:10 +0200 | [diff] [blame] | 11932 | static bool exclude_test(int test_id) |
| 11933 | { |
| 11934 | return test_id < test_range[0] || test_id > test_range[1]; |
| 11935 | } |
| 11936 | |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 11937 | static __init struct sk_buff *build_test_skb(void) |
| 11938 | { |
| 11939 | u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN; |
| 11940 | struct sk_buff *skb[2]; |
| 11941 | struct page *page[2]; |
| 11942 | int i, data_size = 8; |
| 11943 | |
| 11944 | for (i = 0; i < 2; i++) { |
| 11945 | page[i] = alloc_page(GFP_KERNEL); |
| 11946 | if (!page[i]) { |
| 11947 | if (i == 0) |
| 11948 | goto err_page0; |
| 11949 | else |
| 11950 | goto err_page1; |
| 11951 | } |
| 11952 | |
| 11953 | /* this will set skb[i]->head_frag */ |
| 11954 | skb[i] = dev_alloc_skb(headroom + data_size); |
| 11955 | if (!skb[i]) { |
| 11956 | if (i == 0) |
| 11957 | goto err_skb0; |
| 11958 | else |
| 11959 | goto err_skb1; |
| 11960 | } |
| 11961 | |
| 11962 | skb_reserve(skb[i], headroom); |
| 11963 | skb_put(skb[i], data_size); |
| 11964 | skb[i]->protocol = htons(ETH_P_IP); |
| 11965 | skb_reset_network_header(skb[i]); |
| 11966 | skb_set_mac_header(skb[i], -ETH_HLEN); |
| 11967 | |
| 11968 | skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64); |
| 11969 | // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1 |
| 11970 | } |
| 11971 | |
| 11972 | /* setup shinfo */ |
| 11973 | skb_shinfo(skb[0])->gso_size = 1448; |
| 11974 | skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4; |
| 11975 | skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY; |
| 11976 | skb_shinfo(skb[0])->gso_segs = 0; |
| 11977 | skb_shinfo(skb[0])->frag_list = skb[1]; |
Vadim Fedorenko | 3384c7c | 2021-09-10 01:04:09 +0300 | [diff] [blame] | 11978 | skb_shinfo(skb[0])->hwtstamps.hwtstamp = 1000; |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 11979 | |
| 11980 | /* adjust skb[0]'s len */ |
| 11981 | skb[0]->len += skb[1]->len; |
| 11982 | skb[0]->data_len += skb[1]->data_len; |
| 11983 | skb[0]->truesize += skb[1]->truesize; |
| 11984 | |
| 11985 | return skb[0]; |
| 11986 | |
| 11987 | err_skb1: |
| 11988 | __free_page(page[1]); |
| 11989 | err_page1: |
| 11990 | kfree_skb(skb[0]); |
| 11991 | err_skb0: |
| 11992 | __free_page(page[0]); |
| 11993 | err_page0: |
| 11994 | return NULL; |
| 11995 | } |
| 11996 | |
Shmulik Ladkani | cf204a7 | 2019-10-25 16:42:23 +0300 | [diff] [blame] | 11997 | static __init struct sk_buff *build_test_skb_linear_no_head_frag(void) |
| 11998 | { |
| 11999 | unsigned int alloc_size = 2000; |
| 12000 | unsigned int headroom = 102, doffset = 72, data_size = 1308; |
| 12001 | struct sk_buff *skb[2]; |
| 12002 | int i; |
| 12003 | |
| 12004 | /* skbs linked in a frag_list, both with linear data, with head_frag=0 |
| 12005 | * (data allocated by kmalloc), both have tcp data of 1308 bytes |
| 12006 | * (total payload is 2616 bytes). |
| 12007 | * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom. |
| 12008 | */ |
| 12009 | for (i = 0; i < 2; i++) { |
| 12010 | skb[i] = alloc_skb(alloc_size, GFP_KERNEL); |
| 12011 | if (!skb[i]) { |
| 12012 | if (i == 0) |
| 12013 | goto err_skb0; |
| 12014 | else |
| 12015 | goto err_skb1; |
| 12016 | } |
| 12017 | |
| 12018 | skb[i]->protocol = htons(ETH_P_IPV6); |
| 12019 | skb_reserve(skb[i], headroom); |
| 12020 | skb_put(skb[i], doffset + data_size); |
| 12021 | skb_reset_network_header(skb[i]); |
| 12022 | if (i == 0) |
| 12023 | skb_reset_mac_header(skb[i]); |
| 12024 | else |
| 12025 | skb_set_mac_header(skb[i], -ETH_HLEN); |
| 12026 | __skb_pull(skb[i], doffset); |
| 12027 | } |
| 12028 | |
| 12029 | /* setup shinfo. |
| 12030 | * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a |
| 12031 | * reduced gso_size. |
| 12032 | */ |
| 12033 | skb_shinfo(skb[0])->gso_size = 1288; |
| 12034 | skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY; |
| 12035 | skb_shinfo(skb[0])->gso_segs = 0; |
| 12036 | skb_shinfo(skb[0])->frag_list = skb[1]; |
| 12037 | |
| 12038 | /* adjust skb[0]'s len */ |
| 12039 | skb[0]->len += skb[1]->len; |
| 12040 | skb[0]->data_len += skb[1]->len; |
| 12041 | skb[0]->truesize += skb[1]->truesize; |
| 12042 | |
| 12043 | return skb[0]; |
| 12044 | |
| 12045 | err_skb1: |
| 12046 | kfree_skb(skb[0]); |
| 12047 | err_skb0: |
| 12048 | return NULL; |
| 12049 | } |
| 12050 | |
Shmulik Ladkani | af21c71 | 2019-10-25 16:42:22 +0300 | [diff] [blame] | 12051 | struct skb_segment_test { |
| 12052 | const char *descr; |
| 12053 | struct sk_buff *(*build_skb)(void); |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12054 | netdev_features_t features; |
Shmulik Ladkani | af21c71 | 2019-10-25 16:42:22 +0300 | [diff] [blame] | 12055 | }; |
| 12056 | |
| 12057 | static struct skb_segment_test skb_segment_tests[] __initconst = { |
| 12058 | { |
| 12059 | .descr = "gso_with_rx_frags", |
| 12060 | .build_skb = build_test_skb, |
| 12061 | .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM | |
| 12062 | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
Shmulik Ladkani | cf204a7 | 2019-10-25 16:42:23 +0300 | [diff] [blame] | 12063 | }, |
| 12064 | { |
| 12065 | .descr = "gso_linear_no_head_frag", |
| 12066 | .build_skb = build_test_skb_linear_no_head_frag, |
| 12067 | .features = NETIF_F_SG | NETIF_F_FRAGLIST | |
| 12068 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO | |
| 12069 | NETIF_F_LLTX_BIT | NETIF_F_GRO | |
| 12070 | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
| 12071 | NETIF_F_HW_VLAN_STAG_TX_BIT |
Shmulik Ladkani | af21c71 | 2019-10-25 16:42:22 +0300 | [diff] [blame] | 12072 | } |
| 12073 | }; |
| 12074 | |
| 12075 | static __init int test_skb_segment_single(const struct skb_segment_test *test) |
| 12076 | { |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12077 | struct sk_buff *skb, *segs; |
| 12078 | int ret = -1; |
| 12079 | |
Shmulik Ladkani | af21c71 | 2019-10-25 16:42:22 +0300 | [diff] [blame] | 12080 | skb = test->build_skb(); |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12081 | if (!skb) { |
| 12082 | pr_info("%s: failed to build_test_skb", __func__); |
| 12083 | goto done; |
| 12084 | } |
| 12085 | |
Shmulik Ladkani | af21c71 | 2019-10-25 16:42:22 +0300 | [diff] [blame] | 12086 | segs = skb_segment(skb, test->features); |
Dan Carpenter | 99fe29d | 2018-03-28 14:48:36 +0300 | [diff] [blame] | 12087 | if (!IS_ERR(segs)) { |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12088 | kfree_skb_list(segs); |
| 12089 | ret = 0; |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12090 | } |
| 12091 | kfree_skb(skb); |
| 12092 | done: |
| 12093 | return ret; |
| 12094 | } |
| 12095 | |
Shmulik Ladkani | af21c71 | 2019-10-25 16:42:22 +0300 | [diff] [blame] | 12096 | static __init int test_skb_segment(void) |
| 12097 | { |
| 12098 | int i, err_cnt = 0, pass_cnt = 0; |
| 12099 | |
| 12100 | for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) { |
| 12101 | const struct skb_segment_test *test = &skb_segment_tests[i]; |
| 12102 | |
| 12103 | pr_info("#%d %s ", i, test->descr); |
| 12104 | |
| 12105 | if (test_skb_segment_single(test)) { |
| 12106 | pr_cont("FAIL\n"); |
| 12107 | err_cnt++; |
| 12108 | } else { |
| 12109 | pr_cont("PASS\n"); |
| 12110 | pass_cnt++; |
| 12111 | } |
| 12112 | } |
| 12113 | |
| 12114 | pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__, |
| 12115 | pass_cnt, err_cnt); |
| 12116 | return err_cnt ? -EINVAL : 0; |
| 12117 | } |
| 12118 | |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12119 | static __init int test_bpf(void) |
| 12120 | { |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12121 | int i, err_cnt = 0, pass_cnt = 0; |
Daniel Borkmann | 327941f | 2015-04-30 16:17:27 +0200 | [diff] [blame] | 12122 | int jit_cnt = 0, run_cnt = 0; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12123 | |
| 12124 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 12125 | struct bpf_prog *fp; |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12126 | int err; |
| 12127 | |
Eric Dumazet | d40bc96 | 2018-02-26 10:52:46 -0800 | [diff] [blame] | 12128 | cond_resched(); |
Nicolas Schichan | d2648d4 | 2015-08-04 15:19:10 +0200 | [diff] [blame] | 12129 | if (exclude_test(i)) |
| 12130 | continue; |
| 12131 | |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12132 | pr_info("#%d %s ", i, tests[i].descr); |
| 12133 | |
Johan Almbladh | 4bc3541 | 2021-09-14 11:18:30 +0200 | [diff] [blame] | 12134 | if (tests[i].fill_helper && |
| 12135 | tests[i].fill_helper(&tests[i]) < 0) { |
| 12136 | pr_cont("FAIL to prog_fill\n"); |
| 12137 | continue; |
| 12138 | } |
| 12139 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12140 | fp = generate_filter(i, &err); |
Johan Almbladh | 4bc3541 | 2021-09-14 11:18:30 +0200 | [diff] [blame] | 12141 | |
| 12142 | if (tests[i].fill_helper) { |
| 12143 | kfree(tests[i].u.ptr.insns); |
| 12144 | tests[i].u.ptr.insns = NULL; |
| 12145 | } |
| 12146 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12147 | if (fp == NULL) { |
| 12148 | if (err == 0) { |
| 12149 | pass_cnt++; |
| 12150 | continue; |
| 12151 | } |
Alexei Starovoitov | 290af86 | 2018-01-09 10:04:29 -0800 | [diff] [blame] | 12152 | err_cnt++; |
| 12153 | continue; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12154 | } |
Daniel Borkmann | 327941f | 2015-04-30 16:17:27 +0200 | [diff] [blame] | 12155 | |
| 12156 | pr_cont("jited:%u ", fp->jited); |
| 12157 | |
| 12158 | run_cnt++; |
| 12159 | if (fp->jited) |
| 12160 | jit_cnt++; |
| 12161 | |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12162 | err = run_one(fp, &tests[i]); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12163 | release_filter(fp, i); |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12164 | |
| 12165 | if (err) { |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12166 | pr_cont("FAIL (%d times)\n", err); |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12167 | err_cnt++; |
| 12168 | } else { |
| 12169 | pr_cont("PASS\n"); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12170 | pass_cnt++; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12171 | } |
| 12172 | } |
| 12173 | |
Daniel Borkmann | 327941f | 2015-04-30 16:17:27 +0200 | [diff] [blame] | 12174 | pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n", |
| 12175 | pass_cnt, err_cnt, jit_cnt, run_cnt); |
| 12176 | |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12177 | return err_cnt ? -EINVAL : 0; |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12178 | } |
| 12179 | |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12180 | struct tail_call_test { |
| 12181 | const char *descr; |
| 12182 | struct bpf_insn insns[MAX_INSNS]; |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12183 | int flags; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12184 | int result; |
| 12185 | int stack_depth; |
| 12186 | }; |
| 12187 | |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12188 | /* Flags that can be passed to tail call test cases */ |
| 12189 | #define FLAG_NEED_STATE BIT(0) |
| 12190 | #define FLAG_RESULT_IN_STATE BIT(1) |
| 12191 | |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12192 | /* |
| 12193 | * Magic marker used in test snippets for tail calls below. |
| 12194 | * BPF_LD/MOV to R2 and R2 with this immediate value is replaced |
| 12195 | * with the proper values by the test runner. |
| 12196 | */ |
| 12197 | #define TAIL_CALL_MARKER 0x7a11ca11 |
| 12198 | |
| 12199 | /* Special offset to indicate a NULL call target */ |
| 12200 | #define TAIL_CALL_NULL 0x7fff |
| 12201 | |
| 12202 | /* Special offset to indicate an out-of-range index */ |
| 12203 | #define TAIL_CALL_INVALID 0x7ffe |
| 12204 | |
| 12205 | #define TAIL_CALL(offset) \ |
| 12206 | BPF_LD_IMM64(R2, TAIL_CALL_MARKER), \ |
| 12207 | BPF_RAW_INSN(BPF_ALU | BPF_MOV | BPF_K, R3, 0, \ |
| 12208 | offset, TAIL_CALL_MARKER), \ |
| 12209 | BPF_JMP_IMM(BPF_TAIL_CALL, 0, 0, 0) |
| 12210 | |
| 12211 | /* |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12212 | * A test function to be called from a BPF program, clobbering a lot of |
| 12213 | * CPU registers in the process. A JITed BPF program calling this function |
| 12214 | * must save and restore any caller-saved registers it uses for internal |
| 12215 | * state, for example the current tail call count. |
| 12216 | */ |
| 12217 | BPF_CALL_1(bpf_test_func, u64, arg) |
| 12218 | { |
| 12219 | char buf[64]; |
| 12220 | long a = 0; |
| 12221 | long b = 1; |
| 12222 | long c = 2; |
| 12223 | long d = 3; |
| 12224 | long e = 4; |
| 12225 | long f = 5; |
| 12226 | long g = 6; |
| 12227 | long h = 7; |
| 12228 | |
| 12229 | return snprintf(buf, sizeof(buf), |
| 12230 | "%ld %lu %lx %ld %lu %lx %ld %lu %x", |
| 12231 | a, b, c, d, e, f, g, h, (int)arg); |
| 12232 | } |
| 12233 | #define BPF_FUNC_test_func __BPF_FUNC_MAX_ID |
| 12234 | |
| 12235 | /* |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12236 | * Tail call tests. Each test case may call any other test in the table, |
| 12237 | * including itself, specified as a relative index offset from the calling |
| 12238 | * test. The index TAIL_CALL_NULL can be used to specify a NULL target |
| 12239 | * function to test the JIT error path. Similarly, the index TAIL_CALL_INVALID |
| 12240 | * results in a target index that is out of range. |
| 12241 | */ |
| 12242 | static struct tail_call_test tail_call_tests[] = { |
| 12243 | { |
| 12244 | "Tail call leaf", |
| 12245 | .insns = { |
| 12246 | BPF_ALU64_REG(BPF_MOV, R0, R1), |
| 12247 | BPF_ALU64_IMM(BPF_ADD, R0, 1), |
| 12248 | BPF_EXIT_INSN(), |
| 12249 | }, |
| 12250 | .result = 1, |
| 12251 | }, |
| 12252 | { |
| 12253 | "Tail call 2", |
| 12254 | .insns = { |
| 12255 | BPF_ALU64_IMM(BPF_ADD, R1, 2), |
| 12256 | TAIL_CALL(-1), |
| 12257 | BPF_ALU64_IMM(BPF_MOV, R0, -1), |
| 12258 | BPF_EXIT_INSN(), |
| 12259 | }, |
| 12260 | .result = 3, |
| 12261 | }, |
| 12262 | { |
| 12263 | "Tail call 3", |
| 12264 | .insns = { |
| 12265 | BPF_ALU64_IMM(BPF_ADD, R1, 3), |
| 12266 | TAIL_CALL(-1), |
| 12267 | BPF_ALU64_IMM(BPF_MOV, R0, -1), |
| 12268 | BPF_EXIT_INSN(), |
| 12269 | }, |
| 12270 | .result = 6, |
| 12271 | }, |
| 12272 | { |
| 12273 | "Tail call 4", |
| 12274 | .insns = { |
| 12275 | BPF_ALU64_IMM(BPF_ADD, R1, 4), |
| 12276 | TAIL_CALL(-1), |
| 12277 | BPF_ALU64_IMM(BPF_MOV, R0, -1), |
| 12278 | BPF_EXIT_INSN(), |
| 12279 | }, |
| 12280 | .result = 10, |
| 12281 | }, |
| 12282 | { |
| 12283 | "Tail call error path, max count reached", |
| 12284 | .insns = { |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12285 | BPF_LDX_MEM(BPF_W, R2, R1, 0), |
| 12286 | BPF_ALU64_IMM(BPF_ADD, R2, 1), |
| 12287 | BPF_STX_MEM(BPF_W, R1, R2, 0), |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12288 | TAIL_CALL(0), |
| 12289 | BPF_EXIT_INSN(), |
| 12290 | }, |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12291 | .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE, |
| 12292 | .result = (MAX_TAIL_CALL_CNT + 1 + 1) * MAX_TESTRUNS, |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12293 | }, |
| 12294 | { |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12295 | "Tail call count preserved across function calls", |
| 12296 | .insns = { |
| 12297 | BPF_LDX_MEM(BPF_W, R2, R1, 0), |
| 12298 | BPF_ALU64_IMM(BPF_ADD, R2, 1), |
| 12299 | BPF_STX_MEM(BPF_W, R1, R2, 0), |
| 12300 | BPF_STX_MEM(BPF_DW, R10, R1, -8), |
| 12301 | BPF_CALL_REL(BPF_FUNC_get_numa_node_id), |
| 12302 | BPF_CALL_REL(BPF_FUNC_ktime_get_ns), |
| 12303 | BPF_CALL_REL(BPF_FUNC_ktime_get_boot_ns), |
| 12304 | BPF_CALL_REL(BPF_FUNC_ktime_get_coarse_ns), |
| 12305 | BPF_CALL_REL(BPF_FUNC_jiffies64), |
| 12306 | BPF_CALL_REL(BPF_FUNC_test_func), |
| 12307 | BPF_LDX_MEM(BPF_DW, R1, R10, -8), |
| 12308 | BPF_ALU32_REG(BPF_MOV, R0, R1), |
| 12309 | TAIL_CALL(0), |
| 12310 | BPF_EXIT_INSN(), |
| 12311 | }, |
| 12312 | .stack_depth = 8, |
| 12313 | .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE, |
| 12314 | .result = (MAX_TAIL_CALL_CNT + 1 + 1) * MAX_TESTRUNS, |
| 12315 | }, |
| 12316 | { |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12317 | "Tail call error path, NULL target", |
| 12318 | .insns = { |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12319 | BPF_LDX_MEM(BPF_W, R2, R1, 0), |
| 12320 | BPF_ALU64_IMM(BPF_ADD, R2, 1), |
| 12321 | BPF_STX_MEM(BPF_W, R1, R2, 0), |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12322 | TAIL_CALL(TAIL_CALL_NULL), |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12323 | BPF_EXIT_INSN(), |
| 12324 | }, |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12325 | .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE, |
| 12326 | .result = MAX_TESTRUNS, |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12327 | }, |
| 12328 | { |
| 12329 | "Tail call error path, index out of range", |
| 12330 | .insns = { |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12331 | BPF_LDX_MEM(BPF_W, R2, R1, 0), |
| 12332 | BPF_ALU64_IMM(BPF_ADD, R2, 1), |
| 12333 | BPF_STX_MEM(BPF_W, R1, R2, 0), |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12334 | TAIL_CALL(TAIL_CALL_INVALID), |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12335 | BPF_EXIT_INSN(), |
| 12336 | }, |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12337 | .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE, |
| 12338 | .result = MAX_TESTRUNS, |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12339 | }, |
| 12340 | }; |
| 12341 | |
| 12342 | static void __init destroy_tail_call_tests(struct bpf_array *progs) |
| 12343 | { |
| 12344 | int i; |
| 12345 | |
| 12346 | for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) |
| 12347 | if (progs->ptrs[i]) |
| 12348 | bpf_prog_free(progs->ptrs[i]); |
| 12349 | kfree(progs); |
| 12350 | } |
| 12351 | |
| 12352 | static __init int prepare_tail_call_tests(struct bpf_array **pprogs) |
| 12353 | { |
| 12354 | int ntests = ARRAY_SIZE(tail_call_tests); |
| 12355 | struct bpf_array *progs; |
| 12356 | int which, err; |
| 12357 | |
| 12358 | /* Allocate the table of programs to be used for tall calls */ |
| 12359 | progs = kzalloc(sizeof(*progs) + (ntests + 1) * sizeof(progs->ptrs[0]), |
| 12360 | GFP_KERNEL); |
| 12361 | if (!progs) |
| 12362 | goto out_nomem; |
| 12363 | |
| 12364 | /* Create all eBPF programs and populate the table */ |
| 12365 | for (which = 0; which < ntests; which++) { |
| 12366 | struct tail_call_test *test = &tail_call_tests[which]; |
| 12367 | struct bpf_prog *fp; |
| 12368 | int len, i; |
| 12369 | |
| 12370 | /* Compute the number of program instructions */ |
| 12371 | for (len = 0; len < MAX_INSNS; len++) { |
| 12372 | struct bpf_insn *insn = &test->insns[len]; |
| 12373 | |
| 12374 | if (len < MAX_INSNS - 1 && |
| 12375 | insn->code == (BPF_LD | BPF_DW | BPF_IMM)) |
| 12376 | len++; |
| 12377 | if (insn->code == 0) |
| 12378 | break; |
| 12379 | } |
| 12380 | |
| 12381 | /* Allocate and initialize the program */ |
| 12382 | fp = bpf_prog_alloc(bpf_prog_size(len), 0); |
| 12383 | if (!fp) |
| 12384 | goto out_nomem; |
| 12385 | |
| 12386 | fp->len = len; |
| 12387 | fp->type = BPF_PROG_TYPE_SOCKET_FILTER; |
| 12388 | fp->aux->stack_depth = test->stack_depth; |
| 12389 | memcpy(fp->insnsi, test->insns, len * sizeof(struct bpf_insn)); |
| 12390 | |
| 12391 | /* Relocate runtime tail call offsets and addresses */ |
| 12392 | for (i = 0; i < len; i++) { |
| 12393 | struct bpf_insn *insn = &fp->insnsi[i]; |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12394 | long addr = 0; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12395 | |
| 12396 | switch (insn->code) { |
| 12397 | case BPF_LD | BPF_DW | BPF_IMM: |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12398 | if (insn->imm != TAIL_CALL_MARKER) |
| 12399 | break; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12400 | insn[0].imm = (u32)(long)progs; |
| 12401 | insn[1].imm = ((u64)(long)progs) >> 32; |
| 12402 | break; |
| 12403 | |
| 12404 | case BPF_ALU | BPF_MOV | BPF_K: |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12405 | if (insn->imm != TAIL_CALL_MARKER) |
| 12406 | break; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12407 | if (insn->off == TAIL_CALL_NULL) |
| 12408 | insn->imm = ntests; |
| 12409 | else if (insn->off == TAIL_CALL_INVALID) |
| 12410 | insn->imm = ntests + 1; |
| 12411 | else |
| 12412 | insn->imm = which + insn->off; |
| 12413 | insn->off = 0; |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12414 | break; |
| 12415 | |
| 12416 | case BPF_JMP | BPF_CALL: |
| 12417 | if (insn->src_reg != BPF_PSEUDO_CALL) |
| 12418 | break; |
| 12419 | switch (insn->imm) { |
| 12420 | case BPF_FUNC_get_numa_node_id: |
| 12421 | addr = (long)&numa_node_id; |
| 12422 | break; |
| 12423 | case BPF_FUNC_ktime_get_ns: |
| 12424 | addr = (long)&ktime_get_ns; |
| 12425 | break; |
| 12426 | case BPF_FUNC_ktime_get_boot_ns: |
| 12427 | addr = (long)&ktime_get_boot_fast_ns; |
| 12428 | break; |
| 12429 | case BPF_FUNC_ktime_get_coarse_ns: |
| 12430 | addr = (long)&ktime_get_coarse_ns; |
| 12431 | break; |
| 12432 | case BPF_FUNC_jiffies64: |
| 12433 | addr = (long)&get_jiffies_64; |
| 12434 | break; |
| 12435 | case BPF_FUNC_test_func: |
| 12436 | addr = (long)&bpf_test_func; |
| 12437 | break; |
| 12438 | default: |
| 12439 | err = -EFAULT; |
| 12440 | goto out_err; |
| 12441 | } |
Kees Cook | 3d717fa | 2021-09-28 16:09:45 -0700 | [diff] [blame^] | 12442 | *insn = BPF_EMIT_CALL(addr); |
Johan Almbladh | 29eef85 | 2021-09-14 11:18:42 +0200 | [diff] [blame] | 12443 | if ((long)__bpf_call_base + insn->imm != addr) |
| 12444 | *insn = BPF_JMP_A(0); /* Skip: NOP */ |
| 12445 | break; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12446 | } |
| 12447 | } |
| 12448 | |
| 12449 | fp = bpf_prog_select_runtime(fp, &err); |
| 12450 | if (err) |
| 12451 | goto out_err; |
| 12452 | |
| 12453 | progs->ptrs[which] = fp; |
| 12454 | } |
| 12455 | |
| 12456 | /* The last entry contains a NULL program pointer */ |
| 12457 | progs->map.max_entries = ntests + 1; |
| 12458 | *pprogs = progs; |
| 12459 | return 0; |
| 12460 | |
| 12461 | out_nomem: |
| 12462 | err = -ENOMEM; |
| 12463 | |
| 12464 | out_err: |
| 12465 | if (progs) |
| 12466 | destroy_tail_call_tests(progs); |
| 12467 | return err; |
| 12468 | } |
| 12469 | |
| 12470 | static __init int test_tail_calls(struct bpf_array *progs) |
| 12471 | { |
| 12472 | int i, err_cnt = 0, pass_cnt = 0; |
| 12473 | int jit_cnt = 0, run_cnt = 0; |
| 12474 | |
| 12475 | for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) { |
| 12476 | struct tail_call_test *test = &tail_call_tests[i]; |
| 12477 | struct bpf_prog *fp = progs->ptrs[i]; |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12478 | int *data = NULL; |
| 12479 | int state = 0; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12480 | u64 duration; |
| 12481 | int ret; |
| 12482 | |
| 12483 | cond_resched(); |
| 12484 | |
| 12485 | pr_info("#%d %s ", i, test->descr); |
| 12486 | if (!fp) { |
| 12487 | err_cnt++; |
| 12488 | continue; |
| 12489 | } |
| 12490 | pr_cont("jited:%u ", fp->jited); |
| 12491 | |
| 12492 | run_cnt++; |
| 12493 | if (fp->jited) |
| 12494 | jit_cnt++; |
| 12495 | |
Johan Almbladh | 18935a7 | 2021-09-14 11:18:41 +0200 | [diff] [blame] | 12496 | if (test->flags & FLAG_NEED_STATE) |
| 12497 | data = &state; |
| 12498 | ret = __run_one(fp, data, MAX_TESTRUNS, &duration); |
| 12499 | if (test->flags & FLAG_RESULT_IN_STATE) |
| 12500 | ret = state; |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12501 | if (ret == test->result) { |
| 12502 | pr_cont("%lld PASS", duration); |
| 12503 | pass_cnt++; |
| 12504 | } else { |
| 12505 | pr_cont("ret %d != %d FAIL", ret, test->result); |
| 12506 | err_cnt++; |
| 12507 | } |
| 12508 | } |
| 12509 | |
| 12510 | pr_info("%s: Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n", |
| 12511 | __func__, pass_cnt, err_cnt, jit_cnt, run_cnt); |
| 12512 | |
| 12513 | return err_cnt ? -EINVAL : 0; |
| 12514 | } |
| 12515 | |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12516 | static int __init test_bpf_init(void) |
| 12517 | { |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12518 | struct bpf_array *progs = NULL; |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 12519 | int ret; |
| 12520 | |
| 12521 | ret = prepare_bpf_tests(); |
| 12522 | if (ret < 0) |
| 12523 | return ret; |
| 12524 | |
| 12525 | ret = test_bpf(); |
Daniel Borkmann | a4afd37b | 2015-05-13 13:12:43 +0200 | [diff] [blame] | 12526 | destroy_bpf_tests(); |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12527 | if (ret) |
| 12528 | return ret; |
| 12529 | |
Johan Almbladh | 874be05 | 2021-08-09 11:18:29 +0200 | [diff] [blame] | 12530 | ret = prepare_tail_call_tests(&progs); |
| 12531 | if (ret) |
| 12532 | return ret; |
| 12533 | ret = test_tail_calls(progs); |
| 12534 | destroy_tail_call_tests(progs); |
| 12535 | if (ret) |
| 12536 | return ret; |
| 12537 | |
Yonghong Song | 76db808 | 2018-03-21 16:31:04 -0700 | [diff] [blame] | 12538 | return test_skb_segment(); |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12539 | } |
| 12540 | |
| 12541 | static void __exit test_bpf_exit(void) |
| 12542 | { |
| 12543 | } |
| 12544 | |
| 12545 | module_init(test_bpf_init); |
| 12546 | module_exit(test_bpf_exit); |
Daniel Borkmann | 10f18e0 | 2014-05-23 18:44:00 +0200 | [diff] [blame] | 12547 | |
Alexei Starovoitov | 64a8946 | 2014-05-08 14:10:52 -0700 | [diff] [blame] | 12548 | MODULE_LICENSE("GPL"); |