1e5a0516eSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */ 2e5a0516eSJiri Olsa 3e5a0516eSJiri Olsa #ifndef _LINUX_BTF_IDS_H 4e5a0516eSJiri Olsa #define _LINUX_BTF_IDS_H 5e5a0516eSJiri Olsa 6eae2e83eSJiri Olsa struct btf_id_set { 7eae2e83eSJiri Olsa u32 cnt; 8eae2e83eSJiri Olsa u32 ids[]; 9eae2e83eSJiri Olsa }; 10eae2e83eSJiri Olsa 11*9707ac4fSViktor Malik struct btf_id_set8 { 12*9707ac4fSViktor Malik u32 cnt; 13*9707ac4fSViktor Malik u32 flags; 14*9707ac4fSViktor Malik struct { 15*9707ac4fSViktor Malik u32 id; 16*9707ac4fSViktor Malik u32 flags; 17*9707ac4fSViktor Malik } pairs[]; 18*9707ac4fSViktor Malik }; 19*9707ac4fSViktor Malik 20d8dfe5bfSYonghong Song #ifdef CONFIG_DEBUG_INFO_BTF 21d8dfe5bfSYonghong Song 22e5a0516eSJiri Olsa #include <linux/compiler.h> /* for __PASTE */ 23e5a0516eSJiri Olsa 24e5a0516eSJiri Olsa /* 25e5a0516eSJiri Olsa * Following macros help to define lists of BTF IDs placed 26e5a0516eSJiri Olsa * in .BTF_ids section. They are initially filled with zeros 27e5a0516eSJiri Olsa * (during compilation) and resolved later during the 28e5a0516eSJiri Olsa * linking phase by resolve_btfids tool. 29e5a0516eSJiri Olsa * 30e5a0516eSJiri Olsa * Any change in list layout must be reflected in resolve_btfids 31e5a0516eSJiri Olsa * tool logic. 32e5a0516eSJiri Olsa */ 33e5a0516eSJiri Olsa 34e5a0516eSJiri Olsa #define BTF_IDS_SECTION ".BTF_ids" 35e5a0516eSJiri Olsa 36e5a0516eSJiri Olsa #define ____BTF_ID(symbol) \ 37e5a0516eSJiri Olsa asm( \ 38e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 39e5a0516eSJiri Olsa ".local " #symbol " ; \n" \ 40d8dfe5bfSYonghong Song ".type " #symbol ", STT_OBJECT; \n" \ 41e5a0516eSJiri Olsa ".size " #symbol ", 4; \n" \ 42e5a0516eSJiri Olsa #symbol ": \n" \ 43e5a0516eSJiri Olsa ".zero 4 \n" \ 44e5a0516eSJiri Olsa ".popsection; \n"); 45e5a0516eSJiri Olsa 46e5a0516eSJiri Olsa #define __BTF_ID(symbol) \ 47e5a0516eSJiri Olsa ____BTF_ID(symbol) 48e5a0516eSJiri Olsa 49e5a0516eSJiri Olsa #define __ID(prefix) \ 50c0bb9fb0SNick Desaulniers __PASTE(__PASTE(prefix, __COUNTER__), __LINE__) 51e5a0516eSJiri Olsa 52e5a0516eSJiri Olsa /* 53e5a0516eSJiri Olsa * The BTF_ID defines unique symbol for each ID pointing 54e5a0516eSJiri Olsa * to 4 zero bytes. 55e5a0516eSJiri Olsa */ 56e5a0516eSJiri Olsa #define BTF_ID(prefix, name) \ 57e5a0516eSJiri Olsa __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__)) 58e5a0516eSJiri Olsa 59e5a0516eSJiri Olsa /* 60e5a0516eSJiri Olsa * The BTF_ID_LIST macro defines pure (unsorted) list 61e5a0516eSJiri Olsa * of BTF IDs, with following layout: 62e5a0516eSJiri Olsa * 63e5a0516eSJiri Olsa * BTF_ID_LIST(list1) 64e5a0516eSJiri Olsa * BTF_ID(type1, name1) 65e5a0516eSJiri Olsa * BTF_ID(type2, name2) 66e5a0516eSJiri Olsa * 67e5a0516eSJiri Olsa * list1: 68e5a0516eSJiri Olsa * __BTF_ID__type1__name1__1: 69e5a0516eSJiri Olsa * .zero 4 70e5a0516eSJiri Olsa * __BTF_ID__type2__name2__2: 71e5a0516eSJiri Olsa * .zero 4 72e5a0516eSJiri Olsa * 73e5a0516eSJiri Olsa */ 740f12e584SYonghong Song #define __BTF_ID_LIST(name, scope) \ 75e5a0516eSJiri Olsa asm( \ 76e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 770f12e584SYonghong Song "." #scope " " #name "; \n" \ 78e5a0516eSJiri Olsa #name ":; \n" \ 79eae2e83eSJiri Olsa ".popsection; \n"); 80e5a0516eSJiri Olsa 81e5a0516eSJiri Olsa #define BTF_ID_LIST(name) \ 820f12e584SYonghong Song __BTF_ID_LIST(name, local) \ 83e5a0516eSJiri Olsa extern u32 name[]; 84e5a0516eSJiri Olsa 853b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL(name, n) \ 860f12e584SYonghong Song __BTF_ID_LIST(name, globl) 870f12e584SYonghong Song 8827774b70SLorenz Bauer /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with 8927774b70SLorenz Bauer * a single entry. 9027774b70SLorenz Bauer */ 9127774b70SLorenz Bauer #define BTF_ID_LIST_SINGLE(name, prefix, typename) \ 9227774b70SLorenz Bauer BTF_ID_LIST(name) \ 9327774b70SLorenz Bauer BTF_ID(prefix, typename) 943b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \ 953b34bcb9SStanislav Fomichev BTF_ID_LIST_GLOBAL(name, 1) \ 963b34bcb9SStanislav Fomichev BTF_ID(prefix, typename) 9727774b70SLorenz Bauer 98e5a0516eSJiri Olsa /* 99e5a0516eSJiri Olsa * The BTF_ID_UNUSED macro defines 4 zero bytes. 100e5a0516eSJiri Olsa * It's used when we want to define 'unused' entry 101e5a0516eSJiri Olsa * in BTF_ID_LIST, like: 102e5a0516eSJiri Olsa * 103e5a0516eSJiri Olsa * BTF_ID_LIST(bpf_skb_output_btf_ids) 104e5a0516eSJiri Olsa * BTF_ID(struct, sk_buff) 105e5a0516eSJiri Olsa * BTF_ID_UNUSED 106e5a0516eSJiri Olsa * BTF_ID(struct, task_struct) 107e5a0516eSJiri Olsa */ 108e5a0516eSJiri Olsa 109e5a0516eSJiri Olsa #define BTF_ID_UNUSED \ 110e5a0516eSJiri Olsa asm( \ 111e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 112e5a0516eSJiri Olsa ".zero 4 \n" \ 113e5a0516eSJiri Olsa ".popsection; \n"); 114e5a0516eSJiri Olsa 115eae2e83eSJiri Olsa /* 116eae2e83eSJiri Olsa * The BTF_SET_START/END macros pair defines sorted list of 117eae2e83eSJiri Olsa * BTF IDs plus its members count, with following layout: 118eae2e83eSJiri Olsa * 119eae2e83eSJiri Olsa * BTF_SET_START(list) 120eae2e83eSJiri Olsa * BTF_ID(type1, name1) 121eae2e83eSJiri Olsa * BTF_ID(type2, name2) 122eae2e83eSJiri Olsa * BTF_SET_END(list) 123eae2e83eSJiri Olsa * 124eae2e83eSJiri Olsa * __BTF_ID__set__list: 125eae2e83eSJiri Olsa * .zero 4 126eae2e83eSJiri Olsa * list: 127eae2e83eSJiri Olsa * __BTF_ID__type1__name1__3: 128eae2e83eSJiri Olsa * .zero 4 129eae2e83eSJiri Olsa * __BTF_ID__type2__name2__4: 130eae2e83eSJiri Olsa * .zero 4 131eae2e83eSJiri Olsa * 132eae2e83eSJiri Olsa */ 133eae2e83eSJiri Olsa #define __BTF_SET_START(name, scope) \ 134eae2e83eSJiri Olsa asm( \ 135eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 136eae2e83eSJiri Olsa "." #scope " __BTF_ID__set__" #name "; \n" \ 137eae2e83eSJiri Olsa "__BTF_ID__set__" #name ":; \n" \ 138eae2e83eSJiri Olsa ".zero 4 \n" \ 139eae2e83eSJiri Olsa ".popsection; \n"); 140eae2e83eSJiri Olsa 141eae2e83eSJiri Olsa #define BTF_SET_START(name) \ 142eae2e83eSJiri Olsa __BTF_ID_LIST(name, local) \ 143eae2e83eSJiri Olsa __BTF_SET_START(name, local) 144eae2e83eSJiri Olsa 145eae2e83eSJiri Olsa #define BTF_SET_START_GLOBAL(name) \ 146eae2e83eSJiri Olsa __BTF_ID_LIST(name, globl) \ 147eae2e83eSJiri Olsa __BTF_SET_START(name, globl) 148eae2e83eSJiri Olsa 149eae2e83eSJiri Olsa #define BTF_SET_END(name) \ 150eae2e83eSJiri Olsa asm( \ 151eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 152eae2e83eSJiri Olsa ".size __BTF_ID__set__" #name ", .-" #name " \n" \ 153eae2e83eSJiri Olsa ".popsection; \n"); \ 154eae2e83eSJiri Olsa extern struct btf_id_set name; 155eae2e83eSJiri Olsa 156d8dfe5bfSYonghong Song #else 157d8dfe5bfSYonghong Song 1583b34bcb9SStanislav Fomichev #define BTF_ID_LIST(name) static u32 __maybe_unused name[5]; 159d8dfe5bfSYonghong Song #define BTF_ID(prefix, name) 160d8dfe5bfSYonghong Song #define BTF_ID_UNUSED 1613b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n]; 1623b34bcb9SStanislav Fomichev #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1]; 1633b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1]; 1643b34bcb9SStanislav Fomichev #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 }; 1653b34bcb9SStanislav Fomichev #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 }; 166eae2e83eSJiri Olsa #define BTF_SET_END(name) 167d8dfe5bfSYonghong Song 168d8dfe5bfSYonghong Song #endif /* CONFIG_DEBUG_INFO_BTF */ 169e5a0516eSJiri Olsa 170fce557bcSYonghong Song #ifdef CONFIG_NET 171fce557bcSYonghong Song /* Define a list of socket types which can be the argument for 172fce557bcSYonghong Song * skc_to_*_sock() helpers. All these sockets should have 173fce557bcSYonghong Song * sock_common as the first argument in its memory layout. 174fce557bcSYonghong Song */ 175fce557bcSYonghong Song #define BTF_SOCK_TYPE_xxx \ 176fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ 177fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ 178fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ 179fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ 180fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ 181fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ 182fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ 183fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ 184fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ 185fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ 186fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ 187fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ 1883b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ 1893b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ 1903b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \ 1913b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket) 192fce557bcSYonghong Song 193fce557bcSYonghong Song enum { 194fce557bcSYonghong Song #define BTF_SOCK_TYPE(name, str) name, 195fce557bcSYonghong Song BTF_SOCK_TYPE_xxx 196fce557bcSYonghong Song #undef BTF_SOCK_TYPE 197fce557bcSYonghong Song MAX_BTF_SOCK_TYPE, 198fce557bcSYonghong Song }; 199fce557bcSYonghong Song 200fce557bcSYonghong Song extern u32 btf_sock_ids[]; 201fce557bcSYonghong Song #endif 202fce557bcSYonghong Song 2033b34bcb9SStanislav Fomichev #define BTF_TRACING_TYPE_xxx \ 2043b34bcb9SStanislav Fomichev BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \ 2053b34bcb9SStanislav Fomichev BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \ 2063b34bcb9SStanislav Fomichev BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct) 2073b34bcb9SStanislav Fomichev 2083b34bcb9SStanislav Fomichev enum { 2093b34bcb9SStanislav Fomichev #define BTF_TRACING_TYPE(name, type) name, 2103b34bcb9SStanislav Fomichev BTF_TRACING_TYPE_xxx 2113b34bcb9SStanislav Fomichev #undef BTF_TRACING_TYPE 2123b34bcb9SStanislav Fomichev MAX_BTF_TRACING_TYPE, 2133b34bcb9SStanislav Fomichev }; 2143b34bcb9SStanislav Fomichev 2153b34bcb9SStanislav Fomichev extern u32 btf_tracing_ids[]; 2163b34bcb9SStanislav Fomichev 217e5a0516eSJiri Olsa #endif 218