From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342737; b=CjOKulRxfaSEiLovQsDB/YrEQ8REtb9pYX+dCblYYQq6rny0fuB5CN0r0WdoX3GHegNh W0XbCDckGp3CnjDoEc7/Fd4DDFiHmha+oyhJneqBkPa8w4U6AW32azKCoVb3osYRIm3bW EadSLdhCDGE3AtrJeUeT4Rm/+wWJv8rWV51zCsfrkHLOAR8tUhFlE0kvoNw4ff9/IlBEw MHyGEJUA6vaq98wOX5L6UAARUGezgFx0rIt8czdm+IwYSFKA3Rz2png2BJLv5cbifqykL GT3Q9CuqQDTkceJXETpzMHn7CZyErSSPRPdlUFL4puHWQQE//x6ZV8ER7C7y4wWtb7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342737; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=ejZ5xL5oXCnzzAXFLsHIBey5mgaQqUX61ewJyJiqE6Q=; b=XLKZ9j276Kz6vOOnN4Qy4nNhv52rlwnpm1Lg/jtSOIt7cy0VT0rJvVHIQuY1RQZ4rEDc 4itoXg0AGisaXhutm5iX9hfQ7YHY8aBJsd5Oq4ukfuWUkNtypV3MXfkqhgkumzINs7auM xPsAAExVrQqyLZvplQ3+SMQON61bq0he+F00JN29w2f5Fx5tU/d0FaQx12OyUOke1hA4w jte5X3m+5UWRq6/PQHJTkfAvLEthd/hDw+3n+nLz4HYD/jG/GpD4uKzFId1eW7PEriQSl Pkxck56g16HtMXkJgVxPCuj0sQLRC36HZPnXGfCCf4NqwpVwIiLEWw5tA0mtHEnXhQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AZGRDMyY; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DE97606A681 for ; Fri, 4 Dec 2026 00:05:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3DE97606A681 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AZGRDMyY Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso2409565e9.1 for ; Thu, 03 Dec 2026 16:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342735; x=1796947535; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ejZ5xL5oXCnzzAXFLsHIBey5mgaQqUX61ewJyJiqE6Q=; b=AZGRDMyYkqtlayNS2B6Da7pFcHN0ft57Gfq2TFR0raUByYW8+VR0Bc5IGZ4a1wXUjs CY3n7LdnG7jYSgPt5jDHA6wmoeZL0WRqA7V/tgmez8CBktdGKo39tc61R6Sr4D/+6Bk7 y2c3bUJM0PId3dvcFUOTsz97NoGcc9aA00HQqmiuJ8K1423/Bf9/FuUTdwV2qRaHkZzZ jwQMmp7SEc7jtQxFRTz8M/plLO8X1lbESsVdwzL9r+XqIGrYDtCjGA5sZall4Slx2rqJ 6kDj+QW3ELjbZ71KUJLbvNi/IrffoxjrRZNYVBnFCoElnYAtsETHNrYLkXzTpnL9d5q+ dhgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342735; x=1796947535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ejZ5xL5oXCnzzAXFLsHIBey5mgaQqUX61ewJyJiqE6Q=; b=EsOwbK/zmvi2UhWyrrcp3YFp+T+TNl2aNEuUy5/HQixn3244zaWAq3be2Qd8fpHB4K JSOaDDjDO0fLzjRjJb7Tsr3i7u1dPKkongJLMdosTyD1biAbMzfxwthWKoOtGW1mNkZn QtdwglO5N056PbQE8U6ZNY3Akh1fu1j58I/T3W76Idv2owWy1endCvUQGHUfK6kGECsE 3qiEqf2HpVbnT3G5iI2TX0uUPOxPfXz8h1/YtFuUru+YlKbkBsB557GDcZNh3/GeapAh +41h+lV0dh3RMiZ2M00GbKpT6ByPmxSetO30PCNmoEmUrL7Ui5Hpym/uNzd8t7rN7gyC RcGw== X-Gm-Message-State: APuU4Z9O8NVtKxNWRTsj8cBvsf4SFHrIMIGcscSUCcv6DbvB75++EOTg TUe84B1sd+/tICYcvnvPRrqJInTX5GOA1OJ9cOnNLhNfjTNjISZZomOJogxJJ+HQ X-Gm-Gg: AZFdTZcNCEvcX3CTXfXrAEHac5scm/qzytHTL6FqPLjxhgSTZEU6yF9cY0xhzOd9hU4 ElSPo/HYtzFIsLqPI803PAUubtJe+iEMib1ZCAjOJUqu2fbGv4jctl0gKJFb0w8P8gepAR6E0x0 LpIZw2FPNsFmuz/x/0GmkU/qM3oP50HEfW5X4cCTv64e4B+mUbDLP/4QF4zw/YtyNRYO7W8izXq 5dQf2g/DHo+0WEpHPYS2Mgj9oXeeQc2hiSHjHxybtmctxkTusXkNoyF2JIohHIeIO2oyG6ZsvlN GKTOHpzUf3G2qQFTaD3GIfbbiioyxX7KDTKilpOZPmKqgbfN7HdqFHHnVnofpIDrTXP72WLDipP jUoAgH/NgoNpScg7rrihJTSFjMJUgbrI/nLw7r/mgI2HRgn1l2r7V92Kn8pHtBDuQvNnFb/xbXi +qCdiVWZE79EXdbYOX7iu4robg/xHpmKHkhGjxc7+QLIo1JRO+rUGHsWBk4JmT7G3Cuf6yGUtsA 5BsWT1drrMv9LzKMca68MMYmN8PskBpRuKPuAm2Vs6d2Zp4ZsxA+iOwGZSGvf8UAd0W/Db8j7FU Fg7hgHe39IeIxsXSWEZ7Fj1J6Jg= X-Received: by 2002:a05:600c:3e17:b0:4bb:6687:5394 with SMTP id 5b1f17b1804b1-4bbeb8bc0damr4668045e9.9.1796342734570; Thu, 03 Dec 2026 16:05:34 -0800 (PST) Received: from localhost ([2a03:2880:31ff:3a::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbdff53b41sm130135235e9.0.2026.12.03.16.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 16:05:33 -0800 (PST) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope Date: Thu, 3 Dec 2026 16:05:14 -0800 Message-ID: <20261204000521.3396802-5-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com> References: <20261204000521.3396802-1-mohsin.bashr@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Mohsin Bashir Police offload is only useful if matching traffic is held to the configured rate and other traffic is left alone. Add police_rate to verify that UDP sent at twice the police rate arrives at the police rate, and police_isolation to verify that traffic to another address of the device is not limited. The rate is measured on the receiver, scaled from the UDP payload to the IP packet size that act_police counts, and must be within 10%. link_baseline measures the unpoliced rate, and the policing tests skip if it does not reach the offered rate, so a slow link is not mistaken for a working policer. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../drivers/net/hw/tc_flower_police.py | 158 +++++++++++++++++- 1 file changed, 154 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py index b03a00ad0c0b..b42ed22419ad 100755 --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py @@ -3,14 +3,25 @@ """Test HW offload of tc-flower rules with a police action on ingress.""" import ipaddress +import json +import random import tempfile import time from lib.py import ksft_run, ksft_exit, ksft_pr -from lib.py import ksft_eq +from lib.py import ksft_eq, ksft_ge from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx -from lib.py import NetDrvEpEnv +from lib.py import Iperf3Runner, NetDrvEpEnv from lib.py import set_ethtool_feat -from lib.py import cmd, defer, ethtool, tc +from lib.py import cmd, defer, ethtool, ip, tc +from lib.py import rand_port + + +RATE_MBIT = 100 +TOLERANCE = 0.10 +OFFERED_MBIT = 2 * RATE_MBIT +MEASURE_SEC = 5 +UDP_PAYLOAD = 1200 +IP6_PKT_LEN = UDP_PAYLOAD + 8 + 40 def _setup_clsact(cfg): @@ -36,6 +47,27 @@ def _local_prefix(cfg): return net +def _dev_addrs(cfg): + addrs = ip(f"-6 addr show dev {cfg.ifname}", json=True)[0] + return {a["local"] for a in addrs.get("addr_info", [])} + + +def _add_secondary_addr(cfg, want=None): + net = _local_prefix(cfg) + + taken = _dev_addrs(cfg) + hosts = range(1, min(net.num_addresses, 1 << 16)) + for i in random.sample(hosts, len(hosts)): + addr = str(net[i]) + if addr not in taken and (want is None or want(addr)): + break + else: + raise KsftSkipEx("No free address in LOCAL_PREFIX_V6") + ip(f"-6 addr add {addr}/128 dev {cfg.ifname} nodad") + defer(ip, f"-6 addr del {addr}/128 dev {cfg.ifname}") + return addr + + def _police(rate_mbit): return (f"action police rate {rate_mbit}mbit burst 1m " "conform-exceed drop/ok") @@ -79,6 +111,81 @@ def _ctrl_rule(cfg, i=0): return f"protocol ipv6 flower dst_ip {net[i + 1]}" +def _payload_mbit(mbit): + # iperf3 rates only count the UDP payload + return round(mbit * UDP_PAYLOAD / IP6_PKT_LEN, 3) + + +def _iperf3(cfg, dst_addr, bw_mbit): + runner = Iperf3Runner(cfg, port=rand_port(), server_ip=dst_addr) + server = runner.start_server(json=True) + done = False + try: + runner.start_client(duration=MEASURE_SEC, omit=1, + udp_mbit=_payload_mbit(bw_mbit), + length=UDP_PAYLOAD) + done = True + except CmdExitFailure as ex: + out = f"{ex.cmd.stderr} {ex.cmd.stdout}" + raise KsftFailEx(f"iperf3 failed: {out}") from ex + finally: + server.process(terminate=not done, fail=False, timeout=5) + return _rx_mbit(server.stdout) + + +def _rx_ivals(out): + try: + res = json.loads(out) + if "error" in res: + raise KsftFailEx(f"iperf3 server: {res['error']}") + return [(i["sum"]["seconds"], + i["sum"]["bytes"] * IP6_PKT_LEN / UDP_PAYLOAD) + for i in res["intervals"] + if not i["sum"].get("omitted")] + except (ValueError, KeyError) as ex: + raise KsftFailEx(f"iperf3 server output: {out}") from ex + + +def _rx_mbit(out): + ivals = _rx_ivals(out) + secs = sum(secs for secs, _ in ivals) + rx_bytes = sum(rx_bytes for _, rx_bytes in ivals) + return rx_bytes * 8 / secs / 1e6 if secs else 0 + + +def _check_rate(got, expect, what): + low, high = expect * (1 - TOLERANCE), expect * (1 + TOLERANCE) + ksft_ge(high, got, f"{what} above the expected {expect:.0f} Mbit/s") + ksft_ge(got, low, f"{what} below the expected {expect:.0f} Mbit/s") + return low <= got <= high + + +def _check_unpoliced(got, rate_mbit, what): + ksft_ge(got, rate_mbit * (1 + TOLERANCE), f"{what} looks policed") + + +def _get_baseline(cfg): + if cfg.baseline is None: + cfg.require_ipver("6") + cfg.require_cmd("iperf3", local=True, remote=True) + cfg.baseline = _iperf3(cfg, cfg.addr_v["6"], OFFERED_MBIT) + ksft_pr(f"Unpoliced UDP rate {cfg.baseline:.0f} Mbit/s") + return cfg.baseline + + +def _check_baseline_rate(cfg): + want = OFFERED_MBIT * (1 - TOLERANCE) + baseline = _get_baseline(cfg) + if baseline < want: + raise KsftSkipEx(f"Baseline rate {baseline:.0f} Mbit/s too low, " + f"need {want:.0f} Mbit/s") + + +def _dst_ip_rule(cfg): + dst = _add_secondary_addr(cfg) + return f"protocol ipv6 flower dst_ip {dst}", dst + + def offload_flags(cfg): """ Check that a skip_sw police rule is offloaded and reported in_hw, and @@ -152,11 +259,54 @@ def police_no_leak(cfg): ksft_eq(refill, full, "Rules taken after the flush") +def link_baseline(cfg): + """ + Measure the unpoliced UDP rate, so that the policing tests can skip if + the link is too slow to tell policed traffic from unpoliced. + """ + if not _get_baseline(cfg): + raise KsftFailEx("No UDP traffic received") + + +def police_rate(cfg): + """ + Check that UDP sent at twice the police rate to the destination IP of + a rule is limited to that rate. + """ + _setup_clsact(cfg) + rule, dst = _dst_ip_rule(cfg) + + _check_baseline_rate(cfg) + _add_filter(cfg, rule, _police(RATE_MBIT), pref=10) + _check_in_hw(cfg, 10) + + got = _iperf3(cfg, dst, OFFERED_MBIT) + _check_rate(got, RATE_MBIT, "matching flow") + + +def police_isolation(cfg): + """ + Check that traffic to another address of the device is not policed. + """ + _setup_clsact(cfg) + rule, _ = _dst_ip_rule(cfg) + + _check_baseline_rate(cfg) + _add_filter(cfg, rule, _police(RATE_MBIT), pref=10) + + got = _iperf3(cfg, cfg.addr_v["6"], OFFERED_MBIT) + _check_unpoliced(got, RATE_MBIT, "other address") + + def main() -> None: """Ksft boilerplate main.""" with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + cfg.baseline = None ksft_run([offload_flags, - police_no_leak], + police_no_leak, + link_baseline, + police_rate, + police_isolation], args=(cfg,)) ksft_exit() -- 2.53.1-Meta