diff mbox series

[bpf-next,12/15] selftests/xsk: add test when some packets are XDP_DROPed

Message ID 20221206090826.2957-13-magnus.karlsson@gmail.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series selftests/xsk: speed-ups, fixes, and new XDP programs | expand

Checks

Context Check Description
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 6 maintainers not CCed: linux-kselftest@vger.kernel.org davem@davemloft.net kuba@kernel.org shuah@kernel.org hawk@kernel.org mykolal@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 warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? WARNING: line length of 89 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain }}
bpf/vmtest-bpf-next-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 fail Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-9 success Logs for set-matrix

Commit Message

Magnus Karlsson Dec. 6, 2022, 9:08 a.m. UTC
From: Magnus Karlsson <magnus.karlsson@intel.com>

Add a new test where some of the packets are not passed to the AF_XDP
socket and instead get a XDP_DROP verdict. This is important as it
tests the recycling mechanism of the buffer pool. If a packet is not
sent to the AF_XDP socket, the buffer the packet resides in is instead
recycled so it can be used again without the round-trip to user
space. The test introduces a new XDP program that drops every other
packet.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 tools/testing/selftests/bpf/Makefile          |  2 +-
 .../selftests/bpf/progs/xsk_xdp_drop.c        | 25 ++++++++++
 tools/testing/selftests/bpf/xskxceiver.c      | 48 +++++++++++++++++--
 tools/testing/selftests/bpf/xskxceiver.h      |  3 ++
 4 files changed, 72 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/xsk_xdp_drop.c

Comments

Fijalkowski, Maciej Dec. 12, 2022, 3:13 p.m. UTC | #1
On Tue, Dec 06, 2022 at 10:08:23AM +0100, Magnus Karlsson wrote:
> From: Magnus Karlsson <magnus.karlsson@intel.com>
> 
> Add a new test where some of the packets are not passed to the AF_XDP
> socket and instead get a XDP_DROP verdict. This is important as it
> tests the recycling mechanism of the buffer pool. If a packet is not
> sent to the AF_XDP socket, the buffer the packet resides in is instead
> recycled so it can be used again without the round-trip to user
> space. The test introduces a new XDP program that drops every other
> packet.
> 
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> ---
>  tools/testing/selftests/bpf/Makefile          |  2 +-
>  .../selftests/bpf/progs/xsk_xdp_drop.c        | 25 ++++++++++
>  tools/testing/selftests/bpf/xskxceiver.c      | 48 +++++++++++++++++--
>  tools/testing/selftests/bpf/xskxceiver.h      |  3 ++
>  4 files changed, 72 insertions(+), 6 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 42e15b5a34a7..77ef8a8e6db4 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -240,7 +240,7 @@ $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS)
>  $(OUTPUT)/test_maps: $(TESTING_HELPERS)
>  $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS)
>  $(OUTPUT)/xsk.o: $(BPFOBJ)
> -$(OUTPUT)/xskxceiver: $(OUTPUT)/xsk.o $(OUTPUT)/xsk_def_prog.skel.h
> +$(OUTPUT)/xskxceiver: $(OUTPUT)/xsk.o $(OUTPUT)/xsk_def_prog.skel.h $(OUTPUT)/xsk_xdp_drop.skel.h
>  
>  BPFTOOL ?= $(DEFAULT_BPFTOOL)
>  $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)    \
> diff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c b/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
> new file mode 100644
> index 000000000000..12a12b0d9fc1
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
> @@ -0,0 +1,25 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2022 Intel */
> +
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +struct {
> +	__uint(type, BPF_MAP_TYPE_XSKMAP);
> +	__uint(max_entries, 1);
> +	__uint(key_size, sizeof(int));
> +	__uint(value_size, sizeof(int));
> +} xsk SEC(".maps");
> +
> +static unsigned int idx;
> +
> +SEC("xdp") int xsk_xdp_drop(struct xdp_md *xdp)
> +{
> +	/* Drop every other packet */
> +	if (idx++ % 2)
> +		return XDP_DROP;
> +
> +	return bpf_redirect_map(&xsk, 0, XDP_DROP);
> +}
> +
> +char _license[] SEC("license") = "GPL";
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index 0cda4e3f1871..522dc1d69c17 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -1654,18 +1654,53 @@ static void testapp_invalid_desc(struct test_spec *test)
>  	pkt_stream_restore_default(test);
>  }
>  
> -static int xsk_load_xdp_program(struct ifobject *ifobj)
> +static void testapp_xdp_drop(struct test_spec *test)
> +{
> +	struct ifobject *ifobj = test->ifobj_rx;
> +	int err;
> +
> +	test_spec_set_name(test, "XDP_CONSUMES_SOME_PACKETS");

XDP_DROP_ODD_PACKETS ?

> +	xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
> +	err = xsk_attach_xdp_program(ifobj->xdp_drop->progs.xsk_xdp_drop, ifobj->ifindex,
> +				     ifobj->xdp_flags);
> +	if (err) {
> +		printf("Error attaching XDP_DROP program\n");
> +		test->fail = true;
> +		return;
> +	}
> +	ifobj->xskmap = ifobj->xdp_drop->maps.xsk;
> +
> +	pkt_stream_receive_half(test);
> +	testapp_validate_traffic(test);
> +
> +	pkt_stream_restore_default(test);
> +	xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
> +	err = xsk_attach_xdp_program(ifobj->def_prog->progs.xsk_def_prog, ifobj->ifindex,
> +				     ifobj->xdp_flags);
> +	if (err) {
> +		printf("Error restoring default XDP program\n");
> +		exit_with_error(-err);
> +	}
> +	ifobj->xskmap = ifobj->def_prog->maps.xsk;
> +}
> +
> +static int xsk_load_xdp_programs(struct ifobject *ifobj)
>  {
>  	ifobj->def_prog = xsk_def_prog__open_and_load();
>  	if (libbpf_get_error(ifobj->def_prog))
>  		return libbpf_get_error(ifobj->def_prog);
>  
> +	ifobj->xdp_drop = xsk_xdp_drop__open_and_load();
> +	if (libbpf_get_error(ifobj->xdp_drop))
> +		return libbpf_get_error(ifobj->xdp_drop);
> +
>  	return 0;
>  }
>  
> -static void xsk_unload_xdp_program(struct ifobject *ifobj)
> +static void xsk_unload_xdp_programs(struct ifobject *ifobj)
>  {
>  	xsk_def_prog__destroy(ifobj->def_prog);
> +	xsk_xdp_drop__destroy(ifobj->xdp_drop);
>  }
>  
>  static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac,
> @@ -1692,7 +1727,7 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *
>  	if (!load_xdp)
>  		return;
>  
> -	err = xsk_load_xdp_program(ifobj);
> +	err = xsk_load_xdp_programs(ifobj);
>  	if (err) {
>  		printf("Error loading XDP program\n");
>  		exit_with_error(err);
> @@ -1804,6 +1839,9 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_
>  	case TEST_TYPE_HEADROOM:
>  		testapp_headroom(test);
>  		break;
> +	case TEST_TYPE_XDP_CONSUMES_PACKETS:
> +		testapp_xdp_drop(test);
> +		break;
>  	default:
>  		break;
>  	}
> @@ -1971,8 +2009,8 @@ int main(int argc, char **argv)
>  
>  	pkt_stream_delete(tx_pkt_stream_default);
>  	pkt_stream_delete(rx_pkt_stream_default);
> -	xsk_unload_xdp_program(ifobj_tx);
> -	xsk_unload_xdp_program(ifobj_rx);
> +	xsk_unload_xdp_programs(ifobj_tx);
> +	xsk_unload_xdp_programs(ifobj_rx);
>  	ifobject_delete(ifobj_tx);
>  	ifobject_delete(ifobj_rx);
>  
> diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
> index eb6355bcc143..3483ac240b2e 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.h
> +++ b/tools/testing/selftests/bpf/xskxceiver.h
> @@ -6,6 +6,7 @@
>  #define XSKXCEIVER_H_
>  
>  #include "xsk_def_prog.skel.h"
> +#include "xsk_xdp_drop.skel.h"
>  
>  #ifndef SOL_XDP
>  #define SOL_XDP 283
> @@ -87,6 +88,7 @@ enum test_type {
>  	TEST_TYPE_STATS_RX_FULL,
>  	TEST_TYPE_STATS_FILL_EMPTY,
>  	TEST_TYPE_BPF_RES,
> +	TEST_TYPE_XDP_CONSUMES_PACKETS,
>  	TEST_TYPE_MAX
>  };
>  
> @@ -141,6 +143,7 @@ struct ifobject {
>  	validation_func_t validation_func;
>  	struct pkt_stream *pkt_stream;
>  	struct xsk_def_prog *def_prog;
> +	struct xsk_xdp_drop *xdp_drop;

Is this going to scale if we add plenty of XDP progs for testing?

>  	struct bpf_map *xskmap;
>  	int ifindex;
>  	u32 dst_ip;
> -- 
> 2.34.1
>
Magnus Karlsson Dec. 14, 2022, 10:53 a.m. UTC | #2
On Mon, Dec 12, 2022 at 4:14 PM Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> On Tue, Dec 06, 2022 at 10:08:23AM +0100, Magnus Karlsson wrote:
> > From: Magnus Karlsson <magnus.karlsson@intel.com>
> >
> > Add a new test where some of the packets are not passed to the AF_XDP
> > socket and instead get a XDP_DROP verdict. This is important as it
> > tests the recycling mechanism of the buffer pool. If a packet is not
> > sent to the AF_XDP socket, the buffer the packet resides in is instead
> > recycled so it can be used again without the round-trip to user
> > space. The test introduces a new XDP program that drops every other
> > packet.
> >
> > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> > ---
> >  tools/testing/selftests/bpf/Makefile          |  2 +-
> >  .../selftests/bpf/progs/xsk_xdp_drop.c        | 25 ++++++++++
> >  tools/testing/selftests/bpf/xskxceiver.c      | 48 +++++++++++++++++--
> >  tools/testing/selftests/bpf/xskxceiver.h      |  3 ++
> >  4 files changed, 72 insertions(+), 6 deletions(-)
> >  create mode 100644 tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 42e15b5a34a7..77ef8a8e6db4 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -240,7 +240,7 @@ $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS)
> >  $(OUTPUT)/test_maps: $(TESTING_HELPERS)
> >  $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS)
> >  $(OUTPUT)/xsk.o: $(BPFOBJ)
> > -$(OUTPUT)/xskxceiver: $(OUTPUT)/xsk.o $(OUTPUT)/xsk_def_prog.skel.h
> > +$(OUTPUT)/xskxceiver: $(OUTPUT)/xsk.o $(OUTPUT)/xsk_def_prog.skel.h $(OUTPUT)/xsk_xdp_drop.skel.h
> >
> >  BPFTOOL ?= $(DEFAULT_BPFTOOL)
> >  $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)    \
> > diff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c b/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
> > new file mode 100644
> > index 000000000000..12a12b0d9fc1
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
> > @@ -0,0 +1,25 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Copyright (c) 2022 Intel */
> > +
> > +#include <linux/bpf.h>
> > +#include <bpf/bpf_helpers.h>
> > +
> > +struct {
> > +     __uint(type, BPF_MAP_TYPE_XSKMAP);
> > +     __uint(max_entries, 1);
> > +     __uint(key_size, sizeof(int));
> > +     __uint(value_size, sizeof(int));
> > +} xsk SEC(".maps");
> > +
> > +static unsigned int idx;
> > +
> > +SEC("xdp") int xsk_xdp_drop(struct xdp_md *xdp)
> > +{
> > +     /* Drop every other packet */
> > +     if (idx++ % 2)
> > +             return XDP_DROP;
> > +
> > +     return bpf_redirect_map(&xsk, 0, XDP_DROP);
> > +}
> > +
> > +char _license[] SEC("license") = "GPL";
> > diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> > index 0cda4e3f1871..522dc1d69c17 100644
> > --- a/tools/testing/selftests/bpf/xskxceiver.c
> > +++ b/tools/testing/selftests/bpf/xskxceiver.c
> > @@ -1654,18 +1654,53 @@ static void testapp_invalid_desc(struct test_spec *test)
> >       pkt_stream_restore_default(test);
> >  }
> >
> > -static int xsk_load_xdp_program(struct ifobject *ifobj)
> > +static void testapp_xdp_drop(struct test_spec *test)
> > +{
> > +     struct ifobject *ifobj = test->ifobj_rx;
> > +     int err;
> > +
> > +     test_spec_set_name(test, "XDP_CONSUMES_SOME_PACKETS");
>
> XDP_DROP_ODD_PACKETS ?

Ha! What is an ODD packet?!?! I will think of a better name than these two.

> > +     xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
> > +     err = xsk_attach_xdp_program(ifobj->xdp_drop->progs.xsk_xdp_drop, ifobj->ifindex,
> > +                                  ifobj->xdp_flags);
> > +     if (err) {
> > +             printf("Error attaching XDP_DROP program\n");
> > +             test->fail = true;
> > +             return;
> > +     }
> > +     ifobj->xskmap = ifobj->xdp_drop->maps.xsk;
> > +
> > +     pkt_stream_receive_half(test);
> > +     testapp_validate_traffic(test);
> > +
> > +     pkt_stream_restore_default(test);
> > +     xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
> > +     err = xsk_attach_xdp_program(ifobj->def_prog->progs.xsk_def_prog, ifobj->ifindex,
> > +                                  ifobj->xdp_flags);
> > +     if (err) {
> > +             printf("Error restoring default XDP program\n");
> > +             exit_with_error(-err);
> > +     }
> > +     ifobj->xskmap = ifobj->def_prog->maps.xsk;
> > +}
> > +
> > +static int xsk_load_xdp_programs(struct ifobject *ifobj)
> >  {
> >       ifobj->def_prog = xsk_def_prog__open_and_load();
> >       if (libbpf_get_error(ifobj->def_prog))
> >               return libbpf_get_error(ifobj->def_prog);
> >
> > +     ifobj->xdp_drop = xsk_xdp_drop__open_and_load();
> > +     if (libbpf_get_error(ifobj->xdp_drop))
> > +             return libbpf_get_error(ifobj->xdp_drop);
> > +
> >       return 0;
> >  }
> >
> > -static void xsk_unload_xdp_program(struct ifobject *ifobj)
> > +static void xsk_unload_xdp_programs(struct ifobject *ifobj)
> >  {
> >       xsk_def_prog__destroy(ifobj->def_prog);
> > +     xsk_xdp_drop__destroy(ifobj->xdp_drop);
> >  }
> >
> >  static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac,
> > @@ -1692,7 +1727,7 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *
> >       if (!load_xdp)
> >               return;
> >
> > -     err = xsk_load_xdp_program(ifobj);
> > +     err = xsk_load_xdp_programs(ifobj);
> >       if (err) {
> >               printf("Error loading XDP program\n");
> >               exit_with_error(err);
> > @@ -1804,6 +1839,9 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_
> >       case TEST_TYPE_HEADROOM:
> >               testapp_headroom(test);
> >               break;
> > +     case TEST_TYPE_XDP_CONSUMES_PACKETS:
> > +             testapp_xdp_drop(test);
> > +             break;
> >       default:
> >               break;
> >       }
> > @@ -1971,8 +2009,8 @@ int main(int argc, char **argv)
> >
> >       pkt_stream_delete(tx_pkt_stream_default);
> >       pkt_stream_delete(rx_pkt_stream_default);
> > -     xsk_unload_xdp_program(ifobj_tx);
> > -     xsk_unload_xdp_program(ifobj_rx);
> > +     xsk_unload_xdp_programs(ifobj_tx);
> > +     xsk_unload_xdp_programs(ifobj_rx);
> >       ifobject_delete(ifobj_tx);
> >       ifobject_delete(ifobj_rx);
> >
> > diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
> > index eb6355bcc143..3483ac240b2e 100644
> > --- a/tools/testing/selftests/bpf/xskxceiver.h
> > +++ b/tools/testing/selftests/bpf/xskxceiver.h
> > @@ -6,6 +6,7 @@
> >  #define XSKXCEIVER_H_
> >
> >  #include "xsk_def_prog.skel.h"
> > +#include "xsk_xdp_drop.skel.h"
> >
> >  #ifndef SOL_XDP
> >  #define SOL_XDP 283
> > @@ -87,6 +88,7 @@ enum test_type {
> >       TEST_TYPE_STATS_RX_FULL,
> >       TEST_TYPE_STATS_FILL_EMPTY,
> >       TEST_TYPE_BPF_RES,
> > +     TEST_TYPE_XDP_CONSUMES_PACKETS,
> >       TEST_TYPE_MAX
> >  };
> >
> > @@ -141,6 +143,7 @@ struct ifobject {
> >       validation_func_t validation_func;
> >       struct pkt_stream *pkt_stream;
> >       struct xsk_def_prog *def_prog;
> > +     struct xsk_xdp_drop *xdp_drop;
>
> Is this going to scale if we add plenty of XDP progs for testing?

Good point. No. I will put the programs in the same source file and
see if that makes it better.

> >       struct bpf_map *xskmap;
> >       int ifindex;
> >       u32 dst_ip;
> > --
> > 2.34.1
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 42e15b5a34a7..77ef8a8e6db4 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -240,7 +240,7 @@  $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS)
 $(OUTPUT)/test_maps: $(TESTING_HELPERS)
 $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS)
 $(OUTPUT)/xsk.o: $(BPFOBJ)
-$(OUTPUT)/xskxceiver: $(OUTPUT)/xsk.o $(OUTPUT)/xsk_def_prog.skel.h
+$(OUTPUT)/xskxceiver: $(OUTPUT)/xsk.o $(OUTPUT)/xsk_def_prog.skel.h $(OUTPUT)/xsk_xdp_drop.skel.h
 
 BPFTOOL ?= $(DEFAULT_BPFTOOL)
 $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)    \
diff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c b/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
new file mode 100644
index 000000000000..12a12b0d9fc1
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/xsk_xdp_drop.c
@@ -0,0 +1,25 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2022 Intel */
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+
+struct {
+	__uint(type, BPF_MAP_TYPE_XSKMAP);
+	__uint(max_entries, 1);
+	__uint(key_size, sizeof(int));
+	__uint(value_size, sizeof(int));
+} xsk SEC(".maps");
+
+static unsigned int idx;
+
+SEC("xdp") int xsk_xdp_drop(struct xdp_md *xdp)
+{
+	/* Drop every other packet */
+	if (idx++ % 2)
+		return XDP_DROP;
+
+	return bpf_redirect_map(&xsk, 0, XDP_DROP);
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 0cda4e3f1871..522dc1d69c17 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -1654,18 +1654,53 @@  static void testapp_invalid_desc(struct test_spec *test)
 	pkt_stream_restore_default(test);
 }
 
-static int xsk_load_xdp_program(struct ifobject *ifobj)
+static void testapp_xdp_drop(struct test_spec *test)
+{
+	struct ifobject *ifobj = test->ifobj_rx;
+	int err;
+
+	test_spec_set_name(test, "XDP_CONSUMES_SOME_PACKETS");
+	xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
+	err = xsk_attach_xdp_program(ifobj->xdp_drop->progs.xsk_xdp_drop, ifobj->ifindex,
+				     ifobj->xdp_flags);
+	if (err) {
+		printf("Error attaching XDP_DROP program\n");
+		test->fail = true;
+		return;
+	}
+	ifobj->xskmap = ifobj->xdp_drop->maps.xsk;
+
+	pkt_stream_receive_half(test);
+	testapp_validate_traffic(test);
+
+	pkt_stream_restore_default(test);
+	xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
+	err = xsk_attach_xdp_program(ifobj->def_prog->progs.xsk_def_prog, ifobj->ifindex,
+				     ifobj->xdp_flags);
+	if (err) {
+		printf("Error restoring default XDP program\n");
+		exit_with_error(-err);
+	}
+	ifobj->xskmap = ifobj->def_prog->maps.xsk;
+}
+
+static int xsk_load_xdp_programs(struct ifobject *ifobj)
 {
 	ifobj->def_prog = xsk_def_prog__open_and_load();
 	if (libbpf_get_error(ifobj->def_prog))
 		return libbpf_get_error(ifobj->def_prog);
 
+	ifobj->xdp_drop = xsk_xdp_drop__open_and_load();
+	if (libbpf_get_error(ifobj->xdp_drop))
+		return libbpf_get_error(ifobj->xdp_drop);
+
 	return 0;
 }
 
