1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2019 Facebook 3 #include <test_progs.h> 4 static int libbpf_debug_print(enum libbpf_print_level level, 5 const char *format, va_list args) 6 { 7 if (level != LIBBPF_DEBUG) { 8 vprintf(format, args); 9 return 0; 10 } 11 12 if (!strstr(format, "verifier log")) 13 return 0; 14 vprintf("%s", args); 15 return 0; 16 } 17 18 extern int extra_prog_load_log_flags; 19 20 static int check_load(const char *file, enum bpf_prog_type type) 21 { 22 struct bpf_object *obj = NULL; 23 struct bpf_program *prog; 24 int err; 25 26 obj = bpf_object__open_file(file, NULL); 27 err = libbpf_get_error(obj); 28 if (err) 29 return err; 30 31 prog = bpf_object__next_program(obj, NULL); 32 if (!prog) { 33 err = -ENOENT; 34 goto err_out; 35 } 36 37 bpf_program__set_type(prog, type); 38 bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32); 39 bpf_program__set_log_level(prog, 4 | extra_prog_load_log_flags); 40 41 err = bpf_object__load(obj); 42 43 err_out: 44 bpf_object__close(obj); 45 return err; 46 } 47 48 struct scale_test_def { 49 const char *file; 50 enum bpf_prog_type attach_type; 51 bool fails; 52 }; 53 54 static void scale_test(const char *file, 55 enum bpf_prog_type attach_type, 56 bool should_fail) 57 { 58 libbpf_print_fn_t old_print_fn = NULL; 59 int err; 60 61 if (env.verifier_stats) { 62 test__force_log(); 63 old_print_fn = libbpf_set_print(libbpf_debug_print); 64 } 65 66 err = check_load(file, attach_type); 67 if (should_fail) 68 ASSERT_ERR(err, "expect_error"); 69 else 70 ASSERT_OK(err, "expect_success"); 71 72 if (env.verifier_stats) 73 libbpf_set_print(old_print_fn); 74 } 75 76 void test_verif_scale1() 77 { 78 scale_test("test_verif_scale1.o", BPF_PROG_TYPE_SCHED_CLS, false); 79 } 80 81 void test_verif_scale2() 82 { 83 scale_test("test_verif_scale2.o", BPF_PROG_TYPE_SCHED_CLS, false); 84 } 85 86 void test_verif_scale3() 87 { 88 scale_test("test_verif_scale3.o", BPF_PROG_TYPE_SCHED_CLS, false); 89 } 90 91 void test_verif_scale_pyperf_global() 92 { 93 scale_test("pyperf_global.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 94 } 95 96 void test_verif_scale_pyperf_subprogs() 97 { 98 scale_test("pyperf_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 99 } 100 101 void test_verif_scale_pyperf50() 102 { 103 /* full unroll by llvm */ 104 scale_test("pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 105 } 106 107 void test_verif_scale_pyperf100() 108 { 109 /* full unroll by llvm */ 110 scale_test("pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 111 } 112 113 void test_verif_scale_pyperf180() 114 { 115 /* full unroll by llvm */ 116 scale_test("pyperf180.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 117 } 118 119 void test_verif_scale_pyperf600() 120 { 121 /* partial unroll. llvm will unroll loop ~150 times. 122 * C loop count -> 600. 123 * Asm loop count -> 4. 124 * 16k insns in loop body. 125 * Total of 5 such loops. Total program size ~82k insns. 126 */ 127 scale_test("pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 128 } 129 130 void test_verif_scale_pyperf600_bpf_loop(void) 131 { 132 /* use the bpf_loop helper*/ 133 scale_test("pyperf600_bpf_loop.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 134 } 135 136 void test_verif_scale_pyperf600_nounroll() 137 { 138 /* no unroll at all. 139 * C loop count -> 600. 140 * ASM loop count -> 600. 141 * ~110 insns in loop body. 142 * Total of 5 such loops. Total program size ~1500 insns. 143 */ 144 scale_test("pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 145 } 146 147 void test_verif_scale_loop1() 148 { 149 scale_test("loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 150 } 151 152 void test_verif_scale_loop2() 153 { 154 scale_test("loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 155 } 156 157 void test_verif_scale_loop3_fail() 158 { 159 scale_test("loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */); 160 } 161 162 void test_verif_scale_loop4() 163 { 164 scale_test("loop4.o", BPF_PROG_TYPE_SCHED_CLS, false); 165 } 166 167 void test_verif_scale_loop5() 168 { 169 scale_test("loop5.o", BPF_PROG_TYPE_SCHED_CLS, false); 170 } 171 172 void test_verif_scale_loop6() 173 { 174 scale_test("loop6.o", BPF_PROG_TYPE_KPROBE, false); 175 } 176 177 void test_verif_scale_strobemeta() 178 { 179 /* partial unroll. 19k insn in a loop. 180 * Total program size 20.8k insn. 181 * ~350k processed_insns 182 */ 183 scale_test("strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 184 } 185 186 void test_verif_scale_strobemeta_bpf_loop(void) 187 { 188 /* use the bpf_loop helper*/ 189 scale_test("strobemeta_bpf_loop.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 190 } 191 192 void test_verif_scale_strobemeta_nounroll1() 193 { 194 /* no unroll, tiny loops */ 195 scale_test("strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 196 } 197 198 void test_verif_scale_strobemeta_nounroll2() 199 { 200 /* no unroll, tiny loops */ 201 scale_test("strobemeta_nounroll2.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 202 } 203 204 void test_verif_scale_strobemeta_subprogs() 205 { 206 /* non-inlined subprogs */ 207 scale_test("strobemeta_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 208 } 209 210 void test_verif_scale_sysctl_loop1() 211 { 212 scale_test("test_sysctl_loop1.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false); 213 } 214 215 void test_verif_scale_sysctl_loop2() 216 { 217 scale_test("test_sysctl_loop2.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false); 218 } 219 220 void test_verif_scale_xdp_loop() 221 { 222 scale_test("test_xdp_loop.o", BPF_PROG_TYPE_XDP, false); 223 } 224 225 void test_verif_scale_seg6_loop() 226 { 227 scale_test("test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL, false); 228 } 229 230 void test_verif_twfw() 231 { 232 scale_test("twfw.o", BPF_PROG_TYPE_CGROUP_SKB, false); 233 } 234