From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342736; b=QO2zXs9Ds/eWlU8Y5LXD7GAFQpB5bmyWRGZ39OsRZxVD++Pj0Z6KCwOQA6IBQmLp9zmh Na8Y/uPUs9uHaRI0ecrUKBSJz6Bz7mQ0fkkQeRQdDxMmQg8Isybi1RZCYkrtfe03JFAJ6 j7C5/EKvhCvXdgL1xXai9l/PSJoEpcmwUqZDAk9x6dHUihHhUzQ+Q0VHsjpYQolsZHvr2 skdf6m6w5aB+8j17mYzG5jXIeWsKsUIif/hqik99FlHVJ3l7Ua1MWLsT6Fsi8ahI3FZQn NMxfI3/UJlbAkkW6hw8NsNZ+34c+/y4Z8k6/AxoL9Qr+D+z/PhGkITjjX0qONeWbJ2g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342736; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=w9ltoRpaUC8iOqYEdJwbMw+1z6WKOnvzs8rJzh2rlFSA4xnbxKiwoP0XWTEACdK7BmPo jOfKZF8JpaoPmkzqxmxqBH5eKpfYl3OinsP47EJspSAMY/hG5CI7JSXGuCglvREMzd8hz Goef8fnfmKPjoUbQJXQW4HEODpY/ng+lVMo0N/Pv8zrPAzhRw8Ghl7S7wmMud2ZFz0tYi 0jJ6W0ZPrPBZIBvfjOgWE2T1A/c3kwq7U9gDLo9KWIfwE+hUUzV72DfHUqq6TqroCmgVR XXx1Ob24OLAJwysH177X1xSFxF08NGXZ5b7WS6fQt9b01vX0fVUgfYQeg8FqNMqmnRg== 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.45 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 1E239606A33A for ; Fri, 4 Dec 2026 00:05:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1E239606A33A 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-f45.google.com with SMTP id 5b1f17b1804b1-49d05d51553so2185465e9.2 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=hQ/LMANZtnnX21Hue1xkVIOyU1vOTDd7nvGsi1KcBnw5lTJiQ9qBsagtoNr4cnwgQV cDL4X3Fw4lYwqxmtPpAl7arUFZLrd22xBhRg9MgUl3N2sF6jdACtozkRU7hANvLlBIxd bMmRlAtCw8xg6NDXlB6wNxQj/9biHRCd9Atn9wUxbtTCr2d8n/fdHUh9RE97PzBMYU5K 7WZVm52aKhoK0sJbBktRtJZio8t8mfdfMRq8SpZViHLhINBU0fDiqHy70p4owzNRTrmQ PMp3QF+9ZS6dlVqgzgFbgVL4N/XjN9yXgFsftoASvz0AhE/VBewVvoJBbE/LB3hkVWzg jINg== X-Forwarded-Encrypted: i=1; AL+hErHoxhdfrN5/fNp6Xda4RwNGttwSHuIzUjFbee7k0dwQ8hkQl6hvKXbH465UZ9Cw3Q0Pj5DQnvDmywcA9eIKhm0=@vger.kernel.org X-Gm-Message-State: APuU4Z+gyc66q8mW/kmoK6TbMEW79BMC4M10K+nyFLGNVaGQTLHHf0fg uXfaqR8VUtNDW2Q7lj2zU/L+XzoyJmTYq9+va8vToAgKw8Y0bL2TjcFI X-Gm-Gg: AZFdTZcTouOGUeR3vBbduMKHr8jDtIPMt1TOrlGwNTTI6JS+DNKfHw8xpKBgO+pgyoH aZXp0Hx4WN4S/1RCW4YNlXdMXIMShKn+CH8wJv3hinD5H9oXPcGyKC2xbtqEHuIwzKegbtYWrk0 VtRGMi0x1XmrUTGqiMW09yKDtLN8pEyoMq18HQoTzlg9qPPVHdTVv11FcCKN4D00+SCJdKSh1UU 4od+JTZepwH93FXeH2gVpetBihUABiqKRwm3M6ckHcWXZcoh/IqCcnQyccDIE5ARuI4TDU8Ljku 7DAy9vrfD2IjzEB6bFvU9sH6Hy4yUkKqJPsCWy8uuhIqgUUemd431ZJjnCOw9EDRtRQVA4MCLq0 KDXoNJ46LyjhTcqHNfobrgwW1mFjhCY2p2PGcnxWdy0YEhkQOjw9MOYA5qoZWvqDl58G95xZBqf xNvlhF5rpw+qTXdGOa3p3aABzopBxRzjmh6yex6/q1TeQJVvKgBjdHBP3E2Gq5znN9jfJQJv/3c PVtnFgUMMhWSkKlUt5M0emBUmWhpU3Jr+HJOLmf6qEd0nQwChblxYmdC4xdEOR7GB6YKJLJKB7L MTWMKmKxBZJvfBSNDMysMSjq2sc= 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: linux-kselftest@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