kernel: bump 4.9 to 4.9.82
[openwrt/openwrt.git] / target / linux / generic / pending-4.9 / 680-NET-skip-GRO-for-foreign-MAC-addresses.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: net: replace GRO optimization patch with a new one that supports VLANs/bridges with different MAC addresses
3
4 Signed-off-by: Felix Fietkau <nbd@nbd.name>
5 ---
6 include/linux/netdevice.h | 2 ++
7 include/linux/skbuff.h | 3 ++-
8 net/core/dev.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
9 net/ethernet/eth.c | 18 +++++++++++++++++-
10 4 files changed, 69 insertions(+), 2 deletions(-)
11
12 --- a/include/linux/netdevice.h
13 +++ b/include/linux/netdevice.h
14 @@ -1749,6 +1749,8 @@ struct net_device {
15 struct netdev_hw_addr_list mc;
16 struct netdev_hw_addr_list dev_addrs;
17
18 + unsigned char local_addr_mask[MAX_ADDR_LEN];
19 +
20 #ifdef CONFIG_SYSFS
21 struct kset *queues_kset;
22 #endif
23 --- a/include/linux/skbuff.h
24 +++ b/include/linux/skbuff.h
25 @@ -742,7 +742,8 @@ struct sk_buff {
26 #ifdef CONFIG_NET_SWITCHDEV
27 __u8 offload_fwd_mark:1;
28 #endif
29 - /* 2, 4 or 5 bit hole */
30 + __u8 gro_skip:1;
31 + /* 1, 3 or 4 bit hole */
32
33 #ifdef CONFIG_NET_SCHED
34 __u16 tc_index; /* traffic control index */
35 --- a/net/core/dev.c
36 +++ b/net/core/dev.c
37 @@ -4535,6 +4535,9 @@ static enum gro_result dev_gro_receive(s
38 enum gro_result ret;
39 int grow;
40
41 + if (skb->gro_skip)
42 + goto normal;
43 +
44 if (!(skb->dev->features & NETIF_F_GRO))
45 goto normal;
46
47 @@ -5823,6 +5826,48 @@ static void __netdev_adjacent_dev_unlink
48 &upper_dev->adj_list.lower);
49 }
50
51 +static void __netdev_addr_mask(unsigned char *mask, const unsigned char *addr,
52 + struct net_device *dev)
53 +{
54 + int i;
55 +
56 + for (i = 0; i < dev->addr_len; i++)
57 + mask[i] |= addr[i] ^ dev->dev_addr[i];
58 +}
59 +
60 +static void __netdev_upper_mask(unsigned char *mask, struct net_device *dev,
61 + struct net_device *lower)
62 +{
63 + struct net_device *cur;
64 + struct list_head *iter;
65 +
66 + netdev_for_each_upper_dev_rcu(dev, cur, iter) {
67 + __netdev_addr_mask(mask, cur->dev_addr, lower);
68 + __netdev_upper_mask(mask, cur, lower);
69 + }
70 +}
71 +
72 +static void __netdev_update_addr_mask(struct net_device *dev)
73 +{
74 + unsigned char mask[MAX_ADDR_LEN];
75 + struct net_device *cur;
76 + struct list_head *iter;
77 +
78 + memset(mask, 0, sizeof(mask));
79 + __netdev_upper_mask(mask, dev, dev);
80 + memcpy(dev->local_addr_mask, mask, dev->addr_len);
81 +
82 + netdev_for_each_lower_dev(dev, cur, iter)
83 + __netdev_update_addr_mask(cur);
84 +}
85 +
86 +static void netdev_update_addr_mask(struct net_device *dev)
87 +{
88 + rcu_read_lock();
89 + __netdev_update_addr_mask(dev);
90 + rcu_read_unlock();
91 +}
92 +
93 static int __netdev_upper_dev_link(struct net_device *dev,
94 struct net_device *upper_dev, bool master,
95 void *upper_priv, void *upper_info)
96 @@ -6021,6 +6066,8 @@ void netdev_upper_dev_unlink(struct net_
97 list_for_each_entry(i, &upper_dev->all_adj_list.upper, list)
98 __netdev_adjacent_dev_unlink(dev, i->dev, i->ref_nr);
99
100 + netdev_update_addr_mask(dev);
101 + netdev_update_addr_mask(dev);
102 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
103 &changeupper_info.info);
104 }
105 @@ -6621,6 +6668,7 @@ int dev_set_mac_address(struct net_devic
106 if (err)
107 return err;
108 dev->addr_assign_type = NET_ADDR_SET;
109 + netdev_update_addr_mask(dev);
110 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
111 add_device_randomness(dev->dev_addr, dev->addr_len);
112 return 0;
113 --- a/net/ethernet/eth.c
114 +++ b/net/ethernet/eth.c
115 @@ -143,6 +143,18 @@ u32 eth_get_headlen(void *data, unsigned
116 }
117 EXPORT_SYMBOL(eth_get_headlen);
118
119 +static inline bool
120 +eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
121 +{
122 + const u16 *a1 = addr1;
123 + const u16 *a2 = addr2;
124 + const u16 *m = mask;
125 +
126 + return (((a1[0] ^ a2[0]) & ~m[0]) |
127 + ((a1[1] ^ a2[1]) & ~m[1]) |
128 + ((a1[2] ^ a2[2]) & ~m[2]));
129 +}
130 +
131 /**
132 * eth_type_trans - determine the packet's protocol ID.
133 * @skb: received socket data
134 @@ -171,8 +183,12 @@ __be16 eth_type_trans(struct sk_buff *sk
135 skb->pkt_type = PACKET_MULTICAST;
136 }
137 else if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
138 - dev->dev_addr)))
139 + dev->dev_addr))) {
140 skb->pkt_type = PACKET_OTHERHOST;
141 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
142 + dev->local_addr_mask))
143 + skb->gro_skip = 1;
144 + }
145
146 /*
147 * Some variants of DSA tagging don't have an ethertype field