BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/8] bpf: Mark loop heads in check_cfg()
Date: Wed, 23 Sep 2026 23:05:23 +0000	[thread overview]
Message-ID: <20260923230524.339091F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260923223554.562379-3-alexei.starovoitov@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: stale CFG backedge metadata causes incorrect loop detection
--

commit de7e162d2062bfebc2e588cb33048e1edec24938
Author: Alexei Starovoitov <ast@kernel.org>

bpf: Mark loop heads in check_cfg()

check_cfg() finds back-edges while it walks the control flow graph.
Remember their targets as loop heads and which edge of the insn is
the back-edge. The main pass needs it to tell the state that enters
the loop from the state that went around it.
No functional change.

> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
> index 92f528c456052..5a08f079a4896 100644
> --- a/include/linux/bpf_verifier.h
> +++ b/include/linux/bpf_verifier.h
> @@ -709,6 +709,9 @@ struct bpf_insn_aux_data {
>  	u32 non_stack_access:1; /* instruction can access non-stack memory */
>  	/* true if some jump or call instruction targets this instruction */
>  	u32 jump_target:1;
> +	u32 loop_head:1; /* target of a back-edge */
> +	u32 backedge_ft:1; /* the edge to the next insn is a back-edge */
> +	u32 backedge_br:1; /* the jump is a back-edge */

[Severity: High]
Does this new CFG metadata need to be cleared when dead conditional jumps are
rewritten?

When bpf_prune_dead_branches() in kernel/bpf/const_fold.c rewrites dead
conditional jumps into unconditional BPF_JA jumps:

kernel/bpf/const_fold.c:bpf_prune_dead_branches()
    *insn = BPF_JMP_A(taken ? insn->off : 0);
    changed = true;

it does not seem to clear the newly added backedge_br or backedge_ft metadata.

If a pruned branch was a back-edge but the actually taken branch is a forward
edge, and a later function like is_backedge() assumes unconditional jumps have
only a single edge:

kernel/bpf/states.c:is_backedge()
    if ((BPF_CLASS(insn->code) == BPF_JMP || BPF_CLASS(insn->code) == BPF_JMP32) &&
        BPF_OP(insn->code) == BPF_JA)
        return aux->backedge_ft || aux->backedge_br;

could this stale metadata cause forward edges to be incorrectly classified as
loop back-edges? This might lead to spurious state widening and the addition
of unnecessary may_goto loop guards.

>  	/*
>  	 * CFG strongly connected component this instruction belongs to,
>  	 * zero if it is a singleton SCC.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923223554.562379-1-alexei.starovoitov@gmail.com?part=2

  reply	other threads:[~2026-09-23 23:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 22:35 [PATCH bpf-next 0/8] bpf: Verify loops without walking every iteration Alexei Starovoitov
2026-09-23 22:35 ` [PATCH bpf-next 1/8] bpf: Trim range ends to var_off members Alexei Starovoitov
2026-09-23 23:37   ` bot+bpf-ci
2026-09-23 22:35 ` [PATCH bpf-next 2/8] bpf: Mark loop heads in check_cfg() Alexei Starovoitov
2026-09-23 23:05   ` sashiko-bot [this message]
2026-09-23 23:37   ` bot+bpf-ci
2026-09-23 22:35 ` [PATCH bpf-next 3/8] bpf: Widen scalars at loop heads Alexei Starovoitov
2026-09-23 23:37   ` bot+bpf-ci
2026-09-23 22:35 ` [PATCH bpf-next 4/8] bpf: Detect loops that never exit Alexei Starovoitov
2026-09-23 23:25   ` sashiko-bot
2026-09-23 23:37   ` bot+bpf-ci
2026-09-23 22:35 ` [PATCH bpf-next 5/8] bpf: Add may_goto to loops that are not walked to the end Alexei Starovoitov
2026-09-23 23:37   ` bot+bpf-ci
2026-09-23 23:48   ` sashiko-bot
2026-09-23 22:35 ` [PATCH bpf-next 6/8] bpf: Walk loops with widened states first Alexei Starovoitov
2026-09-23 23:23   ` bot+bpf-ci
2026-09-23 22:35 ` [PATCH bpf-next 7/8] selftests/bpf: Adjust tests to widened loops Alexei Starovoitov
2026-09-23 23:37   ` bot+bpf-ci
2026-09-23 22:35 ` [PATCH bpf-next 8/8] selftests/bpf: Add tests for " Alexei Starovoitov
2026-09-23 23:23   ` bot+bpf-ci

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=20260923230524.339091F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --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