Re: [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope

From: netdev-bot+sashiko

Date: Fri Dec 04 2026 - 19:16:15 EST


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit author (From:) is Mohsin Bashir, but the trailers are
'Signed-off-by: Jakub Kicinski' followed by 'Signed-off-by: Mohsin…
- [Low] In this patch, _add_secondary_addr() gains a `want` filter
callback that no caller uses (_dst_ip_rule() calls it with no…
- [Low] selftests: drv-net: _iperf3() leaks iperf3 server on
TimeoutExpired

--

selftests: drv-net: tc_flower_police: Test the policed rate and its scope

This commit adds three tests to tc_flower_police.py: link_baseline,
police_rate and police_isolation. police_rate checks that UDP sent at twice
the police rate to a rule's destination address arrives at the police rate,
within 10%. police_isolation checks that traffic to another address of the
device is not limited, and link_baseline measures the unpoliced rate so the
policing tests can skip on slow links.

> Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
> Signed-off-by: Mohsin Bashir <hmohsin@xxxxxxxx>

[Severity: Low]
This isn't a bug, but should there be a Co-developed-by: tag for Jakub
here?

The patch author is Mohsin Bashir, but the first Signed-off-by: is
Jakub's. Documentation/process/submitting-patches.rst describes the SoB
chain "with the first SoB entry signalling primary authorship of a single
author". It also says co-authors should be credited with Co-developed-by:,
followed immediately by their Signed-off-by:.

As written, the trailers suggest Jakub is the primary author, and that
doesn't match the From: line. The other patches in this series have the
same trailers, from "selftests: drv-net: Iperf3Runner: Support UDP and
server side results" through "selftests: drv-net: tc_flower_police: Test
policing with RSS contexts".

Could "Co-developed-by: Jakub Kicinski <kuba@xxxxxxxxxx>" be added right
before his Signed-off-by:? If Jakub wrote the patch, the From: author
could be changed to him instead.

> 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 b03a00ad0c0ba..b42ed22419ad1 100755
> --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
> +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py

[ ... ]

> @@ -36,6 +47,27 @@ def _local_prefix(cfg):
> return net
>
>
> +def _dev_addrs(cfg):
> + addrs = ip(f"-6 addr show dev {cfg.ifname}", json=True)[0]
> + return {a["local"] for a in addrs.get("addr_info", [])}
> +
> +
> +def _add_secondary_addr(cfg, want=None):
> + net = _local_prefix(cfg)
> +
> + taken = _dev_addrs(cfg)
> + hosts = range(1, min(net.num_addresses, 1 << 16))
> + for i in random.sample(hosts, len(hosts)):
> + addr = str(net[i])
> + if addr not in taken and (want is None or want(addr)):
> + break

[ ... ]

> @@ -79,6 +111,81 @@ def _ctrl_rule(cfg, i=0):

[ ... ]

> +def _check_rate(got, expect, what):
> + low, high = expect * (1 - TOLERANCE), expect * (1 + TOLERANCE)
> + ksft_ge(high, got, f"{what} above the expected {expect:.0f} Mbit/s")
> + ksft_ge(got, low, f"{what} below the expected {expect:.0f} Mbit/s")
> + return low <= got <= high

[ ... ]

> +def _dst_ip_rule(cfg):
> + dst = _add_secondary_addr(cfg)
> + return f"protocol ipv6 flower dst_ip {dst}", dst

[ ... ]

> @@ -152,11 +259,54 @@ def police_no_leak(cfg):

[ ... ]

> +def police_rate(cfg):
> + """
> + Check that UDP sent at twice the police rate to the destination IP of
> + a rule is limited to that rate.
> + """
> + _setup_clsact(cfg)
> + rule, dst = _dst_ip_rule(cfg)
> +
> + _check_baseline_rate(cfg)
> + _add_filter(cfg, rule, _police(RATE_MBIT), pref=10)
> + _check_in_hw(cfg, 10)
> +
> + got = _iperf3(cfg, dst, OFFERED_MBIT)
> + _check_rate(got, RATE_MBIT, "matching flow")

[Severity: Low]
This isn't a bug, but in this patch nothing uses the want argument of
_add_secondary_addr(). Its only caller, _dst_ip_rule(), calls
_add_secondary_addr(cfg) without one. Similarly, police_rate() is the only
caller of _check_rate() and ignores the boolean it returns.

Both get users later in the series. In "selftests: drv-net:
tc_flower_police: Test destination prefix rules", police_dst_prefix()
passes a want lambda. In "selftests: drv-net: tc_flower_police: Test
police parameters", _add_filter(..., dst=...) raises KsftFailEx based on
the return value of _check_rate().

Would it be cleaner to add the want argument and the return value in the
patches that use them?

[ ... ]

> @@ -79,6 +111,81 @@ def _ctrl_rule(cfg, i=0):
> return f"protocol ipv6 flower dst_ip {net[i + 1]}"
>
>
> +def _payload_mbit(mbit):
> + # iperf3 rates only count the UDP payload
> + return round(mbit * UDP_PAYLOAD / IP6_PKT_LEN, 3)
> +
> +
> +def _iperf3(cfg, dst_addr, bw_mbit):
> + runner = Iperf3Runner(cfg, port=rand_port(), server_ip=dst_addr)
> + server = runner.start_server(json=True)
> + done = False
> + try:
> + runner.start_client(duration=MEASURE_SEC, omit=1,
> + udp_mbit=_payload_mbit(bw_mbit),
> + length=UDP_PAYLOAD)
> + done = True
> + except CmdExitFailure as ex:
> + out = f"{ex.cmd.stderr} {ex.cmd.stdout}"
> + raise KsftFailEx(f"iperf3 failed: {out}") from ex
> + finally:
> + server.process(terminate=not done, fail=False, timeout=5)
> + return _rx_mbit(server.stdout)
> +
> +
> +def _rx_ivals(out):
> + try:
> + res = json.loads(out)
> + if "error" in res:
> + raise KsftFailEx(f"iperf3 server: {res['error']}")
> + return [(i["sum"]["seconds"],
> + i["sum"]["bytes"] * IP6_PKT_LEN / UDP_PAYLOAD)
> + for i in res["intervals"]
> + if not i["sum"].get("omitted")]
> + except (ValueError, KeyError) as ex:
> + raise KsftFailEx(f"iperf3 server output: {out}") from ex
> +
> +
> +def _rx_mbit(out):
> + ivals = _rx_ivals(out)
> + secs = sum(secs for secs, _ in ivals)
> + rx_bytes = sum(rx_bytes for _, rx_bytes in ivals)
> + return rx_bytes * 8 / secs / 1e6 if secs else 0
> +
> +
> +def _check_rate(got, expect, what):
> + low, high = expect * (1 - TOLERANCE), expect * (1 + TOLERANCE)
> + ksft_ge(high, got, f"{what} above the expected {expect:.0f} Mbit/s")
> + ksft_ge(got, low, f"{what} below the expected {expect:.0f} Mbit/s")
> + return low <= got <= high
> +
> +
> +def _check_unpoliced(got, rate_mbit, what):
> + ksft_ge(got, rate_mbit * (1 + TOLERANCE), f"{what} looks policed")
> +
> +
> +def _get_baseline(cfg):
> + if cfg.baseline is None:
> + cfg.require_ipver("6")
> + cfg.require_cmd("iperf3", local=True, remote=True)
> + cfg.baseline = _iperf3(cfg, cfg.addr_v["6"], OFFERED_MBIT)
> + ksft_pr(f"Unpoliced UDP rate {cfg.baseline:.0f} Mbit/s")
> + return cfg.baseline
> +
> +
> +def _check_baseline_rate(cfg):
> + want = OFFERED_MBIT * (1 - TOLERANCE)
> + baseline = _get_baseline(cfg)
> + if baseline < want:
> + raise KsftSkipEx(f"Baseline rate {baseline:.0f} Mbit/s too low, "
> + f"need {want:.0f} Mbit/s")
> +
> +
> +def _dst_ip_rule(cfg):
> + dst = _add_secondary_addr(cfg)
> + return f"protocol ipv6 flower dst_ip {dst}", dst
> +
> +
> def offload_flags(cfg):
> """
> Check that a skip_sw police rule is offloaded and reported in_hw, and

[Severity: Low]
What cleans up the local iperf3 server if it doesn't exit within
5 seconds here?

When the client succeeds, done is True, so server.process() is called
with terminate=False and no signal is sent to the server. If
communicate(timeout=5) in cmd._process_terminate() then expires,
subprocess.TimeoutExpired propagates out of _iperf3(). The server is
not terminated, killed or reaped, and its stdout and stderr pipes are
not closed. The terminate=True path has the same problem if iperf3 is
slow to act on SIGTERM.

ksft_run() catches the exception, runs the deferred cleanups and moves
on to the next test case. The orphaned iperf3 server can then keep
running through police_isolation and the tests added later in the
series, and possibly after the script exits.

The _iperf3_flows() helper added in "selftests: drv-net:
tc_flower_police: Test multiple policers" already handles this. On
TimeoutExpired it retries with terminate=True and then calls kill().
Could _iperf3() use the same fallback, or could the two helpers share
that logic?

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204000521.3396802-1-mohsin.bashr%40gmail.com