diff mbox series

[v22,bpf-next,18/23] libbpf: Add SEC name for xdp multi-frags programs

Message ID c2bdc436abe8e27a46aa8ba13f75d24f119e18a4.1642439548.git.lorenzo@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series mvneta: introduce XDP multi-buffer support | expand

Checks

Context Check Description
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: andrii@kernel.org hawk@kernel.org kpsingh@kernel.org kafai@fb.com songliubraving@fb.com yhs@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Lorenzo Bianconi Jan. 17, 2022, 5:28 p.m. UTC
Introduce support for the following SEC entries for XDP multi-frags
property:
- SEC("xdp.frags")
- SEC("xdp.frags/devmap")
- SEC("xdp.frags/cpumap")

Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 tools/lib/bpf/libbpf.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Alexei Starovoitov Jan. 18, 2022, 8:14 p.m. UTC | #1
On Mon, Jan 17, 2022 at 06:28:30PM +0100, Lorenzo Bianconi wrote:
> Introduce support for the following SEC entries for XDP multi-frags
> property:
> - SEC("xdp.frags")
> - SEC("xdp.frags/devmap")
> - SEC("xdp.frags/cpumap")
> 
> Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
> Acked-by: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  tools/lib/bpf/libbpf.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index fdb3536afa7d..611e81357fb6 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -6562,6 +6562,9 @@ static int libbpf_preload_prog(struct bpf_program *prog,
>  	if (def & SEC_SLEEPABLE)
>  		opts->prog_flags |= BPF_F_SLEEPABLE;
>  
> +	if (prog->type == BPF_PROG_TYPE_XDP && strstr(prog->sec_name, ".frags"))
> +		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;

That's a bit sloppy.
Could you handle it similar to SEC_SLEEPABLE?

> +
>  	if ((prog->type == BPF_PROG_TYPE_TRACING ||
>  	     prog->type == BPF_PROG_TYPE_LSM ||
>  	     prog->type == BPF_PROG_TYPE_EXT) && !prog->attach_btf_id) {
> @@ -8600,8 +8603,11 @@ static const struct bpf_sec_def section_defs[] = {
>  	SEC_DEF("lsm.s/",		LSM, BPF_LSM_MAC, SEC_ATTACH_BTF | SEC_SLEEPABLE, attach_lsm),
>  	SEC_DEF("iter/",		TRACING, BPF_TRACE_ITER, SEC_ATTACH_BTF, attach_iter),
>  	SEC_DEF("syscall",		SYSCALL, 0, SEC_SLEEPABLE),
> +	SEC_DEF("xdp.frags/devmap",	XDP, BPF_XDP_DEVMAP, SEC_NONE),
>  	SEC_DEF("xdp_devmap/",		XDP, BPF_XDP_DEVMAP, SEC_ATTACHABLE),
> +	SEC_DEF("xdp.frags/cpumap",	XDP, BPF_XDP_CPUMAP, SEC_NONE),
>  	SEC_DEF("xdp_cpumap/",		XDP, BPF_XDP_CPUMAP, SEC_ATTACHABLE),
> +	SEC_DEF("xdp.frags",		XDP, BPF_XDP, SEC_NONE),

It would be SEC_FRAGS here instead of SEC_NONE.

>  	SEC_DEF("xdp",			XDP, BPF_XDP, SEC_ATTACHABLE_OPT | SEC_SLOPPY_PFX),
>  	SEC_DEF("perf_event",		PERF_EVENT, 0, SEC_NONE | SEC_SLOPPY_PFX),
>  	SEC_DEF("lwt_in",		LWT_IN, 0, SEC_NONE | SEC_SLOPPY_PFX),
> -- 
> 2.34.1
> 

--
Lorenzo Bianconi Jan. 18, 2022, 10:31 p.m. UTC | #2
> On Mon, Jan 17, 2022 at 06:28:30PM +0100, Lorenzo Bianconi wrote:
> > Introduce support for the following SEC entries for XDP multi-frags
> > property:
> > - SEC("xdp.frags")
> > - SEC("xdp.frags/devmap")
> > - SEC("xdp.frags/cpumap")
> > 
> > Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
> > Acked-by: John Fastabend <john.fastabend@gmail.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  tools/lib/bpf/libbpf.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index fdb3536afa7d..611e81357fb6 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -6562,6 +6562,9 @@ static int libbpf_preload_prog(struct bpf_program *prog,
> >  	if (def & SEC_SLEEPABLE)
> >  		opts->prog_flags |= BPF_F_SLEEPABLE;
> >  
> > +	if (prog->type == BPF_PROG_TYPE_XDP && strstr(prog->sec_name, ".frags"))
> > +		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
> 
> That's a bit sloppy.
> Could you handle it similar to SEC_SLEEPABLE?
> 
> > +
> >  	if ((prog->type == BPF_PROG_TYPE_TRACING ||
> >  	     prog->type == BPF_PROG_TYPE_LSM ||
> >  	     prog->type == BPF_PROG_TYPE_EXT) && !prog->attach_btf_id) {
> > @@ -8600,8 +8603,11 @@ static const struct bpf_sec_def section_defs[] = {
> >  	SEC_DEF("lsm.s/",		LSM, BPF_LSM_MAC, SEC_ATTACH_BTF | SEC_SLEEPABLE, attach_lsm),
> >  	SEC_DEF("iter/",		TRACING, BPF_TRACE_ITER, SEC_ATTACH_BTF, attach_iter),
> >  	SEC_DEF("syscall",		SYSCALL, 0, SEC_SLEEPABLE),
> > +	SEC_DEF("xdp.frags/devmap",	XDP, BPF_XDP_DEVMAP, SEC_NONE),
> >  	SEC_DEF("xdp_devmap/",		XDP, BPF_XDP_DEVMAP, SEC_ATTACHABLE),
> > +	SEC_DEF("xdp.frags/cpumap",	XDP, BPF_XDP_CPUMAP, SEC_NONE),
> >  	SEC_DEF("xdp_cpumap/",		XDP, BPF_XDP_CPUMAP, SEC_ATTACHABLE),
> > +	SEC_DEF("xdp.frags",		XDP, BPF_XDP, SEC_NONE),
> 
> It would be SEC_FRAGS here instead of SEC_NONE.

ack, I dropped SEC_FRAGS (SEC_XDP_MB before) from sec_def_flags because Andrii asked to remove
it but I am fine to add it back. Agree?

Regards,
Lorenzo

> 
> >  	SEC_DEF("xdp",			XDP, BPF_XDP, SEC_ATTACHABLE_OPT | SEC_SLOPPY_PFX),
> >  	SEC_DEF("perf_event",		PERF_EVENT, 0, SEC_NONE | SEC_SLOPPY_PFX),
> >  	SEC_DEF("lwt_in",		LWT_IN, 0, SEC_NONE | SEC_SLOPPY_PFX),
> > -- 
> > 2.34.1
> > 
> 
> --
Alexei Starovoitov Jan. 18, 2022, 10:33 p.m. UTC | #3
On Tue, Jan 18, 2022 at 2:31 PM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> > On Mon, Jan 17, 2022 at 06:28:30PM +0100, Lorenzo Bianconi wrote:
> > > Introduce support for the following SEC entries for XDP multi-frags
> > > property:
> > > - SEC("xdp.frags")
> > > - SEC("xdp.frags/devmap")
> > > - SEC("xdp.frags/cpumap")
> > >
> > > Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
> > > Acked-by: John Fastabend <john.fastabend@gmail.com>
> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > > ---
> > >  tools/lib/bpf/libbpf.c | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > >
> > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > > index fdb3536afa7d..611e81357fb6 100644
> > > --- a/tools/lib/bpf/libbpf.c
> > > +++ b/tools/lib/bpf/libbpf.c
> > > @@ -6562,6 +6562,9 @@ static int libbpf_preload_prog(struct bpf_program *prog,
> > >     if (def & SEC_SLEEPABLE)
> > >             opts->prog_flags |= BPF_F_SLEEPABLE;
> > >
> > > +   if (prog->type == BPF_PROG_TYPE_XDP && strstr(prog->sec_name, ".frags"))
> > > +           opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
> >
> > That's a bit sloppy.
> > Could you handle it similar to SEC_SLEEPABLE?
> >
> > > +
> > >     if ((prog->type == BPF_PROG_TYPE_TRACING ||
> > >          prog->type == BPF_PROG_TYPE_LSM ||
> > >          prog->type == BPF_PROG_TYPE_EXT) && !prog->attach_btf_id) {
> > > @@ -8600,8 +8603,11 @@ static const struct bpf_sec_def section_defs[] = {
> > >     SEC_DEF("lsm.s/",               LSM, BPF_LSM_MAC, SEC_ATTACH_BTF | SEC_SLEEPABLE, attach_lsm),
> > >     SEC_DEF("iter/",                TRACING, BPF_TRACE_ITER, SEC_ATTACH_BTF, attach_iter),
> > >     SEC_DEF("syscall",              SYSCALL, 0, SEC_SLEEPABLE),
> > > +   SEC_DEF("xdp.frags/devmap",     XDP, BPF_XDP_DEVMAP, SEC_NONE),
> > >     SEC_DEF("xdp_devmap/",          XDP, BPF_XDP_DEVMAP, SEC_ATTACHABLE),
> > > +   SEC_DEF("xdp.frags/cpumap",     XDP, BPF_XDP_CPUMAP, SEC_NONE),
> > >     SEC_DEF("xdp_cpumap/",          XDP, BPF_XDP_CPUMAP, SEC_ATTACHABLE),
> > > +   SEC_DEF("xdp.frags",            XDP, BPF_XDP, SEC_NONE),
> >
> > It would be SEC_FRAGS here instead of SEC_NONE.
>
> ack, I dropped SEC_FRAGS (SEC_XDP_MB before) from sec_def_flags because Andrii asked to remove
> it but I am fine to add it back. Agree?

Andrii,
what was the motivation?
imo that's cleaner than strstr.
Andrii Nakryiko Jan. 19, 2022, 1:11 a.m. UTC | #4
On Tue, Jan 18, 2022 at 2:33 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Tue, Jan 18, 2022 at 2:31 PM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >
> > > On Mon, Jan 17, 2022 at 06:28:30PM +0100, Lorenzo Bianconi wrote:
> > > > Introduce support for the following SEC entries for XDP multi-frags
> > > > property:
> > > > - SEC("xdp.frags")
> > > > - SEC("xdp.frags/devmap")
> > > > - SEC("xdp.frags/cpumap")
> > > >
> > > > Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
> > > > Acked-by: John Fastabend <john.fastabend@gmail.com>
> > > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > > > ---
> > > >  tools/lib/bpf/libbpf.c | 6 ++++++
> > > >  1 file changed, 6 insertions(+)
> > > >
> > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > > > index fdb3536afa7d..611e81357fb6 100644
> > > > --- a/tools/lib/bpf/libbpf.c
> > > > +++ b/tools/lib/bpf/libbpf.c
> > > > @@ -6562,6 +6562,9 @@ static int libbpf_preload_prog(struct bpf_program *prog,
> > > >     if (def & SEC_SLEEPABLE)
> > > >             opts->prog_flags |= BPF_F_SLEEPABLE;
> > > >
> > > > +   if (prog->type == BPF_PROG_TYPE_XDP && strstr(prog->sec_name, ".frags"))
> > > > +           opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
> > >
> > > That's a bit sloppy.
> > > Could you handle it similar to SEC_SLEEPABLE?
> > >
> > > > +
> > > >     if ((prog->type == BPF_PROG_TYPE_TRACING ||
> > > >          prog->type == BPF_PROG_TYPE_LSM ||
> > > >          prog->type == BPF_PROG_TYPE_EXT) && !prog->attach_btf_id) {
> > > > @@ -8600,8 +8603,11 @@ static const struct bpf_sec_def section_defs[] = {
> > > >     SEC_DEF("lsm.s/",               LSM, BPF_LSM_MAC, SEC_ATTACH_BTF | SEC_SLEEPABLE, attach_lsm),
> > > >     SEC_DEF("iter/",                TRACING, BPF_TRACE_ITER, SEC_ATTACH_BTF, attach_iter),
> > > >     SEC_DEF("syscall",              SYSCALL, 0, SEC_SLEEPABLE),
> > > > +   SEC_DEF("xdp.frags/devmap",     XDP, BPF_XDP_DEVMAP, SEC_NONE),
> > > >     SEC_DEF("xdp_devmap/",          XDP, BPF_XDP_DEVMAP, SEC_ATTACHABLE),
> > > > +   SEC_DEF("xdp.frags/cpumap",     XDP, BPF_XDP_CPUMAP, SEC_NONE),
> > > >     SEC_DEF("xdp_cpumap/",          XDP, BPF_XDP_CPUMAP, SEC_ATTACHABLE),
> > > > +   SEC_DEF("xdp.frags",            XDP, BPF_XDP, SEC_NONE),
> > >
> > > It would be SEC_FRAGS here instead of SEC_NONE.
> >
> > ack, I dropped SEC_FRAGS (SEC_XDP_MB before) from sec_def_flags because Andrii asked to remove
> > it but I am fine to add it back. Agree?
>
> Andrii,
> what was the motivation?
> imo that's cleaner than strstr.

Given it was XDP-specific (as opposed to sleepable flag that applies
more widely), it felt cleaner ([0]) to handle that as a special case
in libbpf_preload_prog. But I didn't feel that strongly about that
back then and still don't, so if you think SEC_FRAGS is better, I'm
fine with it. I'd make it SEC_XDP_FRAGS to make it more obvious it's
still XDP-specific (there are no plans to extend it to non-XDP,
right?).

But whichever way, it's internal implementation detail and pretty
small one at that, so I don't care much.

  [0] https://lore.kernel.org/bpf/CAEf4BzbfDvH5CYNsWg9Dx7JcFEp4jNmNRR6H-6sJEUxDSy1zZw@mail.gmail.com/
Lorenzo Bianconi Jan. 19, 2022, 9:38 a.m. UTC | #5
> On Tue, Jan 18, 2022 at 2:33 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Tue, Jan 18, 2022 at 2:31 PM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> > >
> > > > On Mon, Jan 17, 2022 at 06:28:30PM +0100, Lorenzo Bianconi wrote:
> > > > > Introduce support for the following SEC entries for XDP multi-frags
> > > > > property:
> > > > > - SEC("xdp.frags")
> > > > > - SEC("xdp.frags/devmap")
> > > > > - SEC("xdp.frags/cpumap")
> > > > >
> > > > > Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
> > > > > Acked-by: John Fastabend <john.fastabend@gmail.com>
> > > > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > > > > ---
> > > > >  tools/lib/bpf/libbpf.c | 6 ++++++
> > > > >  1 file changed, 6 insertions(+)
> > > > >
> > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > > > > index fdb3536afa7d..611e81357fb6 100644
> > > > > --- a/tools/lib/bpf/libbpf.c
> > > > > +++ b/tools/lib/bpf/libbpf.c
> > > > > @@ -6562,6 +6562,9 @@ static int libbpf_preload_prog(struct bpf_program *prog,
> > > > >     if (def & SEC_SLEEPABLE)
> > > > >             opts->prog_flags |= BPF_F_SLEEPABLE;
> > > > >
> > > > > +   if (prog->type == BPF_PROG_TYPE_XDP && strstr(prog->sec_name, ".frags"))
> > > > > +           opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
> > > >
> > > > That's a bit sloppy.
> > > > Could you handle it similar to SEC_SLEEPABLE?
> > > >
> > > > > +
> > > > >     if ((prog->type == BPF_PROG_TYPE_TRACING ||
> > > > >          prog->type == BPF_PROG_TYPE_LSM ||
> > > > >          prog->type == BPF_PROG_TYPE_EXT) && !prog->attach_btf_id) {
> > > > > @@ -8600,8 +8603,11 @@ static const struct bpf_sec_def section_defs[] = {
> > > > >     SEC_DEF("lsm.s/",               LSM, BPF_LSM_MAC, SEC_ATTACH_BTF | SEC_SLEEPABLE, attach_lsm),
> > > > >     SEC_DEF("iter/",                TRACING, BPF_TRACE_ITER, SEC_ATTACH_BTF, attach_iter),
> > > > >     SEC_DEF("syscall",              SYSCALL, 0, SEC_SLEEPABLE),
> > > > > +   SEC_DEF("xdp.frags/devmap",     XDP, BPF_XDP_DEVMAP, SEC_NONE),
> > > > >     SEC_DEF("xdp_devmap/",          XDP, BPF_XDP_DEVMAP, SEC_ATTACHABLE),
> > > > > +   SEC_DEF("xdp.frags/cpumap",     XDP, BPF_XDP_CPUMAP, SEC_NONE),
> > > > >     SEC_DEF("xdp_cpumap/",          XDP, BPF_XDP_CPUMAP, SEC_ATTACHABLE),
> > > > > +   SEC_DEF("xdp.frags",            XDP, BPF_XDP, SEC_NONE),
> > > >
> > > > It would be SEC_FRAGS here instead of SEC_NONE.
> > >
> > > ack, I dropped SEC_FRAGS (SEC_XDP_MB before) from sec_def_flags because Andrii asked to remove
> > > it but I am fine to add it back. Agree?
> >
> > Andrii,
> > what was the motivation?
> > imo that's cleaner than strstr.
> 
> Given it was XDP-specific (as opposed to sleepable flag that applies
> more widely), it felt cleaner ([0]) to handle that as a special case
> in libbpf_preload_prog. But I didn't feel that strongly about that
> back then and still don't, so if you think SEC_FRAGS is better, I'm
> fine with it. I'd make it SEC_XDP_FRAGS to make it more obvious it's
> still XDP-specific (there are no plans to extend it to non-XDP,
> right?).

I do not think so and anyway it is an internal flag so we can change it in the
future if necessary, right?

Regards,
Lorenzo

> 
> But whichever way, it's internal implementation detail and pretty
> small one at that, so I don't care much.
> 
>   [0] https://lore.kernel.org/bpf/CAEf4BzbfDvH5CYNsWg9Dx7JcFEp4jNmNRR6H-6sJEUxDSy1zZw@mail.gmail.com/
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index fdb3536afa7d..611e81357fb6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6562,6 +6562,9 @@  static int libbpf_preload_prog(struct bpf_program *prog,
 	if (def & SEC_SLEEPABLE)
 		opts->prog_flags |= BPF_F_SLEEPABLE;
 
+	if (prog->type == BPF_PROG_TYPE_XDP && strstr(prog->sec_name, ".frags"))
+		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
+
 	if ((prog->type == BPF_PROG_TYPE_TRACING ||
 	     prog->type == BPF_PROG_TYPE_LSM ||
 	     prog->type == BPF_PROG_TYPE_EXT) && !prog->attach_btf_id) {
@@ -8600,8 +8603,11 @@  static const struct bpf_sec_def section_defs[] = {
 	SEC_DEF("lsm.s/",		LSM, BPF_LSM_MAC, SEC_ATTACH_BTF | SEC_SLEEPABLE, attach_lsm),
 	SEC_DEF("iter/",		TRACING, BPF_TRACE_ITER, SEC_ATTACH_BTF, attach_iter),
 	SEC_DEF("syscall",		SYSCALL, 0, SEC_SLEEPABLE),
+	SEC_DEF("xdp.frags/devmap",	XDP, BPF_XDP_DEVMAP, SEC_NONE),
 	SEC_DEF("xdp_devmap/",		XDP, BPF_XDP_DEVMAP, SEC_ATTACHABLE),
+	SEC_DEF("xdp.frags/cpumap",	XDP, BPF_XDP_CPUMAP, SEC_NONE),
 	SEC_DEF("xdp_cpumap/",		XDP, BPF_XDP_CPUMAP, SEC_ATTACHABLE),
+	SEC_DEF("xdp.frags",		XDP, BPF_XDP, SEC_NONE),
 	SEC_DEF("xdp",			XDP, BPF_XDP, SEC_ATTACHABLE_OPT | SEC_SLOPPY_PFX),
 	SEC_DEF("perf_event",		PERF_EVENT, 0, SEC_NONE | SEC_SLOPPY_PFX),
 	SEC_DEF("lwt_in",		LWT_IN, 0, SEC_NONE | SEC_SLOPPY_PFX),