Skip to content

Commit 1e48e58

Browse files
borkmannkernel-patches-bot
authored andcommitted
bpf, selftests: use bpf_tail_call_static where appropriate
For those locations where we use an immediate tail call map index use the newly added bpf_tail_call_static() helper. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent f524f48 commit 1e48e58

File tree

9 files changed

+51
-49
lines changed

9 files changed

+51
-49
lines changed

samples/bpf/sockex3_kern.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,30 @@ struct {
3131
#define PARSE_IP 3
3232
#define PARSE_IPV6 4
3333

34-
/* protocol dispatch routine.
35-
* It tail-calls next BPF program depending on eth proto
36-
* Note, we could have used:
37-
* bpf_tail_call(skb, &jmp_table, proto);
38-
* but it would need large prog_array
34+
/* Protocol dispatch routine. It tail-calls next BPF program depending
35+
* on eth proto. Note, we could have used ...
36+
*
37+
* bpf_tail_call(skb, &jmp_table, proto);
38+
*
39+
* ... but it would need large prog_array and cannot be optimised given
40+
* the map key is not static.
3941
*/
4042
static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto)
4143
{
4244
switch (proto) {
4345
case ETH_P_8021Q:
4446
case ETH_P_8021AD:
45-
bpf_tail_call(skb, &jmp_table, PARSE_VLAN);
47+
bpf_tail_call_static(skb, &jmp_table, PARSE_VLAN);
4648
break;
4749
case ETH_P_MPLS_UC:
4850
case ETH_P_MPLS_MC:
49-
bpf_tail_call(skb, &jmp_table, PARSE_MPLS);
51+
bpf_tail_call_static(skb, &jmp_table, PARSE_MPLS);
5052
break;
5153
case ETH_P_IP:
52-
bpf_tail_call(skb, &jmp_table, PARSE_IP);
54+
bpf_tail_call_static(skb, &jmp_table, PARSE_IP);
5355
break;
5456
case ETH_P_IPV6:
55-
bpf_tail_call(skb, &jmp_table, PARSE_IPV6);
57+
bpf_tail_call_static(skb, &jmp_table, PARSE_IPV6);
5658
break;
5759
}
5860
}

tools/testing/selftests/bpf/progs/bpf_flow.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ static __always_inline int parse_eth_proto(struct __sk_buff *skb, __be16 proto)
118118

