All of lore.kernel.org
 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 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering
Date: Thu,  3 Dec 2026 16:05:20 -0800	[thread overview]
Message-ID: <20261204000521.3396802-11-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com>

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


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

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
2026-12-04  0:05 ` [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test 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
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` Mohsin Bashir [this message]
2026-12-05  0:15   ` [PATCH net-next 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko

Reply instructions:

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

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

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

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

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

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

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