From nobody Thu Dec 18 03:26:38 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B584632ED52; Fri, 31 Oct 2025 08:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761897905; cv=none; b=Px/3zdb7QTN7fyjJcyga4XAuajlZaBn+51mXrTiF0EnOmV5q5aOpPit9ToxtIWdRd/EcBeISe7pZKTlcQTxlVu81EB+8J4JLrEzOWXEQi/dob1r0SpOEZdd5fHAhVoZy7RSsYMUxSdZdwNeqYqUY8DjpCDBZoB9Ovqvjwoaf8Vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761897905; c=relaxed/simple; bh=ZwKe430WcXOk/3GiwCgeIjtMWKpX3sKwXSY1J1f6ucU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CcZp8HMgb5y0Myo0RkAnFLSD13oZxhwOHgv08rKNkJI968x4baJjLwuX03RNJIodnMa3ddisZRuCwV4Sj9KFbIH9NgmvRu6/FE/cyJPvnyewJESGWyp5jLXKxZTWQPpT97+VsI7Wctp8VQ7S/ysAN0wk2tywUTmCym5dPzIWY5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=05MoPBNq; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="05MoPBNq" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C09BEC0E94D; Fri, 31 Oct 2025 08:04:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4772A60704; Fri, 31 Oct 2025 08:05:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9F7071180FB57; Fri, 31 Oct 2025 09:04:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1761897900; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=wjSUqrmy8yTxpGwe8E8DxpLkivQqp7irxh7QJFAmi08=; b=05MoPBNqggJhq9WNBXxCmidbJty7YJgMATkc7cynd5VDws/xY3P4EqQiTGLeUIRFmt41Yt y6b+E5FJX0HeIU6jLFCzoQh3yf4nO/m3Th123Rp8YiDl/xUDgr60kU6a1Wv6gcn/HmlZ4Z Jm64GfNd7lHnhYIgeZndYPMKeXZML2GrSFND6faKecAx5TAm79T+YluOvGSWRVwMup04Y8 Xzu7Td62jDCVm2Ihq2gCkfunlRqoobezlv5aQZ+dfVCPn3uMQHx0VZDEHa6FTDQu4vlA+E wOsyHER96rnck4UP4A3ar5lGKTzEcAhhMBvxW2+MNSu/FdIGf+FMUTc5SmL7SQ== From: "Bastien Curutchet (eBPF Foundation)" Date: Fri, 31 Oct 2025 09:04:41 +0100 Subject: [PATCH bpf-next v7 05/15] selftests/bpf: test_xsk: fix memory leak in testapp_xdp_shared_umem() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-xsk-v7-5-39fe486593a3@bootlin.com> References: <20251031-xsk-v7-0-39fe486593a3@bootlin.com> In-Reply-To: <20251031-xsk-v7-0-39fe486593a3@bootlin.com> To: =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer Cc: Thomas Petazzoni , Alexis Lothore , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Bastien Curutchet (eBPF Foundation)" X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 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 Signed-off-by: Bastien Curutchet (eBPF Foundation) --- tools/testing/selftests/bpf/test_xsk.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_xsk.c b/tools/testing/selftes= ts/bpf/test_xsk.c index eb18288ea1e4aa1c9337d16333b7174ecaed0999..d7cb2821469c62abd0d532821e8= 36336a2177eb5 100644 --- a/tools/testing/selftests/bpf/test_xsk.c +++ b/tools/testing/selftests/bpf/test_xsk.c @@ -570,6 +570,22 @@ static void pkt_stream_even_odd_sequence(struct test_s= pec *test) } } =20 +static void release_even_odd_sequence(struct test_spec *test) +{ + struct pkt_stream *later_free_tx =3D test->ifobj_tx->xsk->pkt_stream; + struct pkt_stream *later_free_rx =3D test->ifobj_rx->xsk->pkt_stream; + int i; + + for (i =3D 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 !=3D later_free_tx) + pkt_stream_delete(test->ifobj_tx->xsk_arr[i].pkt_stream); + if (test->ifobj_rx->xsk_arr[i].pkt_stream !=3D 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 =3D test->ifobj_rx->xdp_progs; struct xsk_xdp_progs *skel_tx =3D test->ifobj_tx->xdp_progs; + int ret; =20 test->total_steps =3D 1; test->nb_sockets =3D 2; @@ -2053,7 +2070,11 @@ int testapp_xdp_shared_umem(struct test_spec *test) =20 pkt_stream_even_odd_sequence(test); =20 - return testapp_validate_traffic(test); + ret =3D testapp_validate_traffic(test); + + release_even_odd_sequence(test); + + return ret; } =20 int testapp_poll_txq_tmout(struct test_spec *test) --=20 2.51.0