Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mohsin.bashr@gmail.com
Cc: netdev@vger.kernel.org, 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: Re: [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak
Date: Sat, 05 Dec 2026 00:15:27 +0000	[thread overview]
Message-ID: <179642972779.3146.4146352416139305976@kernel.org> (raw)
In-Reply-To: <20261204000521.3396802-4-mohsin.bashr@gmail.com>

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@kernel.org>` 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@kernel.org>
> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>

[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@kernel.org>"
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

  reply	other threads:[~2026-12-05  0:15 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 [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-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 ` [PATCH net-next 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering Mohsin Bashir
2026-12-05  0:15   ` 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=179642972779.3146.4146352416139305976@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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=mohsin.bashr@gmail.com \
    --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