Commit e310efc5 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

selftests/bpf: allow to adjust BPF verifier log level in veristat



Add -l (--log-level) flag to override default BPF verifier log lever.
This only matters in verbose mode, which is the mode in which veristat
emits verifier log for each processed BPF program.

This is important because for successfully verified BPF programs
log_level 1 is empty, as BPF verifier truncates all the successfully
verified paths. So -l2 is the only way to actually get BPF verifier log
in practice. It looks sometihng like this:

  [vmuser@archvm bpf]$ sudo ./veristat xdp_tx.bpf.o -vl2
  Processing 'xdp_tx.bpf.o'...
  PROCESSING xdp_tx.bpf.o/xdp_tx, DURATION US: 19, VERDICT: success, VERIFIER LOG:
  func#0 @0
  0: R1=ctx(off=0,imm=0) R10=fp0
  ; return XDP_TX;
  0: (b4) w0 = 3                        ; R0_w=3
  1: (95) exit
  verification time 19 usec
  stack depth 0
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0

  File          Program  Verdict  Duration (us)  Total insns  Total states  Peak states
  ------------  -------  -------  -------------  -----------  ------------  -----------
  xdp_tx.bpf.o  xdp_tx   success             19            2             0            0
  ------------  -------  -------  -------------  -----------  ------------  -----------
  Done. Processed 1 files, 0 programs. Skipped 1 files, 0 programs.

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220923175913.3272430-6-andrii@kernel.org


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent c511d009
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ static struct env {
	int filename_cnt;
	bool verbose;
	bool quiet;
	int log_level;
	enum resfmt out_fmt;
	bool comparison_mode;

@@ -108,6 +109,7 @@ const char argp_program_doc[] =
static const struct argp_option opts[] = {
	{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" },
	{ "verbose", 'v', NULL, 0, "Verbose mode" },
	{ "log-level", 'l', "LEVEL", 0, "Verifier log level (default 0 for normal mode, 1 for verbose mode)" },
	{ "quiet", 'q', NULL, 0, "Quiet mode" },
	{ "emit", 'e', "SPEC", 0, "Specify stats to be emitted" },
	{ "sort", 's', "SPEC", 0, "Specify sort order" },
@@ -156,6 +158,14 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
			return -EINVAL;
		}
		break;
	case 'l':
		errno = 0;
		env.log_level = strtol(arg, NULL, 10);
		if (errno) {
			fprintf(stderr, "invalid log level: %s\n", arg);
			argp_usage(state);
		}
		break;
	case 'C':
		env.comparison_mode = true;
		break;
@@ -526,7 +536,7 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf
		if (!buf)
			return -ENOMEM;
		bpf_program__set_log_buf(prog, buf, buf_sz);
		bpf_program__set_log_level(prog, 1 | 4); /* stats + log */
		bpf_program__set_log_level(prog, env.log_level | 4); /* stats + log */
	} else {
		bpf_program__set_log_buf(prog, buf, buf_sz);
		bpf_program__set_log_level(prog, 4); /* only verifier stats */
@@ -1280,6 +1290,8 @@ int main(int argc, char **argv)
		argp_help(&argp, stderr, ARGP_HELP_USAGE, "veristat");
		return 1;
	}
	if (env.verbose && env.log_level == 0)
		env.log_level = 1;

	if (env.output_spec.spec_cnt == 0)
		env.output_spec = default_output_spec;