🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21290

Re: [PATCH net v2 2/3] selftests: net: py: add a bkg() timeout and kill the child when it expires

#21290
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 20:39
171 lines
14995 bytes
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
Technical Details
Message-ID: <179546636853.3135.5221989489890379101@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369748-linux-kernel-netdev=dewy.ru
References: <20261119191341.4089157-2-rjethwani@purestorage.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369748-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179546636853.3135.5221989489890379101@kernel.org>
References: <20261119191341.4089157-2-rjethwani@purestorage.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3979358"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:aEmym7wloIbsksO6WQ5Zt3z/iHU= sha256:rMQltV3ovZbWWCgy3ObD4QbnqaEqismrwepGjtXN4HY=
	sha1:pBdRi257v9VUiXMlVaNfVPjmQTM= sha256:+WJCvYFsPtMAe9Uyo825oeNm4lVfnE9xF3Dobl+uay4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 24181125DC6; Mon, 23 Nov 2026 23:39:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id r4wS2QU0KuPT;
	Mon, 23 Nov 2026 23:39:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369748-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 271C6125DC5; Mon, 23 Nov 2026 23:39:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8842D391FE; Mon, 23 Nov 2026 20:39:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795466371;
	b=YOWvQoFZEM8wdSnc57uOsbPsT3BmSdvwsF0hM+YX6vWiOZrvVfh3HuZQHwu8822r5lXn
	 jNlirk3WxcZ5KvKXaKVDoYQG/boDxN7OO6cEXPFwFE0YXOsvJ7wHWmut94lQ3Gzh26dGb
	 0czWp3Yczz8waxHiewynCRHHNDbx26U2fUfDwihVsG92wJMtdg3a/Q/PASJceKkf242ym
	 XvcT2B9jHyjgImUg2ouV5JsdPQ5OhgFkcxlS494rQtWE4DU0eQMzdYrbF2fQk9cgYwli8
	 ajimsLT3VW7rjnqfm4OuzFZaDg+CvgqlWKgwUDs6cFPmfqRWzL/fH2c+gQGO8aZYbXQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795466371;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=D0KHOZVofruhcg+Qn5VOsyQ2WExJk7PqsXpAACuiVqE=;
	b=hhDXFRn6d20N8FsjIt5OETNfkr+E71+uSDP6+/dxn4XLC9YWHyv/tCPAI5dfuo56G6IY
	 s7AhmvwZGB4o3Q0dsh/m8B4qNX1lPBKZ/DqK67Phym5U/hgA9cpkLQHb+RU23sxazgfbZ
	 cWeOYakeaZ87Kw2AimgMGDaskVmqfXSSpNOivIjgIbm33e1nZqVxiRBbM/P5q3pQfgHdy
	 VwnIVJgNiipQS+ad1uW3YMgRI3uwJz5kV7FcZ0m3lZlhyv6f3IDbebAsKHPaBiFrFbgYU
	 HFfuf8zmZ3GlxHwt38tyMiGP3nlwC6PZS1mBGskLnzowoU1OztzHd22PH2zn2ym1lxA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="MpDsk/hw";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 60C55606A326;
	Mon, 23 Nov 2026 20:39:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MpDsk/hw
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795466370;
	b=pqvKZJF9MwDXZM6PTl8D/s9ZtxtI67ttP+pGL8dicJBWK8CPadNNj1YM5XEag4wU2pcC
	 mJNCmx9EMeat1oj6TPbMz7OkCqoCmwyVamX/8/mAd3OGa1UmS8zkWnTvANCYBA7WjnfA6
	 CxVGjMbuQyYanWlbOf8aSI9ILZyx+HEmt9yxr5rhKV75deOacCZ9VivtbDK+E1mtP/sbp
	 hrff9Pk6Swcr4Ylj4cCqazh7Lva7yHU6smw88KXWtSdy1tovuE55iFjClbop8Wxf/BZrF
	 MK85XQPVU3TnvtzkuaXVjtjq6nqPpIoQDlM//XCEL9Hj0qDWkED96dJQZiIdBbGtkxg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795466370;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=D0KHOZVofruhcg+Qn5VOsyQ2WExJk7PqsXpAACuiVqE=;
	b=BvIhOi0iiqFeHK/b7dpbwOfodh4NKbmxa+O2cdcUXofhRcORX7q4vA9EMsgwfBsBesji
	 /OmiHbgL4xMsCU7NjjpKUU8pp4Q6PXE4h8V53tQYS9e5hGXmgHT8zjWgEZrlCkt8lG7Gl
	 tivyfF9u8VqRqprrOuEWovQMS90UqfILyRHmbSQ4bUWrFCDuES4U8P00t1uNMo9uLB0uT
	 JM3ihIKDy6AU//41W7LBn0i6PG2JCYqiHEMwdbM3bYSs17rc3f7VQ9Jun3zW/PIpsVlFl
	 ifwz6GBb6pxRNr8aTJ+94zAuxe9RpLYJyiAzQF1dmE2qtjaBeYpyiOfg0uxjl8DMLGA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="MpDsk/hw";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F07B606A31E;
	Mon, 23 Nov 2026 20:39:29 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2C211F000CF;
	Mon, 23 Nov 2026 20:39:28 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795466369;
	bh=D0KHOZVofruhcg+Qn5VOsyQ2WExJk7PqsXpAACuiVqE=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=MpDsk/hwN3owQGvNzZWYAKicAT0ixjii36t2u7FvQ1EgmI0kYjmTQjUQDNlw0SutF
	 AY0aLpiTywNgmri8RAif1ewAI2ZR9XSsHcsJww+n+3FwojAbrnzgBGYa7Gnc+X+WrM
	 pfVDsQLjr2bQjjjTyKqzqqUh+g08dJyTikcVwK6S9tx55ilda0VhJUzQEpCNlmJ4Ye
	 EVwTTwgztAcxZvV3iJkF4PznnP4eyMRMVZbayQrzV2yEaXIt46YCl1kI3rPJlUgbmv
	 Nekr2EWB40MysIGpiJkQAPb7q2qzrUliYQKfpwzI7guhVoM82r5t5g0JQPSDM32QMK
	 EnKWNB1JwKAHw==
X-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
X-In-Reply-To: <20261119191341.4089157-2-rjethwani@purestorage.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list