Merge tag 'xfs-6.4-rc1-fixes' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-block.git] / include / linux / btf_ids.h
CommitLineData
5a2798ab
JO
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef _LINUX_BTF_IDS_H
4#define _LINUX_BTF_IDS_H
5
eae2e83e
JO
6struct btf_id_set {
7 u32 cnt;
8 u32 ids[];
9};
10
ab21d606
KKD
11struct btf_id_set8 {
12 u32 cnt;
13 u32 flags;
14 struct {
15 u32 id;
16 u32 flags;
17 } pairs[];
18};
19
079ef536
JO
20#ifdef CONFIG_DEBUG_INFO_BTF
21
5a2798ab 22#include <linux/compiler.h> /* for __PASTE */
dee872e1 23#include <linux/compiler_attributes.h> /* for __maybe_unused */
5a2798ab
JO
24
25/*
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.
30 *
31 * Any change in list layout must be reflected in resolve_btfids
32 * tool logic.
33 */
34
35#define BTF_IDS_SECTION ".BTF_ids"
36
ab21d606 37#define ____BTF_ID(symbol, word) \
5a2798ab
JO
38asm( \
39".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
40".local " #symbol " ; \n" \
11bb2f7a 41".type " #symbol ", STT_OBJECT; \n" \
5a2798ab
JO
42".size " #symbol ", 4; \n" \
43#symbol ": \n" \
44".zero 4 \n" \
ab21d606 45word \
5a2798ab
JO
46".popsection; \n");
47
ab21d606
KKD
48#define __BTF_ID(symbol, word) \
49 ____BTF_ID(symbol, word)
5a2798ab
JO
50
51#define __ID(prefix) \
52 __PASTE(prefix, __COUNTER__)
53
54/*
55 * The BTF_ID defines unique symbol for each ID pointing
56 * to 4 zero bytes.
57 */
58#define BTF_ID(prefix, name) \
ab21d606
KKD
59 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "")
60
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)
5a2798ab
JO
67
68/*
69 * The BTF_ID_LIST macro defines pure (unsorted) list
70 * of BTF IDs, with following layout:
71 *
72 * BTF_ID_LIST(list1)
73 * BTF_ID(type1, name1)
74 * BTF_ID(type2, name2)
75 *
76 * list1:
77 * __BTF_ID__type1__name1__1:
78 * .zero 4
79 * __BTF_ID__type2__name2__2:
80 * .zero 4
81 *
82 */
0f12e584 83#define __BTF_ID_LIST(name, scope) \
5a2798ab
JO
84asm( \
85".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
0f12e584 86"." #scope " " #name "; \n" \
5a2798ab 87#name ":; \n" \
eae2e83e 88".popsection; \n");
5a2798ab
JO
89
90#define BTF_ID_LIST(name) \
0f12e584 91__BTF_ID_LIST(name, local) \
5a2798ab
JO
92extern u32 name[];
93
9e2ad638 94#define BTF_ID_LIST_GLOBAL(name, n) \
0f12e584
YS
95__BTF_ID_LIST(name, globl)
96
27774b70
LB
97/* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
98 * a single entry.
99 */
100#define BTF_ID_LIST_SINGLE(name, prefix, typename) \
101 BTF_ID_LIST(name) \
102 BTF_ID(prefix, typename)
1b07d00a 103#define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
9e2ad638 104 BTF_ID_LIST_GLOBAL(name, 1) \
1b07d00a 105 BTF_ID(prefix, typename)
27774b70 106
5a2798ab
JO
107/*
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:
111 *
112 * BTF_ID_LIST(bpf_skb_output_btf_ids)
113 * BTF_ID(struct, sk_buff)
114 * BTF_ID_UNUSED
115 * BTF_ID(struct, task_struct)
116 */
117
118#define BTF_ID_UNUSED \
119asm( \
120".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
121".zero 4 \n" \
122".popsection; \n");
123
eae2e83e
JO
124/*
125 * The BTF_SET_START/END macros pair defines sorted list of
126 * BTF IDs plus its members count, with following layout:
127 *
128 * BTF_SET_START(list)
129 * BTF_ID(type1, name1)
130 * BTF_ID(type2, name2)
131 * BTF_SET_END(list)
132 *
133 * __BTF_ID__set__list:
134 * .zero 4
135 * list:
136 * __BTF_ID__type1__name1__3:
137 * .zero 4
138 * __BTF_ID__type2__name2__4:
139 * .zero 4
140 *
141 */
142#define __BTF_SET_START(name, scope) \
143asm( \
144".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
145"." #scope " __BTF_ID__set__" #name "; \n" \
146"__BTF_ID__set__" #name ":; \n" \
147".zero 4 \n" \
148".popsection; \n");
149
150#define BTF_SET_START(name) \
151__BTF_ID_LIST(name, local) \
152__BTF_SET_START(name, local)
153
154#define BTF_SET_START_GLOBAL(name) \
155__BTF_ID_LIST(name, globl) \
156__BTF_SET_START(name, globl)
157
158#define BTF_SET_END(name) \
159asm( \
160".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
161".size __BTF_ID__set__" #name ", .-" #name " \n" \
162".popsection; \n"); \
163extern struct btf_id_set name;
164
ab21d606
KKD
165/*
166 * The BTF_SET8_START/END macros pair defines sorted list of
167 * BTF IDs and their flags plus its members count, with the
168 * following layout:
169 *
170 * BTF_SET8_START(list)
171 * BTF_ID_FLAGS(type1, name1, flags)
172 * BTF_ID_FLAGS(type2, name2, flags)
173 * BTF_SET8_END(list)
174 *
175 * __BTF_ID__set8__list:
176 * .zero 8
177 * list:
178 * __BTF_ID__type1__name1__3:
179 * .zero 4
180 * .word (1 << 0) | (1 << 2)
181 * __BTF_ID__type2__name2__5:
182 * .zero 4
183 * .word (1 << 3) | (1 << 1) | (1 << 2)
184 *
185 */
186#define __BTF_SET8_START(name, scope) \
187asm( \
188".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
189"." #scope " __BTF_ID__set8__" #name "; \n" \
190"__BTF_ID__set8__" #name ":; \n" \
191".zero 8 \n" \
192".popsection; \n");
193
194#define BTF_SET8_START(name) \
195__BTF_ID_LIST(name, local) \
196__BTF_SET8_START(name, local)
197
198#define BTF_SET8_END(name) \
199asm( \
200".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
201".size __BTF_ID__set8__" #name ", .-" #name " \n" \
202".popsection; \n"); \
203extern struct btf_id_set8 name;
204
079ef536
JO
205#else
206
2d5bcdcd 207#define BTF_ID_LIST(name) static u32 __maybe_unused name[64];
079ef536 208#define BTF_ID(prefix, name)
e4234143 209#define BTF_ID_FLAGS(prefix, name, ...)
079ef536 210#define BTF_ID_UNUSED
dee872e1
KKD
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 };
eae2e83e 216#define BTF_SET_END(name)
ab21d606 217#define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 };
e4234143 218#define BTF_SET8_END(name)
079ef536
JO
219
220#endif /* CONFIG_DEBUG_INFO_BTF */
5a2798ab 221
fce557bc
YS
222#ifdef CONFIG_NET
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.
226 */
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) \
2c860a43 240 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
3bc253c2 241 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
69fd337a
SF
242 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
243 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
fce557bc
YS
244
245enum {
246#define BTF_SOCK_TYPE(name, str) name,
247BTF_SOCK_TYPE_xxx
248#undef BTF_SOCK_TYPE
249MAX_BTF_SOCK_TYPE,
250};
251
252extern u32 btf_sock_ids[];
253#endif
254
d19ddb47
SL
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)
259
260enum {
261#define BTF_TRACING_TYPE(name, type) name,
262BTF_TRACING_TYPE_xxx
263#undef BTF_TRACING_TYPE
264MAX_BTF_TRACING_TYPE,
265};
266
267extern u32 btf_tracing_ids[];
5e67b8ef 268extern u32 bpf_cgroup_btf_id[];
3144bfa5 269extern u32 bpf_local_storage_map_btf_id[];
33c5cb36 270
5a2798ab 271#endif