From: sashiko-bot@kernel.org
To: "Eduard Zingerman" <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next v2 2/6] bpf: compute loops hierarchy
Date: Tue, 26 May 2026 20:26:35 +0000 [thread overview]
Message-ID: <20260526202635.6FBC91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260526-better-1m-reporting-v2-2-e7ec61c45d41@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Worst-case O(N^2) algorithmic complexity in assign_header() lacking cond_resched() leads to soft lockup.
--
commit 5ba437ec70f22b36c162a26467753448539086e8
Author: Eduard Zingerman <eddyz87@gmail.com>
bpf: compute loops hierarchy
This commit introduces an analysis phase to the bpf verifier that computes
the loops hierarchy using a non-recursive adaptation of the Wei et al.
algorithm. It records the innermost loop header per instruction to be used
as sampling points for callchain profiling.
> diff --git a/kernel/bpf/loops.c b/kernel/bpf/loops.c
> new file mode 100644
> index 0000000000000..1f0b10c57957a
> --- /dev/null
> +++ b/kernel/bpf/loops.c
[ ... ]
> +static int assign_header(struct bpf_verifier_env *env, struct loops_dfs *dfs, int n, int h)
> +{
> + struct bpf_insn_aux_data *aux = env->insn_aux_data;
> + int *dfs_pos = dfs->dfs_pos;
> + int err, nh;
> +
> + err = mark_header(env, h);
> + if (err)
> + return err;
> +
> + /* Don't encode self-loops, otherwise can't reflect loops nesting structure. */
> + if (n == h)
> + return 0;
> +
> + /* Make sure that loop headers up the chain are sorted by dfs_pos. */
> + while (aux[n].loop_header != -1) {
> + nh = aux[n].loop_header;
> + if (nh == h)
> + return 0;
> + if (dfs_pos[nh] < dfs_pos[h]) {
> + aux[n].loop_header = h;
> + n = h;
> + h = nh;
> + } else {
> + n = nh;
> + }
> + }
[Severity: High]
Could this while loop lead to a cpu soft lockup under specific pathological
conditions?
With deeply nested loops and cross-edges, it appears possible to force
repeated O(n) traversals of this header chain for O(n) nodes without
actually modifying the chain. Given the 1 million bpf instruction limit,
this worst-case O(n^2) algorithmic complexity might result in a massive
number of iterations.
Because neither this chain traversal nor the surrounding search algorithm in
compute_loops_in_subprog() seem to call cond_resched(), does this risk
stalling the cpu core long enough to trigger a system soft lockup or a
local denial of service?
> + aux[n].loop_header = h;
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260526-better-1m-reporting-v2-0-e7ec61c45d41@gmail.com?part=2
next prev parent reply other threads:[~2026-05-26 20:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 19:37 [PATCH RFC bpf-next v2 0/6] bpf: better error reporting when verifier hits 1M instructions limit Eduard Zingerman
2026-05-26 19:37 ` [PATCH RFC bpf-next v2 1/6] bpf: move live registers and scc printout to a standalone function Eduard Zingerman
2026-05-26 19:37 ` [PATCH RFC bpf-next v2 2/6] bpf: compute loops hierarchy Eduard Zingerman
2026-05-26 20:26 ` sashiko-bot [this message]
2026-05-26 20:33 ` Eduard Zingerman
2026-05-26 19:37 ` [PATCH RFC bpf-next v2 3/6] selftests/bpf: test cases for loop hierarchy computation Eduard Zingerman
2026-05-26 19:37 ` [PATCH RFC bpf-next v2 4/6] bpf: report hot simulated callchains when 1M instructions limit is met Eduard Zingerman
2026-05-26 19:37 ` [PATCH RFC bpf-next v2 5/6] bpf: report register diff summary for hot callchains Eduard Zingerman
2026-05-26 20:17 ` bot+bpf-ci
2026-05-26 20:35 ` Eduard Zingerman
2026-05-26 21:31 ` sashiko-bot
2026-05-26 23:24 ` Eduard Zingerman
2026-05-26 19:37 ` [PATCH RFC bpf-next v2 6/6] selftests/bpf: test budget exhaustion profiling report Eduard Zingerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260526202635.6FBC91F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox