bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
@ 2019-12-19 11:03 Eelco Chaudron
  2019-12-19 23:02 ` Andrii Nakryiko
  0 siblings, 1 reply; 7+ messages in thread
From: Eelco Chaudron @ 2019-12-19 11:03 UTC (permalink / raw)
  To: bpf; +Cc: davem, ast, netdev

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

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c
new file mode 100644
index 000000000000..175364843ec5
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <net/if.h>
+
+#define PROG_CNT 2
+
+void test_xdp_bpf2bpf(void)
+{
+	const char *prog_name[PROG_CNT] = {
+		"fentry/_xdp_tx_iptunnel",
+		"fexit/_xdp_tx_iptunnel"
+	};
+	struct bpf_link *link[PROG_CNT] = {};
+	struct bpf_program *prog[PROG_CNT];
+	struct bpf_map *data_map;
+	const int zero = 0;
+	u64 result[PROG_CNT];
+	struct vip key4 = {.protocol = 6, .family = AF_INET};
+	struct iptnl_info value4 = {.family = AF_INET};
+	const char *file = "./test_xdp.o";
+	struct bpf_object *obj, *tracer_obj = NULL;
+	char buf[128];
+	struct iphdr *iph = (void *)buf + sizeof(struct ethhdr);
+	__u32 duration, retval, size;
+	int err, prog_fd, map_fd;
+
+	/* Load XDP program to introspect */
+	err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
+	if (CHECK_FAIL(err))
+		return;
+
+	map_fd = bpf_find_map(__func__, obj, "vip2tnl");
+	if (map_fd < 0)
+		goto out;
+	bpf_map_update_elem(map_fd, &key4, &value4, 0);
+
+	/* Load eBPF trace program */
+	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 (CHECK(IS_ERR_OR_NULL(tracer_obj), "obj_open",
+		  "failed to open test_xdp_bpf2bpf: %ld\n",
+		  PTR_ERR(tracer_obj)))
+		goto out;
+
+	err = bpf_object__load(tracer_obj);
+	if (CHECK(err, "obj_load", "err %d\n", err))
+		goto out;
+
+	for (int i = 0; i < PROG_CNT; i++) {
+		prog[i] = bpf_object__find_program_by_title(tracer_obj,
+							    prog_name[i]);
+		if (CHECK(!prog[i], "find_prog", "prog %s not found\n",
+			  prog_name[i]))
+			goto out;
+		link[i] = bpf_program__attach_trace(prog[i]);
+		if (CHECK(IS_ERR(link[i]), "attach_trace", "failed to link\n"))
+			goto out;
+	}
+	data_map = bpf_object__find_map_by_name(tracer_obj, "test_xdp.bss");
+	if (CHECK(!data_map, "find_data_map", "data map not found\n"))
+		goto out;
+
+	/* Run test program */
+	err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
+				buf, &size, &retval, &duration);
+
+	CHECK(err || retval != XDP_TX || size != 74 ||
+	      iph->protocol != IPPROTO_IPIP, "ipv4",
+	      "err %d errno %d retval %d size %d\n",
+	      err, errno, retval, size);
+
+	/* Verify test results */
+	err = bpf_map_lookup_elem(bpf_map__fd(data_map), &zero, &result);
+	if (CHECK(err, "get_result",
+		  "failed to get output data: %d\n", err))
+		goto out;
+
+	if (CHECK(result[0] != if_nametoindex("lo"),
+		  "result", "%s failed err %ld\n", prog_name[0], result[0]))
+		goto out;
+
+	if (CHECK(result[1] != XDP_TX, "result", "%s failed err %ld\n",
+		  prog_name[1], result[1]))
+		goto out;
+out:
+	for (int i = 0; i < PROG_CNT; i++)
+		if (!IS_ERR_OR_NULL(link[i]))
+			bpf_link__destroy(link[i]);
+	if (!IS_ERR_OR_NULL(tracer_obj))
+		bpf_object__close(tracer_obj);
+	bpf_object__close(obj);
+}
diff --git a/tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c b/tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c
new file mode 100644
index 000000000000..82b87b2fc4e1
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include "bpf_helpers.h"
+#include "bpf_trace_helpers.h"
+
+struct net_device {
+	/* Structure does not need to contain all entries,
+	 * as "preserve_access_index" will use BTF to fix this...
+	 */
+	int ifindex;
+} __attribute__((preserve_access_index));
+
+struct xdp_rxq_info {
+	/* Structure does not need to contain all entries,
+	 * as "preserve_access_index" will use BTF to fix this...
+	 */
+	struct net_device *dev;
+	__u32 queue_index;
+} __attribute__((preserve_access_index));
+
+struct xdp_buff {
+	void *data;
+	void *data_end;
+	void *data_meta;
+	void *data_hard_start;
+	unsigned long handle;
+	struct xdp_rxq_info *rxq;
+} __attribute__((preserve_access_index));
+
+static volatile __u64 test_result_fentry;
+BPF_TRACE_1("fentry/_xdp_tx_iptunnel", trace_on_entry,
+	    struct xdp_buff *, xdp)
+{
+	test_result_fentry = xdp->rxq->dev->ifindex;
+	return 0;
+}
+
+static volatile __u64 test_result_fexit;
+BPF_TRACE_2("fexit/_xdp_tx_iptunnel", trace_on_exit,
+	    struct xdp_buff*, xdp, int, ret)
+{
+	test_result_fexit = ret;
+	return 0;
+}


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
  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
  2020-01-02 14:13   ` Eelco Chaudron
  0 siblings, 2 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-12-19 23:02 UTC (permalink / raw)
  To: Eelco Chaudron; +Cc: bpf, David S. Miller, Alexei Starovoitov, Networking

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.

