1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
11 /* This flag implies BTF_SET8 holds kfunc(s) */
12 #define BTF_SET8_KFUNCS (1 << 0)
23 #ifdef CONFIG_DEBUG_INFO_BTF
25 #include <linux/compiler.h> /* for __PASTE */
26 #include <linux/compiler_attributes.h> /* for __maybe_unused */
27 #include <linux/stringify.h>
30 * Following macros help to define lists of BTF IDs placed
31 * in .BTF_ids section. They are initially filled with zeros
32 * (during compilation) and resolved later during the
33 * linking phase by resolve_btfids tool.
35 * Any change in list layout must be reflected in resolve_btfids
39 #define BTF_IDS_SECTION ".BTF_ids"
41 #define ____BTF_ID(symbol, word) \
43 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
44 ".local " #symbol " ; \n" \
45 ".type " #symbol ", STT_OBJECT; \n" \
46 ".size " #symbol ", 4; \n" \
52 #define __BTF_ID(symbol, word) \
53 ____BTF_ID(symbol, word)
55 #define __ID(prefix) \
56 __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
59 * The BTF_ID defines unique symbol for each ID pointing
62 #define BTF_ID(prefix, name) \
63 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "")
65 #define ____BTF_ID_FLAGS(prefix, name, flags) \
66 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n")
67 #define __BTF_ID_FLAGS(prefix, name, flags, ...) \
68 ____BTF_ID_FLAGS(prefix, name, flags)
69 #define BTF_ID_FLAGS(prefix, name, ...) \
70 __BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0)
73 * The BTF_ID_LIST macro defines pure (unsorted) list
74 * of BTF IDs, with following layout:
77 * BTF_ID(type1, name1)
78 * BTF_ID(type2, name2)
81 * __BTF_ID__type1__name1__1:
83 * __BTF_ID__type2__name2__2:
87 #define __BTF_ID_LIST(name, scope) \
89 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
90 "." #scope " " #name "; \n" \
94 #define BTF_ID_LIST(name) \
95 __BTF_ID_LIST(name, local) \
98 #define BTF_ID_LIST_GLOBAL(name, n) \
99 __BTF_ID_LIST(name, globl)
101 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
104 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \
106 BTF_ID(prefix, typename)
107 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
108 BTF_ID_LIST_GLOBAL(name, 1) \
109 BTF_ID(prefix, typename)
112 * The BTF_ID_UNUSED macro defines 4 zero bytes.
113 * It's used when we want to define 'unused' entry
114 * in BTF_ID_LIST, like:
116 * BTF_ID_LIST(bpf_skb_output_btf_ids)
117 * BTF_ID(struct, sk_buff)
119 * BTF_ID(struct, task_struct)
122 #define BTF_ID_UNUSED \
124 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
129 * The BTF_SET_START/END macros pair defines sorted list of
130 * BTF IDs plus its members count, with following layout:
132 * BTF_SET_START(list)
133 * BTF_ID(type1, name1)
134 * BTF_ID(type2, name2)
137 * __BTF_ID__set__list:
140 * __BTF_ID__type1__name1__3:
142 * __BTF_ID__type2__name2__4:
146 #define __BTF_SET_START(name, scope) \
148 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
149 "." #scope " __BTF_ID__set__" #name "; \n" \
150 "__BTF_ID__set__" #name ":; \n" \
154 #define BTF_SET_START(name) \
155 __BTF_ID_LIST(name, local) \
156 __BTF_SET_START(name, local)
158 #define BTF_SET_START_GLOBAL(name) \
159 __BTF_ID_LIST(name, globl) \
160 __BTF_SET_START(name, globl)
162 #define BTF_SET_END(name) \
164 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
165 ".size __BTF_ID__set__" #name ", .-" #name " \n" \
166 ".popsection; \n"); \
167 extern struct btf_id_set name;
170 * The BTF_SET8_START/END macros pair defines sorted list of
171 * BTF IDs and their flags plus its members count, with the
174 * BTF_SET8_START(list)
175 * BTF_ID_FLAGS(type1, name1, flags)
176 * BTF_ID_FLAGS(type2, name2, flags)
179 * __BTF_ID__set8__list:
182 * __BTF_ID__type1__name1__3:
184 * .word (1 << 0) | (1 << 2)
185 * __BTF_ID__type2__name2__5:
187 * .word (1 << 3) | (1 << 1) | (1 << 2)
190 #define __BTF_SET8_START(name, scope, flags) \
191 __BTF_ID_LIST(name, local) \
193 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
194 "." #scope " __BTF_ID__set8__" #name "; \n" \
195 "__BTF_ID__set8__" #name ":; \n" \
197 ".long " __stringify(flags) "\n" \
200 #define BTF_SET8_START(name) \
201 __BTF_SET8_START(name, local, 0)
203 #define BTF_SET8_END(name) \
205 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
206 ".size __BTF_ID__set8__" #name ", .-" #name " \n" \
207 ".popsection; \n"); \
208 extern struct btf_id_set8 name;
210 #define BTF_KFUNCS_START(name) \
211 __BTF_SET8_START(name, local, BTF_SET8_KFUNCS)
213 #define BTF_KFUNCS_END(name) \
218 #define BTF_ID_LIST(name) static u32 __maybe_unused name[64];
219 #define BTF_ID(prefix, name)
220 #define BTF_ID_FLAGS(prefix, name, ...)
221 #define BTF_ID_UNUSED
222 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
223 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
224 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
225 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
226 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
227 #define BTF_SET_END(name)
228 #define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 };
229 #define BTF_SET8_END(name)
230 #define BTF_KFUNCS_START(name) static struct btf_id_set8 __maybe_unused name = { .flags = BTF_SET8_KFUNCS };
231 #define BTF_KFUNCS_END(name)
233 #endif /* CONFIG_DEBUG_INFO_BTF */
236 /* Define a list of socket types which can be the argument for
237 * skc_to_*_sock() helpers. All these sockets should have
238 * sock_common as the first argument in its memory layout.
240 #define BTF_SOCK_TYPE_xxx \
241 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
242 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
243 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
244 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
245 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
246 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
247 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
248 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
249 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
250 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
251 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
252 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
253 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
254 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
255 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
256 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
259 #define BTF_SOCK_TYPE(name, str) name,
265 extern u32 btf_sock_ids[];
268 #define BTF_TRACING_TYPE_xxx \
269 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
270 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
271 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
274 #define BTF_TRACING_TYPE(name, type) name,
276 #undef BTF_TRACING_TYPE
277 MAX_BTF_TRACING_TYPE,
280 extern u32 btf_tracing_ids[];
281 extern u32 bpf_cgroup_btf_id[];
282 extern u32 bpf_local_storage_map_btf_id[];
283 extern u32 btf_bpf_map_id[];