Re: [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak
From: netdev-bot+sashiko
Date: Fri Dec 04 2026 - 19:15:45 EST
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] police_no_leak() is not built to catch the leak the commit
message gives as its motivation.
- [Medium] _scale_fill() runs up to 1025 synchronous skip_sw hardware
offloads in one `tc -batch` through cmd(), and police_no_leak()…
- [Low] The commit is authored by Mohsin Bashir (From:), but the tag
block lists `Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>` before…
--
selftests: drv-net: tc_flower_police: Test that rules do not leak
This adds a police_no_leak test to tc_flower_police.py. The test adds
skip_sw flower rules with a police action until the device refuses one.
It then flushes the rules and checks that the device takes the same
number of rules again.
> Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
> Signed-off-by: Mohsin Bashir <hmohsin@xxxxxxxx>
[Severity: Low]
This isn't a bug, but is a Co-developed-by: tag missing here?
Mohsin Bashir is the author of the patch, but Jakub has the first
Signed-off-by:. Documentation/process/submitting-patches.rst says the
first SoB signals primary authorship. It also says a co-author is
recorded with Co-developed-by:, immediately followed by that person's
Signed-off-by:.
Should there be a "Co-developed-by: Jakub Kicinski <kuba@xxxxxxxxxx>"
line above his SoB, or is the From: author wrong? The other patches in
the series seem to have the same pattern.
> 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 86d26314decf7..b03a00ad0c0ba 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
[ ... ]
> +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)
[Severity: Medium]
Can this run past the default cmd() timeout on slower devices?
This single tc process does up to 1025 synchronous skip_sw offloads, and
cmd() keeps its default timeout=20. cmd._process_terminate() in
tools/testing/selftests/net/lib/py/utils.py does this:
stdout, stderr = self.proc.communicate(timeout=timeout)
When the timeout expires, this raises subprocess.TimeoutExpired. cmd
doesn't catch it, and the tc child is not killed. If a device averages
more than about 19ms per offload (slow firmware mailbox, debug kernel),
ksft_run() reports a failure with a raw traceback instead of a clear
result.
The NamedTemporaryFile is then unlinked, but tc still has it open. So tc
keeps adding rules while the deferred "tc filter del" and the clsact
teardown run.
The flush in police_no_leak() has the same problem:
cmd(f"tc filter del dev {cfg.ifname} ingress")
fl_destroy()->fl_hw_destroy_filter() calls into the driver synchronously
for each of the roughly 1000 filters. The refill of full + 1 rules has
the same cost.
A later patch in the series handles subprocess.TimeoutExpired in
_iperf3_flows(), but _scale_fill() and the flush are still the same at
the end of the series. Would it make sense to scale the timeout with the
rule count here?
> + if res.ret and "Command failed" not in res.stderr:
> + raise KsftFailEx(f"tc -batch failed: {res.stderr.strip()}")
> + return _count_filters(cfg)
[ ... ]
> +def police_no_leak(cfg):
[ ... ]
> + 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")
[Severity: Medium]
Will this check catch a leak on a failed install, as the commit message
says it should?
The commit message says:
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
A failed install can only leak a resource X that it managed to reserve.
That means X still had room after full rules, so cap_X >= full + 1.
After the flush, at least cap_X - n units of X are free, where n is the
number of failed installs in the first fill. The refill only drops below
full if n > cap_X - full.
The test does not control n. The first fill runs without -force, so tc
-batch stops at the first error it reports. tc groups the filter add
lines into netlink batches of up to 128 messages per sendmsg.
netlink_rcv_skb() keeps processing every message in the batch after an
error:
err = cb(skb, nlh, &extack);
...
if (nlh->nlmsg_flags & NLM_F_ACK || err)
netlink_ack(skb, nlh, err, &extack);
So n is the rest of the batch that holds rule full + 1, anywhere from 1
to 127. For full = 1023 or 1024 there is exactly one failed install.
With only one failure, a leaked policer or ID that is not the limiting
resource never changes the refill count, so a leaking driver would pass.
The refill also ends with one failed install, but nothing checks the
device after it.
Could the test repeat the refused install on purpose so the leaked units
add up until they become the limit? For example, it could retry the
rejected rule many times, or run the first fill with -force over all
1025 attempts. If not, should the commit message be limited to leaks on
rule removal?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com