From: Dave Marchevsky <davemarchevsky@fb.com>
To: Andrii Nakryiko <andrii@kernel.org>, <bpf@vger.kernel.org>,
<ast@kernel.org>, <daniel@iogearbox.net>
Cc: <kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf-next 6/9] libbpf: refactor ELF section handler definitions
Date: Tue, 21 Sep 2021 21:34:37 -0400 [thread overview]
Message-ID: <78a539a7-7c1b-d9ce-e4e1-8e8fa66e04bb@fb.com> (raw)
In-Reply-To: <20210920234320.3312820-7-andrii@kernel.org>
On 9/20/21 7:43 PM, Andrii Nakryiko wrote:
> Refactor ELF section handler definitions table to use a set of flags and
> unified SEC_DEF() macro. This allows for more succinct and table-like
> set of definitions, and allows to more easily extend the logic without
> adding more verbosity (this is utilized in later patches in the series).
>
> This approach is also making libbpf-internal program pre-load callback
> not rely on bpf_sec_def definition, which demonstrates that future
> pluggable ELF section handlers will be able to achieve similar level of
> integration without libbpf having to expose extra types and APIs.
>
> For starters, update SEC_DEF() definitions and make them more succinct.
> Also convert BPF_PROG_SEC() and BPF_APROG_COMPAT() definitions to
> a common SEC_DEF() use.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
> tools/lib/bpf/libbpf.c | 183 ++++++++++++++++-------------------------
> 1 file changed, 73 insertions(+), 110 deletions(-)
To summarize VC convo we had about this patch, you don't expect custom sec_def
writers to necessarily follow your sec_def_flags approach, but it's a good
demonstration that a long's worth of flags is plenty for enabling custom
functionality. And custom sec_def writers can treat the cookie as a ptr to a
config struct if they need something more complicated, without imposing the
struct format on all other sec_defs.
[...]
> @@ -7955,15 +7965,14 @@ void bpf_program__set_expected_attach_type(struct bpf_program *prog,
> .sec = string, \
> .prog_type = ptype, \
> .expected_attach_type = eatype, \
> - .is_exp_attach_type_optional = eatype_optional, \
> - .is_attachable = attachable, \
> - .is_attach_btf = attach_btf, \
> + .cookie = (long) ( \
> + (eatype_optional ? SEC_EXP_ATTACH_OPT : 0) | \
> + (attachable ? SEC_ATTACHABLE : 0) | \
> + (attach_btf ? SEC_ATTACH_BTF : 0) \
> + ), \
> .preload_fn = libbpf_preload_prog, \
> }
>
> -/* Programs that can NOT be attached. */
I found this comment and APROG_COMPAT comment useful. Not as clear to me what
SEC_NONE implies without some comment explaining or giving example. The other
flags are more obvious to me but might be worth being explicit there as well.
> -#define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, 0, 0, 0)
> -
> /* Programs that can be attached. */
> #define BPF_APROG_SEC(string, ptype, atype) \
> BPF_PROG_SEC_IMPL(string, ptype, atype, true, 1, 0)
> @@ -7976,14 +7985,11 @@ void bpf_program__set_expected_attach_type(struct bpf_program *prog,
> #define BPF_PROG_BTF(string, ptype, eatype) \
> BPF_PROG_SEC_IMPL(string, ptype, eatype, false, 0, 1)
>
> -/* Programs that can be attached but attach type can't be identified by section
> - * name. Kept for backward compatibility.
> - */
> -#define BPF_APROG_COMPAT(string, ptype) BPF_PROG_SEC(string, ptype)
> -
> -#define SEC_DEF(sec_pfx, ptype, ...) { \
> +#define SEC_DEF(sec_pfx, ptype, atype, flags, ...) { \
> .sec = sec_pfx, \
> .prog_type = BPF_PROG_TYPE_##ptype, \
> + .expected_attach_type = atype, \
> + .cookie = (long)(flags), \
> .preload_fn = libbpf_preload_prog, \
> __VA_ARGS__ \
> }
> @@ -7996,92 +8002,49 @@ static struct bpf_link *attach_lsm(const struct bpf_program *prog, long cookie);
> static struct bpf_link *attach_iter(const struct bpf_program *prog, long cookie);
>
> static const struct bpf_sec_def section_defs[] = {
> - BPF_PROG_SEC("socket", BPF_PROG_TYPE_SOCKET_FILTER),
> + SEC_DEF("socket", SOCKET_FILTER, 0, SEC_NONE),
Didn't know how strictly you felt about checkpatch line-length complaints,
won't comment on them further since you mentioned 100 chars being the new
standard. But would complain about the alignment here and elsewhere in
changes to section_defs even if checkpatch didn't exist :)
> BPF_EAPROG_SEC("sk_reuseport/migrate", BPF_PROG_TYPE_SK_REUSEPORT,
> BPF_SK_REUSEPORT_SELECT_OR_MIGRATE),
> BPF_EAPROG_SEC("sk_reuseport", BPF_PROG_TYPE_SK_REUSEPORT,
> BPF_SK_REUSEPORT_SELECT),
[...]
next prev parent reply other threads:[~2021-09-22 1:34 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-20 23:43 [PATCH v2 bpf-next 0/9] libbpf: stricter BPF program section name handling Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 1/9] selftests/bpf: normalize XDP section names in selftests Andrii Nakryiko
2021-09-21 4:55 ` Dave Marchevsky
2021-09-21 23:08 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 2/9] selftests/bpf: normalize SEC("classifier") usage Andrii Nakryiko
2021-09-21 5:20 ` Dave Marchevsky
2021-09-21 23:10 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 3/9] selftests/bpf: normalize all the rest SEC() uses Andrii Nakryiko
2021-09-21 5:41 ` Dave Marchevsky
2021-09-21 23:12 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 4/9] libbpf: refactor internal sec_def handling to enable pluggability Andrii Nakryiko
2021-09-22 0:42 ` Dave Marchevsky
2021-09-22 22:06 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 5/9] libbpf: reduce reliance of attach_fns on sec_def internals Andrii Nakryiko
2021-09-22 1:00 ` Dave Marchevsky
2021-09-20 23:43 ` [PATCH v2 bpf-next 6/9] libbpf: refactor ELF section handler definitions Andrii Nakryiko
2021-09-22 1:34 ` Dave Marchevsky [this message]
2021-09-22 21:54 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 7/9] libbpf: complete SEC() table unification for BPF_APROG_SEC/BPF_EAPROG_SEC Andrii Nakryiko
2021-09-22 1:42 ` Dave Marchevsky
2021-09-22 21:55 ` Andrii Nakryiko
2021-09-22 22:12 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 8/9] libbpf: add opt-in strict BPF program section name handling logic Andrii Nakryiko
2021-09-22 1:53 ` Dave Marchevsky
2021-09-22 21:57 ` Andrii Nakryiko
2021-09-20 23:43 ` [PATCH v2 bpf-next 9/9] selftests/bpf: switch sk_lookup selftests to strict SEC("sk_lookup") use Andrii Nakryiko
2021-09-22 2:37 ` Dave Marchevsky
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=78a539a7-7c1b-d9ce-e4e1-8e8fa66e04bb@fb.com \
--to=davemarchevsky@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@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