Skip to contentSkip to conversation

sefltests: netdevsim: wait for devlink instance after netns removal

PATCH Applied Jiri Pirko 3 participants 3 messages Feb 20, 2023 – Feb 21, 2023

Subsystems (4)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 sefltests: netdevsim: wait for devlink instance after netns removal

From: Jiri Pirko <[email protected]>

When devlink instance is put into network namespace and that network namespace gets deleted, devlink instance is moved back into init_ns. This is done as a part of cleanup_net() routine. Since cleanup_net() is called asynchronously from workqueue, there is no guarantee that the devlink instance move is done after "ip netns del" returns.

So fix this race by making sure that the devlink instance is present before any other operation.

Fixes b74c37fd35a2 ("selftests: netdevsim: add tests for devlink reload with resources")
---
 .../selftests/drivers/net/netdevsim/devlink.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +18 -0
index a08c02abde12..7f7d20f22207 100755
@@ -17,6 +17,18 @@ SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
 DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
 DL_HANDLE=netdevsim/$DEV_NAME
 
+wait_for_devlink()
+{
+	"$@" | grep -q $DL_HANDLE
+}
+
+devlink_wait()
+{
+	local timeout=$1
+
+	busywait "$timeout" wait_for_devlink devlink dev
+}
+
 fw_flash_test()
 {
 	RET=0
@@ -256,6 +268,9 @@ netns_reload_test()
 	ip netns del testns2
 	ip netns del testns1
 
+	# Wait until netns async cleanup is done.
+	devlink_wait 2000
+
 	log_test "netns reload test"
 }
 
@@ -348,6 +363,9 @@ resource_test()
 	ip netns del testns2
 	ip netns del testns1
 
+	# Wait until netns async cleanup is done.
+	devlink_wait 2000
+
 	log_test "resource test"
 }
 
Signature · 1 line
2.39.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 63 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

When devlink instance is put into network namespace and that network namespace gets deleted, devlink instance is moved back into init_ns. This is done as a part of cleanup_net() routine. Since cleanup_net() is called asynchronously from workqueue, there is no guarantee that the devlink instance move is done after "ip netns del" returns.

So fix this race by making sure that the devlink instance is present before any other operation.

Fixes b74c37fd35a2 ("selftests: netdevsim: add tests for devlink reload with resources")
---
 .../selftests/drivers/net/netdevsim/devlink.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +18 -1
index a08c02abde12..7f7d20f22207 100755
@@ -17,6 +17,18 @@ SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
 DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
 DL_HANDLE=netdevsim/$DEV_NAME
 
+wait_for_devlink()
+{
+       "$@" | grep -q $DL_HANDLE
+}
+
+devlink_wait()
+{
+       local timeout=$1
+
+       busywait "$timeout" wait_for_devlink devlink dev
+}
+
 fw_flash_test()
 {
        RET=0
@@ -256,6 +268,9 @@ netns_reload_test()
        ip netns del testns2
        ip netns del testns1
 
+       # Wait until netns async cleanup is done.
+       devlink_wait 2000
+
        log_test "netns reload test"
 }
 
@@ -348,6 +363,9 @@ resource_test()
        ip netns del testns2
        ip netns del testns1
 
+       # Wait until netns async cleanup is done.
+       devlink_wait 2000
+
        log_test "resource test"
 }
 
--
Quoted 2 lines

2.39.0

Looks good to me.

#2 lore raw
In reply to Jiri Pirko
This patch was applied to netdev/net.git (master) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Mon, 20 Feb 2023 14:23:36 +0100 you wrote:

From: Jiri Pirko <[email protected]>

When devlink instance is put into network namespace and that network namespace gets deleted, devlink instance is moved back into init_ns. This is done as a part of cleanup_net() routine. Since cleanup_net() is called asynchronously from workqueue, there is no guarantee that the devlink instance move is done after "ip netns del" returns.

[...]

Here is the summary with links:
- [net] sefltests: netdevsim: wait for devlink instance after netns removal

    https://git.kernel.org/netdev/net/c/f922c7b1c1c4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html