Message ID | 20240301033734.95939-1-alexei.starovoitov@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | bpf: Introduce may_goto and cond_break | expand |
Alexei Starovoitov wrote: > From: Alexei Starovoitov <ast@kernel.org> > > 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. Nice back to the original instruction idea for loops. I was walking around thinking about this for last day or so and had the same thought, but you beat me to it. The original troublesome parts was jumps into the loop. But will read on to see the solution. > - 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. I will need to review last bit is too dense for me to process right now. I think this will be useful for lots of cases. > > 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 | 1 + > kernel/bpf/core.c | 1 + > kernel/bpf/disasm.c | 3 + > kernel/bpf/verifier.c | 269 +++++++++++++----- > tools/include/uapi/linux/bpf.h | 1 + > tools/testing/selftests/bpf/DENYLIST.s390x | 1 + > .../testing/selftests/bpf/bpf_experimental.h | 12 + > .../bpf/progs/verifier_iterating_callbacks.c | 72 ++++- > 9 files changed, 291 insertions(+), 71 deletions(-) > > -- > 2.34.1 > >
On Thu, 2024-02-29 at 19:37 -0800, Alexei Starovoitov wrote: > From: Alexei Starovoitov <ast@kernel.org> > > 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. Sorry for the delay, I will look through this patch-set over the weekend.
On Fri, Mar 1, 2024 at 5:20 PM Eduard Zingerman <eddyz87@gmail.com> wrote: > > On Thu, 2024-02-29 at 19:37 -0800, Alexei Starovoitov wrote: > > From: Alexei Starovoitov <ast@kernel.org> > > > > 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. > > Sorry for the delay, I will look through this patch-set over the weekend. I fixed the drain issue reported by John, fixed no_alu32, and will resubmit soon. Ignore this set.
From: Alexei Starovoitov <ast@kernel.org> 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 | 1 + kernel/bpf/core.c | 1 + kernel/bpf/disasm.c | 3 + kernel/bpf/verifier.c | 269 +++++++++++++----- tools/include/uapi/linux/bpf.h | 1 + tools/testing/selftests/bpf/DENYLIST.s390x | 1 + .../testing/selftests/bpf/bpf_experimental.h | 12 + .../bpf/progs/verifier_iterating_callbacks.c | 72 ++++- 9 files changed, 291 insertions(+), 71 deletions(-)