Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Thaison Phan <thaisonphan@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Shuah Khan <shuah@kernel.org>
Cc: Fengyuan Gong <gfengyuan@google.com>,
	Stan Iliev <stani@google.com>,  Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Petr Machata <petrm@nvidia.com>,
	 netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	Thaison Phan <thaisonphan@google.com>
Subject: [PATCH net-next] selftests: net: update wait mechanism for relocating netdevsim to a new ns
Date: Thu,  9 Jul 2026 16:08:07 +0000	[thread overview]
Message-ID: <20260709160807.23650-1-thaisonphan@google.com> (raw)

When netdevsim devices are reloaded into a non-default network namespace
via 'devlink dev reload', the host's udev daemon does not receive the
subsequent device creation events since it is generally associated to the
default network namespace, so the host udevd queue never officially clears.
As a result, running 'udevadm settle' blocks indefinitely and eventually
times out.

Fixed this by bypassing 'udevadm settle' when a namespace ('ns') is
provided by utilizing the namespace-aware 'self.wait_for_netdevs()'
helper to poll the namespace's sysfs until the interfaces are visible.
For host-only configurations (where 'ns' is None), preserve the original
'udevadm settle' behavior to ensure udev renaming rules are completed.

Also fixed minor bug in wait_for_devs() where wrong exception was caught
from if get_ifnames() failed. Now the if get_ifnames() results in a
command failure exception, wait_for_devs() will catch the exception and
set an empty list for the interface names rather than the exception
propogating upward.

Tested that tools/testing/selftests/drivers/net/ping.py and
tools/testing/selftests/drivers/net/psp.py still pass when using
software network devices in a QEMU x86_64 environment.

Signed-off-by: Thaison Phan <thaisonphan@google.com>
---
 tools/testing/selftests/net/lib/py/nsim.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py
index 7c640ed64c0b..a01491c2d1b6 100644
--- a/tools/testing/selftests/net/lib/py/nsim.py
+++ b/tools/testing/selftests/net/lib/py/nsim.py
@@ -6,7 +6,7 @@ import os
 import random
 import re
 import time
-from .utils import cmd, ip
+from .utils import cmd, ip, CmdExitFailure
 
 
 class NetdevSim:
@@ -76,8 +76,11 @@ class NetdevSimDev:
         if ns:
             cmd(f"devlink dev reload netdevsim/netdevsim{addr} netns {ns.name}")
             self.ns = ns
-
-        cmd("udevadm settle", ns=self.ns)
+            # udev daemon is not guaranteed to get notified of netdevs being created
+            # when in a new netns, so poll until we see the netdevs appear.
+            self.wait_for_netdevs(port_count)
+        else:
+            cmd("udevadm settle", ns=self.ns)
         ifnames = self.get_ifnames()
 
         self.dfs_dir = "/sys/kernel/debug/netdevsim/netdevsim%u/" % addr
@@ -116,7 +119,7 @@ class NetdevSimDev:
         while True:
             try:
                 ifnames = self.get_ifnames()
-            except FileNotFoundError as e:
+            except CmdExitFailure:
                 ifnames = []
             if len(ifnames) == port_count:
                 break
-- 
2.55.0.795.g602f6c329a-goog


                 reply	other threads:[~2026-07-09 16:08 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=20260709160807.23650-1-thaisonphan@google.com \
    --to=thaisonphan@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gfengyuan@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=shuah@kernel.org \
    --cc=stani@google.com \
    --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