net: use netdev_features_t in skb_needs_linearize()
[linux-2.6.git] / net / core / dev.c
index 7e6b7dc..7db83d6 100644 (file)
@@ -73,7 +73,6 @@
  */
 
 #include <asm/uaccess.h>
-#include <asm/system.h>
 #include <linux/bitops.h>
 #include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/inetdevice.h>
 #include <linux/cpu_rmap.h>
 #include <linux/net_tstamp.h>
-#include <linux/jump_label.h>
+#include <linux/static_key.h>
 #include <net/flow_keys.h>
 
 #include "net-sysfs.h"
@@ -446,7 +445,7 @@ void __dev_remove_pack(struct packet_type *pt)
                }
        }
 
-       printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
+       pr_warn("dev_remove_pack: %p not found\n", pt);
 out:
        spin_unlock(&ptype_lock);
 }
@@ -848,21 +847,21 @@ EXPORT_SYMBOL(dev_get_by_flags_rcu);
  *     to allow sysfs to work.  We also disallow any kind of
  *     whitespace.
  */
-int dev_valid_name(const char *name)
+bool dev_valid_name(const char *name)
 {
        if (*name == '\0')
-               return 0;
+               return false;
        if (strlen(name) >= IFNAMSIZ)
-               return 0;
+               return false;
        if (!strcmp(name, ".") || !strcmp(name, ".."))
-               return 0;
+               return false;
 
        while (*name) {
                if (*name == '/' || isspace(*name))
-                       return 0;
+                       return false;
                name++;
        }
-       return 1;
+       return true;
 }
 EXPORT_SYMBOL(dev_valid_name);
 
@@ -1039,8 +1038,7 @@ rollback:
                        memcpy(dev->name, oldname, IFNAMSIZ);
                        goto rollback;
                } else {
-                       printk(KERN_ERR
-                              "%s: name change rollback failed: %d.\n",
+                       pr_err("%s: name change rollback failed: %d\n",
                               dev->name, ret);
                }
        }
@@ -1058,6 +1056,8 @@ rollback:
  */
 int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 {
+       char *new_ifalias;
+
        ASSERT_RTNL();
 
        if (len >= IFALIASZ)
@@ -1071,9 +1071,10 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
                return 0;
        }
 
-       dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
-       if (!dev->ifalias)
+       new_ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
+       if (!new_ifalias)
                return -ENOMEM;
+       dev->ifalias = new_ifalias;
 
        strlcpy(dev->ifalias, alias, len+1);
        return len;
@@ -1139,9 +1140,8 @@ void dev_load(struct net *net, const char *name)
                no_module = request_module("netdev-%s", name);
        if (no_module && capable(CAP_SYS_MODULE)) {
                if (!request_module("%s", name))
-                       pr_err("Loading kernel module for a network device "
-"with CAP_SYS_MODULE (deprecated).  Use CAP_NET_ADMIN and alias netdev-%s "
-"instead\n", name);
+                       pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated).  Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
+                              name);
        }
 }
 EXPORT_SYMBOL(dev_load);
@@ -1176,6 +1176,7 @@ static int __dev_open(struct net_device *dev)
                net_dmaengine_get();
                dev_set_rx_mode(dev);
                dev_activate(dev);
+               add_device_randomness(dev->dev_addr, dev->addr_len);
        }
 
        return ret;
@@ -1412,14 +1413,34 @@ EXPORT_SYMBOL(register_netdevice_notifier);
  *     register_netdevice_notifier(). The notifier is unlinked into the
  *     kernel structures and may then be reused. A negative errno code
  *     is returned on a failure.
+ *
+ *     After unregistering unregister and down device events are synthesized
+ *     for all devices on the device list to the removed notifier to remove
+ *     the need for special case cleanup code.
  */
 
 int unregister_netdevice_notifier(struct notifier_block *nb)
 {
+       struct net_device *dev;
+       struct net *net;
        int err;
 
        rtnl_lock();
        err = raw_notifier_chain_unregister(&netdev_chain, nb);
+       if (err)
+               goto unlock;
+
+       for_each_net(net) {
+               for_each_netdev(net, dev) {
+                       if (dev->flags & IFF_UP) {
+                               nb->notifier_call(nb, NETDEV_GOING_DOWN, dev);
+                               nb->notifier_call(nb, NETDEV_DOWN, dev);
+                       }
+                       nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
+                       nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev);
+               }
+       }
+unlock:
        rtnl_unlock();
        return err;
 }
@@ -1441,11 +1462,11 @@ int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
 }
 EXPORT_SYMBOL(call_netdevice_notifiers);
 
