From nobody Fri Oct 3 11:22:26 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 040A82D9EF2; Tue, 2 Sep 2025 12:53:54 +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=1756817637; cv=none; b=SChzzgujQ/A7T6N+VCY1vk5ud7LN+vCONj2+O1E6c6Ugt58OU9w5mv0LGqO93UQ7g4W2UdYgILi21e9dh5IHYTejpMqK6KeCjlWA5ORyONugXzzngXJxBKRdX84CZKGZXiLdPWFXYVMkYPlh5C0z2kMHw++1ogOztyIaPUW/88Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817637; c=relaxed/simple; bh=KaIc/sAMmf9m/4tDc/peu4Ei8Bg3+2S3pNE6u0QxbrA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eNk0h0Xvuxi64ZJzGKs5ZLulGQxQp7X2un6GBxzCuOJqGBtiptQoF3mCfcscBzsPDkkfR36q/JoCWk3pbONksm1k4CTv0Bi1hnPtqLBNBvpOww8aFF9NiYybYqmmmyLtl7/cUhe9sWdQ475lYle7DzT9zf4EDkWqxbdzYSPPKJM= 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=l5NGRSes; 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="l5NGRSes" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 975C6C8EC76; Tue, 2 Sep 2025 12:53:38 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8BC1960695; Tue, 2 Sep 2025 12:53:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5DF9F1C228A25; Tue, 2 Sep 2025 14:53:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1756817632; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=xKAAs49ysc1JGn9SitoGwGRTvlpfa+C0zKye7bwupeg=; b=l5NGRSesQX5ijEmi5acokqtJDuMy42vYjmBXFGJSNmyY9zY16CKU/7U4V0tiP2n3+2uYOY JI/nAIaCHM12FK3he217kLyg8qk9fRj3RxJYnWGBtHYceXuwQqfGmziFBSZhr1nIUDYYgI YNqFT0AUqAa233oblHA32o70L3mMpnPGNnC7GWj4fGpFq6KKFdu4Ks/kH+uRSDo/z+Zurf 1QQ9T50eg6oDRRGA/N8IbBr+DIuqAAgAA5xsoJvDubFUWvsCYJQPxzmq/IEoWzfnOuHICl DG9QyRAwNxDhTs/q/jM+WBUIgkYxEMETOPW+8Sb8bptXrzX3hyI5xLMg55if3Q== From: "Bastien Curutchet (eBPF Foundation)" Date: Tue, 02 Sep 2025 14:49:53 +0200 Subject: [PATCH bpf-next v2 03/14] selftests/bpf: test_xsk: Fix memory leaks 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: <20250902-xsk-v2-3-17c6345d5215@bootlin.com> References: <20250902-xsk-v2-0-17c6345d5215@bootlin.com> In-Reply-To: <20250902-xsk-v2-0-17c6345d5215@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 Some tests introduce memory leaks by not freeing all the pkt_stream objects they're creating. Fix these memory leaks. Signed-off-by: Bastien Curutchet (eBPF Foundation) --- tools/testing/selftests/bpf/test_xsk.c | 32 ++++++++++++++++++++++++++++++= +- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_xsk.c b/tools/testing/selftes= ts/bpf/test_xsk.c index ef65beec3b870ae4fdc7aae9e3c4537c8ebbfce3..dd4bd31a14be2361ed9c51e1001= 790ead6ee17fd 100644 --- a/tools/testing/selftests/bpf/test_xsk.c +++ b/tools/testing/selftests/bpf/test_xsk.c @@ -546,6 +546,13 @@ static void pkt_stream_receive_half(struct test_spec *= test) struct pkt_stream *pkt_stream =3D test->ifobj_tx->xsk->pkt_stream; u32 i; =20 + if (test->ifobj_rx->xsk->pkt_stream !=3D test->rx_pkt_stream_default) + /* Packet stream has already been replaced so we have to release this on= e. + * The newly created one will be freed by the restore_default() at the + * end of the test + */ + pkt_stream_delete(test->ifobj_rx->xsk->pkt_stream); + test->ifobj_rx->xsk->pkt_stream =3D pkt_stream_generate(pkt_stream->nb_pk= ts, pkt_stream->pkts[0].len); pkt_stream =3D test->ifobj_rx->xsk->pkt_stream; @@ -573,6 +580,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) @@ -1874,6 +1897,7 @@ int testapp_stats_tx_invalid_descs(struct test_spec *= test) int testapp_stats_rx_full(struct test_spec *test) { pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2,= MIN_PKT_SIZE); + pkt_stream_delete(test->ifobj_rx->xsk->pkt_stream); test->ifobj_rx->xsk->pkt_stream =3D pkt_stream_generate(DEFAULT_UMEM_BUFF= ERS, MIN_PKT_SIZE); =20 test->ifobj_rx->xsk->rxqsize =3D DEFAULT_UMEM_BUFFERS; @@ -1885,6 +1909,7 @@ int testapp_stats_rx_full(struct test_spec *test) int testapp_stats_fill_empty(struct test_spec *test) { pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2,= MIN_PKT_SIZE); + pkt_stream_delete(test->ifobj_rx->xsk->pkt_stream); test->ifobj_rx->xsk->pkt_stream =3D pkt_stream_generate(DEFAULT_UMEM_BUFF= ERS, MIN_PKT_SIZE); =20 test->ifobj_rx->use_fill_ring =3D false; @@ -2055,6 +2080,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; @@ -2065,7 +2091,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.50.1