* [PATCH net v2 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink
@ 2025-12-30 16:03 yk
2025-12-30 16:03 ` [PATCH net v2 1/2] " yk
2025-12-30 16:03 ` [PATCH net v2 2/2] selftests: netdevsim: add carrier state consistency test yk
0 siblings, 2 replies; 5+ messages in thread
From: yk @ 2025-12-30 16:03 UTC (permalink / raw)
To: Jakub Kicinski, Andrew Lunn, netdev
Cc: Yohei Kojima, David S. Miller, Eric Dumazet, Paolo Abeni,
Shuah Khan, Breno Leitao, linux-kernel, linux-kselftest
From: Yohei Kojima <yk@y-koj.net>
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
=========
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 | 6 ++
.../selftests/drivers/net/netdevsim/peer.sh | 63 +++++++++++++++++++
2 files changed, 69 insertions(+)
--
2.51.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
2025-12-30 16:03 [PATCH net v2 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink yk
@ 2025-12-30 16:03 ` yk
2025-12-31 10:16 ` Breno Leitao
2025-12-30 16:03 ` [PATCH net v2 2/2] selftests: netdevsim: add carrier state consistency test yk
1 sibling, 1 reply; 5+ messages in thread
From: yk @ 2025-12-30 16:03 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
From: Yohei Kojima <yk@y-koj.net>
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>
---
drivers/net/netdevsim/bus.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index 70e8c38ddad6..fa94c680c92a 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -332,6 +332,9 @@ 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);
+ netif_carrier_on(dev_a);
+ netif_carrier_on(dev_b);
+
out_err:
put_net(ns_b);
put_net(ns_a);
@@ -381,6 +384,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] 5+ messages in thread
* [PATCH net v2 2/2] selftests: netdevsim: add carrier state consistency test
2025-12-30 16:03 [PATCH net v2 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink yk
2025-12-30 16:03 ` [PATCH net v2 1/2] " yk
@ 2025-12-30 16:03 ` yk
1 sibling, 0 replies; 5+ messages in thread
From: yk @ 2025-12-30 16:03 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
From: Yohei Kojima <yk@y-koj.net>
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 | 63 +++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/tools/testing/selftests/drivers/net/netdevsim/peer.sh b/tools/testing/selftests/drivers/net/netdevsim/peer.sh
index 7f32b5600925..4ca994d2aa31 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/peer.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/peer.sh
@@ -52,6 +52,43 @@ cleanup_ns()
ip netns del nssv
}
+is_carrier_up()
+{
+ local netns="$1"
+ local nsim_dev="$2"
+
+ # 0: DOWN
+ # 1: UP
+ local is_up=$(ip netns exec "$netns" \
+ cat /sys/class/net/"$nsim_dev"/carrier 2>/dev/null)
+
+ test "$is_up" -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 +150,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] 5+ messages in thread
* Re: [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
2025-12-30 16:03 ` [PATCH net v2 1/2] " yk
@ 2025-12-31 10:16 ` Breno Leitao
2025-12-31 16:06 ` Yohei Kojima
0 siblings, 1 reply; 5+ messages in thread
From: Breno Leitao @ 2025-12-31 10:16 UTC (permalink / raw)
To: yk
Cc: Jakub Kicinski, Andrew Lunn, David S. Miller, Eric Dumazet,
Paolo Abeni, Andrew Lunn, netdev, linux-kernel
Hello Yohei,
On Wed, Dec 31, 2025 at 01:03:29AM +0900, yk@y-koj.net wrote:
> From: Yohei Kojima <yk@y-koj.net>
>
> 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.)
That seems a real issue, in fact. The carriers are only getting up when
opening the device, not when linking. Thus, this patch makes sense to
me.
> 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>
Thanks for the fix!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
2025-12-31 10:16 ` Breno Leitao
@ 2025-12-31 16:06 ` Yohei Kojima
0 siblings, 0 replies; 5+ messages in thread
From: Yohei Kojima @ 2025-12-31 16:06 UTC (permalink / raw)
To: Breno Leitao
Cc: Jakub Kicinski, Andrew Lunn, David S. Miller, Eric Dumazet,
Paolo Abeni, Andrew Lunn, netdev, linux-kernel
On Wed, Dec 31, 2025 at 02:16:53AM -0800, Breno Leitao wrote:
> Hello Yohei,
>
> On Wed, Dec 31, 2025 at 01:03:29AM +0900, yk@y-koj.net wrote:
> > From: Yohei Kojima <yk@y-koj.net>
> >
> > 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.)
>
> That seems a real issue, in fact. The carriers are only getting up when
> opening the device, not when linking. Thus, this patch makes sense to
> me.
>
> > 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>
Thank you for the review!
>
> Thanks for the fix!
When I encountered this bug, I could easily identify where to fix thanks
to your previous commit. Thanks again for your support!
Best regards,
Yohei Kojima
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-31 16:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-30 16:03 [PATCH net v2 0/2] net: netdevsim: fix inconsistent carrier state after link/unlink yk
2025-12-30 16:03 ` [PATCH net v2 1/2] " yk
2025-12-31 10:16 ` Breno Leitao
2025-12-31 16:06 ` Yohei Kojima
2025-12-30 16:03 ` [PATCH net v2 2/2] selftests: netdevsim: add carrier state consistency test yk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).