1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 3 #ifndef _LINUX_BTF_IDS_H 3 #ifndef _LINUX_BTF_IDS_H 4 #define _LINUX_BTF_IDS_H 4 #define _LINUX_BTF_IDS_H 5 5 6 #include <linux/types.h> /* for u32 */ << 7 << 8 struct btf_id_set { 6 struct btf_id_set { 9 u32 cnt; 7 u32 cnt; 10 u32 ids[]; 8 u32 ids[]; 11 }; 9 }; 12 10 13 /* This flag implies BTF_SET8 holds kfunc(s) * << 14 #define BTF_SET8_KFUNCS (1 << 0) << 15 << 16 struct btf_id_set8 { 11 struct btf_id_set8 { 17 u32 cnt; 12 u32 cnt; 18 u32 flags; 13 u32 flags; 19 struct { 14 struct { 20 u32 id; 15 u32 id; 21 u32 flags; 16 u32 flags; 22 } pairs[]; 17 } pairs[]; 23 }; 18 }; 24 19 25 #ifdef CONFIG_DEBUG_INFO_BTF 20 #ifdef CONFIG_DEBUG_INFO_BTF 26 21 27 #include <linux/compiler.h> /* for __PASTE */ 22 #include <linux/compiler.h> /* for __PASTE */ 28 #include <linux/compiler_attributes.h> /* for 23 #include <linux/compiler_attributes.h> /* for __maybe_unused */ 29 #include <linux/stringify.h> << 30 24 31 /* 25 /* 32 * Following macros help to define lists of BT 26 * Following macros help to define lists of BTF IDs placed 33 * in .BTF_ids section. They are initially fil 27 * in .BTF_ids section. They are initially filled with zeros 34 * (during compilation) and resolved later dur 28 * (during compilation) and resolved later during the 35 * linking phase by resolve_btfids tool. 29 * linking phase by resolve_btfids tool. 36 * 30 * 37 * Any change in list layout must be reflected 31 * Any change in list layout must be reflected in resolve_btfids 38 * tool logic. 32 * tool logic. 39 */ 33 */ 40 34 41 #define BTF_IDS_SECTION ".BTF_ids" 35 #define BTF_IDS_SECTION ".BTF_ids" 42 36 43 #define ____BTF_ID(symbol, word) 37 #define ____BTF_ID(symbol, word) \ 44 asm( 38 asm( \ 45 ".pushsection " BTF_IDS_SECTION ",\"a\"; 39 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 46 ".local " #symbol " ; 40 ".local " #symbol " ; \n" \ 47 ".type " #symbol ", STT_OBJECT; 41 ".type " #symbol ", STT_OBJECT; \n" \ 48 ".size " #symbol ", 4; 42 ".size " #symbol ", 4; \n" \ 49 #symbol ": 43 #symbol ": \n" \ 50 ".zero 4 44 ".zero 4 \n" \ 51 word 45 word \ 52 ".popsection; 46 ".popsection; \n"); 53 47 54 #define __BTF_ID(symbol, word) \ 48 #define __BTF_ID(symbol, word) \ 55 ____BTF_ID(symbol, word) 49 ____BTF_ID(symbol, word) 56 50 57 #define __ID(prefix) \ 51 #define __ID(prefix) \ 58 __PASTE(__PASTE(prefix, __COUNTER__), 52 __PASTE(__PASTE(prefix, __COUNTER__), __LINE__) 59 53 60 /* 54 /* 61 * The BTF_ID defines unique symbol for each I 55 * The BTF_ID defines unique symbol for each ID pointing 62 * to 4 zero bytes. 56 * to 4 zero bytes. 63 */ 57 */ 64 #define BTF_ID(prefix, name) \ 58 #define BTF_ID(prefix, name) \ 65 __BTF_ID(__ID(__BTF_ID__##prefix##__## 59 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "") 66 60 67 #define ____BTF_ID_FLAGS(prefix, name, flags) 61 #define ____BTF_ID_FLAGS(prefix, name, flags) \ 68 __BTF_ID(__ID(__BTF_ID__##prefix##__## 62 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n") 69 #define __BTF_ID_FLAGS(prefix, name, flags, .. 63 #define __BTF_ID_FLAGS(prefix, name, flags, ...) \ 70 ____BTF_ID_FLAGS(prefix, name, flags) 64 ____BTF_ID_FLAGS(prefix, name, flags) 71 #define BTF_ID_FLAGS(prefix, name, ...) \ 65 #define BTF_ID_FLAGS(prefix, name, ...) \ 72 __BTF_ID_FLAGS(prefix, name, ##__VA_AR 66 __BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0) 73 67 74 /* 68 /* 75 * The BTF_ID_LIST macro defines pure (unsorte 69 * The BTF_ID_LIST macro defines pure (unsorted) list 76 * of BTF IDs, with following layout: 70 * of BTF IDs, with following layout: 77 * 71 * 78 * BTF_ID_LIST(list1) 72 * BTF_ID_LIST(list1) 79 * BTF_ID(type1, name1) 73 * BTF_ID(type1, name1) 80 * BTF_ID(type2, name2) 74 * BTF_ID(type2, name2) 81 * 75 * 82 * list1: 76 * list1: 83 * __BTF_ID__type1__name1__1: 77 * __BTF_ID__type1__name1__1: 84 * .zero 4 78 * .zero 4 85 * __BTF_ID__type2__name2__2: 79 * __BTF_ID__type2__name2__2: 86 * .zero 4 80 * .zero 4 87 * 81 * 88 */ 82 */ 89 #define __BTF_ID_LIST(name, scope) 83 #define __BTF_ID_LIST(name, scope) \ 90 asm( 84 asm( \ 91 ".pushsection " BTF_IDS_SECTION ",\"a\"; 85 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 92 "." #scope " " #name "; 86 "." #scope " " #name "; \n" \ 93 #name ":; 87 #name ":; \n" \ 94 ".popsection; 88 ".popsection; \n"); 95 89 96 #define BTF_ID_LIST(name) 90 #define BTF_ID_LIST(name) \ 97 __BTF_ID_LIST(name, local) 91 __BTF_ID_LIST(name, local) \ 98 extern u32 name[]; 92 extern u32 name[]; 99 93 100 #define BTF_ID_LIST_GLOBAL(name, n) 94 #define BTF_ID_LIST_GLOBAL(name, n) \ 101 __BTF_ID_LIST(name, globl) 95 __BTF_ID_LIST(name, globl) 102 96 103 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ 97 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with 104 * a single entry. 98 * a single entry. 105 */ 99 */ 106 #define BTF_ID_LIST_SINGLE(name, prefix, typen 100 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \ 107 BTF_ID_LIST(name) \ 101 BTF_ID_LIST(name) \ 108 BTF_ID(prefix, typename) 102 BTF_ID(prefix, typename) 109 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix 103 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \ 110 BTF_ID_LIST_GLOBAL(name, 1) 104 BTF_ID_LIST_GLOBAL(name, 1) \ 111 BTF_ID(prefix, typename) 105 BTF_ID(prefix, typename) 112 106 113 /* 107 /* 114 * The BTF_ID_UNUSED macro defines 4 zero byte 108 * The BTF_ID_UNUSED macro defines 4 zero bytes. 115 * It's used when we want to define 'unused' e 109 * It's used when we want to define 'unused' entry 116 * in BTF_ID_LIST, like: 110 * in BTF_ID_LIST, like: 117 * 111 * 118 * BTF_ID_LIST(bpf_skb_output_btf_ids) 112 * BTF_ID_LIST(bpf_skb_output_btf_ids) 119 * BTF_ID(struct, sk_buff) 113 * BTF_ID(struct, sk_buff) 120 * BTF_ID_UNUSED 114 * BTF_ID_UNUSED 121 * BTF_ID(struct, task_struct) 115 * BTF_ID(struct, task_struct) 122 */ 116 */ 123 117 124 #define BTF_ID_UNUSED 118 #define BTF_ID_UNUSED \ 125 asm( 119 asm( \ 126 ".pushsection " BTF_IDS_SECTION ",\"a\"; 120 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 127 ".zero 4 121 ".zero 4 \n" \ 128 ".popsection; 122 ".popsection; \n"); 129 123 130 /* 124 /* 131 * The BTF_SET_START/END macros pair defines s 125 * The BTF_SET_START/END macros pair defines sorted list of 132 * BTF IDs plus its members count, with follow 126 * BTF IDs plus its members count, with following layout: 133 * 127 * 134 * BTF_SET_START(list) 128 * BTF_SET_START(list) 135 * BTF_ID(type1, name1) 129 * BTF_ID(type1, name1) 136 * BTF_ID(type2, name2) 130 * BTF_ID(type2, name2) 137 * BTF_SET_END(list) 131 * BTF_SET_END(list) 138 * 132 * 139 * __BTF_ID__set__list: 133 * __BTF_ID__set__list: 140 * .zero 4 134 * .zero 4 141 * list: 135 * list: 142 * __BTF_ID__type1__name1__3: 136 * __BTF_ID__type1__name1__3: 143 * .zero 4 137 * .zero 4 144 * __BTF_ID__type2__name2__4: 138 * __BTF_ID__type2__name2__4: 145 * .zero 4 139 * .zero 4 146 * 140 * 147 */ 141 */ 148 #define __BTF_SET_START(name, scope) 142 #define __BTF_SET_START(name, scope) \ 149 asm( 143 asm( \ 150 ".pushsection " BTF_IDS_SECTION ",\"a\"; 144 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 151 "." #scope " __BTF_ID__set__" #name "; 145 "." #scope " __BTF_ID__set__" #name "; \n" \ 152 "__BTF_ID__set__" #name ":; 146 "__BTF_ID__set__" #name ":; \n" \ 153 ".zero 4 147 ".zero 4 \n" \ 154 ".popsection; 148 ".popsection; \n"); 155 149 156 #define BTF_SET_START(name) 150 #define BTF_SET_START(name) \ 157 __BTF_ID_LIST(name, local) 151 __BTF_ID_LIST(name, local) \ 158 __BTF_SET_START(name, local) 152 __BTF_SET_START(name, local) 159 153 160 #define BTF_SET_START_GLOBAL(name) 154 #define BTF_SET_START_GLOBAL(name) \ 161 __BTF_ID_LIST(name, globl) 155 __BTF_ID_LIST(name, globl) \ 162 __BTF_SET_START(name, globl) 156 __BTF_SET_START(name, globl) 163 157 164 #define BTF_SET_END(name) 158 #define BTF_SET_END(name) \ 165 asm( 159 asm( \ 166 ".pushsection " BTF_IDS_SECTION ",\"a\"; 160 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 167 ".size __BTF_ID__set__" #name ", .-" #name " 161 ".size __BTF_ID__set__" #name ", .-" #name " \n" \ 168 ".popsection; 162 ".popsection; \n"); \ 169 extern struct btf_id_set name; 163 extern struct btf_id_set name; 170 164 171 /* 165 /* 172 * The BTF_SET8_START/END macros pair defines 166 * The BTF_SET8_START/END macros pair defines sorted list of 173 * BTF IDs and their flags plus its members co 167 * BTF IDs and their flags plus its members count, with the 174 * following layout: 168 * following layout: 175 * 169 * 176 * BTF_SET8_START(list) 170 * BTF_SET8_START(list) 177 * BTF_ID_FLAGS(type1, name1, flags) 171 * BTF_ID_FLAGS(type1, name1, flags) 178 * BTF_ID_FLAGS(type2, name2, flags) 172 * BTF_ID_FLAGS(type2, name2, flags) 179 * BTF_SET8_END(list) 173 * BTF_SET8_END(list) 180 * 174 * 181 * __BTF_ID__set8__list: 175 * __BTF_ID__set8__list: 182 * .zero 8 176 * .zero 8 183 * list: 177 * list: 184 * __BTF_ID__type1__name1__3: 178 * __BTF_ID__type1__name1__3: 185 * .zero 4 179 * .zero 4 186 * .word (1 << 0) | (1 << 2) 180 * .word (1 << 0) | (1 << 2) 187 * __BTF_ID__type2__name2__5: 181 * __BTF_ID__type2__name2__5: 188 * .zero 4 182 * .zero 4 189 * .word (1 << 3) | (1 << 1) | (1 << 2) 183 * .word (1 << 3) | (1 << 1) | (1 << 2) 190 * 184 * 191 */ 185 */ 192 #define __BTF_SET8_START(name, scope, flags) !! 186 #define __BTF_SET8_START(name, scope) \ 193 __BTF_ID_LIST(name, local) << 194 asm( 187 asm( \ 195 ".pushsection " BTF_IDS_SECTION ",\"a\"; 188 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 196 "." #scope " __BTF_ID__set8__" #name "; 189 "." #scope " __BTF_ID__set8__" #name "; \n" \ 197 "__BTF_ID__set8__" #name ":; 190 "__BTF_ID__set8__" #name ":; \n" \ 198 ".zero 4 !! 191 ".zero 8 \n" \ 199 ".long " __stringify(flags) << 200 ".popsection; 192 ".popsection; \n"); 201 193 202 #define BTF_SET8_START(name) 194 #define BTF_SET8_START(name) \ 203 __BTF_SET8_START(name, local, 0) !! 195 __BTF_ID_LIST(name, local) \ >> 196 __BTF_SET8_START(name, local) 204 197 205 #define BTF_SET8_END(name) 198 #define BTF_SET8_END(name) \ 206 asm( 199 asm( \ 207 ".pushsection " BTF_IDS_SECTION ",\"a\"; 200 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 208 ".size __BTF_ID__set8__" #name ", .-" #name " 201 ".size __BTF_ID__set8__" #name ", .-" #name " \n" \ 209 ".popsection; 202 ".popsection; \n"); \ 210 extern struct btf_id_set8 name; 203 extern struct btf_id_set8 name; 211 204 212 #define BTF_KFUNCS_START(name) << 213 __BTF_SET8_START(name, local, BTF_SET8_KFUNCS) << 214 << 215 #define BTF_KFUNCS_END(name) << 216 BTF_SET8_END(name) << 217 << 218 #else 205 #else 219 206 220 #define BTF_ID_LIST(name) static u32 __maybe_u 207 #define BTF_ID_LIST(name) static u32 __maybe_unused name[64]; 221 #define BTF_ID(prefix, name) 208 #define BTF_ID(prefix, name) 222 #define BTF_ID_FLAGS(prefix, name, ...) 209 #define BTF_ID_FLAGS(prefix, name, ...) 223 #define BTF_ID_UNUSED 210 #define BTF_ID_UNUSED 224 #define BTF_ID_LIST_GLOBAL(name, n) u32 __mayb 211 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n]; 225 #define BTF_ID_LIST_SINGLE(name, prefix, typen 212 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1]; 226 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix 213 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1]; 227 #define BTF_SET_START(name) static struct btf_ 214 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 }; 228 #define BTF_SET_START_GLOBAL(name) static stru 215 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 }; 229 #define BTF_SET_END(name) 216 #define BTF_SET_END(name) 230 #define BTF_SET8_START(name) static struct btf 217 #define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 }; 231 #define BTF_SET8_END(name) 218 #define BTF_SET8_END(name) 232 #define BTF_KFUNCS_START(name) static struct b << 233 #define BTF_KFUNCS_END(name) << 234 219 235 #endif /* CONFIG_DEBUG_INFO_BTF */ 220 #endif /* CONFIG_DEBUG_INFO_BTF */ 236 221 237 #ifdef CONFIG_NET 222 #ifdef CONFIG_NET 238 /* Define a list of socket types which can be 223 /* Define a list of socket types which can be the argument for 239 * skc_to_*_sock() helpers. All these sockets 224 * skc_to_*_sock() helpers. All these sockets should have 240 * sock_common as the first argument in its me 225 * sock_common as the first argument in its memory layout. 241 */ 226 */ 242 #define BTF_SOCK_TYPE_xxx \ 227 #define BTF_SOCK_TYPE_xxx \ 243 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet 228 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ 244 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, 229 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ 245 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, 230 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ 246 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, i 231 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ 247 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, reque 232 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ 248 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock 233 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ 249 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMO 234 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ 250 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_s 235 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ 251 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, t 236 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ 252 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tc 237 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ 253 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6 238 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ 254 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_s 239 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ 255 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6 240 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ 256 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix 241 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ 257 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mpt 242 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \ 258 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, so 243 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket) 259 244 260 enum { 245 enum { 261 #define BTF_SOCK_TYPE(name, str) name, 246 #define BTF_SOCK_TYPE(name, str) name, 262 BTF_SOCK_TYPE_xxx 247 BTF_SOCK_TYPE_xxx 263 #undef BTF_SOCK_TYPE 248 #undef BTF_SOCK_TYPE 264 MAX_BTF_SOCK_TYPE, 249 MAX_BTF_SOCK_TYPE, 265 }; 250 }; 266 251 267 extern u32 btf_sock_ids[]; 252 extern u32 btf_sock_ids[]; 268 #endif 253 #endif 269 254 270 #define BTF_TRACING_TYPE_xxx \ 255 #define BTF_TRACING_TYPE_xxx \ 271 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK 256 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \ 272 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE 257 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \ 273 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, 258 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct) 274 259 275 enum { 260 enum { 276 #define BTF_TRACING_TYPE(name, type) name, 261 #define BTF_TRACING_TYPE(name, type) name, 277 BTF_TRACING_TYPE_xxx 262 BTF_TRACING_TYPE_xxx 278 #undef BTF_TRACING_TYPE 263 #undef BTF_TRACING_TYPE 279 MAX_BTF_TRACING_TYPE, 264 MAX_BTF_TRACING_TYPE, 280 }; 265 }; 281 266 282 extern u32 btf_tracing_ids[]; 267 extern u32 btf_tracing_ids[]; 283 extern u32 bpf_cgroup_btf_id[]; 268 extern u32 bpf_cgroup_btf_id[]; 284 extern u32 bpf_local_storage_map_btf_id[]; 269 extern u32 bpf_local_storage_map_btf_id[]; 285 extern u32 btf_bpf_map_id[]; 270 extern u32 btf_bpf_map_id[]; 286 271 287 #endif 272 #endif 288 273
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.