diff mbox series

[bpf-next,2/4] selftests: xsk: introduce XDP prog load based on existing AF_XDP socket

Message ID 20220629143458.934337-3-maciej.fijalkowski@intel.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series selftests: xsk: fix TEST_MODE_SKB in xdpxceiver | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
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: songliubraving@fb.com hawk@kernel.org linux-kselftest@vger.kernel.org davem@davemloft.net kuba@kernel.org john.fastabend@gmail.com yhs@fb.com kafai@fb.com shuah@kernel.org kpsingh@kernel.org
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, 26 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-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc

Commit Message

Maciej Fijalkowski June 29, 2022, 2:34 p.m. UTC
Currently, xsk_setup_xdp_prog() uses anonymous xsk_socket struct which
means that during xsk_create_bpf_link() call, xsk->config.xdp_flags is
always 0. This in turn means that from xdpxceiver it is impossible to
use xdpgeneric attachment, so since commit 3b22523bca02 ("selftests,
xsk: Fix bpf_res cleanup test") we were not testing SKB mode at all.

To fix this, introduce a function, called xsk_setup_xdp_prog_xsk(), that
will load XDP prog based on the existing xsk_socket, so that xsk
context's refcount is correctly bumped and flags from application side
are respected. Use this from xdpxceiver side so we get coverage of
generic and native XDP program attach points.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 tools/testing/selftests/bpf/xdpxceiver.c | 2 +-
 tools/testing/selftests/bpf/xsk.c        | 5 +++++
 tools/testing/selftests/bpf/xsk.h        | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

Comments

Magnus Karlsson June 30, 2022, 9:57 a.m. UTC | #1
On Wed, Jun 29, 2022 at 4:38 PM Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> Currently, xsk_setup_xdp_prog() uses anonymous xsk_socket struct which
> means that during xsk_create_bpf_link() call, xsk->config.xdp_flags is
> always 0. This in turn means that from xdpxceiver it is impossible to
> use xdpgeneric attachment, so since commit 3b22523bca02 ("selftests,
> xsk: Fix bpf_res cleanup test") we were not testing SKB mode at all.
>
> To fix this, introduce a function, called xsk_setup_xdp_prog_xsk(), that
> will load XDP prog based on the existing xsk_socket, so that xsk
> context's refcount is correctly bumped and flags from application side
> are respected. Use this from xdpxceiver side so we get coverage of
> generic and native XDP program attach points.

Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> ---
>  tools/testing/selftests/bpf/xdpxceiver.c | 2 +-
>  tools/testing/selftests/bpf/xsk.c        | 5 +++++
>  tools/testing/selftests/bpf/xsk.h        | 1 +
>  3 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
> index 019c567b6b4e..c024aa91ea02 100644
> --- a/tools/testing/selftests/bpf/xdpxceiver.c
> +++ b/tools/testing/selftests/bpf/xdpxceiver.c
> @@ -1130,7 +1130,7 @@ static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
>         if (!ifindex)
>                 exit_with_error(errno);
>
> -       ret = xsk_setup_xdp_prog(ifindex, &ifobject->xsk_map_fd);
> +       ret = xsk_setup_xdp_prog_xsk(ifobject->xsk->xsk, &ifobject->xsk_map_fd);
>         if (ret)
>                 exit_with_error(-ret);
>
> diff --git a/tools/testing/selftests/bpf/xsk.c b/tools/testing/selftests/bpf/xsk.c
> index fa13d2c44517..db911127720e 100644
> --- a/tools/testing/selftests/bpf/xsk.c
> +++ b/tools/testing/selftests/bpf/xsk.c
> @@ -880,6 +880,11 @@ static int __xsk_setup_xdp_prog(struct xsk_socket *_xdp, int *xsks_map_fd)
>         return err;
>  }
>
> +int xsk_setup_xdp_prog_xsk(struct xsk_socket *xsk, int *xsks_map_fd)
> +{
> +       return __xsk_setup_xdp_prog(xsk, xsks_map_fd);
> +}
> +
>  static struct xsk_ctx *xsk_get_ctx(struct xsk_umem *umem, int ifindex,
>                                    __u32 queue_id)
>  {
> diff --git a/tools/testing/selftests/bpf/xsk.h b/tools/testing/selftests/bpf/xsk.h
> index 915e7135337c..997723b0bfb2 100644
> --- a/tools/testing/selftests/bpf/xsk.h
> +++ b/tools/testing/selftests/bpf/xsk.h
> @@ -269,6 +269,7 @@ struct xsk_umem_config {
>         __u32 flags;
>  };
>
> +int xsk_setup_xdp_prog_xsk(struct xsk_socket *xsk, int *xsks_map_fd);
>  int xsk_setup_xdp_prog(int ifindex, int *xsks_map_fd);
>  int xsk_socket__update_xskmap(struct xsk_socket *xsk, int xsks_map_fd);
>
> --
> 2.27.0
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index 019c567b6b4e..c024aa91ea02 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -1130,7 +1130,7 @@  static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
 	if (!ifindex)
 		exit_with_error(errno);
 
-	ret = xsk_setup_xdp_prog(ifindex, &ifobject->xsk_map_fd);
+	ret = xsk_setup_xdp_prog_xsk(ifobject->xsk->xsk, &ifobject->xsk_map_fd);
 	if (ret)
 		exit_with_error(-ret);
 
diff --git a/tools/testing/selftests/bpf/xsk.c b/tools/testing/selftests/bpf/xsk.c
index fa13d2c44517..db911127720e 100644
--- a/tools/testing/selftests/bpf/xsk.c
+++ b/tools/testing/selftests/bpf/xsk.c
@@ -880,6 +880,11 @@  static int __xsk_setup_xdp_prog(struct xsk_socket *_xdp, int *xsks_map_fd)
 	return err;
 }
 
+int xsk_setup_xdp_prog_xsk(struct xsk_socket *xsk, int *xsks_map_fd)
+{
+	return __xsk_setup_xdp_prog(xsk, xsks_map_fd);
+}
+
 static struct xsk_ctx *xsk_get_ctx(struct xsk_umem *umem, int ifindex,
 				   __u32 queue_id)
 {
diff --git a/tools/testing/selftests/bpf/xsk.h b/tools/testing/selftests/bpf/xsk.h
index 915e7135337c..997723b0bfb2 100644
--- a/tools/testing/selftests/bpf/xsk.h
+++ b/tools/testing/selftests/bpf/xsk.h
@@ -269,6 +269,7 @@  struct xsk_umem_config {
 	__u32 flags;
 };
 
+int xsk_setup_xdp_prog_xsk(struct xsk_socket *xsk, int *xsks_map_fd);
 int xsk_setup_xdp_prog(int ifindex, int *xsks_map_fd);
 int xsk_socket__update_xskmap(struct xsk_socket *xsk, int xsks_map_fd);