-static void xsk_unload_xdp_program(struct ifobject *ifobj)
+static void xsk_unload_xdp_programs(struct ifobject *ifobj)
 {
 	xsk_def_prog__destroy(ifobj->def_prog);
+	xsk_xdp_drop__destroy(ifobj->xdp_drop);
 }
 
 static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac,
@@ -1692,7 +1727,7 @@  static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *
 	if (!load_xdp)
 		return;
 
-	err = xsk_load_xdp_program(ifobj);
+	err = xsk_load_xdp_programs(ifobj);
 	if (err) {
 		printf("Error loading XDP program\n");
 		exit_with_error(err);
@@ -1804,6 +1839,9 @@  static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_
 	case TEST_TYPE_HEADROOM:
 		testapp_headroom(test);
 		break;
+	case TEST_TYPE_XDP_CONSUMES_PACKETS:
+		testapp_xdp_drop(test);
+		break;
 	default:
 		break;
 	}
@@ -1971,8 +2009,8 @@  int main(int argc, char **argv)
 
 	pkt_stream_delete(tx_pkt_stream_default);
 	pkt_stream_delete(rx_pkt_stream_default);
-	xsk_unload_xdp_program(ifobj_tx);
-	xsk_unload_xdp_program(ifobj_rx);
+	xsk_unload_xdp_programs(ifobj_tx);
+	xsk_unload_xdp_programs(ifobj_rx);
 	ifobject_delete(ifobj_tx);
 	ifobject_delete(ifobj_rx);
 
diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
index eb6355bcc143..3483ac240b2e 100644
--- a/tools/testing/selftests/bpf/xskxceiver.h
+++ b/tools/testing/selftests/bpf/xskxceiver.h
@@ -6,6 +6,7 @@ 
 #define XSKXCEIVER_H_
 
 #include "xsk_def_prog.skel.h"
+#include "xsk_xdp_drop.skel.h"
 
 #ifndef SOL_XDP
 #define SOL_XDP 283
@@ -87,6 +88,7 @@  enum test_type {
 	TEST_TYPE_STATS_RX_FULL,
 	TEST_TYPE_STATS_FILL_EMPTY,
 	TEST_TYPE_BPF_RES,
+	TEST_TYPE_XDP_CONSUMES_PACKETS,
 	TEST_TYPE_MAX
 };
 
@@ -141,6 +143,7 @@  struct ifobject {
 	validation_func_t validation_func;
 	struct pkt_stream *pkt_stream;
 	struct xsk_def_prog *def_prog;
+	struct xsk_xdp_drop *xdp_drop;
 	struct bpf_map *xskmap;
 	int ifindex;
 	u32 dst_ip;