kernel: bump 4.14 to 4.14.115
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.14 / 202-core-linux-support-layerscape.patch
1 From 74243154052af635ee9ce9d07aab273ce219c855 Mon Sep 17 00:00:00 2001
2 From: Biwen Li <biwen.li@nxp.com>
3 Date: Thu, 13 Dec 2018 13:23:52 +0800
4 Subject: [PATCH] core-linux: support layerscape
5
6 This is an integrated patch of core-linux for layerscape.
7
8 Signed-off-by: Abhijit Ayarekar <abhijit.ayarekar@caviumnetworks.com>
9 Signed-off-by: Amrita Kumari <amrita.kumari@nxp.com>
10 Signed-off-by: Ashish Kumar <Ashish.Kumar@nxp.com>
11 Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
12 Signed-off-by: Christoph Hellwig <hch@lst.de>
13 Signed-off-by: David Ahern <dsahern@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 Signed-off-by: Guanhua Gao <guanhua.gao@nxp.com>
16 Signed-off-by: Jiri Pirko <jiri@mellanox.com>
17 Signed-off-by: Joel Fernandes <joelaf@google.com>
18 Signed-off-by: Li Yang <leoyang.li@nxp.com>
19 Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
20 Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
21 Signed-off-by: Nikhil Badola <nikhil.badola@freescale.com>
22 Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
23 Signed-off-by: Ramneek Mehresh <ramneek.mehresh@freescale.com>
24 Signed-off-by: Robin Murphy <robin.murphy@arm.com>
25 Signed-off-by: Suresh Gupta <suresh.gupta@freescale.com>
26 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
27 Signed-off-by: yinbo.zhu <yinbo.zhu@nxp.com>
28 Signed-off-by: Biwen Li <biwen.li@nxp.com>
29 ---
30 drivers/base/dma-mapping.c | 7 ++
31 drivers/net/bonding/bond_main.c | 5 +-
32 drivers/net/bonding/bond_options.c | 2 +-
33 drivers/net/team/team.c | 3 +-
34 drivers/net/vrf.c | 3 +-
35 drivers/of/device.c | 13 +++-
36 drivers/soc/fsl/guts.c | 3 +
37 include/linux/fsl_devices.h | 2 +
38 include/linux/netdevice.h | 13 +++-
39 include/linux/skbuff.h | 2 +
40 include/net/bonding.h | 3 +-
41 net/batman-adv/soft-interface.c | 3 +-
42 net/bridge/br_device.c | 3 +-
43 net/core/dev.c | 81 ++++++++++++++---------
44 net/core/rtnetlink.c | 10 +--
45 net/core/skbuff.c | 29 +++++++-
46 samples/bpf/Makefile | 12 +++-
47 samples/bpf/map_perf_test_kern.c | 2 +-
48 samples/bpf/map_perf_test_user.c | 2 +-
49 tools/testing/selftests/bpf/bpf_helpers.h | 56 ++++++++++++++--
50 20 files changed, 193 insertions(+), 61 deletions(-)
51
52 --- a/drivers/base/dma-mapping.c
53 +++ b/drivers/base/dma-mapping.c
54 @@ -335,6 +335,7 @@ void dma_common_free_remap(void *cpu_add
55 * Common configuration to enable DMA API use for a device
56 */
57 #include <linux/pci.h>
58 +#include <linux/fsl/mc.h>
59
60 int dma_configure(struct device *dev)
61 {
62 @@ -350,6 +351,12 @@ int dma_configure(struct device *dev)
63 dma_dev = dma_dev->parent;
64 }
65
66 + if (dev_is_fsl_mc(dev)) {
67 + dma_dev = dev;
68 + while (dev_is_fsl_mc(dma_dev))
69 + dma_dev = dma_dev->parent;
70 + }
71 +
72 if (dma_dev->of_node) {
73 ret = of_dma_configure(dev, dma_dev->of_node);
74 } else if (has_acpi_companion(dma_dev)) {
75 --- a/drivers/net/bonding/bond_main.c
76 +++ b/drivers/net/bonding/bond_main.c
77 @@ -1330,7 +1330,8 @@ void bond_lower_state_changed(struct sla
78 }
79
80 /* enslave device <slave> to bond device <master> */
81 -int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
82 +int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
83 + struct netlink_ext_ack *extack)
84 {
85 struct bonding *bond = netdev_priv(bond_dev);
86 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
87 @@ -3506,7 +3507,7 @@ static int bond_do_ioctl(struct net_devi
88 switch (cmd) {
89 case BOND_ENSLAVE_OLD:
90 case SIOCBONDENSLAVE:
91 - res = bond_enslave(bond_dev, slave_dev);
92 + res = bond_enslave(bond_dev, slave_dev, NULL);
93 break;
94 case BOND_RELEASE_OLD:
95 case SIOCBONDRELEASE:
96 --- a/drivers/net/bonding/bond_options.c
97 +++ b/drivers/net/bonding/bond_options.c
98 @@ -1389,7 +1389,7 @@ static int bond_option_slaves_set(struct
99 switch (command[0]) {
100 case '+':
101 netdev_dbg(bond->dev, "Adding slave %s\n", dev->name);
102 - ret = bond_enslave(bond->dev, dev);
103 + ret = bond_enslave(bond->dev, dev, NULL);
104 break;
105
106 case '-':
107 --- a/drivers/net/team/team.c
108 +++ b/drivers/net/team/team.c
109 @@ -1953,7 +1953,8 @@ static int team_netpoll_setup(struct net
110 }
111 #endif
112
113 -static int team_add_slave(struct net_device *dev, struct net_device *port_dev)
114 +static int team_add_slave(struct net_device *dev, struct net_device *port_dev,
115 + struct netlink_ext_ack *extack)
116 {
117 struct team *team = netdev_priv(dev);
118 int err;
119 --- a/drivers/net/vrf.c
120 +++ b/drivers/net/vrf.c
121 @@ -791,7 +791,8 @@ err:
122 return ret;
123 }
124
125 -static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev)
126 +static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev,
127 + struct netlink_ext_ack *extack)
128 {
129 if (netif_is_l3_master(port_dev) || netif_is_l3_slave(port_dev))
130 return -EINVAL;
131 --- a/drivers/of/device.c
132 +++ b/drivers/of/device.c
133 @@ -15,6 +15,9 @@
134
135 #include <asm/errno.h>
136 #include "of_private.h"
137 +#ifdef CONFIG_FSL_MC_BUS
138 +#include <linux/fsl/mc.h>
139 +#endif
140
141 /**
142 * of_match_device - Tell if a struct device matches an of_device_id list
143 @@ -105,6 +108,9 @@ int of_dma_configure(struct device *dev,
144 #ifdef CONFIG_ARM_AMBA
145 dev->bus != &amba_bustype &&
146 #endif
147 +#ifdef CONFIG_FSL_MC_BUS
148 + dev->bus != &fsl_mc_bus_type &&
149 +#endif
150 dev->bus != &platform_bus_type)
151 return ret == -ENODEV ? 0 : ret;
152
153 @@ -155,7 +161,12 @@ int of_dma_configure(struct device *dev,
154 dev->coherent_dma_mask &= mask;
155 *dev->dma_mask &= mask;
156
157 - coherent = of_dma_is_coherent(np);
158 +#ifdef CONFIG_FSL_MC_BUS
159 + if (dev_is_fsl_mc(dev))
160 + coherent = fsl_mc_is_dev_coherent(dev);
161 + else
162 +#endif
163 + coherent = of_dma_is_coherent(np);
164 dev_dbg(dev, "device is%sdma coherent\n",
165 coherent ? " " : " not ");
166
167 --- a/drivers/soc/fsl/guts.c
168 +++ b/drivers/soc/fsl/guts.c
169 @@ -213,6 +213,9 @@ static const struct of_device_id fsl_gut
170 { .compatible = "fsl,ls1021a-dcfg", },
171 { .compatible = "fsl,ls1043a-dcfg", },
172 { .compatible = "fsl,ls2080a-dcfg", },
173 + { .compatible = "fsl,ls1088a-dcfg", },
174 + { .compatible = "fsl,ls1012a-dcfg", },
175 + { .compatible = "fsl,ls1046a-dcfg", },
176 {}
177 };
178 MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
179 --- a/include/linux/fsl_devices.h
180 +++ b/include/linux/fsl_devices.h
181 @@ -99,7 +99,9 @@ struct fsl_usb2_platform_data {
182 unsigned suspended:1;
183 unsigned already_suspended:1;
184 unsigned has_fsl_erratum_a007792:1;
185 + unsigned has_fsl_erratum_14:1;
186 unsigned has_fsl_erratum_a005275:1;
187 + unsigned has_fsl_erratum_a006918:1;
188 unsigned has_fsl_erratum_a005697:1;
189 unsigned check_phy_clk_valid:1;
190
191 --- a/include/linux/netdevice.h
192 +++ b/include/linux/netdevice.h
193 @@ -1260,7 +1260,8 @@ struct net_device_ops {
194 u32 flow_id);
195 #endif
196 int (*ndo_add_slave)(struct net_device *dev,
197 - struct net_device *slave_dev);
198 + struct net_device *slave_dev,
199 + struct netlink_ext_ack *extack);
200 int (*ndo_del_slave)(struct net_device *dev,
201 struct net_device *slave_dev);
202 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
203 @@ -2344,7 +2345,8 @@ int register_netdevice_notifier(struct n
204 int unregister_netdevice_notifier(struct notifier_block *nb);
205
206 struct netdev_notifier_info {
207 - struct net_device *dev;
208 + struct net_device *dev;
209 + struct netlink_ext_ack *extack;
210 };
211
212 struct netdev_notifier_info_ext {
213 @@ -2376,6 +2378,7 @@ static inline void netdev_notifier_info_
214 struct net_device *dev)
215 {
216 info->dev = dev;
217 + info->extack = NULL;
218 }
219
220 static inline struct net_device *
221 @@ -2384,6 +2387,12 @@ netdev_notifier_info_to_dev(const struct
222 return info->dev;
223 }
224
225 +static inline struct netlink_ext_ack *
226 +netdev_notifier_info_to_extack(const struct netdev_notifier_info *info)
227 +{
228 + return info->extack;
229 +}
230 +
231 int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
232
233
234 --- a/include/linux/skbuff.h
235 +++ b/include/linux/skbuff.h
236 @@ -964,6 +964,7 @@ void kfree_skb_list(struct sk_buff *segs
237 void skb_tx_error(struct sk_buff *skb);
238 void consume_skb(struct sk_buff *skb);
239 void __consume_stateless_skb(struct sk_buff *skb);
240 +void skb_recycle(struct sk_buff *skb);
241 void __kfree_skb(struct sk_buff *skb);
242 extern struct kmem_cache *skbuff_head_cache;
243
244 @@ -3294,6 +3295,7 @@ static inline void skb_free_datagram_loc
245 }
246 int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags);
247 int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len);
248 +void copy_skb_header(struct sk_buff *new, const struct sk_buff *old);
249 int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len);
250 __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, u8 *to,
251 int len, __wsum csum);
252 --- a/include/net/bonding.h
253 +++ b/include/net/bonding.h
254 @@ -592,7 +592,8 @@ void bond_destroy_sysfs(struct bond_net
255 void bond_prepare_sysfs_group(struct bonding *bond);
256 int bond_sysfs_slave_add(struct slave *slave);
257 void bond_sysfs_slave_del(struct slave *slave);
258 -int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
259 +int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
260 + struct netlink_ext_ack *extack);
261 int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
262 u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb);
263 int bond_set_carrier(struct bonding *bond);
264 --- a/net/batman-adv/soft-interface.c
265 +++ b/net/batman-adv/soft-interface.c
266 @@ -876,7 +876,8 @@ free_bat_counters:
267 * Return: 0 if successful or error otherwise.
268 */
269 static int batadv_softif_slave_add(struct net_device *dev,
270 - struct net_device *slave_dev)
271 + struct net_device *slave_dev,
272 + struct netlink_ext_ack *extack)
273 {
274 struct batadv_hard_iface *hard_iface;
275 struct net *net = dev_net(dev);
276 --- a/net/bridge/br_device.c
277 +++ b/net/bridge/br_device.c
278 @@ -324,7 +324,8 @@ void br_netpoll_disable(struct net_bridg
279
280 #endif
281
282 -static int br_add_slave(struct net_device *dev, struct net_device *slave_dev)
283 +static int br_add_slave(struct net_device *dev, struct net_device *slave_dev,
284 + struct netlink_ext_ack *extack)
285
286 {
287 struct net_bridge *br = netdev_priv(dev);
288 --- a/net/core/dev.c
289 +++ b/net/core/dev.c
290 @@ -162,7 +162,6 @@ static struct list_head offload_base __r
291
292 static int netif_rx_internal(struct sk_buff *skb);
293 static int call_netdevice_notifiers_info(unsigned long val,
294 - struct net_device *dev,
295 struct netdev_notifier_info *info);
296 static struct napi_struct *napi_by_id(unsigned int napi_id);
297
298 @@ -1312,10 +1311,11 @@ EXPORT_SYMBOL(netdev_features_change);
299 void netdev_state_change(struct net_device *dev)
300 {
301 if (dev->flags & IFF_UP) {
302 - struct netdev_notifier_change_info change_info;
303 + struct netdev_notifier_change_info change_info = {
304 + .info.dev = dev,
305 + };
306
307 - change_info.flags_changed = 0;
308 - call_netdevice_notifiers_info(NETDEV_CHANGE, dev,
309 + call_netdevice_notifiers_info(NETDEV_CHANGE,
310 &change_info.info);
311 rtmsg_ifinfo(RTM_NEWLINK, dev, 0, GFP_KERNEL);
312 }
313 @@ -1536,9 +1536,10 @@ EXPORT_SYMBOL(dev_disable_lro);
314 static int call_netdevice_notifier(struct notifier_block *nb, unsigned long val,
315 struct net_device *dev)
316 {
317 - struct netdev_notifier_info info;
318 + struct netdev_notifier_info info = {
319 + .dev = dev,
320 + };
321
322 - netdev_notifier_info_init(&info, dev);
323 return nb->notifier_call(nb, val, &info);
324 }
325
326 @@ -1663,11 +1664,9 @@ EXPORT_SYMBOL(unregister_netdevice_notif
327 */
328
329 static int call_netdevice_notifiers_info(unsigned long val,
330 - struct net_device *dev,
331 struct netdev_notifier_info *info)
332 {
333 ASSERT_RTNL();
334 - netdev_notifier_info_init(info, dev);
335 return raw_notifier_call_chain(&netdev_chain, val, info);
336 }
337
338 @@ -1682,9 +1681,11 @@ static int call_netdevice_notifiers_info
339
340 int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
341 {
342 - struct netdev_notifier_info info;
343 + struct netdev_notifier_info info = {
344 + .dev = dev,
345 + };
346
347 - return call_netdevice_notifiers_info(val, dev, &info);
348 + return call_netdevice_notifiers_info(val, &info);
349 }
350 EXPORT_SYMBOL(call_netdevice_notifiers);
351
352 @@ -1707,7 +1708,7 @@ static int call_netdevice_notifiers_mtu(
353
354 BUILD_BUG_ON(offsetof(struct netdev_notifier_info_ext, info) != 0);
355
356 - return call_netdevice_notifiers_info(val, dev, &info.info);
357 + return call_netdevice_notifiers_info(val, &info.info);
358 }
359
360 #ifdef CONFIG_NET_INGRESS
361 @@ -6338,7 +6339,15 @@ static int __netdev_upper_dev_link(struc
362 struct net_device *upper_dev, bool master,
363 void *upper_priv, void *upper_info)
364 {
365 - struct netdev_notifier_changeupper_info changeupper_info;
366 + struct netdev_notifier_changeupper_info changeupper_info = {
367 + .info = {
368 + .dev = dev,
369 + },
370 + .upper_dev = upper_dev,
371 + .master = master,
372 + .linking = true,
373 + .upper_info = upper_info,
374 + };
375 int ret = 0;
376
377 ASSERT_RTNL();
378 @@ -6356,12 +6365,7 @@ static int __netdev_upper_dev_link(struc
379 if (master && netdev_master_upper_dev_get(dev))
380 return -EBUSY;
381
382 - changeupper_info.upper_dev = upper_dev;
383 - changeupper_info.master = master;
384 - changeupper_info.linking = true;
385 - changeupper_info.upper_info = upper_info;
386 -
387 - ret = call_netdevice_notifiers_info(NETDEV_PRECHANGEUPPER, dev,
388 + ret = call_netdevice_notifiers_info(NETDEV_PRECHANGEUPPER,
389 &changeupper_info.info);
390 ret = notifier_to_errno(ret);
391 if (ret)
392 @@ -6373,7 +6377,7 @@ static int __netdev_upper_dev_link(struc
393 return ret;
394
395 netdev_update_addr_mask(dev);
396 - ret = call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
397 + ret = call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
398 &changeupper_info.info);
399 ret = notifier_to_errno(ret);
400 if (ret)
401 @@ -6437,21 +6441,25 @@ EXPORT_SYMBOL(netdev_master_upper_dev_li
402 void netdev_upper_dev_unlink(struct net_device *dev,
403 struct net_device *upper_dev)
404 {
405 - struct netdev_notifier_changeupper_info changeupper_info;
406 + struct netdev_notifier_changeupper_info changeupper_info = {
407 + .info = {
408 + .dev = dev,
409 + },
410 + .upper_dev = upper_dev,
411 + .linking = false,
412 + };
413
414 ASSERT_RTNL();
415
416 - changeupper_info.upper_dev = upper_dev;
417 changeupper_info.master = netdev_master_upper_dev_get(dev) == upper_dev;
418 - changeupper_info.linking = false;
419
420 - call_netdevice_notifiers_info(NETDEV_PRECHANGEUPPER, dev,
421 + call_netdevice_notifiers_info(NETDEV_PRECHANGEUPPER,
422 &changeupper_info.info);
423
424 __netdev_adjacent_dev_unlink_neighbour(dev, upper_dev);
425
426 netdev_update_addr_mask(dev);
427 - call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
428 + call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
429 &changeupper_info.info);
430 }
431 EXPORT_SYMBOL(netdev_upper_dev_unlink);
432 @@ -6467,11 +6475,13 @@ EXPORT_SYMBOL(netdev_upper_dev_unlink);
433 void netdev_bonding_info_change(struct net_device *dev,
434 struct netdev_bonding_info *bonding_info)
435 {
436 - struct netdev_notifier_bonding_info info;
437 + struct netdev_notifier_bonding_info info = {
438 + .info.dev = dev,
439 + };
440
441 memcpy(&info.bonding_info, bonding_info,
442 sizeof(struct netdev_bonding_info));
443 - call_netdevice_notifiers_info(NETDEV_BONDING_INFO, dev,
444 + call_netdevice_notifiers_info(NETDEV_BONDING_INFO,
445 &info.info);
446 }
447 EXPORT_SYMBOL(netdev_bonding_info_change);
448 @@ -6597,11 +6607,13 @@ EXPORT_SYMBOL(dev_get_nest_level);
449 void netdev_lower_state_changed(struct net_device *lower_dev,
450 void *lower_state_info)
451 {
452 - struct netdev_notifier_changelowerstate_info changelowerstate_info;
453 + struct netdev_notifier_changelowerstate_info changelowerstate_info = {
454 + .info.dev = lower_dev,
455 + };
456
457 ASSERT_RTNL();
458 changelowerstate_info.lower_state_info = lower_state_info;
459 - call_netdevice_notifiers_info(NETDEV_CHANGELOWERSTATE, lower_dev,
460 + call_netdevice_notifiers_info(NETDEV_CHANGELOWERSTATE,
461 &changelowerstate_info.info);
462 }
463 EXPORT_SYMBOL(netdev_lower_state_changed);
464 @@ -6892,11 +6904,14 @@ void __dev_notify_flags(struct net_devic
465
466 if (dev->flags & IFF_UP &&
467 (changes & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI | IFF_VOLATILE))) {
468 - struct netdev_notifier_change_info change_info;
469 + struct netdev_notifier_change_info change_info = {
470 + .info = {
471 + .dev = dev,
472 + },
473 + .flags_changed = changes,
474 + };
475
476 - change_info.flags_changed = changes;
477 - call_netdevice_notifiers_info(NETDEV_CHANGE, dev,
478 - &change_info.info);
479 + call_netdevice_notifiers_info(NETDEV_CHANGE, &change_info.info);
480 }
481 }
482
483 --- a/net/core/rtnetlink.c
484 +++ b/net/core/rtnetlink.c
485 @@ -1912,7 +1912,8 @@ static int do_setvfinfo(struct net_devic
486 return err;
487 }
488
489 -static int do_set_master(struct net_device *dev, int ifindex)
490 +static int do_set_master(struct net_device *dev, int ifindex,
491 + struct netlink_ext_ack *extack)
492 {
493 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
494 const struct net_device_ops *ops;
495 @@ -1937,7 +1938,7 @@ static int do_set_master(struct net_devi
496 return -EINVAL;
497 ops = upper_dev->netdev_ops;
498 if (ops->ndo_add_slave) {
499 - err = ops->ndo_add_slave(upper_dev, dev);
500 + err = ops->ndo_add_slave(upper_dev, dev, extack);
501 if (err)
502 return err;
503 } else {
504 @@ -2074,7 +2075,7 @@ static int do_setlink(const struct sk_bu
505 }
506
507 if (tb[IFLA_MASTER]) {
508 - err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]));
509 + err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]), extack);
510 if (err)
511 goto errout;
512 status |= DO_SETLINK_MODIFIED;
513 @@ -2723,7 +2724,8 @@ replay:
514 goto out_unregister;
515 }
516 if (tb[IFLA_MASTER]) {
517 - err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]));
518 + err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]),
519 + extack);
520 if (err)
521 goto out_unregister;
522 }
523 --- a/net/core/skbuff.c
524 +++ b/net/core/skbuff.c
525 @@ -803,6 +803,32 @@ void napi_consume_skb(struct sk_buff *sk
526 }
527 EXPORT_SYMBOL(napi_consume_skb);
528
529 +/**
530 + * skb_recycle - clean up an skb for reuse
531 + * @skb: buffer
532 + *
533 + * Recycles the skb to be reused as a receive buffer. This
534 + * function does any necessary reference count dropping, and
535 + * cleans up the skbuff as if it just came from __alloc_skb().
536 + */
537 +void skb_recycle(struct sk_buff *skb)
538 +{
539 + struct skb_shared_info *shinfo;
540 + u8 head_frag = skb->head_frag;
541 +
542 + skb_release_head_state(skb);
543 +
544 + shinfo = skb_shinfo(skb);
545 + memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
546 + atomic_set(&shinfo->dataref, 1);
547 +
548 + memset(skb, 0, offsetof(struct sk_buff, tail));
549 + skb->data = skb->head + NET_SKB_PAD;
550 + skb->head_frag = head_frag;
551 + skb_reset_tail_pointer(skb);
552 +}
553 +EXPORT_SYMBOL(skb_recycle);
554 +
555 /* Make sure a field is enclosed inside headers_start/headers_end section */
556 #define CHECK_SKB_FIELD(field) \
557 BUILD_BUG_ON(offsetof(struct sk_buff, field) < \
558 @@ -1322,7 +1348,7 @@ static void skb_headers_offset_update(st
559 skb->inner_mac_header += off;
560 }
561
562 -static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
563 +void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
564 {
565 __copy_skb_header(new, old);
566
567 @@ -1330,6 +1356,7 @@ static void copy_skb_header(struct sk_bu
568 skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
569 skb_shinfo(new)->gso_type = skb_shinfo(old)->gso_type;
570 }
571 +EXPORT_SYMBOL(copy_skb_header);
572
573 static inline int skb_alloc_rx_flag(const struct sk_buff *skb)
574 {
575 --- a/samples/bpf/Makefile
576 +++ b/samples/bpf/Makefile
577 @@ -178,6 +178,12 @@ HOSTLOADLIBES_syscall_tp += -lelf
578 LLC ?= llc
579 CLANG ?= clang
580
581 +# Detect that we're cross compiling and use the cross compiler
582 +ifdef CROSS_COMPILE
583 +HOSTCC = $(CROSS_COMPILE)gcc
584 +CLANG_ARCH_ARGS = -target $(ARCH)
585 +endif
586 +
587 # Trick to allow make to be run from this directory
588 all: $(LIBBPF)
589 $(MAKE) -C ../../ $(CURDIR)/
590 @@ -228,9 +234,9 @@ $(obj)/tracex5_kern.o: $(obj)/syscall_nr
591 $(obj)/%.o: $(src)/%.c
592 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
593 -I$(srctree)/tools/testing/selftests/bpf/ \
594 - -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
595 - -Wno-compare-distinct-pointer-types \
596 + -D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
597 + -D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
598 -Wno-gnu-variable-sized-type-not-at-end \
599 -Wno-address-of-packed-member -Wno-tautological-compare \
600 - -Wno-unknown-warning-option \
601 + -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
602 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
603 --- a/samples/bpf/map_perf_test_kern.c
604 +++ b/samples/bpf/map_perf_test_kern.c
605 @@ -266,7 +266,7 @@ int stress_hash_map_lookup(struct pt_reg
606 return 0;
607 }
608
609 -SEC("kprobe/sys_getpgrp")
610 +SEC("kprobe/sys_getppid")
611 int stress_array_map_lookup(struct pt_regs *ctx)
612 {
613 u32 key = 1, i;
614 --- a/samples/bpf/map_perf_test_user.c
615 +++ b/samples/bpf/map_perf_test_user.c
616 @@ -282,7 +282,7 @@ static void test_array_lookup(int cpu)
617
618 start_time = time_get_ns();
619 for (i = 0; i < max_cnt; i++)
620 - syscall(__NR_getpgrp, 0);
621 + syscall(__NR_getppid, 0);
622 printf("%d:array_lookup %lld lookups per sec\n",
623 cpu, max_cnt * 1000000000ll * 64 / (time_get_ns() - start_time));
624 }
625 --- a/tools/testing/selftests/bpf/bpf_helpers.h
626 +++ b/tools/testing/selftests/bpf/bpf_helpers.h
627 @@ -110,7 +110,47 @@ static int (*bpf_skb_under_cgroup)(void
628 static int (*bpf_skb_change_head)(void *, int len, int flags) =
629 (void *) BPF_FUNC_skb_change_head;
630
631 +/* Scan the ARCH passed in from ARCH env variable (see Makefile) */
632 +#if defined(__TARGET_ARCH_x86)
633 + #define bpf_target_x86
634 + #define bpf_target_defined
635 +#elif defined(__TARGET_ARCH_s930x)
636 + #define bpf_target_s930x
637 + #define bpf_target_defined
638 +#elif defined(__TARGET_ARCH_arm64)
639 + #define bpf_target_arm64
640 + #define bpf_target_defined
641 +#elif defined(__TARGET_ARCH_mips)
642 + #define bpf_target_mips
643 + #define bpf_target_defined
644 +#elif defined(__TARGET_ARCH_powerpc)
645 + #define bpf_target_powerpc
646 + #define bpf_target_defined
647 +#elif defined(__TARGET_ARCH_sparc)
648 + #define bpf_target_sparc
649 + #define bpf_target_defined
650 +#else
651 + #undef bpf_target_defined
652 +#endif
653 +
654 +/* Fall back to what the compiler says */
655 +#ifndef bpf_target_defined
656 #if defined(__x86_64__)
657 + #define bpf_target_x86
658 +#elif defined(__s390x__)
659 + #define bpf_target_s930x
660 +#elif defined(__aarch64__)
661 + #define bpf_target_arm64
662 +#elif defined(__mips__)
663 + #define bpf_target_mips
664 +#elif defined(__powerpc__)
665 + #define bpf_target_powerpc
666 +#elif defined(__sparc__)
667 + #define bpf_target_sparc
668 +#endif
669 +#endif
670 +
671 +#if defined(bpf_target_x86)
672
673 #define PT_REGS_PARM1(x) ((x)->di)
674 #define PT_REGS_PARM2(x) ((x)->si)
675 @@ -123,7 +163,7 @@ static int (*bpf_skb_change_head)(void *
676 #define PT_REGS_SP(x) ((x)->sp)
677 #define PT_REGS_IP(x) ((x)->ip)
678
679 -#elif defined(__s390x__)
680 +#elif defined(bpf_target_s390x)
681
682 #define PT_REGS_PARM1(x) ((x)->gprs[2])
683 #define PT_REGS_PARM2(x) ((x)->gprs[3])
684 @@ -136,7 +176,7 @@ static int (*bpf_skb_change_head)(void *
685 #define PT_REGS_SP(x) ((x)->gprs[15])
686 #define PT_REGS_IP(x) ((x)->psw.addr)
687
688 -#elif defined(__aarch64__)
689 +#elif defined(bpf_target_arm64)
690
691 #define PT_REGS_PARM1(x) ((x)->regs[0])
692 #define PT_REGS_PARM2(x) ((x)->regs[1])
693 @@ -149,7 +189,7 @@ static int (*bpf_skb_change_head)(void *
694 #define PT_REGS_SP(x) ((x)->sp)
695 #define PT_REGS_IP(x) ((x)->pc)
696
697 -#elif defined(__mips__)
698 +#elif defined(bpf_target_mips)
699
700 #define PT_REGS_PARM1(x) ((x)->regs[4])
701 #define PT_REGS_PARM2(x) ((x)->regs[5])
702 @@ -162,7 +202,7 @@ static int (*bpf_skb_change_head)(void *
703 #define PT_REGS_SP(x) ((x)->regs[29])
704 #define PT_REGS_IP(x) ((x)->cp0_epc)
705
706 -#elif defined(__powerpc__)
707 +#elif defined(bpf_target_powerpc)
708
709 #define PT_REGS_PARM1(x) ((x)->gpr[3])
710 #define PT_REGS_PARM2(x) ((x)->gpr[4])
711 @@ -173,7 +213,7 @@ static int (*bpf_skb_change_head)(void *
712 #define PT_REGS_SP(x) ((x)->sp)
713 #define PT_REGS_IP(x) ((x)->nip)
714
715 -#elif defined(__sparc__)
716 +#elif defined(bpf_target_sparc)
717
718 #define PT_REGS_PARM1(x) ((x)->u_regs[UREG_I0])
719 #define PT_REGS_PARM2(x) ((x)->u_regs[UREG_I1])
720 @@ -183,6 +223,8 @@ static int (*bpf_skb_change_head)(void *
721 #define PT_REGS_RET(x) ((x)->u_regs[UREG_I7])
722 #define PT_REGS_RC(x) ((x)->u_regs[UREG_I0])
723 #define PT_REGS_SP(x) ((x)->u_regs[UREG_FP])
724 +
725 +/* Should this also be a bpf_target check for the sparc case? */
726 #if defined(__arch64__)
727 #define PT_REGS_IP(x) ((x)->tpc)
728 #else
729 @@ -191,10 +233,10 @@ static int (*bpf_skb_change_head)(void *
730
731 #endif
732
733 -#ifdef __powerpc__
734 +#ifdef bpf_target_powerpc
735 #define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = (ctx)->link; })
736 #define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
737 -#elif defined(__sparc__)
738 +#elif bpf_target_sparc
739 #define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = PT_REGS_RET(ctx); })
740 #define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
741 #else