From: netdev-bot+sashiko@kernel.org
To: rjethwani@purestorage.com
Cc: netdev@vger.kernel.org, stable@vger.kernel.org,
john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net,
davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
horms@kernel.org, tariqt@nvidia.com, alice.kernel@fastmail.im
Subject: Re: [PATCH net v2 2/3] selftests: net: py: add a bkg() timeout and kill the child when it expires
Date: Mon, 23 Nov 2026 20:39:28 +0000 [thread overview]
Message-ID: <179546636853.3135.5221989489890379101@kernel.org> (raw)
In-Reply-To: <20261119191341.4089157-2-rjethwani@purestorage.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 3
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] In tools/testing/selftests/net/lib/py/utils.py,
cmd._process_terminate() handles a communicate() timeout by calling…
- [Medium] In cmd._process_terminate(), when the second
communicate(timeout=1) times out after self.proc.kill(), the code…
- [Low] The commit message describes a bkg()-only change, but the
modified helper cmd._process_terminate() is shared.
- [Low] The new comment in cmd._process_terminate() says "bkg() with
exit_wait or ksft_wait never sends one [terminate()]".
- [Low] The new comments in cmd._process_terminate() describe which
backends leave processes behind after kill().
--
selftests: net: py: add a bkg() timeout and kill the child when it expires
This adds a timeout argument to bkg() for its exit-time wait. It also
changes cmd._process_terminate() so that, when communicate() times out,
the child gets SIGKILL before TimeoutExpired is re-raised. The goal is to
stop a timed-out background command from outliving the devices and
namespaces the test tears down.
> diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
> index 1727bc4180733..7a3fc39db3348 100644
> --- a/tools/testing/selftests/net/lib/py/utils.py
> +++ b/tools/testing/selftests/net/lib/py/utils.py
> @@ -104,13 +104,32 @@ class cmd:
> def _process_terminate(self, terminate, timeout):
> if terminate:
> self.proc.terminate()
> - stdout, stderr = self.proc.communicate(timeout=timeout)
> + timed_out = None
> + try:
> + stdout, stderr = self.proc.communicate(timeout=timeout)
> + except subprocess.TimeoutExpired as exc:
> + # terminate() is only a request, and bkg() with exit_wait or
> + # ksft_wait never sends one, so kill rather than leave the child
[Severity: Low]
Is this comment accurate for exit_wait? When the with-body raises and the
child is still running, bkg.__exit__() in this same file does send
terminate for an exit_wait bkg():
if self.proc.poll() is None:
terminate = terminate or (self._exit_wait and ex_type is not None)
Callers can also call process(terminate=True) on an exit_wait bkg()
directly. The next patch in the series does this in run_tls_test() with
pending.process(terminate=True, ...).
The statement seems to hold only for ksft_wait, and for exit_wait when no
exception is in flight.
> + # running. That does not stop a command run over ssh on the
> + # remote; it needs a bound of its own.
> + self.proc.kill()
[Severity: Medium]
Does this kill() reach the process that is actually doing the work?
Popen.kill() sends SIGKILL only to the direct child pid. cmd.__init__()
creates the Popen without start_new_session or a process group, so the
whole tree can't be killed with os.killpg().
In several setups the workload is not the direct child:
remote_ssh.py Remote.cmd():
return subprocess.Popen(["ssh", "-q", self.name, comm],
Here only the local ssh client is killed, and the remote command keeps
running.
remote_netns.py Remote.cmd():
return subprocess.Popen(["ip", "netns", "exec", self.name, "bash", "-c", comm],
With compound commands (pipelines, ;, &&, or loops such as the for loop in
rss_flow_label.py), bash forks children that survive SIGKILL to bash. The
same is true of bkg(shell=True) with a compound command.
In these cases the inner except branch below reaps the dead direct child,
drops the output and re-raises. The workload is still alive when the
caller's defer/teardown runs. Isn't that the same ordering problem the
commit message says this patch fixes?
The code comment mentions the ssh case, but the commit message doesn't
mention any limitation. Would a complete local fix need start_new_session
plus os.killpg()?
> + try:
> + stdout, stderr = self.proc.communicate(timeout=1)
> + except subprocess.TimeoutExpired:
> + # A grandchild (shell=True, ssh) still holds the pipes.
[Severity: Low]
Should this comment, and the ssh comment above it, also mention the
remote_netns backend? remote_netns.py Remote.cmd() wraps every remote
command in ip netns exec <ns> bash -c comm. The forked parts of compound
commands can survive kill(), keep the pipes open, and take this same path
while the workload keeps running inside the namespace.
> + self.proc.wait()
[Severity: Medium]
Can this wait() block forever? It has no timeout. The comment assumes that
only a grandchild can still hold the pipes here, but the direct child may
still be alive too.
SIGKILL doesn't act on a task in uninterruptible sleep until the task
leaves that state. Two examples: an ip command blocked in
mutex_lock(&rtnl_mutex) while RTNL is held indefinitely, or ip link del
stuck in the msleep() loop of netdev_wait_allrefs_any() because of a
leaked netdev refcount.
In that case the child still holds its own stdout/stderr, so
communicate(timeout=1) times out. wait() then blocks for as long as the
task stays in D state.
Before this patch, _process_terminate() always returned or raised
TimeoutExpired within timeout. Now the harness hangs instead of reporting
a failure. ksft_run can't record the failure, run defer() cleanup, or move
on to later cases.
The helper is shared, so this affects foreground cmd() as well as bkg().
Would a bounded wait be safer here?
> + stdout, stderr = b"", b""
> + timed_out = exc
> +
> self.stdout = stdout.decode("utf-8")
> self.stderr = stderr.decode("utf-8")
> self.proc.stdout.close()
> self.proc.stderr.close()
> self.ret = self.proc.returncode
>
> + if timed_out:
> + raise timed_out
> +
[Severity: Low]
The commit message describes a change to bkg() only, but
_process_terminate() is shared. Foreground cmd() reaches it through
cmd.__init__() when background is False:
if not background:
self.process(terminate=False, fail=fail, expect_fail=expect_fail,
timeout=timeout)
The ksft_ready init-failure path also calls it directly with timeout=1.
With this patch, any foreground cmd() that hits its timeout now gets
SIGKILL, and ret/stdout/stderr are filled in before TimeoutExpired is
re-raised. Before, the child was left running and those fields stayed
None.
No in-tree caller seems to rely on the old behaviour. Could the commit
message mention this change?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119191341.4089157-1-rjethwani%40purestorage.com
next prev parent reply other threads:[~2026-11-23 20:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:13 [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output Rishikesh Jethwani
2026-11-19 19:13 ` [PATCH net v2 2/3] selftests: net: py: add a bkg() timeout and kill the child when it expires Rishikesh Jethwani
2026-11-23 20:39 ` netdev-bot+sashiko [this message]
2026-11-19 19:13 ` [PATCH net v2 3/3] selftests: net: add TLS offload over bond tests Rishikesh Jethwani
2026-11-23 20:39 ` netdev-bot+sashiko
2026-11-19 19:18 ` [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output netdev-bot+sinfo
2026-11-23 20:39 ` 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=179546636853.3135.5221989489890379101@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=alice.kernel@fastmail.im \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rjethwani@purestorage.com \
--cc=sd@queasysnail.net \
--cc=stable@vger.kernel.org \
--cc=tariqt@nvidia.com \
/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