Verifier diagnostics collect active-path history and render richer reports for selected verifier failures. That work is useful only when the caller requests normal verifier log output. Do not enable diagnostic collection or report rendering for BPF_LOG_STATS-only loads. Stats-only loads still need the verifier's summary counters, but not the extra path history used by diagnostic reports. Keep enablement in the verifier environment and requested log mode so async callback verification uses the same diagnostic policy as the main verifier pass. Signed-off-by: Kumar Kartikeya Dwivedi --- kernel/bpf/verifier.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f7c5beb88217..9da36f850748 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5509,7 +5509,9 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx, * of caller's stack as shown on the example above. */ if (idx && subprog[idx].has_tail_call && depth >= 256) { - char *chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); + char *chain = bpf_diag_enabled(env) ? + bpf_diag_alloc_subprog_call_chain(env, dinfo, idx) : + NULL; verbose(env, "tail_calls are not allowed when call stack of previous frames is %d bytes. Too large\n", @@ -5543,11 +5545,12 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx, if (subprog_depth > env->max_stack_depth) env->max_stack_depth = subprog_depth; if (subprog_depth > MAX_BPF_STACK) { - char *chain; + char *chain = NULL; verbose(env, "stack size of subprog %d is %d. Too large\n", idx, subprog_depth); - chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); + if (bpf_diag_enabled(env)) + chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); bpf_diag_report_limit(env, subprog[idx].start, "subprogram stack depth", "Reduce stack usage in this subprogram, or move " "large data out of the BPF stack.", @@ -5571,9 +5574,10 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx, verbose(env, "combined stack size of %d calls is %d. Too large\n", total, depth); { - char *chain; + char *chain = NULL; - chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); + if (bpf_diag_enabled(env)) + chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); bpf_diag_report_limit(env, subprog[idx].start, "combined call stack depth", "Reduce stack usage or call depth along this " @@ -5654,11 +5658,12 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx, frame = bpf_subprog_is_global(env, idx) ? 0 : frame + 1; if (frame >= MAX_CALL_FRAMES) { - char *chain; + char *chain = NULL; verbose(env, "the call stack of %d frames is too deep !\n", frame); - chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); + if (bpf_diag_enabled(env)) + chain = bpf_diag_alloc_subprog_call_chain(env, dinfo, idx); bpf_diag_report_limit(env, call_insn, "bpf2bpf call frames", "Reduce the number of nested bpf2bpf calls on this " "path.", @@ -9963,11 +9968,12 @@ static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int calls int err; if (state->curframe + 1 >= MAX_CALL_FRAMES) { - char *chain; + char *chain = NULL; verbose(env, "the call stack of %d frames is too deep\n", state->curframe + 2); - chain = bpf_diag_alloc_state_call_chain(env, state, subprog); + if (bpf_diag_enabled(env)) + chain = bpf_diag_alloc_state_call_chain(env, state, subprog); bpf_diag_report_limit(env, callsite, "bpf2bpf call frames", "Reduce the number of nested bpf2bpf calls on this path.", "Call chain %s would create %d verifier call frames, " -- 2.53.0