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