Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink
@ 2026-01-05 15:17 Yohei Kojima
  2026-01-05 15:17 ` [PATCH net v3 2/2] selftests: netdevsim: add carrier state consistency test Yohei Kojima
  2026-01-07  2:30 ` [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Yohei Kojima @ 2026-01-05 15:17 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Yohei Kojima, David S. Miller, Eric Dumazet, Paolo Abeni,
	Shuah Khan, Breno Leitao, Andrew Lunn, netdev, linux-kernel,
	linux-kselftest

This series fixes netdevsim's inconsistent behavior between carrier
and link/unlink state.

More specifically, this fixes a bug that the carrier goes DOWN although
two netdevsim were peered, depending on the order of peering and ifup.
Especially in a NetworkManager-enabled environment, netdevsim test fails
because of this.

The first patch fixes the bug itself in netdevsim/bus.c by adding
netif_carrier_on() into a proper function. The second patch adds a
regression test for this bug.

Changelog
=========
v2 -> v3:
- Rebase to the latest net/main
- patch 1:
  - Add Reviewed-by tag from Breno Leitao
  - Address the review comments from Jakub Kicinski regarding the condition
    to call netif_carrier_on()
- patch 2:
  - Solve the shellcheck warning in the test
    - Line too long error is left as is for consistency with other test
      cases
- v2: https://lore.kernel.org/netdev/cover.1767108538.git.yk@y-koj.net/

v1 -> v2:
- Rebase to the latest net/main
- Separate TFO tests from this series
- Separate netdevsim test improvement from this series
- v1: https://lore.kernel.org/netdev/cover.1767032397.git.yk@y-koj.net/

Yohei Kojima (2):
  net: netdevsim: fix inconsistent carrier state after link/unlink
  selftests: netdevsim: add carrier state consistency test

 drivers/net/netdevsim/bus.c                   |  8 +++
 .../selftests/drivers/net/netdevsim/peer.sh   | 59 +++++++++++++++++++
 2 files changed, 67 insertions(+)

-- 
2.51.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v3 2/2] selftests: netdevsim: add carrier state consistency test
  2026-01-05 15:17 [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink Yohei Kojima
@ 2026-01-05 15:17 ` Yohei Kojima
  2026-01-07  2:30 ` [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Yohei Kojima @ 2026-01-05 15:17 UTC (permalink / raw)
  To: Jakub Kicinski, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni, Shuah Khan
  Cc: Yohei Kojima, netdev, linux-kselftest, linux-kernel

This commit adds a test case for netdevsim carrier state consistency.
Specifically, the added test verifies the carrier state during the
following operations:

1. Unlink two netdevsims
2. ifdown one netdevsim, then ifup again
3. Link the netdevsims again
4. ifdown one netdevsim, then ifup again

These steps verifies that the carrier is UP iff two netdevsims are
linked and ifuped.

Signed-off-by: Yohei Kojima <yk@y-koj.net>
---
 .../selftests/drivers/net/netdevsim/peer.sh   | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/tools/testing/selftests/drivers/net/netdevsim/peer.sh b/tools/testing/selftests/drivers/net/netdevsim/peer.sh
index 7f32b5600925..f4721f7636dd 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/peer.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/peer.sh
@@ -52,6 +52,39 @@ cleanup_ns()
 	ip netns del nssv
 }
 
+is_carrier_up()
+{
+	local netns="$1"
+	local nsim_dev="$2"
+
+	test "$(ip netns exec "$netns"	\
+		cat /sys/class/net/"$nsim_dev"/carrier 2>/dev/null)" -eq 1
+}
+
+assert_carrier_up()
+{
+	local netns="$1"
+	local nsim_dev="$2"
+
+	if ! is_carrier_up "$netns" "$nsim_dev"; then
+		echo "$nsim_dev's carrier should be UP, but it isn't"
+		cleanup_ns
+		exit 1
+	fi
+}
+
+assert_carrier_down()
+{
+	local netns="$1"
+	local nsim_dev="$2"
+
+	if is_carrier_up "$netns" "$nsim_dev"; then
+		echo "$nsim_dev's carrier should be DOWN, but it isn't"
+		cleanup_ns
+		exit 1
+	fi
+}
+
 ###
 ### Code start
 ###
@@ -113,6 +146,32 @@ if [ $? -eq 0 ]; then
 	exit 1
 fi
 
+# netdevsim carrier state consistency checking
+assert_carrier_up nssv "$NSIM_DEV_1_NAME"
+assert_carrier_up nscl "$NSIM_DEV_2_NAME"
+
+echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX" > "$NSIM_DEV_SYS_UNLINK"
+
+assert_carrier_down nssv "$NSIM_DEV_1_NAME"
+assert_carrier_down nscl "$NSIM_DEV_2_NAME"
+
+ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" down
+ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" up
+
+assert_carrier_down nssv "$NSIM_DEV_1_NAME"
+assert_carrier_down nscl "$NSIM_DEV_2_NAME"
+
+echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:$NSIM_DEV_2_IFIDX" > $NSIM_DEV_SYS_LINK
+
+assert_carrier_up nssv "$NSIM_DEV_1_NAME"
+assert_carrier_up nscl "$NSIM_DEV_2_NAME"
+
+ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" down
+ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" up
+
+assert_carrier_up nssv "$NSIM_DEV_1_NAME"
+assert_carrier_up nscl "$NSIM_DEV_2_NAME"
+
 # send/recv packets
 
 tmp_file=$(mktemp)
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink
  2026-01-05 15:17 [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink Yohei Kojima
  2026-01-05 15:17 ` [PATCH net v3 2/2] selftests: netdevsim: add carrier state consistency test Yohei Kojima
@ 2026-01-07  2:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-07  2:30 UTC (permalink / raw)
  To: Yohei Kojima
  Cc: kuba, davem, edumazet, pabeni, shuah, leitao, andrew+netdev,
	netdev, linux-kernel, linux-kselftest

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  6 Jan 2026 00:17:31 +0900 you wrote:
> This series fixes netdevsim's inconsistent behavior between carrier
> and link/unlink state.
> 
> More specifically, this fixes a bug that the carrier goes DOWN although
> two netdevsim were peered, depending on the order of peering and ifup.
> Especially in a NetworkManager-enabled environment, netdevsim test fails
> because of this.
> 
> [...]

Here is the summary with links:
  - [net,v3,1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
    https://git.kernel.org/netdev/net/c/d83dddffe190
  - [net,v3,2/2] selftests: netdevsim: add carrier state consistency test
    https://git.kernel.org/netdev/net/c/75df712cddfd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-07  2:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-05 15:17 [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink Yohei Kojima
2026-01-05 15:17 ` [PATCH net v3 2/2] selftests: netdevsim: add carrier state consistency test Yohei Kojima
2026-01-07  2:30 ` [PATCH net v3 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox