1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2020 Facebook */
3 #include <stddef.h>
4 #include <linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7 
8 #define MAX_STACK (512 - 3 * 32)
9 
10 static __attribute__ ((noinline))
f0(int var,struct __sk_buff * skb)11 int f0(int var, struct __sk_buff *skb)
12 {
13 	return skb->len;
14 }
15 
16 __attribute__ ((noinline))
f1(struct __sk_buff * skb)17 int f1(struct __sk_buff *skb)
18 {
19 	volatile char buf[MAX_STACK] = {};
20 
21 	__sink(buf[MAX_STACK - 1]);
22 
23 	return f0(0, skb) + skb->len;
24 }
25 
26 int f3(int, struct __sk_buff *skb, int);
27 
28 __attribute__ ((noinline))
f2(int val,struct __sk_buff * skb)29 int f2(int val, struct __sk_buff *skb)
30 {
31 	return f1(skb) + f3(val, skb, 1);
32 }
33 
34 __attribute__ ((noinline))
f3(int val,struct __sk_buff * skb,int var)35 int f3(int val, struct __sk_buff *skb, int var)
36 {
37 	volatile char buf[MAX_STACK] = {};
38 
39 	__sink(buf[MAX_STACK - 1]);
40 
41 	return skb->ifindex * val * var;
42 }
43 
44 SEC("tc")
45 __success
global_func2(struct __sk_buff * skb)46 int global_func2(struct __sk_buff *skb)
47 {
48 	return f0(1, skb) + f1(skb) + f2(2, skb) + f3(3, skb, 4);
49 }
50