]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: openvswitch: Avoid needlessly taking the RTNL on vport destroy
authorToke Høiland-Jørgensen <toke@redhat.com>
Thu, 11 Dec 2025 11:50:05 +0000 (12:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:56 +0000 (13:09 +0100)
[ Upstream commit 5498227676303e3ffa9a3a46214af96bc3e81314 ]

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")
Tested-by: Adrian Moreno <amorenoz@redhat.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Link: https://patch.msgid.link/20251211115006.228876-1-toke@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/openvswitch/vport-netdev.c

index 8e1a88f136227d6ea2e954e0c911832c3b216286..3beec619283a95212901da869de4c6ca93b4da8d 100644 (file)
@@ -154,10 +154,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);
 }