aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/netpoll.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/netpoll.c')
-rw-r--r--net/core/netpoll.c109
1 files changed, 78 insertions, 31 deletions
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index b4c90e42b443..346b1eb83a1f 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -26,6 +26,7 @@
26#include <linux/workqueue.h> 26#include <linux/workqueue.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/export.h> 28#include <linux/export.h>
29#include <linux/if_vlan.h>
29#include <net/tcp.h> 30#include <net/tcp.h>
30#include <net/udp.h> 31#include <net/udp.h>
31#include <asm/unaligned.h> 32#include <asm/unaligned.h>
@@ -54,7 +55,7 @@ static atomic_t trapped;
54 MAX_UDP_CHUNK) 55 MAX_UDP_CHUNK)
55 56
56static void zap_completion_queue(void); 57static void zap_completion_queue(void);
57static void arp_reply(struct sk_buff *skb); 58static void netpoll_arp_reply(struct sk_buff *skb, struct netpoll_info *npinfo);
58 59
59static unsigned int carrier_timeout = 4; 60static unsigned int carrier_timeout = 4;
60module_param(carrier_timeout, uint, 0644); 61module_param(carrier_timeout, uint, 0644);
@@ -167,15 +168,24 @@ static void poll_napi(struct net_device *dev)
167 struct napi_struct *napi; 168 struct napi_struct *napi;
168 int budget = 16; 169 int budget = 16;
169 170
171 WARN_ON_ONCE(!irqs_disabled());
172
170 list_for_each_entry(napi, &dev->napi_list, dev_list) { 173 list_for_each_entry(napi, &dev->napi_list, dev_list) {
174 local_irq_enable();
171 if (napi->poll_owner != smp_processor_id() && 175 if (napi->poll_owner != smp_processor_id() &&
172 spin_trylock(&napi->poll_lock)) { 176 spin_trylock(&napi->poll_lock)) {
173 budget = poll_one_napi(dev->npinfo, napi, budget); 177 rcu_read_lock_bh();
178 budget = poll_one_napi(rcu_dereference_bh(dev->npinfo),
179 napi, budget);
180 rcu_read_unlock_bh();
174 spin_unlock(&napi->poll_lock); 181 spin_unlock(&napi->poll_lock);
175 182
176 if (!budget) 183 if (!budget) {
184 local_irq_disable();
177 break; 185 break;
186 }
178 } 187 }
188 local_irq_disable();
179 } 189 }
180} 190}
181 191
@@ -185,13 +195,14 @@ static void service_arp_queue(struct netpoll_info *npi)
185 struct sk_buff *skb; 195 struct sk_buff *skb;
186 196
187 while ((skb = skb_dequeue(&npi->arp_tx))) 197 while ((skb = skb_dequeue(&npi->arp_tx)))
188 arp_reply(skb); 198 netpoll_arp_reply(skb, npi);
189 } 199 }
190} 200}
191 201
192static void netpoll_poll_dev(struct net_device *dev) 202static void netpoll_poll_dev(struct net_device *dev)
193{ 203{
194 const struct net_device_ops *ops; 204 const struct net_device_ops *ops;
205 struct netpoll_info *ni = rcu_dereference_bh(dev->npinfo);
195 206
196 if (!dev || !netif_running(dev)) 207 if (!dev || !netif_running(dev))
197 return; 208 return;
@@ -206,17 +217,18 @@ static void netpoll_poll_dev(struct net_device *dev)
206 poll_napi(dev); 217 poll_napi(dev);
207 218
208 if (dev->flags & IFF_SLAVE) { 219 if (dev->flags & IFF_SLAVE) {
209 if (dev->npinfo) { 220 if (ni) {
210 struct net_device *bond_dev = dev->master; 221 struct net_device *bond_dev = dev->master;
211 struct sk_buff *skb; 222 struct sk_buff *skb;
212 while ((skb = skb_dequeue(&dev->npinfo->arp_tx))) { 223 struct netpoll_info *bond_ni = rcu_dereference_bh(bond_dev->npinfo);
224 while ((skb = skb_dequeue(&ni->arp_tx))) {
213 skb->dev = bond_dev; 225 skb->dev = bond_dev;
214 skb_queue_tail(&bond_dev->npinfo->arp_tx, skb); 226 skb_queue_tail(&bond_ni->arp_tx, skb);
215 } 227 }
216 } 228 }
217 } 229 }
218 230
219 service_arp_queue(dev->npinfo); 231 service_arp_queue(ni);
220 232
221 zap_completion_queue(); 233 zap_completion_queue();
222} 234}
@@ -302,6 +314,7 @@ static int netpoll_owner_active(struct net_device *dev)
302 return 0; 314 return 0;
303} 315}
304 316
317/* call with IRQ disabled */
305void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb, 318void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
306 struct net_device *dev) 319 struct net_device *dev)
307{ 320{
@@ -309,8 +322,11 @@ void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
309 unsigned long tries; 322 unsigned long tries;
310 const struct net_device_ops *ops = dev->netdev_ops; 323 const struct net_device_ops *ops = dev->netdev_ops;
311 /* It is up to the caller to keep npinfo alive. */ 324 /* It is up to the caller to keep npinfo alive. */
312 struct netpoll_info *npinfo = np->dev->npinfo; 325 struct netpoll_info *npinfo;
326
327 WARN_ON_ONCE(!irqs_disabled());
313 328
329 npinfo = rcu_dereference_bh(np->dev->npinfo);
314 if (!npinfo || !netif_running(dev) || !netif_device_present(dev)) { 330 if (!npinfo || !netif_running(dev) || !netif_device_present(dev)) {
315 __kfree_skb(skb); 331 __kfree_skb(skb);
316 return; 332 return;
@@ -319,16 +335,22 @@ void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
319 /* don't get messages out of order, and no recursion */ 335 /* don't get messages out of order, and no recursion */
320 if (skb_queue_len(&npinfo->txq) == 0 && !netpoll_owner_active(dev)) { 336 if (skb_queue_len(&npinfo->txq) == 0 && !netpoll_owner_active(dev)) {
321 struct netdev_queue *txq; 337 struct netdev_queue *txq;
322 unsigned long flags;
323 338
324 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); 339 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
325 340
326 local_irq_save(flags);
327 /* try until next clock tick */ 341 /* try until next clock tick */
328 for (tries = jiffies_to_usecs(1)/USEC_PER_POLL; 342 for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
329 tries > 0; --tries) { 343 tries > 0; --tries) {
330 if (__netif_tx_trylock(txq)) { 344 if (__netif_tx_trylock(txq)) {
331 if (!netif_xmit_stopped(txq)) { 345 if (!netif_xmit_stopped(txq)) {
346 if (vlan_tx_tag_present(skb) &&
347 !(netif_skb_features(skb) & NETIF_F_HW_VLAN_TX)) {
348 skb = __vlan_put_tag(skb, vlan_tx_tag_get(skb));
349 if (unlikely(!skb))
350 break;
351 skb->vlan_tci = 0;
352 }
353
332 status = ops->ndo_start_xmit(skb, dev); 354 status = ops->ndo_start_xmit(skb, dev);
333 if (status == NETDEV_TX_OK) 355 if (status == NETDEV_TX_OK)
334 txq_trans_update(txq); 356 txq_trans_update(txq);
@@ -347,10 +369,9 @@ void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
347 } 369 }
348 370
349 WARN_ONCE(!irqs_disabled(), 371 WARN_ONCE(!irqs_disabled(),
350 "netpoll_send_skb(): %s enabled interrupts in poll (%pF)\n", 372 "netpoll_send_skb_on_dev(): %s enabled interrupts in poll (%pF)\n",
351 dev->name, ops->ndo_start_xmit); 373 dev->name, ops->ndo_start_xmit);
352 374
353 local_irq_restore(flags);
354 } 375 }
355 376
356 if (status != NETDEV_TX_OK) { 377 if (status != NETDEV_TX_OK) {
@@ -423,9 +444,8 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
423} 444}
424EXPORT_SYMBOL(netpoll_send_udp); 445EXPORT_SYMBOL(netpoll_send_udp);
425 446
426static void arp_reply(struct sk_buff *skb) 447static void netpoll_arp_reply(struct sk_buff *skb, struct netpoll_info *npinfo)
427{ 448{
428 struct netpoll_info *npinfo = skb->dev->npinfo;
429 struct arphdr *arp; 449 struct arphdr *arp;
430 unsigned char *arp_ptr; 450 unsigned char *arp_ptr;
431 int size, type = ARPOP_REPLY, ptype = ETH_P_ARP; 451 int size, type = ARPOP_REPLY, ptype = ETH_P_ARP;
@@ -543,13 +563,12 @@ static void arp_reply(struct sk_buff *skb)
543 spin_unlock_irqrestore(&npinfo->rx_lock, flags); 563 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
544} 564}
545 565
546int __netpoll_rx(struct sk_buff *skb) 566int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
547{ 567{
548 int proto, len, ulen; 568 int proto, len, ulen;
549 int hits = 0; 569 int hits = 0;
550 const struct iphdr *iph; 570 const struct iphdr *iph;
551 struct udphdr *uh; 571 struct udphdr *uh;
552 struct netpoll_info *npinfo = skb->dev->npinfo;
553 struct netpoll *np, *tmp; 572 struct netpoll *np, *tmp;
554 573
555 if (list_empty(&npinfo->rx_np)) 574 if (list_empty(&npinfo->rx_np))
@@ -565,6 +584,12 @@ int __netpoll_rx(struct sk_buff *skb)
565 return 1; 584 return 1;
566 } 585 }
567 586
587 if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
588 skb = vlan_untag(skb);
589 if (unlikely(!skb))
590 goto out;
591 }
592
568 proto = ntohs(eth_hdr(skb)->h_proto); 593 proto = ntohs(eth_hdr(skb)->h_proto);
569 if (proto != ETH_P_IP) 594 if (proto != ETH_P_IP)
570 goto out; 595 goto out;
@@ -715,7 +740,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
715} 740}
716EXPORT_SYMBOL(netpoll_parse_options); 741EXPORT_SYMBOL(netpoll_parse_options);
717 742
718int __netpoll_setup(struct netpoll *np, struct net_device *ndev) 743int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp)
719{ 744{
720 struct netpoll_info *npinfo; 745 struct netpoll_info *npinfo;
721 const struct net_device_ops *ops; 746 const struct net_device_ops *ops;
@@ -734,7 +759,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
734 } 759 }
735 760
736 if (!ndev->npinfo) { 761 if (!ndev->npinfo) {
737 npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL); 762 npinfo = kmalloc(sizeof(*npinfo), gfp);
738 if (!npinfo) { 763 if (!npinfo) {
739 err = -ENOMEM; 764 err = -ENOMEM;
740 goto out; 765 goto out;
@@ -752,7 +777,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
752 777
753 ops = np->dev->netdev_ops; 778 ops = np->dev->netdev_ops;
754 if (ops->ndo_netpoll_setup) { 779 if (ops->ndo_netpoll_setup) {
755 err = ops->ndo_netpoll_setup(ndev, npinfo); 780 err = ops->ndo_netpoll_setup(ndev, npinfo, gfp);
756 if (err) 781 if (err)
757 goto free_npinfo; 782 goto free_npinfo;
758 } 783 }
@@ -857,7 +882,7 @@ int netpoll_setup(struct netpoll *np)
857 refill_skbs(); 882 refill_skbs();
858 883
859 rtnl_lock(); 884 rtnl_lock();
860 err = __netpoll_setup(np, ndev); 885 err = __netpoll_setup(np, ndev, GFP_KERNEL);
861 rtnl_unlock(); 886 rtnl_unlock();
862 887
863 if (err) 888 if (err)
@@ -878,6 +903,24 @@ static int __init netpoll_init(void)
878} 903}
879core_initcall(netpoll_init); 904core_initcall(netpoll_init);
880 905
906static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
907{
908 struct netpoll_info *npinfo =
909 container_of(rcu_head, struct netpoll_info, rcu);
910
911 skb_queue_purge(&npinfo->arp_tx);
912 skb_queue_purge(&npinfo->txq);
913
914 /* we can't call cancel_delayed_work_sync here, as we are in softirq */
915 cancel_delayed_work(&npinfo->tx_work);
916
917 /* clean after last, unfinished work */
918 __skb_queue_purge(&npinfo->txq);
919 /* now cancel it again */
920 cancel_delayed_work(&npinfo->tx_work);
921 kfree(npinfo);
922}
923
881void __netpoll_cleanup(struct netpoll *np) 924void __netpoll_cleanup(struct netpoll *np)
882{ 925{
883 struct netpoll_info *npinfo; 926 struct netpoll_info *npinfo;
@@ -903,20 +946,24 @@ void __netpoll_cleanup(struct netpoll *np)
903 ops->ndo_netpoll_cleanup(np->dev); 946 ops->ndo_netpoll_cleanup(np->dev);
904 947
905 RCU_INIT_POINTER(np->dev->npinfo, NULL); 948 RCU_INIT_POINTER(np->dev->npinfo, NULL);
949 call_rcu_bh(&npinfo->rcu, rcu_cleanup_netpoll_info);
950 }
951}
952EXPORT_SYMBOL_GPL(__netpoll_cleanup);
906 953
907 /* avoid racing with NAPI reading npinfo */ 954static void rcu_cleanup_netpoll(struct rcu_head *rcu_head)
908 synchronize_rcu_bh(); 955{
956 struct netpoll *np = container_of(rcu_head, struct netpoll, rcu);
909 957
910 skb_queue_purge(&npinfo->arp_tx); 958 __netpoll_cleanup(np);
911 skb_queue_purge(&npinfo->txq); 959 kfree(np);
912 cancel_delayed_work_sync(&npinfo->tx_work); 960}
913 961
914 /* clean after last, unfinished work */ 962void __netpoll_free_rcu(struct netpoll *np)
915 __skb_queue_purge(&npinfo->txq); 963{
916 kfree(npinfo); 964 call_rcu_bh(&np->rcu, rcu_cleanup_netpoll);
917 }
918} 965}
919EXPORT_SYMBOL_GPL(__netpoll_cleanup); 966EXPORT_SYMBOL_GPL(__netpoll_free_rcu);
920 967
921void netpoll_cleanup(struct netpoll *np) 968void netpoll_cleanup(struct netpoll *np)
922{ 969{