Skip to content

Commit 84ee6e5

Browse files
committed
Merge branch 'net-followup-series-for-exit_rtnl'
Kuniyuki Iwashima says: ==================== net: Followup series for ->exit_rtnl(). Patch 1 drops the hold_rtnl arg in ops_undo_list() as suggested by Jakub. Patch 2 & 3 apply ->exit_rtnl() to pfcp and ppp. v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 21b01cb + 7ee3207 commit 84ee6e5

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

drivers/net/pfcp.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,21 @@ static int __net_init pfcp_net_init(struct net *net)
245245
return 0;
246246
}
247247

248-
static void __net_exit pfcp_net_exit(struct net *net)
248+
static void __net_exit pfcp_net_exit_rtnl(struct net *net,
249+
struct list_head *dev_to_kill)
249250
{
250251
struct pfcp_net *pn = net_generic(net, pfcp_net_id);
251252
struct pfcp_dev *pfcp, *pfcp_next;
252-
struct net_device *dev;
253-
LIST_HEAD(list);
254-
255-
rtnl_lock();
256-
for_each_netdev(net, dev)
257-
if (dev->rtnl_link_ops == &pfcp_link_ops)
258-
pfcp_dellink(dev, &list);
259253

260254
list_for_each_entry_safe(pfcp, pfcp_next, &pn->pfcp_dev_list, list)
261-
pfcp_dellink(pfcp->dev, &list);
262-
263-
unregister_netdevice_many(&list);
264-
rtnl_unlock();
255+
pfcp_dellink(pfcp->dev, dev_to_kill);
265256
}
266257

267258
static struct pernet_operations pfcp_net_ops = {
268-
.init = pfcp_net_init,
269-
.exit = pfcp_net_exit,
270-
.id = &pfcp_net_id,
271-
.size = sizeof(struct pfcp_net),
259+
.init = pfcp_net_init,
260+
.exit_rtnl = pfcp_net_exit_rtnl,
261+
.id = &pfcp_net_id,
262+
.size = sizeof(struct pfcp_net),
272263
};
273264

274265
static int __init pfcp_init(void)

drivers/net/ppp/ppp_generic.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,8 @@ static const struct file_operations ppp_device_fops = {
11311131
.llseek = noop_llseek,
11321132
};
11331133

1134+
static void ppp_nl_dellink(struct net_device *dev, struct list_head *head);
1135+
11341136
static __net_init int ppp_init_net(struct net *net)
11351137
{
11361138
struct ppp_net *pn = net_generic(net, ppp_net_id);
@@ -1146,28 +1148,20 @@ static __net_init int ppp_init_net(struct net *net)
11461148
return 0;
11471149
}
11481150

1149-
static __net_exit void ppp_exit_net(struct net *net)
1151+
static __net_exit void ppp_exit_rtnl_net(struct net *net,
1152+
struct list_head *dev_to_kill)
11501153
{
11511154
struct ppp_net *pn = net_generic(net, ppp_net_id);
1152-
struct net_device *dev;
1153-
struct net_device *aux;
11541155
struct ppp *ppp;
1155-
LIST_HEAD(list);
11561156
int id;
11571157

1158-
rtnl_lock();
1159-
for_each_netdev_safe(net, dev, aux) {
1160-
if (dev->netdev_ops == &ppp_netdev_ops)
1161-
unregister_netdevice_queue(dev, &list);
1162-
}
1163-
11641158
idr_for_each_entry(&pn->units_idr, ppp, id)
1165-
/* Skip devices already unregistered by previous loop */
1166-
if (!net_eq(dev_net(ppp->dev), net))
1167-
unregister_netdevice_queue(ppp->dev, &list);
1159+
ppp_nl_dellink(ppp->dev, dev_to_kill);
1160+
}
11681161

1169-
unregister_netdevice_many(&list);
1170-
rtnl_unlock();
1162+
static __net_exit void ppp_exit_net(struct net *net)
1163+
{
1164+
struct ppp_net *pn = net_generic(net, ppp_net_id);
11711165

11721166
mutex_destroy(&pn->all_ppp_mutex);
11731167
idr_destroy(&pn->units_idr);
@@ -1177,6 +1171,7 @@ static __net_exit void ppp_exit_net(struct net *net)
11771171

11781172
static struct pernet_operations ppp_net_ops = {
11791173
.init = ppp_init_net,
1174+
.exit_rtnl = ppp_exit_rtnl_net,
11801175
.exit = ppp_exit_net,
11811176
.id = &ppp_net_id,
11821177
.size = sizeof(struct ppp_net),

net/core/net_namespace.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,20 @@ static void ops_free_list(const struct pernet_operations *ops,
220220
static void ops_undo_list(const struct list_head *ops_list,
221221
const struct pernet_operations *ops,
222222
struct list_head *net_exit_list,
223-
bool expedite_rcu, bool hold_rtnl)
223+
bool expedite_rcu)
224224
{
225225
const struct pernet_operations *saved_ops;
226+
bool hold_rtnl = false;
226227

227228
if (!ops)
228229
ops = list_entry(ops_list, typeof(*ops), list);
229230

230231
saved_ops = ops;
231232

232-
list_for_each_entry_continue_reverse(ops, ops_list, list)
233+
list_for_each_entry_continue_reverse(ops, ops_list, list) {
234+
hold_rtnl |= !!ops->exit_rtnl;
233235
ops_pre_exit_list(ops, net_exit_list);
236+
}
234237

235238
/* Another CPU might be rcu-iterating the list, wait for it.
236239
* This needs to be before calling the exit() notifiers, so the
@@ -257,11 +260,10 @@ static void ops_undo_list(const struct list_head *ops_list,
257260
static void ops_undo_single(struct pernet_operations *ops,
258261
struct list_head *net_exit_list)
259262
{
260-
bool hold_rtnl = !!ops->exit_rtnl;
261263
LIST_HEAD(ops_list);
262264

263265
list_add(&ops->list, &ops_list);
264-
ops_undo_list(&ops_list, NULL, net_exit_list, false, hold_rtnl);
266+
ops_undo_list(&ops_list, NULL, net_exit_list, false);
265267
list_del(&ops->list);
266268
}
267269

@@ -452,7 +454,7 @@ static __net_init int setup_net(struct net *net)
452454
* for the pernet modules whose init functions did not fail.
453455
*/
454456
list_add(&net->exit_list, &net_exit_list);
455-
ops_undo_list(&pernet_list, ops, &net_exit_list, false, true);
457+
ops_undo_list(&pernet_list, ops, &net_exit_list, false);
456458
rcu_barrier();
457459
goto out;
458460
}
@@ -681,7 +683,7 @@ static void cleanup_net(struct work_struct *work)
681683
list_add_tail(&net->exit_list, &net_exit_list);
682684
}
683685

684-
ops_undo_list(&pernet_list, NULL, &net_exit_list, true, true);
686+
ops_undo_list(&pernet_list, NULL, &net_exit_list, true);
685687

686688
up_read(&pernet_ops_rwsem);
687689

0 commit comments

Comments
 (0)