Documentation: embargoed-hardware-issues.rst: Add myself for Power
[sfrench/cifs-2.6.git] / tools / include / linux / btf_ids.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
5
6 struct btf_id_set {
7         u32 cnt;
8         u32 ids[];
9 };
10
11 struct btf_id_set8 {
12         u32 cnt;
13         u32 flags;
14         struct {
15                 u32 id;
16                 u32 flags;
17         } pairs[];
18 };
19
20 #ifdef CONFIG_DEBUG_INFO_BTF
21
22 #include <linux/compiler.h> /* for __PASTE */
23
24 /*
25  * Following macros help to define lists of BTF IDs placed
26  * in .BTF_ids section. They are initially filled with zeros
27  * (during compilation) and resolved later during the
28  * linking phase by resolve_btfids tool.
29  *
30  * Any change in list layout must be reflected in resolve_btfids
31  * tool logic.
32  */
33
34 #define BTF_IDS_SECTION ".BTF_ids"
35
36 #define ____BTF_ID(symbol)                              \
37 asm(                                                    \
38 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"      \
39 ".local " #symbol " ;                          \n"      \
40 ".type  " #symbol ", STT_OBJECT;               \n"      \
41 ".size  " #symbol ", 4;                        \n"      \
42 #symbol ":                                     \n"      \
43 ".zero 4                                       \n"      \
44 ".popsection;                                  \n");
45
46 #define __BTF_ID(symbol) \
47         ____BTF_ID(symbol)
48
49 #define __ID(prefix) \
50         __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
51
52 /*
53  * The BTF_ID defines unique symbol for each ID pointing
54  * to 4 zero bytes.
55  */
56 #define BTF_ID(prefix, name) \
57         __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
58
59 /*
60  * The BTF_ID_LIST macro defines pure (unsorted) list
61  * of BTF IDs, with following layout:
62  *
63  * BTF_ID_LIST(list1)
64  * BTF_ID(type1, name1)
65  * BTF_ID(type2, name2)
66  *
67  * list1:
68  * __BTF_ID__type1__name1__1:
69  * .zero 4
70  * __BTF_ID__type2__name2__2:
71  * .zero 4
72  *
73  */
74 #define __BTF_ID_LIST(name, scope)                      \
75 asm(                                                    \
76 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"      \
77 "." #scope " " #name ";                        \n"      \
78 #name ":;                                      \n"      \
79 ".popsection;                                  \n");
80
81 #define BTF_ID_LIST(name)                               \
82 __BTF_ID_LIST(name, local)                              \
83 extern u32 name[];
84
85 #define BTF_ID_LIST_GLOBAL(name, n)                     \
86 __BTF_ID_LIST(name, globl)
87
88 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
89  * a single entry.
90  */
91 #define BTF_ID_LIST_SINGLE(name, prefix, typename)      \
92         BTF_ID_LIST(name) \
93         BTF_ID(prefix, typename)
94 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
95         BTF_ID_LIST_GLOBAL(name, 1)                       \
96         BTF_ID(prefix, typename)
97
98 /*
99  * The BTF_ID_UNUSED macro defines 4 zero bytes.
100  * It's used when we want to define 'unused' entry
101  * in BTF_ID_LIST, like:
102  *
103  *   BTF_ID_LIST(bpf_skb_output_btf_ids)
104  *   BTF_ID(struct, sk_buff)
105  *   BTF_ID_UNUSED
106  *   BTF_ID(struct, task_struct)
107  */
108
109 #define BTF_ID_UNUSED                                   \
110 asm(                                                    \
111 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"      \
112 ".zero 4                                       \n"      \
113 ".popsection;                                  \n");
114
115 /*
116  * The BTF_SET_START/END macros pair defines sorted list of
117  * BTF IDs plus its members count, with following layout:
118  *
119  * BTF_SET_START(list)
120  * BTF_ID(type1, name1)
121  * BTF_ID(type2, name2)
122  * BTF_SET_END(list)
123  *
124  * __BTF_ID__set__list:
125  * .zero 4
126  * list:
127  * __BTF_ID__type1__name1__3:
128  * .zero 4
129  * __BTF_ID__type2__name2__4:
130  * .zero 4
131  *
132  */
133 #define __BTF_SET_START(name, scope)                    \
134 asm(                                                    \
135 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"      \
136 "." #scope " __BTF_ID__set__" #name ";         \n"      \
137 "__BTF_ID__set__" #name ":;                    \n"      \
138 ".zero 4                                       \n"      \
139 ".popsection;                                  \n");
140
141 #define BTF_SET_START(name)                             \
142 __BTF_ID_LIST(name, local)                              \
143 __BTF_SET_START(name, local)
144
145 #define BTF_SET_START_GLOBAL(name)                      \
146 __BTF_ID_LIST(name, globl)                              \
147 __BTF_SET_START(name, globl)
148
149 #define BTF_SET_END(name)                               \
150 asm(                                                    \
151 ".pushsection " BTF_IDS_SECTION ",\"a\";      \n"       \
152 ".size __BTF_ID__set__" #name ", .-" #name "  \n"       \
153 ".popsection;                                 \n");     \
154 extern struct btf_id_set name;
155
156 #else
157
158 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
159 #define BTF_ID(prefix, name)
160 #define BTF_ID_UNUSED
161 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
162 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
163 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
164 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
165 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
166 #define BTF_SET_END(name)
167
168 #endif /* CONFIG_DEBUG_INFO_BTF */
169
170 #ifdef CONFIG_NET
171 /* Define a list of socket types which can be the argument for
172  * skc_to_*_sock() helpers. All these sockets should have
173  * sock_common as the first argument in its memory layout.
174  */
175 #define BTF_SOCK_TYPE_xxx \
176         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)                    \
177         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)    \
178         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)        \
179         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
180         BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)                  \
181         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)                         \
182         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)           \
183         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)                      \
184         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)          \
185         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)          \
186         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)                    \
187         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)                      \
188         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)                    \
189         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)                    \
190         BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock)                  \
191         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
192
193 enum {
194 #define BTF_SOCK_TYPE(name, str) name,
195 BTF_SOCK_TYPE_xxx
196 #undef BTF_SOCK_TYPE
197 MAX_BTF_SOCK_TYPE,
198 };
199
200 extern u32 btf_sock_ids[];
201 #endif
202
203 #define BTF_TRACING_TYPE_xxx    \
204         BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct)    \
205         BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file)           \
206         BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
207
208 enum {
209 #define BTF_TRACING_TYPE(name, type) name,
210 BTF_TRACING_TYPE_xxx
211 #undef BTF_TRACING_TYPE
212 MAX_BTF_TRACING_TYPE,
213 };
214
215 extern u32 btf_tracing_ids[];
216
217 #endif