The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mohsin Bashir <mohsin.bashr@gmail.com>
To: netdev@vger.kernel.org
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers
Date: Thu,  3 Dec 2026 16:05:17 -0800	[thread overview]
Message-ID: <20261204000521.3396802-8-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com>

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


  parent reply	other threads:[~2026-12-04  0:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
2026-12-04  0:05 ` [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results Mohsin Bashir
2026-12-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 ` Mohsin Bashir [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204000521.3396802-8-mohsin.bashr@gmail.com \
    --to=mohsin.bashr@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox