bareudp/pfcp/ppp: Improve netns dismantle.
Subsystems (3)
cover bareudp/pfcp/ppp: Improve netns dismantle.
pfcp and ppp holds RTNL in pernet_operations.exit(), which can be converted to ->exit_batch_rtnl(). Patch 1 and 2 do the conversion.
bareudp leaves some unregistered devices in a list in dying netns depending on where the device is cleaned up. Patch 3 fixes that inconsistency.
Kuniyuki Iwashima (3):
pfcp: Convert pfcp_net_exit() to ->exit_batch_rtnl().
ppp: Split ppp_exit_net() to ->exit_batch_rtnl().
bareudp: Call bareudp_dellink() in bareudp_destroy_tunnels().
drivers/net/bareudp.c | 2 +- drivers/net/pfcp.c | 27 ++++++++++++++++----------- drivers/net/ppp/ppp_generic.c | 33 ++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 23 deletions(-)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH 1/3 pfcp: Convert pfcp_net_exit() to ->exit_batch_rtnl().
pfcp_net_exit() holds RTNL and calls unregister_netdevice_queue() for dev in the netns.
Let's convert pfcp_net_exit() to ->exit_batch_rtnl to save RTNL dances for each netns.
--- drivers/net/pfcp.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/net/pfcp.c +16 -11
@@ -244,30 +244,35 @@ static int __net_init pfcp_net_init(struct net *net)return 0 ; } -static void __net_exit pfcp_net_exit(struct net *net) +static void __net_exit pfcp_destroy_links(struct net *net, +struct list_head *dev_kill_list) {struct pfcp_net *pn =net_generic (net, pfcp_net_id);struct pfcp_dev *pfcp, *pfcp_next;struct net_device *dev; -LIST_HEAD (list); -rtnl_lock ();for_each_netdev (net, dev)if (dev->rtnl_link_ops == &pfcp_link_ops) -pfcp_dellink (dev, &list); +pfcp_dellink (dev, dev_kill_list);list_for_each_entry_safe (pfcp, pfcp_next, &pn->pfcp_dev_list, list) -pfcp_dellink (pfcp->dev, &list); +pfcp_dellink (pfcp->dev, dev_kill_list); +} + +static void __net_exit pfcp_net_exit_batch_rtnl(struct list_head *net_exit_list, +struct list_head *dev_kill_list) +{ +struct net *net; -unregister_netdevice_many (&list); -rtnl_unlock (); +list_for_each_entry (net, net_exit_list, exit_list) +pfcp_destroy_links (net, dev_kill_list); }static struct pernet_operations pfcp_net_ops = { - .init = pfcp_net_init, - .exit = pfcp_net_exit, - .id = &pfcp_net_id, - .size =sizeof (struct pfcp_net ), + .init = pfcp_net_init, + .exit_batch_rtnl = pfcp_net_exit_batch_rtnl, + .id = &pfcp_net_id, + .size =sizeof (struct pfcp_net ), };static int __init pfcp_init (void )
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v1 net-next 1/3] pfcp: Convert pfcp_net_exit() to ->exit_batch_rtnl().
From: Kuniyuki Iwashima <[email protected]>
Date: Fri, 14 Feb 2025 17:18:16 +0900
Quoted 23 lines
pfcp_net_exit()holds RTNL and callsunregister_netdevice_queue()for dev in the netns.Let's convert
pfcp_net_exit()to ->exit_batch_rtnl to save RTNL dances for each netns.Signed-off-by Kuniyuki Iwashima <[email protected]>--- drivers/net/pfcp.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)drivers/net/pfcp.c +2
-1@@ -244,30 +244,35 @@ static int __net_init pfcp_net_init(struct net *net)return 0 ; } -static void __net_exit pfcp_net_exit(struct net *net) +static void __net_exit pfcp_destroy_links(struct net *net, +struct list_head *dev_kill_list) {
drivers/net/pfcp.c static int __net_init pfcp_net_init(struct net *net) · line 256
Quoted 10 lines
drivers/net/pfcp.c +1
-3struct pfcp_net *pn =net_generic (net, pfcp_net_id);struct pfcp_dev *pfcp, *pfcp_next;struct net_device *dev; -LIST_HEAD (list); -rtnl_lock ();for_each_netdev (net, dev)if (dev->rtnl_link_ops == &pfcp_link_ops) -pfcp_dellink (dev, &list); +pfcp_dellink (dev, dev_kill_list);
I got a report regarding this part and will post a fix conflicting with this hunk, so please ignore this series
pw-bot: cr
PATCH 2/3 ppp: Split ppp_exit_net() to ->exit_batch_rtnl().
In reply to Kuniyuki Iwashimappp_exit_net() unregisters devices related to the netns under RTNL and destroys lists and IDR.
Let's move the device unregistration to ->exit_batch_rtnl() to save RTNL dances for each netns.
While at it, unregister_netdevice_queue() is replaced with ppp_nl_dellink() to avoid a potential issue like the one recently found in geneve. [0]
Note that ppp_nl_dellink() is bare unregister_netdevice_queue().
--- drivers/net/ppp/ppp_generic.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
drivers/net/ppp/ppp_generic.c +22 -11
@@ -1134,28 +1134,38 @@ static __net_init int ppp_init_net(struct net *net)return 0 ; } -static __net_exit void ppp_exit_net(struct net *net) +static void ppp_nl_dellink (struct net_device *dev,struct list_head *head); + +static __net_exit void ppp_destroy_links(struct net *net, +struct list_head *dev_kill_list) {struct ppp_net *pn =net_generic (net, ppp_net_id); -struct net_device *dev; -struct net_device *aux; +struct net_device *dev, *aux;struct ppp *ppp; -LIST_HEAD (list);int id; -rtnl_lock (); -for_each_netdev_safe (net, dev, aux) { +for_each_netdev_safe (net, dev, aux)if (dev->netdev_ops == &ppp_netdev_ops) -unregister_netdevice_queue (dev, &list); - } +ppp_nl_dellink (dev, dev_kill_list);idr_for_each_entry (&pn->units_idr, ppp, id)/* Skip devices already unregistered by previous loop */ if (!net_eq (dev_net (ppp->dev), net)) -unregister_netdevice_queue (ppp->dev, &list); +ppp_nl_dellink (ppp->dev, dev_kill_list); +} -unregister_netdevice_many (&list); -rtnl_unlock (); +static __net_exit void ppp_exit_net_batch_rtnl(struct list_head *net_exit_list, +struct list_head *dev_kill_list) +{ +struct net *net; + +list_for_each_entry (net, net_exit_list, exit_list) +ppp_destroy_links (net, dev_kill_list); +} + +static __net_exit void ppp_exit_net(struct net *net) +{ +struct ppp_net *pn =net_generic (net, ppp_net_id);mutex_destroy (&pn->all_ppp_mutex);idr_destroy (&pn->units_idr);
@@ -1165,6 +1175,7 @@ static __net_exit void ppp_exit_net(struct net *net)static struct pernet_operations ppp_net_ops = { .init = ppp_init_net, + .exit_batch_rtnl = ppp_exit_net_batch_rtnl, .exit = ppp_exit_net, .id = &ppp_net_id, .size =sizeof (struct ppp_net ),
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH 3/3 bareudp: Call bareudp_dellink() in bareudp_destroy_tunnels().
In reply to Kuniyuki Iwashimabareudp devices are destroyed in two places during netns dismantle:bareudp_exit_batch_rtnl() and default_device_exit_batch().
bareudp_exit_batch_rtnl() unregisters devices whose backend UDP socket is in the dying netns.
default_device_exit_batch() unregisters devices in the dying netns.
The latter calls ->dellink(), but the former calls unregister_netdevice_queue() only. In the former case, the device remains in net_generic(net, bareudp_net_id)->bareudp_list.
There is no real bug, but let's call ->dellink() to avoid a potential issue like the one recently found in geneve. [0]
--- drivers/net/bareudp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bareudp.c +1 -1
@@ -780,7 +780,7 @@ static void bareudp_destroy_tunnels(struct net *net, struct list_head *head)struct bareudp_dev *bareudp, *next;list_for_each_entry_safe (bareudp, next, &bn->bareudp_list, next) -unregister_netdevice_queue (bareudp->dev, head); +bareudp_dellink (bareudp->dev, head); } static void __net_exit bareudp_exit_batch_rtnl(struct list_head *net_list,
Signature · 1 line
2.39.5 (Apple Git-154)