Upgrade to 4.4.50-rt62
[kvmfornfv.git] / kernel / net / core / pktgen.c
index 4da4d51..b632760 100644 (file)
 #define M_NETIF_RECEIVE        1       /* Inject packets into stack */
 
 /* If lock -- protects updating of if_list */
-#define   if_lock(t)           spin_lock(&(t->if_lock));
-#define   if_unlock(t)           spin_unlock(&(t->if_lock));
+#define   if_lock(t)           mutex_lock(&(t->if_lock));
+#define   if_unlock(t)           mutex_unlock(&(t->if_lock));
 
 /* Used to help with determining the pkts on receive */
 #define PKTGEN_MAGIC 0xbe9be955
@@ -422,7 +422,7 @@ struct pktgen_net {
 };
 
 struct pktgen_thread {
-       spinlock_t if_lock;             /* for list of devices */
+       struct mutex if_lock;           /* for list of devices */
        struct list_head if_list;       /* All device here */
        struct list_head th_list;
        struct task_struct *tsk;
@@ -2002,11 +2002,13 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
 {
        struct pktgen_thread *t;
 
+       mutex_lock(&pktgen_thread_lock);
+
        list_for_each_entry(t, &pn->pktgen_threads, th_list) {
                struct pktgen_dev *pkt_dev;
 
-               rcu_read_lock();
-               list_for_each_entry_rcu(pkt_dev, &t->if_list, list) {
+               if_lock(t);
+               list_for_each_entry(pkt_dev, &t->if_list, list) {
                        if (pkt_dev->odev != dev)
                                continue;
 
@@ -2021,8 +2023,9 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
                                       dev->name);
                        break;
                }
-               rcu_read_unlock();
+               if_unlock(t);
        }
+       mutex_unlock(&pktgen_thread_lock);
 }
 
 static int pktgen_device_event(struct notifier_block *unused,
@@ -2278,7 +2281,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
 
 static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
 {
-       pkt_dev->pkt_overhead = LL_RESERVED_SPACE(pkt_dev->odev);
+       pkt_dev->pkt_overhead = 0;
        pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32);
        pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev);
        pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev);
@@ -2769,13 +2772,13 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb,
 }
 
 static struct sk_buff *pktgen_alloc_skb(struct net_device *dev,
-                                       struct pktgen_dev *pkt_dev,
-                                       unsigned int extralen)
+                                       struct pktgen_dev *pkt_dev)
 {
+       unsigned int extralen = LL_RESERVED_SPACE(dev);
        struct sk_buff *skb = NULL;
-       unsigned int size = pkt_dev->cur_pkt_size + 64 + extralen +
-                           pkt_dev->pkt_overhead;
+       unsigned int size;
 
+       size = pkt_dev->cur_pkt_size + 64 + extralen + pkt_dev->pkt_overhead;
        if (pkt_dev->flags & F_NODE) {
                int node = pkt_dev->node >= 0 ? pkt_dev->node : numa_node_id();
 
@@ -2788,8 +2791,9 @@ static struct sk_buff *pktgen_alloc_skb(struct net_device *dev,
                 skb = __netdev_alloc_skb(dev, size, GFP_NOWAIT);
        }
 
+       /* the caller pre-fetches from skb->data and reserves for the mac hdr */
        if (likely(skb))
-               skb_reserve(skb, LL_RESERVED_SPACE(dev));
+               skb_reserve(skb, extralen - 16);
 
        return skb;
 }
@@ -2822,16 +2826,14 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
        mod_cur_headers(pkt_dev);
        queue_map = pkt_dev->cur_queue_map;
 
-       datalen = (odev->hard_header_len + 16) & ~0xf;
-
-       skb = pktgen_alloc_skb(odev, pkt_dev, datalen);
+       skb = pktgen_alloc_skb(odev, pkt_dev);
        if (!skb) {
                sprintf(pkt_dev->result, "No memory");
                return NULL;
        }
 
        prefetchw(skb->data);
-       skb_reserve(skb, datalen);
+       skb_reserve(skb, 16);
 
        /*  Reserve for ethernet and IP header  */
        eth = (__u8 *) skb_push(skb, 14);
@@ -2951,7 +2953,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        mod_cur_headers(pkt_dev);
        queue_map = pkt_dev->cur_queue_map;
 
-       skb = pktgen_alloc_skb(odev, pkt_dev, 16);
+       skb = pktgen_alloc_skb(odev, pkt_dev);
        if (!skb) {
                sprintf(pkt_dev->result, "No memory");
                return NULL;
@@ -3727,7 +3729,7 @@ static int __net_init pktgen_create_thread(int cpu, struct pktgen_net *pn)
                return -ENOMEM;
        }
 
-       spin_lock_init(&t->if_lock);
+       mutex_init(&t->if_lock);
        t->cpu = cpu;
 
        INIT_LIST_HEAD(&t->if_list);