From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342744; b=id1qY+2eOVzFZ0Td8ieBpw7SUSoabIfeCU9Fq9BsGjTw+a6dy82S7SjpK6MGJ8LnrX4n 7pLTkioQEHQxF6X/u2I9LGXoHdlPJjfWqPoqGwV1z4pkx8kkXTX9gTDQWMPEKp8RgLkFN TrA+0pPlcjHiDRVFaWWkZ1R++p6ccr0VNUxq/QALKCylVmr1WjJ840IK9NtTffqEE1jRA cEZK5iOTsk5YatzL/gQTbA/qV+neJT3ySNAEBU1asNDhgEN33F9SyGXZW5/a2ncsmaLLV 8BdJj+l8i53A5R2DbpHOY5KsAyvY+v0o4TpoQj0wcuZNgSUZwNTlQyRTQfVYf/Byvug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342744; 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=EPPXLFO+yqw0jILTlXZDRtxUahG5zq0+Dg+2/1ZfRfs=; b=tlWIlvP1joFX7NHN92omYiVBS9Dww4bO1Mtp2QUyri37Ad+aTJxTIKS4Y5I0AbjCaiyj gGhcNkKVUp7c2iCZ88/E8g798e9Nl7ajbrA7breK5D+Z1RVglM78AW/jz2tVlGbyAyNIa 2x8pSnu+PvgcPHaCH5iwGIT0nsfii98Lz+477Br6eiHKYh9SnK/US04llGdcmQ4cltofJ toIfLMpefFO1N6vxppwDuFWiRj1xoUV4OKpv8dSvrWj3KL7lcKwHYU9p2A3unnIpjzINv e8ssMsorYQGpM/UFIQrMr263ZZkWiwb5jfCV1essfi6iIRxXbaAA7lWzLeBqUBYJCGw== 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=QO85cieT; arc=none smtp.remote-ip=209.85.128.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 E5596606A680 for ; Fri, 4 Dec 2026 00:05:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E5596606A680 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=QO85cieT Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4a9a8d6cea8so3502855e9.1 for ; Thu, 03 Dec 2026 16:05:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342742; x=1796947542; 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=EPPXLFO+yqw0jILTlXZDRtxUahG5zq0+Dg+2/1ZfRfs=; b=QO85cieTfv3tv7xwrev/2sNtgC2sCuhIE/Slqzqfw5Ba1nHjwYhWWVEyUbfaQZKCxt 1F7Mz7xpT9lIX8MvpQ3h/M9PMwvXCLMTZmDpWqr/eKeUctPEonpLn6EIOuaxFKiObuXo vVNNT/Nmxa5kXe5xaXzotb01Sg0P7+EzKElE+GE99J4vbYChNVpam8d+58RKLNJRY4Ig d9gT9X+eF+3DRDhAijXAiT9603LOaUIEVk4AV5iLO0NTrzc+egX6w1Ez2n3YuzmrdvAo nFezCv72AquoJgBQ3PfPeJ6681t2hrsu5FsMXFZ0swAcO1O0sTNN40i74ekk43LWx/Vw ioEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342742; x=1796947542; 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=EPPXLFO+yqw0jILTlXZDRtxUahG5zq0+Dg+2/1ZfRfs=; b=Rn7wiP7ZygqySbtz9uBVOiU18UKiIXWa7r+VtrAyfanPsfIfYauPFv+T2JbkkZOmdk y0FhSDI4Ahl3s3M0//d19KOwQsknEhcu9xOb2M5Bs/glaexStJKOGhunZ8hfSYWpPTMh iM5/R7/tP7D3shMyz9zMiPpt8dRA9BniW3YqjcOQszhka2D7kJnEg3Y2nlygUJ4lpBPq tcFlM156AtnEiURhy3Ab/Njwx330V1bRZNyG1jIj1ftvJZ6ASp03Mkx+e/9GtdM6hJ25 epknuixGHQLtFC2lrOu30Kj1unkjqa1P8w478f6+MJz+nKJXp0Se2W4Ge+9lRQCXYuA+ AcOg== X-Forwarded-Encrypted: i=1; AL+hErFj0nCUoHWOiJtBQtfMcconcgbVFiqh6Zynsy+nVtU0ph7KlF+O1yeVnkEMM5h6BwSG8uw6siOu77/Vf8U=@vger.kernel.org X-Gm-Message-State: APuU4Z8u18kA+rf/gQVSM9snyMvOKDIoiTQeJnM6ORkFVDPMWMB6oQVT VpDzcLUxjqjIfyz9UBCVssd+mKb8y9qYgZDkRbGkL9op9nA4pq9YaXa2 X-Gm-Gg: AZFdTZdUoIcgzLuV6sVbF4MEINMeujm3rPDsQZk/Z4LFeyacBi0cc9uOt1cpqbYjnmk 7uE0DIVz0Obo2TFkSfgMrQ1pg9xrEJR0ZypZQiBtYktPJAm0fqJO5F+rvummw2kDxpwLp5hhgJR u9OeJPldYeX2gWvxpI/OjXD129DUnmeAbWQipZS07nYZKUSLj/plWdLzv1oZHANpJONooaGaZD3 4V4coOQYUa3ZmnvDfmLI1+87xOsExFurHF/HHMRxklEf0RUuHjMYs1chi8KKioGHaeqbrmJd9Xm B+PFYAwW/zjI2pS2VA5gR5MNs5XB2e9wNjiTrxZrwNfMYhWet6lCXSbJuBanwFgwKpbwOOUdKpl tHEd+Ehpp/Ev1Ow+wKG8WlngD0SdckhKFZrxLQ082BGalwMZ+xETsej4A9rzn1ZmptqRf0WrV6G VUMgEwIdgKZermpb8i+Hu8RqJQApo0QJFIKrUOkkzJ1bTKqYtTxUVwrJcXBHsnxRKPPr6Tv/rfk 31XkTcKHxmiI/mtkQ60rFw/BBD4AzjVLwE3W+3fghr/TMy58OWtj9Tn3XFDt4Rpdiw+jfa266AA 3i8YiYRNaKjcCssI0MrKbBHv0M7GUJSG7+t6eKRDVu5AHQObTg== X-Received: by 2002:a05:600c:c4a8:b0:4a1:c27d:e1a8 with SMTP id 5b1f17b1804b1-4bbeb897287mr4950365e9.10.1796342742241; Thu, 03 Dec 2026 16:05:42 -0800 (PST) Received: from localhost ([2a03:2880:31ff:44::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d174c08b17sm1872911f8f.54.2026.12.03.16.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 16:05:40 -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 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Date: Thu, 3 Dec 2026 16:05:17 -0800 Message-ID: <20261204000521.3396802-8-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 With more than one rule installed, the device has to keep the policers apart, share them when asked to, and apply them in priority order. Add police_independent, police_shared_action and police_priority to verify each of these. The two flows run at the same time, so that each policer is busy while the other one is. The second flow starts slightly later, so with a shared action the sum reads a few percent high, within the 10% tolerance. A device that rejects shared or overlapping rules is skipped. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../drivers/net/hw/tc_flower_police.py | 110 +++++++++++++++++- 1 file changed, 108 insertions(+), 2 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 66d32f6e13f7..bca1e324e69a 100755 --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py @@ -5,6 +5,7 @@ import ipaddress import json import random +import subprocess import tempfile import time from lib.py import ksft_run, ksft_exit, ksft_pr @@ -14,7 +15,7 @@ from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx from lib.py import Iperf3Runner, NetDrvEpEnv from lib.py import set_ethtool_feat from lib.py import cmd, defer, ethtool, ip, tc -from lib.py import rand_port +from lib.py import rand_port, rand_ports RATE_MBIT = 100 @@ -377,6 +378,108 @@ def police_params(cfg, action, expect): raise KsftSkipEx(f"Not offloaded: {reason}") +def _iperf3_flows(cfg, dsts, bw_mbit): + runners = [Iperf3Runner(cfg, port=port, server_ip=dst) + for dst, port in zip(dsts, rand_ports(len(dsts)))] + servers, clients = [], [] + try: + for runner in runners: + servers.append(runner.start_server(json=True)) + for runner in runners: + clients.append(runner.start_client(background=True, + duration=MEASURE_SEC, omit=1, + udp_mbit=_payload_mbit(bw_mbit), + length=UDP_PAYLOAD)) + for proc in clients: + proc.process(terminate=False, timeout=MEASURE_SEC + 15) + for proc in servers: + proc.process(terminate=False, fail=False, timeout=5) + except CmdExitFailure as ex: + out = f"{ex.cmd.stderr} {ex.cmd.stdout}" + raise KsftFailEx(f"iperf3 failed: {out}") from ex + finally: + for proc in clients + servers: + if proc.ret is None: + try: + proc.process(terminate=True, fail=False, timeout=5) + except subprocess.TimeoutExpired: + proc.proc.kill() + return [_rx_mbit(server.stdout) for server in servers] + + +def police_independent(cfg): + """ + Check that two rules with their own police actions each enforce their + own rate. + """ + _setup_clsact(cfg) + rule1, dst1 = _dst_ip_rule(cfg) + rule2, dst2 = _dst_ip_rule(cfg) + + _check_baseline_rate(cfg) + _add_filter(cfg, rule1, _police(RATE_MBIT // 4), pref=10) + _add_filter(cfg, rule2, _police(RATE_MBIT // 2), pref=11) + + got1, got2 = _iperf3_flows(cfg, [dst1, dst2], OFFERED_MBIT // 2) + _check_rate(got1, RATE_MBIT // 4, "first filter") + _check_rate(got2, RATE_MBIT // 2, "second filter") + + +def _skip_rejected(cfg, err, pref, what): + if _filter_info(cfg, pref) is not None: + raise KsftFailEx(f"Rejected {what} left behind") + ksft_pr(err) + raise KsftSkipEx(f"{what} not offloaded") + + +def police_shared_action(cfg): + """ + Check that two rules sharing a police action index are limited together + to a single rate. + """ + _setup_clsact(cfg) + rule1, dst1 = _dst_ip_rule(cfg) + rule2, dst2 = _dst_ip_rule(cfg) + while True: + index = random.randint(1000, 60000) + if cmd(f"tc actions get action police index {index}", + fail=False).ret: + break + + _check_baseline_rate(cfg) + _add_filter(cfg, rule1, _police(RATE_MBIT, extra=f"index {index}"), + pref=10) + added, err = _try_filter(cfg, rule2, f"action police index {index}", + pref=11) + if not added: + _skip_rejected(cfg, err, 11, "Shared police action") + + total = sum(_iperf3_flows(cfg, [dst1, dst2], OFFERED_MBIT // 2)) + _check_rate(total, RATE_MBIT, "aggregate of shared action") + + +@ksft_variants([ + KsftNamedVariant("slow_first", 10, 20, RATE_MBIT // 2), + KsftNamedVariant("fast_first", 20, 10, RATE_MBIT), +]) +def police_priority(cfg, slow_pref, fast_pref, expect): + """ + Check that of two rules with the same match, the one with the lower + priority value decides, whichever of them is installed first. + """ + _setup_clsact(cfg) + rule, dst = _dst_ip_rule(cfg) + _check_baseline_rate(cfg) + + _add_filter(cfg, rule, _police(RATE_MBIT // 2), pref=slow_pref) + added, err = _try_filter(cfg, rule, _police(RATE_MBIT), pref=fast_pref) + if not added: + _skip_rejected(cfg, err, fast_pref, "Second rule with the same match") + + got = _iperf3(cfg, dst, OFFERED_MBIT) + _check_rate(got, expect, "rule with the lower pref") + + def main() -> None: """Ksft boilerplate main.""" with NetDrvEpEnv(__file__, nsim_test=False) as cfg: @@ -387,7 +490,10 @@ def main() -> None: police_rate, police_isolation, police_dst_prefix, - police_params], + police_params, + police_independent, + police_shared_action, + police_priority], args=(cfg,)) ksft_exit() -- 2.53.1-Meta