public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][net-next] net: vrf: switch to synchronize_net() when releasing routes
@ 2026-03-10 10:53 lirongqing
  2026-03-11 13:19 ` Ido Schimmel
  0 siblings, 1 reply; 4+ messages in thread
From: lirongqing @ 2026-03-10 10:53 UTC (permalink / raw)
  To: David Ahern, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev
  Cc: Li RongQing

From: Li RongQing <lirongqing@baidu.com>

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.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/net/vrf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index 8c009bc..92a0f4b 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -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
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][net-next] net: vrf: switch to synchronize_net() when releasing routes
  2026-03-10 10:53 [PATCH][net-next] net: vrf: switch to synchronize_net() when releasing routes lirongqing
@ 2026-03-11 13:19 ` Ido Schimmel
  2026-03-11 13:26   ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Ido Schimmel @ 2026-03-11 13:19 UTC (permalink / raw)
  To: lirongqing
  Cc: David Ahern, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev

On Tue, Mar 10, 2026 at 06:53:31AM -0400, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
> 
> 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.
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  drivers/net/vrf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
> index 8c009bc..92a0f4b 100644
> --- a/drivers/net/vrf.c
> +++ b/drivers/net/vrf.c
> @@ -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().

>  
>  	/* 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
> -- 
> 2.9.4
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][net-next] net: vrf: switch to synchronize_net() when releasing routes
  2026-03-11 13:19 ` Ido Schimmel
@ 2026-03-11 13:26   ` Eric Dumazet
  2026-03-11 15:26     ` Ido Schimmel
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2026-03-11 13:26 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: lirongqing, David Ahern, Andrew Lunn, David S . Miller,
	Jakub Kicinski, Paolo Abeni, netdev

On Wed, Mar 11, 2026 at 2:19 PM Ido Schimmel <idosch@nvidia.com> wrote:
>
> On Tue, Mar 10, 2026 at 06:53:31AM -0400, lirongqing wrote:
> > From: Li RongQing <lirongqing@baidu.com>
> >
> > 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.
> >
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
> >  drivers/net/vrf.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
> > index 8c009bc..92a0f4b 100644
> > --- a/drivers/net/vrf.c
> > +++ b/drivers/net/vrf.c
> > @@ -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).

Agreed, this could/should have been removed after

commit 4f04256c983a4f115417d2009b44dcb7d70a6375
Author: David Ahern <dsahern@gmail.com>
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.



>
> Also, I think that instead of using net->loopback_dev the code can be
> converted to use dst_dev_put() before dst_release().
>

Maybe in a separate patch ;)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][net-next] net: vrf: switch to synchronize_net() when releasing routes
  2026-03-11 13:26   ` Eric Dumazet
@ 2026-03-11 15:26     ` Ido Schimmel
  0 siblings, 0 replies; 4+ messages in thread
From: Ido Schimmel @ 2026-03-11 15:26 UTC (permalink / raw)
  To: Eric Dumazet, lirongqing
  Cc: David Ahern, Andrew Lunn, David S . Miller, Jakub Kicinski,
	Paolo Abeni, netdev

On Wed, Mar 11, 2026 at 02:26:57PM +0100, Eric Dumazet wrote:
> On Wed, Mar 11, 2026 at 2:19 PM Ido Schimmel <idosch@nvidia.com> wrote:
> >
> > On Tue, Mar 10, 2026 at 06:53:31AM -0400, lirongqing wrote:
> > > From: Li RongQing <lirongqing@baidu.com>
> > >
> > > 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.
> > >
> > > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > > ---
> > >  drivers/net/vrf.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
> > > index 8c009bc..92a0f4b 100644
> > > --- a/drivers/net/vrf.c
> > > +++ b/drivers/net/vrf.c
> > > @@ -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).
> 
> Agreed, this could/should have been removed after
> 
> commit 4f04256c983a4f115417d2009b44dcb7d70a6375
> Author: David Ahern <dsahern@gmail.com>
> 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.
> 
> 
> 
> >
> > Also, I think that instead of using net->loopback_dev the code can be
> > converted to use dst_dev_put() before dst_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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-11 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 10:53 [PATCH][net-next] net: vrf: switch to synchronize_net() when releasing routes lirongqing
2026-03-11 13:19 ` Ido Schimmel
2026-03-11 13:26   ` Eric Dumazet
2026-03-11 15:26     ` Ido Schimmel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox