From: Mohsin Bashir <mohsin.bashr@gmail.com>
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 02/11] selftests: drv-net: Add tc-flower police offload test
Date: Thu, 3 Dec 2026 16:05:12 -0800 [thread overview]
Message-ID: <20261204000521.3396802-3-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com>
From: Mohsin Bashir <hmohsin@meta.com>
Add tc_flower_police.py to test tc flower police offload, starting with
the offload flags. A skip_sw rule must be reported as in_hw and a
skip_hw rule must not.
The rules match on the destination IPv6 address, so the test needs
LOCAL_PREFIX_V6. Tests skip if the device does not offload the rule and
report XFAIL if hw-tc-offload cannot be turned on.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../testing/selftests/drivers/net/hw/Makefile | 1 +
tools/testing/selftests/drivers/net/hw/config | 2 +
.../drivers/net/hw/lib/py/__init__.py | 4 +-
.../drivers/net/hw/tc_flower_police.py | 103 ++++++++++++++++++
4 files changed, 108 insertions(+), 2 deletions(-)
create mode 100755 tools/testing/selftests/drivers/net/hw/tc_flower_police.py
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
index 429cb545a4f0..809d84358d95 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile
@@ -47,6 +47,7 @@ TEST_PROGS = \
rss_drv.py \
rss_flow_label.py \
rss_input_xfrm.py \
+ tc_flower_police.py \
tls_hw_offload.py \
toeplitz.py \
tso.py \
diff --git a/tools/testing/selftests/drivers/net/hw/config b/tools/testing/selftests/drivers/net/hw/config
index 081155bf7847..f16d22215f09 100644
--- a/tools/testing/selftests/drivers/net/hw/config
+++ b/tools/testing/selftests/drivers/net/hw/config
@@ -13,8 +13,10 @@ CONFIG_IPV6=y
CONFIG_IPV6_GRE=y
CONFIG_IPV6_SIT=y
CONFIG_IPV6_TUNNEL=y
+CONFIG_NET_ACT_POLICE=y
CONFIG_NET_CLS_ACT=y
CONFIG_NET_CLS_BPF=y
+CONFIG_NET_CLS_FLOWER=y
CONFIG_NET_DEVMEM=y
CONFIG_NET_IPGRE=y
CONFIG_NET_IPGRE_DEMUX=y
diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
index 4077f5f1a1be..96f2f5659c23 100644
--- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
+++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
@@ -23,7 +23,7 @@ try:
NlError, RtnlFamily, DevlinkFamily, PSPFamily, Netlink
from net.lib.py import CmdExitFailure
from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
- fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, \
+ fd_read_timeout, ip, rand_port, rand_ports, tc, wait_port_listen, \
wait_file, ctl_file_write, tool
from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
@@ -40,7 +40,7 @@ try:
"NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily", "Netlink",
"CmdExitFailure",
"bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool",
- "fd_read_timeout", "ip", "rand_port", "rand_ports",
+ "fd_read_timeout", "ip", "rand_port", "rand_ports", "tc",
"wait_port_listen", "wait_file", "ctl_file_write", "tool",
"bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
"KsftSkipEx", "KsftFailEx", "KsftXfailEx",
diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
new file mode 100755
index 000000000000..86d26314decf
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+"""Test HW offload of tc-flower rules with a police action on ingress."""
+
+import ipaddress
+from lib.py import ksft_run, ksft_exit
+from lib.py import ksft_eq
+from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx
+from lib.py import NetDrvEpEnv
+from lib.py import set_ethtool_feat
+from lib.py import cmd, defer, ethtool, tc
+
+
+def _setup_clsact(cfg):
+ feats = ethtool(f"-k {cfg.ifname}", json=True)[0]
+ try:
+ set_ethtool_feat(cfg.ifname, feats, {"hw-tc-offload": True})
+ except CmdExitFailure as ex:
+ raise KsftXfailEx("Cannot turn hw-tc-offload on") from ex
+ res = cmd(f"tc qdisc add dev {cfg.ifname} clsact", fail=False)
+ if res.ret:
+ raise KsftSkipEx(f"Cannot add clsact qdisc: {res.stderr.strip()}")
+ defer(tc, f"qdisc del dev {cfg.ifname} clsact")
+
+
+def _local_prefix(cfg):
+ cfg.require_ipver("6")
+ prefix = cfg.env.get("LOCAL_PREFIX_V6")
+ if not prefix:
+ raise KsftSkipEx("LOCAL_PREFIX_V6 required")
+ net = ipaddress.IPv6Network(prefix, strict=False)
+ if ipaddress.ip_address(cfg.addr_v["6"]) in net:
+ raise KsftSkipEx("LOCAL_V6 must not fall within LOCAL_PREFIX_V6")
+ return net
+
+
+def _police(rate_mbit):
+ return (f"action police rate {rate_mbit}mbit burst 1m "
+ "conform-exceed drop/ok")
+
+
+def _try_filter(cfg, rule, action, pref):
+ res = cmd(f"tc filter add dev {cfg.ifname} ingress pref {pref} handle 1 "
+ f"{rule} skip_sw {action}", fail=False)
+ if res.ret == 0:
+ defer(cmd, f"tc filter del dev {cfg.ifname} ingress pref {pref}",
+ fail=False)
+ return res.ret == 0, res.stderr.strip()
+
+
+def _add_filter(cfg, rule, action, pref):
+ added, err = _try_filter(cfg, rule, action, pref)
+ if not added:
+ raise KsftSkipEx(f"Rule not offloaded: {err}")
+
+
+def _filter_info(cfg, pref):
+ data = tc(f"filter show dev {cfg.ifname} ingress pref {pref}", json=True)
+ for entry in data:
+ if "options" in entry:
+ return entry["options"]
+ return None
+
+
+def _check_in_hw(cfg, pref, expect=True):
+ info = _filter_info(cfg, pref)
+ if info is None:
+ raise KsftFailEx(f"No filter at pref {pref}")
+ ksft_eq(bool(info.get("in_hw")), expect, f"in_hw for pref {pref}: {info}")
+
+
+def _ctrl_rule(cfg, i=0):
+ # The rule sees no traffic, so its address is not added
+ net = _local_prefix(cfg)
+ if i + 1 >= net.num_addresses:
+ raise KsftSkipEx("LOCAL_PREFIX_V6 too small for the control rules")
+ return f"protocol ipv6 flower dst_ip {net[i + 1]}"
+
+
+def offload_flags(cfg):
+ """
+ Check that a skip_sw police rule is offloaded and reported in_hw, and
+ that a skip_hw rule is not.
+ """
+ _setup_clsact(cfg)
+ _add_filter(cfg, _ctrl_rule(cfg, 0), _police(100), pref=10)
+ _check_in_hw(cfg, 10)
+ # A software-only rule only needs flower and act_police
+ tc(f"filter add dev {cfg.ifname} ingress pref 11 {_ctrl_rule(cfg, 1)} "
+ f"skip_hw {_police(100)}")
+ _check_in_hw(cfg, 11, expect=False)
+
+
+def main() -> None:
+ """Ksft boilerplate main."""
+ with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ ksft_run([offload_flags],
+ args=(cfg,))
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
--
2.53.1-Meta
next prev parent reply other threads:[~2026-12-04 0:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
2026-12-04 0:05 ` [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` Mohsin Bashir [this message]
2026-12-05 0:15 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204000521.3396802-3-mohsin.bashr@gmail.com \
--to=mohsin.bashr@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.