diff mbox series

[v3,bpf-next,7/8] selftests/bpf: add test for bpf_xdp_query xdp-features support

Message ID 7c403a3a043554df3ebe4b4a94b8e0d97414cb7e.1674737592.git.lorenzo@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series xdp: introduce xdp-feature support | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on s390x with gcc
netdev/tree_selection success Clearly marked for bpf-next, async
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 success Link
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 10 maintainers not CCed: sdf@google.com kpsingh@kernel.org jolsa@kernel.org mykolal@fb.com song@kernel.org linux-kselftest@vger.kernel.org john.fastabend@gmail.com shuah@kernel.org haoluo@google.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/check_selftest success No net selftest shell script
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, 69 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-7 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 fail Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16

Commit Message

Lorenzo Bianconi Jan. 26, 2023, 12:58 p.m. UTC
Introduce a self-test to verify libbpf bpf_xdp_query capability to dump
the xdp-features supported by the device (lo and veth in this case).

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../bpf/prog_tests/xdp_do_redirect.c          | 27 ++++++++++++++++++-
 .../selftests/bpf/prog_tests/xdp_info.c       |  8 ++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

Comments

Stanislav Fomichev Jan. 26, 2023, 6:28 p.m. UTC | #1
On 01/26, Lorenzo Bianconi wrote:
> Introduce a self-test to verify libbpf bpf_xdp_query capability to dump
> the xdp-features supported by the device (lo and veth in this case).

> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Acked-by: Stanislav Fomichev <sdf@google.com>

> ---
>   .../bpf/prog_tests/xdp_do_redirect.c          | 27 ++++++++++++++++++-
>   .../selftests/bpf/prog_tests/xdp_info.c       |  8 ++++++
>   2 files changed, 34 insertions(+), 1 deletion(-)

> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c  
> b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
> index a50971c6cf4a..e15fb3f0306c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
> @@ -4,10 +4,12 @@
>   #include <net/if.h>
>   #include <linux/if_ether.h>
>   #include <linux/if_packet.h>
> +#include <linux/if_link.h>
>   #include <linux/ipv6.h>
>   #include <linux/in6.h>
>   #include <linux/udp.h>
>   #include <bpf/bpf_endian.h>
> +#include <uapi/linux/netdev.h>
>   #include "test_xdp_do_redirect.skel.h"

>   #define SYS(fmt, ...)						\
> @@ -92,7 +94,7 @@ void test_xdp_do_redirect(void)
>   	struct test_xdp_do_redirect *skel = NULL;
>   	struct nstoken *nstoken = NULL;
>   	struct bpf_link *link;
> -
> +	LIBBPF_OPTS(bpf_xdp_query_opts, query_opts);
>   	struct xdp_md ctx_in = { .data = sizeof(__u32),
>   				 .data_end = sizeof(data) };
>   	DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
> @@ -153,6 +155,29 @@ void test_xdp_do_redirect(void)
>   	    !ASSERT_NEQ(ifindex_dst, 0, "ifindex_dst"))
>   		goto out;

> +	/* Check xdp features supported by veth driver */
> +	err = bpf_xdp_query(ifindex_src, XDP_FLAGS_DRV_MODE, &query_opts);
> +	if (!ASSERT_OK(err, "veth_src bpf_xdp_query"))
> +		goto out;
> +
> +	if (!ASSERT_EQ(query_opts.fflags,
> +		       NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
> +		       NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
> +		       NETDEV_XDP_ACT_NDO_XMIT_SG,
> +		       "veth_src query_opts.fflags"))
> +		goto out;
> +
> +	err = bpf_xdp_query(ifindex_dst, XDP_FLAGS_DRV_MODE, &query_opts);
> +	if (!ASSERT_OK(err, "veth_dst bpf_xdp_query"))
> +		goto out;
> +
> +	if (!ASSERT_EQ(query_opts.fflags,
> +		       NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
> +		       NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
> +		       NETDEV_XDP_ACT_NDO_XMIT_SG,
> +		       "veth_dst query_opts.fflags"))
> +		goto out;
> +
>   	memcpy(skel->rodata->expect_dst, &pkt_udp.eth.h_dest, ETH_ALEN);
>   	skel->rodata->ifindex_out = ifindex_src; /* redirect back to the same  
> iface */
>   	skel->rodata->ifindex_in = ifindex_src;
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_info.c  
> b/tools/testing/selftests/bpf/prog_tests/xdp_info.c
> index cd3aa340e65e..8397468a9e74 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_info.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_info.c
> @@ -8,6 +8,7 @@ void serial_test_xdp_info(void)
>   {
>   	__u32 len = sizeof(struct bpf_prog_info), duration = 0, prog_id;
>   	const char *file = "./xdp_dummy.bpf.o";
> +	LIBBPF_OPTS(bpf_xdp_query_opts, opts);
>   	struct bpf_prog_info info = {};
>   	struct bpf_object *obj;
>   	int err, prog_fd;
> @@ -61,6 +62,13 @@ void serial_test_xdp_info(void)
>   	if (CHECK(prog_id, "prog_id_drv", "unexpected prog_id=%u\n", prog_id))
>   		goto out;

> +	/* Check xdp features supported by lo device */
> +	opts.fflags = ~0;
> +	err = bpf_xdp_query(IFINDEX_LO, XDP_FLAGS_DRV_MODE, &opts);
> +	if (!ASSERT_OK(err, "bpf_xdp_query"))
> +		goto out;
> +
> +	ASSERT_EQ(opts.fflags, 0, "opts.fflags");
>   out:
>   	bpf_xdp_detach(IFINDEX_LO, 0, NULL);
>   out_close:
> --
> 2.39.1
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
index a50971c6cf4a..e15fb3f0306c 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
@@ -4,10 +4,12 @@ 
 #include <net/if.h>
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
+#include <linux/if_link.h>
 #include <linux/ipv6.h>
 #include <linux/in6.h>
 #include <linux/udp.h>
 #include <bpf/bpf_endian.h>
+#include <uapi/linux/netdev.h>
 #include "test_xdp_do_redirect.skel.h"
 
 #define SYS(fmt, ...)						\
@@ -92,7 +94,7 @@  void test_xdp_do_redirect(void)
 	struct test_xdp_do_redirect *skel = NULL;
 	struct nstoken *nstoken = NULL;
 	struct bpf_link *link;
-
+	LIBBPF_OPTS(bpf_xdp_query_opts, query_opts);
 	struct xdp_md ctx_in = { .data = sizeof(__u32),
 				 .data_end = sizeof(data) };
 	DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
@@ -153,6 +155,29 @@  void test_xdp_do_redirect(void)
 	    !ASSERT_NEQ(ifindex_dst, 0, "ifindex_dst"))
 		goto out;
 
+	/* Check xdp features supported by veth driver */
+	err = bpf_xdp_query(ifindex_src, XDP_FLAGS_DRV_MODE, &query_opts);
+	if (!ASSERT_OK(err, "veth_src bpf_xdp_query"))
+		goto out;
+
+	if (!ASSERT_EQ(query_opts.fflags,
+		       NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
+		       NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
+		       NETDEV_XDP_ACT_NDO_XMIT_SG,
+		       "veth_src query_opts.fflags"))
+		goto out;
+
+	err = bpf_xdp_query(ifindex_dst, XDP_FLAGS_DRV_MODE, &query_opts);
+	if (!ASSERT_OK(err, "veth_dst bpf_xdp_query"))
+		goto out;
+
+	if (!ASSERT_EQ(query_opts.fflags,
+		       NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
+		       NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
+		       NETDEV_XDP_ACT_NDO_XMIT_SG,
+		       "veth_dst query_opts.fflags"))
+		goto out;
+
 	memcpy(skel->rodata->expect_dst, &pkt_udp.eth.h_dest, ETH_ALEN);
 	skel->rodata->ifindex_out = ifindex_src; /* redirect back to the same iface */
 	skel->rodata->ifindex_in = ifindex_src;
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_info.c b/tools/testing/selftests/bpf/prog_tests/xdp_info.c
index cd3aa340e65e..8397468a9e74 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_info.c
@@ -8,6 +8,7 @@  void serial_test_xdp_info(void)
 {
 	__u32 len = sizeof(struct bpf_prog_info), duration = 0, prog_id;
 	const char *file = "./xdp_dummy.bpf.o";
+	LIBBPF_OPTS(bpf_xdp_query_opts, opts);
 	struct bpf_prog_info info = {};
 	struct bpf_object *obj;
 	int err, prog_fd;
@@ -61,6 +62,13 @@  void serial_test_xdp_info(void)
 	if (CHECK(prog_id, "prog_id_drv", "unexpected prog_id=%u\n", prog_id))
 		goto out;
 
+	/* Check xdp features supported by lo device */
+	opts.fflags = ~0;
+	err = bpf_xdp_query(IFINDEX_LO, XDP_FLAGS_DRV_MODE, &opts);
+	if (!ASSERT_OK(err, "bpf_xdp_query"))
+		goto out;
+
+	ASSERT_EQ(opts.fflags, 0, "opts.fflags");
 out:
 	bpf_xdp_detach(IFINDEX_LO, 0, NULL);
 out_close: