net: vrf: switch to synchronize_net() when releasing routes
Subsystems (3)
PATCH 1/1 net: vrf: switch to synchronize_net() when releasing routes
From: Li RongQing <[email protected]>
Replace synchronize_rcu() with synchronize_net() in vrf_rtable_release() and vrf_rt6_release().
synchronize_net() is RTNL-aware and can use the more efficient synchronize_rcu_expedited() when the RTNL lock is held, avoiding potentially long wait times for a standard RCU grace period.
Since these release functions are called during device teardown where the RTNL lock is typically held, this change reduces the time spent in RTNL critical sections and speeds up VRF device deletion.
--- drivers/net/vrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/vrf.c +2 -2
@@ -755,7 +755,7 @@ static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf)struct dst_entry *dst;RCU_INIT_POINTER (vrf->rt6,NULL ); -synchronize_rcu (); +synchronize_net ();/* move dev in dst's to loopback so this VRF device can be deleted * - based on dst_ifdown
@@ -1002,7 +1002,7 @@ static void vrf_rtable_release(struct net_device *dev, struct net_vrf *vrf)struct dst_entry *dst;RCU_INIT_POINTER (vrf->rth,NULL ); -synchronize_rcu (); +synchronize_net ();/* move dev in dst's to loopback so this VRF device can be deleted * - based on dst_ifdown
Signature · 1 line
2.9.4
Quoted 23 lines · lirongqing
From: Li RongQing <[email protected]>
Replace
synchronize_rcu()withsynchronize_net()invrf_rtable_release()andvrf_rt6_release().
synchronize_net()is RTNL-aware and can use the more efficientsynchronize_rcu_expedited()when the RTNL lock is held, avoiding potentially long wait times for a standard RCU grace period.Since these release functions are called during device teardown where the RTNL lock is typically held, this change reduces the time spent in RTNL critical sections and speeds up VRF device deletion.
Signed-off-by Li RongQing <[email protected]>--- drivers/net/vrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/vrf.c +0
-0
drivers/net/vrf.c static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf) · line 758
Quoted 5 lines
drivers/net/vrf.c +1
-1@@ -755,7 +755,7 @@ static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf)struct dst_entry *dst;RCU_INIT_POINTER (vrf->rt6,NULL ); -synchronize_rcu (); +synchronize_net ();
I might be missing something, but why do we need synchronize_rcu() here? The code below calls dst_release() which will only free the dst entry after an RCU grace period (assuming we dropped the last reference).
Also, I think that instead of using net->loopback_dev the code can be converted to use dst_dev_put() before dst_release().
Quoted 15 lines
drivers/net/vrf.c +1
-1/* move dev in dst's to loopback so this VRF device can be deleted * - based on dst_ifdown @@ -1002,7 +1002,7 @@ static void vrf_rtable_release(struct net_device *dev, struct net_vrf *vrf)struct dst_entry *dst;RCU_INIT_POINTER (vrf->rth,NULL ); -synchronize_rcu (); +synchronize_net ();/* move dev in dst's to loopback so this VRF device can be deleted * - based on dst_ifdown Signature · 1 line
2.9.4
Quoted 27 lines · Ido Schimmel
Quoted 25 lines · lirongqing
From: Li RongQing <[email protected]>
Replace
synchronize_rcu()withsynchronize_net()invrf_rtable_release()andvrf_rt6_release().
synchronize_net()is RTNL-aware and can use the more efficientsynchronize_rcu_expedited()when the RTNL lock is held, avoiding potentially long wait times for a standard RCU grace period.Since these release functions are called during device teardown where the RTNL lock is typically held, this change reduces the time spent in RTNL critical sections and speeds up VRF device deletion.
Signed-off-by Li RongQing <[email protected]>--- drivers/net/vrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/vrf.c +0
-0@@ -755,7 +755,7 @@ static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf)struct dst_entry *dst;
Quoted 7 lines
drivers/net/vrf.c static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf) · line 758
Quoted 3 lines
drivers/net/vrf.c +1
-1RCU_INIT_POINTER (vrf->rt6,NULL ); -synchronize_rcu (); +synchronize_net ();I might be missing something, but why do we need
synchronize_rcu()here? The code below callsdst_release()which will only free the dst entry after an RCU grace period (assuming we dropped the last reference).
Agreed, this could/should have been removed after
commit 4f04256c983a4f115417d2009b44dcb7d70a6375
Author: David Ahern <[email protected]> Date: Fri Aug 11 17:11:14 2017 -0700
net: vrf: Drop local rtable and rt6_info
The VRF cached rtable and rt6_info for local traffic are no longer needed and actually prevent local traffic through enslaved devices. Remove them.
Quoted 4 lines
Also, I think that instead of using
net->loopback_devthe code can be converted to usedst_dev_put()beforedst_release().
Maybe in a separate patch ;)
Quoted 51 lines · Eric Dumazet
Quoted 27 lines · Ido Schimmel
Quoted 25 lines · lirongqing
From: Li RongQing <[email protected]>
Replace
synchronize_rcu()withsynchronize_net()invrf_rtable_release()andvrf_rt6_release().
synchronize_net()is RTNL-aware and can use the more efficientsynchronize_rcu_expedited()when the RTNL lock is held, avoiding potentially long wait times for a standard RCU grace period.Since these release functions are called during device teardown where the RTNL lock is typically held, this change reduces the time spent in RTNL critical sections and speeds up VRF device deletion.
Signed-off-by Li RongQing <[email protected]>--- drivers/net/vrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/vrf.c +0
-0@@ -755,7 +755,7 @@ static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf)struct dst_entry *dst;Quoted 7 lines
drivers/net/vrf.c static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf) · line 758
Quoted 3 lines
drivers/net/vrf.c +1
-1RCU_INIT_POINTER (vrf->rt6,NULL ); -synchronize_rcu (); +synchronize_net ();I might be missing something, but why do we need
synchronize_rcu()here? The code below callsdst_release()which will only free the dst entry after an RCU grace period (assuming we dropped the last reference).Agreed, this could/should have been removed after
commit
4f04256c983a4f115417d2009b44dcb7d70a6375Author: David Ahern <[email protected]> Date: Fri Aug 11 17:11:14 2017 -0700net: vrf: Drop local rtable and
rt6_infoThe VRF cached rtable and
rt6_infofor local traffic are no longer needed and actually prevent local traffic through enslaved devices. Remove them.Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Also, I think that instead of using
net->loopback_devthe code can be converted to usedst_dev_put()beforedst_release().Maybe in a separate patch ;)
Yes, separate patch. Another thing that can be simplified in this area is the NULL check in vrf_rtable_release(). I don't see how that can happen. It is necessary in the case of vrf_rt6_release() due to 'ipv6.disable=1'.
Li RongQing, can you take care of these changes?
1. Remove NULL check in vrf_rtable_release().
2. Convert vrf_rtable_release() and vrf_rt6_release() to use dst_dev_put() before dst_release(), instead of using 'net->loopback_dev'.
3. Remove synchronize_rcu() from both vrf_rtable_release() and vrf_rt6_release().
Thanks