mbox series

[RFC,bpf-next,0/2] bpf: bpf link iterator

Message ID 20220422182254.13693-1-9erthalion6@gmail.com (mailing list archive)
Headers show
Series bpf: bpf link iterator | expand

Message

Dmitry Dolgov April 22, 2022, 6:22 p.m. UTC
Bpf links seem to be one of the important structures for which no
iterator is provided. Such iterator could be useful in those cases when
generic 'task/file' is not suitable or better performance is needed.

The implementation is mostly copied from prog iterator, and I would like
to get any high-level feedback about what needs to be different or have
to be taken into account. As a side note, I would also appreciate if
someone could point me out to some guide about writing selftests for bpf
subsystem -- for some unclear reason I couldn't compile the test from
this changeset, and was testing it only manually with a custom test
program.

Dmitrii Dolgov (2):
  bpf: Add bpf_link iterator
  selftests/bpf: Add bpf_link test

 include/linux/bpf.h                           |   1 +
 kernel/bpf/Makefile                           |   2 +-
 kernel/bpf/link_iter.c                        | 107 ++++++++++++++++++
 kernel/bpf/syscall.c                          |  19 ++++
 .../selftests/bpf/prog_tests/bpf_iter.c       |  15 +++
 .../selftests/bpf/progs/bpf_iter_bpf_link.c   |  18 +++
 6 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 kernel/bpf/link_iter.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c

Comments

Andrii Nakryiko April 27, 2022, 7:04 p.m. UTC | #1
On Fri, Apr 22, 2022 at 11:23 AM Dmitrii Dolgov <9erthalion6@gmail.com> wrote:
>
> Bpf links seem to be one of the important structures for which no
> iterator is provided. Such iterator could be useful in those cases when
> generic 'task/file' is not suitable or better performance is needed.
>

Overall looks good, I'll defer to Yonghong to validate kernel-side
iterator logic. Yonghong, can you please take a look? Thanks!

> The implementation is mostly copied from prog iterator, and I would like
> to get any high-level feedback about what needs to be different or have
> to be taken into account. As a side note, I would also appreciate if
> someone could point me out to some guide about writing selftests for bpf
> subsystem -- for some unclear reason I couldn't compile the test from
> this changeset, and was testing it only manually with a custom test
> program.
>

What was the error? Generally, you need very recent Clang (probably
built from sources), latest pahole built from sources, and you should
compile kernel before building selftests/bpf.


> Dmitrii Dolgov (2):
>   bpf: Add bpf_link iterator
>   selftests/bpf: Add bpf_link test
>
>  include/linux/bpf.h                           |   1 +
>  kernel/bpf/Makefile                           |   2 +-
>  kernel/bpf/link_iter.c                        | 107 ++++++++++++++++++
>  kernel/bpf/syscall.c                          |  19 ++++
>  .../selftests/bpf/prog_tests/bpf_iter.c       |  15 +++
>  .../selftests/bpf/progs/bpf_iter_bpf_link.c   |  18 +++
>  6 files changed, 161 insertions(+), 1 deletion(-)
>  create mode 100644 kernel/bpf/link_iter.c
>  create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c
>
> --
> 2.32.0
>