]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: test_xsk: fix memory leak in testapp_xdp_shared_umem()
authorBastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Fri, 31 Oct 2025 08:04:41 +0000 (09:04 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 31 Oct 2025 16:24:38 +0000 (09:24 -0700)
testapp_xdp_shared_umem() generates pkt_stream on each xsk from xsk_arr,
where normally xsk_arr[0] gets pkt_streams and xsk_arr[1] have them NULLed.
At the end of the test pkt_stream_restore_default() only releases
xsk_arr[0] which leads to memory leaks.

Release the missing pkt_stream at the end of testapp_xdp_shared_umem()

Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Link: https://lore.kernel.org/r/20251031-xsk-v7-5-39fe486593a3@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_xsk.c

index eb18288ea1e4aa1c9337d16333b7174ecaed0999..d7cb2821469c62abd0d532821e836336a2177eb5 100644 (file)
@@ -570,6 +570,22 @@ static void pkt_stream_even_odd_sequence(struct test_spec *test)
        }
 }
 
+static void release_even_odd_sequence(struct test_spec *test)
+{
+       struct pkt_stream *later_free_tx = test->ifobj_tx->xsk->pkt_stream;
+       struct pkt_stream *later_free_rx = test->ifobj_rx->xsk->pkt_stream;
+       int i;
+
+       for (i = 0; i < test->nb_sockets; i++) {
+               /* later_free_{rx/tx} will be freed by restore_default() */
+               if (test->ifobj_tx->xsk_arr[i].pkt_stream != later_free_tx)
+                       pkt_stream_delete(test->ifobj_tx->xsk_arr[i].pkt_stream);
+               if (test->ifobj_rx->xsk_arr[i].pkt_stream != later_free_rx)
+                       pkt_stream_delete(test->ifobj_rx->xsk_arr[i].pkt_stream);
+       }
+
+}
+
 static u64 pkt_get_addr(struct pkt *pkt, struct xsk_umem_info *umem)
 {
        if (!pkt->valid)
@@ -2043,6 +2059,7 @@ int testapp_xdp_shared_umem(struct test_spec *test)
 {
        struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs;
        struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs;
+       int ret;
 
        test->total_steps = 1;
        test->nb_sockets = 2;
@@ -2053,7 +2070,11 @@ int testapp_xdp_shared_umem(struct test_spec *test)
 
        pkt_stream_even_odd_sequence(test);
 
-       return testapp_validate_traffic(test);
+       ret = testapp_validate_traffic(test);
+
+       release_even_odd_sequence(test);
+
+       return ret;
 }
 
 int testapp_poll_txq_tmout(struct test_spec *test)