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 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak
Date: Thu, 3 Dec 2026 16:05:13 -0800 [thread overview]
Message-ID: <20261204000521.3396802-4-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com>
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
next prev 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 ` Mohsin Bashir [this message]
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
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-4-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