From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342736; b=TUASWVhMgmzK/TizOHFnmXtL2lk1w/JDDCJgE/c8ZykID87OGjfoWblX146bUN3EKNaj VThmQ09BagITzqyCcLJYkAylXg9V7/5rcrDCJvt7RO7lpIFhDpwlmy1zdmj0dZ/jBJbQL VxnMz1ZryZaA+cBoxOGzMe4+HDt2s8h1YODdaL7RtJWrFXttYaaP+Hf8suyRFKBiex4HP 7DF1uB9O6Q+sPFUQ+YY7qBsP5Z5JqGDrw/gji9+q3eQok6Q9iuEATmuzX0nk4i1o0PkHe BY2wYVQFqgypcKNth/k465Nsq1Jt49enlFEurfPsP/Ul7kDSM32m1E7hGjmgLr6vsxw== 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=vPu/vBgULC1g6Bfw369PdSvPeHZE5rjutqrkLQ3dkJvsUp56JYrPn47PW3sKzVhCXbXS IiGXOnZdswGHXq8eY1QZ5dLbFCrNo7aOY+RS6ZOBku1KWLUHkjpqECg2pdnJm45YQHpVo aP6FMhgIxBDoLGm8ty5FXtjiNrnd/PixqbOwj/Q9eexKrGKrovQ7bONweJmE0vmg3t9Kb VBIe5/Xbaz8FkCWYPwxYmsGnua7j0lQYxlO6HyW3xOS382tSp/VeFT1g+ZGL0b1bvMEN5 oysAyvankjIcQmoBHtrd31y3MyFWeOhpU726Xsa+KrD5awJ4wLqOAkTchZLR5x2djzw== 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.221.50 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 3E734606A682 for ; Fri, 4 Dec 2026 00:05:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3E734606A682 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-wr1-f50.google.com with SMTP id ffacd0b85a97d-4a34ffd3e39so229728f8f.0 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=jAsnYCIL3BayleSCpHWC1zmBbihFPh9AuNFMvvYV2tqDsG1+jJ6LX5XEOODBK348Wg HxGflheDkOwHyMGB/IeYMS7vU94mQr/GQ6BneGsrwXbQJfjk2ZBXGDaun8JyAKDnw17l PibbAfd9zSF096MfQtLNpl8R4d8NRiifxWF8oqVr7nRvSogNUPjror8zbVCfju9efbFz Z48izb4MkfpUwCQGUqT4NZtzMtTEUbcoHj9OkvcJVUQJwcDK32e+bk6OzP+8CcR9plAz iQEm7atRXwCf8iq6lyehHqR1iTetA8UyV6V1ioYWhBIzfjDMWaYco8WUORFiZVwyeoBC QRpQ== X-Forwarded-Encrypted: i=1; AL+hErH2J3RUf8hR0n/GbHhDtebIzWF9d9AnizjVlrH4X6dZA12ce0Oa0BIcDR0flsq2r6SNpWj61+5/el5WaPA=@vger.kernel.org X-Gm-Message-State: APuU4Z++6/9J3R2ectMajc8tyFjo/nE+/ezBTfwIRr9NDfmhSwn9POlp WtuYlmNBDrhbJUcno8VZzg877nGTiujBRcTKdTgCLqFbmEv8KkeSJZ3EQ7aPhymm X-Gm-Gg: AZFdTZdOs6+VNJ/VGpw72lBnccJQLEJkcYaBK2Ke+D7YnYsXnpK5tZKJdwQnQCFUIh7 dzvpRODDDccX2XxX0cLUj+W5Z3S6+KUqwCx+7FC59XhzjJ7X0vVG0Fm047l48S8DRF8dm5sT4Mr yaPXBezvbBMtn5Cb8oZsZ6KnPsnWDcGJjNkk/4SGOE1c9qfmqLIYnx62n7opfdd1KcoDVjDe1DC fN7lJH2rR1IXxtNJVXBaFIcS7Ar3CqZVXzoqgNOAWN0TblOClClazT1Md/tXHScw6/vlrG2bk/e yZU8hYQ7NrWxdObac9dV+mDr//m3xFoiBHkOIaDun5PE4fCdd504/QYkJSCBFPy8TK35YTH8sZC PDU1vb9KazWYQknIpwDj8ut9XoQz2XLthpuJgjRpyhrdHftIaF2+v+8s2lYJEUSRydZGlP4nZbF XjSAM4Q06gUuIVJ9p8HC7FR5M5szZSHHCYp7fXjIiQppgbUOavU3jGtrVJ9iZImyYB78cb4HbU1 iDi7siBWMwQt9413eiFiYIezpevuGJ4Iz4gm95Qz4IMQcq2ACgRQoZoziSOZSpx5lfutJtKY4U8 K2zfHhijwHNEz6Sv14gWKdjDbKg= 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-kernel@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