119119
switch (proto) {
120120
case bpf_htons(ETH_P_IP):
121-
bpf_tail_call(skb, &jmp_table, IP);
121+
bpf_tail_call_static(skb, &jmp_table, IP);
122122
break;
123123
case bpf_htons(ETH_P_IPV6):
124-
bpf_tail_call(skb, &jmp_table, IPV6);
124+
bpf_tail_call_static(skb, &jmp_table, IPV6);
125125
break;
126126
case bpf_htons(ETH_P_MPLS_MC):
127127
case bpf_htons(ETH_P_MPLS_UC):
128-
bpf_tail_call(skb, &jmp_table, MPLS);
128+
bpf_tail_call_static(skb, &jmp_table, MPLS);
129129
break;
130130
case bpf_htons(ETH_P_8021Q):
131131
case bpf_htons(ETH_P_8021AD):
132-
bpf_tail_call(skb, &jmp_table, VLAN);
132+
bpf_tail_call_static(skb, &jmp_table, VLAN);
133133
break;
134134
default:
135135
/* Protocol not supported */
@@ -246,10 +246,10 @@ static __always_inline int parse_ipv6_proto(struct __sk_buff *skb, __u8 nexthdr)
246246
switch (nexthdr) {
247247
case IPPROTO_HOPOPTS:
248248
case IPPROTO_DSTOPTS:
249-
bpf_tail_call(skb, &jmp_table, IPV6OP);
249+
bpf_tail_call_static(skb, &jmp_table, IPV6OP);
250250
break;
251251
case IPPROTO_FRAGMENT:
252-
bpf_tail_call(skb, &jmp_table, IPV6FR);
252+
bpf_tail_call_static(skb, &jmp_table, IPV6FR);
253253
break;
254254
default:
255255
return parse_ip_proto(skb, nexthdr);

tools/testing/selftests/bpf/progs/tailcall1.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ int entry(struct __sk_buff *skb)
2626
/* Multiple locations to make sure we patch
2727
* all of them.
2828
*/
29-
bpf_tail_call(skb, &jmp_table, 0);
30-
bpf_tail_call(skb, &jmp_table, 0);
31-
bpf_tail_call(skb, &jmp_table, 0);
32-
bpf_tail_call(skb, &jmp_table, 0);
33-
34-
bpf_tail_call(skb, &jmp_table, 1);
35-
bpf_tail_call(skb, &jmp_table, 1);
36-
bpf_tail_call(skb, &jmp_table, 1);
37-
bpf_tail_call(skb, &jmp_table, 1);
38-
39-
bpf_tail_call(skb, &jmp_table, 2);
40-
bpf_tail_call(skb, &jmp_table, 2);
41-
bpf_tail_call(skb, &jmp_table, 2);
42-
bpf_tail_call(skb, &jmp_table, 2);
29+
bpf_tail_call_static(skb, &jmp_table, 0);
30+
bpf_tail_call_static(skb, &jmp_table, 0);
31+
bpf_tail_call_static(skb, &jmp_table, 0);
32+
bpf_tail_call_static(skb, &jmp_table, 0);
33+
34+
bpf_tail_call_static(skb, &jmp_table, 1);
35+
bpf_tail_call_static(skb, &jmp_table, 1);
36+
bpf_tail_call_static(skb, &jmp_table, 1);
37+
bpf_tail_call_static(skb, &jmp_table, 1);
38+
39+
bpf_tail_call_static(skb, &jmp_table, 2);
40+
bpf_tail_call_static(skb, &jmp_table, 2);
41+
bpf_tail_call_static(skb, &jmp_table, 2);
42+
bpf_tail_call_static(skb, &jmp_table, 2);
4343

4444
return 3;
4545
}

tools/testing/selftests/bpf/progs/tailcall2.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ struct {
1313
SEC("classifier/0")
1414
int bpf_func_0(struct __sk_buff *skb)
1515
{
16-
bpf_tail_call(skb, &jmp_table, 1);
16+
bpf_tail_call_static(skb, &jmp_table, 1);
1717
return 0;
1818
}
1919

2020
SEC("classifier/1")
2121
int bpf_func_1(struct __sk_buff *skb)
2222
{
23-
bpf_tail_call(skb, &jmp_table, 2);
23+
bpf_tail_call_static(skb, &jmp_table, 2);
2424
return 1;
2525
}
2626

@@ -33,25 +33,25 @@ int bpf_func_2(struct __sk_buff *skb)
3333
SEC("classifier/3")
3434
int bpf_func_3(struct __sk_buff *skb)
3535
{
36-
bpf_tail_call(skb, &jmp_table, 4);
36+
bpf_tail_call_static(skb, &jmp_table, 4);
3737
return 3;
3838
}
3939

4040
SEC("classifier/4")
4141
int bpf_func_4(struct __sk_buff *skb)
4242
{
43-
bpf_tail_call(skb, &jmp_table, 3);
43+
bpf_tail_call_static(skb, &jmp_table, 3);
4444
return 4;
4545
}
4646

4747
SEC("classifier")
4848
int entry(struct __sk_buff *skb)
4949
{
50-
bpf_tail_call(skb, &jmp_table, 0);
50+
bpf_tail_call_static(skb, &jmp_table, 0);
5151
/* Check multi-prog update. */
52-
bpf_tail_call(skb, &jmp_table, 2);
52+
bpf_tail_call_static(skb, &jmp_table, 2);
5353
/* Check tail call limit. */
54-
bpf_tail_call(skb, &jmp_table, 3);
54+
bpf_tail_call_static(skb, &jmp_table, 3);
5555
return 3;
5656
}
5757

tools/testing/selftests/bpf/progs/tailcall3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ SEC("classifier/0")
1616
int bpf_func_0(struct __sk_buff *skb)
1717
{
1818
count++;
19-
bpf_tail_call(skb, &jmp_table, 0);
19+
bpf_tail_call_static(skb, &jmp_table, 0);
2020
return 1;
2121
}
2222

2323
SEC("classifier")
2424
int entry(struct __sk_buff *skb)
2525
{
26-
bpf_tail_call(skb, &jmp_table, 0);
26+
bpf_tail_call_static(skb, &jmp_table, 0);
2727
return 0;
2828
}
2929

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ TAIL_FUNC(1)
2121
static __noinline
2222
int subprog_tail(struct __sk_buff *skb)
2323
{
24-
bpf_tail_call(skb, &jmp_table, 0);
24+
bpf_tail_call_static(skb, &jmp_table, 0);
2525

2626
return skb->len * 2;
2727
}
2828

2929
SEC("classifier")
3030
int entry(struct __sk_buff *skb)
3131
{
32-
bpf_tail_call(skb, &jmp_table, 1);
32+
bpf_tail_call_static(skb, &jmp_table, 1);
3333

3434
return subprog_tail(skb);
3535
}

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ static __noinline
1414
int subprog_tail(struct __sk_buff *skb)
1515
{
1616
if (load_byte(skb, 0))
17-
bpf_tail_call(skb, &jmp_table, 1);
17+
bpf_tail_call_static(skb, &jmp_table, 1);
1818
else
19-
bpf_tail_call(skb, &jmp_table, 0);
19+
bpf_tail_call_static(skb, &jmp_table, 0);
2020
return 1;
2121
}
2222

@@ -32,7 +32,7 @@ int bpf_func_0(struct __sk_buff *skb)
3232
SEC("classifier")
3333
int entry(struct __sk_buff *skb)
3434
{
35-
bpf_tail_call(skb, &jmp_table, 0);
35+
bpf_tail_call_static(skb, &jmp_table, 0);
3636

3737
return 0;
3838
}

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf3.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ int subprog_tail2(struct __sk_buff *skb)
1616
volatile char arr[64] = {};
1717

1818
if (load_word(skb, 0) || load_half(skb, 0))
19-
bpf_tail_call(skb, &jmp_table, 10);
19+
bpf_tail_call_static(skb, &jmp_table, 10);
2020
else
21-
bpf_tail_call(skb, &jmp_table, 1);
21+
bpf_tail_call_static(skb, &jmp_table, 1);
2222

2323
return skb->len;
2424
}
@@ -28,7 +28,7 @@ int subprog_tail(struct __sk_buff *skb)
2828
{
2929
volatile char arr[64] = {};
3030

31-
bpf_tail_call(skb, &jmp_table, 0);
31+
bpf_tail_call_static(skb, &jmp_table, 0);
3232

3333
return skb->len * 2;
3434
}

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ static volatile int count;
1414
__noinline
1515
int subprog_tail_2(struct __sk_buff *skb)
1616
{
17-
bpf_tail_call(skb, &jmp_table, 2);
17+
bpf_tail_call_static(skb, &jmp_table, 2);
1818
return skb->len * 3;
1919
}
2020

2121
__noinline
2222
int subprog_tail_1(struct __sk_buff *skb)
2323
{
24-
bpf_tail_call(skb, &jmp_table, 1);
24+
bpf_tail_call_static(skb, &jmp_table, 1);
2525
return skb->len * 2;
2626
}
2727

2828
__noinline
2929
int subprog_tail(struct __sk_buff *skb)
3030
{
31-
bpf_tail_call(skb, &jmp_table, 0);
31+
bpf_tail_call_static(skb, &jmp_table, 0);
3232
return skb->len;
3333
}
3434

0 commit comments

Comments
 (0)