xref: /linux/tools/include/linux/btf_ids.h (revision 9b61b2069681b60d0d0bedbd0fe3c70123dddb19)
1e5a0516eSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */
2e5a0516eSJiri Olsa 
3e5a0516eSJiri Olsa #ifndef _LINUX_BTF_IDS_H
4e5a0516eSJiri Olsa #define _LINUX_BTF_IDS_H
5e5a0516eSJiri Olsa 
6*62248b22SNatanael Copa #include <linux/types.h> /* for u32 */
7*62248b22SNatanael Copa 
8eae2e83eSJiri Olsa struct btf_id_set {
9eae2e83eSJiri Olsa 	u32 cnt;
10eae2e83eSJiri Olsa 	u32 ids[];
11eae2e83eSJiri Olsa };
12eae2e83eSJiri Olsa 
139707ac4fSViktor Malik struct btf_id_set8 {
149707ac4fSViktor Malik 	u32 cnt;
159707ac4fSViktor Malik 	u32 flags;
169707ac4fSViktor Malik 	struct {
179707ac4fSViktor Malik 		u32 id;
189707ac4fSViktor Malik 		u32 flags;
199707ac4fSViktor Malik 	} pairs[];
209707ac4fSViktor Malik };
219707ac4fSViktor Malik 
22d8dfe5bfSYonghong Song #ifdef CONFIG_DEBUG_INFO_BTF
23d8dfe5bfSYonghong Song 
24e5a0516eSJiri Olsa #include <linux/compiler.h> /* for __PASTE */
25e5a0516eSJiri Olsa 
26e5a0516eSJiri Olsa /*
27e5a0516eSJiri Olsa  * Following macros help to define lists of BTF IDs placed
28e5a0516eSJiri Olsa  * in .BTF_ids section. They are initially filled with zeros
29e5a0516eSJiri Olsa  * (during compilation) and resolved later during the
30e5a0516eSJiri Olsa  * linking phase by resolve_btfids tool.
31e5a0516eSJiri Olsa  *
32e5a0516eSJiri Olsa  * Any change in list layout must be reflected in resolve_btfids
33e5a0516eSJiri Olsa  * tool logic.
34e5a0516eSJiri Olsa  */
35e5a0516eSJiri Olsa 
36e5a0516eSJiri Olsa #define BTF_IDS_SECTION ".BTF_ids"
37e5a0516eSJiri Olsa 
38e5a0516eSJiri Olsa #define ____BTF_ID(symbol)				\
39e5a0516eSJiri Olsa asm(							\
40e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"	\
41e5a0516eSJiri Olsa ".local " #symbol " ;                          \n"	\
42d8dfe5bfSYonghong Song ".type  " #symbol ", STT_OBJECT;               \n"	\
43e5a0516eSJiri Olsa ".size  " #symbol ", 4;                        \n"	\
44e5a0516eSJiri Olsa #symbol ":                                     \n"	\
45e5a0516eSJiri Olsa ".zero 4                                       \n"	\
46e5a0516eSJiri Olsa ".popsection;                                  \n");
47e5a0516eSJiri Olsa 
48e5a0516eSJiri Olsa #define __BTF_ID(symbol) \
49e5a0516eSJiri Olsa 	____BTF_ID(symbol)
50e5a0516eSJiri Olsa 
51e5a0516eSJiri Olsa #define __ID(prefix) \
52c0bb9fb0SNick Desaulniers 	__PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
53e5a0516eSJiri Olsa 
54e5a0516eSJiri Olsa /*
55e5a0516eSJiri Olsa  * The BTF_ID defines unique symbol for each ID pointing
56e5a0516eSJiri Olsa  * to 4 zero bytes.
57e5a0516eSJiri Olsa  */
58e5a0516eSJiri Olsa #define BTF_ID(prefix, name) \
59e5a0516eSJiri Olsa 	__BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
60e5a0516eSJiri Olsa 
61e5a0516eSJiri Olsa /*
62e5a0516eSJiri Olsa  * The BTF_ID_LIST macro defines pure (unsorted) list
63e5a0516eSJiri Olsa  * of BTF IDs, with following layout:
64e5a0516eSJiri Olsa  *
65e5a0516eSJiri Olsa  * BTF_ID_LIST(list1)
66e5a0516eSJiri Olsa  * BTF_ID(type1, name1)
67e5a0516eSJiri Olsa  * BTF_ID(type2, name2)
68e5a0516eSJiri Olsa  *
69e5a0516eSJiri Olsa  * list1:
70e5a0516eSJiri Olsa  * __BTF_ID__type1__name1__1:
71e5a0516eSJiri Olsa  * .zero 4
72e5a0516eSJiri Olsa  * __BTF_ID__type2__name2__2:
73e5a0516eSJiri Olsa  * .zero 4
74e5a0516eSJiri Olsa  *
75e5a0516eSJiri Olsa  */
760f12e584SYonghong Song #define __BTF_ID_LIST(name, scope)			\
77e5a0516eSJiri Olsa asm(							\
78e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"	\
790f12e584SYonghong Song "." #scope " " #name ";                        \n"	\
80e5a0516eSJiri Olsa #name ":;                                      \n"	\
81eae2e83eSJiri Olsa ".popsection;                                  \n");
82e5a0516eSJiri Olsa 
83e5a0516eSJiri Olsa #define BTF_ID_LIST(name)				\
840f12e584SYonghong Song __BTF_ID_LIST(name, local)				\
85e5a0516eSJiri Olsa extern u32 name[];
86e5a0516eSJiri Olsa 
873b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL(name, n)			\
880f12e584SYonghong Song __BTF_ID_LIST(name, globl)
890f12e584SYonghong Song 
9027774b70SLorenz Bauer /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
9127774b70SLorenz Bauer  * a single entry.
9227774b70SLorenz Bauer  */
9327774b70SLorenz Bauer #define BTF_ID_LIST_SINGLE(name, prefix, typename)	\
9427774b70SLorenz Bauer 	BTF_ID_LIST(name) \
9527774b70SLorenz Bauer 	BTF_ID(prefix, typename)
963b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
973b34bcb9SStanislav Fomichev 	BTF_ID_LIST_GLOBAL(name, 1)			  \
983b34bcb9SStanislav Fomichev 	BTF_ID(prefix, typename)
9927774b70SLorenz Bauer 
100e5a0516eSJiri Olsa /*
101e5a0516eSJiri Olsa  * The BTF_ID_UNUSED macro defines 4 zero bytes.
102e5a0516eSJiri Olsa  * It's used when we want to define 'unused' entry
103e5a0516eSJiri Olsa  * in BTF_ID_LIST, like:
104e5a0516eSJiri Olsa  *
105e5a0516eSJiri Olsa  *   BTF_ID_LIST(bpf_skb_output_btf_ids)
106e5a0516eSJiri Olsa  *   BTF_ID(struct, sk_buff)
107e5a0516eSJiri Olsa  *   BTF_ID_UNUSED
108e5a0516eSJiri Olsa  *   BTF_ID(struct, task_struct)
109e5a0516eSJiri Olsa  */
110e5a0516eSJiri Olsa 
111e5a0516eSJiri Olsa #define BTF_ID_UNUSED					\
112e5a0516eSJiri Olsa asm(							\
113e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"	\
114e5a0516eSJiri Olsa ".zero 4                                       \n"	\
115e5a0516eSJiri Olsa ".popsection;                                  \n");
116e5a0516eSJiri Olsa 
117eae2e83eSJiri Olsa /*
118eae2e83eSJiri Olsa  * The BTF_SET_START/END macros pair defines sorted list of
119eae2e83eSJiri Olsa  * BTF IDs plus its members count, with following layout:
120eae2e83eSJiri Olsa  *
121eae2e83eSJiri Olsa  * BTF_SET_START(list)
122eae2e83eSJiri Olsa  * BTF_ID(type1, name1)
123eae2e83eSJiri Olsa  * BTF_ID(type2, name2)
124eae2e83eSJiri Olsa  * BTF_SET_END(list)
125eae2e83eSJiri Olsa  *
126eae2e83eSJiri Olsa  * __BTF_ID__set__list:
127eae2e83eSJiri Olsa  * .zero 4
128eae2e83eSJiri Olsa  * list:
129eae2e83eSJiri Olsa  * __BTF_ID__type1__name1__3:
130eae2e83eSJiri Olsa  * .zero 4
131eae2e83eSJiri Olsa  * __BTF_ID__type2__name2__4:
132eae2e83eSJiri Olsa  * .zero 4
133eae2e83eSJiri Olsa  *
134eae2e83eSJiri Olsa  */
135eae2e83eSJiri Olsa #define __BTF_SET_START(name, scope)			\
136eae2e83eSJiri Olsa asm(							\
137eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"	\
138eae2e83eSJiri Olsa "." #scope " __BTF_ID__set__" #name ";         \n"	\
139eae2e83eSJiri Olsa "__BTF_ID__set__" #name ":;                    \n"	\
140eae2e83eSJiri Olsa ".zero 4                                       \n"	\
141eae2e83eSJiri Olsa ".popsection;                                  \n");
142eae2e83eSJiri Olsa 
143eae2e83eSJiri Olsa #define BTF_SET_START(name)				\
144eae2e83eSJiri Olsa __BTF_ID_LIST(name, local)				\
145eae2e83eSJiri Olsa __BTF_SET_START(name, local)
146eae2e83eSJiri Olsa 
147eae2e83eSJiri Olsa #define BTF_SET_START_GLOBAL(name)			\
148eae2e83eSJiri Olsa __BTF_ID_LIST(name, globl)				\
149eae2e83eSJiri Olsa __BTF_SET_START(name, globl)
150eae2e83eSJiri Olsa 
151eae2e83eSJiri Olsa #define BTF_SET_END(name)				\
152eae2e83eSJiri Olsa asm(							\
153eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\";      \n"	\
154eae2e83eSJiri Olsa ".size __BTF_ID__set__" #name ", .-" #name "  \n"	\
155eae2e83eSJiri Olsa ".popsection;                                 \n");	\
156eae2e83eSJiri Olsa extern struct btf_id_set name;
157eae2e83eSJiri Olsa 
158d8dfe5bfSYonghong Song #else
159d8dfe5bfSYonghong Song 
1603b34bcb9SStanislav Fomichev #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
161d8dfe5bfSYonghong Song #define BTF_ID(prefix, name)
162d8dfe5bfSYonghong Song #define BTF_ID_UNUSED
1633b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
1643b34bcb9SStanislav Fomichev #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
1653b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
1663b34bcb9SStanislav Fomichev #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
1673b34bcb9SStanislav Fomichev #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
168eae2e83eSJiri Olsa #define BTF_SET_END(name)
169d8dfe5bfSYonghong Song 
170d8dfe5bfSYonghong Song #endif /* CONFIG_DEBUG_INFO_BTF */
171e5a0516eSJiri Olsa 
172fce557bcSYonghong Song #ifdef CONFIG_NET
173fce557bcSYonghong Song /* Define a list of socket types which can be the argument for
174fce557bcSYonghong Song  * skc_to_*_sock() helpers. All these sockets should have
175fce557bcSYonghong Song  * sock_common as the first argument in its memory layout.
176fce557bcSYonghong Song  */
177fce557bcSYonghong Song #define BTF_SOCK_TYPE_xxx \
178fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
179fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
180fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
181fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
182fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
183fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
184fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
185fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
186fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
187fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
188fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
189fce557bcSYonghong Song 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
1903b34bcb9SStanislav Fomichev 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)			\
1913b34bcb9SStanislav Fomichev 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)			\
1923b34bcb9SStanislav Fomichev 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock)			\
1933b34bcb9SStanislav Fomichev 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
194fce557bcSYonghong Song 
195fce557bcSYonghong Song enum {
196fce557bcSYonghong Song #define BTF_SOCK_TYPE(name, str) name,
197fce557bcSYonghong Song BTF_SOCK_TYPE_xxx
198fce557bcSYonghong Song #undef BTF_SOCK_TYPE
199fce557bcSYonghong Song MAX_BTF_SOCK_TYPE,
200fce557bcSYonghong Song };
201fce557bcSYonghong Song 
202fce557bcSYonghong Song extern u32 btf_sock_ids[];
203fce557bcSYonghong Song #endif
204fce557bcSYonghong Song 
2053b34bcb9SStanislav Fomichev #define BTF_TRACING_TYPE_xxx	\
2063b34bcb9SStanislav Fomichev 	BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct)	\
2073b34bcb9SStanislav Fomichev 	BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file)		\
2083b34bcb9SStanislav Fomichev 	BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
2093b34bcb9SStanislav Fomichev 
2103b34bcb9SStanislav Fomichev enum {
2113b34bcb9SStanislav Fomichev #define BTF_TRACING_TYPE(name, type) name,
2123b34bcb9SStanislav Fomichev BTF_TRACING_TYPE_xxx
2133b34bcb9SStanislav Fomichev #undef BTF_TRACING_TYPE
2143b34bcb9SStanislav Fomichev MAX_BTF_TRACING_TYPE,
2153b34bcb9SStanislav Fomichev };
2163b34bcb9SStanislav Fomichev 
2173b34bcb9SStanislav Fomichev extern u32 btf_tracing_ids[];
2183b34bcb9SStanislav Fomichev 
219e5a0516eSJiri Olsa #endif
220