Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Increase verifier log limit in veristat

The current default buffer size of 16MB allocated by veristat is no
longer sufficient to hold the verifier logs of some production BPF
programs. To address this issue, we need to increase the verifier log
limit.
Commit 7a9f5c65abcc ("bpf: increase verifier log limit") has already
increased the supported buffer size by the kernel, but veristat users
need to explicitly pass a log size argument to use the bigger log.

This patch adds a function to detect the maximum verifier log size
supported by the kernel and uses that by default in veristat.
This ensures that veristat can handle larger verifier logs without
requiring users to manually specify the log size.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20241023155314.126255-1-mykyta.yatsenko5@gmail.com

authored by

Mykyta Yatsenko and committed by
Andrii Nakryiko
1f7c3363 efe79219

+31 -1
+31 -1
tools/testing/selftests/bpf/veristat.c
··· 16 16 #include <sys/stat.h> 17 17 #include <bpf/libbpf.h> 18 18 #include <bpf/btf.h> 19 + #include <bpf/bpf.h> 19 20 #include <libelf.h> 20 21 #include <gelf.h> 21 22 #include <float.h> ··· 1110 1109 return; 1111 1110 } 1112 1111 1112 + static int max_verifier_log_size(void) 1113 + { 1114 + const int SMALL_LOG_SIZE = UINT_MAX >> 8; 1115 + const int BIG_LOG_SIZE = UINT_MAX >> 2; 1116 + struct bpf_insn insns[] = { 1117 + { .code = BPF_ALU | BPF_MOV | BPF_X, .dst_reg = BPF_REG_0, }, 1118 + { .code = BPF_JMP | BPF_EXIT, }, 1119 + }; 1120 + LIBBPF_OPTS(bpf_prog_load_opts, opts, 1121 + .log_size = BIG_LOG_SIZE, 1122 + .log_buf = (void *)-1, 1123 + .log_level = 4 1124 + ); 1125 + int ret, insn_cnt = ARRAY_SIZE(insns); 1126 + static int log_size; 1127 + 1128 + if (log_size != 0) 1129 + return log_size; 1130 + 1131 + ret = bpf_prog_load(BPF_PROG_TYPE_TRACEPOINT, NULL, "GPL", insns, insn_cnt, &opts); 1132 + 1133 + if (ret == -EFAULT) 1134 + log_size = BIG_LOG_SIZE; 1135 + else /* ret == -EINVAL, big log size is not supported by the verifier */ 1136 + log_size = SMALL_LOG_SIZE; 1137 + 1138 + return log_size; 1139 + } 1140 + 1113 1141 static int process_prog(const char *filename, struct bpf_object *obj, struct bpf_program *prog) 1114 1142 { 1115 1143 const char *base_filename = basename(strdupa(filename)); ··· 1162 1132 memset(stats, 0, sizeof(*stats)); 1163 1133 1164 1134 if (env.verbose || env.top_src_lines > 0) { 1165 - buf_sz = env.log_size ? env.log_size : 16 * 1024 * 1024; 1135 + buf_sz = env.log_size ? env.log_size : max_verifier_log_size(); 1166 1136 buf = malloc(buf_sz); 1167 1137 if (!buf) 1168 1138 return -ENOMEM;