From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Andrey Ignatov <rdna@fb.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, Martin Lau <kafai@fb.com>,
Andrii Nakryiko <andriin@fb.com>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v3 bpf-next 4/6] libbpf: Introduce bpf_prog_attach_xattr
Date: Wed, 18 Dec 2019 21:49:55 -0800 [thread overview]
Message-ID: <CAEf4BzZEmnmQm=JEVyq4G=DfAvZY3M9NK+gwkGgQmgTrhizNvw@mail.gmail.com> (raw)
In-Reply-To: <a47ee7676254d3e94d3ff61afe20477eb8ace561.1576720240.git.rdna@fb.com>
On Wed, Dec 18, 2019 at 6:56 PM Andrey Ignatov <rdna@fb.com> wrote:
>
> Introduce a new bpf_prog_attach_xattr function that, in addition to
> program fd, target fd and attach type, accepts an extendable struct
> bpf_prog_attach_opts.
>
> bpf_prog_attach_opts relies on DECLARE_LIBBPF_OPTS macro to maintain
> backward and forward compatibility and has the following "optional"
> attach attributes:
>
> * existing attach_flags, since it's not required when attaching in NONE
> mode. Even though it's quite often used in MULTI and OVERRIDE mode it
> seems to be a good idea to reduce number of arguments to
> bpf_prog_attach_xattr;
>
> * newly introduced attribute of BPF_PROG_ATTACH command: replace_prog_fd
> that is fd of previously attached cgroup-bpf program to replace if
> BPF_F_REPLACE flag is used.
>
> The new function is named to be consistent with other xattr-functions
> (bpf_prog_test_run_xattr, bpf_create_map_xattr, bpf_load_program_xattr).
>
> The struct bpf_prog_attach_opts is supposed to be used with
> DECLARE_LIBBPF_OPTS macro.
>
> Signed-off-by: Andrey Ignatov <rdna@fb.com>
> ---
> tools/lib/bpf/bpf.c | 16 +++++++++++++++-
> tools/lib/bpf/bpf.h | 11 +++++++++++
> tools/lib/bpf/libbpf.map | 1 +
> 3 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 98596e15390f..ebb4f8d71bdb 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -466,6 +466,17 @@ int bpf_obj_get(const char *pathname)
>
> int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
> unsigned int flags)
> +{
> + DECLARE_LIBBPF_OPTS(bpf_prog_attach_opts, opts,
> + .flags = flags,
> + );
> +
> + return bpf_prog_attach_xattr(prog_fd, target_fd, type, &opts);
> +}
> +
> +int bpf_prog_attach_xattr(int prog_fd, int target_fd,
> + enum bpf_attach_type type,
> + const struct bpf_prog_attach_opts *opts)
> {
> union bpf_attr attr;
>
You need to validate opts with OPTS_VALID macro (see
btf_dump__emit_type_decl() for simple example).
> @@ -473,7 +484,10 @@ int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
> attr.target_fd = target_fd;
> attr.attach_bpf_fd = prog_fd;
> attr.attach_type = type;
> - attr.attach_flags = flags;
> + if (opts) {
> + attr.attach_flags = opts->flags;
> + attr.replace_bpf_fd = opts->replace_prog_fd;
> + }
Please use OPTS_GET() macro to fetch values from opts struct and
provide default value if they are not specified.
>
> return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr));
> }
[...]
next prev parent reply other threads:[~2019-12-19 5:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-19 1:55 [PATCH v3 bpf-next 0/6] bpf: Support replacing cgroup-bpf program in MULTI mode Andrey Ignatov
2019-12-19 1:55 ` [PATCH v3 bpf-next 1/6] bpf: Simplify __cgroup_bpf_attach Andrey Ignatov
2019-12-19 1:55 ` [PATCH v3 bpf-next 2/6] bpf: Remove unused new_flags in hierarchy_allows_attach() Andrey Ignatov
2019-12-19 1:56 ` [PATCH v3 bpf-next 3/6] bpf: Support replacing cgroup-bpf program in MULTI mode Andrey Ignatov
2019-12-19 1:56 ` [PATCH v3 bpf-next 4/6] libbpf: Introduce bpf_prog_attach_xattr Andrey Ignatov
2019-12-19 5:49 ` Andrii Nakryiko [this message]
2019-12-19 7:03 ` Andrey Ignatov
2019-12-19 1:56 ` [PATCH v3 bpf-next 5/6] selftests/bpf: Convert test_cgroup_attach to prog_tests Andrey Ignatov
2019-12-19 6:11 ` Andrii Nakryiko
2019-12-19 7:20 ` Andrey Ignatov
2019-12-19 20:40 ` Andrii Nakryiko
2019-12-19 1:56 ` [PATCH v3 bpf-next 6/6] selftests/bpf: Test BPF_F_REPLACE in cgroup_attach_multi Andrey Ignatov
2019-12-19 5:58 ` Andrii Nakryiko
2019-12-19 7:35 ` Andrey Ignatov
2019-12-19 20:44 ` Andrii Nakryiko
2019-12-19 21:09 ` Andrey Ignatov
2019-12-19 21:19 ` Andrii Nakryiko
2019-12-19 21:25 ` Andrey Ignatov
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='CAEf4BzZEmnmQm=JEVyq4G=DfAvZY3M9NK+gwkGgQmgTrhizNvw@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=rdna@fb.com \
/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;
as well as URLs for NNTP newsgroup(s).