net: openvswitch: Avoid needlessly taking the RTNL on vport destroy
Subsystems (3)
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.
---
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
@@ -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
Eelco Chaudron
maintainerQuoted 9 lines · Toke Høiland-Jørgensen
The openvswitch teardown code will immediately call
ovs_netdev_detach_dev()in response to aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>
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 logicnet/openvswitch/vport-netdev.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)net/openvswitch/vport-netdev.c +13
-4@@ -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
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 aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.
Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>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
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 aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>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_netdevicewarning 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 :)
Paolo Abeni
maintainerQuoted 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 aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>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_netdevicewarning 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 :)
Acked-by Eelco Chaudron [email protected]
@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
Eelco Chaudron
maintainerQuoted 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 aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.Quoted 6 lines
Quoted 3 lines
Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>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_netdevicewarning 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 :)
Acked-by Eelco Chaudron [email protected]@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
Quoted 9 lines · Toke Høiland-Jørgensen
The openvswitch teardown code will immediately call
ovs_netdev_detach_dev()in response to aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>---
LGTM,
A message that is not in the archive (sent off-list or not yet received): CAKDHXDHsdfRfaDyfzoTymsPkm=mPdFtJOA=GHb6HGx6TjvYA7w@mail.gmail.com
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,
VladimirQuoted 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 aNETDEV_UNREGISTERnotification. It will then start thedp_notify_workworkqueue, which will later end up calling the vportdestroy()callback. This callback takes the RTNL to do anotherovs_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_DATAPATHflag has already been unset.Fixes b07c26511e94 ("openvswitch: fix vport-netdev unregister")Tested-by Adrian Moreno <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>---
LGTM,
Acked-by Aaron Conole <[email protected]>