selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
Subsystems (6)
PATCH v2 1/1 selftests/bpf: Add a test for attaching a bpf fentry/fexit trace to an XDP program
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.
---
v1 -> v2:
- Changed code to use the BPF skeleton
- Replace static volatile with global variable in eBPF code
.../testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c | 69 ++++++++++++++++++++ .../testing/selftests/bpf/progs/test_xdp_bpf2bpf.c | 44 +++++++++++++ 2 files changed, 113 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
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +69 -0
@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <test_progs.h> +#include <net/if.h> +#include "test_xdp.skel.h" +#include "test_xdp_bpf2bpf.skel.h" + +void test_xdp_bpf2bpf (void ) +{ + +struct test_xdp *pkt_skel =NULL ; +struct test_xdp_bpf2bpf *ftrace_skel =NULL ; +__u64 *ftrace_res; + +struct vip key4 = {.protocol =6 , .family =AF_INET }; +struct iptnl_info value4 = {.family =AF_INET }; +char buf[128 ]; +struct iphdr *iph = (void *)buf +sizeof (struct ethhdr ); +__u32 duration =0 , retval, size; +int err, pkt_fd, map_fd; + +/* Load XDP program to introspect */ + pkt_skel =test_xdp__open_and_load (); +if (CHECK (!pkt_skel,"pkt_skel_load" ,"test_xdp skeleton failed\n" )) +return ; + + pkt_fd =bpf_program__fd (pkt_skel->progs._xdp_tx_iptunnel); + + map_fd =bpf_map__fd (pkt_skel->maps.vip2tnl); +bpf_map_update_elem (map_fd, &key4, &value4,0 ); + +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" ,"ftrace skeleton failed\n" )) + goto out; + +if (CHECK (test_xdp_bpf2bpf__load (ftrace_skel),"__load" ,"ftrace skeleton failed\n" )) + goto out; + + err =test_xdp_bpf2bpf__attach (ftrace_skel); +if (CHECK (err,"ftrace_attach" ,"ftrace attach failed: %d\n" , err)) + goto out; + +/* Run test program */ + err =bpf_prog_test_run (pkt_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 */ + ftrace_res = (__u64 *)ftrace_skel->bss; + +if (CHECK (ftrace_res[0 ] !=if_nametoindex ("lo" ),"result" , +"fentry failed err %llu\n" , ftrace_res[0 ])) + goto out; + +if (CHECK (ftrace_res[1 ] !=XDP_TX ,"result" , +"fexit failed err %llu\n" , ftrace_res[1 ])) + goto out; + +out: +test_xdp__destroy (pkt_skel); +test_xdp_bpf2bpf__destroy (ftrace_skel); +}
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +44 -0
44 lines not on this page · raw message
Quoted 25 lines · Eelco Chaudron
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 <[email protected]>---
v1 -> v2:
- Changed code to use the BPF skeleton
- Replace static volatile with global variable in eBPF code.../testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c | 69 ++++++++++++++++++++ .../testing/selftests/bpf/progs/test_xdp_bpf2bpf.c | 44 +++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.ctools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +2
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <test_progs.h>
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 12
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+#include <net/if.h> +#include "test_xdp.skel.h" +#include "test_xdp_bpf2bpf.skel.h" + +void test_xdp_bpf2bpf (void ) +{ + +struct test_xdp *pkt_skel =NULL ; +struct test_xdp_bpf2bpf *ftrace_skel =NULL ; +__u64 *ftrace_res;
Wanted to point out the RCT here but I see that tools/testing/selftests/bpf/prog_tests don't really follow that rule.
Quoted 15 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +15
-0+ +struct vip key4 = {.protocol =6 , .family =AF_INET }; +struct iptnl_info value4 = {.family =AF_INET }; +char buf[128 ]; +struct iphdr *iph = (void *)buf +sizeof (struct ethhdr ); +__u32 duration =0 , retval, size; +int err, pkt_fd, map_fd; + +/* Load XDP program to introspect */ + pkt_skel =test_xdp__open_and_load (); +if (CHECK (!pkt_skel,"pkt_skel_load" ,"test_xdp skeleton failed\n" )) +return ; + + pkt_fd =bpf_program__fd (pkt_skel->progs._xdp_tx_iptunnel); +
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 37
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+ map_fd =bpf_map__fd (pkt_skel->maps.vip2tnl); +bpf_map_update_elem (map_fd, &key4, &value4,0 ); + +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" ,"ftrace skeleton failed\n" )) + goto out;
Hmm do you have here mixed tabs and spaces? Maybe my client messes this line up.
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 39
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +2
-0+ +if (CHECK (test_xdp_bpf2bpf__load (ftrace_skel),"__load" ,"ftrace skeleton failed\n" ))
line too long?
Quoted 15 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +15
-0+ goto out; + + err =test_xdp_bpf2bpf__attach (ftrace_skel); +if (CHECK (err,"ftrace_attach" ,"ftrace attach failed: %d\n" , err)) + goto out; + +/* Run test program */ + err =bpf_prog_test_run (pkt_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); +
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 64
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+/* Verify test results */ + ftrace_res = (__u64 *)ftrace_skel->bss; + +if (CHECK (ftrace_res[0 ] !=if_nametoindex ("lo" ),"result" , +"fentry failed err %llu\n" , ftrace_res[0 ])) + goto out; + +if (CHECK (ftrace_res[1 ] !=XDP_TX ,"result" , +"fexit failed err %llu\n" , ftrace_res[1 ])) + goto out;
this goto doesn't really make sense, can be dropped.
Quoted 56 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +5
-0+ +out: +test_xdp__destroy (pkt_skel); +test_xdp_bpf2bpf__destroy (ftrace_skel); +}tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +44
-0@@ -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)); + +__u64 test_result_fentry =0 ; +BPF_TRACE_1 ("fentry/_xdp_tx_iptunnel" , trace_on_entry, + struct xdp_buff *, xdp) +{ + test_result_fentry = xdp->rxq->dev->ifindex; +return 0 ; +} + +__u64 test_result_fexit =0 ; +BPF_TRACE_2 ("fexit/_xdp_tx_iptunnel" , trace_on_exit, + struct xdp_buff*, xdp, int, ret) +{ + test_result_fexit = ret; +return 0 ; +}
Quoted 24 lines · Eelco Chaudron
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 <[email protected]>---
v1 -> v2:
- Changed code to use the BPF skeleton
- Replace static volatile with global variable in eBPF code.../testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c | 69 ++++++++++++++++++++ .../testing/selftests/bpf/progs/test_xdp_bpf2bpf.c | 44 +++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.ctools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +0
-0
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 9
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +9
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <test_progs.h> +#include <net/if.h> +#include "test_xdp.skel.h" +#include "test_xdp_bpf2bpf.skel.h" + +void test_xdp_bpf2bpf (void ) +{ +
extra line
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 11
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +2
-0+struct test_xdp *pkt_skel =NULL ; +struct test_xdp_bpf2bpf *ftrace_skel =NULL ;
something with indentation?
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 13
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +2
-0+__u64 *ftrace_res; +
variable declarations shouldn't be split, probably?
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+struct vip key4 = {.protocol =6 , .family =AF_INET }; +struct iptnl_info value4 = {.family =AF_INET }; +char buf[128 ]; +struct iphdr *iph = (void *)buf +sizeof (struct ethhdr ); +__u32 duration =0 , retval, size; +int err, pkt_fd, map_fd; + +/* Load XDP program to introspect */ + pkt_skel =test_xdp__open_and_load (); +if (CHECK (!pkt_skel,"pkt_skel_load" ,"test_xdp skeleton failed\n" ))
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 33
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+return ; + + pkt_fd =bpf_program__fd (pkt_skel->progs._xdp_tx_iptunnel); + + map_fd =bpf_map__fd (pkt_skel->maps.vip2tnl); +bpf_map_update_elem (map_fd, &key4, &value4,0 ); + +DECLARE_LIBBPF_OPTS (bpf_object_open_opts, opts, + .attach_prog_fd = pkt_fd, + );
DECLARE_LIBBPF_OPTS is a variable declaration, so should go together with all other declarations. Compiler should complain about this, but I guess selftests/bpf Makefile doesn't have necessary flags, that other kernel code has. You can declare opts first and then initialize some extra fields later:
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts);
... later in code ...
opts.attach_prog_fd = pkt_fd;
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 40
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +7
-0+ + ftrace_skel =test_xdp_bpf2bpf__open_opts (&opts); +if (CHECK (!ftrace_skel,"__open" ,"ftrace skeleton failed\n" )) + goto out; + +if (CHECK (test_xdp_bpf2bpf__load (ftrace_skel),"__load" ,"ftrace skeleton failed\n" )) + goto out;
for consistency with attach check below and for readability, move out load call into separate statement, it's easy to miss when it is inside CHECK()
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 53
Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +13
-0+ + err =test_xdp_bpf2bpf__attach (ftrace_skel); +if (CHECK (err,"ftrace_attach" ,"ftrace attach failed: %d\n" , err)) + goto out; + +/* Run test program */ + err =bpf_prog_test_run (pkt_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);
should it goto out here as well?
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 64
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +11
-0+ +/* Verify test results */ + ftrace_res = (__u64 *)ftrace_skel->bss; + +if (CHECK (ftrace_res[0 ] !=if_nametoindex ("lo" ),"result" , +"fentry failed err %llu\n" , ftrace_res[0 ])) + goto out; + +if (CHECK (ftrace_res[1 ] !=XDP_TX ,"result" , +"fexit failed err %llu\n" , ftrace_res[1 ])) + goto out;
why this casting? You can do access those variables much more naturally with ftrace_skel->bss->test_result_fentry and ftrace_skel->bss->test_result_fexit without making dangerous assumptions about their offsets within data section.
Quoted 33 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +5
-0+ +out: +test_xdp__destroy (pkt_skel); +test_xdp_bpf2bpf__destroy (ftrace_skel); +}tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +22
-0@@ -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;
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c line 32
Quoted 10 lines
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +10
-0+void *data_end; +void *data_meta; +void *data_hard_start; +unsigned long handle; +struct xdp_rxq_info *rxq; +} __attribute__((preserve_access_index)); + +__u64 test_result_fentry =0 ; +BPF_TRACE_1 ("fentry/_xdp_tx_iptunnel" , trace_on_entry, + struct xdp_buff *, xdp)
BPF_TRACE_x is no more, see BPF_PROG and how it's used for fentry/fexit tests:
SEC("fentry/_xdp_tx_iptunnel")
int BPF_PROG(trace_on_entry, struct xdp_buff *xdp)
Quoted 13 lines
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +12
-0+{ + test_result_fentry = xdp->rxq->dev->ifindex; +return 0 ; +} + +__u64 test_result_fexit =0 ; +BPF_TRACE_2 ("fexit/_xdp_tx_iptunnel" , trace_on_exit, + struct xdp_buff*, xdp, int, ret) +{ + test_result_fexit = ret; +return 0 ; +}
Andrii and Maciej thanks for your reviews, I’ve addressed all your comments, and will send out a v3 soon…
//Eelco
Quoted 197 lines · Andrii Nakryiko
Quoted 28 lines · Eelco Chaudron
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 <[email protected]>---
v1 -> v2:
- Changed code to use the BPF skeleton
- Replace static volatile with global variable in eBPF code.../testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c | 69 ++++++++++++++++++++ .../testing/selftests/bpf/progs/test_xdp_bpf2bpf.c | 44 +++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c create mode 100644
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.ctools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +0
-0tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 9
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +9
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <test_progs.h> +#include <net/if.h> +#include "test_xdp.skel.h" +#include "test_xdp_bpf2bpf.skel.h" + +void test_xdp_bpf2bpf (void ) +{ +extra line
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 11
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +2
-0+struct test_xdp *pkt_skel =NULL ; +struct test_xdp_bpf2bpf *ftrace_skel =NULL ;something with indentation?
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 13
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +2
-0+__u64 *ftrace_res; +variable declarations shouldn't be split, probably?
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+struct vip key4 = {.protocol =6 , .family =AF_INET }; +struct iptnl_info value4 = {.family =AF_INET }; +char buf[128 ]; +struct iphdr *iph = (void *)buf +sizeof (struct ethhdr ); +__u32 duration =0 , retval, size; +int err, pkt_fd, map_fd; + +/* Load XDP program to introspect */ + pkt_skel =test_xdp__open_and_load (); + if (CHECK(!pkt_skel, "pkt_skel_load", "test_xdp skeletonfailed\n"))
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 33
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+return ; + + pkt_fd =bpf_program__fd (pkt_skel->progs._xdp_tx_iptunnel); + + map_fd =bpf_map__fd (pkt_skel->maps.vip2tnl); +bpf_map_update_elem (map_fd, &key4, &value4,0 ); + +DECLARE_LIBBPF_OPTS (bpf_object_open_opts, opts, + .attach_prog_fd = pkt_fd, + );
DECLARE_LIBBPF_OPTSis a variable declaration, so should go together with all other declarations. Compiler should complain about this, but I guess selftests/bpfMakefiledoesn't have necessary flags, that other kernel code has. You can declare opts first and then initialize some extra fields later:
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts);... later in code ...
opts.attach_prog_fd =
pkt_fd;Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +3
-0+ + ftrace_skel =test_xdp_bpf2bpf__open_opts (&opts); + if (CHECK(!ftrace_skel, "__open", "ftrace skeletonfailed\n"))
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +3
-0+ goto out; + + if (CHECK(test_xdp_bpf2bpf__load(ftrace_skel), "__load","ftrace skeleton failed\n"))
+ goto out;for consistency with attach check below and for readability, move out load call into separate statement, it's easy to miss when it is inside
CHECK()Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +3
-0+ + err =test_xdp_bpf2bpf__attach (ftrace_skel); + if (CHECK(err, "ftrace_attach", "ftrace attach failed: %d\n",err))
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 53
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +10
-0+ goto out; + +/* Run test program */ + err =bpf_prog_test_run (pkt_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);should it goto out here as well?
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c line 64
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +11
-0+ +/* Verify test results */ + ftrace_res = (__u64 *)ftrace_skel->bss; + +if (CHECK (ftrace_res[0 ] !=if_nametoindex ("lo" ),"result" , +"fentry failed err %llu\n" , ftrace_res[0 ])) + goto out; + +if (CHECK (ftrace_res[1 ] !=XDP_TX ,"result" , +"fexit failed err %llu\n" , ftrace_res[1 ])) + goto out;why this casting? You can do access those variables much more naturally with
ftrace_skel->bss->test_result_fentryandftrace_skel->bss->test_result_fexitwithout making dangerous assumptions about their offsets within data section.Quoted 33 lines
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c new file +5
-0+ +out: +test_xdp__destroy (pkt_skel); +test_xdp_bpf2bpf__destroy (ftrace_skel); +}tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +22
-0@@ -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;tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c line 32
Quoted 10 lines
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +10
-0+void *data_end; +void *data_meta; +void *data_hard_start; +unsigned long handle; +struct xdp_rxq_info *rxq; +} __attribute__((preserve_access_index)); + +__u64 test_result_fentry =0 ; +BPF_TRACE_1 ("fentry/_xdp_tx_iptunnel" , trace_on_entry, + struct xdp_buff *, xdp)
BPF_TRACE_xis no more, seeBPF_PROGand how it's used for fentry/fexit tests:
SEC("fentry/_xdp_tx_iptunnel")
intBPF_PROG(trace_on_entry, struct xdp_buff *xdp)Quoted 13 lines
tools/testing/selftests/bpf/progs/test_xdp_bpf2bpf.c new file +12
-0+{ + test_result_fentry = xdp->rxq->dev->ifindex; +return 0 ; +} + +__u64 test_result_fexit =0 ; +BPF_TRACE_2 ("fexit/_xdp_tx_iptunnel" , trace_on_exit, + struct xdp_buff*, xdp, int, ret) +{ + test_result_fexit = ret; +return 0 ; +}