diff options
| author | Eduard Zingerman <ezingerman@fb.com> | 2026-10-09 03:47:49 -0700 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-10-09 20:29:14 +0000 |
| commit | 2fa579694ddf3a96454669c764ca0c06dea50817 (patch) | |
| tree | 02fdaac2826067c2abf8aa60b99cca2bde7ba2f0 /kernel | |
| parent | 1291ad5906933355fbe7b042ee5e3eedb5743e46 (diff) | |
| download | linux-next-2fa579694ddf3a96454669c764ca0c06dea50817.tar.gz linux-next-2fa579694ddf3a96454669c764ca0c06dea50817.zip | |
bpf: Record basic-block ends in insn_aux_data
SCEV needs information about the program's basic-block structure.
Piggyback on compute_predecessors() and set
insn_aux_data->bb_end for an instruction if:
- it has multiple successors, or
- its sole successor has multiple predecessors, or
- it is a jump instruction.
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20261009-scev-minimal-rebase-v3-31-bcba9bc53ac9@gmail.com
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/bpf/loops.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/kernel/bpf/loops.c b/kernel/bpf/loops.c index 8a6dc805e559..2568079c2945 100644 --- a/kernel/bpf/loops.c +++ b/kernel/bpf/loops.c @@ -5,8 +5,23 @@ #include <linux/sched/signal.h> #include <linux/bpf_verifier.h> +static bool is_cfg_jump(struct bpf_insn *insn) +{ + u8 class = BPF_CLASS(insn->code); + u8 opcode = BPF_OP(insn->code); + + switch (class) { + case BPF_JMP: + case BPF_JMP32: + return opcode != BPF_CALL; + default: + return false; + } +} + static struct bpf_iarray **compute_predecessors(struct bpf_verifier_env *env) { + struct bpf_insn_aux_data *aux = env->insn_aux_data; struct bpf_iarray *succ, *preds, **result; struct bpf_prog *prog = env->prog; u32 *num_preds, i, s, len = prog->len; @@ -54,6 +69,10 @@ static struct bpf_iarray **compute_predecessors(struct bpf_verifier_env *env) preds = result[s]; preds->items[preds->cnt++] = i; } + if (succ->cnt > 1 || + (succ->cnt == 1 && num_preds[succ->items[0]] > 1) || + is_cfg_jump(insn)) + aux[i].bb_end = true; if (bpf_is_ldimm64(insn)) i++; } |
