* Re: [PATCH net v3 5/9] selftests: net: py: reap commands that fail to report ready
[not found] <20261204235642.36653-6-rjethwani@purestorage.com>
@ 2026-12-06 0:23 ` netdev-bot+sashiko
0 siblings, 0 replies; only message in thread
From: netdev-bot+sashiko @ 2026-12-06 0:23 UTC (permalink / raw)
To: rjethwani
Cc: netdev, stable, john.fastabend, kuba, sd, davem, edumazet, pabeni,
willemb, horms, alice.kernel, tariqt
Thank you for your contribution! Sashiko AI review found 8 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 5
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] The new branch in bkg.__exit__() (utils.py lines 411-422)
catches and only prints a background command's failure whenever any…
- [Medium] cmd.__init__() starts readiness commands with
`start_new_session=self._own_pgrp` (line 120), which calls setsid() in…
- [Medium] selftests: net: py: 20s cancel stall for ksft_wait helpers in
bkg.__exit__()
- [Low] cmd._cleanup_quietly() prints a cleanup failure with a single
print(f"# Warning: ... {type(e).__name__}: {e}"), so only the first…
- [Low] bkg.__init__() still prints "combining shell and terminate is
risky!
- [Low] cmd._kill_group() calls os.killpg(self.proc.pid, sig) with no
check of whether the group leader has already been reaped or the group…
- [Low] On the normal teardown path of an own-process-group command
(bkg.__exit__ with ex_type None, then process(terminate=False), then…
- [Low] Several interrupt windows are not covered by any cleanup guard.
--
selftests: net: py: reap commands that fail to report ready
This patch gives readiness-enabled commands in the net selftest Python
library their own session and process group. It kills that group when the
command times out, closes the ready FD, or is interrupted. It also adds
bounded output draining, delays closing the ksft_wait pipe until teardown,
switches fd_read_timeout() to poll(), and makes bkg.__exit__() suppress
cleanup failures while another exception is propagating.
> diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
> index 1727bc4180733..9edfc4f88621c 100644
> --- a/tools/testing/selftests/net/lib/py/utils.py
> +++ b/tools/testing/selftests/net/lib/py/utils.py
[ ... ]
> @@ -84,26 +109,207 @@ class cmd:
> pass_fds.append(ready_fd)
> env["KSFT_READY_FD"] = str(ready_fd)
>
> + # A command that reports ready leads its own process group, so
> + # that _reap_unready() and _kill_leftovers() can stop what it
> + # started too. Terminal signals then no longer reach it: on
> + # Ctrl-C, KeyboardInterrupt here leads to the same cleanup.
> + self._own_pgrp = ksft_ready is not None
> self.proc = subprocess.Popen(comm, shell=shell, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE, pass_fds=pass_fds,
> - env=env)
> + env=env,
> + start_new_session=self._own_pgrp)
[Severity: Medium]
start_new_session makes the child call setsid(). That takes the command
and its workers out of the terminal's process group, and also out of the
test runner's group and session. Is that trade-off intended?
kselftest/runner.sh runs each test through tap_timeout():
/usr/bin/timeout --foreground "$kselftest_timeout" \
/usr/bin/timeout "$kselftest_timeout" $1
The inner timeout has no --foreground, so when it expires it signals its
whole process group. Before this patch, readiness helpers were in that
group and got the SIGTERM directly. SIGHUP, SIGINT and SIGQUIT sent to the
foreground group reached them too.
Now they only stop if Python unwinds into bkg.__exit__() or
_reap_cancelled(). The runner timeout itself still reaches Python, which
raises KsftTerminate and cleans up.
What stops the helpers if the interpreter dies without unwinding? Examples
are SIGHUP on an ssh hangup, SIGQUIT, SIGKILL of the test process, a
harness killing the process group, or an interpreter crash.
ksft_wait helpers may still exit on EOF of the wait pipe. ksft_ready-only
helpers have no such pipe, for example in toeplitz.py:
with bkg(" ".join(rx_cmd), ksft_ready=True, exit_wait=True) as rx_proc:
gro_lib.py and gro_stats.py use the same pattern. Could those helpers, and
any wrapper workers, now outlive the test and stay bound to the device or
port?
The in-code comment only mentions terminal signals. The commit message
doesn't mention the new session or the change to group signals.
> if ksft_wait is not None:
> os.close(wait_fd)
> if ksft_ready is not None:
> os.close(ready_fd)
> - msg = fd_read_timeout(rfd, ksft_wait)
> - os.close(rfd)
> + timed_out = False
> + try:
> + msg = fd_read_timeout(rfd, ksft_wait)
[Severity: Low]
Are there interrupt windows around this try block that no cleanup guard
covers? The command now lives in its own session. A Ctrl-C or runner
SIGTERM in these windows no longer reaches the child as well, so nothing
reaps it:
1) KeyboardInterrupt or KsftTerminate while subprocess.Popen() waits on
its exec-status pipe. CPython re-raises without killing the forked
child, and self.proc is never assigned.
2) The os.close(wait_fd), os.close(ready_fd) and timed_out = False
statements before the try.
3) After a successful ready message, the rest of cmd.__init__() and
bkg.__init__() before __enter__() runs.
4) The time between getting a bkg back from a helper such as setup_xsk()
in xsk_reconfig.py and entering the caller's with block.
In these cases _reap_unready(), _kill_leftovers() and bkg.__exit__() never
run. A ksft_ready-only helper has no wait-pipe EOF to make it exit, and
rfd, ready_fd and ksft_term_fd leak too.
The windows are short. Still, the commit message says the patch was
"Tested locally with ... Ctrl-C during readiness and teardown", and
readiness only partly covers these adjacent windows.
[ ... ]
> + def _cleanup_quietly(self, func, *args, **kwargs):
> + """Run a cleanup step while an exception is propagating.
> +
> + Report a failure instead of raising it, which would replace that
> + exception. A second interruption still propagates.
> + """
> + try:
> + func(*args, **kwargs)
> + except Exception as e:
> + print(f"# Warning: cleanup of {self.comm!r} failed: "
> + f"{type(e).__name__}: {e}")
[Severity: Low]
Only the first line of this message gets the '#' prefix. Can this put
unprefixed helper output into the TAP stream?
CmdExitFailure and CmdInitFailure build their message as:
super().__init__(msg + "\n" + repr(cmd_obj))
cmd.__repr__() puts the command's STDOUT and STDERR on the following
lines, indented with spaces rather than '#'.
ksft_run() prints exceptions through ksft_pr() with a per-line prefix.
With this patch, bkg.__exit__() sends process() through
_cleanup_quietly(), so a CmdExitFailure ends up in this print() instead.
runner.sh pipes output through tap_prefix, so this mostly shows when a
test is run standalone. Should every line get the '#' prefix, as ksft_pr()
does?
[ ... ]
> + def _kill_group(self, sig):
> + """Signal the process group the command leads.
> +
> + The group outlives the command while any of its descendants are
> + left in it, so this reaches them after the command is reaped too.
> + """
> + try:
> + os.killpg(self.proc.pid, sig)
> + except ProcessLookupError:
> + pass
[Severity: Low]
Could this signal an unrelated process group? os.killpg() runs without
checking whether the leader is still unreaped or whether the group has
any members left. Several callers reach it after the leader has been
reaped:
1) _collect_reaped() sends SIGKILL right after _drain_until_exit(), whose
self.proc.poll() loop normally reaps the leader. It also does so when
_reap_unready() or _reap_cancelled() found the leader already reaped.
2) _kill_leftovers() sends SIGKILL before it checks returncode. By then
communicate() in _process_terminate() may already have reaped the
leader, for example if decode("utf-8") raised.
3) _process_terminate() now calls _kill_group(signal.SIGTERM) for
own-pgrp commands, even if self.proc.poll() in bkg.__exit__() already
reaped the leader.
Popen.terminate(), which _process_terminate() used before, skips the
signal once returncode is set, to avoid PID reuse.
If the group is empty and its PID has been reused by a new group leader,
that group would get SIGTERM or SIGKILL. Only ProcessLookupError is
handled. PID reuse inside such a short window is unlikely, but nothing
here rules it out.
[ ... ]
> def _process_terminate(self, terminate, timeout):
> if terminate:
> - self.proc.terminate()
> + if self._own_pgrp:
> + self._kill_group(signal.SIGTERM)
> + else:
> + self.proc.terminate()
[Severity: Low]
SIGTERM now goes to the whole group for own-pgrp commands. Is the warning
in bkg.__init__() still accurate for them?
if shell and self.terminate:
print("# Warning: combining shell and terminate is risky!")
print("# SIGTERM may not reach the child on zsh/ksh!")
Take bkg(..., shell=True, ksft_ready=True) with no exit_wait or
ksft_wait. self.terminate is set and the warning prints, yet os.killpg()
now delivers SIGTERM to the shell's children. No in-tree caller combines
these today.
> stdout, stderr = self.proc.communicate(timeout=timeout)
[Severity: Low]
Should this path also kill whatever is left of the group? On a normal
teardown of an own-pgrp command, bkg.__exit__() runs with no exception,
calls process(), and this communicate() succeeds. Nothing then sends the
final group SIGKILL that _collect_reaped() and _kill_leftovers() send.
Workers of a readiness wrapper that redirected their own output don't keep
communicate() waiting. No TimeoutExpired fires, so _kill_leftovers() never
runs.
Leaving such workers behind on a normal exit predates this patch. Before,
though, they stayed in Python's process group, so a later Ctrl-C or
runner group SIGTERM reached them. Now they sit in a separate session that
nothing signals. No in-tree readiness helper uses such a wrapper today.
> self.stdout = stdout.decode("utf-8")
> self.stderr = stderr.decode("utf-8")
[ ... ]
> @@ -202,8 +408,18 @@ class bkg(cmd):
> # since forcing termination silences failures with fail=None
> if self.proc.poll() is None:
> terminate = terminate or (self._exit_wait and ex_type is not None)
> - return self.process(terminate=terminate, fail=self.check_fail,
> - expect_fail=self.expect_fail)
> + if ex_type is None:
> + return self.process(terminate=terminate, fail=self.check_fail,
> + expect_fail=self.expect_fail)
> + # Cancelled, e.g. by Ctrl-C: stop the command and what it started,
> + # without replacing the exception in flight.
> + if self._own_pgrp:
> + self._cleanup_quietly(self._reap_cancelled, terminate, 20)
> + else:
> + self._cleanup_quietly(self.process, terminate=terminate,
> + fail=self.check_fail,
> + expect_fail=self.expect_fail)
> + return None
[Severity: Medium]
For a ksft_wait command, can a cancelled bkg() now stall for 20
seconds before anything stops the helper?
bkg.__init__() sets self.terminate to False whenever ksft_wait is
given, and self._exit_wait is False unless exit_wait was passed. So
terminate stays False in __exit__() even with an exception in flight,
and _reap_cancelled() runs with terminate=False and timeout=20.
It writes to ksft_term_fd and skips the group SIGTERM. Then
_drain_until_exit() waits the full 20 seconds before
_collect_reaped() sends SIGKILL.
The wait pipe write only helps a helper that is already sitting in
ksft_wait(). napi_id.py runs:
with bkg(listen_cmd, ksft_wait=3) as server:
and then connects to it with socat from cfg.remote. napi_id_helper
calls ksft_ready() and then blocks in accept() and read() before it
reaches ksft_wait(). The remote socat may fail, or the user may hit
Ctrl-C, before the peer has connected. In either case the helper never
reads KSFT_WAIT_FD.
Before this patch, the helper shared Python's process group. Ctrl-C
and the runner's group SIGTERM reached it directly, so it died right
away. With start_new_session it is in its own session, and the only
thing that ends it is the SIGKILL 20 seconds later. A foreground
failure also goes from the 5 second default of process() to 20
seconds.
On a runner timeout, KsftTerminate unwinds into this path, and
teardown blocks for 20 seconds per such helper. If the test process is
killed in that window, the defer queue never runs. The helper's group
is then left in a session that nothing else signals.
Should _reap_cancelled() send SIGTERM to the group whenever an
exception is in flight, as exit_wait commands already get? Or should
it use a much shorter grace period than 20 seconds?
[Severity: Medium]
This branch runs for any exception in flight, not just an interruption. It
also covers commands without their own process group. Is that intended?
Before this patch, a CmdExitFailure, CmdExitZeroFailure or TimeoutExpired
from process() replaced the in-flight exception, and ksft_run() reported
FAIL. Now _cleanup_quietly() catches Exception and only prints a warning.
Take a test body inside with bkg(..., ksft_wait=N), or any
bkg(fail=True), that raises KsftSkipEx or KsftXfailEx after the helper
exited non-zero. ksft_run() now reports SKIP or XFAIL instead of FAIL:
except KsftSkipEx as e:
comment = "SKIP " + str(e)
cnt_key = 'skip'
except KsftXfailEx as e:
comment = "XFAIL " + str(e)
cnt_key = 'xfail'
The else branch also catches remote host= commands and plain local bkg()
users. The commit message only says:
Clean up the group on interruption without masking the original
exception.
Could the commit message describe this change in reported results? Or
could the suppression be limited to interruptions such as
KeyboardInterrupt and KsftTerminate?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204235642.36653-1-rjethwani%40purestorage.com
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-06 0:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261204235642.36653-6-rjethwani@purestorage.com>
2026-12-06 0:23 ` [PATCH net v3 5/9] selftests: net: py: reap commands that fail to report ready netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox