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