kernel: update kernel 4.9 to 4.9.37
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-4.9 / 680-NET-skip-GRO-for-foreign-MAC-addresses.patch
1 Subject: NET: skip GRO for foreign MAC addresses
2
3 For network drivers using napi_gro_receive, packets are run through GRO,
4 even when the destination MAC address does not match, and they're supposed
5 to be delivered to another host behind a different bridge port.
6
7 This can be very expensive, because for drivers without TSO or scatter-
8 gather, this can only be undone by copying the skb and checksumming it
9 again.
10
11 To be able to track foreign MAC addresses in an inexpensive way, create
12 a mask of changed bits in MAC addresses of upper devices. This allows
13 handling VLANs and bridge devices with different addresses (as long as
14 they are not too different).
15
16 Signed-off-by: Felix Fietkau <nbd@nbd.name>
17
18 --- a/net/core/dev.c
19 +++ b/net/core/dev.c
20 @@ -4513,6 +4513,9 @@ static enum gro_result dev_gro_receive(s
21 enum gro_result ret;
22 int grow;
23
24 + if (skb->gro_skip)
25 + goto normal;
26 +
27 if (!(skb->dev->features & NETIF_F_GRO))
28 goto normal;
29
30 @@ -5790,6 +5793,48 @@ static void __netdev_adjacent_dev_unlink
31 &upper_dev->adj_list.lower);
32 }
33
34 +static void __netdev_addr_mask(unsigned char *mask, const unsigned char *addr,
35 + struct net_device *dev)
36 +{
37 + int i;
38 +
39 + for (i = 0; i < dev->addr_len; i++)
40 + mask[i] |= addr[i] ^ dev->dev_addr[i];
41 +}
42 +
43 +static void __netdev_upper_mask(unsigned char *mask, struct net_device *dev,
44 + struct net_device *lower)
45 +{
46 + struct net_device *cur;
47 + struct list_head *iter;
48 +
49 + netdev_for_each_upper_dev_rcu(dev, cur, iter) {
50 + __netdev_addr_mask(mask, cur->dev_addr, lower);
51 + __netdev_upper_mask(mask, cur, lower);
52 + }
53 +}
54 +
55 +static void __netdev_update_addr_mask(struct net_device *dev)
56 +{
57 + unsigned char mask[MAX_ADDR_LEN];
58 + struct net_device *cur;
59 + struct list_head *iter;
60 +
61 + memset(mask, 0, sizeof(mask));
62 + __netdev_upper_mask(mask, dev, dev);
63 + memcpy(dev->local_addr_mask, mask, dev->addr_len);
64 +
65 + netdev_for_each_lower_dev(dev, cur, iter)
66 + __netdev_update_addr_mask(cur);
67 +}
68 +
69 +static void netdev_update_addr_mask(struct net_device *dev)
70 +{
71 + rcu_read_lock();
72 + __netdev_update_addr_mask(dev);
73 + rcu_read_unlock();
74 +}
75 +
76 static int __netdev_upper_dev_link(struct net_device *dev,
77 struct net_device *upper_dev, bool master,
78 void *upper_priv, void *upper_info)
79 @@ -5988,6 +6033,8 @@ void netdev_upper_dev_unlink(struct net_
80 list_for_each_entry(i, &upper_dev->all_adj_list.upper, list)
81 __netdev_adjacent_dev_unlink(dev, i->dev, i->ref_nr);
82
83 + netdev_update_addr_mask(dev);
84 + netdev_update_addr_mask(dev);
85 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
86 &changeupper_info.info);
87 }
88 @@ -6588,6 +6635,7 @@ int dev_set_mac_address(struct net_devic
89 if (err)
90 return err;
91 dev->addr_assign_type = NET_ADDR_SET;
92 + netdev_update_addr_mask(dev);
93 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
94 add_device_randomness(dev->dev_addr, dev->addr_len);
95 return 0;
96 --- a/include/linux/netdevice.h
97 +++ b/include/linux/netdevice.h
98 @@ -1749,6 +1749,8 @@ struct net_device {
99 struct netdev_hw_addr_list mc;
100 struct netdev_hw_addr_list dev_addrs;
101
102 + unsigned char local_addr_mask[MAX_ADDR_LEN];
103 +
104 #ifdef CONFIG_SYSFS
105 struct kset *queues_kset;
106 #endif
107 --- a/include/linux/skbuff.h
108 +++ b/include/linux/skbuff.h
109 @@ -742,7 +742,8 @@ struct sk_buff {
110 #ifdef CONFIG_NET_SWITCHDEV
111 __u8 offload_fwd_mark:1;
112 #endif
113 - /* 2, 4 or 5 bit hole */
114 + __u8 gro_skip:1;
115 + /* 1, 3 or 4 bit hole */
116
117 #ifdef CONFIG_NET_SCHED
118 __u16 tc_index; /* traffic control index */
119 --- a/net/ethernet/eth.c
120 +++ b/net/ethernet/eth.c
121 @@ -143,6 +143,18 @@ u32 eth_get_headlen(void *data, unsigned
122 }
123 EXPORT_SYMBOL(eth_get_headlen);
124
125 +static inline bool
126 +eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
127 +{
128 + const u16 *a1 = addr1;
129 + const u16 *a2 = addr2;
130 + const u16 *m = mask;
131 +
132 + return (((a1[0] ^ a2[0]) & ~m[0]) |
133 + ((a1[1] ^ a2[1]) & ~m[1]) |
134 + ((a1[2] ^ a2[2]) & ~m[2]));
135 +}
136 +
137 /**
138 * eth_type_trans - determine the packet's protocol ID.
139 * @skb: received socket data
140 @@ -171,8 +183,12 @@ __be16 eth_type_trans(struct sk_buff *sk
141 skb->pkt_type = PACKET_MULTICAST;
142 }
143 else if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
144 - dev->dev_addr)))
145 + dev->dev_addr))) {
146 skb->pkt_type = PACKET_OTHERHOST;
147 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
148 + dev->local_addr_mask))
149 + skb->gro_skip = 1;
150 + }
151
152 /*
153 * Some variants of DSA tagging don't have an ethertype field