]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: bpf: have a separate variable for drop test
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Thu, 2 Apr 2026 15:49:57 +0000 (17:49 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 7 Apr 2026 01:43:52 +0000 (18:43 -0700)
Currently two different XDP programs share a static variable for
different purposes (picking where to redirect on shared umem test &
whether to drop a packet). This can be a problem when running full test
suite - idx can be written by shared umem test and this value can cause
a false behavior within XDP drop half test.

Introduce a dedicated variable for drop half test so that these two
don't step on each other toes. There is no real need for using
__sync_fetch_and_add here as XSK tests are executed on single CPU.

Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://patch.msgid.link/20260402154958.562179-8-maciej.fijalkowski@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/bpf/progs/xsk_xdp_progs.c

index 683306db8594e196659b10623d8820136ad852dd..023d8befd4cab03feca07a6bf92966c64f5519e1 100644 (file)
@@ -26,8 +26,10 @@ SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp)
 
 SEC("xdp.frags") int xsk_xdp_drop(struct xdp_md *xdp)
 {
+       static unsigned int drop_idx;
+
        /* Drop every other packet */
-       if (idx++ % 2)
+       if (drop_idx++ % 2)
                return XDP_DROP;
 
        return bpf_redirect_map(&xsk, 0, XDP_DROP);