kernel: bump 6.1 to 6.1.31
[openwrt/openwrt.git] / target / linux / generic / pending-6.1 / 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 @@ -2132,6 +2132,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 @@ -964,6 +964,7 @@ struct sk_buff {
26 #ifdef CONFIG_IPV6_NDISC_NODETYPE
27 __u8 ndisc_nodetype:2;
28 #endif
29 + __u8 gro_skip:1;
30
31 __u8 ipvs_property:1;
32 __u8 inner_protocol_type:1;
33 --- a/net/core/gro.c
34 +++ b/net/core/gro.c
35 @@ -491,6 +491,9 @@ static enum gro_result dev_gro_receive(s
36 int same_flow;
37 int grow;
38
39 + if (skb->gro_skip)
40 + goto normal;
41 +
42 if (netif_elide_gro(skb->dev))
43 goto normal;
44
45 --- a/net/core/dev.c
46 +++ b/net/core/dev.c
47 @@ -7606,6 +7606,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 @@ -7657,6 +7699,7 @@ static int __netdev_upper_dev_link(struc
97 if (ret)
98 return ret;
99
100 + netdev_update_addr_mask(dev);
101 ret = call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
102 &changeupper_info.info);
103 ret = notifier_to_errno(ret);
104 @@ -7753,6 +7796,7 @@ static void __netdev_upper_dev_unlink(st
105
106 __netdev_adjacent_dev_unlink_neighbour(dev, upper_dev);
107
108 + netdev_update_addr_mask(dev);
109 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
110 &changeupper_info.info);
111
112 @@ -8805,6 +8849,7 @@ int dev_set_mac_address(struct net_devic
113 if (err)
114 return err;
115 dev->addr_assign_type = NET_ADDR_SET;
116 + netdev_update_addr_mask(dev);
117 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
118 add_device_randomness(dev->dev_addr, dev->addr_len);
119 return 0;
120 --- a/net/ethernet/eth.c
121 +++ b/net/ethernet/eth.c
122 @@ -143,6 +143,18 @@ u32 eth_get_headlen(const struct net_dev
123 }
124 EXPORT_SYMBOL(eth_get_headlen);
125
126 +static inline bool
127 +eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
128 +{
129 + const u16 *a1 = addr1;
130 + const u16 *a2 = addr2;
131 + const u16 *m = mask;
132 +
133 + return (((a1[0] ^ a2[0]) & ~m[0]) |
134 + ((a1[1] ^ a2[1]) & ~m[1]) |
135 + ((a1[2] ^ a2[2]) & ~m[2]));
136 +}
137 +
138 /**
139 * eth_type_trans - determine the packet's protocol ID.
140 * @skb: received socket data
141 @@ -174,6 +186,10 @@ __be16 eth_type_trans(struct sk_buff *sk
142 } else {
143 skb->pkt_type = PACKET_OTHERHOST;
144 }
145 +
146 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
147 + dev->local_addr_mask))
148 + skb->gro_skip = 1;
149 }
150
151 /*