1b1b53d41SAndrey Ignatov // SPDX-License-Identifier: GPL-2.0
2b1b53d41SAndrey Ignatov // Copyright (c) 2020 Facebook
3b1b53d41SAndrey Ignatov 
4b1b53d41SAndrey Ignatov #include <linux/bpf.h>
5b1b53d41SAndrey Ignatov #include <bpf/bpf_helpers.h>
6b1b53d41SAndrey Ignatov 
7b1b53d41SAndrey Ignatov #define LOOP_BOUND 0xf
8b1b53d41SAndrey Ignatov #define MAX_ENTRIES 8
9b1b53d41SAndrey Ignatov #define HALF_ENTRIES (MAX_ENTRIES >> 1)
10b1b53d41SAndrey Ignatov 
11b1b53d41SAndrey Ignatov _Static_assert(MAX_ENTRIES < LOOP_BOUND, "MAX_ENTRIES must be < LOOP_BOUND");
12b1b53d41SAndrey Ignatov 
13b1b53d41SAndrey Ignatov enum bpf_map_type g_map_type = BPF_MAP_TYPE_UNSPEC;
14b1b53d41SAndrey Ignatov __u32 g_line = 0;
157a85e4dfSYauheni Kaliuta int page_size = 0; /* userspace should set it */
16b1b53d41SAndrey Ignatov 
17b1b53d41SAndrey Ignatov #define VERIFY_TYPE(type, func) ({	\
18b1b53d41SAndrey Ignatov 	g_map_type = type;		\
19b1b53d41SAndrey Ignatov 	if (!func())			\
20b1b53d41SAndrey Ignatov 		return 0;		\
21b1b53d41SAndrey Ignatov })
22b1b53d41SAndrey Ignatov 
23b1b53d41SAndrey Ignatov 
24b1b53d41SAndrey Ignatov #define VERIFY(expr) ({		\
25b1b53d41SAndrey Ignatov 	g_line = __LINE__;	\
26b1b53d41SAndrey Ignatov 	if (!(expr))		\
27b1b53d41SAndrey Ignatov 		return 0;	\
28b1b53d41SAndrey Ignatov })
29b1b53d41SAndrey Ignatov 
30b1b53d41SAndrey Ignatov struct bpf_map {
31b1b53d41SAndrey Ignatov 	enum bpf_map_type map_type;
32b1b53d41SAndrey Ignatov 	__u32 key_size;
33b1b53d41SAndrey Ignatov 	__u32 value_size;
34b1b53d41SAndrey Ignatov 	__u32 max_entries;
35b1b53d41SAndrey Ignatov 	__u32 id;
36b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
37b1b53d41SAndrey Ignatov 
check_bpf_map_fields(struct bpf_map * map,__u32 key_size,__u32 value_size,__u32 max_entries)38b1b53d41SAndrey Ignatov static inline int check_bpf_map_fields(struct bpf_map *map, __u32 key_size,
39b1b53d41SAndrey Ignatov 				       __u32 value_size, __u32 max_entries)
40b1b53d41SAndrey Ignatov {
41b1b53d41SAndrey Ignatov 	VERIFY(map->map_type == g_map_type);
42b1b53d41SAndrey Ignatov 	VERIFY(map->key_size == key_size);
43b1b53d41SAndrey Ignatov 	VERIFY(map->value_size == value_size);
44b1b53d41SAndrey Ignatov 	VERIFY(map->max_entries == max_entries);
45b1b53d41SAndrey Ignatov 	VERIFY(map->id > 0);
46b1b53d41SAndrey Ignatov 
47b1b53d41SAndrey Ignatov 	return 1;
48b1b53d41SAndrey Ignatov }
49b1b53d41SAndrey Ignatov 
check_bpf_map_ptr(struct bpf_map * indirect,struct bpf_map * direct)50b1b53d41SAndrey Ignatov static inline int check_bpf_map_ptr(struct bpf_map *indirect,
51b1b53d41SAndrey Ignatov 				    struct bpf_map *direct)
52b1b53d41SAndrey Ignatov {
53b1b53d41SAndrey Ignatov 	VERIFY(indirect->map_type == direct->map_type);
54b1b53d41SAndrey Ignatov 	VERIFY(indirect->key_size == direct->key_size);
55b1b53d41SAndrey Ignatov 	VERIFY(indirect->value_size == direct->value_size);
56b1b53d41SAndrey Ignatov 	VERIFY(indirect->max_entries == direct->max_entries);
57b1b53d41SAndrey Ignatov 	VERIFY(indirect->id == direct->id);
58b1b53d41SAndrey Ignatov 
59b1b53d41SAndrey Ignatov 	return 1;
60b1b53d41SAndrey Ignatov }
61b1b53d41SAndrey Ignatov 
check(struct bpf_map * indirect,struct bpf_map * direct,__u32 key_size,__u32 value_size,__u32 max_entries)62b1b53d41SAndrey Ignatov static inline int check(struct bpf_map *indirect, struct bpf_map *direct,
63b1b53d41SAndrey Ignatov 			__u32 key_size, __u32 value_size, __u32 max_entries)
64b1b53d41SAndrey Ignatov {
65b1b53d41SAndrey Ignatov 	VERIFY(check_bpf_map_ptr(indirect, direct));
66b1b53d41SAndrey Ignatov 	VERIFY(check_bpf_map_fields(indirect, key_size, value_size,
67b1b53d41SAndrey Ignatov 				    max_entries));
68b1b53d41SAndrey Ignatov 	return 1;
69b1b53d41SAndrey Ignatov }
70b1b53d41SAndrey Ignatov 
check_default(struct bpf_map * indirect,struct bpf_map * direct)71b1b53d41SAndrey Ignatov static inline int check_default(struct bpf_map *indirect,
72b1b53d41SAndrey Ignatov 				struct bpf_map *direct)
73b1b53d41SAndrey Ignatov {
74b1b53d41SAndrey Ignatov 	VERIFY(check(indirect, direct, sizeof(__u32), sizeof(__u32),
75b1b53d41SAndrey Ignatov 		     MAX_ENTRIES));
76b1b53d41SAndrey Ignatov 	return 1;
77b1b53d41SAndrey Ignatov }
78b1b53d41SAndrey Ignatov 
79e6054fc1SYonghong Song static __noinline int
check_default_noinline(struct bpf_map * indirect,struct bpf_map * direct)80e6054fc1SYonghong Song check_default_noinline(struct bpf_map *indirect, struct bpf_map *direct)
81e6054fc1SYonghong Song {
82e6054fc1SYonghong Song 	VERIFY(check(indirect, direct, sizeof(__u32), sizeof(__u32),
83e6054fc1SYonghong Song 		     MAX_ENTRIES));
84e6054fc1SYonghong Song 	return 1;
85e6054fc1SYonghong Song }
86e6054fc1SYonghong Song 
87b1b53d41SAndrey Ignatov typedef struct {
88b1b53d41SAndrey Ignatov 	int counter;
89b1b53d41SAndrey Ignatov } atomic_t;
90b1b53d41SAndrey Ignatov 
91b1b53d41SAndrey Ignatov struct bpf_htab {
92b1b53d41SAndrey Ignatov 	struct bpf_map map;
93b1b53d41SAndrey Ignatov 	atomic_t count;
94b1b53d41SAndrey Ignatov 	__u32 n_buckets;
95b1b53d41SAndrey Ignatov 	__u32 elem_size;
96b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
97b1b53d41SAndrey Ignatov 
98b1b53d41SAndrey Ignatov struct {
99b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_HASH);
100b1b53d41SAndrey Ignatov 	__uint(map_flags, BPF_F_NO_PREALLOC); /* to test bpf_htab.count */
101b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
102b1b53d41SAndrey Ignatov 	__type(key, __u32);
103b1b53d41SAndrey Ignatov 	__type(value, __u32);
104b1b53d41SAndrey Ignatov } m_hash SEC(".maps");
105b1b53d41SAndrey Ignatov 
106*72829b1cSAnton Protopopov __s64 bpf_map_sum_elem_count(struct bpf_map *map) __ksym;
107*72829b1cSAnton Protopopov 
check_hash(void)108b1b53d41SAndrey Ignatov static inline int check_hash(void)
109b1b53d41SAndrey Ignatov {
110b1b53d41SAndrey Ignatov 	struct bpf_htab *hash = (struct bpf_htab *)&m_hash;
111b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_hash;
112b1b53d41SAndrey Ignatov 	int i;
113b1b53d41SAndrey Ignatov 
114e6054fc1SYonghong Song 	VERIFY(check_default_noinline(&hash->map, map));
115b1b53d41SAndrey Ignatov 
116b1b53d41SAndrey Ignatov 	VERIFY(hash->n_buckets == MAX_ENTRIES);
117b1b53d41SAndrey Ignatov 	VERIFY(hash->elem_size == 64);
118b1b53d41SAndrey Ignatov 
119b1b53d41SAndrey Ignatov 	VERIFY(hash->count.counter == 0);
120*72829b1cSAnton Protopopov 	VERIFY(bpf_map_sum_elem_count(map) == 0);
121*72829b1cSAnton Protopopov 
122b1b53d41SAndrey Ignatov 	for (i = 0; i < HALF_ENTRIES; ++i) {
123b1b53d41SAndrey Ignatov 		const __u32 key = i;
124b1b53d41SAndrey Ignatov 		const __u32 val = 1;
125b1b53d41SAndrey Ignatov 
126b1b53d41SAndrey Ignatov 		if (bpf_map_update_elem(hash, &key, &val, 0))
127b1b53d41SAndrey Ignatov 			return 0;
128b1b53d41SAndrey Ignatov 	}
129b1b53d41SAndrey Ignatov 	VERIFY(hash->count.counter == HALF_ENTRIES);
130*72829b1cSAnton Protopopov 	VERIFY(bpf_map_sum_elem_count(map) == HALF_ENTRIES);
131b1b53d41SAndrey Ignatov 
132b1b53d41SAndrey Ignatov 	return 1;
133b1b53d41SAndrey Ignatov }
134b1b53d41SAndrey Ignatov 
135b1b53d41SAndrey Ignatov struct bpf_array {
136b1b53d41SAndrey Ignatov 	struct bpf_map map;
137b1b53d41SAndrey Ignatov 	__u32 elem_size;
138b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
139b1b53d41SAndrey Ignatov 
140b1b53d41SAndrey Ignatov struct {
141b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_ARRAY);
142b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
143b1b53d41SAndrey Ignatov 	__type(key, __u32);
144b1b53d41SAndrey Ignatov 	__type(value, __u32);
145b1b53d41SAndrey Ignatov } m_array SEC(".maps");
146b1b53d41SAndrey Ignatov 
check_array(void)147b1b53d41SAndrey Ignatov static inline int check_array(void)
148b1b53d41SAndrey Ignatov {
149b1b53d41SAndrey Ignatov 	struct bpf_array *array = (struct bpf_array *)&m_array;
150b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_array;
151b1b53d41SAndrey Ignatov 	int i, n_lookups = 0, n_keys = 0;
152b1b53d41SAndrey Ignatov 
153b1b53d41SAndrey Ignatov 	VERIFY(check_default(&array->map, map));
154b1b53d41SAndrey Ignatov 
155b1b53d41SAndrey Ignatov 	VERIFY(array->elem_size == 8);
156b1b53d41SAndrey Ignatov 
157b1b53d41SAndrey Ignatov 	for (i = 0; i < array->map.max_entries && i < LOOP_BOUND; ++i) {
158b1b53d41SAndrey Ignatov 		const __u32 key = i;
159b1b53d41SAndrey Ignatov 		__u32 *val = bpf_map_lookup_elem(array, &key);
160b1b53d41SAndrey Ignatov 
161b1b53d41SAndrey Ignatov 		++n_lookups;
162b1b53d41SAndrey Ignatov 		if (val)
163b1b53d41SAndrey Ignatov 			++n_keys;
164b1b53d41SAndrey Ignatov 	}
165b1b53d41SAndrey Ignatov 
166b1b53d41SAndrey Ignatov 	VERIFY(n_lookups == MAX_ENTRIES);
167b1b53d41SAndrey Ignatov 	VERIFY(n_keys == MAX_ENTRIES);
168b1b53d41SAndrey Ignatov 
169b1b53d41SAndrey Ignatov 	return 1;
170b1b53d41SAndrey Ignatov }
171b1b53d41SAndrey Ignatov 
172b1b53d41SAndrey Ignatov struct {
173b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
174b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
175b1b53d41SAndrey Ignatov 	__type(key, __u32);
176b1b53d41SAndrey Ignatov 	__type(value, __u32);
177b1b53d41SAndrey Ignatov } m_prog_array SEC(".maps");
178b1b53d41SAndrey Ignatov 
check_prog_array(void)179b1b53d41SAndrey Ignatov static inline int check_prog_array(void)
180b1b53d41SAndrey Ignatov {
181b1b53d41SAndrey Ignatov 	struct bpf_array *prog_array = (struct bpf_array *)&m_prog_array;
182b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_prog_array;
183b1b53d41SAndrey Ignatov 
184b1b53d41SAndrey Ignatov 	VERIFY(check_default(&prog_array->map, map));
185b1b53d41SAndrey Ignatov 
186b1b53d41SAndrey Ignatov 	return 1;
187b1b53d41SAndrey Ignatov }
188b1b53d41SAndrey Ignatov 
189b1b53d41SAndrey Ignatov struct {
190b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
191b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
192b1b53d41SAndrey Ignatov 	__type(key, __u32);
193b1b53d41SAndrey Ignatov 	__type(value, __u32);
194b1b53d41SAndrey Ignatov } m_perf_event_array SEC(".maps");
195b1b53d41SAndrey Ignatov 
check_perf_event_array(void)196b1b53d41SAndrey Ignatov static inline int check_perf_event_array(void)
197b1b53d41SAndrey Ignatov {
198b1b53d41SAndrey Ignatov 	struct bpf_array *perf_event_array = (struct bpf_array *)&m_perf_event_array;
199b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_perf_event_array;
200b1b53d41SAndrey Ignatov 
201b1b53d41SAndrey Ignatov 	VERIFY(check_default(&perf_event_array->map, map));
202b1b53d41SAndrey Ignatov 
203b1b53d41SAndrey Ignatov 	return 1;
204b1b53d41SAndrey Ignatov }
205b1b53d41SAndrey Ignatov 
206b1b53d41SAndrey Ignatov struct {
207b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
208b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
209b1b53d41SAndrey Ignatov 	__type(key, __u32);
210b1b53d41SAndrey Ignatov 	__type(value, __u32);
211b1b53d41SAndrey Ignatov } m_percpu_hash SEC(".maps");
212b1b53d41SAndrey Ignatov 
check_percpu_hash(void)213b1b53d41SAndrey Ignatov static inline int check_percpu_hash(void)
214b1b53d41SAndrey Ignatov {
215b1b53d41SAndrey Ignatov 	struct bpf_htab *percpu_hash = (struct bpf_htab *)&m_percpu_hash;
216b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_percpu_hash;
217b1b53d41SAndrey Ignatov 
218b1b53d41SAndrey Ignatov 	VERIFY(check_default(&percpu_hash->map, map));
219b1b53d41SAndrey Ignatov 
220b1b53d41SAndrey Ignatov 	return 1;
221b1b53d41SAndrey Ignatov }
222b1b53d41SAndrey Ignatov 
223b1b53d41SAndrey Ignatov struct {
224b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
225b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
226b1b53d41SAndrey Ignatov 	__type(key, __u32);
227b1b53d41SAndrey Ignatov 	__type(value, __u32);
228b1b53d41SAndrey Ignatov } m_percpu_array SEC(".maps");
229b1b53d41SAndrey Ignatov 
check_percpu_array(void)230b1b53d41SAndrey Ignatov static inline int check_percpu_array(void)
231b1b53d41SAndrey Ignatov {
232b1b53d41SAndrey Ignatov 	struct bpf_array *percpu_array = (struct bpf_array *)&m_percpu_array;
233b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_percpu_array;
234b1b53d41SAndrey Ignatov 
235b1b53d41SAndrey Ignatov 	VERIFY(check_default(&percpu_array->map, map));
236b1b53d41SAndrey Ignatov 
237b1b53d41SAndrey Ignatov 	return 1;
238b1b53d41SAndrey Ignatov }
239b1b53d41SAndrey Ignatov 
240b1b53d41SAndrey Ignatov struct bpf_stack_map {
241b1b53d41SAndrey Ignatov 	struct bpf_map map;
242b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
243b1b53d41SAndrey Ignatov 
244b1b53d41SAndrey Ignatov struct {
245b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_STACK_TRACE);
246b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
247b1b53d41SAndrey Ignatov 	__type(key, __u32);
248b1b53d41SAndrey Ignatov 	__type(value, __u64);
249b1b53d41SAndrey Ignatov } m_stack_trace SEC(".maps");
250b1b53d41SAndrey Ignatov 
check_stack_trace(void)251b1b53d41SAndrey Ignatov static inline int check_stack_trace(void)
252b1b53d41SAndrey Ignatov {
253b1b53d41SAndrey Ignatov 	struct bpf_stack_map *stack_trace =
254b1b53d41SAndrey Ignatov 		(struct bpf_stack_map *)&m_stack_trace;
255b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_stack_trace;
256b1b53d41SAndrey Ignatov 
257b1b53d41SAndrey Ignatov 	VERIFY(check(&stack_trace->map, map, sizeof(__u32), sizeof(__u64),
258b1b53d41SAndrey Ignatov 		     MAX_ENTRIES));
259b1b53d41SAndrey Ignatov 
260b1b53d41SAndrey Ignatov 	return 1;
261b1b53d41SAndrey Ignatov }
262b1b53d41SAndrey Ignatov 
263b1b53d41SAndrey Ignatov struct {
264b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_CGROUP_ARRAY);
265b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
266b1b53d41SAndrey Ignatov 	__type(key, __u32);
267b1b53d41SAndrey Ignatov 	__type(value, __u32);
268b1b53d41SAndrey Ignatov } m_cgroup_array SEC(".maps");
269b1b53d41SAndrey Ignatov 
check_cgroup_array(void)270b1b53d41SAndrey Ignatov static inline int check_cgroup_array(void)
271b1b53d41SAndrey Ignatov {
272b1b53d41SAndrey Ignatov 	struct bpf_array *cgroup_array = (struct bpf_array *)&m_cgroup_array;
273b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_cgroup_array;
274b1b53d41SAndrey Ignatov 
275b1b53d41SAndrey Ignatov 	VERIFY(check_default(&cgroup_array->map, map));
276b1b53d41SAndrey Ignatov 
277b1b53d41SAndrey Ignatov 	return 1;
278b1b53d41SAndrey Ignatov }
279b1b53d41SAndrey Ignatov 
280b1b53d41SAndrey Ignatov struct {
281b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_LRU_HASH);
282b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
283b1b53d41SAndrey Ignatov 	__type(key, __u32);
284b1b53d41SAndrey Ignatov 	__type(value, __u32);
285b1b53d41SAndrey Ignatov } m_lru_hash SEC(".maps");
286b1b53d41SAndrey Ignatov 
check_lru_hash(void)287b1b53d41SAndrey Ignatov static inline int check_lru_hash(void)
288b1b53d41SAndrey Ignatov {
289b1b53d41SAndrey Ignatov 	struct bpf_htab *lru_hash = (struct bpf_htab *)&m_lru_hash;
290b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_lru_hash;
291b1b53d41SAndrey Ignatov 
292b1b53d41SAndrey Ignatov 	VERIFY(check_default(&lru_hash->map, map));
293b1b53d41SAndrey Ignatov 
294b1b53d41SAndrey Ignatov 	return 1;
295b1b53d41SAndrey Ignatov }
296b1b53d41SAndrey Ignatov 
297b1b53d41SAndrey Ignatov struct {
298b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_LRU_PERCPU_HASH);
299b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
300b1b53d41SAndrey Ignatov 	__type(key, __u32);
301b1b53d41SAndrey Ignatov 	__type(value, __u32);
302b1b53d41SAndrey Ignatov } m_lru_percpu_hash SEC(".maps");
303b1b53d41SAndrey Ignatov 
check_lru_percpu_hash(void)304b1b53d41SAndrey Ignatov static inline int check_lru_percpu_hash(void)
305b1b53d41SAndrey Ignatov {
306b1b53d41SAndrey Ignatov 	struct bpf_htab *lru_percpu_hash = (struct bpf_htab *)&m_lru_percpu_hash;
307b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_lru_percpu_hash;
308b1b53d41SAndrey Ignatov 
309b1b53d41SAndrey Ignatov 	VERIFY(check_default(&lru_percpu_hash->map, map));
310b1b53d41SAndrey Ignatov 
311b1b53d41SAndrey Ignatov 	return 1;
312b1b53d41SAndrey Ignatov }
313b1b53d41SAndrey Ignatov 
314b1b53d41SAndrey Ignatov struct lpm_trie {
315b1b53d41SAndrey Ignatov 	struct bpf_map map;
316b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
317b1b53d41SAndrey Ignatov 
318b1b53d41SAndrey Ignatov struct lpm_key {
319b1b53d41SAndrey Ignatov 	struct bpf_lpm_trie_key trie_key;
320b1b53d41SAndrey Ignatov 	__u32 data;
321b1b53d41SAndrey Ignatov };
322b1b53d41SAndrey Ignatov 
323b1b53d41SAndrey Ignatov struct {
324b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_LPM_TRIE);
325b1b53d41SAndrey Ignatov 	__uint(map_flags, BPF_F_NO_PREALLOC);
326b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
327b1b53d41SAndrey Ignatov 	__type(key, struct lpm_key);
328b1b53d41SAndrey Ignatov 	__type(value, __u32);
329b1b53d41SAndrey Ignatov } m_lpm_trie SEC(".maps");
330b1b53d41SAndrey Ignatov 
check_lpm_trie(void)331b1b53d41SAndrey Ignatov static inline int check_lpm_trie(void)
332b1b53d41SAndrey Ignatov {
333b1b53d41SAndrey Ignatov 	struct lpm_trie *lpm_trie = (struct lpm_trie *)&m_lpm_trie;
334b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_lpm_trie;
335b1b53d41SAndrey Ignatov 
336b1b53d41SAndrey Ignatov 	VERIFY(check(&lpm_trie->map, map, sizeof(struct lpm_key), sizeof(__u32),
337b1b53d41SAndrey Ignatov 		     MAX_ENTRIES));
338b1b53d41SAndrey Ignatov 
339b1b53d41SAndrey Ignatov 	return 1;
340b1b53d41SAndrey Ignatov }
341b1b53d41SAndrey Ignatov 
342d82fa9b7SAlexei Starovoitov #define INNER_MAX_ENTRIES 1234
343d82fa9b7SAlexei Starovoitov 
344b1b53d41SAndrey Ignatov struct inner_map {
345b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_ARRAY);
346d82fa9b7SAlexei Starovoitov 	__uint(max_entries, INNER_MAX_ENTRIES);
347b1b53d41SAndrey Ignatov 	__type(key, __u32);
348b1b53d41SAndrey Ignatov 	__type(value, __u32);
349b1b53d41SAndrey Ignatov } inner_map SEC(".maps");
350b1b53d41SAndrey Ignatov 
351b1b53d41SAndrey Ignatov struct {
352b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
353b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
354b1b53d41SAndrey Ignatov 	__type(key, __u32);
355b1b53d41SAndrey Ignatov 	__type(value, __u32);
356b1b53d41SAndrey Ignatov 	__array(values, struct {
357b1b53d41SAndrey Ignatov 		__uint(type, BPF_MAP_TYPE_ARRAY);
358d82fa9b7SAlexei Starovoitov 		__uint(max_entries, INNER_MAX_ENTRIES);
359b1b53d41SAndrey Ignatov 		__type(key, __u32);
360b1b53d41SAndrey Ignatov 		__type(value, __u32);
361b1b53d41SAndrey Ignatov 	});
362b1b53d41SAndrey Ignatov } m_array_of_maps SEC(".maps") = {
363b1b53d41SAndrey Ignatov 	.values = { (void *)&inner_map, 0, 0, 0, 0, 0, 0, 0, 0 },
364b1b53d41SAndrey Ignatov };
365b1b53d41SAndrey Ignatov 
check_array_of_maps(void)366b1b53d41SAndrey Ignatov static inline int check_array_of_maps(void)
367b1b53d41SAndrey Ignatov {
368b1b53d41SAndrey Ignatov 	struct bpf_array *array_of_maps = (struct bpf_array *)&m_array_of_maps;
369b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_array_of_maps;
370d82fa9b7SAlexei Starovoitov 	struct bpf_array *inner_map;
371d82fa9b7SAlexei Starovoitov 	int key = 0;
372b1b53d41SAndrey Ignatov 
373b1b53d41SAndrey Ignatov 	VERIFY(check_default(&array_of_maps->map, map));
374d82fa9b7SAlexei Starovoitov 	inner_map = bpf_map_lookup_elem(array_of_maps, &key);
3752609f635SHaowen Bai 	VERIFY(inner_map != NULL);
376d82fa9b7SAlexei Starovoitov 	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
377b1b53d41SAndrey Ignatov 
378b1b53d41SAndrey Ignatov 	return 1;
379b1b53d41SAndrey Ignatov }
380b1b53d41SAndrey Ignatov 
381b1b53d41SAndrey Ignatov struct {
382b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
383b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
384b1b53d41SAndrey Ignatov 	__type(key, __u32);
385b1b53d41SAndrey Ignatov 	__type(value, __u32);
386b1b53d41SAndrey Ignatov 	__array(values, struct inner_map);
387b1b53d41SAndrey Ignatov } m_hash_of_maps SEC(".maps") = {
388b1b53d41SAndrey Ignatov 	.values = {
389b1b53d41SAndrey Ignatov 		[2] = &inner_map,
390b1b53d41SAndrey Ignatov 	},
391b1b53d41SAndrey Ignatov };
392b1b53d41SAndrey Ignatov 
check_hash_of_maps(void)393b1b53d41SAndrey Ignatov static inline int check_hash_of_maps(void)
394b1b53d41SAndrey Ignatov {
395b1b53d41SAndrey Ignatov 	struct bpf_htab *hash_of_maps = (struct bpf_htab *)&m_hash_of_maps;
396b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_hash_of_maps;
397d82fa9b7SAlexei Starovoitov 	struct bpf_htab *inner_map;
398d82fa9b7SAlexei Starovoitov 	int key = 2;
399b1b53d41SAndrey Ignatov 
400b1b53d41SAndrey Ignatov 	VERIFY(check_default(&hash_of_maps->map, map));
401d82fa9b7SAlexei Starovoitov 	inner_map = bpf_map_lookup_elem(hash_of_maps, &key);
4022609f635SHaowen Bai 	VERIFY(inner_map != NULL);
403d82fa9b7SAlexei Starovoitov 	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
404b1b53d41SAndrey Ignatov 
405b1b53d41SAndrey Ignatov 	return 1;
406b1b53d41SAndrey Ignatov }
407b1b53d41SAndrey Ignatov 
408b1b53d41SAndrey Ignatov struct bpf_dtab {
409b1b53d41SAndrey Ignatov 	struct bpf_map map;
410b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
411b1b53d41SAndrey Ignatov 
412b1b53d41SAndrey Ignatov struct {
413b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_DEVMAP);
414b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
415b1b53d41SAndrey Ignatov 	__type(key, __u32);
416b1b53d41SAndrey Ignatov 	__type(value, __u32);
417b1b53d41SAndrey Ignatov } m_devmap SEC(".maps");
418b1b53d41SAndrey Ignatov 
check_devmap(void)419b1b53d41SAndrey Ignatov static inline int check_devmap(void)
420b1b53d41SAndrey Ignatov {
421b1b53d41SAndrey Ignatov 	struct bpf_dtab *devmap = (struct bpf_dtab *)&m_devmap;
422b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_devmap;
423b1b53d41SAndrey Ignatov 
424b1b53d41SAndrey Ignatov 	VERIFY(check_default(&devmap->map, map));
425b1b53d41SAndrey Ignatov 
426b1b53d41SAndrey Ignatov 	return 1;
427b1b53d41SAndrey Ignatov }
428b1b53d41SAndrey Ignatov 
429b1b53d41SAndrey Ignatov struct bpf_stab {
430b1b53d41SAndrey Ignatov 	struct bpf_map map;
431b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
432b1b53d41SAndrey Ignatov 
433b1b53d41SAndrey Ignatov struct {
434b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_SOCKMAP);
435b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
436b1b53d41SAndrey Ignatov 	__type(key, __u32);
437b1b53d41SAndrey Ignatov 	__type(value, __u32);
438b1b53d41SAndrey Ignatov } m_sockmap SEC(".maps");
439b1b53d41SAndrey Ignatov 
check_sockmap(void)440b1b53d41SAndrey Ignatov static inline int check_sockmap(void)
441b1b53d41SAndrey Ignatov {
442b1b53d41SAndrey Ignatov 	struct bpf_stab *sockmap = (struct bpf_stab *)&m_sockmap;
443b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_sockmap;
444b1b53d41SAndrey Ignatov 
445b1b53d41SAndrey Ignatov 	VERIFY(check_default(&sockmap->map, map));
446b1b53d41SAndrey Ignatov 
447b1b53d41SAndrey Ignatov 	return 1;
448b1b53d41SAndrey Ignatov }
449b1b53d41SAndrey Ignatov 
450b1b53d41SAndrey Ignatov struct bpf_cpu_map {
451b1b53d41SAndrey Ignatov 	struct bpf_map map;
452b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
453b1b53d41SAndrey Ignatov 
454b1b53d41SAndrey Ignatov struct {
455b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_CPUMAP);
456b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
457b1b53d41SAndrey Ignatov 	__type(key, __u32);
458b1b53d41SAndrey Ignatov 	__type(value, __u32);
459b1b53d41SAndrey Ignatov } m_cpumap SEC(".maps");
460b1b53d41SAndrey Ignatov 
check_cpumap(void)461b1b53d41SAndrey Ignatov static inline int check_cpumap(void)
462b1b53d41SAndrey Ignatov {
463b1b53d41SAndrey Ignatov 	struct bpf_cpu_map *cpumap = (struct bpf_cpu_map *)&m_cpumap;
464b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_cpumap;
465b1b53d41SAndrey Ignatov 
466b1b53d41SAndrey Ignatov 	VERIFY(check_default(&cpumap->map, map));
467b1b53d41SAndrey Ignatov 
468b1b53d41SAndrey Ignatov 	return 1;
469b1b53d41SAndrey Ignatov }
470b1b53d41SAndrey Ignatov 
471b1b53d41SAndrey Ignatov struct xsk_map {
472b1b53d41SAndrey Ignatov 	struct bpf_map map;
473b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
474b1b53d41SAndrey Ignatov 
475b1b53d41SAndrey Ignatov struct {
476b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_XSKMAP);
477b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
478b1b53d41SAndrey Ignatov 	__type(key, __u32);
479b1b53d41SAndrey Ignatov 	__type(value, __u32);
480b1b53d41SAndrey Ignatov } m_xskmap SEC(".maps");
481b1b53d41SAndrey Ignatov 
check_xskmap(void)482b1b53d41SAndrey Ignatov static inline int check_xskmap(void)
483b1b53d41SAndrey Ignatov {
484b1b53d41SAndrey Ignatov 	struct xsk_map *xskmap = (struct xsk_map *)&m_xskmap;
485b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_xskmap;
486b1b53d41SAndrey Ignatov 
487b1b53d41SAndrey Ignatov 	VERIFY(check_default(&xskmap->map, map));
488b1b53d41SAndrey Ignatov 
489b1b53d41SAndrey Ignatov 	return 1;
490b1b53d41SAndrey Ignatov }
491b1b53d41SAndrey Ignatov 
492b1b53d41SAndrey Ignatov struct bpf_shtab {
493b1b53d41SAndrey Ignatov 	struct bpf_map map;
494b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
495b1b53d41SAndrey Ignatov 
496b1b53d41SAndrey Ignatov struct {
497b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_SOCKHASH);
498b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
499b1b53d41SAndrey Ignatov 	__type(key, __u32);
500b1b53d41SAndrey Ignatov 	__type(value, __u32);
501b1b53d41SAndrey Ignatov } m_sockhash SEC(".maps");
502b1b53d41SAndrey Ignatov 
check_sockhash(void)503b1b53d41SAndrey Ignatov static inline int check_sockhash(void)
504b1b53d41SAndrey Ignatov {
505b1b53d41SAndrey Ignatov 	struct bpf_shtab *sockhash = (struct bpf_shtab *)&m_sockhash;
506b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_sockhash;
507b1b53d41SAndrey Ignatov 
508b1b53d41SAndrey Ignatov 	VERIFY(check_default(&sockhash->map, map));
509b1b53d41SAndrey Ignatov 
510b1b53d41SAndrey Ignatov 	return 1;
511b1b53d41SAndrey Ignatov }
512b1b53d41SAndrey Ignatov 
513b1b53d41SAndrey Ignatov struct bpf_cgroup_storage_map {
514b1b53d41SAndrey Ignatov 	struct bpf_map map;
515b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
516b1b53d41SAndrey Ignatov 
517b1b53d41SAndrey Ignatov struct {
518b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
519b1b53d41SAndrey Ignatov 	__type(key, struct bpf_cgroup_storage_key);
520b1b53d41SAndrey Ignatov 	__type(value, __u32);
521b1b53d41SAndrey Ignatov } m_cgroup_storage SEC(".maps");
522b1b53d41SAndrey Ignatov 
check_cgroup_storage(void)523b1b53d41SAndrey Ignatov static inline int check_cgroup_storage(void)
524b1b53d41SAndrey Ignatov {
525b1b53d41SAndrey Ignatov 	struct bpf_cgroup_storage_map *cgroup_storage =
526b1b53d41SAndrey Ignatov 		(struct bpf_cgroup_storage_map *)&m_cgroup_storage;
527b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_cgroup_storage;
528b1b53d41SAndrey Ignatov 
529b1b53d41SAndrey Ignatov 	VERIFY(check(&cgroup_storage->map, map,
530b1b53d41SAndrey Ignatov 		     sizeof(struct bpf_cgroup_storage_key), sizeof(__u32), 0));
531b1b53d41SAndrey Ignatov 
532b1b53d41SAndrey Ignatov 	return 1;
533b1b53d41SAndrey Ignatov }
534b1b53d41SAndrey Ignatov 
535b1b53d41SAndrey Ignatov struct reuseport_array {
536b1b53d41SAndrey Ignatov 	struct bpf_map map;
537b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
538b1b53d41SAndrey Ignatov 
539b1b53d41SAndrey Ignatov struct {
540b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY);
541b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
542b1b53d41SAndrey Ignatov 	__type(key, __u32);
543b1b53d41SAndrey Ignatov 	__type(value, __u32);
544b1b53d41SAndrey Ignatov } m_reuseport_sockarray SEC(".maps");
545b1b53d41SAndrey Ignatov 
check_reuseport_sockarray(void)546b1b53d41SAndrey Ignatov static inline int check_reuseport_sockarray(void)
547b1b53d41SAndrey Ignatov {
548b1b53d41SAndrey Ignatov 	struct reuseport_array *reuseport_sockarray =
549b1b53d41SAndrey Ignatov 		(struct reuseport_array *)&m_reuseport_sockarray;
550b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_reuseport_sockarray;
551b1b53d41SAndrey Ignatov 
552b1b53d41SAndrey Ignatov 	VERIFY(check_default(&reuseport_sockarray->map, map));
553b1b53d41SAndrey Ignatov 
554b1b53d41SAndrey Ignatov 	return 1;
555b1b53d41SAndrey Ignatov }
556b1b53d41SAndrey Ignatov 
557b1b53d41SAndrey Ignatov struct {
558b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE);
559b1b53d41SAndrey Ignatov 	__type(key, struct bpf_cgroup_storage_key);
560b1b53d41SAndrey Ignatov 	__type(value, __u32);
561b1b53d41SAndrey Ignatov } m_percpu_cgroup_storage SEC(".maps");
562b1b53d41SAndrey Ignatov 
check_percpu_cgroup_storage(void)563b1b53d41SAndrey Ignatov static inline int check_percpu_cgroup_storage(void)
564b1b53d41SAndrey Ignatov {
565b1b53d41SAndrey Ignatov 	struct bpf_cgroup_storage_map *percpu_cgroup_storage =
566b1b53d41SAndrey Ignatov 		(struct bpf_cgroup_storage_map *)&m_percpu_cgroup_storage;
567b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_percpu_cgroup_storage;
568b1b53d41SAndrey Ignatov 
569b1b53d41SAndrey Ignatov 	VERIFY(check(&percpu_cgroup_storage->map, map,
570b1b53d41SAndrey Ignatov 		     sizeof(struct bpf_cgroup_storage_key), sizeof(__u32), 0));
571b1b53d41SAndrey Ignatov 
572b1b53d41SAndrey Ignatov 	return 1;
573b1b53d41SAndrey Ignatov }
574b1b53d41SAndrey Ignatov 
575b1b53d41SAndrey Ignatov struct bpf_queue_stack {
576b1b53d41SAndrey Ignatov 	struct bpf_map map;
577b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
578b1b53d41SAndrey Ignatov 
579b1b53d41SAndrey Ignatov struct {
580b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_QUEUE);
581b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
582b1b53d41SAndrey Ignatov 	__type(value, __u32);
583b1b53d41SAndrey Ignatov } m_queue SEC(".maps");
584b1b53d41SAndrey Ignatov 
check_queue(void)585b1b53d41SAndrey Ignatov static inline int check_queue(void)
586b1b53d41SAndrey Ignatov {
587b1b53d41SAndrey Ignatov 	struct bpf_queue_stack *queue = (struct bpf_queue_stack *)&m_queue;
588b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_queue;
589b1b53d41SAndrey Ignatov 
590b1b53d41SAndrey Ignatov 	VERIFY(check(&queue->map, map, 0, sizeof(__u32), MAX_ENTRIES));
591b1b53d41SAndrey Ignatov 
592b1b53d41SAndrey Ignatov 	return 1;
593b1b53d41SAndrey Ignatov }
594b1b53d41SAndrey Ignatov 
595b1b53d41SAndrey Ignatov struct {
596b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_STACK);
597b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
598b1b53d41SAndrey Ignatov 	__type(value, __u32);
599b1b53d41SAndrey Ignatov } m_stack SEC(".maps");
600b1b53d41SAndrey Ignatov 
check_stack(void)601b1b53d41SAndrey Ignatov static inline int check_stack(void)
602b1b53d41SAndrey Ignatov {
603b1b53d41SAndrey Ignatov 	struct bpf_queue_stack *stack = (struct bpf_queue_stack *)&m_stack;
604b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_stack;
605b1b53d41SAndrey Ignatov 
606b1b53d41SAndrey Ignatov 	VERIFY(check(&stack->map, map, 0, sizeof(__u32), MAX_ENTRIES));
607b1b53d41SAndrey Ignatov 
608b1b53d41SAndrey Ignatov 	return 1;
609b1b53d41SAndrey Ignatov }
610b1b53d41SAndrey Ignatov 
6111f00d375SKP Singh struct bpf_local_storage_map {
612b1b53d41SAndrey Ignatov 	struct bpf_map map;
613b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
614b1b53d41SAndrey Ignatov 
615b1b53d41SAndrey Ignatov struct {
616b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_SK_STORAGE);
617b1b53d41SAndrey Ignatov 	__uint(map_flags, BPF_F_NO_PREALLOC);
618b1b53d41SAndrey Ignatov 	__type(key, __u32);
619b1b53d41SAndrey Ignatov 	__type(value, __u32);
620b1b53d41SAndrey Ignatov } m_sk_storage SEC(".maps");
621b1b53d41SAndrey Ignatov 
check_sk_storage(void)622b1b53d41SAndrey Ignatov static inline int check_sk_storage(void)
623b1b53d41SAndrey Ignatov {
6241f00d375SKP Singh 	struct bpf_local_storage_map *sk_storage =
6251f00d375SKP Singh 		(struct bpf_local_storage_map *)&m_sk_storage;
626b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_sk_storage;
627b1b53d41SAndrey Ignatov 
628b1b53d41SAndrey Ignatov 	VERIFY(check(&sk_storage->map, map, sizeof(__u32), sizeof(__u32), 0));
629b1b53d41SAndrey Ignatov 
630b1b53d41SAndrey Ignatov 	return 1;
631b1b53d41SAndrey Ignatov }
632b1b53d41SAndrey Ignatov 
633b1b53d41SAndrey Ignatov struct {
634b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_DEVMAP_HASH);
635b1b53d41SAndrey Ignatov 	__uint(max_entries, MAX_ENTRIES);
636b1b53d41SAndrey Ignatov 	__type(key, __u32);
637b1b53d41SAndrey Ignatov 	__type(value, __u32);
638b1b53d41SAndrey Ignatov } m_devmap_hash SEC(".maps");
639b1b53d41SAndrey Ignatov 
check_devmap_hash(void)640b1b53d41SAndrey Ignatov static inline int check_devmap_hash(void)
641b1b53d41SAndrey Ignatov {
642b1b53d41SAndrey Ignatov 	struct bpf_dtab *devmap_hash = (struct bpf_dtab *)&m_devmap_hash;
643b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_devmap_hash;
644b1b53d41SAndrey Ignatov 
645b1b53d41SAndrey Ignatov 	VERIFY(check_default(&devmap_hash->map, map));
646b1b53d41SAndrey Ignatov 
647b1b53d41SAndrey Ignatov 	return 1;
648b1b53d41SAndrey Ignatov }
649b1b53d41SAndrey Ignatov 
650b1b53d41SAndrey Ignatov struct bpf_ringbuf_map {
651b1b53d41SAndrey Ignatov 	struct bpf_map map;
652b1b53d41SAndrey Ignatov } __attribute__((preserve_access_index));
653b1b53d41SAndrey Ignatov 
654b1b53d41SAndrey Ignatov struct {
655b1b53d41SAndrey Ignatov 	__uint(type, BPF_MAP_TYPE_RINGBUF);
656b1b53d41SAndrey Ignatov } m_ringbuf SEC(".maps");
657b1b53d41SAndrey Ignatov 
check_ringbuf(void)658b1b53d41SAndrey Ignatov static inline int check_ringbuf(void)
659b1b53d41SAndrey Ignatov {
660b1b53d41SAndrey Ignatov 	struct bpf_ringbuf_map *ringbuf = (struct bpf_ringbuf_map *)&m_ringbuf;
661b1b53d41SAndrey Ignatov 	struct bpf_map *map = (struct bpf_map *)&m_ringbuf;
662b1b53d41SAndrey Ignatov 
6637a85e4dfSYauheni Kaliuta 	VERIFY(check(&ringbuf->map, map, 0, 0, page_size));
664b1b53d41SAndrey Ignatov 
665b1b53d41SAndrey Ignatov 	return 1;
666b1b53d41SAndrey Ignatov }
667b1b53d41SAndrey Ignatov 
668b1b53d41SAndrey Ignatov SEC("cgroup_skb/egress")
cg_skb(void * ctx)669b1b53d41SAndrey Ignatov int cg_skb(void *ctx)
670b1b53d41SAndrey Ignatov {
671b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_HASH, check_hash);
672b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_ARRAY, check_array);
673b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_PROG_ARRAY, check_prog_array);
674b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_PERF_EVENT_ARRAY, check_perf_event_array);
675b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_PERCPU_HASH, check_percpu_hash);
676b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_PERCPU_ARRAY, check_percpu_array);
677b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_STACK_TRACE, check_stack_trace);
678b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_CGROUP_ARRAY, check_cgroup_array);
679b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_LRU_HASH, check_lru_hash);
680b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_LRU_PERCPU_HASH, check_lru_percpu_hash);
681b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_LPM_TRIE, check_lpm_trie);
682b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_ARRAY_OF_MAPS, check_array_of_maps);
683b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_HASH_OF_MAPS, check_hash_of_maps);
684b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_DEVMAP, check_devmap);
685b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_SOCKMAP, check_sockmap);
686b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_CPUMAP, check_cpumap);
687b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_XSKMAP, check_xskmap);
688b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_SOCKHASH, check_sockhash);
689b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_CGROUP_STORAGE, check_cgroup_storage);
690b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
691b1b53d41SAndrey Ignatov 		    check_reuseport_sockarray);
692b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
693b1b53d41SAndrey Ignatov 		    check_percpu_cgroup_storage);
694b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_QUEUE, check_queue);
695b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_STACK, check_stack);
696b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_SK_STORAGE, check_sk_storage);
697b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_DEVMAP_HASH, check_devmap_hash);
698b1b53d41SAndrey Ignatov 	VERIFY_TYPE(BPF_MAP_TYPE_RINGBUF, check_ringbuf);
699b1b53d41SAndrey Ignatov 
700b1b53d41SAndrey Ignatov 	return 1;
701b1b53d41SAndrey Ignatov }
702b1b53d41SAndrey Ignatov 
703b1b53d41SAndrey Ignatov char _license[] SEC("license") = "GPL";
704