* [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload
@ 2026-12-04 0:05 Mohsin Bashir
2026-12-04 0:05 ` [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results Mohsin Bashir
` (10 more replies)
0 siblings, 11 replies; 12+ 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>
At Meta, we intend to use tc-flower ingress rate limiting to limit the
ingress rate of containers. Each container has its own IPv6 address,
and a tc-flower rule on that destination address with a police action
limits the traffic the NIC delivers to it. This series adds
tc_flower_police.py, a drv-net test that covers this use case on any
device that offloads it. The existing police tests either need a switch
topology, only cover the software action, or are tied to a single
driver.
Patch 1 extends Iperf3Runner to send UDP at a given rate and read the
results on the receiver. Patches 2-8 cover the offload itself. and the
last 3 patches check that policing keeps working across channel and ring
changes and a link flap, and next to ntuple steering and RSS contexts.
The series was tested on mlx5 (ConnectX-7) in switchdev mode, with the
fix that allows police as the last action of a TC rule [1]. mlx5 does
not offload peakrate and overhead and has no ntuple filters in
switchdev mode, so those tests skip. police_no_leak skips because the
device accepts all 1025 rules.
[1] https://lore.kernel.org/all/20261201212455.2836814-1-mohsin.bashr@gmail.com/
# TAP version 13
# 1..22
# ok 1 tc_flower_police.offload_flags
# ok 2 tc_flower_police.police_no_leak # SKIP Device accepted all 1025 rules, cannot fill it
# # Unpoliced UDP rate 200 Mbit/s
# ok 3 tc_flower_police.link_baseline
# ok 4 tc_flower_police.police_rate
# ok 5 tc_flower_police.police_isolation
# ok 6 tc_flower_police.police_dst_prefix
# ok 7 tc_flower_police.police_params.exceed_pipe
# ok 8 tc_flower_police.police_params.peakrate # SKIP Not offloaded: Error: mlx5_core: Offload not supported when peakrate/avrate/overhead is configured.
# ok 9 tc_flower_police.police_params.overhead # SKIP Not offloaded: Error: mlx5_core: Offload not supported when peakrate/avrate/overhead is configured.
# ok 10 tc_flower_police.police_params.pkts_rate
# ok 11 tc_flower_police.police_independent
# ok 12 tc_flower_police.police_shared_action
# ok 13 tc_flower_police.police_priority.slow_first
# ok 14 tc_flower_police.police_priority.fast_first
# ok 15 tc_flower_police.police_delete
# ok 16 tc_flower_police.police_channels
# ok 17 tc_flower_police.police_ring_size
# ok 18 tc_flower_police.police_with_ntuple.ntuple_first # SKIP Device does not support ntuple-filters
# ok 19 tc_flower_police.police_with_ntuple.police_first # SKIP Device does not support ntuple-filters
# ok 20 tc_flower_police.police_rss_ctx # SKIP Device does not support ntuple-filters
# ok 21 tc_flower_police.police_link_flap
# ok 22 tc_flower_police.police_add_while_down
# # Totals: pass:16 fail:0 xfail:0 xpass:0 skip:6 error:0
ok 1 selftests: drivers/net/hw: tc_flower_police.py
Mohsin Bashir (11):
selftests: drv-net: Iperf3Runner: Support UDP and server side results
selftests: drv-net: Add tc-flower police offload test
selftests: drv-net: tc_flower_police: Test that rules do not leak
selftests: drv-net: tc_flower_police: Test the policed rate and its
scope
selftests: drv-net: tc_flower_police: Test destination prefix rules
selftests: drv-net: tc_flower_police: Test police parameters
selftests: drv-net: tc_flower_police: Test multiple policers
selftests: drv-net: tc_flower_police: Test rule removal
selftests: drv-net: tc_flower_police: Test policing across
reconfiguration
selftests: drv-net: tc_flower_police: Test policing with ntuple
steering
selftests: drv-net: tc_flower_police: Test policing with RSS contexts
.../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 | 833 ++++++++++++++++++
.../selftests/drivers/net/lib/py/load.py | 49 +-
5 files changed, 874 insertions(+), 15 deletions(-)
create mode 100755 tools/testing/selftests/drivers/net/hw/tc_flower_police.py
--
2.53.1-Meta
^ permalink raw reply [flat|nested] 12+ messages in thread
* [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-04 0:05 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test Mohsin Bashir
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ 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] 12+ 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-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, 0 replies; 12+ 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] 12+ 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-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, 0 replies; 12+ 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] 12+ 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-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, 0 replies; 12+ 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] 12+ 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-04 0:05 ` [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters Mohsin Bashir
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ 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] 12+ 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-04 0:05 ` [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Mohsin Bashir
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ 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] 12+ 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-04 0:05 ` [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal Mohsin Bashir
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ 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] 12+ 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-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, 0 replies; 12+ 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] 12+ 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-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, 0 replies; 12+ 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] 12+ 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-04 0:05 ` [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts Mohsin Bashir
10 siblings, 0 replies; 12+ 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] 12+ 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
10 siblings, 0 replies; 12+ 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] 12+ messages in thread
end of thread, other threads:[~2026-12-04 0:05 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak Mohsin Bashir
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 ` [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules Mohsin Bashir
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 ` [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Mohsin Bashir
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 ` [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration Mohsin Bashir
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox