Netdev List
 help / color / mirror / Atom feed
From: Minxi Hou <houminxi@gmail.com>
To: netdev@vger.kernel.org
Cc: Aaron Conole <aconole@redhat.com>,
	Eelco Chaudron <echaudro@redhat.com>,
	Ilya Maximets <i.maximets@ovn.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
	dev@openvswitch.org, linux-kselftest@vger.kernel.org,
	Ilya Maximets <i.maximets@redhat.com>
Subject: [PATCH net-next v1 1/1] selftests/net/openvswitch: terminate namespace processes before deletion
Date: Sun,  6 Dec 2026 04:29:27 -0500	[thread overview]
Message-ID: <20261206092927.2282478-1-houminxi@gmail.com> (raw)

ovs_netns_spawn_daemon() records only the PID of the process it starts.
A daemon such as socat with the fork option can leave children behind
when cleanup terminates that PID. Deleting the namespace name does not
terminate the remaining processes, so a live child can keep the network
namespace alive after the test exits.

Send SIGTERM to the processes in each test namespace and use the existing
bounded wait before deleting its name. Keep the sweep before deletion,
while ip netns pids can still find the namespace's processes. Cleanup
remains best effort if a process does not exit within the timeout.

Fixes: 07a9e3975039 ("selftests/net/openvswitch: add SCTP flow key support and test")
Signed-off-by: Minxi Hou <houminxi@gmail.com>

---
Testing: all 19 registered OVS selftest cases passed in a fresh guest
on a reused 7.4.0-rc4-virtme kernel and matching OVS module. The suite
completed in 155.074 seconds. No matching test processes remained
during the 10-second post-suite observation; datapaths and named
namespaces were empty, and the OVS module unloaded.
The userspace sources are from this base plus the patch; the kernel
was not rebuilt from this base.

A controlled real SCTP connection reproduced the cleanup defect:
with only the new cleanup registration withdrawn, a forked listener
child remained alive for 10 seconds. The fixed and restored copies
drained the namespace. Natural withdrawal runs did not reliably
reproduce the original intermittent leak.

AI assistance: Hermes assisted with diagnosis, the cleanup helper,
test execution and this message. The task was to clean up processes
left by the OVS selftests without changing their forwarding tests.

 .../selftests/net/openvswitch/openvswitch.sh       | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh
index 21444657a04049c293ad8b875f89602eeb9218aa..01f1f56608147caeecc3c40614fc4a156cff1e7c 100755
--- a/tools/testing/selftests/net/openvswitch/openvswitch.sh
+++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh
@@ -68,6 +68,24 @@ ovs_wait() {
 	return 1
 }
 
+# Called indirectly by ovs_wait during namespace cleanup.
+# shellcheck disable=SC2329
+ovs_netns_pids_gone() {
+	[ -z "$(ip netns pids "$1" 2>/dev/null)" ]
+}
+
+# Registered as a deferred command by ovs_add_netns_and_veths.
+# shellcheck disable=SC2329
+ovs_cleanup_netns() {
+	local netns=$1
+	local pid
+
+	for pid in $(ip netns pids "$netns" 2>/dev/null); do
+		kill -TERM "$pid" 2>/dev/null || true
+	done
+	ovs_wait ovs_netns_pids_gone "$netns" || true
+}
+
 ovs_base=`pwd`
 sbxs=
 sbx_add () {
@@ -160,10 +178,12 @@ ovs_spawn_daemon() {
 	ovs_netns_spawn_daemon $sbx "_default" $*
 }
 
+# Called by test functions dispatched indirectly by run_test.
+# shellcheck disable=SC2329
 ovs_add_netns_and_veths () {
 	info "Adding netns attached: sbx:$1 dp:$2 {$3, $4, $5}"
 	ovs_sbx "$1" ip netns add "$3" || return 1
-	on_exit "ovs_sbx $1 ip netns del $3"
+	on_exit "ovs_sbx $1 ovs_cleanup_netns $3; ovs_sbx $1 ip netns del $3"
 	ovs_sbx "$1" ip link add "$4" type veth peer name "$5" || return 1
 	on_exit "ovs_sbx $1 ip link del $4 >/dev/null 2>&1"
 	ovs_sbx "$1" ip link set "$4" up || return 1

base-commit: 76c4fde2458287eb92924f35fe7888e5fc427ed5

                 reply	other threads:[~2026-12-06  9:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261206092927.2282478-1-houminxi@gmail.com \
    --to=houminxi@gmail.com \
    --cc=aconole@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=i.maximets@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=willemb@google.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