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, testing_prog_flags()); 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.bpf.o", BPF_PROG_TYPE_SCHED_CLS, false); 79 } 80 81 void test_verif_scale2() 82 { 83 scale_test("test_verif_scale2.bpf.o", BPF_PROG_TYPE_SCHED_CLS, false); 84 } 85 86 void test_verif_scale3() 87 { 88 scale_test("test_verif_scale3.bpf.o", BPF_PROG_TYPE_SCHED_CLS, false); 89 } 90 91 void test_verif_scale_pyperf_global() 92 { 93 scale_test("pyperf_global.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 94 } 95 96 void test_verif_scale_pyperf_subprogs() 97 { 98 scale_test("pyperf_subprogs.bpf.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.bpf.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.bpf.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.bpf.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.bpf.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.bpf.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.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 145 } 146 147 void test_verif_scale_pyperf600_iter() 148 { 149 /* open-coded BPF iterator version */ 150 scale_test("pyperf600_iter.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 151 } 152 153 void test_verif_scale_loop1() 154 { 155 scale_test("loop1.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 156 } 157 158 void test_verif_scale_loop2() 159 { 160 scale_test("loop2.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 161 } 162 163 void test_verif_scale_loop3_fail() 164 { 165 scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */); 166 } 167 168 void test_verif_scale_loop4() 169 { 170 scale_test("loop4.bpf.o", BPF_PROG_TYPE_SCHED_CLS, false); 171 } 172 173 void test_verif_scale_loop5() 174 { 175 scale_test("loop5.bpf.o", BPF_PROG_TYPE_SCHED_CLS, false); 176 } 177 178 void test_verif_scale_loop6() 179 { 180 scale_test("loop6.bpf.o", BPF_PROG_TYPE_KPROBE, false); 181 } 182 183 void test_verif_scale_strobemeta() 184 { 185 /* partial unroll. 19k insn in a loop. 186 * Total program size 20.8k insn. 187 * ~350k processed_insns 188 */ 189 scale_test("strobemeta.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 190 } 191 192 void test_verif_scale_strobemeta_bpf_loop(void) 193 { 194 /* use the bpf_loop helper*/ 195 scale_test("strobemeta_bpf_loop.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 196 } 197 198 void test_verif_scale_strobemeta_nounroll1() 199 { 200 /* no unroll, tiny loops */ 201 scale_test("strobemeta_nounroll1.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 202 } 203 204 void test_verif_scale_strobemeta_nounroll2() 205 { 206 /* no unroll, tiny loops */ 207 scale_test("strobemeta_nounroll2.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 208 } 209 210 void test_verif_scale_strobemeta_subprogs() 211 { 212 /* non-inlined subprogs */ 213 scale_test("strobemeta_subprogs.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); 214 } 215 216 void test_verif_scale_sysctl_loop1() 217 { 218 scale_test("test_sysctl_loop1.bpf.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false); 219 } 220 221 void test_verif_scale_sysctl_loop2() 222 { 223 scale_test("test_sysctl_loop2.bpf.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false); 224 } 225 226 void test_verif_scale_xdp_loop() 227 { 228 scale_test("test_xdp_loop.bpf.o", BPF_PROG_TYPE_XDP, false); 229 } 230 231 void test_verif_scale_seg6_loop() 232 { 233 scale_test("test_seg6_loop.bpf.o", BPF_PROG_TYPE_LWT_SEG6LOCAL, false); 234 } 235 236 void test_verif_twfw() 237 { 238 scale_test("twfw.bpf.o", BPF_PROG_TYPE_CGROUP_SKB, false); 239 } 240