Skip to contentSkip to conversation

net: openvswitch: Avoid needlessly taking the RTNL on vport destroy

PATCH In review Toke Høiland-Jørgensen 5 participants 8 messages Dec 11, 2025 – Dec 22, 2025 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: openvswitch: Avoid needlessly taking the RTNL on vport destroy

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

---
v2:
- Expand comments explaining the logic

 net/openvswitch/vport-netdev.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
net/openvswitch/vport-netdev.c +13 -4
index 91a11067e458..6574f9bcdc02 100644
@@ -160,10 +160,19 @@ void ovs_netdev_detach_dev(struct vport *vport)
 
 static void netdev_destroy(struct vport *vport)
 {
-	rtnl_lock();
-	if (netif_is_ovs_port(vport->dev))
-		ovs_netdev_detach_dev(vport);
-	rtnl_unlock();
+	/* When called from ovs_db_notify_wq() after a dp_device_event(), the
+	 * port has already been detached, so we can avoid taking the RTNL by
+	 * checking this first.
+	 */
+	if (netif_is_ovs_port(vport->dev)) {
+		rtnl_lock();
+		/* Check again while holding the lock to ensure we don't race
+		 * with the netdev notifier and detach twice.
+		 */
+		if (netif_is_ovs_port(vport->dev))
+			ovs_netdev_detach_dev(vport);
+		rtnl_unlock();
+	}
 
 	call_rcu(&vport->rcu, vport_netdev_free);
 }
Signature · 1 line
2.52.0
maintainer
#1 lore raw
Quoted 9 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

Quoted 7 lines

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

Guess the change looks good, but I’m waiting for some feedback from Adrian to see if this change makes sense. Any luck reproducing the issue it’s supposed to fix?

Cheers,

Eelco

Quoted 37 lines

---
v2:
- Expand comments explaining the logic

 net/openvswitch/vport-netdev.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
net/openvswitch/vport-netdev.c +13 -4
index 91a11067e458..6574f9bcdc02 100644
@@ -160,10 +160,19 @@ void ovs_netdev_detach_dev(struct vport *vport)
 
 static void netdev_destroy(struct vport *vport)
 {
-	rtnl_lock();
-	if (netif_is_ovs_port(vport->dev))
-		ovs_netdev_detach_dev(vport);
-	rtnl_unlock();
+	/* When called from ovs_db_notify_wq() after a dp_device_event(), the
+	 * port has already been detached, so we can avoid taking the RTNL by
+	 * checking this first.
+	 */
+	if (netif_is_ovs_port(vport->dev)) {
+		rtnl_lock();
+		/* Check again while holding the lock to ensure we don't race
+		 * with the netdev notifier and detach twice.
+		 */
+		if (netif_is_ovs_port(vport->dev))
+			ovs_netdev_detach_dev(vport);
+		rtnl_unlock();
+	}
 
 	call_rcu(&vport->rcu, vport_netdev_free);
 }
Signature · 1 line
2.52.0
#2 lore raw
Quoted 15 lines · Eelco Chaudron
Quoted 13 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

Guess the change looks good, but I’m waiting for some feedback from Adrian to see if this change makes sense.

OK.

Quoted 1 line

Any luck reproducing the issue it’s supposed to fix?

We got a report from the customer that originally reported it (who had their own reproducer) that this patch fixes their issue to the point where they can now delete ~2000 pods/node without triggering the unregister_netdevice warning at all (where before it triggered at around ~500 pod deletions). So that's encouraging :)

-Toke

maintainer Acked-by
#3 lore raw
Quoted 26 lines · Toke Høiland-Jørgensen
Quoted 15 lines · Eelco Chaudron
Quoted 13 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

Guess the change looks good, but I’m waiting for some feedback from Adrian to see if this change makes sense.

OK.

Quoted 7 lines
Quoted 1 line

Any luck reproducing the issue it’s supposed to fix?

