mbox series

[v2,0/6] Add _opts variant for bpf_*_get_fd_by_id()

Message ID 20221006110736.84253-1-roberto.sassu@huaweicloud.com
Headers show
Series Add _opts variant for bpf_*_get_fd_by_id() | expand

Message

Roberto Sassu Oct. 6, 2022, 11:07 a.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com>

Add the _opts variant for bpf_*_get_fd_by_id() functions, to be able to
pass to the kernel more options, when requesting a fd of an eBPF object.

Pass the options through a newly introduced structure,
bpf_get_fd_by_id_opts, which currently contains open_flags (the other two
members are for compatibility and for padding).

open_flags allows the caller to request specific permissions to access a
map (e.g. read-only). This is useful for example in the situation where a
map is write-protected.

Besides patches 2-6, which introduce the new variants and the data
structure, patch 1 fixes the LIBBPF_1.0.0 declaration in libbpf.map.

Changelog

v1:
 - Don't CC stable kernel mailing list for patch 1 (suggested by Andrii)
 - Rename bpf_get_fd_opts struct to bpf_get_fd_by_id_opts (suggested by
   Andrii)
 - Move declaration of _opts variants after non-opts variants (suggested by
   Andrii)
 - Correctly initialize bpf_map_info, fix style issues, use map from
   skeleton, check valid fd in the test (suggested by Andrii)
 - Rename libbpf_get_fd_opts test to libbpf_get_fd_by_id_opts

Roberto Sassu (6):
  libbpf: Fix LIBBPF_1.0.0 declaration in libbpf.map
  libbpf: Introduce bpf_get_fd_by_id_opts and
    bpf_map_get_fd_by_id_opts()
  libbpf: Introduce bpf_prog_get_fd_by_id_opts()
  libbpf: Introduce bpf_btf_get_fd_by_id_opts()
  libbpf: Introduce bpf_link_get_fd_by_id_opts()
  selftests/bpf: Add tests for _opts variants of bpf_*_get_fd_by_id()

 tools/lib/bpf/bpf.c                           | 48 +++++++++-
 tools/lib/bpf/bpf.h                           | 16 ++++
 tools/lib/bpf/libbpf.map                      |  6 +-
 tools/testing/selftests/bpf/DENYLIST.s390x    |  1 +
 .../bpf/prog_tests/libbpf_get_fd_by_id_opts.c | 87 +++++++++++++++++++
 .../bpf/progs/test_libbpf_get_fd_by_id_opts.c | 36 ++++++++
 6 files changed, 189 insertions(+), 5 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/libbpf_get_fd_by_id_opts.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_libbpf_get_fd_by_id_opts.c

Comments

Jiri Olsa Oct. 7, 2022, 10:59 a.m. UTC | #1
On Thu, Oct 06, 2022 at 01:07:30PM +0200, Roberto Sassu wrote:
> From: Roberto Sassu <roberto.sassu@huawei.com>
> 
> Add the _opts variant for bpf_*_get_fd_by_id() functions, to be able to
> pass to the kernel more options, when requesting a fd of an eBPF object.
> 
> Pass the options through a newly introduced structure,
> bpf_get_fd_by_id_opts, which currently contains open_flags (the other two
> members are for compatibility and for padding).
> 
> open_flags allows the caller to request specific permissions to access a
> map (e.g. read-only). This is useful for example in the situation where a
> map is write-protected.
> 
> Besides patches 2-6, which introduce the new variants and the data
> structure, patch 1 fixes the LIBBPF_1.0.0 declaration in libbpf.map.
> 
> Changelog
> 
> v1:
>  - Don't CC stable kernel mailing list for patch 1 (suggested by Andrii)
>  - Rename bpf_get_fd_opts struct to bpf_get_fd_by_id_opts (suggested by
>    Andrii)
>  - Move declaration of _opts variants after non-opts variants (suggested by
>    Andrii)
>  - Correctly initialize bpf_map_info, fix style issues, use map from
>    skeleton, check valid fd in the test (suggested by Andrii)
>  - Rename libbpf_get_fd_opts test to libbpf_get_fd_by_id_opts
> 
> Roberto Sassu (6):
>   libbpf: Fix LIBBPF_1.0.0 declaration in libbpf.map
>   libbpf: Introduce bpf_get_fd_by_id_opts and
>     bpf_map_get_fd_by_id_opts()
>   libbpf: Introduce bpf_prog_get_fd_by_id_opts()
>   libbpf: Introduce bpf_btf_get_fd_by_id_opts()
>   libbpf: Introduce bpf_link_get_fd_by_id_opts()
>   selftests/bpf: Add tests for _opts variants of bpf_*_get_fd_by_id()

it's not marked, but I'm assuming this goes to bpf-next, right?

