1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
20 #ifdef CONFIG_DEBUG_INFO_BTF
22 #include <linux/compiler.h> /* for __PASTE */
23 #include <linux/compiler_attributes.h> /* for __maybe_unused */
26 * Following macros help to define lists of BTF IDs placed
27 * in .BTF_ids section. They are initially filled with zeros
28 * (during compilation) and resolved later during the
29 * linking phase by resolve_btfids tool.
31 * Any change in list layout must be reflected in resolve_btfids
35 #define BTF_IDS_SECTION ".BTF_ids"
37 #define ____BTF_ID(symbol, word) \
39 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
40 ".local " #symbol " ; \n" \
41 ".type " #symbol ", STT_OBJECT; \n" \
42 ".size " #symbol ", 4; \n" \
48 #define __BTF_ID(symbol, word) \
49 ____BTF_ID(symbol, word)
51 #define __ID(prefix) \
52 __PASTE(prefix, __COUNTER__)
55 * The BTF_ID defines unique symbol for each ID pointing
58 #define BTF_ID(prefix, name) \
59 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "")
61 #define ____BTF_ID_FLAGS(prefix, name, flags) \
62 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n")
63 #define __BTF_ID_FLAGS(prefix, name, flags, ...) \
64 ____BTF_ID_FLAGS(prefix, name, flags)
65 #define BTF_ID_FLAGS(prefix, name, ...) \
66 __BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0)
69 * The BTF_ID_LIST macro defines pure (unsorted) list
70 * of BTF IDs, with following layout:
73 * BTF_ID(type1, name1)
74 * BTF_ID(type2, name2)
77 * __BTF_ID__type1__name1__1:
79 * __BTF_ID__type2__name2__2:
83 #define __BTF_ID_LIST(name, scope) \
85 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
86 "." #scope " " #name "; \n" \
90 #define BTF_ID_LIST(name) \
91 __BTF_ID_LIST(name, local) \
94 #define BTF_ID_LIST_GLOBAL(name, n) \
95 __BTF_ID_LIST(name, globl)
97 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
100 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \
102 BTF_ID(prefix, typename)
103 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
104 BTF_ID_LIST_GLOBAL(name, 1) \
105 BTF_ID(prefix, typename)
108 * The BTF_ID_UNUSED macro defines 4 zero bytes.
109 * It's used when we want to define 'unused' entry
110 * in BTF_ID_LIST, like:
112 * BTF_ID_LIST(bpf_skb_output_btf_ids)
113 * BTF_ID(struct, sk_buff)
115 * BTF_ID(struct, task_struct)
118 #define BTF_ID_UNUSED \
120 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
125 * The BTF_SET_START/END macros pair defines sorted list of
126 * BTF IDs plus its members count, with following layout:
128 * BTF_SET_START(list)
129 * BTF_ID(type1, name1)
130 * BTF_ID(type2, name2)
133 * __BTF_ID__set__list:
136 * __BTF_ID__type1__name1__3:
138 * __BTF_ID__type2__name2__4:
142 #define __BTF_SET_START(name, scope) \
144 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
145 "." #scope " __BTF_ID__set__" #name "; \n" \
146 "__BTF_ID__set__" #name ":; \n" \
150 #define BTF_SET_START(name) \
151 __BTF_ID_LIST(name, local) \
152 __BTF_SET_START(name, local)
154 #define BTF_SET_START_GLOBAL(name) \
155 __BTF_ID_LIST(name, globl) \
156 __BTF_SET_START(name, globl)
158 #define BTF_SET_END(name) \
160 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
161 ".size __BTF_ID__set__" #name ", .-" #name " \n" \
162 ".popsection; \n"); \
163 extern struct btf_id_set name;
166 * The BTF_SET8_START/END macros pair defines sorted list of
167 * BTF IDs and their flags plus its members count, with the
170 * BTF_SET8_START(list)
171 * BTF_ID_FLAGS(type1, name1, flags)
172 * BTF_ID_FLAGS(type2, name2, flags)
175 * __BTF_ID__set8__list:
178 * __BTF_ID__type1__name1__3:
180 * .word (1 << 0) | (1 << 2)
181 * __BTF_ID__type2__name2__5:
183 * .word (1 << 3) | (1 << 1) | (1 << 2)
186 #define __BTF_SET8_START(name, scope) \
188 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
189 "." #scope " __BTF_ID__set8__" #name "; \n" \
190 "__BTF_ID__set8__" #name ":; \n" \
194 #define BTF_SET8_START(name) \
195 __BTF_ID_LIST(name, local) \
196 __BTF_SET8_START(name, local)
198 #define BTF_SET8_END(name) \
200 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
201 ".size __BTF_ID__set8__" #name ", .-" #name " \n" \
202 ".popsection; \n"); \
203 extern struct btf_id_set8 name;
207 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
208 #define BTF_ID(prefix, name)
209 #define BTF_ID_FLAGS(prefix, name, ...)
210 #define BTF_ID_UNUSED
211 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
212 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
213 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
214 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
215 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
216 #define BTF_SET_END(name)
217 #define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 };
218 #define BTF_SET8_END(name)
220 #endif /* CONFIG_DEBUG_INFO_BTF */
223 /* Define a list of socket types which can be the argument for
224 * skc_to_*_sock() helpers. All these sockets should have
225 * sock_common as the first argument in its memory layout.
227 #define BTF_SOCK_TYPE_xxx \
228 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
229 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
230 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
231 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
232 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
233 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
234 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
235 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
236 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
237 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
238 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
239 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
240 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
241 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
242 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
243 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
246 #define BTF_SOCK_TYPE(name, str) name,
252 extern u32 btf_sock_ids[];
255 #define BTF_TRACING_TYPE_xxx \
256 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
257 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
258 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
261 #define BTF_TRACING_TYPE(name, type) name,
263 #undef BTF_TRACING_TYPE
264 MAX_BTF_TRACING_TYPE,
267 extern u32 btf_tracing_ids[];
268 extern u32 bpf_cgroup_btf_id[];