* [PATCH net v3 1/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 ` 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
2 siblings, 0 replies; 4+ 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, Breno Leitao
Cc: Yohei Kojima, Andrew Lunn, netdev, linux-kernel
This patch fixes the edge case behavior on ifup/ifdown and
linking/unlinking two netdevsim interfaces:
1. unlink two interfaces netdevsim1 and netdevsim2
2. ifdown netdevsim1
3. ifup netdevsim1
4. link two interfaces netdevsim1 and netdevsim2
5. (Now two interfaces are linked in terms of netdevsim peer, but
carrier state of the two interfaces remains DOWN.)
This inconsistent behavior is caused by the current implementation,
which only cares about the "link, then ifup" order, not "ifup, then
link" order. This patch fixes the inconsistency by calling
netif_carrier_on() when two netdevsim interfaces are linked.
This patch fixes buggy behavior on NetworkManager-based systems which
causes the netdevsim test to fail with the following error:
# timeout set to 600
# selftests: drivers/net/netdevsim: peer.sh
# 2025/12/25 00:54:03 socat[9115] W address is opened in read-write mode but only supports read-only
# 2025/12/25 00:56:17 socat[9115] W connect(7, AF=2 192.168.1.1:1234, 16): Connection timed out
# 2025/12/25 00:56:17 socat[9115] E TCP:192.168.1.1:1234: Connection timed out
# expected 3 bytes, got 0
# 2025/12/25 00:56:17 socat[9109] W exiting on signal 15
not ok 13 selftests: drivers/net/netdevsim: peer.sh # exit=1
This patch also solves timeout on TCP Fast Open (TFO) test in
NetworkManager-based systems because it also depends on netdevsim's
carrier consistency.
Fixes: 1a8fed52f7be ("netdevsim: set the carrier when the device goes up")
Signed-off-by: Yohei Kojima <yk@y-koj.net>
Reviewed-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netdevsim/bus.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index 70e8c38ddad6..d16b95304aa7 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -332,6 +332,11 @@ static ssize_t link_device_store(const struct bus_type *bus, const char *buf, si
rcu_assign_pointer(nsim_a->peer, nsim_b);
rcu_assign_pointer(nsim_b->peer, nsim_a);
+ if (netif_running(dev_a) && netif_running(dev_b)) {
+ netif_carrier_on(dev_a);
+ netif_carrier_on(dev_b);
+ }
+
out_err:
put_net(ns_b);
put_net(ns_a);
@@ -381,6 +386,9 @@ static ssize_t unlink_device_store(const struct bus_type *bus, const char *buf,
if (!peer)
goto out_put_netns;
+ netif_carrier_off(dev);
+ netif_carrier_off(peer->netdev);
+
err = 0;
RCU_INIT_POINTER(nsim->peer, NULL);
RCU_INIT_POINTER(peer->peer, NULL);
--
2.51.2
^ permalink raw reply related [flat|nested] 4+ 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 ` [PATCH net v3 1/2] " 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
2 siblings, 0 replies; 4+ 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] 4+ 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 1/2] " 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
2 siblings, 0 replies; 4+ 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] 4+ messages in thread