[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bza4MQW6QEg7_VdWJwMJPKP8nPSD-ErkUFhVtxyA=jLkHw@mail.gmail.com>
Date: Wed, 12 Feb 2020 10:34:05 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Song Liu <songliubraving@...com>
Cc: Eelco Chaudron <echaudro@...hat.com>, bpf <bpf@...r.kernel.org>,
"David S. Miller" <davem@...emloft.net>,
Networking <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Martin Lau <kafai@...com>, Yonghong Song <yhs@...com>,
Andrii Nakryiko <andriin@...com>,
Toke Høiland-Jørgensen <toke@...hat.com>
Subject: Re: [PATCH bpf-next] libbpf: Add support for dynamic program attach target
On Wed, Feb 12, 2020 at 10:29 AM Song Liu <songliubraving@...com> wrote:
>
>
>
> > On Feb 12, 2020, at 10:14 AM, Andrii Nakryiko <andrii.nakryiko@...il.com> wrote:
> >
> > On Wed, Feb 12, 2020 at 10:07 AM Song Liu <songliubraving@...com> wrote:
> >>
> >>
> >>
> >>> On Feb 12, 2020, at 9:34 AM, Andrii Nakryiko <andrii.nakryiko@...il.com> wrote:
> >>>
> >>> On Wed, Feb 12, 2020 at 4:32 AM Eelco Chaudron <echaudro@...hat.com> wrote:
> >>>>
> >>>> Currently when you want to attach a trace program to a bpf program
> >>>> the section name needs to match the tracepoint/function semantics.
> >>>>
> >>>> However the addition of the bpf_program__set_attach_target() API
> >>>> allows you to specify the tracepoint/function dynamically.
> >>>>
> >>>> The call flow would look something like this:
> >>>>
> >>>> xdp_fd = bpf_prog_get_fd_by_id(id);
> >>>> trace_obj = bpf_object__open_file("func.o", NULL);
> >>>> prog = bpf_object__find_program_by_title(trace_obj,
> >>>> "fentry/myfunc");
> >>>> bpf_program__set_attach_target(prog, xdp_fd,
> >>>> "fentry/xdpfilt_blk_all");
> >>>> bpf_object__load(trace_obj)
> >>>>
> >>>> Signed-off-by: Eelco Chaudron <echaudro@...hat.com>
> >>
> >>
> >> I am trying to solve the same problem with slightly different approach.
> >>
> >> It works as the following (with skeleton):
> >>
> >> obj = myobject_bpf__open_opts(&opts);
> >> bpf_object__for_each_program(prog, obj->obj)
> >> bpf_program__overwrite_section_name(prog, new_names[id++]);
> >> err = myobject_bpf__load(obj);
> >>
> >> I don't have very strong preference. But I think my approach is simpler?
> >
> > I prefer bpf_program__set_attach_target() approach. Section name is a
> > program identifier and a *hint* for libbpf to determine program type,
> > attach type, and whatever else makes sense. But there still should be
> > an API to set all that manually at runtime, thus
> > bpf_program__set_attach_target(). Doing same by overriding section
> > name feels like a hack, plus it doesn't handle overriding
> > attach_program_fd at all.
>
> We already have bpf_object_open_opts to handle different attach_program_fd.
Not really, because open_opts apply to bpf_object and all its
bpf_programs, not to individual bpf_program. So it works only if BPF
application has only one BPF program. If you have many, you can only
set the same attach_program_fd for all of them. Basically, open_opts'
attach_prog_fd should be treated as a default or fallback
attach_prog_fd.
> Can we depreciate bpf_object_open_opts.attach_prog_fd with the
> bpf_program__set_attach_target() approach?
bpf_program__set_attach_target() overrides attach_prog_fd, yes. But we
can't just deprecate that option because it's part of an API already,
even though adding it to open opts was probably a mistake. But for
simple BPF apps with single BPF program it does work fine, so...
>
> Thanks,
> Song
>
Powered by blists - more mailing lists