Skip to content

Commit 38e6bc1

Browse files
Amerigo Wangdavem330
authored andcommitted
netpoll: make __netpoll_cleanup non-block
Like the previous patch, slave_disable_netpoll() and __netpoll_cleanup() may be called with read_lock() held too, so we should make them non-block, by moving the cleanup and kfree() to call_rcu_bh() callbacks. Cc: "David S. Miller" <davem@davemloft.net> Signed-off-by: Cong Wang <amwang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 47be03a commit 38e6bc1

5 files changed

Lines changed: 38 additions & 23 deletions

File tree

‎drivers/net/bonding/bond_main.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,9 +1257,7 @@ static inline void slave_disable_netpoll(struct slave *slave)
12571257
return;
12581258

12591259
slave->np = NULL;
1260-
synchronize_rcu_bh();
1261-
__netpoll_cleanup(np);
1262-
kfree(np);
1260+
__netpoll_free_rcu(np);
12631261
}
12641262
static inline bool slave_dev_support_netpoll(struct net_device *slave_dev)
12651263
{

‎include/linux/netpoll.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct netpoll {
2323
u8 remote_mac[ETH_ALEN];
2424

2525
struct list_head rx; /* rx_np list element */
26+
struct rcu_head rcu;
2627
};
2728

2829
struct netpoll_info {
@@ -38,6 +39,7 @@ struct netpoll_info {
3839
struct delayed_work tx_work;
3940

4041
struct netpoll *netpoll;
42+
struct rcu_head rcu;
4143
};
4244

4345
void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
@@ -48,6 +50,7 @@ int netpoll_setup(struct netpoll *np);
4850
int netpoll_trap(void);
4951
void netpoll_set_trap(int trap);
5052
void __netpoll_cleanup(struct netpoll *np);
53+
void __netpoll_free_rcu(struct netpoll *np);
5154
void netpoll_cleanup(struct netpoll *np);
5255
int __netpoll_rx(struct sk_buff *skb);
5356
void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,

‎net/8021q/vlan_dev.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,7 @@ static void vlan_dev_netpoll_cleanup(struct net_device *dev)
704704

705705
info->netpoll = NULL;
706706

707-
/* Wait for transmitting packets to finish before freeing. */
708-
synchronize_rcu_bh();
709-
710-
__netpoll_cleanup(netpoll);
711-
kfree(netpoll);
707+
__netpoll_free_rcu(netpoll);
712708
}
713709
#endif /* CONFIG_NET_POLL_CONTROLLER */
714710

‎net/bridge/br_device.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,7 @@ void br_netpoll_disable(struct net_bridge_port *p)
267267

268268
p->np = NULL;
269269

270-
/* Wait for transmitting packets to finish before freeing. */
271-
synchronize_rcu_bh();
272-
273-
__netpoll_cleanup(np);
274-
kfree(np);
270+
__netpoll_free_rcu(np);
275271
}
276272

277273
#endif

‎net/core/netpoll.c‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,24 @@ static int __init netpoll_init(void)
878878
}
879879
core_initcall(netpoll_init);
880880

881+
static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
882+
{
883+
struct netpoll_info *npinfo =
884+
container_of(rcu_head, struct netpoll_info, rcu);
885+
886+
skb_queue_purge(&npinfo->arp_tx);
887+
skb_queue_purge(&npinfo->txq);
888+
889+
/* we can't call cancel_delayed_work_sync here, as we are in softirq */
890+
cancel_delayed_work(&npinfo->tx_work);
891+
892+
/* clean after last, unfinished work */
893+
__skb_queue_purge(&npinfo->txq);
894+
/* now cancel it again */
895+
cancel_delayed_work(&npinfo->tx_work);
896+
kfree(npinfo);
897+
}
898+
881899
void __netpoll_cleanup(struct netpoll *np)
882900
{
883901
struct netpoll_info *npinfo;
@@ -903,20 +921,24 @@ void __netpoll_cleanup(struct netpoll *np)
903921
ops->ndo_netpoll_cleanup(np->dev);
904922

905923
RCU_INIT_POINTER(np->dev->npinfo, NULL);
924+
call_rcu_bh(&npinfo->rcu, rcu_cleanup_netpoll_info);
925+
}
926+
}
927+
EXPORT_SYMBOL_GPL(__netpoll_cleanup);
906928

907-
/* avoid racing with NAPI reading npinfo */
908-
synchronize_rcu_bh();
929+
static void rcu_cleanup_netpoll(struct rcu_head *rcu_head)
930+
{
931+
struct netpoll *np = container_of(rcu_head, struct netpoll, rcu);
909932

910-
skb_queue_purge(&npinfo->arp_tx);
911-
skb_queue_purge(&npinfo->txq);
912-
cancel_delayed_work_sync(&npinfo->tx_work);
933+
__netpoll_cleanup(np);
934+
kfree(np);
935+
}
913936

914-
/* clean after last, unfinished work */
915-
__skb_queue_purge(&npinfo->txq);
916-
kfree(npinfo);
917-
}
937+
void __netpoll_free_rcu(struct netpoll *np)
938+
{
939+
call_rcu_bh(&np->rcu, rcu_cleanup_netpoll);
918940
}
919-
EXPORT_SYMBOL_GPL(__netpoll_cleanup);
941+
EXPORT_SYMBOL_GPL(__netpoll_free_rcu);
920942

921943
void netpoll_cleanup(struct netpoll *np)
922944
{

0 commit comments

Comments
 (0)