> +       if (CHECK_FAIL(err))
> +               return;
> +

[...]

> +
> +static volatile __u64 test_result_fentry;

no need for static volatile anymore, just use global var

> +BPF_TRACE_1("fentry/_xdp_tx_iptunnel", trace_on_entry,
> +           struct xdp_buff *, xdp)
> +{
> +       test_result_fentry = xdp->rxq->dev->ifindex;
> +       return 0;
> +}
> +
> +static volatile __u64 test_result_fexit;

same here

> +BPF_TRACE_2("fexit/_xdp_tx_iptunnel", trace_on_exit,
> +           struct xdp_buff*, xdp, int, ret)
> +{
> +       test_result_fexit = ret;
> +       return 0;
> +}
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
  2019-12-19 23:02 ` Andrii Nakryiko
@ 2019-12-23 12:53   ` Eelco Chaudron
  2019-12-23 17:57     ` Andrii Nakryiko
  2020-01-02 14:13   ` Eelco Chaudron
  1 sibling, 1 reply; 7+ messages in thread
From: Eelco Chaudron @ 2019-12-23 12:53 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, David S. Miller, Alexei Starovoitov, Networking



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
>>
>
> [...]

Thanks for the review, updated my kernel to the latest bfp-next, but now 
I get the following build issue for the test suite:

    GEN-SKEL [test_progs] loop3.skel.h
    GEN-SKEL [test_progs] test_skeleton.skel.h
libbpf: failed to find BTF for extern 'CONFIG_BPF_SYSCALL': -2
Error: failed to open BPF object file: 0
make: *** [Makefile:333: 
/data/linux_kernel/tools/testing/selftests/bpf/test_skeleton.skel.h] 
Error 255
make: *** Deleting file 
'/data/linux_kernel/tools/testing/selftests/bpf/test_skeleton.skel.h'

Verified, and I still have all the correct config and CLANG version. 
Something else I need to update?
I have pahole v1.15 in my search path…

>
>> +       /* 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.
>
>> +       if (CHECK_FAIL(err))
>> +               return;
>> +
>
> [...]
>
>> +
>> +static volatile __u64 test_result_fentry;
>
> no need for static volatile anymore, just use global var
>
>> +BPF_TRACE_1("fentry/_xdp_tx_iptunnel", trace_on_entry,
>> +           struct xdp_buff *, xdp)
>> +{
>> +       test_result_fentry = xdp->rxq->dev->ifindex;
>> +       return 0;
>> +}
>> +
>> +static volatile __u64 test_result_fexit;
>
> same here
>
>> +BPF_TRACE_2("fexit/_xdp_tx_iptunnel", trace_on_exit,
>> +           struct xdp_buff*, xdp, int, ret)
>> +{
>> +       test_result_fexit = ret;
>> +       return 0;
>> +}
>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
  2019-12-23 12:53   ` Eelco Chaudron
@ 2019-12-23 17:57     ` Andrii Nakryiko
  2019-12-24 15:49       ` Eelco Chaudron
  0 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2019-12-23 17:57 UTC (permalink / raw)
  To: Eelco Chaudron; +Cc: bpf, David S. Miller, Alexei Starovoitov, Networking

On Mon, Dec 23, 2019 at 4:54 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
> >>
> >
> > [...]
>
> Thanks for the review, updated my kernel to the latest bfp-next, but now
> I get the following build issue for the test suite:
>
>     GEN-SKEL [test_progs] loop3.skel.h
>     GEN-SKEL [test_progs] test_skeleton.skel.h
> libbpf: failed to find BTF for extern 'CONFIG_BPF_SYSCALL': -2

This looks like you have Clang without BTF types for extern. Can you
try pull the very latest Clang/LLVM and try again? The latest commit
you should have is e3d8ee35e4ad ("reland "[DebugInfo] Support to emit
debugInfo for extern variables"").

> Error: failed to open BPF object file: 0
> make: *** [Makefile:333:
> /data/linux_kernel/tools/testing/selftests/bpf/test_skeleton.skel.h]
> Error 255
> make: *** Deleting file
> '/data/linux_kernel/tools/testing/selftests/bpf/test_skeleton.skel.h'
>
> Verified, and I still have all the correct config and CLANG version.
> Something else I need to update?
> I have pahole v1.15 in my search path…
>
> >
> >> +       /* 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.
> >
> >> +       if (CHECK_FAIL(err))
> >> +               return;
> >> +
> >
> > [...]
> >
> >> +
> >> +static volatile __u64 test_result_fentry;
> >
> > no need for static volatile anymore, just use global var
> >
> >> +BPF_TRACE_1("fentry/_xdp_tx_iptunnel", trace_on_entry,
> >> +           struct xdp_buff *, xdp)
> >> +{
> >> +       test_result_fentry = xdp->rxq->dev->ifindex;
> >> +       return 0;
> >> +}
> >> +
> >> +static volatile __u64 test_result_fexit;
> >
> > same here
> >
> >> +BPF_TRACE_2("fexit/_xdp_tx_iptunnel", trace_on_exit,
> >> +           struct xdp_buff*, xdp, int, ret)
> >> +{
> >> +       test_result_fexit = ret;
> >> +       return 0;
> >> +}
> >>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
  2019-12-23 17:57     ` Andrii Nakryiko
@ 2019-12-24 15:49       ` Eelco Chaudron
  0 siblings, 0 replies; 7+ messages in thread
From: Eelco Chaudron @ 2019-12-24 15:49 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, David S. Miller, Alexei Starovoitov, Networking



On 23 Dec 2019, at 18:57, Andrii Nakryiko wrote:

> On Mon, Dec 23, 2019 at 4:54 AM Eelco Chaudron <echaudro@redhat.com> wrote:
<SNIP<
>>
>> Thanks for the review, updated my kernel to the latest bfp-next, but now
>> I get the following build issue for the test suite:
>>
>>     GEN-SKEL [test_progs] loop3.skel.h
>>     GEN-SKEL [test_progs] test_skeleton.skel.h
>> libbpf: failed to find BTF for extern 'CONFIG_BPF_SYSCALL': -2
>
> This looks like you have Clang without BTF types for extern. Can you
> try pull the very latest Clang/LLVM and try again? The latest commit
> you should have is e3d8ee35e4ad ("reland "[DebugInfo] Support to emit
> debugInfo for extern variables"").
>

Thanks, rebuilding the latest master LLVM fixed the problem!

//Eelco


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
  2019-12-19 23:02 ` Andrii Nakryiko
  2019-12-23 12:53   ` Eelco Chaudron
@ 2020-01-02 14:13   ` Eelco Chaudron
  2020-01-09  5:04     ` Andrii Nakryiko
  1 sibling, 1 reply; 7+ messages in thread
From: Eelco Chaudron @ 2020-01-02 14:13 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, David S. Miller, Alexei Starovoitov, Networking



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.
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 :(


[...]


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
  2020-01-02 14:13   ` Eelco Chaudron
@ 2020-01-09  5:04     ` Andrii Nakryiko
  0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2020-01-09  5:04 UTC (permalink / raw)
  To: Eelco Chaudron; +Cc: bpf, David S. Miller, Alexei Starovoitov, Networking

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.

>
>
> [...]
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-09  5:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).