From nobody Fri Oct 3 07:40:40 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 C59BA2FD1A6; Thu, 4 Sep 2025 10:11:23 +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=1756980687; cv=none; b=ZzFPxTVhYBCLAbla184gATiroInDx4atrEdyGS7CGBY3cg+0oYy1fz5SNn/aKGnU3XAB/0v9Rw+VcMMg73Tx4d7bnm7odh/A2YxDRirM5ElVjI/m+oEcW3Bw1SqHRMREHZRDXc1tuQgP3177gNb5M7Tk+z97xlbr+Vx3FWancrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980687; c=relaxed/simple; bh=YVcckO5jBZAgbvX3OtUxOAoC1bvJIGVV+T1xUWM+My0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rFXVkCT8Y5G1O3VhoWYGz5BbqujOamlSqrGZEecnGIee1bN2pqRoeD0b4povV7b2Mzm36YbpORPOV4C+IpnGkyhdkmQUB2wTbDIP38Dznqg8yTBloHp2zh3MU4031ZIIlW9KhJS193tHvJW4juN44TB1jG0YhcKyM8eXUXxk+Jo= 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=duBZzL7b; 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="duBZzL7b" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 3B5CBC8EC7F; Thu, 4 Sep 2025 10:11:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 63EC6606BB; Thu, 4 Sep 2025 10:11:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4CB841C22DC75; Thu, 4 Sep 2025 12:11:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1756980681; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=Ulz9LCgOlPLFkcXBBcxm3XotfG+b0NSQamGGLR8FGsg=; b=duBZzL7bsDj/DxSdRfajyc+GQHTJm4gEWZum9+PMEpixHd3BxjggkdMu39FDL6Zlu4JeYG NQnT+XIWx0oS7neruqwrDd+JM1kPYyayLr9Yy3Gb+Idx7gq0Yuo6SBm+Tk/7JLn+itiUE2 kcyRSa9hXAp8CL3gFm8f+wop9PvuzaTbrRNFNM6f00e6fDSeSEQN8+QKaSkNcLW937YRnr efWF41uAvqpBPF/bxnVW3F2H0t9JaNDJN7jB4h1qDxIoIyJ45RmqAk+DMGRbWBXOpEHl8u PvY4dXrBhoYZyibZET9QC92TDbUxLiHQ+nLBIVVNnmYPmdQiqkfowRwUKU1oag== From: "Bastien Curutchet (eBPF Foundation)" Date: Thu, 04 Sep 2025 12:10:18 +0200 Subject: [PATCH bpf-next v3 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: <20250904-xsk-v3-3-ce382e331485@bootlin.com> References: <20250904-xsk-v3-0-ce382e331485@bootlin.com> In-Reply-To: <20250904-xsk-v3-0-ce382e331485@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 37752b2dad651b36d155051931d7b3b902fac403..e4059c7d0a289449a6b73669fa8= 7f7440b7f55c0 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; @@ -2043,6 +2068,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 +2079,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