From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Eelco Chaudron <echaudro@redhat.com>
Cc: bpf <bpf@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Alexei Starovoitov <ast@kernel.org>,
Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
Date: Wed, 8 Jan 2020 21:04:51 -0800 [thread overview]
Message-ID: <CAEf4Bzb1pwv9a6pdY+Tjb17O-7YXhyRe3=nZuujoM5zjgq4SBA@mail.gmail.com> (raw)
In-Reply-To: <8F140E5A-2E29-4594-94BA-4D43B592A5B1@redhat.com>
On Thu, Jan 2, 2020 at 6:13 AM Eelco Chaudron <echaudro@redhat.com> wrote:
>
>
>
> On 20 Dec 2019, at 0:02, Andrii Nakryiko wrote:
>
> > On Thu, Dec 19, 2019 at 3:04 AM Eelco Chaudron <echaudro@redhat.com>
> > wrote:
> >>
> >> Add a test that will attach a FENTRY and FEXIT program to the XDP
> >> test
> >> program. It will also verify data from the XDP context on FENTRY and
> >> verifies the return code on exit.
> >>
> >> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> >> ---
> >> .../testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c | 95
> >> ++++++++++++++++++++
> >> .../testing/selftests/bpf/progs/test_xdp_bpf2bpf.c | 44 +++++++++
> >> 2 files changed, 139 insertions(+)
> >> create mode 100644
> >> tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c
> >> create mode 100644
> >> tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c
> >>
> >
> > [...]
> >
> >> + /* Load XDP program to introspect */
> >> + err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
> >
> > Please use BPF skeleton for this test. It will make it significantly
> > shorter and clearer. See other fentry_fexit selftest for example.
> >
>
> Trying to do this, however, I’m getting the following when trying to
> execute the test:
>
> test_xdp_bpf2bpf:PASS:pkt_skel_load 0 nsec
> libbpf: fentry/_xdp_tx_iptunnel is not found in vmlinux BTF
> libbpf: failed to load object 'test_xdp_bpf2bpf'
> libbpf: failed to load BPF skeleton 'test_xdp_bpf2bpf': -2
> test_xdp_bpf2bpf:FAIL:ftrace_skel_load ftrace skeleton failed
>
>
> My program is straight forward following the fentry_fexit.c example:
>
> pkt_skel = test_xdp__open_and_load()
> if (CHECK(!pkt_skel, "pkt_skel_load", "test_xdp skeleton
> failed\n"))
> return;
>
> map_fd = bpf_map__fd(pkt_skel->maps.vip2tnl);
> bpf_map_update_elem(map_fd, &key4, &value4, 0);
>
> /* Load eBPF trace program */
> ftrace_skel = test_xdp_bpf2bpf__open_and_load();
> if (CHECK(!ftrace_skel, "ftrace_skel_load", "ftrace skeleton
> failed\n"))
> goto out;
>
> I assume this is due to the missing link from the XDP program to the
> eBPF trace program.
yes, exactly
> Previously I did this trough:
>
> + DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
> + .attach_prog_fd = prog_fd,
> + );
> +
> + tracer_obj = bpf_object__open_file("./test_xdp_bpf2bpf.o", &opts);
>
>
> If I use this approach as before it works, i.e.:
>
> DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
> .attach_prog_fd = pkt_fd,
> );
>
> ftrace_skel = test_xdp_bpf2bpf__open_opts(&opts);
> if (CHECK(!ftrace_skel, "__open_opts”, "ftrace skeleton
> failed\n"))
> goto out;
> if (CHECK(test_xdp_bpf2bpf__load(ftrace_skel), "__load",
> "ftrace skeleton failed\n"))
> goto out;
>
> But I do not see this in the fentry_fexit.c example, guess I might be
> missing something that is right in front of me :(
you are not missing anything, and this second variant is what you have
to do. __open_and_load() is just an convenience wrapper around
separate __open() followed by __load(), for cases where user doesn't
have to specify any extra options.
>
>
> [...]
>
prev parent reply other threads:[~2020-01-09 5:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-19 11:03 [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program Eelco Chaudron
2019-12-19 23:02 ` Andrii Nakryiko
2019-12-23 12:53 ` Eelco Chaudron
2019-12-23 17:57 ` Andrii Nakryiko
2019-12-24 15:49 ` Eelco Chaudron
2020-01-02 14:13 ` Eelco Chaudron
2020-01-09 5:04 ` Andrii Nakryiko [this message]
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='CAEf4Bzb1pwv9a6pdY+Tjb17O-7YXhyRe3=nZuujoM5zjgq4SBA@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=echaudro@redhat.com \
--cc=netdev@vger.kernel.org \
/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).