kernel: split patches folder up into backport, pending and hack folders
[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 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
13 index 780e7171f548..6b738c662bc1 100644
14 --- a/include/linux/netdevice.h
15 +++ b/include/linux/netdevice.h
16 @@ -1749,6 +1749,8 @@ struct net_device {
17 struct netdev_hw_addr_list mc;
18 struct netdev_hw_addr_list dev_addrs;
19
20 + unsigned char local_addr_mask[MAX_ADDR_LEN];
21 +
22 #ifdef CONFIG_SYSFS
23 struct kset *queues_kset;
24 #endif
25 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
26 index 5f3343ae25ef..3a04baab9b28 100644
27 --- a/include/linux/skbuff.h
28 +++ b/include/linux/skbuff.h
29 @@ -742,7 +742,8 @@ struct sk_buff {
30 #ifdef CONFIG_NET_SWITCHDEV
31 __u8 offload_fwd_mark:1;
32 #endif
33 - /* 2, 4 or 5 bit hole */
34 + __u8 gro_skip:1;
35 + /* 1, 3 or 4 bit hole */
36
37 #ifdef CONFIG_NET_SCHED
38 __u16 tc_index; /* traffic control index */
39 diff --git a/net/core/dev.c b/net/core/dev.c
40 index 2e04fd188081..c7c96308bc84 100644
41 --- a/net/core/dev.c
42 +++ b/net/core/dev.c
43 @@ -4512,6 +4512,9 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
44 enum gro_result ret;
45 int grow;
46
47 + if (skb->gro_skip)
48 + goto normal;
49 +
50 if (!(skb->dev->features & NETIF_F_GRO))
51 goto normal;
52
53 @@ -5789,6 +5792,48 @@ static void __netdev_adjacent_dev_unlink_neighbour(struct net_device *dev,
54 &upper_dev->adj_list.lower);
55 }
56
57 +static void __netdev_addr_mask(unsigned char *mask, const unsigned char *addr,
58 + struct net_device *dev)
59 +{
60 + int i;
61 +
62 + for (i = 0; i < dev->addr_len; i++)
63 + mask[i] |= addr[i] ^ dev->dev_addr[i];
64 +}
65 +
66 +static void __netdev_upper_mask(unsigned char *mask, struct net_device *dev,
67 + struct net_device *lower)
68 +{
69 + struct net_device *cur;
70 + struct list_head *iter;
71 +
72 + netdev_for_each_upper_dev_rcu(dev, cur, iter) {
73 + __netdev_addr_mask(mask, cur->dev_addr, lower);
74 + __netdev_upper_mask(mask, cur, lower);
75 + }
76 +}
77 +
78 +static void __netdev_update_addr_mask(struct net_device *dev)
79 +{
80 + unsigned char mask[MAX_ADDR_LEN];
81 + struct net_device *cur;
82 + struct list_head *iter;
83 +
84 + memset(mask, 0, sizeof(mask));
85 + __netdev_upper_mask(mask, dev, dev);
86 + memcpy(dev->local_addr_mask, mask, dev->addr_len);
87 +
88 + netdev_for_each_lower_dev(dev, cur, iter)
89 + __netdev_update_addr_mask(cur);
90 +}
91 +
92 +static void netdev_update_addr_mask(struct net_device *dev)
93 +{
94 + rcu_read_lock();
95 + __netdev_update_addr_mask(dev);
96 + rcu_read_unlock();
97 +}
98 +
99 static int __netdev_upper_dev_link(struct net_device *dev,
100 struct net_device *upper_dev, bool master,
101 void *upper_priv, void *upper_info)
102 @@ -5987,6 +6032,8 @@ void netdev_upper_dev_unlink(struct net_device *dev,
103 list_for_each_entry(i, &upper_dev->all_adj_list.upper, list)
104 __netdev_adjacent_dev_unlink(dev, i->dev, i->ref_nr);
105
106 + netdev_update_addr_mask(dev);
107 + netdev_update_addr_mask(dev);
108 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
109 &changeupper_info.info);
110 }
111 @@ -6587,6 +6634,7 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
112 if (err)
113 return err;
114 dev->addr_assign_type = NET_ADDR_SET;
115 + netdev_update_addr_mask(dev);
116 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
117 add_device_randomness(dev->dev_addr, dev->addr_len);
118 return 0;
119 diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
120 index fbf1de965a9a..6a6d90b9a880 100644
121 --- a/net/ethernet/eth.c
122 +++ b/net/ethernet/eth.c
123 @@ -143,6 +143,18 @@ u32 eth_get_headlen(void *data, unsigned int len)
124 }
125 EXPORT_SYMBOL(eth_get_headlen);
126
127 +static inline bool
128 +eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
129 +{
130 + const u16 *a1 = addr1;
131 + const u16 *a2 = addr2;
132 + const u16 *m = mask;
133 +
134 + return (((a1[0] ^ a2[0]) & ~m[0]) |
135 + ((a1[1] ^ a2[1]) & ~m[1]) |
136 + ((a1[2] ^ a2[2]) & ~m[2]));
137 +}
138 +
139 /**
140 * eth_type_trans - determine the packet's protocol ID.
141 * @skb: received socket data
142 @@ -171,8 +183,12 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
143 skb->pkt_type = PACKET_MULTICAST;
144 }
145 else if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
146 - dev->dev_addr)))
147 + dev->dev_addr))) {
148 skb->pkt_type = PACKET_OTHERHOST;
149 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
150 + dev->local_addr_mask))
151 + skb->gro_skip = 1;
152 + }
153
154 /*
155 * Some variants of DSA tagging don't have an ethertype field
156 --
157 2.11.0
158