15a2798abSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */ 25a2798abSJiri Olsa 35a2798abSJiri Olsa #ifndef _LINUX_BTF_IDS_H 45a2798abSJiri Olsa #define _LINUX_BTF_IDS_H 55a2798abSJiri Olsa 6cfd3bfe9SDmitrii Bundin #include <linux/types.h> /* for u32 */ 7cfd3bfe9SDmitrii Bundin 8eae2e83eSJiri Olsa struct btf_id_set { 9eae2e83eSJiri Olsa u32 cnt; 10eae2e83eSJiri Olsa u32 ids[]; 11eae2e83eSJiri Olsa }; 12eae2e83eSJiri Olsa 13a05e9042SDaniel Xu /* This flag implies BTF_SET8 holds kfunc(s) */ 14a05e9042SDaniel Xu #define BTF_SET8_KFUNCS (1 << 0) 15a05e9042SDaniel Xu 16ab21d606SKumar Kartikeya Dwivedi struct btf_id_set8 { 17ab21d606SKumar Kartikeya Dwivedi u32 cnt; 18ab21d606SKumar Kartikeya Dwivedi u32 flags; 19ab21d606SKumar Kartikeya Dwivedi struct { 20ab21d606SKumar Kartikeya Dwivedi u32 id; 21ab21d606SKumar Kartikeya Dwivedi u32 flags; 22ab21d606SKumar Kartikeya Dwivedi } pairs[]; 23ab21d606SKumar Kartikeya Dwivedi }; 24ab21d606SKumar Kartikeya Dwivedi 25079ef536SJiri Olsa #ifdef CONFIG_DEBUG_INFO_BTF 26079ef536SJiri Olsa 275a2798abSJiri Olsa #include <linux/compiler.h> /* for __PASTE */ 28dee872e1SKumar Kartikeya Dwivedi #include <linux/compiler_attributes.h> /* for __maybe_unused */ 2979b47344SDaniel Xu #include <linux/stringify.h> 305a2798abSJiri Olsa 315a2798abSJiri Olsa /* 325a2798abSJiri Olsa * Following macros help to define lists of BTF IDs placed 335a2798abSJiri Olsa * in .BTF_ids section. They are initially filled with zeros 345a2798abSJiri Olsa * (during compilation) and resolved later during the 355a2798abSJiri Olsa * linking phase by resolve_btfids tool. 365a2798abSJiri Olsa * 375a2798abSJiri Olsa * Any change in list layout must be reflected in resolve_btfids 385a2798abSJiri Olsa * tool logic. 395a2798abSJiri Olsa */ 405a2798abSJiri Olsa 415a2798abSJiri Olsa #define BTF_IDS_SECTION ".BTF_ids" 425a2798abSJiri Olsa 43ab21d606SKumar Kartikeya Dwivedi #define ____BTF_ID(symbol, word) \ 445a2798abSJiri Olsa asm( \ 455a2798abSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 465a2798abSJiri Olsa ".local " #symbol " ; \n" \ 4711bb2f7aSJiri Olsa ".type " #symbol ", STT_OBJECT; \n" \ 485a2798abSJiri Olsa ".size " #symbol ", 4; \n" \ 495a2798abSJiri Olsa #symbol ": \n" \ 505a2798abSJiri Olsa ".zero 4 \n" \ 51ab21d606SKumar Kartikeya Dwivedi word \ 525a2798abSJiri Olsa ".popsection; \n"); 535a2798abSJiri Olsa 54ab21d606SKumar Kartikeya Dwivedi #define __BTF_ID(symbol, word) \ 55ab21d606SKumar Kartikeya Dwivedi ____BTF_ID(symbol, word) 565a2798abSJiri Olsa 575a2798abSJiri Olsa #define __ID(prefix) \ 588f908db7SJiri Olsa __PASTE(__PASTE(prefix, __COUNTER__), __LINE__) 595a2798abSJiri Olsa 605a2798abSJiri Olsa /* 615a2798abSJiri Olsa * The BTF_ID defines unique symbol for each ID pointing 625a2798abSJiri Olsa * to 4 zero bytes. 635a2798abSJiri Olsa */ 645a2798abSJiri Olsa #define BTF_ID(prefix, name) \ 65ab21d606SKumar Kartikeya Dwivedi __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "") 66ab21d606SKumar Kartikeya Dwivedi 67ab21d606SKumar Kartikeya Dwivedi #define ____BTF_ID_FLAGS(prefix, name, flags) \ 68ab21d606SKumar Kartikeya Dwivedi __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n") 69ab21d606SKumar Kartikeya Dwivedi #define __BTF_ID_FLAGS(prefix, name, flags, ...) \ 70ab21d606SKumar Kartikeya Dwivedi ____BTF_ID_FLAGS(prefix, name, flags) 71ab21d606SKumar Kartikeya Dwivedi #define BTF_ID_FLAGS(prefix, name, ...) \ 72ab21d606SKumar Kartikeya Dwivedi __BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0) 735a2798abSJiri Olsa 745a2798abSJiri Olsa /* 755a2798abSJiri Olsa * The BTF_ID_LIST macro defines pure (unsorted) list 765a2798abSJiri Olsa * of BTF IDs, with following layout: 775a2798abSJiri Olsa * 785a2798abSJiri Olsa * BTF_ID_LIST(list1) 795a2798abSJiri Olsa * BTF_ID(type1, name1) 805a2798abSJiri Olsa * BTF_ID(type2, name2) 815a2798abSJiri Olsa * 825a2798abSJiri Olsa * list1: 835a2798abSJiri Olsa * __BTF_ID__type1__name1__1: 845a2798abSJiri Olsa * .zero 4 855a2798abSJiri Olsa * __BTF_ID__type2__name2__2: 865a2798abSJiri Olsa * .zero 4 875a2798abSJiri Olsa * 885a2798abSJiri Olsa */ 890f12e584SYonghong Song #define __BTF_ID_LIST(name, scope) \ 905a2798abSJiri Olsa asm( \ 915a2798abSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 920f12e584SYonghong Song "." #scope " " #name "; \n" \ 935a2798abSJiri Olsa #name ":; \n" \ 94eae2e83eSJiri Olsa ".popsection; \n"); 955a2798abSJiri Olsa 965a2798abSJiri Olsa #define BTF_ID_LIST(name) \ 970f12e584SYonghong Song __BTF_ID_LIST(name, local) \ 985a2798abSJiri Olsa extern u32 name[]; 995a2798abSJiri Olsa 1009e2ad638SSong Liu #define BTF_ID_LIST_GLOBAL(name, n) \ 1010f12e584SYonghong Song __BTF_ID_LIST(name, globl) 1020f12e584SYonghong Song 10327774b70SLorenz Bauer /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with 10427774b70SLorenz Bauer * a single entry. 10527774b70SLorenz Bauer */ 10627774b70SLorenz Bauer #define BTF_ID_LIST_SINGLE(name, prefix, typename) \ 10727774b70SLorenz Bauer BTF_ID_LIST(name) \ 10827774b70SLorenz Bauer BTF_ID(prefix, typename) 1091b07d00aSDaniel Xu #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \ 1109e2ad638SSong Liu BTF_ID_LIST_GLOBAL(name, 1) \ 1111b07d00aSDaniel Xu BTF_ID(prefix, typename) 11227774b70SLorenz Bauer 1135a2798abSJiri Olsa /* 1145a2798abSJiri Olsa * The BTF_ID_UNUSED macro defines 4 zero bytes. 1155a2798abSJiri Olsa * It's used when we want to define 'unused' entry 1165a2798abSJiri Olsa * in BTF_ID_LIST, like: 1175a2798abSJiri Olsa * 1185a2798abSJiri Olsa * BTF_ID_LIST(bpf_skb_output_btf_ids) 1195a2798abSJiri Olsa * BTF_ID(struct, sk_buff) 1205a2798abSJiri Olsa * BTF_ID_UNUSED 1215a2798abSJiri Olsa * BTF_ID(struct, task_struct) 1225a2798abSJiri Olsa */ 1235a2798abSJiri Olsa 1245a2798abSJiri Olsa #define BTF_ID_UNUSED \ 1255a2798abSJiri Olsa asm( \ 1265a2798abSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 1275a2798abSJiri Olsa ".zero 4 \n" \ 1285a2798abSJiri Olsa ".popsection; \n"); 1295a2798abSJiri Olsa 130eae2e83eSJiri Olsa /* 131eae2e83eSJiri Olsa * The BTF_SET_START/END macros pair defines sorted list of 132eae2e83eSJiri Olsa * BTF IDs plus its members count, with following layout: 133eae2e83eSJiri Olsa * 134eae2e83eSJiri Olsa * BTF_SET_START(list) 135eae2e83eSJiri Olsa * BTF_ID(type1, name1) 136eae2e83eSJiri Olsa * BTF_ID(type2, name2) 137eae2e83eSJiri Olsa * BTF_SET_END(list) 138eae2e83eSJiri Olsa * 139eae2e83eSJiri Olsa * __BTF_ID__set__list: 140eae2e83eSJiri Olsa * .zero 4 141eae2e83eSJiri Olsa * list: 142eae2e83eSJiri Olsa * __BTF_ID__type1__name1__3: 143eae2e83eSJiri Olsa * .zero 4 144eae2e83eSJiri Olsa * __BTF_ID__type2__name2__4: 145eae2e83eSJiri Olsa * .zero 4 146eae2e83eSJiri Olsa * 147eae2e83eSJiri Olsa */ 148eae2e83eSJiri Olsa #define __BTF_SET_START(name, scope) \ 149eae2e83eSJiri Olsa asm( \ 150eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 151eae2e83eSJiri Olsa "." #scope " __BTF_ID__set__" #name "; \n" \ 152eae2e83eSJiri Olsa "__BTF_ID__set__" #name ":; \n" \ 153eae2e83eSJiri Olsa ".zero 4 \n" \ 154eae2e83eSJiri Olsa ".popsection; \n"); 155eae2e83eSJiri Olsa 156eae2e83eSJiri Olsa #define BTF_SET_START(name) \ 157eae2e83eSJiri Olsa __BTF_ID_LIST(name, local) \ 158eae2e83eSJiri Olsa __BTF_SET_START(name, local) 159eae2e83eSJiri Olsa 160eae2e83eSJiri Olsa #define BTF_SET_START_GLOBAL(name) \ 161eae2e83eSJiri Olsa __BTF_ID_LIST(name, globl) \ 162eae2e83eSJiri Olsa __BTF_SET_START(name, globl) 163eae2e83eSJiri Olsa 164eae2e83eSJiri Olsa #define BTF_SET_END(name) \ 165eae2e83eSJiri Olsa asm( \ 166eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 167eae2e83eSJiri Olsa ".size __BTF_ID__set__" #name ", .-" #name " \n" \ 168eae2e83eSJiri Olsa ".popsection; \n"); \ 169eae2e83eSJiri Olsa extern struct btf_id_set name; 170eae2e83eSJiri Olsa 171ab21d606SKumar Kartikeya Dwivedi /* 172ab21d606SKumar Kartikeya Dwivedi * The BTF_SET8_START/END macros pair defines sorted list of 173ab21d606SKumar Kartikeya Dwivedi * BTF IDs and their flags plus its members count, with the 174ab21d606SKumar Kartikeya Dwivedi * following layout: 175ab21d606SKumar Kartikeya Dwivedi * 176ab21d606SKumar Kartikeya Dwivedi * BTF_SET8_START(list) 177ab21d606SKumar Kartikeya Dwivedi * BTF_ID_FLAGS(type1, name1, flags) 178ab21d606SKumar Kartikeya Dwivedi * BTF_ID_FLAGS(type2, name2, flags) 179ab21d606SKumar Kartikeya Dwivedi * BTF_SET8_END(list) 180ab21d606SKumar Kartikeya Dwivedi * 181ab21d606SKumar Kartikeya Dwivedi * __BTF_ID__set8__list: 182ab21d606SKumar Kartikeya Dwivedi * .zero 8 183ab21d606SKumar Kartikeya Dwivedi * list: 184ab21d606SKumar Kartikeya Dwivedi * __BTF_ID__type1__name1__3: 185ab21d606SKumar Kartikeya Dwivedi * .zero 4 186ab21d606SKumar Kartikeya Dwivedi * .word (1 << 0) | (1 << 2) 187ab21d606SKumar Kartikeya Dwivedi * __BTF_ID__type2__name2__5: 188ab21d606SKumar Kartikeya Dwivedi * .zero 4 189ab21d606SKumar Kartikeya Dwivedi * .word (1 << 3) | (1 << 1) | (1 << 2) 190ab21d606SKumar Kartikeya Dwivedi * 191ab21d606SKumar Kartikeya Dwivedi */ 19279b47344SDaniel Xu #define __BTF_SET8_START(name, scope, flags) \ 19379b47344SDaniel Xu __BTF_ID_LIST(name, local) \ 194ab21d606SKumar Kartikeya Dwivedi asm( \ 195ab21d606SKumar Kartikeya Dwivedi ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 196ab21d606SKumar Kartikeya Dwivedi "." #scope " __BTF_ID__set8__" #name "; \n" \ 197ab21d606SKumar Kartikeya Dwivedi "__BTF_ID__set8__" #name ":; \n" \ 19879b47344SDaniel Xu ".zero 4 \n" \ 19979b47344SDaniel Xu ".long " __stringify(flags) "\n" \ 200ab21d606SKumar Kartikeya Dwivedi ".popsection; \n"); 201ab21d606SKumar Kartikeya Dwivedi 202ab21d606SKumar Kartikeya Dwivedi #define BTF_SET8_START(name) \ 20379b47344SDaniel Xu __BTF_SET8_START(name, local, 0) 204ab21d606SKumar Kartikeya Dwivedi 205ab21d606SKumar Kartikeya Dwivedi #define BTF_SET8_END(name) \ 206ab21d606SKumar Kartikeya Dwivedi asm( \ 207ab21d606SKumar Kartikeya Dwivedi ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 208ab21d606SKumar Kartikeya Dwivedi ".size __BTF_ID__set8__" #name ", .-" #name " \n" \ 209ab21d606SKumar Kartikeya Dwivedi ".popsection; \n"); \ 210ab21d606SKumar Kartikeya Dwivedi extern struct btf_id_set8 name; 211ab21d606SKumar Kartikeya Dwivedi 212a05e9042SDaniel Xu #define BTF_KFUNCS_START(name) \ 213a05e9042SDaniel Xu __BTF_SET8_START(name, local, BTF_SET8_KFUNCS) 214a05e9042SDaniel Xu 215a05e9042SDaniel Xu #define BTF_KFUNCS_END(name) \ 216a05e9042SDaniel Xu BTF_SET8_END(name) 217a05e9042SDaniel Xu 218079ef536SJiri Olsa #else 219079ef536SJiri Olsa 2202d5bcdcdSNathan Chancellor #define BTF_ID_LIST(name) static u32 __maybe_unused name[64]; 221079ef536SJiri Olsa #define BTF_ID(prefix, name) 222e4234143SKumar Kartikeya Dwivedi #define BTF_ID_FLAGS(prefix, name, ...) 223079ef536SJiri Olsa #define BTF_ID_UNUSED 224dee872e1SKumar Kartikeya Dwivedi #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n]; 225dee872e1SKumar Kartikeya Dwivedi #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1]; 226dee872e1SKumar Kartikeya Dwivedi #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1]; 227dee872e1SKumar Kartikeya Dwivedi #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 }; 228dee872e1SKumar Kartikeya Dwivedi #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 }; 229eae2e83eSJiri Olsa #define BTF_SET_END(name) 230ab21d606SKumar Kartikeya Dwivedi #define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 }; 231e4234143SKumar Kartikeya Dwivedi #define BTF_SET8_END(name) 232a05e9042SDaniel Xu #define BTF_KFUNCS_START(name) static struct btf_id_set8 __maybe_unused name = { .flags = BTF_SET8_KFUNCS }; 233a05e9042SDaniel Xu #define BTF_KFUNCS_END(name) 234079ef536SJiri Olsa 235079ef536SJiri Olsa #endif /* CONFIG_DEBUG_INFO_BTF */ 2365a2798abSJiri Olsa 237fce557bcSYonghong Song #ifdef CONFIG_NET 238fce557bcSYonghong Song /* Define a list of socket types which can be the argument for 239fce557bcSYonghong Song * skc_to_*_sock() helpers. All these sockets should have 240fce557bcSYonghong Song * sock_common as the first argument in its memory layout. 241fce557bcSYonghong Song */ 242fce557bcSYonghong Song #define BTF_SOCK_TYPE_xxx \ 243fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ 244fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ 245fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ 246fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ 247fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ 248fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ 249fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ 250fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ 251fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ 252fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ 253fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ 254fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ 2552c860a43SKuniyuki Iwashima BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ 2563bc253c2SGeliang Tang BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ 25769fd337aSStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \ 25869fd337aSStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket) 259fce557bcSYonghong Song 260fce557bcSYonghong Song enum { 261fce557bcSYonghong Song #define BTF_SOCK_TYPE(name, str) name, 262fce557bcSYonghong Song BTF_SOCK_TYPE_xxx 263fce557bcSYonghong Song #undef BTF_SOCK_TYPE 264fce557bcSYonghong Song MAX_BTF_SOCK_TYPE, 265fce557bcSYonghong Song }; 266fce557bcSYonghong Song 267fce557bcSYonghong Song extern u32 btf_sock_ids[]; 268fce557bcSYonghong Song #endif 269fce557bcSYonghong Song 270d19ddb47SSong Liu #define BTF_TRACING_TYPE_xxx \ 271d19ddb47SSong Liu BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \ 272d19ddb47SSong Liu BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \ 273d19ddb47SSong Liu BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct) 274d19ddb47SSong Liu 275d19ddb47SSong Liu enum { 276d19ddb47SSong Liu #define BTF_TRACING_TYPE(name, type) name, 277d19ddb47SSong Liu BTF_TRACING_TYPE_xxx 278d19ddb47SSong Liu #undef BTF_TRACING_TYPE 279d19ddb47SSong Liu MAX_BTF_TRACING_TYPE, 280d19ddb47SSong Liu }; 281d19ddb47SSong Liu 282d19ddb47SSong Liu extern u32 btf_tracing_ids[]; 2835e67b8efSYonghong Song extern u32 bpf_cgroup_btf_id[]; 2843144bfa5SYonghong Song extern u32 bpf_local_storage_map_btf_id[]; 2855ba190c2SAnton Protopopov extern u32 btf_bpf_map_id[]; 286*4971266eSNamhyung Kim extern u32 bpf_kmem_cache_btf_id[]; 28733c5cb36SDaniel Xu 2885a2798abSJiri Olsa #endif 289