1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
6 #include <linux/types.h> /* for u32 */
13 /* This flag implies BTF_SET8 holds kfunc(s) */
14 #define BTF_SET8_KFUNCS (1 << 0)
25 #ifdef CONFIG_DEBUG_INFO_BTF
27 #include <linux/compiler.h> /* for __PASTE */
28 #include <linux/compiler_attributes.h> /* for __maybe_unused */
29 #include <linux/stringify.h>
32 * Following macros help to define lists of BTF IDs placed
33 * in .BTF_ids section. They are initially filled with zeros
34 * (during compilation) and resolved later during the
35 * linking phase by resolve_btfids tool.
37 * Any change in list layout must be reflected in resolve_btfids
41 #define BTF_IDS_SECTION ".BTF_ids"
43 #define ____BTF_ID(symbol, word) \
45 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
46 ".local " #symbol " ; \n" \
47 ".type " #symbol ", STT_OBJECT; \n" \
48 ".size " #symbol ", 4; \n" \
54 #define __BTF_ID(symbol, word) \
55 ____BTF_ID(symbol, word)
57 #define __ID(prefix) \
58 __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
61 * The BTF_ID defines unique symbol for each ID pointing
64 #define BTF_ID(prefix, name) \
65 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "")
67 #define ____BTF_ID_FLAGS(prefix, name, flags) \
68 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n")
69 #define __BTF_ID_FLAGS(prefix, name, flags, ...) \
70 ____BTF_ID_FLAGS(prefix, name, flags)
71 #define BTF_ID_FLAGS(prefix, name, ...) \
72 __BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0)
75 * The BTF_ID_LIST macro defines pure (unsorted) list
76 * of BTF IDs, with following layout:
79 * BTF_ID(type1, name1)
80 * BTF_ID(type2, name2)
83 * __BTF_ID__type1__name1__1:
85 * __BTF_ID__type2__name2__2:
89 #define __BTF_ID_LIST(name, scope) \
91 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
92 "." #scope " " #name "; \n" \
96 #define BTF_ID_LIST(name) \
97 __BTF_ID_LIST(name, local) \
100 #define BTF_ID_LIST_GLOBAL(name, n) \
101 __BTF_ID_LIST(name, globl)
103 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
106 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \
108 BTF_ID(prefix, typename)
109 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
110 BTF_ID_LIST_GLOBAL(name, 1) \
111 BTF_ID(prefix, typename)
114 * The BTF_ID_UNUSED macro defines 4 zero bytes.
115 * It's used when we want to define 'unused' entry
116 * in BTF_ID_LIST, like:
118 * BTF_ID_LIST(bpf_skb_output_btf_ids)
119 * BTF_ID(struct, sk_buff)
121 * BTF_ID(struct, task_struct)
124 #define BTF_ID_UNUSED \
126 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
131 * The BTF_SET_START/END macros pair defines sorted list of
132 * BTF IDs plus its members count, with following layout:
134 * BTF_SET_START(list)
135 * BTF_ID(type1, name1)
136 * BTF_ID(type2, name2)
139 * __BTF_ID__set__list:
142 * __BTF_ID__type1__name1__3:
144 * __BTF_ID__type2__name2__4:
148 #define __BTF_SET_START(name, scope) \
150 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
151 "." #scope " __BTF_ID__set__" #name "; \n" \
152 "__BTF_ID__set__" #name ":; \n" \
156 #define BTF_SET_START(name) \
157 __BTF_ID_LIST(name, local) \
158 __BTF_SET_START(name, local)
160 #define BTF_SET_START_GLOBAL(name) \
161 __BTF_ID_LIST(name, globl) \
162 __BTF_SET_START(name, globl)
164 #define BTF_SET_END(name) \
166 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
167 ".size __BTF_ID__set__" #name ", .-" #name " \n" \
168 ".popsection; \n"); \
169 extern struct btf_id_set name;
172 * The BTF_SET8_START/END macros pair defines sorted list of
173 * BTF IDs and their flags plus its members count, with the
176 * BTF_SET8_START(list)
177 * BTF_ID_FLAGS(type1, name1, flags)
178 * BTF_ID_FLAGS(type2, name2, flags)
181 * __BTF_ID__set8__list:
184 * __BTF_ID__type1__name1__3:
186 * .word (1 << 0) | (1 << 2)
187 * __BTF_ID__type2__name2__5:
189 * .word (1 << 3) | (1 << 1) | (1 << 2)
192 #define __BTF_SET8_START(name, scope, flags) \
193 __BTF_ID_LIST(name, local) \
195 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
196 "." #scope " __BTF_ID__set8__" #name "; \n" \
197 "__BTF_ID__set8__" #name ":; \n" \
199 ".long " __stringify(flags) "\n" \
202 #define BTF_SET8_START(name) \
203 __BTF_SET8_START(name, local, 0)
205 #define BTF_SET8_END(name) \
207 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
208 ".size __BTF_ID__set8__" #name ", .-" #name " \n" \
209 ".popsection; \n"); \
210 extern struct btf_id_set8 name;
212 #define BTF_KFUNCS_START(name) \
213 __BTF_SET8_START(name, local, BTF_SET8_KFUNCS)
215 #define BTF_KFUNCS_END(name) \
220 #define BTF_ID_LIST(name) static u32 __maybe_unused name[64];
221 #define BTF_ID(prefix, name)
222 #define BTF_ID_FLAGS(prefix, name, ...)
223 #define BTF_ID_UNUSED
224 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
225 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
226 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
227 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
228 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
229 #define BTF_SET_END(name)
230 #define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 };
231 #define BTF_SET8_END(name)
232 #define BTF_KFUNCS_START(name) static struct btf_id_set8 __maybe_unused name = { .flags = BTF_SET8_KFUNCS };
233 #define BTF_KFUNCS_END(name)
235 #endif /* CONFIG_DEBUG_INFO_BTF */
238 /* Define a list of socket types which can be the argument for
239 * skc_to_*_sock() helpers. All these sockets should have
240 * sock_common as the first argument in its memory layout.
242 #define BTF_SOCK_TYPE_xxx \
243 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
244 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
245 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
246 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
247 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
248 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
249 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
250 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
251 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
252 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
253 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
254 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
255 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
256 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
257 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
258 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
261 #define BTF_SOCK_TYPE(name, str) name,
267 extern u32 btf_sock_ids[];
270 #define BTF_TRACING_TYPE_xxx \
271 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
272 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
273 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
276 #define BTF_TRACING_TYPE(name, type) name,
278 #undef BTF_TRACING_TYPE
279 MAX_BTF_TRACING_TYPE,
282 extern u32 btf_tracing_ids[];
283 extern u32 bpf_cgroup_btf_id[];
284 extern u32 bpf_local_storage_map_btf_id[];
285 extern u32 btf_bpf_map_id[];
286 extern u32 bpf_kmem_cache_btf_id[];