selftests/bpf: test_xsk: fix memory leak in testapp_xdp_shared_umem()

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>
This commit is contained in:
Bastien Curutchet (eBPF Foundation)
2025-10-31 09:04:41 +01:00
committed by Alexei Starovoitov
parent d66e49ffa0
commit bea4f03897

View 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)