History

bpf: Don't run arg-tracking analysis twice on main subprog

Because subprog 0, the main subprog, is considered a global function, we end up running the arg-tracking dataflow analysis twice on it. That results in slightly longer verification but mostly in more verbose verifier logs. This patch fixes it by keeping only the iteration over global subprogs. When running over all of Cilium's programs with BPF_LOG_LEVEL2, this reduces verbosity by ~20% on average.

Paul Chaignon committed 6 months ago

Commit 512809b1 parent 18fc6501 file · +7 −18Browse files

Unified · Split

kernel/bpf/liveness.c+7−18
@@ -1914,26 +1914,15 @@ int bpf_compute_subprog_arg_access(struct bpf_verifier_env *env) · 1913 unmodified lines
19141914 return -ENOMEM;
19151915 }
19161916
1917− instance = call_instance(env, NULL, 0, 0);
1918− if (IS_ERR(instance)) {
1919− err = PTR_ERR(instance);
1920− goto out;
1921− }
1922− err = analyze_subprog(env, NULL, info, instance, callsites);
1923− if (err)
1924− goto out;
1925−
19261917 /*
1927− * Subprogs and callbacks that don't receive FP-derived arguments
1928− * cannot access ancestor stack frames, so they were skipped during
1929− * the recursive walk above. Async callbacks (timer, workqueue) are
1930− * also not reachable from the main program's call graph. Analyze
1931− * all unvisited subprogs as independent roots at depth 0.
1918+ * Analyze every subprog in reverse topological order (callers
1919+ * before callees) so that each subprog is analyzed before its
1920+ * callees, allowing the recursive walk inside analyze_subprog()
1921+ * to naturally reach callees that receive FP-derived args.
19321922 *
1933− * Use reverse topological order (callers before callees) so that
1934− * each subprog is analyzed before its callees, allowing the
1935− * recursive walk inside analyze_subprog() to naturally
1936− * reach nested callees that also lack FP-derived args.
1923+ * Subprogs and callbacks that don't receive FP-derived arguments
1924+ * cannot access ancestor stack frames are analyzed independently.
1925+ * Async callbacks (timer, workqueue) are handled the same way.
19371926 */
19381927 for (k = env->subprog_cnt - 1; k >= 0; k--) {
19391928 int sub = env->subprog_topo_order[k];