[PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink

yk@y-koj.net posted 2 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
Posted by yk@y-koj.net 1 month, 1 week ago
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
Re: [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
Posted by Jakub Kicinski 1 month ago
On Wed, 31 Dec 2025 01:03:29 +0900 yk@y-koj.net wrote:
> +	netif_carrier_on(dev_a);
> +	netif_carrier_on(dev_b);

	if (netif_running(dev_a) && netif_running(dev_b)) {
		/// your code
	}

right? If one side is down there should be no carrier.
-- 
pw-bot: cr
Re: [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
Posted by Yohei Kojima 1 month ago
On Sun, Jan 04, 2026 at 10:54:22AM -0800, Jakub Kicinski wrote:
> On Wed, 31 Dec 2025 01:03:29 +0900 yk@y-koj.net wrote:
> > +	netif_carrier_on(dev_a);
> > +	netif_carrier_on(dev_b);
> 
> 	if (netif_running(dev_a) && netif_running(dev_b)) {
> 		/// your code
> 	}
> 
> right? If one side is down there should be no carrier.

That's right. I have updated the first patch with netif_running()
checks accordingly.

Here is the v3 series including the fix:
https://lore.kernel.org/netdev/cover.1767624906.git.yk@y-koj.net/T/

Thank you,
Yohei Kojima

> -- 
> pw-bot: cr
Re: [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
Posted by Breno Leitao 1 month, 1 week ago
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!
Re: [PATCH net v2 1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
Posted by Yohei Kojima 1 month, 1 week ago
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