Netdev 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 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration
Date: Thu,  3 Dec 2026 16:05:19 -0800	[thread overview]
Message-ID: <20261204000521.3396802-10-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com>

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


  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 ` [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 ` Mohsin Bashir [this message]
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-10-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