-static struct jump_label_key netstamp_needed __read_mostly;
+static struct static_key netstamp_needed __read_mostly;
 #ifdef HAVE_JUMP_LABEL
-/* We are not allowed to call jump_label_dec() from irq context
+/* We are not allowed to call static_key_slow_dec() from irq context
  * If net_disable_timestamp() is called from irq context, defer the
- * jump_label_dec() calls.
+ * static_key_slow_dec() calls.
  */
 static atomic_t netstamp_needed_deferred;
 #endif
@@ -1457,12 +1478,11 @@ void net_enable_timestamp(void)
 
        if (deferred) {
                while (--deferred)
-                       jump_label_dec(&netstamp_needed);
+                       static_key_slow_dec(&netstamp_needed);
                return;
        }
 #endif
-       WARN_ON(in_interrupt());
-       jump_label_inc(&netstamp_needed);
+       static_key_slow_inc(&netstamp_needed);
 }
 EXPORT_SYMBOL(net_enable_timestamp);
 
@@ -1474,19 +1494,19 @@ void net_disable_timestamp(void)
                return;
        }
 #endif
-       jump_label_dec(&netstamp_needed);
+       static_key_slow_dec(&netstamp_needed);
 }
 EXPORT_SYMBOL(net_disable_timestamp);
 
 static inline void net_timestamp_set(struct sk_buff *skb)
 {
        skb->tstamp.tv64 = 0;
-       if (static_branch(&netstamp_needed))
+       if (static_key_false(&netstamp_needed))
                __net_timestamp(skb);
 }
 
 #define net_timestamp_check(COND, SKB)                 \
-       if (static_branch(&netstamp_needed)) {          \
+       if (static_key_false(&netstamp_needed)) {               \
                if ((COND) && !(SKB)->tstamp.tv64)      \
                        __net_timestamp(SKB);           \
        }                                               \
@@ -1599,10 +1619,16 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
                kfree_skb(skb);
                return NET_RX_DROP;
        }
-       skb_set_dev(skb, dev);
+       skb->skb_iif = 0;
+       skb->dev = dev;
+       skb_dst_drop(skb);
        skb->tstamp.tv64 = 0;
        skb->pkt_type = PACKET_HOST;
        skb->protocol = eth_type_trans(skb, dev);
+       skb->mark = 0;
+       secpath_reset(skb);
+       nf_reset(skb);
+       nf_reset_trace(skb);
        return netif_rx(skb);
 }
 EXPORT_SYMBOL_GPL(dev_forward_skb);
@@ -1615,6 +1641,19 @@ static inline int deliver_skb(struct sk_buff *skb,
        return pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
 }
 
+static inline bool skb_loop_sk(struct packet_type *ptype, struct sk_buff *skb)
+{
+       if (!ptype->af_packet_priv || !skb->sk)
+               return false;
+
+       if (ptype->id_match)
+               return ptype->id_match(ptype, skb->sk);
+       else if ((struct sock *)ptype->af_packet_priv == skb->sk)
+               return true;
+
+       return false;
+}
+
 /*
  *     Support routine. Sends outgoing frames to any network
  *     taps currently in use.
@@ -1632,8 +1671,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
                 * they originated from - MvS (miquels@drinkel.ow.org)
                 */
                if ((ptype->dev == dev || !ptype->dev) &&
-                   (ptype->af_packet_priv == NULL ||
-                    (struct sock *)ptype->af_packet_priv != skb->sk)) {
+                   (!skb_loop_sk(ptype, skb))) {
                        if (pt_prev) {
                                deliver_skb(skb2, pt_prev, skb->dev);
                                pt_prev = ptype;
@@ -1655,10 +1693,9 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
                        if (skb_network_header(skb2) < skb2->data ||
                            skb2->network_header > skb2->tail) {
                                if (net_ratelimit())
-                                       printk(KERN_CRIT "protocol %04x is "
-                                              "buggy, dev %s\n",
-                                              ntohs(skb2->protocol),
-                                              dev->name);
+                                       pr_crit("protocol %04x is buggy, dev %s\n",
+                                               ntohs(skb2->protocol),
+                                               dev->name);
                                skb_reset_network_header(skb2);
                        }
 
@@ -1691,9 +1728,7 @@ static void netif_setup_tc(struct net_device *dev, unsigned int txq)
 
        /* If TC0 is invalidated disable TC mapping */
        if (tc->offset + tc->count > txq) {
-               pr_warning("Number of in use tx queues changed "
-                          "invalidating tc mappings. Priority "
-                          "traffic classification disabled!\n");
+               pr_warn("Number of in use tx queues changed invalidating tc mappings. Priority traffic classification disabled!\n");
                dev->num_tc = 0;
                return;
        }
@@ -1704,11 +1739,8 @@ static void netif_setup_tc(struct net_device *dev, unsigned int txq)
 
                tc = &dev->tc_to_txq[q];
                if (tc->offset + tc->count > txq) {
-                       pr_warning("Number of in use tx queues "
-                                  "changed. Priority %i to tc "
-                                  "mapping %i is no longer valid "
-                                  "setting map to 0\n",
-                                  i, q);
+                       pr_warn("Number of in use tx queues changed. Priority %i to tc mapping %i is no longer valid. Setting map to 0\n",
+                               i, q);
                        netdev_set_prio_tc_map(dev, i, 0);
                }
        }
@@ -1857,35 +1889,25 @@ void netif_device_attach(struct net_device *dev)
 }
 EXPORT_SYMBOL(netif_device_attach);
 
-/**
- * skb_dev_set -- assign a new device to a buffer
- * @skb: buffer for the new device
- * @dev: network device
- *
- * If an skb is owned by a device already, we have to reset
- * all data private to the namespace a device belongs to
- * before assigning it a new device.
- */
-#ifdef CONFIG_NET_NS
-void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
+static void skb_warn_bad_offload(const struct sk_buff *skb)
 {
-       skb_dst_drop(skb);
-       if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) {
-               secpath_reset(skb);
-               nf_reset(skb);
-               skb_init_secmark(skb);
-               skb->mark = 0;
-               skb->priority = 0;
-               skb->nf_trace = 0;
-               skb->ipvs_property = 0;
-#ifdef CONFIG_NET_SCHED
-               skb->tc_index = 0;
-#endif
-       }
-       skb->dev = dev;
+       static const netdev_features_t null_features = 0;
+       struct net_device *dev = skb->dev;
+       const char *driver = "";
+
+       if (!net_ratelimit())
+               return;
+
+       if (dev && dev->dev.parent)
+               driver = dev_driver_string(dev->dev.parent);
+
+       WARN(1, "%s: caps=(%pNF, %pNF) len=%d data_len=%d gso_size=%d "
+            "gso_type=%d ip_summed=%d\n",
+            driver, dev ? &dev->features : &null_features,
+            skb->sk ? &skb->sk->sk_route_caps : &null_features,
+            skb->len, skb->data_len, skb_shinfo(skb)->gso_size,
+            skb_shinfo(skb)->gso_type, skb->ip_summed);
 }
-EXPORT_SYMBOL(skb_set_dev);
-#endif /* CONFIG_NET_NS */
 
 /*
  * Invalidate hardware checksum when packet is to be mangled, and
@@ -1900,8 +1922,8 @@ int skb_checksum_help(struct sk_buff *skb)
                goto out_set_summed;
 
        if (unlikely(skb_shinfo(skb)->gso_size)) {
-               /* Let GSO fix up the checksum. */
-               goto out_set_summed;
+               skb_warn_bad_offload(skb);
+               return -EINVAL;
        }
 
        offset = skb_checksum_start_offset(skb);
@@ -1961,16 +1983,7 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb,
        __skb_pull(skb, skb->mac_len);
 
        if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