anyway, lgtm

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
>  tools/lib/bpf/bpf.c                           | 48 +++++++++-
>  tools/lib/bpf/bpf.h                           | 16 ++++
>  tools/lib/bpf/libbpf.map                      |  6 +-
>  tools/testing/selftests/bpf/DENYLIST.s390x    |  1 +
>  .../bpf/prog_tests/libbpf_get_fd_by_id_opts.c | 87 +++++++++++++++++++
>  .../bpf/progs/test_libbpf_get_fd_by_id_opts.c | 36 ++++++++
>  6 files changed, 189 insertions(+), 5 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/libbpf_get_fd_by_id_opts.c
>  create mode 100644 tools/testing/selftests/bpf/progs/test_libbpf_get_fd_by_id_opts.c
> 
> -- 
> 2.25.1
>
Roberto Sassu Oct. 7, 2022, 11:31 a.m. UTC | #2
On Fri, 2022-10-07 at 12:59 +0200, Jiri Olsa wrote:
> On Thu, Oct 06, 2022 at 01:07:30PM +0200, Roberto Sassu wrote:
> > From: Roberto Sassu <roberto.sassu@huawei.com>
> > 
> > Add the _opts variant for bpf_*_get_fd_by_id() functions, to be
> > able to
> > pass to the kernel more options, when requesting a fd of an eBPF
> > object.
> > 
> > Pass the options through a newly introduced structure,
> > bpf_get_fd_by_id_opts, which currently contains open_flags (the
> > other two
> > members are for compatibility and for padding).
> > 
> > open_flags allows the caller to request specific permissions to
> > access a
> > map (e.g. read-only). This is useful for example in the situation
> > where a
> > map is write-protected.
> > 
> > Besides patches 2-6, which introduce the new variants and the data
> > structure, patch 1 fixes the LIBBPF_1.0.0 declaration in
> > libbpf.map.
> > 
> > Changelog
> > 
> > v1:
> >  - Don't CC stable kernel mailing list for patch 1 (suggested by
> > Andrii)
> >  - Rename bpf_get_fd_opts struct to bpf_get_fd_by_id_opts
> > (suggested by
> >    Andrii)
> >  - Move declaration of _opts variants after non-opts variants
> > (suggested by
> >    Andrii)
> >  - Correctly initialize bpf_map_info, fix style issues, use map
> > from
> >    skeleton, check valid fd in the test (suggested by Andrii)
> >  - Rename libbpf_get_fd_opts test to libbpf_get_fd_by_id_opts
> > 
> > Roberto Sassu (6):
> >   libbpf: Fix LIBBPF_1.0.0 declaration in libbpf.map
> >   libbpf: Introduce bpf_get_fd_by_id_opts and
> >     bpf_map_get_fd_by_id_opts()
> >   libbpf: Introduce bpf_prog_get_fd_by_id_opts()
> >   libbpf: Introduce bpf_btf_get_fd_by_id_opts()
> >   libbpf: Introduce bpf_link_get_fd_by_id_opts()
> >   selftests/bpf: Add tests for _opts variants of
> > bpf_*_get_fd_by_id()
> 
> it's not marked, but I'm assuming this goes to bpf-next, right?

At the next possible chance would be perfect.

> anyway, lgtm
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks

Roberto

> thanks,
> jirka
> 
> >  tools/lib/bpf/bpf.c                           | 48 +++++++++-
> >  tools/lib/bpf/bpf.h                           | 16 ++++
> >  tools/lib/bpf/libbpf.map                      |  6 +-
> >  tools/testing/selftests/bpf/DENYLIST.s390x    |  1 +
> >  .../bpf/prog_tests/libbpf_get_fd_by_id_opts.c | 87
> > +++++++++++++++++++
> >  .../bpf/progs/test_libbpf_get_fd_by_id_opts.c | 36 ++++++++
> >  6 files changed, 189 insertions(+), 5 deletions(-)
> >  create mode 100644
> > tools/testing/selftests/bpf/prog_tests/libbpf_get_fd_by_id_opts.c
> >  create mode 100644
> > tools/testing/selftests/bpf/progs/test_libbpf_get_fd_by_id_opts.c
> > 
> > -- 
> > 2.25.1
> >
patchwork-bot+netdevbpf@kernel.org Oct. 11, 2022, 12:20 a.m. UTC | #3
Hello:

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

On Thu,  6 Oct 2022 13:07:30 +0200 you wrote:
> From: Roberto Sassu <roberto.sassu@huawei.com>
> 
> Add the _opts variant for bpf_*_get_fd_by_id() functions, to be able to
> pass to the kernel more options, when requesting a fd of an eBPF object.
> 
> Pass the options through a newly introduced structure,
> bpf_get_fd_by_id_opts, which currently contains open_flags (the other two
> members are for compatibility and for padding).
> 
> [...]

Here is the summary with links:
  - [v2,1/6] libbpf: Fix LIBBPF_1.0.0 declaration in libbpf.map
    https://git.kernel.org/bpf/bpf-next/c/7a366da2d2ba
  - [v2,2/6] libbpf: Introduce bpf_get_fd_by_id_opts and bpf_map_get_fd_by_id_opts()
    https://git.kernel.org/bpf/bpf-next/c/243e300563b1
  - [v2,3/6] libbpf: Introduce bpf_prog_get_fd_by_id_opts()
    https://git.kernel.org/bpf/bpf-next/c/8f13f168ea14
  - [v2,4/6] libbpf: Introduce bpf_btf_get_fd_by_id_opts()
    https://git.kernel.org/bpf/bpf-next/c/2ce7cbf2ba71
  - [v2,5/6] libbpf: Introduce bpf_link_get_fd_by_id_opts()
    https://git.kernel.org/bpf/bpf-next/c/97c8f9dd5db8
  - [v2,6/6] selftests/bpf: Add tests for _opts variants of bpf_*_get_fd_by_id()
    https://git.kernel.org/bpf/bpf-next/c/a9c7c18b5759

You are awesome, thank you!