From nobody Thu Oct 2 02:15:05 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 8097730DD34; Wed, 24 Sep 2025 14:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758725419; cv=none; b=bQh5xxml4va2BX73BvPKN7RjEb3GZWXlADi+pxn3WqpqK3cwJoc5rzrKcjWoEzCUL5z7QnJGvAgWpq5mWeEukeWoYHc5HoKSMYSKZrMBri3jDsTtzscF7b7V36BNcE/UlnLOBIhfQhQ1pPPWZFA4ad52NiQobpm+PdQsxeX920w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758725419; c=relaxed/simple; bh=p5/Ue/EDWrCLygK9OUD9Vn8dsndfDHqeLNBvRGglxCk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cwQEeTtAVD7vugf6PFlVyIW59isuSo/y5wM3ImJrnWmLsnuv2rjN5iVuTVmala6rtE2Oq2RRWehWzk5hzYKOnfx/gDNDn4MQ/zEN3pMpVFBmivhtxT1ScvKmpNROxbf4Sp1pV5M1aPTOOMuyFsjQjgdUZ8HaLTSEGdCA9dS9GGk= 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=XNg8TocZ; arc=none smtp.client-ip=185.246.85.4 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="XNg8TocZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id C4D004E40D58; Wed, 24 Sep 2025 14:50:13 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9A75860634; Wed, 24 Sep 2025 14:50:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EAE84102F18D8; Wed, 24 Sep 2025 16:50:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758725412; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=ez1VzhqefwOv/TLGGLfSuvB3WSc3tsfGzKqORDO0iCU=; b=XNg8TocZoYR9DFgkjwpAElOvJVPmjc7W/W1zUUMJ2EVgqJrDlSWIpXHoxPn+WBeGeCrAAW On8bhnSmDzwe28+vCD2iaaBDVV3y81EQ+W/awfc+Nl+Aav8hODfllJWgRIvv9dqJ+i4ecI i92iHcChbaqHyRSvaLl9/zw3M8ymJ08olWkJt9JNOuayiHdsVryDF1txplfVflzar/U/6r xbhKQ2SOX9AJnTScTaNp/yExhJ5ex6R2NiYTIvywrkSs5eggFMudnQ61fn3T0RgKwhwNUo 6agJRT9MY9sLVILNGGbxLUtF8tQHIGPvwK9KcZOY62yrSZ1YM7fihddAu2PViw== From: "Bastien Curutchet (eBPF Foundation)" Date: Wed, 24 Sep 2025 16:49:40 +0200 Subject: [PATCH bpf-next v4 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: <20250924-xsk-v4-5-20e57537b876@bootlin.com> References: <20250924-xsk-v4-0-20e57537b876@bootlin.com> In-Reply-To: <20250924-xsk-v4-0-20e57537b876@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() 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