From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342751; b=KHA0RmHlqjTm6vDeaks1i5dn/5o27T3uAxY5X39NtipkjmOQCevC/WBjmy8kROpDntb2 FYyRw7X5Mg8Tkskhw+mPgo2TtNzy8FF5SvHzIIe065RuvDATR6PnOqBQl8RhBCXS54w0x JG0ZiaR8dMjrt23tQDRGMeWEEqQDXPEoZJF/ZJ6hULGgrKttA851b6SxoLlCTVjjq5UWR Qzpd2p+gMFkdTcPjHZiCdRv7WNM6TbLPL5+XPmCiDcYF0a5ZN33IkRwvNhwRQtDORq8XM 11ag4GrF9ksvVf0PT83MvKvVYNd3IS9lUGOJ20G3LfwJozOIDnp7Xen/EerxkdT4leA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342751; 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=NIKP6JTQADdXumccQnGf8AU17DjTFbnmpM4H5THQtPg=; b=l+vTXB4y6zLsNeVorqNro0XS4HdVQcvD+zBKXYDIU8mGlDC/1F7Erl3JQ0zpFOd9PpWL CBn5sxr6c+qOKzmlas25AoPFSYu4+6Dh2WqYKCEiG8OOGth3AcGQHOfTuq9zBpKFwnASM eyJWeFYRRzNK9k3B2kqJhuoSAqLlzBGfbgEV3StMV8+krLTAroi3RZgwHYL00Qfd3nmgm JNzaUodyXzR9w36q9Diostp6XhlC6Zp8qfsdL0iKHaIOkq70DjKKPEiIRabOVxHQ7O+B+ QWnRQWxiTa3ZRdSQNJ84JjAnBghmQ5Ffe3yTky2XFmk0d30njtgFNyK3xanzFhQBiRA== 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.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 86938606A684 for ; Fri, 4 Dec 2026 00:05:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86938606A684 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-f45.google.com with SMTP id ffacd0b85a97d-4cf418d85bbso94328f8f.2 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=lQqvxZgU3xkxUdukNPR/z23ZAxKL3fdwTfz+YQQr27UddfLCpbUdq3spGABVCbdrFS kl2KsuUnHhnsdOx4hW4zWgvPTGGZ42Grw4KECkUIMB4gpQWLpGGm6t1pDREOQSCtL6yL E769bVbxvvQ/8jsesWju6tnYv5sJTuklb7ska7sf22Ej8B39DeYN7Rc3Co8fY0eqOoP6 VQSF94SMB3tmjxF/f2aSJ/rxa6fhj0P0UMnxO19oyxndDwn8lqysr32s/s0d2AC1Zgeo WOFzRhkS/BgkR9x9M6Z1Khq37+1zER+g458MsN9d+7bSBa4JYNNstU8SQZD7/I8iwHx6 0rQA== X-Forwarded-Encrypted: i=1; AL+hErGz04kImXIZO2Tw2Pg5Q4QFhnwtyGMt/2ItIWDXxBPVLGcKb4plzW2qM8mBT/2d3jMGssqJyyEGtlE4fSSmXOU=@vger.kernel.org X-Gm-Message-State: APuU4Z+pqOR1MCfdQL804thfZM7zg0+CRjKt13RZwnK/i1vI6oageCRa 19U9RnSp3MUft1MyqFgyjuWh8GNBMDG/w2Lwtiiz4YZBfWmp/uvXZjHT X-Gm-Gg: AZFdTZeo3lYqOJEsWwitg5c7iZ5Zdek4oyKgiwUnYBGmzwEO6oLjP0VKdjh/A/6QaCn 8IrzUG96Wo4tvCOI+FA1FljFgiWm+EFgVKxCRjCQuI7WeomAHd7eUeDBtLkw4exVtJbSmO88+Pf /+4uAPDWflD5c3mf2JmyANYKwXyxgyR3Ll6H5o7rMT6xDXznnbS0ZKQxurFYX1yZ98zhnFGT+7b sVt8ZN3Z9bzx4CchpW+vWXXKsomccK5zPwK0rKP725fm1uBnnVq2onQ/3fgDPbe1tJsmZuxrRcA gujeJz78XjcNcTbrCNmh5boDfsEPtnlAeXYR9JmGWEvAUQ43VeVFQBrtXyAifPO7sRS7MGBnduM hhPcvG2SaeaJZcrhH9d1IFlMxxAX93FjDnUdJ1u+VRVZ5Df9IaoLhD8zkFG8Gc4p2/qGKpy8VOE 43nui8yUyMv3285G0YH9FQF6modyjyrbVE6uwIStSIMpY5iIyv520LG7u9U8+Jw4kjEGnc/k10m ZNCGEl1ijJgViukQZfBVsua46dGhYsrh/4yIwf6/ykvXeGjSJgP3eKHi+c2zI2H6i2ag6Od78P3 hdPTAK4EVSjb4pDB1ZblzYkiBkrv 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: 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 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