From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>, Tejun Heo <tj@kernel.org>
Subject: [PATCH bpf-next 00/17] BPF open-coded iterators
Date: Thu, 2 Mar 2023 15:49:58 -0800 [thread overview]
Message-ID: <20230302235015.2044271-1-andrii@kernel.org> (raw)
Add support for open-coded (aka inline) iterators in BPF world. This is a next
evolution of gradually allowing more powerful and less restrictive looping and
iteration capabilities to BPF programs.
We set up a framework for implementing all kinds of iterators (e.g., cgroup,
task, file, etc, iterators), but this patch set only implements numbers
iterator, which is used to implement ergonomic bpf_for() for-like construct
(see patch #15). We also add bpf_for_each(), which is a generic foreach-like
construct that will work with any kind of open-coded iterator implementation,
as long as we stick with bpf_iter_<type>_{new,next,destroy}() naming pattern.
Patches #1 through #12 are various preparatory patches, first eitht of them
are from preliminaries patch set ([0]) which haven't landed yet, so I just
merged them together to let CI do end-to-end testing of everything properly.
Few new patches further adds some necessary functionality in verifier (like
fixed-size read-only memory access for `int *`-returning kfuncs).
The meat of verifier-side logic is in lucky patch #13. Patch #14 implements
numbers iterator. I kept them separate to have clean reference for how to
integrate new iterator types. And it makes verifier core logic changes
abstracted from any particularities of numbers iterator. Patch #15 adds
bpf_for(), bpf_for_each(), and bpf_repeat() macros to bpf_misc.h, and also
adds yet another pyperf test variant, now with bpf_for() loop. Patch #16 is
verification tests, based on numbers iterator (as the only available right
now). Patch #17 actually tests runtime behavior of numbers iterator.
Most of the relevant details are in corresponding commit messages or code
comments.
[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=725996&state=*
Cc: Tejun Heo <tj@kernel.org>
Andrii Nakryiko (17):
bpf: improve stack slot state printing
bpf: improve regsafe() checks for PTR_TO_{MEM,BUF,TP_BUFFER}
selftests/bpf: enhance align selftest's expected log matching
bpf: honor env->test_state_freq flag in is_state_visited()
selftests/bpf: adjust log_fixup's buffer size for proper truncation
bpf: clean up visit_insn()'s instruction processing
bpf: fix visit_insn()'s detection of BPF_FUNC_timer_set_callback
helper
bpf: ensure that r0 is marked scratched after any function call
bpf: move kfunc_call_arg_meta higher in the file
bpf: mark PTR_TO_MEM as non-null register type
bpf: generalize dynptr_get_spi to be usable for iters
bpf: add support for fixed-size memory pointer returns for kfuncs
bpf: add support for open-coded iterator loops
bpf: implement number iterator
selftests/bpf: add bpf_for_each(), bpf_for(), and bpf_repeat() macros
selftests/bpf: add iterators tests
selftests/bpf: add number iterator tests
include/linux/bpf.h | 19 +-
include/linux/bpf_verifier.h | 22 +-
include/uapi/linux/bpf.h | 6 +
kernel/bpf/bpf_iter.c | 71 ++
kernel/bpf/helpers.c | 3 +
kernel/bpf/verifier.c | 851 ++++++++++++++++--
tools/include/uapi/linux/bpf.h | 6 +
.../testing/selftests/bpf/prog_tests/align.c | 18 +-
.../bpf/prog_tests/bpf_verif_scale.c | 6 +
.../testing/selftests/bpf/prog_tests/iters.c | 62 ++
.../selftests/bpf/prog_tests/log_fixup.c | 2 +-
.../bpf/prog_tests/uprobe_autoattach.c | 1 -
tools/testing/selftests/bpf/progs/bpf_misc.h | 77 ++
tools/testing/selftests/bpf/progs/iters.c | 720 +++++++++++++++
.../selftests/bpf/progs/iters_looping.c | 163 ++++
tools/testing/selftests/bpf/progs/iters_num.c | 242 +++++
.../selftests/bpf/progs/iters_state_safety.c | 455 ++++++++++
tools/testing/selftests/bpf/progs/lsm.c | 4 +-
tools/testing/selftests/bpf/progs/pyperf.h | 14 +-
.../selftests/bpf/progs/pyperf600_iter.c | 7 +
.../selftests/bpf/progs/pyperf600_nounroll.c | 3 -
21 files changed, 2641 insertions(+), 111 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/iters.c
create mode 100644 tools/testing/selftests/bpf/progs/iters.c
create mode 100644 tools/testing/selftests/bpf/progs/iters_looping.c
create mode 100644 tools/testing/selftests/bpf/progs/iters_num.c
create mode 100644 tools/testing/selftests/bpf/progs/iters_state_safety.c
create mode 100644 tools/testing/selftests/bpf/progs/pyperf600_iter.c
--
2.30.2
next reply other threads:[~2023-03-02 23:50 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 23:49 Andrii Nakryiko [this message]
2023-03-02 23:49 ` [PATCH bpf-next 01/17] bpf: improve stack slot state printing Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 02/17] bpf: improve regsafe() checks for PTR_TO_{MEM,BUF,TP_BUFFER} Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 03/17] selftests/bpf: enhance align selftest's expected log matching Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 04/17] bpf: honor env->test_state_freq flag in is_state_visited() Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 05/17] selftests/bpf: adjust log_fixup's buffer size for proper truncation Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 06/17] bpf: clean up visit_insn()'s instruction processing Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 07/17] bpf: fix visit_insn()'s detection of BPF_FUNC_timer_set_callback helper Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 08/17] bpf: ensure that r0 is marked scratched after any function call Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 09/17] bpf: move kfunc_call_arg_meta higher in the file Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 10/17] bpf: mark PTR_TO_MEM as non-null register type Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 11/17] bpf: generalize dynptr_get_spi to be usable for iters Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 12/17] bpf: add support for fixed-size memory pointer returns for kfuncs Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 13/17] bpf: add support for open-coded iterator loops Andrii Nakryiko
2023-03-04 20:02 ` Alexei Starovoitov
2023-03-04 23:27 ` Andrii Nakryiko
2023-03-05 23:46 ` Alexei Starovoitov
2023-03-07 21:54 ` Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 14/17] bpf: implement number iterator Andrii Nakryiko
2023-03-04 20:21 ` Alexei Starovoitov
2023-03-04 23:27 ` Andrii Nakryiko
2023-03-05 23:49 ` Alexei Starovoitov
2023-03-02 23:50 ` [PATCH bpf-next 15/17] selftests/bpf: add bpf_for_each(), bpf_for(), and bpf_repeat() macros Andrii Nakryiko
2023-03-04 20:34 ` Alexei Starovoitov
2023-03-04 23:28 ` Andrii Nakryiko
2023-03-06 0:12 ` Alexei Starovoitov
2023-03-07 21:54 ` Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 16/17] selftests/bpf: add iterators tests Andrii Nakryiko
2023-03-04 20:39 ` Alexei Starovoitov
2023-03-04 23:29 ` Andrii Nakryiko
2023-03-06 0:14 ` Alexei Starovoitov
2023-03-04 21:09 ` Jiri Olsa
2023-03-04 23:29 ` Andrii Nakryiko
2023-03-02 23:50 ` [PATCH bpf-next 17/17] selftests/bpf: add number iterator tests Andrii Nakryiko
2023-03-04 19:30 ` [PATCH bpf-next 00/17] BPF open-coded iterators patchwork-bot+netdevbpf
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=20230302235015.2044271-1-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=tj@kernel.org \
/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