diff options
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 342 |
1 files changed, 140 insertions, 202 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index 6ba50a1e404c..115dee1d985d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -133,10 +133,9 @@ | |||
133 | #include <linux/pci.h> | 133 | #include <linux/pci.h> |
134 | #include <linux/inetdevice.h> | 134 | #include <linux/inetdevice.h> |
135 | #include <linux/cpu_rmap.h> | 135 | #include <linux/cpu_rmap.h> |
136 | #include <linux/if_tunnel.h> | ||
137 | #include <linux/if_pppox.h> | ||
138 | #include <linux/ppp_defs.h> | ||
139 | #include <linux/net_tstamp.h> | 136 | #include <linux/net_tstamp.h> |
137 | #include <linux/jump_label.h> | ||
138 | #include <net/flow_keys.h> | ||
140 | 139 | ||
141 | #include "net-sysfs.h" | 140 | #include "net-sysfs.h" |
142 | 141 | ||
@@ -1320,8 +1319,6 @@ EXPORT_SYMBOL(dev_close); | |||
1320 | */ | 1319 | */ |
1321 | void dev_disable_lro(struct net_device *dev) | 1320 | void dev_disable_lro(struct net_device *dev) |
1322 | { | 1321 | { |
1323 | u32 flags; | ||
1324 | |||
1325 | /* | 1322 | /* |
1326 | * If we're trying to disable lro on a vlan device | 1323 | * If we're trying to disable lro on a vlan device |
1327 | * use the underlying physical device instead | 1324 | * use the underlying physical device instead |
@@ -1329,15 +1326,9 @@ void dev_disable_lro(struct net_device *dev) | |||
1329 | if (is_vlan_dev(dev)) | 1326 | if (is_vlan_dev(dev)) |
1330 | dev = vlan_dev_real_dev(dev); | 1327 | dev = vlan_dev_real_dev(dev); |
1331 | 1328 | ||
1332 | if (dev->ethtool_ops && dev->ethtool_ops->get_flags) | 1329 | dev->wanted_features &= ~NETIF_F_LRO; |
1333 | flags = dev->ethtool_ops->get_flags(dev); | 1330 | netdev_update_features(dev); |
1334 | else | ||
1335 | flags = ethtool_op_get_flags(dev); | ||
1336 | |||
1337 | if (!(flags & ETH_FLAG_LRO)) | ||
1338 | return; | ||
1339 | 1331 | ||
1340 | __ethtool_set_flags(dev, flags & ~ETH_FLAG_LRO); | ||
1341 | if (unlikely(dev->features & NETIF_F_LRO)) | 1332 | if (unlikely(dev->features & NETIF_F_LRO)) |
1342 | netdev_WARN(dev, "failed to disable LRO!\n"); | 1333 | netdev_WARN(dev, "failed to disable LRO!\n"); |
1343 | } | 1334 | } |
@@ -1396,7 +1387,7 @@ rollback: | |||
1396 | for_each_net(net) { | 1387 | for_each_net(net) { |
1397 | for_each_netdev(net, dev) { | 1388 | for_each_netdev(net, dev) { |
1398 | if (dev == last) | 1389 | if (dev == last) |
1399 | break; | 1390 | goto outroll; |
1400 | 1391 | ||
1401 | if (dev->flags & IFF_UP) { | 1392 | if (dev->flags & IFF_UP) { |
1402 | nb->notifier_call(nb, NETDEV_GOING_DOWN, dev); | 1393 | nb->notifier_call(nb, NETDEV_GOING_DOWN, dev); |
@@ -1407,6 +1398,7 @@ rollback: | |||
1407 | } | 1398 | } |
1408 | } | 1399 | } |
1409 | 1400 | ||
1401 | outroll: | ||
1410 | raw_notifier_chain_unregister(&netdev_chain, nb); | 1402 | raw_notifier_chain_unregister(&netdev_chain, nb); |
1411 | goto unlock; | 1403 | goto unlock; |
1412 | } | 1404 | } |
@@ -1449,34 +1441,55 @@ int call_netdevice_notifiers(unsigned long val, struct net_device *dev) | |||
1449 | } | 1441 | } |
1450 | EXPORT_SYMBOL(call_netdevice_notifiers); | 1442 | EXPORT_SYMBOL(call_netdevice_notifiers); |
1451 | 1443 | ||
1452 | /* When > 0 there are consumers of rx skb time stamps */ | 1444 | static struct jump_label_key netstamp_needed __read_mostly; |
1453 | static atomic_t netstamp_needed = ATOMIC_INIT(0); | 1445 | #ifdef HAVE_JUMP_LABEL |
1446 | /* We are not allowed to call jump_label_dec() from irq context | ||
1447 | * If net_disable_timestamp() is called from irq context, defer the | ||
1448 | * jump_label_dec() calls. | ||
1449 | */ | ||
1450 | static atomic_t netstamp_needed_deferred; | ||
1451 | #endif | ||
1454 | 1452 | ||
1455 | void net_enable_timestamp(void) | 1453 | void net_enable_timestamp(void) |
1456 | { | 1454 | { |
1457 | atomic_inc(&netstamp_needed); | 1455 | #ifdef HAVE_JUMP_LABEL |
1456 | int deferred = atomic_xchg(&netstamp_needed_deferred, 0); | ||
1457 | |||
1458 | if (deferred) { | ||
1459 | while (--deferred) | ||
1460 | jump_label_dec(&netstamp_needed); | ||
1461 | return; | ||
1462 | } | ||
1463 | #endif | ||
1464 | WARN_ON(in_interrupt()); | ||
1465 | jump_label_inc(&netstamp_needed); | ||
1458 | } | 1466 | } |
1459 | EXPORT_SYMBOL(net_enable_timestamp); | 1467 | EXPORT_SYMBOL(net_enable_timestamp); |
1460 | 1468 | ||
1461 | void net_disable_timestamp(void) | 1469 | void net_disable_timestamp(void) |
1462 | { | 1470 | { |
1463 | atomic_dec(&netstamp_needed); | 1471 | #ifdef HAVE_JUMP_LABEL |
1472 | if (in_interrupt()) { | ||
1473 | atomic_inc(&netstamp_needed_deferred); | ||
1474 | return; | ||
1475 | } | ||
1476 | #endif | ||
1477 | jump_label_dec(&netstamp_needed); | ||
1464 | } | 1478 | } |
1465 | EXPORT_SYMBOL(net_disable_timestamp); | 1479 | EXPORT_SYMBOL(net_disable_timestamp); |
1466 | 1480 | ||
1467 | static inline void net_timestamp_set(struct sk_buff *skb) | 1481 | static inline void net_timestamp_set(struct sk_buff *skb) |
1468 | { | 1482 | { |
1469 | if (atomic_read(&netstamp_needed)) | 1483 | skb->tstamp.tv64 = 0; |
1484 | if (static_branch(&netstamp_needed)) | ||
1470 | __net_timestamp(skb); | 1485 | __net_timestamp(skb); |
1471 | else | ||
1472 | skb->tstamp.tv64 = 0; | ||
1473 | } | 1486 | } |
1474 | 1487 | ||
1475 | static inline void net_timestamp_check(struct sk_buff *skb) | 1488 | #define net_timestamp_check(COND, SKB) \ |
1476 | { | 1489 | if (static_branch(&netstamp_needed)) { \ |
1477 | if (!skb->tstamp.tv64 && atomic_read(&netstamp_needed)) | 1490 | if ((COND) && !(SKB)->tstamp.tv64) \ |
1478 | __net_timestamp(skb); | 1491 | __net_timestamp(SKB); \ |
1479 | } | 1492 | } \ |
1480 | 1493 | ||
1481 | static int net_hwtstamp_validate(struct ifreq *ifr) | 1494 | static int net_hwtstamp_validate(struct ifreq *ifr) |
1482 | { | 1495 | { |
@@ -1874,6 +1887,23 @@ void skb_set_dev(struct sk_buff *skb, struct net_device *dev) | |||
1874 | EXPORT_SYMBOL(skb_set_dev); | 1887 | EXPORT_SYMBOL(skb_set_dev); |
1875 | #endif /* CONFIG_NET_NS */ | 1888 | #endif /* CONFIG_NET_NS */ |
1876 | 1889 | ||
1890 | static void skb_warn_bad_offload(const struct sk_buff *skb) | ||
1891 | { | ||
1892 | static const netdev_features_t null_features = 0; | ||
1893 | struct net_device *dev = skb->dev; | ||
1894 | const char *driver = ""; | ||
1895 | |||
1896 | if (dev && dev->dev.parent) | ||
1897 | driver = dev_driver_string(dev->dev.parent); | ||
1898 | |||
1899 | WARN(1, "%s: caps=(%pNF, %pNF) len=%d data_len=%d gso_size=%d " | ||
1900 | "gso_type=%d ip_summed=%d\n", | ||
1901 | driver, dev ? &dev->features : &null_features, | ||
1902 | skb->sk ? &skb->sk->sk_route_caps : &null_features, | ||
1903 | skb->len, skb->data_len, skb_shinfo(skb)->gso_size, | ||
1904 | skb_shinfo(skb)->gso_type, skb->ip_summed); | ||
1905 | } | ||
1906 | |||
1877 | /* | 1907 | /* |
1878 | * Invalidate hardware checksum when packet is to be mangled, and | 1908 | * Invalidate hardware checksum when packet is to be mangled, and |
1879 | * complete checksum manually on outgoing path. | 1909 | * complete checksum manually on outgoing path. |
@@ -1887,8 +1917,8 @@ int skb_checksum_help(struct sk_buff *skb) | |||
1887 | goto out_set_summed; | 1917 | goto out_set_summed; |
1888 | 1918 | ||
1889 | if (unlikely(skb_shinfo(skb)->gso_size)) { | 1919 | if (unlikely(skb_shinfo(skb)->gso_size)) { |
1890 | /* Let GSO fix up the checksum. */ | 1920 | skb_warn_bad_offload(skb); |
1891 | goto out_set_summed; | 1921 | return -EINVAL; |
1892 | } | 1922 | } |
1893 | 1923 | ||
1894 | offset = skb_checksum_start_offset(skb); | 1924 | offset = skb_checksum_start_offset(skb); |
@@ -1923,7 +1953,8 @@ EXPORT_SYMBOL(skb_checksum_help); | |||
1923 | * It may return NULL if the skb requires no segmentation. This is | 1953 | * It may return NULL if the skb requires no segmentation. This is |
1924 | * only possible when GSO is used for verifying header integrity. | 1954 | * only possible when GSO is used for verifying header integrity. |
1925 | */ | 1955 | */ |
1926 | struct sk_buff *skb_gso_segment(struct sk_buff *skb, u32 features) | 1956 | struct sk_buff *skb_gso_segment(struct sk_buff *skb, |
1957 | netdev_features_t features) | ||
1927 | { | 1958 | { |
1928 | struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); | 1959 | struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); |
1929 | struct packet_type *ptype; | 1960 | struct packet_type *ptype; |
@@ -1947,16 +1978,7 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, u32 features) | |||
1947 | __skb_pull(skb, skb->mac_len); | 1978 | __skb_pull(skb, skb->mac_len); |
1948 | 1979 | ||
1949 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { | 1980 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { |
1950 | struct net_device *dev = skb->dev; | 1981 | skb_warn_bad_offload(skb); |
1951 | struct ethtool_drvinfo info = {}; | ||
1952 | |||
1953 | if (dev && dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) | ||
1954 | dev->ethtool_ops->get_drvinfo(dev, &info); | ||
1955 | |||
1956 | WARN(1, "%s: caps=(0x%lx, 0x%lx) len=%d data_len=%d ip_summed=%d\n", | ||
1957 | info.driver, dev ? dev->features : 0L, | ||
1958 | skb->sk ? skb->sk->sk_route_caps : 0L, | ||
1959 | skb->len, skb->data_len, skb->ip_summed); | ||
1960 | 1982 | ||
1961 | if (skb_header_cloned(skb) && | 1983 | if (skb_header_cloned(skb) && |
1962 | (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) | 1984 | (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) |
@@ -2064,7 +2086,7 @@ static void dev_gso_skb_destructor(struct sk_buff *skb) | |||
2064 | * This function segments the given skb and stores the list of segments | 2086 | * This function segments the given skb and stores the list of segments |
2065 | * in skb->next. | 2087 | * in skb->next. |
2066 | */ | 2088 | */ |
2067 | static int dev_gso_segment(struct sk_buff *skb, int features) | 2089 | static int dev_gso_segment(struct sk_buff *skb, netdev_features_t features) |
2068 | { | 2090 | { |
2069 | struct sk_buff *segs; | 2091 | struct sk_buff *segs; |
2070 | 2092 | ||
@@ -2103,7 +2125,7 @@ static inline void skb_orphan_try(struct sk_buff *skb) | |||
2103 | } | 2125 | } |
2104 | } | 2126 | } |
2105 | 2127 | ||
2106 | static bool can_checksum_protocol(unsigned long features, __be16 protocol) | 2128 | static bool can_checksum_protocol(netdev_features_t features, __be16 protocol) |
2107 | { | 2129 | { |
2108 | return ((features & NETIF_F_GEN_CSUM) || | 2130 | return ((features & NETIF_F_GEN_CSUM) || |
2109 | ((features & NETIF_F_V4_CSUM) && | 2131 | ((features & NETIF_F_V4_CSUM) && |
@@ -2114,7 +2136,8 @@ static bool can_checksum_protocol(unsigned long features, __be16 protocol) | |||
2114 | protocol == htons(ETH_P_FCOE))); | 2136 | protocol == htons(ETH_P_FCOE))); |
2115 | } | 2137 | } |
2116 | 2138 | ||
2117 | static u32 harmonize_features(struct sk_buff *skb, __be16 protocol, u32 features) | 2139 | static netdev_features_t harmonize_features(struct sk_buff *skb, |
2140 | __be16 protocol, netdev_features_t features) | ||
2118 | { | 2141 | { |
2119 | if (!can_checksum_protocol(features, protocol)) { | 2142 | if (!can_checksum_protocol(features, protocol)) { |
2120 | features &= ~NETIF_F_ALL_CSUM; | 2143 | features &= ~NETIF_F_ALL_CSUM; |
@@ -2126,10 +2149,10 @@ static u32 harmonize_features(struct sk_buff *skb, __be16 protocol, u32 features | |||
2126 | return features; | 2149 | return features; |
2127 | } | 2150 | } |
2128 | 2151 | ||
2129 | u32 netif_skb_features(struct sk_buff *skb) | 2152 | netdev_features_t netif_skb_features(struct sk_buff *skb) |
2130 | { | 2153 | { |
2131 | __be16 protocol = skb->protocol; | 2154 | __be16 protocol = skb->protocol; |
2132 | u32 features = skb->dev->features; | 2155 | netdev_features_t features = skb->dev->features; |
2133 | 2156 | ||
2134 | if (protocol == htons(ETH_P_8021Q)) { | 2157 | if (protocol == htons(ETH_P_8021Q)) { |
2135 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; | 2158 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
@@ -2175,7 +2198,7 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, | |||
2175 | unsigned int skb_len; | 2198 | unsigned int skb_len; |
2176 | 2199 | ||
2177 | if (likely(!skb->next)) { | 2200 | if (likely(!skb->next)) { |
2178 | u32 features; | 2201 | netdev_features_t features; |
2179 | 2202 | ||
2180 | /* | 2203 | /* |
2181 | * If device doesn't need skb->dst, release it right now while | 2204 | * If device doesn't need skb->dst, release it right now while |
@@ -2256,7 +2279,7 @@ gso: | |||
2256 | return rc; | 2279 | return rc; |
2257 | } | 2280 | } |
2258 | txq_trans_update(txq); | 2281 | txq_trans_update(txq); |
2259 | if (unlikely(netif_tx_queue_stopped(txq) && skb->next)) | 2282 | if (unlikely(netif_xmit_stopped(txq) && skb->next)) |
2260 | return NETDEV_TX_BUSY; | 2283 | return NETDEV_TX_BUSY; |
2261 | } while (skb->next); | 2284 | } while (skb->next); |
2262 | 2285 | ||
@@ -2456,6 +2479,18 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, | |||
2456 | return rc; | 2479 | return rc; |
2457 | } | 2480 | } |
2458 | 2481 | ||
2482 | #if IS_ENABLED(CONFIG_NETPRIO_CGROUP) | ||
2483 | static void skb_update_prio(struct sk_buff *skb) | ||
2484 | { | ||
2485 | struct netprio_map *map = rcu_dereference_bh(skb->dev->priomap); | ||
2486 | |||
2487 | if ((!skb->priority) && (skb->sk) && map) | ||
2488 | skb->priority = map->priomap[skb->sk->sk_cgrp_prioidx]; | ||
2489 | } | ||
2490 | #else | ||
2491 | #define skb_update_prio(skb) | ||
2492 | #endif | ||
2493 | |||
2459 | static DEFINE_PER_CPU(int, xmit_recursion); | 2494 | static DEFINE_PER_CPU(int, xmit_recursion); |
2460 | #define RECURSION_LIMIT 10 | 2495 | #define RECURSION_LIMIT 10 |
2461 | 2496 | ||
@@ -2496,6 +2531,8 @@ int dev_queue_xmit(struct sk_buff *skb) | |||
2496 | */ | 2531 | */ |
2497 | rcu_read_lock_bh(); | 2532 | rcu_read_lock_bh(); |
2498 | 2533 | ||
2534 | skb_update_prio(skb); | ||
2535 | |||
2499 | txq = dev_pick_tx(dev, skb); | 2536 | txq = dev_pick_tx(dev, skb); |
2500 | q = rcu_dereference_bh(txq->qdisc); | 2537 | q = rcu_dereference_bh(txq->qdisc); |
2501 | 2538 | ||
@@ -2530,7 +2567,7 @@ int dev_queue_xmit(struct sk_buff *skb) | |||
2530 | 2567 | ||
2531 | HARD_TX_LOCK(dev, txq, cpu); | 2568 | HARD_TX_LOCK(dev, txq, cpu); |
2532 | 2569 | ||
2533 | if (!netif_tx_queue_stopped(txq)) { | 2570 | if (!netif_xmit_stopped(txq)) { |
2534 | __this_cpu_inc(xmit_recursion); | 2571 | __this_cpu_inc(xmit_recursion); |
2535 | rc = dev_hard_start_xmit(skb, dev, txq); | 2572 | rc = dev_hard_start_xmit(skb, dev, txq); |
2536 | __this_cpu_dec(xmit_recursion); | 2573 | __this_cpu_dec(xmit_recursion); |
@@ -2591,123 +2628,28 @@ static inline void ____napi_schedule(struct softnet_data *sd, | |||
2591 | */ | 2628 | */ |
2592 | void __skb_get_rxhash(struct sk_buff *skb) | 2629 | void __skb_get_rxhash(struct sk_buff *skb) |
2593 | { | 2630 | { |
2594 | int nhoff, hash = 0, poff; | 2631 | struct flow_keys keys; |
2595 | const struct ipv6hdr *ip6; | 2632 | u32 hash; |
2596 | const struct iphdr *ip; | ||
2597 | const struct vlan_hdr *vlan; | ||
2598 | u8 ip_proto; | ||
2599 | u32 addr1, addr2; | ||
2600 | u16 proto; | ||
2601 | union { | ||
2602 | u32 v32; | ||
2603 | u16 v16[2]; | ||
2604 | } ports; | ||
2605 | |||
2606 | nhoff = skb_network_offset(skb); | ||
2607 | proto = skb->protocol; | ||
2608 | |||
2609 | again: | ||
2610 | switch (proto) { | ||
2611 | case __constant_htons(ETH_P_IP): | ||
2612 | ip: | ||
2613 | if (!pskb_may_pull(skb, sizeof(*ip) + nhoff)) | ||
2614 | goto done; | ||
2615 | |||
2616 | ip = (const struct iphdr *) (skb->data + nhoff); | ||
2617 | if (ip_is_fragment(ip)) | ||
2618 | ip_proto = 0; | ||
2619 | else | ||
2620 | ip_proto = ip->protocol; | ||
2621 | addr1 = (__force u32) ip->saddr; | ||
2622 | addr2 = (__force u32) ip->daddr; | ||
2623 | nhoff += ip->ihl * 4; | ||
2624 | break; | ||
2625 | case __constant_htons(ETH_P_IPV6): | ||
2626 | ipv6: | ||
2627 | if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff)) | ||
2628 | goto done; | ||
2629 | |||
2630 | ip6 = (const struct ipv6hdr *) (skb->data + nhoff); | ||
2631 | ip_proto = ip6->nexthdr; | ||
2632 | addr1 = (__force u32) ip6->saddr.s6_addr32[3]; | ||
2633 | addr2 = (__force u32) ip6->daddr.s6_addr32[3]; | ||
2634 | nhoff += 40; | ||
2635 | break; | ||
2636 | case __constant_htons(ETH_P_8021Q): | ||
2637 | if (!pskb_may_pull(skb, sizeof(*vlan) + nhoff)) | ||
2638 | goto done; | ||
2639 | vlan = (const struct vlan_hdr *) (skb->data + nhoff); | ||
2640 | proto = vlan->h_vlan_encapsulated_proto; | ||
2641 | nhoff += sizeof(*vlan); | ||
2642 | goto again; | ||
2643 | case __constant_htons(ETH_P_PPP_SES): | ||
2644 | if (!pskb_may_pull(skb, PPPOE_SES_HLEN + nhoff)) | ||
2645 | goto done; | ||
2646 | proto = *((__be16 *) (skb->data + nhoff + | ||
2647 | sizeof(struct pppoe_hdr))); | ||
2648 | nhoff += PPPOE_SES_HLEN; | ||
2649 | switch (proto) { | ||
2650 | case __constant_htons(PPP_IP): | ||
2651 | goto ip; | ||
2652 | case __constant_htons(PPP_IPV6): | ||
2653 | goto ipv6; | ||
2654 | default: | ||
2655 | goto done; | ||
2656 | } | ||
2657 | default: | ||
2658 | goto done; | ||
2659 | } | ||
2660 | |||
2661 | switch (ip_proto) { | ||
2662 | case IPPROTO_GRE: | ||
2663 | if (pskb_may_pull(skb, nhoff + 16)) { | ||
2664 | u8 *h = skb->data + nhoff; | ||
2665 | __be16 flags = *(__be16 *)h; | ||
2666 | 2633 | ||
2667 | /* | 2634 | if (!skb_flow_dissect(skb, &keys)) |
2668 | * Only look inside GRE if version zero and no | 2635 | return; |
2669 | * routing | ||
2670 | */ | ||
2671 | if (!(flags & (GRE_VERSION|GRE_ROUTING))) { | ||
2672 | proto = *(__be16 *)(h + 2); | ||
2673 | nhoff += 4; | ||
2674 | if (flags & GRE_CSUM) | ||
2675 | nhoff += 4; | ||
2676 | if (flags & GRE_KEY) | ||
2677 | nhoff += 4; | ||
2678 | if (flags & GRE_SEQ) | ||
2679 | nhoff += 4; | ||
2680 | goto again; | ||
2681 | } | ||
2682 | } | ||
2683 | break; | ||
2684 | case IPPROTO_IPIP: | ||
2685 | goto again; | ||
2686 | default: | ||
2687 | break; | ||
2688 | } | ||
2689 | 2636 | ||
2690 | ports.v32 = 0; | 2637 | if (keys.ports) { |
2691 | poff = proto_ports_offset(ip_proto); | 2638 | if ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]) |
2692 | if (poff >= 0) { | 2639 | swap(keys.port16[0], keys.port16[1]); |
2693 | nhoff += poff; | 2640 | skb->l4_rxhash = 1; |
2694 | if (pskb_may_pull(skb, nhoff + 4)) { | ||
2695 | ports.v32 = * (__force u32 *) (skb->data + nhoff); | ||
2696 | if (ports.v16[1] < ports.v16[0]) | ||
2697 | swap(ports.v16[0], ports.v16[1]); | ||
2698 | skb->l4_rxhash = 1; | ||
2699 | } | ||
2700 | } | 2641 | } |
2701 | 2642 | ||
2702 | /* get a consistent hash (same value on both flow directions) */ | 2643 | /* get a consistent hash (same value on both flow directions) */ |
2703 | if (addr2 < addr1) | 2644 | if ((__force u32)keys.dst < (__force u32)keys.src) |
2704 | swap(addr1, addr2); | 2645 | swap(keys.dst, keys.src); |
2705 | 2646 | ||
2706 | hash = jhash_3words(addr1, addr2, ports.v32, hashrnd); | 2647 | hash = jhash_3words((__force u32)keys.dst, |
2648 | (__force u32)keys.src, | ||
2649 | (__force u32)keys.ports, hashrnd); | ||
2707 | if (!hash) | 2650 | if (!hash) |
2708 | hash = 1; | 2651 | hash = 1; |
2709 | 2652 | ||
2710 | done: | ||
2711 | skb->rxhash = hash; | 2653 | skb->rxhash = hash; |
2712 | } | 2654 | } |
2713 | EXPORT_SYMBOL(__skb_get_rxhash); | 2655 | EXPORT_SYMBOL(__skb_get_rxhash); |
@@ -2718,6 +2660,8 @@ EXPORT_SYMBOL(__skb_get_rxhash); | |||
2718 | struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly; | 2660 | struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly; |
2719 | EXPORT_SYMBOL(rps_sock_flow_table); | 2661 | EXPORT_SYMBOL(rps_sock_flow_table); |
2720 | 2662 | ||
2663 | struct jump_label_key rps_needed __read_mostly; | ||
2664 | |||
2721 | static struct rps_dev_flow * | 2665 | static struct rps_dev_flow * |
2722 | set_rps_cpu(struct net_device *dev, struct sk_buff *skb, | 2666 | set_rps_cpu(struct net_device *dev, struct sk_buff *skb, |
2723 | struct rps_dev_flow *rflow, u16 next_cpu) | 2667 | struct rps_dev_flow *rflow, u16 next_cpu) |
@@ -2997,12 +2941,11 @@ int netif_rx(struct sk_buff *skb) | |||
2997 | if (netpoll_rx(skb)) | 2941 | if (netpoll_rx(skb)) |
2998 | return NET_RX_DROP; | 2942 | return NET_RX_DROP; |
2999 | 2943 | ||
3000 | if (netdev_tstamp_prequeue) | 2944 | net_timestamp_check(netdev_tstamp_prequeue, skb); |
3001 | net_timestamp_check(skb); | ||
3002 | 2945 | ||
3003 | trace_netif_rx(skb); | 2946 | trace_netif_rx(skb); |
3004 | #ifdef CONFIG_RPS | 2947 | #ifdef CONFIG_RPS |
3005 | { | 2948 | if (static_branch(&rps_needed)) { |
3006 | struct rps_dev_flow voidflow, *rflow = &voidflow; | 2949 | struct rps_dev_flow voidflow, *rflow = &voidflow; |
3007 | int cpu; | 2950 | int cpu; |
3008 | 2951 | ||
@@ -3017,14 +2960,13 @@ int netif_rx(struct sk_buff *skb) | |||
3017 | 2960 | ||
3018 | rcu_read_unlock(); | 2961 | rcu_read_unlock(); |
3019 | preempt_enable(); | 2962 | preempt_enable(); |
3020 | } | 2963 | } else |
3021 | #else | 2964 | #endif |
3022 | { | 2965 | { |
3023 | unsigned int qtail; | 2966 | unsigned int qtail; |
3024 | ret = enqueue_to_backlog(skb, get_cpu(), &qtail); | 2967 | ret = enqueue_to_backlog(skb, get_cpu(), &qtail); |
3025 | put_cpu(); | 2968 | put_cpu(); |
3026 | } | 2969 | } |
3027 | #endif | ||
3028 | return ret; | 2970 | return ret; |
3029 | } | 2971 | } |
3030 | EXPORT_SYMBOL(netif_rx); | 2972 | EXPORT_SYMBOL(netif_rx); |
@@ -3230,8 +3172,7 @@ static int __netif_receive_skb(struct sk_buff *skb) | |||
3230 | int ret = NET_RX_DROP; | 3172 | int ret = NET_RX_DROP; |
3231 | __be16 type; | 3173 | __be16 type; |
3232 | 3174 | ||
3233 | if (!netdev_tstamp_prequeue) | 3175 | net_timestamp_check(!netdev_tstamp_prequeue, skb); |
3234 | net_timestamp_check(skb); | ||
3235 | 3176 | ||
3236 | trace_netif_receive_skb(skb); | 3177 | trace_netif_receive_skb(skb); |
3237 | 3178 | ||
@@ -3362,14 +3303,13 @@ out: | |||
3362 | */ | 3303 | */ |
3363 | int netif_receive_skb(struct sk_buff *skb) | 3304 | int netif_receive_skb(struct sk_buff *skb) |
3364 | { | 3305 | { |
3365 | if (netdev_tstamp_prequeue) | 3306 | net_timestamp_check(netdev_tstamp_prequeue, skb); |
3366 | net_timestamp_check(skb); | ||
3367 | 3307 | ||
3368 | if (skb_defer_rx_timestamp(skb)) | 3308 | if (skb_defer_rx_timestamp(skb)) |
3369 | return NET_RX_SUCCESS; | 3309 | return NET_RX_SUCCESS; |
3370 | 3310 | ||
3371 | #ifdef CONFIG_RPS | 3311 | #ifdef CONFIG_RPS |
3372 | { | 3312 | if (static_branch(&rps_needed)) { |
3373 | struct rps_dev_flow voidflow, *rflow = &voidflow; | 3313 | struct rps_dev_flow voidflow, *rflow = &voidflow; |
3374 | int cpu, ret; | 3314 | int cpu, ret; |
3375 | 3315 | ||
@@ -3380,16 +3320,12 @@ int netif_receive_skb(struct sk_buff *skb) | |||
3380 | if (cpu >= 0) { | 3320 | if (cpu >= 0) { |
3381 | ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); | 3321 | ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); |
3382 | rcu_read_unlock(); | 3322 | rcu_read_unlock(); |
3383 | } else { | 3323 | return ret; |
3384 | rcu_read_unlock(); | ||
3385 | ret = __netif_receive_skb(skb); | ||
3386 | } | 3324 | } |
3387 | 3325 | rcu_read_unlock(); | |
3388 | return ret; | ||
3389 | } | 3326 | } |
3390 | #else | ||
3391 | return __netif_receive_skb(skb); | ||
3392 | #endif | 3327 | #endif |
3328 | return __netif_receive_skb(skb); | ||
3393 | } | 3329 | } |
3394 | EXPORT_SYMBOL(netif_receive_skb); | 3330 | EXPORT_SYMBOL(netif_receive_skb); |
3395 | 3331 | ||
@@ -4282,6 +4218,12 @@ static int dev_seq_open(struct inode *inode, struct file *file) | |||
4282 | sizeof(struct dev_iter_state)); | 4218 | sizeof(struct dev_iter_state)); |
4283 | } | 4219 | } |
4284 | 4220 | ||
4221 | int dev_seq_open_ops(struct inode *inode, struct file *file, | ||
4222 | const struct seq_operations *ops) | ||
4223 | { | ||
4224 | return seq_open_net(inode, file, ops, sizeof(struct dev_iter_state)); | ||
4225 | } | ||
4226 | |||
4285 | static const struct file_operations dev_seq_fops = { | 4227 | static const struct file_operations dev_seq_fops = { |
4286 | .owner = THIS_MODULE, | 4228 | .owner = THIS_MODULE, |
4287 | .open = dev_seq_open, | 4229 | .open = dev_seq_open, |
@@ -4532,7 +4474,7 @@ static void dev_change_rx_flags(struct net_device *dev, int flags) | |||
4532 | 4474 | ||
4533 | static int __dev_set_promiscuity(struct net_device *dev, int inc) | 4475 | static int __dev_set_promiscuity(struct net_device *dev, int inc) |
4534 | { | 4476 | { |
4535 | unsigned short old_flags = dev->flags; | 4477 | unsigned int old_flags = dev->flags; |
4536 | uid_t uid; | 4478 | uid_t uid; |
4537 | gid_t gid; | 4479 | gid_t gid; |
4538 | 4480 | ||
@@ -4589,7 +4531,7 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc) | |||
4589 | */ | 4531 | */ |
4590 | int dev_set_promiscuity(struct net_device *dev, int inc) | 4532 | int dev_set_promiscuity(struct net_device *dev, int inc) |
4591 | { | 4533 | { |
4592 | unsigned short old_flags = dev->flags; | 4534 | unsigned int old_flags = dev->flags; |
4593 | int err; | 4535 | int err; |
4594 | 4536 | ||
4595 | err = __dev_set_promiscuity(dev, inc); | 4537 | err = __dev_set_promiscuity(dev, inc); |
@@ -4616,7 +4558,7 @@ EXPORT_SYMBOL(dev_set_promiscuity); | |||
4616 | 4558 | ||
4617 | int dev_set_allmulti(struct net_device *dev, int inc) | 4559 | int dev_set_allmulti(struct net_device *dev, int inc) |
4618 | { | 4560 | { |
4619 | unsigned short old_flags = dev->flags; | 4561 | unsigned int old_flags = dev->flags; |
4620 | 4562 | ||
4621 | ASSERT_RTNL(); | 4563 | ASSERT_RTNL(); |
4622 | 4564 | ||
@@ -4719,7 +4661,7 @@ EXPORT_SYMBOL(dev_get_flags); | |||
4719 | 4661 | ||
4720 | int __dev_change_flags(struct net_device *dev, unsigned int flags) | 4662 | int __dev_change_flags(struct net_device *dev, unsigned int flags) |
4721 | { | 4663 | { |
4722 | int old_flags = dev->flags; | 4664 | unsigned int old_flags = dev->flags; |
4723 | int ret; | 4665 | int ret; |
4724 | 4666 | ||
4725 | ASSERT_RTNL(); | 4667 | ASSERT_RTNL(); |
@@ -4802,10 +4744,10 @@ void __dev_notify_flags(struct net_device *dev, unsigned int old_flags) | |||
4802 | * Change settings on device based state flags. The flags are | 4744 | * Change settings on device based state flags. The flags are |
4803 | * in the userspace exported format. | 4745 | * in the userspace exported format. |
4804 | */ | 4746 | */ |
4805 | int dev_change_flags(struct net_device *dev, unsigned flags) | 4747 | int dev_change_flags(struct net_device *dev, unsigned int flags) |
4806 | { | 4748 | { |
4807 | int ret, changes; | 4749 | int ret; |
4808 | int old_flags = dev->flags; | 4750 | unsigned int changes, old_flags = dev->flags; |
4809 | 4751 | ||
4810 | ret = __dev_change_flags(dev, flags); | 4752 | ret = __dev_change_flags(dev, flags); |
4811 | if (ret < 0) | 4753 | if (ret < 0) |
@@ -5362,7 +5304,8 @@ static void rollback_registered(struct net_device *dev) | |||
5362 | list_del(&single); | 5304 | list_del(&single); |
5363 | } | 5305 | } |
5364 | 5306 | ||
5365 | static u32 netdev_fix_features(struct net_device *dev, u32 features) | 5307 | static netdev_features_t netdev_fix_features(struct net_device *dev, |
5308 | netdev_features_t features) | ||
5366 | { | 5309 | { |
5367 | /* Fix illegal checksum combinations */ | 5310 | /* Fix illegal checksum combinations */ |
5368 | if ((features & NETIF_F_HW_CSUM) && | 5311 | if ((features & NETIF_F_HW_CSUM) && |
@@ -5371,12 +5314,6 @@ static u32 netdev_fix_features(struct net_device *dev, u32 features) | |||
5371 | features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM); | 5314 | features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM); |
5372 | } | 5315 | } |
5373 | 5316 | ||
5374 | if ((features & NETIF_F_NO_CSUM) && | ||
5375 | (features & (NETIF_F_HW_CSUM|NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { | ||
5376 | netdev_warn(dev, "mixed no checksumming and other settings.\n"); | ||
5377 | features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM|NETIF_F_HW_CSUM); | ||
5378 | } | ||
5379 | |||
5380 | /* Fix illegal SG+CSUM combinations. */ | 5317 | /* Fix illegal SG+CSUM combinations. */ |
5381 | if ((features & NETIF_F_SG) && | 5318 | if ((features & NETIF_F_SG) && |
5382 | !(features & NETIF_F_ALL_CSUM)) { | 5319 | !(features & NETIF_F_ALL_CSUM)) { |
@@ -5424,7 +5361,7 @@ static u32 netdev_fix_features(struct net_device *dev, u32 features) | |||
5424 | 5361 | ||
5425 | int __netdev_update_features(struct net_device *dev) | 5362 | int __netdev_update_features(struct net_device *dev) |
5426 | { | 5363 | { |
5427 | u32 features; | 5364 | netdev_features_t features; |
5428 | int err = 0; | 5365 | int err = 0; |
5429 | 5366 | ||
5430 | ASSERT_RTNL(); | 5367 | ASSERT_RTNL(); |
@@ -5440,16 +5377,16 @@ int __netdev_update_features(struct net_device *dev) | |||
5440 | if (dev->features == features) | 5377 | if (dev->features == features) |
5441 | return 0; | 5378 | return 0; |
5442 | 5379 | ||
5443 | netdev_dbg(dev, "Features changed: 0x%08x -> 0x%08x\n", | 5380 | netdev_dbg(dev, "Features changed: %pNF -> %pNF\n", |
5444 | dev->features, features); | 5381 | &dev->features, &features); |
5445 | 5382 | ||
5446 | if (dev->netdev_ops->ndo_set_features) | 5383 | if (dev->netdev_ops->ndo_set_features) |
5447 | err = dev->netdev_ops->ndo_set_features(dev, features); | 5384 | err = dev->netdev_ops->ndo_set_features(dev, features); |
5448 | 5385 | ||
5449 | if (unlikely(err < 0)) { | 5386 | if (unlikely(err < 0)) { |
5450 | netdev_err(dev, | 5387 | netdev_err(dev, |
5451 | "set_features() failed (%d); wanted 0x%08x, left 0x%08x\n", | 5388 | "set_features() failed (%d); wanted %pNF, left %pNF\n", |
5452 | err, features, dev->features); | 5389 | err, &features, &dev->features); |
5453 | return -1; | 5390 | return -1; |
5454 | } | 5391 | } |
5455 | 5392 | ||
@@ -5548,6 +5485,9 @@ static void netdev_init_one_queue(struct net_device *dev, | |||
5548 | queue->xmit_lock_owner = -1; | 5485 | queue->xmit_lock_owner = -1; |
5549 | netdev_queue_numa_node_write(queue, NUMA_NO_NODE); | 5486 | netdev_queue_numa_node_write(queue, NUMA_NO_NODE); |
5550 | queue->dev = dev; | 5487 | queue->dev = dev; |
5488 | #ifdef CONFIG_BQL | ||
5489 | dql_init(&queue->dql, HZ); | ||
5490 | #endif | ||
5551 | } | 5491 | } |
5552 | 5492 | ||
5553 | static int netif_alloc_netdev_queues(struct net_device *dev) | 5493 | static int netif_alloc_netdev_queues(struct net_device *dev) |
@@ -5633,11 +5573,12 @@ int register_netdevice(struct net_device *dev) | |||
5633 | dev->wanted_features = dev->features & dev->hw_features; | 5573 | dev->wanted_features = dev->features & dev->hw_features; |
5634 | 5574 | ||
5635 | /* Turn on no cache copy if HW is doing checksum */ | 5575 | /* Turn on no cache copy if HW is doing checksum */ |
5636 | dev->hw_features |= NETIF_F_NOCACHE_COPY; | 5576 | if (!(dev->flags & IFF_LOOPBACK)) { |
5637 | if ((dev->features & NETIF_F_ALL_CSUM) && | 5577 | dev->hw_features |= NETIF_F_NOCACHE_COPY; |
5638 | !(dev->features & NETIF_F_NO_CSUM)) { | 5578 | if (dev->features & NETIF_F_ALL_CSUM) { |
5639 | dev->wanted_features |= NETIF_F_NOCACHE_COPY; | 5579 | dev->wanted_features |= NETIF_F_NOCACHE_COPY; |
5640 | dev->features |= NETIF_F_NOCACHE_COPY; | 5580 | dev->features |= NETIF_F_NOCACHE_COPY; |
5581 | } | ||
5641 | } | 5582 | } |
5642 | 5583 | ||
5643 | /* Make NETIF_F_HIGHDMA inheritable to VLAN devices. | 5584 | /* Make NETIF_F_HIGHDMA inheritable to VLAN devices. |
@@ -6373,7 +6314,8 @@ static int dev_cpu_callback(struct notifier_block *nfb, | |||
6373 | * @one to the master device with current feature set @all. Will not | 6314 | * @one to the master device with current feature set @all. Will not |
6374 | * enable anything that is off in @mask. Returns the new feature set. | 6315 | * enable anything that is off in @mask. Returns the new feature set. |
6375 | */ | 6316 | */ |
6376 | u32 netdev_increment_features(u32 all, u32 one, u32 mask) | 6317 | netdev_features_t netdev_increment_features(netdev_features_t all, |
6318 | netdev_features_t one, netdev_features_t mask) | ||
6377 | { | 6319 | { |
6378 | if (mask & NETIF_F_GEN_CSUM) | 6320 | if (mask & NETIF_F_GEN_CSUM) |
6379 | mask |= NETIF_F_ALL_CSUM; | 6321 | mask |= NETIF_F_ALL_CSUM; |
@@ -6382,10 +6324,6 @@ u32 netdev_increment_features(u32 all, u32 one, u32 mask) | |||
6382 | all |= one & (NETIF_F_ONE_FOR_ALL|NETIF_F_ALL_CSUM) & mask; | 6324 | all |= one & (NETIF_F_ONE_FOR_ALL|NETIF_F_ALL_CSUM) & mask; |
6383 | all &= one | ~NETIF_F_ALL_FOR_ALL; | 6325 | all &= one | ~NETIF_F_ALL_FOR_ALL; |
6384 | 6326 | ||
6385 | /* If device needs checksumming, downgrade to it. */ | ||
6386 | if (all & (NETIF_F_ALL_CSUM & ~NETIF_F_NO_CSUM)) | ||
6387 | all &= ~NETIF_F_NO_CSUM; | ||
6388 | |||
6389 | /* If one device supports hw checksumming, set for all. */ | 6327 | /* If one device supports hw checksumming, set for all. */ |
6390 | if (all & NETIF_F_GEN_CSUM) | 6328 | if (all & NETIF_F_GEN_CSUM) |
6391 | all &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM); | 6329 | all &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM); |