-               struct net_device *dev = skb->dev;
-               const char *driver = "";
-
-               if (dev && dev->dev.parent)
-                       driver = dev_driver_string(dev->dev.parent);
-
-               WARN(1, "%s: caps=(%pNF, %pNF) len=%d data_len=%d ip_summed=%d\n",
-                    driver, dev ? &dev->features : NULL,
-                    skb->sk ? &skb->sk->sk_route_caps : NULL,
-                    skb->len, skb->data_len, skb->ip_summed);
+               skb_warn_bad_offload(skb);
 
                if (skb_header_cloned(skb) &&
                    (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
@@ -2006,8 +2019,7 @@ EXPORT_SYMBOL(skb_gso_segment);
 void netdev_rx_csum_fault(struct net_device *dev)
 {
        if (net_ratelimit()) {
-               printk(KERN_ERR "%s: hw csum failure.\n",
-                       dev ? dev->name : "<unknown>");
+               pr_err("%s: hw csum failure\n", dev ? dev->name : "<unknown>");
                dump_stack();
        }
 }
@@ -2098,25 +2110,6 @@ static int dev_gso_segment(struct sk_buff *skb, netdev_features_t features)
        return 0;
 }
 
-/*
- * Try to orphan skb early, right before transmission by the device.
- * We cannot orphan skb if tx timestamp is requested or the sk-reference
- * is needed on driver level for other reasons, e.g. see net/can/raw.c
- */
-static inline void skb_orphan_try(struct sk_buff *skb)
-{
-       struct sock *sk = skb->sk;
-
-       if (sk && !skb_shinfo(skb)->tx_flags) {
-               /* skb_tx_hash() wont be able to get sk.
-                * We copy sk_hash into skb->rxhash
-                */
-               if (!skb->rxhash)
-                       skb->rxhash = sk->sk_hash;
-               skb_orphan(skb);
-       }
-}
-
 static bool can_checksum_protocol(netdev_features_t features, __be16 protocol)
 {
        return ((features & NETIF_F_GEN_CSUM) ||
@@ -2131,7 +2124,8 @@ static bool can_checksum_protocol(netdev_features_t features, __be16 protocol)
 static netdev_features_t harmonize_features(struct sk_buff *skb,
        __be16 protocol, netdev_features_t features)
 {
-       if (!can_checksum_protocol(features, protocol)) {
+       if (skb->ip_summed != CHECKSUM_NONE &&
+           !can_checksum_protocol(features, protocol)) {
                features &= ~NETIF_F_ALL_CSUM;
                features &= ~NETIF_F_SG;
        } else if (illegal_highdma(skb->dev, skb)) {
@@ -2146,6 +2140,9 @@ netdev_features_t netif_skb_features(struct sk_buff *skb)
        __be16 protocol = skb->protocol;
        netdev_features_t features = skb->dev->features;
 
+       if (skb_shinfo(skb)->gso_segs > skb->dev->gso_max_segs)
+               features &= ~NETIF_F_GSO_MASK;
+
        if (protocol == htons(ETH_P_8021Q)) {
                struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
                protocol = veh->h_vlan_encapsulated_proto;
@@ -2173,7 +2170,7 @@ EXPORT_SYMBOL(netif_skb_features);
  *        support DMA from it.
  */
 static inline int skb_needs_linearize(struct sk_buff *skb,
-                                     int features)
+                                     netdev_features_t features)
 {
        return skb_is_nonlinear(skb) &&
                        ((skb_has_frag_list(skb) &&
@@ -2202,8 +2199,6 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
                if (!list_empty(&ptype_all))
                        dev_queue_xmit_nit(skb, dev);
 
-               skb_orphan_try(skb);
-
                features = netif_skb_features(skb);
 
                if (vlan_tx_tag_present(skb) &&
@@ -2313,7 +2308,7 @@ u16 __skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb,
        if (skb->sk && skb->sk->sk_hash)
                hash = skb->sk->sk_hash;
        else
-               hash = (__force u16) skb->protocol ^ skb->rxhash;
+               hash = (__force u16) skb->protocol;
        hash = jhash_1word(hash, hashrnd);
 
        return (u16) (((u64) hash * qcount) >> 32) + qoffset;
@@ -2324,9 +2319,9 @@ static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
 {
        if (unlikely(queue_index >= dev->real_num_tx_queues)) {
                if (net_ratelimit()) {
-                       pr_warning("%s selects TX queue %d, but "
-                               "real number of TX queues is %d\n",
-                               dev->name, queue_index, dev->real_num_tx_queues);
+                       pr_warn("%s selects TX queue %d, but real number of TX queues is %d\n",
+                               dev->name, queue_index,
+                               dev->real_num_tx_queues);
                }
                return 0;
        }
@@ -2570,16 +2565,16 @@ int dev_queue_xmit(struct sk_buff *skb)
                        }
                        HARD_TX_UNLOCK(dev, txq);
                        if (net_ratelimit())
-                               printk(KERN_CRIT "Virtual device %s asks to "
-                                      "queue packet!\n", dev->name);
+                               pr_crit("Virtual device %s asks to queue packet!\n",
+                                       dev->name);
                } else {
                        /* Recursion is detected! It is possible,
                         * unfortunately
                         */
 recursion_alert:
                        if (net_ratelimit())
-                               printk(KERN_CRIT "Dead loop on virtual device "
-                                      "%s, fix it urgently!\n", dev->name);
+                               pr_crit("Dead loop on virtual device %s, fix it urgently!\n",
+                                       dev->name);
                }
        }
 
@@ -2626,15 +2621,16 @@ void __skb_get_rxhash(struct sk_buff *skb)
        if (!skb_flow_dissect(skb, &keys))
                return;
 
-       if (keys.ports) {
-               if ((__force u16)keys.port16[1] < (__force u16)keys.port16[0])
-                       swap(keys.port16[0], keys.port16[1]);
+       if (keys.ports)
                skb->l4_rxhash = 1;
-       }
 
        /* get a consistent hash (same value on both flow directions) */
-       if ((__force u32)keys.dst < (__force u32)keys.src)
+       if (((__force u32)keys.dst < (__force u32)keys.src) ||
+           (((__force u32)keys.dst == (__force u32)keys.src) &&
+            ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]))) {
                swap(keys.dst, keys.src);
+               swap(keys.port16[0], keys.port16[1]);
+       }
 
        hash = jhash_3words((__force u32)keys.dst,
                            (__force u32)keys.src,
@@ -2652,7 +2648,7 @@ EXPORT_SYMBOL(__skb_get_rxhash);
 struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly;
 EXPORT_SYMBOL(rps_sock_flow_table);
 
-struct jump_label_key rps_needed __read_mostly;
+struct static_key rps_needed __read_mostly;
 
 static struct rps_dev_flow *
 set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
@@ -2770,8 +2766,10 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
                if (unlikely(tcpu != next_cpu) &&
                    (tcpu == RPS_NO_CPU || !cpu_online(tcpu) ||
                     ((int)(per_cpu(softnet_data, tcpu).input_queue_head -
-                     rflow->last_qtail)) >= 0))
+                     rflow->last_qtail)) >= 0)) {
+                       tcpu = next_cpu;
                        rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
+               }
 
                if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) {
                        *rflowp = rflow;
@@ -2937,7 +2935,7 @@ int netif_rx(struct sk_buff *skb)
 
        trace_netif_rx(skb);
 #ifdef CONFIG_RPS
-       if (static_branch(&rps_needed)) {
+       if (static_key_false(&rps_needed)) {
                struct rps_dev_flow voidflow, *rflow = &voidflow;
                int cpu;
 
@@ -3061,8 +3059,8 @@ static int ing_filter(struct sk_buff *skb, struct netdev_queue *rxq)
 
        if (unlikely(MAX_RED_LOOP < ttl++)) {
                if (net_ratelimit())
-                       pr_warning( "Redir loop detected Dropping packet (%d->%d)\n",
-                              skb->skb_iif, dev->ifindex);
+                       pr_warn("Redir loop detected Dropping packet (%d->%d)\n",
+                               skb->skb_iif, dev->ifindex);
                return TC_ACT_SHOT;
        }
 
@@ -3130,6 +3128,7 @@ int netdev_rx_handler_register(struct net_device *dev,
        if (dev->rx_handler)
                return -EBUSY;
 
+       /* Note: rx_handler_data must be set before rx_handler */
        rcu_assign_pointer(dev->rx_handler_data, rx_handler_data);
        rcu_assign_pointer(dev->rx_handler, rx_handler);
 
@@ -3150,6 +3149,11 @@ void netdev_rx_handler_unregister(struct net_device *dev)
 
        ASSERT_RTNL();
        RCU_INIT_POINTER(dev->rx_handler, NULL);
+       /* a reader seeing a non NULL rx_handler in a rcu_read_lock()
+        * section has a guarantee to see a non NULL rx_handler_data
+        * as well.
+        */
+       synchronize_net();
        RCU_INIT_POINTER(dev->rx_handler_data, NULL);
 }
 EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister);
@@ -3216,18 +3220,18 @@ another_round:
 ncls:
 #endif
 
-       rx_handler = rcu_dereference(skb->dev->rx_handler);
        if (vlan_tx_tag_present(skb)) {
                if (pt_prev) {
                        ret = deliver_skb(skb, pt_prev, orig_dev);
                        pt_prev = NULL;
                }
-               if (vlan_do_receive(&skb, !rx_handler))
+               if (vlan_do_receive(&skb))
                        goto another_round;
                else if (unlikely(!skb))
                        goto out;
        }
 
+       rx_handler = rcu_dereference(skb->dev->rx_handler);
        if (rx_handler) {
                if (pt_prev) {
                        ret = deliver_skb(skb, pt_prev, orig_dev);
@@ -3235,6 +3239,7 @@ ncls:
                }
                switch (rx_handler(&skb)) {
                case RX_HANDLER_CONSUMED:
+                       ret = NET_RX_SUCCESS;
                        goto out;
                case RX_HANDLER_ANOTHER:
                        goto another_round;
@@ -3247,6 +3252,9 @@ ncls:
                }
        }
 
+       if (vlan_tx_nonzero_tag_present(skb))
+               skb->pkt_type = PACKET_OTHERHOST;
+
        /* deliver only exact match when indicated */
        null_or_dev = deliver_exact ? skb->dev : NULL;
 
@@ -3301,7 +3309,7 @@ int netif_receive_skb(struct sk_buff *skb)
                return NET_RX_SUCCESS;
 
 #ifdef CONFIG_RPS
-       if (static_branch(&rps_needed)) {
+       if (static_key_false(&rps_needed)) {
                struct rps_dev_flow voidflow, *rflow = &voidflow;
                int cpu, ret;
 
@@ -3492,14 +3500,20 @@ static inline gro_result_t
 __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
 {
        struct sk_buff *p;
+       unsigned int maclen = skb->dev->hard_header_len;
 
        for (p = napi->gro_list; p; p = p->next) {
                unsigned long diffs;
 
                diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev;
                diffs |= p->vlan_tci ^ skb->vlan_tci;
-               diffs |= compare_ether_header(skb_mac_header(p),
-                                             skb_gro_mac_header(skb));
+               if (maclen == ETH_HLEN)
+                       diffs |= compare_ether_header(skb_mac_header(p),
+                                                     skb_gro_mac_header(skb));
+               else if (!diffs)
+                       diffs = memcmp(skb_mac_header(p),
+                                      skb_gro_mac_header(skb),
+                                      maclen);
                NAPI_GRO_CB(p)->same_flow = !diffs;
                NAPI_GRO_CB(p)->flush = 0;
        }
@@ -3555,7 +3569,8 @@ EXPORT_SYMBOL(napi_gro_receive);
 static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
 {
        __skb_pull(skb, skb_headlen(skb));
-       skb_reserve(skb, NET_IP_ALIGN - skb_headroom(skb));
+       /* restore the reserve we had after netdev_alloc_skb_ip_align() */
+       skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN - skb_headroom(skb));
        skb->vlan_tci = 0;
        skb->dev = napi->dev;
        skb->skb_iif = 0;
@@ -4022,54 +4037,41 @@ static int dev_ifconf(struct net *net, char __user *arg)
 
 #ifdef CONFIG_PROC_FS
 
-#define BUCKET_SPACE (32 - NETDEV_HASHBITS)
-
-struct dev_iter_state {
-       struct seq_net_private p;
-       unsigned int pos; /* bucket << BUCKET_SPACE + offset */
-};
+#define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
 
 #define get_bucket(x) ((x) >> BUCKET_SPACE)
 #define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1))
 #define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o))
 
-static inline struct net_device *dev_from_same_bucket(struct seq_file *seq)
+static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff_t *pos)
 {
-       struct dev_iter_state *state = seq->private;
        struct net *net = seq_file_net(seq);
        struct net_device *dev;
        struct hlist_node *p;
        struct hlist_head *h;
-       unsigned int count, bucket, offset;
+       unsigned int count = 0, offset = get_offset(*pos);
 
-       bucket = get_bucket(state->pos);
-       offset = get_offset(state->pos);
-       h = &net->dev_name_head[bucket];
-       count = 0;
+       h = &net->dev_name_head[get_bucket(*pos)];
        hlist_for_each_entry_rcu(dev, p, h, name_hlist) {
-               if (count++ == offset) {
-                       state->pos = set_bucket_offset(bucket, count);
+               if (++count == offset)
                        return dev;
-               }
        }
 
        return NULL;
 }
 
-static inline struct net_device *dev_from_new_bucket(struct seq_file *seq)
+static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *pos)
 {
-       struct dev_iter_state *state = seq->private;
        struct net_device *dev;
        unsigned int bucket;
 
-       bucket = get_bucket(state->pos);
        do {
-               dev = dev_from_same_bucket(seq);
+               dev = dev_from_same_bucket(seq, pos);
                if (dev)
                        return dev;
 
-               bucket++;
-               state->pos = set_bucket_offset(bucket, 0);
+               bucket = get_bucket(*pos) + 1;
+               *pos = set_bucket_offset(bucket, 1);
        } while (bucket < NETDEV_HASHENTRIES);
 
        return NULL;
@@ -4082,33 +4084,20 @@ static inline struct net_device *dev_from_new_bucket(struct seq_file *seq)
 void *dev_seq_start(struct seq_file *seq, loff_t *pos)
        __acquires(RCU)
 {
-       struct dev_iter_state *state = seq->private;
-
        rcu_read_lock();
        if (!*pos)
                return SEQ_START_TOKEN;
 
-       /* check for end of the hash */
-       if (state->pos == 0 && *pos > 1)
+       if (get_bucket(*pos) >= NETDEV_HASHENTRIES)
                return NULL;
 
-       return dev_from_new_bucket(seq);
+       return dev_from_bucket(seq, pos);
 }
 
 void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
-       struct net_device *dev;
-
        ++*pos;
-
-       if (v == SEQ_START_TOKEN)
-               return dev_from_new_bucket(seq);
-
-       dev = dev_from_same_bucket(seq);
-       if (dev)
-               return dev;
-
-       return dev_from_new_bucket(seq);
+       return dev_from_bucket(seq, pos);
 }
 
 void dev_seq_stop(struct seq_file *seq, void *v)
@@ -4207,13 +4196,7 @@ static const struct seq_operations dev_seq_ops = {
 static int dev_seq_open(struct inode *inode, struct file *file)
 {
        return seq_open_net(inode, file, &dev_seq_ops,
-                           sizeof(struct dev_iter_state));
-}
-
-int dev_seq_open_ops(struct inode *inode, struct file *file,
-                    const struct seq_operations *ops)
-{
-       return seq_open_net(inode, file, ops, sizeof(struct dev_iter_state));
+                           sizeof(struct seq_net_private));
 }
 
 static const struct file_operations dev_seq_fops = {
@@ -4483,16 +4466,15 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc)
                        dev->flags &= ~IFF_PROMISC;
                else {
                        dev->promiscuity -= inc;
-                       printk(KERN_WARNING "%s: promiscuity touches roof, "
-                               "set promiscuity failed, promiscuity feature "
-                               "of device might be broken.\n", dev->name);
+                       pr_warn("%s: promiscuity touches roof, set promiscuity failed. promiscuity feature of device might be broken.\n",
+                               dev->name);
                        return -EOVERFLOW;
                }
        }
        if (dev->flags != old_flags) {
-               printk(KERN_INFO "device %s %s promiscuous mode\n",
-                      dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
-                                                              "left");
+               pr_info("device %s %s promiscuous mode\n",
+                       dev->name,
+                       dev->flags & IFF_PROMISC ? "entered" : "left");
                if (audit_enabled) {
                        current_uid_gid(&uid, &gid);
                        audit_log(current->audit_context, GFP_ATOMIC,
@@ -4565,9 +4547,8 @@ int dev_set_allmulti(struct net_device *dev, int inc)
                        dev->flags &= ~IFF_ALLMULTI;
                else {
                        dev->allmulti -= inc;
-                       printk(KERN_WARNING "%s: allmulti touches roof, "
-                               "set allmulti failed, allmulti feature of "
-                               "device might be broken.\n", dev->name);
+                       pr_warn("%s: allmulti touches roof, set allmulti failed. allmulti feature of device might be broken.\n",
+                               dev->name);
                        return -EOVERFLOW;
                }
        }
@@ -4820,6 +4801,7 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
        err = ops->ndo_set_mac_address(dev, sa);
        if (!err)
                call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
+       add_device_randomness(dev->dev_addr, dev->addr_len);
        return err;
 }
 EXPORT_SYMBOL(dev_set_mac_address);
@@ -5224,8 +5206,8 @@ static void rollback_registered_many(struct list_head *head)
                 * devices and proceed with the remaining.
                 */
                if (dev->reg_state == NETREG_UNINITIALIZED) {
-                       pr_debug("unregister_netdevice: device %s/%p never "
-                                "was registered\n", dev->name, dev);
+                       pr_debug("unregister_netdevice: device %s/%p never was registered\n",
+                                dev->name, dev);
 
                        WARN_ON(1);
                        list_del(&dev->unreg_list);
@@ -5457,7 +5439,7 @@ static int netif_alloc_rx_queues(struct net_device *dev)
 
        rx = kcalloc(count, sizeof(struct netdev_rx_queue), GFP_KERNEL);
        if (!rx) {
-               pr_err("netdev: Unable to allocate %u rx queues.\n", count);
+               pr_err("netdev: Unable to allocate %u rx queues\n", count);
                return -ENOMEM;
        }
        dev->_rx = rx;
@@ -5491,8 +5473,7 @@ static int netif_alloc_netdev_queues(struct net_device *dev)
 
        tx = kcalloc(count, sizeof(struct netdev_queue), GFP_KERNEL);
        if (!tx) {
-               pr_err("netdev: Unable to allocate %u tx queues.\n",
-                      count);
+               pr_err("netdev: Unable to allocate %u tx queues\n", count);
                return -ENOMEM;
        }
        dev->_tx = tx;
@@ -5599,6 +5580,7 @@ int register_netdevice(struct net_device *dev)
        dev_init_scheduler(dev);
        dev_hold(dev);
        list_netdevice(dev);
+       add_device_randomness(dev->dev_addr, dev->addr_len);
 
        /* Notify protocols, that a new device appeared. */
        ret = call_netdevice_notifiers(NETDEV_REGISTER, dev);
@@ -5751,10 +5733,8 @@ static void netdev_wait_allrefs(struct net_device *dev)
                refcnt = netdev_refcnt_read(dev);
 
                if (time_after(jiffies, warning_time + 10 * HZ)) {
-                       printk(KERN_EMERG "unregister_netdevice: "
-                              "waiting for %s to become free. Usage "
-                              "count = %d\n",
-                              dev->name, refcnt);
+                       pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n",
+                                dev->name, refcnt);
                        warning_time = jiffies;
                }
        }
@@ -5805,7 +5785,7 @@ void netdev_run_todo(void)
                list_del(&dev->todo_list);
 
                if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
-                       printk(KERN_ERR "network todo '%s' but state %d\n",
+                       pr_err("network todo '%s' but state %d\n",
                               dev->name, dev->reg_state);
                        dump_stack();
                        continue;
@@ -5834,12 +5814,12 @@ void netdev_run_todo(void)
 /* Convert net_device_stats to rtnl_link_stats64.  They have the same
  * fields in the same order, with only the type differing.
  */
-static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
-                                   const struct net_device_stats *netdev_stats)
+void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
+                            const struct net_device_stats *netdev_stats)
 {
 #if BITS_PER_LONG == 64
-        BUILD_BUG_ON(sizeof(*stats64) != sizeof(*netdev_stats));
-        memcpy(stats64, netdev_stats, sizeof(*stats64));
+       BUILD_BUG_ON(sizeof(*stats64) != sizeof(*netdev_stats));
+       memcpy(stats64, netdev_stats, sizeof(*stats64));
 #else
        size_t i, n = sizeof(*stats64) / sizeof(u64);
        const unsigned long *src = (const unsigned long *)netdev_stats;
@@ -5851,6 +5831,7 @@ static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
                dst[i] = src[i];
 #endif
 }
+EXPORT_SYMBOL(netdev_stats_to_stats64);
 
 /**
  *     dev_get_stats   - get network device statistics
@@ -5921,15 +5902,13 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
        BUG_ON(strlen(name) >= sizeof(dev->name));
 
        if (txqs < 1) {
-               pr_err("alloc_netdev: Unable to allocate device "
-                      "with zero queues.\n");
+               pr_err("alloc_netdev: Unable to allocate device with zero queues\n");
                return NULL;
        }
 
 #ifdef CONFIG_RPS
        if (rxqs < 1) {
-               pr_err("alloc_netdev: Unable to allocate device "
-                      "with zero RX queues.\n");
+               pr_err("alloc_netdev: Unable to allocate device with zero RX queues\n");
                return NULL;
        }
 #endif
@@ -5945,7 +5924,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 
        p = kzalloc(alloc_size, GFP_KERNEL);
        if (!p) {
-               printk(KERN_ERR "alloc_netdev: Unable to allocate device.\n");
+               pr_err("alloc_netdev: Unable to allocate device\n");
                return NULL;
        }
 
@@ -5965,6 +5944,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
        dev_net_set(dev, &init_net);
 
        dev->gso_max_size = GSO_MAX_SIZE;
+       dev->gso_max_segs = GSO_MAX_SEGS;
 
        INIT_LIST_HEAD(&dev->napi_list);
        INIT_LIST_HEAD(&dev->unreg_list);
@@ -6340,7 +6320,8 @@ static struct hlist_head *netdev_create_hash(void)
 /* Initialize per network namespace state */
 static int __net_init netdev_init(struct net *net)
 {
-       INIT_LIST_HEAD(&net->dev_base_head);
+       if (net != &init_net)
+               INIT_LIST_HEAD(&net->dev_base_head);
 
        net->dev_name_head = netdev_create_hash();
        if (net->dev_name_head == NULL)
@@ -6478,8 +6459,8 @@ static void __net_exit default_device_exit(struct net *net)
                snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
                err = dev_change_net_namespace(dev, &init_net, fb_name);
                if (err) {
-                       printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n",
-                               __func__, dev->name, err);
+                       pr_emerg("%s: failed to move %s to init_net: %d\n",
+                                __func__, dev->name, err);
                        BUG();
                }
        }