@@ -27,14 +27,16 @@ int timer_result;
2727const volatile bool has_stack_arg = true;
2828
2929__noinline static int static_func_many_args (int a , int b , int c , int d ,
30- int e , int f , int g , int h )
30+ int e , int f , int g , int h ,
31+ int i , int j )
3132{
32- return a + b + c + d + e + f + g + h ;
33+ return a + b + c + d + e + f + g + h + i + j ;
3334}
3435
3536__noinline int global_calls_many_args (int a , int b , int c )
3637{
37- return static_func_many_args (a , b , c , 4 , 5 , 6 , 7 , 8 );
38+ return static_func_many_args (a , b , c , a + 3 , a + 4 , a + 5 , a + 6 ,
39+ a + 7 , a + 8 , a + 9 );
3840}
3941
4042SEC ("tc" )
@@ -48,18 +50,20 @@ struct test_data {
4850 long y ;
4951};
5052
51- /* 1 + 2 + 3 + 4 + 5 + 10 + 20 = 45 */
53+ /* 1+2+3+4+5+6+7+8+9+10+ 20 = 75 */
5254__noinline static long func_with_ptr_stack_arg (long a , long b , long c , long d ,
53- long e , struct test_data * p )
55+ long e , long f , long g , long h ,
56+ long i , struct test_data * p )
5457{
55- return a + b + c + d + e + p -> x + p -> y ;
58+ return a + b + c + d + e + f + g + h + i + p -> x + p -> y ;
5659}
5760
5861__noinline long global_ptr_stack_arg (long a , long b , long c , long d , long e )
5962{
6063 struct test_data data = { .x = 10 , .y = 20 };
6164
62- return func_with_ptr_stack_arg (a , b , c , d , e , & data );
65+ return func_with_ptr_stack_arg (a , b , c , d , e , a + 5 , a + 6 , a + 7 ,
66+ a + 8 , & data );
6367}
6468
6569SEC ("tc" )
@@ -68,20 +72,22 @@ int test_bpf2bpf_ptr_stack_arg(void)
6872 return global_ptr_stack_arg (1 , 2 , 3 , 4 , 5 );
6973}
7074
71- /* 1 + 2 + 3 + 4 + 5 + 10 + 6 + 20 = 51 */
75+ /* 1+2+3+4+5+6+7+10+8+ 20 = 66 */
7276__noinline static long func_with_mix_stack_args (long a , long b , long c , long d ,
73- long e , struct test_data * p ,
74- long f , struct test_data * q )
77+ long e , long f , long g ,
78+ struct test_data * p ,
79+ long h , struct test_data * q )
7580{
76- return a + b + c + d + e + p -> x + f + q -> y ;
81+ return a + b + c + d + e + f + g + p -> x + h + q -> y ;
7782}
7883
7984__noinline long global_mix_stack_args (long a , long b , long c , long d , long e )
8085{
8186 struct test_data p = { .x = 10 };
8287 struct test_data q = { .y = 20 };
8388
84- return func_with_mix_stack_args (a , b , c , d , e , & p , e + 1 , & q );
89+ return func_with_mix_stack_args (a , b , c , d , e , e + 1 , e + 2 , & p ,
90+ e + 3 , & q );
8591}
8692
8793SEC ("tc" )
@@ -94,26 +100,30 @@ int test_bpf2bpf_mix_stack_args(void)
94100 * Nesting test: func_outer calls func_inner, both with struct pointer
95101 * as stack arg.
96102 *
97- * func_inner: (a+1) + (b+1) + (c+1) + (d+1) + (e +1) + p->x + p->y
98- * = 2 + 3 + 4 + 5 + 6 + 10 + 20 = 50
103+ * func_inner: (a+1)+...+(i +1) + p->x + p->y
104+ * = 2+3+4+5+6+7+8+9+10+10+ 20 = 84
99105 */
100106__noinline static long func_inner_ptr (long a , long b , long c , long d ,
101- long e , struct test_data * p )
107+ long e , long f , long g , long h ,
108+ long i , struct test_data * p )
102109{
103- return a + b + c + d + e + p -> x + p -> y ;
110+ return a + b + c + d + e + f + g + h + i + p -> x + p -> y ;
104111}
105112
106113__noinline static long func_outer_ptr (long a , long b , long c , long d ,
107- long e , struct test_data * p )
114+ long e , long f , long g , long h ,
115+ long i , struct test_data * p )
108116{
109- return func_inner_ptr (a + 1 , b + 1 , c + 1 , d + 1 , e + 1 , p );
117+ return func_inner_ptr (a + 1 , b + 1 , c + 1 , d + 1 , e + 1 ,
118+ f + 1 , g + 1 , h + 1 , i + 1 , p );
110119}
111120
112121__noinline long global_nesting_ptr (long a , long b , long c , long d , long e )
113122{
114123 struct test_data data = { .x = 10 , .y = 20 };
115124
116- return func_outer_ptr (a , b , c , d , e , & data );
125+ return func_outer_ptr (a , b , c , d , e , a + 5 , a + 6 , a + 7 , a + 8 ,
126+ & data );
117127}
118128
119129SEC ("tc" )
@@ -122,11 +132,12 @@ int test_bpf2bpf_nesting_stack_arg(void)
122132 return global_nesting_ptr (1 , 2 , 3 , 4 , 5 );
123133}
124134
125- /* 1 + 2 + 3 + 4 + 5 + sizeof(pkt_v4) = 15 + 54 = 69 */
135+ /* 1+2+3+4+5+6+7+8+9+ sizeof(pkt_v4) = 45+ 54 = 99 */
126136__noinline static long func_with_dynptr (long a , long b , long c , long d ,
127- long e , struct bpf_dynptr * ptr )
137+ long e , long f , long g , long h ,
138+ long i , struct bpf_dynptr * ptr )
128139{
129- return a + b + c + d + e + bpf_dynptr_size (ptr );
140+ return a + b + c + d + e + f + g + h + i + bpf_dynptr_size (ptr );
130141}
131142
132143__noinline long global_dynptr_stack_arg (void * ctx __arg_ctx , long a , long b ,
@@ -135,7 +146,8 @@ __noinline long global_dynptr_stack_arg(void *ctx __arg_ctx, long a, long b,
135146 struct bpf_dynptr ptr ;
136147
137148 bpf_dynptr_from_skb (ctx , 0 , & ptr );
138- return func_with_dynptr (a , b , c , d , d + 1 , & ptr );
149+ return func_with_dynptr (a , b , c , d , d + 1 , d + 2 , d + 3 , d + 4 ,
150+ d + 5 , & ptr );
139151}
140152
141153SEC ("tc" )
@@ -144,33 +156,35 @@ int test_bpf2bpf_dynptr_stack_arg(struct __sk_buff *skb)
144156 return global_dynptr_stack_arg (skb , 1 , 2 , 3 , 4 );
145157}
146158
147- /* foo1: a+b+c+d+e+f+g+h */
148- __noinline static int foo1 (int a , int b , int c , int d ,
149- int e , int f , int g , int h )
159+ /* foo1: a+b+c+d+e+f+g+h+i+j */
160+ __noinline static int foo1 (int a , int b , int c , int d , int e ,
161+ int f , int g , int h , int i , int j )
150162{
151- return a + b + c + d + e + f + g + h ;
163+ return a + b + c + d + e + f + g + h + i + j ;
152164}
153165
154- /* foo2: a+b+c+d+e+f+g+h+i+j */
166+ /* foo2: a+b+c+d+e+f+g+h+i+j+k+l */
155167__noinline static int foo2 (int a , int b , int c , int d , int e ,
156- int f , int g , int h , int i , int j )
168+ int f , int g , int h , int i , int j ,
169+ int k , int l )
157170{
158- return a + b + c + d + e + f + g + h + i + j ;
171+ return a + b + c + d + e + f + g + h + i + j + k + l ;
159172}
160173
161- /* global_two_callees calls foo1 (3 stack args) and foo2 (5 stack args).
174+ /* global_two_callees calls foo1 (5 stack args) and foo2 (7 stack args).
162175 * The outgoing stack arg area is sized for foo2 (the larger callee).
163176 * Stores for foo1 are a subset of the area used by foo2.
164- * Result: foo1(1,2,3,4,5,6,7,8 ) + foo2(1,2,3,4,5,6,7,8,9,10 ) = 36 + 55 = 91
177+ * Result: foo1(1..10 ) + foo2(1..12 ) = 55 + 78 = 133
165178 *
166179 * Pass a-e through so the compiler can't constant-fold the stack args away.
167180 */
168181__noinline int global_two_callees (int a , int b , int c , int d , int e )
169182{
170183 int ret ;
171184
172- ret = foo1 (a , b , c , d , e , a + 5 , a + 6 , a + 7 );
173- ret += foo2 (a , b , c , d , e , a + 5 , a + 6 , a + 7 , a + 8 , a + 9 );
185+ ret = foo1 (a , b , c , d , e , a + 5 , a + 6 , a + 7 , a + 8 , a + 9 );
186+ ret += foo2 (a , b , c , d , e , a + 5 , a + 6 , a + 7 , a + 8 , a + 9 ,
187+ a + 10 , a + 11 );
174188 return ret ;
175189}
176190
@@ -180,9 +194,15 @@ int test_two_callees(void)
180194 return global_two_callees (1 , 2 , 3 , 4 , 5 );
181195}
182196
197+ const volatile int timer_base = 10 ;
198+
183199static int timer_cb_many_args (void * map , int * key , struct bpf_timer * timer )
184200{
185- timer_result = static_func_many_args (10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 );
201+ int v = timer_base ;
202+
203+ timer_result = static_func_many_args (v , v * 2 , v * 3 , v * 4 , v * 5 ,
204+ v * 6 , v * 7 , v * 8 , v * 9 ,
205+ v * 10 );
186206 return 0 ;
187207}
188208
0 commit comments