xref: /linux/tools/testing/selftests/bpf/progs/verifier_tailcall.c (revision 260f6f4fda93c8485c8037865c941b42b9cba5d2)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include "bpf_misc.h"
6 
7 struct {
8 	__uint(type, BPF_MAP_TYPE_ARRAY);
9 	__uint(max_entries, 1);
10 	__type(key, __u32);
11 	__type(value, __u32);
12 } map_array SEC(".maps");
13 
14 SEC("socket")
15 __description("invalid map type for tail call")
16 __failure __msg("expected prog array map for tail call")
17 __failure_unpriv
18 __naked void invalid_map_for_tail_call(void)
19 {
20 	asm volatile ("			\
21 	r2 = %[map_array] ll;	\
22 	r3 = 0;				\
23 	call %[bpf_tail_call];		\
24 	exit;				\
25 "	:
26 	: __imm(bpf_tail_call),
27 	  __imm_addr(map_array)
28 	: __clobber_all);
29 }
30 
31 char _license[] SEC("license") = "GPL";
32