From nobody Mon Dec 1 22:36:55 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 A08DD2DF714 for ; Fri, 28 Nov 2025 22:27:34 +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=1764368856; cv=none; b=SbtKsV7M6v3O5ZsCqGmDbwLM5lDFB+1k/u8mFnEZ0m1jb3LbGhar5KydnXDc+sePGLPi9J89WS65gxcvhCBf8SVWMVmddZqRdI0ZbDU/znAixLty7CxoNSPoxUGGuUevZuFGdDTcmrRAqkAKPNSiS5MAob6mquoabLfySFYomj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764368856; c=relaxed/simple; bh=UOA0t60khVSN/bMn4uhfnWLuRj8VxHon/feXSwRNaGM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=unvS8dPeWeM26JU6gGBHjqfasQBt2izRXSAFFKeWGKOPPrKQ79F9udfcg3oha+UxxWYsL6cLTu5+R4sVJdwkVmwDGL5jZC689wJWwxlkK0oKYNxhunZ8u1KvKcm6hpEgu21xUpjYxwLCSSUjumpdZyXA77GJzsis/l8oEXu48lU= 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=Az7JIzPG; 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="Az7JIzPG" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id D3B7FC15D77; Fri, 28 Nov 2025 22:27:09 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C571F60706; Fri, 28 Nov 2025 22:27:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BDF8410B02592; Fri, 28 Nov 2025 23:27:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764368851; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=TtWlNHZ6iWxqj8l3sDu9iENK/pI3nl8z2yfzqiYCxMw=; b=Az7JIzPGJANARDfSoooF2hXl/gpoWptxbqm6k1popnsHg9fVxK+caZSBDQFM2VEOcpN+q9 OVLVPbID78gqvKgUt6VWfnOyBlZGJWPbv6yOF2FsrELCxTSR533ZREg9xhOQy/jtb9MKDs ur7d/x7vkHxfQ8aX0PpVHOxmfUBbU5KoKvqwE2PEVnJcRseuI+IfPvwjtWZ//KuGSULuPX F/OigEhFUqvXlYahMv5aTdM4U2VCwRJyi4dl8sR8Q9L4A0jagrw99N0EkPe3frNfCbHf+S LNA7mrYxwosL7IgNLJs1v4+fo5xbTPYH89NswUi0t/pES1J5C/+ysfseFRRxKQ== From: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= Date: Fri, 28 Nov 2025 23:27:18 +0100 Subject: [PATCH bpf-next v2 1/4] selftests/bpf: rename test_tc_edt.bpf.c section to expose program type 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: <20251128-tc_edt-v2-1-26db48373e73@bootlin.com> References: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> In-Reply-To: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> To: 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 , Shuah Khan Cc: ebpf@linuxfoundation.org, Bastien Curutchet , Thomas Petazzoni , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 The test_tc_edt BPF program uses a custom section name, which works fine when manually loading it with tc, but prevents it from being loaded with libbpf. Update the program section name to "tc" to be able to manipulate it with a libbpf-based C test. Signed-off-by: Alexis Lothor=C3=A9 (eBPF Foundation) --- tools/testing/selftests/bpf/progs/test_tc_edt.c | 3 ++- tools/testing/selftests/bpf/test_tc_edt.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/test_tc_edt.c b/tools/testin= g/selftests/bpf/progs/test_tc_edt.c index 950a70b61e74..9b80109d5c3d 100644 --- a/tools/testing/selftests/bpf/progs/test_tc_edt.c +++ b/tools/testing/selftests/bpf/progs/test_tc_edt.c @@ -99,7 +99,8 @@ static inline int handle_ipv4(struct __sk_buff *skb) return TC_ACT_OK; } =20 -SEC("cls_test") int tc_prog(struct __sk_buff *skb) +SEC("tc") +int tc_prog(struct __sk_buff *skb) { if (skb->protocol =3D=3D bpf_htons(ETH_P_IP)) return handle_ipv4(skb); diff --git a/tools/testing/selftests/bpf/test_tc_edt.sh b/tools/testing/sel= ftests/bpf/test_tc_edt.sh index 76f0bd17061f..8db8e146a431 100755 --- a/tools/testing/selftests/bpf/test_tc_edt.sh +++ b/tools/testing/selftests/bpf/test_tc_edt.sh @@ -55,7 +55,7 @@ ip -netns ${NS_DST} route add ${IP_SRC}/32 dev veth_dst ip netns exec ${NS_SRC} tc qdisc add dev veth_src root fq ip netns exec ${NS_SRC} tc qdisc add dev veth_src clsact ip netns exec ${NS_SRC} tc filter add dev veth_src egress \ - bpf da obj ${BPF_FILE} sec cls_test + bpf da obj ${BPF_FILE} sec tc =20 =20 # start the listener --=20 2.51.2 From nobody Mon Dec 1 22:36:55 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 161312E8DFE; Fri, 28 Nov 2025 22:27:36 +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=1764368859; cv=none; b=oFhhH0BvThm1xLcv6ZkSJ16GFHdl9S8QwakanYDcIS4Y00iZHn5XBF/2NuRe/WRQowQRqOSla8AjEXh5uN4tQ2dUNUmQwMW02aTl1hymdUUixI34uBCY8HZgxzduREnH1LNUZ3VhSXSddTSvGgUy5rd+LuQsbcSuJLuaHrPqS+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764368859; c=relaxed/simple; bh=iNy3+2BC40xaanFZ33v7Qj0LzuYFlWWryMucOWesFao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JITRIgYv042b2xxv5y1RAQ0BxRn7SRUlAsdI2cvIwEHfCVga2DjMlWnTuUPf35c7UNNk7Ql9lBqw3xrDEf8NzTYmlzX7CQ/uAyVg3fM4/IULIupeRcU2XiGPdbeXwsJ9l8jhv5wm0tE/YHcJZh69d7RljYwnd0NfLL0c1G2vEvg= 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=dYN6m5Oh; 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="dYN6m5Oh" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 71F2F4E4195A; Fri, 28 Nov 2025 22:27:35 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 486A060706; Fri, 28 Nov 2025 22:27:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0F88910B02598; Fri, 28 Nov 2025 23:27:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764368854; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=vpPgdxy49eI4YREjOTkPjJ6SggMZfZ1B/R+/EdiVrT4=; b=dYN6m5Oh714oPBDopNueaOHZxK/tlsJCBfs/7f3f1lJ7MO3ChDIk+oduDEI+r39GwwWb6k P13yjyHcua6bV4py7OUS1ghfFiaaENXqCevJRwR3BBStcWC+gGRNcbyGNLVkMBeNOdzgOF TKHZbOaku/3VLyXHUKhCiRKSzxOvRPKHg1MOjuO1mgkl3YcMquSVvcU1jFpznru+MNI6Wb GzMzXplSp+aeYL28rL59VKb3jQXZwNwqFFidzh3msRJOrTPgjMfmwepdvlL3fKiig8p4cW KDNt/IJnnKd6lwVq0nz1RK7XdsdxzOkSQQlpK0l8pB4CGN6cVl6Um0LA57mV0A== From: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= Date: Fri, 28 Nov 2025 23:27:19 +0100 Subject: [PATCH bpf-next v2 2/4] selftests/bpf: integrate test_tc_edt into test_progs 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: <20251128-tc_edt-v2-2-26db48373e73@bootlin.com> References: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> In-Reply-To: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> To: 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 , Shuah Khan Cc: ebpf@linuxfoundation.org, Bastien Curutchet , Thomas Petazzoni , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 test_tc_edt.sh uses a pair of veth and a BPF program attached to the TX veth to shape the traffic to 5MBps. It then checks that the amount of received bytes (at interface level), compared to the TX duration, indeed matches 5Mbps. Convert this test script to the test_progs framework: - keep the double veth setup, isolated in two veths - run a small tcp server, and connect client to server - push a pre-configured amount of bytes, and measure how much time has been needed to push those - ensure that this rate is in a 2% error margin around the target rate This two percent value, while being tight, is hopefully large enough to not make the test too flaky in CI, while also turning it into a small example of BPF-based shaping. Signed-off-by: Alexis Lothor=C3=A9 (eBPF Foundation) --- Changes in v2: - drop custom server/client management and replace it with send_recv_data - drop bytes reading, as we now base the test duration on number of tx bytes - update bpf program check on source port rather than dest port, as this is now the server which sends bytes --- .../testing/selftests/bpf/prog_tests/test_tc_edt.c | 144 +++++++++++++++++= ++++ tools/testing/selftests/bpf/progs/test_tc_edt.c | 2 +- 2 files changed, 145 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_tc_edt.c b/tools/t= esting/selftests/bpf/prog_tests/test_tc_edt.c new file mode 100644 index 000000000000..9ba69398eec4 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/test_tc_edt.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +/* + * BPF-based flow shaping + * + * The test brings up two veth in two isolated namespaces, attach some flow + * shaping program onto it, and ensures that a manual speedtest maximum + * value matches the rate set in the BPF shapers. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "test_progs.h" +#include "network_helpers.h" +#include "test_tc_edt.skel.h" + +#define SERVER_NS "tc-edt-server-ns" +#define CLIENT_NS "tc-edt-client-ns" +#define IP4_ADDR_VETH1 "192.168.1.1" +#define IP4_ADDR_VETH2 "192.168.1.2" +#define IP4_ADDR_VETH2_HEX 0xC0A80102 + +#define TIMEOUT_MS 2000 +#define TEST_PORT 9000 +#define TARGET_RATE_MBPS 5.0 +#define TX_BYTES_COUNT (1 * 1000 * 1000) +#define RATE_ERROR_PERCENT 2.0 + +struct connection { + int server_listen_fd; + int server_conn_fd; + int client_conn_fd; +}; + +static int setup(struct test_tc_edt *skel) +{ + struct nstoken *nstoken_client, *nstoken_server; + int ret; + + if (!ASSERT_OK(make_netns(CLIENT_NS), "create client ns")) + goto fail; + if (!ASSERT_OK(make_netns(SERVER_NS), "create server ns")) + goto fail_delete_client_ns; + + nstoken_client =3D open_netns(CLIENT_NS); + if (!ASSERT_OK_PTR(nstoken_client, "open client ns")) + goto fail_delete_server_ns; + SYS(fail_close_client_ns, "ip link add veth1 type veth peer name %s", + "veth2 netns " SERVER_NS); + SYS(fail_close_client_ns, "ip -4 addr add " IP4_ADDR_VETH1 "/24 dev veth1= "); + SYS(fail_close_client_ns, "ip link set veth1 up"); + + nstoken_server =3D open_netns(SERVER_NS); + if (!ASSERT_OK_PTR(nstoken_server, "enter server ns")) + goto fail_close_client_ns; + SYS(fail_close_server_ns, "ip -4 addr add " IP4_ADDR_VETH2 "/24 dev veth2= "); + SYS(fail_close_server_ns, "ip link set veth2 up"); + SYS(fail_close_server_ns, "tc qdisc add dev veth2 root fq"); + ret =3D tc_prog_attach("veth2", -1, bpf_program__fd(skel->progs.tc_prog)); + if (!ASSERT_OK(ret, "attach bpf prog")) + goto fail_close_server_ns; + close_netns(nstoken_server); + close_netns(nstoken_client); + + return 0; + +fail_close_server_ns: + close_netns(nstoken_server); +fail_close_client_ns: + close_netns(nstoken_client); +fail_delete_server_ns: + remove_netns(SERVER_NS); +fail_delete_client_ns: + remove_netns(CLIENT_NS); +fail: + return -1; +} + +static void cleanup(void) +{ + remove_netns(CLIENT_NS); + remove_netns(SERVER_NS); +} + +static void run_test(void) +{ + int server_fd, client_fd, err; + double rate_mbps, rate_error; + struct nstoken *nstoken; + __u64 ts_start, ts_end; + + nstoken =3D open_netns(SERVER_NS); + if (!ASSERT_OK_PTR(nstoken, "open server ns")) + return; + server_fd =3D start_server(AF_INET, SOCK_STREAM, IP4_ADDR_VETH2, + TEST_PORT, TIMEOUT_MS); + if (!ASSERT_OK_FD(server_fd, "start server")) + return; + + close_netns(nstoken); + nstoken =3D open_netns(CLIENT_NS); + if (!ASSERT_OK_PTR(nstoken, "open client ns")) + return; + client_fd =3D connect_to_fd(server_fd, 0); + if (!ASSERT_OK_FD(client_fd, "connect client")) + return; + + ts_start =3D get_time_ns(); + err =3D send_recv_data(server_fd, client_fd, TX_BYTES_COUNT); + ts_end =3D get_time_ns(); + close_netns(nstoken); + ASSERT_OK(err, "send_recv_data"); + + rate_mbps =3D TX_BYTES_COUNT / ((ts_end - ts_start) / 1000.0); + rate_error =3D + fabs((rate_mbps - TARGET_RATE_MBPS) * 100.0 / TARGET_RATE_MBPS); + + ASSERT_LE(rate_error, RATE_ERROR_PERCENT, + "rate error is lower than threshold"); +} + +void test_tc_edt(void) +{ + struct test_tc_edt *skel; + + skel =3D test_tc_edt__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel open and load")) + return; + + if (!ASSERT_OK(setup(skel), "global setup")) + return; + + run_test(); + + cleanup(); + test_tc_edt__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/progs/test_tc_edt.c b/tools/testin= g/selftests/bpf/progs/test_tc_edt.c index 9b80109d5c3d..d31058cf4eca 100644 --- a/tools/testing/selftests/bpf/progs/test_tc_edt.c +++ b/tools/testing/selftests/bpf/progs/test_tc_edt.c @@ -70,7 +70,7 @@ static inline int handle_tcp(struct __sk_buff *skb, struc= t tcphdr *tcp) if ((void *)(tcp + 1) > data_end) return TC_ACT_SHOT; =20 - if (tcp->dest =3D=3D bpf_htons(9000)) + if (tcp->source =3D=3D bpf_htons(9000)) return throttle_flow(skb); =20 return TC_ACT_OK; --=20 2.51.2 From nobody Mon Dec 1 22:36:55 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 A66F92E8B8E; Fri, 28 Nov 2025 22:27:39 +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=1764368861; cv=none; b=c1g8UJnraYgO41yY4sKJl8QR3EHQUfCi3BIdQnpfamKBeMdLgVUSkrdbWgrxjCUC9AtocHhOQ/6sBMYQMkxtLI6TDeqpHyvWS5+zCfIxXnL81/ECzxFCTG1DpZ5qLoUT+PMxdjsDgU6k31WeLAr0QY/92na8i6CuOz+Vam3Pobs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764368861; c=relaxed/simple; bh=HwIa3DtEJdOE6ITDDz1l6OkqAvIrgUyTqZLZIg5ZNHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L3yz8ZWmUam0YnOSbZM4QSYWToVjxOGUxeZbSfm5ywoNno2ngZMPao9wb1VyO4FT5h5TO29go1ZbwN9T62hRl1gaJMDDm3EaDT4pMF7Bid3HG+Qac6kgLspYTtMuR7yB3Ds4OqQPNzGm8dOcw/WiSDdwGPmGiiRNlGFgcPm4jRc= 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=w08EIFeF; 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="w08EIFeF" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id F3A934E41958; Fri, 28 Nov 2025 22:27:37 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C36E160706; Fri, 28 Nov 2025 22:27:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8A2B210B02591; Fri, 28 Nov 2025 23:27:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764368856; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=smB+nuAdze4umSzpM0gSvxnCnoPRhGonuD+j2xiHPRs=; b=w08EIFeFdChsNkyBRWCkPVC0NfOyz5K71Qqosnuwb3bLQ+5XEvLgu84DhqkI/ITv4M3ab6 GARhdO6ZUvOadoRiAImAMPYLXXETTQjnhoEtkxxhnrAb2FnKXSr0StTUjSlXjRE71U6YAL n35OFbhqpax8yzofmGsIsb971tqaHWMxzPYE7XJ6LFWod2Ne1Qqjzk3di1Qa3eE+HXUGh/ 6AM6fVSiNVv1H6WWSqvK144FmMwy8+UmuOLGQ+159MaTRvqSXiE9X9JLHi0fhvIQ6saPd1 swRoZuOPCg/tUiTkVzYeoxLmRQ6jvwV1jOeF6MWy+a0Wt6dF+9kHjUoWkBxghg== From: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= Date: Fri, 28 Nov 2025 23:27:20 +0100 Subject: [PATCH bpf-next v2 3/4] selftests/bpf: remove test_tc_edt.sh 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: <20251128-tc_edt-v2-3-26db48373e73@bootlin.com> References: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> In-Reply-To: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> To: 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 , Shuah Khan Cc: ebpf@linuxfoundation.org, Bastien Curutchet , Thomas Petazzoni , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 Now that test_tc_edt has been integrated in test_progs, remove the legacy shell script. Signed-off-by: Alexis Lothor=C3=A9 (eBPF Foundation) --- tools/testing/selftests/bpf/Makefile | 2 - tools/testing/selftests/bpf/test_tc_edt.sh | 100 -------------------------= ---- 2 files changed, 102 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index bac22265e7ff..01ef8f4552b8 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -99,13 +99,11 @@ TEST_GEN_PROGS +=3D test_progs-cpuv4 TEST_INST_SUBDIRS +=3D cpuv4 endif =20 -TEST_GEN_FILES =3D test_tc_edt.bpf.o TEST_FILES =3D xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) =20 # Order correspond to 'make run_tests' order TEST_PROGS :=3D test_kmod.sh \ test_lirc_mode2.sh \ - test_tc_edt.sh \ test_xdping.sh \ test_bpftool_build.sh \ test_bpftool.sh \ diff --git a/tools/testing/selftests/bpf/test_tc_edt.sh b/tools/testing/sel= ftests/bpf/test_tc_edt.sh deleted file mode 100755 index 8db8e146a431..000000000000 --- a/tools/testing/selftests/bpf/test_tc_edt.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 -# -# This test installs a TC bpf program that throttles a TCP flow -# with dst port =3D 9000 down to 5MBps. Then it measures actual -# throughput of the flow. - -BPF_FILE=3D"test_tc_edt.bpf.o" -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root" - echo "FAIL" - exit 1 -fi - -# check that nc, dd, and timeout are present -command -v nc >/dev/null 2>&1 || \ - { echo >&2 "nc is not available"; exit 1; } -command -v dd >/dev/null 2>&1 || \ - { echo >&2 "nc is not available"; exit 1; } -command -v timeout >/dev/null 2>&1 || \ - { echo >&2 "timeout is not available"; exit 1; } - -readonly NS_SRC=3D"ns-src-$(mktemp -u XXXXXX)" -readonly NS_DST=3D"ns-dst-$(mktemp -u XXXXXX)" - -readonly IP_SRC=3D"172.16.1.100" -readonly IP_DST=3D"172.16.2.100" - -cleanup() -{ - ip netns del ${NS_SRC} - ip netns del ${NS_DST} -} - -trap cleanup EXIT - -set -e # exit on error - -ip netns add "${NS_SRC}" -ip netns add "${NS_DST}" -ip link add veth_src type veth peer name veth_dst -ip link set veth_src netns ${NS_SRC} -ip link set veth_dst netns ${NS_DST} - -ip -netns ${NS_SRC} addr add ${IP_SRC}/24 dev veth_src -ip -netns ${NS_DST} addr add ${IP_DST}/24 dev veth_dst - -ip -netns ${NS_SRC} link set dev veth_src up -ip -netns ${NS_DST} link set dev veth_dst up - -ip -netns ${NS_SRC} route add ${IP_DST}/32 dev veth_src -ip -netns ${NS_DST} route add ${IP_SRC}/32 dev veth_dst - -# set up TC on TX -ip netns exec ${NS_SRC} tc qdisc add dev veth_src root fq -ip netns exec ${NS_SRC} tc qdisc add dev veth_src clsact -ip netns exec ${NS_SRC} tc filter add dev veth_src egress \ - bpf da obj ${BPF_FILE} sec tc - - -# start the listener -ip netns exec ${NS_DST} bash -c \ - "nc -4 -l -p 9000 >/dev/null &" -declare -i NC_PID=3D$! -sleep 1 - -declare -ir TIMEOUT=3D20 -declare -ir EXPECTED_BPS=3D5000000 - -# run the load, capture RX bytes on DST -declare -ir RX_BYTES_START=3D$( ip netns exec ${NS_DST} \ - cat /sys/class/net/veth_dst/statistics/rx_bytes ) - -set +e -ip netns exec ${NS_SRC} bash -c "timeout ${TIMEOUT} dd if=3D/dev/zero \ - bs=3D1000 count=3D1000000 > /dev/tcp/${IP_DST}/9000 2>/dev/null" -set -e - -declare -ir RX_BYTES_END=3D$( ip netns exec ${NS_DST} \ - cat /sys/class/net/veth_dst/statistics/rx_bytes ) - -declare -ir ACTUAL_BPS=3D$(( ($RX_BYTES_END - $RX_BYTES_START) / $TIMEOUT = )) - -echo $TIMEOUT $ACTUAL_BPS $EXPECTED_BPS | \ - awk '{printf "elapsed: %d sec; bps difference: %.2f%%\n", - $1, ($2-$3)*100.0/$3}' - -# Pass the test if the actual bps is within 1% of the expected bps. -# The difference is usually about 0.1% on a 20-sec test, and =3D=3D> zero -# the longer the test runs. -declare -ir RES=3D$( echo $ACTUAL_BPS $EXPECTED_BPS | \ - awk 'function abs(x){return ((x < 0.0) ? -x : x)} - {if (abs(($1-$2)*100.0/$2) > 1.0) { print "1" } - else { print "0"} }' ) -if [ "${RES}" =3D=3D "0" ] ; then - echo "PASS" -else - echo "FAIL" - exit 1 -fi --=20 2.51.2 From nobody Mon Dec 1 22:36:55 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 1A9AB2F12D3; Fri, 28 Nov 2025 22:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764368862; cv=none; b=g4yXJe/8a2XHCDBfrfasv4ms+oYEUSaEJz6BeYZTuz4Qhm68zeucOH5tgWEhVoTCKjojMomGs8C9I31q0/fhzFB8JWrgxAqZrGDqdDpVt2XsjDyBefnLU3JuW6+Kc+bETNDWbN8M0M2nADC3cqIKsijzk+vfed7+mLpx9CPKw+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764368862; c=relaxed/simple; bh=kmh6ENzofXIt4PAXZH0Z7jfrbDrhfbIKRSttu04afiU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=igDRf3tFW+432sw+f5IvhIUPHlQmOKPcFeZsniQ+ZT3FDaKLiFm5NVzk1dSeWDaT+8upsEz4BOCZWLrDg8wQYl7dPjWfSo4Latyexxwm7usNKwplnh6YWj1noR3tS7852bu8RBvnQoGAD0evwyc6Xwa06iQ8Uxh4/gUqkmOwTA8= 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=0UuSSr2/; arc=none smtp.client-ip=185.246.84.56 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="0UuSSr2/" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id DB72F1A1E11; Fri, 28 Nov 2025 22:27:39 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AFE8E60706; Fri, 28 Nov 2025 22:27:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 064D810B02592; Fri, 28 Nov 2025 23:27:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764368858; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=NbJJlFsehdI9InaPGxFPtlAMd7ghBkNRbJp1O6wK1xY=; b=0UuSSr2/hkGVdCZldRlsE+zz8BwXcaukxPw1hFaOfFV5kGckmpBvvzS5m/o9T4do33b/UZ eWCtdktbpcJojSoLLtPwyz4bOPsyIi52X1Zyss6/OThTBX/mhWW/hIl6t+pRU2gO4cUfCT qUmapUjwNx9Y1RKIrSmSxFUEBtXp2MwnsqKMPSegPpkbIdYtRmArXCUWHN/lDMi8J3OsZe ZdETLYrSvAhr5oGHWf9Z5cnRTU+7OCM+E6IEJgM0Cl7F64MyMGu22u7DNqBfRMIp4BDV8J JVHXnSH1XQY6tIqQKDdg4tO/wPFjXIoGUWPuRWv5KSQyZEbt4YPpx/tY+d1O5g== From: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= Date: Fri, 28 Nov 2025 23:27:21 +0100 Subject: [PATCH bpf-next v2 4/4] selftests/bpf: do not hardcode target rate in test_tc_edt BPF program 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: <20251128-tc_edt-v2-4-26db48373e73@bootlin.com> References: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> In-Reply-To: <20251128-tc_edt-v2-0-26db48373e73@bootlin.com> To: 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 , Shuah Khan Cc: ebpf@linuxfoundation.org, Bastien Curutchet , Thomas Petazzoni , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 test_tc_edt currently defines the target rate in both the userspace and BPF parts. This value could be defined once in the userspace part if we make it able to configure the BPF program before starting the test. Add a target_rate variable in the BPF part, and make the userspace part set it to the desired rate before attaching the shaping program. Signed-off-by: Alexis Lothor=C3=A9 (eBPF Foundation) --- tools/testing/selftests/bpf/prog_tests/test_tc_edt.c | 1 + tools/testing/selftests/bpf/progs/test_tc_edt.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_tc_edt.c b/tools/t= esting/selftests/bpf/prog_tests/test_tc_edt.c index 9ba69398eec4..462512fb191f 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_tc_edt.c +++ b/tools/testing/selftests/bpf/prog_tests/test_tc_edt.c @@ -66,6 +66,7 @@ static int setup(struct test_tc_edt *skel) ret =3D tc_prog_attach("veth2", -1, bpf_program__fd(skel->progs.tc_prog)); if (!ASSERT_OK(ret, "attach bpf prog")) goto fail_close_server_ns; + skel->bss->target_rate =3D TARGET_RATE_MBPS * 1000 * 1000; close_netns(nstoken_server); close_netns(nstoken_client); =20 diff --git a/tools/testing/selftests/bpf/progs/test_tc_edt.c b/tools/testin= g/selftests/bpf/progs/test_tc_edt.c index d31058cf4eca..4f6f03122d61 100644 --- a/tools/testing/selftests/bpf/progs/test_tc_edt.c +++ b/tools/testing/selftests/bpf/progs/test_tc_edt.c @@ -14,7 +14,6 @@ #define TIME_HORIZON_NS (2000 * 1000 * 1000) #define NS_PER_SEC 1000000000 #define ECN_HORIZON_NS 5000000 -#define THROTTLE_RATE_BPS (5 * 1000 * 1000) =20 /* flow_key =3D> last_tstamp timestamp used */ struct { @@ -24,12 +23,13 @@ struct { __uint(max_entries, 1); } flow_map SEC(".maps"); =20 +__uint64_t target_rate; + static inline int throttle_flow(struct __sk_buff *skb) { int key =3D 0; uint64_t *last_tstamp =3D bpf_map_lookup_elem(&flow_map, &key); - uint64_t delay_ns =3D ((uint64_t)skb->len) * NS_PER_SEC / - THROTTLE_RATE_BPS; + uint64_t delay_ns =3D ((uint64_t)skb->len) * NS_PER_SEC / target_rate; uint64_t now =3D bpf_ktime_get_ns(); uint64_t tstamp, next_tstamp =3D 0; =20 --=20 2.51.2