mbox series

[v6,bpf-next,0/4] bpf: Introduce may_goto and cond_break

Message ID 20240306031929.42666-1-alexei.starovoitov@gmail.com (mailing list archive)
Headers show
Series bpf: Introduce may_goto and cond_break | expand

Message

Alexei Starovoitov March 6, 2024, 3:19 a.m. UTC
From: Alexei Starovoitov <ast@kernel.org>

v5 -> v6:
- Rename BPF_JMA to BPF_JCOND
- Addressed Andrii's review comments

v4 -> v5:
- rewrote patch 1 to avoid fake may_goto_reg and use 'u32 may_goto_cnt' instead.
  This way may_goto handling is similar to bpf_loop() processing.
- fixed bug in patch 2 that RANGE_WITHIN should not use
  rold->type == NOT_INIT as a safe signal.
- patch 3 fixed negative offset computation in cond_break macro
- using bpf_arena and cond_break recompiled lib/glob.c as bpf prog
  and it works! It will be added as a selftest to arena series.

v3 -> v4:
- fix drained issue reported by John.
  may_goto insn could be implemented with sticky state (once
  reaches 0 it stays 0), but the verifier shouldn't assume that.
  It has to explore both branches.
  Arguably drained iterator state shouldn't be there at all.
  bpf_iter_css_next() is not sticky. Can be fixed, but auditing all
  iterators for stickiness. That's an orthogonal discussion.
- explained JMA name reasons in patch 1
- fixed test_progs-no_alu32 issue and added another test

v2 -> v3: Major change
- drop bpf_can_loop() kfunc and introduce may_goto instruction instead
  kfunc is a function call while may_goto doesn't consume any registers
  and LLVM can produce much better code due to less register pressure.
- instead of counting from zero to BPF_MAX_LOOPS start from it instead
  and break out of the loop when count reaches zero
- use may_goto instruction in cond_break macro
- recognize that 'exact' state comparison doesn't need to be truly exact.
  regsafe() should ignore precision and liveness marks, but range_within
  logic is safe to use while evaluating open coded iterators.

Alexei Starovoitov (4):
  bpf: Introduce may_goto instruction
  bpf: Recognize that two registers are safe when their ranges match
  bpf: Add cond_break macro
  selftests/bpf: Test may_goto

 include/linux/bpf_verifier.h                  |   2 +
 include/uapi/linux/bpf.h                      |   5 +
 kernel/bpf/core.c                             |   1 +
 kernel/bpf/disasm.c                           |   4 +
 kernel/bpf/verifier.c                         | 212 +++++++++++++-----
 tools/include/uapi/linux/bpf.h                |   5 +
 tools/testing/selftests/bpf/DENYLIST.s390x    |   1 +
 .../testing/selftests/bpf/bpf_experimental.h  |  12 +
 .../bpf/progs/verifier_iterating_callbacks.c  | 103 ++++++++-
 9 files changed, 292 insertions(+), 53 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org March 6, 2024, 6:50 p.m. UTC | #1
Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Tue,  5 Mar 2024 19:19:25 -0800 you wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> v5 -> v6:
> - Rename BPF_JMA to BPF_JCOND
> - Addressed Andrii's review comments
> 
> v4 -> v5:
> - rewrote patch 1 to avoid fake may_goto_reg and use 'u32 may_goto_cnt' instead.
>   This way may_goto handling is similar to bpf_loop() processing.
> - fixed bug in patch 2 that RANGE_WITHIN should not use
>   rold->type == NOT_INIT as a safe signal.
> - patch 3 fixed negative offset computation in cond_break macro
> - using bpf_arena and cond_break recompiled lib/glob.c as bpf prog
>   and it works! It will be added as a selftest to arena series.
> 
> [...]

Here is the summary with links:
  - [v6,bpf-next,1/4] bpf: Introduce may_goto instruction
    https://git.kernel.org/bpf/bpf-next/c/9c4cab4e6756
  - [v6,bpf-next,2/4] bpf: Recognize that two registers are safe when their ranges match
    https://git.kernel.org/bpf/bpf-next/c/cc570d85e66e
  - [v6,bpf-next,3/4] bpf: Add cond_break macro
    https://git.kernel.org/bpf/bpf-next/c/7825948e135b
  - [v6,bpf-next,4/4] selftests/bpf: Test may_goto
    https://git.kernel.org/bpf/bpf-next/c/8089b99d4649

You are awesome, thank you!
John Fastabend March 6, 2024, 7:15 p.m. UTC | #2
patchwork-bot+netdevbpf@ wrote:
> Hello:
> 
> This series was applied to bpf/bpf-next.git (master)
> by Andrii Nakryiko <andrii@kernel.org>:
> 
> On Tue,  5 Mar 2024 19:19:25 -0800 you wrote:
> > From: Alexei Starovoitov <ast@kernel.org>
> > 
> > v5 -> v6:
> > - Rename BPF_JMA to BPF_JCOND
> > - Addressed Andrii's review comments
> > 
> > v4 -> v5:
> > - rewrote patch 1 to avoid fake may_goto_reg and use 'u32 may_goto_cnt' instead.
> >   This way may_goto handling is similar to bpf_loop() processing.
> > - fixed bug in patch 2 that RANGE_WITHIN should not use
> >   rold->type == NOT_INIT as a safe signal.
> > - patch 3 fixed negative offset computation in cond_break macro
> > - using bpf_arena and cond_break recompiled lib/glob.c as bpf prog
> >   and it works! It will be added as a selftest to arena series.
> > 
> > [...]
> 
> Here is the summary with links:
>   - [v6,bpf-next,1/4] bpf: Introduce may_goto instruction
>     https://git.kernel.org/bpf/bpf-next/c/9c4cab4e6756
>   - [v6,bpf-next,2/4] bpf: Recognize that two registers are safe when their ranges match
>     https://git.kernel.org/bpf/bpf-next/c/cc570d85e66e
>   - [v6,bpf-next,3/4] bpf: Add cond_break macro
>     https://git.kernel.org/bpf/bpf-next/c/7825948e135b
>   - [v6,bpf-next,4/4] selftests/bpf: Test may_goto
>     https://git.kernel.org/bpf/bpf-next/c/8089b99d4649
> 
> You are awesome, thank you!
> -- 
> Deet-doot-dot, I am a bot.
> https://korg.docs.kernel.org/patchwork/pwbot.html
> 
> 

Fwiw, I've been running this for a few days converting things to it.

Tested-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>