We got a report from the customer that originally reported it (who had their own reproducer) that this patch fixes their issue to the point where they can now delete ~2000 pods/node without triggering the unregister_netdevice warning at all (where before it triggered at around ~500 pod deletions). So that's encouraging :)

That’s good news; just wanted to make sure we are not chasing a red herring :)

maintainer
#4 lore raw
Quoted 33 lines · Eelco Chaudron
Quoted 24 lines · Toke Høiland-Jørgensen
Quoted 14 lines · Eelco Chaudron
Quoted 13 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

Guess the change looks good, but I’m waiting for some feedback from Adrian to see if this change makes sense.

OK.

Quoted 7 lines
Quoted 1 line

Any luck reproducing the issue it’s supposed to fix?

We got a report from the customer that originally reported it (who had their own reproducer) that this patch fixes their issue to the point where they can now delete ~2000 pods/node without triggering the unregister_netdevice warning at all (where before it triggered at around ~500 pod deletions). So that's encouraging :)

Quoted 3 lines

That’s good news; just wanted to make sure we are not chasing a red herring :)

@Eelco: your SoB above is lacking the required <> around the email address. I'm fixing that while applying the patch, but please take care of it in the next reviews.

Thanks,

Paolo

maintainer
#5 lore raw
Quoted 34 lines · Paolo Abeni
Quoted 33 lines · Eelco Chaudron
Quoted 31 lines · Toke Høiland-Jørgensen
Quoted 14 lines · Eelco Chaudron
Quoted 13 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

Guess the change looks good, but I’m waiting for some feedback from Adrian to see if this change makes sense.

OK.

Quoted 1 line

Any luck reproducing the issue it’s supposed to fix?

We got a report from the customer that originally reported it (who had their own reproducer) that this patch fixes their issue to the point where they can now delete ~2000 pods/node without triggering the unregister_netdevice warning at all (where before it triggered at around ~500 pod deletions). So that's encouraging :)

Quoted 7 lines
Quoted 3 lines

That’s good news; just wanted to make sure we are not chasing a red herring :)

@Eelco: your SoB above is lacking the required <> around the email address. I'm fixing that while applying the patch, but please take care of it in the next reviews.

Thanks Paolo, no idea what happened here :(

Quoted 4 lines

Thanks,

Paolo

maintainer Acked-by on v2 1/1
#6 lore raw
In reply to Toke Høiland-Jørgensen
Quoted 9 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

Quoted 8 lines

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

---

LGTM,

A message that is not in the archive (sent off-list or not yet received): CAKDHXDHsdfRfaDyfzoTymsPkm=mPdFtJOA=GHb6HGx6TjvYA7w@mail.gmail.com

#8 lore raw
Quoted 4 lines · Vladimir Shebordaev

Perhaps, ovs_netdev_tunnel_destroy() is also worth to be modified this way. It is invoked as a vport destructor in similar code paths and even has a nice comment about its double duty.

In this case OVS owns the underlying tunnel device so it's less likely that someone will delete it by other means. Still, I think you're right and we could spare one RTNL lock in such case.

We can fix this in an independent patch so that Fixes points to the right commit.

Thanks.
Adrián

Quoted 33 lines

--
Regards,
Vladimir

Quoted 26 lines · Aaron Conole
Quoted 9 lines · Toke Høiland-Jørgensen

The openvswitch teardown code will immediately call ovs_netdev_detach_dev() in response to a NETDEV_UNREGISTER notification. It will then start the dp_notify_work workqueue, which will later end up calling the vport destroy() callback. This callback takes the RTNL to do another ovs_netdev_detach_port(), which in this case is unnecessary. This causes extra pressure on the RTNL, in some cases leading to "unregister_netdevice: waiting for XX to become free" warnings on teardown.

Quoted 8 lines

We can straight-forwardly avoid the extra RTNL lock acquisition by checking the device flags before taking the lock, and skip the locking altogether if the IFF_OVS_DATAPATH flag has already been unset.

Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")

---

LGTM,