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=1796342752; b=KoqVvcW1jiDhK5Pq45zIQRQJoY0MyqOUjiwv5eB4OXbmzjxlHBXmadGM29wocPrjVKRm HdVrDNTA3EEWO3G+qYOe2XW8G9/c4p8H0UD5JzdwLYOhq1JelA7x+fxIMeswnUEyQOnec m1E96Knsuvkqkto2BMCzgv3i9lkbinpnPSWtEa2eGFal/Bplv6nx9b9CyUTRwALPmUxci ZTgRub84m36ihb5Na9pge0MKqJ0+DvlmlLkEQIMNKucI2AfmI17ejA8oZ7WO9nYl2J+JV RWJ1ynU3uXTbjhh+3rpkc9QFVPirb+aA0Iupfkxi0XPv3m11FDol5iXlJGPGXbR2IIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342752; 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=NIKP6JTQADdXumccQnGf8AU17DjTFbnmpM4H5THQtPg=; b=ILMPt9Ko2mr4qMcHoFB3TZKp62DFusuxRnbXp5Hyfx6aPrH4kZCe9Nkc59LCPBIcTIbn pCVM+YKx/9ZQbsnZ9+4KZVU34ezB8ubM+o9ynOiVfj49+NCmNIoS9rNNMk248trxWH6Xk pbkqWXJYEGy59QXuHLLkSYE/aabkQ7ZofK/Izqz4PAdRtYG3dPLoewG1TrR12DBRz09zR H6u8/IRi04CELOdonbWrJWjTWTOXA7I5/MkrF40Y9S+mpIZde/hUORYX1SoQE5iqjxi+I 0pxXq0nybNKuMNdj2wwIyB3VaLf4x+kAjCFC4FDswwK6Qf67ZmTjEFD9QDqX+20WfZA== 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=FWoGtMA+; 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 9294C606A689 for ; Fri, 4 Dec 2026 00:05:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9294C606A689 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=FWoGtMA+ Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-4a358881793so84135f8f.0 for ; Thu, 03 Dec 2026 16:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342750; x=1796947550; 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=NIKP6JTQADdXumccQnGf8AU17DjTFbnmpM4H5THQtPg=; b=FWoGtMA+PpkygaTPMkTh0i7mhSTfOESoFAYa0mZl5Zdd8Tx3MfDOfrhIaHNe4ZiEHP TxZFQMIOH+E5bXC8yBMfkVl9BBGMoDGkrFgy1dghwOZlwZ8XAJ5ZPEUFhInEtchqVbnH GFnC2h1gE0aiXEdY9CRsqHY8cGFyebUM9vwtTzo7aIosfKKzsdI3UxnCiiOujDsRaipA 6hcyXPFnOcjG4NJIn6fUePrOFjE5t1azJgsae7V4fIvHE95J2+O2r8Qt9nY7r2/fu3Az WyVjVZw3q+kHQ+bQXiHqJ1aKjzXhs1KRFcSfcXQ3sIF2Gcadh1Fut7lFkkuXWs2aHQ3F ghfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342750; x=1796947550; 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=NIKP6JTQADdXumccQnGf8AU17DjTFbnmpM4H5THQtPg=; b=Pkd891iP7M4uvyXkc8IJMMBxx4HDeYaKO1OaJSnrKDbilGjJrt00GhaAAI7vKycxHf LO05Qi3kDRSoONgpkB54egI7WzSK98Ile1nBEqD48aBYt3BIRgnWIxifwRTxrnZSBFue RqwATKbnyXxv2Lj206gHoABT4b8xKWft91YW6itkvDs2mLdWPjtas0Ejino+Ka8tEgcF LS0eTYUmFVfKfVAFApath1FoUqxawZgmHW2WEEPGB+Qn5U1kHabLcBwA4EBCaD67lVSn BgmRHJfIA1yZhTToBZYFVqa1uFyiPChioq4hANAi6K72zmwi/WUajs0AmZVKxBTpYrLF GKXw== X-Gm-Message-State: APuU4Z95ntCvO1VvR20HtyAB6PL5/agj62Jb26yhs1RHT/MtB182slSp xoflq9Iho6AfkrX8c8Voc3Mi/Izb6BqJxkB8orIACLX/jkquS6Pinbn9DLvD3LFO X-Gm-Gg: AZFdTZee+Bg0KScBu8HD5izYPuzgLJzD7IEXcd2yUgL7v8asktYWH9tkkJpz5Xw6S7b k8PZroZmVRipvhe5H7wVV0IO92rdw9Ywd8Tj/KIbjqI8cC/SQwY6qnsv/8Eb8S5V03QASS4aViq 8JohsCGiCCT6YpGOqFVU0F0vgXVEd9rVy8usswLeQ58ShBvSl48DPWM8eN2+75DqMo5UTWGST1z /FjLn5k7znci8m0Ist4vA9MHa44SWQ25L/Wv0FdsWqTbQh6AbzcT56k2GYu5dT2rbWyzFNCQHfd TjOxMOTNAs3g29cEEYd+GHsuqwVVIPH3Jv2dPJVIZaFEVvyCinNIjfclZC/8CIoA30ad5p/0ZlI qPO6Q7iszpZVnCTLLd8EEDw/W1P7EP9NwyKdtLwym4Wu5n+aACDO2XJnKb99cUSD0IAwczlWAeS jolbmnIn/B6qQDBxvWwsVPeeQoATt27tJUECmcj+TPJod++HesQPZV53vMEMtm0cVg6ZbPPHEhD D4oSCsZahyck/4s+eyYFJRkAAPmnU08ESLvVOQ3QvVs5xsz225Wrdf/tQdQpRx1B8tT6CfsZ0DR iHaPcNv38o5BdL8NyPQN+ImeS5/e X-Received: by 2002:a05:600c:3145:b0:4bb:7347:d5df with SMTP id 5b1f17b1804b1-4bbeb8cdd1amr5057895e9.13.1796342749914; Thu, 03 Dec 2026 16:05:49 -0800 (PST) Received: from localhost ([2a03:2880:31ff:2b::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172e41d76sm2038527f8f.23.2026.12.03.16.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 16:05:48 -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 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering Date: Thu, 3 Dec 2026 16:05:20 -0800 Message-ID: <20261204000521.3396802-11-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 An ntuple rule and a policer can match the same flow, and a device may implement both with a single classifier lookup. Add police_with_ntuple to verify that, in either install order, the flow is rate limited and lands on the ntuple queue only. A device without ntuple filters, or one that rejects the second rule, is skipped. A rejected policer must not be left behind. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../drivers/net/hw/tc_flower_police.py | 118 +++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) 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 368882984411..d0315e8bf2b2 100755 --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py @@ -12,7 +12,7 @@ from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_eq, ksft_ge from lib.py import ksft_disruptive, ksft_variants, KsftNamedVariant from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx, NlError -from lib.py import Iperf3Runner, NetDrvEpEnv, EthtoolFamily +from lib.py import Iperf3Runner, NetDrvEpEnv, NetdevFamily, EthtoolFamily from lib.py import set_ethtool_feat from lib.py import cmd, ctl_file_write, defer, ethtool, ip, tc from lib.py import rand_port, rand_ports, wait_file @@ -569,6 +569,120 @@ def police_ring_size(cfg): _check_rate(got, RATE_MBIT, "after ring resize") +def _set_rss_indir(cfg, ehdr, indir): + try: + cfg.ethnl.rss_set(ehdr | {"indir": indir}) + except NlError as ex: + raise KsftSkipEx("Cannot change the RSS indirection table") from ex + defer(cfg.ethnl.rss_set, ehdr | {"indir": None}) + + +def _require_ntuple(cfg): + feat = ethtool(f"-k {cfg.ifname}", json=True)[0]["ntuple-filters"] + if not feat["active"]: + if feat["fixed"]: + raise KsftSkipEx("Device does not support ntuple-filters") + defer(ethtool, f"-K {cfg.ifname} ntuple-filters off") + cmd(f"ethtool -K {cfg.ifname} ntuple-filters on", fail=False) + feat = ethtool(f"-k {cfg.ifname}", json=True)[0]["ntuple-filters"] + if not feat["active"]: + raise KsftSkipEx("Cannot turn ntuple-filters on") + + +def _rx_queue_pkts(cfg): + cfg.wait_hw_stats_settle() + try: + stats = cfg.netdevnl.qstats_get({"ifindex": cfg.ifindex, + "scope": ["queue"]}, dump=True) + except NlError as ex: + raise KsftSkipEx("Device does not report queue stats") from ex + pkts = {s["queue-id"]: s["rx-packets"] for s in stats + if s["queue-type"] == "rx" and "rx-packets" in s} + if not pkts: + raise KsftSkipEx("Device does not report RX packets per queue") + return pkts + + +def _expected_pkts(mbit): + # The client sends for -t plus the -O second + return mbit * 1e6 * (MEASURE_SEC + 1) / 8 / IP6_PKT_LEN + + +def _add_ntuple(cfg, flow): + res = cmd(f"ethtool -N {cfg.ifname} {flow}", fail=False) + if res.ret: + ksft_pr(res.stderr.strip()) + raise KsftSkipEx("ntuple rule rejected") + defer(ethtool, f"-N {cfg.ifname} delete {int(res.stdout.split()[-1])}") + + +@ksft_variants([ + KsftNamedVariant("ntuple_first", True), + KsftNamedVariant("police_first", False), +]) +def police_with_ntuple(cfg, ntuple_first): + """ + Check that an ntuple rule and a police rule for the same flow both take + effect, whichever is installed first: the flow is policed and lands on + the ntuple queue only. + """ + _setup_clsact(cfg) + rule, dst = _dst_ip_rule(cfg) + _require_ntuple(cfg) + _rx_queue_pkts(cfg) + + ehdr = {"header": {"dev-index": cfg.ifindex}} + try: + channels = cfg.ethnl.channels_get(ehdr) + except NlError as ex: + raise KsftSkipEx("channel-get not supported by device") from ex + cnt = channels.get("combined-count", 0) + if cnt < 2: + if channels.get("combined-max", 0) < 2: + raise KsftSkipEx("Need at least 2 combined channels") + defer(wait_file, f"/sys/class/net/{cfg.ifname}/carrier", + lambda x: x.strip() == "1", deadline=30) + defer(cfg.ethnl.channels_set, ehdr | {"combined-count": cnt}) + try: + cfg.ethnl.channels_set(ehdr | {"combined-count": 2}) + except NlError as ex: + raise KsftSkipEx("Cannot set 2 combined channels") from ex + wait_file(f"/sys/class/net/{cfg.ifname}/carrier", + lambda x: x.strip() == "1", deadline=30) + cnt = 2 + queue = cnt - 1 + _set_rss_indir(cfg, ehdr, [0]) + + _check_baseline_rate(cfg) + flow = f"flow-type udp6 dst-ip {dst} action {queue}" + if ntuple_first: + _add_ntuple(cfg, flow) + added, err = _try_filter(cfg, rule, _police(RATE_MBIT), pref=10) + if not added: + _skip_rejected(cfg, err, 10, "Policer next to the ntuple rule") + else: + _add_filter(cfg, rule, _police(RATE_MBIT), pref=10) + try: + _add_ntuple(cfg, flow) + except KsftSkipEx: + # Rejecting the ntuple rule must not break the policer + got = _iperf3(cfg, dst, OFFERED_MBIT) + if _check_rate(got, RATE_MBIT, "policer after ntuple rejection"): + raise + return + + before = _rx_queue_pkts(cfg) + got = _iperf3(cfg, dst, OFFERED_MBIT) + after = _rx_queue_pkts(cfg) + _check_rate(got, RATE_MBIT, "ntuple steered flow") + + delta = {q: after[q] - before.get(q, 0) for q in after} + ksft_ge(delta.get(queue, 0), _expected_pkts(got) * 0.9, + f"Policed flow not on ntuple queue {queue}: {delta}") + idle = sum(delta.values()) - delta.get(0, 0) - delta.get(queue, 0) + ksft_eq(idle, 0, f"Traffic on queues other than 0 and {queue}: {delta}") + + def _link_down(cfg): ctl_file_write("/proc/sys/net/ipv6/conf/all/keep_addr_on_down", 1) ip(f"link set dev {cfg.ifname} down") @@ -628,6 +742,7 @@ def main() -> None: """Ksft boilerplate main.""" with NetDrvEpEnv(__file__, nsim_test=False) as cfg: cfg.ethnl = EthtoolFamily() + cfg.netdevnl = NetdevFamily() cfg.baseline = None ksft_run([offload_flags, police_no_leak, @@ -642,6 +757,7 @@ def main() -> None: police_delete, police_channels, police_ring_size, + police_with_ntuple, police_link_flap, police_add_while_down], args=(cfg,)) -- 2.53.1-Meta