* [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results
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 ` Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
2026-12-04 0:05 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test Mohsin Bashir
` (9 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
Iperf3Runner only runs TCP and reports results on the client. Tests that
rate limit traffic on the receive side need to send UDP at a given rate
and read the per-interval results on the server. Add a json option to
start_server() and udp_mbit, length and omit options to start_client().
The defaults keep the current command lines, so existing users are not
affected. start_server() now also stops the server if it does not start
listening in time.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../selftests/drivers/net/lib/py/load.py | 49 ++++++++++++++-----
1 file changed, 36 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py
index f337b576c4b4..97d91f55e11f 100644
--- a/tools/testing/selftests/drivers/net/lib/py/load.py
+++ b/tools/testing/selftests/drivers/net/lib/py/load.py
@@ -2,7 +2,7 @@
import re
import time
-import json
+import json as _json
from dataclasses import dataclass
from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
@@ -26,39 +26,62 @@ class Iperf3Runner:
self.server_ip = server_ip
self.client_ip = client_ip
- def _build_server(self):
+ def _build_server(self, json):
cmdline = f"iperf3 -s -1 -p {self.port}"
if self.server_ip:
cmdline += f" -B {self.server_ip}"
+ if json:
+ cmdline += " -J"
return cmdline
- def _build_client(self, streams, duration, reverse):
+ def _build_client(self, streams, duration, reverse, udp_mbit, length,
+ omit):
host = self.env.addr if self.server_ip is None else self.server_ip
cmdline = f"iperf3 -c {host} -p {self.port} -P {streams} -t {duration} -J"
if self.client_ip:
cmdline += f" -B {self.client_ip}"
if reverse:
cmdline += " --reverse"
+ if udp_mbit is not None:
+ cmdline += f" -u -b {udp_mbit}M"
+ if length is not None:
+ cmdline += f" -l {length}"
+ if omit:
+ cmdline += f" -O {omit}"
return cmdline
- def start_server(self):
+ def start_server(self, json=None):
"""
- Starts an iperf3 server with optional bind IP.
+ Starts an iperf3 server with optional bind IP. With @json the
+ server prints its results as JSON when the client is done,
+ including the bytes it received in each interval, or sent if the
+ client runs with @reverse.
"""
- cmdline = self._build_server()
+ cmdline = self._build_server(json)
proc = cmd(cmdline, background=True)
- wait_port_listen(self.port)
+ try:
+ wait_port_listen(self.port)
+ except Exception:
+ # Do not leave a server behind that waits for a client
+ proc.process(terminate=True, fail=False)
+ raise
time.sleep(0.1)
return proc
- def start_client(self, background=False, streams=1, duration=10, reverse=False):
+ def start_client(self, background=False, streams=1, duration=10, reverse=False,
+ udp_mbit=None, length=None, omit=0):
"""
- Starts the iperf3 client with the configured options.
+ Starts the iperf3 client with the configured options. TCP is used
+ unless @udp_mbit gives the UDP rate to send at, in Mbit/s. The
+ rate applies to each of the @streams. @length is the read/write
+ buffer size (the UDP payload size) and @omit the number of seconds
+ to run before measuring.
"""
- cmdline = self._build_client(streams, duration, reverse)
+ cmdline = self._build_client(streams, duration, reverse, udp_mbit,
+ length, omit)
kwargs = {"background": background, "host": self.env.remote}
if not background:
- kwargs["timeout"] = duration + 5
+ kwargs["timeout"] = duration + omit + 5
return cmd(cmdline, **kwargs)
def measure(self, reverse=False):
@@ -73,8 +96,8 @@ class Iperf3Runner:
if result.ret != 0:
raise RuntimeError("iperf3 failed to run successfully")
try:
- out = json.loads(result.stdout)
- except json.JSONDecodeError as exc:
+ out = _json.loads(result.stdout)
+ except _json.JSONDecodeError as exc:
raise ValueError("Failed to parse iperf3 JSON output") from exc
intervals = out.get("intervals", [])
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The Signed-off-by chain does not match the commit author.
--
selftests: drv-net: Iperf3Runner: Support UDP and server side results
This commit lets Iperf3Runner print server side results as JSON, and adds
udp_mbit, length and omit options so the client can send UDP at a set rate.
The defaults leave the existing command lines unchanged. start_server() now
also stops the server if it does not start listening in time.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
Does the Signed-off-by chain match the authorship here? The author is
Mohsin Bashir, but the first Signed-off-by is Jakub Kicinski. There is no
Co-developed-by tag for Jakub and no From: line in the body.
Documentation/process/submitting-patches.rst treats the first Signed-off-by
as the original author. Read that way, these trailers say Jakub wrote the
patch, while the author field credits Mohsin.
If Jakub is the author, could the author be set to him with a From: line?
If you both wrote it, could "Co-developed-by: Jakub Kicinski
<kuba@kernel.org>" go just before Jakub's Signed-off-by? In both cases,
Mohsin's Signed-off-by as the submitter stays last.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test
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-04 0:05 ` Mohsin Bashir
2026-12-05 0:15 ` 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
` (8 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
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
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test
2026-12-04 0:05 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test Mohsin Bashir
@ 2026-12-05 0:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The authorship trailers contradict the From: line.
--
selftests: drv-net: Add tc-flower police offload test
This commit adds tc_flower_police.py, a test for tc flower police
offload. The first case checks that a skip_sw rule is reported as in_hw
and a skip_hw rule is not. The rules match on a destination IPv6
address taken from LOCAL_PREFIX_V6. The commit also adds
CONFIG_NET_ACT_POLICE and CONFIG_NET_CLS_FLOWER to the config.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
Do these trailers match the From: line? The author is Mohsin Bashir,
but Jakub's Signed-off-by: comes before the author's, and there is no
Co-developed-by: tag.
Documentation/process/submitting-patches.rst says:
Since Co-developed-by: denotes authorship, every Co-developed-by: must
be immediately followed by a Signed-off-by: of the associated
co-author. Standard sign-off procedure applies, i.e. the ordering of
Signed-off-by: tags should reflect the chronological history of the
patch
If Jakub wrote the patch, should the From: be his? If he co-wrote it,
is a "Co-developed-by: Jakub Kicinski <kuba@kernel.org>" line missing
just before his Signed-off-by:?
The same trailers appear on all 11 patches in the series, from
"selftests: drv-net: Iperf3Runner: Support UDP and server side results"
through "selftests: drv-net: tc_flower_police: Test policing with RSS
contexts".
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak
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-04 0:05 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test Mohsin Bashir
@ 2026-12-04 0:05 ` 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
` (7 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
Drivers often reserve a policer or a classifier entry before they know
whether a rule can be installed. Missing the release on rule removal or
on a failed install leaks the entry, and the device eventually rejects
valid rules. Add police_no_leak to fill the device until it refuses a
rule, flush the rules and verify that it takes the same number again.
The test adds at most 1025 rules, each with its own address from
LOCAL_PREFIX_V6, and skips if the prefix is too small or the device
accepts all of them. Some devices use the action index as the policer
slot, so both fills wait for earlier police actions to be freed. Police
actions still present after 5 seconds skip the test before the first
fill and fail it after the flush.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../drivers/net/hw/tc_flower_police.py | 66 ++++++++++++++++++-
1 file changed, 64 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 86d26314decf..b03a00ad0c0b 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -3,7 +3,9 @@
"""Test HW offload of tc-flower rules with a police action on ingress."""
import ipaddress
-from lib.py import ksft_run, ksft_exit
+import tempfile
+import time
+from lib.py import ksft_run, ksft_exit, ksft_pr
from lib.py import ksft_eq
from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx
from lib.py import NetDrvEpEnv
@@ -91,10 +93,70 @@ def offload_flags(cfg):
_check_in_hw(cfg, 11, expect=False)
+def _count_filters(cfg):
+ data = tc(f"filter show dev {cfg.ifname} ingress", json=True)
+ return sum(1 for entry in data if "options" in entry)
+
+
+def _scale_fill(cfg, count, force=False):
+ with tempfile.NamedTemporaryFile("w") as tmp:
+ for i in range(count):
+ tmp.write(f"filter add dev {cfg.ifname} ingress pref 100 "
+ f"handle {i + 1} {_ctrl_rule(cfg, i)} skip_sw "
+ f"{_police(100)}\n")
+ tmp.flush()
+ res = cmd(f"tc {'-force ' if force else ''}-batch {tmp.name}",
+ fail=False)
+ if res.ret and "Command failed" not in res.stderr:
+ raise KsftFailEx(f"tc -batch failed: {res.stderr.strip()}")
+ return _count_filters(cfg)
+
+
+def _wait_police_freed():
+ for _ in range(50):
+ if not tc("actions list action police", json=True):
+ return True
+ time.sleep(0.1)
+ return False
+
+
+def police_no_leak(cfg):
+ """
+ Fill the device with police rules, flush them, and check that it then
+ takes exactly as many rules again.
+ """
+ _setup_clsact(cfg)
+
+ limit = 1025
+ # Each rule uses its own address, starting with the second one
+ if _local_prefix(cfg).num_addresses <= limit:
+ raise KsftSkipEx(f"LOCAL_PREFIX_V6 too small, need {limit + 1} "
+ "addresses")
+ defer(cmd, f"tc filter del dev {cfg.ifname} ingress", fail=False)
+ if not _wait_police_freed():
+ raise KsftSkipEx("Police actions present before the test")
+ full = _scale_fill(cfg, limit)
+ if not full:
+ raise KsftSkipEx("Rule not offloaded")
+ if full == limit:
+ raise KsftSkipEx(f"Device accepted all {limit} rules, cannot fill it")
+ ksft_pr(f"Device full after {full} rules")
+
+ cmd(f"tc filter del dev {cfg.ifname} ingress")
+ left = _count_filters(cfg)
+ if left:
+ raise KsftFailEx(f"{left} rules left after the flush")
+ if not _wait_police_freed():
+ raise KsftFailEx("Police actions still present after 5 s")
+ refill = _scale_fill(cfg, full + 1, force=True)
+ ksft_eq(refill, full, "Rules taken after the flush")
+
+
def main() -> None:
"""Ksft boilerplate main."""
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
- ksft_run([offload_flags],
+ ksft_run([offload_flags,
+ police_no_leak],
args=(cfg,))
ksft_exit()
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] police_no_leak() is not built to catch the leak the commit
message gives as its motivation.
- [Medium] _scale_fill() runs up to 1025 synchronous skip_sw hardware
offloads in one `tc -batch` through cmd(), and police_no_leak()…
- [Low] The commit is authored by Mohsin Bashir (From:), but the tag
block lists `Signed-off-by: Jakub Kicinski <kuba@kernel.org>` before…
--
selftests: drv-net: tc_flower_police: Test that rules do not leak
This adds a police_no_leak test to tc_flower_police.py. The test adds
skip_sw flower rules with a police action until the device refuses one.
It then flushes the rules and checks that the device takes the same
number of rules again.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but is a Co-developed-by: tag missing here?
Mohsin Bashir is the author of the patch, but Jakub has the first
Signed-off-by:. Documentation/process/submitting-patches.rst says the
first SoB signals primary authorship. It also says a co-author is
recorded with Co-developed-by:, immediately followed by that person's
Signed-off-by:.
Should there be a "Co-developed-by: Jakub Kicinski <kuba@kernel.org>"
line above his SoB, or is the From: author wrong? The other patches in
the series seem to have the same pattern.
> 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 86d26314decf7..b03a00ad0c0ba 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
[ ... ]
> +def _scale_fill(cfg, count, force=False):
> + with tempfile.NamedTemporaryFile("w") as tmp:
> + for i in range(count):
> + tmp.write(f"filter add dev {cfg.ifname} ingress pref 100 "
> + f"handle {i + 1} {_ctrl_rule(cfg, i)} skip_sw "
> + f"{_police(100)}\n")
> + tmp.flush()
> + res = cmd(f"tc {'-force ' if force else ''}-batch {tmp.name}",
> + fail=False)
[Severity: Medium]
Can this run past the default cmd() timeout on slower devices?
This single tc process does up to 1025 synchronous skip_sw offloads, and
cmd() keeps its default timeout=20. cmd._process_terminate() in
tools/testing/selftests/net/lib/py/utils.py does this:
stdout, stderr = self.proc.communicate(timeout=timeout)
When the timeout expires, this raises subprocess.TimeoutExpired. cmd
doesn't catch it, and the tc child is not killed. If a device averages
more than about 19ms per offload (slow firmware mailbox, debug kernel),
ksft_run() reports a failure with a raw traceback instead of a clear
result.
The NamedTemporaryFile is then unlinked, but tc still has it open. So tc
keeps adding rules while the deferred "tc filter del" and the clsact
teardown run.
The flush in police_no_leak() has the same problem:
cmd(f"tc filter del dev {cfg.ifname} ingress")
fl_destroy()->fl_hw_destroy_filter() calls into the driver synchronously
for each of the roughly 1000 filters. The refill of full + 1 rules has
the same cost.
A later patch in the series handles subprocess.TimeoutExpired in
_iperf3_flows(), but _scale_fill() and the flush are still the same at
the end of the series. Would it make sense to scale the timeout with the
rule count here?
> + if res.ret and "Command failed" not in res.stderr:
> + raise KsftFailEx(f"tc -batch failed: {res.stderr.strip()}")
> + return _count_filters(cfg)
[ ... ]
> +def police_no_leak(cfg):
[ ... ]
> + full = _scale_fill(cfg, limit)
> + if not full:
> + raise KsftSkipEx("Rule not offloaded")
> + if full == limit:
> + raise KsftSkipEx(f"Device accepted all {limit} rules, cannot fill it")
> + ksft_pr(f"Device full after {full} rules")
> +
> + cmd(f"tc filter del dev {cfg.ifname} ingress")
> + left = _count_filters(cfg)
> + if left:
> + raise KsftFailEx(f"{left} rules left after the flush")
> + if not _wait_police_freed():
> + raise KsftFailEx("Police actions still present after 5 s")
> + refill = _scale_fill(cfg, full + 1, force=True)
> + ksft_eq(refill, full, "Rules taken after the flush")
[Severity: Medium]
Will this check catch a leak on a failed install, as the commit message
says it should?
The commit message says:
Drivers often reserve a policer or a classifier entry before they know
whether a rule can be installed. Missing the release on rule removal or
on a failed install leaks the entry
A failed install can only leak a resource X that it managed to reserve.
That means X still had room after full rules, so cap_X >= full + 1.
After the flush, at least cap_X - n units of X are free, where n is the
number of failed installs in the first fill. The refill only drops below
full if n > cap_X - full.
The test does not control n. The first fill runs without -force, so tc
-batch stops at the first error it reports. tc groups the filter add
lines into netlink batches of up to 128 messages per sendmsg.
netlink_rcv_skb() keeps processing every message in the batch after an
error:
err = cb(skb, nlh, &extack);
...
if (nlh->nlmsg_flags & NLM_F_ACK || err)
netlink_ack(skb, nlh, err, &extack);
So n is the rest of the batch that holds rule full + 1, anywhere from 1
to 127. For full = 1023 or 1024 there is exactly one failed install.
With only one failure, a leaked policer or ID that is not the limiting
resource never changes the refill count, so a leaking driver would pass.
The refill also ends with one failed install, but nothing checks the
device after it.
Could the test repeat the refused install on purpose so the leaked units
add up until they become the limit? For example, it could retry the
rejected rule many times, or run the first fill with -force over all
1025 attempts. If not, should the commit message be limited to leaks on
rule removal?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (2 preceding siblings ...)
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-04 0:05 ` 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
` (6 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
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 <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../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
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit author (From:) is Mohsin Bashir, but the trailers are
'Signed-off-by: Jakub Kicinski' followed by 'Signed-off-by: Mohsin…
- [Low] In this patch, _add_secondary_addr() gains a `want` filter
callback that no caller uses (_dst_ip_rule() calls it with no…
- [Low] selftests: drv-net: _iperf3() leaks iperf3 server on
TimeoutExpired
--
selftests: drv-net: tc_flower_police: Test the policed rate and its scope
This commit adds three tests to tc_flower_police.py: link_baseline,
police_rate and police_isolation. police_rate checks that UDP sent at twice
the police rate to a rule's destination address arrives at the police rate,
within 10%. police_isolation checks that traffic to another address of the
device is not limited, and link_baseline measures the unpoliced rate so the
policing tests can skip on slow links.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but should there be a Co-developed-by: tag for Jakub
here?
The patch author is Mohsin Bashir, but the first Signed-off-by: is
Jakub's. Documentation/process/submitting-patches.rst describes the SoB
chain "with the first SoB entry signalling primary authorship of a single
author". It also says co-authors should be credited with Co-developed-by:,
followed immediately by their Signed-off-by:.
As written, the trailers suggest Jakub is the primary author, and that
doesn't match the From: line. The other patches in this series have the
same trailers, from "selftests: drv-net: Iperf3Runner: Support UDP and
server side results" through "selftests: drv-net: tc_flower_police: Test
policing with RSS contexts".
Could "Co-developed-by: Jakub Kicinski <kuba@kernel.org>" be added right
before his Signed-off-by:? If Jakub wrote the patch, the From: author
could be changed to him instead.
> 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 b03a00ad0c0ba..b42ed22419ad1 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
[ ... ]
> @@ -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
[ ... ]
> @@ -79,6 +111,81 @@ def _ctrl_rule(cfg, i=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 _dst_ip_rule(cfg):
> + dst = _add_secondary_addr(cfg)
> + return f"protocol ipv6 flower dst_ip {dst}", dst
[ ... ]
> @@ -152,11 +259,54 @@ def police_no_leak(cfg):
[ ... ]
> +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")
[Severity: Low]
This isn't a bug, but in this patch nothing uses the want argument of
_add_secondary_addr(). Its only caller, _dst_ip_rule(), calls
_add_secondary_addr(cfg) without one. Similarly, police_rate() is the only
caller of _check_rate() and ignores the boolean it returns.
Both get users later in the series. In "selftests: drv-net:
tc_flower_police: Test destination prefix rules", police_dst_prefix()
passes a want lambda. In "selftests: drv-net: tc_flower_police: Test
police parameters", _add_filter(..., dst=...) raises KsftFailEx based on
the return value of _check_rate().
Would it be cleaner to add the want argument and the return value in the
patches that use them?
[ ... ]
> @@ -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
[Severity: Low]
What cleans up the local iperf3 server if it doesn't exit within
5 seconds here?
When the client succeeds, done is True, so server.process() is called
with terminate=False and no signal is sent to the server. If
communicate(timeout=5) in cmd._process_terminate() then expires,
subprocess.TimeoutExpired propagates out of _iperf3(). The server is
not terminated, killed or reaped, and its stdout and stderr pipes are
not closed. The terminate=True path has the same problem if iperf3 is
slow to act on SIGTERM.
ksft_run() catches the exception, runs the deferred cleanups and moves
on to the next test case. The orphaned iperf3 server can then keep
running through police_isolation and the tests added later in the
series, and possibly after the script exits.
The _iperf3_flows() helper added in "selftests: drv-net:
tc_flower_police: Test multiple policers" already handles this. On
TimeoutExpired it retries with terminate=True and then calls kill().
Could _iperf3() use the same fallback, or could the two helpers share
that logic?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (3 preceding siblings ...)
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-04 0:05 ` 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
` (5 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
Flower can also match on a destination prefix. A device that ignores
the mask, or applies a longer one, polices only part of the prefix. Add
police_dst_prefix to verify that a /120 rule limits traffic to an address
in the upper half of the prefix and leaves traffic outside it alone.
The test skips if LOCAL_PREFIX_V6 is longer than /120 or the device
rejects the rule.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../drivers/net/hw/tc_flower_police.py | 35 ++++++++++++++++++-
1 file changed, 34 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 b42ed22419ad..cdff5cb6b6a3 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -298,6 +298,38 @@ def police_isolation(cfg):
_check_unpoliced(got, RATE_MBIT, "other address")
+def police_dst_prefix(cfg):
+ """
+ Check that a destination prefix rule polices traffic to an address in
+ the prefix and leaves traffic to an address outside it alone.
+ """
+ _setup_clsact(cfg)
+ if _local_prefix(cfg).prefixlen > 120:
+ raise KsftSkipEx("LOCAL_PREFIX_V6 longer than /120")
+ dst = _add_secondary_addr(cfg,
+ lambda a: int(ipaddress.IPv6Address(a)) & 0x80)
+ rule = f"protocol ipv6 flower dst_ip {dst}/120"
+
+ _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")
+ got = _iperf3(cfg, cfg.addr_v["6"], OFFERED_MBIT)
+ _check_unpoliced(got, RATE_MBIT, "address outside the prefix")
+ if _local_prefix(cfg).prefixlen < 120:
+ # Just outside the /120, for a device that uses a shorter mask
+ near = ipaddress.IPv6Address(int(ipaddress.IPv6Address(dst)) ^ 0x100)
+ if str(near) not in _dev_addrs(cfg):
+ ip(f"-6 addr add {near}/128 dev {cfg.ifname} nodad")
+ defer(ip, f"-6 addr del {near}/128 dev {cfg.ifname}")
+ got = _iperf3(cfg, near, OFFERED_MBIT)
+ _check_unpoliced(got, RATE_MBIT, "address next to the prefix")
+ else:
+ ksft_pr("LOCAL_PREFIX_V6 is a /120, shorter masks not checked")
+
+
def main() -> None:
"""Ksft boilerplate main."""
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
@@ -306,7 +338,8 @@ def main() -> None:
police_no_leak,
link_baseline,
police_rate,
- police_isolation],
+ police_isolation,
+ police_dst_prefix],
args=(cfg,))
ksft_exit()
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The Signed-off-by chain in commit "selftests: drv-net:
tc_flower_police: Test destination prefix rules" does not match its…
--
selftests: drv-net: tc_flower_police: Test destination prefix rules
This commit adds a police_dst_prefix test to tc_flower_police.py. The
test checks that a flower dst_ip /120 rule polices traffic to an address
in the prefix and leaves traffic outside the prefix alone. If
LOCAL_PREFIX_V6 is shorter than /120, it also checks an address just
outside the /120.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but the Signed-off-by chain doesn't seem to match the
authorship of the patch.
The author is Mohsin Bashir, but the first trailer is Jakub Kicinski's
Signed-off-by. The author's Signed-off-by comes after it, and there is
no Co-developed-by tag.
Documentation/process/submitting-patches.rst says:
Any further SoBs (Signed-off-by:'s) following the author's SoB are from
people handling and transporting the patch, but were not involved in its
development. SoB chains should reflect the **real** route a patch took
Should the From: line name Jakub, if he wrote the patch? If he co-wrote
it, should there be a "Co-developed-by: Jakub Kicinski" tag directly
before his Signed-off-by, as the Co-developed-by section of the same
document describes?
The other patches in this series have the same trailers. That includes
"selftests: drv-net: Iperf3Runner: Support UDP and server side results"
through "selftests: drv-net: tc_flower_police: Test policing with RSS
contexts", so the same question applies to them.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (4 preceding siblings ...)
2026-12-04 0:05 ` [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules Mohsin Bashir
@ 2026-12-04 0:05 ` 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
` (4 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
act_police supports more than a rate and a burst, and drivers usually
offload only a subset of it. Add police_params to cover the pipe exceed
action, peak rate, overhead and packet rate, and verify that traffic
shows the effect of each option the device accepts. If the device
rejects an option, the test checks that a plain police rule still works
and skips. A rejected rule must not be left behind.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../drivers/net/hw/tc_flower_police.py | 56 +++++++++++++++++--
1 file changed, 52 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 cdff5cb6b6a3..66d32f6e13f7 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -9,6 +9,7 @@ import tempfile
import time
from lib.py import ksft_run, ksft_exit, ksft_pr
from lib.py import ksft_eq, ksft_ge
+from lib.py import ksft_variants, KsftNamedVariant
from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx
from lib.py import Iperf3Runner, NetDrvEpEnv
from lib.py import set_ethtool_feat
@@ -68,9 +69,9 @@ def _add_secondary_addr(cfg, want=None):
return addr
-def _police(rate_mbit):
+def _police(rate_mbit, extra="", exceed="drop"):
return (f"action police rate {rate_mbit}mbit burst 1m "
- "conform-exceed drop/ok")
+ f"conform-exceed {exceed}/ok {extra}")
def _try_filter(cfg, rule, action, pref):
@@ -82,10 +83,16 @@ def _try_filter(cfg, rule, action, pref):
return res.ret == 0, res.stderr.strip()
-def _add_filter(cfg, rule, action, pref):
+def _add_filter(cfg, rule, action, pref, dst=None):
added, err = _try_filter(cfg, rule, action, pref)
if not added:
raise KsftSkipEx(f"Rule not offloaded: {err}")
+ if dst is None:
+ return
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ if not _check_rate(got, RATE_MBIT, f"rule at pref {pref}"):
+ raise KsftFailEx(f"Police rule at pref {pref} not at the "
+ "expected rate")
def _filter_info(cfg, pref):
@@ -330,6 +337,46 @@ def police_dst_prefix(cfg):
ksft_pr("LOCAL_PREFIX_V6 is a /120, shorter masks not checked")
+@ksft_variants([
+ KsftNamedVariant("exceed_pipe",
+ f"{_police(RATE_MBIT, exceed='pipe')} "
+ f"{_police(RATE_MBIT // 2)}",
+ RATE_MBIT + RATE_MBIT // 2),
+ KsftNamedVariant("peakrate",
+ _police(OFFERED_MBIT * 2,
+ extra=f"peakrate {RATE_MBIT}mbit mtu 65535"),
+ RATE_MBIT),
+ KsftNamedVariant("overhead",
+ _police(RATE_MBIT, extra=f"overhead {UDP_PAYLOAD}"),
+ RATE_MBIT * IP6_PKT_LEN / (IP6_PKT_LEN + UDP_PAYLOAD)),
+ KsftNamedVariant("pkts_rate",
+ "action police pkts_rate 1000 pkts_burst 100 "
+ "conform-exceed drop/ok", 1000 * IP6_PKT_LEN * 8 / 1e6),
+])
+def police_params(cfg, action, expect):
+ """
+ Check police parameters beyond the rate and burst. A device that
+ offloads the rule must limit the traffic as configured. A device may
+ reject it, and a plain police rule must then still limit the traffic,
+ after which the case is skipped.
+ """
+ _setup_clsact(cfg)
+ rule, dst = _dst_ip_rule(cfg)
+
+ _check_baseline_rate(cfg)
+ added, err = _try_filter(cfg, rule, action, pref=10)
+ if added:
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_rate(got, expect, "policed flow")
+ return
+
+ if _filter_info(cfg, 10) is not None:
+ raise KsftFailEx(f"Rejected filter left behind: {err}")
+ _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
+ reason = err.partition("\n")[0]
+ raise KsftSkipEx(f"Not offloaded: {reason}")
+
+
def main() -> None:
"""Ksft boilerplate main."""
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
@@ -339,7 +386,8 @@ def main() -> None:
link_baseline,
police_rate,
police_isolation,
- police_dst_prefix],
+ police_dst_prefix,
+ police_params],
args=(cfg,))
ksft_exit()
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] selftests: drv-net: police_params() uses _add_filter() which
skips on error
- [Low] The authorship and Signed-off-by chain in the commit "selftests:
drv-net: tc_flower_police: Test police parameters" contradict each…
--
selftests: drv-net: tc_flower_police: Test police parameters
This commit adds a police_params test case to tc_flower_police.py. It
checks the pipe exceed action, peak rate, overhead and packet rate
options of act_police. If the device rejects an option, the test checks
that a plain police rule still limits traffic and then skips.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but the Signed-off-by chain and the authorship don't
seem to agree.
The Author is Mohsin Bashir. Jakub Kicinski's Signed-off-by comes before
the author's, and there is no Co-developed-by tag.
Documentation/process/submitting-patches.rst allows two readings of a
Signed-off-by that comes before the author's:
- Jakub wrote the patch and passed it on. In that case the From: line
should name Jakub.
- Jakub co-wrote the patch. In that case a
"Co-developed-by: Jakub Kicinski <kuba@kernel.org>" line should come
right before his Signed-off-by.
Should the From: line be changed, or should a Co-developed-by tag be
added? The same pattern may also be on other patches in the series, but
only this commit's trailer was checked.
[ ... ]
> diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> @@ -330,6 +337,46 @@ def police_dst_prefix(cfg):
> ksft_pr("LOCAL_PREFIX_V6 is a /120, shorter masks not checked")
>
>
> +@ksft_variants([
> + KsftNamedVariant("exceed_pipe",
> + f"{_police(RATE_MBIT, exceed='pipe')} "
> + f"{_police(RATE_MBIT // 2)}",
> + RATE_MBIT + RATE_MBIT // 2),
> + KsftNamedVariant("peakrate",
> + _police(OFFERED_MBIT * 2,
> + extra=f"peakrate {RATE_MBIT}mbit mtu 65535"),
> + RATE_MBIT),
> + KsftNamedVariant("overhead",
> + _police(RATE_MBIT, extra=f"overhead {UDP_PAYLOAD}"),
> + RATE_MBIT * IP6_PKT_LEN / (IP6_PKT_LEN + UDP_PAYLOAD)),
> + KsftNamedVariant("pkts_rate",
> + "action police pkts_rate 1000 pkts_burst 100 "
> + "conform-exceed drop/ok", 1000 * IP6_PKT_LEN * 8 / 1e6),
> +])
> +def police_params(cfg, action, expect):
> + """
> + Check police parameters beyond the rate and burst. A device that
> + offloads the rule must limit the traffic as configured. A device may
> + reject it, and a plain police rule must then still limit the traffic,
> + after which the case is skipped.
> + """
> + _setup_clsact(cfg)
> + rule, dst = _dst_ip_rule(cfg)
> +
> + _check_baseline_rate(cfg)
> + added, err = _try_filter(cfg, rule, action, pref=10)
> + if added:
> + got = _iperf3(cfg, dst, OFFERED_MBIT)
> + _check_rate(got, expect, "policed flow")
> + return
> +
> + if _filter_info(cfg, 10) is not None:
> + raise KsftFailEx(f"Rejected filter left behind: {err}")
> + _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
> + reason = err.partition("\n")[0]
> + raise KsftSkipEx(f"Not offloaded: {reason}")
> +
> +
> def main() -> None:
> """Ksft boilerplate main."""
> with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
[Severity: Medium]
Does this fallback check actually fail when the plain rule can't be
reinstalled?
The commit message and the docstring say that after a rejection the
test checks that a plain police rule still works. This goes through
_add_filter(), though, and _add_filter() raises
KsftSkipEx("Rule not offloaded: ...") whenever _try_filter() fails.
Consider a driver that rejects, say, peakrate but does not unwind its
own state on that error path, for example by leaking a flow entry or a
policer slot for the same dst_ip. The plain _police(RATE_MBIT) rule at
pref 10 would then fail to install.
The _filter_info(cfg, 10) check won't catch this, because tc core has
already dropped its software copy of the rejected filter. The failure
is reported as a SKIP from _add_filter(), and ksft_run() counts it the
same as a clean rejection.
So the regression this path seems meant to catch is reported as a
skip. Only the case where the plain rule installs but does not limit
the rate becomes a KsftFailEx.
Would it work to check plain police offload first? For example,
install and remove _police(RATE_MBIT) before trying the parameterized
action, or cache that result on cfg the way the baseline rate is
cached. Then a failure to add the plain rule after the rejection could
raise KsftFailEx, while devices that don't offload act_police at all
would still skip.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (5 preceding siblings ...)
2026-12-04 0:05 ` [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters Mohsin Bashir
@ 2026-12-04 0:05 ` 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
` (3 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
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 <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../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
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] selftests/drv-net: police_shared_action() allows a dropping
rule to pass
- [Low] The authorship tags contradict the From: line.
- [Low] selftests/drv-net: police_shared_action() index exceeds HW
policer table size
- [Low] selftests/drv-net: _iperf3_flows() does not reap child or close
pipes on kill
--
selftests: drv-net: tc_flower_police: Test multiple policers
This commit adds three tests to tc_flower_police.py: police_independent,
police_shared_action and police_priority. Together they check that a
device keeps separate policers apart, shares a police action across
rules when asked to, and applies overlapping rules in priority order.
Both flows run at the same time through a new _iperf3_flows() helper.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but do these trailers match the From: line?
The author is Mohsin Bashir, but the first Signed-off-by is Jakub
Kicinski's, and there is no Co-developed-by tag.
Documentation/process/submitting-patches.rst says the first SoB entry
signals primary authorship. It also says that when a patch has more than
one author, each co-author needs a Co-developed-by tag immediately
followed by their Signed-off-by.
If Jakub co-developed the patch, should the block look like this?
Co-developed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
If Jakub is the sole author, should the From: line carry his name
instead?
Every patch in the series has the same trailer, from "selftests:
drv-net: Iperf3Runner: Support UDP and server side results" through
"selftests: drv-net: tc_flower_police: Test policing with RSS contexts",
so the same change would apply to all of them.
[ ... ]
> diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> @@ -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)
[Severity: Low]
Does this leave the killed process behind?
proc.process(terminate=True, ...) ends up in cmd._process_terminate().
That function calls self.proc.communicate(timeout=timeout) before it
closes self.proc.stdout and self.proc.stderr and sets self.ret. When
communicate() raises subprocess.TimeoutExpired, none of that happens.
proc.proc.kill() then only sends SIGKILL.
Nothing waits for the child afterwards. It stays a zombie, and its
pipes stay open until the objects are garbage collected. The deferred
teardown of the test addresses and the clsact qdisc can then race with
the dying iperf3 process. Later test cases in the same run also keep
the leaked descriptors.
Would it be better to follow the kill with proc.proc.wait(), or with
another proc.process(terminate=False, fail=False) call? The kperf
helpers in drivers/net/lib/py already handle their kill path that way.
[Severity: Low]
Will this index work on devices that map the police action index
straight onto a hardware policer slot?
The kernel hands act->tcfa_index to drivers as
flow_action_entry.hw_index, and some in-tree drivers use it directly.
ocelot_flower_parse_action() computes pol_ix from a->hw_index plus
vcap_pol.base, and returns -EINVAL once that reaches vcap_pol.max,
which is 191 on VSC7514. enetc_psfp_parse_clsflower() uses
entryp->hw_index as the flow meter index.
random.randint(1000, 60000) never picks anything below 1000. On such
hardware the first _add_filter() in police_shared_action() would be
rejected, and the test would bail out before the shared rule is even
tried. That can happen even if the device supports shared policers
just fine.
Could the first rule be installed without an explicit index, and the
index the kernel assigned be read back for the second rule? For
example, _filter_info() on pref 10 could provide it, if it exposes the
action index. Or would probing for a free index starting from a low
value be simpler?
> + 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:
[Severity: Medium]
Can this check pass when one of the two rules is not forwarding
anything?
_iperf3_flows() is called with OFFERED_MBIT // 2, so each flow offers
100 Mbit/s. That is already the full RATE_MBIT of the shared policer.
Only the sum of the two measured rates is compared against RATE_MBIT.
Suppose the device mis-programs the second rule, the one created with
"action police index N", and drops all of its traffic. The first flow
alone then delivers about 100 Mbit/s, and _check_rate() is satisfied.
The same holds the other way round.
That looks like exactly the kind of breakage a shared-action test
should catch. Would it make sense to also check that each value
returned by _iperf3_flows() carries a meaningful share of the rate?
Alternatively, each flow could offer less than
RATE_MBIT * (1 - TOLERANCE). The policer is still oversubscribed in
aggregate, but a single flow can no longer reach the limit on its own.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (6 preceding siblings ...)
2026-12-04 0:05 ` [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Mohsin Bashir
@ 2026-12-04 0:05 ` 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
` (2 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
Removing a policing rule must also remove the rate limit in hardware.
Add police_delete to verify that a flow is no longer limited once its
rule is deleted.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../drivers/net/hw/tc_flower_police.py | 18 +++++++++++++++++-
1 file changed, 17 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 bca1e324e69a..73162c31bd59 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -480,6 +480,21 @@ def police_priority(cfg, slow_pref, fast_pref, expect):
_check_rate(got, expect, "rule with the lower pref")
+def police_delete(cfg):
+ """
+ Check that deleting a rule removes the limit in hardware.
+ """
+ _setup_clsact(cfg)
+ rule, dst = _dst_ip_rule(cfg)
+
+ _check_baseline_rate(cfg)
+ _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
+
+ tc(f"filter del dev {cfg.ifname} ingress pref 10")
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_unpoliced(got, RATE_MBIT, "after delete")
+
+
def main() -> None:
"""Ksft boilerplate main."""
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
@@ -493,7 +508,8 @@ def main() -> None:
police_params,
police_independent,
police_shared_action,
- police_priority],
+ police_priority,
+ police_delete],
args=(cfg,))
ksft_exit()
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The Signed-off-by chain is inconsistent with the recorded author.
--
selftests: drv-net: tc_flower_police: Test rule removal
This commit adds a police_delete test to tc_flower_police.py. The test
installs a policing filter, deletes it, and then checks that iperf3
traffic is no longer rate limited.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but does the Signed-off-by chain match the recorded
authorship?
The author is Mohsin Bashir, but the first Signed-off-by is from Jakub
Kicinski, and there is no Co-developed-by: tag.
Documentation/process/submitting-patches.rst says the SoB chain should
reflect the real route the patch took, "with the first SoB entry
signalling primary authorship of a single author". It also says each
Co-developed-by: must be immediately followed by a Signed-off-by: from
that co-author.
If Jakub wrote the patch, should the author be Jakub? If it was
co-developed, should "Co-developed-by: Jakub Kicinski <kuba@kernel.org>"
go directly before his Signed-off-by?
The other patches in this series, from "selftests: drv-net:
Iperf3Runner: Support UDP and server side results" through "selftests:
drv-net: tc_flower_police: Test policing with RSS contexts", have the
same trailers.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (7 preceding siblings ...)
2026-12-04 0:05 ` [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal Mohsin Bashir
@ 2026-12-04 0:05 ` 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-04 0:05 ` [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts Mohsin Bashir
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
Changing the channels or RX rings, or taking the link down and up, can
be disruptive to the device. Verify that a policing rule keeps limiting
traffic across each of these, and that a rule added while the link is
down takes effect once it is up.
The ring test doubles the RX ring size, or halves it if doubling would
exceed the maximum. A device that refuses the change is skipped. Rejecting a
rule only while the link is down is a failure.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../drivers/net/hw/tc_flower_police.py | 146 +++++++++++++++++-
1 file changed, 140 insertions(+), 6 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 73162c31bd59..368882984411 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -10,12 +10,12 @@ import tempfile
import time
from lib.py import ksft_run, ksft_exit, ksft_pr
from lib.py import ksft_eq, ksft_ge
-from lib.py import ksft_variants, KsftNamedVariant
-from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx
-from lib.py import Iperf3Runner, NetDrvEpEnv
+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 set_ethtool_feat
-from lib.py import cmd, defer, ethtool, ip, tc
-from lib.py import rand_port, rand_ports
+from lib.py import cmd, ctl_file_write, defer, ethtool, ip, tc
+from lib.py import rand_port, rand_ports, wait_file
RATE_MBIT = 100
@@ -495,9 +495,139 @@ def police_delete(cfg):
_check_unpoliced(got, RATE_MBIT, "after delete")
+def police_channels(cfg):
+ """
+ Check that a police rule keeps working after the channel count changes.
+ """
+ _setup_clsact(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 not cnt:
+ raise KsftSkipEx("Device does not use combined channels")
+ if cnt > 1:
+ new = cnt - 1
+ elif channels.get("combined-max", 0) > 1:
+ new = 2
+ else:
+ raise KsftSkipEx("Cannot change channel count")
+
+ rule, dst = _dst_ip_rule(cfg)
+ _check_baseline_rate(cfg)
+ _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
+ 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": new})
+ except NlError as ex:
+ raise KsftSkipEx(f"Cannot change the channel count to {new}: "
+ f"{ex}") from ex
+ wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
+ lambda x: x.strip() == "1", deadline=30)
+ ksft_eq(cfg.ethnl.channels_get(ehdr)["combined-count"], new,
+ "Combined channel count")
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_rate(got, RATE_MBIT, "after channel change")
+
+
+def police_ring_size(cfg):
+ """
+ Check that a police rule keeps working after the RX ring size changes.
+ """
+ _setup_clsact(cfg)
+ ehdr = {"header": {"dev-index": cfg.ifindex}}
+ try:
+ rings = cfg.ethnl.rings_get(ehdr)
+ except NlError as ex:
+ raise KsftSkipEx("ring-get not supported by device") from ex
+ if "rx" not in rings or "rx-max" not in rings:
+ raise KsftSkipEx("Device does not report its RX ring size")
+ cur = rings["rx"]
+ new = cur * 2 if cur * 2 <= rings["rx-max"] else cur // 2
+ if not new:
+ raise KsftSkipEx("Cannot change the RX ring size")
+
+ rule, dst = _dst_ip_rule(cfg)
+ _check_baseline_rate(cfg)
+ _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
+ defer(wait_file, f"/sys/class/net/{cfg.ifname}/carrier",
+ lambda x: x.strip() == "1", deadline=30)
+ defer(cfg.ethnl.rings_set, ehdr | {"rx": cur})
+ try:
+ cfg.ethnl.rings_set(ehdr | {"rx": new})
+ except NlError as ex:
+ raise KsftSkipEx(f"Cannot change the RX ring size to {new}: "
+ f"{ex}") from ex
+ wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
+ lambda x: x.strip() == "1", deadline=30)
+ ksft_eq(cfg.ethnl.rings_get(ehdr)["rx"], new, "RX ring size")
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_rate(got, RATE_MBIT, "after ring resize")
+
+
+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")
+ defer(wait_file, f"/sys/class/net/{cfg.ifname}/carrier",
+ lambda x: x.strip() == "1", deadline=30)
+ defer(ip, f"link set dev {cfg.ifname} up")
+
+
+def _link_up(cfg):
+ ip(f"link set dev {cfg.ifname} up")
+ wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
+ lambda x: x.strip() == "1", deadline=30)
+ if cmd(f"ping -c 1 -w 10 {cfg.remote_addr_v['6']}", fail=False).ret:
+ raise KsftFailEx("Cannot reach the remote after the link flap")
+
+
+@ksft_disruptive
+def police_link_flap(cfg):
+ """
+ Check that a police rule survives the link going down and up.
+ """
+ _setup_clsact(cfg)
+ rule, dst = _dst_ip_rule(cfg)
+ _check_baseline_rate(cfg)
+ _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
+ _link_down(cfg)
+ _link_up(cfg)
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_rate(got, RATE_MBIT, "after link flap")
+
+
+@ksft_disruptive
+def police_add_while_down(cfg):
+ """
+ Check that a police rule added while the link is down takes effect once
+ the link is up.
+ """
+ _setup_clsact(cfg)
+ rule, dst = _dst_ip_rule(cfg)
+ _check_baseline_rate(cfg)
+ _link_down(cfg)
+ added, err = _try_filter(cfg, rule, _police(RATE_MBIT), pref=10)
+ _link_up(cfg)
+ if not added:
+ if _filter_info(cfg, 10) is not None:
+ raise KsftFailEx("Rule rejected while the link was down left "
+ "behind")
+ if not _try_filter(cfg, rule, _police(RATE_MBIT), pref=10)[0]:
+ raise KsftSkipEx(f"Rule not offloaded: {err}")
+ raise KsftFailEx(f"Rule rejected while the link was down: {err}")
+ _check_in_hw(cfg, 10)
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_rate(got, RATE_MBIT, "added while down")
+
+
def main() -> None:
"""Ksft boilerplate main."""
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ cfg.ethnl = EthtoolFamily()
cfg.baseline = None
ksft_run([offload_flags,
police_no_leak,
@@ -509,7 +639,11 @@ def main() -> None:
police_independent,
police_shared_action,
police_priority,
- police_delete],
+ police_delete,
+ police_channels,
+ police_ring_size,
+ police_link_flap,
+ police_add_while_down],
args=(cfg,))
ksft_exit()
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] police_channels() and police_ring_size() in
tools/testing/selftests/drivers/net/hw/tc_flower_police.py lack…
- [Medium] police_ring_size() requests new = cur*2 (or cur//2 if doubling
would exceed rx-max).
- [Medium] selftests: drv-net: premature defer() in
police_channels()/police_ring_size()
- [Low] The attribution tags conflict with the author field.
--
selftests: drv-net: tc_flower_police: Test policing across reconfiguration
This adds tests to tc_flower_police.py that check a flower police rule
keeps limiting traffic across a channel count change, an RX ring size
change and a link flap. It also checks that a rule added while the link
is down takes effect once the link comes back up.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
Is a Co-developed-by: Jakub Kicinski tag missing here? The Author line
says Mohsin Bashir, but the first Signed-off-by is Jakub's.
Documentation/process/submitting-patches.rst says the first SoB entry
signals primary authorship. It also says co-authors get a
Co-developed-by: tag immediately followed by their Signed-off-by.
As written, the trailers make Jakub look like the primary author, but the
From: line names someone else. The other tc_flower_police commits in the
series use the same pattern.
> 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 73162c31bd59a..368882984411a 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
[ ... ]
> @@ -495,9 +495,139 @@ def police_delete(cfg):
> _check_unpoliced(got, RATE_MBIT, "after delete")
>
>
> +def police_channels(cfg):
> + """
> + Check that a police rule keeps working after the channel count changes.
> + """
[ ... ]
> + 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": new})
> + except NlError as ex:
> + raise KsftSkipEx(f"Cannot change the channel count to {new}: "
> + f"{ex}") from ex
> + wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
> + lambda x: x.strip() == "1", deadline=30)
[Severity: Medium]
Is the restore deferred too early here? The carrier wait and the
channels_set() restore are both queued before channels_set(new) has
succeeded.
Take a driver that implements get_channels but not set_channels. The
channels_get() above succeeds. The set then fails with -EOPNOTSUPP
from ethnl_set_channels_validate(), and the except branch raises
KsftSkipEx.
When ksft_run() handles the skip, it flushes the defer queue. The
restore to the unchanged cnt also goes through
ethnl_default_set_doit(). There, set_validate() runs before
ethnl_set_channels() can notice that nothing changed, so the restore
fails with -EOPNOTSUPP again.
ksft_flush_defer() catches that NlError, prints a Defer Exception
traceback and sets KSFT_RESULT = False. The case is reported as a
skip, but the whole run exits non-zero.
police_ring_size() has the same problem with rings_set() and
ethnl_set_rings_validate() when set_ringparam is missing.
This is reachable on real hardware. enetc, am65-cpsw and ef100 all
offload flower police and have the get callback without the matching
set one. On those devices, what the commit message describes as a
clean skip turns into a failed run.
Would it work to register both defer() calls only after the
try/except block, once the new value has actually been applied?
[Severity: Medium]
Should police_channels() and police_ring_size() be marked
@ksft_disruptive?
After channels_set() or rings_set(), both tests wait up to 30 seconds for
carrier to come back. They wait again in the deferred restore, so they
expect the link to drop.
tools/testing/selftests/drivers/net/README.rst says:
All tests which may disconnect NETIF
must be annotated with @ksft_disruptive.
This patch does mark police_link_flap() and police_add_while_down(). With
DISRUPTIVE=False, these two tests still run. They can drop carrier on the
interface used to reach the remote, for up to 30 seconds per step.
If the NIC does not come back, wouldn't both the remote session and the
deferred restore be lost?
> + ksft_eq(cfg.ethnl.channels_get(ehdr)["combined-count"], new,
> + "Combined channel count")
> + got = _iperf3(cfg, dst, OFFERED_MBIT)
> + _check_rate(got, RATE_MBIT, "after channel change")
> +
> +
> +def police_ring_size(cfg):
> + """
> + Check that a police rule keeps working after the RX ring size changes.
> + """
[ ... ]
> + cur = rings["rx"]
> + new = cur * 2 if cur * 2 <= rings["rx-max"] else cur // 2
> + if not new:
> + raise KsftSkipEx("Cannot change the RX ring size")
[ ... ]
> + wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
> + lambda x: x.strip() == "1", deadline=30)
> + ksft_eq(cfg.ethnl.rings_get(ehdr)["rx"], new, "RX ring size")
[Severity: Medium]
Can this exact comparison fail on drivers that round the requested ring
size instead of rejecting it?
octeontx2 offloads flower police (FLOW_ACTION_POLICE in otx2_tc.c), and
otx2_set_ringparam() only allows 16*4^n sizes:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c:otx2_set_ringparam() {
...
rx_count = Q_COUNT(Q_SIZE(rx_count, 3));
...
}
Take a 256 entry ring. Doubling it requests 512, the driver rounds that
up to 1024, and rings_get() reports 1024. ksft_eq() then fails even
though the resize and the policing both worked.
ice_set_ringparam() also rounds silently:
new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
An E810 ring at its 8160 maximum would request 4080 and read back 4096.
ice does not offload police today, so this case is not reachable yet.
Would it be enough to check that the reported size differs from cur, or
to use the value read back for the later checks?
> + got = _iperf3(cfg, dst, OFFERED_MBIT)
> + _check_rate(got, RATE_MBIT, "after ring resize")
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (8 preceding siblings ...)
2026-12-04 0:05 ` [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration Mohsin Bashir
@ 2026-12-04 0:05 ` 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
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
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 <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../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
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In police_with_ntuple
(tools/testing/selftests/drivers/net/hw/tc_flower_police.py), the…
- [Low] police_with_ntuple handles a rejected second rule differently
depending on install order.
- [Low] The commit author (From:) is Mohsin Bashir, but the first Signed-
off-by is Jakub Kicinski's, followed by the author's, and there is no…
- [Low] selftests: premature defer() before channels_set() in
police_with_ntuple()
--
selftests: drv-net: tc_flower_police: Test policing with ntuple steering
This commit adds a police_with_ntuple test to tc_flower_police.py. The
test installs an ntuple rule and a tc flower policer for the same flow, in
either order, then checks that the flow is rate limited and steered to the
ntuple queue. Devices that lack ntuple filters or reject the second rule
are skipped.
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
[Severity: Low]
This isn't a bug, but the trailer order looks inconsistent. The From:
author is Mohsin Bashir, but the first Signed-off-by is Jakub Kicinski's,
and there is no Co-developed-by tag.
Documentation/process/submitting-patches.rst says the first SoB entry
signals "primary authorship of a single author". It also says any
co-author needs a Co-developed-by: line immediately followed by their
Signed-off-by:.
If both of you developed this, should there be a "Co-developed-by: Jakub
Kicinski <kuba@kernel.org>" line right before his Signed-off-by? If Jakub
is the primary author, should From: name him instead? The other patches in
the series seem to use the same trailer pattern.
> 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 368882984411a..d0315e8bf2b2d 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
[ ... ]
> @@ -569,6 +569,120 @@ def police_ring_size(cfg):
[ ... ]
> +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.
> + """
[ ... ]
> + 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")
[Severity: Low]
Should this branch check that the ntuple rule still steers the flow before
it skips?
_skip_rejected() only checks that no tc filter is left at pref 10:
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")
The police_first branch below does run traffic after the second rule is
rejected ("Rejecting the ntuple rule must not break the policer"). Nothing
similar happens here.
Suppose a driver merges both rules into one classifier entry. If it breaks
the existing ntuple steering while backing out a failed policer install,
wouldn't the ntuple_first variant report SKIP rather than FAIL?
Running iperf3 and checking that delta[queue] still carries the flow
before raising the skip would make the two install orders symmetric.
> + 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}")
[Severity: Low]
Do these checks confirm that the flow lands "on the ntuple queue only", as
the docstring and commit message say?
_set_rss_indir(cfg, ehdr, [0]) makes queue 0 the fallback for anything the
ntuple rule misses. The idle sum leaves queue 0 out, and the only check on
the ntuple queue is the 90% lower bound.
The value of got is the rate the server measured over all received
packets, including any that went to queue 0. _expected_pkts() also leaves
out the policer burst from the unmeasured -O second. So a device that
sends roughly 10% of the policed flow to queue 0 would still pass both
checks.
Leaving queue 0 out makes sense, because the iperf3 TCP control connection
and ND traffic land there. The side effect is that leaked flow packets on
queue 0 can't be told apart from that traffic.
Could the docstring and commit message be reworded, for example "mostly on
the ntuple queue and on no other non-default queue"? Alternatively, could
the test require delta[0] to stay small compared with delta[queue]?
[ ... ]
> @@ -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")
[Severity: Low]
Are these two defer() calls registered too early? They are queued
before cfg.ethnl.channels_set() to 2 has been attempted, so the skip
path right below still runs them during cleanup.
Take a device that reports a combined-count below 2 and a
combined-max of 2 or more, but where the set request fails. For
example, a driver might implement get_channels without set_channels.
In that case ethnl_set_channels_validate() returns -EOPNOTSUPP. The
test then raises KsftSkipEx("Cannot set 2 combined channels"), which
is what you want.
During teardown, ksft_flush_defer() runs the queued restore of
combined-count back to cnt. That request goes through
ethnl_default_set_doit() again and fails in set_validate() or in
ethnl_ops_begin(). Both run before ethnl_set_channels() could treat
the unchanged count as a no-op.
The NlError from the deferred callback sets KSFT_RESULT to False. The
case is then reported as "not ok ... # SKIP", and ksft_exit()
returns 1 for what should have been a clean skip.
Would it work to register both defer() callbacks only after
channels_set() to 2 succeeds? That is how _set_rss_indir() and
_add_ntuple() already handle it in this patch.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts
2026-12-04 0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
` (9 preceding siblings ...)
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-04 0:05 ` Mohsin Bashir
2026-12-05 0:15 ` netdev-bot+sashiko
10 siblings, 1 reply; 23+ messages in thread
From: Mohsin Bashir @ 2026-12-04 0:05 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
From: Mohsin Bashir <hmohsin@meta.com>
Containers often get their own RSS context, with an ntuple rule steering
the container address to its queues. Add police_rss_ctx to verify that
the policers of two such containers limit their own traffic at their own
rate once it is steered to their context. The test needs 6 combined
channels, ntuple filters and RSS contexts, and skips otherwise.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
.../drivers/net/hw/tc_flower_police.py | 65 +++++++++++++++++++
1 file changed, 65 insertions(+)
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 d0315e8bf2b2..d3051dda49ed 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -683,6 +683,70 @@ def police_with_ntuple(cfg, ntuple_first):
ksft_eq(idle, 0, f"Traffic on queues other than 0 and {queue}: {delta}")
+def police_rss_ctx(cfg):
+ """
+ Check policing of flows steered to RSS contexts: each flow is limited
+ to its own rate and stays on the queues of its context.
+ """
+ _setup_clsact(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 < 6:
+ if channels.get("combined-max", 0) < 6:
+ raise KsftSkipEx("Need 6 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": 6})
+ except NlError as ex:
+ raise KsftSkipEx("Cannot set 6 combined channels") from ex
+ wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
+ lambda x: x.strip() == "1", deadline=30)
+
+ # Steer all other traffic to the default queues 0 and 1
+ _set_rss_indir(cfg, ehdr, [0, 1])
+ flows = []
+ for i in range(2):
+ queues = [2 + 2 * i, 3 + 2 * i]
+ try:
+ ctx = cfg.ethnl.rss_create_act(ehdr | {"indir": queues})["context"]
+ except NlError as ex:
+ raise KsftSkipEx("RSS context not created") from ex
+ defer(cfg.ethnl.rss_delete_act, ehdr | {"context": ctx})
+
+ dst = _add_secondary_addr(cfg)
+ _add_ntuple(cfg, f"flow-type ip6 dst-ip {dst} context {ctx}")
+
+ rule = f"protocol ipv6 flower dst_ip {dst}"
+ limit = RATE_MBIT // 2 * (i + 1)
+ flows.append((rule, dst, limit, queues))
+
+ _check_baseline_rate(cfg)
+ for i, (rule, _, limit, _) in enumerate(flows):
+ _add_filter(cfg, rule, _police(limit), pref=10 + i)
+
+ for i, (_, dst, limit, queues) in enumerate(flows):
+ other = flows[1 - i][3]
+ before = _rx_queue_pkts(cfg)
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ after = _rx_queue_pkts(cfg)
+ delta = {q: after[q] - before.get(q, 0) for q in after}
+ expected = _expected_pkts(got)
+ _check_rate(got, limit, f"context {i}")
+ ksft_ge(sum(delta.get(q, 0) for q in queues), expected * 0.9,
+ f"Context {i} traffic not on queues {queues}: {delta}")
+ ksft_eq(sum(delta.get(q, 0) for q in other), 0,
+ f"Context {i} traffic on the other context: {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")
@@ -758,6 +822,7 @@ def main() -> None:
police_channels,
police_ring_size,
police_with_ntuple,
+ police_rss_ctx,
police_link_flap,
police_add_while_down],
args=(cfg,))
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts
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
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 0:15 UTC (permalink / raw)
To: mohsin.bashr
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, shuah,
linux-kselftest, linux-kernel
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The docstring of police_rss_ctx() in
tools/testing/selftests/drivers/net/hw/tc_flower_police.py says each…
- [Low] selftests: drv-net: duplicated channel setup in police_rss_ctx()
- [Low] selftests: drv-net: police_rss_ctx() queues defer() before
channels_set()
--
selftests: drv-net: tc_flower_police: Test policing with RSS contexts
This adds police_rss_ctx() to tc_flower_police.py. The test steers two
secondary addresses into their own RSS contexts with ntuple rules and
checks that a flower policer on each flow limits it to its own rate. It
needs 6 combined channels, ntuple filters and RSS contexts, and skips
otherwise.
> 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 d0315e8bf2b2d..d3051dda49ed9 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> @@ -683,6 +683,70 @@ def police_with_ntuple(cfg, ntuple_first):
> ksft_eq(idle, 0, f"Traffic on queues other than 0 and {queue}: {delta}")
>
>
> +def police_rss_ctx(cfg):
> + """
> + Check policing of flows steered to RSS contexts: each flow is limited
> + to its own rate and stays on the queues of its context.
> + """
[ ... ]
> + cnt = channels.get("combined-count", 0)
> + if cnt < 6:
[ ... ]
> + for i, (_, dst, limit, queues) in enumerate(flows):
> + other = flows[1 - i][3]
> + before = _rx_queue_pkts(cfg)
> + got = _iperf3(cfg, dst, OFFERED_MBIT)
> + after = _rx_queue_pkts(cfg)
> + delta = {q: after[q] - before.get(q, 0) for q in after}
> + expected = _expected_pkts(got)
> + _check_rate(got, limit, f"context {i}")
> + ksft_ge(sum(delta.get(q, 0) for q in queues), expected * 0.9,
> + f"Context {i} traffic not on queues {queues}: {delta}")
> + ksft_eq(sum(delta.get(q, 0) for q in other), 0,
> + f"Context {i} traffic on the other context: {delta}")
[Severity: Low]
Do these checks fully cover what the docstring says, that each flow
"stays on the queues of its context"?
Only two sets of queues are checked. The flow's own context queues must
see at least 90% of the expected packets, and the other context's queues
must see zero. Queues 0/1 and any queue numbered 6 or higher are not
checked.
The channel count is only changed when cnt < 6. On a device that already
has more than 6 combined channels, queues 6 and up exist. With the main
indirection table set to [0, 1] and the contexts using 2-5, those queues
should get nothing. Nothing checks that they don't.
Suppose a driver programs part of a context's indirection table with the
wrong queue base. If it sends part of a flow back to queues 0/1 or to a
queue >= 6, would the test still pass as long as the leak stays under
about 10%?
The peer test police_with_ntuple() in the same file requires every
non-target queue to be idle:
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}")
Could police_rss_ctx() do the same, and require zero traffic on every
queue outside {0, 1} and the flow's own context queues?
[ ... ]
> @@ -683,6 +683,70 @@ def police_with_ntuple(cfg, ntuple_first):
> ksft_eq(idle, 0, f"Traffic on queues other than 0 and {queue}: {delta}")
>
>
> +def police_rss_ctx(cfg):
> + """
> + Check policing of flows steered to RSS contexts: each flow is limited
> + to its own rate and stays on the queues of its context.
> + """
> + _setup_clsact(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 < 6:
> + if channels.get("combined-max", 0) < 6:
> + raise KsftSkipEx("Need 6 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})
[Severity: Low]
Two cleanups are queued with defer() before channels_set() to 6
has succeeded: the restore of the original channel count and the
carrier wait. If channels_set() raises NlError, the test raises
KsftSkipEx, but ksft_flush_defer() still runs both callbacks.
Take a driver that has get_channels but no set_channels.
ethnl_default_set_doit() calls ethnl_set_channels_validate() first,
and that returns -EOPNOTSUPP. So ethnl_set_channels() never reaches
its no-change early return, and the deferred restore to cnt fails
just like the first call did.
ksft_flush_defer() then sets KSFT_RESULT to False. The intended
SKIP is reported as not ok, and ksft_exit() returns 1. The same
happens if netdev_reconfig_start() or ethnl_ops_begin() fails.
In-tree drivers that pass the earlier checks probably all implement
set_channels, so this is unlikely to trigger today. But even when
the restore succeeds, it is a needless channel set plus an extra
carrier wait, after a change that never happened.
Elsewhere in this function, the defer() for rss_create_act() is
only registered after the create succeeds, and _set_rss_indir()
does the same. Could the two defer() calls be moved after the
try/except around channels_set()? police_with_ntuple() has the same
ordering and might want the same change.
> + try:
> + cfg.ethnl.channels_set(ehdr | {"combined-count": 6})
> + except NlError as ex:
> + raise KsftSkipEx("Cannot set 6 combined channels") from ex
> + wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
> + lambda x: x.strip() == "1", deadline=30)
> +
> + # Steer all other traffic to the default queues 0 and 1
> + _set_rss_indir(cfg, ehdr, [0, 1])
> + flows = []
> + for i in range(2):
> + queues = [2 + 2 * i, 3 + 2 * i]
> + try:
> + ctx = cfg.ethnl.rss_create_act(ehdr | {"indir": queues})["context"]
> + except NlError as ex:
> + raise KsftSkipEx("RSS context not created") from ex
> + defer(cfg.ethnl.rss_delete_act, ehdr | {"context": ctx})
> +
> + dst = _add_secondary_addr(cfg)
> + _add_ntuple(cfg, f"flow-type ip6 dst-ip {dst} context {ctx}")
> +
> + rule = f"protocol ipv6 flower dst_ip {dst}"
> + limit = RATE_MBIT // 2 * (i + 1)
> + flows.append((rule, dst, limit, queues))
> +
> + _check_baseline_rate(cfg)
> + for i, (rule, _, limit, _) in enumerate(flows):
> + _add_filter(cfg, rule, _police(limit), pref=10 + i)
> +
> + for i, (_, dst, limit, queues) in enumerate(flows):
> + other = flows[1 - i][3]
> + before = _rx_queue_pkts(cfg)
> + got = _iperf3(cfg, dst, OFFERED_MBIT)
> + after = _rx_queue_pkts(cfg)
> + delta = {q: after[q] - before.get(q, 0) for q in after}
> + expected = _expected_pkts(got)
> + _check_rate(got, limit, f"context {i}")
> + ksft_ge(sum(delta.get(q, 0) for q in queues), expected * 0.9,
> + f"Context {i} traffic not on queues {queues}: {delta}")
> + ksft_eq(sum(delta.get(q, 0) for q in other), 0,
> + f"Context {i} traffic on the other context: {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")
[Severity: Low]
This block copies the channel setup from police_with_ntuple(). The
only change is that the required count goes from 2 to 6. Both copies
do the same steps: the channels_get() call, the combined-max skip
check, the deferred carrier wait and channel restore, the
channels_set() call and the final carrier wait.
The other setup steps these tests share are already helpers:
_require_ntuple(), _set_rss_indir(), _rx_queue_pkts() and
_add_ntuple(). Could this be pulled into something like
_require_channels(cfg, ehdr, count) and called from both tests?
That keeps the reconfiguration and restore logic in one place. Any
fix to it, such as where the defer() calls sit relative to
channels_set(), would then only have to be made once.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com
^ permalink raw reply [flat|nested] 23+ messages in thread