bpf_verif_scale.c 3.2 KB
Newer Older
1 2 3 4 5 6
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019 Facebook
#include <test_progs.h>
static int libbpf_debug_print(enum libbpf_print_level level,
			      const char *format, va_list args)
{
7
	if (level != LIBBPF_DEBUG) {
8
		vprintf(format, args);
9 10
		return 0;
	}
11 12 13

	if (!strstr(format, "verifier log"))
		return 0;
14
	vprintf("%s", args);
15
	return 0;
16 17
}

18 19
extern int extra_prog_load_log_flags;

20
static int check_load(const char *file, enum bpf_prog_type type)
21 22
{
	struct bpf_prog_load_attr attr;
23
	struct bpf_object *obj = NULL;
24 25 26 27
	int err, prog_fd;

	memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
	attr.file = file;
28
	attr.prog_type = type;
29
	attr.log_level = 4 | extra_prog_load_log_flags;
30
	attr.prog_flags = BPF_F_TEST_RND_HI32;
31 32 33 34 35
	err = bpf_prog_load_xattr(&attr, &obj, &prog_fd);
	bpf_object__close(obj);
	return err;
}

36 37 38 39 40 41
struct scale_test_def {
	const char *file;
	enum bpf_prog_type attach_type;
	bool fails;
};

42 43
void test_bpf_verif_scale(void)
{
44 45 46 47 48 49 50
	struct scale_test_def tests[] = {
		{ "loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */ },

		{ "test_verif_scale1.o", BPF_PROG_TYPE_SCHED_CLS },
		{ "test_verif_scale2.o", BPF_PROG_TYPE_SCHED_CLS },
		{ "test_verif_scale3.o", BPF_PROG_TYPE_SCHED_CLS },

51
		{ "pyperf_global.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
52
		{ "pyperf_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
53

54
		/* full unroll by llvm */
55 56 57
		{ "pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
		{ "pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
		{ "pyperf180.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
58 59 60 61 62 63 64

		/* partial unroll. llvm will unroll loop ~150 times.
		 * C loop count -> 600.
		 * Asm loop count -> 4.
		 * 16k insns in loop body.
		 * Total of 5 such loops. Total program size ~82k insns.
		 */
65
		{ "pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
66 67 68 69 70 71 72

		/* no unroll at all.
		 * C loop count -> 600.
		 * ASM loop count -> 600.
		 * ~110 insns in loop body.
		 * Total of 5 such loops. Total program size ~1500 insns.
		 */
73
		{ "pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
74

75 76
		{ "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
		{ "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
77
		{ "loop4.o", BPF_PROG_TYPE_SCHED_CLS },
78
		{ "loop5.o", BPF_PROG_TYPE_SCHED_CLS },
79 80 81 82 83

		/* partial unroll. 19k insn in a loop.
		 * Total program size 20.8k insn.
		 * ~350k processed_insns
		 */
84
		{ "strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
85 86

		/* no unroll, tiny loops */
87 88 89
		{ "strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
		{ "strobemeta_nounroll2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

90 91 92
		/* non-inlined subprogs */
		{ "strobemeta_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

93 94 95 96 97
		{ "test_sysctl_loop1.o", BPF_PROG_TYPE_CGROUP_SYSCTL },
		{ "test_sysctl_loop2.o", BPF_PROG_TYPE_CGROUP_SYSCTL },

		{ "test_xdp_loop.o", BPF_PROG_TYPE_XDP },
		{ "test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL },
98
	};
99
	libbpf_print_fn_t old_print_fn = NULL;
100
	int err, i;
101

102 103
	if (env.verifier_stats) {
		test__force_log();
104
		old_print_fn = libbpf_set_print(libbpf_debug_print);
105
	}
106

107 108
	for (i = 0; i < ARRAY_SIZE(tests); i++) {
		const struct scale_test_def *test = &tests[i];
109

110 111
		if (!test__start_subtest(test->file))
			continue;
112

113
		err = check_load(test->file, test->attach_type);
114
		CHECK_FAIL(err && !test->fails);
115
	}
116

117
	if (env.verifier_stats)
118
		libbpf_set_print(old_print_fn);
119
}