selftests: net: update wait mechanism for relocating netdevsim to a new ns
Subsystems (3)
PATCH 1/1 selftests: net: update wait mechanism for relocating netdevsim to a new ns
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.
--- tools/testing/selftests/net/lib/py/nsim.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/testing/selftests/net/lib/py/nsim.py +7 -4
@@ -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
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Jakub Kicinski
maintainerQuoted 7 lines · On Thu, 9 Jul 2026 16:08:07 +0000 Thaison Phan wrote:
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.
Quoted 5 lines
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.
I don't get it. I never saw it hang. And if the event is scoped udevadm settle should return immediately, rather than hang. We generally run on latest systemd udev in Fedora and CentOS. Please explain your problem better.
Quoted 5 lines
Also fixed minor bug in
wait_for_devs()where wrong exception was caught from ifget_ifnames()failed. Now the ifget_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.
Should be a separate patch
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next] selftests: net: update wait mechanism for relocating
Quoted 3 lines
I don't get it. I never saw it hang. And if the event is scoped udevadm settle should return immediately, rather than hang. We generally run on latest systemd udev in Fedora and CentOS. Please explain your problem better.
Thanks for reviewing this. I looked into my issue further. I found out when I run into the hanging problem, the machine that I run on is using an internal Linux distro that turns out to be running an old version (182) of udev before it was merged to be a part of systemd. The source code for udev I was referencing was out of date where it looks like udevadm settle relied on an internal uevent sequence number to match up with a kernel uevent sequence number. At some point I think it was a known problem that these sequence numbers could become out of sync because udev would never get uevents not tied to the default namespace. I checked the upstream udev and saw that udevadm settle was refactored, so that sequence numbers are now deprecated. This patch is only applicable for versions of udev without the refactor, so there is probably no reason to upstream it.
Quoted 1 line
Should be a separate patch
Sounds good. I'll create a separate patch for the exception fix.