Commit | Line | Data |
---|---|---|
e5a0516e 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 | ||
d8dfe5bf YS |
11 | #ifdef CONFIG_DEBUG_INFO_BTF |
12 | ||
e5a0516e 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" \ | |
d8dfe5bf | 31 | ".type " #symbol ", STT_OBJECT; \n" \ |
e5a0516e 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) \ |
e5a0516e JO |
66 | asm( \ |
67 | ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ | |
0f12e584 | 68 | "." #scope " " #name "; \n" \ |
e5a0516e | 69 | #name ":; \n" \ |
eae2e83e | 70 | ".popsection; \n"); |
e5a0516e JO |
71 | |
72 | #define BTF_ID_LIST(name) \ | |
0f12e584 | 73 | __BTF_ID_LIST(name, local) \ |
e5a0516e 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) | |
85 | ||
e5a0516e JO |
86 | /* |
87 | * The BTF_ID_UNUSED macro defines 4 zero bytes. | |
88 | * It's used when we want to define 'unused' entry | |
89 | * in BTF_ID_LIST, like: | |
90 | * | |
91 | * BTF_ID_LIST(bpf_skb_output_btf_ids) | |
92 | * BTF_ID(struct, sk_buff) | |
93 | * BTF_ID_UNUSED | |
94 | * BTF_ID(struct, task_struct) | |
95 | */ | |
96 | ||
97 | #define BTF_ID_UNUSED \ | |
98 | asm( \ | |
99 | ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ | |
100 | ".zero 4 \n" \ | |
101 | ".popsection; \n"); | |
102 | ||
eae2e83e JO |
103 | /* |
104 | * The BTF_SET_START/END macros pair defines sorted list of | |
105 | * BTF IDs plus its members count, with following layout: | |
106 | * | |
107 | * BTF_SET_START(list) | |
108 | * BTF_ID(type1, name1) | |
109 | * BTF_ID(type2, name2) | |
110 | * BTF_SET_END(list) | |
111 | * | |
112 | * __BTF_ID__set__list: | |
113 | * .zero 4 | |
114 | * list: | |
115 | * __BTF_ID__type1__name1__3: | |
116 | * .zero 4 | |
117 | * __BTF_ID__type2__name2__4: | |
118 | * .zero 4 | |
119 | * | |
120 | */ | |
121 | #define __BTF_SET_START(name, scope) \ | |
122 | asm( \ | |
123 | ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ | |
124 | "." #scope " __BTF_ID__set__" #name "; \n" \ | |
125 | "__BTF_ID__set__" #name ":; \n" \ | |
126 | ".zero 4 \n" \ | |
127 | ".popsection; \n"); | |
128 | ||
129 | #define BTF_SET_START(name) \ | |
130 | __BTF_ID_LIST(name, local) \ | |
131 | __BTF_SET_START(name, local) | |
132 | ||
133 | #define BTF_SET_START_GLOBAL(name) \ | |
134 | __BTF_ID_LIST(name, globl) \ | |
135 | __BTF_SET_START(name, globl) | |
136 | ||
137 | #define BTF_SET_END(name) \ | |
138 | asm( \ | |
139 | ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ | |
140 | ".size __BTF_ID__set__" #name ", .-" #name " \n" \ | |
141 | ".popsection; \n"); \ | |
142 | extern struct btf_id_set name; | |
143 | ||
d8dfe5bf YS |
144 | #else |
145 | ||
146 | #define BTF_ID_LIST(name) static u32 name[5]; | |
147 | #define BTF_ID(prefix, name) | |
148 | #define BTF_ID_UNUSED | |
0f12e584 | 149 | #define BTF_ID_LIST_GLOBAL(name) u32 name[1]; |
27774b70 | 150 | #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 name[1]; |
eae2e83e JO |
151 | #define BTF_SET_START(name) static struct btf_id_set name = { 0 }; |
152 | #define BTF_SET_START_GLOBAL(name) static struct btf_id_set name = { 0 }; | |
153 | #define BTF_SET_END(name) | |
d8dfe5bf YS |
154 | |
155 | #endif /* CONFIG_DEBUG_INFO_BTF */ | |
e5a0516e | 156 | |
fce557bc YS |
157 | #ifdef CONFIG_NET |
158 | /* Define a list of socket types which can be the argument for | |
159 | * skc_to_*_sock() helpers. All these sockets should have | |
160 | * sock_common as the first argument in its memory layout. | |
161 | */ | |
162 | #define BTF_SOCK_TYPE_xxx \ | |
163 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ | |
164 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ | |
165 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ | |
166 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ | |
167 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ | |
168 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ | |
169 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ | |
170 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ | |
171 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ | |
172 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ | |
173 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ | |
174 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ | |
175 | BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) | |
176 | ||
177 | enum { | |
178 | #define BTF_SOCK_TYPE(name, str) name, | |
179 | BTF_SOCK_TYPE_xxx | |
180 | #undef BTF_SOCK_TYPE | |
181 | MAX_BTF_SOCK_TYPE, | |
182 | }; | |
183 | ||
184 | extern u32 btf_sock_ids[]; | |
185 | #endif | |
186 | ||
e5a0516e | 187 | #endif |